Changeset 2e6bbcf in mainline


Ignore:
Timestamp:
2011-04-07T21:59:19Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
52cc968
Parents:
feb10c88
Message:

Use one function to setup all transfers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/iface.c

    rfeb10c88 r2e6bbcf  
    4141#include "hc.h"
    4242
     43static inline int setup_batch(
     44    ddf_fun_t *fun, usb_target_t target, usb_direction_t direction,
     45    void *data, size_t size, void * setup_data, size_t setup_size,
     46    usbhc_iface_transfer_in_callback_t in,
     47    usbhc_iface_transfer_out_callback_t out, void *arg, const char* name,
     48    hc_t **hc, usb_transfer_batch_t **batch)
     49{
     50        assert(hc);
     51        assert(batch);
     52        assert(fun);
     53        *hc = fun_to_hc(fun);
     54        assert(*hc);
     55
     56        size_t res_bw;
     57        endpoint_t *ep = usb_endpoint_manager_get_ep(&(*hc)->ep_manager,
     58            target.address, target.endpoint, direction, &res_bw);
     59        if (ep == NULL) {
     60                usb_log_error("Endpoint(%d:%d) not registered for %s.\n",
     61                    target.address, target.endpoint, name);
     62                return ENOENT;
     63        }
     64
     65        const size_t bw = bandwidth_count_usb11(
     66            ep->speed, ep->transfer_type, size, ep->max_packet_size);
     67        if (res_bw < bw) {
     68                usb_log_error("Endpoint(%d:%d) %s needs %zu bw "
     69                    "but only %zu is reserved.\n",
     70                    name, target.address, target.endpoint, bw, res_bw);
     71                return ENOSPC;
     72        }
     73        usb_log_debug("%s %d:%d %zu(%zu).\n",
     74            name, target.address, target.endpoint, size, ep->max_packet_size);
     75
     76        assert(ep->speed ==
     77            usb_device_keeper_get_speed(&(*hc)->manager, target.address));
     78//      assert(ep->max_packet_size == max_packet_size);
     79//      assert(ep->transfer_type == USB_TRANSFER_CONTROL);
     80
     81        *batch =
     82            batch_get(fun, ep, data, size, setup_data, setup_size,
     83                in, out, arg);
     84        if (!batch)
     85                return ENOMEM;
     86        return EOK;
     87}
     88
     89
    4390/** Reserve default address interface function
    4491 *
     
    215262    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    216263{
     264        usb_transfer_batch_t *batch = NULL;
     265        hc_t *hc = NULL;
     266        int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
     267            NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
     268        if (ret != EOK)
     269                return ret;
     270#if 0
    217271        assert(fun);
    218272        hc_t *hc = fun_to_hc(fun);
     
    233287            size, ep->max_packet_size);
    234288        if (res_bw < bw) {
    235                 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
     289                usb_log_error("Endpoint(%d:%d) INT OUT needs %zu bw "
    236290                    "but only %zu is reserved.\n",
    237291                    target.address, target.endpoint, bw, res_bw);
    238                 return ENOENT;
    239         }
     292                return ENOSPC;
     293        }
     294
    240295        assert(ep->speed ==
    241296            usb_device_keeper_get_speed(&hc->manager, target.address));
     
    247302        if (!batch)
    248303                return ENOMEM;
     304#endif
    249305        batch_interrupt_out(batch);
    250         const int ret = hc_schedule(hc, batch);
     306        ret = hc_schedule(hc, batch);
    251307        if (ret != EOK) {
    252308                batch_dispose(batch);
     
    270326    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    271327{
     328        usb_transfer_batch_t *batch = NULL;
     329        hc_t *hc = NULL;
     330        int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
     331            NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
     332        if (ret != EOK)
     333                return ret;
     334#if 0
    272335        assert(fun);
    273336        hc_t *hc = fun_to_hc(fun);
     
    283346                usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
    284347                    target.address, target.endpoint);
    285                 return ENOENT;
     348                return ENOSPC;
    286349        }
    287350        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     
    303366        if (!batch)
    304367                return ENOMEM;
     368#endif
    305369        batch_interrupt_in(batch);
    306         const int ret = hc_schedule(hc, batch);
     370        ret = hc_schedule(hc, batch);
    307371        if (ret != EOK) {
    308372                batch_dispose(batch);
     
    326390    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    327391{
     392        usb_transfer_batch_t *batch = NULL;
     393        hc_t *hc = NULL;
     394        int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
     395            NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
     396        if (ret != EOK)
     397                return ret;
     398#if 0
    328399        assert(fun);
    329400        hc_t *hc = fun_to_hc(fun);
     
    349420        if (!batch)
    350421                return ENOMEM;
     422#endif
    351423        batch_bulk_out(batch);
    352         const int ret = hc_schedule(hc, batch);
     424        ret = hc_schedule(hc, batch);
    353425        if (ret != EOK) {
    354426                batch_dispose(batch);
     
    372444    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    373445{
    374         assert(fun);
    375         hc_t *hc = fun_to_hc(fun);
    376         assert(hc);
     446        usb_transfer_batch_t *batch = NULL;
     447        hc_t *hc = NULL;
     448        int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
     449            NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
     450        if (ret != EOK)
     451                return ret;
     452#if 0
     453        assert(fun);
     454        hc_t *hc = fun_to_hc(fun);
     455        assert(hc);
     456
    377457        usb_log_debug("Bulk IN %d:%d %zu(%zu).\n",
    378458            target.address, target.endpoint, size, max_packet_size);
     
    394474        if (!batch)
    395475                return ENOMEM;
     476#endif
    396477        batch_bulk_in(batch);
    397         const int ret = hc_schedule(hc, batch);
     478        ret = hc_schedule(hc, batch);
    398479        if (ret != EOK) {
    399480                batch_dispose(batch);
     
    420501    usbhc_iface_transfer_out_callback_t callback, void *arg)
    421502{
     503        usb_transfer_batch_t *batch = NULL;
     504        hc_t *hc = NULL;
     505        int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
     506            setup_data, setup_size, NULL, callback, arg, "Control WRITE",
     507            &hc, &batch);
     508        if (ret != EOK)
     509                return ret;
     510#if 0
    422511        assert(fun);
    423512        hc_t *hc = fun_to_hc(fun);
     
    447536        if (!batch)
    448537                return ENOMEM;
     538#endif
    449539        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    450540        batch_control_write(batch);
    451         const int ret = hc_schedule(hc, batch);
     541        ret = hc_schedule(hc, batch);
    452542        if (ret != EOK) {
    453543                batch_dispose(batch);
     
    474564    usbhc_iface_transfer_in_callback_t callback, void *arg)
    475565{
     566        usb_transfer_batch_t *batch = NULL;
     567        hc_t *hc = NULL;
     568        int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
     569            setup_data, setup_size, callback, NULL, arg, "Control READ",
     570            &hc, &batch);
     571        if (ret != EOK)
     572                return ret;
     573#if 0
    476574        assert(fun);
    477575        hc_t *hc = fun_to_hc(fun);
     
    498596        if (!batch)
    499597                return ENOMEM;
     598#endif
    500599        batch_control_read(batch);
    501         const int ret = hc_schedule(hc, batch);
     600        ret = hc_schedule(hc, batch);
    502601        if (ret != EOK) {
    503602                batch_dispose(batch);
Note: See TracChangeset for help on using the changeset viewer.