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 * NVMe format field testing. Note, the valid lba formats are not constrained by 18 * the controller at this time. That is a future direction. 19 */ 20 21 #include <stdlib.h> 22 #include <sys/sysmacros.h> 23 #include <err.h> 24 25 #include "nvme_unit.h" 26 27 static const nvme_unit_field_test_t format_field_tests[] = { { 28 .nu_desc = "invalid LBA format (1)", 29 .nu_fields = nvme_format_fields, 30 .nu_index = NVME_FORMAT_REQ_FIELD_LBAF, 31 .nu_data = &nvme_ctrl_base_1v0, 32 .nu_value = 0x10, 33 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 34 }, { 35 .nu_desc = "invalid LBA format (2)", 36 .nu_fields = nvme_format_fields, 37 .nu_index = NVME_FORMAT_REQ_FIELD_LBAF, 38 .nu_data = &nvme_ctrl_base_1v0, 39 .nu_value = 0x7777, 40 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 41 }, { 42 .nu_desc = "valid LBA format (1)", 43 .nu_fields = nvme_format_fields, 44 .nu_index = NVME_FORMAT_REQ_FIELD_LBAF, 45 .nu_data = &nvme_ctrl_base_1v0, 46 .nu_value = 0x0, 47 .nu_ret = NVME_FIELD_ERR_OK 48 }, { 49 .nu_desc = "valid LBA format (2)", 50 .nu_fields = nvme_format_fields, 51 .nu_index = NVME_FORMAT_REQ_FIELD_LBAF, 52 .nu_data = &nvme_ctrl_base_1v0, 53 .nu_value = 0xf, 54 .nu_ret = NVME_FIELD_ERR_OK 55 }, { 56 .nu_desc = "valid LBA format (3)", 57 .nu_fields = nvme_format_fields, 58 .nu_index = NVME_FORMAT_REQ_FIELD_LBAF, 59 .nu_data = &nvme_ctrl_base_1v0, 60 .nu_value = 0x7, 61 .nu_ret = NVME_FIELD_ERR_OK 62 }, { 63 .nu_desc = "invalid SES (1)", 64 .nu_fields = nvme_format_fields, 65 .nu_index = NVME_FORMAT_REQ_FIELD_SES, 66 .nu_data = &nvme_ctrl_base_1v0, 67 .nu_value = 0x3, 68 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 69 }, { 70 .nu_desc = "invalid SES (2)", 71 .nu_fields = nvme_format_fields, 72 .nu_index = NVME_FORMAT_REQ_FIELD_SES, 73 .nu_data = &nvme_ctrl_base_1v0, 74 .nu_value = 0x33, 75 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 76 }, { 77 .nu_desc = "valid SES (1)", 78 .nu_fields = nvme_format_fields, 79 .nu_index = NVME_FORMAT_REQ_FIELD_SES, 80 .nu_data = &nvme_ctrl_base_1v0, 81 .nu_value = 0x0, 82 .nu_ret = NVME_FIELD_ERR_OK 83 }, { 84 .nu_desc = "valid SES (2)", 85 .nu_fields = nvme_format_fields, 86 .nu_index = NVME_FORMAT_REQ_FIELD_SES, 87 .nu_data = &nvme_ctrl_base_1v0, 88 .nu_value = 0x2, 89 .nu_ret = NVME_FIELD_ERR_OK 90 }, { 91 .nu_desc = "invalid NSID (1)", 92 .nu_fields = nvme_format_fields, 93 .nu_index = NVME_FORMAT_REQ_FIELD_NSID, 94 .nu_data = &nvme_ctrl_base_1v0, 95 .nu_value = 0x0, 96 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 97 }, { 98 .nu_desc = "invalid NSID (2)", 99 .nu_fields = nvme_format_fields, 100 .nu_index = NVME_FORMAT_REQ_FIELD_NSID, 101 .nu_data = &nvme_ctrl_base_1v0, 102 .nu_value = 0x23, 103 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 104 }, { 105 .nu_desc = "valid NSID (1)", 106 .nu_fields = nvme_format_fields, 107 .nu_index = NVME_FORMAT_REQ_FIELD_NSID, 108 .nu_data = &nvme_ctrl_base_1v0, 109 .nu_value = 0x1, 110 .nu_ret = NVME_FIELD_ERR_OK 111 }, { 112 .nu_desc = "valid NSID (2)", 113 .nu_fields = nvme_format_fields, 114 .nu_index = NVME_FORMAT_REQ_FIELD_NSID, 115 .nu_data = &nvme_ctrl_base_1v0, 116 .nu_value = NVME_NSID_BCAST, 117 .nu_ret = NVME_FIELD_ERR_OK 118 } }; 119 120 int 121 main(void) 122 { 123 int ret = EXIT_SUCCESS; 124 125 if (!nvme_unit_field_test(format_field_tests, 126 ARRAY_SIZE(format_field_tests))) { 127 ret = EXIT_FAILURE; 128 } 129 130 if (nvme_format_cmds_supported(&nvme_ctrl_nocmds_1v0)) { 131 warnx("TEST FAILED: erroneously found format command " 132 "support on a controller without it"); 133 ret = EXIT_FAILURE; 134 } else { 135 (void) printf("TEST PASSED: successfully determined controller " 136 "doesn't support format commands\n"); 137 } 138 139 if (!nvme_format_cmds_supported(&nvme_ctrl_base_1v0)) { 140 warnx("TEST FAILED: erroneously found format commands aren't " 141 "supported on a controller that should advertise it"); 142 ret = EXIT_FAILURE; 143 } else { 144 (void) printf("TEST PASSED: successfully determined controller " 145 "supports format commands\n"); 146 } 147 148 if (ret == EXIT_SUCCESS) { 149 (void) printf("All tests passed successfully!\n"); 150 } 151 152 return (ret); 153 } 154