Changeset 9620a54 in mainline for uspace/drv/bus/usb/xhci/bus.c


Ignore:
Timestamp:
2017-10-29T10:51:59Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d33dc780
Parents:
62f8025
Message:

Small changes. Temporarily fixed no device problem for endpoint logging. Added similar macro for device logging. Changed log messages to adopt these macros. TRB rings can be freed again. Made ring finalizers noexcept. Upon detach, the entire slot is disabled prior to unregistering endpoints in order to prevent invalid HC commands. Removed active endpoints count from XHCI device. Device context is freed in HC, so DCBAA is not touched from anywhere else.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/bus.c

    r62f8025 r9620a54  
    121121        endpoint_del_ref(ep0_base);
    122122err_slot:
    123         hc_disable_slot(hc, dev->slot_id);
     123        hc_disable_slot(hc, dev);
    124124        return err;
    125125}
     
    189189
    190190        /* Block creation of new endpoints and transfers. */
    191         usb_log_debug2("Device '%s' going offline.", ddf_fun_get_name(dev->fun));
     191        usb_log_debug2("Device " XHCI_DEV_FMT " going offline.", XHCI_DEV_ARGS(*xhci_dev));
    192192        fibril_mutex_lock(&dev->guard);
    193193        xhci_dev->online = false;
     
    195195
    196196        /* Abort running transfers. */
    197         usb_log_debug2("Aborting all active transfers to '%s'.", ddf_fun_get_name(dev->fun));
     197        usb_log_debug2("Aborting all active transfers to device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*xhci_dev));
    198198        for (size_t i = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) {
    199199                xhci_endpoint_t *ep = xhci_dev->endpoints[i];
     
    203203                /* FIXME: This is racy. */
    204204                if ((err = xhci_transfer_abort(&ep->active_transfer))) {
    205                         usb_log_warning("Failed to abort active %s transfer to "
    206                             " endpoint %d of detached device '%s': %s",
    207                             usb_str_transfer_type(ep->base.transfer_type),
    208                             ep->base.endpoint, ddf_fun_get_name(dev->fun),
     205                        usb_log_warning("Failed to abort active transfer to "
     206                            " endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep),
    209207                            str_error(err));
    210208                }
     
    215213        /* Make DDF (and all drivers) forget about the device. */
    216214        if ((err = ddf_fun_unbind(dev->fun))) {
    217                 usb_log_warning("Failed to unbind DDF function of device '%s': %s",
    218                     ddf_fun_get_name(dev->fun), str_error(err));
    219         }
    220 
    221         /* Unregister remaining endpoints. */
     215                usb_log_warning("Failed to unbind DDF function of device " XHCI_DEV_FMT ": %s",
     216                    XHCI_DEV_ARGS(*xhci_dev), str_error(err));
     217        }
     218
     219        /* Disable the slot, dropping all endpoints. */
     220        const uint32_t slot_id = xhci_dev->slot_id;
     221        if ((err = hc_disable_slot(hc, xhci_dev))) {
     222                usb_log_warning("Failed to disable slot of device " XHCI_DEV_FMT ": %s",
     223                    XHCI_DEV_ARGS(*xhci_dev), str_error(err));
     224        }
     225
     226        bus->devices_by_slot[slot_id] = NULL;
     227
     228        /* Unregister remaining endpoints, freeing memory. */
    222229        for (unsigned i = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) {
    223230                if (!xhci_dev->endpoints[i])
     
    225232
    226233                if ((err = unregister_endpoint(&bus->base, &xhci_dev->endpoints[i]->base))) {
    227                         usb_log_warning("Failed to unregister EP (%u:%u): %s", dev->address, i, str_error(err));
     234                        usb_log_warning("Failed to unregister endpoint " XHCI_EP_FMT ": %s",
     235                            XHCI_EP_ARGS(*xhci_dev->endpoints[i]), str_error(err));
    228236                }
    229237        }
    230 
    231         // XXX: Ugly here. Move to device_destroy at endpoint.c?
    232         if ((err = hc_disable_slot(hc, xhci_dev->slot_id))) {
    233                 usb_log_warning("Failed to disable slot %d for device '%s': %s",
    234                     xhci_dev->slot_id, ddf_fun_get_name(dev->fun), str_error(err));
    235         }
    236 
    237         free32(xhci_dev->dev_ctx);
    238         hc->dcbaa[xhci_dev->slot_id] = 0;
    239 
    240         bus->devices_by_slot[xhci_dev->slot_id] = NULL;
    241238
    242239        /* Destroy DDF device. */
     
    291288        /* Transition the device from the Addressed to the Configured state. */
    292289        if ((err = hc_configure_device(hc, dev->slot_id))) {
    293                 usb_log_warning("Failed to configure device %d.", dev_base->address);
     290                usb_log_warning("Failed to configure device " XHCI_DEV_FMT ".", XHCI_DEV_ARGS(*dev));
    294291        }
    295292
    296293        /* Block creation of new endpoints and transfers. */
    297         usb_log_debug2("Device '%s' going online.", ddf_fun_get_name(dev_base->fun));
     294        usb_log_debug2("Device " XHCI_DEV_FMT " going online.", XHCI_DEV_ARGS(*dev));
    298295        fibril_mutex_lock(&dev_base->guard);
    299296        dev->online = true;
     
    326323
    327324        /* Block creation of new endpoints and transfers. */
    328         usb_log_debug2("Device '%s' going offline.", ddf_fun_get_name(dev_base->fun));
     325        usb_log_debug2("Device " XHCI_DEV_FMT " going offline.", XHCI_DEV_ARGS(*dev));
    329326        fibril_mutex_lock(&dev_base->guard);
    330327        dev->online = false;
     
    347344        /* Issue one HC command to simultaneously drop all endpoints except zero. */
    348345        if ((err = hc_deconfigure_device(hc, dev->slot_id))) {
    349                 usb_log_warning("Failed to deconfigure device %d.", dev_base->address);
     346                usb_log_warning("Failed to deconfigure device " XHCI_DEV_FMT ".",
     347                    XHCI_DEV_ARGS(*dev));
    350348        }
    351349
    352350        /* Tear down TRB ring / PSA. */
    353         /* TODO: Make this method "noexcept" */
    354351        for (unsigned i = 1; i < ARRAY_SIZE(endpoints); ++i) {
    355352                if (!endpoints[i])
    356353                        continue;
    357354
    358                 if ((err = xhci_endpoint_free_transfer_ds(endpoints[i]))) {
    359                         usb_log_warning("Failed to free resources of EP (%u:%u): %s", dev_base->address, i, str_error(err));
    360                 }
     355                xhci_endpoint_free_transfer_ds(endpoints[i]);
    361356        }
    362357
     
    404399                goto err_prepared;
    405400
    406         usb_log_info("Endpoint(%d:%d) registered to XHCI bus.", dev->base.address, ep->base.endpoint);
     401        usb_log_info("Endpoint " XHCI_EP_FMT " registered to XHCI bus.", XHCI_EP_ARGS(*ep));
    407402
    408403        xhci_ep_ctx_t ep_ctx;
     
    428423        xhci_device_t *dev = xhci_device_get(ep_base->device);
    429424
    430         usb_log_info("Endpoint(%d:%d) unregistered from XHCI bus.", dev->base.address, ep->base.endpoint);
     425        usb_log_info("Endpoint " XHCI_EP_FMT " unregistered from XHCI bus.", XHCI_EP_ARGS(*ep));
    431426
    432427        xhci_device_remove_endpoint(ep);
    433428
    434         /* Drop the endpoint. */
    435         if ((err = hc_drop_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep)))) {
    436                 usb_log_error("Failed to drop endpoint: %s", str_error(err));
     429        /* If device slot is still available, drop the endpoint. */
     430        if (dev->slot_id) {
     431                if ((err = hc_drop_endpoint(bus->hc, dev->slot_id, xhci_endpoint_index(ep)))) {
     432                        usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err));
     433                }
     434        } else {
     435                usb_log_debug("Not going to drop endpoint " XHCI_EP_FMT " because"
     436                    " the slot has already been disabled.", XHCI_EP_ARGS(*ep));
    437437        }
    438438
    439439        /* Tear down TRB ring / PSA. */
    440         /* TODO: Make this method "noexcept" */
    441         if ((err = xhci_endpoint_free_transfer_ds(ep))) {
    442                 usb_log_error("Failed to free resources of an endpoint.");
    443         }
     440        xhci_endpoint_free_transfer_ds(ep);
    444441
    445442        return EOK;
Note: See TracChangeset for help on using the changeset viewer.