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: 12702782 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 C9F3DC433F5 for ; Mon, 3 Jan 2022 20:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 Received: from mga12.intel.com ([192.55.52.136]:35284 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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="222105774" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105774" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702781 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 0297FC433EF for ; Mon, 3 Jan 2022 20:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 Received: from mga12.intel.com ([192.55.52.136]:35292 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=a4ist+wRtz5MUDFftoH8bUzPjP4x2s9lbL9nKwk7uk8=; b=m8CcMS3C5iAAOKGUQJQ2J951lXp8U1+6P1wy+QeJuTK8MuJyaOBPYj6i jYD+MduCdg5PQjVotHxKgtG7j5es3LS0OEQBDuYu8CAG5cVTuI7NsDD27 tP08l8p7ycjiDoD2pBDUNg74joMRQWLvXe+EV/uAs0yW7FJvpknCsXPAT C1aRepF6/a1E6WMb+BAq6srqKn6SThAAsd+9KZYI4gb3GxlGkIWjM8qPz PlRxH/Dj1vsFuS4dQ88r1xgo+4QR+9/x+nG8eBJmFIgecUdwWe9J5I5Al LiQT3EyiKFSSArN/RRj5gRn5Z8HYk45TLQM93OsvN52ZMY3vVXkDVdL/U w==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105775" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105775" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702783 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 067F1C433FE for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229617AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 Received: from mga12.intel.com ([192.55.52.136]:35284 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=eN99uTDmncVh4iL2OAQGr2qLxxRilTkwPt0bI8R2V3I=; b=FvNIu3hrRKlvGdO/CGg+yTyhheXeuoJp31EnclIMUh6F8zpg2NoABP+L getshAiWDS1jIisDOgGYc8qyaKz4MmCaRC7uTxwcuwAgOndIzAkz8jPsl 3mR61E0m9OQ+K910kN/OmkeAANr7ZZrOv7s+Rlv6Sm9jW3D+ucznmD2AW 3bF02JoH5f91WAM655OynRZ/mhBIX0+aHaCN0g11O+mrByNtkHafhorg4 /5O38zLTQHtG/FaCj7MiVa50zBFB9EtvorFumbA9CBL+3tnxcj/aNRGkD mqwKEcrIlfY9z9yKpJxRVR3JyQhTLoQnOAicMYV1hWMbhFMp3+HxROHcz w==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105776" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105776" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:34 -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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702784 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 3A30DC4332F for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbiACULf (ORCPT ); Mon, 3 Jan 2022 15:11:35 -0500 Received: from mga12.intel.com ([192.55.52.136]:35292 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=i8nB8iLWmY3RrwAJboCr0xODBiC8RVy3LJGcIn0A/Y4=; b=ks712N3J+O3v0aq5tExehRQhMsyZSxTt5BKUadGwziZ+6NWUmIhUenez BfT6gNtcYI6A4TtLDVmwJRn0OSskRxxenEzmRm9FfRMj9np3NfzEa+4r3 MOMPfcxG0TtQx0Ah8I15gC5TO2VG+2jjAD/AdcnH0yVsGOeTGN4EpElVV ZQuhZu2ZcTh85/lpe9vtYd5FeHxZ6JCo0uuGuw1k293C6E/wZiEwNgs2A 5L0AQUzPNmtNZJcjnfHTGk1ZU9QoP+CIzUavF8zU2Rg7YWiMvifNg42VU lGQhKl9g/0OK4QQ7XO4r2YB8niAFWrjHEgz2q8EfpI1WEaV7P2nMyA0Qz A==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105777" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105777" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:34 -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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702785 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 6FFE4C43217 for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbiACULg (ORCPT ); Mon, 3 Jan 2022 15:11:36 -0500 Received: from mga12.intel.com ([192.55.52.136]:35284 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=ExZXAVTyWRNmIDDrWFSUQMsvxT+hLCcqMNH1z0HRo30=; b=OLlnmGoGDvCEzw1Ucq944xXNmG0SzeP26lc/TWJIPJI633YJHzU/zRBA Phq1ElX9FJWHNoFSad0rqTCq8xgATHzoT54ncr9lH35RCWLICNYrygF0Y 4lo0R0UOKgUqGKd4wkaBY1YQ6Sln3TY4l6kQ1IKHjBW9vkDj36xjlL4FL sqSMvrVlp7+FVR6VMGBVN177WklyOg5agAWLCidbZhfm0zkkT0I/CYcDh 4aq+Z3f3ZHiZ3su0hk7wV3gurvw/8G40ZEE6AfQqWP2n4FvEBrdK4CZeN I/43McF0YLo/qlxCA5tWRAU5PJEv3QXO1/6ZdBzr49t84kRkD2DbvTq7M Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105779" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105779" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:34 -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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702786 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 9E41FC43219 for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbiACULg (ORCPT ); Mon, 3 Jan 2022 15:11:36 -0500 Received: from mga12.intel.com ([192.55.52.136]:35292 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=jAsYLLBNz+SUKss7Qz28lVyYvm19aggyMmIkH5M2KtU=; b=S8y3rgcCnlr6tP69JZDhkIUhfImB4BCZEAjO9q1EOxlXbZ5IEWAsOY/s LW7zozTago4JDo0rwfXtcPGKJoCsd0thTqf+It7MWqWJGgTXu5bxk3Xks KcWpMmXpavwqSVpGAcwrczYVWkPLCSilSX8kb1HOgcVhBNrCG0UJEhp7J zQZtEqjmPpQXzWJq8k9qs0o8iqzW5pa8ahOdh9pu4Hn8iDTZnQoqSaLjq OVmyHFextVLbPnAZY7Zwbcq28f07+XZ1Pd2z1k39dzXBemkqDDgL7+xBm 6hehMU3Jk11CSAdJqRUrpG0Is3SuLO3Dwar0LqUr5Zot3mVJ2NjFGpldY Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105780" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105780" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:34 -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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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: 12702787 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 DFB81C433EF for ; Mon, 3 Jan 2022 20:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229472AbiACULg (ORCPT ); Mon, 3 Jan 2022 15:11:36 -0500 Received: from mga12.intel.com ([192.55.52.136]:35284 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbiACULe (ORCPT ); Mon, 3 Jan 2022 15:11:34 -0500 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=+bwgu36dEz5dCKX+coXfMMxj8XYHQrsU2sib4nNa93A=; b=YS5hd0IxU9y0J+XWqo0R/JBMB1UYEQ/FpDO7dIOh/OwjslC6HJx9EwwQ U3OZrKPJFZdr0UHrISS0tLreKmfcOFc9gtDLmTI8P3QMWhlc1w0AZdmFh HAqHOm1z834Zyq28ArKxhKiaPS7y7oSNFqAzmRAy54A3cd9+5PRK6i9gr Ai2Mi8CyibeZj8d5q/OD3Wk7Vk7CO/DB8ClJw7VlI1406RGomAWCaYeVF xiI+AG/YVP34ICKOWIu8L/fvt141JDiuJHF6Pxl+LbajaMdc0asP4nsRX bPDHWPYWK7KAbKX9fAiMHCP/N+80dG9MwynRbbPc4aZRdWiF/SKDUlscI w==; X-IronPort-AV: E=McAfee;i="6200,9189,10216"; a="222105781" X-IronPort-AV: E=Sophos;i="5.88,258,1635231600"; d="scan'208";a="222105781" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2022 12:11:34 -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: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org 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; +}