Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhub/usbhub.c

    rd81ef61c r28cb8bf7  
    3636#include <bool.h>
    3737#include <errno.h>
     38#include <str_error.h>
    3839
    3940#include <usb_iface.h>
    4041#include <usb/usbdrv.h>
    4142#include <usb/descriptor.h>
     43#include <usb/recognise.h>
    4244#include <usb/devreq.h>
    43 #include <usb/request.h>
    4445#include <usb/classes/hub.h>
    4546
     
    4849#include "port_status.h"
    4950#include "usb/usb.h"
    50 #include "usb/pipes.h"
    5151
    5252static usb_iface_t hub_usb_iface = {
     
    6464//*********************************************
    6565
    66 usb_hub_info_t * usb_create_hub_info(device_t * device) {
     66usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
    6767        usb_hub_info_t* result = usb_new(usb_hub_info_t);
    68         usb_device_connection_initialize_from_device(&result->connection, device);
    69         usb_endpoint_pipe_initialize_default_control(&result->endpoints.control,
    70             &result->connection);
    71        
    72 
    7368        //result->device = device;
    7469        result->port_count = -1;
     
    7671        result->device = device;
    7772
    78         result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    79        
     73
     74        dprintf(USB_LOG_LEVEL_DEBUG, "phone to hc = %d", hc);
     75        if (hc < 0) {
     76                return result;
     77        }
     78        //get some hub info
     79        usb_address_t addr = usb_drv_get_my_address(hc, device);
     80        dprintf(USB_LOG_LEVEL_DEBUG, "address of newly created hub = %d", addr);
     81        /*if(addr<0){
     82                //return result;
     83
     84        }*/
     85
     86        result->address = addr;
     87
    8088        // get hub descriptor
    8189
     
    8694        int opResult;
    8795        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
    88         usb_endpoint_pipe_start_session(&result->endpoints.control);
    89         opResult = usb_request_get_descriptor(&result->endpoints.control,
     96       
     97        opResult = usb_drv_req_get_descriptor(hc, addr,
    9098                        USB_REQUEST_TYPE_CLASS,
    9199                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    92100                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    93         usb_endpoint_pipe_end_session(&result->endpoints.control);
    94 
    95         /* Initialize the interrupt endpoint.
    96         usb_endpoint_pipe_initalize(
    97                 &hub_data->endpoints->status_change,
    98                 &endpiont_descriptor, &hub_data->connection);
    99 
    100          */ /// \TODO add this call
    101101
    102102        if (opResult != EOK) {
     
    143143        dev->ops = &hub_device_ops;
    144144
    145 
    146         usb_hub_info_t * hub_info = usb_create_hub_info(dev);
    147         usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     145        //create the hub structure
     146        //get hc connection
     147        int hc = usb_drv_hc_connect_auto(dev, 0);
     148        if (hc < 0) {
     149                return hc;
     150        }
     151
     152        usb_hub_info_t * hub_info = usb_create_hub_info(dev, hc);
    148153        int port;
    149154        int opResult;
    150         //usb_target_t target;
    151         //target.address = hub_info->usb_device->address;
    152         //target.endpoint = 0;
     155        usb_target_t target;
     156        target.address = hub_info->address;
     157        target.endpoint = 0;
    153158
    154159        //get configuration descriptor
     
    156161        // and all should be checked
    157162        usb_standard_device_descriptor_t std_descriptor;
    158         opResult = usb_request_get_device_descriptor(&hub_info->endpoints.control,
     163        opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    159164            &std_descriptor);
    160165        if(opResult!=EOK){
     
    169174        /// \TODO check other configurations
    170175        usb_standard_configuration_descriptor_t config_descriptor;
    171         opResult = usb_request_get_bare_configuration_descriptor(
    172             &hub_info->endpoints.control, 0,
     176        opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
     177        target.address, 0,
    173178        &config_descriptor);
    174179        if(opResult!=EOK){
     
    177182        }
    178183        //set configuration
    179         opResult = usb_request_set_configuration(&hub_info->endpoints.control,
     184        opResult = usb_drv_req_set_configuration(hc, target.address,
    180185    config_descriptor.configuration_number);
    181186
     
    187192        for (port = 1; port < hub_info->port_count+1; ++port) {
    188193                usb_hub_set_power_port_request(&request, port);
    189                 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
    190                                 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     194                opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    191195                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    192196                if (opResult != EOK) {
     
    196200        //ports powered, hub seems to be enabled
    197201
    198         usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    199         //async_hangup(hc);
     202        async_hangup(hc);
    200203
    201204        //add the hub to list
     
    212215        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
    213216        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
    214                         hub_info->usb_device->address,
     217                        hub_info->address,
    215218                        hub_info->port_count);
    216219        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",config_descriptor.configuration_number);
     
    249252 * @param target
    250253 */
    251 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
     254static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
    252255        usb_device_request_setup_packet_t request;
    253256        int opResult;
    254257        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    255258        //get default address
    256         ///////////////here ended pipe api upgrading
    257         gfdl;gfdgldglglkfgklfjfkld;sjgk;fgklsjgld
    258259        opResult = usb_drv_reserve_default_address(hc);
    259260        if (opResult != EOK) {
     
    317318        }
    318319
     320        devman_handle_t hc_handle;
     321        opResult = usb_drv_find_hc(hub->device, &hc_handle);
     322        if (opResult != EOK) {
     323                usb_log_error("Failed to get handle of host controller: %s.\n",
     324                    str_error(opResult));
     325                return;
     326        }
     327
    319328        devman_handle_t child_handle;
    320         opResult = usb_drv_register_child_in_devman(hc, hub->device,
    321             new_device_address, &child_handle);
     329        opResult = usb_device_register_child_in_devman(new_device_address,
     330            hc_handle, hub->device, &child_handle);
    322331        if (opResult != EOK) {
    323332                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
     
    374383 * @param target
    375384 */
    376 static void usb_hub_process_interrupt(usb_hub_info_t * hub,
    377         uint16_t port) {
     385static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
     386        uint16_t port, usb_address_t address) {
    378387        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    379388        //determine type of change
    380         int opResult = usb_endpoint_pipe_start_session(&hub->endpoints.control);
    381         usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
    382         if(opResult != EOK){
    383                 continue;
    384         }
    385 
    386         /*
    387389        usb_target_t target;
    388390        target.address=address;
    389391        target.endpoint=0;
    390         */
    391 
    392392        usb_port_status_t status;
    393393        size_t rcvd_size;
    394394        usb_device_request_setup_packet_t request;
    395         //int opResult;
     395        int opResult;
    396396        usb_hub_set_port_status_request(&request, port);
    397397        //endpoint 0
    398398
    399         opResult = usb_endpoint_pipe_control_read(
    400                         pipe,
    401                         &request, sizeof(usb_device_request_setup_packet_t),
     399        opResult = usb_drv_sync_control_read(
     400                        hc, target,
     401                        &request,
    402402                        &status, 4, &rcvd_size
    403403                        );
     
    412412        //something connected/disconnected
    413413        if (usb_port_connect_change(&status)) {
    414                 opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
     414                opResult = usb_hub_clear_port_feature(hc, target.address,
    415415                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    416416                // TODO: check opResult
    417417                if (usb_port_dev_connected(&status)) {
    418418                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
    419                         usb_hub_init_add_device(hub, port);
     419                        usb_hub_init_add_device(hc, port, target);
    420420                } else {
    421                         usb_hub_removed_device(hub, port);
     421                        usb_hub_removed_device(hub, hc, port, target);
    422422                }
    423423        }
     
    426426                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    427427                if (usb_port_enabled(&status)) {
    428                         usb_hub_finalize_add_device(hub, port);
     428                        usb_hub_finalize_add_device(hub, hc, port, target);
    429429                } else {
    430430                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
     
    442442        /// \TODO handle other changes
    443443        /// \TODO debug log for various situations
    444         usb_endpoint_pipe_end_session(&hub->endpoints.control);
    445 
    446444
    447445}
     
    461459                fibril_mutex_unlock(&usb_hub_list_lock);
    462460                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
    463                 int opResult;
    464 
    465                 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
    466                 if(opResult != EOK){
    467                         continue;
    468                 }
    469461                /*
    470462                 * Check status change pipe of this hub.
    471463                 */
    472                 /*
     464
    473465                usb_target_t target;
    474                 target.address = hub_info->usb_device->address;
     466                target.address = hub_info->address;
    475467                target.endpoint = 1;/// \TODO get from endpoint descriptor
    476468                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    477469                    target.address);
    478                 */
     470
    479471                size_t port_count = hub_info->port_count;
    480472
    481473                /*
    482474                 * Connect to respective HC.
    483                  *
     475                 */
    484476                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    485477                if (hc < 0) {
    486478                        continue;
    487                 }*/
     479                }
    488480
    489481                /// FIXME: count properly
     
    497489                 * Send the request.
    498490                 */
    499                 opResult = usb_endpoint_pipe_read(
    500                                 &hub_info->endpoints.status_change,
     491                int opResult = usb_drv_async_interrupt_in(hc, target,
    501492                                change_bitmap, byte_length, &actual_size,
    502                                 );
     493                                &handle);
    503494
    504495                usb_drv_async_wait_for(handle);
     
    515506                        if (interrupt) {
    516507                                usb_hub_process_interrupt(
    517                                         hub_info, port);
     508                                        hub_info, hc, port, hub_info->address);
    518509                        }
    519510                }
    520                 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    521511                free(change_bitmap);
    522                
    523 
    524                 //async_hangup(hc);
     512
     513                async_hangup(hc);
    525514                fibril_mutex_lock(&usb_hub_list_lock);
    526515        }
Note: See TracChangeset for help on using the changeset viewer.