From patchwork Mon Jan 3 20:16: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: 12702773 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 186A62CA7 for ; Mon, 3 Jan 2022 20:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240694; x=1672776694; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=deLhvT2rkO5L/SLA7rPyzJse0nz+c7TFWMdZ+dd8Fz8=; b=n5HdY1smPu8ykkxFisHHBJ9ogA31HYp3X+BtS10ujHlLsDyrGbqfnmZB 0kTKRrk8DLkNlL8MOpgc2wEYmFYzLqwFsocqHCuJoB5wuuzxVLuegPDhs wzwKrcSCaGUg/UmBp1/NXRYzg4v5Hi2vs6ZIT6i2fppgX6emLp7cuNzi2 dj+iYzHQYnAZQxtxCNc4YhpxRq/mls4SzcgssOD7GjtejVt4mJ6PEINZO Hh34XJCCbVe0mKBbdHDkbL13JLgVEbq/TNcN3AzOJ40ROLetHskO1WadR HkmIFN3uUFHQRkERwMXXTwXz5UZv547U5fz8gaIy1E+5i+hl65+JiQK0O w==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866885" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866885" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709387" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 1/7] libcxl: add GET_PARTITION_INFO mailbox command and accessors Date: Mon, 3 Jan 2022 12:16:12 -0800 Message-Id: <9d3c55cbd36efb6eabec075cc8596a6382f1f145.1641233076.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield 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. Signed-off-by: Alison Schofield --- cxl/lib/private.h | 10 ++++++++++ cxl/libcxl.h | 5 +++++ util/size.h | 1 + cxl/lib/libcxl.c | 41 +++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 5 +++++ 5 files changed, 62 insertions(+) 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..7cf9061 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_get_partition_info_get_active_volatile_cap(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_get_partition_info_get_active_persistent_cap(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_get_partition_info_get_next_volatile_cap(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_get_partition_info_get_next_persistent_cap(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 diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index f0664be..f3d4022 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1157,6 +1157,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_get_partition_info_get_active_volatile_cap(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, active_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_get_partition_info_get_active_persistent_cap(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, active_persistent_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_get_partition_info_get_next_volatile_cap(struct cxl_cmd *cmd) +{ + cmd_partition_get_capacity_field(cmd, next_volatile_cap); +} + +CXL_EXPORT unsigned long long +cxl_cmd_get_partition_info_get_next_persistent_cap(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..09d6d94 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_get_partition_info_get_active_volatile_cap; + cxl_cmd_get_partition_info_get_active_persistent_cap; + cxl_cmd_get_partition_info_get_next_volatile_cap; + cxl_cmd_get_partition_info_get_next_persistent_cap; local: *; }; From patchwork Mon Jan 3 20:16: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: 12702775 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 BFC222CA9 for ; Mon, 3 Jan 2022 20:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240695; x=1672776695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=a4ist+wRtz5MUDFftoH8bUzPjP4x2s9lbL9nKwk7uk8=; b=KifmBSXoCJ9YvBLuAKqfVe3XqV51UB6JOIAqp6oO979pWkyahY59Qh+l 35yhfCS/U5adZe67FG0gj8xg67VtETtp9rRr4yTM/uv7BdDgpFayC2H7A mGPMsVCP5dkwIZ/iUUZkB1CUvj6/IgqIID0NdLGnLHoA+XozqGGhcEoGs yDaYqbijAz3YcDDxZuSh4U7LdHyyjAvQ8VwNOu5ekN/1nQaQgR01DiJkL iTpXEmm0+8JM4yua88uSFGpw/YSyDRUDcZpb6n8t+qutiJbpnvcUzWKmt dBsBPhq/QaRWAK1ZvMsjOhJb2U5oO62tR66PxJhPHKyrl5HHDvX+zkZbT g==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866886" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866886" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709392" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 2/7] libcxl: add accessors for capacity fields of the IDENTIFY command Date: Mon, 3 Jan 2022 12:16:13 -0800 Message-Id: <577012d59f5b6b9754d2ce1147585ce5f91a3108.1641233076.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Add accessors to retrieve total capacity, volatile only capacity, and persistent only capacity from the IDENTIFY mailbox command. These values are useful when partitioning the device. Signed-off-by: Alison Schofield --- cxl/libcxl.h | 3 +++ cxl/lib/libcxl.c | 29 +++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 3 +++ 3 files changed, 35 insertions(+) diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 7cf9061..d333b6d 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_capacity(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_volatile_only_capacity(struct cxl_cmd *cmd); +unsigned long long cxl_cmd_identify_get_persistent_only_capacity(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); diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index f3d4022..715d8e4 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1102,6 +1102,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_capacity(struct cxl_cmd *cmd) +{ + cmd_identify_get_capacity_field(cmd, total_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_volatile_only_capacity(struct cxl_cmd *cmd) +{ + cmd_identify_get_capacity_field(cmd, volatile_capacity); +} + +CXL_EXPORT unsigned long long +cxl_cmd_identify_get_persistent_only_capacity(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 09d6d94..bed6427 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_capacity; + cxl_cmd_identify_get_volatile_only_capacity; + cxl_cmd_identify_get_persistent_only_capacity; cxl_cmd_identify_get_partition_align; cxl_cmd_identify_get_label_size; cxl_cmd_new_get_health_info; From patchwork Mon Jan 3 20:16: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: 12702774 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 E50542CA7 for ; Mon, 3 Jan 2022 20:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240695; x=1672776695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eN99uTDmncVh4iL2OAQGr2qLxxRilTkwPt0bI8R2V3I=; b=hhX/azV+Alsn47OXiytbl2114ALGhj7VlTGAhOj2fQijc8PMKfBsWXcW m6V1/kZm5VQM9aYaDeyHb+9MpW/VdTkIXIWiXDazn6y7npI6MLQNgpqSO BZ0uGQC7Xmw+Hn8uxZ/Wk8cyoWxPTALjXM2C1EjwXBmNHw0Mv0bNlAQnp C6BV18jye1RO4HlVwM3B6lcWOPThQrSFSTEDw8Swr+N0PIOZcwFtT/JNb 5Q1gL0URfIPOfobaDfBTFi23R+eiMhcNQAMcPDGgnTi0jj2mSQJfXNgTo Org/gurqxX3552RfYQw5J1N2UHTPD1LuEr1gvoNhTluORTx/2l3k0yKn4 A==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866888" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866888" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709395" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 3/7] libcxl: apply CXL_CAPACITY_MULTIPLIER to partition alignment field Date: Mon, 3 Jan 2022 12:16:14 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield The IDENTIFY mailbox command returns the partition alignment field expressed in multiples of 256 MB. Use CXL_CAPACITY_MULTIPLIER when returning this field. This is in sync with all the other partitioning related fields using the multiplier. Signed-off-by: Alison Schofield --- 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 715d8e4..85a6c0e 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1086,7 +1086,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 Mon Jan 3 20:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12702776 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 E2D342CAD for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240696; x=1672776696; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i8nB8iLWmY3RrwAJboCr0xODBiC8RVy3LJGcIn0A/Y4=; b=lFnnOJxcecFlrMfGT5/Mlw6XI4qS8qe5uH10tPRoE19O8DV7C7lBqnVP IifmwZwoLkwiYeyG3rpDJC5cAaXTcmcrH1RMtq9/5//S4uugBq4O/k/ck Tq8C3otIrGbCbP4mdcjUbSzW5ch+5GGWpRa7dgXA2RcXuo/DZSTAJi0Y4 LHKhGg/pS/+8rbN/K5nId6ComZLBoWyczmVn13KomuuYLzh5zHhElt06c gs6s+8wZtXUYiYzjhycxYMesubPzS3OsGR6wQg++69V6B332Xo93TZvN2 h7esgOcG9bTxy0Ys4QZ1pbofSll79QbZHYbZwMzKfQM525l805QJDqYfb Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866890" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866890" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709400" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 4/7] cxl: add memdev partition information to cxl-list Date: Mon, 3 Jan 2022 12:16:15 -0800 Message-Id: <78ff68a062f23cef48fb6ea1f91bcd7e11e4fa6e.1641233076.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Add information useful for managing memdev partitions to cxl-list output. Include all of the fields from GET_PARTITION_INFO and the partitioning related fields from the IDENTIFY mailbox command. "partition":{ "active_volatile_capacity":273535729664, "active_persistent_capacity":0, "next_volatile_capacity":0, "next_persistent_capacity":0, "total_capacity":273535729664, "volatile_only_capacity":0, "persistent_only_capacity":0, "partition_alignment":268435456 } Signed-off-by: Alison Schofield Reviewed-by: Dan Williams --- Documentation/cxl/cxl-list.txt | 23 +++++++ util/json.h | 1 + cxl/list.c | 5 ++ util/json.c | 112 +++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index c8d10fb..e65e944 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -85,6 +85,29 @@ OPTIONS } ] ---- +-P:: +--partition:: + Include partition information in the memdev listing. Example listing: +---- +# cxl list -m mem0 -P +[ + { + "memdev":"mem0", + "pmem_size":0, + "ram_size":273535729664, + "partition":{ + "active_volatile_capacity":273535729664, + "active_persistent_capacity":0, + "next_volatile_capacity":0, + "next_persistent_capacity":0, + "total_capacity":273535729664, + "volatile_only_capacity":0, + "persistent_only_capacity":0, + "partition_alignment":268435456 + } + } +] +---- include::human-option.txt[] diff --git a/util/json.h b/util/json.h index ce575e6..76a8816 100644 --- a/util/json.h +++ b/util/json.h @@ -20,6 +20,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; diff --git a/cxl/list.c b/cxl/list.c index b1468b7..368ec21 100644 --- a/cxl/list.c +++ b/cxl/list.c @@ -17,6 +17,7 @@ static struct { bool idle; bool human; bool health; + bool partition; } list; static unsigned long listopts_to_flags(void) @@ -29,6 +30,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; } @@ -62,6 +65,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('P', "partition", &list.partition, + "include memory device partition information "), OPT_END(), }; const char * const u[] = { diff --git a/util/json.c b/util/json.c index f97cf07..4254dea 100644 --- a/util/json.c +++ b/util/json.c @@ -1616,6 +1616,113 @@ 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_get_partition_info_get_active_volatile_cap(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "active_volatile_capacity", jobj); + } + cap = cxl_cmd_get_partition_info_get_active_persistent_cap(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "active_persistent_capacity", jobj); + } + cap = cxl_cmd_get_partition_info_get_next_volatile_cap(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "next_volatile_capacity", jobj); + } + cap = cxl_cmd_get_partition_info_get_next_persistent_cap(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "next_persistent_capacity", 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_capacity(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, "total_capacity", jobj); + } + cap = cxl_cmd_identify_get_volatile_only_capacity(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "volatile_only_capacity", jobj); + } + cap = cxl_cmd_identify_get_persistent_only_capacity(cmd); + if (cap != ULLONG_MAX) { + jobj = util_json_object_size(cap, flags); + if (jobj) + json_object_object_add(jpart, + "persistent_only_capacity", 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", jobj); + + 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) { @@ -1643,5 +1750,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", jobj); + } return jdev; } From patchwork Mon Jan 3 20:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12702778 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 F12A02CA7 for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240696; x=1672776696; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ExZXAVTyWRNmIDDrWFSUQMsvxT+hLCcqMNH1z0HRo30=; b=DicS7Iy9nQPpChkXl/Hhyvqa9rfFYzfq5KJBfYsJlE2PIl8WVZ1HjbEv fIl5OnKVLIutwkT/yDKHJgc/z1rp1LdP7ERoyzIceFUhR0ZrX8dtlPgBX tTVFxcO0uEwq3bwlzVFCeRk9aWTBju1S3N5p5g4lxEoK5bmbjE5XOJj/J kgAtje2/xX9koU86gWb7K+PnjZN2IGIneCSHlUZRL9MtSrT6vVOBwJ9sE NXE3PAFWUDRHc7d9idSXp2lXryLY4l6AQxvz4zHaA97vEsJhWt5T19uv8 VLtbcC1ozn8+mrl2ZDg5AmpYHz4hevLq9zCPqRzNirwnPgtZFx85frNWt A==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866891" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866891" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709404" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 5/7] libcxl: add interfaces for SET_PARTITION_INFO mailbox command Date: Mon, 3 Jan 2022 12:16:16 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Add APIs to allocate and send a SET_PARTITION_INFO mailbox command. Signed-off-by: Alison Schofield --- cxl/lib/private.h | 9 +++++++++ cxl/libcxl.h | 4 ++++ cxl/lib/libcxl.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 3 +++ 4 files changed, 61 insertions(+) diff --git a/cxl/lib/private.h b/cxl/lib/private.h index dd9234f..841aa80 100644 --- a/cxl/lib/private.h +++ b/cxl/lib/private.h @@ -114,6 +114,15 @@ 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_NO_FLAG (0) +#define CXL_CMD_SET_PARTITION_INFO_IMMEDIATE_FLAG (1) + /* 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 d333b6d..67d6ffc 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,8 @@ unsigned long long cxl_cmd_get_partition_info_get_active_volatile_cap(struct cxl unsigned long long cxl_cmd_get_partition_info_get_active_persistent_cap(struct cxl_cmd *cmd); unsigned long long cxl_cmd_get_partition_info_get_next_volatile_cap(struct cxl_cmd *cmd); unsigned long long cxl_cmd_get_partition_info_get_next_persistent_cap(struct cxl_cmd *cmd); +struct cxl_cmd *cxl_cmd_new_set_partition_info(struct cxl_memdev *memdev, + unsigned long long volatile_capacity, int flags); #ifdef __cplusplus } /* extern "C" */ diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 85a6c0e..877a783 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1227,6 +1227,21 @@ cxl_cmd_get_partition_info_get_next_persistent_cap(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; @@ -1425,3 +1440,33 @@ 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; +} diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index bed6427..5d02c45 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -78,6 +78,9 @@ global: cxl_cmd_get_partition_info_get_active_persistent_cap; cxl_cmd_get_partition_info_get_next_volatile_cap; cxl_cmd_get_partition_info_get_next_persistent_cap; + cxl_cmd_new_set_partition_info; + cxl_memdev_set_partition_info; + local: *; }; From patchwork Mon Jan 3 20:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12702777 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 0962C2CB1 for ; Mon, 3 Jan 2022 20:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240697; x=1672776697; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jAsYLLBNz+SUKss7Qz28lVyYvm19aggyMmIkH5M2KtU=; b=DojVl7aTRcVVU793b8WC5pu2yFMtxUMLzJjhjbOozexNI1JQ4FbsgINh Ls4RP1EXQhx9CQ719G47GrdRZkTPsAjy2rYKj76Q1IhsAzulRxkbbrv/u noNLjueFW2RMKrbV3iYU8Tk3633jHzyvY1UncttcriYumqTYfDQNCM09j FLV7gk2t//IYA/V1Js2RS6BHLZmbT/d0CdzLKydjVDI0i4fjBvXU3Hr35 yaR8O9BwO6KaCc8Nlmsyd3f8JXJ6FhXTMErbqVsXkJ6jTGxAM1zzcYfwX n7BC/TXes+DYG61GBvoWqwm0UfR+xR4T5ZPv/BroRu7jtvS9bThX+JW6M Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866892" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866892" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709408" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 6/7] ndctl, util: use 'unsigned long long' type in OPT_U64 define Date: Mon, 3 Jan 2022 12:16:17 -0800 Message-Id: <4653004cf532c2e14f79a45bddf0ebaac09ef4e6.1641233076.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield The OPT_U64 define failed in check_vtype() with unknown 'u64' type. Replace with 'unsigned long long' to make the OPT_U64 define usable. Signed-off-by: Alison Schofield --- util/parse-options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/parse-options.h b/util/parse-options.h index 9318fe7..91b7932 100644 --- a/util/parse-options.h +++ b/util/parse-options.h @@ -124,7 +124,7 @@ struct option { #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) } -#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) } +#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned long long *), .help = (h) } #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } #define OPT_FILENAME(s, l, v, a, h) { .type = OPTION_FILENAME, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } #define OPT_DATE(s, l, v, h) \ From patchwork Mon Jan 3 20:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12702779 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 4BA7B2CB3 for ; Mon, 3 Jan 2022 20:11:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1641240698; x=1672776698; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+bwgu36dEz5dCKX+coXfMMxj8XYHQrsU2sib4nNa93A=; b=Fs8VS0qZYxevemms+MPKQbC6XrWduMGVqD7Fq7/ww82/SQVAa1/Pwyjx vIhRFanFchXqn2UCdhcnHsALGYbrZ/G1/hJzbXMdQlSxYgD6ciNAu2lR2 v5y79hLWoId7op4NwxmV5T1k1GzUaqQ2ZfbJnW0YvT41XKy7RqFLd0C5K QBvEhRgeKQMnUGaiMb7HkFaZ+cgwwvsbCu4OufrIfmYxo2KHRdsvFKTES ZianiHldJx2/uESF8ATNnwI/pS6VaLzJU1GiXfTNQxCB6jY4RNoqCnGJe lGB6EcCSoi2PYL4H7kjt926T6mFoyAu+23e25mCu4+3VOWfvffVWAydf0 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="302866893" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="302866893" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="525709412" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:33 -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 7/7] cxl: add command set-partition-info Date: Mon, 3 Jan 2022 12:16:18 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield The command 'cxl set-partition-info' operates on a CXL memdev, or a set of memdevs, allowing the user to change the partition layout of the device. Synopsis: Usage: cxl set-partition-info [..] [] -v, --verbose turn on debug -s, --volatile_size next volatile partition size in bytes The MAN page explains how to find partitioning capabilities and restrictions. Signed-off-by: Alison Schofield --- Documentation/cxl/cxl-set-partition-info.txt | 27 ++++++ Documentation/cxl/partition-description.txt | 15 ++++ Documentation/cxl/partition-options.txt | 19 +++++ Documentation/cxl/Makefile.am | 3 +- cxl/builtin.h | 1 + cxl/cxl.c | 1 + cxl/memdev.c | 89 ++++++++++++++++++++ 7 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 Documentation/cxl/cxl-set-partition-info.txt create mode 100644 Documentation/cxl/partition-description.txt create mode 100644 Documentation/cxl/partition-options.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..32418b6 --- /dev/null +++ b/Documentation/cxl/cxl-set-partition-info.txt @@ -0,0 +1,27 @@ +// 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 [ [..] []' + +include::partition-description.txt[] +Partition the device on the next device reset using the volatile capacity +requested. Using this command to change the size of the persistent capacity +shall result in the loss of stored data. + +OPTIONS +------- +include::partition-options.txt[] + +SEE ALSO +-------- +linkcxl:cxl-list[1], +CXL-2.0 8.2.9.5.2 diff --git a/Documentation/cxl/partition-description.txt b/Documentation/cxl/partition-description.txt new file mode 100644 index 0000000..b3efac8 --- /dev/null +++ b/Documentation/cxl/partition-description.txt @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 + +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 -P" to examine the partition capacities +supported on a device. Paritionable capacity must exist on the +device. A partition_alignment of zero means no partitionable +capacity is available. + +Using this command to change the size of the persistent capacity shall +result in the loss of data stored. diff --git a/Documentation/cxl/partition-options.txt b/Documentation/cxl/partition-options.txt new file mode 100644 index 0000000..84e49c9 --- /dev/null +++ b/Documentation/cxl/partition-options.txt @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +:: +include::memdev-option.txt[] + +-s:: +--size=:: + Size in bytes of the volatile partition requested. + + Size must align to the devices partition_alignment. + Use 'cxl list -m -P' to find partition_alignment. + + Size must be less than or equal to the devices partitionable bytes. + (total_capacity - volatile_only_capacity - persistent_only_capacity) + Use 'cxl list -m -P' to find *_capacity values. + +-v:: + Turn on verbose debug messages in the library (if libcxl was built with + logging and debug enabled). diff --git a/Documentation/cxl/Makefile.am b/Documentation/cxl/Makefile.am index efabaa3..c5faf04 100644 --- a/Documentation/cxl/Makefile.am +++ b/Documentation/cxl/Makefile.am @@ -22,7 +22,8 @@ man1_MANS = \ cxl-list.1 \ cxl-read-labels.1 \ cxl-write-labels.1 \ - cxl-zero-labels.1 + cxl-zero-labels.1 \ + cxl-set-partition-info.1 EXTRA_DIST = $(man1_MANS) 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 5ee38e5..fa63317 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ static struct parameters { unsigned len; unsigned offset; bool verbose; + unsigned long long volatile_size; } param; #define fail(fmt, ...) \ @@ -47,6 +49,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_U64('s', "volatile_size", ¶m.volatile_size, \ + "next volatile partition size in bytes") + static const struct option read_options[] = { BASE_OPTIONS(), LABEL_OPTIONS(), @@ -67,6 +73,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; @@ -174,6 +186,73 @@ 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_capacity(cmd); + volatile_only = cxl_cmd_identify_get_volatile_only_capacity(cmd); + persistent_only = cxl_cmd_identify_get_persistent_only_capacity(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 = param.volatile_size; + + rc = validate_partition(memdev, volatile_request); + if (rc) + return rc; + + rc = cxl_memdev_set_partition_info(memdev, volatile_request, 0); + 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) @@ -322,3 +401,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; +}