Changes in uspace/lib/usbdev/src/hub.c [7711296:7267fa1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/hub.c
r7711296 r7267fa1 63 63 } while (false) 64 64 65 /** Ask host controller for free address assignment.66 *67 * @param connection Opened connection to host controller.68 * @param preferred Preferred SUB address.69 * @param strict Fail if the preferred address is not avialable.70 * @param speed Speed of the new device (device that will be assigned71 * the returned address).72 * @return Assigned USB address or negative error code.73 */74 usb_address_t usb_hc_request_address(usb_hc_connection_t *connection,75 usb_address_t preferred, bool strict, usb_speed_t speed)76 {77 CHECK_CONNECTION(connection);78 79 async_exch_t *exch = async_exchange_begin(connection->hc_sess);80 if (!exch)81 return (usb_address_t)ENOMEM;82 83 usb_address_t address = preferred;84 const int ret = usbhc_request_address(exch, &address, strict, speed);85 86 async_exchange_end(exch);87 return ret == EOK ? address : ret;88 }89 65 90 66 /** Inform host controller about new device. … … 97 73 const usb_hub_attached_device_t *attached_device) 98 74 { 99 CHECK_CONNECTION(connection);75 // CHECK_CONNECTION(connection); 100 76 if (attached_device == NULL || attached_device->fun == NULL) 101 77 return EINVAL; … … 120 96 usb_address_t address) 121 97 { 122 CHECK_CONNECTION(connection);98 // CHECK_CONNECTION(connection); 123 99 124 100 async_exch_t *exch = async_exchange_begin(connection->hc_sess); … … 145 121 * @return Error code. 146 122 */ 147 static int usb_request_set_address(usb_pipe_t *pipe, usb_address_t new_address, 148 usb_hc_connection_t *hc_conn) 123 static int usb_request_set_address(usb_pipe_t *pipe, usb_address_t new_address) 149 124 { 150 125 if ((new_address < 0) || (new_address >= USB11_ADDRESS_MAX)) { … … 152 127 } 153 128 assert(pipe); 154 assert(hc_conn);155 129 assert(pipe->wire != NULL); 156 130 … … 166 140 167 141 /* TODO: prevent others from accessing the wire now. */ 168 if (usb_pipe_unregister(pipe , hc_conn) != EOK) {142 if (usb_pipe_unregister(pipe) != EOK) { 169 143 usb_log_warning( 170 144 "Failed to unregister the old pipe on address change.\n"); 171 145 } 146 /* Address changed. We can release the default, thus 147 * allowing other to access the default address. */ 148 usb_hc_unregister_device(pipe->wire->hc_connection, 149 pipe->wire->address); 150 172 151 /* The address is already changed so set it in the wire */ 173 152 pipe->wire->address = new_address; 174 rc = usb_pipe_register(pipe, 0 , hc_conn);153 rc = usb_pipe_register(pipe, 0); 175 154 if (rc != EOK) 176 155 return EADDRNOTAVAIL; … … 220 199 */ 221 200 int usb_hc_new_device_wrapper(ddf_dev_t *parent, 222 usb_hc_connection_t * connection, usb_speed_t dev_speed,201 usb_hc_connection_t *hc_conn, usb_speed_t dev_speed, 223 202 int (*enable_port)(void *arg), void *arg, usb_address_t *assigned_address, 224 203 ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun) 225 204 { 226 if (new_fun == NULL || connection == NULL)205 if (new_fun == NULL || hc_conn == NULL) 227 206 return EINVAL; 228 229 // TODO: Why not use provided connection?230 usb_hc_connection_t hc_conn;231 usb_hc_connection_initialize(&hc_conn, connection->hc_handle);232 207 233 208 int rc; … … 239 214 } 240 215 241 rc = usb_hc_connection_open(&hc_conn); 216 /* We are gona do a lot of communication better open it in advance. */ 217 rc = usb_hc_connection_open(hc_conn); 242 218 if (rc != EOK) { 243 219 return rc; 244 220 } 245 221 246 /* 247 * Request new address. 248 */ 222 /* Request a new address. */ 249 223 usb_address_t dev_addr = 250 usb_hc_request_address( &hc_conn, 0, false, dev_speed);224 usb_hc_request_address(hc_conn, 0, false, dev_speed); 251 225 if (dev_addr < 0) { 252 226 rc = EADDRNOTAVAIL; 253 227 goto close_connection; 228 } 229 230 /* Initialize connection to device. */ 231 usb_device_connection_t dev_conn; 232 rc = usb_device_connection_initialize_on_default_address( 233 &dev_conn, hc_conn); 234 if (rc != EOK) { 235 rc = ENOTCONN; 236 goto leave_release_free_address; 254 237 } 255 238 … … 260 243 * (Someone else already wants to add a new device.) 261 244 */ 262 usb_device_connection_t dev_conn;263 rc = usb_device_connection_initialize_on_default_address(&dev_conn,264 &hc_conn);265 if (rc != EOK) {266 rc = ENOTCONN;267 goto leave_release_free_address;268 }269 270 245 usb_pipe_t ctrl_pipe; 271 246 rc = usb_pipe_initialize_default_control(&ctrl_pipe, &dev_conn); … … 276 251 277 252 do { 278 rc = usb_hc_request_address( &hc_conn, USB_ADDRESS_DEFAULT,253 rc = usb_hc_request_address(hc_conn, USB_ADDRESS_DEFAULT, 279 254 true, dev_speed); 280 255 if (rc == ENOENT) { … … 288 263 289 264 /* Register control pipe on default address. */ 290 rc = usb_pipe_register(&ctrl_pipe, 0 , &hc_conn);265 rc = usb_pipe_register(&ctrl_pipe, 0); 291 266 if (rc != EOK) { 292 267 rc = ENOTCONN; … … 330 305 } 331 306 332 rc = usb_request_set_address(&ctrl_pipe, dev_addr , &hc_conn);307 rc = usb_request_set_address(&ctrl_pipe, dev_addr); 333 308 if (rc != EOK) { 334 309 rc = ESTALL; … … 336 311 } 337 312 338 /* Address changed. We can release the default, thus339 * allowing other to access the default address. */340 usb_hc_unregister_device(&hc_conn, USB_ADDRESS_DEFAULT);341 313 342 314 /* Register the device with devman. */ … … 356 328 357 329 /* Inform the host controller about the handle. */ 358 rc = usb_hc_register_device( &hc_conn, &new_device);330 rc = usb_hc_register_device(hc_conn, &new_device); 359 331 if (rc != EOK) { 360 332 /* We know nothing about that data. */ … … 381 353 */ 382 354 leave_release_default_address: 383 usb_hc_unregister_device( &hc_conn, USB_ADDRESS_DEFAULT);355 usb_hc_unregister_device(hc_conn, USB_ADDRESS_DEFAULT); 384 356 385 357 leave_release_free_address: 386 358 /* This might be either 0:0 or dev_addr:0 */ 387 if (usb_pipe_unregister(&ctrl_pipe , &hc_conn) != EOK)359 if (usb_pipe_unregister(&ctrl_pipe) != EOK) 388 360 usb_log_warning("%s: Failed to unregister default pipe.\n", 389 361 __FUNCTION__); 390 362 391 if (usb_hc_unregister_device( &hc_conn, dev_addr) != EOK)363 if (usb_hc_unregister_device(hc_conn, dev_addr) != EOK) 392 364 usb_log_warning("%s: Failed to unregister device.\n", 393 365 __FUNCTION__); 394 366 395 367 close_connection: 396 if (usb_hc_connection_close( &hc_conn) != EOK)368 if (usb_hc_connection_close(hc_conn) != EOK) 397 369 usb_log_warning("%s: Failed to close hc connection.\n", 398 370 __FUNCTION__);
Note:
See TracChangeset
for help on using the changeset viewer.