Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause 2 : * Copyright (C) 2017 Intel Corporation. 3 : * Copyright (c) 2016 FUJITSU LIMITED, All rights reserved. 4 : */ 5 : 6 : #include "spdk/bdev_module.h" 7 : 8 : #include "spdk/nvme_spec.h" 9 : 10 : void 11 26 : spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io, int *sc, int *sk, 12 : int *asc, int *ascq) 13 : { 14 26 : int nvme_sct = bdev_io->internal.error.nvme.sct; 15 26 : int nvme_sc = bdev_io->internal.error.nvme.sc; 16 : 17 26 : switch (nvme_sct) { 18 12 : case SPDK_NVME_SCT_GENERIC: 19 12 : switch (nvme_sc) { 20 1 : case SPDK_NVME_SC_SUCCESS: 21 1 : *sc = SPDK_SCSI_STATUS_GOOD; 22 1 : *sk = SPDK_SCSI_SENSE_NO_SENSE; 23 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 24 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 25 1 : break; 26 1 : case SPDK_NVME_SC_INVALID_OPCODE: 27 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 28 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 29 1 : *asc = SPDK_SCSI_ASC_INVALID_COMMAND_OPERATION_CODE; 30 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 31 1 : break; 32 1 : case SPDK_NVME_SC_INVALID_FIELD: 33 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 34 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 35 1 : *asc = SPDK_SCSI_ASC_INVALID_FIELD_IN_CDB; 36 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 37 1 : break; 38 1 : case SPDK_NVME_SC_DATA_TRANSFER_ERROR: 39 : case SPDK_NVME_SC_CAPACITY_EXCEEDED: 40 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 41 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 42 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 43 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 44 1 : break; 45 1 : case SPDK_NVME_SC_ABORTED_POWER_LOSS: 46 1 : *sc = SPDK_SCSI_STATUS_TASK_ABORTED; 47 1 : *sk = SPDK_SCSI_SENSE_ABORTED_COMMAND; 48 1 : *asc = SPDK_SCSI_ASC_WARNING; 49 1 : *ascq = SPDK_SCSI_ASCQ_POWER_LOSS_EXPECTED; 50 1 : break; 51 1 : case SPDK_NVME_SC_INTERNAL_DEVICE_ERROR: 52 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 53 1 : *sk = SPDK_SCSI_SENSE_HARDWARE_ERROR; 54 1 : *asc = SPDK_SCSI_ASC_INTERNAL_TARGET_FAILURE; 55 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 56 1 : break; 57 1 : case SPDK_NVME_SC_ABORTED_BY_REQUEST: 58 : case SPDK_NVME_SC_ABORTED_SQ_DELETION: 59 : case SPDK_NVME_SC_ABORTED_FAILED_FUSED: 60 : case SPDK_NVME_SC_ABORTED_MISSING_FUSED: 61 1 : *sc = SPDK_SCSI_STATUS_TASK_ABORTED; 62 1 : *sk = SPDK_SCSI_SENSE_ABORTED_COMMAND; 63 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 64 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 65 1 : break; 66 1 : case SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT: 67 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 68 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 69 1 : *asc = SPDK_SCSI_ASC_ACCESS_DENIED; 70 1 : *ascq = SPDK_SCSI_ASCQ_INVALID_LU_IDENTIFIER; 71 1 : break; 72 1 : case SPDK_NVME_SC_LBA_OUT_OF_RANGE: 73 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 74 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 75 1 : *asc = SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 76 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 77 1 : break; 78 1 : case SPDK_NVME_SC_NAMESPACE_NOT_READY: 79 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 80 1 : *sk = SPDK_SCSI_SENSE_NOT_READY; 81 1 : *asc = SPDK_SCSI_ASC_LOGICAL_UNIT_NOT_READY; 82 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 83 1 : break; 84 1 : case SPDK_NVME_SC_RESERVATION_CONFLICT: 85 1 : *sc = SPDK_SCSI_STATUS_RESERVATION_CONFLICT; 86 1 : *sk = SPDK_SCSI_SENSE_NO_SENSE; 87 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 88 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 89 1 : break; 90 1 : case SPDK_NVME_SC_COMMAND_ID_CONFLICT: 91 : case SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR: 92 : case SPDK_NVME_SC_INVALID_SGL_SEG_DESCRIPTOR: 93 : case SPDK_NVME_SC_INVALID_NUM_SGL_DESCIRPTORS: 94 : case SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID: 95 : case SPDK_NVME_SC_METADATA_SGL_LENGTH_INVALID: 96 : case SPDK_NVME_SC_SGL_DESCRIPTOR_TYPE_INVALID: 97 : case SPDK_NVME_SC_INVALID_CONTROLLER_MEM_BUF: 98 : case SPDK_NVME_SC_INVALID_PRP_OFFSET: 99 : case SPDK_NVME_SC_ATOMIC_WRITE_UNIT_EXCEEDED: 100 : case SPDK_NVME_SC_INVALID_SGL_OFFSET: 101 : case SPDK_NVME_SC_HOSTID_INCONSISTENT_FORMAT: 102 : case SPDK_NVME_SC_KEEP_ALIVE_EXPIRED: 103 : case SPDK_NVME_SC_KEEP_ALIVE_INVALID: 104 : case SPDK_NVME_SC_FORMAT_IN_PROGRESS: 105 : default: 106 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 107 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 108 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 109 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 110 1 : break; 111 : } 112 12 : break; 113 5 : case SPDK_NVME_SCT_COMMAND_SPECIFIC: 114 5 : switch (nvme_sc) { 115 1 : case SPDK_NVME_SC_COMPLETION_QUEUE_INVALID: 116 : case SPDK_NVME_SC_ABORT_COMMAND_LIMIT_EXCEEDED: 117 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 118 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 119 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 120 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 121 1 : break; 122 1 : case SPDK_NVME_SC_INVALID_FORMAT: 123 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 124 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 125 1 : *asc = SPDK_SCSI_ASC_FORMAT_COMMAND_FAILED; 126 1 : *ascq = SPDK_SCSI_ASCQ_FORMAT_COMMAND_FAILED; 127 1 : break; 128 1 : case SPDK_NVME_SC_CONFLICTING_ATTRIBUTES: 129 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 130 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 131 1 : *asc = SPDK_SCSI_ASC_INVALID_FIELD_IN_CDB; 132 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 133 1 : break; 134 1 : case SPDK_NVME_SC_ATTEMPTED_WRITE_TO_RO_RANGE: 135 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 136 1 : *sk = SPDK_SCSI_SENSE_DATA_PROTECT; 137 1 : *asc = SPDK_SCSI_ASC_WRITE_PROTECTED; 138 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 139 1 : break; 140 1 : case SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER: 141 : case SPDK_NVME_SC_INVALID_QUEUE_SIZE: 142 : case SPDK_NVME_SC_ASYNC_EVENT_REQUEST_LIMIT_EXCEEDED: 143 : case SPDK_NVME_SC_INVALID_FIRMWARE_SLOT: 144 : case SPDK_NVME_SC_INVALID_FIRMWARE_IMAGE: 145 : case SPDK_NVME_SC_INVALID_INTERRUPT_VECTOR: 146 : case SPDK_NVME_SC_INVALID_LOG_PAGE: 147 : case SPDK_NVME_SC_FIRMWARE_REQ_CONVENTIONAL_RESET: 148 : case SPDK_NVME_SC_INVALID_QUEUE_DELETION: 149 : case SPDK_NVME_SC_FEATURE_ID_NOT_SAVEABLE: 150 : case SPDK_NVME_SC_FEATURE_NOT_CHANGEABLE: 151 : case SPDK_NVME_SC_FEATURE_NOT_NAMESPACE_SPECIFIC: 152 : case SPDK_NVME_SC_FIRMWARE_REQ_NVM_RESET: 153 : case SPDK_NVME_SC_FIRMWARE_REQ_RESET: 154 : case SPDK_NVME_SC_FIRMWARE_REQ_MAX_TIME_VIOLATION: 155 : case SPDK_NVME_SC_FIRMWARE_ACTIVATION_PROHIBITED: 156 : case SPDK_NVME_SC_OVERLAPPING_RANGE: 157 : case SPDK_NVME_SC_NAMESPACE_INSUFFICIENT_CAPACITY: 158 : case SPDK_NVME_SC_NAMESPACE_ID_UNAVAILABLE: 159 : case SPDK_NVME_SC_NAMESPACE_ALREADY_ATTACHED: 160 : case SPDK_NVME_SC_NAMESPACE_IS_PRIVATE: 161 : case SPDK_NVME_SC_NAMESPACE_NOT_ATTACHED: 162 : case SPDK_NVME_SC_THINPROVISIONING_NOT_SUPPORTED: 163 : case SPDK_NVME_SC_CONTROLLER_LIST_INVALID: 164 : case SPDK_NVME_SC_INVALID_PROTECTION_INFO: 165 : default: 166 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 167 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 168 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 169 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 170 1 : break; 171 : } 172 5 : break; 173 8 : case SPDK_NVME_SCT_MEDIA_ERROR: 174 8 : switch (nvme_sc) { 175 1 : case SPDK_NVME_SC_WRITE_FAULTS: 176 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 177 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 178 1 : *asc = SPDK_SCSI_ASC_PERIPHERAL_DEVICE_WRITE_FAULT; 179 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 180 1 : break; 181 1 : case SPDK_NVME_SC_UNRECOVERED_READ_ERROR: 182 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 183 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 184 1 : *asc = SPDK_SCSI_ASC_UNRECOVERED_READ_ERROR; 185 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 186 1 : break; 187 1 : case SPDK_NVME_SC_GUARD_CHECK_ERROR: 188 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 189 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 190 1 : *asc = SPDK_SCSI_ASC_LOGICAL_BLOCK_GUARD_CHECK_FAILED; 191 1 : *ascq = SPDK_SCSI_ASCQ_LOGICAL_BLOCK_GUARD_CHECK_FAILED; 192 1 : break; 193 1 : case SPDK_NVME_SC_APPLICATION_TAG_CHECK_ERROR: 194 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 195 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 196 1 : *asc = SPDK_SCSI_ASC_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; 197 1 : *ascq = SPDK_SCSI_ASCQ_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED; 198 1 : break; 199 1 : case SPDK_NVME_SC_REFERENCE_TAG_CHECK_ERROR: 200 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 201 1 : *sk = SPDK_SCSI_SENSE_MEDIUM_ERROR; 202 1 : *asc = SPDK_SCSI_ASC_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; 203 1 : *ascq = SPDK_SCSI_ASCQ_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED; 204 1 : break; 205 1 : case SPDK_NVME_SC_COMPARE_FAILURE: 206 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 207 1 : *sk = SPDK_SCSI_SENSE_MISCOMPARE; 208 1 : *asc = SPDK_SCSI_ASC_MISCOMPARE_DURING_VERIFY_OPERATION; 209 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 210 1 : break; 211 1 : case SPDK_NVME_SC_ACCESS_DENIED: 212 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 213 1 : *sk = SPDK_SCSI_SENSE_DATA_PROTECT; 214 1 : *asc = SPDK_SCSI_ASC_ACCESS_DENIED; 215 1 : *ascq = SPDK_SCSI_ASCQ_NO_ACCESS_RIGHTS; 216 1 : break; 217 1 : case SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK: 218 : default: 219 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 220 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 221 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 222 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 223 1 : break; 224 : } 225 8 : break; 226 1 : case SPDK_NVME_SCT_VENDOR_SPECIFIC: 227 : default: 228 1 : *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; 229 1 : *sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST; 230 1 : *asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE; 231 1 : *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; 232 1 : break; 233 : } 234 26 : }