Changeset 92574f4 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-02-24T12:03:27Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e7b7ebd5
Parents:
4837092 (diff), a80849c (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:

Merged development (changes in DDF, etc.).

Conflicts in uspace/drv/usbkbd/main.c

File:
1 edited

Legend:

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

    r4837092 r92574f4  
    3333 */
    3434
    35 #include <driver.h>
     35#include <ddf/driver.h>
    3636#include <bool.h>
    3737#include <errno.h>
     38#include <str_error.h>
    3839
    3940#include <usb_iface.h>
    40 #include <usb/usbdrv.h>
     41#include <usb/ddfiface.h>
    4142#include <usb/descriptor.h>
    42 #include <usb/devreq.h>
     43#include <usb/recognise.h>
     44#include <usb/request.h>
    4345#include <usb/classes/hub.h>
    4446
     
    4749#include "port_status.h"
    4850#include "usb/usb.h"
    49 
    50 static usb_iface_t hub_usb_iface = {
    51         .get_hc_handle = usb_drv_find_hc
     51#include "usb/pipes.h"
     52#include "usb/classes/classes.h"
     53
     54static ddf_dev_ops_t hub_device_ops = {
     55        .interfaces[USB_DEV_IFACE] = &usb_iface_hub_impl
    5256};
    5357
    54 static device_ops_t hub_device_ops = {
    55         .interfaces[USB_DEV_IFACE] = &hub_usb_iface
     58/** Hub status-change endpoint description */
     59static usb_endpoint_description_t status_change_endpoint_description = {
     60        .transfer_type = USB_TRANSFER_INTERRUPT,
     61        .direction = USB_DIRECTION_IN,
     62        .interface_class = USB_CLASS_HUB,
     63        .flags = 0
    5664};
     65
    5766
    5867//*********************************************
     
    6271//*********************************************
    6372
    64 usb_hub_info_t * usb_create_hub_info(device_t * device, int hc) {
     73/**
     74 * Initialize connnections to host controller, device, and device
     75 * control endpoint
     76 * @param hub
     77 * @param device
     78 * @return
     79 */
     80static int usb_hub_init_communication(usb_hub_info_t * hub){
     81        usb_log_debug("Initializing hub USB communication (hub->device->handle=%zu).\n", hub->device->handle);
     82        int opResult;
     83        opResult = usb_device_connection_initialize_from_device(
     84                        &hub->device_connection,
     85                        hub->device);
     86        if(opResult != EOK){
     87                dprintf(USB_LOG_LEVEL_ERROR,
     88                                "could not initialize connection to hc, errno %d",opResult);
     89                return opResult;
     90        }
     91        usb_log_debug("Initializing USB wire abstraction.\n");
     92        opResult = usb_hc_connection_initialize_from_device(&hub->connection,
     93                        hub->device);
     94        if(opResult != EOK){
     95                dprintf(USB_LOG_LEVEL_ERROR,
     96                                "could not initialize connection to device, errno %d",opResult);
     97                return opResult;
     98        }
     99        usb_log_debug("Initializing default control pipe.\n");
     100        opResult = usb_endpoint_pipe_initialize_default_control(&hub->endpoints.control,
     101            &hub->device_connection);
     102        if(opResult != EOK){
     103                dprintf(USB_LOG_LEVEL_ERROR,
     104                                "could not initialize connection to device endpoint, errno %d",opResult);
     105        }
     106        return opResult;
     107}
     108
     109/**
     110 * When entering this function, hub->endpoints.control should be active.
     111 * @param hub
     112 * @return
     113 */
     114static int usb_hub_process_configuration_descriptors(
     115        usb_hub_info_t * hub){
     116        if(hub==NULL) {
     117                return EINVAL;
     118        }
     119        int opResult;
     120       
     121        //device descriptor
     122        usb_standard_device_descriptor_t std_descriptor;
     123        opResult = usb_request_get_device_descriptor(&hub->endpoints.control,
     124            &std_descriptor);
     125        if(opResult!=EOK){
     126                dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult);
     127                return opResult;
     128        }
     129        dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations",
     130                        std_descriptor.configuration_count);
     131        if(std_descriptor.configuration_count<1){
     132                dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE");
     133                //shouldn`t I return?
     134        }
     135
     136        //configuration descriptor
     137        /// \TODO check other configurations
     138        usb_standard_configuration_descriptor_t config_descriptor;
     139        opResult = usb_request_get_bare_configuration_descriptor(
     140            &hub->endpoints.control, 0,
     141        &config_descriptor);
     142        if(opResult!=EOK){
     143                dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult);
     144                return opResult;
     145        }
     146        //set configuration
     147        opResult = usb_request_set_configuration(&hub->endpoints.control,
     148                config_descriptor.configuration_number);
     149
     150        if (opResult != EOK) {
     151                dprintf(USB_LOG_LEVEL_ERROR,
     152                                "something went wrong when setting hub`s configuration, %d",
     153                                opResult);
     154                return opResult;
     155        }
     156        dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d",
     157                        config_descriptor.configuration_number);
     158
     159        //full configuration descriptor
     160        size_t transferred = 0;
     161        uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length);
     162        if (descriptors == NULL) {
     163                dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory");
     164                return ENOMEM;
     165        }
     166        opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control,
     167            0, descriptors,
     168            config_descriptor.total_length, &transferred);
     169        if(opResult!=EOK){
     170                free(descriptors);
     171                dprintf(USB_LOG_LEVEL_ERROR,
     172                                "could not get full configuration descriptor, %d",opResult);
     173                return opResult;
     174        }
     175        if (transferred != config_descriptor.total_length) {
     176                dprintf(USB_LOG_LEVEL_ERROR,
     177                                "received incorrect full configuration descriptor");
     178                return ELIMIT;
     179        }
     180
     181        /**
     182         * Initialize the interrupt in endpoint.
     183         * \TODO this code should be checked...
     184         */
     185        usb_endpoint_mapping_t endpoint_mapping[1] = {
     186                {
     187                        .pipe = &hub->endpoints.status_change,
     188                        .description = &status_change_endpoint_description,
     189                        .interface_no =
     190                            usb_device_get_assigned_interface(hub->device)
     191                }
     192        };
     193        opResult = usb_endpoint_pipe_initialize_from_configuration(
     194            endpoint_mapping, 1,
     195            descriptors, config_descriptor.total_length,
     196            &hub->device_connection);
     197        if (opResult != EOK) {
     198                dprintf(USB_LOG_LEVEL_ERROR,
     199                                "Failed to initialize status change pipe: %s",
     200                    str_error(opResult));
     201                return opResult;
     202        }
     203        if (!endpoint_mapping[0].present) {
     204                dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \
     205                    "cannot understand what is happenning");
     206                return EREFUSED;
     207        }
     208
     209        free(descriptors);
     210        return EOK;
     211       
     212
     213        // Initialize the interrupt(=status change) endpoint.
     214        /*usb_endpoint_pipe_initialize(
     215                &result->endpoints->status_change,
     216                &result->device_connection, );USB_TRANSFER_INTERRUPT
     217        USB_DIRECTION_IN*/
     218
     219}
     220
     221
     222/**
     223 * Create hub representation from device information.
     224 * @param device
     225 * @return pointer to created structure or NULL in case of error
     226 */
     227usb_hub_info_t * usb_create_hub_info(ddf_dev_t * device) {
    65228        usb_hub_info_t* result = usb_new(usb_hub_info_t);
     229        result->device = device;
     230        int opResult;
     231        opResult = usb_hub_init_communication(result);
     232        if(opResult != EOK){
     233                free(result);
     234                return NULL;
     235        }
     236
    66237        //result->device = device;
    67238        result->port_count = -1;
    68         /// \TODO is this correct? is the device stored?
    69239        result->device = device;
    70240
    71 
    72         //printf("[usb_hub] phone to hc = %d\n", hc);
    73         if (hc < 0) {
    74                 return result;
    75         }
    76         //get some hub info
    77         usb_address_t addr = usb_drv_get_my_address(hc, device);
    78         dprintf(1, "address of newly created hub = %d", addr);
    79         /*if(addr<0){
    80                 //return result;
    81 
    82         }*/
    83 
    84         result->usb_device = usb_new(usb_hcd_attached_device_info_t);
    85         result->usb_device->address = addr;
     241        //result->usb_device = usb_new(usb_hcd_attached_device_info_t);
     242        size_t received_size;
    86243
    87244        // get hub descriptor
    88 
    89         //printf("[usb_hub] creating serialized descriptor\n");
     245        dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton");
    90246        void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE);
    91247        usb_hub_descriptor_t * descriptor;
    92         size_t received_size;
    93         int opResult;
    94         //printf("[usb_hub] starting control transaction\n");
    95        
    96         opResult = usb_drv_req_get_descriptor(hc, addr,
     248        dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction");
     249        usb_endpoint_pipe_start_session(&result->endpoints.control);
     250        opResult = usb_request_get_descriptor(&result->endpoints.control,
    97251                        USB_REQUEST_TYPE_CLASS,
    98252                        USB_DESCTYPE_HUB, 0, 0, serialized_descriptor,
    99253                        USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size);
    100 
    101         if (opResult != EOK) {
    102                 dprintf(1, "failed when receiving hub descriptor, badcode = %d",opResult);
     254        usb_endpoint_pipe_end_session(&result->endpoints.control);
     255
     256        if (opResult != EOK) {
     257                dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult);
    103258                free(serialized_descriptor);
    104259                return result;
    105260        }
    106         //printf("[usb_hub] deserializing descriptor\n");
     261        dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor");
    107262        descriptor = usb_deserialize_hub_desriptor(serialized_descriptor);
    108263        if(descriptor==NULL){
    109                 dprintf(1, "could not deserialize descriptor ");
     264                dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor ");
    110265                result->port_count = 1;///\TODO this code is only for debug!!!
    111266                return result;
    112267        }
    113         //printf("[usb_hub] setting port count to %d\n",descriptor->ports_count);
     268
     269       
     270        dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count);
    114271        result->port_count = descriptor->ports_count;
    115         result->attached_devs = (usb_hub_attached_device_t*)
    116             malloc((result->port_count+1) * sizeof(usb_hub_attached_device_t));
     272        result->attached_devs = (usb_hc_attached_device_t*)
     273            malloc((result->port_count+1) * sizeof(usb_hc_attached_device_t));
    117274        int i;
    118275        for(i=0;i<result->port_count+1;++i){
    119                 result->attached_devs[i].devman_handle=0;
     276                result->attached_devs[i].handle=0;
    120277                result->attached_devs[i].address=0;
    121278        }
    122         //printf("[usb_hub] freeing data\n");
     279        dprintf(USB_LOG_LEVEL_DEBUG2, "freeing data");
    123280        free(serialized_descriptor);
    124281        free(descriptor->devices_removable);
     
    127284        //finish
    128285
    129         dprintf(1, "hub info created");
     286        dprintf(USB_LOG_LEVEL_INFO, "hub info created");
    130287
    131288        return result;
    132289}
    133290
    134 int usb_add_hub_device(device_t *dev) {
    135         dprintf(1, "add_hub_device(handle=%d)", (int) dev->handle);
    136         dprintf(1, "hub device");
    137 
    138         /*
    139          * We are some (probably deeply nested) hub.
    140          * Thus, assign our own operations and explore already
    141          * connected devices.
    142          */
    143         dev->ops = &hub_device_ops;
    144 
    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);
     291/**
     292 * Create hub representation and add it into hub list
     293 * @param dev
     294 * @return
     295 */
     296int usb_add_hub_device(ddf_dev_t *dev) {
     297        dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle);
     298
     299        //dev->ops = &hub_device_ops;
     300        (void) hub_device_ops;
     301
     302        usb_hub_info_t * hub_info = usb_create_hub_info(dev);
     303
     304        int opResult;
     305
     306        //perform final configurations
     307        usb_endpoint_pipe_start_session(&hub_info->endpoints.control);
     308        // process descriptors
     309        opResult = usb_hub_process_configuration_descriptors(hub_info);
     310        if(opResult != EOK){
     311                dprintf(USB_LOG_LEVEL_ERROR,"could not get condiguration descriptors, %d",
     312                                opResult);
     313                return opResult;
     314        }
     315        //power ports
     316        usb_device_request_setup_packet_t request;
    153317        int port;
    154         int opResult;
    155         usb_target_t target;
    156         target.address = hub_info->usb_device->address;
    157         target.endpoint = 0;
    158 
    159         //get configuration descriptor
    160         // this is not fully correct - there are more configurations
    161         // and all should be checked
    162         usb_standard_device_descriptor_t std_descriptor;
    163         opResult = usb_drv_req_get_device_descriptor(hc, target.address,
    164             &std_descriptor);
    165         if(opResult!=EOK){
    166                 dprintf(1, "could not get device descriptor, %d",opResult);
    167                 return opResult;
    168         }
    169         dprintf(1, "hub has %d configurations",std_descriptor.configuration_count);
    170         if(std_descriptor.configuration_count<1){
    171                 dprintf(1, "THERE ARE NO CONFIGURATIONS AVAILABLE");
    172                 //shouldn`t I return?
    173         }
    174         /// \TODO check other configurations
    175         usb_standard_configuration_descriptor_t config_descriptor;
    176         opResult = usb_drv_req_get_bare_configuration_descriptor(hc,
    177         target.address, 0,
    178         &config_descriptor);
    179         if(opResult!=EOK){
    180                 dprintf(1, "could not get configuration descriptor, %d",opResult);
    181                 return opResult;
    182         }
    183         //set configuration
    184         opResult = usb_drv_req_set_configuration(hc, target.address,
    185     config_descriptor.configuration_number);
    186 
    187         if (opResult != EOK) {
    188                 dprintf(1, "something went wrong when setting hub`s configuration, %d", opResult);
    189         }
    190 
    191         usb_device_request_setup_packet_t request;
    192318        for (port = 1; port < hub_info->port_count+1; ++port) {
    193319                usb_hub_set_power_port_request(&request, port);
    194                 opResult = usb_drv_sync_control_write(hc, target, &request, NULL, 0);
    195                 dprintf(1, "powering port %d",port);
     320                opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control,
     321                                &request,sizeof(usb_device_request_setup_packet_t), NULL, 0);
     322                dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port);
    196323                if (opResult != EOK) {
    197                         dprintf(1, "something went wrong when setting hub`s %dth port", port);
     324                        dprintf(USB_LOG_LEVEL_WARNING, "something went wrong when setting hub`s %dth port", port);
    198325                }
    199326        }
    200327        //ports powered, hub seems to be enabled
    201 
    202         ipc_hangup(hc);
     328        usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
    203329
    204330        //add the hub to list
     
    207333        fibril_mutex_unlock(&usb_hub_list_lock);
    208334
    209         dprintf(1, "hub info added to list");
     335        dprintf(USB_LOG_LEVEL_DEBUG, "hub info added to list");
    210336        //(void)hub_info;
    211337        usb_hub_check_hub_changes();
    212 
    213338       
    214 
    215         dprintf(1, "hub dev added");
    216         dprintf(1, "\taddress %d, has %d ports ",
    217                         hub_info->usb_device->address,
     339        dprintf(USB_LOG_LEVEL_INFO, "hub dev added");
     340        //address is lost...
     341        dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ",
     342                        //hub_info->endpoints.control.,
    218343                        hub_info->port_count);
    219         dprintf(1, "\tused configuration %d",config_descriptor.configuration_number);
    220344
    221345        return EOK;
     
    231355
    232356/**
    233  * Convenience function for releasing default address and writing debug info
    234  * (these few lines are used too often to be written again and again).
    235  * @param hc
    236  * @return
    237  */
    238 inline static int usb_hub_release_default_address(int hc){
    239         int opResult;
    240         dprintf(1, "releasing default address");
    241         opResult = usb_drv_release_default_address(hc);
    242         if (opResult != EOK) {
    243                 dprintf(1, "failed to release default address");
    244         }
    245         return opResult;
    246 }
    247 
    248 /**
    249357 * Reset the port with new device and reserve the default address.
    250358 * @param hc
     
    252360 * @param target
    253361 */
    254 static void usb_hub_init_add_device(int hc, uint16_t port, usb_target_t target) {
     362static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port) {
    255363        usb_device_request_setup_packet_t request;
    256364        int opResult;
    257         dprintf(1, "some connection changed");
     365        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     366        assert(hub->endpoints.control.hc_phone);
    258367        //get default address
    259         opResult = usb_drv_reserve_default_address(hc);
    260         if (opResult != EOK) {
    261                 dprintf(1, "cannot assign default address, it is probably used");
     368        //opResult = usb_drv_reserve_default_address(hc);
     369        opResult = usb_hc_reserve_default_address(&hub->connection, USB_SPEED_LOW);
     370
     371        if (opResult != EOK) {
     372                dprintf(USB_LOG_LEVEL_WARNING, "cannot assign default address, it is probably used");
    262373                return;
    263374        }
    264375        //reset port
    265376        usb_hub_set_reset_port_request(&request, port);
    266         opResult = usb_drv_sync_control_write(
    267                         hc, target,
    268                         &request,
     377        opResult = usb_endpoint_pipe_control_write(
     378                        &hub->endpoints.control,
     379                        &request,sizeof(usb_device_request_setup_packet_t),
    269380                        NULL, 0
    270381                        );
    271382        if (opResult != EOK) {
    272                 dprintf(1, "something went wrong when reseting a port");
    273                 usb_hub_release_default_address(hc);
     383                dprintf(USB_LOG_LEVEL_ERROR, "something went wrong when reseting a port");
     384                //usb_hub_release_default_address(hc);
     385                usb_hc_release_default_address(&hub->connection);
    274386        }
    275387}
     
    282394 */
    283395static void usb_hub_finalize_add_device( usb_hub_info_t * hub,
    284                 int hc, uint16_t port, usb_target_t target) {
     396                uint16_t port) {
    285397
    286398        int opResult;
    287         dprintf(1, "finalizing add device");
    288         opResult = usb_hub_clear_port_feature(hc, target.address,
     399        dprintf(USB_LOG_LEVEL_INFO, "finalizing add device");
     400        opResult = usb_hub_clear_port_feature(&hub->endpoints.control,
    289401            port, USB_HUB_FEATURE_C_PORT_RESET);
    290         if (opResult != EOK) {
    291                 dprintf(1, "failed to clear port reset feature");
    292                 usb_hub_release_default_address(hc);
    293                 return;
    294         }
    295 
    296         /* Request address at from host controller. */
    297         usb_address_t new_device_address = usb_drv_request_address(hc);
     402
     403        if (opResult != EOK) {
     404                dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature");
     405                usb_hc_release_default_address(&hub->connection);
     406                return;
     407        }
     408        //create connection to device
     409        usb_endpoint_pipe_t new_device_pipe;
     410        usb_device_connection_t new_device_connection;
     411        usb_device_connection_initialize_on_default_address(
     412                        &new_device_connection,
     413                        &hub->connection
     414                        );
     415        usb_endpoint_pipe_initialize_default_control(
     416                        &new_device_pipe,
     417                        &new_device_connection);
     418        /// \TODO get highspeed info
     419
     420
     421
     422
     423
     424        /* Request address from host controller. */
     425        usb_address_t new_device_address = usb_hc_request_address(
     426                        &hub->connection,
     427                        USB_SPEED_LOW/// \TODO fullspeed??
     428                        );
    298429        if (new_device_address < 0) {
    299                 dprintf(1, "failed to get free USB address");
     430                dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address");
    300431                opResult = new_device_address;
    301                 usb_hub_release_default_address(hc);
    302                 return;
    303         }
    304         dprintf(1, "setting new address");
    305         opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
    306             new_device_address);
    307 
    308         if (opResult != EOK) {
    309                 dprintf(1, "could not set address for new device");
    310                 usb_hub_release_default_address(hc);
    311                 return;
    312         }
    313 
    314 
    315         opResult = usb_hub_release_default_address(hc);
     432                usb_hc_release_default_address(&hub->connection);
     433                return;
     434        }
     435        dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address);
     436        //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT,
     437        //    new_device_address);
     438        opResult = usb_request_set_address(&new_device_pipe,new_device_address);
     439
     440        if (opResult != EOK) {
     441                dprintf(USB_LOG_LEVEL_ERROR, "could not set address for new device");
     442                usb_hc_release_default_address(&hub->connection);
     443                return;
     444        }
     445
     446
     447        //opResult = usb_hub_release_default_address(hc);
     448        opResult = usb_hc_release_default_address(&hub->connection);
    316449        if(opResult!=EOK){
    317450                return;
     
    319452
    320453        devman_handle_t child_handle;
    321         opResult = usb_drv_register_child_in_devman(hc, hub->device,
    322             new_device_address, &child_handle);
    323         if (opResult != EOK) {
    324                 dprintf(1, "could not start driver for new device");
    325                 return;
    326         }
    327         hub->attached_devs[port].devman_handle = child_handle;
     454        //??
     455    opResult = usb_device_register_child_in_devman(new_device_address,
     456            hub->connection.hc_handle, hub->device, &child_handle,
     457            NULL, NULL, NULL);
     458
     459        if (opResult != EOK) {
     460                dprintf(USB_LOG_LEVEL_ERROR, "could not start driver for new device");
     461                return;
     462        }
     463        hub->attached_devs[port].handle = child_handle;
    328464        hub->attached_devs[port].address = new_device_address;
    329465
    330         opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
    331         if (opResult != EOK) {
    332                 dprintf(1, "could not assign address of device in hcd");
    333                 return;
    334         }
    335         dprintf(1, "new device address %d, handle %zu",
     466        //opResult = usb_drv_bind_address(hc, new_device_address, child_handle);
     467        opResult = usb_hc_register_device(
     468                        &hub->connection,
     469                        &hub->attached_devs[port]);
     470        if (opResult != EOK) {
     471                dprintf(USB_LOG_LEVEL_ERROR, "could not assign address of device in hcd");
     472                return;
     473        }
     474        dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu",
    336475            new_device_address, child_handle);
    337476
     
    345484 */
    346485static void usb_hub_removed_device(
    347     usb_hub_info_t * hub, int hc, uint16_t port, usb_target_t target) {
     486    usb_hub_info_t * hub,uint16_t port) {
    348487        //usb_device_request_setup_packet_t request;
    349488        int opResult;
     
    352491         * devide manager
    353492         */
    354 
    355         hub->attached_devs[port].devman_handle=0;
     493       
    356494        //close address
    357495        if(hub->attached_devs[port].address!=0){
    358                 opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     496                //opResult = usb_drv_release_address(hc,hub->attached_devs[port].address);
     497                opResult = usb_hc_unregister_device(
     498                                &hub->connection, hub->attached_devs[port].address);
    359499                if(opResult != EOK) {
    360                         dprintf(1, "could not release address of " \
     500                        dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \
    361501                            "removed device: %d", opResult);
    362502                }
    363503                hub->attached_devs[port].address = 0;
     504                hub->attached_devs[port].handle = 0;
    364505        }else{
    365                 dprintf(1, "this is strange, disconnected device had no address");
     506                dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address");
    366507                //device was disconnected before it`s port was reset - return default address
    367                 usb_drv_release_default_address(hc);
     508                //usb_drv_release_default_address(hc);
     509                usb_hc_release_default_address(&hub->connection);
    368510        }
    369511}
     
    375517 * @param target
    376518 */
    377 static void usb_hub_process_interrupt(usb_hub_info_t * hub, int hc,
    378         uint16_t port, usb_address_t address) {
    379         dprintf(1, "interrupt at port %d", port);
     519static void usb_hub_process_interrupt(usb_hub_info_t * hub,
     520        uint16_t port) {
     521        dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port);
    380522        //determine type of change
     523        usb_endpoint_pipe_t *pipe = &hub->endpoints.control;
     524        int opResult = usb_endpoint_pipe_start_session(pipe);
     525       
     526        if(opResult != EOK){
     527                dprintf(USB_LOG_LEVEL_ERROR, "cannot open pipe %d", opResult);
     528        }
     529
     530        /*
    381531        usb_target_t target;
    382532        target.address=address;
    383533        target.endpoint=0;
     534        */
     535
    384536        usb_port_status_t status;
    385537        size_t rcvd_size;
    386538        usb_device_request_setup_packet_t request;
    387         int opResult;
     539        //int opResult;
    388540        usb_hub_set_port_status_request(&request, port);
    389541        //endpoint 0
    390542
    391         opResult = usb_drv_sync_control_read(
    392                         hc, target,
    393                         &request,
     543        opResult = usb_endpoint_pipe_control_read(
     544                        pipe,
     545                        &request, sizeof(usb_device_request_setup_packet_t),
    394546                        &status, 4, &rcvd_size
    395547                        );
    396548        if (opResult != EOK) {
    397                 dprintf(1, "ERROR: could not get port status");
     549                dprintf(USB_LOG_LEVEL_ERROR, "ERROR: could not get port status");
    398550                return;
    399551        }
    400552        if (rcvd_size != sizeof (usb_port_status_t)) {
    401                 dprintf(1, "ERROR: received status has incorrect size");
     553                dprintf(USB_LOG_LEVEL_ERROR, "ERROR: received status has incorrect size");
    402554                return;
    403555        }
    404556        //something connected/disconnected
    405557        if (usb_port_connect_change(&status)) {
    406                 opResult = usb_hub_clear_port_feature(hc, target.address,
     558                opResult = usb_hub_clear_port_feature(pipe,
    407559                    port, USB_HUB_FEATURE_C_PORT_CONNECTION);
    408560                // TODO: check opResult
    409561                if (usb_port_dev_connected(&status)) {
    410                         dprintf(1, "some connection changed");
    411                         usb_hub_init_add_device(hc, port, target);
     562                        dprintf(USB_LOG_LEVEL_INFO, "some connection changed");
     563                        usb_hub_init_add_device(hub, port);
    412564                } else {
    413                         usb_hub_removed_device(hub, hc, port, target);
     565                        usb_hub_removed_device(hub, port);
    414566                }
    415567        }
    416568        //port reset
    417569        if (usb_port_reset_completed(&status)) {
    418                 dprintf(1, "port reset complete");
     570                dprintf(USB_LOG_LEVEL_INFO, "port reset complete");
    419571                if (usb_port_enabled(&status)) {
    420                         usb_hub_finalize_add_device(hub, hc, port, target);
     572                        usb_hub_finalize_add_device(hub, port);
    421573                } else {
    422                         dprintf(1, "ERROR: port reset, but port still not enabled");
     574                        dprintf(USB_LOG_LEVEL_WARNING, "ERROR: port reset, but port still not enabled");
    423575                }
    424576        }
     
    429581        usb_port_set_dev_connected(&status, false);
    430582        if (status>>16) {
    431                 dprintf(1, "there was some unsupported change on port %d: %X",port,status);
     583                dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status);
    432584
    433585        }
    434586        /// \TODO handle other changes
    435587        /// \TODO debug log for various situations
     588        usb_endpoint_pipe_end_session(pipe);
     589
    436590
    437591}
     
    451605                fibril_mutex_unlock(&usb_hub_list_lock);
    452606                usb_hub_info_t * hub_info = ((usb_hub_info_t*)lst_item->data);
     607                int opResult;
     608
     609                opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change);
     610                if(opResult != EOK){
     611                        continue;
     612                }
    453613                /*
    454614                 * Check status change pipe of this hub.
    455615                 */
    456 
     616                /*
    457617                usb_target_t target;
    458                 target.address = hub_info->usb_device->address;
     618                target.address = hub_info->address;
    459619                target.endpoint = 1;/// \TODO get from endpoint descriptor
    460                 dprintf(1, "checking changes for hub at addr %d",
     620                dprintf(USB_LOG_LEVEL_INFO, "checking changes for hub at addr %d",
    461621                    target.address);
    462 
     622                */
    463623                size_t port_count = hub_info->port_count;
    464624
    465625                /*
    466626                 * Connect to respective HC.
    467                  */
     627                 *
    468628                int hc = usb_drv_hc_connect_auto(hub_info->device, 0);
    469629                if (hc < 0) {
    470630                        continue;
    471                 }
     631                }*/
    472632
    473633                /// FIXME: count properly
     
    476636                void *change_bitmap = malloc(byte_length);
    477637                size_t actual_size;
    478                 usb_handle_t handle;
     638                //usb_handle_t handle;
    479639
    480640                /*
    481641                 * Send the request.
    482642                 */
    483                 int opResult = usb_drv_async_interrupt_in(hc, target,
    484                                 change_bitmap, byte_length, &actual_size,
    485                                 &handle);
    486 
    487                 usb_drv_async_wait_for(handle);
     643                opResult = usb_endpoint_pipe_read(
     644                                &hub_info->endpoints.status_change,
     645                                change_bitmap, byte_length, &actual_size
     646                                );
     647
     648                //usb_drv_async_wait_for(handle);
    488649
    489650                if (opResult != EOK) {
    490651                        free(change_bitmap);
    491                         dprintf(1, "something went wrong while getting status of hub");
     652                        dprintf(USB_LOG_LEVEL_WARNING, "something went wrong while getting status of hub");
    492653                        continue;
    493654                }
     
    498659                        if (interrupt) {
    499660                                usb_hub_process_interrupt(
    500                                         hub_info, hc, port, hub_info->usb_device->address);
     661                                        hub_info, port);
    501662                        }
    502663                }
     664                usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change);
    503665                free(change_bitmap);
    504 
    505                 ipc_hangup(hc);
     666               
     667
     668                //async_hangup(hc);
    506669                fibril_mutex_lock(&usb_hub_list_lock);
    507670        }
Note: See TracChangeset for help on using the changeset viewer.