From patchwork Sat Sep 7 08:18:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795134 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBC1712E5B; Sat, 7 Sep 2024 08:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697167; cv=fail; b=kodMGZJ3qwIcL1DtbyXCJn4YPwI7uYlFD+rydoZJcRFqGxOdx49xVnZzGWdfIndW46wsqX+pRZT+XB855OqBucls9ZgdjdzAxclVbVRw0B0PRuzzkho+jEsQXvsgWEThE9DUwdnZiJKP6OqtZAWQ3kSdmTqtzh82+HDyFLATiQA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697167; c=relaxed/simple; bh=jbQhunVL7odg8AabHxc+yU6LGMZ6hJp1LfOK0r/tMsQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oA1B//Ek5Q+IEfjQrOCubU9DNRsZJP0AkL2LSDvbtlX4TFo6mu+3VjpffrHFHvQwLRuSRDZnR9Cj2FzXdJME9LVPrfaB9+SHmVfZKP97QAAYMwEaSZHPyysIJGXwijW3PHBjX0iaUC9iqIwc1zLUVCbRyPpBrduqZP7/wzkFLNY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=IgNYnSgw; arc=fail smtp.client-ip=40.107.92.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="IgNYnSgw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=T6iPmOxfiZO69MzXjf9gNilXQnW1U1/JKGIMvQSOTp5INnb0z1BISATGF/QtAX7DnlyJ/QVssNaWHUCxVVwB1xVp6X3GpbVN+Y7fRl9nQgyomKelzvHFUqcVtepnMMpRjUPtREh7j+ff/c8vLn+6Byf8dKkfDdHP4bLWy+capjEpDd0jJLM/3DDkuw4FlchcBehgT78S9Yf++6QAwRIdyZqOlVLlvCxLqqda+hNM7OYKc5SG+VWTjVsAf6PbMq69pND6W2FgEjZApSFFlFWA7x3honN+3o0AjapXZ7TdfkrMvJL/gnth24AK8gqXnZo0UJTp5c4ae8Lv+27L5gZsuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=abaUXHyq1h64r/cdcONIRSTYLX8igp5kmIILyS97b0I=; b=AL2loyOvYBJYKxkTOqBkDeKMh9H6lSOGFqaz6SVnSmyxzItp9XVNmowcUK7funJMH1PMUe41yxm9qI200hmotVrRAbMAogmYyDCz+c8+JxjsYiGLUrNOmv5K6FP8TWwzzXJcYDmiOL9zAQkbHbKA3we1RUg5r0tkFIx0DcWc13J4BXtQRbyFpqjqbdYYWoVdCLRvraS+UO29ruXR1ld3bz7GQ1XtvzlORnfySYWEJEjyqqjiYn7RYNZVYUY9rU9DonQWcRrbA+b3/bRrwcj2bmgRr1WGvX/7tQ4c7cvyB5kChycC+mWz7cta5jcWAm4cYv0bW0bZj9yxHBdTrxXJMA== 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 (0) 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=abaUXHyq1h64r/cdcONIRSTYLX8igp5kmIILyS97b0I=; b=IgNYnSgwxX+Kg95bbuCfaQL/puKGQy+hEuUDGnLVA8Ijnt4elCjaPSsUvOknOc0TAvGtlE0Pg/PKqHvu1/gI8lFwC9a6qI2NqZfY29S0sZpQBFmzEIDjETqjCu/0RWq4abFEMaCnqLZiWgZITHPsQ4N34AQa88Yz+0b+xVWIR5o= Received: from DM6PR04CA0024.namprd04.prod.outlook.com (2603:10b6:5:334::29) by IA0PR12MB8864.namprd12.prod.outlook.com (2603:10b6:208:485::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Sat, 7 Sep 2024 08:19:20 +0000 Received: from DS1PEPF0001709C.namprd05.prod.outlook.com (2603:10b6:5:334:cafe::4d) by DM6PR04CA0024.outlook.office365.com (2603:10b6:5:334::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Sat, 7 Sep 2024 08:19:20 +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 DS1PEPF0001709C.mail.protection.outlook.com (10.167.18.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:20 +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.2507.39; Sat, 7 Sep 2024 03:19:19 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:19 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:18 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 01/20] cxl: add type2 device basic support Date: Sat, 7 Sep 2024 09:18:17 +0100 Message-ID: <20240907081836.5801-2-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709C:EE_|IA0PR12MB8864:EE_ X-MS-Office365-Filtering-Correlation-Id: befc506e-5065-404d-ffbc-08dccf15c5ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: suJ9Ir30o5qkV2RUoBcZm6t71PSyHSj8PSU4LIHJ6ogPSA6NR8+eCB/gkhI6DqIXfkeQb66nLdPdk7zGvgmHX9KcfKKBBOePmE6+KA2rFOPA0lws8jqHiYIg02ohQwFono49pb5kjo7dZ1aTwgO8I5JPYgpSJ5h8qGNqfXVFCqfzRfMn62ePR6V4I/kKbKSbxtQUnNcBBTizmiPP2FPvC1xAvrHMD16VV/+wGuRPNlYGXygZyKPgKmhawJD/l31TYDGVKJ9N3Cb3+CmToPWqRqps7/CrcnpvIitRGul6nXUVom2DDA8BaD0AVewRuHh5/Zu3q/9nGGqQgSC+WTeFCtK6hFoeIYDN+N+k0nP4CzwvfOd/My1roY4ReVZlKuRDbCTdurgSCSOGvqXOLnzkjGs7Hdk27TbZ/0n5lqbPPlHGV1aFEiz3S/7Emi+3xT/zsr8T6UGCmZATbM9b4D/T3zww4D0U7gbQeTPBY3+61ZFth4EGkQpZgjXcHyLEgA9FfszMckPbDVrHaw7xwNaOlx/Wfb6zwKWUD556ErIoSmZhPAEorGXnyvs1Vl6mHV9Ohc9UdHoZV3bC3nHGHhJUEfPoa3DZCWhncoLxavuMuePNhAePMKYAxtpeFDjEQmHpDry2TJkU29MI9CQ5KO6/n68YSjS6uT3x1PJrr12AXYb3aoflPFZygoGHMQ2d6tzduZkJhof3SrTfXr/+LdYVV4EvTh9CpXbfUTJBItb7AqueYZkyMnJYxMIuBmissixoB4mLJZOgEMBfvLMlTR10C24RBAMZZ1qmkTZWzEKJ17DQqe9LtgKizCIj3HhoOMpC1vnlG/8bWtdv+P39ommQiwP0MGFGLriR/CKiNWTU6vxUtl8XZ1YEaEns8yBw5uybW9EYJt9rGKRxJuwAfiaKIke0Or0+9TMHqght0KOU4/iIdXx/glGK5STKbHfWrQA6YIucSdok+YrI0BGkIxv/Nelhrv2Cz/u8jJmoahTWwcwAio/cxgehOWMf9s06qYj1tF0pBI4no1Si1HoJGHL/tek8gWb8U0hGY5BPAeYm4H/ZfBug03wUQKhlAwsYaPoYdgfPjxzLbc3QHiTsb+DMjeYCtASSKwBszF+VnVWY5Ot0AuiwryzqUb4HFVSYLCVx2Mte5AIrZCCIcWQ9dEXTuW4PJ4uIcez6nz42+cK08Pd4rFT1icC0ABIxNItSLue6pzqixBPtIfGN+LGD18ofon8HP4diNHA65idlzuTuW0DRDN5BWxX71IRvSwszSTDQFP8GVUvFYAQQngolSVB97j/tlaH1Opb6GFQspQNnlhwvrJVkZ1CH6IR1Gub4yhvgYCxsH3GQEjVQ9OBv58rYGSOkDbex/FfCUS+9NxteSvUaX+dQxT+iGttRkrr6ieHOJ7o31SWfw2+ZG02dw9G/lNrzX4xUI68ercAc3Q5pB/zoaVxI4zflckEGb4RspYXH 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:(13230040)(36860700013)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:20.0711 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: befc506e-5065-404d-ffbc-08dccf15c5ee 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: DS1PEPF0001709C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8864 From: Alejandro Lucero Differientiate Type3, aka memory expanders, from Type2, aka device accelerators, with a new function for initializing cxl_dev_state. Create accessors to cxl_dev_state to be used by accel drivers. Add SFC ethernet network driver as the client. Based on https://lore.kernel.org/linux-cxl/168592160379.1948938.12863272903570476312.stgit@dwillia2-xfh.jf.intel.com/ Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/memdev.c | 52 ++++++++++++++++ drivers/cxl/core/pci.c | 1 + drivers/cxl/cxlpci.h | 16 ----- drivers/cxl/pci.c | 13 ++-- drivers/net/ethernet/sfc/Makefile | 2 +- drivers/net/ethernet/sfc/efx.c | 13 ++++ drivers/net/ethernet/sfc/efx_cxl.c | 86 +++++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.h | 29 +++++++++ drivers/net/ethernet/sfc/net_driver.h | 6 ++ include/linux/cxl/cxl.h | 21 +++++++ include/linux/cxl/pci.h | 23 +++++++ 11 files changed, 241 insertions(+), 21 deletions(-) create mode 100644 drivers/net/ethernet/sfc/efx_cxl.c create mode 100644 drivers/net/ethernet/sfc/efx_cxl.h create mode 100644 include/linux/cxl/cxl.h create mode 100644 include/linux/cxl/pci.h diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 0277726afd04..10c0a6990f9a 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2020 Intel Corporation. */ +#include #include #include #include @@ -615,6 +616,25 @@ static void detach_memdev(struct work_struct *work) static struct lock_class_key cxl_memdev_key; +struct cxl_dev_state *cxl_accel_state_create(struct device *dev) +{ + struct cxl_dev_state *cxlds; + + cxlds = kzalloc(sizeof(*cxlds), GFP_KERNEL); + if (!cxlds) + return ERR_PTR(-ENOMEM); + + cxlds->dev = dev; + cxlds->type = CXL_DEVTYPE_DEVMEM; + + cxlds->dpa_res = DEFINE_RES_MEM_NAMED(0, 0, "dpa"); + cxlds->ram_res = DEFINE_RES_MEM_NAMED(0, 0, "ram"); + cxlds->pmem_res = DEFINE_RES_MEM_NAMED(0, 0, "pmem"); + + return cxlds; +} +EXPORT_SYMBOL_NS_GPL(cxl_accel_state_create, CXL); + static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds, const struct file_operations *fops) { @@ -692,6 +712,38 @@ static int cxl_memdev_open(struct inode *inode, struct file *file) return 0; } +void cxl_set_dvsec(struct cxl_dev_state *cxlds, u16 dvsec) +{ + cxlds->cxl_dvsec = dvsec; +} +EXPORT_SYMBOL_NS_GPL(cxl_set_dvsec, CXL); + +void cxl_set_serial(struct cxl_dev_state *cxlds, u64 serial) +{ + cxlds->serial = serial; +} +EXPORT_SYMBOL_NS_GPL(cxl_set_serial, CXL); + +int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, + enum cxl_resource type) +{ + switch (type) { + case CXL_ACCEL_RES_DPA: + cxlds->dpa_res = res; + return 0; + case CXL_ACCEL_RES_RAM: + cxlds->ram_res = res; + return 0; + case CXL_ACCEL_RES_PMEM: + cxlds->pmem_res = res; + return 0; + default: + dev_err(cxlds->dev, "unknown resource type (%u)\n", type); + return -EINVAL; + } +} +EXPORT_SYMBOL_NS_GPL(cxl_set_resource, CXL); + static int cxl_memdev_release_file(struct inode *inode, struct file *file) { struct cxl_memdev *cxlmd = diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 51132a575b27..3d6564dbda57 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 4da07727ab9c..eb59019fe5f3 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -14,22 +14,6 @@ */ #define PCI_DVSEC_HEADER1_LENGTH_MASK GENMASK(31, 20) -/* CXL 2.0 8.1.3: PCIe DVSEC for CXL Device */ -#define CXL_DVSEC_PCIE_DEVICE 0 -#define CXL_DVSEC_CAP_OFFSET 0xA -#define CXL_DVSEC_MEM_CAPABLE BIT(2) -#define CXL_DVSEC_HDM_COUNT_MASK GENMASK(5, 4) -#define CXL_DVSEC_CTRL_OFFSET 0xC -#define CXL_DVSEC_MEM_ENABLE BIT(2) -#define CXL_DVSEC_RANGE_SIZE_HIGH(i) (0x18 + (i * 0x10)) -#define CXL_DVSEC_RANGE_SIZE_LOW(i) (0x1C + (i * 0x10)) -#define CXL_DVSEC_MEM_INFO_VALID BIT(0) -#define CXL_DVSEC_MEM_ACTIVE BIT(1) -#define CXL_DVSEC_MEM_SIZE_LOW_MASK GENMASK(31, 28) -#define CXL_DVSEC_RANGE_BASE_HIGH(i) (0x20 + (i * 0x10)) -#define CXL_DVSEC_RANGE_BASE_LOW(i) (0x24 + (i * 0x10)) -#define CXL_DVSEC_MEM_BASE_LOW_MASK GENMASK(31, 28) - #define CXL_DVSEC_RANGE_MAX 2 /* CXL 2.0 8.1.4: Non-CXL Function Map DVSEC */ diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 4be35dc22202..742a7b2a1be5 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include "cxlmem.h" #include "cxlpci.h" #include "cxl.h" @@ -795,6 +797,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct cxl_memdev *cxlmd; int i, rc, pmu_count; bool irq_avail; + u16 dvsec; /* * Double check the anonymous union trickery in struct cxl_regs @@ -815,12 +818,14 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) pci_set_drvdata(pdev, cxlds); cxlds->rcd = is_cxl_restricted(pdev); - cxlds->serial = pci_get_dsn(pdev); - cxlds->cxl_dvsec = pci_find_dvsec_capability( - pdev, PCI_VENDOR_ID_CXL, CXL_DVSEC_PCIE_DEVICE); - if (!cxlds->cxl_dvsec) + cxl_set_serial(cxlds, pci_get_dsn(pdev)); + dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL, + CXL_DVSEC_PCIE_DEVICE); + if (!dvsec) dev_warn(&pdev->dev, "Device DVSEC not present, skip CXL.mem init\n"); + else + cxl_set_dvsec(cxlds, dvsec); rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map); if (rc) diff --git a/drivers/net/ethernet/sfc/Makefile b/drivers/net/ethernet/sfc/Makefile index 8f446b9bd5ee..e80c713c3b0c 100644 --- a/drivers/net/ethernet/sfc/Makefile +++ b/drivers/net/ethernet/sfc/Makefile @@ -7,7 +7,7 @@ sfc-y += efx.o efx_common.o efx_channels.o nic.o \ mcdi_functions.o mcdi_filters.o mcdi_mon.o \ ef100.o ef100_nic.o ef100_netdev.o \ ef100_ethtool.o ef100_rx.o ef100_tx.o \ - efx_devlink.o + efx_devlink.o efx_cxl.o sfc-$(CONFIG_SFC_MTD) += mtd.o sfc-$(CONFIG_SFC_SRIOV) += sriov.o ef10_sriov.o ef100_sriov.o ef100_rep.o \ mae.o tc.o tc_bindings.o tc_counters.o \ diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index 6f1a01ded7d4..3a7406aa950c 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -33,6 +33,7 @@ #include "selftest.h" #include "sriov.h" #include "efx_devlink.h" +#include "efx_cxl.h" #include "mcdi_port_common.h" #include "mcdi_pcol.h" @@ -899,6 +900,9 @@ static void efx_pci_remove(struct pci_dev *pci_dev) efx_pci_remove_main(efx); efx_fini_io(efx); + + efx_cxl_exit(efx); + pci_dbg(efx->pci_dev, "shutdown successful\n"); efx_fini_devlink_and_unlock(efx); @@ -1109,6 +1113,15 @@ static int efx_pci_probe(struct pci_dev *pci_dev, if (rc) goto fail2; + /* A successful cxl initialization implies a CXL region created to be + * used for PIO buffers. If there is no CXL support, or initialization + * fails, efx_cxl_pio_initialised wll be false and legacy PIO buffers + * defined at specific PCI BAR regions will be used. + */ + rc = efx_cxl_init(efx); + if (rc) + pci_err(pci_dev, "CXL initialization failed with error %d\n", rc); + rc = efx_pci_probe_post_io(efx); if (rc) { /* On failure, retry once immediately. diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c new file mode 100644 index 000000000000..bba36cbbab22 --- /dev/null +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-only +/**************************************************************************** + * + * Driver for AMD network controllers and boards + * Copyright (C) 2024, 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 "net_driver.h" +#include "efx_cxl.h" + +#define EFX_CTPIO_BUFFER_SIZE (1024 * 1024 * 256) + +int efx_cxl_init(struct efx_nic *efx) +{ + struct pci_dev *pci_dev = efx->pci_dev; + struct efx_cxl *cxl; + struct resource res; + u16 dvsec; + int rc; + + efx->efx_cxl_pio_initialised = false; + + dvsec = pci_find_dvsec_capability(pci_dev, PCI_VENDOR_ID_CXL, + CXL_DVSEC_PCIE_DEVICE); + + if (!dvsec) + return 0; + + pci_dbg(pci_dev, "CXL_DVSEC_PCIE_DEVICE capability found\n"); + + efx->cxl = kzalloc(sizeof(*cxl), GFP_KERNEL); + if (!efx->cxl) + return -ENOMEM; + + cxl = efx->cxl; + + cxl->cxlds = cxl_accel_state_create(&pci_dev->dev); + if (IS_ERR(cxl->cxlds)) { + pci_err(pci_dev, "CXL accel device state failed"); + kfree(efx->cxl); + return -ENOMEM; + } + + cxl_set_dvsec(cxl->cxlds, dvsec); + cxl_set_serial(cxl->cxlds, pci_dev->dev.id); + + res = DEFINE_RES_MEM(0, EFX_CTPIO_BUFFER_SIZE); + if (cxl_set_resource(cxl->cxlds, res, CXL_ACCEL_RES_DPA)) { + pci_err(pci_dev, "cxl_set_resource DPA failed\n"); + rc = -EINVAL; + goto err; + } + + res = DEFINE_RES_MEM_NAMED(0, EFX_CTPIO_BUFFER_SIZE, "ram"); + if (cxl_set_resource(cxl->cxlds, res, CXL_ACCEL_RES_RAM)) { + pci_err(pci_dev, "cxl_set_resource RAM failed\n"); + rc = -EINVAL; + goto err; + } + + return 0; +err: + kfree(cxl->cxlds); + kfree(cxl); + efx->cxl = NULL; + + return rc; +} + +void efx_cxl_exit(struct efx_nic *efx) +{ + if (efx->cxl) { + kfree(efx->cxl->cxlds); + kfree(efx->cxl); + } +} + +MODULE_IMPORT_NS(CXL); diff --git a/drivers/net/ethernet/sfc/efx_cxl.h b/drivers/net/ethernet/sfc/efx_cxl.h new file mode 100644 index 000000000000..f57fb2afd124 --- /dev/null +++ b/drivers/net/ethernet/sfc/efx_cxl.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/**************************************************************************** + * Driver for AMD network controllers and boards + * Copyright (C) 2024, 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_CXL_H +#define EFX_CXL_H + +struct efx_nic; +struct cxl_dev_state; + +struct efx_cxl { + struct cxl_dev_state *cxlds; + struct cxl_memdev *cxlmd; + struct cxl_root_decoder *cxlrd; + struct cxl_port *endpoint; + struct cxl_endpoint_decoder *cxled; + struct cxl_region *efx_region; + void __iomem *ctpio_cxl; +}; + +int efx_cxl_init(struct efx_nic *efx); +void efx_cxl_exit(struct efx_nic *efx); +#endif diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index b85c51cbe7f9..77261de65e63 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -817,6 +817,8 @@ enum efx_xdp_tx_queues_mode { struct efx_mae; +struct efx_cxl; + /** * struct efx_nic - an Efx NIC * @name: Device name (net device name or bus id before net device registered) @@ -963,6 +965,8 @@ struct efx_mae; * @tc: state for TC offload (EF100). * @devlink: reference to devlink structure owned by this device * @dl_port: devlink port associated with the PF + * @cxl: details of related cxl objects + * @efx_cxl_pio_initialised: clx initialization outcome. * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. * @monitor_work: Hardware monitor workitem @@ -1148,6 +1152,8 @@ struct efx_nic { struct devlink *devlink; struct devlink_port *dl_port; + struct efx_cxl *cxl; + bool efx_cxl_pio_initialised; unsigned int mem_bar; u32 reg_base; diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h new file mode 100644 index 000000000000..e78eefa82123 --- /dev/null +++ b/include/linux/cxl/cxl.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2024 Advanced Micro Devices, Inc. */ + +#ifndef __CXL_H +#define __CXL_H + +#include + +enum cxl_resource { + CXL_ACCEL_RES_DPA, + CXL_ACCEL_RES_RAM, + CXL_ACCEL_RES_PMEM, +}; + +struct cxl_dev_state *cxl_accel_state_create(struct device *dev); + +void cxl_set_dvsec(struct cxl_dev_state *cxlds, u16 dvsec); +void cxl_set_serial(struct cxl_dev_state *cxlds, u64 serial); +int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, + enum cxl_resource); +#endif diff --git a/include/linux/cxl/pci.h b/include/linux/cxl/pci.h new file mode 100644 index 000000000000..c337ae8797e6 --- /dev/null +++ b/include/linux/cxl/pci.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2024 Advanced Micro Devices, Inc. */ + +#ifndef __CXL_ACCEL_PCI_H +#define __CXL_ACCEL_PCI_H + +/* CXL 2.0 8.1.3: PCIe DVSEC for CXL Device */ +#define CXL_DVSEC_PCIE_DEVICE 0 +#define CXL_DVSEC_CAP_OFFSET 0xA +#define CXL_DVSEC_MEM_CAPABLE BIT(2) +#define CXL_DVSEC_HDM_COUNT_MASK GENMASK(5, 4) +#define CXL_DVSEC_CTRL_OFFSET 0xC +#define CXL_DVSEC_MEM_ENABLE BIT(2) +#define CXL_DVSEC_RANGE_SIZE_HIGH(i) (0x18 + (i * 0x10)) +#define CXL_DVSEC_RANGE_SIZE_LOW(i) (0x1C + (i * 0x10)) +#define CXL_DVSEC_MEM_INFO_VALID BIT(0) +#define CXL_DVSEC_MEM_ACTIVE BIT(1) +#define CXL_DVSEC_MEM_SIZE_LOW_MASK GENMASK(31, 28) +#define CXL_DVSEC_RANGE_BASE_HIGH(i) (0x20 + (i * 0x10)) +#define CXL_DVSEC_RANGE_BASE_LOW(i) (0x24 + (i * 0x10)) +#define CXL_DVSEC_MEM_BASE_LOW_MASK GENMASK(31, 28) + +#endif From patchwork Sat Sep 7 08:18:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795136 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2071.outbound.protection.outlook.com [40.107.236.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DBAA14D2A3; Sat, 7 Sep 2024 08:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697172; cv=fail; b=PyvADm6u30b7gAXc1dGuLTtJ60HQhmmnP4RqsB15ikCc0pFzNxRWQ9LN7hJK9pFGkDy5Lvvk68R8GQudI1xZR6bNsRZRzXTqNMFbMOp+UTskAp0OZYNhaBdKbZ99QYt+MokFCOLeRcKGe1RjC6p4h4ZxxSOxWavYVVikX5qgH1M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697172; c=relaxed/simple; bh=Had/Wf+ENyHWkWUkvIAsRI/aCTIvij1E+ZIoTMuIgdA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HynWvnRIkVnAMp7rTUQJ/ZXBGIyqHMDZYHOq1Vo8VcD5RUKnXcKgbJ5EFYi5uDyNs8WZP5O4losnP/MLMkk/yeqA2zXZ7ACD2sFF2MY0U1jDkvzAWxJWmCaJ8t8o7su3t4AYN8NgmzSvuCq28xwRXmMtz31571BNybwlzm183mU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=dHqVnCmV; arc=fail smtp.client-ip=40.107.236.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="dHqVnCmV" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=F0eW/0eYnvmGS0vRkttQ47YqvYfyMyFxpnOON+yDn3bZROncBg7otyt10MIhiDgfVtQqzVVg1TgJQX4IqoXgMsp9+uENaYzdwi8oSWhkMsw3kSezIPQ7ijUlWG3Xra0cYyXmZ+Uoojx27XiubdjrfPdgWYuE3AqWb5nqbR7nbuajGj717bdZ6laK1PyoOf/G4jwVC8xZs0uxKPUjtmuP8Fg/YlrOwDhNjQFp/Yub4QA0mH0d5XHLchEzajaUhSSsoQAd3ZXA5aiSDFafeYd940d1vyUdYmFOmchN+0egTCR7ApS1XJDD+xprGvB6rkORNd+EO5VuUnfkAG5Pmm1fmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=icX+T0gf6CCWs6YLnKH6hf7VYe2ePjG0Nllz+CMgvQ0=; b=AGeaM1B9SW1uAttCo8DX0kWTT3jLV55JG4rLPrfpVvusgHbBsc1sFkH5123DYzqaf5VE6mFEz2Zyz5Y2kMnjTl2PK+RgxoPMR5EeTiW/+HUvhhDRZJUhtC/VQ//6lP9/MkEQxobSUEljMx2Veh7Dd3dwtUutMGXgv8SkRaAFK6AwQW9YY8DZGq5SmtCbyfoLZDPFvF6KHDPFGLIBbTy1nQVGN0hU7ILuMCk/REmo19pDbgbZsjz3SF0/U7wf1ABUezTGGMZkHJsEivbjeSPhTJHAsRoE+metyny53JDijS45oEfjtezBHMNoAjm4b/AN1SgiTO7iECkz+YoMt5aS5w== 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 (0) 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=icX+T0gf6CCWs6YLnKH6hf7VYe2ePjG0Nllz+CMgvQ0=; b=dHqVnCmVYRwuoBj9AOUPBXyDUs2Nj5DdgpoNbLVyMzGly1ngu4fmnCiKC2EXLBqhbalkGm8nCL9NfI5k5XLJQDgav7oODtE7kP/gmB1ueZtRh6RMwgkZBBZ0CcXw8iCzdbxGX17mJvwjjhrwa8sifMfmMyPlNil2k1l5kk4yP/k= Received: from SJ0PR05CA0042.namprd05.prod.outlook.com (2603:10b6:a03:33f::17) by IA1PR12MB7589.namprd12.prod.outlook.com (2603:10b6:208:42b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20; Sat, 7 Sep 2024 08:19:23 +0000 Received: from MWH0EPF000989E6.namprd02.prod.outlook.com (2603:10b6:a03:33f:cafe::93) by SJ0PR05CA0042.outlook.office365.com (2603:10b6:a03:33f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Sat, 7 Sep 2024 08:19:22 +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 MWH0EPF000989E6.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:22 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:21 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:21 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:20 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 02/20] cxl: add capabilities field to cxl_dev_state and cxl_port Date: Sat, 7 Sep 2024 09:18:18 +0100 Message-ID: <20240907081836.5801-3-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E6:EE_|IA1PR12MB7589:EE_ X-MS-Office365-Filtering-Correlation-Id: a8e1ace7-d71e-4cd4-1c61-08dccf15c775 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: f+bdHE4IwwqRUO/46Fd4h2BS6+exefB27mFeXortLL7JoGBSyKRrJJgPoc+sx+uUaXAJiMBa1THnJlKKltV5IqhveBCOBMCVwCJwhvDJ7jDt1v0qmbFtu1TZyqvX1iOe5oGntz4bQp8I7hiLkxymP7gEcIegj7w3eYpUBlKH+JWN7GVCok55MkbyocSYO/AZCQlYtBmxyewtBqpKadXGWLfqxFn12JcpzuGvIJg5eHDXiPChk+yQWDdigONli4QyLCz3HTWk+QaNVF2tkfIFLGMAtzWF7v15+uhWfdj3A3S1krgfdBXMYpSAQfzxpwY/l2boko4jVqVocOuVQdEQeoNPyhix8tQvm2cHziMVrGUJD7PS6izU2uoNPNAHwnUWAtZux379mtrV8YTdvABTYU1cxLDF69JjDueR/PXJ9AO8UCVG6T8ZyP3+98hTT/JuC/hI3w/A6Mwsdje7GsF/TU9JbcWk7N5Z23z4aJH7eM4hxvPHB/XbaLgu09U6c8SKmhV/usjaNJavNGoL+jeEcwPMr5N9b6Xt9knXFrDSUWja44p070WTTROfAigz8YhTZ5A+8ypGNhhmaz14WMKY4kVl7ypdAbL4Yb5jJr1l3MLEW2WA/yeR7LBkpAg39oWosPaqIqcCgt3Fb9glnRGp+5QsUclCbNXZTr5ky20lrNvLOUdAZ9WoDC1ejdMln0fqdFF29qvx/KxmEiQ6Hi06sGTCfFI1Pp4EHfPz4r2QBLgGn2Pe9rFCL3P+VYP2JTWfZP2xpe6SQsQwMZHzWNdjboJ5jL9EcOSZEs1QPVAWw1Hu7zoMHSigA45+n2Fs6RfJcLnbP/QInEjN8uDIr2lD1CcGLkXVR31tLzTMYLDjDdkPetRPKZeWVL3Ye9kS3/rfQkFHUfd/qzbbc9Ua/+Q2d5K9LsUo3+Lixbqaou4DcIm9DwBKfjbZtXkavtrupXEn9Z7hGOg3Q/L6bO7+PIw7l6EhOr5UjEwqMWcQ/wTaPl27LI6YVAaagU+jwe4fykliCicroi62goOPCJR4bChuvgmvx+5m9T/n5J1hS5A/SxfAQpZ1KMQpATeIBm2NswXahk4NDwGSis5Z5eEfjwZ9exeFF4EbmndI3sQx9YvUnpajVrpgm3Kdnqlg46exuVOmFzeTJEOwBM/JdHwg9P4PKZMFALB1kRV07X0l9/W7RT4WuGrxzMBTT3qm0nhvFTyWDbKduZmJHsJ1A8SIZ37j76XubwwHaKLqW17uKMSsf/jH32F2hDfhVr6z7subJoaCx1Acq4W9cy/s9Mvm0AyC4Jpr7/18eZWiAW3SJfjv4GyGG1NHfce+P2AtVAriLxsiZLwmeSDhLSAtQ4SWWXiCQ8nImx9lUKkJnB30Ihh+1ROrOoOhST64zyhwDiXgp+aD/IMoPYeI2UtmTwPl17BAPFq+6Yvydry6ZNeQFG0PY9584EVn/3W9rlJg7nhKrytq 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:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:22.5652 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8e1ace7-d71e-4cd4-1c61-08dccf15c775 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: MWH0EPF000989E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7589 From: Alejandro Lucero Type2 devices have some Type3 functionalities as optional like an mbox or an hdm decoder, and CXL core needs a way to know what an CXL accelerator implements. Add a new field for keeping device capabilities as discovered during initialization. Add same field to cxl_port which for an endpoint will use those capabilities discovered previously, and which will be initialized when calling cxl_port_setup_regs for no endpoints. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/port.c | 9 +++++---- drivers/cxl/core/regs.c | 20 +++++++++++++------- drivers/cxl/cxl.h | 8 +++++--- drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 9 +++++---- include/linux/cxl/cxl.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 1d5007e3795a..39b20ddd0296 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -749,7 +749,7 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev, } static int cxl_setup_comp_regs(struct device *host, struct cxl_register_map *map, - resource_size_t component_reg_phys) + resource_size_t component_reg_phys, u32 *caps) { *map = (struct cxl_register_map) { .host = host, @@ -763,7 +763,7 @@ static int cxl_setup_comp_regs(struct device *host, struct cxl_register_map *map map->reg_type = CXL_REGLOC_RBI_COMPONENT; map->max_size = CXL_COMPONENT_REG_BLOCK_SIZE; - return cxl_setup_regs(map); + return cxl_setup_regs(map, caps); } static int cxl_port_setup_regs(struct cxl_port *port, @@ -772,7 +772,7 @@ static int cxl_port_setup_regs(struct cxl_port *port, if (dev_is_platform(port->uport_dev)) return 0; return cxl_setup_comp_regs(&port->dev, &port->reg_map, - component_reg_phys); + component_reg_phys, &port->capabilities); } static int cxl_dport_setup_regs(struct device *host, struct cxl_dport *dport, @@ -789,7 +789,7 @@ static int cxl_dport_setup_regs(struct device *host, struct cxl_dport *dport, * NULL. */ rc = cxl_setup_comp_regs(dport->dport_dev, &dport->reg_map, - component_reg_phys); + component_reg_phys, &dport->port->capabilities); dport->reg_map.host = host; return rc; } @@ -858,6 +858,7 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host, port->reg_map = cxlds->reg_map; port->reg_map.host = &port->dev; cxlmd->endpoint = port; + port->capabilities = cxlds->capabilities; } else if (parent_dport) { rc = dev_set_name(dev, "port%d", port->id); if (rc) diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c index e1082e749c69..8b8abcadcb93 100644 --- a/drivers/cxl/core/regs.c +++ b/drivers/cxl/core/regs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2020 Intel Corporation. */ #include +#include #include #include #include @@ -36,7 +37,7 @@ * Probe for component register information and return it in map object. */ void cxl_probe_component_regs(struct device *dev, void __iomem *base, - struct cxl_component_reg_map *map) + struct cxl_component_reg_map *map, u32 *caps) { int cap, cap_count; u32 cap_array; @@ -84,6 +85,7 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base, decoder_cnt = cxl_hdm_decoder_count(hdr); length = 0x20 * decoder_cnt + 0x10; rmap = &map->hdm_decoder; + *caps |= BIT(CXL_DEV_CAP_HDM); break; } case CXL_CM_CAP_CAP_ID_RAS: @@ -91,6 +93,7 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base, offset); length = CXL_RAS_CAPABILITY_LENGTH; rmap = &map->ras; + *caps |= BIT(CXL_DEV_CAP_RAS); break; default: dev_dbg(dev, "Unknown CM cap ID: %d (0x%x)\n", cap_id, @@ -117,7 +120,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_probe_component_regs, CXL); * Probe for device register information and return it in map object. */ void cxl_probe_device_regs(struct device *dev, void __iomem *base, - struct cxl_device_reg_map *map) + struct cxl_device_reg_map *map, u32 *caps) { int cap, cap_count; u64 cap_array; @@ -146,10 +149,12 @@ void cxl_probe_device_regs(struct device *dev, void __iomem *base, case CXLDEV_CAP_CAP_ID_DEVICE_STATUS: dev_dbg(dev, "found Status capability (0x%x)\n", offset); rmap = &map->status; + *caps |= BIT(CXL_DEV_CAP_DEV_STATUS); break; case CXLDEV_CAP_CAP_ID_PRIMARY_MAILBOX: dev_dbg(dev, "found Mailbox capability (0x%x)\n", offset); rmap = &map->mbox; + *caps |= BIT(CXL_DEV_CAP_MAILBOX_PRIMARY); break; case CXLDEV_CAP_CAP_ID_SECONDARY_MAILBOX: dev_dbg(dev, "found Secondary Mailbox capability (0x%x)\n", offset); @@ -157,6 +162,7 @@ void cxl_probe_device_regs(struct device *dev, void __iomem *base, case CXLDEV_CAP_CAP_ID_MEMDEV: dev_dbg(dev, "found Memory Device capability (0x%x)\n", offset); rmap = &map->memdev; + *caps |= BIT(CXL_DEV_CAP_MEMDEV); break; default: if (cap_id >= 0x8000) @@ -421,7 +427,7 @@ static void cxl_unmap_regblock(struct cxl_register_map *map) map->base = NULL; } -static int cxl_probe_regs(struct cxl_register_map *map) +static int cxl_probe_regs(struct cxl_register_map *map, u32 *caps) { struct cxl_component_reg_map *comp_map; struct cxl_device_reg_map *dev_map; @@ -431,12 +437,12 @@ static int cxl_probe_regs(struct cxl_register_map *map) switch (map->reg_type) { case CXL_REGLOC_RBI_COMPONENT: comp_map = &map->component_map; - cxl_probe_component_regs(host, base, comp_map); + cxl_probe_component_regs(host, base, comp_map, caps); dev_dbg(host, "Set up component registers\n"); break; case CXL_REGLOC_RBI_MEMDEV: dev_map = &map->device_map; - cxl_probe_device_regs(host, base, dev_map); + cxl_probe_device_regs(host, base, dev_map, caps); if (!dev_map->status.valid || !dev_map->mbox.valid || !dev_map->memdev.valid) { dev_err(host, "registers not found: %s%s%s\n", @@ -455,7 +461,7 @@ static int cxl_probe_regs(struct cxl_register_map *map) return 0; } -int cxl_setup_regs(struct cxl_register_map *map) +int cxl_setup_regs(struct cxl_register_map *map, u32 *caps) { int rc; @@ -463,7 +469,7 @@ int cxl_setup_regs(struct cxl_register_map *map) if (rc) return rc; - rc = cxl_probe_regs(map); + rc = cxl_probe_regs(map, caps); cxl_unmap_regblock(map); return rc; diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 9afb407d438f..07c153aa3d77 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -284,9 +284,9 @@ struct cxl_register_map { }; void cxl_probe_component_regs(struct device *dev, void __iomem *base, - struct cxl_component_reg_map *map); + struct cxl_component_reg_map *map, u32 *caps); void cxl_probe_device_regs(struct device *dev, void __iomem *base, - struct cxl_device_reg_map *map); + struct cxl_device_reg_map *map, u32 *caps); int cxl_map_component_regs(const struct cxl_register_map *map, struct cxl_component_regs *regs, unsigned long map_mask); @@ -300,7 +300,7 @@ int cxl_find_regblock_instance(struct pci_dev *pdev, enum cxl_regloc_type type, struct cxl_register_map *map, int index); int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type, struct cxl_register_map *map); -int cxl_setup_regs(struct cxl_register_map *map); +int cxl_setup_regs(struct cxl_register_map *map, u32 *caps); struct cxl_dport; resource_size_t cxl_rcd_component_reg_phys(struct device *dev, struct cxl_dport *dport); @@ -600,6 +600,7 @@ struct cxl_dax_region { * @cdat: Cached CDAT data * @cdat_available: Should a CDAT attribute be available in sysfs * @pci_latency: Upstream latency in picoseconds + * @capabilities: those capabilities as defined in device mapped registers */ struct cxl_port { struct device dev; @@ -623,6 +624,7 @@ struct cxl_port { } cdat; bool cdat_available; long pci_latency; + u32 capabilities; }; /** diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index afb53d058d62..37c043100300 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -424,6 +424,7 @@ struct cxl_dpa_perf { * @ram_res: Active Volatile memory capacity configuration * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device + * @capabilities: those capabilities as defined in device mapped registers */ struct cxl_dev_state { struct device *dev; @@ -438,6 +439,7 @@ struct cxl_dev_state { struct resource ram_res; u64 serial; enum cxl_devtype type; + u32 capabilities; }; /** diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 742a7b2a1be5..58f325019886 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -503,7 +503,7 @@ static int cxl_rcrb_get_comp_regs(struct pci_dev *pdev, } static int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, - struct cxl_register_map *map) + struct cxl_register_map *map, u32 *caps) { int rc; @@ -520,7 +520,7 @@ static int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, if (rc) return rc; - return cxl_setup_regs(map); + return cxl_setup_regs(map, caps); } static int cxl_pci_ras_unmask(struct pci_dev *pdev) @@ -827,7 +827,8 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) else cxl_set_dvsec(cxlds, dvsec); - rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map); + rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map, + &cxlds->capabilities); if (rc) return rc; @@ -840,7 +841,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) * still be useful for management functions so don't return an error. */ rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_COMPONENT, - &cxlds->reg_map); + &cxlds->reg_map, &cxlds->capabilities); if (rc) dev_warn(&pdev->dev, "No component registers (%d)\n", rc); else if (!cxlds->reg_map.component_map.ras.valid) diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index e78eefa82123..930b1b9c1d6a 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -12,6 +12,36 @@ enum cxl_resource { CXL_ACCEL_RES_PMEM, }; +/* Capabilities as defined for: + * + * Component Registers (Table 8-22 CXL 3.0 specification) + * Device Registers (8.2.8.2.1 CXL 3.0 specification) + */ + +enum cxl_dev_cap { + /* capabilities from Component Registers */ + CXL_DEV_CAP_RAS, + CXL_DEV_CAP_SEC, + CXL_DEV_CAP_LINK, + CXL_DEV_CAP_HDM, + CXL_DEV_CAP_SEC_EXT, + CXL_DEV_CAP_IDE, + CXL_DEV_CAP_SNOOP_FILTER, + CXL_DEV_CAP_TIMEOUT_AND_ISOLATION, + CXL_DEV_CAP_CACHEMEM_EXT, + CXL_DEV_CAP_BI_ROUTE_TABLE, + CXL_DEV_CAP_BI_DECODER, + CXL_DEV_CAP_CACHEID_ROUTE_TABLE, + CXL_DEV_CAP_CACHEID_DECODER, + CXL_DEV_CAP_HDM_EXT, + CXL_DEV_CAP_METADATA_EXT, + /* capabilities from Device Registers */ + CXL_DEV_CAP_DEV_STATUS, + CXL_DEV_CAP_MAILBOX_PRIMARY, + CXL_DEV_CAP_MAILBOX_SECONDARY, + CXL_DEV_CAP_MEMDEV, +}; + struct cxl_dev_state *cxl_accel_state_create(struct device *dev); void cxl_set_dvsec(struct cxl_dev_state *cxlds, u16 dvsec); From patchwork Sat Sep 7 08:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795135 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2054.outbound.protection.outlook.com [40.107.100.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 804DB14B96B; Sat, 7 Sep 2024 08:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697170; cv=fail; b=tmMXGCjRE5N12mhwYUGjDM5jpZs90FAiob8xfBOwMzAA1FCQoSzZnwS/CZpFudaS6OHTpnGRoiPBXQ8m2XtU3ORUza3PGCAtP0FmA7wPZyyurNHNFZORoSYxdqn6UwNLXlWH9Pe4u/qoQ2G7tZfo4xlZukts+hsSEZWB7YzrVTc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697170; c=relaxed/simple; bh=6K0hrWWR7B1zKP7PvYH56V/znPOvBLtluCp40C0wLys=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=puYROAnZTSk1oVV3tf0oVcxc3XZWc3iBsFqaRv/I5ACJZdYeGpyd0dKE7CyjKmkDm2zU7fetZLmcVzaxhLP8e8U/HCJevmDSYG99iz5lqnkyeqSi1ARdFiKpyxCNI7UTX5MDke4bmbsPCG80M519VEXXNKsV77sEZUF71T4Dexc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=41ErD8sz; arc=fail smtp.client-ip=40.107.100.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="41ErD8sz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SZjFIHX4ARaETuMujd9rOIHxgjRJvg97QZv/o3TZyp1l8cUb66EzPo6/EWcVluOPzAsmg/vxlNeRVm/ki+OgKMHCpg7UAlSS173UE/gW7ngSQ2KKgjR7JJQo8wv8aw6qQ1rAupCMr5TkiZts7LuhuHwxu37rAj750KNeZ0q+VmqXgpfAnFnng3rhn/BbKvNe70MU9l6IuQRKMWoLF1OvWqroMbwBL8apNsNchuO5QZbytSVROdXJ6QlT/sXOH/aTgmuTeoSVqaiKD4xPQFa2EtOSsbOGiBJEjMwu8+ecOKg/oIxmmx3F4yiESRdxdtGvJPah7p2ZTtYloYmFk6TgWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=VinIpL1SUbfp0fzsP3+HGIGxY2UZaPwTS7QEsb+qHTw=; b=LKJ5DNl0iFmjHetk3Jjf+FLhzX4WtMHPyqxAXQfTamFqpbcDlH26I0xRHw6gzGTjM9TYYnpShvIevAZvz0qWjMmuNObrxzNX6RS/DAxaqLKREQR9t83WU1x6m850j+A3NXOKo78rt8Yxm/s/f+vyYPoDAd9ggRxY8CW2IyxElpTPmRXF6NIxtmm5K5IbLFX3EjMGNCSBwDUYpeujgRcSLaJGmDbJfvDhYww2m9a7dp7QdGnkoyDwK12Fp/WM/66AzRSYD13rAi0hQX3+BGkQVlzVxs131cE9C2r+/kh70Rv78rOeIV5cJEC6QWmdfVy9Gn91EETdLNkZgq3MrROF4g== 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 (0) 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=VinIpL1SUbfp0fzsP3+HGIGxY2UZaPwTS7QEsb+qHTw=; b=41ErD8szAo+TNivPsfs4n4I1VP+lAmWhN+Vwk1UR03XN0qU2keDitHtAWeCWTlcDPNcvNkTlBSJy/p2ukrjKZFc3wI/V6RTFYqWLOxN5iClYRhsEEYIVn3iNmIukdLs+jgDYg/YP8vQBPaE7sYjvELJ7MjJ1tJ6Aq/YE1RiqDco= Received: from DM6PR02CA0101.namprd02.prod.outlook.com (2603:10b6:5:1f4::42) by MW6PR12MB8959.namprd12.prod.outlook.com (2603:10b6:303:23c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:24 +0000 Received: from DS1PEPF0001709D.namprd05.prod.outlook.com (2603:10b6:5:1f4:cafe::8a) by DM6PR02CA0101.outlook.office365.com (2603:10b6:5:1f4::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Sat, 7 Sep 2024 08:19:24 +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 DS1PEPF0001709D.mail.protection.outlook.com (10.167.18.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:24 +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.2507.39; Sat, 7 Sep 2024 03:19:23 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:22 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 03/20] cxl/pci: add check for validating capabilities Date: Sat, 7 Sep 2024 09:18:19 +0100 Message-ID: <20240907081836.5801-4-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709D:EE_|MW6PR12MB8959:EE_ X-MS-Office365-Filtering-Correlation-Id: e450b5d3-8568-40b5-f999-08dccf15c858 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: g9dpocshBMwM3YKrfYPR1PzgldIgljFlBPAT3CZjG60hZ4girt/RzLSpGiiwuUUH4OdFndggb1lWEP0v+yN/A6CWVufsqy+yEm1H/toBuWIfd9e1DgkbBqA1NB0UaCu5N7Yq7YcTl+4Ut1vBS5fl2BN09l91vl0Yga4X76ZTuFR8zhuY8Pg85ro6KaNf0gG6nr8lPby3urPkGPOew1pl9zPuqLknV0YMGgbVSI4vNCPuQM5yVYk8pHX6t41oeGHymaRunGQH1rm1KOOQ2HYSPiGOyFwyf2mjYOLmrmeqCdK6pTBo79SRAhbToXu0GcmJ76in4y5sBEtkY59+9sEJ4Lm2diz/qzT0AMxTEiFz3WIdY94fj9i650aftBHSDENr8xyguQGQvMD4/GGuZc12VlElEZ2elQ00ff3hG43ciG4UKkgsBDoUfZnFmC4ZDx/qz2cpq+i06+XxkNjvKE4kXSvnQFGBNJ8oGEipOaBD4iD9hBaAsnCEzxvvj3u8tH0f7Se0gTcYh0iQZ7zkIt3kBYeYamK4iFAeuYXyIuljrg2u0PRNc98DfIuEFdW99lGoAm/8PHbWlkfplfdielmas/kmkw5p3WK+DyvTINDZfNEHmk2bYAlhIWur3ZQzotsZb2Zle01capGUw837IJ96CtGDewabA1nv7Ahf4XOe6aAtEGn3kj7EdmetJCfuaL+NIH/x8kPPf5y33sj3acOt0+SnQfOVkTAPcTSYQWIb/B+X5DdLmMfxuoxL+LzV3T6dgarWmOwyzCANbGewtpDCDtgku5JPRfdGTYkE8aseFu9pC22lYUvUojAquQC2rsyqWN50Lj+9fEIMwgv5rFCkbmjfSevqDYY1icSqpVXbc41Il2G2NFjCiWBERYklD9VGKH5gpa/Abn2XGFoPTVB/9WHR1pQeNapcVNuWz0QryBmVl2tokGlCfSW5YsvlkqpSjGLPnefYo4zOWt88uI0uIKTU79KJKsmadvn2MNZzFGa5eKsITF3z7uBFsAXdn97soNDeFOeeZQDQdqyRlatxJrhU6cbdeh7HMofaxmM5pmmToqGNR+5tWPwgm4f9Eo5fwJIVcoxEkFiLuyTB3yJpDhKKiC53NntnKSJ3yD1i7ulfJYOZIwoN6jCuwOPbA8tWTuCmmXs4tl7HKD+aLthxrCI9qbWScoZpb/TEDoeOgaRQ6/XR/E4z2zSny8/HP1PrXaEbFWMat9TgUy7sU9E2IIaAmVZxnCxZaadUTDFnbP698FOenU6IvE9uTaCyvfBuY5U8N8cOfA3z5LfuDUyyXFKWiMkcIREhmsUawNazTuOC//3ZVrmztmCxut/aSOk7+IvxKYbG2CYGokgzL1ltIHZdy84DC332UzZ/LQCGYfeKg0F3/xVLSA0yJrHfjy6DpoSS/bZXUpbidCVPhQYu9AZjl227yD3cBbZSw3Hb4yICB1uik5bwl3/s+Io4J9bb 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:24.1211 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e450b5d3-8568-40b5-f999-08dccf15c858 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: DS1PEPF0001709D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8959 From: Alejandro Lucero During CXL device initialization supported capabilities by the device are discovered. Type3 and Type2 devices have different mandatory capabilities and a Type2 expects a specific set including optional capabilities. Add a function for checking expected capabilities against those found during initialization. Rely on this function for validating capabilities instead of when CXL regs are probed. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/pci.c | 17 +++++++++++++++++ drivers/cxl/core/regs.c | 9 --------- drivers/cxl/pci.c | 12 ++++++++++++ include/linux/cxl/cxl.h | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 3d6564dbda57..57370d9beb32 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1077,3 +1078,19 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port) __cxl_endpoint_decoder_reset_detected); } EXPORT_SYMBOL_NS_GPL(cxl_endpoint_decoder_reset_detected, CXL); + +bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, + u32 *current_caps) +{ + if (current_caps) + *current_caps = cxlds->capabilities; + + dev_dbg(cxlds->dev, "Checking cxlds caps 0x%08x vs expected caps 0x%08x\n", + cxlds->capabilities, expected_caps); + + if ((cxlds->capabilities & expected_caps) != expected_caps) + return false; + + return true; +} +EXPORT_SYMBOL_NS_GPL(cxl_pci_check_caps, CXL); diff --git a/drivers/cxl/core/regs.c b/drivers/cxl/core/regs.c index 8b8abcadcb93..35f6dc97be6e 100644 --- a/drivers/cxl/core/regs.c +++ b/drivers/cxl/core/regs.c @@ -443,15 +443,6 @@ static int cxl_probe_regs(struct cxl_register_map *map, u32 *caps) case CXL_REGLOC_RBI_MEMDEV: dev_map = &map->device_map; cxl_probe_device_regs(host, base, dev_map, caps); - if (!dev_map->status.valid || !dev_map->mbox.valid || - !dev_map->memdev.valid) { - dev_err(host, "registers not found: %s%s%s\n", - !dev_map->status.valid ? "status " : "", - !dev_map->mbox.valid ? "mbox " : "", - !dev_map->memdev.valid ? "memdev " : ""); - return -ENXIO; - } - dev_dbg(host, "Probing device registers...\n"); break; default: diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 58f325019886..bec660357eec 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -796,6 +796,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct cxl_register_map map; struct cxl_memdev *cxlmd; int i, rc, pmu_count; + u32 expected, found; bool irq_avail; u16 dvsec; @@ -852,6 +853,17 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (rc) dev_dbg(&pdev->dev, "Failed to map RAS capability.\n"); + /* These are the mandatory capabilities for a Type3 device */ + expected = BIT(CXL_DEV_CAP_HDM) | BIT(CXL_DEV_CAP_DEV_STATUS) | + BIT(CXL_DEV_CAP_MAILBOX_PRIMARY) | BIT(CXL_DEV_CAP_MEMDEV); + + if (!cxl_pci_check_caps(cxlds, expected, &found)) { + dev_err(&pdev->dev, + "Expected capabilities not matching with found capabilities: (%08x - %08x)\n", + expected, found); + return -ENXIO; + } + rc = cxl_await_media_ready(cxlds); if (rc == 0) cxlds->media_ready = true; diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 930b1b9c1d6a..4a57bf60403d 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -48,4 +48,6 @@ void cxl_set_dvsec(struct cxl_dev_state *cxlds, u16 dvsec); void cxl_set_serial(struct cxl_dev_state *cxlds, u64 serial); int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, enum cxl_resource); +bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, + u32 *current_caps); #endif From patchwork Sat Sep 7 08:18:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795137 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16FC11514DC; Sat, 7 Sep 2024 08:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697174; cv=fail; b=bFtLOVl0DJyP/6V7GC/SqqNfQo8TmwinGawUdcjPy6hVLqGECTtQBUr/yIkrDQPOCL+kKqlS2VXTkWrfB2k0DlqM77aolbs6Sg7eBE7NFylSmQEl2vu1wkbJTMC96f7ZWUTDMJq3lzVTU9zHbnDfpUhQaeSeMxbH9OwCJ26kgJ0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697174; c=relaxed/simple; bh=3otBWoLSGTBRjmiQcv76bn+la33Im3oe3W7WLWidPNI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z/T1lKrm7SHoCiYYGnCB7Zc4JeoEOFCPEWxF+u7qnaazsccBXlIhkiXV8cbgGtIW5Y1LmsIwuYlyy0+s932b1aeMe1KZI92p6PFj9Um8v8sLw1CU/dhGWhctfvcQl2K35foFVap/jSwJlomHAgPXYq5Ap0g26IXlOZGcKJTY5+s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=w3/TTOC3; arc=fail smtp.client-ip=40.107.237.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="w3/TTOC3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xFBXLeNAOUet0pFGRcMh7WJBJAVikOQVMA9zNtiTP1qabwMwoWjCbjNKXESU/u82wSnk/a6cxwhNhmQjtrFLQC4mhs5CuP/d9BPCCONcwaN6fVt42m+z6Qo49ojCGzFhu4oCFnwJ6u6yOn2FKYGkj4JHw+61h72kwAjo1LqZbzsMDLhgyfv9bqT2QojE/EnM7lPdxEBZq6vyhOO9CidzDWxx+Cgw/q34UFzNZ0y6+5ZQjSBo8tTn1sCy7aM6mMgcyPJRG7uOpqGIxBBOS6vmUx+vkDu2e9T5gHCfnkRaXZJlFq/mGVYqAFEF2ymuSaXFuIjtEc2oyJFMXEkAU7vSdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=rXCSOC+JS45vGXTZsoVuhC+AKDjV+94ZBsPvmyQX/s8=; b=aKi6rc8xh7JqYKAkm1P6XuMJ5t/mCBwd9SsGgnptX3EJOt91t0LUdY+hP9Ju943DIa38V86Oi3/5/6hR+4vwnf2RRYmjS2cxzrGUzjW62yXBlx1+6iKLL8JCocgcMA4DO5NkFCRItInUEN/0ZcIds2mbCQx3SuOz9zV0R8+iJjsGiz+S1tUU+ehDm+mEgUUKKmQdDMqiH6qCNwX4pB7seAHlvw//QY6TsYA6W2gF3qeeObRI5xR0JlAU4g3mA7oysEMaL8f6EFs1BTcOgfDCgc9I37PL83ewvjW4LONSGrcUNfLWjn2YUU0CH+HZoncQwJVfBFmMVKxJTYnvqow+vA== 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 (0) 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=rXCSOC+JS45vGXTZsoVuhC+AKDjV+94ZBsPvmyQX/s8=; b=w3/TTOC3bdNMwzOPaXZcgLnVMjOSomP3IFN+kd/B6xeDvMRF0YHmEroxT3OCcGIkGMoW2MEF3CekJLKlnUSbBYsK+Ov2PdTEWsIGhf9eAP7ZOuZ/3JIa/sOkx5Uo9HlIXabJnlB/KjH7MWMiJOmAOqnTMmN5K7oS95IS7nonzxI= Received: from DM6PR03CA0050.namprd03.prod.outlook.com (2603:10b6:5:100::27) by SJ1PR12MB6242.namprd12.prod.outlook.com (2603:10b6:a03:457::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:27 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:100:cafe::23) by DM6PR03CA0050.outlook.office365.com (2603:10b6:5:100::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Sat, 7 Sep 2024 08:19:26 +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 DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:26 +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.2507.39; Sat, 7 Sep 2024 03:19:25 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:25 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:24 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 04/20] cxl: move pci generic code Date: Sat, 7 Sep 2024 09:18:20 +0100 Message-ID: <20240907081836.5801-5-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|SJ1PR12MB6242:EE_ X-MS-Office365-Filtering-Correlation-Id: 43bd8324-dde3-4341-a7b2-08dccf15c9b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: bMeMRUPQspkDvaOdU08H6f7T5bnheRzbdgp7uImCYcEi5i+/gJa0AXBE1bA2VNo6/geWLLet6+HZqXWt3fbXljilDjSwHwgQjkLbKBN8XiTyelBHl+MUo+tegG5YRk077jkGsmMIxVQo1nvHvYB9TRwzE/v1sGijGeaJnkrPb3Tdg4jfJWWXvE+1a/K6zFW10Dw1a9irV48Y9oR+uEc87z1G57NkYf9h6OE85gn7a4CEIKwc61W9ri7+53GT61a/4eJrG/oDtmLIEJSy8OCV7a4DpXGafLpfHhQBZsc/y612jdYh3ZZpSipyFc96uY3cJxQ3geB3gb0VFMslmlykXYg+NaqK4eL1ggeYOdeMftYpVA7cQ5CvgxRcGoQP3xP6rXH4u4StcMWfj17sPATe2FWm4FoO74fDVXYcz6z3sQeTiZoZQ2aLATmkN5E0/XG9/mHNiEtpJ6mjHQ2uvLvOUGyUfdjCLHNFxvB4Ds8b8WKGpcB+6dcubIs+bgtumPckZkccb4J5tC7ryy+K/USsNcjFlW1GY7J3112ic9JyleJilAw9Ag7w/ES6vjN/oU1NpMQq1nYV8MfUe+koLZwZvp3e8YSwXFe74znu0HhvpK3EJc/odG/mNTqtLTz55GRYUa0O1fDJmBnYyAMe+OT6p+NCTJMOpRDZKQ2KquVd7RxxSPDvCQXICo81k98tNi25RSoHd4URxeevhG6VHx4jUOMKgAa+GDbJ70iyJHo0L1NDz1pxd9T0uG4Kfcc5AoRrOvvawZsCHCBgbJb7pWtjrc3gHIrGpmromTYcLtUeCT7io10CUd70x6p6mm2u8DVA5bCSsW68imOwCNA93Pu5I1IgsO7Ak8FbwTAA/dEhe1fCdzieLjDTjt+Rmk6vdXNAhI3RAycb5GPi9Xv7RWeo0sUgl+pienAXgJ4zCcRevee9lD7zAtEwzfMZLVpYjIjMl0+ju3+W4v4J6I74Gv3vBz5lDD3SjFxkUV6x5gTKPyEoCLV/U5DEEtR5RYMvIQRL2TJuL9drfvUdzgqPjd07RwqPQHzFNTT2AwAauPKt8LzqT7b8UTy4sKrGqMSuyaOG8S8hJC0cWPx0bNfMj3xHXBNb/bOnlZRH1NP/SCHjyV3woFfA133YGQb+CxbNnE8zkpXX4PDYugx5+il5gbaMf76AN6c1GsPr5BWByAnzPuxnyTtckjvjKbS+SMxktgFhEfWZ3L+VSG/53KI8MWuE3hWdu/u/OqdIEpwtcD9DUNvd5qJrGFMGpj7B+u2CZyLqD11sMFMhGvLpjpfEWTIQ/c+gQIXxyMAGBYIzHzLGJl4aViVrmCuX1eHhMM7eRe/XzQ1rThSwwg0C1ANmb4+sAgz8nfVx2lKhozM9AB5FN5NUhBoLq7fdbVqvo3Uo3xvjHd6XEWPmLWj2xI+bKXJzmqeiGvDmEQ1pxiv4NTNGt9uxtoY73UgDSH0QTDHk2bBb 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:(13230040)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:26.3578 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 43bd8324-dde3-4341-a7b2-08dccf15c9b0 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: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6242 From: Alejandro Lucero Inside cxl/core/pci.c there are helpers for CXL PCIe initialization meanwhile cxl/pci.c implements the functionality for a Type3 device initialization. Move those functions required also for Type2 initialization to cxl/core/pci.c with a specific function using that moved code added in a following patch. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/pci.c | 63 ++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlpci.h | 3 ++ drivers/cxl/pci.c | 60 ---------------------------------------- 3 files changed, 66 insertions(+), 60 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 57370d9beb32..bf57f081ef8f 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -1079,6 +1079,69 @@ bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port) } EXPORT_SYMBOL_NS_GPL(cxl_endpoint_decoder_reset_detected, CXL); +/* + * Assume that any RCIEP that emits the CXL memory expander class code + * is an RCD + */ +bool is_cxl_restricted(struct pci_dev *pdev) +{ + return pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END; +} +EXPORT_SYMBOL_NS_GPL(is_cxl_restricted, CXL); + +static int cxl_rcrb_get_comp_regs(struct pci_dev *pdev, + struct cxl_register_map *map) +{ + struct cxl_port *port; + struct cxl_dport *dport; + resource_size_t component_reg_phys; + + *map = (struct cxl_register_map) { + .host = &pdev->dev, + .resource = CXL_RESOURCE_NONE, + }; + + port = cxl_pci_find_port(pdev, &dport); + if (!port) + return -EPROBE_DEFER; + + component_reg_phys = cxl_rcd_component_reg_phys(&pdev->dev, dport); + + put_device(&port->dev); + + if (component_reg_phys == CXL_RESOURCE_NONE) + return -ENXIO; + + map->resource = component_reg_phys; + map->reg_type = CXL_REGLOC_RBI_COMPONENT; + map->max_size = CXL_COMPONENT_REG_BLOCK_SIZE; + + return 0; +} + +int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, + struct cxl_register_map *map, + u32 *caps) +{ + int rc; + + rc = cxl_find_regblock(pdev, type, map); + + /* + * If the Register Locator DVSEC does not exist, check if it + * is an RCH and try to extract the Component Registers from + * an RCRB. + */ + if (rc && type == CXL_REGLOC_RBI_COMPONENT && is_cxl_restricted(pdev)) + rc = cxl_rcrb_get_comp_regs(pdev, map); + + if (rc) + return rc; + + return cxl_setup_regs(map, caps); +} +EXPORT_SYMBOL_NS_GPL(cxl_pci_setup_regs, CXL); + bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, u32 *current_caps) { diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index eb59019fe5f3..786b811effba 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -113,4 +113,7 @@ void read_cdat_data(struct cxl_port *port); void cxl_cor_error_detected(struct pci_dev *pdev); pci_ers_result_t cxl_error_detected(struct pci_dev *pdev, pci_channel_state_t state); +bool is_cxl_restricted(struct pci_dev *pdev); +int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, + struct cxl_register_map *map, u32 *caps); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index bec660357eec..2b85f87549c2 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -463,66 +463,6 @@ static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds, bool irq_avail) return 0; } -/* - * Assume that any RCIEP that emits the CXL memory expander class code - * is an RCD - */ -static bool is_cxl_restricted(struct pci_dev *pdev) -{ - return pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END; -} - -static int cxl_rcrb_get_comp_regs(struct pci_dev *pdev, - struct cxl_register_map *map) -{ - struct cxl_port *port; - struct cxl_dport *dport; - resource_size_t component_reg_phys; - - *map = (struct cxl_register_map) { - .host = &pdev->dev, - .resource = CXL_RESOURCE_NONE, - }; - - port = cxl_pci_find_port(pdev, &dport); - if (!port) - return -EPROBE_DEFER; - - component_reg_phys = cxl_rcd_component_reg_phys(&pdev->dev, dport); - - put_device(&port->dev); - - if (component_reg_phys == CXL_RESOURCE_NONE) - return -ENXIO; - - map->resource = component_reg_phys; - map->reg_type = CXL_REGLOC_RBI_COMPONENT; - map->max_size = CXL_COMPONENT_REG_BLOCK_SIZE; - - return 0; -} - -static int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, - struct cxl_register_map *map, u32 *caps) -{ - int rc; - - rc = cxl_find_regblock(pdev, type, map); - - /* - * If the Register Locator DVSEC does not exist, check if it - * is an RCH and try to extract the Component Registers from - * an RCRB. - */ - if (rc && type == CXL_REGLOC_RBI_COMPONENT && is_cxl_restricted(pdev)) - rc = cxl_rcrb_get_comp_regs(pdev, map); - - if (rc) - return rc; - - return cxl_setup_regs(map, caps); -} - static int cxl_pci_ras_unmask(struct pci_dev *pdev) { struct cxl_dev_state *cxlds = pci_get_drvdata(pdev); From patchwork Sat Sep 7 08:18:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795139 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2081.outbound.protection.outlook.com [40.107.236.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0E11537CB; Sat, 7 Sep 2024 08:19:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697176; cv=fail; b=Bs7IbEfyNDg8crNhlheqETIgjRfeHrWK3nJGzQfQgjHdv4LchYKrwPVRgz0XtzcMnwNkn/PJ8hc4WMsMgNZ8oIUZVD8TmF2adPR3QK0bn06ezebani2q9yHO1L1Y8TOMLbvOAezTO7vV5BXLAiM3f1eEGrRQ1j7f93+LdN5uX30= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697176; c=relaxed/simple; bh=VGF91VQY93JxXvSVsOW5atcR5uKSCIkDV+ZsueoQERc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dXcJuOvRJZTPYI2dyDfwOOjID9SmSA6ZYtjWMHeY3W9Db3/XMy+W4xlzwmusfgeIpfDUALNzQDacFwgLakrYW2QaA36J0sW6msWPjSq9e+K4bKYtslDyG9yIgOjrBpglJachw3J23vHS09TBrHdpAacRCnf4n4U+8eD3RdlTeOw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=rkuG7rs9; arc=fail smtp.client-ip=40.107.236.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="rkuG7rs9" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c/IeyWspm2wn7xu12ZkEN1nwfZ/TGpYtTAlImK5c1hk5s0rauxDrhv53cL+snlEj2+Zw0GqpDZa98Eag/QLHHwlOQlvIGHOydjGFyyim3ieDNfMldW1IKi35DMR/oZyWsGjNiPQCxEWM8sXlz0HMnaKN3BYh6l3V6SLZlc/5h8aBFWUqeZEKmDO/x04gRgs5aPMD5WNzsFaiO5zIrKalmfVVCmRqTlIXudGNwf99Uwt4A3zq/LlVAOZWSFPFHjK/H6pcAj1pAaZMuiHJ3+FZ9NvJ5n5qyqypM9bq0TtCchflX9lXpXai37g43wbjTHWM/qoWV68aIey6IF8PAwo2+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=RiPHZnn/JvdYqd28Qu0Rxr3PspmDvs/sQvyl/CdeqFk=; b=Gs2b1JxGGxSRtmz0LJFidgz6cuC2qvD2vQnUnYMvnFmjPsXHi58kSPP1OGu6Z2kJncr4uU4VehWLn2bGzygpnUMBwA12eswlj5l7l3K+dfmIsZnMF4PFHEMzI/AxactKpZXJApA1JbdHz4eKh4md2xqQ15BIbQ8VsyWQR9hWxVo7aPyaQ0K12NmTtEgCKGaMCgovo+lINeVjWXkK1ZqoVsYv+sAdnaFznHoyUtsGAIFXeteiRjTTAy7Gpuvs3EQXvhe7VKNd9w30xVGp2WbUGWYuFaUklIfqsHkVYWoknbscBonEPd0rAsa5qLGYoc1qqIMRAEAX+kaNt20P/T9WKQ== 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 (0) 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=RiPHZnn/JvdYqd28Qu0Rxr3PspmDvs/sQvyl/CdeqFk=; b=rkuG7rs9Fx4CP6dLfIev8v4FEFXgV29t4WOXGzmplNKKPTycgPOenHiwtaNGi2IZXaDzMa39tKagQ55vn7xxIq7u+Q7CcGBQyRDjeLYjC0pcaY/8ddzF6/u5onJkZVAqW7UOCpUJfankJUNnrFRRoOWwcZqbcpSGAYfKqsEeOx4= Received: from SJ0PR03CA0342.namprd03.prod.outlook.com (2603:10b6:a03:39c::17) by MN6PR12MB8567.namprd12.prod.outlook.com (2603:10b6:208:478::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:29 +0000 Received: from MWH0EPF000989EA.namprd02.prod.outlook.com (2603:10b6:a03:39c:cafe::47) by SJ0PR03CA0342.outlook.office365.com (2603:10b6:a03:39c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Sat, 7 Sep 2024 08:19: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 MWH0EPF000989EA.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:28 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:27 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:27 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:26 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 05/20] cxl: add function for type2 cxl regs setup Date: Sat, 7 Sep 2024 09:18:21 +0100 Message-ID: <20240907081836.5801-6-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EA:EE_|MN6PR12MB8567:EE_ X-MS-Office365-Filtering-Correlation-Id: ae98a0fb-2cb8-4ebf-5c29-08dccf15cb08 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: x9cu+eEwwpxD023VgpcfeTNHDwUDejGrbZTAWV3MBhipIXXScL15Qds+lnwslAvlh06E/n/1EIu9cXtPZyuWvksn5QWT7BOtT1pQ1Wv0ON41Rb6KG5nwO6qhPqAaKL3GY1KvUE5E9Vshd8BjqWwwgRwtqKdCSJeN/JM2LyVj3btIAGr7MT5WOIGzfEB5Suus3hWfkyI4kKQBd1fc/SYTKGCwN8hlljZ33/KY/hdTuZZrYbjl9gQswGkJTPoPjIMOdhYgLuJGEXeLibAXLZQfSDScMVwVtQP9XzmKn2apZms75vE2UxSu00p8Ro2AZ9gABzAwAP5gBjf9SKV5xkN16cI3WDeIoVHXJY9Vrsui8x7DgmnmcPhQ3ioH9WdxaHcVtw5/opPy5WaPIE8PBr+uuPypzsjYV5JGpcZxIaPB0ffBWFXfF8SuPv1Z9ZaR7iOgU3C+oEa4ZChrPwwch5vq1vd7Ab5jpp1/QsWhQx8HCHMKTaiby5muiOkYtYDpPJ8EmUQyWMKFNn0uJ3aOGsl935qf8WL0WKrZQy94MValS1mxshkap9TKUyWbh9wU+qNRM+pBzn3q10Kuj9pXo0PwhOZ0qTafwK2n7XYWdhCgj2I+EDGNCztHWnl4Ry4unbwd0cbR+h3tcMtUN85FJN54nJ2wD3Ez+Y8Ys1TuuucT+bF//9Q48yCBvY2qOwAf0+mjrkU12wnlf34qHFdl8NV9nvv0dOZlJolCuIr4PWGxuUMndcGgjYVQpAejH1bLUbEPu9iuHyIdzJn05P4h3kKcH9f4mfOqQLiDXwrdxVUf+KCuJUP057s86DeF9kG6cWG2C97RNH/9tZtgOBhIu9oFFAh7MZ+uYSI354M6DyUJkyZoPT8fkc+aibQmtS59J5JfJQxKBwXpuCHcb2v+IQyqfb2Bi2fYbmefNG0mFtzVrkRNv3PQylGJUD8S0JBqQyPQk1yGtCZFMQsiTkERj476eXBYP2qZaIpVHFabZLqtUcjALiJYgzfLtodiWDEOJA0r7xm/oFyoe1+EqPlGVH9Q3RjspSRAYoyiINtylYHNw/NVmFX9bDdMDnqwpFWBc4+4i0tyLF5K3nq5Y9rB2oFiCrKdoVhUJZqHZXp5gs4WRs+ODiaKhiOpdxAyk6Kjl05/taSzDjO2NR1d1gE5NVHEKaaHVT9S8OdwGykr63HA89/GGPzjUi5R2x3BhlW4p4hWLYj7BNfyJaTHuOxF0rNZLazKyM2Ctc0WXb1UXhBUgiVXRGuHmj1Teb8xFDHSS+/dBpziaV6ewWbtWJFgvd+IFtXaPqM3BBHj8WDDQeAe/gaTuUKL7lsUQKHU2/7NDHGk5YgqL7EO5aTIzi0JtaqHitkZgV/RDujfFPZobTZGSdRJgG38RSXVLLQ5OGNQZ0lVPxXIwcKpcrqHYAa1/TFh3HhoCNscFP0+5t+qcG5WsPWpXjH6Eo6Y9+5A2HgsCmL+ 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:28.5790 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ae98a0fb-2cb8-4ebf-5c29-08dccf15cb08 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: MWH0EPF000989EA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8567 From: Alejandro Lucero Create a new function for a type2 device initialising cxl_dev_state struct regarding cxl regs setup and mapping. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/pci.c | 30 ++++++++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.c | 6 ++++++ include/linux/cxl/cxl.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index bf57f081ef8f..9afcdd643866 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -1142,6 +1142,36 @@ int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, } EXPORT_SYMBOL_NS_GPL(cxl_pci_setup_regs, CXL); +int cxl_pci_accel_setup_regs(struct pci_dev *pdev, struct cxl_dev_state *cxlds) +{ + struct cxl_register_map map; + int rc; + + rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map, + &cxlds->capabilities); + if (!rc) { + rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs); + if (rc) + return rc; + } + + rc = cxl_pci_setup_regs(pdev, CXL_REGLOC_RBI_COMPONENT, + &cxlds->reg_map, &cxlds->capabilities); + if (rc) + dev_warn(&pdev->dev, "No component registers (%d)\n", rc); + + if (cxlds->capabilities & BIT(CXL_CM_CAP_CAP_ID_RAS)) { + rc = cxl_map_component_regs(&cxlds->reg_map, + &cxlds->regs.component, + BIT(CXL_CM_CAP_CAP_ID_RAS)); + if (rc) + dev_dbg(&pdev->dev, "Failed to map RAS capability.\n"); + } + + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_pci_accel_setup_regs, CXL); + bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, u32 *current_caps) { diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index bba36cbbab22..fee143e94c1f 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -66,6 +66,12 @@ int efx_cxl_init(struct efx_nic *efx) goto err; } + rc = cxl_pci_accel_setup_regs(pci_dev, cxl->cxlds); + if (rc) { + pci_err(pci_dev, "CXL accel setup regs failed"); + goto err; + } + return 0; err: kfree(cxl->cxlds); diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 4a57bf60403d..f2dcba6cdc22 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -5,6 +5,7 @@ #define __CXL_H #include +#include enum cxl_resource { CXL_ACCEL_RES_DPA, @@ -50,4 +51,5 @@ int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, enum cxl_resource); bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, u32 *current_caps); +int cxl_pci_accel_setup_regs(struct pci_dev *pdev, struct cxl_dev_state *cxlds); #endif From patchwork Sat Sep 7 08:18:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795138 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2055.outbound.protection.outlook.com [40.107.92.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3210A14AD2B; Sat, 7 Sep 2024 08:19:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697176; cv=fail; b=tYZbzPT9zvwTzrD7TitAftYjo6CkFggtfGlGnIzM4IvJovAiT8DTvefvp7VZDuqq63cQJie7IPb0oINxC6g98VNgvmSvX8X0XcnP0v1VHdRt5NNLJpHSNChFKJdIAesIk7WrJgJTX51PJ1/y47jbkP0ObfWt7Gqi8kfbTzpUYcE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697176; c=relaxed/simple; bh=XENGUSXp5MqD0EnxHjZ3bndZ9FmCP/roR7S0RvjPvng=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O+MMHtbcsi+Be071IqZvVTpb4Rbl80jJ1RkkM8uMX4v88e+voS9iJDcnc7QARWpAfsoY34YPDhlNCfp/evlc9ir2Yg/k/EelvG798+yuAkHG9/cYwF3/1fud1t+cqKUyV3FszGEMoQNlMr2udSDFlAzRny2VBF6Vl0kQ/NpU1dE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=bu3s+Xcl; arc=fail smtp.client-ip=40.107.92.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="bu3s+Xcl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JNYyQUs4sGV4WIQH854impW1/A1rD6SqD3dIObakB4Mz4qk2/HzOznH071a/xl7ypL0JGL4gTLPh4gmXWmNOt+4M9pxqkmrleUF6MLWHXGHV064mG175XKUJLK9dij1ipAJNNnisYjOXf96e8MFR4WPJ4FTQSAlCxqOCvcnnePLumhIns1WqqvcLP2uJS1TGu7AQqEBeSq7Cxr8H2SZ9xAHELiZCO5JhBAcJPKpUB6tJZjt3s6gVnlcfxD5RKyQ7w2qZpCqrPaS08ENaRY1ZFxTwMCN1qwWKjUmLpJT28IpX9RqGlshylNGwwpqs9aX+jwI6ILS7RSDxIET/dlgfJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=a32juu3lT9HE3boW3OCJsU2VMql+SLFh9g5aOWoU7Rs=; b=NEdAJMC+wu3aryxXEuz1jg5w8SkqryeQvEs6mMCGqC+mRl5dbpxnrR0T7hmvDVD+vRUMq+sqo2eh6zV08jPIB5OK/akoC18RUfBER1t9+9OtcCuwkd6VMxp+83BM5iY5WXVXgnAtkflGNHieXv18DCdwGS2cxGFMrpQWYVMGb6ejO+BEb/Z4CwWU+iHP7Wy6C8PujSvycR0SuEv5InuVAFBDGhsQNKKIecCqLJ9SewVgwiJasbChKefUJS14WYD75CyuQt7L71uR2jWfFvBnnpN6TqXnHl2zBaXTZaOtqyRwojFKb5rzvuEJvalJUZBNqK4JSlZml2KwOxqhQnozPg== 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 (0) 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=a32juu3lT9HE3boW3OCJsU2VMql+SLFh9g5aOWoU7Rs=; b=bu3s+XclkRN1RO1hvrAZRJSuTK+DNAX8pV8enGWL5rGqxU7metkBlCvPyKwCvKCde6pET0vz+Ldkimeufxn/swZBLAXOmY1CnPwnK0J/O4Rrgt+poaxV+wCMmXk2CcYpZgFp023a4lGPH6JafMC2EaDAeuMde0ocILrx+c55caI= Received: from YQBP288CA0040.CANP288.PROD.OUTLOOK.COM (2603:10b6:c01:9d::24) by SA1PR12MB8741.namprd12.prod.outlook.com (2603:10b6:806:378::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:31 +0000 Received: from DS1PEPF00017097.namprd05.prod.outlook.com (2603:10b6:c01:9d:cafe::38) by YQBP288CA0040.outlook.office365.com (2603:10b6:c01:9d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Sat, 7 Sep 2024 08:19:30 +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 DS1PEPF00017097.mail.protection.outlook.com (10.167.18.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:30 +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.2507.39; Sat, 7 Sep 2024 03:19:29 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:29 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:28 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 06/20] cxl: add functions for resource request/release by a driver Date: Sat, 7 Sep 2024 09:18:22 +0100 Message-ID: <20240907081836.5801-7-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017097:EE_|SA1PR12MB8741:EE_ X-MS-Office365-Filtering-Correlation-Id: 95c48d57-91c3-457f-7680-08dccf15cc14 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: N1ERPx4Lya3thLFbCpAM/wcCCZczk5YtKR/dh9OVFyX1TyPfhb9aZ3813HF6y2CkHSHMHSoYleLbel4Rp2hn6IdiIL3Cx5ZoT6gR5kTckVpgNE3bvUVxyHAZNkhxzdIqGYDX4uRNlLBqKY5I7AxEwSa7sZQ3GxKCrd7gvH7afcasBInLnRH3eCwcII4Gf2ab14u8I1BYYDlry3a3eyZkCCYR/jUJJRKf+ZnJ1S7oJLtspAAv2GpltvGpksBaOOXf4luoVumkKuTbctXElpYsbWveyXwmFW+Nwyk149GZgqxBaWcIl+hsvdrUil3aOJbsGyPO++VnqaLMMv8z5LTQPzbeMHDPgXvHhi6ctrMeH3MhELNuxiAr3F5lqp2tW1Z5+XifPtggwpzZ7ZneIHWOVWfZsrn2bvNDWBqoKybazylQJyQHACs4Sj7FhUKaI1VJGPMdVNRivyiVfvqpSKbsxOUlEd446XuOp+w2QrgNdYJmqJzPboe1tCTcIi8IaKCr+V/+9qRMUzI8Pn3n2fjWPzavbmn/xNkkut3+RsREsZb7i7QdPz4CvOW93yrSf6RvWyPiEJ2X1HfKeXtDsoS6zAJzobpEjc5f/Ib3FwrU9y1ki1KeBkUOaiiOmT7B+kt6kJp/WGDjPGNqadAecG52VjCbiyi7kJQfDqCHdgEVPdGqLyvsoE0NLUlkzgOQSrvWSY3PaJIRCx7LLfsDo/mJS/H7D0dbKbVYt23v9NMWuHqKYBmw6bHY64GB8WCf+OgZyq7CftILxWZXzTs/53wGqNW0Ece5RphIp3xxWCuAulPdllbpnsZBAkrkTULrFDhk8HXLaKcPjnclJvW7rnCp/VvIzR6CRzlevYXXpFvuz6N59d1IpoN9WM5ArsS114vKkXbijK4RhzXowx6rg50BZxvIHRFt7sy0Vu4uV9YDuG+XUOR1FuKlpjXXvq4gZuNe5i5F73Vz0Ai88HiDzjfaYu6UDsNZiXLy6FWhbe7IQtIIAYWOWztFyhaGc9xy1L7yPfOXbxe0tgst9bLdvDB9SB+hqR2jg9lzVOXgMnSK6edols8DsatF8BAcSNDyb7DhbJ5jP0MhIelZtGibiJlj8Fw0Rnl5z3sMH7Y5M7BPRdu4qqvXP+PbmXVTb1NNnjyUKTWLK1J3uFCo8l640ASuQL/cz5jWGuLKdASXFYTXD4exyIIIoAAIFIEjzfHwa2NJ8bTqRmmKZ2YcKxkmyb2OXAEpbxKfKzQthrvkhiaNycIB2LdeXrtgUBOGjUHqeHkcH+srxLXUhq3BS+E15vIteGNkY5tPdzhng0K21zaNgrQ6QNDk+YHZNrJouT4Fw8QK35tuKXtw5pirRrmDbM3WwrGaLuzGEmKZdv7yzlwPY2RY2kkUjoxuxIFtWKd7fK1+b0rT1fYdt1zFwyUPgfKfgtZDvZoHbOwYwBYXxa0ZnkIoRPC2KuGlu+m8zY0jw0h9 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:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:30.3673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95c48d57-91c3-457f-7680-08dccf15cc14 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: DS1PEPF00017097.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8741 From: Alejandro Lucero Create accessors for an accel driver requesting and releaseing a resource. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/memdev.c | 40 ++++++++++++++++++++++++++++++ drivers/net/ethernet/sfc/efx_cxl.c | 7 ++++++ include/linux/cxl/cxl.h | 2 ++ 3 files changed, 49 insertions(+) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 10c0a6990f9a..a7d8daf4a59b 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -744,6 +744,46 @@ int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, } EXPORT_SYMBOL_NS_GPL(cxl_set_resource, CXL); +int cxl_request_resource(struct cxl_dev_state *cxlds, enum cxl_resource type) +{ + int rc; + + switch (type) { + case CXL_ACCEL_RES_RAM: + rc = request_resource(&cxlds->dpa_res, &cxlds->ram_res); + break; + case CXL_ACCEL_RES_PMEM: + rc = request_resource(&cxlds->dpa_res, &cxlds->pmem_res); + break; + default: + dev_err(cxlds->dev, "unknown resource type (%u)\n", type); + return -EINVAL; + } + + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_request_resource, CXL); + +int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type) +{ + int rc; + + switch (type) { + case CXL_ACCEL_RES_RAM: + rc = release_resource(&cxlds->ram_res); + break; + case CXL_ACCEL_RES_PMEM: + rc = release_resource(&cxlds->pmem_res); + break; + default: + dev_err(cxlds->dev, "unknown resource type (%u)\n", type); + return -EINVAL; + } + + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_release_resource, CXL); + static int cxl_memdev_release_file(struct inode *inode, struct file *file) { struct cxl_memdev *cxlmd = diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index fee143e94c1f..80259c8317fd 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -72,6 +72,12 @@ int efx_cxl_init(struct efx_nic *efx) goto err; } + rc = cxl_request_resource(cxl->cxlds, CXL_ACCEL_RES_RAM); + if (rc) { + pci_err(pci_dev, "CXL request resource failed"); + goto err; + } + return 0; err: kfree(cxl->cxlds); @@ -84,6 +90,7 @@ int efx_cxl_init(struct efx_nic *efx) void efx_cxl_exit(struct efx_nic *efx) { if (efx->cxl) { + cxl_release_resource(efx->cxl->cxlds, CXL_ACCEL_RES_RAM); kfree(efx->cxl->cxlds); kfree(efx->cxl); } diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index f2dcba6cdc22..22912b2d9bb2 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -52,4 +52,6 @@ int cxl_set_resource(struct cxl_dev_state *cxlds, struct resource res, bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, u32 *current_caps); int cxl_pci_accel_setup_regs(struct pci_dev *pdev, struct cxl_dev_state *cxlds); +int cxl_request_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); +int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); #endif From patchwork Sat Sep 7 08:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795140 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2065.outbound.protection.outlook.com [40.107.94.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD0FB156227; Sat, 7 Sep 2024 08:19:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697179; cv=fail; b=R+1+AcR30Qwp1heYE251otZxqKovxquMcr9jAQBLIiFWJC6CEXGpvVTJK6Uo+zSIpHsat2KyliPpCAA4dV4dY3x8Z5mP5SnBoZj2RIGMWkw9m9yGaulTGgHHaK8VWbx/9uvxb2+BSGkOuvQpKlzgr2klqQQIQDp0sCSAQWfEsJw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697179; c=relaxed/simple; bh=VtZYfQHONQby2EX07NAzcmrS8f8L2l7cBIJf+d1f9F8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pcxIh0gz/JyvQLE/5PO9m4LHxb55r8Y1liandG0PlDqbXx15vRne5F+PkmKC4o9k/9k9by4TTC7A15xZN/iV10x2pGqWambYonSoUcSqktecu5xby6wQNWgsk69VYwWO08v6bQ4pj7jIIt8XqobvqQRtt5evf2/eRJuJ8GHand8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=js3R0YUD; arc=fail smtp.client-ip=40.107.94.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="js3R0YUD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j1YsBMaIgCjhO8TVJPCP5R8YhjB8g7+8v29uvNaMZt57LKCyEBGDOe+UX3EdjrxcoNBTV+ZKF2XcObRYVMSskWDYEyEbXrIMso1LtJljt0pTOHdNFtnvSrWQoiCG4lHbC//pnaiOfbmfg+gMtzuhVDKlYKNZm1icjPh14+cl171kUu1gRdI0U25IXm3WjL1bpYTGV8tIjvYtxb8Sj/IUZna8XmJAFduG+JWuqp3sN0c6Jw0KAATKexJK5RQm2zug53B1+pI+qchGrjmMnb0B7aowfnzOvRFLQ1aPKhSVb3o1akgf/pqN5Cre7QG4mr8PDY3bg98DxLahQwMyLnNlfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Mt2g3tCIlrtoekwE4xpZtAtLk0JXgrvZINw8+ZTgNXM=; b=vA4NnSFWmT7IXfdp3PDkylLERXh/KAcJo9RenKdsKhMl7TeopuDSOUXXln3tIemEfVoR+Gz3J1349CjCkImGEStN9nyfMQW+CFhHdblD2ZAWRgpt22XEyiSRKweZ7KxgR9sWFu89qhDD5TYnyLxoOhN53dZ1KjxTM2wJOKxsHodpn6zEkgOmMrcVzOPjWEM8duQbkeLu1+BXJm7c3QXA1HcQy3duVyDQyoowAvo4xxN4rVS0fPqFB04P9Jn2TA/U5Bqwskbv25FTJd5Uw1gDh8NDREU5hLbFcOkH5kxADnKApXpAfA/bTxoHj7qb+zKRDd1aUr0Tm5NPUmsvUSQr/g== 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 (0) 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=Mt2g3tCIlrtoekwE4xpZtAtLk0JXgrvZINw8+ZTgNXM=; b=js3R0YUDQdit0lL+OQm8sVmaN5mpy5AwucCpKlQPTaq2jDQLbj0IBFuAOqIRfQKCgwslb/wSs2Zfg3v+bVl3QRVNW/Zw0V60/OFIGr1hqXvL1KduW2+1kqbD9nJrBuS03p4IuRTn9Ijp0zicUJHh1e1Wz8i5mh0nsLXRPbrH6zU= Received: from YQBP288CA0035.CANP288.PROD.OUTLOOK.COM (2603:10b6:c01:9d::12) by SJ2PR12MB7990.namprd12.prod.outlook.com (2603:10b6:a03:4c3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Sat, 7 Sep 2024 08:19:32 +0000 Received: from DS1PEPF00017097.namprd05.prod.outlook.com (2603:10b6:c01:9d:cafe::23) by YQBP288CA0035.outlook.office365.com (2603:10b6:c01:9d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.18 via Frontend Transport; Sat, 7 Sep 2024 08:19:32 +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 DS1PEPF00017097.mail.protection.outlook.com (10.167.18.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19: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.2507.39; Sat, 7 Sep 2024 03:19:31 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:30 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 07/20] cxl: harden resource_contains checks to handle zero size resources Date: Sat, 7 Sep 2024 09:18:23 +0100 Message-ID: <20240907081836.5801-8-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017097:EE_|SJ2PR12MB7990:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b746882-f007-43ef-93f0-08dccf15ccf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: hOrotJL/fBLEDr3FNrt8cWmVKwvrowp+N24URbl3NJkn9v8TkW2g0jLfG4CyuuFFeUdQ1lR8wTcMiM9RkYCBA6kBje5+E6uMDNWqEaGC7Zms5Y9j3OmWqF55pdgWaTmdl1Re9t6N+plvUcRHLjCDUoDmJx0LylVkHMQBclM31KVp6zS8WotX8oEClfwTuVqdLGL1/rCCnENPssXYmP58XqtqPqRG80YFpZHCqIeQWYcf0w3vSyF5kAKh3esA6+/T0UOFu//ISRcysRpy9uyswXPVowH9Oj31aDUg3ZFomjNcQoN48qo5XDMePXm3ODn7JLkQjFAU2oDsgHNbu10HvPgw6hDWNLChHwj/yZsiyBfU0n18StAHrAjZ3CKkSk1LoMW5MKJ/xZ2kw04ScXHeU225i1eack0qo2qeIRHeTM9mx1qQivPVFVwm2Le4P4p/0NpuPTH9WvxORYgnqdNR0ik3fg7O1lytI41NTnES1soa6PZfVVp0Ck4tu07F5pVEE6zH587WLDjel/G1nHkOxERlML4Vm4cqf9c53ECMk0Uzuaq4tJUyx171Zf0zLbgNEUOTWPDloRQyiWzHIfg4zs3WMcy0riCmWACDDid4ncY55mNalmE8R/oQJXNsPjtVOdv8IwN5AGVUjMCYMricFkK9wiDUFAg/kcaFTjNjs99RAmT3Iud42nVgsP473h0yzgi1oJWTyfyuqAMKc+b/bMtlLooOzGmrWEf1B2lCNS/KtFAmuHNhDPpgqhBHCN9kagceJGThxgw0f1NEOvteVdL1B5wS84gnU60DtPcDDziLc4lRX3qYkEQmJae5EEV7vkPcFiP/MoEz596A3AqEgBdltp9cYGNLUCYFOWs7E1XZLtMNZHTNuMPVPAPI9bhCvsQ9VJ0g0hudgVCA2sNUagKEw43OLZBT1UzeElrlLjig9dA1yXnjzXhHD8AC7l+RUjCpLP40dPjWQjeUIk/fCtLNuz93mZ9s8zsh7m4UqrX3AzbBVjCxNC5n+z4434SmHToOjUYptMMbNPgZUH8cwOfSuChWu8al8fjGbLNoZsfSDPUC0cSkN0eSzevqSwpSjHpSyJiCc3WyXnAeuMDOrkojNRMwRXSPwsQnSQlP+lJI49hka3vyMsrC6VpM8fjZCrpy42ia8MdTCPvKpL6ZCmQ5nz/s8zDxktfaDhDWYCjp/fUXg3wxLz00hxcoa5g9HEEb7cyWHiXLjXIXUuP7wD1jUjM13Y4L5LvF5l9oq2aL9NZoDU260Amtw6T0cqoNFOYwYBqzhQ3BoMsy0rtjVs4FL5Bnf5g58GBh1ixqRwayOislX805AN0bZiMAsNnpfg4ZomSzjJJqZnzDPKxTupQLAXjPW7RsKgrKNGnLWzEQ1X8jROF/Xfi+Xbaf9C2GiiNU8sgdh04sgQObWPtzrAMJS5FpJ33ToqMfUMOYoZ5TMrtXxdWd45oPXsUoFTPe 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:(13230040)(376014)(36860700013)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:31.8517 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b746882-f007-43ef-93f0-08dccf15ccf4 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: DS1PEPF00017097.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7990 From: Alejandro Lucero For a resource defined with size zero, resource_contains returns always true. Add resource size check before using it. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/hdm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 3df10517a327..953a5f86a43f 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -327,10 +327,11 @@ static int __cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, cxled->dpa_res = res; cxled->skip = skipped; - if (resource_contains(&cxlds->pmem_res, res)) + if ((resource_size(&cxlds->pmem_res)) && (resource_contains(&cxlds->pmem_res, res))) { cxled->mode = CXL_DECODER_PMEM; - else if (resource_contains(&cxlds->ram_res, res)) + } else if ((resource_size(&cxlds->ram_res)) && (resource_contains(&cxlds->ram_res, res))) { cxled->mode = CXL_DECODER_RAM; + } else { dev_warn(dev, "decoder%d.%d: %pr mixed mode not supported\n", port->id, cxled->cxld.id, cxled->dpa_res); From patchwork Sat Sep 7 08:18:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795141 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2065.outbound.protection.outlook.com [40.107.236.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59ACF14AD2B; Sat, 7 Sep 2024 08:19:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697180; cv=fail; b=j6S2Q29Xa0icjPcsWMeVO+7y8LMJEluEbc8DxVU2ktygbzVkRft5A8dkTHjMdZ7Nk3R/JSI9p5QBbOHOdmGRO5r9nYt0QnLix0rosqLGwMm7SAGxDrmZp81ShSrcyfbQcFap+NiXEKsDpMnhSF1Hq3VqQRvpKgObHzobhvm6qyw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697180; c=relaxed/simple; bh=wVszij8loj0aktksCsbVzt9ZbDi/g54X/YMIlTfkT64=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AW+v5vRe5ptiIrEGiH77nh1l8EztD5EC5ENf4SJo07czFX0XU8Tpuea9omzJGYJMc1b27wl4XY27rIuo/ATKxydhtDO7tyP2LBnQ5PUXe9xCf7c5fowWv9DAzrQCU1kVI9kXG0h/LdZ+ZP0C00HB4efQm5QdjLT7WTt2Wv0TyV8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=pedaAAbO; arc=fail smtp.client-ip=40.107.236.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="pedaAAbO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SBm+FzmcRor1uKMBTx6btOAsEgyhpMTg0Pd2GdPXAo3UFY4KBza6kP8Cxd8FlKLKUhC/Jq7U2RTRbJsYRv9In7S9+SD0sBgDNi4i99a58Rb4WK7/W6tq8sobxmsEJASuSVtbLKqYb4zT1oMmVN1PdXF7Df6jyD6FtWlcQTJg2Xk+KyGxrji4OyaZJOdfQUEZ+Fnuh50Yy2tUNJJSpQqKY7RpL5maFLzqUl2TouzzE3VEc5UeHqY0AMD8goiCUu1aNJG03+5naE6qkoxEdy/KwdiIrtZL4i4vRsktW0jX5rUB05JKLDi5q3tJo0sKgBPsqxTuuX6F190sNGWr/qNeQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=O8Ri2IevzBpOepKFq8WTEVypmC+OTzRlYeV0cboBam8=; b=gEhRoiDFyU/O0WusGACyY9o9GscJvF1GLyNicdVL2wNuhX2MukuVFRvOhK3+E5RyO+c3wV/xo+6NJsuNjo+OQoOXk9mj1uS9GZxpS+Oo75vn4gt5vThigCQWi2rDY8vPtQdNT7q7IODbnyzqcct3MDNefwAbHoJyLPqCz7DXi8hZRWX3zYqT9PI8yKq9SHBSQRktiB8l0kKTMTPt668ezh66UJF/1/9k43fUxzDMJbvf97+bB0v4Shg5DWo2+8QR3oBIyXog+mpqm8ETqAs2R3vDuyrgK88AlpwIRNek/IAz+Eu60R0Mpzrs8HssRaFmw7KujCaZgqIMvfirNXnneg== 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 (0) 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=O8Ri2IevzBpOepKFq8WTEVypmC+OTzRlYeV0cboBam8=; b=pedaAAbOUluFyC/XQben21I36EQ0pg0ELzXZPt5ZRPXkUgH2sFnYR+v3h32ipws/vJxKBBfGKN0XsEdz5Jze6d86rA2r0nnatF2sya+n/FS9ZbVHcRn2MeZpWAytnJoQ/HVSb8kqel4FnWfVzt9nm5l3+qx25FSJyt+sNX94Lcc= Received: from DS7PR03CA0140.namprd03.prod.outlook.com (2603:10b6:5:3b4::25) by SN7PR12MB7884.namprd12.prod.outlook.com (2603:10b6:806:343::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Sat, 7 Sep 2024 08:19:34 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:5:3b4:cafe::85) by DS7PR03CA0140.outlook.office365.com (2603:10b6:5:3b4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20 via Frontend Transport; Sat, 7 Sep 2024 08:19:34 +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 DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:34 +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.2507.39; Sat, 7 Sep 2024 03:19:33 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:33 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:32 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 08/20] cxl: add function for setting media ready by a driver Date: Sat, 7 Sep 2024 09:18:24 +0100 Message-ID: <20240907081836.5801-9-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|SN7PR12MB7884:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d3fbe87-0b8c-4737-9be4-08dccf15ce6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: 04Tvo9PLxwxgzKgHBfdWAlWPlTzTaiMAzN23DSFHCsMl0nGLOQoJmOw8z3mTMuU9RkmGfra85sylaZGw1mRUUmQkVT73wjnzcXLJBFkdYq5qC9Cy81DcMKTzYqpXsskPEggMQ1aeuVFFVBK0ruDTgjgOCAwdRw3O4RRriwNeLCKoRV4o8F5hHdApIcZpbWNPgRW8Pbs7hczaZAhdaYmpaA8pX0H033jxmjm36DOS9VPdWaIBHJL5VDbpTprPbMuPldKGVXOCcH7uZsWC6SM/rnnyUOR4k7yLssYdjF3HXgwGA8nf6YBwDwo3u4hM2Xr5xJ6qkTQ8xcNPJiqeBkJn0u/fnb70/FEjJp/r5mHsUm8+F9J43IY/sOWIKNGabjBD+ep8VwNB9w/NnOjqSrIFbIb0MNSgxD9Hh8x3RCE/3c/VrmKL0uXrk2GVlmt0eWwLNeFNRuikxAtTRCmf9gD6gHSYCAACrqb/I02HpG1V53S6vM201dLHEtBqa8p01BWAyNqpnZIsaMlFYCzVbq0TaedMJZU3S3YudYuwSdlV8ZLc3WT+5DFE1jlyBuxLQwtsq7Z7el4AE74hjAyreSB+F1V84s4jXnNSdazs1DWtyEeXRqbPzWVU5j9etwQkKr4y5wXZuj2UvPTn4qle2kILdmdlZ+H5WOohIkqtnHXQq8fbN7fsCDlnlOVLhdMlD2Eqio8SQjrkKVV2WSmz1VRVpCYhSmjK2Ly+w8uA9L4K4VIMZ9/+Z7FhQZwEHLesLQdOU+Sw78A2SAl0Sj/c6mfIRgY98auTNtBYUzKmj+miYKzqCKYYg71+YD7QR5i7sk66FoPYxuhxFreyyCzaX+D8Y6I39OO9o6RJSTVULLVbWJPTPyX5vVpN4jdxXQiqEeEUD4O+vZIJv1mJ+p6qVMlUQlXjhgaWitQ0PNlx4R1/wSVSkcVQHCCG+hNA6Mqi9QkbI92ZDTQHD/wIgQyNVGxfYGpmz4peR5dK5b2eo67zJP3oprccmY1WPIqiSTFxs9S0g+kKwqg/DXGrs9LjVV3TH8u1AIYLqzKOe6OEYiTG5w7vI+1HddcZBCEtBycj1hvT7+W22o1p8LeVlJTNyKIuQuIWjuuycHfdKrRqiVKhvphpYfPIN2xNKwvs5JxtMY9rAoJDSRuXLy04AOJ7a9Ml1NHDCp3segBUyBYp2UsV/0IhITQOeYU3xVkM/3u1IWwMu3jFCC+ZfSwmOTPoo2HZqkWENJ40DHuS/Ld3njfeMHeokQteXURtiZJ5nNe+72fEaT5igcqjN+b4/7pk4WoFxberoioM9wmBUD9C4MXs18QZonT5iNEwxx8DJloP4kS2Bser9Kg0+rEqnzIQhkam9NfDfvlMEV555rJgHImJWEE5lfE/PSJZEM3/wCEfKcCk7NxbzkeUhW+9EnFj+6qocA20wsDDhpRVItXSRMaFf6BvQFoQY8HXlVL4J9fUAm0q 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:(13230040)(36860700013)(376014)(82310400026)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:34.3292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d3fbe87-0b8c-4737-9be4-08dccf15ce6e 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: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7884 From: Alejandro Lucero A Type-2 driver can require to set the memory availability explicitly. Add a function to the exported CXL API for accelerator drivers. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/memdev.c | 6 ++++++ drivers/net/ethernet/sfc/efx_cxl.c | 5 +++++ include/linux/cxl/cxl.h | 1 + 3 files changed, 12 insertions(+) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index a7d8daf4a59b..836faf09b328 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -784,6 +784,12 @@ int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type) } EXPORT_SYMBOL_NS_GPL(cxl_release_resource, CXL); +void cxl_set_media_ready(struct cxl_dev_state *cxlds) +{ + cxlds->media_ready = true; +} +EXPORT_SYMBOL_NS_GPL(cxl_set_media_ready, CXL); + static int cxl_memdev_release_file(struct inode *inode, struct file *file) { struct cxl_memdev *cxlmd = diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 80259c8317fd..14fab41fe10a 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -78,6 +78,11 @@ int efx_cxl_init(struct efx_nic *efx) goto err; } + /* We do not have the register about media status. Hardware design + * implies it is ready. + */ + cxl_set_media_ready(cxl->cxlds); + return 0; err: kfree(cxl->cxlds); diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 22912b2d9bb2..08723b2d75bc 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -54,4 +54,5 @@ bool cxl_pci_check_caps(struct cxl_dev_state *cxlds, u32 expected_caps, int cxl_pci_accel_setup_regs(struct pci_dev *pdev, struct cxl_dev_state *cxlds); int cxl_request_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); +void cxl_set_media_ready(struct cxl_dev_state *cxlds); #endif From patchwork Sat Sep 7 08:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795143 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2087.outbound.protection.outlook.com [40.107.95.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6782F14D444; Sat, 7 Sep 2024 08:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697185; cv=fail; b=capxwp5Uft+G2ogrv6ODjDOJJ5zwItIn79laPBRqPK8zhJGpHaC07wyXaDHqGepmaG9KN+1j830ijVf/c4BzmsDcvxwZFp3+APvIJ6Gb0Vmse6DmaT9CL3/48XWDq3pb4DQsW7/5vaJIAlvfdufqUuoqQH0RyJHaRuOGuCKjl/E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697185; c=relaxed/simple; bh=XfAZFewFqEJ0wLZFwhsCxWEEaaT3i1R/PrFq5boor8A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s5MUKTuW8ruOrwb8Om8BP+Kh2LtvYr8oHjxYdLpojUEOvStMFIYNM1AdD/cnu+lNVekOWS3t2dEljhXqzsEXgNGe4B+h6yTZGp2WzDLgK+TjE2vu4mLNJzy18EMJJx4McCKFQ0WtwxhdIxx5dOEsdvs9tGTqcaDF2o08wJyZGf0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=rFOAvihb; arc=fail smtp.client-ip=40.107.95.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="rFOAvihb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WfCkPXHwDpG86PfvjW0cP4qCgvQ5yi4xLuG7UCIHElVlurQIADZQ6l5kWVKfTBy2oJUOn+9DnULtOwv1yHIPIxESzUQzKQV6Bb5FJb0k6h686P2ZSHVo6wrcAgqPvAUjiw0qvCOHW8N6orgbMzBMbtAy7BSxFc3SvInL1miZAoIdUDpoQ8itoNwY1etX8GEXy1ZcSnsl0kwtYRPqZNtqp5fp8WE15OPipSqBPRKQNHsvSuJtVrzZV7gjygRZRzCtxT5u7QBLkvJqQ3p7GjWvb87lWIfB5n/+HXlHyGDOracCSCU29WWqzV7ZYCs6e5JZ1rNYcpN2+o8WSVkv7JR84g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=v4JHaADDa0IZNCi1R9QwUXLEo/yDw0n9egHV+GCXIG0=; b=WxzxecnhnnOqnRsUUJS/cDNeg3YIPhgWbnB8FpGWdq+weOoTVlAEV/xR0VBM9/2ST7xtmxjhbPc+p+n+db3bG2ZoLrsNn9+TG+xG02diK0uDSt73Snx8Bcbzt8LxwW/IE23Vx85BlK4TMKwkra2SEXrBSqmjD4aTPI5Ydm9areRReZ+YUpN2AulS/ILDbO7Kaw6lfNbH5j1GhzYTEYD/IGi10n7XNNtid3IKjYaDqvJ+R4oGrzF24XT8sLdQ8bEhUkuthW4WQaZrRK1uDdPJqJzYm7Qu4OA7VeyYqMPkxE3qrETKF4FrA0/GtEbzrsw/CIruZ9i6K/3OsJwILzbOcQ== 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 (0) 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=v4JHaADDa0IZNCi1R9QwUXLEo/yDw0n9egHV+GCXIG0=; b=rFOAvihbg86+sW8qF1wDuy7xvKsBmgXl+LQB0LZ5gFMcpTaxaXyqAvhEouIeXmxXlazqb9LKOmQzrsA3hXvYOF2un6XHDnDO43nQVkAu0mreu5HP4+HEes5htwudXocRux6rup5Wws5n+RK/9+L9OTYF8q2m0W+HJdIX14H+cKQ= Received: from BYAPR08CA0014.namprd08.prod.outlook.com (2603:10b6:a03:100::27) by PH7PR12MB5901.namprd12.prod.outlook.com (2603:10b6:510:1d5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:37 +0000 Received: from MWH0EPF000989E7.namprd02.prod.outlook.com (2603:10b6:a03:100:cafe::ef) by BYAPR08CA0014.outlook.office365.com (2603:10b6:a03:100::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Sat, 7 Sep 2024 08:19: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 MWH0EPF000989E7.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:36 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:35 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:35 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:34 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 09/20] cxl: support type2 memdev creation Date: Sat, 7 Sep 2024 09:18:25 +0100 Message-ID: <20240907081836.5801-10-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E7:EE_|PH7PR12MB5901:EE_ X-MS-Office365-Filtering-Correlation-Id: b9e83f8f-65e1-4c95-c85a-08dccf15cfc8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: laaDbPifZZGW+FMlVNRh/H/QComNz8QfvqUx7ZdN+svlM8Dmw8rNfi+sDMrK9vwAO6I4dKvwI94wWNUcXpVObwODGAWbCk3vwSt/Abfi1JucbVElgbpdRpIzBfVuCSfLnJqYFclGh5YixhDKbNIkXVlutJcXQXe/S8D3P4HBYvmsCDJV7uNjyS1J49IEfykwUKuPnqgSGdt9NRBujKBfyZdhA6SNq8oYgs2Cy+ZjmmD2S2MFIGozWSXrfM5yxbHkagvpOfnPfJtJVoq2ESfDJH9cwBnn9y9XzEz0yxLUdu2G9uScrNb2us0zlyVwpjITa1sJDP/ERspxN1rdyh6gZqeRYnADE2+8S2cYvrOSQiBjD/CTnqdmkjn6gzyfZ799aAk4p40+L/9gOAWAsVhSMHsYg6ORlEDqktSm1O2oJwOjvri8FHu012kFqGJ6Uz4mVVKy6/jaV+ias1uokgoPM4DgMeHIVkafsPmiVidf9NDNbvq7NcNoqpL/vu5L9NoLLWMa893QDyzc+V1yybHugEirJjAgszKQuyelpU6LKLc6fX4FUBSaQd0imamP/dgcvgCBS1kuHAHu58ADVLC/So8s6QT5Us+WbWIA6GOnGRzYU1s3tz2z9HS7eaqVVkIwhvHYqnm5pt6bi8lmcRsziugu3lG5LKglqMLbVMKp45XOtf3M/SipJi8biz2aH/Jqjdm5xlpmmP9llpBHqTf2pIWW4nzpF0SJc7soJ754nCKiy45K9IL8bsItFEGwaZv+NG9+Qri6EyClUtoHi2iGvSmaYU6i56vFHt1S2NQnYEl8CX40Z6eqLNetBEUJkt0ccLlfnzHD7O04J6wSkfQdzJNwIz1ENdoL7O6FdCIqQmURAvx7JmJlN5qOwP60T/LMq9qNrsqFrJgyO++LBLKZpXpIc0a947WDmZdVKRHj3IPA5uPms2rcQt5vya7i5DFgxsd7JeQp202fV0nOYhhFvuPCypMfDFmcmWuk1euy44VURfpwRpLClG4AAhOLVnAznGn8CKeecaRcZqUEq0kcRFXcRWoJhtZ0+5EKiMo/23FdjaQRCFdxsB64+C8JC9+qiLMYqwqKuS7LCaGYh89WoHM1953NRVd5XgOjt6YyraRrXJqipr00Q32kauWZZq/NcJhOnBgCt7uZmsK+bZm8i2au/107pJAntBQAIZK2SAdh/tfihYoZdXwcuulsLXCLItm28LC5BCmaYCjO8iEwFbFvPiUcIzRhvAI8zJMHw/Hj3pfX3wbd+QiiLIQL5Wr3yLinSJlTUQBrWfp1V6l6G5Pmm+55Z+a51SaEMBQ2MTXBqjkKUcAcpTmW+Ir7J4chZOolvzUXDtEBVLLijWMov1S4JpTbP6bK+V4OkArN7d29SMxFTiEQmjOXM8ZipagCE5Z7S+hsL2sZbIe84AjfoJPzLbG3qozURA8fTjOTsScTcc19uGUjH9n2T3yEY7eK 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:36.5354 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9e83f8f-65e1-4c95-c85a-08dccf15cfc8 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: MWH0EPF000989E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5901 From: Alejandro Lucero Add memdev creation from sfc driver. Current cxl core is relying on a CXL_DEVTYPE_CLASSMEM type device when creating a memdev leading to problems when obtaining cxl_memdev_state references from a CXL_DEVTYPE_DEVMEM type. This last device type is managed by a specific vendor driver and does not need same sysfs files since not userspace intervention is expected. This patch checks for the right device type in those functions using cxl_memdev_state. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/cdat.c | 3 +++ drivers/cxl/core/memdev.c | 9 +++++++++ drivers/cxl/mem.c | 17 +++++++++++------ drivers/net/ethernet/sfc/efx_cxl.c | 7 +++++++ include/linux/cxl/cxl.h | 2 ++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index bb83867d9fec..0d4679c137d4 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -558,6 +558,9 @@ void cxl_region_perf_data_calculate(struct cxl_region *cxlr, }; struct cxl_dpa_perf *perf; + if (!mds) + return; + switch (cxlr->mode) { case CXL_DECODER_RAM: perf = &mds->ram_perf; diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 836faf09b328..5f8418620b70 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -468,6 +468,9 @@ static umode_t cxl_ram_visible(struct kobject *kobj, struct attribute *a, int n) struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); + if (!mds) + return 0; + if (a == &dev_attr_ram_qos_class.attr) if (mds->ram_perf.qos_class == CXL_QOS_CLASS_INVALID) return 0; @@ -487,6 +490,9 @@ static umode_t cxl_pmem_visible(struct kobject *kobj, struct attribute *a, int n struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); + if (!mds) + return 0; + if (a == &dev_attr_pmem_qos_class.attr) if (mds->pmem_perf.qos_class == CXL_QOS_CLASS_INVALID) return 0; @@ -507,6 +513,9 @@ static umode_t cxl_memdev_security_visible(struct kobject *kobj, struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); + if (!mds) + return 0; + if (a == &dev_attr_security_sanitize.attr && !test_bit(CXL_SEC_ENABLED_SANITIZE, mds->security.enabled_cmds)) return 0; diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 7de232eaeb17..5c7ad230bccb 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -131,12 +131,14 @@ static int cxl_mem_probe(struct device *dev) dentry = cxl_debugfs_create_dir(dev_name(dev)); debugfs_create_devm_seqfile(dev, "dpamem", dentry, cxl_mem_dpa_show); - if (test_bit(CXL_POISON_ENABLED_INJECT, mds->poison.enabled_cmds)) - debugfs_create_file("inject_poison", 0200, dentry, cxlmd, - &cxl_poison_inject_fops); - if (test_bit(CXL_POISON_ENABLED_CLEAR, mds->poison.enabled_cmds)) - debugfs_create_file("clear_poison", 0200, dentry, cxlmd, - &cxl_poison_clear_fops); + if (mds) { + if (test_bit(CXL_POISON_ENABLED_INJECT, mds->poison.enabled_cmds)) + debugfs_create_file("inject_poison", 0200, dentry, cxlmd, + &cxl_poison_inject_fops); + if (test_bit(CXL_POISON_ENABLED_CLEAR, mds->poison.enabled_cmds)) + debugfs_create_file("clear_poison", 0200, dentry, cxlmd, + &cxl_poison_clear_fops); + } rc = devm_add_action_or_reset(dev, remove_debugfs, dentry); if (rc) @@ -222,6 +224,9 @@ static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n) struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); + if (!mds) + return 0; + if (a == &dev_attr_trigger_poison_list.attr) if (!test_bit(CXL_POISON_ENABLED_LIST, mds->poison.enabled_cmds)) diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 14fab41fe10a..899bc823a212 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -83,6 +83,13 @@ int efx_cxl_init(struct efx_nic *efx) */ cxl_set_media_ready(cxl->cxlds); + cxl->cxlmd = devm_cxl_add_memdev(&pci_dev->dev, cxl->cxlds); + if (IS_ERR(cxl->cxlmd)) { + pci_err(pci_dev, "CXL accel memdev creation failed"); + rc = PTR_ERR(cxl->cxlmd); + goto err; + } + return 0; err: kfree(cxl->cxlds); diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 08723b2d75bc..fc0859f841dc 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -55,4 +55,6 @@ int cxl_pci_accel_setup_regs(struct pci_dev *pdev, struct cxl_dev_state *cxlds); int cxl_request_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); void cxl_set_media_ready(struct cxl_dev_state *cxlds); +struct cxl_memdev *devm_cxl_add_memdev(struct device *host, + struct cxl_dev_state *cxlds); #endif From patchwork Sat Sep 7 08:18:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795142 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AE1814A605; Sat, 7 Sep 2024 08:19:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697184; cv=fail; b=qmB/tELY9dn6BUWQwO9yKTv6QTUiVy6xLjA838H3V4KO6Pt1xiuUkF1lXUQ1fPaJeBwVPVPe8knEUkGdpD6K8i2Wako2kk+tWUxk/JHFm0z2fk1HtUL9I/3sDvWm2EFlgnMYc34XYbUEd2N+YK1CTLKIW2STAWjkS2p5U2kp1ec= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697184; c=relaxed/simple; bh=fVN0fQTkBsu4Jovn/xn+BUwKJK5Hkdguvrz0FZno4NA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u/K7WSG3bJy6/KW5Xrb7hvZvLygLmDPumIwu/uQlfJxqVpq5gxHrUuXkFU3uo3wH43VmuwIkODIkWlqNF/12dwaZy6WNlRocsA0XfNX4prc4+CcgRCJdGtIxA4nKx6Nme/h/3XIDyKtus6gWjM2u9uCPXYCX563JOXDCJ/pkkE4= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=sKSTkFmZ; arc=fail smtp.client-ip=40.107.220.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="sKSTkFmZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bh7CSzblKq+sI+dxAjktHkOoaNOB38wSaQ+hYARGOgiFOXW2OR32cYUWot7hyFTj3C1pkbz4aJLg0AhOtLxLp9Pmg2vFyp+3Whm+o/PJySUcfEgI/zbVkO1tB9l4QdFBkCvkoPB13kUr8bsjuYzdLgOzXc88wjQ4yOJFGx1yZMJpC1lYkSQPHLTuqgkM3NyxM/kmMwdPfdqJUKkemEbKNdGLzOjThajL+i1jlEV1wzFNA+BUQnQS3TFCMRfpMqrvmZhfh7qOs4SSwV+jwCHtnSUuLa3HvDKNlfLCTQUm+jZVdA2/zMv4TPMNGLaesmySjOUIA6NGiWkJuqTht74f6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=y2HXGPedV7Cu3m6/JEOlxvXT70qSaWc2eyE9bfvH+Jc=; b=YVhxNCDDE+25O7JppK6AOg37YfT9tfOL5SFe1+NfL/FR7zibTWiV2CmwQyqGJU06SJddEpRQ9b3QXrTAsQrKEGTofPavTT43aPbFqHlz5vpky3Q5fY+/CQMcEq0YfeyFT5aFNMwXOE5ucCjmZHO0L+wn1IHoTvFPUh4aEqdTz8QLVMDjf0MMurkmPkEDMsQejwWkFeKnfwyynzTX2IFNMOGn8SDQcrO3CaP6IGgSUKpgEOk+KbXoNBa713JBqlSqp5k9GDKUEhomVbE4SeqHWLEz3v47gK+rOwPARIdJrZ7odbtOyepiqd87OB3d2bRY3U+9MRWHZDAVRGWU5DhFng== 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 (0) 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=y2HXGPedV7Cu3m6/JEOlxvXT70qSaWc2eyE9bfvH+Jc=; b=sKSTkFmZk8+f4OdcunLINiEWi4t+etPNBDO3YrnOWWchrjybmnNBXFjb+9QKXPzEmDAurusNGc9l88s2OjG2nqyft9QQ4ZRD3weDVfIEy2hIYRLSlon745VhjmXO++FOwYoebNYfZwZGoFscunDgew0bcXkEleWXhj6AF3IYNwo= Received: from DS7PR03CA0122.namprd03.prod.outlook.com (2603:10b6:5:3b4::7) by PH0PR12MB7486.namprd12.prod.outlook.com (2603:10b6:510:1e9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Sat, 7 Sep 2024 08:19:38 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:5:3b4:cafe::39) by DS7PR03CA0122.outlook.office365.com (2603:10b6:5:3b4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Sat, 7 Sep 2024 08:19:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:38 +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.2507.39; Sat, 7 Sep 2024 03:19:37 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:37 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:36 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 10/20] cxl: indicate probe deferral Date: Sat, 7 Sep 2024 09:18:26 +0100 Message-ID: <20240907081836.5801-11-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|PH0PR12MB7486:EE_ X-MS-Office365-Filtering-Correlation-Id: 352ee910-a6ed-4a7e-1d39-08dccf15d0d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: y/TSLmHNHkWvc5qyM60GoZMK5KLA+QeqqeuC9rpo3gRn7NWvfG48EKYB9jjdVqS+KHsOJkfX9ITgQ6T6gMoFjvJSicV29lQkIouFuu8+cGyHCTNFmF9YONwQWzk07/XT4yHw8SzWDZaW7OdBlZxtO69PXlIHyt6/1gZ26/NnUtEqGj+djTT4Bh6VuN9W6ze8WLFCkFEzxoEx60psnUogFidhbNS20NpvWFdOS9M7vadPQVjGZ2MWfXTuns7yHd9IhDnQZwkL3f6XrD0tfclqYv7QVyEuT2SxdS1P0d/n1Y8MbLTlyzWsPvRCGXXPjcdlqhcGTISl4l41BHkWuSV5bxbDq6ZLrmeDiSdo/cVoaESf6j4lZstNbvfOFE+jzPfX0E85m6p6+Dow3LHqrhTWQM/eeszEZ72K5RDD716G3WANqK5iSKrWxqq0FqTMakgJHTr09BN+So1erHrDFG3evwwC5avJxwKpHt/HtW+1pqaXGLexGYVTmij63U84EecuPA4YYhw4lvripVAVgGzfwBWqHa8/ff7l+TmCR+OoIKSuWlS9hDTt9p2sK2CPd+2korks1Y89OLrgrOYI4UNnjfcYRgGWHTCCb0lMVkNrluDb6wDVlZ4vNn2STVZQTZGwmfS4ZNd7Ml7aJlL2Fa4K760JQLcNC0pipin1WEGcpRimytkqGPJLUOg3B6k4QFE5S4dOOMlNDN85V+/2xU2N9qInpLS5K82egnjaRgvh6xbcBxTaMF7RgUMrvOmWPG0BUgrEjisf2RqiCVjGFmmbz+fRdDYCZ+zqqDCktrm2e90AU1vhxkkbtbB9N8mRXfG1/aQsSanF0CxDzg5XaYRLEuWNSV6u2PGz6VRVDe0nc1TjkBxm/0QZ8pamDzkSWnBtOGeebtTKxCCyXc/bwPqNh3yiSuu+TryUpkoUjavSLj4VIH0kj4QX0QU+01O8OkriQhJ1G8dnB53GoT5WwxnfxiT9LkgwJsgs4tkJC0QBdonT6j0rRixY79LXTkO4DcFxGyUdTHiEh5ugkATfnM7bgZM7/c7Xv0X/LQiveahZbZIZs4Q97Fw+/Gp5QwLwA3xHggR0J2cMxNxAU6MB1SPgPX/ZB62lnCQnfFDgPI1pUCgD0mZ1VGZoG76oSQt5TIiPrHPup8McjTsXvmCg+bMeI9ag3qMCwB2mSpjJOhpS59QL6gmixkXr3E2DJ5PpFAsZdy2lwxZ44xThYJBab1iNxJTPLUc+1mp5gyEsqRM6FIFCN9/LSnvS2Qey2X5GHkHzcm3uhpKfGaNDUCm07nndA7p2Qm6yPyCa46oAg17dzw2sIvVeG91/puqqycZTefYGDiQ6SlnckEHppGrTxAAvJAPysgvFphtwKjm1UXPM/C2nhKnpauplN63vNqU1BRuaQy2t5aMJdXlOmKz1MzN6/euWkENkjE678nATZXSSGiPCGa5fIHHjPnKTInIerjg0 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:(13230040)(376014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:38.3761 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 352ee910-a6ed-4a7e-1d39-08dccf15d0d8 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: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7486 From: Alejandro Lucero The first stop for a CXL accelerator driver that wants to establish new CXL.mem regions is to register a 'struct cxl_memdev. That kicks off cxl_mem_probe() to enumerate all 'struct cxl_port' instances in the topology up to the root. If the root driver has not attached yet the expectation is that the driver waits until that link is established. The common cxl_pci_driver has reason to keep the 'struct cxl_memdev' device attached to the bus until the root driver attaches. An accelerator may want to instead defer probing until CXL resources can be acquired. Use the @endpoint attribute of a 'struct cxl_memdev' to convey when accelerator driver probing should be deferred vs failed. Provide that indication via a new cxl_acquire_endpoint() API that can retrieve the probe status of the memdev. Based on https://lore.kernel.org/linux-cxl/168592155270.1948938.11536845108449547920.stgit@dwillia2-xfh.jf.intel.com/ Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/memdev.c | 67 +++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/mem.c | 4 ++- include/linux/cxl/cxl.h | 2 ++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 5f8418620b70..d4406cf3ed32 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,8 @@ static DECLARE_RWSEM(cxl_memdev_rwsem); static int cxl_mem_major; static DEFINE_IDA(cxl_memdev_ida); +static unsigned short endpoint_ready_timeout = HZ; + static void cxl_memdev_release(struct device *dev) { struct cxl_memdev *cxlmd = to_cxl_memdev(dev); @@ -1163,6 +1166,70 @@ struct cxl_memdev *devm_cxl_add_memdev(struct device *host, } EXPORT_SYMBOL_NS_GPL(devm_cxl_add_memdev, CXL); +/* + * Try to get a locked reference on a memdev's CXL port topology + * connection. Be careful to observe when cxl_mem_probe() has deposited + * a probe deferral awaiting the arrival of the CXL root driver. + */ +struct cxl_port *cxl_acquire_endpoint(struct cxl_memdev *cxlmd) +{ + struct cxl_port *endpoint; + unsigned long timeout; + int rc = -ENXIO; + + /* + * A memdev creation triggers ports creation through the kernel + * device object model. An endpoint port could not be created yet + * but coming. Wait here for a gentle space of time for ensuring + * and endpoint port not there is due to some error and not because + * the race described. + * + * Note this is a similar case this function is implemented for, but + * instead of the race with the root port, this is against its own + * endpoint port. + */ + timeout = jiffies + endpoint_ready_timeout; + do { + device_lock(&cxlmd->dev); + endpoint = cxlmd->endpoint; + if (endpoint) + break; + device_unlock(&cxlmd->dev); + if (msleep_interruptible(100)) { + device_lock(&cxlmd->dev); + break; + } + } while (!time_after(jiffies, timeout)); + + if (!endpoint) + goto err; + + if (IS_ERR(endpoint)) { + rc = PTR_ERR(endpoint); + goto err; + } + + device_lock(&endpoint->dev); + if (!endpoint->dev.driver) + goto err_endpoint; + + return endpoint; + +err_endpoint: + device_unlock(&endpoint->dev); +err: + device_unlock(&cxlmd->dev); + return ERR_PTR(rc); +} +EXPORT_SYMBOL_NS(cxl_acquire_endpoint, CXL); + +void cxl_release_endpoint(struct cxl_memdev *cxlmd, struct cxl_port *endpoint) +{ + device_unlock(&endpoint->dev); + device_unlock(&cxlmd->dev); +} +EXPORT_SYMBOL_NS(cxl_release_endpoint, CXL); + static void sanitize_teardown_notifier(void *data) { struct cxl_memdev_state *mds = data; diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 39b20ddd0296..ca2c993faa9c 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -1554,7 +1554,7 @@ static int add_port_attach_ep(struct cxl_memdev *cxlmd, */ dev_dbg(&cxlmd->dev, "%s is a root dport\n", dev_name(dport_dev)); - return -ENXIO; + return -EPROBE_DEFER; } parent_port = find_cxl_port(dparent, &parent_dport); diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 5c7ad230bccb..56fd7a100c2f 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -145,8 +145,10 @@ static int cxl_mem_probe(struct device *dev) return rc; rc = devm_cxl_enumerate_ports(cxlmd); - if (rc) + if (rc) { + cxlmd->endpoint = ERR_PTR(rc); return rc; + } parent_port = cxl_mem_find_port(cxlmd, &dport); if (!parent_port) { diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index fc0859f841dc..7e4580fb8659 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -57,4 +57,6 @@ int cxl_release_resource(struct cxl_dev_state *cxlds, enum cxl_resource type); void cxl_set_media_ready(struct cxl_dev_state *cxlds); struct cxl_memdev *devm_cxl_add_memdev(struct device *host, struct cxl_dev_state *cxlds); +struct cxl_port *cxl_acquire_endpoint(struct cxl_memdev *cxlmd); +void cxl_release_endpoint(struct cxl_memdev *cxlmd, struct cxl_port *endpoint); #endif From patchwork Sat Sep 7 08:18:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795144 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2065.outbound.protection.outlook.com [40.107.236.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B61111586C7; Sat, 7 Sep 2024 08:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697188; cv=fail; b=kk9zr1Q6+AaTvFH6Ce3aM1PVGUX57yAVwtDcixkpQmP3TDfgIizxqEDf2Hexwa8Upy8oHQ3SsIwrQs3toG5xbfmTtjqWAYH4yDDYOYkIln0MGfmcark+I1RlZiNGLnbomlKj7pW1hTfJsDJlWdQfNYH68mQBZ71i2C4rhwZYeig= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697188; c=relaxed/simple; bh=Ejm9PQ0n7YzoouzOj7j/GQBQJ1EcEZS9jgksBJj4MYc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cfUBpdhfRuECcjnqOY8Hw4yANdGJIJHgR+eyAIm4ZOPEG1ElNdZHEPoGsTcOc4njU6NSlDxgeh5aRWZ8TVmvTU+x+WVWy7lBG30Og49BRJ6HzBGN1OmVEcl6CNYynWQyRqdbgQw3Hmb0u/UrEVFYD2ycQpuMVZNedEjPN2JzD7o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1Br27qmS; arc=fail smtp.client-ip=40.107.236.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="1Br27qmS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JtCZWPASOnQoxWGz0/pmRAO6EpEy9I1IiRM5VTBOXt4muBi8RMYKV+twnMXWfGq0miXZ2KOKzuAh2MmLyR5cTKNtlXLik7vUc3vMgj7to7qyOI4PuQggVhhPlww6nqyFU2uk99RfsZL1wpmOffGohtoEzAhSB/A33rpLhwhlfEjJV9FJca8hQj8U3ZmqlvQlXyfBUCjxMY9rSjp6lXZjmtXzbknWbbnmAxu23J5/ppG1TQF7OZJ1r7qJMpHJyFVIDRsPV/1322y/1jOyQ4abiQMHtr18ioAO2FNKtjWgtpGDE9Po9Nv36ATrkS+AIYB7u8j1ut9oAfgsSrCuktAS+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=o0wcPiin7P3XCLhVL9i7ZYhk6urUVeP1QUBpBE5NR6U=; b=rHiZCAEMWvwdxjsS6Q3vlZ3utpmAUCXhFDVlNaRjyEThnrtOabwE3EVzmA0HsU4nkSnEArGtBHOt3nD6jg9zVqetF3cTxoPfgHk/okF+8+9C34K2Fj1PLcuaiG4fupgRQjR3uMxvdSpGjCwnAP3Rcl/D9SWBphOYm0VIJkwnwnP7eMMD1OmztXnrPvylKxA5dr9MdCc+uw84YihFafSkCxf2CZsWyJ+Dvbe/VqdQZeRQd45d/2GqovrfwgURdzLVVRhwHc9pLxKJYs/WFgOuFMyGJ334Zk47N3Doi3dGrdH2Ky2jHVkkKzVYNd7DIFq4wnjKwVtjMmzoBUR+3epu4A== 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 (0) 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=o0wcPiin7P3XCLhVL9i7ZYhk6urUVeP1QUBpBE5NR6U=; b=1Br27qmS7EAk5AVqkrKhE4Bxj7fo8hWQnR2dD+FkF4LHb/UOuGbCUd1czJVCgoB0pzWBl9Xk8kOxmBxc1vmaUCmHrGYH7NpQM0EvrWhlQ0e2GkM1yZsxPm33BKG51q096aQlhrGsf4eaY60RAdpXeMyvhERLFgGh9A+enGosS0o= Received: from BYAPR01CA0024.prod.exchangelabs.com (2603:10b6:a02:80::37) by CY5PR12MB9055.namprd12.prod.outlook.com (2603:10b6:930:35::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Sat, 7 Sep 2024 08:19:41 +0000 Received: from MWH0EPF000989EC.namprd02.prod.outlook.com (2603:10b6:a02:80:cafe::98) by BYAPR01CA0024.outlook.office365.com (2603:10b6:a02:80::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Sat, 7 Sep 2024 08:19:40 +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 MWH0EPF000989EC.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:40 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:39 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:39 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:38 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 11/20] cxl: define a driver interface for HPA free space enumaration Date: Sat, 7 Sep 2024 09:18:27 +0100 Message-ID: <20240907081836.5801-12-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EC:EE_|CY5PR12MB9055:EE_ X-MS-Office365-Filtering-Correlation-Id: 4678b9ea-fcf8-4635-bebd-08dccf15d23e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: 1A14LeCMWezqx44hlq/BvGwCc486tiDx2+g9vjmhJpwv7+IoimJNKMlsgDGiAUx29wHX25HxqrNiYtx2YqaCTNpHUo2Zi6LkgS8o0nQ3KAVKIX2tXNnhN0UlP1JMWXqEtUxPMqjeiTW8v3epJs8ezJE64Z+Mb8nOAKkxF2tNSPSw/VZ2W0AfeSBOJDNLetiycILSA9H5M78vwGUHs/ZpZIANQ9WH0E2Xxmv76NJO2zPARPhB3h4QB1SZPUK0UsN0I1ssTxK5EjsjIr1FEQaNJafeZmurNO3pA6voRgnxzSaQ8Bpl3EKldEzvoO9lvhevGN3y7vsW2QLIxht7+lbINE7Z2th6p7pi9irupO8s/LK/9Kp+dHvijXSaeyznCirJgZi13n11XArUwFYWNZOvdLGBP2KbI+7vwgfjSKZDH+EdKSKVVcJRDGXAlyM3r7oGnviLBdAX4FutK9uPudcqBxv1Fq8lUJqoy3Bo9IkM0zzk6HTHMDsbGYdX+kEuDeBgvlAVHykIpjjvxUZrBTQaLLwG6f2/jVA3CGowUc4Z2I7+s41Bcqv/FCoUESY9W/LKM5O9/oMtn7PtUEGiLLHd3z/reDteLVcCY8GsGYSq1jsOa+fhvnZkaNMx/7mpZgsMh1vcykKX1pNetA6WiC7V5bgTjbY56iOh+SkTYH+aFu2wRgQBjPzIw02M/CPwpxSPL5r86+j65QLpw81sJOZB2kxZQA621tk1Mr4zNakwFbCsxnWiHYTf0f+ArIz67RTsnn2F0+GhpSbM1q92XZYd9MuEf+RQgeuuHS/d6sLclpIARoO/stfIzOVMXWH/Y9jts8tsXT6H+ygv7+01e9GdaZ7bRfdsZ/fgN66apkxQ5zH7nCkDwUykJe8rwR46Jv1oWKHbOXG+sCS3ZlVwb+M+XZwZfjlHz9JK1NPRbIhoHneTm+kDjhkW3dnASRWAaF1zRDPOfF29Dl1/OLlnLNICyxVveLEok2F+CTwY0h99X8awYgONOJcOZkvuKWV3fQK57u7WUE0KQXBPlwN1v2/Opvh0cSq/2knWAOA6jyVjU0va+hV4TtsxfqueyXQKm86lZiB561PPKKjLgYhC1/ppZbnkAc8CRI8QOHYKYYh51Qgk86OEFKTxgF/MAJJdwFVcxglKhUZDTfCzykeZq+fVJ5rx9fKXoQSdsEFj7AzKXyxK/DX6DDwzNeqtR9Siv2td1dHQHmIgKNGMKtJax+Wu5tZw/MOP41nyRwY4KiFoJTNZSdof2+ayo7Ugt7QdR+CE1WtU407RClyV8xHctTef8KtA/M1xExsLqglYVo4zWcTlcy7Rw5zkZLjAwp2QatUXhcBdBjkhQlImowkDO0XFVFrg23MdBKA/26jWE1KJQOfOAuq8+uhFTE7lcDQ2tBsyKpCIkIQX+OSaF0sMHUZjiGBzw9g0rdMNR51oOfE691+64c6pOlWsgvp2EIOo9iB7 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:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:40.6639 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4678b9ea-fcf8-4635-bebd-08dccf15d23e 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: MWH0EPF000989EC.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9055 From: Alejandro Lucero CXL region creation involves allocating capacity from device DPA (device-physical-address space) and assigning it to decode a given HPA (host-physical-address space). Before determining how much DPA to allocate the amount of available HPA must be determined. Also, not all HPA is create equal, some specifically targets RAM, some target PMEM, some is prepared for device-memory flows like HDM-D and HDM-DB, and some is host-only (HDM-H). Wrap all of those concerns into an API that retrieves a root decoder (platform CXL window) that fits the specified constraints and the capacity available for a new region. Based on https://lore.kernel.org/linux-cxl/168592159290.1948938.13522227102445462976.stgit@dwillia2-xfh.jf.intel.com/ Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/region.c | 141 ++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 3 + drivers/cxl/cxlmem.h | 3 + include/linux/cxl/cxl.h | 8 +++ 4 files changed, 155 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 21ad5f242875..bb227bf894c4 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -703,6 +703,147 @@ static int free_hpa(struct cxl_region *cxlr) return 0; } +struct cxlrd_max_context { + struct device *host_bridge; + unsigned long flags; + resource_size_t max_hpa; + struct cxl_root_decoder *cxlrd; +}; + +static int find_max_hpa(struct device *dev, void *data) +{ + struct cxlrd_max_context *ctx = data; + struct cxl_switch_decoder *cxlsd; + struct cxl_root_decoder *cxlrd; + struct resource *res, *prev; + struct cxl_decoder *cxld; + resource_size_t max; + + if (!is_root_decoder(dev)) + return 0; + + cxlrd = to_cxl_root_decoder(dev); + cxld = &cxlrd->cxlsd.cxld; + if ((cxld->flags & ctx->flags) != ctx->flags) { + dev_dbg(dev, "%s, flags not matching: %08lx vs %08lx\n", + __func__, cxld->flags, ctx->flags); + return 0; + } + + /* An accelerator can not be part of an interleaved HPA range. */ + if (cxld->interleave_ways != 1) { + dev_dbg(dev, "%s, interleave_ways not matching\n", __func__); + return 0; + } + + cxlsd = &cxlrd->cxlsd; + + guard(rwsem_read)(&cxl_region_rwsem); + if (ctx->host_bridge != cxlsd->target[0]->dport_dev) { + dev_dbg(dev, "%s, HOST BRIDGE DOES NOT MATCH\n", __func__); + return 0; + } + + /* + * Walk the root decoder resource range relying on cxl_region_rwsem to + * preclude sibling arrival/departure and find the largest free space + * gap. + */ + lockdep_assert_held_read(&cxl_region_rwsem); + max = 0; + res = cxlrd->res->child; + if (!res) + max = resource_size(cxlrd->res); + else + max = 0; + + for (prev = NULL; res; prev = res, res = res->sibling) { + struct resource *next = res->sibling; + resource_size_t free = 0; + + if (!prev && res->start > cxlrd->res->start) { + free = res->start - cxlrd->res->start; + max = max(free, max); + } + if (prev && res->start > prev->end + 1) { + free = res->start - prev->end + 1; + max = max(free, max); + } + if (next && res->end + 1 < next->start) { + free = next->start - res->end + 1; + max = max(free, max); + } + if (!next && res->end + 1 < cxlrd->res->end + 1) { + free = cxlrd->res->end + 1 - res->end + 1; + max = max(free, max); + } + } + + dev_dbg(CXLRD_DEV(cxlrd), "%s, found %pa bytes of free space\n", + __func__, &max); + if (max > ctx->max_hpa) { + if (ctx->cxlrd) + put_device(CXLRD_DEV(ctx->cxlrd)); + get_device(CXLRD_DEV(cxlrd)); + ctx->cxlrd = cxlrd; + ctx->max_hpa = max; + dev_dbg(CXLRD_DEV(cxlrd), "%s, found %pa bytes of free space\n", + __func__, &max); + } + return 0; +} + +/** + * cxl_get_hpa_freespace - find a root decoder with free capacity per constraints + * @endpoint: an endpoint that is mapped by the returned decoder + * @flags: CXL_DECODER_F flags for selecting RAM vs PMEM, and HDM-H vs HDM-D[B] + * @max_avail_contig: output parameter of max contiguous bytes available in the + * returned decoder + * + * The return tuple of a 'struct cxl_root_decoder' and 'bytes available (@max)' + * is a point in time snapshot. If by the time the caller goes to use this root + * decoder's capacity the capacity is reduced then caller needs to loop and + * retry. + * + * The returned root decoder has an elevated reference count that needs to be + * put with put_device(cxlrd_dev(cxlrd)). Locking context is with + * cxl_{acquire,release}_endpoint(), that ensures removal of the root decoder + * does not race. + */ +struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_port *endpoint, + unsigned long flags, + resource_size_t *max_avail_contig) +{ + struct cxlrd_max_context ctx = { + .host_bridge = endpoint->host_bridge, + .flags = flags, + }; + struct cxl_port *root_port; + struct cxl_root *root __free(put_cxl_root) = find_cxl_root(endpoint); + + if (!is_cxl_endpoint(endpoint)) { + dev_dbg(&endpoint->dev, "hpa requestor is not an endpoint\n"); + return ERR_PTR(-EINVAL); + } + + if (!root) { + dev_dbg(&endpoint->dev, "endpoint can not be related to a root port\n"); + return ERR_PTR(-ENXIO); + } + + root_port = &root->port; + down_read(&cxl_region_rwsem); + device_for_each_child(&root_port->dev, &ctx, find_max_hpa); + up_read(&cxl_region_rwsem); + + if (!ctx.cxlrd) + return ERR_PTR(-ENOMEM); + + *max_avail_contig = ctx.max_hpa; + return ctx.cxlrd; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_hpa_freespace, CXL); + static ssize_t size_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 07c153aa3d77..5d83e4a960ef 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -772,6 +772,9 @@ static inline void cxl_setup_parent_dport(struct device *host, struct cxl_decoder *to_cxl_decoder(struct device *dev); struct cxl_root_decoder *to_cxl_root_decoder(struct device *dev); struct cxl_switch_decoder *to_cxl_switch_decoder(struct device *dev); + +#define CXLRD_DEV(cxlrd) (&(cxlrd)->cxlsd.cxld.dev) + struct cxl_endpoint_decoder *to_cxl_endpoint_decoder(struct device *dev); bool is_root_decoder(struct device *dev); bool is_switch_decoder(struct device *dev); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 37c043100300..07259840da8f 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -875,4 +875,7 @@ struct cxl_hdm { struct seq_file; struct dentry *cxl_debugfs_create_dir(const char *dir); void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); +struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_port *endpoint, + unsigned long flags, + resource_size_t *max); #endif /* __CXL_MEM_H__ */ diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 7e4580fb8659..60a32f60401f 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -7,6 +7,10 @@ #include #include +#define CXL_DECODER_F_RAM BIT(0) +#define CXL_DECODER_F_PMEM BIT(1) +#define CXL_DECODER_F_TYPE2 BIT(2) + enum cxl_resource { CXL_ACCEL_RES_DPA, CXL_ACCEL_RES_RAM, @@ -59,4 +63,8 @@ struct cxl_memdev *devm_cxl_add_memdev(struct device *host, struct cxl_dev_state *cxlds); struct cxl_port *cxl_acquire_endpoint(struct cxl_memdev *cxlmd); void cxl_release_endpoint(struct cxl_memdev *cxlmd, struct cxl_port *endpoint); + +struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_port *endpoint, + unsigned long flags, + resource_size_t *max); #endif From patchwork Sat Sep 7 08:18:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795145 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2058.outbound.protection.outlook.com [40.107.237.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65E1D14A614; Sat, 7 Sep 2024 08:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697188; cv=fail; b=n8WGC7F6DhNbVhqvooaJxfcsbtgLcLyxqi8Gj/qw094SUFZop0JLe7wetAt8LkKtd7aZcoXLoA+2rsshB10eUdM6+8+UhEyQC9/4UpazBeHnjPjkWEVGJC98dH9Dmxm3VBfMBaF+zeE9EyQfm2iuJutQzTtYVm9gHghOb9bn2lI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697188; c=relaxed/simple; bh=zpOhnuV6wciXcR0wGiNV9mTU7N4hXUkLkP9Fsv6jD5g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IlXcO+Qpm9e17Dnibig7ZOsimFEelR4XpkhUrAheDMv3JcY8e7DJkJZkh0kFy7QJgo6G/IvuWuyUGOr0IWCDnknv4lnqX6LeRZnqFeNWnLxlqBhOZGy+yTUoer/DurZIEUpRTQOcFuW4oPuWVzUzOTKPEXMOcFfRcm415en1I4k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=u5BCLBgR; arc=fail smtp.client-ip=40.107.237.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="u5BCLBgR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sQ2tQhrGzR78BaXKFv8zZh0glOTKq1D4/EdiFw7bwvylRfyK7IvQ8SOB6XvPgQQo7oqIF+NwZpoPKw6WyARSkCAZz0DfMH2CNN0iVUaZulFrDe4Kq4z5US02VaXY9whxfJErRWL/UWGg9nWAv16Yhb9bh3VzQN0fKJ3/K3etmYCU/RBAFSIPTBBVlmJpCDSc4aU5yJi67cjCwzYirZTtJ736h/YouY7ugTKESO6LQfwvsbEAU5z8tufszoo0q30Gog4LH4PJT2pqLJAkVRoL1qRgWP4DNL6z9dXVPbulQJF6P03y5vMLkFFhV+8Rhf2QnF/PlQzneVpexC45eJlB9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=vBMb4Hln9DJcXSpvaKraVH2Nm4a1Lr5PFzU8XJIPHCI=; b=w1RmDuhc+RoaIt7q4ChByiVhjgv6AXLeuwyFGSa8Xqm3vDznVVW2VEbZuYGA2MKPXDNIQ7/Gz7WR7akcPulQGzUdo5gGa5EjIdXvbhqzuTDGVLeR2QJawUsMMFmAldTxKrECfnqEv5dGWG00YQ4Zi0qjA4ax0E7WQpPZz6X+gl86KlNWWz9T3Gb+LmpvilIqy3DbwU6PjTtsij1Oqq0KQp2MzXvbxiqSw6mvLHS62XwGawMBWs13pi8pxIcLy183IRjeOMcfSGn0/wR/t4wjvPdlVcCMEJXYBP2jWqfQ5p/UrFtWoiMAlUrwODSugsDy4za6Kwoaa6cwKaY6YhJ6pA== 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 (0) 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=vBMb4Hln9DJcXSpvaKraVH2Nm4a1Lr5PFzU8XJIPHCI=; b=u5BCLBgRxDcr1YDIa9xSbJflLdl73S9myHYn72s6/j9LU0b4Fu65geFwuGitzwAjPEH33JaVrwq4nLU5Pw6d4uyrYY6IAB09Zhd6kaBnDpByrfFu+YAud4WrabIm/JlbkLwyZ0xACdBH/CCsA+ZInpXXuOiHtzYJ0Izgagxf8aQ= Received: from DS7PR03CA0210.namprd03.prod.outlook.com (2603:10b6:5:3b6::35) by SN7PR12MB7369.namprd12.prod.outlook.com (2603:10b6:806:298::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Sat, 7 Sep 2024 08:19:42 +0000 Received: from DS1PEPF0001709B.namprd05.prod.outlook.com (2603:10b6:5:3b6:cafe::bb) by DS7PR03CA0210.outlook.office365.com (2603:10b6:5:3b6::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Sat, 7 Sep 2024 08:19:42 +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 DS1PEPF0001709B.mail.protection.outlook.com (10.167.18.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:42 +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.2507.39; Sat, 7 Sep 2024 03:19:41 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:41 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:40 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 12/20] efx: use acquire_endpoint when looking for free HPA Date: Sat, 7 Sep 2024 09:18:28 +0100 Message-ID: <20240907081836.5801-13-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709B:EE_|SN7PR12MB7369:EE_ X-MS-Office365-Filtering-Correlation-Id: fb706f70-3c4c-4c12-07cf-08dccf15d358 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: qEi5EjzDPjnZqKKrq+jTbOTS+AzaBa59TMve02Qy4PMRUn/HefHSCBroxsN6Dnh0KYxHtmfwGVFgwpQGzawXqs1TBs2xX75EHaJpGESWfydFmpmBUaA/ij/4l3oqSBhyjtEMAHELIYIrHtyMTT/nmPNsuk5KtipjglXesONTvsoSpUydFTeL9iSmWkMjjxQjY5I7VMvcQFcJd1hDnTvwJ70rvLKr0iYdROl2Sy9Ey0gicQFhDDlv9h6z8tDHd8wTd09ZAfcPJP+gLSKSqez5ScjxrG0nzIEL0afQN8E86Go1nzygNUJcLc9ncHK/cib0/HhrfHC68t9kwjR9Tn1HUEmmOYlU/OVIt+zwNM018zbRrz1mPheK94J3yximncdzjDSwbz5etXZ2Yhlcq9gvc5Vw1dMRC0u/M8Lk/J2h7MZFXuRc8Xtd4maJYhvl7TUTbjkTNcFyET+Ua+RopJvK4k2WTOcXvZAKXvmycIESAEqiSB4siPyqAi2jZr1qvKDZrGc1RMzcROHRtuQVgY7ewwtjHJasDYDsT9Pml/RkkYk6OHl6dYuW4BP57XQ+Li4uOcXipzR0zYq2ZaiPFb7xwGvvUqScl4tpwd2P99lSV5xOwA0fCFTAzyHYD7OqY59MV75TsOv9qKA6vzi5tLwhdT2g17PfAV45wOJNQnP3Lbj9XGec4vdFH2G7ZEZDYQj21XlzTiHixUbCANbJgBMB8VVlpt6DjyH8SPxMp35svo8WQ7G73B9ynmkODUTJ9si98gcb6+d5PkQV9R5mZrG4KBG9h7fLxliBsv2XMO+GA8wQz/GymnnUXwDlq2AdCAFcdIQNgbst1vmtDIUKuLSNIT7mBJ8FCC49aUZFXQCkIFkD5SQDUmuG7nixFCx3/b9uaDu10myYjpgKO0vV00l9DmvSoql97N63gCuwdWy/+7OhstzDUqTcCHlXDCyYD2NZb4Hb3HGyNqI16IwITOO2yJ37hcKP9gZJHDEE5iElLcIUK301m/e6lBQ903W9KgVxuP74CY+XWLyjZ2GjjWEDBm21+wu6bI8oMkt9oir41VrXP6bRsx7qMN5HQ0EoEzKjnt/5a9nhpknDJw4YgrwHnqqYVFdfHVfw51ifi9jw4lEyoSmVJNWzeAH3faqIyJ+Vk1lBbzqe6idv+tDN3W+gCifjlT7VCT5s0Q/m/WsmkQSr0Hni9oGJfejEP9pLG1Aku64jgGOXaXBB7zDqPECTL6ncEspOYFmm8kVQKTn+0w2/OZhTtV/7dh7mBk91gIyoyA3eRqvHaLPPXL3snllWF1YEYxq0JHEubVTI23RdIrQkiPVtFWwQ2N7xPBL6HQ8arAuT7iL6JUoQ2jH+7KgOk4JlDOjJDJqe+pNNfsTEGxhDf8OyG9IgBFcfDqXnIyxmFw0HNRn58Qc4+x80Fq+foMxsfZ8vBU/D4Op7dqbMFISxh+1XgyqmBbxXrL+u+kar 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:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:42.5698 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb706f70-3c4c-4c12-07cf-08dccf15d358 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: DS1PEPF0001709B.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7369 From: Alejandro Lucero Asking for availbale HPA space is the previous step to try to obtain an HPA range suitable to accel driver purposes. Add this call to efx cxl initialization and use acquire_endpoint for avoiding potential races with cxl port creation. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/efx.c | 8 +++++++- drivers/net/ethernet/sfc/efx_cxl.c | 32 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c index 3a7406aa950c..08a2f527df16 100644 --- a/drivers/net/ethernet/sfc/efx.c +++ b/drivers/net/ethernet/sfc/efx.c @@ -1117,10 +1117,16 @@ static int efx_pci_probe(struct pci_dev *pci_dev, * used for PIO buffers. If there is no CXL support, or initialization * fails, efx_cxl_pio_initialised wll be false and legacy PIO buffers * defined at specific PCI BAR regions will be used. + * + * The only error to handle is -EPROBE_DEFER happening if the root port + * is not there yet. */ rc = efx_cxl_init(efx); - if (rc) + if (rc) { + if (rc == -EPROBE_DEFER) + goto fail2; pci_err(pci_dev, "CXL initialization failed with error %d\n", rc); + } rc = efx_pci_probe_post_io(efx); if (rc) { diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 899bc823a212..826759caa552 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -23,6 +23,7 @@ int efx_cxl_init(struct efx_nic *efx) struct pci_dev *pci_dev = efx->pci_dev; struct efx_cxl *cxl; struct resource res; + resource_size_t max; u16 dvsec; int rc; @@ -90,7 +91,38 @@ int efx_cxl_init(struct efx_nic *efx) goto err; } + cxl->endpoint = cxl_acquire_endpoint(cxl->cxlmd); + if (IS_ERR(cxl->endpoint)) { + rc = PTR_ERR(cxl->endpoint); + if (rc != -EPROBE_DEFER) { + pci_err(pci_dev, "CXL accel acquire endpoint failed"); + goto err; + } + } + + cxl->cxlrd = cxl_get_hpa_freespace(cxl->endpoint, + CXL_DECODER_F_RAM | CXL_DECODER_F_TYPE2, + &max); + + if (IS_ERR(cxl->cxlrd)) { + pci_err(pci_dev, "cxl_get_hpa_freespace failed\n"); + rc = PTR_ERR(cxl->cxlrd); + goto err_release; + } + + if (max < EFX_CTPIO_BUFFER_SIZE) { + pci_err(pci_dev, "%s: no enough free HPA space %llu < %u\n", + __func__, max, EFX_CTPIO_BUFFER_SIZE); + rc = -ENOSPC; + goto err; + } + + cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); + return 0; + +err_release: + cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); err: kfree(cxl->cxlds); kfree(cxl); From patchwork Sat Sep 7 08:18:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795146 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2083.outbound.protection.outlook.com [40.107.101.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034F014AD22; Sat, 7 Sep 2024 08:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697192; cv=fail; b=CrvaQ7cXMpyQdGuFz1VXL/nzu7MiX4PbdHhkMNXA8fFf4Mzy8hpLMs80fKzg+zsjM2zTN2GvAczw7M68DytwD6Fj0NtoaViusx4ZhIeGBp+gogjamUcXNMaat/TP3gtVnWjSipoVYkolAsR0mdMljOB3Sd392KtrwB7sFSNIUEE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697192; c=relaxed/simple; bh=NMDKmCMmDP2HOl0Wzb9WsNa1tnuy0FCCRw2rBLEQl3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M1CVdOF3RUqUt9VNvom+JsbDPrzbiLUlWaI/a/wWjnYNkut6rtgsK4pGTg15dFYtzKI5IpKzOarjD/JNtkyRaWGNYp1y+aw5dgopcZedLmYw0lOAfwqGijO8dI0XLr06X7+bsvi2qC42iZlVQTLtwM/ZmQx9hy14aRiHXxlWGec= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=z9dsAZwZ; arc=fail smtp.client-ip=40.107.101.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="z9dsAZwZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eTESdCkJlwhduMd+n/fENfEHPs03dMuxCQtzeffsGxtvgyi77k85cYbIWRpk57sbfRs3X5WL6Auz4AxyVQ5MVWLCY9yKvLu8b5XJIdf9Kg3+8pYL+ZvuUlPlAJXCILcaoaOc8jNP//1fhp0EnAbBgMbUP9TtFhDAYBjvf1Sr/L0NG3wDzV4dZsc1loqWTDEhEwjgtX1Yd2S9dajnLgon/ffrki5i+s7K/4LDuSksq/f5Gtm9jA1dBl2VxcECwza5XwVUytMjjbh2PIlIUaQqlJMt81ulKmjTUutlkV0prw+KgKBRH+H6EZag6glvv1lHq8OvDZbqq5FXEOGy+zu4IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=9w4TrBvPOtvcnfy91SlHDCbID1qMXwCEVL7yytr9VOE=; b=WeHBxNnIFdNHMbLmL38aRVDUts7jNY4/vZ9/iHRxM47FMDusjW8au6GG3w79VIlRABOnGiMsNYoL9nwK78XQGaqoiBcfkFwRM8VXaVre1jfd6s9Rf2YASpIoAWvXTLBodDpLDvLXWLKjUGxFnIznCTRrELTE6Rb9Z2vzUvDlf6C7gke5eQ3MLvMdwxtUMrCnSqz5YRE2aU9UEvzwjTmU0IqJ6DVV4GvJERFEeppV9MILqo7csb0Xxvcf+SLrGD2tQlgUzU29tu+OIl3Jtu5jPJxjMq4vK13L0BYo1rBgQHgXBBJF85eEyHiwouNBSl8jYtiduEHN/ZSFYvzzA6wE7Q== 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 (0) 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=9w4TrBvPOtvcnfy91SlHDCbID1qMXwCEVL7yytr9VOE=; b=z9dsAZwZeyw3Ugrg9Dl3lzevWRuc3jGZt559R6KSoz07RYtLtapwel19yPOkiWj46SuQHkcUnpQwC+XCEBWAsb2fTvOEBoEpUW/CID0WYQOklucdtQKl50m0HZF/G41yfr2anolZgDxWY8VqIt5nyqiQGUy58mD3uocb2Ri09qI= Received: from DM6PR02CA0135.namprd02.prod.outlook.com (2603:10b6:5:1b4::37) by BL1PR12MB5996.namprd12.prod.outlook.com (2603:10b6:208:39c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Sat, 7 Sep 2024 08:19:44 +0000 Received: from DS1PEPF0001709A.namprd05.prod.outlook.com (2603:10b6:5:1b4:cafe::1d) by DM6PR02CA0135.outlook.office365.com (2603:10b6:5:1b4::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Sat, 7 Sep 2024 08:19: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 DS1PEPF0001709A.mail.protection.outlook.com (10.167.18.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:44 +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.2507.39; Sat, 7 Sep 2024 03:19:43 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:43 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:42 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 13/20] cxl: define a driver interface for DPA allocation Date: Sat, 7 Sep 2024 09:18:29 +0100 Message-ID: <20240907081836.5801-14-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709A:EE_|BL1PR12MB5996:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b3b9c36-8b5f-4738-d9ac-08dccf15d47c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: c40h1b/aK1Xxmzy/Qs7Ts3LpH5sL0tzQ0R7Py6CIE50pn6oFmRgp77MetCmFQZ7Dxpzps8ad90CACT9s7sac/ohBWzBpckvpiZvaYlh9csY31F1lfHqDRFLeoB7jijn3EcFoOojplK5d9n7CWNp0ABBbCXh2wUJ5WSR/l8G8l8IKZgeF4I9NoP58f0kW+oVzi//pCtLrceuBNcRtpWzSRYIXUKOO9YNoElTPSOqJaeWMz+x7p5MHV2QJVBABpiomr4hl9Qjuey6tH64trbz460JJn2nt/JKFOgzXG0QpxtiAC7okj4+/Rcw5/rJH+1I9zUGxkpUdMccLKTrU0WS7aXIUwTfsWlpQXCai8EzB17xHKn2IikYauOPnoD/TvxeM9fhuuG8HNqZNFcnghCPz2ORTzynhoh6tkY0m1bZCyZ6Dc+mH51+JH1hixA07j+yeMIGTutdWkRlXDy6QBCmb5D6RekfFZx1H013rm/sgG62BbuWZoD2nWdGXvvYSB213GcBtL4YcPKHO3g0Ha2JvkmtJ9D0fS2DDJTiZ908+2YIR5p+sd5Vjw0vWcHzQaWrmf+b4x0Wsy3dgrZaMt290YEGeByeEmUILs2QwQrpYp0jO7Qg1uxF3og4A3Z2kRR2csr3r5602qNO0PPHOKYEbruM0iWEC5ILfB7IKW9ar1eRBWPPko20bJYi3UUeUfcJsOsQFIRz6qYlJR3WbgL9oTl2ojf5wqDesdKsgAVAGezbJWa5+302J9mJTReYM6Vvd6dYgepo9gqHyNbUsazDO7L3N0xQ8iH3xG40/BQxuV2f3YxYVBUYbhIYO20iPQYokQuWRX1tpYq+1kvcJahuyf98qMHYRQAT8EbbOwuD6freQALMbdu6+OV4J19XOX2UEBb+UE2MaARcY3kQ4PN4vmrm1z1CFNVj9QsKwbQjckYRA58vwem2zEqXhkDr/x1n0Fb45kFSW8Txzt15iJ8EMWaUosyUGDL/KQgnHAwM4MFOshY8JmPzrIjsKh6EuisOoM+mVZj0WZ5ta/f9W41o2yZkg14bh3uqLZtrDtzglglz/kJftwMub1WqvLHYTmxeYkj/ZHuOrMyjW+lxDk8iizulhbQqLS++kw8dhrD1IPRwXAqF0wPYd8WPElOZOokI40jPnviLgNpMkUlt9KQg7ZlYSIcgjz33FMKHrYzbfaHG6yl5vlkYSmQdzMYq4xNJc8G/OLYuBcn/F4ytuW/BkVIUquW3KuGxo5x4K3+J7HpkubK0u+N1Wu2A3H4UIppSo/RptGao2UWhduc3LMrjt0bdo8njbs1Ej+h8y3zaponZTgQAGn+xfOzySN3P/5eTGPjK5gBKTJeCHr+HqbfHfiFczBToSrMwB/Qr411t+vB7hjqQKI9ykDO0L0ATa7Y7ZDU+wqCs1ZR+El10y7PNxsFXa4KQuXSvpimFa+dNO1NFUi8JTyCvCjizg5Lk+yUE3 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:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:44.5045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b3b9c36-8b5f-4738-d9ac-08dccf15d47c 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: DS1PEPF0001709A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5996 From: Alejandro Lucero Region creation involves finding available DPA (device-physical-address) capacity to map into HPA (host-physical-address) space. Given the HPA capacity constraint, define an API, cxl_request_dpa(), that has the flexibility to map the minimum amount of memory the driver needs to operate vs the total possible that can be mapped given HPA availability. Factor out the core of cxl_dpa_alloc, that does free space scanning, into a cxl_dpa_freespace() helper, and use that to balance the capacity available to map vs the @min and @max arguments to cxl_request_dpa. Based on https://lore.kernel.org/linux-cxl/168592158743.1948938.7622563891193802610.stgit@dwillia2-xfh.jf.intel.com/ Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/hdm.c | 153 +++++++++++++++++++++++++---- drivers/net/ethernet/sfc/efx_cxl.c | 9 ++ include/linux/cxl/cxl.h | 5 + 3 files changed, 147 insertions(+), 20 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 953a5f86a43f..1d034ef7bee3 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "cxlmem.h" #include "core.h" @@ -418,6 +419,7 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled) up_write(&cxl_dpa_rwsem); return rc; } +EXPORT_SYMBOL_NS_GPL(cxl_dpa_free, CXL); int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, enum cxl_decoder_mode mode) @@ -465,31 +467,18 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, return rc; } -int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) +static resource_size_t cxl_dpa_freespace(struct cxl_endpoint_decoder *cxled, + resource_size_t *start_out, + resource_size_t *skip_out) { struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); resource_size_t free_ram_start, free_pmem_start; - struct cxl_port *port = cxled_to_port(cxled); struct cxl_dev_state *cxlds = cxlmd->cxlds; - struct device *dev = &cxled->cxld.dev; resource_size_t start, avail, skip; struct resource *p, *last; - int rc; - - down_write(&cxl_dpa_rwsem); - if (cxled->cxld.region) { - dev_dbg(dev, "decoder attached to %s\n", - dev_name(&cxled->cxld.region->dev)); - rc = -EBUSY; - goto out; - } - if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { - dev_dbg(dev, "decoder enabled\n"); - rc = -EBUSY; - goto out; - } + lockdep_assert_held(&cxl_dpa_rwsem); for (p = cxlds->ram_res.child, last = NULL; p; p = p->sibling) last = p; if (last) @@ -526,14 +515,45 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) skip_end = start - 1; skip = skip_end - skip_start + 1; } else { - dev_dbg(dev, "mode not set\n"); - rc = -EINVAL; + avail = 0; + } + + if (!avail) + return 0; + if (start_out) + *start_out = start; + if (skip_out) + *skip_out = skip; + return avail; +} + +int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) +{ + struct cxl_port *port = cxled_to_port(cxled); + struct device *dev = &cxled->cxld.dev; + resource_size_t start, avail, skip; + int rc; + + down_write(&cxl_dpa_rwsem); + if (cxled->cxld.region) { + dev_dbg(dev, "EBUSY, decoder attached to %s\n", + dev_name(&cxled->cxld.region->dev)); + rc = -EBUSY; goto out; } + if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { + dev_dbg(dev, "EBUSY, decoder enabled\n"); + rc = -EBUSY; + goto out; + } + + avail = cxl_dpa_freespace(cxled, &start, &skip); + if (size > avail) { dev_dbg(dev, "%pa exceeds available %s capacity: %pa\n", &size, - cxl_decoder_mode_name(cxled->mode), &avail); + cxled->mode == CXL_DECODER_RAM ? "ram" : "pmem", + &avail); rc = -ENOSPC; goto out; } @@ -548,6 +568,99 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled); } +static int find_free_decoder(struct device *dev, void *data) +{ + struct cxl_endpoint_decoder *cxled; + struct cxl_port *port; + + if (!is_endpoint_decoder(dev)) + return 0; + + cxled = to_cxl_endpoint_decoder(dev); + port = cxled_to_port(cxled); + + if (cxled->cxld.id != port->hdm_end + 1) + return 0; + + return 1; +} + +/** + * cxl_request_dpa - search and reserve DPA given input constraints + * @endpoint: an endpoint port with available decoders + * @is_ram: DPA operation mode (ram vs pmem) + * @min: the minimum amount of capacity the call needs + * @max: extra capacity to allocate after min is satisfied + * + * Given that a region needs to allocate from limited HPA capacity it + * may be the case that a device has more mappable DPA capacity than + * available HPA. So, the expectation is that @min is a driver known + * value for how much capacity is needed, and @max is based the limit of + * how much HPA space is available for a new region. + * + * Returns a pinned cxl_decoder with at least @min bytes of capacity + * reserved, or an error pointer. The caller is also expected to own the + * lifetime of the memdev registration associated with the endpoint to + * pin the decoder registered as well. + */ +struct cxl_endpoint_decoder *cxl_request_dpa(struct cxl_port *endpoint, + bool is_ram, + resource_size_t min, + resource_size_t max) +{ + struct cxl_endpoint_decoder *cxled; + enum cxl_decoder_mode mode; + struct device *cxled_dev; + resource_size_t alloc; + int rc; + + if (!IS_ALIGNED(min | max, SZ_256M)) + return ERR_PTR(-EINVAL); + + down_read(&cxl_dpa_rwsem); + + cxled_dev = device_find_child(&endpoint->dev, NULL, find_free_decoder); + if (!cxled_dev) + cxled = ERR_PTR(-ENXIO); + else + cxled = to_cxl_endpoint_decoder(cxled_dev); + + up_read(&cxl_dpa_rwsem); + + if (IS_ERR(cxled)) + return cxled; + + if (is_ram) + mode = CXL_DECODER_RAM; + else + mode = CXL_DECODER_PMEM; + + rc = cxl_dpa_set_mode(cxled, mode); + if (rc) + goto err; + + down_read(&cxl_dpa_rwsem); + alloc = cxl_dpa_freespace(cxled, NULL, NULL); + up_read(&cxl_dpa_rwsem); + + if (max) + alloc = min(max, alloc); + if (alloc < min) { + rc = -ENOMEM; + goto err; + } + + rc = cxl_dpa_alloc(cxled, alloc); + if (rc) + goto err; + + return cxled; +err: + put_device(cxled_dev); + return ERR_PTR(rc); +} +EXPORT_SYMBOL_NS_GPL(cxl_request_dpa, CXL); + static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl) { u16 eig; diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 826759caa552..57667d753550 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -117,6 +117,14 @@ int efx_cxl_init(struct efx_nic *efx) goto err; } + cxl->cxled = cxl_request_dpa(cxl->endpoint, true, EFX_CTPIO_BUFFER_SIZE, + EFX_CTPIO_BUFFER_SIZE); + if (IS_ERR(cxl->cxled)) { + pci_err(pci_dev, "CXL accel request DPA failed"); + rc = PTR_ERR(cxl->cxlrd); + goto err_release; + } + cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); return 0; @@ -134,6 +142,7 @@ int efx_cxl_init(struct efx_nic *efx) void efx_cxl_exit(struct efx_nic *efx) { if (efx->cxl) { + cxl_dpa_free(efx->cxl->cxled); cxl_release_resource(efx->cxl->cxlds, CXL_ACCEL_RES_RAM); kfree(efx->cxl->cxlds); kfree(efx->cxl); diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 60a32f60401f..3250342843e4 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -67,4 +67,9 @@ void cxl_release_endpoint(struct cxl_memdev *cxlmd, struct cxl_port *endpoint); struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_port *endpoint, unsigned long flags, resource_size_t *max); +struct cxl_endpoint_decoder *cxl_request_dpa(struct cxl_port *endpoint, + bool is_ram, + resource_size_t min, + resource_size_t max); +int cxl_dpa_free(struct cxl_endpoint_decoder *cxled); #endif From patchwork Sat Sep 7 08:18:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795147 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2049.outbound.protection.outlook.com [40.107.237.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C83C14A614; Sat, 7 Sep 2024 08:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697193; cv=fail; b=RDtSK5bg2smP5QZFC274xHyCGQXiY5kzSTjFudUBVx7qKXEgrscUs8fdmAVOns9p2MAzjgt8TNGbt2wWlFEcqnIfxd57igIACkGRy9RMKxv5XCgATPfZDLrPOnOae7v6ijcMrJ5qGwjcqmu/6vGpAl14Z9F9nVRVoHtRy0r3Glc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697193; c=relaxed/simple; bh=OEoxtDUOdCUgkvfkC0F2pDkPqVNtXDSyghHUEs/WVts=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BM6j3rnzyrnLAswrs7m6r1kRJ8x7aRaC1Wu/an/VLUsLUcH58PKaXNE4ir7c734oYSqu+34mue6RPuqPaRhgIok1Ht6/Na4YyVJbhMzZNMzRF1q3x9HRfGoBI+jt4ipZyKHm/snmFRa01JrGrc0wOKL91uGdReSFD+f4JkSIzNU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=iSCZTpcN; arc=fail smtp.client-ip=40.107.237.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="iSCZTpcN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=k9NTfT//Vxkk5lHUA8UIV+f1OszlG1apMp6HRwm/taIlsaern3II2x91B19tAPQkLW9YLO2Cd48OnKYLJmn1s+FHKOpNg+R9EpMQEjOvhVgIO02jiPKYjBaQlcO0XSdm37f9qzP+G2w4LwPQa1MW9jrX5A5mD/rtH6tjmA41OD0R9sq6j/XyODXwXgAKOaS0A5u5h014T5LHyqiI6nTeWp4ehZ2ZnBzb9QBNKvsQKywI+o8Bh6SobX95KqlP/v21ojcx3uceUEYm2WiehWy2CqrQ18GK1m0aZPTHat6f0jRpPCUc3wjaApZKXT+ncbg4LX7Fh45aiQk6GDUPIM6hug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=6KracG6sScg50+g9r9McAM4i1z1hE4Kt5z0lhBGyXv0=; b=U9e7QXM5wfuDRVYrphUTfB8i6sZUeDK5rcLISDP32+tiq3++rJKZG1dlXx3pJrBUn9naRmZ8kRG3cFFB/YOwy205jwbkmkXxVhua9H4hHcxfqDOk9rbgw1mBR71XZfVzhTIx9loyAkg9I8vgCIcJKjhx6r+7IA9RjxetWbFF/e5i0bYQVjPlO3Fbo9kLT1Vm+NizEpfP5Sq9eOcmdJrSq3RG4mNeBGpLzY5yU2CAJB2CG9FR2ZIiL2PPLISFJeHUjM+x3IzFddiFgwgxuoJ5uGG7wF4RfaO02MBUGF/sNwWRYj/yrCKWPj1GcqMzW9zlTUgdgZbapy/pA1L/M6IsQA== 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 (0) 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=6KracG6sScg50+g9r9McAM4i1z1hE4Kt5z0lhBGyXv0=; b=iSCZTpcNtGFTNkj9Lkq7EqYQCXKhD1SjaIjdhbtKxK06+PWyxhE83WjetPmuL47MsSiVGO8tihgCKPW1t+UQ30GJQg07M1nWvvZRl6K+MYHwV48pDp2JmC1tITEJ20UItXKFVVWhtZeZ8XuWSrYX4dXaOKF+3B01vjSMZ42138c= Received: from BYAPR01CA0032.prod.exchangelabs.com (2603:10b6:a02:80::45) by SJ0PR12MB8167.namprd12.prod.outlook.com (2603:10b6:a03:4e6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Sat, 7 Sep 2024 08:19:47 +0000 Received: from MWH0EPF000989EC.namprd02.prod.outlook.com (2603:10b6:a02:80:cafe::87) by BYAPR01CA0032.outlook.office365.com (2603:10b6:a02:80::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Sat, 7 Sep 2024 08:19:47 +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 MWH0EPF000989EC.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:46 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:45 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:45 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:44 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 14/20] cxl: make region type based on endpoint type Date: Sat, 7 Sep 2024 09:18:30 +0100 Message-ID: <20240907081836.5801-15-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989EC:EE_|SJ0PR12MB8167:EE_ X-MS-Office365-Filtering-Correlation-Id: 31fb90a9-882d-47c0-cf00-08dccf15d5db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: /NaiBd3E/IKeRnRrEqbgc3giXPvcx1Jedv4fXoqExty+fAYq5JQNmOvbW6PmIoWJed+bqknqWlIo24SW3KQSViFBTwOnjWHjXIYtO9csyb9eMTmVD8Fr0QmUoJEhqLwtoqf2JdUTpjo0GKcxwhcROEHJ7Eug2N9wnHv9rmA+7XAdGhbmEzhWSeilMUq1ZJcopSQeQ9+xQHqAenCC5H+h2uF59KXZM0AJQ5Bnyjb0KsfGl0rG3Zz7H7l7rJvomGQPZGh3kD27j4IWzld8rv2OF940OVa9Fg7i3Qz1qCRQeP7osHVdU76lpmVcCVx0l/aUleNA54ztvTGS3t2AIS8Xwxj5H3g2CPyvYANGeunjTSCKIz+Tf8HRHkBEYO0QIE4QbNcyeg6RSE8D3sXxj8dzLxrY9oX0+ngxS2aRiAK99JPQoIXDe9ddq6OVtQnNKgOPZrE0HJioRJimR/EUol9kktjf0n+OYN95wS1X1YIt4mAqUzFvogZW0eMq6sRB2NKCv7gBRg+k4iCVfRzUhNqJ3pGa0J8v8U4cZ6SNr9jaGQlZaXgWDB36qmJcSvBoVD6+S96Z16sfvaHkL3QUkZSoY7xXi5lI9EXoCOJhYCjEEHjSHR7gmZrqNpPxh+zHFNiZUBwzEPU87l1+Ci0/sv86KCS1HGbi2JBpaGEUFJm4862u09GYh1LcTLyBQfuYmhTb96ZhPlWNwjnAXfpdZt0CT1tpTrdISlJI4l5rUU/ydVbKTR+EOs4P1LxrNndQ6kmgn+6S0Zo3dfn3GQmd2jsLt4ymZrUs4N3bjfUJgampR+5KtTFzVVldGtiGv03/vlTQcsMOGk9u9oQ1N7bGreeIFMcBq4WDeoeUiF3soo/snBWFKxaverAugts3WbvyOg0V8GCYhrquXzFX7cWjK0rbhB7sdAthJHk0nrJ6UzeHvYYUuY+6FTOBU0VAspOyNIECGgnIMu0r064c5yCX73wet4zyg2J2v5MCCfFl9VHzKXTpjeEqJRM1j7oLQFIHOht9ePUqC8BCyrhnvz64szeb4l1OmwgHosLM5d0TVfv5w6ytRvVtiXpuoUa1LXBJ9dHB9zAzIEeQTDOA1iFaBRcEcsaKOlQkQKb3oa5LYHV9BKx34hlQmQ4qpaFMHDrq3kUwrzocUBb9JB6kBcq8ryhYOelagDmQzmw2lVVgVY13ttvvLQToP1h0O4ZGiCzRGLECoT3xjnoJ2Z1+K+vq9ifdaL+PrXc2cONuRT3dMEb4D1Jxaulg4RZAWfUwu281lnZ8eyrprBWbM35WVD+dqXBcHVTpklM5/JIheiIPb5UiOoA4C0BpuvW/TKMvQZaD17PFSXuOs7KdaRtgu79Bz3qOrFY7EGvIIYhnmNZOHs8rzfEbneUSNq2Xn7rqvdNHbVLcYT+Tw8LzVJs0YrTnZfi+AIzbi4KIkVDtjTJIAiV1KUQrt1lXLeaXdfjVXQGXWVZX 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:(13230040)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:46.7264 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31fb90a9-882d-47c0-cf00-08dccf15d5db 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: MWH0EPF000989EC.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB8167 From: Alejandro Lucero Current code is expecting Type3 or CXL_DECODER_HOSTONLYMEM devices only. Support for Type2 implies region type needs to be based on the endpoint type instead. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/region.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index bb227bf894c4..b27303b9764c 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2664,7 +2664,8 @@ static ssize_t create_ram_region_show(struct device *dev, } static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, - enum cxl_decoder_mode mode, int id) + enum cxl_decoder_mode mode, int id, + enum cxl_decoder_type target_type) { int rc; @@ -2686,7 +2687,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, return ERR_PTR(-EBUSY); } - return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); + return devm_cxl_add_region(cxlrd, id, mode, target_type); } static ssize_t create_pmem_region_store(struct device *dev, @@ -2701,7 +2702,8 @@ static ssize_t create_pmem_region_store(struct device *dev, if (rc != 1) return -EINVAL; - cxlr = __create_region(cxlrd, CXL_DECODER_PMEM, id); + cxlr = __create_region(cxlrd, CXL_DECODER_PMEM, id, + CXL_DECODER_HOSTONLYMEM); if (IS_ERR(cxlr)) return PTR_ERR(cxlr); @@ -2721,7 +2723,8 @@ static ssize_t create_ram_region_store(struct device *dev, if (rc != 1) return -EINVAL; - cxlr = __create_region(cxlrd, CXL_DECODER_RAM, id); + cxlr = __create_region(cxlrd, CXL_DECODER_RAM, id, + CXL_DECODER_HOSTONLYMEM); if (IS_ERR(cxlr)) return PTR_ERR(cxlr); @@ -3381,7 +3384,8 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, do { cxlr = __create_region(cxlrd, cxled->mode, - atomic_read(&cxlrd->region_id)); + atomic_read(&cxlrd->region_id), + cxled->cxld.target_type); } while (IS_ERR(cxlr) && PTR_ERR(cxlr) == -EBUSY); if (IS_ERR(cxlr)) { From patchwork Sat Sep 7 08:18:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795148 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2041.outbound.protection.outlook.com [40.107.244.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F26CF1537AA; Sat, 7 Sep 2024 08:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697195; cv=fail; b=RjT/W3zOw1ojAPjkVU4+BjY9eeKV2nbg0RUBkE3WeosOHqkYTNKC75fO5+TTqZJ3MF8j7w0Fq3MFUF6uhtUug7RunBnQbhjrIKAyHmAfIsZhYXnuUqjoJ0N93OjV7M6jPcygeTHyvA2W2ImOeNkkXLArc7F1NmBzxUNMcmpXR/I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697195; c=relaxed/simple; bh=tVu6urx6U8yTEvHqe5CqXZ6LeiopZgxbSqR0PJXdzo0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IbLgZ3AxNQ2W22GjZZEsOeog8h+k5ciN8z9BKY7Q3YXKDgz/IQ8Lhmdxg4t1eW7W0+HiFROLvBDIAVdeO6MjJbxeUsjiKUSpXCNxEF8W8guDGxxDe/LUvA6MtydOFlcxh5Fr7j4VKAgxF5OG0arxrWbPYHKKO7uhYtT4lu/BS4Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=tpyZzFvm; arc=fail smtp.client-ip=40.107.244.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="tpyZzFvm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WZ+FBJGNeA2YoZ905vqmW/FYvDV1S0aAkEFC61DX25VrnKrz43wadTa0t9McNL7uXfrIBTpKfvuV5YCVRrV8xvoeRktMCwYcXGR+S8g7jzxPkFVLoib7hH14oblyBJzcAJUkIKC3bx/YKdjfBK2SWudsibVSNGw7Xu9iKSPxXjScuTcHBI9o7CvouNlaXPDtA+CUKFfaGtsM8Pql2Ldlg5JZuGpQ2S//Gmz4YxEFTo5Q7hugOEYkGH1qre+mf9ea1Hma5lQWQTx7pr6JN9Eq/PB+H55+3RY0qu9PBBavISW08S5KhgA/Uy4ZbTvoIwjbg2zL9h+RDmq+sALECH0+RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=mhu5N4ZTzfCYq0bQowULOeQSrnVJJz6IjoM7IJ5B/nE=; b=cHjlPfxji50BxyFvbH9bEJhBIVLDxOnfLjFlD/L8wVnXlIncmLI61nVPbK5NZMUDC5/gJQU/YOmJI2YeDMg8fr4qRYGjNkFINWWCi7165PPzt8wXBie8R6n9btCrVi+gd8EVOHDtKg41+UJw2xfI6DUr53rr9u9RA+9SnaNt1IBj6Ot6gJglo/0ddRNMGZcq80ZoeH8CTbOwc5q70DkPtRP4uxenJxE7+/d5SnV+NzRbvxTpGxrcgnbBGcrMe5CfdN96f7yrW91nhDOfpDJcByi5KEHnpJrrChJVxR3XhGnttTaUi8VgTuKOdClHAxRrg4U8ZDFtZo54+T5fNKZyRw== 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 (0) 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=mhu5N4ZTzfCYq0bQowULOeQSrnVJJz6IjoM7IJ5B/nE=; b=tpyZzFvmh2YhVZuSS8FJj3wKCvtazV3zlWL7NBJJmIofHFV/MvMxRoxCvPwXXWV5WKNs1XdZjry4CV8IunAhiM/nVmuXRFg2/UVHCqzmE3rHd1U63W3bWF+zmodWaspa4fWRGB42u1QxgVwgYEf9OXvDSjhzcu//aJv0FweexVk= Received: from DM6PR04CA0017.namprd04.prod.outlook.com (2603:10b6:5:334::22) by IA1PR12MB8222.namprd12.prod.outlook.com (2603:10b6:208:3f2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20; Sat, 7 Sep 2024 08:19:48 +0000 Received: from DS1PEPF0001709C.namprd05.prod.outlook.com (2603:10b6:5:334:cafe::9e) by DM6PR04CA0017.outlook.office365.com (2603:10b6:5:334::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Sat, 7 Sep 2024 08:19: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 DS1PEPF0001709C.mail.protection.outlook.com (10.167.18.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:48 +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.2507.39; Sat, 7 Sep 2024 03:19:47 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:46 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 15/20] cxl/region: factor out interleave ways setup Date: Sat, 7 Sep 2024 09:18:31 +0100 Message-ID: <20240907081836.5801-16-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709C:EE_|IA1PR12MB8222:EE_ X-MS-Office365-Filtering-Correlation-Id: 15b8985e-e197-4417-e786-08dccf15d6f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: ELeYTiVshgHUSjyTUR4urBncFY+kdKauBiYHGabcXgkJdOUjsk/I8icaCu5lr+MwV0+19zf1bNmXkIjF9e3B+aShm8e48j0VE5J8q8+lHmjAgtHAPaQ3w47yx9F7tJ6Y7/qzVsuLEjdLB/PpFyr8UTEAlX7zAu+VMXmE9ZUHb0zFOVMW+bSs8x072SgcATkatGU0t593Xkb7GFodpCKrxZR9WKPsvfaOUNsAo1sR1qySFAa9wyIiJsF4bmn+3UHHqK62ywqKkn8gaGhNVJnTIBkdzOrUnKu2xI2glcobMqCP5tWmSJKovbozXjoJdXkcCOg/Z/uW8brXsX+ed7AJSJE/D+PNq15W280QBe+n2okgw0o1xyVa+KYIkg1xnru1AcvKexz2W69Kk9/ThV9uRGrwHLrrWtDXr41UQLog2izf7L0YxFtXl4miHhkLtxc+SGbUxiI3b9d41lmOOW8uBJ6KIUgu66dhJeBOnNz2UkIv7B8p9WT4CZOV5Hl0pCM5dsv93l1jZQr5QAUQU+qnhUmhSlbe2OuTzT4kehfCGCz3h0JIWAZIY0+Cf7aVEXeuBasf1gsRnEXMQb7h7Uj5sHmgum9t73dskNoOkZRQW/QHypZTCP8TRIQtlhLN3JH3EeEX/LG+bO+Ni9X7NXEmloD5OrkgvMakVFinWQa+IxhrKHlw942Cnp1b1IuFOmbf3pDmebYkEPLd5FWyq2+KuqZ+gGuaOiGVsSo7ldXnQDhDy2kDsrPNl6VPb1zHen+wUEMN6HUbVQVLZaXBmWRAVQHC203+Q7oDj9V1uJxpuogl7mv/HEiAaOdtJivAHhRVFzbklTw1Y4dvQfK4k/Dgzld+xYQpSrQz2QWi/Au2xLEpS1iZnW4tmNz1OtL0rETuNFjI2jPwcPgleP/o91/3o21SB1PnRJkvTjGjnpBKv4et4yme1hdbahIKU8u2BMnAFtEQTr0p3fvaZ27HHferrGW9B3Q9PCa7KGmeQz5LT9RWMcAewJGtSogBmHJWKmQUdnSeNqlFrE+ctJYW0ZVY3q+j5nS/fvmrc+I7wPeURA65I5s1tqSsBNzGrr4c2uJE1EFNJDTzqMvMnbT+r40hMgkch5/hnR4oleIW8MQGVWOz05A1XX0vL+QEtuSvzEHuax4LHd7s8vBQeLBdgeF01AA25qN99Q2DkoPctFVOep0POCvZm9wZOHkaP1AiuCTgSi3U16hTEkZu5DMQ02FXP30EeaYYYl/fbXF5bk6LvAdCV6Cbvqdk52gzjBvAap4RiqSgUTygnSNc9uKDLdjrTbUCXbVH/bD9MxQUMtnAIBglVTt/LtNTj9LkbWXcFTkf8sPE4hB3GcQffk0U4zrUB57AD3uizMPiXYr80H8w+lnkYCOAAq/VqmoHqWZ3X5KvAdgEG4YqkGYzigDd3/YoAsqlyAABH6y3JDx0o7MYY1t/MpM8yyv2g46vmN86o9dg 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:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:48.6336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15b8985e-e197-4417-e786-08dccf15d6f2 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: DS1PEPF0001709C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8222 From: Alejandro Lucero In preparation for kernel driven region creation, factor out a common helper from the user-sysfs region setup for interleave ways. Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/region.c | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index b27303b9764c..edd710105302 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -480,22 +480,14 @@ static ssize_t interleave_ways_show(struct device *dev, static const struct attribute_group *get_cxl_region_target_group(void); -static ssize_t interleave_ways_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) +static int set_interleave_ways(struct cxl_region *cxlr, int val) { - struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent); + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; - struct cxl_region *cxlr = to_cxl_region(dev); struct cxl_region_params *p = &cxlr->params; - unsigned int val, save; - int rc; + int save, rc; u8 iw; - rc = kstrtouint(buf, 0, &val); - if (rc) - return rc; - rc = ways_to_eiw(val, &iw); if (rc) return rc; @@ -510,20 +502,36 @@ static ssize_t interleave_ways_store(struct device *dev, return -EINVAL; } - rc = down_write_killable(&cxl_region_rwsem); - if (rc) - return rc; - if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { - rc = -EBUSY; - goto out; - } + lockdep_assert_held_write(&cxl_region_rwsem); + if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) + return -EBUSY; save = p->interleave_ways; p->interleave_ways = val; rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); if (rc) p->interleave_ways = save; -out: + + return rc; +} + +static ssize_t interleave_ways_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + unsigned int val; + int rc; + + rc = kstrtouint(buf, 0, &val); + if (rc) + return rc; + + rc = down_write_killable(&cxl_region_rwsem); + if (rc) + return rc; + + rc = set_interleave_ways(cxlr, val); up_write(&cxl_region_rwsem); if (rc) return rc; From patchwork Sat Sep 7 08:18:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795149 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2081.outbound.protection.outlook.com [40.107.236.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 224DD1537AA; Sat, 7 Sep 2024 08:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.81 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697198; cv=fail; b=NHhm6pgQ2AcxNHu0SyPJunphbjVJmpLUQ5tiUkZRAkbyZOXTrysFXrFMC6Sbz9gr08PoMfIwMjvtLRWAY5gEUP/i4lV+YAYFwO4AmmJ5uivoo9yeAd2YBOC7ED/b9FRFar1LVO+J4C/nXJ9mi/UDVZpSyAiZGenFQHGgwKA+qTI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697198; c=relaxed/simple; bh=6quKWQASegmxYifwCqVi9q26VQrGazjhmmvJJqU0pbc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qYD3scg67MfnISXJupQ5GF4wASKSwYgHgrd/wKhhGE/rXrUi2hbSq3FddjvvPPLlhZ5WF/ZLiLG6RegM7uBioP74qQWSRjOotsaiAtV8BRx5Z1cMcFKg132Lotrf/E6w6amjH1RVmOAZ4cJDB0jKhbPKMSmE2kg3o4FwwAQI46Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=PQKAa9Wx; arc=fail smtp.client-ip=40.107.236.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="PQKAa9Wx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uv9b0gx4VWnmVXmJL49WBXuXmp8tZ/9mw47JI98Rkp0BIDeIPQjpp9xiYwHOW2yhNG8+eAM/86rQMCBCK1MaFGYDUwAUhtO7F6OW8Vz8g9UnhBpJJtYSIQ2Gs4Z36L/pHOhRp6UPaQyCFIP6eVDjMMfle39xRpPvQaQwlcs5lS/UI6358WlsgKtZQLUhEWuYFpWOiHFcY35dow4A8fFFV3cZFhpSjyamccjtgJ9GnCblZWdIX0Y+DlfyGRLRgRnv7sbX+uhI1E7ki/NHzhc23gQdnT4C//Lb5nVQNByLTV7q6cL2VMcRyS3wu6FruoGlRd1sC8iGgISIp9xrcb4Vwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=oDZ7fw+ejj7QKNyzXLiGk3BytzKw2U/A4tsYEgIA4og=; b=qzXo36M40QD4wnzwHEMWbTC/xqae/+AZD5jO3BTfjG168KvWYPiXbvGpxDSq/L3qIogGYYqPSHxIhJh1uYzk0gRje7HG2eTXhUEvCmkI0iLk+fqO1ZWtiG+j/amicMzwF/MH4w7JoeOTzmZz4keODP4bmuJlZvggXTDRokb8KsfYC5yi8um5Y7/Dmi4waTCln+ywWg/nfzofxwJ958O5ABtWtea/hkQkGrG5CMYPq+lH+xXjBbj74JF+DFNufwqe57zIONbiQKlHxdOjKWIIqXkL+bQmplTebedJQFZgXm1TRUQu9eVwxHtBTNsDM0yIcSJ13PpHsA/Ud16GlwGz6w== 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 (0) 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=oDZ7fw+ejj7QKNyzXLiGk3BytzKw2U/A4tsYEgIA4og=; b=PQKAa9WxvaFZLHM27WjKllHwJKdnRYQj1gThW5rW2UEtl6DlT11oO4N240b4efi1y5bdDEii0J9B3JopxPU1Z4bMMVANL0RvvO5Tatj+pgw736qE8/KrUx7qFrmuN14212HCCdFU41iIDxyuQKl4sR7qitSq7NvVwtvrwOrg2DI= Received: from SJ0PR05CA0057.namprd05.prod.outlook.com (2603:10b6:a03:33f::32) by DS7PR12MB8249.namprd12.prod.outlook.com (2603:10b6:8:ea::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Sat, 7 Sep 2024 08:19:51 +0000 Received: from MWH0EPF000989E6.namprd02.prod.outlook.com (2603:10b6:a03:33f:cafe::d1) by SJ0PR05CA0057.outlook.office365.com (2603:10b6:a03:33f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20 via Frontend Transport; Sat, 7 Sep 2024 08:19:50 +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 MWH0EPF000989E6.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:50 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.2507.39; Sat, 7 Sep 2024 03:19:49 -0500 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.2507.39; Sat, 7 Sep 2024 03:19:49 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:48 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 16/20] cxl/region: factor out interleave granularity setup Date: Sat, 7 Sep 2024 09:18:32 +0100 Message-ID: <20240907081836.5801-17-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E6:EE_|DS7PR12MB8249:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d3f14ad-99fb-4e97-835f-08dccf15d831 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: wGkcU79EmPPnLaYvgRnVxDIzcy6nT+/JoK8QybAEfl3/QcI4GoaCmyC10O7dHKlIzWouyyjnSCTFIvv3ZBvp989q/kLJArvGvZr2uPZDq+6OUs/mZOHFxv8kQobEJt3wlQ6tTQ3vXEhNdJ9f56lSpSkl8ia0iRulc0f0XerWtGfImdBks7R/gRQqaLx0zZ1w2BzvKgHa04GEva4ShwGZ4b0r1e3zmIJOT0686cD4Keuwca+TZN3qd1W+/++I9TVd3vAe1154oKpmNisP1sfod9E6bciSOgdFAr8oKp41RE0LSrIuXABz977GNqAzIahMJ/f+XmBspT4Xa3HplVRDbrUpXmgR6zvsq6MNziznRVG47DUlE8MAMLMjlQeK9/FvsV1bOVm8oNONhcTg3c4dJYFSUuurCV244gqaO7DfYb6dZj8uY8bAN/DA2hZat1v6fAjSVrFES2m0Oh0EDb857+w1NLnokQ38PSieJ2PXNaC61uwzJYI/B8hRdPjhXocOWtCYzWzGjSER8dkwoRGFLSq0lYdtg6kFJPkAfEE4q0OwBXWC8z1szNT3AQLWterZ4pUhH04SSdviXK007Jq7pRXhe9VMi02pml/zZDX8btIYpFqQSoSsWh6FMelpO4DYev8VKk9DUSMBnen6QqWg1CkjHTqfXx/ow6b2qyKegNiDY4rQ64oyedmYuZHBzElm8EEt+oCoa5IebRnaqBgjQnHJatpM+//0YObVpD28DQQKTVjUWW5lSM/2P9IJVEyK0J8/j2ufjoXFvTNmOpgYdC/HihJ3zSCOev7xdPRTeuEr7vBoHpRJuadw5SHoZM8BO2tLT6JnLAMIHHcnNdY5p35AlcjRv6Cp9LIacE+YzWjEhAq4BGC2wQyarl8Sp6oORgQiRjWeKSueeqIbdtSW3i6/pQqv4Ov9GaQT/FxVId+sBiavV0sley7kwcyk4akJFUnXwGJsK675vQE5ra9r/BsQSns3lzXZY/bBjvxsaZU0JxSYU8sxl4DxVRmycNJJv2vbvtLW84l5XwaHabhnBTEDhnr1otH/seiyYEDkOUFA/anipXH28o9dxNy552ZYIX3IVQ/a4axZPqqmuDzd4/RKj4ICPPisqt//PAnbDGzjbJBuciWQMiPMamZeRgMVvRiHgl1xm4r1QwNp3j0zthtCAqxBJwT6ykpPh9ICJF6mUeqOfEBkpg9WoDUCaOCU93y6mskYW63oLBPpRSVpzYdKyNXomBTGITB1G/ugsL8K8ajnYkC0DRIYLHagqPxHkjuS8re8ITlN1WewW3cFUaF93TdEQwpSVSCAHKblHDCL+KPClr/aUBXxjsRxSXkigHB7pubk1LmFebwdtILXbBwuVKgUlhU8b6Q1hg+OQ7+ZTEeBrMV92PvmzCxSzHOVbmVaO2XM8NBem914QTe6DLctniMAmIC7vWYrsAJB5USMcvMMMkkLpMYC2yqB2Msx 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:(13230040)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:50.6279 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d3f14ad-99fb-4e97-835f-08dccf15d831 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: MWH0EPF000989E6.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8249 From: Alejandro Lucero In preparation for kernel driven region creation, factor out a common helper from the user-sysfs region setup for interleave granularity. Signed-off-by: Alejandro Lucero Co-developed-by: Dan Williams --- drivers/cxl/core/region.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index edd710105302..c6fa9e7e4909 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -556,21 +556,14 @@ static ssize_t interleave_granularity_show(struct device *dev, return rc; } -static ssize_t interleave_granularity_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) +static int set_interleave_granularity(struct cxl_region *cxlr, int val) { - struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev->parent); + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; - struct cxl_region *cxlr = to_cxl_region(dev); struct cxl_region_params *p = &cxlr->params; - int rc, val; + int rc; u16 ig; - rc = kstrtoint(buf, 0, &val); - if (rc) - return rc; - rc = granularity_to_eig(val, &ig); if (rc) return rc; @@ -586,16 +579,30 @@ static ssize_t interleave_granularity_store(struct device *dev, if (cxld->interleave_ways > 1 && val != cxld->interleave_granularity) return -EINVAL; + lockdep_assert_held_write(&cxl_region_rwsem); + if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) + return -EBUSY; + + p->interleave_granularity = val; + return 0; +} + +static ssize_t interleave_granularity_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + int rc, val; + + rc = kstrtoint(buf, 0, &val); + if (rc) + return rc; + rc = down_write_killable(&cxl_region_rwsem); if (rc) return rc; - if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { - rc = -EBUSY; - goto out; - } - p->interleave_granularity = val; -out: + rc = set_interleave_granularity(cxlr, val); up_write(&cxl_region_rwsem); if (rc) return rc; From patchwork Sat Sep 7 08:18:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795150 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2082.outbound.protection.outlook.com [40.107.220.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0423014D2A3; Sat, 7 Sep 2024 08:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697198; cv=fail; b=eJ/G4Kxo+8dt0+1th77vtecFS6q65VAQSf9k6GLOx1L299uO1o7r1oR1Q52OidoIxfPaVew4Gn7Ub9WdHq0oTwsFnnZ8fUZ/SkveMI0oP2hSVaHjuBgpf9Lwf6jmqNQ6tEa1IR22NbO5SotPuyzbT4HaEH8JP94P8twk+WGnJmA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697198; c=relaxed/simple; bh=dFWMe7f96kDlwKg0LLGVutB1UnT/HbGHRzgVDxQ/v8o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HDpUZs2OJfKTe9hgKtBN/0UCdxlvYenhhGPGfLX/61OJiXBVt0Q35eAZjopMiQjTollSYjajspKAK1ZH1pjR17vJkZhfIa6XAzhv2VoZXlt+yrbBsa+J+piQIDk47GRuMVhMHaSJVVYOx6nRJGwJ0hiQEFn+1c2UWiM7NLlHUg8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=4xJNb4do; arc=fail smtp.client-ip=40.107.220.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="4xJNb4do" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y/sEbPiCJxmF4+KYdTSdMETBcrZ1Ks9i67WFwhD2cGWyENYfg1F6P5YB81TprbSdtUnmgGMhhWLyRv9pikphVgGWh2rS+1hiBXPB2a/bao86EFY/KSV1ExGkT4TT/1DhP1iE13/Y79TfRFaAhgM6mtraclWR9xhcy/MIOZJZ/H9X8R91NLeM1WenTEQQUEV6lq6jeKy01r8r05V1hzlGpGEppTMNAOYsgLYtp1zHPvcbSjaQWVFusKxCxfzlDdb4dvMuJuEq0mIO0DXMU3FzO2Q//rgHF2ilGU7jVLmosq0FTBC9pDzGhwcOFKR5EfMtWPn45J+UXZxzFsXmZdZc3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=wQk0ZgAXSdGK3C1LxxcmS0/dy45KiHhb7h8ulZ32pi0=; b=ZmAVCwq6zkDqi0VHLEvcB1UmUN99XCE9QO9tD2yQp6SDVRe9oZWOelsmUydltiPH9AExVBIorTjPMLjg/rozMIH5rsCO8ael+wMCbM3X3ZRZQemD7cDkiLQij1AjeRAv4IgneNzRhWlVtms4q6mExGwNitzmVGwSvY0LvgRrGDr9du14KUbwhUweZRamgsk3PcVlk2R2lFmRMGDfOJ7DbHHv7oO1VfpeHqb8IlNw9WmTrAEB6tsVsn9f97RSq+M0bCR4hXXJFFvVzxahNyVod+a067+QjN/tXKpoV1AJC0BZUQHriSo5EzVp5TfsLQACPBD3+ggao3+IMn0zJpukDg== 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 (0) 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=wQk0ZgAXSdGK3C1LxxcmS0/dy45KiHhb7h8ulZ32pi0=; b=4xJNb4doJ+QqLulyrPdH3t8w/nPcvSOUzDHZUkMeWmhka4RPdc6qY6XRAo9IvGOAE39t87ZqxjGaTXrkfPlFJRawPmKydbVDZ3gkUjIM70nHI6lYUhxBLG7dyLamfd2Jegozf2ui/SQQ0kIsU29+GqnvPclDxuiBtXM7pgSXbog= Received: from DS7PR03CA0127.namprd03.prod.outlook.com (2603:10b6:5:3b4::12) by SA1PR12MB6797.namprd12.prod.outlook.com (2603:10b6:806:259::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20; Sat, 7 Sep 2024 08:19:52 +0000 Received: from DS1PEPF00017099.namprd05.prod.outlook.com (2603:10b6:5:3b4:cafe::9e) by DS7PR03CA0127.outlook.office365.com (2603:10b6:5:3b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Sat, 7 Sep 2024 08:19:52 +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 DS1PEPF00017099.mail.protection.outlook.com (10.167.18.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:51 +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.2507.39; Sat, 7 Sep 2024 03:19:51 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:50 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 17/20] cxl: allow region creation by type2 drivers Date: Sat, 7 Sep 2024 09:18:33 +0100 Message-ID: <20240907081836.5801-18-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017099:EE_|SA1PR12MB6797:EE_ X-MS-Office365-Filtering-Correlation-Id: ec543275-0ff5-4de4-7060-08dccf15d8e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: YO6ktH4zlrNuMYghiQS1Ub7PSfHM1l0V9kdFvyklFmz7NIPQfdv3izYrttf7LqGKCcBYjA3yDYMC314S2X7UhuWYUsUfn3IaairM2kmc6GPq9XLHa+0NfzYEueQdEH1wM5LmrKFnc+9sTYQOJ9zey+ElAY/xNA5mlzamjGORhi/OxwhOn5zKKZ4o3F9vOS6eHk90KpPoVQBrNuoedB5kybdn+O36YYdlZgiHYP+KWMq0Yq/jsz7iVsKSoQB0UOqVkwVPdswLRrhpOsQxh5h7sfED94iy8MoOYILiUIysn34oYU7TkBRIwDH3igfXpPrCCYEB0mBVlaLodZxCDZ8+GngCc1umZUarkPCLzEBfAWf8eSBXlClMnu4z1XjpfCeK++sCq16Fk46vo40n8lq1cMSuYqwDqPp+Nr83TuVhFOR9nlWga8AtMRBaRZ03p1OOQ70B3fmz8QrgqvMYkvy5t+NJ4YqTRY/L5M83cGw7MDNCTRpmw8aGOh8sW2AVvFbWXN3vg4lfiTFtHSVmmVovwXUQI5ZbKVvCpW2hls+VAM/5nFnM0yO9r6LX3lsAgX8Ozl/xuxcHLI91jgZ3BXOA5T+yIYCDPE5J1RB42kbsaSr2NeoMWQQ0O0Dzz+gwg6NY6TLWSOHwqhBjggqixpO48YKxvFcyWKHZRmuYWpwkoCq9IXGkl4ZESz7DwF2Co/LXK6KeLCjWckUfpQ9WbAPkgqbOhUN9lpa8aPHdKEYOWpf75Rc+nL6s4zpFK80OubBsf2nIEZqlfWC0kJDrXIGtz2B5d/+Dac2WLkawBkv2lIZpm23m4L8dY4E+AnmJ3BoGpn6oJGg3zld7QnmJkibochuA/BTrN72mJ+UbbJsVtjgS6zjP41rGPOmz0Z7dwq0qQHKh0SACjS2qMkbpNqGz/Fda+656kTH20mxftmQXaITM9YrmPzhqm5rnA93rY1LmnAstiqS2WzfY5jNJkhBM2XWcZVe1ZdNlBJe9ZC5nW9G2nRHhnAe+0OK96/V+xIA9PwjfXFsUMIxaFVcQas9ugcJmfO7PP6sLJBWxp3Y0oV4JS3b3n3SRr45HE9NZp6qvE9E8Gq17EmENGQTZVN2PfCjyPG45cSbebAPPzOQeIVkXU/OgITcp0nBzPhzxOPF+UJvxZQt/Dcm1wBeEWWiVzzUmdJm+AYPZqTQ0/QhnHQgR76E5Zs8qdKUwKPe9D97vxk3ILOL+tptutAeVJYDMvnn0AqyAcxxEvZtGrTaqhaMBtsd/EBpck1quendFCiUf5lx7SyiCjvJlmYcvwm34czmRRhZeZgBf34msI8MJGeFi3+/7E6nWD8JikMi7K5/QkK3SqhrnlOqXogbJlM91J8Zs8Ks4FQ27/1O7kNt+FDcEqUkSCR/7p6pElaV65tix1VZM3kRxcfX+9RRd3c8IEANTZVHG31ybTU6kfHDlEtzkfqHX+OmTY04zpVapXSZR 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:51.8762 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec543275-0ff5-4de4-7060-08dccf15d8e6 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: DS1PEPF00017099.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6797 From: Alejandro Lucero Creating a CXL region requires userspace intervention through the cxl sysfs files. Type2 support should allow accelerator drivers to create such cxl region from kernel code. Adding that functionality and integrating it with current support for memory expanders. Based on https://lore.kernel.org/linux-cxl/168592159835.1948938.1647215579839222774.stgit@dwillia2-xfh.jf.intel.com/ Signed-off-by: Alejandro Lucero Signed-off-by: Dan Williams --- drivers/cxl/core/region.c | 158 +++++++++++++++++++++++++---- drivers/cxl/cxl.h | 1 + drivers/cxl/cxlmem.h | 2 + drivers/net/ethernet/sfc/efx_cxl.c | 10 ++ include/linux/cxl/cxl.h | 4 + 5 files changed, 153 insertions(+), 22 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index c6fa9e7e4909..d8c29e28e60c 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2192,7 +2192,7 @@ static int cxl_region_attach(struct cxl_region *cxlr, return 0; } -static int cxl_region_detach(struct cxl_endpoint_decoder *cxled) +int cxl_region_detach(struct cxl_endpoint_decoder *cxled) { struct cxl_port *iter, *ep_port = cxled_to_port(cxled); struct cxl_region *cxlr = cxled->cxld.region; @@ -2251,6 +2251,7 @@ static int cxl_region_detach(struct cxl_endpoint_decoder *cxled) put_device(&cxlr->dev); return rc; } +EXPORT_SYMBOL_NS_GPL(cxl_region_detach, CXL); void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled) { @@ -2780,6 +2781,14 @@ cxl_find_region_by_name(struct cxl_root_decoder *cxlrd, const char *name) return to_cxl_region(region_dev); } +static void drop_region(struct cxl_region *cxlr) +{ + struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(cxlr->dev.parent); + struct cxl_port *port = cxlrd_to_port(cxlrd); + + devm_release_action(port->uport_dev, unregister_region, cxlr); +} + static ssize_t delete_region_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -3385,17 +3394,18 @@ static int match_region_by_range(struct device *dev, void *data) return rc; } -/* Establish an empty region covering the given HPA range */ -static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) +static void construct_region_end(void) +{ + up_write(&cxl_region_rwsem); +} + +static struct cxl_region *construct_region_begin(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); - struct cxl_port *port = cxlrd_to_port(cxlrd); - struct range *hpa = &cxled->cxld.hpa_range; struct cxl_region_params *p; struct cxl_region *cxlr; - struct resource *res; - int rc; + int err = 0; do { cxlr = __create_region(cxlrd, cxled->mode, @@ -3404,8 +3414,7 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, } while (IS_ERR(cxlr) && PTR_ERR(cxlr) == -EBUSY); if (IS_ERR(cxlr)) { - dev_err(cxlmd->dev.parent, - "%s:%s: %s failed assign region: %ld\n", + dev_err(cxlmd->dev.parent, "%s:%s: %s failed assign region: %ld\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, PTR_ERR(cxlr)); return cxlr; @@ -3415,19 +3424,41 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, p = &cxlr->params; if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { dev_err(cxlmd->dev.parent, - "%s:%s: %s autodiscovery interrupted\n", + "%s:%s: %s region setup interrupted\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__); - rc = -EBUSY; - goto err; + err = -EBUSY; } + if (err) { + construct_region_end(); + drop_region(cxlr); + return ERR_PTR(err); + } + return cxlr; +} + +/* Establish an empty region covering the given HPA range */ +static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) +{ + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); + struct range *hpa = &cxled->cxld.hpa_range; + struct cxl_region_params *p; + struct cxl_region *cxlr; + struct resource *res; + int rc; + + cxlr = construct_region_begin(cxlrd, cxled); + if (IS_ERR(cxlr)) + return cxlr; + set_bit(CXL_REGION_F_AUTO, &cxlr->flags); res = kmalloc(sizeof(*res), GFP_KERNEL); if (!res) { rc = -ENOMEM; - goto err; + goto out; } *res = DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa), @@ -3444,6 +3475,7 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, __func__, dev_name(&cxlr->dev)); } + p = &cxlr->params; p->res = res; p->interleave_ways = cxled->cxld.interleave_ways; p->interleave_granularity = cxled->cxld.interleave_granularity; @@ -3451,24 +3483,106 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); if (rc) - goto err; + goto out; dev_dbg(cxlmd->dev.parent, "%s:%s: %s %s res: %pr iw: %d ig: %d\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, - dev_name(&cxlr->dev), p->res, p->interleave_ways, - p->interleave_granularity); + dev_name(&cxlmd->dev), + dev_name(&cxled->cxld.dev), __func__, + dev_name(&cxlr->dev), p->res, + p->interleave_ways, + p->interleave_granularity); /* ...to match put_device() in cxl_add_to_region() */ get_device(&cxlr->dev); up_write(&cxl_region_rwsem); +out: + construct_region_end(); + if (rc) { + drop_region(cxlr); + return ERR_PTR(rc); + } return cxlr; +} -err: - up_write(&cxl_region_rwsem); - devm_release_action(port->uport_dev, unregister_region, cxlr); - return ERR_PTR(rc); +static struct cxl_region * +__construct_new_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) +{ + struct cxl_decoder *cxld = &cxlrd->cxlsd.cxld; + struct cxl_region_params *p; + resource_size_t size = 0; + struct cxl_region *cxlr; + int rc; + + cxlr = construct_region_begin(cxlrd, cxled); + if (IS_ERR(cxlr)) + return cxlr; + + rc = set_interleave_ways(cxlr, 1); + if (rc) + goto out; + + rc = set_interleave_granularity(cxlr, cxld->interleave_granularity); + if (rc) + goto out; + + size = resource_size(cxled->dpa_res); + + rc = alloc_hpa(cxlr, size); + if (rc) + goto out; + + down_read(&cxl_dpa_rwsem); + rc = cxl_region_attach(cxlr, cxled, 0); + up_read(&cxl_dpa_rwsem); + + if (rc) + goto out; + + rc = cxl_region_decode_commit(cxlr); + if (rc) + goto out; + + p = &cxlr->params; + p->state = CXL_CONFIG_COMMIT; +out: + construct_region_end(); + if (rc) { + drop_region(cxlr); + return ERR_PTR(rc); + } + return cxlr; +} + +/** + * cxl_create_region - Establish a region given an endpoint decoder + * @cxlrd: root decoder to allocate HPA + * @cxled: endpoint decoder with reserved DPA capacity + * + * Returns a fully formed region in the commit state and attached to the + * cxl_region driver. + */ +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) +{ + struct cxl_region *cxlr; + + mutex_lock(&cxlrd->range_lock); + cxlr = __construct_new_region(cxlrd, cxled); + mutex_unlock(&cxlrd->range_lock); + + if (IS_ERR(cxlr)) + return cxlr; + + if (device_attach(&cxlr->dev) <= 0) { + dev_err(&cxlr->dev, "failed to create region\n"); + drop_region(cxlr); + return ERR_PTR(-ENODEV); + } + return cxlr; } +EXPORT_SYMBOL_NS_GPL(cxl_create_region, CXL); int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 5d83e4a960ef..120e961f2e31 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -903,6 +903,7 @@ void cxl_coordinates_combine(struct access_coordinate *out, bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port); +int cxl_region_detach(struct cxl_endpoint_decoder *cxled); /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 07259840da8f..b0a66b064c73 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -878,4 +878,6 @@ void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_port *endpoint, unsigned long flags, resource_size_t *max); +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled); #endif /* __CXL_MEM_H__ */ diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index 57667d753550..dd2dbfb8ba15 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -125,10 +125,19 @@ int efx_cxl_init(struct efx_nic *efx) goto err_release; } + cxl->efx_region = cxl_create_region(cxl->cxlrd, cxl->cxled); + if (!cxl->efx_region) { + pci_err(pci_dev, "CXL accel create region failed"); + rc = PTR_ERR(cxl->efx_region); + goto err_region; + } + cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); return 0; +err_region: + cxl_dpa_free(efx->cxl->cxled); err_release: cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); err: @@ -142,6 +151,7 @@ int efx_cxl_init(struct efx_nic *efx) void efx_cxl_exit(struct efx_nic *efx) { if (efx->cxl) { + cxl_region_detach(efx->cxl->cxled); cxl_dpa_free(efx->cxl->cxled); cxl_release_resource(efx->cxl->cxlds, CXL_ACCEL_RES_RAM); kfree(efx->cxl->cxlds); diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 3250342843e4..169683d75030 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -72,4 +72,8 @@ struct cxl_endpoint_decoder *cxl_request_dpa(struct cxl_port *endpoint, resource_size_t min, resource_size_t max); int cxl_dpa_free(struct cxl_endpoint_decoder *cxled); +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled); + +int cxl_region_detach(struct cxl_endpoint_decoder *cxled); #endif From patchwork Sat Sep 7 08:18:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795151 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2078.outbound.protection.outlook.com [40.107.244.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7D941547C7; Sat, 7 Sep 2024 08:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697201; cv=fail; b=YI9R3zCLy3LpyUAxtKehwHqRQ3uyaswx6sBC1aFVM6aAsuMspoLbT3qLHymy/qUQNlcRg5LDl+51b7GgLP+4fH8675fo8EmUWfNS9TcAV7UNnbeby/BZJFT7DB1BF9KihwTX5Z5QSSyOr9KvKmR02pKAj6K6bZxHsVMaSt5bUJI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697201; c=relaxed/simple; bh=7Y4TDB0tzf6bsoQf1W7vsNQxeQbqL1p+mNC0L1kQsRU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tn3Veju4gvy1RT4EnFTykQyGHwHibDwhKcsfkOJ+ewPhDh+iY+MXs8WchhCEGZF7/wDcVzbj3yklOr/NxCRE0myW0oVo4FCo2KyI0+YHnpEpDt7egxiuCeFlAR3dm3eMtcD+Ty+/23XNUJtqIzgfTq6Epx/ga1zCDl0WwScPAeU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=NHPeth/+; arc=fail smtp.client-ip=40.107.244.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="NHPeth/+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q5MC4SFH+Q5r43Mc3RwGl29KkWI3k5xp8lXZF7gosDz57rmT5A+Wl53BnNyAP+MsWnJF60NxBVudGhCw7E8dJc2z3IGZSUChs8Bm5jzknJ82hBGYqYoK5SAnzIhw4su0XTcNbtTE3TpumZCRuY5eOR89v6GPnNXF16vMFMv0ZWmfHtEKTWxeEDn5xaiq2m4usZgdgOhi0wu9eTgc7I59BtIWp456fEuEm+7EJHyuk59PU0G4YlLBlZ+1GIN1MCmL7YAf6Q1JS+pnE9m0eTrt9gZMYFh+Vwps7uMKPoYDBW329ftJ/+97fUp/xEtHNlCAbbOnFk3t0IvnbyM0LTgILw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=NorrTxfK1Nl1nd3bc61TjZa005rlHGBdl7XNHAtcqp0=; b=aN51duMQ/lGipllvXIhcSwSTy7m+5PF++qJ4KmWNK8piv1CB34I7KDicNyABTUlwJzH5y04+aFwYcSe0Whi5W8R7nkJMwSOr70JU1symOHwpnRS4YgxCAlNXtkzE4fHR07c71rs6oAXRY9mgCui5jeVdCZ697fA+1qCxtsYkvXrLEU9brewhXXNguB5ZO0trgdy8lg9s9FCGTBWdREhmh3FEnwtTehilo49KmExiTERettsgxrx+Pu79Qk0ALZAiBrli9GlE5f4B2LW0/6fu4NIXPwJ2b5iVWpSy22D/4LnBg8onQQz8uManvelfunbw7ej+Iniyg+NaHVMIkxfrfw== 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 (0) 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=NorrTxfK1Nl1nd3bc61TjZa005rlHGBdl7XNHAtcqp0=; b=NHPeth/+kuhq8lTVag0WTraYaaypsqx+b0sCnQ8yZtpYkfxQORI+LxH31Hdkyh9OEJjMokqrMoXiHjkdVNKzS+bq4UGJhkcF9fZ7UQpDwiKfQFhm9tfzkSBKQXr4ueTpsMsGXOLdzcFD8A6A0bpCyGtQOlg+edxEuUyQcuqe790= Received: from DM6PR04CA0024.namprd04.prod.outlook.com (2603:10b6:5:334::29) by SA3PR12MB7973.namprd12.prod.outlook.com (2603:10b6:806:305::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Sat, 7 Sep 2024 08:19:54 +0000 Received: from DS1PEPF0001709C.namprd05.prod.outlook.com (2603:10b6:5:334:cafe::87) by DM6PR04CA0024.outlook.office365.com (2603:10b6:5:334::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Sat, 7 Sep 2024 08:19:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0001709C.mail.protection.outlook.com (10.167.18.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:54 +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.2507.39; Sat, 7 Sep 2024 03:19:53 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:52 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 18/20] cxl: preclude device memory to be used for dax Date: Sat, 7 Sep 2024 09:18:34 +0100 Message-ID: <20240907081836.5801-19-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709C:EE_|SA3PR12MB7973:EE_ X-MS-Office365-Filtering-Correlation-Id: 5040b25a-176f-4dc0-7121-08dccf15da48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: m8o+qP1i6dffclzSyI3XLgBQDQJq2d72/zQ6E5nwgXDodhi1RTf9hp0QHhC/8FCIrDJSDwff7EHU8ZlOSMrW5/KmDtQ9zgyY9uug9EVIJ+frH6ru/JWw5GKsBNwW+jmeEnUnYu5sU16wJd/4q0g4hiNu9uUZtledQSs/fkTWc36xamA16Uf8gkhmwTd++4AMG5XpfgKeq7jxCm20NK1G48nkGUzWgeAWCndJiuDY4kAYxltVlRqWdLUVeKrf8KQx9A8TL0p9nki6Xbd3wUeIYNWfehePEE1Cf6fU8LOxwMR5t1Lw04sA1s82FFiSnLqdRqwpTeiTvME4tLJ4w5h38mJ8Hd7BjXyUQJebg6OI0oQQKBgR6Vg1xzBBdRxZwiMio6hBtx16EEn4KWGgCeQkFb6T6Ubtc6RqNefntpWN5uF9KqWqrPWhBNNZ5WidCTjBKx9zzj6c56kn5FmWxFW0kzcGgPHyZrF+KIzmQmMazJlIxe4qXn3zTK7KPilSXkqPM6k8kNi3LcV8NBQ3FngtimUuFTqFtSgkcMZwyjbXPcjC7E0UoCeEJzhrSHNaJDuvgTq+IahFXT2AEZn0gZZB7sycUQnZbOx14CoesoDgLh8FEYdfHbpKYIDqa4Uez8wIMolP/jfJMmTULtvU6DeT6tGAfED96SpP2JG3KbbuGi85NHCuo3+QiaX3kp8FVhOqzZ434MQjqCFCzN1LKtVCLfqYUVaCH4jjBGl9+mMzexffEVmx+3bb5+pvZ1KpUYTeaBftaY2WptJDYv0kIOdHUQ8S364KLlK2+VLun82UkXE1kMJnwyXyCeYW8VaCN+EkAmrCeib3kTi1zQ8pLbUQn3IMWaecAGcRIJwhKWNKVQXfdSDHjwzl+DfMHIa5YnG/EkHzkEHjIIuthecuf4J5ZD6v/JRQFeNTWUNIOdk5bMFeJZSrJAtFj4HLZfzUQkY/HZMiM+6eS/uo10RM2ydHOyHzlh4kPXhnT4p5mr2hpy+WOsq0o+A4kSZDc7F9/eLykKwKU3QD67xh6lDtDw7DFTaGaR+5RXqxaQTCBJQtO8408iiHYURNpeJ8xJQjRvI86D5cbONOBC9//EGsqwDQxHy7xGqAM00H7Y2XRtTx5piI3ZC6uVaqL2sYYAX6meUbe/h0V4IlO4dT4YU5KdqbAkQMH7M78apVYfP98G5FPC1ONOireynoXNDAsjnIfEopTttI4PVJSNtVv/cV0NHR5E5Ra1aQ0ysRrIZXv9hOMsdB3sy9hpvgy9rD4cvIRc3OC8Mrei9Yls4oDA2wdgHia7/RG8r7pncfHsKlQgQjNu61MBY5z0IYXtAMXaUXwtn74eb8pP0gWu9zNv07in+nwMqTt2fy36h4zDfDL1CNoXeRrx9Ge/Q0WcraDRb3psieJmMSRPOWNtHdPlfC+tqoXOM9CRSihdYcn6FSGDzvMc1rIYycsomRVjtiv5bCzReZ 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:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:54.2117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5040b25a-176f-4dc0-7121-08dccf15da48 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: DS1PEPF0001709C.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7973 From: Alejandro Lucero By definition a type2 cxl device will use the host managed memory for specific functionality, therefore it should not be available to other uses. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/region.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index d8c29e28e60c..45b4891035a6 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3699,6 +3699,9 @@ static int cxl_region_probe(struct device *dev) case CXL_DECODER_PMEM: return devm_cxl_add_pmem_region(cxlr); case CXL_DECODER_RAM: + if (cxlr->type != CXL_DECODER_HOSTONLYMEM) + return 0; + /* * The region can not be manged by CXL if any portion of * it is already online as 'System RAM' From patchwork Sat Sep 7 08:18:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795152 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2046.outbound.protection.outlook.com [40.107.244.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541B81494B2; Sat, 7 Sep 2024 08:19:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697201; cv=fail; b=dNF5Rbfd7ZGH3laKZ+ELZGlz6DkbViBUID0MIstx4Y567lDZ0hl9Rzp1ffXQon1NWYpve7wNHMdt6mgc6f4HThwAhE8DrwBe2sNHUwKQbC0FyPT5R8ZlJWF8XzNJUt5cUVJtihGM96k9HdruOlJ+EuhLkGzZdwypSSWh3rXYghM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697201; c=relaxed/simple; bh=obX9n7MXadAuIBrAyhN0m00OyWhUJIurTpIupkT+Cx0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qkF/s/OfJ95hvrbqXWATlEbLVIwSZjs2oPUwHdmcfETm0TjNp/GM0kOUyfQ0JFs59xSrp5xhtvw1TF4NtfjieFBZs3RcLxlhsx8lTAR2MTmTbqE1skSChakGSRMEWmXgQMt2lAEYAdi1aZaf+eq78LVqc0dgg0tjkXnKX1MFLus= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Sof5BFbx; arc=fail smtp.client-ip=40.107.244.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Sof5BFbx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Tbx5o1WV8i2iiTOFP+9iuJoHE+hi+lsi9igtquneuTcyv9u+mqOkLOt2GwfAslGFkVVfCYlHqUcgE5JlVbsukJdiDUTUbD283PCdZS7KDt8KeRAVNcok+wNbVik88wOdzY1Nu5QvAJcRjoikvWUdHBryWY6WM6jpSe6bBBAcxri7Og0UU0gnbbE9XPsIj+d+braHh1Q4JG7dVeKFRscd/k1NY1mObghcwKfbgy5PBnGsqF6/yqm3SARi24fv1tAZ8AXZdF/pTWSTpAnsXUIorG4HatHzq7pTmZQN/bS2wjFIcoJ+IB2JcSAPwcFg0tYWcTcSWZniV5W/jav7uuMQ2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=7GXAhfFDm73LSN7qZZ3zWKNkdBkAdsnph9VjuS0ulpo=; b=XPbVw0htKNM1lfdmexVQHnbsnQHcLVTE2IfNKG8n++Kt1Xk/rXHutU8GePeNWPyVjgMAMeZ3iZuGAwb48mwlvPW/82exYi1zclxbUPxvJtQ+PFLjnKXC7+49avjZJOpdiQmCHyEess02zCc9MtMV0cxPOSXBd0r/TrqoNC802lICV3n94syGbPbTs0sWMhwYfIsXmu8zzQRn2osHUgitdlooJNBGo1vQY9TJSq0fX8hi08d0/C94+ftWzfsGsnG7TjABBPYINfXOU0F6PnvVEAsxoBC1+Jie8hMHDeqACjEiMJTiLXnG2lKzJogWctKsygn56g5LLzDnUKkrBDxbOA== 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 (0) 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=7GXAhfFDm73LSN7qZZ3zWKNkdBkAdsnph9VjuS0ulpo=; b=Sof5BFbx0p1tW/W7+kkIm03dyo6CeSQGVev/X0/q5/Z0SitZA/HTCRYhIax5jq+9i7Suw+/3jq3YpPHG8gC7blW/xiHkv3vetn216Uhll3q4T+UKRYHIHEXytdduVNTpk869gzGrrqXIk3gi3YMC07DD1pL22BMOu+rnt3UonXo= Received: from DM6PR03CA0069.namprd03.prod.outlook.com (2603:10b6:5:100::46) by SA1PR12MB8742.namprd12.prod.outlook.com (2603:10b6:806:373::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Sat, 7 Sep 2024 08:19:56 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:100:cafe::81) by DM6PR03CA0069.outlook.office365.com (2603:10b6:5:100::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Sat, 7 Sep 2024 08:19:56 +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 DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:56 +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.2507.39; Sat, 7 Sep 2024 03:19:55 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:54 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 19/20] cxl: add function for obtaining params from a region Date: Sat, 7 Sep 2024 09:18:35 +0100 Message-ID: <20240907081836.5801-20-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|SA1PR12MB8742:EE_ X-MS-Office365-Filtering-Correlation-Id: ade8758e-d675-4bdf-3bd6-08dccf15db9e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: ETefO9GTTu9NIpL/7dlnihtRMIRNRV5guPTfVPSyVPFfm7czLnb98MHx7q6n5l9HXxX5lv5ikSjRDEsr92Dpk2JQ4XOZR4FcTA5C6nqZUni4JcNLRyLptijsWO1p7p8IK6zKELB5RhxWcLZwEmENw9BiJ6C1ZYib/F1vzbvBil8F4yVP76gq6iiByX5nlCoevXbboZwqyoGIiVhPQf4/PwiDctoAij8OZAfqA1d7Wvvc064mVgxr+MKWUyd18x8WC9+jK7Rs0bgjijlKb3GHhF9H6ZAq9UIcoeW/05PPPjykuavVpYITYvm5jYpGhXUHSSalrxMioccBnidT/+g7rY3fzUbtjhreRf8lNaFYr/iY+MLhnjv/sP6LO61gvT3XIJZ1Dt0TYRShie2nt2cXNhbxsYjR/U8iwmjSiwh/mrB7+vr/vAw+Ge71ljYekxZFHvAh+Jhh9PTFsji/AshliKWS/ZqJTz+noYfqI4B5xNHBVq7G/freh0fxaZB9C3txc+W0zIMQx5NeMiiMRNXFvyIP8bZFQxVx4Egbn91E7LBRySQ4WRvvBOEkurwyFVbjCajVR7lb3Bt2iW51sqc3M4noNjU9URdJl+UvM42TUm4nxL0EVtXs6VmbYRGtLK9MmpIj0BeJgzpY9nRlDk0xHG8E4TBMjKUAcTg1rqeaj7h39w3oM9NW/Iqq0eqc/htccMp2dttCjbJs3oMoHD8mJ39Vh/yZYnVB+wKAkRhzkDw0lQuUp47BXkNI0OLjpDpaRESUaH67c5DxD2HrZRR7PzhL16ogdeg6VjPzvW5ZIx7JjX476/GOvhZIfGpZIAB5WgeihuGtQc/r3GR3cudUb7LNhsTs64xx16rgM1lEnURSu4OrYazvWClgu0DO8bt6w4QkRAN5MVgQQsNWsV4bfXYGwJJPk2NnuhQI7E7v8NJ/pyS6h/fnA27rmhONQCkWM3cNoIfT5SMjW4V0sbki/0QYxb7F+jhOYEmoEvSBi/VZJzxNakV7RyYzuten1YG8wnR/FGnV//NlVIrmxJm0yZ+mklq6OVn3b9Zn2l8bpG7oQ9xLYi19b1B3Z1MfB5hnZJOxiDQ0MSlNj0p9vYiUFqDOxbYDxo68MOKyJYDUespgjqFfTNPx5XCAFX2Aum1XuZBubPhTrMIfauJKqTvXazMhtXDs/AfS1NaFSg860psLpITtMfiyTdj4DZLr0y8jfCclfqNFPfXKXjXScEe6rdeqWw2PIJoe4fH21yxes9aCvPjx5P+U3/EL5cJiXov86ERNoP2bRV9iUzQJauDv7E9M9ORMR9EjjjlzS9tcTRNxA8V+EhXjHJI/he/M93vOIGoPgtcCG/MfsgqCc3p6aCMmGdP/kgdxGEIiyZJ0REvErCVYZaa/o3H4pQzaMZtN2Qnmqz50aWi3I5MTeZ2jMjg2ZS64T5GtOma75VbtZAKjUHtSSBwhDBgW7lVK7EeA 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:(13230040)(36860700013)(1800799024)(82310400026)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:56.4517 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ade8758e-d675-4bdf-3bd6-08dccf15db9e 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: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8742 From: Alejandro Lucero A CXL region struct contains the physical address to work with. Add a function for given a opaque cxl region struct returns the params to be used for mapping such memory range. Signed-off-by: Alejandro Lucero --- drivers/cxl/core/region.c | 16 ++++++++++++++++ drivers/cxl/cxl.h | 2 ++ include/linux/cxl/cxl.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 45b4891035a6..e0e2342bb1ed 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2662,6 +2662,22 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd, return ERR_PTR(rc); } +int cxl_get_region_params(struct cxl_region *region, resource_size_t *start, + resource_size_t *end) +{ + if (!region) + return -ENODEV; + + if (!region->params.res) + return -ENOSPC; + + *start = region->params.res->start; + *end = region->params.res->end; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_region_params, CXL); + static ssize_t __create_region_show(struct cxl_root_decoder *cxlrd, char *buf) { return sysfs_emit(buf, "region%u\n", atomic_read(&cxlrd->region_id)); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 120e961f2e31..b26833ff52c0 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -904,6 +904,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port); int cxl_region_detach(struct cxl_endpoint_decoder *cxled); +int cxl_get_region_params(struct cxl_region *region, resource_size_t *start, + resource_size_t *end); /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. diff --git a/include/linux/cxl/cxl.h b/include/linux/cxl/cxl.h index 169683d75030..ef3bd8329bd8 100644 --- a/include/linux/cxl/cxl.h +++ b/include/linux/cxl/cxl.h @@ -76,4 +76,6 @@ struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, struct cxl_endpoint_decoder *cxled); int cxl_region_detach(struct cxl_endpoint_decoder *cxled); +int cxl_get_region_params(struct cxl_region *region, resource_size_t *start, + resource_size_t *end); #endif From patchwork Sat Sep 7 08:18:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 13795153 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2043.outbound.protection.outlook.com [40.107.102.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D17015B561; Sat, 7 Sep 2024 08:20:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697204; cv=fail; b=KBTMvpWJ0g+TAdw1MrJ+E+oeD4ylAfBsuzfVniroUvbEwTDpB2PfGXnjlE1uayQ+n+dYZxyDL+Zv4WXQrWGKbdW8BLMGsjjhkcFnxv+jk1rkfnFv4ioSRcXwnrRdpWf9OTPzGuarwT+fdTd7z8M6ANKJ3cLhB7+yL1H1/9XPc20= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725697204; c=relaxed/simple; bh=7GX6wIfJL5Gi/Ty6yGhWnBvgjsMoJjS9XScxPCDZD48=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IJsouTZvW425AWRGKS9YLTM1reNCfiqsvj+F2OWFEUs1wKMMXHV7BhE669WT4O3tgxsvJWI0TLexdjj0D8ri5Pal3JxP8WeJXm4PKzRS+Vlv/joKvxkqted3ji7dBZgB2grf1cP0X1ZDyqFPpLbPw0DoTS2PIUMv7v5s8ADqzHY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=1Yo4mYet; arc=fail smtp.client-ip=40.107.102.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="1Yo4mYet" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oHBxj6KW+R1U6SiEhL4Z7iKOtGZjEonRbCt5MAMHXU8h8eZw5gXzZUq9B3uMmwkO2PaK0DXinsb7H3mA1DXqDsY/BqeeOGQuyKSrJD7YSnr8OjMEDG9pURIo7d2delZRq17RBIz76Sr2vN2gd3CcjUa3LfsWGpBuuJAS5W0zsVmrOobIuCXUh8A92VeHrjbCaBOs1PP8Df99jPJxUmHGGeua4eXH3stZKzO2WEe7c4XkannwN3let7uf67LWT4Y1N/K2CWTuJ+fYqOcGe8i4FE9NShgk7qryiY4Hu6pExEroNsWF76zzCk4xwVW9fm2NVZ0uUxkiJRWpm1857C7U2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nombQutZ7tb66ymj7wDLaJLA0to7Z0ZjG6RUub4ZZJo=; b=Y/zIJk7Pk99Yva11B+QEjPFAok/VXnvRLnkZ6u5eanhLkZNjMvFnoswtBwH6QiABKyjVt6u1Ibwu5YclQveqSS2Zx5PyLw5ZSMEUP9nip0HP2HGCN6GC09dCvQy4RCKh8J2TGjaX88wUeCUArzFsd4IGAFN0CdpeqEZ1hgaJp6IP5DnAY+aRBX7/1yjuSTm3h1r0oAGfuc1NH90Qc15SEvjE2A48jENoXmYvk67RRrZOdEVCdvNf2AOJD2J5mrBH9An0WC+odVcaA7G0fcVeQBHIesED3GzuhrAIvfKCA5yOWBej/0pnRfoaREvN203ofD1K++KXXT/xE2ZdHn13uw== 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 (0) 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=nombQutZ7tb66ymj7wDLaJLA0to7Z0ZjG6RUub4ZZJo=; b=1Yo4mYetX7oUNB3CmHrXhKqODY+g3ogiZqSUEsBqeHUWTV8xJEiLwOTs4Myeouv9Q2MKCTYxfhqSNj165XvLji4BVzTFqat2Ny16CboK4vhpr5t99ZO/WvtIZR7rnd7/HEfZYvo+v9OQdlJh39bczMXYWpmol7sikc6I0lFprKs= Received: from DM6PR02CA0135.namprd02.prod.outlook.com (2603:10b6:5:1b4::37) by DS7PR12MB5744.namprd12.prod.outlook.com (2603:10b6:8:73::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Sat, 7 Sep 2024 08:19:58 +0000 Received: from DS1PEPF0001709A.namprd05.prod.outlook.com (2603:10b6:5:1b4:cafe::1d) by DM6PR02CA0135.outlook.office365.com (2603:10b6:5:1b4::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Sat, 7 Sep 2024 08:19:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0001709A.mail.protection.outlook.com (10.167.18.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Sat, 7 Sep 2024 08:19:58 +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.2507.39; Sat, 7 Sep 2024 03:19:57 -0500 Received: from xcbalucerop41x.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Sat, 7 Sep 2024 03:19:56 -0500 From: To: , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v3 20/20] efx: support pio mapping based on cxl Date: Sat, 7 Sep 2024 09:18:36 +0100 Message-ID: <20240907081836.5801-21-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> References: <20240907081836.5801-1-alejandro.lucero-palau@amd.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: alejandro.lucero-palau@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709A:EE_|DS7PR12MB5744:EE_ X-MS-Office365-Filtering-Correlation-Id: 95e2437b-487c-4fb5-1185-08dccf15dcf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: xxQM1YNunuoAqxiGOZYYlq39XU+/GHPr/j/vqktd0U0qVJPwIGk52AZolu4OQGjK7vIjR8E3nuCTm7KD4AOpwioCSHm2hXXOq9R0CYlEOx50gToc7ChNNBLgVvU64opQOkJjIZgfwsVeYbwiAhh/V0utUmUhddcj5c4T+2Vq/P1vSJsu8W6NYCkt7sJYC0472jOiZltgyEFH5tAt7GeDhp1Ahlkl37T4YSW1tF3mSsgjDPEbOp+DFaRj1M0yVCafHHggVwjBQMn+4uMHPhpDCvnWjs/OvTYcf6JW1cHXFTuxXS0iCpacTBi0PNY0X43zCufCOfgYwNSx9xx6eZk+eziR1PQwUkpGQ6A4EcbzHFGsVb0ffkv7ZerTR2cF2+tW0RTcZXQH6cAhFINufhou1DJq7BJOEuurWoHZ/BpLlvoznt0zp8Io82TWgm+mbPO2uUBUDng7G4HpqO8tMKLSIe/CQEoTzOLZGI9l0o7tH3ZpJBvWxTaoGPw88huuKPRHOkNtALrsQLVeJCwzPjJ1lrg3vS67LuspKo5wj2g1Yo7fNgDgGSjqmLp6T+ukM5VabGN3ZvRU6Su84TMvFtXgVjBCxSqO1Sa+KRzvKhyQ7jHiqpuH6/qbwZNxOdmXiQywy4Jrw/qHN7tWGWxcPZcbw6jvagDuJ6kYnax4iGWXw/BunBfHmyoaP/BWpPamgiZymZJJofkNESyTmle1ZZcUVykfZup8b0w610lL3N45z881+qhsCu+wPvGZz3Ex+IHr6eso/6YzYw9aJgLJA5OGKHjjM1ePQ1Lqp3cZbNOb0hFRkMFmpHJeZ2XzjlB+35FiMdtszKi1FVwkqTbi9ktmvMMVmhuwioL5lXMDu+GVvBxKklw3rCygaVod5MP1MNlmUjjJhlydo+x6mDmPl0CS21BukWqn2kqtxssTMTtKVMGMf7pJ7y6RYT4GI8FEEszRVzBLxcbrRadczZEcQ/KtHFRyttIQ9pjlwkm40D3FxYdBFvN4CMT+Z/FZeNQHUsqs5JZoFfqIXDHC6bxK9y7NGMR1D+n+LmV6U9UU3o+aLew3ZRoYnGcVMWc3Ueku1W7p6iJK6qOFuNQPe0TDInbmrabAzXTaaxofzLf1umDV9wVdN/bfZQEsI+4nC3eepZqTlN6dMEfxs97tI/0RfdD7t1Gt9V3r9wZEFSM2yYlGc0LIbG+59BZ/KxMemJXoQR5F7lVVa947eVNQD3/MmWUYuC7tFtIDALLZ7u+8o/taXRAcWTjHVwKZkrH5tuj9c1nBms6aq0r+5iU0EConSjke2bZaWqdVthQRiaeFgZaEpVb6ojnn1HcD8TzKz7tQKNQp5lp/WWG7v1Q9tnRcKx4MsnGdx8G/yN2lYN5QUAm30ehcPtVD245l614G6dyHTam6ppLwWb8exxke+fxYuU77h5JvowkyKZ4W7fCLSQu+5YhCbFeo7Um9UNZlVQbNOiOW 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:(13230040)(82310400026)(1800799024)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2024 08:19:58.6919 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95e2437b-487c-4fb5-1185-08dccf15dcf4 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: DS1PEPF0001709A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5744 From: Alejandro Lucero With a device supporting CXL and successfully initialised, use the cxl region to map the memory range and use this mapping for PIO buffers. Signed-off-by: Alejandro Lucero --- drivers/net/ethernet/sfc/ef10.c | 32 +++++++++++++++++++++------ drivers/net/ethernet/sfc/efx_cxl.c | 20 ++++++++++++++++- drivers/net/ethernet/sfc/mcdi_pcol.h | 12 ++++++++++ drivers/net/ethernet/sfc/net_driver.h | 2 ++ drivers/net/ethernet/sfc/nic.h | 2 ++ 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c index 7d69302ffa0a..d4e64cd0f7a4 100644 --- a/drivers/net/ethernet/sfc/ef10.c +++ b/drivers/net/ethernet/sfc/ef10.c @@ -24,6 +24,7 @@ #include #include #include +#include "efx_cxl.h" /* Hardware control for EF10 architecture including 'Huntington'. */ @@ -177,6 +178,12 @@ static int efx_ef10_init_datapath_caps(struct efx_nic *efx) efx->num_mac_stats); } + if (outlen < MC_CMD_GET_CAPABILITIES_V7_OUT_LEN) + nic_data->datapath_caps3 = 0; + else + nic_data->datapath_caps3 = MCDI_DWORD(outbuf, + GET_CAPABILITIES_V7_OUT_FLAGS3); + return 0; } @@ -949,7 +956,7 @@ static void efx_ef10_remove(struct efx_nic *efx) efx_mcdi_rx_free_indir_table(efx); - if (nic_data->wc_membase) + if (nic_data->wc_membase && !efx->efx_cxl_pio_in_use) iounmap(nic_data->wc_membase); rc = efx_mcdi_free_vis(efx); @@ -1263,8 +1270,19 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx) iounmap(efx->membase); efx->membase = membase; - /* Set up the WC mapping if needed */ - if (wc_mem_map_size) { + if (!wc_mem_map_size) + return 0; + + /* Using PIO through CXL mapping? */ + if ((nic_data->datapath_caps3 & + (1 << MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_LBN)) && + efx->efx_cxl_pio_initialised) { + nic_data->pio_write_base = efx->cxl->ctpio_cxl + + (pio_write_vi_base * efx->vi_stride + + ER_DZ_TX_PIOBUF - uc_mem_map_size); + efx->efx_cxl_pio_in_use = true; + } else { + /* Using legacy PIO BAR mapping */ nic_data->wc_membase = ioremap_wc(efx->membase_phys + uc_mem_map_size, wc_mem_map_size); @@ -1279,12 +1297,12 @@ static int efx_ef10_dimension_resources(struct efx_nic *efx) nic_data->wc_membase + (pio_write_vi_base * efx->vi_stride + ER_DZ_TX_PIOBUF - uc_mem_map_size); - - rc = efx_ef10_link_piobufs(efx); - if (rc) - efx_ef10_free_piobufs(efx); } + rc = efx_ef10_link_piobufs(efx); + if (rc) + efx_ef10_free_piobufs(efx); + netif_dbg(efx, probe, efx->net_dev, "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", &efx->membase_phys, efx->membase, uc_mem_map_size, diff --git a/drivers/net/ethernet/sfc/efx_cxl.c b/drivers/net/ethernet/sfc/efx_cxl.c index dd2dbfb8ba15..ef57f833b8a7 100644 --- a/drivers/net/ethernet/sfc/efx_cxl.c +++ b/drivers/net/ethernet/sfc/efx_cxl.c @@ -21,9 +21,9 @@ int efx_cxl_init(struct efx_nic *efx) { struct pci_dev *pci_dev = efx->pci_dev; + resource_size_t start, end, max = 0; struct efx_cxl *cxl; struct resource res; - resource_size_t max; u16 dvsec; int rc; @@ -132,10 +132,27 @@ int efx_cxl_init(struct efx_nic *efx) goto err_region; } + rc = cxl_get_region_params(cxl->efx_region, &start, &end); + if (rc) { + pci_err(pci_dev, "CXL getting regions params failed"); + goto err_map; + } + + cxl->ctpio_cxl = ioremap(start, end - start); + if (!cxl->ctpio_cxl) { + pci_err(pci_dev, "CXL ioremap region failed"); + rc = -EIO; + goto err_map; + } + + efx->efx_cxl_pio_initialised = true; + cxl_release_endpoint(cxl->cxlmd, cxl->endpoint); return 0; +err_map: + cxl_region_detach(cxl->cxled); err_region: cxl_dpa_free(efx->cxl->cxled); err_release: @@ -151,6 +168,7 @@ int efx_cxl_init(struct efx_nic *efx) void efx_cxl_exit(struct efx_nic *efx) { if (efx->cxl) { + iounmap(efx->cxl->ctpio_cxl); cxl_region_detach(efx->cxl->cxled); cxl_dpa_free(efx->cxl->cxled); cxl_release_resource(efx->cxl->cxlds, CXL_ACCEL_RES_RAM); diff --git a/drivers/net/ethernet/sfc/mcdi_pcol.h b/drivers/net/ethernet/sfc/mcdi_pcol.h index cd297e19cddc..c158a1e8d01b 100644 --- a/drivers/net/ethernet/sfc/mcdi_pcol.h +++ b/drivers/net/ethernet/sfc/mcdi_pcol.h @@ -16799,6 +16799,9 @@ #define MC_CMD_GET_CAPABILITIES_V7_OUT_DYNAMIC_MPORT_JOURNAL_OFST 148 #define MC_CMD_GET_CAPABILITIES_V7_OUT_DYNAMIC_MPORT_JOURNAL_LBN 14 #define MC_CMD_GET_CAPABILITIES_V7_OUT_DYNAMIC_MPORT_JOURNAL_WIDTH 1 +#define MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_OFST 148 +#define MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_LBN 17 +#define MC_CMD_GET_CAPABILITIES_V7_OUT_CXL_CONFIG_ENABLE_WIDTH 1 /* MC_CMD_GET_CAPABILITIES_V8_OUT msgresponse */ #define MC_CMD_GET_CAPABILITIES_V8_OUT_LEN 160 @@ -17303,6 +17306,9 @@ #define MC_CMD_GET_CAPABILITIES_V8_OUT_DYNAMIC_MPORT_JOURNAL_OFST 148 #define MC_CMD_GET_CAPABILITIES_V8_OUT_DYNAMIC_MPORT_JOURNAL_LBN 14 #define MC_CMD_GET_CAPABILITIES_V8_OUT_DYNAMIC_MPORT_JOURNAL_WIDTH 1 +#define MC_CMD_GET_CAPABILITIES_V8_OUT_CXL_CONFIG_ENABLE_OFST 148 +#define MC_CMD_GET_CAPABILITIES_V8_OUT_CXL_CONFIG_ENABLE_LBN 17 +#define MC_CMD_GET_CAPABILITIES_V8_OUT_CXL_CONFIG_ENABLE_WIDTH 1 /* These bits are reserved for communicating test-specific capabilities to * host-side test software. All production drivers should treat this field as * opaque. @@ -17821,6 +17827,9 @@ #define MC_CMD_GET_CAPABILITIES_V9_OUT_DYNAMIC_MPORT_JOURNAL_OFST 148 #define MC_CMD_GET_CAPABILITIES_V9_OUT_DYNAMIC_MPORT_JOURNAL_LBN 14 #define MC_CMD_GET_CAPABILITIES_V9_OUT_DYNAMIC_MPORT_JOURNAL_WIDTH 1 +#define MC_CMD_GET_CAPABILITIES_V9_OUT_CXL_CONFIG_ENABLE_OFST 148 +#define MC_CMD_GET_CAPABILITIES_V9_OUT_CXL_CONFIG_ENABLE_LBN 17 +#define MC_CMD_GET_CAPABILITIES_V9_OUT_CXL_CONFIG_ENABLE_WIDTH 1 /* These bits are reserved for communicating test-specific capabilities to * host-side test software. All production drivers should treat this field as * opaque. @@ -18374,6 +18383,9 @@ #define MC_CMD_GET_CAPABILITIES_V10_OUT_DYNAMIC_MPORT_JOURNAL_OFST 148 #define MC_CMD_GET_CAPABILITIES_V10_OUT_DYNAMIC_MPORT_JOURNAL_LBN 14 #define MC_CMD_GET_CAPABILITIES_V10_OUT_DYNAMIC_MPORT_JOURNAL_WIDTH 1 +#define MC_CMD_GET_CAPABILITIES_V10_OUT_CXL_CONFIG_ENABLE_OFST 148 +#define MC_CMD_GET_CAPABILITIES_V10_OUT_CXL_CONFIG_ENABLE_LBN 17 +#define MC_CMD_GET_CAPABILITIES_V10_OUT_CXL_CONFIG_ENABLE_WIDTH 1 /* These bits are reserved for communicating test-specific capabilities to * host-side test software. All production drivers should treat this field as * opaque. diff --git a/drivers/net/ethernet/sfc/net_driver.h b/drivers/net/ethernet/sfc/net_driver.h index 77261de65e63..893e7841ffb4 100644 --- a/drivers/net/ethernet/sfc/net_driver.h +++ b/drivers/net/ethernet/sfc/net_driver.h @@ -967,6 +967,7 @@ struct efx_cxl; * @dl_port: devlink port associated with the PF * @cxl: details of related cxl objects * @efx_cxl_pio_initialised: clx initialization outcome. + * @efx_cxl_pio_in_use: PIO using CXL mapping * @mem_bar: The BAR that is mapped into membase. * @reg_base: Offset from the start of the bar to the function control window. * @monitor_work: Hardware monitor workitem @@ -1154,6 +1155,7 @@ struct efx_nic { struct devlink_port *dl_port; struct efx_cxl *cxl; bool efx_cxl_pio_initialised; + bool efx_cxl_pio_in_use; unsigned int mem_bar; u32 reg_base; diff --git a/drivers/net/ethernet/sfc/nic.h b/drivers/net/ethernet/sfc/nic.h index 1db64fc6e909..b7148810acdb 100644 --- a/drivers/net/ethernet/sfc/nic.h +++ b/drivers/net/ethernet/sfc/nic.h @@ -151,6 +151,7 @@ enum { * @datapath_caps: Capabilities of datapath firmware (FLAGS1 field of * %MC_CMD_GET_CAPABILITIES response) * @datapath_caps2: Further Capabilities of datapath firmware (FLAGS2 field of + * @datapath_caps3: Further Capabilities of datapath firmware (FLAGS3 field of * %MC_CMD_GET_CAPABILITIES response) * @rx_dpcpu_fw_id: Firmware ID of the RxDPCPU * @tx_dpcpu_fw_id: Firmware ID of the TxDPCPU @@ -186,6 +187,7 @@ struct efx_ef10_nic_data { bool must_check_datapath_caps; u32 datapath_caps; u32 datapath_caps2; + u32 datapath_caps3; unsigned int rx_dpcpu_fw_id; unsigned int tx_dpcpu_fw_id; bool must_probe_vswitching;