1 /** @file
2 
3     The definition for USB hub.
4 
5 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution.  The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10 
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef _USB_HUB_H_
17 #define _USB_HUB_H_
18 
19 #include <IndustryStandard/Usb.h>
20 
21 #define USB_ENDPOINT_ADDR(EpAddr) ((EpAddr) & 0x7F)
22 #define USB_ENDPOINT_TYPE(Desc)   ((Desc)->Attributes & USB_ENDPOINT_TYPE_MASK)
23 
24 
25 #define USB_DESC_TYPE_HUB     0x29
26 
27 #define USB_DESC_TYPE_HUB_SUPER_SPEED  0x2a
28 
29 //
30 // Hub class control transfer target
31 //
32 #define USB_HUB_TARGET_HUB    0
33 #define USB_HUB_TARGET_PORT   3
34 //
35 // HUB class specific contrl transfer request type
36 //
37 #define USB_HUB_REQ_GET_STATUS      0
38 #define USB_HUB_REQ_CLEAR_FEATURE   1
39 #define USB_HUB_REQ_SET_FEATURE     3
40 #define USB_HUB_REQ_GET_DESC        6
41 #define USB_HUB_REQ_SET_DESC        7
42 #define USB_HUB_REQ_CLEAR_TT        8
43 #define USB_HUB_REQ_RESET_TT        9
44 #define USB_HUB_REQ_GET_TT_STATE    10
45 #define USB_HUB_REQ_STOP_TT         11
46 
47 #define USB_HUB_REQ_SET_DEPTH       12
48 
49 //
50 // USB hub class feature selector
51 //
52 #define USB_HUB_C_HUB_LOCAL_POWER   0
53 #define USB_HUB_C_HUB_OVER_CURRENT  1
54 #define USB_HUB_PORT_CONNECTION     0
55 #define USB_HUB_PORT_ENABLE         1
56 #define USB_HUB_PORT_SUSPEND        2
57 #define USB_HUB_PORT_OVER_CURRENT   3
58 #define USB_HUB_PORT_RESET          4
59 
60 #define USB_HUB_PORT_LINK_STATE     5
61 
62 #define USB_HUB_PORT_POWER          8
63 #define USB_HUB_PORT_LOW_SPEED      9
64 #define USB_HUB_C_PORT_CONNECT      16
65 #define USB_HUB_C_PORT_ENABLE       17
66 #define USB_HUB_C_PORT_SUSPEND      18
67 #define USB_HUB_C_PORT_OVER_CURRENT 19
68 #define USB_HUB_C_PORT_RESET        20
69 #define USB_HUB_PORT_TEST           21
70 #define USB_HUB_PORT_INDICATOR      22
71 
72 #define USB_HUB_C_PORT_LINK_STATE     25
73 #define USB_HUB_PORT_REMOTE_WAKE_MASK 27
74 #define USB_HUB_BH_PORT_RESET         28
75 #define USB_HUB_C_BH_PORT_RESET       29
76 
77 //
78 // Constant value for Port Status & Port Change Status of SuperSpeed port
79 //
80 #define USB_SS_PORT_STAT_C_BH_RESET         0x0020
81 #define USB_SS_PORT_STAT_C_PORT_LINK_STATE  0x0040
82 //
83 // USB hub power control method. In gang power control
84 //
85 #define USB_HUB_GANG_POWER_CTRL     0
86 #define USB_HUB_PORT_POWER_CTRL     0x01
87 //
88 // USB hub status bits
89 //
90 #define USB_HUB_STAT_LOCAL_POWER    0x01
91 #define USB_HUB_STAT_OVER_CURRENT   0x02
92 #define USB_HUB_STAT_C_LOCAL_POWER  0x01
93 #define USB_HUB_STAT_C_OVER_CURRENT 0x02
94 
95 #define USB_HUB_CLASS_CODE          0x09
96 #define USB_HUB_SUBCLASS_CODE       0x00
97 
98 //
99 // Host software return timeout if port status doesn't change
100 // after 500ms(LOOP * STALL = 5000 * 0.1ms), set by experience
101 //
102 #define USB_WAIT_PORT_STS_CHANGE_LOOP  5000
103 
104 #pragma pack(1)
105 //
106 // Hub descriptor, the last two fields are of variable lenght.
107 //
108 typedef struct {
109   UINT8           Length;
110   UINT8           DescType;
111   UINT8           NumPorts;
112   UINT16          HubCharacter;
113   UINT8           PwrOn2PwrGood;
114   UINT8           HubContrCurrent;
115   UINT8           Filler[16];
116 } EFI_USB_HUB_DESCRIPTOR;
117 
118 typedef struct {
119   UINT8           Length;
120   UINT8           DescType;
121   UINT8           NumPorts;
122   UINT16          HubCharacter;
123   UINT8           PwrOn2PwrGood;
124   UINT8           HubContrCurrent;
125   UINT8           HubHdrDecLat;
126   UINT8           HubDelay;
127   UINT8           DeviceRemovable;
128 } EFI_USB_SUPER_SPEED_HUB_DESCRIPTOR;
129 
130 #pragma pack()
131 
132 
133 typedef struct {
134   UINT16                ChangedBit;
135   EFI_USB_PORT_FEATURE  Feature;
136 } USB_CHANGE_FEATURE_MAP;
137 
138 
139 /**
140   Clear the transaction translate buffer if full/low
141   speed control/bulk transfer failed and the transfer
142   uses this hub as translator.Remember to clear the TT
143   buffer of transaction translator, not that of the
144   parent.
145 
146   @param  UsbDev                The Usb device.
147   @param  Port                  The port of the hub.
148   @param  DevAddr               Address of the failed transaction.
149   @param  EpNum                 The endpoint number of the failed transaction.
150   @param  EpType                The type of failed transaction.
151 
152   @retval EFI_SUCCESS           The TT buffer is cleared.
153   @retval Others                Failed to clear the TT buffer.
154 
155 **/
156 EFI_STATUS
157 UsbHubCtrlClearTTBuffer (
158   IN USB_DEVICE           *UsbDev,
159   IN UINT8                Port,
160   IN UINT16               DevAddr,
161   IN UINT16               EpNum,
162   IN UINT16               EpType
163   );
164 
165 
166 /**
167   Test whether the interface is a hub interface.
168 
169   @param  UsbIf                 The interface to test.
170 
171   @retval TRUE                  The interface is a hub interface.
172   @retval FALSE                 The interface isn't a hub interface.
173 
174 **/
175 BOOLEAN
176 UsbIsHubInterface (
177   IN USB_INTERFACE        *UsbIf
178   );
179 
180 
181 /**
182   Ack the hub change bits. If these bits are not ACKed, Hub will
183   always return changed bit map from its interrupt endpoint.
184 
185   @param  UsbDev                The Usb device.
186 
187   @retval EFI_SUCCESS           The hub change status is ACKed.
188   @retval Others                Failed to ACK the hub status.
189 
190 **/
191 EFI_STATUS
192 UsbHubAckHubStatus (
193   IN  USB_DEVICE         *UsbDev
194   );
195 
196 extern USB_HUB_API        mUsbHubApi;
197 extern USB_HUB_API        mUsbRootHubApi;
198 #endif
199 
200