1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright 2016 Joyent, Inc.
*/
#ifndef _SYS_USB_HCDI_H
#define _SYS_USB_HCDI_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/usb/usba/genconsole.h>
#include <sys/usb/usba/usba_types.h>
/*
* HCD ops structure
*
* - this structure defines all entry points into HCD
*
* - all client driver USBAI functions that require HCD
* involvement go through this ops table
*
* - at HCD attach time, the HCD ops are passed to
* to the USBA through usba_hcdi_attach()
*
* some of these ops implement the semantics of the corresponding
* USBAI interfaces. Refer to usbai.h for detailed description
*/
#define HCDI_OPS_VERSION_0 0
#define HCDI_OPS_VERSION_1 1
#define HCDI_OPS_VERSION_2 2
#define HCDI_OPS_VERSION HCDI_OPS_VERSION_2
typedef struct usba_hcdi_ops {
int usba_hcdi_ops_version; /* implementation version */
dev_info_t *usba_hcdi_dip; /* HCD's devinfo ptr */
/* can this hcd support pm? */
int (*usba_hcdi_pm_support)(dev_info_t *dip);
/*
* usba_hcdi_pipe_open:
* implements the semantics of usb_pipe_open()
* USBA allocate the pipe_handle which contains
* pipe_policy and endpoint pointers
*/
int (*usba_hcdi_pipe_open)(
usba_pipe_handle_data_t *pipe_handle,
usb_flags_t usb_flags);
/*
* close a pipe
*/
int (*usba_hcdi_pipe_close)(
usba_pipe_handle_data_t *pipe_handle,
usb_flags_t usb_flags);
/*
* pipe management
*/
int (*usba_hcdi_pipe_reset)(
usba_pipe_handle_data_t *pipe_handle,
usb_flags_t usb_flags);
/*
* pipe management
*/
void (*usba_hcdi_pipe_reset_data_toggle)(
usba_pipe_handle_data_t *pipe_handle);
/*
* data transfer management
*/
int (*usba_hcdi_pipe_ctrl_xfer)(
usba_pipe_handle_data_t *pipe_handle,
usb_ctrl_req_t *usb_ctrl_req,
usb_flags_t usb_flags);
/*
* get HCD limitation on bulk xfer at a time?
*/
int (*usba_hcdi_bulk_transfer_size)(
usba_device_t *usba_device,
size_t *size);
/*
* do bulk read/write
*/
int (*usba_hcdi_pipe_bulk_xfer)(
usba_pipe_handle_data_t *pipe_handle,
usb_bulk_req_t *usb_bulk_req,
usb_flags_t usb_flags);
/*
* do interrupt pipe read/write
*/
int (*usba_hcdi_pipe_intr_xfer)(
usba_pipe_handle_data_t *pipe_handle,
usb_intr_req_t *usb_intr_req,
usb_flags_t usb_flags);
/*
* stop interrupt pipe polling
*/
int (*usba_hcdi_pipe_stop_intr_polling)(
usba_pipe_handle_data_t *pipe_handle,
usb_flags_t usb_flags);
/*
* do isoch pipe read/write
*/
int (*usba_hcdi_pipe_isoc_xfer)(
usba_pipe_handle_data_t *pipe_handle,
usb_isoc_req_t *usb_isoc_req,
usb_flags_t usb_flags);
/*
* stop isoc pipe polling
*/
int (*usba_hcdi_pipe_stop_isoc_polling)(
usba_pipe_handle_data_t *pipe_handle,
usb_flags_t usb_flags);
/* utility isoc functions */
int (*usba_hcdi_get_current_frame_number)(
usba_device_t *usba_device,
usb_frame_number_t *frame_number);
int (*usba_hcdi_get_max_isoc_pkts)(
usba_device_t *usba_device,
uint_t *max_isoc_pkts_per_request);
/*
* Initialize OBP support for input
*/
int (*usba_hcdi_console_input_init)(
usba_pipe_handle_data_t *pipe_handle,
uchar_t **obp_buf,
usb_console_info_impl_t *console_input_info);
/*
* Free resources allocated by usba_hcdi_console_input_init
*/
int (*usba_hcdi_console_input_fini)(
usb_console_info_impl_t *console_input_info);
/*
* Save controller state information
*/
int (*usba_hcdi_console_input_enter)(
usb_console_info_impl_t *console_input_info);
/*
* Read character from controller
*/
int (*usba_hcdi_console_read)(
usb_console_info_impl_t *console_input_info,
uint_t *num_characters);
/*
* Restore controller state information
*/
int (*usba_hcdi_console_input_exit)(
usb_console_info_impl_t *console_input_info);
/*
* VERSION 1 ops: support for polled output
*/
int (*usba_hcdi_console_output_init)(
usba_pipe_handle_data_t *pipe_handle,
usb_console_info_impl_t *console_output_info);
int (*usba_hcdi_console_output_fini)(
usb_console_info_impl_t *console_output_info);
int (*usba_hcdi_console_output_enter)(
usb_console_info_impl_t *console_output_info);
int (*usba_hcdi_console_write)(
usb_console_info_impl_t *console_output_info,
uchar_t *buf,
uint_t num_characters,
uint_t *num_characters_written);
int (*usba_hcdi_console_output_exit)(
usb_console_info_impl_t *console_output_info);
/*
* VERSION 2 ops: support for device initialization
*/
int (*usba_hcdi_device_init)(
usba_device_t *usba_device,
usb_port_t port,
void **);
void (*usba_hcdi_device_fini)(
usba_device_t *usba_device,
void *);
int (*usba_hcdi_device_address)(
usba_device_t *usba_device);
int (*usba_hcdi_hub_update)(
usba_device_t *usba_device,
uint8_t nports,
uint8_t think_time);
} usba_hcdi_ops_t;
/*
* callback support:
* this function handles all HCD callbacks as follows:
* - USB_FLAGS_SLEEP determines whether the client driver made
* a synchronous or asynchronous USBAI call
* - for synchronous calls, the args are copied into the pipe handle
* and the sync cv of the pipe handle is signalled
* - for async calls and completion_reason = 0, the normal callback
* is invoked
* - for async calls and completion_reason != 0, the exception
* callback is invoked
*/
void
usba_hcdi_cb(usba_pipe_handle_data_t *ph,
usb_opaque_t req,
usb_cr_t completion_reason);
/*
* function to duplicate a interrupt/isoc request (for HCD)
*/
usb_intr_req_t *usba_hcdi_dup_intr_req(dev_info_t *,
usb_intr_req_t *, size_t, usb_flags_t);
usb_isoc_req_t *usba_hcdi_dup_isoc_req(dev_info_t *,
usb_isoc_req_t *, usb_flags_t);
/* access to private member of requests */
usb_opaque_t usba_hcdi_get_req_private(usb_opaque_t);
void usba_hcdi_set_req_private(usb_opaque_t, usb_opaque_t);
usba_pipe_handle_data_t *
usba_hcdi_get_ph_data(usba_device_t *, uint8_t);
/* data toggle get and set */
uchar_t usba_hcdi_get_data_toggle(usba_device_t *, uint8_t);
void usba_hcdi_set_data_toggle(usba_device_t *, uint8_t, uchar_t);
/*
* HCD Nexus driver support:
*/
/*
* hcd_ops allocator/deallocator
* USBA allocates the usba_hcdi_ops so we can easily handle
* versioning
*/
usba_hcdi_ops_t *usba_alloc_hcdi_ops();
void usba_free_hcdi_ops(usba_hcdi_ops_t *);
/*
* Argument structure for usba_hcdi_register
*/
typedef struct usba_hcdi_register_args {
uint_t usba_hcdi_register_version;
dev_info_t *usba_hcdi_register_dip;
usba_hcdi_ops_t *usba_hcdi_register_ops;
ddi_dma_attr_t *usba_hcdi_register_dma_attr;
ddi_iblock_cookie_t usba_hcdi_register_iblock_cookie;
} usba_hcdi_register_args_t;
#define HCDI_REGISTER_VERS_0 0
#define HCDI_REGISTER_VERSION HCDI_REGISTER_VERS_0
/*
* make this instance known to USBA
*
* the HCD must initialize the hcdi_ops before calling this function
*/
int usba_hcdi_register(usba_hcdi_register_args_t *, uint_t);
/*
* detach support
*/
void usba_hcdi_unregister(dev_info_t *);
/*
* HCD device private storage
*/
void *usba_hcdi_get_device_private(usba_device_t *);
/*
* Hotplug kstats named structure
*
* Number of types of USB transfers
*/
#define USB_N_COUNT_KSTATS 4
typedef struct hcdi_hotplug_stats {
struct kstat_named hcdi_hotplug_total_success;
struct kstat_named hcdi_hotplug_success;
struct kstat_named hcdi_hotplug_total_failure;
struct kstat_named hcdi_hotplug_failure;
struct kstat_named hcdi_device_count;
} hcdi_hotplug_stats_t;
/*
* USB error kstats named structure
*/
typedef struct hcdi_error_stats {
/* transport completion codes */
struct kstat_named cc_crc;
struct kstat_named cc_bitstuffing;
struct kstat_named cc_data_toggle_mm;
struct kstat_named cc_stall;
struct kstat_named cc_dev_not_resp;
struct kstat_named cc_pid_checkfailure;
struct kstat_named cc_unexp_pid;
struct kstat_named cc_data_overrun;
struct kstat_named cc_data_underrun;
struct kstat_named cc_buffer_overrun;
struct kstat_named cc_buffer_underrun;
struct kstat_named cc_timeout;
struct kstat_named cc_not_accessed;
struct kstat_named cc_no_resources;
struct kstat_named cc_unspecified_err;
struct kstat_named cc_stopped_polling;
struct kstat_named cc_pipe_closing;
struct kstat_named cc_pipe_reset;
struct kstat_named cc_not_supported;
struct kstat_named cc_flushed;
} hcdi_error_stats_t;
/*
* hcdi kstat defines
* XXX this needs to be a function
*/
#define HCDI_HOTPLUG_STATS(hcdi) ((hcdi)->hcdi_hotplug_stats)
#define HCDI_HOTPLUG_STATS_DATA(hcdi) \
((hcdi_hotplug_stats_t *)HCDI_HOTPLUG_STATS((hcdi))->ks_data)
#define HCDI_ERROR_STATS(hcdi) ((hcdi)->hcdi_error_stats)
#define HCDI_ERROR_STATS_DATA(hcdi) \
((hcdi_error_stats_t *)HCDI_ERROR_STATS((hcdi))->ks_data)
/*
* The default timeout that should occur for non-periodic transfers if a timeout
* is not requested by a client driver. This is a time in seconds.
*/
#define HCDI_DEFAULT_TIMEOUT 5
#ifdef __cplusplus
}
#endif
#endif /* _SYS_USB_HCDI_H */
|