Changes in uspace/drv/bus/usb/usbhub/port.c [344a0ac:e231d26] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
r344a0ac re231d26 50 50 /** Information for fibril for device discovery. */ 51 51 struct add_device_phase1 { 52 usb_hub_ dev_t *hub;52 usb_hub_info_t *hub; 53 53 usb_hub_port_t *port; 54 54 usb_speed_t speed; 55 55 }; 56 56 57 static int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub); 57 static void usb_hub_port_removed_device(usb_hub_port_t *port, 58 usb_hub_info_t *hub); 58 59 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 59 60 usb_port_status_t status); 60 61 static int get_port_status(usb_hub_port_t *port, usb_port_status_t *status); 61 static int enable_port_callback( void *arg);62 static int enable_port_callback(int port_no, void *arg); 62 63 static int add_device_phase1_worker_fibril(void *arg); 63 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_ dev_t *hub,64 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_info_t *hub, 64 65 usb_speed_t speed); 65 66 66 int usb_hub_port_fini(usb_hub_port_t *port, usb_hub_dev_t *hub)67 {68 assert(port);69 if (port->attached_device.fun)70 return usb_hub_port_device_gone(port, hub);71 return EOK;72 }73 /*----------------------------------------------------------------------------*/74 67 /** 75 68 * Clear feature on hub port. 76 69 * 77 * @param port Port structure. 78 * @param feature Feature selector. 70 * @param hc Host controller telephone 71 * @param address Hub address 72 * @param port_index Port 73 * @param feature Feature selector 79 74 * @return Operation result 80 75 */ … … 83 78 { 84 79 assert(port); 85 constusb_device_request_setup_packet_t clear_request = {80 usb_device_request_setup_packet_t clear_request = { 86 81 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, 87 82 .request = USB_DEVREQ_CLEAR_FEATURE, … … 95 90 /*----------------------------------------------------------------------------*/ 96 91 /** 97 * Set feature on hub port. 98 * 99 * @param port Port structure. 100 * @param feature Feature selector. 92 * Clear feature on hub port. 93 * 94 * @param hc Host controller telephone 95 * @param address Hub address 96 * @param port_index Port 97 * @param feature Feature selector 101 98 * @return Operation result 102 99 */ … … 105 102 { 106 103 assert(port); 107 constusb_device_request_setup_packet_t clear_request = {104 usb_device_request_setup_packet_t clear_request = { 108 105 .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE, 109 106 .request = USB_DEVREQ_SET_FEATURE, … … 116 113 } 117 114 /*----------------------------------------------------------------------------*/ 118 /**119 * Mark reset process as failed due to external reasons120 *121 * @param port Port structure122 */123 115 void usb_hub_port_reset_fail(usb_hub_port_t *port) 124 116 { … … 132 124 /*----------------------------------------------------------------------------*/ 133 125 /** 134 * Process interrupts on given port126 * Process interrupts on given hub port 135 127 * 136 128 * Accepts connection, over current and port reset change. 137 * @param port port structure138 129 * @param hub hub representation 139 */ 140 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub) 130 * @param port port number, starting from 1 131 */ 132 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_info_t *hub) 141 133 { 142 134 assert(port); … … 179 171 * to that handler, it shall ACK the change too. */ 180 172 if (!(status & USB_HUB_PORT_C_STATUS_ENABLED)) { 181 usb_hub_port_ device_gone(port, hub);173 usb_hub_port_removed_device(port, hub); 182 174 } 183 175 } … … 188 180 usb_log_info("Port %zu, disabled because of errors.\n", 189 181 port->port_number); 190 usb_hub_port_ device_gone(port, hub);182 usb_hub_port_removed_device(port, hub); 191 183 const int rc = usb_hub_port_clear_feature(port, 192 184 USB_HUB_FEATURE_C_PORT_ENABLE); … … 246 238 port->port_number, status); 247 239 } 248 /*----------------------------------------------------------------------------*/ 240 249 241 /** 250 242 * routine called when a device on port has been removed … … 253 245 * Otherwise does not do anything, because DDF does not allow to remove device 254 246 * from it`s device tree. 255 * @param port port structure256 247 * @param hub hub representation 257 */ 258 int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub) 248 * @param port port number, starting from 1 249 */ 250 static void usb_hub_port_removed_device(usb_hub_port_t *port, 251 usb_hub_info_t *hub) 259 252 { 260 253 assert(port); 261 254 assert(hub); 262 if (port->attached_device.address < 0) { 255 if (port->attached_device.address >= 0) { 256 fibril_mutex_lock(&port->mutex); 257 port->attached_device.address = -1; 258 port->attached_device.handle = 0; 259 fibril_mutex_unlock(&port->mutex); 260 usb_log_info("Removed device on port %zu.\n", 261 port->port_number); 262 } else { 263 263 usb_log_warning( 264 264 "Device on port %zu removed before being registered.\n", … … 271 271 */ 272 272 usb_hub_port_reset_fail(port); 273 return EOK; 274 } 275 276 fibril_mutex_lock(&port->mutex); 277 assert(port->attached_device.fun); 278 usb_log_debug("Removing device on port %zu.\n", port->port_number); 279 int ret = ddf_fun_unbind(port->attached_device.fun); 280 if (ret != EOK) { 281 usb_log_error("Failed to unbind child function on port" 282 " %zu: %s.\n", port->port_number, str_error(ret)); 283 fibril_mutex_unlock(&port->mutex); 284 return ret; 285 } 286 287 ddf_fun_destroy(port->attached_device.fun); 288 port->attached_device.fun = NULL; 289 290 ret = usb_hc_connection_open(&hub->connection); 291 if (ret == EOK) { 292 ret = usb_hc_unregister_device(&hub->connection, 293 port->attached_device.address); 294 if (ret != EOK) { 295 usb_log_warning("Failed to unregister address of the " 296 "removed device: %s.\n", str_error(ret)); 297 } 298 ret = usb_hc_connection_close(&hub->connection); 299 if (ret != EOK) { 300 usb_log_warning("Failed to close hc connection %s.\n", 301 str_error(ret)); 302 } 303 304 } else { 305 usb_log_warning("Failed to open hc connection %s.\n", 306 str_error(ret)); 307 } 308 309 port->attached_device.address = -1; 310 fibril_mutex_unlock(&port->mutex); 311 usb_log_info("Removed device on port %zu.\n", port->port_number); 312 return EOK; 313 } 314 /*----------------------------------------------------------------------------*/ 273 } 274 } 275 315 276 /** 316 277 * Process port reset change … … 318 279 * After this change port should be enabled, unless some problem occurred. 319 280 * This functions triggers second phase of enabling new device. 320 * @param port Port structure 321 * @param status Port status mask 322 */ 323 void usb_hub_port_reset_completed(usb_hub_port_t *port, 281 * @param hub 282 * @param port 283 * @param status 284 */ 285 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 324 286 usb_port_status_t status) 325 287 { … … 351 313 /** Retrieve port status. 352 314 * 353 * @param[in] port Port structure 315 * @param[in] ctrl_pipe Control pipe to use. 316 * @param[in] port Port number (starting at 1). 354 317 * @param[out] status Where to store the port status. 355 318 * @return Error code. … … 395 358 * 396 359 * @param port_no Port number (starting at 1). 397 * @param arg Custom argument, points to @c usb_hub_ dev_t.360 * @param arg Custom argument, points to @c usb_hub_info_t. 398 361 * @return Error code. 399 362 */ 400 static int enable_port_callback( void *arg)363 static int enable_port_callback(int port_no, void *arg) 401 364 { 402 365 usb_hub_port_t *port = arg; … … 417 380 fibril_mutex_unlock(&port->mutex); 418 381 419 return port->reset_okay ? EOK : ESTALL; 420 } 421 /*----------------------------------------------------------------------------*/ 382 if (port->reset_okay) { 383 return EOK; 384 } else { 385 return ESTALL; 386 } 387 } 388 422 389 /** Fibril for adding a new device. 423 390 * … … 428 395 * @return 0 Always. 429 396 */ 430 int add_device_phase1_worker_fibril(void *arg)397 static int add_device_phase1_worker_fibril(void *arg) 431 398 { 432 399 struct add_device_phase1 *data = arg; … … 434 401 435 402 usb_address_t new_address; 436 d df_fun_t *child_fun;403 devman_handle_t child_handle; 437 404 438 405 const int rc = usb_hc_new_device_wrapper(data->hub->usb_device->ddf_dev, 439 &data->hub->connection, data->speed, enable_port_callback, 440 data->port, &new_address, NULL, NULL, &child_fun); 406 &data->hub->connection, data->speed, 407 enable_port_callback, (int) data->port->port_number, 408 data->port, &new_address, &child_handle, 409 NULL, NULL, NULL); 441 410 442 411 if (rc != EOK) { … … 447 416 448 417 fibril_mutex_lock(&data->port->mutex); 449 data->port->attached_device. fun = child_fun;418 data->port->attached_device.handle = child_handle; 450 419 data->port->attached_device.address = new_address; 451 420 fibril_mutex_unlock(&data->port->mutex); … … 454 423 "address %d (handle %" PRIun ").\n", 455 424 data->hub->usb_device->ddf_dev->name, data->port->port_number, 456 new_address, child_ fun->handle);425 new_address, child_handle); 457 426 458 427 leave: … … 465 434 free(arg); 466 435 467 return rc;468 } 469 /*----------------------------------------------------------------------------*/ 436 return EOK; 437 } 438 470 439 /** Start device adding when connection change is detected. 471 440 * … … 477 446 * @return Error code. 478 447 */ 479 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_ dev_t *hub,448 static int create_add_device_fibril(usb_hub_port_t *port, usb_hub_info_t *hub, 480 449 usb_speed_t speed) 481 450 { … … 483 452 assert(port); 484 453 struct add_device_phase1 *data 485 = malloc(sizeof (struct add_device_phase1));454 = malloc(sizeof (struct add_device_phase1)); 486 455 if (data == NULL) { 487 456 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.