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