Changes in uspace/drv/uhci-hcd/iface.c [c61338a:92d6868] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/iface.c
rc61338a r92d6868 36 36 37 37 #include <usb/debug.h> 38 #include <usb/host/endpoint.h> 38 39 39 40 #include "iface.h" … … 54 55 usb_device_keeper_reserve_default_address(&hc->manager, speed); 55 56 return EOK; 57 #if 0 58 endpoint_t *ep = malloc(sizeof(endpoint_t)); 59 if (ep == NULL) 60 return ENOMEM; 61 const size_t max_packet_size = speed == USB_SPEED_LOW ? 8 : 64; 62 endpoint_init(ep, USB_TRANSFER_CONTROL, speed, max_packet_size); 63 int ret; 64 try_retgister: 65 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, 66 USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH, ep, endpoint_destroy, 0); 67 if (ret == EEXISTS) { 68 async_usleep(1000); 69 goto try_retgister; 70 } 71 if (ret != EOK) { 72 endpoint_destroy(ep); 73 } 74 return ret; 75 #endif 56 76 } 57 77 /*----------------------------------------------------------------------------*/ … … 67 87 assert(hc); 68 88 usb_log_debug("Default address release.\n"); 89 // return usb_endpoint_manager_unregister_ep(&hc->ep_manager, 90 // USB_ADDRESS_DEFAULT, 0, USB_DIRECTION_BOTH); 69 91 usb_device_keeper_release_default_address(&hc->manager); 70 92 return EOK; … … 128 150 } 129 151 /*----------------------------------------------------------------------------*/ 152 static int register_endpoint( 153 ddf_fun_t *fun, usb_address_t address, usb_endpoint_t endpoint, 154 usb_transfer_type_t transfer_type, usb_direction_t direction, 155 size_t max_packet_size, unsigned int interval) 156 { 157 hc_t *hc = fun_to_hc(fun); 158 assert(hc); 159 const usb_speed_t speed = 160 usb_device_keeper_get_speed(&hc->manager, address); 161 const size_t size = 162 (transfer_type == USB_TRANSFER_INTERRUPT 163 || transfer_type == USB_TRANSFER_ISOCHRONOUS) ? 164 max_packet_size : 0; 165 int ret; 166 167 endpoint_t *ep = malloc(sizeof(endpoint_t)); 168 if (ep == NULL) 169 return ENOMEM; 170 ret = endpoint_init(ep, address, endpoint, direction, 171 transfer_type, speed, max_packet_size); 172 if (ret != EOK) { 173 free(ep); 174 return ret; 175 } 176 177 usb_log_debug("Register endpoint %d:%d %s %s(%d) %zu(%zu) %u.\n", 178 address, endpoint, usb_str_transfer_type(transfer_type), 179 usb_str_speed(speed), direction, size, max_packet_size, interval); 180 181 ret = usb_endpoint_manager_register_ep(&hc->ep_manager, ep, size); 182 if (ret != EOK) { 183 endpoint_destroy(ep); 184 } else { 185 usb_device_keeper_add_ep(&hc->manager, address, ep); 186 } 187 return ret; 188 } 189 /*----------------------------------------------------------------------------*/ 190 static int unregister_endpoint( 191 ddf_fun_t *fun, usb_address_t address, 192 usb_endpoint_t endpoint, usb_direction_t direction) 193 { 194 hc_t *hc = fun_to_hc(fun); 195 assert(hc); 196 usb_log_debug("Unregister endpoint %d:%d %d.\n", 197 address, endpoint, direction); 198 return usb_endpoint_manager_unregister_ep(&hc->ep_manager, address, 199 endpoint, direction); 200 } 201 /*----------------------------------------------------------------------------*/ 130 202 /** Interrupt out transaction interface function 131 203 * … … 146 218 hc_t *hc = fun_to_hc(fun); 147 219 assert(hc); 148 usb_speed_t speed =149 usb_device_keeper_get_speed(&hc->manager, target.address);150 220 151 221 usb_log_debug("Interrupt OUT %d:%d %zu(%zu).\n", 152 222 target.address, target.endpoint, size, max_packet_size); 153 223 224 size_t res_bw; 225 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 226 target.address, target.endpoint, USB_DIRECTION_OUT, &res_bw); 227 if (ep == NULL) { 228 usb_log_error("Endpoint(%d:%d) not registered for INT OUT.\n", 229 target.address, target.endpoint); 230 return ENOENT; 231 } 232 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 233 size, ep->max_packet_size); 234 if (res_bw < bw) 235 { 236 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 237 "but only %zu is reserved.\n", 238 target.address, target.endpoint, bw, res_bw); 239 return ENOENT; 240 } 241 assert(ep->speed == 242 usb_device_keeper_get_speed(&hc->manager, target.address)); 243 assert(ep->max_packet_size == max_packet_size); 244 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 245 154 246 usb_transfer_batch_t *batch = 155 batch_get(fun, target, USB_TRANSFER_INTERRUPT,max_packet_size,156 speed, data, size, NULL, 0, NULL, callback, arg, &hc->manager);247 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 248 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 157 249 if (!batch) 158 250 return ENOMEM; … … 183 275 hc_t *hc = fun_to_hc(fun); 184 276 assert(hc); 185 usb_speed_t speed = 186 usb_device_keeper_get_speed(&hc->manager, target.address); 277 187 278 usb_log_debug("Interrupt IN %d:%d %zu(%zu).\n", 188 279 target.address, target.endpoint, size, max_packet_size); 189 280 281 size_t res_bw; 282 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 283 target.address, target.endpoint, USB_DIRECTION_IN, &res_bw); 284 if (ep == NULL) { 285 usb_log_error("Endpoint(%d:%d) not registered for INT IN.\n", 286 target.address, target.endpoint); 287 return ENOENT; 288 } 289 const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type, 290 size, ep->max_packet_size); 291 if (res_bw < bw) 292 { 293 usb_log_error("Endpoint(%d:%d) INT IN needs %zu bw " 294 "but only %zu bw is reserved.\n", 295 target.address, target.endpoint, bw, res_bw); 296 return ENOENT; 297 } 298 299 assert(ep->speed == 300 usb_device_keeper_get_speed(&hc->manager, target.address)); 301 assert(ep->max_packet_size == max_packet_size); 302 assert(ep->transfer_type == USB_TRANSFER_INTERRUPT); 303 190 304 usb_transfer_batch_t *batch = 191 batch_get(fun, target, USB_TRANSFER_INTERRUPT,max_packet_size,192 speed, data, size, NULL, 0, callback, NULL, arg, &hc->manager);305 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 306 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 193 307 if (!batch) 194 308 return ENOMEM; … … 219 333 hc_t *hc = fun_to_hc(fun); 220 334 assert(hc); 221 usb_speed_t speed =222 usb_device_keeper_get_speed(&hc->manager, target.address);223 335 224 336 usb_log_debug("Bulk OUT %d:%d %zu(%zu).\n", 225 337 target.address, target.endpoint, size, max_packet_size); 226 338 339 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 340 target.address, target.endpoint, USB_DIRECTION_OUT, NULL); 341 if (ep == NULL) { 342 usb_log_error("Endpoint(%d:%d) not registered for BULK OUT.\n", 343 target.address, target.endpoint); 344 return ENOENT; 345 } 346 assert(ep->speed == 347 usb_device_keeper_get_speed(&hc->manager, target.address)); 348 assert(ep->max_packet_size == max_packet_size); 349 assert(ep->transfer_type == USB_TRANSFER_BULK); 350 227 351 usb_transfer_batch_t *batch = 228 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,229 data, size, NULL, 0, NULL, callback, arg, &hc->manager);352 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 353 ep->speed, data, size, NULL, 0, NULL, callback, arg, ep); 230 354 if (!batch) 231 355 return ENOMEM; … … 256 380 hc_t *hc = fun_to_hc(fun); 257 381 assert(hc); 258 usb_speed_t speed =259 usb_device_keeper_get_speed(&hc->manager, target.address);260 382 usb_log_debug("Bulk IN %d:%d %zu(%zu).\n", 261 383 target.address, target.endpoint, size, max_packet_size); 262 384 385 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 386 target.address, target.endpoint, USB_DIRECTION_IN, NULL); 387 if (ep == NULL) { 388 usb_log_error("Endpoint(%d:%d) not registered for BULK IN.\n", 389 target.address, target.endpoint); 390 return ENOENT; 391 } 392 assert(ep->speed == 393 usb_device_keeper_get_speed(&hc->manager, target.address)); 394 assert(ep->max_packet_size == max_packet_size); 395 assert(ep->transfer_type == USB_TRANSFER_BULK); 396 263 397 usb_transfer_batch_t *batch = 264 batch_get(fun, target, USB_TRANSFER_BULK, max_packet_size, speed,265 data, size, NULL, 0, callback, NULL, arg, &hc->manager);398 batch_get(fun, target, ep->transfer_type, ep->max_packet_size, 399 ep->speed, data, size, NULL, 0, callback, NULL, arg, ep); 266 400 if (!batch) 267 401 return ENOMEM; … … 299 433 usb_log_debug("Control WRITE (%d) %d:%d %zu(%zu).\n", 300 434 speed, target.address, target.endpoint, size, max_packet_size); 435 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 436 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 437 if (ep == NULL) { 438 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 439 target.address, target.endpoint); 440 } 301 441 302 442 if (setup_size != 8) … … 305 445 usb_transfer_batch_t *batch = 306 446 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 307 data, size, setup_data, setup_size, NULL, callback, arg, 308 &hc->manager); 447 data, size, setup_data, setup_size, NULL, callback, arg, ep); 309 448 if (!batch) 310 449 return ENOMEM; … … 344 483 usb_log_debug("Control READ(%d) %d:%d %zu(%zu).\n", 345 484 speed, target.address, target.endpoint, size, max_packet_size); 485 endpoint_t *ep = usb_endpoint_manager_get_ep(&hc->ep_manager, 486 target.address, target.endpoint, USB_DIRECTION_BOTH, NULL); 487 if (ep == NULL) { 488 usb_log_warning("Endpoint(%d:%d) not registered for CONTROL.\n", 489 target.address, target.endpoint); 490 } 346 491 usb_transfer_batch_t *batch = 347 492 batch_get(fun, target, USB_TRANSFER_CONTROL, max_packet_size, speed, 348 data, size, setup_data, setup_size, callback, NULL, arg, 349 &hc->manager); 493 data, size, setup_data, setup_size, callback, NULL, arg, ep); 350 494 if (!batch) 351 495 return ENOMEM; … … 365 509 .release_address = release_address, 366 510 511 .register_endpoint = register_endpoint, 512 .unregister_endpoint = unregister_endpoint, 513 367 514 .interrupt_out = interrupt_out, 368 515 .interrupt_in = interrupt_in,
Note:
See TracChangeset
for help on using the changeset viewer.