Debian Codegraph @

src/plugins/nvme/nvme.h

raw
1 #include <glib.h>
2 #include <glib-object.h>
3 #include <blockdev/utils.h>
4
5 #ifndef BD_NVME
6 #define BD_NVME
7
8 GQuark bd_nvme_error_quark (void);
9 #define BD_NVME_ERROR bd_nvme_error_quark ()
10
11 /**
12 * BDNVMEError:
13 * @BD_NVME_ERROR_TECH_UNAVAIL: NVMe support not available.
14 * @BD_NVME_ERROR_FAILED: General error.
15 * @BD_NVME_ERROR_BUSY: The device is temporarily unavailable or in an inconsistent state.
16 * @BD_NVME_ERROR_INVALID_ARGUMENT: Invalid argument.
17 * @BD_NVME_ERROR_WOULD_FORMAT_ALL_NS: The NVMe controller indicates that it would format all namespaces in the NVM subsystem.
18 * @BD_NVME_ERROR_SC_GENERIC: Generic NVMe Command Status Code.
19 * @BD_NVME_ERROR_SC_CMD_SPECIFIC: NVMe Command Specific error.
20 * @BD_NVME_ERROR_SC_MEDIA: Media and Data Integrity Errors: media specific errors that occur in the NVM or data integrity type errors.
21 * @BD_NVME_ERROR_SC_PATH: Path related error.
22 * @BD_NVME_ERROR_SC_VENDOR_SPECIFIC: NVMe Vendor specific error.
23 * @BD_NVME_ERROR_NO_MATCH: No matching resource found (e.g. a Fabrics Controller).
24 * @BD_NVME_ERROR_CONNECT: General connection error.
25 * @BD_NVME_ERROR_CONNECT_ALREADY: Already connected.
26 * @BD_NVME_ERROR_CONNECT_INVALID: Invalid argument specified.
27 * @BD_NVME_ERROR_CONNECT_ADDRINUSE: HostNQN already in use.
28 * @BD_NVME_ERROR_CONNECT_NODEV: Invalid interface.
29 * @BD_NVME_ERROR_CONNECT_OPNOTSUPP: Operation not supported.
30 * @BD_NVME_ERROR_CONNECT_REFUSED: Connection refused.
31 */
32 typedef enum {
33 BD_NVME_ERROR_TECH_UNAVAIL,
34 BD_NVME_ERROR_FAILED,
35 BD_NVME_ERROR_BUSY,
36 BD_NVME_ERROR_INVALID_ARGUMENT,
37 BD_NVME_ERROR_WOULD_FORMAT_ALL_NS,
38 BD_NVME_ERROR_SC_GENERIC,
39 BD_NVME_ERROR_SC_CMD_SPECIFIC,
40 BD_NVME_ERROR_SC_MEDIA,
41 BD_NVME_ERROR_SC_PATH,
42 BD_NVME_ERROR_SC_VENDOR_SPECIFIC,
43 BD_NVME_ERROR_NO_MATCH,
44 BD_NVME_ERROR_CONNECT,
45 BD_NVME_ERROR_CONNECT_ALREADY,
46 BD_NVME_ERROR_CONNECT_INVALID,
47 BD_NVME_ERROR_CONNECT_ADDRINUSE,
48 BD_NVME_ERROR_CONNECT_NODEV,
49 BD_NVME_ERROR_CONNECT_OPNOTSUPP,
50 BD_NVME_ERROR_CONNECT_REFUSED,
51 } BDNVMEError;
52
53 typedef enum {
54 BD_NVME_TECH_NVME = 0,
55 BD_NVME_TECH_FABRICS,
56 } BDNVMETech;
57
58 typedef enum {
59 BD_NVME_TECH_MODE_INFO = 1 << 0,
60 BD_NVME_TECH_MODE_MANAGE = 1 << 1,
61 BD_NVME_TECH_MODE_INITIATOR = 1 << 2,
62 } BDNVMETechMode;
63
64 /**
65 * BDNVMEControllerFeature:
66 * @BD_NVME_CTRL_FEAT_MULTIPORT: if set, then the NVM subsystem may contain more than one NVM subsystem port, otherwise it's single-port only.
67 * @BD_NVME_CTRL_FEAT_MULTICTRL: if set, then the NVM subsystem may contain two or more controllers, otherwise contains only single controller.
68 * @BD_NVME_CTRL_FEAT_SRIOV: if set, then the controller is associated with an SR-IOV Virtual Function, otherwise it's associated with a PCI Function or a Fabrics connection.
69 * @BD_NVME_CTRL_FEAT_ANA_REPORTING: indicates that the NVM subsystem supports Asymmetric Namespace Access (ANA) Reporting.
70 * @BD_NVME_CTRL_FEAT_FORMAT: indicates that the controller supports the Format NVM command.
71 * @BD_NVME_CTRL_FEAT_FORMAT_ALL_NS: if set, then a format (excluding secure erase) of any namespace results in a format of all namespaces
72 * in an NVM subsystem with all namespaces in an NVM subsystem configured with the same attributes.
73 * If not set, then the controller supports format on a per namespace basis.
74 * @BD_NVME_CTRL_FEAT_NS_MGMT: indicates that the controller supports the Namespace Management and Attachment capability.
75 * @BD_NVME_CTRL_FEAT_SELFTEST: indicates that the controller supports the Device Self-test command.
76 * @BD_NVME_CTRL_FEAT_SELFTEST_SINGLE: indicates that the NVM subsystem supports only one device self-test operation in progress at a time.
77 * @BD_NVME_CTRL_FEAT_SANITIZE_CRYPTO: indicates that the controller supports the Crypto Erase sanitize operation.
78 * @BD_NVME_CTRL_FEAT_SANITIZE_BLOCK: indicates that the controller supports the Block Erase sanitize operation.
79 * @BD_NVME_CTRL_FEAT_SANITIZE_OVERWRITE: indicates that the controller supports the Overwrite sanitize operation.
80 * @BD_NVME_CTRL_FEAT_SECURE_ERASE_ALL_NS: if set, then any secure erase performed as part of a format operation
81 * results in a secure erase of all namespaces in the NVM subsystem. If not set,
82 * then any secure erase performed as part of a format results in a secure erase
83 * of the particular namespace specified.
84 * @BD_NVME_CTRL_FEAT_SECURE_ERASE_CRYPTO: indicates that the cryptographic erase is supported.
85 * @BD_NVME_CTRL_FEAT_STORAGE_DEVICE: indicates that the NVM subsystem is part of an NVMe Storage Device.
86 * @BD_NVME_CTRL_FEAT_ENCLOSURE: indicates that the NVM subsystem is part of an NVMe Enclosure.
87 * @BD_NVME_CTRL_FEAT_MGMT_PCIE: indicates that the NVM subsystem contains a Management Endpoint on a PCIe port.
88 * @BD_NVME_CTRL_FEAT_MGMT_SMBUS: indicates that the NVM subsystem contains a Management Endpoint on an SMBus/I2C port.
89 */
90 typedef enum {
91 BD_NVME_CTRL_FEAT_MULTIPORT = 1 << 0,
92 BD_NVME_CTRL_FEAT_MULTICTRL = 1 << 1,
93 BD_NVME_CTRL_FEAT_SRIOV = 1 << 2,
94 BD_NVME_CTRL_FEAT_ANA_REPORTING = 1 << 3,
95 BD_NVME_CTRL_FEAT_FORMAT = 1 << 4,
96 BD_NVME_CTRL_FEAT_FORMAT_ALL_NS = 1 << 5,
97 BD_NVME_CTRL_FEAT_NS_MGMT = 1 << 6,
98 BD_NVME_CTRL_FEAT_SELFTEST = 1 << 7,
99 BD_NVME_CTRL_FEAT_SELFTEST_SINGLE = 1 << 8,
100 BD_NVME_CTRL_FEAT_SANITIZE_CRYPTO = 1 << 9,
101 BD_NVME_CTRL_FEAT_SANITIZE_BLOCK = 1 << 10,
102 BD_NVME_CTRL_FEAT_SANITIZE_OVERWRITE = 1 << 11,
103 BD_NVME_CTRL_FEAT_SECURE_ERASE_ALL_NS = 1 << 12,
104 BD_NVME_CTRL_FEAT_SECURE_ERASE_CRYPTO = 1 << 13,
105 BD_NVME_CTRL_FEAT_STORAGE_DEVICE = 1 << 14,
106 BD_NVME_CTRL_FEAT_ENCLOSURE = 1 << 15,
107 BD_NVME_CTRL_FEAT_MGMT_PCIE = 1 << 16,
108 BD_NVME_CTRL_FEAT_MGMT_SMBUS = 1 << 17,
109 } BDNVMEControllerFeature;
110
111 /**
112 * BDNVMEControllerType:
113 * @BD_NVME_CTRL_TYPE_UNKNOWN: Controller type not reported (as reported by older NVMe-compliant devices).
114 * @BD_NVME_CTRL_TYPE_IO: I/O controller.
115 * @BD_NVME_CTRL_TYPE_DISCOVERY: Discovery controller.
116 * @BD_NVME_CTRL_TYPE_ADMIN: Administrative controller.
117 */
118 typedef enum {
119 BD_NVME_CTRL_TYPE_UNKNOWN = 0,
120 BD_NVME_CTRL_TYPE_IO,
121 BD_NVME_CTRL_TYPE_DISCOVERY,
122 BD_NVME_CTRL_TYPE_ADMIN,
123 } BDNVMEControllerType;
124
125 /**
126 * BDNVMEControllerInfo:
127 * @pci_vendor_id: The PCI Vendor ID.
128 * @pci_subsys_vendor_id: The PCI Subsystem Vendor ID.
129 * @ctrl_id: Controller ID, the NVM subsystem unique controller identifier associated with the controller.
130 * @fguid: FRU GUID, a 128-bit value that is globally unique for a given Field Replaceable Unit.
131 * @model_number: The model number.
132 * @serial_number: The serial number.
133 * @firmware_ver: The currently active firmware revision.
134 * @nvme_ver: The NVM Express base specification that the controller implementation supports or %NULL when not reported by the device.
135 * @features: features and capabilities present for this controller, see #BDNVMEControllerFeature.
136 * @controller_type: The controller type.
137 * @selftest_ext_time: Extended Device Self-test Time, if #BD_NVME_CTRL_FEAT_SELFTEST is supported then this field
138 * indicates the nominal amount of time in one minute units that the controller takes
139 * to complete an extended device self-test operation when in power state 0.
140 * @hmb_pref_size: Host Memory Buffer Preferred Size indicates the preferred size that the host
141 * is requested to allocate for the Host Memory Buffer feature in bytes.
142 * @hmb_min_size: Host Memory Buffer Minimum Size indicates the minimum size that the host
143 * is requested to allocate for the Host Memory Buffer feature in bytes.
144 * @size_total: Total NVM Capacity in the NVM subsystem in bytes.
145 * @size_unalloc: Unallocated NVM Capacity in the NVM subsystem in bytes.
146 * @num_namespaces: Maximum Number of Allowed Namespaces supported by the NVM subsystem.
147 * @subsysnqn: NVM Subsystem NVMe Qualified Name, UTF-8 null terminated string.
148 */
149 typedef struct BDNVMEControllerInfo {
150 guint16 pci_vendor_id;
151 guint16 pci_subsys_vendor_id;
152 guint16 ctrl_id;
153 gchar *fguid;
154 gchar *model_number;
155 gchar *serial_number;
156 gchar *firmware_ver;
157 gchar *nvme_ver;
158 guint64 features;
159 BDNVMEControllerType controller_type;
160 gint selftest_ext_time;
161 guint64 hmb_pref_size;
162 guint64 hmb_min_size;
163 guint64 size_total;
164 guint64 size_unalloc;
165 guint num_namespaces;
166 gchar *subsysnqn;
167 } BDNVMEControllerInfo;
168
169 /**
170 * BDNVMELBAFormatRelativePerformance:
171 * Performance index of the LBA format relative to other LBA formats supported by the controller.
172 * @BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_UNKNOWN: Unknown relative performance index.
173 * @BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_BEST: Best performance.
174 * @BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_BETTER: Better performance.
175 * @BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_GOOD: Good performance.
176 * @BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_DEGRADED: Degraded performance.
177 */
178 typedef enum {
179 BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_UNKNOWN = 0,
180 BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_BEST = 1,
181 BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_BETTER = 2,
182 BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_GOOD = 3,
183 BD_NVME_LBA_FORMAT_RELATIVE_PERFORMANCE_DEGRADED = 4
184 } BDNVMELBAFormatRelativePerformance;
185
186 /**
187 * BDNVMELBAFormat:
188 * Namespace LBA Format Data Structure.
189 * @data_size: LBA data size (i.e. a sector size) in bytes.
190 * @metadata_size: metadata size in bytes or `0` in case of no metadata support.
191 * @relative_performance: Relative Performance index, see #BDNVMELBAFormatRelativePerformance.
192 */
193 typedef struct BDNVMELBAFormat {
194 guint16 data_size;
195 guint16 metadata_size;
196 BDNVMELBAFormatRelativePerformance relative_performance;
197 } BDNVMELBAFormat;
198
199 /**
200 * BDNVMENamespaceFeature:
201 * @BD_NVME_NS_FEAT_THIN: indicates that the namespace supports thin provisioning. Specifically, the Namespace Capacity
202 * reported may be less than the Namespace Size.
203 * @BD_NVME_NS_FEAT_MULTIPATH_SHARED: indicates the capability to attach the namespace to two or more controllers
204 * in the NVM subsystem concurrently.
205 * @BD_NVME_NS_FEAT_FORMAT_PROGRESS: indicates the capability to report the percentage of the namespace
206 * that remains to be formatted.
207 * @BD_NVME_NS_FEAT_ROTATIONAL: indicates a rotational medium.
208 */
209 typedef enum {
210 BD_NVME_NS_FEAT_THIN = 1 << 0,
211 BD_NVME_NS_FEAT_MULTIPATH_SHARED = 1 << 1,
212 BD_NVME_NS_FEAT_FORMAT_PROGRESS = 1 << 2,
213 BD_NVME_NS_FEAT_ROTATIONAL = 1 << 3,
214 } BDNVMENamespaceFeature;
215
216 /**
217 * BDNVMENamespaceInfo:
218 * @nsid: The Namespace Identifier (NSID).
219 * @eui64: IEEE Extended Unique Identifier: a 64-bit IEEE Extended Unique Identifier (EUI-64)
220 * that is globally unique and assigned to the namespace when the namespace is created.
221 * Remains fixed throughout the life of the namespace and is preserved across namespace
222 * and controller operations.
223 * @nguid: Namespace Globally Unique Identifier: a 128-bit value that is globally unique and
224 * assigned to the namespace when the namespace is created. Remains fixed throughout
225 * the life of the namespace and is preserved across namespace and controller operations.
226 * @uuid: Namespace 128-bit Universally Unique Identifier (UUID) as specified in RFC 4122.
227 * @nsize: Namespace Size: total size of the namespace in logical blocks. The number of logical blocks
228 * is based on the formatted LBA size (see @current_lba_format).
229 * @ncap: Namespace Capacity: maximum number of logical blocks that may be allocated in the namespace
230 * at any point in time. The number of logical blocks is based on the formatted LBA size (see @current_lba_format).
231 * @nuse: Namespace Utilization: current number of logical blocks allocated in the namespace.
232 * This field is smaller than or equal to the Namespace Capacity. The number of logical
233 * blocks is based on the formatted LBA size (see @current_lba_format).
234 * @features: features and capabilities present for this namespace, see #BDNVMENamespaceFeature.
235 * @format_progress_remaining: The percentage value remaining of a format operation in progress.
236 * @write_protected: %TRUE if the namespace is currently write protected and all write access to the namespace shall fail.
237 * @lba_formats: (array zero-terminated=1): A list of supported LBA Formats.
238 * @current_lba_format: A LBA Format currently used for the namespace. Contains zeroes in case of
239 * an invalid or no supported LBA Format reported.
240 */
241 typedef struct BDNVMENamespaceInfo {
242 guint32 nsid;
243 gchar *eui64;
244 gchar *uuid;
245 gchar *nguid;
246 guint64 nsize;
247 guint64 ncap;
248 guint64 nuse;
249 guint64 features;
250 guint8 format_progress_remaining;
251 gboolean write_protected;
252 BDNVMELBAFormat **lba_formats;
253 BDNVMELBAFormat current_lba_format;
254 } BDNVMENamespaceInfo;
255
256 /**
257 * BDNVMESmartCriticalWarning:
258 * @BD_NVME_SMART_CRITICAL_WARNING_SPARE: the available spare capacity has fallen below the threshold.
259 * @BD_NVME_SMART_CRITICAL_WARNING_TEMPERATURE: a temperature is either greater than or equal to an over temperature threshold;
260 * or less than or equal to an under temperature threshold.
261 * @BD_NVME_SMART_CRITICAL_WARNING_DEGRADED: the NVM subsystem reliability has been degraded due to significant media
262 * related errors or any internal error that degrades NVM subsystem reliability.
263 * @BD_NVME_SMART_CRITICAL_WARNING_READONLY: all of the media has been placed in read only mode. Unrelated to the write
264 * protection state of a namespace.
265 * @BD_NVME_SMART_CRITICAL_WARNING_VOLATILE_MEM: the volatile memory backup device has failed. Valid only if the controller
266 * has a volatile memory backup solution.
267 * @BD_NVME_SMART_CRITICAL_WARNING_PMR_READONLY: Persistent Memory Region has become read-only or unreliable.
268 */
269 typedef enum {
270 BD_NVME_SMART_CRITICAL_WARNING_SPARE = 1 << 0,
271 BD_NVME_SMART_CRITICAL_WARNING_TEMPERATURE = 1 << 1,
272 BD_NVME_SMART_CRITICAL_WARNING_DEGRADED = 1 << 2,
273 BD_NVME_SMART_CRITICAL_WARNING_READONLY = 1 << 3,
274 BD_NVME_SMART_CRITICAL_WARNING_VOLATILE_MEM = 1 << 4,
275 BD_NVME_SMART_CRITICAL_WARNING_PMR_READONLY = 1 << 5,
276 } BDNVMESmartCriticalWarning;
277
278 /**
279 * BDNVMESmartLog:
280 * @critical_warning: critical warnings for the state of the controller, see #BDNVMESmartCriticalWarning.
281 * @avail_spare: Available Spare: a normalized percentage (0% to 100%) of the remaining spare capacity available.
282 * @spare_thresh: Available Spare Threshold: a normalized percentage (0% to 100%) of the available spare threshold.
283 * @percent_used: Percentage Used: a vendor specific estimate of the percentage drive life used based on the
284 * actual usage and the manufacturer's prediction. A value of 100 indicates that the estimated
285 * endurance has been consumed, but may not indicate an NVM subsystem failure.
286 * The value is allowed to exceed 100.
287 * @total_data_read: An estimated calculation of total data read in bytes based on calculation of data
288 * units read from the host. A value of 0 indicates that the number of Data Units Read
289 * is not reported.
290 * @total_data_written: An estimated calculation of total data written in bytes based on calculation
291 * of data units written by the host. A value of 0 indicates that the number
292 * of Data Units Written is not reported.
293 * @ctrl_busy_time: Amount of time the controller is busy with I/O commands, reported in minutes.
294 * @power_cycles: The number of power cycles.
295 * @power_on_hours: The number of power-on hours, excluding a non-operational power state.
296 * @unsafe_shutdowns: The number of unsafe shutdowns as a result of a Shutdown Notification not received prior to loss of power.
297 * @media_errors: Media and Data Integrity Errors: the number of occurrences where the controller detected
298 * an unrecovered data integrity error (e.g. uncorrectable ECC, CRC checksum failure, or LBA tag mismatch).
299 * @num_err_log_entries: Number of Error Information Log Entries: the number of Error Information log
300 * entries over the life of the controller.
301 * @temperature: Composite Temperature: temperature in Kelvins that represents the current composite
302 * temperature of the controller and associated namespaces or 0 when not applicable.
303 * @temp_sensors: Temperature Sensor 1-8: array of the current temperature reported by temperature sensors
304 * 1-8 in Kelvins or 0 when the particular sensor is not available.
305 * @wctemp: Warning Composite Temperature Threshold (WCTEMP): indicates the minimum Composite Temperature (@temperature)
306 * value that indicates an overheating condition during which controller operation continues.
307 * A value of 0 indicates that no warning temperature threshold value is reported by the controller.
308 * @cctemp: Critical Composite Temperature Threshold (CCTEMP): indicates the minimum Composite Temperature (@temperature)
309 * value that indicates a critical overheating condition (e.g., may prevent continued normal operation,
310 * possibility of data loss, automatic device shutdown, extreme performance throttling, or permanent damage).
311 * A value of 0 indicates that no critical temperature threshold value is reported by the controller.
312 * @warning_temp_time: Warning Composite Temperature Time: the amount of time in minutes that the Composite Temperature (@temperature)
313 * is greater than or equal to the Warning Composite Temperature Threshold (@wctemp) and less than the
314 * Critical Composite Temperature Threshold (@cctemp).
315 * @critical_temp_time: Critical Composite Temperature Time: the amount of time in minutes that the Composite Temperature (@temperature)
316 * is greater than or equal to the Critical Composite Temperature Threshold (@cctemp).
317 */
318 typedef struct BDNVMESmartLog {
319 guint critical_warning;
320 guint8 avail_spare;
321 guint8 spare_thresh;
322 guint8 percent_used;
323 guint64 total_data_read;
324 guint64 total_data_written;
325 guint64 ctrl_busy_time;
326 guint64 power_cycles;
327 guint64 power_on_hours;
328 guint64 unsafe_shutdowns;
329 guint64 media_errors;
330 guint64 num_err_log_entries;
331 guint16 temperature;
332 guint16 temp_sensors[8];
333 guint16 wctemp;
334 guint16 cctemp;
335 guint warning_temp_time;
336 guint critical_temp_time;
337 } BDNVMESmartLog;
338
339 /**
340 * BDNVMETransportType:
341 * Transport Type.
342 * @BD_NVME_TRANSPORT_TYPE_UNSPECIFIED: Not indicated
343 * @BD_NVME_TRANSPORT_TYPE_RDMA: RDMA Transport
344 * @BD_NVME_TRANSPORT_TYPE_FC: Fibre Channel Transport
345 * @BD_NVME_TRANSPORT_TYPE_TCP: TCP Transport
346 * @BD_NVME_TRANSPORT_TYPE_LOOP: Intra-host Transport (loopback)
347 */
348 typedef enum {
349 BD_NVME_TRANSPORT_TYPE_UNSPECIFIED = 0,
350 BD_NVME_TRANSPORT_TYPE_RDMA = 1,
351 BD_NVME_TRANSPORT_TYPE_FC = 2,
352 BD_NVME_TRANSPORT_TYPE_TCP = 3,
353 BD_NVME_TRANSPORT_TYPE_LOOP = 254
354 } BDNVMETransportType;
355
356 /**
357 * BDNVMEErrorLogEntry:
358 * @error_count: internal error counter, a unique identifier for the error.
359 * @command_id: the Command Identifier of the command that the error is associated with or `0xffff` if the error is not specific to a particular command.
360 * @command_specific: Command Specific Information specific to @command_id.
361 * @command_status: the Status code for the command that completed.
362 * @command_error: translated command error in the BD_NVME_ERROR domain or %NULL in case @command_status indicates success.
363 * @lba: the first LBA that experienced the error condition.
364 * @nsid: the NSID of the namespace that the error is associated with.
365 * @transport_type: type of the transport associated with the error.
366 */
367 typedef struct BDNVMEErrorLogEntry {
368 guint64 error_count;
369 guint16 command_id;
370 guint64 command_specific;
371 guint16 command_status;
372 GError *command_error;
373 guint64 lba;
374 guint32 nsid;
375 BDNVMETransportType transport_type;
376 } BDNVMEErrorLogEntry;
377
378 /**
379 * BDNVMESelfTestAction:
380 * Action taken by the Device Self-test command.
381 * @BD_NVME_SELF_TEST_ACTION_NOT_RUNNING: No device self-test operation in progress. Not a valid argument for bd_nvme_device_self_test().
382 * @BD_NVME_SELF_TEST_ACTION_SHORT: Start a short device self-test operation.
383 * @BD_NVME_SELF_TEST_ACTION_EXTENDED: Start an extended device self-test operation.
384 * @BD_NVME_SELF_TEST_ACTION_VENDOR_SPECIFIC: Start a vendor specific device self-test operation.
385 * @BD_NVME_SELF_TEST_ACTION_ABORT: Abort the device self-test operation. Only valid for bd_nvme_device_self_test().
386 */
387 typedef enum {
388 BD_NVME_SELF_TEST_ACTION_NOT_RUNNING = 0,
389 BD_NVME_SELF_TEST_ACTION_SHORT = 1,
390 BD_NVME_SELF_TEST_ACTION_EXTENDED = 2,
391 BD_NVME_SELF_TEST_ACTION_VENDOR_SPECIFIC = 3,
392 BD_NVME_SELF_TEST_ACTION_ABORT = 4,
393 } BDNVMESelfTestAction;
394
395 /**
396 * BDNVMESelfTestResult:
397 * @BD_NVME_SELF_TEST_RESULT_NO_ERROR: Operation completed without error.
398 * @BD_NVME_SELF_TEST_RESULT_ABORTED: Operation was aborted by a Device Self-test command.
399 * @BD_NVME_SELF_TEST_RESULT_CTRL_RESET: Operation was aborted by a Controller Level Reset.
400 * @BD_NVME_SELF_TEST_RESULT_NS_REMOVED: Operation was aborted due to a removal of a namespace from the namespace inventory.
401 * @BD_NVME_SELF_TEST_RESULT_ABORTED_FORMAT: Operation was aborted due to the processing of a Format NVM command.
402 * @BD_NVME_SELF_TEST_RESULT_FATAL_ERROR: A fatal error or unknown test error occurred while the controller was executing the device self-test operation and the operation did not complete.
403 * @BD_NVME_SELF_TEST_RESULT_UNKNOWN_SEG_FAIL: Operation completed with a segment that failed and the segment that failed is not known.
404 * @BD_NVME_SELF_TEST_RESULT_KNOWN_SEG_FAIL: Operation completed with one or more failed segments and the first segment that failed is indicated in the Segment Number field.
405 * @BD_NVME_SELF_TEST_RESULT_ABORTED_UNKNOWN: Operation was aborted for unknown reason.
406 * @BD_NVME_SELF_TEST_RESULT_ABORTED_SANITIZE: Operation was aborted due to a sanitize operation.
407 */
408 typedef enum {
409 BD_NVME_SELF_TEST_RESULT_NO_ERROR = 0,
410 BD_NVME_SELF_TEST_RESULT_ABORTED = 1,
411 BD_NVME_SELF_TEST_RESULT_CTRL_RESET = 2,
412 BD_NVME_SELF_TEST_RESULT_NS_REMOVED = 3,
413 BD_NVME_SELF_TEST_RESULT_ABORTED_FORMAT = 4,
414 BD_NVME_SELF_TEST_RESULT_FATAL_ERROR = 5,
415 BD_NVME_SELF_TEST_RESULT_UNKNOWN_SEG_FAIL = 6,
416 BD_NVME_SELF_TEST_RESULT_KNOWN_SEG_FAIL = 7,
417 BD_NVME_SELF_TEST_RESULT_ABORTED_UNKNOWN = 8,
418 BD_NVME_SELF_TEST_RESULT_ABORTED_SANITIZE = 9,
419 } BDNVMESelfTestResult;
420
421 /**
422 * BDNVMESelfTestLogEntry:
423 * @result: Result of the device self-test operation.
424 * @action: The Self-test Code value (action) that was specified in the Device Self-test command that started this device self-test operation.
425 * @segment: Segment number where the first self-test failure occurred. Valid only when @result is set to #BD_NVME_SELF_TEST_RESULT_KNOWN_SEG_FAIL.
426 * @power_on_hours: Number of power-on hours at the time the device self-test operation was completed or aborted. Does not include time that the controller was powered and in a low power state condition.
427 * @nsid: Namespace ID that the Failing LBA occurred on.
428 * @failing_lba: LBA of the logical block that caused the test to fail. If the device encountered more than one failed logical block during the test, then this field only indicates one of those failed logical blocks.
429 * @status_code_error: Translated NVMe Command Status Code representing additional information related to errors or conditions.
430 */
431 typedef struct BDNVMESelfTestLogEntry {
432 BDNVMESelfTestResult result;
433 BDNVMESelfTestAction action;
434 guint8 segment;
435 guint64 power_on_hours;
436 guint32 nsid;
437 guint64 failing_lba;
438 GError *status_code_error;
439 } BDNVMESelfTestLogEntry;
440
441 /**
442 * BDNVMESelfTestLog:
443 * @current_operation: Current running device self-test operation. There's no corresponding record in @entries for a device self-test operation that is in progress.
444 * @current_operation_completion: Percentage of the currently running device self-test operation. Only valid when @current_operation is other than #BD_NVME_SELF_TEST_ACTION_NOT_RUNNING.
445 * @entries: (array zero-terminated=1): Self-test log entries for the last 20 operations, sorted from newest (first element) to oldest.
446 */
447 typedef struct BDNVMESelfTestLog {
448 BDNVMESelfTestAction current_operation;
449 guint8 current_operation_completion;
450 BDNVMESelfTestLogEntry **entries;
451 } BDNVMESelfTestLog;
452
453 /**
454 * BDNVMEFormatSecureErase:
455 * Optional Format NVM secure erase action.
456 * @BD_NVME_FORMAT_SECURE_ERASE_NONE: No secure erase operation requested.
457 * @BD_NVME_FORMAT_SECURE_ERASE_USER_DATA: User Data Erase: All user data shall be erased, contents of the user data after the erase is indeterminate
458 * (e.g., the user data may be zero filled, one filled, etc.). If a User Data Erase is requested and all affected
459 * user data is encrypted, then the controller is allowed to use a cryptographic erase to perform the requested User Data Erase.
460 * @BD_NVME_FORMAT_SECURE_ERASE_CRYPTO: Cryptographic Erase: All user data shall be erased cryptographically. This is accomplished by deleting the encryption key.
461 */
462 typedef enum {
463 BD_NVME_FORMAT_SECURE_ERASE_NONE = 0,
464 BD_NVME_FORMAT_SECURE_ERASE_USER_DATA = 1,
465 BD_NVME_FORMAT_SECURE_ERASE_CRYPTO = 2,
466 } BDNVMEFormatSecureErase;
467
468 /**
469 * BDNVMESanitizeStatus:
470 * @BD_NVME_SANITIZE_STATUS_NEVER_SANITIZED: The NVM subsystem has never been sanitized.
471 * @BD_NVME_SANITIZE_STATUS_IN_PROGRESS: A sanitize operation is currently in progress.
472 * @BD_NVME_SANITIZE_STATUS_IN_PROGESS: Deprecated alias for %BD_NVME_SANITIZE_STATUS_IN_PROGRESS
473 * @BD_NVME_SANITIZE_STATUS_SUCCESS: The most recent sanitize operation completed successfully including any additional media modification.
474 * @BD_NVME_SANITIZE_STATUS_SUCCESS_NO_DEALLOC: The most recent sanitize operation for which No-Deallocate After Sanitize was requested has completed successfully with deallocation of all user data.
475 * @BD_NVME_SANITIZE_STATUS_FAILED: The most recent sanitize operation failed.
476 */
477 typedef enum {
478 BD_NVME_SANITIZE_STATUS_NEVER_SANITIZED = 0,
479 BD_NVME_SANITIZE_STATUS_IN_PROGRESS = 1,
480 BD_NVME_SANITIZE_STATUS_IN_PROGESS = BD_NVME_SANITIZE_STATUS_IN_PROGRESS,
481 BD_NVME_SANITIZE_STATUS_SUCCESS = 2,
482 BD_NVME_SANITIZE_STATUS_SUCCESS_NO_DEALLOC = 3,
483 BD_NVME_SANITIZE_STATUS_FAILED = 4,
484 } BDNVMESanitizeStatus;
485
486 /**
487 * BDNVMESanitizeLog:
488 * @sanitize_progress: The percentage complete of the sanitize operation.
489 * @sanitize_status: The status of the most recent sanitize operation.
490 * @global_data_erased: Indicates that no user data has been written either since the drive was manufactured and
491 * has never been sanitized or since the most recent successful sanitize operation.
492 * @overwrite_passes: Number of completed passes if the most recent sanitize operation was an Overwrite.
493 * @time_for_overwrite: Estimated time in seconds needed to complete an Overwrite sanitize operation with 16 passes in the background.
494 * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
495 * to be completed in the background when the Sanitize command is completed.
496 * @time_for_block_erase: Estimated time in seconds needed to complete a Block Erase sanitize operation in the background.
497 * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
498 * to be completed in the background when the Sanitize command is completed.
499 * @time_for_crypto_erase: Estimated time in seconds needed to complete a Crypto Erase sanitize operation in the background.
500 * A value of -1 means that no time estimate is reported. A value of 0 means that the operation is expected
501 * to be completed in the background when the Sanitize command is completed.
502 * @time_for_overwrite_nd: Estimated time in seconds needed to complete an Overwrite sanitize operation and the associated
503 * additional media modification in the background when the No-Deallocate After Sanitize or
504 * the No-Deallocate Modifies Media After Sanitize features have been requested.
505 * @time_for_block_erase_nd: Estimated time in seconds needed to complete a Block Erase sanitize operation and the associated
506 * additional media modification in the background when the No-Deallocate After Sanitize or
507 * the No-Deallocate Modifies Media After Sanitize features have been requested.
508 * @time_for_crypto_erase_nd: Estimated time in seconds needed to complete a Crypto Erase sanitize operation and the associated
509 * additional media modification in the background when the No-Deallocate After Sanitize or
510 * the No-Deallocate Modifies Media After Sanitize features have been requested.
511 */
512 typedef struct BDNVMESanitizeLog {
513 gdouble sanitize_progress;
514 BDNVMESanitizeStatus sanitize_status;
515 gboolean global_data_erased;
516 guint8 overwrite_passes;
517 gint64 time_for_overwrite;
518 gint64 time_for_block_erase;
519 gint64 time_for_crypto_erase;
520 gint64 time_for_overwrite_nd;
521 gint64 time_for_block_erase_nd;
522 gint64 time_for_crypto_erase_nd;
523 } BDNVMESanitizeLog;
524
525 /**
526 * BDNVMESanitizeAction:
527 * @BD_NVME_SANITIZE_ACTION_EXIT_FAILURE: Exit Failure Mode.
528 * @BD_NVME_SANITIZE_ACTION_BLOCK_ERASE: Start a Block Erase sanitize operation - a low-level block erase method that is specific to the media.
529 * @BD_NVME_SANITIZE_ACTION_OVERWRITE: Start an Overwrite sanitize operation - writing a fixed data pattern or related patterns in multiple passes.
530 * @BD_NVME_SANITIZE_ACTION_CRYPTO_ERASE: Start a Crypto Erase sanitize operation - changing the media encryption keys for all locations on the media.
531 */
532 typedef enum {
533 BD_NVME_SANITIZE_ACTION_EXIT_FAILURE = 0,
534 BD_NVME_SANITIZE_ACTION_BLOCK_ERASE = 1,
535 BD_NVME_SANITIZE_ACTION_OVERWRITE = 2,
536 BD_NVME_SANITIZE_ACTION_CRYPTO_ERASE = 3,
537 } BDNVMESanitizeAction;
538
539
540 void bd_nvme_controller_info_free (BDNVMEControllerInfo *info);
541 BDNVMEControllerInfo * bd_nvme_controller_info_copy (BDNVMEControllerInfo *info);
542
543 void bd_nvme_lba_format_free (BDNVMELBAFormat *fmt);
544 BDNVMELBAFormat * bd_nvme_lba_format_copy (BDNVMELBAFormat *fmt);
545
546 void bd_nvme_namespace_info_free (BDNVMENamespaceInfo *info);
547 BDNVMENamespaceInfo * bd_nvme_namespace_info_copy (BDNVMENamespaceInfo *info);
548
549 void bd_nvme_smart_log_free (BDNVMESmartLog *log);
550 BDNVMESmartLog * bd_nvme_smart_log_copy (BDNVMESmartLog *log);
551
552 void bd_nvme_error_log_entry_free (BDNVMEErrorLogEntry *entry);
553 BDNVMEErrorLogEntry * bd_nvme_error_log_entry_copy (BDNVMEErrorLogEntry *entry);
554
555 void bd_nvme_self_test_log_entry_free (BDNVMESelfTestLogEntry *entry);
556 BDNVMESelfTestLogEntry * bd_nvme_self_test_log_entry_copy (BDNVMESelfTestLogEntry *entry);
557 const gchar * bd_nvme_self_test_result_to_string (BDNVMESelfTestResult result, GError **error);
558
559 void bd_nvme_self_test_log_free (BDNVMESelfTestLog *log);
560 BDNVMESelfTestLog * bd_nvme_self_test_log_copy (BDNVMESelfTestLog *log);
561
562 void bd_nvme_sanitize_log_free (BDNVMESanitizeLog *log);
563 BDNVMESanitizeLog * bd_nvme_sanitize_log_copy (BDNVMESanitizeLog *log);
564
565 /*
566 * If using the plugin as a standalone library, the following functions should
567 * be called to:
568 *
569 * init() - initialize the plugin, returning TRUE on success
570 * close() - clean after the plugin at the end or if no longer used
571 *
572 */
573 gboolean bd_nvme_init (void);
574 void bd_nvme_close (void);
575
576 gboolean bd_nvme_is_tech_avail (BDNVMETech tech, guint64 mode, GError **error);
577
578
579 BDNVMEControllerInfo * bd_nvme_get_controller_info (const gchar *device, GError **error);
580 BDNVMENamespaceInfo * bd_nvme_get_namespace_info (const gchar *device, GError **error);
581 BDNVMESmartLog * bd_nvme_get_smart_log (const gchar *device, GError **error);
582 BDNVMEErrorLogEntry ** bd_nvme_get_error_log_entries (const gchar *device, GError **error);
583 BDNVMESelfTestLog * bd_nvme_get_self_test_log (const gchar *device, GError **error);
584 BDNVMESanitizeLog * bd_nvme_get_sanitize_log (const gchar *device, GError **error);
585
586 gboolean bd_nvme_device_self_test (const gchar *device,
587 BDNVMESelfTestAction action,
588 GError **error);
589
590 gboolean bd_nvme_format (const gchar *device,
591 guint16 lba_data_size,
592 guint16 metadata_size,
593 BDNVMEFormatSecureErase secure_erase,
594 GError **error);
595 gboolean bd_nvme_sanitize (const gchar *device,
596 BDNVMESanitizeAction action,
597 gboolean no_dealloc,
598 gint overwrite_pass_count,
599 guint32 overwrite_pattern,
600 gboolean overwrite_invert_pattern,
601 GError **error);
602
603 gchar * bd_nvme_get_host_nqn (GError **error);
604 gchar * bd_nvme_generate_host_nqn (GError **error);
605 gchar * bd_nvme_get_host_id (GError **error);
606 gboolean bd_nvme_set_host_nqn (const gchar *host_nqn,
607 GError **error);
608 gboolean bd_nvme_set_host_id (const gchar *host_id,
609 GError **error);
610
611 gboolean bd_nvme_connect (const gchar *subsysnqn,
612 const gchar *transport,
613 const gchar *transport_addr,
614 const gchar *transport_svcid,
615 const gchar *host_traddr,
616 const gchar *host_iface,
617 const gchar *host_nqn,
618 const gchar *host_id,
619 const BDExtraArg **extra,
620 GError **error);
621 gboolean bd_nvme_disconnect (const gchar *subsysnqn,
622 GError **error);
623 gboolean bd_nvme_disconnect_by_path (const gchar *path,
624 GError **error);
625
626 gchar ** bd_nvme_find_ctrls_for_ns (const gchar *ns_sysfs_path,
627 const gchar *subsysnqn,
628 const gchar *host_nqn,
629 const gchar *host_id,
630 GError **error);
631
632 gchar ** bd_nvme_find_namespaces_for_ctrl (const gchar *ctrl_sysfs_path,
633 const gchar *subsysnqn,
634 const gchar *host_nqn,
635 const gchar *host_id,
636 GError **error);
637
638
639 #endif /* BD_NVME */