From patchwork Wed Jan 13 12:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 362646 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E57C433E0 for ; Wed, 13 Jan 2021 12:13:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B38B233F8 for ; Wed, 13 Jan 2021 12:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727331AbhAMMNJ (ORCPT ); Wed, 13 Jan 2021 07:13:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726852AbhAMMNI (ORCPT ); Wed, 13 Jan 2021 07:13:08 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2BBBC061794 for ; Wed, 13 Jan 2021 04:12:27 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id r7so1870983wrc.5 for ; Wed, 13 Jan 2021 04:12:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uyB8QWTqN7dE+Bhpok/Tm0FFRe0cWIIcYpY5tQDKDs8=; b=qWywD6eGc2waYHF/uyxdY8b0/WbSDYR9RXFmpgGwMSUUTpqES3JxKAs/d7aX0quXRg VDx8VTET/WyT4TBtDdI1ILLpVw6h3+XKRkFJuniHxYvhR1VQySi+xMJiopMiPWDMYMQw 5cbtOJSPUMNbPV01cgosYMZ5pNdyDRBKM40yEf/yuiDsXqMEnOsPU8oOxgzkq9AeqmPV xb93frShemquk8KN4yh9nkj9xWEQd2OA9NnT7fc2lsIl+rCHhTHTspjL3d9D2TKbGQoW ScEe6t03+xHmiCpwtNtwKIktW9YKgr6fVaXJ7rPz5Q/pzN4zCHB31JSdJ7rWP8klFyW8 E3xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uyB8QWTqN7dE+Bhpok/Tm0FFRe0cWIIcYpY5tQDKDs8=; b=dBTA9JnHsLz8/V8CF3NPv52qsfA9b0Y7P7M6BlMNfnzyZN51YSPS7jZ3wX3wiR3gfO kBHch4v5JW7xjuUSW0N/9fa4aRyUYMR2Vc9AsBlgO7HFgXhoVvsRRgTugkzYudFIqyyD 4HoE12NB2aZMt8AX+WiLRK2vboY1f8RblP2J4+X+lTjahYXcG1GszGNkOoM6Kvq9bkYj 8dmh0vCREhk8CzDwh0HIoED27yUMm5ft9NGe3/tcxvGeoPvc4MCuoM/XX14DhDInqf+f AgCXr/5bfDlzoAulgLSKgShNVrng/L0kzXJRSUhsE0gvdiHjy3ycHNFHHlZhvbkG/LDv zuMQ== X-Gm-Message-State: AOAM532lnXLqO0JBvmLqGliQZ7RGsyKf+b5T8MUbu0hcepn8OJTnKPXS 4RwApJCxIIuZTt5bQidXyaUXtqlksgTjrHtv X-Google-Smtp-Source: ABdhPJxYdNvXbj3crHN5gmb6BB1tLjF/OZGlw5xvmUWTDFC7AvXhMixhAzS7YO/60Qm7QtZGD/+dsA== X-Received: by 2002:a5d:6ccb:: with SMTP id c11mr2314259wrc.224.1610539946094; Wed, 13 Jan 2021 04:12:26 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id x66sm2731803wmg.26.2021.01.13.04.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:25 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jacob.e.keller@intel.com, roopa@nvidia.com, mlxsw@nvidia.com Subject: [patch net-next RFC 02/10] devlink: implement line card provisioning Date: Wed, 13 Jan 2021 13:12:14 +0100 Message-Id: <20210113121222.733517-3-jiri@resnulli.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210113121222.733517-1-jiri@resnulli.us> References: <20210113121222.733517-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko In order to be able to configure all needed stuff on a port/netdevice of a line card without the line card being present, introduce line card provisioning. Basically provisioning will create a placeholder for instances (ports/netdevices) for a line card type. Allow the user to query the supported line card types over line card get command. Then implement two netlink commands to allow user to provision/unprovision the line card with selected line card type. On the driver API side, add provision/unprovision ops and supported types array to be advertised. Upon provision op call, the driver should take care of creating the instances for the particular line card type. Introduce provision_set/clear() functions to be called by the driver once the provisioning/unprovisioning is done on its side. Signed-off-by: Jiri Pirko --- include/net/devlink.h | 31 +++++++- include/uapi/linux/devlink.h | 17 +++++ net/core/devlink.c | 141 ++++++++++++++++++++++++++++++++++- 3 files changed, 185 insertions(+), 4 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 67c2547d5ef9..854abd53e9ea 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -139,10 +139,33 @@ struct devlink_port { struct mutex reporters_lock; /* Protects reporter_list */ }; +struct devlink_linecard_ops; + struct devlink_linecard { struct list_head list; struct devlink *devlink; unsigned int index; + const struct devlink_linecard_ops *ops; + void *priv; + enum devlink_linecard_state state; + const char *provisioned_type; +}; + +/** + * struct devlink_linecard_ops - Linecard operations + * @supported_types: array of supported types of linecards + * @supported_types_count: number of elements in the array above + * @provision: callback to provision the linecard slot with certain + * type of linecard + * @unprovision: callback to unprovision the linecard slot + */ +struct devlink_linecard_ops { + const char **supported_types; + unsigned int supported_types_count; + int (*provision)(struct devlink_linecard *linecard, void *priv, + u32 type_index, struct netlink_ext_ack *extack); + int (*unprovision)(struct devlink_linecard *linecard, void *priv, + struct netlink_ext_ack *extack); }; struct devlink_sb_pool_info { @@ -1414,9 +1437,13 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro u16 pf, bool external); void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller, u16 pf, u16 vf, bool external); -struct devlink_linecard *devlink_linecard_create(struct devlink *devlink, - unsigned int linecard_index); +struct devlink_linecard * +devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, + const struct devlink_linecard_ops *ops, void *priv); void devlink_linecard_destroy(struct devlink_linecard *linecard); +void devlink_linecard_provision_set(struct devlink_linecard *linecard, + u32 type_index); +void devlink_linecard_provision_clear(struct devlink_linecard *linecard); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count, diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index e5ed0522591f..4111ddcc000b 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -131,6 +131,9 @@ enum devlink_command { DEVLINK_CMD_LINECARD_NEW, DEVLINK_CMD_LINECARD_DEL, + DEVLINK_CMD_LINECARD_PROVISION, + DEVLINK_CMD_LINECARD_UNPROVISION, + /* add new commands above here */ __DEVLINK_CMD_MAX, DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1 @@ -329,6 +332,17 @@ enum devlink_reload_limit { #define DEVLINK_RELOAD_LIMITS_VALID_MASK (_BITUL(__DEVLINK_RELOAD_LIMIT_MAX) - 1) +enum devlink_linecard_state { + DEVLINK_LINECARD_STATE_UNSPEC, + DEVLINK_LINECARD_STATE_UNPROVISIONED, + DEVLINK_LINECARD_STATE_UNPROVISIONING, + DEVLINK_LINECARD_STATE_PROVISIONING, + DEVLINK_LINECARD_STATE_PROVISIONED, + + __DEVLINK_LINECARD_STATE_MAX, + DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1 +}; + enum devlink_attr { /* don't change the order or add anything between, this is ABI! */ DEVLINK_ATTR_UNSPEC, @@ -535,6 +549,9 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ DEVLINK_ATTR_LINECARD_INDEX, /* u32 */ + DEVLINK_ATTR_LINECARD_STATE, /* u8 */ + DEVLINK_ATTR_LINECARD_TYPE, /* string */ + DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES, /* 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 564e921133cf..434eecc310c3 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -1192,7 +1192,9 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, u32 seq, int flags, struct netlink_ext_ack *extack) { + struct nlattr *attr; void *hdr; + int i; hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); if (!hdr) @@ -1202,6 +1204,22 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, goto nla_put_failure; if (nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, linecard->index)) goto nla_put_failure; + if (nla_put_u8(msg, DEVLINK_ATTR_LINECARD_STATE, linecard->state)) + goto nla_put_failure; + if (linecard->state >= DEVLINK_LINECARD_STATE_PROVISIONED && + nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, + linecard->provisioned_type)) + goto nla_put_failure; + + attr = nla_nest_start(msg, DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES); + if (!attr) + return -EMSGSIZE; + for (i = 0; i < linecard->ops->supported_types_count; i++) { + if (nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, + linecard->ops->supported_types[i])) + goto nla_put_failure; + } + nla_nest_end(msg, attr); genlmsg_end(msg, hdr); return 0; @@ -1300,6 +1318,68 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, return msg->len; } +static int devlink_nl_cmd_linecard_provision_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_linecard *linecard = info->user_ptr[1]; + const char *type; + int i; + + if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard is currently being provisioned"); + return -EBUSY; + } + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard is currently being unprovisioned"); + return -EBUSY; + } + if (linecard->state != DEVLINK_LINECARD_STATE_UNPROVISIONED) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard already provisioned"); + return -EBUSY; + } + + if (!info->attrs[DEVLINK_ATTR_LINECARD_TYPE]) { + NL_SET_ERR_MSG_MOD(info->extack, "Provision type not provided"); + return -EINVAL; + } + + type = nla_data(info->attrs[DEVLINK_ATTR_LINECARD_TYPE]); + for (i = 0; i < linecard->ops->supported_types_count; i++) { + if (!strcmp(linecard->ops->supported_types[i], type)) { + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + return linecard->ops->provision(linecard, + linecard->priv, i, + info->extack); + } + } + NL_SET_ERR_MSG_MOD(info->extack, "Unsupported provision type provided"); + return -EINVAL; +} + +static int devlink_nl_cmd_linecard_unprovision_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_linecard *linecard = info->user_ptr[1]; + + if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard is currently being provisioned"); + return -EBUSY; + } + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard is currently being unprovisioned"); + return -EBUSY; + } + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONED) { + NL_SET_ERR_MSG_MOD(info->extack, "Linecard is not provisioned"); + return -EOPNOTSUPP; + } + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONING; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + return linecard->ops->unprovision(linecard, linecard->priv, + info->extack); +} + static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, enum devlink_command cmd, u32 portid, @@ -7759,6 +7839,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { DEVLINK_RELOAD_ACTION_MAX), [DEVLINK_ATTR_RELOAD_LIMITS] = NLA_POLICY_BITFIELD32(DEVLINK_RELOAD_LIMITS_VALID_MASK), [DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 }, + [DEVLINK_ATTR_LINECARD_TYPE] = { .type = NLA_NUL_STRING }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -7806,6 +7887,20 @@ static const struct genl_small_ops devlink_nl_ops[] = { .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, /* can be retrieved by unprivileged users */ }, + { + .cmd = DEVLINK_CMD_LINECARD_PROVISION, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = devlink_nl_cmd_linecard_provision_doit, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, + }, + { + .cmd = DEVLINK_CMD_LINECARD_UNPROVISION, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = devlink_nl_cmd_linecard_unprovision_doit, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, + }, { .cmd = DEVLINK_CMD_SB_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -8613,11 +8708,17 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, * Create devlink linecard instance with provided linecard index. * Caller can use any indexing, even hw-related one. */ -struct devlink_linecard *devlink_linecard_create(struct devlink *devlink, - unsigned int linecard_index) +struct devlink_linecard * +devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, + const struct devlink_linecard_ops *ops, void *priv) { struct devlink_linecard *linecard; + if (WARN_ON(!ops || !ops->supported_types || + !ops->supported_types_count || + !ops->provision || !ops->unprovision)) + return ERR_PTR(-EINVAL); + mutex_lock(&devlink->lock); if (devlink_linecard_index_exists(devlink, linecard_index)) { mutex_unlock(&devlink->lock); @@ -8630,6 +8731,9 @@ struct devlink_linecard *devlink_linecard_create(struct devlink *devlink, linecard->devlink = devlink; linecard->index = linecard_index; + linecard->ops = ops; + linecard->priv = priv; + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; list_add_tail(&linecard->list, &devlink->linecard_list); mutex_unlock(&devlink->lock); devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); @@ -8653,6 +8757,39 @@ void devlink_linecard_destroy(struct devlink_linecard *linecard) } EXPORT_SYMBOL_GPL(devlink_linecard_create); +/** + * devlink_linecard_provision_set - Set provisioning on linecard + * + * @devlink_linecard: devlink linecard + * @type_index: index of the linecard type (in array of types in ops) + */ +void devlink_linecard_provision_set(struct devlink_linecard *linecard, + u32 type_index) +{ + WARN_ON(type_index >= linecard->ops->supported_types_count); + mutex_lock(&linecard->devlink->lock); + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; + linecard->provisioned_type = linecard->ops->supported_types[type_index]; + mutex_unlock(&linecard->devlink->lock); + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); +} +EXPORT_SYMBOL_GPL(devlink_linecard_provision_set); + +/** + * devlink_linecard_provision_clear - Clear provisioning on linecard + * + * @devlink_linecard: devlink linecard + */ +void devlink_linecard_provision_clear(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->devlink->lock); + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; + linecard->provisioned_type = NULL; + mutex_unlock(&linecard->devlink->lock); + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); +} +EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear); + int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count, From patchwork Wed Jan 13 12:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 362645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E026C433DB for ; Wed, 13 Jan 2021 12:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C78AB233F8 for ; Wed, 13 Jan 2021 12:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727359AbhAMMNL (ORCPT ); Wed, 13 Jan 2021 07:13:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726852AbhAMMNK (ORCPT ); Wed, 13 Jan 2021 07:13:10 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D39C0C06179F for ; Wed, 13 Jan 2021 04:12:29 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id a12so1856699wrv.8 for ; Wed, 13 Jan 2021 04:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2/6Viei4wUAY+PsK+PLnXLv1pWrXcOkQrAGShU5Kxx0=; b=aCvq8iXZdjuUWvW7dTYgMdsItdhNtG2eb+XPfDTlHe/Z2LH6srjt30M/pBh35TF0kY pwd9AtKft2XUOXusNn4SkFUkjWYALgvpbUz+GCn3UrxChDOy1MESKXZ1jDvSQgJAt107 WcHEoPFKarrz0AxQpMMfkBuW+b21m5lxjFx2FG1eA42Mwg2gTvAmI1HzoVUkzcCujyhJ R2tO0hanqESY5EydvcOtay6YjzevEfjVb5MHb3mRSSQpKJ9Oefxs6idpC9PO1VXYlf7P FNZHiFcEPMOO+hFU1ifOQjfBcPV1+xqb+vbfU8XFAh25/yAU+yF7ODzvdtkwZxBIco1Z WHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2/6Viei4wUAY+PsK+PLnXLv1pWrXcOkQrAGShU5Kxx0=; b=N2CiaF7f4xa4b4jaPehKReJqrz+pM9/p58yvEXVbQTa0Mqzkp3jR0XoJEIeKfq2t0t DhgFKKS19QnRwzi5vVR7HRo8uxD4pt8pfC7XmbO8cXTVA+zTUmWLlhHYYAi7TsxPZc68 9FcKjSBWjAfQDGFsOxTDdfHJJyXjurXi6F4p8jcSm8nH6dJMb+gBf4WcZbiyVcf+6saZ 381b+QkzSJcUy5M/HycAwna7WFLJrxUSp6+jOiOo9EBdTJgYn6fKp2CIoPOa50SmHUwH khQwjIx038U52Pipz1DRyNKVTr9TW5ZNsjd/yNkUknCUSyGX+Qrj0y0GIcLtXK1v9g6g 6Apw== X-Gm-Message-State: AOAM531VspmnRZbqJWcK0b5NWyn3s3lx681vH9dPNsXO75gQcwrWMag+ wQl6Q5YfcTPorTAKRIW3debekFh3duYVkOqw X-Google-Smtp-Source: ABdhPJzHNmitR6ByHql70eU9T1mupHyKJ7wwagKU8dtNCUQ3dMRuEPuAVuc4TiyRa4zSihoZuZC7CA== X-Received: by 2002:adf:92a4:: with SMTP id 33mr2274641wrn.347.1610539948324; Wed, 13 Jan 2021 04:12:28 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id v65sm2867470wme.23.2021.01.13.04.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:27 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jacob.e.keller@intel.com, roopa@nvidia.com, mlxsw@nvidia.com Subject: [patch net-next RFC 04/10] devlink: append split port number to the port name Date: Wed, 13 Jan 2021 13:12:16 +0100 Message-Id: <20210113121222.733517-5-jiri@resnulli.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210113121222.733517-1-jiri@resnulli.us> References: <20210113121222.733517-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Instead of doing sprintf twice in case the port is split or not, append the split port suffix in case the port is split. Signed-off-by: Jiri Pirko --- net/core/devlink.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index 9c76edf8c8af..347976b88404 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -8654,12 +8654,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, switch (attrs->flavour) { case DEVLINK_PORT_FLAVOUR_PHYSICAL: case DEVLINK_PORT_FLAVOUR_VIRTUAL: - if (!attrs->split) - n = snprintf(name, len, "p%u", attrs->phys.port_number); - else - n = snprintf(name, len, "p%us%u", - attrs->phys.port_number, - attrs->phys.split_subport_number); + n = snprintf(name, len, "p%u", attrs->phys.port_number); + if (attrs->split) + n += snprintf(name + n, len - n, "s%u", + attrs->phys.split_subport_number); break; case DEVLINK_PORT_FLAVOUR_CPU: case DEVLINK_PORT_FLAVOUR_DSA: From patchwork Wed Jan 13 12:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 362642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8178FC433E6 for ; Wed, 13 Jan 2021 12:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A6F4233F8 for ; Wed, 13 Jan 2021 12:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbhAMMNq (ORCPT ); Wed, 13 Jan 2021 07:13:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726244AbhAMMNq (ORCPT ); Wed, 13 Jan 2021 07:13:46 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 313D2C0617A2 for ; Wed, 13 Jan 2021 04:12:31 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id q18so1893994wrn.1 for ; Wed, 13 Jan 2021 04:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=teuEjPh52h3oV1ShtApks7daisOe6Febjyada3/d28o=; b=BdKdNPcvNjL2nNL3ZQ7/aNO7WOPaPBPlR3wp9z9DBwRkVlcbS5K1C4mvIpDCplzVFq FFK2fMZ4rgdbNDfyCOGjYZjoEblEdqT4bRK3bRHU2xZIuntzhXDUmS9U4J0AOuh7+SbM kQmBpxBtHZQZNk1tNQW/tt4LbWR13CJn9CGBfXM5EPqgdirqFdgmAJikRlCCXbW2ekdK J4Kvak+IdJ8G8PEjNTNR/jbTmAfYUPDXVImVa0byKb9Rg1ZGkljwoqOMCZuxZ7uHXFm2 b6QK4UTtdr3E98qBrGrKJWIsEfKMu7c+9rRgJp3dReAUadxXxQB8iB5rIqrgOLLDSo8R GHoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=teuEjPh52h3oV1ShtApks7daisOe6Febjyada3/d28o=; b=DPoRij/AIp6PUCFb4YZvnyoy9R4iDH/80j+Kqg7w/oq9tidXSzJGx7PzQQ/gbQSrfJ n2pWfSAd/sbEXtcq/J5fCTIwsaw3u8LB/n6d5ii2xXdBeeU0VDVxKbInb22DaELoMgJU RYPtk1Y3uBz8F4BxuiqnedkUXaD+HoBP/bekx8wmUNC3xMuNLwYc/rOYjTY9fdXMT5fk e8bq1cSl3/MViUnzCjMGDMUZeeLvKL7VG4wJ46kHKQW8sND+10xKlhMDmhcFmQulNV6i ZI9/RQcz84ctaS7bHpgRy75jUCZyMwK421r4i8JP3jchpbB0mF3sW9eYdRmZI5Qxnc8+ 1vdA== X-Gm-Message-State: AOAM533WEh1ake9hafoJyujStlFEOfcDc9qPZ+R+EZJT2ZbFWR3kednW Ce0rlVZByAsphkxVj6X7bwMQIFB4ueSAbbZo X-Google-Smtp-Source: ABdhPJwQ1OArMWrEE69pix+F6MLx9tHbZg/imnX80/F71y2PiNBs60iE1eH/64q6Kt/rk38tq1rW9Q== X-Received: by 2002:a5d:4ad0:: with SMTP id y16mr2288778wrs.424.1610539949631; Wed, 13 Jan 2021 04:12:29 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id c6sm3176111wrh.7.2021.01.13.04.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:29 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jacob.e.keller@intel.com, roopa@nvidia.com, mlxsw@nvidia.com Subject: [patch net-next RFC 05/10] devlink: add port to line card relationship set Date: Wed, 13 Jan 2021 13:12:17 +0100 Message-Id: <20210113121222.733517-6-jiri@resnulli.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210113121222.733517-1-jiri@resnulli.us> References: <20210113121222.733517-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko In order to properly inform user about relationship between port and line card, introduce a driver API to set line card for a port. Use this information to extend port devlink netlink message by line card index and also include the line card index into phys_port_name and by that into a netdevice name. Signed-off-by: Jiri Pirko --- include/net/devlink.h | 3 +++ net/core/devlink.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index ec00cd94c626..cb911b6fdeda 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -137,6 +137,7 @@ struct devlink_port { struct delayed_work type_warn_dw; struct list_head reporter_list; struct mutex reporters_lock; /* Protects reporter_list */ + struct devlink_linecard *linecard; }; struct devlink_linecard_ops; @@ -1438,6 +1439,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro u16 pf, bool external); void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller, u16 pf, u16 vf, bool external); +void devlink_port_linecard_set(struct devlink_port *devlink_port, + struct devlink_linecard *linecard); struct devlink_linecard * devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index, const struct devlink_linecard_ops *ops, void *priv); diff --git a/net/core/devlink.c b/net/core/devlink.c index 347976b88404..2faa30cc5cce 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -855,6 +855,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure; if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack)) goto nla_put_failure; + if (devlink_port->linecard && + nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, + devlink_port->linecard->index)) + goto nla_put_failure; genlmsg_end(msg, hdr); return 0; @@ -8642,6 +8646,21 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro } EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set); +/** + * devlink_port_linecard_set - Link port with a linecard + * + * @devlink_port: devlink port + * @devlink_linecard: devlink linecard + */ +void devlink_port_linecard_set(struct devlink_port *devlink_port, + struct devlink_linecard *linecard) +{ + if (WARN_ON(devlink_port->registered)) + return; + devlink_port->linecard = linecard; +} +EXPORT_SYMBOL_GPL(devlink_port_linecard_set); + static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, char *name, size_t len) { @@ -8654,7 +8673,11 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, switch (attrs->flavour) { case DEVLINK_PORT_FLAVOUR_PHYSICAL: case DEVLINK_PORT_FLAVOUR_VIRTUAL: - n = snprintf(name, len, "p%u", attrs->phys.port_number); + if (devlink_port->linecard) + n = snprintf(name, len, "l%u", + devlink_port->linecard->index); + n += snprintf(name + n, len - n, "p%u", + attrs->phys.port_number); if (attrs->split) n += snprintf(name + n, len - n, "s%u", attrs->phys.split_subport_number); From patchwork Wed Jan 13 12:12:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 362644 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56ED6C433E6 for ; Wed, 13 Jan 2021 12:13:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0938A233F8 for ; Wed, 13 Jan 2021 12:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727380AbhAMMNs (ORCPT ); Wed, 13 Jan 2021 07:13:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbhAMMNr (ORCPT ); Wed, 13 Jan 2021 07:13:47 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAFAC0617A4 for ; Wed, 13 Jan 2021 04:12:33 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id r3so1891188wrt.2 for ; Wed, 13 Jan 2021 04:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vOhGgb7y/DuZ0fHW4uLtmD1PoVTLNKXc3BKeuKC8gZg=; b=wIu2gFvs/WNX/DG4WKt8ixD6cElrmCzJILAMzr0nlDopYpWBvnwKmQC9iGtBc6I9B1 /QSbqnrALaKDifMi19rqnqGsd4l3X3LxU/5MUoB9KJwE58fvcSEmw2GPbLRew29L9/D5 t8UX6/N9vfgbcGn7ihuWm49m2QG3WXJuUVWhaq7Ge86jYhyYkq+8MBppCHnLRzY8pMsl YQ7GzZYl5tVUexyQ+LU5Kpxr/4rByb35lpmIS2tLBrFdnI2QSHamGhiXPbysYPnHkVQr PPsjuUh44qNSLE3ZN+EesCXa+YKTqbWPblEr/Pbg1IfRj2hvOYTDOrFAMTS6R0jwhFQq /G7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vOhGgb7y/DuZ0fHW4uLtmD1PoVTLNKXc3BKeuKC8gZg=; b=RNZNvztQ4u1J20/pWs6AzpNUxF/Ep6WFrq8yKkmM/hKa0RrHQI2eMi32Hb5RHJ0J1w N1EZxXIjIW48SA42GBBkAR9Icv6nuA4Bktittnb+ShyyyYRSgURQVimMC80KXodRdhzQ Z1UWBDvv9p5J1RCIDzSc4o52B5D/15pVx3vbOtzyYe9smmOB+2cxaHj+PfQkDTvuY0zR vIjnJF2o/GaNcuuUGIWZuJ/0HR9QZVtK2D7SV9qRZ3+lHw6tVDdH1vRAbAhI9f+a7MsU 3I8a95j+VMUWSj+4s0b5qf10YyE/PNP+HB8UZm8OMQx3o0oQfoDwdYmFjPZHLTowimYm x3Uw== X-Gm-Message-State: AOAM533uAm//JzdgeJxt+0i5j05D81ZArsfXNDAzhNP3900bD8B0vr7p VSWkavtsH4+dUDOt/f7EJgAOp38OtCUM6PBe X-Google-Smtp-Source: ABdhPJy5SwFxJNcPaTN5bx5UTR4+oEPKct6KBOJQrsjoJsT7RFm+sMsMzNGxKYUmmodwT/fRRnEjBg== X-Received: by 2002:adf:dd90:: with SMTP id x16mr2265682wrl.85.1610539951945; Wed, 13 Jan 2021 04:12:31 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id h15sm3121168wru.4.2021.01.13.04.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:31 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jacob.e.keller@intel.com, roopa@nvidia.com, mlxsw@nvidia.com Subject: [patch net-next RFC 07/10] netdevsim: allow port objects to be linked with line cards Date: Wed, 13 Jan 2021 13:12:19 +0100 Message-Id: <20210113121222.733517-8-jiri@resnulli.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210113121222.733517-1-jiri@resnulli.us> References: <20210113121222.733517-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Line cards contain ports. Allow ports to be places on the line cards. Track the ports that belong under certain line card. Make sure that the line card port carrier is down, as it will be taken up later on during "activation". Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/bus.c | 4 +-- drivers/net/netdevsim/dev.c | 48 +++++++++++++++++++++++++------ drivers/net/netdevsim/netdev.c | 2 ++ drivers/net/netdevsim/netdevsim.h | 4 +++ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index ed57c012e660..a0afd30d76e6 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -113,7 +113,7 @@ new_port_store(struct device *dev, struct device_attribute *attr, mutex_lock(&nsim_bus_dev->nsim_bus_reload_lock); devlink_reload_disable(devlink); - ret = nsim_dev_port_add(nsim_bus_dev, port_index); + ret = nsim_dev_port_add(nsim_bus_dev, NULL, port_index); devlink_reload_enable(devlink); mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock); return ret ? ret : count; @@ -142,7 +142,7 @@ del_port_store(struct device *dev, struct device_attribute *attr, mutex_lock(&nsim_bus_dev->nsim_bus_reload_lock); devlink_reload_disable(devlink); - ret = nsim_dev_port_del(nsim_bus_dev, port_index); + ret = nsim_dev_port_del(nsim_bus_dev, NULL, port_index); devlink_reload_enable(devlink); mutex_unlock(&nsim_bus_dev->nsim_bus_reload_lock); return ret ? ret : count; diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index d81ccfa05a28..e706317fc0f9 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -35,6 +35,21 @@ #include "netdevsim.h" +#define NSIM_DEV_LINECARD_PORT_INDEX_BASE 1000 +#define NSIM_DEV_LINECARD_PORT_INDEX_STEP 100 + +static unsigned int +nsim_dev_port_index(struct nsim_dev_linecard *nsim_dev_linecard, + unsigned int port_index) +{ + if (!nsim_dev_linecard) + return port_index; + + return NSIM_DEV_LINECARD_PORT_INDEX_BASE + + nsim_dev_linecard->linecard_index * NSIM_DEV_LINECARD_PORT_INDEX_STEP + + port_index; +} + static struct dentry *nsim_dev_ddir; #define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32) @@ -942,6 +957,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = { #define NSIM_DEV_TEST1_DEFAULT true static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, + struct nsim_dev_linecard *nsim_dev_linecard, unsigned int port_index) { struct devlink_port_attrs attrs = {}; @@ -952,8 +968,9 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, nsim_dev_port = kzalloc(sizeof(*nsim_dev_port), GFP_KERNEL); if (!nsim_dev_port) return -ENOMEM; - nsim_dev_port->port_index = port_index; - + nsim_dev_port->port_index = nsim_dev_port_index(nsim_dev_linecard, + port_index); + nsim_dev_port->linecard = nsim_dev_linecard; devlink_port = &nsim_dev_port->devlink_port; attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; attrs.phys.port_number = port_index + 1; @@ -961,7 +978,7 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, attrs.switch_id.id_len = nsim_dev->switch_id.id_len; devlink_port_attrs_set(devlink_port, &attrs); err = devlink_port_register(priv_to_devlink(nsim_dev), devlink_port, - port_index); + nsim_dev_port->port_index); if (err) goto err_port_free; @@ -975,6 +992,11 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, goto err_port_debugfs_exit; } + if (nsim_dev_linecard) + list_add(&nsim_dev_port->list_lc, &nsim_dev_linecard->port_list); + else + netif_carrier_on(nsim_dev_port->ns->netdev); + devlink_port_type_eth_set(devlink_port, nsim_dev_port->ns->netdev); list_add(&nsim_dev_port->list, &nsim_dev->port_list); @@ -994,6 +1016,8 @@ static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port) struct devlink_port *devlink_port = &nsim_dev_port->devlink_port; list_del(&nsim_dev_port->list); + if (nsim_dev_port->linecard) + list_del(&nsim_dev_port->list_lc); devlink_port_type_clear(devlink_port); nsim_destroy(nsim_dev_port->ns); nsim_dev_port_debugfs_exit(nsim_dev_port); @@ -1018,7 +1042,7 @@ static int nsim_dev_port_add_all(struct nsim_dev *nsim_dev, int i, err; for (i = 0; i < port_count; i++) { - err = __nsim_dev_port_add(nsim_dev, i); + err = __nsim_dev_port_add(nsim_dev, NULL, i); if (err) goto err_port_del_all; } @@ -1040,6 +1064,7 @@ static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, return -ENOMEM; nsim_dev_linecard->nsim_dev = nsim_dev; nsim_dev_linecard->linecard_index = linecard_index; + INIT_LIST_HEAD(&nsim_dev_linecard->port_list); err = nsim_dev_linecard_debugfs_init(nsim_dev, nsim_dev_linecard); if (err) @@ -1286,10 +1311,13 @@ void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev) } static struct nsim_dev_port * -__nsim_dev_port_lookup(struct nsim_dev *nsim_dev, unsigned int port_index) +__nsim_dev_port_lookup(struct nsim_dev *nsim_dev, + struct nsim_dev_linecard *nsim_dev_linecard, + unsigned int port_index) { struct nsim_dev_port *nsim_dev_port; + port_index = nsim_dev_port_index(nsim_dev_linecard, port_index); list_for_each_entry(nsim_dev_port, &nsim_dev->port_list, list) if (nsim_dev_port->port_index == port_index) return nsim_dev_port; @@ -1297,21 +1325,24 @@ __nsim_dev_port_lookup(struct nsim_dev *nsim_dev, unsigned int port_index) } int nsim_dev_port_add(struct nsim_bus_dev *nsim_bus_dev, + struct nsim_dev_linecard *nsim_dev_linecard, unsigned int port_index) { struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); int err; mutex_lock(&nsim_dev->port_list_lock); - if (__nsim_dev_port_lookup(nsim_dev, port_index)) + if (__nsim_dev_port_lookup(nsim_dev, nsim_dev_linecard, port_index)) err = -EEXIST; else - err = __nsim_dev_port_add(nsim_dev, port_index); + err = __nsim_dev_port_add(nsim_dev, nsim_dev_linecard, + port_index); mutex_unlock(&nsim_dev->port_list_lock); return err; } int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev, + struct nsim_dev_linecard *nsim_dev_linecard, unsigned int port_index) { struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); @@ -1319,7 +1350,8 @@ int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev, int err = 0; mutex_lock(&nsim_dev->port_list_lock); - nsim_dev_port = __nsim_dev_port_lookup(nsim_dev, port_index); + nsim_dev_port = __nsim_dev_port_lookup(nsim_dev, nsim_dev_linecard, + port_index); if (!nsim_dev_port) err = -ENOENT; else diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index aec92440eef1..1e0dc298bf20 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -312,6 +312,8 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) nsim_ipsec_init(ns); + netif_carrier_off(dev); + err = register_netdevice(dev); if (err) goto err_ipsec_teardown; diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index df10f9d11e9d..88b61b9390bf 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -184,6 +184,7 @@ struct nsim_dev_linecard; struct nsim_dev_port { struct list_head list; + struct list_head list_lc; /* node in linecard list */ struct devlink_port devlink_port; struct nsim_dev_linecard *linecard; unsigned int port_index; @@ -196,6 +197,7 @@ struct nsim_dev; struct nsim_dev_linecard { struct list_head list; struct nsim_dev *nsim_dev; + struct list_head port_list; unsigned int linecard_index; struct dentry *ddir; }; @@ -255,8 +257,10 @@ void nsim_dev_exit(void); int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev); void nsim_dev_remove(struct nsim_bus_dev *nsim_bus_dev); int nsim_dev_port_add(struct nsim_bus_dev *nsim_bus_dev, + struct nsim_dev_linecard *nsim_dev_linecard, unsigned int port_index); int nsim_dev_port_del(struct nsim_bus_dev *nsim_bus_dev, + struct nsim_dev_linecard *nsim_dev_linecard, unsigned int port_index); struct nsim_fib_data *nsim_fib_create(struct devlink *devlink, From patchwork Wed Jan 13 12:12:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 362643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 349CDC433E9 for ; Wed, 13 Jan 2021 12:13:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9161233F8 for ; Wed, 13 Jan 2021 12:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727403AbhAMMNt (ORCPT ); Wed, 13 Jan 2021 07:13:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727256AbhAMMNr (ORCPT ); Wed, 13 Jan 2021 07:13:47 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95A8C0617A5 for ; Wed, 13 Jan 2021 04:12:34 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id y187so1402789wmd.3 for ; Wed, 13 Jan 2021 04:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w7tEKM8STzYMPv/IRNCUuYVAkgY7njbrDoavQWdwiy4=; b=LdcwkXNtZp8GXY0OiBYvmdMmH1EtTi2vgQa7cz6tmFuMR1EucG+93TvLVhcY8MWQ9E PzA3UbLMdl+80o+Ptw+Si3SQA4kY1DneF9qrVGd/5MgmDkHlhEqjPwKBg2NLZ3mtrt9P oQhceXjQUNZ4iA4qqs6Aep1eZ6Hsn+mGjWDTE02szL3KXO44BI+2CYD2uJsLTtK1pk3s Ad/QumlR2fO718xHSO6ZzsRZWBEYlX8c4tmHEVdNOUNDVNNJL+cO/UGlr0jzY3roiVm0 /xPcA9qP6Bap2pz98C0qNEB7jpkhm37+th/0krGEvz3U+NkpDSmwvJhdWJvDm7grMbI3 3etw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w7tEKM8STzYMPv/IRNCUuYVAkgY7njbrDoavQWdwiy4=; b=td1WGVC0XACBYvhux2syB21Ga/IhNMwYnjDKSWgblZmeW12/w1u66Ku2EdJliNoiTG mY6GRljSsbhEtAmDJEdrJw8SryK+Zu25dCxuT6k0GU1QJ+hTAqCndWT+YAtaRSSXy2k0 JJFd+dQ5jAtujllG0SCSf6mu61DQ9gqwda3l5tMr4UCaImponXTRq990zT51+4Mpa8Sl eP9ZjIXis3N9tMiZeDdf7FiJdbgM9HNB2yrkxBGOVfLCRdN8eMk6Onm023qZucUX6wLy Ds2iYn+IUqv41OsWvJ8o+nfU5Ksl4wBLYBOerBaNuK25kmv5sOBleUDWEyM+yVI4DQ1l /N4Q== X-Gm-Message-State: AOAM530TOkolaHIZ3liD+72KePXk3m/N9kxMaVQbAAnarGME/AEtoiuF nmrG4dw/UBrvWEq6MiTnq7BHzsREztR5GZ7y X-Google-Smtp-Source: ABdhPJyBWxYC2i/N897dJ0k8qxHoJ69xMdK/uy2E7irJCTvYxF9aY1hBARb77l6PjSoLbFZrOBR4bg== X-Received: by 2002:a1c:b742:: with SMTP id h63mr1918921wmf.122.1610539953152; Wed, 13 Jan 2021 04:12:33 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id u17sm2621431wmj.35.2021.01.13.04.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:32 -0800 (PST) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jacob.e.keller@intel.com, roopa@nvidia.com, mlxsw@nvidia.com Subject: [patch net-next RFC 08/10] netdevsim: create devlink line card object and implement provisioning Date: Wed, 13 Jan 2021 13:12:20 +0100 Message-Id: <20210113121222.733517-9-jiri@resnulli.us> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210113121222.733517-1-jiri@resnulli.us> References: <20210113121222.733517-1-jiri@resnulli.us> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Use devlink_linecard_create/destroy() to register the line card with devlink core. Implement provisioning ops with a list of supported line cards. To avoid deadlock and to mimic actual HW flow, use workqueue to add/del ports during provisioning as the port add/del calls devlink_port_register/unregister() which take devlink mutex. Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 135 +++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 4 + 2 files changed, 138 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index e706317fc0f9..9e9a2a75ddf8 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -35,6 +35,20 @@ #include "netdevsim.h" +static const char * const nsim_dev_linecard_supported_types[] = { + "card1port", "card2ports", "card4ports", +}; + +static const unsigned int nsim_dev_linecard_port_counts[] = { + 1, 2, 4, +}; + +static unsigned int +nsim_dev_linecard_port_count(struct nsim_dev_linecard *nsim_dev_linecard) +{ + return nsim_dev_linecard_port_counts[nsim_dev_linecard->type_index]; +} + #define NSIM_DEV_LINECARD_PORT_INDEX_BASE 1000 #define NSIM_DEV_LINECARD_PORT_INDEX_STEP 100 @@ -285,6 +299,25 @@ static void nsim_dev_port_debugfs_exit(struct nsim_dev_port *nsim_dev_port) debugfs_remove_recursive(nsim_dev_port->ddir); } +static ssize_t nsim_dev_linecard_type_read(struct file *file, char __user *data, + size_t count, loff_t *ppos) +{ + struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; + const char *type; + + if (!nsim_dev_linecard->provisioned) + return -EOPNOTSUPP; + + type = nsim_dev_linecard_supported_types[nsim_dev_linecard->type_index]; + return simple_read_from_buffer(data, count, ppos, type, strlen(type)); +} + +static const struct file_operations nsim_dev_linecard_type_fops = { + .open = simple_open, + .read = nsim_dev_linecard_type_read, + .owner = THIS_MODULE, +}; + static int nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev, struct nsim_dev_linecard *nsim_dev_linecard) @@ -301,6 +334,8 @@ nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev, sprintf(dev_link_name, "../../../" DRV_NAME "%u", nsim_dev->nsim_bus_dev->dev.id); debugfs_create_symlink("dev", nsim_dev_linecard->ddir, dev_link_name); + debugfs_create_file("type", 0400, nsim_dev_linecard->ddir, + nsim_dev_linecard, &nsim_dev_linecard_type_fops); return 0; } @@ -977,6 +1012,9 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, memcpy(attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); attrs.switch_id.id_len = nsim_dev->switch_id.id_len; devlink_port_attrs_set(devlink_port, &attrs); + if (nsim_dev_linecard) + devlink_port_linecard_set(devlink_port, + nsim_dev_linecard->devlink_linecard); err = devlink_port_register(priv_to_devlink(nsim_dev), devlink_port, nsim_dev_port->port_index); if (err) @@ -1053,10 +1091,88 @@ static int nsim_dev_port_add_all(struct nsim_dev *nsim_dev, return err; } +static void nsim_dev_linecard_provision_work(struct work_struct *work) +{ + struct nsim_dev_linecard *nsim_dev_linecard; + struct nsim_bus_dev *nsim_bus_dev; + int err; + int i; + + nsim_dev_linecard = container_of(work, struct nsim_dev_linecard, + provision_work); + + nsim_bus_dev = nsim_dev_linecard->nsim_dev->nsim_bus_dev; + for (i = 0; i < nsim_dev_linecard_port_count(nsim_dev_linecard); i++) { + err = nsim_dev_port_add(nsim_bus_dev, nsim_dev_linecard, i); + if (err) + goto err_port_del_all; + } + nsim_dev_linecard->provisioned = true; + devlink_linecard_provision_set(nsim_dev_linecard->devlink_linecard, + nsim_dev_linecard->type_index); + return; + +err_port_del_all: + for (i--; i >= 0; i--) + nsim_dev_port_del(nsim_bus_dev, nsim_dev_linecard, i); + devlink_linecard_provision_clear(nsim_dev_linecard->devlink_linecard); +} + +static int nsim_dev_linecard_provision(struct devlink_linecard *linecard, + void *priv, u32 type_index, + struct netlink_ext_ack *extack) +{ + struct nsim_dev_linecard *nsim_dev_linecard = priv; + + nsim_dev_linecard->type_index = type_index; + INIT_WORK(&nsim_dev_linecard->provision_work, + nsim_dev_linecard_provision_work); + schedule_work(&nsim_dev_linecard->provision_work); + + return 0; +} + +static void nsim_dev_linecard_unprovision_work(struct work_struct *work) +{ + struct nsim_dev_linecard *nsim_dev_linecard; + struct nsim_bus_dev *nsim_bus_dev; + int i; + + nsim_dev_linecard = container_of(work, struct nsim_dev_linecard, + provision_work); + + nsim_bus_dev = nsim_dev_linecard->nsim_dev->nsim_bus_dev; + nsim_dev_linecard->provisioned = false; + devlink_linecard_provision_clear(nsim_dev_linecard->devlink_linecard); + for (i = 0; i < nsim_dev_linecard_port_count(nsim_dev_linecard); i++) + nsim_dev_port_del(nsim_bus_dev, nsim_dev_linecard, i); +} + +static int nsim_dev_linecard_unprovision(struct devlink_linecard *linecard, + void *priv, + struct netlink_ext_ack *extack) +{ + struct nsim_dev_linecard *nsim_dev_linecard = priv; + + INIT_WORK(&nsim_dev_linecard->provision_work, + nsim_dev_linecard_unprovision_work); + schedule_work(&nsim_dev_linecard->provision_work); + + return 0; +} + +static const struct devlink_linecard_ops nsim_dev_linecard_ops = { + .supported_types = nsim_dev_linecard_supported_types, + .supported_types_count = ARRAY_SIZE(nsim_dev_linecard_supported_types), + .provision = nsim_dev_linecard_provision, + .unprovision = nsim_dev_linecard_unprovision, +}; + static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, unsigned int linecard_index) { struct nsim_dev_linecard *nsim_dev_linecard; + struct devlink_linecard *devlink_linecard; int err; nsim_dev_linecard = kzalloc(sizeof(*nsim_dev_linecard), GFP_KERNEL); @@ -1066,14 +1182,27 @@ static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, nsim_dev_linecard->linecard_index = linecard_index; INIT_LIST_HEAD(&nsim_dev_linecard->port_list); + devlink_linecard = devlink_linecard_create(priv_to_devlink(nsim_dev), + linecard_index, + &nsim_dev_linecard_ops, + nsim_dev_linecard); + if (IS_ERR(devlink_linecard)) { + err = PTR_ERR(devlink_linecard); + goto err_linecard_free; + } + + nsim_dev_linecard->devlink_linecard = devlink_linecard; + err = nsim_dev_linecard_debugfs_init(nsim_dev, nsim_dev_linecard); if (err) - goto err_linecard_free; + goto err_dl_linecard_destroy; list_add(&nsim_dev_linecard->list, &nsim_dev->linecard_list); return 0; +err_dl_linecard_destroy: + devlink_linecard_destroy(devlink_linecard); err_linecard_free: kfree(nsim_dev_linecard); return err; @@ -1081,8 +1210,12 @@ static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, static void __nsim_dev_linecard_del(struct nsim_dev_linecard *nsim_dev_linecard) { + struct devlink_linecard *devlink_linecard = + nsim_dev_linecard->devlink_linecard; + list_del(&nsim_dev_linecard->list); nsim_dev_linecard_debugfs_exit(nsim_dev_linecard); + devlink_linecard_destroy(devlink_linecard); kfree(nsim_dev_linecard); } diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 88b61b9390bf..ab217b361416 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -196,10 +196,14 @@ struct nsim_dev; struct nsim_dev_linecard { struct list_head list; + struct devlink_linecard *devlink_linecard; struct nsim_dev *nsim_dev; struct list_head port_list; unsigned int linecard_index; struct dentry *ddir; + bool provisioned; + u32 type_index; + struct work_struct provision_work; }; struct nsim_dev {