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