Changeset 1af4c00 in mainline


Ignore:
Timestamp:
2018-01-17T13:28:34Z (6 years ago)
Author:
Salmelu <salmelu@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4cc0c2e0
Parents:
61e27e80
Message:

xhci: fixed transition to and from streams

Added remove streams function to transition the endpoint back to single ring no streams mode.
Requesting streams now stops the endpoint, clears the ring and executes update endpoint command.

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

Legend:

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

    r61e27e80 r1af4c00  
    4747
    4848static int alloc_transfer_ds(xhci_endpoint_t *);
    49 static void free_transfer_ds(xhci_endpoint_t *);
    5049
    5150/**
     
    121120        assert(xhci_ep);
    122121
    123         free_transfer_ds(xhci_ep);
     122        xhci_endpoint_free_transfer_ds(xhci_ep);
    124123
    125124        // TODO: Something missed?
     
    156155}
    157156
    158 /** Allocate transfer data structures for XHCI endpoint.
     157/** Allocate transfer data structures for XHCI endpoint not using streams.
    159158 * @param[in] xhci_ep XHCI endpoint to allocate data structures for.
    160159 *
     
    166165        usb_log_debug2("Allocating main transfer ring for endpoint " XHCI_EP_FMT, XHCI_EP_ARGS(*xhci_ep));
    167166
    168         xhci_ep->primary_stream_ctx_array = NULL;
     167        xhci_ep->primary_stream_data_array = NULL;
     168        xhci_ep->primary_stream_data_size = 0;
    169169
    170170        int err;
     
    186186 * @param[in] xhci_ep XHCI endpoint to free data structures for.
    187187 */
    188 static void free_transfer_ds(xhci_endpoint_t *xhci_ep)
     188void xhci_endpoint_free_transfer_ds(xhci_endpoint_t *xhci_ep)
    189189{
    190190        if (xhci_ep->primary_stream_data_size) {
  • uspace/drv/bus/usb/xhci/endpoint.h

    r61e27e80 r1af4c00  
    135135void xhci_endpoint_fini(xhci_endpoint_t *);
    136136
     137void xhci_endpoint_free_transfer_ds(xhci_endpoint_t *xhci_ep);
     138
    137139uint8_t xhci_endpoint_dci(xhci_endpoint_t *);
    138140uint8_t xhci_endpoint_index(xhci_endpoint_t *);
  • uspace/drv/bus/usb/xhci/streams.c

    r61e27e80 r1af4c00  
    110110        dma_buffer_free(&xhci_ep->primary_stream_ctx_dma);
    111111        free(xhci_ep->primary_stream_data_array);
     112
     113        xhci_ep->primary_stream_data_array = NULL;
     114        xhci_ep->primary_stream_data_size = 0;
    112115}
    113116
     
    312315}
    313316
     317/** Cancels streams and reconfigures endpoint back to single ring no stream endpoint.
     318 * @param[in] hc Host controller of the endpoint.
     319 * @param[in] dev Used device.
     320 * @param[in] xhci_ep Associated XHCI bulk endpoint.
     321 */
     322int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *xhci_ep)
     323{
     324        if (!xhci_ep->primary_stream_data_size) {
     325                usb_log_warning("There are no streams enabled on the endpoint, doing nothing.");
     326                return EOK;
     327        }
     328
     329        hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     330        xhci_endpoint_free_transfer_ds(xhci_ep);
     331
     332        /* Streams are now removed, proceed with reconfiguring endpoint. */
     333        int err;
     334        if ((err = xhci_trb_ring_init(&xhci_ep->ring))) {
     335                usb_log_error("Failed to initialize a transfer ring.");
     336                return err;
     337        }
     338
     339        xhci_ep_ctx_t ep_ctx;
     340        memset(&ep_ctx, 0, sizeof(ep_ctx));
     341        xhci_setup_endpoint_context(xhci_ep, &ep_ctx);
     342        return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     343}
     344
    314345/** Initialize, setup and register primary streams.
    315346 * @param[in] hc Host controller of the endpoint.
     
    325356                return err;
    326357        }
     358
     359        /*
     360         * We have passed the checks.
     361         * Stop the endpoint, destroy the ring, and transition to streams.
     362         */
     363        hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     364        xhci_endpoint_free_transfer_ds(xhci_ep);
    327365
    328366        err = initialize_primary_structures(xhci_ep, count);
     
    343381        setup_stream_context(xhci_ep, &ep_ctx, pstreams, 1);
    344382
    345         // FIXME: do we add endpoint? do we need to destroy previous configuration?
    346         return hc_add_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     383        return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
    347384}
    348385
     
    393430        }
    394431
     432        /*
     433         * We have passed all checks.
     434         * Stop the endpoint, destroy the ring, and transition to streams.
     435         */
     436        hc_stop_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep));
     437        xhci_endpoint_free_transfer_ds(xhci_ep);
     438
    395439        err = initialize_primary_structures(xhci_ep, count);
    396440        if (err) {
     
    411455        setup_stream_context(xhci_ep, &ep_ctx, pstreams, 0);
    412456
    413         // FIXME: do we add endpoint? do we need to destroy previous configuration?
    414         return hc_add_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
     457        return hc_update_endpoint(hc, dev->slot_id, xhci_endpoint_index(xhci_ep), &ep_ctx);
    415458
    416459err_init:
  • uspace/drv/bus/usb/xhci/streams.h

    r61e27e80 r1af4c00  
    6464void xhci_stream_free_ds(xhci_endpoint_t *xhci_ep);
    6565
     66int xhci_endpoint_remove_streams(xhci_hc_t *hc, xhci_device_t *dev, xhci_endpoint_t *xhci_ep);
    6667int xhci_endpoint_request_primary_streams(xhci_hc_t *hc, xhci_device_t *dev,
    6768        xhci_endpoint_t *xhci_ep, unsigned count);
Note: See TracChangeset for help on using the changeset viewer.