xref: /illumos-gate/usr/src/common/nvme/nvme_format.c (revision aaceae985c2e78cadef76bf0b7b50ed887ccb3a6)
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  */
15 
16 /*
17  * Common field and validation for NVMe Format NVM operations. This covers what
18  * nvmeadm(8) calls both secure-erase and format.
19  */
20 
21 #include "nvme_common.h"
22 
23 #include <sys/sysmacros.h>
24 
25 const nvme_field_info_t nvme_format_fields[] = {
26 	[NVME_FORMAT_REQ_FIELD_LBAF] = {
27 		.nlfi_vers = &nvme_vers_1v0,
28 		/*
29 		 * In the future we should plumb through enough information that
30 		 * we can check this against the common namespace information.
31 		 */
32 		.nlfi_max_size = NVME_FRMT_MAX_LBAF,
33 		.nlfi_spec = "lbaf",
34 		.nlfi_human = "LBA format",
35 		.nlfi_def_req = true,
36 		.nlfi_def_allow = true
37 	},
38 	[NVME_FORMAT_REQ_FIELD_SES] = {
39 		.nlfi_vers = &nvme_vers_1v0,
40 		.nlfi_max_size = NVME_FRMT_MAX_SES,
41 		.nlfi_spec = "ses",
42 		.nlfi_human = "secure erase settings",
43 		.nlfi_def_req = false,
44 		.nlfi_def_allow = true
45 	},
46 	[NVME_FORMAT_REQ_FIELD_NSID] = {
47 		.nlfi_vers = &nvme_vers_1v0,
48 		.nlfi_valid = nvme_field_valid_nsid,
49 		.nlfi_spec = "nsid",
50 		.nlfi_human = "namespace ID",
51 		.nlfi_def_req = false,
52 		.nlfi_def_allow = true
53 	}
54 };
55 
56 size_t nvme_format_nfields = ARRAY_SIZE(nvme_format_fields);
57 
58 bool
59 nvme_format_cmds_supported(const nvme_valid_ctrl_data_t *data)
60 {
61 	return (data->vcd_id->id_oacs.oa_format != 0);
62 }
63