Changes in / [7b715892:8e8b84f] in mainline


Ignore:
Location:
uspace
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/dev.c

    r7b715892 r8e8b84f  
    5050
    5151        int rc;
    52         bool transfer_started = false;
    5352
    5453        rc = usb_device_connection_initialize(&dev->wire, hc_handle, dev_addr);
     
    7776        }
    7877
    79         rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe);
     78        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    8079        if (rc != EOK) {
    8180                fprintf(stderr,
    82                     NAME ": failed to start transfer on control pipe: %s.\n",
     81                    NAME ": failed to start session on control pipe: %s.\n",
    8382                    str_error(rc));
    8483                goto leave;
    8584        }
    86         transfer_started = true;
    8785
    8886        rc = usb_request_get_device_descriptor(&dev->ctrl_pipe,
     
    109107
    110108leave:
    111         if (transfer_started) {
    112                 usb_pipe_end_long_transfer(&dev->ctrl_pipe);
     109        if (usb_pipe_is_session_started(&dev->ctrl_pipe)) {
     110                usb_pipe_end_session(&dev->ctrl_pipe);
    113111        }
    114112
     
    120118void destroy_device(usbinfo_device_t *dev)
    121119{
    122         usb_pipe_end_long_transfer(&dev->ctrl_pipe);
     120        usb_pipe_end_session(&dev->ctrl_pipe);
    123121        free(dev);
    124122}
  • uspace/drv/usbmid/main.c

    r7b715892 r8e8b84f  
    5555        int rc;
    5656
    57         rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe);
     57        rc = usb_pipe_start_session(&dev->ctrl_pipe);
    5858        if (rc != EOK) {
    59                 usb_log_error("Failed to start transfer on control pipe: %s.\n",
     59                usb_log_error("Failed to start session on control pipe: %s.\n",
    6060                    str_error(rc));
    6161                return rc;
     
    6464        bool accept = usbmid_explore_device(dev);
    6565
    66         usb_pipe_end_long_transfer(&dev->ctrl_pipe);
     66        rc = usb_pipe_end_session(&dev->ctrl_pipe);
     67        if (rc != EOK) {
     68                usb_log_warning("Failed to end session on control pipe: %s.\n",
     69                    str_error(rc));
     70        }
    6771
    6872        if (!accept) {
  • uspace/lib/usb/Makefile

    r7b715892 r8e8b84f  
    4343        src/hidparser.c \
    4444        src/hub.c \
    45         src/pipepriv.c \
    4645        src/pipes.c \
    4746        src/pipesinit.c \
  • uspace/lib/usb/include/usb/pipes.h

    r7b715892 r8e8b84f  
    4242#include <ipc/devman.h>
    4343#include <ddf/driver.h>
    44 #include <fibril_synch.h>
    4544
    4645/** Abstraction of a physical connection to the device.
     
    6059 * This endpoint must be bound with existing usb_device_connection_t
    6160 * (i.e. the wire to send data over).
    62  *
    63  * Locking order: if you want to lock both mutexes
    64  * (@c guard and @c hc_phone_mutex), lock @c guard first.
    65  * It is not necessary to lock @c guard if you want to lock @c hc_phone_mutex
    66  * only.
    6761 */
    6862typedef struct {
    69         /** Guard of the whole pipe. */
    70         fibril_mutex_t guard;
    71 
    7263        /** The connection used for sending the data. */
    7364        usb_device_connection_t *wire;
     
    8778        /** Phone to the host controller.
    8879         * Negative when no session is active.
    89          * It is an error to access this member without @c hc_phone_mutex
    90          * being locked.
    91          * If call over the phone is to be made, it must be preceeded by
    92          * call to pipe_add_ref() [internal libusb function].
    9380         */
    9481        int hc_phone;
    95 
    96         /** Guard for serialization of requests over the phone. */
    97         fibril_mutex_t hc_phone_mutex;
    98 
    99         /** Number of active transfers over the pipe. */
    100         int refcount;
    10182} usb_pipe_t;
    10283
     
    160141bool usb_pipe_is_session_started(usb_pipe_t *);
    161142
    162 int usb_pipe_start_long_transfer(usb_pipe_t *);
    163 void usb_pipe_end_long_transfer(usb_pipe_t *);
    164 
    165143int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
    166144int usb_pipe_write(usb_pipe_t *, void *, size_t);
  • uspace/lib/usb/src/devdrv.c

    r7b715892 r8e8b84f  
    239239
    240240        /*
    241          * We will do some querying of the device, it is worth to prepare
    242          * the long transfer.
     241         * For further actions, we need open session on default control pipe.
    243242         */
    244         rc = usb_pipe_start_long_transfer(&dev->ctrl_pipe);
    245         if (rc != EOK) {
    246                 usb_log_error("Failed to start transfer: %s.\n",
     243        rc = usb_pipe_start_session(&dev->ctrl_pipe);
     244        if (rc != EOK) {
     245                usb_log_error("Failed to start an IPC session: %s.\n",
    247246                    str_error(rc));
    248247                return rc;
     
    253252            &dev->descriptors.device);
    254253        if (rc != EOK) {
    255                 usb_pipe_end_long_transfer(&dev->ctrl_pipe);
    256254                usb_log_error("Failed to retrieve device descriptor: %s.\n",
    257255                    str_error(rc));
     
    264262            &dev->descriptors.configuration_size);
    265263        if (rc != EOK) {
    266                 usb_pipe_end_long_transfer(&dev->ctrl_pipe);
    267264                usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",
    268265                    dev->ddf_dev->name, str_error(rc));
     
    274271        }
    275272
    276         usb_pipe_end_long_transfer(&dev->ctrl_pipe);
     273        /* No checking here. */
     274        usb_pipe_end_session(&dev->ctrl_pipe);
    277275
    278276        /* Rollback actions. */
  • uspace/lib/usb/src/devpoll.c

    r7b715892 r8e8b84f  
    7777                int rc;
    7878
     79                rc = usb_pipe_start_session(pipe);
     80                if (rc != EOK) {
     81                        failed_attempts++;
     82                        continue;
     83                }
     84
    7985                size_t actual_size;
    8086                rc = usb_pipe_read(pipe, polling_data->buffer,
    8187                    polling_data->request_size, &actual_size);
    8288
     89                /* Quit the session regardless of errors. */
     90                usb_pipe_end_session(pipe);
    8391               
    8492//              if (rc == ESTALL) {
  • uspace/lib/usb/src/hub.c

    r7b715892 r8e8b84f  
    287287        }
    288288
     289        rc = usb_pipe_start_session(&ctrl_pipe);
     290        if (rc != EOK) {
     291                rc = ENOTCONN;
     292                goto leave_unregister_endpoint;
     293        }
     294
    289295        rc = usb_request_set_address(&ctrl_pipe, dev_addr);
    290296        if (rc != EOK) {
     
    292298                goto leave_stop_session;
    293299        }
     300
     301        usb_pipe_end_session(&ctrl_pipe);
    294302
    295303        /*
  • uspace/lib/usb/src/pipes.c

    r7b715892 r8e8b84f  
    4141#include <errno.h>
    4242#include <assert.h>
    43 #include "pipepriv.h"
    4443
    4544#define IPC_AGAIN_DELAY (1000 * 2) /* 2ms */
     
    242241 * necessary.
    243242 *
    244  * @deprecated
    245  * Obsoleted with introduction of usb_pipe_start_long_transfer
    246  *
    247243 * @param pipe Endpoint pipe to start the session on.
    248244 * @return Error code.
     
    250246int usb_pipe_start_session(usb_pipe_t *pipe)
    251247{
    252         usb_log_warning("usb_pipe_start_session() was deprecated.\n");
     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
    253261        return EOK;
    254262}
     
    257265/** Ends a session on the endpoint pipe.
    258266 *
    259  * @deprecated
    260  * Obsoleted with introduction of usb_pipe_end_long_transfer
    261  *
    262267 * @see usb_pipe_start_session
    263268 *
     
    267272int usb_pipe_end_session(usb_pipe_t *pipe)
    268273{
    269         usb_log_warning("usb_pipe_end_session() was deprecated.\n");
     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
    270287        return EOK;
    271288}
     
    281298bool usb_pipe_is_session_started(usb_pipe_t *pipe)
    282299{
    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  */
    299 int 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  */
    310 void usb_pipe_end_long_transfer(usb_pipe_t *pipe)
    311 {
    312         pipe_drop_ref(pipe);
     300        return (pipe->hc_phone >= 0);
    313301}
    314302
  • uspace/lib/usb/src/pipesinit.c

    r7b715892 r8e8b84f  
    356356        assert(connection);
    357357
    358         fibril_mutex_initialize(&pipe->guard);
    359358        pipe->wire = connection;
    360359        pipe->hc_phone = -1;
    361         fibril_mutex_initialize(&pipe->hc_phone_mutex);
    362360        pipe->endpoint_no = endpoint_no;
    363361        pipe->transfer_type = transfer_type;
    364362        pipe->max_packet_size = max_packet_size;
    365363        pipe->direction = direction;
    366         pipe->refcount = 0;
    367364
    368365        return EOK;
     
    416413        int rc;
    417414
    418         rc = usb_pipe_start_long_transfer(pipe);
     415        TRY_LOOP(failed_attempts) {
     416                rc = usb_pipe_start_session(pipe);
     417                if (rc == EOK) {
     418                        break;
     419                }
     420        }
    419421        if (rc != EOK) {
    420422                return rc;
     
    437439                }
    438440        }
    439         usb_pipe_end_long_transfer(pipe);
     441        usb_pipe_end_session(pipe);
    440442        if (rc != EOK) {
    441443                return rc;
  • uspace/lib/usb/src/pipesio.c

    r7b715892 r8e8b84f  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
    51 #include "pipepriv.h"
    5251
    5352/** Request an in transfer, no checking of input parameters.
     
    7978        }
    8079
    81         /* Ensure serialization over the phone. */
    82         pipe_start_transaction(pipe);
    83 
    8480        /*
    8581         * Make call identifying target USB device and type of transfer.
     
    9187            NULL);
    9288        if (opening_request == 0) {
    93                 pipe_end_transaction(pipe);
    9489                return ENOMEM;
    9590        }
     
    10196        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    10297            &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);
    10998
    11099        if (data_request == 0) {
     
    157146
    158147        if (buffer == NULL) {
    159                 return EINVAL;
     148                        return EINVAL;
    160149        }
    161150
     
    164153        }
    165154
     155        if (!usb_pipe_is_session_started(pipe)) {
     156                return EBADF;
     157        }
     158
    166159        if (pipe->direction != USB_DIRECTION_IN) {
    167160                return EBADF;
     
    172165        }
    173166
     167        size_t act_size = 0;
    174168        int rc;
    175         rc = pipe_add_ref(pipe);
    176         if (rc != EOK) {
    177                 return rc;
    178         }
    179 
    180 
    181         size_t act_size = 0;
    182169
    183170        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
    184 
    185         pipe_drop_ref(pipe);
    186 
    187171        if (rc != EOK) {
    188172                return rc;
     
    226210        }
    227211
    228         /* Ensure serialization over the phone. */
    229         pipe_start_transaction(pipe);
    230 
    231212        /*
    232213         * Make call identifying target USB device and type of transfer.
     
    238219            NULL);
    239220        if (opening_request == 0) {
    240                 pipe_end_transaction(pipe);
    241221                return ENOMEM;
    242222        }
     
    246226         */
    247227        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 
    255228        if (rc != EOK) {
    256229                async_wait_for(opening_request, NULL);
     
    287260        }
    288261
     262        if (!usb_pipe_is_session_started(pipe)) {
     263                return EBADF;
     264        }
     265
    289266        if (pipe->direction != USB_DIRECTION_OUT) {
    290267                return EBADF;
     
    295272        }
    296273
    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);
     274        int rc = usb_pipe_write_no_check(pipe, buffer, size);
    307275
    308276        return rc;
     
    325293    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    326294{
    327         /* Ensure serialization over the phone. */
    328         pipe_start_transaction(pipe);
    329 
    330295        /*
    331296         * Make call identifying target USB device and control transfer type.
     
    346311            setup_buffer, setup_buffer_size);
    347312        if (rc != EOK) {
    348                 pipe_end_transaction(pipe);
    349313                async_wait_for(opening_request, NULL);
    350314                return rc;
     
    358322            data_buffer, data_buffer_size,
    359323            &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 
    368324        if (data_request == 0) {
    369325                async_wait_for(opening_request, NULL);
     
    423379        }
    424380
     381        if (!usb_pipe_is_session_started(pipe)) {
     382                return EBADF;
     383        }
     384
    425385        if ((pipe->direction != USB_DIRECTION_BOTH)
    426386            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    428388        }
    429389
    430         int rc;
    431 
    432         rc = pipe_add_ref(pipe);
    433         if (rc != EOK) {
    434                 return rc;
    435         }
    436 
    437390        size_t act_size = 0;
    438         rc = usb_pipe_control_read_no_check(pipe,
     391        int rc = usb_pipe_control_read_no_check(pipe,
    439392            setup_buffer, setup_buffer_size,
    440393            data_buffer, data_buffer_size, &act_size);
    441 
    442         pipe_drop_ref(pipe);
    443394
    444395        if (rc != EOK) {
     
    467418    void *data_buffer, size_t data_buffer_size)
    468419{
    469         /* Ensure serialization over the phone. */
    470         pipe_start_transaction(pipe);
    471 
    472420        /*
    473421         * Make call identifying target USB device and control transfer type.
     
    480428            NULL);
    481429        if (opening_request == 0) {
    482                 pipe_end_transaction(pipe);
    483430                return ENOMEM;
    484431        }
     
    490437            setup_buffer, setup_buffer_size);
    491438        if (rc != EOK) {
    492                 pipe_end_transaction(pipe);
    493439                async_wait_for(opening_request, NULL);
    494440                return rc;
     
    501447                rc = async_data_write_start(pipe->hc_phone,
    502448                    data_buffer, data_buffer_size);
    503 
    504                 /* All data sent, pipe can be released. */
    505                 pipe_end_transaction(pipe);
    506 
    507449                if (rc != EOK) {
    508450                        async_wait_for(opening_request, NULL);
    509451                        return rc;
    510452                }
    511         } else {
    512                 /* No data to send, we can release the pipe for others. */
    513                 pipe_end_transaction(pipe);
    514453        }
    515454
     
    552491        }
    553492
     493        if (!usb_pipe_is_session_started(pipe)) {
     494                return EBADF;
     495        }
     496
    554497        if ((pipe->direction != USB_DIRECTION_BOTH)
    555498            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    557500        }
    558501
    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,
     502        int rc = usb_pipe_control_write_no_check(pipe,
    567503            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
    568 
    569         pipe_drop_ref(pipe);
    570504
    571505        return rc;
  • uspace/lib/usb/src/recognise.c

    r7b715892 r8e8b84f  
    404404        child->driver_data = dev_data;
    405405
     406        rc = usb_pipe_start_session(&ctrl_pipe);
     407        if (rc != EOK) {
     408                goto failure;
     409        }
     410
    406411        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);
    407417        if (rc != EOK) {
    408418                goto failure;
Note: See TracChangeset for help on using the changeset viewer.