Source-Changes-HG archive

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

[src/trunk]: src/sbin/nvmectl add -s option for 'power' command, this instruc...



details:   https://anonhg.NetBSD.org/src/rev/be1ff1402707
branches:  trunk
changeset: 955373:be1ff1402707
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sun Sep 27 18:17:35 2020 +0000

description:
add -s option for 'power' command, this instructs the controller to save
the value so it persists resets/whatnot; the NVMe specification lists
this as optional, so this only works if the controller supports it

diffstat:

 sbin/nvmectl/nvmectl.8 |  18 ++++++++++++++++--
 sbin/nvmectl/nvmectl.h |   4 ++--
 sbin/nvmectl/power.c   |  20 +++++++++++---------
 3 files changed, 29 insertions(+), 13 deletions(-)

diffs (131 lines):

diff -r e31a2d46f1d8 -r be1ff1402707 sbin/nvmectl/nvmectl.8
--- a/sbin/nvmectl/nvmectl.8    Sun Sep 27 18:11:31 2020 +0000
+++ b/sbin/nvmectl/nvmectl.8    Sun Sep 27 18:17:35 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: nvmectl.8,v 1.5 2018/04/18 10:17:54 nonaka Exp $
+.\" $NetBSD: nvmectl.8,v 1.6 2020/09/27 18:17:35 jdolecek Exp $
 .\"
 .\" Copyright (c) 2012 Intel Corporation
 .\" All rights reserved.
@@ -34,7 +34,7 @@
 .\"
 .\" $FreeBSD: head/sbin/nvmecontrol/nvmecontrol.8 314230 2017-02-25 00:09:16Z imp $
 .\"
-.Dd May 19, 2016
+.Dd September 27, 2020
 .Dt NVMECTL 8
 .Os
 .Sh NAME
@@ -74,6 +74,7 @@
 .Nm
 .Ic power
 .Op Fl l
+.Op Fl s
 .Op Fl p Ar power_state
 .Op Fl w Ar workload_hint
 .Ar device_id
@@ -84,6 +85,19 @@
 .Sh DESCRIPTION
 NVM Express (NVMe) is a storage protocol standard, for SSDs and other
 high-speed storage devices over PCI Express.
+.Ss power
+The power command controls the supported power states.
+.Fl l
+will list supported power states.
+.Fl p
+will set the power state to specified value.
+.Fl w
+will set workload value.
+With
+.Fl s ,
+the specified power state and workload value is saved,
+so it persists any autonomous transitions and resets.
+Support for saving the values is optional, and depends on the controller.
 .Ss logpage
 The logpage command knows how to print log pages of various types.
 It also knows about vendor specific log pages from hgst/wdc and intel.
diff -r e31a2d46f1d8 -r be1ff1402707 sbin/nvmectl/nvmectl.h
--- a/sbin/nvmectl/nvmectl.h    Sun Sep 27 18:11:31 2020 +0000
+++ b/sbin/nvmectl/nvmectl.h    Sun Sep 27 18:17:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmectl.h,v 1.8 2018/04/18 10:16:22 nonaka Exp $       */
+/*     $NetBSD: nvmectl.h,v 1.9 2020/09/27 18:17:35 jdolecek Exp $     */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -78,7 +78,7 @@
 #endif
 
 #define POWER_USAGE                                                           \
-"power [-l] [-p new-state [-w workload-hint]] <controller_id>\n"
+"power [-l] [[-s] -p new-state [-w workload-hint]] <controller_id>\n"
 
 #define WDC_USAGE                                                             \
 "wdc cap-diag [-o path-templete]\n"
diff -r e31a2d46f1d8 -r be1ff1402707 sbin/nvmectl/power.c
--- a/sbin/nvmectl/power.c      Sun Sep 27 18:11:31 2020 +0000
+++ b/sbin/nvmectl/power.c      Sun Sep 27 18:17:35 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: power.c,v 1.5 2020/09/27 17:27:07 jdolecek Exp $       */
+/*     $NetBSD: power.c,v 1.6 2020/09/27 18:17:35 jdolecek Exp $       */
 
 /*-
  * Copyright (c) 2016 Netflix, Inc
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: power.c,v 1.5 2020/09/27 17:27:07 jdolecek Exp $");
+__RCSID("$NetBSD: power.c,v 1.6 2020/09/27 18:17:35 jdolecek Exp $");
 #if 0
 __FBSDID("$FreeBSD: head/sbin/nvmecontrol/power.c 329824 2018-02-22 13:32:31Z wma $");
 #endif
@@ -96,15 +96,14 @@
 }
 
 static void
-power_set(int fd, int power_val, int workload, int perm)
+power_set(int fd, int power_val, int workload, int saveflag)
 {
        struct nvme_pt_command  pt;
-       uint32_t p;
 
-       p = perm ? (1u << 31) : 0;
        memset(&pt, 0, sizeof(pt));
        pt.cmd.opcode = NVM_ADMIN_SET_FEATURES;
-       pt.cmd.cdw10 = NVM_FEAT_POWER_MANAGEMENT | p;
+       pt.cmd.cdw10 = NVM_FEAT_POWER_MANAGEMENT
+               | (saveflag ? NVM_SET_FEATURES_SV : 0);
        pt.cmd.cdw11 = power_val | (workload << 5);
 
        if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
@@ -138,15 +137,18 @@
 power(int argc, char *argv[])
 {
        struct nvm_identify_controller  cdata;
-       int                             ch, listflag = 0, powerflag = 0, power_val = 0, fd;
+       int                             ch, listflag = 0, powerflag = 0, power_val = 0, fd, saveflag = 0;
        int                             workload = 0;
        char                            *end;
 
-       while ((ch = getopt(argc, argv, "lp:w:")) != -1) {
+       while ((ch = getopt(argc, argv, "lsp:w:")) != -1) {
                switch (ch) {
                case 'l':
                        listflag = 1;
                        break;
+               case 's':
+                       saveflag = 1;
+                       break;
                case 'p':
                        powerflag = 1;
                        power_val = strtol(optarg, &end, 0);
@@ -185,7 +187,7 @@
        }
 
        if (powerflag) {
-               power_set(fd, power_val, workload, 0);
+               power_set(fd, power_val, workload, saveflag);
                goto out;
        }
        power_show(fd);



Home | Main Index | Thread Index | Old Index