Changeset 6c399765 in mainline for uspace/drv/usbhub/usbhub.c


Ignore:
Timestamp:
2011-04-03T20:06:39Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
195890b
Parents:
fefc27d
Message:

attempt to solve non-removable devices
some fixes in root hub driver

File:
1 edited

Legend:

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

    rfefc27d r6c399765  
    5454
    5555
    56 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     56static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    5757                usb_speed_t speed);
    5858
     
    7676                async_usleep(1000 * 1000 * 10 );/// \TODO proper number once
    7777                errorCode = usb_hub_check_hub_changes(hub_info);
     78               
    7879        }
    7980        usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode);
     
    125126         * these lines allow to reset hub once more, it can be used as
    126127         * brute-force initialization for non-removable devices
    127         int opResult = usb_request_set_configuration(&result->endpoints.control, 1);
     128         */
     129        int opResult = usb_request_set_configuration(hub_info->control_pipe,
     130                        1);
    128131        if(opResult!=EOK){
    129132                usb_log_error("could not set default configuration, errno %d",opResult);
    130133                return opResult;
    131134        }
    132          */
     135         
     136         
    133137        size_t received_size;
    134         int opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,
     138        opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe,
    135139                        USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE,
    136140                        USB_DESCTYPE_HUB,
     
    163167        usb_log_debug2("freeing data\n");
    164168        free(serialized_descriptor);
    165         free(descriptor->devices_removable);
    166         free(descriptor);
     169        hub_info->descriptor = descriptor;
     170        hub_info->not_initialized_non_removables =
     171                (uint8_t*)malloc((hub_info->port_count+8)/8);
     172        memcpy(hub_info->not_initialized_non_removables,
     173                descriptor->devices_removable,
     174                (hub_info->port_count+8)/8
     175                );
     176
     177        //free(descriptor->devices_removable);
     178        //free(descriptor);
    167179        return EOK;
    168180}
     
    289301 * @return error code
    290302 */
    291 static int usb_hub_trigger_connecting_non_removable_devices(usb_hub_info_t * hub,
     303static int usb_hub_trigger_connecting_non_removable_devices(
     304                usb_hub_info_t * hub,
    292305                usb_hub_descriptor_t * descriptor)
    293306{
    294307        usb_log_info("attaching non-removable devices(if any)\n");
    295         usb_device_request_setup_packet_t request;
     308        //usb_device_request_setup_packet_t request;
    296309        int opResult;
    297         size_t rcvd_size;
    298         usb_port_status_t status;
     310        //size_t rcvd_size;
     311        //usb_port_status_t status;
    299312        uint8_t * non_removable_dev_bitmap = descriptor->devices_removable;
    300313        int port;
     314
     315        opResult = usb_request_set_configuration(hub->control_pipe,
     316                        1);
     317        if(opResult!=EOK){
     318                usb_log_error("could not set default configuration, errno %d",opResult);
     319                return opResult;
     320        }
     321#if 0
    301322        for(port=1;port<=descriptor->ports_count;++port){
    302323                bool is_non_removable =
     
    315336                                return opResult;
    316337                        }
    317                         if(usb_port_dev_connected(&status)){
    318                         usb_hub_set_enable_port_feature_request(&request, port,
    319                                         USB_HUB_FEATURE_PORT_RESET);
    320                         opResult = usb_pipe_control_read(
    321                                         hub->control_pipe,
    322                                         &request, sizeof(usb_device_request_setup_packet_t),
    323                                         &status, 4, &rcvd_size
    324                                         );
    325                         if (opResult != EOK) {
    326                                 usb_log_warning(
    327                                                 "could not reset port %d errno:%d\n",
    328                                                 port, opResult);
    329                         }
    330                         usb_log_debug("port reset\n");
     338                        //try to reset port
     339                        if(usb_port_dev_connected(&status) || true){
     340                                usb_hub_set_enable_port_feature_request(&request, port,
     341                                                USB_HUB_FEATURE_PORT_RESET);
     342                                opResult = usb_pipe_control_read(
     343                                                hub->control_pipe,
     344                                                &request, sizeof(usb_device_request_setup_packet_t),
     345                                                &status, 4, &rcvd_size
     346                                                );
     347                                if (opResult != EOK) {
     348                                        usb_log_warning(
     349                                                        "could not reset port %d errno:%d\n",
     350                                                        port, opResult);
     351                                }
     352                                usb_log_debug("port reset, should look like %d,x%x\n",
     353                                                (1<<USB_HUB_FEATURE_PORT_RESET),
     354                                                (1<<USB_HUB_FEATURE_PORT_RESET)
     355                                                );
    331356                        }
    332357                        //set the status change bit, so it will be noticed in driver loop
    333                         /*if(usb_port_dev_connected(&status)){
     358                        if(usb_port_dev_connected(&status) && false){
    334359                                usb_hub_set_disable_port_feature_request(&request, port,
    335360                                                USB_HUB_FEATURE_PORT_CONNECTION);
     
    358383                                }
    359384                                usb_log_debug("port set to enabled - should lead to connection change\n");
    360                         }*/
     385                        }
    361386                }
    362387        }
     388#endif
     389
    363390        /// \TODO this is just a debug code
    364391        for(port=1;port<=descriptor->ports_count;++port){
     
    366393                                ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;
    367394                if(is_non_removable){
    368                         usb_log_debug("port %d is non-removable\n",port);
     395                        usb_log_debug("CHECKING port %d is non-removable\n",port);
    369396                        usb_port_status_t status;
    370397                        size_t rcvd_size;
     
    392419                }
    393420        }
     421
    394422        return EOK;
    395423}
     
    419447 * @param port port number, starting from 1
    420448 * @param speed transfer speed of attached device, one of low, full or high
    421  */
    422 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
     449 * @return error code
     450 */
     451static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port,
    423452                usb_speed_t speed) {
    424453        //if this hub already uses default address, it cannot request it once more
    425         if(hub->is_default_address_used) return;
     454        if(hub->is_default_address_used) return EREFUSED;
    426455        usb_log_debug("some connection changed\n");
    427456        assert(hub->control_pipe->hc_phone);
     
    439468                usb_log_warning("cannot assign default address, it is probably used %d\n",
    440469                                opResult);
    441                 return;
     470                return opResult;
    442471        }
    443472        hub->is_default_address_used = true;
     
    453482                usb_hub_release_default_address(hub);
    454483        }
    455         return;
     484        return opResult;
    456485}
    457486
     
    670699                }
    671700        }
    672         usb_log_debug("status %x\n ",status);
     701        usb_log_debug("status x%x : %d\n ",status,status);
    673702
    674703        usb_port_set_connect_change(&status, false);
     
    683712}
    684713
     714
     715static int initialize_non_removable(usb_hub_info_t * hub_info,
     716        unsigned int port){
     717        int opResult;
     718        usb_log_debug("there is not pluged in non-removable device on "
     719                "port %d\n",port
     720                );
     721        //usb_hub_init_add_device(hub_info, port, usb_port_speed(&status));
     722        usb_port_status_t status;
     723        size_t rcvd_size;
     724        usb_device_request_setup_packet_t request;
     725        //int opResult;
     726        usb_hub_set_port_status_request(&request, port);
     727        //endpoint 0
     728
     729        opResult = usb_pipe_control_read(
     730                        hub_info->control_pipe,
     731                        &request, sizeof(usb_device_request_setup_packet_t),
     732                        &status, 4, &rcvd_size
     733                        );
     734        if (opResult != EOK) {
     735                usb_log_error("could not get port status %d\n",opResult);
     736                return opResult;
     737        }
     738        if (rcvd_size != sizeof (usb_port_status_t)) {
     739                usb_log_error("received status has incorrect size\n");
     740                return opResult;
     741        }
     742        usb_log_debug("port status %d, x%x\n",status,status);
     743        if(usb_port_dev_connected(&status)){
     744                usb_log_debug("there is connected device on this port\n");
     745        }
     746        if(!hub_info->is_default_address_used)
     747                usb_hub_init_add_device(hub_info, port, usb_port_speed(&status));
     748        return opResult;
     749}
     750
    685751/**
    686752 * check changes on hub
     
    694760        opResult = usb_pipe_start_session(
    695761                        hub_info->status_change_pipe);
     762        //this might not be necessary - if all non-removables are ok, it is not needed here
     763        opResult = usb_pipe_start_session(hub_info->control_pipe);
    696764        if(opResult != EOK){
    697765                usb_log_error("could not initialize communication for hub; %d\n",
     
    701769
    702770        size_t port_count = hub_info->port_count;
     771        //first check non-removable devices
     772        {
     773        unsigned int port;
     774        for(port = 1; port<=port_count; ++port){
     775                bool is_non_removable =
     776                        hub_info->not_initialized_non_removables[port/8]
     777                        & (1 << (port%8));
     778                if(is_non_removable){
     779                        opResult = initialize_non_removable(hub_info,port);
     780                }
     781        }
     782        }
     783
    703784
    704785        /// FIXME: count properly
     
    722803        }
    723804        unsigned int port;
    724         opResult = usb_pipe_start_session(hub_info->control_pipe);
     805       
    725806        if(opResult!=EOK){
    726807                usb_log_error("could not start control pipe session %d\n", opResult);
Note: See TracChangeset for help on using the changeset viewer.