git: 2ad9a815fd58 - main - nvme: Directly lookup op code
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 07 Aug 2023 22:45:45 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=2ad9a815fd588f26ecfbbadd77a10b7b6cf9a68a commit 2ad9a815fd588f26ecfbbadd77a10b7b6cf9a68a Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2023-08-07 22:36:45 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2023-08-07 22:44:32 +0000 nvme: Directly lookup op code Rather than have a table to walk through, use a sparse array. Suggested by: jhb Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D41353 --- sys/dev/nvme/nvme_qpair.c | 114 ++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/sys/dev/nvme/nvme_qpair.c b/sys/dev/nvme/nvme_qpair.c index 878df6183eea..9e15749d1bca 100644 --- a/sys/dev/nvme/nvme_qpair.c +++ b/sys/dev/nvme/nvme_qpair.c @@ -46,71 +46,67 @@ static void _nvme_qpair_submit_request(struct nvme_qpair *qpair, struct nvme_request *req); static void nvme_qpair_destroy(struct nvme_qpair *qpair); -struct nvme_opcode_string { - uint16_t opc; - const char * str; -}; - -static struct nvme_opcode_string admin_opcode[] = { - { NVME_OPC_DELETE_IO_SQ, "DELETE IO SQ" }, - { NVME_OPC_CREATE_IO_SQ, "CREATE IO SQ" }, - { NVME_OPC_GET_LOG_PAGE, "GET LOG PAGE" }, - { NVME_OPC_DELETE_IO_CQ, "DELETE IO CQ" }, - { NVME_OPC_CREATE_IO_CQ, "CREATE IO CQ" }, - { NVME_OPC_IDENTIFY, "IDENTIFY" }, - { NVME_OPC_ABORT, "ABORT" }, - { NVME_OPC_SET_FEATURES, "SET FEATURES" }, - { NVME_OPC_GET_FEATURES, "GET FEATURES" }, - { NVME_OPC_ASYNC_EVENT_REQUEST, "ASYNC EVENT REQUEST" }, - { NVME_OPC_NAMESPACE_MANAGEMENT, "NAMESPACE MANAGEMENT" }, - { NVME_OPC_FIRMWARE_ACTIVATE, "FIRMWARE ACTIVATE" }, - { NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD, "FIRMWARE IMAGE DOWNLOAD" }, - { NVME_OPC_DEVICE_SELF_TEST, "DEVICE SELF-TEST" }, - { NVME_OPC_NAMESPACE_ATTACHMENT, "NAMESPACE ATTACHMENT" }, - { NVME_OPC_KEEP_ALIVE, "KEEP ALIVE" }, - { NVME_OPC_DIRECTIVE_SEND, "DIRECTIVE SEND" }, - { NVME_OPC_DIRECTIVE_RECEIVE, "DIRECTIVE RECEIVE" }, - { NVME_OPC_VIRTUALIZATION_MANAGEMENT, "VIRTUALIZATION MANAGEMENT" }, - { NVME_OPC_NVME_MI_SEND, "NVME-MI SEND" }, - { NVME_OPC_NVME_MI_RECEIVE, "NVME-MI RECEIVE" }, - { NVME_OPC_CAPACITY_MANAGEMENT, "CAPACITY MANAGEMENT" }, - { NVME_OPC_LOCKDOWN, "LOCKDOWN" }, - { NVME_OPC_DOORBELL_BUFFER_CONFIG, "DOORBELL BUFFER CONFIG" }, - { NVME_OPC_FABRICS_COMMANDS, "FABRICS COMMANDS" }, - { NVME_OPC_FORMAT_NVM, "FORMAT NVM" }, - { NVME_OPC_SECURITY_SEND, "SECURITY SEND" }, - { NVME_OPC_SECURITY_RECEIVE, "SECURITY RECEIVE" }, - { NVME_OPC_SANITIZE, "SANITIZE" }, - { NVME_OPC_GET_LBA_STATUS, "GET LBA STATUS" }, - { 0xFFFF, "ADMIN COMMAND" } +#define DEFAULT_INDEX 256 +#define DEFAULT_ENTRY(x) [DEFAULT_INDEX] = x +#define OPC_ENTRY(x) [NVME_OPC_ ## x] = #x + +static const char *admin_opcode[DEFAULT_INDEX + 1] = { + OPC_ENTRY(DELETE_IO_SQ), + OPC_ENTRY(CREATE_IO_SQ), + OPC_ENTRY(GET_LOG_PAGE), + OPC_ENTRY(DELETE_IO_CQ), + OPC_ENTRY(CREATE_IO_CQ), + OPC_ENTRY(IDENTIFY), + OPC_ENTRY(ABORT), + OPC_ENTRY(SET_FEATURES), + OPC_ENTRY(GET_FEATURES), + OPC_ENTRY(ASYNC_EVENT_REQUEST), + OPC_ENTRY(NAMESPACE_MANAGEMENT), + OPC_ENTRY(FIRMWARE_ACTIVATE), + OPC_ENTRY(FIRMWARE_IMAGE_DOWNLOAD), + OPC_ENTRY(DEVICE_SELF_TEST), + OPC_ENTRY(NAMESPACE_ATTACHMENT), + OPC_ENTRY(KEEP_ALIVE), + OPC_ENTRY(DIRECTIVE_SEND), + OPC_ENTRY(DIRECTIVE_RECEIVE), + OPC_ENTRY(VIRTUALIZATION_MANAGEMENT), + OPC_ENTRY(NVME_MI_SEND), + OPC_ENTRY(NVME_MI_RECEIVE), + OPC_ENTRY(CAPACITY_MANAGEMENT), + OPC_ENTRY(LOCKDOWN), + OPC_ENTRY(DOORBELL_BUFFER_CONFIG), + OPC_ENTRY(FABRICS_COMMANDS), + OPC_ENTRY(FORMAT_NVM), + OPC_ENTRY(SECURITY_SEND), + OPC_ENTRY(SECURITY_RECEIVE), + OPC_ENTRY(SANITIZE), + OPC_ENTRY(GET_LBA_STATUS), + DEFAULT_ENTRY("ADMIN COMMAND"), }; -static struct nvme_opcode_string io_opcode[] = { - { NVME_OPC_FLUSH, "FLUSH" }, - { NVME_OPC_WRITE, "WRITE" }, - { NVME_OPC_READ, "READ" }, - { NVME_OPC_WRITE_UNCORRECTABLE, "WRITE UNCORRECTABLE" }, - { NVME_OPC_COMPARE, "COMPARE" }, - { NVME_OPC_WRITE_ZEROES, "WRITE ZEROES" }, - { NVME_OPC_DATASET_MANAGEMENT, "DATASET MANAGEMENT" }, - { NVME_OPC_VERIFY, "VERIFY" }, - { NVME_OPC_RESERVATION_REGISTER, "RESERVATION REGISTER" }, - { NVME_OPC_RESERVATION_REPORT, "RESERVATION REPORT" }, - { NVME_OPC_RESERVATION_ACQUIRE, "RESERVATION ACQUIRE" }, - { NVME_OPC_RESERVATION_RELEASE, "RESERVATION RELEASE" }, - { NVME_OPC_COPY, "COPY" }, - { 0xFFFF, "IO COMMAND" } +static const char *io_opcode[DEFAULT_INDEX + 1] = { + OPC_ENTRY(FLUSH), + OPC_ENTRY(WRITE), + OPC_ENTRY(READ), + OPC_ENTRY(WRITE_UNCORRECTABLE), + OPC_ENTRY(COMPARE), + OPC_ENTRY(WRITE_ZEROES), + OPC_ENTRY(DATASET_MANAGEMENT), + OPC_ENTRY(VERIFY), + OPC_ENTRY(RESERVATION_REGISTER), + OPC_ENTRY(RESERVATION_REPORT), + OPC_ENTRY(RESERVATION_ACQUIRE), + OPC_ENTRY(RESERVATION_RELEASE), + OPC_ENTRY(COPY), + DEFAULT_ENTRY("IO COMMAND"), }; static const char * -get_opcode_string(struct nvme_opcode_string *entry, uint16_t opc) +get_opcode_string(const char *op[DEFAULT_INDEX + 1], uint16_t opc) { - while (entry->opc != 0xFFFF) { - if (entry->opc == opc) - return (entry->str); - entry++; - } - return (entry->str); + const char *nm = opc < DEFAULT_INDEX ? op[opc] : op[DEFAULT_INDEX]; + + return (nm != NULL ? nm : op[DEFAULT_INDEX]); } static const char *