From patchwork Fri Jun 19 03:32:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 217566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FD2AC433E0 for ; Fri, 19 Jun 2020 03:33:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40B9420888 for ; Fri, 19 Jun 2020 03:33:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="UmHihxAu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731002AbgFSDdl (ORCPT ); Thu, 18 Jun 2020 23:33:41 -0400 Received: from mail-eopbgr70089.outbound.protection.outlook.com ([40.107.7.89]:25892 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730924AbgFSDdi (ORCPT ); Thu, 18 Jun 2020 23:33:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e+l/W3ZjYYVwc7D2tdx6rRfoJT0igg0EAdltgn4v1+pkrehIp8g2Vg94i72koRGEpRMT8+2Ky1+1ajQKBtvGY+QXAZVtvklzEdaUGx7UDu+iasPi+JXYImNGdaqtRkaqR1QhpX0E3WCoyjEMjzz2IBiKWnbRNWPTJ+9ytSUmbafqsjl+TZwlyx81OZP8b5eq0JiCBwoyfZzt0TSIJINQv734oLsh5VsC0EaFbtERjyfz7VkTWOj4fzCUxsTVp6CjVtd3wqoY/NJ55I2Jeb6NbWYOJmTVhZaiV7geW6kukgcBQqHKS9AxoDXB8j4/m9gKm+K5278xTXFa3i74XYqLrw== 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-SenderADCheck; bh=96eyhbksGJ6SGyuLtRHdY2YS43qPzEeyxY3S69N7olc=; b=YQT6QC350jFfMDs3UY1AVzlAN/PmvD4VtW2qdLAzIjrGfQ1gL3derBXFYFwPkqQLey8f/RwY6E11/M419NpKn/R6Dp4dQqF2Pcf36b5C/5OmwOdBukSDdkEr1llPDB0n52PoWz60DiNUBqhjuFLM3EkW68sbAqqOC+ev9GQvr4AnUJ/sNwN1KAe51mDk2uzgigark+K/qekLSTevB+3/CaoooJwLlihfe90arw3E4+Y6W2Fbh4WxlF/Fh2Ut9tV1m+suOi7N6JU9OojBZyuVTr6TlPaZSdbkexWX7zEhkt56EvMOaekOFeSfSkteiAyeVqJl27EwmpqKSoDT4w3/Nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=96eyhbksGJ6SGyuLtRHdY2YS43qPzEeyxY3S69N7olc=; b=UmHihxAui9K869A9t3++XE0UTwmE2NMG7P1grdEdbizFBN2z3swepS0kwSskMezhZ7VheSTGskTFE6szDiZMwybuv2ciDtt6tP5sV52ReEueII53zJSgWCOrMhxJSEeYugok9YcOouPs4VKB2CqiJk1RkYpGKBWSoOvbFMKViWA= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) by AM0PR05MB6804.eurprd05.prod.outlook.com (2603:10a6:20b:146::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Fri, 19 Jun 2020 03:33:25 +0000 Received: from AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7]) by AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7%2]) with mapi id 15.20.3109.021; Fri, 19 Jun 2020 03:33:24 +0000 From: Parav Pandit To: netdev@vger.kernel.org Cc: saeedm@mellanox.com, davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com, Parav Pandit Subject: [PATCH net-next 3/9] net/devlink: Support setting hardware address of port function Date: Fri, 19 Jun 2020 03:32:49 +0000 Message-Id: <20200619033255.163-4-parav@mellanox.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200619033255.163-1-parav@mellanox.com> References: <20200619033255.163-1-parav@mellanox.com> X-ClientProxiedBy: SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) To AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw-mtx-036.mtx.labs.mlnx (208.176.44.194) by SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Fri, 19 Jun 2020 03:33:23 +0000 X-Mailer: git-send-email 2.25.4 X-Originating-IP: [208.176.44.194] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 67c54e3f-0cf2-4688-bb9a-08d8140185d9 X-MS-TrafficTypeDiagnostic: AM0PR05MB6804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:128; X-Forefront-PRVS: 0439571D1D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bo7ImGUKErIjsaJm2G52UXCUou1sNGo9uAjG6EkxdpgOdlVdlFny5yaIvM6bzFBzEURhvZfDb9J5mTvbgO4uavObT0KQUsEBWw0/DW5VQGbcxIPKBmUFhEI3rS2C6K6KK+SJPxQx3dHrMeIeZaKFttj3rSaXC4GOjo1P8xpnUnwsIeg6uPj+z9uMBFjBHRmqAtM3e14BKdrf1Dv2x+NlTja0StqiAa94NtRo20ko1XTeU9aVIO+GkINtoVL/YBhdWLPmifT+ges6qHI4GCpHGKtBHnk5ZZa2dzhY07uQQz9TfFn7X5gGdQXuxVyqNQJ5SPYHZQrrXzXFtuQXYtZfLQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4866.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(366004)(376002)(346002)(8676002)(2616005)(2906002)(4326008)(107886003)(6486002)(478600001)(8936002)(6512007)(5660300002)(6916009)(956004)(6666004)(26005)(66476007)(16526019)(186003)(66556008)(66946007)(316002)(6506007)(86362001)(52116002)(36756003)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WmvzZPKMSB5KArBpUEzp0Jp3kCTwMyk+J6JcU334gtuD3KN7d/AcEug8gIbb2oS6tHMjw1OIrGEPXhl5689NdRDaxwRHFWF3M50biRfxfu7EEH0jsL1ylP/u0nsioocxiohwPntWXJzL/purLwa+5B5dhEjryOsSwAz2wN+VcNxTAHNrD4v4VhKLVaqXsMnUcEBlEACv1X4lVADqf4S1D+aP+CaDvPb6vF0Mgb/ZidKv8nO8ChVBpeV9wNqp3KItR/0EDmMil0pOxq3zLsfurtyByqj9gBqcyfSe62YfNBnCk9Cr8hSr35/a5wCaCAs9ca1bTzSWsdXgQP/Xcx690Wm8WxgQnxK1CzXFAQe5i/BYQp/ykXHVSc6GT3lNRQv7LlKvMGnHIebfyjMJoi9L/YO6kVEbON6VjpXH6hFVwLp/uZt3vEos+umTPSSJSeZ8VY+Jjo3I0kDkwAfxjbNEUmkrQqJI9j+CCpVV/tccMLjtIjxlnA7KaEC6yjYGf7iv X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67c54e3f-0cf2-4688-bb9a-08d8140185d9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2020 03:33:24.8115 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: OQ5oOHAA40NQx3nGMeYXxxQiEF//55s/b/CgcdFqVTaMwALNFmRjrvqlCe1Cv3TttnJqgv14bpUtNWYpryTZwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6804 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org PCI PF and VF devlink port can manage the function represented by a devlink port. Allow users to set port function's hardware address. Example of a PCI VF port which supports a port function: $ devlink port show pci/0000:06:00.0/2 pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1 function: hw_addr 00:00:00:00:00:00 $ devlink port function set pci/0000:06:00.0/2 hw_addr 00:11:22:33:44:55 $ devlink port show pci/0000:06:00.0/2 pci/0000:06:00.0/2: type eth netdev enp6s0pf0vf1 flavour pcivf pfnum 0 vfnum 1 function: hw_addr 00:11:22:33:44:55 Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko --- include/net/devlink.h | 10 ++++++ net/core/devlink.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 56fc9cdb189d..7007f93585a5 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1119,6 +1119,16 @@ struct devlink_ops { int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port, u8 *hw_addr, int *hw_addr_len, struct netlink_ext_ack *extack); + /** + * @port_function_hw_addr_set: Port function's hardware address set function. + * + * Should be used by device drivers to set the hardware address of a function managed + * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port + * function handling for a particular port. + */ + int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack); }; static inline void *devlink_priv(struct devlink *devlink) diff --git a/net/core/devlink.c b/net/core/devlink.c index b6848b607e9c..baa45eca6b5a 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -85,6 +85,10 @@ EXPORT_SYMBOL(devlink_dpipe_header_ipv6); EXPORT_TRACEPOINT_SYMBOL_GPL(devlink_hwmsg); EXPORT_TRACEPOINT_SYMBOL_GPL(devlink_hwerr); +static const struct nla_policy devlink_function_nl_policy[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1] = { + [DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .type = NLA_BINARY }, +}; + static LIST_HEAD(devlink_list); /* devlink_mutex @@ -827,6 +831,67 @@ static int devlink_port_type_set(struct devlink *devlink, return -EOPNOTSUPP; } +static int +devlink_port_function_hw_addr_set(struct devlink *devlink, struct devlink_port *port, + const struct nlattr *attr, struct netlink_ext_ack *extack) +{ + const struct devlink_ops *ops; + const u8 *hw_addr; + int hw_addr_len; + int err; + + hw_addr = nla_data(attr); + hw_addr_len = nla_len(attr); + if (hw_addr_len > MAX_ADDR_LEN) { + NL_SET_ERR_MSG_MOD(extack, "Port function hardware address too long"); + return -EINVAL; + } + if (port->type == DEVLINK_PORT_TYPE_ETH) { + if (hw_addr_len != ETH_ALEN) { + NL_SET_ERR_MSG_MOD(extack, "Address must be 6 bytes for Ethernet device"); + return -EINVAL; + } + if (!is_unicast_ether_addr(hw_addr)) { + NL_SET_ERR_MSG_MOD(extack, "Non-unicast hardware address unsupported"); + return -EINVAL; + } + } + + ops = devlink->ops; + if (!ops->port_function_hw_addr_set) { + NL_SET_ERR_MSG_MOD(extack, "Port doesn't support function attributes"); + return -EOPNOTSUPP; + } + + err = ops->port_function_hw_addr_set(devlink, port, hw_addr, hw_addr_len, extack); + if (err) + return err; + + devlink_port_notify(port, DEVLINK_CMD_PORT_NEW); + return 0; +} + +static int +devlink_port_function_set(struct devlink *devlink, struct devlink_port *port, + const struct nlattr *attr, struct netlink_ext_ack *extack) +{ + struct nlattr *tb[DEVLINK_PORT_FUNCTION_ATTR_MAX + 1]; + int err; + + err = nla_parse_nested(tb, DEVLINK_PORT_FUNCTION_ATTR_MAX, attr, + devlink_function_nl_policy, extack); + if (err < 0) { + NL_SET_ERR_MSG_MOD(extack, "Fail to parse port function attributes"); + return err; + } + + attr = tb[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR]; + if (attr) + err = devlink_port_function_hw_addr_set(devlink, port, attr, extack); + + return err; +} + static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb, struct genl_info *info) { @@ -842,6 +907,16 @@ static int devlink_nl_cmd_port_set_doit(struct sk_buff *skb, if (err) return err; } + + if (info->attrs[DEVLINK_ATTR_PORT_FUNCTION]) { + struct nlattr *attr = info->attrs[DEVLINK_ATTR_PORT_FUNCTION]; + struct netlink_ext_ack *extack = info->extack; + + err = devlink_port_function_set(devlink, devlink_port, attr, extack); + if (err) + return err; + } + return 0; } @@ -6758,6 +6833,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_TRAP_POLICER_ID] = { .type = NLA_U32 }, [DEVLINK_ATTR_TRAP_POLICER_RATE] = { .type = NLA_U64 }, [DEVLINK_ATTR_TRAP_POLICER_BURST] = { .type = NLA_U64 }, + [DEVLINK_ATTR_PORT_FUNCTION] = { .type = NLA_NESTED }, }; static const struct genl_ops devlink_nl_ops[] = { From patchwork Fri Jun 19 03:32:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 217565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4A54C433DF for ; Fri, 19 Jun 2020 03:33:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC64320888 for ; Fri, 19 Jun 2020 03:33:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="oyK24gyb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731038AbgFSDdp (ORCPT ); Thu, 18 Jun 2020 23:33:45 -0400 Received: from mail-eopbgr80088.outbound.protection.outlook.com ([40.107.8.88]:57212 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730962AbgFSDdn (ORCPT ); Thu, 18 Jun 2020 23:33:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GHpNoEJGBm3qRjpDf6bwzE/Nz4kpV6UanxrbUS/K/s+2xLyczaVmurwX4aipwl6nOZDkd8eoUXhGuDsm5pyHrzu1G0rVnp12j7uQfTgy1jUL5Luk/om51Y6UQ8HAYohxkSBdmc40yaSv+Y+EH23d6rIx0Fs0iaton48F/SBdEd7CaaLSg+vrI9F/QlxxwPxzJ1tV659mTYfe4qXMD1TdWledUFHLlh8tPhJIQonNxAsIFu1EPaZpRXd+TM2xMkoAzDCYp1Y0mEEuF3yOOI0C/TxzB3ahsSVcPC3bLssY5mYjiQ7eaczQDlX302Vr4spvZgsv+y9J9QBDl2aNR4EUxw== 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-SenderADCheck; bh=jatV1TJUaxjZOC4Z+8goiTkRHn+lGLqnQVtf1Ku43Yk=; b=fVNFF6nuEhDUmhTcTuNrmTAowDjGo/hSHqax7JcEGsbr6N0Ag0S7VxNdEx76kgSCreRh1nUCJMgaidXhzKOeo/xLES5ulQUDHDrD5uI4ymGGaRSarvKPoozuRawLRCYcyTc4KIz3NkQnvwJBFClL+zrVhh8xULjrXDDklNRSYcv9XM19dZ/D76OmgPhYTO/KxKbK6vIvJIhNAiBWKtkEArDQC9OpRbVyAXS7S+qaF2DQNWGX+RtrpORa0qN6qj4kJ8pOfw10A/qiQFGYDldK+AtVWTnYPMDsFOz1Vepfi4gA5XXTrnnD7zFRAvqJ38t40OSUF1InPIT2ar3cJ7IKng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jatV1TJUaxjZOC4Z+8goiTkRHn+lGLqnQVtf1Ku43Yk=; b=oyK24gybXRdV95WPe8h6G9HYjyCBeJLu/Z4LFUJkSXFkGUs4v/tMdihzoq9UpXCrhdzou5LEcI9l01nrlfJfrRLJKs5ksDzPL5yH27vme+1pQiwCVZiI7BaFYb8q3RvwREb8x/eEYqwkwa+CpmUNp23StaF4V0feYqiheYWIXs0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) by AM0PR05MB6804.eurprd05.prod.outlook.com (2603:10a6:20b:146::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Fri, 19 Jun 2020 03:33:28 +0000 Received: from AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7]) by AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7%2]) with mapi id 15.20.3109.021; Fri, 19 Jun 2020 03:33:28 +0000 From: Parav Pandit To: netdev@vger.kernel.org Cc: saeedm@mellanox.com, davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com, Parav Pandit , Roi Dayan Subject: [PATCH net-next 5/9] net/mlx5: E-switch, Introduce and use eswitch support check helper Date: Fri, 19 Jun 2020 03:32:51 +0000 Message-Id: <20200619033255.163-6-parav@mellanox.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200619033255.163-1-parav@mellanox.com> References: <20200619033255.163-1-parav@mellanox.com> X-ClientProxiedBy: SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) To AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw-mtx-036.mtx.labs.mlnx (208.176.44.194) by SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Fri, 19 Jun 2020 03:33:26 +0000 X-Mailer: git-send-email 2.25.4 X-Originating-IP: [208.176.44.194] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 71d882b8-fdf2-4f48-0f3a-08d8140187eb X-MS-TrafficTypeDiagnostic: AM0PR05MB6804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1091; X-Forefront-PRVS: 0439571D1D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AMYq+6pbjHOVfAa11zldN8ofFG3AbZEzbvo8lu+FFwl9plvaiPRikucdc6jzFC0vvk2fFzB2tn6jMqrH1qB2Q3F29edhf4vSYquAltzSvt0rwexmTheoq1XUXFvggolvdegkpIMT0NzR4U04Hk8+nxFpqd+UU2Yo7uKunQI2F5Ow9Wm+HQmPM9JjM/ucv1MQDirJ/85KRgGi2uVRjw6IkndYrHNA+yiHbRRgR4QC3D6z87Ln4YNbGYc3X9qh5bzf/z9NFdUPlK9cBDHoXLUhb8cj0UfCsE8RxuPDX1opEWo3/uXmpVn50KutwoQDQwr+ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4866.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(366004)(376002)(346002)(8676002)(2616005)(2906002)(4326008)(107886003)(6486002)(478600001)(8936002)(6512007)(5660300002)(6916009)(956004)(6666004)(26005)(66476007)(16526019)(186003)(66556008)(66946007)(83380400001)(316002)(6506007)(54906003)(86362001)(52116002)(36756003)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wRnui4jsU/gUK7hyAxt8rNtOcoytCJnz8IYIPaBHWZim/9soTxz6BZy9tO5IpZv0FoOpAApHJLASGG2pd8nwl0EezmkIi/0X//onX1f1Mw/W4tEEln+qGAmFExsd7GePIKj5TWAvzShPv5vrZF0xV28jGg7kCMlph2YoeiQoTIpryxZQ89nzfTNVkpkcm6uNqyFglysd9jZMV/AtC4GmZBNE8MyxZ3ZJRMyuJooOIoMVSuPPd+6eSoT3F44FemlzCdWsdDMMF6uthzrMotPEW269UVKMwzuk/90Sl3AoquSTheXIOv09rnlKHLFJ1XtUel5yXaT0VvcROtxgiJmdsj8Mld6WukNFwwHlVkxajg4+BY5qp8CpotbfyjBv6Tgpimie6JEV/h0wFOmP9Wch//wtOZzodCtK7qPW0Rcd1S+UCqkpwS0zZCihsRmbvDISfDm4CVgCJwR7x3P4044k3+Grq0iCvEcm4n8nJz7LFSkCte0WCxL98QMHFAkSh4hT X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71d882b8-fdf2-4f48-0f3a-08d8140187eb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2020 03:33:28.4205 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: m1/j45uO+PBrOcc3BCllwZRt9tvlfwjYuLhS2oH8/4C5UM9szwvhgAZljknXD1yKrvA5BtdomTD+paMAIS+pzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6804 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Introduce an helper routine to get esw from a devlink device and use it at eswitch callbacks and in subsequent patch. Signed-off-by: Parav Pandit Reviewed-by: Roi Dayan --- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 23 +++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + .../mellanox/mlx5/core/eswitch_offloads.c | 66 ++++++++----------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index d6a585a143dc..9f04fd10cb1e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -63,6 +63,29 @@ struct vport_addr { static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch *esw); static void esw_cleanup_vepa_rules(struct mlx5_eswitch *esw); +static int mlx5_eswitch_check(const struct mlx5_core_dev *dev) +{ + if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH) + return -EOPNOTSUPP; + + if (!MLX5_ESWITCH_MANAGER(dev)) + return -EPERM; + + return 0; +} + +struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink) +{ + struct mlx5_core_dev *dev = devlink_priv(devlink); + int err; + + err = mlx5_eswitch_check(dev); + if (err) + return ERR_PTR(err); + + return dev->priv.eswitch; +} + struct mlx5_vport *__must_check mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index 165a23efc608..dde5a36fee9d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -634,6 +634,7 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw); for ((vport) = (nvfs); \ (vport) >= (esw)->first_host_vport; (vport)--) +struct mlx5_eswitch *mlx5_devlink_eswitch_get(struct devlink *devlink); struct mlx5_vport *__must_check mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index 060354bb211a..74a2b76c7c07 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -2279,17 +2279,6 @@ static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode) return 0; } -static int mlx5_eswitch_check(const struct mlx5_core_dev *dev) -{ - if (MLX5_CAP_GEN(dev, port_type) != MLX5_CAP_PORT_TYPE_ETH) - return -EOPNOTSUPP; - - if(!MLX5_ESWITCH_MANAGER(dev)) - return -EPERM; - - return 0; -} - static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw) { /* devlink commands in NONE eswitch mode are currently supported only @@ -2302,14 +2291,13 @@ static int eswitch_devlink_esw_mode_check(const struct mlx5_eswitch *esw) int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, struct netlink_ext_ack *extack) { - struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; u16 cur_mlx5_mode, mlx5_mode = 0; + struct mlx5_eswitch *esw; int err; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); if (esw_mode_from_devlink(mode, &mlx5_mode)) return -EINVAL; @@ -2338,16 +2326,15 @@ int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode) { - struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; + struct mlx5_eswitch *esw; int err; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); mutex_lock(&esw->mode_lock); - err = eswitch_devlink_esw_mode_check(dev->priv.eswitch); + err = eswitch_devlink_esw_mode_check(esw); if (err) goto unlock; @@ -2361,13 +2348,13 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, struct netlink_ext_ack *extack) { struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; int err, vport, num_vport; + struct mlx5_eswitch *esw; u8 mlx5_mode; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); mutex_lock(&esw->mode_lock); err = eswitch_devlink_esw_mode_check(esw); @@ -2424,13 +2411,12 @@ int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode, int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode) { - struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; + struct mlx5_eswitch *esw; int err; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); mutex_lock(&esw->mode_lock); err = eswitch_devlink_esw_mode_check(esw); @@ -2448,12 +2434,12 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, struct netlink_ext_ack *extack) { struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; + struct mlx5_eswitch *esw; int err; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); mutex_lock(&esw->mode_lock); err = eswitch_devlink_esw_mode_check(esw); @@ -2508,13 +2494,13 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink, int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink, enum devlink_eswitch_encap_mode *encap) { - struct mlx5_core_dev *dev = devlink_priv(devlink); - struct mlx5_eswitch *esw = dev->priv.eswitch; + struct mlx5_eswitch *esw; int err; - err = mlx5_eswitch_check(dev); - if (err) - return err; + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) + return PTR_ERR(esw); + mutex_lock(&esw->mode_lock); err = eswitch_devlink_esw_mode_check(esw); From patchwork Fri Jun 19 03:32:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 217564 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F7E3C433DF for ; Fri, 19 Jun 2020 03:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF0042080D for ; Fri, 19 Jun 2020 03:33:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="s2X7nBki" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731045AbgFSDdu (ORCPT ); Thu, 18 Jun 2020 23:33:50 -0400 Received: from mail-eopbgr80088.outbound.protection.outlook.com ([40.107.8.88]:57212 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731008AbgFSDdr (ORCPT ); Thu, 18 Jun 2020 23:33:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZbmUsUc4mPCkhB5XI+OF66be9lR2JNLU5JbZ3P3Vj9MlNbdIWbzOkbQJhIi9DFwmwfj8n71TTijKbD+X5L0eGKZnIgQf3irk/r65F4biM6marmRfTPjmFiw8K/aWoxDEcU90jl34qgM/sUHr8xDU2LaAtmYyyXxOtIekjtBFkqHbjwDjK16CZLj3sbxcc4dES2YGTM9iG+Qcgc/vE1Q+NQC5NR6QGfYPX2D/1/uulRbeaNKH1hOKOpuAazIqKrBVfwvCBaGDiJlTHBxZbNMkURJQYiXUMVj3sxEHQVjewSAbmY9mPLXV1qFpE0dSpfXDamMSQt0qiH7XEBXu+cxx+w== 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-SenderADCheck; bh=xUObjke8/5gjkr7pDSeGQp+f5O8czs+Y3AP2FqFTwI8=; b=kqkUiofLCUmMogmTa6gCkLBqb6Mc8pWMnTKPMSNYwg5Jm4R/1f/RICgB2FdFBhoLWg2OlIe+wOK0ruEW71UZLk6Y6htRB+xZyWbSBz5kdz0k8GgDXhcpffxRknBt7GhY6JT20U2gtKyussQBGIFbrHtbWDOWoeDjX4317+cXiWSHZVjpHooKqB+tTRZA1VueMJ/DpqvgrnDzftqLQgUY0lqpSAofah3tXS68XHMJ/ggs4ZERBoW1ug0diOS/tna10qfjEBcBXfbwYxRIxU3lTGs9TWRor3GPzwzRnH06mGAli+EKJzw1X2vPChTehEP8ZN8+Y/dxb/4eVIU0arnjYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xUObjke8/5gjkr7pDSeGQp+f5O8czs+Y3AP2FqFTwI8=; b=s2X7nBkiZsZE4SUW+AxZRsJb3Qa68xjgHn6ON1bbcO6Y9qKSLA1tZJEXJPGr1DnISIHIqSSltOaeUPgbyqUueAh5JD8dGviBtH3j3K9X7R198e6f9IHEPITMbWdAY9LvaZm+z4OZbW06SXQV+3cl1mwKB1NT89kRfHBJX3v1TR8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) by AM0PR05MB6804.eurprd05.prod.outlook.com (2603:10a6:20b:146::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Fri, 19 Jun 2020 03:33:33 +0000 Received: from AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7]) by AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7%2]) with mapi id 15.20.3109.021; Fri, 19 Jun 2020 03:33:33 +0000 From: Parav Pandit To: netdev@vger.kernel.org Cc: saeedm@mellanox.com, davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com, Parav Pandit , Roi Dayan Subject: [PATCH net-next 8/9] net/mlx5: Split mac address setting function for using state_lock Date: Fri, 19 Jun 2020 03:32:54 +0000 Message-Id: <20200619033255.163-9-parav@mellanox.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200619033255.163-1-parav@mellanox.com> References: <20200619033255.163-1-parav@mellanox.com> X-ClientProxiedBy: SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) To AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw-mtx-036.mtx.labs.mlnx (208.176.44.194) by SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Fri, 19 Jun 2020 03:33:32 +0000 X-Mailer: git-send-email 2.25.4 X-Originating-IP: [208.176.44.194] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 09347809-a18f-4aef-9da1-08d814018b0a X-MS-TrafficTypeDiagnostic: AM0PR05MB6804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 0439571D1D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hGVaJWAIa9xSxLXdJpA1lEOlUim3O4RNdYarhfTqLAhomQtz0bYeIwUsmJ4D1mF+SkXGx3/yOCl04hF8ZiW2w8F3fH5yR0F9VBgIsfy31bP0/oXFkmQULwvFw8Y8DRcT+dHVexo4DrlL1c6m0WAR7o4e3LkkMRaBNmyfGkvTc35MHppoQbMLsPYG9yM0bUzGK5sgIyxvUNi9fDa8Qrvcs2YNsOgTi/ys4xnzyydXz6bRwmNLNdT+5AIj2Z02ojBBuUQ3u2Pi6KY8hC+oLVxiq4+22BbsMBAO1AK98Jvvns5488ej4zmKrLLsNj7RQfug X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4866.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(366004)(376002)(346002)(8676002)(2616005)(2906002)(4326008)(107886003)(6486002)(478600001)(8936002)(6512007)(5660300002)(6916009)(956004)(6666004)(26005)(66476007)(16526019)(186003)(66556008)(66946007)(83380400001)(316002)(6506007)(54906003)(86362001)(52116002)(36756003)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2dXyI2MaLJVhL9KhbJbkMz23XjOJQCcqIwwuKBFx/XpV/00j2LZulJnEV1jTgNb+8XwGa0oVxLZvVwei9ulekV1h/L9N84wuobKQ7jpK5W1qbIxElIkYpS6cnM4B6GxIzQaiL6hTCdB6+a8m2nhSG+Rmso/AuaveX56WOHGdliPsA4A6RsgpvNWn407L/q4mvrDPqqrrMMLrxlgvY62QIfhl1zlLC8zlDnd2cMQ5pqGEIp4k+Oy9BarFY0P2czi/H+FGPHJP87Xk9xaZqWbQl5D+lDQhpI8M+zGJxJ4YDRAxOScfxOrwPGLoNkz3DMqiNATrjbLe6JV8nn3yeeoNUcfHrmSP3faDuf6c40N1lKPFEiHF865IYWrXMAi5rkjdvqVXHO1blmSEf0wuLWiQyNlKMAEWbO0Nvcux9C1jG/4Kt3pGM/IFUEpSGDw5apJITe5XeNFy91mHbNXSez9Qpa+lt9r3t5g8Vkog31XlFLMTpz+b+VdmEdPyBn4qieUe X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09347809-a18f-4aef-9da1-08d814018b0a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2020 03:33:33.4765 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gNL9T/FXwTj4vaRUsLTix7suG4YTYzcSjkXCL9BQoYH05/ASBOu4gEh1N0ZH0TTyTp1q1GLl2ycRO0bGQHNXDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6804 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Refactor mac address setting function to let caller hold the necessary state_lock mutex, so that subsequent patch and use this helper routine. Signed-off-by: Parav Pandit Reviewed-by: Roi Dayan --- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 999e51656e16..2c08411e34ee 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -1801,46 +1801,56 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw) } /* Vport Administration */ -int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw, - u16 vport, const u8 *mac) +static int +mlx5_esw_set_vport_mac_locked(struct mlx5_eswitch *esw, + struct mlx5_vport *evport, const u8 *mac) { - struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport); + u16 vport_num = evport->vport; u64 node_guid; int err = 0; - if (IS_ERR(evport)) - return PTR_ERR(evport); if (is_multicast_ether_addr(mac)) return -EINVAL; - mutex_lock(&esw->state_lock); - if (evport->info.spoofchk && !is_valid_ether_addr(mac)) mlx5_core_warn(esw->dev, "Set invalid MAC while spoofchk is on, vport(%d)\n", - vport); + vport_num); - err = mlx5_modify_nic_vport_mac_address(esw->dev, vport, mac); + err = mlx5_modify_nic_vport_mac_address(esw->dev, vport_num, mac); if (err) { mlx5_core_warn(esw->dev, "Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n", - vport, err); - goto unlock; + vport_num, err); + return err; } node_guid_gen_from_mac(&node_guid, mac); - err = mlx5_modify_nic_vport_node_guid(esw->dev, vport, node_guid); + err = mlx5_modify_nic_vport_node_guid(esw->dev, vport_num, node_guid); if (err) mlx5_core_warn(esw->dev, "Failed to set vport %d node guid, err = %d. RDMA_CM will not function properly for this VF.\n", - vport, err); + vport_num, err); ether_addr_copy(evport->info.mac, mac); evport->info.node_guid = node_guid; if (evport->enabled && esw->mode == MLX5_ESWITCH_LEGACY) err = esw_acl_ingress_lgcy_setup(esw, evport); -unlock: + return err; +} + +int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw, + u16 vport, const u8 *mac) +{ + struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport); + int err = 0; + + if (IS_ERR(evport)) + return PTR_ERR(evport); + + mutex_lock(&esw->state_lock); + err = mlx5_esw_set_vport_mac_locked(esw, evport, mac); mutex_unlock(&esw->state_lock); return err; } From patchwork Fri Jun 19 03:32:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parav Pandit X-Patchwork-Id: 217563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A327AC433E0 for ; Fri, 19 Jun 2020 03:33:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ED4C2080D for ; Fri, 19 Jun 2020 03:33:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="UINHxrCc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731076AbgFSDdz (ORCPT ); Thu, 18 Jun 2020 23:33:55 -0400 Received: from mail-eopbgr80088.outbound.protection.outlook.com ([40.107.8.88]:57212 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729570AbgFSDdv (ORCPT ); Thu, 18 Jun 2020 23:33:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dg6zfRMBXsLwE7UmR4675cUIX2J9nyjhAo+2iZQBytKIbwVAz6BH3rkeatP6RokXyo7gD91+XefCx/7SRrCeqSWfGPNSVlyF5DJiWhRBPFpFJciCxsw5QcWf0e/H5KbuJyZGNHS2Vt4VFJ24RP8a6TyqytTfJOGk8A1lxn9IWMjayabE3KUcDjaDxMMuc2cTwXFywB4MDr1KQhCULnOecYMh0fP2GTumK2VW+cCpA60DU6FsSudM06Uxz9UpKa7TJ2iE8543DBXj3FxhP5yf4rEl9JwxX2U9ElqCAqZe5hh+gHJ6JrppcY5pV9qhnuCoRdtG7zEOukC8lCzhh/Shrw== 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-SenderADCheck; bh=uEYRV2HQdbkIMUscgJ3Hot+jiakxgF+1mF5OSTtx1zk=; b=WX0G4yuFuJIYoeHKW7368cLmMmEAEPU9RfyQn4AJzu5NsFoZWTQprD/b00UJ2suKMqpVkG5XR3RJXbj3ZBKyHkbTnAK5Rk0jwSFBbPx/kyQvr3KhFPJpQuHISkOyA43StJ2jxUDQ3niWBMlO/QyLMisi+u/hNPz4c0VtqloLcKlG5NZZNRobOTpl93uRfiQlze+klongq1N2dVdGNKe4tq4YCtqRVs+kpPbKjeVh1XDjc9xQNp0CeOfdA+sz/nY9q02eEr1uc4ePqDnPssd0lul9BADurFrSGh8PwK2yvgeQ0TK7npPHP/tjXu+z9qcgyxMUeKEsLpy5eig04Ose/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uEYRV2HQdbkIMUscgJ3Hot+jiakxgF+1mF5OSTtx1zk=; b=UINHxrCcOh8B73N3Ws/VacHJPBEUoQc03TuQ/k2xeaXFffUkk2Chtipd03FkwNRUjlEpld7wme47frg1YigFrSdwpySRx3bl4Wpvwc3CXTyih8pePtqiTJ40wrgVoek3DH6xoZ4xDBoyhOz1DllkbSL/2Kfq+zFTs/g0WUk8QlI= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) by AM0PR05MB6804.eurprd05.prod.outlook.com (2603:10a6:20b:146::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Fri, 19 Jun 2020 03:33:35 +0000 Received: from AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7]) by AM0PR05MB4866.eurprd05.prod.outlook.com ([fe80::d44d:a804:c730:d2b7%2]) with mapi id 15.20.3109.021; Fri, 19 Jun 2020 03:33:35 +0000 From: Parav Pandit To: netdev@vger.kernel.org Cc: saeedm@mellanox.com, davem@davemloft.net, kuba@kernel.org, jiri@mellanox.com, Parav Pandit , Roi Dayan Subject: [PATCH net-next 9/9] net/mlx5: E-switch, Supporting setting devlink port function mac address Date: Fri, 19 Jun 2020 03:32:55 +0000 Message-Id: <20200619033255.163-10-parav@mellanox.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200619033255.163-1-parav@mellanox.com> References: <20200619033255.163-1-parav@mellanox.com> X-ClientProxiedBy: SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) To AM0PR05MB4866.eurprd05.prod.outlook.com (2603:10a6:208:c0::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw-mtx-036.mtx.labs.mlnx (208.176.44.194) by SN4PR0401CA0019.namprd04.prod.outlook.com (2603:10b6:803:21::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Fri, 19 Jun 2020 03:33:33 +0000 X-Mailer: git-send-email 2.25.4 X-Originating-IP: [208.176.44.194] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f1d19a17-6a67-4ffb-9d88-08d814018bfe X-MS-TrafficTypeDiagnostic: AM0PR05MB6804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:792; X-Forefront-PRVS: 0439571D1D X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9eDHot7zBQmfBv959/+9fwxdAZYuxLTSBEZC4bi6iJ+zaUyYmO4bp8JocYeRlaqWaPjHK8UE5PIvZUq3JNuZIrAaj99KpwuyW5e82nDclRDtF24wtxgr3oXPuH5PrAQAFO2NO7LGmKYlgysu/m6Ngqg7CdXvmxMFnasrWWV1vIca82nW0CHUHNJfr4njCrJPx4Te0FIoArJ5UlNNaFGMthC02xiYEenujueqQ6q8FVv3X+fCgpjzCM0hdTZnSTuD5NOc0+4ge/ibydwxyXuIW8mSIvkgdLbyuT7+S/YYLks4t5wPY226NecxRtmhltTJ4t3dLUcWv5kLvxuo6yrvWw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4866.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(366004)(376002)(346002)(8676002)(2616005)(2906002)(4326008)(107886003)(6486002)(478600001)(8936002)(6512007)(5660300002)(6916009)(956004)(6666004)(26005)(66476007)(16526019)(186003)(66556008)(66946007)(83380400001)(316002)(6506007)(54906003)(86362001)(52116002)(36756003)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: phAN6Q6TP2vRfgrJq0DMguu8+3OjV5rsp+XxVdqbcZbaDrD0jJPmL/iy4FdyUyWlmLpkXhyx+8B5pfNhvWqEoRcWhCuZrojm//SaRTA9xJvn2A+QXRHZ09MAGeZqDQyRfXY1+/FdlL6Ct0NnJtlss5S+s6OGmv/E0/+QKTH6wOAHi6LpK3EYcrIdNAxRguWFwy8ISejjrkGn4W85oMVINRne65QfsrZapgcSpivACtxJTbcso04Gq+NEGm2/QHpNgjCrX4myn8vA0E3bWYWzSIZEvq0pcsdMyi9jy+A/QJPeLQc0decjRdIu3QUrsp5TL1P+RFsq2VgdkA6i+DaFI+QqNblCn2x57Tdh2JWkwA/Ic+17t37kodazSpZc6FQAQDXJ7PQCTVaMZZYUVKdpzbDyDVZ5MqeOj2BABg4XfUkKbjwWz3Zg8U/yiGh1ZYLWSq4fpDr0UdyE+eI7OEEw/Mo7beHVXpXNUMTFHKsBtgKCRwWtKM24CMF/sXDu0AUD X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1d19a17-6a67-4ffb-9d88-08d814018bfe X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jun 2020 03:33:35.1166 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u/IYJh313M6wZuvawvuDsTBTUd4a32/mgHEG9I6887hrPfieli+BYFB0XKcs2rq6+blPqSxClBOzFdMhn79gAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6804 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Enable user to set mac address of the PCI PF and VF port function. Signed-off-by: Parav Pandit Reviewed-by: Roi Dayan Acked-by: Jiri Pirko --- .../net/ethernet/mellanox/mlx5/core/devlink.c | 1 + .../net/ethernet/mellanox/mlx5/core/eswitch.c | 36 +++++++++++++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 4 +++ 3 files changed, 41 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c index 3177d2458fa5..c709e9a385f6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c @@ -114,6 +114,7 @@ static const struct devlink_ops mlx5_devlink_ops = { .eswitch_encap_mode_set = mlx5_devlink_eswitch_encap_mode_set, .eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get, .port_function_hw_addr_get = mlx5_devlink_port_function_hw_addr_get, + .port_function_hw_addr_set = mlx5_devlink_port_function_hw_addr_set, #endif .flash_update = mlx5_devlink_flash_update, .info_get = mlx5_devlink_info_get, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c index 2c08411e34ee..c656c9f081c1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -1898,6 +1898,42 @@ int mlx5_devlink_port_function_hw_addr_get(struct devlink *devlink, return err; } +int mlx5_devlink_port_function_hw_addr_set(struct devlink *devlink, + struct devlink_port *port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct mlx5_eswitch *esw; + struct mlx5_vport *vport; + int err = -EOPNOTSUPP; + u16 vport_num; + + esw = mlx5_devlink_eswitch_get(devlink); + if (IS_ERR(esw)) { + NL_SET_ERR_MSG_MOD(extack, "Eswitch doesn't support set hw_addr"); + return PTR_ERR(esw); + } + + vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index); + if (!is_port_function_supported(esw, vport_num)) { + NL_SET_ERR_MSG_MOD(extack, "Port doesn't support set hw_addr"); + return -EINVAL; + } + vport = mlx5_eswitch_get_vport(esw, vport_num); + if (IS_ERR(vport)) { + NL_SET_ERR_MSG_MOD(extack, "Invalid port"); + return PTR_ERR(vport); + } + + mutex_lock(&esw->state_lock); + if (vport->enabled) + err = mlx5_esw_set_vport_mac_locked(esw, vport, hw_addr); + else + NL_SET_ERR_MSG_MOD(extack, "Eswitch vport is disabled"); + mutex_unlock(&esw->state_lock); + return err; +} + int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw, u16 vport, int link_state) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h index 19cd0af7afda..67e09902bd88 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -454,6 +454,10 @@ int mlx5_devlink_port_function_hw_addr_get(struct devlink *devlink, struct devlink_port *port, u8 *hw_addr, int *hw_addr_len, struct netlink_ext_ack *extack); +int mlx5_devlink_port_function_hw_addr_set(struct devlink *devlink, + struct devlink_port *port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack); void *mlx5_eswitch_get_uplink_priv(struct mlx5_eswitch *esw, u8 rep_type);