From patchwork Mon Mar 31 14:45:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lucero Palau, Alejandro" X-Patchwork-Id: 14033680 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2088.outbound.protection.outlook.com [40.107.93.88]) (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 08687221564; Mon, 31 Mar 2025 14:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743432401; cv=fail; b=LsBavR2C9MSIDXJ//vrECBe82DRo5uukfIWCeYpbB2qqzRQ2iOxvNszB43atr/Oq1iNPrhvIpthZR4sxwF4iHdo8geOJ7gcpBQsk2Oh/JG+QCqH37zb/VbWjoPFM9WRpLOgOYzV8dDFCz+65owJ3Q1BzR//QoJGJk3xAFiZDXoo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743432401; c=relaxed/simple; bh=U/Xs62DG2XMYyqpnDd4mQ8M3V6z7kof4frnnHJUbU7Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sY6E15Bxzl/SXr28DOmgWhdi4m8UBBhqbee283nQrRGtbf/EfA/DxZ33Yf4fmki+CLlrFqCj+4OnotKRjkxhTlKj19k1DE0hKT+IPEXwJKnbGvioA1XxGU21cTVGNIv6cf5dTBqVNSaVAyynZI0qOM9/amTHdpjV2+m4UlWquW0= 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=kuk29wq7; arc=fail smtp.client-ip=40.107.93.88 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="kuk29wq7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rulIgDnxJFSFnCkBzAtwLSeV5AgVBpBuvSE1YhNLax+te4OxhLHfEvUCJ22AvLmWOmSlM3nC6MZ6HgvEhJQG8CovRPvXT5Yfqf/w4vRMmDYddrxgyqCcbjGvmh4N+5inCjXmbCkz8VoOy5x1YZR841PWjYHNrep4eZqvl+0EkcLbCAh1FQt7MMQ2ZxZr+NPIkhp6nGrf5nK/TBaYGkkMQljA1EyhU1FIRP9GG80nPuDNx3zDLr8jE6caw+xRoce+T+OTdS54AAL4JAzYlfA/isTR1rOxkySyjmv/fs2d0Y7Q/vPqZSYkHXG88YYyrOvJxQ1j6ICLXdNKtCzVdVBvpw== 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=i7fWiOpRzAkHdZpmCdjvyy9RMYU2NG5/BM2NwNDWvuI=; b=PKqvb5glpA6/rH97X54Wmam9miB+vI/QM9J067NNHdaVCWuV3i4xK55xV6WtsYbCImvqmlMGawsm1V9YY0j2Iw676ImsZOhfVbDyknK3qJmk2Q0dP7mv2JTOzyWskmvldmH+O9eQhVj5otsPnzJqjmv8e61WQKXq7nG+wqMTRYLlUWJzDOIOg0Gej2+0MIZS0JTmmeUv21YscGLD+ZSRwK2F3vYjKkL4nIllt1P41D5lotlgzv0Age900SKTCfqyY/YuwFIz0mJ0DFNzShQ8Jqus8nyQ8UwGENOfo1Z3UmMzxg4y9gA63qedi48w2hK01XlqIVuBNkNlhu6nagqxWQ== 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=i7fWiOpRzAkHdZpmCdjvyy9RMYU2NG5/BM2NwNDWvuI=; b=kuk29wq7kgEzYAZeIswutV1J3JrQJufKz6OW+g6W/SCXe/6DtgK0Ta2U+yhpn9TKSCqNMxiH5oHG/N8PbEgVhL7zGPWr8oEd9TADsVF5DzNk2+6u3ayGkjZkGo22/D3s7a5NENz8hEBSYVUkf1a8wNvE14B0iMG5kWIhqXTm5tw= Received: from PH7P221CA0057.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:33c::20) by CY5PR12MB6480.namprd12.prod.outlook.com (2603:10b6:930:33::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.44; Mon, 31 Mar 2025 14:46:37 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:510:33c:cafe::75) by PH7P221CA0057.outlook.office365.com (2603:10b6:510:33c::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8583.38 via Frontend Transport; Mon, 31 Mar 2025 14:46: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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8606.22 via Frontend Transport; Mon, 31 Mar 2025 14:46:36 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Mon, 31 Mar 2025 09:46:35 -0500 Received: from xcbalucerop40x.xilinx.com (10.180.168.240) 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 via Frontend Transport; Mon, 31 Mar 2025 09:46:34 -0500 From: To: , , , , , , , , CC: Alejandro Lucero , Zhi Wang , "Jonathan Cameron" , Ben Cheatham Subject: [PATCH v12 17/23] cxl/region: factor out interleave granularity setup Date: Mon, 31 Mar 2025 15:45:49 +0100 Message-ID: <20250331144555.1947819-18-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250331144555.1947819-1-alejandro.lucero-palau@amd.com> References: <20250331144555.1947819-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: SA2PEPF000015CB:EE_|CY5PR12MB6480:EE_ X-MS-Office365-Filtering-Correlation-Id: c6d34871-0038-4053-0f99-08dd7062d6b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|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E26zTYkxNzOuVoUD1IN/E3LFqgDQoo9yxu+54dtAMFmEPbxjy4bvYx3qHmHqcNjqtwEHCEoRfpVgg3FCFKvPqpU4eDWZwxReF6zsQUK6O3tR8SkJe8PNPVJlMDpQTXrfbc9Z0EW3tBc38RJn2jE47yH622uo8RqG7q+As8YNM2JaxidgrFMP7stxgfmXxThbqd50DLi0yg70fq1qK0Na/sDrODSoV2BwdEG8w+R5N1NkJfw93WvA5k6NJfSo56BGCXZZSvx9U9okCVGkWFaOba6vlL2foY6nHYWbFpGjUfLK0kx4ZIwYgygeJYnLEvcaeiNolAkjb63/QiT1p1o4Lme1iznYcQQUhVUR2En7gNrkeD+gGcss471/kXQFiic+AcMSLuMR1+ET1xvvdETVnDyzFQjbMqauLM6GqDdb6FWUfQ7lNF/nUqUnbt1RTr1+TUfJr722TAGam7Hi6SrNzet4wDqvY4= 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)(7416014)(376014)(34020700016)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2025 14:46:36.6887 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6d34871-0038-4053-0f99-08dd7062d6b1 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6480 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 Reviewed-by: Zhi Wang Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Reviewed-by: Ben Cheatham --- 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 816f974a4379..892fb799bf46 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -540,21 +540,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; @@ -570,16 +563,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;