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