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 * Validate fields for the various VUC fields. Note, these do not change with 18 * the controller itself. These have been the same since NVMe 1.0. 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 vuc_field_tests[] = { { 28 .nu_desc = "invalid opcode (1)", 29 .nu_fields = nvme_vuc_fields, 30 .nu_index = NVME_VUC_REQ_FIELD_OPC, 31 .nu_data = &nvme_ctrl_base_1v0, 32 .nu_value = 0xbf, 33 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 34 }, { 35 .nu_desc = "invalid opcode (2)", 36 .nu_fields = nvme_vuc_fields, 37 .nu_index = NVME_VUC_REQ_FIELD_OPC, 38 .nu_data = &nvme_ctrl_base_1v0, 39 .nu_value = 0x100, 40 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 41 }, { 42 .nu_desc = "invalid opcode (3)", 43 .nu_fields = nvme_vuc_fields, 44 .nu_index = NVME_VUC_REQ_FIELD_OPC, 45 .nu_data = &nvme_ctrl_base_1v0, 46 .nu_value = 0x3, 47 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 48 }, { 49 .nu_desc = "valid opcode (1)", 50 .nu_fields = nvme_vuc_fields, 51 .nu_index = NVME_VUC_REQ_FIELD_OPC, 52 .nu_data = &nvme_ctrl_base_1v0, 53 .nu_value = 0xc0, 54 .nu_ret = NVME_FIELD_ERR_OK 55 }, { 56 .nu_desc = "valid opcode (2)", 57 .nu_fields = nvme_vuc_fields, 58 .nu_index = NVME_VUC_REQ_FIELD_OPC, 59 .nu_data = &nvme_ctrl_base_1v0, 60 .nu_value = 0xff, 61 .nu_ret = NVME_FIELD_ERR_OK 62 }, { 63 .nu_desc = "valid opcode (3)", 64 .nu_fields = nvme_vuc_fields, 65 .nu_index = NVME_VUC_REQ_FIELD_OPC, 66 .nu_data = &nvme_ctrl_base_1v0, 67 .nu_value = 0xde, 68 .nu_ret = NVME_FIELD_ERR_OK 69 }, { 70 .nu_desc = "invalid namespace (1)", 71 .nu_fields = nvme_vuc_fields, 72 .nu_index = NVME_VUC_REQ_FIELD_NSID, 73 .nu_data = &nvme_ctrl_base_1v0, 74 .nu_value = 0x33, 75 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 76 }, { 77 .nu_desc = "valid namespace (1)", 78 .nu_fields = nvme_vuc_fields, 79 .nu_index = NVME_VUC_REQ_FIELD_NSID, 80 .nu_data = &nvme_ctrl_base_1v0, 81 .nu_value = 0x0, 82 .nu_ret = NVME_FIELD_ERR_OK 83 }, { 84 .nu_desc = "valid namespace (2)", 85 .nu_fields = nvme_vuc_fields, 86 .nu_index = NVME_VUC_REQ_FIELD_NSID, 87 .nu_data = &nvme_ctrl_base_1v0, 88 .nu_value = NVME_NSID_BCAST, 89 .nu_ret = NVME_FIELD_ERR_OK 90 }, { 91 .nu_desc = "valid namespace (3)", 92 .nu_fields = nvme_vuc_fields, 93 .nu_index = NVME_VUC_REQ_FIELD_NSID, 94 .nu_data = &nvme_ctrl_base_1v0, 95 .nu_value = 0x1, 96 .nu_ret = NVME_FIELD_ERR_OK 97 }, { 98 .nu_desc = "invalid cdw12", 99 .nu_fields = nvme_vuc_fields, 100 .nu_index = NVME_VUC_REQ_FIELD_CDW12, 101 .nu_data = &nvme_ctrl_base_1v0, 102 .nu_value = 0x100000000, 103 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 104 }, { 105 .nu_desc = "valid cdw12", 106 .nu_fields = nvme_vuc_fields, 107 .nu_index = NVME_VUC_REQ_FIELD_CDW12, 108 .nu_data = &nvme_ctrl_base_1v0, 109 .nu_value = 0x7777, 110 .nu_ret = NVME_FIELD_ERR_OK 111 }, { 112 .nu_desc = "invalid cdw13", 113 .nu_fields = nvme_vuc_fields, 114 .nu_index = NVME_VUC_REQ_FIELD_CDW13, 115 .nu_data = &nvme_ctrl_base_1v0, 116 .nu_value = 0x100000000, 117 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 118 }, { 119 .nu_desc = "valid cdw13", 120 .nu_fields = nvme_vuc_fields, 121 .nu_index = NVME_VUC_REQ_FIELD_CDW13, 122 .nu_data = &nvme_ctrl_base_1v0, 123 .nu_value = 0x6666, 124 .nu_ret = NVME_FIELD_ERR_OK 125 }, { 126 .nu_desc = "invalid cdw14", 127 .nu_fields = nvme_vuc_fields, 128 .nu_index = NVME_VUC_REQ_FIELD_CDW14, 129 .nu_data = &nvme_ctrl_base_1v0, 130 .nu_value = 0x100000000, 131 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 132 }, { 133 .nu_desc = "valid cdw14", 134 .nu_fields = nvme_vuc_fields, 135 .nu_index = NVME_VUC_REQ_FIELD_CDW14, 136 .nu_data = &nvme_ctrl_base_1v0, 137 .nu_value = 0x5555, 138 .nu_ret = NVME_FIELD_ERR_OK 139 }, { 140 .nu_desc = "invalid cdw15", 141 .nu_fields = nvme_vuc_fields, 142 .nu_index = NVME_VUC_REQ_FIELD_CDW15, 143 .nu_data = &nvme_ctrl_base_1v0, 144 .nu_value = 0x100000000, 145 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 146 }, { 147 .nu_desc = "valid cdw15", 148 .nu_fields = nvme_vuc_fields, 149 .nu_index = NVME_VUC_REQ_FIELD_CDW15, 150 .nu_data = &nvme_ctrl_base_1v0, 151 .nu_value = 0x4444, 152 .nu_ret = NVME_FIELD_ERR_OK 153 }, { 154 .nu_desc = "invalid ndt (1)", 155 .nu_fields = nvme_vuc_fields, 156 .nu_index = NVME_VUC_REQ_FIELD_NDT, 157 .nu_data = &nvme_ctrl_base_1v0, 158 .nu_value = 0x400000000, 159 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 160 }, { 161 .nu_desc = "invalid ndt (2)", 162 .nu_fields = nvme_vuc_fields, 163 .nu_index = NVME_VUC_REQ_FIELD_NDT, 164 .nu_data = &nvme_ctrl_base_1v0, 165 .nu_value = 0x3, 166 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 167 }, { 168 .nu_desc = "invalid ndt (3)", 169 .nu_fields = nvme_vuc_fields, 170 .nu_index = NVME_VUC_REQ_FIELD_NDT, 171 .nu_data = &nvme_ctrl_base_1v0, 172 .nu_value = 0x17, 173 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 174 }, { 175 .nu_desc = "valid ndt (1)", 176 .nu_fields = nvme_vuc_fields, 177 .nu_index = NVME_VUC_REQ_FIELD_NDT, 178 .nu_data = &nvme_ctrl_base_1v0, 179 .nu_value = 0x3fffffffc, 180 .nu_ret = NVME_FIELD_ERR_OK 181 }, { 182 .nu_desc = "valid ndt (2)", 183 .nu_fields = nvme_vuc_fields, 184 .nu_index = NVME_VUC_REQ_FIELD_NDT, 185 .nu_data = &nvme_ctrl_base_1v0, 186 .nu_value = 0x0, 187 .nu_ret = NVME_FIELD_ERR_OK 188 }, { 189 .nu_desc = "valid ndt (3)", 190 .nu_fields = nvme_vuc_fields, 191 .nu_index = NVME_VUC_REQ_FIELD_NDT, 192 .nu_data = &nvme_ctrl_base_1v0, 193 .nu_value = 0x1234, 194 .nu_ret = NVME_FIELD_ERR_OK 195 }, { 196 .nu_desc = "invalid timeout (1)", 197 .nu_fields = nvme_vuc_fields, 198 .nu_index = NVME_VUC_REQ_FIELD_TO, 199 .nu_data = &nvme_ctrl_base_1v0, 200 .nu_value = 0x0, 201 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 202 }, { 203 .nu_desc = "invalid timeout (2)", 204 .nu_fields = nvme_vuc_fields, 205 .nu_index = NVME_VUC_REQ_FIELD_TO, 206 .nu_data = &nvme_ctrl_base_1v0, 207 .nu_value = 0x100000000, 208 .nu_ret = NVME_FIELD_ERR_BAD_VALUE 209 }, { 210 .nu_desc = "valid timeout (1)", 211 .nu_fields = nvme_vuc_fields, 212 .nu_index = NVME_VUC_REQ_FIELD_TO, 213 .nu_data = &nvme_ctrl_base_1v0, 214 .nu_value = 0x1, 215 .nu_ret = NVME_FIELD_ERR_OK 216 }, { 217 .nu_desc = "valid timeout (2)", 218 .nu_fields = nvme_vuc_fields, 219 .nu_index = NVME_VUC_REQ_FIELD_TO, 220 .nu_data = &nvme_ctrl_base_1v0, 221 .nu_value = 0x101, 222 .nu_ret = NVME_FIELD_ERR_OK 223 } }; 224 225 int 226 main(void) 227 { 228 int ret = EXIT_SUCCESS; 229 230 if (!nvme_unit_field_test(vuc_field_tests, 231 ARRAY_SIZE(vuc_field_tests))) { 232 ret = EXIT_FAILURE; 233 } 234 235 if (ret == EXIT_SUCCESS) { 236 (void) printf("All tests passed successfully!\n"); 237 } 238 239 return (ret); 240 } 241