]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassCbi.c
Minor refinement for USB modules.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassCbi.c
CommitLineData
e237e7ae 1/** @file\r
d80ed2a7 2 Implementation of the USB mass storage Control/Bulk/Interrupt transport,\r
3 according to USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport, Revision 1.1.\r
d7db0902 4 Notice: it is being obsoleted by the standard body in favor of the BOT\r
cc5166ff 5 (Bulk-Only Transport).\r
6\r
c7e39923 7Copyright (c) 2007 - 2008, Intel Corporation\r
e237e7ae 8All rights reserved. This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
cc5166ff 16**/\r
e237e7ae 17\r
3e03cb4d 18#include "UsbMassBoot.h"\r
cc5166ff 19#include "UsbMassCbi.h"\r
e237e7ae 20\r
d80ed2a7 21//\r
22// Definition of USB CBI0 Transport Protocol\r
23//\r
24USB_MASS_TRANSPORT mUsbCbi0Transport = {\r
25 USB_MASS_STORE_CBI0,\r
26 UsbCbiInit,\r
27 UsbCbiExecCommand,\r
28 UsbCbiResetDevice,\r
29 NULL,\r
30 UsbCbiCleanUp\r
31};\r
e237e7ae 32\r
d80ed2a7 33//\r
34// Definition of USB CBI1 Transport Protocol\r
35//\r
36USB_MASS_TRANSPORT mUsbCbi1Transport = {\r
37 USB_MASS_STORE_CBI1,\r
38 UsbCbiInit,\r
39 UsbCbiExecCommand,\r
40 UsbCbiResetDevice,\r
41 NULL,\r
42 UsbCbiCleanUp\r
43};\r
e237e7ae 44\r
45/**\r
d80ed2a7 46 Initializes USB CBI protocol.\r
47\r
48 This function initializes the USB mass storage class CBI protocol.\r
49 It will save its context which is a USB_CBI_PROTOCOL structure\r
50 in the Context if Context isn't NULL.\r
e237e7ae 51\r
d80ed2a7 52 @param UsbIo The USB I/O Protocol instance\r
53 @param Context The buffer to save the context to\r
e237e7ae 54\r
d80ed2a7 55 @retval EFI_SUCCESS The device is successfully initialized.\r
56 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.\r
57 @retval Other The USB CBI initialization fails.\r
e237e7ae 58\r
59**/\r
e237e7ae 60EFI_STATUS\r
61UsbCbiInit (\r
62 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
e237e7ae 63 OUT VOID **Context OPTIONAL\r
64 )\r
65{\r
66 USB_CBI_PROTOCOL *UsbCbi;\r
67 EFI_USB_INTERFACE_DESCRIPTOR *Interface;\r
68 EFI_USB_ENDPOINT_DESCRIPTOR EndPoint;\r
69 EFI_STATUS Status;\r
70 UINT8 Index;\r
71\r
72 //\r
d80ed2a7 73 // Allocate the CBI context for USB_CBI_PROTOCOL and 3 endpoint descriptors.\r
e237e7ae 74 //\r
75 UsbCbi = AllocateZeroPool (\r
76 sizeof (USB_CBI_PROTOCOL) + 3 * sizeof (EFI_USB_ENDPOINT_DESCRIPTOR)\r
77 );\r
d80ed2a7 78 ASSERT (UsbCbi != NULL);\r
e237e7ae 79\r
80 UsbCbi->UsbIo = UsbIo;\r
81\r
82 //\r
d80ed2a7 83 // Get the interface descriptor and validate that it\r
84 // is a USB Mass Storage CBI interface.\r
e237e7ae 85 //\r
86 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &UsbCbi->Interface);\r
87 if (EFI_ERROR (Status)) {\r
88 goto ON_ERROR;\r
89 }\r
90\r
91 Interface = &UsbCbi->Interface;\r
92 if ((Interface->InterfaceProtocol != USB_MASS_STORE_CBI0)\r
93 && (Interface->InterfaceProtocol != USB_MASS_STORE_CBI1)) {\r
94 Status = EFI_UNSUPPORTED;\r
95 goto ON_ERROR;\r
96 }\r
97\r
98 //\r
99 // Locate and save the bulk-in, bulk-out, and interrupt endpoint\r
100 //\r
101 for (Index = 0; Index < Interface->NumEndpoints; Index++) {\r
102 Status = UsbIo->UsbGetEndpointDescriptor (UsbIo, Index, &EndPoint);\r
103 if (EFI_ERROR (Status)) {\r
104 continue;\r
105 }\r
106\r
107 if (USB_IS_BULK_ENDPOINT (EndPoint.Attributes)) {\r
108 //\r
109 // Use the first Bulk-In and Bulk-Out endpoints\r
110 //\r
111 if (USB_IS_IN_ENDPOINT (EndPoint.EndpointAddress) &&\r
112 (UsbCbi->BulkInEndpoint == NULL)) {\r
113\r
114 UsbCbi->BulkInEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1);\r
84b5c78e 115 CopyMem(UsbCbi->BulkInEndpoint, &EndPoint, sizeof (EndPoint));;\r
e237e7ae 116 }\r
117\r
118 if (USB_IS_OUT_ENDPOINT (EndPoint.EndpointAddress) &&\r
119 (UsbCbi->BulkOutEndpoint == NULL)) {\r
120\r
121 UsbCbi->BulkOutEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1) + 1;\r
84b5c78e 122 CopyMem(UsbCbi->BulkOutEndpoint, &EndPoint, sizeof (EndPoint));\r
e237e7ae 123 }\r
e237e7ae 124 } else if (USB_IS_INTERRUPT_ENDPOINT (EndPoint.Attributes)) {\r
125 //\r
126 // Use the first interrupt endpoint if it is CBI0\r
127 //\r
128 if ((Interface->InterfaceProtocol == USB_MASS_STORE_CBI0) &&\r
129 (UsbCbi->InterruptEndpoint == NULL)) {\r
130\r
131 UsbCbi->InterruptEndpoint = (EFI_USB_ENDPOINT_DESCRIPTOR *) (UsbCbi + 1) + 2;\r
84b5c78e 132 CopyMem(UsbCbi->InterruptEndpoint, &EndPoint, sizeof (EndPoint));\r
e237e7ae 133 }\r
134 }\r
135 }\r
136\r
d80ed2a7 137 if ((UsbCbi->BulkInEndpoint == NULL) || (UsbCbi->BulkOutEndpoint == NULL)) {\r
138 Status = EFI_UNSUPPORTED;\r
139 goto ON_ERROR;\r
140 }\r
141 if ((Interface->InterfaceProtocol == USB_MASS_STORE_CBI0) && (UsbCbi->InterruptEndpoint == NULL)) {\r
e237e7ae 142 Status = EFI_UNSUPPORTED;\r
143 goto ON_ERROR;\r
144 }\r
145\r
146 if (Context != NULL) {\r
147 *Context = UsbCbi;\r
148 } else {\r
c92e277d 149 FreePool (UsbCbi);\r
e237e7ae 150 }\r
d80ed2a7 151 \r
e237e7ae 152 return EFI_SUCCESS;\r
153\r
154ON_ERROR:\r
c92e277d 155 FreePool (UsbCbi);\r
e237e7ae 156 return Status;\r
157}\r
158\r
e237e7ae 159/**\r
160 Send the command to the device using class specific control transfer.\r
161\r
d80ed2a7 162 This function sends command to the device using class specific control transfer.\r
163 The CBI contains three phases: Command, Data, and Status. This is Command phase.\r
164\r
e237e7ae 165 @param UsbCbi The USB CBI protocol\r
166 @param Cmd The high level command to transfer to device\r
167 @param CmdLen The length of the command\r
168 @param Timeout The time to wait the command to finish\r
169\r
d80ed2a7 170 @retval EFI_SUCCESS The command is sent to the device.\r
e237e7ae 171 @retval Others The command failed to transfer to device\r
172\r
173**/\r
e237e7ae 174EFI_STATUS\r
175UsbCbiSendCommand (\r
176 IN USB_CBI_PROTOCOL *UsbCbi,\r
177 IN UINT8 *Cmd,\r
178 IN UINT8 CmdLen,\r
179 IN UINT32 Timeout\r
180 )\r
181{\r
182 EFI_USB_DEVICE_REQUEST Request;\r
183 EFI_STATUS Status;\r
184 UINT32 TransStatus;\r
185 UINTN DataLen;\r
186 INTN Retry;\r
187\r
188 //\r
189 // Fill in the device request, CBI use the "Accept Device-Specific\r
d80ed2a7 190 // Cmd" (ADSC) class specific request to send commands.\r
e237e7ae 191 //\r
192 Request.RequestType = 0x21;\r
193 Request.Request = 0;\r
194 Request.Value = 0;\r
195 Request.Index = UsbCbi->Interface.InterfaceNumber;\r
196 Request.Length = CmdLen;\r
197\r
198 Status = EFI_SUCCESS;\r
41e8ff27 199 Timeout = Timeout / USB_MASS_1_MILLISECOND;\r
e237e7ae 200\r
201 for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {\r
202 //\r
d80ed2a7 203 // Use USB I/O Protocol to send the command to the device\r
e237e7ae 204 //\r
205 TransStatus = 0;\r
206 DataLen = CmdLen;\r
207\r
208 Status = UsbCbi->UsbIo->UsbControlTransfer (\r
209 UsbCbi->UsbIo,\r
210 &Request,\r
211 EfiUsbDataOut,\r
212 Timeout,\r
213 Cmd,\r
214 DataLen,\r
215 &TransStatus\r
216 );\r
217 //\r
218 // The device can fail the command by STALL the control endpoint.\r
219 // It can delay the command by NAK the data or status stage, this\r
220 // is a "class-specific exemption to the USB specification". Retry\r
221 // if the command is NAKed.\r
222 //\r
223 if (EFI_ERROR (Status) && (TransStatus == EFI_USB_ERR_NAK)) {\r
224 continue;\r
225 }\r
226\r
227 break;\r
228 }\r
229\r
230 return Status;\r
231}\r
232\r
233\r
234/**\r
d80ed2a7 235 Transfer data between the device and host.\r
236\r
237 This function transfers data between the device and host.\r
238 The CBI contains three phases: Command, Data, and Status. This is Data phase.\r
e237e7ae 239\r
240 @param UsbCbi The USB CBI device\r
241 @param DataDir The direction of the data transfer\r
d80ed2a7 242 @param Data The buffer to hold the data for input or output.\r
243 @param TransLen On input, the expected transfer length.\r
244 On output, the length of data actually transferred.\r
245 @param Timeout The time to wait for the command to execute\r
e237e7ae 246\r
d80ed2a7 247 @retval EFI_SUCCESS The data transferred successfully.\r
248 @retval EFI_SUCCESS No data to transfer\r
e237e7ae 249 @retval Others Failed to transfer all the data\r
250\r
251**/\r
e237e7ae 252EFI_STATUS\r
253UsbCbiDataTransfer (\r
254 IN USB_CBI_PROTOCOL *UsbCbi,\r
255 IN EFI_USB_DATA_DIRECTION DataDir,\r
256 IN OUT UINT8 *Data,\r
257 IN OUT UINTN *TransLen,\r
258 IN UINT32 Timeout\r
259 )\r
260{\r
261 EFI_USB_ENDPOINT_DESCRIPTOR *Endpoint;\r
262 EFI_STATUS Status;\r
263 UINT32 TransStatus;\r
264 UINTN Remain;\r
265 UINTN Increment;\r
266 UINT8 *Next;\r
267 UINTN Retry;\r
268\r
269 //\r
d80ed2a7 270 // If no data to transfer, just return EFI_SUCCESS.\r
e237e7ae 271 //\r
272 if ((DataDir == EfiUsbNoData) || (*TransLen == 0)) {\r
273 return EFI_SUCCESS;\r
274 }\r
275\r
276 //\r
277 // Select the endpoint then issue the transfer\r
278 //\r
279 if (DataDir == EfiUsbDataIn) {\r
280 Endpoint = UsbCbi->BulkInEndpoint;\r
281 } else {\r
282 Endpoint = UsbCbi->BulkOutEndpoint;\r
283 }\r
284\r
285 Next = Data;\r
286 Remain = *TransLen;\r
287 Retry = 0;\r
288 Status = EFI_SUCCESS;\r
41e8ff27 289 Timeout = Timeout / USB_MASS_1_MILLISECOND;\r
e237e7ae 290\r
291 //\r
d80ed2a7 292 // Transfer the data with a loop. The length of data transferred once is restricted.\r
e237e7ae 293 //\r
294 while (Remain > 0) {\r
295 TransStatus = 0;\r
296\r
297 if (Remain > (UINTN) USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize) {\r
298 Increment = USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize;\r
299 } else {\r
300 Increment = Remain;\r
301 }\r
302\r
303 Status = UsbCbi->UsbIo->UsbBulkTransfer (\r
304 UsbCbi->UsbIo,\r
305 Endpoint->EndpointAddress,\r
306 Next,\r
307 &Increment,\r
308 Timeout,\r
309 &TransStatus\r
310 );\r
311 if (EFI_ERROR (Status)) {\r
312 if (TransStatus == EFI_USB_ERR_NAK) {\r
313 //\r
314 // The device can NAK the host if either the data/buffer isn't\r
d80ed2a7 315 // aviable or the command is in-progress.\r
316 // If data are partially transferred, we just ignore NAK and continue.\r
317 // If all data have been transferred and status is NAK, then we retry for several times.\r
318 // If retry exceeds the USB_CBI_MAX_RETRY, then return error status.\r
e237e7ae 319 //\r
320 if (Increment == 0) {\r
321 if (++Retry > USB_CBI_MAX_RETRY) {\r
322 goto ON_EXIT;\r
323 }\r
e237e7ae 324 } else {\r
325 Next += Increment;\r
326 Remain -= Increment;\r
327 Retry = 0;\r
328 }\r
329\r
330 continue;\r
331 }\r
332\r
333 //\r
334 // The device can fail the command by STALL the bulk endpoint.\r
335 // Clear the stall if that is the case.\r
336 //\r
337 if (TransStatus == EFI_USB_ERR_STALL) {\r
338 UsbClearEndpointStall (UsbCbi->UsbIo, Endpoint->EndpointAddress);\r
339 }\r
340\r
341 goto ON_EXIT;\r
342 }\r
343\r
344 Next += Increment;\r
345 Remain -= Increment;\r
346 }\r
347\r
348ON_EXIT:\r
349 *TransLen -= Remain;\r
350 return Status;\r
351}\r
352\r
353\r
354/**\r
d80ed2a7 355 Gets the result of high level command execution from interrupt endpoint.\r
356\r
357 This function returns the USB transfer status, and put the high level\r
358 command execution result in Result.\r
359 The CBI contains three phases: Command, Data, and Status. This is Status phase.\r
e237e7ae 360\r
361 @param UsbCbi The USB CBI protocol\r
d80ed2a7 362 @param Timeout The time to wait for the command to execute\r
363 @param Result The result of the command execution.\r
e237e7ae 364\r
365 @retval EFI_SUCCESS The high level command execution result is\r
366 retrieved in Result.\r
367 @retval Others Failed to retrieve the result.\r
368\r
369**/\r
e237e7ae 370EFI_STATUS\r
371UsbCbiGetStatus (\r
372 IN USB_CBI_PROTOCOL *UsbCbi,\r
373 IN UINT32 Timeout,\r
374 OUT USB_CBI_STATUS *Result\r
375 )\r
376{\r
377 UINTN Len;\r
378 UINT8 Endpoint;\r
379 EFI_STATUS Status;\r
380 UINT32 TransStatus;\r
381 INTN Retry;\r
382\r
383 Endpoint = UsbCbi->InterruptEndpoint->EndpointAddress;\r
384 Status = EFI_SUCCESS;\r
41e8ff27 385 Timeout = Timeout / USB_MASS_1_MILLISECOND;\r
e237e7ae 386\r
387 //\r
388 // Attemp to the read the result from interrupt endpoint\r
389 //\r
390 for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {\r
391 TransStatus = 0;\r
392 Len = sizeof (USB_CBI_STATUS);\r
393\r
394 Status = UsbCbi->UsbIo->UsbSyncInterruptTransfer (\r
395 UsbCbi->UsbIo,\r
396 Endpoint,\r
397 Result,\r
398 &Len,\r
399 Timeout,\r
400 &TransStatus\r
401 );\r
402 //\r
403 // The CBI can NAK the interrupt endpoint if the command is in-progress.\r
404 //\r
405 if (EFI_ERROR (Status) && (TransStatus == EFI_USB_ERR_NAK)) {\r
406 continue;\r
407 }\r
408\r
409 break;\r
410 }\r
411\r
412 return Status;\r
413}\r
414\r
415\r
416/**\r
cc5166ff 417 Execute USB mass storage command through the CBI0/CBI1 transport protocol.\r
e237e7ae 418\r
d80ed2a7 419 @param Context The USB CBI Protocol.\r
e237e7ae 420 @param Cmd The command to transfer to device\r
421 @param CmdLen The length of the command\r
422 @param DataDir The direction of data transfer\r
423 @param Data The buffer to hold the data\r
424 @param DataLen The length of the buffer\r
c7e39923 425 @param Lun Should be 0, this field for bot only\r
e237e7ae 426 @param Timeout The time to wait\r
427 @param CmdStatus The result of the command execution\r
428\r
d80ed2a7 429 @retval EFI_SUCCESS The command is executed successfully.\r
cc5166ff 430 @retval Other Failed to execute the command\r
e237e7ae 431\r
432**/\r
e237e7ae 433EFI_STATUS\r
434UsbCbiExecCommand (\r
435 IN VOID *Context,\r
436 IN VOID *Cmd,\r
437 IN UINT8 CmdLen,\r
438 IN EFI_USB_DATA_DIRECTION DataDir,\r
439 IN VOID *Data,\r
440 IN UINT32 DataLen,\r
c7e39923 441 IN UINT8 Lun,\r
e237e7ae 442 IN UINT32 Timeout,\r
443 OUT UINT32 *CmdStatus\r
444 )\r
445{\r
446 USB_CBI_PROTOCOL *UsbCbi;\r
447 USB_CBI_STATUS Result;\r
448 EFI_STATUS Status;\r
449 UINTN TransLen;\r
450\r
451 *CmdStatus = USB_MASS_CMD_SUCCESS;\r
452 UsbCbi = (USB_CBI_PROTOCOL *) Context;\r
453\r
454 //\r
455 // Send the command to the device. Return immediately if device\r
456 // rejects the command.\r
457 //\r
458 Status = UsbCbiSendCommand (UsbCbi, Cmd, CmdLen, Timeout);\r
459 if (EFI_ERROR (Status)) {\r
1c619535 460 DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiSendCommand (%r)\n",Status));\r
e237e7ae 461 return Status;\r
462 }\r
463\r
464 //\r
d80ed2a7 465 // Transfer the data. Return this status if no interrupt endpoint\r
e237e7ae 466 // is used to report the transfer status.\r
467 //\r
468 TransLen = (UINTN) DataLen;\r
469\r
470 Status = UsbCbiDataTransfer (UsbCbi, DataDir, Data, &TransLen, Timeout);\r
471 if (UsbCbi->InterruptEndpoint == NULL) {\r
1c619535 472 DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n",Status));\r
e237e7ae 473 return Status;\r
474 }\r
475\r
476 //\r
d80ed2a7 477 // Get the status. If it succeeds, interpret the result.\r
e237e7ae 478 //\r
479 Status = UsbCbiGetStatus (UsbCbi, Timeout, &Result);\r
480 if (EFI_ERROR (Status)) {\r
1c619535 481 DEBUG ((EFI_D_ERROR, "UsbCbiExecCommand: UsbCbiGetStatus (%r)\n",Status));\r
d80ed2a7 482 return Status;\r
e237e7ae 483 }\r
484\r
485 if (UsbCbi->Interface.InterfaceSubClass == USB_MASS_STORE_UFI) {\r
486 //\r
487 // For UFI device, ASC and ASCQ are returned.\r
488 //\r
489 if (Result.Type != 0) {\r
490 *CmdStatus = USB_MASS_CMD_FAIL;\r
491 }\r
492\r
493 } else {\r
494 //\r
495 // Check page 27, CBI spec 1.1 for vaious reture status.\r
496 //\r
497 switch (Result.Value & 0x03) {\r
498 case 0x00:\r
499 //\r
500 // Pass\r
501 //\r
502 *CmdStatus = USB_MASS_CMD_SUCCESS;\r
503 break;\r
504\r
505 case 0x02:\r
506 //\r
d80ed2a7 507 // Phase Error, response with reset.\r
508 // No break here to fall through to "Fail".\r
e237e7ae 509 //\r
510 UsbCbiResetDevice (UsbCbi, FALSE);\r
511\r
512 case 0x01:\r
513 //\r
514 // Fail\r
515 //\r
516 *CmdStatus = USB_MASS_CMD_FAIL;\r
517 break;\r
518\r
519 case 0x03:\r
520 //\r
d80ed2a7 521 // Persistent Fail. Need to send REQUEST SENSE.\r
e237e7ae 522 //\r
523 *CmdStatus = USB_MASS_CMD_PERSISTENT;\r
524 break;\r
525 }\r
526 }\r
527\r
528 return EFI_SUCCESS;\r
529}\r
530\r
531\r
532/**\r
d80ed2a7 533 Reset the USB mass storage device by CBI protocol.\r
e237e7ae 534\r
d80ed2a7 535 This function resets the USB mass storage device by CBI protocol.\r
536 The reset is defined as a non-data command. Don't use UsbCbiExecCommand\r
537 to send the command to device because that may introduce recursive loop.\r
e237e7ae 538\r
d80ed2a7 539 @param Context The USB CBI protocol\r
540 @param ExtendedVerification The flag controlling the rule of reset.\r
541 Not used here.\r
542\r
543 @retval EFI_SUCCESS The device is reset.\r
544 @retval Others Failed to reset the device.\r
e237e7ae 545\r
546**/\r
e237e7ae 547EFI_STATUS\r
548UsbCbiResetDevice (\r
549 IN VOID *Context,\r
550 IN BOOLEAN ExtendedVerification\r
551 )\r
552{\r
553 UINT8 ResetCmd[USB_CBI_RESET_CMD_LEN];\r
554 USB_CBI_PROTOCOL *UsbCbi;\r
555 USB_CBI_STATUS Result;\r
556 EFI_STATUS Status;\r
557 UINT32 Timeout;\r
558\r
559 UsbCbi = (USB_CBI_PROTOCOL *) Context;\r
560\r
561 //\r
562 // Fill in the reset command.\r
563 //\r
564 SetMem (ResetCmd, USB_CBI_RESET_CMD_LEN, 0xFF);\r
565\r
566 ResetCmd[0] = 0x1D;\r
567 ResetCmd[1] = 0x04;\r
41e8ff27 568 Timeout = USB_CBI_RESET_DEVICE_TIMEOUT / USB_MASS_1_MILLISECOND;\r
e237e7ae 569\r
570 //\r
571 // Send the command to the device. Don't use UsbCbiExecCommand here.\r
572 //\r
573 Status = UsbCbiSendCommand (UsbCbi, ResetCmd, USB_CBI_RESET_CMD_LEN, Timeout);\r
574 if (EFI_ERROR (Status)) {\r
575 return Status;\r
576 }\r
577\r
578 //\r
579 // Just retrieve the status and ignore that. Then stall\r
d80ed2a7 580 // 50ms to wait for it to complete.\r
e237e7ae 581 //\r
582 UsbCbiGetStatus (UsbCbi, Timeout, &Result);\r
41e8ff27 583 gBS->Stall (USB_CBI_RESET_DEVICE_STALL);\r
e237e7ae 584\r
585 //\r
d80ed2a7 586 // Clear the Bulk-In and Bulk-Out stall condition and init data toggle.\r
e237e7ae 587 //\r
588 UsbClearEndpointStall (UsbCbi->UsbIo, UsbCbi->BulkInEndpoint->EndpointAddress);\r
589 UsbClearEndpointStall (UsbCbi->UsbIo, UsbCbi->BulkOutEndpoint->EndpointAddress);\r
d80ed2a7 590\r
e237e7ae 591 return Status;\r
592}\r
593\r
594\r
595/**\r
cc5166ff 596 Clean up the CBI protocol's resource.\r
e237e7ae 597\r
cc5166ff 598 @param Context The instance of CBI protocol.\r
e237e7ae 599\r
600 @retval EFI_SUCCESS The resource is cleaned up.\r
601\r
602**/\r
e237e7ae 603EFI_STATUS\r
d80ed2a7 604UsbCbiCleanUp (\r
e237e7ae 605 IN VOID *Context\r
606 )\r
607{\r
c92e277d 608 FreePool (Context);\r
e237e7ae 609 return EFI_SUCCESS;\r
610}\r