]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Bus/Usb/UsbCbi/Dxe/Cbi1/cbi1.c
Move the share file: cbi.h to Cbi0 and Cbi1 directory.
[mirror_edk2.git] / EdkModulePkg / Bus / Usb / UsbCbi / Dxe / Cbi1 / cbi1.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 cbi1.c
15
16 Abstract:
17 cbi1 transportation protocol implementation files
18
19 --*/
20
21 #include "cbi.h"
22
23 EFI_STATUS
24 EFIAPI
25 UsbCBI1DriverEntryPoint (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 );
29
30 //
31 // CBI Function prototypes
32 //
33 STATIC
34 EFI_STATUS
35 CBI1CommandPhase (
36 IN USB_CBI_DEVICE *UsbCbiDev,
37 IN VOID *Command,
38 IN UINT8 CommandSize,
39 OUT UINT32 *Result
40 );
41
42 STATIC
43 EFI_STATUS
44 CBI1DataPhase (
45 IN USB_CBI_DEVICE *UsbCbiDev,
46 IN UINT32 DataSize,
47 IN OUT VOID *DataBuffer,
48 IN EFI_USB_DATA_DIRECTION Direction,
49 IN UINT16 Timeout,
50 OUT UINT32 *Result
51 );
52
53 //
54 // USB Atapi implementation
55 //
56 STATIC
57 EFI_STATUS
58 EFIAPI
59 CBI1AtapiCommand (
60 IN EFI_USB_ATAPI_PROTOCOL *This,
61 IN VOID *Command,
62 IN UINT8 CommandSize,
63 IN VOID *DataBuffer,
64 IN UINT32 BufferLength,
65 IN EFI_USB_DATA_DIRECTION Direction,
66 IN UINT16 TimeOutInMilliSeconds
67 );
68
69 STATIC
70 EFI_STATUS
71 EFIAPI
72 CBI1MassStorageReset (
73 IN EFI_USB_ATAPI_PROTOCOL *This,
74 IN BOOLEAN ExtendedVerification
75 );
76
77 //
78 // CBI1 Driver Binding Protocol
79 //
80 STATIC
81 EFI_STATUS
82 EFIAPI
83 CBI1DriverBindingSupported (
84 IN EFI_DRIVER_BINDING_PROTOCOL *This,
85 IN EFI_HANDLE ControllerHandle,
86 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
87 );
88
89 STATIC
90 EFI_STATUS
91 EFIAPI
92 CBI1DriverBindingStart (
93 IN EFI_DRIVER_BINDING_PROTOCOL *This,
94 IN EFI_HANDLE ControllerHandle,
95 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
96 );
97
98 STATIC
99 EFI_STATUS
100 EFIAPI
101 CBI1DriverBindingStop (
102 IN EFI_DRIVER_BINDING_PROTOCOL *This,
103 IN EFI_HANDLE ControllerHandle,
104 IN UINTN NumberOfChildren,
105 IN EFI_HANDLE *ChildHandleBuffer
106 );
107
108 VOID
109 Cbi1ReportStatusCode (
110 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
111 IN EFI_STATUS_CODE_TYPE CodeType,
112 IN EFI_STATUS_CODE_VALUE Value
113 );
114
115
116 EFI_DRIVER_BINDING_PROTOCOL gCBI1DriverBinding = {
117 CBI1DriverBindingSupported,
118 CBI1DriverBindingStart,
119 CBI1DriverBindingStop,
120 0x10,
121 NULL,
122 NULL
123 };
124
125 STATIC EFI_USB_ATAPI_PROTOCOL CBI1AtapiProtocol = {
126 CBI1AtapiCommand,
127 CBI1MassStorageReset,
128 0
129 };
130
131 //
132 // CBI1 Driver Binding implementation
133 //
134 STATIC
135 EFI_STATUS
136 EFIAPI
137 CBI1DriverBindingSupported (
138 IN EFI_DRIVER_BINDING_PROTOCOL *This,
139 IN EFI_HANDLE ControllerHandle,
140 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
141 )
142 /*++
143
144 Routine Description:
145 Test to see if this driver supports ControllerHandle. Any ControllerHandle
146 than contains a BlockIo and DiskIo protocol can be supported.
147
148 Arguments:
149 This - Protocol instance pointer.
150 ControllerHandle - Handle of device to test
151 RemainingDevicePath - Not used
152
153 Returns:
154 EFI_SUCCESS - This driver supports this device
155 EFI_ALREADY_STARTED - This driver is already running on this device
156 other - This driver does not support this device
157
158 --*/
159 {
160 EFI_STATUS Status;
161 EFI_USB_IO_PROTOCOL *UsbIo;
162 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
163
164 //
165 // Check if the Controller supports USB IO protocol
166 //
167 Status = gBS->OpenProtocol (
168 ControllerHandle,
169 &gEfiUsbIoProtocolGuid,
170 (VOID **) &UsbIo,
171 This->DriverBindingHandle,
172 ControllerHandle,
173 EFI_OPEN_PROTOCOL_BY_DRIVER
174 );
175 if (EFI_ERROR (Status)) {
176 return Status;
177 }
178 //
179 // Get the Controller interface descriptor
180 //
181 Status = UsbIo->UsbGetInterfaceDescriptor (
182 UsbIo,
183 &InterfaceDescriptor
184 );
185 if (EFI_ERROR (Status)) {
186 goto Exit;
187 }
188 //
189 // Bug here: just let Vendor specific CBI protocol get supported
190 //
191 if (!((InterfaceDescriptor.InterfaceClass == 0xFF) &&
192 (InterfaceDescriptor.InterfaceProtocol == 0))) {
193 Status = EFI_UNSUPPORTED;
194 goto Exit;
195 }
196
197 Exit:
198 gBS->CloseProtocol (
199 ControllerHandle,
200 &gEfiUsbIoProtocolGuid,
201 This->DriverBindingHandle,
202 ControllerHandle
203 );
204 return Status;
205
206 }
207
208 STATIC
209 EFI_STATUS
210 EFIAPI
211 CBI1DriverBindingStart (
212 IN EFI_DRIVER_BINDING_PROTOCOL *This,
213 IN EFI_HANDLE ControllerHandle,
214 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
215 )
216 /*++
217
218 Routine Description:
219 Start this driver on ControllerHandle by opening a Block IO and Disk IO
220 protocol, reading Device Path, and creating a child handle with a
221 Disk IO and device path protocol.
222
223 Arguments:
224 This - Protocol instance pointer.
225 ControllerHandle - Handle of device to bind driver to
226 RemainingDevicePath - Not used
227
228 Returns:
229 EFI_SUCCESS - This driver is added to DeviceHandle
230 EFI_ALREADY_STARTED - This driver is already running on DeviceHandle
231 other - This driver does not support this device
232
233 --*/
234 {
235 USB_CBI_DEVICE *UsbCbiDev;
236 UINT8 Index;
237 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
238 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
239 EFI_STATUS Status;
240 EFI_USB_IO_PROTOCOL *UsbIo;
241 BOOLEAN Found;
242
243 Found = FALSE;
244 //
245 // Check if the Controller supports USB IO protocol
246 //
247 UsbCbiDev = NULL;
248
249 Status = gBS->OpenProtocol (
250 ControllerHandle,
251 &gEfiUsbIoProtocolGuid,
252 (VOID **) &UsbIo,
253 This->DriverBindingHandle,
254 ControllerHandle,
255 EFI_OPEN_PROTOCOL_BY_DRIVER
256 );
257 if (EFI_ERROR (Status)) {
258 return Status;
259 }
260 //
261 // Get the controller interface descriptor
262 //
263 Status = UsbIo->UsbGetInterfaceDescriptor (
264 UsbIo,
265 &InterfaceDescriptor
266 );
267 if (EFI_ERROR (Status)) {
268 goto ErrorExit;
269 }
270
271 CBI1AtapiProtocol.CommandProtocol = InterfaceDescriptor.InterfaceSubClass;
272
273 UsbCbiDev = AllocateZeroPool (sizeof (USB_CBI_DEVICE));
274 if (UsbCbiDev == NULL) {
275 Status = EFI_OUT_OF_RESOURCES;
276 goto ErrorExit;
277 }
278
279 UsbCbiDev->Signature = USB_CBI_DEVICE_SIGNATURE;
280 UsbCbiDev->UsbIo = UsbIo;
281 CopyMem (&UsbCbiDev->InterfaceDescriptor, &InterfaceDescriptor, sizeof (InterfaceDescriptor));
282 CopyMem (&UsbCbiDev->UsbAtapiProtocol , &CBI1AtapiProtocol, sizeof (CBI1AtapiProtocol));
283
284 //
285 // Get the Device Path Protocol on Controller's handle
286 //
287 Status = gBS->OpenProtocol (
288 ControllerHandle,
289 &gEfiDevicePathProtocolGuid,
290 (VOID **) &UsbCbiDev->DevicePath,
291 This->DriverBindingHandle,
292 ControllerHandle,
293 EFI_OPEN_PROTOCOL_GET_PROTOCOL
294 );
295
296 if (EFI_ERROR (Status)) {
297 goto ErrorExit;
298 }
299
300 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
301 UsbIo->UsbGetEndpointDescriptor (
302 UsbIo,
303 Index,
304 &EndpointDescriptor
305 );
306
307 //
308 // We parse bulk endpoint
309 //
310 if (EndpointDescriptor.Attributes == 0x02) {
311 if (EndpointDescriptor.EndpointAddress & 0x80) {
312 CopyMem (&UsbCbiDev->BulkInEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
313 //UsbCbiDev->BulkInEndpointDescriptor = EndpointDescriptor;
314 } else {
315 CopyMem (&UsbCbiDev->BulkOutEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
316 //UsbCbiDev->BulkOutEndpointDescriptor = EndpointDescriptor;
317 }
318
319 Found = TRUE;
320 }
321 //
322 // We parse interrupt endpoint
323 //
324 if (EndpointDescriptor.Attributes == 0x03) {
325 CopyMem (&UsbCbiDev->InterruptEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));
326 //UsbCbiDev->InterruptEndpointDescriptor = EndpointDescriptor;
327 Found = TRUE;
328 }
329
330 }
331 //
332 // Double check we have these
333 //
334 if (!Found) {
335 goto ErrorExit;
336 }
337 //
338 // After installing Usb-Atapi protocol onto this handle
339 // it will be called by upper layer drivers such as Fat
340 //
341 Cbi1ReportStatusCode (
342 UsbCbiDev->DevicePath,
343 EFI_PROGRESS_CODE,
344 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE)
345 );
346
347 Status = gBS->InstallProtocolInterface (
348 &ControllerHandle,
349 &gEfiUsbAtapiProtocolGuid,
350 EFI_NATIVE_INTERFACE,
351 &UsbCbiDev->UsbAtapiProtocol
352 );
353
354 if (EFI_ERROR (Status)) {
355 goto ErrorExit;
356 }
357
358 return EFI_SUCCESS;
359
360 ErrorExit:
361 gBS->CloseProtocol (
362 ControllerHandle,
363 &gEfiUsbIoProtocolGuid,
364 This->DriverBindingHandle,
365 ControllerHandle
366 );
367 if (UsbCbiDev != NULL) {
368 gBS->FreePool (UsbCbiDev);
369 }
370
371 return Status;
372
373 }
374
375 STATIC
376 EFI_STATUS
377 EFIAPI
378 CBI1DriverBindingStop (
379 IN EFI_DRIVER_BINDING_PROTOCOL *This,
380 IN EFI_HANDLE ControllerHandle,
381 IN UINTN NumberOfChildren,
382 IN EFI_HANDLE *ChildHandleBuffer
383 )
384 /*++
385
386 Routine Description:
387 Stop this driver on ControllerHandle. Support stoping any child handles
388 created by this driver.
389
390 Arguments:
391 This - Protocol instance pointer.
392 ControllerHandle - Handle of device to stop driver on
393 NumberOfChildren - Number of Children in the ChildHandleBuffer
394 ChildHandleBuffer - List of handles for the children we need to stop.
395
396 Returns:
397 EFI_SUCCESS - This driver is removed DeviceHandle
398 EFI_UNSUPPORTED - Can't open the gEfiUsbAtapiProtocolGuid protocol
399 other - This driver was not removed from this device
400
401 --*/
402 {
403 EFI_STATUS Status;
404 EFI_USB_ATAPI_PROTOCOL *CBI1AtapiProtocol;
405 USB_CBI_DEVICE *UsbCbiDev;
406 EFI_USB_IO_PROTOCOL *UsbIo;
407
408 //
409 // Get our context back.
410 //
411 Status = gBS->OpenProtocol (
412 ControllerHandle,
413 &gEfiUsbAtapiProtocolGuid,
414 (VOID **) &CBI1AtapiProtocol,
415 This->DriverBindingHandle,
416 ControllerHandle,
417 EFI_OPEN_PROTOCOL_GET_PROTOCOL
418 );
419 if (EFI_ERROR (Status)) {
420 return EFI_UNSUPPORTED;
421 }
422
423 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (CBI1AtapiProtocol);
424
425 UsbIo = UsbCbiDev->UsbIo;
426
427 Cbi1ReportStatusCode (
428 UsbCbiDev->DevicePath,
429 EFI_PROGRESS_CODE,
430 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE)
431 );
432
433 Status = gBS->UninstallProtocolInterface (
434 ControllerHandle,
435 &gEfiUsbAtapiProtocolGuid,
436 &UsbCbiDev->UsbAtapiProtocol
437 );
438 if (EFI_ERROR (Status)) {
439 return Status;
440 }
441
442 Status = gBS->CloseProtocol (
443 ControllerHandle,
444 &gEfiUsbIoProtocolGuid,
445 This->DriverBindingHandle,
446 ControllerHandle
447 );
448 gBS->FreePool (UsbCbiDev);
449
450 return Status;
451
452 }
453 //
454 // CBI1 command
455 //
456 STATIC
457 EFI_STATUS
458 CBI1CommandPhase (
459 IN USB_CBI_DEVICE *UsbCbiDev,
460 IN VOID *Command,
461 IN UINT8 CommandSize,
462 OUT UINT32 *Result
463 )
464 /*++
465
466 Routine Description:
467 In order to make consistence, CBI transportation protocol does only use
468 the first 3 parameters. Other parameters are not used here.
469
470 Arguments:
471 UsbCbiDev - USB_CBI_DEVICE
472 Command - Command to send
473 CommandSize - Command Size
474 Result - Result to return
475
476 Returns:
477 EFI_SUCCESS - This driver is removed DeviceHandle
478 other - This driver was not removed from this device
479 --*/
480 {
481 EFI_STATUS Status;
482 EFI_USB_IO_PROTOCOL *UsbIo;
483 EFI_USB_DEVICE_REQUEST Request;
484 UINT32 TimeOutInMilliSeconds;
485
486 UsbIo = UsbCbiDev->UsbIo;
487
488 ZeroMem (&Request, sizeof (EFI_USB_DEVICE_REQUEST));
489
490 //
491 // Device request see CBI specification
492 //
493 Request.RequestType = 0x21;
494 Request.Length = CommandSize;
495
496 TimeOutInMilliSeconds = 1000;
497
498 Status = UsbIo->UsbControlTransfer (
499 UsbIo,
500 &Request,
501 EfiUsbDataOut,
502 TimeOutInMilliSeconds,
503 Command,
504 CommandSize,
505 Result
506 );
507
508 return Status;
509 }
510
511 STATIC
512 EFI_STATUS
513 CBI1DataPhase (
514 IN USB_CBI_DEVICE *UsbCbiDev,
515 IN UINT32 DataSize,
516 IN OUT VOID *DataBuffer,
517 IN EFI_USB_DATA_DIRECTION Direction,
518 IN UINT16 Timeout,
519 OUT UINT32 *Result
520 )
521 /*++
522
523 Routine Description:
524
525 CBI1 Data Phase
526
527 Arguments:
528
529 UsbCbiDev - USB_CBI_DEVICE
530 DataSize - Data Size
531 DataBuffer - Data Buffer
532 Direction - IN/OUT/NODATA
533 Timeout - Time out value in milliseconds
534 Result - Transfer result
535
536 Returns:
537
538 EFI_SUCCESS - Success
539
540 --*/
541 {
542 EFI_STATUS Status;
543 EFI_USB_IO_PROTOCOL *UsbIo;
544 UINT8 EndpointAddr;
545 UINTN Remain;
546 UINTN Increment;
547 UINT32 MaxPacketLen;
548 UINT8 *BufferPtr;
549
550 UsbIo = UsbCbiDev->UsbIo;
551
552 Remain = DataSize;
553 BufferPtr = (UINT8 *) DataBuffer;
554
555 //
556 // retrieve the the max packet length of the given endpoint
557 //
558 if (Direction == EfiUsbDataIn) {
559 MaxPacketLen = (UsbCbiDev->BulkInEndpointDescriptor).MaxPacketSize;
560 EndpointAddr = (UsbCbiDev->BulkInEndpointDescriptor).EndpointAddress;
561 } else {
562 MaxPacketLen = (UsbCbiDev->BulkOutEndpointDescriptor).MaxPacketSize;
563 EndpointAddr = (UsbCbiDev->BulkOutEndpointDescriptor).EndpointAddress;
564 }
565
566 while (Remain > 0) {
567 //
568 // Using 15 packets to aVOID Bitstuff error
569 //
570 if (Remain > 15 * MaxPacketLen) {
571 Increment = 15 * MaxPacketLen;
572 } else {
573 Increment = Remain;
574 }
575
576 Status = UsbIo->UsbBulkTransfer (
577 UsbIo,
578 EndpointAddr,
579 BufferPtr,
580 &Increment,
581 Timeout,
582 Result
583 );
584
585 if (EFI_ERROR (Status)) {
586 goto ErrorExit;
587 }
588
589 BufferPtr += Increment;
590 Remain -= Increment;
591 }
592
593 return EFI_SUCCESS;
594
595 ErrorExit:
596
597 if (Direction == EfiUsbDataIn) {
598 Cbi1ReportStatusCode (
599 UsbCbiDev->DevicePath,
600 EFI_ERROR_CODE | EFI_ERROR_MINOR,
601 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_INPUT_ERROR)
602 );
603 } else {
604 Cbi1ReportStatusCode (
605 UsbCbiDev->DevicePath,
606 EFI_ERROR_CODE | EFI_ERROR_MINOR,
607 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_OUTPUT_ERROR)
608 );
609 }
610
611 if (((*Result) & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
612 //
613 // just endpoint stall happens
614 //
615 UsbClearEndpointHalt (
616 UsbIo,
617 EndpointAddr,
618 Result
619 );
620 }
621
622 return Status;
623 }
624 //
625 // CBI1 USB ATAPI Protocol
626 //
627 STATIC
628 EFI_STATUS
629 EFIAPI
630 CBI1MassStorageReset (
631 IN EFI_USB_ATAPI_PROTOCOL *This,
632 IN BOOLEAN ExtendedVerification
633 )
634 /*++
635
636 Routine Description:
637 Reset CBI Devices
638
639 Arguments:
640 This - Protocol instance pointer.
641 ExtendedVerification - TRUE if we need to do strictly reset.
642
643 Returns:
644 EFI_SUCCESS - Command succeeded.
645 EFI_DEVICE_ERROR - Command failed.
646
647 --*/
648 {
649 UINT8 ResetCommand[12];
650 EFI_STATUS Status;
651 EFI_USB_IO_PROTOCOL *UsbIo;
652 USB_CBI_DEVICE *UsbCbiDev;
653 UINT8 EndpointAddr;
654 UINT32 Result;
655
656 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
657 UsbIo = UsbCbiDev->UsbIo;
658
659 Cbi1ReportStatusCode (
660 UsbCbiDev->DevicePath,
661 EFI_PROGRESS_CODE,
662 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_RESET)
663 );
664
665 if (ExtendedVerification) {
666 UsbIo->UsbPortReset (UsbIo);
667 }
668 //
669 // CBI reset command protocol
670 //
671 SetMem (ResetCommand, sizeof (ResetCommand), 0xff);
672 ResetCommand[0] = 0x1d;
673 ResetCommand[1] = 0x04;
674
675 Status = CBI1CommandPhase (
676 UsbCbiDev,
677 ResetCommand,
678 12,
679 &Result
680 );
681
682 //
683 // clear bulk in endpoint stall feature
684 //
685 EndpointAddr = UsbCbiDev->BulkInEndpointDescriptor.EndpointAddress;
686 UsbClearEndpointHalt (
687 UsbIo,
688 EndpointAddr,
689 &Result
690 );
691
692 //
693 // clear bulk out endpoint stall feature
694 //
695 EndpointAddr = UsbCbiDev->BulkOutEndpointDescriptor.EndpointAddress;
696 UsbClearEndpointHalt (
697 UsbIo,
698 EndpointAddr,
699 &Result
700 );
701
702 return EFI_SUCCESS;
703
704 }
705
706 STATIC
707 EFI_STATUS
708 EFIAPI
709 CBI1AtapiCommand (
710 IN EFI_USB_ATAPI_PROTOCOL *This,
711 IN VOID *Command,
712 IN UINT8 CommandSize,
713 IN VOID *DataBuffer,
714 IN UINT32 BufferLength,
715 IN EFI_USB_DATA_DIRECTION Direction,
716 IN UINT16 TimeOutInMilliSeconds
717 )
718 /*++
719
720 Routine Description:
721 Send ATAPI command using CBI1 protocol.
722
723 Arguments:
724 This - Protocol instance pointer.
725 Command - Command buffer
726 CommandSize - Size of Command Buffer
727 DataBuffer - Data buffer
728 BufferLength - Length of Data buffer
729 Direction - Data direction of this command
730 TimeOutInMilliSeconds - Timeout value in ms
731
732 Returns:
733 EFI_SUCCESS - Command succeeded.
734 EFI_DEVICE_ERROR - Command failed.
735
736 --*/
737 {
738 EFI_STATUS Status;
739 USB_CBI_DEVICE *UsbCbiDev;
740 UINT32 Result;
741 UINT8 Index;
742 UINT8 MaxRetryNum;
743
744 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
745
746 MaxRetryNum = 3;
747
748 for (Index = 0; Index < MaxRetryNum; Index++) {
749
750 //
751 // First send ATAPI command through CBI1
752 //
753 Status = CBI1CommandPhase (
754 UsbCbiDev,
755 Command,
756 CommandSize,
757 &Result
758 );
759 if (EFI_ERROR (Status)) {
760
761 switch (Result) {
762
763 case EFI_USB_NOERROR:
764 case EFI_USB_ERR_STALL:
765 case EFI_USB_ERR_SYSTEM:
766 return EFI_DEVICE_ERROR;
767
768 default:
769 continue;
770 break;
771 }
772 } else {
773 break;
774 }
775 }
776
777 if (Index == MaxRetryNum) {
778 return EFI_DEVICE_ERROR;
779 }
780
781 for (Index = 0; Index < MaxRetryNum; Index++) {
782 //
783 // Send/Get Data if there is a Data Stage
784 //
785 switch (Direction) {
786
787 case EfiUsbDataIn:
788 case EfiUsbDataOut:
789 Status = CBI1DataPhase (
790 UsbCbiDev,
791 BufferLength,
792 DataBuffer,
793 Direction,
794 TimeOutInMilliSeconds,
795 &Result
796 );
797
798 if (EFI_ERROR (Status)) {
799 switch (Result) {
800
801 case EFI_USB_NOERROR:
802 case EFI_USB_ERR_STALL:
803 case EFI_USB_ERR_SYSTEM:
804 return EFI_DEVICE_ERROR;
805
806 default:
807 continue;
808 break;
809 }
810
811 } else {
812
813 return EFI_SUCCESS;
814 }
815 break;
816
817 case EfiUsbNoData:
818 return EFI_SUCCESS;
819 }
820 }
821 //
822 // If goes here, means met error.
823 //
824 return EFI_DEVICE_ERROR;
825 }
826
827 VOID
828 Cbi1ReportStatusCode (
829 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
830 IN EFI_STATUS_CODE_TYPE CodeType,
831 IN EFI_STATUS_CODE_VALUE Value
832 )
833 /*++
834
835 Routine Description:
836 Report Status Code in Usb Cbi1 Driver
837
838 Arguments:
839 DevicePath - Use this to get Device Path
840 CodeType - Status Code Type
841 CodeValue - Status Code Value
842
843 Returns:
844 None
845
846 --*/
847 {
848 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
849 CodeType,
850 Value,
851 DevicePath
852 );
853
854 }