Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/usb/clients/usbskel/usbskel.c
+++ new/usr/src/uts/common/io/usb/clients/usbskel/usbskel.c
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.
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 25
26 26
27 27 /*
28 28 * Sample skeleton USB driver.
29 29 * This driver provides a framework for developing USB client drivers.
30 30 *
31 31 * As a simplistic example, usbskel implements a data transfer by reading
32 32 * raw configuration data, which every USB device has. It is expected that
33 33 * the caller will issue an initial 4-byte read to get the total length of the
34 34 * first configuration, and follow up with a second read, passing the total
35 35 * length to read the entire configuration cloud.
36 36 *
37 37 * The device has four states (refer to usbai.h):
38 38 * USB_DEV_ONLINE: In action or ready for action.
39 39 * USB_DEV_DISCONNECTED: Hotplug removed, or device not present/correct on
40 40 * resume (CPR).
41 41 * USB_DEV_SUSPENDED: Device has been suspended along with the system.
42 42 * USB_DEV_PWRED_DOWN: Device has been powered down. (Note that this
43 43 * driver supports only two power states, powered down and
44 44 * full power.)
45 45 *
46 46 * In order to avoid race conditions between driver entry points,
47 47 * access to the device is serialized. Race conditions are an issue in
48 48 * particular between disconnect event callbacks, detach, power, open
49 49 * and data transfer callbacks. The functions usbskel_serialize/release_access
50 50 * are implemented for this purpose.
51 51 *
52 52 * Mutexes should never be held when making calls into USBA or when
53 53 * sleeping.
54 54 *
55 55 * pm_busy_component and pm_idle_component mark the device as busy or idle to
56 56 * the system. These functions are paired, and are called only from code
57 57 * bracketed by usbskel_serialize_access and usbskel_release_access.
58 58 *
59 59 * NOTE: PM and CPR will be enabled at a later release of S10.
60 60 */
61 61
62 62 #if defined(lint) && !defined(DEBUG)
63 63 #define DEBUG
64 64 #endif
65 65
66 66 #define USBDRV_MAJOR_VER 2
67 67 #define USBDRV_MINOR_VER 0
68 68
69 69 /* Uncomment to enable Power Management, when the OS PM framework is ready. */
70 70 /*
71 71 * #ifndef USBSKEL_PM
72 72 * #define USBSKEL_PM
73 73 * #endif
74 74 */
75 75
76 76 /*
77 77 * Uncomment to enable Check Point Resume (system suspend and resume) when the
78 78 * OS CPR framework is ready.
79 79 */
80 80 /*
81 81 * #ifndef USBSKEL_CPR
82 82 * #define USBSKEL_CPR
83 83 * #endif
84 84 */
85 85
86 86 #include <sys/usb/usba.h>
87 87 #include <sys/strsun.h>
88 88 #include <sys/usb/clients/usbskel/usbskel.h>
89 89
90 90 int usbskel_errlevel = USBSKEL_LOG_LOG;
91 91 static char *name = "usbskl"; /* Driver name, used all over. */
92 92
93 93 /*
94 94 * Boolean set to whether or not to dump the device's descriptor tree.
95 95 * Can be changed with the usblog_dumptree property in a usbskel.conf file.
96 96 */
97 97 static boolean_t usbskel_dumptree;
98 98
99 99 /*
100 100 * Function Prototypes
101 101 */
102 102 static int usbskel_attach(dev_info_t *, ddi_attach_cmd_t);
103 103 static int usbskel_detach(dev_info_t *, ddi_detach_cmd_t);
104 104 static int usbskel_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
105 105 static int usbskel_cleanup(dev_info_t *, usbskel_state_t *);
106 106 static int usbskel_open(dev_t *, int, int, cred_t *);
107 107 static int usbskel_close(dev_t, int, int, cred_t *);
108 108 static int usbskel_read(dev_t, struct uio *uip_p, cred_t *);
109 109 static int usbskel_strategy(struct buf *);
110 110 static void usbskel_minphys(struct buf *);
111 111 static void usbskel_normal_callback(usb_pipe_handle_t, usb_ctrl_req_t *);
112 112 static void usbskel_exception_callback(usb_pipe_handle_t, usb_ctrl_req_t *);
113 113 static int usbskel_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
114 114 static int usbskel_disconnect_callback(dev_info_t *);
115 115 static int usbskel_reconnect_callback(dev_info_t *);
116 116 static void usbskel_restore_device_state(dev_info_t *, usbskel_state_t *);
117 117 static int usbskel_cpr_suspend(dev_info_t *);
118 118 static void usbskel_cpr_resume(dev_info_t *);
119 119 static int usbskel_test_and_adjust_device_state(usbskel_state_t *);
120 120 static int usbskel_open_pipes(usbskel_state_t *);
121 121 static void usbskel_close_pipes(usbskel_state_t *);
122 122 static int usbskel_pm_busy_component(usbskel_state_t *);
123 123 static void usbskel_pm_idle_component(usbskel_state_t *);
124 124 static int usbskel_power(dev_info_t *, int, int);
125 125 #ifdef USBSKEL_PM
126 126 static int usbskel_init_power_mgmt(usbskel_state_t *);
127 127 static void usbskel_destroy_power_mgmt(usbskel_state_t *);
128 128 #endif
129 129 static int usbskel_serialize_access(usbskel_state_t *, boolean_t);
130 130 static void usbskel_release_access(usbskel_state_t *);
131 131 static int usbskel_check_same_device(usbskel_state_t *);
132 132
133 133 /*PRINTFLIKE3*/
134 134 static void usbskel_log(usbskel_state_t *, int, char *, ...);
135 135
136 136 /* _NOTE is an advice for locklint. Locklint checks lock use for deadlocks. */
137 137 _NOTE(SCHEME_PROTECTS_DATA("unique per call", usb_ctrl_req))
138 138 _NOTE(SCHEME_PROTECTS_DATA("unique per call", buf))
139 139
140 140 /* module loading stuff */
141 141 struct cb_ops usbskel_cb_ops = {
142 142 usbskel_open, /* open */
143 143 usbskel_close, /* close */
144 144 usbskel_strategy, /* strategy */
145 145 nulldev, /* print */
146 146 nulldev, /* dump */
147 147 usbskel_read, /* read */
148 148 nodev, /* write */
149 149 usbskel_ioctl, /* ioctl */
150 150 nulldev, /* devmap */
151 151 nodev, /* mmap */
152 152 nodev, /* segmap */
153 153 nochpoll, /* poll */
154 154 ddi_prop_op, /* cb_prop_op */
155 155 NULL, /* streamtab */
156 156 D_MP
157 157 };
158 158
159 159 static struct dev_ops usbskel_ops = {
160 160 DEVO_REV, /* devo_rev, */
161 161 0, /* refcnt */
162 162 usbskel_info, /* info */
163 163 nulldev, /* identify */
164 164 nulldev, /* probe */
165 165 usbskel_attach, /* attach */
166 166 usbskel_detach, /* detach */
167 167 nodev, /* reset */
168 168 &usbskel_cb_ops, /* driver operations */
169 169 NULL, /* bus operations */
170 170 usbskel_power, /* power */
171 171 ddi_quiesce_not_needed, /* devo_quiesce */
↓ open down ↓ |
171 lines elided |
↑ open up ↑ |
172 172 };
173 173
174 174 static struct modldrv usbskel_modldrv = {
175 175 &mod_driverops,
176 176 "USB skeleton driver",
177 177 &usbskel_ops
178 178 };
179 179
180 180 static struct modlinkage modlinkage = {
181 181 MODREV_1,
182 - &usbskel_modldrv,
183 - NULL
182 + { &usbskel_modldrv, NULL }
184 183 };
185 184
186 185 /* local variables */
187 186
188 187 /* Soft state structures */
189 188 #define USBSKEL_INITIAL_SOFT_SPACE 1
190 189 static void *usbskel_statep;
191 190
192 191
193 192 /*
194 193 * Module-wide initialization routine.
195 194 */
196 195 int
197 196 _init(void)
198 197 {
199 198 int rval;
200 199
201 200 usbskel_log(NULL, USBSKEL_LOG_LOG, "usbskel _init");
202 201
203 202 if ((rval = ddi_soft_state_init(&usbskel_statep,
204 203 sizeof (usbskel_state_t), USBSKEL_INITIAL_SOFT_SPACE)) != 0) {
205 204
206 205 return (rval);
207 206 }
208 207
209 208 if ((rval = mod_install(&modlinkage)) != 0) {
210 209 ddi_soft_state_fini(&usbskel_statep);
211 210 }
212 211
213 212 usbskel_log(NULL, USBSKEL_LOG_LOG, "usbskel _init done");
214 213
215 214 return (rval);
216 215 }
217 216
218 217
219 218 /*
220 219 * Module-wide tear-down routine.
221 220 */
222 221 int
223 222 _fini(void)
224 223 {
225 224 int rval;
226 225
227 226 usbskel_log(NULL, USBSKEL_LOG_LOG, "usbskel _fini");
228 227 if ((rval = mod_remove(&modlinkage)) != 0) {
229 228
230 229 return (rval);
231 230 }
232 231
233 232 ddi_soft_state_fini(&usbskel_statep);
234 233 usbskel_log(NULL, USBSKEL_LOG_LOG, "usbskel _fini done");
235 234
236 235 return (rval);
237 236 }
238 237
239 238
240 239 int
241 240 _info(struct modinfo *modinfop)
242 241 {
243 242 return (mod_info(&modlinkage, modinfop));
244 243 }
245 244
246 245
247 246 /*
248 247 * usbskel_info:
249 248 * Get minor number, soft state structure, etc.
250 249 */
251 250 /*ARGSUSED*/
252 251 static int
253 252 usbskel_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
254 253 void *arg, void **result)
255 254 {
256 255 usbskel_state_t *usbskelp;
257 256 int error = DDI_FAILURE;
258 257
259 258 switch (infocmd) {
260 259 case DDI_INFO_DEVT2DEVINFO:
261 260 if ((usbskelp = ddi_get_soft_state(usbskel_statep,
262 261 getminor((dev_t)arg))) != NULL) {
263 262 *result = usbskelp->usbskel_dip;
264 263 if (*result != NULL) {
265 264 error = DDI_SUCCESS;
266 265 }
267 266 } else {
268 267 *result = NULL;
269 268 }
270 269 break;
271 270 case DDI_INFO_DEVT2INSTANCE:
272 271 *result = (void *)(uintptr_t)getminor((dev_t)arg);
273 272 error = DDI_SUCCESS;
274 273 break;
275 274 default:
276 275 break;
277 276 }
278 277
279 278 return (error);
280 279 }
281 280
282 281
283 282 /*
284 283 * usbskel_attach:
285 284 * Attach or resume.
286 285 *
287 286 * For attach, initialize state and device, including:
288 287 * state variables, locks, device node
289 288 * device registration with system
290 289 * power management, hotplugging
291 290 * For resume, restore device and state
292 291 */
293 292 static int
294 293 usbskel_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
295 294 {
296 295 int instance = ddi_get_instance(dip);
297 296 char *devinst;
298 297 int devinstlen;
299 298 usbskel_state_t *usbskelp = NULL;
300 299 usb_reg_parse_lvl_t parse_level;
301 300 usb_ep_data_t *ep_datap;
302 301 int status;
303 302
304 303 switch (cmd) {
305 304 case DDI_ATTACH:
306 305 break;
307 306
308 307 case DDI_RESUME:
309 308 usbskel_cpr_resume(dip);
310 309
311 310 /*
312 311 * Always return success to work around enumeration failures.
313 312 * This works around an issue where devices which are present
314 313 * before a suspend and absent upon resume could cause a system
315 314 * panic on resume.
316 315 */
317 316 return (DDI_SUCCESS);
318 317 default:
319 318 return (DDI_FAILURE);
320 319 }
321 320
322 321 if (ddi_soft_state_zalloc(usbskel_statep, instance) == DDI_SUCCESS) {
323 322 usbskelp = ddi_get_soft_state(usbskel_statep, instance);
324 323 }
325 324 if (usbskelp == NULL) {
326 325
327 326 return (DDI_FAILURE);
328 327 }
329 328
330 329 usbskelp->usbskel_dip = dip;
331 330
332 331 devinst = kmem_zalloc(USB_MAXSTRINGLEN, KM_SLEEP);
333 332 devinstlen = snprintf(devinst, USB_MAXSTRINGLEN, "%s%d: ",
334 333 ddi_driver_name(dip), instance);
335 334
336 335 usbskelp->usbskel_devinst = kmem_zalloc(devinstlen + 1, KM_SLEEP);
337 336 (void) strncpy(usbskelp->usbskel_devinst, devinst, devinstlen);
338 337 kmem_free(devinst, USB_MAXSTRINGLEN);
339 338
340 339 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "Attach: enter for attach");
341 340
342 341 usbskel_dumptree = (ddi_prop_exists(DDI_DEV_T_ANY, dip,
343 342 DDI_PROP_DONTPASS, "usbskel_dumptree") == 1);
344 343
345 344 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "Tree will %sbe dumped",
346 345 ((usbskel_dumptree) ? "" : "not "));
347 346
348 347 parse_level = (usb_reg_parse_lvl_t)ddi_prop_get_int(
349 348 DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
350 349 "usbskel_parse_level", USB_PARSE_LVL_ALL);
351 350
352 351 switch (parse_level) {
353 352 case USB_PARSE_LVL_NONE:
354 353 /* This driver needs a tree. */
355 354 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
356 355 "parse_level requested to NOT DUMP");
357 356 parse_level = USB_PARSE_LVL_IF;
358 357 /*FALLTHROUGH*/
359 358 case USB_PARSE_LVL_IF:
360 359 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
361 360 "parse_level set to dump specific interface");
362 361 break;
363 362 case USB_PARSE_LVL_CFG:
364 363 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
365 364 "parse_level set to dump specific config");
366 365 break;
367 366 case USB_PARSE_LVL_ALL:
368 367 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
369 368 "parse_level set to dump everything");
370 369 break;
371 370 default:
372 371 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
373 372 "attach: parse_level will default to dump everything");
374 373 parse_level = USB_PARSE_LVL_ALL;
375 374 }
376 375
377 376 if ((status = usb_client_attach(dip, USBDRV_VERSION, 0)) !=
378 377 USB_SUCCESS) {
379 378 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
380 379 "attach: usb_client_attach failed, error code:%d", status);
381 380 goto fail;
382 381 }
383 382
384 383 if ((status = usb_get_dev_data(dip, &usbskelp->usbskel_reg, parse_level,
385 384 0)) != USB_SUCCESS) {
386 385 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
387 386 "attach: usb_get_dev_data failed, error code:%d", status);
388 387 goto fail;
389 388 }
390 389
391 390 if (usbskel_dumptree) {
392 391 (void) usb_print_descr_tree(
393 392 usbskelp->usbskel_dip, usbskelp->usbskel_reg);
394 393 }
395 394
396 395 /*
397 396 * Get the descriptor for an intr pipe at alt 0 of current interface.
398 397 * This will be used later to open the pipe.
399 398 */
400 399 if ((ep_datap = usb_lookup_ep_data(dip, usbskelp->usbskel_reg,
401 400 usbskelp->usbskel_reg->dev_curr_if, 0, 0,
402 401 USB_EP_ATTR_INTR, USB_EP_DIR_IN)) == NULL) {
403 402 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
404 403 "attach: Error getting intr endpoint descriptor");
405 404 goto fail;
406 405 }
407 406 usbskelp->usbskel_intr_ep_descr = ep_datap->ep_descr;
408 407
409 408 usb_free_descr_tree(dip, usbskelp->usbskel_reg);
410 409
411 410 mutex_init(&usbskelp->usbskel_mutex, NULL, MUTEX_DRIVER,
412 411 usbskelp->usbskel_reg->dev_iblock_cookie);
413 412
414 413 cv_init(&usbskelp->usbskel_serial_cv, NULL, CV_DRIVER, NULL);
415 414 usbskelp->usbskel_serial_inuse = B_FALSE;
416 415
417 416 usbskelp->usbskel_locks_initialized = B_TRUE;
418 417
419 418 /* create minor node */
420 419 if (ddi_create_minor_node(dip, name, S_IFCHR, instance,
421 420 "usb_skeleton", 0) != DDI_SUCCESS) {
422 421 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
423 422 "attach: Error creating minor node");
424 423 goto fail;
425 424 }
426 425
427 426 /* Put online before PM init as can get power managed afterward. */
428 427 usbskelp->usbskel_dev_state = USB_DEV_ONLINE;
429 428
430 429 #ifdef USBSKEL_PM
431 430 /* initialize power management */
432 431 if (usbskel_init_power_mgmt(usbskelp) != USB_SUCCESS) {
433 432 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
434 433 "attach: Could not initialize power mgmt");
435 434 }
436 435 #endif
437 436
438 437 if (usb_register_hotplug_cbs(dip, usbskel_disconnect_callback,
439 438 usbskel_reconnect_callback) != USB_SUCCESS) {
440 439
441 440 goto fail;
442 441 }
443 442
444 443 /* Report device */
445 444 ddi_report_dev(dip);
446 445
447 446 return (DDI_SUCCESS);
448 447
449 448 fail:
450 449 if (usbskelp) {
451 450 (void) usbskel_cleanup(dip, usbskelp);
452 451 }
453 452
454 453 return (DDI_FAILURE);
455 454 }
456 455
457 456
458 457 /*
459 458 * usbskel_detach:
460 459 * detach or suspend driver instance
461 460 *
462 461 * Note: in detach, only contention threads is from pm and disconnnect.
463 462 */
464 463 static int
465 464 usbskel_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
466 465 {
467 466 int instance = ddi_get_instance(dip);
468 467 usbskel_state_t *usbskelp =
469 468 ddi_get_soft_state(usbskel_statep, instance);
470 469 int rval = DDI_FAILURE;
471 470
472 471 switch (cmd) {
473 472 case DDI_DETACH:
474 473 mutex_enter(&usbskelp->usbskel_mutex);
475 474 ASSERT((usbskelp->usbskel_drv_state & USBSKEL_OPEN) == 0);
476 475 mutex_exit(&usbskelp->usbskel_mutex);
477 476
478 477 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
479 478 "Detach: enter for detach");
480 479
481 480 rval = usbskel_cleanup(dip, usbskelp);
482 481
483 482 break;
484 483 case DDI_SUSPEND:
485 484 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
486 485 "Detach: enter for suspend");
487 486
488 487 rval = usbskel_cpr_suspend(dip);
489 488 default:
490 489
491 490 break;
492 491 }
493 492
494 493 return ((rval == USB_SUCCESS) ? DDI_SUCCESS : DDI_FAILURE);
495 494 }
496 495
497 496
498 497 /*
499 498 * usbskel_cleanup:
500 499 * clean up the driver state for detach
501 500 */
502 501 static int
503 502 usbskel_cleanup(dev_info_t *dip, usbskel_state_t *usbskelp)
504 503 {
505 504 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "Cleanup: enter");
506 505
507 506 if (usbskelp->usbskel_locks_initialized) {
508 507
509 508 /* This must be done 1st to prevent more events from coming. */
510 509 usb_unregister_hotplug_cbs(dip);
511 510
512 511 /*
513 512 * At this point, no new activity can be initiated. The driver
514 513 * has disabled hotplug callbacks. The Solaris framework has
515 514 * disabled new opens on a device being detached, and does not
516 515 * allow detaching an open device.
517 516 *
518 517 * The following ensures that all driver activity has drained.
519 518 */
520 519 mutex_enter(&usbskelp->usbskel_mutex);
521 520 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
522 521 usbskel_release_access(usbskelp);
523 522 mutex_exit(&usbskelp->usbskel_mutex);
524 523
525 524 #ifdef USBSKEL_PM
526 525 /* All device activity has died down. */
527 526 usbskel_destroy_power_mgmt(usbskelp);
528 527 #endif
529 528
530 529 /* start dismantling */
531 530 ddi_remove_minor_node(dip, NULL);
532 531
533 532 cv_destroy(&usbskelp->usbskel_serial_cv);
534 533 mutex_destroy(&usbskelp->usbskel_mutex);
535 534 }
536 535
537 536 usb_client_detach(dip, usbskelp->usbskel_reg);
538 537
539 538 if (usbskelp->usbskel_devinst != NULL) {
540 539 kmem_free(usbskelp->usbskel_devinst,
541 540 strlen(usbskelp->usbskel_devinst) + 1);
542 541 }
543 542
544 543 ddi_soft_state_free(usbskel_statep, ddi_get_instance(dip));
545 544 ddi_prop_remove_all(dip);
546 545
547 546 return (USB_SUCCESS);
548 547 }
549 548
550 549
551 550 /*ARGSUSED*/
552 551 static int
553 552 usbskel_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
554 553 {
555 554 usbskel_state_t *usbskelp =
556 555 ddi_get_soft_state(usbskel_statep, getminor(*devp));
557 556 int rval = 0;
558 557
559 558 if (usbskelp == NULL) {
560 559
561 560 return (ENXIO);
562 561 }
563 562
564 563 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "open: enter");
565 564
566 565 /*
567 566 * Keep it simple: one client at a time.
568 567 * Exclusive open only
569 568 */
570 569 mutex_enter(&usbskelp->usbskel_mutex);
571 570 if ((usbskelp->usbskel_drv_state & USBSKEL_OPEN) != 0) {
572 571 mutex_exit(&usbskelp->usbskel_mutex);
573 572
574 573 return (EBUSY);
575 574 }
576 575 usbskelp->usbskel_drv_state |= USBSKEL_OPEN;
577 576
578 577 /*
579 578 * This is in place so that a disconnect or CPR doesn't interfere with
580 579 * pipe opens.
581 580 */
582 581 if (usbskel_serialize_access(usbskelp, USBSKEL_SER_SIG) == 0) {
583 582 usbskelp->usbskel_drv_state &= ~USBSKEL_OPEN;
584 583 mutex_exit(&usbskelp->usbskel_mutex);
585 584
586 585 return (EINTR);
587 586 }
588 587
589 588 mutex_exit(&usbskelp->usbskel_mutex);
590 589 if (usbskel_pm_busy_component(usbskelp) != DDI_SUCCESS) {
591 590 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
592 591 "open: Error raising power");
593 592 rval = EIO;
594 593 goto done;
595 594 }
596 595 mutex_enter(&usbskelp->usbskel_mutex);
597 596
598 597 /* Fail if device is no longer ready. */
599 598 if (usbskelp->usbskel_dev_state != USB_DEV_ONLINE) {
600 599 mutex_exit(&usbskelp->usbskel_mutex);
601 600 rval = EIO;
602 601 goto done;
603 602 }
604 603
605 604 mutex_exit(&usbskelp->usbskel_mutex);
606 605 if (usbskel_open_pipes(usbskelp) != USB_SUCCESS) {
607 606 rval = EIO;
608 607 goto done;
609 608 }
610 609
611 610 /* Device specific initialization goes here. */
612 611
613 612 done:
614 613 if (rval != 0) {
615 614 mutex_enter(&usbskelp->usbskel_mutex);
616 615 usbskelp->usbskel_drv_state &= ~USBSKEL_OPEN;
617 616
618 617 usbskel_release_access(usbskelp);
619 618 mutex_exit(&usbskelp->usbskel_mutex);
620 619
621 620 usbskel_pm_idle_component(usbskelp);
622 621 } else {
623 622
624 623 /* Device is idle until it is used. */
625 624 mutex_enter(&usbskelp->usbskel_mutex);
626 625 usbskel_release_access(usbskelp);
627 626 mutex_exit(&usbskelp->usbskel_mutex);
628 627 }
629 628
630 629 return (rval);
631 630 }
632 631
633 632
634 633 /*ARGSUSED*/
635 634 static int
636 635 usbskel_close(dev_t dev, int flag, int otyp, cred_t *cred_p)
637 636 {
638 637 usbskel_state_t *usbskelp =
639 638 ddi_get_soft_state(usbskel_statep, getminor(dev));
640 639
641 640 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "close: enter");
642 641
643 642 mutex_enter(&usbskelp->usbskel_mutex);
644 643 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
645 644 mutex_exit(&usbskelp->usbskel_mutex);
646 645
647 646 /* Perform device session cleanup here. */
648 647
649 648 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "close: cleaning up...");
650 649
651 650 /*
652 651 * USBA automatically flushes/resets active non-default pipes
653 652 * when they are closed. We can't reset default pipe, but we
654 653 * can wait for all requests on it from this dip to drain.
655 654 */
656 655 (void) usb_pipe_drain_reqs(usbskelp->usbskel_dip,
657 656 usbskelp->usbskel_reg->dev_default_ph, 0,
658 657 USB_FLAGS_SLEEP, NULL, 0);
659 658
660 659 mutex_enter(&usbskelp->usbskel_mutex);
661 660 usbskel_close_pipes(usbskelp);
662 661
663 662 usbskelp->usbskel_drv_state &= ~USBSKEL_OPEN;
664 663
665 664 usbskel_release_access(usbskelp);
666 665 mutex_exit(&usbskelp->usbskel_mutex);
667 666
668 667 usbskel_pm_idle_component(usbskelp);
669 668
670 669 return (0);
671 670 }
672 671
673 672
674 673 /*ARGSUSED*/
675 674 static int
676 675 usbskel_read(dev_t dev, struct uio *uio_p, cred_t *cred_p)
677 676 {
678 677 usbskel_state_t *usbskelp =
679 678 ddi_get_soft_state(usbskel_statep, getminor(dev));
680 679
681 680 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "read enter");
682 681
683 682 return (physio(usbskel_strategy, NULL, dev, B_READ,
684 683 usbskel_minphys, uio_p));
685 684 }
686 685
687 686
688 687 /*
689 688 * strategy:
690 689 * Called through physio to setup and start the transfer.
691 690 */
692 691 static int
693 692 usbskel_strategy(struct buf *bp)
694 693 {
695 694 usbskel_state_t *usbskelp = ddi_get_soft_state(usbskel_statep,
696 695 getminor(bp->b_edev));
697 696 usb_pipe_handle_t pipe = usbskelp->usbskel_reg->dev_default_ph;
698 697 usb_ctrl_req_t *request;
699 698 int status;
700 699
701 700 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "strategy enter");
702 701
703 702 /*
704 703 * Initialize residual count here in case transfer doesn't even get
705 704 * started.
706 705 */
707 706 bp->b_resid = bp->b_bcount;
708 707
709 708 /* Needed as this is a character driver. */
710 709 if (bp->b_flags & (B_PHYS | B_PAGEIO)) {
711 710 bp_mapin(bp);
712 711 }
713 712
714 713 mutex_enter(&usbskelp->usbskel_mutex);
715 714 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
716 715
717 716 /* Make sure device has not been disconnected. */
718 717 if (usbskelp->usbskel_dev_state != USB_DEV_ONLINE) {
719 718 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
720 719 "usbskel_strategy: device can't be accessed");
721 720 mutex_exit(&usbskelp->usbskel_mutex);
722 721 goto fail;
723 722 }
724 723 mutex_exit(&usbskelp->usbskel_mutex);
725 724
726 725 /*
727 726 * Since every device has raw configuration data, set up a control
728 727 * transfer to read the raw configuration data. In a production driver
729 728 * a read would probably be done on a pipe other than the default pipe,
730 729 * and would be reading data streamed by the device.
731 730 */
732 731
733 732 /* Allocate and initialize the request. */
734 733 if ((bp->b_private = request = usb_alloc_ctrl_req(
735 734 usbskelp->usbskel_dip, bp->b_bcount, USB_FLAGS_SLEEP)) ==
736 735 NULL) {
737 736 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
738 737 "usbskel_read: Error allocating request");
739 738 goto fail;
740 739 }
741 740
742 741 request->ctrl_bmRequestType =
743 742 USB_DEV_REQ_DEV_TO_HOST | USB_DEV_REQ_TYPE_STANDARD |
744 743 USB_DEV_REQ_RCPT_DEV;
745 744 request->ctrl_bRequest = USB_REQ_GET_DESCR;
746 745
747 746 /* For now, return only the first configuration. */
748 747 request->ctrl_wValue = USB_DESCR_TYPE_SETUP_CFG | 0;
749 748 request->ctrl_wIndex = 0;
750 749 request->ctrl_wLength = bp->b_bcount;
751 750 request->ctrl_timeout = 3;
752 751
753 752 /* Autoclearing automatically set on default pipe. */
754 753 request->ctrl_attributes = USB_ATTRS_SHORT_XFER_OK;
755 754
756 755 request->ctrl_cb = usbskel_normal_callback;
757 756 request->ctrl_exc_cb = usbskel_exception_callback;
758 757
759 758 /* Hook the req to the bp, so callback knows where to put the data. */
760 759 /* Now both bp and request know about each other. */
761 760 request->ctrl_client_private = (usb_opaque_t)bp;
762 761
763 762 /*
764 763 * Issue the request asynchronously. Physio will block waiting for an
765 764 * "interrupt" which comes as a callback. The callback calls biodone
766 765 * to release physio from its wait.
767 766 */
768 767 if ((status = usb_pipe_ctrl_xfer(pipe, request, USB_FLAGS_NOSLEEP)) !=
769 768 USB_SUCCESS) {
770 769 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
771 770 "usbskel_strategy: can't start transfer: status: %d",
772 771 status);
773 772 goto fail;
774 773 }
775 774
776 775 /*
777 776 * Normally, usbskel_release_access() and usbskel_pm_idle_component
778 777 * is called in callback handler.
779 778 */
780 779
781 780 return (0);
782 781
783 782 fail:
784 783 mutex_enter(&usbskelp->usbskel_mutex);
785 784 usbskel_release_access(usbskelp);
786 785 mutex_exit(&usbskelp->usbskel_mutex);
787 786
788 787 bioerror(bp, EIO);
789 788 biodone(bp);
790 789
791 790 return (0);
792 791 }
793 792
794 793
795 794 static void
796 795 usbskel_minphys(struct buf *bp)
797 796 {
798 797 /* the config cloud is limited to 64k */
799 798 if (bp->b_bcount > USBSKEL_REQUEST_SIZE) {
800 799 bp->b_bcount = USBSKEL_REQUEST_SIZE;
801 800 }
802 801 minphys(bp);
803 802 }
804 803
805 804
806 805 /*
807 806 * usbskel_normal_callback:
808 807 * Completion handler for successful transfer.
809 808 * Copy data from mblk returned by USBA, into
810 809 * buffer passed by physio, to get it back to user.
811 810 * Idle device
812 811 * update counts, etc.
813 812 * release request.
814 813 * signal completion via biodone
815 814 */
816 815 /*ARGSUSED*/
817 816 static void
818 817 usbskel_normal_callback(usb_pipe_handle_t pipe, usb_ctrl_req_t *request)
819 818 {
820 819 struct buf *bp = (struct buf *)request->ctrl_client_private;
821 820 usbskel_state_t *usbskelp = ddi_get_soft_state(usbskel_statep,
822 821 getminor(bp->b_edev));
823 822 mblk_t *data = request->ctrl_data;
824 823 int amt_transferred = MBLKL(data);
825 824
826 825 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "normal callback enter");
827 826
828 827 ASSERT((request->ctrl_cb_flags & USB_CB_INTR_CONTEXT) == 0);
829 828
830 829 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
831 830 "at entry, b_bcount = %lu, b_resid = %lu, trans = %d", bp->b_bcount,
832 831 bp->b_resid, amt_transferred);
833 832
834 833 mutex_enter(&usbskelp->usbskel_mutex);
835 834 usbskel_release_access(usbskelp);
836 835 mutex_exit(&usbskelp->usbskel_mutex);
837 836
838 837 /* Copy data out of mblk, into buffer. */
839 838 if (amt_transferred) {
840 839 bcopy(data->b_rptr, bp->b_un.b_addr, amt_transferred);
841 840 }
842 841
843 842 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
844 843 "normal callback: transferring %d bytes from 0x%p to 0x%p",
845 844 amt_transferred, (void *)data, (void *)(bp->b_un.b_addr));
846 845
847 846 /* Unhook. */
848 847 bp->b_private = NULL;
849 848 request->ctrl_client_private = NULL;
850 849
851 850 /* Free request. */
852 851 usb_free_ctrl_req(request);
853 852
854 853 /* Finish up. */
855 854 bp->b_resid = bp->b_bcount - amt_transferred;
856 855
857 856 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
858 857 "at exit, b_bcount = %lu, b_resid = %lu, trans = %d", bp->b_bcount,
859 858 bp->b_resid, amt_transferred);
860 859
861 860 biodone(bp);
862 861 }
863 862
864 863
865 864 /*
866 865 * usbskel_exception_callback:
867 866 * Completion handler for an erred transfer.
868 867 * Copy data from mblk returned by USBA, if any, into
869 868 * buffer passed by physio, to get it back to user.
870 869 * Idle device
871 870 * update counts, etc.
872 871 * release request.
873 872 * signal completion via biodone
874 873 */
875 874 /*ARGSUSED*/
876 875 static void
877 876 usbskel_exception_callback(usb_pipe_handle_t pipe, usb_ctrl_req_t *request)
878 877 {
879 878 struct buf *bp = (struct buf *)request->ctrl_client_private;
880 879 usbskel_state_t *usbskelp = ddi_get_soft_state(usbskel_statep,
881 880 getminor(bp->b_edev));
882 881 mblk_t *data = request->ctrl_data;
883 882 int amt_transferred = (data ? MBLKL(data) : 0);
884 883
885 884 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
886 885 "at except cb entry, b_bcount = %lu, b_resid = %lu, trans = %d",
887 886 bp->b_bcount, bp->b_resid, amt_transferred);
888 887
889 888 ASSERT((request->ctrl_cb_flags & USB_CB_INTR_CONTEXT) == 0);
890 889
891 890 mutex_enter(&usbskelp->usbskel_mutex);
892 891 usbskel_release_access(usbskelp);
893 892 mutex_exit(&usbskelp->usbskel_mutex);
894 893
895 894 /* Copy data, if any, out of mblk, into buffer. */
896 895 if (amt_transferred) {
897 896 bcopy(data, bp->b_un.b_addr, amt_transferred);
898 897 }
899 898 bp->b_resid = bp->b_bcount - amt_transferred;
900 899
901 900 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
902 901 "exception cb: req = 0x%p, cr = %d\n\t cb_flags = 0x%x "
903 902 "data = 0x%p, amt xfered = %d", (void *)request,
904 903 request->ctrl_completion_reason, request->ctrl_cb_flags,
905 904 (void *)(request->ctrl_data), amt_transferred);
906 905
907 906 /* Unhook */
908 907 bp->b_private = NULL;
909 908 request->ctrl_client_private = NULL;
910 909
911 910 /* Free request. */
912 911 usb_free_ctrl_req(request);
913 912
914 913 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
915 914 "at except cb exit, b_bcount = %lu, b_resid = %lu, trans = %d",
916 915 bp->b_bcount, bp->b_resid, amt_transferred);
917 916
918 917 bioerror(bp, EIO);
919 918 biodone(bp);
920 919 }
921 920
922 921
923 922 /*
924 923 * XXX Empty ioctl for now.
925 924 */
926 925 /*ARGSUSED*/
927 926 static int
928 927 usbskel_ioctl(dev_t dev, int cmd, intptr_t arg,
929 928 int mode, cred_t *cred_p, int *rval_p)
930 929 {
931 930 usbskel_state_t *usbskelp =
932 931 ddi_get_soft_state(usbskel_statep, getminor(dev));
933 932
934 933 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "ioctl enter");
935 934
936 935 return (ENOTTY);
937 936 }
938 937
939 938
940 939 /*
941 940 * usbskel_disconnect_callback:
942 941 * Called when device hotplug-removed.
943 942 * Close pipes. (This does not attempt to contact device.)
944 943 * Set state to DISCONNECTED
945 944 */
946 945 static int
947 946 usbskel_disconnect_callback(dev_info_t *dip)
948 947 {
949 948 int instance = ddi_get_instance(dip);
950 949 usbskel_state_t *usbskelp =
951 950 ddi_get_soft_state(usbskel_statep, instance);
952 951
953 952 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "disconnect: enter");
954 953
955 954 mutex_enter(&usbskelp->usbskel_mutex);
956 955 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
957 956
958 957 /*
959 958 * Save any state of device or IO in progress required by
960 959 * usbskel_restore_device_state for proper device "thawing" later.
961 960 */
962 961 usbskelp->usbskel_dev_state = USB_DEV_DISCONNECTED;
963 962
964 963 usbskel_release_access(usbskelp);
965 964 mutex_exit(&usbskelp->usbskel_mutex);
966 965
967 966 return (USB_SUCCESS);
968 967 }
969 968
970 969
971 970 /*
972 971 * usbskel_reconnect_callback:
973 972 * Called with device hotplug-inserted
974 973 * Restore state
975 974 */
976 975 static int
977 976 usbskel_reconnect_callback(dev_info_t *dip)
978 977 {
979 978 int instance = ddi_get_instance(dip);
980 979 usbskel_state_t *usbskelp =
981 980 ddi_get_soft_state(usbskel_statep, instance);
982 981
983 982 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "reconnect: enter");
984 983
985 984 mutex_enter(&usbskelp->usbskel_mutex);
986 985 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
987 986 usbskel_restore_device_state(dip, usbskelp);
988 987 usbskel_release_access(usbskelp);
989 988 mutex_exit(&usbskelp->usbskel_mutex);
990 989
991 990 return (USB_SUCCESS);
992 991 }
993 992
994 993
995 994 /*
996 995 * usbskel_restore_device_state:
997 996 * Called during hotplug-reconnect and resume.
998 997 * reenable power management
999 998 * Verify the device is the same as before the disconnect/suspend.
1000 999 * Restore device state
1001 1000 * Thaw any IO which was frozen.
1002 1001 * Quiesce device. (Other routines will activate if thawed IO.)
1003 1002 * Set device online.
1004 1003 * Leave device disconnected if there are problems.
1005 1004 */
1006 1005 static void
1007 1006 usbskel_restore_device_state(dev_info_t *dip, usbskel_state_t *usbskelp)
1008 1007 {
1009 1008 int rval;
1010 1009
1011 1010 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1012 1011 "usbskel_restore_device_state: enter");
1013 1012
1014 1013 ASSERT(mutex_owned(&usbskelp->usbskel_mutex));
1015 1014
1016 1015 ASSERT((usbskelp->usbskel_dev_state == USB_DEV_DISCONNECTED) ||
1017 1016 (usbskelp->usbskel_dev_state == USB_DEV_SUSPENDED));
1018 1017
1019 1018 mutex_exit(&usbskelp->usbskel_mutex);
1020 1019
1021 1020 if (usbskel_pm_busy_component(usbskelp) != DDI_SUCCESS) {
1022 1021 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1023 1022 "usbskel_restore_device_state: Error raising power");
1024 1023
1025 1024 goto fail;
1026 1025 }
1027 1026
1028 1027 /* Check if we are talking to the same device */
1029 1028 if (usbskel_check_same_device(usbskelp) != USB_SUCCESS) {
1030 1029
1031 1030 goto fail;
1032 1031 }
1033 1032
1034 1033 mutex_enter(&usbskelp->usbskel_mutex);
1035 1034 if ((rval = usbskel_test_and_adjust_device_state(usbskelp)) !=
1036 1035 USB_SUCCESS) {
1037 1036 mutex_exit(&usbskelp->usbskel_mutex);
1038 1037 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1039 1038 "usbskel_restore_device_state: "
1040 1039 "Error adjusting device: rval = %d", rval);
1041 1040
1042 1041 goto fail;
1043 1042 }
1044 1043 usbskelp->usbskel_dev_state = USB_DEV_ONLINE;
1045 1044 mutex_exit(&usbskelp->usbskel_mutex);
1046 1045
1047 1046 if (usbskelp->usbskel_pm) {
1048 1047
1049 1048 /* Failure here means device disappeared again. */
1050 1049 if (usb_handle_remote_wakeup(dip, USB_REMOTE_WAKEUP_ENABLE) !=
1051 1050 USB_SUCCESS) {
1052 1051 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1053 1052 "device may or may not be accessible. "
1054 1053 "Please verify reconnection");
1055 1054 }
1056 1055 usbskel_pm_idle_component(usbskelp);
1057 1056 }
1058 1057
1059 1058
1060 1059 mutex_enter(&usbskelp->usbskel_mutex);
1061 1060
1062 1061 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1063 1062 "usbskel_restore_device_state: end");
1064 1063
1065 1064 return;
1066 1065
1067 1066 fail:
1068 1067 /* change the device state from suspended to disconnected */
1069 1068 mutex_enter(&usbskelp->usbskel_mutex);
1070 1069 usbskelp->usbskel_dev_state = USB_DEV_DISCONNECTED;
1071 1070 mutex_exit(&usbskelp->usbskel_mutex);
1072 1071
1073 1072 usbskel_pm_idle_component(usbskelp);
1074 1073 mutex_enter(&usbskelp->usbskel_mutex);
1075 1074 }
1076 1075
1077 1076
1078 1077 /*
1079 1078 * usbskel_cpr_suspend:
1080 1079 * Clean up device.
1081 1080 * Wait for any IO to finish, then close pipes.
1082 1081 * Quiesce device.
1083 1082 */
1084 1083 static int
1085 1084 usbskel_cpr_suspend(dev_info_t *dip)
1086 1085 {
1087 1086 int instance = ddi_get_instance(dip);
1088 1087 usbskel_state_t *usbskelp = ddi_get_soft_state(usbskel_statep,
1089 1088 instance);
1090 1089
1091 1090 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "suspend enter");
1092 1091
1093 1092 /* Serialize to prevent races with detach, open, device access. */
1094 1093 mutex_enter(&usbskelp->usbskel_mutex);
1095 1094 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
1096 1095 mutex_exit(&usbskelp->usbskel_mutex);
1097 1096
1098 1097 if (usbskel_pm_busy_component(usbskelp) != DDI_SUCCESS) {
1099 1098 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1100 1099 "suspend: Error raising power");
1101 1100 usbskel_pm_idle_component(usbskelp);
1102 1101
1103 1102 return (USB_FAILURE);
1104 1103 }
1105 1104
1106 1105 mutex_enter(&usbskelp->usbskel_mutex);
1107 1106
1108 1107 /*
1109 1108 * Set dev_state to suspended so other driver threads don't start any
1110 1109 * new I/O. In a real driver, there may be draining of requests done
1111 1110 * afterwards, and we don't want the draining to compete with new
1112 1111 * requests being queued.
1113 1112 */
1114 1113
1115 1114 /* Don't suspend if the device is open. */
1116 1115 if ((usbskelp->usbskel_drv_state & USBSKEL_OPEN) != 0) {
1117 1116 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1118 1117 "suspend: Device is open. Can't suspend");
1119 1118
1120 1119 usbskel_release_access(usbskelp);
1121 1120 mutex_exit(&usbskelp->usbskel_mutex);
1122 1121
1123 1122 usbskel_pm_idle_component(usbskelp);
1124 1123
1125 1124 return (USB_FAILURE);
1126 1125 }
1127 1126
1128 1127 /* Access device here to clean it up. */
1129 1128
1130 1129 usbskelp->usbskel_dev_state = USB_DEV_SUSPENDED;
1131 1130
1132 1131 /*
1133 1132 * Save any state of device required by usbskel_restore_device_state
1134 1133 * for proper device "thawing" later.
1135 1134 */
1136 1135
1137 1136 usbskel_release_access(usbskelp);
1138 1137 mutex_exit(&usbskelp->usbskel_mutex);
1139 1138
1140 1139 usbskel_pm_idle_component(usbskelp);
1141 1140
1142 1141 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "suspend: success");
1143 1142
1144 1143 return (USB_SUCCESS);
1145 1144 }
1146 1145
1147 1146
1148 1147 /*
1149 1148 * usbskel_cpr_resume:
1150 1149 *
1151 1150 * usbskel_restore_device_state marks success by putting device back online
1152 1151 */
1153 1152 static void
1154 1153 usbskel_cpr_resume(dev_info_t *dip)
1155 1154 {
1156 1155 int instance = ddi_get_instance(dip);
1157 1156 usbskel_state_t *usbskelp = ddi_get_soft_state(usbskel_statep,
1158 1157 instance);
1159 1158
1160 1159 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "resume: enter");
1161 1160
1162 1161 /*
1163 1162 * NOTE: A pm_raise_power in usbskel_restore_device_state will bring
1164 1163 * the power-up state of device into synch with the system.
1165 1164 */
1166 1165 mutex_enter(&usbskelp->usbskel_mutex);
1167 1166 usbskel_restore_device_state(dip, usbskelp);
1168 1167 mutex_exit(&usbskelp->usbskel_mutex);
1169 1168 }
1170 1169
1171 1170
1172 1171 /*
1173 1172 * usbskel_test_and_adjust_device_state:
1174 1173 * Place any device-specific initialization or sanity verification here.
1175 1174 */
1176 1175 static int
1177 1176 usbskel_test_and_adjust_device_state(usbskel_state_t *usbskelp)
1178 1177 {
1179 1178 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "test and adjust enter");
1180 1179
1181 1180 return (USB_SUCCESS);
1182 1181 }
1183 1182
1184 1183
1185 1184 /*
1186 1185 * usbskel_open_pipes:
1187 1186 * Open any pipes other than default pipe.
1188 1187 * Mutex is assumed to be held.
1189 1188 */
1190 1189 static int
1191 1190 usbskel_open_pipes(usbskel_state_t *usbskelp)
1192 1191 {
1193 1192
1194 1193 int rval = USB_SUCCESS;
1195 1194 usb_pipe_policy_t pipe_policy;
1196 1195 usb_pipe_handle_t pipe_handle;
1197 1196
1198 1197 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "open_pipes enter");
1199 1198
1200 1199 bzero(&pipe_policy, sizeof (pipe_policy));
1201 1200
1202 1201 /*
1203 1202 * Allow that pipes can support at least two asynchronous operations
1204 1203 * going on simultaneously. Operations include asynchronous callbacks,
1205 1204 * resets, closures.
1206 1205 */
1207 1206 pipe_policy.pp_max_async_reqs = 2;
1208 1207
1209 1208 if ((rval = usb_pipe_open(usbskelp->usbskel_dip,
1210 1209 &usbskelp->usbskel_intr_ep_descr, &pipe_policy,
1211 1210 USB_FLAGS_SLEEP, &pipe_handle)) != USB_SUCCESS) {
1212 1211 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1213 1212 "usbskel_open_pipes: Error opening intr pipe: status = %d",
1214 1213 rval);
1215 1214 rval = USB_FAILURE;
1216 1215 }
1217 1216 mutex_enter(&usbskelp->usbskel_mutex);
1218 1217 usbskelp->usbskel_intr_ph = pipe_handle;
1219 1218 mutex_exit(&usbskelp->usbskel_mutex);
1220 1219
1221 1220 /*
1222 1221 * At this point, polling could be started on the pipe by making an
1223 1222 * asynchronous input request on the pipe. Allocate a request by
1224 1223 * calling usb_alloc_intr_req(9F) with a zero length, initialize
1225 1224 * attributes with USB_ATTRS_SHORT_XFER_OK | USB_ATTRS_AUTOCLEARING,
1226 1225 * initialize length to be packetsize of the endpoint, specify the
1227 1226 * callbacks. Pass this request to usb_pipe_intr_xfer to start polling.
1228 1227 * Call usb_pipe_stop_intr_poling(9F) to stop polling.
1229 1228 */
1230 1229
1231 1230 return (rval);
1232 1231 }
1233 1232
1234 1233
1235 1234 /*
1236 1235 * usbskel_close_pipes:
1237 1236 * Close pipes. Mutex is assumed to be held.
1238 1237 */
1239 1238 /*ARGSUSED*/
1240 1239 static void
1241 1240 usbskel_close_pipes(usbskel_state_t *usbskelp)
1242 1241 {
1243 1242 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "close_pipes enter");
1244 1243
1245 1244 if (usbskelp->usbskel_intr_ph) {
1246 1245 usb_pipe_handle_t pipe_handle = usbskelp->usbskel_intr_ph;
1247 1246 usbskelp->usbskel_intr_ph = NULL;
1248 1247 mutex_exit(&usbskelp->usbskel_mutex);
1249 1248
1250 1249 usb_pipe_close(usbskelp->usbskel_dip, pipe_handle,
1251 1250 USB_FLAGS_SLEEP, NULL, 0);
1252 1251
1253 1252 mutex_enter(&usbskelp->usbskel_mutex);
1254 1253 }
1255 1254 }
1256 1255
1257 1256 static int
1258 1257 usbskel_pm_busy_component(usbskel_state_t *usbskelp)
1259 1258 {
1260 1259 int rval = DDI_SUCCESS;
1261 1260
1262 1261 mutex_enter(&usbskelp->usbskel_mutex);
1263 1262 if (usbskelp->usbskel_pm != NULL) {
1264 1263 usbskelp->usbskel_pm->usbskel_pm_busy++;
1265 1264 mutex_exit(&usbskelp->usbskel_mutex);
1266 1265 if (pm_busy_component(usbskelp->usbskel_dip, 0) ==
1267 1266 DDI_SUCCESS) {
1268 1267 (void) pm_raise_power(
1269 1268 usbskelp->usbskel_dip, 0, USB_DEV_OS_FULL_PWR);
1270 1269 mutex_enter(&usbskelp->usbskel_mutex);
1271 1270 } else {
1272 1271 mutex_enter(&usbskelp->usbskel_mutex);
1273 1272 usbskelp->usbskel_pm->usbskel_pm_busy--;
1274 1273 rval = DDI_FAILURE;
1275 1274 }
1276 1275 }
1277 1276 mutex_exit(&usbskelp->usbskel_mutex);
1278 1277
1279 1278 return (rval);
1280 1279 }
1281 1280
1282 1281 static void
1283 1282 usbskel_pm_idle_component(usbskel_state_t *usbskelp)
1284 1283 {
1285 1284 mutex_enter(&usbskelp->usbskel_mutex);
1286 1285 if (usbskelp->usbskel_pm != NULL) {
1287 1286 mutex_exit(&usbskelp->usbskel_mutex);
1288 1287 if (pm_idle_component(usbskelp->usbskel_dip, 0) ==
1289 1288 DDI_SUCCESS) {
1290 1289 mutex_enter(&usbskelp->usbskel_mutex);
1291 1290 ASSERT(usbskelp->usbskel_pm->usbskel_pm_busy > 0);
1292 1291 usbskelp->usbskel_pm->usbskel_pm_busy--;
1293 1292 mutex_exit(&usbskelp->usbskel_mutex);
1294 1293 }
1295 1294 mutex_enter(&usbskelp->usbskel_mutex);
1296 1295 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1297 1296 "usbskel_pm_idle_component: %d",
1298 1297 usbskelp->usbskel_pm->usbskel_pm_busy);
1299 1298 }
1300 1299 mutex_exit(&usbskelp->usbskel_mutex);
1301 1300 }
1302 1301
1303 1302 /*
1304 1303 * usbskel_power :
1305 1304 * Power entry point, the workhorse behind pm_raise_power, pm_lower_power,
1306 1305 * usb_req_raise_power and usb_req_lower_power.
1307 1306 */
1308 1307 /* ARGSUSED */
1309 1308 static int
1310 1309 usbskel_power(dev_info_t *dip, int comp, int level)
1311 1310 {
1312 1311 usbskel_state_t *usbskelp;
1313 1312 usbskel_power_t *pm;
1314 1313 int rval = USB_FAILURE;
1315 1314
1316 1315 usbskelp = ddi_get_soft_state(usbskel_statep, ddi_get_instance(dip));
1317 1316
1318 1317 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1319 1318 "usbskel_power: enter: level = %d", level);
1320 1319
1321 1320 mutex_enter(&usbskelp->usbskel_mutex);
1322 1321 (void) usbskel_serialize_access(usbskelp, USBSKEL_SER_NOSIG);
1323 1322
1324 1323
1325 1324 /*
1326 1325 * If we are disconnected/suspended, return success. Note that if we
1327 1326 * return failure, bringing down the system will hang when
1328 1327 * PM tries to power up all devices
1329 1328 */
1330 1329 if ((usbskelp->usbskel_dev_state == USB_DEV_DISCONNECTED) ||
1331 1330 (usbskelp->usbskel_dev_state == USB_DEV_SUSPENDED)) {
1332 1331
1333 1332 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1334 1333 "usbskel_power: disconnected/suspended "
1335 1334 "dev_state=%d", usbskelp->usbskel_dev_state);
1336 1335 rval = USB_SUCCESS;
1337 1336
1338 1337 goto done;
1339 1338 }
1340 1339
1341 1340 if (usbskelp->usbskel_pm == NULL) {
1342 1341
1343 1342 goto done;
1344 1343 }
1345 1344
1346 1345 pm = usbskelp->usbskel_pm;
1347 1346
1348 1347 /* Check if we are transitioning to a legal power level */
1349 1348 if (USB_DEV_PWRSTATE_OK(pm->usbskel_pwr_states, level)) {
1350 1349 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1351 1350 "usbskel_power: illegal power level = %d "
1352 1351 "pwr_states: %x", level, pm->usbskel_pwr_states);
1353 1352
1354 1353 goto done;
1355 1354 }
1356 1355
1357 1356 switch (level) {
1358 1357 case USB_DEV_OS_PWR_OFF :
1359 1358 /* fail attempt to go to low power if busy */
1360 1359 if (pm->usbskel_pm_busy) {
1361 1360
1362 1361 goto done;
1363 1362 }
1364 1363 if (usbskelp->usbskel_dev_state == USB_DEV_ONLINE) {
1365 1364 usbskelp->usbskel_dev_state = USB_DEV_PWRED_DOWN;
1366 1365 usbskelp->usbskel_pm->usbskel_current_power =
1367 1366 USB_DEV_OS_PWR_OFF;
1368 1367 } else {
1369 1368 rval = USB_SUCCESS;
1370 1369 }
1371 1370 break;
1372 1371
1373 1372 case USB_DEV_OS_FULL_PWR :
1374 1373 /*
1375 1374 * PM framework tries to put us in full power during system
1376 1375 * shutdown.
1377 1376 */
1378 1377 usbskelp->usbskel_dev_state = USB_DEV_ONLINE;
1379 1378 usbskelp->usbskel_pm->usbskel_current_power =
1380 1379 USB_DEV_OS_FULL_PWR;
1381 1380 break;
1382 1381
1383 1382 /* Levels 1 and 2 are not supported by this driver to keep it simple. */
1384 1383 default:
1385 1384 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1386 1385 "usbskel_power: power level %d not supported", level);
1387 1386 break;
1388 1387 }
1389 1388 done:
1390 1389 usbskel_release_access(usbskelp);
1391 1390 mutex_exit(&usbskelp->usbskel_mutex);
1392 1391
1393 1392 return ((rval == USB_SUCCESS) ? DDI_SUCCESS : DDI_FAILURE);
1394 1393 }
1395 1394
1396 1395
1397 1396 #ifdef USBSKEL_PM
1398 1397 /*
1399 1398 * usbskel_init_power_mgmt:
1400 1399 * Initialize power management and remote wakeup functionality.
1401 1400 * No mutex is necessary in this function as it's called only by attach.
1402 1401 */
1403 1402 static int
1404 1403 usbskel_init_power_mgmt(usbskel_state_t *usbskelp)
1405 1404 {
1406 1405 int rval = USB_FAILURE;
1407 1406
1408 1407 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "init_power_mgmt enter");
1409 1408
1410 1409 /*
1411 1410 * If remote wakeup is not available you may not want to do
1412 1411 * power management.
1413 1412 */
1414 1413 if (usb_handle_remote_wakeup(usbskelp->usbskel_dip,
1415 1414 USB_REMOTE_WAKEUP_ENABLE) == USB_SUCCESS) {
1416 1415 usbskel_power_t *usbskelpm;
1417 1416 uint_t pwr_states;
1418 1417
1419 1418 /* Allocate the state structure */
1420 1419 usbskelpm = kmem_zalloc(sizeof (usbskel_power_t), KM_SLEEP);
1421 1420 usbskelp->usbskel_pm = usbskelpm;
1422 1421 usbskelpm->usbskel_state = usbskelp;
1423 1422 usbskelpm->usbskel_pm_capabilities = 0;
1424 1423 usbskelpm->usbskel_current_power = USB_DEV_OS_FULL_PWR;
1425 1424
1426 1425 if ((rval = usb_create_pm_components(
1427 1426 usbskelp->usbskel_dip, &pwr_states)) == USB_SUCCESS) {
1428 1427
1429 1428 usbskel_log(usbskelp, USBSKEL_LOG_LOG,
1430 1429 "usbskel_init_power_mgmt: created PM components");
1431 1430
1432 1431 usbskelpm->usbskel_pwr_states =
1433 1432 (uint8_t)pwr_states;
1434 1433 (void) pm_raise_power(
1435 1434 usbskelp->usbskel_dip, 0, USB_DEV_OS_FULL_PWR);
1436 1435 } else {
1437 1436 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1438 1437 "usbskel_init_power_mgmt: create_pm_compts failed");
1439 1438 }
1440 1439 } else {
1441 1440 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1442 1441 "usbskel_init_power_mgmt: failure enabling remote wakeup");
1443 1442 }
1444 1443 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "usbskel_init_power_mgmt: end");
1445 1444
1446 1445 return (rval);
1447 1446 }
1448 1447
1449 1448
1450 1449 /*
1451 1450 * usbskel_destroy_power_mgmt:
1452 1451 * Shut down and destroy power management and remote wakeup functionality.
1453 1452 */
1454 1453 static void
1455 1454 usbskel_destroy_power_mgmt(usbskel_state_t *usbskelp)
1456 1455 {
1457 1456 usbskel_log(usbskelp, USBSKEL_LOG_LOG, "destroy_power_mgmt enter");
1458 1457
1459 1458 ASSERT(!mutex_owned(&usbskelp->usbskel_mutex));
1460 1459
1461 1460 if (usbskelp->usbskel_pm) {
1462 1461 (void) usbskel_pm_busy_component(usbskelp);
1463 1462
1464 1463 mutex_enter(&usbskelp->usbskel_mutex);
1465 1464 if (usbskelp->usbskel_dev_state != USB_DEV_DISCONNECTED) {
1466 1465 int rval;
1467 1466
1468 1467 mutex_exit(&usbskelp->usbskel_mutex);
1469 1468
1470 1469 if ((rval = usb_handle_remote_wakeup(
1471 1470 usbskelp->usbskel_dip,
1472 1471 USB_REMOTE_WAKEUP_DISABLE)) !=
1473 1472 USB_SUCCESS) {
1474 1473 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1475 1474 "usbskel_destroy_power_mgmt: "
1476 1475 "Error disabling rmt wakeup: rval = %d",
1477 1476 rval);
1478 1477 }
1479 1478 } else {
1480 1479 mutex_exit(&usbskelp->usbskel_mutex);
1481 1480 }
1482 1481
1483 1482 /*
1484 1483 * Since remote wakeup is disabled now,
1485 1484 * no one can raise power
1486 1485 * and get to device once power is lowered here.
1487 1486 */
1488 1487 pm_lower_power(usbskelp->usbskel_dip, 0, USB_DEV_OS_PWR_OFF);
1489 1488 usbskel_pm_idle_component(usbskelp);
1490 1489 kmem_free(usbskelp->usbskel_pm, sizeof (usbskel_power_t));
1491 1490 usbskelp->usbskel_pm = NULL;
1492 1491 }
1493 1492 }
1494 1493 #endif
1495 1494
1496 1495
1497 1496 /*
1498 1497 * usbskel_serialize_access:
1499 1498 * Get the serial synchronization object before returning.
1500 1499 *
1501 1500 * Arguments:
1502 1501 * usbskelp - Pointer to usbskel state structure
1503 1502 * waitsig - Set to:
1504 1503 * USBSKEL_SER_SIG - to wait such that a signal can interrupt
1505 1504 * USBSKEL_SER_NOSIG - to wait such that a signal cannot interrupt
1506 1505 */
1507 1506 static int
1508 1507 usbskel_serialize_access(usbskel_state_t *usbskelp, boolean_t waitsig)
1509 1508 {
1510 1509 int rval = 1;
1511 1510
1512 1511 ASSERT(mutex_owned(&usbskelp->usbskel_mutex));
1513 1512
1514 1513 while (usbskelp->usbskel_serial_inuse) {
1515 1514 if (waitsig == USBSKEL_SER_SIG) {
1516 1515 rval = cv_wait_sig(&usbskelp->usbskel_serial_cv,
1517 1516 &usbskelp->usbskel_mutex);
1518 1517 } else {
1519 1518 cv_wait(&usbskelp->usbskel_serial_cv,
1520 1519 &usbskelp->usbskel_mutex);
1521 1520 }
1522 1521 }
1523 1522 usbskelp->usbskel_serial_inuse = B_TRUE;
1524 1523
1525 1524 return (rval);
1526 1525 }
1527 1526
1528 1527
1529 1528 /*
1530 1529 * usbskel_release_access:
1531 1530 * Release the serial synchronization object.
1532 1531 */
1533 1532 static void
1534 1533 usbskel_release_access(usbskel_state_t *usbskelp)
1535 1534 {
1536 1535 ASSERT(mutex_owned(&usbskelp->usbskel_mutex));
1537 1536 usbskelp->usbskel_serial_inuse = B_FALSE;
1538 1537 cv_broadcast(&usbskelp->usbskel_serial_cv);
1539 1538 }
1540 1539
1541 1540
1542 1541 /*
1543 1542 * usbskel_check_same_device:
1544 1543 * Check if the device connected to the port is the same as
1545 1544 * the previous device that was in the port. The previous device is
1546 1545 * represented by the dip on record for the port. Print a message
1547 1546 * if the device is different. Can block.
1548 1547 *
1549 1548 * return values:
1550 1549 * USB_SUCCESS: same device
1551 1550 * USB_INVALID_VERSION not same device
1552 1551 * USB_FAILURE: Failure processing request
1553 1552 */
1554 1553 static int
1555 1554 usbskel_check_same_device(usbskel_state_t *usbskelp)
1556 1555 {
1557 1556 usb_dev_descr_t *orig_usb_dev_descr;
1558 1557 usb_dev_descr_t usb_dev_descr;
1559 1558 mblk_t *pdata = NULL;
1560 1559 int rval;
1561 1560 char *buf;
1562 1561 usb_cr_t completion_reason;
1563 1562 usb_cb_flags_t cb_flags;
1564 1563 boolean_t match = B_TRUE;
1565 1564
1566 1565 usb_ctrl_setup_t setup = {
1567 1566 USB_DEV_REQ_DEV_TO_HOST | USB_DEV_REQ_TYPE_STANDARD |
1568 1567 USB_DEV_REQ_RCPT_DEV,
1569 1568 USB_REQ_GET_DESCR, /* bRequest */
1570 1569 USB_DESCR_TYPE_SETUP_DEV, /* wValue */
1571 1570 0, /* wIndex */
1572 1571 USB_DEV_DESCR_SIZE, /* wLength */
1573 1572 0 /* request attributes */
1574 1573 };
1575 1574
1576 1575 ASSERT(!mutex_owned(&usbskelp->usbskel_mutex));
1577 1576
1578 1577 orig_usb_dev_descr = usbskelp->usbskel_reg->dev_descr;
1579 1578
1580 1579 /* get the "new" device descriptor */
1581 1580 rval = usb_pipe_ctrl_xfer_wait(usbskelp->usbskel_reg->dev_default_ph,
1582 1581 &setup, &pdata, &completion_reason, &cb_flags, USB_FLAGS_SLEEP);
1583 1582
1584 1583 if (rval != USB_SUCCESS) {
1585 1584 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1586 1585 "usbskel_check_same_device: "
1587 1586 "getting device descriptor failed "
1588 1587 "rval=%d, cr=%d, cb=0x%x\n",
1589 1588 rval, completion_reason, cb_flags);
1590 1589 freemsg(pdata);
1591 1590
1592 1591 return (USB_FAILURE);
1593 1592 }
1594 1593
1595 1594 ASSERT(pdata != NULL);
1596 1595
1597 1596 (void) usb_parse_data("2cs4c3s4c", pdata->b_rptr,
1598 1597 MBLKL(pdata), &usb_dev_descr,
1599 1598 sizeof (usb_dev_descr_t));
1600 1599
1601 1600 freemsg(pdata);
1602 1601 pdata = NULL;
1603 1602
1604 1603 /* Always check the device descriptor length. */
1605 1604 if (usb_dev_descr.bLength != USB_DEV_DESCR_SIZE) {
1606 1605 match = B_FALSE;
1607 1606
1608 1607 /* Always check the device descriptor. */
1609 1608 } else if (bcmp(orig_usb_dev_descr,
1610 1609 (char *)&usb_dev_descr, USB_DEV_DESCR_SIZE) != 0) {
1611 1610 match = B_FALSE;
1612 1611 }
1613 1612
1614 1613 /* if requested & this device has a serial number check and compare */
1615 1614 if ((match == B_TRUE) &&
1616 1615 (usbskelp->usbskel_reg->dev_serial != NULL)) {
1617 1616 buf = kmem_alloc(USB_MAXSTRINGLEN, KM_SLEEP);
1618 1617 if (usb_get_string_descr(usbskelp->usbskel_dip, USB_LANG_ID,
1619 1618 usb_dev_descr.iSerialNumber, buf,
1620 1619 USB_MAXSTRINGLEN) == USB_SUCCESS) {
1621 1620 match =
1622 1621 (strcmp(buf,
1623 1622 usbskelp->usbskel_reg->dev_serial) == 0);
1624 1623 }
1625 1624 kmem_free(buf, USB_MAXSTRINGLEN);
1626 1625 }
1627 1626
1628 1627 if (match == B_FALSE) {
1629 1628 usbskel_log(usbskelp, USBSKEL_LOG_CONSOLE,
1630 1629 "Device is not identical to the "
1631 1630 "previous one this port.\n"
1632 1631 "Please disconnect and reconnect");
1633 1632
1634 1633 return (USB_INVALID_VERSION);
1635 1634 }
1636 1635
1637 1636 return (USB_SUCCESS);
1638 1637 }
1639 1638
1640 1639 /*
1641 1640 * usbskel_log:
1642 1641 * Switchable logging to logfile and screen.
1643 1642 *
1644 1643 * Arguments:
1645 1644 * usbskelp: usbskel state pointer.
1646 1645 * if NULL, driver name and instance won't print with the message
1647 1646 * msglevel:
1648 1647 * if USBSKEL_LOG_LOG, goes only to logfile.
1649 1648 * (usbskel_errlevel must be set to USBSKEL_LOG_LOG too.)
1650 1649 * if USBSKEL_LOG_CONSOLE, goes to both logfile and screen
1651 1650 * (usbskel_errlevel can be either value for this to work.)
1652 1651 * cmn_err_level: error level passed to cmn_err(9F)
1653 1652 * format and args: as you would call cmn_err, except without special
1654 1653 * first routing character.
1655 1654 *
1656 1655 * Do not call this in an interrupt context, since kmem_alloc can sleep.
1657 1656 */
1658 1657 static void
1659 1658 usbskel_log(usbskel_state_t *usbskelp, int msglevel, char *formatarg, ...)
1660 1659 {
1661 1660 va_list ap;
1662 1661
1663 1662 if (msglevel <= usbskel_errlevel) {
1664 1663 char *format;
1665 1664 int formatlen = strlen(formatarg) + 2; /* '!' and NULL char */
1666 1665 int devinst_start = 0;
1667 1666
1668 1667 /* Allocate extra room if driver name and instance is present */
1669 1668 if (usbskelp != NULL) {
1670 1669 formatlen += strlen(usbskelp->usbskel_devinst);
1671 1670 }
1672 1671
1673 1672 format = kmem_zalloc(formatlen, KM_SLEEP);
1674 1673
1675 1674 if (msglevel == USBSKEL_LOG_LOG) {
1676 1675 format[0] = '!';
1677 1676 devinst_start = 1;
1678 1677 }
1679 1678
1680 1679 if (usbskelp != NULL) {
1681 1680 (void) strcpy(&format[devinst_start],
1682 1681 usbskelp->usbskel_devinst);
1683 1682 }
1684 1683
1685 1684 va_start(ap, formatarg);
1686 1685 (void) strcat(format, formatarg);
1687 1686 vcmn_err(CE_CONT, format, ap);
1688 1687 va_end(ap);
1689 1688
1690 1689 kmem_free(format, formatlen);
1691 1690 }
1692 1691 }
↓ open down ↓ |
1499 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX