#include "nvme_common.h"
#include <sys/sysmacros.h>
#ifdef _KERNEL
#include <sys/sunddi.h>
#include <sys/stdint.h>
#else
#include <stdio.h>
#include <inttypes.h>
#endif
static bool
nvme_vuc_field_valid_opc(const nvme_field_info_t *field,
const nvme_valid_ctrl_data_t *data, uint64_t opcode, char *msg,
size_t msglen)
{
return (nvme_field_range_check(field, NVME_PASSTHRU_MIN_ADMIN_OPC,
NVME_PASSTHRU_MAX_ADMIN_OPC, msg, msglen, opcode));
}
static bool
nvme_vuc_field_valid_nsid(const nvme_field_info_t *field,
const nvme_valid_ctrl_data_t *data, uint64_t nsid, char *msg, size_t msglen)
{
if (nsid == 0) {
return (true);
}
return (nvme_field_valid_nsid(field, data, nsid, msg, msglen));
}
static bool
nvme_vuc_field_valid_ndt(const nvme_field_info_t *field,
const nvme_valid_ctrl_data_t *data, uint64_t len, char *msg, size_t msglen)
{
uint64_t max = (uint64_t)UINT32_MAX << NVME_DWORD_SHIFT;
if ((len % NVME_DWORD_SIZE) != 0) {
(void) snprintf(msg, msglen, "%s (%s) value 0x%" PRIx64 " is "
"invalid: value must be %u-byte aligned", field->nlfi_human,
field->nlfi_spec, len, NVME_DWORD_SIZE);
return (false);
}
return (nvme_field_range_check(field, 0, max, msg, msglen, len));
}
static bool
nvme_vuc_field_valid_to(const nvme_field_info_t *field,
const nvme_valid_ctrl_data_t *data, uint64_t to, char *msg, size_t msglen)
{
return (nvme_field_range_check(field, 1, UINT32_MAX, msg, msglen, to));
}
const nvme_field_info_t nvme_vuc_fields[] = {
[NVME_VUC_REQ_FIELD_OPC] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_valid = nvme_vuc_field_valid_opc,
.nlfi_spec = "opc",
.nlfi_human = "opcode",
.nlfi_def_req = true,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_NSID] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_valid = nvme_vuc_field_valid_nsid,
.nlfi_spec = "nsid",
.nlfi_human = "namespace ID",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_CDW12] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_max_size = UINT32_MAX,
.nlfi_spec = "cdw12",
.nlfi_human = "command dword 12",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_CDW13] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_max_size = UINT32_MAX,
.nlfi_spec = "cdw13",
.nlfi_human = "command dword 13",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_CDW14] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_max_size = UINT32_MAX,
.nlfi_spec = "cdw14",
.nlfi_human = "command dword 14",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_CDW15] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_max_size = UINT32_MAX,
.nlfi_spec = "cdw15",
.nlfi_human = "command dword 15",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_NDT] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_valid = nvme_vuc_field_valid_ndt,
.nlfi_spec = "ndt",
.nlfi_human = "number of dwords in data transfer",
.nlfi_def_req = false,
.nlfi_def_allow = true
},
[NVME_VUC_REQ_FIELD_TO] = {
.nlfi_vers = &nvme_vers_1v0,
.nlfi_valid = nvme_vuc_field_valid_to,
.nlfi_spec = "to",
.nlfi_human = "timeout",
.nlfi_def_req = true,
.nlfi_def_allow = true
}
};
const size_t nvme_vuc_nfields = ARRAY_SIZE(nvme_vuc_fields);