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