From patchwork Wed Jan 13 12:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12016655 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 X-Spam-Level: X-Spam-Status: No, score=-14.0 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,UNWANTED_LANGUAGE_BODY, 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 AEC9EC433E6 for ; Wed, 13 Jan 2021 12:13:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 579E523120 for ; Wed, 13 Jan 2021 12:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbhAMMNH (ORCPT ); Wed, 13 Jan 2021 07:13:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726834AbhAMMNH (ORCPT ); Wed, 13 Jan 2021 07:13:07 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94515C061786 for ; Wed, 13 Jan 2021 04:12:26 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id 91so1868459wrj.7 for ; Wed, 13 Jan 2021 04:12:26 -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=l5oNXmwmy/iZXgUmTX4ON2k66GUzJt8/nt5Sf8nKUDI=; b=0WK07mMnq68B4Ax4an15CQZSVzJZVn0p+LpmYqMhLlkiMrXf8KD+6qFl71U90fyXXo mpUWE3YwfMcelw84wpyE817yrGLduB7tUSqUQXUR6NWZfNpU9NsfKd7hEaIyEaC8C8h7 XgRLcw8QjvhnTvEqwXcce0h/kY69P1L0WMWmPEtC2zdYSE6AbnyxeAat+kbkDhq1AD+p HYhCS2E7s6pjXd8+z5dNqmPEitj0/p+5KKizVxUpTdXtYGjKAZkpH3vkalrFSmgi1Gtv kygv227H57LYfCtWaeKxnETAw/kxCvW9glF6X5CaEC7FCKddLjG8zEVrxFAQVD+h55Z+ h0Xg== 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=l5oNXmwmy/iZXgUmTX4ON2k66GUzJt8/nt5Sf8nKUDI=; b=TEXoAat3LJGlfiKoEEjjghMsXrgrLEXOrHOWF4zPkE74Y0CTLT/mDcZXXxOJ1E0jZC 7Vhxa0KhsjpxX/FRH0aWZcU1ToUkLSfb/5rVvmYqteTtVP+iUotQIBdEy7Y9G54uasIP 9nH7V8IQheuJqoWNw9Gl02bCY7nVebYzuTy+LH98fKt0+ThWfzkILO35Z5IYhsT8qLHS iRUKYXmoGHGHTG7K/5+yG2ufg2aL0baBsaDxIJ5pD8QGZ87SexBv1NaKvP9qXzkLPBHp yG1S5ELEDQjAVqn5bf6HU87umPjJ0Uop2+I2/Yir7uW/rlW5wLZZY7vKUs/eNWInqQ2V P9Hw== X-Gm-Message-State: AOAM5322yZfW8GZpmaK/E+vTlEut9dNdQRSGow9ntZOLRyKAcUQ1+apZ SvtrIboYziLOWPIyI/WUfX67Ti2v07pSFr1X X-Google-Smtp-Source: ABdhPJzMVFkTE3T+Io0bulr9kEfTEDWkiyvnKiyadsOwwyppAkVzUkb37KvepiYohy0npwi6cTKOMg== X-Received: by 2002:a5d:5917:: with SMTP id v23mr2407539wrd.308.1610539944991; Wed, 13 Jan 2021 04:12:24 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id h16sm2633813wmb.41.2021.01.13.04.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:24 -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 01/10] devlink: add support to create line card and expose to user Date: Wed, 13 Jan 2021 13:12:13 +0100 Message-Id: <20210113121222.733517-2-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jiri Pirko Extend the devlink API so the driver is going to be able to create and destroy linecard instances. There can be multiple line cards per devlink device. Expose this new type of object over devlink netlink API to the userspace, with notifications. Signed-off-by: Jiri Pirko --- include/net/devlink.h | 10 ++ include/uapi/linux/devlink.h | 7 ++ net/core/devlink.c | 227 ++++++++++++++++++++++++++++++++++- 3 files changed, 243 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index dd0c0b8fba6e..67c2547d5ef9 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -45,6 +45,7 @@ struct devlink { struct list_head trap_list; struct list_head trap_group_list; struct list_head trap_policer_list; + struct list_head linecard_list; const struct devlink_ops *ops; struct xarray snapshot_ids; struct devlink_dev_stats stats; @@ -138,6 +139,12 @@ struct devlink_port { struct mutex reporters_lock; /* Protects reporter_list */ }; +struct devlink_linecard { + struct list_head list; + struct devlink *devlink; + unsigned int index; +}; + struct devlink_sb_pool_info { enum devlink_sb_pool_type pool_type; u32 size; @@ -1407,6 +1414,9 @@ 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); +void devlink_linecard_destroy(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 cf89c318f2ac..e5ed0522591f 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -126,6 +126,11 @@ enum devlink_command { DEVLINK_CMD_HEALTH_REPORTER_TEST, + DEVLINK_CMD_LINECARD_GET, /* can dump */ + DEVLINK_CMD_LINECARD_SET, + DEVLINK_CMD_LINECARD_NEW, + DEVLINK_CMD_LINECARD_DEL, + /* add new commands above here */ __DEVLINK_CMD_MAX, DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1 @@ -529,6 +534,8 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION_INFO, /* nested */ DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ + DEVLINK_ATTR_LINECARD_INDEX, /* u32 */ + /* 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 f86688bfad46..564e921133cf 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -187,6 +187,46 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink, return devlink_port_get_from_attrs(devlink, info->attrs); } +static struct devlink_linecard * +devlink_linecard_get_by_index(struct devlink *devlink, + unsigned int linecard_index) +{ + struct devlink_linecard *devlink_linecard; + + list_for_each_entry(devlink_linecard, &devlink->linecard_list, list) { + if (devlink_linecard->index == linecard_index) + return devlink_linecard; + } + return NULL; +} + +static bool devlink_linecard_index_exists(struct devlink *devlink, + unsigned int linecard_index) +{ + return devlink_linecard_get_by_index(devlink, linecard_index); +} + +static struct devlink_linecard * +devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) +{ + if (attrs[DEVLINK_ATTR_LINECARD_INDEX]) { + u32 linecard_index = nla_get_u32(attrs[DEVLINK_ATTR_LINECARD_INDEX]); + struct devlink_linecard *linecard; + + linecard = devlink_linecard_get_by_index(devlink, linecard_index); + if (!linecard) + return ERR_PTR(-ENODEV); + return linecard; + } + return ERR_PTR(-EINVAL); +} + +static struct devlink_linecard * +devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) +{ + return devlink_linecard_get_from_attrs(devlink, info->attrs); +} + struct devlink_sb { struct list_head list; unsigned int index; @@ -405,16 +445,18 @@ devlink_region_snapshot_get_by_id(struct devlink_region *region, u32 id) #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) +#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(2) /* The per devlink instance lock is taken by default in the pre-doit * operation, yet several commands do not require this. The global * devlink lock is taken and protects from disruption by user-calls. */ -#define DEVLINK_NL_FLAG_NO_LOCK BIT(2) +#define DEVLINK_NL_FLAG_NO_LOCK BIT(3) static int devlink_nl_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, struct genl_info *info) { + struct devlink_linecard *linecard; struct devlink_port *devlink_port; struct devlink *devlink; int err; @@ -439,6 +481,13 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, devlink_port = devlink_port_get_from_info(devlink, info); if (!IS_ERR(devlink_port)) info->user_ptr[1] = devlink_port; + } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) { + linecard = devlink_linecard_get_from_info(devlink, info); + if (IS_ERR(linecard)) { + err = PTR_ERR(linecard); + goto unlock; + } + info->user_ptr[1] = linecard; } return 0; @@ -1136,6 +1185,121 @@ static int devlink_nl_cmd_port_unsplit_doit(struct sk_buff *skb, return devlink_port_unsplit(devlink, port_index, info->extack); } +static int devlink_nl_linecard_fill(struct sk_buff *msg, + struct devlink *devlink, + struct devlink_linecard *linecard, + enum devlink_command cmd, u32 portid, + u32 seq, int flags, + struct netlink_ext_ack *extack) +{ + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); + if (!hdr) + return -EMSGSIZE; + + if (devlink_nl_put_handle(msg, devlink)) + goto nla_put_failure; + if (nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, linecard->index)) + goto nla_put_failure; + + genlmsg_end(msg, hdr); + return 0; + +nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + +static void devlink_linecard_notify(struct devlink_linecard *linecard, + enum devlink_command cmd) +{ + struct devlink *devlink = linecard->devlink; + struct sk_buff *msg; + int err; + + WARN_ON(cmd != DEVLINK_CMD_LINECARD_NEW && + cmd != DEVLINK_CMD_LINECARD_DEL); + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return; + + err = devlink_nl_linecard_fill(msg, devlink, linecard, cmd, 0, 0, 0, + NULL); + if (err) { + nlmsg_free(msg); + return; + } + + genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), + msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); +} + +static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_linecard *linecard = info->user_ptr[1]; + struct devlink *devlink = linecard->devlink; + struct sk_buff *msg; + int err; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + err = devlink_nl_linecard_fill(msg, devlink, linecard, + DEVLINK_CMD_LINECARD_NEW, + info->snd_portid, info->snd_seq, 0, + info->extack); + if (err) { + nlmsg_free(msg); + return err; + } + + return genlmsg_reply(msg, info); +} + +static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) +{ + struct devlink_linecard *linecard; + struct devlink *devlink; + int start = cb->args[0]; + int idx = 0; + int err; + + mutex_lock(&devlink_mutex); + list_for_each_entry(devlink, &devlink_list, list) { + if (!net_eq(devlink_net(devlink), sock_net(msg->sk))) + continue; + mutex_lock(&devlink->lock); + list_for_each_entry(linecard, &devlink->linecard_list, list) { + if (idx < start) { + idx++; + continue; + } + err = devlink_nl_linecard_fill(msg, devlink, linecard, + DEVLINK_CMD_LINECARD_NEW, + NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, + NLM_F_MULTI, + cb->extack); + if (err) { + mutex_unlock(&devlink->lock); + goto out; + } + idx++; + } + mutex_unlock(&devlink->lock); + } +out: + mutex_unlock(&devlink_mutex); + + cb->args[0] = idx; + return msg->len; +} + static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, enum devlink_command cmd, u32 portid, @@ -7594,6 +7758,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_RELOAD_ACTION] = NLA_POLICY_RANGE(NLA_U8, DEVLINK_RELOAD_ACTION_DRIVER_REINIT, DEVLINK_RELOAD_ACTION_MAX), [DEVLINK_ATTR_RELOAD_LIMITS] = NLA_POLICY_BITFIELD32(DEVLINK_RELOAD_LIMITS_VALID_MASK), + [DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -7633,6 +7798,14 @@ static const struct genl_small_ops devlink_nl_ops[] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NO_LOCK, }, + { + .cmd = DEVLINK_CMD_LINECARD_GET, + .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, + .doit = devlink_nl_cmd_linecard_get_doit, + .dumpit = devlink_nl_cmd_linecard_get_dumpit, + .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, + /* can be retrieved by unprivileged users */ + }, { .cmd = DEVLINK_CMD_SB_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -7982,6 +8155,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size) xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); __devlink_net_set(devlink, &init_net); INIT_LIST_HEAD(&devlink->port_list); + INIT_LIST_HEAD(&devlink->linecard_list); INIT_LIST_HEAD(&devlink->sb_list); INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list); INIT_LIST_HEAD(&devlink->resource_list); @@ -8084,6 +8258,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->resource_list)); WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); + WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!list_empty(&devlink->port_list)); xa_destroy(&devlink->snapshot_ids); @@ -8428,6 +8603,56 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, return 0; } +/** + * devlink_linecard_register - Register devlink linecard + * + * @devlink: devlink + * @devlink_linecard: devlink linecard + * @linecard_index: driver-specific numerical identifier of the linecard + * + * 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 *linecard; + + mutex_lock(&devlink->lock); + if (devlink_linecard_index_exists(devlink, linecard_index)) { + mutex_unlock(&devlink->lock); + return ERR_PTR(-EEXIST); + } + + linecard = kzalloc(sizeof(*linecard), GFP_KERNEL); + if (!linecard) + return ERR_PTR(-ENOMEM); + + linecard->devlink = devlink; + linecard->index = linecard_index; + list_add_tail(&linecard->list, &devlink->linecard_list); + mutex_unlock(&devlink->lock); + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + return linecard; +} +EXPORT_SYMBOL_GPL(devlink_linecard_create); + +/** + * devlink_linecard_destroy - Destroy devlink linecard + * + * @devlink_linecard: devlink linecard + */ +void devlink_linecard_destroy(struct devlink_linecard *linecard) +{ + struct devlink *devlink = linecard->devlink; + + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); + mutex_lock(&devlink->lock); + list_del(&linecard->list); + mutex_unlock(&devlink->lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_create); + 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: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: 12016657 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 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12016659 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 X-Spam-Level: X-Spam-Status: No, score=-14.0 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,UNWANTED_LANGUAGE_BODY, 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 8B2F2C433E9 for ; Wed, 13 Jan 2021 12:13:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45B12233F8 for ; Wed, 13 Jan 2021 12:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbhAMMNK (ORCPT ); Wed, 13 Jan 2021 07:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbhAMMNJ (ORCPT ); Wed, 13 Jan 2021 07:13:09 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C1FBC061795 for ; Wed, 13 Jan 2021 04:12:29 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id c5so1871499wrp.6 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=q5KdQEKor/xNGEAiee3yVmkHYi5dKtkCDib7jFEW8Bw=; b=KWeB45D/RpQ9wwN/+e0VrDWH/jVH0ofcnDlw0HKXuXdYNAWC6EeJB1fx/CutZH60z8 gLqKIY1pMoCQ4GGPMdpUy/eQw63DQfw+GgL2V8UtaOEZkquUE+akUil+9q1UDK/4KY3h uTrovYNDVXIf1D7ThrrryCWvX22UmUTPuW8EiD3LfZ2PDjr5O1p4ZS4m/lOZ8GD4nj72 XGnaeuTzYtLi2G9dUVhNICe0Im68rSyGg+rPJwpG3KEOywh7DyPbTOOlMnRrCg4LBvkC 8oufVJm1e5a8XGNVmqMb+TWJCqKuurvc/BGIGeDaghkZhrZD0bkRpyNS9eC+f4ffwWYV rQrg== 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=q5KdQEKor/xNGEAiee3yVmkHYi5dKtkCDib7jFEW8Bw=; b=gT5tW+s3z07ur/kC1PF94RfHvNa59Amn0Q0Dq3PvegnYHkpF4ZvJZ5YRNhrM3S/fYf 4YUcEqmQQh0TJ5v16tKernLlm0UM2i9z5UymROQwWllrOhASJCS9FTbW2UM8O97qx1fF wT1ugl2cCrbInowEZejXLvwiAOC3zOYujj5MkX2hlq4nKWAhz8derrVmcrl1NhkkUVGU ZC5ZXA+rvR2oCuwdpoZ3yF9hudbJmxRCjgpz+3iUbTvcK3BbTzdJg0c8jnl9a2FGGiEY LVaEeNCH40ANWdAJbvHmkC9Ofpj0aVE9bXmHeiA2G/k8BXskodidVzVQ+LniW/axyrM0 PxKw== X-Gm-Message-State: AOAM531cRiO8mTpZhvctxSwZNTIwqLH0ueZicSEzjrksM574AS7U77hM 345mMlvh9QNAlIUynqtdzqXphCJA2OBTmEPP X-Google-Smtp-Source: ABdhPJwv4982CaJB4sNJTeOPxXPZqtpeLm/c6XReG66v8100IMmVnyyFnEKNrE7Q9ZKQ/adHh3Rl2g== X-Received: by 2002:a05:6000:222:: with SMTP id l2mr2275189wrz.392.1610539947204; Wed, 13 Jan 2021 04:12:27 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id l20sm3237356wrh.82.2021.01.13.04.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:26 -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 03/10] devlink: implement line card active state Date: Wed, 13 Jan 2021 13:12:15 +0100 Message-Id: <20210113121222.733517-4-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jiri Pirko Allow driver to mark a lin ecards as active. Expose this state to the userspace over devlink netlink interface with proper notifications. Signed-off-by: Jiri Pirko --- include/net/devlink.h | 4 ++++ include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 854abd53e9ea..ec00cd94c626 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -149,6 +149,7 @@ struct devlink_linecard { void *priv; enum devlink_linecard_state state; const char *provisioned_type; + bool active; }; /** @@ -1444,6 +1445,9 @@ 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); +void devlink_linecard_activate(struct devlink_linecard *linecard); +void devlink_linecard_deactivate(struct devlink_linecard *linecard); +bool devlink_linecard_is_active(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 4111ddcc000b..d961d31fe288 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -338,6 +338,7 @@ enum devlink_linecard_state { DEVLINK_LINECARD_STATE_UNPROVISIONING, DEVLINK_LINECARD_STATE_PROVISIONING, DEVLINK_LINECARD_STATE_PROVISIONED, + DEVLINK_LINECARD_STATE_ACTIVE, __DEVLINK_LINECARD_STATE_MAX, DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1 diff --git a/net/core/devlink.c b/net/core/devlink.c index 434eecc310c3..9c76edf8c8af 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -8790,6 +8790,52 @@ void devlink_linecard_provision_clear(struct devlink_linecard *linecard) } EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear); +/** + * devlink_linecard_activate - Set linecard active + * + * @devlink_linecard: devlink linecard + */ +void devlink_linecard_activate(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->devlink->lock); + WARN_ON(linecard->state != DEVLINK_LINECARD_STATE_PROVISIONED); + linecard->state = DEVLINK_LINECARD_STATE_ACTIVE; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->devlink->lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_activate); + +/** + * devlink_linecard_deactivate - Set linecard deactive + * + * @devlink_linecard: devlink linecard + */ +void devlink_linecard_deactivate(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->devlink->lock); + WARN_ON(linecard->state != DEVLINK_LINECARD_STATE_ACTIVE); + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->devlink->lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); + +/** + * devlink_linecard_is_active - Check if active + * + * @devlink_linecard: devlink linecard + */ +bool devlink_linecard_is_active(struct devlink_linecard *linecard) +{ + bool active; + + mutex_lock(&linecard->devlink->lock); + active = linecard->state == DEVLINK_LINECARD_STATE_ACTIVE; + mutex_unlock(&linecard->devlink->lock); + return active; +} +EXPORT_SYMBOL_GPL(devlink_linecard_is_active); + 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: 12016661 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 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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: 12016673 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 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12016663 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 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 B4B77C433DB for ; Wed, 13 Jan 2021 12:13:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A56C233F8 for ; Wed, 13 Jan 2021 12:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727252AbhAMMNr (ORCPT ); Wed, 13 Jan 2021 07:13:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbhAMMNq (ORCPT ); Wed, 13 Jan 2021 07:13:46 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64581C0617A3 for ; Wed, 13 Jan 2021 04:12:32 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id y23so1403242wmi.1 for ; Wed, 13 Jan 2021 04:12:32 -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=chtmYzDo6YZa3nS5UTeYXFkh5EkhTkZCSDsjSSulFTk=; b=sUmB6f2ZBC81J14OmsdR4qBzhyLD3igo5EAqs/g/MSlyf9tthNRP+5ArsiFyWo2eIl FMCCMvOv1n1kczMhgpxnh+g+8BpCH5b/kNQUgQcHIQpfRKNCjUoZVcGJe9z8z80ivTuU 9WYHTqMdkROonXjl6LUzrRmrPUANz7E3W4UmpqnvrnKcSugDImw3ehig7WNx95u9T4xc acSkoWnkXg3kangreyjxmg4er38qZVQ3Zg2pnstVaJT5XX0mXcKUyskIknR6yF0kExY9 vZpvUlQUANx1aLqygzHAMKXsPWDtrJ2HLiG8GlMlHdeKJQaUefvQfq/G9gCQnrOPcbH8 yp1Q== 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=chtmYzDo6YZa3nS5UTeYXFkh5EkhTkZCSDsjSSulFTk=; b=tCJAiig3FGTVlQozgJvPsMRxcfLBGBGNg/SiR0n/jHKBqp3xb6rAzfxKv+nItI0EMq ukAuLuiu+OJ0bLvj77OqkjWaII50Fyu5oYk5z/X5qu4hGQci+iN9506HKFoC6RKZ6HLy jc8JJLDtQbYY+yzKQ4x3pG1+T0qXfP3jJm0QIvJSvX+LIJ4p3e5o/CkIEPZLJk5puB0O 9X4VROtrO4xbHtoMRFDYMyEc1XEb/NpNIexZWhlmvv9+d36C7mh6F4jntomZEXIkY5d0 ksBIC2zvU7JMRn8nrhVqHHIYG8UOiaUBB4wCs5hnTEfcjRdR/I19LY9laNVSb1C0d9wR UkGA== X-Gm-Message-State: AOAM5318S3JWU2YWkrDaSFKgR6NKUD3JnrCCCwGfRfyoWWWI70rRML2h Q5ue1DTQeG7/RiF96r7Y0onhJEnfFH1xrKpj X-Google-Smtp-Source: ABdhPJw5UlBj9y5dHSnZAOqCwZtQYnmD9yExDZY4Y3DUYycdHTcFj3s6gyhfjQsikA/ZWD26PvAqyw== X-Received: by 2002:a1c:e042:: with SMTP id x63mr1950330wmg.68.1610539950795; Wed, 13 Jan 2021 04:12:30 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id r7sm2675973wmh.2.2021.01.13.04.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:30 -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 06/10] netdevsim: introduce line card support Date: Wed, 13 Jan 2021 13:12:18 +0100 Message-Id: <20210113121222.733517-7-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jiri Pirko Add support for line card objects. Expose them over debugfs and allow user to specify number of line cards to be created for a new device. Similar to ports, the number of line cards is fixed. Extend "new_device" sysfs file write by third number to allow to specify number line cards like this: $ echo "10 4 2" >/sys/bus/netdevsim/new_device This command asks to create two line cards. By default, if this number is not preset, no line card is created. Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/bus.c | 17 +++-- drivers/net/netdevsim/dev.c | 108 +++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 15 +++++ 3 files changed, 133 insertions(+), 7 deletions(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 0e9511661601..ed57c012e660 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -179,29 +179,34 @@ static struct device_type nsim_bus_dev_type = { }; static struct nsim_bus_dev * -nsim_bus_dev_new(unsigned int id, unsigned int port_count); +nsim_bus_dev_new(unsigned int id, unsigned int port_count, + unsigned int linecard_count); static ssize_t new_device_store(struct bus_type *bus, const char *buf, size_t count) { struct nsim_bus_dev *nsim_bus_dev; + unsigned int linecard_count; unsigned int port_count; unsigned int id; int err; - err = sscanf(buf, "%u %u", &id, &port_count); + err = sscanf(buf, "%u %u %u", &id, &port_count, &linecard_count); switch (err) { case 1: port_count = 1; fallthrough; case 2: + linecard_count = 0; + fallthrough; + case 3: if (id > INT_MAX) { pr_err("Value of \"id\" is too big.\n"); return -EINVAL; } break; default: - pr_err("Format for adding new device is \"id port_count\" (uint uint).\n"); + pr_err("Format for adding new device is \"id port_count linecard_count\" (uint uint uint).\n"); return -EINVAL; } @@ -212,7 +217,7 @@ new_device_store(struct bus_type *bus, const char *buf, size_t count) goto err; } - nsim_bus_dev = nsim_bus_dev_new(id, port_count); + nsim_bus_dev = nsim_bus_dev_new(id, port_count, linecard_count); if (IS_ERR(nsim_bus_dev)) { err = PTR_ERR(nsim_bus_dev); goto err; @@ -312,7 +317,8 @@ static struct bus_type nsim_bus = { }; static struct nsim_bus_dev * -nsim_bus_dev_new(unsigned int id, unsigned int port_count) +nsim_bus_dev_new(unsigned int id, unsigned int port_count, + unsigned int linecard_count) { struct nsim_bus_dev *nsim_bus_dev; int err; @@ -328,6 +334,7 @@ nsim_bus_dev_new(unsigned int id, unsigned int port_count) nsim_bus_dev->dev.bus = &nsim_bus; nsim_bus_dev->dev.type = &nsim_bus_dev_type; nsim_bus_dev->port_count = port_count; + nsim_bus_dev->linecard_count = linecard_count; nsim_bus_dev->initial_net = current->nsproxy->net_ns; mutex_init(&nsim_bus_dev->nsim_bus_reload_lock); /* Disallow using nsim_bus_dev */ diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 816af1f55e2c..d81ccfa05a28 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -203,6 +203,10 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) nsim_dev->ports_ddir = debugfs_create_dir("ports", nsim_dev->ddir); if (IS_ERR(nsim_dev->ports_ddir)) return PTR_ERR(nsim_dev->ports_ddir); + nsim_dev->linecards_ddir = debugfs_create_dir("linecards", + nsim_dev->ddir); + if (IS_ERR(nsim_dev->linecards_ddir)) + return PTR_ERR(nsim_dev->linecards_ddir); debugfs_create_bool("fw_update_status", 0600, nsim_dev->ddir, &nsim_dev->fw_update_status); debugfs_create_u32("fw_update_overwrite_mask", 0600, nsim_dev->ddir, @@ -237,6 +241,7 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) { + debugfs_remove_recursive(nsim_dev->linecards_ddir); debugfs_remove_recursive(nsim_dev->ports_ddir); debugfs_remove_recursive(nsim_dev->ddir); } @@ -265,6 +270,32 @@ static void nsim_dev_port_debugfs_exit(struct nsim_dev_port *nsim_dev_port) debugfs_remove_recursive(nsim_dev_port->ddir); } +static int +nsim_dev_linecard_debugfs_init(struct nsim_dev *nsim_dev, + struct nsim_dev_linecard *nsim_dev_linecard) +{ + char linecard_ddir_name[16]; + char dev_link_name[32]; + + sprintf(linecard_ddir_name, "%u", nsim_dev_linecard->linecard_index); + nsim_dev_linecard->ddir = debugfs_create_dir(linecard_ddir_name, + nsim_dev->linecards_ddir); + if (IS_ERR(nsim_dev_linecard->ddir)) + return PTR_ERR(nsim_dev_linecard->ddir); + + 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); + + return 0; +} + +static void +nsim_dev_linecard_debugfs_exit(struct nsim_dev_linecard *nsim_dev_linecard) +{ + debugfs_remove_recursive(nsim_dev_linecard->ddir); +} + static int nsim_dev_resources_register(struct devlink *devlink) { struct devlink_resource_size_params params = { @@ -998,6 +1029,64 @@ static int nsim_dev_port_add_all(struct nsim_dev *nsim_dev, return err; } +static int __nsim_dev_linecard_add(struct nsim_dev *nsim_dev, + unsigned int linecard_index) +{ + struct nsim_dev_linecard *nsim_dev_linecard; + int err; + + nsim_dev_linecard = kzalloc(sizeof(*nsim_dev_linecard), GFP_KERNEL); + if (!nsim_dev_linecard) + return -ENOMEM; + nsim_dev_linecard->nsim_dev = nsim_dev; + nsim_dev_linecard->linecard_index = linecard_index; + + err = nsim_dev_linecard_debugfs_init(nsim_dev, nsim_dev_linecard); + if (err) + goto err_linecard_free; + + list_add(&nsim_dev_linecard->list, &nsim_dev->linecard_list); + + return 0; + +err_linecard_free: + kfree(nsim_dev_linecard); + return err; +} + +static void __nsim_dev_linecard_del(struct nsim_dev_linecard *nsim_dev_linecard) +{ + list_del(&nsim_dev_linecard->list); + nsim_dev_linecard_debugfs_exit(nsim_dev_linecard); + kfree(nsim_dev_linecard); +} + +static void nsim_dev_linecard_del_all(struct nsim_dev *nsim_dev) +{ + struct nsim_dev_linecard *nsim_dev_linecard, *tmp; + + list_for_each_entry_safe(nsim_dev_linecard, tmp, + &nsim_dev->linecard_list, list) + __nsim_dev_linecard_del(nsim_dev_linecard); +} + +static int nsim_dev_linecard_add_all(struct nsim_dev *nsim_dev, + unsigned int linecard_count) +{ + int i, err; + + for (i = 0; i < linecard_count; i++) { + err = __nsim_dev_linecard_add(nsim_dev, i); + if (err) + goto err_linecard_del_all; + } + return 0; + +err_linecard_del_all: + nsim_dev_linecard_del_all(nsim_dev); + return err; +} + static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack) { @@ -1009,6 +1098,7 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, nsim_dev = devlink_priv(devlink); INIT_LIST_HEAD(&nsim_dev->port_list); mutex_init(&nsim_dev->port_list_lock); + INIT_LIST_HEAD(&nsim_dev->linecard_list); nsim_dev->fw_update_status = true; nsim_dev->fw_update_overwrite_mask = 0; @@ -1030,10 +1120,14 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, if (err) goto err_traps_exit; - err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + err = nsim_dev_linecard_add_all(nsim_dev, nsim_bus_dev->linecard_count); if (err) goto err_health_exit; + err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + if (err) + goto err_linecard_del_all; + nsim_dev->take_snapshot = debugfs_create_file("take_snapshot", 0200, nsim_dev->ddir, @@ -1041,6 +1135,8 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, &nsim_dev_take_snapshot_fops); return 0; +err_linecard_del_all: + nsim_dev_linecard_del_all(nsim_dev); err_health_exit: nsim_dev_health_exit(nsim_dev); err_traps_exit: @@ -1068,6 +1164,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) get_random_bytes(nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); INIT_LIST_HEAD(&nsim_dev->port_list); mutex_init(&nsim_dev->port_list_lock); + INIT_LIST_HEAD(&nsim_dev->linecard_list); nsim_dev->fw_update_status = true; nsim_dev->fw_update_overwrite_mask = 0; nsim_dev->max_macs = NSIM_DEV_MAX_MACS_DEFAULT; @@ -1116,14 +1213,20 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) if (err) goto err_health_exit; - err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + err = nsim_dev_linecard_add_all(nsim_dev, nsim_bus_dev->linecard_count); if (err) goto err_bpf_dev_exit; + err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + if (err) + goto err_linecard_del_all; + devlink_params_publish(devlink); devlink_reload_enable(devlink); return 0; +err_linecard_del_all: + nsim_dev_linecard_del_all(nsim_dev); err_bpf_dev_exit: nsim_bpf_dev_exit(nsim_dev); err_health_exit: @@ -1156,6 +1259,7 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) return; debugfs_remove(nsim_dev->take_snapshot); nsim_dev_port_del_all(nsim_dev); + nsim_dev_linecard_del_all(nsim_dev); nsim_dev_health_exit(nsim_dev); nsim_dev_traps_exit(devlink); nsim_dev_dummy_region_exit(nsim_dev); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 48163c5f2ec9..df10f9d11e9d 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -180,20 +180,33 @@ struct nsim_dev_health { int nsim_dev_health_init(struct nsim_dev *nsim_dev, struct devlink *devlink); void nsim_dev_health_exit(struct nsim_dev *nsim_dev); +struct nsim_dev_linecard; + struct nsim_dev_port { struct list_head list; struct devlink_port devlink_port; + struct nsim_dev_linecard *linecard; unsigned int port_index; struct dentry *ddir; struct netdevsim *ns; }; +struct nsim_dev; + +struct nsim_dev_linecard { + struct list_head list; + struct nsim_dev *nsim_dev; + unsigned int linecard_index; + struct dentry *ddir; +}; + struct nsim_dev { struct nsim_bus_dev *nsim_bus_dev; struct nsim_fib_data *fib_data; struct nsim_trap_data *trap_data; struct dentry *ddir; struct dentry *ports_ddir; + struct dentry *linecards_ddir; struct dentry *take_snapshot; struct bpf_offload_dev *bpf_dev; bool bpf_bind_accept; @@ -206,6 +219,7 @@ struct nsim_dev { struct netdev_phys_item_id switch_id; struct list_head port_list; struct mutex port_list_lock; /* protects port list */ + struct list_head linecard_list; bool fw_update_status; u32 fw_update_overwrite_mask; u32 max_macs; @@ -287,6 +301,7 @@ struct nsim_bus_dev { struct device dev; struct list_head list; unsigned int port_count; + unsigned int linecard_count; struct net *initial_net; /* Purpose of this is to carry net pointer * during the probe time only. */ 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: 12016665 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 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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: 12016669 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 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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 { From patchwork Wed Jan 13 12:12:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12016667 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 X-Spam-Level: X-Spam-Status: No, score=-14.0 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,UNWANTED_LANGUAGE_BODY, 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 95E5DC433E0 for ; Wed, 13 Jan 2021 12:13:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 491E3233F8 for ; Wed, 13 Jan 2021 12:13:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727429AbhAMMNu (ORCPT ); Wed, 13 Jan 2021 07:13:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbhAMMNs (ORCPT ); Wed, 13 Jan 2021 07:13:48 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75CAC0617A6 for ; Wed, 13 Jan 2021 04:12:35 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id m4so1856924wrx.9 for ; Wed, 13 Jan 2021 04:12:35 -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=mL7WDxG4zT3nUU/BtKIjBqyFzFB6+PWnuRMCcmIHzHo=; b=tYLc5qNKyPjPaGbRpdHn9CyjwLY7CxkVsGbVgDrtxGLp/04s0PkKG6skFkHR6Wpjle qCvmkwzVyku3kz8M9+D9TsOGQmZ2HClSRvT+I8H6Gfqr93QCJlTWt44Xzx3t+hzqFsrY ZL3DHNKxooQ+PtjZNF6nKvdCPT3zN9/oySCjATKW9K8vHOMy/o3Ajk9YE9E76h1/doiR 4zLvWXL41Vrw1svq6Wbs0h81fShKATKrGr53pINlbClvoXM3XhOrt42XZOEH2uA+0hqG ZCV3GU4cMqPj3hmeabbiw9GeDdHgrl3UZ3BZW2aFiQb+2G6T0ahfRp+oVS77WrZ3ED47 mtNQ== 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=mL7WDxG4zT3nUU/BtKIjBqyFzFB6+PWnuRMCcmIHzHo=; b=rG8LDkkG81jO/LCLhoEPt9GeAe4HvqVjLubJRZVtaxvL8dnOG53TUGIRSapVqk70ol RVDItEmIpZnztObGeuumRBRhpFseBIrxMlYRyFt6Y7ZljfJ2avPUuNrD10QisXe38PP1 srTPv/nInBXBSvbRGRBOs/oPiaoMmpLLs8ZxiipN9u3ljWtkCD90htrcLEP3Kauut9lg bxlSRo7E3kH3Mwr420t5vuGtO6i0bTFn+x3KlgUVyZZFlN8SWVCcxWn1WPMMY1U1BQ3f ZY4UUdPeqO+VyVeTH1qLrLMs6ONJkBR8bwFCksQy9dolg9uqs6OB6iOe1yLM3kDOmdZ3 g0iQ== X-Gm-Message-State: AOAM530ywXHwAyWTejmKvYtWT3Pck0nNfwA5QIG99lQ6JkLYUdTzO6jK t48SYEm/WiZkqtzD0X4G/VtxU8hH39q+Gg4H X-Google-Smtp-Source: ABdhPJyl0nDoTqAb6of+h6YpdDlX77U1GV0qnv5smkHQKpDnqO3qW6HvkkMogTAmA7YbwSiWg/zwrw== X-Received: by 2002:adf:9dc4:: with SMTP id q4mr2278353wre.367.1610539954316; Wed, 13 Jan 2021 04:12:34 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id s3sm2567308wmc.44.2021.01.13.04.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:33 -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 09/10] netdevsim: implement line card activation Date: Wed, 13 Jan 2021 13:12:21 +0100 Message-Id: <20210113121222.733517-10-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jiri Pirko On real HW, the activation typically happens upon line card insertion. Emulate such event using write to debugfs file "active". Signed-off-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 9e9a2a75ddf8..81d68269e121 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -64,6 +64,30 @@ nsim_dev_port_index(struct nsim_dev_linecard *nsim_dev_linecard, port_index; } +static int +nsim_dev_linecard_activate(struct nsim_dev_linecard *nsim_dev_linecard) +{ + struct nsim_dev_port *nsim_dev_port; + + list_for_each_entry(nsim_dev_port, &nsim_dev_linecard->port_list, + list_lc) + netif_carrier_on(nsim_dev_port->ns->netdev); + + devlink_linecard_activate(nsim_dev_linecard->devlink_linecard); + return 0; +} + +static void +nsim_dev_linecard_deactivate(struct nsim_dev_linecard *nsim_dev_linecard) +{ + struct nsim_dev_port *nsim_dev_port; + + list_for_each_entry(nsim_dev_port, &nsim_dev_linecard->port_list, + list_lc) + netif_carrier_off(nsim_dev_port->ns->netdev); + devlink_linecard_deactivate(nsim_dev_linecard->devlink_linecard); +} + static struct dentry *nsim_dev_ddir; #define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32) @@ -299,6 +323,61 @@ 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_active_read(struct file *file, + char __user *data, + size_t count, loff_t *ppos) +{ + struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; + char buf[3]; + + if (!nsim_dev_linecard->provisioned) + return -EOPNOTSUPP; + + if (devlink_linecard_is_active(nsim_dev_linecard->devlink_linecard)) + buf[0] = 'Y'; + else + buf[0] = 'N'; + buf[1] = '\n'; + buf[2] = 0x00; + return simple_read_from_buffer(data, count, ppos, buf, strlen(buf)); +} + +static ssize_t nsim_dev_linecard_active_write(struct file *file, + const char __user *data, + size_t count, loff_t *ppos) +{ + struct nsim_dev_linecard *nsim_dev_linecard = file->private_data; + bool active; + bool bv; + int err; + int r; + + if (!nsim_dev_linecard->provisioned) + return -EOPNOTSUPP; + + active = devlink_linecard_is_active(nsim_dev_linecard->devlink_linecard); + + r = kstrtobool_from_user(data, count, &bv); + if (!r && active != bv) { + if (bv) { + err = nsim_dev_linecard_activate(nsim_dev_linecard); + if (err) + return err; + } else { + nsim_dev_linecard_deactivate(nsim_dev_linecard); + } + } + return count; +} + +static const struct file_operations nsim_dev_linecard_active_fops = { + .open = simple_open, + .read = nsim_dev_linecard_active_read, + .write = nsim_dev_linecard_active_write, + .llseek = generic_file_llseek, + .owner = THIS_MODULE, +}; + static ssize_t nsim_dev_linecard_type_read(struct file *file, char __user *data, size_t count, loff_t *ppos) { @@ -334,6 +413,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("active", 0600, nsim_dev_linecard->ddir, + nsim_dev_linecard, &nsim_dev_linecard_active_fops); debugfs_create_file("type", 0400, nsim_dev_linecard->ddir, nsim_dev_linecard, &nsim_dev_linecard_type_fops); From patchwork Wed Jan 13 12:12:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 12016671 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 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 4C102C433DB for ; Wed, 13 Jan 2021 12:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01AF9233F8 for ; Wed, 13 Jan 2021 12:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbhAMMNw (ORCPT ); Wed, 13 Jan 2021 07:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727382AbhAMMNs (ORCPT ); Wed, 13 Jan 2021 07:13:48 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 387CFC0617A7 for ; Wed, 13 Jan 2021 04:12:37 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id c5so1871950wrp.6 for ; Wed, 13 Jan 2021 04:12:37 -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=ATylw7O0JvPXuZo0K63DCjbbvEh4iMcDM+Z+skEBAj8=; b=OfeynaacaTCjabxQsY34bA30qnjJxvMrfnJf81GhgAYpVZqB3041sP3ORO+ebJK5Ku ySeexoFT1iDIndFTHW4qDaro0TkA7PGHROfYeczPXm4jOh+GO/SAXWGF0uy4bmyfAdjV vKljxURPnDXlT+L0rF0sXXNJeXzexGmzsnV4xJSlvCjSn3Lp3I4tA7GBkHuXsLMgDZgV 8484k2oICS8O3N7KQCrNZRSdrrQOrH5f9Pz1/gCJd7sbmlpjOAZ3p9H7rsZONMkcvJbY kvFlkcMiRRywSdVfyPX+4CXZSOBFHgjoRsQHg/IBDVEzf0sQOJ7BRxqvB+rnfoNAWL4M EW9A== 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=ATylw7O0JvPXuZo0K63DCjbbvEh4iMcDM+Z+skEBAj8=; b=HV4hlZI/lxJvdpy5y480E82kq2PBmj+8YvClQDFeTXK6adgqPdoC0bYTEn7zubg7vv HYCA7wMIWl/wPf0i9NvRKj37s7czGX6Ioui86uoECnp64EOZFjjoA9MSMbbBZjPrZk08 J5EXpdiT37D01IGdNxia2tJbe521o+Iyq6uc292lreDVpfyaV8a/egpifIxC5lUVxRHV +u8hnVMaOZxxWJUSmJkSxDEWNqpLefReBjUv47IgzkbeY+6Y1DSCfi/V23cWPRTqykiq FwRr6m0BUCB2kJppkxm1G/fn605AIabFAOZec2fA4MI5wEcTkOLyhiZUEXDV+X+d7J5u bqwg== X-Gm-Message-State: AOAM530rO5waxELEqQF0GCmihp2N22RI6ntrrXuinxFUQnb/w8GFEK7D mMtVzHeppBXjOxODc0DViypYjo86/AcDr/XP X-Google-Smtp-Source: ABdhPJyyzZc9KDK7We44APjrHcsZd8VgkUsKLlSvgJ322I0+0p8DUL7WAuIyG3S4xAIf/DM6KrVLCQ== X-Received: by 2002:adf:a441:: with SMTP id e1mr2265084wra.385.1610539955512; Wed, 13 Jan 2021 04:12:35 -0800 (PST) Received: from localhost ([85.163.43.78]) by smtp.gmail.com with ESMTPSA id h83sm2806067wmf.9.2021.01.13.04.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 04:12:35 -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 10/10] selftests: add netdevsim devlink lc test Date: Wed, 13 Jan 2021 13:12:22 +0100 Message-Id: <20210113121222.733517-11-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 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jiri Pirko Add test to verify netdevsim driver line card functionality. Signed-off-by: Jiri Pirko --- .../drivers/net/netdevsim/devlink.sh | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index 40909c254365..c33cf13d3bf3 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -5,12 +5,13 @@ lib_dir=$(dirname $0)/../../../net/forwarding ALL_TESTS="fw_flash_test params_test regions_test reload_test \ netns_reload_test resource_test dev_info_test \ - empty_reporter_test dummy_reporter_test" + empty_reporter_test dummy_reporter_test linecard_test" NUM_NETIFS=0 source $lib_dir/lib.sh BUS_ADDR=10 PORT_COUNT=4 +LINECARD_COUNT=2 DEV_NAME=netdevsim$BUS_ADDR SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/ DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/ @@ -507,10 +508,67 @@ dummy_reporter_test() log_test "dummy reporter test" } +check_linecards_state() +{ + local expected_state_0=$1 + local expected_state_1=$2 + + local state=$(devlink lc show $DL_HANDLE lc 0 -j | jq -e -r ".[][][].state") + check_err $? "Failed to get linecard 0 state" + + [ "$state" == "$expected_state_0" ] + check_err $? "Unexpected linecard 0 state (got $state, expected $expected_state_0)" + + local state=$(devlink lc show $DL_HANDLE lc 1 -j | jq -e -r ".[][][].state") + check_err $? "Failed to get linecard 1 state" + + [ "$state" == "$expected_state_1" ] + check_err $? "Unexpected linecard 1 state (got $state, expected $expected_state_1)" +} + +linecard_test() +{ + RET=0 + + check_linecards_state "unprovisioned" "unprovisioned" + + devlink lc provision $DL_HANDLE lc 0 type card2ports + check_err $? "Failed to provision linecard 0 with card2ports" + + check_linecards_state "provisioned" "unprovisioned" + + devlink lc provision $DL_HANDLE lc 1 type card4ports + check_err $? "Failed to provision linecard 0 with card4ports" + + check_linecards_state "provisioned" "provisioned" + + echo "Y"> $DEBUGFS_DIR/linecards/0/active + check_err $? "Failed to set lincard 0 active" + + check_linecards_state "active" "provisioned" + + echo "Y"> $DEBUGFS_DIR/linecards/1/active + check_err $? "Failed to set lincard 1 active" + + check_linecards_state "active" "active" + + devlink lc unprovision $DL_HANDLE lc 0 + check_err $? "Failed to unprovision linecard 0" + + check_linecards_state "unprovisioned" "active" + + devlink lc unprovision $DL_HANDLE lc 1 + check_err $? "Failed to unprovision linecard 1" + + check_linecards_state "unprovisioned" "unprovisioned" + + log_test "linecard test" +} + setup_prepare() { modprobe netdevsim - echo "$BUS_ADDR $PORT_COUNT" > /sys/bus/netdevsim/new_device + echo "$BUS_ADDR $PORT_COUNT $LINECARD_COUNT" > /sys/bus/netdevsim/new_device while [ ! -d $SYSFS_NET_DIR ] ; do :; done }