Changeset c3d926f in mainline for uspace/drv/bus/usb/xhci/hc.c


Ignore:
Timestamp:
2017-10-25T08:03:13Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a5b3de6
Parents:
0206d35
Message:

Big command refactoring. Unified and encapsulated command function API. Removed explicit heap command (de)allocation functions. Added three functions for (a)synchronous command issuing and neat inline macro with syntax sugar.

File:
1 edited

Legend:

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

    r0206d35 rc3d926f  
    600600        int err;
    601601        xhci_cmd_t cmd;
    602         xhci_cmd_init(&cmd);
    603 
    604         if ((err = xhci_send_enable_slot_command(hc, &cmd)) != EOK)
    605                 return err;
    606 
    607         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
    608                 return err;
    609 
    610         if (slot_id)
     602        xhci_cmd_init(&cmd, XHCI_CMD_ENABLE_SLOT);
     603
     604        if ((err = xhci_cmd_sync(hc, &cmd))) {
     605                goto end;
     606        }
     607
     608        if (slot_id) {
    611609                *slot_id = cmd.slot_id;
    612 
     610        }
     611
     612end:
    613613        xhci_cmd_fini(&cmd);
    614         return EOK;
     614        return err;
    615615}
    616616
     
    620620
    621621        int err;
    622         xhci_cmd_t cmd;
    623         xhci_cmd_init(&cmd);
    624 
    625         cmd.slot_id = slot_id;
    626 
    627         if ((err = xhci_send_disable_slot_command(hc, &cmd)) != EOK)
    628                 return err;
    629 
    630         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
    631                 return err;
    632 
    633         xhci_cmd_fini(&cmd);
     622        if ((err = xhci_cmd_sync_inline(hc, DISABLE_SLOT, .slot_id = slot_id))) {
     623                return err;
     624        }
     625
    634626        return EOK;
    635627}
     
    688680        xhci_setup_endpoint_context(ep0, &ictx->endpoint_ctx[0]);
    689681
    690         xhci_cmd_t cmd;
    691         xhci_cmd_init(&cmd);
    692 
    693         cmd.slot_id = dev->slot_id;
    694 
    695         if ((err = xhci_send_address_device_command(hc, &cmd, ictx)) != EOK)
    696                 goto err_cmd;
    697 
    698         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT)) != EOK)
    699                 goto err_cmd;
     682        /* Issue Address Device command. */
     683        if ((err = xhci_cmd_sync_inline(hc, ADDRESS_DEVICE, .slot_id = dev->slot_id, .input_ctx = ictx))) {
     684                goto err_dev_ctx;
     685        }
    700686
    701687        dev->base.address = XHCI_SLOT_DEVICE_ADDRESS(dev->dev_ctx->slot_ctx);
     
    707693        fibril_mutex_unlock(&dev->base.guard);
    708694
    709         xhci_cmd_fini(&cmd);
    710         free32(ictx);
    711         return EOK;
    712 
    713 err_cmd:
    714         xhci_cmd_fini(&cmd);
    715         free32(ictx);
     695        return EOK;
     696
    716697err_dev_ctx:
    717698        free32(dev->dev_ctx);
     
    728709        xhci_input_ctx_t *ictx;
    729710        if ((err = create_valid_input_ctx(&ictx))) {
    730                 goto err;
    731         }
    732 
     711                return err;
     712        }
    733713        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    734714
    735         xhci_cmd_t cmd;
    736         xhci_cmd_init(&cmd);
    737 
    738         cmd.slot_id = slot_id;
    739 
    740         if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
    741                 goto err_cmd;
    742         }
    743 
    744         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
    745                 goto err_cmd;
    746         }
    747 
    748         xhci_cmd_fini(&cmd);
    749 
    750         free32(ictx);
    751         return EOK;
    752 
    753 err_cmd:
    754         free32(ictx);
    755 err:
    756         return err;
     715        if ((err = xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx))) {
     716                return err;
     717        }
     718
     719        return EOK;
    757720}
    758721
     
    762725
    763726        /* Issue configure endpoint command (sec 4.3.5) with the DC flag. */
    764         xhci_cmd_t cmd;
    765         xhci_cmd_init(&cmd);
    766 
    767         cmd.slot_id = slot_id;
    768         cmd.deconfigure = true;
    769 
    770         if ((err = xhci_send_configure_endpoint_command(hc, &cmd, NULL))) {
    771                 return err;
    772         }
    773 
    774         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
    775                 return err;
    776         }
    777 
    778         xhci_cmd_fini(&cmd);
     727        if ((err = xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .deconfigure = true))) {
     728                return err;
     729        }
    779730
    780731        return EOK;
     
    788739        xhci_input_ctx_t *ictx;
    789740        if ((err = create_valid_input_ctx(&ictx))) {
    790                 goto err;
     741                return err;
    791742        }
    792743
    793744        XHCI_INPUT_CTRL_CTX_ADD_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    794745        memcpy(&ictx->endpoint_ctx[ep_idx], ep_ctx, sizeof(xhci_ep_ctx_t));
    795 
    796746        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    797747
    798         xhci_cmd_t cmd;
    799         xhci_cmd_init(&cmd);
    800 
    801         cmd.slot_id = slot_id;
    802 
    803         if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
    804                 goto err_cmd;
    805         }
    806 
    807         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
    808                 goto err_cmd;
    809         }
    810 
    811         xhci_cmd_fini(&cmd);
    812 
    813         free32(ictx);
    814         return EOK;
    815 
    816 err_cmd:
    817         free32(ictx);
    818 err:
    819         return err;
     748        if ((err = xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx))) {
     749                return err;
     750        }
     751
     752        return EOK;
    820753}
    821754
     
    827760        xhci_input_ctx_t *ictx;
    828761        if ((err = create_valid_input_ctx(&ictx))) {
    829                 goto err;
     762                return err;
    830763        }
    831764
    832765        XHCI_INPUT_CTRL_CTX_DROP_SET(ictx->ctrl_ctx, ep_idx + 1); /* Preceded by slot ctx */
    833 
    834766        // TODO: Set slot context and other flags. (probably forgot a lot of 'em)
    835767
    836         xhci_cmd_t cmd;
    837         xhci_cmd_init(&cmd);
    838 
    839         cmd.slot_id = slot_id;
    840 
    841         if ((err = xhci_send_configure_endpoint_command(hc, &cmd, ictx))) {
    842                 goto err_cmd;
    843         }
    844 
    845         if ((err = xhci_cmd_wait(&cmd, XHCI_DEFAULT_TIMEOUT))) {
    846                 goto err_cmd;
    847         }
    848 
    849         xhci_cmd_fini(&cmd);
    850 
    851         free32(ictx);
    852         return EOK;
    853 
    854 err_cmd:
    855         free32(ictx);
    856 err:
    857         return err;
     768        if ((err = xhci_cmd_sync_inline(hc, CONFIGURE_ENDPOINT, .slot_id = slot_id, .input_ctx = ictx))) {
     769                return err;
     770        }
     771
     772        return EOK;
    858773}
    859774
Note: See TracChangeset for help on using the changeset viewer.