Module Name:    src
Committed By:   jdolecek
Date:           Sun Sep 27 18:17:35 UTC 2020

Modified Files:
        src/sbin/nvmectl: nvmectl.8 nvmectl.h power.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sbin/nvmectl/nvmectl.8 src/sbin/nvmectl/power.c
cvs rdiff -u -r1.8 -r1.9 src/sbin/nvmectl/nvmectl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/nvmectl/nvmectl.8
diff -u src/sbin/nvmectl/nvmectl.8:1.5 src/sbin/nvmectl/nvmectl.8:1.6
--- src/sbin/nvmectl/nvmectl.8:1.5	Wed Apr 18 10:17:54 2018
+++ src/sbin/nvmectl/nvmectl.8	Sun Sep 27 18:17:35 2020
@@ -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.
Index: src/sbin/nvmectl/power.c
diff -u src/sbin/nvmectl/power.c:1.5 src/sbin/nvmectl/power.c:1.6
--- src/sbin/nvmectl/power.c:1.5	Sun Sep 27 17:27:07 2020
+++ src/sbin/nvmectl/power.c	Sun Sep 27 18:17:35 2020
@@ -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 @@ power_list(struct nvm_identify_controlle
 }
 
 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 @@ void
 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 @@ power(int argc, char *argv[])
 	}
 
 	if (powerflag) {
-		power_set(fd, power_val, workload, 0);
+		power_set(fd, power_val, workload, saveflag);
 		goto out;
 	}
 	power_show(fd);

Index: src/sbin/nvmectl/nvmectl.h
diff -u src/sbin/nvmectl/nvmectl.h:1.8 src/sbin/nvmectl/nvmectl.h:1.9
--- src/sbin/nvmectl/nvmectl.h:1.8	Wed Apr 18 10:16:22 2018
+++ src/sbin/nvmectl/nvmectl.h	Sun Sep 27 18:17:35 2020
@@ -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 @@ struct nvme_function {
 #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"

Reply via email to