xref: /titanic_50/usr/src/uts/common/sys/usb/usba/hcdi.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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 2004 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 	/*
62 	 * usba_hcdi_pipe_open:
63 	 *	implements the semantics of usb_pipe_open()
64 	 *	USBA allocate the pipe_handle which contains
65 	 *	pipe_policy and endpoint pointers
66 	 */
67 	int	(*usba_hcdi_pipe_open)(
68 		usba_pipe_handle_data_t	*pipe_handle,
69 		usb_flags_t		usb_flags);
70 
71 	/*
72 	 * close a pipe
73 	 */
74 	int	(*usba_hcdi_pipe_close)(
75 		usba_pipe_handle_data_t	*pipe_handle,
76 		usb_flags_t		usb_flags);
77 
78 	/*
79 	 * pipe management
80 	 */
81 	int	(*usba_hcdi_pipe_reset)(
82 		usba_pipe_handle_data_t	*pipe_handle,
83 		usb_flags_t		usb_flags);
84 
85 	/*
86 	 * data transfer management
87 	 */
88 	int	(*usba_hcdi_pipe_ctrl_xfer)(
89 		usba_pipe_handle_data_t	*pipe_handle,
90 		usb_ctrl_req_t		*usb_ctrl_req,
91 		usb_flags_t		usb_flags);
92 
93 	/*
94 	 * get HCD limitation on bulk xfer at a time?
95 	 */
96 	int	(*usba_hcdi_bulk_transfer_size)(
97 		usba_device_t		*usba_device,
98 		size_t			*size);
99 
100 	/*
101 	 * do bulk read/write
102 	 */
103 	int	(*usba_hcdi_pipe_bulk_xfer)(
104 		usba_pipe_handle_data_t	*pipe_handle,
105 		usb_bulk_req_t		*usb_bulk_req,
106 		usb_flags_t		usb_flags);
107 
108 	/*
109 	 * do interrupt pipe read/write
110 	 */
111 	int	(*usba_hcdi_pipe_intr_xfer)(
112 		usba_pipe_handle_data_t	*pipe_handle,
113 		usb_intr_req_t		*usb_intr_req,
114 		usb_flags_t		usb_flags);
115 
116 	/*
117 	 * stop interrupt pipe polling
118 	 */
119 	int	(*usba_hcdi_pipe_stop_intr_polling)(
120 		usba_pipe_handle_data_t	*pipe_handle,
121 		usb_flags_t		usb_flags);
122 
123 	/*
124 	 * do isoch pipe read/write
125 	 */
126 	int	(*usba_hcdi_pipe_isoc_xfer)(
127 		usba_pipe_handle_data_t	*pipe_handle,
128 		usb_isoc_req_t		*usb_isoc_req,
129 		usb_flags_t		usb_flags);
130 
131 	/*
132 	 * stop isoc pipe polling
133 	 */
134 	int	(*usba_hcdi_pipe_stop_isoc_polling)(
135 		usba_pipe_handle_data_t	*pipe_handle,
136 		usb_flags_t		usb_flags);
137 
138 	/* utility isoc functions */
139 	usb_frame_number_t
140 		(*usba_hcdi_get_current_frame_number)(
141 		usba_device_t		*usba_device);
142 
143 	uint_t	(*usba_hcdi_get_max_isoc_pkts)(
144 		usba_device_t		*usba_device);
145 
146 	/*
147 	 * Initialize OBP support for input
148 	 */
149 	int	(*usba_hcdi_console_input_init)(
150 		usba_pipe_handle_data_t		*pipe_handle,
151 		uchar_t				**obp_buf,
152 		usb_console_info_impl_t		*console_input_info);
153 
154 	/*
155 	 * Free resources allocated by usba_hcdi_console_input_init
156 	 */
157 	int	(*usba_hcdi_console_input_fini)(
158 		usb_console_info_impl_t		*console_input_info);
159 
160 	/*
161 	 * Save controller state information
162 	 */
163 	int	(*usba_hcdi_console_input_enter)(
164 		usb_console_info_impl_t		*console_input_info);
165 
166 	/*
167 	 * Read character from controller
168 	 */
169 	int	(*usba_hcdi_console_read)(
170 		usb_console_info_impl_t		*console_input_info,
171 		uint_t				*num_characters);
172 
173 	/*
174 	 * Restore controller state information
175 	 */
176 	int	(*usba_hcdi_console_input_exit)(
177 		usb_console_info_impl_t		*console_input_info);
178 } usba_hcdi_ops_t;
179 
180 
181 /*
182  * callback support:
183  *	this function handles all HCD callbacks as follows:
184  *	- USB_FLAGS_SLEEP determines whether the client driver made
185  *	  a synchronous or asynchronous USBAI call
186  *	- for synchronous calls, the args are copied into the pipe handle
187  *		and the sync cv of the pipe handle is signalled
188  *	- for async calls and completion_reason = 0, the normal callback
189  *		is invoked
190  *	- for async calls and completion_reason != 0, the exception
191  *		callback is invoked
192  */
193 void
194 usba_hcdi_cb(usba_pipe_handle_data_t	*ph,
195 		usb_opaque_t		req,
196 		usb_cr_t		completion_reason);
197 
198 /*
199  * function to duplicate a interrupt/isoc request (for HCD)
200  */
201 usb_intr_req_t	*usba_hcdi_dup_intr_req(dev_info_t *,
202 			usb_intr_req_t *, size_t, usb_flags_t);
203 usb_isoc_req_t	*usba_hcdi_dup_isoc_req(dev_info_t *,
204 			usb_isoc_req_t *, usb_flags_t);
205 
206 /* access to private member of requests */
207 usb_opaque_t	usba_hcdi_get_req_private(usb_opaque_t);
208 void		usba_hcdi_set_req_private(usb_opaque_t, usb_opaque_t);
209 usba_pipe_handle_data_t *
210 		usba_hcdi_get_ph_data(usba_device_t *, uint8_t);
211 
212 /* data toggle get and set */
213 uchar_t		usba_hcdi_get_data_toggle(usba_device_t *, uint8_t);
214 void 		usba_hcdi_set_data_toggle(usba_device_t *, uint8_t, uchar_t);
215 
216 /*
217  * HCD Nexus driver support:
218  */
219 
220 /*
221  * hcd_ops allocator/deallocator
222  *	USBA allocates the usba_hcdi_ops so we can easily handle
223  *	versioning
224  */
225 usba_hcdi_ops_t	*usba_alloc_hcdi_ops();
226 void		usba_free_hcdi_ops(usba_hcdi_ops_t *);
227 
228 /*
229  * Argument structure for usba_hcdi_register
230  */
231 typedef struct usba_hcdi_register_args {
232 	uint_t			usba_hcdi_register_version;
233 	dev_info_t		*usba_hcdi_register_dip;
234 	usba_hcdi_ops_t		*usba_hcdi_register_ops;
235 	ddi_dma_attr_t		*usba_hcdi_register_dma_attr;
236 	ddi_iblock_cookie_t	usba_hcdi_register_iblock_cookie;
237 
238 } usba_hcdi_register_args_t;
239 
240 #define	HCDI_REGISTER_VERS_0		0
241 #define	HCDI_REGISTER_VERSION		HCDI_REGISTER_VERS_0
242 
243 
244 /*
245  * make	this instance known to USBA
246  *
247  * the HCD must initialize the hcdi_ops before calling this function
248  */
249 int	usba_hcdi_register(usba_hcdi_register_args_t *, uint_t);
250 
251 /*
252  * detach support
253  */
254 void	usba_hcdi_unregister(dev_info_t *);
255 
256 /*
257  * Hotplug kstats named structure
258  *
259  * Number of types of USB transfers
260  */
261 #define	USB_N_COUNT_KSTATS	4
262 
263 typedef struct hcdi_hotplug_stats {
264 	struct kstat_named	hcdi_hotplug_total_success;
265 	struct kstat_named	hcdi_hotplug_success;
266 	struct kstat_named	hcdi_hotplug_total_failure;
267 	struct kstat_named	hcdi_hotplug_failure;
268 	struct kstat_named	hcdi_device_count;
269 } hcdi_hotplug_stats_t;
270 
271 /*
272  * USB error kstats named structure
273  */
274 typedef struct hcdi_error_stats {
275 	/* transport completion codes */
276 	struct kstat_named	cc_crc;
277 	struct kstat_named	cc_bitstuffing;
278 	struct kstat_named	cc_data_toggle_mm;
279 	struct kstat_named	cc_stall;
280 	struct kstat_named	cc_dev_not_resp;
281 	struct kstat_named	cc_pid_checkfailure;
282 	struct kstat_named	cc_unexp_pid;
283 	struct kstat_named	cc_data_overrun;
284 	struct kstat_named	cc_data_underrun;
285 	struct kstat_named	cc_buffer_overrun;
286 	struct kstat_named	cc_buffer_underrun;
287 	struct kstat_named	cc_timeout;
288 	struct kstat_named	cc_not_accessed;
289 	struct kstat_named	cc_no_resources;
290 	struct kstat_named	cc_unspecified_err;
291 	struct kstat_named	cc_stopped_polling;
292 	struct kstat_named	cc_pipe_closing;
293 	struct kstat_named	cc_pipe_reset;
294 	struct kstat_named	cc_not_supported;
295 	struct kstat_named	cc_flushed;
296 
297 #ifdef	NOTYETNEEDED
298 	/* USBA function return values */
299 	struct kstat_named	hcdi_usb_failure;
300 	struct kstat_named	hcdi_usb_no_resources;
301 	struct kstat_named	hcdi_usb_no_bandwidth;
302 	struct kstat_named	hcdi_usb_pipe_reserved;
303 	struct kstat_named	hcdi_usb_pipe_unshareable;
304 	struct kstat_named	hcdi_usb_not_supported;
305 	struct kstat_named	hcdi_usb_pipe_error;
306 	struct kstat_named	hcdi_usb_pipe_busy;
307 #endif
308 } hcdi_error_stats_t;
309 
310 /*
311  * hcdi kstat defines
312  * XXX this needs to be a function
313  */
314 #define	HCDI_HOTPLUG_STATS(hcdi)	((hcdi)->hcdi_hotplug_stats)
315 #define	HCDI_HOTPLUG_STATS_DATA(hcdi)	\
316 	((hcdi_hotplug_stats_t *)HCDI_HOTPLUG_STATS((hcdi))->ks_data)
317 
318 #define	HCDI_ERROR_STATS(hcdi)		((hcdi)->hcdi_error_stats)
319 #define	HCDI_ERROR_STATS_DATA(hcdi)	\
320 	((hcdi_error_stats_t *)HCDI_ERROR_STATS((hcdi))->ks_data)
321 
322 
323 #ifdef __cplusplus
324 }
325 #endif
326 
327 #endif	/* _SYS_USB_HCDI_H */
328