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