Changeset a43f1d18 in mainline for uspace/lib/usb/src/hub.c


Ignore:
Timestamp:
2011-04-09T18:26:22Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2ad98fd
Parents:
f35b294 (diff), 97e7e8a (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/lib/usb/src/hub.c

    rf35b294 ra43f1d18  
    4040#include <errno.h>
    4141#include <assert.h>
     42#include <usb/debug.h>
    4243
    4344/** Check that HC connection is alright.
     
    5556
    5657/** Tell host controller to reserve default address.
     58 * @deprecated
    5759 *
    5860 * @param connection Opened connection to host controller.
     
    6567        CHECK_CONNECTION(connection);
    6668
     69        usb_log_warning("usb_hc_reserve_default_address() considered obsolete");
     70
    6771        return async_req_2_0(connection->hc_phone,
    6872            DEV_IFACE_ID(USBHC_DEV_IFACE),
     
    7175
    7276/** Tell host controller to release default address.
     77 * @deprecated
    7378 *
    7479 * @param connection Opened connection to host controller.
     
    7883{
    7984        CHECK_CONNECTION(connection);
     85
     86        usb_log_warning("usb_hc_release_default_address() considered obsolete");
    8087
    8188        return async_req_1_0(connection->hc_phone,
     
    235242        }
    236243
    237 
    238         /*
    239          * Reserve the default address.
    240          */
    241         rc = usb_hc_reserve_default_address(&hc_conn, dev_speed);
    242         if (rc != EOK) {
    243                 rc = EBUSY;
    244                 goto leave_release_free_address;
    245         }
    246 
    247         /*
    248          * Enable the port (i.e. allow signaling through this port).
    249          */
    250         rc = enable_port(port_no, arg);
    251         if (rc != EOK) {
    252                 goto leave_release_default_address;
    253         }
    254 
    255         /*
    256          * Change the address from default to the free one.
    257          * We need to create a new control pipe for that.
     244        /*
     245         * We will not register control pipe on default address.
     246         * The registration might fail. That means that someone else already
     247         * registered that endpoint. We will simply wait and try again.
     248         * (Someone else already wants to add a new device.)
    258249         */
    259250        usb_device_connection_t dev_conn;
     
    262253        if (rc != EOK) {
    263254                rc = ENOTCONN;
    264                 goto leave_release_default_address;
     255                goto leave_release_free_address;
    265256        }
    266257
     
    270261        if (rc != EOK) {
    271262                rc = ENOTCONN;
     263                goto leave_release_free_address;
     264        }
     265
     266        do {
     267                rc = usb_pipe_register_with_speed(&ctrl_pipe, dev_speed, 0,
     268                    &hc_conn);
     269                if (rc != EOK) {
     270                        /* Do not overheat the CPU ;-). */
     271                        async_usleep(10);
     272                }
     273        } while (rc != EOK);
     274
     275        /*
     276         * Endpoint is registered. We can enable the port and change
     277         * device address.
     278         */
     279        rc = enable_port(port_no, arg);
     280        if (rc != EOK) {
    272281                goto leave_release_default_address;
    273282        }
    274283
    275         /* Before sending any traffic, we need to register this
    276          * endpoint.
     284        rc = usb_pipe_probe_default_control(&ctrl_pipe);
     285        if (rc != EOK) {
     286                rc = ESTALL;
     287                goto leave_release_default_address;
     288        }
     289
     290        rc = usb_request_set_address(&ctrl_pipe, dev_addr);
     291        if (rc != EOK) {
     292                rc = ESTALL;
     293                goto leave_release_default_address;
     294        }
     295
     296        /*
     297         * Address changed. We can release the original endpoint, thus
     298         * allowing other to access the default address.
     299         */
     300        unregister_control_endpoint_on_default_address(&hc_conn);
     301
     302        /*
     303         * Time to register the new endpoint.
    277304         */
    278305        rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
    279306        if (rc != EOK) {
    280                 rc = EREFUSED;
    281                 goto leave_release_default_address;
    282         }
    283         rc = usb_pipe_probe_default_control(&ctrl_pipe);
    284         if (rc != EOK) {
    285                 rc = ENOTCONN;
    286                 goto leave_release_default_address;
    287         }
    288 
    289         rc = usb_pipe_start_session(&ctrl_pipe);
    290         if (rc != EOK) {
    291                 rc = ENOTCONN;
    292                 goto leave_unregister_endpoint;
    293         }
    294 
    295         rc = usb_request_set_address(&ctrl_pipe, dev_addr);
    296         if (rc != EOK) {
    297                 rc = ESTALL;
    298                 goto leave_stop_session;
    299         }
    300 
    301         usb_pipe_end_session(&ctrl_pipe);
    302 
    303         /*
    304          * Register the control endpoint for the new device.
    305          */
    306         rc = usb_pipe_register(&ctrl_pipe, 0, &hc_conn);
    307         if (rc != EOK) {
    308                 rc = EREFUSED;
    309                 goto leave_unregister_endpoint;
    310         }
    311 
    312         /*
    313          * Release the original endpoint.
    314          */
    315         unregister_control_endpoint_on_default_address(&hc_conn);
    316 
    317         /*
    318          * Once the address is changed, we can return the default address.
    319          */
    320         usb_hc_release_default_address(&hc_conn);
    321 
     307                goto leave_release_free_address;
     308        }
    322309
    323310        /*
     
    334321        }
    335322
    336 
    337 
    338323        /*
    339324         * And now inform the host controller about the handle.
     
    367352         * Completely ignoring errors here.
    368353         */
    369 
    370 leave_stop_session:
    371         usb_pipe_end_session(&ctrl_pipe);
    372 
    373 leave_unregister_endpoint:
     354leave_release_default_address:
    374355        usb_pipe_unregister(&ctrl_pipe, &hc_conn);
    375 
    376 leave_release_default_address:
    377         usb_hc_release_default_address(&hc_conn);
    378356
    379357leave_release_free_address:
Note: See TracChangeset for help on using the changeset viewer.