From patchwork Fri Aug 16 14:00:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13766334 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 CCAC11BB6B7; Fri, 16 Aug 2024 14:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723816819; cv=none; b=EsmXcRYpWRyugXGPTPrVTuiPIYAPY8gLh9X+0kpzIV+OhOIQzgcIYBeMrtPr25isxnhspJaPEF0XncPaNe8H/q8gRFyEDT8sg8HjzWNBHQEsW1cvtZcYJgfrj3MXwJDRisg7jBTMRATo27+XVMlg4XvdjhTZ2A/M44YP4EC45u8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723816819; c=relaxed/simple; bh=CHaiWuhlK2oilB02S0vAQGpbVxQJYSALMGWJkD3RrYQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=do+/4VeyBXjNhF35pXGrV23njrYYGCwPILVxCpXJHz8NpQv8vb1MgFU99IgURDlqfubCPiLPr0r6LcT2HakdjB0TmOEhvtaqXhBc/0iUWXyS9Y+Z681hFs1TZScR+TZ5PzzP4w3Sj+/sl980V7KNUvswJol0midfW0gFYFQoPUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=junJ56aO; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="junJ56aO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723816817; x=1755352817; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=CHaiWuhlK2oilB02S0vAQGpbVxQJYSALMGWJkD3RrYQ=; b=junJ56aOEO91ySnWnhGgI7n0jmxagpiAbEARVPWvtbXT7zZDc2QJlr/A NMhr9B0s2tNWW0yJSAFr4zj1bSjf9wiNcXaBnNeyIPQrq7lrkSgYfvuXc 8En4Z/6ozwjrodr5VRZ4BKSanGq+yfbktfY3JVuu0A22ZhATykbWUOFik NEnxsxY5OKg21J7douketTT2aV+rdwMcBxojVtWQJOasg5PDY804PRthn o6SAAzQBEgxRg5L0wbLUIIGvpJumouBLarhBFVOyxyWtQctLluGzFOk4+ zSCwpK8Hoh3P7uPNPB3fX6PBIIE8iNyl+yfpq6JtMSPCbRgjzVfMF+aoa Q==; X-CSE-ConnectionGUID: rTiy98WiQQ+SxAFQlR6r+A== X-CSE-MsgGUID: RxY67ZhvSWeJ1sFZhaRjlw== X-IronPort-AV: E=McAfee;i="6700,10204,11166"; a="22272805" X-IronPort-AV: E=Sophos;i="6.10,151,1719903600"; d="scan'208";a="22272805" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2024 07:00:17 -0700 X-CSE-ConnectionGUID: z5oAXfV/Rumu2d/evbcU5Q== X-CSE-MsgGUID: QEjvY54FSe+UBuX/mqx16g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,151,1719903600"; d="scan'208";a="90411324" Received: from iweiny-mobl.amr.corp.intel.com (HELO localhost) ([10.125.111.52]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2024 07:00:17 -0700 From: Ira Weiny Date: Fri, 16 Aug 2024 09:00:00 -0500 Subject: [PATCH v2 12/25] cxl/region: Refactor common create region code Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240816-dcd-type2-upstream-v2-12-20189a10ad7d@intel.com> References: <20240816-dcd-type2-upstream-v2-0-20189a10ad7d@intel.com> In-Reply-To: <20240816-dcd-type2-upstream-v2-0-20189a10ad7d@intel.com> To: Dave Jiang , Fan Ni , Jonathan Cameron , Navneet Singh Cc: Dan Williams , Davidlohr Bueso , Alison Schofield , Vishal Verma , Ira Weiny , linux-btrfs@vger.kernel.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.13-dev-2d940 X-Developer-Signature: v=1; a=ed25519-sha256; t=1723816790; l=2376; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=CHaiWuhlK2oilB02S0vAQGpbVxQJYSALMGWJkD3RrYQ=; b=cL9fGj/DZSo6UW/kPXrOdJ6X7WcGZBSw70jnsvIREtJB6UdKuilQCiGvqZDznfh0FyiYdokuK 1XK2oAQxPhHCf5sMJxCn6A2lOKKfWYR5asYkZt9Z54CT37G/Kt8z93v X-Developer-Key: i=ira.weiny@intel.com; a=ed25519; pk=noldbkG+Wp1qXRrrkfY1QJpDf7QsOEthbOT7vm0PqsE= create_pmem_region_store() and create_ram_region_store() are identical with the exception of the region mode. With the addition of DC region mode this would end up being 3 copies of the same code. Refactor create_pmem_region_store() and create_ram_region_store() to use a single common function to be used in subsequent DC code. Suggested-by: Fan Ni Signed-off-by: Ira Weiny --- drivers/cxl/core/region.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 650fe33f2ed4..f85b26b39b2f 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2553,9 +2553,8 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); } -static ssize_t create_pmem_region_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) +static ssize_t create_region_store(struct device *dev, const char *buf, + size_t len, enum cxl_region_mode mode) { struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev); struct cxl_region *cxlr; @@ -2565,31 +2564,26 @@ static ssize_t create_pmem_region_store(struct device *dev, if (rc != 1) return -EINVAL; - cxlr = __create_region(cxlrd, CXL_REGION_PMEM, id); + cxlr = __create_region(cxlrd, mode, id); if (IS_ERR(cxlr)) return PTR_ERR(cxlr); return len; } + +static ssize_t create_pmem_region_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + return create_region_store(dev, buf, len, CXL_REGION_PMEM); +} DEVICE_ATTR_RW(create_pmem_region); static ssize_t create_ram_region_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { - struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev); - struct cxl_region *cxlr; - int rc, id; - - rc = sscanf(buf, "region%d\n", &id); - if (rc != 1) - return -EINVAL; - - cxlr = __create_region(cxlrd, CXL_REGION_RAM, id); - if (IS_ERR(cxlr)) - return PTR_ERR(cxlr); - - return len; + return create_region_store(dev, buf, len, CXL_REGION_RAM); } DEVICE_ATTR_RW(create_ram_region);