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
56c7181fcSsl  * Common Development and Distribution License (the "License").
66c7181fcSsl  * 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.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_USB_HUBDVAR_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_HUBDVAR_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
357c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
377c478bd9Sstevel@tonic-gate #include <sys/callb.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * HUB USB device state management :
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  *                          CHILD PWRLVL---1>--------+
437c478bd9Sstevel@tonic-gate  *                               ^                   |
447c478bd9Sstevel@tonic-gate  *                               8                   |
457c478bd9Sstevel@tonic-gate  *                               |                   |
467c478bd9Sstevel@tonic-gate  *                               9                   |
477c478bd9Sstevel@tonic-gate  *                               v                   |
487c478bd9Sstevel@tonic-gate  *	PWRED_DWN---<3----4>--ONLINE---<2-----1>-DISCONNECTED
497c478bd9Sstevel@tonic-gate  *          |                  |  ^                |  |
507c478bd9Sstevel@tonic-gate  *          |                  |  10               |  |
517c478bd9Sstevel@tonic-gate  *          |                  |  |                |  |
527c478bd9Sstevel@tonic-gate  *          |                  |  RECOVER-<2-------+  |
537c478bd9Sstevel@tonic-gate  *          |                  |  ^                   |
547c478bd9Sstevel@tonic-gate  *          |                  5  6                   |
557c478bd9Sstevel@tonic-gate  *          |                  |  |                   |
567c478bd9Sstevel@tonic-gate  *          |                  v  |                   |
577c478bd9Sstevel@tonic-gate  *          +----5>----------SUSPENDED----<5----7>----+
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  *	1 = Device Unplug
607c478bd9Sstevel@tonic-gate  *	2 = Original Device reconnected and after hub driver restores its own
617c478bd9Sstevel@tonic-gate  *	    device state.
627c478bd9Sstevel@tonic-gate  *	3 = Device idles for time T & transitions to low power state
637c478bd9Sstevel@tonic-gate  *	4 = Remote wakeup by device OR Application kicking off IO to device
647c478bd9Sstevel@tonic-gate  *	5 = Notification to save state prior to DDI_SUSPEND
657c478bd9Sstevel@tonic-gate  *	6 = Notification to restore state after DDI_RESUME with correct device
667c478bd9Sstevel@tonic-gate  *          and after hub driver restores its own device state.
677c478bd9Sstevel@tonic-gate  *	7 = Notification to restore state after DDI_RESUME with device
687c478bd9Sstevel@tonic-gate  *	    disconnected or a wrong device
697c478bd9Sstevel@tonic-gate  *	8 = Hub detect child doing remote wakeup and request the PM
707c478bd9Sstevel@tonic-gate  *	    framework to bring it to full power
717c478bd9Sstevel@tonic-gate  *      9 = PM framework has compeleted call power entry point of the child
727c478bd9Sstevel@tonic-gate  *	    and bus ctls of hub
737c478bd9Sstevel@tonic-gate  *     10 = Restoring states of its children i.e. set addrs & config.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #define	HUBD_INITIAL_SOFT_SPACE	4
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef struct hub_power_struct {
807c478bd9Sstevel@tonic-gate 	void		*hubp_hubd;	/* points back to hubd_t */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	uint8_t		hubp_wakeup_enabled;	/* remote wakeup enabled? */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/* this is the bit mask of the power states that device has */
857c478bd9Sstevel@tonic-gate 	uint8_t		hubp_pwr_states;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	int		hubp_busy_pm;	/* device busy accounting */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	/* wakeup and power transition capabilities of an interface */
907c478bd9Sstevel@tonic-gate 	uint8_t		hubp_pm_capabilities;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	uint8_t		hubp_current_power;	/* current power level */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	time_t		hubp_time_at_full_power;	/* timestamp 0->3 */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	uint8_t		hubp_min_pm_threshold;		/* in seconds */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	/* power state of all children are tracked here */
997c478bd9Sstevel@tonic-gate 	uint8_t		*hubp_child_pwrstate;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	/* pm-components properties are stored here */
1027c478bd9Sstevel@tonic-gate 	char		*hubp_pmcomp[5];
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	usba_cfg_pwr_descr_t	hubp_confpwr_descr; /* config pwr descr */
1057c478bd9Sstevel@tonic-gate } hub_power_t;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /* warlock directives, stable data */
1087c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_hubd))
1097c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_wakeup_enabled))
1107c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pwr_states))
1117c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_time_at_full_power))
1127c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_min_pm_threshold))
1137c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pm_capabilities))
1147c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pmcomp))
1157c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_confpwr_descr))
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	HUBD_APID_NAMELEN	32		/* max len in cfgadm display */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * hubd cpr data structure used for callback before kernel threads are
1227c478bd9Sstevel@tonic-gate  * suspended
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate typedef struct hubd_cpr {
1257c478bd9Sstevel@tonic-gate 	callb_cpr_t		cpr;		/* for cpr related info */
1267c478bd9Sstevel@tonic-gate 	struct hubd		*statep;	/* ohci soft state struct */
1277c478bd9Sstevel@tonic-gate 	kmutex_t		lockp;
1287c478bd9Sstevel@tonic-gate } hubd_cpr_t;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd_cpr_t::cpr))
1317c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd_cpr_t::statep))
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * soft	state information for this hubd
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate typedef struct hubd {
1387c478bd9Sstevel@tonic-gate 	int			h_instance;
1397c478bd9Sstevel@tonic-gate 	uint_t			h_init_state;
1407c478bd9Sstevel@tonic-gate 	uint_t			h_dev_state;
1417c478bd9Sstevel@tonic-gate 	int8_t			h_bus_ctls;
1427c478bd9Sstevel@tonic-gate 	int8_t			h_bus_pwr;
1437c478bd9Sstevel@tonic-gate 	hub_power_t		*h_hubpm; /* pointer to power struct */
1447c478bd9Sstevel@tonic-gate 	dev_info_t		*h_dip;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	/*
1477c478bd9Sstevel@tonic-gate 	 * mutex to protect softstate and hw regs
1487c478bd9Sstevel@tonic-gate 	 */
1497c478bd9Sstevel@tonic-gate 	kmutex_t		h_mutex;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * save the usba_device pointer
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	usba_device_t		*h_usba_device;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	int			h_softstate;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	/*
1597c478bd9Sstevel@tonic-gate 	 * default pipe handle
1607c478bd9Sstevel@tonic-gate 	 */
1617c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	h_default_pipe;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	/*
1647c478bd9Sstevel@tonic-gate 	 * pipe handle for ep1
1657c478bd9Sstevel@tonic-gate 	 */
1667c478bd9Sstevel@tonic-gate 	usb_pipe_handle_t	h_ep1_ph;
1677c478bd9Sstevel@tonic-gate 	usb_ep_descr_t		h_ep1_descr;
1687c478bd9Sstevel@tonic-gate 	usb_pipe_policy_t	h_pipe_policy;
1697c478bd9Sstevel@tonic-gate 	uint_t			h_intr_pipe_state;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	/*
1727c478bd9Sstevel@tonic-gate 	 * root hub descriptor
1737c478bd9Sstevel@tonic-gate 	 */
1747c478bd9Sstevel@tonic-gate 	struct usb_hub_descr	h_hub_descr;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/*
1777c478bd9Sstevel@tonic-gate 	 * hotplug handling
1787c478bd9Sstevel@tonic-gate 	 */
1797c478bd9Sstevel@tonic-gate 	uint_t			h_hotplug_thread;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	/*
1827c478bd9Sstevel@tonic-gate 	 * h_children_dips is a  array for holding
1837c478bd9Sstevel@tonic-gate 	 * each child dip indexed by port
1847c478bd9Sstevel@tonic-gate 	 * h_usba_devices is the corresponding usba_device
1857c478bd9Sstevel@tonic-gate 	 */
1867c478bd9Sstevel@tonic-gate 	dev_info_t		**h_children_dips;
1877c478bd9Sstevel@tonic-gate 	size_t			h_cd_list_length;
1887c478bd9Sstevel@tonic-gate 	usba_device_t		**h_usba_devices;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	/* change reported by hub, limited to 31 ports */
1917c478bd9Sstevel@tonic-gate 	usb_port_mask_t		h_port_change;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	/* waiting for reset completion callback */
1947c478bd9Sstevel@tonic-gate 	usb_port_mask_t		h_port_reset_wait;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	/* track transitions of child on each port */
1977c478bd9Sstevel@tonic-gate 	uint16_t		h_port_state[MAX_PORTS + 1];
1987c478bd9Sstevel@tonic-gate 
199ffcd51f3Slg 	/* track reset state of each port */
200ffcd51f3Slg 	boolean_t		h_reset_port[MAX_PORTS + 1];
201ffcd51f3Slg 
2027c478bd9Sstevel@tonic-gate 	/* track event registration of children */
2037c478bd9Sstevel@tonic-gate 	uint8_t			h_child_events[MAX_PORTS + 1];
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	kcondvar_t		h_cv_reset_port;
206ffcd51f3Slg 	kcondvar_t		h_cv_hotplug_dev;
2077c478bd9Sstevel@tonic-gate 	uint_t			h_intr_completion_reason;
2087c478bd9Sstevel@tonic-gate 	usb_log_handle_t	h_log_handle;	/* for logging msgs */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	ndi_event_hdl_t		h_ndi_event_hdl;
2117c478bd9Sstevel@tonic-gate 	hubd_cpr_t		*h_cpr_cb;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	/*
2147c478bd9Sstevel@tonic-gate 	 * Hotplug event statistics since hub was attached
2157c478bd9Sstevel@tonic-gate 	 */
2167c478bd9Sstevel@tonic-gate 	ulong_t			h_total_hotplug_success;
2177c478bd9Sstevel@tonic-gate 	ulong_t			h_total_hotplug_failure;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	/* for minor node */
2207c478bd9Sstevel@tonic-gate 	char			*h_ancestry_str;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	/* registration data */
2237c478bd9Sstevel@tonic-gate 	usb_client_dev_data_t	*h_dev_data;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	/* for deathrow implementation */
2267c478bd9Sstevel@tonic-gate 	boolean_t		h_cleanup_enabled;
2277c478bd9Sstevel@tonic-gate 	boolean_t		h_cleanup_needed;
2287c478bd9Sstevel@tonic-gate 	boolean_t		h_cleanup_active;
22935f36846Ssl 
23035f36846Ssl 	/*
23135f36846Ssl 	 * for power budget support
23235f36846Ssl 	 * h_pwr_limit and h_pwr_left are expressed
23335f36846Ssl 	 * in 2mA units
23435f36846Ssl 	 */
23535f36846Ssl 	boolean_t		h_local_pwr_capable;
23635f36846Ssl 	boolean_t		h_local_pwr_on;
23735f36846Ssl 	uint16_t		h_pwr_limit; /* per port pwr limit */
23835f36846Ssl 	int16_t			h_pwr_left; /* limit on the whole hub */
23935f36846Ssl 
24035f36846Ssl 	/*
24135f36846Ssl 	 * conf file override to power budget property
24235f36846Ssl 	 * if 1, power budget is disabled
24335f36846Ssl 	 */
24435f36846Ssl 	boolean_t		h_ignore_pwr_budget;
245ff0e937bSRaymond Chen 
246ff0e937bSRaymond Chen 	/* for HWA to cleanup child, NULL for normal hubs */
247ff0e937bSRaymond Chen 	int			(*h_cleanup_child)(dev_info_t *);
2487c478bd9Sstevel@tonic-gate } hubd_t;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(hubd::h_mutex, hubd))
2517c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(hubd::h_mutex, hub_power_t))
2527c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd::h_default_pipe
2537c478bd9Sstevel@tonic-gate 		hubd::h_usba_device
2547c478bd9Sstevel@tonic-gate 		hubd::h_dev_data
2557c478bd9Sstevel@tonic-gate 		hubd::h_ndi_event_hdl
2567c478bd9Sstevel@tonic-gate 		hubd::h_cpr_cb
2577c478bd9Sstevel@tonic-gate 		hubd::h_log_handle
2587c478bd9Sstevel@tonic-gate 		hubd::h_ep1_ph
2597c478bd9Sstevel@tonic-gate 		hubd::h_instance
2607c478bd9Sstevel@tonic-gate 		hubd::h_hubpm
2617c478bd9Sstevel@tonic-gate 		hubd::h_dip
26235f36846Ssl 		hubd::h_ignore_pwr_budget
263*489b7c4aSRaymond Chen 		hubd::h_hub_descr
264*489b7c4aSRaymond Chen 		hubd::h_cleanup_child
2657c478bd9Sstevel@tonic-gate ))
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_ep_descr))
2687c478bd9Sstevel@tonic-gate 
2696c7181fcSsl /*
2706c7181fcSsl  * hubd hotplug thread argument data structure
2716c7181fcSsl  */
2726c7181fcSsl typedef struct hubd_hotplug_arg {
2736c7181fcSsl 	hubd_t		*hubd;
2746c7181fcSsl 
2756c7181fcSsl 	/*
2766c7181fcSsl 	 * flag to indicate if a hotplug thread is started
2776c7181fcSsl 	 * during hubd attach time, if true, it means the
2786c7181fcSsl 	 * connected devices need to be enumerated regardless
2796c7181fcSsl 	 * of the connect status change bit
2806c7181fcSsl 	 */
2816c7181fcSsl 	boolean_t	hotplug_during_attach;
2826c7181fcSsl } hubd_hotplug_arg_t;
2836c7181fcSsl 
284ffcd51f3Slg /*
285ffcd51f3Slg  * hubd reset thread argument data structure
286ffcd51f3Slg  */
287ffcd51f3Slg typedef struct hubd_reset_arg {
288ffcd51f3Slg 	hubd_t		*hubd;
289ffcd51f3Slg 	/* The port needs to be reset */
290ffcd51f3Slg 	uint16_t	reset_port;
291ffcd51f3Slg } hubd_reset_arg_t;
292ffcd51f3Slg 
2936c7181fcSsl _NOTE(SCHEME_PROTECTS_DATA("unshared", hubd_hotplug_arg))
294ffcd51f3Slg _NOTE(SCHEME_PROTECTS_DATA("unshared", hubd_reset_arg))
2956c7181fcSsl 
2967c478bd9Sstevel@tonic-gate #define	HUBD_UNIT(dev)		(getminor((dev)))
2977c478bd9Sstevel@tonic-gate #define	HUBD_MUTEX(hubd)	(&((hubd)->h_mutex))
2987c478bd9Sstevel@tonic-gate #define	HUBD_SS_ISOPEN		0x0001
2997c478bd9Sstevel@tonic-gate #define	HUBD_ACK_ALL_CHANGES	PORT_CHANGE_MASK
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate /* init state */
3027c478bd9Sstevel@tonic-gate #define	HUBD_LOCKS_DONE		0x0001
3037c478bd9Sstevel@tonic-gate #define	HUBD_HUBDI_REGISTERED	0x0002
3047c478bd9Sstevel@tonic-gate #define	HUBD_MINOR_NODE_CREATED 0x0004
30535f36846Ssl #define	HUBD_CHILDREN_CREATED	0x0008
3067c478bd9Sstevel@tonic-gate #define	HUBD_EVENTS_REGISTERED	0x0020
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * port flags : These are essentially extensions of  Port Status Field Bits
3107c478bd9Sstevel@tonic-gate  * as in USB 2.0 spec Table 11-21 and #defined in hubd.h file. We make use
3117c478bd9Sstevel@tonic-gate  * of the unused bits (5-7,13-15) here to track states of the hub's child.
3127c478bd9Sstevel@tonic-gate  */
3137c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_ATTACHING		0x0020
3147c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_DETACHING		0x0040
3157c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_PWRLVL_CHNG		0x0080
3167c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_RAISE_POWER		0x2000
3177c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_ZAP			0x4000
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate /* Tracking events registered by children */
3207c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_EVENT_DISCONNECT	0x01
3217c478bd9Sstevel@tonic-gate #define	HUBD_CHILD_EVENT_PRESUSPEND	0x02
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate /* This dev state is used exclusively by hub to change port suspend/resume */
3247c478bd9Sstevel@tonic-gate #define	USB_DEV_HUB_CHILD_PWRLVL	0x80
3257c478bd9Sstevel@tonic-gate #define	USB_DEV_HUB_STATE_RECOVER	0x81
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * hubd interrupt pipe management :
3297c478bd9Sstevel@tonic-gate  *
3307c478bd9Sstevel@tonic-gate  * Following are the states of the interrupt pipe
3317c478bd9Sstevel@tonic-gate  *
3327c478bd9Sstevel@tonic-gate  * IDLE:
3337c478bd9Sstevel@tonic-gate  *	initial state and after closing of the interrupt pipe
3347c478bd9Sstevel@tonic-gate  *
3357c478bd9Sstevel@tonic-gate  * OPENING:
3367c478bd9Sstevel@tonic-gate  *	Set when the pipe is being opened
3377c478bd9Sstevel@tonic-gate  *
3387c478bd9Sstevel@tonic-gate  * ACTIVE:
3397c478bd9Sstevel@tonic-gate  *	Set when the pipe has been opened in hubd_open_intr_pipe. This is
3407c478bd9Sstevel@tonic-gate  *	typically after a hub has got enumerated and initialized.
3417c478bd9Sstevel@tonic-gate  *
3427c478bd9Sstevel@tonic-gate  * CLOSING :
3437c478bd9Sstevel@tonic-gate  *	Set when the pipe is closed by calling hubd_close_intr_pipe(). This is
3447c478bd9Sstevel@tonic-gate  *	typically called on hub disconnect via hubd_cleanup.
3457c478bd9Sstevel@tonic-gate  */
3467c478bd9Sstevel@tonic-gate #define	HUBD_INTR_PIPE_IDLE		0
3477c478bd9Sstevel@tonic-gate #define	HUBD_INTR_PIPE_OPENING		1
3487c478bd9Sstevel@tonic-gate #define	HUBD_INTR_PIPE_ACTIVE		2
3497c478bd9Sstevel@tonic-gate #define	HUBD_INTR_PIPE_STOPPED		3
3507c478bd9Sstevel@tonic-gate #define	HUBD_INTR_PIPE_CLOSING		4
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate /* request structure for putting dips on deathrow list */
3547c478bd9Sstevel@tonic-gate typedef struct hubd_offline_req {
3557c478bd9Sstevel@tonic-gate 	usba_list_entry_t	or_queue; /* DO NOT MOVE! */
3567c478bd9Sstevel@tonic-gate 	hubd_t			*or_hubd;
3577c478bd9Sstevel@tonic-gate 	usb_port_t		or_port;
3587c478bd9Sstevel@tonic-gate 	dev_info_t		*or_dip;
3597c478bd9Sstevel@tonic-gate 	uint_t			or_flag;
3607c478bd9Sstevel@tonic-gate } hubd_offline_req_t;
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared", hubd_offline_req))
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate  * cfgadm state values
3677c478bd9Sstevel@tonic-gate  */
3687c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_NORMAL		0	/* normal state */
3697c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_DISCONNECTED	1	/* logically disconnected */
3707c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_UNCONFIGURED	2	/* port is unconfigured */
3717c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_EMPTY		3	/* port is empty */
3727c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_STILL_REFERENCED	4	/* ndi_devi_offline failed */
3737c478bd9Sstevel@tonic-gate #define	HUBD_CFGADM_CONFIGURED		5	/* port is configured */
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate /*
3767c478bd9Sstevel@tonic-gate  * Debug printing
3777c478bd9Sstevel@tonic-gate  * Masks
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ATTA	0x00000001
3807c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_CBOPS	0x00000002
3817c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_CALLBACK	0x00000004
3827c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_PORT	0x00000008
3837c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HUB 	0x00000010
3847c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_HOTPLUG	0x00000020
3857c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_EVENTS	0x00000040
3867c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_PM		0x00000080
3877c478bd9Sstevel@tonic-gate #define	DPRINT_MASK_ALL 	0xFFFFFFFF
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /* status length used in getting hub status */
3917c478bd9Sstevel@tonic-gate #define	GET_STATUS_LENGTH	0x04		/* length of get status req */
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /* flag for hubd_start_polling */
3947c478bd9Sstevel@tonic-gate #define	HUBD_ALWAYS_START_POLLING	1
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate /* enumeration timeout */
3977c478bd9Sstevel@tonic-gate #define	HUBDI_ENUM_TIMEOUT	1	/* 1 second */
3987c478bd9Sstevel@tonic-gate 
39935f36846Ssl /* power budget unit in mA */
40035f36846Ssl #define	USB_PWR_UNIT_LOAD	100
40135f36846Ssl 
40235f36846Ssl /* power values in 100mA units */
40335f36846Ssl #define	USB_HIGH_PWR_VALUE	5
40435f36846Ssl #define	USB_LOW_PWR_VALUE	1
40535f36846Ssl 
40635f36846Ssl /*
40735f36846Ssl  * According to section 9.6.3 of USB 2.0 spec,
40835f36846Ssl  * bMaxPower in the device configuration descriptor
40935f36846Ssl  * is expressed in 2mA units
41035f36846Ssl  */
41135f36846Ssl #define	USB_CFG_DESCR_PWR_UNIT	2
41235f36846Ssl 
413ff0e937bSRaymond Chen /* variables shared with wire adapter class drivers */
414ff0e937bSRaymond Chen extern uint_t hubd_errlevel;
415ff0e937bSRaymond Chen extern uint_t hubd_errmask;
416ff0e937bSRaymond Chen extern uint_t hubd_instance_debug;
417ff0e937bSRaymond Chen 
418ff0e937bSRaymond Chen /* common interfaces for hub and wire adapter class devices */
419ff0e937bSRaymond Chen hubd_t	*hubd_get_soft_state(dev_info_t *);
420ff0e937bSRaymond Chen void	hubd_get_ancestry_str(hubd_t *);
421ff0e937bSRaymond Chen int	hubd_get_all_device_config_cloud(hubd_t *, dev_info_t *,
422ff0e937bSRaymond Chen 	usba_device_t *);
423ff0e937bSRaymond Chen int	hubd_select_device_configuration(hubd_t *, usb_port_t,
424ff0e937bSRaymond Chen 	dev_info_t *, usba_device_t *);
425ff0e937bSRaymond Chen dev_info_t *hubd_ready_device(hubd_t *, dev_info_t *, usba_device_t *,
426ff0e937bSRaymond Chen 	uint_t);
427ff0e937bSRaymond Chen void	hubd_schedule_cleanup(dev_info_t *);
428ff0e937bSRaymond Chen 
4297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate #endif
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_HUBDVAR_H */
434