From 4499a264fea220ffcc18149503d76226e92b82a9 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Fri, 17 Dec 2021 16:45:10 +0100 Subject: [PATCH] nvme-print: Add Controller Metadata and Namespace Metadata Port and extent the libnvme part from the commit b8a403b ("Add NVMe MI Features: Controller Metadata (0x7E) and Namespace Metadata (0x7F).") from the nvme-cli monolithic branch. While at it add the missing definitions. Signed-off-by: Daniel Wagner --- libnvme | 2 +- nvme-print.c | 90 ++++++++++++++++++++++++++++++++++++++++ subprojects/libnvme.wrap | 2 +- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/libnvme b/libnvme index e4ab11b3..cfc9f9be 160000 --- a/libnvme +++ b/libnvme @@ -1 +1 @@ -Subproject commit e4ab11b3fac33b397932a562b634533d9985073e +Subproject commit cfc9f9be07f365e07a8c5a27d2ddb9e7bbae5eae diff --git a/nvme-print.c b/nvme-print.c index 27bee7e0..894d2571 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -5982,6 +5982,8 @@ const char *nvme_feature_to_string(enum nvme_features_id feature) case NVME_FEAT_FID_ENDURANCE_EVT_CFG: return "Enduarance Event Group Configuration"; case NVME_FEAT_FID_IOCS_PROFILE: return "I/O Command Set Profile"; case NVME_FEAT_FID_SPINUP_CONTROL: return "Spinup Control"; + case NVME_FEAT_FID_CTRL_METADATA: return "Controller Metadata"; + case NVME_FEAT_FID_NS_METADATA: return "Namespace Metadata"; case NVME_FEAT_FID_SW_PROGRESS: return "Software Progress"; case NVME_FEAT_FID_HOST_ID: return "Host Identifier"; case NVME_FEAT_FID_RESV_MASK: return "Reservation Notification Mask"; @@ -6296,6 +6298,90 @@ static void nvme_show_plm_config(struct nvme_plm_config *plmcfg) printf("\tDTWIN Time Threshold :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwintt)); } +static char *nvme_show_host_metadata_type_to_string(enum nvme_features_id fid, + __u8 type) +{ + switch (fid) { + case NVME_FEAT_FID_CTRL_METADATA: + switch (type) { + case NVME_CTRL_METADATA_OS_CTRL_NAME: + return "Operating System Controller Name"; + case NVME_CTRL_METADATA_OS_DRIVER_NAME: + return "Operating System Driver Name"; + case NVME_CTRL_METADATA_OS_DRIVER_VER: + return "Operating System Driver Version"; + case NVME_CTRL_METADATA_PRE_BOOT_CTRL_NAME: + return "Pre-boot Controller Name"; + case NVME_CTRL_METADATA_PRE_BOOT_DRIVER_NAME: + return "Pre-boot Driver Name"; + case NVME_CTRL_METADATA_PRE_BOOT_DRIVER_VER: + return "Pre-boot Driver Version"; + case NVME_CTRL_METADATA_SYS_PROC_MODEL: + return "System Processor Model"; + case NVME_CTRL_METADATA_CHIPSET_DRV_NAME: + return "Chipset Driver Name"; + case NVME_CTRL_METADATA_CHIPSET_DRV_VERSION: + return "Chipset Driver Version"; + case NVME_CTRL_METADATA_OS_NAME_AND_BUILD: + return "Operating System Name and Build"; + case NVME_CTRL_METADATA_SYS_PROD_NAME: + return "System Product Name"; + case NVME_CTRL_METADATA_FIRMWARE_VERSION: + return "Firmware Version"; + case NVME_CTRL_METADATA_OS_DRIVER_FILENAME: + return "Operating System Driver Filename"; + case NVME_CTRL_METADATA_DISPLAY_DRV_NAME: + return "Display Driver Name"; + case NVME_CTRL_METADATA_DISPLAY_DRV_VERSION: + return "Display Driver Version"; + case NVME_CTRL_METADATA_HOST_DET_FAIL_REC: + return "Host-Determined Failure Record"; + default: + return "Unknown Controller Type"; + } + case NVME_FEAT_FID_NS_METADATA: + switch (type) { + case NVME_NS_METADATA_OS_NS_NAME: + return "Operating System Namespace Name"; + case NVME_NS_METADATA_PRE_BOOT_NS_NAME: + return "Pre-boot Namespace Name"; + case NVME_NS_METADATA_OS_NS_QUAL_1: + return "Operating System Namespace Name Qualifier 1"; + case NVME_NS_METADATA_OS_NS_QUAL_2: + return "Operating System Namespace Name Qualifier 2"; + default: + return "Unknown Namespace Type"; + } + default: + return "Unknown Feature"; + } +} + +static void nvme_show_host_metadata(enum nvme_features_id fid, + struct nvme_host_metadata *data) +{ + struct nvme_metadata_element_desc *desc = &data->descs[0]; + int i; + char val[4096]; + __u16 len; + + printf("\tNum Metadata Element Descriptors: %d\n", data->ndesc); + for (i = 0; i < data->ndesc; i++) { + len = le16_to_cpu(desc->len); + strncpy(val, (char *)desc->val, min(sizeof(val) - 1, len)); + + printf("\tElement[%-3d]:\n", i); + printf("\t\tType : 0x%02x (%s)\n", desc->type, + nvme_show_host_metadata_type_to_string(fid, desc->type)); + printf("\t\tRevision : %d\n", desc->rev); + printf("\t\tLength : %d\n", len); + printf("\t\tValue : %s\n", val); + + desc = (struct nvme_metadata_element_desc *) + &desc->val[desc->len]; + } +} + void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, unsigned char *buf) { __u8 field; @@ -6428,6 +6514,10 @@ void nvme_feature_show_fields(enum nvme_features_id fid, unsigned int result, un case NVME_FEAT_FID_SPINUP_CONTROL: printf("\tSpinup control feature Enabled: %s\n", (result & 1) ? "True" : "False"); break; + case NVME_FEAT_FID_CTRL_METADATA: + case NVME_FEAT_FID_NS_METADATA: + nvme_show_host_metadata(fid, (struct nvme_host_metadata *)buf); + break; case NVME_FEAT_FID_SW_PROGRESS: printf("\tPre-boot Software Load Count (PBSLC): %u\n", result & 0x000000ff); break; diff --git a/subprojects/libnvme.wrap b/subprojects/libnvme.wrap index 0dc91f6d..ae0da728 100644 --- a/subprojects/libnvme.wrap +++ b/subprojects/libnvme.wrap @@ -1,3 +1,3 @@ [wrap-git] url = https://github.com/linux-nvme/libnvme.git -revision = e4ab11b3fac33b397932a562b634533d9985073e +revision = cfc9f9be07f365e07a8c5a27d2ddb9e7bbae5eae -- 2.50.1