56 OUT VOID **Context OPTIONAL
71 ASSERT (UsbCbi !=
NULL);
73 UsbCbi->UsbIo = UsbIo;
79 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &UsbCbi->Interface);
80 if (EFI_ERROR (Status)) {
84 Interface = &UsbCbi->Interface;
88 Status = EFI_UNSUPPORTED;
95 for (Index = 0; Index < Interface->NumEndpoints; Index++) {
96 Status = UsbIo->UsbGetEndpointDescriptor (UsbIo, Index, &EndPoint);
97 if (EFI_ERROR (Status)) {
101 if (USB_IS_BULK_ENDPOINT (EndPoint.Attributes)) {
105 if (USB_IS_IN_ENDPOINT (EndPoint.EndpointAddress) &&
106 (UsbCbi->BulkInEndpoint ==
NULL))
109 CopyMem (UsbCbi->BulkInEndpoint, &EndPoint, sizeof (EndPoint));
112 if (USB_IS_OUT_ENDPOINT (EndPoint.EndpointAddress) &&
113 (UsbCbi->BulkOutEndpoint ==
NULL))
116 CopyMem (UsbCbi->BulkOutEndpoint, &EndPoint, sizeof (EndPoint));
118 }
else if (USB_IS_INTERRUPT_ENDPOINT (EndPoint.Attributes)) {
123 (UsbCbi->InterruptEndpoint ==
NULL))
126 CopyMem (UsbCbi->InterruptEndpoint, &EndPoint, sizeof (EndPoint));
131 if ((UsbCbi->BulkInEndpoint ==
NULL) || (UsbCbi->BulkOutEndpoint ==
NULL)) {
132 Status = EFI_UNSUPPORTED;
137 Status = EFI_UNSUPPORTED;
141 if (Context !=
NULL) {
187 Request.RequestType = 0x21;
190 Request.Index = UsbCbi->Interface.InterfaceNumber;
191 Request.Length = CmdLen;
194 Timeout = Timeout / USB_MASS_1_MILLISECOND;
196 for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {
203 Status = UsbCbi->UsbIo->UsbControlTransfer (
218 if (EFI_ERROR (Status) && (TransStatus == EFI_USB_ERR_NAK)) {
266 if ((DataDir == EfiUsbNoData) || (*TransLen == 0)) {
273 if (DataDir == EfiUsbDataIn) {
274 Endpoint = UsbCbi->BulkInEndpoint;
276 Endpoint = UsbCbi->BulkOutEndpoint;
283 Timeout = Timeout / USB_MASS_1_MILLISECOND;
291 if (Remain > (
UINTN)USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize) {
292 Increment = USB_CBI_MAX_PACKET_NUM * Endpoint->MaxPacketSize;
297 Status = UsbCbi->UsbIo->UsbBulkTransfer (
299 Endpoint->EndpointAddress,
305 if (EFI_ERROR (Status)) {
306 if (TransStatus == EFI_USB_ERR_NAK) {
314 if (Increment == 0) {
315 if (++Retry > USB_CBI_MAX_RETRY) {
331 if (TransStatus == EFI_USB_ERR_STALL) {
376 Endpoint = UsbCbi->InterruptEndpoint->EndpointAddress;
378 Timeout = Timeout / USB_MASS_1_MILLISECOND;
383 for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {
387 Status = UsbCbi->UsbIo->UsbSyncInterruptTransfer (
398 if (EFI_ERROR (Status) && (TransStatus == EFI_USB_ERR_NAK)) {
435 OUT UINT32 *CmdStatus
443 *CmdStatus = USB_MASS_CMD_SUCCESS;
451 if (EFI_ERROR (Status)) {
452 gBS->Stall (10 * USB_MASS_1_MILLISECOND);
453 DEBUG ((DEBUG_ERROR,
"UsbCbiExecCommand: UsbCbiSendCommand (%r)\n", Status));
461 TransLen = (
UINTN)DataLen;
464 if (UsbCbi->InterruptEndpoint ==
NULL) {
465 DEBUG ((DEBUG_ERROR,
"UsbCbiExecCommand: UsbCbiDataTransfer (%r)\n", Status));
473 if (EFI_ERROR (Status)) {
474 DEBUG ((DEBUG_ERROR,
"UsbCbiExecCommand: UsbCbiGetStatus (%r)\n", Status));
485 if ((Result.Type != 0) && (*(UINT8 *)Cmd != 0x03)) {
486 *CmdStatus = USB_MASS_CMD_FAIL;
492 switch (Result.Value & 0x03) {
497 *CmdStatus = USB_MASS_CMD_SUCCESS;
511 *CmdStatus = USB_MASS_CMD_FAIL;
518 *CmdStatus = USB_MASS_CMD_PERSISTENT;
544 IN BOOLEAN ExtendedVerification
547 UINT8 ResetCmd[USB_CBI_RESET_CMD_LEN];
558 SetMem (ResetCmd, USB_CBI_RESET_CMD_LEN, 0xFF);
562 Timeout = USB_CBI_RESET_DEVICE_TIMEOUT / USB_MASS_1_MILLISECOND;
568 if (EFI_ERROR (Status)) {
569 return EFI_DEVICE_ERROR;
577 gBS->Stall (USB_CBI_RESET_DEVICE_STALL);
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
#define USB_MASS_STORE_UFI
Typically a floppy disk driver device.
#define USB_MASS_STORE_CBI0
CBI protocol with command completion interrupt.
#define USB_MASS_STORE_CBI1
CBI protocol without command completion interrupt.
EFI_STATUS UsbClearEndpointStall(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 EndpointAddr)
EFI_STATUS UsbCbiDataTransfer(IN USB_CBI_PROTOCOL *UsbCbi, IN EFI_USB_DATA_DIRECTION DataDir, IN OUT UINT8 *Data, IN OUT UINTN *TransLen, IN UINT32 Timeout)
EFI_STATUS UsbCbiCleanUp(IN VOID *Context)
EFI_STATUS UsbCbiResetDevice(IN VOID *Context, IN BOOLEAN ExtendedVerification)
EFI_STATUS UsbCbiGetStatus(IN USB_CBI_PROTOCOL *UsbCbi, IN UINT32 Timeout, OUT USB_CBI_STATUS *Result)
EFI_STATUS UsbCbiExecCommand(IN VOID *Context, IN VOID *Cmd, IN UINT8 CmdLen, IN EFI_USB_DATA_DIRECTION DataDir, IN VOID *Data, IN UINT32 DataLen, IN UINT8 Lun, IN UINT32 Timeout, OUT UINT32 *CmdStatus)
EFI_STATUS UsbCbiInit(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT VOID **Context OPTIONAL)
EFI_STATUS UsbCbiSendCommand(IN USB_CBI_PROTOCOL *UsbCbi, IN UINT8 *Cmd, IN UINT8 CmdLen, IN UINT32 Timeout)