Source-Changes-HG archive

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

[src/trunk]: src nvmectl(8): Added NVM Express control utility.



details:   https://anonhg.NetBSD.org/src/rev/f578d4d39884
branches:  trunk
changeset: 345668:f578d4d39884
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Sat Jun 04 16:29:35 2016 +0000

description:
nvmectl(8): Added NVM Express control utility.

Ported from FreeBSD nvmecontrol(8).

diffstat:

 distrib/sets/lists/base/mi  |    3 +-
 distrib/sets/lists/debug/mi |    3 +-
 distrib/sets/lists/man/mi   |    5 +-
 sbin/Makefile               |    5 +-
 sbin/nvmectl/Makefile       |   19 ++
 sbin/nvmectl/devlist.c      |  123 ++++++++++++++
 sbin/nvmectl/firmware.c     |  333 ++++++++++++++++++++++++++++++++++++++
 sbin/nvmectl/identify.c     |  314 ++++++++++++++++++++++++++++++++++++
 sbin/nvmectl/logpage.c      |  377 ++++++++++++++++++++++++++++++++++++++++++++
 sbin/nvmectl/nvme.h         |  143 ++++++++++++++++
 sbin/nvmectl/nvmectl.8      |  147 +++++++++++++++++
 sbin/nvmectl/nvmectl.c      |  287 +++++++++++++++++++++++++++++++++
 sbin/nvmectl/nvmectl.h      |   94 ++++++++++
 sbin/nvmectl/perftest.c     |  185 +++++++++++++++++++++
 sbin/nvmectl/power.c        |  194 ++++++++++++++++++++++
 sbin/nvmectl/reset.c        |   80 +++++++++
 sys/dev/ic/nvmereg.h        |   82 ++++++++-
 17 files changed, 2383 insertions(+), 11 deletions(-)

diffs (truncated from 2599 to 300 lines):

diff -r f0f944f2c6d2 -r f578d4d39884 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sat Jun 04 16:14:29 2016 +0000
+++ b/distrib/sets/lists/base/mi        Sat Jun 04 16:29:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1126 2016/06/04 15:27:11 agc Exp $
+# $NetBSD: mi,v 1.1127 2016/06/04 16:29:35 nonaka Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -527,6 +527,7 @@
 ./sbin/nfsiod                                  base-obsolete           obsolete
 ./sbin/nologin                                 base-sysutil-root
 ./sbin/npfctl                                  base-npf-bin            npf
+./sbin/nvmectl                                 base-sysutil-root
 ./sbin/pdisk                                   base-sysutil-root
 ./sbin/pfctl                                   base-pf-root            pf
 ./sbin/pflogd                                  base-pf-root            pf
diff -r f0f944f2c6d2 -r f578d4d39884 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Sat Jun 04 16:14:29 2016 +0000
+++ b/distrib/sets/lists/debug/mi       Sat Jun 04 16:29:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.154 2016/06/01 23:59:21 joerg Exp $
+# $NetBSD: mi,v 1.155 2016/06/04 16:29:35 nonaka Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -377,6 +377,7 @@
 ./usr/libdata/debug/sbin/newfs_udf.debug       comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/newfs_v7fs.debug      comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/npfctl.debug          comp-npf-debug          npf,debug
+./usr/libdata/debug/sbin/nvmectl.debug         comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/pdisk.debug           comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/pfctl.debug           comp-pf-debug           pf,debug
 ./usr/libdata/debug/sbin/pflogd.debug          comp-pf-debug           pf,debug
diff -r f0f944f2c6d2 -r f578d4d39884 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sat Jun 04 16:14:29 2016 +0000
+++ b/distrib/sets/lists/man/mi Sat Jun 04 16:29:35 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1525 2016/06/04 15:27:11 agc Exp $
+# $NetBSD: mi,v 1.1526 2016/06/04 16:29:35 nonaka Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2779,6 +2779,7 @@
 ./usr/share/man/cat8/ntpq.0                    man-ntp-catman          .cat
 ./usr/share/man/cat8/ntptime.0                 man-ntp-catman          .cat
 ./usr/share/man/cat8/ntptrace.0                        man-ntp-catman          .cat
+./usr/share/man/cat8/nvmectl.0                 man-sysutil-catman      .cat
 ./usr/share/man/cat8/ofctl.0                   man-sysutil-catman      .cat
 ./usr/share/man/cat8/ofppc/MAKEDEV.0           man-obsolete            obsolete
 ./usr/share/man/cat8/ofppc/makedev.0           man-obsolete            obsolete
@@ -5630,6 +5631,7 @@
 ./usr/share/man/html8/ntpq.html                        man-ntp-htmlman         html
 ./usr/share/man/html8/ntptime.html             man-ntp-htmlman         html
 ./usr/share/man/html8/ntptrace.html            man-ntp-htmlman         html
+./usr/share/man/html8/nvmectl.html             man-sysutil-htmlman     html
 ./usr/share/man/html8/ofctl.html               man-sysutil-htmlman     html
 ./usr/share/man/html8/oqmgr.html               man-postfix-htmlman     postfix,html
 ./usr/share/man/html8/pac.html                 man-sysutil-htmlman     html
@@ -8705,6 +8707,7 @@
 ./usr/share/man/man8/ntpq.8                    man-ntp-man             .man
 ./usr/share/man/man8/ntptime.8                 man-ntp-man             .man
 ./usr/share/man/man8/ntptrace.8                        man-ntp-man             .man
+./usr/share/man/man8/nvmectl.8                 man-sysutil-man         .man
 ./usr/share/man/man8/ofctl.8                   man-sysutil-man         .man
 ./usr/share/man/man8/ofppc/MAKEDEV.8           man-obsolete            obsolete
 ./usr/share/man/man8/ofppc/makedev.8           man-obsolete            obsolete
diff -r f0f944f2c6d2 -r f578d4d39884 sbin/Makefile
--- a/sbin/Makefile     Sat Jun 04 16:14:29 2016 +0000
+++ b/sbin/Makefile     Sat Jun 04 16:29:35 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.127 2014/09/11 13:10:03 roy Exp $
+#      $NetBSD: Makefile,v 1.128 2016/06/04 16:29:35 nonaka Exp $
 #      @(#)Makefile    8.5 (Berkeley) 3/31/94
 
 # Not ported: XNSrouted enpload scsiformat startslip
@@ -9,7 +9,8 @@
 SUBDIR=        amrctl apmlabel atactl badsect bioctl brconfig ccdconfig \
        chown devpubd disklabel dkctl dkscan_bsdlabel dmesg dmctl \
        drvctl fastboot fdisk fsck fsirand gpt ifconfig init ldconfig luactl \
-       mbrlabel mknod modload modstat modunload mount newbtconf nologin \
+       mbrlabel mknod modload modstat modunload mount \
+       newbtconf nologin nvmectl \
        ping pppoectl raidctl reboot rcorder rndctl route routed \
        savecore scan_ffs scsictl shutdown slattach svhlabel swapctl sysctl \
        ttyflags umount veriexecctl wdogctl wsconsctl
diff -r f0f944f2c6d2 -r f578d4d39884 sbin/nvmectl/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/nvmectl/Makefile     Sat Jun 04 16:29:35 2016 +0000
@@ -0,0 +1,19 @@
+#      $NetBSD: Makefile,v 1.1 2016/06/04 16:29:35 nonaka Exp $
+
+.include <bsd.own.mk>
+
+PROG=  nvmectl
+SRCS=  nvmectl.c
+SRCS+= devlist.c
+SRCS+= firmware.c
+SRCS+= identify.c
+SRCS+= logpage.c
+SRCS+= perftest.c
+SRCS+= power.c
+SRCS+= reset.c
+MAN=   nvmectl.8
+
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+
+.include <bsd.prog.mk>
diff -r f0f944f2c6d2 -r f578d4d39884 sbin/nvmectl/devlist.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/nvmectl/devlist.c    Sat Jun 04 16:29:35 2016 +0000
@@ -0,0 +1,123 @@
+/*     $NetBSD: devlist.c,v 1.1 2016/06/04 16:29:35 nonaka Exp $       */
+
+/*-
+ * Copyright (C) 2012-2013 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: devlist.c,v 1.1 2016/06/04 16:29:35 nonaka Exp $");
+#if 0
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/devlist.c 260381 2014-01-06 23:48:47Z jimharris $");
+#endif
+#endif
+
+#include <sys/param.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "nvmectl.h"
+
+static void
+devlist_usage(void)
+{
+       fprintf(stderr, "usage:\n");
+       fprintf(stderr, DEVLIST_USAGE);
+       exit(1);
+}
+
+static inline uint32_t
+ns_get_sector_size(struct nvm_identify_namespace *nsdata)
+{
+
+       return 1 << nsdata->lbaf[NVME_ID_NS_FLBAS(nsdata->flbas)].lbads;
+}
+
+void
+devlist(int argc, char *argv[])
+{
+       struct nvm_identify_controller  cdata;
+       struct nvm_identify_namespace   nsdata;
+       char                            name[64];
+       uint8_t                         mn[64];
+       uint32_t                        i;
+       int                             ch, ctrlr, fd, found, ret;
+
+       while ((ch = getopt(argc, argv, "")) != -1) {
+               switch (ch) {
+               default:
+                       devlist_usage();
+               }
+       }
+
+       ctrlr = -1;
+       found = 0;
+
+       while (1) {
+               ctrlr++;
+               sprintf(name, "%s%d", NVME_CTRLR_PREFIX, ctrlr);
+
+               ret = open_dev(name, &fd, 0, 0);
+
+               if (ret != 0) {
+                       if (ret == EACCES) {
+                               warnx("could not open "_PATH_DEV"%s\n", name);
+                               continue;
+                       } else
+                               break;
+               }
+
+               found++;
+               read_controller_data(fd, &cdata);
+               nvme_strvis(mn, sizeof(mn), cdata.mn, sizeof(cdata.mn));
+               printf("%6s: %s\n", name, mn);
+
+               for (i = 0; i < cdata.nn; i++) {
+                       sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,
+                           NVME_NS_PREFIX, i+1);
+                       read_namespace_data(fd, i+1, &nsdata);
+                       printf("  %10s (%lldMB)\n",
+                               name,
+                               nsdata.nsze *
+                               (long long)ns_get_sector_size(&nsdata) /
+                               1024 / 1024);
+               }
+
+               close(fd);
+       }
+
+       if (found == 0)
+               printf("No NVMe controllers found.\n");
+
+       exit(1);
+}
diff -r f0f944f2c6d2 -r f578d4d39884 sbin/nvmectl/firmware.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/nvmectl/firmware.c   Sat Jun 04 16:29:35 2016 +0000
@@ -0,0 +1,333 @@
+/*     $NetBSD: firmware.c,v 1.1 2016/06/04 16:29:35 nonaka Exp $      */
+
+/*-
+ * Copyright (c) 2013 EMC Corp.
+ * All rights reserved.
+ *
+ * Copyright (C) 2012-2013 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: firmware.c,v 1.1 2016/06/04 16:29:35 nonaka Exp $");
+#if 0
+__FBSDID("$FreeBSD: head/sbin/nvmecontrol/firmware.c 258071 2013-11-12 21:14:19Z jimharris $");
+#endif
+#endif
+
+#include <sys/param.h>
+#include <sys/ioccom.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "nvmectl.h"
+
+#ifdef FIRMWARE_USAGE
+static int
+slot_has_valid_firmware(int fd, int slot)



Home | Main Index | Thread Index | Old Index