diff options
| -rw-r--r-- | drivers/usb/host/xhci-hcd.c | 24 | ||||
| -rw-r--r-- | drivers/usb/host/xhci-ring.c | 133 | ||||
| -rw-r--r-- | drivers/usb/host/xhci.h | 12 |
3 files changed, 120 insertions, 49 deletions
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c index 057a07e876be..816c39caca1c 100644 --- a/drivers/usb/host/xhci-hcd.c +++ b/drivers/usb/host/xhci-hcd.c | |||
| @@ -1089,6 +1089,8 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
| 1089 | unsigned int ep_index; | 1089 | unsigned int ep_index; |
| 1090 | unsigned long flags; | 1090 | unsigned long flags; |
| 1091 | int ret; | 1091 | int ret; |
| 1092 | struct xhci_dequeue_state deq_state; | ||
| 1093 | struct xhci_ring *ep_ring; | ||
| 1092 | 1094 | ||
| 1093 | xhci = hcd_to_xhci(hcd); | 1095 | xhci = hcd_to_xhci(hcd); |
| 1094 | udev = (struct usb_device *) ep->hcpriv; | 1096 | udev = (struct usb_device *) ep->hcpriv; |
| @@ -1098,11 +1100,33 @@ void xhci_endpoint_reset(struct usb_hcd *hcd, | |||
| 1098 | if (!ep->hcpriv) | 1100 | if (!ep->hcpriv) |
| 1099 | return; | 1101 | return; |
| 1100 | ep_index = xhci_get_endpoint_index(&ep->desc); | 1102 | ep_index = xhci_get_endpoint_index(&ep->desc); |
| 1103 | ep_ring = xhci->devs[udev->slot_id]->ep_rings[ep_index]; | ||
| 1104 | if (!ep_ring->stopped_td) { | ||
| 1105 | xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", | ||
| 1106 | ep->desc.bEndpointAddress); | ||
| 1107 | return; | ||
| 1108 | } | ||
| 1101 | 1109 | ||
| 1102 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); | 1110 | xhci_dbg(xhci, "Queueing reset endpoint command\n"); |
| 1103 | spin_lock_irqsave(&xhci->lock, flags); | 1111 | spin_lock_irqsave(&xhci->lock, flags); |
| 1104 | ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); | 1112 | ret = xhci_queue_reset_ep(xhci, udev->slot_id, ep_index); |
| 1113 | /* | ||
| 1114 | * Can't change the ring dequeue pointer until it's transitioned to the | ||
| 1115 | * stopped state, which is only upon a successful reset endpoint | ||
| 1116 | * command. Better hope that last command worked! | ||
| 1117 | */ | ||
| 1105 | if (!ret) { | 1118 | if (!ret) { |
| 1119 | xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); | ||
| 1120 | /* We need to move the HW's dequeue pointer past this TD, | ||
| 1121 | * or it will attempt to resend it on the next doorbell ring. | ||
| 1122 | */ | ||
| 1123 | xhci_find_new_dequeue_state(xhci, udev->slot_id, | ||
| 1124 | ep_index, ep_ring->stopped_td, &deq_state); | ||
| 1125 | xhci_dbg(xhci, "Queueing new dequeue state\n"); | ||
| 1126 | xhci_queue_new_dequeue_state(xhci, ep_ring, | ||
| 1127 | udev->slot_id, | ||
| 1128 | ep_index, &deq_state); | ||
| 1129 | kfree(ep_ring->stopped_td); | ||
| 1106 | xhci_ring_cmd_db(xhci); | 1130 | xhci_ring_cmd_db(xhci); |
| 1107 | } | 1131 | } |
| 1108 | spin_unlock_irqrestore(&xhci->lock, flags); | 1132 | spin_unlock_irqrestore(&xhci->lock, flags); |
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index ea31753c3137..aa88a067148b 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c | |||
| @@ -335,12 +335,6 @@ static struct xhci_segment *find_trb_seg( | |||
| 335 | return cur_seg; | 335 | return cur_seg; |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | struct dequeue_state { | ||
| 339 | struct xhci_segment *new_deq_seg; | ||
| 340 | union xhci_trb *new_deq_ptr; | ||
| 341 | int new_cycle_state; | ||
| 342 | }; | ||
| 343 | |||
| 344 | /* | 338 | /* |
| 345 | * Move the xHC's endpoint ring dequeue pointer past cur_td. | 339 | * Move the xHC's endpoint ring dequeue pointer past cur_td. |
| 346 | * Record the new state of the xHC's endpoint ring dequeue segment, | 340 | * Record the new state of the xHC's endpoint ring dequeue segment, |
| @@ -355,26 +349,30 @@ struct dequeue_state { | |||
| 355 | * - Finally we move the dequeue state one TRB further, toggling the cycle bit | 349 | * - Finally we move the dequeue state one TRB further, toggling the cycle bit |
| 356 | * if we've moved it past a link TRB with the toggle cycle bit set. | 350 | * if we've moved it past a link TRB with the toggle cycle bit set. |
| 357 | */ | 351 | */ |
| 358 | static void find_new_dequeue_state(struct xhci_hcd *xhci, | 352 | void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, |
| 359 | unsigned int slot_id, unsigned int ep_index, | 353 | unsigned int slot_id, unsigned int ep_index, |
| 360 | struct xhci_td *cur_td, struct dequeue_state *state) | 354 | struct xhci_td *cur_td, struct xhci_dequeue_state *state) |
| 361 | { | 355 | { |
| 362 | struct xhci_virt_device *dev = xhci->devs[slot_id]; | 356 | struct xhci_virt_device *dev = xhci->devs[slot_id]; |
| 363 | struct xhci_ring *ep_ring = dev->ep_rings[ep_index]; | 357 | struct xhci_ring *ep_ring = dev->ep_rings[ep_index]; |
| 364 | struct xhci_generic_trb *trb; | 358 | struct xhci_generic_trb *trb; |
| 365 | struct xhci_ep_ctx *ep_ctx; | 359 | struct xhci_ep_ctx *ep_ctx; |
| 360 | dma_addr_t addr; | ||
| 366 | 361 | ||
| 367 | state->new_cycle_state = 0; | 362 | state->new_cycle_state = 0; |
| 363 | xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); | ||
| 368 | state->new_deq_seg = find_trb_seg(cur_td->start_seg, | 364 | state->new_deq_seg = find_trb_seg(cur_td->start_seg, |
| 369 | ep_ring->stopped_trb, | 365 | ep_ring->stopped_trb, |
| 370 | &state->new_cycle_state); | 366 | &state->new_cycle_state); |
| 371 | if (!state->new_deq_seg) | 367 | if (!state->new_deq_seg) |
| 372 | BUG(); | 368 | BUG(); |
| 373 | /* Dig out the cycle state saved by the xHC during the stop ep cmd */ | 369 | /* Dig out the cycle state saved by the xHC during the stop ep cmd */ |
| 370 | xhci_dbg(xhci, "Finding endpoint context\n"); | ||
| 374 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); | 371 | ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); |
| 375 | state->new_cycle_state = 0x1 & ep_ctx->deq; | 372 | state->new_cycle_state = 0x1 & ep_ctx->deq; |
| 376 | 373 | ||
| 377 | state->new_deq_ptr = cur_td->last_trb; | 374 | state->new_deq_ptr = cur_td->last_trb; |
| 375 | xhci_dbg(xhci, "Finding segment containing last TRB in TD.\n"); | ||
| 378 | state->new_deq_seg = find_trb_seg(state->new_deq_seg, | 376 | state->new_deq_seg = find_trb_seg(state->new_deq_seg, |
| 379 | state->new_deq_ptr, | 377 | state->new_deq_ptr, |
| 380 | &state->new_cycle_state); | 378 | &state->new_cycle_state); |
| @@ -388,6 +386,12 @@ static void find_new_dequeue_state(struct xhci_hcd *xhci, | |||
| 388 | next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); | 386 | next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); |
| 389 | 387 | ||
| 390 | /* Don't update the ring cycle state for the producer (us). */ | 388 | /* Don't update the ring cycle state for the producer (us). */ |
| 389 | xhci_dbg(xhci, "New dequeue segment = %p (virtual)\n", | ||
| 390 | state->new_deq_seg); | ||
| 391 | addr = xhci_trb_virt_to_dma(state->new_deq_seg, state->new_deq_ptr); | ||
| 392 | xhci_dbg(xhci, "New dequeue pointer = 0x%llx (DMA)\n", | ||
| 393 | (unsigned long long) addr); | ||
| 394 | xhci_dbg(xhci, "Setting dequeue pointer in internal ring state.\n"); | ||
| 391 | ep_ring->dequeue = state->new_deq_ptr; | 395 | ep_ring->dequeue = state->new_deq_ptr; |
| 392 | ep_ring->deq_seg = state->new_deq_seg; | 396 | ep_ring->deq_seg = state->new_deq_seg; |
| 393 | } | 397 | } |
| @@ -437,6 +441,30 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, | |||
| 437 | unsigned int ep_index, struct xhci_segment *deq_seg, | 441 | unsigned int ep_index, struct xhci_segment *deq_seg, |
| 438 | union xhci_trb *deq_ptr, u32 cycle_state); | 442 | union xhci_trb *deq_ptr, u32 cycle_state); |
| 439 | 443 | ||
| 444 | void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, | ||
| 445 | struct xhci_ring *ep_ring, unsigned int slot_id, | ||
| 446 | unsigned int ep_index, struct xhci_dequeue_state *deq_state) | ||
| 447 | { | ||
| 448 | xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " | ||
| 449 | "new deq ptr = %p (0x%llx dma), new cycle = %u\n", | ||
| 450 | deq_state->new_deq_seg, | ||
| 451 | (unsigned long long)deq_state->new_deq_seg->dma, | ||
| 452 | deq_state->new_deq_ptr, | ||
| 453 | (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr), | ||
| 454 | deq_state->new_cycle_state); | ||
| 455 | queue_set_tr_deq(xhci, slot_id, ep_index, | ||
| 456 | deq_state->new_deq_seg, | ||
| 457 | deq_state->new_deq_ptr, | ||
| 458 | (u32) deq_state->new_cycle_state); | ||
| 459 | /* Stop the TD queueing code from ringing the doorbell until | ||
| 460 | * this command completes. The HC won't set the dequeue pointer | ||
| 461 | * if the ring is running, and ringing the doorbell starts the | ||
| 462 | * ring running. | ||
| 463 | */ | ||
| 464 | ep_ring->state |= SET_DEQ_PENDING; | ||
| 465 | xhci_ring_cmd_db(xhci); | ||
| 466 | } | ||
| 467 | |||
| 440 | /* | 468 | /* |
| 441 | * When we get a command completion for a Stop Endpoint Command, we need to | 469 | * When we get a command completion for a Stop Endpoint Command, we need to |
| 442 | * unlink any cancelled TDs from the ring. There are two ways to do that: | 470 | * unlink any cancelled TDs from the ring. There are two ways to do that: |
| @@ -457,7 +485,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
| 457 | struct xhci_td *cur_td = 0; | 485 | struct xhci_td *cur_td = 0; |
| 458 | struct xhci_td *last_unlinked_td; | 486 | struct xhci_td *last_unlinked_td; |
| 459 | 487 | ||
| 460 | struct dequeue_state deq_state; | 488 | struct xhci_dequeue_state deq_state; |
| 461 | #ifdef CONFIG_USB_HCD_STAT | 489 | #ifdef CONFIG_USB_HCD_STAT |
| 462 | ktime_t stop_time = ktime_get(); | 490 | ktime_t stop_time = ktime_get(); |
| 463 | #endif | 491 | #endif |
| @@ -485,7 +513,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
| 485 | * move the xHC endpoint ring dequeue pointer past this TD. | 513 | * move the xHC endpoint ring dequeue pointer past this TD. |
| 486 | */ | 514 | */ |
| 487 | if (cur_td == ep_ring->stopped_td) | 515 | if (cur_td == ep_ring->stopped_td) |
| 488 | find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, | 516 | xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, |
| 489 | &deq_state); | 517 | &deq_state); |
| 490 | else | 518 | else |
| 491 | td_to_noop(xhci, ep_ring, cur_td); | 519 | td_to_noop(xhci, ep_ring, cur_td); |
| @@ -501,24 +529,8 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci, | |||
