Changeset 8c877b2 in mainline for uspace/drv/uhci-hcd/batch.c


Ignore:
Timestamp:
2011-03-04T13:05:35Z (14 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d49728c
Parents:
dff940f8 (diff), 9a422574 (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 with \usb\development

File:
1 edited

Legend:

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

    rdff940f8 r8c877b2  
    3333 */
    3434#include <errno.h>
    35 
     35#include <str_error.h>
     36
     37#include <usb/usb.h>
    3638#include <usb/debug.h>
    3739
     
    4547static int batch_schedule(batch_t *instance);
    4648
     49static void batch_control(
     50    batch_t *instance, int data_stage, int status_stage);
    4751static void batch_call_in(batch_t *instance);
    4852static void batch_call_out(batch_t *instance);
     
    5357batch_t * batch_get(ddf_fun_t *fun, usb_target_t target,
    5458    usb_transfer_type_t transfer_type, size_t max_packet_size,
    55     dev_speed_t speed, char *buffer, size_t size,
     59    usb_speed_t speed, char *buffer, size_t size,
    5660    char* setup_buffer, size_t setup_size,
    5761    usbhc_iface_transfer_in_callback_t func_in,
     
    9296        instance->transport_buffer =
    9397           (size > 0) ? malloc32(transport_size) : NULL;
     98
    9499        if ((size > 0) && (instance->transport_buffer == NULL)) {
    95100                usb_log_error("Failed to allocate device accessible buffer.\n");
     
    133138
    134139        queue_head_element_td(instance->qh, addr_to_phys(instance->tds));
     140        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
     141            instance, target.address, target.endpoint);
    135142        return instance;
    136143}
     
    139146{
    140147        assert(instance);
    141         usb_log_debug("Checking(%p) %d packet for completion.\n",
     148        usb_log_debug2("Batch(%p) checking %d packet(s) for completion.\n",
    142149            instance, instance->packets);
    143150        instance->transfered_size = 0;
     
    151158                        if (i > 0)
    152159                                instance->transfered_size -= instance->setup_size;
     160                        usb_log_debug("Batch(%p) found error TD(%d):%x.\n",
     161                          instance, i, instance->tds[i].status);
    153162                        return true;
    154163                }
     
    156165                    transfer_descriptor_actual_size(&instance->tds[i]);
    157166        }
    158         /* This is just an ugly trick to support the old API */
    159167        instance->transfered_size -= instance->setup_size;
    160168        return true;
     
    164172{
    165173        assert(instance);
    166 
    167174        /* we are data out, we are supposed to provide data */
    168175        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    169 
    170         int toggle = 0;
    171         /* setup stage */
    172         transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    173             instance->setup_size, toggle, false, instance->target,
    174             USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
    175 
    176         /* data stage */
    177         size_t i = 1;
    178         for (;i < instance->packets - 1; ++i) {
    179                 char *data =
    180                     instance->transport_buffer + ((i - 1) * instance->max_packet_size);
    181                 toggle = 1 - toggle;
    182 
    183                 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    184                     instance->max_packet_size, toggle++, false, instance->target,
    185                     USB_PID_OUT, data, &instance->tds[i + 1]);
    186         }
    187 
    188         /* status stage */
    189         i = instance->packets - 1;
    190         transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    191             0, 1, false, instance->target, USB_PID_IN, NULL, NULL);
    192 
    193         instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
    194 
     176        batch_control(instance, USB_PID_OUT, USB_PID_IN);
    195177        instance->next_step = batch_call_out_and_dispose;
     178        usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);
    196179        batch_schedule(instance);
    197180}
     
    200183{
    201184        assert(instance);
    202 
    203         int toggle = 0;
    204         /* setup stage */
    205         transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    206             instance->setup_size, toggle, false, instance->target,
    207             USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
    208 
    209         /* data stage */
    210         size_t i = 1;
    211         for (;i < instance->packets - 1; ++i) {
    212                 char *data =
    213                     instance->transport_buffer + ((i - 1) * instance->max_packet_size);
    214                 toggle = 1 - toggle;
    215 
    216                 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    217                     instance->max_packet_size, toggle, false, instance->target,
    218                     USB_PID_IN, data, &instance->tds[i + 1]);
    219         }
    220 
    221         /* status stage */
    222         i = instance->packets - 1;
    223         transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    224             0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);
    225 
    226         instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
    227 
     185        batch_control(instance, USB_PID_IN, USB_PID_OUT);
    228186        instance->next_step = batch_call_in_and_dispose;
     187        usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);
    229188        batch_schedule(instance);
    230189}
     
    234193        assert(instance);
    235194
     195        const bool low_speed = instance->speed == USB_SPEED_LOW;
    236196        int toggle = 1;
    237197        size_t i = 0;
     
    244204
    245205                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    246                     instance->max_packet_size, toggle, false, instance->target,
    247                     USB_PID_IN, data, next);
     206                    instance->max_packet_size, toggle, false, low_speed,
     207                    instance->target, USB_PID_IN, data, next);
    248208        }
    249209
     
    251211
    252212        instance->next_step = batch_call_in_and_dispose;
     213        usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);
    253214        batch_schedule(instance);
    254215}
     
    257218{
    258219        assert(instance);
    259 
    260220        memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size);
    261221
     222        const bool low_speed = instance->speed == USB_SPEED_LOW;
    262223        int toggle = 1;
    263224        size_t i = 0;
     
    270231
    271232                transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT,
    272                     instance->max_packet_size, toggle++, false, instance->target,
    273                     USB_PID_OUT, data, next);
     233                    instance->max_packet_size, toggle++, false, low_speed,
     234                    instance->target, USB_PID_OUT, data, next);
    274235        }
    275236
     
    277238
    278239        instance->next_step = batch_call_out_and_dispose;
     240        usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance);
    279241        batch_schedule(instance);
    280242}
    281243/*----------------------------------------------------------------------------*/
     244static void batch_control(
     245    batch_t *instance, int data_stage, int status_stage)
     246{
     247        assert(instance);
     248
     249        const bool low_speed = instance->speed == USB_SPEED_LOW;
     250        int toggle = 0;
     251        /* setup stage */
     252        transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
     253            instance->setup_size, toggle, false, low_speed, instance->target,
     254            USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]);
     255
     256        /* data stage */
     257        size_t packet = 1;
     258        size_t remain_size = instance->buffer_size;
     259        while (remain_size > 0) {
     260                char *data =
     261                    instance->transport_buffer + instance->buffer_size
     262                    - remain_size;
     263
     264                toggle = 1 - toggle;
     265
     266                const size_t packet_size =
     267                    (instance->max_packet_size > remain_size) ?
     268                    remain_size : instance->max_packet_size;
     269
     270                transfer_descriptor_init(&instance->tds[packet],
     271                    DEFAULT_ERROR_COUNT, packet_size, toggle, false, low_speed,
     272                    instance->target, data_stage, data,
     273                    &instance->tds[packet + 1]);
     274
     275                ++packet;
     276                assert(packet < instance->packets);
     277                assert(packet_size <= remain_size);
     278                remain_size -= packet_size;
     279        }
     280
     281        /* status stage */
     282        assert(packet == instance->packets - 1);
     283        transfer_descriptor_init(&instance->tds[packet], DEFAULT_ERROR_COUNT,
     284            0, 1, false, low_speed, instance->target, status_stage, NULL, NULL);
     285
     286
     287        instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG;
     288        usb_log_debug2("Control last TD status: %x.\n",
     289            instance->tds[packet].status);
     290}
     291/*----------------------------------------------------------------------------*/
    282292void batch_call_in(batch_t *instance)
    283293{
     
    288298
    289299        int err = instance->error;
    290         usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type,
    291             err, instance->transfered_size);
     300        usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n",
     301            instance, instance->transfer_type, str_error(err), err,
     302            instance->transfered_size);
    292303
    293304        instance->callback_in(instance->fun,
     
    302313
    303314        int err = instance->error;
    304         usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err);
     315        usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n",
     316            instance, instance->transfer_type, str_error(err), err);
    305317        instance->callback_out(instance->fun,
    306318            err, instance->arg);
     
    311323        assert(instance);
    312324        batch_call_in(instance);
    313         usb_log_debug("Disposing batch: %p.\n", instance);
     325        usb_log_debug("Batch(%p) disposing.\n", instance);
    314326        free32(instance->tds);
    315327        free32(instance->qh);
     
    323335        assert(instance);
    324336        batch_call_out(instance);
    325         usb_log_debug("Disposing batch: %p.\n", instance);
     337        usb_log_debug("Batch(%p) disposing.\n", instance);
    326338        free32(instance->tds);
    327339        free32(instance->qh);
     
    338350        return uhci_schedule(hc, instance);
    339351}
    340 /*----------------------------------------------------------------------------*/
    341 /* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */
    342 void batch_control_setup_old(batch_t *instance)
    343 {
    344         assert(instance);
    345         instance->packets = 1;
    346 
    347         /* setup stage */
    348         transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    349             instance->setup_size, 0, false, instance->target,
    350             USB_PID_SETUP, instance->setup_buffer, NULL);
    351 
    352         instance->next_step = batch_call_out_and_dispose;
    353         batch_schedule(instance);
    354 }
    355 /*----------------------------------------------------------------------------*/
    356 void batch_control_write_data_old(batch_t *instance)
    357 {
    358         assert(instance);
    359         instance->packets -= 2;
    360         batch_interrupt_out(instance);
    361 }
    362 /*----------------------------------------------------------------------------*/
    363 void batch_control_read_data_old(batch_t *instance)
    364 {
    365         assert(instance);
    366         instance->packets -= 2;
    367         batch_interrupt_in(instance);
    368 }
    369 /*----------------------------------------------------------------------------*/
    370 void batch_control_write_status_old(batch_t *instance)
    371 {
    372         assert(instance);
    373         instance->packets = 1;
    374         transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    375             0, 1, false, instance->target, USB_PID_IN, NULL, NULL);
    376         instance->next_step = batch_call_in_and_dispose;
    377         batch_schedule(instance);
    378 }
    379 /*----------------------------------------------------------------------------*/
    380 void batch_control_read_status_old(batch_t *instance)
    381 {
    382         assert(instance);
    383         instance->packets = 1;
    384         transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT,
    385             0, 1, false, instance->target, USB_PID_OUT, NULL, NULL);
    386         instance->next_step = batch_call_out_and_dispose;
    387         batch_schedule(instance);
    388 }
    389352/**
    390353 * @}
Note: See TracChangeset for help on using the changeset viewer.