xref: /illumos-gate/usr/src/cmd/nvmeadm/nvmeadm.h (revision f96a0cef040313f6281fbc014a0b63d5c5cc760f)
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 2016 Nexenta Systems, Inc.
14  * Copyright 2019 Western Digital Corporation
15  * Copyright 2021 Oxide Computer Company
16  */
17 
18 #ifndef _NVMEADM_H
19 #define	_NVMEADM_H
20 
21 #include <stdio.h>
22 #include <libdevinfo.h>
23 #include <sys/nvme.h>
24 #include <nvme_reg.h>
25 #include <ofmt.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 extern int verbose;
32 extern int debug;
33 
34 /* Common structures */
35 typedef struct nvme_process_arg nvme_process_arg_t;
36 typedef struct nvme_feature nvme_feature_t;
37 typedef struct nvmeadm_cmd nvmeadm_cmd_t;
38 
39 struct nvme_process_arg {
40 	int npa_argc;
41 	char **npa_argv;
42 	char *npa_name;
43 	char *npa_nsid;
44 	int npa_found;
45 	boolean_t npa_isns;
46 	const nvmeadm_cmd_t *npa_cmd;
47 	di_node_t npa_node;
48 	di_minor_t npa_minor;
49 	char *npa_path;
50 	char *npa_dsk;
51 	nvme_identify_ctrl_t *npa_idctl;
52 	nvme_identify_nsid_t *npa_idns;
53 	nvme_version_t *npa_version;
54 	ofmt_handle_t npa_ofmt;
55 };
56 
57 /* Version checking */
58 extern boolean_t nvme_version_check(nvme_version_t *, uint_t, uint_t);
59 
60 /* printing functions */
61 extern int nvme_strlen(const char *, int);
62 extern void nvme_print(int, const char *, int, const char *, ...);
63 extern void nvme_print_ctrl_summary(nvme_identify_ctrl_t *, nvme_version_t *);
64 extern void nvme_print_nsid_summary(nvme_identify_nsid_t *);
65 extern void nvme_print_identify_ctrl(nvme_identify_ctrl_t *,
66     nvme_capabilities_t *, nvme_version_t *);
67 extern void nvme_print_identify_nsid(nvme_identify_nsid_t *, nvme_version_t *);
68 extern void nvme_print_error_log(int, nvme_error_log_entry_t *,
69     nvme_version_t *);
70 extern void nvme_print_health_log(nvme_health_log_t *, nvme_identify_ctrl_t *,
71     nvme_version_t *);
72 extern void nvme_print_fwslot_log(nvme_fwslot_log_t *);
73 
74 extern void nvme_print_feat_arbitration(uint64_t, void *, size_t,
75     nvme_identify_ctrl_t *, nvme_version_t *);
76 extern void nvme_print_feat_power_mgmt(uint64_t, void *, size_t,
77     nvme_identify_ctrl_t *, nvme_version_t *);
78 extern void nvme_print_feat_lba_range(uint64_t, void *, size_t,
79     nvme_identify_ctrl_t *, nvme_version_t *);
80 extern void nvme_print_feat_temperature(uint64_t, void *, size_t,
81     nvme_identify_ctrl_t *, nvme_version_t *);
82 extern void nvme_print_feat_error(uint64_t, void *, size_t,
83     nvme_identify_ctrl_t *, nvme_version_t *);
84 extern void nvme_print_feat_write_cache(uint64_t, void *, size_t,
85     nvme_identify_ctrl_t *, nvme_version_t *);
86 extern void nvme_print_feat_nqueues(uint64_t, void *, size_t,
87     nvme_identify_ctrl_t *, nvme_version_t *);
88 extern void nvme_print_feat_intr_coal(uint64_t, void *, size_t,
89     nvme_identify_ctrl_t *, nvme_version_t *);
90 extern void nvme_print_feat_intr_vect(uint64_t, void *, size_t,
91     nvme_identify_ctrl_t *, nvme_version_t *);
92 extern void nvme_print_feat_write_atom(uint64_t, void *, size_t,
93     nvme_identify_ctrl_t *, nvme_version_t *);
94 extern void nvme_print_feat_async_event(uint64_t, void *, size_t,
95     nvme_identify_ctrl_t *, nvme_version_t *);
96 extern void nvme_print_feat_auto_pst(uint64_t, void *, size_t,
97     nvme_identify_ctrl_t *, nvme_version_t *);
98 extern void nvme_print_feat_progress(uint64_t, void *, size_t,
99     nvme_identify_ctrl_t *, nvme_version_t *);
100 extern const char *nvme_str_error(int, int);
101 
102 /* device node functions */
103 extern int nvme_open(di_minor_t);
104 extern void nvme_close(int);
105 extern nvme_version_t *nvme_version(int);
106 extern nvme_capabilities_t *nvme_capabilities(int);
107 extern nvme_identify_ctrl_t *nvme_identify_ctrl(int);
108 extern nvme_identify_nsid_t *nvme_identify_nsid(int);
109 extern void *nvme_get_logpage(int, uint8_t, size_t *);
110 extern boolean_t nvme_get_feature(int, uint8_t, uint32_t, uint64_t *, size_t *,
111     void **);
112 extern int nvme_intr_cnt(int);
113 extern boolean_t nvme_format_nvm(int, uint8_t, uint8_t);
114 extern boolean_t nvme_detach(int);
115 extern boolean_t nvme_attach(int);
116 extern boolean_t nvme_firmware_load(int, void *, size_t, offset_t);
117 extern boolean_t nvme_firmware_commit(int fd, int, int, uint16_t *, uint16_t *);
118 
119 /*
120  * ofmt related
121  */
122 extern const ofmt_field_t nvme_list_ofmt[];
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif /* _NVMEADM_H */
129