Changeset 0892663a in mainline for uspace/drv/bus/usb/uhci/hc.c


Ignore:
Timestamp:
2018-01-11T04:14:37Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9848c77
Parents:
bad4a05
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-11 03:59:03)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-11 04:14:37)
Message:

usbhost: device removal and off/onlining moved into the library

Also, it is just not possible to make generic transfer abortion. So the
current semantics of endpoint unregistering is also aborting the pending
transfer. As it is not yet implemented in XHCI, and the stub in UHCI is
missing the magic, it breaks offlining interrupt devices, such as mouse.

When finishing this commit, I came across the fact we need some more
synchronization above device. Guard can protect internal structures, but
it cannot synchronize multiple calls to offline, or offline & removal
between each other - they both need to allow driver to unregister
endpoints, and as such must release the guard.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/hc.c

    rbad4a05 r0892663a  
    321321}
    322322
    323 static int device_online(device_t *device)
    324 {
    325         int err;
    326         hc_t *instance = bus_to_hc(device->bus);
    327         assert(instance);
    328 
    329         /* Allow creation of new endpoints and transfers. */
    330         usb_log_info("Device(%d): Going online.", device->address);
    331         fibril_mutex_lock(&device->guard);
    332         device->online = true;
    333         fibril_mutex_unlock(&device->guard);
    334 
    335         if ((err = ddf_fun_online(device->fun))) {
    336                 return err;
    337         }
    338 
    339         return EOK;
    340 }
    341 
    342 static int device_offline(device_t *device)
    343 {
    344         int err;
    345         hc_t *instance = bus_to_hc(device->bus);
    346         assert(instance);
    347 
    348         /* Tear down all drivers working with the device. */
    349         if ((err = ddf_fun_offline(device->fun))) {
    350                 return err;
    351         }
    352 
    353         /* At this point, all drivers are assumed to have already terminated
    354          * in a consistent way. The following code just cleans up hanging
    355          * transfers if there are any. */
    356 
    357         /* Block creation of new endpoints and transfers. */
    358         usb_log_info("Device(%d): Going offline.", device->address);
    359         fibril_mutex_lock(&device->guard);
    360         device->online = false;
    361         fibril_mutex_unlock(&device->guard);
    362 
    363         /* Abort all transfers to all endpoints. */
    364         transfer_list_abort_device(&instance->transfers_interrupt, device->address);
    365         transfer_list_abort_device(&instance->transfers_control_slow, device->address);
    366         transfer_list_abort_device(&instance->transfers_control_full, device->address);
    367         transfer_list_abort_device(&instance->transfers_bulk_full, device->address);
    368 
    369         return EOK;
     323static void endpoint_unregister(endpoint_t *ep)
     324{
     325        usb2_bus_ops.endpoint_unregister(ep);
     326
     327        fibril_mutex_lock(&ep->guard);
     328        if (ep->active_batch) {
     329                uhci_transfer_batch_t *ub = uhci_transfer_batch_get(ep->active_batch);
     330                uhci_transfer_batch_abort(ub);
     331
     332                assert(ep->active_batch == NULL);
     333        }
     334        fibril_mutex_unlock(&ep->guard);
    370335}
    371336
     
    379344        .status = hc_status,
    380345
     346        .endpoint_unregister = endpoint_unregister,
    381347        .endpoint_count_bw = bandwidth_count_usb11,
     348
    382349        .batch_create = create_transfer_batch,
    383350        .batch_schedule = hc_schedule,
    384351        .batch_destroy = destroy_transfer_batch,
    385 
    386         .device_online = device_online,
    387         .device_offline = device_offline,
    388352};
    389353
     
    522486static int hc_schedule(usb_transfer_batch_t *batch)
    523487{
     488        assert(batch);
    524489        hc_t *instance = bus_to_hc(endpoint_get_bus(batch->ep));
    525         assert(batch);
    526490
    527491        if (batch->target.address == uhci_rh_get_address(&instance->rh))
Note: See TracChangeset for help on using the changeset viewer.