- Revert 44301
[reactos.git] / drivers / usb / nt4compat / usbdriver / hub.h
1
2 #ifndef __HUB_H__
3 #define __HUB_H__
4
5 /*
6 * Hub Class feature numbers
7 */
8 #define C_HUB_LOCAL_POWER 0
9 #define C_HUB_OVER_CURRENT 1
10
11 /*
12 * Port feature numbers
13 */
14 #define USB_PORT_FEAT_CONNECTION 0
15 #define USB_PORT_FEAT_ENABLE 1
16 #define USB_PORT_FEAT_SUSPEND 2
17 #define USB_PORT_FEAT_OVER_CURRENT 3
18 #define USB_PORT_FEAT_RESET 4
19 #define USB_PORT_FEAT_POWER 8
20 #define USB_PORT_FEAT_LOWSPEED 9
21 #define USB_PORT_FEAT_C_CONNECTION 16
22 #define USB_PORT_FEAT_C_ENABLE 17
23 #define USB_PORT_FEAT_C_SUSPEND 18
24 #define USB_PORT_FEAT_C_OVER_CURRENT 19
25 #define USB_PORT_FEAT_C_RESET 20
26
27 /* wPortStatus bits */
28 #define USB_PORT_STAT_CONNECTION 0x0001
29 #define USB_PORT_STAT_ENABLE 0x0002
30 #define USB_PORT_STAT_SUSPEND 0x0004
31 #define USB_PORT_STAT_OVERCURRENT 0x0008
32 #define USB_PORT_STAT_RESET 0x0010
33 #define USB_PORT_STAT_POWER 0x0100
34 #define USB_PORT_STAT_LOW_SPEED 0x0200
35
36 /* usb 2.0 features */
37 #define USB_PORT_STAT_HIGH_SPEED 0x0400
38 #define USB_PORT_STAT_PORT_TEST 0x0800
39 #define USB_PORT_STAT_PORT_INDICATOR 0x1000
40
41 /* wPortChange bits */
42 #define USB_PORT_STAT_C_CONNECTION 0x0001
43 #define USB_PORT_STAT_C_ENABLE 0x0002
44 #define USB_PORT_STAT_C_SUSPEND 0x0004
45 #define USB_PORT_STAT_C_OVERCURRENT 0x0008
46 #define USB_PORT_STAT_C_RESET 0x0010
47
48 /* wHubCharacteristics (masks) */
49 #define HUB_CHAR_LPSM 0x0003
50 #define HUB_CHAR_COMPOUND 0x0004
51 #define HUB_CHAR_OCPM 0x0018
52
53 /*
54 *Hub Status & Hub Change bit masks
55 */
56 #define HUB_STATUS_LOCAL_POWER 0x0001
57 #define HUB_STATUS_OVERCURRENT 0x0002
58
59 #define HUB_CHANGE_LOCAL_POWER 0x0001
60 #define HUB_CHANGE_OVERCURRENT 0x0002
61
62 #define HUB_DESCRIPTOR_MAX_SIZE 39 /* enough for 127 ports on a hub */
63
64 #define MAX_HUB_PORTS 8
65 #define USB_HUB_INTERVAL 0xff
66
67 #define USB_PORT_FLAG_STATE_MASK ( 0xf << 16 )
68 #define USB_PORT_FLAG_ENABLE ( 0x1 << 16 )
69 #define USB_PORT_FLAG_DISABLE ( 0x2 << 16 )
70 #define USB_PORT_FLAG_DISCONNECT ( 0x3 << 16 )
71
72 #define USB_PORT_QUE_STATE_MASK 0xff // for detail, refer to document.txt
73 #define STATE_IDLE 0x00
74 #define STATE_EXAMINE_STATUS_QUE 0x01 // set when post a event to examine the status queue
75 #define STATE_WAIT_STABLE 0x02 // set when a new connection comes and about to wait some ms
76 #define STATE_WAIT_RESET 0x03 // set when dev stable and about to reset, may pending in the event queue
77 #define STATE_WAIT_RESET_COMPLETE 0x04 // set when reset signal is about to assert on the port
78 #define STATE_WAIT_ADDRESSED 0x05 // set when reset complete and before address is assigned
79
80 #define port_state( port_FLAG ) \
81 ( port_FLAG & USB_PORT_QUE_STATE_MASK )
82
83 #define set_port_state( port_FLAG, stATE ) \
84 { port_FLAG = ( port_FLAG & (~USB_PORT_QUE_STATE_MASK ) ) | ( stATE & USB_PORT_QUE_STATE_MASK ) ;}
85
86 #define default_endp_handle( endp_HANDLE ) \
87 ( ( endp_HANDLE & 0xffff ) == 0xffff )
88
89 #define is_if_dev( pdev ) ( pdev->flags & USB_DEV_FLAG_IF_DEV )
90
91 #define is_composite_dev( pdev ) \
92 ( is_if_dev( pdev ) == FALSE \
93 && pdev->pusb_dev_desc->bDeviceClass == 0 \
94 && pdev->pusb_dev_desc->bDeviceSubClass == 0 )
95
96 #define dev_handle_from_dev( pdev ) ( pdev->dev_id << 16 )
97 #define hub_ext_from_dev( pdEV ) ( ( PHUB2_EXTENSION )pdEV->dev_ext )
98
99 #pragma pack( push, hub_align, 1 )
100 typedef struct _USB_PORT_STATUS
101 {
102 USHORT wPortStatus;
103 USHORT wPortChange;
104
105 } USB_PORT_STATUS, *PUSB_PORT_STATUS;
106
107
108 typedef struct _USB_HUB_STATUS
109 {
110 USHORT wHubStatus;
111 USHORT wHubChange;
112
113 } USB_HUB_STATUS, *PUSB_HUB_STATUS;
114
115
116 typedef struct _USB_HUB_DESCRIPTOR
117 {
118 BYTE bLength;
119 BYTE bDescriptorType;
120 BYTE bNbrPorts;
121 USHORT wHubCharacteristics;
122 BYTE bPwrOn2PwrGood;
123 BYTE bHubContrCurrent;
124
125 /* DeviceRemovable and PortPwrCtrlMask want to be variable-length
126 bitmaps that hold max 256 entries, but for now they're ignored */
127 BYTE bitmap[0];
128 } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
129 #pragma pack( pop, hub_align )
130
131 typedef struct _PORT_STATUS_QUEUE
132 {
133 USB_PORT_STATUS port_status[ 4 ];
134 BYTE status_count;
135 ULONG port_flags;
136
137 } PORT_STATUS_QUEUE, *PPORT_STATUS_QUEUE;
138
139 VOID
140 psq_init(
141 PPORT_STATUS_QUEUE psq
142 );
143
144 BOOLEAN
145 psq_enqueue(
146 PPORT_STATUS_QUEUE psq,
147 ULONG status
148 );
149 ULONG
150 psq_outqueue(
151 PPORT_STATUS_QUEUE psq
152 ); //return 0xffffffff if no element
153
154 BOOLEAN
155 psq_push(
156 PPORT_STATUS_QUEUE psq,
157 ULONG status
158 );
159
160 #define psq_is_empty( pSQ ) ( ( pSQ )->status_count == 0 )
161 #define psq_is_full( pSQ ) ( ( pSQ )->status_count == 4 )
162 #define psq_count( psq ) ( ( psq )->status_count )
163 #define psq_peek( psq, i ) \
164 ( ( ( ULONG )i ) < 3 ? ( psq )->port_status[ i ] : ( psq )->port_status[ 3 ] )
165
166 #define MAX_DEVS 127
167 #define EHCI_MAX_ROOT_PORTS 15
168
169 typedef struct _HUB_EXTENSION
170 {
171
172 LONG port_count;
173 PUSB_DEV child_dev[ MAX_HUB_PORTS + 1 ];
174
175 PORT_STATUS_QUEUE port_status_queue[ MAX_HUB_PORTS + 1];
176 PUSB_DEV pdev;
177 PUSB_INTERFACE pif;
178 BYTE int_data_buf[ 64 ];
179
180 USB_HUB_STATUS hub_status;
181 USB_PORT_STATUS port_status; //working data buf for get port feature
182
183 USB_PORT_STATUS rh_port1_status; //working buf for get rh port1 feature
184 USB_PORT_STATUS rh_port2_status; //working buf for get rh port2 feature
185
186 USB_HUB_DESCRIPTOR hub_desc;
187
188 } HUB_EXTENSION, *PHUB_EXTENSION;
189
190 typedef struct _HUB2_PORT_TT
191 {
192 ULONG tt_busy : 1;
193
194 } HUB2_PORT_TT, *PHUB2_PORT_TT;
195
196 typedef struct _HUB2_EXTENSION
197 {
198
199 LONG port_count;
200 PUSB_DEV child_dev[ MAX_HUB_PORTS + 1 ];
201
202 PORT_STATUS_QUEUE port_status_queue[ MAX_HUB_PORTS + 1];
203
204 PUSB_DEV pdev;
205 PUSB_INTERFACE pif;
206 BYTE int_data_buf[ 32 ]; // for ports up to 127
207
208 USB_HUB_STATUS hub_status;
209 USB_PORT_STATUS port_status; //working data buf for get port feature
210
211 USB_PORT_STATUS rh_port_status[ EHCI_MAX_ROOT_PORTS + 1 ]; //working buf for get rh ports feature
212
213 UCHAR multiple_tt; // boolean
214 ULONG tt_status_map[ 4 ]; // bit map to indicate the indexed tt's periodic buffer busy or not
215 ULONG tt_bulk_map[ 4 ]; // bit map to indicate the indexed tt's bulk/control buffer busy or not
216 USB_HUB_DESCRIPTOR hub_desc;
217
218 } HUB2_EXTENSION, *PHUB2_EXTENSION;
219
220
221 VOID
222 event_list_default_process_queue(
223 PLIST_HEAD event_list,
224 PUSB_EVENT_POOL event_pool,
225 PUSB_EVENT usb_event,
226 PUSB_EVENT out_event
227 );
228
229 VOID
230 event_list_default_process_event(
231 PUSB_DEV dev,
232 ULONG event,
233 ULONG context,
234 ULONG param
235 );
236
237 // root hub routines and definitions
238
239 #define RH_INTERVAL ( USB_HUB_INTERVAL / DEV_MGR_TIMER_INTERVAL_MS )
240
241 BOOLEAN
242 rh_driver_destroy(
243 PUSB_DEV_MANAGER dev_mgr,
244 PUSB_DRIVER pdriver
245 );
246
247 BOOLEAN
248 rh_driver_init(
249 PUSB_DEV_MANAGER dev_mgr,
250 PUSB_DRIVER pdriver
251 );
252
253 BOOLEAN
254 rh_destroy(
255 PUSB_DEV pdev
256 );
257
258 VOID
259 rh_timer_svc(
260 PUSB_DEV dev,
261 PVOID context
262 );
263
264 BOOLEAN
265 rh_submit_urb(
266 PUSB_DEV pdev,
267 PURB urb
268 );
269
270 BOOLEAN
271 hub_init(
272 PUSB_DEV pdev
273 );
274
275 BOOLEAN
276 hub_destroy(
277 PUSB_DEV pdev
278 );
279
280 BOOLEAN
281 hub_lock_tt(
282 PUSB_DEV pdev,
283 UCHAR port_idx,
284 UCHAR type // transfer type
285 );
286
287 BOOLEAN
288 hub_unlock_tt(
289 PUSB_DEV pdev,
290 UCHAR port_idx,
291 UCHAR type
292 );
293
294
295 VOID
296 hub_post_clear_tt_event(
297 PUSB_DEV pdev,
298 BYTE port_idx,
299 ULONG pipe
300 );
301
302 BOOLEAN
303 compdev_driver_init(
304 PUSB_DEV_MANAGER dev_mgr,
305 PUSB_DRIVER pdriver
306 );
307
308 BOOLEAN
309 compdev_driver_destroy(
310 PUSB_DEV_MANAGER dev_mgr,
311 PUSB_DRIVER pdriver
312 );
313
314 BOOLEAN
315 gendrv_driver_init(
316 PUSB_DEV_MANAGER dev_mgr,
317 PUSB_DRIVER pdriver
318 );
319
320 BOOLEAN
321 gendrv_driver_destroy(
322 PUSB_DEV_MANAGER dev_mgr,
323 PUSB_DRIVER pdriver
324 );
325
326 BOOLEAN
327 gendrv_if_driver_init(
328 PUSB_DEV_MANAGER dev_mgr,
329 PUSB_DRIVER pdriver
330 );
331
332 BOOLEAN
333 gendrv_if_driver_destroy(
334 PUSB_DEV_MANAGER dev_mgr,
335 PUSB_DRIVER pdriver
336 );
337
338 BOOLEAN hub_driver_init(PUSB_DEV_MANAGER dev_mgr, PUSB_DRIVER pdriver);
339 BOOLEAN hub_driver_destroy(PUSB_DEV_MANAGER dev_mgr, PUSB_DRIVER pdriver);
340 BOOLEAN hub_remove_reset_event(PUSB_DEV pdev, ULONG port_idx, BOOLEAN from_dpc);
341 BOOLEAN hub_start_next_reset_port(PUSB_DEV_MANAGER dev_mgr, BOOLEAN from_dpc);
342 NTSTATUS hub_start_int_request(PUSB_DEV pdev);
343
344 #endif
345
346