xref: /onnv-gate/usr/src/uts/common/sys/usb/usba/hcdi.h (revision 880:0f8e93fcf632)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*880Sfrits  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_USB_HCDI_H
280Sstevel@tonic-gate #define	_SYS_USB_HCDI_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifdef	__cplusplus
330Sstevel@tonic-gate extern "C" {
340Sstevel@tonic-gate #endif
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include <sys/usb/usba/genconsole.h>
370Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * HCD ops structure
410Sstevel@tonic-gate  *
420Sstevel@tonic-gate  * - this structure defines all entry points into HCD
430Sstevel@tonic-gate  *
440Sstevel@tonic-gate  * - all client driver USBAI functions that require HCD
450Sstevel@tonic-gate  *   involvement go through this ops table
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * - at HCD attach time, the HCD ops are passed to
480Sstevel@tonic-gate  *   to the USBA through usba_hcdi_attach()
490Sstevel@tonic-gate  *
500Sstevel@tonic-gate  * some of these ops implement the semantics of the corresponding
510Sstevel@tonic-gate  * USBAI interfaces. Refer to usbai.h for detailed description
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #define	HCDI_OPS_VERSION_0 0
540Sstevel@tonic-gate #define	HCDI_OPS_VERSION	HCDI_OPS_VERSION_0
550Sstevel@tonic-gate 
560Sstevel@tonic-gate typedef struct usba_hcdi_ops {
570Sstevel@tonic-gate 	int	usba_hcdi_ops_version;	/* implementation version */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	dev_info_t	*usba_hcdi_dip;	/* HCD's devinfo ptr */
600Sstevel@tonic-gate 
61*880Sfrits 	/* can this hcd support pm? */
62*880Sfrits 	int	(*usba_hcdi_pm_support)(dev_info_t *dip);
63*880Sfrits 
640Sstevel@tonic-gate 	/*
650Sstevel@tonic-gate 	 * usba_hcdi_pipe_open:
660Sstevel@tonic-gate 	 *	implements the semantics of usb_pipe_open()
670Sstevel@tonic-gate 	 *	USBA allocate the pipe_handle which contains
680Sstevel@tonic-gate 	 *	pipe_policy and endpoint pointers
690Sstevel@tonic-gate 	 */
700Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_open)(
710Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
720Sstevel@tonic-gate 		usb_flags_t		usb_flags);
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 	/*
750Sstevel@tonic-gate 	 * close a pipe
760Sstevel@tonic-gate 	 */
770Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_close)(
780Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
790Sstevel@tonic-gate 		usb_flags_t		usb_flags);
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	/*
820Sstevel@tonic-gate 	 * pipe management
830Sstevel@tonic-gate 	 */
840Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_reset)(
850Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
860Sstevel@tonic-gate 		usb_flags_t		usb_flags);
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	/*
890Sstevel@tonic-gate 	 * data transfer management
900Sstevel@tonic-gate 	 */
910Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_ctrl_xfer)(
920Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
930Sstevel@tonic-gate 		usb_ctrl_req_t		*usb_ctrl_req,
940Sstevel@tonic-gate 		usb_flags_t		usb_flags);
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	/*
970Sstevel@tonic-gate 	 * get HCD limitation on bulk xfer at a time?
980Sstevel@tonic-gate 	 */
990Sstevel@tonic-gate 	int	(*usba_hcdi_bulk_transfer_size)(
1000Sstevel@tonic-gate 		usba_device_t		*usba_device,
1010Sstevel@tonic-gate 		size_t			*size);
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	/*
1040Sstevel@tonic-gate 	 * do bulk read/write
1050Sstevel@tonic-gate 	 */
1060Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_bulk_xfer)(
1070Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
1080Sstevel@tonic-gate 		usb_bulk_req_t		*usb_bulk_req,
1090Sstevel@tonic-gate 		usb_flags_t		usb_flags);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	/*
1120Sstevel@tonic-gate 	 * do interrupt pipe read/write
1130Sstevel@tonic-gate 	 */
1140Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_intr_xfer)(
1150Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
1160Sstevel@tonic-gate 		usb_intr_req_t		*usb_intr_req,
1170Sstevel@tonic-gate 		usb_flags_t		usb_flags);
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	/*
1200Sstevel@tonic-gate 	 * stop interrupt pipe polling
1210Sstevel@tonic-gate 	 */
1220Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_stop_intr_polling)(
1230Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
1240Sstevel@tonic-gate 		usb_flags_t		usb_flags);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	/*
1270Sstevel@tonic-gate 	 * do isoch pipe read/write
1280Sstevel@tonic-gate 	 */
1290Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_isoc_xfer)(
1300Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
1310Sstevel@tonic-gate 		usb_isoc_req_t		*usb_isoc_req,
1320Sstevel@tonic-gate 		usb_flags_t		usb_flags);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	/*
1350Sstevel@tonic-gate 	 * stop isoc pipe polling
1360Sstevel@tonic-gate 	 */
1370Sstevel@tonic-gate 	int	(*usba_hcdi_pipe_stop_isoc_polling)(
1380Sstevel@tonic-gate 		usba_pipe_handle_data_t	*pipe_handle,
1390Sstevel@tonic-gate 		usb_flags_t		usb_flags);
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate 	/* utility isoc functions */
1420Sstevel@tonic-gate 	usb_frame_number_t
1430Sstevel@tonic-gate 		(*usba_hcdi_get_current_frame_number)(
1440Sstevel@tonic-gate 		usba_device_t		*usba_device);
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	uint_t	(*usba_hcdi_get_max_isoc_pkts)(
1470Sstevel@tonic-gate 		usba_device_t		*usba_device);
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	/*
1500Sstevel@tonic-gate 	 * Initialize OBP support for input
1510Sstevel@tonic-gate 	 */
1520Sstevel@tonic-gate 	int	(*usba_hcdi_console_input_init)(
1530Sstevel@tonic-gate 		usba_pipe_handle_data_t		*pipe_handle,
1540Sstevel@tonic-gate 		uchar_t				**obp_buf,
1550Sstevel@tonic-gate 		usb_console_info_impl_t		*console_input_info);
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	/*
1580Sstevel@tonic-gate 	 * Free resources allocated by usba_hcdi_console_input_init
1590Sstevel@tonic-gate 	 */
1600Sstevel@tonic-gate 	int	(*usba_hcdi_console_input_fini)(
1610Sstevel@tonic-gate 		usb_console_info_impl_t		*console_input_info);
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	/*
1640Sstevel@tonic-gate 	 * Save controller state information
1650Sstevel@tonic-gate 	 */
1660Sstevel@tonic-gate 	int	(*usba_hcdi_console_input_enter)(
1670Sstevel@tonic-gate 		usb_console_info_impl_t		*console_input_info);
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	/*
1700Sstevel@tonic-gate 	 * Read character from controller
1710Sstevel@tonic-gate 	 */
1720Sstevel@tonic-gate 	int	(*usba_hcdi_console_read)(
1730Sstevel@tonic-gate 		usb_console_info_impl_t		*console_input_info,
1740Sstevel@tonic-gate 		uint_t				*num_characters);
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	/*
1770Sstevel@tonic-gate 	 * Restore controller state information
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate 	int	(*usba_hcdi_console_input_exit)(
1800Sstevel@tonic-gate 		usb_console_info_impl_t		*console_input_info);
1810Sstevel@tonic-gate } usba_hcdi_ops_t;
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate /*
1850Sstevel@tonic-gate  * callback support:
1860Sstevel@tonic-gate  *	this function handles all HCD callbacks as follows:
1870Sstevel@tonic-gate  *	- USB_FLAGS_SLEEP determines whether the client driver made
1880Sstevel@tonic-gate  *	  a synchronous or asynchronous USBAI call
1890Sstevel@tonic-gate  *	- for synchronous calls, the args are copied into the pipe handle
1900Sstevel@tonic-gate  *		and the sync cv of the pipe handle is signalled
1910Sstevel@tonic-gate  *	- for async calls and completion_reason = 0, the normal callback
1920Sstevel@tonic-gate  *		is invoked
1930Sstevel@tonic-gate  *	- for async calls and completion_reason != 0, the exception
1940Sstevel@tonic-gate  *		callback is invoked
1950Sstevel@tonic-gate  */
1960Sstevel@tonic-gate void
1970Sstevel@tonic-gate usba_hcdi_cb(usba_pipe_handle_data_t	*ph,
1980Sstevel@tonic-gate 		usb_opaque_t		req,
1990Sstevel@tonic-gate 		usb_cr_t		completion_reason);
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate /*
2020Sstevel@tonic-gate  * function to duplicate a interrupt/isoc request (for HCD)
2030Sstevel@tonic-gate  */
2040Sstevel@tonic-gate usb_intr_req_t	*usba_hcdi_dup_intr_req(dev_info_t *,
2050Sstevel@tonic-gate 			usb_intr_req_t *, size_t, usb_flags_t);
2060Sstevel@tonic-gate usb_isoc_req_t	*usba_hcdi_dup_isoc_req(dev_info_t *,
2070Sstevel@tonic-gate 			usb_isoc_req_t *, usb_flags_t);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate /* access to private member of requests */
2100Sstevel@tonic-gate usb_opaque_t	usba_hcdi_get_req_private(usb_opaque_t);
2110Sstevel@tonic-gate void		usba_hcdi_set_req_private(usb_opaque_t, usb_opaque_t);
2120Sstevel@tonic-gate usba_pipe_handle_data_t *
2130Sstevel@tonic-gate 		usba_hcdi_get_ph_data(usba_device_t *, uint8_t);
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate /* data toggle get and set */
2160Sstevel@tonic-gate uchar_t		usba_hcdi_get_data_toggle(usba_device_t *, uint8_t);
2170Sstevel@tonic-gate void 		usba_hcdi_set_data_toggle(usba_device_t *, uint8_t, uchar_t);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate  * HCD Nexus driver support:
2210Sstevel@tonic-gate  */
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate  * hcd_ops allocator/deallocator
2250Sstevel@tonic-gate  *	USBA allocates the usba_hcdi_ops so we can easily handle
2260Sstevel@tonic-gate  *	versioning
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate usba_hcdi_ops_t	*usba_alloc_hcdi_ops();
2290Sstevel@tonic-gate void		usba_free_hcdi_ops(usba_hcdi_ops_t *);
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate  * Argument structure for usba_hcdi_register
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate typedef struct usba_hcdi_register_args {
2350Sstevel@tonic-gate 	uint_t			usba_hcdi_register_version;
2360Sstevel@tonic-gate 	dev_info_t		*usba_hcdi_register_dip;
2370Sstevel@tonic-gate 	usba_hcdi_ops_t		*usba_hcdi_register_ops;
2380Sstevel@tonic-gate 	ddi_dma_attr_t		*usba_hcdi_register_dma_attr;
2390Sstevel@tonic-gate 	ddi_iblock_cookie_t	usba_hcdi_register_iblock_cookie;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate } usba_hcdi_register_args_t;
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate #define	HCDI_REGISTER_VERS_0		0
2440Sstevel@tonic-gate #define	HCDI_REGISTER_VERSION		HCDI_REGISTER_VERS_0
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * make	this instance known to USBA
2490Sstevel@tonic-gate  *
2500Sstevel@tonic-gate  * the HCD must initialize the hcdi_ops before calling this function
2510Sstevel@tonic-gate  */
2520Sstevel@tonic-gate int	usba_hcdi_register(usba_hcdi_register_args_t *, uint_t);
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate /*
2550Sstevel@tonic-gate  * detach support
2560Sstevel@tonic-gate  */
2570Sstevel@tonic-gate void	usba_hcdi_unregister(dev_info_t *);
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate  * Hotplug kstats named structure
2610Sstevel@tonic-gate  *
2620Sstevel@tonic-gate  * Number of types of USB transfers
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate #define	USB_N_COUNT_KSTATS	4
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate typedef struct hcdi_hotplug_stats {
2670Sstevel@tonic-gate 	struct kstat_named	hcdi_hotplug_total_success;
2680Sstevel@tonic-gate 	struct kstat_named	hcdi_hotplug_success;
2690Sstevel@tonic-gate 	struct kstat_named	hcdi_hotplug_total_failure;
2700Sstevel@tonic-gate 	struct kstat_named	hcdi_hotplug_failure;
2710Sstevel@tonic-gate 	struct kstat_named	hcdi_device_count;
2720Sstevel@tonic-gate } hcdi_hotplug_stats_t;
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate /*
2750Sstevel@tonic-gate  * USB error kstats named structure
2760Sstevel@tonic-gate  */
2770Sstevel@tonic-gate typedef struct hcdi_error_stats {
2780Sstevel@tonic-gate 	/* transport completion codes */
2790Sstevel@tonic-gate 	struct kstat_named	cc_crc;
2800Sstevel@tonic-gate 	struct kstat_named	cc_bitstuffing;
2810Sstevel@tonic-gate 	struct kstat_named	cc_data_toggle_mm;
2820Sstevel@tonic-gate 	struct kstat_named	cc_stall;
2830Sstevel@tonic-gate 	struct kstat_named	cc_dev_not_resp;
2840Sstevel@tonic-gate 	struct kstat_named	cc_pid_checkfailure;
2850Sstevel@tonic-gate 	struct kstat_named	cc_unexp_pid;
2860Sstevel@tonic-gate 	struct kstat_named	cc_data_overrun;
2870Sstevel@tonic-gate 	struct kstat_named	cc_data_underrun;
2880Sstevel@tonic-gate 	struct kstat_named	cc_buffer_overrun;
2890Sstevel@tonic-gate 	struct kstat_named	cc_buffer_underrun;
2900Sstevel@tonic-gate 	struct kstat_named	cc_timeout;
2910Sstevel@tonic-gate 	struct kstat_named	cc_not_accessed;
2920Sstevel@tonic-gate 	struct kstat_named	cc_no_resources;
2930Sstevel@tonic-gate 	struct kstat_named	cc_unspecified_err;
2940Sstevel@tonic-gate 	struct kstat_named	cc_stopped_polling;
2950Sstevel@tonic-gate 	struct kstat_named	cc_pipe_closing;
2960Sstevel@tonic-gate 	struct kstat_named	cc_pipe_reset;
2970Sstevel@tonic-gate 	struct kstat_named	cc_not_supported;
2980Sstevel@tonic-gate 	struct kstat_named	cc_flushed;
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate #ifdef	NOTYETNEEDED
3010Sstevel@tonic-gate 	/* USBA function return values */
3020Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_failure;
3030Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_no_resources;
3040Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_no_bandwidth;
3050Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_pipe_reserved;
3060Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_pipe_unshareable;
3070Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_not_supported;
3080Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_pipe_error;
3090Sstevel@tonic-gate 	struct kstat_named	hcdi_usb_pipe_busy;
3100Sstevel@tonic-gate #endif
3110Sstevel@tonic-gate } hcdi_error_stats_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate /*
3140Sstevel@tonic-gate  * hcdi kstat defines
3150Sstevel@tonic-gate  * XXX this needs to be a function
3160Sstevel@tonic-gate  */
3170Sstevel@tonic-gate #define	HCDI_HOTPLUG_STATS(hcdi)	((hcdi)->hcdi_hotplug_stats)
3180Sstevel@tonic-gate #define	HCDI_HOTPLUG_STATS_DATA(hcdi)	\
3190Sstevel@tonic-gate 	((hcdi_hotplug_stats_t *)HCDI_HOTPLUG_STATS((hcdi))->ks_data)
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate #define	HCDI_ERROR_STATS(hcdi)		((hcdi)->hcdi_error_stats)
3220Sstevel@tonic-gate #define	HCDI_ERROR_STATS_DATA(hcdi)	\
3230Sstevel@tonic-gate 	((hcdi_error_stats_t *)HCDI_ERROR_STATS((hcdi))->ks_data)
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate #ifdef __cplusplus
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate #endif
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate #endif	/* _SYS_USB_HCDI_H */
331