]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/UefiScsiLib.h
d721735b46f2e5c18b3131051c0150a362f17809
[mirror_edk2.git] / MdePkg / Include / Library / UefiScsiLib.h
1 /** @file
2
3 Provides the functions to submit Scsi commands defined in SCSI-2 specification for scsi device.
4
5 Copyright (c) 2006 - 2008, Intel Corporation<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _SCSI_LIB_H_
17 #define _SCSI_LIB_H_
18
19 #include <Protocol/ScsiIo.h>
20
21 //
22 // the time unit is 100ns, since the SCSI I/O defines timeout in 100ns unit.
23 //
24 #define EFI_SCSI_STALL_1_MICROSECOND 10
25 #define EFI_SCSI_STALL_1_MILLISECOND 10000
26 #define EFI_SCSI_STALL_1_SECOND 10000000
27
28 ///
29 /// this macro cannot be directly used by the gBS->Stall(),
30 /// since the value output by this macro is in 100ns unit,
31 /// not 1us unit (1us = 1000ns)
32 ///
33 #define EFI_SCSI_STALL_SECONDS(a) ((a) * EFI_SCSI_STALL_1_SECOND)
34
35
36 /**
37 Execute Test Unit Ready SCSI command on a specific SCSI target.
38
39 Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.
40 If Timeout is zero, then this function waits indefinitely for the command to complete.
41 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
42 If ScsiIo is NULL, then ASSERT().
43 If SenseDataLength is NULL, then ASSERT().
44 If HostAdapterStatus is NULL, then ASSERT().
45 If TargetStatus is NULL, then ASSERT().
46
47
48 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
49 for the specific SCSI target.
50 @param[in] Timeout The timeout in 100 ns units to use for the execution
51 of this SCSI Request Packet. A Timeout value of
52 zero means that this function will wait indefinitely
53 for the SCSI Request Packet to execute. If Timeout
54 is greater than zero, then this function will return
55 EFI_TIMEOUT if the time required to execute the SCSI
56 Request Packet is greater than Timeout.
57 @param[in, out] SenseData A pointer to sense data that was generated by
58 the execution of the SCSI Request Packet. This
59 buffer must be allocated by the caller.
60 If SenseDataLength is 0, then this parameter is
61 optional and may be NULL.
62 @param[in, out] SenseDataLength On input, a pointer to the length in bytes of
63 the SenseData buffer. On output, a poiinter to
64 the number of bytes written to the SenseData buffer.
65 @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces
66 the SCSI bus containing the SCSI target specified by
67 ScsiIo when the SCSI Request Packet was executed.
68 See the EFI SCSI I/O Protocol in the UEFI Specification
69 for details on the possible return values.
70 @param[out] TargetStatus The status returned by the SCSI target specified
71 by ScsiIo when the SCSI Request Packat was executed
72 on the SCSI Host Controller. See the EFI SCSI I/O
73 Protocol in the UEFI Specification for details on
74 the possible return values.
75
76 @retval EFI_SUCCESS The command was executed successfully.
77 See HostAdapterStatus, TargetStatus, SenseDataLength,
78 and SenseData in that order for additional status
79 information.
80 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
81 there are too many SCSI Command Packets already
82 queued. The SCSI Request Packet was not sent, so
83 no additional status information is available.
84 The caller may retry again later.
85 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
86 SCSI Request Packet. See HostAdapterStatus,
87 TargetStatus, SenseDataLength, and SenseData in that
88 order for additional status information.
89 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
90 is not supported by the SCSI initiator(i.e., SCSI
91 Host Controller). The SCSI Request Packet was not
92 sent, so no additional status information is available.
93 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
94 Packet to execute. See HostAdapterStatus, TargetStatus,
95 SenseDataLength, and SenseData in that order for
96 additional status information.
97 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
98 but the entire DataBuffer could not be transferred.
99 The actual number of bytes transferred is returned
100 in InTransferLength.
101
102 **/
103 EFI_STATUS
104 EFIAPI
105 ScsiTestUnitReadyCommand (
106 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
107 IN UINT64 Timeout,
108 IN OUT VOID *SenseData, OPTIONAL
109 IN OUT UINT8 *SenseDataLength,
110 OUT UINT8 *HostAdapterStatus,
111 OUT UINT8 *TargetStatus
112 );
113
114
115 /**
116 Execute Inquiry SCSI command on a specific SCSI target.
117
118 Executes the Inquiry command on the SCSI target specified by ScsiIo.
119 If Timeout is zero, then this function waits indefinitely for the command to complete.
120 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
121 If ScsiIo is NULL, then ASSERT().
122 If SenseDataLength is NULL, then ASSERT().
123 If HostAdapterStatus is NULL, then ASSERT().
124 If TargetStatus is NULL, then ASSERT().
125 If InquiryDataLength is NULL, then ASSERT().
126
127 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
128 for the specific SCSI target.
129 @param[in] Timeout The timeout in 100 ns units to use for the
130 execution of this SCSI Request Packet. A Timeout
131 value of zero means that this function will wait
132 indefinitely for the SCSI Request Packet to execute.
133 If Timeout is greater than zero, then this function
134 will return EFI_TIMEOUT if the time required to
135 execute the SCSI Request Packet is greater than Timeout.
136 @param[in, out] SenseData A pointer to sense data that was generated
137 by the execution of the SCSI Request Packet.
138 This buffer must be allocated by the caller.
139 If SenseDataLength is 0, then this parameter
140 is optional and may be NULL.
141 @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.
142 On output, the number of bytes written to the SenseData buffer.
143 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
144 produces the SCSI bus containing the SCSI
145 target specified by ScsiIo when the SCSI
146 Request Packet was executed. See the EFI
147 SCSI I/O Protocol in the UEFI Specification
148 for details on the possible return values.
149 @param[out] TargetStatus The status returned by the SCSI target specified
150 by ScsiIo when the SCSI Request Packat was
151 executed on the SCSI Host Controller.
152 See the EFI SCSI I/O Protocol in the UEFI
153 Specification for details on the possible
154 return values.
155 @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated
156 by the execution of the SCSI Request Packet.
157 This buffer must be allocated by the caller.
158 If InquiryDataLength is 0, then this parameter
159 is optional and may be NULL.
160 @param[in, out] InquiryDataLength On input, a pointer to the length in bytes
161 of the InquiryDataBuffer buffer.
162 On output, a pointer to the number of bytes
163 written to the InquiryDataBuffer buffer.
164 @param[in] EnableVitalProductData If TRUE, then the supported vital product
165 data is returned in InquiryDataBuffer.
166 If FALSE, then the standard inquiry data is
167 returned in InquiryDataBuffer.
168
169 @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,
170 TargetStatus, SenseDataLength, and SenseData in that order
171 for additional status information.
172 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire
173 InquiryDataBuffer could not be transferred. The actual
174 number of bytes transferred is returned in InquiryDataLength.
175 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there
176 are too many SCSI Command Packets already queued.
177 The SCSI Request Packet was not sent, so no additional
178 status information is available. The caller may retry again later.
179 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI
180 Request Packet. See HostAdapterStatus, TargetStatus,
181 SenseDataLength, and SenseData in that order for additional
182 status information.
183 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not
184 supported by the SCSI initiator(i.e., SCSI Host Controller).
185 The SCSI Request Packet was not sent, so no additional
186 status information is available.
187 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request
188 Packet to execute. See HostAdapterStatus, TargetStatus,
189 SenseDataLength, and SenseData in that order for
190 additional status information.
191
192 **/
193 EFI_STATUS
194 EFIAPI
195 ScsiInquiryCommand (
196 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
197 IN UINT64 Timeout,
198 IN OUT VOID *SenseData, OPTIONAL
199 IN OUT UINT8 *SenseDataLength,
200 OUT UINT8 *HostAdapterStatus,
201 OUT UINT8 *TargetStatus,
202 IN OUT VOID *InquiryDataBuffer, OPTIONAL
203 IN OUT UINT32 *InquiryDataLength,
204 IN BOOLEAN EnableVitalProductData
205 );
206
207
208 /**
209 Execute Mode Sense(10) SCSI command on a specific SCSI target.
210
211 Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.
212 If Timeout is zero, then this function waits indefinitely for the command to complete.
213 If Timeout is greater than zero, then the command is executed and will timeout
214 after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters
215 are used to construct the CDB for this SCSI command.
216 If ScsiIo is NULL, then ASSERT().
217 If SenseDataLength is NULL, then ASSERT().
218 If HostAdapterStatus is NULL, then ASSERT().
219 If TargetStatus is NULL, then ASSERT().
220 If DataLength is NULL, then ASSERT().
221
222
223 @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance
224 for the specific SCSI target.
225 @param[in] Timeout The timeout in 100 ns units to use for the
226 execution of this SCSI Request Packet. A Timeout
227 value of zero means that this function will wait
228 indefinitely for the SCSI Request Packet to execute.
229 If Timeout is greater than zero, then this function
230 will return EFI_TIMEOUT if the time required to
231 execute the SCSI Request Packet is greater than Timeout.
232 @param[in,out] SenseData A pointer to sense data that was generated
233 by the execution of the SCSI Request Packet.
234 This buffer must be allocated by the caller.
235 If SenseDataLength is 0, then this parameter
236 is optional and may be NULL.
237 @param[in,out] SenseDataLength On input, the length in bytes of the SenseData buffer.
238 On output, the number of bytes written to the SenseData buffer.
239 @param[out] HostAdapterStatus The status of the SCSI Host Controller that
240 produces the SCSI bus containing the SCSI target
241 specified by ScsiIo when the SCSI Request Packet
242 was executed. See the EFI SCSI I/O Protocol in the
243 UEFI Specification for details on the possible
244 return values.
245 @param[out] TargetStatus The status returned by the SCSI target specified
246 by ScsiIo when the SCSI Request Packat was executed
247 on the SCSI Host Controller. See the EFI SCSI
248 I/O Protocol in the UEFI Specification for details
249 on the possible return values.
250 @param[in,out] DataBuffer A pointer to data that was generated by the
251 execution of the SCSI Request Packet. This
252 buffer must be allocated by the caller. If
253 DataLength is 0, then this parameter is optional
254 and may be NULL.
255 @param[in,out] DataLength On input, a pointer to the length in bytes of
256 the DataBuffer buffer. On output, a pointer
257 to the number of bytes written to the DataBuffer
258 buffer.
259 @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.
260 @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command.
261 @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command.
262
263 @retval EFI_SUCCESS The command was executed successfully.
264 See HostAdapterStatus, TargetStatus, SenseDataLength,
265 and SenseData in that order for additional status information.
266 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the
267 entire DataBuffer could not be transferred.
268 The actual number of bytes transferred is returned
269 in DataLength.
270 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
271 there are too many SCSI Command Packets already queued.
272 The SCSI Request Packet was not sent, so no additional
273 status information is available. The caller may retry
274 again later.
275 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
276 SCSI Request Packet. See HostAdapterStatus, TargetStatus,
277 SenseDataLength, and SenseData in that order for
278 additional status information.
279 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
280 is not supported by the SCSI initiator(i.e., SCSI
281 Host Controller). The SCSI Request Packet was not
282 sent, so no additional status information is available.
283 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
284 Request Packet to execute. See HostAdapterStatus,
285 TargetStatus, SenseDataLength, and SenseData in that
286 order for additional status information.
287
288 **/
289 EFI_STATUS
290 EFIAPI
291 ScsiModeSense10Command (
292 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
293 IN UINT64 Timeout,
294 IN OUT VOID *SenseData, OPTIONAL
295 IN OUT UINT8 *SenseDataLength,
296 OUT UINT8 *HostAdapterStatus,
297 OUT UINT8 *TargetStatus,
298 IN OUT VOID *DataBuffer, OPTIONAL
299 IN OUT UINT32 *DataLength,
300 IN UINT8 DBDField, OPTIONAL
301 IN UINT8 PageControl,
302 IN UINT8 PageCode
303 );
304
305
306
307 /**
308 Execute Request Sense SCSI command on a specific SCSI target.
309
310 Executes the Request Sense command on the SCSI target specified by ScsiIo.
311 If Timeout is zero, then this function waits indefinitely for the command to complete.
312 If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.
313 If ScsiIo is NULL, then ASSERT().
314 If SenseDataLength is NULL, then ASSERT().
315 If HostAdapterStatus is NULL, then ASSERT().
316 If TargetStatus is NULL, then ASSERT().
317
318 @param[in] ScsiIo A pointer to SCSI IO protocol.
319 @param[in] Timeout The length of timeout period.
320 @param[in, out] SenseData A pointer to output sense data.
321 @param[in, out] SenseDataLength The length of output sense data.
322 @param[out] HostAdapterStatus The status of Host Adapter.
323 @param[out] TargetStatus The status of the target.
324
325 @retval EFI_SUCCESS Command is executed successfully.
326 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are
327 too many SCSI Command Packets already queued.
328 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
329 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
330 the SCSI initiator(i.e., SCSI Host Controller)
331 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
332
333 **/
334 EFI_STATUS
335 EFIAPI
336 ScsiRequestSenseCommand (
337 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
338 IN UINT64 Timeout,
339 IN OUT VOID *SenseData, OPTIONAL
340 IN OUT UINT8 *SenseDataLength,
341 OUT UINT8 *HostAdapterStatus,
342 OUT UINT8 *TargetStatus
343 );
344
345
346 /**
347 Execute Read Capacity SCSI command on a specific SCSI target.
348
349 Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.
350 If Timeout is zero, then this function waits indefinitely for the command to complete.
351 If Timeout is greater than zero, then the command is executed and will timeout after
352 Timeout 100 ns units. The PMI parameter is used to construct the CDB for this SCSI command.
353 If ScsiIo is NULL, then ASSERT().
354 If SenseDataLength is NULL, then ASSERT().
355 If HostAdapterStatus is NULL, then ASSERT().
356 If TargetStatus is NULL, then ASSERT().
357 If DataLength is NULL, then ASSERT().
358
359 @param[in] ScsiIo A pointer to SCSI IO protocol.
360 @param[in] Timeout The length of timeout period.
361 @param[in, out] SenseData A pointer to output sense data.
362 @param[in, out] SenseDataLength The length of output sense data.
363 @param[out] HostAdapterStatus The status of Host Adapter.
364 @param[out] TargetStatus The status of the target.
365 @param[in, out] DataBuffer A pointer to a data buffer.
366 @param[in, out] DataLength The length of data buffer.
367 @param[in] PMI Partial medium indicator.
368
369 @retval EFI_SUCCESS Command is executed successfully.
370 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
371 not be transferred. The actual number of bytes transferred is returned in DataLength.
372 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
373 SCSI Command Packets already queued.
374 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
375 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
376 the SCSI initiator(i.e., SCSI Host Controller)
377 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
378
379 **/
380 EFI_STATUS
381 EFIAPI
382 ScsiReadCapacityCommand (
383 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
384 IN UINT64 Timeout,
385 IN OUT VOID *SenseData, OPTIONAL
386 IN OUT UINT8 *SenseDataLength,
387 OUT UINT8 *HostAdapterStatus,
388 OUT UINT8 *TargetStatus,
389 IN OUT VOID *DataBuffer, OPTIONAL
390 IN OUT UINT32 *DataLength,
391 IN BOOLEAN PMI
392 );
393
394
395 /**
396 Execute Read(10) SCSI command on a specific SCSI target.
397
398 Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.
399 If Timeout is zero, then this function waits indefinitely for the command to complete.
400 If Timeout is greater than zero, then the command is executed and will timeout
401 after Timeout 100 ns units. The StartLba and SectorSize parameters are used to
402 construct the CDB for this SCSI command.
403 If ScsiIo is NULL, then ASSERT().
404 If SenseDataLength is NULL, then ASSERT().
405 If HostAdapterStatus is NULL, then ASSERT().
406 If TargetStatus is NULL, then ASSERT().
407 If DataLength is NULL, then ASSERT().
408
409
410 @param[in] ScsiIo A pointer to SCSI IO protocol.
411 @param[in] Timeout The length of timeout period.
412 @param[in, out] SenseData A pointer to output sense data.
413 @param[in, out] SenseDataLength The length of output sense data.
414 @param[out] HostAdapterStatus The status of Host Adapter.
415 @param[out] TargetStatus The status of the target.
416 @param[in, out] DataBuffer Read 10 command data.
417 @param[in, out] DataLength The length of data buffer.
418 @param[in] StartLba The start address of LBA.
419 @param[in] SectorSize The sector size.
420
421 @retval EFI_SUCCESS Command is executed successfully.
422 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
423 not be transferred. The actual number of bytes transferred is returned in DataLength.
424 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
425 SCSI Command Packets already queued.
426 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
427 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
428 the SCSI initiator(i.e., SCSI Host Controller)
429 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
430
431 **/
432 EFI_STATUS
433 EFIAPI
434 ScsiRead10Command (
435 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
436 IN UINT64 Timeout,
437 IN OUT VOID *SenseData, OPTIONAL
438 IN OUT UINT8 *SenseDataLength,
439 OUT UINT8 *HostAdapterStatus,
440 OUT UINT8 *TargetStatus,
441 IN OUT VOID *DataBuffer, OPTIONAL
442 IN OUT UINT32 *DataLength,
443 IN UINT32 StartLba,
444 IN UINT32 SectorSize
445 );
446
447
448 /**
449 Execute Write(10) SCSI command on a specific SCSI target.
450
451 Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.
452 If Timeout is zero, then this function waits indefinitely for the command to complete.
453 If Timeout is greater than zero, then the command is executed and will timeout after
454 Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct
455 the CDB for this SCSI command.
456 If ScsiIo is NULL, then ASSERT().
457 If SenseDataLength is NULL, then ASSERT().
458 If HostAdapterStatus is NULL, then ASSERT().
459 If TargetStatus is NULL, then ASSERT().
460 If DataLength is NULL, then ASSERT().
461
462 @param[in] ScsiIo SCSI IO Protocol to use
463 @param[in] Timeout The length of timeout period.
464 @param[in, out] SenseData A pointer to output sense data.
465 @param[in, out] SenseDataLength The length of output sense data.
466 @param[out] HostAdapterStatus The status of Host Adapter.
467 @param[out] TargetStatus The status of the target.
468 @param[in, out] DataBuffer A pointer to a data buffer.
469 @param[in, out] DataLength The length of data buffer.
470 @param[in] StartLba The start address of LBA.
471 @param[in] SectorSize The sector size.
472
473 @retval EFI_SUCCESS Command is executed successfully.
474 @retval EFI_WARN_BUFFER_TOO_SMALL The SCSI Request Packet was executed, but the entire DataBuffer could
475 not be transferred. The actual number of bytes transferred is returned in DataLength.
476 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
477 SCSI Command Packets already queued.
478 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.
479 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by
480 the SCSI initiator(i.e., SCSI Host Controller)
481 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
482
483 **/
484 EFI_STATUS
485 EFIAPI
486 ScsiWrite10Command (
487 IN EFI_SCSI_IO_PROTOCOL *ScsiIo,
488 IN UINT64 Timeout,
489 IN OUT VOID *SenseData, OPTIONAL
490 IN OUT UINT8 *SenseDataLength,
491 OUT UINT8 *HostAdapterStatus,
492 OUT UINT8 *TargetStatus,
493 IN OUT VOID *DataBuffer, OPTIONAL
494 IN OUT UINT32 *DataLength,
495 IN UINT32 StartLba,
496 IN UINT32 SectorSize
497 );
498
499
500 #endif