Changeset 40a3bfa in mainline for uspace/drv/bus/usb/xhci/bus.c


Ignore:
Timestamp:
2017-10-28T11:25:11Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d46ceb2b
Parents:
58ac3ec
Message:

Refactoring. Moved a lot of device deallocation from root hub to bus. Also zeroing DCBAA to avoid assertion fails upon reconnection. Temporarily disabled freeing endpoint data structures due to suspected memory corruption.

File:
1 edited

Legend:

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

    r58ac3ec r40a3bfa  
    185185int xhci_bus_remove_device(xhci_bus_t *bus, xhci_hc_t *hc, device_t *dev)
    186186{
     187        int err;
    187188        xhci_device_t *xhci_dev = xhci_device_get(dev);
     189
     190        /* Block creation of new endpoints and transfers. */
     191        usb_log_debug2("Device '%s' going offline.", ddf_fun_get_name(dev->fun));
     192        fibril_mutex_lock(&dev->guard);
     193        xhci_dev->online = false;
     194        fibril_mutex_unlock(&dev->guard);
     195
     196        /* Abort running transfers. */
     197        usb_log_debug2("Aborting all active transfers to '%s'.", ddf_fun_get_name(dev->fun));
     198        for (size_t i = 0; i < ARRAY_SIZE(xhci_dev->endpoints); ++i) {
     199                xhci_endpoint_t *ep = xhci_dev->endpoints[i];
     200                if (!ep || !ep->base.active)
     201                        continue;
     202
     203                /* FIXME: This is racy. */
     204                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),
     209                            str_error(err));
     210                }
     211        }
     212
     213        /* TODO: Figure out how to handle errors here. So far, they are reported and skipped. */
     214
     215        /* Make DDF (and all drivers) forget about the device. */
     216        if ((err = ddf_fun_unbind(dev->fun))) {
     217                usb_log_warning("Failed to unbind DDF function of detached device '%s': %s",
     218                    ddf_fun_get_name(dev->fun), str_error(err));
     219        }
     220
     221        /* Deconfigure device if it's still attached. */
     222        if (!xhci_dev->detached) {
     223                if ((err = hc_deconfigure_device(hc, xhci_dev->slot_id))) {
     224                        usb_log_warning("Failed to deconfigure detached device '%s': %s",
     225                            ddf_fun_get_name(dev->fun), str_error(err));
     226                }
     227        }
    188228
    189229        /* Unregister remaining endpoints. */
     
    192232                        continue;
    193233
    194                 const int err = unregister_endpoint(&bus->base, &xhci_dev->endpoints[i]->base);
    195                 if (err)
     234                if ((err = unregister_endpoint(&bus->base, &xhci_dev->endpoints[i]->base))) {
    196235                        usb_log_warning("Failed to unregister EP (%u:%u): %s", dev->address, i, str_error(err));
     236                }
    197237        }
    198238
    199239        // XXX: Ugly here. Move to device_destroy at endpoint.c?
     240        if ((err = hc_disable_slot(hc, xhci_dev->slot_id))) {
     241                usb_log_warning("Failed to disable slot %d for device '%s': %s",
     242                    xhci_dev->slot_id, ddf_fun_get_name(dev->fun), str_error(err));
     243        }
     244
    200245        free32(xhci_dev->dev_ctx);
    201246        hc->dcbaa[xhci_dev->slot_id] = 0;
     247
     248        bus->devices_by_slot[xhci_dev->slot_id] = NULL;
     249
    202250        return EOK;
    203251}
     
    305353        /* Tear down TRB ring / PSA. */
    306354        /* TODO: Make this method "noexcept" */
    307         if ((err = xhci_endpoint_free_transfer_ds(ep))) {
     355        /* FIXME: There is some memory corruption going on, causing this to crash. */
     356        /*if ((err = xhci_endpoint_free_transfer_ds(ep))) {
    308357                usb_log_error("Failed to free resources of an endpoint.");
    309         }
     358        }*/
    310359
    311360        return EOK;
Note: See TracChangeset for help on using the changeset viewer.