xref: /illumos-gate/usr/src/test/nvme-tests/tests/ioctl/basic-get-feature.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2024 Oxide Computer Company
14  */
15 
16 /*
17  * Perform a GET FEATURES commands that should work on all devices since NVMe
18  * 1.0 (though may fail on some emulated cases). We use the temperature
19  * threshold feature because its output value is generally expected to be
20  * non-zero and the default is 0xFFFF (as of NVMe 1.2). If we find devices that
21  * actually return a default of zero, we should probably put them in an ignore
22  * list in here.
23  */
24 
25 #include <err.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 
30 #include "nvme_ioctl_util.h"
31 
32 int
33 main(void)
34 {
35 	int fd = nvme_ioctl_test_get_fd(0);
36 	nvme_ioctl_get_feature_t get;
37 
38 	(void) memset(&get, 0, sizeof (get));
39 	get.nigf_fid = NVME_FEAT_TEMPERATURE;
40 
41 	if (ioctl(fd, NVME_IOC_GET_FEATURE, &get) != 0) {
42 		err(EXIT_FAILURE, "TEST FAILED: failed to issue NVMe get "
43 		    "features ioctl");
44 	} else if (get.nigf_common.nioc_drv_err != NVME_IOCTL_E_OK) {
45 		errx(EXIT_FAILURE, "TEST FAILED: failed to get temperature "
46 		    "threshold feature: found error 0x%x, but expected success",
47 		    get.nigf_common.nioc_drv_err);
48 	}
49 
50 	if (get.nigf_cdw0 == 0) {
51 		errx(EXIT_FAILURE, "TEST FAILED: found zeroed cdw0 value for "
52 		    "composite temperature threshold");
53 	} else {
54 		(void) printf("TEST PASSED: successfully read composite "
55 		    "temperature threshold\n");
56 	}
57 
58 	VERIFY0(close(fd));
59 	return (0);
60 }
61