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