diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 8649a74c..8d88af12 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -114,112 +114,6 @@ static void nvme_show_command(struct nvme_passthru_cmd *cmd, int err) printf("err : %d\n", err); } -const char *nvme_admin_to_string(__u8 opcode) -{ - switch (opcode) { - case nvme_admin_delete_sq: - return "Delete I/O Submission Queue"; - case nvme_admin_create_sq: - return "Create I/O Submission Queue"; - case nvme_admin_get_log_page: - return "Get Log Page"; - case nvme_admin_delete_cq: - return "Delete I/O Completion Queue"; - case nvme_admin_create_cq: - return "Create I/O Completion Queue"; - case nvme_admin_identify: - return "Identify"; - case nvme_admin_abort_cmd: - return "Abort"; - case nvme_admin_set_features: - return "Set Features"; - case nvme_admin_get_features: - return "Get Features"; - case nvme_admin_async_event: - return "Asynchronous Event Request"; - case nvme_admin_ns_mgmt: - return "Namespace Management"; - case nvme_admin_fw_commit: - return "Firmware Commit"; - case nvme_admin_fw_download: - return "Firmware Image Download"; - case nvme_admin_dev_self_test: - return "Device Self-test"; - case nvme_admin_ns_attach: - return "Namespace Attachment"; - case nvme_admin_keep_alive: - return "Keep Alive"; - case nvme_admin_directive_send: - return "Directive Send"; - case nvme_admin_directive_recv: - return "Directive Receive"; - case nvme_admin_virtual_mgmt: - return "Virtualization Management"; - case nvme_admin_nvme_mi_send: - return "NVMe-MI Send"; - case nvme_admin_nvme_mi_recv: - return "NVMe-MI Receive"; - case nvme_admin_dbbuf: - return "Doorbell Buffer Config"; - case nvme_admin_format_nvm: - return "Format NVM"; - case nvme_admin_security_send: - return "Security Send"; - case nvme_admin_security_recv: - return "Security Receive"; - case nvme_admin_sanitize_nvm: - return "Sanitize"; - case nvme_admin_get_lba_status: - return "Get LBA Status"; - default: - break; - } - - return NULL; -} - -const char *nvme_nvm_to_string(__u8 opcode) -{ - switch (opcode) { - case nvme_cmd_flush: - return "Flush"; - case nvme_cmd_write: - return "Write"; - case nvme_cmd_read: - return "Read"; - case nvme_cmd_write_uncor: - return "Write Uncorrectable"; - case nvme_cmd_compare: - return "Compare"; - case nvme_cmd_write_zeroes: - return "Write Zeroes"; - case nvme_cmd_dsm: - return "Dataset Management"; - case nvme_cmd_resv_register: - return "Reservation Register"; - case nvme_cmd_resv_report: - return "Reservation Report"; - case nvme_cmd_resv_acquire: - return "Reservation Acquire"; - case nvme_cmd_resv_release: - return "Reservation Release"; - case nvme_cmd_verify: - return "Verify"; - case nvme_cmd_copy: - return "Copy"; - case nvme_zns_cmd_mgmt_send: - return "Zone Management Send"; - case nvme_zns_cmd_mgmt_recv: - return "Zone Management Receive"; - case nvme_zns_cmd_append: - return "Zone Append"; - default: - break; - } - - return NULL; -} - static const char *nvme_cmd_to_string(bool admin, __u8 opcode) { const char *cmd_name; diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index bdb22b3f..f48b5b44 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -4072,22 +4072,4 @@ void nvme_set_latency(bool latency); * Return: false if disabled or true if enabled. */ bool nvme_get_latency(void); - -/** - * nvme_admin_to_string - Returns string describing nvme admin opcode - * @opcode: Admin opcode for an nvme command - * - * Return: representation of the admin opcode if it is an admin opcode field, - * or NULL if opcode is unknown. - */ -const char *nvme_admin_to_string(__u8 opcode); - -/** - * nvme_nvm_to_string - Returns string describing nvme nvm opcode - * @opcode: NVM opcode for an nvme command - * - * Return: representation of the nvm opcode if it is an nvm opcode field, - * or NULL if opcode is unknown. - */ -const char *nvme_nvm_to_string(__u8 opcode); #endif /* _LIBNVME_IOCTL_H */ diff --git a/src/nvme/util.c b/src/nvme/util.c index 45512ff9..bf3946c0 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -1116,3 +1116,68 @@ void *__nvme_alloc(size_t len) memset(p, 0, _len); return p; } + +static const char * const admin_opcode[] = { + [nvme_admin_delete_sq] = "Delete I/O Submission Queue", + [nvme_admin_create_sq] = "Create I/O Submission Queue", + [nvme_admin_get_log_page] = "Get Log Page", + [nvme_admin_delete_cq] = "Delete I/O Completion Queue", + [nvme_admin_create_cq] = "Create I/O Completion Queue", + [nvme_admin_identify] = "Identify", + [nvme_admin_abort_cmd] = "Abort", + [nvme_admin_set_features] = "Set Features", + [nvme_admin_get_features] = "Get Features", + [nvme_admin_async_event] = "Asynchronous Event Request", + [nvme_admin_ns_mgmt] = "Namespace Management", + [nvme_admin_fw_commit] = "Firmware Commit", + [nvme_admin_fw_download] = "Firmware Image Download", + [nvme_admin_dev_self_test] = "Device Self-test", + [nvme_admin_ns_attach] = "Namespace Attachment", + [nvme_admin_keep_alive] = "Keep Alive", + [nvme_admin_directive_send] = "Directive Send", + [nvme_admin_directive_recv] = "Directive Receive", + [nvme_admin_virtual_mgmt] = "Virtualization Management", + [nvme_admin_nvme_mi_send] = "NVMe-MI Send", + [nvme_admin_nvme_mi_recv] = "NVMe-MI Receive", + [nvme_admin_dbbuf] = "Doorbell Buffer Config", + [nvme_admin_format_nvm] = "Format NVM", + [nvme_admin_security_send] = "Security Send", + [nvme_admin_security_recv] = "Security Receive", + [nvme_admin_sanitize_nvm] = "Sanitize", + [nvme_admin_get_lba_status] = "Get LBA Status", +}; + +static const char * const nvm_opcode[] = { + [nvme_cmd_flush] = "Flush", + [nvme_cmd_write] = "Write", + [nvme_cmd_read] = "Read", + [nvme_cmd_write_uncor] = "Write Uncorrectable", + [nvme_cmd_compare] = "Compare", + [nvme_cmd_write_zeroes] = "Write Zeroes", + [nvme_cmd_dsm] = "Dataset Management", + [nvme_cmd_resv_register] = "Reservation Register", + [nvme_cmd_resv_report] = "Reservation Report", + [nvme_cmd_resv_acquire] = "Reservation Acquire", + [nvme_cmd_resv_release] = "Reservation Release", + [nvme_cmd_verify] = "Verify", + [nvme_cmd_copy] = "Copy", + [nvme_zns_cmd_mgmt_send] = "Zone Management Send", + [nvme_zns_cmd_mgmt_recv] = "Zone Management Receive", + [nvme_zns_cmd_append] = "Zone Append", +}; + +const char *nvme_admin_to_string(__u8 opcode) +{ + if (opcode < ARRAY_SIZE(admin_opcode)) + return admin_opcode[opcode]; + + return NULL; +} + +const char *nvme_nvm_to_string(__u8 opcode) +{ + if (opcode < ARRAY_SIZE(nvm_opcode)) + return nvm_opcode[opcode]; + + return NULL; +} diff --git a/src/nvme/util.h b/src/nvme/util.h index 16d5b9ca..bf91302e 100644 --- a/src/nvme/util.h +++ b/src/nvme/util.h @@ -702,4 +702,21 @@ const char *nvme_iface_matching_addr(const struct ifaddrs *iface_list, const cha */ bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const char *iface, const char *addr); +/** + * nvme_admin_to_string - Returns string describing nvme admin opcode + * @opcode: Admin opcode for an nvme command + * + * Return: representation of the admin opcode if it is an admin opcode field, + * or NULL if opcode is unknown. + */ +const char *nvme_admin_to_string(__u8 opcode); + +/** + * nvme_nvm_to_string - Returns string describing nvme nvm opcode + * @opcode: NVM opcode for an nvme command + * + * Return: representation of the nvm opcode if it is an nvm opcode field, + * or NULL if opcode is unknown. + */ +const char *nvme_nvm_to_string(__u8 opcode); #endif /* _LIBNVME_UTIL_H */