iPXE
usbhub.h
Go to the documentation of this file.
1#ifndef _USBHUB_H
2#define _USBHUB_H
3
4/** @file
5 *
6 * USB hubs
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <ipxe/usb.h>
14#include <ipxe/list.h>
15#include <ipxe/process.h>
16
17/** Request recipient is a port */
18#define USB_HUB_RECIP_PORT ( 3 << 0 )
19
20/** A basic USB hub descriptor */
22 /** Descriptor header */
24 /** Number of ports */
26 /** Characteristics */
28 /** Power-on delay (in 2ms intervals */
30 /** Controller current (in mA) */
32} __attribute__ (( packed ));
33
34/** A basic USB hub descriptor */
35#define USB_HUB_DESCRIPTOR 41
36
37/** An enhanced USB hub descriptor */
39 /** Basic USB hub descriptor */
41 /** Header decode latency */
43 /** Maximum delay */
45 /** Removable device bitmask */
47} __attribute__ (( packed ));
48
49/** An enhanced USB hub descriptor */
50#define USB_HUB_DESCRIPTOR_ENHANCED 42
51
52/** A USB hub descriptor */
54 /** Descriptor header */
56 /** Basic hub descriptor */
58 /** Enhanced hub descriptor */
60} __attribute__ (( packed ));
61
62/** Port status */
64 /** Current status */
66 /** Changed status */
68} __attribute__ (( packed ));
69
70/** Current connect status feature */
71#define USB_HUB_PORT_CONNECTION 0
72
73/** Port enabled/disabled feature */
74#define USB_HUB_PORT_ENABLE 1
75
76/** Port reset feature */
77#define USB_HUB_PORT_RESET 4
78
79/** Port power feature */
80#define USB_HUB_PORT_POWER 8
81
82/** Low-speed device attached */
83#define USB_HUB_PORT_LOW_SPEED 9
84
85/** High-speed device attached */
86#define USB_HUB_PORT_HIGH_SPEED 10
87
88/** Connect status changed */
89#define USB_HUB_C_PORT_CONNECTION 16
90
91/** Port enable/disable changed */
92#define USB_HUB_C_PORT_ENABLE 17
93
94/** Suspend changed */
95#define USB_HUB_C_PORT_SUSPEND 18
96
97/** Over-current indicator changed */
98#define USB_HUB_C_PORT_OVER_CURRENT 19
99
100/** Reset changed */
101#define USB_HUB_C_PORT_RESET 20
102
103/** Link state changed */
104#define USB_HUB_C_PORT_LINK_STATE 25
105
106/** Configuration error */
107#define USB_HUB_C_PORT_CONFIG_ERROR 26
108
109/** Calculate feature from change bit number */
110#define USB_HUB_C_FEATURE( bit ) ( 16 + (bit) )
111
112/** USB features */
113#define USB_HUB_FEATURES \
114 ( ( 1 << USB_HUB_C_PORT_CONNECTION ) | \
115 ( 1 << USB_HUB_C_PORT_ENABLE ) | \
116 ( 1 << USB_HUB_C_PORT_SUSPEND ) | \
117 ( 1 << USB_HUB_C_PORT_OVER_CURRENT ) | \
118 ( 1 << USB_HUB_C_PORT_RESET ) )
119
120/** USB features for enhanced hubs */
121#define USB_HUB_FEATURES_ENHANCED \
122 ( ( 1 << USB_HUB_C_PORT_CONNECTION ) | \
123 ( 1 << USB_HUB_C_PORT_OVER_CURRENT ) | \
124 ( 1 << USB_HUB_C_PORT_RESET ) | \
125 ( 1 << USB_HUB_C_PORT_LINK_STATE ) | \
126 ( 1 << USB_HUB_C_PORT_CONFIG_ERROR ) )
127
128/** Set hub depth */
129#define USB_HUB_SET_HUB_DEPTH \
130 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_DEVICE | \
131 USB_REQUEST_TYPE ( 12 ) )
132
133/** Clear transaction translator buffer */
134#define USB_HUB_CLEAR_TT_BUFFER \
135 ( USB_DIR_OUT | USB_TYPE_CLASS | USB_HUB_RECIP_PORT | \
136 USB_REQUEST_TYPE ( 8 ) )
137
138/**
139 * Get hub descriptor
140 *
141 * @v usb USB device
142 * @v enhanced Hub is an enhanced hub
143 * @v data Hub descriptor to fill in
144 * @ret rc Return status code
145 */
146static inline __attribute__ (( always_inline )) int
147usb_hub_get_descriptor ( struct usb_device *usb, int enhanced,
148 union usb_hub_descriptor *data ) {
149 unsigned int desc;
150 size_t len;
151
152 /* Determine descriptor type and length */
154 len = ( enhanced ? sizeof ( data->enhanced ) : sizeof ( data->basic ) );
155
156 return usb_get_descriptor ( usb, USB_TYPE_CLASS, desc, 0, 0,
157 &data->header, len );
158}
159
160/**
161 * Get port status
162 *
163 * @v usb USB device
164 * @v port Port address
165 * @v status Port status descriptor to fill in
166 * @ret rc Return status code
167 */
168static inline __attribute__ (( always_inline )) int
169usb_hub_get_port_status ( struct usb_device *usb, unsigned int port,
170 struct usb_hub_port_status *status ) {
171
173 port, status, sizeof ( *status ) );
174}
175
176/**
177 * Clear port feature
178 *
179 * @v usb USB device
180 * @v port Port address
181 * @v feature Feature to clear
182 * @v index Index (when clearing a port indicator)
183 * @ret rc Return status code
184 */
185static inline __attribute__ (( always_inline )) int
186usb_hub_clear_port_feature ( struct usb_device *usb, unsigned int port,
187 unsigned int feature, unsigned int index ) {
188
190 feature, ( ( index << 8 ) | port ) );
191}
192
193/**
194 * Set port feature
195 *
196 * @v usb USB device
197 * @v port Port address
198 * @v feature Feature to clear
199 * @v index Index (when clearing a port indicator)
200 * @ret rc Return status code
201 */
202static inline __attribute__ (( always_inline )) int
203usb_hub_set_port_feature ( struct usb_device *usb, unsigned int port,
204 unsigned int feature, unsigned int index ) {
205
207 feature, ( ( index << 8 ) | port ) );
208}
209
210/**
211 * Set hub depth
212 *
213 * @v usb USB device
214 * @v depth Hub depth
215 * @ret rc Return status code
216 */
217static inline __attribute__ (( always_inline )) int
218usb_hub_set_hub_depth ( struct usb_device *usb, unsigned int depth ) {
219
220 return usb_control ( usb, USB_HUB_SET_HUB_DEPTH, depth, 0, NULL, 0 );
221}
222
223/**
224 * Clear transaction translator buffer
225 *
226 * @v usb USB device
227 * @v device Device address
228 * @v endpoint Endpoint address
229 * @v attributes Endpoint attributes
230 * @v tt_port Transaction translator port (or 1 for single-TT hubs)
231 * @ret rc Return status code
232 */
233static inline __attribute__ (( always_inline )) int
234usb_hub_clear_tt_buffer ( struct usb_device *usb, unsigned int device,
235 unsigned int endpoint, unsigned int attributes,
236 unsigned int tt_port ) {
237 unsigned int value;
238
239 /* Calculate value */
240 value = ( ( ( endpoint & USB_ENDPOINT_MAX ) << 0 ) | ( device << 4 ) |
241 ( ( attributes & USB_ENDPOINT_ATTR_TYPE_MASK ) << 11 ) |
242 ( ( endpoint & USB_ENDPOINT_IN ) << 8 ) );
243
245 tt_port, NULL, 0 );
246}
247
248/** Transaction translator port value for single-TT hubs */
249#define USB_HUB_TT_SINGLE 1
250
251/** A USB hub device */
253 /** Name */
254 const char *name;
255 /** USB device */
257 /** USB hub */
258 struct usb_hub *hub;
259 /** Features */
260 unsigned int features;
261 /** Flags */
262 unsigned int flags;
263
264 /** Interrupt endpoint */
266 /** Interrupt endpoint refill process */
268};
269
270/** Hub requires additional settling delay */
271#define USB_HUB_SLOW_START 0x0001
272
273/** Additional setting delay for out-of-spec hubs */
274#define USB_HUB_SLOW_START_DELAY_MS 500
275
276/** Interrupt ring fill level
277 *
278 * This is a policy decision.
279 */
280#define USB_HUB_INTR_FILL 4
281
282/** Maximum time to wait for port to become enabled
283 *
284 * This is a policy decision.
285 */
286#define USB_HUB_ENABLE_MAX_WAIT_MS 100
287
288#endif /* _USBHUB_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
long index
Definition bigint.h:65
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint8_t status
Status.
Definition ena.h:5
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
Universal Serial Bus (USB)
#define USB_ENDPOINT_MAX
Maximum endpoint number.
Definition usb.h:522
static int usb_clear_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Clear feature.
Definition usb.h:1127
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition usb.h:525
static int usb_set_feature(struct usb_device *usb, unsigned int type, unsigned int feature, unsigned int index)
Set feature.
Definition usb.h:1144
#define USB_ENDPOINT_ATTR_TYPE_MASK
Endpoint attribute transfer type mask.
Definition usb.h:281
static int usb_get_status(struct usb_device *usb, unsigned int type, unsigned int index, void *data, size_t len)
Get status.
Definition usb.h:1110
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition usb.h:1177
#define USB_TYPE_CLASS
Class-specific request type.
Definition usb.h:104
Linked lists.
Processes.
A hardware device.
Definition device.h:77
A named feature.
Definition features.h:79
A process.
Definition process.h:18
A USB descriptor header.
Definition usb.h:173
A USB device.
Definition usb.h:723
A USB endpoint.
Definition usb.h:404
A basic USB hub descriptor.
Definition usbhub.h:21
uint8_t current
Controller current (in mA)
Definition usbhub.h:31
uint8_t delay
Power-on delay (in 2ms intervals.
Definition usbhub.h:29
struct usb_descriptor_header header
Descriptor header.
Definition usbhub.h:23
uint8_t ports
Number of ports.
Definition usbhub.h:25
uint16_t characteristics
Characteristics.
Definition usbhub.h:27
An enhanced USB hub descriptor.
Definition usbhub.h:38
uint16_t removable
Removable device bitmask.
Definition usbhub.h:46
uint8_t latency
Header decode latency.
Definition usbhub.h:42
uint16_t delay
Maximum delay.
Definition usbhub.h:44
struct usb_hub_descriptor_basic basic
Basic USB hub descriptor.
Definition usbhub.h:40
A USB hub device.
Definition usbhub.h:252
struct usb_endpoint intr
Interrupt endpoint.
Definition usbhub.h:265
struct process refill
Interrupt endpoint refill process.
Definition usbhub.h:267
unsigned int flags
Flags.
Definition usbhub.h:262
const char * name
Name.
Definition usbhub.h:254
struct usb_hub * hub
USB hub.
Definition usbhub.h:258
struct usb_device * usb
USB device.
Definition usbhub.h:256
unsigned int features
Features.
Definition usbhub.h:260
Port status.
Definition usbhub.h:63
uint16_t current
Current status.
Definition usbhub.h:65
uint16_t changed
Changed status.
Definition usbhub.h:67
A USB hub.
Definition usb.h:841
A USB hub descriptor.
Definition usbhub.h:53
struct usb_hub_descriptor_enhanced enhanced
Enhanced hub descriptor.
Definition usbhub.h:59
struct usb_descriptor_header header
Descriptor header.
Definition usbhub.h:55
struct usb_hub_descriptor_basic basic
Basic hub descriptor.
Definition usbhub.h:57
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition usb.c:784
#define USB_HUB_SET_HUB_DEPTH
Set hub depth.
Definition usbhub.h:129
static int usb_hub_set_hub_depth(struct usb_device *usb, unsigned int depth)
Set hub depth.
Definition usbhub.h:218
static int usb_hub_set_port_feature(struct usb_device *usb, unsigned int port, unsigned int feature, unsigned int index)
Set port feature.
Definition usbhub.h:203
static int usb_hub_clear_port_feature(struct usb_device *usb, unsigned int port, unsigned int feature, unsigned int index)
Clear port feature.
Definition usbhub.h:186
static int usb_hub_get_port_status(struct usb_device *usb, unsigned int port, struct usb_hub_port_status *status)
Get port status.
Definition usbhub.h:169
static int usb_hub_get_descriptor(struct usb_device *usb, int enhanced, union usb_hub_descriptor *data)
Get hub descriptor.
Definition usbhub.h:147
#define USB_HUB_CLEAR_TT_BUFFER
Clear transaction translator buffer.
Definition usbhub.h:134
#define USB_HUB_DESCRIPTOR
A basic USB hub descriptor.
Definition usbhub.h:35
#define USB_HUB_RECIP_PORT
Request recipient is a port.
Definition usbhub.h:18
#define USB_HUB_DESCRIPTOR_ENHANCED
An enhanced USB hub descriptor.
Definition usbhub.h:50
static int usb_hub_clear_tt_buffer(struct usb_device *usb, unsigned int device, unsigned int endpoint, unsigned int attributes, unsigned int tt_port)
Clear transaction translator buffer.
Definition usbhub.h:234