xref: /titanic_41/usr/src/uts/common/sys/usb/hubd/hubdvar.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_USB_HUBDVAR_H
28 #define	_SYS_USB_HUBDVAR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/sunndi.h>
37 #include <sys/ndi_impldefs.h>
38 #include <sys/usb/usba/usba_types.h>
39 #include <sys/callb.h>
40 
41 /*
42  * HUB USB device state management :
43  *
44  *                          CHILD PWRLVL---1>--------+
45  *                               ^                   |
46  *                               8                   |
47  *                               |                   |
48  *                               9                   |
49  *                               v                   |
50  *	PWRED_DWN---<3----4>--ONLINE---<2-----1>-DISCONNECTED
51  *          |                  |  ^                |  |
52  *          |                  |  10               |  |
53  *          |                  |  |                |  |
54  *          |                  |  RECOVER-<2-------+  |
55  *          |                  |  ^                   |
56  *          |                  5  6                   |
57  *          |                  |  |                   |
58  *          |                  v  |                   |
59  *          +----5>----------SUSPENDED----<5----7>----+
60  *
61  *	1 = Device Unplug
62  *	2 = Original Device reconnected and after hub driver restores its own
63  *	    device state.
64  *	3 = Device idles for time T & transitions to low power state
65  *	4 = Remote wakeup by device OR Application kicking off IO to device
66  *	5 = Notification to save state prior to DDI_SUSPEND
67  *	6 = Notification to restore state after DDI_RESUME with correct device
68  *          and after hub driver restores its own device state.
69  *	7 = Notification to restore state after DDI_RESUME with device
70  *	    disconnected or a wrong device
71  *	8 = Hub detect child doing remote wakeup and request the PM
72  *	    framework to bring it to full power
73  *      9 = PM framework has compeleted call power entry point of the child
74  *	    and bus ctls of hub
75  *     10 = Restoring states of its children i.e. set addrs & config.
76  *
77  */
78 
79 #define	HUBD_INITIAL_SOFT_SPACE	4
80 
81 typedef struct hub_power_struct {
82 	void		*hubp_hubd;	/* points back to hubd_t */
83 
84 	uint8_t		hubp_wakeup_enabled;	/* remote wakeup enabled? */
85 
86 	/* this is the bit mask of the power states that device has */
87 	uint8_t		hubp_pwr_states;
88 
89 	int		hubp_busy_pm;	/* device busy accounting */
90 
91 	/* wakeup and power transition capabilities of an interface */
92 	uint8_t		hubp_pm_capabilities;
93 
94 	uint8_t		hubp_current_power;	/* current power level */
95 
96 	time_t		hubp_time_at_full_power;	/* timestamp 0->3 */
97 
98 	uint8_t		hubp_min_pm_threshold;		/* in seconds */
99 
100 	/* power state of all children are tracked here */
101 	uint8_t		*hubp_child_pwrstate;
102 
103 	/* pm-components properties are stored here */
104 	char		*hubp_pmcomp[5];
105 
106 	usba_cfg_pwr_descr_t	hubp_confpwr_descr; /* config pwr descr */
107 } hub_power_t;
108 
109 /* warlock directives, stable data */
110 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_hubd))
111 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_wakeup_enabled))
112 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pwr_states))
113 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_time_at_full_power))
114 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_min_pm_threshold))
115 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pm_capabilities))
116 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_pmcomp))
117 _NOTE(DATA_READABLE_WITHOUT_LOCK(hub_power_t::hubp_confpwr_descr))
118 
119 
120 #define	HUBD_APID_NAMELEN	32		/* max len in cfgadm display */
121 
122 /*
123  * hubd cpr data structure used for callback before kernel threads are
124  * suspended
125  */
126 typedef struct hubd_cpr {
127 	callb_cpr_t		cpr;		/* for cpr related info */
128 	struct hubd		*statep;	/* ohci soft state struct */
129 	kmutex_t		lockp;
130 } hubd_cpr_t;
131 
132 _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd_cpr_t::cpr))
133 _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd_cpr_t::statep))
134 
135 
136 /*
137  * soft	state information for this hubd
138  */
139 typedef struct hubd {
140 	int			h_instance;
141 	uint_t			h_init_state;
142 	uint_t			h_dev_state;
143 	int8_t			h_bus_ctls;
144 	int8_t			h_bus_pwr;
145 	hub_power_t		*h_hubpm; /* pointer to power struct */
146 	dev_info_t		*h_dip;
147 
148 	/*
149 	 * mutex to protect softstate and hw regs
150 	 */
151 	kmutex_t		h_mutex;
152 
153 	/*
154 	 * save the usba_device pointer
155 	 */
156 	usba_device_t		*h_usba_device;
157 
158 	int			h_softstate;
159 
160 	/*
161 	 * default pipe handle
162 	 */
163 	usb_pipe_handle_t	h_default_pipe;
164 
165 	/*
166 	 * pipe handle for ep1
167 	 */
168 	usb_pipe_handle_t	h_ep1_ph;
169 	usb_ep_descr_t		h_ep1_descr;
170 	usb_pipe_policy_t	h_pipe_policy;
171 	uint_t			h_intr_pipe_state;
172 
173 	/*
174 	 * root hub descriptor
175 	 */
176 	struct usb_hub_descr	h_hub_descr;
177 
178 	/*
179 	 * hotplug handling
180 	 */
181 	uint_t			h_hotplug_thread;
182 
183 	/*
184 	 * h_children_dips is a  array for holding
185 	 * each child dip indexed by port
186 	 * h_usba_devices is the corresponding usba_device
187 	 */
188 	dev_info_t		**h_children_dips;
189 	size_t			h_cd_list_length;
190 	usba_device_t		**h_usba_devices;
191 
192 	/* change reported by hub, limited to 31 ports */
193 	usb_port_mask_t		h_port_change;
194 
195 	/* waiting for reset completion callback */
196 	usb_port_mask_t		h_port_reset_wait;
197 
198 	/* track transitions of child on each port */
199 	uint16_t		h_port_state[MAX_PORTS + 1];
200 
201 	/* track event registration of children */
202 	uint8_t			h_child_events[MAX_PORTS + 1];
203 
204 	kcondvar_t		h_cv_reset_port;
205 	uint_t			h_intr_completion_reason;
206 	usb_log_handle_t	h_log_handle;	/* for logging msgs */
207 
208 	ndi_event_hdl_t		h_ndi_event_hdl;
209 	hubd_cpr_t		*h_cpr_cb;
210 
211 	/*
212 	 * Hotplug event statistics since hub was attached
213 	 */
214 	ulong_t			h_total_hotplug_success;
215 	ulong_t			h_total_hotplug_failure;
216 
217 	/* for minor node */
218 	char			*h_ancestry_str;
219 
220 	/* registration data */
221 	usb_client_dev_data_t	*h_dev_data;
222 
223 	/* for deathrow implementation */
224 	boolean_t		h_cleanup_enabled;
225 	boolean_t		h_cleanup_needed;
226 	boolean_t		h_cleanup_active;
227 } hubd_t;
228 
229 _NOTE(MUTEX_PROTECTS_DATA(hubd::h_mutex, hubd))
230 _NOTE(MUTEX_PROTECTS_DATA(hubd::h_mutex, hub_power_t))
231 _NOTE(DATA_READABLE_WITHOUT_LOCK(hubd::h_default_pipe
232 		hubd::h_usba_device
233 		hubd::h_dev_data
234 		hubd::h_ndi_event_hdl
235 		hubd::h_cpr_cb
236 		hubd::h_log_handle
237 		hubd::h_ep1_ph
238 		hubd::h_instance
239 		hubd::h_hubpm
240 		hubd::h_dip
241 ))
242 
243 _NOTE(SCHEME_PROTECTS_DATA("stable data", usb_ep_descr))
244 
245 #define	HUBD_UNIT(dev)		(getminor((dev)))
246 #define	HUBD_MUTEX(hubd)	(&((hubd)->h_mutex))
247 #define	HUBD_SS_ISOPEN		0x0001
248 #define	HUBD_ACK_ALL_CHANGES	PORT_CHANGE_MASK
249 
250 /* init state */
251 #define	HUBD_LOCKS_DONE		0x0001
252 #define	HUBD_HUBDI_REGISTERED	0x0002
253 #define	HUBD_MINOR_NODE_CREATED 0x0004
254 #define	HUBD_EVENTS_REGISTERED	0x0020
255 
256 /*
257  * port flags : These are essentially extensions of  Port Status Field Bits
258  * as in USB 2.0 spec Table 11-21 and #defined in hubd.h file. We make use
259  * of the unused bits (5-7,13-15) here to track states of the hub's child.
260  */
261 #define	HUBD_CHILD_ATTACHING		0x0020
262 #define	HUBD_CHILD_DETACHING		0x0040
263 #define	HUBD_CHILD_PWRLVL_CHNG		0x0080
264 #define	HUBD_CHILD_RAISE_POWER		0x2000
265 #define	HUBD_CHILD_ZAP			0x4000
266 
267 /* Tracking events registered by children */
268 #define	HUBD_CHILD_EVENT_DISCONNECT	0x01
269 #define	HUBD_CHILD_EVENT_PRESUSPEND	0x02
270 
271 /* This dev state is used exclusively by hub to change port suspend/resume */
272 #define	USB_DEV_HUB_CHILD_PWRLVL	0x80
273 #define	USB_DEV_HUB_STATE_RECOVER	0x81
274 
275 /*
276  * hubd interrupt pipe management :
277  *
278  * Following are the states of the interrupt pipe
279  *
280  * IDLE:
281  *	initial state and after closing of the interrupt pipe
282  *
283  * OPENING:
284  *	Set when the pipe is being opened
285  *
286  * ACTIVE:
287  *	Set when the pipe has been opened in hubd_open_intr_pipe. This is
288  *	typically after a hub has got enumerated and initialized.
289  *
290  * CLOSING :
291  *	Set when the pipe is closed by calling hubd_close_intr_pipe(). This is
292  *	typically called on hub disconnect via hubd_cleanup.
293  */
294 #define	HUBD_INTR_PIPE_IDLE		0
295 #define	HUBD_INTR_PIPE_OPENING		1
296 #define	HUBD_INTR_PIPE_ACTIVE		2
297 #define	HUBD_INTR_PIPE_STOPPED		3
298 #define	HUBD_INTR_PIPE_CLOSING		4
299 
300 
301 /* request structure for putting dips on deathrow list */
302 typedef struct hubd_offline_req {
303 	usba_list_entry_t	or_queue; /* DO NOT MOVE! */
304 	hubd_t			*or_hubd;
305 	usb_port_t		or_port;
306 	dev_info_t		*or_dip;
307 	uint_t			or_flag;
308 } hubd_offline_req_t;
309 
310 _NOTE(SCHEME_PROTECTS_DATA("unshared", hubd_offline_req))
311 
312 
313 /*
314  * cfgadm state values
315  */
316 #define	HUBD_CFGADM_NORMAL		0	/* normal state */
317 #define	HUBD_CFGADM_DISCONNECTED	1	/* logically disconnected */
318 #define	HUBD_CFGADM_UNCONFIGURED	2	/* port is unconfigured */
319 #define	HUBD_CFGADM_EMPTY		3	/* port is empty */
320 #define	HUBD_CFGADM_STILL_REFERENCED	4	/* ndi_devi_offline failed */
321 #define	HUBD_CFGADM_CONFIGURED		5	/* port is configured */
322 
323 /*
324  * Debug printing
325  * Masks
326  */
327 #define	DPRINT_MASK_ATTA	0x00000001
328 #define	DPRINT_MASK_CBOPS	0x00000002
329 #define	DPRINT_MASK_CALLBACK	0x00000004
330 #define	DPRINT_MASK_PORT	0x00000008
331 #define	DPRINT_MASK_HUB 	0x00000010
332 #define	DPRINT_MASK_HOTPLUG	0x00000020
333 #define	DPRINT_MASK_EVENTS	0x00000040
334 #define	DPRINT_MASK_PM		0x00000080
335 #define	DPRINT_MASK_ALL 	0xFFFFFFFF
336 
337 
338 /* status length used in getting hub status */
339 #define	GET_STATUS_LENGTH	0x04		/* length of get status req */
340 
341 /* flag for hubd_start_polling */
342 #define	HUBD_ALWAYS_START_POLLING	1
343 
344 /* enumeration timeout */
345 #define	HUBDI_ENUM_TIMEOUT	1	/* 1 second */
346 
347 #ifdef	__cplusplus
348 }
349 #endif
350 
351 #endif	/* _SYS_USB_HUBDVAR_H */
352