From patchwork Mon Dec 16 16:10: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: 13910000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2072.outbound.protection.outlook.com [40.107.237.72]) (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 4E5D71B87FB; Mon, 16 Dec 2024 16:11:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734365489; cv=fail; b=Xez8H4SYJIE6jLXPouvCk6ob6aMCAwQ4K3Q+qypAnjDpxC5o+HqayrfG4yruf5js8W+HnQcap6TVnHo2/Hd867wUxNDFpKqfdYbrLsrUZu52r9krPyV9C0XszoZD1WWEbhxr7CAXSkLn7mmnAi3uIWpdoG9ie0pCQzUhUQ8UA0o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734365489; c=relaxed/simple; bh=yTJ3GlXO9NchaxYYlHh79Y8LjDMqKh4b1/15SRpt8Dg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZN8JUEnbVqxHiG6THKIAW/72bDOSHFWOknElOtlWle7wP3vpkCVYA2Bsokee9x79HXgIh32Hz6ffr4O2PgfP/q5rOtxu9A+33TEzjlWGxzg9hn+d6PDiLei4FUmcQQfF8Wro39NYvSuDLOvCe0i2kGmKdBnz0SiC6ieii+jlm/8= 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=Ipl822iB; arc=fail smtp.client-ip=40.107.237.72 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="Ipl822iB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p5gjGu7kIadD+dWiMMRAMT35JWaUMTsY6SR99UV0VDytF/FtkeS+TBfV+lIX20oEAdvJyqGuo2y6G4U+6R45M3wvRynf//yYVlC+nq55N5y/tPPdA+9/9IlcqjBQrArFhpPe+Pzc8dB9I/eb12Hyfs+bUVoodSqw7u6dfLT5cOF3LzP9lshEmDpxjbaZ03yj3c5IeFM4M3QBnrvvoyix60pSLx4UN1TBdo8evYOthhK9QBZLjVQvGP0lpw36gp98XStNpU10QniCKI0RDIQryNDVT4H6ByDakdFww5tWJ2q8yXPe/DhveLXQ6ujUunAKmJHjJP//sny1yMLkdsNBrw== 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=WkeJ4TP/KQC/0vbJS36U5TxIeXAJCOV0+NwsnZh34bQ=; b=DhlFjLJQB423bK+PwQBEi8Kx3v+QIvqhQh1xOcXpxyNI9YxBVG2Tm1IKfPh+M5Q1wVoZpfHtqADbVSOiTi9KbT3RwCi1yel+jebI+mruOwum4ImyZTSLBCtlJ7ROlK5foxrzhvqN+H5aKKaPg/He2WcRH2my4wJI1uS5jiq2oLoYS1LDrUSYTOLPnB+1mpzqhQEcMI9aGCP/cOLEN80CvMDgbXjvf8HSJTuyNBXatKD33RYGt6jihcI7szKQsWBFaR5kgbb7H0dn7Q58qUN08u3d6fPAS9DtnsE/YFxd4qz2yCZ+kataoz+AXtkwxlLg/9kR4QHlV8ey+oBkcT3V8g== 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=WkeJ4TP/KQC/0vbJS36U5TxIeXAJCOV0+NwsnZh34bQ=; b=Ipl822iBm2p1/AEys8v4AO7ftMcDLICYzb7mPpzI57DCGjbFurU6aGyj1C7/JRCwP1ne2N4GcDypTcBTnK8f5geKv3wOe7vYu8BGW0XrPuBOWJrFFfaS1fSp7eLVkU89MquXz0zu5HAgaw9W66P86OoEhR6vi2M4MexqLgK0cBE= Received: from CH5PR05CA0019.namprd05.prod.outlook.com (2603:10b6:610:1f0::27) by BY5PR12MB4211.namprd12.prod.outlook.com (2603:10b6:a03:20f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.21; Mon, 16 Dec 2024 16:11:23 +0000 Received: from CH1PEPF0000AD74.namprd04.prod.outlook.com (2603:10b6:610:1f0:cafe::58) by CH5PR05CA0019.outlook.office365.com (2603:10b6:610:1f0::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8272.9 via Frontend Transport; Mon, 16 Dec 2024 16:11:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD74.mail.protection.outlook.com (10.167.244.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Mon, 16 Dec 2024 16:11:23 +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, 16 Dec 2024 10:11:22 -0600 Received: from xcbalucerop41x.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, 16 Dec 2024 10:11:21 -0600 From: To: , , , , , , , , , CC: Alejandro Lucero Subject: [PATCH v8 21/27] cxl/region: factor out interleave granularity setup Date: Mon, 16 Dec 2024 16:10:36 +0000 Message-ID: <20241216161042.42108-22-alejandro.lucero-palau@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20241216161042.42108-1-alejandro.lucero-palau@amd.com> References: <20241216161042.42108-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: CH1PEPF0000AD74:EE_|BY5PR12MB4211:EE_ X-MS-Office365-Filtering-Correlation-Id: fee9a48b-1178-441c-27d5-08dd1dec491c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|376014|1800799024|82310400026|921020; X-Microsoft-Antispam-Message-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auF2JN/0jnVUJ0lt+UymruwL63yN124hEWMK6lYnaaS5dRgzqkXHvd8+YsNAXQKKtgu16yWBjMkdxyjWkaroR3iuLzUTDCzpCvnwbLyB0T39F9N92BBK9qo2417OjRZP51Lq+gSBVvkTn6SwQ8Wn4hc4NmiJqXJNiWhkLN+Z7DFjpa2nn/SfPLok44QZXuMkasggo47M1pQ0WV3aZ9Tlv0VUFveTds/D5Zd4OvqX2SAcRq9yjq2E596cUfhya4ZhP9Rfl6yQebYwxuMTVqrZp9K6IRIjF2rGya52RCzRYf8cmCHc5qMwBnZZllQ+8CUrheNQH0pgwCotuvxLmojrj1Pdl+aT6AGTJgUKaaSfs0R9kFkLOXAtyY74Ha2YWkYYLKUziMNaps3l80oyupY5ZoCtFkU0TUCxsBQ6ELaJrvZUGoGpM2JGPzzfIWC1Bifb8HF1JEf/+dPwSu5udAm4bw71 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)(1800799024)(82310400026)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2024 16:11:23.1766 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fee9a48b-1178-441c-27d5-08dd1dec491c 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: CH1PEPF0000AD74.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4211 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 Reviewed-by: Zhi Wang Reviewed-by: Dave Jiang --- 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 f02f0c0f28cf..3d9bc7d7c0c4 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;