From patchwork Mon Oct 7 23:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 13825435 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 731B2192588; Mon, 7 Oct 2024 23:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728343034; cv=none; b=FeoPdIgPbcNluxVa+SKUE0ZvfP+f/dYw4BsCabStRm4lBB99nCt7qH4NDsTxomvJud6G0Mlhn1lW8sNVtejIWWH3QN7QnxVj872rFp2uBTlCkTEFV7N9x7NrWDnlSbEnIyjWOlbLuVJep0JMGkGAH+/YNX+yIIaVBNk0/dW9LV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728343034; c=relaxed/simple; bh=oySoVzqba1kb9G76fXV+2nmWRG0tWG+HBET/md+uTvc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uG0zI+y6zffv4g/8O8tT3IDxlcZejvZUfvik0HKmGju3BcdPsHNfKXaYReXjaOqcXXEfaDLvDkGTKZcT1U27k7DMofBGxDZeTJnbtZTbUBz1S5Hv9FwZd6+4MM85F1tsWofiut/a9GVxuIgQyqIdnTrsipB+YRbPhV2GhxdU3Ts= 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=ixptUsJW; arc=none smtp.client-ip=192.198.163.8 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="ixptUsJW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728343033; x=1759879033; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=oySoVzqba1kb9G76fXV+2nmWRG0tWG+HBET/md+uTvc=; b=ixptUsJW20XTa6xbmaruykcpS97WjOfjFOUgw72zq+SAFF3AHRsh28Qp +D0RvV/AJpUrqyYETkwKQATOH1+/pBsqlq/uIk5vScwwPKwJYmmIjImIX jQ2hfUa9qP80+25O71rlIvIo6E2sEiJQd4Av0mJitv4ZIRqSdUihZfeKU 9gZEJarfKs8ONm9+QK9b8GRBKwKddc456RZI0Lw8a3H4nSiuTlbQKx9zR QlkVKekOYJjjYjWh1CDlpDhX6TxYmWVj3dbMQpuFHuRGuhZax8d2zqMcr R33JAtNju0cz2MwsHGVljK3HVGLSOzWiQvTGqAgIoinng/F8GJfXV4tSa A==; X-CSE-ConnectionGUID: 6FBrNnRtT6qdPZJ9XSwpkw== X-CSE-MsgGUID: 6p7qnQ1TRkObqc8Scnas3w== X-IronPort-AV: E=McAfee;i="6700,10204,11218"; a="45036942" X-IronPort-AV: E=Sophos;i="6.11,185,1725346800"; d="scan'208";a="45036942" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2024 16:16:59 -0700 X-CSE-ConnectionGUID: WmluaNqnTeayYzBqIuVj8A== X-CSE-MsgGUID: 4w1wFf9OS1qPcGB5Q7OgiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,185,1725346800"; d="scan'208";a="75309139" Received: from ldmartin-desk2.corp.intel.com (HELO localhost) ([10.125.110.112]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Oct 2024 16:16:56 -0700 From: Ira Weiny Date: Mon, 07 Oct 2024 18:16:21 -0500 Subject: [PATCH v4 15/28] cxl/region: Refactor common create region code Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241007-dcd-type2-upstream-v4-15-c261ee6eeded@intel.com> References: <20241007-dcd-type2-upstream-v4-0-c261ee6eeded@intel.com> In-Reply-To: <20241007-dcd-type2-upstream-v4-0-c261ee6eeded@intel.com> To: Dave Jiang , Fan Ni , Jonathan Cameron , Navneet Singh , Jonathan Corbet , Andrew Morton Cc: Dan Williams , Davidlohr Bueso , Alison Schofield , Vishal Verma , Ira Weiny , linux-btrfs@vger.kernel.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728342968; l=2376; i=ira.weiny@intel.com; s=20221211; h=from:subject:message-id; bh=oySoVzqba1kb9G76fXV+2nmWRG0tWG+HBET/md+uTvc=; b=Z9mzbCT9+x9RtElP9/Bu7froCWyfuXRo5gKK5TR3S46FklNREcvIIDcGPomGxXia55hZhPFth sNOsavotjsKCE0u9gV/VLwCRbfbHJUivG4IdGLzO2hKEFW+gE5xJKIb 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 Reviewed-by: Jonathan Cameron Reviewed-by: Fan Ni Reviewed-by: Alison Schofield --- 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 ab00203f285a..2ca6148d108c 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2552,9 +2552,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; @@ -2564,31 +2563,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);