Changeset 7e5a12b in mainline


Ignore:
Timestamp:
2018-01-19T17:57:13Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
69b2dfee
Parents:
2833bb4
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:57:06)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-19 17:57:13)
Message:

xhci: make enable/disable slot symmetric

Previously, device slot context was allocated inside address_device,
complicating error paths.

Location:
uspace/drv/bus/usb/xhci
Files:
3 edited

Legend:

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

    r2833bb4 r7e5a12b  
    6969 * @return Error code.
    7070 */
    71 static int address_device(xhci_bus_t *bus, xhci_device_t *dev)
     71static int address_device(xhci_device_t *dev)
    7272{
    7373        int err;
    7474
    7575        /* Enable new slot. */
    76         if ((err = hc_enable_slot(bus->hc, &dev->slot_id)) != EOK)
     76        if ((err = hc_enable_slot(dev)) != EOK)
    7777                return err;
    7878        usb_log_debug2("Obtained slot ID: %u.", dev->slot_id);
     
    100100        dev->base.endpoints[0] = NULL;
    101101err_slot:
    102         hc_disable_slot(bus->hc, dev);
     102        hc_disable_slot(dev);
    103103        return err;
    104104}
     
    193193        do {
    194194                /* Assign an address to the device */
    195                 err = address_device(bus, xhci_dev);
     195                err = address_device(xhci_dev);
    196196        } while (err == ESTALL && --retries > 0);
    197197
     
    253253        /* Disable the slot, dropping all endpoints. */
    254254        const uint32_t slot_id = xhci_dev->slot_id;
    255         if ((err = hc_disable_slot(bus->hc, xhci_dev))) {
     255        if ((err = hc_disable_slot(xhci_dev))) {
    256256                usb_log_warning("Failed to disable slot of device " XHCI_DEV_FMT ": %s",
    257257                    XHCI_DEV_ARGS(*xhci_dev), str_error(err));
  • uspace/drv/bus/usb/xhci/hc.c

    r2833bb4 r7e5a12b  
    714714
    715715/**
    716  * Issue an Enable Slot command, returning the obtained Slot ID.
    717  *
    718  * @param slot_id Pointer where to store the obtained Slot ID.
    719  */
    720 int hc_enable_slot(xhci_hc_t *hc, uint32_t *slot_id)
    721 {
    722         assert(hc);
    723 
     716 * Issue an Enable Slot command. Allocate memory for the slot and fill the
     717 * DCBAA with the newly created slot.
     718 */
     719int hc_enable_slot(xhci_device_t *dev)
     720{
    724721        int err;
     722        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
     723
     724        /* Prepare memory for the context */
     725        if ((err = dma_buffer_alloc(&dev->dev_ctx, sizeof(xhci_device_ctx_t))))
     726                return err;
     727        memset(dev->dev_ctx.virt, 0, sizeof(xhci_device_ctx_t));
     728
     729        /* Get the slot number */
    725730        xhci_cmd_t cmd;
    726731        xhci_cmd_init(&cmd, XHCI_CMD_ENABLE_SLOT);
    727732
    728         if ((err = xhci_cmd_sync(hc, &cmd))) {
    729                 goto end;
    730         }
    731 
    732         if (slot_id) {
    733                 *slot_id = cmd.slot_id;
    734         }
    735 
    736 end:
     733        err = xhci_cmd_sync(hc, &cmd);
     734
     735        /* Link them together */
     736        if (err == EOK) {
     737                dev->slot_id = cmd.slot_id;
     738                hc->dcbaa[dev->slot_id] = host2xhci(64, dev->dev_ctx.phys);
     739        }
     740
    737741        xhci_cmd_fini(&cmd);
    738742        return err;
     
    741745/**
    742746 * Issue a Disable Slot command for a slot occupied by device.
    743  *
    744  * Frees the device context
    745  */
    746 int hc_disable_slot(xhci_hc_t *hc, xhci_device_t *dev)
     747 * Frees the device context.
     748 */
     749int hc_disable_slot(xhci_device_t *dev)
    747750{
    748751        int err;
    749         assert(hc);
     752        xhci_hc_t * const hc = bus_to_hc(dev->base.bus);
    750753
    751754        if ((err = xhci_cmd_sync_inline(hc, DISABLE_SLOT, .slot_id = dev->slot_id))) {
     
    837840        }
    838841
    839         /* Setup and register device context */
    840         if (dma_buffer_alloc(&dev->dev_ctx, sizeof(xhci_device_ctx_t)))
    841                 goto err;
    842         memset(dev->dev_ctx.virt, 0, sizeof(xhci_device_ctx_t));
    843 
    844         hc->dcbaa[dev->slot_id] = host2xhci(64, dev->dev_ctx.phys);
    845 
    846842        /* Issue configure endpoint command (sec 4.3.5). */
    847843        dma_buffer_t ictx_dma_buf;
    848         if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf))) {
    849                 goto err_dev_ctx;
    850         }
     844        if ((err = create_configure_ep_input_ctx(dev, &ictx_dma_buf)))
     845                return err;
    851846        xhci_input_ctx_t *ictx = ictx_dma_buf.virt;
    852847
     
    856851
    857852        /* Issue Address Device command. */
    858         if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf))) {
    859                 goto err_dev_ctx;
    860         }
     853        if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx_dma_buf)))
     854                return err;
    861855
    862856        xhci_device_ctx_t *dev_ctx = dev->dev_ctx.virt;
     
    865859
    866860        return EOK;
    867 
    868 err_dev_ctx:
    869         hc->dcbaa[dev->slot_id] = 0;
    870         dma_buffer_free(&dev->dev_ctx);
    871 err:
    872         return err;
    873861}
    874862
  • uspace/drv/bus/usb/xhci/hc.h

    r2833bb4 r7e5a12b  
    121121void hc_ring_doorbell(xhci_hc_t *, unsigned, unsigned);
    122122
    123 int hc_enable_slot(xhci_hc_t *, uint32_t *);
    124 int hc_disable_slot(xhci_hc_t *, xhci_device_t *);
     123int hc_enable_slot(xhci_device_t *);
     124int hc_disable_slot(xhci_device_t *);
    125125int hc_address_device(xhci_device_t *, xhci_endpoint_t *);
    126126int hc_configure_device(xhci_device_t *);
Note: See TracChangeset for help on using the changeset viewer.