Changeset c6394aa in mainline for uspace/lib/usb/src


Ignore:
Timestamp:
2011-04-09T16:56:51Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
77223f8
Parents:
b6c9e1e (diff), 5410c04 (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/lib/usb/src
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/devdrv.c

    rb6c9e1e rc6394aa  
    161161
    162162        /*
    163          * For further actions, we need open session on default control pipe.
     163         * We will do some querying of the device, it is worth to prepare
     164         * the long transfer.
    164165         */
    165         rc = usb_pipe_start_session(&dev->ctrl_pipe);
    166         if (rc != EOK) {
    167                 usb_log_error("Failed to start an IPC session: %s.\n",
     166        rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe);
     167        if (rc != EOK) {
     168                usb_log_error("Failed to start transfer: %s.\n",
    168169                    str_error(rc));
    169170                return rc;
     
    185186        }
    186187
    187         /* No checking here. */
    188         usb_pipe_end_session(&dev->ctrl_pipe);
     188        usb_pipe_end_long_transfer(&dev->ctrl_pipe);
    189189
    190190        /* Rollback actions. */
  • uspace/lib/usb/src/devpoll.c

    rb6c9e1e rc6394aa  
    7777                int rc;
    7878
    79                 rc = usb_pipe_start_session(pipe);
    80                 if (rc != EOK) {
    81                         failed_attempts++;
    82                         continue;
    83                 }
    84 
    8579                size_t actual_size;
    8680                rc = usb_pipe_read(pipe, polling_data->buffer,
    8781                    polling_data->request_size, &actual_size);
    8882
    89                 /* Quit the session regardless of errors. */
    90                 usb_pipe_end_session(pipe);
    9183               
    9284//              if (rc == ESTALL) {
  • uspace/lib/usb/src/host/batch.c

    rb6c9e1e rc6394aa  
    6363        instance->transfer_type = transfer_type;
    6464        instance->speed = speed;
    65         instance->direction = USB_DIRECTION_BOTH;
     65        instance->direction = ep->direction;
    6666        instance->callback_in = func_in;
    6767        instance->callback_out = func_out;
  • uspace/lib/usb/src/hub.c

    rb6c9e1e rc6394aa  
    288288        }
    289289
    290 
    291         rc = usb_pipe_start_session(&ctrl_pipe);
    292         if (rc != EOK) {
    293                 rc = ENOTCONN;
     290        rc = usb_request_set_address(&ctrl_pipe, dev_addr);
     291        if (rc != EOK) {
     292                rc = ESTALL;
    294293                goto leave_release_default_address;
    295294        }
    296 
    297         rc = usb_request_set_address(&ctrl_pipe, dev_addr);
    298         if (rc != EOK) {
    299                 rc = ESTALL;
    300                 goto leave_stop_session;
    301         }
    302 
    303         usb_pipe_end_session(&ctrl_pipe);
    304295
    305296        /*
     
    361352         * Completely ignoring errors here.
    362353         */
    363 
    364 leave_stop_session:
    365         usb_pipe_end_session(&ctrl_pipe);
    366 
    367354leave_release_default_address:
    368355        usb_pipe_unregister(&ctrl_pipe, &hc_conn);
  • uspace/lib/usb/src/pipes.c

    rb6c9e1e rc6394aa  
    4141#include <errno.h>
    4242#include <assert.h>
     43#include "pipepriv.h"
    4344
    4445#define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */
     
    241242 * necessary.
    242243 *
     244 * @deprecated
     245 * Obsoleted with introduction of usb_pipe_start_long_transfer
     246 *
    243247 * @param pipe Endpoint pipe to start the session on.
    244248 * @return Error code.
     
    246250int usb_pipe_start_session(usb_pipe_t *pipe)
    247251{
    248         assert(pipe);
    249 
    250         if (usb_pipe_is_session_started(pipe)) {
    251                 return EBUSY;
    252         }
    253 
    254         int phone = devman_device_connect(pipe->wire->hc_handle, 0);
    255         if (phone < 0) {
    256                 return phone;
    257         }
    258 
    259         pipe->hc_phone = phone;
    260 
     252        usb_log_warning("usb_pipe_start_session() was deprecated.\n");
    261253        return EOK;
    262254}
     
    265257/** Ends a session on the endpoint pipe.
    266258 *
     259 * @deprecated
     260 * Obsoleted with introduction of usb_pipe_end_long_transfer
     261 *
    267262 * @see usb_pipe_start_session
    268263 *
     
    272267int usb_pipe_end_session(usb_pipe_t *pipe)
    273268{
    274         assert(pipe);
    275 
    276         if (!usb_pipe_is_session_started(pipe)) {
    277                 return ENOENT;
    278         }
    279 
    280         int rc = async_hangup(pipe->hc_phone);
    281         if (rc != EOK) {
    282                 return rc;
    283         }
    284 
    285         pipe->hc_phone = -1;
    286 
     269        usb_log_warning("usb_pipe_end_session() was deprecated.\n");
    287270        return EOK;
    288271}
     
    298281bool usb_pipe_is_session_started(usb_pipe_t *pipe)
    299282{
    300         return (pipe->hc_phone >= 0);
     283        pipe_acquire(pipe);
     284        bool started = pipe->refcount > 0;
     285        pipe_release(pipe);
     286        return started;
     287}
     288
     289/** Prepare pipe for a long transfer.
     290 *
     291 * By a long transfer is mean transfer consisting of several
     292 * requests to the HC.
     293 * Calling such function is optional and it has positive effect of
     294 * improved performance because IPC session is initiated only once.
     295 *
     296 * @param pipe Pipe over which the transfer will happen.
     297 * @return Error code.
     298 */
     299int usb_pipe_start_long_transfer(usb_pipe_t *pipe)
     300{
     301        return pipe_add_ref(pipe);
     302}
     303
     304/** Terminate a long transfer on a pipe.
     305 *
     306 * @see usb_pipe_start_long_transfer
     307 *
     308 * @param pipe Pipe where to end the long transfer.
     309 */
     310void usb_pipe_end_long_transfer(usb_pipe_t *pipe)
     311{
     312        pipe_drop_ref(pipe);
    301313}
    302314
  • uspace/lib/usb/src/pipesinit.c

    rb6c9e1e rc6394aa  
    356356        assert(connection);
    357357
     358        fibril_mutex_initialize(&pipe->guard);
    358359        pipe->wire = connection;
    359360        pipe->hc_phone = -1;
     361        fibril_mutex_initialize(&pipe->hc_phone_mutex);
    360362        pipe->endpoint_no = endpoint_no;
    361363        pipe->transfer_type = transfer_type;
    362364        pipe->max_packet_size = max_packet_size;
    363365        pipe->direction = direction;
     366        pipe->refcount = 0;
    364367
    365368        return EOK;
     
    413416        int rc;
    414417
    415         TRY_LOOP(failed_attempts) {
    416                 rc = usb_pipe_start_session(pipe);
    417                 if (rc == EOK) {
    418                         break;
    419                 }
    420         }
     418        rc = usb_pipe_start_long_transfer(pipe);
    421419        if (rc != EOK) {
    422420                return rc;
     
    439437                }
    440438        }
    441         usb_pipe_end_session(pipe);
     439        usb_pipe_end_long_transfer(pipe);
    442440        if (rc != EOK) {
    443441                return rc;
  • uspace/lib/usb/src/pipesio.c

    rb6c9e1e rc6394aa  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
     51#include "pipepriv.h"
    5152
    5253/** Request an in transfer, no checking of input parameters.
     
    7879        }
    7980
     81        /* Ensure serialization over the phone. */
     82        pipe_start_transaction(pipe);
     83
    8084        /*
    8185         * Make call identifying target USB device and type of transfer.
     
    8791            NULL);
    8892        if (opening_request == 0) {
     93                pipe_end_transaction(pipe);
    8994                return ENOMEM;
    9095        }
     
    96101        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    97102            &data_request_call);
     103
     104        /*
     105         * Since now on, someone else might access the backing phone
     106         * without breaking the transfer IPC protocol.
     107         */
     108        pipe_end_transaction(pipe);
    98109
    99110        if (data_request == 0) {
     
    146157
    147158        if (buffer == NULL) {
    148                         return EINVAL;
     159                return EINVAL;
    149160        }
    150161
    151162        if (size == 0) {
    152163                return EINVAL;
    153         }
    154 
    155         if (!usb_pipe_is_session_started(pipe)) {
    156                 return EBADF;
    157164        }
    158165
     
    165172        }
    166173
     174        int rc;
     175        rc = pipe_add_ref(pipe);
     176        if (rc != EOK) {
     177                return rc;
     178        }
     179
     180
    167181        size_t act_size = 0;
    168         int rc;
    169182
    170183        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
     184
     185        pipe_drop_ref(pipe);
     186
    171187        if (rc != EOK) {
    172188                return rc;
     
    210226        }
    211227
     228        /* Ensure serialization over the phone. */
     229        pipe_start_transaction(pipe);
     230
    212231        /*
    213232         * Make call identifying target USB device and type of transfer.
     
    219238            NULL);
    220239        if (opening_request == 0) {
     240                pipe_end_transaction(pipe);
    221241                return ENOMEM;
    222242        }
     
    226246         */
    227247        int rc = async_data_write_start(pipe->hc_phone, buffer, size);
     248
     249        /*
     250         * Since now on, someone else might access the backing phone
     251         * without breaking the transfer IPC protocol.
     252         */
     253        pipe_end_transaction(pipe);
     254
    228255        if (rc != EOK) {
    229256                async_wait_for(opening_request, NULL);
     
    260287        }
    261288
    262         if (!usb_pipe_is_session_started(pipe)) {
    263                 return EBADF;
    264         }
    265 
    266289        if (pipe->direction != USB_DIRECTION_OUT) {
    267290                return EBADF;
     
    272295        }
    273296
    274         int rc = usb_pipe_write_no_check(pipe, buffer, size);
     297        int rc;
     298
     299        rc = pipe_add_ref(pipe);
     300        if (rc != EOK) {
     301                return rc;
     302        }
     303
     304        rc = usb_pipe_write_no_check(pipe, buffer, size);
     305
     306        pipe_drop_ref(pipe);
    275307
    276308        return rc;
     
    293325    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    294326{
     327        /* Ensure serialization over the phone. */
     328        pipe_start_transaction(pipe);
     329
    295330        /*
    296331         * Make call identifying target USB device and control transfer type.
     
    311346            setup_buffer, setup_buffer_size);
    312347        if (rc != EOK) {
     348                pipe_end_transaction(pipe);
    313349                async_wait_for(opening_request, NULL);
    314350                return rc;
     
    322358            data_buffer, data_buffer_size,
    323359            &data_request_call);
     360
     361        /*
     362         * Since now on, someone else might access the backing phone
     363         * without breaking the transfer IPC protocol.
     364         */
     365        pipe_end_transaction(pipe);
     366
     367
    324368        if (data_request == 0) {
    325369                async_wait_for(opening_request, NULL);
     
    379423        }
    380424
    381         if (!usb_pipe_is_session_started(pipe)) {
    382                 return EBADF;
    383         }
    384 
    385425        if ((pipe->direction != USB_DIRECTION_BOTH)
    386426            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    388428        }
    389429
     430        int rc;
     431
     432        rc = pipe_add_ref(pipe);
     433        if (rc != EOK) {
     434                return rc;
     435        }
     436
    390437        size_t act_size = 0;
    391         int rc = usb_pipe_control_read_no_check(pipe,
     438        rc = usb_pipe_control_read_no_check(pipe,
    392439            setup_buffer, setup_buffer_size,
    393440            data_buffer, data_buffer_size, &act_size);
     441
     442        pipe_drop_ref(pipe);
    394443
    395444        if (rc != EOK) {
     
    418467    void *data_buffer, size_t data_buffer_size)
    419468{
     469        /* Ensure serialization over the phone. */
     470        pipe_start_transaction(pipe);
     471
    420472        /*
    421473         * Make call identifying target USB device and control transfer type.
     
    428480            NULL);
    429481        if (opening_request == 0) {
     482                pipe_end_transaction(pipe);
    430483                return ENOMEM;
    431484        }
     
    437490            setup_buffer, setup_buffer_size);
    438491        if (rc != EOK) {
     492                pipe_end_transaction(pipe);
    439493                async_wait_for(opening_request, NULL);
    440494                return rc;
     
    447501                rc = async_data_write_start(pipe->hc_phone,
    448502                    data_buffer, data_buffer_size);
     503
     504                /* All data sent, pipe can be released. */
     505                pipe_end_transaction(pipe);
     506
    449507                if (rc != EOK) {
    450508                        async_wait_for(opening_request, NULL);
    451509                        return rc;
    452510                }
     511        } else {
     512                /* No data to send, we can release the pipe for others. */
     513                pipe_end_transaction(pipe);
    453514        }
    454515
     
    491552        }
    492553
    493         if (!usb_pipe_is_session_started(pipe)) {
    494                 return EBADF;
    495         }
    496 
    497554        if ((pipe->direction != USB_DIRECTION_BOTH)
    498555            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    500557        }
    501558
    502         int rc = usb_pipe_control_write_no_check(pipe,
     559        int rc;
     560
     561        rc = pipe_add_ref(pipe);
     562        if (rc != EOK) {
     563                return rc;
     564        }
     565
     566        rc = usb_pipe_control_write_no_check(pipe,
    503567            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
     568
     569        pipe_drop_ref(pipe);
    504570
    505571        return rc;
  • uspace/lib/usb/src/recognise.c

    rb6c9e1e rc6394aa  
    404404        child->driver_data = dev_data;
    405405
    406         rc = usb_pipe_start_session(&ctrl_pipe);
    407         if (rc != EOK) {
    408                 goto failure;
    409         }
    410 
    411406        rc = usb_device_create_match_ids(&ctrl_pipe, &child->match_ids);
    412         if (rc != EOK) {
    413                 goto failure;
    414         }
    415 
    416         rc = usb_pipe_end_session(&ctrl_pipe);
    417407        if (rc != EOK) {
    418408                goto failure;
Note: See TracChangeset for help on using the changeset viewer.