From f945642ac3c816b84b78cec1fa066602286620d1 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 29 Mar 2018 14:16:53 -0700 Subject: [PATCH] nvme/identify: print firmware slot information Change-Id: I730fa785f91034e15881d4ca3b94a98e9381f89b Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/405825 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- examples/nvme/identify/identify.c | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index b1e708dc8..c5fe32e56 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -59,6 +59,8 @@ static struct spdk_nvme_error_information_entry error_page[256]; static struct spdk_nvme_health_information_page health_page; +static struct spdk_nvme_firmware_page firmware_page; + static struct spdk_nvme_intel_smart_information_page intel_smart_page; static struct spdk_nvme_intel_temperature_page intel_temperature_page; @@ -223,6 +225,18 @@ get_health_log_page(struct spdk_nvme_ctrlr *ctrlr) return 0; } +static int +get_firmware_log_page(struct spdk_nvme_ctrlr *ctrlr) +{ + if (spdk_nvme_ctrlr_cmd_get_log_page(ctrlr, SPDK_NVME_LOG_FIRMWARE_SLOT, + SPDK_NVME_GLOBAL_NS_TAG, &firmware_page, sizeof(firmware_page), 0, get_log_page_completion, NULL)) { + printf("spdk_nvme_ctrlr_cmd_get_log_page() failed\n"); + exit(1); + } + + return 0; +} + static int get_intel_smart_log_page(struct spdk_nvme_ctrlr *ctrlr) { @@ -371,6 +385,12 @@ get_log_pages(struct spdk_nvme_ctrlr *ctrlr) printf("Get Log Page (SMART/health) failed\n"); } + if (get_firmware_log_page(ctrlr) == 0) { + outstanding_commands++; + } else { + printf("Get Log Page (Firmware Slot Information) failed\n"); + } + if (cdata->vid == SPDK_PCI_VID_INTEL) { if (spdk_nvme_ctrlr_is_log_page_supported(ctrlr, SPDK_NVME_INTEL_LOG_SMART)) { if (get_intel_smart_log_page(ctrlr) == 0) { @@ -452,6 +472,27 @@ print_uint_var_dec(uint8_t *array, unsigned int len) printf("%lu", result); } +/* Print ASCII string as defined by the NVMe spec */ +static void +print_ascii_string(const void *buf, size_t size) +{ + const uint8_t *str = buf; + + /* Trim trailing spaces */ + while (size > 0 && str[size - 1] == ' ') { + size--; + } + + while (size--) { + if (*str >= 0x20 && *str <= 0x7E) { + printf("%c", *str); + } else { + printf("."); + } + str++; + } +} + static void print_namespace(struct spdk_nvme_ns *ns) { @@ -780,6 +821,25 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport cdata->sgls.sgl_offset ? "Supported" : "Not Supported"); printf("\n"); + printf("Firmware Slot Information\n"); + printf("=========================\n"); + if (g_hex_dump) { + hex_dump(&firmware_page, sizeof(firmware_page)); + printf("\n"); + } + printf("Active slot: %u\n", firmware_page.afi.active_slot); + if (firmware_page.afi.next_reset_slot) { + printf("Next controller reset slot: %u\n", firmware_page.afi.next_reset_slot); + } + for (i = 0; i < 7; i++) { + if (!spdk_mem_all_zero(firmware_page.revision[i], sizeof(firmware_page.revision[i]))) { + printf("Slot %u Firmware Revision: ", i + 1); + print_ascii_string(firmware_page.revision[i], sizeof(firmware_page.revision[i])); + printf("\n"); + } + } + printf("\n"); + printf("Error Log\n"); printf("=========\n"); for (i = 0; i <= cdata->elpe; i++) {