Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: nvmectl(8): Add big-endian support.



details:   https://anonhg.NetBSD.org/src/rev/c30e8909608e
branches:  trunk
changeset: 318341:c30e8909608e
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Wed Apr 18 10:11:44 2018 +0000
description:
nvmectl(8): Add big-endian support.

from FreeBSD nvmecontolr(8) r329824.

diffstat:

 sbin/nvmectl/devlist.c  |    6 +-
 sbin/nvmectl/firmware.c |    8 +-
 sbin/nvmectl/identify.c |    6 +-
 sbin/nvmectl/logpage.c  |   87 +++++++++++++++++++++++++++++++++++++--
 sbin/nvmectl/nvme.h     |   22 +---------
 sbin/nvmectl/nvmectl.c  |   12 ++++-
 sbin/nvmectl/perftest.c |    6 +-
 sbin/nvmectl/power.c    |   10 ++--
 sbin/nvmectl/util.c     |   21 ++++++--
 sbin/nvmectl/wdc.c      |    6 +-
 sys/dev/ic/ld_nvme.c    |    8 +--
 sys/dev/ic/nvme.c       |   37 +++++++++-------
 sys/dev/ic/nvmeio.h     |  104 +++++++++++++++++++++++++++++++++++++++++++++++-
 13 files changed, 254 insertions(+), 79 deletions(-)

diffs (truncated from 700 to 300 lines):

diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/devlist.c
--- a/sbin/nvmectl/devlist.c    Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/devlist.c    Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: devlist.c,v 1.4 2018/04/17 08:54:35 nonaka Exp $       */
+/*     $NetBSD: devlist.c,v 1.5 2018/04/18 10:11:44 nonaka Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,9 +30,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: devlist.c,v 1.4 2018/04/17 08:54:35 nonaka Exp $");
+__RCSID("$NetBSD: devlist.c,v 1.5 2018/04/18 10:11:44 nonaka Exp $");
 #if 0
-__FBSDID("$FreeBSD: head/sbin/nvmecontrol/devlist.c 326276 2017-11-27 15:37:16Z pfg $");
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/devlist.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
 #endif
 
diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/firmware.c
--- a/sbin/nvmectl/firmware.c   Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/firmware.c   Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: firmware.c,v 1.3 2018/04/17 08:54:35 nonaka Exp $      */
+/*     $NetBSD: firmware.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -33,9 +33,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: firmware.c,v 1.3 2018/04/17 08:54:35 nonaka Exp $");
+__RCSID("$NetBSD: firmware.c,v 1.4 2018/04/18 10:11:44 nonaka Exp $");
 #if 0
-__FBSDID("$FreeBSD: head/sbin/nvmecontrol/firmware.c 326276 2017-11-27 15:37:16Z pfg $");
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/firmware.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
 #endif
 
@@ -188,7 +188,7 @@
        int                             fd = -1;
        int                             a_flag, s_flag, f_flag;
        int                             commit_action, reboot_required;
-       int                             ch,
+       int                             ch;
        char                            *p, *image = NULL;
        char                            *controller = NULL, prompt[64];
        void                            *buf = NULL;
diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/identify.c
--- a/sbin/nvmectl/identify.c   Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/identify.c   Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: identify.c,v 1.4 2018/04/17 08:54:35 nonaka Exp $      */
+/*     $NetBSD: identify.c,v 1.5 2018/04/18 10:11:44 nonaka Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,9 +30,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: identify.c,v 1.4 2018/04/17 08:54:35 nonaka Exp $");
+__RCSID("$NetBSD: identify.c,v 1.5 2018/04/18 10:11:44 nonaka Exp $");
 #if 0
-__FBSDID("$FreeBSD: head/sbin/nvmecontrol/identify.c 326276 2017-11-27 15:37:16Z pfg $");
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/identify.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
 #endif
 
diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/logpage.c
--- a/sbin/nvmectl/logpage.c    Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/logpage.c    Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: logpage.c,v 1.6 2018/04/17 08:54:35 nonaka Exp $       */
+/*     $NetBSD: logpage.c,v 1.7 2018/04/18 10:11:44 nonaka Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -33,9 +33,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: logpage.c,v 1.6 2018/04/17 08:54:35 nonaka Exp $");
+__RCSID("$NetBSD: logpage.c,v 1.7 2018/04/18 10:11:44 nonaka Exp $");
 #if 0
-__FBSDID("$FreeBSD: head/sbin/nvmecontrol/logpage.c 326276 2017-11-27 15:37:16Z pfg $");
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/logpage.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
 #endif
 
@@ -128,12 +128,30 @@
 }
 
 static void
+nvme_error_information_entry_swapbytes(struct nvme_error_information_entry *e)
+{
+#if _BYTE_ORDER != _LITTLE_ENDIAN
+       e->error_count = le64toh(e->error_count);
+       e->sqid = le16toh(e->sqid);
+       e->cid = le16toh(e->cid);
+       e->status = le16toh(e->status);
+       e->error_location = le16toh(e->error_location);
+       e->lba = le64toh(e->lba);
+       e->nsid = le32toh(e->nsid);
+       e->command_specific = le64toh(e->command_specific);
+#endif
+}
+
+static void
 print_log_error(const struct nvm_identify_controller *cdata __unused, void *buf,
     uint32_t size)
 {
        int                                     i, nentries;
        struct nvme_error_information_entry     *entry = buf;
 
+       /* Convert data to host endian */
+       nvme_error_information_entry_swapbytes(entry);
+
        printf("Error Information Log\n");
        printf("=====================\n");
 
@@ -181,11 +199,38 @@
 }
 
 static void
+nvme_health_information_page_swapbytes(struct nvme_health_information_page *e)
+{
+#if _BYTE_ORDER != _LITTLE_ENDIAN
+       u_int i;
+
+       e->composite_temperature = le16toh(e->composite_temperature);
+       nvme_le128toh(e->data_units_read);
+       nvme_le128toh(e->data_units_written);
+       nvme_le128toh(e->host_read_commands);
+       nvme_le128toh(e->host_write_commands);
+       nvme_le128toh(e->controller_busy_time);
+       nvme_le128toh(e->power_cycles);
+       nvme_le128toh(e->power_on_hours);
+       nvme_le128toh(e->unsafe_shutdowns);
+       nvme_le128toh(e->media_errors);
+       nvme_le128toh(e->num_error_info_log_entries);
+       e->warning_temp_time = le32toh(e->warning_temp_time);
+       e->error_temp_time = le32toh(e->error_temp_time);
+       for (i = 0; i < __arraycount(e->temp_sensor); i++)
+               e->temp_sensor[i] = le16toh(e->temp_sensor[i]);
+#endif
+}
+
+static void
 print_log_health(const struct nvm_identify_controller *cdata __unused, void *buf,
     uint32_t size __unused)
 {
        struct nvme_health_information_page *health = buf;
-       int i;
+       u_int i;
+
+       /* Convert data to host endian */
+       nvme_health_information_page_swapbytes(health);
 
        printf("SMART/Health Information Log\n");
        printf("============================\n");
@@ -232,7 +277,7 @@
 
        printf("Warning Temp Composite Time:    %d\n", health->warning_temp_time);
        printf("Error Temp Composite Time:      %d\n", health->error_temp_time);
-       for (i = 0; i < 7; i++) {
+       for (i = 0; i < __arraycount(health->temp_sensor); i++) {
                if (health->temp_sensor[i] == 0)
                        continue;
                printf("Temperature Sensor %d:           ", i + 1);
@@ -241,6 +286,17 @@
 }
 
 static void
+nvme_firmware_page_swapbytes(struct nvme_firmware_page *e)
+{
+#if _BYTE_ORDER != _LITTLE_ENDIAN
+       u_int i;
+
+       for (i = 0; i < __arraycount(e->revision); i++)
+               e->revision[i] = le64toh(e->revision[i]);
+#endif
+}
+
+static void
 print_log_firmware(const struct nvm_identify_controller *cdata, void *buf,
     uint32_t size __unused)
 {
@@ -248,6 +304,9 @@
        const char                      *status;
        struct nvme_firmware_page       *fw = buf;
 
+       /* Convert data to host endian */
+       nvme_firmware_page_swapbytes(fw);
+
        printf("Firmware Slot Log\n");
        printf("=================\n");
 
@@ -284,11 +343,29 @@
  * offset 147: it is only 1 byte, not 6.
  */
 static void
+intel_log_temp_stats_swapbytes(struct intel_log_temp_stats *e)
+{
+#if _BYTE_ORDER != _LITTLE_ENDIAN
+       e->current = le64toh(e->current);
+       e->overtemp_flag_last = le64toh(e->overtemp_flag_last);
+       e->overtemp_flag_life = le64toh(e->overtemp_flag_life);
+       e->max_temp = le64toh(e->max_temp);
+       e->min_temp = le64toh(e->min_temp);
+       e->max_oper_temp = le64toh(e->max_oper_temp);
+       e->min_oper_temp = le64toh(e->min_oper_temp);
+       e->est_offset = le64toh(e->est_offset);
+#endif
+}
+
+static void
 print_intel_temp_stats(const struct nvm_identify_controller *cdata __unused,
     void *buf, uint32_t size __unused)
 {
        struct intel_log_temp_stats     *temp = buf;
 
+       /* Convert data to host endian */
+       intel_log_temp_stats_swapbytes(temp);
+
        printf("Intel Temperature Log\n");
        printf("=====================\n");
 
diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/nvme.h
--- a/sbin/nvmectl/nvme.h       Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/nvme.h       Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvme.h,v 1.2 2017/04/29 00:06:40 nonaka Exp $  */
+/*     $NetBSD: nvme.h,v 1.3 2018/04/18 10:11:44 nonaka Exp $  */
 
 /*-
  * Copyright (C) 2012-2013 Intel Corporation
@@ -34,26 +34,6 @@
 /* Cap nvme to 1MB transfers driver explodes with larger sizes */
 #define NVME_MAX_XFER_SIZE             (MAXPHYS < (1<<20) ? MAXPHYS : (1<<20))
 
-/* Get/Set Features */
-#define        NVME_FEAT_ARBITRATION                           0x01
-#define        NVME_FEAT_POWER_MANAGEMENT                      0x02
-#define        NVME_FEAT_LBA_RANGE_TYPE                        0x03
-#define        NVME_FEAT_TEMPERATURE_THRESHOLD                 0x04
-#define        NVME_FEAT_ERROR_RECOVERY                        0x05
-#define        NVME_FEAT_VOLATILE_WRITE_CACHE                  0x06
-#define        NVME_FEAT_NUMBER_OF_QUEUES                      0x07
-#define        NVME_FEAT_INTERRUPT_COALESCING                  0x08
-#define        NVME_FEAT_INTERRUPT_VECTOR_CONFIGURATION        0x09
-#define        NVME_FEAT_WRITE_ATOMICITY_NORMAL                0x0a
-#define        NVME_FEAT_ASYNC_EVENT_CONFIGURATION             0x0b
-#define        NVME_FEAT_AUTONOMOUS_POWER_STATE_TRANSITION     0x0c
-#define        NVME_FEAT_HOST_MEMORY_BUFFER                    0x0d
-/* NVM Command Set specific */
-#define        NVME_FEAT_SOFTWARE_PROGRESS_MARKER              0x80
-#define        NVME_FEAT_HOST_IDENTIFIER                       0x81
-#define        NVME_FEAT_RESERVATION_NOTIFICATION_MASK         0x82
-#define        NVME_FEAT_RESERVATION_PERSISTANCE               0x83
-
 /* Get Log Page */
 #define        NVME_LOG_ERROR                                  0x01
 #define        NVME_LOG_HEALTH_INFORMATION                     0x02
diff -r 3d4015911776 -r c30e8909608e sbin/nvmectl/nvmectl.c
--- a/sbin/nvmectl/nvmectl.c    Wed Apr 18 10:10:26 2018 +0000
+++ b/sbin/nvmectl/nvmectl.c    Wed Apr 18 10:11:44 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmectl.c,v 1.6 2018/04/17 08:54:35 nonaka Exp $       */
+/*     $NetBSD: nvmectl.c,v 1.7 2018/04/18 10:11:44 nonaka Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,9 +30,9 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: nvmectl.c,v 1.6 2018/04/17 08:54:35 nonaka Exp $");
+__RCSID("$NetBSD: nvmectl.c,v 1.7 2018/04/18 10:11:44 nonaka Exp $");
 #if 0
-__FBSDID("$FreeBSD: head/sbin/nvmecontrol/nvmecontrol.c 326276 2017-11-27 15:37:16Z pfg $");
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/nvmecontrol.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
 #endif
 
@@ -167,6 +167,9 @@
 
        if (nvme_completion_is_error(&pt.cpl))
                errx(1, "identify request returned error");
+
+       /* Convert data to host endian */
+       nvme_identify_controller_swapbytes(cdata);
 }
 
 void
@@ -186,6 +189,9 @@
 



Home | Main Index | Thread Index | Old Index