Changeset 3df8ea9 in mainline
- Timestamp:
- 2013-01-07T16:52:15Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e6becb9
- Parents:
- c8c758d
- Location:
- uspace/drv/bus/usb/usbhub
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
rc8c758d r3df8ea9 58 58 usb_port_status_t status); 59 59 static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status); 60 static int enable_port_callback(void *arg);60 //static int enable_port_callback(void *arg); 61 61 static int add_device_phase1_worker_fibril(void *arg); 62 62 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_dev_t *hub, … … 259 259 assert(port); 260 260 assert(hub); 261 async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session); 262 if (!exch) 263 return ENOMEM; 264 const int rc = usb_device_remove(exch, port->attached_handle); 265 async_exchange_end(exch); 266 if (rc == EOK) 267 port->attached_handle = -1; 268 return rc; 269 270 #if 0 261 271 if (port->attached_device.address < 0) { 262 272 usb_log_warning( … … 298 308 usb_log_info("Removed device on port %zu.\n", port->port_number); 299 309 return EOK; 310 #endif 300 311 } 301 312 … … 376 387 } 377 388 389 static int port_enable(usb_hub_port_t *port, bool enable) 390 { 391 if (enable) { 392 const int rc = 393 usb_hub_port_set_feature(port, USB_HUB_FEATURE_PORT_RESET); 394 if (rc != EOK) { 395 usb_log_error("Port reset failed: %s.\n", 396 str_error(rc)); 397 } else { 398 /* Wait until reset completes. */ 399 fibril_mutex_lock(&port->mutex); 400 while (!port->reset_completed) { 401 fibril_condvar_wait(&port->reset_cv, 402 &port->mutex); 403 } 404 fibril_mutex_unlock(&port->mutex); 405 } 406 return port->reset_okay ? EOK : ESTALL; 407 } else { 408 return usb_hub_port_clear_feature(port, 409 USB_HUB_FEATURE_PORT_ENABLE); 410 } 411 } 412 378 413 /** Callback for enabling a specific port. 379 414 * … … 385 420 * @return Error code. 386 421 */ 422 #if 0 387 423 static int enable_port_callback(void *arg) 388 424 { … … 407 443 return port->reset_okay ? EOK : ESTALL; 408 444 } 445 #endif 409 446 410 447 /** Fibril for adding a new device. … … 418 455 int add_device_phase1_worker_fibril(void *arg) 419 456 { 457 struct add_device_phase1 *params = arg; 458 assert(params); 459 460 usb_hub_dev_t *hub = params->hub; 461 usb_hub_port_t *port = params->port; 462 const usb_speed_t speed = params->speed; 463 free(arg); 464 465 usb_log_fatal("Creating Exchange on session %p\n", 466 hub->usb_device->bus_session); 467 async_exch_t *exch = async_exchange_begin(hub->usb_device->bus_session); 468 if (!exch) { 469 usb_log_error("Failed to begin bus exchange\n"); 470 return ENOMEM; 471 } 472 473 usb_log_fatal("reserving default address\n"); 474 475 /* Reserve default address */ 476 int ret; 477 while ((ret = usb_reserve_default_address(exch, speed)) == ENOENT) { 478 usb_log_fatal("reserving default address %d\n", ret); 479 async_usleep(1000000); 480 } 481 if (ret != EOK) { 482 usb_log_error("Failed to reserve default address: %s\n", 483 str_error(ret)); 484 async_exchange_end(exch); 485 return ret; 486 } 487 488 /* Reset port */ 489 port_enable(port, true); 490 if (!port->reset_completed || !port->reset_okay) { 491 usb_log_error("Failed to reset port %zu\n", port->port_number); 492 if (usb_release_default_address(exch) != EOK) 493 usb_log_warning("Failed to release default address\n"); 494 async_exchange_end(exch); 495 return EIO; 496 } 497 498 ret = usb_device_enumerate(exch, &port->attached_handle); 499 if (ret != EOK) { 500 usb_log_error("Failed to reset port %zu\n", port->port_number); 501 if (port_enable(port, false) != EOK) { 502 usb_log_warning("Failed to disable port %zu, NOT " 503 "releasing default address.\n", port->port_number); 504 } else { 505 if (usb_release_default_address(exch) != EOK) 506 usb_log_warning( 507 "Failed to release default address\n"); 508 } 509 } 510 async_exchange_end(exch); 511 return ret; 512 #if 0 420 513 struct add_device_phase1 *data = arg; 421 514 assert(data); … … 454 547 455 548 return rc; 549 #endif 456 550 } 457 551 -
uspace/drv/bus/usb/usbhub/port.h
rc8c758d r3df8ea9 59 59 bool reset_okay; 60 60 61 usb_device_handle_t attached_handle; 62 61 63 /** Information about attached device. */ 62 64 usb_hub_attached_device_t attached_device; … … 75 77 port->port_number = port_number; 76 78 port->control_pipe = control_pipe; 79 port->attached_handle = USB_DEVICE_HANDLE_INVALID; 77 80 fibril_mutex_initialize(&port->mutex); 78 81 fibril_condvar_initialize(&port->reset_cv);
Note:
See TracChangeset
for help on using the changeset viewer.