Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 4deca9b in mainline


Ignore:
Timestamp:
2011-04-12T11:43:35Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
651b352
Parents:
1324ff3 (diff), 910ca3f (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:

Extensive cleanup, preparation for OHCI rework

Location:
uspace
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/batch.c

    r1324ff3 r4deca9b  
    7373        CHECK_NULL_DISPOSE_RETURN(instance,
    7474            "Failed to allocate batch instance.\n");
    75         usb_target_t target =
    76             { .address = ep->address, .endpoint = ep->endpoint };
    77         usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed,
    78             ep->max_packet_size, buffer, NULL, buffer_size, NULL, setup_size,
    79             func_in, func_out, arg, fun, ep, NULL);
     75        usb_transfer_batch_init(instance, ep, buffer, NULL, buffer_size,
     76            NULL, setup_size, func_in, func_out, arg, fun, NULL);
    8077
    8178        ohci_batch_t *data = malloc(sizeof(ohci_batch_t));
     
    10198
    10299        if (buffer_size > 0) {
    103                 instance->transport_buffer = malloc32(buffer_size);
    104                 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
     100                instance->data_buffer = malloc32(buffer_size);
     101                CHECK_NULL_DISPOSE_RETURN(instance->data_buffer,
    105102                    "Failed to allocate device accessible buffer.\n");
    106103        }
     
    124121        free32(data->tds);
    125122        free32(instance->setup_buffer);
    126         free32(instance->transport_buffer);
     123        free32(instance->data_buffer);
    127124        free(data);
    128125        free(instance);
     
    165162        assert(instance);
    166163        /* We are data out, we are supposed to provide data */
    167         memcpy(instance->transport_buffer, instance->buffer,
    168             instance->buffer_size);
     164        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    169165        instance->next_step = batch_call_out_and_dispose;
    170166        batch_control(instance, USB_DIRECTION_OUT, USB_DIRECTION_IN);
     
    183179{
    184180        assert(instance);
    185         assert(instance->direction == USB_DIRECTION_IN);
    186181        instance->next_step = batch_call_in_and_dispose;
    187182        batch_data(instance);
     
    192187{
    193188        assert(instance);
    194         assert(instance->direction == USB_DIRECTION_OUT);
    195189        /* We are data out, we are supposed to provide data */
    196         memcpy(instance->transport_buffer, instance->buffer,
    197             instance->buffer_size);
     190        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    198191        instance->next_step = batch_call_out_and_dispose;
    199192        batch_data(instance);
     
    204197{
    205198        assert(instance);
    206         instance->direction = USB_DIRECTION_IN;
    207199        instance->next_step = batch_call_in_and_dispose;
    208200        batch_data(instance);
     
    213205{
    214206        assert(instance);
    215         instance->direction = USB_DIRECTION_IN;
    216207        instance->next_step = batch_call_in_and_dispose;
    217208        batch_data(instance);
     
    249240        size_t td_current = 1;
    250241        size_t remain_size = instance->buffer_size;
    251         char *transfer_buffer = instance->transport_buffer;
     242        char *buffer = instance->data_buffer;
    252243        while (remain_size > 0) {
    253244                size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ?
     
    255246                toggle = 1 - toggle;
    256247
    257                 td_init(&data->tds[td_current], data_dir, transfer_buffer,
     248                td_init(&data->tds[td_current], data_dir, buffer,
    258249                    transfer_size, toggle);
    259250                td_set_next(&data->tds[td_current], &data->tds[td_current + 1]);
     
    262253                    data->tds[td_current].next, data->tds[td_current].be);
    263254
    264                 transfer_buffer += transfer_size;
     255                buffer += transfer_size;
    265256                remain_size -= transfer_size;
    266257                assert(td_current < data->td_count - 2);
     
    290281        size_t td_current = 0;
    291282        size_t remain_size = instance->buffer_size;
    292         char *transfer_buffer = instance->transport_buffer;
     283        char *buffer = instance->data_buffer;
    293284        while (remain_size > 0) {
    294285                size_t transfer_size = remain_size > OHCI_TD_MAX_TRANSFER ?
     
    296287
    297288                td_init(&data->tds[td_current], instance->ep->direction,
    298                     transfer_buffer, transfer_size, -1);
     289                    buffer, transfer_size, -1);
    299290                td_set_next(&data->tds[td_current], &data->tds[td_current + 1]);
    300291                usb_log_debug("Created DATA TD: %x:%x:%x:%x.\n",
     
    302293                    data->tds[td_current].next, data->tds[td_current].be);
    303294
    304                 transfer_buffer += transfer_size;
     295                buffer += transfer_size;
    305296                remain_size -= transfer_size;
    306297                assert(td_current < data->td_count);
  • uspace/drv/ohci/hc.c

    r1324ff3 r4deca9b  
    5555        assert(hub_fun);
    5656
     57        int ret;
     58
    5759        usb_address_t hub_address =
    5860            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
     61        if (hub_address <= 0) {
     62                usb_log_error("Failed to get OHCI root hub address.\n");
     63                return hub_address;
     64        }
    5965        instance->rh.address = hub_address;
    6066        usb_device_keeper_bind(
    6167            &instance->manager, hub_address, hub_fun->handle);
    6268
    63         endpoint_t *ep = malloc(sizeof(endpoint_t));
    64         assert(ep);
    65         int ret = endpoint_init(ep, hub_address, 0, USB_DIRECTION_BOTH,
    66             USB_TRANSFER_CONTROL, USB_SPEED_FULL, 64);
    67         assert(ret == EOK);
    68         ret = usb_endpoint_manager_register_ep(&instance->ep_manager, ep, 0);
    69         assert(ret == EOK);
     69        ret = usb_endpoint_manager_add_ep(&instance->ep_manager,
     70            hub_address, 0, USB_DIRECTION_BOTH, USB_TRANSFER_CONTROL,
     71            USB_SPEED_FULL, 64, 0);
     72        if (ret != EOK) {
     73                usb_log_error("Failed to add OHCI rh endpoint 0.\n");
     74                usb_device_keeper_release(&instance->manager, hub_address);
     75                return ret;
     76        }
    7077
    7178        char *match_str = NULL;
     79        /* DDF needs heap allocated string */
    7280        ret = asprintf(&match_str, "usb&class=hub");
    73 //      ret = (match_str == NULL) ? ret : EOK;
    7481        if (ret < 0) {
    7582                usb_log_error(
    7683                    "Failed(%d) to create root hub match-id string.\n", ret);
     84                usb_device_keeper_release(&instance->manager, hub_address);
    7785                return ret;
    7886        }
     
    8088        ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
    8189        if (ret != EOK) {
    82                 usb_log_error("Failed add create root hub match-id.\n");
     90                usb_log_error("Failed add root hub match-id.\n");
    8391        }
    8492        return ret;
     
    115123        fibril_mutex_initialize(&instance->guard);
    116124
    117         rh_init(&instance->rh, dev, instance->registers);
     125        rh_init(&instance->rh, instance->registers);
    118126
    119127        if (!interrupts) {
     
    130138        assert(instance);
    131139        assert(batch);
     140        assert(batch->ep);
    132141
    133142        /* check for root hub communication */
    134         if (batch->target.address == instance->rh.address) {
     143        if (batch->ep->address == instance->rh.address) {
    135144                return rh_request(&instance->rh, batch);
    136145        }
    137146
    138147        fibril_mutex_lock(&instance->guard);
    139         switch (batch->transfer_type) {
     148        switch (batch->ep->transfer_type) {
    140149        case USB_TRANSFER_CONTROL:
    141150                instance->registers->control &= ~C_CLE;
    142151                transfer_list_add_batch(
    143                     instance->transfers[batch->transfer_type], batch);
     152                    instance->transfers[batch->ep->transfer_type], batch);
    144153                instance->registers->command_status |= CS_CLF;
    145154                usb_log_debug2("Set CS control transfer filled: %x.\n",
     
    151160                instance->registers->control &= ~C_BLE;
    152161                transfer_list_add_batch(
    153                     instance->transfers[batch->transfer_type], batch);
     162                    instance->transfers[batch->ep->transfer_type], batch);
    154163                instance->registers->command_status |= CS_BLF;
    155164                usb_log_debug2("Set bulk transfer filled: %x.\n",
     
    161170                instance->registers->control &= (~C_PLE & ~C_IE);
    162171                transfer_list_add_batch(
    163                     instance->transfers[batch->transfer_type], batch);
     172                    instance->transfers[batch->ep->transfer_type], batch);
    164173                instance->registers->control |= C_PLE | C_IE;
    165174                usb_log_debug2("Added periodic transfer: %x.\n",
  • uspace/drv/ohci/root_hub.c

    r1324ff3 r4deca9b  
    205205 * @return Error code.
    206206 */
    207 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs) {
     207int rh_init(rh_t *instance, ohci_regs_t *regs) {
    208208        assert(instance);
    209         //instance->address = -1;
    210209        instance->registers = regs;
    211         instance->device = dev;
    212210        instance->port_count =
    213211            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    214212        rh_init_descriptors(instance);
    215213        // set port power mode to no-power-switching
    216         instance->registers->rh_desc_a =
    217                 instance->registers->rh_desc_a | (1<<9);
     214        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    218215
    219216        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
    220 
    221         //start generic usb hub driver
    222 
    223         /* TODO: implement */
    224217        return EOK;
    225218}
     
    237230        assert(request);
    238231        int opResult;
    239         if (request->transfer_type == USB_TRANSFER_CONTROL) {
     232        if (request->ep->transfer_type == USB_TRANSFER_CONTROL) {
    240233                usb_log_info("Root hub got CONTROL packet\n");
    241234                opResult = process_ctrl_request(instance, request);
    242         } else if (request->transfer_type == USB_TRANSFER_INTERRUPT) {
     235        } else if (request->ep->transfer_type == USB_TRANSFER_INTERRUPT) {
    243236                usb_log_info("Root hub got INTERRUPT packet\n");
    244237                void * buffer;
    245238                create_interrupt_mask(instance, &buffer,
    246239                        &(request->transfered_size));
    247                 memcpy(request->transport_buffer, buffer,
     240                memcpy(request->data_buffer, buffer,
    248241                        request->transfered_size);
    249242                opResult = EOK;
     
    374367        if (port < 1 || port > instance->port_count)
    375368                return EINVAL;
    376         uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
     369        uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    377370        request->transfered_size = 4;
    378371        uint32_buffer[0] = instance->registers->rh_port_status[port - 1];
     
    400393static int process_get_hub_status_request(rh_t *instance,
    401394        usb_transfer_batch_t * request) {
    402         uint32_t * uint32_buffer = (uint32_t*) request->transport_buffer;
     395        uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    403396        request->transfered_size = 4;
    404397        //bits, 0,1,16,17
     
    550543        }
    551544        request->transfered_size = size;
    552         memcpy(request->transport_buffer, result_descriptor, size);
     545        memcpy(request->data_buffer, result_descriptor, size);
    553546        if (del)
    554547                free(result_descriptor);
     
    571564        if (request->buffer_size != 1)
    572565                return EINVAL;
    573         request->transport_buffer[0] = 1;
     566        request->data_buffer[0] = 1;
    574567        request->transfered_size = 1;
    575568        return EOK;
  • uspace/drv/ohci/root_hub.h

    r1324ff3 r4deca9b  
    5050        /** usb address of the root hub */
    5151        usb_address_t address;
    52         /** ddf device information */
    53         ddf_dev_t *device;
    5452        /** hub port count */
    5553        int port_count;
     
    5856} rh_t;
    5957
    60 int rh_init(rh_t *instance, ddf_dev_t *dev, ohci_regs_t *regs);
     58int rh_init(rh_t *instance, ohci_regs_t *regs);
    6159
    6260int rh_request(rh_t *instance, usb_transfer_batch_t *request);
  • uspace/drv/uhci-hcd/batch.c

    r1324ff3 r4deca9b  
    3030 */
    3131/** @file
    32  * @brief UHCI driver USB transaction structure
     32 * @brief UHCI driver USB transfer structure
    3333 */
    3434#include <errno.h>
     
    4848        qh_t *qh;
    4949        td_t *tds;
    50         size_t transfers;
     50        size_t td_count;
    5151} uhci_batch_t;
    5252
     
    6161 *
    6262 * @param[in] fun DDF function to pass to callback.
    63  * @param[in] target Device and endpoint target of the transaction.
    64  * @param[in] transfer_type Interrupt, Control or Bulk.
    65  * @param[in] max_packet_size maximum allowed size of data transfers.
    66  * @param[in] speed Speed of the transaction.
     63 * @param[in] ep Communication target
    6764 * @param[in] buffer Data source/destination.
    6865 * @param[in] size Size of the buffer.
    6966 * @param[in] setup_buffer Setup data source (if not NULL)
    7067 * @param[in] setup_size Size of setup_buffer (should be always 8)
    71  * @param[in] func_in function to call on inbound transaction completion
    72  * @param[in] func_out function to call on outbound transaction completion
     68 * @param[in] func_in function to call on inbound transfer completion
     69 * @param[in] func_out function to call on outbound transfer completion
    7370 * @param[in] arg additional parameter to func_in or func_out
    74  * @param[in] ep Pointer to endpoint toggle management structure.
    7571 * @return Valid pointer if all substructures were successfully created,
    7672 * NULL otherwise.
    7773 *
    78  * Determines the number of needed transfers (TDs). Prepares a transport buffer
    79  * (that is accessible by the hardware). Initializes parameters needed for the
    80  * transaction and callback.
     74 * Determines the number of needed transfer descriptors (TDs).
     75 * Prepares a transport buffer (that is accessible by the hardware).
     76 * Initializes parameters needed for the transfer and callback.
    8177 */
    8278usb_transfer_batch_t * batch_get(ddf_fun_t *fun, endpoint_t *ep,
     
    10399        usb_target_t target =
    104100            { .address = ep->address, .endpoint = ep->endpoint };
    105         usb_transfer_batch_init(instance, target, ep->transfer_type, ep->speed,
    106             ep->max_packet_size, buffer, NULL, buffer_size, NULL, setup_size,
    107             func_in, func_out, arg, fun, ep, NULL);
     101        usb_transfer_batch_init(instance, ep,
     102            buffer, NULL, buffer_size, NULL, setup_size,
     103            func_in, func_out, arg, fun, NULL);
    108104
    109105
     
    113109        instance->private_data = data;
    114110
    115         data->transfers =
     111        data->td_count =
    116112            (buffer_size + ep->max_packet_size - 1) / ep->max_packet_size;
    117113        if (ep->transfer_type == USB_TRANSFER_CONTROL) {
    118                 data->transfers += 2;
    119         }
    120 
    121         data->tds = malloc32(sizeof(td_t) * data->transfers);
     114                data->td_count += 2;
     115        }
     116
     117        data->tds = malloc32(sizeof(td_t) * data->td_count);
    122118        CHECK_NULL_DISPOSE_RETURN(
    123119            data->tds, "Failed to allocate transfer descriptors.\n");
    124         bzero(data->tds, sizeof(td_t) * data->transfers);
     120        bzero(data->tds, sizeof(td_t) * data->td_count);
    125121
    126122        data->qh = malloc32(sizeof(qh_t));
     
    131127
    132128        if (buffer_size > 0) {
    133                 instance->transport_buffer = malloc32(buffer_size);
    134                 CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
     129                instance->data_buffer = malloc32(buffer_size);
     130                CHECK_NULL_DISPOSE_RETURN(instance->data_buffer,
    135131                    "Failed to allocate device accessible buffer.\n");
    136132        }
     
    154150 *
    155151 * Walk all TDs. Stop with false if there is an active one (it is to be
    156  * processed). Stop with true if an error is found. Return true if the last TS
     152 * processed). Stop with true if an error is found. Return true if the last TD
    157153 * is reached.
    158154 */
     
    164160
    165161        usb_log_debug2("Batch(%p) checking %d transfer(s) for completion.\n",
    166             instance, data->transfers);
     162            instance, data->td_count);
    167163        instance->transfered_size = 0;
    168164        size_t i = 0;
    169         for (;i < data->transfers; ++i) {
     165        for (;i < data->td_count; ++i) {
    170166                if (td_is_active(&data->tds[i])) {
    171167                        return false;
     
    177173                            instance, i, data->tds[i].status);
    178174                        td_print_status(&data->tds[i]);
     175
    179176                        assert(instance->ep != NULL);
    180 
    181177                        endpoint_toggle_set(instance->ep,
    182178                            td_toggle(&data->tds[i]));
     
    195191}
    196192/*----------------------------------------------------------------------------*/
    197 /** Prepares control write transaction.
    198  *
    199  * @param[in] instance Batch structure to use.
    200  *
    201  * Uses genercir control function with pids OUT and IN.
     193/** Prepares control write transfer.
     194 *
     195 * @param[in] instance Batch structure to use.
     196 *
     197 * Uses generic control function with pids OUT and IN.
    202198 */
    203199void batch_control_write(usb_transfer_batch_t *instance)
     
    205201        assert(instance);
    206202        /* We are data out, we are supposed to provide data */
    207         memcpy(instance->transport_buffer, instance->buffer,
    208             instance->buffer_size);
     203        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    209204        batch_control(instance, USB_PID_OUT, USB_PID_IN);
    210205        instance->next_step = batch_call_out_and_dispose;
     
    212207}
    213208/*----------------------------------------------------------------------------*/
    214 /** Prepares control read transaction.
     209/** Prepares control read transfer.
    215210 *
    216211 * @param[in] instance Batch structure to use.
     
    226221}
    227222/*----------------------------------------------------------------------------*/
    228 /** Prepare interrupt in transaction.
    229  *
    230  * @param[in] instance Batch structure to use.
    231  *
    232  * Data transaction with PID_IN.
     223/** Prepare interrupt in transfer.
     224 *
     225 * @param[in] instance Batch structure to use.
     226 *
     227 * Data transfer with PID_IN.
    233228 */
    234229void batch_interrupt_in(usb_transfer_batch_t *instance)
    235230{
    236231        assert(instance);
    237         instance->direction = USB_DIRECTION_IN;
    238232        batch_data(instance, USB_PID_IN);
    239233        instance->next_step = batch_call_in_and_dispose;
     
    241235}
    242236/*----------------------------------------------------------------------------*/
    243 /** Prepare interrupt out transaction.
    244  *
    245  * @param[in] instance Batch structure to use.
    246  *
    247  * Data transaction with PID_OUT.
     237/** Prepare interrupt out transfer.
     238 *
     239 * @param[in] instance Batch structure to use.
     240 *
     241 * Data transfer with PID_OUT.
    248242 */
    249243void batch_interrupt_out(usb_transfer_batch_t *instance)
    250244{
    251245        assert(instance);
    252         instance->direction = USB_DIRECTION_OUT;
    253246        /* We are data out, we are supposed to provide data */
    254         memcpy(instance->transport_buffer, instance->buffer,
    255             instance->buffer_size);
     247        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    256248        batch_data(instance, USB_PID_OUT);
    257249        instance->next_step = batch_call_out_and_dispose;
     
    259251}
    260252/*----------------------------------------------------------------------------*/
    261 /** Prepare bulk in transaction.
    262  *
    263  * @param[in] instance Batch structure to use.
    264  *
    265  * Data transaction with PID_IN.
     253/** Prepare bulk in transfer.
     254 *
     255 * @param[in] instance Batch structure to use.
     256 *
     257 * Data transfer with PID_IN.
    266258 */
    267259void batch_bulk_in(usb_transfer_batch_t *instance)
     
    269261        assert(instance);
    270262        batch_data(instance, USB_PID_IN);
    271         instance->direction = USB_DIRECTION_IN;
    272263        instance->next_step = batch_call_in_and_dispose;
    273264        usb_log_debug("Batch(%p) BULK IN initialized.\n", instance);
    274265}
    275266/*----------------------------------------------------------------------------*/
    276 /** Prepare bulk out transaction.
    277  *
    278  * @param[in] instance Batch structure to use.
    279  *
    280  * Data transaction with PID_OUT.
     267/** Prepare bulk out transfer.
     268 *
     269 * @param[in] instance Batch structure to use.
     270 *
     271 * Data transfer with PID_OUT.
    281272 */
    282273void batch_bulk_out(usb_transfer_batch_t *instance)
    283274{
    284275        assert(instance);
    285         instance->direction = USB_DIRECTION_OUT;
    286276        /* We are data out, we are supposed to provide data */
    287         memcpy(instance->transport_buffer, instance->buffer,
    288             instance->buffer_size);
     277        memcpy(instance->data_buffer, instance->buffer, instance->buffer_size);
    289278        batch_data(instance, USB_PID_OUT);
    290279        instance->next_step = batch_call_out_and_dispose;
     
    292281}
    293282/*----------------------------------------------------------------------------*/
    294 /** Prepare generic data transaction
    295  *
    296  * @param[in] instance Batch structure to use.
    297  * @param[in] pid Pid to use for data transfers.
    298  *
    299  * Packets with alternating toggle bit and supplied pid value.
     283/** Prepare generic data transfer
     284 *
     285 * @param[in] instance Batch structure to use.
     286 * @param[in] pid Pid to use for data transactions.
     287 *
     288 * Transactions with alternating toggle bit and supplied pid value.
    300289 * The last transfer is marked with IOC flag.
    301290 */
     
    306295        assert(data);
    307296
    308         const bool low_speed = instance->speed == USB_SPEED_LOW;
     297        const bool low_speed = instance->ep->speed == USB_SPEED_LOW;
    309298        int toggle = endpoint_toggle_get(instance->ep);
    310299        assert(toggle == 0 || toggle == 1);
    311300
    312         size_t transfer = 0;
     301        size_t td = 0;
    313302        size_t remain_size = instance->buffer_size;
     303        char *buffer = instance->data_buffer;
    314304        while (remain_size > 0) {
    315                 char *trans_data =
    316                     instance->transport_buffer + instance->buffer_size
    317                     - remain_size;
    318 
    319305                const size_t packet_size =
    320                     (instance->max_packet_size > remain_size) ?
    321                     remain_size : instance->max_packet_size;
    322 
    323                 td_t *next_transfer = (transfer + 1 < data->transfers)
    324                     ? &data->tds[transfer + 1] : NULL;
    325 
    326                 assert(transfer < data->transfers);
     306                    (instance->ep->max_packet_size > remain_size) ?
     307                    remain_size : instance->ep->max_packet_size;
     308
     309                td_t *next_td = (td + 1 < data->td_count)
     310                    ? &data->tds[td + 1] : NULL;
     311
     312
     313                usb_target_t target =
     314                    { instance->ep->address, instance->ep->endpoint };
     315
     316                assert(td < data->td_count);
     317                td_init(
     318                    &data->tds[td], DEFAULT_ERROR_COUNT, packet_size,
     319                    toggle, false, low_speed, target, pid, buffer, next_td);
     320
     321                ++td;
     322                toggle = 1 - toggle;
     323                buffer += packet_size;
    327324                assert(packet_size <= remain_size);
    328 
    329                 td_init(
    330                     &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size,
    331                     toggle, false, low_speed, instance->target, pid, trans_data,
    332                     next_transfer);
    333 
    334 
    335                 toggle = 1 - toggle;
    336325                remain_size -= packet_size;
    337                 ++transfer;
    338         }
    339         td_set_ioc(&data->tds[transfer - 1]);
     326        }
     327        td_set_ioc(&data->tds[td - 1]);
    340328        endpoint_toggle_set(instance->ep, toggle);
    341329}
    342330/*----------------------------------------------------------------------------*/
    343 /** Prepare generic control transaction
    344  *
    345  * @param[in] instance Batch structure to use.
    346  * @param[in] data_stage Pid to use for data transfers.
    347  * @param[in] status_stage Pid to use for data transfers.
     331/** Prepare generic control transfer
     332 *
     333 * @param[in] instance Batch structure to use.
     334 * @param[in] data_stage Pid to use for data tds.
     335 * @param[in] status_stage Pid to use for data tds.
    348336 *
    349337 * Setup stage with toggle 0 and USB_PID_SETUP.
     
    358346        uhci_batch_t *data = instance->private_data;
    359347        assert(data);
    360         assert(data->transfers >= 2);
    361 
    362         const bool low_speed = instance->speed == USB_SPEED_LOW;
    363         int toggle = 0;
     348        assert(data->td_count >= 2);
     349
     350        const bool low_speed = instance->ep->speed == USB_SPEED_LOW;
     351        const usb_target_t target =
     352            { instance->ep->address, instance->ep->endpoint };
     353
    364354        /* setup stage */
    365355        td_init(
    366             data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, toggle, false,
    367             low_speed, instance->target, USB_PID_SETUP, instance->setup_buffer,
     356            data->tds, DEFAULT_ERROR_COUNT, instance->setup_size, 0, false,
     357            low_speed, target, USB_PID_SETUP, instance->setup_buffer,
    368358            &data->tds[1]);
    369359
    370360        /* data stage */
    371         size_t transfer = 1;
     361        size_t td = 1;
     362        unsigned toggle = 1;
    372363        size_t remain_size = instance->buffer_size;
     364        char *buffer = instance->data_buffer;
    373365        while (remain_size > 0) {
    374                 char *control_data =
    375                     instance->transport_buffer + instance->buffer_size
    376                     - remain_size;
    377 
     366                const size_t packet_size =
     367                    (instance->ep->max_packet_size > remain_size) ?
     368                    remain_size : instance->ep->max_packet_size;
     369
     370                td_init(
     371                    &data->tds[td], DEFAULT_ERROR_COUNT, packet_size,
     372                    toggle, false, low_speed, target, data_stage,
     373                    buffer, &data->tds[td + 1]);
     374
     375                ++td;
    378376                toggle = 1 - toggle;
    379 
    380                 const size_t packet_size =
    381                     (instance->max_packet_size > remain_size) ?
    382                     remain_size : instance->max_packet_size;
    383 
    384                 td_init(
    385                     &data->tds[transfer], DEFAULT_ERROR_COUNT, packet_size,
    386                     toggle, false, low_speed, instance->target, data_stage,
    387                     control_data, &data->tds[transfer + 1]);
    388 
    389                 ++transfer;
    390                 assert(transfer < data->transfers);
     377                buffer += packet_size;
     378                assert(td < data->td_count);
    391379                assert(packet_size <= remain_size);
    392380                remain_size -= packet_size;
     
    394382
    395383        /* status stage */
    396         assert(transfer == data->transfers - 1);
     384        assert(td == data->td_count - 1);
    397385
    398386        td_init(
    399             &data->tds[transfer], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
    400             instance->target, status_stage, NULL, NULL);
    401         td_set_ioc(&data->tds[transfer]);
     387            &data->tds[td], DEFAULT_ERROR_COUNT, 0, 1, false, low_speed,
     388            target, status_stage, NULL, NULL);
     389        td_set_ioc(&data->tds[td]);
    402390
    403391        usb_log_debug2("Control last TD status: %x.\n",
    404             data->tds[transfer].status);
     392            data->tds[td].status);
    405393}
    406394/*----------------------------------------------------------------------------*/
     
    413401}
    414402/*----------------------------------------------------------------------------*/
    415 /** Helper function calls callback and correctly disposes of batch structure.
     403/** Helper function, calls callback and correctly destroys batch structure.
    416404 *
    417405 * @param[in] instance Batch structure to use.
     
    424412}
    425413/*----------------------------------------------------------------------------*/
    426 /** Helper function calls callback and correctly disposes of batch structure.
     414/** Helper function calls callback and correctly destroys batch structure.
    427415 *
    428416 * @param[in] instance Batch structure to use.
     
    449437        free32(data->qh);
    450438        free32(instance->setup_buffer);
    451         free32(instance->transport_buffer);
     439        free32(instance->data_buffer);
    452440        free(data);
    453441        free(instance);
  • uspace/drv/uhci-hcd/hc.c

    r1324ff3 r4deca9b  
    329329
    330330        transfer_list_t *list =
    331             instance->transfers[batch->speed][batch->transfer_type];
     331            instance->transfers[batch->ep->speed][batch->ep->transfer_type];
    332332        assert(list);
    333333        transfer_list_add_batch(list, batch);
  • uspace/drv/uhci-hcd/iface.c

    r1324ff3 r4deca9b  
    148148        assert(hc);
    149149        const size_t size = max_packet_size;
    150         int ret;
    151150        usb_speed_t speed = usb_device_keeper_get_speed(&hc->manager, address);
    152151        if (speed >= USB_SPEED_MAX) {
     
    157156            usb_str_speed(speed), direction, size, max_packet_size, interval);
    158157
    159 
    160         endpoint_t *ep = malloc(sizeof(endpoint_t));
    161         if (ep == NULL)
    162                 return ENOMEM;
    163         ret = endpoint_init(ep, address, endpoint, direction,
    164             transfer_type, speed, max_packet_size);
    165         if (ret != EOK) {
    166                 free(ep);
    167                 return ret;
    168         }
    169 
    170         ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size);
    171         if (ret != EOK) {
    172                 endpoint_destroy(ep);
    173         }
    174         return ret;
     158        return usb_endpoint_manager_add_ep(&hc->ep_manager, address, endpoint,
     159            direction, transfer_type, speed, max_packet_size, size);
    175160}
    176161/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/include/usb/host/batch.h

    r1324ff3 r4deca9b  
    4343typedef struct usb_transfer_batch usb_transfer_batch_t;
    4444struct usb_transfer_batch {
     45        endpoint_t *ep;
    4546        link_t link;
    46         usb_target_t target;
    47         usb_transfer_type_t transfer_type;
    48         usb_speed_t speed;
    49         usb_direction_t direction;
    5047        usbhc_iface_transfer_in_callback_t callback_in;
    5148        usbhc_iface_transfer_out_callback_t callback_out;
     49        void *arg;
    5250        char *buffer;
    53         char *transport_buffer;
     51        char *data_buffer;
    5452        size_t buffer_size;
    5553        char *setup_buffer;
    5654        size_t setup_size;
    57         size_t max_packet_size;
    5855        size_t transfered_size;
    5956        void (*next_step)(usb_transfer_batch_t *);
    6057        int error;
    6158        ddf_fun_t *fun;
    62         void *arg;
    63         endpoint_t *ep;
    6459        void *private_data;
    6560};
     
    6762void usb_transfer_batch_init(
    6863    usb_transfer_batch_t *instance,
    69     usb_target_t target,
    70     usb_transfer_type_t transfer_type,
    71     usb_speed_t speed,
    72     size_t max_packet_size,
     64                endpoint_t *ep,
    7365    char *buffer,
    74     char *transport_buffer,
     66    char *data_buffer,
    7567    size_t buffer_size,
    7668    char *setup_buffer,
     
    8072    void *arg,
    8173    ddf_fun_t *fun,
    82                 endpoint_t *ep,
    8374    void *private_data
    8475);
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r1324ff3 r4deca9b  
    5454        usb_speed_t speed;
    5555        bool occupied;
    56         link_t endpoints;
    57         uint16_t control_used;
    5856        devman_handle_t handle;
    5957};
     
    6563        struct usb_device_info devices[USB_ADDRESS_COUNT];
    6664        fibril_mutex_t guard;
    67         fibril_condvar_t change;
    6865        usb_address_t last_address;
    6966} usb_device_keeper_t;
    7067
    7168void usb_device_keeper_init(usb_device_keeper_t *instance);
    72 
    73 void usb_device_keeper_reserve_default_address(
    74     usb_device_keeper_t *instance, usb_speed_t speed);
    75 
    76 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance);
    77 
    78 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
    79     usb_target_t target, const uint8_t *setup_data);
    8069
    8170usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
  • uspace/lib/usb/include/usb/host/usb_endpoint_manager.h

    r1324ff3 r4deca9b  
    6666    endpoint_t *ep, size_t data_size);
    6767
    68 int usb_endpoint_manager_register_ep_wait(usb_endpoint_manager_t *instance,
    69     usb_address_t address, usb_endpoint_t ep, usb_direction_t direction,
    70     void *data, void (*data_remove_callback)(void* data, void* arg), void *arg,
    71     size_t bw);
    72 
    7368int usb_endpoint_manager_unregister_ep(usb_endpoint_manager_t *instance,
    7469    usb_address_t address, usb_endpoint_t ep, usb_direction_t direction);
     
    8075void usb_endpoint_manager_reset_if_need(
    8176    usb_endpoint_manager_t *instance, usb_target_t target, const uint8_t *data);
     77
     78static inline int usb_endpoint_manager_add_ep(usb_endpoint_manager_t *instance,
     79    usb_address_t address, usb_endpoint_t endpoint, usb_direction_t direction,
     80    usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size,
     81    size_t data_size)
     82{
     83        endpoint_t *ep = malloc(sizeof(endpoint_t));
     84        if (ep == NULL)
     85                return ENOMEM;
     86
     87        int ret = endpoint_init(ep, address, endpoint, direction, type, speed,
     88            max_packet_size);
     89        if (ret != EOK) {
     90                free(ep);
     91                return ret;
     92        }
     93
     94        ret = usb_endpoint_manager_register_ep(instance, ep, data_size);
     95        if (ret != EOK) {
     96                endpoint_destroy(ep);
     97                return ret;
     98        }
     99        return EOK;
     100}
    82101#endif
    83102/**
  • uspace/lib/usb/src/host/batch.c

    r1324ff3 r4deca9b  
    4141void usb_transfer_batch_init(
    4242    usb_transfer_batch_t *instance,
    43     usb_target_t target,
    44     usb_transfer_type_t transfer_type,
    45     usb_speed_t speed,
    46     size_t max_packet_size,
     43                endpoint_t *ep,
    4744    char *buffer,
    48     char *transport_buffer,
     45    char *data_buffer,
    4946    size_t buffer_size,
    5047    char *setup_buffer,
     
    5451    void *arg,
    5552    ddf_fun_t *fun,
    56                 endpoint_t *ep,
    5753    void *private_data
    5854    )
     
    6056        assert(instance);
    6157        link_initialize(&instance->link);
    62         instance->target = target;
    63         instance->transfer_type = transfer_type;
    64         instance->speed = speed;
    65         instance->direction = ep->direction;
     58        instance->ep = ep;
    6659        instance->callback_in = func_in;
    6760        instance->callback_out = func_out;
    6861        instance->arg = arg;
    6962        instance->buffer = buffer;
    70         instance->transport_buffer = transport_buffer;
     63        instance->data_buffer = data_buffer;
    7164        instance->buffer_size = buffer_size;
    7265        instance->setup_buffer = setup_buffer;
    7366        instance->setup_size = setup_size;
    74         instance->max_packet_size = max_packet_size;
    7567        instance->fun = fun;
    7668        instance->private_data = private_data;
     
    7870        instance->next_step = NULL;
    7971        instance->error = EOK;
    80         instance->ep = ep;
    8172        endpoint_use(instance->ep);
    8273}
     
    10596        assert(instance);
    10697        assert(instance->callback_in);
     98        assert(instance->ep);
    10799
    108100        /* We are data in, we need data */
    109         memcpy(instance->buffer, instance->transport_buffer,
    110             instance->buffer_size);
     101        memcpy(instance->buffer, instance->data_buffer, instance->buffer_size);
    111102
    112103        usb_log_debug("Batch %p done (T%d.%d, %s %s in, %zuB): %s (%d).\n",
    113             instance,
    114             instance->target.address, instance->target.endpoint,
    115             usb_str_speed(instance->speed),
    116             usb_str_transfer_type_short(instance->transfer_type),
    117             instance->transfered_size,
    118             str_error(instance->error), instance->error);
     104            instance, instance->ep->address, instance->ep->endpoint,
     105            usb_str_speed(instance->ep->speed),
     106            usb_str_transfer_type_short(instance->ep->transfer_type),
     107            instance->transfered_size, str_error(instance->error), instance->error);
    119108
    120109        instance->callback_in(instance->fun, instance->error,
     
    132121
    133122        usb_log_debug("Batch %p done (T%d.%d, %s %s out): %s (%d).\n",
    134             instance,
    135             instance->target.address, instance->target.endpoint,
    136             usb_str_speed(instance->speed),
    137             usb_str_transfer_type_short(instance->transfer_type),
     123            instance, instance->ep->address, instance->ep->endpoint,
     124            usb_str_speed(instance->ep->speed),
     125            usb_str_transfer_type_short(instance->ep->transfer_type),
    138126            str_error(instance->error), instance->error);
    139127
  • uspace/lib/usb/src/host/device_keeper.c

    r1324ff3 r4deca9b  
    4848{
    4949        assert(instance);
    50         fibril_mutex_initialize(&instance->guard);
    51         fibril_condvar_initialize(&instance->change);
    52         instance->last_address = 0;
    5350        unsigned i = 0;
    5451        for (; i < USB_ADDRESS_COUNT; ++i) {
     
    6057        // (it is needed to allow smooth registration at default address)
    6158        instance->devices[0].occupied = true;
     59        instance->last_address = 0;
     60        fibril_mutex_initialize(&instance->guard);
    6261}
    63 /*----------------------------------------------------------------------------*/
    64 /** Attempt to obtain address 0, blocks.
    65  *
    66  * @param[in] instance Device keeper structure to use.
    67  * @param[in] speed Speed of the device requesting default address.
    68  */
    69 void usb_device_keeper_reserve_default_address(
    70     usb_device_keeper_t *instance, usb_speed_t speed)
    71 {
    72         assert(instance);
    73         fibril_mutex_lock(&instance->guard);
    74         while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {
    75                 fibril_condvar_wait(&instance->change, &instance->guard);
    76         }
    77         instance->devices[USB_ADDRESS_DEFAULT].occupied = true;
    78         instance->devices[USB_ADDRESS_DEFAULT].speed = speed;
    79         fibril_mutex_unlock(&instance->guard);
    80 }
    81 /*----------------------------------------------------------------------------*/
    82 /** Attempt to obtain address 0, blocks.
    83  *
    84  * @param[in] instance Device keeper structure to use.
    85  * @param[in] speed Speed of the device requesting default address.
    86  */
    87 void usb_device_keeper_release_default_address(usb_device_keeper_t *instance)
    88 {
    89         assert(instance);
    90         fibril_mutex_lock(&instance->guard);
    91         instance->devices[USB_ADDRESS_DEFAULT].occupied = false;
    92         fibril_mutex_unlock(&instance->guard);
    93         fibril_condvar_signal(&instance->change);
    94 }
    95 /*----------------------------------------------------------------------------*/
    9662/*----------------------------------------------------------------------------*/
    9763/** Get a free USB address
     
    12086        assert(new_address != USB_ADDRESS_DEFAULT);
    12187        assert(instance->devices[new_address].occupied == false);
     88
    12289        instance->devices[new_address].occupied = true;
    12390        instance->devices[new_address].speed = speed;
    12491        instance->last_address = new_address;
     92
    12593        fibril_mutex_unlock(&instance->guard);
    12694        return new_address;
     
    138106        assert(instance);
    139107        fibril_mutex_lock(&instance->guard);
     108
    140109        assert(address > 0);
    141110        assert(address <= USB11_ADDRESS_MAX);
    142111        assert(instance->devices[address].occupied);
     112
    143113        instance->devices[address].handle = handle;
    144114        fibril_mutex_unlock(&instance->guard);
     
    159129        fibril_mutex_lock(&instance->guard);
    160130        assert(instance->devices[address].occupied);
     131
    161132        instance->devices[address].occupied = false;
    162133        fibril_mutex_unlock(&instance->guard);
     
    177148        while (address <= USB11_ADDRESS_MAX) {
    178149                if (instance->devices[address].handle == handle) {
     150                        assert(instance->devices[address].occupied);
    179151                        fibril_mutex_unlock(&instance->guard);
    180152                        return address;
     
    198170        assert(address >= 0);
    199171        assert(address <= USB11_ADDRESS_MAX);
     172
    200173        return instance->devices[address].speed;
    201174}
Note: See TracChangeset for help on using the changeset viewer.