1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SCSI_PERIPHERAL_TYPES_H 17 #define SCSI_PERIPHERAL_TYPES_H 18 /** 19 * @addtogroup ScsiPeripheralDDK 20 * @{ 21 * 22 * @brief Provides ScsiPeripheral DDK types and declares macros, enumerations, and\n 23 * data structures used by the ScsiPeripheral DDK. 24 * 25 * @syscap SystemCapability.Driver.SCSI.Extension 26 * @since 16 27 */ 28 29 /** 30 * @file scsi_peripheral_types.h 31 * 32 * @brief Provides the enums, structs, and macros used in SCSI Peripheral DDK APIs. 33 * 34 * @since 16 35 */ 36 37 #include <stddef.h> 38 #include <stdint.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif /* __cplusplus */ 43 44 /** 45 * @brief The min length of descriptor format sense data: 8. 46 * 47 * @since 16 48 */ 49 #define SCSIPERIPHERAL_MIN_DESCRIPTOR_FORMAT_SENSE 8 50 51 /** 52 * @brief The min length of fixed format sense data: 18. 53 * 54 * @since 16 55 */ 56 #define SCSIPERIPHERAL_MIN_FIXED_FORMAT_SENSE 18 57 58 /** 59 * @brief Defines error codes for SCSI DDK. 60 * 61 * @since 16 62 */ 63 typedef enum { 64 /** @error Permission denied. */ 65 SCSIPERIPHERAL_DDK_NO_PERM = 201, 66 /** @error Invalid parameter. */ 67 SCSIPERIPHERAL_DDK_INVALID_PARAMETER = 401, 68 /** @error The operation is successful. */ 69 SCSIPERIPHERAL_DDK_SUCCESS = 31700000, 70 /** @error Memory-related error, for example, insufficient memory, memory data copy failure,\n 71 * memory data init failure, or memory map failure. 72 */ 73 SCSIPERIPHERAL_DDK_MEMORY_ERROR = 31700001, 74 /** @error Invalid operation. */ 75 SCSIPERIPHERAL_DDK_INVALID_OPERATION = 31700002, 76 /** @error Device I/O operation failed. */ 77 SCSIPERIPHERAL_DDK_IO_ERROR = 31700003, 78 /** @error Transmission timeout. */ 79 SCSIPERIPHERAL_DDK_TIMEOUT = 31700004, 80 /** @error The ddk init error or the ddk not init. */ 81 SCSIPERIPHERAL_DDK_INIT_ERROR = 31700005, 82 /** @error Communication with the SCSI ddk service failed. */ 83 SCSIPERIPHERAL_DDK_SERVICE_ERROR = 31700006, 84 /** @error Device not found. */ 85 SCSIPERIPHERAL_DDK_DEVICE_NOT_FOUND = 31700007, 86 } ScsiPeripheral_DdkErrCode; 87 88 /** 89 * @brief Defines SCSI status for response. 90 * 91 * @since 16 92 */ 93 typedef enum { 94 /** Good condition */ 95 SCSIPERIPHERAL_STATUS_GOOD = 0x00, 96 /** Check condition needed */ 97 SCSIPERIPHERAL_STATUS_CHECK_CONDITION_NEEDED = 0x02, 98 /** Condition met */ 99 SCSIPERIPHERAL_STATUS_CONDITION_MET = 0x04, 100 /** Busy */ 101 SCSIPERIPHERAL_STATUS_BUSY = 0x08, 102 /** Reservation conflict */ 103 SCSIPERIPHERAL_STATUS_RESERVATION_CONFLICT = 0x18, 104 /** Task set full */ 105 SCSIPERIPHERAL_STATUS_TASK_SET_FULL = 0x28, 106 /** ACA active */ 107 SCSIPERIPHERAL_STATUS_ACA_ACTIVE = 0x30, 108 /** Task aborted */ 109 SCSIPERIPHERAL_STATUS_TASK_ABORTED = 0x40, 110 } ScsiPeripheral_Status; 111 112 /** 113 * @brief Opaque SCSI device structure. 114 * 115 * @since 16 116 */ 117 typedef struct ScsiPeripheral_Device ScsiPeripheral_Device; 118 119 /** 120 * @brief Device memory map created by calling <b>OH_ScsiPeripheral_CreateDeviceMemMap</b>.\n 121 * A buffer using the device memory map can provide better performance. 122 * 123 * @since 16 124 */ 125 typedef struct ScsiPeripheral_DeviceMemMap { 126 /** Buffer address. */ 127 uint8_t * const address; 128 /** Buffer size. */ 129 const size_t size; 130 /** Offset of the used buffer. The default value is 0, indicating that there is no offset\n 131 * and the buffer starts from the specified address. 132 */ 133 uint32_t offset; 134 /** Length of the used buffer. By default, the value is equal to the size, indicating that\n 135 * the entire buffer is used. 136 */ 137 uint32_t bufferLength; 138 /** Length of the transferred data. */ 139 uint32_t transferredLength; 140 } ScsiPeripheral_DeviceMemMap; 141 142 /** 143 * @brief Request parameters for read/write. 144 * 145 * @since 16 146 */ 147 typedef struct ScsiPeripheral_IORequest { 148 /** Starting with the logical block. */ 149 uint32_t lbAddress; 150 /** Number of contiguous logical blocks that shall be read. */ 151 uint16_t transferLength; 152 /** Control byte. */ 153 uint8_t control; 154 /** Byte 1 of the CDB. */ 155 uint8_t byte1; 156 /** Byte 6 of the CDB. */ 157 uint8_t byte6; 158 /** Buffer of data transfer. */ 159 ScsiPeripheral_DeviceMemMap *data; 160 /** Timeout(unit: millisec). */ 161 uint32_t timeout; 162 } ScsiPeripheral_IORequest; 163 164 /** 165 * @brief The max length of command descriptor block: 16. 166 * 167 * @since 16 168 */ 169 #define SCSIPERIPHERAL_MAX_CMD_DESC_BLOCK_LEN 16 170 171 /** 172 * @brief Request parameters. 173 * 174 * @since 16 175 */ 176 typedef struct ScsiPeripheral_Request { 177 /** Command descriptor block. */ 178 uint8_t commandDescriptorBlock[SCSIPERIPHERAL_MAX_CMD_DESC_BLOCK_LEN]; 179 /** The length of command descriptor block. */ 180 uint8_t cdbLength; 181 /** Data transfer direction. */ 182 int8_t dataTransferDirection; 183 /** Buffer of data transfer. */ 184 ScsiPeripheral_DeviceMemMap *data; 185 /** Timeout(unit: millisec). */ 186 uint32_t timeout; 187 } ScsiPeripheral_Request; 188 189 /** 190 * @brief The max length of sense data: 252. 191 * 192 * @since 16 193 */ 194 #define SCSIPERIPHERAL_MAX_SENSE_DATA_LEN 252 195 196 /** 197 * @brief Response parameters. 198 * 199 * @since 16 200 */ 201 typedef struct ScsiPeripheral_Response { 202 /** Sense data. */ 203 uint8_t senseData[SCSIPERIPHERAL_MAX_SENSE_DATA_LEN]; 204 /** The status at completion of the call, such as good, busy, or timeout. */ 205 ScsiPeripheral_Status status; 206 /** Shifted, masked scsi status. */ 207 uint8_t maskedStatus; 208 /** Messaging level data (optional). */ 209 uint8_t msgStatus; 210 /** Byte count actually written to sbp. */ 211 uint8_t sbLenWr; 212 /** Errors from host adapter. */ 213 uint16_t hostStatus; 214 /** Errors from software driver. */ 215 uint16_t driverStatus; 216 /** Dxfer_len - actual_transferred. */ 217 int32_t resId; 218 /** Time taken by cmd (unit: millisec). */ 219 uint32_t duration; 220 } ScsiPeripheral_Response; 221 222 /** 223 * @brief SCSI test unit ready request. 224 * 225 * @since 16 226 */ 227 typedef struct ScsiPeripheral_TestUnitReadyRequest { 228 /** Control byte. */ 229 uint8_t control; 230 /** Timeout(unit: millisec). */ 231 uint32_t timeout; 232 } ScsiPeripheral_TestUnitReadyRequest; 233 234 /** 235 * @brief SCSI inquiry request. 236 * 237 * @since 16 238 */ 239 typedef struct ScsiPeripheral_InquiryRequest { 240 /** Page code. */ 241 uint8_t pageCode; 242 /** Allocation length. */ 243 uint16_t allocationLength; 244 /** Control byte. */ 245 uint8_t control; 246 /** Byte 1 of the CDB. */ 247 uint8_t byte1; 248 /** Timeout(unit: millisec). */ 249 uint32_t timeout; 250 } ScsiPeripheral_InquiryRequest; 251 252 /** 253 * @brief The length of vendor identification: 8. 254 * 255 * @since 16 256 */ 257 #define SCSIPERIPHERAL_VENDOR_ID_LEN 8 258 259 /** 260 * @brief The length of product identification: 16. 261 * 262 * @since 16 263 */ 264 #define SCSIPERIPHERAL_PRODUCT_ID_LEN 16 265 266 /** 267 * @brief The length of product revision: 4. 268 * 269 * @since 16 270 */ 271 #define SCSIPERIPHERAL_PRODUCT_REV_LEN 4 272 273 /** 274 * @brief SCSI inquiry data. 275 * 276 * @since 16 277 */ 278 typedef struct ScsiPeripheral_InquiryInfo { 279 /** Peripheral device type. */ 280 uint8_t deviceType; 281 /** Vendor identification. */ 282 char idVendor[SCSIPERIPHERAL_VENDOR_ID_LEN + 1]; 283 /** Product identification. */ 284 char idProduct[SCSIPERIPHERAL_PRODUCT_ID_LEN + 1]; 285 /** Product revision. */ 286 char revProduct[SCSIPERIPHERAL_PRODUCT_REV_LEN + 1]; 287 /** All inquiry data. */ 288 ScsiPeripheral_DeviceMemMap *data; 289 } ScsiPeripheral_InquiryInfo; 290 291 /** 292 * @brief SCSI read capacity request. 293 * 294 * @since 16 295 */ 296 typedef struct ScsiPeripheral_ReadCapacityRequest { 297 /** Logical block address. */ 298 uint32_t lbAddress; 299 /** Control byte. */ 300 uint8_t control; 301 /** Byte 8 of the CDB. */ 302 uint8_t byte8; 303 /** Timeout(unit: millisec). */ 304 uint32_t timeout; 305 } ScsiPeripheral_ReadCapacityRequest; 306 307 /** 308 * @brief SCSI read capacity data. 309 * 310 * @since 16 311 */ 312 typedef struct ScsiPeripheral_CapacityInfo { 313 /** Returned logical block address. */ 314 uint32_t lbAddress; 315 /** Logical block length in bytes. */ 316 uint32_t lbLength; 317 } ScsiPeripheral_CapacityInfo; 318 319 /** 320 * @brief SCSI request sense request. 321 * 322 * @since 16 323 */ 324 typedef struct ScsiPeripheral_RequestSenseRequest { 325 /** Allocation length. */ 326 uint8_t allocationLength; 327 /** Control byte. */ 328 uint8_t control; 329 /** Byte 1 of the CDB. */ 330 uint8_t byte1; 331 /** Timeout(unit: millisec). */ 332 uint32_t timeout; 333 } ScsiPeripheral_RequestSenseRequest; 334 335 /** 336 * @brief Basic sense data of Information、Command-specific information、Sense key specific. 337 * 338 * @since 16 339 */ 340 typedef struct ScsiPeripheral_BasicSenseInfo { 341 /** Response code. */ 342 uint8_t responseCode; 343 /** Information valid bit. */ 344 bool valid; 345 /** Information sense data descriptor. */ 346 uint64_t information; 347 /** Command-specific information sense data descriptor. */ 348 uint64_t commandSpecific; 349 /** Sense key specific valid bit. */ 350 bool sksv; 351 /** Sense key specific sense data descriptor. */ 352 uint32_t senseKeySpecific; 353 } ScsiPeripheral_BasicSenseInfo; 354 355 /** 356 * @brief SCSI verify request. 357 * 358 * @since 16 359 */ 360 typedef struct ScsiPeripheral_VerifyRequest { 361 /** Starting with the logical block. */ 362 uint32_t lbAddress; 363 /** Number of contiguous logical blocks that shall be verify. */ 364 uint16_t verificationLength; 365 /** Control byte. */ 366 uint8_t control; 367 /** Byte 1 of the CDB. */ 368 uint8_t byte1; 369 /** Byte 6 of the CDB. */ 370 uint8_t byte6; 371 /** Timeout(unit: millisec). */ 372 uint32_t timeout; 373 } ScsiPeripheral_VerifyRequest; 374 #ifdef __cplusplus 375 } 376 /** @} */ 377 #endif /* __cplusplus */ 378 #endif // SCSI_PERIPHERAL_TYPES_H