1 /** @file
2   Definition for the USB mass storage Control/Bulk/Interrupt (CBI) transport,
3   according to USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport, Revision 1.1.
4 
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #ifndef _EFI_USBMASS_CBI_H_
11 #define _EFI_USBMASS_CBI_H_
12 
13 extern USB_MASS_TRANSPORT mUsbCbi0Transport;
14 extern USB_MASS_TRANSPORT mUsbCbi1Transport;
15 
16 #define USB_CBI_MAX_PACKET_NUM        16
17 #define USB_CBI_RESET_CMD_LEN         12
18 //
19 // USB CBI retry C/B/I transport times, set by experience
20 //
21 #define USB_CBI_MAX_RETRY             3
22 //
23 // Time to wait for USB CBI reset to complete, set by experience
24 //
25 #define USB_CBI_RESET_DEVICE_STALL    (50 * USB_MASS_1_MILLISECOND)
26 //
27 // USB CBI transport timeout, set by experience
28 //
29 #define USB_CBI_RESET_DEVICE_TIMEOUT  (1 * USB_MASS_1_SECOND)
30 
31 typedef struct {
32   //
33   // Put Interface at the first field to make it easy to distinguish BOT/CBI Protocol instance
34   //
35   EFI_USB_INTERFACE_DESCRIPTOR  Interface;
36   EFI_USB_ENDPOINT_DESCRIPTOR   *BulkInEndpoint;
37   EFI_USB_ENDPOINT_DESCRIPTOR   *BulkOutEndpoint;
38   EFI_USB_ENDPOINT_DESCRIPTOR   *InterruptEndpoint;
39   EFI_USB_IO_PROTOCOL           *UsbIo;
40 } USB_CBI_PROTOCOL;
41 
42 #pragma pack(1)
43 typedef struct {
44   UINT8               Type;
45   UINT8               Value;
46 } USB_CBI_STATUS;
47 #pragma pack()
48 
49 /**
50   Initializes USB CBI protocol.
51 
52   This function initializes the USB mass storage class CBI protocol.
53   It will save its context which is a USB_CBI_PROTOCOL structure
54   in the Context if Context isn't NULL.
55 
56   @param  UsbIo                 The USB I/O Protocol instance
57   @param  Context               The buffer to save the context to
58 
59   @retval EFI_SUCCESS           The device is successfully initialized.
60   @retval EFI_UNSUPPORTED       The transport protocol doesn't support the device.
61   @retval Other                 The USB CBI initialization fails.
62 
63 **/
64 EFI_STATUS
65 UsbCbiInit (
66   IN  EFI_USB_IO_PROTOCOL   *UsbIo,
67   OUT VOID                  **Context       OPTIONAL
68   );
69 
70 /**
71   Execute USB mass storage command through the CBI0/CBI1 transport protocol.
72 
73   @param  Context               The USB CBI Protocol.
74   @param  Cmd                   The command to transfer to device
75   @param  CmdLen                The length of the command
76   @param  DataDir               The direction of data transfer
77   @param  Data                  The buffer to hold the data
78   @param  DataLen               The length of the buffer
79   @param  Lun                   Should be 0, this field for bot only
80   @param  Timeout               The time to wait
81   @param  CmdStatus             The result of the command execution
82 
83   @retval EFI_SUCCESS           The command is executed successfully.
84   @retval Other                 Failed to execute the command
85 
86 **/
87 EFI_STATUS
88 UsbCbiExecCommand (
89   IN  VOID                    *Context,
90   IN  VOID                    *Cmd,
91   IN  UINT8                   CmdLen,
92   IN  EFI_USB_DATA_DIRECTION  DataDir,
93   IN  VOID                    *Data,
94   IN  UINT32                  DataLen,
95   IN  UINT8                   Lun,
96   IN  UINT32                  Timeout,
97   OUT UINT32                  *CmdStatus
98   );
99 
100 /**
101   Reset the USB mass storage device by CBI protocol.
102 
103   This function resets the USB mass storage device by CBI protocol.
104   The reset is defined as a non-data command. Don't use UsbCbiExecCommand
105   to send the command to device because that may introduce recursive loop.
106 
107   @param  Context               The USB CBI protocol
108   @param  ExtendedVerification  The flag controlling the rule of reset.
109                                 Not used here.
110 
111   @retval EFI_SUCCESS           The device is reset.
112   @retval Others                Failed to reset the device.
113 
114 **/
115 EFI_STATUS
116 UsbCbiResetDevice (
117   IN  VOID                    *Context,
118   IN  BOOLEAN                  ExtendedVerification
119   );
120 
121 /**
122   Clean up the CBI protocol's resource.
123 
124   @param  Context               The instance of CBI protocol.
125 
126   @retval EFI_SUCCESS           The resource is cleaned up.
127 
128 **/
129 EFI_STATUS
130 UsbCbiCleanUp (
131   IN  VOID                   *Context
132   );
133 
134 #endif
135