Changeset 51c1d500 in mainline for uspace/drv/bus/usb/xhci/endpoint.c
- Timestamp:
- 2018-01-20T17:16:33Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6271a34
- Parents:
- abb5d08
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/xhci/endpoint.c
rabb5d08 r51c1d500 172 172 int err; 173 173 xhci_endpoint_t *ep = xhci_endpoint_get(ep_base); 174 xhci_device_t *dev = xhci_device_get(ep_base->device); 175 176 xhci_ep_ctx_t ep_ctx; 177 xhci_setup_endpoint_context(ep, &ep_ctx); 178 179 if ((err = hc_add_endpoint(dev, xhci_endpoint_index(ep), &ep_ctx))) 174 175 if ((err = hc_add_endpoint(ep))) 180 176 return err; 181 177 … … 189 185 { 190 186 xhci_device_t *dev = xhci_device_get(ep->device); 187 xhci_endpoint_t *xhci_ep = xhci_endpoint_get(ep); 191 188 192 189 usb_transfer_batch_t *batch = NULL; … … 194 191 if (ep->active_batch) { 195 192 if (dev->slot_id) { 196 const int err = hc_stop_endpoint( dev, xhci_endpoint_dci(xhci_endpoint_get(ep)));193 const int err = hc_stop_endpoint(xhci_ep); 197 194 if (err) { 198 195 usb_log_warning("Failed to stop endpoint %u of device " XHCI_DEV_FMT ": %s", … … 235 232 if (dev->slot_id) { 236 233 237 if ((err = hc_drop_endpoint( dev, xhci_endpoint_index(ep)))) {234 if ((err = hc_drop_endpoint(ep))) { 238 235 usb_log_error("Failed to drop endpoint " XHCI_EP_FMT ": %s", XHCI_EP_ARGS(*ep), str_error(err)); 239 236 } … … 318 315 } 319 316 320 /** See section 4.5.1 of the xHCI spec. 321 */ 322 uint8_t xhci_endpoint_dci(xhci_endpoint_t *ep) 323 { 324 return (2 * ep->base.endpoint) + 325 (ep->base.transfer_type == USB_TRANSFER_CONTROL 326 || ep->base.direction == USB_DIRECTION_IN); 327 } 328 329 /** Return an index to the endpoint array. The indices are assigned as follows: 330 * 0 EP0 BOTH 331 * 1 EP1 OUT 332 * 2 EP1 IN 333 * 334 * For control endpoints >0, the IN endpoint index is used. 335 * 336 * The index returned must be usually offset by a number of contexts preceding 337 * the endpoint contexts themselves. 338 */ 339 uint8_t xhci_endpoint_index(xhci_endpoint_t *ep) 340 { 341 return xhci_endpoint_dci(ep) - 1; 317 xhci_trb_ring_t *xhci_endpoint_get_ring(xhci_endpoint_t *ep, uint32_t stream_id) 318 { 319 if (ep->primary_stream_data_size == 0) 320 return stream_id == 0 ? &ep->ring : NULL; 321 322 xhci_stream_data_t *stream_data = xhci_get_stream_ctx_data(ep, stream_id); 323 if (stream_data == NULL) { 324 usb_log_warning("No transfer ring was found for stream %u.", stream_id); 325 return NULL; 326 } 327 328 return &stream_data->ring; 342 329 } 343 330 … … 435 422 } 436 423 437 uint8_t xhci_endpoint_get_state(xhci_endpoint_t *ep)438 {439 assert(ep);440 441 xhci_device_t *dev = xhci_device_get(ep->base.device);442 if (!dev->slot_id)443 return EP_STATE_DISABLED;444 445 unsigned idx = xhci_endpoint_index(ep);446 xhci_device_ctx_t *ctx = dev->dev_ctx.virt;447 const xhci_hc_t * hc = bus_to_hc(dev->base.bus);448 xhci_ep_ctx_t *ep_ctx = XHCI_GET_EP_CTX(ctx, hc, idx);449 450 return XHCI_EP_STATE(*ep_ctx);451 }452 453 424 /** 454 425 * Clear endpoint halt condition by resetting the endpoint and skipping the 455 426 * offending transfer. 456 427 */ 457 int xhci_endpoint_clear_halt(xhci_endpoint_t *ep, u nsignedstream_id)428 int xhci_endpoint_clear_halt(xhci_endpoint_t *ep, uint32_t stream_id) 458 429 { 459 430 int err; 460 431 461 xhci_device_t * const dev = xhci_device_get(ep->base.device); 462 xhci_bus_t * const bus = bus_to_xhci_bus(dev->base.bus); 463 xhci_hc_t * const hc = bus->hc; 464 465 const unsigned slot_id = dev->slot_id; 466 const unsigned dci = xhci_endpoint_dci(ep); 467 468 if ((err = hc_reset_endpoint(dev, dci))) 432 if ((err = hc_reset_endpoint(ep))) 469 433 return err; 470 434 471 uintptr_t addr; 472 473 xhci_trb_ring_reset_dequeue_state(&ep->ring, &addr); 474 475 if ((err = xhci_cmd_sync_inline(hc, SET_TR_DEQUEUE_POINTER, 476 .slot_id = slot_id, 477 .endpoint_id = dci, 478 .stream_id = stream_id, 479 .dequeue_ptr = addr, 480 ))) 435 if ((err = hc_reset_ring(ep, stream_id))) 481 436 return err; 482 437
Note:
See TracChangeset
for help on using the changeset viewer.