xref: /illumos-gate/usr/src/cmd/nvmeadm/nvmeadm.h (revision 3b8e64428fecd54234c133286f9c0009ad8940b0)
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 2023 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 <sys/nvme.h>
23 #include <nvme_reg.h>
24 #include <ofmt.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 extern int verbose;
31 extern int debug;
32 
33 /* Common structures */
34 typedef struct nvme_process_arg nvme_process_arg_t;
35 typedef struct nvme_feature nvme_feature_t;
36 typedef struct nvmeadm_cmd nvmeadm_cmd_t;
37 
38 struct nvme_process_arg {
39 	int npa_argc;
40 	char **npa_argv;
41 	char *npa_name;
42 	char *npa_nsid;
43 	char *npa_eui64;
44 	char *npa_nguid;
45 	int npa_found;
46 	boolean_t npa_excl;
47 	boolean_t npa_isns;
48 	boolean_t npa_interactive;
49 	uint32_t npa_cmdflags;
50 	const nvmeadm_cmd_t *npa_cmd;
51 	di_node_t npa_node;
52 	di_minor_t npa_minor;
53 	char *npa_dsk;
54 	nvme_ns_state_t npa_ns_state;
55 	nvme_identify_ctrl_t *npa_idctl;
56 	nvme_identify_nsid_t *npa_idns;
57 	nvme_identify_nsid_list_t *npa_idnslist;
58 	nvme_version_t *npa_version;
59 	ofmt_handle_t npa_ofmt;
60 };
61 
62 /* Version checking */
63 extern boolean_t nvme_version_check(nvme_version_t *, uint_t, uint_t);
64 
65 /* printing functions */
66 extern int nvme_strlen(const char *, int);
67 extern void nvme_print(int, const char *, int, const char *, ...);
68 extern int nvme_snprint_uint128(char *, size_t, nvme_uint128_t, int, int);
69 extern void nvme_print_ctrl_summary(nvme_identify_ctrl_t *, nvme_version_t *);
70 extern void nvme_print_nsid_summary(nvme_identify_nsid_t *);
71 extern void nvme_print_identify_ctrl(nvme_identify_ctrl_t *,
72     nvme_capabilities_t *, nvme_version_t *);
73 extern void nvme_print_identify_nsid(nvme_identify_nsid_t *, nvme_version_t *);
74 extern void nvme_print_identify_nsid_list(const char *,
75     nvme_identify_nsid_list_t *);
76 extern void nvme_print_identify_nsid_desc(void *);
77 extern void nvme_print_identify_ctrl_list(const char *,
78     nvme_identify_ctrl_list_t *);
79 extern void nvme_print_error_log(int, nvme_error_log_entry_t *,
80     nvme_version_t *);
81 extern void nvme_print_health_log(nvme_health_log_t *, nvme_identify_ctrl_t *,
82     nvme_version_t *);
83 extern void nvme_print_fwslot_log(nvme_fwslot_log_t *, nvme_identify_ctrl_t *);
84 
85 extern void nvme_print_feat_arbitration(uint64_t, void *, size_t,
86     nvme_identify_ctrl_t *, nvme_version_t *);
87 extern void nvme_print_feat_power_mgmt(uint64_t, void *, size_t,
88     nvme_identify_ctrl_t *, nvme_version_t *);
89 extern void nvme_print_feat_lba_range(uint64_t, void *, size_t,
90     nvme_identify_ctrl_t *, nvme_version_t *);
91 extern void nvme_print_feat_temperature(uint64_t, void *, size_t,
92     nvme_identify_ctrl_t *, nvme_version_t *);
93 extern void nvme_print_feat_error(uint64_t, void *, size_t,
94     nvme_identify_ctrl_t *, nvme_version_t *);
95 extern void nvme_print_feat_write_cache(uint64_t, void *, size_t,
96     nvme_identify_ctrl_t *, nvme_version_t *);
97 extern void nvme_print_feat_nqueues(uint64_t, void *, size_t,
98     nvme_identify_ctrl_t *, nvme_version_t *);
99 extern void nvme_print_feat_intr_coal(uint64_t, void *, size_t,
100     nvme_identify_ctrl_t *, nvme_version_t *);
101 extern void nvme_print_feat_intr_vect(uint64_t, void *, size_t,
102     nvme_identify_ctrl_t *, nvme_version_t *);
103 extern void nvme_print_feat_write_atom(uint64_t, void *, size_t,
104     nvme_identify_ctrl_t *, nvme_version_t *);
105 extern void nvme_print_feat_async_event(uint64_t, void *, size_t,
106     nvme_identify_ctrl_t *, nvme_version_t *);
107 extern void nvme_print_feat_auto_pst(uint64_t, void *, size_t,
108     nvme_identify_ctrl_t *, nvme_version_t *);
109 extern void nvme_print_feat_progress(uint64_t, void *, size_t,
110     nvme_identify_ctrl_t *, nvme_version_t *);
111 extern const char *nvme_fw_error(int, int);
112 
113 /* device node functions */
114 extern int nvme_open(di_minor_t, boolean_t);
115 extern void nvme_close(int);
116 extern nvme_version_t *nvme_version(int);
117 extern nvme_capabilities_t *nvme_capabilities(int);
118 extern void *nvme_identify(int, uint8_t);
119 extern void *nvme_get_logpage(int, uint8_t, size_t *);
120 extern boolean_t nvme_get_feature(int, uint8_t, uint32_t, uint64_t *, size_t *,
121     void **);
122 extern int nvme_intr_cnt(int);
123 extern boolean_t nvme_format_nvm(int, uint8_t, uint8_t);
124 extern boolean_t nvme_detach(int);
125 extern boolean_t nvme_attach(int);
126 extern boolean_t nvme_firmware_load(int, void *, size_t, offset_t, uint16_t *);
127 extern boolean_t nvme_firmware_commit(int, int, int, uint16_t *);
128 extern nvme_ns_state_t nvme_namespace_state(int);
129 
130 /*
131  * ofmt related
132  */
133 extern const ofmt_field_t nvme_list_ctrl_ofmt[];
134 extern const ofmt_field_t nvme_list_nsid_ofmt[];
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif /* _NVMEADM_H */
141