Changeset 327f147 in mainline


Ignore:
Timestamp:
2017-10-23T19:03:37Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b724494
Parents:
e160bfe8
Message:

usbhost: change parameters of methods

Pass (device_t, usb_target_t) to read and write, which finally allows to drop hash tables and access device right away. Then, all callbacks to complete transfer now uses usb_transfer_batch. This requires libdrv to include libusbhost, but it is not linked against it - it is there only to share definition of usb_transfer_batch_t.

Location:
uspace
Files:
14 edited

Legend:

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

    re160bfe8 r327f147  
    3333 */
    3434
    35 #include <adt/hash_table.h>
    36 #include <adt/hash.h>
    3735#include <usb/host/utils/malloc32.h>
    3836#include <usb/host/ddf_helpers.h>
     
    5048#include "endpoint.h"
    5149#include "transfers.h"
    52 
    53 /** Element of the hash table. */
    54 typedef struct {
    55         ht_link_t link;
    56 
    57         /** Device */
    58         xhci_device_t *device;
    59 } hashed_device_t;
    60 
    61 static int hashed_device_insert(xhci_bus_t *bus, hashed_device_t **hashed_dev, xhci_device_t *dev);
    62 static int hashed_device_remove(xhci_bus_t *bus, hashed_device_t *hashed_dev);
    63 static int hashed_device_find_by_address(xhci_bus_t *bus, usb_address_t address, hashed_device_t **dev);
    6450
    6551/** TODO: Still some copy-pasta left...
     
    9480        bus->devices_by_slot[xhci_dev->slot_id] = xhci_dev;
    9581
    96         hashed_device_t *hashed_dev = NULL;
    97         if ((err = hashed_device_insert(bus, &hashed_dev, xhci_dev)))
    98                 goto err_address;
    99 
    10082        /* Read the device descriptor, derive the match ids */
    10183        if ((err = hcd_ddf_device_explore(hc->hcd, dev))) {
    10284                usb_log_error("Device(%d): Failed to explore device: %s", dev->address, str_error(err));
    103                 goto err_hash;
    104         }
    105 
    106         return EOK;
    107 
    108 err_hash:
    109         bus->devices_by_slot[xhci_dev->slot_id] = NULL;
    110         hashed_device_remove(bus, hashed_dev);
     85                goto err_address;
     86        }
     87
     88        return EOK;
     89
    11190err_address:
    11291        bus_release_address(&bus->base, dev->address);
     
    127106        }
    128107
    129         hashed_device_t *hashed_dev;
    130         int res = hashed_device_find_by_address(bus, dev->address, &hashed_dev);
    131         if (res)
    132                 return res;
    133 
    134         res = hashed_device_remove(bus, hashed_dev);
    135         if (res != EOK)
    136                 return res;
    137 
    138108        // XXX: Ugly here. Move to device_destroy at endpoint.c?
    139109        free32(xhci_dev->dev_ctx);
     
    193163        xhci_endpoint_fini(xhci_ep);
    194164        free(xhci_ep);
    195 }
    196 
    197 static int hashed_device_find_by_address(xhci_bus_t *bus, usb_address_t address, hashed_device_t **dev)
    198 {
    199         ht_link_t *link = hash_table_find(&bus->devices, &address);
    200         if (link == NULL)
    201                 return ENOENT;
    202 
    203         *dev = hash_table_get_inst(link, hashed_device_t, link);
    204         return EOK;
    205 }
    206 
    207 static int xhci_endpoint_find_by_target(xhci_bus_t *bus, usb_target_t target, xhci_endpoint_t **ep)
    208 {
    209         hashed_device_t *dev;
    210         int res = hashed_device_find_by_address(bus, target.address, &dev);
    211         if (res != EOK)
    212                 return res;
    213 
    214         xhci_endpoint_t *ret_ep = xhci_device_get_endpoint(dev->device, target.endpoint);
    215         if (!ret_ep)
    216                 return ENOENT;
    217 
    218         *ep = ret_ep;
    219         return EOK;
    220 }
    221 
    222 static int hashed_device_insert(xhci_bus_t *bus, hashed_device_t **hashed_dev, xhci_device_t *dev)
    223 {
    224         hashed_device_t *ret_dev = (hashed_device_t *) calloc(1, sizeof(hashed_device_t));
    225         if (!ret_dev)
    226                 return ENOMEM;
    227 
    228         ret_dev->device = dev;
    229 
    230         usb_log_info("Device(%d) registered to XHCI bus.", dev->base.address);
    231 
    232         hash_table_insert(&bus->devices, &ret_dev->link);
    233         *hashed_dev = ret_dev;
    234         return EOK;
    235 }
    236 
    237 static int hashed_device_remove(xhci_bus_t *bus, hashed_device_t *hashed_dev)
    238 {
    239         usb_log_info("Device(%d) released from XHCI bus.", hashed_dev->device->base.address);
    240 
    241         hash_table_remove(&bus->devices, &hashed_dev->device->base.address);
    242         free(hashed_dev);
    243 
    244         return EOK;
    245165}
    246166
     
    273193}
    274194
    275 static endpoint_t* find_endpoint(bus_t *bus_base, usb_target_t target, usb_direction_t direction)
    276 {
    277         xhci_bus_t *bus = bus_to_xhci_bus(bus_base);
    278         assert(bus);
    279 
    280         xhci_endpoint_t *ep;
    281         int res = xhci_endpoint_find_by_target(bus, target, &ep);
    282         if (res != EOK)
     195static endpoint_t* find_endpoint(bus_t *bus_base, device_t *dev_base, usb_target_t target, usb_direction_t direction)
     196{
     197        xhci_device_t *dev = xhci_device_get(dev_base);
     198
     199        xhci_endpoint_t *ep = xhci_device_get_endpoint(dev, target.endpoint);
     200        if (!ep)
    283201                return NULL;
    284202
     
    345263};
    346264
    347 static size_t device_ht_hash(const ht_link_t *item)
    348 {
    349         hashed_device_t *dev = hash_table_get_inst(item, hashed_device_t, link);
    350         return (size_t) hash_mix(dev->device->base.address);
    351 }
    352 
    353 static size_t device_ht_key_hash(void *key)
    354 {
    355         return (size_t) hash_mix(*(usb_address_t *)key);
    356 }
    357 
    358 static bool device_ht_key_equal(void *key, const ht_link_t *item)
    359 {
    360         hashed_device_t *dev = hash_table_get_inst(item, hashed_device_t, link);
    361         return dev->device->base.address == *(usb_address_t *) key;
    362 }
    363 
    364 /** Operations for the device hash table. */
    365 static hash_table_ops_t device_ht_ops = {
    366         .hash = device_ht_hash,
    367         .key_hash = device_ht_key_hash,
    368         .key_equal = device_ht_key_equal,
    369         .equal = NULL,
    370         .remove_callback = NULL
    371 };
    372 
    373265int xhci_bus_init(xhci_bus_t *bus, xhci_hc_t *hc)
    374266{
     
    381273                return ENOMEM;
    382274
    383         if (!hash_table_create(&bus->devices, 0, 0, &device_ht_ops)) {
    384                 free(bus->devices_by_slot);
    385                 return ENOMEM;
    386         }
    387 
    388275        bus->base.ops = xhci_bus_ops;
    389276        return EOK;
     
    392279void xhci_bus_fini(xhci_bus_t *bus)
    393280{
    394         // FIXME: Make sure no devices are in the hash table.
    395 
    396         hash_table_destroy(&bus->devices);
     281
    397282}
    398283
  • uspace/drv/bus/usb/xhci/bus.h

    re160bfe8 r327f147  
    3838#define XHCI_BUS_H
    3939
    40 #include <adt/hash_table.h>
    4140#include <usb/usb.h>
    4241#include <usb/host/bus.h>
     
    5049
    5150        xhci_device_t **devices_by_slot;        /**< Devices by Slot ID */
    52 
    53         /** TODO: Do we really need this? */
    54         hash_table_t devices;           /**< Devices by address */
    5551} xhci_bus_t;
    5652
  • uspace/lib/drv/Makefile

    re160bfe8 r327f147  
    3333        -Igeneric/private \
    3434        -I$(LIBUSB_PREFIX)/include \
     35        -I$(LIBUSBHOST_PREFIX)/include \
    3536        -I$(LIBPCM_PREFIX)/include
    3637LIBRARY = libdrv
  • uspace/lib/drv/generic/remote_usb.c

    re160bfe8 r327f147  
    3838#include <errno.h>
    3939#include <devman.h>
     40#include <usb/host/usb_transfer_batch.h>
    4041
    4142#include "usb_iface.h"
     
    539540}
    540541
    541 static void callback_out(int outcome, void *arg)
    542 {
    543         async_transaction_t *trans = arg;
    544 
    545         async_answer_0(trans->caller, outcome);
     542static int callback_out(usb_transfer_batch_t *batch)
     543{
     544        async_transaction_t *trans = batch->on_complete_data;
     545
     546        const int err = async_answer_0(trans->caller, batch->error);
    546547
    547548        async_transaction_destroy(trans);
    548 }
    549 
    550 static void callback_in(int outcome, size_t actual_size, void *arg)
    551 {
    552         async_transaction_t *trans = (async_transaction_t *)arg;
    553 
    554         if (outcome != EOK) {
    555                 async_answer_0(trans->caller, outcome);
    556                 if (trans->data_caller) {
     549
     550        return err;
     551}
     552
     553static int callback_in(usb_transfer_batch_t *batch)
     554{
     555        async_transaction_t *trans = batch->on_complete_data;
     556
     557        if (trans->data_caller) {
     558                if (batch->error == EOK) {
     559                        batch->error = async_data_read_finalize(trans->data_caller,
     560                            trans->buffer, batch->transfered_size);
     561                } else {
    557562                        async_answer_0(trans->data_caller, EINTR);
    558563                }
    559                 async_transaction_destroy(trans);
    560                 return;
    561         }
    562 
    563         if (trans->data_caller) {
    564                 async_data_read_finalize(trans->data_caller,
    565                     trans->buffer, actual_size);
    566         }
    567 
    568         async_answer_0(trans->caller, EOK);
    569 
     564        }
     565
     566        const int err = async_answer_0(trans->caller, batch->error);
    570567        async_transaction_destroy(trans);
     568        return err;
    571569}
    572570
     
    611609        }
    612610
     611        const usb_target_t target = {{
     612                /* .address is initialized by read itself */
     613                .endpoint = ep,
     614        }};
     615
    613616        const int rc = usb_iface->read(
    614             fun, ep, setup, trans->buffer, size, callback_in, trans);
     617            fun, target, setup, trans->buffer, size, callback_in, trans);
    615618
    616619        if (rc != EOK) {
     
    659662        }
    660663
     664        const usb_target_t target = {{
     665                /* .address is initialized by write itself */
     666                .endpoint = ep,
     667        }};
     668
    661669        const int rc = usb_iface->write(
    662             fun, ep, setup, trans->buffer, size, callback_out, trans);
     670            fun, target, setup, trans->buffer, size, callback_out, trans);
    663671
    664672        if (rc != EOK) {
  • uspace/lib/drv/include/usb_iface.h

    re160bfe8 r327f147  
    6464    size_t);
    6565
    66 /** Callback for outgoing transfer. */
    67 typedef void (*usb_iface_transfer_out_callback_t)(int, void *);
     66/** Defined in usb/host/usb_transfer_batch.h */
     67typedef struct usb_transfer_batch usb_transfer_batch_t;
    6868
    69 /** Callback for incoming transfer. */
    70 typedef void (*usb_iface_transfer_in_callback_t)(int, size_t, void *);
     69/** Callback for outgoing transfer - clone of usb_transfer_batch_callback_t */
     70typedef int (*usb_iface_transfer_callback_t)(usb_transfer_batch_t *);
    7171
    7272/** USB device communication interface. */
     
    8484        int (*unregister_endpoint)(ddf_fun_t *, usb_endpoint_desc_t *);
    8585
    86         int (*read)(ddf_fun_t *, usb_endpoint_t, uint64_t, uint8_t *, size_t,
    87             usb_iface_transfer_in_callback_t, void *);
    88         int (*write)(ddf_fun_t *, usb_endpoint_t, uint64_t, const uint8_t *,
    89             size_t, usb_iface_transfer_out_callback_t, void *);
     86        int (*read)(ddf_fun_t *, usb_target_t,
     87                uint64_t, char *, size_t,
     88                usb_iface_transfer_callback_t, void *);
     89        int (*write)(ddf_fun_t *, usb_target_t,
     90                uint64_t, const char *, size_t,
     91                usb_iface_transfer_callback_t, void *);
    9092} usb_iface_t;
    9193
  • uspace/lib/usbhost/include/usb/host/bus.h

    re160bfe8 r327f147  
    8585        int (*register_endpoint)(bus_t *, endpoint_t *);
    8686        int (*unregister_endpoint)(bus_t *, endpoint_t *);
    87         endpoint_t *(*find_endpoint)(bus_t *, usb_target_t, usb_direction_t);
     87        endpoint_t *(*find_endpoint)(bus_t *, device_t*, usb_target_t, usb_direction_t);
    8888        void (*destroy_endpoint)(endpoint_t *);                 /**< Optional */
    8989        bool (*endpoint_get_toggle)(endpoint_t *);              /**< Optional */
     
    120120    usb_direction_t dir, usb_transfer_type_t type, size_t max_packet_size,
    121121    unsigned packets, size_t size);
    122 extern int bus_remove_ep(bus_t *bus, usb_target_t target, usb_direction_t dir);
     122extern int bus_remove_ep(bus_t *, device_t *, usb_target_t, usb_direction_t);
    123123
    124124int device_set_default_name(device_t *);
     
    130130int bus_register_endpoint(bus_t *, endpoint_t *);
    131131int bus_unregister_endpoint(bus_t *, endpoint_t *);
    132 endpoint_t *bus_find_endpoint(bus_t *, usb_target_t, usb_direction_t);
     132endpoint_t *bus_find_endpoint(bus_t *, device_t *, usb_target_t, usb_direction_t);
    133133
    134134size_t bus_count_bw(endpoint_t *, size_t);
  • uspace/lib/usbhost/include/usb/host/hcd.h

    re160bfe8 r327f147  
    108108extern int hcd_remove_ep(hcd_t *, usb_target_t, usb_direction_t);
    109109
    110 extern int hcd_send_batch(hcd_t *, usb_target_t, usb_direction_t, void *,
    111     size_t, uint64_t, usbhc_iface_transfer_in_callback_t,
    112     usbhc_iface_transfer_out_callback_t, void *, const char *);
     110extern int hcd_send_batch(hcd_t *, device_t *, usb_target_t,
     111    usb_direction_t direction, char *, size_t, uint64_t,
     112    usb_transfer_batch_callback_t, void *, const char *);
    113113
    114 extern ssize_t hcd_send_batch_sync(hcd_t *, usb_target_t, usb_direction_t,
    115     void *, size_t, uint64_t, const char *);
     114extern ssize_t hcd_send_batch_sync(hcd_t *, device_t *, usb_target_t,
     115    usb_direction_t direction, char *, size_t, uint64_t,
     116    const char *);
    116117
    117118#endif
  • uspace/lib/usbhost/include/usb/host/usb2_bus.h

    re160bfe8 r327f147  
    5656                usb_speed_t speed;      /**< Device speed */
    5757                bool occupied;          /**< The address is in use. */
     58                // TODO: This can be stored in usb2_bus-specific device_t
    5859                list_t endpoint_list;   /**< Store endpoint_t instances */
    5960        } devices[USB_ADDRESS_COUNT];
  • uspace/lib/usbhost/include/usb/host/usb_transfer_batch.h

    re160bfe8 r327f147  
    108108void usb_transfer_batch_destroy(usb_transfer_batch_t *);
    109109
    110 /** Provided to ease the transition. Wraps old-style handlers into a new one.
    111  */
    112 extern void usb_transfer_batch_set_old_handlers(usb_transfer_batch_t *,
    113         usbhc_iface_transfer_in_callback_t,
    114         usbhc_iface_transfer_out_callback_t, void *);
    115 
    116110#endif
    117111
  • uspace/lib/usbhost/src/bus.c

    re160bfe8 r327f147  
    9999}
    100100
    101 int bus_remove_ep(bus_t *bus, usb_target_t target, usb_direction_t dir)
    102 {
    103         assert(bus);
    104         endpoint_t *ep = bus_find_endpoint(bus, target, dir);
     101int bus_remove_ep(bus_t *bus, device_t *dev, usb_target_t target, usb_direction_t dir)
     102{
     103        assert(bus);
     104        endpoint_t *ep = bus_find_endpoint(bus, dev, target, dir);
    105105        if (!ep)
    106106                return ENOENT;
     
    200200/** Searches for an endpoint. Returns a reference.
    201201 */
    202 endpoint_t *bus_find_endpoint(bus_t *bus, usb_target_t target, usb_direction_t dir)
    203 {
    204         assert(bus);
    205 
    206         fibril_mutex_lock(&bus->guard);
    207         endpoint_t *ep = bus->ops.find_endpoint(bus, target, dir);
     202endpoint_t *bus_find_endpoint(bus_t *bus, device_t *device, usb_target_t endpoint, usb_direction_t dir)
     203{
     204        assert(bus);
     205
     206        fibril_mutex_lock(&bus->guard);
     207        endpoint_t *ep = bus->ops.find_endpoint(bus, device, endpoint, dir);
    208208        if (ep) {
    209209                /* Exporting reference */
  • uspace/lib/usbhost/src/ddf_helpers.c

    re160bfe8 r327f147  
    135135                dev->address, endpoint_desc->endpoint_no,
    136136                usb_str_direction(endpoint_desc->direction));
    137         return bus_remove_ep(hcd->bus, target, endpoint_desc->direction);
     137        return bus_remove_ep(hcd->bus, dev, target, endpoint_desc->direction);
    138138}
    139139
     
    216216 * @return Error code.
    217217 */
    218 static int dev_read(ddf_fun_t *fun, usb_endpoint_t endpoint,
    219     uint64_t setup_data, uint8_t *data, size_t size,
    220     usbhc_iface_transfer_in_callback_t callback, void *arg)
     218static int dev_read(ddf_fun_t *fun, usb_target_t target,
     219    uint64_t setup_data, char *data, size_t size,
     220    usb_iface_transfer_callback_t callback, void *arg)
    221221{
    222222        assert(fun);
     223        hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
    223224        device_t *dev = ddf_fun_data_get(fun);
    224225        assert(dev);
    225         const usb_target_t target = {{
    226             .address  = dev->address,
    227             .endpoint = endpoint,
    228         }};
    229         return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)), target,
    230             USB_DIRECTION_IN, data, size, setup_data, callback, NULL, arg,
    231             "READ");
     226
     227        target.address = dev->address;
     228
     229        return hcd_send_batch(hcd, dev, target, USB_DIRECTION_IN,
     230            data, size, setup_data,
     231            callback, arg, "READ");
    232232}
    233233
     
    242242 * @return Error code.
    243243 */
    244 static int dev_write(ddf_fun_t *fun, usb_endpoint_t endpoint,
    245     uint64_t setup_data, const uint8_t *data, size_t size,
    246     usbhc_iface_transfer_out_callback_t callback, void *arg)
     244static int dev_write(ddf_fun_t *fun, usb_target_t target,
     245    uint64_t setup_data, const char *data, size_t size,
     246    usb_iface_transfer_callback_t callback, void *arg)
    247247{
    248248        assert(fun);
     249        hcd_t *hcd = dev_to_hcd(ddf_fun_get_dev(fun));
    249250        device_t *dev = ddf_fun_data_get(fun);
    250251        assert(dev);
    251         const usb_target_t target = {{
    252             .address  = dev->address,
    253             .endpoint = endpoint,
    254         }};
    255         return hcd_send_batch(dev_to_hcd(ddf_fun_get_dev(fun)),
    256             target, USB_DIRECTION_OUT, (uint8_t*)data, size, setup_data, NULL,
     252
     253        target.address = dev->address;
     254
     255        return hcd_send_batch(hcd, dev, target, USB_DIRECTION_OUT,
     256            (char *) data, size, setup_data,
    257257            callback, arg, "WRITE");
    258258}
     
    411411        init_match_ids(&mids);
    412412
    413         usb_target_t control_ep = {{
     413        const usb_target_t control_ep = {{
    414414                .address = device->address,
    415                 .endpoint = 0
     415                .endpoint = 0,
    416416        }};
    417417
     
    422422        usb_log_debug("Device(%d): Requesting full device descriptor.",
    423423            device->address);
    424         ssize_t got = hcd_send_batch_sync(hcd, control_ep, USB_DIRECTION_IN,
    425             &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
     424        ssize_t got = hcd_send_batch_sync(hcd, device, control_ep, USB_DIRECTION_IN,
     425            (char *) &desc, sizeof(desc), *(uint64_t *)&get_device_desc,
    426426            "read device descriptor");
    427427        if (got < 0) {
  • uspace/lib/usbhost/src/hcd.c

    re160bfe8 r327f147  
    8080 * @return Error code.
    8181 */
    82 int hcd_send_batch(hcd_t *hcd, usb_target_t target, usb_direction_t direction,
    83         void *data, size_t size, uint64_t setup_data,
    84         usbhc_iface_transfer_in_callback_t in, usbhc_iface_transfer_out_callback_t out,
    85         void *arg, const char *name)
     82int hcd_send_batch(hcd_t *hcd, device_t *device, usb_target_t target,
     83    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     84    usb_transfer_batch_callback_t on_complete, void *arg, const char *name)
    8685{
    8786        assert(hcd);
     87        assert(device->address == target.address);
    8888
    89         endpoint_t *ep = bus_find_endpoint(hcd->bus, target, direction);
     89        endpoint_t *ep = bus_find_endpoint(hcd->bus, device, target, direction);
    9090        if (ep == NULL) {
    9191                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
    92                     target.address, target.endpoint, name);
     92                    device->address, target.endpoint, name);
    9393                return ENOENT;
    9494        }
     
    120120        batch->setup.packed = setup_data;
    121121        batch->dir = direction;
     122        batch->on_complete = on_complete;
     123        batch->on_complete_data = arg;
    122124
    123125        /* Check for commands that reset toggle bit */
     
    125127                batch->toggle_reset_mode
    126128                        = usb_request_get_toggle_reset_mode(&batch->setup.packet);
    127 
    128         usb_transfer_batch_set_old_handlers(batch, in, out, arg);
    129129
    130130        const int ret = hcd->ops.schedule(hcd, batch);
     
    144144        fibril_condvar_t done_cv;
    145145        unsigned done;
    146         int ret;
    147         size_t size;
     146
     147        size_t transfered_size;
     148        int error;
    148149} sync_data_t;
    149150
    150 static void transfer_in_cb(int ret, size_t size, void* data)
     151static int sync_transfer_complete(usb_transfer_batch_t *batch)
    151152{
    152         sync_data_t *d = data;
     153        sync_data_t *d = batch->on_complete_data;
    153154        assert(d);
    154         d->ret = ret;
    155         d->size = size;
     155        d->transfered_size = batch->transfered_size;
     156        d->error = batch->error;
    156157        fibril_mutex_lock(&d->done_mtx);
    157158        d->done = 1;
    158159        fibril_condvar_broadcast(&d->done_cv);
    159160        fibril_mutex_unlock(&d->done_mtx);
     161        return EOK;
    160162}
    161163
    162 static void transfer_out_cb(int ret, void* data)
    163 {
    164         sync_data_t *d = data;
    165         assert(data);
    166         d->ret = ret;
    167         fibril_mutex_lock(&d->done_mtx);
    168         d->done = 1;
    169         fibril_condvar_broadcast(&d->done_cv);
    170         fibril_mutex_unlock(&d->done_mtx);
    171 }
    172 
    173 /** this is really ugly version of sync usb communication */
    174 ssize_t hcd_send_batch_sync(
    175     hcd_t *hcd, usb_target_t target, usb_direction_t dir,
    176     void *data, size_t size, uint64_t setup_data, const char* name)
     164ssize_t hcd_send_batch_sync(hcd_t *hcd, device_t *device, usb_target_t target,
     165    usb_direction_t direction, char *data, size_t size, uint64_t setup_data,
     166    const char *name)
    177167{
    178168        assert(hcd);
    179         sync_data_t sd = { .done = 0, .ret = EBUSY, .size = size };
     169        sync_data_t sd = { .done = 0 };
    180170        fibril_mutex_initialize(&sd.done_mtx);
    181171        fibril_condvar_initialize(&sd.done_cv);
    182172
    183         const int ret = hcd_send_batch(hcd, target, dir, data, size, setup_data,
    184             dir == USB_DIRECTION_IN ? transfer_in_cb : NULL,
    185             dir == USB_DIRECTION_OUT ? transfer_out_cb : NULL, &sd, name);
     173        const int ret = hcd_send_batch(hcd, device, target, direction,
     174            data, size, setup_data,
     175            sync_transfer_complete, &sd, name);
    186176        if (ret != EOK)
    187177                return ret;
     
    192182        fibril_mutex_unlock(&sd.done_mtx);
    193183
    194         if (sd.ret == EOK)
    195                 return sd.size;
    196         return sd.ret;
     184        return (sd.error == EOK)
     185                ? (ssize_t) sd.transfered_size
     186                : (ssize_t) sd.error;
    197187}
    198188
  • uspace/lib/usbhost/src/usb2_bus.c

    re160bfe8 r327f147  
    126126        usb_log_debug("Device(%d): Requesting first 8B of device descriptor.",
    127127            address);
    128         ssize_t got = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_IN,
    129             &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
     128        ssize_t got = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_IN,
     129            (char *) &desc, CTRL_PIPE_MIN_PACKET_SIZE, *(uint64_t *)&get_device_desc_8,
    130130            "read first 8 bytes of dev descriptor");
    131131
     
    141141
    142142        usb_log_debug("Device(%d): Setting USB address.", address);
    143         err = hcd_send_batch_sync(hcd, default_target, USB_DIRECTION_OUT,
     143        err = hcd_send_batch_sync(hcd, dev, default_target, USB_DIRECTION_OUT,
    144144            NULL, 0, *(uint64_t *)&set_address, "set address");
    145145        if (err != 0) {
     
    163163        }
    164164
    165         bus_remove_ep(bus, default_target, USB_DIRECTION_BOTH);
     165        bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);
    166166        return EOK;
    167167
    168168err_default_target:
    169         bus_remove_ep(bus, default_target, USB_DIRECTION_BOTH);
     169        bus_remove_ep(bus, dev, default_target, USB_DIRECTION_BOTH);
    170170err_address:
    171171        bus_release_address(bus, address);
     
    247247 * @note Assumes that the internal mutex is locked.
    248248 */
    249 static endpoint_t *usb2_bus_find_ep(bus_t *bus_base, usb_target_t target, usb_direction_t direction)
     249static endpoint_t *usb2_bus_find_ep(bus_t *bus_base, device_t *device, usb_target_t target, usb_direction_t direction)
    250250{
    251251        usb2_bus_t *bus = bus_to_usb2_bus(bus_base);
     
    293293
    294294        /* Check for existence */
    295         if (usb2_bus_find_ep(bus_base, ep->target, ep->direction))
     295        if (usb2_bus_find_ep(bus_base, ep->device, ep->target, ep->direction))
    296296                return EEXIST;
    297297
  • uspace/lib/usbhost/src/usb_transfer_batch.c

    re160bfe8 r327f147  
    133133}
    134134
    135 
    136 struct old_handler_wrapper_data {
    137         usbhc_iface_transfer_in_callback_t in_callback;
    138         usbhc_iface_transfer_out_callback_t out_callback;
    139         void *arg;
    140 };
    141 
    142 static int old_handler_wrapper(usb_transfer_batch_t *batch)
    143 {
    144         struct old_handler_wrapper_data *data = batch->on_complete_data;
    145 
    146         assert(data);
    147 
    148         if (data->out_callback)
    149                 data->out_callback(batch->error, data->arg);
    150 
    151         if (data->in_callback)
    152                 data->in_callback(batch->error, batch->transfered_size, data->arg);
    153 
    154         free(data);
    155         return EOK;
    156 }
    157 
    158 void usb_transfer_batch_set_old_handlers(usb_transfer_batch_t *batch,
    159         usbhc_iface_transfer_in_callback_t in_callback,
    160         usbhc_iface_transfer_out_callback_t out_callback,
    161         void *arg)
    162 {
    163         struct old_handler_wrapper_data *data = malloc(sizeof(*data));
    164 
    165         assert((!in_callback) != (!out_callback));
    166 
    167         data->in_callback = in_callback;
    168         data->out_callback = out_callback;
    169         data->arg = arg;
    170 
    171         batch->on_complete = old_handler_wrapper;
    172         batch->on_complete_data = data;
    173 }
    174135/**
    175136 * @}
Note: See TracChangeset for help on using the changeset viewer.