17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d73ae94eSgc  * Common Development and Distribution License (the "License").
6d73ae94eSgc  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22ff0e937bSRaymond Chen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*e2c88f0cSGarrett D'Amore  *
25*e2c88f0cSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_SYS_USB_USBA_USBA_PRIVATE_H
297c478bd9Sstevel@tonic-gate #define	_SYS_USB_USBA_USBA_PRIVATE_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Header file for items to be shared within usba but not to be used
367c478bd9Sstevel@tonic-gate  * by drivers
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * **************************************************************************
457c478bd9Sstevel@tonic-gate  * DDK version 0.8 binaries are supported.
467c478bd9Sstevel@tonic-gate  * **************************************************************************
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /* USBA supports (obsolete) legacy version 0.8 of the S8/S9 DDK. */
507c478bd9Sstevel@tonic-gate #define	USBA_LEG_MAJOR_VER	0
517c478bd9Sstevel@tonic-gate #define	USBA_LEG_MINOR_VER	8
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * **************************************************************************
557c478bd9Sstevel@tonic-gate  * Descriptor definitions and parsing functions.
567c478bd9Sstevel@tonic-gate  * **************************************************************************
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * functions to return a pre-processed device descriptor to the client driver.
617c478bd9Sstevel@tonic-gate  * These all extract data from the raw config cloud  returned by a
627c478bd9Sstevel@tonic-gate  * usb_get_raw_cfg_data()
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * The pre-processed descriptor is returned into a buffer supplied by
657c478bd9Sstevel@tonic-gate  * the caller
667c478bd9Sstevel@tonic-gate  * The size of the buffer should allow for padding
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * In the following:
697c478bd9Sstevel@tonic-gate  *	buf		buffer containing data returned by GET_DESCRIPTOR
707c478bd9Sstevel@tonic-gate  *	buflen		length of the data at buf
717c478bd9Sstevel@tonic-gate  *	ret_descr	buffer the data is to be returned in
727c478bd9Sstevel@tonic-gate  *	ret_buf_len	size of the buffer at ret_descr
737c478bd9Sstevel@tonic-gate  *
74d73ae94eSgc  * 	first_if	the first interace associated with current iad
75d73ae94eSgc  *	if_index	the index in the array of concurrent interfaces
767c478bd9Sstevel@tonic-gate  *			supported by this configuration
77d73ae94eSgc  *	alt_if_setting	alternate setting for the interface identified
787c478bd9Sstevel@tonic-gate  *			by if_index
797c478bd9Sstevel@tonic-gate  *	ep_index	the index in the array of endpoints supported by
807c478bd9Sstevel@tonic-gate  *			this configuration
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  * These functions return the length of the returned descriptor structure,
837c478bd9Sstevel@tonic-gate  * or USB_PARSE_ERROR on error.
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  * No error is returned if ret_buf_len is too small but
867c478bd9Sstevel@tonic-gate  * the data is truncated
877c478bd9Sstevel@tonic-gate  * This allows successful parsing of descriptors that have been
887c478bd9Sstevel@tonic-gate  * extended in a later rev of the spec.
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate size_t usb_parse_dev_descr(
917c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(DEVICE) */
927c478bd9Sstevel@tonic-gate 	size_t			buflen,
937c478bd9Sstevel@tonic-gate 	usb_dev_descr_t		*ret_descr,
947c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate size_t usb_parse_cfg_descr(
987c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
997c478bd9Sstevel@tonic-gate 	size_t			buflen,
1007c478bd9Sstevel@tonic-gate 	usb_cfg_descr_t		*ret_descr,
1017c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
104d73ae94eSgc size_t usb_parse_ia_descr(
105d73ae94eSgc 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
106d73ae94eSgc 	size_t			buflen,
107d73ae94eSgc 	size_t			first_if,
108d73ae94eSgc 	usb_ia_descr_t		*ret_descr,
109d73ae94eSgc 	size_t			ret_buf_len);
110d73ae94eSgc 
111d73ae94eSgc 
1127c478bd9Sstevel@tonic-gate size_t usb_parse_if_descr(
1137c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1147c478bd9Sstevel@tonic-gate 	size_t			buflen,
1157c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1167c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1177c478bd9Sstevel@tonic-gate 	usb_if_descr_t		*ret_descr,
1187c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * the endpoint index is relative to the interface. index 0 is
1237c478bd9Sstevel@tonic-gate  * the first endpoint
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate size_t usb_parse_ep_descr(
1267c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1277c478bd9Sstevel@tonic-gate 	size_t			buflen,
1287c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1297c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1307c478bd9Sstevel@tonic-gate 	uint_t			ep_index,
1317c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		*ret_descr,
1327c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * functions to handle arbitrary descriptors. USBA doesn't know the format
1367c478bd9Sstevel@tonic-gate  * and therefore cannot do any automatic pre-processing.
1377c478bd9Sstevel@tonic-gate  *
1387c478bd9Sstevel@tonic-gate  * In the following:
1397c478bd9Sstevel@tonic-gate  *	buf		buffer containing data returned by GET_DESCRIPTOR
1407c478bd9Sstevel@tonic-gate  *	buflen		length of the data at buf allowing for padding
1417c478bd9Sstevel@tonic-gate  *	fmt		a null terminated string describing the format of
1427c478bd9Sstevel@tonic-gate  *			the data structure for general-purpose byte swapping,
1437c478bd9Sstevel@tonic-gate  *			use NULL for raw access.
1447c478bd9Sstevel@tonic-gate  *			The letters "c", "s", "l", and "L"
1457c478bd9Sstevel@tonic-gate  *			represent 1, 2, 4, and 8 byte quantities,
1467c478bd9Sstevel@tonic-gate  *			respectively.  A descriptor that consists of a
1477c478bd9Sstevel@tonic-gate  *			short and two bytes would be described by "scc\0".
1487c478bd9Sstevel@tonic-gate  *	descr_type	type of the desired descriptor, USB_DESCR_TYPE_ANY
1497c478bd9Sstevel@tonic-gate  *			to get any type.
1507c478bd9Sstevel@tonic-gate  *	descr_index	index of the desired descriptor
1517c478bd9Sstevel@tonic-gate  *	ret_descr	buffer the data is to be returned in
1527c478bd9Sstevel@tonic-gate  *	ret_buf_len	size of the buffer at ret_descr
1537c478bd9Sstevel@tonic-gate  *
1547c478bd9Sstevel@tonic-gate  * Specifying descr_index=0 returns the first descriptor of the specified
1557c478bd9Sstevel@tonic-gate  * type, specifying descr_index=1 returns the second, and so on.
1567c478bd9Sstevel@tonic-gate  *
1577c478bd9Sstevel@tonic-gate  * No error is returned if ret_buf_len is too small. This allows successful
1587c478bd9Sstevel@tonic-gate  * parsing of descriptors that have been extended in a later rev of the spec.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	USB_DESCR_TYPE_ANY			-1	/* Wild card */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate size_t usb_parse_CV_cfg_descr(
1637c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1647c478bd9Sstevel@tonic-gate 	size_t			buflen,
1657c478bd9Sstevel@tonic-gate 	char			*fmt,
1667c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1677c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1687c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1697c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate size_t usb_parse_CV_if_descr(
1737c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1747c478bd9Sstevel@tonic-gate 	size_t			buflen,
1757c478bd9Sstevel@tonic-gate 	char			*fmt,
1767c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1777c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1787c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1797c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1807c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1817c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate size_t usb_parse_CV_ep_descr(
1857c478bd9Sstevel@tonic-gate 	uchar_t			*buf,	/* from GET_DESCRIPTOR(CONFIGURATION) */
1867c478bd9Sstevel@tonic-gate 	size_t			buflen,
1877c478bd9Sstevel@tonic-gate 	char			*fmt,
1887c478bd9Sstevel@tonic-gate 	uint_t			if_index,
1897c478bd9Sstevel@tonic-gate 	uint_t			alt_if_setting,
1907c478bd9Sstevel@tonic-gate 	uint_t			ep_index,
1917c478bd9Sstevel@tonic-gate 	uint_t			descr_type,
1927c478bd9Sstevel@tonic-gate 	uint_t			descr_index,
1937c478bd9Sstevel@tonic-gate 	void			*ret_descr,
1947c478bd9Sstevel@tonic-gate 	size_t			ret_buf_len);
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  * for unpacking any kind of LE data
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate size_t usb_parse_CV_descr(
2017c478bd9Sstevel@tonic-gate 	char			*format,
2027c478bd9Sstevel@tonic-gate 	uchar_t			*data,
2037c478bd9Sstevel@tonic-gate 	size_t			datalen,
2047c478bd9Sstevel@tonic-gate 	void			*structure,
2057c478bd9Sstevel@tonic-gate 	size_t			structlen);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Returns pointer to the raw config cloud. The client should
2097c478bd9Sstevel@tonic-gate  * not free this space.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate uchar_t *usb_get_raw_cfg_data(
2127c478bd9Sstevel@tonic-gate 	dev_info_t		*dip,
2137c478bd9Sstevel@tonic-gate 	size_t			*length);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * Return pointer to device descriptor
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate usb_dev_descr_t *usb_get_dev_descr(
2197c478bd9Sstevel@tonic-gate 	dev_info_t		*dip);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * **************************************************************************
2247c478bd9Sstevel@tonic-gate  * List entry functions and definitions
2257c478bd9Sstevel@tonic-gate  * **************************************************************************
2267c478bd9Sstevel@tonic-gate  */
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate  * Data structure for maintaining lists
2307c478bd9Sstevel@tonic-gate  * This data structure private to USBA and not exposed to HCD or client
2317c478bd9Sstevel@tonic-gate  * driver or hub driver
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate typedef struct usba_list_entry {
2347c478bd9Sstevel@tonic-gate 	struct usba_list_entry	*next;		/* ptr to next element */
2357c478bd9Sstevel@tonic-gate 	struct usba_list_entry	*prev;		/* ptr to previous element */
2367c478bd9Sstevel@tonic-gate 	kmutex_t		list_mutex;	/* mutex that protects queue */
2377c478bd9Sstevel@tonic-gate 	usb_opaque_t		private;	/* ptr to private data */
2387c478bd9Sstevel@tonic-gate 	int			count;		/* for head of the list */
2397c478bd9Sstevel@tonic-gate 						/* counts of entries */
2407c478bd9Sstevel@tonic-gate } usba_list_entry_t;
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(usba_list_entry::list_mutex, usba_list_entry))
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate /* list entry functions. */
2467c478bd9Sstevel@tonic-gate void	usba_init_list(usba_list_entry_t *, usb_opaque_t,
2477c478bd9Sstevel@tonic-gate 					ddi_iblock_cookie_t);
2487c478bd9Sstevel@tonic-gate void	usba_destroy_list(usba_list_entry_t *);
2497c478bd9Sstevel@tonic-gate void	usba_add_to_list(usba_list_entry_t *, usba_list_entry_t *);
2507c478bd9Sstevel@tonic-gate int	usba_rm_from_list(usba_list_entry_t *, usba_list_entry_t *);
2517c478bd9Sstevel@tonic-gate void	usba_move_list(usba_list_entry_t *, usba_list_entry_t *,
2527c478bd9Sstevel@tonic-gate 					ddi_iblock_cookie_t);
2537c478bd9Sstevel@tonic-gate int	usba_check_in_list(usba_list_entry_t *, usba_list_entry_t *);
2547c478bd9Sstevel@tonic-gate int	usba_list_entry_leaks(usba_list_entry_t *, char *);
2557c478bd9Sstevel@tonic-gate int	usba_list_entry_count(usba_list_entry_t *);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate usb_opaque_t usba_rm_first_pvt_from_list(usba_list_entry_t *);
2587c478bd9Sstevel@tonic-gate usba_list_entry_t *usba_rm_first_from_list(usba_list_entry_t *);
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /*
2617c478bd9Sstevel@tonic-gate  * **************************************************************************
2627c478bd9Sstevel@tonic-gate  * Kernel interface definitions and functionality
2637c478bd9Sstevel@tonic-gate  * **************************************************************************
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * USBA private event definitions
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate typedef enum usba_event {
2707c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_HOT_REMOVAL = 0,
2717c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_HOT_INSERTION = 1,
2727c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_PRE_SUSPEND = 2,
2737c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_POST_RESUME = 3,
2747c478bd9Sstevel@tonic-gate 	USBA_EVENT_TAG_CPR = -1
2757c478bd9Sstevel@tonic-gate } usba_event_t;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #define	USBA_PRE_SUSPEND_EVENT	"SUNW,USBA:USBA_PRE_SUSPEND"
2787c478bd9Sstevel@tonic-gate #define	USBA_POST_RESUME_EVENT	"SUNW,USBA:USBA_POST_RESUME"
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate  * Get dma attributes from HC.
2827c478bd9Sstevel@tonic-gate  */
2837c478bd9Sstevel@tonic-gate ddi_dma_attr_t *usba_get_hc_dma_attr(dev_info_t *dip);
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate  * This function calls ndi_devi_bind_driver() to bind the
2877c478bd9Sstevel@tonic-gate  * driver to the device. If the call fails it reports an
2887c478bd9Sstevel@tonic-gate  * error on the console. Attaching of the driver is done
2897c478bd9Sstevel@tonic-gate  * later by devfs framework.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate int usba_bind_driver(dev_info_t *);
2927c478bd9Sstevel@tonic-gate 
293d73ae94eSgc /* check whether the dip owns an interface-associaiton */
294d73ae94eSgc boolean_t usba_owns_ia(dev_info_t *dip);
295d73ae94eSgc 
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate  * Driver binding functions
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate dev_info_t *usba_ready_device_node(dev_info_t *);
300d73ae94eSgc dev_info_t *usba_ready_interface_association_node(dev_info_t *,
301d73ae94eSgc 					uint_t, uint_t *);
3027c478bd9Sstevel@tonic-gate dev_info_t *usba_ready_interface_node(dev_info_t *, uint_t);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate /* Some Nexus driver functions. */
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate  * Common bus ctl for hcd, usb_mid and hubd.
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate int	usba_bus_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
3107c478bd9Sstevel@tonic-gate 					void *, void *);
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate void	usb_enable_parent_notification(dev_info_t *);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate  * Some functions for setting/getting usba_device from dip.
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate struct	usba_device	*usba_get_usba_device(dev_info_t *);
3187c478bd9Sstevel@tonic-gate struct	usba_device	*usba_polled_get_usba_device(dev_info_t *);
3197c478bd9Sstevel@tonic-gate void	usba_set_usba_device(dev_info_t *, struct usba_device *);
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /* extract NDI event registration info */
3227c478bd9Sstevel@tonic-gate struct	usba_evdata	*usba_get_evdata(dev_info_t *);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate /*
3257c478bd9Sstevel@tonic-gate  * **************************************************************************
3267c478bd9Sstevel@tonic-gate  * Misc private USBA functions
3277c478bd9Sstevel@tonic-gate  * **************************************************************************
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate /*
3317c478bd9Sstevel@tonic-gate  * Get policy of a pipe while holding only opaque pipe handle.
3327c478bd9Sstevel@tonic-gate  */
3337c478bd9Sstevel@tonic-gate usb_pipe_policy_t *usba_pipe_get_policy(usb_pipe_handle_t);
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  * Check interrupt context and or in USB_CB_INTR_CONTEXT to cb_flags as needed.
3377c478bd9Sstevel@tonic-gate  */
3387c478bd9Sstevel@tonic-gate usb_cb_flags_t	usba_check_intr_context(usb_cb_flags_t);
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /* returns interface number, zero if driver owns the device */
3417c478bd9Sstevel@tonic-gate uint8_t	usba_get_ifno(dev_info_t *);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * **************************************************************************
3457c478bd9Sstevel@tonic-gate  * Misc private descriptor definitions and functionality
3467c478bd9Sstevel@tonic-gate  * **************************************************************************
3477c478bd9Sstevel@tonic-gate  */
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /* default endpoint descriptor */
3507c478bd9Sstevel@tonic-gate extern usb_ep_descr_t   usba_default_ep_descr;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate /*
3537c478bd9Sstevel@tonic-gate  * The compiler pads the above structures;  the following represent the
3547c478bd9Sstevel@tonic-gate  * unpadded, aggregate data sizes.
3557c478bd9Sstevel@tonic-gate  */
3567c478bd9Sstevel@tonic-gate #define	USB_DEV_DESCR_SIZE	18	/* device descr size */
3577c478bd9Sstevel@tonic-gate #define	USB_CFG_DESCR_SIZE	 9	/* configuration desc. size */
3587c478bd9Sstevel@tonic-gate #define	USBA_CFG_PWR_DESCR_SIZE	18	/* configuration pwr desc. size */
3597c478bd9Sstevel@tonic-gate #define	USB_IF_DESCR_SIZE	 9	/* interface descr size */
3607c478bd9Sstevel@tonic-gate #define	USBA_IF_PWR_DESCR_SIZE	15	/* interface pwr descr size */
3617c478bd9Sstevel@tonic-gate #define	USB_EP_DESCR_SIZE	 7	/* endpoint descr size */
362d73ae94eSgc #define	USB_IA_DESCR_SIZE	 8	/* interface association descr size */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate  * For compatibility with old code.
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate #define	USBA_DESCR_TYPE_CFG_PWR_1_1	0xfe
3687c478bd9Sstevel@tonic-gate #define	USBA_DESCR_TYPE_IF_PWR_1_1	0xff
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate /*
3717c478bd9Sstevel@tonic-gate  * Configuration Power Descriptor
3727c478bd9Sstevel@tonic-gate  *	This reports the power consuption of the device core
3737c478bd9Sstevel@tonic-gate  *	for all types of USB devices.
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate typedef struct usba_cfg_pwr_descr {
3767c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* size of this descriptor 0x12 */
3777c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* config pwr descr 0x07 */
3787c478bd9Sstevel@tonic-gate 	uint16_t	SelfPowerConsumedD0_l;	/* power consumed lower word */
3797c478bd9Sstevel@tonic-gate 	uint8_t		SelfPowerConsumedD0_h;	/* power consumed upper byte */
3807c478bd9Sstevel@tonic-gate 	uint8_t		bPowerSummaryId;	/* ID for own power devices */
3817c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD1;	/* power saving in D1 */
3827c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD1;	/* power saving in D1 */
3837c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD2;	/* power saving in D2 */
3847c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD2;	/* power saving in D2 */
3857c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD3;	/* power saving in D3 */
3867c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD3;	/* power saving in D3 */
3877c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD1;	/* D1 -> D0 transition time */
3887c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD2;	/* D2 -> D0 transition time */
3897c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD3;	/* D3 -> D0 transition time */
3907c478bd9Sstevel@tonic-gate } usba_cfg_pwr_descr_t;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate  * Interface Power Descriptor
3947c478bd9Sstevel@tonic-gate  *	This reports the power states implemented by the interface
3957c478bd9Sstevel@tonic-gate  *	and its wake-up capabilities.
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate typedef struct usba_if_pwr_descr {
3987c478bd9Sstevel@tonic-gate 	uint8_t		bLength;	/* size of this descriptor 0x0F */
3997c478bd9Sstevel@tonic-gate 	uint8_t		bDescriptorType;	/* i/f pwr descr 0x08 */
4007c478bd9Sstevel@tonic-gate 	uint8_t		bmCapabilitiesFlags;	/* wakeup & pwr transition */
4017c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD1;	/* power saving in D1 */
4027c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD1;	/* power saving in D1 */
4037c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD2;	/* power saving in D2 */
4047c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD2;	/* power saving in D2 */
4057c478bd9Sstevel@tonic-gate 	uint8_t		bBusPowerSavingD3;	/* power saving in D3 */
4067c478bd9Sstevel@tonic-gate 	uint8_t		bSelfPowerSavingD3;	/* power saving in D3 */
4077c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD1;	/* D1 -> D0 transition time */
4087c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD2;	/* D2 -> D0 transition time */
4097c478bd9Sstevel@tonic-gate 	uint16_t	TransitionTimeFromD3;	/* D3 -> D0 transition time */
4107c478bd9Sstevel@tonic-gate } usba_if_pwr_descr_t;
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate size_t usba_parse_cfg_pwr_descr(uchar_t *, size_t, usba_cfg_pwr_descr_t *,
4137c478bd9Sstevel@tonic-gate 						size_t);
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate size_t usba_parse_if_pwr_descr(uchar_t *, size_t buflen, uint_t,
4167c478bd9Sstevel@tonic-gate 	uint_t, usba_if_pwr_descr_t *, size_t);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /*
4197c478bd9Sstevel@tonic-gate  * Returns (at ret_descr) a null-terminated string.  Null termination is
4207c478bd9Sstevel@tonic-gate  * guaranteed, even if the string is longer than the buffer.  Thus, a
4217c478bd9Sstevel@tonic-gate  * maximum of (ret_buf_len - 1) characters are returned.
4227c478bd9Sstevel@tonic-gate  *
4237c478bd9Sstevel@tonic-gate  * XXX is this needed when there is usb_get_string_descriptor
4247c478bd9Sstevel@tonic-gate  * If so, then more comments about how it differs?
4257c478bd9Sstevel@tonic-gate  */
4267c478bd9Sstevel@tonic-gate size_t usba_ascii_string_descr(uchar_t *, size_t, char *, size_t);
4277c478bd9Sstevel@tonic-gate 
428d73ae94eSgc 
429d73ae94eSgc /*
430d73ae94eSgc  * usb common power management, for usb_mid, usb_ia and maybe other simple
431d73ae94eSgc  * drivers.
432d73ae94eSgc  */
433d73ae94eSgc typedef struct usb_common_power_struct {
434d73ae94eSgc 	void		*uc_usb_statep;	/* points back to state structure */
435d73ae94eSgc 
436d73ae94eSgc 	uint8_t		uc_wakeup_enabled;
437d73ae94eSgc 
438d73ae94eSgc 	/* this is the bit mask of the power states that device has */
439d73ae94eSgc 	uint8_t		uc_pwr_states;
440d73ae94eSgc 
441d73ae94eSgc 	/* wakeup and power transition capabilites of an interface */
442d73ae94eSgc 	uint8_t		uc_pm_capabilities;
443d73ae94eSgc 
444d73ae94eSgc 	uint8_t		uc_current_power;	/* current power level */
445d73ae94eSgc } usb_common_power_t;
446d73ae94eSgc 
447d73ae94eSgc /* warlock directives, stable data */
448036aa261Sgc 
449d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_usb_statep))
450d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_wakeup_enabled))
451d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_pwr_states))
452d73ae94eSgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_pm_capabilities))
453036aa261Sgc _NOTE(DATA_READABLE_WITHOUT_LOCK(usb_common_power_t::uc_current_power))
454d73ae94eSgc 
455d73ae94eSgc /* power management */
456036aa261Sgc int usba_common_power(dev_info_t *, uint8_t *, int *, int);
457d73ae94eSgc 
458d73ae94eSgc /*
459d73ae94eSgc  * usb common events handler for usb_mid, usb_ia and maybe other nexus
460d73ae94eSgc  * drivers.
461d73ae94eSgc  */
462d73ae94eSgc 
463d73ae94eSgc void usba_common_register_events(dev_info_t *, uint_t,
464d73ae94eSgc 	void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *));
465d73ae94eSgc 
466d73ae94eSgc void usba_common_unregister_events(dev_info_t *, uint_t);
467d73ae94eSgc 
468d73ae94eSgc 
4697c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate #endif
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_USBA_USBA_PRIVATE_H */
474