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 /* Version checking */ 108 extern boolean_t nvme_version_check(const nvme_process_arg_t *, 109 const nvme_version_t *); 110 111 /* printing functions */ 112 extern int nvme_strlen(const char *, int); 113 extern void nvme_print(int, const char *, int, const char *, ...); 114 extern int nvme_snprint_uint128(char *, size_t, nvme_uint128_t, int, int); 115 extern void nvme_print_ctrl_summary(nvme_ctrl_info_t *); 116 extern void nvme_print_nsid_summary(nvme_ns_info_t *); 117 extern void nvme_print_identify_ctrl(const nvme_identify_ctrl_t *, uint32_t, 118 const nvme_version_t *); 119 extern void nvme_print_identify_nsid(const nvme_identify_nsid_t *, 120 const nvme_version_t *); 121 extern void nvme_print_identify_nsid_list(const char *, 122 const nvme_identify_nsid_list_t *); 123 extern void nvme_print_identify_nsid_desc(void *); 124 extern void nvme_print_identify_ctrl_list(const char *, 125 const nvme_identify_ctrl_list_t *); 126 extern void nvme_print_error_log(int, const nvme_error_log_entry_t *, 127 const nvme_version_t *); 128 extern void nvme_print_health_log(const nvme_health_log_t *, 129 const nvme_identify_ctrl_t *, 130 const nvme_version_t *); 131 extern void nvme_print_fwslot_log(const nvme_fwslot_log_t *, 132 const nvme_identify_ctrl_t *); 133 134 extern void nvme_print_feat_unknown(nvme_feat_output_t, uint32_t, void *, 135 size_t); 136 extern void nvme_print_feat_arbitration(uint32_t, void *, size_t, 137 const nvme_identify_ctrl_t *, const nvme_version_t *); 138 extern void nvme_print_feat_power_mgmt(uint32_t, void *, size_t, 139 const nvme_identify_ctrl_t *, const nvme_version_t *); 140 extern void nvme_print_feat_lba_range(uint32_t, void *, size_t, 141 const nvme_identify_ctrl_t *, const nvme_version_t *); 142 extern void nvme_print_feat_temperature(uint32_t, void *, size_t, 143 const nvme_identify_ctrl_t *, const nvme_version_t *); 144 extern void nvme_print_feat_error(uint32_t, void *, size_t, 145 const nvme_identify_ctrl_t *, const nvme_version_t *); 146 extern void nvme_print_feat_write_cache(uint32_t, void *, size_t, 147 const nvme_identify_ctrl_t *, const nvme_version_t *); 148 extern void nvme_print_feat_nqueues(uint32_t, void *, size_t, 149 const nvme_identify_ctrl_t *, const nvme_version_t *); 150 extern void nvme_print_feat_intr_coal(uint32_t, void *, size_t, 151 const nvme_identify_ctrl_t *, const nvme_version_t *); 152 extern void nvme_print_feat_intr_vect(uint32_t, void *, size_t, 153 const nvme_identify_ctrl_t *, const nvme_version_t *); 154 extern void nvme_print_feat_write_atom(uint32_t, void *, size_t, 155 const nvme_identify_ctrl_t *, const nvme_version_t *); 156 extern void nvme_print_feat_async_event(uint32_t, void *, size_t, 157 const nvme_identify_ctrl_t *, const nvme_version_t *); 158 extern void nvme_print_feat_auto_pst(uint32_t, void *, size_t, 159 const nvme_identify_ctrl_t *, const nvme_version_t *); 160 extern void nvme_print_feat_progress(uint32_t, void *, size_t, 161 const nvme_identify_ctrl_t *, const nvme_version_t *); 162 163 extern void nvmeadm_dump_hex(const uint8_t *, size_t); 164 165 /* 166 * ofmt related 167 */ 168 typedef struct { 169 const char *nloa_name; 170 nvme_ctrl_info_t *nloa_ctrl; 171 nvme_ns_info_t *nloa_ns; 172 const char *nloa_disk; 173 } nvmeadm_list_ofmt_arg_t; 174 175 extern const ofmt_field_t nvmeadm_list_ctrl_ofmt[]; 176 extern const ofmt_field_t nvmeadm_list_nsid_ofmt[]; 177 178 typedef struct { 179 const char *nlloa_name; 180 const nvme_log_disc_t *nlloa_disc; 181 } nvmeadm_list_logs_ofmt_arg_t; 182 183 extern const char *nvmeadm_list_logs_fields; 184 extern const char *nvmeadm_list_logs_fields_impl; 185 extern const ofmt_field_t nvmeadm_list_logs_ofmt[]; 186 187 typedef struct { 188 const char *nlfoa_name; 189 const nvme_feat_disc_t *nlfoa_feat; 190 } nvmeadm_list_features_ofmt_arg_t; 191 192 extern const char *nvmeadm_list_features_fields; 193 extern const ofmt_field_t nvmeadm_list_features_ofmt[]; 194 195 196 /* 197 * Warning and error cases. The default nvmeadm ones assume a libnvme related 198 * issue. Most errors are on the nvme_ctrl_t, which are the versions without any 199 * args. The ones that operate on the nvme_t handle have hdl in the name. 200 */ 201 extern void nvmeadm_warn(const nvme_process_arg_t *, const char *, 202 ...) __PRINTFLIKE(2); 203 extern void nvmeadm_fatal(const nvme_process_arg_t *, const char *, 204 ...) __PRINTFLIKE(2) __NORETURN; 205 extern void nvmeadm_hdl_warn(const nvme_process_arg_t *, const char *, 206 ...) __PRINTFLIKE(2); 207 extern void nvmeadm_hdl_fatal(const nvme_process_arg_t *, const char *, 208 ...) __PRINTFLIKE(2) __NORETURN; 209 210 /* 211 * Vendor specific commands. 212 * 213 * All vendor commands must first call nvmeadm_vuc_validate() which will 214 * validate that a given vendor unique command is useable by the device and then 215 * proceed to take any necessary locks that the command suggests. 216 */ 217 extern nvme_vuc_disc_t *nvmeadm_vuc_init(const nvme_process_arg_t *, 218 const char *); 219 extern void nvmeadm_vuc_fini(const nvme_process_arg_t *, nvme_vuc_disc_t *); 220 221 extern int do_wdc_e6dump(const nvme_process_arg_t *); 222 extern void optparse_wdc_e6dump(nvme_process_arg_t *); 223 extern void usage_wdc_e6dump(const char *); 224 225 extern int do_wdc_resize(const nvme_process_arg_t *); 226 extern void optparse_wdc_resize(nvme_process_arg_t *); 227 extern void usage_wdc_resize(const char *); 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif /* _NVMEADM_H */ 234