From patchwork Wed Dec 7 14:54:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067254 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 DBCB6C4708E for ; Wed, 7 Dec 2022 14:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbiLGO4Z (ORCPT ); Wed, 7 Dec 2022 09:56:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbiLGO4Y (ORCPT ); Wed, 7 Dec 2022 09:56:24 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2086.outbound.protection.outlook.com [40.107.220.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FA294F1A5; Wed, 7 Dec 2022 06:56:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V8uEyz+uEPcLjv43iUGevFNBoDWhO5mISA3jjZlAAYm8ZCrvUJr0XZFtArwKahrSDpvhFSJlY30ORJOfXOp1fiiByz/DZqK5HlURqsDEzk3XyA1dRn4o7vet2ezeR6/A0DpYRvRYb3ZWBC6Iomvm+XSkBQabCX2T/s6qjUoY6bE1ys4Hut1MPKHpImyQ/0KQekTHxgkKa4B0feAFgSAZpa0Zvn4HBqNJgWlf6bnVONj1Uq74uZ2e1/T1cTIsOUgpJaq6rRQWRsgz+9F31QwB+3qG/54Jk68TpfZ1Y8eUefGY1bx2yoXuyOMlI4kaOZv+gx/xkwrdk15gIg+8o0CDbg== 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=Hip/ibXfIEvyJAj0mTWh/48v0JyNcGhhrokubS6rWDI=; b=FzVEWznR0E5L6roy6lsA5lkYdHRAMtgbAlPsPL1nXwhGU3pBZPJlE2Wg9oa5LVs5wOezV8pFMt5RWkpKpkvfxOIMDBxM8/kGfbkun/k+65XzXxREevGA1T3Pz/Lz3cwZkNmvkhvP9+YZcFxTJwLM92Y2PmB1s28I9mOHV9darGcODwXdACqUY7A6VpsMzE2At2gf00H6EkqhZXGW7ZGopUyZDPRSQrSx/6EZsTP33FiQTjTEU+78tvs3D6muNqTGTrPu4UoEUFpb9NUAbNA+v3Zebu8hHNfaop2qzh/GpQjPCMDxM3QGS/Pb6Du0WJuyZlFHb8DDZ1wJboncHObDnA== 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=Hip/ibXfIEvyJAj0mTWh/48v0JyNcGhhrokubS6rWDI=; b=MD9wHCyyRp5PszgsLg3rq2EDSss41TxsBaleSNKQ21eu6+lEVH6TxMryLRpra6JWELb7cTsW9pV/u40DcCEbLm4gar6TFKOhaW9ZWb67mINYvcCCFlqEsV6TN+qIMsvLgHxSX0WVbB4gLoKFsDk+0GtuZy8F4DeliyZZ34evgPw= Received: from DM6PR08CA0028.namprd08.prod.outlook.com (2603:10b6:5:80::41) by MN0PR12MB5715.namprd12.prod.outlook.com (2603:10b6:208:372::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:20 +0000 Received: from DS1PEPF0000E655.namprd02.prod.outlook.com (2603:10b6:5:80:cafe::2) by DM6PR08CA0028.outlook.office365.com (2603:10b6:5:80::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:19 +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 DS1PEPF0000E655.mail.protection.outlook.com (10.167.18.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:19 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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; Wed, 7 Dec 2022 08:56:15 -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; Wed, 7 Dec 2022 06:56:11 -0800 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:07 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Martin Habets , Edward Cree , "David S. Miller" , Eric Dumazet , "Jakub Kicinski" , Paolo Abeni , Subject: [PATCH net-next 01/11] sfc: add function personality support for EF100 devices Date: Wed, 7 Dec 2022 20:24:17 +0530 Message-ID: <20221207145428.31544-2-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E655:EE_|MN0PR12MB5715:EE_ X-MS-Office365-Filtering-Correlation-Id: bce1f5f4-88ab-4de6-64af-08dad8633303 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DhZcrYannvw0brYX3U4S6KSgIYewgUFLpqh/speCne4QeVI4KpUrv7l5ldfaIcNmpfKh2fEXsLNNk97bssoG/1C3xEB+rzfWJ/cDaTZvDEHJz1hv0d6PaNZMGUYpmTGL12G8r4SQQERvyy33JmjABAzTqFJY7KGXA/LMz4H1X/ikl7XgfPJVSvNIdDWwMUILQXYHBepZfOpnuya1PTiXAM+jvNrTI99FlpWI6xMpze2BGOyDIHIQwQ8Wa5JubLcSkX4ijl0oliGBoLL74f3OAWkHbq6n4q9LCU0iEF60NvwvRBPD8n8dR47n9dt0HNt+wK/3900045lQ9pX8MrtTEc3TF4T8nU20ADXTygtM1zyg+80Nzo9sdFhGmYU1Qab0no5BytqKCg/vd9UmF7zobiXOwy8HKZG2oYUOOTfxwpUa7heVmtTle0D4+gM6vCgiTvk9lvE6FZG6n13CdoaNt3+yHP7JKt9Gotj9GT2qxa8r0sWV/f3zdqwt6lzsJ2VtDvNLuz0eVHVQligZYloDM+FxgSZdm8kfuDhdThyJK93RrgEh2vl/XMxadJ9l0FLn78UPMNGgzwgBD/0w2qXqpPICX2DrsL8/8OxSHBJmI1FfSRYjzZQ3X1A/KYgdi5BruPb+cydFEEnPocBN9Mj5n8wyBR8TvN4zeWktKe0vhVMzqQ+JofleaGU3NsOyIOP8o5U6ogI2gsrQxx4zUzXW+AZLHv5dQyle/L8rtkhr8Mc= 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:(13230022)(4636009)(136003)(39860400002)(346002)(376002)(396003)(451199015)(46966006)(40470700004)(36840700001)(70206006)(70586007)(36860700001)(8676002)(356005)(478600001)(4326008)(40480700001)(6666004)(82740400003)(81166007)(1076003)(110136005)(54906003)(186003)(82310400005)(8936002)(86362001)(44832011)(336012)(40460700003)(41300700001)(83380400001)(2906002)(47076005)(7416002)(426003)(2616005)(5660300002)(26005)(316002)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:19.4787 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bce1f5f4-88ab-4de6-64af-08dad8633303 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: DS1PEPF0000E655.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5715 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org A function personality defines the location and semantics of registers in the BAR. EF100 NICs allow different personalities of a PCIe function and changing it at run-time. A total of three function personalities are defined as of now: EF100, vDPA and None with EF100 being the default. For now, vDPA net devices can be created on a EF100 virtual function and the VF personality will be changed to vDPA in the process. Co-developed-by: Martin Habets Signed-off-by: Martin Habets Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100.c | 6 +- drivers/net/ethernet/sfc/ef100_nic.c | 98 +++++++++++++++++++++++++++- drivers/net/ethernet/sfc/ef100_nic.h | 11 ++++ 3 files changed, 111 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100.c b/drivers/net/ethernet/sfc/ef100.c index 71aab3d0480f..c1c69783db7b 100644 --- a/drivers/net/ethernet/sfc/ef100.c +++ b/drivers/net/ethernet/sfc/ef100.c @@ -429,8 +429,7 @@ static void ef100_pci_remove(struct pci_dev *pci_dev) if (!efx) return; - probe_data = container_of(efx, struct efx_probe_data, efx); - ef100_remove_netdev(probe_data); + efx_ef100_set_bar_config(efx, EF100_BAR_CONFIG_NONE); #ifdef CONFIG_SFC_SRIOV efx_fini_struct_tc(efx); #endif @@ -443,6 +442,7 @@ static void ef100_pci_remove(struct pci_dev *pci_dev) pci_disable_pcie_error_reporting(pci_dev); pci_set_drvdata(pci_dev, NULL); + probe_data = container_of(efx, struct efx_probe_data, efx); efx_fini_struct(efx); kfree(probe_data); }; @@ -508,7 +508,7 @@ static int ef100_pci_probe(struct pci_dev *pci_dev, goto fail; efx->state = STATE_PROBED; - rc = ef100_probe_netdev(probe_data); + rc = efx_ef100_set_bar_config(efx, EF100_BAR_CONFIG_EF100); if (rc) goto fail; diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index ad686c671ab8..a57ec6d5b781 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -751,6 +751,99 @@ static int efx_ef100_get_base_mport(struct efx_nic *efx) } #endif +/* BAR configuration. + * To change BAR configuration, tear down the current configuration (which + * leaves the hardware in the PROBED state), and then initialise the new + * BAR state. + */ +struct ef100_bar_config_ops { + int (*init)(struct efx_probe_data *probe_data); + void (*fini)(struct efx_probe_data *probe_data); +}; + +static const struct ef100_bar_config_ops bar_config_ops[] = { + [EF100_BAR_CONFIG_EF100] = { + .init = ef100_probe_netdev, + .fini = ef100_remove_netdev + }, +#ifdef CONFIG_SFC_VDPA + [EF100_BAR_CONFIG_VDPA] = { + .init = NULL, + .fini = NULL + }, +#endif + [EF100_BAR_CONFIG_NONE] = { + .init = NULL, + .fini = NULL + }, +}; + +/* Keep this in sync with the definition of enum ef100_bar_config. */ +static char *bar_config_name[] = { + [EF100_BAR_CONFIG_NONE] = "None", + [EF100_BAR_CONFIG_EF100] = "EF100", + [EF100_BAR_CONFIG_VDPA] = "vDPA", +}; + +#ifdef CONFIG_SFC_VDPA +static bool efx_vdpa_supported(struct efx_nic *efx) +{ + return efx->type->is_vf; +} +#endif + +int efx_ef100_set_bar_config(struct efx_nic *efx, + enum ef100_bar_config new_config) +{ + const struct ef100_bar_config_ops *old_config_ops; + const struct ef100_bar_config_ops *new_config_ops; + struct ef100_nic_data *nic_data = efx->nic_data; + struct efx_probe_data *probe_data; + enum ef100_bar_config old_config; + int rc; + + if (WARN_ON_ONCE(nic_data->bar_config > EF100_BAR_CONFIG_VDPA)) + return -EINVAL; + +#ifdef CONFIG_SFC_VDPA + /* Current EF100 hardware supports vDPA on VFs only */ + if (new_config == EF100_BAR_CONFIG_VDPA && !efx_vdpa_supported(efx)) { + pci_err(efx->pci_dev, "vdpa over PF not supported : %s", + efx->name); + return -EOPNOTSUPP; + } +#endif + mutex_lock(&nic_data->bar_config_lock); + old_config = nic_data->bar_config; + if (new_config == old_config) { + mutex_unlock(&nic_data->bar_config_lock); + return 0; + } + + old_config_ops = &bar_config_ops[old_config]; + new_config_ops = &bar_config_ops[new_config]; + + probe_data = container_of(efx, struct efx_probe_data, efx); + if (old_config_ops->fini) + old_config_ops->fini(probe_data); + nic_data->bar_config = EF100_BAR_CONFIG_NONE; + + if (new_config_ops->init) { + rc = new_config_ops->init(probe_data); + if (rc) { + mutex_unlock(&nic_data->bar_config_lock); + return rc; + } + } + + nic_data->bar_config = new_config; + pci_dbg(efx->pci_dev, "BAR configuration changed to %s\n", + bar_config_name[new_config]); + mutex_unlock(&nic_data->bar_config_lock); + + return 0; +} + static int compare_versions(const char *a, const char *b) { int a_major, a_minor, a_point, a_patch; @@ -1004,6 +1097,7 @@ static int ef100_probe_main(struct efx_nic *efx) return -ENOMEM; efx->nic_data = nic_data; nic_data->efx = efx; + mutex_init(&nic_data->bar_config_lock); efx->max_vis = EF100_MAX_VIS; /* Populate design-parameter defaults */ @@ -1159,8 +1253,10 @@ void ef100_remove(struct efx_nic *efx) efx_mcdi_detach(efx); efx_mcdi_fini(efx); - if (nic_data) + if (nic_data) { efx_nic_free_buffer(efx, &nic_data->mcdi_buf); + mutex_destroy(&nic_data->bar_config_lock); + } kfree(nic_data); efx->nic_data = NULL; } diff --git a/drivers/net/ethernet/sfc/ef100_nic.h b/drivers/net/ethernet/sfc/ef100_nic.h index 0295933145fa..5ed693fbe79f 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.h +++ b/drivers/net/ethernet/sfc/ef100_nic.h @@ -61,6 +61,13 @@ enum { EF100_STAT_COUNT }; +/* Keep this in sync with the contents of bar_config_name. */ +enum ef100_bar_config { + EF100_BAR_CONFIG_NONE, + EF100_BAR_CONFIG_EF100, + EF100_BAR_CONFIG_VDPA, +}; + struct ef100_nic_data { struct efx_nic *efx; struct efx_buffer mcdi_buf; @@ -71,6 +78,8 @@ struct ef100_nic_data { u16 warm_boot_count; u8 port_id[ETH_ALEN]; DECLARE_BITMAP(evq_phases, EFX_MAX_CHANNELS); + enum ef100_bar_config bar_config; + struct mutex bar_config_lock; /* lock to control access to bar config */ u64 stats[EF100_STAT_COUNT]; u32 base_mport; bool have_mport; /* base_mport was populated successfully */ @@ -88,4 +97,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 efx_ef100_set_bar_config(struct efx_nic *efx, + enum ef100_bar_config new_config); #endif /* EFX_EF100_NIC_H */ From patchwork Wed Dec 7 14:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067255 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 F2478C4708E for ; Wed, 7 Dec 2022 14:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbiLGO4c (ORCPT ); Wed, 7 Dec 2022 09:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbiLGO41 (ORCPT ); Wed, 7 Dec 2022 09:56:27 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2072.outbound.protection.outlook.com [40.107.237.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F38604EC07; Wed, 7 Dec 2022 06:56:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OlidqjaSyxSF1typPv8jWBqwZ+Z3aB/zebQ3Ody3kN+Xh7HnUaJZVuRFc4dG7cOxYLM8J8udlrVEwZrG0U1lcZpPzvVSSIm/FCzdjSredSlubltRHJyrlwN6g0mTNalggwMkuMnqz56P8Hru7Ed2MWNgIEEMWOuhZ3vd8EUd3DUZxXCrz6cyxb72A1BKKVN1G08Y0SKrq8jUQEI/dx33PZfXMlloAfQHMCF80k6lpU15kptQyIJTKn84RcwXI9CwOYy5fPYCeo6ziRcnBpnlULwd/Nt4YsoPinZHmOMAHqrbhHMtLUVVIR2gXshlyJ9JpvUjPaHSi9Vc4PrFk2vwIA== 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=WOwLPd+tFDdjCuwgWdqCxhhxoquBZBiYqWk+L4xVZLk=; b=Z374D/wFivFjUPKaWOXkKFrF4KjXuuc/iEm+ohSmv9PJ3WE35Kx5b2Q1MnTy5FzxGss0JDxQ7AiE9mlswy8x7lYjoraGebHx2NqS8iHdEsXaeMaqXXGoWFwSq+WhkO8vOuaZ/ktLNqyZtwlHJxxgJv/zJpKEpcev/4oN/UO+4uAKrsiWuuqii8w25voBRkOjHPlY2ZVt2a09sQBqNtiOzWALDkh/8zaObHnGUSdZl9Imv6Hz3yOdlWhdmFHvPOcOfGkq4heGRl93hHhnE8p/O6AT/7fOWFtOKgDCS/aP1LF4NFUrYY0rBjle2LQzf+0kk7asN/3G3TUHZloDnd7aww== 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=WOwLPd+tFDdjCuwgWdqCxhhxoquBZBiYqWk+L4xVZLk=; b=yYHNs4pPvv/oNuM9eCPtIhMAh9hBwZBoy+ke5zW6xT1RGr1V8M+Y2Mea3gNI5bOsicbTmFxfO9sG2KrskFLB6XDJWWGjzp2tiB1JEQJuHHc/RYc6pOd+BlIg/+8FhVrI1W/qIYpI6GKQU8FnZyTsVwdOPY5WQR1iTOKRZdsZk+4= Received: from DM6PR08CA0011.namprd08.prod.outlook.com (2603:10b6:5:80::24) by IA1PR12MB6385.namprd12.prod.outlook.com (2603:10b6:208:38b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:23 +0000 Received: from DS1PEPF0000E655.namprd02.prod.outlook.com (2603:10b6:5:80:cafe::97) by DM6PR08CA0011.outlook.office365.com (2603:10b6:5:80::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:23 +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 DS1PEPF0000E655.mail.protection.outlook.com (10.167.18.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:22 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 7 Dec 2022 08:56:18 -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; Wed, 7 Dec 2022 08:56:17 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:14 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 02/11] sfc: implement MCDI interface for vDPA operations Date: Wed, 7 Dec 2022 20:24:18 +0530 Message-ID: <20221207145428.31544-3-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E655:EE_|IA1PR12MB6385:EE_ X-MS-Office365-Filtering-Correlation-Id: c98b2e81-f70d-4753-e8a4-08dad863350f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2nO23ARL8flD963piRJncYHbvTchYomWNDfeHXX9zYhXEWbiqBCLjbuyF2DRf23Uy6Pcc5uq0+o6AuK64wBUdOGl8ztY2n2VJAxSu7wrB0xKmK5ia7OFX70qwVLlP+DWtWWRccwOsUPGjIGz+lAzwGnBGfillbBfM0cKrq2G3Z+ZDUZ+3BDkAoq03HF3e4eNZMrB1fM4U0qoqkKZuE/RBswmQ3oTm1VNIvURemJSVKNcaBxqbal4pknykgkCv1SuzcSrVfF3TddeFtLhRrnXTQEoaHKpXsZ1a6xbfn11u6RU4mv9FzYzqKLUcX5d9vgK8knX9mVrTUv/ZnpHS9ykOUYozF9IiatGg8zH2jir4tGjdpSi6v12sKVG+QfgMMPpuLyY8NEBlH0C4PSIm8YeROuOIGtJqKbYf4ZcozmMCYbQegmjHULtZsQ+gBqWWOpr0VduCIkgYEXcsqa2xQv1AIdEYMR8cz93yvQeOAXdldsasjPnC6iaaO86vlwFG4ZPh+F519wgPAvGJOJMSYzZ71IJOU3MhRsD08NWrwARMLs+Lgt3yrc7mx/4HDFUhFlLrQht8xkckMpD1Z3ja/KGBQ+jjrpGjP9IVno6aRoANolVmqFXY3LQ853lB8GapHRZcwA5pF3ONwPP38Fc7ueAPPOCSV9UL5gwc5IL5oOo8n/qXP/2dS3m20w8vm6s8/5AwNT4l4Nmjeak3fgVRPnsGAAluf/Ai5Evhum0AEUeDCnrghkdmsSy4DdtwLfKjoNm 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:(13230022)(4636009)(136003)(376002)(396003)(346002)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(36756003)(7416002)(82740400003)(86362001)(81166007)(356005)(5660300002)(8936002)(8676002)(4326008)(2906002)(40460700003)(44832011)(83380400001)(36860700001)(30864003)(478600001)(70206006)(70586007)(316002)(2616005)(110136005)(54906003)(40480700001)(82310400005)(41300700001)(1076003)(336012)(47076005)(426003)(26005)(186003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:22.9162 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c98b2e81-f70d-4753-e8a4-08dad863350f 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: DS1PEPF0000E655.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6385 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Implement functions to perform vDPA operations like creating and removing virtqueues, getting doorbell register offset etc. using the MCDI interface with FW. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/Kconfig | 8 + drivers/net/ethernet/sfc/Makefile | 1 + drivers/net/ethernet/sfc/ef100_vdpa.h | 32 +++ drivers/net/ethernet/sfc/mcdi.h | 4 + drivers/net/ethernet/sfc/mcdi_vdpa.c | 268 ++++++++++++++++++++++++++ drivers/net/ethernet/sfc/mcdi_vdpa.h | 84 ++++++++ 6 files changed, 397 insertions(+) create mode 100644 drivers/net/ethernet/sfc/ef100_vdpa.h create mode 100644 drivers/net/ethernet/sfc/mcdi_vdpa.c create mode 100644 drivers/net/ethernet/sfc/mcdi_vdpa.h diff --git a/drivers/net/ethernet/sfc/Kconfig b/drivers/net/ethernet/sfc/Kconfig index 0950e6b0508f..1fa626c87d36 100644 --- a/drivers/net/ethernet/sfc/Kconfig +++ b/drivers/net/ethernet/sfc/Kconfig @@ -63,6 +63,14 @@ config SFC_MCDI_LOGGING Driver-Interface) commands and responses, allowing debugging of driver/firmware interaction. The tracing is actually enabled by a sysfs file 'mcdi_logging' under the PCI device. +config SFC_VDPA + bool "Solarflare EF100-family VDPA support" + depends on SFC && VDPA && SFC_SRIOV + default y + help + This enables support for the virtio data path acceleration (vDPA). + vDPA device's datapath complies with the virtio specification, + but control path is vendor specific. source "drivers/net/ethernet/sfc/falcon/Kconfig" source "drivers/net/ethernet/sfc/siena/Kconfig" diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index 712a48d00069..059a0944e89a 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -11,6 +11,7 @@ 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 +sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o obj-$(CONFIG_SFC) += sfc.o obj-$(CONFIG_SFC_FALCON) += falcon/ diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h new file mode 100644 index 000000000000..f6564448d0c7 --- /dev/null +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Driver for Xilinx network controllers and boards + * Copyright (C) 2020-2022, Xilinx, Inc. + * Copyright (C) 2022, 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 __EF100_VDPA_H__ +#define __EF100_VDPA_H__ + +#include +#include +#include "net_driver.h" +#include "ef100_nic.h" + +#if defined(CONFIG_SFC_VDPA) + +enum ef100_vdpa_device_type { + EF100_VDPA_DEVICE_TYPE_NET, +}; + +enum ef100_vdpa_vq_type { + EF100_VDPA_VQ_TYPE_NET_RXQ, + EF100_VDPA_VQ_TYPE_NET_TXQ, + EF100_VDPA_VQ_NTYPES +}; + +#endif /* CONFIG_SFC_VDPA */ +#endif /* __EF100_VDPA_H__ */ diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h index 7e35fec9da35..db4ca4975ada 100644 --- a/drivers/net/ethernet/sfc/mcdi.h +++ b/drivers/net/ethernet/sfc/mcdi.h @@ -214,6 +214,10 @@ void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); #define _MCDI_STRUCT_DWORD(_buf, _field) \ ((_buf) + (_MCDI_CHECK_ALIGN(_field ## _OFST, 4) >> 2)) +#define MCDI_SET_BYTE(_buf, _field, _value) do { \ + BUILD_BUG_ON(MC_CMD_ ## _field ## _LEN != 1); \ + *(u8 *)MCDI_PTR(_buf, _field) = _value; \ + } while (0) #define MCDI_STRUCT_SET_BYTE(_buf, _field, _value) do { \ BUILD_BUG_ON(_field ## _LEN != 1); \ *(u8 *)MCDI_STRUCT_PTR(_buf, _field) = _value; \ diff --git a/drivers/net/ethernet/sfc/mcdi_vdpa.c b/drivers/net/ethernet/sfc/mcdi_vdpa.c new file mode 100644 index 000000000000..35f822170049 --- /dev/null +++ b/drivers/net/ethernet/sfc/mcdi_vdpa.c @@ -0,0 +1,268 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Driver for Xilinx network controllers and boards + * Copyright (C) 2020-2022, Xilinx, Inc. + * Copyright (C) 2022, 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 "ef100_vdpa.h" +#include "efx.h" +#include "nic.h" +#include "mcdi_vdpa.h" +#include "mcdi_pcol.h" + +/* The value of target_vf in virtio MC commands like + * virtqueue create, delete and get doorbell offset should + * contain the VF index when the calling function is a PF + * and VF_NULL (0xFFFF) otherwise. As the vDPA driver invokes + * MC commands in context of the VF, it uses VF_NULL. + */ +#define MC_CMD_VIRTIO_TARGET_VF_NULL 0xFFFF + +struct efx_vring_ctx *efx_vdpa_vring_init(struct efx_nic *efx, u32 vi, + enum ef100_vdpa_vq_type vring_type) +{ + struct efx_vring_ctx *vring_ctx; + u32 queue_cmd; + + vring_ctx = kzalloc(sizeof(*vring_ctx), GFP_KERNEL); + if (!vring_ctx) + return ERR_PTR(-ENOMEM); + + switch (vring_type) { + case EF100_VDPA_VQ_TYPE_NET_RXQ: + queue_cmd = MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ; + break; + case EF100_VDPA_VQ_TYPE_NET_TXQ: + queue_cmd = MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ; + break; + default: + pci_err(efx->pci_dev, + "%s: Invalid Queue type %u\n", __func__, vring_type); + kfree(vring_ctx); + return ERR_PTR(-ENOMEM); + } + + vring_ctx->efx = efx; + vring_ctx->vf_index = MC_CMD_VIRTIO_TARGET_VF_NULL; + vring_ctx->vi_index = vi; + vring_ctx->mcdi_vring_type = queue_cmd; + return vring_ctx; +} + +void efx_vdpa_vring_fini(struct efx_vring_ctx *vring_ctx) +{ + kfree(vring_ctx); +} + +int efx_vdpa_get_features(struct efx_nic *efx, + enum ef100_vdpa_device_type type, + u64 *features) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_VIRTIO_GET_FEATURES_IN_LEN); + u32 high_val, low_val; + ssize_t outlen; + u32 dev_type; + int rc; + + if (!efx) { + pci_err(efx->pci_dev, "%s: Invalid NIC pointer\n", __func__); + return -EINVAL; + } + switch (type) { + case EF100_VDPA_DEVICE_TYPE_NET: + dev_type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET; + break; + default: + pci_err(efx->pci_dev, + "%s: Device type %d not supported\n", __func__, type); + return -EINVAL; + } + MCDI_SET_DWORD(inbuf, VIRTIO_GET_FEATURES_IN_DEVICE_ID, dev_type); + rc = efx_mcdi_rpc(efx, MC_CMD_VIRTIO_GET_FEATURES, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + if (outlen < MC_CMD_VIRTIO_GET_FEATURES_OUT_LEN) + return -EIO; + low_val = MCDI_DWORD(outbuf, VIRTIO_GET_FEATURES_OUT_FEATURES_LO); + high_val = MCDI_DWORD(outbuf, VIRTIO_GET_FEATURES_OUT_FEATURES_HI); + *features = ((u64)high_val << 32) | low_val; + return 0; +} + +int efx_vdpa_verify_features(struct efx_nic *efx, + enum ef100_vdpa_device_type type, u64 features) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_VIRTIO_TEST_FEATURES_IN_LEN); + u32 dev_type; + int rc; + + BUILD_BUG_ON(MC_CMD_VIRTIO_TEST_FEATURES_OUT_LEN != 0); + switch (type) { + case EF100_VDPA_DEVICE_TYPE_NET: + dev_type = MC_CMD_VIRTIO_GET_FEATURES_IN_NET; + break; + default: + pci_err(efx->pci_dev, + "%s: Device type %d not supported\n", __func__, type); + return -EINVAL; + } + MCDI_SET_DWORD(inbuf, VIRTIO_TEST_FEATURES_IN_DEVICE_ID, dev_type); + MCDI_SET_DWORD(inbuf, VIRTIO_TEST_FEATURES_IN_FEATURES_LO, features); + MCDI_SET_DWORD(inbuf, VIRTIO_TEST_FEATURES_IN_FEATURES_HI, + features >> 32); + rc = efx_mcdi_rpc(efx, MC_CMD_VIRTIO_TEST_FEATURES, inbuf, + sizeof(inbuf), NULL, 0, NULL); + return rc; +} + +int efx_vdpa_vring_create(struct efx_vring_ctx *vring_ctx, + struct efx_vring_cfg *vring_cfg, + struct efx_vring_dyn_cfg *vring_dyn_cfg) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_VIRTIO_INIT_QUEUE_REQ_LEN); + struct efx_nic *efx = vring_ctx->efx; + int rc; + + BUILD_BUG_ON(MC_CMD_VIRTIO_INIT_QUEUE_RESP_LEN != 0); + + MCDI_SET_BYTE(inbuf, VIRTIO_INIT_QUEUE_REQ_QUEUE_TYPE, + vring_ctx->mcdi_vring_type); + MCDI_SET_WORD(inbuf, VIRTIO_INIT_QUEUE_REQ_TARGET_VF, + vring_ctx->vf_index); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_INSTANCE, + vring_ctx->vi_index); + + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_SIZE, vring_cfg->size); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_LO, + vring_cfg->desc); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_DESC_TBL_ADDR_HI, + vring_cfg->desc >> 32); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_LO, + vring_cfg->avail); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_AVAIL_RING_ADDR_HI, + vring_cfg->avail >> 32); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_LO, + vring_cfg->used); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_USED_RING_ADDR_HI, + vring_cfg->used >> 32); + MCDI_SET_WORD(inbuf, VIRTIO_INIT_QUEUE_REQ_MSIX_VECTOR, + vring_cfg->msix_vector); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_FEATURES_LO, + vring_cfg->features); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_FEATURES_HI, + vring_cfg->features >> 32); + + if (vring_dyn_cfg) { + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_INITIAL_PIDX, + vring_dyn_cfg->avail_idx); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_INITIAL_CIDX, + vring_dyn_cfg->used_idx); + } + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_MPORT_SELECTOR, + MAE_MPORT_SELECTOR_ASSIGNED); + + rc = efx_mcdi_rpc(efx, MC_CMD_VIRTIO_INIT_QUEUE, inbuf, sizeof(inbuf), + NULL, 0, NULL); + return rc; +} + +int efx_vdpa_vring_destroy(struct efx_vring_ctx *vring_ctx, + struct efx_vring_dyn_cfg *vring_dyn_cfg) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_VIRTIO_FINI_QUEUE_REQ_LEN); + struct efx_nic *efx = vring_ctx->efx; + ssize_t outlen; + int rc; + + MCDI_SET_BYTE(inbuf, VIRTIO_FINI_QUEUE_REQ_QUEUE_TYPE, + vring_ctx->mcdi_vring_type); + MCDI_SET_WORD(inbuf, VIRTIO_INIT_QUEUE_REQ_TARGET_VF, + vring_ctx->vf_index); + MCDI_SET_DWORD(inbuf, VIRTIO_INIT_QUEUE_REQ_INSTANCE, + vring_ctx->vi_index); + rc = efx_mcdi_rpc(efx, MC_CMD_VIRTIO_FINI_QUEUE, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + + if (rc) + return rc; + + if (outlen < MC_CMD_VIRTIO_FINI_QUEUE_RESP_LEN) + return -EIO; + + if (vring_dyn_cfg) { + vring_dyn_cfg->avail_idx = MCDI_DWORD(outbuf, + VIRTIO_FINI_QUEUE_RESP_FINAL_PIDX); + vring_dyn_cfg->used_idx = MCDI_DWORD(outbuf, + VIRTIO_FINI_QUEUE_RESP_FINAL_CIDX); + } + + return 0; +} + +int efx_vdpa_get_doorbell_offset(struct efx_vring_ctx *vring_ctx, + u32 *offset) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET_REQ_LEN); + struct efx_nic *efx = vring_ctx->efx; + ssize_t outlen; + int rc; + + if (vring_ctx->mcdi_vring_type != MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ && + vring_ctx->mcdi_vring_type != MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_TXQ) { + pci_err(efx->pci_dev, + "%s: Invalid Queue type %u\n", + __func__, vring_ctx->mcdi_vring_type); + return -EINVAL; + } + + MCDI_SET_BYTE(inbuf, VIRTIO_GET_DOORBELL_OFFSET_REQ_DEVICE_ID, + MC_CMD_VIRTIO_GET_FEATURES_IN_NET); + MCDI_SET_WORD(inbuf, VIRTIO_GET_DOORBELL_OFFSET_REQ_TARGET_VF, + vring_ctx->vf_index); + MCDI_SET_DWORD(inbuf, VIRTIO_GET_DOORBELL_OFFSET_REQ_INSTANCE, + vring_ctx->vi_index); + + rc = efx_mcdi_rpc(efx, MC_CMD_VIRTIO_GET_DOORBELL_OFFSET, inbuf, + sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + + if (outlen < MC_CMD_VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_LEN) + return -EIO; + if (vring_ctx->mcdi_vring_type == MC_CMD_VIRTIO_INIT_QUEUE_REQ_NET_RXQ) + *offset = MCDI_DWORD(outbuf, + VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_RX_DBL_OFFSET); + else + *offset = MCDI_DWORD(outbuf, + VIRTIO_GET_NET_DOORBELL_OFFSET_RESP_TX_DBL_OFFSET); + + return 0; +} + +int efx_vdpa_get_mtu(struct efx_nic *efx, u16 *mtu) +{ + MCDI_DECLARE_BUF(outbuf, MC_CMD_SET_MAC_V2_OUT_LEN); + MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_MAC_EXT_IN_LEN); + ssize_t outlen; + int rc; + + MCDI_SET_DWORD(inbuf, SET_MAC_EXT_IN_CONTROL, 0); + rc = efx_mcdi_rpc(efx, MC_CMD_SET_MAC, inbuf, sizeof(inbuf), + outbuf, sizeof(outbuf), &outlen); + if (rc) + return rc; + if (outlen < MC_CMD_SET_MAC_V2_OUT_LEN) + return -EIO; + + *mtu = MCDI_DWORD(outbuf, SET_MAC_V2_OUT_MTU); + return 0; +} diff --git a/drivers/net/ethernet/sfc/mcdi_vdpa.h b/drivers/net/ethernet/sfc/mcdi_vdpa.h new file mode 100644 index 000000000000..2a0f7c647c44 --- /dev/null +++ b/drivers/net/ethernet/sfc/mcdi_vdpa.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Driver for Xilinx network controllers and boards + * Copyright (C) 2020-2022, Xilinx, Inc. + * Copyright (C) 2022, 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_MCDI_VDPA_H +#define EFX_MCDI_VDPA_H + +#if defined(CONFIG_SFC_VDPA) +#include "mcdi.h" + +/** + * struct efx_vring_ctx: The vring context + * + * @efx: pointer of the VF's efx_nic object + * @vf_index: VF index of the vDPA VF + * @vi_index: vi index to be used for queue creation + * @mcdi_vring_type: corresponding MCDI vring type + */ +struct efx_vring_ctx { + struct efx_nic *efx; + u32 vf_index; + u32 vi_index; + u32 mcdi_vring_type; +}; + +/** + * struct efx_vring_cfg: Configuration for vring creation + * + * @desc: Descriptor area address of the vring + * @avail: Available area address of the vring + * @used: Device area address of the vring + * @size: Queue size, in entries. Must be a power of two + * @msix_vector: msix vector address for the queue + * @features: negotiated feature bits + */ +struct efx_vring_cfg { + u64 desc; + u64 avail; + u64 used; + u32 size; + u16 msix_vector; + u64 features; +}; + +/** + * struct efx_vring_dyn_cfg - dynamic vring configuration + * + * @avail_idx: last available index of the vring + * @used_idx: last used index of the vring + */ +struct efx_vring_dyn_cfg { + u32 avail_idx; + u32 used_idx; +}; + +int efx_vdpa_get_features(struct efx_nic *efx, enum ef100_vdpa_device_type type, + u64 *featuresp); + +int efx_vdpa_verify_features(struct efx_nic *efx, + enum ef100_vdpa_device_type type, u64 features); + +struct efx_vring_ctx *efx_vdpa_vring_init(struct efx_nic *efx, u32 vi, + enum ef100_vdpa_vq_type vring_type); + +void efx_vdpa_vring_fini(struct efx_vring_ctx *vring_ctx); + +int efx_vdpa_vring_create(struct efx_vring_ctx *vring_ctx, + struct efx_vring_cfg *vring_cfg, + struct efx_vring_dyn_cfg *vring_dyn_cfg); + +int efx_vdpa_vring_destroy(struct efx_vring_ctx *vring_ctx, + struct efx_vring_dyn_cfg *vring_dyn_cfg); + +int efx_vdpa_get_doorbell_offset(struct efx_vring_ctx *vring_ctx, + u32 *offsetp); +int efx_vdpa_get_mtu(struct efx_nic *efx, u16 *mtu); +#endif +#endif From patchwork Wed Dec 7 14:54:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067256 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 BA943C63703 for ; Wed, 7 Dec 2022 14:56:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbiLGO4p (ORCPT ); Wed, 7 Dec 2022 09:56:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbiLGO4e (ORCPT ); Wed, 7 Dec 2022 09:56:34 -0500 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2046.outbound.protection.outlook.com [40.107.95.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D34D461502; Wed, 7 Dec 2022 06:56:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NY1qR8CiFTy/6knkBZrfMWzG2sO5+wrHwcBg544jiJlysurYE1a7cZA3PIyziOjalRxxUUAtpAvfmgQIQv2M0QsWEBV4XgPoYrKqZ+9XZE1aCjCUicpnvOOCWJ4OfRp/xvy89hPOBijNfTlDF8n3lnOaCByuBaQQcwcCep1ZJsy2NLxvlbNiUEppktfWruKFlcmZloIh/8U/HOWpiduovKGGBLuj9ePf/RbtkhbjMW9hov1C1cXFwUJgVYHwQBvSwgmX4/e56A6+xsCJzYjAv95vUWNKBXMnsspBadZAeSMP4bcg8j2/c/hHoNKFEMWO1RGJ+J9tB5z0WgLx70VNAg== 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=PANQeQJX8qMH7dnXLPQEwFAodYlsrRUf3qLVS/p6ZBA=; b=G7X2MXY3/au24B9pTfvIa1Ful0+t6L8p/sgpvGLTwmE3bqRXtWHyFTr6f/ggVdYMQfaSXF6L7ts/Ep9eNgdR8lIp0WsJvBeeJ0Efsgv67sz8QauV8UIqw44CoOFR1l5yohzlNhJKqW9bmKR7JuSfjHSIqckM4EZBmfCwXSPMmEyNWqBkpcr2tPCi/WGTmDN8w0k7swWPvu2rXA8NM4Vi05C2V1U2jGljVMwn2SGy891Ncy8oflYbgV0wxFLAzBTe9rv/4b3C9o6V/iEbqJv+t4ozDVgbPgEJWFfUBIHHEM2mCt1uGxX6TXl7n6nX1gQdLDlXIBe/Itrq8pXtPaQIYg== 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=PANQeQJX8qMH7dnXLPQEwFAodYlsrRUf3qLVS/p6ZBA=; b=yJw8CqROk8FavdUoVnhHs6mlBANBveLj8+EGB/wI8JGMpcVy1O41WLwYFhiyJ6mozj+TfKC//wB75nnXvCqOjNPwjSU8mDr+lJxCkzaxR3c9N6pbf4yg7artCsl/siT6Pqb2GxTFXCMXPF3AoXlItma8xoVYSTLxTdZ5fVvvdTE= Received: from DM6PR02CA0053.namprd02.prod.outlook.com (2603:10b6:5:177::30) by DS7PR12MB8289.namprd12.prod.outlook.com (2603:10b6:8:d8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:28 +0000 Received: from DS1PEPF0000E634.namprd02.prod.outlook.com (2603:10b6:5:177:cafe::ca) by DM6PR02CA0053.outlook.office365.com (2603:10b6:5:177::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:28 +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 DS1PEPF0000E634.mail.protection.outlook.com (10.167.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:28 +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; Wed, 7 Dec 2022 08:56:25 -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; Wed, 7 Dec 2022 08:56:24 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:20 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 03/11] sfc: implement init and fini functions for vDPA personality Date: Wed, 7 Dec 2022 20:24:19 +0530 Message-ID: <20221207145428.31544-4-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E634:EE_|DS7PR12MB8289:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a065168-b0be-4c8a-8e76-08dad8633894 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 38dxOVqMBayVZdLcmjfxvGZd6a4rFQtKcPkHZTuTvqL/o/1gD9CDYiRUIC9bgcUE0wx076pxiCq0CwYe5KXlnXqnuY2ThVhUyNKULLDoDNo5Pb7MlkI5O/CRu24jAjIBI8Cnsh0U71s8/Nr57ohjrDOvF76IYMGDKx71FzLF2DUzV7X1d3TY24b5W1YaUMOoL1aULqWVXLHM3QwNuT2eZt7pTVcKg45DeB6N3rPmbsSHazbtgSP4GqN8oJXQH3h++7RYZ7ADHJ3yYo+dms2h7Op78fKm04NmaLi8Ok3LJ5KhTBYqkvOllsv65Q1diIZWVOOLC0+3e8l9k8RXSy3pP4bpfsNKT4eaWWnKh0BLBIBDSQck2bOOxRGx6y0UfRt3QN/Jb7HY9IOOKu5ue7XhKIXxp6xbJ4ybXgi6cpkH1uzzIW/CXJfdUFj1FptGBCjYLHlIOmuu99L/uiDCRM7CJ8B88nzqeJ+pPbjVHespBWASevIgIel1APb6j+HXIBHRrBFvmUhYMF7bzwbvjH+P0y128HA4bxr2HeLGq95KK4yqBlCPYaoStrOD6Eg/8ZfXQrR9k2t/RiJnHxpYLEOpwuJ2eWpzQA3ezgN3Ds/RhSAXX9m30clBXwaM8r8Ks8DrfqnTQXIwIciqPvgBzaRDNFpOSTiIlkANlJlS9JYQecLc2pOgMlk6EKsSf8yVKMYZ+4KJ9tB22YpLlxR/47GXU0jqJvp3Y4fYscgeg/65NBIqdqATCAevT3hGCo0DQNaG 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:(13230022)(4636009)(136003)(376002)(346002)(39860400002)(396003)(451199015)(46966006)(40470700004)(36840700001)(426003)(356005)(86362001)(81166007)(26005)(478600001)(82310400005)(82740400003)(36860700001)(70206006)(36756003)(83380400001)(1076003)(41300700001)(54906003)(70586007)(4326008)(8676002)(2906002)(44832011)(40460700003)(40480700001)(7416002)(8936002)(47076005)(2616005)(5660300002)(110136005)(336012)(316002)(186003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:28.8187 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a065168-b0be-4c8a-8e76-08dad8633894 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: DS1PEPF0000E634.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8289 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When the bar_config for a PCIe function is changed from EF100 to vDPA or vice-versa, corresponding EF100/vDPA fini/init functions are invoked. Also, because of the fact that a vDPA device doesn't have an associated net device i.e. efx->net_dev is NULL, the code in efx_mcdi_filter_table_probe() has been re-structured to have the common code for both EF100 and vDPA personalities first and then return early for vDPA case (before efx->net_dev is accessed for EF100 personality). Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/ef100_nic.c | 7 ++- drivers/net/ethernet/sfc/ef100_vdpa.c | 58 +++++++++++++++++++++++++ drivers/net/ethernet/sfc/ef100_vdpa.h | 2 + drivers/net/ethernet/sfc/mcdi_filters.c | 51 ++++++++++++---------- drivers/net/ethernet/sfc/net_driver.h | 1 + 6 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 drivers/net/ethernet/sfc/ef100_vdpa.c diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index 059a0944e89a..84c9f0590368 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -11,7 +11,7 @@ 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 -sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o +sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o ef100_vdpa.o obj-$(CONFIG_SFC) += sfc.o obj-$(CONFIG_SFC_FALCON) += falcon/ diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index a57ec6d5b781..41175eb00326 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -27,6 +27,9 @@ #include "tc.h" #include "mae.h" #include "rx_common.h" +#ifdef CONFIG_SFC_VDPA +#include "ef100_vdpa.h" +#endif #define EF100_MAX_VIS 4096 #define EF100_NUM_MCDI_BUFFERS 1 @@ -768,8 +771,8 @@ static const struct ef100_bar_config_ops bar_config_ops[] = { }, #ifdef CONFIG_SFC_VDPA [EF100_BAR_CONFIG_VDPA] = { - .init = NULL, - .fini = NULL + .init = ef100_vdpa_init, + .fini = ef100_vdpa_fini }, #endif [EF100_BAR_CONFIG_NONE] = { diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c new file mode 100644 index 000000000000..5e215cee585a --- /dev/null +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Driver for Xilinx network controllers and boards + * Copyright(C) 2020-2022 Xilinx, Inc. + * Copyright(C) 2022 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 +#include +#include "ef100_vdpa.h" +#include "mcdi_vdpa.h" +#include "mcdi_filters.h" +#include "ef100_netdev.h" + +int ef100_vdpa_init(struct efx_probe_data *probe_data) +{ + struct efx_nic *efx = &probe_data->efx; + int rc; + + if (efx->state != STATE_PROBED) { + pci_err(efx->pci_dev, "Invalid efx state %u", efx->state); + return -EBUSY; + } + + efx->state = STATE_VDPA; + down_write(&efx->filter_sem); + rc = ef100_filter_table_probe(efx); + up_write(&efx->filter_sem); + if (rc) { + pci_err(efx->pci_dev, "filter probe failed, err: %d\n", rc); + goto fail; + } + + return 0; + +fail: + efx->state = STATE_PROBED; + return rc; +} + +void ef100_vdpa_fini(struct efx_probe_data *probe_data) +{ + struct efx_nic *efx = &probe_data->efx; + + if (efx->state != STATE_VDPA && efx->state != STATE_DISABLED) { + pci_err(efx->pci_dev, "Invalid efx state %u", efx->state); + return; + } + + efx->state = STATE_PROBED; + down_write(&efx->filter_sem); + efx_mcdi_filter_table_remove(efx); + up_write(&efx->filter_sem); +} diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index f6564448d0c7..6b51a05becd8 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -28,5 +28,7 @@ enum ef100_vdpa_vq_type { EF100_VDPA_VQ_NTYPES }; +int ef100_vdpa_init(struct efx_probe_data *probe_data); +void ef100_vdpa_fini(struct efx_probe_data *probe_data); #endif /* CONFIG_SFC_VDPA */ #endif /* __EF100_VDPA_H__ */ diff --git a/drivers/net/ethernet/sfc/mcdi_filters.c b/drivers/net/ethernet/sfc/mcdi_filters.c index 4ff6586116ee..fde2b5b50ade 100644 --- a/drivers/net/ethernet/sfc/mcdi_filters.c +++ b/drivers/net/ethernet/sfc/mcdi_filters.c @@ -1282,14 +1282,14 @@ efx_mcdi_filter_table_probe_matches(struct efx_nic *efx, pd_match_pri); rc = efx_mcdi_filter_match_flags_from_mcdi(encap, mcdi_flags); if (rc < 0) { - netif_dbg(efx, probe, efx->net_dev, - "%s: fw flags %#x pri %u not supported in driver\n", - __func__, mcdi_flags, pd_match_pri); + pci_dbg(efx->pci_dev, + "%s: fw flags %#x pri %u not supported in driver\n", + __func__, mcdi_flags, pd_match_pri); } else { - netif_dbg(efx, probe, efx->net_dev, - "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", - __func__, mcdi_flags, pd_match_pri, - rc, table->rx_match_count); + pci_dbg(efx->pci_dev, + "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", + __func__, mcdi_flags, pd_match_pri, + rc, table->rx_match_count); table->rx_match_mcdi_flags[table->rx_match_count] = mcdi_flags; table->rx_match_count++; } @@ -1318,11 +1318,26 @@ int efx_mcdi_filter_table_probe(struct efx_nic *efx, bool multicast_chaining) table->rx_match_count = 0; rc = efx_mcdi_filter_table_probe_matches(efx, table, false); if (rc) - goto fail; + goto fail1; + table->entry = vzalloc(array_size(EFX_MCDI_FILTER_TBL_ROWS, + sizeof(*table->entry))); + if (!table->entry) { + rc = -ENOMEM; + goto fail1; + } + + table->mc_promisc_last = false; + INIT_LIST_HEAD(&table->vlan_list); + init_rwsem(&table->lock); + + efx->filter_state = table; + if (efx->state == STATE_VDPA) + return 0; + if (efx_has_cap(efx, VXLAN_NVGRE)) rc = efx_mcdi_filter_table_probe_matches(efx, table, true); if (rc) - goto fail; + goto fail2; if ((efx_supported_features(efx) & NETIF_F_HW_VLAN_CTAG_FILTER) && !(efx_mcdi_filter_match_supported(table, false, (EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_LOC_MAC)) && @@ -1335,24 +1350,16 @@ int efx_mcdi_filter_table_probe(struct efx_nic *efx, bool multicast_chaining) net_dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; } - table->entry = vzalloc(array_size(EFX_MCDI_FILTER_TBL_ROWS, - sizeof(*table->entry))); - if (!table->entry) { - rc = -ENOMEM; - goto fail; - } - - table->mc_promisc_last = false; table->vlan_filter = !!(efx->net_dev->features & NETIF_F_HW_VLAN_CTAG_FILTER); - INIT_LIST_HEAD(&table->vlan_list); - init_rwsem(&table->lock); - - efx->filter_state = table; return 0; -fail: + +fail2: + vfree(table->entry); +fail1: kfree(table); + efx->filter_state = NULL; return rc; } diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 3b49e216768b..ffda80a95221 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -646,6 +646,7 @@ enum nic_state { STATE_NET_DOWN, /* netdev registered */ STATE_NET_UP, /* ready for traffic */ STATE_DISABLED, /* device disabled due to hardware errors */ + STATE_VDPA, /* device bar_config changed to vDPA */ STATE_RECOVERY = 0x100,/* recovering from PCI error */ STATE_FROZEN = 0x200, /* frozen by power management */ From patchwork Wed Dec 7 14:54:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067257 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 C8315C63703 for ; Wed, 7 Dec 2022 14:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbiLGO4s (ORCPT ); Wed, 7 Dec 2022 09:56:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbiLGO4m (ORCPT ); Wed, 7 Dec 2022 09:56:42 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73C484F1A5; Wed, 7 Dec 2022 06:56:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ai7d4qkbtQnbrxbvNvFf7nK4yq2H6kfRa0RvfTVZUb900V6+kyimBTB4mcHPMyxAyY6bdZT9ti4shzH5TrFaH+iK6J7DC/qJMkDsl2tbndpqXXCVjM3EB+mrGpRoKFY2lp/KZwj/odzp5TkD3eniUcavhdH0kZ5UlvPvtKYnmZrwwDfF9KZMS6Z5+pFeq5P5akLfgvDRldsCoqxaz/YjSYILjBXISrkvtlnqL/+ULAgCV3I5a9SRb9CNRTqEJsviHJAZkaVgs2oPiMKRkPc8Q77qMEo5fzXtQ12Q6HN/Ihm2ehr8DQqPuh0NjmMA99FCcdRfKx3X4l5u02cRlcvZTQ== 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=S1jVTA2cP2nV730jZbiPBofg3pDjjrz3eaasFFGmpLk=; b=N5UmqEcEl6LGVIs74PsEN/lSwyrcg0P1OOWmeje0aKPb2X304rTQ/illo1YvH35qhOh+5zOSUcvJVnMVCLTLeXaLOhCFFa90ey8PSqCxNwCtwDpFfks7bYnPoZ154LBRJrEOSia8e2LkiikrGBZHLQlOX4PKkAIiymJpv/6TCegQ1CXoDejrOBqVuboR6+BAkRWX6c5+zdfJP5PFOOnhzKNyPxvcdE7Md75exqDDJKfAr/rrxQSlZk12feXZyvZbd+n5BFLrSx2ooiP1YgaMt5E2JhIE0zQeA9ZIwh+5sFMNSCyDbSUXEX6eXxb5L3Zl158+7VC8dxWbGcp4F/9NzQ== 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=S1jVTA2cP2nV730jZbiPBofg3pDjjrz3eaasFFGmpLk=; b=kHR/eUTXE3vxk40ACCPjAddwdPH/4CCs0mMaMgxWJLAim6Cc4vkG0WSadsLXc48b8ddwGvU8jV+1umNyxhM9rN9Mw5ZBmfO3LvuH5csoYm6AhW3vz+/B40wO4jId9o5XbeRqcdWU2hcxF+0dlo5C91a9Iv6EEKhIA4MVy8NIDv0= Received: from DM6PR02CA0088.namprd02.prod.outlook.com (2603:10b6:5:1f4::29) by CH2PR12MB4087.namprd12.prod.outlook.com (2603:10b6:610:7f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:32 +0000 Received: from DS1PEPF0000E64F.namprd02.prod.outlook.com (2603:10b6:5:1f4:cafe::57) by DM6PR02CA0088.outlook.office365.com (2603:10b6:5:1f4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:31 +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 DS1PEPF0000E64F.mail.protection.outlook.com (10.167.18.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:31 +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; Wed, 7 Dec 2022 08:56:31 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:27 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 04/11] sfc: implement vDPA management device operations Date: Wed, 7 Dec 2022 20:24:20 +0530 Message-ID: <20221207145428.31544-5-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E64F:EE_|CH2PR12MB4087:EE_ X-MS-Office365-Filtering-Correlation-Id: 5afc5ff3-2e96-4ec8-b1f5-08dad8633a68 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LoPefXGhOKZaIcUQR5H3XhiDHlb6ZnzVJ5xal7eY/pWSD9IXWjmKOv73RlxkU1V/tOSNWzJTWbCXaM4hQgXMPdM2oD9qenGzchCGtSbGhZp5MepUume3ByAf4lVBiJxzHsCeNtTLE8S7xr83uaAM0JyKy7BpM3SxyIzkCCo8wY3mCU5bdKHuoZMZ4KGz318Vjjo+gpzwjD2Sg56MkA3j/UciZlCQcrXx7u0ZHOisxE3pXSRwNCeY0MtTWb83AVQMi7T7KEqVZEIqOZaJIfmgugeMgVjDgUN8edVImqNojsv3Jwu4dzgXmYkOvHDpR+RBI65hoYu+SgaHl/AmeuH8iICf1LAcPUmCnWkey8ICFjn8IT3Hlu1uBAukbDqkze35Roxguqq+Xpzs3vG2LDNqyQWveLq3RuIq3CPK8MFEvrfI0nSaWgt1xZihHtNwMmMSiPllomdpwmAMsKL5ZSNtAVWnzCjKZ0t9PQI0Gr9lltYhyuD7pRNgTKp4H3PEfVFxBrNygqyqTm8Ya4jK8LHTAEOLCuQBHvFOR7PWkZHCobY5p5yu8X+/RAxU7dcXryLcX1ksEsKxDnVFEUzy8Ul3RI0S+X8mByRgUUO6PLVxlBG0MeZrrRHGs64Lompul5etrazO4NxR6rhjz4ZGzkKC0KUvQ29N/LZC0SdHYA0y99Sa76/fnZbfFhJKyZ8Iv1+i3y+4xOtgd6h60E/xB+wg5f3pzIqNMEnzjdX0ao89HSViXagpjmTLtVWHbvz3dxXM 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:(13230022)(4636009)(396003)(39860400002)(136003)(346002)(376002)(451199015)(46966006)(40470700004)(36840700001)(40480700001)(4326008)(110136005)(54906003)(86362001)(316002)(8676002)(70206006)(26005)(70586007)(36860700001)(82740400003)(186003)(356005)(1076003)(81166007)(2906002)(41300700001)(336012)(2616005)(44832011)(47076005)(7416002)(8936002)(478600001)(426003)(6666004)(82310400005)(30864003)(5660300002)(83380400001)(36756003)(40460700003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:31.8867 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5afc5ff3-2e96-4ec8-b1f5-08dad8633a68 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: DS1PEPF0000E64F.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4087 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org To allow vDPA device creation and deletion, add a vDPA management device per function. Currently, the vDPA devices can be created only on a VF. Also, for now only network class of vDPA devices are supported. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/ef10.c | 2 +- drivers/net/ethernet/sfc/ef100_nic.c | 24 ++- drivers/net/ethernet/sfc/ef100_nic.h | 11 + drivers/net/ethernet/sfc/ef100_vdpa.c | 232 ++++++++++++++++++++++ drivers/net/ethernet/sfc/ef100_vdpa.h | 84 ++++++++ drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 28 +++ drivers/net/ethernet/sfc/mcdi_functions.c | 9 +- drivers/net/ethernet/sfc/mcdi_functions.h | 3 +- drivers/net/ethernet/sfc/net_driver.h | 6 + 10 files changed, 394 insertions(+), 7 deletions(-) create mode 100644 drivers/net/ethernet/sfc/ef100_vdpa_ops.c diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index 84c9f0590368..a10eac91ab23 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -11,7 +11,7 @@ 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 -sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o ef100_vdpa.o +sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o ef100_vdpa.o ef100_vdpa_ops.o obj-$(CONFIG_SFC) += sfc.o obj-$(CONFIG_SFC_FALCON) += falcon/ diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index 7022fb2005a2..366ecd3c80b1 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -589,7 +589,7 @@ static int efx_ef10_probe(struct efx_nic *efx) if (rc) goto fail4; - rc = efx_get_pf_index(efx, &nic_data->pf_index); + rc = efx_get_fn_info(efx, &nic_data->pf_index, NULL); if (rc) goto fail5; diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index 41175eb00326..41811c519275 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -1160,7 +1160,7 @@ static int ef100_probe_main(struct efx_nic *efx) if (rc) goto fail; - rc = efx_get_pf_index(efx, &nic_data->pf_index); + rc = efx_get_fn_info(efx, &nic_data->pf_index, &nic_data->vf_index); if (rc) goto fail; @@ -1247,13 +1247,33 @@ int ef100_probe_netdev_pf(struct efx_nic *efx) int ef100_probe_vf(struct efx_nic *efx) { - return ef100_probe_main(efx); +#if defined(CONFIG_SFC_VDPA) + int err; +#endif + int rc; + + rc = ef100_probe_main(efx); + if (rc) + return rc; + +#if defined(CONFIG_SFC_VDPA) + err = ef100_vdpa_register_mgmtdev(efx); + if (err) + pci_warn(efx->pci_dev, + "vdpa_register_mgmtdev failed, err: %d\n", err); +#endif + return 0; } void ef100_remove(struct efx_nic *efx) { struct ef100_nic_data *nic_data = efx->nic_data; +#if defined(CONFIG_SFC_VDPA) + if (efx_vdpa_supported(efx)) + ef100_vdpa_unregister_mgmtdev(efx); +#endif + 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 5ed693fbe79f..730c8bb932b0 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.h +++ b/drivers/net/ethernet/sfc/ef100_nic.h @@ -68,6 +68,13 @@ enum ef100_bar_config { EF100_BAR_CONFIG_VDPA, }; +#ifdef CONFIG_SFC_VDPA +enum ef100_vdpa_class { + EF100_VDPA_CLASS_NONE, + EF100_VDPA_CLASS_NET, +}; +#endif + struct ef100_nic_data { struct efx_nic *efx; struct efx_buffer mcdi_buf; @@ -75,7 +82,11 @@ struct ef100_nic_data { u32 datapath_caps2; u32 datapath_caps3; unsigned int pf_index; + unsigned int vf_index; u16 warm_boot_count; +#ifdef CONFIG_SFC_VDPA + enum ef100_vdpa_class vdpa_class; +#endif u8 port_id[ETH_ALEN]; DECLARE_BITMAP(evq_phases, EFX_MAX_CHANNELS); enum ef100_bar_config bar_config; diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index 5e215cee585a..ff4bb61e598e 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -11,11 +11,17 @@ #include #include #include +#include #include "ef100_vdpa.h" #include "mcdi_vdpa.h" #include "mcdi_filters.h" #include "ef100_netdev.h" +static struct virtio_device_id ef100_vdpa_id_table[] = { + { .device = VIRTIO_ID_NET, .vendor = PCI_VENDOR_ID_REDHAT_QUMRANET }, + { 0 }, +}; + int ef100_vdpa_init(struct efx_probe_data *probe_data) { struct efx_nic *efx = &probe_data->efx; @@ -42,17 +48,243 @@ int ef100_vdpa_init(struct efx_probe_data *probe_data) return rc; } +static void ef100_vdpa_delete(struct efx_nic *efx) +{ + if (efx->vdpa_nic) { + /* replace with _vdpa_unregister_device later */ + put_device(&efx->vdpa_nic->vdpa_dev.dev); + efx->vdpa_nic = NULL; + } +} + void ef100_vdpa_fini(struct efx_probe_data *probe_data) { struct efx_nic *efx = &probe_data->efx; + struct ef100_nic_data *nic_data; if (efx->state != STATE_VDPA && efx->state != STATE_DISABLED) { pci_err(efx->pci_dev, "Invalid efx state %u", efx->state); return; } + /* Handle vdpa device deletion, if not done explicitly */ + ef100_vdpa_delete(efx); + nic_data = efx->nic_data; + nic_data->vdpa_class = EF100_VDPA_CLASS_NONE; efx->state = STATE_PROBED; down_write(&efx->filter_sem); efx_mcdi_filter_table_remove(efx); up_write(&efx->filter_sem); } + +static int get_net_config(struct ef100_vdpa_nic *vdpa_nic) +{ + struct efx_nic *efx = vdpa_nic->efx; + u16 mtu; + int rc; + + vdpa_nic->net_config.max_virtqueue_pairs = + cpu_to_efx_vdpa16(vdpa_nic, vdpa_nic->max_queue_pairs); + + rc = efx_vdpa_get_mtu(efx, &mtu); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: Get MTU for vf:%u failed:%d\n", __func__, + vdpa_nic->vf_index, rc); + return rc; + } + vdpa_nic->net_config.mtu = cpu_to_efx_vdpa16(vdpa_nic, mtu); + vdpa_nic->net_config.status = cpu_to_efx_vdpa16(vdpa_nic, + VIRTIO_NET_S_LINK_UP); + return 0; +} + +static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, + const char *dev_name, + enum ef100_vdpa_class dev_type, + const u8 *mac) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct ef100_vdpa_nic *vdpa_nic; + struct device *dev; + int rc; + + nic_data->vdpa_class = dev_type; + vdpa_nic = vdpa_alloc_device(struct ef100_vdpa_nic, + vdpa_dev, &efx->pci_dev->dev, + &ef100_vdpa_config_ops, + 1, 1, + dev_name, false); + if (!vdpa_nic) { + pci_err(efx->pci_dev, + "vDPA device allocation failed for vf: %u\n", + nic_data->vf_index); + nic_data->vdpa_class = EF100_VDPA_CLASS_NONE; + return ERR_PTR(-ENOMEM); + } + + mutex_init(&vdpa_nic->lock); + dev = &vdpa_nic->vdpa_dev.dev; + efx->vdpa_nic = vdpa_nic; + vdpa_nic->vdpa_dev.dma_dev = &efx->pci_dev->dev; + vdpa_nic->vdpa_dev.mdev = efx->mgmt_dev; + vdpa_nic->efx = efx; + vdpa_nic->pf_index = nic_data->pf_index; + vdpa_nic->vf_index = nic_data->vf_index; + vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; + vdpa_nic->mac_address = (u8 *)&vdpa_nic->net_config.mac; + ether_addr_copy(vdpa_nic->mac_address, mac); + vdpa_nic->mac_configured = true; + + rc = get_net_config(vdpa_nic); + if (rc) + goto err_put_device; + + /* _vdpa_register_device when its ready */ + + return vdpa_nic; + +err_put_device: + /* put_device invokes ef100_vdpa_free */ + put_device(&vdpa_nic->vdpa_dev.dev); + return ERR_PTR(rc); +} + +static void ef100_vdpa_net_dev_del(struct vdpa_mgmt_dev *mgmt_dev, + struct vdpa_device *vdev) +{ + struct ef100_nic_data *nic_data; + struct efx_nic *efx; + int rc; + + efx = pci_get_drvdata(to_pci_dev(mgmt_dev->device)); + nic_data = efx->nic_data; + + rc = efx_ef100_set_bar_config(efx, EF100_BAR_CONFIG_EF100); + if (rc) + pci_err(efx->pci_dev, + "set_bar_config EF100 failed, err: %d\n", rc); + else + pci_dbg(efx->pci_dev, + "vdpa net device deleted, vf: %u\n", + nic_data->vf_index); +} + +static int ef100_vdpa_net_dev_add(struct vdpa_mgmt_dev *mgmt_dev, + const char *name, + const struct vdpa_dev_set_config *config) +{ + struct ef100_vdpa_nic *vdpa_nic; + struct ef100_nic_data *nic_data; + struct efx_nic *efx; + int rc, err; + + efx = pci_get_drvdata(to_pci_dev(mgmt_dev->device)); + if (efx->vdpa_nic) { + pci_warn(efx->pci_dev, + "vDPA device already exists on this VF\n"); + return -EEXIST; + } + + if (config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR)) { + if (!is_valid_ether_addr(config->net.mac)) { + pci_err(efx->pci_dev, "Invalid MAC address %pM\n", + config->net.mac); + return -EINVAL; + } + } else { + pci_err(efx->pci_dev, "MAC address parameter missing\n"); + return -EIO; + } + + nic_data = efx->nic_data; + + rc = efx_ef100_set_bar_config(efx, EF100_BAR_CONFIG_VDPA); + if (rc) { + pci_err(efx->pci_dev, + "set_bar_config vDPA failed, err: %d\n", rc); + goto err_set_bar_config; + } + + vdpa_nic = ef100_vdpa_create(efx, name, EF100_VDPA_CLASS_NET, + (const u8 *)config->net.mac); + if (IS_ERR(vdpa_nic)) { + pci_err(efx->pci_dev, + "vDPA device creation failed, vf: %u, err: %ld\n", + nic_data->vf_index, PTR_ERR(vdpa_nic)); + rc = PTR_ERR(vdpa_nic); + goto err_set_bar_config; + } else { + pci_dbg(efx->pci_dev, + "vdpa net device created, vf: %u\n", + nic_data->vf_index); + pci_warn(efx->pci_dev, + "Use QEMU versions 6.1.0 and later with vhost-vdpa\n"); + } + + return 0; + +err_set_bar_config: + err = efx_ef100_set_bar_config(efx, EF100_BAR_CONFIG_EF100); + if (err) + pci_err(efx->pci_dev, + "set_bar_config EF100 failed, err: %d\n", err); + + return rc; +} + +static const struct vdpa_mgmtdev_ops ef100_vdpa_net_mgmtdev_ops = { + .dev_add = ef100_vdpa_net_dev_add, + .dev_del = ef100_vdpa_net_dev_del +}; + +int ef100_vdpa_register_mgmtdev(struct efx_nic *efx) +{ + struct vdpa_mgmt_dev *mgmt_dev; + u64 features; + int rc; + + mgmt_dev = kzalloc(sizeof(*mgmt_dev), GFP_KERNEL); + if (!mgmt_dev) + return -ENOMEM; + + rc = efx_vdpa_get_features(efx, EF100_VDPA_DEVICE_TYPE_NET, &features); + if (rc) { + pci_err(efx->pci_dev, "%s: MCDI get features error:%d\n", + __func__, rc); + goto err_get_features; + } + + efx->mgmt_dev = mgmt_dev; + mgmt_dev->device = &efx->pci_dev->dev; + mgmt_dev->id_table = ef100_vdpa_id_table; + mgmt_dev->ops = &ef100_vdpa_net_mgmtdev_ops; + mgmt_dev->supported_features = features; + mgmt_dev->max_supported_vqs = EF100_VDPA_MAX_QUEUES_PAIRS * 2; + mgmt_dev->config_attr_mask = BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR); + + rc = vdpa_mgmtdev_register(mgmt_dev); + if (rc) { + pci_err(efx->pci_dev, + "vdpa_mgmtdev_register failed, err: %d\n", rc); + goto err_mgmtdev_register; + } + + return 0; + +err_mgmtdev_register: +err_get_features: + kfree(mgmt_dev); + efx->mgmt_dev = NULL; + + return rc; +} + +void ef100_vdpa_unregister_mgmtdev(struct efx_nic *efx) +{ + if (efx->mgmt_dev) { + vdpa_mgmtdev_unregister(efx->mgmt_dev); + kfree(efx->mgmt_dev); + efx->mgmt_dev = NULL; + } +} diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index 6b51a05becd8..83f6d819f6a5 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -18,6 +18,24 @@ #if defined(CONFIG_SFC_VDPA) +/* Max queue pairs currently supported */ +#define EF100_VDPA_MAX_QUEUES_PAIRS 1 + +/** + * enum ef100_vdpa_nic_state - possible states for a vDPA NIC + * + * @EF100_VDPA_STATE_INITIALIZED: State after vDPA NIC created + * @EF100_VDPA_STATE_NEGOTIATED: State after feature negotiation + * @EF100_VDPA_STATE_STARTED: State after driver ok + * @EF100_VDPA_STATE_NSTATES: Number of VDPA states + */ +enum ef100_vdpa_nic_state { + EF100_VDPA_STATE_INITIALIZED, + EF100_VDPA_STATE_NEGOTIATED, + EF100_VDPA_STATE_STARTED, + EF100_VDPA_STATE_NSTATES +}; + enum ef100_vdpa_device_type { EF100_VDPA_DEVICE_TYPE_NET, }; @@ -28,7 +46,73 @@ enum ef100_vdpa_vq_type { EF100_VDPA_VQ_NTYPES }; +/** + * struct ef100_vdpa_nic - vDPA NIC data structure + * + * @vdpa_dev: vdpa_device object which registers on the vDPA bus. + * @vdpa_state: NIC state machine governed by ef100_vdpa_nic_state + * @efx: pointer to the VF's efx_nic object + * @lock: Managing access to vdpa config operations + * @pf_index: PF index of the vDPA VF + * @vf_index: VF index of the vDPA VF + * @status: device status as per VIRTIO spec + * @features: negotiated feature bits + * @max_queue_pairs: maximum number of queue pairs supported + * @net_config: virtio_net_config data + * @mac_address: mac address of interface associated with this vdpa device + * @mac_configured: true after MAC address is configured + */ +struct ef100_vdpa_nic { + struct vdpa_device vdpa_dev; + enum ef100_vdpa_nic_state vdpa_state; + struct efx_nic *efx; + /* for synchronizing access to vdpa config operations */ + struct mutex lock; + u32 pf_index; + u32 vf_index; + u8 status; + u64 features; + u32 max_queue_pairs; + struct virtio_net_config net_config; + u8 *mac_address; + bool mac_configured; +}; + int ef100_vdpa_init(struct efx_probe_data *probe_data); void ef100_vdpa_fini(struct efx_probe_data *probe_data); +int ef100_vdpa_register_mgmtdev(struct efx_nic *efx); +void ef100_vdpa_unregister_mgmtdev(struct efx_nic *efx); + +static inline bool efx_vdpa_is_little_endian(struct ef100_vdpa_nic *vdpa_nic) +{ + return virtio_legacy_is_little_endian() || + (vdpa_nic->features & (1ULL << VIRTIO_F_VERSION_1)); +} + +static inline u16 efx_vdpa16_to_cpu(struct ef100_vdpa_nic *vdpa_nic, + __virtio16 val) +{ + return __virtio16_to_cpu(efx_vdpa_is_little_endian(vdpa_nic), val); +} + +static inline __virtio16 cpu_to_efx_vdpa16(struct ef100_vdpa_nic *vdpa_nic, + u16 val) +{ + return __cpu_to_virtio16(efx_vdpa_is_little_endian(vdpa_nic), val); +} + +static inline u32 efx_vdpa32_to_cpu(struct ef100_vdpa_nic *vdpa_nic, + __virtio32 val) +{ + return __virtio32_to_cpu(efx_vdpa_is_little_endian(vdpa_nic), val); +} + +static inline __virtio32 cpu_to_efx_vdpa32(struct ef100_vdpa_nic *vdpa_nic, + u32 val) +{ + return __cpu_to_virtio32(efx_vdpa_is_little_endian(vdpa_nic), val); +} + +extern const struct vdpa_config_ops ef100_vdpa_config_ops; #endif /* CONFIG_SFC_VDPA */ #endif /* __EF100_VDPA_H__ */ diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c new file mode 100644 index 000000000000..31952931c198 --- /dev/null +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Driver for Xilinx network controllers and boards + * Copyright(C) 2020-2022 Xilinx, Inc. + * Copyright(C) 2022 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 "ef100_vdpa.h" + +static struct ef100_vdpa_nic *get_vdpa_nic(struct vdpa_device *vdev) +{ + return container_of(vdev, struct ef100_vdpa_nic, vdpa_dev); +} + +static void ef100_vdpa_free(struct vdpa_device *vdev) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + mutex_destroy(&vdpa_nic->lock); +} + +const struct vdpa_config_ops ef100_vdpa_config_ops = { + .free = ef100_vdpa_free, +}; diff --git a/drivers/net/ethernet/sfc/mcdi_functions.c b/drivers/net/ethernet/sfc/mcdi_functions.c index d3e6d8239f5c..4415f19cf68f 100644 --- a/drivers/net/ethernet/sfc/mcdi_functions.c +++ b/drivers/net/ethernet/sfc/mcdi_functions.c @@ -413,7 +413,8 @@ int efx_mcdi_window_mode_to_stride(struct efx_nic *efx, u8 vi_window_mode) return 0; } -int efx_get_pf_index(struct efx_nic *efx, unsigned int *pf_index) +int efx_get_fn_info(struct efx_nic *efx, unsigned int *pf_index, + unsigned int *vf_index) { MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); size_t outlen; @@ -426,6 +427,10 @@ int efx_get_pf_index(struct efx_nic *efx, unsigned int *pf_index) if (outlen < sizeof(outbuf)) return -EIO; - *pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); + if (pf_index) + *pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); + + if (efx->type->is_vf && vf_index) + *vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF); return 0; } diff --git a/drivers/net/ethernet/sfc/mcdi_functions.h b/drivers/net/ethernet/sfc/mcdi_functions.h index b0e2f53a0d9b..76dc0a13463e 100644 --- a/drivers/net/ethernet/sfc/mcdi_functions.h +++ b/drivers/net/ethernet/sfc/mcdi_functions.h @@ -28,6 +28,7 @@ void efx_mcdi_rx_remove(struct efx_rx_queue *rx_queue); void efx_mcdi_rx_fini(struct efx_rx_queue *rx_queue); int efx_fini_dmaq(struct efx_nic *efx); int efx_mcdi_window_mode_to_stride(struct efx_nic *efx, u8 vi_window_mode); -int efx_get_pf_index(struct efx_nic *efx, unsigned int *pf_index); +int efx_get_fn_info(struct efx_nic *efx, unsigned int *pf_index, + unsigned int *vf_index); #endif diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index ffda80a95221..79356d614109 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -1182,6 +1182,12 @@ struct efx_nic { unsigned int mem_bar; u32 reg_base; +#ifdef CONFIG_SFC_VDPA + /** @mgmt_dev: vDPA Management device */ + struct vdpa_mgmt_dev *mgmt_dev; + /** @vdpa_nic: vDPA device structure (EF100) */ + struct ef100_vdpa_nic *vdpa_nic; +#endif /* The following fields may be written more often */ From patchwork Wed Dec 7 14:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067259 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 51E06C352A1 for ; Wed, 7 Dec 2022 14:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230298AbiLGO5e (ORCPT ); Wed, 7 Dec 2022 09:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbiLGO4t (ORCPT ); Wed, 7 Dec 2022 09:56:49 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2065.outbound.protection.outlook.com [40.107.92.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D2E060359; Wed, 7 Dec 2022 06:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pilh7EWcCoxzVkIn7/81qf2Ues75EArNLy0wXuedTdoNNDvnCOqnqFD9gLzm1pCOam/SAcwT+F8aLGRIwFjOxWJt+0Nmuj54FKss8dU4hcKEtete+aJCTB7YWszW9XAzGhdmQg6QInBX/gZKPrrIwEGUYXVbBsCtHyotnXfYdtUyjffjIZB34/yMAA6ZOKPkEvfQwgLMUIG1Dcn/AK+XMsZe7rWL3P4jo1DbwXVX5xFrn3i5jcmWiG28ds3yMIEzB8M2dLuCAsyG7Hcwmvu1VN36ATvaZ86mc63zG1I3qFuFefbbaQBAsklSOrS+hBK0bzyXfNkAvQ6hCIk9Y5Sw8Q== 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=ptQNG+kRb2mcK9TcZk4sB6PxbZ/cpAZHKDPZf7ZuDjA=; b=b+6m2rCXt1VauaVQmbQvnPhYvC+tHLcvh28tea1NU6m1Thp8iiuVo9l7S9XwgH0wRssH3vMub4QdXLoCuB0GQO1Nfnjl5wxH8BYQ6b1UV7U5vJE0pOeg49enbhi0BHLJjEnDEUlbviVfyJP12iiGyek+NKme6oHfqfPGVDD5C/SEGaoGPdBIQXAxBSJWdnAr/O05r1nAnb+3XC13vvAh5AgA8ohu0Tk3KsGhTCywVo8b1bIyKYcUfXGuGlpKflod/5MmZL6dZW3qjjL7442DKlGMsQMF5Lu3nlj5uDJ+RM93kb9hC9IATM7p5ZM7DoGezs3Qsm68nQ3cmJoaVMW8FA== 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=ptQNG+kRb2mcK9TcZk4sB6PxbZ/cpAZHKDPZf7ZuDjA=; b=kGUc84/YLGji5UvX38PFROhALOXXsYxCfTtLxxmY3kZciHNgE4ji3wWU5L9B9LSoyDp5SKcfroj5nZ1FaByMfgKCqT5jy/6+oHPO2q4F0YlCf4xmM3ODMpbNYhSp2R5Vd7kZ/ojIQlxBrhDIBuiN0Mci5C5XFZfzgz3AWs8SgxA= Received: from DM6PR01CA0018.prod.exchangelabs.com (2603:10b6:5:296::23) by SJ1PR12MB6314.namprd12.prod.outlook.com (2603:10b6:a03:457::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:37 +0000 Received: from DS1PEPF0000E64E.namprd02.prod.outlook.com (2603:10b6:5:296:cafe::ad) by DM6PR01CA0018.outlook.office365.com (2603:10b6:5:296::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10 via Frontend Transport; Wed, 7 Dec 2022 14:56:37 +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 DS1PEPF0000E64E.mail.protection.outlook.com (10.167.18.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:36 +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; Wed, 7 Dec 2022 08:56:36 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:32 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 05/11] sfc: implement vdpa device config operations Date: Wed, 7 Dec 2022 20:24:21 +0530 Message-ID: <20221207145428.31544-6-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E64E:EE_|SJ1PR12MB6314:EE_ X-MS-Office365-Filtering-Correlation-Id: 15fbb702-9e90-4b80-1a4f-08dad8633d70 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FxOWiJjoG73UDnJr4+ipYjmRQz4+PcLBNKxjte0tTqTiUXkV5N/mx0MacqQgxZarS7cAdLxMWsxJiDY2qr47o+CB3LPhjrvTyHQmYih5wtk5yMwi7HDO5wVoSjEDd5taqnMqyz4/euqTTUI/kMdFBYCP8W8/uZmkZj8tnRjwoEMd0N885CxcK8fbyPFi+38eLRdpw2s4XYIOgxnpkDbPr/SS5hPD6OCtLyDpBw50X0wW2oN6gra67xIJKZ5b/4izzfmuJheuFEm+fE86sVaXGFucZMCYwjxrPNXArNFZu+9tattjfxbJIfIxMNz82EIx03J5YmDAl7zzQv4qNzuBt2Y+nYgMzkloPvLQa+6u9jIzKukLi0JyXFX6/F3fXRlcQFtAC4NwaYrCoxR37h415UzHUKYUyXeYOVJY5OEb7uiR0nv4ULczJN28dZsFg1jyGZ9pQZlELBIGAoaYMHupU5eNk9Syr2c3deh7Y5SIqAdN9d7m18ygBPvsexRDIoixGH9e5fLXM+JxqOtHvjCsPFe4IBzheiTIJjoteVnohAytibh22pCnpEBuGBYnp62pvSBT1XvahBZ7OVX3SMeN8qHH4EQsQavibJpO58LWUSCvxR2crL7ruvkHrZzH5ZIENBiKqjNBvnq5BVBjXY1N5CeLz/YDUf/zc0lGz9pgoliPE8fRv/X2oe0MdDrea1fE+iw1jTWF09wvuGfgHNg9ytQO1Xl8pL4Rsfc0/OrsNO/Cf/+CVf1EGFdBQIpBgmiu5FB9ypzZhcUmdI4BBEgKZQ== 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:(13230022)(4636009)(396003)(376002)(346002)(136003)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(40480700001)(110136005)(316002)(54906003)(26005)(186003)(40460700003)(36756003)(44832011)(81166007)(356005)(83380400001)(82740400003)(7416002)(36860700001)(2906002)(5660300002)(8676002)(4326008)(86362001)(70206006)(70586007)(82310400005)(336012)(47076005)(8936002)(426003)(2616005)(41300700001)(1076003)(478600001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:36.9527 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15fbb702-9e90-4b80-1a4f-08dad8633d70 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: DS1PEPF0000E64E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6314 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org vDPA config operations can be broadly categorized in to either virtqueue operations, device operations or DMA operations. This patch implements most of the device level config operations. SN1022 supports VIRTIO_F_IN_ORDER which is supported by the DPDK virtio driver but not the kernel virtio driver. Due to a bug in QEMU (https://gitlab.com/qemu-project/qemu/-/issues/331#), with vhost-vdpa, this feature bit is returned with guest kernel virtio driver in set_features config operation. The fix for this bug (qemu_commit c33f23a419f95da16ab4faaf08be635c89b96ff0) is available in QEMU versions 6.1.0 and later. Hence, that's the oldest QEMU version required for testing with the vhost-vdpa driver. With older QEMU releases, VIRTIO_F_IN_ORDER is negotiated but not honored causing Firmware exception. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.h | 14 ++ drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 148 ++++++++++++++++++++++ 2 files changed, 162 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index 83f6d819f6a5..be7650c3166a 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -21,6 +21,18 @@ /* Max queue pairs currently supported */ #define EF100_VDPA_MAX_QUEUES_PAIRS 1 +/* Device ID of a virtio net device */ +#define EF100_VDPA_VIRTIO_NET_DEVICE_ID VIRTIO_ID_NET + +/* Vendor ID of Xilinx vDPA NIC */ +#define EF100_VDPA_VENDOR_ID PCI_VENDOR_ID_XILINX + +/* Max number of Buffers supported in the virtqueue */ +#define EF100_VDPA_VQ_NUM_MAX_SIZE 512 + +/* Alignment requirement of the Virtqueue */ +#define EF100_VDPA_VQ_ALIGN 4096 + /** * enum ef100_vdpa_nic_state - possible states for a vDPA NIC * @@ -61,6 +73,7 @@ enum ef100_vdpa_vq_type { * @net_config: virtio_net_config data * @mac_address: mac address of interface associated with this vdpa device * @mac_configured: true after MAC address is configured + * @cfg_cb: callback for config change */ struct ef100_vdpa_nic { struct vdpa_device vdpa_dev; @@ -76,6 +89,7 @@ struct ef100_vdpa_nic { struct virtio_net_config net_config; u8 *mac_address; bool mac_configured; + struct vdpa_callback cfg_cb; }; int ef100_vdpa_init(struct efx_probe_data *probe_data); diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index 31952931c198..87899baa1c52 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -10,12 +10,148 @@ #include #include "ef100_vdpa.h" +#include "mcdi_vdpa.h" static struct ef100_vdpa_nic *get_vdpa_nic(struct vdpa_device *vdev) { return container_of(vdev, struct ef100_vdpa_nic, vdpa_dev); } +static u32 ef100_vdpa_get_vq_align(struct vdpa_device *vdev) +{ + return EF100_VDPA_VQ_ALIGN; +} + +static u64 ef100_vdpa_get_device_features(struct vdpa_device *vdev) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u64 features; + int rc; + + rc = efx_vdpa_get_features(vdpa_nic->efx, + EF100_VDPA_DEVICE_TYPE_NET, &features); + if (rc) { + dev_err(&vdev->dev, "%s: MCDI get features error:%d\n", + __func__, rc); + /* Returning 0 as value of features will lead to failure + * of feature negotiation. + */ + return 0; + } + + /* SN1022 supports VIRTIO_F_IN_ORDER which is supported by the DPDK + * virtio driver but not the kernel virtio driver. Due to a bug in + * QEMU (https://gitlab.com/qemu-project/qemu/-/issues/331#), with + * vhost-vdpa, this feature bit is returned with guest kernel virtio + * driver in set_features config operation. The fix for this bug + * (commit c33f23a419f95da16ab4faaf08be635c89b96ff0) is available + * in QEMU versions 6.1.0 and later. Hence, that's the oldest QEMU + * version required for testing with the vhost-vdpa driver. + */ + features |= BIT_ULL(VIRTIO_NET_F_MAC); + + return features; +} + +static int ef100_vdpa_set_driver_features(struct vdpa_device *vdev, + u64 features) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u64 verify_features; + int rc; + + mutex_lock(&vdpa_nic->lock); + if (vdpa_nic->vdpa_state != EF100_VDPA_STATE_INITIALIZED) { + dev_err(&vdev->dev, "%s: Invalid state %u\n", + __func__, vdpa_nic->vdpa_state); + rc = -EINVAL; + goto err; + } + verify_features = features & ~BIT_ULL(VIRTIO_NET_F_MAC); + rc = efx_vdpa_verify_features(vdpa_nic->efx, + EF100_VDPA_DEVICE_TYPE_NET, + verify_features); + + if (rc) { + dev_err(&vdev->dev, "%s: MCDI verify features error:%d\n", + __func__, rc); + goto err; + } + + vdpa_nic->features = features; +err: + mutex_unlock(&vdpa_nic->lock); + return rc; +} + +static u64 ef100_vdpa_get_driver_features(struct vdpa_device *vdev) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + return vdpa_nic->features; +} + +static void ef100_vdpa_set_config_cb(struct vdpa_device *vdev, + struct vdpa_callback *cb) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (cb) + vdpa_nic->cfg_cb = *cb; +} + +static u16 ef100_vdpa_get_vq_num_max(struct vdpa_device *vdev) +{ + return EF100_VDPA_VQ_NUM_MAX_SIZE; +} + +static u32 ef100_vdpa_get_device_id(struct vdpa_device *vdev) +{ + return EF100_VDPA_VIRTIO_NET_DEVICE_ID; +} + +static u32 ef100_vdpa_get_vendor_id(struct vdpa_device *vdev) +{ + return EF100_VDPA_VENDOR_ID; +} + +static size_t ef100_vdpa_get_config_size(struct vdpa_device *vdev) +{ + return sizeof(struct virtio_net_config); +} + +static void ef100_vdpa_get_config(struct vdpa_device *vdev, + unsigned int offset, + void *buf, unsigned int len) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + /* Avoid the possibility of wrap-up after the sum exceeds U32_MAX */ + if (WARN_ON(((u64)offset + len) > sizeof(struct virtio_net_config))) { + dev_err(&vdev->dev, + "%s: Offset + len exceeds config size\n", __func__); + return; + } + memcpy(buf, (u8 *)&vdpa_nic->net_config + offset, len); +} + +static void ef100_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, + const void *buf, unsigned int len) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + /* Avoid the possibility of wrap-up after the sum exceeds U32_MAX */ + if (WARN_ON(((u64)offset + len) > sizeof(vdpa_nic->net_config))) { + dev_err(&vdev->dev, + "%s: Offset + len exceeds config size\n", __func__); + return; + } + + memcpy((u8 *)&vdpa_nic->net_config + offset, buf, len); + if (is_valid_ether_addr(vdpa_nic->mac_address)) + vdpa_nic->mac_configured = true; +} + static void ef100_vdpa_free(struct vdpa_device *vdev) { struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); @@ -24,5 +160,17 @@ static void ef100_vdpa_free(struct vdpa_device *vdev) } const struct vdpa_config_ops ef100_vdpa_config_ops = { + .get_vq_align = ef100_vdpa_get_vq_align, + .get_device_features = ef100_vdpa_get_device_features, + .set_driver_features = ef100_vdpa_set_driver_features, + .get_driver_features = ef100_vdpa_get_driver_features, + .set_config_cb = ef100_vdpa_set_config_cb, + .get_vq_num_max = ef100_vdpa_get_vq_num_max, + .get_device_id = ef100_vdpa_get_device_id, + .get_vendor_id = ef100_vdpa_get_vendor_id, + .get_config_size = ef100_vdpa_get_config_size, + .get_config = ef100_vdpa_get_config, + .set_config = ef100_vdpa_set_config, + .get_generation = NULL, .free = ef100_vdpa_free, }; From patchwork Wed Dec 7 14:54:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067260 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 C97AAC4708E for ; Wed, 7 Dec 2022 14:57:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbiLGO5h (ORCPT ); Wed, 7 Dec 2022 09:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbiLGO45 (ORCPT ); Wed, 7 Dec 2022 09:56:57 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2081.outbound.protection.outlook.com [40.107.101.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35FF46150D; Wed, 7 Dec 2022 06:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dpR4T495MIYMzyPqkaC4EChCD5yMEzFhvbLjC9XwmR2FJW0nHKgYJmJ5lLtzkivIOXWsIofy0Y8T5L4p/K3L1g2JP92FLrv78pU2Q3wYERT9R0cUa533jm9f/iyu0/PtTdD0gf3coFKbrWUWWffv23jcW19rjBpntUZvonnLeyOwM9XLetgPx2s7ACzRbnsgFf3d07YgYPZSuOb6tdOlr6rHh2OMzmbG4rg/0y1MhJoT75BLBl7IWzSODo/6Lvw+LEcMx85VAGN+JSxUWWgHvPg5gt0tPQOQXkzRiDaIONT/Yogmb83t75LF6mLXNzSxeYjXTNdetOdxZagMG50v2g== 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=HSXOwyGhioi9rIw6XzCWswo7Bg6HUujNaj3TOcrr9vk=; b=nqT71QdpjJd2xNbnUu3iGlxD0Yn07ujzYx86v8XmRzwnsz1+qx9fwVX7EBGP16ajDelpJwT54cbORs3OJ3D7LXC3kwwpsAsu1DleZllrj7koMWOBapl1P8rBIfERJiHVq82L+icXapV/2+x9aPKWePZwmsO4gcTypblvuMUjRgF7dhievT232cuT09wBOUuIavg2f5DDhOGK6USTYL6OyE2Q3uMjaYLyJanyQ6R/omCVozj06S+PIBfBWU9k3P1veYYq/roWkGfhfQmZ/CBHK/SmaMmsVRz35R3Vk6OnuKb2kIOdcFEYqq6v5js3YpD7V5TTr1yMAehYEQLumXHSug== 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=HSXOwyGhioi9rIw6XzCWswo7Bg6HUujNaj3TOcrr9vk=; b=o26fnRIFP/CQM5gsNSoux7KH3Ix5xTY62kjt5tcxdHIOMmZcsF+aNgOeAHOyqE02P4qNrSH/sKgYdiEqVQtREoPKAsEUPTvs3ahydRVQapPy/FuidIbK5ptyu6MZz1pULJNdfqIEI36GlZy3PHhDAp+xv6DefAvaMkaPImgI/wg= Received: from DM5PR08CA0032.namprd08.prod.outlook.com (2603:10b6:4:60::21) by SJ2PR12MB7865.namprd12.prod.outlook.com (2603:10b6:a03:4cc::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:44 +0000 Received: from DS1PEPF0000E650.namprd02.prod.outlook.com (2603:10b6:4:60:cafe::6d) by DM5PR08CA0032.outlook.office365.com (2603:10b6:4:60::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:44 +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 DS1PEPF0000E650.mail.protection.outlook.com (10.167.18.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:44 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 7 Dec 2022 08:56:42 -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; Wed, 7 Dec 2022 08:56:42 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:38 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 06/11] sfc: implement vdpa vring config operations Date: Wed, 7 Dec 2022 20:24:22 +0530 Message-ID: <20221207145428.31544-7-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E650:EE_|SJ2PR12MB7865:EE_ X-MS-Office365-Filtering-Correlation-Id: d05ff206-6b06-459c-4b3c-08dad86341b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c1ThylNiC2zSf/JHfO9xytRlvTKGeSzwoGw1ahCE85hq8dj3AaCGSDAmhOAvazA+p8IA3ahMPJy9EDiwUuFYMSTb7XCdu+zVOM5sW8z1/yalPsO7LgRjtfHO4eUPmIggvzPB+e0wFUhCyqD73ffId5L5T07pg69zQMjsDWMX7ERh0LP+OIja6VPCM1ZPKAx6YNrMoOveNuQWL1e4PKha3GTJoCTVmc3ilPp6Scb5QJT5q0O82qNRCiA6+zqwbMPuNyA48edbkw2rXIsL47e2B+dH7/Ycku3pWJ0/moowLsJumYT/7L+ihru1fUlG6kVim/s2fBRAdjJD8HMQLcEdJSA9M57cXhQ/KpGI4xNwvN5NVpfMofzTNRxKcOOcxx8V/tc0skIV3/BGU6mvlGQtsxM2VcdgHfkTW+UxFSfKgJRweU9dXrlJw5hqZnu7eAg7Zk+LQJCXnHiveQm4wyRclzyHUMTzIQ3acRWkI4T/Pvk/h9t1rmv/6za5u/KPqdGwzmqQE9urg5CbWVNLFiBv3fsnQKJgUGAAIjSqXcMGc+ERoqyhZx0kE6r5n4FZekvHj++LVd/x9C3r0a8RopDT/4/hE2Kkk+xfT8aFFmM3yrn7JXE8VTqCvwrS1ffsOlhlu/QfABLG+ISirxft8GIYd0SYposrGBtnZb8yD0I+esBytNqwQnIE96HE2kwAyRjQUxdekyD8zp+GZ87aYca+LG52bD5rnGjqxAZuSvFcYIM= 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:(13230022)(4636009)(396003)(376002)(39860400002)(346002)(136003)(451199015)(46966006)(36840700001)(40470700004)(2906002)(83380400001)(36860700001)(41300700001)(1076003)(336012)(70586007)(186003)(36756003)(70206006)(2616005)(40460700003)(82310400005)(86362001)(40480700001)(81166007)(356005)(54906003)(110136005)(26005)(426003)(82740400003)(47076005)(7416002)(30864003)(44832011)(8936002)(8676002)(478600001)(4326008)(316002)(5660300002)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:44.1458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d05ff206-6b06-459c-4b3c-08dad86341b7 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: DS1PEPF0000E650.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7865 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch implements the vDPA config operations related to virtqueues or vrings. These include setting vring address, getting vq state, operations to enable/disable a vq etc. The resources required for vring operations eg. VI, interrupts etc. are also allocated. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.c | 58 ++- drivers/net/ethernet/sfc/ef100_vdpa.h | 55 +++ drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 449 +++++++++++++++++++++- 3 files changed, 560 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index ff4bb61e598e..41eb7aef6798 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -15,6 +15,7 @@ #include "ef100_vdpa.h" #include "mcdi_vdpa.h" #include "mcdi_filters.h" +#include "mcdi_functions.h" #include "ef100_netdev.h" static struct virtio_device_id ef100_vdpa_id_table[] = { @@ -48,6 +49,24 @@ int ef100_vdpa_init(struct efx_probe_data *probe_data) return rc; } +static int vdpa_allocate_vis(struct efx_nic *efx, unsigned int *allocated_vis) +{ + /* The first VI is reserved for MCDI + * 1 VI each for rx + tx ring + */ + unsigned int max_vis = 1 + EF100_VDPA_MAX_QUEUES_PAIRS; + unsigned int min_vis = 1 + 1; + int rc; + + rc = efx_mcdi_alloc_vis(efx, min_vis, max_vis, + NULL, allocated_vis); + if (!rc) + return rc; + if (*allocated_vis < min_vis) + return -ENOSPC; + return 0; +} + static void ef100_vdpa_delete(struct efx_nic *efx) { if (efx->vdpa_nic) { @@ -55,6 +74,7 @@ static void ef100_vdpa_delete(struct efx_nic *efx) put_device(&efx->vdpa_nic->vdpa_dev.dev); efx->vdpa_nic = NULL; } + efx_mcdi_free_vis(efx); } void ef100_vdpa_fini(struct efx_probe_data *probe_data) @@ -106,10 +126,20 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, { struct ef100_nic_data *nic_data = efx->nic_data; struct ef100_vdpa_nic *vdpa_nic; + unsigned int allocated_vis; struct device *dev; int rc; + u8 i; nic_data->vdpa_class = dev_type; + rc = vdpa_allocate_vis(efx, &allocated_vis); + if (rc) { + pci_err(efx->pci_dev, + "%s Alloc VIs failed for vf:%u error:%d\n", + __func__, nic_data->vf_index, rc); + return ERR_PTR(rc); + } + vdpa_nic = vdpa_alloc_device(struct ef100_vdpa_nic, vdpa_dev, &efx->pci_dev->dev, &ef100_vdpa_config_ops, @@ -120,7 +150,8 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, "vDPA device allocation failed for vf: %u\n", nic_data->vf_index); nic_data->vdpa_class = EF100_VDPA_CLASS_NONE; - return ERR_PTR(-ENOMEM); + rc = -ENOMEM; + goto err_alloc_vis_free; } mutex_init(&vdpa_nic->lock); @@ -129,6 +160,7 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, vdpa_nic->vdpa_dev.dma_dev = &efx->pci_dev->dev; vdpa_nic->vdpa_dev.mdev = efx->mgmt_dev; vdpa_nic->efx = efx; + vdpa_nic->max_queue_pairs = allocated_vis - 1; vdpa_nic->pf_index = nic_data->pf_index; vdpa_nic->vf_index = nic_data->vf_index; vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; @@ -136,6 +168,27 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, ether_addr_copy(vdpa_nic->mac_address, mac); vdpa_nic->mac_configured = true; + for (i = 0; i < (2 * vdpa_nic->max_queue_pairs); i++) + vdpa_nic->vring[i].irq = -EINVAL; + + rc = ef100_vdpa_irq_vectors_alloc(efx->pci_dev, + vdpa_nic->max_queue_pairs * 2); + if (rc < 0) { + pci_err(efx->pci_dev, + "vDPA IRQ alloc failed for vf: %u err:%d\n", + nic_data->vf_index, rc); + goto err_put_device; + } + + rc = devm_add_action_or_reset(&efx->pci_dev->dev, + ef100_vdpa_irq_vectors_free, + efx->pci_dev); + if (rc) { + pci_err(efx->pci_dev, + "Failed adding devres for freeing irq vectors\n"); + goto err_put_device; + } + rc = get_net_config(vdpa_nic); if (rc) goto err_put_device; @@ -147,6 +200,9 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, err_put_device: /* put_device invokes ef100_vdpa_free */ put_device(&vdpa_nic->vdpa_dev.dev); + +err_alloc_vis_free: + efx_mcdi_free_vis(efx); return ERR_PTR(rc); } diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index be7650c3166a..3cc33daa0431 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -33,6 +33,20 @@ /* Alignment requirement of the Virtqueue */ #define EF100_VDPA_VQ_ALIGN 4096 +/* Vring configuration definitions */ +#define EF100_VRING_ADDRESS_CONFIGURED 0x1 +#define EF100_VRING_SIZE_CONFIGURED 0x10 +#define EF100_VRING_READY_CONFIGURED 0x100 +#define EF100_VRING_CONFIGURED (EF100_VRING_ADDRESS_CONFIGURED | \ + EF100_VRING_SIZE_CONFIGURED | \ + EF100_VRING_READY_CONFIGURED) + +/* Maximum size of msix name */ +#define EF100_VDPA_MAX_MSIX_NAME_SIZE 256 + +/* Default high IOVA for MCDI buffer */ +#define EF100_VDPA_IOVA_BASE_ADDR 0x20000000000 + /** * enum ef100_vdpa_nic_state - possible states for a vDPA NIC * @@ -58,6 +72,43 @@ enum ef100_vdpa_vq_type { EF100_VDPA_VQ_NTYPES }; +/** + * struct ef100_vdpa_vring_info - vDPA vring data structure + * + * @desc: Descriptor area address of the vring + * @avail: Available area address of the vring + * @used: Device area address of the vring + * @size: Number of entries in the vring + * @vring_state: bit map to track vring configuration + * @vring_created: set to true when vring is created. + * @last_avail_idx: last available index of the vring + * @last_used_idx: last used index of the vring + * @doorbell_offset: doorbell offset + * @doorbell_offset_valid: true if @doorbell_offset is updated + * @vring_type: type of vring created + * @vring_ctx: vring context information + * @msix_name: device name for vring irq handler + * @irq: irq number for vring irq handler + * @cb: callback for vring interrupts + */ +struct ef100_vdpa_vring_info { + dma_addr_t desc; + dma_addr_t avail; + dma_addr_t used; + u32 size; + u16 vring_state; + bool vring_created; + u32 last_avail_idx; + u32 last_used_idx; + u32 doorbell_offset; + bool doorbell_offset_valid; + enum ef100_vdpa_vq_type vring_type; + struct efx_vring_ctx *vring_ctx; + char msix_name[EF100_VDPA_MAX_MSIX_NAME_SIZE]; + u32 irq; + struct vdpa_callback cb; +}; + /** * struct ef100_vdpa_nic - vDPA NIC data structure * @@ -71,6 +122,7 @@ enum ef100_vdpa_vq_type { * @features: negotiated feature bits * @max_queue_pairs: maximum number of queue pairs supported * @net_config: virtio_net_config data + * @vring: vring information of the vDPA device. * @mac_address: mac address of interface associated with this vdpa device * @mac_configured: true after MAC address is configured * @cfg_cb: callback for config change @@ -87,6 +139,7 @@ struct ef100_vdpa_nic { u64 features; u32 max_queue_pairs; struct virtio_net_config net_config; + struct ef100_vdpa_vring_info vring[EF100_VDPA_MAX_QUEUES_PAIRS * 2]; u8 *mac_address; bool mac_configured; struct vdpa_callback cfg_cb; @@ -96,6 +149,8 @@ int ef100_vdpa_init(struct efx_probe_data *probe_data); void ef100_vdpa_fini(struct efx_probe_data *probe_data); int ef100_vdpa_register_mgmtdev(struct efx_nic *efx); void ef100_vdpa_unregister_mgmtdev(struct efx_nic *efx); +int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs); +void ef100_vdpa_irq_vectors_free(void *data); static inline bool efx_vdpa_is_little_endian(struct ef100_vdpa_nic *vdpa_nic) { diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index 87899baa1c52..b7efd3e0c901 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -10,13 +10,441 @@ #include #include "ef100_vdpa.h" +#include "io.h" #include "mcdi_vdpa.h" +/* Get the queue's function-local index of the associated VI + * virtqueue number queue 0 is reserved for MCDI + */ +#define EFX_GET_VI_INDEX(vq_num) (((vq_num) / 2) + 1) + static struct ef100_vdpa_nic *get_vdpa_nic(struct vdpa_device *vdev) { return container_of(vdev, struct ef100_vdpa_nic, vdpa_dev); } +static irqreturn_t vring_intr_handler(int irq, void *arg) +{ + struct ef100_vdpa_vring_info *vring = arg; + + if (vring->cb.callback) + return vring->cb.callback(vring->cb.private); + + return IRQ_NONE; +} + +int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs) +{ + int rc; + + rc = pci_alloc_irq_vectors(pci_dev, nvqs, nvqs, PCI_IRQ_MSIX); + if (rc < 0) + pci_err(pci_dev, + "Failed to alloc %d IRQ vectors, err:%d\n", nvqs, rc); + return rc; +} + +void ef100_vdpa_irq_vectors_free(void *data) +{ + pci_free_irq_vectors(data); +} + +static int irq_vring_init(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + struct ef100_vdpa_vring_info *vring = &vdpa_nic->vring[idx]; + struct pci_dev *pci_dev = vdpa_nic->efx->pci_dev; + int irq; + int rc; + + snprintf(vring->msix_name, 256, "x_vdpa[%s]-%d\n", + pci_name(pci_dev), idx); + irq = pci_irq_vector(pci_dev, idx); + rc = devm_request_irq(&pci_dev->dev, irq, vring_intr_handler, 0, + vring->msix_name, vring); + if (rc) + pci_err(pci_dev, + "devm_request_irq failed for vring %d, rc %d\n", + idx, rc); + else + vring->irq = irq; + + return rc; +} + +static void irq_vring_fini(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + struct ef100_vdpa_vring_info *vring = &vdpa_nic->vring[idx]; + struct pci_dev *pci_dev = vdpa_nic->efx->pci_dev; + + devm_free_irq(&pci_dev->dev, vring->irq, vring); + vring->irq = -EINVAL; +} + +static bool can_create_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + if (vdpa_nic->vring[idx].vring_state == EF100_VRING_CONFIGURED && + vdpa_nic->status & VIRTIO_CONFIG_S_DRIVER_OK && + !vdpa_nic->vring[idx].vring_created) + return true; + + return false; +} + +static int create_vring_ctx(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + struct efx_vring_ctx *vring_ctx; + u32 vi_index; + + if (idx % 2) /* Even VQ for RX and odd for TX */ + vdpa_nic->vring[idx].vring_type = EF100_VDPA_VQ_TYPE_NET_TXQ; + else + vdpa_nic->vring[idx].vring_type = EF100_VDPA_VQ_TYPE_NET_RXQ; + vi_index = EFX_GET_VI_INDEX(idx); + vring_ctx = efx_vdpa_vring_init(vdpa_nic->efx, vi_index, + vdpa_nic->vring[idx].vring_type); + if (IS_ERR(vring_ctx)) + return PTR_ERR(vring_ctx); + + vdpa_nic->vring[idx].vring_ctx = vring_ctx; + return 0; +} + +static void delete_vring_ctx(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + efx_vdpa_vring_fini(vdpa_nic->vring[idx].vring_ctx); + vdpa_nic->vring[idx].vring_ctx = NULL; +} + +static int delete_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + struct efx_vring_dyn_cfg vring_dyn_cfg; + int rc; + + rc = efx_vdpa_vring_destroy(vdpa_nic->vring[idx].vring_ctx, + &vring_dyn_cfg); + if (rc) + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: delete vring failed index:%u, err:%d\n", + __func__, idx, rc); + vdpa_nic->vring[idx].last_avail_idx = vring_dyn_cfg.avail_idx; + vdpa_nic->vring[idx].last_used_idx = vring_dyn_cfg.used_idx; + vdpa_nic->vring[idx].vring_created = false; + + irq_vring_fini(vdpa_nic, idx); + + if (vdpa_nic->vring[idx].vring_ctx) + delete_vring_ctx(vdpa_nic, idx); + + return rc; +} + +static int create_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + struct efx_vring_dyn_cfg vring_dyn_cfg; + struct efx_vring_ctx *vring_ctx; + struct efx_vring_cfg vring_cfg; + u32 offset; + int rc; + + if (!vdpa_nic->vring[idx].vring_ctx) { + rc = create_vring_ctx(vdpa_nic, idx); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: create_vring_ctx failed idx:%u, err:%d\n", + __func__, idx, rc); + return rc; + } + } + vring_ctx = vdpa_nic->vring[idx].vring_ctx; + + rc = irq_vring_init(vdpa_nic, idx); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: irq_vring_init failed. index:%u, err:%d\n", + __func__, idx, rc); + goto err_irq_vring_init; + } + vring_cfg.desc = vdpa_nic->vring[idx].desc; + vring_cfg.avail = vdpa_nic->vring[idx].avail; + vring_cfg.used = vdpa_nic->vring[idx].used; + vring_cfg.size = vdpa_nic->vring[idx].size; + vring_cfg.features = vdpa_nic->features; + vring_cfg.msix_vector = idx; + vring_dyn_cfg.avail_idx = vdpa_nic->vring[idx].last_avail_idx; + vring_dyn_cfg.used_idx = vdpa_nic->vring[idx].last_used_idx; + + rc = efx_vdpa_vring_create(vring_ctx, &vring_cfg, &vring_dyn_cfg); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: vring_create failed index:%u, err:%d\n", + __func__, idx, rc); + goto err_vring_create; + } + vdpa_nic->vring[idx].vring_created = true; + if (!vdpa_nic->vring[idx].doorbell_offset_valid) { + rc = efx_vdpa_get_doorbell_offset(vring_ctx, &offset); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: get offset failed, index:%u err:%d\n", + __func__, idx, rc); + goto err_get_doorbell_offset; + } + vdpa_nic->vring[idx].doorbell_offset = offset; + vdpa_nic->vring[idx].doorbell_offset_valid = true; + } + + return 0; + +err_get_doorbell_offset: + efx_vdpa_vring_destroy(vdpa_nic->vring[idx].vring_ctx, + &vring_dyn_cfg); + vdpa_nic->vring[idx].vring_created = false; +err_vring_create: + irq_vring_fini(vdpa_nic, idx); +err_irq_vring_init: + delete_vring_ctx(vdpa_nic, idx); + + return rc; +} + +static void reset_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) +{ + if (vdpa_nic->vring[idx].vring_created) + delete_vring(vdpa_nic, idx); + + memset((void *)&vdpa_nic->vring[idx], 0, + sizeof(vdpa_nic->vring[idx])); + vdpa_nic->vring[idx].vring_type = EF100_VDPA_VQ_NTYPES; +} + +static bool is_qid_invalid(struct ef100_vdpa_nic *vdpa_nic, u16 idx, + const char *caller) +{ + if (unlikely(idx >= (vdpa_nic->max_queue_pairs * 2))) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: Invalid qid %u\n", caller, idx); + return true; + } + return false; +} + +static int ef100_vdpa_set_vq_address(struct vdpa_device *vdev, + u16 idx, u64 desc_area, u64 driver_area, + u64 device_area) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return -EINVAL; + + mutex_lock(&vdpa_nic->lock); + vdpa_nic->vring[idx].desc = desc_area; + vdpa_nic->vring[idx].avail = driver_area; + vdpa_nic->vring[idx].used = device_area; + vdpa_nic->vring[idx].vring_state |= EF100_VRING_ADDRESS_CONFIGURED; + mutex_unlock(&vdpa_nic->lock); + return 0; +} + +static void ef100_vdpa_set_vq_num(struct vdpa_device *vdev, u16 idx, u32 num) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return; + + if (!is_power_of_2(num)) { + dev_err(&vdev->dev, "%s: Index:%u size:%u not power of 2\n", + __func__, idx, num); + return; + } + if (num > EF100_VDPA_VQ_NUM_MAX_SIZE) { + dev_err(&vdev->dev, "%s: Index:%u size:%u more than max:%u\n", + __func__, idx, num, EF100_VDPA_VQ_NUM_MAX_SIZE); + return; + } + mutex_lock(&vdpa_nic->lock); + vdpa_nic->vring[idx].size = num; + vdpa_nic->vring[idx].vring_state |= EF100_VRING_SIZE_CONFIGURED; + mutex_unlock(&vdpa_nic->lock); +} + +static void ef100_vdpa_kick_vq(struct vdpa_device *vdev, u16 idx) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u32 idx_val; + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return; + + if (!vdpa_nic->vring[idx].vring_created) { + dev_err(&vdev->dev, "%s: Invalid vring%u\n", __func__, idx); + return; + } + + idx_val = idx; + _efx_writed(vdpa_nic->efx, cpu_to_le32(idx_val), + vdpa_nic->vring[idx].doorbell_offset); +} + +static void ef100_vdpa_set_vq_cb(struct vdpa_device *vdev, u16 idx, + struct vdpa_callback *cb) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return; + + if (cb) + vdpa_nic->vring[idx].cb = *cb; +} + +static void ef100_vdpa_set_vq_ready(struct vdpa_device *vdev, u16 idx, + bool ready) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return; + + mutex_lock(&vdpa_nic->lock); + if (ready) { + vdpa_nic->vring[idx].vring_state |= + EF100_VRING_READY_CONFIGURED; + if (vdpa_nic->vdpa_state == EF100_VDPA_STATE_STARTED && + can_create_vring(vdpa_nic, idx)) { + if (create_vring(vdpa_nic, idx)) + /* Rollback ready configuration + * So that the above layer driver + * can make another attempt to set ready + */ + vdpa_nic->vring[idx].vring_state &= + ~EF100_VRING_READY_CONFIGURED; + } + } else { + vdpa_nic->vring[idx].vring_state &= + ~EF100_VRING_READY_CONFIGURED; + if (vdpa_nic->vring[idx].vring_created) + delete_vring(vdpa_nic, idx); + } + mutex_unlock(&vdpa_nic->lock); +} + +static bool ef100_vdpa_get_vq_ready(struct vdpa_device *vdev, u16 idx) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + bool ready; + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return false; + + mutex_lock(&vdpa_nic->lock); + ready = vdpa_nic->vring[idx].vring_state & EF100_VRING_READY_CONFIGURED; + mutex_unlock(&vdpa_nic->lock); + return ready; +} + +static int ef100_vdpa_set_vq_state(struct vdpa_device *vdev, u16 idx, + const struct vdpa_vq_state *state) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return -EINVAL; + + mutex_lock(&vdpa_nic->lock); + vdpa_nic->vring[idx].last_avail_idx = state->split.avail_index; + mutex_unlock(&vdpa_nic->lock); + return 0; +} + +static int ef100_vdpa_get_vq_state(struct vdpa_device *vdev, + u16 idx, struct vdpa_vq_state *state) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return -EINVAL; + + mutex_lock(&vdpa_nic->lock); + state->split.avail_index = (u16)vdpa_nic->vring[idx].last_avail_idx; + mutex_unlock(&vdpa_nic->lock); + + return 0; +} + +static struct vdpa_notification_area + ef100_vdpa_get_vq_notification(struct vdpa_device *vdev, + u16 idx) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + struct vdpa_notification_area notify_area = {0, 0}; + struct efx_vring_ctx *vring_ctx; + struct efx_nic *efx; + u32 offset; + int rc; + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + goto end; + + mutex_lock(&vdpa_nic->lock); + vring_ctx = vdpa_nic->vring[idx].vring_ctx; + if (!vring_ctx) { + rc = create_vring_ctx(vdpa_nic, idx); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: vring ctx failed index:%u, err:%d\n", + __func__, idx, rc); + goto err_create_vring_ctx; + } + vring_ctx = vdpa_nic->vring[idx].vring_ctx; + } + if (!vdpa_nic->vring[idx].doorbell_offset_valid) { + rc = efx_vdpa_get_doorbell_offset(vring_ctx, &offset); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: get_doorbell failed idx:%u, err:%d\n", + __func__, idx, rc); + goto err_get_doorbell_off; + } + vdpa_nic->vring[idx].doorbell_offset = offset; + vdpa_nic->vring[idx].doorbell_offset_valid = true; + } + + efx = vdpa_nic->efx; + notify_area.addr = (uintptr_t)(efx->membase_phys + + vdpa_nic->vring[idx].doorbell_offset); + /* VDPA doorbells are at a stride of VI/2 + * One VI stride is shared by both rx & tx doorbells + */ + notify_area.size = efx->vi_stride / 2; + + mutex_unlock(&vdpa_nic->lock); + return notify_area; + +err_get_doorbell_off: + delete_vring_ctx(vdpa_nic, idx); +err_create_vring_ctx: + mutex_unlock(&vdpa_nic->lock); +end: + return notify_area; +} + +static int ef100_get_vq_irq(struct vdpa_device *vdev, u16 idx) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u32 irq; + + if (is_qid_invalid(vdpa_nic, idx, __func__)) + return -EINVAL; + + mutex_lock(&vdpa_nic->lock); + irq = vdpa_nic->vring[idx].irq; + mutex_unlock(&vdpa_nic->lock); + + return irq; +} + static u32 ef100_vdpa_get_vq_align(struct vdpa_device *vdev) { return EF100_VDPA_VQ_ALIGN; @@ -98,6 +526,8 @@ static void ef100_vdpa_set_config_cb(struct vdpa_device *vdev, if (cb) vdpa_nic->cfg_cb = *cb; + else + memset(&vdpa_nic->cfg_cb, 0, sizeof(vdpa_nic->cfg_cb)); } static u16 ef100_vdpa_get_vq_num_max(struct vdpa_device *vdev) @@ -155,11 +585,28 @@ static void ef100_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, static void ef100_vdpa_free(struct vdpa_device *vdev) { struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + int i; - mutex_destroy(&vdpa_nic->lock); + if (vdpa_nic) { + for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) + reset_vring(vdpa_nic, i); + ef100_vdpa_irq_vectors_free(vdpa_nic->efx->pci_dev); + mutex_destroy(&vdpa_nic->lock); + vdpa_nic->efx->vdpa_nic = NULL; + } } const struct vdpa_config_ops ef100_vdpa_config_ops = { + .set_vq_address = ef100_vdpa_set_vq_address, + .set_vq_num = ef100_vdpa_set_vq_num, + .kick_vq = ef100_vdpa_kick_vq, + .set_vq_cb = ef100_vdpa_set_vq_cb, + .set_vq_ready = ef100_vdpa_set_vq_ready, + .get_vq_ready = ef100_vdpa_get_vq_ready, + .set_vq_state = ef100_vdpa_set_vq_state, + .get_vq_state = ef100_vdpa_get_vq_state, + .get_vq_notification = ef100_vdpa_get_vq_notification, + .get_vq_irq = ef100_get_vq_irq, .get_vq_align = ef100_vdpa_get_vq_align, .get_device_features = ef100_vdpa_get_device_features, .set_driver_features = ef100_vdpa_set_driver_features, From patchwork Wed Dec 7 14:54:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067261 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 78015C63706 for ; Wed, 7 Dec 2022 14:57:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230358AbiLGO5i (ORCPT ); Wed, 7 Dec 2022 09:57:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230381AbiLGO46 (ORCPT ); Wed, 7 Dec 2022 09:56:58 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2046.outbound.protection.outlook.com [40.107.93.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC076153F; Wed, 7 Dec 2022 06:56:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R4EDoWBVLRGCvvyA4Hv9+NBNmBhqJlkdRzJN0Z6jwmt9oW+H+dVUp2F1PbXWZ8uuEFm2NJciyVxeXhfH04/VQiBmQin446artftbSpN4gVOQRq5e/O2YxXSUtPokzYi2d3o7h3oE0O/qINpUaTQ0WXnwY5YoaZNYndWZrwxzyCIqr7j20ig5l0l+XPzav7wYg20hT4jnI7iVNfRTsbmcQGK0jdbEV7bpvhNPv4H8gcneLONw9KP098zFJtoKiNKZ/X7o21OgH3ZGxP89Wr6PfBj4RudApZTW4CYzo7XhW5UFUgVcc1KMGZ4YzFukJgq51egRb/MMrlaGd5IcErfGwA== 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=Ic5TNo6q1jZhFnO4jJDarwcedb1PQLi+h0Vo9bCxJDI=; b=dMAIUSVL9W/ccn+AjDAAxTAzBL1kc1z25rmSBSDR/Gfz+5ypTlUHnTbtx8APpOctcxUbOpTYnC4L3WDTBy+RdVROGwyTbG9cK3lIMi/ZbMkZYgc/FffqQj0lei6qakjDB+QIEAjENa4AoisXRF0yJno7jK6laxA2TvUSnlwPCelNBqMCArzyxtbXvtxDF7FkXLDehJeajSmatSnfw1Tn2M0xh8GgAo/E7h5Yd9iDNSX34SDdGX3J6bWcLV2h1pz0I5yittDdSPY0i3qecb31XmM+EL+Zrpswj45861mtlQL9XOnfUw+A1rqX+yexRzgbhXWrexDn2XtQfI5uNh31bQ== 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=Ic5TNo6q1jZhFnO4jJDarwcedb1PQLi+h0Vo9bCxJDI=; b=NrX9rOuhLJRIjIjdmWhVsQFpmicS9Sn/HH9QwePH6tnC8KGTDECd03AoULy+g61Xees/TudUBlv5jixlqvWRwSBrfn11fixEcy7jgd/m4aoPDDkmaImlR7Q3NHvqyHSLqgCRObJTtN6v1qu8jcRgkZmeHXS5ttHH0dMA1kdR9cQ= Received: from DM6PR08CA0014.namprd08.prod.outlook.com (2603:10b6:5:80::27) by BY5PR12MB4853.namprd12.prod.outlook.com (2603:10b6:a03:1da::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:56:48 +0000 Received: from DS1PEPF0000E651.namprd02.prod.outlook.com (2603:10b6:5:80:cafe::fa) by DM6PR08CA0014.outlook.office365.com (2603:10b6:5:80::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:56:48 +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 DS1PEPF0000E651.mail.protection.outlook.com (10.167.18.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:56:48 +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; Wed, 7 Dec 2022 08:56:47 -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; Wed, 7 Dec 2022 08:56:47 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:43 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 07/11] sfc: implement filters for receiving traffic Date: Wed, 7 Dec 2022 20:24:23 +0530 Message-ID: <20221207145428.31544-8-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E651:EE_|BY5PR12MB4853:EE_ X-MS-Office365-Filtering-Correlation-Id: aaf61f91-8f78-483c-53ff-08dad8634422 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EkUh9lhzBmPsgec61BYz93v4vQUygzk5NVGVOVEfMLi4Psu7JTydHd0RyQf/glDlw0WKwNJOfITSFyiPtGY1V7cOhMexsY8br6QEmPgjFLG8GZrPcCiubskN8WnUnwi8SsVeeDN/hR31riFp0nsHTLT5PX1djmRUtzMs+XoNI9e1I7X3LkttqUXHKrkdOPF7B+xvqtdD1C+v0Rt+IwKI/+6MsBOqXKtXCbNK8gFx+Wyhp99kPk4osarKcpZyfff6iA1rpEtNGI/o9966obwdAJzMmb/uZC8JtCd//m3NNFUdIE49nfzSsy/7K7c53zwzTGPoPTSCbJpUJBw5GqzRnJol0nMKozfqCrdOLN5ZQBFPBd7Qs7DjUuWIBv9gNNzfpj0FBDgDTIxaUA2cL2HUAjuKIfAFIR4J30bL/y7O/VtDNOZ69wUYKA7f+Zn2YqsdBZf3lpFssDVgbvOAq3dUYdgnTx4NbqhraMLyHNKec2qONsEzRyN8LBi0KjXxpfwYxGi82DYDiAfVmSnfdIF3gUcXakpmaeJ0X2QyD0rIRRPVbf4RiPNA7dHJTjpGHSAjHdEuF0JpvVsACZfVFkrm0JP1kzdU0LgBl8t3y8IT5arkkZjf9gBP5R8eSwk4s3baPIJ3VEn9/HEdWUUloN/F64v7CjmOODZrF4znwCuIoL5UobvJTSGCNmePIg3518nGqxQHvXpWrdI8OfpZGWgQOvFb26WFH/tx8TYpV5W7vL8= 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:(13230022)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199015)(36840700001)(40470700004)(46966006)(81166007)(8676002)(4326008)(70586007)(41300700001)(54906003)(70206006)(8936002)(426003)(6666004)(47076005)(40460700003)(478600001)(316002)(26005)(36756003)(186003)(82740400003)(356005)(2616005)(1076003)(336012)(110136005)(40480700001)(86362001)(36860700001)(83380400001)(5660300002)(82310400005)(7416002)(44832011)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:56:48.2183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aaf61f91-8f78-483c-53ff-08dad8634422 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: DS1PEPF0000E651.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4853 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Implement unicast, broadcast and unknown multicast filters for receiving different types of traffic. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.c | 159 ++++++++++++++++++++++ drivers/net/ethernet/sfc/ef100_vdpa.h | 35 +++++ drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 27 +++- 3 files changed, 220 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index 41eb7aef6798..04d64bfe3c93 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -17,12 +17,168 @@ #include "mcdi_filters.h" #include "mcdi_functions.h" #include "ef100_netdev.h" +#include "filter.h" +#include "efx.h" +#define EFX_INVALID_FILTER_ID -1 + +/* vDPA queues starts from 2nd VI or qid 1 */ +#define EF100_VDPA_BASE_RX_QID 1 + +static const char * const filter_names[] = { "bcast", "ucast", "mcast" }; static struct virtio_device_id ef100_vdpa_id_table[] = { { .device = VIRTIO_ID_NET, .vendor = PCI_VENDOR_ID_REDHAT_QUMRANET }, { 0 }, }; +static int ef100_vdpa_set_mac_filter(struct efx_nic *efx, + struct efx_filter_spec *spec, + u32 qid, + u8 *mac_addr) +{ + int rc; + + efx_filter_init_rx(spec, EFX_FILTER_PRI_AUTO, 0, qid); + + if (mac_addr) { + rc = efx_filter_set_eth_local(spec, EFX_FILTER_VID_UNSPEC, + mac_addr); + if (rc) + pci_err(efx->pci_dev, + "Filter set eth local failed, err: %d\n", rc); + } else { + efx_filter_set_mc_def(spec); + } + + rc = efx_filter_insert_filter(efx, spec, true); + if (rc < 0) + pci_err(efx->pci_dev, + "Filter insert failed, err: %d\n", rc); + + return rc; +} + +static int ef100_vdpa_delete_filter(struct ef100_vdpa_nic *vdpa_nic, + enum ef100_vdpa_mac_filter_type type) +{ + struct vdpa_device *vdev = &vdpa_nic->vdpa_dev; + int rc; + + if (vdpa_nic->filters[type].filter_id == EFX_INVALID_FILTER_ID) + return rc; + + rc = efx_filter_remove_id_safe(vdpa_nic->efx, + EFX_FILTER_PRI_AUTO, + vdpa_nic->filters[type].filter_id); + if (rc) { + dev_err(&vdev->dev, "%s filter id: %d remove failed, err: %d\n", + filter_names[type], vdpa_nic->filters[type].filter_id, + rc); + } else { + vdpa_nic->filters[type].filter_id = EFX_INVALID_FILTER_ID; + vdpa_nic->filter_cnt--; + } + return rc; +} + +int ef100_vdpa_add_filter(struct ef100_vdpa_nic *vdpa_nic, + enum ef100_vdpa_mac_filter_type type) +{ + struct vdpa_device *vdev = &vdpa_nic->vdpa_dev; + struct efx_nic *efx = vdpa_nic->efx; + /* Configure filter on base Rx queue only */ + u32 qid = EF100_VDPA_BASE_RX_QID; + struct efx_filter_spec *spec; + u8 baddr[ETH_ALEN]; + int rc; + + /* remove existing filter */ + rc = ef100_vdpa_delete_filter(vdpa_nic, type); + if (rc < 0) { + dev_err(&vdev->dev, "%s MAC filter deletion failed, err: %d", + filter_names[type], rc); + return rc; + } + + /* Configure MAC Filter */ + spec = &vdpa_nic->filters[type].spec; + if (type == EF100_VDPA_BCAST_MAC_FILTER) { + eth_broadcast_addr(baddr); + rc = ef100_vdpa_set_mac_filter(efx, spec, qid, baddr); + } else if (type == EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER) { + rc = ef100_vdpa_set_mac_filter(efx, spec, qid, NULL); + } else { + /* Ensure we have everything required to insert the filter */ + if (!vdpa_nic->mac_configured || + !vdpa_nic->vring[0].vring_created || + !is_valid_ether_addr(vdpa_nic->mac_address)) + return -EINVAL; + + rc = ef100_vdpa_set_mac_filter(efx, spec, qid, + vdpa_nic->mac_address); + } + + if (rc >= 0) { + vdpa_nic->filters[type].filter_id = rc; + vdpa_nic->filter_cnt++; + + return 0; + } + + dev_err(&vdev->dev, "%s MAC filter insert failed, err: %d\n", + filter_names[type], rc); + + if (type != EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER) { + ef100_vdpa_filter_remove(vdpa_nic); + return rc; + } + + return 0; +} + +int ef100_vdpa_filter_remove(struct ef100_vdpa_nic *vdpa_nic) +{ + enum ef100_vdpa_mac_filter_type filter; + int err = 0; + int rc; + + for (filter = EF100_VDPA_BCAST_MAC_FILTER; + filter <= EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER; filter++) { + rc = ef100_vdpa_delete_filter(vdpa_nic, filter); + if (rc < 0) + /* store status of last failed filter remove */ + err = rc; + } + return err; +} + +int ef100_vdpa_filter_configure(struct ef100_vdpa_nic *vdpa_nic) +{ + struct vdpa_device *vdev = &vdpa_nic->vdpa_dev; + enum ef100_vdpa_mac_filter_type filter; + int rc; + + /* remove existing filters, if any */ + rc = ef100_vdpa_filter_remove(vdpa_nic); + if (rc < 0) { + dev_err(&vdev->dev, + "MAC filter deletion failed, err: %d", rc); + goto fail; + } + + for (filter = EF100_VDPA_BCAST_MAC_FILTER; + filter <= EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER; filter++) { + if (filter == EF100_VDPA_UCAST_MAC_FILTER && + !vdpa_nic->mac_configured) + continue; + rc = ef100_vdpa_add_filter(vdpa_nic, filter); + if (rc < 0) + goto fail; + } +fail: + return rc; +} + int ef100_vdpa_init(struct efx_probe_data *probe_data) { struct efx_nic *efx = &probe_data->efx; @@ -168,6 +324,9 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, ether_addr_copy(vdpa_nic->mac_address, mac); vdpa_nic->mac_configured = true; + for (i = 0; i < EF100_VDPA_MAC_FILTER_NTYPES; i++) + vdpa_nic->filters[i].filter_id = EFX_INVALID_FILTER_ID; + for (i = 0; i < (2 * vdpa_nic->max_queue_pairs); i++) vdpa_nic->vring[i].irq = -EINVAL; diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index 3cc33daa0431..a33edd6dda12 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -72,6 +72,22 @@ enum ef100_vdpa_vq_type { EF100_VDPA_VQ_NTYPES }; +/** + * enum ef100_vdpa_mac_filter_type - vdpa filter types + * + * @EF100_VDPA_BCAST_MAC_FILTER: Broadcast MAC filter + * @EF100_VDPA_UCAST_MAC_FILTER: Unicast MAC filter + * @EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER: Unknown multicast MAC filter to allow + * IPv6 Neighbor Solicitation Message + * @EF100_VDPA_MAC_FILTER_NTYPES: Number of vDPA filter types + */ +enum ef100_vdpa_mac_filter_type { + EF100_VDPA_BCAST_MAC_FILTER, + EF100_VDPA_UCAST_MAC_FILTER, + EF100_VDPA_UNKNOWN_MCAST_MAC_FILTER, + EF100_VDPA_MAC_FILTER_NTYPES, +}; + /** * struct ef100_vdpa_vring_info - vDPA vring data structure * @@ -109,6 +125,17 @@ struct ef100_vdpa_vring_info { struct vdpa_callback cb; }; +/** + * struct ef100_vdpa_filter - vDPA filter data structure + * + * @filter_id: filter id of this filter + * @efx_filter_spec: hardware filter specs for this vdpa device + */ +struct ef100_vdpa_filter { + s32 filter_id; + struct efx_filter_spec spec; +}; + /** * struct ef100_vdpa_nic - vDPA NIC data structure * @@ -118,6 +145,7 @@ struct ef100_vdpa_vring_info { * @lock: Managing access to vdpa config operations * @pf_index: PF index of the vDPA VF * @vf_index: VF index of the vDPA VF + * @filter_cnt: total number of filters created on this vdpa device * @status: device status as per VIRTIO spec * @features: negotiated feature bits * @max_queue_pairs: maximum number of queue pairs supported @@ -125,6 +153,7 @@ struct ef100_vdpa_vring_info { * @vring: vring information of the vDPA device. * @mac_address: mac address of interface associated with this vdpa device * @mac_configured: true after MAC address is configured + * @filters: details of all filters created on this vdpa device * @cfg_cb: callback for config change */ struct ef100_vdpa_nic { @@ -135,6 +164,7 @@ struct ef100_vdpa_nic { struct mutex lock; u32 pf_index; u32 vf_index; + u32 filter_cnt; u8 status; u64 features; u32 max_queue_pairs; @@ -142,6 +172,7 @@ struct ef100_vdpa_nic { struct ef100_vdpa_vring_info vring[EF100_VDPA_MAX_QUEUES_PAIRS * 2]; u8 *mac_address; bool mac_configured; + struct ef100_vdpa_filter filters[EF100_VDPA_MAC_FILTER_NTYPES]; struct vdpa_callback cfg_cb; }; @@ -149,6 +180,10 @@ int ef100_vdpa_init(struct efx_probe_data *probe_data); void ef100_vdpa_fini(struct efx_probe_data *probe_data); int ef100_vdpa_register_mgmtdev(struct efx_nic *efx); void ef100_vdpa_unregister_mgmtdev(struct efx_nic *efx); +int ef100_vdpa_filter_configure(struct ef100_vdpa_nic *vdpa_nic); +int ef100_vdpa_filter_remove(struct ef100_vdpa_nic *vdpa_nic); +int ef100_vdpa_add_filter(struct ef100_vdpa_nic *vdpa_nic, + enum ef100_vdpa_mac_filter_type type); int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs); void ef100_vdpa_irq_vectors_free(void *data); diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index b7efd3e0c901..132ddb4a647b 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -135,6 +135,15 @@ static int delete_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) if (vdpa_nic->vring[idx].vring_ctx) delete_vring_ctx(vdpa_nic, idx); + if (idx == 0 && vdpa_nic->filter_cnt != 0) { + rc = ef100_vdpa_filter_remove(vdpa_nic); + if (rc < 0) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: vdpa remove filter failed, err:%d\n", + __func__, rc); + } + } + return rc; } @@ -193,8 +202,22 @@ static int create_vring(struct ef100_vdpa_nic *vdpa_nic, u16 idx) vdpa_nic->vring[idx].doorbell_offset_valid = true; } + /* Configure filters on rxq 0 */ + if (idx == 0) { + rc = ef100_vdpa_filter_configure(vdpa_nic); + if (rc < 0) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: vdpa configure filter failed, err:%d\n", + __func__, rc); + goto err_filter_configure; + } + } + return 0; +err_filter_configure: + ef100_vdpa_filter_remove(vdpa_nic); + vdpa_nic->vring[idx].doorbell_offset_valid = false; err_get_doorbell_offset: efx_vdpa_vring_destroy(vdpa_nic->vring[idx].vring_ctx, &vring_dyn_cfg); @@ -578,8 +601,10 @@ static void ef100_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, } memcpy((u8 *)&vdpa_nic->net_config + offset, buf, len); - if (is_valid_ether_addr(vdpa_nic->mac_address)) + if (is_valid_ether_addr(vdpa_nic->mac_address)) { vdpa_nic->mac_configured = true; + ef100_vdpa_add_filter(vdpa_nic, EF100_VDPA_UCAST_MAC_FILTER); + } } static void ef100_vdpa_free(struct vdpa_device *vdev) From patchwork Wed Dec 7 14:54:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067262 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 0876BC4708E for ; Wed, 7 Dec 2022 14:58:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229507AbiLGO6p (ORCPT ); Wed, 7 Dec 2022 09:58:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbiLGO6Z (ORCPT ); Wed, 7 Dec 2022 09:58:25 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2072.outbound.protection.outlook.com [40.107.101.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062314EC07; Wed, 7 Dec 2022 06:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ggw8Cwa4M+o8lMdZg2qKcIAn5KVK5wBku8037Ur+MW4hnvoINfvVUVM+azlQLeMmLGqVu7FpuRZRR1lepGS+GSgJR0jTaER9FnNAchknA6oMkHQNuyABAwOgdPf3OhIo7ktx07iysYX5aFR5/2NmwD7c5wRQc80Plpi33RUPLI3m6RrZ9pznbKIxGLZP40lQAk7ZIYv6Y+1x/nHWXuZ+UA1brf2q3BUtWmxHeANfN7KvFSbOMH0DZyo+2ptpDtrN02E2VfavGzfDs//D6l80Uwu1oiAQB5hYjevNTWs7T/CfbPLVcg5rKK0dGtorXwSzLoWtWZOhRhl3yA/RHknpgA== 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=wN4JvbxJUxprc40JNbIgPFAwATrQ47v54hKmeJapnNI=; b=ftrxIdBIEtuXDvWiMhvJg52wl3bhb4vpYOMVHMuhNXUu1Jp7EMXpXQBDP5g3RXRieuAtwbxmUkTxC2dHUv050La9PvlEAOoPiMHSjMjvaO+ETqBThEYaHiyWwZctvpHKR/TuG9cExoPuO2tWek0FQP07i+U15DHyWz87Rl46geykmC5IfiV7vehhMD1iXbX1p7Q0Lao7Lx6UO+3WL6Nv+h9UoxwmxKDo28RqpdxPFhPQE5KrI9eXboApmiLWKqgyxYsIZ/DV1pv692QVIwCJ/xykAGd9TOqMqE0/pnjAxVfe+oy//nBuXp+9TC6QGYbgIz6xypRLb2Z6pbu/LJyE8A== 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=wN4JvbxJUxprc40JNbIgPFAwATrQ47v54hKmeJapnNI=; b=gsubCZ6mQU8pG73WYfxzdX4hAgBWqZ3T3g5riO6/FLzZcB5rs2gTka+Kh7pCAhO/fgm0kB6/4Y2kHdCpR4kTujoT3W6furkrZCf/gcDq0yFYaf4r1dOQ/Ti8ysXRscDtlZSUpyFlarEfjpUWytCmIYQS8+bhykcgekr/mcPx1KI= Received: from DS7PR05CA0028.namprd05.prod.outlook.com (2603:10b6:5:3b9::33) by BN9PR12MB5383.namprd12.prod.outlook.com (2603:10b6:408:104::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:57:26 +0000 Received: from DS1PEPF0000E633.namprd02.prod.outlook.com (2603:10b6:5:3b9:cafe::13) by DS7PR05CA0028.outlook.office365.com (2603:10b6:5:3b9::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Wed, 7 Dec 2022 14:57:25 +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 DS1PEPF0000E633.mail.protection.outlook.com (10.167.17.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:57:25 +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; Wed, 7 Dec 2022 08:57:21 -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; Wed, 7 Dec 2022 06:56:52 -0800 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:56:48 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 08/11] sfc: implement device status related vdpa config operations Date: Wed, 7 Dec 2022 20:24:24 +0530 Message-ID: <20221207145428.31544-9-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E633:EE_|BN9PR12MB5383:EE_ X-MS-Office365-Filtering-Correlation-Id: 051276fa-6fb3-4102-b023-08dad8635a91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T9S7GfRO1F21F1Xrm+NPQQ6SBp+dLnRiv0K6rLVOAu/kGecCq4qmfPo1vpogz+vIlaahrKdTuIhtUX1S0w4/M10pLNLSjHbLlXy2K0/thtfoXeBHSdEXRvFy46bL1CKbAFznUtxuPRl5hd+4iQLlngKwGNrfuJYmhW4/ID9DQOsM24TiNMR1i4PuCGKa1wiiLd+d3DZ8/7kbxqKDvCGOYpDWvgzxzFlCwh1dAvQfBwnOm08ZtBhTPnPDKIpNZzGl7r+LOTLpyMNk2Tv6udPEbN2iJ3cYNygUuW2a6YOPU2ahLzpaJSxmhlikkqcqABzWaGcyuyroOSQEUMtClPM5lxxgtyqJOQ3SVmpcLKTw2vTNrKyCXsjYnrSGTzehwN1aA9SnD0PIIaHG2bgHEk+iSgmytRMix3e2EUAQyRZWS36L7QtF4YP1WdQkZmeS8qLg/w83FR1YXky/dx2M9oPeDm5sFPnYA1JWLymllktaHqXL0mjve6XcKiIv3D9fJl/WarEgECd8GZyeHbmTXELi8FjbCXygFtIsm+V72qHkyCBklEiIK20rqlx8yLGVnVbngWx97zGrJ7IeO3aoxJ5KXyp3sM9VmUfxzBplKAOHIJxrLfRDBzPM1bG8NEiGvfF9eRfhVJj9To/aYD8OVvaT3RQ2iqd4WdeX7wDPNSuoRHl60BXajHcewbtYALiqQN2Wbwl+1o/J+aclltuWjCGJqRkzOSynVu6Y2wB5Qj0AWls= 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:(13230022)(4636009)(136003)(346002)(376002)(39860400002)(396003)(451199015)(36840700001)(46966006)(40470700004)(36756003)(81166007)(8936002)(356005)(86362001)(44832011)(40460700003)(4326008)(41300700001)(2906002)(5660300002)(7416002)(36860700001)(83380400001)(70206006)(54906003)(110136005)(316002)(70586007)(8676002)(2616005)(82740400003)(40480700001)(82310400005)(478600001)(186003)(426003)(6666004)(47076005)(26005)(336012)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:57:25.8425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 051276fa-6fb3-4102-b023-08dad8635a91 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: DS1PEPF0000E633.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5383 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org vDPA config opertions to handle get/set device status and device reset have been implemented. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.c | 7 +- drivers/net/ethernet/sfc/ef100_vdpa.h | 1 + drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 133 ++++++++++++++++++++++ 3 files changed, 140 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index 04d64bfe3c93..80bca281a748 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -225,9 +225,14 @@ static int vdpa_allocate_vis(struct efx_nic *efx, unsigned int *allocated_vis) static void ef100_vdpa_delete(struct efx_nic *efx) { + struct vdpa_device *vdpa_dev; + if (efx->vdpa_nic) { + vdpa_dev = &efx->vdpa_nic->vdpa_dev; + ef100_vdpa_reset(vdpa_dev); + /* replace with _vdpa_unregister_device later */ - put_device(&efx->vdpa_nic->vdpa_dev.dev); + put_device(&vdpa_dev->dev); efx->vdpa_nic = NULL; } efx_mcdi_free_vis(efx); diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index a33edd6dda12..1b0bbba88154 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -186,6 +186,7 @@ int ef100_vdpa_add_filter(struct ef100_vdpa_nic *vdpa_nic, enum ef100_vdpa_mac_filter_type type); int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs); void ef100_vdpa_irq_vectors_free(void *data); +int ef100_vdpa_reset(struct vdpa_device *vdev); static inline bool efx_vdpa_is_little_endian(struct ef100_vdpa_nic *vdpa_nic) { diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index 132ddb4a647b..718b67f6da90 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -251,6 +251,62 @@ static bool is_qid_invalid(struct ef100_vdpa_nic *vdpa_nic, u16 idx, return false; } +static void ef100_reset_vdpa_device(struct ef100_vdpa_nic *vdpa_nic) +{ + int i; + + WARN_ON(!mutex_is_locked(&vdpa_nic->lock)); + + if (!vdpa_nic->status) + return; + + vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; + vdpa_nic->status = 0; + vdpa_nic->features = 0; + for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) + reset_vring(vdpa_nic, i); +} + +/* May be called under the rtnl lock */ +int ef100_vdpa_reset(struct vdpa_device *vdev) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + + /* vdpa device can be deleted anytime but the bar_config + * could still be vdpa and hence efx->state would be STATE_VDPA. + * Accordingly, ensure vdpa device exists before reset handling + */ + if (!vdpa_nic) + return -ENODEV; + + mutex_lock(&vdpa_nic->lock); + ef100_reset_vdpa_device(vdpa_nic); + mutex_unlock(&vdpa_nic->lock); + return 0; +} + +static int start_vdpa_device(struct ef100_vdpa_nic *vdpa_nic) +{ + int rc = 0; + int i, j; + + for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) { + if (can_create_vring(vdpa_nic, i)) { + rc = create_vring(vdpa_nic, i); + if (rc) + goto clear_vring; + } + } + vdpa_nic->vdpa_state = EF100_VDPA_STATE_STARTED; + return rc; + +clear_vring: + for (j = 0; j < i; j++) + if (vdpa_nic->vring[j].vring_created) + delete_vring(vdpa_nic, j); + return rc; +} + static int ef100_vdpa_set_vq_address(struct vdpa_device *vdev, u16 idx, u64 desc_area, u64 driver_area, u64 device_area) @@ -568,6 +624,80 @@ static u32 ef100_vdpa_get_vendor_id(struct vdpa_device *vdev) return EF100_VDPA_VENDOR_ID; } +static u8 ef100_vdpa_get_status(struct vdpa_device *vdev) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u8 status; + + mutex_lock(&vdpa_nic->lock); + status = vdpa_nic->status; + mutex_unlock(&vdpa_nic->lock); + return status; +} + +static void ef100_vdpa_set_status(struct vdpa_device *vdev, u8 status) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + u8 new_status; + int rc; + + mutex_lock(&vdpa_nic->lock); + if (!status) { + dev_info(&vdev->dev, + "%s: Status received is 0. Device reset being done\n", + __func__); + ef100_reset_vdpa_device(vdpa_nic); + goto unlock_return; + } + new_status = status & ~vdpa_nic->status; + if (new_status == 0) { + dev_info(&vdev->dev, + "%s: New status same as current status\n", __func__); + goto unlock_return; + } + if (new_status & VIRTIO_CONFIG_S_FAILED) { + ef100_reset_vdpa_device(vdpa_nic); + goto unlock_return; + } + + if (new_status & VIRTIO_CONFIG_S_ACKNOWLEDGE && + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { + vdpa_nic->status |= VIRTIO_CONFIG_S_ACKNOWLEDGE; + new_status &= ~VIRTIO_CONFIG_S_ACKNOWLEDGE; + } + if (new_status & VIRTIO_CONFIG_S_DRIVER && + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { + vdpa_nic->status |= VIRTIO_CONFIG_S_DRIVER; + new_status &= ~VIRTIO_CONFIG_S_DRIVER; + } + if (new_status & VIRTIO_CONFIG_S_FEATURES_OK && + vdpa_nic->vdpa_state == EF100_VDPA_STATE_INITIALIZED) { + vdpa_nic->status |= VIRTIO_CONFIG_S_FEATURES_OK; + vdpa_nic->vdpa_state = EF100_VDPA_STATE_NEGOTIATED; + new_status &= ~VIRTIO_CONFIG_S_FEATURES_OK; + } + if (new_status & VIRTIO_CONFIG_S_DRIVER_OK && + vdpa_nic->vdpa_state == EF100_VDPA_STATE_NEGOTIATED) { + vdpa_nic->status |= VIRTIO_CONFIG_S_DRIVER_OK; + rc = start_vdpa_device(vdpa_nic); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: vDPA device failed:%d\n", __func__, rc); + vdpa_nic->status &= ~VIRTIO_CONFIG_S_DRIVER_OK; + goto unlock_return; + } + new_status &= ~VIRTIO_CONFIG_S_DRIVER_OK; + } + if (new_status) { + dev_warn(&vdev->dev, + "%s: Mismatch Status: %x & State: %u\n", + __func__, new_status, vdpa_nic->vdpa_state); + } + +unlock_return: + mutex_unlock(&vdpa_nic->lock); +} + static size_t ef100_vdpa_get_config_size(struct vdpa_device *vdev) { return sizeof(struct virtio_net_config); @@ -640,6 +770,9 @@ const struct vdpa_config_ops ef100_vdpa_config_ops = { .get_vq_num_max = ef100_vdpa_get_vq_num_max, .get_device_id = ef100_vdpa_get_device_id, .get_vendor_id = ef100_vdpa_get_vendor_id, + .get_status = ef100_vdpa_get_status, + .set_status = ef100_vdpa_set_status, + .reset = ef100_vdpa_reset, .get_config_size = ef100_vdpa_get_config_size, .get_config = ef100_vdpa_get_config, .set_config = ef100_vdpa_set_config, From patchwork Wed Dec 7 14:54:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067263 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 3AD54C352A1 for ; Wed, 7 Dec 2022 14:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229818AbiLGO6r (ORCPT ); Wed, 7 Dec 2022 09:58:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbiLGO61 (ORCPT ); Wed, 7 Dec 2022 09:58:27 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2066.outbound.protection.outlook.com [40.107.92.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054D5286C9; Wed, 7 Dec 2022 06:57:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QO2AFiHcp7FsPca032sRGVisIb6Dng0k6krhrNmhpncOcgQe8F4SconpcF1PnJmE+zh9GdDsuNAAJXG+Os5sZxbjLzQvJwGCa0IhK1pKzfz3I5teQH52L03q3x1Oj/lKeX6MlENpMrhHi2ol5WPFZqntv4J2ClIRCsiHvmsvnQHfR3iCpRpiQDt/RcHtYB91cJS6zUBTb0GHg63birSEeyfu0EwXpyZ7KXQL1kBec43t/6HI/4AcAh3aMwGBwIl3hYWRqG7R/tlelLVPDnXt3zLs5XDY9NCPP28FCU57t7Ekt+jgrnuRtmC8yG8c26ciMU0k+oeopearabYttOT3Tw== 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=pBP928L7PbICB3GBzOJVIoT4VDNI03KsNRLoodNlAhg=; b=eMkiv/GkhvM7Xqz1ML1eUzgI0l+7NQwKODrR4OsP9ae3GsI7CBEk8JYD0JvjlWp5W2HNJ7arI5yoyv6fXfBARPGgUObAA8CWZSS4lQ9YXNcjDh+/le7nE82wHnswOCL/1sGyZt2cyyimZt9X2QEQANizT7jgEB4HoWvg7C2wGRqc8yg2EdJJ3cPSk8yQxWnACq+PhKPbqEigSdP/AVnXRBNYqNCyOaVCKdf50IS82H9Yo20fs2XwS1u/rXmfl+YwpQ6NijecyoJTxI1ikBe6Z2/GgjOEIHsZir13QHF4yiC6ktPMfdSj1ak3lz75Ego5yunntz5hzqwgCqVny+VdGA== 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=pBP928L7PbICB3GBzOJVIoT4VDNI03KsNRLoodNlAhg=; b=3mMVMRJQ0ewbC5n23YNfKdDUHdyBoiT/RrqtIenS5qQ818EifBZbHlbiQMbUYD1NcvafflkNyAW5905mLOFTWjwCx6mAGU+FVoOH33jpsjPx/cA5jiUZ1+FmzreatDs/L3DCoyilqBhiNAcCCWWdRQvtnAXUkPes1vtyZru+ZEw= Received: from DM6PR03CA0039.namprd03.prod.outlook.com (2603:10b6:5:100::16) by BL0PR12MB4929.namprd12.prod.outlook.com (2603:10b6:208:1c4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:57:29 +0000 Received: from DS1PEPF0000E652.namprd02.prod.outlook.com (2603:10b6:5:100:cafe::f4) by DM6PR03CA0039.outlook.office365.com (2603:10b6:5:100::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:57:29 +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 DS1PEPF0000E652.mail.protection.outlook.com (10.167.18.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:57:29 +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; Wed, 7 Dec 2022 08:57:27 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:57:23 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 09/11] sfc: implement iova rbtree to store dma mappings Date: Wed, 7 Dec 2022 20:24:25 +0530 Message-ID: <20221207145428.31544-10-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E652:EE_|BL0PR12MB4929:EE_ X-MS-Office365-Filtering-Correlation-Id: a5b0856c-55dd-4e24-9768-08dad8635cda X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ipiim5mvAGn0SCUyc4iU+nRkxk1AlfI1q9zCp5zRjPvZhg/Fas43pgtEZQNWcZD1fOtLCPAl48T7vOnCAA6BVNMa3PGXsjPVI2BJo0TZXGw8NnAZGcbZQ+brHNKoqQq7GEGvtpkT9kf/Uw4N+RM5bbMsf3qEE+ihMe7eAlkdIUJ/QOiaBLNT5zLnRDwnWoPPfe9f7Hyp2eqcSfn9dfqCB3fZux89s3t8fsNk4ARZADkvA2ropBjs3z/T6uRZI/5apAd9Oj9s77d9s2YcpNcEAAoiOtwH6SWQLsrok0xDi6PPDGeSE5/VW/uXS1c16OqAmSCjgH9ArOTEnjwXv1EzRycoXm4DskCZRfRaMDbpur7fUkbvjNgWnfjct6EAroe0entYMWVDJX/nOiHqRzPfMXRsIUaOhJuX4/b2jGmySmpMF4i5ySOjYT1YHZJiSq5tLGYlQcJAwRZCG1tE1jWT72VjXuJjVPaCTEdyEF6ZolCmi6dz1aCrLlGu6uG7F4vagrHpzWkaLXWFdX71kmU5S/cjgz0stUj2HR8nmH+NYxV3xueW54YAYW5lfy//WXnYAzI2PCPV9Z14/mHYPdBEJgU7s/SKWahripmEt1FoOYSr8zLsefUpbt13MKbEJjnC3NRxxIgJxNPMjTiCkAbIHN3xrSO5ZFf729Ll2xdG5YMwS/rI2+T+y39ZUgzjh/aC5sdwjIfsJ0wl3yQJXSGa3Hj2qfA4yW5rpYx6a5cuKpGgIfmzxSUnOYwaA1CgMin9 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:(13230022)(4636009)(39860400002)(396003)(136003)(346002)(376002)(451199015)(36840700001)(46966006)(40470700004)(86362001)(36756003)(2616005)(70206006)(4326008)(41300700001)(2906002)(8676002)(40460700003)(7416002)(5660300002)(8936002)(30864003)(356005)(44832011)(81166007)(316002)(40480700001)(82740400003)(110136005)(83380400001)(36860700001)(54906003)(426003)(336012)(478600001)(1076003)(26005)(82310400005)(70586007)(47076005)(186003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:57:29.6756 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a5b0856c-55dd-4e24-9768-08dad8635cda 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: DS1PEPF0000E652.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4929 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org sfc uses a MCDI DMA buffer that is allocated on the host for communicating with the Firmware. The MCDI buffer IOVA could overlap with the IOVA used by the guest for the virtqueue buffers. To detect such overlap, the DMA mappings from the guest will be stored in a IOVA rbtree and every such mapping will be compared against the MCDI buffer IOVA range. If an overlap is detected, the MCDI buffer will be relocated to a different IOVA. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/Makefile | 3 +- drivers/net/ethernet/sfc/ef100_iova.c | 205 ++++++++++++++++++++++ drivers/net/ethernet/sfc/ef100_iova.h | 40 +++++ drivers/net/ethernet/sfc/ef100_nic.c | 1 - drivers/net/ethernet/sfc/ef100_vdpa.c | 38 ++++ drivers/net/ethernet/sfc/ef100_vdpa.h | 15 ++ drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 5 + drivers/net/ethernet/sfc/mcdi.h | 3 + 8 files changed, 308 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/sfc/ef100_iova.c create mode 100644 drivers/net/ethernet/sfc/ef100_iova.h diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index a10eac91ab23..85852ff50b7c 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -11,7 +11,8 @@ 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 -sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o ef100_vdpa.o ef100_vdpa_ops.o +sfc-$(CONFIG_SFC_VDPA) += mcdi_vdpa.o ef100_vdpa.o ef100_vdpa_ops.o \ + ef100_iova.o obj-$(CONFIG_SFC) += sfc.o obj-$(CONFIG_SFC_FALCON) += falcon/ diff --git a/drivers/net/ethernet/sfc/ef100_iova.c b/drivers/net/ethernet/sfc/ef100_iova.c new file mode 100644 index 000000000000..863314c5b9b5 --- /dev/null +++ b/drivers/net/ethernet/sfc/ef100_iova.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Driver for Xilinx network controllers and boards + * Copyright(C) 2020-2022 Xilinx, Inc. + * Copyright(C) 2022 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 "ef100_iova.h" + +static void update_free_list_node(struct ef100_vdpa_iova_node *target_node, + struct ef100_vdpa_iova_node *next_node, + struct ef100_vdpa_nic *vdpa_nic) +{ + unsigned long target_node_end; + unsigned long free_area; + bool in_list; + + target_node_end = target_node->iova + target_node->size; + free_area = next_node->iova - target_node_end; + in_list = !(list_empty(&target_node->free_node)); + + if (!in_list && free_area >= MCDI_BUF_LEN) { + list_add(&target_node->free_node, + &vdpa_nic->free_list); + } else if (in_list && free_area < MCDI_BUF_LEN) { + list_del_init(&target_node->free_node); + } +} + +static void update_free_list(struct ef100_vdpa_iova_node *iova_node, + struct ef100_vdpa_nic *vdpa_nic, + bool add_node) +{ + struct ef100_vdpa_iova_node *prev_in = NULL; + struct ef100_vdpa_iova_node *next_in = NULL; + struct rb_node *prev_node; + struct rb_node *next_node; + + prev_node = rb_prev(&iova_node->node); + next_node = rb_next(&iova_node->node); + + if (prev_node) + prev_in = rb_entry(prev_node, + struct ef100_vdpa_iova_node, node); + if (next_node) + next_in = rb_entry(next_node, + struct ef100_vdpa_iova_node, node); + + if (add_node) { + if (prev_in) + update_free_list_node(prev_in, iova_node, vdpa_nic); + + if (next_in) + update_free_list_node(iova_node, next_in, vdpa_nic); + } else { + if (next_in && prev_in) + update_free_list_node(prev_in, next_in, vdpa_nic); + if (!list_empty(&iova_node->free_node)) + list_del_init(&iova_node->free_node); + } +} + +int efx_ef100_insert_iova_node(struct ef100_vdpa_nic *vdpa_nic, + u64 iova, u64 size) +{ + struct ef100_vdpa_iova_node *iova_node; + struct ef100_vdpa_iova_node *new_node; + struct rb_node *parent; + struct rb_node **link; + struct rb_root *root; + int rc = 0; + + mutex_lock(&vdpa_nic->iova_lock); + + root = &vdpa_nic->iova_root; + link = &root->rb_node; + parent = *link; + /* Go to the bottom of the tree */ + while (*link) { + parent = *link; + iova_node = rb_entry(parent, struct ef100_vdpa_iova_node, node); + + /* handle duplicate node */ + if (iova_node->iova == iova) { + rc = -EEXIST; + goto out_unlock; + } + + if (iova_node->iova > iova) + link = &(*link)->rb_left; + else + link = &(*link)->rb_right; + } + + new_node = kzalloc(sizeof(*new_node), GFP_KERNEL); + if (!new_node) { + rc = -ENOMEM; + goto out_unlock; + } + + new_node->iova = iova; + new_node->size = size; + INIT_LIST_HEAD(&new_node->free_node); + + /* Put the new node here */ + rb_link_node(&new_node->node, parent, link); + rb_insert_color(&new_node->node, root); + + update_free_list(new_node, vdpa_nic, true); + +out_unlock: + mutex_unlock(&vdpa_nic->iova_lock); + return rc; +} + +static struct ef100_vdpa_iova_node* +ef100_rbt_search_node(struct ef100_vdpa_nic *vdpa_nic, + unsigned long iova) +{ + struct ef100_vdpa_iova_node *iova_node; + struct rb_node *rb_node; + struct rb_root *root; + + root = &vdpa_nic->iova_root; + if (!root) + return NULL; + + rb_node = root->rb_node; + + while (rb_node) { + iova_node = rb_entry(rb_node, struct ef100_vdpa_iova_node, + node); + if (iova_node->iova > iova) + rb_node = rb_node->rb_left; + else if (iova_node->iova < iova) + rb_node = rb_node->rb_right; + else + return iova_node; + } + + return NULL; +} + +void efx_ef100_remove_iova_node(struct ef100_vdpa_nic *vdpa_nic, + unsigned long iova) +{ + struct ef100_vdpa_iova_node *iova_node; + + mutex_lock(&vdpa_nic->iova_lock); + iova_node = ef100_rbt_search_node(vdpa_nic, iova); + if (!iova_node) + goto out_unlock; + + update_free_list(iova_node, vdpa_nic, false); + + rb_erase(&iova_node->node, &vdpa_nic->iova_root); + kfree(iova_node); + +out_unlock: + mutex_unlock(&vdpa_nic->iova_lock); +} + +void efx_ef100_delete_iova(struct ef100_vdpa_nic *vdpa_nic) +{ + struct ef100_vdpa_iova_node *iova_node; + struct rb_root *iova_root; + struct rb_node *node; + + mutex_lock(&vdpa_nic->iova_lock); + + iova_root = &vdpa_nic->iova_root; + while (!RB_EMPTY_ROOT(iova_root)) { + node = rb_first(iova_root); + iova_node = rb_entry(node, struct ef100_vdpa_iova_node, node); + if (!list_empty(&iova_node->free_node)) + list_del_init(&iova_node->free_node); + if (vdpa_nic->domain) + iommu_unmap(vdpa_nic->domain, iova_node->iova, + iova_node->size); + rb_erase(node, iova_root); + kfree(iova_node); + } + + mutex_unlock(&vdpa_nic->iova_lock); +} + +int efx_ef100_find_new_iova(struct ef100_vdpa_nic *vdpa_nic, + unsigned int buf_len, + u64 *new_iova) +{ + struct ef100_vdpa_iova_node *iova_node; + + /* pick the first node from freelist */ + iova_node = list_first_entry_or_null(&vdpa_nic->free_list, + struct ef100_vdpa_iova_node, + free_node); + if (!iova_node) + return -ENOENT; + + *new_iova = iova_node->iova + iova_node->size; + return 0; +} diff --git a/drivers/net/ethernet/sfc/ef100_iova.h b/drivers/net/ethernet/sfc/ef100_iova.h new file mode 100644 index 000000000000..68e39c4152c7 --- /dev/null +++ b/drivers/net/ethernet/sfc/ef100_iova.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Driver for Xilinx network controllers and boards + * Copyright(C) 2020-2022 Xilinx, Inc. + * Copyright(C) 2022 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_EF100_IOVA_H +#define EFX_EF100_IOVA_H + +#include "ef100_nic.h" +#include "ef100_vdpa.h" + +#if defined(CONFIG_SFC_VDPA) +/** + * struct ef100_vdpa_iova_node - guest buffer iova entry + * + * @node: red black tree node + * @iova: mapping's IO virtual address + * @size: length of mapped region in bytes + * @free_node: free list node + */ +struct ef100_vdpa_iova_node { + struct rb_node node; + unsigned long iova; + size_t size; + struct list_head free_node; +}; + +int efx_ef100_insert_iova_node(struct ef100_vdpa_nic *vdpa_nic, + u64 iova, u64 size); +void efx_ef100_remove_iova_node(struct ef100_vdpa_nic *vdpa_nic, + unsigned long iova); +void efx_ef100_delete_iova(struct ef100_vdpa_nic *vdpa_nic); +int efx_ef100_find_new_iova(struct ef100_vdpa_nic *vdpa_nic, + unsigned int buf_len, u64 *new_iova); +#endif /* CONFIG_SFC_VDPA */ +#endif /* EFX_EF100_IOVA_H */ diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c index 41811c519275..72820d2fe19d 100644 --- a/drivers/net/ethernet/sfc/ef100_nic.c +++ b/drivers/net/ethernet/sfc/ef100_nic.c @@ -33,7 +33,6 @@ #define EF100_MAX_VIS 4096 #define EF100_NUM_MCDI_BUFFERS 1 -#define MCDI_BUF_LEN (8 + MCDI_CTL_SDU_LEN_MAX) #define EF100_RESET_PORT ((ETH_RESET_MAC | ETH_RESET_PHY) << ETH_RESET_SHARED_SHIFT) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index 80bca281a748..b9368eb1acd5 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -14,6 +14,7 @@ #include #include "ef100_vdpa.h" #include "mcdi_vdpa.h" +#include "ef100_iova.h" #include "mcdi_filters.h" #include "mcdi_functions.h" #include "ef100_netdev.h" @@ -280,6 +281,34 @@ static int get_net_config(struct ef100_vdpa_nic *vdpa_nic) return 0; } +static int vdpa_update_domain(struct ef100_vdpa_nic *vdpa_nic) +{ + struct vdpa_device *vdpa = &vdpa_nic->vdpa_dev; + struct iommu_domain_geometry *geo; + struct device *dma_dev; + + dma_dev = vdpa_get_dma_dev(vdpa); + if (!device_iommu_capable(dma_dev, IOMMU_CAP_CACHE_COHERENCY)) + return -EOPNOTSUPP; + + vdpa_nic->domain = iommu_get_domain_for_dev(dma_dev); + if (!vdpa_nic->domain) + return -ENODEV; + + geo = &vdpa_nic->domain->geometry; + /* save the geo aperture range for validation in dma_map */ + vdpa_nic->geo_aper_start = geo->aperture_start; + + /* Handle the boundary case */ + if (geo->aperture_end == ~0ULL) + geo->aperture_end -= 1; + vdpa_nic->geo_aper_end = geo->aperture_end; + + /* insert a sentinel node */ + return efx_ef100_insert_iova_node(vdpa_nic, + vdpa_nic->geo_aper_end + 1, 0); +} + static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, const char *dev_name, enum ef100_vdpa_class dev_type, @@ -316,6 +345,7 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, } mutex_init(&vdpa_nic->lock); + mutex_init(&vdpa_nic->iova_lock); dev = &vdpa_nic->vdpa_dev.dev; efx->vdpa_nic = vdpa_nic; vdpa_nic->vdpa_dev.dma_dev = &efx->pci_dev->dev; @@ -325,9 +355,11 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, vdpa_nic->pf_index = nic_data->pf_index; vdpa_nic->vf_index = nic_data->vf_index; vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; + vdpa_nic->iova_root = RB_ROOT; vdpa_nic->mac_address = (u8 *)&vdpa_nic->net_config.mac; ether_addr_copy(vdpa_nic->mac_address, mac); vdpa_nic->mac_configured = true; + INIT_LIST_HEAD(&vdpa_nic->free_list); for (i = 0; i < EF100_VDPA_MAC_FILTER_NTYPES; i++) vdpa_nic->filters[i].filter_id = EFX_INVALID_FILTER_ID; @@ -353,6 +385,12 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, goto err_put_device; } + rc = vdpa_update_domain(vdpa_nic); + if (rc) { + pci_err(efx->pci_dev, "update_domain failed, err: %d\n", rc); + goto err_put_device; + } + rc = get_net_config(vdpa_nic); if (rc) goto err_put_device; diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index 1b0bbba88154..c3c77029973d 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -12,7 +12,9 @@ #define __EF100_VDPA_H__ #include +#include #include +#include #include "net_driver.h" #include "ef100_nic.h" @@ -155,6 +157,12 @@ struct ef100_vdpa_filter { * @mac_configured: true after MAC address is configured * @filters: details of all filters created on this vdpa device * @cfg_cb: callback for config change + * @domain: IOMMU domain + * @iova_root: iova rbtree root + * @iova_lock: lock to synchronize updates to rbtree and freelist + * @free_list: list to store free iova areas of size >= MCDI buffer length + * @geo_aper_start: start of valid IOVA range + * @geo_aper_end: end of valid IOVA range */ struct ef100_vdpa_nic { struct vdpa_device vdpa_dev; @@ -174,6 +182,13 @@ struct ef100_vdpa_nic { bool mac_configured; struct ef100_vdpa_filter filters[EF100_VDPA_MAC_FILTER_NTYPES]; struct vdpa_callback cfg_cb; + struct iommu_domain *domain; + struct rb_root iova_root; + /* mutex to synchronize rbtree operations */ + struct mutex iova_lock; + struct list_head free_list; + u64 geo_aper_start; + u64 geo_aper_end; }; int ef100_vdpa_init(struct efx_probe_data *probe_data); diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index 718b67f6da90..8c198d949fdb 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -10,6 +10,7 @@ #include #include "ef100_vdpa.h" +#include "ef100_iova.h" #include "io.h" #include "mcdi_vdpa.h" @@ -260,6 +261,7 @@ static void ef100_reset_vdpa_device(struct ef100_vdpa_nic *vdpa_nic) if (!vdpa_nic->status) return; + efx_ef100_delete_iova(vdpa_nic); vdpa_nic->vdpa_state = EF100_VDPA_STATE_INITIALIZED; vdpa_nic->status = 0; vdpa_nic->features = 0; @@ -743,9 +745,12 @@ static void ef100_vdpa_free(struct vdpa_device *vdev) int i; if (vdpa_nic) { + /* clean-up the mappings and iova tree */ + efx_ef100_delete_iova(vdpa_nic); for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) reset_vring(vdpa_nic, i); ef100_vdpa_irq_vectors_free(vdpa_nic->efx->pci_dev); + mutex_destroy(&vdpa_nic->iova_lock); mutex_destroy(&vdpa_nic->lock); vdpa_nic->efx->vdpa_nic = NULL; } diff --git a/drivers/net/ethernet/sfc/mcdi.h b/drivers/net/ethernet/sfc/mcdi.h index db4ca4975ada..7d977a58a0df 100644 --- a/drivers/net/ethernet/sfc/mcdi.h +++ b/drivers/net/ethernet/sfc/mcdi.h @@ -7,6 +7,7 @@ #ifndef EFX_MCDI_H #define EFX_MCDI_H +#include "mcdi_pcol.h" /** * enum efx_mcdi_state - MCDI request handling state * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the @@ -40,6 +41,8 @@ enum efx_mcdi_mode { MCDI_MODE_FAIL, }; +#define MCDI_BUF_LEN (8 + MCDI_CTL_SDU_LEN_MAX) + /** * struct efx_mcdi_iface - MCDI protocol context * @efx: The associated NIC. From patchwork Wed Dec 7 14:54:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067264 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 D2B8EC63703 for ; Wed, 7 Dec 2022 14:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229696AbiLGO6v (ORCPT ); Wed, 7 Dec 2022 09:58:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbiLGO6a (ORCPT ); Wed, 7 Dec 2022 09:58:30 -0500 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE0F6388; Wed, 7 Dec 2022 06:57:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UPOc27J6yXX0KPjtKHhur/njFqw+Ty7ADZuiXd8wvZ2gUtV8w1efmBNGQehG3LzcI1SQs+l1h8ad2AZlqVapsEtTrvERpBEzJOWTVNEyzIChEM4wPTV24s9pN/8Akxam8OfSLzcepOcAdyvivkMaw19Ik5lub76fbM+pufBgUjC5gK7SgwcBSFBhRzfoiBawtsP4af42EGSO2JuF/JmZ0afzt8byjpg3bty86ZcLOXK5WhfFR1FLxNTwVRWewC38aewb7s2ge59pkk0qZA27pId6IDMLganvKdGMELH1UJK6j9rGC6hVLZ5i5x1Vd7ojcsQGZYev7gV+xQKmo+BW8Q== 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=oeYlK7TeC5QObliScKEh48xLWbBSlHY1Z26BEvD/iKI=; b=ZXS1CSWKCYQyu+qUSjZiAS/eFZ+gTnMCpahp3P3Z7HLzv+WkaAP9fID4ysrKEL3IDkmb5sGqc7xivwZCcdQ4ZG15MIkaVzjs5S+IXGF98r1Y4QyvOS2yuqUplO2EOuEq4xPOK0bzUfoNZy7ZiqKpLOh2ihq2eUswWLdTV4gy04KffJMLr3tBmD7kaCyivHEB+UMYrKD0qSD7PhXaFdoXdqjQI22Sc7+Fki/w6kXRr3Dr1ae+paGj2rieaNKNDmFeI+4qxwWMedtX+qQ1y1Tl1nNVri1gRcYM7AHLVPuvv2FtirEcKqg7V4593BBVTrP6ErWsIQVr59HxavQMplvl4Q== 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=oeYlK7TeC5QObliScKEh48xLWbBSlHY1Z26BEvD/iKI=; b=rf/POx1TkO8tuRgYG9lgpAtJRm85W9xh0yEAaFtW8c2Xpyq2jTYhK9lVc8pm7CfrRav+KSkh0shqckgmczyzxL5QPit1tTc47oYIjH4BZVsVo11pk4+zRd4JFCZjX28nlMDKeQrAJ/AeceLkyDyIkxwa2YNSjk1wDCbvcqQfx4Y= Received: from DS7PR03CA0301.namprd03.prod.outlook.com (2603:10b6:8:2b::8) by SA1PR12MB5615.namprd12.prod.outlook.com (2603:10b6:806:229::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:57:36 +0000 Received: from DS1PEPF0000E630.namprd02.prod.outlook.com (2603:10b6:8:2b:cafe::8f) by DS7PR03CA0301.outlook.office365.com (2603:10b6:8:2b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 14:57:36 +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 DS1PEPF0000E630.mail.protection.outlook.com (10.167.17.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:57:36 +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; Wed, 7 Dec 2022 08:57:32 -0600 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:57:28 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 10/11] sfc: implement vdpa config_ops for dma operations Date: Wed, 7 Dec 2022 20:24:26 +0530 Message-ID: <20221207145428.31544-11-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E630:EE_|SA1PR12MB5615:EE_ X-MS-Office365-Filtering-Correlation-Id: fcd64626-3044-4793-ee99-08dad86360d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cMMcKSdxwIb6lh/2dohh3HZC6Apez31TxBCwxRuwletRDwBMLTkBe4N6/mcZw7ljdyH9C3ltotBGc5HNx/ne7IEH5NBBne6cQ9oAlj0qBmkRt9AntWdVIDE1X7MY9tgCSgiEUPvGDvN5rBXdcjot35mmm70oc+57V8RleQldiwSqCeZ+GHnLUXRxSc8N7gxeI1pCj/7vns6ewoCaczhxW/nlAGZQSPr2A+SzfaQ5Tz17lgY9OXhr6tKZye3z+xQs7cD7xTYl8UAPxrtJbMMLmyU9L0/XX/jAx0UbfDtxQQhkO2/crh92A/Afqp708XOpjpRmYoJSGYnvMI1lx/KXwn17qjFPKPK0YFufNyhwKAZtlfFFYj/5nGozok6uCZJWmv8vo35eaDH+Dz1qv4DTB7XStOQ9ZMYj0G+fUasLVbNrY19s+Z6TFGq2C/Z9IJNjbc5aRErBxbCl/dvj1YwBU1gS78wUlaX3XQvF438AafW5QU4J7q6exJQOAv6jNOlT1pPUAuanKZeNDoc2Y5xXUADka1npFI0jgX9uJklaBBsvTaxoHKG1kCLixekla6oNMzMT5jqQdLPItn+5Xetokm7a6aqtFG836Pc1dSLxRxrURYA+94YoJiuOlUSmP1cAhiiadWUoe4UoiYpiC04sZrCO7fby+FwCZfTXOuSxpYRlEsEfSSTTuUUZ3Fi6R3leFaQvXnI2Lrv4udyFk3sHoZvHMMiiqY1lMRCBr0MhhmA= 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:(13230022)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(5660300002)(7416002)(70206006)(66899015)(2906002)(30864003)(316002)(41300700001)(44832011)(4326008)(70586007)(8676002)(8936002)(54906003)(36756003)(478600001)(26005)(110136005)(36860700001)(186003)(82310400005)(1076003)(2616005)(336012)(83380400001)(40460700003)(40480700001)(47076005)(86362001)(426003)(82740400003)(356005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:57:36.3534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fcd64626-3044-4793-ee99-08dad86360d7 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: DS1PEPF0000E630.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5615 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Although sfc uses the platform IOMMU but it still implements the DMA config operations to deal with possible IOVA overlap with the MCDI DMA buffer and relocates the latter if such overlap is detected. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.c | 140 ++++++++++++++++++++++ drivers/net/ethernet/sfc/ef100_vdpa.h | 3 + drivers/net/ethernet/sfc/ef100_vdpa_ops.c | 111 +++++++++++++++++ drivers/net/ethernet/sfc/net_driver.h | 12 ++ 4 files changed, 266 insertions(+) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index b9368eb1acd5..16681d164fd1 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -309,6 +309,140 @@ static int vdpa_update_domain(struct ef100_vdpa_nic *vdpa_nic) vdpa_nic->geo_aper_end + 1, 0); } +static int ef100_vdpa_alloc_buffer(struct efx_nic *efx, struct efx_buffer *buf) +{ + struct ef100_vdpa_nic *vdpa_nic = efx->vdpa_nic; + struct device *dev = &vdpa_nic->vdpa_dev.dev; + int rc; + + buf->addr = kzalloc(buf->len, GFP_KERNEL); + if (!buf->addr) + return -ENOMEM; + + rc = iommu_map(vdpa_nic->domain, buf->dma_addr, + virt_to_phys(buf->addr), buf->len, + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + if (rc) + dev_err(dev, "iommu_map failed, rc: %d\n", rc); + + return rc; +} + +static void ef100_vdpa_free_buffer(struct ef100_vdpa_nic *vdpa_nic, + struct efx_buffer *buf) +{ + struct device *dev = &vdpa_nic->vdpa_dev.dev; + int rc; + + rc = iommu_unmap(vdpa_nic->domain, buf->dma_addr, buf->len); + if (rc < 0) + dev_err(dev, "iommu_unmap failed, rc: %d\n", rc); + + kfree(buf->addr); +} + +int ef100_setup_ef100_mcdi_buffer(struct ef100_vdpa_nic *vdpa_nic) +{ + struct efx_nic *efx = vdpa_nic->efx; + struct ef100_nic_data *nic_data; + struct efx_mcdi_iface *mcdi; + struct efx_buffer mcdi_buf; + enum efx_mcdi_mode mode; + struct device *dev; + int rc; + + /* Switch to poll mode MCDI mode */ + nic_data = efx->nic_data; + dev = &vdpa_nic->vdpa_dev.dev; + mcdi = efx_mcdi(efx); + mode = mcdi->mode; + efx_mcdi_mode_poll(efx); + efx_mcdi_flush_async(efx); + + /* First, allocate the MCDI buffer for EF100 mode */ + rc = efx_nic_alloc_buffer(efx, &mcdi_buf, + MCDI_BUF_LEN, GFP_KERNEL); + if (rc) { + dev_err(dev, "nic alloc buf failed, rc: %d\n", rc); + goto restore_mode; + } + + /* unmap and free the vDPA MCDI buffer now */ + ef100_vdpa_free_buffer(vdpa_nic, &nic_data->mcdi_buf); + memcpy(&nic_data->mcdi_buf, &mcdi_buf, sizeof(struct efx_buffer)); + efx->mcdi_buf_mode = EFX_BUF_MODE_EF100; + +restore_mode: + if (mode == MCDI_MODE_EVENTS) + efx_mcdi_mode_event(efx); + + return rc; +} + +int ef100_setup_vdpa_mcdi_buffer(struct efx_nic *efx, u64 mcdi_iova) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct efx_mcdi_iface *mcdi = efx_mcdi(efx); + enum efx_mcdi_mode mode = mcdi->mode; + struct efx_buffer mcdi_buf; + int rc; + + efx_mcdi_mode_poll(efx); + efx_mcdi_flush_async(efx); + + /* First, prepare the MCDI buffer for vDPA mode */ + mcdi_buf.dma_addr = mcdi_iova; + /* iommu_map requires page aligned memory */ + mcdi_buf.len = PAGE_ALIGN(MCDI_BUF_LEN); + rc = ef100_vdpa_alloc_buffer(efx, &mcdi_buf); + if (rc) { + pci_err(efx->pci_dev, "alloc vdpa buf failed, rc: %d\n", rc); + goto restore_mode; + } + + /* All set-up, free the EF100 MCDI buffer now */ + efx_nic_free_buffer(efx, &nic_data->mcdi_buf); + memcpy(&nic_data->mcdi_buf, &mcdi_buf, sizeof(struct efx_buffer)); + efx->mcdi_buf_mode = EFX_BUF_MODE_VDPA; + +restore_mode: + if (mode == MCDI_MODE_EVENTS) + efx_mcdi_mode_event(efx); + return rc; +} + +int ef100_remap_vdpa_mcdi_buffer(struct efx_nic *efx, u64 mcdi_iova) +{ + struct ef100_nic_data *nic_data = efx->nic_data; + struct ef100_vdpa_nic *vdpa_nic = efx->vdpa_nic; + struct efx_mcdi_iface *mcdi = efx_mcdi(efx); + struct efx_buffer *mcdi_buf; + int rc; + + mcdi_buf = &nic_data->mcdi_buf; + spin_lock_bh(&mcdi->iface_lock); + + rc = iommu_unmap(vdpa_nic->domain, mcdi_buf->dma_addr, mcdi_buf->len); + if (rc < 0) { + pci_err(efx->pci_dev, "iommu_unmap failed, rc: %d\n", rc); + goto out; + } + + rc = iommu_map(vdpa_nic->domain, mcdi_iova, + virt_to_phys(mcdi_buf->addr), + mcdi_buf->len, + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + if (rc) { + pci_err(efx->pci_dev, "iommu_map failed, rc: %d\n", rc); + goto out; + } + + mcdi_buf->dma_addr = mcdi_iova; +out: + spin_unlock_bh(&mcdi->iface_lock); + return rc; +} + static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, const char *dev_name, enum ef100_vdpa_class dev_type, @@ -391,6 +525,12 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, goto err_put_device; } + rc = ef100_setup_vdpa_mcdi_buffer(efx, EF100_VDPA_IOVA_BASE_ADDR); + if (rc) { + pci_err(efx->pci_dev, "realloc mcdi failed, err: %d\n", rc); + goto err_put_device; + } + rc = get_net_config(vdpa_nic); if (rc) goto err_put_device; diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.h b/drivers/net/ethernet/sfc/ef100_vdpa.h index c3c77029973d..f15d8739dcde 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.h +++ b/drivers/net/ethernet/sfc/ef100_vdpa.h @@ -202,6 +202,9 @@ int ef100_vdpa_add_filter(struct ef100_vdpa_nic *vdpa_nic, int ef100_vdpa_irq_vectors_alloc(struct pci_dev *pci_dev, u16 nvqs); void ef100_vdpa_irq_vectors_free(void *data); int ef100_vdpa_reset(struct vdpa_device *vdev); +int ef100_setup_ef100_mcdi_buffer(struct ef100_vdpa_nic *vdpa_nic); +int ef100_setup_vdpa_mcdi_buffer(struct efx_nic *efx, u64 mcdi_iova); +int ef100_remap_vdpa_mcdi_buffer(struct efx_nic *efx, u64 mcdi_iova); static inline bool efx_vdpa_is_little_endian(struct ef100_vdpa_nic *vdpa_nic) { diff --git a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c index 8c198d949fdb..7c632f179bcf 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa_ops.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa_ops.c @@ -12,6 +12,7 @@ #include "ef100_vdpa.h" #include "ef100_iova.h" #include "io.h" +#include "ef100_iova.h" #include "mcdi_vdpa.h" /* Get the queue's function-local index of the associated VI @@ -739,14 +740,121 @@ static void ef100_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, } } +static bool is_iova_overlap(u64 iova1, u64 size1, u64 iova2, u64 size2) +{ + return max(iova1, iova2) < min(iova1 + size1, iova2 + size2); +} + +static int ef100_vdpa_dma_map(struct vdpa_device *vdev, + unsigned int asid, + u64 iova, u64 size, + u64 pa, u32 perm, void *opaque) +{ + struct ef100_vdpa_nic *vdpa_nic; + struct ef100_nic_data *nic_data; + unsigned int mcdi_buf_len; + dma_addr_t mcdi_buf_addr; + u64 mcdi_iova = 0; + int rc; + + vdpa_nic = get_vdpa_nic(vdev); + nic_data = vdpa_nic->efx->nic_data; + mcdi_buf_addr = nic_data->mcdi_buf.dma_addr; + mcdi_buf_len = nic_data->mcdi_buf.len; + + /* Validate the iova range against geo aperture */ + if (iova < vdpa_nic->geo_aper_start || + ((iova + size - 1) > vdpa_nic->geo_aper_end)) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: iova range (%llx, %llx) not within geo aperture\n", + __func__, iova, (iova + size)); + return -EINVAL; + } + + rc = efx_ef100_insert_iova_node(vdpa_nic, iova, size); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "%s: iova_node insert failure: %d\n", __func__, rc); + return rc; + } + + if (is_iova_overlap(mcdi_buf_addr, mcdi_buf_len, iova, size)) { + dev_info(&vdpa_nic->vdpa_dev.dev, + "%s: mcdi iova overlap detected: %llx\n", + __func__, mcdi_buf_addr); + /* find the new iova for mcdi buffer */ + rc = efx_ef100_find_new_iova(vdpa_nic, mcdi_buf_len, + &mcdi_iova); + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "new mcdi iova not found, err: %d\n", rc); + goto fail; + } + + if (vdpa_nic->efx->mcdi_buf_mode == EFX_BUF_MODE_VDPA) + rc = ef100_remap_vdpa_mcdi_buffer(vdpa_nic->efx, + mcdi_iova); + else if (vdpa_nic->efx->mcdi_buf_mode == EFX_BUF_MODE_EF100) + rc = ef100_setup_vdpa_mcdi_buffer(vdpa_nic->efx, + mcdi_iova); + else + goto fail; + + if (rc) { + dev_err(&vdpa_nic->vdpa_dev.dev, + "mcdi buf update failed, err: %d\n", rc); + goto fail; + } + } + + rc = iommu_map(vdpa_nic->domain, iova, pa, size, perm); + if (rc) { + dev_err(&vdev->dev, + "%s: iommu_map iova: %llx size: %llx rc: %d\n", + __func__, iova, size, rc); + goto fail; + } + + return 0; + +fail: + efx_ef100_remove_iova_node(vdpa_nic, iova); + return rc; +} + +static int ef100_vdpa_dma_unmap(struct vdpa_device *vdev, + unsigned int asid, + u64 iova, u64 size) +{ + struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + int rc; + + rc = iommu_unmap(vdpa_nic->domain, iova, size); + if (rc < 0) + dev_info(&vdev->dev, + "%s: iommu_unmap iova: %llx size: %llx rc: %d\n", + __func__, iova, size, rc); + efx_ef100_remove_iova_node(vdpa_nic, iova); + return rc; +} + static void ef100_vdpa_free(struct vdpa_device *vdev) { struct ef100_vdpa_nic *vdpa_nic = get_vdpa_nic(vdev); + int rc; int i; if (vdpa_nic) { /* clean-up the mappings and iova tree */ efx_ef100_delete_iova(vdpa_nic); + if (vdpa_nic->efx->mcdi_buf_mode == EFX_BUF_MODE_VDPA) { + rc = ef100_setup_ef100_mcdi_buffer(vdpa_nic); + if (rc) { + dev_err(&vdev->dev, + "setup_ef100_mcdi failed, err: %d\n", + rc); + } + } for (i = 0; i < (vdpa_nic->max_queue_pairs * 2); i++) reset_vring(vdpa_nic, i); ef100_vdpa_irq_vectors_free(vdpa_nic->efx->pci_dev); @@ -782,5 +890,8 @@ const struct vdpa_config_ops ef100_vdpa_config_ops = { .get_config = ef100_vdpa_get_config, .set_config = ef100_vdpa_set_config, .get_generation = NULL, + .set_map = NULL, + .dma_map = ef100_vdpa_dma_map, + .dma_unmap = ef100_vdpa_dma_unmap, .free = ef100_vdpa_free, }; diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 79356d614109..34b94372d9a6 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -846,6 +846,16 @@ enum efx_xdp_tx_queues_mode { EFX_XDP_TX_QUEUES_BORROWED /* queues borrowed from net stack */ }; +/** + * enum efx_buf_alloc_mode - buffer allocation mode + * @EFX_BUF_MODE_EF100: buffer setup in ef100 mode + * @EFX_BUF_MODE_VDPA: buffer setup in vdpa mode + */ +enum efx_buf_alloc_mode { + EFX_BUF_MODE_EF100, + EFX_BUF_MODE_VDPA +}; + /** * struct efx_nic - an Efx NIC * @name: Device name (net device name or bus id before net device registered) @@ -997,6 +1007,7 @@ enum efx_xdp_tx_queues_mode { * @tc: state for TC offload (EF100). * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. + * @mcdi_buf_mode: mcdi buffer allocation mode * @monitor_work: Hardware monitor workitem * @biu_lock: BIU (bus interface unit) lock * @last_irq_cpu: Last CPU to handle a possible test interrupt. This @@ -1182,6 +1193,7 @@ struct efx_nic { unsigned int mem_bar; u32 reg_base; + enum efx_buf_alloc_mode mcdi_buf_mode; #ifdef CONFIG_SFC_VDPA /** @mgmt_dev: vDPA Management device */ struct vdpa_mgmt_dev *mgmt_dev; From patchwork Wed Dec 7 14:54:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gautam Dawar X-Patchwork-Id: 13067265 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 D705CC4708E for ; Wed, 7 Dec 2022 14:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229966AbiLGO7z (ORCPT ); Wed, 7 Dec 2022 09:59:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbiLGO71 (ORCPT ); Wed, 7 Dec 2022 09:59:27 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2049.outbound.protection.outlook.com [40.107.243.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA80663D4B; Wed, 7 Dec 2022 06:58:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cywa3rnC72bqiIKk6I7eNN63JGtVp1Tqhd3H3Xkvsu9zN7fzrfbILhUAxOJoZJn8xBGPZLyFyhZOy+1KMTFCLc5+aRq07xNh9bqH/KfCz5Ay3+EbWoUtkRYrblpYgPKDYV0WtS1hddhlI5IAgFyk746x9SWfpYs6OlXp0kSXfNNJm3aVAvzNOx8sDswMvJQm0I25GYKL7N/Z/97LBhQEgWtQmTNPXEY5VqI19rL9Xt0YGIC4Dy26RQwT51M2H0faJT1Z2jUPfUtPVF3pYZIyVompixDKoVYlt4Uu/LRPMyahElr77a/1ESJijfK0js4VvK8C8uhJ8SURr93D4y2OSA== 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=SzCuX+xn1dKb3qq+JB4DsNggC/4+ve8vrZcXeVlMIf0=; b=ninqB8RAlSKPvOIKdMf5/Ok8u94kuJQOygLLqnHV9Ox/yRqvG8Io6wqB/7g4Sim0CnAzdip7+kM0pEG1SVCfBjGSlMiTs/4Y0kf+4XHNSi45yiVVChafcS9Yej9ghVQVopCkRaJ/L0SS2HGcaWfPwT0myBxlg7fH3yN4CAb8ve1fuqA+3wPGcbs/As1LmOH1/SH3XFhyIkFr15lOYhO6YYLTHQxDQV906WNhGwJZx/RP2KBAMZS8iAGZVMBwIEXKTUMhnNi0Cr1ENhPiyV0F4bV44ZXgowuYK4/B5djUq5ZxfW7ty6k4fS4LoRRk+Jj2JVuBGxdlnn7y5Xtoet9iRw== 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=SzCuX+xn1dKb3qq+JB4DsNggC/4+ve8vrZcXeVlMIf0=; b=Qk5Fa+TpbjKSlRYqX/FB3LCe9CbzUs2fFt67GW4vRRANT2umLm76fcJI4ehPdOSPPJktg84VpvuhZk45ddnX/aGCTESt98m00VlddweUnVj8zzKASYrZkuHbn2Xmnck3AQmfmrF1hApJhWDCc60SO76mWd9D5xj/6vJeWm6dJPI= Received: from DS7PR05CA0025.namprd05.prod.outlook.com (2603:10b6:5:3b9::30) by SJ1PR12MB6172.namprd12.prod.outlook.com (2603:10b6:a03:459::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 14:58:09 +0000 Received: from DS1PEPF0000E633.namprd02.prod.outlook.com (2603:10b6:5:3b9:cafe::e5) by DS7PR05CA0025.outlook.office365.com (2603:10b6:5:3b9::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5901.8 via Frontend Transport; Wed, 7 Dec 2022 14:58:09 +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 DS1PEPF0000E633.mail.protection.outlook.com (10.167.17.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 14:58:08 +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; Wed, 7 Dec 2022 08:57:37 -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; Wed, 7 Dec 2022 06:57:37 -0800 Received: from xndengvm004102.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 7 Dec 2022 08:57:33 -0600 From: Gautam Dawar To: , , , CC: , , , Gautam Dawar , Edward Cree , Martin Habets , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Subject: [PATCH net-next 11/11] sfc: register the vDPA device Date: Wed, 7 Dec 2022 20:24:27 +0530 Message-ID: <20221207145428.31544-12-gautam.dawar@amd.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20221207145428.31544-1-gautam.dawar@amd.com> References: <20221207145428.31544-1-gautam.dawar@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E633:EE_|SJ1PR12MB6172:EE_ X-MS-Office365-Filtering-Correlation-Id: b0190eef-2b85-4897-210b-08dad8637446 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dZJTS/XoVEsFtXqh13KYgs0nMSoDLlCHPbD7Gr9jKw6q3H1Dr1c8OvgdDRG9x2h25LD2+PqPPnBmV4Z+uRw4QAuHFZM7bOaaCvhf2psW3jpHoW0EhUcmNMG7ei+V4YrNY75sROR36LSSw0DMFrDU4OIzCNVM3FK9+ZAVdzBEVwG1/nue4f+QKh6pnmyPkqQQMGBozAwPa08OgflX4SKGSTW/1Lj2ghf7pqJm29hevBejMi7KY2DscseFPGAyexy6WsUxd/Oh9RrmkJXZFnZgXQ9U7juJG6K1/vydU+N4eUTJkmu+Fleli2h3Ii9zjnbojdWkAP1aCjNesmJBiS0wyG3+kE5k/OjVpLtOOr+3dgDGz8feZGLV8iOcdFoX64qcUdCbUJFEuJbQZD4C5d1XrJMBYRnen9x288n/QNQBef6ov61PYJHsxNGwq/8IDHDtBDvb4bR6JTuJmFm0DdFCEecZh+Qw6zkLW5WwBajpwvjf04B6G2qigYHmyLiUCmhItqbrUzfpdcqGNldHqslaEdhkLg+GzylLV/wca7wOQMBuWsqL0O0tVXnu5Vc/inb9o0RLTqTQiAiXxytFyGIpKS53SosAfePKcb0b5yoGgB9cIJyphVkxgJ3zMq0avXOCJf3bBNonfZ0EvCv0skhy178h7Spxk00QWPHpuP/Ksifeie2FEvhM8xt/23jOPor4vw4CZnrzVUTAl9WkqB9B2XUyXE8+8CL7tXgMAZ1JdLo= 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:(13230022)(4636009)(346002)(376002)(396003)(136003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(47076005)(426003)(478600001)(40460700003)(82740400003)(81166007)(36756003)(40480700001)(86362001)(83380400001)(36860700001)(336012)(26005)(2616005)(1076003)(356005)(186003)(41300700001)(7416002)(8936002)(82310400005)(44832011)(6666004)(5660300002)(316002)(70206006)(8676002)(54906003)(70586007)(4326008)(110136005)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 14:58:08.9680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0190eef-2b85-4897-210b-08dad8637446 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: DS1PEPF0000E633.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6172 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Register the vDPA device which results in adding the device to the vDPA bus which will be probed by either of the vDPA bus drivers: virtio_vdpa or vhost_vdpa. Signed-off-by: Gautam Dawar --- drivers/net/ethernet/sfc/ef100_vdpa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef100_vdpa.c b/drivers/net/ethernet/sfc/ef100_vdpa.c index 16681d164fd1..ed59974c9633 100644 --- a/drivers/net/ethernet/sfc/ef100_vdpa.c +++ b/drivers/net/ethernet/sfc/ef100_vdpa.c @@ -231,9 +231,7 @@ static void ef100_vdpa_delete(struct efx_nic *efx) if (efx->vdpa_nic) { vdpa_dev = &efx->vdpa_nic->vdpa_dev; ef100_vdpa_reset(vdpa_dev); - - /* replace with _vdpa_unregister_device later */ - put_device(&vdpa_dev->dev); + _vdpa_unregister_device(&efx->vdpa_nic->vdpa_dev); efx->vdpa_nic = NULL; } efx_mcdi_free_vis(efx); @@ -535,7 +533,14 @@ static struct ef100_vdpa_nic *ef100_vdpa_create(struct efx_nic *efx, if (rc) goto err_put_device; - /* _vdpa_register_device when its ready */ + rc = _vdpa_register_device(&vdpa_nic->vdpa_dev, + (allocated_vis - 1) * 2); + if (rc) { + pci_err(efx->pci_dev, + "vDPA device registration failed, vf: %u, rc: %d\n", + nic_data->vf_index, rc); + goto err_put_device; + } return vdpa_nic;