Changeset 195890b in mainline for uspace/drv/usbhub/usbhub.c
- Timestamp:
- 2011-04-03T21:39:28Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
- Children:
- 3bb6b35
- Parents:
- 6c399765
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
r6c399765 r195890b 55 55 56 56 static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 57 57 usb_speed_t speed); 58 58 59 59 static int usb_hub_trigger_connecting_non_removable_devices( 60 60 usb_hub_info_t * hub, usb_hub_descriptor_t * descriptor); 61 61 62 62 /** … … 69 69 * @return zero 70 70 */ 71 int usb_hub_control_loop(void * hub_info_param) {72 usb_hub_info_t * hub_info = (usb_hub_info_t*) hub_info_param;71 int usb_hub_control_loop(void * hub_info_param) { 72 usb_hub_info_t * hub_info = (usb_hub_info_t*) hub_info_param; 73 73 int errorCode = EOK; 74 74 75 while (errorCode == EOK){76 async_usleep(1000 * 1000 * 10 );/// \TODO proper number once75 while (errorCode == EOK) { 76 async_usleep(1000 * 1000 * 10); /// \TODO proper number once 77 77 errorCode = usb_hub_check_hub_changes(hub_info); 78 79 } 80 usb_log_error("something in ctrl loop went wrong, errno %d\n",errorCode); 78 79 } 80 usb_log_error("something in ctrl loop went wrong, errno %d\n", 81 errorCode); 81 82 82 83 return 0; … … 99 100 static usb_hub_info_t * usb_hub_info_create(usb_device_t * usb_dev) { 100 101 usb_hub_info_t * result = usb_new(usb_hub_info_t); 101 if (!result) return NULL;102 if (!result) return NULL; 102 103 result->usb_device = usb_dev; 103 104 result->status_change_pipe = usb_dev->pipes[0].pipe; … … 117 118 * @return error code 118 119 */ 119 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) {120 static int usb_hub_process_hub_specific_info(usb_hub_info_t * hub_info) { 120 121 // get hub descriptor 121 122 usb_log_debug("creating serialized descriptor\n"); … … 128 129 */ 129 130 int opResult = usb_request_set_configuration(hub_info->control_pipe, 130 1); 131 if(opResult!=EOK){ 132 usb_log_error("could not set default configuration, errno %d",opResult); 133 return opResult; 134 } 135 136 131 1); 132 if (opResult != EOK) { 133 usb_log_error("could not set default configuration, errno %d", 134 opResult); 135 return opResult; 136 } 137 138 137 139 size_t received_size; 138 140 opResult = usb_request_get_descriptor(&hub_info->usb_device->ctrl_pipe, 139 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 140 USB_DESCTYPE_HUB, 141 0, 0, serialized_descriptor, 142 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 143 144 if (opResult != EOK) { 145 usb_log_error("failed when receiving hub descriptor, badcode = %d\n", 146 opResult); 141 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_DEVICE, 142 USB_DESCTYPE_HUB, 143 0, 0, serialized_descriptor, 144 USB_HUB_MAX_DESCRIPTOR_SIZE, &received_size); 145 146 if (opResult != EOK) { 147 usb_log_error("failed when receiving hub descriptor, " 148 "badcode = %d\n", 149 opResult); 147 150 free(serialized_descriptor); 148 151 return opResult; … … 150 153 usb_log_debug2("deserializing descriptor\n"); 151 154 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 152 if (descriptor==NULL){155 if (descriptor == NULL) { 153 156 usb_log_warning("could not deserialize descriptor \n"); 154 157 return opResult; 155 158 } 156 usb_log_debug("setting port count to %d\n", descriptor->ports_count);159 usb_log_debug("setting port count to %d\n", descriptor->ports_count); 157 160 hub_info->port_count = descriptor->ports_count; 158 161 hub_info->attached_devs = (usb_hc_attached_device_t*) 159 malloc((hub_info->port_count+1) * sizeof(usb_hc_attached_device_t)); 162 malloc((hub_info->port_count + 1) * 163 sizeof (usb_hc_attached_device_t) 164 ); 160 165 int i; 161 for (i=0;i<hub_info->port_count+1;++i){162 hub_info->attached_devs[i].handle =0;163 hub_info->attached_devs[i].address =0;166 for (i = 0; i < hub_info->port_count + 1; ++i) { 167 hub_info->attached_devs[i].handle = 0; 168 hub_info->attached_devs[i].address = 0; 164 169 } 165 170 //handle non-removable devices … … 169 174 hub_info->descriptor = descriptor; 170 175 hub_info->not_initialized_non_removables = 171 (uint8_t*) malloc((hub_info->port_count+8)/8);176 (uint8_t*) malloc((hub_info->port_count + 8) / 8); 172 177 memcpy(hub_info->not_initialized_non_removables, 173 178 descriptor->devices_removable, 174 (hub_info->port_count +8)/8179 (hub_info->port_count + 8) / 8 175 180 ); 176 181 … … 179 184 return EOK; 180 185 } 186 181 187 /** 182 188 * Set configuration of hub … … 187 193 * @return error code 188 194 */ 189 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) {195 static int usb_hub_set_configuration(usb_hub_info_t * hub_info) { 190 196 //device descriptor 191 197 usb_standard_device_descriptor_t *std_descriptor 192 198 = &hub_info->usb_device->descriptors.device; 193 199 usb_log_debug("hub has %d configurations\n", 194 195 if (std_descriptor->configuration_count<1){200 std_descriptor->configuration_count); 201 if (std_descriptor->configuration_count < 1) { 196 202 usb_log_error("there are no configurations available\n"); 197 203 return EINVAL; … … 199 205 200 206 usb_standard_configuration_descriptor_t *config_descriptor 201 202 207 = (usb_standard_configuration_descriptor_t *) 208 hub_info->usb_device->descriptors.configuration; 203 209 204 210 /* Set configuration. */ 205 211 int opResult = usb_request_set_configuration( 206 207 212 &hub_info->usb_device->ctrl_pipe, 213 config_descriptor->configuration_number); 208 214 209 215 if (opResult != EOK) { 210 216 usb_log_error("Failed to set hub configuration: %s.\n", 211 217 str_error(opResult)); 212 218 return opResult; 213 219 } 214 220 usb_log_debug("\tused configuration %d\n", 215 221 config_descriptor->configuration_number); 216 222 217 223 return EOK; … … 226 232 * @return error code 227 233 */ 228 int usb_hub_add_device(usb_device_t * usb_dev) {229 if (!usb_dev) return EINVAL;234 int usb_hub_add_device(usb_device_t * usb_dev) { 235 if (!usb_dev) return EINVAL; 230 236 usb_hub_info_t * hub_info = usb_hub_info_create(usb_dev); 231 237 //create hc connection 232 238 usb_log_debug("Initializing USB wire abstraction.\n"); 233 239 int opResult = usb_hc_connection_initialize_from_device( 234 &hub_info->connection, 235 hub_info->usb_device->ddf_dev); 236 if(opResult != EOK){ 237 usb_log_error("could not initialize connection to device, errno %d\n", 238 opResult); 240 &hub_info->connection, 241 hub_info->usb_device->ddf_dev); 242 if (opResult != EOK) { 243 usb_log_error("could not initialize connection to device, " 244 "errno %d\n", 245 opResult); 239 246 free(hub_info); 240 247 return opResult; 241 248 } 242 249 243 250 usb_pipe_start_session(hub_info->control_pipe); 244 251 //set hub configuration 245 252 opResult = usb_hub_set_configuration(hub_info); 246 if(opResult!=EOK){ 247 usb_log_error("could not set hub configuration, errno %d\n",opResult); 253 if (opResult != EOK) { 254 usb_log_error("could not set hub configuration, errno %d\n", 255 opResult); 248 256 free(hub_info); 249 257 return opResult; … … 251 259 //get port count and create attached_devs 252 260 opResult = usb_hub_process_hub_specific_info(hub_info); 253 if(opResult!=EOK){ 254 usb_log_error("could not set hub configuration, errno %d\n",opResult); 261 if (opResult != EOK) { 262 usb_log_error("could not set hub configuration, errno %d\n", 263 opResult); 255 264 free(hub_info); 256 265 return opResult; … … 262 271 usb_log_debug("Creating `hub' function.\n"); 263 272 ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev, 264 273 fun_exposed, "hub"); 265 274 assert(hub_fun != NULL); 266 275 hub_fun->ops = NULL; … … 274 283 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 275 284 if (fid == 0) { 276 usb_log_error("failed to start monitoring fibril for new hub.\n"); 285 usb_log_error("failed to start monitoring fibril for new" 286 " hub.\n"); 277 287 return ENOMEM; 278 288 } … … 281 291 282 292 usb_log_info("Controlling hub `%s' (%d ports).\n", 283 293 hub_info->usb_device->ddf_dev->name, hub_info->port_count); 284 294 return EOK; 285 295 } … … 302 312 */ 303 313 static int usb_hub_trigger_connecting_non_removable_devices( 304 usb_hub_info_t * hub, 305 usb_hub_descriptor_t * descriptor) 306 { 314 usb_hub_info_t * hub, 315 usb_hub_descriptor_t * descriptor) { 307 316 usb_log_info("attaching non-removable devices(if any)\n"); 308 317 //usb_device_request_setup_packet_t request; … … 314 323 315 324 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); 325 1); 326 if (opResult != EOK) { 327 usb_log_error("could not set default configuration, errno %d", 328 opResult); 319 329 return opResult; 320 330 } 321 331 #if 0 322 for (port=1;port<=descriptor->ports_count;++port){332 for (port = 1; port <= descriptor->ports_count; ++port) { 323 333 bool is_non_removable = 324 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2;325 if (is_non_removable){326 usb_log_debug("non-removable device on port %d\n", port);334 ((non_removable_dev_bitmap[port / 8]) >> (port % 8)) % 2; 335 if (is_non_removable) { 336 usb_log_debug("non-removable device on port %d\n", port); 327 337 usb_hub_set_port_status_request(&request, port); 328 338 opResult = usb_pipe_control_read( 329 hub->control_pipe, 330 &request, sizeof(usb_device_request_setup_packet_t), 331 &status, 4, &rcvd_size 332 ); 339 hub->control_pipe, 340 &request, 341 sizeof (usb_device_request_setup_packet_t), 342 &status, 4, &rcvd_size 343 ); 333 344 if (opResult != EOK) { 334 usb_log_error("could not get port status of port %d errno:%d\n", 335 port, opResult); 345 usb_log_error("could not get port status of " 346 "port %d errno:%d\n", 347 port, opResult); 336 348 return opResult; 337 349 } 338 350 //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); 351 if (usb_port_dev_connected(&status) || true) { 352 usb_hub_set_enable_port_feature_request( 353 &request, port, 354 USB_HUB_FEATURE_PORT_RESET); 342 355 opResult = usb_pipe_control_read( 343 hub->control_pipe, 344 &request, sizeof(usb_device_request_setup_packet_t), 345 &status, 4, &rcvd_size 346 ); 356 hub->control_pipe, 357 &request, 358 sizeof (usb_device_request_setup_packet_t), 359 &status, 4, &rcvd_size 360 ); 347 361 if (opResult != EOK) { 348 362 usb_log_warning( 349 "could not reset port %d errno:%d\n", 350 port, opResult); 363 "could not reset port %d " 364 "errno:%d\n", 365 port, opResult); 351 366 } 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 ); 367 usb_log_debug("port reset, should look like " 368 "%d,x%x\n", 369 (1 << USB_HUB_FEATURE_PORT_RESET), 370 (1 << USB_HUB_FEATURE_PORT_RESET) 371 ); 356 372 } 357 //set the status change bit, so it will be noticed in driver loop 358 if(usb_port_dev_connected(&status) && false){ 359 usb_hub_set_disable_port_feature_request(&request, port, 360 USB_HUB_FEATURE_PORT_CONNECTION); 373 //set the status change bit, so it will be noticed 374 //in driver loop 375 if (usb_port_dev_connected(&status) && false) { 376 usb_hub_set_disable_port_feature_request( 377 &request, port, 378 USB_HUB_FEATURE_PORT_CONNECTION); 361 379 opResult = usb_pipe_control_read( 362 hub->control_pipe, 363 &request, sizeof(usb_device_request_setup_packet_t), 364 &status, 4, &rcvd_size 365 ); 380 hub->control_pipe, 381 &request, 382 sizeof (usb_device_request_setup_packet_t), 383 &status, 4, &rcvd_size 384 ); 366 385 if (opResult != EOK) { 367 386 usb_log_warning( 368 "could not clear port connection on port %d errno:%d\n", 369 port, opResult); 387 "could not clear port " 388 "connection on port %d " 389 "errno:%d\n", 390 port, opResult); 370 391 } 371 392 usb_log_debug("cleared port connection\n"); 372 usb_hub_set_enable_port_feature_request(&request, port, 373 USB_HUB_FEATURE_PORT_ENABLE); 393 usb_hub_set_enable_port_feature_request(&request, 394 port, 395 USB_HUB_FEATURE_PORT_ENABLE); 374 396 opResult = usb_pipe_control_read( 375 hub->control_pipe, 376 &request, sizeof(usb_device_request_setup_packet_t), 377 &status, 4, &rcvd_size 378 ); 397 hub->control_pipe, 398 &request, 399 sizeof (usb_device_request_setup_packet_t), 400 &status, 4, &rcvd_size 401 ); 379 402 if (opResult != EOK) { 380 403 usb_log_warning( 381 "could not set port enabled on port %d errno:%d\n", 382 port, opResult); 404 "could not set port enabled " 405 "on port %d errno:%d\n", 406 port, opResult); 383 407 } 384 usb_log_debug("port set to enabled - should lead to connection change\n"); 408 usb_log_debug("port set to enabled - " 409 "should lead to connection change\n"); 385 410 } 386 411 } … … 389 414 390 415 /// \TODO this is just a debug code 391 for (port=1;port<=descriptor->ports_count;++port){416 for (port = 1; port <= descriptor->ports_count; ++port) { 392 417 bool is_non_removable = 393 ((non_removable_dev_bitmap[port/8]) >> (port%8)) %2; 394 if(is_non_removable){ 395 usb_log_debug("CHECKING port %d is non-removable\n",port); 418 ((non_removable_dev_bitmap[port / 8]) >> (port % 8)) % 2; 419 if (is_non_removable) { 420 usb_log_debug("CHECKING port %d is non-removable\n", 421 port); 396 422 usb_port_status_t status; 397 423 size_t rcvd_size; … … 401 427 //endpoint 0 402 428 opResult = usb_pipe_control_read( 403 hub->control_pipe, 404 &request, sizeof(usb_device_request_setup_packet_t), 405 &status, 4, &rcvd_size 406 ); 429 hub->control_pipe, 430 &request, 431 sizeof (usb_device_request_setup_packet_t), 432 &status, 4, &rcvd_size 433 ); 407 434 if (opResult != EOK) { 408 usb_log_error("could not get port status %d\n",opResult); 435 usb_log_error("could not get port status %d\n", 436 opResult); 409 437 } 410 438 if (rcvd_size != sizeof (usb_port_status_t)) { 411 usb_log_error("received status has incorrect size\n"); 439 usb_log_error("received status has incorrect" 440 " size\n"); 412 441 } 413 442 //something connected/disconnected … … 415 444 usb_log_debug("some connection changed\n"); 416 445 } 417 usb_log_debug("status: %s\n", usb_debug_str_buffer(418 (uint8_t *)&status,4,4));446 usb_log_debug("status: %s\n", usb_debug_str_buffer( 447 (uint8_t *) & status, 4, 4)); 419 448 } 420 449 } … … 422 451 return EOK; 423 452 } 424 425 453 426 454 /** … … 432 460 * @return error code 433 461 */ 434 static int usb_hub_release_default_address(usb_hub_info_t * hub) {462 static int usb_hub_release_default_address(usb_hub_info_t * hub) { 435 463 int opResult = usb_hc_release_default_address(&hub->connection); 436 if(opResult!=EOK){ 437 usb_log_error("could not release default address, errno %d\n",opResult); 464 if (opResult != EOK) { 465 usb_log_error("could not release default address, errno %d\n", 466 opResult); 438 467 return opResult; 439 468 } … … 450 479 */ 451 480 static int usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 452 481 usb_speed_t speed) { 453 482 //if this hub already uses default address, it cannot request it once more 454 if (hub->is_default_address_used) return EREFUSED;483 if (hub->is_default_address_used) return EREFUSED; 455 484 usb_log_debug("some connection changed\n"); 456 485 assert(hub->control_pipe->hc_phone); 457 486 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 458 459 if (opResult != EOK){487 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 488 if (opResult != EOK) { 460 489 usb_log_warning("could not clear port-change-connection flag\n"); 461 490 } 462 491 usb_device_request_setup_packet_t request; 463 492 464 493 //get default address 465 494 opResult = usb_hc_reserve_default_address(&hub->connection, speed); 466 467 if (opResult != EOK) { 468 usb_log_warning("cannot assign default address, it is probably used %d\n", 469 opResult); 495 496 if (opResult != EOK) { 497 usb_log_warning("cannot assign default address, it is probably " 498 "used %d\n", 499 opResult); 470 500 return opResult; 471 501 } … … 474 504 usb_hub_set_reset_port_request(&request, port); 475 505 opResult = usb_pipe_control_write( 476 hub->control_pipe, 477 &request,sizeof(usb_device_request_setup_packet_t), 478 NULL, 0 479 ); 480 if (opResult != EOK) { 481 usb_log_error("something went wrong when reseting a port %d\n",opResult); 506 hub->control_pipe, 507 &request, sizeof (usb_device_request_setup_packet_t), 508 NULL, 0 509 ); 510 if (opResult != EOK) { 511 usb_log_error("something went wrong when reseting a port %d\n", 512 opResult); 482 513 usb_hub_release_default_address(hub); 483 514 } … … 493 524 * @param speed transfer speed of attached device, one of low, full or high 494 525 */ 495 static void usb_hub_finalize_add_device( 496 526 static void usb_hub_finalize_add_device(usb_hub_info_t * hub, 527 uint16_t port, usb_speed_t speed) { 497 528 498 529 int opResult; 499 530 usb_log_debug("finalizing add device\n"); 500 531 opResult = usb_hub_clear_port_feature(hub->control_pipe, 501 532 port, USB_HUB_FEATURE_C_PORT_RESET); 502 533 503 534 if (opResult != EOK) { … … 510 541 usb_device_connection_t new_device_connection; 511 542 usb_device_connection_initialize_on_default_address( 512 513 514 543 &new_device_connection, 544 &hub->connection 545 ); 515 546 usb_pipe_initialize_default_control( 516 517 547 &new_device_pipe, 548 &new_device_connection); 518 549 usb_pipe_probe_default_control(&new_device_pipe); 519 550 520 551 /* Request address from host controller. */ 521 552 usb_address_t new_device_address = usb_hc_request_address( 522 523 524 553 &hub->connection, 554 speed 555 ); 525 556 if (new_device_address < 0) { 526 557 usb_log_error("failed to get free USB address\n"); … … 529 560 return; 530 561 } 531 usb_log_debug("setting new address %d\n", new_device_address);562 usb_log_debug("setting new address %d\n", new_device_address); 532 563 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 533 564 // new_device_address); 534 565 usb_pipe_start_session(&new_device_pipe); 535 opResult = usb_request_set_address(&new_device_pipe,new_device_address); 566 opResult = usb_request_set_address(&new_device_pipe, 567 new_device_address); 536 568 usb_pipe_end_session(&new_device_pipe); 537 569 if (opResult != EOK) { 538 usb_log_error("could not set address for new device %d\n",opResult); 570 usb_log_error("could not set address for new device %d\n", 571 opResult); 539 572 usb_hub_release_default_address(hub); 540 573 return; … … 543 576 //opResult = usb_hub_release_default_address(hc); 544 577 opResult = usb_hub_release_default_address(hub); 545 if (opResult!=EOK){578 if (opResult != EOK) { 546 579 return; 547 580 } … … 549 582 devman_handle_t child_handle; 550 583 //?? 551 opResult = usb_device_register_child_in_devman(new_device_address, 552 hub->connection.hc_handle, hub->usb_device->ddf_dev, &child_handle, 553 NULL, NULL, NULL); 554 555 if (opResult != EOK) { 556 usb_log_error("could not start driver for new device %d\n",opResult); 584 opResult = usb_device_register_child_in_devman(new_device_address, 585 hub->connection.hc_handle, hub->usb_device->ddf_dev, 586 &child_handle, 587 NULL, NULL, NULL); 588 589 if (opResult != EOK) { 590 usb_log_error("could not start driver for new device %d\n", 591 opResult); 557 592 return; 558 593 } … … 562 597 //opResult = usb_drv_bind_address(hc, new_device_address, child_handle); 563 598 opResult = usb_hc_register_device( 564 &hub->connection, 565 &hub->attached_devs[port]); 566 if (opResult != EOK) { 567 usb_log_error("could not assign address of device in hcd %d\n",opResult); 599 &hub->connection, 600 &hub->attached_devs[port]); 601 if (opResult != EOK) { 602 usb_log_error("could not assign address of device in hcd %d\n", 603 opResult); 568 604 return; 569 605 } 570 606 usb_log_info("Detected new device on `%s' (port %d), " \ 571 607 "address %d (handle %llu).\n", 572 573 608 hub->usb_device->ddf_dev->name, (int) port, 609 new_device_address, child_handle); 574 610 } 575 611 … … 584 620 */ 585 621 static void usb_hub_removed_device( 586 usb_hub_info_t * hub,uint16_t port) {622 usb_hub_info_t * hub, uint16_t port) { 587 623 588 624 int opResult = usb_hub_clear_port_feature(hub->control_pipe, 589 590 if (opResult != EOK){625 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 626 if (opResult != EOK) { 591 627 usb_log_warning("could not clear port-change-connection flag\n"); 592 628 } … … 594 630 * devide manager 595 631 */ 596 632 597 633 //close address 598 if (hub->attached_devs[port].address!=0){634 if (hub->attached_devs[port].address != 0) { 599 635 /*uncomment this code to use it when DDF allows device removal 600 636 opResult = usb_hc_unregister_device( 601 &hub->connection, hub->attached_devs[port].address); 637 &hub->connection, 638 hub->attached_devs[port].address); 602 639 if(opResult != EOK) { 603 dprintf(USB_LOG_LEVEL_WARNING, "could not release address of " \ 640 dprintf(USB_LOG_LEVEL_WARNING, "could not release " 641 "address of " 604 642 "removed device: %d", opResult); 605 643 } … … 607 645 hub->attached_devs[port].handle = 0; 608 646 */ 609 }else{ 610 usb_log_warning("this is strange, disconnected device had no address\n"); 611 //device was disconnected before it`s port was reset - return default address 647 } else { 648 usb_log_warning("this is strange, disconnected device had " 649 "no address\n"); 650 //device was disconnected before it`s port was reset - 651 //return default address 612 652 usb_hub_release_default_address(hub); 613 653 } 614 654 } 615 655 616 617 656 /** 618 657 * Process over current condition on port. 619 * 658 * 620 659 * Turn off the power on the port. 621 660 * … … 623 662 * @param port port number, starting from 1 624 663 */ 625 static void usb_hub_over_current( 626 uint16_t port){664 static void usb_hub_over_current(usb_hub_info_t * hub, 665 uint16_t port) { 627 666 int opResult; 628 667 opResult = usb_hub_clear_port_feature(hub->control_pipe, 629 630 if (opResult!=EOK){668 port, USB_HUB_FEATURE_PORT_POWER); 669 if (opResult != EOK) { 631 670 usb_log_error("cannot power off port %d; %d\n", 632 671 port, opResult); 633 672 } 634 673 } … … 641 680 * @param port port number, starting from 1 642 681 */ 643 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 644 682 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 683 uint16_t port) { 645 684 usb_log_debug("interrupt at port %d\n", port); 646 685 //determine type of change 647 686 usb_pipe_t *pipe = hub->control_pipe; 648 687 649 688 int opResult; 650 689 … … 657 696 658 697 opResult = usb_pipe_control_read( 659 660 &request, sizeof(usb_device_request_setup_packet_t),661 662 698 pipe, 699 &request, sizeof (usb_device_request_setup_packet_t), 700 &status, 4, &rcvd_size 701 ); 663 702 if (opResult != EOK) { 664 703 usb_log_error("could not get port status\n"); … … 674 713 if (usb_port_dev_connected(&status)) { 675 714 usb_log_debug("some connection changed\n"); 676 usb_hub_init_add_device(hub, port, usb_port_speed(&status)); 715 usb_hub_init_add_device(hub, port, 716 usb_port_speed(&status)); 677 717 } else { 678 718 usb_hub_removed_device(hub, port); … … 683 723 //check if it was not auto-resolved 684 724 usb_log_debug("overcurrent change on port\n"); 685 if(usb_port_over_current(&status)){ 686 usb_hub_over_current(hub,port); 687 }else{ 688 usb_log_debug("over current condition was auto-resolved on port %d\n", 689 port); 725 if (usb_port_over_current(&status)) { 726 usb_hub_over_current(hub, port); 727 } else { 728 usb_log_debug("over current condition was " 729 "auto-resolved on port %d\n", 730 port); 690 731 } 691 732 } … … 694 735 usb_log_debug("port reset complete\n"); 695 736 if (usb_port_enabled(&status)) { 696 usb_hub_finalize_add_device(hub, port, usb_port_speed(&status)); 737 usb_hub_finalize_add_device(hub, port, 738 usb_port_speed(&status)); 697 739 } else { 698 usb_log_warning("port reset, but port still not enabled\n"); 740 usb_log_warning("port reset, but port still not " 741 "enabled\n"); 699 742 } 700 743 } 701 usb_log_debug("status x%x : %d\n ", status,status);744 usb_log_debug("status x%x : %d\n ", status, status); 702 745 703 746 usb_port_set_connect_change(&status, false); … … 705 748 usb_port_set_reset_completed(&status, false); 706 749 usb_port_set_dev_connected(&status, false); 707 if (status >>16) {750 if (status >> 16) { 708 751 usb_log_info("there was some unsupported change on port %d: %X\n", 709 port,status); 710 711 } 712 } 713 752 port, status); 753 754 } 755 } 714 756 715 757 static int initialize_non_removable(usb_hub_info_t * hub_info, 716 unsigned int port) {758 unsigned int port) { 717 759 int opResult; 718 760 usb_log_debug("there is not pluged in non-removable device on " 719 "port %d\n", port761 "port %d\n", port 720 762 ); 721 763 //usb_hub_init_add_device(hub_info, port, usb_port_speed(&status)); … … 728 770 729 771 opResult = usb_pipe_control_read( 730 731 &request, sizeof(usb_device_request_setup_packet_t),732 733 734 if (opResult != EOK) { 735 usb_log_error("could not get port status %d\n", opResult);772 hub_info->control_pipe, 773 &request, sizeof (usb_device_request_setup_packet_t), 774 &status, 4, &rcvd_size 775 ); 776 if (opResult != EOK) { 777 usb_log_error("could not get port status %d\n", opResult); 736 778 return opResult; 737 779 } … … 740 782 return opResult; 741 783 } 742 usb_log_debug("port status %d, x%x\n", status,status);743 if (usb_port_dev_connected(&status)){784 usb_log_debug("port status %d, x%x\n", status, status); 785 if (usb_port_dev_connected(&status)) { 744 786 usb_log_debug("there is connected device on this port\n"); 745 787 } 746 if(!hub_info->is_default_address_used) 747 usb_hub_init_add_device(hub_info, port, usb_port_speed(&status)); 788 if (!hub_info->is_default_address_used) 789 usb_hub_init_add_device(hub_info, port, 790 usb_port_speed(&status)); 748 791 return opResult; 749 792 } … … 756 799 * @return error code 757 800 */ 758 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info) {801 int usb_hub_check_hub_changes(usb_hub_info_t * hub_info) { 759 802 int opResult; 760 803 opResult = usb_pipe_start_session( 761 hub_info->status_change_pipe); 762 //this might not be necessary - if all non-removables are ok, it is not needed here 804 hub_info->status_change_pipe); 805 //this might not be necessary - if all non-removables are ok, it is 806 //not needed here 763 807 opResult = usb_pipe_start_session(hub_info->control_pipe); 764 if (opResult != EOK){808 if (opResult != EOK) { 765 809 usb_log_error("could not initialize communication for hub; %d\n", 766 810 opResult); 767 811 return opResult; 768 812 } … … 771 815 //first check non-removable devices 772 816 { 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); 817 unsigned int port; 818 for (port = 1; port <= port_count; ++port) { 819 bool is_non_removable = 820 hub_info->not_initialized_non_removables[port/8] 821 & (1 << (port % 8)); 822 if (is_non_removable) { 823 opResult = initialize_non_removable(hub_info, 824 port); 825 } 780 826 } 781 827 } 782 }783 828 784 829 785 830 /// FIXME: count properly 786 size_t byte_length = ((port_count +1) / 8) + 1;787 831 size_t byte_length = ((port_count + 1) / 8) + 1; 832 void *change_bitmap = malloc(byte_length); 788 833 size_t actual_size; 789 834 … … 792 837 */ 793 838 opResult = usb_pipe_read( 794 795 796 839 hub_info->status_change_pipe, 840 change_bitmap, byte_length, &actual_size 841 ); 797 842 798 843 if (opResult != EOK) { 799 844 free(change_bitmap); 800 usb_log_warning("something went wrong while getting status of hub\n"); 845 usb_log_warning("something went wrong while getting the" 846 "status of hub\n"); 801 847 usb_pipe_end_session(hub_info->status_change_pipe); 802 848 return opResult; 803 849 } 804 850 unsigned int port; 805 806 if(opResult!=EOK){ 807 usb_log_error("could not start control pipe session %d\n", opResult); 851 852 if (opResult != EOK) { 853 usb_log_error("could not start control pipe session %d\n", 854 opResult); 808 855 usb_pipe_end_session(hub_info->status_change_pipe); 809 856 return opResult; 810 857 } 811 858 opResult = usb_hc_connection_open(&hub_info->connection); 812 if (opResult!=EOK){859 if (opResult != EOK) { 813 860 usb_log_error("could not start host controller session %d\n", 814 861 opResult); 815 862 usb_pipe_end_session(hub_info->control_pipe); 816 863 usb_pipe_end_session(hub_info->status_change_pipe); … … 819 866 820 867 ///todo, opresult check, pre obe konekce 821 for (port = 1; port < port_count +1; ++port) {868 for (port = 1; port < port_count + 1; ++port) { 822 869 bool interrupt = 823 870 (((uint8_t*) change_bitmap)[port / 8] >> (port % 8)) % 2; 824 871 if (interrupt) { 825 872 usb_hub_process_interrupt( 826 873 hub_info, port); 827 874 } 828 875 }
Note:
See TracChangeset
for help on using the changeset viewer.