Skip to content

Commit 7a35395

Browse files
arthurshauigaw
authored andcommitted
ocp: Add Get DSSD Power State Feature (FID: C7h)
Implements the Get DSSD Power State Feature (FID C7h). Also added an optional flag that you can pass to the plugin command to print out all three values at once. Signed-off-by: Arthur Shau <arthurshau@meta.com>
1 parent 931082b commit 7a35395

File tree

5 files changed

+198
-5
lines changed

5 files changed

+198
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
get-dssd-power-state-feature(1)
2+
===============================
3+
4+
NAME
5+
----
6+
nvme-ocp-get-dssd-power-state-feature - Get DSSD Power State
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
'nvme ocp get-dssd-power-state-feature' <device>
12+
[--sel=<select> | -S <select>] [--all | -a]
13+
[--no-uuid | -n]
14+
15+
DESCRIPTION
16+
-----------
17+
For the NVMe device given, retrieves OCP DSSD Power State.
18+
Passing --all calls NVMe Get Feature three times, returning all three of
19+
the Current, Default, and Saved values.
20+
21+
The <device> parameter is mandatory and may be either the NVMe character
22+
device (ex: /dev/nvme0) or block device (ex: /dev/nvme0n1).
23+
24+
This will only work on OCP compliant devices supporting this feature.
25+
Results for any other device are undefined.
26+
27+
On success it returns 0, error code otherwise.
28+
29+
OPTIONS
30+
-------
31+
-S <select>::
32+
--sel=<select>::
33+
Select (SEL): This field specifies which value of the attributes
34+
to return in the provided data:
35+
+
36+
[]
37+
|==================
38+
|Select|Description
39+
|0|Current
40+
|1|Default
41+
|2|Saved
42+
|3|Supported capabilities
43+
|4-7|Reserved
44+
|==================
45+
46+
-a::
47+
--all::
48+
Print out all 3 values at once - Current DSSD Power State,
49+
Default DSSD Power State, and Saved DSSD Power State
50+
51+
-n::
52+
--no-uuid::
53+
Do not try to automatically detect UUID index for this command (required
54+
for old OCP 1.0 support)
55+
56+
EXAMPLES
57+
--------
58+
* Has the program issue a get-dssd-power-state-feature command to get the Curent DSSD Power State in watts.
59+
+
60+
------------
61+
# nvme ocp get-dssd-power-state-feature /dev/nvme0 -S 0
62+
------------
63+
+
64+
65+
* Has the program issue a get-dssd-power-state-feature command to get all three DSSD Power States in watts.
66+
+
67+
------------
68+
# nvme ocp get-dssd-power-state-feature /dev/nvme0 -a
69+
------------
70+
71+
72+
NVME
73+
----
74+
Part of the nvme-user suite.

completions/_nvme

+15
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ _nvme () {
256256
_arguments '*:: :->subcmds'
257257
_describe -t commands "nvme ocp set-dssd-power-state-feature options" _set_dssd_power_state_feature
258258
;;
259+
(get-dssd-power-state-feature)
260+
local _get_dssd_power_state_feature
261+
_get_dssd_power_state_feature=(
262+
/dev/nvme':supply a device to use (required)'
263+
--sel=':select from 0 - current, 1 - default, 2 - saved, 3 - supported'
264+
-S':alias to --sel'
265+
--all=':Print out all 3 values at once - current, default, and saved'
266+
-a':alias to --all'
267+
--no-uuid':Skip UUID index search'
268+
-n':alias for --no-uuid'
269+
)
270+
_arguments '*:: :->subcmds'
271+
_describe -t commands "nvme ocp get-dssd-power-state-feature options" _get_dssd_power_state_feature
272+
;;
259273
(telemetry-string-log)
260274
local _telemetry_string_log
261275
_telemetry_string_log=(
@@ -2358,6 +2372,7 @@ _nvme () {
23582372
vs-fw-activate-history':Get firmware activation history log'
23592373
device-capability-log':Get Device capability log'
23602374
set-dssd-power-state-feature':Set DSSD Power State'
2375+
get-dssd-power-state-feature':Get DSSD Power State'
23612376
telemetry-string-log':Retrieve Telemetry string Log Page'
23622377
set-telemetry-profile':Set Telemetry Profile'
23632378
)

completions/bash-nvme-completion.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ plugin_ocp_opts () {
14551455
"set-dssd-power-state-feature")
14561456
opts+=" --power-state= -p --no-uuid -n --save -s"
14571457
;;
1458+
"get-dssd-power-state-feature")
1459+
opts+=" --sel= -S --all -a --no-uuid -n"
1460+
;;
14581461
"telemetry-string-log")
14591462
opts+=" --output-file= -o"
14601463
;;
@@ -1464,7 +1467,7 @@ plugin_ocp_opts () {
14641467
"set-dssd-async-event-config")
14651468
opts+=" --enable-panic-notices -e --save -s"
14661469
;;
1467-
"get-dssd-power-state-feature")
1470+
"get-dssd-async-event-config")
14681471
opts+=" --sel= -S"
14691472
;;
14701473
"help")
@@ -1542,9 +1545,9 @@ _nvme_subcmds () {
15421545
clear-fw-activate-history eol-plp-failure-mode \
15431546
clear-pcie-correctable-error-counters \
15441547
vs-fw-activate-history device-capability-log \
1545-
set-dssd-power-state-feature telemetry-string-log \
1546-
set-telemetry-profile set-dssd-async-event-config \
1547-
get-dssd-async-event-config"
1548+
set-dssd-power-state-feature get-dssd-power-state-feature \
1549+
telemetry-string-log set-telemetry-profile \
1550+
set-dssd-async-event-config get-dssd-async-event-config"
15481551
)
15491552

15501553
# Associative array mapping plugins to corresponding option completions

plugins/ocp/ocp-nvme.c

+100
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,106 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *c
22372237
return err;
22382238
}
22392239

2240+
///////////////////////////////////////////////////////////////////////////////
2241+
///////////////////////////////////////////////////////////////////////////////
2242+
///////////////////////////////////////////////////////////////////////////////
2243+
///////////////////////////////////////////////////////////////////////////////
2244+
/// DSSD Power State (Feature Identifier C7h) Get Feature
2245+
2246+
static int get_dssd_power_state(struct nvme_dev *dev, const __u32 nsid,
2247+
const __u8 fid, __u8 sel, bool uuid)
2248+
{
2249+
__u32 result;
2250+
int err;
2251+
__u8 uuid_index = 0;
2252+
2253+
if (uuid) {
2254+
/* OCP 2.0 requires UUID index support */
2255+
err = ocp_get_uuid_index(dev, &uuid_index);
2256+
if (err || !uuid_index) {
2257+
nvme_show_error("ERROR: No OCP UUID index found");
2258+
return err;
2259+
}
2260+
}
2261+
2262+
struct nvme_get_features_args args = {
2263+
.args_size = sizeof(args),
2264+
.fd = dev_fd(dev),
2265+
.fid = fid,
2266+
.nsid = nsid,
2267+
.sel = sel,
2268+
.cdw11 = 0,
2269+
.uuidx = uuid_index,
2270+
.data_len = 0,
2271+
.data = NULL,
2272+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
2273+
.result = &result,
2274+
};
2275+
2276+
err = nvme_get_features(&args);
2277+
if (!err) {
2278+
printf("get-feature:0xC7 %s value: %#08x\n", nvme_select_to_string(sel), result);
2279+
2280+
if (sel == NVME_GET_FEATURES_SEL_SUPPORTED)
2281+
nvme_show_select_result(fid, result);
2282+
} else {
2283+
nvme_show_error("Could not get feature: 0xC7 with sel: %d\n", sel);
2284+
}
2285+
2286+
return err;
2287+
}
2288+
2289+
static int get_dssd_power_state_feature(int argc, char **argv, struct command *cmd,
2290+
struct plugin *plugin)
2291+
{
2292+
const char *desc = "Define DSSD Power State (Feature Identifier C7h) Get Feature.";
2293+
const char *all = "Print out all 3 values at once - Current, Default, and Saved";
2294+
const char *sel = "[0-3]: current/default/saved/supported/";
2295+
const __u32 nsid = 0;
2296+
const __u8 fid = 0xC7;
2297+
struct nvme_dev *dev;
2298+
int i, err;
2299+
2300+
struct config {
2301+
__u8 sel;
2302+
bool all;
2303+
};
2304+
2305+
struct config cfg = {
2306+
.sel = 0,
2307+
.all = false,
2308+
};
2309+
2310+
OPT_ARGS(opts) = {
2311+
OPT_BYTE("sel", 'S', &cfg.sel, sel),
2312+
OPT_FLAG("all", 'a', NULL, all),
2313+
OPT_FLAG("no-uuid", 'n', NULL,
2314+
"Skip UUID index search (UUID index not required for OCP 1.0)"),
2315+
OPT_END()
2316+
};
2317+
2318+
err = parse_and_open(&dev, argc, argv, desc, opts);
2319+
if (err)
2320+
return err;
2321+
2322+
if (argconfig_parse_seen(opts, "all")) {
2323+
for (i = 0; i < 3; i++) {
2324+
err = get_dssd_power_state(dev, nsid, fid, i,
2325+
!argconfig_parse_seen(opts, "no-uuid"));
2326+
if (err)
2327+
break;
2328+
}
2329+
} else if (argconfig_parse_seen(opts, "sel"))
2330+
err = get_dssd_power_state(dev, nsid, fid, cfg.sel,
2331+
!argconfig_parse_seen(opts, "no-uuid"));
2332+
else
2333+
nvme_show_error("Required to have --sel as an argument, or pass the --all flag.");
2334+
2335+
dev_close(dev);
2336+
2337+
return err;
2338+
}
2339+
22402340
///////////////////////////////////////////////////////////////////////////////
22412341
///////////////////////////////////////////////////////////////////////////////
22422342
///////////////////////////////////////////////////////////////////////////////

plugins/ocp/ocp-nvme.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION),
2626
ENTRY("unsupported-reqs-log", "Get Unsupported Requirements Log Page", ocp_unsupported_requirements_log)
2727
ENTRY("error-recovery-log", "Retrieve Error Recovery Log Page", ocp_error_recovery_log)
2828
ENTRY("device-capability-log", "Get Device capabilities Requirements Log Page", ocp_device_capabilities_log)
29-
ENTRY("set-dssd-power-state-feature", "Get Device capabilities Requirements Log Page", set_dssd_power_state_feature)
29+
ENTRY("set-dssd-power-state-feature", "Set DSSD Power State feature", set_dssd_power_state_feature)
30+
ENTRY("get-dssd-power-state-feature", "Get DSSD Power State feature", get_dssd_power_state_feature)
3031
ENTRY("set-plp-health-check-interval", "Set PLP Health Check Interval", set_plp_health_check_interval)
3132
ENTRY("get-plp-health-check-interval", "Get PLP Health Check Interval", get_plp_health_check_interval)
3233
ENTRY("telemetry-string-log", "Retrieve Telemetry string Log Page", ocp_telemetry_str_log_format)

0 commit comments

Comments
 (0)