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