usb_ia.c revision 193974072f41a843678abf5f61979c748687e66b
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * CDDL HEADER START
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * The contents of this file are subject to the terms of the
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Common Development and Distribution License (the "License").
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * You may not use this file except in compliance with the License.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * See the License for the specific language governing permissions
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * and limitations under the License.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * When distributing Covered Code, include this CDDL HEADER in each
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * If applicable, add the following below this CDDL HEADER, with the
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * fields enclosed by brackets "[]" replaced with your own identifying
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * information: Portions Copyright [yyyy] [name of copyright owner]
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * CDDL HEADER END
112116d842e816e29d26a8fe28ed25d201063169fb * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Use is subject to license terms.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb interface association driver
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * this driver attempts to the interface association node and
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * creates/manages child nodes for the included interfaces.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* Debugging support */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * autoconfiguration data and routines.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc void *, void **);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* other routines */
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void usb_ia_create_pm_components(dev_info_t *, usb_ia_t *);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ddi_ctl_enum_t, void *, void *);
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic int usb_ia_restore_device_state(dev_info_t *, usb_ia_t *);
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void usb_ia_event_cb(dev_info_t *, ddi_eventcookie_t, void *, void *);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* prototypes */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Busops vector
d73ae94e59c019f5cc3221ee0a0012d02091b40egc 0, /* refcnt */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc &mod_driverops, /* Type of module. This one is a driver */
77e515715b61e28fcf0c3f30936492888cecfd8bgongtian zhao - Sun Microsystems - Beijing China "USB Interface Association Driver", /* Name of the module. */
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void *usb_ia_statep;
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * event definition
d73ae94e59c019f5cc3221ee0a0012d02091b40egc {USBA_EVENT_TAG_HOT_REMOVAL, DDI_DEVI_REMOVE_EVENT, EPL_KERNEL,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc {USBA_EVENT_TAG_HOT_INSERTION, DDI_DEVI_INSERT_EVENT, EPL_KERNEL,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc {USBA_EVENT_TAG_POST_RESUME, USBA_POST_RESUME_EVENT, EPL_KERNEL,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc {USBA_EVENT_TAG_PRE_SUSPEND, USBA_PRE_SUSPEND_EVENT, EPL_KERNEL,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (sizeof (usb_ia_ndi_event_defs) / sizeof (ndi_event_definition_t))
d73ae94e59c019f5cc3221ee0a0012d02091b40egc NDI_EVENTS_REV1, USB_IA_N_NDI_EVENTS, usb_ia_ndi_event_defs};
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * standard driver entry points
d73ae94e59c019f5cc3221ee0a0012d02091b40egc rval = ddi_soft_state_init(&usb_ia_statep, sizeof (struct usb_ia),
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (rval != 0) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/*ARGSUSED*/
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * child post attach/detach notification
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_post_attach(usb_ia_t *usb_ia, uint8_t ifno, struct attachspec *as)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_post_attach: ifno = %d result = %d", ifno, as->result);
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_post_detach(usb_ia_t *usb_ia, uint8_t ifno, struct detachspec *ds)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_post_detach: ifno = %d result = %d", ifno, ds->result);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * bus ctl support. we handle notifications here and the
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * rest goes up to root hub/hcd
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/*ARGSUSED*/
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usba_device_t *hub_usba_device = usba_get_usba_device(rdip);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc dev_info_t *root_hub_dip = hub_usba_device->usb_root_hub_dip;
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_bus_ctl:\n\t"
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "dip = 0x%p, rdip = 0x%p, op = 0x%x, arg = 0x%p",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc switch (op) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* nothing to do basically */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "DDI_PRE DDI_CTLOPS_ATTACH");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* nothing to do basically */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "DDI_PRE DDI_CTLOPS_DETACH");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* pass to root hub to handle */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc return (usba_bus_ctl(root_hub_dip, rdip, op, arg, result));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * bus enumeration entry points
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_bus_config(dev_info_t *dip, uint_t flag, ddi_bus_config_op_t op,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* enumerate each interface below us */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc rval = ndi_busop_bus_config(dip, flag, op, arg, child, 0);
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_bus_unconfig(dev_info_t *dip, uint_t flag, ddi_bus_config_op_t op,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * first offline and if offlining successful, then
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * remove children
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* update children's list */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* now search if this dip still exists */
112116d842e816e29d26a8fe28ed25d201063169fb for (cdip = ddi_get_child(dip); cdip && (cdip != mdip); )
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* we lost the dip on this interface */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc } else if (cdip) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * keep in DS_INITALIZED to prevent parent
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * from detaching
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* power entry point */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* ARGSUSED */
112116d842e816e29d26a8fe28ed25d201063169fb "usb_ia_power: Begin: usb_ia = %p, level = %d",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* check if we are transitioning to a legal power level */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_power: illegal power level = %d "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * attach/resume entry point
d73ae94e59c019f5cc3221ee0a0012d02091b40egc switch (cmd) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Allocate soft state and initialize
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (ddi_soft_state_zalloc(usb_ia_statep, instance) != DDI_SUCCESS) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* allocate handle for logging of messages */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usb_ia->ia_first_if = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "interface-association property failed");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* attach client driver to USBA */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (usb_client_attach(dip, USBDRV_VERSION, 0) != USB_SUCCESS) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_client_attach failed");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (usb_get_dev_data(dip, &usb_ia->ia_dev_data, USB_PARSE_LVL_NONE,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_get_dev_data failed");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (ddi_create_minor_node(dip, "usb_ia", S_IFCHR, instance,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "cannot create devctl minor node");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * allocate array for keeping track of child dips
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usb_ia->ia_cd_list_length = size = (sizeof (dev_info_t *)) * n_ifs;
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usb_ia->ia_child_events = kmem_zalloc(sizeof (uint8_t) * n_ifs,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Event handling: definition and registration
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * get event handle for events that we have defined
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (void) ndi_event_alloc_hdl(dip, 0, &usb_ia->ia_ndi_event_hdl,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* bind event set to the handle */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (ndi_event_bind_set(usb_ia->ia_ndi_event_hdl, &usb_ia_ndi_events,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_attach: binding event set failed");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * now create components to power manage this device
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * before attaching children
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* event registration for events from our parent */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usba_common_register_events(dip, n_ifs, usb_ia_event_cb);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L2(DPRINT_MASK_ATTA, NULL, "usb_ia%d cannot attach",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/* detach or suspend this instance */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc switch (cmd) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* nothing to do */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* NOTREACHED */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb_ia_cleanup:
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * cleanup usb_ia and deallocate. this function is called for
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * handling attach failures and detaching including dynamic
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * reconfiguration
d73ae94e59c019f5cc3221ee0a0012d02091b40egc/*ARGSUSED*/
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_cleanup:");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * deallocate events, if events are still registered
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * (ie. children still attached) then we have to fail the detach
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (ndi_event_free_hdl(usb_ia->ia_ndi_event_hdl) != NDI_SUCCESS)) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_cleanup: ndi_event_free_hdl failed");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Disable the event callbacks, after this point, event
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * callbacks will never get called. Note we shouldn't hold
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * mutex while unregistering events because there may be a
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * competing event callback thread. Event callbacks are done
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * with ndi mutex held and this can cause a potential deadlock.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Note that cleanup can't fail after deregistration of events.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc usba_common_unregister_events(usb_ia->ia_dip, usb_ia->ia_n_ifs);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if ((iapm) && (usb_ia->ia_dev_state != USB_DEV_DISCONNECTED)) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* First bring the device to full power */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_cleanup: disable remote "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (void) pm_lower_power(usb_ia->ia_dip, 0, USB_DEV_OS_PWR_OFF);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* free children list */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ddi_soft_state_free(usb_ia_statep, ddi_get_instance(dip));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb_ia_create_children:
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_attach_child_drivers: port = %d, address = %d",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * create all children if not already present
d73ae94e59c019f5cc3221ee0a0012d02091b40egc for (i = 0; i < n_ifs; i++) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc cdip = usba_ready_interface_node(usb_ia->ia_dip, first_if + i);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * event support
d73ae94e59c019f5cc3221ee0a0012d02091b40egc dev_info_t *rdip, char *eventname, ddi_eventcookie_t *cookie)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_busop_get_eventcookie: dip=0x%p, rdip=0x%p, "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L3(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "(dip=%s%d rdip=%s%d)",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* return event cookie, iblock cookie, and level */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc return (ndi_event_retrieve_cookie(usb_ia->ia_ndi_event_hdl,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (ifno < 0) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_busop_add_eventcall: dip=0x%p, rdip=0x%p "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "cookie=0x%p, cb=0x%p, arg=0x%p",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (void *)dip, (void *)rdip, (void *)cookie, (void *)callback, arg);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L3(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "(dip=%s%d rdip=%s%d event=%s)",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ndi_event_cookie_to_name(usb_ia->ia_ndi_event_hdl, cookie));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* Set flag on children registering events */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc switch (ndi_event_cookie_to_tag(usb_ia->ia_ndi_event_hdl, cookie)) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* add callback (perform registration) */
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_busop_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ndi_event_callbacks_t *cb = (ndi_event_callbacks_t *)cb_id;
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_busop_remove_eventcall: dip=0x%p, rdip=0x%p "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L3(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "(dip=%s%d rdip=%s%d event=%s)",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* remove event registration from our event set */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc return (ndi_event_remove_callback(usb_ia->ia_ndi_event_hdl, cb_id));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_busop_post_event: dip=0x%p, rdip=0x%p "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "cookie=0x%p, impl=0x%p",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc (void *)dip, (void *)rdip, (void *)cookie, bus_impldata);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L3(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "(dip=%s%d rdip=%s%d event=%s)",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ndi_event_cookie_to_name(usb_ia->ia_ndi_event_hdl, cookie));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* post event to all children registered for this event */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc return (ndi_event_run_callbacks(usb_ia->ia_ndi_event_hdl, rdip,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb_ia_restore_device_state
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * set the original configuration of the device
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_restore_device_state(dev_info_t *dip, usb_ia_t *usb_ia)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
112116d842e816e29d26a8fe28ed25d201063169fb "usb_ia_restore_device_state: usb_ia = %p", (void *)usb_ia);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* First bring the device to full power */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (usb_check_same_device(dip, usb_ia->ia_log_handle, USB_LOG_L0,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc DPRINT_MASK_EVENTS, USB_CHK_VIDPID, NULL) != USB_SUCCESS) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* change the device state from suspended to disconnected */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * if the device had remote wakeup earlier,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * enable it again
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb_ia_event_cb()
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * handle disconnect and connect events
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_event_cb(dev_info_t *dip, ddi_eventcookie_t cookie,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ddi_eventcookie_t rm_cookie, ins_cookie, suspend_cookie, resume_cookie;
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_event_cb: dip=0x%p, cookie=0x%p, "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "arg=0x%p, impl=0x%p",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc USB_DPRINTF_L4(DPRINT_MASK_EVENTS, usb_ia->ia_log_handle,
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "(dip=%s%d event=%s)",
d73ae94e59c019f5cc3221ee0a0012d02091b40egc ndi_event_cookie_to_name(usb_ia->ia_ndi_event_hdl, cookie));
d73ae94e59c019f5cc3221ee0a0012d02091b40egc switch (tag) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_event_cb: Device already disconnected");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* we are disconnected so set our state now */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* pass disconnect event to all the children */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* set our state *after* suspending children */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* pass pre_suspend event to all the children */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (usb_ia_restore_device_state(dip, usb_ia) == USB_SUCCESS) {
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Check to see if this child has missed the disconnect
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * event before it registered for event cb
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* post the missed disconnect */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* pass reconnect event to all the children */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * Check to see if this child has missed the pre-suspend
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * event before it registered for event cb
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* post the missed pre-suspend event */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* pass post_resume event to all the children */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * create the pm components required for power management
d73ae94e59c019f5cc3221ee0a0012d02091b40egcstatic void
d73ae94e59c019f5cc3221ee0a0012d02091b40egcusb_ia_create_pm_components(dev_info_t *dip, usb_ia_t *usb_ia)
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_create_pm_components: Begin");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc /* Allocate the PM state structure */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc iapm = kmem_zalloc(sizeof (usb_common_power_t), KM_SLEEP);
d73ae94e59c019f5cc3221ee0a0012d02091b40egc iapm->uc_pm_capabilities = 0; /* XXXX should this be 0?? */
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * By not enabling parental notification, PM enforces
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * "strict parental dependency" meaning, usb_ia won't
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * power off until any of its children are in full power.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * there are 3 scenarios:
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * 1. a well behaved device should have remote wakeup
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * at interface and device level. If the interface
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * wakes up, usb_ia will wake up
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * 2. if the device doesn't have remote wake up and
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * the interface has, PM will still work, ie.
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * the interfaces wakes up and usb_ia wakes up
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * 3. if neither the interface nor device has remote
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * wakeup, the interface will wake up when it is opened
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * and goes to sleep after being closed for a while
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * In this case usb_ia should also go to sleep shortly
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * thereafter
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * In all scenarios it doesn't really matter whether
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * remote wakeup at the device level is enabled or not
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * but we do it anyways
d73ae94e59c019f5cc3221ee0a0012d02091b40egc if (usb_handle_remote_wakeup(dip, USB_REMOTE_WAKEUP_ENABLE) ==
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_create_pm_components: "
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "Remote Wakeup Enabled");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc "usb_ia_create_pm_components: End");
d73ae94e59c019f5cc3221ee0a0012d02091b40egc * usb_ia_obtain_state: