Changeset c6cb76d in mainline for uspace/drv/uhci-hcd


Ignore:
Timestamp:
2011-04-08T20:19:48Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
297341b
Parents:
7dfc06fa (diff), 61727bf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

Location:
uspace/drv/uhci-hcd
Files:
5 edited

Legend:

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

    r7dfc06fa rc6cb76d  
    8080 * transaction and callback.
    8181 */
    82 usb_transfer_batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    83     usb_transfer_type_t transfer_type, size_t max_packet_size,
    84     usb_speed_t speed, char *buffer, size_t buffer_size,
    85     char* setup_buffer, size_t setup_size,
     82usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
     83    char *buffer, size_t buffer_size, char* setup_buffer, size_t setup_size,
    8684    usbhc_iface_transfer_in_callback_t func_in,
    87     usbhc_iface_transfer_out_callback_t func_out, void *arg, endpoint_t *ep
    88     )
    89 {
     85    usbhc_iface_transfer_out_callback_t func_out, void *arg)
     86{
     87        assert(ep);
    9088        assert(func_in == NULL || func_out == NULL);
    9189        assert(func_in != NULL || func_out != NULL);
     
    103101        CHECK_NULL_DISPOSE_RETURN(instance,
    104102            "Failed to allocate batch instance.\n");
     103        usb_target_t target =
     104            { .address = ep->address, .endpoint = ep->endpoint };
    105105        usb_transfer_batch_init(instance, target,
    106             transfer_type, speed, max_packet_size,
     106            ep->transfer_type, ep->speed, ep->max_packet_size,
    107107            buffer, NULL, buffer_size, NULL, setup_size, func_in,
    108108            func_out, arg, fun, ep, NULL);
     
    115115        instance->private_data = data;
    116116
    117         data->transfers = (buffer_size + max_packet_size - 1) / max_packet_size;
    118         if (transfer_type == USB_TRANSFER_CONTROL) {
     117        data->transfers =
     118            (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size;
     119        if (ep->transfer_type == USB_TRANSFER_CONTROL) {
    119120                data->transfers += 2;
    120121        }
     
    178179                            instance, i, data->tds[i].status);
    179180                        td_print_status(&data->tds[i]);
    180                         if (instance->ep != NULL)
    181                                 endpoint_toggle_set(instance->ep,
    182                                     td_toggle(&data->tds[i]));
     181                        assert(instance->ep != NULL);
     182
     183                        endpoint_toggle_set(instance->ep,
     184                            td_toggle(&data->tds[i]));
    183185                        if (i > 0)
    184186                                goto substract_ret;
  • uspace/drv/uhci-hcd/batch.h

    r7dfc06fa rc6cb76d  
    4444
    4545usb_transfer_batch_t * batch_get(
    46     ddf_fun_t *fun,
    47                 usb_target_t target,
    48     usb_transfer_type_t transfer_type,
    49                 size_t max_packet_size,
    50     usb_speed_t speed,
    51                 char *buffer,
    52                 size_t size,
    53                 char *setup_buffer,
    54                 size_t setup_size,
     46    ddf_fun_t *fun, endpoint_t *ep, char *buffer, size_t size,
     47    char *setup_buffer, size_t setup_size,
    5548    usbhc_iface_transfer_in_callback_t func_in,
    5649    usbhc_iface_transfer_out_callback_t func_out,
    57                 void *arg,
    58                 endpoint_t *ep
    59                 );
     50    void *arg);
    6051
    6152void batch_dispose(usb_transfer_batch_t *instance);
  • uspace/drv/uhci-hcd/hc.c

    r7dfc06fa rc6cb76d  
    332332            instance->transfers[batch->speed][batch->transfer_type];
    333333        assert(list);
    334         if (batch->transfer_type == USB_TRANSFER_CONTROL) {
    335                 usb_device_keeper_use_control(
    336                     &instance->manager, batch->target);
    337         }
    338334        transfer_list_add_batch(list, batch);
    339335
     
    373369                        usb_transfer_batch_t *batch =
    374370                            list_get_instance(item, usb_transfer_batch_t, link);
    375                         switch (batch->transfer_type)
    376                         {
    377                         case USB_TRANSFER_CONTROL:
    378                                 usb_device_keeper_release_control(
    379                                     &instance->manager, batch->target);
    380                                 break;
    381                         case USB_TRANSFER_INTERRUPT:
    382                         case USB_TRANSFER_ISOCHRONOUS: {
    383 /*
    384                                 int ret = bandwidth_free(&instance->bandwidth,
    385                                     batch->target.address,
    386                                     batch->target.endpoint,
    387                                     batch->direction);
    388                                 if (ret != EOK)
    389                                         usb_log_warning("Failed(%d) to free "
    390                                             "reserved bw: %s.\n", ret,
    391                                             str_error(ret));
    392 */
    393                                 }
    394                         default:
    395                                 break;
    396                         }
    397                         batch->next_step(batch);
     371                        usb_transfer_batch_finish(batch);
    398372                }
    399373        }
  • uspace/drv/uhci-hcd/iface.c

    r7dfc06fa rc6cb76d  
    4040#include "iface.h"
    4141#include "hc.h"
     42
     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
    4289
    4390/** Reserve default address interface function
     
    214261    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    215262{
    216         assert(fun);
    217         hc_t *hc = fun_to_hc(fun);
    218         assert(hc);
    219 
    220         usb_log_debug("Interrupt OUT %d:%d %zu.\n",
    221             target.address, target.endpoint, size);
    222 
    223         size_t res_bw;
    224         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    225             target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw);
    226         if (ep == NULL) {
    227                 usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n",
    228                         target.address, target.endpoint);
    229                 return ENOENT;
    230         }
    231         const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
    232             size, ep->max_packet_size);
    233         if (res_bw < bw)
    234         {
    235                 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
    236                     "but only %zu is reserved.\n",
    237                     target.address, target.endpoint, bw, res_bw);
    238                 return ENOENT;
    239         }
    240         assert(ep->speed ==
    241             usb_device_keeper_get_speed(&hc->manager, target.address));
    242         assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
    243 
    244         usb_transfer_batch_t *batch =
    245             batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
    246                 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    247         if (!batch)
    248                 return ENOMEM;
     263        usb_transfer_batch_t *batch = NULL;
     264        hc_t *hc = NULL;
     265        int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
     266            NULL, 0, NULL, callback, arg, "Interrupt OUT", &hc, &batch);
     267        if (ret != EOK)
     268                return ret;
    249269        batch_interrupt_out(batch);
    250         const int ret = hc_schedule(hc, batch);
     270        ret = hc_schedule(hc, batch);
    251271        if (ret != EOK) {
    252272                batch_dispose(batch);
     
    269289    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    270290{
    271         assert(fun);
    272         hc_t *hc = fun_to_hc(fun);
    273         assert(hc);
    274 
    275         usb_log_debug("Interrupt IN %d:%d %zu.\n",
    276             target.address, target.endpoint, size);
    277 
    278         size_t res_bw;
    279         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    280             target.address, target.endpoint, USB_DIRECTION_IN, &res_bw);
    281         if (ep == NULL) {
    282                 usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n",
    283                     target.address, target.endpoint);
    284                 return ENOENT;
    285         }
    286         const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
    287             size, ep->max_packet_size);
    288         if (res_bw < bw)
    289         {
    290                 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw "
    291                     "but only %zu bw is reserved.\n",
    292                     target.address, target.endpoint, bw, res_bw);
    293                 return ENOENT;
    294         }
    295 
    296         assert(ep->speed ==
    297             usb_device_keeper_get_speed(&hc->manager, target.address));
    298         assert(ep->transfer_type == USB_TRANSFER_INTERRUPT);
    299 
    300         usb_transfer_batch_t *batch =
    301             batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
    302                 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    303         if (!batch)
    304                 return ENOMEM;
     291        usb_transfer_batch_t *batch = NULL;
     292        hc_t *hc = NULL;
     293        int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
     294            NULL, 0, callback, NULL, arg, "Interrupt IN", &hc, &batch);
     295        if (ret != EOK)
     296                return ret;
    305297        batch_interrupt_in(batch);
    306         const int ret = hc_schedule(hc, batch);
     298        ret = hc_schedule(hc, batch);
    307299        if (ret != EOK) {
    308300                batch_dispose(batch);
     
    325317    size_t size, usbhc_iface_transfer_out_callback_t callback, void *arg)
    326318{
    327         assert(fun);
    328         hc_t *hc = fun_to_hc(fun);
    329         assert(hc);
    330 
    331         usb_log_debug("Bulk OUT %d:%d %zu.\n",
    332             target.address, target.endpoint, size);
    333 
    334         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    335             target.address, target.endpoint, USB_DIRECTION_OUT, NULL);
    336         if (ep == NULL) {
    337                 usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n",
    338                         target.address, target.endpoint);
    339                 return ENOENT;
    340         }
    341         assert(ep->speed ==
    342             usb_device_keeper_get_speed(&hc->manager, target.address));
    343         assert(ep->transfer_type == USB_TRANSFER_BULK);
    344 
    345         usb_transfer_batch_t *batch =
    346             batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
    347                 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep);
    348         if (!batch)
    349                 return ENOMEM;
     319        usb_transfer_batch_t *batch = NULL;
     320        hc_t *hc = NULL;
     321        int ret = setup_batch(fun, target, USB_DIRECTION_OUT, data, size,
     322            NULL, 0, NULL, callback, arg, "Bulk OUT", &hc, &batch);
     323        if (ret != EOK)
     324                return ret;
    350325        batch_bulk_out(batch);
    351         const int ret = hc_schedule(hc, batch);
     326        ret = hc_schedule(hc, batch);
    352327        if (ret != EOK) {
    353328                batch_dispose(batch);
     
    370345    size_t size, usbhc_iface_transfer_in_callback_t callback, void *arg)
    371346{
    372         assert(fun);
    373         hc_t *hc = fun_to_hc(fun);
    374         assert(hc);
    375         usb_log_debug("Bulk IN %d:%d %zu.\n",
    376             target.address, target.endpoint, size);
    377 
    378         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    379             target.address, target.endpoint, USB_DIRECTION_IN, NULL);
    380         if (ep == NULL) {
    381                 usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n",
    382                         target.address, target.endpoint);
    383                 return ENOENT;
    384         }
    385         assert(ep->speed ==
    386             usb_device_keeper_get_speed(&hc->manager, target.address));
    387         assert(ep->transfer_type == USB_TRANSFER_BULK);
    388 
    389         usb_transfer_batch_t *batch =
    390             batch_get(fun, target, ep->transfer_type, ep->max_packet_size,
    391                 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep);
    392         if (!batch)
    393                 return ENOMEM;
     347        usb_transfer_batch_t *batch = NULL;
     348        hc_t *hc = NULL;
     349        int ret = setup_batch(fun, target, USB_DIRECTION_IN, data, size,
     350            NULL, 0, callback, NULL, arg, "Bulk IN", &hc, &batch);
     351        if (ret != EOK)
     352                return ret;
    394353        batch_bulk_in(batch);
    395         const int ret = hc_schedule(hc, batch);
     354        ret = hc_schedule(hc, batch);
    396355        if (ret != EOK) {
    397356                batch_dispose(batch);
     
    417376    usbhc_iface_transfer_out_callback_t callback, void *arg)
    418377{
    419         assert(fun);
    420         hc_t *hc = fun_to_hc(fun);
    421         assert(hc);
    422         usb_speed_t speed =
    423             usb_device_keeper_get_speed(&hc->manager, target.address);
    424         usb_log_debug("Control WRITE (%d) %d:%d %zu.\n",
    425             speed, target.address, target.endpoint, size);
    426         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    427             target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
    428         if (ep == NULL) {
    429                 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
    430                         target.address, target.endpoint);
    431         }
    432 
    433         if (setup_size != 8)
    434                 return EINVAL;
    435 
    436         usb_transfer_batch_t *batch =
    437             batch_get(fun, target, USB_TRANSFER_CONTROL, ep->max_packet_size, speed,
    438                 data, size, setup_data, setup_size, NULL, callback, arg, ep);
    439         if (!batch)
    440                 return ENOMEM;
     378        usb_transfer_batch_t *batch = NULL;
     379        hc_t *hc = NULL;
     380        int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
     381            setup_data, setup_size, NULL, callback, arg, "Control WRITE",
     382            &hc, &batch);
     383        if (ret != EOK)
     384                return ret;
    441385        usb_device_keeper_reset_if_need(&hc->manager, target, setup_data);
    442386        batch_control_write(batch);
    443         const int ret = hc_schedule(hc, batch);
     387        ret = hc_schedule(hc, batch);
    444388        if (ret != EOK) {
    445389                batch_dispose(batch);
     
    465409    usbhc_iface_transfer_in_callback_t callback, void *arg)
    466410{
    467         assert(fun);
    468         hc_t *hc = fun_to_hc(fun);
    469         assert(hc);
    470         usb_speed_t speed =
    471             usb_device_keeper_get_speed(&hc->manager, target.address);
    472 
    473         usb_log_debug("Control READ(%d) %d:%d %zu.\n",
    474             speed, target.address, target.endpoint, size);
    475         endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager,
    476             target.address, target.endpoint, USB_DIRECTION_BOTH, NULL);
    477         if (ep == NULL) {
    478                 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n",
    479                         target.address, target.endpoint);
    480         }
    481         usb_transfer_batch_t *batch =
    482             batch_get(fun, target, USB_TRANSFER_CONTROL, ep->max_packet_size, speed,
    483                 data, size, setup_data, setup_size, callback, NULL, arg, ep);
    484         if (!batch)
    485                 return ENOMEM;
     411        usb_transfer_batch_t *batch = NULL;
     412        hc_t *hc = NULL;
     413        int ret = setup_batch(fun, target, USB_DIRECTION_BOTH, data, size,
     414            setup_data, setup_size, callback, NULL, arg, "Control READ",
     415            &hc, &batch);
     416        if (ret != EOK)
     417                return ret;
    486418        batch_control_read(batch);
    487         const int ret = hc_schedule(hc, batch);
     419        ret = hc_schedule(hc, batch);
    488420        if (ret != EOK) {
    489421                batch_dispose(batch);
  • uspace/drv/uhci-hcd/transfer_list.c

    r7dfc06fa rc6cb76d  
    132132}
    133133/*----------------------------------------------------------------------------*/
    134 /** Check list for finished batches.
    135  *
    136  * @param[in] instance List to use.
    137  * @return Error code
    138  *
    139  * Creates a local list of finished batches and calls next_step on each and
    140  * every one. This is safer because next_step may theoretically access
    141  * this transfer list leading to the deadlock if its done inline.
     134/** Create list for finished batches.
     135 *
     136 * @param[in] instance List to use.
     137 * @param[in] done list to fill
    142138 */
    143139void transfer_list_remove_finished(transfer_list_t *instance, link_t *done)
     
    161157        }
    162158        fibril_mutex_unlock(&instance->guard);
    163 
    164159}
    165160/*----------------------------------------------------------------------------*/
     
    176171                    list_get_instance(current, usb_transfer_batch_t, link);
    177172                transfer_list_remove_batch(instance, batch);
    178                 usb_transfer_batch_finish(batch, EIO);
     173                usb_transfer_batch_finish_error(batch, EIO);
    179174        }
    180175        fibril_mutex_unlock(&instance->guard);
Note: See TracChangeset for help on using the changeset viewer.