Changeset 32fb6bce in mainline for uspace/lib/usbhost/src/endpoint.c


Ignore:
Timestamp:
2017-12-18T22:50:21Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7f70d1c
Parents:
1ea0bbf
git-author:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:04:50)
git-committer:
Ondřej Hlavatý <aearsis@…> (2017-12-18 22:50:21)
Message:

usbhost: refactoring

This commit moves interrupt, status and schedule to bus
operations. Then the purpose of hcd_t is better defined, and split into
hc_driver_t and hc_device_t. hc_driver_t is used to wrap driver
implementation by the library (similar to how usb_driver_t is used to
wrap usb device drivers). hc_device_t is used as a parent for hc_t
inside drivers, and is allocated inside the DDF device node.

To support these changes, some local identifiers were renamed, some
functions were moved and/or renamed and their arguments changed. The
most notable one being hcd_send_batch → bus_device_send_batch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/endpoint.c

    r1ea0bbf r32fb6bce  
    3939#include <mem.h>
    4040#include <stdlib.h>
     41#include <str_error.h>
     42#include <usb/debug.h>
     43#include <usb/host/hcd.h>
    4144
    4245#include "usb_transfer_batch.h"
     
    187190}
    188191
     192/** Prepare generic usb_transfer_batch and schedule it.
     193 * @param ep Endpoint for which the batch shall be created.
     194 * @param target address and endpoint number.
     195 * @param setup_data Data to use in setup stage (Control communication type)
     196 * @param in Callback for device to host communication.
     197 * @param out Callback for host to device communication.
     198 * @param arg Callback parameter.
     199 * @param name Communication identifier (for nicer output).
     200 * @return Error code.
     201 */
     202int endpoint_send_batch(endpoint_t *ep, usb_target_t target,
     203    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     204    usbhc_iface_transfer_callback_t on_complete, void *arg, const char *name)
     205{
     206        usb_log_debug2("%s %d:%d %zu(%zu).\n",
     207            name, target.address, target.endpoint, size, ep->max_packet_size);
     208
     209        bus_t *bus = endpoint_get_bus(ep);
     210        const bus_ops_t *ops = BUS_OPS_LOOKUP(bus->ops, batch_schedule);
     211        if (!ops) {
     212                usb_log_error("HCD does not implement scheduler.\n");
     213                return ENOTSUP;
     214        }
     215
     216        const size_t bw = endpoint_count_bw(ep, size);
     217        /* Check if we have enough bandwidth reserved */
     218        if (ep->bandwidth < bw) {
     219                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
     220                    "but only %zu is reserved.\n",
     221                    ep->device->address, ep->endpoint, name, bw, ep->bandwidth);
     222                return ENOSPC;
     223        }
     224
     225        usb_transfer_batch_t *batch = usb_transfer_batch_create(ep);
     226        if (!batch) {
     227                usb_log_error("Failed to create transfer batch.\n");
     228                return ENOMEM;
     229        }
     230
     231        batch->target = target;
     232        batch->buffer = data;
     233        batch->buffer_size = size;
     234        batch->setup.packed = setup_data;
     235        batch->dir = direction;
     236        batch->on_complete = on_complete;
     237        batch->on_complete_data = arg;
     238
     239        /* Check for commands that reset toggle bit */
     240        if (ep->transfer_type == USB_TRANSFER_CONTROL)
     241                batch->toggle_reset_mode
     242                        = hcd_get_request_toggle_reset_mode(&batch->setup.packet);
     243
     244        const int ret = ops->batch_schedule(batch);
     245        if (ret != EOK) {
     246                usb_log_warning("Batch %p failed to schedule: %s", batch, str_error(ret));
     247                usb_transfer_batch_destroy(batch);
     248        }
     249
     250        return ret;
     251}
     252
    189253/**
    190254 * @}
Note: See TracChangeset for help on using the changeset viewer.