From patchwork Tue Jan 18 20:25:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68E9FC433F5 for ; Tue, 18 Jan 2022 20:20:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349131AbiARUUb (ORCPT ); Tue, 18 Jan 2022 15:20:31 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349098AbiARUUa (ORCPT ); Tue, 18 Jan 2022 15:20:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537230; x=1674073230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5BfBNZA4cDZx28lOEHJoMmO/axgVrEIzIMxH3cnGJeE=; b=cHZk665GqzuNRS9Qe2adwr2y08Syy607h9rw2A0Vi2ilmu3a8iKYSA6k b7coJRrIq5AEdi94OS2wuh1yxD8bWjAsECU6sYbCehjrEzGn0PAsrGhEW 6yrvjh/nqSasy6Ms6yjbp5ZgbFGRkuoiGq/9tunpkcWc9E8Tp6eyIKy9V Q8624YVO/bI7B09yFVEzz+3YCQfTCOEEM3bBaAW9zXo0DkmF/ziVwSiyk fHTKYMQT7DXnu4esr+l4wWi7SgC61T1oZWUmGdNMqvf5hm7ey5umwlJK4 cmjqhKibdSTE6yHh9URWl7b9duyjLludvM1zU/HRdlQSnFHcLWjpnBAG9 g==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250308" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250308" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:30 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953850" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:29 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 1/6] libcxl: add GET_PARTITION_INFO mailbox command and accessors Date: Tue, 18 Jan 2022 12:25:10 -0800 Message-Id: <2072a34022dabcc92e3cc73b16c8008656e1084e.1642535478.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Users need access to the CXL GET_PARTITION_INFO mailbox command to inspect and confirm changes to the partition layout of a memory device. Add libcxl APIs to create a new GET_PARTITION_INFO mailbox command, the command output data structure (privately), and accessor APIs to return the different fields in the partition info output. Per the CXL 2.0 specification, devices report partition capacities as multiples of 256MB. Define and use a capacity multiplier to convert the raw data into bytes for user consumption. Use byte format as the norm for all capacity values produced or consumed using CXL Mailbox commands. Signed-off-by: Alison Schofield Reviewed-by: Dan Williams --- cxl/lib/libcxl.c | 41 +++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 10 ++++++++++ cxl/libcxl.h | 5 +++++ util/size.h | 1 + 5 files changed, 62 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 3390eb9..58181c0 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1160,6 +1160,47 @@ CXL_EXPORT ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, return length; } +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_get_partition_info(struct cxl_memdev *memdev) +{ + return cxl_cmd_new_generic(memdev, + CXL_MEM_COMMAND_ID_GET_PARTITION_INFO); +} + +#define cmd_partition_get_capacity_field(cmd, field) \ +do { \ + struct cxl_cmd_get_partition_info *c = \ + (struct cxl_cmd_get_partition_info *)cmd->send_cmd->out.payload;\ + int rc = cxl_cmd_validate_status(cmd, \ + CXL_MEM_COMMAND_ID_GET_PARTITION_INFO); \ + if (rc) \ + return ULLONG_MAX; \ + return le64_to_cpu(c->field) * CXL_CAPACITY_MULTIPLIER; \ +} while (0) + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_active_volatile_bytes(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, active_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_active_persistent_bytes(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, active_persistent_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_next_volatile_bytes(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, next_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, next_persistent_cap); +} + CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd) { struct cxl_memdev *memdev = cmd->memdev; diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index 077d104..e019c3c 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -70,6 +70,11 @@ global: cxl_memdev_zero_label; cxl_memdev_write_label; cxl_memdev_read_label; + cxl_cmd_new_get_partition_info; + cxl_cmd_partition_info_get_active_volatile_bytes; + cxl_cmd_partition_info_get_active_persistent_bytes; + cxl_cmd_partition_info_get_next_volatile_bytes; + cxl_cmd_partition_info_get_next_persistent_bytes; local: *; }; diff --git a/cxl/lib/private.h b/cxl/lib/private.h index a1b8b50..dd9234f 100644 --- a/cxl/lib/private.h +++ b/cxl/lib/private.h @@ -7,6 +7,7 @@ #include #include #include +#include #define CXL_EXPORT __attribute__ ((visibility("default"))) @@ -104,6 +105,15 @@ struct cxl_cmd_get_health_info { le32 pmem_errors; } __attribute__((packed)); +struct cxl_cmd_get_partition_info { + le64 active_volatile_cap; + le64 active_persistent_cap; + le64 next_volatile_cap; + le64 next_persistent_cap; +} __attribute__((packed)); + +#define CXL_CAPACITY_MULTIPLIER SZ_256M + /* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */ #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK BIT(0) #define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK BIT(1) diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 89d35ba..08fd840 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -109,6 +109,11 @@ ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf, unsigned int length); struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev, void *buf, unsigned int offset, unsigned int length); +struct cxl_cmd *cxl_cmd_new_get_partition_info(struct cxl_memdev *memdev); +unsigned long long cxl_cmd_partition_info_get_active_volatile_bytes(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_active_persistent_bytes(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_next_volatile_bytes(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd); #ifdef __cplusplus } /* extern "C" */ diff --git a/util/size.h b/util/size.h index a0f3593..e72467f 100644 --- a/util/size.h +++ b/util/size.h @@ -15,6 +15,7 @@ #define SZ_4M 0x00400000 #define SZ_16M 0x01000000 #define SZ_64M 0x04000000 +#define SZ_256M 0x10000000 #define SZ_1G 0x40000000 #define SZ_1T 0x10000000000ULL From patchwork Tue Jan 18 20:25:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C1FCC433FE for ; Tue, 18 Jan 2022 20:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349098AbiARUUb (ORCPT ); Tue, 18 Jan 2022 15:20:31 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349122AbiARUUa (ORCPT ); Tue, 18 Jan 2022 15:20:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537230; x=1674073230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rXeIZWlZ4MaR5SiTd9P5N37auWUvFhOUNkOo5BEkuak=; b=e6qCFzBWrQSPZAd7VIRKXMvHwrnpTMo9DL5m5PHVvNxMbnSNb8MiTRuq NqKE7Isy3893g33mwfteRGEAOEWuKV3fnBMKprR5ElnBClqMcIi8mGup1 mbAStlx2v9pEvilYHDQf6GUeMDf4Y2/Sr/qzmUh34ZZFCNWuJggJvh3nc wKchRlqIYleG/156uCxNVX2gB94JtbiM1DkVRrjCBFcgq96onDd43j+O8 7iMI7odzlkIJtu9nCaRlJevQWiZXXGoXDyAuGTcFmUZCDBFoOlNuDVVWg om0PIW/EHx+e0vpQKSt5iF7Hf71YKrFhgDCyU+TEAZ1IS0EdSeuBFhPgh g==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250309" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250309" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:30 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953854" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:30 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 2/6] libcxl: add accessors for capacity fields of the IDENTIFY command Date: Tue, 18 Jan 2022 12:25:11 -0800 Message-Id: <55800f227e4d72f90fcdd49affb352fe4386f628.1642535478.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Users need access to a few additional fields reported by the IDENTIFY mailbox command: total, volatile_only, and persistent_only capacities. These values are useful when defining partition layouts. Add accessors to the libcxl API to retrieve these values from the IDENTIFY command. The fields are specified in multiples of 256MB per the CXL 2.0 spec. Use the capacity multiplier to convert the raw data into bytes for user consumption. Signed-off-by: Alison Schofield --- cxl/lib/libcxl.c | 29 +++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 3 +++ cxl/libcxl.h | 3 +++ 3 files changed, 35 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 58181c0..1fd584a 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1105,6 +1105,35 @@ CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd) return le32_to_cpu(id->lsa_size); } +#define cmd_identify_get_capacity_field(cmd, field) \ +do { \ + struct cxl_cmd_identify *c = \ + (struct cxl_cmd_identify *)cmd->send_cmd->out.payload;\ + int rc = cxl_cmd_validate_status(cmd, \ + CXL_MEM_COMMAND_ID_IDENTIFY); \ + if (rc) \ + return ULLONG_MAX; \ + return le64_to_cpu(c->field) * CXL_CAPACITY_MULTIPLIER; \ +} while (0) + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_total_bytes(struct cxl_cmd *cmd) +{ + cmd_identify_get_capacity_field(cmd, total_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_volatile_only_bytes(struct cxl_cmd *cmd) +{ + cmd_identify_get_capacity_field(cmd, volatile_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_persistent_only_bytes(struct cxl_cmd *cmd) +{ + cmd_identify_get_capacity_field(cmd, persistent_capacity); +} + CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode) { diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index e019c3c..b7e969f 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -31,6 +31,9 @@ global: cxl_cmd_get_out_size; cxl_cmd_new_identify; cxl_cmd_identify_get_fw_rev; + cxl_cmd_identify_get_total_bytes; + cxl_cmd_identify_get_volatile_only_bytes; + cxl_cmd_identify_get_persistent_only_bytes; cxl_cmd_identify_get_partition_align; cxl_cmd_identify_get_label_size; cxl_cmd_new_get_health_info; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 08fd840..46f99fb 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -68,6 +68,9 @@ int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd); int cxl_cmd_get_out_size(struct cxl_cmd *cmd); struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev); int cxl_cmd_identify_get_fw_rev(struct cxl_cmd *cmd, char *fw_rev, int fw_len); +unsigned long long cxl_cmd_identify_get_total_bytes(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_volatile_only_bytes(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_persistent_only_bytes(struct cxl_cmd *cmd); unsigned long long cxl_cmd_identify_get_partition_align(struct cxl_cmd *cmd); unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd); struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev); From patchwork Tue Jan 18 20:25:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FF99C4332F for ; Tue, 18 Jan 2022 20:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349122AbiARUUb (ORCPT ); Tue, 18 Jan 2022 15:20:31 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349138AbiARUUb (ORCPT ); Tue, 18 Jan 2022 15:20:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537231; x=1674073231; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+vOG/MGG3HFOK6Q+Ameq9bNgHeIQFxU/FTVdUSHEkes=; b=C8S1hpq8Lb5TGRhmm/NQAhxVTVByHJjDZ3bEcnhY3C3DZPhj2RSEKqbH vJcA6DwcOS0Ps7nIvQkK4AyVAEuDEcFnkE8VKi4DGlAQZAt1bqb91unF4 gbZ72JWncCvwOBNWNiepNuVt6Pc4thCrJWO8yIxIrtUd2jc5XAYK4Dyb8 bPaz0ACgRH7jqoTkEWWtlJzYK627HmRKZvIipkYZNNYWLIDbyCX3GIKgB wAJEv5rRdk7qkSltr9yV/KdoR1Syeebq1daXdd7bBL2fzkj5Hz3D35iYF NjgY3T1mtdUG8FUqN5N/ZXHpK50mmzya3DPp5HiZxARFluJY4KyT8+A4E A==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250311" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250311" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:31 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953858" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:30 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 3/6] libcxl: return the partition alignment field in bytes Date: Tue, 18 Jan 2022 12:25:12 -0800 Message-Id: <6e295b9c3ab676906e6f58588b54071ea968e0cd.1642535478.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Per the CXL specification, the partition alignment field reports the alignment value in multiples of 256MB. In the libcxl API, values for all capacity fields are defined to return bytes. Update the partition alignment accessor to return bytes so that it is in sync with other capacity related fields. Signed-off-by: Alison Schofield Reviewed-by: Dan Williams --- cxl/lib/libcxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 1fd584a..5b1fc32 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1089,7 +1089,7 @@ CXL_EXPORT unsigned long long cxl_cmd_identify_get_partition_align( if (cmd->status < 0) return cmd->status; - return le64_to_cpu(id->partition_align); + return le64_to_cpu(id->partition_align) * CXL_CAPACITY_MULTIPLIER; } CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd) From patchwork Tue Jan 18 20:25:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9044CC43217 for ; Tue, 18 Jan 2022 20:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349138AbiARUUc (ORCPT ); Tue, 18 Jan 2022 15:20:32 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349141AbiARUUb (ORCPT ); Tue, 18 Jan 2022 15:20:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537231; x=1674073231; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qOTX1D+R1jhV419hdzUp4XYWbde0zFCZvBd7GlKjnas=; b=NvfF5FPcaOHY8LO3c9kfr4iRKddgaf1ccegMqFmIo42qRj1fdbhBmvdz ti8O03kdJ59M1LQcUE8yP25Y+Ys5IwCEps+l5n6C1tO/9MxmNGf8ru7eL pmcO/3BfCXqetqT7L2c87gitkZrG1Ghx0U6qy/uERGgW4i+utQ7gNhwXd eFRqYyzegCr6BEbMwpFspFmMPDurJw+zwJK2vWvUKWjDuDJNjA4JMLmOy XchOMh0bEt0izDURAxq/XUblID3KqqUdzKN3LUbl1HHm+0Q+Io4pjgfkR 4CTdLaA+aVERzo2mJOjj6EActg1bM/Bzcw95miuLOdALjYs/5abXBM1Cn Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250312" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250312" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:31 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953863" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:31 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 4/6] cxl: add memdev partition information to cxl-list Date: Tue, 18 Jan 2022 12:25:13 -0800 Message-Id: <5c20a16be96fb402b792b0b23cc1373651cef111.1642535478.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Users may want to check the partition information of a memory device using the CXL command line tool. This is useful for understanding the active, as well as creating the next, partition layout. Add an option the 'cxl list' command to display partition information. Include all of the fields from GET_PARTITION_INFO and the partitioning related fields from the IDENTIFY mailbox command. Example: "partition_info":{ "active_volatile_bytes":273535729664, "active_persistent_bytes":0, "next_volatile_bytes":0, "next_persistent_bytes":0, "total_bytes":273535729664, "volatile_only_bytes":0, "persistent_only_bytes":0, "partition_alignment_bytes":268435456 } Signed-off-by: Alison Schofield Reviewed-by: Dan Williams --- Documentation/cxl/cxl-list.txt | 23 +++++++ cxl/json.c | 114 +++++++++++++++++++++++++++++++++ cxl/list.c | 5 ++ util/json.h | 1 + 4 files changed, 143 insertions(+) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index c8d10fb..912ac11 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -85,6 +85,29 @@ OPTIONS } ] ---- +-I:: +--partition:: + Include partition information in the memdev listing. Example listing: +---- +# cxl list -m mem0 -I +[ + { + "memdev":"mem0", + "pmem_size":0, + "ram_size":273535729664, + "partition_info":{ + "active_volatile_bytes":273535729664, + "active_persistent_bytes":0, + "next_volatile_bytes":0, + "next_persistent_bytes":0, + "total_bytes":273535729664, + "volatile_only_bytes":0, + "persistent_only_bytes":0, + "partition_alignment_bytes":268435456 + } + } +] +---- include::human-option.txt[] diff --git a/cxl/json.c b/cxl/json.c index e562502..e51a96e 100644 --- a/cxl/json.c +++ b/cxl/json.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2015-2020 Intel Corporation. All rights reserved. +#include #include #include #include @@ -183,6 +184,114 @@ err_jobj: return NULL; } +/* + * Present complete view of memdev partition by presenting fields from + * both GET_PARTITION_INFO and IDENTIFY mailbox commands. + */ +static struct json_object *util_cxl_memdev_partition_to_json(struct cxl_memdev *memdev, + unsigned long flags) +{ + struct json_object *jobj = NULL; + struct json_object *jpart; + unsigned long long cap; + struct cxl_cmd *cmd; + int rc; + + jpart = json_object_new_object(); + if (!jpart) + return NULL; + if (!memdev) + goto err_jobj; + + /* Retrieve partition info in GET_PARTITION_INFO mbox cmd */ + cmd = cxl_cmd_new_get_partition_info(memdev); + if (!cmd) + goto err_jobj; + + rc = cxl_cmd_submit(cmd); + if (rc < 0) + goto err_cmd; + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) + goto err_cmd; + + cap = cxl_cmd_partition_info_get_active_volatile_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "active_volatile_bytes", jobj); + } + cap = cxl_cmd_partition_info_get_active_persistent_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "active_persistent_bytes", jobj); + } + cap = cxl_cmd_partition_info_get_next_volatile_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "next_volatile_bytes", jobj); + } + cap = cxl_cmd_partition_info_get_next_persistent_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "next_persistent_bytes", jobj); + } + cxl_cmd_unref(cmd); + + /* Retrieve partition info in the IDENTIFY mbox cmd */ + cmd = cxl_cmd_new_identify(memdev); + if (!cmd) + goto err_jobj; + + rc = cxl_cmd_submit(cmd); + if (rc < 0) + goto err_cmd; + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) + goto err_cmd; + + cap = cxl_cmd_identify_get_total_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, "total_bytes", jobj); + } + cap = cxl_cmd_identify_get_volatile_only_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "volatile_only_bytes", jobj); + } + cap = cxl_cmd_identify_get_persistent_only_bytes(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "persistent_only_bytes", jobj); + } + cap = cxl_cmd_identify_get_partition_align(cmd); + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, "partition_alignment_bytes", jobj); + + cxl_cmd_unref(cmd); + return jpart; + +err_cmd: + cxl_cmd_unref(cmd); +err_jobj: + json_object_put(jpart); + return NULL; +} + struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, unsigned long flags) { @@ -210,5 +319,10 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, if (jobj) json_object_object_add(jdev, "health", jobj); } + if (flags & UTIL_JSON_PARTITION) { + jobj = util_cxl_memdev_partition_to_json(memdev, flags); + if (jobj) + json_object_object_add(jdev, "partition_info", jobj); + } return jdev; } diff --git a/cxl/list.c b/cxl/list.c index 7f7a04d..73dc390 100644 --- a/cxl/list.c +++ b/cxl/list.c @@ -19,6 +19,7 @@ static struct { bool idle; bool human; bool health; + bool partition; } list; static unsigned long listopts_to_flags(void) @@ -31,6 +32,8 @@ static unsigned long listopts_to_flags(void) flags |= UTIL_JSON_HUMAN; if (list.health) flags |= UTIL_JSON_HEALTH; + if (list.partition) + flags |= UTIL_JSON_PARTITION; return flags; } @@ -64,6 +67,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) "use human friendly number formats "), OPT_BOOLEAN('H', "health", &list.health, "include memory device health information "), + OPT_BOOLEAN('I', "partition", &list.partition, + "include memory device partition information "), OPT_END(), }; const char * const u[] = { diff --git a/util/json.h b/util/json.h index 4ca2c89..f198036 100644 --- a/util/json.h +++ b/util/json.h @@ -17,6 +17,7 @@ enum util_json_flags { UTIL_JSON_FIRMWARE = (1 << 8), UTIL_JSON_DAX_MAPPINGS = (1 << 9), UTIL_JSON_HEALTH = (1 << 10), + UTIL_JSON_PARTITION = (1 << 11), }; struct json_object; From patchwork Tue Jan 18 20:25:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBABFC433F5 for ; Tue, 18 Jan 2022 20:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349019AbiARUUd (ORCPT ); Tue, 18 Jan 2022 15:20:33 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349141AbiARUUc (ORCPT ); Tue, 18 Jan 2022 15:20:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537232; x=1674073232; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PAJilnz5lTX52V9oiTom4kJZWUazgIG3WYPPl2V8m0M=; b=nXPmmPXKbkzO64jwhYhpO4LXw3ryRSLCPjfUQbRA7Hf0C220SSsCKqhl qM9AadiS+CfsvrMH825wpkc5FwYdnRgz/dRmNdqFB2IPkhXH+n39USDYc zUdzalTMyvR0nQ47eT03rPeGw8Fm2ZZ/TRYPO11w8mtcYpIh4O3OoGpS4 eyIXHY8CRm+/Le9fhEuKtMJFxqQmgBK6rbw0d3ga4wDp5pXv2ek81Rj4f zYQDX5WWpNpVdorceSOeLTgmDO4dBIpardK3ujspQ49c02XgIuhUGr/xj wdAy4Qwa6gJmzbXJH7yvNTgD9o5ajylK4c4OJJWj+0se1g91s1n7Lcm8V A==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250313" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250313" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:32 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953871" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:31 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 5/6] libcxl: add interfaces for SET_PARTITION_INFO mailbox command Date: Tue, 18 Jan 2022 12:25:14 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Users may want the ability to change the partition layout of a CXL memory device. Add interfaces to libcxl to allocate and send a SET_PARTITION_INFO mailbox as defined in the CXL 2.0 specification. Signed-off-by: Alison Schofield --- cxl/lib/libcxl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ cxl/lib/private.h | 8 ++++++++ cxl/libcxl.h | 5 +++++ 4 files changed, 68 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 5b1fc32..5a5b189 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1230,6 +1230,21 @@ cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd) cmd_partition_get_capacity_field(cmd, next_persistent_cap); } +CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, + unsigned long long volatile_capacity, int flags) +{ + struct cxl_cmd_set_partition_info *set_partition; + struct cxl_cmd *cmd; + + cmd = cxl_cmd_new_generic(memdev, + CXL_MEM_COMMAND_ID_SET_PARTITION_INFO); + + set_partition = (struct cxl_cmd_set_partition_info *)cmd->send_cmd->in.payload; + set_partition->volatile_capacity = cpu_to_le64(volatile_capacity); + set_partition->flags = flags; + return cmd; +} + CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd) { struct cxl_memdev *memdev = cmd->memdev; @@ -1428,3 +1443,38 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, { return lsa_op(memdev, LSA_OP_GET, buf, length, offset); } + +CXL_EXPORT int cxl_memdev_set_partition_info(struct cxl_memdev *memdev, + unsigned long long volatile_capacity, int flags) +{ + struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); + struct cxl_cmd *cmd; + int rc; + + dbg(ctx, "%s: enter cap: %llx, flags %d\n", __func__, + volatile_capacity, flags); + + cmd = cxl_cmd_new_set_partition_info(memdev, + volatile_capacity / CXL_CAPACITY_MULTIPLIER, flags); + if (!cmd) + return -ENXIO; + + rc = cxl_cmd_submit(cmd); + if (rc < 0) { + err(ctx, "cmd submission failed: %s\n", strerror(-rc)); + goto err; + } + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) { + err(ctx, "%s: mbox status: %d\n", __func__, rc); + rc = -ENXIO; + } +err: + cxl_cmd_unref(cmd); + return rc; +} + +CXL_EXPORT int cxl_cmd_partition_info_flag_immediate(void) +{ + return CXL_CMD_SET_PARTITION_INFO_FLAG_IMMEDIATE; +} diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index b7e969f..0ce931d 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -78,6 +78,11 @@ global: cxl_cmd_partition_info_get_active_persistent_bytes; cxl_cmd_partition_info_get_next_volatile_bytes; cxl_cmd_partition_info_get_next_persistent_bytes; + cxl_cmd_new_set_partition_info; + cxl_memdev_set_partition_info; + cxl_cmd_partition_info_flag_none; + cxl_cmd_partition_info_flag_immediate; + local: *; }; diff --git a/cxl/lib/private.h b/cxl/lib/private.h index dd9234f..4da8ea7 100644 --- a/cxl/lib/private.h +++ b/cxl/lib/private.h @@ -114,6 +114,14 @@ struct cxl_cmd_get_partition_info { #define CXL_CAPACITY_MULTIPLIER SZ_256M +struct cxl_cmd_set_partition_info { + le64 volatile_capacity; + u8 flags; +} __attribute__((packed)); + +/* CXL 2.0 8.2.9.5.2 Set Partition Info */ +#define CXL_CMD_SET_PARTITION_INFO_FLAG_IMMEDIATE BIT(0) + /* CXL 2.0 8.2.9.5.3 Byte 0 Health Status */ #define CXL_CMD_HEALTH_INFO_STATUS_MAINTENANCE_NEEDED_MASK BIT(0) #define CXL_CMD_HEALTH_INFO_STATUS_PERFORMANCE_DEGRADED_MASK BIT(1) diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 46f99fb..9b0a599 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -50,6 +50,8 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); +int cxl_memdev_set_partition_info(struct cxl_memdev *memdev, + unsigned long long volatile_capacity, int flags); #define cxl_memdev_foreach(ctx, memdev) \ for (memdev = cxl_memdev_get_first(ctx); \ @@ -117,6 +119,9 @@ unsigned long long cxl_cmd_partition_info_get_active_volatile_bytes(struct cxl_c unsigned long long cxl_cmd_partition_info_get_active_persistent_bytes(struct cxl_cmd *cmd); unsigned long long cxl_cmd_partition_info_get_next_volatile_bytes(struct cxl_cmd *cmd); unsigned long long cxl_cmd_partition_info_get_next_persistent_bytes(struct cxl_cmd *cmd); +struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, + unsigned long long volatile_capacity, int flags); +int cxl_cmd_partition_info_flag_immediate(void); #ifdef __cplusplus } /* extern "C" */ From patchwork Tue Jan 18 20:25:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12716864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3B25C433EF for ; Tue, 18 Jan 2022 20:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343860AbiARUUd (ORCPT ); Tue, 18 Jan 2022 15:20:33 -0500 Received: from mga07.intel.com ([134.134.136.100]:58421 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349016AbiARUUd (ORCPT ); Tue, 18 Jan 2022 15:20:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642537233; x=1674073233; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Drb8WUegwQsVAO3IROQ+hVH5hs+0PSkrLqtelSfX7HI=; b=j7vnFVAzsKifR4EvpeTqVhCi6Fn4VyjpTaCRN2FMlpWDLK9xZRLzZ15Y y2iLQRZclIimP0bu9hm9kAACM2qemvpR6fDe0FnkhlbdeaaefxptjdIz/ cEfUin5hP7p784xmtMqrchHVRuxhgrbkvrG76sqzaZHTtLC9Ga7NVb9G1 FLnSkFpmMaOzz+y/v3TG7/C7NyAV/wCTKdnK8KCpC8FvbLMa14Ma0LJjD c7qpBpdHPX7MZF33W915cRdO25zofcnFjIMsD4R9Yvj0iAin5sezwOOKe Fq00uH5uKG27UJdOyGicAAu9njMDfVK8bFI7ktWfejPiro4ws0hyb96+1 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10231"; a="308250316" X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="308250316" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:32 -0800 X-IronPort-AV: E=Sophos;i="5.88,298,1635231600"; d="scan'208";a="671953875" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jan 2022 12:20:32 -0800 From: alison.schofield@intel.com To: Ben Widawsky , Dan Williams , Ira Weiny , Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v3 6/6] cxl: add command set-partition-info Date: Tue, 18 Jan 2022 12:25:15 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Users may want to change the partition layout of a memory device using the CXL command line tool. Add a new CXL command, 'cxl set-partition-info', that operates on a CXL memdev, or a set of memdevs, and allows the user to change the partition layout of the device(s). Synopsis: Usage: cxl set-partition-info [..] [] -v, --verbose turn on debug -s, --volatile_size next volatile partition size in bytes The included MAN page explains how to find the partitioning capabilities and restrictions of a CXL memory device. Signed-off-by: Alison Schofield --- Documentation/cxl/cxl-set-partition-info.txt | 53 ++++++++++ Documentation/cxl/meson.build | 1 + cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/memdev.c | 101 +++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 Documentation/cxl/cxl-set-partition-info.txt diff --git a/Documentation/cxl/cxl-set-partition-info.txt b/Documentation/cxl/cxl-set-partition-info.txt new file mode 100644 index 0000000..d99a1b9 --- /dev/null +++ b/Documentation/cxl/cxl-set-partition-info.txt @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-set-partition-info(1) +========================= + +NAME +---- +cxl-set-partition-info - set the partitioning between volatile and persistent capacity on a CXL memdev + +SYNOPSIS +-------- +[verse] +'cxl set-partition-info [ [..] []' + +DESCRIPTION +----------- +Partition the device into volatile and persistent capacity. The change +in partitioning will become the “next” configuration, to become active +on the next device reset. + +Use "cxl list -m -I" to examine the partitioning capabilities +of a device. A partition_alignment_bytes value of zero means there are +no partitionable bytes available and therefore the partitions cannot be +changed. + +Using this command to change the size of the persistent capacity shall +result in the loss of data stored. + +OPTIONS +------- +:: +include::memdev-option.txt[] + +-s:: +--size=:: + Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment_bytes. + Use 'cxl list -m -I' to find partition_alignment_bytes. + + Size must be less than or equal to the device's partitionable bytes. + Calculate partitionable bytes by subracting the volatile_only_bytes, + and the persistent_only_bytes, from the total_bytes. + Use 'cxl list -m -I' to find the above mentioned_byte values. + +-v:: + Turn on verbose debug messages in the library (if libcxl was built with + logging and debug enabled). + +SEE ALSO +-------- +linkcxl:cxl-list[1], +CXL-2.0 8.2.9.5.2 diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build index 64ce13f..0108eea 100644 --- a/Documentation/cxl/meson.build +++ b/Documentation/cxl/meson.build @@ -28,6 +28,7 @@ cxl_manpages = [ 'cxl-read-labels.txt', 'cxl-write-labels.txt', 'cxl-zero-labels.txt', + 'cxl-set-partition-info.txt', ] foreach man : cxl_manpages diff --git a/cxl/builtin.h b/cxl/builtin.h index 78eca6e..7f11f28 100644 --- a/cxl/builtin.h +++ b/cxl/builtin.h @@ -10,4 +10,5 @@ int cmd_read_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_init_labels(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_check_labels(int argc, const char **argv, struct cxl_ctx *ctx); +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx); #endif /* _CXL_BUILTIN_H_ */ diff --git a/cxl/cxl.c b/cxl/cxl.c index 4b1661d..3153cf0 100644 --- a/cxl/cxl.c +++ b/cxl/cxl.c @@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { { "zero-labels", .c_fn = cmd_zero_labels }, { "read-labels", .c_fn = cmd_read_labels }, { "write-labels", .c_fn = cmd_write_labels }, + { "set-partition-info", .c_fn = cmd_set_partition_info }, }; int main(int argc, const char **argv) diff --git a/cxl/memdev.c b/cxl/memdev.c index d063d51..e1348c8 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ static struct parameters { unsigned len; unsigned offset; bool verbose; + const char *volatile_size; } param; #define fail(fmt, ...) \ @@ -48,6 +50,10 @@ OPT_UINTEGER('s', "size", ¶m.len, "number of label bytes to operate"), \ OPT_UINTEGER('O', "offset", ¶m.offset, \ "offset into the label area to start operation") +#define SET_PARTITION_OPTIONS() \ +OPT_STRING('s', "volatile_size", ¶m.volatile_size, "volatile-size", \ + "next volatile partition size in bytes") + static const struct option read_options[] = { BASE_OPTIONS(), LABEL_OPTIONS(), @@ -68,6 +74,12 @@ static const struct option zero_options[] = { OPT_END(), }; +static const struct option set_partition_options[] = { + BASE_OPTIONS(), + SET_PARTITION_OPTIONS(), + OPT_END(), +}; + static int action_zero(struct cxl_memdev *memdev, struct action_context *actx) { size_t size; @@ -175,6 +187,80 @@ out: return rc; } +static int validate_partition(struct cxl_memdev *memdev, + unsigned long long volatile_request) +{ + unsigned long long total_cap, volatile_only, persistent_only; + unsigned long long partitionable_bytes, partition_align_bytes; + const char *devname = cxl_memdev_get_devname(memdev); + struct cxl_cmd *cmd; + int rc; + + cmd = cxl_cmd_new_identify(memdev); + if (!cmd) + return -ENXIO; + rc = cxl_cmd_submit(cmd); + if (rc < 0) + goto err; + rc = cxl_cmd_get_mbox_status(cmd); + if (rc != 0) + goto err; + + partition_align_bytes = cxl_cmd_identify_get_partition_align(cmd); + if (partition_align_bytes == 0) { + fprintf(stderr, "%s: no partitionable capacity\n", devname); + rc = -EINVAL; + goto err; + } + + total_cap = cxl_cmd_identify_get_total_bytes(cmd); + volatile_only = cxl_cmd_identify_get_volatile_only_bytes(cmd); + persistent_only = cxl_cmd_identify_get_persistent_only_bytes(cmd); + + partitionable_bytes = total_cap - volatile_only - persistent_only; + + if (volatile_request > partitionable_bytes) { + fprintf(stderr, "%s: volatile size %lld exceeds partitionable capacity %lld\n", + devname, volatile_request, partitionable_bytes); + rc = -EINVAL; + goto err; + } + if (!IS_ALIGNED(volatile_request, partition_align_bytes)) { + fprintf(stderr, "%s: volatile size %lld is not partition aligned %lld\n", + devname, volatile_request, partition_align_bytes); + rc = -EINVAL; + } +err: + cxl_cmd_unref(cmd); + return rc; +} + +static int action_set_partition(struct cxl_memdev *memdev, + struct action_context *actx) +{ + const char *devname = cxl_memdev_get_devname(memdev); + unsigned long long volatile_request; + int rc; + + volatile_request = parse_size64(param.volatile_size); + if (volatile_request == ULLONG_MAX) { + fprintf(stderr, "%s: failed to parse volatile size '%s'\n", + devname, param.volatile_size); + return -EINVAL; + } + + rc = validate_partition(memdev, volatile_request); + if (rc) + return rc; + + rc = cxl_memdev_set_partition_info(memdev, volatile_request, + !cxl_cmd_partition_info_flag_immediate()); + if (rc) + fprintf(stderr, "%s error: %s\n", devname, strerror(-rc)); + + return rc; +} + static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, int (*action)(struct cxl_memdev *memdev, struct action_context *actx), const struct option *options, const char *usage) @@ -235,6 +321,11 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, } } + if (action == action_set_partition && !param.volatile_size) { + usage_with_options(u, options); + return -EINVAL; + } + if (param.verbose) cxl_set_log_priority(ctx, LOG_DEBUG); @@ -323,3 +414,13 @@ int cmd_zero_labels(int argc, const char **argv, struct cxl_ctx *ctx) count > 1 ? "s" : ""); return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_set_partition_info(int argc, const char **argv, struct cxl_ctx *ctx) +{ + int count = memdev_action(argc, argv, ctx, action_set_partition, + set_partition_options, + "cxl set-partition-info [..] []"); + fprintf(stderr, "set_partition %d mem%s\n", count >= 0 ? count : 0, + count > 1 ? "s" : ""); + return count >= 0 ? 0 : EXIT_FAILURE; +}