Changes in uspace/drv/usbhub/usbhub.c [e93e319:42a3a57] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhub/usbhub.c
re93e319 r42a3a57 78 78 async_usleep(1000 * 1000 );/// \TODO proper number once 79 79 } 80 usb_log_error("something in ctrl loop went wrong, errno %d",errorCode);81 80 dprintf(USB_LOG_LEVEL_ERROR, 81 "something in ctrl loop went wrong, errno %d",errorCode); 82 82 return 0; 83 83 } … … 104 104 hub->device); 105 105 if(opResult != EOK){ 106 usb_log_error("could not initialize connection to hc, errno %d",opResult); 106 dprintf(USB_LOG_LEVEL_ERROR, 107 "could not initialize connection to hc, errno %d",opResult); 107 108 return opResult; 108 109 } … … 111 112 hub->device); 112 113 if(opResult != EOK){ 113 usb_log_error("could not initialize connection to device, errno %d",114 opResult);114 dprintf(USB_LOG_LEVEL_ERROR, 115 "could not initialize connection to device, errno %d",opResult); 115 116 return opResult; 116 117 } … … 119 120 &hub->device_connection); 120 121 if(opResult != EOK){ 121 usb_log_error("could not initialize connection to device endpoint, errno %d",122 opResult);122 dprintf(USB_LOG_LEVEL_ERROR, 123 "could not initialize connection to device endpoint, errno %d",opResult); 123 124 return opResult; 124 125 } … … 126 127 opResult = usb_endpoint_pipe_probe_default_control(&hub->endpoints.control); 127 128 if (opResult != EOK) { 128 usb_log_error("failed probing endpoint 0, %d", opResult);129 dprintf(USB_LOG_LEVEL_ERROR, "failed probing endpoint 0, %d", opResult); 129 130 return opResult; 130 131 } … … 150 151 &std_descriptor); 151 152 if(opResult!=EOK){ 152 usb_log_error("could not get device descriptor, %d",opResult);153 return opResult; 154 } 155 usb_log_info("hub has %d configurations",153 dprintf(USB_LOG_LEVEL_ERROR, "could not get device descriptor, %d",opResult); 154 return opResult; 155 } 156 dprintf(USB_LOG_LEVEL_INFO, "hub has %d configurations", 156 157 std_descriptor.configuration_count); 157 158 if(std_descriptor.configuration_count<1){ 158 usb_log_error("THERE ARE NO CONFIGURATIONS AVAILABLE");159 dprintf(USB_LOG_LEVEL_ERROR, "THERE ARE NO CONFIGURATIONS AVAILABLE"); 159 160 //shouldn`t I return? 160 161 } … … 183 184 return opResult; 184 185 } 185 usb_log_debug("\tused configuration %d",186 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d", 186 187 config_descriptor->configuration_number); 187 188 … … 199 200 &hub->device_connection); 200 201 if (opResult != EOK) { 201 usb_log_error("Failed to initialize status change pipe: %s", 202 dprintf(USB_LOG_LEVEL_ERROR, 203 "Failed to initialize status change pipe: %s", 202 204 str_error(opResult)); 203 205 return opResult; 204 206 } 205 207 if (!endpoint_mapping[0].present) { 206 usb_log_error("Not accepting device, " \208 dprintf(USB_LOG_LEVEL_ERROR,"Not accepting device, " \ 207 209 "cannot understand what is happenning"); 208 210 return EREFUSED; … … 233 235 result->port_count = -1; 234 236 result->device = device; 235 result->is_default_address_used = false;236 237 237 238 //result->usb_device = usb_new(usb_hcd_attached_device_info_t); … … 239 240 240 241 // get hub descriptor 241 usb_log_debug("creating serialized descripton");242 dprintf(USB_LOG_LEVEL_DEBUG, "creating serialized descripton"); 242 243 void * serialized_descriptor = malloc(USB_HUB_MAX_DESCRIPTOR_SIZE); 243 244 usb_hub_descriptor_t * descriptor; 244 usb_log_debug("starting control transaction");245 dprintf(USB_LOG_LEVEL_DEBUG, "starting control transaction"); 245 246 usb_endpoint_pipe_start_session(&result->endpoints.control); 246 247 opResult = usb_request_set_configuration(&result->endpoints.control, 1); … … 255 256 256 257 if (opResult != EOK) { 257 usb_log_error("failed when receiving hub descriptor, badcode = %d", 258 opResult); 258 dprintf(USB_LOG_LEVEL_ERROR, "failed when receiving hub descriptor, badcode = %d",opResult); 259 259 free(serialized_descriptor); 260 260 free(result); 261 261 return NULL; 262 262 } 263 usb_log_debug2("deserializing descriptor");263 dprintf(USB_LOG_LEVEL_DEBUG2, "deserializing descriptor"); 264 264 descriptor = usb_deserialize_hub_desriptor(serialized_descriptor); 265 265 if(descriptor==NULL){ 266 usb_log_warning("could not deserialize descriptor ");266 dprintf(USB_LOG_LEVEL_WARNING, "could not deserialize descriptor "); 267 267 free(result); 268 268 return NULL; 269 269 } 270 270 271 usb_log_info("setting port count to %d",descriptor->ports_count);271 dprintf(USB_LOG_LEVEL_INFO, "setting port count to %d",descriptor->ports_count); 272 272 result->port_count = descriptor->ports_count; 273 273 result->attached_devs = (usb_hc_attached_device_t*) … … 278 278 result->attached_devs[i].address=0; 279 279 } 280 usb_log_debug2("freeing data");280 dprintf(USB_LOG_LEVEL_DEBUG2, "freeing data"); 281 281 free(serialized_descriptor); 282 282 free(descriptor->devices_removable); … … 285 285 //finish 286 286 287 usb_log_info("hub info created");287 dprintf(USB_LOG_LEVEL_INFO, "hub info created"); 288 288 289 289 return result; … … 296 296 */ 297 297 int usb_add_hub_device(ddf_dev_t *dev) { 298 usb_log_info("add_hub_device(handle=%d)", (int) dev->handle);298 dprintf(USB_LOG_LEVEL_INFO, "add_hub_device(handle=%d)", (int) dev->handle); 299 299 300 300 //dev->ops = &hub_device_ops; … … 313 313 opResult = usb_hub_process_configuration_descriptors(hub_info); 314 314 if(opResult != EOK){ 315 usb_log_error("could not get configuration descriptors, %d",315 dprintf(USB_LOG_LEVEL_ERROR,"could not get configuration descriptors, %d", 316 316 opResult); 317 317 return opResult; … … 324 324 opResult = usb_endpoint_pipe_control_write(&hub_info->endpoints.control, 325 325 &request,sizeof(usb_device_request_setup_packet_t), NULL, 0); 326 usb_log_info("powering port %d",port);326 dprintf(USB_LOG_LEVEL_INFO, "powering port %d",port); 327 327 if (opResult != EOK) { 328 usb_log_warning("something went wrong when setting hub`s %dth port", port);328 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong when setting hub`s %dth port", port); 329 329 } 330 330 } … … 337 337 usb_lst_append(&usb_hub_list, hub_info); 338 338 fibril_mutex_unlock(&usb_hub_list_lock); 339 usb_log_debug("hub info added to list");340 341 usb_log_debug("adding to ddf");339 dprintf(USB_LOG_LEVEL_DEBUG, "hub info added to list"); 340 341 dprintf(USB_LOG_LEVEL_DEBUG, "adding to ddf"); 342 342 ddf_fun_t *hub_fun = ddf_fun_create(dev, fun_exposed, "hub"); 343 343 assert(hub_fun != NULL); … … 351 351 fid_t fid = fibril_create(usb_hub_control_loop, hub_info); 352 352 if (fid == 0) { 353 usb_log_error("failed to start monitoring fibril for new hub"); 353 dprintf(USB_LOG_LEVEL_ERROR, 354 ": failed to start monitoring fibril for new hub"); 354 355 return ENOMEM; 355 356 } 356 357 fibril_add_ready(fid); 357 358 358 usb_log_debug("hub fibril created");359 dprintf(USB_LOG_LEVEL_DEBUG, "hub fibril created"); 359 360 //(void)hub_info; 360 361 //usb_hub_check_hub_changes(); 361 362 362 usb_log_info("hub dev added");363 dprintf(USB_LOG_LEVEL_INFO, "hub dev added"); 363 364 //address is lost... 364 usb_log_debug("\taddress %d, has %d ports ",365 dprintf(USB_LOG_LEVEL_DEBUG, "\taddress %d, has %d ports ", 365 366 //hub_info->endpoints.control., 366 367 hub_info->port_count); … … 378 379 379 380 /** 380 * release default address used by given hub381 *382 * Also unsets hub->is_default_address_used. Convenience wrapper function.383 * @note hub->connection MUST be open for communication384 * @param hub hub representation385 * @return error code386 */387 static int usb_hub_release_default_address(usb_hub_info_t * hub){388 int opResult = usb_hc_release_default_address(&hub->connection);389 if(opResult!=EOK){390 usb_log_error("could not release default address, errno %d",opResult);391 return opResult;392 }393 hub->is_default_address_used = false;394 return EOK;395 }396 397 /**398 381 * Reset the port with new device and reserve the default address. 399 382 * @param hc … … 402 385 */ 403 386 static void usb_hub_init_add_device(usb_hub_info_t * hub, uint16_t port, 404 usb_speed_t speed) { 405 //if this hub already uses default address, it cannot request it once more 406 if(hub->is_default_address_used) return; 407 int opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 408 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 409 if(opResult != EOK){ 410 usb_log_warning("could not clear port-change-connection flag"); 411 } 412 387 bool isLowSpeed) { 413 388 usb_device_request_setup_packet_t request; 414 usb_log_info("some connection changed"); 389 int opResult; 390 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 415 391 assert(hub->endpoints.control.hc_phone); 416 392 //get default address 393 usb_speed_t speed = isLowSpeed?USB_SPEED_LOW:USB_SPEED_FULL; 417 394 opResult = usb_hc_reserve_default_address(&hub->connection, speed); 418 395 419 396 if (opResult != EOK) { 420 usb_log_warning("cannot assign default address, it is probably used %d", 421 opResult); 422 return; 423 } 424 hub->is_default_address_used = true; 397 dprintf(USB_LOG_LEVEL_WARNING, 398 "cannot assign default address, it is probably used %d",opResult); 399 return; 400 } 425 401 //reset port 426 402 usb_hub_set_reset_port_request(&request, port); … … 431 407 ); 432 408 if (opResult != EOK) { 433 usb_log_error("something went wrong when reseting a port %d",opResult); 409 dprintf(USB_LOG_LEVEL_ERROR, 410 "something went wrong when reseting a port %d",opResult); 434 411 //usb_hub_release_default_address(hc); 435 usb_hub_release_default_address(hub); 436 } 437 return; 412 usb_hc_release_default_address(&hub->connection); 413 } 438 414 } 439 415 … … 448 424 449 425 int opResult; 450 usb_log_info("finalizing add device");426 dprintf(USB_LOG_LEVEL_INFO, "finalizing add device"); 451 427 opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 452 428 port, USB_HUB_FEATURE_C_PORT_RESET); 453 429 454 430 if (opResult != EOK) { 455 usb_log_error("failed to clear port reset feature");456 usb_h ub_release_default_address(hub);431 dprintf(USB_LOG_LEVEL_ERROR, "failed to clear port reset feature"); 432 usb_hc_release_default_address(&hub->connection); 457 433 return; 458 434 } … … 478 454 ); 479 455 if (new_device_address < 0) { 480 usb_log_error("failed to get free USB address");456 dprintf(USB_LOG_LEVEL_ERROR, "failed to get free USB address"); 481 457 opResult = new_device_address; 482 usb_h ub_release_default_address(hub);483 return; 484 } 485 usb_log_info("setting new address %d",new_device_address);458 usb_hc_release_default_address(&hub->connection); 459 return; 460 } 461 dprintf(USB_LOG_LEVEL_INFO, "setting new address %d",new_device_address); 486 462 //opResult = usb_drv_req_set_address(hc, USB_ADDRESS_DEFAULT, 487 463 // new_device_address); … … 490 466 usb_endpoint_pipe_end_session(&new_device_pipe); 491 467 if (opResult != EOK) { 492 usb_log_error("could not set address for new device %d",opResult); 493 usb_hub_release_default_address(hub); 468 dprintf(USB_LOG_LEVEL_ERROR, 469 "could not set address for new device %d",opResult); 470 usb_hc_release_default_address(&hub->connection); 494 471 return; 495 472 } … … 497 474 498 475 //opResult = usb_hub_release_default_address(hc); 499 opResult = usb_h ub_release_default_address(hub);476 opResult = usb_hc_release_default_address(&hub->connection); 500 477 if(opResult!=EOK){ 501 478 return; … … 509 486 510 487 if (opResult != EOK) { 511 usb_log_error("could not start driver for new device %d",opResult); 488 dprintf(USB_LOG_LEVEL_ERROR, 489 "could not start driver for new device %d",opResult); 512 490 return; 513 491 } … … 520 498 &hub->attached_devs[port]); 521 499 if (opResult != EOK) { 522 usb_log_error("could not assign address of device in hcd %d",opResult); 523 return; 524 } 525 usb_log_info("new device address %d, handle %zu", 500 dprintf(USB_LOG_LEVEL_ERROR, 501 "could not assign address of device in hcd %d",opResult); 502 return; 503 } 504 dprintf(USB_LOG_LEVEL_INFO, "new device address %d, handle %zu", 526 505 new_device_address, child_handle); 527 506 … … 536 515 static void usb_hub_removed_device( 537 516 usb_hub_info_t * hub,uint16_t port) { 538 539 int opResult = usb_hub_clear_port_feature(&hub->endpoints.control, 540 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 541 if(opResult != EOK){ 542 usb_log_warning("could not clear port-change-connection flag"); 543 } 517 544 518 /** \TODO remove device from device manager - not yet implemented in 545 519 * devide manager … … 559 533 */ 560 534 }else{ 561 usb_log_warning("this is strange, disconnected device had no address");535 dprintf(USB_LOG_LEVEL_WARNING, "this is strange, disconnected device had no address"); 562 536 //device was disconnected before it`s port was reset - return default address 563 usb_hub_release_default_address(hub); 564 } 565 } 566 567 568 /** 569 * Process over current condition on port. 537 //usb_drv_release_default_address(hc); 538 usb_hc_release_default_address(&hub->connection); 539 } 540 } 541 542 543 /** 544 *Process over current condition on port. 570 545 * 571 546 * Turn off the power on the port. … … 580 555 port, USB_HUB_FEATURE_PORT_POWER); 581 556 if(opResult!=EOK){ 582 usb_log_error("cannot power off port %d; %d",557 dprintf(USB_LOG_LEVEL_ERROR, "cannot power off port %d; %d", 583 558 port, opResult); 584 559 } … … 593 568 static void usb_hub_process_interrupt(usb_hub_info_t * hub, 594 569 uint16_t port) { 595 usb_log_debug("interrupt at port %d", port);570 dprintf(USB_LOG_LEVEL_DEBUG, "interrupt at port %d", port); 596 571 //determine type of change 597 572 usb_endpoint_pipe_t *pipe = &hub->endpoints.control; … … 612 587 ); 613 588 if (opResult != EOK) { 614 usb_log_error("could not get port status");589 dprintf(USB_LOG_LEVEL_ERROR, "could not get port status"); 615 590 return; 616 591 } 617 592 if (rcvd_size != sizeof (usb_port_status_t)) { 618 usb_log_error("received status has incorrect size");593 dprintf(USB_LOG_LEVEL_ERROR, "received status has incorrect size"); 619 594 return; 620 595 } 621 596 //something connected/disconnected 622 597 if (usb_port_connect_change(&status)) { 598 opResult = usb_hub_clear_port_feature(pipe, 599 port, USB_HUB_FEATURE_C_PORT_CONNECTION); 600 // TODO: check opResult 623 601 if (usb_port_dev_connected(&status)) { 624 usb_log_info("some connection changed");625 usb_hub_init_add_device(hub, port, usb_port_ speed(&status));602 dprintf(USB_LOG_LEVEL_INFO, "some connection changed"); 603 usb_hub_init_add_device(hub, port, usb_port_low_speed(&status)); 626 604 } else { 627 605 usb_hub_removed_device(hub, port); … … 634 612 usb_hub_over_current(hub,port); 635 613 }else{ 636 usb_log_info("over current condition was auto-resolved on port %d",637 614 dprintf(USB_LOG_LEVEL_INFO, 615 "over current condition was auto-resolved on port %d",port); 638 616 } 639 617 } 640 618 //port reset 641 619 if (usb_port_reset_completed(&status)) { 642 usb_log_info("port reset complete");620 dprintf(USB_LOG_LEVEL_INFO, "port reset complete"); 643 621 if (usb_port_enabled(&status)) { 644 622 usb_hub_finalize_add_device(hub, port, usb_port_low_speed(&status)); 645 623 } else { 646 usb_log_warning("port reset, but port still not enabled");624 dprintf(USB_LOG_LEVEL_WARNING, "port reset, but port still not enabled"); 647 625 } 648 626 } … … 653 631 usb_port_set_dev_connected(&status, false); 654 632 if (status>>16) { 655 usb_log_info("there was some unsupported change on port %d: %X", 656 port,status); 657 658 } 659 /// \TODO handle other changes - is there any? 633 dprintf(USB_LOG_LEVEL_INFO, "there was some unsupported change on port %d: %X",port,status); 634 635 } 636 /// \TODO handle other changes 660 637 } 661 638 … … 670 647 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.status_change); 671 648 if(opResult != EOK){ 672 usb_log_error("could not initialize communication for hub; %d",673 opResult);649 dprintf(USB_LOG_LEVEL_ERROR, 650 "could not initialize communication for hub; %d", opResult); 674 651 return opResult; 675 652 } … … 692 669 if (opResult != EOK) { 693 670 free(change_bitmap); 694 usb_log_warning("something went wrong while getting status of hub");671 dprintf(USB_LOG_LEVEL_WARNING, "something went wrong while getting status of hub"); 695 672 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 696 673 return opResult; … … 699 676 opResult = usb_endpoint_pipe_start_session(&hub_info->endpoints.control); 700 677 if(opResult!=EOK){ 701 usb_log_error("could not start control pipe session %d", opResult); 678 dprintf(USB_LOG_LEVEL_ERROR, "could not start control pipe session %d", 679 opResult); 702 680 usb_endpoint_pipe_end_session(&hub_info->endpoints.status_change); 703 681 return opResult; … … 705 683 opResult = usb_hc_connection_open(&hub_info->connection); 706 684 if(opResult!=EOK){ 707 usb_log_error("could not start host controller session %d",685 dprintf(USB_LOG_LEVEL_ERROR, "could not start host controller session %d", 708 686 opResult); 709 687 usb_endpoint_pipe_end_session(&hub_info->endpoints.control);
Note:
See TracChangeset
for help on using the changeset viewer.