xref: /illumos-gate/usr/src/cmd/nvmeadm/nvmeadm.h (revision 7a27a99a5b13d5aa203a174e41ab2d4fd5f6566c)
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  * Copyright 2022 Tintri by DDN, Inc. All rights reserved.
15  */
16 
17 #ifndef _NVMEADM_H
18 #define	_NVMEADM_H
19 
20 #include <stdio.h>
21 #include <libdevinfo.h>
22 #include <libnvme.h>
23 #include <nvme_common.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 nvmeadm_feature nvmeadm_feature_t;
37 typedef struct nvmeadm_cmd nvmeadm_cmd_t;
38 
39 #define	NVMEADM_C_MULTI	1
40 #define	NVMEADM_C_EXCL	2
41 
42 /*
43  * General command structure
44  */
45 struct nvmeadm_cmd {
46 	const char *c_name;
47 	const char *c_desc;
48 	const char *c_flagdesc;
49 	const char *c_fielddesc;
50 	int (*c_func)(const nvme_process_arg_t *);
51 	void (*c_usage)(const char *);
52 	void (*c_optparse)(nvme_process_arg_t *);
53 	int c_flags;
54 };
55 
56 /*
57  * This is used to represent information for getting and printing specific
58  * features.
59  */
60 struct nvmeadm_feature {
61 	uint8_t f_feature;
62 	boolean_t (*f_get)(const nvme_process_arg_t *, const nvme_feat_disc_t *,
63 	    const nvmeadm_feature_t *);
64 	void (*f_print)(uint32_t, void *, size_t, const nvme_identify_ctrl_t *,
65 	    const nvme_version_t *);
66 };
67 
68 struct nvme_process_arg {
69 	nvme_t *npa_nvme;
70 	nvme_ctrl_t *npa_ctrl;
71 	nvme_ns_t *npa_ns;
72 	nvme_ctrl_info_t *npa_ctrl_info;
73 	nvme_ns_info_t *npa_ns_info;
74 	int npa_argc;
75 	char **npa_argv;
76 	char *npa_name;
77 	const char *npa_ctrl_name;
78 	boolean_t npa_excl;
79 	uint32_t npa_cmdflags;
80 	const nvmeadm_cmd_t *npa_cmd;
81 	const nvme_identify_ctrl_t *npa_idctl;
82 	const nvme_version_t *npa_version;
83 	ofmt_handle_t npa_ofmt;
84 	void *npa_cmd_arg;
85 };
86 
87 /*
88  * Command-specific arguments
89  */
90 typedef struct {
91 	boolean_t nll_unimpl;
92 	nvme_log_disc_scope_t nll_scope;
93 	uint32_t nll_nprint;
94 	int nll_nfilts;
95 	char *const *nll_filts;
96 	boolean_t *nll_used;
97 } nvmeadm_list_logs_t;
98 
99 typedef struct {
100 	boolean_t nf_unimpl;
101 	uint32_t nf_nprint;
102 	uint32_t nf_nfilts;
103 	char *const *nf_filts;
104 	boolean_t *nf_used;
105 } nvmeadm_features_t;
106 
107 typedef struct {
108 	const char *ngl_output;
109 } nvmeadm_get_logpage_t;
110 
111 /* Version checking */
112 extern boolean_t nvme_version_check(const nvme_process_arg_t *,
113     const nvme_version_t *);
114 
115 /* printing functions */
116 extern int nvme_strlen(const char *, int);
117 extern void nvme_print(int, const char *, int, const char *, ...);
118 extern int nvme_snprint_uint128(char *, size_t, nvme_uint128_t, int, int);
119 extern void nvme_print_ctrl_summary(nvme_ctrl_info_t *);
120 extern void nvme_print_nsid_summary(nvme_ns_info_t *);
121 extern void nvme_print_identify_ctrl(const nvme_identify_ctrl_t *, uint32_t,
122     const nvme_version_t *);
123 extern void nvme_print_identify_nsid(const nvme_identify_nsid_t *,
124     const nvme_version_t *);
125 extern void nvme_print_identify_nsid_list(const char *,
126     const nvme_identify_nsid_list_t *);
127 extern void nvme_print_identify_nsid_desc(void *);
128 extern void nvme_print_identify_ctrl_list(const char *,
129     const nvme_identify_ctrl_list_t *);
130 extern void nvme_print_error_log(int, const nvme_error_log_entry_t *,
131     const nvme_version_t *);
132 extern void nvme_print_health_log(const nvme_health_log_t *,
133     const nvme_identify_ctrl_t *,
134     const nvme_version_t *);
135 extern void nvme_print_fwslot_log(const nvme_fwslot_log_t *,
136     const nvme_identify_ctrl_t *);
137 
138 extern void nvme_print_feat_unknown(nvme_feat_output_t, uint32_t, void *,
139     size_t);
140 extern void nvme_print_feat_arbitration(uint32_t, void *, size_t,
141     const nvme_identify_ctrl_t *, const nvme_version_t *);
142 extern void nvme_print_feat_power_mgmt(uint32_t, void *, size_t,
143     const nvme_identify_ctrl_t *, const nvme_version_t *);
144 extern void nvme_print_feat_lba_range(uint32_t, void *, size_t,
145     const nvme_identify_ctrl_t *, const nvme_version_t *);
146 extern void nvme_print_feat_temperature(uint32_t, void *, size_t,
147     const nvme_identify_ctrl_t *, const nvme_version_t *);
148 extern void nvme_print_feat_error(uint32_t, void *, size_t,
149     const nvme_identify_ctrl_t *, const nvme_version_t *);
150 extern void nvme_print_feat_write_cache(uint32_t, void *, size_t,
151     const nvme_identify_ctrl_t *, const nvme_version_t *);
152 extern void nvme_print_feat_nqueues(uint32_t, void *, size_t,
153     const nvme_identify_ctrl_t *, const nvme_version_t *);
154 extern void nvme_print_feat_intr_coal(uint32_t, void *, size_t,
155     const nvme_identify_ctrl_t *, const nvme_version_t *);
156 extern void nvme_print_feat_intr_vect(uint32_t, void *, size_t,
157     const nvme_identify_ctrl_t *, const nvme_version_t *);
158 extern void nvme_print_feat_write_atom(uint32_t, void *, size_t,
159     const nvme_identify_ctrl_t *, const nvme_version_t *);
160 extern void nvme_print_feat_async_event(uint32_t, void *, size_t,
161     const nvme_identify_ctrl_t *, const nvme_version_t *);
162 extern void nvme_print_feat_auto_pst(uint32_t, void *, size_t,
163     const nvme_identify_ctrl_t *, const nvme_version_t *);
164 extern void nvme_print_feat_progress(uint32_t, void *, size_t,
165     const nvme_identify_ctrl_t *, const nvme_version_t *);
166 
167 extern void nvmeadm_dump_hex(const uint8_t *, size_t);
168 
169 /*
170  * ofmt related
171  */
172 typedef struct {
173 	const char *nloa_name;
174 	nvme_ctrl_info_t *nloa_ctrl;
175 	nvme_ns_info_t *nloa_ns;
176 	const char *nloa_disk;
177 } nvmeadm_list_ofmt_arg_t;
178 
179 extern const ofmt_field_t nvmeadm_list_ctrl_ofmt[];
180 extern const ofmt_field_t nvmeadm_list_nsid_ofmt[];
181 
182 typedef struct {
183 	const char *nlloa_name;
184 	const nvme_log_disc_t *nlloa_disc;
185 } nvmeadm_list_logs_ofmt_arg_t;
186 
187 extern const char *nvmeadm_list_logs_fields;
188 extern const char *nvmeadm_list_logs_fields_impl;
189 extern const ofmt_field_t nvmeadm_list_logs_ofmt[];
190 
191 typedef struct {
192 	const char *nlfoa_name;
193 	const nvme_feat_disc_t *nlfoa_feat;
194 } nvmeadm_list_features_ofmt_arg_t;
195 
196 extern const char *nvmeadm_list_features_fields;
197 extern const ofmt_field_t nvmeadm_list_features_ofmt[];
198 
199 
200 /*
201  * Warning and error cases. The default nvmeadm ones assume a libnvme related
202  * issue. Most errors are on the nvme_ctrl_t, which are the versions without any
203  * args. The ones that operate on the nvme_t handle have hdl in the name.
204  */
205 extern void nvmeadm_warn(const nvme_process_arg_t *, const char *,
206     ...) __PRINTFLIKE(2);
207 extern void nvmeadm_fatal(const nvme_process_arg_t *, const char *,
208     ...) __PRINTFLIKE(2) __NORETURN;
209 extern void nvmeadm_hdl_warn(const nvme_process_arg_t *, const char *,
210     ...) __PRINTFLIKE(2);
211 extern void nvmeadm_hdl_fatal(const nvme_process_arg_t *, const char *,
212     ...) __PRINTFLIKE(2) __NORETURN;
213 
214 /*
215  * Vendor specific commands.
216  *
217  * All vendor commands must first call nvmeadm_vuc_validate() which will
218  * validate that a given vendor unique command is useable by the device and then
219  * proceed to take any necessary locks that the command suggests.
220  */
221 extern nvme_vuc_disc_t *nvmeadm_vuc_init(const nvme_process_arg_t *,
222     const char *);
223 extern void nvmeadm_vuc_fini(const nvme_process_arg_t *, nvme_vuc_disc_t *);
224 
225 extern int do_wdc_e6dump(const nvme_process_arg_t *);
226 extern void optparse_wdc_e6dump(nvme_process_arg_t *);
227 extern void usage_wdc_e6dump(const char *);
228 
229 extern int do_wdc_resize(const nvme_process_arg_t *);
230 extern void optparse_wdc_resize(nvme_process_arg_t *);
231 extern void usage_wdc_resize(const char *);
232 
233 extern int do_wdc_clear_assert(const nvme_process_arg_t *);
234 extern void usage_wdc_clear_assert(const char *);
235 
236 extern int do_wdc_inject_assert(const nvme_process_arg_t *);
237 extern void usage_wdc_inject_assert(const char *);
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif /* _NVMEADM_H */
244