Changeset a825eeb0 in mainline
- Timestamp:
- 2011-10-13T12:55:34Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22a2b763
- Parents:
- 3875af65
- Location:
- uspace/drv/bus/usb/usbhub
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
r3875af65 ra825eeb0 55 55 }; 56 56 57 static void usb_hub_port_removed_device(usb_hub_port_t *port, 58 usb_hub_dev_t *hub); 57 static int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub); 59 58 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 60 59 usb_port_status_t status); … … 65 64 usb_speed_t speed); 66 65 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 /*----------------------------------------------------------------------------*/ 67 74 /** 68 75 * Clear feature on hub port. 69 76 * 70 * @param hc Host controller telephone 71 * @param address Hub address 72 * @param port_index Port 73 * @param feature Feature selector 77 * @param port Port structure. 78 * @param feature Feature selector. 74 79 * @return Operation result 75 80 */ … … 78 83 { 79 84 assert(port); 80 usb_device_request_setup_packet_t clear_request = {85 const usb_device_request_setup_packet_t clear_request = { 81 86 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE, 82 87 .request = USB_DEVREQ_CLEAR_FEATURE, … … 90 95 /*----------------------------------------------------------------------------*/ 91 96 /** 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 97 * Set feature on hub port. 98 * 99 * @param port Port structure. 100 * @param feature Feature selector. 98 101 * @return Operation result 99 102 */ … … 102 105 { 103 106 assert(port); 104 usb_device_request_setup_packet_t clear_request = {107 const usb_device_request_setup_packet_t clear_request = { 105 108 .request_type = USB_HUB_REQ_TYPE_SET_PORT_FEATURE, 106 109 .request = USB_DEVREQ_SET_FEATURE, … … 113 116 } 114 117 /*----------------------------------------------------------------------------*/ 118 /** 119 * Mark reset process as failed due to external reasons 120 * 121 * @param port Port structure 122 */ 115 123 void usb_hub_port_reset_fail(usb_hub_port_t *port) 116 124 { … … 124 132 /*----------------------------------------------------------------------------*/ 125 133 /** 126 * Process interrupts on given hubport134 * Process interrupts on given port 127 135 * 128 136 * Accepts connection, over current and port reset change. 137 * @param port port structure 129 138 * @param hub hub representation 130 * @param port port number, starting from 1131 139 */ 132 140 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub) … … 171 179 * to that handler, it shall ACK the change too. */ 172 180 if (!(status & USB_HUB_PORT_C_STATUS_ENABLED)) { 173 usb_hub_port_ removed_device(port, hub);181 usb_hub_port_device_gone(port, hub); 174 182 } 175 183 } … … 180 188 usb_log_info("Port %zu, disabled because of errors.\n", 181 189 port->port_number); 182 usb_hub_port_ removed_device(port, hub);190 usb_hub_port_device_gone(port, hub); 183 191 const int rc = usb_hub_port_clear_feature(port, 184 192 USB_HUB_FEATURE_C_PORT_ENABLE); … … 238 246 port->port_number, status); 239 247 } 240 248 /*----------------------------------------------------------------------------*/ 241 249 /** 242 250 * routine called when a device on port has been removed … … 245 253 * Otherwise does not do anything, because DDF does not allow to remove device 246 254 * from it`s device tree. 255 * @param port port structure 247 256 * @param hub hub representation 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_dev_t *hub) 257 */ 258 int usb_hub_port_device_gone(usb_hub_port_t *port, usb_hub_dev_t *hub) 252 259 { 253 260 assert(port); 254 261 assert(hub); 255 if (port->attached_device.address >= 0) { 256 fibril_mutex_lock(&port->mutex); 257 usb_log_debug("Removing device on port %zu.\n", 258 port->port_number); 259 const int ret = ddf_fun_unbind(port->attached_device.fun); 260 if (ret == EOK) { 261 ddf_fun_destroy(port->attached_device.fun); 262 const int ret = 263 usb_hc_unregister_device(&hub->connection, 264 port->attached_device.address); 265 if (ret != EOK) { 266 usb_log_error("Failed to unregister " 267 "address of removed device: %s.\n", 268 str_error(ret)); 269 } 270 } else { 271 usb_log_error("Failed to unbind child function on port" 272 " %zu: %s.\n", port->port_number, str_error(ret)); 273 } 274 port->attached_device.address = -1; 275 port->attached_device.fun = NULL; 276 fibril_mutex_unlock(&port->mutex); 277 usb_log_info("Removed device on port %zu.\n", 278 port->port_number); 279 } else { 262 if (port->attached_device.address < 0) { 280 263 usb_log_warning( 281 264 "Device on port %zu removed before being registered.\n", … … 288 271 */ 289 272 usb_hub_port_reset_fail(port); 290 } 291 } 292 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_unregister_device(&hub->connection, 291 port->attached_device.address); 292 if (ret != EOK) { 293 usb_log_warning("Failed to unregister address of the removed " 294 "device: %s.\n", str_error(ret)); 295 } 296 port->attached_device.address = -1; 297 fibril_mutex_unlock(&port->mutex); 298 usb_log_info("Removed device on port %zu.\n", port->port_number); 299 return EOK; 300 } 301 /*----------------------------------------------------------------------------*/ 293 302 /** 294 303 * Process port reset change … … 296 305 * After this change port should be enabled, unless some problem occurred. 297 306 * This functions triggers second phase of enabling new device. 298 * @param hub 299 * @param port 300 * @param status 301 */ 302 static void usb_hub_port_reset_completed(usb_hub_port_t *port, 307 * @param port Port structure 308 * @param status Port status mask 309 */ 310 void usb_hub_port_reset_completed(usb_hub_port_t *port, 303 311 usb_port_status_t status) 304 312 { … … 330 338 /** Retrieve port status. 331 339 * 332 * @param[in] ctrl_pipe Control pipe to use. 333 * @param[in] port Port number (starting at 1). 340 * @param[in] port Port structure 334 341 * @param[out] status Where to store the port status. 335 342 * @return Error code. … … 397 404 fibril_mutex_unlock(&port->mutex); 398 405 399 if (port->reset_okay) { 400 return EOK; 401 } else { 402 return ESTALL; 403 } 404 } 405 406 return port->reset_okay ? EOK : ESTALL; 407 } 408 /*----------------------------------------------------------------------------*/ 406 409 /** Fibril for adding a new device. 407 410 * … … 412 415 * @return 0 Always. 413 416 */ 414 staticint add_device_phase1_worker_fibril(void *arg)417 int add_device_phase1_worker_fibril(void *arg) 415 418 { 416 419 struct add_device_phase1 *data = arg; … … 449 452 free(arg); 450 453 451 return EOK;452 } 453 454 return rc; 455 } 456 /*----------------------------------------------------------------------------*/ 454 457 /** Start device adding when connection change is detected. 455 458 * -
uspace/drv/bus/usb/usbhub/port.h
r3875af65 ra825eeb0 76 76 fibril_condvar_initialize(&port->reset_cv); 77 77 } 78 79 void usb_hub_port_reset_fail(usb_hub_port_t *port); 80 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub); 78 int usb_hub_port_fini(usb_hub_port_t *port, usb_hub_dev_t *hub); 81 79 int usb_hub_port_clear_feature( 82 80 usb_hub_port_t *port, usb_hub_class_feature_t feature); 83 81 int usb_hub_port_set_feature( 84 82 usb_hub_port_t *port, usb_hub_class_feature_t feature); 83 void usb_hub_port_reset_fail(usb_hub_port_t *port); 84 void usb_hub_port_process_interrupt(usb_hub_port_t *port, usb_hub_dev_t *hub); 85 85 86 86 #endif -
uspace/drv/bus/usb/usbhub/usbhub.c
r3875af65 ra825eeb0 98 98 99 99 assert(!hub->running); 100 101 for (size_t port = 0; port < hub->port_count; ++port) { 102 if (hub->ports[port].attached_device.fun) { 103 const int ret = 104 usb_hub_port_fini(&hub->ports[port], hub); 105 if (ret != EOK) 106 return ret; 107 } 108 } 109 free(hub->ports); 110 100 111 const int ret = ddf_fun_unbind(hub->hub_fun); 101 112 if (ret != EOK) { … … 105 116 } 106 117 ddf_fun_destroy(hub->hub_fun); 107 free(hub->ports); 118 108 119 free(hub); 109 120 usb_dev->driver_data = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.