From patchwork Tue Jan 31 14:58:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123072 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 A3FD2C38142 for ; Tue, 31 Jan 2023 14:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232342AbjAaO7E (ORCPT ); Tue, 31 Jan 2023 09:59:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232396AbjAaO6p (ORCPT ); Tue, 31 Jan 2023 09:58:45 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2047.outbound.protection.outlook.com [40.107.93.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E43446A2; Tue, 31 Jan 2023 06:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N23RvslmW7hHCUyBcY2WCyiUXLdTjuZCsX/XgRjm9Pjxtn3eaJvePKz/KA+LIxxPOYwjsXIVBH7goD8BbEVnZ1lKSzZl5tzZfmGUlImTOPO1DNSBQE/jPqtSaPpiv8Jb91zcQ68IzDLnYc3vtloy/MPv4m938PgS3auOifm5rnuhZ6BeOmhEXDj9u/ZsQWORDjIAu6IsQB7aqVPDVc/AUWO+2tqO6eI4khSYnVK+TS+L1cvwgxDzP8WfdDtMN31QUV5QwLxFUddcec6C3vSmOQf7D4C9j6fOA78CBH6tdejW0ucN5JPowUStlO22fpvNFqvNtPmIFKgE24GZRf9nvA== 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=ev/BYxe0mYIWIcl8dWTcGiCoyZUM0AYLbiPwiUXPVnU=; b=d99lciTbzzSVUljgEp0rXC8aircqnFynIJfgyWNyXJtX+wWbd7HOHLf95LaAU7M0sF7PBK3MMpmWpZ5XeN3uBtL91AUoKTbw+NDW7RPbpYh08ZWIF8VnPDq2v9obyhYjkDm9Ain26ck1TjkBvXPmAFSqTkjWfLQe8Ad5nub+URfnN+Uo+/wnMe+5j/MMeIdf09TPq0XreuserYNlL1LE4PuRoOaTxQiWiZ3w9RH5xM8L+T+c5JgrlwRCZ+K/1ZpGOad8+WNRjZSCkdM1htCQ1SwP/xsPjiyqelljdJEiveSJBr/N1jggpal9jHslDkwLTyh/CduJcUqB2KR3n2SS6A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ev/BYxe0mYIWIcl8dWTcGiCoyZUM0AYLbiPwiUXPVnU=; b=eLtD9nwGUj42dZTEpG02Wd0gCxKQmA1RLLdRt/x5rUNvk64JrnBeD7WMwX7VW3kEyYsbmsWoISLs9TE2bKlvkOm4kdYkbcjWqgNUjM7p7trO+bO24UMwP6asey/OwPqNLyWXAXHiRXerOI/ZU5QHs+oozXVbxwMEAM2jnrA1GRE= Received: from BN9P221CA0027.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::21) by MN0PR12MB5955.namprd12.prod.outlook.com (2603:10b6:208:37e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36; Tue, 31 Jan 2023 14:58:39 +0000 Received: from BN8NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::63) by BN9P221CA0027.outlook.office365.com (2603:10b6:408:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT039.mail.protection.outlook.com (10.13.177.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.21 via Frontend Transport; Tue, 31 Jan 2023 14:58:39 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:35 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:34 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:33 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 1/8] sfc: add devlink support for ef100 Date: Tue, 31 Jan 2023 14:58:15 +0000 Message-ID: <20230131145822.36208-2-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT039:EE_|MN0PR12MB5955:EE_ X-MS-Office365-Filtering-Correlation-Id: 829632df-c7d5-4fa8-6380-08db039ba354 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QzYZgILRefcs58yl/NjlBxr/DIyA4Fx2kjLVrwxPEMELYjBegDHWQCUB8LxEIWGNtGFz7S+W1doDkL0VzFKsXd3cJQsnP1V/kpT7cHUd/tnMZeYPh/wjfB5n/G2DRzbuo6RYeWLfYCoDSEPKr/kabJDw6FojY/h8LXpV5W+/Wl+QJAgTk7gGylrwpa4ieNYKw3++Sm8YaTN2M+G6bGDduTApOz+/d8p//xBC1r+ICgF7pQG0yrbKOwPRtMXI/k28tkcAxKq0yscU7o96bFx6a2sX09P3XWvB/WXwJr+mvAPiFmdvZll2xJ1JcnizmuJpTo7qSupgMWb43jk43FtHMxItNVGP2hGfTkb0HU7XN1P64ct2gJrXcjj93PtXijv/Edjq87HLLKjKatEykyqgCEzsntw+64xWJRoA7mwxZOwMgz7k179Z3fV4ZlRgDAc0tWT7C89oXs4hnsHE0Z5epUrmkH2dsfYrnTV4Z8jyE4n/LqOal7ey67/OqHtvJYrC4goFCe/8XDaDnrCD2mFPvGxNNxtNCsitBXhVB1BPmPJBMp3++sL8ci71uFwzbIJt4qeu4t1ifo6Iox9KHbq1osTEfcxjgBA8sXzXmDn4RBMcQiHMtG8IgtkrbGlGM4x6SKYYGdFbUDWCEaE5d+Vbw6jxCa2FBp8Zm0MAFBu1vdMa6DR8zV2qrXOVAVhwL29dWFdg6Jmw1Nn3+tF98J7X4+//YFpK14dcTeLC/0QGMyJIhFwPkfsoiH3IpbABGSZk X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(396003)(376002)(136003)(39860400002)(451199018)(40470700004)(46966006)(36840700001)(356005)(86362001)(70206006)(81166007)(82740400003)(36756003)(110136005)(6636002)(5660300002)(316002)(8676002)(4326008)(36860700001)(54906003)(8936002)(70586007)(40460700003)(82310400005)(40480700001)(2906002)(41300700001)(336012)(2876002)(83380400001)(2616005)(426003)(47076005)(7416002)(478600001)(26005)(6666004)(186003)(1076003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:39.7619 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 829632df-c7d5-4fa8-6380-08db039ba354 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5955 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Basic devlink infrastructure support. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/Kconfig | 1 + drivers/net/ethernet/sfc/Makefile | 3 +- drivers/net/ethernet/sfc/ef100_netdev.c | 12 +++++ drivers/net/ethernet/sfc/ef100_nic.c | 3 +- drivers/net/ethernet/sfc/efx_devlink.c | 71 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_devlink.h | 22 ++++++++ drivers/net/ethernet/sfc/net_driver.h | 2 + 7 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/sfc/efx_devlink.c create mode 100644 drivers/net/ethernet/sfc/efx_devlink.h diff --git a/drivers/net/ethernet/sfc/Kconfig b/drivers/net/ethernet/sfc/Kconfig index 0950e6b0508f..4af36ba8906b 100644 --- a/drivers/net/ethernet/sfc/Kconfig +++ b/drivers/net/ethernet/sfc/Kconfig @@ -22,6 +22,7 @@ config SFC depends on PTP_1588_CLOCK_OPTIONAL select MDIO select CRC32 + select NET_DEVLINK help This driver supports 10/40-gigabit Ethernet cards based on the Solarflare SFC9100-family controllers. diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index 712a48d00069..55b9c73cd8ef 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -6,7 +6,8 @@ sfc-y += efx.o efx_common.o efx_channels.o nic.o \ mcdi.o mcdi_port.o mcdi_port_common.o \ mcdi_functions.o mcdi_filters.o mcdi_mon.o \ ef100.o ef100_nic.o ef100_netdev.o \ - ef100_ethtool.o ef100_rx.o ef100_tx.o + ef100_ethtool.o ef100_rx.o ef100_tx.o \ + efx_devlink.o sfc-$(CONFIG_SFC_MTD) += mtd.o sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \ mae.o tc.o tc_bindings.o tc_counters.o diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c index ddcc325ed570..b10a226f4a07 100644 --- a/drivers/net/ethernet/sfc/ef100_netdev.c +++ b/drivers/net/ethernet/sfc/ef100_netdev.c @@ -24,6 +24,7 @@ #include "rx_common.h" #include "ef100_sriov.h" #include "tc_bindings.h" +#include "efx_devlink.h" static void ef100_update_name(struct efx_nic *efx) { @@ -332,6 +333,8 @@ void ef100_remove_netdev(struct efx_probe_data *probe_data) efx_ef100_pci_sriov_disable(efx, true); #endif + /* devlink lock */ + efx_fini_devlink_start(efx); ef100_unregister_netdev(efx); #ifdef CONFIG_SFC_SRIOV @@ -345,6 +348,9 @@ void ef100_remove_netdev(struct efx_probe_data *probe_data) kfree(efx->phy_data); efx->phy_data = NULL; + /* devlink unlock */ + efx_fini_devlink(efx); + free_netdev(efx->net_dev); efx->net_dev = NULL; efx->state = STATE_PROBED; @@ -405,6 +411,10 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) /* Don't fail init if RSS setup doesn't work. */ efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels); + /* devlink creation, registration and lock */ + if (efx_probe_devlink(efx)) + pci_info(efx->pci_dev, "devlink registration failed"); + rc = ef100_register_netdev(efx); if (rc) goto fail; @@ -424,5 +434,7 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) } fail: + /* devlink unlock */ + efx_probe_devlink_done(efx); return rc; } diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index ad686c671ab8..e4aacb4ec666 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -1120,11 +1120,10 @@ int ef100_probe_netdev_pf(struct efx_nic *efx) return rc; rc = efx_ef100_get_base_mport(efx); - if (rc) { + if (rc) netif_warn(efx, probe, net_dev, "Failed to probe base mport rc %d; representors will not function\n", rc); - } rc = efx_init_tc(efx); if (rc) { diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c new file mode 100644 index 000000000000..fab06aaa4b8a --- /dev/null +++ b/drivers/net/ethernet/sfc/efx_devlink.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-only +/**************************************************************************** + * Driver for AMD network controllers and boards + * Copyright (C) 2023, Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, incorporated herein by reference. + */ + +#include +#include "net_driver.h" +#include "ef100_nic.h" +#include "efx_devlink.h" +#include "nic.h" +#include "mcdi.h" +#include "mcdi_functions.h" +#include "mcdi_pcol.h" + +struct efx_devlink { + struct efx_nic *efx; +}; + +static const struct devlink_ops sfc_devlink_ops = { +}; + +void efx_fini_devlink_start(struct efx_nic *efx) +{ + if (efx->devlink) + devl_lock(efx->devlink); +} + +void efx_fini_devlink(struct efx_nic *efx) +{ + if (efx->devlink) { + devl_unregister(efx->devlink); + devl_unlock(efx->devlink); + devlink_free(efx->devlink); + efx->devlink = NULL; + } +} + +int efx_probe_devlink(struct efx_nic *efx) +{ + struct efx_devlink *devlink_private; + + if (efx->type->is_vf) + return 0; + + efx->devlink = devlink_alloc(&sfc_devlink_ops, + sizeof(struct efx_devlink), + &efx->pci_dev->dev); + if (!efx->devlink) + return -ENOMEM; + + devl_lock(efx->devlink); + devlink_private = devlink_priv(efx->devlink); + devlink_private->efx = efx; + + devl_register(efx->devlink); + + return 0; +} + +void efx_probe_devlink_done(struct efx_nic *efx) +{ + if (!efx->devlink) + return; + + devl_unlock(efx->devlink); +} diff --git a/drivers/net/ethernet/sfc/efx_devlink.h b/drivers/net/ethernet/sfc/efx_devlink.h new file mode 100644 index 000000000000..55d0d8aeca1e --- /dev/null +++ b/drivers/net/ethernet/sfc/efx_devlink.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/**************************************************************************** + * Driver for AMD network controllers and boards + * Copyright (C) 2023, Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation, incorporated herein by reference. + */ + +#ifndef _EFX_DEVLINK_H +#define _EFX_DEVLINK_H + +#include "net_driver.h" +#include + +int efx_probe_devlink(struct efx_nic *efx); +void efx_probe_devlink_done(struct efx_nic *efx); +void efx_fini_devlink_start(struct efx_nic *efx); +void efx_fini_devlink(struct efx_nic *efx); + +#endif /* _EFX_DEVLINK_H */ diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 3b49e216768b..d036641dc043 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -994,6 +994,7 @@ enum efx_xdp_tx_queues_mode { * xdp_rxq_info structures? * @netdev_notifier: Netdevice notifier. * @tc: state for TC offload (EF100). + * @devlink: reference to devlink structure owned by this device * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. * @monitor_work: Hardware monitor workitem @@ -1179,6 +1180,7 @@ struct efx_nic { struct notifier_block netdev_notifier; struct efx_tc_state *tc; + struct devlink *devlink; unsigned int mem_bar; u32 reg_base; From patchwork Tue Jan 31 14:58:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123071 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 481DEC636D3 for ; Tue, 31 Jan 2023 14:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232301AbjAaO7D (ORCPT ); Tue, 31 Jan 2023 09:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232391AbjAaO6o (ORCPT ); Tue, 31 Jan 2023 09:58:44 -0500 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2057.outbound.protection.outlook.com [40.107.102.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1351613D42; Tue, 31 Jan 2023 06:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V+eq0ujv5CvYqj1dus3LwlItMV68MNzUiyhtBq0xogHU17Ye0n8yWN4KKAfHlN2dfx61lVL/yH02mwt8rwT3uEBLJYb7ldowzzHO2e1GYa/W/7GG2TgLFFvujA67N3blNOhLWTPH3EQXTaONH+s1/xXMmUrYMg80YtHHmwiznnxbEajPcq5wqyLBDUHBlqti27Qgx4ufaLOxkPdYTfU4tqj33LQmq655MIEH/CCueFMAbTqge3t5SVVUnmnQN1PY6O1jhGtUb9kNH0Qc3tl2D/ACW07Dzsr6m4B0oLGnK09jrh1K8Cg3yO/ljkMsRoWnqjc9cVyvvArIpg1SD3PA0w== 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=V050RbNsxSocucbRBSPTTBgRSGknieVHrU9I+ntuC4Y=; b=kyB3XHaOf21+GDlsARjBiWMdCuaI7xY7gHsUY4vFSZHe3+vKB1cNY7VEPuP78BqE+2XNWUks4k1XcXIGIv6WeiEEJXhK8EZhEklelfgrCPL0h4qHQaVIZRtS7tf1yMeibby8X/Q8uaiCt8yRYzyF/nbOoQPrv3m1q/kxYH/I2WCjffgAJRcpK7v2zyC3peu1iKZXXTgHlSWyNGzIVSCWjqSrEEGP/pRNm1zdI4aM9U11MKHlYf5EDeXMqsPu09NrSATM+jCXQVRT5kL9QiiOW+DKJzgpsBr1wN1ukMcNkpHuQljwaAsgKm252yY5cvKMc3U0Qe+KvwD/a6KWukBfyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=V050RbNsxSocucbRBSPTTBgRSGknieVHrU9I+ntuC4Y=; b=FJ17oN8FbhnpoiBOEbeX5lleJwFjNob0kk9rtQfTDtk9mVHg/DsdXQaP2qhFGdkUYrWphGfTAySP+XipiSOEXYDtjmHwayx6oOPCU0yT3LkchmmjEbjSUuOmO1u8luEWN75lwvB5DVrEZDGCs/72RZx6p0Ca4TRbp/iL3cH34LQ= Received: from DM6PR06CA0085.namprd06.prod.outlook.com (2603:10b6:5:336::18) by SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Tue, 31 Jan 2023 14:58:38 +0000 Received: from DM6NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::30) by DM6PR06CA0085.outlook.office365.com (2603:10b6:5:336::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT017.mail.protection.outlook.com (10.13.172.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.22 via Frontend Transport; Tue, 31 Jan 2023 14:58:38 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:37 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:35 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 2/8] sfc: add devlink info support for ef100 Date: Tue, 31 Jan 2023 14:58:16 +0000 Message-ID: <20230131145822.36208-3-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT017:EE_|SA0PR12MB4509:EE_ X-MS-Office365-Filtering-Correlation-Id: 0cf86172-b4b1-4968-7388-08db039ba2c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5CRhiae9EPI9YMDutCD3vcFFXcJEw4/fYgVNkwg+VdVYEUig02+3+AxtYZsJ9ecDqhLme36nymxlGW1CuJ5dj4kOOmxtd0148ejzNUmnroTX9Z0/XMtLLnwgir8TLVGkR9qsqlGH4x2UEvtsiREMtbfWXRYJ1xVMy6ovEC7Rygtl9gPIy4QpjYrP62B8SftxgIEUEdnTaSraxDmWCB23F5/U6p/45Qy8n4w7NNtpsLfzgK1/4x+tlSN0EU1RF0AIBiR4+oY0m5uEeFO1ZbI56r/aKUiAZMFjLP8ap9QpzlNF2aLCrmAapldO/SF+16dLpAkMSsJbZM34duhZ9NQbu+9ZxU80gk9ocPJtHvP8RW3VmmnUDqABRU0f4oGuowCh5qDlp1c/vprRn2iLNJzDVFTiMVUN1nX3wC4ZN274ZnyZMaOlnewvbaFoYtcYLXSUQ2M4xTyiMOkGXtWnYZooRl85LkyOXlqncsTkX2P8Xy83kCSzRZ4YnJxOZZbpTJQui2H0GIALTsjL+uoXikBkYIYSoPqlNd+LMZ3ceulbBwPfLS1e+qFN28dEEA730cDCxI0663Cdft8B5dFPnysb1Ms0x5n9sIAKSFGFIJtWpxCfUEv1p7/mmsUfgamQ9FNkTTChVFVL34du6UHi07BMHtjQRipdNJlk5+fJN4PXgVVepX6kZEZ7HBV1LN9cQyeuQChdzxH0O+kqC1ROArXCumfgOzE41WNawOT0WgDTvs3CxRDslPqxo72xTl2oDG3NitsG63mpWCUH2Y6EiYCa/wnnjHZWz0dGxEhNztY8ixI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(376002)(136003)(396003)(39860400002)(451199018)(36840700001)(40470700004)(46966006)(36860700001)(36756003)(40460700003)(82310400005)(6636002)(110136005)(316002)(5660300002)(54906003)(7416002)(426003)(336012)(356005)(2616005)(47076005)(86362001)(40480700001)(81166007)(82740400003)(26005)(186003)(2906002)(478600001)(2876002)(4326008)(30864003)(70586007)(70206006)(1076003)(6666004)(8676002)(8936002)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:38.7586 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0cf86172-b4b1-4968-7388-08db039ba2c2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Support for devlink info command. Signed-off-by: Alejandro Lucero --- Documentation/networking/devlink/sfc.rst | 57 ++++ MAINTAINERS | 1 + drivers/net/ethernet/sfc/efx_devlink.c | 404 +++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_devlink.h | 17 + drivers/net/ethernet/sfc/mcdi.c | 72 ++++ drivers/net/ethernet/sfc/mcdi.h | 3 + 6 files changed, 554 insertions(+) create mode 100644 Documentation/networking/devlink/sfc.rst diff --git a/Documentation/networking/devlink/sfc.rst b/Documentation/networking/devlink/sfc.rst new file mode 100644 index 000000000000..e2541a2f18ee --- /dev/null +++ b/Documentation/networking/devlink/sfc.rst @@ -0,0 +1,57 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================== +sfc devlink support +=================== + +This document describes the devlink features implemented by the ``sfc`` +device driver for the ef100 device. + +Info versions +============= + +The ``sfc`` driver reports the following versions + +.. list-table:: devlink info versions implemented + :widths: 5 5 90 + + * - Name + - Type + - Description + * - ``fw.mgmt.suc`` + - running + - For boards where the management function is split between multiple + control units, this is the SUC control unit's firmware version. + * - ``fw.mgmt.cmc`` + - running + - For boards where the management function is split between multiple + control units, this is the CMC control unit's firmware version. + * - ``fpga.rev`` + - running + - FPGA design revision. + * - ``fpga.app`` + - running + - Datapath programmable logic version. + * - ``fw.app`` + - running + - Datapath software/microcode/firmware version. + * - ``coproc.boot`` + - running + - SmartNIC application co-processor (APU) first stage boot loader version. + * - ``coproc.uboot`` + - running + - SmartNIC application co-processor (APU) co-operating system loader version. + * - ``coproc.main`` + - running + - SmartNIC application co-processor (APU) main operating system version. + * - ``coproc.recovery`` + - running + - SmartNIC application co-processor (APU) recovery operating system version. + * - ``fw.exprom`` + - running + - Expansion ROM version. For boards where the expansion ROM is split between + multiple images (e.g. PXE and UEFI), this is the specifically the PXE boot + ROM version. + * - ``fw.uefi`` + - running + - UEFI driver version (No UNDI support). diff --git a/MAINTAINERS b/MAINTAINERS index f82dd8d43c2b..57c9cb55cfd3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18920,6 +18920,7 @@ M: Martin Habets L: netdev@vger.kernel.org S: Supported F: drivers/net/ethernet/sfc/ +F: Documentation/networking/devlink/sfc.rst SFF/SFP/SFP+ MODULE SUPPORT M: Russell King diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c index fab06aaa4b8a..ff5adfe3905e 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.c +++ b/drivers/net/ethernet/sfc/efx_devlink.c @@ -21,7 +21,411 @@ struct efx_devlink { struct efx_nic *efx; }; +static int efx_devlink_info_nvram_partition(struct efx_nic *efx, + struct devlink_info_req *req, + unsigned int partition_type, + const char *version_name) +{ + char buf[EFX_MAX_VERSION_INFO_LEN]; + u16 version[4]; + int rc; + + rc = efx_mcdi_nvram_metadata(efx, partition_type, NULL, version, NULL, + 0); + if (rc) + return rc; + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", version[0], + version[1], version[2], version[3]); + devlink_info_version_stored_put(req, version_name, buf); + + return 0; +} + +static void efx_devlink_info_stored_versions(struct efx_nic *efx, + struct devlink_info_req *req) +{ + efx_devlink_info_nvram_partition(efx, req, NVRAM_PARTITION_TYPE_BUNDLE, + DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID); + efx_devlink_info_nvram_partition(efx, req, + NVRAM_PARTITION_TYPE_MC_FIRMWARE, + DEVLINK_INFO_VERSION_GENERIC_FW_MGMT); + efx_devlink_info_nvram_partition(efx, req, + NVRAM_PARTITION_TYPE_SUC_FIRMWARE, + EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC); + efx_devlink_info_nvram_partition(efx, req, + NVRAM_PARTITION_TYPE_EXPANSION_ROM, + EFX_DEVLINK_INFO_VERSION_FW_EXPROM); + efx_devlink_info_nvram_partition(efx, req, + NVRAM_PARTITION_TYPE_EXPANSION_UEFI, + EFX_DEVLINK_INFO_VERSION_FW_UEFI); +} + +#define EFX_VER_FLAG(_f) \ + (MC_CMD_GET_VERSION_V5_OUT_ ## _f ## _PRESENT_LBN) + +static void efx_devlink_info_running_v2(struct efx_nic *efx, + struct devlink_info_req *req, + unsigned int flags, efx_dword_t *outbuf) +{ + char buf[EFX_MAX_VERSION_INFO_LEN]; + union { + const __le32 *dwords; + const __le16 *words; + const char *str; + } ver; + struct rtc_time build_date; + unsigned int build_id; + size_t offset; + u64 tstamp; + + if (flags & BIT(EFX_VER_FLAG(BOARD_EXT_INFO))) { + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%s", + MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_NAME)); + devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_BOARD_ID, + buf); + + /* Favour full board version if present (in V5 or later) */ + if (~flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) { + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u", + MCDI_DWORD(outbuf, + GET_VERSION_V2_OUT_BOARD_REVISION)); + devlink_info_version_fixed_put(req, + DEVLINK_INFO_VERSION_GENERIC_BOARD_REV, + buf); + } + + ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_BOARD_SERIAL); + if (ver.str[0]) + devlink_info_board_serial_number_put(req, ver.str); + } + + if (flags & BIT(EFX_VER_FLAG(FPGA_EXT_INFO))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V2_OUT_FPGA_VERSION); + offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u_%c%u", + le32_to_cpu(ver.dwords[0]), + 'A' + le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2])); + + ver.str = MCDI_PTR(outbuf, GET_VERSION_V2_OUT_FPGA_EXTRA); + if (ver.str[0]) + snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset, + " (%s)", ver.str); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_FPGA_REV, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(CMC_EXT_INFO))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V2_OUT_CMCFW_VERSION); + offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), + le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + tstamp = MCDI_QWORD(outbuf, + GET_VERSION_V2_OUT_CMCFW_BUILD_DATE); + if (tstamp) { + rtc_time64_to_tm(tstamp, &build_date); + snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset, + " (%ptRd)", &build_date); + } + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_FW_MGMT_CMC, + buf); + } + + ver.words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_V2_OUT_VERSION); + offset = snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le16_to_cpu(ver.words[0]), le16_to_cpu(ver.words[1]), + le16_to_cpu(ver.words[2]), le16_to_cpu(ver.words[3])); + if (flags & BIT(EFX_VER_FLAG(MCFW_EXT_INFO))) { + build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_ID); + snprintf(&buf[offset], EFX_MAX_VERSION_INFO_LEN - offset, + " (%x) %s", build_id, + MCDI_PTR(outbuf, GET_VERSION_V2_OUT_MCFW_BUILD_NAME)); + } + devlink_info_version_running_put(req, + DEVLINK_INFO_VERSION_GENERIC_FW_MGMT, + buf); + + if (flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V2_OUT_SUCFW_VERSION); + tstamp = MCDI_QWORD(outbuf, + GET_VERSION_V2_OUT_SUCFW_BUILD_DATE); + rtc_time64_to_tm(tstamp, &build_date); + build_id = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_SUCFW_CHIP_ID); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, + "%u.%u.%u.%u type %x (%ptRd)", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), le32_to_cpu(ver.dwords[3]), + build_id, &build_date); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC, + buf); + } +} + +static void efx_devlink_info_running_v3(struct efx_nic *efx, + struct devlink_info_req *req, + unsigned int flags, efx_dword_t *outbuf) +{ + char buf[EFX_MAX_VERSION_INFO_LEN]; + union { + const __le32 *dwords; + const __le16 *words; + const char *str; + } ver; + + if (flags & BIT(EFX_VER_FLAG(DATAPATH_HW_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V3_OUT_DATAPATH_HW_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_DATAPATH_HW, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(DATAPATH_FW_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V3_OUT_DATAPATH_FW_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_DATAPATH_FW, + buf); + } +} + +static void efx_devlink_info_running_v4(struct efx_nic *efx, + struct devlink_info_req *req, + unsigned int flags, efx_dword_t *outbuf) +{ + char buf[EFX_MAX_VERSION_INFO_LEN]; + union { + const __le32 *dwords; + const __le16 *words; + const char *str; + } ver; + + if (flags & BIT(EFX_VER_FLAG(SOC_BOOT_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V4_OUT_SOC_BOOT_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_SOC_BOOT, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(SOC_UBOOT_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V4_OUT_SOC_UBOOT_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_SOC_UBOOT, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(SOC_MAIN_ROOTFS_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V4_OUT_SOC_MAIN_ROOTFS_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_SOC_MAIN, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(SOC_RECOVERY_BUILDROOT_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V4_OUT_SOC_RECOVERY_BUILDROOT_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_SOC_RECOVERY, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(SUCFW_VERSION)) && + ~flags & BIT(EFX_VER_FLAG(SUCFW_EXT_INFO))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V4_OUT_SUCFW_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC, + buf); + } +} + +static void efx_devlink_info_running_v5(struct efx_nic *efx, + struct devlink_info_req *req, + unsigned int flags, efx_dword_t *outbuf) +{ + char buf[EFX_MAX_VERSION_INFO_LEN]; + union { + const __le32 *dwords; + const __le16 *words; + const char *str; + } ver; + + if (flags & BIT(EFX_VER_FLAG(BOARD_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V5_OUT_BOARD_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + DEVLINK_INFO_VERSION_GENERIC_BOARD_REV, + buf); + } + + if (flags & BIT(EFX_VER_FLAG(BUNDLE_VERSION))) { + ver.dwords = (__le32 *)MCDI_PTR(outbuf, + GET_VERSION_V5_OUT_BUNDLE_VERSION); + + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le32_to_cpu(ver.dwords[0]), le32_to_cpu(ver.dwords[1]), + le32_to_cpu(ver.dwords[2]), + le32_to_cpu(ver.dwords[3])); + + devlink_info_version_running_put(req, + DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID, + buf); + } +} + +static void efx_devlink_info_running_versions(struct efx_nic *efx, + struct devlink_info_req *req) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_V5_OUT_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_VERSION_EXT_IN_LEN); + char buf[EFX_MAX_VERSION_INFO_LEN]; + union { + const __le32 *dwords; + const __le16 *words; + const char *str; + } ver; + size_t outlength; + unsigned int flags; + int rc; + + rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlength); + if (rc || outlength < MC_CMD_GET_VERSION_OUT_LEN) + return; + + /* Handle previous output */ + if (outlength < MC_CMD_GET_VERSION_V2_OUT_LEN) { + ver.words = (__le16 *)MCDI_PTR(outbuf, + GET_VERSION_EXT_OUT_VERSION); + snprintf(buf, EFX_MAX_VERSION_INFO_LEN, "%u.%u.%u.%u", + le16_to_cpu(ver.words[0]), + le16_to_cpu(ver.words[1]), + le16_to_cpu(ver.words[2]), + le16_to_cpu(ver.words[3])); + + devlink_info_version_running_put(req, + DEVLINK_INFO_VERSION_GENERIC_FW_MGMT, + buf); + return; + } + + /* Handle V2 additions */ + flags = MCDI_DWORD(outbuf, GET_VERSION_V2_OUT_FLAGS); + efx_devlink_info_running_v2(efx, req, flags, outbuf); + + if (outlength < MC_CMD_GET_VERSION_V3_OUT_LEN) + return; + + /* Handle V3 additions */ + efx_devlink_info_running_v3(efx, req, flags, outbuf); + + if (outlength < MC_CMD_GET_VERSION_V4_OUT_LEN) + return; + + /* Handle V4 additions */ + efx_devlink_info_running_v4(efx, req, flags, outbuf); + + if (outlength < MC_CMD_GET_VERSION_V5_OUT_LEN) + return; + + /* Handle V5 additions */ + efx_devlink_info_running_v5(efx, req, flags, outbuf); +} + +#define EFX_MAX_SERIALNUM_LEN (ETH_ALEN * 2 + 1) + +static void efx_devlink_info_board_cfg(struct efx_nic *efx, + struct devlink_info_req *req) +{ + char sn[EFX_MAX_SERIALNUM_LEN]; + u8 mac_address[ETH_ALEN]; + int rc; + + rc = efx_mcdi_get_board_cfg(efx, (u8 *)mac_address, NULL, NULL); + if (!rc) { + snprintf(sn, EFX_MAX_SERIALNUM_LEN, "%pm", mac_address); + devlink_info_serial_number_put(req, sn); + } +} + +static int efx_devlink_info_get(struct devlink *devlink, + struct devlink_info_req *req, + struct netlink_ext_ack *extack) +{ + struct efx_devlink *devlink_private = devlink_priv(devlink); + struct efx_nic *efx = devlink_private->efx; + + efx_devlink_info_board_cfg(efx, req); + efx_devlink_info_stored_versions(efx, req); + efx_devlink_info_running_versions(efx, req); + return 0; +} + static const struct devlink_ops sfc_devlink_ops = { + .info_get = efx_devlink_info_get, }; void efx_fini_devlink_start(struct efx_nic *efx) diff --git a/drivers/net/ethernet/sfc/efx_devlink.h b/drivers/net/ethernet/sfc/efx_devlink.h index 55d0d8aeca1e..8bcd077d8d8d 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.h +++ b/drivers/net/ethernet/sfc/efx_devlink.h @@ -14,6 +14,23 @@ #include "net_driver.h" #include +/* Custom devlink-info version object names for details that do not map to the + * generic standardized names. + */ +#define EFX_DEVLINK_INFO_VERSION_FW_MGMT_SUC "fw.mgmt.suc" +#define EFX_DEVLINK_INFO_VERSION_FW_MGMT_CMC "fw.mgmt.cmc" +#define EFX_DEVLINK_INFO_VERSION_FPGA_REV "fpga.rev" +#define EFX_DEVLINK_INFO_VERSION_DATAPATH_HW "fpga.app" +#define EFX_DEVLINK_INFO_VERSION_DATAPATH_FW DEVLINK_INFO_VERSION_GENERIC_FW_APP +#define EFX_DEVLINK_INFO_VERSION_SOC_BOOT "coproc.boot" +#define EFX_DEVLINK_INFO_VERSION_SOC_UBOOT "coproc.uboot" +#define EFX_DEVLINK_INFO_VERSION_SOC_MAIN "coproc.main" +#define EFX_DEVLINK_INFO_VERSION_SOC_RECOVERY "coproc.recovery" +#define EFX_DEVLINK_INFO_VERSION_FW_EXPROM "fw.exprom" +#define EFX_DEVLINK_INFO_VERSION_FW_UEFI "fw.uefi" + +#define EFX_MAX_VERSION_INFO_LEN 64 + int efx_probe_devlink(struct efx_nic *efx); void efx_probe_devlink_done(struct efx_nic *efx); void efx_fini_devlink_start(struct efx_nic *efx); diff --git a/drivers/net/ethernet/sfc/mcdi.c b/drivers/net/ethernet/sfc/mcdi.c index af338208eae9..a7f2c31071e8 100644 --- a/drivers/net/ethernet/sfc/mcdi.c +++ b/drivers/net/ethernet/sfc/mcdi.c @@ -2175,6 +2175,78 @@ int efx_mcdi_get_privilege_mask(struct efx_nic *efx, u32 *mask) return 0; } +int efx_mcdi_nvram_metadata(struct efx_nic *efx, unsigned int type, + u32 *subtype, u16 version[4], char *desc, + size_t descsize) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); + efx_dword_t *outbuf; + size_t outlen; + u32 flags; + int rc; + + outbuf = kzalloc(MC_CMD_NVRAM_METADATA_OUT_LENMAX_MCDI2, GFP_KERNEL); + if (!outbuf) + return -ENOMEM; + + MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); + + rc = efx_mcdi_rpc_quiet(efx, MC_CMD_NVRAM_METADATA, inbuf, + sizeof(inbuf), outbuf, + MC_CMD_NVRAM_METADATA_OUT_LENMAX_MCDI2, + &outlen); + if (rc) + goto out_free; + if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) { + rc = -EIO; + goto out_free; + } + + flags = MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS); + + if (desc && descsize > 0) { + if (flags & BIT(MC_CMD_NVRAM_METADATA_OUT_DESCRIPTION_VALID_LBN)) { + if (descsize <= + MC_CMD_NVRAM_METADATA_OUT_DESCRIPTION_NUM(outlen)) { + rc = -E2BIG; + goto out_free; + } + + strncpy(desc, + MCDI_PTR(outbuf, NVRAM_METADATA_OUT_DESCRIPTION), + MC_CMD_NVRAM_METADATA_OUT_DESCRIPTION_NUM(outlen)); + desc[MC_CMD_NVRAM_METADATA_OUT_DESCRIPTION_NUM(outlen)] = '\0'; + } else { + desc[0] = '\0'; + } + } + + if (subtype) { + if (flags & BIT(MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) + *subtype = MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_SUBTYPE); + else + *subtype = 0; + } + + if (version) { + if (flags & BIT(MC_CMD_NVRAM_METADATA_OUT_VERSION_VALID_LBN)) { + version[0] = MCDI_WORD(outbuf, NVRAM_METADATA_OUT_VERSION_W); + version[1] = MCDI_WORD(outbuf, NVRAM_METADATA_OUT_VERSION_X); + version[2] = MCDI_WORD(outbuf, NVRAM_METADATA_OUT_VERSION_Y); + version[3] = MCDI_WORD(outbuf, NVRAM_METADATA_OUT_VERSION_Z); + } else { + version[0] = 0; + version[1] = 0; + version[2] = 0; + version[3] = 0; + } + } + +out_free: + kfree(outbuf); + return rc; +} + #ifdef CONFIG_SFC_MTD #define EFX_MCDI_NVRAM_LEN_MAX 128 diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h index 7e35fec9da35..5cb202684858 100644 --- a/drivers/net/ethernet/sfc/mcdi.h +++ b/drivers/net/ethernet/sfc/mcdi.h @@ -378,6 +378,9 @@ int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, size_t *size_out, size_t *erase_size_out, bool *protected_out); int efx_new_mcdi_nvram_test_all(struct efx_nic *efx); +int efx_mcdi_nvram_metadata(struct efx_nic *efx, unsigned int type, + u32 *subtype, u16 version[4], char *desc, + size_t descsize); int efx_mcdi_nvram_test_all(struct efx_nic *efx); int efx_mcdi_handle_assertion(struct efx_nic *efx); int efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode); From patchwork Tue Jan 31 14:58:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123074 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 3ED74C38142 for ; Tue, 31 Jan 2023 14:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232376AbjAaO7I (ORCPT ); Tue, 31 Jan 2023 09:59:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232417AbjAaO6r (ORCPT ); Tue, 31 Jan 2023 09:58:47 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2042.outbound.protection.outlook.com [40.107.100.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB04E234D5; Tue, 31 Jan 2023 06:58:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NRIgHJLWQpDzHx1pNPqqz33Yx/jTm5M5GAhgCfW+kVYji/j/UcSxRDqi1wMa9EblpGv8n8d52MluXpst695HMvrIqIEc6Xmz9fDBgZ4NOpobq+YoX1OhfDZYtsSgSyUGXr+q55S0efhIKaMigV75/FkboRJZA5GdVkDhql7tyxQSUVIrBtZYJOCBV4uGjCarowE9sUkgU9cDLufgf8xZmJdUzhoGOt7X8q8hDzX7EHYoMhyw7JNsqYFhJA2rm079WfNkzxJziO4BqJAM9U7Eg2b/6ml9La10xdhC2IvgZBoGTR8NXXAp/2i9wWsrGewQyGsPZjogWVTp4ZpxcRjZEA== 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=+ySfW8tfsKE9K3stbxr6s+lo/S5VziImX0Yg4W1V8ZE=; b=CgrL54fxujeQ8HQ7Vv8KepL0avKfbbpANMUTvpBZh5KV6V4AHxMWX58psquWrgFl77eW4XrAd04NDEfb9njoq0wvumIeoTNxx6uVS2+6ieCI+4wiPmyp2VrTIiP+5MKNROa5JpciXyZF4eWchE3z8KsZOxcEkLRE0lvAGapvvrtuKfKiZ+MaSE24iVwENoEnIZyB1LJdgwrKQk3Z6Nwkf1FN6hmerIoRwc+pn2ATyPSrvLMtBRNSz/ixF5yCuz2JuLYesOoTraKRHaFiE4ThJvs35JvW7S1inxuXb50JkvizP0HjI6/Tg94OouX2q9z2xPt5NEmpp0dFBjE5/AfLrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+ySfW8tfsKE9K3stbxr6s+lo/S5VziImX0Yg4W1V8ZE=; b=m066SRG0xbbbZPFIrvsUtJdPFtZk24LIsZX7XzcOK22/CUDZgYjA1OD094RwgyKk/ppMeGuEMlNcwWqiZeD5VgeiXvx3xLqr5PKOf9oNe+g6tId6KsdSDqFG9CsCR6Z+HkNXVVH+LDrmUeNJ76r9sR8IWmWqTv3Cl8OCLWOBo/A= Received: from BN9P221CA0005.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::28) by MN2PR12MB4501.namprd12.prod.outlook.com (2603:10b6:208:269::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Tue, 31 Jan 2023 14:58:41 +0000 Received: from BN8NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::97) by BN9P221CA0005.outlook.office365.com (2603:10b6:408:10a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT039.mail.protection.outlook.com (10.13.177.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.21 via Frontend Transport; Tue, 31 Jan 2023 14:58:41 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:40 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 06:58:40 -0800 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:38 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 3/8] sfc: enumerate mports in ef100 Date: Tue, 31 Jan 2023 14:58:17 +0000 Message-ID: <20230131145822.36208-4-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT039:EE_|MN2PR12MB4501:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a695539-1462-42d5-7ee1-08db039ba415 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: noU+FMmPOICdBaTDWhOwHisAeFb2uJe9Ww0yygau63Al/Gzokc5z54OFwMtSfodBULfBNfergHdQkueNwQB4AlqXsRnotus71SpneKw5phQu5iwz8YGwWchDrwd7Bv2P0MxRfhgwCfYr5ldWKrTS9QlRXKaAhwpDghsCet0WjHBhXhCjpZ2Ls/4RayzvwE4oqOMTK3WAIhwl42ek31+lk34hhRi6iTGSL8ZudBk7FzeGTfrrPnLVcWPuHQHXnCytbopxaMcEr/tP1HRr9Y1Ozlf2jfcAcPAbnpfEksYu1KvSyQE1RZrN8tXBAAKxHoTnL9k/nQxSbDCteWzZsoHEjn7cMA+BqpCyTZ6U7K7RVxzCvPSL4mx2FAIvmEwsyawbTJdTKRsw7y6u1i8C/dqAJTt+8/xNthnAh62EdQIizwqI91DUoSSmSwuSGQGVwSWwwlzFLRL3gqZ1Knh3AvCH6kOk7zCbSgjLp8V45tzRF1h3a5Y2+wrjV5dBrcvj4jRv+16aecFAUOGK2xMAcQXvtvqP/JRkG7cnbloi1tMl0cyGGVriQqDHqBurRZ9Inn6E2Pu94wyetpfpqsZ2GN+e4KpBOEv6g+1kcgJUdvGzggih+hU3rc4GhHGW0OMejPoahlHinh+ThkA87/twS+rT2OBPMQKd1idXhPZqr1K0OP4aRYp3AuXhHDpGf0V6myw4DcJGCPC5ALMcYaPNjjyBAu75I0H/2XhPrJyRZHJHrhpTt2rU9EruDwKN22oyACCb X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(396003)(136003)(39860400002)(376002)(346002)(451199018)(46966006)(40470700004)(36840700001)(26005)(186003)(2906002)(82740400003)(4326008)(70586007)(36860700001)(40460700003)(86362001)(2876002)(81166007)(30864003)(5660300002)(7416002)(41300700001)(8936002)(356005)(336012)(40480700001)(83380400001)(426003)(47076005)(2616005)(36756003)(54906003)(82310400005)(8676002)(6636002)(70206006)(110136005)(316002)(478600001)(1076003)(6666004)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:41.0274 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5a695539-1462-42d5-7ee1-08db039ba415 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4501 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero MAE ports (mports) are the ports on the EF100 embedded switch such as networking PCIe functions, the physical port, and potentially others. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef100_nic.c | 24 ++++ drivers/net/ethernet/sfc/ef100_nic.h | 4 + drivers/net/ethernet/sfc/ef100_rep.c | 22 +++ drivers/net/ethernet/sfc/ef100_rep.h | 2 + drivers/net/ethernet/sfc/mae.c | 191 ++++++++++++++++++++++++++ drivers/net/ethernet/sfc/mae.h | 37 +++++ drivers/net/ethernet/sfc/mcdi.h | 5 + drivers/net/ethernet/sfc/net_driver.h | 4 + 8 files changed, 289 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index e4aacb4ec666..767edb1d922c 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -747,6 +747,18 @@ static int efx_ef100_get_base_mport(struct efx_nic *efx) id); nic_data->base_mport = id; nic_data->have_mport = true; + + /* Construct mport selector for "calling PF" */ + efx_mae_mport_uplink(efx, &selector); + /* Look up actual mport ID */ + rc = efx_mae_lookup_mport(efx, selector, &id); + if (rc) + return rc; + if (id >> 16) + netif_warn(efx, probe, efx->net_dev, "Bad own m-port id %#x\n", + id); + nic_data->own_mport = id; + nic_data->have_own_mport = true; return 0; } #endif @@ -1125,6 +1137,14 @@ int ef100_probe_netdev_pf(struct efx_nic *efx) "Failed to probe base mport rc %d; representors will not function\n", rc); + rc = efx_init_mae(efx); + if (rc) + netif_warn(efx, probe, net_dev, + "Failed to init MAE rc %d; representors will not function\n", + rc); + else + efx_ef100_init_reps(efx); + rc = efx_init_tc(efx); if (rc) { /* Either we don't have an MAE at all (i.e. legacy v-switching), @@ -1156,6 +1176,10 @@ void ef100_remove(struct efx_nic *efx) { struct ef100_nic_data *nic_data = efx->nic_data; + if (efx->mae) { + efx_ef100_fini_reps(efx); + efx_fini_mae(efx); + } efx_mcdi_detach(efx); efx_mcdi_fini(efx); if (nic_data) diff --git a/drivers/net/ethernet/sfc/ef100_nic.h b/drivers/net/ethernet/sfc/ef100_nic.h index 0295933145fa..496aea43c60f 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.h +++ b/drivers/net/ethernet/sfc/ef100_nic.h @@ -74,6 +74,10 @@ struct ef100_nic_data { u64 stats[EF100_STAT_COUNT]; u32 base_mport; bool have_mport; /* base_mport was populated successfully */ + u32 own_mport; + u32 local_mae_intf; /* interface_idx that corresponds to us, in mport enumerate */ + bool have_own_mport; /* own_mport was populated successfully */ + bool have_local_intf; /* local_mae_intf was populated successfully */ bool grp_mae; /* MAE Privilege */ u16 tso_max_hdr_len; u16 tso_max_payload_num_segs; diff --git a/drivers/net/ethernet/sfc/ef100_rep.c b/drivers/net/ethernet/sfc/ef100_rep.c index 81ab22c74635..ebe7b1275713 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.c +++ b/drivers/net/ethernet/sfc/ef100_rep.c @@ -9,6 +9,7 @@ * by the Free Software Foundation, incorporated herein by reference. */ +#include #include "ef100_rep.h" #include "ef100_netdev.h" #include "ef100_nic.h" @@ -341,6 +342,27 @@ void efx_ef100_fini_vfreps(struct efx_nic *efx) efx_ef100_vfrep_destroy(efx, efv); } +void efx_ef100_init_reps(struct efx_nic *efx) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + int rc; + + nic_data->have_local_intf = false; + rc = efx_mae_enumerate_mports(efx); + if (rc) + pci_warn(efx->pci_dev, + "Could not enumerate mports (rc=%d), are we admin?", + rc); +} + +void efx_ef100_fini_reps(struct efx_nic *efx) +{ + struct efx_mae *mae = efx->mae; + + rhashtable_free_and_destroy(&mae->mports_ht, efx_mae_remove_mport, + NULL); +} + static int efx_ef100_rep_poll(struct napi_struct *napi, int weight) { struct efx_rep *efv = container_of(napi, struct efx_rep, napi); diff --git a/drivers/net/ethernet/sfc/ef100_rep.h b/drivers/net/ethernet/sfc/ef100_rep.h index c21bc716f847..328ac0cbb532 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.h +++ b/drivers/net/ethernet/sfc/ef100_rep.h @@ -67,4 +67,6 @@ void efx_ef100_rep_rx_packet(struct efx_rep *efv, struct efx_rx_buffer *rx_buf); */ struct efx_rep *efx_ef100_find_rep_by_mport(struct efx_nic *efx, u16 mport); extern const struct net_device_ops efx_ef100_rep_netdev_ops; +void efx_ef100_init_reps(struct efx_nic *efx); +void efx_ef100_fini_reps(struct efx_nic *efx); #endif /* EF100_REP_H */ diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index 583baf69981c..725a3ab31087 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -9,8 +9,11 @@ * by the Free Software Foundation, incorporated herein by reference. */ +#include +#include "ef100_nic.h" #include "mae.h" #include "mcdi.h" +#include "mcdi_pcol.h" #include "mcdi_pcol_mae.h" int efx_mae_allocate_mport(struct efx_nic *efx, u32 *id, u32 *label) @@ -490,6 +493,163 @@ static bool efx_mae_asl_id(u32 id) return !!(id & BIT(31)); } +/* mport handling */ +static const struct rhashtable_params efx_mae_mports_ht_params = { + .key_len = sizeof(u32), + .key_offset = offsetof(struct mae_mport_desc, mport_id), + .head_offset = offsetof(struct mae_mport_desc, linkage), +}; + +struct mae_mport_desc *efx_mae_get_mport(struct efx_nic *efx, u32 mport_id) +{ + return rhashtable_lookup_fast(&efx->mae->mports_ht, &mport_id, + efx_mae_mports_ht_params); +} + +static int efx_mae_add_mport(struct efx_nic *efx, struct mae_mport_desc *desc) +{ + struct efx_mae *mae = efx->mae; + int rc; + + rc = rhashtable_insert_fast(&mae->mports_ht, &desc->linkage, + efx_mae_mports_ht_params); + + if (rc) { + pci_err(efx->pci_dev, "Failed to insert MPORT %08x, rc %d\n", + desc->mport_id, rc); + kfree(desc); + return rc; + } + + return rc; +} + +void efx_mae_remove_mport(void *desc, void *arg) +{ + struct mae_mport_desc *mport = desc; + + synchronize_rcu(); + kfree(mport); +} + +static int efx_mae_process_mport(struct efx_nic *efx, + struct mae_mport_desc *desc) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct mae_mport_desc *mport; + + mport = efx_mae_get_mport(efx, desc->mport_id); + if (!IS_ERR_OR_NULL(mport)) { + netif_err(efx, drv, efx->net_dev, + "mport with id %u does exist!!!\n", desc->mport_id); + return -EEXIST; + } + + if (nic_data->have_own_mport && + desc->mport_id == nic_data->own_mport) { + WARN_ON(desc->mport_type != MAE_MPORT_DESC_MPORT_TYPE_VNIC); + WARN_ON(desc->vnic_client_type != + MAE_MPORT_DESC_VNIC_CLIENT_TYPE_FUNCTION); + nic_data->local_mae_intf = desc->interface_idx; + nic_data->have_local_intf = true; + pci_dbg(efx->pci_dev, "MAE interface_idx is %u\n", + nic_data->local_mae_intf); + } + + return efx_mae_add_mport(efx, desc); +} + +#define MCDI_MPORT_JOURNAL_LEN \ + ALIGN(MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LENMAX_MCDI2, 4) + +int efx_mae_enumerate_mports(struct efx_nic *efx) +{ + efx_dword_t *outbuf = kzalloc(MCDI_MPORT_JOURNAL_LEN, GFP_KERNEL); + MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_MPORT_READ_JOURNAL_IN_LEN); + MCDI_DECLARE_STRUCT_PTR(desc); + size_t outlen, stride, count; + int rc = 0, i; + + if (!outbuf) + return -ENOMEM; + do { + rc = efx_mcdi_rpc(efx, MC_CMD_MAE_MPORT_READ_JOURNAL, inbuf, + sizeof(inbuf), outbuf, + MCDI_MPORT_JOURNAL_LEN, &outlen); + if (rc) + goto fail; + if (outlen < MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA_OFST) { + rc = -EIO; + goto fail; + } + count = MCDI_DWORD(outbuf, MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_COUNT); + if (!count) + continue; /* not break; we want to look at MORE flag */ + stride = MCDI_DWORD(outbuf, MAE_MPORT_READ_JOURNAL_OUT_SIZEOF_MPORT_DESC); + if (stride < MAE_MPORT_DESC_LEN) { + rc = -EIO; + goto fail; + } + if (outlen < MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LEN(count * stride)) { + rc = -EIO; + goto fail; + } + + for (i = 0; i < count; i++) { + struct mae_mport_desc *d; + + d = kzalloc(sizeof(*d), GFP_KERNEL); + if (!d) { + rc = -ENOMEM; + goto fail; + } + + desc = (efx_dword_t *) + _MCDI_PTR(outbuf, MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA_OFST + + i * stride); + d->mport_id = MCDI_STRUCT_DWORD(desc, MAE_MPORT_DESC_MPORT_ID); + d->flags = MCDI_STRUCT_DWORD(desc, MAE_MPORT_DESC_FLAGS); + d->caller_flags = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_CALLER_FLAGS); + d->mport_type = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_MPORT_TYPE); + switch (d->mport_type) { + case MAE_MPORT_DESC_MPORT_TYPE_NET_PORT: + d->port_idx = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_NET_PORT_IDX); + break; + case MAE_MPORT_DESC_MPORT_TYPE_ALIAS: + d->alias_mport_id = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_ALIAS_DELIVER_MPORT_ID); + break; + case MAE_MPORT_DESC_MPORT_TYPE_VNIC: + d->vnic_client_type = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_VNIC_CLIENT_TYPE); + d->interface_idx = MCDI_STRUCT_DWORD(desc, + MAE_MPORT_DESC_VNIC_FUNCTION_INTERFACE); + d->pf_idx = MCDI_STRUCT_WORD(desc, + MAE_MPORT_DESC_VNIC_FUNCTION_PF_IDX); + d->vf_idx = MCDI_STRUCT_WORD(desc, + MAE_MPORT_DESC_VNIC_FUNCTION_VF_IDX); + break; + default: + /* Unknown mport_type, just accept it */ + break; + } + rc = efx_mae_process_mport(efx, d); + /* Any failure will be due to memory allocation faiure, + * so there is no point to try subsequent entries. + */ + if (rc) + goto fail; + } + } while (MCDI_FIELD(outbuf, MAE_MPORT_READ_JOURNAL_OUT, MORE) && + !WARN_ON(!count)); +fail: + kfree(outbuf); + return rc; +} + int efx_mae_alloc_action_set(struct efx_nic *efx, struct efx_tc_action_set *act) { MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN); @@ -805,3 +965,34 @@ int efx_mae_delete_rule(struct efx_nic *efx, u32 id) return -EIO; return 0; } + +int efx_init_mae(struct efx_nic *efx) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct efx_mae *mae; + int rc; + + if (!nic_data->have_mport) + return -EINVAL; + + mae = kmalloc(sizeof(*mae), GFP_KERNEL); + if (!mae) + return -ENOMEM; + + rc = rhashtable_init(&mae->mports_ht, &efx_mae_mports_ht_params); + if (rc < 0) { + kfree(mae); + return rc; + } + efx->mae = mae; + mae->efx = efx; + return 0; +} + +void efx_fini_mae(struct efx_nic *efx) +{ + struct efx_mae *mae = efx->mae; + + kfree(mae); + efx->mae = NULL; +} diff --git a/drivers/net/ethernet/sfc/mae.h b/drivers/net/ethernet/sfc/mae.h index 72343e90e222..e1f057f01f08 100644 --- a/drivers/net/ethernet/sfc/mae.h +++ b/drivers/net/ethernet/sfc/mae.h @@ -27,6 +27,40 @@ void efx_mae_mport_mport(struct efx_nic *efx, u32 mport_id, u32 *out); int efx_mae_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id); +struct mae_mport_desc { + u32 mport_id; + u32 flags; + u32 caller_flags; /* enum mae_mport_desc_caller_flags */ + u32 mport_type; /* MAE_MPORT_DESC_MPORT_TYPE_* */ + union { + u32 port_idx; /* for mport_type == NET_PORT */ + u32 alias_mport_id; /* for mport_type == ALIAS */ + struct { /* for mport_type == VNIC */ + u32 vnic_client_type; /* MAE_MPORT_DESC_VNIC_CLIENT_TYPE_* */ + u32 interface_idx; + u16 pf_idx; + u16 vf_idx; + }; + }; + struct rhash_head linkage; + struct efx_rep *efv; +}; + +int efx_mae_enumerate_mports(struct efx_nic *efx); +struct mae_mport_desc *efx_mae_get_mport(struct efx_nic *efx, u32 mport_id); +void efx_mae_put_mport(struct efx_nic *efx, struct mae_mport_desc *desc); + +/** + * struct efx_mae - MAE information + * + * @efx: The associated NIC + * @mports_ht: m-port descriptions from MC_CMD_MAE_MPORT_READ_JOURNAL + */ +struct efx_mae { + struct efx_nic *efx; + struct rhashtable mports_ht; +}; + int efx_mae_start_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue); int efx_mae_stop_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue); void efx_mae_counters_grant_credits(struct work_struct *work); @@ -60,4 +94,7 @@ int efx_mae_insert_rule(struct efx_nic *efx, const struct efx_tc_match *match, u32 prio, u32 acts_id, u32 *id); int efx_mae_delete_rule(struct efx_nic *efx, u32 id); +int efx_init_mae(struct efx_nic *efx); +void efx_fini_mae(struct efx_nic *efx); +void efx_mae_remove_mport(void *desc, void *arg); #endif /* EF100_MAE_H */ diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h index 5cb202684858..b139b76febff 100644 --- a/drivers/net/ethernet/sfc/mcdi.h +++ b/drivers/net/ethernet/sfc/mcdi.h @@ -229,6 +229,9 @@ void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); #define MCDI_WORD(_buf, _field) \ ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field))) +#define MCDI_STRUCT_WORD(_buf, _field) \ + ((void)BUILD_BUG_ON_ZERO(_field ## _LEN != 2), \ + le16_to_cpu(*(__force const __le16 *)MCDI_STRUCT_PTR(_buf, _field))) /* Write a 16-bit field defined in the protocol as being big-endian. */ #define MCDI_STRUCT_SET_WORD_BE(_buf, _field, _value) do { \ BUILD_BUG_ON(_field ## _LEN != 2); \ @@ -241,6 +244,8 @@ void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); EFX_POPULATE_DWORD_1(*_MCDI_STRUCT_DWORD(_buf, _field), EFX_DWORD_0, _value) #define MCDI_DWORD(_buf, _field) \ EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0) +#define MCDI_STRUCT_DWORD(_buf, _field) \ + EFX_DWORD_FIELD(*_MCDI_STRUCT_DWORD(_buf, _field), EFX_DWORD_0) /* Write a 32-bit field defined in the protocol as being big-endian. */ #define MCDI_STRUCT_SET_DWORD_BE(_buf, _field, _value) do { \ BUILD_BUG_ON(_field ## _LEN != 4); \ diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index d036641dc043..bc9efbfb3d6b 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -845,6 +845,8 @@ enum efx_xdp_tx_queues_mode { EFX_XDP_TX_QUEUES_BORROWED /* queues borrowed from net stack */ }; +struct efx_mae; + /** * struct efx_nic - an Efx NIC * @name: Device name (net device name or bus id before net device registered) @@ -881,6 +883,7 @@ enum efx_xdp_tx_queues_mode { * @msi_context: Context for each MSI * @extra_channel_types: Types of extra (non-traffic) channels that * should be allocated for this NIC + * @mae: Details of the Match Action Engine * @xdp_tx_queue_count: Number of entries in %xdp_tx_queues. * @xdp_tx_queues: Array of pointers to tx queues used for XDP transmit. * @xdp_txq_queues_mode: XDP TX queues sharing strategy. @@ -1044,6 +1047,7 @@ struct efx_nic { struct efx_msi_context msi_context[EFX_MAX_CHANNELS]; const struct efx_channel_type * extra_channel_type[EFX_MAX_EXTRA_CHANNELS]; + struct efx_mae *mae; unsigned int xdp_tx_queue_count; struct efx_tx_queue **xdp_tx_queues; From patchwork Tue Jan 31 14:58:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123073 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 65507C6379F for ; Tue, 31 Jan 2023 14:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbjAaO7G (ORCPT ); Tue, 31 Jan 2023 09:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjAaO6r (ORCPT ); Tue, 31 Jan 2023 09:58:47 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2076.outbound.protection.outlook.com [40.107.92.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F06112F14; Tue, 31 Jan 2023 06:58:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X28A8jLpBgrFUSrjC+m9fiyf9Hn/7rCbemAn6XRhGRu6ZxbJCs8zNDPg2JCl/RaOco3090EFiOyXe5omYzHhj3VcYr5Ra8Ccoxf0NlXRUmQm9SkyIBpjHMZtKhW9ENKW56t6yD50iiiYCKLGM3YDA6ig/XClpXEECEcqSmZ41vDHKJ94k1unaRArZKTVHShnoa4pV1T/niOld3FlW8VxX22ejELl3BC6dSItM1+TGAlqCUV0ZWU1qswj/RuXFzzivBh6OlPueyPGdiK64q0C3gRonA04h2YmbHHjlXFhvgGumeNduXNfEONBB2H11QHSmwPDAnJhQDoxHcL9Vf5vfw== 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=PT9vGe9K91fu7mj2f9y5+TgaW04AXIJU1aYRYXPdsrg=; b=hOVHGboWjLbq9Ts3AQHoV/U5M/qDUoIuLn5B7wokVJ5mReYnFawLWhh6rs06ZAtJTIUGWkyyFZZfnjxJfjnJuPIVVsuv1NcRFZYnemR1XOufKmOiqCHfVhgPJ5MB5kjGsCVRKxNXwfBld2+DAdDhETzxqpuZkNx6Kw0NqJe6Os7pRhL2szs9RNcZ8HYlHlHcmbh+vt1tZDfGxv4d5IjQbLdJkt4lcbdCeQlHP7rO0upl3qWeaBQfhFt4UnEu/0TfVrh284JL/oOU+dCqJiNwB9SmRlFBXaeErqb19mLB9j0cW5YijzjWAeZjnx1CStGo+lGvx5cq5A2JU/cjCeU2tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PT9vGe9K91fu7mj2f9y5+TgaW04AXIJU1aYRYXPdsrg=; b=hlw/Y/yGHAupk6qgAJIvibqKDGSZyhKLTKf/7CB1E0dd6TDyHl9/Ckwid/vRamIPivcbfeT+RTHN8cn1/TEEyedPQT0UGvL+SWhQIC4nbnUYJkTZEcceYahnPApAGwH2/MxW+rYRaJy1ba8DV9qHWT9Nrlvak/R4jdAo6CccgYI= Received: from DM6PR01CA0014.prod.exchangelabs.com (2603:10b6:5:296::19) by DM6PR12MB4927.namprd12.prod.outlook.com (2603:10b6:5:20a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36; Tue, 31 Jan 2023 14:58:43 +0000 Received: from DM6NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::6f) by DM6PR01CA0014.outlook.office365.com (2603:10b6:5:296::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT088.mail.protection.outlook.com (10.13.172.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.22 via Frontend Transport; Tue, 31 Jan 2023 14:58:43 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:42 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:41 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 4/8] sfc: add mport lookup based on driver's mport data Date: Tue, 31 Jan 2023 14:58:18 +0000 Message-ID: <20230131145822.36208-5-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT088:EE_|DM6PR12MB4927:EE_ X-MS-Office365-Filtering-Correlation-Id: 13030bfa-2faa-458d-5b78-08db039ba568 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hjbhj8x/qpM962VmrucaY5j+WAlDIfJWO2RLd8FibiQlTpBgnwuD3beyydfchjQzckIS4fMR+7+Kr99wttD/onfteWfu7o5mqRZx4HGJ+RVTxj7q1O/K7ErfUjzlnNBKXVJIa9mvpoCJK7WjX3n58J25Wf+8kMNRmmuuMu5GR96X3xj3v28z2Gh7IYPWapYUL9sOld2TEqpRy9gqKUsqFtef1/pbxgxHckETha7hwTUTGtP1Kp0Xt3i9WG5WzT0MzgZdMC74blbWM7kf5M+HhvUtgsh/oI8KeFz68XRAK4ecPvrsj2xUVmXIQgqeHnBsm0Xk9MeRbKFkHpqAM2k6FnnIfJAVaD0QPUEy4EQzqkTkSslC3sW4zpT3dRbDWU8UcapUuZ3QCX/s/P4s8KSUm7ajLHr55O/PgrbyKMINDkPQb/W8SzJD4bRorM/sxazUZgBnzsR8MVfvWjq2hMKcxx3FuGPfe7rLEIr3/ezLqdgalxzYIVn7LKN3pmuDaZZWPBA47VWXxp0cqxSvwHJyYpDggBMh5eUI1mM3iJ+v+WPmkU1htgkI/nOH1hMqqsE/7hWQoxAYRcE0Cx5VIj7Eu0P83YjXRXPqAtyKrJjS3ruZmooBcExCaRC/C3Rtcl4HGLrBTeKMbLZTlXQEgOEoxLVRWE8kZeirS5rw89xtYHNhVF7dmAUTVTmDw70y05Fa8y0TYHxSmpWC0fqXNiWtt/E6MmwJglj+dnRODw/I6Qc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(376002)(396003)(136003)(39860400002)(451199018)(40470700004)(36840700001)(46966006)(47076005)(2876002)(8676002)(70206006)(4326008)(36860700001)(41300700001)(8936002)(70586007)(336012)(83380400001)(426003)(478600001)(86362001)(2906002)(316002)(6666004)(40480700001)(82740400003)(82310400005)(1076003)(6636002)(81166007)(5660300002)(26005)(186003)(356005)(36756003)(110136005)(40460700003)(7416002)(2616005)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:43.2169 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13030bfa-2faa-458d-5b78-08db039ba568 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4927 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Obtaining mport id is based on asking the firmware about it. This is still needed for mport initialization itself, but once the mport data is now kept by the driver, further mport id request can be satisfied internally without firmware interaction. Previous function is just modified in name making clear the firmware interaction. The new function uses the old name and looks for the data in the mport data structure. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef100_nic.c | 4 ++-- drivers/net/ethernet/sfc/ef100_rep.c | 5 +---- drivers/net/ethernet/sfc/mae.c | 27 ++++++++++++++++++++++++++- drivers/net/ethernet/sfc/mae.h | 2 ++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index 767edb1d922c..04774f33b493 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -736,7 +736,7 @@ static int efx_ef100_get_base_mport(struct efx_nic *efx) /* Construct mport selector for "physical network port" */ efx_mae_mport_wire(efx, &selector); /* Look up actual mport ID */ - rc = efx_mae_lookup_mport(efx, selector, &id); + rc = efx_mae_fw_lookup_mport(efx, selector, &id); if (rc) return rc; /* The ID should always fit in 16 bits, because that's how wide the @@ -751,7 +751,7 @@ static int efx_ef100_get_base_mport(struct efx_nic *efx) /* Construct mport selector for "calling PF" */ efx_mae_mport_uplink(efx, &selector); /* Look up actual mport ID */ - rc = efx_mae_lookup_mport(efx, selector, &id); + rc = efx_mae_fw_lookup_mport(efx, selector, &id); if (rc) return rc; if (id >> 16) diff --git a/drivers/net/ethernet/sfc/ef100_rep.c b/drivers/net/ethernet/sfc/ef100_rep.c index ebe7b1275713..9cd1a3ac67e0 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.c +++ b/drivers/net/ethernet/sfc/ef100_rep.c @@ -243,14 +243,11 @@ static struct efx_rep *efx_ef100_rep_create_netdev(struct efx_nic *efx, static int efx_ef100_configure_rep(struct efx_rep *efv) { struct efx_nic *efx = efv->parent; - u32 selector; int rc; efv->rx_pring_size = EFX_REP_DEFAULT_PSEUDO_RING_SIZE; - /* Construct mport selector for corresponding VF */ - efx_mae_mport_vf(efx, efv->idx, &selector); /* Look up actual mport ID */ - rc = efx_mae_lookup_mport(efx, selector, &efv->mport); + rc = efx_mae_lookup_mport(efx, efv->idx, &efv->mport); if (rc) return rc; pci_dbg(efx->pci_dev, "VF %u has mport ID %#x\n", efv->idx, efv->mport); diff --git a/drivers/net/ethernet/sfc/mae.c b/drivers/net/ethernet/sfc/mae.c index 725a3ab31087..6321fd393fc3 100644 --- a/drivers/net/ethernet/sfc/mae.c +++ b/drivers/net/ethernet/sfc/mae.c @@ -97,7 +97,7 @@ void efx_mae_mport_mport(struct efx_nic *efx __always_unused, u32 mport_id, u32 } /* id is really only 24 bits wide */ -int efx_mae_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id) +int efx_mae_fw_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id) { MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_MPORT_LOOKUP_OUT_LEN); MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_MPORT_LOOKUP_IN_LEN); @@ -488,6 +488,31 @@ int efx_mae_free_counter(struct efx_nic *efx, struct efx_tc_counter *cnt) return 0; } +int efx_mae_lookup_mport(struct efx_nic *efx, u32 vf_idx, u32 *id) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct efx_mae *mae = efx->mae; + struct rhashtable_iter walk; + struct mae_mport_desc *m; + int rc = -ENOENT; + + rhashtable_walk_enter(&mae->mports_ht, &walk); + rhashtable_walk_start(&walk); + while ((m = rhashtable_walk_next(&walk)) != NULL) { + if (m->mport_type == MAE_MPORT_DESC_MPORT_TYPE_VNIC && + m->interface_idx == nic_data->local_mae_intf && + m->pf_idx == 0 && + m->vf_idx == vf_idx) { + *id = m->mport_id; + rc = 0; + break; + } + } + rhashtable_walk_stop(&walk); + rhashtable_walk_exit(&walk); + return rc; +} + static bool efx_mae_asl_id(u32 id) { return !!(id & BIT(31)); diff --git a/drivers/net/ethernet/sfc/mae.h b/drivers/net/ethernet/sfc/mae.h index e1f057f01f08..d9adeafc0654 100644 --- a/drivers/net/ethernet/sfc/mae.h +++ b/drivers/net/ethernet/sfc/mae.h @@ -97,4 +97,6 @@ int efx_mae_delete_rule(struct efx_nic *efx, u32 id); int efx_init_mae(struct efx_nic *efx); void efx_fini_mae(struct efx_nic *efx); void efx_mae_remove_mport(void *desc, void *arg); +int efx_mae_fw_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id); +int efx_mae_lookup_mport(struct efx_nic *efx, u32 vf, u32 *id); #endif /* EF100_MAE_H */ From patchwork Tue Jan 31 14:58:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123075 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 71FAAC636CC for ; Tue, 31 Jan 2023 14:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbjAaO7N (ORCPT ); Tue, 31 Jan 2023 09:59:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbjAaO6v (ORCPT ); Tue, 31 Jan 2023 09:58:51 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2045.outbound.protection.outlook.com [40.107.243.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8690E83EB; Tue, 31 Jan 2023 06:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gjkVH+BwxzMznXbfAQDR/x0RwQ9PUZLXGyoQX0JpACka4DtF3UmweNY+IxbOsxKI0fBzHSIz1tN2iKdNJ2VzGpfh9/mC8Bue5KJFon7Jb7UCnNu6ZWEo3gIIZyymrZDVxsB9RlXFv4WX0XQ+inGM0e1EqdtsqNHK+ABGrv+tqxSTo7AujBWD2HBxEbgvV5u7oAQQOUTQVAgFKTfYWDfPc0214gWwP/dQmg8OjSBM2fP5Uh5HGlug4TIlbJZjj4OlIrAXvnxTrrQOJ3skRvRwsnYcBKJ+jhAOUw2/NCtMaImob0Srg78+GiRWbN67Iq0mtxZqaLL5bXp03DMfhs7X6Q== 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=RQHb5LLicsBbl5PFYXgEXpelQtGX/1q2ywua6uj8GfI=; b=nwHWNJjNUvc2pQKlSzCoU3ALXRE48nJwYEquVdDTmPmTrQEmH+9CKoyrrUrvD+9nOCQ0p6tFBz6s4KTIEiF2L8w8tmb8C9Qm/OJdBOR51FayE1HMnUxzf5E0WvGZYyN+kQ2I3IChcka9NGffTmdwvMy+cP5ECqHyvhmnMu51j+ZGK9yqiSF7Ey3NbqwdJZ8DEcXEWcvUwGqkc7zwSxI8YND43iUv9nxohY5+TDqVGsvJgrJNaHgHNdvrHmgif/RMla4tc92iblBM/1WZH2D+1eG3AR26pbVIAYuesTlfEAKVSVXWEw1unAHIRM0IoORJkoWdl4q1hQvWExIzNoVD5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RQHb5LLicsBbl5PFYXgEXpelQtGX/1q2ywua6uj8GfI=; b=f7Z2oiUfi7VWaEHKmOghyVHHtgmiYumt5haGvTsj0UnRa9DS0qcZDkgK+hdZa5yUmN7FmnZ36kd6FWndIZKAJFVCQX7d4jqT7YiLdN+X7kTZpTgsEg9JoZU5K4um+n0WV0YiABJXIFmrVTN0pdUvNjtU2uwYSfLrwfUNfdab7EY= Received: from DM6PR01CA0027.prod.exchangelabs.com (2603:10b6:5:296::32) by DM4PR12MB6495.namprd12.prod.outlook.com (2603:10b6:8:bc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.36; Tue, 31 Jan 2023 14:58:46 +0000 Received: from DM6NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::73) by DM6PR01CA0027.outlook.office365.com (2603:10b6:5:296::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT088.mail.protection.outlook.com (10.13.172.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.22 via Frontend Transport; Tue, 31 Jan 2023 14:58:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:45 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:43 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 5/8] sfc: add devlink port support for ef100 Date: Tue, 31 Jan 2023 14:58:19 +0000 Message-ID: <20230131145822.36208-6-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT088:EE_|DM4PR12MB6495:EE_ X-MS-Office365-Filtering-Correlation-Id: 8f45d4d6-0f82-4416-4492-08db039ba6fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wX4QpHkm1uAeUtPnaUyDNrPjvZ0sMrOmdCE1tA7vtCL+crfMAGIwU1hNYHX2XjZpa5gONPizVHNE4Y0Htd1ND56eyoJ2Q0RrxxJeD6Ir5FUohbAnUC2/nZMCjRD3lnCaJ5+J31uBg910XJnFGnFENxrRHWoBdrUEK4hdbKg2k7E288lOUURggWH+sfv0XLImODyndTonSk3lpHbNnOb2nV4dMkT+TugFVCMqeItvQNdVbvzrkgTMJcthqEsRfj4fv1biilnOdbClja8wG/T038SxwIKSAf1VUDhMfH5UcMLcPzpsIhr8WG2HRBJi++Xau9R0e+37a0fIUI0zC3SikYiW92jedQjIOL8/FqDoGXjzip/VstVKHd5uQHQ3etTVnuGAIhc5Hw7Fc/7mDIZENEhJJ5ZJk7xXRd18VVs/hJJEz43qr+sH9lp58QEmBrhK6JytOaW79tddOF1aLBu0ILAMAhJGev8BIpPdA45VotwfRyQNbu0LTWWpFMlgF8EDGJ/zEW6+9KPo2OVzuvuJ8WbiKZEoNIGPYfmwwqqZ5k4ygTa39vduElrXoKV6OkkKuZ5j20+B6yXA13IfeSjzTNvOZ13b0nWwAESwqOkSo179uTI7unDqKxri7IOs5epCXbClIunyEdvsOjieACRb/40Cmg9Nb2wNUoj042FDevJxSw75NUQQNucXOBAZyv6zwsrz0FkPlJBKYtXKrvD0h2PoyVsr1+rJJ6+Z1jZt/N4= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(376002)(396003)(39860400002)(136003)(346002)(451199018)(40470700004)(36840700001)(46966006)(8936002)(81166007)(40460700003)(356005)(41300700001)(86362001)(5660300002)(7416002)(83380400001)(426003)(47076005)(336012)(54906003)(110136005)(4326008)(2616005)(82740400003)(6636002)(8676002)(70586007)(70206006)(40480700001)(316002)(6666004)(186003)(1076003)(36756003)(26005)(36860700001)(478600001)(82310400005)(2876002)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:45.8575 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8f45d4d6-0f82-4416-4492-08db039ba6fb X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6495 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Using the data when enumerating mports, create devlink ports just before netdevs are registered and remove those devlink ports after netdev has been unregistered. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef100_netdev.c | 9 +++ drivers/net/ethernet/sfc/ef100_rep.c | 22 ++++++ drivers/net/ethernet/sfc/ef100_rep.h | 7 ++ drivers/net/ethernet/sfc/efx_devlink.c | 97 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_devlink.h | 6 ++ drivers/net/ethernet/sfc/mae.h | 2 + drivers/net/ethernet/sfc/net_driver.h | 2 + 7 files changed, 145 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c index b10a226f4a07..36774b55d413 100644 --- a/drivers/net/ethernet/sfc/ef100_netdev.c +++ b/drivers/net/ethernet/sfc/ef100_netdev.c @@ -335,7 +335,9 @@ void ef100_remove_netdev(struct efx_probe_data *probe_data) /* devlink lock */ efx_fini_devlink_start(efx); + ef100_unregister_netdev(efx); + ef100_pf_unset_devlink_port(efx); #ifdef CONFIG_SFC_SRIOV efx_fini_tc(efx); @@ -423,6 +425,8 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) rc = ef100_probe_netdev_pf(efx); if (rc) goto fail; + + ef100_pf_set_devlink_port(efx); } efx->netdev_notifier.notifier_call = ef100_netdev_event; @@ -433,7 +437,12 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) goto fail; } + /* devlink unlock */ + efx_probe_devlink_done(efx); + return rc; fail: + /* remove devlink port if does exist */ + ef100_pf_unset_devlink_port(efx); /* devlink unlock */ efx_probe_devlink_done(efx); return rc; diff --git a/drivers/net/ethernet/sfc/ef100_rep.c b/drivers/net/ethernet/sfc/ef100_rep.c index 9cd1a3ac67e0..6b5bc5d6955d 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.c +++ b/drivers/net/ethernet/sfc/ef100_rep.c @@ -16,6 +16,7 @@ #include "mae.h" #include "rx_common.h" #include "tc_bindings.h" +#include "efx_devlink.h" #define EFX_EF100_REP_DRIVER "efx_ef100_rep" @@ -297,6 +298,7 @@ int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i) i, rc); goto fail1; } + ef100_rep_set_devlink_port(efv); rc = register_netdev(efv->net_dev); if (rc) { pci_err(efx->pci_dev, @@ -308,6 +310,7 @@ int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i) efv->net_dev->name); return 0; fail2: + ef100_rep_unset_devlink_port(efv); efx_ef100_deconfigure_rep(efv); fail1: efx_ef100_rep_destroy_netdev(efv); @@ -323,6 +326,7 @@ void efx_ef100_vfrep_destroy(struct efx_nic *efx, struct efx_rep *efv) return; netif_dbg(efx, drv, rep_dev, "Removing VF representor\n"); unregister_netdev(rep_dev); + ef100_rep_unset_devlink_port(efv); efx_ef100_deconfigure_rep(efv); efx_ef100_rep_destroy_netdev(efv); } @@ -339,6 +343,24 @@ void efx_ef100_fini_vfreps(struct efx_nic *efx) efx_ef100_vfrep_destroy(efx, efv); } +static bool ef100_mport_is_pcie_vnic(struct mae_mport_desc *mport_desc) +{ + return mport_desc->mport_type == MAE_MPORT_DESC_MPORT_TYPE_VNIC && + mport_desc->vnic_client_type == MAE_MPORT_DESC_VNIC_CLIENT_TYPE_FUNCTION; +} + +bool ef100_mport_on_local_intf(struct efx_nic *efx, + struct mae_mport_desc *mport_desc) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + bool pcie_func; + + pcie_func = ef100_mport_is_pcie_vnic(mport_desc); + + return nic_data->have_local_intf && pcie_func && + mport_desc->interface_idx == nic_data->local_mae_intf; +} + void efx_ef100_init_reps(struct efx_nic *efx) { struct ef100_nic_data *nic_data = efx->nic_data; diff --git a/drivers/net/ethernet/sfc/ef100_rep.h b/drivers/net/ethernet/sfc/ef100_rep.h index 328ac0cbb532..ae6add4b0855 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.h +++ b/drivers/net/ethernet/sfc/ef100_rep.h @@ -22,6 +22,8 @@ struct efx_rep_sw_stats { atomic64_t rx_dropped, tx_errors; }; +struct devlink_port; + /** * struct efx_rep - Private data for an Efx representor * @@ -39,6 +41,7 @@ struct efx_rep_sw_stats { * @rx_lock: protects @rx_list * @napi: NAPI control structure * @stats: software traffic counters for netdev stats + * @dl_port: devlink port associated to this netdev representor */ struct efx_rep { struct efx_nic *parent; @@ -54,6 +57,7 @@ struct efx_rep { spinlock_t rx_lock; struct napi_struct napi; struct efx_rep_sw_stats stats; + struct devlink_port *dl_port; }; int efx_ef100_vfrep_create(struct efx_nic *efx, unsigned int i); @@ -69,4 +73,7 @@ struct efx_rep *efx_ef100_find_rep_by_mport(struct efx_nic *efx, u16 mport); extern const struct net_device_ops efx_ef100_rep_netdev_ops; void efx_ef100_init_reps(struct efx_nic *efx); void efx_ef100_fini_reps(struct efx_nic *efx); +struct mae_mport_desc; +bool ef100_mport_on_local_intf(struct efx_nic *efx, + struct mae_mport_desc *mport_desc); #endif /* EF100_REP_H */ diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c index ff5adfe3905e..b1637eb372ad 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.c +++ b/drivers/net/ethernet/sfc/efx_devlink.c @@ -16,11 +16,48 @@ #include "mcdi.h" #include "mcdi_functions.h" #include "mcdi_pcol.h" +#include "mae.h" +#include "ef100_rep.h" struct efx_devlink { struct efx_nic *efx; }; +static void efx_devlink_del_port(struct devlink_port *dl_port) +{ + if (!dl_port) + return; + devl_port_unregister(dl_port); +} + +static int efx_devlink_add_port(struct efx_nic *efx, + struct mae_mport_desc *mport) +{ + bool external = false; + + if (!ef100_mport_on_local_intf(efx, mport)) + external = true; + + switch (mport->mport_type) { + case MAE_MPORT_DESC_MPORT_TYPE_VNIC: + if (mport->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL) + devlink_port_attrs_pci_vf_set(&mport->dl_port, 0, mport->pf_idx, + mport->vf_idx, + external); + else + devlink_port_attrs_pci_pf_set(&mport->dl_port, 0, mport->pf_idx, + external); + break; + default: + /* MAE_MPORT_DESC_MPORT_ALIAS and UNDEFINED */ + return 0; + } + + mport->dl_port.index = mport->mport_id; + + return devl_port_register(efx->devlink, &mport->dl_port, mport->mport_id); +} + static int efx_devlink_info_nvram_partition(struct efx_nic *efx, struct devlink_info_req *req, unsigned int partition_type, @@ -428,6 +465,66 @@ static const struct devlink_ops sfc_devlink_ops = { .info_get = efx_devlink_info_get, }; +static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx) +{ + struct mae_mport_desc *mport; + u32 id; + + if (efx_mae_lookup_mport(efx, idx, &id)) { + /* This should not happen. */ + if (idx == MAE_MPORT_DESC_VF_IDX_NULL) + pci_warn(efx->pci_dev, "No mport ID found for PF.\n"); + else + pci_warn(efx->pci_dev, "No mport ID found for VF %u.\n", + idx); + return NULL; + } + + mport = efx_mae_get_mport(efx, id); + if (!mport) { + /* This should not happen. */ + if (idx == MAE_MPORT_DESC_VF_IDX_NULL) + pci_warn(efx->pci_dev, "No mport found for PF.\n"); + else + pci_warn(efx->pci_dev, "No mport found for VF %u.\n", + idx); + return NULL; + } + + if (efx_devlink_add_port(efx, mport)) { + if (idx == MAE_MPORT_DESC_VF_IDX_NULL) + pci_warn(efx->pci_dev, + "devlink port creation for PF failed.\n"); + else + pci_warn(efx->pci_dev, + "devlink_port creationg for VF %u failed.\n", + idx); + return NULL; + } + + return &mport->dl_port; +} + +void ef100_rep_set_devlink_port(struct efx_rep *efv) +{ + efv->dl_port = ef100_set_devlink_port(efv->parent, efv->idx); +} + +void ef100_pf_set_devlink_port(struct efx_nic *efx) +{ + efx->dl_port = ef100_set_devlink_port(efx, MAE_MPORT_DESC_VF_IDX_NULL); +} + +void ef100_rep_unset_devlink_port(struct efx_rep *efv) +{ + efx_devlink_del_port(efv->dl_port); +} + +void ef100_pf_unset_devlink_port(struct efx_nic *efx) +{ + efx_devlink_del_port(efx->dl_port); +} + void efx_fini_devlink_start(struct efx_nic *efx) { if (efx->devlink) diff --git a/drivers/net/ethernet/sfc/efx_devlink.h b/drivers/net/ethernet/sfc/efx_devlink.h index 8bcd077d8d8d..d453a180c44c 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.h +++ b/drivers/net/ethernet/sfc/efx_devlink.h @@ -36,4 +36,10 @@ void efx_probe_devlink_done(struct efx_nic *efx); void efx_fini_devlink_start(struct efx_nic *efx); void efx_fini_devlink(struct efx_nic *efx); +struct efx_rep; + +void ef100_pf_set_devlink_port(struct efx_nic *efx); +void ef100_rep_set_devlink_port(struct efx_rep *efv); +void ef100_pf_unset_devlink_port(struct efx_nic *efx); +void ef100_rep_unset_devlink_port(struct efx_rep *efv); #endif /* _EFX_DEVLINK_H */ diff --git a/drivers/net/ethernet/sfc/mae.h b/drivers/net/ethernet/sfc/mae.h index d9adeafc0654..e1b7967132ad 100644 --- a/drivers/net/ethernet/sfc/mae.h +++ b/drivers/net/ethernet/sfc/mae.h @@ -13,6 +13,7 @@ #define EF100_MAE_H /* MCDI interface for the ef100 Match-Action Engine */ +#include #include "net_driver.h" #include "tc.h" #include "mcdi_pcol.h" /* needed for various MC_CMD_MAE_*_NULL defines */ @@ -44,6 +45,7 @@ struct mae_mport_desc { }; struct rhash_head linkage; struct efx_rep *efv; + struct devlink_port dl_port; }; int efx_mae_enumerate_mports(struct efx_nic *efx); diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index bc9efbfb3d6b..fcd51d3992fa 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -998,6 +998,7 @@ struct efx_mae; * @netdev_notifier: Netdevice notifier. * @tc: state for TC offload (EF100). * @devlink: reference to devlink structure owned by this device + * @dl_port: devlink port associated with the PF * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. * @monitor_work: Hardware monitor workitem @@ -1185,6 +1186,7 @@ struct efx_nic { struct efx_tc_state *tc; struct devlink *devlink; + struct devlink_port *dl_port; unsigned int mem_bar; u32 reg_base; From patchwork Tue Jan 31 14:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123076 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 4A54AC38142 for ; Tue, 31 Jan 2023 14:59:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231673AbjAaO7Q (ORCPT ); Tue, 31 Jan 2023 09:59:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232064AbjAaO6w (ORCPT ); Tue, 31 Jan 2023 09:58:52 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2065.outbound.protection.outlook.com [40.107.220.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C285526BB; Tue, 31 Jan 2023 06:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VnmpWkv7y9sfVnH6LPSc6NZyCl51TYtXCcogFZfqoT8yV799FhQactUemTKeAcs6l1DndVQY1Mf9lulTbbsPs7c5qWioo46rW41rGRtOiItTNhFbbZpSNp7hJeJeD/k4oATES3g/57h/mNpA9zLqi9Za3OdGDCCSAG/JOXzt80h8M7epmyc8PFKSNDsYCIpB/HNYkwbGmPdJc1V0XNiOU7u3JgyUFdfEWgckmF4rdfgW5dquWw/OpEsdGwFILPfG9eyU1wL8IG3dYFCUZgluQav/xd+V6HZ6nZfWdzVYvcIdAY9rWmhRbM33dPSNoMkn3SFgcLeaDABSvxEW4z+zqw== 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=qDMhZFOyzmtTJTTvWlpKjfCTaQ3KE0ptNvOmsmEV0Hk=; b=VbIl8ekDus3G1qqjwltmL+2VHHcCuFXlL29Ahm8551MSHspvxW5kdE0PAOsQYaV6ruiKqzAzyhQ9WyM8RueI6g7GHBDRXTb6Q6FnPlNol0BAd4cMCZu1XblbaBcVAAm2Eneof6sXfjYfwLQmMj4VkDyyouEyg0fWmluO8LXG+nXdr0zeNQrGlBfkng9m2Rm97ViYQarA77X7jRL4gfYqLXLS/i9BNLTiCPxJJcfGnB+ZqQKXr2ao+zje5Br6Uthv6ikZIfzPaby0/ouv4absIGoWyNSMGk2UUgbBHSVYN9Ttk17Z8SlBU0gnLZpHAB/+xzkMoIy3FrZP3tKqruh4Lw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qDMhZFOyzmtTJTTvWlpKjfCTaQ3KE0ptNvOmsmEV0Hk=; b=MPpTkoGKPpJd3ALoPsx6Tcm+fmGqQAzgOkH2n7byD8ttdKFDZ9ZxjeoLDXEW2OFC0gDYMj0wvYCZytRyiZnRk95bh2zw+C8uQvjcQ2zEZ4vKLsXsdPDASE/sOM8kKJpU9mY4G5XzOuNdC2BuULe2BlxzCP7emMRNjSywU5ThW6E= Received: from BN8PR12CA0027.namprd12.prod.outlook.com (2603:10b6:408:60::40) by DM6PR12MB4187.namprd12.prod.outlook.com (2603:10b6:5:212::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Tue, 31 Jan 2023 14:58:49 +0000 Received: from BN8NAM11FT038.eop-nam11.prod.protection.outlook.com (2603:10b6:408:60:cafe::b2) by BN8PR12CA0027.outlook.office365.com (2603:10b6:408:60::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT038.mail.protection.outlook.com (10.13.176.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6043.21 via Frontend Transport; Tue, 31 Jan 2023 14:58:49 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:48 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 06:58:48 -0800 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:46 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 6/8] sfc: obtain device mac address based on firmware handle for ef100 Date: Tue, 31 Jan 2023 14:58:20 +0000 Message-ID: <20230131145822.36208-7-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT038:EE_|DM6PR12MB4187:EE_ X-MS-Office365-Filtering-Correlation-Id: e4e22431-3d8d-49c9-f572-08db039ba8db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: su2geluOPNPQgG09l//vaPffTavcuxTWhhv2hEFNgClC3D7lhMWMpwm44g8sdRUPpu0/g0kSld078uJjS+gVoek2X3F3YDls/7sB2HZvseEFwjlHA5u/nnPXlf+SkkNiZNICIyChrZLQtNs+Lxb72e1NEuUQHrGgJNcCjYmXb1O+GURu92+PXqUcvWGn3ikRobTDlImoEvbbJsgU3tddXFLF6Wl/Hdq1fTw6WFi3+CeiKGopjwn+yHELucIqwLaJaEcwhVkiBYw5U8/2ApEEQivgWZexpiR6dstIyovWwnt3VKAfjr4Q7bzgCwnYkJgIJ+jAD9FK8eMTB13CZ35znNhn/34unTDefh+/x7rpFHcBlVVY8YqiSrBvtjWdYoWQVEeBUijxS5EZdzp4nm38bN0lHGhFuQGt5xGl7XU0FZIale0iWdPFnvAGxaXAV74rEpgbMOTFS4IlfqQ/hpeorJ11DDXWq5Rs1Sbp9ka+dLjH1IwNBpCHDvRY0flmVVJgXo9iHzz8lIB/m4dSrUuG3YX/uZ03lZXL05xHgykl4iOuh2Ci4SIz+ZRic6vIWhQ19vv5sriTxmbStwde+NKKXOxWq7b5/0gJlwjSzeeU6qLsJyObBR8EJmfnfWmnPoToRiV6T2GgIi8TkplZRJFhLdsfHR4wuaITLFrCgyi4K2nHXU6i4DMH2Gz097LZQNvbH3RPI8pfuDWyKrjcNtL/0ZfMAZupSNmEnjwNSVv1gME= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(396003)(346002)(39860400002)(376002)(136003)(451199018)(36840700001)(46966006)(40470700004)(316002)(6636002)(54906003)(110136005)(426003)(36756003)(47076005)(36860700001)(82740400003)(5660300002)(2906002)(2876002)(8936002)(40480700001)(7416002)(356005)(81166007)(86362001)(82310400005)(8676002)(4326008)(70206006)(70586007)(83380400001)(41300700001)(40460700003)(2616005)(6666004)(186003)(26005)(478600001)(336012)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:49.0390 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e4e22431-3d8d-49c9-f572-08db039ba8db X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT038.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4187 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Getting device mac address is currently based on a specific MCDI command only available for the PF. This patch changes the MCDI command to a generic one for PFs and VFs based on a client handle. This allows both PFs and VFs to ask for their mac address during initialization using the CLIENT_HANDLE_SELF. Moreover, the patch allows other client handles which will be used by the PF to ask for mac addresses linked to VFs. This is necessary for suporting the port_function_hw_addr_get devlink function in further patches. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef100_netdev.c | 10 +++++++ drivers/net/ethernet/sfc/ef100_nic.c | 37 +++++++++++++------------ drivers/net/ethernet/sfc/ef100_nic.h | 2 ++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100_netdev.c b/drivers/net/ethernet/sfc/ef100_netdev.c index 36774b55d413..d591ad150972 100644 --- a/drivers/net/ethernet/sfc/ef100_netdev.c +++ b/drivers/net/ethernet/sfc/ef100_netdev.c @@ -362,6 +362,7 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) { struct efx_nic *efx = &probe_data->efx; struct efx_probe_data **probe_ptr; + struct ef100_nic_data *nic_data; struct net_device *net_dev; int rc; @@ -413,6 +414,15 @@ int ef100_probe_netdev(struct efx_probe_data *probe_data) /* Don't fail init if RSS setup doesn't work. */ efx_mcdi_push_default_indir_table(efx, efx->n_rx_channels); + nic_data = efx->nic_data; + rc = ef100_get_mac_address(efx, net_dev->perm_addr, CLIENT_HANDLE_SELF, + efx->type->is_vf); + if (rc) + return rc; + /* Assign MAC address */ + eth_hw_addr_set(net_dev, net_dev->perm_addr); + ether_addr_copy(nic_data->port_id, net_dev->perm_addr); + /* devlink creation, registration and lock */ if (efx_probe_devlink(efx)) pci_info(efx->pci_dev, "devlink registration failed"); diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index 04774f33b493..bcf937fb3d95 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -130,23 +130,34 @@ static void ef100_mcdi_reboot_detected(struct efx_nic *efx) /* MCDI calls */ -static int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address) +int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address, + int client_handle, bool empty_ok) { - MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); + MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_MAC_ADDRESSES_OUT_LEN(1)); + MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_MAC_ADDRESSES_IN_LEN); size_t outlen; int rc; BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); + MCDI_SET_DWORD(inbuf, GET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE, + client_handle); - rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, - outbuf, sizeof(outbuf), &outlen); + rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_MAC_ADDRESSES, inbuf, + sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; - if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) - return -EIO; - ether_addr_copy(mac_address, - MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); + if (outlen >= MC_CMD_GET_CLIENT_MAC_ADDRESSES_OUT_LEN(1)) { + ether_addr_copy(mac_address, + MCDI_PTR(outbuf, GET_CLIENT_MAC_ADDRESSES_OUT_MAC_ADDRS)); + } else if (empty_ok) { + pci_warn(efx->pci_dev, + "No MAC address provisioned for client ID %#x.\n", + client_handle); + eth_zero_addr(mac_address); + } else { + return -ENOENT; + } return 0; } @@ -1116,13 +1127,6 @@ int ef100_probe_netdev_pf(struct efx_nic *efx) struct net_device *net_dev = efx->net_dev; int rc; - rc = ef100_get_mac_address(efx, net_dev->perm_addr); - if (rc) - goto fail; - /* Assign MAC address */ - eth_hw_addr_set(net_dev, net_dev->perm_addr); - memcpy(nic_data->port_id, net_dev->perm_addr, ETH_ALEN); - if (!nic_data->grp_mae) return 0; @@ -1161,9 +1165,6 @@ int ef100_probe_netdev_pf(struct efx_nic *efx) efx->fixed_features |= NETIF_F_HW_TC; } #endif - return 0; - -fail: return rc; } diff --git a/drivers/net/ethernet/sfc/ef100_nic.h b/drivers/net/ethernet/sfc/ef100_nic.h index 496aea43c60f..e59044072333 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.h +++ b/drivers/net/ethernet/sfc/ef100_nic.h @@ -92,4 +92,6 @@ int efx_ef100_init_datapath_caps(struct efx_nic *efx); int ef100_phy_probe(struct efx_nic *efx); int ef100_filter_table_probe(struct efx_nic *efx); +int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address, + int client_handle, bool empty_ok); #endif /* EFX_EF100_NIC_H */ From patchwork Tue Jan 31 14:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123077 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 A5B04C636CC for ; Tue, 31 Jan 2023 14:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232252AbjAaO7i (ORCPT ); Tue, 31 Jan 2023 09:59:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbjAaO66 (ORCPT ); Tue, 31 Jan 2023 09:58:58 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2041.outbound.protection.outlook.com [40.107.100.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01850869A; Tue, 31 Jan 2023 06:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l0f7laxIdsFuHdMlHTfaMLXXoLKNUC/4rgi9PikS8ZNuQ7gMNsM0wfu8dw6vI6ueSfKtJ4YJFK9Zz/4TKPR8C5vvIuc5iwrba882VV1jSJPFCip3FPH+CAYMm6hZwtJlXBoBQE5VR1UmZm+m00gtl6WH/bLNn1eRHaDygxi9Xbn6Ucd3IJIInW7rK5L2TckQrB8AFH7dpgCvwnvCWfEVBUgmustfS8PuqRC5Wcq+rbqmRIRBI2WUUIeZJUcDPJHaaTMjI3R9JzyjPDOHN635NJgiY1oyyn1ufAZGGSbvdc4765WMtbVtZKFgAMFGXl/xCExAkep5A+D5FXq9bXvJ/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=yeZ3rucqmohHozuA48g1DL6kqbvCB6bNQ2pmcd80ry0=; b=RhEJVlmGi4eOcUXQZVPphFcr11m7poEo/5e0853SbN5QsBq96yJd8Jx3MymJTMskl6yvC6r3P4tuJzWu5rEUX8EUt1Z9L6cxeL2Z4LcBmw6D2rFArhh6JU8PN0kmgD4+31BWsXIPSRHzVliAR2IeMQlTm3o4X5sfWkbOM1fAZKelAvRgywlnJckXE3LsodpVMCYhSstDwLs/FTFVS6K4BUgPXRIhOlFG0phR0yPiJ3NxJfVRiwiVOHXrTHw16tyN+Vzqocm8mPE2HaaRNcVt6iV8alULr3682Y6qWn80EPiTsHzuLGLBA8u1XGIr1Bo+J4CAbR2yZiya09fizlUT2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yeZ3rucqmohHozuA48g1DL6kqbvCB6bNQ2pmcd80ry0=; b=PfAGKh9toZhLjQQcTknIOiIDL2evH9lJVj7RqZJHMUDqot8xbrjqxm59L4f6T8D71Y8YwtWDh46oFimTzxSnatzm8C6Vf72eQ+jiKy0YV6cV1K06hkOj1selX0XXnH9HzMi3x6DPRpkq2vNKD2jESZ69/RwKGbkuG2aVhjS1WUI= Received: from DM6PR02CA0037.namprd02.prod.outlook.com (2603:10b6:5:177::14) by DM4PR12MB5915.namprd12.prod.outlook.com (2603:10b6:8:68::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Tue, 31 Jan 2023 14:58:54 +0000 Received: from DM6NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:5:177:cafe::3b) by DM6PR02CA0037.outlook.office365.com (2603:10b6:5:177::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT108.mail.protection.outlook.com (10.13.172.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6064.22 via Frontend Transport; Tue, 31 Jan 2023 14:58:54 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:51 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:50 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:49 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 7/8] sfc: add support for devlink port_function_hw_addr_get in ef100 Date: Tue, 31 Jan 2023 14:58:21 +0000 Message-ID: <20230131145822.36208-8-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT108:EE_|DM4PR12MB5915:EE_ X-MS-Office365-Filtering-Correlation-Id: dd5b2318-5027-4410-516f-08db039babd8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xh2iQOCoq5JXid94HsFCQFLl0rQRZKZgp4/oOFcwwHUhZV/p/u0xm/XxDCYRiuY6DKpSmIHbJvJBCe6UHH2JQhL7kaKNq8/7oFxARmq7t/ZwEUooZIW7CbaDDXQf2tJo9q9nZmnyTnNMNbdwHyRBg0qaL9NN/GyDFiWKj1C74m6oFbyTDkvWqLnF0TgZSISqxHgxYsWE5XAmse6vrPoejzlM4G/hMiIAkxA34uEnaZNzJT3fF4VwyP8CovB/Y943IWVWCofUIIcLKXgNG7KRzuWYb6gU5A1PNbcQnt4pFFnSUzWTQ77RNOcrTjRhYiJpi6GEv1GiaJFj50fjAqicMtHyOudnLjodjhmbMqoP4Ok/cBf9lj3EUGGfKkvB37hyFScgSYhjpm9AS13zh9oAan/Tpsh3ys4b4kguDN+BIu8bliYeKPLWvmiWOJHHIfKOd8ce+9KO5yqR/yFlQcJe/6Xo68pTUbJOHx4luRVltthMSrXBbtneAOFC+ppJg0HYPb7BZC9eIIwbuGwcBzdVZD/41tJL1X4JDH87vhTz6VDbTHj31eOryl9nD9Q3xvtLqkUqIuF2vwfrjrC8Ba69fhJOk+0zujUR25wIl0Eq9+VL9dZNkdoiQXCw8b3aJ1d4Tzqk2i2ppnZJPU2iahFBpXJqUiWR42bQCfPMmJwUsJkaKTqDBAmHJbXYC5kusSa5WFoIytB+DS4wLjl7Xm/bo9Fsb+77oUXt0L/fXCe1vWg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(136003)(376002)(396003)(39860400002)(346002)(451199018)(46966006)(36840700001)(40470700004)(8676002)(70586007)(70206006)(336012)(2616005)(47076005)(316002)(426003)(6636002)(110136005)(40460700003)(478600001)(6666004)(54906003)(186003)(1076003)(26005)(36756003)(86362001)(7416002)(2876002)(81166007)(2906002)(356005)(4326008)(40480700001)(82310400005)(5660300002)(82740400003)(8936002)(41300700001)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:54.0014 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd5b2318-5027-4410-516f-08db039babd8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5915 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Using the builtin client handle id infrastructure, this patch adds support for obtaining the mac address linked to mports in ef100. This implies to execute an MCDI command for getting the data from the firmware for each devlink port. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef100_nic.c | 27 ++++++++++++++ drivers/net/ethernet/sfc/ef100_nic.h | 1 + drivers/net/ethernet/sfc/ef100_rep.c | 8 +++++ drivers/net/ethernet/sfc/ef100_rep.h | 1 + drivers/net/ethernet/sfc/efx_devlink.c | 50 ++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index bcf937fb3d95..e64a7fb5353b 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -1121,6 +1121,33 @@ static int ef100_probe_main(struct efx_nic *efx) return rc; } +/* MCDI commands are related to the same device issuing them. This function + * allows to do an MCDI command on behalf of another device, mainly PFs setting + * things for VFs. + */ +int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLIENT_HANDLE_OUT_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_CLIENT_HANDLE_IN_LEN); + u64 pciefn_flat = le64_to_cpu(pciefn.u64[0]); + size_t outlen; + int rc; + + MCDI_SET_DWORD(inbuf, GET_CLIENT_HANDLE_IN_TYPE, + MC_CMD_GET_CLIENT_HANDLE_IN_TYPE_FUNC); + MCDI_SET_QWORD(inbuf, GET_CLIENT_HANDLE_IN_FUNC, + pciefn_flat); + + rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLIENT_HANDLE, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + if (outlen < sizeof(outbuf)) + return -EIO; + *id = MCDI_DWORD(outbuf, GET_CLIENT_HANDLE_OUT_HANDLE); + return 0; +} + int ef100_probe_netdev_pf(struct efx_nic *efx) { struct ef100_nic_data *nic_data = efx->nic_data; diff --git a/drivers/net/ethernet/sfc/ef100_nic.h b/drivers/net/ethernet/sfc/ef100_nic.h index e59044072333..f1ed481c1260 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.h +++ b/drivers/net/ethernet/sfc/ef100_nic.h @@ -94,4 +94,5 @@ int ef100_filter_table_probe(struct efx_nic *efx); int ef100_get_mac_address(struct efx_nic *efx, u8 *mac_address, int client_handle, bool empty_ok); +int efx_ef100_lookup_client_id(struct efx_nic *efx, efx_qword_t pciefn, u32 *id); #endif /* EFX_EF100_NIC_H */ diff --git a/drivers/net/ethernet/sfc/ef100_rep.c b/drivers/net/ethernet/sfc/ef100_rep.c index 6b5bc5d6955d..0b3083ef0ead 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.c +++ b/drivers/net/ethernet/sfc/ef100_rep.c @@ -361,6 +361,14 @@ bool ef100_mport_on_local_intf(struct efx_nic *efx, mport_desc->interface_idx == nic_data->local_mae_intf; } +bool ef100_mport_is_vf(struct mae_mport_desc *mport_desc) +{ + bool pcie_func; + + pcie_func = ef100_mport_is_pcie_vnic(mport_desc); + return pcie_func && (mport_desc->vf_idx != MAE_MPORT_DESC_VF_IDX_NULL); +} + void efx_ef100_init_reps(struct efx_nic *efx) { struct ef100_nic_data *nic_data = efx->nic_data; diff --git a/drivers/net/ethernet/sfc/ef100_rep.h b/drivers/net/ethernet/sfc/ef100_rep.h index ae6add4b0855..a042525a2240 100644 --- a/drivers/net/ethernet/sfc/ef100_rep.h +++ b/drivers/net/ethernet/sfc/ef100_rep.h @@ -76,4 +76,5 @@ void efx_ef100_fini_reps(struct efx_nic *efx); struct mae_mport_desc; bool ef100_mport_on_local_intf(struct efx_nic *efx, struct mae_mport_desc *mport_desc); +bool ef100_mport_is_vf(struct mae_mport_desc *mport_desc); #endif /* EF100_REP_H */ diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c index b1637eb372ad..709418b1935a 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.c +++ b/drivers/net/ethernet/sfc/efx_devlink.c @@ -58,6 +58,55 @@ static int efx_devlink_add_port(struct efx_nic *efx, return devl_port_register(efx->devlink, &mport->dl_port, mport->mport_id); } +static int efx_devlink_port_addr_get(struct devlink_port *port, u8 *hw_addr, + int *hw_addr_len, + struct netlink_ext_ack *extack) +{ + struct efx_devlink *devlink = devlink_priv(port->devlink); + struct mae_mport_desc *mport_desc; + efx_qword_t pciefn; + u32 client_id; + int rc = 0; + + mport_desc = container_of(port, struct mae_mport_desc, dl_port); + + if (!ef100_mport_on_local_intf(devlink->efx, mport_desc)) { + rc = -EINVAL; + NL_SET_ERR_MSG_FMT(extack, + "Port not on local interface (mport: %u)", + mport_desc->mport_id); + goto out; + } + + if (ef100_mport_is_vf(mport_desc)) + EFX_POPULATE_QWORD_3(pciefn, + PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL, + PCIE_FUNCTION_VF, mport_desc->vf_idx, + PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER); + else + EFX_POPULATE_QWORD_3(pciefn, + PCIE_FUNCTION_PF, mport_desc->pf_idx, + PCIE_FUNCTION_VF, PCIE_FUNCTION_VF_NULL, + PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER); + + rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id); + if (rc) { + NL_SET_ERR_MSG_FMT(extack, + "No internal client_ID for port (mport: %u)", + mport_desc->mport_id); + goto out; + } + + rc = ef100_get_mac_address(devlink->efx, hw_addr, client_id, true); + if (rc != 0) + NL_SET_ERR_MSG_FMT(extack, + "No available MAC for port (mport: %u)", + mport_desc->mport_id); +out: + *hw_addr_len = ETH_ALEN; + return rc; +} + static int efx_devlink_info_nvram_partition(struct efx_nic *efx, struct devlink_info_req *req, unsigned int partition_type, @@ -463,6 +512,7 @@ static int efx_devlink_info_get(struct devlink *devlink, static const struct devlink_ops sfc_devlink_ops = { .info_get = efx_devlink_info_get, + .port_function_hw_addr_get = efx_devlink_port_addr_get, }; static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx) From patchwork Tue Jan 31 14:58:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13123078 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 16FC9C636D3 for ; Tue, 31 Jan 2023 14:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232298AbjAaO7l (ORCPT ); Tue, 31 Jan 2023 09:59:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232345AbjAaO7E (ORCPT ); Tue, 31 Jan 2023 09:59:04 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA60C526F; Tue, 31 Jan 2023 06:59:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=djdhv1tO/BX0AT/RSHu5wdZ/EtlrlNHpt++aFp8Tzhh4pW2ohA2wJCu2tbbPek/S8omprcm+Iu3UcSHA1ehG2vpPtEPj2PQ1dzTb7mtMeMcLyhDPzqbbIOPVQoZiLUCmTequsV3+VkjWSgbu/F71mz/XF+N8s2NMyUQnw6v1cL5MldV2AdQ5umYHW0n0IVOIM5SkFagPZ4ZUOclFURtwBmiECPeipz6YVFkCKeVWj0NORBuW560KphXsRiCHRqOZ2k3I5pcFnOHrXPfAEsMT5FPb1oMqM96ln41VHw2kFLII4/xPnEwYOn5AxBudB4wOKpo+Z3OLom1efvWIWSatWw== 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=EJZ9CdJPwpfEsAg4eN3qSEH+8FiBnklNOpbPHSapSbE=; b=gqq+dBfY5+wg8d96fH0cD1m3R/AXSdSOLaKM1h+/QWvaNJ6cgfL8+mWPGNO+Q+DggLA0DdYhdlu91UuSg6WhblPVPasbTP/3zm/1QaGDeu31fUL8fqqKiQgSX0pF7QDHY9SLXjEH5UDAb8hscDF6wFsCj4Qtui0g+vod2HzAFeJtx4B9SmxwWJLa0447qbOzPNv7Qqi0e//USrLy6VBEs9cLJuGKUPsH8Gv9gItdvtGuBT6leIdzJZOUJIk51F5rwDCHrvgEq3RJKRf5NOdYyT39RYedG2fQh6DO5RwiCMEleSBu6UsvVDl3idZMatjaeO+UsDGBsQ/9OmROfiib6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EJZ9CdJPwpfEsAg4eN3qSEH+8FiBnklNOpbPHSapSbE=; b=VchuWbse+IDpht4JALgv1LK8kNqbZORwqdAa2kx6hNLvGu7GLMtdqFdw5xaLoy6dw5roAODGLmRNk9+y4WS9Hkt3zkDZbpYpE8YPgOwwKCmmZSls8znSnwcw7ipXunbqGDcPpbXBZEpxLwqvcOptf1t0EoLCmize3ssgF70+3Ac= Received: from BN7PR06CA0057.namprd06.prod.outlook.com (2603:10b6:408:34::34) by CY5PR12MB6405.namprd12.prod.outlook.com (2603:10b6:930:3e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38; Tue, 31 Jan 2023 14:58:58 +0000 Received: from BN8NAM11FT081.eop-nam11.prod.protection.outlook.com (2603:10b6:408:34:cafe::3b) by BN7PR06CA0057.outlook.office365.com (2603:10b6:408:34::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.38 via Frontend Transport; Tue, 31 Jan 2023 14:58:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT081.mail.protection.outlook.com (10.13.177.233) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6064.22 via Frontend Transport; Tue, 31 Jan 2023 14:58:58 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 31 Jan 2023 08:58:53 -0600 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34 via Frontend Transport; Tue, 31 Jan 2023 08:58:52 -0600 From: To: , CC: , , , , , , , , , "Alejandro Lucero" Subject: [PATCH v4 net-next 8/8] sfc: add support for devlink port_function_hw_addr_set in ef100 Date: Tue, 31 Jan 2023 14:58:22 +0000 Message-ID: <20230131145822.36208-9-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> References: <20230131145822.36208-1-alejandro.lucero-palau@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT081:EE_|CY5PR12MB6405:EE_ X-MS-Office365-Filtering-Correlation-Id: ccf85879-d21a-4ddb-5583-08db039bae73 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hHDxfD6Da0vJo4p6OwhwUsby2DdhsS82F/Vi9O4fGIEkIKURJQKVsQHAT0nhibTFJ6fcn/MhTMH0QR9xwTu/aSuLnSTesVja7WTZvPkL9e6XPreW83BHY1QHVIbcG0AaamOIpOxjMq4YDEIjXhEE/JClgFgYiXTAzonJBu0U/evXt/KZLJxJPzgoBzwb9HqY3Hv11ckvQM9v+KH4bKj3fuesCg+60qcXSu32Q4u9MTbGgDBQQ/YVjWr7xfiIwQDdkvp5gxfg0dsmRbhy5G+K2qdQPqI19XrUAY7O77zYYPazpJ2ILkXYUtabxLwekRKQYDClDeVpYwsf/BP9V7I7bXT0JN1keTQerLnwvmJYYPL7dteirFS9BORoWzGaIWv+82a+NbGhKQm0PniN1PMcMUwwrVkIoc+vv+tG4+s3O+tLcNRSysltEk860dflWnz/6BHcKT0IdzrkCNO/VMUUoiTOzEqaSSOygQ3KjDwMdtX5epj4sQaLjs19S8dzd3dPs2nQ8pknyl3bcuzMPN2Wxrb6tFHZwp/h/YZ8DeSSfE6gVXF4mnRciiqY/ZbQpiRM3z3mrl1ycD3Oh8sBoJoGHyT8yxbc3m8vvH/wkEb7Q26bKFnmDw7s9eKQGDHv90Ad5tid6LereETADCQSNVZM2WoanKmMZhCxJuF4KkCz/7YBxErjxx40AeJXqpezqXoNetOpCQUQKs3zLmM5HiMuOJ49BxEjhRcBa/XuV/Qkv/8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199018)(36840700001)(46966006)(40470700004)(36756003)(41300700001)(70206006)(6636002)(316002)(110136005)(54906003)(82310400005)(8676002)(4326008)(5660300002)(7416002)(8936002)(70586007)(86362001)(81166007)(356005)(82740400003)(36860700001)(6666004)(186003)(26005)(1076003)(336012)(426003)(40480700001)(2906002)(2876002)(40460700003)(47076005)(478600001)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2023 14:58:58.4196 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ccf85879-d21a-4ddb-5583-08db039bae73 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT081.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6405 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Alejandro Lucero Using the builtin client handle id infrastructure, this patch adds support for setting the mac address linked to mports in ef100. This implies to execute an MCDI command for giving the address to the firmware for the specific devlink port. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/efx_devlink.c | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/net/ethernet/sfc/efx_devlink.c b/drivers/net/ethernet/sfc/efx_devlink.c index 709418b1935a..454187b7f98b 100644 --- a/drivers/net/ethernet/sfc/efx_devlink.c +++ b/drivers/net/ethernet/sfc/efx_devlink.c @@ -107,6 +107,55 @@ static int efx_devlink_port_addr_get(struct devlink_port *port, u8 *hw_addr, return rc; } +static int efx_devlink_port_addr_set(struct devlink_port *port, + const u8 *hw_addr, int hw_addr_len, + struct netlink_ext_ack *extack) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_CLIENT_MAC_ADDRESSES_IN_LEN(1)); + struct efx_devlink *devlink = devlink_priv(port->devlink); + struct mae_mport_desc *mport_desc; + efx_qword_t pciefn; + u32 client_id; + int rc; + + mport_desc = container_of(port, struct mae_mport_desc, dl_port); + + if (!ef100_mport_is_vf(mport_desc)) { + NL_SET_ERR_MSG_FMT(extack, + "port mac change not allowed (mport: %u)", + mport_desc->mport_id); + return -EPERM; + } + + EFX_POPULATE_QWORD_3(pciefn, + PCIE_FUNCTION_PF, PCIE_FUNCTION_PF_NULL, + PCIE_FUNCTION_VF, mport_desc->vf_idx, + PCIE_FUNCTION_INTF, PCIE_INTERFACE_CALLER); + + rc = efx_ef100_lookup_client_id(devlink->efx, pciefn, &client_id); + if (rc) { + NL_SET_ERR_MSG_FMT(extack, + "No internal client_ID for port (mport: %u)", + mport_desc->mport_id); + return rc; + } + + MCDI_SET_DWORD(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_CLIENT_HANDLE, + client_id); + + ether_addr_copy(MCDI_PTR(inbuf, SET_CLIENT_MAC_ADDRESSES_IN_MAC_ADDRS), + hw_addr); + + rc = efx_mcdi_rpc(devlink->efx, MC_CMD_SET_CLIENT_MAC_ADDRESSES, inbuf, + sizeof(inbuf), NULL, 0, NULL); + if (rc) + NL_SET_ERR_MSG_FMT(extack, + "sfc MC_CMD_SET_CLIENT_MAC_ADDRESSES mcdi error (mport: %u)", + mport_desc->mport_id); + + return rc; +} + static int efx_devlink_info_nvram_partition(struct efx_nic *efx, struct devlink_info_req *req, unsigned int partition_type, @@ -513,6 +562,7 @@ static int efx_devlink_info_get(struct devlink *devlink, static const struct devlink_ops sfc_devlink_ops = { .info_get = efx_devlink_info_get, .port_function_hw_addr_get = efx_devlink_port_addr_get, + .port_function_hw_addr_set = efx_devlink_port_addr_set, }; static struct devlink_port *ef100_set_devlink_port(struct efx_nic *efx, u32 idx)