Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 1ed3eb4 in mainline


Ignore:
Timestamp:
2018-01-13T19:13:04Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
2489353
Parents:
001778c
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-13 19:12:34)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-13 19:13:04)
Message:

usbhost: endpoint is identified also by its direction

Location:
uspace
Files:
9 edited

Legend:

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

    r001778c r1ed3eb4  
    116116                return err;
    117117
    118         xhci_endpoint_t *ep0 = xhci_device_get_endpoint(dev, 0);
     118        xhci_endpoint_t *ep0 = xhci_endpoint_get(dev->base.endpoints[0]);
    119119        assert(ep0);
    120120
  • uspace/drv/bus/usb/xhci/endpoint.c

    r001778c r1ed3eb4  
    443443}
    444444
    445 /** Retrieve XHCI endpoint from a device by the endpoint number.
    446  * @param[in] dev XHCI device to query.
    447  * @param[in] ep Endpoint number identifying the endpoint to retrieve.
    448  *
    449  * @return XHCI endpoint with the specified number or NULL if no such endpoint exists.
    450  */
    451 xhci_endpoint_t *xhci_device_get_endpoint(xhci_device_t *dev, usb_endpoint_t ep)
    452 {
    453         endpoint_t *ep_base = dev->base.endpoints[ep];
    454         if (!ep_base)
    455                 return NULL;
    456 
    457         return xhci_endpoint_get(ep_base);
    458 }
    459 
    460445/**
    461446 * @}
  • uspace/drv/bus/usb/xhci/endpoint.h

    r001778c r1ed3eb4  
    139139void xhci_setup_endpoint_context(xhci_endpoint_t *, xhci_ep_ctx_t *);
    140140
    141 xhci_endpoint_t * xhci_device_get_endpoint(xhci_device_t *, usb_endpoint_t);
    142 
    143141static inline xhci_device_t * xhci_device_get(device_t *dev)
    144142{
  • uspace/drv/bus/usb/xhci/isoch.c

    r001778c r1ed3eb4  
    572572}
    573573
    574 int isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep, xhci_trb_t *trb)
     574void isoch_handle_transfer_event(xhci_hc_t *hc, xhci_endpoint_t *ep, xhci_trb_t *trb)
    575575{
    576576        assert(ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS);
     
    591591                        fibril_condvar_broadcast(&ep->isoch->avail);
    592592                        fibril_mutex_unlock(&ep->isoch->guard);
    593                         return EOK;
     593                        goto out;
    594594                case XHCI_TRBC_SHORT_PACKET:
    595595                case XHCI_TRBC_SUCCESS:
     
    641641        timer_schedule_reset(ep);
    642642
     643out:
    643644        fibril_condvar_broadcast(&ep->isoch->avail);
    644645        fibril_mutex_unlock(&ep->isoch->guard);
    645         return EOK;
    646646}
    647647
  • uspace/drv/bus/usb/xhci/isoch.h

    r001778c r1ed3eb4  
    123123int isoch_schedule_out(xhci_transfer_t *);
    124124int isoch_schedule_in(xhci_transfer_t *);
    125 int isoch_handle_transfer_event(xhci_hc_t *, xhci_endpoint_t *, xhci_trb_t *);
     125void isoch_handle_transfer_event(xhci_hc_t *, xhci_endpoint_t *, xhci_trb_t *);
    126126
    127127#endif
  • uspace/drv/bus/usb/xhci/transfers.c

    r001778c r1ed3eb4  
    258258
    259259        const usb_endpoint_t ep_num = ep_dci / 2;
    260         xhci_endpoint_t *ep = xhci_device_get_endpoint(dev, ep_num);
    261         if (!ep) {
    262                 usb_log_error("Transfer event on dropped endpoint %u of device "
    263                     XHCI_DEV_FMT, ep_num, XHCI_DEV_ARGS(*dev));
     260        const usb_endpoint_t dir = ep_dci % 2 ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
     261        endpoint_t *ep_base = bus_find_endpoint(&dev->base, ep_num, dir);
     262        if (!ep_base) {
     263                usb_log_error("Transfer event on dropped endpoint %u %s of device "
     264                    XHCI_DEV_FMT, ep_num, usb_str_direction(dir), XHCI_DEV_ARGS(*dev));
    264265                return ENOENT;
    265266        }
    266         // No need to add reference for endpoint, it is held by the transfer batch.
     267        xhci_endpoint_t *ep = xhci_endpoint_get(ep_base);
    267268
    268269        /* FIXME: This is racy. Do we care? */
     
    270271
    271272        if (ep->base.transfer_type == USB_TRANSFER_ISOCHRONOUS) {
    272                 return isoch_handle_transfer_event(hc, ep, trb);
     273                isoch_handle_transfer_event(hc, ep, trb);
     274                endpoint_del_ref(&ep->base);
     275                return EOK;
    273276        }
    274277
     
    277280        if (!batch) {
    278281                fibril_mutex_unlock(&ep->base.guard);
     282                endpoint_del_ref(&ep->base);
    279283                return ENOENT;
    280284        }
     
    305309
    306310        usb_transfer_batch_finish(batch);
     311        endpoint_del_ref(&ep->base);
    307312        return EOK;
    308313}
  • uspace/lib/usbhost/include/usb/host/bus.h

    r001778c r1ed3eb4  
    7676        usb_speed_t speed;
    7777        usb_address_t address;
    78         endpoint_t *endpoints [USB_ENDPOINT_MAX];
     78        endpoint_t *endpoints [2 * USB_ENDPOINT_MAX];
    7979
    8080        /* Managing bus */
     
    163163
    164164int bus_endpoint_add(device_t *, const usb_endpoint_descriptors_t *, endpoint_t **);
    165 endpoint_t *bus_find_endpoint(device_t *, usb_endpoint_t);
     165endpoint_t *bus_find_endpoint(device_t *, usb_endpoint_t, usb_direction_t);
    166166int bus_endpoint_remove(endpoint_t *);
    167167
  • uspace/lib/usbhost/src/bus.c

    r001778c r1ed3eb4  
    307307err:
    308308        return rc;
     309}
     310
     311/**
     312 * Calculate an index to the endpoint array.
     313 * For the default control endpoint 0, it must return 0.
     314 * For different arguments, the result is stable but not defined.
     315 */
     316static int bus_endpoint_index(usb_endpoint_t ep, usb_direction_t dir)
     317{
     318        return 2 * ep + (dir == USB_DIRECTION_OUT);
    309319}
    310320
     
    357367            ep->max_transfer_size);
    358368
     369        const int idx = bus_endpoint_index(ep->endpoint, ep->direction);
     370
    359371        fibril_mutex_lock(&device->guard);
    360372        if (!device->online && ep->endpoint != 0) {
    361373                err = EAGAIN;
    362         } else if (device->endpoints[ep->endpoint] != NULL) {
     374        } else if (device->endpoints[idx] != NULL) {
    363375                err = EEXIST;
    364376        } else {
    365377                err = register_ops->endpoint_register(ep);
    366378                if (!err)
    367                         device->endpoints[ep->endpoint] = ep;
     379                        device->endpoints[idx] = ep;
    368380        }
    369381        fibril_mutex_unlock(&device->guard);
     
    385397 * Search for an endpoint. Returns a reference.
    386398 */
    387 endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint)
     399endpoint_t *bus_find_endpoint(device_t *device, usb_endpoint_t endpoint, usb_direction_t dir)
    388400{
    389401        assert(device);
    390402
     403        const int idx = bus_endpoint_index(endpoint, dir);
     404        const int ctrl_idx = bus_endpoint_index(endpoint, USB_DIRECTION_BOTH);
     405
    391406        fibril_mutex_lock(&device->guard);
    392         endpoint_t *ep = device->endpoints[endpoint];
     407        endpoint_t *ep = device->endpoints[idx];
     408        /*
     409         * If the endpoint was not found, it's still possible it is a control
     410         * endpoint having direction BOTH.
     411         */
     412        if (!ep) {
     413                ep = device->endpoints[ctrl_idx];
     414                if (ep && ep->transfer_type != USB_TRANSFER_CONTROL)
     415                        ep = NULL;
     416        }
    393417        if (ep) {
    394418                /* Exporting reference */
     
    423447            ep->max_transfer_size);
    424448
     449        const int idx = bus_endpoint_index(ep->endpoint, ep->direction);
     450
    425451        fibril_mutex_lock(&device->guard);
    426452        ops->endpoint_unregister(ep);
    427         device->endpoints[ep->endpoint] = NULL;
     453        device->endpoints[idx] = NULL;
    428454        fibril_mutex_unlock(&device->guard);
    429455
     
    489515
    490516        /* Temporary reference */
    491         endpoint_t *ep = bus_find_endpoint(device, target.endpoint);
     517        endpoint_t *ep = bus_find_endpoint(device, target.endpoint, direction);
    492518        if (ep == NULL) {
    493519                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
  • uspace/lib/usbhost/src/ddf_helpers.c

    r001778c r1ed3eb4  
    111111        assert(dev);
    112112
    113         endpoint_t *ep = bus_find_endpoint(dev, pipe_desc->endpoint_no);
     113        endpoint_t *ep = bus_find_endpoint(dev, pipe_desc->endpoint_no, pipe_desc->direction);
    114114        if (!ep)
    115115                return ENOENT;
Note: See TracChangeset for help on using the changeset viewer.