]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
MdeModulePkg/UsbMassStorage: Add 16 byte SCSI cmds support if the last LBA can not...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.c
CommitLineData
e237e7ae 1/** @file\r
d80ed2a7 2 Implementation of the command set of USB Mass Storage Specification\r
3 for Bootability, Revision 1.0.\r
cc5166ff 4\r
16d718a5 5Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 6This program and the accompanying materials\r
e237e7ae 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
cc5166ff 14**/\r
e237e7ae 15\r
39840c50 16#include "UsbMass.h"\r
e237e7ae 17\r
e237e7ae 18/**\r
d80ed2a7 19 Execute REQUEST SENSE Command to retrieve sense data from device.\r
e237e7ae 20\r
d80ed2a7 21 @param UsbMass The device whose sense data is requested.\r
e237e7ae 22\r
d80ed2a7 23 @retval EFI_SUCCESS The command is excuted successfully.\r
cc5166ff 24 @retval EFI_DEVICE_ERROR Failed to request sense.\r
25 @retval EFI_NO_RESPONSE The device media doesn't response this request.\r
26 @retval EFI_INVALID_PARAMETER The command has some invalid parameters.\r
27 @retval EFI_WRITE_PROTECTED The device is write protected.\r
28 @retval EFI_MEDIA_CHANGED The device media has been changed.\r
e237e7ae 29\r
30**/\r
31EFI_STATUS\r
32UsbBootRequestSense (\r
33 IN USB_MASS_DEVICE *UsbMass\r
34 )\r
35{\r
36 USB_BOOT_REQUEST_SENSE_CMD SenseCmd;\r
37 USB_BOOT_REQUEST_SENSE_DATA SenseData;\r
38 EFI_BLOCK_IO_MEDIA *Media;\r
39 USB_MASS_TRANSPORT *Transport;\r
40 EFI_STATUS Status;\r
41 UINT32 CmdResult;\r
42\r
43 Transport = UsbMass->Transport;\r
44\r
45 //\r
d80ed2a7 46 // Request the sense data from the device\r
e237e7ae 47 //\r
48 ZeroMem (&SenseCmd, sizeof (USB_BOOT_REQUEST_SENSE_CMD));\r
49 ZeroMem (&SenseData, sizeof (USB_BOOT_REQUEST_SENSE_DATA));\r
50\r
51 SenseCmd.OpCode = USB_BOOT_REQUEST_SENSE_OPCODE;\r
c52fa98c 52 SenseCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
c9325700 53 SenseCmd.AllocLen = (UINT8) sizeof (USB_BOOT_REQUEST_SENSE_DATA);\r
e237e7ae 54\r
55 Status = Transport->ExecCommand (\r
56 UsbMass->Context,\r
57 &SenseCmd,\r
58 sizeof (USB_BOOT_REQUEST_SENSE_CMD),\r
59 EfiUsbDataIn,\r
60 &SenseData,\r
61 sizeof (USB_BOOT_REQUEST_SENSE_DATA),\r
c7e39923 62 UsbMass->Lun,\r
e237e7ae 63 USB_BOOT_GENERAL_CMD_TIMEOUT,\r
64 &CmdResult\r
65 );\r
66 if (EFI_ERROR (Status) || CmdResult != USB_MASS_CMD_SUCCESS) {\r
1c619535 67 DEBUG ((EFI_D_ERROR, "UsbBootRequestSense: (%r) CmdResult=0x%x\n", Status, CmdResult));\r
88e349f1 68 if (!EFI_ERROR (Status)) {\r
69 Status = EFI_DEVICE_ERROR;\r
70 }\r
50fa1b3a 71 return Status;\r
e237e7ae 72 }\r
73\r
74 //\r
d80ed2a7 75 // If sense data is retrieved successfully, interpret the sense data\r
76 // and update the media status if necessary.\r
e237e7ae 77 //\r
78 Media = &UsbMass->BlockIoMedia;\r
79\r
80 switch (USB_BOOT_SENSE_KEY (SenseData.SenseKey)) {\r
81\r
82 case USB_BOOT_SENSE_NO_SENSE:\r
50fa1b3a 83 Status = EFI_NO_RESPONSE;\r
84 break;\r
85\r
e237e7ae 86 case USB_BOOT_SENSE_RECOVERED:\r
87 //\r
88 // Suppose hardware can handle this case, and recover later by itself\r
89 //\r
90 Status = EFI_NOT_READY;\r
91 break;\r
92\r
93 case USB_BOOT_SENSE_NOT_READY:\r
50fa1b3a 94 Status = EFI_DEVICE_ERROR;\r
1ccdbf2a 95 if (SenseData.Asc == USB_BOOT_ASC_NO_MEDIA) {\r
d80ed2a7 96 Media->MediaPresent = FALSE;\r
97 Status = EFI_NO_MEDIA;\r
1ccdbf2a 98 } else if (SenseData.Asc == USB_BOOT_ASC_NOT_READY) {\r
d80ed2a7 99 Status = EFI_NOT_READY;\r
e237e7ae 100 }\r
101 break;\r
102\r
103 case USB_BOOT_SENSE_ILLEGAL_REQUEST:\r
104 Status = EFI_INVALID_PARAMETER;\r
105 break;\r
106\r
107 case USB_BOOT_SENSE_UNIT_ATTENTION:\r
108 Status = EFI_DEVICE_ERROR;\r
1ccdbf2a 109 if (SenseData.Asc == USB_BOOT_ASC_MEDIA_CHANGE) {\r
50fa1b3a 110 //\r
d80ed2a7 111 // If MediaChange, reset ReadOnly and new MediaId\r
50fa1b3a 112 //\r
d80ed2a7 113 Status = EFI_MEDIA_CHANGED;\r
50fa1b3a 114 Media->ReadOnly = FALSE;\r
115 Media->MediaId++;\r
e237e7ae 116 }\r
117 break;\r
118\r
d80ed2a7 119 case USB_BOOT_SENSE_DATA_PROTECT:\r
120 Status = EFI_WRITE_PROTECTED;\r
50fa1b3a 121 Media->ReadOnly = TRUE;\r
e237e7ae 122 break;\r
123\r
124 default:\r
125 Status = EFI_DEVICE_ERROR;\r
126 break;\r
127 }\r
128\r
1c619535 129 DEBUG ((EFI_D_INFO, "UsbBootRequestSense: (%r) with sense key %x/%x/%x\n",\r
e237e7ae 130 Status,\r
131 USB_BOOT_SENSE_KEY (SenseData.SenseKey),\r
1ccdbf2a 132 SenseData.Asc,\r
133 SenseData.Ascq\r
e237e7ae 134 ));\r
135\r
136 return Status;\r
137}\r
138\r
139\r
140/**\r
d80ed2a7 141 Execute the USB mass storage bootability commands.\r
142\r
143 This function executes the USB mass storage bootability commands.\r
144 If execution failed, retrieve the error by REQUEST_SENSE, then\r
145 update the device's status, such as ReadyOnly.\r
e237e7ae 146\r
147 @param UsbMass The device to issue commands to\r
148 @param Cmd The command to execute\r
149 @param CmdLen The length of the command\r
150 @param DataDir The direction of data transfer\r
151 @param Data The buffer to hold the data\r
152 @param DataLen The length of expected data\r
153 @param Timeout The timeout used to transfer\r
154\r
d80ed2a7 155 @retval EFI_SUCCESS Command is excuted successfully\r
156 @retval Others Command execution failed.\r
e237e7ae 157\r
158**/\r
e237e7ae 159EFI_STATUS\r
160UsbBootExecCmd (\r
161 IN USB_MASS_DEVICE *UsbMass,\r
162 IN VOID *Cmd,\r
163 IN UINT8 CmdLen,\r
164 IN EFI_USB_DATA_DIRECTION DataDir,\r
165 IN VOID *Data,\r
166 IN UINT32 DataLen,\r
167 IN UINT32 Timeout\r
168 )\r
169{\r
170 USB_MASS_TRANSPORT *Transport;\r
171 EFI_STATUS Status;\r
172 UINT32 CmdResult;\r
173\r
174 Transport = UsbMass->Transport;\r
175 Status = Transport->ExecCommand (\r
176 UsbMass->Context,\r
177 Cmd,\r
178 CmdLen,\r
179 DataDir,\r
180 Data,\r
181 DataLen,\r
c7e39923 182 UsbMass->Lun,\r
e237e7ae 183 Timeout,\r
184 &CmdResult\r
185 );\r
19bc8527 186\r
187 if (Status == EFI_TIMEOUT) {\r
188 DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Timeout to Exec 0x%x Cmd\n", *(UINT8 *)Cmd));\r
189 return EFI_TIMEOUT;\r
190 }\r
191\r
e237e7ae 192 //\r
d80ed2a7 193 // If ExecCommand() returns no error and CmdResult is success,\r
194 // then the commnad transfer is successful.\r
e237e7ae 195 //\r
d80ed2a7 196 if ((CmdResult == USB_MASS_CMD_SUCCESS) && !EFI_ERROR (Status)) {\r
e237e7ae 197 return EFI_SUCCESS;\r
198 }\r
199\r
d80ed2a7 200 //\r
201 // If command execution failed, then retrieve error info via sense request.\r
202 //\r
e237e7ae 203 return UsbBootRequestSense (UsbMass);\r
204}\r
205\r
206\r
207/**\r
d80ed2a7 208 Execute the USB mass storage bootability commands with retrial.\r
e237e7ae 209\r
d80ed2a7 210 This function executes USB mass storage bootability commands.\r
211 If the device isn't ready, wait for it. If the device is ready\r
212 and error occurs, retry the command again until it exceeds the\r
213 limit of retrial times.\r
214 \r
e237e7ae 215 @param UsbMass The device to issue commands to\r
216 @param Cmd The command to execute\r
217 @param CmdLen The length of the command\r
218 @param DataDir The direction of data transfer\r
219 @param Data The buffer to hold the data\r
220 @param DataLen The length of expected data\r
cc5166ff 221 @param Timeout The timeout used to transfer\r
e237e7ae 222\r
d80ed2a7 223 @retval EFI_SUCCESS The command is executed successfully.\r
224 @retval EFI_MEDIA_CHANGED The device media has been changed.\r
225 @retval Others Command execution failed after retrial.\r
e237e7ae 226\r
227**/\r
e237e7ae 228EFI_STATUS\r
229UsbBootExecCmdWithRetry (\r
230 IN USB_MASS_DEVICE *UsbMass,\r
231 IN VOID *Cmd,\r
232 IN UINT8 CmdLen,\r
233 IN EFI_USB_DATA_DIRECTION DataDir,\r
234 IN VOID *Data,\r
235 IN UINT32 DataLen,\r
236 IN UINT32 Timeout\r
237 )\r
238{\r
239 EFI_STATUS Status;\r
d80ed2a7 240 UINTN Retry;\r
19bc8527 241 EFI_EVENT TimeoutEvt;\r
242\r
243 Retry = 0;\r
244 Status = EFI_SUCCESS;\r
245 Status = gBS->CreateEvent (\r
246 EVT_TIMER,\r
247 TPL_CALLBACK,\r
248 NULL,\r
249 NULL,\r
250 &TimeoutEvt\r
251 );\r
252 if (EFI_ERROR (Status)) {\r
253 return Status;\r
254 }\r
e237e7ae 255\r
19bc8527 256 Status = gBS->SetTimer (TimeoutEvt, TimerRelative, EFI_TIMER_PERIOD_SECONDS(60));\r
257 if (EFI_ERROR (Status)) {\r
258 goto EXIT;\r
259 }\r
e237e7ae 260\r
19bc8527 261 //\r
262 // Execute the cmd and retry if it fails.\r
263 //\r
264 while (EFI_ERROR (gBS->CheckEvent (TimeoutEvt))) {\r
e237e7ae 265 Status = UsbBootExecCmd (\r
266 UsbMass,\r
267 Cmd,\r
268 CmdLen,\r
269 DataDir,\r
270 Data,\r
271 DataLen,\r
1c619535 272 Timeout\r
e237e7ae 273 );\r
19bc8527 274 if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA) {\r
e237e7ae 275 break;\r
276 }\r
277 //\r
19bc8527 278 // If the sense data shows the drive is not ready, we need execute the cmd again.\r
279 // We limit the upper boundary to 60 seconds.\r
e237e7ae 280 //\r
19bc8527 281 if (Status == EFI_NOT_READY) {\r
282 continue;\r
e237e7ae 283 }\r
19bc8527 284 //\r
285 // If the status is other error, then just retry 5 times.\r
286 //\r
287 if (Retry++ >= USB_BOOT_COMMAND_RETRY) {\r
288 break;\r
289 }\r
290 }\r
291\r
292EXIT:\r
293 if (TimeoutEvt != NULL) {\r
294 gBS->CloseEvent (TimeoutEvt);\r
e237e7ae 295 }\r
296\r
297 return Status;\r
298}\r
299\r
300\r
e237e7ae 301/**\r
d80ed2a7 302 Execute TEST UNIT READY command to check if the device is ready.\r
e237e7ae 303\r
304 @param UsbMass The device to test\r
305\r
d80ed2a7 306 @retval EFI_SUCCESS The device is ready.\r
e237e7ae 307 @retval Others Device not ready.\r
308\r
309**/\r
310EFI_STATUS\r
311UsbBootIsUnitReady (\r
312 IN USB_MASS_DEVICE *UsbMass\r
313 )\r
314{\r
315 USB_BOOT_TEST_UNIT_READY_CMD TestCmd;\r
316\r
317 ZeroMem (&TestCmd, sizeof (USB_BOOT_TEST_UNIT_READY_CMD));\r
318\r
319 TestCmd.OpCode = USB_BOOT_TEST_UNIT_READY_OPCODE;\r
c52fa98c 320 TestCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
e237e7ae 321\r
322 return UsbBootExecCmdWithRetry (\r
323 UsbMass,\r
324 &TestCmd,\r
c9325700 325 (UINT8) sizeof (USB_BOOT_TEST_UNIT_READY_CMD),\r
e237e7ae 326 EfiUsbNoData,\r
327 NULL,\r
328 0,\r
329 USB_BOOT_GENERAL_CMD_TIMEOUT\r
330 );\r
331}\r
332\r
333\r
334/**\r
d80ed2a7 335 Execute INQUIRY Command to request information regarding parameters of\r
336 the device be sent to the host computer.\r
e237e7ae 337\r
d80ed2a7 338 @param UsbMass The device to inquire.\r
e237e7ae 339\r
d80ed2a7 340 @retval EFI_SUCCESS INQUIRY Command is executed successfully.\r
341 @retval Others INQUIRY Command is not executed successfully.\r
e237e7ae 342\r
343**/\r
344EFI_STATUS\r
345UsbBootInquiry (\r
346 IN USB_MASS_DEVICE *UsbMass\r
347 )\r
348{\r
349 USB_BOOT_INQUIRY_CMD InquiryCmd;\r
e237e7ae 350 EFI_BLOCK_IO_MEDIA *Media;\r
351 EFI_STATUS Status;\r
352\r
353 Media = &(UsbMass->BlockIoMedia);\r
354\r
e237e7ae 355 ZeroMem (&InquiryCmd, sizeof (USB_BOOT_INQUIRY_CMD));\r
39840c50 356 ZeroMem (&UsbMass->InquiryData, sizeof (USB_BOOT_INQUIRY_DATA));\r
e237e7ae 357\r
358 InquiryCmd.OpCode = USB_BOOT_INQUIRY_OPCODE;\r
c52fa98c 359 InquiryCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
39840c50 360 InquiryCmd.AllocLen = (UINT8) sizeof (USB_BOOT_INQUIRY_DATA);\r
e237e7ae 361\r
362 Status = UsbBootExecCmdWithRetry (\r
363 UsbMass,\r
364 &InquiryCmd,\r
c9325700 365 (UINT8) sizeof (USB_BOOT_INQUIRY_CMD),\r
e237e7ae 366 EfiUsbDataIn,\r
39840c50 367 &UsbMass->InquiryData,\r
e237e7ae 368 sizeof (USB_BOOT_INQUIRY_DATA),\r
50fa1b3a 369 USB_BOOT_GENERAL_CMD_TIMEOUT\r
e237e7ae 370 );\r
371 if (EFI_ERROR (Status)) {\r
372 return Status;\r
373 }\r
374\r
d80ed2a7 375 //\r
376 // Get information from PDT (Peripheral Device Type) field and Removable Medium Bit\r
377 // from the inquiry data.\r
378 //\r
39840c50 379 UsbMass->Pdt = (UINT8) (USB_BOOT_PDT (UsbMass->InquiryData.Pdt));\r
380 Media->RemovableMedia = (BOOLEAN) (USB_BOOT_REMOVABLE (UsbMass->InquiryData.Removable));\r
e237e7ae 381 //\r
d80ed2a7 382 // Set block size to the default value of 512 Bytes, in case no media is present at first time.\r
e237e7ae 383 //\r
384 Media->BlockSize = 0x0200;\r
385\r
386 return Status;\r
387}\r
388\r
99c1725e 389/**\r
390 Execute READ CAPACITY 16 bytes command to request information regarding\r
391 the capacity of the installed medium of the device.\r
392\r
393 This function executes READ CAPACITY 16 bytes command to get the capacity\r
394 of the USB mass storage media, including the presence, block size,\r
395 and last block number.\r
396\r
397 @param UsbMass The device to retireve disk gemotric.\r
398\r
399 @retval EFI_SUCCESS The disk geometry is successfully retrieved.\r
400 @retval EFI_NOT_READY The returned block size is zero.\r
401 @retval Other READ CAPACITY 16 bytes command execution failed.\r
402 \r
403**/\r
404EFI_STATUS\r
405UsbBootReadCapacity16 (\r
406 IN USB_MASS_DEVICE *UsbMass\r
407 )\r
408{\r
409 UINT8 CapacityCmd[16];\r
410 EFI_SCSI_DISK_CAPACITY_DATA16 CapacityData;\r
411 EFI_BLOCK_IO_MEDIA *Media;\r
412 EFI_STATUS Status;\r
413 UINT32 BlockSize;\r
414\r
415 Media = &UsbMass->BlockIoMedia;\r
416\r
417 Media->MediaPresent = FALSE;\r
418 Media->LastBlock = 0;\r
419 Media->BlockSize = 0;\r
420\r
421 ZeroMem (CapacityCmd, sizeof (CapacityCmd));\r
422 ZeroMem (&CapacityData, sizeof (CapacityData));\r
423\r
424 CapacityCmd[0] = EFI_SCSI_OP_READ_CAPACITY16;\r
425 CapacityCmd[1] = 0x10;\r
426 //\r
427 // Partial medium indicator, set the bytes 2 ~ 9 of the Cdb as ZERO.\r
428 //\r
429 ZeroMem ((CapacityCmd + 2), 8);\r
430\r
431 CapacityCmd[13] = sizeof (CapacityData);\r
432 \r
433 Status = UsbBootExecCmdWithRetry (\r
434 UsbMass,\r
435 CapacityCmd,\r
436 (UINT8) sizeof (CapacityCmd),\r
437 EfiUsbDataIn,\r
438 &CapacityData,\r
439 sizeof (CapacityData),\r
440 USB_BOOT_GENERAL_CMD_TIMEOUT\r
441 );\r
442 if (EFI_ERROR (Status)) {\r
443 return Status;\r
444 }\r
445\r
446 //\r
447 // Get the information on media presence, block size, and last block number\r
448 // from READ CAPACITY data.\r
449 //\r
450 Media->MediaPresent = TRUE;\r
451 Media->LastBlock = SwapBytes64 (ReadUnaligned64 ((CONST UINT64 *) &(CapacityData.LastLba7)));\r
452\r
453 BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) &(CapacityData.BlockSize3)));\r
454 \r
455 Media->LowestAlignedLba = (CapacityData.LowestAlignLogic2 << 8) |\r
456 CapacityData.LowestAlignLogic1;\r
457 Media->LogicalBlocksPerPhysicalBlock = (1 << CapacityData.LogicPerPhysical);\r
458 if (BlockSize == 0) {\r
459 //\r
460 // Get sense data \r
461 //\r
462 return UsbBootRequestSense (UsbMass);\r
463 } else {\r
464 Media->BlockSize = BlockSize;\r
465 }\r
466\r
467 return Status;\r
468}\r
469\r
e237e7ae 470\r
471/**\r
d80ed2a7 472 Execute READ CAPACITY command to request information regarding\r
473 the capacity of the installed medium of the device.\r
474\r
475 This function executes READ CAPACITY command to get the capacity\r
476 of the USB mass storage media, including the presence, block size,\r
477 and last block number.\r
e237e7ae 478\r
479 @param UsbMass The device to retireve disk gemotric.\r
480\r
d80ed2a7 481 @retval EFI_SUCCESS The disk geometry is successfully retrieved.\r
482 @retval EFI_NOT_READY The returned block size is zero.\r
483 @retval Other READ CAPACITY command execution failed.\r
cc5166ff 484 \r
e237e7ae 485**/\r
486EFI_STATUS\r
487UsbBootReadCapacity (\r
488 IN USB_MASS_DEVICE *UsbMass\r
489 )\r
490{\r
491 USB_BOOT_READ_CAPACITY_CMD CapacityCmd;\r
492 USB_BOOT_READ_CAPACITY_DATA CapacityData;\r
493 EFI_BLOCK_IO_MEDIA *Media;\r
494 EFI_STATUS Status;\r
88e349f1 495 UINT32 BlockSize;\r
e237e7ae 496\r
497 Media = &UsbMass->BlockIoMedia;\r
498\r
e237e7ae 499 ZeroMem (&CapacityCmd, sizeof (USB_BOOT_READ_CAPACITY_CMD));\r
500 ZeroMem (&CapacityData, sizeof (USB_BOOT_READ_CAPACITY_DATA));\r
501\r
502 CapacityCmd.OpCode = USB_BOOT_READ_CAPACITY_OPCODE;\r
c52fa98c 503 CapacityCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
e237e7ae 504\r
505 Status = UsbBootExecCmdWithRetry (\r
506 UsbMass,\r
507 &CapacityCmd,\r
c9325700 508 (UINT8) sizeof (USB_BOOT_READ_CAPACITY_CMD),\r
e237e7ae 509 EfiUsbDataIn,\r
510 &CapacityData,\r
511 sizeof (USB_BOOT_READ_CAPACITY_DATA),\r
512 USB_BOOT_GENERAL_CMD_TIMEOUT\r
513 );\r
514 if (EFI_ERROR (Status)) {\r
515 return Status;\r
516 }\r
517\r
d80ed2a7 518 //\r
519 // Get the information on media presence, block size, and last block number\r
520 // from READ CAPACITY data.\r
521 //\r
e237e7ae 522 Media->MediaPresent = TRUE;\r
d80ed2a7 523 Media->LastBlock = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.LastLba));\r
e237e7ae 524\r
88e349f1 525 BlockSize = SwapBytes32 (ReadUnaligned32 ((CONST UINT32 *) CapacityData.BlockLen));\r
526 if (BlockSize == 0) {\r
efe9186f 527 //\r
528 // Get sense data \r
529 //\r
530 return UsbBootRequestSense (UsbMass);\r
88e349f1 531 } else {\r
532 Media->BlockSize = BlockSize;\r
50fa1b3a 533 }\r
534\r
99c1725e 535 if (Media->LastBlock == 0xFFFFFFFF) {\r
536 Status = UsbBootReadCapacity16 (UsbMass);\r
537 if (!EFI_ERROR (Status)) {\r
538 UsbMass->Cdb16Byte = TRUE;\r
539 }\r
540 }\r
541\r
efe9186f 542 return Status;\r
e237e7ae 543}\r
544\r
e237e7ae 545/**\r
d80ed2a7 546 Retrieves SCSI mode sense information via MODE SENSE(6) command.\r
e237e7ae 547\r
d80ed2a7 548 @param UsbMass The device whose sense data is requested.\r
e237e7ae 549\r
d80ed2a7 550 @retval EFI_SUCCESS SCSI mode sense information retrieved successfully.\r
551 @retval Other Command execution failed.\r
e237e7ae 552\r
553**/\r
554EFI_STATUS\r
50fa1b3a 555UsbScsiModeSense (\r
e237e7ae 556 IN USB_MASS_DEVICE *UsbMass\r
557 )\r
558{\r
ca12415a 559 EFI_STATUS Status;\r
50fa1b3a 560 USB_SCSI_MODE_SENSE6_CMD ModeSenseCmd;\r
561 USB_SCSI_MODE_SENSE6_PARA_HEADER ModeParaHeader;\r
562 EFI_BLOCK_IO_MEDIA *Media;\r
563\r
ca12415a 564 Media = &UsbMass->BlockIoMedia;\r
e237e7ae 565\r
50fa1b3a 566 ZeroMem (&ModeSenseCmd, sizeof (USB_SCSI_MODE_SENSE6_CMD));\r
567 ZeroMem (&ModeParaHeader, sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER));\r
e237e7ae 568\r
569 //\r
d80ed2a7 570 // MODE SENSE(6) command is defined in Section 8.2.10 of SCSI-2 Spec\r
e237e7ae 571 //\r
50fa1b3a 572 ModeSenseCmd.OpCode = USB_SCSI_MODE_SENSE6_OPCODE;\r
687a2e5f 573 ModeSenseCmd.Lun = (UINT8) USB_BOOT_LUN (UsbMass->Lun);\r
50fa1b3a 574 ModeSenseCmd.PageCode = 0x3F;\r
575 ModeSenseCmd.AllocateLen = (UINT8) sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER);\r
e237e7ae 576\r
577 Status = UsbBootExecCmdWithRetry (\r
578 UsbMass,\r
579 &ModeSenseCmd,\r
c9325700 580 (UINT8) sizeof (USB_SCSI_MODE_SENSE6_CMD),\r
e237e7ae 581 EfiUsbDataIn,\r
582 &ModeParaHeader,\r
50fa1b3a 583 sizeof (USB_SCSI_MODE_SENSE6_PARA_HEADER),\r
e237e7ae 584 USB_BOOT_GENERAL_CMD_TIMEOUT\r
585 );\r
50fa1b3a 586\r
e237e7ae 587 //\r
d80ed2a7 588 // Format of device-specific parameter byte of the mode parameter header is defined in\r
589 // Section 8.2.10 of SCSI-2 Spec.\r
590 // BIT7 of this byte is indicates whether the medium is write protected.\r
e237e7ae 591 //\r
50fa1b3a 592 if (!EFI_ERROR (Status)) {\r
d80ed2a7 593 Media->ReadOnly = (BOOLEAN) ((ModeParaHeader.DevicePara & BIT7) != 0);\r
50fa1b3a 594 }\r
e237e7ae 595\r
596 return Status;\r
597}\r
598\r
599\r
600/**\r
d80ed2a7 601 Get the parameters for the USB mass storage media.\r
602\r
603 This function get the parameters for the USB mass storage media,\r
604 It is used both to initialize the media during the Start() phase\r
605 of Driver Binding Protocol and to re-initialize it when the media is\r
e237e7ae 606 changed. Althought the RemoveableMedia is unlikely to change,\r
d80ed2a7 607 it is also included here.\r
e237e7ae 608\r
d80ed2a7 609 @param UsbMass The device to retrieve disk gemotric.\r
e237e7ae 610\r
611 @retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r
d80ed2a7 612 @retval Other Failed to get the parameters.\r
e237e7ae 613\r
614**/\r
615EFI_STATUS\r
616UsbBootGetParams (\r
617 IN USB_MASS_DEVICE *UsbMass\r
618 )\r
619{\r
620 EFI_BLOCK_IO_MEDIA *Media;\r
621 EFI_STATUS Status;\r
50fa1b3a 622\r
ca12415a 623 Media = &(UsbMass->BlockIoMedia);\r
e237e7ae 624\r
625 Status = UsbBootInquiry (UsbMass);\r
626 if (EFI_ERROR (Status)) {\r
1c619535 627 DEBUG ((EFI_D_ERROR, "UsbBootGetParams: UsbBootInquiry (%r)\n", Status));\r
e237e7ae 628 return Status;\r
629 }\r
630\r
e237e7ae 631 //\r
d80ed2a7 632 // Don't use the Removable bit in inquiry data to test whether the media\r
e237e7ae 633 // is removable because many flash disks wrongly set this bit.\r
634 //\r
635 if ((UsbMass->Pdt == USB_PDT_CDROM) || (UsbMass->Pdt == USB_PDT_OPTICAL)) {\r
636 //\r
50fa1b3a 637 // CD-Rom device and Non-CD optical device\r
e237e7ae 638 //\r
639 UsbMass->OpticalStorage = TRUE;\r
640 //\r
641 // Default value 2048 Bytes, in case no media present at first time\r
642 //\r
643 Media->BlockSize = 0x0800;\r
50fa1b3a 644 }\r
645\r
19bc8527 646 Status = UsbBootDetectMedia (UsbMass);\r
e237e7ae 647\r
19bc8527 648 return Status;\r
e237e7ae 649}\r
650\r
651\r
652/**\r
653 Detect whether the removable media is present and whether it has changed.\r
e237e7ae 654\r
d80ed2a7 655 @param UsbMass The device to check.\r
e237e7ae 656\r
d80ed2a7 657 @retval EFI_SUCCESS The media status is successfully checked.\r
658 @retval Other Failed to detect media.\r
e237e7ae 659\r
660**/\r
661EFI_STATUS\r
662UsbBootDetectMedia (\r
663 IN USB_MASS_DEVICE *UsbMass\r
664 )\r
665{\r
666 EFI_BLOCK_IO_MEDIA OldMedia;\r
667 EFI_BLOCK_IO_MEDIA *Media;\r
50fa1b3a 668 UINT8 CmdSet;\r
669 EFI_TPL OldTpl;\r
e237e7ae 670 EFI_STATUS Status;\r
671\r
672 Media = &UsbMass->BlockIoMedia;\r
e61d30b0 673\r
d80ed2a7 674 CopyMem (&OldMedia, &(UsbMass->BlockIoMedia), sizeof (EFI_BLOCK_IO_MEDIA));\r
e237e7ae 675\r
50fa1b3a 676 CmdSet = ((EFI_USB_INTERFACE_DESCRIPTOR *) (UsbMass->Context))->InterfaceSubClass;\r
677\r
e237e7ae 678 Status = UsbBootIsUnitReady (UsbMass);\r
19bc8527 679 if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {\r
50fa1b3a 680 goto ON_ERROR;\r
e237e7ae 681 }\r
50fa1b3a 682\r
683 if ((UsbMass->Pdt != USB_PDT_CDROM) && (CmdSet == USB_MASS_STORE_SCSI)) {\r
684 //\r
d80ed2a7 685 // MODE SENSE is required for the device with PDT of 0x00/0x07/0x0E,\r
686 // according to Section 4 of USB Mass Storage Specification for Bootability.\r
687 // MODE SENSE(10) is useless here, while MODE SENSE(6) defined in SCSI\r
688 // could get the information of Write Protected.\r
689 // Since not all device support this command, skip if fail.\r
50fa1b3a 690 //\r
691 UsbScsiModeSense (UsbMass);\r
692 }\r
693\r
694 Status = UsbBootReadCapacity (UsbMass);\r
e237e7ae 695 if (EFI_ERROR (Status)) {\r
1c619535 696 DEBUG ((EFI_D_ERROR, "UsbBootDetectMedia: UsbBootReadCapacity (%r)\n", Status));\r
50fa1b3a 697 goto ON_ERROR;\r
e237e7ae 698 }\r
699\r
50fa1b3a 700 return EFI_SUCCESS;\r
701\r
702ON_ERROR:\r
e237e7ae 703 //\r
d80ed2a7 704 // Detect whether it is necessary to reinstall the Block I/O Protocol.\r
e237e7ae 705 //\r
50fa1b3a 706 // MediaId may change in RequestSense for MediaChanged\r
707 // MediaPresent may change in RequestSense for NoMedia\r
708 // MediaReadOnly may change in RequestSense for WriteProtected or MediaChanged\r
709 // MediaPresent/BlockSize/LastBlock may change in ReadCapacity\r
710 //\r
e237e7ae 711 if ((Media->MediaId != OldMedia.MediaId) ||\r
712 (Media->MediaPresent != OldMedia.MediaPresent) ||\r
713 (Media->ReadOnly != OldMedia.ReadOnly) ||\r
714 (Media->BlockSize != OldMedia.BlockSize) ||\r
715 (Media->LastBlock != OldMedia.LastBlock)) {\r
50fa1b3a 716\r
d80ed2a7 717 //\r
718 // This function is called by Block I/O Protocol APIs, which run at TPL_NOTIFY.\r
719 // Here we temporarily restore TPL to TPL_CALLBACK to invoke ReinstallProtocolInterface().\r
720 //\r
721 OldTpl = EfiGetCurrentTpl ();\r
50fa1b3a 722 gBS->RestoreTPL (TPL_CALLBACK);\r
723\r
e237e7ae 724 gBS->ReinstallProtocolInterface (\r
725 UsbMass->Controller,\r
726 &gEfiBlockIoProtocolGuid,\r
727 &UsbMass->BlockIo,\r
728 &UsbMass->BlockIo\r
729 );\r
50fa1b3a 730\r
d80ed2a7 731 ASSERT (EfiGetCurrentTpl () == TPL_CALLBACK);\r
50fa1b3a 732 gBS->RaiseTPL (OldTpl);\r
733\r
e237e7ae 734 //\r
d80ed2a7 735 // Update MediaId after reinstalling Block I/O Protocol.\r
e237e7ae 736 //\r
50fa1b3a 737 if (Media->MediaPresent != OldMedia.MediaPresent) {\r
d80ed2a7 738 if (Media->MediaPresent) {\r
50fa1b3a 739 Media->MediaId = 1;\r
740 } else {\r
741 Media->MediaId = 0;\r
742 }\r
e237e7ae 743 }\r
50fa1b3a 744\r
745 if ((Media->ReadOnly != OldMedia.ReadOnly) ||\r
746 (Media->BlockSize != OldMedia.BlockSize) ||\r
747 (Media->LastBlock != OldMedia.LastBlock)) {\r
748 Media->MediaId++;\r
e237e7ae 749 }\r
750 }\r
751\r
752 return Status;\r
753}\r
754\r
755\r
756/**\r
757 Read some blocks from the device.\r
758\r
759 @param UsbMass The USB mass storage device to read from\r
760 @param Lba The start block number\r
761 @param TotalBlock Total block number to read\r
762 @param Buffer The buffer to read to\r
763\r
764 @retval EFI_SUCCESS Data are read into the buffer\r
765 @retval Others Failed to read all the data\r
766\r
767**/\r
768EFI_STATUS\r
769UsbBootReadBlocks (\r
770 IN USB_MASS_DEVICE *UsbMass,\r
771 IN UINT32 Lba,\r
772 IN UINTN TotalBlock,\r
773 OUT UINT8 *Buffer\r
774 )\r
775{\r
776 USB_BOOT_READ10_CMD ReadCmd;\r
777 EFI_STATUS Status;\r
778 UINT16 Count;\r
779 UINT32 BlockSize;\r
780 UINT32 ByteSize;\r
781 UINT32 Timeout;\r
782\r
783 BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
784 Status = EFI_SUCCESS;\r
785\r
786 while (TotalBlock > 0) {\r
787 //\r
788 // Split the total blocks into smaller pieces to ease the pressure\r
789 // on the device. We must split the total block because the READ10\r
790 // command only has 16 bit transfer length (in the unit of block).\r
791 //\r
792 Count = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
793 ByteSize = (UINT32)Count * BlockSize;\r
794\r
795 //\r
50fa1b3a 796 // USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]\r
e237e7ae 797 //\r
50fa1b3a 798 Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;\r
e237e7ae 799\r
800 //\r
801 // Fill in the command then execute\r
802 //\r
803 ZeroMem (&ReadCmd, sizeof (USB_BOOT_READ10_CMD));\r
804\r
805 ReadCmd.OpCode = USB_BOOT_READ10_OPCODE;\r
c52fa98c 806 ReadCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
d80ed2a7 807 WriteUnaligned32 ((UINT32 *) ReadCmd.Lba, SwapBytes32 (Lba));\r
808 WriteUnaligned16 ((UINT16 *) ReadCmd.TransferLen, SwapBytes16 (Count));\r
e237e7ae 809\r
810 Status = UsbBootExecCmdWithRetry (\r
811 UsbMass,\r
812 &ReadCmd,\r
c9325700 813 (UINT8) sizeof (USB_BOOT_READ10_CMD),\r
e237e7ae 814 EfiUsbDataIn,\r
815 Buffer,\r
816 ByteSize,\r
817 Timeout\r
818 );\r
819 if (EFI_ERROR (Status)) {\r
820 return Status;\r
821 }\r
99c1725e 822 DEBUG ((EFI_D_BLKIO, "UsbBootReadBlocks: LBA (0x%x), Blk (0x%x)\n", Lba, Count));\r
e237e7ae 823 Lba += Count;\r
824 Buffer += Count * BlockSize;\r
825 TotalBlock -= Count;\r
826 }\r
827\r
828 return Status;\r
829}\r
830\r
831\r
832/**\r
833 Write some blocks to the device.\r
834\r
835 @param UsbMass The USB mass storage device to write to\r
836 @param Lba The start block number\r
837 @param TotalBlock Total block number to write\r
d80ed2a7 838 @param Buffer Pointer to the source buffer for the data.\r
e237e7ae 839\r
840 @retval EFI_SUCCESS Data are written into the buffer\r
841 @retval Others Failed to write all the data\r
842\r
843**/\r
844EFI_STATUS\r
845UsbBootWriteBlocks (\r
846 IN USB_MASS_DEVICE *UsbMass,\r
847 IN UINT32 Lba,\r
848 IN UINTN TotalBlock,\r
d80ed2a7 849 IN UINT8 *Buffer\r
e237e7ae 850 )\r
851{\r
852 USB_BOOT_WRITE10_CMD WriteCmd;\r
853 EFI_STATUS Status;\r
854 UINT16 Count;\r
855 UINT32 BlockSize;\r
856 UINT32 ByteSize;\r
857 UINT32 Timeout;\r
858\r
859 BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
860 Status = EFI_SUCCESS;\r
861\r
862 while (TotalBlock > 0) {\r
863 //\r
864 // Split the total blocks into smaller pieces to ease the pressure\r
865 // on the device. We must split the total block because the WRITE10\r
866 // command only has 16 bit transfer length (in the unit of block).\r
867 //\r
868 Count = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
869 ByteSize = (UINT32)Count * BlockSize;\r
870\r
871 //\r
50fa1b3a 872 // USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]\r
e237e7ae 873 //\r
50fa1b3a 874 Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;\r
e237e7ae 875\r
876 //\r
877 // Fill in the write10 command block\r
878 //\r
879 ZeroMem (&WriteCmd, sizeof (USB_BOOT_WRITE10_CMD));\r
880\r
881 WriteCmd.OpCode = USB_BOOT_WRITE10_OPCODE;\r
c52fa98c 882 WriteCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
d80ed2a7 883 WriteUnaligned32 ((UINT32 *) WriteCmd.Lba, SwapBytes32 (Lba));\r
884 WriteUnaligned16 ((UINT16 *) WriteCmd.TransferLen, SwapBytes16 (Count));\r
e237e7ae 885\r
886 Status = UsbBootExecCmdWithRetry (\r
887 UsbMass,\r
888 &WriteCmd,\r
c9325700 889 (UINT8) sizeof (USB_BOOT_WRITE10_CMD),\r
e237e7ae 890 EfiUsbDataOut,\r
891 Buffer,\r
892 ByteSize,\r
893 Timeout\r
894 );\r
895 if (EFI_ERROR (Status)) {\r
896 return Status;\r
897 }\r
99c1725e 898 DEBUG ((EFI_D_BLKIO, "UsbBootWriteBlocks: LBA (0x%x), Blk (0x%x)\n", Lba, Count));\r
899\r
900 Lba += Count;\r
901 Buffer += Count * BlockSize;\r
902 TotalBlock -= Count;\r
903 }\r
904\r
905 return Status;\r
906}\r
907\r
908/**\r
909 Read some blocks from the device by SCSI 16 byte cmd.\r
910\r
911 @param UsbMass The USB mass storage device to read from\r
912 @param Lba The start block number\r
913 @param TotalBlock Total block number to read\r
914 @param Buffer The buffer to read to\r
915\r
916 @retval EFI_SUCCESS Data are read into the buffer\r
917 @retval Others Failed to read all the data\r
918\r
919**/\r
920EFI_STATUS\r
921UsbBootReadBlocks16 (\r
922 IN USB_MASS_DEVICE *UsbMass,\r
923 IN UINT64 Lba,\r
924 IN UINTN TotalBlock,\r
925 OUT UINT8 *Buffer\r
926 )\r
927{\r
928 UINT8 ReadCmd[16];\r
929 EFI_STATUS Status;\r
930 UINT16 Count;\r
931 UINT32 BlockSize;\r
932 UINT32 ByteSize;\r
933 UINT32 Timeout;\r
934\r
935 BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
936 Status = EFI_SUCCESS;\r
937\r
938 while (TotalBlock > 0) {\r
939 //\r
940 // Split the total blocks into smaller pieces.\r
941 //\r
942 Count = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
943 ByteSize = (UINT32)Count * BlockSize;\r
944\r
945 //\r
946 // USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]\r
947 //\r
948 Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;\r
949\r
950 //\r
951 // Fill in the command then execute\r
952 //\r
953 ZeroMem (ReadCmd, sizeof (ReadCmd));\r
954\r
955 ReadCmd[0] = EFI_SCSI_OP_READ16;\r
956 ReadCmd[1] = (UINT8) ((USB_BOOT_LUN (UsbMass->Lun) & 0xE0));\r
957 WriteUnaligned64 ((UINT64 *) &ReadCmd[2], SwapBytes64 (Lba));\r
958 WriteUnaligned32 ((UINT32 *) &ReadCmd[10], SwapBytes32 (Count));\r
959\r
960 Status = UsbBootExecCmdWithRetry (\r
961 UsbMass,\r
962 ReadCmd,\r
963 (UINT8) sizeof (ReadCmd),\r
964 EfiUsbDataIn,\r
965 Buffer,\r
966 ByteSize,\r
967 Timeout\r
968 );\r
969 if (EFI_ERROR (Status)) {\r
970 return Status;\r
971 }\r
972 DEBUG ((EFI_D_BLKIO, "UsbBootReadBlocks16: LBA (0x%lx), Blk (0x%x)\n", Lba, Count));\r
973 Lba += Count;\r
974 Buffer += Count * BlockSize;\r
975 TotalBlock -= Count;\r
976 }\r
977\r
978 return Status;\r
979}\r
980\r
981\r
982/**\r
983 Write some blocks to the device by SCSI 16 byte cmd.\r
984\r
985 @param UsbMass The USB mass storage device to write to\r
986 @param Lba The start block number\r
987 @param TotalBlock Total block number to write\r
988 @param Buffer Pointer to the source buffer for the data.\r
989\r
990 @retval EFI_SUCCESS Data are written into the buffer\r
991 @retval Others Failed to write all the data\r
992\r
993**/\r
994EFI_STATUS\r
995UsbBootWriteBlocks16 (\r
996 IN USB_MASS_DEVICE *UsbMass,\r
997 IN UINT64 Lba,\r
998 IN UINTN TotalBlock,\r
999 IN UINT8 *Buffer\r
1000 )\r
1001{\r
1002 UINT8 WriteCmd[16];\r
1003 EFI_STATUS Status;\r
1004 UINT16 Count;\r
1005 UINT32 BlockSize;\r
1006 UINT32 ByteSize;\r
1007 UINT32 Timeout;\r
1008\r
1009 BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
1010 Status = EFI_SUCCESS;\r
1011\r
1012 while (TotalBlock > 0) {\r
1013 //\r
1014 // Split the total blocks into smaller pieces.\r
1015 //\r
1016 Count = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
1017 ByteSize = (UINT32)Count * BlockSize;\r
1018\r
1019 //\r
1020 // USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]\r
1021 //\r
1022 Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;\r
1023\r
1024 //\r
1025 // Fill in the write16 command block\r
1026 //\r
1027 ZeroMem (WriteCmd, sizeof (WriteCmd));\r
1028\r
1029 WriteCmd[0] = EFI_SCSI_OP_WRITE16;\r
1030 WriteCmd[1] = (UINT8) ((USB_BOOT_LUN (UsbMass->Lun) & 0xE0));\r
1031 WriteUnaligned64 ((UINT64 *) &WriteCmd[2], SwapBytes64 (Lba));\r
1032 WriteUnaligned32 ((UINT32 *) &WriteCmd[10], SwapBytes32 (Count));\r
1033\r
1034 Status = UsbBootExecCmdWithRetry (\r
1035 UsbMass,\r
1036 WriteCmd,\r
1037 (UINT8) sizeof (WriteCmd),\r
1038 EfiUsbDataOut,\r
1039 Buffer,\r
1040 ByteSize,\r
1041 Timeout\r
1042 );\r
1043 if (EFI_ERROR (Status)) {\r
1044 return Status;\r
1045 }\r
1046 DEBUG ((EFI_D_BLKIO, "UsbBootWriteBlocks: LBA (0x%lx), Blk (0x%x)\n", Lba, Count));\r
e237e7ae 1047 Lba += Count;\r
1048 Buffer += Count * BlockSize;\r
1049 TotalBlock -= Count;\r
1050 }\r
1051\r
1052 return Status;\r
1053}\r
1054\r
e237e7ae 1055/**\r
d80ed2a7 1056 Use the USB clear feature control transfer to clear the endpoint stall condition.\r
e237e7ae 1057\r
d80ed2a7 1058 @param UsbIo The USB I/O Protocol instance\r
e237e7ae 1059 @param EndpointAddr The endpoint to clear stall for\r
1060\r
d80ed2a7 1061 @retval EFI_SUCCESS The endpoint stall condition is cleared.\r
1062 @retval Others Failed to clear the endpoint stall condition.\r
e237e7ae 1063\r
1064**/\r
1065EFI_STATUS\r
1066UsbClearEndpointStall (\r
1067 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
1068 IN UINT8 EndpointAddr\r
1069 )\r
1070{\r
1071 EFI_USB_DEVICE_REQUEST Request;\r
1072 EFI_STATUS Status;\r
1073 UINT32 CmdResult;\r
1074 UINT32 Timeout;\r
1075\r
1076 Request.RequestType = 0x02;\r
1077 Request.Request = USB_REQ_CLEAR_FEATURE;\r
1078 Request.Value = USB_FEATURE_ENDPOINT_HALT;\r
1079 Request.Index = EndpointAddr;\r
1080 Request.Length = 0;\r
41e8ff27 1081 Timeout = USB_BOOT_GENERAL_CMD_TIMEOUT / USB_MASS_1_MILLISECOND;\r
e237e7ae 1082\r
1083 Status = UsbIo->UsbControlTransfer (\r
1084 UsbIo,\r
1085 &Request,\r
1086 EfiUsbNoData,\r
1087 Timeout,\r
1088 NULL,\r
1089 0,\r
1090 &CmdResult\r
1091 );\r
1092\r
1093 return Status;\r
1094}\r