]>
Commit | Line | Data |
---|---|---|
bf231ea6 A |
1 | /** @file\r |
2 | UEFI SCSI Library implementation\r | |
3 | \r | |
dfc5aca1 | 4 | Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r |
bf231ea6 A |
5 | All rights reserved. This program and the accompanying materials \r |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | **/\r | |
a02e796b | 14 | \r |
bf231ea6 | 15 | \r |
60c93673 | 16 | #include <Uefi.h>\r |
306431f7 | 17 | #include <Library/DebugLib.h>\r |
172ea7c7 | 18 | #include <Library/UefiScsiLib.h>\r |
a02e796b | 19 | #include <Library/BaseMemoryLib.h>\r |
d5954c61 | 20 | \r |
a3589760 | 21 | #include <IndustryStandard/Scsi.h>\r |
d5954c61 | 22 | \r |
23 | \r | |
24 | //\r | |
25 | // Max bytes needed to represent ID of a SCSI device\r | |
26 | //\r | |
dfc5aca1 | 27 | #define EFI_SCSI_TARGET_MAX_BYTES (0x10)\r |
d5954c61 | 28 | \r |
29 | //\r | |
30 | // bit5..7 are for Logical unit number\r | |
31 | // 11100000b (0xe0)\r | |
32 | //\r | |
52cd71dc | 33 | #define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0\r |
d5954c61 | 34 | \r |
35 | //\r | |
36 | // Scsi Command Length six or ten\r | |
37 | //\r | |
52cd71dc LG |
38 | #define EFI_SCSI_OP_LENGTH_SIX 0x6\r |
39 | #define EFI_SCSI_OP_LENGTH_TEN 0xa\r | |
bf231ea6 | 40 | \r |
b91d5eca | 41 | \r |
b91d5eca | 42 | \r |
d5954c61 | 43 | /**\r |
44 | Execute Test Unit Ready SCSI command on a specific SCSI target.\r | |
b91d5eca | 45 | \r |
d5954c61 | 46 | Executes the Test Unit Ready command on the SCSI target specified by ScsiIo.\r |
47 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
48 | If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.\r | |
49 | If ScsiIo is NULL, then ASSERT().\r | |
50 | If SenseDataLength is NULL, then ASSERT().\r | |
52cd71dc LG |
51 | If HostAdapterStatus is NULL, then ASSERT().\r |
52 | If TargetStatus is NULL, then ASSERT().\r | |
a3589760 | 53 | \r |
d5954c61 | 54 | \r |
55 | @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance\r | |
56 | for the specific SCSI target.\r | |
57 | @param[in] Timeout The timeout in 100 ns units to use for the execution\r | |
58 | of this SCSI Request Packet. A Timeout value of\r | |
59 | zero means that this function will wait indefinitely\r | |
60 | for the SCSI Request Packet to execute. If Timeout\r | |
61 | is greater than zero, then this function will return\r | |
62 | EFI_TIMEOUT if the time required to execute the SCSI\r | |
63 | Request Packet is greater than Timeout.\r | |
64 | @param[in, out] SenseData A pointer to sense data that was generated by\r | |
65 | the execution of the SCSI Request Packet. This\r | |
66 | buffer must be allocated by the caller.\r | |
67 | If SenseDataLength is 0, then this parameter is\r | |
68 | optional and may be NULL.\r | |
69 | @param[in, out] SenseDataLength On input, a pointer to the length in bytes of\r | |
9ccbe812 | 70 | the SenseData buffer. On output, a pointer to\r |
d5954c61 | 71 | the number of bytes written to the SenseData buffer. \r |
72 | @param[out] HostAdapterStatus The status of the SCSI Host Controller that produces\r | |
73 | the SCSI bus containing the SCSI target specified by\r | |
74 | ScsiIo when the SCSI Request Packet was executed.\r | |
75 | See the EFI SCSI I/O Protocol in the UEFI Specification\r | |
76 | for details on the possible return values.\r | |
77 | @param[out] TargetStatus The status returned by the SCSI target specified\r | |
9ccbe812 | 78 | by ScsiIo when the SCSI Request Packet was executed\r |
d5954c61 | 79 | on the SCSI Host Controller. See the EFI SCSI I/O\r |
80 | Protocol in the UEFI Specification for details on\r | |
81 | the possible return values. \r | |
82 | \r | |
83 | @retval EFI_SUCCESS The command was executed successfully.\r | |
84 | See HostAdapterStatus, TargetStatus, SenseDataLength,\r | |
85 | and SenseData in that order for additional status\r | |
86 | information.\r | |
87 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r | |
88 | there are too many SCSI Command Packets already\r | |
89 | queued. The SCSI Request Packet was not sent, so\r | |
90 | no additional status information is available.\r | |
91 | The caller may retry again later.\r | |
92 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send\r | |
93 | SCSI Request Packet. See HostAdapterStatus,\r | |
94 | TargetStatus, SenseDataLength, and SenseData in that\r | |
95 | order for additional status information.\r | |
96 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r | |
97 | is not supported by the SCSI initiator(i.e., SCSI\r | |
98 | Host Controller). The SCSI Request Packet was not\r | |
99 | sent, so no additional status information is available.\r | |
100 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request\r | |
101 | Packet to execute. See HostAdapterStatus, TargetStatus,\r | |
102 | SenseDataLength, and SenseData in that order for\r | |
103 | additional status information.\r | |
a3589760 | 104 | \r |
bf231ea6 | 105 | **/\r |
a02e796b | 106 | EFI_STATUS\r |
373b5cf9 | 107 | EFIAPI\r |
d35be2a4 | 108 | ScsiTestUnitReadyCommand (\r |
d5954c61 | 109 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
110 | IN UINT64 Timeout,\r | |
111 | IN OUT VOID *SenseData, OPTIONAL\r | |
112 | IN OUT UINT8 *SenseDataLength,\r | |
113 | OUT UINT8 *HostAdapterStatus,\r | |
114 | OUT UINT8 *TargetStatus\r | |
a02e796b | 115 | )\r |
a02e796b | 116 | {\r |
117 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 118 | UINT64 Lun;\r |
119 | UINT8 *Target;\r | |
120 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 121 | EFI_STATUS Status;\r |
52cd71dc | 122 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];\r |
a02e796b | 123 | \r |
8069d49e LG |
124 | ASSERT (SenseDataLength != NULL);\r |
125 | ASSERT (HostAdapterStatus != NULL);\r | |
126 | ASSERT (TargetStatus != NULL);\r | |
d5954c61 | 127 | ASSERT (ScsiIo != NULL);\r |
a02e796b | 128 | \r |
129 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r | |
52cd71dc | 130 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r |
a02e796b | 131 | \r |
132 | CommandPacket.Timeout = Timeout;\r | |
133 | CommandPacket.InDataBuffer = NULL;\r | |
134 | CommandPacket.InTransferLength= 0;\r | |
135 | CommandPacket.OutDataBuffer = NULL;\r | |
136 | CommandPacket.OutTransferLength= 0;\r | |
137 | CommandPacket.SenseData = SenseData;\r | |
138 | CommandPacket.Cdb = Cdb;\r | |
139 | //\r | |
140 | // Fill Cdb for Test Unit Ready Command\r | |
141 | //\r | |
6b3ecf5c | 142 | Target = &TargetArray[0];\r |
143 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
144 | \r | |
a02e796b | 145 | Cdb[0] = EFI_SCSI_OP_TEST_UNIT_READY;\r |
6b3ecf5c | 146 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
52cd71dc | 147 | CommandPacket.CdbLength = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r |
a02e796b | 148 | CommandPacket.SenseDataLength = *SenseDataLength;\r |
149 | \r | |
150 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
151 | \r | |
152 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
153 | *TargetStatus = CommandPacket.TargetStatus;\r | |
154 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
155 | \r | |
156 | return Status;\r | |
157 | }\r | |
158 | \r | |
bf231ea6 | 159 | \r |
a3589760 | 160 | /**\r |
d5954c61 | 161 | Execute Inquiry SCSI command on a specific SCSI target.\r |
b91d5eca | 162 | \r |
d5954c61 | 163 | Executes the Inquiry command on the SCSI target specified by ScsiIo.\r |
164 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
165 | If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.\r | |
166 | If ScsiIo is NULL, then ASSERT().\r | |
52cd71dc LG |
167 | If SenseDataLength is NULL, then ASSERT().\r |
168 | If HostAdapterStatus is NULL, then ASSERT().\r | |
169 | If TargetStatus is NULL, then ASSERT().\r | |
170 | If InquiryDataLength is NULL, then ASSERT().\r | |
a3589760 | 171 | \r |
d5954c61 | 172 | @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance\r |
173 | for the specific SCSI target.\r | |
174 | @param[in] Timeout The timeout in 100 ns units to use for the\r | |
175 | execution of this SCSI Request Packet. A Timeout\r | |
176 | value of zero means that this function will wait\r | |
177 | indefinitely for the SCSI Request Packet to execute.\r | |
178 | If Timeout is greater than zero, then this function\r | |
179 | will return EFI_TIMEOUT if the time required to\r | |
180 | execute the SCSI Request Packet is greater than Timeout.\r | |
181 | @param[in, out] SenseData A pointer to sense data that was generated\r | |
182 | by the execution of the SCSI Request Packet.\r | |
183 | This buffer must be allocated by the caller.\r | |
184 | If SenseDataLength is 0, then this parameter\r | |
185 | is optional and may be NULL.\r | |
186 | @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.\r | |
187 | On output, the number of bytes written to the SenseData buffer. \r | |
188 | @param[out] HostAdapterStatus The status of the SCSI Host Controller that\r | |
189 | produces the SCSI bus containing the SCSI\r | |
190 | target specified by ScsiIo when the SCSI\r | |
191 | Request Packet was executed. See the EFI\r | |
192 | SCSI I/O Protocol in the UEFI Specification\r | |
193 | for details on the possible return values.\r | |
194 | @param[out] TargetStatus The status returned by the SCSI target specified\r | |
070a76b1 | 195 | by ScsiIo when the SCSI Request Packet was\r |
d5954c61 | 196 | executed on the SCSI Host Controller.\r |
197 | See the EFI SCSI I/O Protocol in the UEFI\r | |
198 | Specification for details on the possible\r | |
199 | return values. \r | |
200 | @param[in, out] InquiryDataBuffer A pointer to inquiry data that was generated\r | |
201 | by the execution of the SCSI Request Packet.\r | |
202 | This buffer must be allocated by the caller.\r | |
203 | If InquiryDataLength is 0, then this parameter\r | |
204 | is optional and may be NULL. \r | |
205 | @param[in, out] InquiryDataLength On input, a pointer to the length in bytes\r | |
206 | of the InquiryDataBuffer buffer.\r | |
207 | On output, a pointer to the number of bytes\r | |
208 | written to the InquiryDataBuffer buffer.\r | |
209 | @param[in] EnableVitalProductData If TRUE, then the supported vital product\r | |
210 | data is returned in InquiryDataBuffer.\r | |
211 | If FALSE, then the standard inquiry data is\r | |
212 | returned in InquiryDataBuffer. \r | |
213 | \r | |
214 | @retval EFI_SUCCESS The command was executed successfully. See HostAdapterStatus,\r | |
215 | TargetStatus, SenseDataLength, and SenseData in that order\r | |
216 | for additional status information.\r | |
217 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire\r | |
218 | InquiryDataBuffer could not be transferred. The actual\r | |
219 | number of bytes transferred is returned in InquiryDataLength.\r | |
220 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there\r | |
221 | are too many SCSI Command Packets already queued.\r | |
222 | The SCSI Request Packet was not sent, so no additional\r | |
223 | status information is available. The caller may retry again later.\r | |
224 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI\r | |
225 | Request Packet. See HostAdapterStatus, TargetStatus,\r | |
226 | SenseDataLength, and SenseData in that order for additional\r | |
227 | status information.\r | |
228 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not\r | |
229 | supported by the SCSI initiator(i.e., SCSI Host Controller).\r | |
230 | The SCSI Request Packet was not sent, so no additional\r | |
231 | status information is available.\r | |
232 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request\r | |
233 | Packet to execute. See HostAdapterStatus, TargetStatus,\r | |
234 | SenseDataLength, and SenseData in that order for\r | |
235 | additional status information.\r | |
a3589760 | 236 | \r |
bf231ea6 | 237 | **/\r |
a02e796b | 238 | EFI_STATUS\r |
373b5cf9 | 239 | EFIAPI\r |
d35be2a4 | 240 | ScsiInquiryCommand (\r |
d5954c61 | 241 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
242 | IN UINT64 Timeout,\r | |
243 | IN OUT VOID *SenseData, OPTIONAL\r | |
244 | IN OUT UINT8 *SenseDataLength,\r | |
245 | OUT UINT8 *HostAdapterStatus,\r | |
246 | OUT UINT8 *TargetStatus,\r | |
247 | IN OUT VOID *InquiryDataBuffer, OPTIONAL\r | |
248 | IN OUT UINT32 *InquiryDataLength,\r | |
249 | IN BOOLEAN EnableVitalProductData\r | |
a02e796b | 250 | )\r |
a02e796b | 251 | {\r |
252 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 253 | UINT64 Lun;\r |
254 | UINT8 *Target;\r | |
255 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 256 | EFI_STATUS Status;\r |
52cd71dc | 257 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];\r |
a02e796b | 258 | \r |
8069d49e LG |
259 | ASSERT (SenseDataLength != NULL);\r |
260 | ASSERT (HostAdapterStatus != NULL);\r | |
261 | ASSERT (TargetStatus != NULL);\r | |
262 | ASSERT (InquiryDataLength != NULL);\r | |
d5954c61 | 263 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 264 | \r |
a02e796b | 265 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 266 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r |
a02e796b | 267 | \r |
268 | CommandPacket.Timeout = Timeout;\r | |
269 | CommandPacket.InDataBuffer = InquiryDataBuffer;\r | |
270 | CommandPacket.InTransferLength= *InquiryDataLength;\r | |
271 | CommandPacket.SenseData = SenseData;\r | |
272 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
273 | CommandPacket.Cdb = Cdb;\r | |
274 | \r | |
6b3ecf5c | 275 | Target = &TargetArray[0];\r |
276 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
277 | \r | |
a02e796b | 278 | Cdb[0] = EFI_SCSI_OP_INQUIRY;\r |
6b3ecf5c | 279 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
a02e796b | 280 | if (EnableVitalProductData) {\r |
281 | Cdb[1] |= 0x01;\r | |
282 | }\r | |
283 | \r | |
284 | if (*InquiryDataLength > 0xff) {\r | |
285 | *InquiryDataLength = 0xff;\r | |
286 | }\r | |
287 | \r | |
288 | Cdb[4] = (UINT8) (*InquiryDataLength);\r | |
52cd71dc | 289 | CommandPacket.CdbLength = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r |
a02e796b | 290 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r |
291 | \r | |
292 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
293 | \r | |
294 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
295 | *TargetStatus = CommandPacket.TargetStatus;\r | |
296 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
297 | *InquiryDataLength = CommandPacket.InTransferLength;\r | |
298 | \r | |
299 | return Status;\r | |
300 | }\r | |
301 | \r | |
bf231ea6 | 302 | \r |
a3589760 | 303 | /**\r |
d5954c61 | 304 | Execute Mode Sense(10) SCSI command on a specific SCSI target.\r |
305 | \r | |
306 | Executes the SCSI Mode Sense(10) command on the SCSI target specified by ScsiIo.\r | |
307 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
308 | If Timeout is greater than zero, then the command is executed and will timeout\r | |
309 | after Timeout 100 ns units. The DBDField, PageControl, and PageCode parameters\r | |
310 | are used to construct the CDB for this SCSI command.\r | |
311 | If ScsiIo is NULL, then ASSERT().\r | |
52cd71dc LG |
312 | If SenseDataLength is NULL, then ASSERT().\r |
313 | If HostAdapterStatus is NULL, then ASSERT().\r | |
314 | If TargetStatus is NULL, then ASSERT().\r | |
315 | If DataLength is NULL, then ASSERT().\r | |
a3589760 | 316 | \r |
d5954c61 | 317 | \r |
318 | @param[in] ScsiIo A pointer to the SCSI I/O Protocol instance\r | |
319 | for the specific SCSI target.\r | |
320 | @param[in] Timeout The timeout in 100 ns units to use for the\r | |
321 | execution of this SCSI Request Packet. A Timeout\r | |
322 | value of zero means that this function will wait\r | |
323 | indefinitely for the SCSI Request Packet to execute.\r | |
324 | If Timeout is greater than zero, then this function\r | |
325 | will return EFI_TIMEOUT if the time required to\r | |
326 | execute the SCSI Request Packet is greater than Timeout.\r | |
6089ba62 | 327 | @param[in, out] SenseData A pointer to sense data that was generated\r |
d5954c61 | 328 | by the execution of the SCSI Request Packet.\r |
329 | This buffer must be allocated by the caller.\r | |
330 | If SenseDataLength is 0, then this parameter\r | |
331 | is optional and may be NULL.\r | |
6089ba62 | 332 | @param[in, out] SenseDataLength On input, the length in bytes of the SenseData buffer.\r |
d5954c61 | 333 | On output, the number of bytes written to the SenseData buffer. \r |
334 | @param[out] HostAdapterStatus The status of the SCSI Host Controller that\r | |
335 | produces the SCSI bus containing the SCSI target\r | |
336 | specified by ScsiIo when the SCSI Request Packet\r | |
337 | was executed. See the EFI SCSI I/O Protocol in the\r | |
338 | UEFI Specification for details on the possible\r | |
339 | return values.\r | |
340 | @param[out] TargetStatus The status returned by the SCSI target specified\r | |
070a76b1 | 341 | by ScsiIo when the SCSI Request Packet was executed\r |
d5954c61 | 342 | on the SCSI Host Controller. See the EFI SCSI\r |
343 | I/O Protocol in the UEFI Specification for details\r | |
344 | on the possible return values.\r | |
345 | @param[in, out] DataBuffer A pointer to data that was generated by the\r | |
346 | execution of the SCSI Request Packet. This\r | |
347 | buffer must be allocated by the caller. If\r | |
348 | DataLength is 0, then this parameter is optional\r | |
349 | and may be NULL. \r | |
350 | @param[in, out] DataLength On input, a pointer to the length in bytes of\r | |
351 | the DataBuffer buffer. On output, a pointer\r | |
352 | to the number of bytes written to the DataBuffer\r | |
353 | buffer. \r | |
354 | @param[in] DBDField Specifies the DBD field of the CDB for this SCSI Command.\r | |
355 | @param[in] PageControl Specifies the PC field of the CDB for this SCSI Command. \r | |
356 | @param[in] PageCode Specifies the Page Control field of the CDB for this SCSI Command. \r | |
357 | \r | |
358 | @retval EFI_SUCCESS The command was executed successfully.\r | |
359 | See HostAdapterStatus, TargetStatus, SenseDataLength,\r | |
360 | and SenseData in that order for additional status information.\r | |
361 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the\r | |
362 | entire DataBuffer could not be transferred.\r | |
bf231ea6 | 363 | The actual number of bytes transferred is returned\r |
d5954c61 | 364 | in DataLength.\r |
365 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r | |
366 | there are too many SCSI Command Packets already queued.\r | |
367 | The SCSI Request Packet was not sent, so no additional\r | |
368 | status information is available. The caller may retry\r | |
369 | again later.\r | |
370 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send\r | |
371 | SCSI Request Packet. See HostAdapterStatus, TargetStatus,\r | |
372 | SenseDataLength, and SenseData in that order for\r | |
373 | additional status information.\r | |
bf231ea6 | 374 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r |
d5954c61 | 375 | is not supported by the SCSI initiator(i.e., SCSI\r |
376 | Host Controller). The SCSI Request Packet was not\r | |
377 | sent, so no additional status information is available.\r | |
378 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI\r | |
379 | Request Packet to execute. See HostAdapterStatus,\r | |
380 | TargetStatus, SenseDataLength, and SenseData in that\r | |
381 | order for additional status information.\r | |
a3589760 | 382 | \r |
bf231ea6 | 383 | **/\r |
a02e796b | 384 | EFI_STATUS\r |
373b5cf9 | 385 | EFIAPI\r |
d35be2a4 | 386 | ScsiModeSense10Command (\r |
d5954c61 | 387 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
388 | IN UINT64 Timeout,\r | |
389 | IN OUT VOID *SenseData, OPTIONAL\r | |
390 | IN OUT UINT8 *SenseDataLength,\r | |
391 | OUT UINT8 *HostAdapterStatus,\r | |
392 | OUT UINT8 *TargetStatus,\r | |
393 | IN OUT VOID *DataBuffer, OPTIONAL\r | |
394 | IN OUT UINT32 *DataLength,\r | |
395 | IN UINT8 DBDField, OPTIONAL\r | |
396 | IN UINT8 PageControl,\r | |
397 | IN UINT8 PageCode\r | |
a02e796b | 398 | )\r |
a02e796b | 399 | {\r |
400 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 401 | UINT64 Lun;\r |
402 | UINT8 *Target;\r | |
403 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 404 | EFI_STATUS Status;\r |
52cd71dc | 405 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];\r |
a02e796b | 406 | \r |
8069d49e LG |
407 | ASSERT (SenseDataLength != NULL);\r |
408 | ASSERT (HostAdapterStatus != NULL);\r | |
409 | ASSERT (TargetStatus != NULL);\r | |
410 | ASSERT (DataLength != NULL);\r | |
d5954c61 | 411 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 412 | \r |
a02e796b | 413 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 414 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r |
a02e796b | 415 | \r |
416 | CommandPacket.Timeout = Timeout;\r | |
417 | CommandPacket.InDataBuffer = DataBuffer;\r | |
418 | CommandPacket.SenseData = SenseData;\r | |
419 | CommandPacket.InTransferLength= *DataLength;\r | |
420 | CommandPacket.Cdb = Cdb;\r | |
421 | //\r | |
422 | // Fill Cdb for Mode Sense (10) Command\r | |
423 | //\r | |
6b3ecf5c | 424 | Target = &TargetArray[0];\r |
425 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
426 | \r | |
a02e796b | 427 | Cdb[0] = EFI_SCSI_OP_MODE_SEN10;\r |
52cd71dc LG |
428 | //\r |
429 | // DBDField is in Cdb[1] bit3 of (bit7..0)\r | |
430 | //\r | |
6b3ecf5c | 431 | Cdb[1] = (UINT8) (((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK) + ((DBDField << 3) & 0x08));\r |
52cd71dc LG |
432 | //\r |
433 | // PageControl is in Cdb[2] bit7..6, PageCode is in Cdb[2] bit5..0\r | |
434 | //\r | |
6b3ecf5c | 435 | Cdb[2] = (UINT8) (((PageControl << 6) & 0xc0) | (PageCode & 0x3f));\r |
a02e796b | 436 | Cdb[7] = (UINT8) (*DataLength >> 8);\r |
437 | Cdb[8] = (UINT8) (*DataLength);\r | |
438 | \r | |
52cd71dc | 439 | CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;\r |
a02e796b | 440 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r |
441 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
442 | \r | |
443 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
444 | \r | |
445 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
446 | *TargetStatus = CommandPacket.TargetStatus;\r | |
447 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
448 | *DataLength = CommandPacket.InTransferLength;\r | |
449 | \r | |
450 | return Status;\r | |
451 | }\r | |
452 | \r | |
bf231ea6 | 453 | \r |
a3589760 | 454 | /**\r |
d5954c61 | 455 | Execute Request Sense SCSI command on a specific SCSI target.\r |
b91d5eca | 456 | \r |
d5954c61 | 457 | Executes the Request Sense command on the SCSI target specified by ScsiIo.\r |
458 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
459 | If Timeout is greater than zero, then the command is executed and will timeout after Timeout 100 ns units.\r | |
460 | If ScsiIo is NULL, then ASSERT().\r | |
52cd71dc LG |
461 | If SenseDataLength is NULL, then ASSERT().\r |
462 | If HostAdapterStatus is NULL, then ASSERT().\r | |
463 | If TargetStatus is NULL, then ASSERT().\r | |
a3589760 | 464 | \r |
b91d5eca | 465 | @param[in] ScsiIo A pointer to SCSI IO protocol.\r |
466 | @param[in] Timeout The length of timeout period.\r | |
d5954c61 | 467 | @param[in, out] SenseData A pointer to output sense data.\r |
468 | @param[in, out] SenseDataLength The length of output sense data.\r | |
b91d5eca | 469 | @param[out] HostAdapterStatus The status of Host Adapter.\r |
470 | @param[out] TargetStatus The status of the target.\r | |
471 | \r | |
472 | @retval EFI_SUCCESS Command is executed successfully.\r | |
473 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are\r | |
474 | too many SCSI Command Packets already queued.\r | |
475 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.\r | |
476 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by\r | |
477 | the SCSI initiator(i.e., SCSI Host Controller)\r | |
478 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r | |
a3589760 | 479 | \r |
bf231ea6 | 480 | **/\r |
a02e796b | 481 | EFI_STATUS\r |
373b5cf9 | 482 | EFIAPI\r |
d35be2a4 | 483 | ScsiRequestSenseCommand (\r |
d5954c61 | 484 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
485 | IN UINT64 Timeout,\r | |
486 | IN OUT VOID *SenseData, OPTIONAL\r | |
487 | IN OUT UINT8 *SenseDataLength,\r | |
488 | OUT UINT8 *HostAdapterStatus,\r | |
489 | OUT UINT8 *TargetStatus\r | |
a02e796b | 490 | )\r |
a02e796b | 491 | {\r |
492 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 493 | UINT64 Lun;\r |
494 | UINT8 *Target;\r | |
495 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 496 | EFI_STATUS Status;\r |
52cd71dc | 497 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_SIX];\r |
a02e796b | 498 | \r |
8069d49e LG |
499 | ASSERT (SenseDataLength != NULL);\r |
500 | ASSERT (HostAdapterStatus != NULL);\r | |
501 | ASSERT (TargetStatus != NULL);\r | |
d5954c61 | 502 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 503 | \r |
a02e796b | 504 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 505 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIX);\r |
a02e796b | 506 | \r |
507 | CommandPacket.Timeout = Timeout;\r | |
508 | CommandPacket.InDataBuffer = SenseData;\r | |
509 | CommandPacket.SenseData = NULL;\r | |
510 | CommandPacket.InTransferLength= *SenseDataLength;\r | |
511 | CommandPacket.Cdb = Cdb;\r | |
512 | //\r | |
513 | // Fill Cdb for Request Sense Command\r | |
514 | //\r | |
6b3ecf5c | 515 | Target = &TargetArray[0];\r |
516 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
517 | \r | |
a02e796b | 518 | Cdb[0] = EFI_SCSI_OP_REQUEST_SENSE;\r |
6b3ecf5c | 519 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
a02e796b | 520 | Cdb[4] = (UINT8) (*SenseDataLength);\r |
521 | \r | |
52cd71dc | 522 | CommandPacket.CdbLength = (UINT8) EFI_SCSI_OP_LENGTH_SIX;\r |
a02e796b | 523 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r |
524 | CommandPacket.SenseDataLength = 0;\r | |
525 | \r | |
526 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
527 | \r | |
528 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
529 | *TargetStatus = CommandPacket.TargetStatus;\r | |
530 | *SenseDataLength = (UINT8) CommandPacket.InTransferLength;\r | |
531 | \r | |
532 | return Status;\r | |
533 | }\r | |
534 | \r | |
bf231ea6 | 535 | \r |
a3589760 | 536 | /**\r |
d5954c61 | 537 | Execute Read Capacity SCSI command on a specific SCSI target.\r |
b91d5eca | 538 | \r |
d5954c61 | 539 | Executes the SCSI Read Capacity command on the SCSI target specified by ScsiIo.\r |
540 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
541 | If Timeout is greater than zero, then the command is executed and will timeout after\r | |
51969ecb | 542 | Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.\r |
d5954c61 | 543 | If ScsiIo is NULL, then ASSERT().\r |
52cd71dc LG |
544 | If SenseDataLength is NULL, then ASSERT().\r |
545 | If HostAdapterStatus is NULL, then ASSERT().\r | |
546 | If TargetStatus is NULL, then ASSERT().\r | |
547 | If DataLength is NULL, then ASSERT().\r | |
bf231ea6 | 548 | \r |
d5954c61 | 549 | @param[in] ScsiIo A pointer to SCSI IO protocol.\r |
550 | @param[in] Timeout The length of timeout period.\r | |
551 | @param[in, out] SenseData A pointer to output sense data.\r | |
ee256e2c | 552 | @param[in, out] SenseDataLength The length of output sense data.\r |
d5954c61 | 553 | @param[out] HostAdapterStatus The status of Host Adapter.\r |
554 | @param[out] TargetStatus The status of the target.\r | |
555 | @param[in, out] DataBuffer A pointer to a data buffer.\r | |
ee256e2c | 556 | @param[in, out] DataLength The length of data buffer.\r |
51969ecb | 557 | @param[in] Pmi Partial medium indicator.\r |
b91d5eca | 558 | \r |
6089ba62 | 559 | @retval EFI_SUCCESS Command is executed successfully.\r |
560 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire\r | |
561 | DataBuffer could not be transferred. The actual\r | |
562 | number of bytes transferred is returned in DataLength.\r | |
563 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r | |
564 | there are too many SCSI Command Packets already queued.\r | |
565 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.\r | |
566 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r | |
567 | is not supported by the SCSI initiator(i.e., SCSI Host Controller)\r | |
568 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r | |
a3589760 | 569 | \r |
bf231ea6 | 570 | **/\r |
a02e796b | 571 | EFI_STATUS\r |
373b5cf9 | 572 | EFIAPI\r |
d35be2a4 | 573 | ScsiReadCapacityCommand (\r |
d5954c61 | 574 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
575 | IN UINT64 Timeout,\r | |
576 | IN OUT VOID *SenseData, OPTIONAL\r | |
577 | IN OUT UINT8 *SenseDataLength,\r | |
578 | OUT UINT8 *HostAdapterStatus,\r | |
579 | OUT UINT8 *TargetStatus,\r | |
580 | IN OUT VOID *DataBuffer, OPTIONAL\r | |
581 | IN OUT UINT32 *DataLength,\r | |
51969ecb | 582 | IN BOOLEAN Pmi\r |
a02e796b | 583 | )\r |
a02e796b | 584 | {\r |
585 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 586 | UINT64 Lun;\r |
587 | UINT8 *Target;\r | |
588 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 589 | EFI_STATUS Status;\r |
52cd71dc | 590 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];\r |
a02e796b | 591 | \r |
8069d49e LG |
592 | ASSERT (SenseDataLength != NULL);\r |
593 | ASSERT (HostAdapterStatus != NULL);\r | |
594 | ASSERT (TargetStatus != NULL);\r | |
595 | ASSERT (DataLength != NULL);\r | |
d5954c61 | 596 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 597 | \r |
a02e796b | 598 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 599 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r |
a02e796b | 600 | \r |
601 | CommandPacket.Timeout = Timeout;\r | |
602 | CommandPacket.InDataBuffer = DataBuffer;\r | |
603 | CommandPacket.SenseData = SenseData;\r | |
604 | CommandPacket.InTransferLength= *DataLength;\r | |
605 | CommandPacket.Cdb = Cdb;\r | |
606 | //\r | |
607 | // Fill Cdb for Read Capacity Command\r | |
608 | //\r | |
6b3ecf5c | 609 | Target = &TargetArray[0];\r |
610 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
611 | \r | |
a02e796b | 612 | Cdb[0] = EFI_SCSI_OP_READ_CAPACITY;\r |
6b3ecf5c | 613 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
51969ecb | 614 | if (!Pmi) {\r |
a02e796b | 615 | //\r |
51969ecb | 616 | // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO.\r |
a02e796b | 617 | //\r |
618 | ZeroMem ((Cdb + 2), 4);\r | |
619 | } else {\r | |
620 | Cdb[8] |= 0x01;\r | |
621 | }\r | |
622 | \r | |
52cd71dc | 623 | CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;\r |
a02e796b | 624 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r |
625 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
626 | \r | |
627 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
628 | \r | |
629 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
630 | *TargetStatus = CommandPacket.TargetStatus;\r | |
631 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
632 | *DataLength = CommandPacket.InTransferLength;\r | |
633 | \r | |
634 | return Status;\r | |
635 | }\r | |
636 | \r | |
bf231ea6 | 637 | \r |
ccb491c8 | 638 | /**\r |
5e11e7c6 | 639 | Execute Read Capacity SCSI 16 command on a specific SCSI target.\r |
640 | \r | |
641 | Executes the SCSI Read Capacity 16 command on the SCSI target specified by ScsiIo.\r | |
642 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
643 | If Timeout is greater than zero, then the command is executed and will timeout after\r | |
644 | Timeout 100 ns units. The Pmi parameter is used to construct the CDB for this SCSI command.\r | |
645 | If ScsiIo is NULL, then ASSERT().\r | |
646 | If SenseDataLength is NULL, then ASSERT().\r | |
647 | If HostAdapterStatus is NULL, then ASSERT().\r | |
648 | If TargetStatus is NULL, then ASSERT().\r | |
649 | If DataLength is NULL, then ASSERT().\r | |
650 | \r | |
651 | @param[in] ScsiIo A pointer to SCSI IO protocol.\r | |
652 | @param[in] Timeout The length of timeout period.\r | |
653 | @param[in, out] SenseData A pointer to output sense data.\r | |
654 | @param[in, out] SenseDataLength The length of output sense data.\r | |
655 | @param[out] HostAdapterStatus The status of Host Adapter.\r | |
656 | @param[out] TargetStatus The status of the target.\r | |
657 | @param[in, out] DataBuffer A pointer to a data buffer.\r | |
658 | @param[in, out] DataLength The length of data buffer.\r | |
659 | @param[in] Pmi Partial medium indicator.\r | |
660 | \r | |
661 | @retval EFI_SUCCESS Command is executed successfully.\r | |
662 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire\r | |
663 | DataBuffer could not be transferred. The actual\r | |
664 | number of bytes transferred is returned in DataLength.\r | |
665 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r | |
666 | there are too many SCSI Command Packets already queued.\r | |
667 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.\r | |
668 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r | |
669 | is not supported by the SCSI initiator(i.e., SCSI Host Controller)\r | |
670 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r | |
ccb491c8 | 671 | \r |
672 | **/\r | |
ccb491c8 | 673 | EFI_STATUS\r |
674 | EFIAPI\r | |
675 | ScsiReadCapacity16Command (\r | |
f158ee67 | 676 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
677 | IN UINT64 Timeout,\r | |
678 | IN OUT VOID *SenseData, OPTIONAL\r | |
679 | IN OUT UINT8 *SenseDataLength,\r | |
680 | OUT UINT8 *HostAdapterStatus,\r | |
681 | OUT UINT8 *TargetStatus,\r | |
682 | IN OUT VOID *DataBuffer, OPTIONAL\r | |
683 | IN OUT UINT32 *DataLength,\r | |
684 | IN BOOLEAN Pmi\r | |
ccb491c8 | 685 | )\r |
686 | {\r | |
687 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 688 | UINT64 Lun;\r |
689 | UINT8 *Target;\r | |
690 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
ccb491c8 | 691 | EFI_STATUS Status;\r |
692 | UINT8 Cdb[16];\r | |
693 | \r | |
694 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r | |
695 | ZeroMem (Cdb, 16);\r | |
696 | \r | |
697 | CommandPacket.Timeout = Timeout;\r | |
698 | CommandPacket.InDataBuffer = DataBuffer;\r | |
699 | CommandPacket.SenseData = SenseData;\r | |
700 | CommandPacket.InTransferLength= *DataLength;\r | |
701 | CommandPacket.Cdb = Cdb;\r | |
702 | //\r | |
703 | // Fill Cdb for Read Capacity Command\r | |
704 | //\r | |
6b3ecf5c | 705 | Target = &TargetArray[0];\r |
706 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
707 | \r | |
ccb491c8 | 708 | Cdb[0] = EFI_SCSI_OP_READ_CAPACITY16;\r |
709 | Cdb[1] = 0x10;\r | |
51969ecb | 710 | if (!Pmi) {\r |
ccb491c8 | 711 | //\r |
51969ecb | 712 | // Partial medium indicator,if Pmi is FALSE, the Cdb.2 ~ Cdb.9 MUST BE ZERO.\r |
ccb491c8 | 713 | //\r |
714 | ZeroMem ((Cdb + 2), 8);\r | |
715 | } else {\r | |
716 | Cdb[14] |= 0x01;\r | |
717 | }\r | |
718 | \r | |
719 | Cdb[13] = 0x20;\r | |
720 | CommandPacket.CdbLength = 16;\r | |
721 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r | |
722 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
723 | \r | |
724 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
725 | \r | |
726 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
727 | *TargetStatus = CommandPacket.TargetStatus;\r | |
728 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
729 | *DataLength = CommandPacket.InTransferLength;\r | |
730 | \r | |
731 | return Status;\r | |
732 | }\r | |
733 | \r | |
734 | \r | |
a3589760 | 735 | /**\r |
d5954c61 | 736 | Execute Read(10) SCSI command on a specific SCSI target.\r |
737 | \r | |
738 | Executes the SCSI Read(10) command on the SCSI target specified by ScsiIo.\r | |
739 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
740 | If Timeout is greater than zero, then the command is executed and will timeout\r | |
741 | after Timeout 100 ns units. The StartLba and SectorSize parameters are used to\r | |
742 | construct the CDB for this SCSI command.\r | |
743 | If ScsiIo is NULL, then ASSERT().\r | |
52cd71dc LG |
744 | If SenseDataLength is NULL, then ASSERT().\r |
745 | If HostAdapterStatus is NULL, then ASSERT().\r | |
746 | If TargetStatus is NULL, then ASSERT().\r | |
b91d5eca | 747 | If DataLength is NULL, then ASSERT().\r |
a3589760 | 748 | \r |
d5954c61 | 749 | \r |
750 | @param[in] ScsiIo A pointer to SCSI IO protocol.\r | |
751 | @param[in] Timeout The length of timeout period.\r | |
752 | @param[in, out] SenseData A pointer to output sense data.\r | |
ee256e2c | 753 | @param[in, out] SenseDataLength The length of output sense data.\r |
d5954c61 | 754 | @param[out] HostAdapterStatus The status of Host Adapter.\r |
755 | @param[out] TargetStatus The status of the target.\r | |
756 | @param[in, out] DataBuffer Read 10 command data.\r | |
ee256e2c | 757 | @param[in, out] DataLength The length of data buffer.\r |
d5954c61 | 758 | @param[in] StartLba The start address of LBA.\r |
759 | @param[in] SectorSize The sector size.\r | |
b91d5eca | 760 | \r |
6089ba62 | 761 | @retval EFI_SUCCESS Command is executed successfully.\r |
762 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could\r | |
763 | not be transferred. The actual number of bytes transferred is returned in DataLength.\r | |
764 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many \r | |
765 | SCSI Command Packets already queued.\r | |
766 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.\r | |
767 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by \r | |
768 | the SCSI initiator(i.e., SCSI Host Controller)\r | |
769 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r | |
a3589760 | 770 | \r |
bf231ea6 | 771 | **/\r |
a02e796b | 772 | EFI_STATUS\r |
373b5cf9 | 773 | EFIAPI\r |
d35be2a4 | 774 | ScsiRead10Command (\r |
d5954c61 | 775 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
776 | IN UINT64 Timeout,\r | |
777 | IN OUT VOID *SenseData, OPTIONAL\r | |
778 | IN OUT UINT8 *SenseDataLength,\r | |
779 | OUT UINT8 *HostAdapterStatus,\r | |
780 | OUT UINT8 *TargetStatus,\r | |
781 | IN OUT VOID *DataBuffer, OPTIONAL\r | |
782 | IN OUT UINT32 *DataLength,\r | |
783 | IN UINT32 StartLba,\r | |
784 | IN UINT32 SectorSize\r | |
a02e796b | 785 | )\r |
a02e796b | 786 | {\r |
787 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 788 | UINT64 Lun;\r |
789 | UINT8 *Target;\r | |
790 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 791 | EFI_STATUS Status;\r |
52cd71dc | 792 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];\r |
a02e796b | 793 | \r |
8069d49e LG |
794 | ASSERT (SenseDataLength != NULL);\r |
795 | ASSERT (HostAdapterStatus != NULL);\r | |
796 | ASSERT (TargetStatus != NULL);\r | |
797 | ASSERT (DataLength != NULL);\r | |
d5954c61 | 798 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 799 | \r |
a02e796b | 800 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 801 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r |
a02e796b | 802 | \r |
803 | CommandPacket.Timeout = Timeout;\r | |
804 | CommandPacket.InDataBuffer = DataBuffer;\r | |
805 | CommandPacket.SenseData = SenseData;\r | |
806 | CommandPacket.InTransferLength= *DataLength;\r | |
807 | CommandPacket.Cdb = Cdb;\r | |
808 | //\r | |
809 | // Fill Cdb for Read (10) Command\r | |
810 | //\r | |
6b3ecf5c | 811 | Target = &TargetArray[0];\r |
812 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
813 | \r | |
a02e796b | 814 | Cdb[0] = EFI_SCSI_OP_READ10;\r |
6b3ecf5c | 815 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
a02e796b | 816 | Cdb[2] = (UINT8) (StartLba >> 24);\r |
817 | Cdb[3] = (UINT8) (StartLba >> 16);\r | |
818 | Cdb[4] = (UINT8) (StartLba >> 8);\r | |
819 | Cdb[5] = (UINT8) (StartLba & 0xff);\r | |
820 | Cdb[7] = (UINT8) (SectorSize >> 8);\r | |
821 | Cdb[8] = (UINT8) (SectorSize & 0xff);\r | |
822 | \r | |
52cd71dc | 823 | CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;\r |
a02e796b | 824 | CommandPacket.DataDirection = EFI_SCSI_DATA_IN;\r |
825 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
826 | \r | |
827 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
828 | \r | |
829 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
830 | *TargetStatus = CommandPacket.TargetStatus;\r | |
831 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
832 | *DataLength = CommandPacket.InTransferLength;\r | |
833 | \r | |
834 | return Status;\r | |
835 | }\r | |
836 | \r | |
bf231ea6 | 837 | \r |
a3589760 | 838 | /**\r |
d5954c61 | 839 | Execute Write(10) SCSI command on a specific SCSI target.\r |
840 | \r | |
841 | Executes the SCSI Write(10) command on the SCSI target specified by ScsiIo.\r | |
842 | If Timeout is zero, then this function waits indefinitely for the command to complete.\r | |
843 | If Timeout is greater than zero, then the command is executed and will timeout after\r | |
844 | Timeout 100 ns units. The StartLba and SectorSize parameters are used to construct\r | |
845 | the CDB for this SCSI command.\r | |
846 | If ScsiIo is NULL, then ASSERT().\r | |
52cd71dc LG |
847 | If SenseDataLength is NULL, then ASSERT().\r |
848 | If HostAdapterStatus is NULL, then ASSERT().\r | |
849 | If TargetStatus is NULL, then ASSERT().\r | |
b91d5eca | 850 | If DataLength is NULL, then ASSERT().\r |
a3589760 | 851 | \r |
d5954c61 | 852 | @param[in] ScsiIo SCSI IO Protocol to use\r |
853 | @param[in] Timeout The length of timeout period.\r | |
854 | @param[in, out] SenseData A pointer to output sense data.\r | |
6089ba62 | 855 | @param[in, out] SenseDataLength The length of output sense data.\r |
d5954c61 | 856 | @param[out] HostAdapterStatus The status of Host Adapter.\r |
857 | @param[out] TargetStatus The status of the target.\r | |
858 | @param[in, out] DataBuffer A pointer to a data buffer.\r | |
6089ba62 | 859 | @param[in, out] DataLength The length of data buffer.\r |
d5954c61 | 860 | @param[in] StartLba The start address of LBA.\r |
861 | @param[in] SectorSize The sector size.\r | |
b91d5eca | 862 | \r |
6089ba62 | 863 | @retval EFI_SUCCESS Command is executed successfully.\r |
864 | @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, but the entire DataBuffer could\r | |
865 | not be transferred. The actual number of bytes transferred is returned in DataLength.\r | |
866 | @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many \r | |
867 | SCSI Command Packets already queued.\r | |
868 | @retval EFI_DEVICE_ERROR A device error occurred while attempting to send SCSI Request Packet.\r | |
869 | @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported by \r | |
870 | the SCSI initiator(i.e., SCSI Host Controller)\r | |
871 | @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r | |
a3589760 | 872 | \r |
bf231ea6 | 873 | **/\r |
a02e796b | 874 | EFI_STATUS\r |
373b5cf9 | 875 | EFIAPI\r |
d35be2a4 | 876 | ScsiWrite10Command (\r |
d5954c61 | 877 | IN EFI_SCSI_IO_PROTOCOL *ScsiIo,\r |
878 | IN UINT64 Timeout,\r | |
879 | IN OUT VOID *SenseData, OPTIONAL\r | |
880 | IN OUT UINT8 *SenseDataLength,\r | |
881 | OUT UINT8 *HostAdapterStatus,\r | |
882 | OUT UINT8 *TargetStatus,\r | |
883 | IN OUT VOID *DataBuffer, OPTIONAL\r | |
884 | IN OUT UINT32 *DataLength,\r | |
885 | IN UINT32 StartLba,\r | |
886 | IN UINT32 SectorSize\r | |
a02e796b | 887 | )\r |
a02e796b | 888 | {\r |
889 | EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r | |
6b3ecf5c | 890 | UINT64 Lun;\r |
891 | UINT8 *Target;\r | |
892 | UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r | |
a02e796b | 893 | EFI_STATUS Status;\r |
52cd71dc | 894 | UINT8 Cdb[EFI_SCSI_OP_LENGTH_TEN];\r |
a02e796b | 895 | \r |
8069d49e LG |
896 | ASSERT (SenseDataLength != NULL);\r |
897 | ASSERT (HostAdapterStatus != NULL);\r | |
898 | ASSERT (TargetStatus != NULL);\r | |
899 | ASSERT (DataLength != NULL);\r | |
d5954c61 | 900 | ASSERT (ScsiIo != NULL);\r |
8069d49e | 901 | \r |
a02e796b | 902 | ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r |
52cd71dc | 903 | ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TEN);\r |
a02e796b | 904 | \r |
905 | CommandPacket.Timeout = Timeout;\r | |
906 | CommandPacket.OutDataBuffer = DataBuffer;\r | |
907 | CommandPacket.SenseData = SenseData;\r | |
908 | CommandPacket.OutTransferLength= *DataLength;\r | |
909 | CommandPacket.Cdb = Cdb;\r | |
910 | //\r | |
911 | // Fill Cdb for Write (10) Command\r | |
912 | //\r | |
6b3ecf5c | 913 | Target = &TargetArray[0];\r |
914 | ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r | |
915 | \r | |
a02e796b | 916 | Cdb[0] = EFI_SCSI_OP_WRITE10;\r |
6b3ecf5c | 917 | Cdb[1] = (UINT8) ((Lun << 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r |
a02e796b | 918 | Cdb[2] = (UINT8) (StartLba >> 24);\r |
919 | Cdb[3] = (UINT8) (StartLba >> 16);\r | |
920 | Cdb[4] = (UINT8) (StartLba >> 8);\r | |
921 | Cdb[5] = (UINT8) StartLba;\r | |
922 | Cdb[7] = (UINT8) (SectorSize >> 8);\r | |
923 | Cdb[8] = (UINT8) SectorSize;\r | |
924 | \r | |
52cd71dc | 925 | CommandPacket.CdbLength = EFI_SCSI_OP_LENGTH_TEN;\r |
a02e796b | 926 | CommandPacket.DataDirection = EFI_SCSI_DATA_OUT;\r |
927 | CommandPacket.SenseDataLength = *SenseDataLength;\r | |
928 | \r | |
929 | Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r | |
930 | \r | |
931 | *HostAdapterStatus = CommandPacket.HostAdapterStatus;\r | |
932 | *TargetStatus = CommandPacket.TargetStatus;\r | |
933 | *SenseDataLength = CommandPacket.SenseDataLength;\r | |
ba7e162e | 934 | *DataLength = CommandPacket.OutTransferLength;\r |
a02e796b | 935 | \r |
936 | return Status;\r | |
937 | }\r | |
373b5cf9 | 938 | \r |