Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d0c060b in mainline


Ignore:
Timestamp:
2011-05-06T15:40:46Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
3b543d5
Parents:
26f6094
Message:

bugfix candidates: ohci: detecting devices connected on startup
hub driver: status change clearing

Location:
uspace/drv
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/root_hub.c

    r26f6094 rd0c060b  
    108108
    109109static const uint32_t hub_clear_feature_valid_mask =
    110         (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
     110    (1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER) |
    111111(1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    112112
    113113static const uint32_t hub_clear_feature_by_writing_one_mask =
    114         1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
     114    1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER;
    115115
    116116static const uint32_t hub_set_feature_valid_mask =
    117         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
     117    (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT) |
    118118(1 << USB_HUB_FEATURE_C_HUB_LOCAL_POWER);
    119119
    120120
    121121static const uint32_t hub_set_feature_direct_mask =
    122         (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
     122    (1 << USB_HUB_FEATURE_C_HUB_OVER_CURRENT);
    123123
    124124static const uint32_t port_set_feature_valid_mask =
    125         (1 << USB_HUB_FEATURE_PORT_ENABLE) |
     125    (1 << USB_HUB_FEATURE_PORT_ENABLE) |
    126126(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    127127(1 << USB_HUB_FEATURE_PORT_RESET) |
     
    129129
    130130static const uint32_t port_clear_feature_valid_mask =
    131         (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
     131    (1 << USB_HUB_FEATURE_PORT_CONNECTION) |
    132132(1 << USB_HUB_FEATURE_PORT_SUSPEND) |
    133133(1 << USB_HUB_FEATURE_PORT_OVER_CURRENT) |
     
    142142
    143143static const uint32_t port_status_change_mask =
    144 (1<< USB_HUB_FEATURE_C_PORT_CONNECTION) |
    145 (1<< USB_HUB_FEATURE_C_PORT_ENABLE) |
    146 (1<< USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
    147 (1<< USB_HUB_FEATURE_C_PORT_RESET) |
    148 (1<< USB_HUB_FEATURE_C_PORT_SUSPEND);
     144    (1 << USB_HUB_FEATURE_C_PORT_CONNECTION) |
     145(1 << USB_HUB_FEATURE_C_PORT_ENABLE) |
     146(1 << USB_HUB_FEATURE_C_PORT_OVER_CURRENT) |
     147(1 << USB_HUB_FEATURE_C_PORT_RESET) |
     148(1 << USB_HUB_FEATURE_C_PORT_SUSPEND);
    149149
    150150
     
    153153static int rh_init_descriptors(rh_t *instance);
    154154
     155static void rh_check_port_connectivity(rh_t * instance);
     156
    155157static int process_get_port_status_request(rh_t *instance, uint16_t port,
    156         usb_transfer_batch_t * request);
     158    usb_transfer_batch_t * request);
    157159
    158160static int process_get_hub_status_request(rh_t *instance,
    159         usb_transfer_batch_t * request);
     161    usb_transfer_batch_t * request);
    160162
    161163static int process_get_status_request(rh_t *instance,
    162         usb_transfer_batch_t * request);
     164    usb_transfer_batch_t * request);
    163165
    164166static void create_interrupt_mask_in_instance(rh_t *instance);
    165167
    166168static int process_get_descriptor_request(rh_t *instance,
    167         usb_transfer_batch_t *request);
     169    usb_transfer_batch_t *request);
    168170
    169171static int process_get_configuration_request(rh_t *instance,
    170         usb_transfer_batch_t *request);
     172    usb_transfer_batch_t *request);
    171173
    172174static int process_hub_feature_set_request(rh_t *instance, uint16_t feature);
    173175
    174176static int process_hub_feature_clear_request(rh_t *instance,
    175         uint16_t feature);
     177    uint16_t feature);
    176178
    177179static int process_port_feature_set_request(rh_t *instance,
    178         uint16_t feature, uint16_t port);
     180    uint16_t feature, uint16_t port);
    179181
    180182static int process_port_feature_clear_request(rh_t *instance,
    181         uint16_t feature, uint16_t port);
     183    uint16_t feature, uint16_t port);
    182184
    183185static int process_address_set_request(rh_t *instance,
    184         uint16_t address);
     186    uint16_t address);
    185187
    186188static int process_request_with_output(rh_t *instance,
    187         usb_transfer_batch_t *request);
     189    usb_transfer_batch_t *request);
    188190
    189191static int process_request_with_input(rh_t *instance,
    190         usb_transfer_batch_t *request);
     192    usb_transfer_batch_t *request);
    191193
    192194static int process_request_without_data(rh_t *instance,
    193         usb_transfer_batch_t *request);
     195    usb_transfer_batch_t *request);
    194196
    195197static int process_ctrl_request(rh_t *instance, usb_transfer_batch_t *request);
     
    198200
    199201static bool is_zeros(void * buffer, size_t size);
    200 
    201 
    202202
    203203/** Root hub initialization
     
    210210            (instance->registers->rh_desc_a >> RHDA_NDS_SHIFT) & RHDA_NDS_MASK;
    211211        int opResult = rh_init_descriptors(instance);
    212         if(opResult != EOK){
     212        if (opResult != EOK) {
    213213                return opResult;
    214214        }
     
    216216        instance->registers->rh_desc_a |= RHDA_NPS_FLAG;
    217217        instance->unfinished_interrupt_transfer = NULL;
    218         instance->interrupt_mask_size = (instance->port_count + 8)/8;
     218        instance->interrupt_mask_size = (instance->port_count + 8) / 8;
    219219        instance->interrupt_buffer = malloc(instance->interrupt_mask_size);
    220         if(!instance->interrupt_buffer)
     220        if (!instance->interrupt_buffer)
    221221                return ENOMEM;
    222        
     222        rh_check_port_connectivity(instance);
     223
    223224
    224225        usb_log_info("OHCI root hub with %d ports.\n", instance->port_count);
     226
    225227        return EOK;
    226228}
     
    245247                usb_log_info("Root hub got INTERRUPT packet\n");
    246248                create_interrupt_mask_in_instance(instance);
    247                 if(is_zeros(instance->interrupt_buffer,
    248                     instance->interrupt_mask_size)){
     249                if (is_zeros(instance->interrupt_buffer,
     250                    instance->interrupt_mask_size)) {
    249251                        usb_log_debug("no changes..\n");
    250252                        instance->unfinished_interrupt_transfer = request;
    251253                        //will be finished later
    252                 }else{
     254                } else {
    253255                        usb_log_debug("processing changes..\n");
    254256                        process_interrupt_mask_in_instance(instance, request);
     
    256258                opResult = EOK;
    257259        } else {
     260
    258261                opResult = EINVAL;
    259262                usb_transfer_batch_finish_error(request, opResult);
     
    271274 */
    272275void rh_interrupt(rh_t *instance) {
    273         if(!instance->unfinished_interrupt_transfer){
     276        if (!instance->unfinished_interrupt_transfer) {
     277
    274278                return;
    275279        }
     
    292296static int create_serialized_hub_descriptor(rh_t *instance) {
    293297        size_t size = 7 +
    294             ((instance->port_count +7 )/ 8) * 2;
    295         size_t var_size = (instance->port_count +7 )/ 8;
     298            ((instance->port_count + 7) / 8) * 2;
     299        size_t var_size = (instance->port_count + 7) / 8;
    296300        uint8_t * result = (uint8_t*) malloc(size);
    297         if(!result) return ENOMEM;
     301        if (!result) return ENOMEM;
    298302
    299303        bzero(result, size);
     
    305309        uint32_t hub_desc_reg = instance->registers->rh_desc_a;
    306310        result[3] =
    307                 ((hub_desc_reg >> 8) % 2) +
    308                 (((hub_desc_reg >> 9) % 2) << 1) +
    309                 (((hub_desc_reg >> 10) % 2) << 2) +
    310                 (((hub_desc_reg >> 11) % 2) << 3) +
    311                 (((hub_desc_reg >> 12) % 2) << 4);
     311            ((hub_desc_reg >> 8) % 2) +
     312            (((hub_desc_reg >> 9) % 2) << 1) +
     313            (((hub_desc_reg >> 10) % 2) << 2) +
     314            (((hub_desc_reg >> 11) % 2) << 3) +
     315            (((hub_desc_reg >> 12) % 2) << 4);
    312316        result[4] = 0;
    313317        result[5] = /*descriptor->pwr_on_2_good_time*/ 50;
    314318        result[6] = 50;
    315319
    316         int port;
     320        size_t port;
    317321        for (port = 1; port <= instance->port_count; ++port) {
    318322                uint8_t is_non_removable =
    319                         instance->registers->rh_desc_b >> port % 2;
     323                    instance->registers->rh_desc_b >> port % 2;
    320324                result[7 + port / 8] +=
    321                         is_non_removable << (port % 8);
     325                    is_non_removable << (port % 8);
    322326        }
    323327        size_t i;
     
    327331        instance->hub_descriptor = result;
    328332        instance->descriptor_size = size;
     333
    329334        return EOK;
    330335}
     
    340345static int rh_init_descriptors(rh_t *instance) {
    341346        memcpy(&instance->descriptors.device, &ohci_rh_device_descriptor,
    342                 sizeof (ohci_rh_device_descriptor)
    343                 );
     347            sizeof (ohci_rh_device_descriptor)
     348            );
    344349        usb_standard_configuration_descriptor_t descriptor;
    345350        memcpy(&descriptor, &ohci_rh_conf_descriptor,
    346                 sizeof (ohci_rh_conf_descriptor));
     351            sizeof (ohci_rh_conf_descriptor));
    347352
    348353        int opResult = create_serialized_hub_descriptor(instance);
    349         if(opResult != EOK){
     354        if (opResult != EOK) {
    350355                return opResult;
    351356        }
    352357        descriptor.total_length =
    353                 sizeof (usb_standard_configuration_descriptor_t) +
    354                 sizeof (usb_standard_endpoint_descriptor_t) +
    355                 sizeof (usb_standard_interface_descriptor_t) +
    356                 instance->descriptor_size;
     358            sizeof (usb_standard_configuration_descriptor_t) +
     359            sizeof (usb_standard_endpoint_descriptor_t) +
     360            sizeof (usb_standard_interface_descriptor_t) +
     361            instance->descriptor_size;
    357362
    358363        uint8_t * full_config_descriptor =
    359                 (uint8_t*) malloc(descriptor.total_length);
    360         if(!full_config_descriptor){
     364            (uint8_t*) malloc(descriptor.total_length);
     365        if (!full_config_descriptor) {
    361366                return ENOMEM;
    362367        }
    363368        memcpy(full_config_descriptor, &descriptor, sizeof (descriptor));
    364369        memcpy(full_config_descriptor + sizeof (descriptor),
    365                 &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
     370            &ohci_rh_iface_descriptor, sizeof (ohci_rh_iface_descriptor));
    366371        memcpy(full_config_descriptor + sizeof (descriptor) +
    367                 sizeof (ohci_rh_iface_descriptor),
    368                 &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
     372            sizeof (ohci_rh_iface_descriptor),
     373            &ohci_rh_ep_descriptor, sizeof (ohci_rh_ep_descriptor));
    369374        memcpy(full_config_descriptor + sizeof (descriptor) +
    370                 sizeof (ohci_rh_iface_descriptor) +
    371                 sizeof (ohci_rh_ep_descriptor),
    372                 instance->hub_descriptor, instance->descriptor_size);
    373        
     375            sizeof (ohci_rh_iface_descriptor) +
     376            sizeof (ohci_rh_ep_descriptor),
     377            instance->hub_descriptor, instance->descriptor_size);
     378
    374379        instance->descriptors.configuration = full_config_descriptor;
    375380        instance->descriptors.configuration_size = descriptor.total_length;
    376         return EOK;
    377 }
     381
     382        return EOK;
     383}
     384/*----------------------------------------------------------------------------*/
     385
     386/**
     387 * check whether there are connected devices on ports and if yes, indicate
     388 * connection change
     389 *
     390 * @param instance
     391 */
     392static void rh_check_port_connectivity(rh_t * instance) {
     393        size_t port;
     394        for (port = 1; port < instance->port_count; ++port) {
     395                bool connected =
     396                    ((instance->registers->rh_port_status[port - 1]) &
     397                    (1 << USB_HUB_FEATURE_PORT_CONNECTION)) != 0;
     398                if (connected) {
     399                        usb_log_debug("port %d has connected device\n", port);
     400                        instance->registers->rh_port_status[port - 1] =
     401                            instance->registers->rh_port_status[port - 1]
     402                            | (1 << USB_HUB_FEATURE_C_PORT_CONNECTION);
     403                        usb_log_debug("change indicated to status "
     404                            "register\n");
     405                }
     406        }
     407}
     408
     409
    378410/*----------------------------------------------------------------------------*/
    379411
     
    389421 */
    390422static int process_get_port_status_request(rh_t *instance, uint16_t port,
    391         usb_transfer_batch_t * request) {
     423    usb_transfer_batch_t * request) {
    392424        if (port < 1 || port > instance->port_count)
    393425                return EINVAL;
     
    398430        int i;
    399431        for (i = 0; i < instance->port_count; ++i) {
     432
    400433                usb_log_debug("port status %d,x%x\n",
    401                         instance->registers->rh_port_status[i],
    402                         instance->registers->rh_port_status[i]);
     434                    instance->registers->rh_port_status[i],
     435                    instance->registers->rh_port_status[i]);
    403436        }
    404437#endif
     
    417450 */
    418451static int process_get_hub_status_request(rh_t *instance,
    419         usb_transfer_batch_t * request) {
     452    usb_transfer_batch_t * request) {
    420453        uint32_t * uint32_buffer = (uint32_t*) request->data_buffer;
    421454        request->transfered_size = 4;
     
    423456        uint32_t mask = 1 | (1 << 1) | (1 << 16) | (1 << 17);
    424457        uint32_buffer[0] = mask & instance->registers->rh_status;
     458
    425459        return EOK;
    426460}
     
    437471 */
    438472static int process_get_status_request(rh_t *instance,
    439         usb_transfer_batch_t * request) {
     473    usb_transfer_batch_t * request) {
    440474        size_t buffer_size = request->buffer_size;
    441475        usb_device_request_setup_packet_t * request_packet =
    442                 (usb_device_request_setup_packet_t*)
    443                 request->setup_buffer;
     476            (usb_device_request_setup_packet_t*)
     477            request->setup_buffer;
    444478
    445479        usb_hub_bm_request_type_t request_type = request_packet->request_type;
     
    453487        if (request_type == USB_HUB_REQ_TYPE_GET_PORT_STATUS)
    454488                return process_get_port_status_request(instance,
    455                 request_packet->index,
    456                 request);
     489            request_packet->index,
     490            request);
     491
    457492        return ENOTSUP;
    458493}
     
    472507        uint8_t * bitmap = (uint8_t*) (instance->interrupt_buffer);
    473508        uint32_t mask = (1 << (USB_HUB_FEATURE_C_HUB_LOCAL_POWER + 16))
    474                 | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
     509            | (1 << (USB_HUB_FEATURE_C_HUB_OVER_CURRENT + 16));
    475510        bzero(bitmap, instance->interrupt_mask_size);
    476511        if (instance->registers->rh_status & mask) {
    477512                bitmap[0] = 1;
    478513        }
    479         int port;
     514        size_t port;
    480515        mask = port_status_change_mask;
    481516        for (port = 1; port <= instance->port_count; ++port) {
    482517                if (mask & instance->registers->rh_port_status[port - 1]) {
     518
    483519                        bitmap[(port) / 8] += 1 << (port % 8);
    484520                }
     
    497533 */
    498534static int process_get_descriptor_request(rh_t *instance,
    499         usb_transfer_batch_t *request) {
     535    usb_transfer_batch_t *request) {
    500536        usb_device_request_setup_packet_t * setup_request =
    501                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     537            (usb_device_request_setup_packet_t*) request->setup_buffer;
    502538        size_t size;
    503539        const void * result_descriptor = NULL;
     
    543579                {
    544580                        usb_log_debug("USB_DESCTYPE_EINVAL %d \n",
    545                                 setup_request->value);
     581                            setup_request->value);
    546582                        usb_log_debug("\ttype %d\n\trequest %d\n\tvalue "
    547                                 "%d\n\tindex %d\n\tlen %d\n ",
    548                                 setup_request->request_type,
    549                                 setup_request->request,
    550                                 setup_request_value,
    551                                 setup_request->index,
    552                                 setup_request->length
    553                                 );
     583                            "%d\n\tindex %d\n\tlen %d\n ",
     584                            setup_request->request_type,
     585                            setup_request->request,
     586                            setup_request_value,
     587                            setup_request->index,
     588                            setup_request->length
     589                            );
    554590                        return EINVAL;
    555591                }
     
    560596        request->transfered_size = size;
    561597        memcpy(request->data_buffer, result_descriptor, size);
     598
    562599        return EOK;
    563600}
     
    573610 */
    574611static int process_get_configuration_request(rh_t *instance,
    575         usb_transfer_batch_t *request) {
     612    usb_transfer_batch_t *request) {
    576613        //set and get configuration requests do not have any meaning, only dummy
    577614        //values are returned
     
    580617        request->data_buffer[0] = 1;
    581618        request->transfered_size = 1;
     619
    582620        return EOK;
    583621}
     
    592630 */
    593631static int process_hub_feature_set_request(rh_t *instance,
    594         uint16_t feature) {
     632    uint16_t feature) {
    595633        if (!((1 << feature) & hub_set_feature_valid_mask))
    596634                return EINVAL;
    597         if(feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
     635        if (feature == USB_HUB_FEATURE_C_HUB_LOCAL_POWER)
    598636                feature = USB_HUB_FEATURE_C_HUB_LOCAL_POWER << 16;
    599637        instance->registers->rh_status =
    600                 (instance->registers->rh_status | (1 << feature))
    601                 & (~hub_clear_feature_by_writing_one_mask);
     638            (instance->registers->rh_status | (1 << feature))
     639            & (~hub_clear_feature_by_writing_one_mask);
     640
    602641        return EOK;
    603642}
     
    612651 */
    613652static int process_hub_feature_clear_request(rh_t *instance,
    614         uint16_t feature) {
     653    uint16_t feature) {
    615654        if (!((1 << feature) & hub_clear_feature_valid_mask))
    616655                return EINVAL;
     
    618657        if ((1 << feature) & hub_set_feature_direct_mask) {
    619658                instance->registers->rh_status =
    620                         (instance->registers->rh_status & (~(1 << feature)))
    621                         & (~hub_clear_feature_by_writing_one_mask);
     659                    (instance->registers->rh_status & (~(1 << feature)))
     660                    & (~hub_clear_feature_by_writing_one_mask);
    622661        } else {//the feature is cleared by writing '1'
     662
    623663                instance->registers->rh_status =
    624                         (instance->registers->rh_status
    625                         & (~hub_clear_feature_by_writing_one_mask))
    626                         | (1 << feature);
     664                    (instance->registers->rh_status
     665                    & (~hub_clear_feature_by_writing_one_mask))
     666                    | (1 << feature);
    627667        }
    628668        return EOK;
     
    640680 */
    641681static int process_port_feature_set_request(rh_t *instance,
    642         uint16_t feature, uint16_t port) {
     682    uint16_t feature, uint16_t port) {
    643683        if (!((1 << feature) & port_set_feature_valid_mask))
    644684                return EINVAL;
     
    646686                return EINVAL;
    647687        instance->registers->rh_port_status[port - 1] =
    648                 (instance->registers->rh_port_status[port - 1] | (1 << feature))
    649                 & (~port_clear_feature_valid_mask);
     688            (instance->registers->rh_port_status[port - 1] | (1 << feature))
     689            & (~port_clear_feature_valid_mask);
    650690        /// \TODO any error?
     691
    651692        return EOK;
    652693}
     
    663704 */
    664705static int process_port_feature_clear_request(rh_t *instance,
    665         uint16_t feature, uint16_t port) {
     706    uint16_t feature, uint16_t port) {
    666707        if (!((1 << feature) & port_clear_feature_valid_mask))
    667708                return EINVAL;
     
    673714                feature = USB_HUB_FEATURE_PORT_OVER_CURRENT;
    674715        instance->registers->rh_port_status[port - 1] =
    675                 (instance->registers->rh_port_status[port - 1]
    676                 & (~port_clear_feature_valid_mask))
    677                 | (1 << feature);
     716            (instance->registers->rh_port_status[port - 1]
     717            & (~port_clear_feature_valid_mask))
     718            | (1 << feature);
    678719        /// \TODO any error?
     720
    679721        return EOK;
    680722}
     
    689731 */
    690732static int process_address_set_request(rh_t *instance,
    691         uint16_t address) {
     733    uint16_t address) {
    692734        instance->address = address;
     735
    693736        return EOK;
    694737}
     
    705748 */
    706749static int process_request_with_output(rh_t *instance,
    707         usb_transfer_batch_t *request) {
     750    usb_transfer_batch_t *request) {
    708751        usb_device_request_setup_packet_t * setup_request =
    709                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     752            (usb_device_request_setup_packet_t*) request->setup_buffer;
    710753        if (setup_request->request == USB_DEVREQ_GET_STATUS) {
    711754                usb_log_debug("USB_DEVREQ_GET_STATUS\n");
     
    718761        if (setup_request->request == USB_DEVREQ_GET_CONFIGURATION) {
    719762                usb_log_debug("USB_DEVREQ_GET_CONFIGURATION\n");
     763
    720764                return process_get_configuration_request(instance, request);
    721765        }
     
    734778 */
    735779static int process_request_with_input(rh_t *instance,
    736         usb_transfer_batch_t *request) {
     780    usb_transfer_batch_t *request) {
    737781        usb_device_request_setup_packet_t * setup_request =
    738                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     782            (usb_device_request_setup_packet_t*) request->setup_buffer;
    739783        request->transfered_size = 0;
    740784        if (setup_request->request == USB_DEVREQ_SET_DESCRIPTOR) {
     
    744788                //set and get configuration requests do not have any meaning,
    745789                //only dummy values are returned
     790
    746791                return EOK;
    747792        }
     
    760805 */
    761806static int process_request_without_data(rh_t *instance,
    762         usb_transfer_batch_t *request) {
     807    usb_transfer_batch_t *request) {
    763808        usb_device_request_setup_packet_t * setup_request =
    764                 (usb_device_request_setup_packet_t*) request->setup_buffer;
     809            (usb_device_request_setup_packet_t*) request->setup_buffer;
    765810        request->transfered_size = 0;
    766811        if (setup_request->request == USB_DEVREQ_CLEAR_FEATURE) {
     
    768813                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    769814                        return process_hub_feature_clear_request(instance,
    770                                 setup_request->value);
     815                            setup_request->value);
    771816                }
    772817                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    773818                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    774819                        return process_port_feature_clear_request(instance,
    775                                 setup_request->value,
    776                                 setup_request->index);
     820                            setup_request->value,
     821                            setup_request->index);
    777822                }
    778823                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    779                         setup_request->request_type);
     824                    setup_request->request_type);
    780825                return EINVAL;
    781826        }
     
    784829                        usb_log_debug("USB_HUB_REQ_TYPE_SET_HUB_FEATURE\n");
    785830                        return process_hub_feature_set_request(instance,
    786                                 setup_request->value);
     831                            setup_request->value);
    787832                }
    788833                if (setup_request->request_type == USB_HUB_REQ_TYPE_SET_PORT_FEATURE) {
    789834                        usb_log_debug("USB_HUB_REQ_TYPE_SET_PORT_FEATURE\n");
    790835                        return process_port_feature_set_request(instance,
    791                                 setup_request->value,
    792                                 setup_request->index);
     836                            setup_request->value,
     837                            setup_request->index);
    793838                }
    794839                usb_log_debug("USB_HUB_REQ_TYPE_INVALID %d\n",
    795                         setup_request->request_type);
     840                    setup_request->request_type);
    796841                return EINVAL;
    797842        }
     
    799844                usb_log_debug("USB_DEVREQ_SET_ADDRESS\n");
    800845                return process_address_set_request(instance,
    801                         setup_request->value);
     846                    setup_request->value);
    802847        }
    803848        usb_log_debug("USB_DEVREQ_SET_ENOTSUP %d\n",
    804                 setup_request->request_type);
     849            setup_request->request_type);
     850
    805851        return ENOTSUP;
    806852}
     
    836882        }
    837883        usb_log_info("CTRL packet: %s.\n",
    838                 usb_debug_str_buffer(
    839                 (const uint8_t *) request->setup_buffer, 8, 8));
     884            usb_debug_str_buffer(
     885            (const uint8_t *) request->setup_buffer, 8, 8));
    840886        usb_device_request_setup_packet_t * setup_request =
    841                 (usb_device_request_setup_packet_t*)
    842                 request->setup_buffer;
     887            (usb_device_request_setup_packet_t*)
     888            request->setup_buffer;
    843889        switch (setup_request->request) {
    844890                case USB_DEVREQ_GET_STATUS:
     
    847893                        usb_log_debug("processing request with output\n");
    848894                        opResult = process_request_with_output(
    849                                 instance, request);
     895                            instance, request);
    850896                        break;
    851897                case USB_DEVREQ_CLEAR_FEATURE:
     
    853899                case USB_DEVREQ_SET_ADDRESS:
    854900                        usb_log_debug("processing request without "
    855                                 "additional data\n");
     901                            "additional data\n");
    856902                        opResult = process_request_without_data(
    857                                 instance, request);
     903                            instance, request);
    858904                        break;
    859905                case USB_DEVREQ_SET_DESCRIPTOR:
    860906                case USB_DEVREQ_SET_CONFIGURATION:
    861907                        usb_log_debug("processing request with "
    862                                 "input\n");
     908                            "input\n");
    863909                        opResult = process_request_with_input(
    864                                 instance, request);
     910                            instance, request);
     911
    865912                        break;
    866913                default:
    867914                        usb_log_warning("received unsuported request: "
    868                                 "%d\n",
    869                                 setup_request->request
    870                                 );
     915                            "%d\n",
     916                            setup_request->request
     917                            );
    871918                        opResult = ENOTSUP;
    872919        }
     
    888935 * @return
    889936 */
    890 static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request){
     937static int process_interrupt_mask_in_instance(rh_t *instance, usb_transfer_batch_t * request) {
    891938        memcpy(request->data_buffer, instance->interrupt_buffer,
    892939            instance->interrupt_mask_size);
     
    894941        instance->unfinished_interrupt_transfer = NULL;
    895942        usb_transfer_batch_finish_error(request, EOK);
     943
    896944        return EOK;
    897945}
     
    907955 * @return
    908956 */
    909 static bool is_zeros(void * buffer, size_t size){
    910         if(!buffer) return true;
    911         if(!size) return true;
     957static bool is_zeros(void * buffer, size_t size) {
     958        if (!buffer) return true;
     959        if (!size) return true;
    912960        size_t i;
    913         for(i=0;i<size;++i){
    914                 if(((char*)buffer)[i])
     961        for (i = 0; i < size; ++i) {
     962                if (((char*) buffer)[i])
    915963                        return false;
    916964        }
  • uspace/drv/ohci/root_hub.h

    r26f6094 rd0c060b  
    5151        usb_address_t address;
    5252        /** hub port count */
    53         int port_count;
     53        size_t port_count;
    5454        /** hubs descriptors */
    5555        usb_device_descriptors_t descriptors;
  • uspace/drv/usbhub/ports.c

    r26f6094 rd0c060b  
    137137            &status, USB_HUB_FEATURE_C_PORT_OVER_CURRENT,false);
    138138        /// \TODO what about port power change?
     139        unsigned int bit_idx;
     140        for(bit_idx = 16;bit_idx<32;++bit_idx){
     141                if(status & (1<<bit_idx)){
     142                        usb_log_info(
     143                            "there was unsupported change on port %d: %d\n",
     144                        port, bit_idx);
     145                        int opResult = usb_hub_clear_port_feature(
     146                            hub->control_pipe,
     147                            port, USB_HUB_FEATURE_C_PORT_CONNECTION);
     148                        if (opResult != EOK) {
     149                                usb_log_warning(
     150                                    "could not clear port flag %d: %d\n",
     151                                    bit_idx, opResult
     152                                    );
     153                        }
     154                        usb_port_status_set_bit(
     155                            &status, bit_idx,false);
     156                }
     157        }
    139158        if (status >> 16) {
    140159                usb_log_info("there was unsupported change on port %d: %X\n",
    141160                        port, status);
    142 
    143161        }
    144162}
     
    222240                    "Port %zu reset complete but port not enabled.\n",
    223241                    (size_t) port);
     242        }
     243        /* Clear the port reset change. */
     244        int rc = usb_hub_clear_port_feature(hub->control_pipe,
     245            port, USB_HUB_FEATURE_C_PORT_RESET);
     246        if (rc != EOK) {
     247                usb_log_error("Failed to clear port %d reset feature: %s.\n",
     248                    port, str_error(rc));
    224249        }
    225250}
     
    319344        fibril_mutex_unlock(&my_port->reset_mutex);
    320345
    321         /* Clear the port reset change. */
    322         rc = usb_hub_clear_port_feature(hub->control_pipe,
    323             port_no, USB_HUB_FEATURE_C_PORT_RESET);
    324         if (rc != EOK) {
    325                 usb_log_error("Failed to clear port %d reset feature: %s.\n",
    326                     port_no, str_error(rc));
    327                 return rc;
    328         }
    329 
    330346        if (my_port->reset_okay) {
    331347                return EOK;
Note: See TracChangeset for help on using the changeset viewer.