From patchwork Mon Apr 18 06:42:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816332 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6221C433EF for ; Mon, 18 Apr 2022 06:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236355AbiDRGqQ (ORCPT ); Mon, 18 Apr 2022 02:46:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236338AbiDRGqM (ORCPT ); Mon, 18 Apr 2022 02:46:12 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2052.outbound.protection.outlook.com [40.107.101.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B309D13DF7 for ; Sun, 17 Apr 2022 23:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FuGQmcg1PbmymE/DNnAdzuOc9GpUATaaXFBvAll89VdNHJkdaUWpTxHXDAowkXA6W3u1MeKOeO4RvgyeLfLYFdsnk3SBElZddJ7WnD6lQDemhmB5+dp5/VfmcCy9DfRi+3t1Y4VM2FU6Rq2oxbGcEEQ3Yu/omswSt5dRkHy5MvYg4dB0y9tjnGm2Jx5l2rkY8LCbEgjx4WLmnaiBShsLPorwZjk8fBadpftB7o9E9k0mkvp7Co60Q06Vy2FLlNdGx1VyqgjtdGSkpFXGUfMPtY1H1dM/5sVnFCLvQP9MaacqcARRxvYrf8lY8mMtMn12ZVSlTBXOyOS/Nm5G/85pMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=a38DiklQh58Sxq360u+R6maR5aqkgbkzBdYRhr6Cyx0=; b=ZeHwtSsw225tfWC6XiFgNXK30CnrFmZ8gCLLIFKpEmMp00P8pwWHvqT8zpXwLu/dJcIB3oqpnTeQwYTCgucPDpSf0WavwRlgVLCeVsJJA7Mr8XwvltX4oTFD0IKO71kkkEKqOFHjaFYpxSMV0zQ3Jc1Dtc+GDMZdnHwi8kgSk3zvwlfdgKS/sN+I/md7LxQCDTPgH+tZCZbUoeWIjYUJrqQm2Hc8YCsewf93UzvZ4PpQIAZmmEQkOjtHmQH/+zgepUPj70Rv98AiKH58H9mr6nupZVpFj6u0BF+umHEqN9f93vyQCDtsEibezKt9fLtb+78nqshLyPNunAJmGUR6KA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a38DiklQh58Sxq360u+R6maR5aqkgbkzBdYRhr6Cyx0=; b=Hn4DuUUpGM4G/kC81vAOh3PrjYJKilo0XsHIq41Pj7iSY6Unq69XL0ncpbHnPr9Q9a5QlXpx9fjP2dLAyoa/XyiJgDuuteYaQL0UrycJoa6jmcK3UBMQN2VSK6cOuddVpHDkQSwVBh6M7sWvPC73cHPbmITKTW74yxewxGotHyPXEwhGAJVTd8CUoh6eqhfiekdc9X/WGUyWWOD/3ihkGsF2v2/NvREpSgTtRNdiyakAyCFD/IHnr/BjubT/ChWlxdVMsp64jS06KuVbjA6U6EJP+dKRw1o7rtxZqFhRlbn+smlCVXMRLfS5iZeAzPyQm67bJlqlob+PaqMZiE6pTg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:43:32 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:43:32 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 01/17] devlink: add support to create line card and expose to user Date: Mon, 18 Apr 2022 09:42:25 +0300 Message-Id: <20220418064241.2925668-2-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO2P265CA0042.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::30) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3063185-52d8-4c4e-f86f-08da2106c10e X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 803HPv7JGoFaK/WEncxXqCy+eS39fdmh8tjBRSakInwckJfoYZZgz8NvNvB+13+X+hZSUQFYD1VyJfaFfV+cyYrCV7TcYmjVEitZwgKfx4R2p/3Eo73GAwfRY8Myeplp8Q1ytyWYSPi+7+wHlf2paiw0kuXWXTJOD1QVWjpa2PNb+VJlGjoFU64Ty0iGCyuyB93l6L16nhYgvpPnnQO7PpsbekgKU9td9OpmmcXzJcDxVCauLmk5dQxEJURnl15z/b7Owdpqfn0F//ZsC70svZbQnHJgbbpv7nSNJkGXWnwL5LWIYDt+EJjJPcgiL7zyJmkMBAqI8yy6lJtpzle49VlJnoyHkwZyhTwpCp1ViOV0PweTraVKnpFfNPanlyRPnYeaDIAqxpqm2kA5qiDcVTA9bVwY2QKuH9Y1dcctSdil3Ex7yZSVBCuh0On6fhZuC7sthiN19iIfu6ZCscT89rkqawjcbRfCXDOrKOAPXMX0PV1HE0KeVmzEnzdm7mHG44JE8TgnFke6SJnReXuXzWddOjR3owT2lWPcRk8Rgys32yBQOUgbjZIjqvHTmW3Hs2I6aoFsC2V3K9uMmpm+zutwUNfI2BoIxb/khcM62EoeqmB7c8egBbiOXQGVI7eT8rgAZudA3tIkw3GOXM4DWw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(30864003)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VINQ7lRbxucBJQdNUuGNkwuUxmopjXVhOOBBVMZ+lrmlknJqDzIhODy52w0XcRSXV6qBYxcCcZojtMMM/IAUsweynJSzFpzRSlT+hshVq+Q9vDpP3Xxfj2vv5iGUlvMqoSxYX4jo0wt8fV36/nTq0TBnmwwMriL5xMqO7wwUe78hZlhguyP8p6ivuMe4t01XGrsfekZeavhYeNGA+0KIOkuFPL8xcpoeDouSejuI00ggbQ5tKx9Z6epcIrBh157iSwKOBTk6t/ichGDrf+//W2jERrhiDLY16+wQIceODHWOr12FkP92P8naI+qsD/yGgDVC72YnPuoofB3x5fvhDH9mNrmztIa7YxzUnAG2BlptMWqURwHC0fVAmDs4wdJzG5pHzWKRLNxFV3sXTmyhSkwatpZUSrJYwOmivta0DcRfeyz51bOwSLiULsfihfqMj2+E9rY3RGjLqSaO6lJcih2H41RUM8/bfs2jMUWfDRflw59+NtjDoCwehrQL395J/bjizvGc7uJcc3JGb3IadySIiNPOuEH1BDfVE/rnIDWrV8UnRXeuuy/Yd1ztxJ09SgaVXdyYy+9JKEHkNVw51l8IrR10iRxhIQz/LRWyBCYTHCqGap2QXsTNqUQ8FLRrCDazL6Vo3iekPSse1w33etRz3pxT1saTolwXy2KFCFs1JDsSMy05TkiaF6NMGch2rU3zlkMgpa4s2Dl5B6H2lZUwYQdAzMhK9BzaSDYWwyi7hPWdLSV42h7FwV+DLYWKmBdRGlAv6mVQ8NOnVKolToezxuAnL4EHv69jcqQkY2+5MrTshx/OdwgzUfuKi141AjLRTynbBdHWMiXK/R4LHozqIGVqtr11BFaeJUVKeZApo692sXMEZWRsJas4GbtiVBLCUHV9FBphR7ofe6NCyoFRdtY9uNotYyPbuVY8pAVtXimC6o9tOWFHkyaCDEE8mPhR5tUTf4LV4+gDFd/5OcGVAD69WJGAxv5DkzNCpb1woY7yDK4m+QX8lDFZtZV4djFvlR9ral5wd9QlAJiM7f1upYem+b26ZIfxEnDtAYFM7jau+t9c8JDv6H45NqHhMul6ILrcLfJ9K3BeQ2ixkA/YMhGbC9YS0oSGK0EVnMh1YAuAeKTVEt7wmAhw1nicxWn7CyfeyqoqqPEefdVxA/5ztwi78d6kPcGoThGyCXLCDhDMsE32cyk4sc1x6lX532O5BtqjdaIy6po6JIh6h4grNZ8l6y6aG0qd2ah8IPi3+RQAdUOOCuncU92YmG2Mxxqu9kC/5MkQbk6jvmXS2OaY/2gH92KL5CrNaKih+myCTXMhXila+z5ThoZ2689jWSBwXYoQVAxT+d/3pgjmFWjFdqFmipohZk0qn6VXlsj0p8/ZbhgHD5YkPE4MFLyu5iZCE0B9fKcHhe8HedEww3VsqdwuJrknw6AuuBUl3Bqhl00OIcDD79GSlj6ICxr1D+WAgb8OxrFjJ/e6dx/TT1iK6JcIDZKAlHEX6zPa1Kt3QtIHPEX8qzOTbeK2RRIpDVpXinr53YFCI2V7id6RMNqe++M/tpg7aINCVV1JvX0eByEPJyLJW0wjg5Ts/WrqCotIDKY4r6e+sHVecZFNvGREAgdm57Y3l+eitvFDh2vsZkPT9JckzudzCZRPjLisjpTePBoOqcPNgA/gkHyFyLQla6dXyyQuRt7fLlOS5k53XkkkbDix1SsXSVNd6QGyczpzhdnwrb0OnRz8EQ4YJQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3063185-52d8-4c4e-f86f-08da2106c10e X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:43:32.1182 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dqHV5NSBFQoux5BUQij8ggqgvqHjcqfp8+0Jj+KhDhnTnG7ZtVe50XuMJ6lTdzbiZDxWk+eOwvqDbbSQHHI7sQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 Signed-off-by: Ido Schimmel --- include/net/devlink.h | 4 + include/uapi/linux/devlink.h | 7 + net/core/devlink.c | 270 ++++++++++++++++++++++++++++++++++- 3 files changed, 280 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index a30180c0988a..7aabdfb3bc6a 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -22,6 +22,7 @@ #include struct devlink; +struct devlink_linecard; struct devlink_port_phys_attrs { u32 port_number; /* Same value as "split group". @@ -1536,6 +1537,9 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, int devlink_rate_leaf_create(struct devlink_port *port, void *priv); void devlink_rate_leaf_destroy(struct devlink_port *devlink_port); void devlink_rate_nodes_destroy(struct devlink *devlink); +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 b897b80770f6..59c33ed2d3e7 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -131,6 +131,11 @@ enum devlink_command { DEVLINK_CMD_RATE_NEW, DEVLINK_CMD_RATE_DEL, + 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 @@ -553,6 +558,8 @@ enum devlink_attr { DEVLINK_ATTR_REGION_MAX_SNAPSHOTS, /* u32 */ + 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 aeca13b6e57b..4cdacd74b82a 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -54,6 +54,8 @@ struct devlink { struct list_head trap_list; struct list_head trap_group_list; struct list_head trap_policer_list; + struct list_head linecard_list; + struct mutex linecards_lock; /* protects linecard_list */ const struct devlink_ops *ops; u64 features; struct xarray snapshot_ids; @@ -70,6 +72,13 @@ struct devlink { char priv[] __aligned(NETDEV_ALIGN); }; +struct devlink_linecard { + struct list_head list; + struct devlink *devlink; + unsigned int index; + refcount_t refcount; +}; + /** * struct devlink_resource - devlink resource * @name: name of the resource @@ -397,6 +406,56 @@ devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info) return ERR_PTR(-EINVAL); } +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; + + mutex_lock(&devlink->linecards_lock); + linecard = devlink_linecard_get_by_index(devlink, linecard_index); + if (linecard) + refcount_inc(&linecard->refcount); + mutex_unlock(&devlink->linecards_lock); + 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); +} + +static void devlink_linecard_put(struct devlink_linecard *linecard) +{ + if (refcount_dec_and_test(&linecard->refcount)) + kfree(linecard); +} + struct devlink_sb { struct list_head list; unsigned int index; @@ -617,16 +676,18 @@ devlink_region_snapshot_get_by_id(struct devlink_region *region, u32 id) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) #define DEVLINK_NL_FLAG_NEED_RATE BIT(2) #define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) +#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4) /* 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(4) +#define DEVLINK_NL_FLAG_NO_LOCK BIT(5) 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; @@ -669,6 +730,13 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, goto unlock; } info->user_ptr[1] = rate_node; + } 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; @@ -683,9 +751,14 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, static void devlink_nl_post_doit(const struct genl_ops *ops, struct sk_buff *skb, struct genl_info *info) { + struct devlink_linecard *linecard; struct devlink *devlink; devlink = info->user_ptr[0]; + if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) { + linecard = info->user_ptr[1]; + devlink_linecard_put(linecard); + } if (~ops->internal_flags & DEVLINK_NL_FLAG_NO_LOCK) mutex_unlock(&devlink->lock); devlink_put(devlink); @@ -1964,6 +2037,132 @@ static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, return err; } +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); + + if (!xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED)) + return; + + 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]; + unsigned long index; + int idx = 0; + int err; + + mutex_lock(&devlink_mutex); + xa_for_each_marked(&devlinks, index, devlink, DEVLINK_REGISTERED) { + if (!devlink_try_get(devlink)) + continue; + + if (!net_eq(devlink_net(devlink), sock_net(msg->sk))) + goto retry; + + mutex_lock(&devlink->linecards_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->linecards_lock); + devlink_put(devlink); + goto out; + } + idx++; + } + mutex_unlock(&devlink->linecards_lock); +retry: + devlink_put(devlink); + } +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, @@ -8589,6 +8788,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 }, [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING }, + [DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -8664,6 +8864,13 @@ 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, + .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, @@ -9043,6 +9250,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, write_pnet(&devlink->_net, net); INIT_LIST_HEAD(&devlink->port_list); INIT_LIST_HEAD(&devlink->rate_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); @@ -9054,6 +9262,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, INIT_LIST_HEAD(&devlink->trap_policer_list); mutex_init(&devlink->lock); mutex_init(&devlink->reporters_lock); + mutex_init(&devlink->linecards_lock); refcount_set(&devlink->refcount, 1); init_completion(&devlink->comp); @@ -9080,10 +9289,14 @@ static void devlink_notify_register(struct devlink *devlink) struct devlink_param_item *param_item; struct devlink_trap_item *trap_item; struct devlink_port *devlink_port; + struct devlink_linecard *linecard; struct devlink_rate *rate_node; struct devlink_region *region; devlink_notify(devlink, DEVLINK_CMD_NEW); + list_for_each_entry(linecard, &devlink->linecard_list, list) + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + list_for_each_entry(devlink_port, &devlink->port_list, list) devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); @@ -9191,6 +9404,7 @@ void devlink_free(struct devlink *devlink) { ASSERT_DEVLINK_NOT_REGISTERED(devlink); + mutex_destroy(&devlink->linecards_lock); mutex_destroy(&devlink->reporters_lock); mutex_destroy(&devlink->lock); WARN_ON(!list_empty(&devlink->trap_policer_list)); @@ -9203,6 +9417,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); WARN_ON(!list_empty(&devlink->rate_list)); + WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!list_empty(&devlink->port_list)); xa_destroy(&devlink->snapshot_ids); @@ -9747,6 +9962,59 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, return 0; } +/** + * devlink_linecard_create - Create devlink linecard + * + * @devlink: devlink + * @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->linecards_lock); + if (devlink_linecard_index_exists(devlink, linecard_index)) { + mutex_unlock(&devlink->linecards_lock); + return ERR_PTR(-EEXIST); + } + + linecard = kzalloc(sizeof(*linecard), GFP_KERNEL); + if (!linecard) { + mutex_unlock(&devlink->linecards_lock); + return ERR_PTR(-ENOMEM); + } + + linecard->devlink = devlink; + linecard->index = linecard_index; + list_add_tail(&linecard->list, &devlink->linecard_list); + refcount_set(&linecard->refcount, 1); + mutex_unlock(&devlink->linecards_lock); + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + return linecard; +} +EXPORT_SYMBOL_GPL(devlink_linecard_create); + +/** + * devlink_linecard_destroy - Destroy devlink linecard + * + * @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->linecards_lock); + list_del(&linecard->list); + mutex_unlock(&devlink->linecards_lock); + devlink_linecard_put(linecard); +} +EXPORT_SYMBOL_GPL(devlink_linecard_destroy); + 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 Mon Apr 18 06:42:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816333 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56267C433F5 for ; Mon, 18 Apr 2022 06:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236829AbiDRGqX (ORCPT ); Mon, 18 Apr 2022 02:46:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236568AbiDRGqS (ORCPT ); Mon, 18 Apr 2022 02:46:18 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2080.outbound.protection.outlook.com [40.107.101.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C6DF13DF7 for ; Sun, 17 Apr 2022 23:43:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SiZv3B2KMg/bTrukm1MpkRIHCtWsH3nbIjSRMgLihWff+R/OP9SPbEl76KcKfBlJDjHKXQP70gFoIA7unX07jVIz9Mu1BWFFja6X5JVXSB4K0q/BViB+fUJ3+7IB16fB2v9d7h+GIicqXQbLhFv5yPx5F9AjRTIlhNRiysyNeNaVlp12pAFQL9PaseVMPGvBDOjHPOws6qM1lCXuHHUhOpHb8doRSxwGoJQp0NGcYe2iKqQq07R8etfBJHuBJL6ndPDVVYiJ0rB6pJ7K5nIwR55WQl2v2ZWC2BBzmNhZKf3gBuHbhdZUAXrN2keynqlx171wEdNpto5e9LCB/sVKKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CF0z3stqiJ+WwBag92buzBYHEdFVbXPd9qoDiVqe9G8=; b=dt05TUOuNhKdIbkDAcoeGOB8ve5rI2YXfylR0BAmW3ZEITGhZweo2uG2DoBFIA/o0yiNmMiWfptfSHHNQefmc/p3eQ+Kxg9/V/wZEWnYhlTmP0dKmAh3OaRR69keyofgFGhEwjSScJM/DMrK+JqGGesPDM7HMnv+s53vIuVlZiyZKLqDN5eVmRR4l3Ub0K/SEHwhB6s+XZF8egCHO8cm5G2gyvt4SUz8vIa7pFNu3LexQowXcemagVA56Bi1DoWz+E85CD+IyVCT/rhxIj79IvUHCvKF905vOjNF/PM5++BcME8OKTjVTcVy1TFTc/+XV8p/+/dHdiDFW4LruMSjHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CF0z3stqiJ+WwBag92buzBYHEdFVbXPd9qoDiVqe9G8=; b=o/GCxcwcNDJ5g4W7R9vBk/Si6tmXXW0NNCZlM10fFuRJ3kZo3uhX4psis9DX6V9v9MC1ma6Fou4GtMXHIZ1dv+LSHVjfbSdfC1S9JNoS6PrkQtBz2MGA9j8b6nrTffVYXjUop2E/C7Vv65/7CRXHnK/Ku9db00cBJ2FBzcxNST9TCaAjsfd6G80AgcVNp14sSUihnsAgf097bOyMqEXEHsTYzxzeYBEK/OB0z0Qkc0+sDJgeoaPqfoNhkM/zzbWBbfdS6bX9Z5y9Ryj1eVFnbNwGL/XRTgtbv2CF49TJAEayOx60BDtC4l1yPEoOoDMYatrrYTo18m9ewMJUN1VYQQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:43:37 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:43:37 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 02/17] devlink: implement line card provisioning Date: Mon, 18 Apr 2022 09:42:26 +0300 Message-Id: <20220418064241.2925668-3-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0062.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:153::13) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e2765ce6-fd71-4669-8f88-08da2106c411 X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y9SuFvpEE8ykpUnHLNYcbQtGvkrzvo/ZjVaJqqjArpHF260C5BpOcWrpF9irBZ4QaKPyRnNUGqMi4mwBnthVXXSbfEz7E3EYKZqj2/SKoxbbG48QfMI2LDUvSbpKxatEB6L/MG/QD43G5UzyVG8vssrL3Dn6X5YP1oUxHhXMxtanyZUqvEgTGcyAQCTGtDxSLjTBn0yUZ72zKpEGG/5OD6F7lf0ACZuGgFjXPExM9QUolqv+pJa+qWXis4UedbZnHRr3x3Dovo+HMzMPtUTg8I/iDFt54vhfOk7xu67Cl1ASA1hSAHWFeGtd3P4sQhn4BEOsofK8TFoln9Jq6UhNp4i9fSu/eAEzHZXQrtldx9N2qRnBYQjtK6rRzKsYY2bCBKkW6UJcnOwrRVUvy7Wd4EfL1oDa0SX5dheXYUB9AHtwSNYLajaDlGsGkLhXclnIyuSAfp58pRQAd0pReKLCRxq/xGyX757roxfyDSjaMFlCr40bRGEBV3wQBa3gXmbnk8hZ4+cqhHEHMITXpkfRZ/ppF4El0ZzyCVtx3n1q75tJFm61v1wpwIm5FUt3yHrfGM9N1coBDBnZhL2JHhmw7QICZ04BJMV77Bnsll5bY20q4m9lt3q4JBr/TPsx4XlGKJ8Hp5VLzXPdvSwoLUpPCA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(30864003)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8zOP1kCMHDStchZKmBT17XLr+A8uOx/X2kgJdPmuT4S1JR5JpLvO8eiTG2zkZ3jAiVCK3ljslkOglSh45qJo3LufGc3YJ91fMsl5tl1MCr5MTJDltMzVutqfbxrN3QuW8kxB0QpGSrxTzC6WrpclnZcrQEaTi2sG3tarW4Kwkx7Mc40bsoTzvo4hHuT5X3mn6SWWRZbuRZenEzvw1Q5/+D6YonTle3G8n1eYX7Ae+GZxPRPpR2dIuRjxPDlJ5Kdokk/Gd7IgFSWtGTEEnyJdNxK4zZwmkTBdXxE0DLJlseHwF3oqYhjnRdSw/R5J6ZnICn/RNpueKUPE+KI6Fwb9LswAOxHvdJBvGYFQYwN6ODUOjfh5gzymZbRG8r2rb1lPAfIsauUONn5OqtG7aUNtr7W+9tqMcnvw1OUcKC08MYTO3HVARFrA3KlvDF1t167Sa83qNma1krI/R37RY2vGahMNMAo363dEiDY5Bn126oxZc0Gn2DnKLsDqz75N2u6hklCKQ4hwntavp6abrw+1nujTmu60qo+h3lqRuH+w9JUjxFbs0Jtqn9nXluxoEEttbFxeY1MlvCxf3ij5mbJ2SidUqUjRSKeBCQL50a088nTdggQENv2pNns+UgoYrNRzdq9IuJ8NX0TLTp6GLW0f4vhk0KxbqNGv8MDb4f1oQaXet48opuxLxQXq6GzHv8bWVTOetvN8FNpyaJLTEvGZ3doP9GINZD75B5JccPKHodrYU+bGiHOwDe82aU5rXKYH6Cn5bydAXZTEj0g9W2mknUbh4iDFdupm1q3osPI/AnEGFGkrqazMqWav/F9xkdQWgZxMdS+wPIHcrKFlYw5qHpJVT98TTPozwRg4+4qS3q51yDUswdcxx6Z3A0a1ZRmPj1qzd+s//PYOzEq5eiPFixyk36V4BTRz1cKAcoK7ze1aXyuS3nIkLd17AHEUaStAaUY3P+koNClvntIRj8S3MIG0KygDe1cYVQskk2Zgrk9evFQZsiEo0Fwe5cikuEmfqS0EIdcm4zqLXhn5oJpcszWegNW+GVuVdBPvwXu0i7Otbp5pvjm0UZpLplWQlND8o3JqTwjvgVEuIQW9yWhzOzG0Vp/M8Ot67B97Kr5Rl87JB83v7NiAQPGBSSYsJXl2VGapQv5wxoPrDL0+xpw+IOXSqABXC8EiIaWB8g9fOvcENMp3g9cdkiBqJNqwDlc4XiH4E2oS7xnDTf22BPSrc9es0Jqy0j9/WfNV+ueLvZ33G5vNGQTUylv1u0RrqG9FEv39jj7vtiF+FB5UMJm1PRdcjaG/SGUfs7YTFY+PBbPBYFIFRK1battZ5zBamz6hN+3dhBZmwasLpfcSrRAQkjonqnEHfPuNvWDxMqUEMglP+H52wjR35tOshiTtoXVegPwtSHvi+39OC3rOxFq4xuOPih8zIgR2N8HnTIP2ntNq7mrbwWvt0Pi8xM3kkWTlnaqCugc+/U1klQ1vRhz9fbOfUTZtXbQx2rQgeM9ohpH51MHZvtNsPilArILszt5QYLgLsa2KeAHyFTtQ/eKnKdN2kYfhJHrCHrm2F2uax/SFEst54ItYmndzefyW357Tv3d4HDYFHl9GPpELaKR5gCsua+OFnk5rTbIreAHGQqOcDf0IXj/tnPI1gd2XObSpaHyvQ2wEapFryoLBnRtXnqOXOYGuRlEQKNRhKNbbWec4/a2+xFnrqmRl1BwTrEQ0moxOSeVF1hrHTgEeCLI6UQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e2765ce6-fd71-4669-8f88-08da2106c411 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:43:37.2310 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Watw1Ug22GfPS8qNjlkfQ3h2uH7An6JZMxX2aaWA2XPJYsy/zYa5pLUj84NNiTienvJ6QS6CS8l4bocdLZ43SA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In order to be able to configure all needed stuff on a port/netdevice of a line card without the line card being present, introduce line card provisioning. Basically by setting a type, provisioning process will start and driver is supposed to 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 command SET to allow user to set/unset the 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. These helpers are not to be called directly due to the async nature of provisioning. Example: $ devlink port # No ports are listed $ devlink lc pci/0000:01:00.0: lc 1 state unprovisioned supported_types: 16x100G lc 2 state unprovisioned supported_types: 16x100G lc 3 state unprovisioned supported_types: 16x100G lc 4 state unprovisioned supported_types: 16x100G lc 5 state unprovisioned supported_types: 16x100G lc 6 state unprovisioned supported_types: 16x100G lc 7 state unprovisioned supported_types: 16x100G lc 8 state unprovisioned supported_types: 16x100G $ devlink lc set pci/0000:01:00.0 lc 8 type 16x100G $ devlink lc show pci/0000:01:00.0 lc 8 pci/0000:01:00.0: lc 8 state active type 16x100G supported_types: 16x100G $ devlink port pci/0000:01:00.0/0: type notset flavour cpu port 0 splittable false pci/0000:01:00.0/53: type eth netdev enp1s0nl8p1 flavour physical lc 8 port 1 splittable true lanes 4 pci/0000:01:00.0/54: type eth netdev enp1s0nl8p2 flavour physical lc 8 port 2 splittable true lanes 4 pci/0000:01:00.0/55: type eth netdev enp1s0nl8p3 flavour physical lc 8 port 3 splittable true lanes 4 pci/0000:01:00.0/56: type eth netdev enp1s0nl8p4 flavour physical lc 8 port 4 splittable true lanes 4 pci/0000:01:00.0/57: type eth netdev enp1s0nl8p5 flavour physical lc 8 port 5 splittable true lanes 4 pci/0000:01:00.0/58: type eth netdev enp1s0nl8p6 flavour physical lc 8 port 6 splittable true lanes 4 pci/0000:01:00.0/59: type eth netdev enp1s0nl8p7 flavour physical lc 8 port 7 splittable true lanes 4 pci/0000:01:00.0/60: type eth netdev enp1s0nl8p8 flavour physical lc 8 port 8 splittable true lanes 4 pci/0000:01:00.0/61: type eth netdev enp1s0nl8p9 flavour physical lc 8 port 9 splittable true lanes 4 pci/0000:01:00.0/62: type eth netdev enp1s0nl8p10 flavour physical lc 8 port 10 splittable true lanes 4 pci/0000:01:00.0/63: type eth netdev enp1s0nl8p11 flavour physical lc 8 port 11 splittable true lanes 4 pci/0000:01:00.0/64: type eth netdev enp1s0nl8p12 flavour physical lc 8 port 12 splittable true lanes 4 pci/0000:01:00.0/125: type eth netdev enp1s0nl8p13 flavour physical lc 8 port 13 splittable true lanes 4 pci/0000:01:00.0/126: type eth netdev enp1s0nl8p14 flavour physical lc 8 port 14 splittable true lanes 4 pci/0000:01:00.0/127: type eth netdev enp1s0nl8p15 flavour physical lc 8 port 15 splittable true lanes 4 pci/0000:01:00.0/128: type eth netdev enp1s0nl8p16 flavour physical lc 8 port 16 splittable true lanes 4 $ devlink lc set pci/0000:01:00.0 lc 8 notype Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../networking/devlink/devlink-linecard.rst | 121 +++++++ Documentation/networking/devlink/index.rst | 1 + include/net/devlink.h | 43 ++- include/uapi/linux/devlink.h | 15 + net/core/devlink.c | 322 +++++++++++++++++- 5 files changed, 497 insertions(+), 5 deletions(-) create mode 100644 Documentation/networking/devlink/devlink-linecard.rst diff --git a/Documentation/networking/devlink/devlink-linecard.rst b/Documentation/networking/devlink/devlink-linecard.rst new file mode 100644 index 000000000000..63ccd17f40ac --- /dev/null +++ b/Documentation/networking/devlink/devlink-linecard.rst @@ -0,0 +1,121 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================= +Devlink Line card +================= + +Background +========== + +The ``devlink-linecard`` mechanism is targeted for manipulation of +line cards that serve as a detachable PHY modules for modular switch +system. Following operations are provided: + + * Get a list of supported line card types. + * Provision of a slot with specific line card type. + * Get and monitor of line card state and its change. + +Line card according to the type may contain one or more gearboxes +to mux the lanes with certain speed to multiple ports with lanes +of different speed. Line card ensures N:M mapping between +the switch ASIC modules and physical front panel ports. + +Overview +======== + +Each line card devlink object is created by device driver, +according to the physical line card slots available on the device. + +Similar to splitter cable, where the device might have no way +of detection of the splitter cable geometry, the device +might not have a way to detect line card type. For that devices, +concept of provisioning is introduced. It allows the user to: + + * Provision a line card slot with certain line card type + + - Device driver would instruct the ASIC to prepare all + resources accordingly. The device driver would + create all instances, namely devlink port and netdevices + that reside on the line card, according to the line card type + * Manipulate of line card entities even without line card + being physically connected or powered-up + * Setup splitter cable on line card ports + + - As on the ordinary ports, user may provision a splitter + cable of a certain type, without the need to + be physically connected to the port + * Configure devlink ports and netdevices + +Netdevice carrier is decided as follows: + + * Line card is not inserted or powered-down + + - The carrier is always down + * Line card is inserted and powered up + + - The carrier is decided as for ordinary port netdevice + +Line card state +=============== + +The ``devlink-linecard`` mechanism supports the following line card states: + + * ``unprovisioned``: Line card is not provisioned on the slot. + * ``unprovisioning``: Line card slot is currently being unprovisioned. + * ``provisioning``: Line card slot is currently in a process of being provisioned + with a line card type. + * ``provisioning_failed``: Provisioning was not successful. + * ``provisioned``: Line card slot is provisioned with a type. + +The following diagram provides a general overview of ``devlink-linecard`` +state transitions:: + + +-------------------------+ + | | + +----------------------------------> unprovisioned | + | | | + | +--------|-------^--------+ + | | | + | | | + | +--------v-------|--------+ + | | | + | | provisioning | + | | | + | +------------|------------+ + | | + | +-----------------------------+ + | | | + | +------------v------------+ +------------v------------+ + | | | | | + +----- provisioning_failed | | provisioned | + | | | | | + | +------------^------------+ +------------|------------+ + | | | + | | | + | | +------------v------------+ + | | | | + | | | unprovisioning | + | | | | + | | +------------|------------+ + | | | + | +-----------------------------+ + | | + +-----------------------------------------------+ + + +Example usage +============= + +.. code:: shell + + $ devlink lc show [ DEV [ lc LC_INDEX ] ] + $ devlink lc set DEV lc LC_INDEX [ { type LC_TYPE | notype } ] + + # Show current line card configuration and status for all slots: + $ devlink lc + + # Set slot 8 to be provisioned with type "16x100G": + $ devlink lc set pci/0000:01:00.0 lc 8 type 16x100G + + # Set slot 8 to be unprovisioned: + $ devlink lc set pci/0000:01:00.0 lc 8 notype diff --git a/Documentation/networking/devlink/index.rst b/Documentation/networking/devlink/index.rst index c17cdb079611..850715512293 100644 --- a/Documentation/networking/devlink/index.rst +++ b/Documentation/networking/devlink/index.rst @@ -39,6 +39,7 @@ general. devlink-resource devlink-reload devlink-trap + devlink-linecard Driver-specific documentation ----------------------------- diff --git a/include/net/devlink.h b/include/net/devlink.h index 7aabdfb3bc6a..3e49d4ff498c 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -149,6 +149,40 @@ struct devlink_port_new_attrs { sfnum_valid:1; }; +/** + * struct devlink_linecard_ops - Linecard operations + * @provision: callback to provision the linecard slot with certain + * type of linecard. As a result of this operation, + * driver is expected to eventually (could be after + * the function call returns) call one of: + * devlink_linecard_provision_set() + * devlink_linecard_provision_fail() + * @unprovision: callback to unprovision the linecard slot. As a result + * of this operation, driver is expected to eventually + * (could be after the function call returns) call + * devlink_linecard_provision_clear() + * devlink_linecard_provision_fail() + * @same_provision: callback to ask the driver if linecard is already + * provisioned in the same way user asks this linecard to be + * provisioned. + * @types_count: callback to get number of supported types + * @types_get: callback to get next type in list + */ +struct devlink_linecard_ops { + int (*provision)(struct devlink_linecard *linecard, void *priv, + const char *type, const void *type_priv, + struct netlink_ext_ack *extack); + int (*unprovision)(struct devlink_linecard *linecard, void *priv, + struct netlink_ext_ack *extack); + bool (*same_provision)(struct devlink_linecard *linecard, void *priv, + const char *type, const void *type_priv); + unsigned int (*types_count)(struct devlink_linecard *linecard, + void *priv); + void (*types_get)(struct devlink_linecard *linecard, + void *priv, unsigned int index, const char **type, + const void **type_priv); +}; + struct devlink_sb_pool_info { enum devlink_sb_pool_type pool_type; u32 size; @@ -1537,9 +1571,14 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, int devlink_rate_leaf_create(struct devlink_port *port, void *priv); void devlink_rate_leaf_destroy(struct devlink_port *devlink_port); void devlink_rate_nodes_destroy(struct devlink *devlink); -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, + const char *type); +void devlink_linecard_provision_clear(struct devlink_linecard *linecard); +void devlink_linecard_provision_fail(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 59c33ed2d3e7..de91e4a0d476 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -343,6 +343,18 @@ 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_PROVISIONING_FAILED, + 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, @@ -559,6 +571,9 @@ enum devlink_attr { DEVLINK_ATTR_REGION_MAX_SNAPSHOTS, /* u32 */ 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 4cdacd74b82a..b7c3a82fbd4b 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -72,11 +72,21 @@ struct devlink { char priv[] __aligned(NETDEV_ALIGN); }; +struct devlink_linecard_ops; +struct devlink_linecard_type; + struct devlink_linecard { struct list_head list; struct devlink *devlink; unsigned int index; refcount_t refcount; + const struct devlink_linecard_ops *ops; + void *priv; + enum devlink_linecard_state state; + struct mutex state_lock; /* Protects state */ + const char *type; + struct devlink_linecard_type *types; + unsigned int types_count; }; /** @@ -452,8 +462,10 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) static void devlink_linecard_put(struct devlink_linecard *linecard) { - if (refcount_dec_and_test(&linecard->refcount)) + if (refcount_dec_and_test(&linecard->refcount)) { + mutex_destroy(&linecard->state_lock); kfree(linecard); + } } struct devlink_sb { @@ -2037,6 +2049,11 @@ static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, return err; } +struct devlink_linecard_type { + const char *type; + const void *priv; +}; + static int devlink_nl_linecard_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_linecard *linecard, @@ -2044,7 +2061,10 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg, u32 seq, int flags, struct netlink_ext_ack *extack) { + struct devlink_linecard_type *linecard_type; + struct nlattr *attr; void *hdr; + int i; hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); if (!hdr) @@ -2054,6 +2074,27 @@ 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->type && + nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, linecard->type)) + goto nla_put_failure; + + if (linecard->types_count) { + attr = nla_nest_start(msg, + DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES); + if (!attr) + goto nla_put_failure; + for (i = 0; i < linecard->types_count; i++) { + linecard_type = &linecard->types[i]; + if (nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, + linecard_type->type)) { + nla_nest_cancel(msg, attr); + goto nla_put_failure; + } + } + nla_nest_end(msg, attr); + } genlmsg_end(msg, hdr); return 0; @@ -2103,10 +2144,12 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, if (!msg) return -ENOMEM; + mutex_lock(&linecard->state_lock); err = devlink_nl_linecard_fill(msg, devlink, linecard, DEVLINK_CMD_LINECARD_NEW, info->snd_portid, info->snd_seq, 0, info->extack); + mutex_unlock(&linecard->state_lock); if (err) { nlmsg_free(msg); return err; @@ -2139,12 +2182,14 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, idx++; continue; } + mutex_lock(&linecard->state_lock); 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); + mutex_unlock(&linecard->state_lock); if (err) { mutex_unlock(&devlink->linecards_lock); devlink_put(devlink); @@ -2163,6 +2208,163 @@ static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg, return msg->len; } +static struct devlink_linecard_type * +devlink_linecard_type_lookup(struct devlink_linecard *linecard, + const char *type) +{ + struct devlink_linecard_type *linecard_type; + int i; + + for (i = 0; i < linecard->types_count; i++) { + linecard_type = &linecard->types[i]; + if (!strcmp(type, linecard_type->type)) + return linecard_type; + } + return NULL; +} + +static int devlink_linecard_type_set(struct devlink_linecard *linecard, + const char *type, + struct netlink_ext_ack *extack) +{ + const struct devlink_linecard_ops *ops = linecard->ops; + struct devlink_linecard_type *linecard_type; + int err; + + mutex_lock(&linecard->state_lock); + if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { + NL_SET_ERR_MSG_MOD(extack, "Line card is currently being provisioned"); + err = -EBUSY; + goto out; + } + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { + NL_SET_ERR_MSG_MOD(extack, "Line card is currently being unprovisioned"); + err = -EBUSY; + goto out; + } + + linecard_type = devlink_linecard_type_lookup(linecard, type); + if (!linecard_type) { + NL_SET_ERR_MSG_MOD(extack, "Unsupported line card type provided"); + err = -EINVAL; + goto out; + } + + if (linecard->state != DEVLINK_LINECARD_STATE_UNPROVISIONED && + linecard->state != DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) { + NL_SET_ERR_MSG_MOD(extack, "Line card already provisioned"); + err = -EBUSY; + /* Check if the line card is provisioned in the same + * way the user asks. In case it is, make the operation + * to return success. + */ + if (ops->same_provision && + ops->same_provision(linecard, linecard->priv, + linecard_type->type, + linecard_type->priv)) + err = 0; + goto out; + } + + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING; + linecard->type = linecard_type->type; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); + err = ops->provision(linecard, linecard->priv, linecard_type->type, + linecard_type->priv, extack); + if (err) { + /* Provisioning failed. Assume the linecard is unprovisioned + * for future operations. + */ + mutex_lock(&linecard->state_lock); + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; + linecard->type = NULL; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); + } + return err; + +out: + mutex_unlock(&linecard->state_lock); + return err; +} + +static int devlink_linecard_type_unset(struct devlink_linecard *linecard, + struct netlink_ext_ack *extack) +{ + int err; + + mutex_lock(&linecard->state_lock); + if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { + NL_SET_ERR_MSG_MOD(extack, "Line card is currently being provisioned"); + err = -EBUSY; + goto out; + } + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { + NL_SET_ERR_MSG_MOD(extack, "Line card is currently being unprovisioned"); + err = -EBUSY; + goto out; + } + if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) { + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; + linecard->type = NULL; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + err = 0; + goto out; + } + + if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONED) { + NL_SET_ERR_MSG_MOD(extack, "Line card is not provisioned"); + err = 0; + goto out; + } + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONING; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); + err = linecard->ops->unprovision(linecard, linecard->priv, + extack); + if (err) { + /* Unprovisioning failed. Assume the linecard is unprovisioned + * for future operations. + */ + mutex_lock(&linecard->state_lock); + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; + linecard->type = NULL; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); + } + return err; + +out: + mutex_unlock(&linecard->state_lock); + return err; +} + +static int devlink_nl_cmd_linecard_set_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_linecard *linecard = info->user_ptr[1]; + struct netlink_ext_ack *extack = info->extack; + int err; + + if (info->attrs[DEVLINK_ATTR_LINECARD_TYPE]) { + const char *type; + + type = nla_data(info->attrs[DEVLINK_ATTR_LINECARD_TYPE]); + if (strcmp(type, "")) { + err = devlink_linecard_type_set(linecard, type, extack); + if (err) + return err; + } else { + err = devlink_linecard_type_unset(linecard, extack); + if (err) + return err; + } + } + + return 0; +} + static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, enum devlink_command cmd, u32 portid, @@ -8789,6 +8991,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING }, [DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 }, + [DEVLINK_ATTR_LINECARD_TYPE] = { .type = NLA_NUL_STRING }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -8871,6 +9074,12 @@ 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_SET, + .doit = devlink_nl_cmd_linecard_set_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, @@ -9962,19 +10171,56 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, return 0; } +static int devlink_linecard_types_init(struct devlink_linecard *linecard) +{ + struct devlink_linecard_type *linecard_type; + unsigned int count; + int i; + + count = linecard->ops->types_count(linecard, linecard->priv); + linecard->types = kmalloc_array(count, sizeof(*linecard_type), + GFP_KERNEL); + if (!linecard->types) + return -ENOMEM; + linecard->types_count = count; + + for (i = 0; i < count; i++) { + linecard_type = &linecard->types[i]; + linecard->ops->types_get(linecard, linecard->priv, i, + &linecard_type->type, + &linecard_type->priv); + } + return 0; +} + +static void devlink_linecard_types_fini(struct devlink_linecard *linecard) +{ + kfree(linecard->types); +} + /** * devlink_linecard_create - Create devlink linecard * * @devlink: devlink * @linecard_index: driver-specific numerical identifier of the linecard + * @ops: linecards ops + * @priv: user priv pointer * * Create devlink linecard instance with provided linecard index. * Caller can use any indexing, even hw-related one. + * + * Return: Line card structure or an ERR_PTR() encoded error code. */ -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; + int err; + + if (WARN_ON(!ops || !ops->provision || !ops->unprovision || + !ops->types_count || !ops->types_get)) + return ERR_PTR(-EINVAL); mutex_lock(&devlink->linecards_lock); if (devlink_linecard_index_exists(devlink, linecard_index)) { @@ -9990,6 +10236,19 @@ 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; + mutex_init(&linecard->state_lock); + + err = devlink_linecard_types_init(linecard); + if (err) { + mutex_destroy(&linecard->state_lock); + kfree(linecard); + mutex_unlock(&devlink->linecards_lock); + return ERR_PTR(err); + } + list_add_tail(&linecard->list, &devlink->linecard_list); refcount_set(&linecard->refcount, 1); mutex_unlock(&devlink->linecards_lock); @@ -10010,11 +10269,68 @@ void devlink_linecard_destroy(struct devlink_linecard *linecard) devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); mutex_lock(&devlink->linecards_lock); list_del(&linecard->list); + devlink_linecard_types_fini(linecard); mutex_unlock(&devlink->linecards_lock); devlink_linecard_put(linecard); } EXPORT_SYMBOL_GPL(devlink_linecard_destroy); +/** + * devlink_linecard_provision_set - Set provisioning on linecard + * + * @linecard: devlink linecard + * @type: linecard type + * + * This is either called directly from the provision() op call or + * as a result of the provision() op call asynchronously. + */ +void devlink_linecard_provision_set(struct devlink_linecard *linecard, + const char *type) +{ + mutex_lock(&linecard->state_lock); + WARN_ON(linecard->type && strcmp(linecard->type, type)); + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; + linecard->type = type; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_provision_set); + +/** + * devlink_linecard_provision_clear - Clear provisioning on linecard + * + * @linecard: devlink linecard + * + * This is either called directly from the unprovision() op call or + * as a result of the unprovision() op call asynchronously. + */ +void devlink_linecard_provision_clear(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->state_lock); + linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; + linecard->type = NULL; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear); + +/** + * devlink_linecard_provision_fail - Fail provisioning on linecard + * + * @linecard: devlink linecard + * + * This is either called directly from the provision() op call or + * as a result of the provision() op call asynchronously. + */ +void devlink_linecard_provision_fail(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->state_lock); + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + mutex_unlock(&linecard->state_lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_provision_fail); + 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 Mon Apr 18 06:42:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816334 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDEB7C433EF for ; Mon, 18 Apr 2022 06:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236819AbiDRGqY (ORCPT ); Mon, 18 Apr 2022 02:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236800AbiDRGqX (ORCPT ); Mon, 18 Apr 2022 02:46:23 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2041.outbound.protection.outlook.com [40.107.101.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03A6B18E38 for ; Sun, 17 Apr 2022 23:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QzrjJT0ODstpV8jGpQ2Lo+R9j5WIh5HHWcHIu3g7zFJ4eW8kUwWIl8dMhjYEINgTE3noI92wiISJaVdNaWj+eHemFp8lI0BWaikf4eAa898LWX8aKkGq9B5ITPbMtPdTAHOHkGUWsu1G5Fuf3xGq+Az36Yx0XWI+M+yfXzShLw7pPc+7VQdrZjKrv/9ALFz6D2BTKdrAoK9fhxCKE9fFHVCbbCXgCyD6F5Brefzaa0wpB/Y9XMoYzXV9AJn9SuQpoGjjQV9L8TXmAhfvSp7kVn29DUtc/4n4pbxV+OCMYYtl13kwRNY7Iwe9JsdLzU8l14DkL+Xk5eVQ/H5fDAcvfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OPvQHzFOFuJIvhYGTkU0X13nJ2klROzwDet0U/0KqEk=; b=lZxhBYlwHKP7g4o9LQVcqKXloFUTcZ5W23QM5l6TEoxutVegfKW3f7EmEydCftGcLI5tVAT6MSj/IJHdiqcmu/SwuqKfqKX+W8Kb+MARWEk6wTBw0aqo89CeLHtsv3PMEEyqudpl0mY9M7GnvcOXsCmznjaFgsYkj3XYmabBPhqODOXolL8kSfYIaWhNnatxZ/7kw3Qb7yIFWCBh/tn7fjmTXRdHYd5i53xuJM3yh1+EHydP0UylNaiqEyI8Ql00dpoTA18LoFDUsc3nMV2FRjdV5M7i+FDnM/JiAtI0tZVM1uVOK695OY2r/UCRnuOJ3ZUDL9aAVv5cW5WrfJ7UUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OPvQHzFOFuJIvhYGTkU0X13nJ2klROzwDet0U/0KqEk=; b=OlcvzX19uKlRd2HKcsIU6G2bFpL3oZLTKnRU1AYuV7Kl+fLSCaCBlNUDLDlj97jTbBGb/j0rQkoIPXUD8eAld0yLD9l+rYVltWAgWSmNer5s99IqgEqnwqtG/+UNE9OeRWAmM+Qych9RPv3H/7jQj0WdC0fu5B0ok0faJk2zAL4ceJXETej82egbq/ThFBc1SXGHRdyIGapybhR6KMRM0fMpnJCLSNonRsUCoxQCWM4pvd5Yky7xK/wYdY4WV9Hgx9gCcHRVx1es/VeLzahVIkiZNCCiy3DvnOnKbuG6CnASMGeGTIlfC+4p4E5v1pPJpTycl6hpSS64BjqmGr9D+Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:43:43 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:43:43 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 03/17] devlink: implement line card active state Date: Mon, 18 Apr 2022 09:42:27 +0300 Message-Id: <20220418064241.2925668-4-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0153.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:188::14) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef517cbc-1fba-4099-40c2-08da2106c7f6 X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f98YJleaOZyxNha+fOaQ0VuYUEYUKwSZxPDhKdODBrg0Bu6f1Xc6SNQKpXYK0mX5FMrVSGk7mIderekhfh8paytON8ISljY+8jnBxb5DjmoVLA8GrNScHOrUs2XwYS96gno300lhl5YTPcRpg4bc3Xx+VDTWGvLAghYzjhnMG38/bwrX4Txg/oLyiPe1/b5Ebqp+gdb6yHovZikjDWvEU9b+4V3cnxT0D8AxW6Fxi/V0mzdudxA7RDIt6SQfeZt86QTWAWewrUXUZoRkNt2bV/q9SDQWXawjPawwe6NxLoCI9XiaACd2BfpU289W9fVmO/o2OlTocwTM66ZP4anTfBDYCG9lgQqEZlmTHWogDhBc0W0Wwdos/daeDWffsILefZcb9u/Ri57aw04K8ZX7XtVzk1leAWknLn/qH3c4dHTyDnR/SEJ4KFyandj9ntCAXV84IBCGJQ1Cv84b9cY45ZouuEh0eQzeWra4TkZXhIiWoxOVC3dnbnsbEeO5+wWIAULxI5ocXErXPasaxRkzSRCHqmXKqLfPsrJcSeK+DgzvbPmlfhLdXKoGH1xsblF3/w9OtTPXH6aKOSOVi8rZv+/CWjNo6p4z4oaoBU7KrXpaBRjEjNtCjzViLq3SOpAPFmKIQRPlefP+QlB9U5uvJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V8a9gN9yEr+Oxy2NI6TkoD0AbYF1jDpkSIV90ziDki/JH6W38JSw8z+h7yAawslcaO3vbZlFTBhJEjVUWmnmHvEHNbA3rQjCnqe1t0tF5yWas61IynNURPdbTl0NbLOe/V52TSZt/PXXe16kltB6YvRnNcUnFq9Kp5kts9emeT0zrSJXcvpkjfYMXNMnqCwngFcDdVCjDCdJUPfXUep/s8wS/hZUHdwVVHAyOeXvhsbY/rUHan08pDjBGZADcrVOgJeKs/2A40UTW1vknh9pNwYTx3gIUKGT71bxXkjXdxlxqhPbI+l4qZT/9pawLSeZOcQDKl316s4BjVIBZ73olwVhrfC4WdV4VI+tQhVwWWIoBctwbvyDPtepkhktB+KM/9fvMK9SF7hC68mVYvG3No+OzSTMMtrD/nOCw8iL3n7R28aWfI8LcxLcm8tTGpLneEGce/HuliedpjIjBS+DaEeLk3d+1yVE4ne5w7zc8Pn7RTohtw5hgDmnlG8FmD1UhC1d2Ah4QKKbLTHUp+nmQ/EElbdJTgFgrule4OW1tfOtSidOgkt9fbOKtGcxNpOqQbBhDpNlg4Ay584Q46bj/JD+s88KBEVak/jA1/eU1hn7ct8uOeF/hwdYXMRXpHXAi9PT8u2X1CDt6SvcoqM7mD0mhoi7Ne90yCwm+87pOgoJMvuyP4hITKNd7oRK5fOM/G+T6ScLrzBBV45rL4IFdcafUs9cB3Fr/p3mkJ3pOcn5QrPNnhJ3gP1rn+Q/82UjnoozY3qoneN3oBJ7+khIpUCDDX/Dxrek9a7eh9lj+eEodvLFySt7iwDYgsxIqrrB2hvpVEoLww4e03vU6hgLAtoP5ZhIjwpDlNCyR12I9VPVi8XwJLexsQ1e+IIf+/k3ZR15dJrO774Gnj1mazKSoQhyHNbxzlQhtsYDqZvrhpR0XVVeuQcfX/iqs6ekK2HankqjjFkBwwcnl/sB8FblahLzMn7Wa7AQ2slwkdqNqsxtEUxk8UX6R0ahA5gRKMp8SL4IPNaSkeBigZBqgv6vPVuhiGodZ2Ryi4Z5BQ50TLaMDZeAcO8RvnROCf7pLU6whihAbXX9xjAKXlTErt1t5UPgNasqNZ5Rugvj7hwwzILvbwdzBbWKUmd5Mmr5RPMviaPb85pKku4uoF65FqQtLgNSaLUSH2PcRiFtc1o+sWbZaZSUly4do2nbh0Hx0tnlEv4am/JZtPPe/3eCh2jppxBddmL+RV2/5yxiPDyQS5B2CEykwvqlkqwZiZzTO5IPJbB1KECgofc0DVBzUjdhyU/DpGtyF2ay4Vsm1X6PpExeh3a57MFMtX1KnY7EGoi+USdBdNYSy2RqZz337+Txu086lWxd9BrUbNEha0GEmNYgRuoOzkAn7u/EK5CQZFTz7SN7iqxY41t/vLusyPSyb8/f8S+JRHQStacVEY/FhmNbPoqD5FgXhaPOABlY104pM2Gb4qOOduWjFKWKiFtexrtY7QYsH4S9gWZhzNP/032cKDE4cLRZ/4AUjQoebeqsB2u6DsyHRL8W6eB/Jmm/zon2x6mFzgtPIfUYsw5X7fJqzV8DBaOFcaz0anMiUwGHE/Sz1/HEdUUuZgrEWgb3BjshCzHia6vVBcNwSshhwl5L5dkb9Ax6SABI75EhvRfiwePI4Udr6gayDshhcEaQHaMMEQkl/LxGpB0fxcfRSjTb0SdHJ7ZV4joJcMCcTiGvMkpIKhh0nsvFsuDPRZLb+A== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef517cbc-1fba-4099-40c2-08da2106c7f6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:43:43.6078 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Wzt0i76/OG89ZUbTxcmXjhVo49zxgR5np4nqBXJqi+EyGQ1/nGXbk2bU3FDxczJ3ytR2Fk6DeZl/QyWN+8OvUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Allow driver to mark a line card as active. Expose this state to the userspace over devlink netlink interface with proper notifications. 'active' state means that line card was plugged in after being provisioned. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../networking/devlink/devlink-linecard.rst | 11 ++--- include/net/devlink.h | 2 + include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 41 +++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/devlink/devlink-linecard.rst b/Documentation/networking/devlink/devlink-linecard.rst index 63ccd17f40ac..6c0b8928bc13 100644 --- a/Documentation/networking/devlink/devlink-linecard.rst +++ b/Documentation/networking/devlink/devlink-linecard.rst @@ -66,6 +66,7 @@ The ``devlink-linecard`` mechanism supports the following line card states: with a line card type. * ``provisioning_failed``: Provisioning was not successful. * ``provisioned``: Line card slot is provisioned with a type. + * ``active``: Line card is powered-up and active. The following diagram provides a general overview of ``devlink-linecard`` state transitions:: @@ -85,11 +86,11 @@ state transitions:: | | | +-----------------------------+ | | | - | +------------v------------+ +------------v------------+ - | | | | | - +----- provisioning_failed | | provisioned | - | | | | | - | +------------^------------+ +------------|------------+ + | +------------v------------+ +------------v------------+ +-------------------------+ + | | | | ----> | + +----- provisioning_failed | | provisioned | | active | + | | | | <---- | + | +------------^------------+ +------------|------------+ +-------------------------+ | | | | | | | | +------------v------------+ diff --git a/include/net/devlink.h b/include/net/devlink.h index 3e49d4ff498c..d8061a11fee6 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1579,6 +1579,8 @@ void devlink_linecard_provision_set(struct devlink_linecard *linecard, const char *type); void devlink_linecard_provision_clear(struct devlink_linecard *linecard); void devlink_linecard_provision_fail(struct devlink_linecard *linecard); +void devlink_linecard_activate(struct devlink_linecard *linecard); +void devlink_linecard_deactivate(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 de91e4a0d476..b3d40a5d72ff 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -350,6 +350,7 @@ enum devlink_linecard_state { DEVLINK_LINECARD_STATE_PROVISIONING, DEVLINK_LINECARD_STATE_PROVISIONING_FAILED, 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 b7c3a82fbd4b..aec0a517282c 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -10331,6 +10331,47 @@ void devlink_linecard_provision_fail(struct devlink_linecard *linecard) } EXPORT_SYMBOL_GPL(devlink_linecard_provision_fail); +/** + * devlink_linecard_activate - Set linecard active + * + * @linecard: devlink linecard + */ +void devlink_linecard_activate(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->state_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->state_lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_activate); + +/** + * devlink_linecard_deactivate - Set linecard inactive + * + * @linecard: devlink linecard + */ +void devlink_linecard_deactivate(struct devlink_linecard *linecard) +{ + mutex_lock(&linecard->state_lock); + switch (linecard->state) { + case DEVLINK_LINECARD_STATE_ACTIVE: + linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; + devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); + break; + case DEVLINK_LINECARD_STATE_UNPROVISIONING: + /* Line card is being deactivated as part + * of unprovisioning flow. + */ + break; + default: + WARN_ON(1); + break; + } + mutex_unlock(&linecard->state_lock); +} +EXPORT_SYMBOL_GPL(devlink_linecard_deactivate); + 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 Mon Apr 18 06:42:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816335 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 786E2C433F5 for ; Mon, 18 Apr 2022 06:44:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236827AbiDRGqh (ORCPT ); Mon, 18 Apr 2022 02:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236822AbiDRGq2 (ORCPT ); Mon, 18 Apr 2022 02:46:28 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2089.outbound.protection.outlook.com [40.107.101.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE45B18E36 for ; Sun, 17 Apr 2022 23:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MyzgDP8kY1jhUb4/R3ypyobjUYifj/mXq71JR7o3/Q0Ioi2kVhTsQcN34vaENwLpEsE5M5ze1OLPG5gPp5/ERXpn+oDz8K70MrP526hPy3R2RAj8rpupLxhhG3ZjjcD8z7Dhlo9I5IEztpZf04N5/3lVm6ROKLu48OxDbXljN96lzuLDfJXp0A/BXCrspVnvh34IIH+N68+LJtn8UpkoGpiFcSmlWO8OCuTS7MpPmffZhnvw+a57W/LKL75RXn2I7QA4p7TExFnSfWc3B6LDPyjcUbTgJPfLMy/S2TuVV8W81A/8v/E5r3PywXAD1pkxe5C3d8YJwZpHqfMS4X9fNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PThkrQAtxogrvzu0RubvsXrpSNZwp7JiaK0XxPPqVkA=; b=ZLoHYEVf93Ptr1vi6lPyQvNb3OeK1mr4ZXFeRPmnrnIpc20OQry0QzXwwBh+C37xdhXD0iGDEEXBCvzbm2Blcxo/O0Rmf3lXotTQ27vnsSg44ythdLz9tozREdaMx61LrZ3H6GKmbThKhpcGBpVaM/Il+DrEWZdfSUrUKkphRm11Eox14k0mD77wPXN6zBFyyIWOg5d5vJIDRSqL/MIqNhJEsMq7HPvx8z9AXnsOZvMuruYazJ/pWbHPhgV6Qdd0j4NvSZFMVgz4syg4YDBGRB4Xt5rhHkKrMRhsvgcdSPjC3xMfCMKvCyFID3JDxx4q1DNzwQ0NmVurd8pTAMWMzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PThkrQAtxogrvzu0RubvsXrpSNZwp7JiaK0XxPPqVkA=; b=CIJD5tLlALh96HzPuwSYOzn7sr8VIzfaF4VzF98Fbu+24cYGIkgWDRxbgy+fmbhxXmOA0gZTkRkg8W8zEiktNZSeguea6M2eFozUl+a1rcyUj7nR0k/XpWhtEZrmdZgkZwljYnuJO034uw67IXYfJpXMJKSOcJITDajqWMuRS5pkaPBd7y5dl1w/qkoGY6qIOHpP5xfXDNPF7TaXUiD73QOUh4+51fIwJtUZBmrX5AVcUJ9b4G9kKDW3GyAD/xsYji8jOFdKTD3Hgse93y5Bo7iR/6LXuz31SoX3A/Ig0y46oZ+r2YMCHgbA3/k3BRnbr3z3ZoQJyZZWIDjXxuYsKw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:43:49 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:43:49 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 04/17] devlink: add port to line card relationship set Date: Mon, 18 Apr 2022 09:42:28 +0300 Message-Id: <20220418064241.2925668-5-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO2P265CA0503.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13b::10) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3d141b33-2800-4eb4-d0c4-08da2106cb74 X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7wsvtkujDq533+X7fMVDuQzaVoXWjYcpB1x0pb8rOaKLt1v5u4jPDRugHWSRciH8l5pGMRi2LDUYE68K7LineQkqw575jJcdP5K56KmsAsCXqXqM7bBC1XqCu3mKXycWHa+zrtqM2b4zhFa+isA/MiXXaLkRGMcium2gNj/WmhFEBdGgW472vKL0DpCg6308M02gyTkIVIye8urjIuKNUEca7s5oFw4D9sNLT+RH0EAwOtmVhmj84vibX8tYdz/NOvDcw6h1lFpp5rPu3H3KEEYxy86Gu1HdfHM3gWGCwtRG27NeUL3PKtZ59T9IeOc9HbdV7Rwh2FW0f8R6Z8ot8Ipmegl9jnZelnxdaKC9twgPuVuvAAGyFbJ2jIDcmuwml+26LTCLcmG2eno2l8hxu+HMbCQVkCX4l9yup+d8ibCNcSvsWalODgt+ptPl1k7CFzJlFmGIN3UzZ3vk3XEogaz6/nwynxq2h3wACJnHFLhegI7lZFVHFWrsJvmHzD9kcoxRFj5nUBnGz7WTfREvwJFciw/kw7GH2GDNW8YuUovNRCVq4S8+IvoRFhl0UnoGZcztSGFx5K/cBLn0MwVCmdJeoc0SO9AMYcBNVZuQGNC7DWQEJKot+4Vzt+I610AIeUxPa2e84jQIcMvFzsDnGw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Xgx9HbdGaKd+zXNai79BETOHZY0kSDRpk5Jg6G2fTNGSc6kQriYegYeSTW5/8g4MfQM8rYRSfzD52dndSlaF0wglrxz+1YFSm+lwsDejGIsFr6mU4ZbzEqqKLfbTHwWkRjopj8hkjIRCaj0p91JqOWPV/EOXFfeppUjNGNNNjx9sgKZek/8FPJdLsym35Of8AqS76sq9gSAUoN4cF/Z53VxG3Nslbqeys/pqrogzp1SVohFJYWciE2YXodNS36yS2SFApqGzMWPVRcM5WBsabYl5yWD0GiB9wfVoc67g6OW7nuC3S5fh4bWGt8+ie8Kb3jGNobRvCGhO2d/dtA+ctnz+vwb6ID3BJP/vfvDVfzzZA28HvSXUHCuJI4zZVF2CSFFv+iSMKS5aEXIEWp/8caUZ4aElUCwIpD0feTLFCoa8D/I3tTpW6hBw0bJ6HAJS/dYFTz1/muoa9KBDBTWpiMThHn7E8rPEArV7aw+SHTCIE0CTPKLW68kIUZcDInBFrxYPhWbFQgn6VSYLUPC/U0T5nQ39fzE13CpTh3LhFfYXwbnUGMC8oiURMFOe4AF+QHTxP/DbtoxvW5lzjH5fEpn5td3UPo2d/YZc9016wxm8VE8j1EY8qbc5I8AYH3P1y78E+E7uL0WILz0KBsUZR+4Ds0rdWFhJ/DyDPJSbzHZSFn4Jfq2FPwPzb7DiM7U7nvy7qFurBGcRg5rMJPpHH5lRrefEHT2gido5PxjSlr/tRx5ZGK1zuqfDyD5FMRqMwAAfgcfvgXwRnNiAqZK8NOhVa1eHcuhs6voswZrjyO83UQXAoTJLgUjeXpBOqTzf/FDlMhtxLoAx08Rg+VmOP6B7Wc3OMaF3YKprRJMnLMfzCya3Oza4ORLzDxvOha3K9B6xBlLrGq+125EWhkhdg5DRxqP3e+6If3j6mQBUOBMwq4ZiKmqz2RSKpEU4my1nEB30Zt0wyf/KovHutKZvOZ4DUhbm6SaGI9ggeFz1vm7Wv/iJv1cPuCJ5l7opkWnXaLHntd6rsYJ7jVhFLh70KKw67Id04J69W++y5YWRry2LVEuep+YyEvKy3n1jdzRnxlhh/xr8ynsUI70ayLJ724VpIIis4n9kmpBTovE4CZloxef4OfU00h+NigdPfSnH8Q/LOPsBjiEz6It30gXiZJhz6nL0Z5qAkRZ1G9O7TSr8D80Efx+NS1xxh45zaUcrMizcfVjz3n2uu43dryNFehMat7pUBK/T3mmJC3ujHNB6ByuKNeIAFWwkO5nkgFv+Pvmnigc3dlawiwvdQTVZU8ZNSv9N4iIbtHMfG6AAu8Ix1+++UOcyHmZJElCbXaDOQcbFJGXHOa47vd/rz9K6uCNf9LJUYimFl11e5HHczFmnyv5lrM20GFMwHy27P+nahcQPBQERCNLx2SgE8FKLvPUgaFI9YLhlYjkCb8QPTlTvJR6FtIQOcuo5fa7TS7UA+DcKUx6I/YTTheGdnKovy3C/b0sR/jYMc2Lze8qx0kj1oclvTVfznPnUOO7hrvWEd4OZcTYuGxGdBTTtNj5h+PRLiotZ4hbGsI6aw4K4xYjp4dYjRykgu7SWaoR3f43fwMb66vpeK5eOgZiqFPtN02U3GO4fDBURKFwttgHcMPNofnlG24UDtHGAcXo94SDa9bTUg/DnJhJwZNDtVPy+HnsFq1440qmorMyMA3YMdjVjyIGnvpG54zqyCJts7DKWUE3xA7vUq9vc6sDSzGcHyw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d141b33-2800-4eb4-d0c4-08da2106cb74 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:43:49.4702 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tMZPvKfaPAYy5ef8ALqW65EXsCbLxOCcr9PVoIh/F1IroryXM5ZJd+r6R+0Q4TXogfm41jCuwzCH6Z6zgRhc6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In order to properly inform user about relationship between port and line card, introduce a driver API to set line card for a port. Use this information to extend port devlink netlink message by line card index and also include the line card index into phys_port_name and by that into a netdevice name. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- include/net/devlink.h | 3 +++ net/core/devlink.c | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index d8061a11fee6..2a2a2a0c93f7 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -136,6 +136,7 @@ struct devlink_port { struct mutex reporters_lock; /* Protects reporter_list */ struct devlink_rate *devlink_rate; + struct devlink_linecard *linecard; }; struct devlink_port_new_attrs { @@ -1571,6 +1572,8 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, int devlink_rate_leaf_create(struct devlink_port *port, void *priv); void devlink_rate_leaf_destroy(struct devlink_port *devlink_port); void devlink_rate_nodes_destroy(struct devlink *devlink); +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 aec0a517282c..5cc88490f18f 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -1243,6 +1243,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, 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; @@ -10105,6 +10109,21 @@ void devlink_rate_nodes_destroy(struct devlink *devlink) } EXPORT_SYMBOL_GPL(devlink_rate_nodes_destroy); +/** + * devlink_port_linecard_set - Link port with a linecard + * + * @devlink_port: devlink port + * @linecard: devlink linecard + */ +void devlink_port_linecard_set(struct devlink_port *devlink_port, + struct devlink_linecard *linecard) +{ + if (WARN_ON(devlink_port->devlink)) + 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) { @@ -10116,7 +10135,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, switch (attrs->flavour) { case DEVLINK_PORT_FLAVOUR_PHYSICAL: - n = snprintf(name, len, "p%u", attrs->phys.port_number); + if (devlink_port->linecard) + n = snprintf(name, len, "l%u", + devlink_port->linecard->index); + if (n < len) + n += snprintf(name + n, len - n, "p%u", + attrs->phys.port_number); if (n < len && attrs->split) n += snprintf(name + n, len - n, "s%u", attrs->phys.split_subport_number); From patchwork Mon Apr 18 06:42:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816336 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FECAC433FE for ; Mon, 18 Apr 2022 06:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236823AbiDRGqi (ORCPT ); Mon, 18 Apr 2022 02:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236571AbiDRGqf (ORCPT ); Mon, 18 Apr 2022 02:46:35 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2055.outbound.protection.outlook.com [40.107.101.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 998E219015 for ; Sun, 17 Apr 2022 23:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PDQkjWbZj8ljw7wVm4PJATas0J17qn2euSC8C0keEzF6I95ccroI22DL3TrscoZkVY1fQMEfAPsTR+9W3xyTxVE4RNelf7eshr2QnY2oqc1cmjqo/a0bSihYLin4tzB/DWaFWGS9MA7Hy4sp33YiHjlFq1PY8Da++XgxlhadculnhmPHHQ7P/YVXIZJBQvL0SQb2wR3H9OtPX5ELIpPcfjzJfMcpRVrdJiG9PgUkH8YkDtoJhE1v0fM6YlI4kVIsyiY4AAuxy1kmYCNVpVsomMR47t0amwfOrg0ojUpm5wSUG68c4HXJCU6v0Ezcyn5VOykqUnu5g/mdyktEO0pjBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YuiD8/n+sj6HvAxrCRzBcsetFw/v/cn0RuraUZEDX5E=; b=I2IOxJe28G+uAr51AccIZtnCPJROcSk7d1JrkGNrMlW+L6mRidwyqAn4t/M/KobTWMKCrmP1qke4RSQRYQTB7U+F7nPPNAcdaqBveXJDIgUdVNDAPS9Fjq56Upl2MHf/8GS9LIF45n6kWcMZbqBUe0kQIa7PbtqC6fNpcd6knsy+8yMA3r8Qg6fuVyDPPmrszcRT8501OOpyXRqKDH0nkNf4hbyvRype1JS3062ygF6MpZbJIhhPvWbIv4icCOnk9IRLFxwKrq5RvlClPBVVhIXdc0I0Od8H2uWupRqpXdMs0J2bQtbvnbZ1aMoADaoRNxt9cxvnAne9cpO38jPUXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YuiD8/n+sj6HvAxrCRzBcsetFw/v/cn0RuraUZEDX5E=; b=PC+LKIBcHB2DOn3IxfpainvoiP5OUhtR0k0X/XddfYltfXBeizdQhlCX4PBLU39n1hPTNavmCwlVY+N1XGbB1JlLyDd9PcI0c7s5FNsSaZ65oduyoa+q4YIUQPQop3ZBnlJtr2Q262KY1PXCZtG5TF0/lBLJlaMoallJAOUhBEL9KzQY1YliSPfqQHcP4n45XzGbTnjDfDqo/3nXP9rt8YAaHp1/Fkvowffkg7Cu2k2f6IsgwhF1F8vqMrZvgiomNSaJlkmeHSWMDYeDmbxlCFU7Wxra0DxuzAZ9KHxIEwXYYJYRa+VOvulaYws0aexYTn1tISDIs9tEt80gbwHohg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:43:54 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:43:54 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 05/17] mlxsw: spectrum: Allow lane to start from non-zero index Date: Mon, 18 Apr 2022 09:42:29 +0300 Message-Id: <20220418064241.2925668-6-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0256.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::9) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f7f0d3c-5fd8-4ecf-2b7e-08da2106ce40 X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1SAgXy19RKs+YQ/zZTdn3wBsfgxkDqiFlJFbDshT0f0dg/ISgW3EhRvHw5pukT+Es3/AzWjZzwKddZaNV+EEsjG4HDw807X5JjjcvMdoCZC5hyH32jijeqkX5ifmqrxPM+8iuf7k9rVWCk6Y8b2iwPI7eVmcimXpe9iNmWKSL5ssddu5TS3NH+z84L1ikDacpOSDHM4AZO20TWP5IEbh2Zta8wZyWBIry8iluietdO7dBlgUt7L5bj9ixN6WaX3RpmND+F/mo5omI0VpaEycwe3afrQ9T8y0vFAVjTJjTGu+51TFX3HDQN4wVBensYVpg9/4/ACqirw5ZdH40GGsE9FF1gd2Nv46OBNoWVTxHL4ZkL6YLcPcAcI+gSF8J3lzT00tZmaKrRS3uI02ANJQcOAkW/m3Ib4n3qb5fHFLXeCjROrr/30MLgs1ln0qhvpIXEas0hTR4YWf5Ksa8gbVdYV/e8GAlnlVWKepDeyFC8XqJCplRmGnmXwvy1vFOSseuEstEbSw7ncvHPprUQrf9JQc9J5UEq+5edQAB0lDuJ9fPMHyh251Q/x39AdEmRL8J4JDiTx8Lpn9Z4NNI6godtv4pZZX2CNhHV8B8kdhgb61SQC/1i3vlojdyvmQjx1Ka1R+VF1rtUd57beG4OLTXg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EIs/RWxQXWel/Ki2TF+YwsOVJ4CMvyyIudB67rvoGD5sQbl0p9FSu0EEzC3GBJ7QuMAF1FjDQHm5/G4uY+XANiDRfzgLSRatq+OsJwiJ2LgkphNU7IFuVDj0OHbzbekrYscu/AAP89Qq9BFgj5+1OVvcMNGvYSIA5W9gXl/1EPYWDOod4stkJ55+jOhmcUIf6VyQRvqEeeAIJjp655QoFWkJTgI5GpTbzqNnK7hfIvDsSrUCiRKAfPWav6jgjGaK6q8ojcLhcG4+1R164bSD0u5ccY5jjPGhTOq0MGMJPI0lpD89l1eqeXb9SFayzLxLaYI4mwZxIg8HSTHz2tKqyJHxdnwg2fW8OUHZwFtjHj9SkGiEsbw8KNq03uAFl2GoZomLJtjcBXIHu2uwWvEkLOmk6MXR6kjgvv+NBLg16h49CxcBMrilJsA4oUMPhVCqRKRSVEEaINn2ZjeLsScUvtmfkTBWJ8USS2Hdpsnw3k+ZxtY0PY8/pH3iZg1yYkrp74wD7dnBQqvLddyIevvXQBCLYjc9hPlF+Pr2l3c9vJ8gNj+h4KbZClayH7VLpA0pfyuosQZy5GKmI2KY6VmoCigGFj3BvKQJEbbxbCwgjMhgYcO805YsKd5MIx2UnKZRlTHIuH7Tq/BPGfaRWyDBG1N/W9YjmVTW/SyRj9OeAce0LXbDt8VvzFUkvMV3zyjpq57RnLb+V2S05nEWT3ysdlmdfyTgvmjYpE6MP9dOCoYGEzHpfVyUy86P2xY6SmiOkerdn3rR0HDn6HcTO0YgprUBi4G8ms63qiuSiBhiVKzU1FqHsVYfJ5tWDu6tg4Azf43/dTHjOcJGH9XUyAlSgdOdCMOzbxGuamdeKkuFRwEV4V902dU2jMOva4JFsDCFWDiIqHY1oWPJtFC7Enlrdk/XI0jKjzEVMC4ZZhHdr0lYfJ3rg72G/UOWgk6L9iRWiDP28RUsxZTPV0FoMuKE+o3Ha5wgRf6t9mOYSFoD0gR+dqrZUzWkSwitdqYiXy+iJ+nKwAmfx2UnQtTdoktWECUesrJ2kzLoR1axD3uZvF2hSCtgMzg+BQwJ2I5SxNXrKQAvrkODhqg8MECtIvpNYBJjTSkNKH2Vkk3N+28jZo0uoMWWlw6cR5nkArIlaHgLR5ZT+Lbx3FtjPL6bo17Jl0IXLsUOpHcItJ7XTLaKt4qb1sm0AK2Da1J/KG3oxqM7g7QtgGtyQMa/E9QRMLFTvgejXaihe2W0sDW1l2RCYNG0Db5i9H9eo7JAUeoarGCew9VR0KXIFDz8SgJK+7MOJR4ep5n/dp6/uxkUQtYio0PObcdLLQgKmjqtWL47QUUTncyxVFfhB9Jnt2L3lU/WpIgYldqaIC5p26LpUfQPBHOdbC0K5eZNUTAo1c6ZduL6h5dKfSuZQo/Asq0t6WfwDlJGPPizjupFDcx4w+B1JHYmHdSOPDcge6DsKAbMJMmrYCPkwt6IKK2PUj6Q/VDoX9lg0QbToGjEoxpXcwHx0vFthPausf7R88tFMAQpg58m3YSraABvlk8AFVAcI3WMyOCTUECf7Q9Z5UX0iisthJSeyAf5lvvPw7++Gl4LmR9sAy0i9gqmR5kuwS2VFXIT4x3pmY1o+iK98I9hJjfz6p6mQCvywwPiyElPiKHO6OC6b4TKYMIIWQf7pGXE4iuv+kAlrMy7pbjChFj68xwXqFAidjZeBWk9iUdcc20KuxuDN6pp/LAqBLaxaOUbYxZ+ug== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f7f0d3c-5fd8-4ecf-2b7e-08da2106ce40 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:43:54.1428 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 16b9IsOE1fQuGGYdypipnytGwmcDsL1h1aD8fbDOXD1Xkq1qHge7sCOH0zpey4O1RQXdcN0w9Nl71UwrvkJb1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko So far, the lane index always started from zero. That is not true for modular systems with gearbox-equipped linecards. Loose the check so the lanes can start from non-zero index. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 684910ca7cf4..120880fad7f8 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -486,6 +486,7 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, { char pmlp_pl[MLXSW_REG_PMLP_LEN]; bool separate_rxtx; + u8 first_lane; u8 module; u8 width; int err; @@ -498,6 +499,7 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0); width = mlxsw_reg_pmlp_width_get(pmlp_pl); separate_rxtx = mlxsw_reg_pmlp_rxtx_get(pmlp_pl); + first_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0); if (width && !is_power_of_2(width)) { dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: width value is not power of 2\n", @@ -518,7 +520,7 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, local_port); return -EINVAL; } - if (mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) != i) { + if (mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) != i + first_lane) { dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: TX and RX lane numbers are not sequential\n", local_port); return -EINVAL; From patchwork Mon Apr 18 06:42:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816337 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C04CC433EF for ; Mon, 18 Apr 2022 06:44:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236845AbiDRGqw (ORCPT ); Mon, 18 Apr 2022 02:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236822AbiDRGqj (ORCPT ); Mon, 18 Apr 2022 02:46:39 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2042.outbound.protection.outlook.com [40.107.101.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D18C018E3B for ; Sun, 17 Apr 2022 23:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oP6+SwCCY4o80M84Cq4nibX4d8+G/tO+JHFynsJJ8rLJhQ9SNLyfsXVH3/jnp3WepTH/yOUPuNa2EMF9AF64neJ4SHyBeCPo+4X7YfMMk46mInnp4boVaxP69aKl/XAsmnr6BOXmfAD4WZI2mXOMEIrOURl673sUrLwrLbrYi+KeSPNCxneui9LXFraJwDi2cUJqtTbEIZBc1L/edrNv4xXw3gNYP7boepivcdz+yCUrIrJXK/WC7rT4k22dIfB3ZsqChHmTgw7jctV4x0egK2m6vwdqHIzCU98JsM4WBem0BxxVQwjzI3A1YoQXXWgEfUyBPzzCnOJxdL3XrDQQLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SI+utdoAUEY1Q72DOJET3tiamn/+EP6TO4kXerbMMyE=; b=DVsuzBCaHsdp25Vi97LTX/+z9zG4KZzG4zAtFGcMf5pTPPd0bnAv8qUqXUtUKpTaxO+oBA7CY05fRkhWUR97pePnctMjnfHiq43QR1CMKJc51vXSPivOSTze/kSltCrkr4AAzsZDkSqRJxEym48cuoS1f6bZFvlqBbofV2CyWndNXTgR3neh8ls2z55xybbS+DauRR1uoKLUlRvZrdh+KbjGq376YwS1/6Y1Dx4FU+R9WJDRxJjj4EaDpKDfQ4ESlKGXldsnWbLUSbpq4THSTldk0pMmqZvtq+r92hc83RtZCfmzemQDNuLLjcPaPUx3Opbr4cN2c6cDlwkn1cAyNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SI+utdoAUEY1Q72DOJET3tiamn/+EP6TO4kXerbMMyE=; b=HY8ll6P/KRMUMQ9LoGAIvOU67auT9esMHptWTvKF5fgwXSPYKayhip8DHsEoy2mm3AfxEKkyEuAAVceVrzc2zFm62y9ZTrXHzQbREiqnqQqygFHlUo+AMl6kk5JQR36GLjftxGnXZHuCMxCfeMzGvqfR0VdIGsUPuXbyu6d3qlMzhXF3fYQdxpkmtX+ZwKP2oto5siu1I64toPhCNnexqb7HpKv+ZpvqQh9W6ZuIlLIAI4xpmf7taRnaxLI09Bmpq07+48XS/lNZPCCEytgNfnLUw+6beZmbyaYiN2WYtzbo2pJ7Px4DayTiR+UFvZbLxYnKNIRQEMmPa8MUzFYfjQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:00 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:00 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 06/17] mlxsw: spectrum: Allocate port mapping array of structs instead of pointers Date: Mon, 18 Apr 2022 09:42:30 +0300 Message-Id: <20220418064241.2925668-7-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0520.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:272::16) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8dec435f-190d-4757-943e-08da2106d1f5 X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R8iSXjLdAwBj6VN3QIvTffFNUpifWfBJK6nBpt9QTIaNa4MBtq3Iryq2eU3Krk0TIhm6QvhMGjfznoum2lYODZc82921UQre4DkKUfeiRPBcQ3+1Xa1LkoEXm/ju2M2shZR7IyY6X53Bwqz2S7U+dWPGS9FGZargg8tZu28elAolOMq3eotmXesbHunxikqiTASNn2XALktiZyrPyFGbShwRjHpub6/MKN9B8+FwImujEK1rXgZVmg3miedILBilDpO8OsYZVV/OvUAZw0HNMtsOvWadVxJUzRCmsOqC7YXRSzwUx4Pv5tTD3zBOSHTT5GxbSuYZ/zgq1d68dedhtpMiffg+QFvXY7Q8vuY2W5OksWsMNS3PnRP8cJhFARR+uqQfnCp0Ow8p5jFXXrH4us1drjDboRE5QMspMfub3neFwyZj/ZFqAR1rSvhK4cCbnJWsCmCwnHxqPO5glaBgRzMuOhzzymizespUTis7XKngxIi8dqWqIM0oQVcgn4H9qcNCz7vdcJl4fnbmTs9c1JvjATN4LnLekVtt1yN/IsTjX7f44i2XJgeE78IHOi7VjdDvA5VR9WwHVMKyVJCI/+RlAiyW6udMKQ9lZrd5OvWmFsF01WuErrS9/Oez/q6BKwFrWCbyyna7FV2zIXOqLg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uW9Z3x8Sdkg5Iz5+uh3mIM6ts6j5HSkWSbJxzUHzsKVxTUUVXF9EN/w5tt2Jn3eUyhjLJfGcfh6PqgZD/PDeiQORrOooQeulbxLBiQLp1gk9zkGtj4F3Cn+27gnaCe+bx3Ru3F6yY0Q2VCwPDj8BVCmZ+nvB5q7Nf7nRI1ZdQAsLLP8hqf/fqEcPQQeyNfcegQr+UKamPaKpd8AfU+DmTkJR+OoKoojl8k5DTBXal2IjOYGrKrjmuUp8L5YnnUnfvMrKfBxWKFtJtr+SEajo2tpRxIVYQ5ejRxNm9TmQlmBF8gdANcGBV+LrMUOBvls2n4LVlH1Kh6JcapQI1Paj9w9N1FIL2DPoPEjznbwe73mhdLQ6eta7YWYykPlt5BhLNXZEAiV3F0QLGEo864LGPqvtncyYnZBkzpri0ESXXQCoMukpo370JH+LPDKx1Lcbfh78HdtI+kh8Sy2cFvxEGalrjCcl4UjACnQmxKZu2GP4GCxYghpaTj7jnH5Cpz6vDao6LFMK180OdGQM1BGqnzqIKmpgYMRaQaiQKKy7lxgTErmDFmAccxSxWFicu3tBdrL9jIF1qtwr79pR/9Lds5FvSyqDBWYCmmJBjh38AAbTymTlxNyZRUE/OAYjkObKMD2kkA8VzkkqBRs+LJoO/Rvm6VKGbblBZEMTuRWyc/yrAKbrZL/xIgl/eYVnFMF41rYpjlDDIX77hpT0NVexiEqiX0sy3yZbuP5BVD/dBCVr+nKFnZ3LVIXltnhBuTHVFQLNIewAYU+qdr2Wym9FqfG8pq9l0iHP8rxfOe6kMDj9D00AclsckrcnTD3duaAhMBrLTYxDjsf+aMvrB4EZxgPvzorjd0g2GbOA56IYdpRktkajvhT0MB78Owkkt0Mpty91uWg5bg7KQi2KgpcKM9jo3W2E6NVm481QTqSuS1A8m+y5N59CSGqPDYcs6VSmBH57wfdxIX0kdXm0/A1OeypzzEylLLBkBXrXC8QRaquCiRqB/wnfG3061Wuh4QQ4bhiS/x0prwZj0y3ny5LLkxJUbG8/3vAPOE6ADH66UxJb7acKOQbw8h302Yd9CTwOEI/mmEr31dvW5xRM4+tgQQoHcxlc+z/OLjFNvlM8i9wteVSURtd61FtC1BBNxX5ERdEbkzchEHJ6mPC7GhmNq4KMEDZRh2O6eO8w/owVLjV1oDFakI6A8v2W3onmk+v5n0zibrNBPPGSyjoqmF3uVGal3n2XWLbIkQqyFY1J9dJpkm23HVYS6xVouMnr/B3EK8KK2nQ2n/bVlmOLmPupum1+dNbFJQXgE8jV3jysphUyRCJb11QWuQAADuzUaYIQQbsrJyhPFjtpP3DSLqSEBulwxylpSsFWJ+NNBvZtF4/lxDI0qw6B0POX9jIIyyjhu3YOisChJUxSUFldaeMTKRmE8DVqjNNzhmoNdnbtg3pRn8CcuFRsLPUEMcea0v4duE6QE3/mkEpIMiGFHdyHBR3Z5w2zukt81tggbwmcuNlmG9Ka7HWqIswYVCIRoBHIT0uzOR77q5bh52huYj4q576m6fNqLuq3lAkwZmTeetGIPVBB+VkcZjC0m1JSRpCaaiYC+KEBnVEW9DoNib4sDj0S0KPTucJhdkWx3+WFLhvjcqU8wWw7hMl9FhD7aqlMqniKjfHw/KEUzyjR8vLI8zsUxyjJSvBgSSJAtfaUDHBkMoUI0WVB+3GTema2wksukNtDxWBzDYTrStzK29jpOg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dec435f-190d-4757-943e-08da2106d1f5 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:00.3805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2CSSrFcZiAvmUSxCIQ7ef5OxOlsEqhKzeflb4mRLlKePt8ZV/pcoinoy7xSmzCjFoNlCMT3fNhnTJhc4z1Btqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Instead of array of pointers to port mapping structures, allocate the array of structures directly. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 32 +++++-------------- .../net/ethernet/mellanox/mlxsw/spectrum.h | 2 +- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 120880fad7f8..55b97ccafd45 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -1891,8 +1891,8 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) goto err_cpu_port_create; for (i = 1; i < max_ports; i++) { - port_mapping = mlxsw_sp->port_mapping[i]; - if (!port_mapping) + port_mapping = &mlxsw_sp->port_mapping[i]; + if (!port_mapping->width) continue; err = mlxsw_sp_port_create(mlxsw_sp, i, false, port_mapping); if (err) @@ -1914,12 +1914,12 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_port_module_info_init(struct mlxsw_sp *mlxsw_sp) { unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); - struct mlxsw_sp_port_mapping port_mapping; + struct mlxsw_sp_port_mapping *port_mapping; int i; int err; mlxsw_sp->port_mapping = kcalloc(max_ports, - sizeof(struct mlxsw_sp_port_mapping *), + sizeof(struct mlxsw_sp_port_mapping), GFP_KERNEL); if (!mlxsw_sp->port_mapping) return -ENOMEM; @@ -1928,36 +1928,20 @@ static int mlxsw_sp_port_module_info_init(struct mlxsw_sp *mlxsw_sp) if (mlxsw_core_port_is_xm(mlxsw_sp->core, i)) continue; - err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, &port_mapping); + port_mapping = &mlxsw_sp->port_mapping[i]; + err = mlxsw_sp_port_module_info_get(mlxsw_sp, i, port_mapping); if (err) goto err_port_module_info_get; - if (!port_mapping.width) - continue; - - mlxsw_sp->port_mapping[i] = kmemdup(&port_mapping, - sizeof(port_mapping), - GFP_KERNEL); - if (!mlxsw_sp->port_mapping[i]) { - err = -ENOMEM; - goto err_port_module_info_dup; - } } return 0; err_port_module_info_get: -err_port_module_info_dup: - for (i--; i >= 1; i--) - kfree(mlxsw_sp->port_mapping[i]); kfree(mlxsw_sp->port_mapping); return err; } static void mlxsw_sp_port_module_info_fini(struct mlxsw_sp *mlxsw_sp) { - int i; - - for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++) - kfree(mlxsw_sp->port_mapping[i]); kfree(mlxsw_sp->port_mapping); } @@ -2007,8 +1991,8 @@ static void mlxsw_sp_port_unsplit_create(struct mlxsw_sp *mlxsw_sp, for (i = 0; i < count; i++) { u16 local_port = mlxsw_reg_pmtdb_port_num_get(pmtdb_pl, i); - port_mapping = mlxsw_sp->port_mapping[local_port]; - if (!port_mapping || !mlxsw_sp_local_port_valid(local_port)) + port_mapping = &mlxsw_sp->port_mapping[local_port]; + if (!port_mapping->width || !mlxsw_sp_local_port_valid(local_port)) continue; mlxsw_sp_port_create(mlxsw_sp, local_port, false, port_mapping); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 20588e699588..68f71e77b5c7 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -164,7 +164,7 @@ struct mlxsw_sp { unsigned char base_mac[ETH_ALEN]; const unsigned char *mac_mask; struct mlxsw_sp_upper *lags; - struct mlxsw_sp_port_mapping **port_mapping; + struct mlxsw_sp_port_mapping *port_mapping; struct rhashtable sample_trigger_ht; struct mlxsw_sp_sb *sb; struct mlxsw_sp_bridge *bridge; From patchwork Mon Apr 18 06:42:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816338 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26A81C433F5 for ; Mon, 18 Apr 2022 06:44:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236858AbiDRGrE (ORCPT ); Mon, 18 Apr 2022 02:47:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236844AbiDRGqw (ORCPT ); Mon, 18 Apr 2022 02:46:52 -0400 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2045.outbound.protection.outlook.com [40.107.101.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8A619015 for ; Sun, 17 Apr 2022 23:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j5wgNE64YDAOlE8A7goQVl6ibR102lirtqjM0m/SCRraWzCfVTvFKwsw+RRvE44JbxWSP9ak4V48KvKhGEA1TC553A4T1hBw94PZWB/jUidpez2CMJv7OJ1lEOdKP6XzsnRxLQuF6yKnYijiuMLSyfNauENp5w1V3oNPynK53SRT0ETVi6aX9V5ewk7urGCtxpOjPzA3sFpRQhUkoZuLdqlLr2BnUaSHZW6eYJCdYyGIK88bM59qPz0pNySWbOrEhcfJa8IS4UwMbqI2rIsmQpdX7umVB5Ly4MwBfoknQV9y2sV4u5z0Tuht7Z9L5NNF5c3zKtIMlkDMVAL5Wt73sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mNM9fvn4FehJaHNRhByhn9HMvi1orRPrHHkbxXkl9/k=; b=ag4HyGHz94XJLiXp71rpi6m4g2VKDgH4K5R6fsAWCxkaRx36u8Z+1BSYGDp4iaSNkp7QmarHJLgkVZl5n0pNM5fYoxaDDLJMkuMrShvsu6I2smj9qfVwTGJm4txyXe6aYSPzQxY72LwQiPOLeQBvxYdEBxHClhlbVLYOKQcPqSnxMxwo56kwVGxfUY8xbrUB7NskuJhY0DJIb9XlF5cPv4f6T3SQat5Ne88+59QxZ15Aj0XzXMWyvt86pu2/QKgMd6FPAH2e67KQX8H5rNsMIB00gHVBzlLFSiXpNN6hxVEjEYtEqeXOUl+iUKFZKElzcLNfn2ye0N6TmNN4xbB2YQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mNM9fvn4FehJaHNRhByhn9HMvi1orRPrHHkbxXkl9/k=; b=mCOfZPdyYpwoNwJD7XxM9ce5yjIu5IX2ekXiQp7v2McYdM1MOCR7VihIgI2BB8yYuP06WAYUGvHKV8BLa9IJLhfsId+RjMqsrDlMFWLCi8+iQy0pW/8NLRYWP+DfZszcIC/081+B4vCkXQI5lpO9u5m1arAwXR0tzZ2oCqIbGVmo68wefF86TQqtjW7r/26ozQTr2GmWhNgS4+O6w+LSo+P1h4GEtN2SQAYplq70JTFkuAO20VVr2Fp3ckzsaHKso680YsqduhwfBHYfsa7JZdHH+fPbr32KkHG4PcLC0tyUl4ae4nA9uF/YZdi4C6byz305fVTmIZBvsuyz33p+7A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:06 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:06 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 07/17] mlxsw: reg: Add Ports Mapping Event Configuration Register Date: Mon, 18 Apr 2022 09:42:31 +0300 Message-Id: <20220418064241.2925668-8-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0196.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a4::21) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25814b01-f392-41a2-06a9-08da2106d55a X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HyxCgL+hO7SN0Tw2LQfo+X3AvUIe+7iHzxSkyFwxy4DwnyaZwxh9Xm9LQcAZ2xpSmq5L/EdtzJqzh3RnrKk2vOjjUbBfkiXVL2qSptiIqf/sq8lVNe0c7pqRyeX/hXja00cjHlJz0Ado5jVxHHrQFDigl8BC6rK+J2FkL8yyjZEvyew2S3ehIt03Ud+jUgxy6FgFLnaPOP/BM48aGu96y/6oawvL0YxhczbjtnZdHK9fj2MtNcu0MsJa/FILRBwPa9MlyXmuB0d42T6pAk7XWlmjR4GttTIm3gk72JBs//GE9gn44d/NfEaDIntuQueSZ8gFFQBsg18iKX654Bk02Dn/5p4a8xr23bLi0U1igkBMduDXWY/2tNcHf951S070GpOrQMj1CnX5VZ/vKMWm+hk522W/0Il9EGCNgbsIDvUc7vspehik7jmEKSmkXsuV+lN45DKR3hVSlQ/qZtYtkfQxJ3OE9XKKVGj+N3CTuJJQHJ4hTt/e4syn6jjSd61GPLWtIC1heA2TW/mStfhdu1GoDAbqdvE9uB2qmXSLnYkyvWdPYLSljHd1K6wt9SFdD6SPwp5vpud3jNxipDRhVavMK3nTkk4h0xN76sw/qSLDEw8yVSxYyZI36ECitkptg9ROdRuDmX2vle//W6WfEA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(316002)(6486002)(508600001)(1076003)(2906002)(6512007)(6506007)(86362001)(6666004)(36756003)(186003)(26005)(83380400001)(66946007)(38100700002)(5660300002)(66556008)(66476007)(107886003)(2616005)(4326008)(8676002)(6916009)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5MkJC8iM2K6isAuEu21TmKyDZc6lgCyAwlnP9gUHdAC4hAABWU300SbukaxumX/AZatPESbIfD6+6p8Fbyf3WeWLGNu18hVr7Q8fJC32Kvqp6KHg8lX63i8YJVL7O5Ndv3Nm3iBHSElc80tew7IWipPHp6KIo6mGr5+5GUOMMtICc0Y22/tUFSOJtf+QOp1f2P5sd/i0OcSXE813Fr4JmtbqkWlhn56Lm4Vi9DdxMUFInwOtiWyt+02en5UH6g6hUufp61UkA6jJuSZNFFbVw129Xb8js/kpW1eGFdFVoK7rQH3pvh3WeDaNZQDG8OkohD6yVm6hRPf5zg4z+4QY8S1fZ9DLcKiSIwiF6hrsov506fAXPRn4FGVLG0tnbj7KKs0SEzWYWNx+7Msz3omOhKVo6YFOwtkgexP9vWVBnXlgNmvIKGpxv6QWch8/oX/zqpF+iR9/7/RBXbJMNTxd2/WrnFt9bDwqJxZiloP+PZuwZkeNpeVB9T98z+B1xew2bGgQMtnWIE1PDCXjYCjQ4egCvAZKD6ZAWDouGcAt8KF0TU13WtIxa9mOKr7RWDurOg+cxUvHP0xzwoOWgMFxUgHmS4yLuazlb79gChzpjdQqB5TonxuU1u3Oah0wNA62zUBI+XKL8uqTzFVebJ4T/WkLLapYkFupGkksLtpVPs70CsqiFJSzsj3GWQOzlOvVIc7KkxJtovdNmYr6DTBLIgbSKeaVslp2Ig7iG66ZJ0FaLxqOfxRdmqA9eLxQkGKqFx47/rOy1f6UZlkeg8R8YVv96aN7LrIS8AtJBvnUcm1Tk7qi2VHEA3OAjP8TSfguvFM5ZofQ05RI5QJpprdmwGDX1182YOGP04P3x3OylLNBT2dgWywtahCh9OmZJIdJ3P/ZZ1ADL4zDrE5BNjg44yrvsQ/b0PwKBWPZaEybk50mNvLXwgNjklOyQAEpl0b0085JiSdCeDeFHM7NSGoLEokayZrgXtZDvjkSC2GyuyidDEY8ho27x9ZxbaSsoQnESlvRkjM+KKVq4O0Ey3CbsFzgVCRUMPA8nU14i/OKbJ15TjYzr9CtVUmR26h8ljrWhUCgHCbzlRXVsC6Uf7jSxixoUiorYz6R+/CuZtp9VVEtpHbK+/l2Lr+fSLkb2Uow7xunI/YXK8xQ+AzZ3vyN3v3x9YFYeMISaKLZ8jL6NY7fXNj+f/Vp6Nawoex65xdOjY2TrwBYmCjpKDCh9um3sFla+qh7etjL4CxDYxNxJCvUZZ8wMrV7dPiAzWRuBmzFbnDfCJH4SOsEkcvqVTQhPC4y0Da8XRnQmVJuXS+TGIlMmHn2CZFJqisICImnnZKq/Eyo1EW8ojkLPeVILtNRmZ4fdf3beG2rsx2CbEyAGeM2hiD7h0HiBtd6pGftBi7ki7mBdbNi+plIzN4hiubFLUuZzR91YNLnlTFN1LEqrHhD0I+LvHUoTqXw/Syj6qlND2RLemCdr0CcFJYxk4BRXyokdMYkel7P9+8c5lvUhAlCC7INku4RJkzyjXKRkujkHXMuhKCj0qxCT1RMIUefsQ4Xj0CQ6tXtAFFmIPLEbsoWm0MWg69mntVsh1ZNjAi1TVLqJRn1s8ts4ZwwYtNQzP+JRfVzizxXqEvXZL3WNSNhhxSatZ1xQYmqirHjLEDS5wxBq3cJt6Fh7/hvawkp7eElX2K3tCygNKlTvPfBH0nWf8EW3L5DtXly9eLN5N7TthmESpBHlwbtRlT+Yyes8w== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25814b01-f392-41a2-06a9-08da2106d55a X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:06.0563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i1wIB2IMdypraX1Ro4q5B20wV8YDezlr9Ogvh3pCdBg18oftVYqcT3QOODOyAwix9fwWvIWmaTpY1ef3vPZ8Jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The PMECR register is used to enable/disable event triggering in case of local port mapping change. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index b8a236872fea..7b51a63d23c1 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -5875,6 +5875,69 @@ static inline void mlxsw_reg_pmtdb_pack(char *payload, u8 slot_index, u8 module, mlxsw_reg_pmtdb_num_ports_set(payload, num_ports); } +/* PMECR - Ports Mapping Event Configuration Register + * -------------------------------------------------- + * The PMECR register is used to enable/disable event triggering + * in case of local port mapping change. + */ +#define MLXSW_REG_PMECR_ID 0x501B +#define MLXSW_REG_PMECR_LEN 0x20 + +MLXSW_REG_DEFINE(pmecr, MLXSW_REG_PMECR_ID, MLXSW_REG_PMECR_LEN); + +/* reg_pmecr_local_port + * Local port number. + * Access: Index + */ +MLXSW_ITEM32_LP(reg, pmecr, 0x00, 16, 0x00, 12); + +/* reg_pmecr_ee + * Event update enable. If this bit is set, event generation will be updated + * based on the e field. Only relevant on Set operations. + * Access: WO + */ +MLXSW_ITEM32(reg, pmecr, ee, 0x04, 30, 1); + +/* reg_pmecr_eswi + * Software ignore enable bit. If this bit is set, the value of swi is used. + * If this bit is clear, the value of swi is ignored. + * Only relevant on Set operations. + * Access: WO + */ +MLXSW_ITEM32(reg, pmecr, eswi, 0x04, 24, 1); + +/* reg_pmecr_swi + * Software ignore. If this bit is set, the device shouldn't generate events + * in case of PMLP SET operation but only upon self local port mapping change + * (if applicable according to e configuration). This is supplementary + * configuration on top of e value. + * Access: RW + */ +MLXSW_ITEM32(reg, pmecr, swi, 0x04, 8, 1); + +enum mlxsw_reg_pmecr_e { + MLXSW_REG_PMECR_E_DO_NOT_GENERATE_EVENT, + MLXSW_REG_PMECR_E_GENERATE_EVENT, + MLXSW_REG_PMECR_E_GENERATE_SINGLE_EVENT, +}; + +/* reg_pmecr_e + * Event generation on local port mapping change. + * Access: RW + */ +MLXSW_ITEM32(reg, pmecr, e, 0x04, 0, 2); + +static inline void mlxsw_reg_pmecr_pack(char *payload, u16 local_port, + enum mlxsw_reg_pmecr_e e) +{ + MLXSW_REG_ZERO(pmecr, payload); + mlxsw_reg_pmecr_local_port_set(payload, local_port); + mlxsw_reg_pmecr_e_set(payload, e); + mlxsw_reg_pmecr_ee_set(payload, true); + mlxsw_reg_pmecr_swi_set(payload, true); + mlxsw_reg_pmecr_eswi_set(payload, true); +} + /* PMPE - Port Module Plug/Unplug Event Register * --------------------------------------------- * This register reports any operational status change of a module. @@ -12678,6 +12741,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { MLXSW_REG(pmaos), MLXSW_REG(pplr), MLXSW_REG(pmtdb), + MLXSW_REG(pmecr), MLXSW_REG(pmpe), MLXSW_REG(pddr), MLXSW_REG(pmmp), From patchwork Mon Apr 18 06:42:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816340 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5755C433EF for ; Mon, 18 Apr 2022 06:44:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236826AbiDRGrG (ORCPT ); Mon, 18 Apr 2022 02:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236850AbiDRGqx (ORCPT ); Mon, 18 Apr 2022 02:46:53 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2044.outbound.protection.outlook.com [40.107.100.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57CB613DF4 for ; Sun, 17 Apr 2022 23:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pgmbbop3Jfbw1ym1HnEsOIP/5T8/jiv3Mf4AxGEk2yp4VcoDdUy+1bFbXuTx+n8YZV2fZR/huzJntiYwolM8GF5RzCym1w9EKeSypNnW+soi9NqD8bIyDcFqTsaxRJX2tnryh/KXquxbRJ3KxBs/lMm4WmRNMcFX2mDgP7tbdZoJmWWV/G9f1I4wOFHYTczMAcu1dBvfKJ3p9RPdgtcO5nLlS3Fqtp6j+tFOEU8A97/8KW0REVMYoaRGgTlGPS+Kl01H+Qct41iZVE+aJDL9zS3OSGdNaRpY/0cQ/MK0yVgR706NgpbQUuSHFt/YTEelPsfLVWMCX8peqzE86TT6vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DO/05PdJTmCA28Zrr9BHcfQha4/XLIGxx4HOlw1IE/o=; b=HStDZugfmcuVW1IUE1IBP/xuSI/YDR8QVIprYkXPWInLixgMRlmCGNNd38jeiAveA1M7vvz8VovBu7wcTKZ++evoEYrppevKYweqPV2upwqwBh2eT0LvR3ci/20oNyKcsSAsI6sZoEVsQvl1TjKjDPzumhhkCi7sSzm/Pf4OaHTIacqF8bQuh00zB+JdvHwuV0DPxjhxZcZ/Z1dxZxycxQwEQVz6dDuTZz3FDzaqmvjKk43k0ZXaLT+7ov0rGZWcn07Fn3q6RV41HWG7uAPXVoqCt/QGiJi6CHdEGis/DDxcwCVGP24MQ08DAkO8dCCHk+C56gT+5hbgTWo2O5FILA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DO/05PdJTmCA28Zrr9BHcfQha4/XLIGxx4HOlw1IE/o=; b=suqBU8Ka6Czll5fbmI89d4Ai0zHahDheajyLd8JBj0jl1TaBCPcXWMwPwambkSs7whjD5zmesqm3bz5T8yrCJ6V/XZWUvKfAeQwdB1AYsLPMbrolAgEERKzQV3xdG8JFFgJO1BWEnsGoAXa3f8+LOzXeHJF8L4mZ3idm6PlI+kG4bCCLokeMJORJuEGy0xqSYhHbPl1w4bPs2mcvqKWRowWuezdHmYFE6HvXZphe9bbRa0TbUf+eHCIl8aaD5+kclmwK4YCgS3l6Mds4lxMsQskT1Pi7PZXZuPK1gC+447AZi5s9F1kArb1eeUzXffuT7SJCbyIXozd/UOPxBE0OOQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:11 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:11 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 08/17] mlxsw: Narrow the critical section of devl_lock during ports creation/removal Date: Mon, 18 Apr 2022 09:42:32 +0300 Message-Id: <20220418064241.2925668-9-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0061.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:153::12) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bc57eaca-ab6f-48f4-1fe9-08da2106d861 X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P+nqn1wxJ4/XkjUnojpF8byKI54vefb6AR8d3eTqVDjpeUDRwSvIv6r06pu4GcHBSEmh+CfkbEpxdOCgvHPiRHZkW2v823M5Pm+V0mwCcDUXdpd2pZ/INCmZuNzZwgGRucspEyc+16+TvbOccBl7PjGvdEU5Y0ajprhii+Rkgzgt8lu9ZiM1C3Opgi/5WHD/xC9RiKEZD9Qep6DjtRmdmGYvQ2HpXnWrZJDfM/WjwNgAtC1k8VQ5pFF7+NKiQMVdB/wqdkqs/h4QMSxTiw+pFRcdQWKU+xe673GIhgk1/QICLzZ9RqsBaQMGzr/YSH13VjLOLOEAQ8qlrtQoKoLPEwgB0wLTbZNRZz5lFkwVCL9cfTLKvblfy9XtMpwU3dVwqxohHuW3qTbvd4HdFPKXL+PPhCfJYWfv1lBF5HyXwxrx9w7OYoDtE4huBAgjEu+0QBZLbr2SiqBsPPWNFSAvmEeCXi+8GZa53KwK0RfEnp+QDWCCacRLbyWg8wSxLcmEuqvB5SWd6cjZ7a6x6XYzzRRhz/Zo2jTvBgD5CtFcTvYJNpG6WPw7ux817Gh3t3CaxosvDUY2CSzNYWDW//rnE1bC3/AcR335FACf1yhbbIej3tacLX43QN/ce3XnV5+6UaPOt1IFjNwRQsYIW8lNmA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Bfz3HD1QEdF0KFjLjbLxQ2cvzNEOdqZ75xAUXx3X4Y/qWOd4SvtSydUw9q7CEcLQFFPSu2fBRu3aqB40pBfau8kPH41mgMmMIcudPX4XknAMXwl8S5J26EJCfJpcIAKNzfohYhHnd7S5Z/Tt2XGY4yxV/Of2jLnL/KTyHGKjbhERn29gAKEuA3OXTcFw2qJwWbLDVxOB0AJLc3YzR3RuMEqcF+xOxXcv8ngUoBZG+MXi1rEmoIHQarG0A7S3ITPdabeWyPF1IYLQdSAPW1LHqn/JLm4o1YLISrieEHMl4XIRfnw0wAQXW0kr01gVbJhegD7S3pNx5ERDCMRfA7KFwJ2j5VIaq8mfOMMAYoI4V/Ol9iPvGTfOcbCgqtv4nyQXYVLdUcOAZ9VYQDepiqlxnSjah5KOOM9Z60G0Jfh57HvLKLH0oSUh2W5BIdXQIl+oYtVEHUBdhCaYY8swnMlqBis1PkGhHDf3WfnrCeeT/4bHkE/84A3KH95wn/7wLmU3WLGPIldb5j9TaJVDdQDLD9T01iDRHjoUmpA4UOr89G1IPwUb4CQojRHOp9PYy2v7Gb7mzt3CcToXB/l7SMdQ1i89JBc9B1qghuRDLY+PYWkbdAoyGAYKZxe/3UvgvJJJvbpcyLsrKdpk34vl0bVq3KIgH9bU1DGy8ZjjwqRtDGsTUXLDDaA8aAHE2W80HshjYAIDqagXOc6cKkvxWGgqiKNYV1EfemOdlOXAbKhGcTVBlIvl281Jm+8ooJtKJkFVs2w0y7Y9h1je5BGzDP+kwFC0fUqo3/bMXE1VYlKT4uiFMiz7Oo0QWLMypv1PTRAtgvwxt9540IQEJ6sHzt9VHP0r41uL7Fl/I24kURHDvcaicRafhNSDdP8tWz1GTRuDH0zPzGDmoxO/kTSyHxhIJz6w95Feab2MAG86aCjyoA+R/JZV8pvI45uJxCP9l0fi6rG8WgRTIgZHYG+SfLPgRtqq9QzE1o+7Jm3F/iCnjELt5ttGHYnzqXcyT8RZia2IJyjUI8GhApmEXRBXhMZ1tyBwagdAA23MwurVw05+ez+BDSOHmMQcNvSbN88qTjltaeaD4+kjU8VS3YceCHXHj212ArlfuylE+MpL/Evth6r8Y9T2Bml4g3p3DveJgU6xgYxuD6tyCxhi1wwddmNdrBYDkd7nZ7C98m1DOh7tk445PZ9BlvxT/EuTjzviANItObaDH25DYoZouN/1zjk6vXLgJqbAVhZQeYYhaGVudAbx3tPlpP/waEBBjqW5Zd5uuRnE0aRCrEIY14Zed6eabPXvNKz1rObOvBMHcC+0MXdncvSclrNC96LMRr/dzWECkGa912+rXBSAKUSQQz9lRiBgy2j2UvekcJ+VngSu/Qa5EXc+eSOlYqlrLOJ2e+jBEglRljeTdzz8R90Z8aZenuNOT+jNS9yr7mpgEF+pPcIOrKHcC+GSOmYEhN/PYtG5YZ+nHXK0gw3ecW1cI0nTUj7HWD6Sk0T3/C9MyjhC+LH8626HX2XPy7hOq13z1NCSysQq6x/TWgevwLjppRcTg7JfXTaoy789kHf2QqZirdbP9IBMR2K3iwHUDH34wpfTkNV9JsVkWKmFvTyMp2+5/asNNOHTqODo2nmB+MKdKH9uqQMP32QnJAu9amnUaDvHPUca5fJTWHk9ao+EaJACPfQxuLdW3qGi27P0p2hal9laWbohBCByePVhFIa3dMlnqgT4RwXuvDtgmPp6rdHsiQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc57eaca-ab6f-48f4-1fe9-08da2106d861 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:11.2454 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UxzKlPsm/Ac0VXBW9WMSndiaXELmM4o5IdN+GgtM7rbLGvk1HTOqpcq9HnxMBVBen/CgsDzw9auClPxohyZh4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko No need to hold the lock for alloc and freecpu. So narrow the critical section. Follow-up patch is going to benefit from this by adding more code to the functions which will be out of the critical as well. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/minimal.c | 13 +++++++------ drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c index eb906b73b4e2..ee1cb1b81669 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c @@ -328,6 +328,7 @@ static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module) static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) { unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); + struct devlink *devlink = priv_to_devlink(mlxsw_m->core); u8 last_module = max_ports; int i; int err; @@ -356,6 +357,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) } /* Create port objects for each valid entry */ + devl_lock(devlink); for (i = 0; i < mlxsw_m->max_ports; i++) { if (mlxsw_m->module_to_port[i] > 0 && !mlxsw_core_port_is_xm(mlxsw_m->core, i)) { @@ -366,6 +368,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) goto err_module_to_port_create; } } + devl_unlock(devlink); return 0; @@ -375,6 +378,7 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) mlxsw_m_port_remove(mlxsw_m, mlxsw_m->module_to_port[i]); } + devl_unlock(devlink); i = max_ports; err_module_to_port_map: for (i--; i > 0; i--) @@ -387,8 +391,10 @@ static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m) { + struct devlink *devlink = priv_to_devlink(mlxsw_m->core); int i; + devl_lock(devlink); for (i = 0; i < mlxsw_m->max_ports; i++) { if (mlxsw_m->module_to_port[i] > 0) { mlxsw_m_port_remove(mlxsw_m, @@ -396,6 +402,7 @@ static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m) mlxsw_m_port_module_unmap(mlxsw_m, i); } } + devl_unlock(devlink); kfree(mlxsw_m->module_to_port); kfree(mlxsw_m->ports); @@ -424,7 +431,6 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, struct netlink_ext_ack *extack) { struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); - struct devlink *devlink = priv_to_devlink(mlxsw_core); int err; mlxsw_m->core = mlxsw_core; @@ -440,9 +446,7 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, return err; } - devl_lock(devlink); err = mlxsw_m_ports_create(mlxsw_m); - devl_unlock(devlink); if (err) { dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n"); return err; @@ -454,11 +458,8 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core, static void mlxsw_m_fini(struct mlxsw_core *mlxsw_core) { struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); - struct devlink *devlink = priv_to_devlink(mlxsw_core); - devl_lock(devlink); mlxsw_m_ports_remove(mlxsw_m); - devl_unlock(devlink); } static const struct mlxsw_config_profile mlxsw_m_config_profile; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 55b97ccafd45..c26c160744d0 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -1863,12 +1863,15 @@ static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u16 local_port) static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp) { + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); int i; + devl_lock(devlink); for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++) if (mlxsw_sp_port_created(mlxsw_sp, i)) mlxsw_sp_port_remove(mlxsw_sp, i); mlxsw_sp_cpu_port_remove(mlxsw_sp); + devl_unlock(devlink); kfree(mlxsw_sp->ports); mlxsw_sp->ports = NULL; } @@ -1876,6 +1879,7 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) { unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); struct mlxsw_sp_port_mapping *port_mapping; size_t alloc_size; int i; @@ -1886,6 +1890,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) if (!mlxsw_sp->ports) return -ENOMEM; + devl_lock(devlink); err = mlxsw_sp_cpu_port_create(mlxsw_sp); if (err) goto err_cpu_port_create; @@ -1898,6 +1903,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) if (err) goto err_port_create; } + devl_unlock(devlink); return 0; err_port_create: @@ -1906,6 +1912,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) mlxsw_sp_port_remove(mlxsw_sp, i); mlxsw_sp_cpu_port_remove(mlxsw_sp); err_cpu_port_create: + devl_unlock(devlink); kfree(mlxsw_sp->ports); mlxsw_sp->ports = NULL; return err; @@ -2805,7 +2812,6 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, struct netlink_ext_ack *extack) { struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); - struct devlink *devlink = priv_to_devlink(mlxsw_core); int err; mlxsw_sp->core = mlxsw_core; @@ -2966,9 +2972,7 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core, goto err_sample_trigger_init; } - devl_lock(devlink); err = mlxsw_sp_ports_create(mlxsw_sp); - devl_unlock(devlink); if (err) { dev_err(mlxsw_sp->bus_info->dev, "Failed to create ports\n"); goto err_ports_create; @@ -3149,12 +3153,8 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core, static void mlxsw_sp_fini(struct mlxsw_core *mlxsw_core) { struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); - struct devlink *devlink = priv_to_devlink(mlxsw_core); - devl_lock(devlink); mlxsw_sp_ports_remove(mlxsw_sp); - devl_unlock(devlink); - rhashtable_destroy(&mlxsw_sp->sample_trigger_ht); mlxsw_sp_port_module_info_fini(mlxsw_sp); mlxsw_sp_dpipe_fini(mlxsw_sp); From patchwork Mon Apr 18 06:42:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816339 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD77C4332F for ; Mon, 18 Apr 2022 06:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236862AbiDRGrK (ORCPT ); Mon, 18 Apr 2022 02:47:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236855AbiDRGrD (ORCPT ); Mon, 18 Apr 2022 02:47:03 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2069.outbound.protection.outlook.com [40.107.100.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5505C1900D for ; Sun, 17 Apr 2022 23:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QRpYoDPMuGfJdhqFyggb7CaDDNbC7GYrLdLOkP8VpHb3tqqi+0Llwk5lqkNjFHmZjnKgfNmjinGfyBKK8M5Gtuhva0Qt9o2X7/wyDCdbCHEmbGwxEVLe1D4MZwdYnEfo8GB0lEfpefykW/jmgm4DBOkmNzkkYvhh7PR+LYBCk7zfHOiKJebIBMmnED/OW63KZjbWc1NO7njWP5TNOrzLXDJKqPB8XRbB6MfY8CTw7+/iq8jFzdzzsKP+CpW6vCznM4ggHEvETgQkC4Ukybli5ARft0ZQWHhWwV552TJz0UbH0zQGC/PdCO/uKLbsgr07PAS7v9PWBCYfhs8MPtkJWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gYukPx+lYyQByfxjwlOKRI1so7F4j7h1LTGsIiQZFM4=; b=CSX1tyrfmRiKqru8z53z1frIFmoB/Vajd3kyd8x4QwXv2HUGMKfGVMsGct28SkAxIOMil75qmxu+AkGSYIuEfLluAgxf30yNbZuWSP6T7JLswh1TMsTXcbf5guFDqBW+IPa6HYfywPUKbnQ925SZO9kJJxez6aMVQivTP9jcDQJvQhkr6Y2oXGgwLGZKX6QdEJHBtePIeQ6K4LlLMjI3f+jk66kAyYgzThyoyKeT78qeFuD8y8W2ex/Tquh9sRvc30dgbasoOF471/2Wzh0GpSZIekLjzSU+QbPTipInVUPkAP3+mnbM3e1cDAEaAqsxSGDhoJwFXeKxh3a93X8+3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gYukPx+lYyQByfxjwlOKRI1so7F4j7h1LTGsIiQZFM4=; b=gHG0UHO8TIqrze9ENhQk0xJsTwzbaouNZ6QQNAM2fhU/pwnQVSLuTPALUBLFjOHJ63rHZKU6tK11Q5ZJlGIgDRIBfNWeeUWdvUkDOZO6BmicDyUfQYyvLHitJ8ZgSZr5Zpjw92/ZLAegR/ANfisVpSRV4/yHrsCJw6uHBrEkBBO01VK7iLBxrV9v9K9cSzuz1+RSHAamud2n/u8SbTElD/Jt7K1wxVrpezR8bJ5OZgUQ6f0ZziYeEqlOKihLoyGB/lK1Jmi/wBKzgBUbpU5VSoJqcIn/g6MhMzqztsasbV+SSO6nJperM1BwiKbDg7jfs10xlrMNC7wLLqqP+fuGvQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:16 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:16 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 09/17] mlxsw: spectrum: Introduce port mapping change event processing Date: Mon, 18 Apr 2022 09:42:33 +0300 Message-Id: <20220418064241.2925668-10-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0087.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:190::20) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b4cc9a36-5a49-4cdf-e0d6-08da2106db84 X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tzDJBnQHC72+6nZ7qCO7gqa59kLmHVRcWWPAVkHp2GLlXuqfByatSblYL8syE3OMD+6+E+Ky/+JtoF1z92xrQtlqMfD9AHGy9vgRz61HW/7cPL8JTBRrVG6zeyXRgBvodkKkQWhnDhNzKTFJt9oI2OOUjr6fDx9LqTKyoYmW3lhxJKgx0AFRme5EXlN1W41o9fQIIpej0oMK5SzMNYfiIDjEvEPJtbQrKZtbOzlqbA2EQfvJzlpCk2PBL2yWxQfBcH6ieYvZD89dJHAIO9TYOQitXa4AHYn4M3V2LTQ49SFPfI46G+j/qtd6Qf0fwPeYK+2W/tO4mZf5K4LGmuenc2VMGOHRZ7v+5lXnX3++G+J45QcfDDyMeXb3bHia2NZindyxMGht+P5QAzcQLjAWm7+L1JO+IoRiyHCLtBhqoY+D3XdlHB/VknNI9T1DU4948kp291lyq7nOgzEaaHwr8Ea4gT1O7uolyB0gP+4oY38IPyW8Qgx1PjW7ClZv3+U6f8VYNmqk4VXsZtidFPzWO9wmb7XdxyiN1xdvbkW9GdTYTRUAKuSd9vCXcHd7eHAXTCc7FPBzXkGsveJ6UHMn9FEEWNR5NNUNf+AnqTZ6lM9qA+qIk037dqVi81wGOM4K2rVofQ9iLZcJWYTahEQF7g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(30864003)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(66574015)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: odiIerVhan4Fb+JYcyvH22MTfp8j8KI5bLbuWxwRrHg92Fto5wz842CGj1P5oymIfcwBnvXD6uYoKm6MI6ALQeAnOuvolLUN1i4Fcef943KXTnBNlk2ddMLRThEm9KTuNsHvGSAcZPMOO7K6j8xAGXdBI0YJdUwbEM7LBlMFMk4YbO7EfhO+gsVB4/V4eNAn10HRxUxCz17PsxY1rWjDrrSGl6QqEUGEVaX1EbI1E5FRwPYg5fYmY73AwLUA4wogZy4eg2slNckT4zGn2TWqSd341OmhouxUZX1dA6nsPhh+NFEnZUcAb9OpNyePzYYQjcTmxNpZooxlCRm1XPFXxE/dtIregxsKZ+A/aymiFY0x9ouGmiR0uc0GbI5xOTxvP/pvLJbc3/+6hh+cccWFCvRlf7SIAQ3ASneptPXKjtRYCt/hFnMH1aFAoMuOdj0iFiOO9XDRcwGLh4dl5qCe38pYQ8/3tmHzdTIwQXScAwL7ccomCtWsGPuBmTd4ePvDlGoWUd4KEeIjGiMdQWtIDAXc0jHDqOgqanWQzk6aGjeNq57VSoxv/XigJMM4NFBYSozTz57Z7NfZR+sx6ARZftkntxMPmQ3RusRNqfV+BMNiUd7VuW5ZNA8fWS4Jsa+QmXJXgPsQ7xo3ZWx7RS1CqThoIA23k1NUwx0HxBWfHHzlMBh6h0VRP9sULD+FD7/8F86dw9LbO1sup8qEPzMJKfEluJICsJLzIHsOAsT08JJxsEdmrFLvU9WHrMtajnnRqh4QNh5MK0OQ10EsjTnTeMSvhbf7BzfPIMYQZCQjm/VCIC+d+cQWTV44fVV8iaq6y1nJjumUxAw823u+IoJbhOwgMfITtJkop/Vvw/SCgxCZi9ZnFBxLPCXCn+9Yy+AlyRVci3VwJJZVOsJlTd7/QMmZddJojVrEt/UL6QZim2uUdJf9ctpcVsokLuCGQ4P/Qy5sd5RUPd3nfQuMevNvEzU8BgEIXmC8LzsQNMnKnAr977k7eui7EuE9FtN4Pjkgav6t7QLmCjDwQjicQ+uo97QIDmDyaeY8ENvA4nkqi9l2G1hrGtOu43IDIl+4EDmtLNJK31l1oltHH2HNHYWwseVIuFSwAdTlNA6dOBaH2JwCu6Ir8OtPhoV6mV8tAjTR8F6az+i6cHTldUyqFuv7plYlcI/C0iZo/jNmbT1FoqhTPT+t3JMaecMj9ClF8yH6hVzL9EOVOuMuccTNUoEv5tC7+WVh3QtRu0vl4H8L2OyxD8CDvXopVlTv2uX3wNBB9/ID5cHG90q81lQTRWZkvMrlEkPklyLIA6kwOYfbscFiubcU70kUwyD6j2fAVr5zlHXgN1d08UvyfOIzJtXX/MChBbVMvENzhm6A0xPp7E1tNtNM2hYc6mwsJ3CCBnq9Wya0WR6G9/Vc75DuAhRaRGGuHgj40rgIJfvqbzydTsCWgDwFHETpKpjvwvn6XRklQtX7sFuPOWuVXNAcAD7SqWeQcwXJtSrN/oGv0nT/BxZowYOXizb9DjLrhkpznQTYYMTFIO8VjOmKh/MaxcJA1c9nEqHShvUsNS151YHVNspo3QvqxT93vyYlf+TMDyuC3yYfZrL7b9TaluzKWUDKZG6TUiJ6fyQW3jqeufP0+hDQSlg1sR/0NJjbcwSsEFZ1nq6bMzMcS2Sz5WBAT4exQZ2Ps2VKXPNrrNZeCYPVzbRXMZxfofz1P/7Z4X4kxZduu/BM2i5cEOBiu+pamzb6QQ== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4cc9a36-5a49-4cdf-e0d6-08da2106db84 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:16.4816 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /XWygQ1q/fakMfRbiIeLbmc6uZXMG0D+WEGiU6l31HT0px6EGz5XYM/76PIR8t64l/2bDd09GweKdArdQ8dy0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Register PMLPE trap and process the port mapping changes delivered by it by creating related ports. Note that this happens after provisioning. The INI of the linecard is processed and merged by FW. PMLPE is generated for each port. Process this mapping change. Layout of PMLPE is the same as layout of PMLP. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 166 +++++++++++++++++- .../net/ethernet/mellanox/mlxsw/spectrum.h | 7 + drivers/net/ethernet/mellanox/mlxsw/trap.h | 2 + 3 files changed, 166 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index c26c160744d0..c3457a216642 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -481,21 +481,16 @@ mlxsw_sp_port_system_port_mapping_set(struct mlxsw_sp_port *mlxsw_sp_port) } static int -mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, - struct mlxsw_sp_port_mapping *port_mapping) +mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp, + u16 local_port, char *pmlp_pl, + struct mlxsw_sp_port_mapping *port_mapping) { - char pmlp_pl[MLXSW_REG_PMLP_LEN]; bool separate_rxtx; u8 first_lane; u8 module; u8 width; - int err; int i; - mlxsw_reg_pmlp_pack(pmlp_pl, local_port); - err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl); - if (err) - return err; module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0); width = mlxsw_reg_pmlp_width_get(pmlp_pl); separate_rxtx = mlxsw_reg_pmlp_rxtx_get(pmlp_pl); @@ -534,6 +529,21 @@ mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, return 0; } +static int +mlxsw_sp_port_module_info_get(struct mlxsw_sp *mlxsw_sp, u16 local_port, + struct mlxsw_sp_port_mapping *port_mapping) +{ + char pmlp_pl[MLXSW_REG_PMLP_LEN]; + int err; + + mlxsw_reg_pmlp_pack(pmlp_pl, local_port); + err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl); + if (err) + return err; + return mlxsw_sp_port_module_info_parse(mlxsw_sp, local_port, + pmlp_pl, port_mapping); +} + static int mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port, const struct mlxsw_sp_port_mapping *port_mapping) @@ -1861,13 +1871,121 @@ static bool mlxsw_sp_port_created(struct mlxsw_sp *mlxsw_sp, u16 local_port) return mlxsw_sp->ports[local_port] != NULL; } +static int mlxsw_sp_port_mapping_event_set(struct mlxsw_sp *mlxsw_sp, + u16 local_port, bool enable) +{ + char pmecr_pl[MLXSW_REG_PMECR_LEN]; + + mlxsw_reg_pmecr_pack(pmecr_pl, local_port, + enable ? MLXSW_REG_PMECR_E_GENERATE_EVENT : + MLXSW_REG_PMECR_E_DO_NOT_GENERATE_EVENT); + return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmecr), pmecr_pl); +} + +struct mlxsw_sp_port_mapping_event { + struct list_head list; + char pmlp_pl[MLXSW_REG_PMLP_LEN]; +}; + +static void mlxsw_sp_port_mapping_events_work(struct work_struct *work) +{ + struct mlxsw_sp_port_mapping_event *event, *next_event; + struct mlxsw_sp_port_mapping_events *events; + struct mlxsw_sp_port_mapping port_mapping; + struct mlxsw_sp *mlxsw_sp; + struct devlink *devlink; + LIST_HEAD(event_queue); + u16 local_port; + int err; + + events = container_of(work, struct mlxsw_sp_port_mapping_events, work); + mlxsw_sp = container_of(events, struct mlxsw_sp, port_mapping_events); + devlink = priv_to_devlink(mlxsw_sp->core); + + spin_lock_bh(&events->queue_lock); + list_splice_init(&events->queue, &event_queue); + spin_unlock_bh(&events->queue_lock); + + list_for_each_entry_safe(event, next_event, &event_queue, list) { + local_port = mlxsw_reg_pmlp_local_port_get(event->pmlp_pl); + err = mlxsw_sp_port_module_info_parse(mlxsw_sp, local_port, + event->pmlp_pl, &port_mapping); + if (err) + goto out; + + if (WARN_ON_ONCE(!port_mapping.width)) + goto out; + + devl_lock(devlink); + + if (!mlxsw_sp_port_created(mlxsw_sp, local_port)) + mlxsw_sp_port_create(mlxsw_sp, local_port, + false, &port_mapping); + else + WARN_ON_ONCE(1); + + devl_unlock(devlink); + + mlxsw_sp->port_mapping[local_port] = port_mapping; + +out: + kfree(event); + } +} + +static void +mlxsw_sp_port_mapping_listener_func(const struct mlxsw_reg_info *reg, + char *pmlp_pl, void *priv) +{ + struct mlxsw_sp_port_mapping_events *events; + struct mlxsw_sp_port_mapping_event *event; + struct mlxsw_sp *mlxsw_sp = priv; + u16 local_port; + + local_port = mlxsw_reg_pmlp_local_port_get(pmlp_pl); + if (WARN_ON_ONCE(!mlxsw_sp_local_port_is_valid(mlxsw_sp, local_port))) + return; + + events = &mlxsw_sp->port_mapping_events; + event = kmalloc(sizeof(*event), GFP_ATOMIC); + if (!event) + return; + memcpy(event->pmlp_pl, pmlp_pl, sizeof(event->pmlp_pl)); + spin_lock(&events->queue_lock); + list_add_tail(&event->list, &events->queue); + spin_unlock(&events->queue_lock); + mlxsw_core_schedule_work(&events->work); +} + +static void +__mlxsw_sp_port_mapping_events_cancel(struct mlxsw_sp *mlxsw_sp) +{ + struct mlxsw_sp_port_mapping_event *event, *next_event; + struct mlxsw_sp_port_mapping_events *events; + + events = &mlxsw_sp->port_mapping_events; + + /* Caller needs to make sure that no new event is going to appear. */ + cancel_work_sync(&events->work); + list_for_each_entry_safe(event, next_event, &events->queue, list) { + list_del(&event->list); + kfree(event); + } +} + static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp) { + unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); int i; + for (i = 1; i < max_ports; i++) + mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, false); + /* Make sure all scheduled events are processed */ + __mlxsw_sp_port_mapping_events_cancel(mlxsw_sp); + devl_lock(devlink); - for (i = 1; i < mlxsw_core_max_ports(mlxsw_sp->core); i++) + for (i = 1; i < max_ports; i++) if (mlxsw_sp_port_created(mlxsw_sp, i)) mlxsw_sp_port_remove(mlxsw_sp, i); mlxsw_sp_cpu_port_remove(mlxsw_sp); @@ -1880,6 +1998,7 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) { unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); + struct mlxsw_sp_port_mapping_events *events; struct mlxsw_sp_port_mapping *port_mapping; size_t alloc_size; int i; @@ -1890,6 +2009,17 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) if (!mlxsw_sp->ports) return -ENOMEM; + events = &mlxsw_sp->port_mapping_events; + INIT_LIST_HEAD(&events->queue); + spin_lock_init(&events->queue_lock); + INIT_WORK(&events->work, mlxsw_sp_port_mapping_events_work); + + for (i = 1; i < max_ports; i++) { + err = mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, true); + if (err) + goto err_event_enable; + } + devl_lock(devlink); err = mlxsw_sp_cpu_port_create(mlxsw_sp); if (err) @@ -1910,9 +2040,15 @@ static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) for (i--; i >= 1; i--) if (mlxsw_sp_port_created(mlxsw_sp, i)) mlxsw_sp_port_remove(mlxsw_sp, i); + i = max_ports; mlxsw_sp_cpu_port_remove(mlxsw_sp); err_cpu_port_create: devl_unlock(devlink); +err_event_enable: + for (i--; i >= 1; i--) + mlxsw_sp_port_mapping_event_set(mlxsw_sp, i, false); + /* Make sure all scheduled events are processed */ + __mlxsw_sp_port_mapping_events_cancel(mlxsw_sp); kfree(mlxsw_sp->ports); mlxsw_sp->ports = NULL; return err; @@ -2074,6 +2210,7 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port, err_port_split_create: mlxsw_sp_port_unsplit_create(mlxsw_sp, count, pmtdb_pl); + return err; } @@ -2294,6 +2431,11 @@ static const struct mlxsw_listener mlxsw_sp1_listener[] = { MLXSW_EVENTL(mlxsw_sp1_ptp_ing_fifo_event_func, PTP_ING_FIFO, SP_PTP0), }; +static const struct mlxsw_listener mlxsw_sp2_listener[] = { + /* Events */ + MLXSW_SP_EVENTL(mlxsw_sp_port_mapping_listener_func, PMLPE), +}; + static int mlxsw_sp_cpu_policers_set(struct mlxsw_core *mlxsw_core) { struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); @@ -3085,6 +3227,8 @@ static int mlxsw_sp2_init(struct mlxsw_core *mlxsw_core, mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops; mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops; mlxsw_sp->router_ops = &mlxsw_sp2_router_ops; + mlxsw_sp->listeners = mlxsw_sp2_listener; + mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener); mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP2; return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack); @@ -3115,6 +3259,8 @@ static int mlxsw_sp3_init(struct mlxsw_core *mlxsw_core, mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops; mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops; mlxsw_sp->router_ops = &mlxsw_sp2_router_ops; + mlxsw_sp->listeners = mlxsw_sp2_listener; + mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener); mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP3; return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack); @@ -3145,6 +3291,8 @@ static int mlxsw_sp4_init(struct mlxsw_core *mlxsw_core, mlxsw_sp->trap_ops = &mlxsw_sp2_trap_ops; mlxsw_sp->mall_ops = &mlxsw_sp2_mall_ops; mlxsw_sp->router_ops = &mlxsw_sp2_router_ops; + mlxsw_sp->listeners = mlxsw_sp2_listener; + mlxsw_sp->listeners_count = ARRAY_SIZE(mlxsw_sp2_listener); mlxsw_sp->lowest_shaper_bs = MLXSW_REG_QEEC_LOWEST_SHAPER_BS_SP4; return mlxsw_sp_init(mlxsw_core, mlxsw_bus_info, extack); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 68f71e77b5c7..928c3a63b6b6 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -150,6 +150,12 @@ struct mlxsw_sp_port_mapping { u8 lane; }; +struct mlxsw_sp_port_mapping_events { + struct list_head queue; + spinlock_t queue_lock; /* protects queue */ + struct work_struct work; +}; + struct mlxsw_sp_parsing { refcount_t parsing_depth_ref; u16 parsing_depth; @@ -165,6 +171,7 @@ struct mlxsw_sp { const unsigned char *mac_mask; struct mlxsw_sp_upper *lags; struct mlxsw_sp_port_mapping *port_mapping; + struct mlxsw_sp_port_mapping_events port_mapping_events; struct rhashtable sample_trigger_ht; struct mlxsw_sp_sb *sb; struct mlxsw_sp_bridge *bridge; diff --git a/drivers/net/ethernet/mellanox/mlxsw/trap.h b/drivers/net/ethernet/mellanox/mlxsw/trap.h index 9e070ab3ed76..7405c400f09b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/trap.h +++ b/drivers/net/ethernet/mellanox/mlxsw/trap.h @@ -133,6 +133,8 @@ enum mlxsw_event_trap_id { MLXSW_TRAP_ID_PTP_ING_FIFO = 0x2D, /* PTP Egress FIFO has a new entry */ MLXSW_TRAP_ID_PTP_EGR_FIFO = 0x2E, + /* Port mapping change */ + MLXSW_TRAP_ID_PMLPE = 0x32E, }; #endif /* _MLXSW_TRAP_H */ From patchwork Mon Apr 18 06:42:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816341 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1D3EC433EF for ; Mon, 18 Apr 2022 06:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236851AbiDRGrM (ORCPT ); Mon, 18 Apr 2022 02:47:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236859AbiDRGrE (ORCPT ); Mon, 18 Apr 2022 02:47:04 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2086.outbound.protection.outlook.com [40.107.100.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F33D19031 for ; Sun, 17 Apr 2022 23:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FrNTITSn1A5FLevQMKExZzCaV18JnPE5XZEAi9y86mn4B5+JRajV1krGJ2s4TTUuXXBPZTGunnI7GrhrYuWzRH76V0ItMgPjhAYphZY2fmI7PoHeLA5ANIpfD33SFao4WH24o1zendlH7gaQDnGbPj1dM7ciD0+233hHgzGHOZRjzk5tnA7Bj+n5JtapItLXc/2/Vs4kEM08jcX+8feNTf3Gq2TfiRwQpOCNd8mBZThgJXaiDVfo6gsbI/AW3wUXoe2B2Kg960Xa5sxMQWbn6snjj5HPSH5+eH3opuh5GBMUPa5ILihaAHq9druEW0x0gb9MgZBtfSGiJK36M9lv8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KwgkG/eRV98o9cmTNw0Js1zt2lqnigHHkVyi2P1f3EA=; b=XzE5Ui/kOcuo38yVzFi3AecRZ1F+A6dV8GBhQPGyiT0Koj/2E/LIJ8cdP7jqiSrD3fRxWuhBydzA56Ha7gZBRqJCnY9tXXL/PBD4rKIuyZEWyegcQDNn0bgY9iX39DwbZO8R6vsQzqvRT3pu6hKdY62GyyamMGvQi/k2FmCldeimz+eWo6YI9ir6h3OvstlrRuOFtqD1zHVbpVHMp0c7nNq1qVEcjLrRF53PgRw3a/6ew44ep6QdJFwcFeQRSVRSIgdjesUStJPqGQ8az+8IK8s5w6knOD/LArky9u4C5xTShlw6YXO5r7SwacqW60Sk/rOBw2RH0kkkWGONW9kGbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KwgkG/eRV98o9cmTNw0Js1zt2lqnigHHkVyi2P1f3EA=; b=lv2qu2+LBDYGR8g8OoCWEFfdMlHPM/J39/JdtKep8R7spn3wt3o8IFYrwGXGKWjgT2yvmt7jRZ+DazItflMecuPuvAtbqCv33rUED3yZh45wlhMO3HjnYZXEB0PO/0eIHAo8zPMxhqPpwHMR+qvCIjs568yf57geE0jA06fgWHR8pQhoNbAXGjh4P3lyFUNWcK4A+wpH9lZ9/WqlM6QPD0aINMQNN2jHJAC35PXCn9Sp/2/1C4l3LWKFFXvUBVEl6wfnkLJBlLxC5znMWmZ/wjjwqrjadhTNJHcRwGwvppHxobRDcBZAFBZt9lXA8kHC6MqwQRn4BGXEMcA9OugoSg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:21 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:21 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 10/17] mlxsw: reg: Add Management DownStream Device Query Register Date: Mon, 18 Apr 2022 09:42:34 +0300 Message-Id: <20220418064241.2925668-11-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0405.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::14) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c75c1820-46dd-4e46-8cb3-08da2106de77 X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ILDWBHk6VAZrNZO6cr2OuPji7vSPwz0K1dOLoY0vfstXy0nvEwX18J6FYy8DRpBobz/6Afkxs1RtKKD9d40WeQ7fRuRyoMWqfll9aQSzuSrQxW1IaZ1RGHdbCm/Ew0h7ZAXSZxoTFwnMgOHnS4Dr4zQQEaBpuOUIzaQNk1WKvClNUpR0tcoQRQNc4piTZSmOTVxojQHIGYaXEoD5JQPd2GjJJBt4SpEWmyJNw0qQUwh64MsqK2yOalv9ta2Sxs9nqrMDAAFRfofAX5BUc92SJ0Qds284A5u34jIAsQZnpMUFgTl2m3rQsNlQ7VeLQ7isLLwLef0V2BDbrpURrqmSBkJIdfZrIhb8a+WP3QqU90dQBYRBwNn2I63WfV6n0iN6N3tdRSl94ghKX766vpnVNYRLrv+p/jatQS7/00nBCXDdF0m2C/fH/aqe9zxqe0lgrvh2ucqDwdN+8/WF8l+h6Z2vVhXD+pLFBRzip2O2RW77CwhZa2Avtm7JvXB2/NEBC/a6tFBxHFoRtiUSj6kc34lWgKkELPPUgcz2Ap9JDOCSfGrn4LFTp7mpmOt0Iw9ftXMr/wzsWfNkNWK2jIKxYiL62/rLiAUl8yDq3oB7nt7GiCS5KLd8LPJSPFZ5dhH/C51K+1JOWZd4gfHRuBIpuQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UT60RBWcaLwZZcVkR+C87CWoYT3vK64x1blBbtlUxlDSje4o7Bzx7AlJomXEpe9OmWMOedvlLO56/4nSzsdR1UtB9wFUTcAVs2gtQtuXl1ZG63pD3ljF8QLx3p9pU8PSRPkMyzGQA7yVAokr254Gt30KV4+GwpSFofsIZ4uWGTOF42dK51oSZdV0NojzYa5EzPGNypC/OCkQKLtuNCYiazR+bDjTAFXcBVrpml43mRcysexoTK+AtvNUeof0Z0kd5/nk8t5zRhIBCcC7uLQs37g/I6+wjDZsp3Vb1Rmaa8Ax/dOSj2s1O7uY77d7Xxd/bmOoUjMEc1HXX+L0/Kl3QgC/nZQOmQ0N3FDfyf8yf01ZF/11CLslAaAkiG82O5Htpi31G4Wool6dpE7hrKLFftGuL7hbyEO1JlodumeEuBs9caWLDxCGDRSSLeUJeewTKmvdHM8MSdNIoY1s31d0zyCjJTPSr7gQyfewLl5cDRDnkqVq3WB6CLY6d69JbC8r8a7PiiWtB1PBIho2LjEOs8B6TjY7qw/bv48TvY9UU+Dot94Sjz3aFpbRp/v9h0swzC3OzqYQom64QpQR9lY8CCtaLPn+g5jAW2Pd2yg14HOIQKXJ0T1JfXIHSAobpjc7d+iVBzeQwxXIAImSMOWcF6gqahDubPS4iJXGLtHgm/y7v8UqRjHfA9yUlkijb+yrabL7aG3AcIQUbdgeW0rcCSlDsyKi+ER9duBIaS0c9WQH9yhsQOFIQAZ0gt3fWPkxuXk5o8MktA+PZ4dtfq+FAeXMgjF62SvsfkD2N1iivSHEOyp8SlvkhyiB5agzBwxT8LF9bH4GNyHApWrt7rLCyoiwn7yjh6GY0npEfkkzH2te2LwtzCHqzenmbBzBuJAKKHD6wRmnbuLCrvG8k5fqOTFUDbOyk3OCBJH0C464sZim76vPtmzwS09VkE8H+HIcYvo5QdAsmCIk1PNdgcCdCjEvoosK2XMFa9Yo7mzDlRITJDzlArn4sujcV38JMpynaXwRM4gMUQyxADlsntDceCjaxZ5hi/67GD3mBocT2jGCd9XFbmybFWDgMiNNqVXGu8KyP7jfrxRlyACkjxvCYtfuDXDVXHcnehSllO7nW97kfJI01egpCN58lGJN1SggF21B6lY1/ws1YZvgbdqH3JuKpl38ErZgaWQdAI4grmGHHEXrE7qcKgXDaW0f94d6J8h9bOemF5vNwRJBQFmMqFkEys05gphQh3f/pp/6nYuQkip+C8bk+FhIXGoL/BTo1nq9u7wVJiYFw3OjWAWYHthZVgWb/RDZDSyn/BWD3H0UWaLu8+WGqoFjmkTIc9UFcyuac95OvhJUk1JGlcCrFbi8MfXeKisZGd/forBkUBJx3237nw97peDc8ztAvYiy57ljkCnnT5VEIw5WX+SJjXxDi6vPWwf6qVNw0NuVvoJ03QL10EqQk3BQ3PDC/S9mn495kVFS9AEpJ8cG6PVQIx7flUaUJyer7HjlsCFofK/q9UA7F7Z548R66SaQVTM1GaSPDpt+2B0lSpjdcC5oIWANibZV3F5dCB+aFTndx6OHZZ7gQn0PsBqRhHOSa8QQ1QjSV/8oddIBgLNmJuVcPu+r2dG6fBre5YhZqro4LNZTZSJXW9IxI1UDowghR0dIUxfie5dgLY4nOzvHRMONnkK6rve4gfbpUruQZKUB7juYb/IC7ryDFBb1bV1F4nHBvMAJYebeQpQPx98aCYWoxg== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c75c1820-46dd-4e46-8cb3-08da2106de77 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:21.4586 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GWz7EbdgevaVTz39gvgRSjxyFu/R2aOPXZylhGTh7/YQnJ+axfzmzkaY+GzrXAg1loVb52MunIqHUuPmrhDmAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The MDDQ register allows to query the DownStream device properties. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 144 ++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index 7b51a63d23c1..1595b33ac519 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -11492,6 +11492,149 @@ mlxsw_reg_mgpir_unpack(char *payload, u8 *num_of_devices, *num_of_slots = mlxsw_reg_mgpir_num_of_slots_get(payload); } +/* MDDQ - Management DownStream Device Query Register + * -------------------------------------------------- + * This register allows to query the DownStream device properties. The desired + * information is chosen upon the query_type field and is delivered by 32B + * of data blocks. + */ +#define MLXSW_REG_MDDQ_ID 0x9161 +#define MLXSW_REG_MDDQ_LEN 0x30 + +MLXSW_REG_DEFINE(mddq, MLXSW_REG_MDDQ_ID, MLXSW_REG_MDDQ_LEN); + +/* reg_mddq_sie + * Slot info event enable. + * When set to '1', each change in the slot_info.provisioned / sr_valid / + * active / ready will generate a DSDSC event. + * Access: RW + */ +MLXSW_ITEM32(reg, mddq, sie, 0x00, 31, 1); + +enum mlxsw_reg_mddq_query_type { + MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO = 1, + MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME = 3, +}; + +/* reg_mddq_query_type + * Access: Index + */ +MLXSW_ITEM32(reg, mddq, query_type, 0x00, 16, 8); + +/* reg_mddq_slot_index + * Slot index. 0 is reserved. + * Access: Index + */ +MLXSW_ITEM32(reg, mddq, slot_index, 0x00, 0, 4); + +/* reg_mddq_slot_info_provisioned + * If set, the INI file is applied and the card is provisioned. + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_provisioned, 0x10, 31, 1); + +/* reg_mddq_slot_info_sr_valid + * If set, Shift Register is valid (after being provisioned) and data + * can be sent from the switch ASIC to the line-card CPLD over Shift-Register. + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_sr_valid, 0x10, 30, 1); + +enum mlxsw_reg_mddq_slot_info_ready { + MLXSW_REG_MDDQ_SLOT_INFO_READY_NOT_READY, + MLXSW_REG_MDDQ_SLOT_INFO_READY_READY, + MLXSW_REG_MDDQ_SLOT_INFO_READY_ERROR, +}; + +/* reg_mddq_slot_info_lc_ready + * If set, the LC is powered on, matching the INI version and a new FW + * version can be burnt (if necessary). + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_lc_ready, 0x10, 28, 2); + +/* reg_mddq_slot_info_active + * If set, the FW has completed the MDDC.device_enable command. + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_active, 0x10, 27, 1); + +/* reg_mddq_slot_info_hw_revision + * Major user-configured version number of the current INI file. + * Valid only when active or ready are '1'. + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_hw_revision, 0x14, 16, 16); + +/* reg_mddq_slot_info_ini_file_version + * User-configured version number of the current INI file. + * Valid only when active or lc_ready are '1'. + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_ini_file_version, 0x14, 0, 16); + +/* reg_mddq_slot_info_card_type + * Access: RO + */ +MLXSW_ITEM32(reg, mddq, slot_info_card_type, 0x18, 0, 8); + +static inline void +__mlxsw_reg_mddq_pack(char *payload, u8 slot_index, + enum mlxsw_reg_mddq_query_type query_type) +{ + MLXSW_REG_ZERO(mddq, payload); + mlxsw_reg_mddq_slot_index_set(payload, slot_index); + mlxsw_reg_mddq_query_type_set(payload, query_type); +} + +static inline void +mlxsw_reg_mddq_slot_info_pack(char *payload, u8 slot_index, bool sie) +{ + __mlxsw_reg_mddq_pack(payload, slot_index, + MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_INFO); + mlxsw_reg_mddq_sie_set(payload, sie); +} + +static inline void +mlxsw_reg_mddq_slot_info_unpack(const char *payload, u8 *p_slot_index, + bool *p_provisioned, bool *p_sr_valid, + enum mlxsw_reg_mddq_slot_info_ready *p_lc_ready, + bool *p_active, u16 *p_hw_revision, + u16 *p_ini_file_version, + u8 *p_card_type) +{ + *p_slot_index = mlxsw_reg_mddq_slot_index_get(payload); + *p_provisioned = mlxsw_reg_mddq_slot_info_provisioned_get(payload); + *p_sr_valid = mlxsw_reg_mddq_slot_info_sr_valid_get(payload); + *p_lc_ready = mlxsw_reg_mddq_slot_info_lc_ready_get(payload); + *p_active = mlxsw_reg_mddq_slot_info_active_get(payload); + *p_hw_revision = mlxsw_reg_mddq_slot_info_hw_revision_get(payload); + *p_ini_file_version = mlxsw_reg_mddq_slot_info_ini_file_version_get(payload); + *p_card_type = mlxsw_reg_mddq_slot_info_card_type_get(payload); +} + +#define MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN 20 + +/* reg_mddq_slot_ascii_name + * Slot's ASCII name. + * Access: RO + */ +MLXSW_ITEM_BUF(reg, mddq, slot_ascii_name, 0x10, + MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN); + +static inline void +mlxsw_reg_mddq_slot_name_pack(char *payload, u8 slot_index) +{ + __mlxsw_reg_mddq_pack(payload, slot_index, + MLXSW_REG_MDDQ_QUERY_TYPE_SLOT_NAME); +} + +static inline void +mlxsw_reg_mddq_slot_name_unpack(const char *payload, char *slot_ascii_name) +{ + mlxsw_reg_mddq_slot_ascii_name_memcpy_from(payload, slot_ascii_name); +} + /* MFDE - Monitoring FW Debug Register * ----------------------------------- */ @@ -12811,6 +12954,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { MLXSW_REG(mtptpt), MLXSW_REG(mfgd), MLXSW_REG(mgpir), + MLXSW_REG(mddq), MLXSW_REG(mfde), MLXSW_REG(tngcr), MLXSW_REG(tnumt), From patchwork Mon Apr 18 06:42:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816342 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96CF2C433FE for ; Mon, 18 Apr 2022 06:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236838AbiDRGrO (ORCPT ); Mon, 18 Apr 2022 02:47:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236831AbiDRGrF (ORCPT ); Mon, 18 Apr 2022 02:47:05 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2068.outbound.protection.outlook.com [40.107.100.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC5A313DF9 for ; Sun, 17 Apr 2022 23:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYbTMcGUf+2U4Av71r8T/bOVy1f/W/TCqzYMtJ3bxkMJ9lyyuccbFlCpv53a6uBnI5uFt9LY0IaWFDd+c4AhJ28q8abfczMX3i8c3DL2GanDPCWxZyw1T13GKsy0DB9tj1t3KiUS3lzW+mUJHM/Wykw6p0dty5Y64LZyW0APolT6ZaAxrZL8AUHrq3U4wnODNL4vtnmPmH/Rz9m6LmGtJZLKCVE/0PgtAEdcnV+e7w3MgU0fHBWe4HgWaSJcc+7a7yE586kb96/tfM1zEWDPxXemjoJFEpKWv08qgamCJp0KJfCLYZYaoIuNEmNPl+O0Dwa+AmWGh6Zcaep0Eo2R/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MR/XWXMsbUYwbVlyUQvIKbDDN9woUiFrodYeydXtEbc=; b=I6EuiP58hmsIeu4wfl9V4OiMi6ohItlA4tcPf9sYNRIEGSnFyv+G5YeARtQ4a/5G2XC68V0lqeJsSdxVo9k1GTklGfwrmGilqjjMzqMYXc3r3gWWEjrq94nVQXkb8niX8SAtouBI90dWYGOp9GVW4OLM8QsxqAR0MwxcGcY0J4CmuAXn8hPFYKdDp385XgMXo0rTyJ3vqGMENZGNrmfy1zgyKXDH+3by+TAFOivahjsTfBWSy4nrWPNE1+zYwyq2KrD5514JESMI+3R8S+v84N4hcxwimTaoX077ySJw8hJsLqB9Jgs9UlVH9EQ7s6gqO9omRjPOCupQuYomdQRZ6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MR/XWXMsbUYwbVlyUQvIKbDDN9woUiFrodYeydXtEbc=; b=D5Wi4pqLb3jp+HDSa05TblCbefYQeuo0QPuHIOomSEW7yK7QqJ1NYAY8BQDna3C8+8WToGNbrF0C/qQ7pwg7gaQmyDhncyS11UGdd4Fa539dRho6Hj4rR1AlHFQ0q586lFhSysg0LpZr1VL92m3ICjGcKtIR7pzx42LsL2XezeCMwQixBnzLuB9gFT2pKJOUsoRBJEv5gQOeUFzJfo8iYA2JzRRAUKQMDhe18dv2xUc6YAYkGJ6IfMJPoNq4Rkcz7tQNNV7t9twiaIU43q/WEZIbHaycWneg28nEYm6n+Yefgj7xd/DZz23/kDhLfNivynnw9u+eMAXEZR405ZYeHw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:26 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:26 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 11/17] mlxsw: reg: Add Management DownStream Device Control Register Date: Mon, 18 Apr 2022 09:42:35 +0300 Message-Id: <20220418064241.2925668-12-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P265CA0058.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2af::8) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6067e084-0a96-4c1c-9293-08da2106e15d X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9SIPVsMRrJl4EeWzmETUlaxe4Ngdg21nneb9ud30grxOsxKP0h8fZIbNEOhdpmLoWBxGjiMsFhAz3ErdlceW23+QxThV1xWzPajtwG7wpU5ajxTeb9GULDEOeI+nym+DXp8ItbLGFkvucmQr4kAuJpcHiuIQHnBvzAXnDGp6cMp2oL6BA/ySi9ZgqHeemjBlipNKiQJcvl5mNtIRuqfU7Cr7lQ3VlAivF06fay4KCILth/tpxwL6cWI0IcS14U8wVsGzq78TTp6iwQ9yOEn3zZ9jhoovnf0drXHiC0/C40MOGpGuBXuBmTDnHo7cbelcbmVcHmnKv0T0nJb+COlaxumWCi73bGTfg2rq16Z77BOv+IIJKdP5zq+4x9gKw+b+8uV1qMNRuoa65rN19d0/SRLJsSOU/OlxtBvfwGfDlFgUun/cmdm6eAVrBqLQC85au6zjE4Y15Pyw5I387uAe9gZiADQLTPj9dily8z1vjT9HEU/Vcq3SNLaxQUfn4lJ9qvYBAJ711gClFRGW/IQQwvwGR7y84WBdqVH7tqukWw+OWLr0Bx5VQHMfXa0HIEgiJ2R9js6Ifr22SiHs4uXV6dln9noGKB5bwP2s3F4Wx/a6rtcEz9DBk7bc1sysExVqHpCemgnTd/5jf/vQuhALsA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S69O5hrMN7wx/1CO72RGcC8TrwWFGjBrDCx2B0ctUM1r9kTBJWUvY5tPti9rNhH1A6TrIGoX02bso9Z+BYVH/u0CnzWJQfN1BCiVaqLVXPsN7EP4b8Y3+LtT4cdFsMyI62DqCzbbbhZio3flTSJcakFtnivIocUj4kh/E5W+6Sozz3ONU8gVSWaGIOBeLlhYWCEpp0lXwlkIegtN13gv/AQbwsxlSR5NGKoLEKO8YbzMf+F7BfzJNNAI2LQx7mV1SQDgrrhOig7A40/dYVXldbggkuj/TehwJqgJ+bB8Ta0Qvj2kvd9qlilPnNJ+oAoVvJUYniQPJSo4sy8lzMzrDJMEaeLP1lsdboisPF9EUfEJ/bGpROfz9PAQXxCoWaNnbEdV2nbJR2XU21HqvBo3u7A6ZAFKNZ+nbVLgcat2+nqDFFPLv/n/WCJuoj0GCeFK7W8mBvpC+zx4Q/mY5qMYBlyXMt5x5GTId/J16Z1leYWHeUZVRCn4PTf9UQl34VqMybiH3uI+VEud5Nrvx4Ct62AvD3TUJ4DpwA3EA1nfwAUY/O8+831cJF0qnvhs/HVgrUVQRkoqY3DgqR/Zsq3yTSoSc+OyqG307Gkma8nRamnYt2/yyIGhTKqy6IbUjpwpiSc5EXGfaJ+owg6yhYV1xA+RC9L0aIsuRlq+gI4+dS9moXBxeUV8RBkKlIAP2/XMEjIKCwdsklTcg21qHjiot3FVwgeTIxK1CwPIS9AMIs82p8nQ3nuk5m0oKu+ePRe4Ad/d8HYxo76AMbSByEHZwgSHWmiOOZNM+rjGDlNh7BLFM2C3WeUeCBCxZ5QyyDoFgpNyM/s/HQVcbl2eHfVvPlfeau7Rsy1qDPhWLxGnQJ0TYFjJIWBjnLw6LptOULD5g8l5nZ2HgEIeRyWnbgH+Qtxcz9KjD4fCkuTDwq3PV0zrKJfHwENJKWMwD62JU+8yvt5vVxvk9saWnMxVr3SsdmvVijF6mEaXP3NH2R4UhihaFQahMfLIKcfrIzN1M1lQrpvtb0B/dqYQGnGXcrE40MOUP5e9Ir4C3f7N3HCaDT9qRVhvNvJuQDrc9EtSWYIV9dLAOfrjgmUPWboJevVE7oubAnO16mqaPQ0AKCckAtcrIHDVDkkR6gpMctYfTWhoE4GCaWPDx7uP+2rQEVpPF2GeC+lmTjTJ2bq5QTeve92/9d+c/GnoXLohjNbNDXIzU+FD4lhwgZQQYD1anny1PLy01WfRnSnv9zbHqx+GQSYTviwwmggw81cad7OQ65swOE4eqyBLrWA1pdMCJA3YjGd4f5YZt3toP0Q+b7W50SlK5XUh5DkxlMMyjEiuBDFxxuaHK5wxFla4yJNp1UnhiEEmgIC3TEYvHouFKOwdOFsfM5Q8gDH/qY5aZ9nrioBYlCt0t3Q5bL/C/SUqVTILXouTfu4VIJvexTrQowhzk5DQJSpMmT6De2hd4Ik+qWNJaqAyXtIsLQ+QoTadKCGCYbBAWKMbn+Uvv2LqZYh3omxEXJZwHPkwMkUFSs9Eq1d0Au+iZ0cf0KuBxyrmMia4AfDG93Uc49A+SKz0X1xN7rfF97gnjTBibO7GMVyY6C16C9a5s2cTjycThGu21dU98f75KMIMTyzxwjrJma4pX2KVHdoRUiGCn6xqw/6G8Qe3sB6AVabO/7FT+Z/UgieHrbBnxWgvNA86T350N47AiwfQy17+3a2YhpWTLwBzTpg5iJBQJJF7XuAuTAHgxDpQWw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6067e084-0a96-4c1c-9293-08da2106e15d X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:26.2278 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZtkBxRJ4ugj3pPco1XbkWlkuEfwgGA6kWKGnKF4ZPp1+o92u5ZYjQgU1a+/HD+FWlhfrWzd9zdY1fgtgXhvZrA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The MDDC register allows to control downstream devices and line cards. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index 1595b33ac519..31a91de61537 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -11635,6 +11635,42 @@ mlxsw_reg_mddq_slot_name_unpack(const char *payload, char *slot_ascii_name) mlxsw_reg_mddq_slot_ascii_name_memcpy_from(payload, slot_ascii_name); } +/* MDDC - Management DownStream Device Control Register + * ---------------------------------------------------- + * This register allows to control downstream devices and line cards. + */ +#define MLXSW_REG_MDDC_ID 0x9163 +#define MLXSW_REG_MDDC_LEN 0x30 + +MLXSW_REG_DEFINE(mddc, MLXSW_REG_MDDC_ID, MLXSW_REG_MDDC_LEN); + +/* reg_mddc_slot_index + * Slot index. 0 is reserved. + * Access: Index + */ +MLXSW_ITEM32(reg, mddc, slot_index, 0x00, 0, 4); + +/* reg_mddc_rst + * Reset request. + * Access: OP + */ +MLXSW_ITEM32(reg, mddc, rst, 0x04, 29, 1); + +/* reg_mddc_device_enable + * When set, FW is the manager and allowed to program the downstream device. + * Access: RW + */ +MLXSW_ITEM32(reg, mddc, device_enable, 0x04, 28, 1); + +static inline void mlxsw_reg_mddc_pack(char *payload, u8 slot_index, bool rst, + bool device_enable) +{ + MLXSW_REG_ZERO(mddc, payload); + mlxsw_reg_mddc_slot_index_set(payload, slot_index); + mlxsw_reg_mddc_rst_set(payload, rst); + mlxsw_reg_mddc_device_enable_set(payload, device_enable); +} + /* MFDE - Monitoring FW Debug Register * ----------------------------------- */ @@ -12955,6 +12991,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { MLXSW_REG(mfgd), MLXSW_REG(mgpir), MLXSW_REG(mddq), + MLXSW_REG(mddc), MLXSW_REG(mfde), MLXSW_REG(tngcr), MLXSW_REG(tnumt), From patchwork Mon Apr 18 06:42:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816343 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFBC8C433EF for ; Mon, 18 Apr 2022 06:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236831AbiDRGrP (ORCPT ); Mon, 18 Apr 2022 02:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236850AbiDRGrL (ORCPT ); Mon, 18 Apr 2022 02:47:11 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2083.outbound.protection.outlook.com [40.107.100.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1883C19002 for ; Sun, 17 Apr 2022 23:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YSj3BPUcl9aQYezPWdlZ/DlpfhVIryaYU0H6y+QHOXmJK97BjD5dwt34zf0ULWB2qko+NAwINwBu+CpXbBG2JkhXFOAcJ3Rbzvi9kNJEBZH/kOpdaCXdafY0y11VCspfGAWyAdD6cGCT1IRMxzbmv6zlDnsXONdqsK16WrSLbH8OLU4BswIzRoEyMW7Sr78pGcdjf1XpYIDblPMEUDqZp24hezE5F+5+BZFcJe38nZ633qfhy2dWKLYlFOyfmfXq+7PyrgFGil+cLoLVf54MlO6//wtPpuQVjP0xSeF6X3ydOnVr70WGJ4I0iQroITG+QVtytfLpeF1OL17O4lyzDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HBOTwVEcpyLK2TsK1FFPzIEC61cnikcClOu+m+h6hog=; b=Kj31pAB/aLEOKTHUQWjB+J7G6E3DarozNPKsjDcGT6ppwPPlAl6uAg915+yxnhCCcIGPvtEwScUJfBl4PMb/m0Dr5uTVNa+KJ5evCWdoTMkNNtpIgFlRGwHTroTnj0XWlYVQRJfosrb68NSBUTPw3ftme7ze5D/bCzNamsPQx4xtabgQfnzllo7K3eb4JqwnErZ7l9diBqY8UkcekpeLNKDbbegt2ReGttoBiUiNM4bnwoh3c2pBIj6eIjUTIIruYL19WgJ3AZUxz5d+mmTd+8/SqqKoeh5GVmzXqqqn0QMCLPSd6CFI+5XvZU1KvqHydDYReaJwxLC3XSNvaufC7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HBOTwVEcpyLK2TsK1FFPzIEC61cnikcClOu+m+h6hog=; b=ksOp3FSfLMCMKZVR9m/e73JHGvf44T14bX+RbHlIT9CZq9Cl8kkNEAhlrHflaB4xpEQs1Rp4/Iq/twDGmoZnRI+l3MqxDt69jCNuypOe27L9Lmfua8MsJbqG+UDqYk7Ff5YZg5EgXsH5eeVZVAamT/143hXzKJJZHgGOjlaHhlVvwViXadHsCTuBQYeyiPQmRbnWacvqP4elMSAwLSP/vYp4QubtuZxvGkr//h9KlbEvCQnmBgWqNgC1yUHb4zW8gnTZX7kH02gcmGPrgsr6DYncHE6jCUa2k/O1nC2k1ud3OYOFY8ueCRPH+l/q2EwwiGCwyFLVz5flmGwUiQvaWQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:31 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:31 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 12/17] mlxsw: reg: Add Management Binary Code Transfer Register Date: Mon, 18 Apr 2022 09:42:36 +0300 Message-Id: <20220418064241.2925668-13-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0332.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18c::13) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b1cfe445-ea23-4181-d6a3-08da2106e48a X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 97YIdGLFuw0EupFylS1NhFnQIcQyYs0WoM7xS7HZwtX9GuUdX64fLNP3ELbl+NwG3BPs9wCDH1YVKyVglez5h/8dbfCZC5fdfiXXdUAAgWYrTxVedGErspN19MDg4pPstQblPvgQXYv1nvNPjruQ7PbdSJwfJkeMzwaZeWYPTP2sms038Fm9GcWfvc2I6p9hITkI1Tzxc5wn8y+lXspgyim01iNJp+tTM8pf5uZYNe4iqLZfH/Alzs/RPhEOaN9E9rnVlIsTBR6PgmknZEeI55aeJ2Wk7rCNjnN3rZBBZwXLvH6qWb2xtIFqabYUELQ3K8d4pmCuShxEGvmSkThjlVa5lfKyJClIs8CWG8gU8zBT4FpfO+WGeqt0F3LY7T4ybiZ7LcMuAL6+g0BTDNtGUZDq9deRP9fEw+1yJV1YqgqfLsnaKfRb5FS4ZGTYDa5kSeipLM+j34QAyGapGYpicRVhOkzlUee6Oa5jQ50bC0VMyhVC5MTikj7LF4B5daF0G8nFUEyVRowjzERozGDrHEehugylG+2drKA4sYfEY/hIyRTRjO/30K3pzTUejI2ajrVDjw6S9paloiJxlukgzrIzG1wSBn53KqaJqWX2URFsRS6W/FyDF+ZzeDZNCnHTZgMoNQYinPeN0evHFziDnw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ReYE5qWOW5s5K6oAczo2cYSNHe7+9BLU6+eu7dukZWboUDbdYjIpW2M/W6j7Xy4d1CjumuGtwYnA/mJh2L78lul+7hKr+UezglYxGaHqg8G4tEzuSHFBM3BLI3EW5eserHKNCYsC9ydGNMFeyMZkv9yn6n0weIznTQQrxhJXiSOLV5gUQW3WxHM6yNQZxg/QMZ4OSCaFADiHdLalI36MjFwT1kZE9pgfetp7G8dnAyU6mFPbbWWIeBlYpFr0U69Wjh7fhDA89HoLs0bW4rHuoPFYhZDeerhs96/S5+jSz4n520eKj9S/FOwXujgnZOlMHMaSYxR4aeXUJRnnv6mPTewYIhXIPvYuPQFhUsr1vtbymtHNjt7rl+hTdY9bx5Hk2CtMDn8SRU4fdXulyI/qc4plkezUytV6QwNKSXcUHhi6fHVxx3dPhutpYM2SRf26hTzPx7kBNmY8ZxAJzVKTSfnda71Mx41oH4TzaBuyOVy0Ob9APGgIiqn4J/kyJcYp0HzjQYdFD2jzf2y8yQBEVB6HZCze/wFeW2MW02MuWJIL2BHj/JMA3AFha3W2gpdx/HY+0MxprMeoWexNm+R5/0w1qcPJrCUKFLkk29JonqC7zH8MNvip9ExrAFJEvoPyCK0bGP3ZfblRbk0NmtG2WI8wq1ZzpDrPzJ9xisRx2WAQE7wz2AW1j1NkNaGm/rfLfRad/HNfJhdE/hG31zhV4UiwywmJsxPGUE9kiyg2QkbCA0fFdB4WGXIcVuxemDilZk+x08UlrLp/3BaZfaEZ8NRNMiJ4nm8pxyX0MaaaPmntbQZe+9PhfpD6HaaMc4igLT6r30qz6owaoF+19ngcrcF17QVEmyiY9p8/h7fLTdnS6ROtx/TR+hWBaycaOf+nt/sNiFnm40DTEaGMf3/XvILLgzajyzWqtFUbyBm688zU5Yqz2HDS6HzGHYRhELXl8PqQZPk1xED2eZVUzMm+lKS0ZlzvNEx/5QdE6gypMI7BAaWztsyuLMUorgFvRMv9ix+b7pBTJz+xn638p2MynHfGCWF0RBDMg/GGEx2BP5vTHyU5WGxJeRLQKCQggIbf/sP/K5UxtF8X4vHlDOBNIM6RQIvBX6Iz4nDuGVaZqut+yo38k9pegjXvT3svUUDM4n9yIK7yA84EucSqXwS7S+7sI4sV27CV03S3sfi0Pty1ajUcVQ7cfxcWtIesRRWn7dNG00CvMwGRNRErOVX9MFDzSyjGDR2kpHqF8wZTM5EUKKVUBax4pkPpzTIuiwrhFc0tAtpja7BoSSw4awx+fY+4CRStJch+Z60RuKjdPrVOtfnz71ZBDDfnrgsrpKNwz+1JEylFl22Aq+GvvRdLsJ2eWNvx/yyKHm+fHEXq2RB8zrKtMtAJXKhCEgiB5O7wHaM7gzcgPWxe5Kpu7Woug40vNpbdsFEiayUETL8EOOtSPrAM66ohH3VqHJ9/5yfO/HEN5FOUCmJOtmAeTaGFPD9lEOOpIhk5z4BjayIdzpzbknlS9uBCJJcAuksBKm2yIoyFSwcMZSvia5/GrwNBXgK46OrFZFWzLDehXAzLMvoBOnsYHvHBfmYjH+K5KdSDF3iyiHw1nte84YYaOjd/ckABrtRWuw9ybvVwrUpk0H8y3Kr5ouifA3Xd5Pk93P/KaNJWw/sBvzcXQAjqEi6mIERsk32oYa9p4PICOHSbnLSZ76GWPe66l4ToS+HfMuvcJd+id6MiInVPuk2gEavg+g== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1cfe445-ea23-4181-d6a3-08da2106e48a X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:31.5264 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sq0qDl6v2Inoc333tfVknt90D36X/thzUxwBhygYH/uV14k+Nz566+3YO/4xe6OGvsuXlVt9emPJMyH4xvGCIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The MBCT register allows to transfer binary INI codes from the host to the management FW by transferring it by chunks of maximum 1KB. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 122 ++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index 31a91de61537..e41451028478 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -11492,6 +11492,127 @@ mlxsw_reg_mgpir_unpack(char *payload, u8 *num_of_devices, *num_of_slots = mlxsw_reg_mgpir_num_of_slots_get(payload); } +/* MBCT - Management Binary Code Transfer Register + * ----------------------------------------------- + * This register allows to transfer binary codes from the host to + * the management FW by transferring it by chunks of maximum 1KB. + */ +#define MLXSW_REG_MBCT_ID 0x9120 +#define MLXSW_REG_MBCT_LEN 0x420 + +MLXSW_REG_DEFINE(mbct, MLXSW_REG_MBCT_ID, MLXSW_REG_MBCT_LEN); + +/* reg_mbct_slot_index + * Slot index. 0 is reserved. + * Access: Index + */ +MLXSW_ITEM32(reg, mbct, slot_index, 0x00, 0, 4); + +/* reg_mbct_data_size + * Actual data field size in bytes for the current data transfer. + * Access: WO + */ +MLXSW_ITEM32(reg, mbct, data_size, 0x04, 0, 11); + +enum mlxsw_reg_mbct_op { + MLXSW_REG_MBCT_OP_ERASE_INI_IMAGE = 1, + MLXSW_REG_MBCT_OP_DATA_TRANSFER, /* Download */ + MLXSW_REG_MBCT_OP_ACTIVATE, + MLXSW_REG_MBCT_OP_CLEAR_ERRORS = 6, + MLXSW_REG_MBCT_OP_QUERY_STATUS, +}; + +/* reg_mbct_op + * Access: WO + */ +MLXSW_ITEM32(reg, mbct, op, 0x08, 28, 4); + +/* reg_mbct_last + * Indicates that the current data field is the last chunk of the INI. + * Access: WO + */ +MLXSW_ITEM32(reg, mbct, last, 0x08, 26, 1); + +/* reg_mbct_oee + * Opcode Event Enable. When set a BCTOE event will be sent once the opcode + * was executed and the fsm_state has changed. + * Access: WO + */ +MLXSW_ITEM32(reg, mbct, oee, 0x08, 25, 1); + +enum mlxsw_reg_mbct_status { + /* Partial data transfer completed successfully and ready for next + * data transfer. + */ + MLXSW_REG_MBCT_STATUS_PART_DATA = 2, + MLXSW_REG_MBCT_STATUS_LAST_DATA, + MLXSW_REG_MBCT_STATUS_ERASE_COMPLETE, + /* Error - trying to erase INI while it being used. */ + MLXSW_REG_MBCT_STATUS_ERROR_INI_IN_USE, + /* Last data transfer completed, applying magic pattern. */ + MLXSW_REG_MBCT_STATUS_ERASE_FAILED = 7, + MLXSW_REG_MBCT_STATUS_INI_ERROR, + MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED, + MLXSW_REG_MBCT_STATUS_ILLEGAL_OPERATION = 11, +}; + +/* reg_mbct_status + * Status. + * Access: RO + */ +MLXSW_ITEM32(reg, mbct, status, 0x0C, 24, 5); + +enum mlxsw_reg_mbct_fsm_state { + MLXSW_REG_MBCT_FSM_STATE_INI_IN_USE = 5, + MLXSW_REG_MBCT_FSM_STATE_ERROR, +}; + +/* reg_mbct_fsm_state + * FSM state. + * Access: RO + */ +MLXSW_ITEM32(reg, mbct, fsm_state, 0x0C, 16, 4); + +#define MLXSW_REG_MBCT_DATA_LEN 1024 + +/* reg_mbct_data + * Up to 1KB of data. + * Access: WO + */ +MLXSW_ITEM_BUF(reg, mbct, data, 0x20, MLXSW_REG_MBCT_DATA_LEN); + +static inline void mlxsw_reg_mbct_pack(char *payload, u8 slot_index, + enum mlxsw_reg_mbct_op op, bool oee) +{ + MLXSW_REG_ZERO(mbct, payload); + mlxsw_reg_mbct_slot_index_set(payload, slot_index); + mlxsw_reg_mbct_op_set(payload, op); + mlxsw_reg_mbct_oee_set(payload, oee); +} + +static inline void mlxsw_reg_mbct_dt_pack(char *payload, + u16 data_size, bool last, + const char *data) +{ + if (WARN_ON(data_size > MLXSW_REG_MBCT_DATA_LEN)) + return; + mlxsw_reg_mbct_data_size_set(payload, data_size); + mlxsw_reg_mbct_last_set(payload, last); + mlxsw_reg_mbct_data_memcpy_to(payload, data); +} + +static inline void +mlxsw_reg_mbct_unpack(const char *payload, u8 *p_slot_index, + enum mlxsw_reg_mbct_status *p_status, + enum mlxsw_reg_mbct_fsm_state *p_fsm_state) +{ + if (p_slot_index) + *p_slot_index = mlxsw_reg_mbct_slot_index_get(payload); + *p_status = mlxsw_reg_mbct_status_get(payload); + if (p_fsm_state) + *p_fsm_state = mlxsw_reg_mbct_fsm_state_get(payload); +} + /* MDDQ - Management DownStream Device Query Register * -------------------------------------------------- * This register allows to query the DownStream device properties. The desired @@ -12990,6 +13111,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { MLXSW_REG(mtptpt), MLXSW_REG(mfgd), MLXSW_REG(mgpir), + MLXSW_REG(mbct), MLXSW_REG(mddq), MLXSW_REG(mddc), MLXSW_REG(mfde), From patchwork Mon Apr 18 06:42:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816344 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97F07C433F5 for ; Mon, 18 Apr 2022 06:45:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236879AbiDRGri (ORCPT ); Mon, 18 Apr 2022 02:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236873AbiDRGrd (ORCPT ); Mon, 18 Apr 2022 02:47:33 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2041.outbound.protection.outlook.com [40.107.100.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF9AB19031 for ; Sun, 17 Apr 2022 23:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FBAOdROPHpOjlib5BLf3L8jWvp4kHXak+8Lm0YqddXOgz6YWPiZMrKvPsHsMXq8ujPTsUfEUOKFnTP2bD49WZj2tY4vqdPgEp51DPNm9updcAKdHlMj1R9CpvevPnPowqVwT+3D8zWsLz2FjqVDkvuVgtqe19HLTnkFd+OGbn53gS3Wt4xf1rmj9bfyrnenxVwVLg76nIqEX8Om64c2Zv/i9/fQP+uAYucolh0iCnUqk+X/lWQtsjmGsc8dkxVkRO5/cpKqGH9yMSCAjr4emHT7HFwxbAyNfIRKPvibpinqaaFh3kYHX/CiXy6v0ufDWxdST3OE92RSEBFtYQZ0V7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vPK6gQnnLaSUilRa7TVuwRVsV/7jdUXqipB2ihWwcbo=; b=RBYsqERuL2Ri0OxL1PO85uGAAF2aKleS4Ca8TadBK/RvkVY6ieJzYp/wkc8qTTj3hXHXfLkCgvaGys2+xbIJnUF7KjTYdIu6zxomhwX1Y3W501HJPZnEPCNRWL4n0DXMU9cQ67Ew7Fxs9GojkAbhyqsKLDw6GDyoteopDCXRQSYDLJc+rpy3Yg/JkW/UJ/6XwCuYbxEcmoa/kv26sKrzx9dk54sjocQEfS6JdRuHLAINSX1sPhIp9TbklvlmNU7QAuN/eLknX9iSJ6EAGg74A/r5gVU4FXj4GAyq46RRusdvc1DYHrozwGygiTrOPWqggEMLmCB7F4W5NxBp/uWaxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vPK6gQnnLaSUilRa7TVuwRVsV/7jdUXqipB2ihWwcbo=; b=W/vPwQwIp2oniLfgTTYpkMAVdYRwb90izpNQwKr2Z44CASGt8P2YKT59/33LEvK7MzyZz9Mwoxfss9AHlIgPVuCptcoMBcrwziPukOAIHtUQ7qpNWxSY3ojKfie5NHpBpd6cGsNfKXdL90M9WQS9vDvx91NWTJ63eD+sWWcVhOJxUa0E8wKvjxWu5NXVbrmW+nwQNuLd7RO1BQMIQC62BbMvAnDcmea82gjo80PC8fFyqH/sNIaougPYdv4YtP63eR1w3c4AseHUIZ71uhWG/zKV+t9tLGWAxVe8ESg5WbPbPajtzTfdRKd/hGdnHdptaO7rJEbyGweFS5QEcy5aIg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:37 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:37 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 13/17] mlxsw: core_linecards: Add line card objects and implement provisioning Date: Mon, 18 Apr 2022 09:42:37 +0300 Message-Id: <20220418064241.2925668-14-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO2P265CA0090.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::30) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9499b130-37ff-4858-662d-08da2106e810 X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tyUJK6p/mihVU4lr4NOxFu45UWSHOJ2wWdhbKwrFp/o8kwlujIykK05eENqkIGsvV3zygXf/xMFJ81ati880iYxnsoZoE9mGmmE+sNiI3YgSriS6p34fjlw+Y+2Tgt96XYMjd1YXxCT7Lls/QiFQMSSZzlGMnykMnxid1PalbCKM8Zi73QUqhwEdpvTJEjTMnquOdkrDbmJhHGYitNYbju5Z4ohtmyC2JKRBrPEnEy3f0c0y1S3K9bjBhgRCtk54889Xhm5Wjc/wLKMOCY2Kb8LPwzAo45WoKkZwMjklHc0hdeBuq53Qkuo6yxSX41eaBaPveNhyGk6HE3C1tZXG+g08ufU4CfpgrPitt8LRq7rAGhEBYaEmFauYdEHdMRtFQTQAV0mPbBXWDqyF3p9UXX870OFy5cpCLu6OeTqjvJGC8rI+8GcFfLCp2FjTscQTPXH/RhNO46u0d27u2tTC79sPKnzq3ZFoeevxY5SFQ0H7VpWr7wJrQ2Ph/8uBXEFj9ezrb1FQNjs+mRDOnNmR+jfzFLCzXt30mhy7Zn1PfksYrLlKWCc2EyGX2s6/uv+JyfrPFF0Zhwn5aQwLG2UNZstTbLwgA+SB20+HXpy2N6+u79ePohoJK+vJ2mRR9yWGhCDYa1dieTzGO3183OMzvg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(30864003)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h2dMT2OU3pHAIJa2z6GS7wvfLFlrQLJxRPA3dYapA013qEi0Y/O6zXvdyxUnWt/iEB9QcoFW3nx222wp1DtURIYmjqxNtyU+66+4SZlOdre2vksJe7GYdxjRkCUt5ZjfRHwfy+5dnU/8VS8eD8z+9MVYyzb7jxjYhIn5+xI/ONSple1WC6A6r4U3pa/5wQjgjxBFdZNtwq7yGozwXYOE0xEKfJsjWoInsYhkVct2zIXojv3ac25i5L4d2BHp4gVDktj4Uyw1KVNjILU57SRdgkvYuRduzA0qZ3pEWdmBpCjbB+YJWqQD+KPZXxRMuH9+KvL6lWq/J/BlhdrT+sGSO+GNptO3gc51VKCDrho4es0fS2laL2iI0E2LeEUYxA1iFkAqahQo4TNMnVllATl7SkO+mKIf6JcC32okS+EvwPnRcYunnrj0UdIWdQZT8AXQpBLGsRmsYWcgAiFMFr0bcuoIBWmCEgcAowVOdLTsCnJa+a3b6ht7o0iwb0bXOdY8oXQelGDcWIhSyo9L/XHpJF9mpFmCFwjqOI6iAuLIh1svPqMLKYa+rpnsq6WJ5mBPRCu+sVlL8qdX0yn/c1imM13uu2qTj6BwYSEFejCM8BGxuSFdB1bMewgdYGo1bKbBTxh5m0O/urJ76pzZUXrVueC+0gvpmlrnsTodDX3gZP8kbfbyF8K2QvZaDXFhcKUb3CpjZEFYE3vkJxmiMS2FSbq/hfoCJTI3mdUejjh2WXfnd1jyPgE8xZPcAGsMYWweNS0qt9WUS16cxfkRN68CQRL8V7WEEqnmT9slhLOhh1A6dyX/GhEE0Plfp9Y6oQEUKWaUnjPiqAgWKCjyOJ9U6xgurvU2g77FQ+H+1b/OsS9ERtHalinpIOxzlUMUgY5N/eI/S3eC2PQKN+UN+jZQgeXDxPaWSwlUY0WjadElKQ0KizSRbPL5BE3oUQplU0cOR6X/alc28duX75rzZTDclEcTSN0yoXnEFOJYadhMsg2jc5NnMAenbGX/r/GW0BVwfT1AwzGCToa5W38n5C0MQ22BtFcC4h5IQFXFTc2lf1x/EQbiFMWqU6OgqKNfw/iSBL7o53njWBjHFOtJ74zpPJmAZc07v4EkIO5K5U7sOLjA0VF63RBnbbt6M6hecL3Pke+zI0Ncb3iaC+Uny5jqPYyXPp/cjMmT8oHnHXVor7whU9YN5IoC9Wuov2NqBbTkRP2V0S0Y+JVjRqe+CHawhbQEGFBgHbWc5iFmGAssrNGezYIKwviMEfrmqbp+2UYXetsKRceM4NPv3targqF1FpMB06IIVYqiOG76GL6hzymTJfrsCYgJnjnzpvf7h8SGiegq6As/Y72FR1SRZUJ9rEDz4KMMsfKwq+emTF0j51LvossLKCCzy87C9iaiW94P31Z04isbougEKMwDmY0uZNZnIyAa8eB65TNaRpSrEpPl3gLP82OhluOV2x4i6TFN9O9wGEkoufvUhJs0K+cVJgZgzvipFd7XSOD9Fi8ATKczNSm4BUZvuy6vxDSA2ED4iDW8GNu9fwp3Qm5cDP8+mB2Cx/qctpGcYD8kPEk4J+Tnqws8bK3TUc/JRfrwsxCjRCaXXsxCUt0oKa7qs8jKpWJ1Mj/8I4aGhBrQXRByfySYMCBJRFfwUdkS5/+x0/sme/izoNMjElC6L6vNXPGAPYcampBQPZTxT/xMIDThY1S42iNM04c5uYXXRbITjg+8Cc1X2QCbOSaFqgmMGqdsBw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9499b130-37ff-4858-662d-08da2106e810 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:37.6214 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /uOHf7DrR5C/MPQOt9weyHekPtWJoIpCsCfNxMdcYWOEtE8lYFw0Cw4cy2UPtuMcDZ4WIn5tmnJf9LsOvFPovA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce objects for line cards and an infrastructure around that. Use devlink_linecard_create/destroy() to register the line card with devlink core. Implement provisioning ops with a list of supported line cards. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/Makefile | 3 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 19 + drivers/net/ethernet/mellanox/mlxsw/core.h | 46 + .../ethernet/mellanox/mlxsw/core_linecards.c | 929 ++++++++++++++++++ .../net/ethernet/mellanox/mlxsw/spectrum.c | 6 + drivers/net/ethernet/mellanox/mlxsw/trap.h | 4 + 6 files changed, 1006 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/mellanox/mlxsw/core_linecards.c diff --git a/drivers/net/ethernet/mellanox/mlxsw/Makefile b/drivers/net/ethernet/mellanox/mlxsw/Makefile index 196adeb33495..1a465fd5d8b3 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/Makefile +++ b/drivers/net/ethernet/mellanox/mlxsw/Makefile @@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_MLXSW_CORE) += mlxsw_core.o mlxsw_core-objs := core.o core_acl_flex_keys.o \ - core_acl_flex_actions.o core_env.o + core_acl_flex_actions.o core_env.o \ + core_linecards.o mlxsw_core-$(CONFIG_MLXSW_CORE_HWMON) += core_hwmon.o mlxsw_core-$(CONFIG_MLXSW_CORE_THERMAL) += core_thermal.o obj-$(CONFIG_MLXSW_PCI) += mlxsw_pci.o diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index b13e0f8d232a..5e1855f752d0 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -82,6 +82,7 @@ struct mlxsw_core { struct mlxsw_res res; struct mlxsw_hwmon *hwmon; struct mlxsw_thermal *thermal; + struct mlxsw_linecards *linecards; struct mlxsw_core_port *ports; unsigned int max_ports; atomic_t active_ports_count; @@ -94,6 +95,17 @@ struct mlxsw_core { /* driver_priv has to be always the last item */ }; +struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core) +{ + return mlxsw_core->linecards; +} + +void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecards) +{ + mlxsw_core->linecards = linecards; +} + #define MLXSW_PORT_MAX_PORTS_DEFAULT 0x40 static u64 mlxsw_ports_occ_get(void *priv) @@ -2145,6 +2157,10 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, if (err) goto err_fw_rev_validate; + err = mlxsw_linecards_init(mlxsw_core, mlxsw_bus_info); + if (err) + goto err_linecards_init; + err = mlxsw_core_health_init(mlxsw_core); if (err) goto err_health_init; @@ -2183,6 +2199,8 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, err_hwmon_init: mlxsw_core_health_fini(mlxsw_core); err_health_init: + mlxsw_linecards_fini(mlxsw_core); +err_linecards_init: err_fw_rev_validate: if (!reload) mlxsw_core_params_unregister(mlxsw_core); @@ -2255,6 +2273,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core, mlxsw_thermal_fini(mlxsw_core->thermal); mlxsw_hwmon_fini(mlxsw_core->hwmon); mlxsw_core_health_fini(mlxsw_core); + mlxsw_linecards_fini(mlxsw_core); if (!reload) mlxsw_core_params_unregister(mlxsw_core); mlxsw_emad_fini(mlxsw_core); diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 16ee5e90973d..44c8a7888985 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -35,6 +35,11 @@ unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core); void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core); +struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core); + +void mlxsw_core_linecards_set(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecard); + bool mlxsw_core_fw_rev_minor_subminor_validate(const struct mlxsw_fw_rev *rev, const struct mlxsw_fw_rev *req_rev); @@ -543,4 +548,45 @@ static inline struct mlxsw_skb_cb *mlxsw_skb_cb(struct sk_buff *skb) return (struct mlxsw_skb_cb *) skb->cb; } +struct mlxsw_linecards; + +enum mlxsw_linecard_status_event_type { + MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION, + MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION, +}; + +struct mlxsw_linecard { + u8 slot_index; + struct mlxsw_linecards *linecards; + struct devlink_linecard *devlink_linecard; + struct mutex lock; /* Locks accesses to the linecard structure */ + char name[MLXSW_REG_MDDQ_SLOT_ASCII_NAME_LEN]; + char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */ + enum mlxsw_linecard_status_event_type status_event_type_to; + struct delayed_work status_event_to_dw; + u8 provisioned:1; + u16 hw_revision; + u16 ini_version; +}; + +struct mlxsw_linecard_types_info; + +struct mlxsw_linecards { + struct mlxsw_core *mlxsw_core; + const struct mlxsw_bus_info *bus_info; + u8 count; + struct mlxsw_linecard_types_info *types_info; + struct mlxsw_linecard linecards[]; +}; + +static inline struct mlxsw_linecard * +mlxsw_linecard_get(struct mlxsw_linecards *linecards, u8 slot_index) +{ + return &linecards->linecards[slot_index - 1]; +} + +int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, + const struct mlxsw_bus_info *bus_info); +void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core); + #endif diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c new file mode 100644 index 000000000000..1401f6d34635 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -0,0 +1,929 @@ +// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 +/* Copyright (c) 2022 NVIDIA Corporation and Mellanox Technologies. All rights reserved */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core.h" + +struct mlxsw_linecard_ini_file { + __le16 size; + union { + u8 data[0]; + struct { + __be16 hw_revision; + __be16 ini_version; + u8 __dontcare[3]; + u8 type; + u8 name[20]; + } format; + }; +}; + +struct mlxsw_linecard_types_info { + struct mlxsw_linecard_ini_file **ini_files; + unsigned int count; + size_t data_size; + char *data; +}; + +#define MLXSW_LINECARD_STATUS_EVENT_TO (10 * MSEC_PER_SEC) + +static void +mlxsw_linecard_status_event_to_schedule(struct mlxsw_linecard *linecard, + enum mlxsw_linecard_status_event_type status_event_type) +{ + cancel_delayed_work_sync(&linecard->status_event_to_dw); + linecard->status_event_type_to = status_event_type; + mlxsw_core_schedule_dw(&linecard->status_event_to_dw, + msecs_to_jiffies(MLXSW_LINECARD_STATUS_EVENT_TO)); +} + +static void +mlxsw_linecard_status_event_done(struct mlxsw_linecard *linecard, + enum mlxsw_linecard_status_event_type status_event_type) +{ + if (linecard->status_event_type_to == status_event_type) + cancel_delayed_work_sync(&linecard->status_event_to_dw); +} + +static const char * +mlxsw_linecard_types_lookup(struct mlxsw_linecards *linecards, u8 card_type) +{ + struct mlxsw_linecard_types_info *types_info; + struct mlxsw_linecard_ini_file *ini_file; + int i; + + types_info = linecards->types_info; + if (!types_info) + return NULL; + for (i = 0; i < types_info->count; i++) { + ini_file = linecards->types_info->ini_files[i]; + if (ini_file->format.type == card_type) + return ini_file->format.name; + } + return NULL; +} + +static const char *mlxsw_linecard_type_name(struct mlxsw_linecard *linecard) +{ + struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core; + char mddq_pl[MLXSW_REG_MDDQ_LEN]; + int err; + + mlxsw_reg_mddq_slot_name_pack(mddq_pl, linecard->slot_index); + err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mddq), mddq_pl); + if (err) + return ERR_PTR(err); + mlxsw_reg_mddq_slot_name_unpack(mddq_pl, linecard->name); + return linecard->name; +} + +static void mlxsw_linecard_provision_fail(struct mlxsw_linecard *linecard) +{ + linecard->provisioned = false; + devlink_linecard_provision_fail(linecard->devlink_linecard); +} + +static int +mlxsw_linecard_provision_set(struct mlxsw_linecard *linecard, u8 card_type, + u16 hw_revision, u16 ini_version) +{ + struct mlxsw_linecards *linecards = linecard->linecards; + const char *type; + + type = mlxsw_linecard_types_lookup(linecards, card_type); + mlxsw_linecard_status_event_done(linecard, + MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION); + if (!type) { + /* It is possible for a line card to be provisioned before + * driver initialization. Due to a missing INI bundle file + * or an outdated one, the queried card's type might not + * be recognized by the driver. In this case, try to query + * the card's name from the device. + */ + type = mlxsw_linecard_type_name(linecard); + if (IS_ERR(type)) { + mlxsw_linecard_provision_fail(linecard); + return PTR_ERR(type); + } + } + linecard->provisioned = true; + linecard->hw_revision = hw_revision; + linecard->ini_version = ini_version; + devlink_linecard_provision_set(linecard->devlink_linecard, type); + return 0; +} + +static void mlxsw_linecard_provision_clear(struct mlxsw_linecard *linecard) +{ + mlxsw_linecard_status_event_done(linecard, + MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION); + linecard->provisioned = false; + devlink_linecard_provision_clear(linecard->devlink_linecard); +} + +static int mlxsw_linecard_status_process(struct mlxsw_linecards *linecards, + struct mlxsw_linecard *linecard, + const char *mddq_pl) +{ + enum mlxsw_reg_mddq_slot_info_ready ready; + bool provisioned, sr_valid, active; + u16 ini_version, hw_revision; + u8 slot_index, card_type; + int err = 0; + + mlxsw_reg_mddq_slot_info_unpack(mddq_pl, &slot_index, &provisioned, + &sr_valid, &ready, &active, + &hw_revision, &ini_version, + &card_type); + + if (linecard) { + if (WARN_ON(slot_index != linecard->slot_index)) + return -EINVAL; + } else { + if (WARN_ON(slot_index > linecards->count)) + return -EINVAL; + linecard = mlxsw_linecard_get(linecards, slot_index); + } + + mutex_lock(&linecard->lock); + + if (provisioned && linecard->provisioned != provisioned) { + err = mlxsw_linecard_provision_set(linecard, card_type, + hw_revision, ini_version); + if (err) + goto out; + } + + if (!provisioned && linecard->provisioned != provisioned) + mlxsw_linecard_provision_clear(linecard); + +out: + mutex_unlock(&linecard->lock); + return err; +} + +static int mlxsw_linecard_status_get_and_process(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecards, + struct mlxsw_linecard *linecard) +{ + char mddq_pl[MLXSW_REG_MDDQ_LEN]; + int err; + + mlxsw_reg_mddq_slot_info_pack(mddq_pl, linecard->slot_index, false); + err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mddq), mddq_pl); + if (err) + return err; + + return mlxsw_linecard_status_process(linecards, linecard, mddq_pl); +} + +static const char * const mlxsw_linecard_status_event_type_name[] = { + [MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION] = "provision", + [MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION] = "unprovision", +}; + +static void mlxsw_linecard_status_event_to_work(struct work_struct *work) +{ + struct mlxsw_linecard *linecard = + container_of(work, struct mlxsw_linecard, + status_event_to_dw.work); + + mutex_lock(&linecard->lock); + dev_err(linecard->linecards->bus_info->dev, "linecard %u: Timeout reached waiting on %s status event", + linecard->slot_index, + mlxsw_linecard_status_event_type_name[linecard->status_event_type_to]); + mlxsw_linecard_provision_fail(linecard); + mutex_unlock(&linecard->lock); +} + +static int __mlxsw_linecard_fix_fsm_state(struct mlxsw_linecard *linecard) +{ + dev_info(linecard->linecards->bus_info->dev, "linecard %u: Clearing FSM state error", + linecard->slot_index); + mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index, + MLXSW_REG_MBCT_OP_CLEAR_ERRORS, false); + return mlxsw_reg_write(linecard->linecards->mlxsw_core, + MLXSW_REG(mbct), linecard->mbct_pl); +} + +static int mlxsw_linecard_fix_fsm_state(struct mlxsw_linecard *linecard, + enum mlxsw_reg_mbct_fsm_state fsm_state) +{ + if (fsm_state != MLXSW_REG_MBCT_FSM_STATE_ERROR) + return 0; + return __mlxsw_linecard_fix_fsm_state(linecard); +} + +static int +mlxsw_linecard_query_ini_status(struct mlxsw_linecard *linecard, + enum mlxsw_reg_mbct_status *status, + enum mlxsw_reg_mbct_fsm_state *fsm_state, + struct netlink_ext_ack *extack) +{ + int err; + + mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index, + MLXSW_REG_MBCT_OP_QUERY_STATUS, false); + err = mlxsw_reg_query(linecard->linecards->mlxsw_core, MLXSW_REG(mbct), + linecard->mbct_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to query linecard INI status"); + return err; + } + mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, status, fsm_state); + return err; +} + +static int +mlxsw_linecard_ini_transfer(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecard *linecard, + const struct mlxsw_linecard_ini_file *ini_file, + struct netlink_ext_ack *extack) +{ + enum mlxsw_reg_mbct_fsm_state fsm_state; + enum mlxsw_reg_mbct_status status; + size_t size_left; + const u8 *data; + int err; + + size_left = le16_to_cpu(ini_file->size); + data = ini_file->data; + while (size_left) { + size_t data_size = MLXSW_REG_MBCT_DATA_LEN; + bool is_last = false; + + if (size_left <= MLXSW_REG_MBCT_DATA_LEN) { + data_size = size_left; + is_last = true; + } + + mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index, + MLXSW_REG_MBCT_OP_DATA_TRANSFER, false); + mlxsw_reg_mbct_dt_pack(linecard->mbct_pl, data_size, + is_last, data); + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct), + linecard->mbct_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI data transfer"); + return err; + } + mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, + &status, &fsm_state); + if ((!is_last && status != MLXSW_REG_MBCT_STATUS_PART_DATA) || + (is_last && status != MLXSW_REG_MBCT_STATUS_LAST_DATA)) { + NL_SET_ERR_MSG_MOD(extack, "Failed to transfer linecard INI data"); + mlxsw_linecard_fix_fsm_state(linecard, fsm_state); + return -EINVAL; + } + size_left -= data_size; + data += data_size; + } + + return 0; +} + +static int +mlxsw_linecard_ini_erase(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecard *linecard, + struct netlink_ext_ack *extack) +{ + enum mlxsw_reg_mbct_fsm_state fsm_state; + enum mlxsw_reg_mbct_status status; + int err; + + mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index, + MLXSW_REG_MBCT_OP_ERASE_INI_IMAGE, false); + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct), + linecard->mbct_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI erase"); + return err; + } + mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, &status, &fsm_state); + switch (status) { + case MLXSW_REG_MBCT_STATUS_ERASE_COMPLETE: + break; + default: + /* Should not happen */ + fallthrough; + case MLXSW_REG_MBCT_STATUS_ERASE_FAILED: + NL_SET_ERR_MSG_MOD(extack, "Failed to erase linecard INI"); + goto fix_fsm_err_out; + case MLXSW_REG_MBCT_STATUS_ERROR_INI_IN_USE: + NL_SET_ERR_MSG_MOD(extack, "Failed to erase linecard INI while being used"); + goto fix_fsm_err_out; + } + return 0; + +fix_fsm_err_out: + mlxsw_linecard_fix_fsm_state(linecard, fsm_state); + return -EINVAL; +} + +static void mlxsw_linecard_bct_process(struct mlxsw_core *mlxsw_core, + const char *mbct_pl) +{ + struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core); + enum mlxsw_reg_mbct_fsm_state fsm_state; + enum mlxsw_reg_mbct_status status; + struct mlxsw_linecard *linecard; + u8 slot_index; + + mlxsw_reg_mbct_unpack(mbct_pl, &slot_index, &status, &fsm_state); + if (WARN_ON(slot_index > linecards->count)) + return; + linecard = mlxsw_linecard_get(linecards, slot_index); + mutex_lock(&linecard->lock); + if (status == MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED) { + dev_err(linecards->bus_info->dev, "linecard %u: Failed to activate INI", + linecard->slot_index); + goto fix_fsm_out; + } + mutex_unlock(&linecard->lock); + return; + +fix_fsm_out: + mlxsw_linecard_fix_fsm_state(linecard, fsm_state); + mlxsw_linecard_provision_fail(linecard); + mutex_unlock(&linecard->lock); +} + +static int +mlxsw_linecard_ini_activate(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecard *linecard, + struct netlink_ext_ack *extack) +{ + enum mlxsw_reg_mbct_fsm_state fsm_state; + enum mlxsw_reg_mbct_status status; + int err; + + mlxsw_reg_mbct_pack(linecard->mbct_pl, linecard->slot_index, + MLXSW_REG_MBCT_OP_ACTIVATE, true); + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mbct), linecard->mbct_pl); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to issue linecard INI activation"); + return err; + } + mlxsw_reg_mbct_unpack(linecard->mbct_pl, NULL, &status, &fsm_state); + if (status == MLXSW_REG_MBCT_STATUS_ACTIVATION_FAILED) { + NL_SET_ERR_MSG_MOD(extack, "Failed to activate linecard INI"); + goto fix_fsm_err_out; + } + + return 0; + +fix_fsm_err_out: + mlxsw_linecard_fix_fsm_state(linecard, fsm_state); + return -EINVAL; +} + +#define MLXSW_LINECARD_INI_WAIT_RETRIES 10 +#define MLXSW_LINECARD_INI_WAIT_MS 500 + +static int +mlxsw_linecard_ini_in_use_wait(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecard *linecard, + struct netlink_ext_ack *extack) +{ + enum mlxsw_reg_mbct_fsm_state fsm_state; + enum mlxsw_reg_mbct_status status; + unsigned int ini_wait_retries = 0; + int err; + +query_ini_status: + err = mlxsw_linecard_query_ini_status(linecard, &status, + &fsm_state, extack); + if (err) + return err; + + switch (fsm_state) { + case MLXSW_REG_MBCT_FSM_STATE_INI_IN_USE: + if (ini_wait_retries++ > MLXSW_LINECARD_INI_WAIT_RETRIES) { + NL_SET_ERR_MSG_MOD(extack, "Failed to wait for linecard INI to be unused"); + return -EINVAL; + } + mdelay(MLXSW_LINECARD_INI_WAIT_MS); + goto query_ini_status; + default: + break; + } + return 0; +} + +static int mlxsw_linecard_provision(struct devlink_linecard *devlink_linecard, + void *priv, const char *type, + const void *type_priv, + struct netlink_ext_ack *extack) +{ + const struct mlxsw_linecard_ini_file *ini_file = type_priv; + struct mlxsw_linecard *linecard = priv; + struct mlxsw_core *mlxsw_core; + int err; + + mutex_lock(&linecard->lock); + + mlxsw_core = linecard->linecards->mlxsw_core; + + err = mlxsw_linecard_ini_erase(mlxsw_core, linecard, extack); + if (err) + goto err_out; + + err = mlxsw_linecard_ini_transfer(mlxsw_core, linecard, + ini_file, extack); + if (err) + goto err_out; + + mlxsw_linecard_status_event_to_schedule(linecard, + MLXSW_LINECARD_STATUS_EVENT_TYPE_PROVISION); + err = mlxsw_linecard_ini_activate(mlxsw_core, linecard, extack); + if (err) + goto err_out; + + goto out; + +err_out: + mlxsw_linecard_provision_fail(linecard); +out: + mutex_unlock(&linecard->lock); + return err; +} + +static int mlxsw_linecard_unprovision(struct devlink_linecard *devlink_linecard, + void *priv, + struct netlink_ext_ack *extack) +{ + struct mlxsw_linecard *linecard = priv; + struct mlxsw_core *mlxsw_core; + int err; + + mutex_lock(&linecard->lock); + + mlxsw_core = linecard->linecards->mlxsw_core; + + err = mlxsw_linecard_ini_in_use_wait(mlxsw_core, linecard, extack); + if (err) + goto err_out; + + mlxsw_linecard_status_event_to_schedule(linecard, + MLXSW_LINECARD_STATUS_EVENT_TYPE_UNPROVISION); + err = mlxsw_linecard_ini_erase(mlxsw_core, linecard, extack); + if (err) + goto err_out; + + goto out; + +err_out: + mlxsw_linecard_provision_fail(linecard); +out: + mutex_unlock(&linecard->lock); + return err; +} + +static bool mlxsw_linecard_same_provision(struct devlink_linecard *devlink_linecard, + void *priv, const char *type, + const void *type_priv) +{ + const struct mlxsw_linecard_ini_file *ini_file = type_priv; + struct mlxsw_linecard *linecard = priv; + bool ret; + + mutex_lock(&linecard->lock); + ret = linecard->hw_revision == be16_to_cpu(ini_file->format.hw_revision) && + linecard->ini_version == be16_to_cpu(ini_file->format.ini_version); + mutex_unlock(&linecard->lock); + return ret; +} + +static unsigned int +mlxsw_linecard_types_count(struct devlink_linecard *devlink_linecard, + void *priv) +{ + struct mlxsw_linecard *linecard = priv; + + return linecard->linecards->types_info ? + linecard->linecards->types_info->count : 0; +} + +static void mlxsw_linecard_types_get(struct devlink_linecard *devlink_linecard, + void *priv, unsigned int index, + const char **type, const void **type_priv) +{ + struct mlxsw_linecard_types_info *types_info; + struct mlxsw_linecard_ini_file *ini_file; + struct mlxsw_linecard *linecard = priv; + + types_info = linecard->linecards->types_info; + if (WARN_ON_ONCE(!types_info)) + return; + ini_file = types_info->ini_files[index]; + *type = ini_file->format.name; + *type_priv = ini_file; +} + +static const struct devlink_linecard_ops mlxsw_linecard_ops = { + .provision = mlxsw_linecard_provision, + .unprovision = mlxsw_linecard_unprovision, + .same_provision = mlxsw_linecard_same_provision, + .types_count = mlxsw_linecard_types_count, + .types_get = mlxsw_linecard_types_get, +}; + +struct mlxsw_linecard_status_event { + struct mlxsw_core *mlxsw_core; + char mddq_pl[MLXSW_REG_MDDQ_LEN]; + struct work_struct work; +}; + +static void mlxsw_linecard_status_event_work(struct work_struct *work) +{ + struct mlxsw_linecard_status_event *event; + struct mlxsw_linecards *linecards; + struct mlxsw_core *mlxsw_core; + + event = container_of(work, struct mlxsw_linecard_status_event, work); + mlxsw_core = event->mlxsw_core; + linecards = mlxsw_core_linecards(mlxsw_core); + mlxsw_linecard_status_process(linecards, NULL, event->mddq_pl); + kfree(event); +} + +static void +mlxsw_linecard_status_listener_func(const struct mlxsw_reg_info *reg, + char *mddq_pl, void *priv) +{ + struct mlxsw_linecard_status_event *event; + struct mlxsw_core *mlxsw_core = priv; + + event = kmalloc(sizeof(*event), GFP_ATOMIC); + if (!event) + return; + event->mlxsw_core = mlxsw_core; + memcpy(event->mddq_pl, mddq_pl, sizeof(event->mddq_pl)); + INIT_WORK(&event->work, mlxsw_linecard_status_event_work); + mlxsw_core_schedule_work(&event->work); +} + +struct mlxsw_linecard_bct_event { + struct mlxsw_core *mlxsw_core; + char mbct_pl[MLXSW_REG_MBCT_LEN]; + struct work_struct work; +}; + +static void mlxsw_linecard_bct_event_work(struct work_struct *work) +{ + struct mlxsw_linecard_bct_event *event; + struct mlxsw_core *mlxsw_core; + + event = container_of(work, struct mlxsw_linecard_bct_event, work); + mlxsw_core = event->mlxsw_core; + mlxsw_linecard_bct_process(mlxsw_core, event->mbct_pl); + kfree(event); +} + +static void +mlxsw_linecard_bct_listener_func(const struct mlxsw_reg_info *reg, + char *mbct_pl, void *priv) +{ + struct mlxsw_linecard_bct_event *event; + struct mlxsw_core *mlxsw_core = priv; + + event = kmalloc(sizeof(*event), GFP_ATOMIC); + if (!event) + return; + event->mlxsw_core = mlxsw_core; + memcpy(event->mbct_pl, mbct_pl, sizeof(event->mbct_pl)); + INIT_WORK(&event->work, mlxsw_linecard_bct_event_work); + mlxsw_core_schedule_work(&event->work); +} + +static const struct mlxsw_listener mlxsw_linecard_listener[] = { + MLXSW_CORE_EVENTL(mlxsw_linecard_status_listener_func, DSDSC), + MLXSW_CORE_EVENTL(mlxsw_linecard_bct_listener_func, BCTOE), +}; + +static int mlxsw_linecard_event_delivery_set(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecard *linecard, + bool enable) +{ + char mddq_pl[MLXSW_REG_MDDQ_LEN]; + + mlxsw_reg_mddq_slot_info_pack(mddq_pl, linecard->slot_index, enable); + return mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddq), mddq_pl); +} + +static int mlxsw_linecard_init(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecards, + u8 slot_index) +{ + struct devlink_linecard *devlink_linecard; + struct mlxsw_linecard *linecard; + int err; + + linecard = mlxsw_linecard_get(linecards, slot_index); + linecard->slot_index = slot_index; + linecard->linecards = linecards; + mutex_init(&linecard->lock); + + devlink_linecard = devlink_linecard_create(priv_to_devlink(mlxsw_core), + slot_index, &mlxsw_linecard_ops, + linecard); + if (IS_ERR(devlink_linecard)) { + err = PTR_ERR(devlink_linecard); + goto err_devlink_linecard_create; + } + linecard->devlink_linecard = devlink_linecard; + INIT_DELAYED_WORK(&linecard->status_event_to_dw, + &mlxsw_linecard_status_event_to_work); + + err = mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, true); + if (err) + goto err_event_delivery_set; + + err = mlxsw_linecard_status_get_and_process(mlxsw_core, linecards, + linecard); + if (err) + goto err_status_get_and_process; + + return 0; + +err_status_get_and_process: + mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false); +err_event_delivery_set: + devlink_linecard_destroy(linecard->devlink_linecard); +err_devlink_linecard_create: + mutex_destroy(&linecard->lock); + return err; +} + +static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecards, + u8 slot_index) +{ + struct mlxsw_linecard *linecard; + + linecard = mlxsw_linecard_get(linecards, slot_index); + mlxsw_linecard_event_delivery_set(mlxsw_core, linecard, false); + cancel_delayed_work_sync(&linecard->status_event_to_dw); + /* Make sure all scheduled events are processed */ + mlxsw_core_flush_owq(); + devlink_linecard_destroy(linecard->devlink_linecard); + mutex_destroy(&linecard->lock); +} + +/* LINECARDS INI BUNDLE FILE + * +----------------------------------+ + * | MAGIC ("NVLCINI+") | + * +----------------------------------+ +--------------------+ + * | INI 0 +---> | __le16 size | + * +----------------------------------+ | __be16 hw_revision | + * | INI 1 | | __be16 ini_version | + * +----------------------------------+ | u8 __dontcare[3] | + * | ... | | u8 type | + * +----------------------------------+ | u8 name[20] | + * | INI N | | ... | + * +----------------------------------+ +--------------------+ + */ + +#define MLXSW_LINECARDS_INI_BUNDLE_MAGIC "NVLCINI+" + +static int +mlxsw_linecard_types_file_validate(struct mlxsw_linecards *linecards, + struct mlxsw_linecard_types_info *types_info) +{ + size_t magic_size = strlen(MLXSW_LINECARDS_INI_BUNDLE_MAGIC); + struct mlxsw_linecard_ini_file *ini_file; + size_t size = types_info->data_size; + const u8 *data = types_info->data; + unsigned int count = 0; + u16 ini_file_size; + + if (size < magic_size) { + dev_warn(linecards->bus_info->dev, "Invalid linecards INIs file size, smaller than magic size\n"); + return -EINVAL; + } + if (memcmp(data, MLXSW_LINECARDS_INI_BUNDLE_MAGIC, magic_size)) { + dev_warn(linecards->bus_info->dev, "Invalid linecards INIs file magic pattern\n"); + return -EINVAL; + } + + data += magic_size; + size -= magic_size; + + while (size > 0) { + if (size < sizeof(*ini_file)) { + dev_warn(linecards->bus_info->dev, "Linecards INIs file contains INI which is smaller than bare minimum\n"); + return -EINVAL; + } + ini_file = (struct mlxsw_linecard_ini_file *) data; + ini_file_size = le16_to_cpu(ini_file->size); + if (ini_file_size + sizeof(__le16) > size) { + dev_warn(linecards->bus_info->dev, "Linecards INIs file appears to be truncated\n"); + return -EINVAL; + } + if (ini_file_size % 4) { + dev_warn(linecards->bus_info->dev, "Linecards INIs file contains INI with invalid size\n"); + return -EINVAL; + } + data += ini_file_size + sizeof(__le16); + size -= ini_file_size + sizeof(__le16); + count++; + } + if (!count) { + dev_warn(linecards->bus_info->dev, "Linecards INIs file does not contain any INI\n"); + return -EINVAL; + } + types_info->count = count; + return 0; +} + +static void +mlxsw_linecard_types_file_parse(struct mlxsw_linecard_types_info *types_info) +{ + size_t magic_size = strlen(MLXSW_LINECARDS_INI_BUNDLE_MAGIC); + size_t size = types_info->data_size - magic_size; + const u8 *data = types_info->data + magic_size; + struct mlxsw_linecard_ini_file *ini_file; + unsigned int count = 0; + u16 ini_file_size; + int i; + + while (size) { + ini_file = (struct mlxsw_linecard_ini_file *) data; + ini_file_size = le16_to_cpu(ini_file->size); + for (i = 0; i < ini_file_size / 4; i++) { + u32 *val = &((u32 *) ini_file->data)[i]; + + *val = swab32(*val); + } + types_info->ini_files[count] = ini_file; + data += ini_file_size + sizeof(__le16); + size -= ini_file_size + sizeof(__le16); + count++; + } +} + +#define MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT \ + "mellanox/lc_ini_bundle_%u_%u.bin" +#define MLXSW_LINECARDS_INI_BUNDLE_FILENAME_LEN \ + (sizeof(MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT) + 4) + +static int mlxsw_linecard_types_init(struct mlxsw_core *mlxsw_core, + struct mlxsw_linecards *linecards) +{ + const struct mlxsw_fw_rev *rev = &linecards->bus_info->fw_rev; + char filename[MLXSW_LINECARDS_INI_BUNDLE_FILENAME_LEN]; + struct mlxsw_linecard_types_info *types_info; + const struct firmware *firmware; + int err; + + err = snprintf(filename, sizeof(filename), + MLXSW_LINECARDS_INI_BUNDLE_FILENAME_FMT, + rev->minor, rev->subminor); + WARN_ON(err >= sizeof(filename)); + + err = request_firmware_direct(&firmware, filename, + linecards->bus_info->dev); + if (err) { + dev_warn(linecards->bus_info->dev, "Could not request linecards INI file \"%s\", provisioning will not be possible\n", + filename); + return 0; + } + + types_info = kzalloc(sizeof(*types_info), GFP_KERNEL); + if (!types_info) { + release_firmware(firmware); + return -ENOMEM; + } + linecards->types_info = types_info; + + types_info->data_size = firmware->size; + types_info->data = vmalloc(types_info->data_size); + if (!types_info->data) { + err = -ENOMEM; + release_firmware(firmware); + goto err_data_alloc; + } + memcpy(types_info->data, firmware->data, types_info->data_size); + release_firmware(firmware); + + err = mlxsw_linecard_types_file_validate(linecards, types_info); + if (err) { + err = 0; + goto err_type_file_file_validate; + } + + types_info->ini_files = kmalloc_array(types_info->count, + sizeof(struct mlxsw_linecard_ini_file), + GFP_KERNEL); + if (!types_info->ini_files) { + err = -ENOMEM; + goto err_ini_files_alloc; + } + + mlxsw_linecard_types_file_parse(types_info); + + return 0; + +err_ini_files_alloc: +err_type_file_file_validate: + vfree(types_info->data); +err_data_alloc: + kfree(types_info); + return err; +} + +static void mlxsw_linecard_types_fini(struct mlxsw_linecards *linecards) +{ + struct mlxsw_linecard_types_info *types_info = linecards->types_info; + + if (!types_info) + return; + kfree(types_info->ini_files); + vfree(types_info->data); + kfree(types_info); +} + +int mlxsw_linecards_init(struct mlxsw_core *mlxsw_core, + const struct mlxsw_bus_info *bus_info) +{ + char mgpir_pl[MLXSW_REG_MGPIR_LEN]; + struct mlxsw_linecards *linecards; + u8 slot_count; + int err; + int i; + + mlxsw_reg_mgpir_pack(mgpir_pl, 0); + err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgpir), mgpir_pl); + if (err) + return err; + + mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, + NULL, &slot_count); + if (!slot_count) + return 0; + + linecards = vzalloc(struct_size(linecards, linecards, slot_count)); + if (!linecards) + return -ENOMEM; + linecards->count = slot_count; + linecards->mlxsw_core = mlxsw_core; + linecards->bus_info = bus_info; + + err = mlxsw_linecard_types_init(mlxsw_core, linecards); + if (err) + goto err_types_init; + + err = mlxsw_core_traps_register(mlxsw_core, mlxsw_linecard_listener, + ARRAY_SIZE(mlxsw_linecard_listener), + mlxsw_core); + if (err) + goto err_traps_register; + + mlxsw_core_linecards_set(mlxsw_core, linecards); + + for (i = 0; i < linecards->count; i++) { + err = mlxsw_linecard_init(mlxsw_core, linecards, i + 1); + if (err) + goto err_linecard_init; + } + + return 0; + +err_linecard_init: + for (i--; i >= 0; i--) + mlxsw_linecard_fini(mlxsw_core, linecards, i + 1); + mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener, + ARRAY_SIZE(mlxsw_linecard_listener), + mlxsw_core); +err_traps_register: + mlxsw_linecard_types_fini(linecards); +err_types_init: + vfree(linecards); + return err; +} + +void mlxsw_linecards_fini(struct mlxsw_core *mlxsw_core) +{ + struct mlxsw_linecards *linecards = mlxsw_core_linecards(mlxsw_core); + int i; + + if (!linecards) + return; + for (i = 0; i < linecards->count; i++) + mlxsw_linecard_fini(mlxsw_core, linecards, i + 1); + mlxsw_core_traps_unregister(mlxsw_core, mlxsw_linecard_listener, + ARRAY_SIZE(mlxsw_linecard_listener), + mlxsw_core); + mlxsw_linecard_types_fini(linecards); + vfree(linecards); +} diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index c3457a216642..b4e064bd77bc 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -89,6 +89,11 @@ static const struct mlxsw_fw_rev mlxsw_sp3_fw_rev = { "." __stringify(MLXSW_SP_FWREV_MINOR) \ "." __stringify(MLXSW_SP_FWREV_SUBMINOR) ".mfa2" +#define MLXSW_SP_LINECARDS_INI_BUNDLE_FILENAME \ + "mellanox/lc_ini_bundle_" \ + __stringify(MLXSW_SP_FWREV_MINOR) "_" \ + __stringify(MLXSW_SP_FWREV_SUBMINOR) ".bin" + static const char mlxsw_sp1_driver_name[] = "mlxsw_spectrum"; static const char mlxsw_sp2_driver_name[] = "mlxsw_spectrum2"; static const char mlxsw_sp3_driver_name[] = "mlxsw_spectrum3"; @@ -5159,3 +5164,4 @@ MODULE_DEVICE_TABLE(pci, mlxsw_sp4_pci_id_table); MODULE_FIRMWARE(MLXSW_SP1_FW_FILENAME); MODULE_FIRMWARE(MLXSW_SP2_FW_FILENAME); MODULE_FIRMWARE(MLXSW_SP3_FW_FILENAME); +MODULE_FIRMWARE(MLXSW_SP_LINECARDS_INI_BUNDLE_FILENAME); diff --git a/drivers/net/ethernet/mellanox/mlxsw/trap.h b/drivers/net/ethernet/mellanox/mlxsw/trap.h index 7405c400f09b..d888498aed33 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/trap.h +++ b/drivers/net/ethernet/mellanox/mlxsw/trap.h @@ -133,6 +133,10 @@ enum mlxsw_event_trap_id { MLXSW_TRAP_ID_PTP_ING_FIFO = 0x2D, /* PTP Egress FIFO has a new entry */ MLXSW_TRAP_ID_PTP_EGR_FIFO = 0x2E, + /* Downstream Device Status Change */ + MLXSW_TRAP_ID_DSDSC = 0x321, + /* Binary Code Transfer Operation Executed Event */ + MLXSW_TRAP_ID_BCTOE = 0x322, /* Port mapping change */ MLXSW_TRAP_ID_PMLPE = 0x32E, }; From patchwork Mon Apr 18 06:42:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816346 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7B6DC433EF for ; Mon, 18 Apr 2022 06:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236902AbiDRGry (ORCPT ); Mon, 18 Apr 2022 02:47:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236887AbiDRGrg (ORCPT ); Mon, 18 Apr 2022 02:47:36 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2041.outbound.protection.outlook.com [40.107.100.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9966319280 for ; Sun, 17 Apr 2022 23:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ik1EiDZodsQeL43zshcmBDzHhkANG3qUGXHMKAuRL+6zL2RiqiNS7CGyHNiI2a0Frdx14LNxN7FtEH0hnTHa2xOeJRM1zpx9nFUhEFJrQJsynVJqKhVEHESQxBqxDT50vM4ikWFl80GoP/JX4iIv3bOm8fzvvoZKGaDRjpo+1O9lfpqGIcQtUyBgNjFBZ3+sYS4S+ZNQLHezRAoAVRyvnLi6ngLXihhy+avHi3D7z2/mVQoEvm47VNAWjg9Y34kg6QrYKgae1wtoLNp7jHYybAI/phpzjz7StHkFbMtWGq9xES/6li0oe54ll+yJbX3j+Lt6mS3TxhGRutxjfoFe+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=P67b8rd1F3gkfaAJC9PFTkYlUCUQXdMbv6+TZ+EMAg8=; b=NPxet/loCo0XU61mpGAkIfsHUNed6BN3ZDTepPVEmzasUJynv8FosDkFUGcSO09W+m87PWQpxflALvHsgBawp+PLIafYJvXZEsulQAqE9uXzS91ddLaiiuFBAMxuL/y8/p1miZJEIOjFuRUpWNF3cKtskb4mtuO5K2qY901xuPoiaZJvxu3sx4ptjoZx94qmSrYOSZv6sewKaOMf1Go2v6i8Km+4Juwm9yrZbMRqRUyMbXd2g2vyWDe7nKqN/ew82IG2kd4X6xf8U1PtnyRFb6vSESHwGBXVjyIkS6KBNKyneKNi4BjzBG7IbU5BNxsav4YZKAvNVZzF+ZR0U7yVGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P67b8rd1F3gkfaAJC9PFTkYlUCUQXdMbv6+TZ+EMAg8=; b=ePIbP1tz6H1zGvhtxI++vHmTdcqcMZ6nsj6+e/8oJ7rKP1aL9zkwh1MrSEy6PXLT2+edmC+YspBX8/ayO32+giMW2tVlKXc+4VsOIZpMA9YaODK6vkbPVvk6xGKvYHEXxsO0ArSG9VdS23HUhTbokdzU1fnZAWr2z2epyt8nRsUefjEEfxD3G9NXLnVB5x/fgmDr3dZwZYrn1Dk29w1VGOHYwcIvGxzZ1AHI5KPkqlWrEE/H6T6eWfmLNjFC/O6+H1/SlC5/hxG4xu1j1La5DFh0oT9zF89svAW0xy99FEtJo1h2F3KtMXEkySau9qf128lH6nlMAbsYEwfWtwrx0w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:42 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:42 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 14/17] mlxsw: core_linecards: Implement line card activation process Date: Mon, 18 Apr 2022 09:42:38 +0300 Message-Id: <20220418064241.2925668-15-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0504.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::23) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ab6479e-16e8-47d7-172c-08da2106eacb X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jtk6dcRuwWR3x2ScitixX83gSymTtl1W50LIQTFJ6ie/Q9qEnIb5HGoPWxguSNkev3aEHa/jcKzyG+uf0iJuilTjw5V/ok2w89FMQ1VriOVMJknMMFw3X1O0ute+5TKui+Da0pNxF+jDaW36jORcIcrr6uX4LGjcGbM/of0/HFs2JCM384CTR60WoaHhy6XwCLBwvvQMjZOgpe4soQ+ihTbnAS0aVWhojzTyKgMU0pBC8kAA4NlSWaXEKKoVCaxvDKS3BiXgye1xywVPIHuWuDIWdKpgIQNFFizV9En3HbT9h/2tpB5Pm7tttBwxs/8zh9oUhOqnicB2KJ/Klv/5RfKVsNkL4aHT6LqqtMzJcROAqrHZ5OZCQt785DNctclEHm86B9B7cs3lMNFOmQ/6B3yyKs2g2z6QbTapN5K35azeDT5fdTZa/e3IiQNIJC4Wb2ZZn+r9V71ozxI43A4P/JNd31jroHNLXRHCrp3zg7DXkXDMgnWTAt1ZjTp0BesMv/CvR9V/L76rKdwwsCxtzcA7d5m1gRxr7YfGVBEQBuaxXh0BrXRH86KXxCdTNu8NsYBNEB6GMtI2LtPeQiG+20wySc0g+3l1ewCb7z/fQ/ffOI3jRQamNfbVHnFtWg3wJY7/BydKwKJ79pIuyTtFqQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c0B6iUTNPRacZ7QX0WMdHXVNj/KE3SP92OQZf1847B6yJ4uSvBekpHp16HRr7ZWex92DDLXoXG6T2V+X9XEaMHD6Yh0WBaMh64ToM7IVRuUU/Z7KbqAUUnQXN8u9fye5DXIjFxv3jaAWbbtvQMQaZHLUKlnkABDP/sK+NgY6Myi4C/BbKbDEjs+TI8bam/2VCdcjOH7WMB1VIaSAHmNNazTxzxRuQgmTbNuYsCi//xTvNmPdRWKNsssoOSOgBYiUwP0cWtBpolEsJ/p3JfzDGhCjUALiKHMkDYjYZ9QvuCEf53iJiE+HeEouPxIPdZxskHC1mYEHoK9/aKhGP8Sg2xIH9ybuVc5QcYvuOWl4jiZ+sXMKdjB53DUq7o7eDwKTkDTGefWLobz+jmMXr2aLW3DBLPlv4tQGcimnmBy75w0RRKN86dvyzhirx3p0kF4hkQ57KbSC4+PkFOpt5GTLxupkHjPaVHsp2sOfvk3oWy1Lx6QQ1zcYFiBvbZ7s05k2YEvU0PqsJpjL2cuw+2FY3CU8QUuO0nLENJyjnXuury1pK4JqSeTrvg2aboBkyz6yS/IOWZvq8boXt3k1fM3qV7LSlq/SAP+eg1Vu6cid38gs8TSXNtwjTgPtE7vUTCAIS9kMFSReO8sOGEQHyLI5UU6ohty1XlS+KyX+3EW2lyBZu3XeBJkF+CPaC1koL4UMTHHs2AaXAAHpx6Wz/ndxwHmVHqVm52KkEgaELSOzSo75XK3aaKVt/1yMVhMMpO0PouzIiOUgGDCya3RezlvyO1q6LNAQctV0+Hz5In9jiaXmlFw0EB7vS7edls1fyxgrfwusv+lS7BBDLIDt8v+JjzzWwMocT8UI+/3jf+fLjs7UMNZcCN3bnXo0/ys37+ptz7CySgfQxH1pFoZ8/5SS8OIPWl4rhMKvuyvnJOA5VMBXITu7c2FkMM4HQIA5B5L1U1dF2T1/xslKLQFPM5MySJ05ZzKx2RM7tz9C9yj+2dUwsO2/Rn+6N/cpxdzACmJ0dtJ1p5kOFiboSNWMdv9NII9xHHJURbgxoWnO8wn5YuiC/PLtuqhTo8VtV+wFKE01tRlmSbcyeaGOfdaNGgN+DrcKmXnJU7Fie1YyAUh/tZjO/JAxlEsDNstquO49N3uxXYcBe3tV0e/dW9TBo561PqFrr6FSVdPXHFw3cHnOcSwDtAxM6gmpu98kTQVbO/kntT1K6pxJeF6crdtLX4YIJiHdVAPgWzMmKoyIKV0LF0t5Om5Mi6aEZBwybZXRw2VTjG+TK7kxMzTcE7Hhlo/ETqw+Bt8NQnfWPrCZI5cr/6zx4c8bfdD0eQW3OMqSR8M8jhRLtj36xwG0r0L/CCeCklFmtRIOEbWvhmDVFqKfQ6IkFyIDTvYAT288l9ULRucnjLPViXHFrs6sPFv9RkFfsOPZmETtnshVs+q5lR87k/mU8xM/JOnJsptiBLmj/pz01r0BNcJzK+ZcGbYoZvQWrXx6qdV951C8ACfvWfPbJaozMgFGRKhUJnNCA5FoQ8IcrL9FMFZDuAYgR8RHkUXrp/LgVjkJaiihJlVHM3N8G07CYdV7thxG+XNtVBakO4K9ViQRTpr0yP0QFNVLKnXiwigUlRAOVRUSUFjh7IChvCobHhC8pvjIjuhSeCCyGb+GiJAC1MPdijh2pHNoD1gjYZsh5H8upb/CpSW/R8xwb3illd7tL9WXnUWizNuct/kCVSG/wdjxVnRgqyDmKbh7Tw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ab6479e-16e8-47d7-172c-08da2106eacb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:42.0801 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AxUKGuzHnvLGUgdSGowZC2tIad/nLx/g7z9/cxldESRPHELJcZsRPPS0b0z7aE92xQO7jcSZfOXd/1vIaKgdkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Allow to process events generated upon line card getting "ready" and "active". When DSDSC event with "ready" bit set is delivered, that means the line card is powered up. Use MDDC register to push the line card to active state. Once FW is done with that, the DSDSC event with "active" bit set is delivered. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.h | 4 +- .../ethernet/mellanox/mlxsw/core_linecards.c | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 44c8a7888985..7d6f8f3bcd93 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -564,7 +564,9 @@ struct mlxsw_linecard { char mbct_pl[MLXSW_REG_MBCT_LEN]; /* Too big for stack */ enum mlxsw_linecard_status_event_type status_event_type_to; struct delayed_work status_event_to_dw; - u8 provisioned:1; + u8 provisioned:1, + ready:1, + active:1; u16 hw_revision; u16 ini_version; }; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c index 1401f6d34635..49dfec14da75 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -90,6 +90,8 @@ static const char *mlxsw_linecard_type_name(struct mlxsw_linecard *linecard) static void mlxsw_linecard_provision_fail(struct mlxsw_linecard *linecard) { linecard->provisioned = false; + linecard->ready = false; + linecard->active = false; devlink_linecard_provision_fail(linecard->devlink_linecard); } @@ -131,6 +133,46 @@ static void mlxsw_linecard_provision_clear(struct mlxsw_linecard *linecard) devlink_linecard_provision_clear(linecard->devlink_linecard); } +static int mlxsw_linecard_ready_set(struct mlxsw_linecard *linecard) +{ + struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core; + char mddc_pl[MLXSW_REG_MDDC_LEN]; + int err; + + mlxsw_reg_mddc_pack(mddc_pl, linecard->slot_index, false, true); + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddc), mddc_pl); + if (err) + return err; + linecard->ready = true; + return 0; +} + +static int mlxsw_linecard_ready_clear(struct mlxsw_linecard *linecard) +{ + struct mlxsw_core *mlxsw_core = linecard->linecards->mlxsw_core; + char mddc_pl[MLXSW_REG_MDDC_LEN]; + int err; + + mlxsw_reg_mddc_pack(mddc_pl, linecard->slot_index, false, false); + err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mddc), mddc_pl); + if (err) + return err; + linecard->ready = false; + return 0; +} + +static void mlxsw_linecard_active_set(struct mlxsw_linecard *linecard) +{ + linecard->active = true; + devlink_linecard_activate(linecard->devlink_linecard); +} + +static void mlxsw_linecard_active_clear(struct mlxsw_linecard *linecard) +{ + linecard->active = false; + devlink_linecard_deactivate(linecard->devlink_linecard); +} + static int mlxsw_linecard_status_process(struct mlxsw_linecards *linecards, struct mlxsw_linecard *linecard, const char *mddq_pl) @@ -164,6 +206,25 @@ static int mlxsw_linecard_status_process(struct mlxsw_linecards *linecards, goto out; } + if (ready == MLXSW_REG_MDDQ_SLOT_INFO_READY_READY && !linecard->ready) { + err = mlxsw_linecard_ready_set(linecard); + if (err) + goto out; + } + + if (active && linecard->active != active) + mlxsw_linecard_active_set(linecard); + + if (!active && linecard->active != active) + mlxsw_linecard_active_clear(linecard); + + if (ready != MLXSW_REG_MDDQ_SLOT_INFO_READY_READY && + linecard->ready) { + err = mlxsw_linecard_ready_clear(linecard); + if (err) + goto out; + } + if (!provisioned && linecard->provisioned != provisioned) mlxsw_linecard_provision_clear(linecard); @@ -676,6 +737,8 @@ static void mlxsw_linecard_fini(struct mlxsw_core *mlxsw_core, cancel_delayed_work_sync(&linecard->status_event_to_dw); /* Make sure all scheduled events are processed */ mlxsw_core_flush_owq(); + if (linecard->active) + mlxsw_linecard_active_clear(linecard); devlink_linecard_destroy(linecard->devlink_linecard); mutex_destroy(&linecard->lock); } From patchwork Mon Apr 18 06:42:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816345 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2240CC433F5 for ; Mon, 18 Apr 2022 06:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236882AbiDRGrr (ORCPT ); Mon, 18 Apr 2022 02:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236909AbiDRGri (ORCPT ); Mon, 18 Apr 2022 02:47:38 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2084.outbound.protection.outlook.com [40.107.100.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05A82F7E for ; Sun, 17 Apr 2022 23:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LVNLlLE4ZuYTzW0h5+5fiJySC+8NYeP/OMx2OTTBm6RG302U45te7qwjLaQNwqFjF2nXPUoPhwg2iwugiDFTVQu90LBiT1FaSYLMHAEcshEWiedHC2jPqtz9ZgkjKiWz5EtIgjfkfaklC2+6+15VAfKzW/lNP/akGO/sjY0Juspcq8WCAXVfsYmhfIWENr2W2isQ6PeDNboqG5t4TqmtD+jua6mboXK6Er0RiRz06rWbg3tcVkbDSRpXAziGXxhf9JOOiGv+lg1JfYRIDMbYRMscVwrFV7MQaZoyGUHeh7f59w5VhswS1sLExky7CRAlhe1/JrvbGDd4VsuK6PqmHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=URwJtH/4Z5IJZnUGw9Q5gNo3D9G+f4qm5qCqGm6Hk9I=; b=dXliHGRxtWemZM0RYgvc1fkqrQzTU27UlR4GMnqvDpQkNKxaEOtAh90p4+59LZLmCNybMVy2X5Jzx/8mxW/p6cW2ooDFaRqbwqcnrJpMmwdV3wziuu3WZWxPZxKFaErAy7cOdz6IxB/qVOLiYsgqPSj53baRqnUFk2Zpspbux1sSj0AgdOn08K8Lp6CMfhcImixGNUC2PKn0WizpzvKilFGbIqZJYDRzQ+UN5T/wAvtvHfj4OWTZOt15j93TgtKCAziLW6Pj2ucGzhF6ch14yepq53lXyFaF4oSEmDHmROVla/L8roYEhMF2sDFx6DqWnSF6GyALnPF+OUzOFMNSLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=URwJtH/4Z5IJZnUGw9Q5gNo3D9G+f4qm5qCqGm6Hk9I=; b=doBfISZnrw0IKAjKOfnCSz8Dp1GUWCzLLVTNzKsqGktD91MhyHpDYc5QcQCEqt84KP1fBadE1Agni9eUnsRWL7KiubmfPI2e2fsNivA4xRmFBCJhtKTPiG+E3rw3qF3o7zWyOQ1ARWeGMd3gIf0OxnAeUW3XXSR+jm1bPCGW12fvxaJAmI/pk74N2ZbhZzd9ZD5wA1ubu1kG88tZNx0NC06D1SeOLiRpVjAkprOLZqF98YXEF5BWb2hTi9PKHa0hLL8waRyEIen06bT/uQx6qHhC4FLlfbz8HORN2lvYa0KY378RbCT5TcRqQduniqJARtZx0jyGuH/4IDw+7cweDA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:51 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:51 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 15/17] mlxsw: core: Extend driver ops by remove selected ports op Date: Mon, 18 Apr 2022 09:42:39 +0300 Message-Id: <20220418064241.2925668-16-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0461.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1aa::16) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb93ead8-84f6-4e4c-49c3-08da2106f09f X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pGUUSMit+Vgxa8kVXs4Vw9tetHs9UgnnCG2ll6nnmrAJyVVcjvKsZblFqmuBP3fLsXneaU/pff3xqZXMhm77eO69bc3OO9LCc51imXJ9+VL7KdeWJWj7p1soS/5wrWW4DSsRcexlPriHAltAI+FrCABF1ELi709Mc2/xi4VWf60QQA/f/t56vsh5bavOkWsHKUDZBryJ9T2w0cioV1h9T6QyTYPE1sgy4syj2FkEzGPZsFIm0J6EBjcg1gTgPM8s61cGl2RGxAXRUJqkYWwVOvFJ6rpgsOVpILQ3bg7vmtQs1ZITkZC8PMD63JKtHSpBk7joEHearj+Iftcwt4oHXtwxGHQxZyax6BMrtfMcvVhx6a4fofzHisau9DR5WW2MzF/HhMtzzZEv8VDiMQwntRYmIbTbwC+fVb2Im0NlPvkrb79xnC6RytD400FQVTteMbATV+rG+MABJsvRadvV0T1VbP++nYWXFDK6gVIIQRmYNp2u5kRrW8NY3Wpj/0z1zmIlQCnA+XP7rRzxQp6ucZ3zjG2UpmNJ19VXZNWdX1PPSrjaMwS8DjXO9g4aOpN1xENH8Q7iZR/tKSE68DEgMQuE9BGN65NbPCQOFRlzUJQPFX87TX1DMNIfnEEygfTcd69RQ5eFGziZuNiVQmYrEA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AFf9M7yafGe+Np9LaoUDTVmTJH8/Tr7ab+J/wbxre97wk5Qg7InCk0A8b9QZS2gljqPv1WmtXnbuuTuxgoHlWNrXSQmsUR0ivI+dWmS/SieBfPIpxHRoB3Nmd3rvu29yuYJ2bjOxRfDMtFVWl3W5nYSAGIIHl55R9eQOxnVCsjkghc2dGfYJWKA05hYNoLw21Qr9U3rohXxOVioN9BR8IuTFq7cpcDAQYFZvBm574W2ffRjnsesRV0BYKengqY7TjRYztoz21W0hl7BJRQYNBS17ArcPpgbKFNgAlOBGR3jvxWuBr641IabX4xHKLFk4FBsAxQoF5bjbcGrpWnTQKzpPY8zx95rbv3Ee5UQPZZDKLcLivCIsZRFka04cSiJ9/UHn0gF1RkcXmdzWdBj27af0pm6GQNzfbuxrJVuyo7TWGU7+62mgGDYu/9dw8UJ5ei6Uv/eOMJlGJSCzykcx2TKPK9sjSEVp0Q+xojjGv1jb0+Eao4VWtVNpnGTS+aUIbmhEyOAbgj7LLzb8NwRGeqT7brBMaHw66Y7+6Nfe/X8eym2jlR40aEmwL7CFkwqdsM/5oVkZj2pCBKJc88ydBvVJALNxXisCE6O2klXsM76pZBPSaczfoaeEYSBo4AvZJS/FmZMaSpi9IIQape+L2LpeflqTUm73z9ZhlCJYoFDxTNLgJxT+Jb7eJ2X2rtUOiCyrxH9Ihanbwt1Qd10uAvztOU/bv6MeEL6Iw2Ls/pwVrOwrWQYbcKBL+PDdC40UNjLR8pK2Mw2BtIxpQAtKIMyV82hC4sobpDJK7SKJJLdZFAVHOs+jv5OUzPVJ2Nk8c/bhDllU+jwbyN2FlvGPGwpIJwXONlAv6Q0pRibTP8p3/nvYZZhaXXfF11/ZufS35sSlYYB8UEnekAn6+3ZAY4ushEpY647B+uK0VjUORo9yqBoNZj3Yb2Tc947cJDSA9i6sd0QNE0NxJ0QD5X+cTx+F+Q+p6ajvxOOyQJYo1kteGXLaU548YeWhdLUJKXYhZZk344L52in+I6R3QDN6bmdStJcO8bASwQnAW2rJWJiM73R17F5a92YTTfTWvQk5eZVRHzUVsbOIZgk5V5zQd1t/FZbQ2nJz9qWAhf02vrSkLfEf5HX0Mq/ry+PIRDaZ/SnNLjRuwyOo/fb3sr/V5A65XEZ0/QZqW1FpCzllv+oxdB+1jnrYFC7w9hVy3bC5WM8hBanUhw5YrdJW8Seum6cx/tX6PXXzy4YOn1gAlXaulacTyGVWQX8yiHf2phfWuo1p9fyoQvu9rCHcS/2LOvmZcviZweXxI6pO8HT4OK0FA/dvIc2matGDCwKjAorAYeM8rK5fcLct5niWS9Eegu/NJ55Wz7uHmEKJ7cVj70HTZQmacO5DD7UPGzKmsMT22vlVU+N0xZnCY1Acv3ir7y7OFW6ou/PTl2Nzwla4QOfMAQGSYErSBBpoJqAXQJpGi6Ab1Nk9uo8ftomXuLAT3XRw38U4509rK1nnEvAskkZLAyaapOGggCGpntY0dhS2oWSYrbWtL2ZO2/zlaLopAmhmr1Ys3PW0/ip69UwGVoG1YRoOssaP1sY1BSjtcJedtHNc8XKzePJrFSeFutVC1CV9yUVmevh9ENxuARfmQc7YBpsc6lKbTL78WPl8rpczrth8MCc7mM23QjahDIxg6CQoTa2JjFvdzI9k6M7W1ZOAwG3M2lE5Pd+LTGdvH1wTM07awWv0Pud5ILbK0WHVQw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb93ead8-84f6-4e4c-49c3-08da2106f09f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:51.7931 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4fedd8rYwMKlyswlEVEdQ25q48L3JcWWGL1YW1+55W3ree7wTus98isAayvOTKkNmD4/TU8R1eWsYafSBpn7AQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In case of line card implementation, the core has to have a way to remove relevant ports manually. Extend the Spectrum driver ops by an op that implements port removal of selected ports upon request. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.c | 9 +++++++++ drivers/net/ethernet/mellanox/mlxsw/core.h | 8 ++++++++ drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 5e1855f752d0..9b5c2c60b9aa 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -3143,6 +3143,15 @@ bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port) } EXPORT_SYMBOL(mlxsw_core_port_is_xm); +void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core, + bool (*selector)(void *priv, u16 local_port), + void *priv) +{ + if (WARN_ON_ONCE(!mlxsw_core->driver->ports_remove_selected)) + return; + mlxsw_core->driver->ports_remove_selected(mlxsw_core, selector, priv); +} + struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core) { return mlxsw_core->env; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 7d6f8f3bcd93..865252e97e14 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -258,6 +258,10 @@ struct devlink_port * mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core, u16 local_port); bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port); +void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core, + bool (*selector)(void *priv, + u16 local_port), + void *priv); struct mlxsw_env *mlxsw_core_env(const struct mlxsw_core *mlxsw_core); int mlxsw_core_schedule_dw(struct delayed_work *dwork, unsigned long delay); @@ -331,6 +335,10 @@ struct mlxsw_driver { unsigned int count, struct netlink_ext_ack *extack); int (*port_unsplit)(struct mlxsw_core *mlxsw_core, u16 local_port, struct netlink_ext_ack *extack); + void (*ports_remove_selected)(struct mlxsw_core *mlxsw_core, + bool (*selector)(void *priv, + u16 local_port), + void *priv); int (*sb_pool_get)(struct mlxsw_core *mlxsw_core, unsigned int sb_index, u16 pool_index, struct devlink_sb_pool_info *pool_info); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index b4e064bd77bc..c3b9e244e888 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -1999,6 +1999,20 @@ static void mlxsw_sp_ports_remove(struct mlxsw_sp *mlxsw_sp) mlxsw_sp->ports = NULL; } +static void +mlxsw_sp_ports_remove_selected(struct mlxsw_core *mlxsw_core, + bool (*selector)(void *priv, u16 local_port), + void *priv) +{ + struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); + unsigned int max_ports = mlxsw_core_max_ports(mlxsw_core); + int i; + + for (i = 1; i < max_ports; i++) + if (mlxsw_sp_port_created(mlxsw_sp, i) && selector(priv, i)) + mlxsw_sp_port_remove(mlxsw_sp, i); +} + static int mlxsw_sp_ports_create(struct mlxsw_sp *mlxsw_sp) { unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); @@ -3785,6 +3799,7 @@ static struct mlxsw_driver mlxsw_sp2_driver = { .fini = mlxsw_sp_fini, .port_split = mlxsw_sp_port_split, .port_unsplit = mlxsw_sp_port_unsplit, + .ports_remove_selected = mlxsw_sp_ports_remove_selected, .sb_pool_get = mlxsw_sp_sb_pool_get, .sb_pool_set = mlxsw_sp_sb_pool_set, .sb_port_pool_get = mlxsw_sp_sb_port_pool_get, @@ -3822,6 +3837,7 @@ static struct mlxsw_driver mlxsw_sp3_driver = { .fini = mlxsw_sp_fini, .port_split = mlxsw_sp_port_split, .port_unsplit = mlxsw_sp_port_unsplit, + .ports_remove_selected = mlxsw_sp_ports_remove_selected, .sb_pool_get = mlxsw_sp_sb_pool_get, .sb_pool_set = mlxsw_sp_sb_pool_set, .sb_port_pool_get = mlxsw_sp_sb_port_pool_get, @@ -3857,6 +3873,7 @@ static struct mlxsw_driver mlxsw_sp4_driver = { .fini = mlxsw_sp_fini, .port_split = mlxsw_sp_port_split, .port_unsplit = mlxsw_sp_port_unsplit, + .ports_remove_selected = mlxsw_sp_ports_remove_selected, .sb_pool_get = mlxsw_sp_sb_pool_get, .sb_pool_set = mlxsw_sp_sb_pool_set, .sb_port_pool_get = mlxsw_sp_sb_port_pool_get, From patchwork Mon Apr 18 06:42:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816347 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E38E5C433F5 for ; Mon, 18 Apr 2022 06:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236860AbiDRGsJ (ORCPT ); Mon, 18 Apr 2022 02:48:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236920AbiDRGrj (ORCPT ); Mon, 18 Apr 2022 02:47:39 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2088.outbound.protection.outlook.com [40.107.100.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B528A626B for ; Sun, 17 Apr 2022 23:44:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6s23fFEyUpi7bdMMgvOdO8KxnGJcuVGKXZ9UeKcSg6JfL6LHX51IVZPprCEHwXu2OtFseYqjnLVwxUXNOh4JXSgWyFmJa1sRwFkudQxUXxhvY2vZ6Y7mg7RqHMQgAYJdHE2BJXaYeEtK5APfFVhIqEjQEw3yyRoQAJ7hK8HNSyhUvkPIlDNDpQdqfSUW4y8vqKVDlNQcUlFNL79LuYtjAhFGtsvarkl5do7kPEoDBZHBp+KchWfQ3tCyHMVDi6dN3j6aYIwFO+lYhBuSycX8v0D33DDUgYACwAtiJ9MPHv3ETgD8kIaagWjBvpUmz9k8vR4jNCJr55AO2seQ9svIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QD2Vpjey8kW5hVEJPIWkofWsKoga7dtgRTO0J12tYYs=; b=XAmRqhNKnJVCtFREpPx19E4i9u0uzaldGuUY+LdSfJ65TZ9rkgwGRmiAHsFMFydLWpIYRbVlkAJHSiyuPTYAQcw+iMbqhuztHbv6QWCChclscbhWya9ciVn5i/DxsulBI94tHDIbNkP/xCOTHgY2oxTQ5DHhUz3OxRL4re/o345uy1f3gdKR6UC8I0TYKyts/QkC0m60onDLI2aydnFbh0xAfv41PZYrnNNy7N7E1ilwpQkdCZaRDdkYtblqSZqDBu9zR6LMwEU3uzED4Eq6estUP9wAXNzl5GlqFTqQ+xlYRBpc3Zp89r/BwaAQhDWXnszNyfMQDBAqmFehRvyulQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QD2Vpjey8kW5hVEJPIWkofWsKoga7dtgRTO0J12tYYs=; b=ZX5vpndqmrmxcoMUR5n+oOLkxKNDFiR8PNZrHSgOn685gYc7ceHxeJ96anUmleE1yfVLaVEx6FET/pf+mvax+C1eYCWSPwAjPFEV7US9y+kx6/oU5OPQS9aC7pj03/JDek/Xq77VWwQaRYteLaUaPy521cmYpB4hH83aG/8ZX6duoVnGMRxaWVk0D0ShQI4uJswVYtPH7M2qBpFIF4w6GaZLnf+hvycnIshzWX+RElwGhNcIUzdpvohPxx2orrsrfeSHGeMtmENE8H5q4slXv0ugSNlv0jJF3bK7vx11uy9+QR3vyESEe8AeCz14XYgh7sFcH2r/ymQtnDjR/lmFhQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:44:56 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:44:56 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 16/17] mlxsw: spectrum: Add port to linecard mapping Date: Mon, 18 Apr 2022 09:42:40 +0300 Message-Id: <20220418064241.2925668-17-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO4P123CA0297.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:196::14) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 29d1807d-8e90-4d68-e4d9-08da2106f35d X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SxUm6kwr2z19EfkjGHNa4wWpNjezqQNUQwyWeNF8avaROZEaudveDQVxnrvVKdBlrtUwjmxx52exryoIBLi3EUqMHNZV2sWDq0KN8X3yCyOsNOmsD8bVo/uI1uuuHA+Ci29oCeHSvgd/oid+m3dhNakHcn6L23WSk6luDeMhbibaL07mqlC8+B/ZLA1smUH+Z8XvNBpAHbIcs689wqvXdKIZX5QnnWqIWv7xyNLl679rGLXu889NZFuPBlhavp+pQJMwwS/BvBe7iGobkoTGuitLV1SfllmjtG9NvLWjEwT0ZGPsHfuQEKX9Cj0gUHBapkGpz5e5Xq4qo08iMN47A74J6XvkS1SV371EIHrE35vFmTZRc0GOqS41DV9nOEGYxJTVYg/f0d3RdO1j1DYFwkaBlVmfk/5iXWM/NdA+U/a6Ap0E4VAMH3q6pnffYwudWzC7quggSoprJoGoM4rVC6d2dUduLV5kwjMyi68mOuCPu051VxjUJmfIaLG9ay4drRtfZH7DsWJe9bUHIiH+qUb2UJ//N3iRgSaqXTG5/nZannJjX3wAmkLaINnKO1DBkkUwIasqrVS2sQgv53BKXdRgsAKHRPMLjAvRrMbj/7g2r30mnnw+qBwFxO9X3qGHdbdPGhXnBXFJE0OpCj8PMg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(30864003)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V8ajz2U1TR3ISGQVA8FllO/oUR3T0JXCYH5BAwomVQVhb4v+Kste9aM/GOCVRZ7D+bCVFuEsFZsQ8NHnSorx6EHRCEsev2RmKdDWaW0anHvLLaExfdxWuReqshg9Pm+mRW//VXmJ8d6EQYYQZIAdsQaTIHXkb5C7yoA6RvzZ7kNYWaZ+qqNL+Dcff+A2+8w/heUumhg14aVIxfWU2P3jm8ViZ5wyFboeicIMb5CGZ3TdWIFxacA6yyGuG4e8itSYgsunwstIiJVT3/ZyxaQxeLXZeUpaCjorDvmdXLwQVoRCMmYza9tLKrzALG5rbMzmUKO3YzjY8fHuSlxb4UFNTlnkPOASnVQxdq+4L9dwqCE4EhJoyQMXXqfXVJBa5JwAdvb/nDWJFjb8ksxqdxlgIwRfMld5IwcnafWRfa3WEMUIZJdohCQ6NCJUJa+R+Zk5oTj9lWsneAgG2tFQ0t42MY+JTfjkirpbYXW6jRfyKoP7RjKLWvwXRBEoO7NQvEubAwqCxSSR64z/49iK2yauu0/Z4gEwyyvUitBfI8WE1k2YrXXaR0cDngQNHH3NlDIFVzlW5kNmWtV5oE9IXcupY6Qs5Jrp27rxXmKtmLGy8Ll81jfE2STPMdDd+Lbq0pIiFnp6rGnwh40ucTvo9ZbDAbOFwMONh9QIuVgG8mnySdt1pltbRcHZvgaxxqTMyGwPNa3xZBFYRQfZPKvhaWHneNEo4e+PJHJ5Tvi7BaM3T5O2SoYlZSBi+qD1Hznqr2mkcDCekur9NVoIicTjD8L/Ep+tlGYlLLEzvUoqcdwTFI2Wb8a95Nr/bWJcj1/nIDGLh4LypdIy9STsL+Zh+FQPqohnXXOe276yDTvQkRTEqSVsFWrRB5RzbIL674uLRctcdSMp5Jd1NyZOvNvyk3nOBmVc9RwWI4olKKQgLshgPpamJa3etI6eA/V1GhlXrt1Tv1ObdS/ZQUGoBY8OLsfBgssnieGU0PJGrPIDRzrXi1UieGjMTEhOHT0v4MQS5Cs93ZxjIpRg5b/8ad4IFFs3unDocUywLR2hZpsXkvt6SBRAJNywHhk+jW9yj9/DMPvjgjhVazFxyTSdvNSIOnosFfORC9T3HqNxr5OYX2aYuA+k/T2xvCxpDkP6Ss1Ik9a/rP5aLWgRnHHt0v3X88ipKVVl6bKxh0TI1b8NnMnAouqKLNTurWSGcYVkkA+rxga9uaiV9j+hth0FSr1aQmTLB44XrKnsKBililk9z5JmHckgBdRzZh4rk/MSR+H8p/S/0C19W75vHJwNYAN4JWB//+m333DUGgPQ8k8ShajyKMTw7u19TbWE/fmMZBrqhOQsX9pkUX7NH+t/TmB6lhXmzAjs0IQacSLIEEfKHc0FZr+7JuCr2mqzsYguC6UP0DO79lbKWO1dgmei3enwz30eamg7Vqi/y2sK40XOh0kERkq/Js5AFvjHKbYOceFTHBpOLNFBTmS+d7NU+rR2c+/AaXF3NK8boMGUmnca/1NZzVTUK12AXUhS2l3zq1EAeYBl3YQ1LSPQw+mGJmausuNfB0/gvPhn51EcaA+XsypO7GiSL/wABKbrq6d6JWbzgWcZzwxI1y+MGt7dqbL5FL0637lF2z7swh3GHOglvlGA5g5ssN/2+VirOTLmIbYHks+nbimVaOoqkTSzfIZAfjrr0Ho9RAyguOM476hh7LHpvJMYZKi2vzFGqhpMKrIKxfjBIA0jEox5jihUf+iKRTj4Tw== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29d1807d-8e90-4d68-e4d9-08da2106f35d X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:44:56.5070 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IdQ8up/LnV9yrGs/c+jmvMiO5m/YgdC+oIaiJqNqTb8gMUbcIAsOIFXg26hMspyLWLjRZCfSKeRed+63LEi9LQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko For each port get slot_index using PMLP register. For ports residing on a linecard, identify it with the linecard by setting mapping using devlink_port_linecard_set() helper. Use linecard slot index for PMTDB register queries. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core.c | 28 ++++++++++-- drivers/net/ethernet/mellanox/mlxsw/core.h | 6 ++- .../ethernet/mellanox/mlxsw/core_linecards.c | 13 ++++++ drivers/net/ethernet/mellanox/mlxsw/minimal.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/reg.h | 9 ++++ .../net/ethernet/mellanox/mlxsw/spectrum.c | 44 ++++++++++++++----- .../net/ethernet/mellanox/mlxsw/spectrum.h | 1 + .../mellanox/mlxsw/spectrum_ethtool.c | 37 +++++++++------- 8 files changed, 107 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 9b5c2c60b9aa..0e92dd91eca4 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -48,6 +48,7 @@ struct mlxsw_core_port { struct devlink_port devlink_port; void *port_driver_priv; u16 local_port; + struct mlxsw_linecard *linecard; }; void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port) @@ -2975,7 +2976,7 @@ EXPORT_SYMBOL(mlxsw_core_res_get); static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, enum devlink_port_flavour flavour, - u32 port_number, bool split, + u8 slot_index, u32 port_number, bool split, u32 split_port_subnumber, bool splittable, u32 lanes, const unsigned char *switch_id, @@ -2998,6 +2999,15 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, attrs.switch_id.id_len = switch_id_len; mlxsw_core_port->local_port = local_port; devlink_port_attrs_set(devlink_port, &attrs); + if (slot_index) { + struct mlxsw_linecard *linecard; + + linecard = mlxsw_linecard_get(mlxsw_core->linecards, + slot_index); + mlxsw_core_port->linecard = linecard; + devlink_port_linecard_set(devlink_port, + linecard->devlink_linecard); + } err = devl_port_register(devlink, devlink_port, local_port); if (err) memset(mlxsw_core_port, 0, sizeof(*mlxsw_core_port)); @@ -3015,7 +3025,7 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u16 local_port } int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, - u32 port_number, bool split, + u8 slot_index, u32 port_number, bool split, u32 split_port_subnumber, bool splittable, u32 lanes, const unsigned char *switch_id, @@ -3024,7 +3034,7 @@ int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, int err; err = __mlxsw_core_port_init(mlxsw_core, local_port, - DEVLINK_PORT_FLAVOUR_PHYSICAL, + DEVLINK_PORT_FLAVOUR_PHYSICAL, slot_index, port_number, split, split_port_subnumber, splittable, lanes, switch_id, switch_id_len); @@ -3055,7 +3065,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core, err = __mlxsw_core_port_init(mlxsw_core, MLXSW_PORT_CPU_PORT, DEVLINK_PORT_FLAVOUR_CPU, - 0, false, 0, false, 0, + 0, 0, false, 0, false, 0, switch_id, switch_id_len); if (err) return err; @@ -3131,6 +3141,16 @@ mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core, } EXPORT_SYMBOL(mlxsw_core_port_devlink_port_get); +struct mlxsw_linecard * +mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core, + u16 local_port) +{ + struct mlxsw_core_port *mlxsw_core_port = + &mlxsw_core->ports[local_port]; + + return mlxsw_core_port->linecard; +} + bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port) { const struct mlxsw_bus_info *bus_info = mlxsw_core->bus_info; diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.h b/drivers/net/ethernet/mellanox/mlxsw/core.h index 865252e97e14..850fff51b79f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.h +++ b/drivers/net/ethernet/mellanox/mlxsw/core.h @@ -236,7 +236,8 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core, void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port); int mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u16 local_port, - u32 port_number, bool split, u32 split_port_subnumber, + u8 slot_index, u32 port_number, bool split, + u32 split_port_subnumber, bool splittable, u32 lanes, const unsigned char *switch_id, unsigned char switch_id_len); @@ -257,6 +258,9 @@ enum devlink_port_type mlxsw_core_port_type_get(struct mlxsw_core *mlxsw_core, struct devlink_port * mlxsw_core_port_devlink_port_get(struct mlxsw_core *mlxsw_core, u16 local_port); +struct mlxsw_linecard * +mlxsw_core_port_linecard_get(struct mlxsw_core *mlxsw_core, + u16 local_port); bool mlxsw_core_port_is_xm(const struct mlxsw_core *mlxsw_core, u16 local_port); void mlxsw_core_ports_remove_selected(struct mlxsw_core *mlxsw_core, bool (*selector)(void *priv, diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c index 49dfec14da75..1d50bfe67156 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecards.c @@ -481,6 +481,15 @@ mlxsw_linecard_ini_in_use_wait(struct mlxsw_core *mlxsw_core, return 0; } +static bool mlxsw_linecard_port_selector(void *priv, u16 local_port) +{ + struct mlxsw_linecard *linecard = priv; + struct mlxsw_core *mlxsw_core; + + mlxsw_core = linecard->linecards->mlxsw_core; + return linecard == mlxsw_core_port_linecard_get(mlxsw_core, local_port); +} + static int mlxsw_linecard_provision(struct devlink_linecard *devlink_linecard, void *priv, const char *type, const void *type_priv, @@ -531,6 +540,10 @@ static int mlxsw_linecard_unprovision(struct devlink_linecard *devlink_linecard, mlxsw_core = linecard->linecards->mlxsw_core; + mlxsw_core_ports_remove_selected(mlxsw_core, + mlxsw_linecard_port_selector, + linecard); + err = mlxsw_linecard_ini_in_use_wait(mlxsw_core, linecard, extack); if (err) goto err_out; diff --git a/drivers/net/ethernet/mellanox/mlxsw/minimal.c b/drivers/net/ethernet/mellanox/mlxsw/minimal.c index ee1cb1b81669..d9660d4cce96 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/minimal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/minimal.c @@ -223,7 +223,7 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 module) struct net_device *dev; int err; - err = mlxsw_core_port_init(mlxsw_m->core, local_port, + err = mlxsw_core_port_init(mlxsw_m->core, local_port, 0, module + 1, false, 0, false, 0, mlxsw_m->base_mac, sizeof(mlxsw_m->base_mac)); diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index e41451028478..23589d3b160a 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -4325,6 +4325,15 @@ MLXSW_ITEM32(reg, pmlp, width, 0x00, 0, 8); */ MLXSW_ITEM32_INDEXED(reg, pmlp, module, 0x04, 0, 8, 0x04, 0x00, false); +/* reg_pmlp_slot_index + * Module number. + * Slot_index + * Slot_index = 0 represent the onboard (motherboard). + * In case of non-modular system only slot_index = 0 is available. + * Access: RW + */ +MLXSW_ITEM32_INDEXED(reg, pmlp, slot_index, 0x04, 8, 4, 0x04, 0x00, false); + /* reg_pmlp_tx_lane * Tx Lane. When rxtx field is cleared, this field is used for Rx as well. * Access: RW diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index c3b9e244e888..ac6348e2ff1f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -492,11 +492,13 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp, { bool separate_rxtx; u8 first_lane; + u8 slot_index; u8 module; u8 width; int i; module = mlxsw_reg_pmlp_module_get(pmlp_pl, 0); + slot_index = mlxsw_reg_pmlp_slot_index_get(pmlp_pl, 0); width = mlxsw_reg_pmlp_width_get(pmlp_pl); separate_rxtx = mlxsw_reg_pmlp_rxtx_get(pmlp_pl); first_lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0); @@ -513,6 +515,11 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp, local_port); return -EINVAL; } + if (mlxsw_reg_pmlp_slot_index_get(pmlp_pl, i) != slot_index) { + dev_err(mlxsw_sp->bus_info->dev, "Port %d: Unsupported module config: contains multiple slot indexes\n", + local_port); + return -EINVAL; + } if (separate_rxtx && mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, i) != mlxsw_reg_pmlp_rx_lane_get(pmlp_pl, i)) { @@ -528,6 +535,7 @@ mlxsw_sp_port_module_info_parse(struct mlxsw_sp *mlxsw_sp, } port_mapping->module = module; + port_mapping->slot_index = slot_index; port_mapping->width = width; port_mapping->module_width = width; port_mapping->lane = mlxsw_reg_pmlp_tx_lane_get(pmlp_pl, 0); @@ -556,11 +564,14 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port, char pmlp_pl[MLXSW_REG_PMLP_LEN]; int i, err; - mlxsw_env_module_port_map(mlxsw_sp->core, 0, port_mapping->module); + mlxsw_env_module_port_map(mlxsw_sp->core, port_mapping->slot_index, + port_mapping->module); mlxsw_reg_pmlp_pack(pmlp_pl, local_port); mlxsw_reg_pmlp_width_set(pmlp_pl, port_mapping->width); for (i = 0; i < port_mapping->width; i++) { + mlxsw_reg_pmlp_slot_index_set(pmlp_pl, i, + port_mapping->slot_index); mlxsw_reg_pmlp_module_set(pmlp_pl, i, port_mapping->module); mlxsw_reg_pmlp_tx_lane_set(pmlp_pl, i, port_mapping->lane + i); /* Rx & Tx */ } @@ -571,7 +582,8 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port, return 0; err_pmlp_write: - mlxsw_env_module_port_unmap(mlxsw_sp->core, 0, port_mapping->module); + mlxsw_env_module_port_unmap(mlxsw_sp->core, port_mapping->slot_index, + port_mapping->module); return err; } @@ -592,7 +604,8 @@ static int mlxsw_sp_port_open(struct net_device *dev) struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; int err; - err = mlxsw_env_module_port_up(mlxsw_sp->core, 0, + err = mlxsw_env_module_port_up(mlxsw_sp->core, + mlxsw_sp_port->mapping.slot_index, mlxsw_sp_port->mapping.module); if (err) return err; @@ -603,7 +616,8 @@ static int mlxsw_sp_port_open(struct net_device *dev) return 0; err_port_admin_status_set: - mlxsw_env_module_port_down(mlxsw_sp->core, 0, + mlxsw_env_module_port_down(mlxsw_sp->core, + mlxsw_sp_port->mapping.slot_index, mlxsw_sp_port->mapping.module); return err; } @@ -615,7 +629,8 @@ static int mlxsw_sp_port_stop(struct net_device *dev) netif_stop_queue(dev); mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false); - mlxsw_env_module_port_down(mlxsw_sp->core, 0, + mlxsw_env_module_port_down(mlxsw_sp->core, + mlxsw_sp_port->mapping.slot_index, mlxsw_sp_port->mapping.module); return 0; } @@ -1462,12 +1477,13 @@ static int mlxsw_sp_port_tc_mc_mode_set(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_port_overheat_init_val_set(struct mlxsw_sp_port *mlxsw_sp_port) { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; u64 overheat_counter; int err; - err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, 0, module, - &overheat_counter); + err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, slot_index, + module, &overheat_counter); if (err) return err; @@ -1542,7 +1558,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port, } splittable = lanes > 1 && !split; - err = mlxsw_core_port_init(mlxsw_sp->core, local_port, + err = mlxsw_core_port_init(mlxsw_sp->core, local_port, slot_index, port_number, split, split_port_subnumber, splittable, lanes, mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac)); @@ -1792,7 +1808,8 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port, mlxsw_sp_port_swid_set(mlxsw_sp, local_port, MLXSW_PORT_SWID_DISABLED_PORT); err_port_swid_set: - mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0, + mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, + port_mapping->slot_index, port_mapping->module); return err; } @@ -1800,6 +1817,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port, static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port) { struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port]; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; cancel_delayed_work_sync(&mlxsw_sp_port->periodic_hw_stats.update_dw); @@ -1822,7 +1840,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port) mlxsw_core_port_fini(mlxsw_sp->core, local_port); mlxsw_sp_port_swid_set(mlxsw_sp, local_port, MLXSW_PORT_SWID_DISABLED_PORT); - mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0, module); + mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, slot_index, module); } static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp) @@ -2194,7 +2212,8 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u16 local_port, return -EINVAL; } - mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module, + mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index, + mlxsw_sp_port->mapping.module, mlxsw_sp_port->mapping.module_width / count, count); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl); @@ -2259,7 +2278,8 @@ static int mlxsw_sp_port_unsplit(struct mlxsw_core *mlxsw_core, u16 local_port, count = mlxsw_sp_port->mapping.module_width / mlxsw_sp_port->mapping.width; - mlxsw_reg_pmtdb_pack(pmtdb_pl, 0, mlxsw_sp_port->mapping.module, + mlxsw_reg_pmtdb_pack(pmtdb_pl, mlxsw_sp_port->mapping.slot_index, + mlxsw_sp_port->mapping.module, mlxsw_sp_port->mapping.module_width / count, count); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtdb), pmtdb_pl); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index 928c3a63b6b6..2ad29ae1c640 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -145,6 +145,7 @@ struct mlxsw_sp_mall_entry; struct mlxsw_sp_port_mapping { u8 module; + u8 slot_index; u8 width; /* Number of lanes used by the port */ u8 module_width; /* Number of lanes in the module (static) */ u8 lane; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c index f72c26ce0391..915dffb85a1c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_ethtool.c @@ -568,14 +568,14 @@ struct mlxsw_sp_port_stats { static u64 mlxsw_sp_port_get_transceiver_overheat_stats(struct mlxsw_sp_port *mlxsw_sp_port) { - struct mlxsw_sp_port_mapping port_mapping = mlxsw_sp_port->mapping; struct mlxsw_core *mlxsw_core = mlxsw_sp_port->mlxsw_sp->core; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; + u8 module = mlxsw_sp_port->mapping.module; u64 stats; int err; - err = mlxsw_env_module_overheat_counter_get(mlxsw_core, 0, - port_mapping.module, - &stats); + err = mlxsw_env_module_overheat_counter_get(mlxsw_core, slot_index, + module, &stats); if (err) return mlxsw_sp_port->module_overheat_initial_val; @@ -1035,7 +1035,8 @@ static int mlxsw_sp_get_module_info(struct net_device *netdev, struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; - return mlxsw_env_get_module_info(netdev, mlxsw_sp->core, 0, + return mlxsw_env_get_module_info(netdev, mlxsw_sp->core, + mlxsw_sp_port->mapping.slot_index, mlxsw_sp_port->mapping.module, modinfo); } @@ -1045,10 +1046,11 @@ static int mlxsw_sp_get_module_eeprom(struct net_device *netdev, { struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; + u8 module = mlxsw_sp_port->mapping.module; - return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, 0, - mlxsw_sp_port->mapping.module, ee, - data); + return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, slot_index, + module, ee, data); } static int @@ -1058,10 +1060,11 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev, { struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; - return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, 0, module, - page, extack); + return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, slot_index, + module, page, extack); } static int @@ -1202,9 +1205,11 @@ static int mlxsw_sp_reset(struct net_device *dev, u32 *flags) { struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; - return mlxsw_env_reset_module(dev, mlxsw_sp->core, 0, module, flags); + return mlxsw_env_reset_module(dev, mlxsw_sp->core, slot_index, + module, flags); } static int @@ -1214,10 +1219,11 @@ mlxsw_sp_get_module_power_mode(struct net_device *dev, { struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; - return mlxsw_env_get_module_power_mode(mlxsw_sp->core, 0, module, - params, extack); + return mlxsw_env_get_module_power_mode(mlxsw_sp->core, slot_index, + module, params, extack); } static int @@ -1227,10 +1233,11 @@ mlxsw_sp_set_module_power_mode(struct net_device *dev, { struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev); struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; + u8 slot_index = mlxsw_sp_port->mapping.slot_index; u8 module = mlxsw_sp_port->mapping.module; - return mlxsw_env_set_module_power_mode(mlxsw_sp->core, 0, module, - params->policy, extack); + return mlxsw_env_set_module_power_mode(mlxsw_sp->core, slot_index, + module, params->policy, extack); } const struct ethtool_ops mlxsw_sp_port_ethtool_ops = { From patchwork Mon Apr 18 06:42:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12816348 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 481EDC433FE for ; Mon, 18 Apr 2022 06:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236863AbiDRGsK (ORCPT ); Mon, 18 Apr 2022 02:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236872AbiDRGrn (ORCPT ); Mon, 18 Apr 2022 02:47:43 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08on2062.outbound.protection.outlook.com [40.107.100.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642B2D9B for ; Sun, 17 Apr 2022 23:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f+fQHbNR9wdBDsMz9NvzJsYRDkKkGuOergYDB4ck5Z5m2Gg+krOugfZU3ZKAF8smxVpRlTA6jLUDxPBq2+1TQozXot5hJBbxiFElmhEkyzkC50urtaTeRFR94C8c+ultOhNflk4OiQtCmAf1Qm6opj8lHpjqlDJpjQ8mrnLRcCZuM3RvK9lxdSsQ9uTOUP4YqKj1SQKcLTmwOgt3ziIEunrn1PlWe8lqJzJceolIYN4K6zijt+yErDORUYYB//7KsdF2RWHf6g2yTx9KV32ILbChkvgR9H2fZJbFwZg1gAslGxabrpwhZsfodIElcbUzs5gXqmXt1c8oVMwh2G0IwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YNdCEC5WT4nq+xlbrZyPjJDXEKYwHE6ODAqUvLi0WSo=; b=Vv0xgI8tjVos4qxCpttc4/MoDpApk3m3qjlsG1B/FdDC6WiED5dmvcXQmh93/tnTviAXRTXrxJotkNVCkPVyln2sQi3Bvw+Fn97VYdT3EotmtundZfGXO8BsBdcLRan7OdGYXhA74ufPqgBfYPrUb2Kp1zyNeAU2QJ56PztHGdJmsMslS4ytKjO4Vavx5ZErdpl7BT4O0/xJiiurE3/OR4T0Xb6WLhbbM2ZSZKpkC3TCZ6nb83WG/dNUCFVHRRZ/QiTYX3xgYCmCuWtVxnN6h5ykdMjVYc/YkJmtqmgfdkq+FmBI3jHMLYxf5NYG4hpzkYc1Bmw6UKZ4CQ4UzURCGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YNdCEC5WT4nq+xlbrZyPjJDXEKYwHE6ODAqUvLi0WSo=; b=Dyqz2TyPer8DnB540NV9xz478YFjT+g5Vx5XhNna7BoMLITY3yIcACAZgFruzhF44T180ml+nIXCoqMgmZS2Li0n/FZ/M1kwa+1+UyDDpG/o6Ki41qo864cQoo9szbXj/+HTzcM/+8X6MYI7DsPoLh1xS5U+R/sjcsmCb/vTwXHJFrs1ZK698g85ILZoLuIbcNM/mwHN4dzoVMHGN28plcJ2WLzJ+xoVtIMflwNIYfjQSvwJFw4l+rdA8sL1E04jZnDcApY4L6xn/gJhk3MtY/otjfXnfJBQ8F6RrOcNn3LLsnaX9A0Vf9wiMAHLaXqxEzkFKnRaeslVRgDMS2rN3A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3664.namprd12.prod.outlook.com (2603:10b6:208:159::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Mon, 18 Apr 2022 06:45:02 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::6131:18cc:19ae:2402%6]) with mapi id 15.20.5164.025; Mon, 18 Apr 2022 06:45:02 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jiri@nvidia.com, vadimp@nvidia.com, petrm@nvidia.com, andrew@lunn.ch, dsahern@gmail.com, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next 17/17] selftests: mlxsw: Introduce devlink line card provision/unprovision/activation tests Date: Mon, 18 Apr 2022 09:42:41 +0300 Message-Id: <20220418064241.2925668-18-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220418064241.2925668-1-idosch@nvidia.com> References: <20220418064241.2925668-1-idosch@nvidia.com> X-ClientProxiedBy: LO2P265CA0401.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:f::29) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 18a48747-6693-45c8-19a0-08da2106f6ef X-MS-TrafficTypeDiagnostic: MN2PR12MB3664:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p3bAD5xwVWIQWJ8bhSwvbhHT+GKTlueD3lo2mGC92ZjFVtSMNKD2hmsx4vtLenVadXCfY8czsVzLhHBKV6pSVOHmh4UfVGnOFON0nDxfGYVoyRnvMbczI6Gdm2GgMa9Lxue6bhH92c6KWW5C089nUIri5hxrmwJt7XVONkWFoOdOT+2ZTlnMjRQ72cKVboCGTUgzOl5qVIxkY94xyTqIZQaEeQb7OoZ5KeE/SZxvO3NVqIy+VaZKR4Ure9cq2U5ZVhvUMZhz2UR715mI8RT7qcRz9XhYNpmIEOf5kGGmqMj8DUlynY+qFpO2gwx9wO7UeTr3X9hLlBklknoiNZH61y5ievsbe+gBOAbUhjRRWQtMTdg72eZdzMH2hbhxTFCG3r4B9BJxg08abesitVqvlBpOBv19SQ24XYOhEUgIrAp/Ic9AMyXhMnC57Wa51S8xyuOncPURvFn+3e/YN3iZz8O0QMmJeNqm2BdNE3h3xpp0Nbi2DpTortbEXXTYmIAAoAIxLZcf5B1+IL5rx+1PwnTkl805fYfxrn/6v51BbOajcbiRqs9aYdY5Vjf0xmleUXoGzvcGZ/SDy5F/LZ2EJE7Gc966PesdT2432v6Li9n0Se+NJA1G4Z2t6pcq+k3cozZcN8iHvVHBllQwmk2YGg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(107886003)(66556008)(316002)(4326008)(8676002)(508600001)(8936002)(6486002)(66476007)(5660300002)(6512007)(186003)(66946007)(38100700002)(86362001)(26005)(83380400001)(36756003)(2616005)(6666004)(2906002)(6916009)(6506007)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +r0za6YE/Fe8iSwNZQh2mvqgfttZtFHjFR+1gmp4eL7hPHLFOkYpom0MLGhngCFYJWlkGU+UihACe6pZkxUasIZSMquI89PlLzEJG6ZYX5xeF+YVqq+EydTmhN0h79Ok2Ho32PtRPQY/8asK4iOtx9M5cmMLEWDmwU2q0X9BMSncMHLcLYSeZgUofvvSMAB5B65bx3b+pY6nEuCrZM3bkSk0CIPMWJi+piGBrPfRBvESpTsW5PYwPfrkv4XiFWSXX3yk4ImnmxpWfQzLbKjoCo2uPN8GVkYkjiEivVozlXcXTL+Q+5SWjjau1a860DXcNte7fKyz1AVQqUOXTfZgy8PtZ/mId2YmgFjFyhD86wjLoLTVWdESsFAzIMzmeFNYFB1k0usTRSM/9gDYL40KVmbNOitfl5y6gxd78v++7KO55SZVb7pSH8O9bN1i5khFFP3gq1lYjVuI1S0T3JDuzPzftPiwAiLVaopXuhQrPJVxqK5tTqCa0M0WF3gyzvMHqnjnbTuCdwdWK/YFIPqdz3mEeD868t9IjQ1VuKSjJdmwbhZdKFXgnv+MfMVY1V+tGsbiW3bhP2jgfN5VgfG32D0TipBi4DejzoYgoE7t82YiTip+MbUUBlkxkEkato5x62TmQsFYOE/dLzTP4XDG149al/WG6iMgFTxQaWKBQNvDyDsaqeDWfCVVpZDX+j7pLzP09aiW9jBBvgTUK7Hr3qZzIInE9zw2e9zATHxRgBfx1Q6aqH2+RrsCXNitK2Z/FFbuqY4N9BHSJUoLcvDSRL87BMqvIiQiei9abiIqea3JlDAwk3OaAGXrcWEGnd75oTEUUXxlYYCnxOKSJWGNpqOPkyD0N1Es7H81ADlVE8xnkigNhhEnv8gHWRaJ0g1XkAUFE2UAeqAa24nS0PnuXXu8nWyUsPlN0EES+Ic6xwGlFPOWsZl8Gl/XbTeDJlRzXYTK5J/J21A+VL3rQzqCL+sL99+IsQbQHhm43LLefcK4oZQRmMv5GmW77yVPgfdAlgDNP1MNUBc3HqIYswePnU+j9XcpyWhBDXoA3ZFPzLtZ8beOsGd4O5lIUkeFyWmS6755278FbOCpP8WRcCYjPwI4rdmW/VIbxDBCtCV/VJkigdu2MJBIGSo4JnzHWeLxFR33iXmrRyjoIGoCRHXnBohC7ZbTcYez+F6ntg02Kt6r0Fn2aIryJlTyLydqC03sh6gCtLkRfpMe8Wr/BTVm8OCsOVxNG4FJC27G8zCMjDFj6nVRQnDD8Dw9GXmnPxukWCEhNoDXUW0datbAIo99oUwrrkSFY+6WJACxpf8mO/Eehx9l5iXB/GqwL6UA0kiZZAb38jT1RiL0EggUc+/v4UigqXN9WJDJ8tKtADiNFdx/gYbt3DFm5UkdLaMQj5s6WsH+BhqaNASdLIw0Inud569Psr+0MLlNLryry4XYvKv9byr2R7kf/oGB8sLTdo2Dn/TQ/buHj89AJ0d6a1BNVZlQQnvHBps9jzJT9NHlOPj9dR5CP/4rF4tIpCxQE/v1dGHv+hGAir2SPXjqjY8C3o+bqsTGx0q/LxThlm6SI+UvhTiRARot+n54NNmlLUMTTBbM5/X5OSqX5AtcKDzfBq+9mnjlYiODDsshYyROaJ1NrHwmgCmDhqp08JUR4JATNb+aj/2Yp6hxf20XUEMR0LMtVh9Wy5ifdSbw56sddX5VOYH+nJYM5fzCfQ/AQcEWLV4Ow/qTPif5ehYLbKLuwA== X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18a48747-6693-45c8-19a0-08da2106f6ef X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2022 06:45:02.4762 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 59R7MfaeJyzt/R+WqrkA7pkX4+T+bltEGbJy7prIFBsPf0xos65+sU/egb1ZUev4i9scb4mc+3/W4aPJlSpggw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3664 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce basic line card manipulation which consists of provisioning, unprovisioning and activation of a line card. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../drivers/net/mlxsw/devlink_linecard.sh | 280 ++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100755 tools/testing/selftests/drivers/net/mlxsw/devlink_linecard.sh diff --git a/tools/testing/selftests/drivers/net/mlxsw/devlink_linecard.sh b/tools/testing/selftests/drivers/net/mlxsw/devlink_linecard.sh new file mode 100755 index 000000000000..08a922d8b86a --- /dev/null +++ b/tools/testing/selftests/drivers/net/mlxsw/devlink_linecard.sh @@ -0,0 +1,280 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# In addition to the common variables, user might use: +# LC_SLOT - If not set, all probed line cards are going to be tested, +# with an exception of the "activation_16x100G_test". +# It set, only the selected line card is going to be used +# for tests, including "activation_16x100G_test". + +lib_dir=$(dirname $0)/../../../net/forwarding + +ALL_TESTS=" + unprovision_test + provision_test + activation_16x100G_test +" + +NUM_NETIFS=0 + +source $lib_dir/lib.sh +source $lib_dir/devlink_lib.sh + +until_lc_state_is() +{ + local state=$1; shift + local current=$("$@") + + echo "$current" + [ "$current" == "$state" ] +} + +until_lc_state_is_not() +{ + ! until_lc_state_is "$@" +} + +lc_state_get() +{ + local lc=$1 + + devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state" +} + +lc_wait_until_state_changes() +{ + local lc=$1 + local state=$2 + local timeout=$3 # ms + + busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc" +} + +lc_wait_until_state_becomes() +{ + local lc=$1 + local state=$2 + local timeout=$3 # ms + + busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc" +} + +until_lc_port_count_is() +{ + local port_count=$1; shift + local current=$("$@") + + echo "$current" + [ $current == $port_count ] +} + +lc_port_count_get() +{ + local lc=$1 + + devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l +} + +lc_wait_until_port_count_is() +{ + local lc=$1 + local port_count=$2 + local timeout=$3 # ms + + busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc" +} + +PROV_UNPROV_TIMEOUT=8000 # ms +POST_PROV_ACT_TIMEOUT=2000 # ms +PROV_PORTS_INSTANTIATION_TIMEOUT=15000 # ms + +unprovision_one() +{ + local lc=$1 + local state + + state=$(lc_state_get $lc) + check_err $? "Failed to get state of linecard $lc" + if [[ "$state" == "unprovisioned" ]]; then + return + fi + + log_info "Unprovisioning linecard $lc" + + devlink lc set $DEVLINK_DEV lc $lc notype + check_err $? "Failed to trigger linecard $lc unprovisioning" + + state=$(lc_wait_until_state_changes $lc "unprovisioning" \ + $PROV_UNPROV_TIMEOUT) + check_err $? "Failed to unprovision linecard $lc (timeout)" + + [ "$state" == "unprovisioned" ] + check_err $? "Failed to unprovision linecard $lc (state=$state)" +} + +provision_one() +{ + local lc=$1 + local type=$2 + local state + + log_info "Provisioning linecard $lc" + + devlink lc set $DEVLINK_DEV lc $lc type $type + check_err $? "Failed trigger linecard $lc provisioning" + + state=$(lc_wait_until_state_changes $lc "provisioning" \ + $PROV_UNPROV_TIMEOUT) + check_err $? "Failed to provision linecard $lc (timeout)" + + [ "$state" == "provisioned" ] || [ "$state" == "active" ] + check_err $? "Failed to provision linecard $lc (state=$state)" + + provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type") + [ "$provisioned_type" == "$type" ] + check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")" + + # Wait for possible activation to make sure the state + # won't change after return from this function. + state=$(lc_wait_until_state_becomes $lc "active" \ + $POST_PROV_ACT_TIMEOUT) +} + +unprovision_test() +{ + RET=0 + local lc + + lc=$LC_SLOT + unprovision_one $lc + log_test "Unprovision" +} + +LC_16X100G_TYPE="16x100G" +LC_16X100G_PORT_COUNT=16 + +supported_types_check() +{ + local lc=$1 + local supported_types_count + local type_index + local lc_16x100_found=false + + supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \ + jq -e -r ".[][][].supported_types | length") + [ $supported_types_count != 0 ] + check_err $? "No supported types found for linecard $lc" + for (( type_index=0; type_index<$supported_types_count; type_index++ )) + do + type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \ + jq -e -r ".[][][].supported_types[$type_index]") + if [[ "$type" == "$LC_16X100G_TYPE" ]]; then + lc_16x100_found=true + break + fi + done + [ $lc_16x100_found = true ] + check_err $? "16X100G not found between supported types of linecard $lc" +} + +ports_check() +{ + local lc=$1 + local expected_port_count=$2 + local port_count + + port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \ + $PROV_PORTS_INSTANTIATION_TIMEOUT) + [ $port_count != 0 ] + check_err $? "No port associated with linecard $lc" + [ $port_count == $expected_port_count ] + check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)" +} + +provision_test() +{ + RET=0 + local lc + local type + local state + + lc=$LC_SLOT + supported_types_check $lc + state=$(lc_state_get $lc) + check_err $? "Failed to get state of linecard $lc" + if [[ "$state" != "unprovisioned" ]]; then + unprovision_one $lc + fi + provision_one $lc $LC_16X100G_TYPE + ports_check $lc $LC_16X100G_PORT_COUNT + log_test "Provision" +} + +ACTIVATION_TIMEOUT=20000 # ms + +interface_check() +{ + ip link set $h1 up + ip link set $h2 up + ifaces_upped=true + setup_wait +} + +activation_16x100G_test() +{ + RET=0 + local lc + local type + local state + + lc=$LC_SLOT + type=$LC_16X100G_TYPE + + unprovision_one $lc + provision_one $lc $type + state=$(lc_wait_until_state_becomes $lc "active" \ + $ACTIVATION_TIMEOUT) + check_err $? "Failed to get linecard $lc activated (timeout)" + + interface_check + + log_test "Activation 16x100G" +} + +setup_prepare() +{ + local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length") + if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then + echo "SKIP: No linecard support found" + exit $ksft_skip + fi + + if [ -z "$LC_SLOT" ]; then + echo "SKIP: \"LC_SLOT\" variable not provided" + exit $ksft_skip + fi + + # Interfaces are not present during the script start, + # that's why we define NUM_NETIFS here so dummy + # implicit veth pairs are not created. + NUM_NETIFS=2 + h1=${NETIFS[p1]} + h2=${NETIFS[p2]} + ifaces_upped=false +} + +cleanup() +{ + if [ "$ifaces_upped" = true ] ; then + ip link set $h1 down + ip link set $h2 down + fi +} + +trap cleanup EXIT + +setup_prepare + +tests_run + +exit $EXIT_STATUS