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 /*
22de6f998eSrui wang - Sun Microsystems - Beijing China  * 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_IMPL_H
297c478bd9Sstevel@tonic-gate #define	_SYS_USB_USBA_USBA_IMPL_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
337c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi.h>
347c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hubdi.h>
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_private.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
377c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
387c478bd9Sstevel@tonic-gate #include <sys/disp.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * UGEN binding values specified in <hcd>.conf files
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #define	USBA_UGEN_DEVICE_BINDING	1
497c478bd9Sstevel@tonic-gate #define	USBA_UGEN_INTERFACE_BINDING	2
50d73ae94eSgc #define	USBA_UGEN_INTERFACE_ASSOCIATION_BINDING		3
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Allocating a USB address
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	USBA_MAX_ADDRESS		127
567c478bd9Sstevel@tonic-gate #define	USBA_ADDRESS_ARRAY_SIZE	((USBA_MAX_ADDRESS+8)/8)
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * async execution of usb_pipe_* functions which have a
607c478bd9Sstevel@tonic-gate  * completion callback parameter (eg. usb_pipe_close(),
617c478bd9Sstevel@tonic-gate  * usb_pipe_reset(), usb_pipe_stop_*_polling()
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate typedef struct usba_pipe_async_req {
647c478bd9Sstevel@tonic-gate 	dev_info_t		*dip;
657c478bd9Sstevel@tonic-gate 	struct usba_ph_impl	*ph_impl;
667c478bd9Sstevel@tonic-gate 	usb_opaque_t		arg;
677c478bd9Sstevel@tonic-gate 	usb_flags_t		usb_flags;
687c478bd9Sstevel@tonic-gate 	void			(*callback)(
697c478bd9Sstevel@tonic-gate 					usb_pipe_handle_t	ph,
707c478bd9Sstevel@tonic-gate 					usb_opaque_t		callback_arg,
717c478bd9Sstevel@tonic-gate 					int			rval,
727c478bd9Sstevel@tonic-gate 					usb_cb_flags_t		error_code);
737c478bd9Sstevel@tonic-gate 	usb_opaque_t		callback_arg;
747c478bd9Sstevel@tonic-gate 	int			(*sync_func)(dev_info_t *,
757c478bd9Sstevel@tonic-gate 					usba_ph_impl_t *,
767c478bd9Sstevel@tonic-gate 					struct usba_pipe_async_req *,
777c478bd9Sstevel@tonic-gate 					usb_flags_t);
787c478bd9Sstevel@tonic-gate } usba_pipe_async_req_t;
797c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usba_pipe_async_req_t))
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* per-pipe taskq */
827c478bd9Sstevel@tonic-gate int	usba_async_ph_req(usba_pipe_handle_data_t *, void (*func)(void *),
837c478bd9Sstevel@tonic-gate 							void *, usb_flags_t);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * usb wrapper around pm_request_power_change to allow for
877c478bd9Sstevel@tonic-gate  * non blocking behavior
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate typedef struct usba_pm_req {
907c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;
917c478bd9Sstevel@tonic-gate 	int		comp;
927c478bd9Sstevel@tonic-gate 	int		old_level;
937c478bd9Sstevel@tonic-gate 	int		level;
947c478bd9Sstevel@tonic-gate 	void		(*cb)(void *, int);
957c478bd9Sstevel@tonic-gate 	void		*arg;
967c478bd9Sstevel@tonic-gate 	uint_t		flags;
977c478bd9Sstevel@tonic-gate } usba_pm_req_t;
987c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per call", usba_pm_req_t))
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * Request wrappers for control/bulk/interrupt and isoch pipes
1037c478bd9Sstevel@tonic-gate  * These are hidden from client driver. They serve as place-holders
1047c478bd9Sstevel@tonic-gate  * for doing callbacks
1057c478bd9Sstevel@tonic-gate  *
1067c478bd9Sstevel@tonic-gate  * Request allocation: wrapper + usb_*_req_t alloc'ed together:
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  *		+-----------------------+
1097c478bd9Sstevel@tonic-gate  *		|	wr_queue	|		for callbacks
1107c478bd9Sstevel@tonic-gate  *		+-----------------------+
1117c478bd9Sstevel@tonic-gate  *		|	wr_req	|-------+	wr_req points to
1127c478bd9Sstevel@tonic-gate  *		+-----------------------+	|	the req below.
1137c478bd9Sstevel@tonic-gate  *		|			|	|
1147c478bd9Sstevel@tonic-gate  *		|	....		|	|
1157c478bd9Sstevel@tonic-gate  *		|	req_wrapper_t	|	|
1167c478bd9Sstevel@tonic-gate  *		|			|	|
1177c478bd9Sstevel@tonic-gate  *		+-----------------------+<------+
1187c478bd9Sstevel@tonic-gate  *		|			|
1197c478bd9Sstevel@tonic-gate  *		|	....		|
1207c478bd9Sstevel@tonic-gate  *		| ctrl/bulk/intr/isoch	|
1217c478bd9Sstevel@tonic-gate  *		|	req_t	|
1227c478bd9Sstevel@tonic-gate  *		|			|
1237c478bd9Sstevel@tonic-gate  *		|			|
1247c478bd9Sstevel@tonic-gate  *		+-----------------------+
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate typedef struct usba_req_wrapper {
1277c478bd9Sstevel@tonic-gate 	/* queueing in either a request or callback queue */
1287c478bd9Sstevel@tonic-gate 	usba_list_entry_t	wr_queue;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * The request could be control/bulk/intr/isoc
1327c478bd9Sstevel@tonic-gate 	 * See usbai.h usb_ctrl_req_t/usb_bulk_req_t
1337c478bd9Sstevel@tonic-gate 	 * usb_intr_req_t/usb_isoc_req_t
1347c478bd9Sstevel@tonic-gate 	 */
1357c478bd9Sstevel@tonic-gate 	usb_opaque_t		wr_req;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	/* for allocation tracking in usba_device_t */
1387c478bd9Sstevel@tonic-gate 	usba_list_entry_t	wr_allocated_list;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	/*
1417c478bd9Sstevel@tonic-gate 	 * All reqs that are synchronous sleep on this cv
1427c478bd9Sstevel@tonic-gate 	 * for completion notification.
1437c478bd9Sstevel@tonic-gate 	 * In hcdi soft interrupt handler we call cv_signal()
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	kcondvar_t		wr_cv;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	/*
1487c478bd9Sstevel@tonic-gate 	 * This goes hand-in-hand with wr_cv. It is set by the soft intr hdlr
1497c478bd9Sstevel@tonic-gate 	 * before doing a cv_signal
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	boolean_t		wr_done;
1527c478bd9Sstevel@tonic-gate 	dev_info_t		*wr_dip;	/* owner */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	usb_opaque_t		wr_hcd_private;	/* for HCD's use */
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	usba_pipe_handle_data_t	*wr_ph_data;	/* ptr to pipe handle */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	usb_cr_t		wr_cr;		/* save cr from HCDI */
1597c478bd9Sstevel@tonic-gate 	usb_cb_flags_t		wr_cb_flags;	/* save cb_flags */
1607c478bd9Sstevel@tonic-gate 	usb_flags_t		wr_usb_flags;	/* save usb flags from HCDI */
1617c478bd9Sstevel@tonic-gate 	usb_req_attrs_t		wr_attrs;	/* save attrs from HCDI */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	/* total lenght of wrapper and request */
1647c478bd9Sstevel@tonic-gate 	size_t			wr_length;
1657c478bd9Sstevel@tonic-gate } usba_req_wrapper_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("method", usba_req_wrapper))
1687c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("method", usb_ctrl_req))
1697c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("method", usb_bulk_req))
1707c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("method", usb_intr_req))
1717c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("method", usb_isoc_req))
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /* additional flag for wr_usb_flags */
1747c478bd9Sstevel@tonic-gate #define	USBA_WRP_FLAGS_WAIT	0x01
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /* additional usb flags, not exposed to clients */
1777c478bd9Sstevel@tonic-gate #define	USBA_FLAGS_PRIVILEGED	0x02	/* for default pipe operations */
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /* Macros to convert wrapper to different request and vice-versa */
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /* to get the wr->wr_req field */
1827c478bd9Sstevel@tonic-gate #define	USBA_WRP2REQ(wrp)	((wrp)->wr_req)
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /* to get the wrapper form the wr_req field */
1857c478bd9Sstevel@tonic-gate #define	USBA_REQ2WRP(req)		(usba_req_wrapper_t *)\
1867c478bd9Sstevel@tonic-gate 				((uintptr_t)(req) - sizeof (usba_req_wrapper_t))
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /* to set the the address in the wr_req field */
1897c478bd9Sstevel@tonic-gate #define	USBA_SETREQ_ADDR(wrp)	((uintptr_t)(wrp) + sizeof (*(wrp)))
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /* to get the 4 xfer type requests */
1927c478bd9Sstevel@tonic-gate #define	USBA_WRP2CTRL_REQ(wrp)	((usb_ctrl_req_t *)USBA_WRP2REQ((wrp)))
1937c478bd9Sstevel@tonic-gate #define	USBA_WRP2INTR_REQ(wrp)	((usb_intr_req_t *)USBA_WRP2REQ((wrp)))
1947c478bd9Sstevel@tonic-gate #define	USBA_WRP2BULK_REQ(wrp)	((usb_bulk_req_t *)USBA_WRP2REQ((wrp)))
1957c478bd9Sstevel@tonic-gate #define	USBA_WRP2ISOC_REQ(wrp)	((usb_isoc_req_t *)USBA_WRP2REQ((wrp)))
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /* to get pipe_handle from the wrapper */
1987c478bd9Sstevel@tonic-gate #define	USBA_WRP2PH_DATA(wrp) \
1997c478bd9Sstevel@tonic-gate 	(usba_pipe_handle_data_t *)((wrp)->wr_ph_data)
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /* to get to the wr_queue from the wrapper */
2027c478bd9Sstevel@tonic-gate #define	USBA_WRQUEUE2WRP(queue)	(usba_req_wrapper_t *)(queue)
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate /* to get to the wr_allocated queue from the wrapper */
2057c478bd9Sstevel@tonic-gate #define	USBA_ALLOCQ2WRP(queue)	(usba_req_wrapper_t *)((uintptr_t) \
2067c478bd9Sstevel@tonic-gate 	(queue)  - sizeof (usba_list_entry_t) - sizeof (usb_opaque_t))
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /* alias for pipe handle member p_usba_private */
2107c478bd9Sstevel@tonic-gate #define	p_active_cntrl_req_wrp	p_usba_private
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate  * This function is used to get the HCD private field maintained by USBA.
2147c478bd9Sstevel@tonic-gate  * HCD calls this function.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate usb_opaque_t usba_hcdi_get_ctrl_req_hcd_private(usb_ctrl_req_t *);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * This function is used to set the HCD private field maintained by USBA.
2207c478bd9Sstevel@tonic-gate  * HCD calls this function.
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate void	usba_hcdi_set_ctrl_req_hcd_private(usb_ctrl_req_t *, usb_opaque_t);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate int	usba_set_usb_address(usba_device_t *);
2257c478bd9Sstevel@tonic-gate void	usba_unset_usb_address(usba_device_t *);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * Per Hub Data Structures
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate typedef  struct usba_hubdi {
2317c478bd9Sstevel@tonic-gate 	usba_list_entry_t hubdi_list;	 /* linking in hubdi list */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	dev_info_t	*hubdi_dip;	 /* ptr to devinfo struct */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	int		hubdi_flags;	/* flag options */
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate } usba_hubdi_t;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * usba_get_mfg_prod_sn_str:
2417c478bd9Sstevel@tonic-gate  *	Return a string containing mfg, product, serial number strings.
2427c478bd9Sstevel@tonic-gate  *	Remove duplicates if some strings are the same.
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate char	*usba_get_mfg_prod_sn_str(dev_info_t *, char *, int);
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /* return value when user doesn't specify configuration index */
2477c478bd9Sstevel@tonic-gate #define	USBA_DEV_CONFIG_INDEX_UNDEFINED	-1
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * prototypes
2517c478bd9Sstevel@tonic-gate  */
2527c478bd9Sstevel@tonic-gate void	usba_usba_initialization();
2537c478bd9Sstevel@tonic-gate void	usba_usba_destroy();
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate void	usba_usbai_register_initialization();
2567c478bd9Sstevel@tonic-gate void	usba_usbai_register_destroy();
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate void	usba_usbai_initialization();
2597c478bd9Sstevel@tonic-gate void	usba_usbai_destroy();
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate void	usba_hubdi_initialization();
2627c478bd9Sstevel@tonic-gate void	usba_hubdi_destroy();
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate void	usba_devdb_initialization();
2657c478bd9Sstevel@tonic-gate void	usba_devdb_destroy();
2667c478bd9Sstevel@tonic-gate 
267ff0e937bSRaymond Chen int	usba_hubdi_register(dev_info_t	*, uint_t);
268ff0e937bSRaymond Chen int	usba_hubdi_unregister(dev_info_t *);
269ff0e937bSRaymond Chen 
2707c478bd9Sstevel@tonic-gate int	usba_is_root_hub(dev_info_t *dip);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate usba_device_t *usba_alloc_usba_device(dev_info_t *);
2737c478bd9Sstevel@tonic-gate void	usba_free_usba_device(usba_device_t *usba_device_t);
2747c478bd9Sstevel@tonic-gate void	usba_clear_data_toggle(usba_device_t *usba_device);
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate void	usba_start_next_req(usba_pipe_handle_data_t *ph);
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate int	usba_pipe_check_handle(usba_pipe_handle_data_t *);
2797c478bd9Sstevel@tonic-gate int	usba_drain_cbs(usba_pipe_handle_data_t *, usb_cb_flags_t,
2807c478bd9Sstevel@tonic-gate 			usb_cr_t);
2817c478bd9Sstevel@tonic-gate int	usba_pipe_setup_func_call(dev_info_t *,
2827c478bd9Sstevel@tonic-gate 			int (*sync_func)(dev_info_t *,
2837c478bd9Sstevel@tonic-gate 				usba_ph_impl_t *, usba_pipe_async_req_t *,
2847c478bd9Sstevel@tonic-gate 				usb_flags_t),
2857c478bd9Sstevel@tonic-gate 			usba_ph_impl_t *,
2867c478bd9Sstevel@tonic-gate 			usb_opaque_t,
2877c478bd9Sstevel@tonic-gate 			usb_flags_t,
2887c478bd9Sstevel@tonic-gate 			void (*cb)(usb_pipe_handle_t, usb_opaque_t,
2897c478bd9Sstevel@tonic-gate 			    int, usb_cb_flags_t),
2907c478bd9Sstevel@tonic-gate 			usb_opaque_t);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate void	usba_pipe_new_state(usba_pipe_handle_data_t *, usb_pipe_state_t);
2947c478bd9Sstevel@tonic-gate 
295de6f998eSrui wang - Sun Microsystems - Beijing China void usba_add_root_hub(dev_info_t *dip);
296de6f998eSrui wang - Sun Microsystems - Beijing China void usba_rem_root_hub(dev_info_t *dip);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate  * retrieve string descriptors for manufacturer, vendor and serial
3007c478bd9Sstevel@tonic-gate  * number
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate void usba_get_dev_string_descrs(dev_info_t *, usba_device_t *);
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate  * Check if we are not in interrupt context and have
3067c478bd9Sstevel@tonic-gate  * USB_FLAGS_SLEEP flags set.
3077c478bd9Sstevel@tonic-gate  */
3087c478bd9Sstevel@tonic-gate #define	USBA_CHECK_CONTEXT()	ASSERT(!(servicing_interrupt()))
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate  * USBA module Masks
3127c478bd9Sstevel@tonic-gate  */
3137c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_USBA		0x00000001
3147c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_USBAI		0x00000002
3157c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HUBDI		0x00000004
3167c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HCDI		0x00000008
3177c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HCDI_DUMPING	0x00000010
3187c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HUBDI_DUMPING	0x00000020
3197c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_REGISTER		0x00000040
3207c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_DEVDB		0x00000080
321ff0e937bSRaymond Chen #define	DPRINT_MASK_WHCDI		0x00000100
3227c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ALL 		0xFFFFFFFF
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate typedef struct usba_log_handle_impl {
3257c478bd9Sstevel@tonic-gate 	dev_info_t	*lh_dip;
3267c478bd9Sstevel@tonic-gate 	char		*lh_name;
3277c478bd9Sstevel@tonic-gate 	uint_t		*lh_errlevel;
3287c478bd9Sstevel@tonic-gate 	uint_t		*lh_mask;
3297c478bd9Sstevel@tonic-gate 	uint_t		*lh_instance_filter;
3307c478bd9Sstevel@tonic-gate 	uint_t		lh_flags;
3317c478bd9Sstevel@tonic-gate } usba_log_handle_impl_t;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("USBA managed data", usba_log_handle_impl))
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  * Miscellaneous definitions.
3377c478bd9Sstevel@tonic-gate  */
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate /* possible strlen of a USB driver's name */
3407c478bd9Sstevel@tonic-gate #define	USBA_DRVNAME_LEN	40
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate /* strings passed to usb_dprintfN() are this long */
3437c478bd9Sstevel@tonic-gate #define	USBA_PRINT_BUF_LEN	256
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate /*
3467c478bd9Sstevel@tonic-gate  * usba_set_node_name() sets a device info node name
3477c478bd9Sstevel@tonic-gate  * according to class, subclass, and protocol.
3487c478bd9Sstevel@tonic-gate  * a subclass == -1 or protocol == -1 is considered a "don't care".
3497c478bd9Sstevel@tonic-gate  */
3507c478bd9Sstevel@tonic-gate #define	DONTCARE		((int16_t)-1)
3517c478bd9Sstevel@tonic-gate #define	FLAG_INTERFACE_NODE	0
3527c478bd9Sstevel@tonic-gate #define	FLAG_DEVICE_NODE	1
3537c478bd9Sstevel@tonic-gate #define	FLAG_COMBINED_NODE	2
354d73ae94eSgc #define	FLAG_INTERFACE_ASSOCIATION_NODE		3
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate typedef struct node_name_entry {
3577c478bd9Sstevel@tonic-gate 	int16_t class;
3587c478bd9Sstevel@tonic-gate 	int16_t subclass;
3597c478bd9Sstevel@tonic-gate 	int16_t protocol;
3607c478bd9Sstevel@tonic-gate 	char	*name;
3617c478bd9Sstevel@tonic-gate } node_name_entry_t;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate  * USB enumeration statistics support
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate /* Flags telling which stats usba_update_hotplug_stats should update */
3697c478bd9Sstevel@tonic-gate #define	USBA_TOTAL_HOTPLUG_SUCCESS	0x01
3707c478bd9Sstevel@tonic-gate #define	USBA_HOTPLUG_SUCCESS		0x02
3717c478bd9Sstevel@tonic-gate #define	USBA_TOTAL_HOTPLUG_FAILURE	0x04
3727c478bd9Sstevel@tonic-gate #define	USBA_HOTPLUG_FAILURE		0x08
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * Increment enumeration stats indicated by the flags
3767c478bd9Sstevel@tonic-gate  */
3777c478bd9Sstevel@tonic-gate void	usba_update_hotplug_stats(dev_info_t *, usb_flags_t);
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate /* Retrieve the current enumeration hotplug statistics */
3807c478bd9Sstevel@tonic-gate void	usba_get_hotplug_stats(dev_info_t *,
3817c478bd9Sstevel@tonic-gate 		ulong_t	*, ulong_t *, ulong_t *,
3827c478bd9Sstevel@tonic-gate 		ulong_t	*, uchar_t *);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /* Reset the resetable hotplug stats */
3857c478bd9Sstevel@tonic-gate void	usba_reset_hotplug_stats(dev_info_t *);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate extern usb_log_handle_t usbai_log_handle;
3897c478bd9Sstevel@tonic-gate extern	kmutex_t usbai_mutex;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate void	usba_req_normal_cb(usba_req_wrapper_t *);
3927c478bd9Sstevel@tonic-gate void	usba_req_exc_cb(usba_req_wrapper_t *, usb_cr_t, usb_cb_flags_t);
3937c478bd9Sstevel@tonic-gate void	usba_do_req_exc_cb(usba_req_wrapper_t *, usb_cr_t,
3947c478bd9Sstevel@tonic-gate 						usb_cb_flags_t);
3957c478bd9Sstevel@tonic-gate void	usba_req_set_cb_flags(usba_req_wrapper_t *, usb_cb_flags_t);
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate /*
3987c478bd9Sstevel@tonic-gate  * Creating/Destroying children (root hub, and hub children)
3997c478bd9Sstevel@tonic-gate  */
4007c478bd9Sstevel@tonic-gate int	usba_create_child_devi(dev_info_t *, char *, usba_hcdi_ops_t *,
4017c478bd9Sstevel@tonic-gate 		dev_info_t *, usb_port_status_t,
4027c478bd9Sstevel@tonic-gate 		usba_device_t *, dev_info_t **);
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate int	usba_destroy_child_devi(dev_info_t *, uint_t);
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate /* utility function to map rval to a meaningful cr */
4077c478bd9Sstevel@tonic-gate usb_cr_t usba_rval2cr(int);
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate /* various conversion functions */
4107c478bd9Sstevel@tonic-gate usb_pipe_handle_t	usba_get_dflt_pipe_handle(dev_info_t *);
4117c478bd9Sstevel@tonic-gate dev_info_t		*usba_get_dip(usb_pipe_handle_t);
4127c478bd9Sstevel@tonic-gate usb_pipe_handle_t	usba_usbdev_to_dflt_pipe_handle(usba_device_t *);
4137c478bd9Sstevel@tonic-gate usb_pipe_handle_t	usba_get_pipe_handle(usba_pipe_handle_data_t *);
4147c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *usba_get_ph_data(usb_pipe_handle_t);
4157c478bd9Sstevel@tonic-gate usb_pipe_state_t	usba_get_ph_state(usba_pipe_handle_data_t *);
4167c478bd9Sstevel@tonic-gate int			usba_get_ph_ref_count(usba_pipe_handle_data_t *);
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /* increment and decrement ref_count */
4197c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t *usba_hold_ph_data(usb_pipe_handle_t);
4207c478bd9Sstevel@tonic-gate void			usba_release_ph_data(usba_ph_impl_t *);
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate /* close all pipe and mark them persistent */
4237c478bd9Sstevel@tonic-gate void			usba_persistent_pipe_close(usba_device_t *);
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate /* reopen pipes that are marked persistent */
4267c478bd9Sstevel@tonic-gate int			usba_persistent_pipe_open(usba_device_t *);
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate /* check for leaks in hubd and usb_mid */
4297c478bd9Sstevel@tonic-gate void	usba_check_for_leaks(usba_device_t *);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate /* free request wrappers */
4327c478bd9Sstevel@tonic-gate void	usba_req_wrapper_free(usba_req_wrapper_t *);
4337c478bd9Sstevel@tonic-gate 
434a7df97baSStrony Zhang - Solaris China Team /* usb device capture for the specific client driver */
435a7df97baSStrony Zhang - Solaris China Team typedef struct usb_dev_cap {
436a7df97baSStrony Zhang - Solaris China Team 	dev_info_t			*dip;
437a7df97baSStrony Zhang - Solaris China Team 	usb_dev_driver_callback_t	usba_dev_driver_cb;
438a7df97baSStrony Zhang - Solaris China Team } usb_dev_cap_t;
439a7df97baSStrony Zhang - Solaris China Team 
440a7df97baSStrony Zhang - Solaris China Team usb_dev_cap_t usb_cap;
441a7df97baSStrony Zhang - Solaris China Team _NOTE(SCHEME_PROTECTS_DATA("unique device capture data", usb_cap))
442a7df97baSStrony Zhang - Solaris China Team 
4437c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate #endif
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate #endif /* _SYS_USB_USBA_USBA_IMPL_H */
448