xref: /openbmc/linux/drivers/nvme/host/constants.c (revision 88a6f899)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * NVM Express device driver verbose errors
4  * Copyright (c) 2022, Oracle and/or its affiliates
5  */
6 
7 #include "nvme.h"
8 
9 static const char * const nvme_ops[] = {
10 	[nvme_cmd_flush] = "Flush",
11 	[nvme_cmd_write] = "Write",
12 	[nvme_cmd_read] = "Read",
13 	[nvme_cmd_write_uncor] = "Write Uncorrectable",
14 	[nvme_cmd_compare] = "Compare",
15 	[nvme_cmd_write_zeroes] = "Write Zeroes",
16 	[nvme_cmd_dsm] = "Dataset Management",
17 	[nvme_cmd_verify] = "Verify",
18 	[nvme_cmd_resv_register] = "Reservation Register",
19 	[nvme_cmd_resv_report] = "Reservation Report",
20 	[nvme_cmd_resv_acquire] = "Reservation Acquire",
21 	[nvme_cmd_resv_release] = "Reservation Release",
22 	[nvme_cmd_zone_mgmt_send] = "Zone Management Send",
23 	[nvme_cmd_zone_mgmt_recv] = "Zone Management Receive",
24 	[nvme_cmd_zone_append] = "Zone Append",
25 };
26 
27 static const char * const nvme_admin_ops[] = {
28 	[nvme_admin_delete_sq] = "Delete SQ",
29 	[nvme_admin_create_sq] = "Create SQ",
30 	[nvme_admin_get_log_page] = "Get Log Page",
31 	[nvme_admin_delete_cq] = "Delete CQ",
32 	[nvme_admin_create_cq] = "Create CQ",
33 	[nvme_admin_identify] = "Identify",
34 	[nvme_admin_abort_cmd] = "Abort Command",
35 	[nvme_admin_set_features] = "Set Features",
36 	[nvme_admin_get_features] = "Get Features",
37 	[nvme_admin_async_event] = "Async Event",
38 	[nvme_admin_ns_mgmt] = "Namespace Management",
39 	[nvme_admin_activate_fw] = "Activate Firmware",
40 	[nvme_admin_download_fw] = "Download Firmware",
41 	[nvme_admin_dev_self_test] = "Device Self Test",
42 	[nvme_admin_ns_attach] = "Namespace Attach",
43 	[nvme_admin_keep_alive] = "Keep Alive",
44 	[nvme_admin_directive_send] = "Directive Send",
45 	[nvme_admin_directive_recv] = "Directive Receive",
46 	[nvme_admin_virtual_mgmt] = "Virtual Management",
47 	[nvme_admin_nvme_mi_send] = "NVMe Send MI",
48 	[nvme_admin_nvme_mi_recv] = "NVMe Receive MI",
49 	[nvme_admin_dbbuf] = "Doorbell Buffer Config",
50 	[nvme_admin_format_nvm] = "Format NVM",
51 	[nvme_admin_security_send] = "Security Send",
52 	[nvme_admin_security_recv] = "Security Receive",
53 	[nvme_admin_sanitize_nvm] = "Sanitize NVM",
54 	[nvme_admin_get_lba_status] = "Get LBA Status",
55 };
56 
57 static const char * const nvme_fabrics_ops[] = {
58 	[nvme_fabrics_type_property_set] = "Property Set",
59 	[nvme_fabrics_type_property_get] = "Property Get",
60 	[nvme_fabrics_type_connect] = "Connect",
61 	[nvme_fabrics_type_auth_send] = "Authentication Send",
62 	[nvme_fabrics_type_auth_receive] = "Authentication Receive",
63 };
64 
65 static const char * const nvme_statuses[] = {
66 	[NVME_SC_SUCCESS] = "Success",
67 	[NVME_SC_INVALID_OPCODE] = "Invalid Command Opcode",
68 	[NVME_SC_INVALID_FIELD] = "Invalid Field in Command",
69 	[NVME_SC_CMDID_CONFLICT] = "Command ID Conflict",
70 	[NVME_SC_DATA_XFER_ERROR] = "Data Transfer Error",
71 	[NVME_SC_POWER_LOSS] = "Commands Aborted due to Power Loss Notification",
72 	[NVME_SC_INTERNAL] = "Internal Error",
73 	[NVME_SC_ABORT_REQ] = "Command Abort Requested",
74 	[NVME_SC_ABORT_QUEUE] = "Command Aborted due to SQ Deletion",
75 	[NVME_SC_FUSED_FAIL] = "Command Aborted due to Failed Fused Command",
76 	[NVME_SC_FUSED_MISSING] = "Command Aborted due to Missing Fused Command",
77 	[NVME_SC_INVALID_NS] = "Invalid Namespace or Format",
78 	[NVME_SC_CMD_SEQ_ERROR] = "Command Sequence Error",
79 	[NVME_SC_SGL_INVALID_LAST] = "Invalid SGL Segment Descriptor",
80 	[NVME_SC_SGL_INVALID_COUNT] = "Invalid Number of SGL Descriptors",
81 	[NVME_SC_SGL_INVALID_DATA] = "Data SGL Length Invalid",
82 	[NVME_SC_SGL_INVALID_METADATA] = "Metadata SGL Length Invalid",
83 	[NVME_SC_SGL_INVALID_TYPE] = "SGL Descriptor Type Invalid",
84 	[NVME_SC_CMB_INVALID_USE] = "Invalid Use of Controller Memory Buffer",
85 	[NVME_SC_PRP_INVALID_OFFSET] = "PRP Offset Invalid",
86 	[NVME_SC_ATOMIC_WU_EXCEEDED] = "Atomic Write Unit Exceeded",
87 	[NVME_SC_OP_DENIED] = "Operation Denied",
88 	[NVME_SC_SGL_INVALID_OFFSET] = "SGL Offset Invalid",
89 	[NVME_SC_RESERVED] = "Reserved",
90 	[NVME_SC_HOST_ID_INCONSIST] = "Host Identifier Inconsistent Format",
91 	[NVME_SC_KA_TIMEOUT_EXPIRED] = "Keep Alive Timeout Expired",
92 	[NVME_SC_KA_TIMEOUT_INVALID] = "Keep Alive Timeout Invalid",
93 	[NVME_SC_ABORTED_PREEMPT_ABORT] = "Command Aborted due to Preempt and Abort",
94 	[NVME_SC_SANITIZE_FAILED] = "Sanitize Failed",
95 	[NVME_SC_SANITIZE_IN_PROGRESS] = "Sanitize In Progress",
96 	[NVME_SC_SGL_INVALID_GRANULARITY] = "SGL Data Block Granularity Invalid",
97 	[NVME_SC_CMD_NOT_SUP_CMB_QUEUE] = "Command Not Supported for Queue in CMB",
98 	[NVME_SC_NS_WRITE_PROTECTED] = "Namespace is Write Protected",
99 	[NVME_SC_CMD_INTERRUPTED] = "Command Interrupted",
100 	[NVME_SC_TRANSIENT_TR_ERR] = "Transient Transport Error",
101 	[NVME_SC_ADMIN_COMMAND_MEDIA_NOT_READY] = "Admin Command Media Not Ready",
102 	[NVME_SC_INVALID_IO_CMD_SET] = "Invalid IO Command Set",
103 	[NVME_SC_LBA_RANGE] = "LBA Out of Range",
104 	[NVME_SC_CAP_EXCEEDED] = "Capacity Exceeded",
105 	[NVME_SC_NS_NOT_READY] = "Namespace Not Ready",
106 	[NVME_SC_RESERVATION_CONFLICT] = "Reservation Conflict",
107 	[NVME_SC_FORMAT_IN_PROGRESS] = "Format In Progress",
108 	[NVME_SC_CQ_INVALID] = "Completion Queue Invalid",
109 	[NVME_SC_QID_INVALID] = "Invalid Queue Identifier",
110 	[NVME_SC_QUEUE_SIZE] = "Invalid Queue Size",
111 	[NVME_SC_ABORT_LIMIT] = "Abort Command Limit Exceeded",
112 	[NVME_SC_ABORT_MISSING] = "Reserved", /* XXX */
113 	[NVME_SC_ASYNC_LIMIT] = "Asynchronous Event Request Limit Exceeded",
114 	[NVME_SC_FIRMWARE_SLOT] = "Invalid Firmware Slot",
115 	[NVME_SC_FIRMWARE_IMAGE] = "Invalid Firmware Image",
116 	[NVME_SC_INVALID_VECTOR] = "Invalid Interrupt Vector",
117 	[NVME_SC_INVALID_LOG_PAGE] = "Invalid Log Page",
118 	[NVME_SC_INVALID_FORMAT] = "Invalid Format",
119 	[NVME_SC_FW_NEEDS_CONV_RESET] = "Firmware Activation Requires Conventional Reset",
120 	[NVME_SC_INVALID_QUEUE] = "Invalid Queue Deletion",
121 	[NVME_SC_FEATURE_NOT_SAVEABLE] = "Feature Identifier Not Saveable",
122 	[NVME_SC_FEATURE_NOT_CHANGEABLE] = "Feature Not Changeable",
123 	[NVME_SC_FEATURE_NOT_PER_NS] = "Feature Not Namespace Specific",
124 	[NVME_SC_FW_NEEDS_SUBSYS_RESET] = "Firmware Activation Requires NVM Subsystem Reset",
125 	[NVME_SC_FW_NEEDS_RESET] = "Firmware Activation Requires Reset",
126 	[NVME_SC_FW_NEEDS_MAX_TIME] = "Firmware Activation Requires Maximum Time Violation",
127 	[NVME_SC_FW_ACTIVATE_PROHIBITED] = "Firmware Activation Prohibited",
128 	[NVME_SC_OVERLAPPING_RANGE] = "Overlapping Range",
129 	[NVME_SC_NS_INSUFFICIENT_CAP] = "Namespace Insufficient Capacity",
130 	[NVME_SC_NS_ID_UNAVAILABLE] = "Namespace Identifier Unavailable",
131 	[NVME_SC_NS_ALREADY_ATTACHED] = "Namespace Already Attached",
132 	[NVME_SC_NS_IS_PRIVATE] = "Namespace Is Private",
133 	[NVME_SC_NS_NOT_ATTACHED] = "Namespace Not Attached",
134 	[NVME_SC_THIN_PROV_NOT_SUPP] = "Thin Provisioning Not Supported",
135 	[NVME_SC_CTRL_LIST_INVALID] = "Controller List Invalid",
136 	[NVME_SC_SELT_TEST_IN_PROGRESS] = "Device Self-test In Progress",
137 	[NVME_SC_BP_WRITE_PROHIBITED] = "Boot Partition Write Prohibited",
138 	[NVME_SC_CTRL_ID_INVALID] = "Invalid Controller Identifier",
139 	[NVME_SC_SEC_CTRL_STATE_INVALID] = "Invalid Secondary Controller State",
140 	[NVME_SC_CTRL_RES_NUM_INVALID] = "Invalid Number of Controller Resources",
141 	[NVME_SC_RES_ID_INVALID] = "Invalid Resource Identifier",
142 	[NVME_SC_PMR_SAN_PROHIBITED] = "Sanitize Prohibited",
143 	[NVME_SC_ANA_GROUP_ID_INVALID] = "ANA Group Identifier Invalid",
144 	[NVME_SC_ANA_ATTACH_FAILED] = "ANA Attach Failed",
145 	[NVME_SC_BAD_ATTRIBUTES] = "Conflicting Attributes",
146 	[NVME_SC_INVALID_PI] = "Invalid Protection Information",
147 	[NVME_SC_READ_ONLY] = "Attempted Write to Read Only Range",
148 	[NVME_SC_ONCS_NOT_SUPPORTED] = "ONCS Not Supported",
149 	[NVME_SC_ZONE_BOUNDARY_ERROR] = "Zoned Boundary Error",
150 	[NVME_SC_ZONE_FULL] = "Zone Is Full",
151 	[NVME_SC_ZONE_READ_ONLY] = "Zone Is Read Only",
152 	[NVME_SC_ZONE_OFFLINE] = "Zone Is Offline",
153 	[NVME_SC_ZONE_INVALID_WRITE] = "Zone Invalid Write",
154 	[NVME_SC_ZONE_TOO_MANY_ACTIVE] = "Too Many Active Zones",
155 	[NVME_SC_ZONE_TOO_MANY_OPEN] = "Too Many Open Zones",
156 	[NVME_SC_ZONE_INVALID_TRANSITION] = "Invalid Zone State Transition",
157 	[NVME_SC_WRITE_FAULT] = "Write Fault",
158 	[NVME_SC_READ_ERROR] = "Unrecovered Read Error",
159 	[NVME_SC_GUARD_CHECK] = "End-to-end Guard Check Error",
160 	[NVME_SC_APPTAG_CHECK] = "End-to-end Application Tag Check Error",
161 	[NVME_SC_REFTAG_CHECK] = "End-to-end Reference Tag Check Error",
162 	[NVME_SC_COMPARE_FAILED] = "Compare Failure",
163 	[NVME_SC_ACCESS_DENIED] = "Access Denied",
164 	[NVME_SC_UNWRITTEN_BLOCK] = "Deallocated or Unwritten Logical Block",
165 	[NVME_SC_INTERNAL_PATH_ERROR] = "Internal Pathing Error",
166 	[NVME_SC_ANA_PERSISTENT_LOSS] = "Asymmetric Access Persistent Loss",
167 	[NVME_SC_ANA_INACCESSIBLE] = "Asymmetric Access Inaccessible",
168 	[NVME_SC_ANA_TRANSITION] = "Asymmetric Access Transition",
169 	[NVME_SC_CTRL_PATH_ERROR] = "Controller Pathing Error",
170 	[NVME_SC_HOST_PATH_ERROR] = "Host Pathing Error",
171 	[NVME_SC_HOST_ABORTED_CMD] = "Host Aborted Command",
172 };
173 
174 const unsigned char *nvme_get_error_status_str(u16 status)
175 {
176 	status &= 0x7ff;
177 	if (status < ARRAY_SIZE(nvme_statuses) && nvme_statuses[status])
178 		return nvme_statuses[status & 0x7ff];
179 	return "Unknown";
180 }
181 
182 const unsigned char *nvme_get_opcode_str(u8 opcode)
183 {
184 	if (opcode < ARRAY_SIZE(nvme_ops) && nvme_ops[opcode])
185 		return nvme_ops[opcode];
186 	return "Unknown";
187 }
188 EXPORT_SYMBOL_GPL(nvme_get_opcode_str);
189 
190 const unsigned char *nvme_get_admin_opcode_str(u8 opcode)
191 {
192 	if (opcode < ARRAY_SIZE(nvme_admin_ops) && nvme_admin_ops[opcode])
193 		return nvme_admin_ops[opcode];
194 	return "Unknown";
195 }
196 EXPORT_SYMBOL_GPL(nvme_get_admin_opcode_str);
197 
198 const unsigned char *nvme_get_fabrics_opcode_str(u8 opcode) {
199 	if (opcode < ARRAY_SIZE(nvme_fabrics_ops) && nvme_fabrics_ops[opcode])
200 		return nvme_fabrics_ops[opcode];
201 	return "Unknown";
202 }
203 EXPORT_SYMBOL_GPL(nvme_get_fabrics_opcode_str);
204