diff options
Diffstat (limited to 'drivers/usb/host/xhci-mem.c')
-rw-r--r-- | drivers/usb/host/xhci-mem.c | 140 |
1 files changed, 120 insertions, 20 deletions
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index e6b9a1c6002d..1db4fea8c170 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c | |||
@@ -94,6 +94,9 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev, | |||
94 | val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; | 94 | val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; |
95 | val &= ~TRB_TYPE_BITMASK; | 95 | val &= ~TRB_TYPE_BITMASK; |
96 | val |= TRB_TYPE(TRB_LINK); | 96 | val |= TRB_TYPE(TRB_LINK); |
97 | /* Always set the chain bit with 0.95 hardware */ | ||
98 | if (xhci_link_trb_quirk(xhci)) | ||
99 | val |= TRB_CHAIN; | ||
97 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; | 100 | prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; |
98 | } | 101 | } |
99 | xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", | 102 | xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", |
@@ -141,7 +144,6 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci, | |||
141 | return 0; | 144 | return 0; |
142 | 145 | ||
143 | INIT_LIST_HEAD(&ring->td_list); | 146 | INIT_LIST_HEAD(&ring->td_list); |
144 | INIT_LIST_HEAD(&ring->cancelled_td_list); | ||
145 | if (num_segs == 0) | 147 | if (num_segs == 0) |
146 | return ring; | 148 | return ring; |
147 | 149 | ||
@@ -262,8 +264,8 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) | |||
262 | return; | 264 | return; |
263 | 265 | ||
264 | for (i = 0; i < 31; ++i) | 266 | for (i = 0; i < 31; ++i) |
265 | if (dev->ep_rings[i]) | 267 | if (dev->eps[i].ring) |
266 | xhci_ring_free(xhci, dev->ep_rings[i]); | 268 | xhci_ring_free(xhci, dev->eps[i].ring); |
267 | 269 | ||
268 | if (dev->in_ctx) | 270 | if (dev->in_ctx) |
269 | xhci_free_container_ctx(xhci, dev->in_ctx); | 271 | xhci_free_container_ctx(xhci, dev->in_ctx); |
@@ -278,6 +280,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
278 | struct usb_device *udev, gfp_t flags) | 280 | struct usb_device *udev, gfp_t flags) |
279 | { | 281 | { |
280 | struct xhci_virt_device *dev; | 282 | struct xhci_virt_device *dev; |
283 | int i; | ||
281 | 284 | ||
282 | /* Slot ID 0 is reserved */ | 285 | /* Slot ID 0 is reserved */ |
283 | if (slot_id == 0 || xhci->devs[slot_id]) { | 286 | if (slot_id == 0 || xhci->devs[slot_id]) { |
@@ -306,12 +309,17 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, | |||
306 | xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, | 309 | xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, |
307 | (unsigned long long)dev->in_ctx->dma); | 310 | (unsigned long long)dev->in_ctx->dma); |
308 | 311 | ||
312 | /* Initialize the cancellation list for each endpoint */ | ||
313 | for (i = 0; i < 31; i++) | ||
314 | INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); | ||
315 | |||
309 | /* Allocate endpoint 0 ring */ | 316 | /* Allocate endpoint 0 ring */ |
310 | dev->ep_rings[0] = xhci_ring_alloc(xhci, 1, true, flags); | 317 | dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); |
311 | if (!dev->ep_rings[0]) | 318 | if (!dev->eps[0].ring) |
312 | goto fail; | 319 | goto fail; |
313 | 320 | ||
314 | init_completion(&dev->cmd_completion); | 321 | init_completion(&dev->cmd_completion); |
322 | INIT_LIST_HEAD(&dev->cmd_list); | ||
315 | 323 | ||
316 | /* Point to output device context in dcbaa. */ | 324 | /* Point to output device context in dcbaa. */ |
317 | xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; | 325 | xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; |
@@ -352,9 +360,9 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
352 | /* 3) Only the control endpoint is valid - one endpoint context */ | 360 | /* 3) Only the control endpoint is valid - one endpoint context */ |
353 | slot_ctx->dev_info |= LAST_CTX(1); | 361 | slot_ctx->dev_info |= LAST_CTX(1); |
354 | 362 | ||
363 | slot_ctx->dev_info |= (u32) udev->route; | ||
355 | switch (udev->speed) { | 364 | switch (udev->speed) { |
356 | case USB_SPEED_SUPER: | 365 | case USB_SPEED_SUPER: |
357 | slot_ctx->dev_info |= (u32) udev->route; | ||
358 | slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; | 366 | slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; |
359 | break; | 367 | break; |
360 | case USB_SPEED_HIGH: | 368 | case USB_SPEED_HIGH: |
@@ -382,14 +390,12 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
382 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); | 390 | xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); |
383 | 391 | ||
384 | /* Is this a LS/FS device under a HS hub? */ | 392 | /* Is this a LS/FS device under a HS hub? */ |
385 | /* | ||
386 | * FIXME: I don't think this is right, where does the TT info for the | ||
387 | * roothub or parent hub come from? | ||
388 | */ | ||
389 | if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && | 393 | if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && |
390 | udev->tt) { | 394 | udev->tt) { |
391 | slot_ctx->tt_info = udev->tt->hub->slot_id; | 395 | slot_ctx->tt_info = udev->tt->hub->slot_id; |
392 | slot_ctx->tt_info |= udev->ttport << 8; | 396 | slot_ctx->tt_info |= udev->ttport << 8; |
397 | if (udev->tt->multi) | ||
398 | slot_ctx->dev_info |= DEV_MTT; | ||
393 | } | 399 | } |
394 | xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); | 400 | xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); |
395 | xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); | 401 | xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); |
@@ -398,22 +404,35 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud | |||
398 | /* Step 5 */ | 404 | /* Step 5 */ |
399 | ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); | 405 | ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); |
400 | /* | 406 | /* |
401 | * See section 4.3 bullet 6: | ||
402 | * The default Max Packet size for ep0 is "8 bytes for a USB2 | ||
403 | * LS/FS/HS device or 512 bytes for a USB3 SS device" | ||
404 | * XXX: Not sure about wireless USB devices. | 407 | * XXX: Not sure about wireless USB devices. |
405 | */ | 408 | */ |
406 | if (udev->speed == USB_SPEED_SUPER) | 409 | switch (udev->speed) { |
410 | case USB_SPEED_SUPER: | ||
407 | ep0_ctx->ep_info2 |= MAX_PACKET(512); | 411 | ep0_ctx->ep_info2 |= MAX_PACKET(512); |
408 | else | 412 | break; |
413 | case USB_SPEED_HIGH: | ||
414 | /* USB core guesses at a 64-byte max packet first for FS devices */ | ||
415 | case USB_SPEED_FULL: | ||
416 | ep0_ctx->ep_info2 |= MAX_PACKET(64); | ||
417 | break; | ||
418 | case USB_SPEED_LOW: | ||
409 | ep0_ctx->ep_info2 |= MAX_PACKET(8); | 419 | ep0_ctx->ep_info2 |= MAX_PACKET(8); |
420 | break; | ||
421 | case USB_SPEED_VARIABLE: | ||
422 | xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); | ||
423 | return -EINVAL; | ||
424 | break; | ||
425 | default: | ||
426 | /* New speed? */ | ||
427 | BUG(); | ||
428 | } | ||
410 | /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ | 429 | /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ |
411 | ep0_ctx->ep_info2 |= MAX_BURST(0); | 430 | ep0_ctx->ep_info2 |= MAX_BURST(0); |
412 | ep0_ctx->ep_info2 |= ERROR_COUNT(3); | 431 | ep0_ctx->ep_info2 |= ERROR_COUNT(3); |
413 | 432 | ||
414 | ep0_ctx->deq = | 433 | ep0_ctx->deq = |
415 | dev->ep_rings[0]->first_seg->dma; | 434 | dev->eps[0].ring->first_seg->dma; |
416 | ep0_ctx->deq |= dev->ep_rings[0]->cycle_state; | 435 | ep0_ctx->deq |= dev->eps[0].ring->cycle_state; |
417 | 436 | ||
418 | /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ | 437 | /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ |
419 | 438 | ||
@@ -523,10 +542,11 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, | |||
523 | ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); | 542 | ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); |
524 | 543 | ||
525 | /* Set up the endpoint ring */ | 544 | /* Set up the endpoint ring */ |
526 | virt_dev->new_ep_rings[ep_index] = xhci_ring_alloc(xhci, 1, true, mem_flags); | 545 | virt_dev->eps[ep_index].new_ring = |
527 | if (!virt_dev->new_ep_rings[ep_index]) | 546 | xhci_ring_alloc(xhci, 1, true, mem_flags); |
547 | if (!virt_dev->eps[ep_index].new_ring) | ||
528 | return -ENOMEM; | 548 | return -ENOMEM; |
529 | ep_ring = virt_dev->new_ep_rings[ep_index]; | 549 | ep_ring = virt_dev->eps[ep_index].new_ring; |
530 | ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; | 550 | ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; |
531 | 551 | ||
532 | ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); | 552 | ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); |
@@ -598,6 +618,48 @@ void xhci_endpoint_zero(struct xhci_hcd *xhci, | |||
598 | */ | 618 | */ |
599 | } | 619 | } |
600 | 620 | ||
621 | /* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy. | ||
622 | * Useful when you want to change one particular aspect of the endpoint and then | ||
623 | * issue a configure endpoint command. | ||
624 | */ | ||
625 | void xhci_endpoint_copy(struct xhci_hcd *xhci, | ||
626 | struct xhci_container_ctx *in_ctx, | ||
627 | struct xhci_container_ctx *out_ctx, | ||
628 | unsigned int ep_index) | ||
629 | { | ||
630 | struct xhci_ep_ctx *out_ep_ctx; | ||
631 | struct xhci_ep_ctx *in_ep_ctx; | ||
632 | |||
633 | out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); | ||
634 | in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index); | ||
635 | |||
636 | in_ep_ctx->ep_info = out_ep_ctx->ep_info; | ||
637 | in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2; | ||
638 | in_ep_ctx->deq = out_ep_ctx->deq; | ||
639 | in_ep_ctx->tx_info = out_ep_ctx->tx_info; | ||
640 | } | ||
641 | |||
642 | /* Copy output xhci_slot_ctx to the input xhci_slot_ctx. | ||
643 | * Useful when you want to change one particular aspect of the endpoint and then | ||
644 | * issue a configure endpoint command. Only the context entries field matters, | ||
645 | * but we'll copy the whole thing anyway. | ||
646 | */ | ||
647 | void xhci_slot_copy(struct xhci_hcd *xhci, | ||
648 | struct xhci_container_ctx *in_ctx, | ||
649 | struct xhci_container_ctx *out_ctx) | ||
650 | { | ||
651 | struct xhci_slot_ctx *in_slot_ctx; | ||
652 | struct xhci_slot_ctx *out_slot_ctx; | ||
653 | |||
654 | in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx); | ||
655 | out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx); | ||
656 | |||
657 | in_slot_ctx->dev_info = out_slot_ctx->dev_info; | ||
658 | in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2; | ||
659 | in_slot_ctx->tt_info = out_slot_ctx->tt_info; | ||
660 | in_slot_ctx->dev_state = out_slot_ctx->dev_state; | ||
661 | } | ||
662 | |||
601 | /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ | 663 | /* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ |
602 | static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) | 664 | static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) |
603 | { | 665 | { |
@@ -695,6 +757,44 @@ static void scratchpad_free(struct xhci_hcd *xhci) | |||
695 | xhci->scratchpad = NULL; | 757 | xhci->scratchpad = NULL; |
696 | } | 758 | } |
697 | 759 | ||
760 | struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, | ||
761 | bool allocate_completion, gfp_t mem_flags) | ||
762 | { | ||
763 | struct xhci_command *command; | ||
764 | |||
765 | command = kzalloc(sizeof(*command), mem_flags); | ||
766 | if (!command) | ||
767 | return NULL; | ||
768 | |||
769 | command->in_ctx = | ||
770 | xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, mem_flags); | ||
771 | if (!command->in_ctx) | ||
772 | return NULL; | ||
773 | |||
774 | if (allocate_completion) { | ||
775 | command->completion = | ||
776 | kzalloc(sizeof(struct completion), mem_flags); | ||
777 | if (!command->completion) { | ||
778 | xhci_free_container_ctx(xhci, command->in_ctx); | ||
779 | return NULL; | ||
780 | } | ||
781 | init_completion(command->completion); | ||
782 | } | ||
783 | |||
784 | command->status = 0; | ||
785 | INIT_LIST_HEAD(&command->cmd_list); | ||
786 | return command; | ||
787 | } | ||
788 | |||
789 | void xhci_free_command(struct xhci_hcd *xhci, | ||
790 | struct xhci_command *command) | ||
791 | { | ||
792 | xhci_free_container_ctx(xhci, | ||
793 | command->in_ctx); | ||
794 | kfree(command->completion); | ||
795 | kfree(command); | ||
796 | } | ||
797 | |||
698 | void xhci_mem_cleanup(struct xhci_hcd *xhci) | 798 | void xhci_mem_cleanup(struct xhci_hcd *xhci) |
699 | { | 799 | { |
700 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); | 800 | struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); |