]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Bus/Usb/UsbCbi/Dxe/Cbi1/cbi1.c
Partially make EdkModulePkg pass intel IPF compiler with /W4 /WX switched on.
[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 0xa,
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 } else {
314 CopyMem (&UsbCbiDev->BulkOutEndpointDescriptor, &EndpointDescriptor, sizeof (EndpointDescriptor));
315 }
316
317 Found = TRUE;
318 }
319 //
320 // We parse interrupt endpoint
321 //
322 if (EndpointDescriptor.Attributes == 0x03) {
323 CopyMem (&UsbCbiDev->InterruptEndpointDescriptor, &EndpointDescriptor, sizeof (EndpointDescriptor));
324 Found = TRUE;
325 }
326
327 }
328 //
329 // Double check we have these
330 //
331 if (!Found) {
332 goto ErrorExit;
333 }
334 //
335 // After installing Usb-Atapi protocol onto this handle
336 // it will be called by upper layer drivers such as Fat
337 //
338 Cbi1ReportStatusCode (
339 UsbCbiDev->DevicePath,
340 EFI_PROGRESS_CODE,
341 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE)
342 );
343
344 Status = gBS->InstallProtocolInterface (
345 &ControllerHandle,
346 &gEfiUsbAtapiProtocolGuid,
347 EFI_NATIVE_INTERFACE,
348 &UsbCbiDev->UsbAtapiProtocol
349 );
350
351 if (EFI_ERROR (Status)) {
352 goto ErrorExit;
353 }
354
355 return EFI_SUCCESS;
356
357 ErrorExit:
358 gBS->CloseProtocol (
359 ControllerHandle,
360 &gEfiUsbIoProtocolGuid,
361 This->DriverBindingHandle,
362 ControllerHandle
363 );
364 if (UsbCbiDev != NULL) {
365 gBS->FreePool (UsbCbiDev);
366 }
367
368 return Status;
369
370 }
371
372 STATIC
373 EFI_STATUS
374 EFIAPI
375 CBI1DriverBindingStop (
376 IN EFI_DRIVER_BINDING_PROTOCOL *This,
377 IN EFI_HANDLE ControllerHandle,
378 IN UINTN NumberOfChildren,
379 IN EFI_HANDLE *ChildHandleBuffer
380 )
381 /*++
382
383 Routine Description:
384 Stop this driver on ControllerHandle. Support stoping any child handles
385 created by this driver.
386
387 Arguments:
388 This - Protocol instance pointer.
389 ControllerHandle - Handle of device to stop driver on
390 NumberOfChildren - Number of Children in the ChildHandleBuffer
391 ChildHandleBuffer - List of handles for the children we need to stop.
392
393 Returns:
394 EFI_SUCCESS - This driver is removed DeviceHandle
395 EFI_UNSUPPORTED - Can't open the gEfiUsbAtapiProtocolGuid protocol
396 other - This driver was not removed from this device
397
398 --*/
399 {
400 EFI_STATUS Status;
401 EFI_USB_ATAPI_PROTOCOL *CBI1AtapiProtocol;
402 USB_CBI_DEVICE *UsbCbiDev;
403
404 //
405 // Get our context back.
406 //
407 Status = gBS->OpenProtocol (
408 ControllerHandle,
409 &gEfiUsbAtapiProtocolGuid,
410 (VOID **) &CBI1AtapiProtocol,
411 This->DriverBindingHandle,
412 ControllerHandle,
413 EFI_OPEN_PROTOCOL_GET_PROTOCOL
414 );
415 if (EFI_ERROR (Status)) {
416 return EFI_UNSUPPORTED;
417 }
418
419 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (CBI1AtapiProtocol);
420
421 Cbi1ReportStatusCode (
422 UsbCbiDev->DevicePath,
423 EFI_PROGRESS_CODE,
424 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE)
425 );
426
427 Status = gBS->UninstallProtocolInterface (
428 ControllerHandle,
429 &gEfiUsbAtapiProtocolGuid,
430 &UsbCbiDev->UsbAtapiProtocol
431 );
432 if (EFI_ERROR (Status)) {
433 return Status;
434 }
435
436 Status = gBS->CloseProtocol (
437 ControllerHandle,
438 &gEfiUsbIoProtocolGuid,
439 This->DriverBindingHandle,
440 ControllerHandle
441 );
442 gBS->FreePool (UsbCbiDev);
443
444 return Status;
445
446 }
447 //
448 // CBI1 command
449 //
450 STATIC
451 EFI_STATUS
452 CBI1CommandPhase (
453 IN USB_CBI_DEVICE *UsbCbiDev,
454 IN VOID *Command,
455 IN UINT8 CommandSize,
456 OUT UINT32 *Result
457 )
458 /*++
459
460 Routine Description:
461 In order to make consistence, CBI transportation protocol does only use
462 the first 3 parameters. Other parameters are not used here.
463
464 Arguments:
465 UsbCbiDev - USB_CBI_DEVICE
466 Command - Command to send
467 CommandSize - Command Size
468 Result - Result to return
469
470 Returns:
471 EFI_SUCCESS - This driver is removed DeviceHandle
472 other - This driver was not removed from this device
473 --*/
474 {
475 EFI_STATUS Status;
476 EFI_USB_IO_PROTOCOL *UsbIo;
477 EFI_USB_DEVICE_REQUEST Request;
478 UINT32 TimeOutInMilliSeconds;
479
480 UsbIo = UsbCbiDev->UsbIo;
481
482 ZeroMem (&Request, sizeof (EFI_USB_DEVICE_REQUEST));
483
484 //
485 // Device request see CBI specification
486 //
487 Request.RequestType = 0x21;
488 Request.Length = CommandSize;
489
490 TimeOutInMilliSeconds = 1000;
491
492 Status = UsbIo->UsbControlTransfer (
493 UsbIo,
494 &Request,
495 EfiUsbDataOut,
496 TimeOutInMilliSeconds,
497 Command,
498 CommandSize,
499 Result
500 );
501
502 return Status;
503 }
504
505 STATIC
506 EFI_STATUS
507 CBI1DataPhase (
508 IN USB_CBI_DEVICE *UsbCbiDev,
509 IN UINT32 DataSize,
510 IN OUT VOID *DataBuffer,
511 IN EFI_USB_DATA_DIRECTION Direction,
512 IN UINT16 Timeout,
513 OUT UINT32 *Result
514 )
515 /*++
516
517 Routine Description:
518
519 CBI1 Data Phase
520
521 Arguments:
522
523 UsbCbiDev - USB_CBI_DEVICE
524 DataSize - Data Size
525 DataBuffer - Data Buffer
526 Direction - IN/OUT/NODATA
527 Timeout - Time out value in milliseconds
528 Result - Transfer result
529
530 Returns:
531
532 EFI_SUCCESS - Success
533
534 --*/
535 {
536 EFI_STATUS Status;
537 EFI_USB_IO_PROTOCOL *UsbIo;
538 UINT8 EndpointAddr;
539 UINTN Remain;
540 UINTN Increment;
541 UINT32 MaxPacketLen;
542 UINT8 *BufferPtr;
543
544 UsbIo = UsbCbiDev->UsbIo;
545
546 Remain = DataSize;
547 BufferPtr = (UINT8 *) DataBuffer;
548
549 //
550 // retrieve the the max packet length of the given endpoint
551 //
552 if (Direction == EfiUsbDataIn) {
553 MaxPacketLen = (UsbCbiDev->BulkInEndpointDescriptor).MaxPacketSize;
554 EndpointAddr = (UsbCbiDev->BulkInEndpointDescriptor).EndpointAddress;
555 } else {
556 MaxPacketLen = (UsbCbiDev->BulkOutEndpointDescriptor).MaxPacketSize;
557 EndpointAddr = (UsbCbiDev->BulkOutEndpointDescriptor).EndpointAddress;
558 }
559
560 while (Remain > 0) {
561 //
562 // Using 15 packets to aVOID Bitstuff error
563 //
564 if (Remain > 15 * MaxPacketLen) {
565 Increment = 15 * MaxPacketLen;
566 } else {
567 Increment = Remain;
568 }
569
570 Status = UsbIo->UsbBulkTransfer (
571 UsbIo,
572 EndpointAddr,
573 BufferPtr,
574 &Increment,
575 Timeout,
576 Result
577 );
578
579 if (EFI_ERROR (Status)) {
580 goto ErrorExit;
581 }
582
583 BufferPtr += Increment;
584 Remain -= Increment;
585 }
586
587 return EFI_SUCCESS;
588
589 ErrorExit:
590
591 if (Direction == EfiUsbDataIn) {
592 Cbi1ReportStatusCode (
593 UsbCbiDev->DevicePath,
594 EFI_ERROR_CODE | EFI_ERROR_MINOR,
595 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_INPUT_ERROR)
596 );
597 } else {
598 Cbi1ReportStatusCode (
599 UsbCbiDev->DevicePath,
600 EFI_ERROR_CODE | EFI_ERROR_MINOR,
601 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_OUTPUT_ERROR)
602 );
603 }
604
605 if (((*Result) & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
606 //
607 // just endpoint stall happens
608 //
609 UsbClearEndpointHalt (
610 UsbIo,
611 EndpointAddr,
612 Result
613 );
614 }
615
616 return Status;
617 }
618 //
619 // CBI1 USB ATAPI Protocol
620 //
621 STATIC
622 EFI_STATUS
623 EFIAPI
624 CBI1MassStorageReset (
625 IN EFI_USB_ATAPI_PROTOCOL *This,
626 IN BOOLEAN ExtendedVerification
627 )
628 /*++
629
630 Routine Description:
631 Reset CBI Devices
632
633 Arguments:
634 This - Protocol instance pointer.
635 ExtendedVerification - TRUE if we need to do strictly reset.
636
637 Returns:
638 EFI_SUCCESS - Command succeeded.
639 EFI_DEVICE_ERROR - Command failed.
640
641 --*/
642 {
643 UINT8 ResetCommand[12];
644 EFI_USB_IO_PROTOCOL *UsbIo;
645 USB_CBI_DEVICE *UsbCbiDev;
646 UINT8 EndpointAddr;
647 UINT32 Result;
648
649 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
650 UsbIo = UsbCbiDev->UsbIo;
651
652 Cbi1ReportStatusCode (
653 UsbCbiDev->DevicePath,
654 EFI_PROGRESS_CODE,
655 (EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_RESET)
656 );
657
658 if (ExtendedVerification) {
659 UsbIo->UsbPortReset (UsbIo);
660 }
661 //
662 // CBI reset command protocol
663 //
664 SetMem (ResetCommand, sizeof (ResetCommand), 0xff);
665 ResetCommand[0] = 0x1d;
666 ResetCommand[1] = 0x04;
667
668 CBI1CommandPhase (
669 UsbCbiDev,
670 ResetCommand,
671 12,
672 &Result
673 );
674
675 //
676 // clear bulk in endpoint stall feature
677 //
678 EndpointAddr = UsbCbiDev->BulkInEndpointDescriptor.EndpointAddress;
679 UsbClearEndpointHalt (
680 UsbIo,
681 EndpointAddr,
682 &Result
683 );
684
685 //
686 // clear bulk out endpoint stall feature
687 //
688 EndpointAddr = UsbCbiDev->BulkOutEndpointDescriptor.EndpointAddress;
689 UsbClearEndpointHalt (
690 UsbIo,
691 EndpointAddr,
692 &Result
693 );
694
695 return EFI_SUCCESS;
696
697 }
698
699 STATIC
700 EFI_STATUS
701 EFIAPI
702 CBI1AtapiCommand (
703 IN EFI_USB_ATAPI_PROTOCOL *This,
704 IN VOID *Command,
705 IN UINT8 CommandSize,
706 IN VOID *DataBuffer,
707 IN UINT32 BufferLength,
708 IN EFI_USB_DATA_DIRECTION Direction,
709 IN UINT16 TimeOutInMilliSeconds
710 )
711 /*++
712
713 Routine Description:
714 Send ATAPI command using CBI1 protocol.
715
716 Arguments:
717 This - Protocol instance pointer.
718 Command - Command buffer
719 CommandSize - Size of Command Buffer
720 DataBuffer - Data buffer
721 BufferLength - Length of Data buffer
722 Direction - Data direction of this command
723 TimeOutInMilliSeconds - Timeout value in ms
724
725 Returns:
726 EFI_SUCCESS - Command succeeded.
727 EFI_DEVICE_ERROR - Command failed.
728
729 --*/
730 {
731 EFI_STATUS Status;
732 USB_CBI_DEVICE *UsbCbiDev;
733 UINT32 Result;
734 UINT8 Index;
735 UINT8 MaxRetryNum;
736
737 UsbCbiDev = USB_CBI_DEVICE_FROM_THIS (This);
738
739 MaxRetryNum = 3;
740
741 for (Index = 0; Index < MaxRetryNum; Index++) {
742
743 //
744 // First send ATAPI command through CBI1
745 //
746 Status = CBI1CommandPhase (
747 UsbCbiDev,
748 Command,
749 CommandSize,
750 &Result
751 );
752 if (EFI_ERROR (Status)) {
753
754 switch (Result) {
755
756 case EFI_USB_NOERROR:
757 case EFI_USB_ERR_STALL:
758 case EFI_USB_ERR_SYSTEM:
759 return EFI_DEVICE_ERROR;
760
761 default:
762 continue;
763 break;
764 }
765 } else {
766 break;
767 }
768 }
769
770 if (Index == MaxRetryNum) {
771 return EFI_DEVICE_ERROR;
772 }
773
774 for (Index = 0; Index < MaxRetryNum; Index++) {
775 //
776 // Send/Get Data if there is a Data Stage
777 //
778 switch (Direction) {
779
780 case EfiUsbDataIn:
781 case EfiUsbDataOut:
782 Status = CBI1DataPhase (
783 UsbCbiDev,
784 BufferLength,
785 DataBuffer,
786 Direction,
787 TimeOutInMilliSeconds,
788 &Result
789 );
790
791 if (EFI_ERROR (Status)) {
792 switch (Result) {
793
794 case EFI_USB_NOERROR:
795 case EFI_USB_ERR_STALL:
796 case EFI_USB_ERR_SYSTEM:
797 return EFI_DEVICE_ERROR;
798
799 default:
800 continue;
801 break;
802 }
803
804 } else {
805
806 return EFI_SUCCESS;
807 }
808 break;
809
810 case EfiUsbNoData:
811 return EFI_SUCCESS;
812 }
813 }
814 //
815 // If goes here, means met error.
816 //
817 return EFI_DEVICE_ERROR;
818 }
819
820 VOID
821 Cbi1ReportStatusCode (
822 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
823 IN EFI_STATUS_CODE_TYPE CodeType,
824 IN EFI_STATUS_CODE_VALUE Value
825 )
826 /*++
827
828 Routine Description:
829 Report Status Code in Usb Cbi1 Driver
830
831 Arguments:
832 DevicePath - Use this to get Device Path
833 CodeType - Status Code Type
834 CodeValue - Status Code Value
835
836 Returns:
837 None
838
839 --*/
840 {
841 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
842 CodeType,
843 Value,
844 DevicePath
845 );
846
847 }