Merge branch 'for-usb-linus' of master.kernel.org:/pub/scm/linux/kernel/git/sarah/xhci into usb-linus

* 'for-usb-linus' of master.kernel.org:/pub/scm/linux/kernel/git/sarah/xhci:
xhci: Remove more doorbell-related reads
xHCI: fix printk_ratelimit() usage
xHCI: replace dev_dbg() with xhci_dbg()
xHCI: fix cycle bit set in giveback_first_trb()
xHCI: remove redundant parameter in giveback_first_trb()
xHCI: fix queue_trb in isoc transfer
xhci: Use GFP_NOIO during device reset.
usb: Realloc xHCI structures after a hub is verified.
xhci: Do not run xhci_cleanup_msix with irq disabled
xHCI: synchronize irq in xhci_suspend()
xhci: Resume bus on any port status change.

+110 -86
+6 -1
drivers/usb/core/hcd-pci.c
··· 405 405 return retval; 406 406 } 407 407 408 - synchronize_irq(pci_dev->irq); 408 + /* If MSI-X is enabled, the driver will have synchronized all vectors 409 + * in pci_suspend(). If MSI or legacy PCI is enabled, that will be 410 + * synchronized here. 411 + */ 412 + if (!hcd->msix_enabled) 413 + synchronize_irq(pci_dev->irq); 409 414 410 415 /* Downstream ports from this root hub should already be quiesced, so 411 416 * there will be no DMA activity. Now we can shut down the upstream
+21
drivers/usb/core/hub.c
··· 676 676 static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) 677 677 { 678 678 struct usb_device *hdev = hub->hdev; 679 + struct usb_hcd *hcd; 680 + int ret; 679 681 int port1; 680 682 int status; 681 683 bool need_debounce_delay = false; ··· 716 714 usb_autopm_get_interface_no_resume( 717 715 to_usb_interface(hub->intfdev)); 718 716 return; /* Continues at init2: below */ 717 + } else if (type == HUB_RESET_RESUME) { 718 + /* The internal host controller state for the hub device 719 + * may be gone after a host power loss on system resume. 720 + * Update the device's info so the HW knows it's a hub. 721 + */ 722 + hcd = bus_to_hcd(hdev->bus); 723 + if (hcd->driver->update_hub_device) { 724 + ret = hcd->driver->update_hub_device(hcd, hdev, 725 + &hub->tt, GFP_NOIO); 726 + if (ret < 0) { 727 + dev_err(hub->intfdev, "Host not " 728 + "accepting hub info " 729 + "update.\n"); 730 + dev_err(hub->intfdev, "LS/FS devices " 731 + "and hubs may not work " 732 + "under this hub\n."); 733 + } 734 + } 735 + hub_power_on(hub, true); 719 736 } else { 720 737 hub_power_on(hub, true); 721 738 }
+51 -40
drivers/usb/host/xhci-ring.c
··· 308 308 /* Ring the host controller doorbell after placing a command on the ring */ 309 309 void xhci_ring_cmd_db(struct xhci_hcd *xhci) 310 310 { 311 - u32 temp; 312 - 313 311 xhci_dbg(xhci, "// Ding dong!\n"); 314 - temp = xhci_readl(xhci, &xhci->dba->doorbell[0]) & DB_MASK; 315 - xhci_writel(xhci, temp | DB_TARGET_HOST, &xhci->dba->doorbell[0]); 312 + xhci_writel(xhci, DB_VALUE_HOST, &xhci->dba->doorbell[0]); 316 313 /* Flush PCI posted writes */ 317 314 xhci_readl(xhci, &xhci->dba->doorbell[0]); 318 315 } ··· 319 322 unsigned int ep_index, 320 323 unsigned int stream_id) 321 324 { 322 - struct xhci_virt_ep *ep; 323 - unsigned int ep_state; 324 - u32 field; 325 325 __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; 326 + struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; 327 + unsigned int ep_state = ep->ep_state; 326 328 327 - ep = &xhci->devs[slot_id]->eps[ep_index]; 328 - ep_state = ep->ep_state; 329 329 /* Don't ring the doorbell for this endpoint if there are pending 330 - * cancellations because the we don't want to interrupt processing. 330 + * cancellations because we don't want to interrupt processing. 331 331 * We don't want to restart any stream rings if there's a set dequeue 332 332 * pointer command pending because the device can choose to start any 333 333 * stream once the endpoint is on the HW schedule. 334 334 * FIXME - check all the stream rings for pending cancellations. 335 335 */ 336 - if (!(ep_state & EP_HALT_PENDING) && !(ep_state & SET_DEQ_PENDING) 337 - && !(ep_state & EP_HALTED)) { 338 - field = xhci_readl(xhci, db_addr) & DB_MASK; 339 - field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id); 340 - xhci_writel(xhci, field, db_addr); 341 - } 336 + if ((ep_state & EP_HALT_PENDING) || (ep_state & SET_DEQ_PENDING) || 337 + (ep_state & EP_HALTED)) 338 + return; 339 + xhci_writel(xhci, DB_VALUE(ep_index, stream_id), db_addr); 340 + /* The CPU has better things to do at this point than wait for a 341 + * write-posting flush. It'll get there soon enough. 342 + */ 342 343 } 343 344 344 345 /* Ring the doorbell for any rings with pending URBs */ ··· 1183 1188 1184 1189 addr = &xhci->op_regs->port_status_base + NUM_PORT_REGS * (port_id - 1); 1185 1190 temp = xhci_readl(xhci, addr); 1186 - if ((temp & PORT_CONNECT) && (hcd->state == HC_STATE_SUSPENDED)) { 1191 + if (hcd->state == HC_STATE_SUSPENDED) { 1187 1192 xhci_dbg(xhci, "resume root hub\n"); 1188 1193 usb_hcd_resume_root_hub(hcd); 1189 1194 } ··· 1705 1710 /* Others already handled above */ 1706 1711 break; 1707 1712 } 1708 - dev_dbg(&td->urb->dev->dev, 1709 - "ep %#x - asked for %d bytes, " 1713 + xhci_dbg(xhci, "ep %#x - asked for %d bytes, " 1710 1714 "%d bytes untransferred\n", 1711 1715 td->urb->ep->desc.bEndpointAddress, 1712 1716 td->urb->transfer_buffer_length, ··· 2383 2389 } 2384 2390 xhci_dbg(xhci, "\n"); 2385 2391 if (!in_interrupt()) 2386 - dev_dbg(&urb->dev->dev, "ep %#x - urb len = %d, sglist used, num_trbs = %d\n", 2392 + xhci_dbg(xhci, "ep %#x - urb len = %d, sglist used, " 2393 + "num_trbs = %d\n", 2387 2394 urb->ep->desc.bEndpointAddress, 2388 2395 urb->transfer_buffer_length, 2389 2396 num_trbs); ··· 2409 2414 2410 2415 static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, 2411 2416 unsigned int ep_index, unsigned int stream_id, int start_cycle, 2412 - struct xhci_generic_trb *start_trb, struct xhci_td *td) 2417 + struct xhci_generic_trb *start_trb) 2413 2418 { 2414 2419 /* 2415 2420 * Pass all the TRBs to the hardware at once and make sure this write 2416 2421 * isn't reordered. 2417 2422 */ 2418 2423 wmb(); 2419 - start_trb->field[3] |= start_cycle; 2424 + if (start_cycle) 2425 + start_trb->field[3] |= start_cycle; 2426 + else 2427 + start_trb->field[3] &= ~0x1; 2420 2428 xhci_ring_ep_doorbell(xhci, slot_id, ep_index, stream_id); 2421 2429 } 2422 2430 ··· 2447 2449 * to set the polling interval (once the API is added). 2448 2450 */ 2449 2451 if (xhci_interval != ep_interval) { 2450 - if (!printk_ratelimit()) 2452 + if (printk_ratelimit()) 2451 2453 dev_dbg(&urb->dev->dev, "Driver uses different interval" 2452 2454 " (%d microframe%s) than xHCI " 2453 2455 "(%d microframe%s)\n", ··· 2549 2551 u32 remainder = 0; 2550 2552 2551 2553 /* Don't change the cycle bit of the first TRB until later */ 2552 - if (first_trb) 2554 + if (first_trb) { 2553 2555 first_trb = false; 2554 - else 2556 + if (start_cycle == 0) 2557 + field |= 0x1; 2558 + } else 2555 2559 field |= ep_ring->cycle_state; 2556 2560 2557 2561 /* Chain all the TRBs together; clear the chain bit in the last ··· 2625 2625 2626 2626 check_trb_math(urb, num_trbs, running_total); 2627 2627 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 2628 - start_cycle, start_trb, td); 2628 + start_cycle, start_trb); 2629 2629 return 0; 2630 2630 } 2631 2631 ··· 2671 2671 /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */ 2672 2672 2673 2673 if (!in_interrupt()) 2674 - dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d), addr = %#llx, num_trbs = %d\n", 2674 + xhci_dbg(xhci, "ep %#x - urb len = %#x (%d), " 2675 + "addr = %#llx, num_trbs = %d\n", 2675 2676 urb->ep->desc.bEndpointAddress, 2676 2677 urb->transfer_buffer_length, 2677 2678 urb->transfer_buffer_length, ··· 2712 2711 field = 0; 2713 2712 2714 2713 /* Don't change the cycle bit of the first TRB until later */ 2715 - if (first_trb) 2714 + if (first_trb) { 2716 2715 first_trb = false; 2717 - else 2716 + if (start_cycle == 0) 2717 + field |= 0x1; 2718 + } else 2718 2719 field |= ep_ring->cycle_state; 2719 2720 2720 2721 /* Chain all the TRBs together; clear the chain bit in the last ··· 2760 2757 2761 2758 check_trb_math(urb, num_trbs, running_total); 2762 2759 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 2763 - start_cycle, start_trb, td); 2760 + start_cycle, start_trb); 2764 2761 return 0; 2765 2762 } 2766 2763 ··· 2821 2818 /* Queue setup TRB - see section 6.4.1.2.1 */ 2822 2819 /* FIXME better way to translate setup_packet into two u32 fields? */ 2823 2820 setup = (struct usb_ctrlrequest *) urb->setup_packet; 2821 + field = 0; 2822 + field |= TRB_IDT | TRB_TYPE(TRB_SETUP); 2823 + if (start_cycle == 0) 2824 + field |= 0x1; 2824 2825 queue_trb(xhci, ep_ring, false, true, 2825 2826 /* FIXME endianness is probably going to bite my ass here. */ 2826 2827 setup->bRequestType | setup->bRequest << 8 | setup->wValue << 16, 2827 2828 setup->wIndex | setup->wLength << 16, 2828 2829 TRB_LEN(8) | TRB_INTR_TARGET(0), 2829 2830 /* Immediate data in pointer */ 2830 - TRB_IDT | TRB_TYPE(TRB_SETUP)); 2831 + field); 2831 2832 2832 2833 /* If there's data, queue data TRBs */ 2833 2834 field = 0; ··· 2866 2859 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); 2867 2860 2868 2861 giveback_first_trb(xhci, slot_id, ep_index, 0, 2869 - start_cycle, start_trb, td); 2862 + start_cycle, start_trb); 2870 2863 return 0; 2871 2864 } 2872 2865 ··· 2907 2900 int running_total, trb_buff_len, td_len, td_remain_len, ret; 2908 2901 u64 start_addr, addr; 2909 2902 int i, j; 2903 + bool more_trbs_coming; 2910 2904 2911 2905 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 2912 2906 ··· 2918 2910 } 2919 2911 2920 2912 if (!in_interrupt()) 2921 - dev_dbg(&urb->dev->dev, "ep %#x - urb len = %#x (%d)," 2913 + xhci_dbg(xhci, "ep %#x - urb len = %#x (%d)," 2922 2914 " addr = %#llx, num_tds = %d\n", 2923 2915 urb->ep->desc.bEndpointAddress, 2924 2916 urb->transfer_buffer_length, ··· 2958 2950 field |= TRB_TYPE(TRB_ISOC); 2959 2951 /* Assume URB_ISO_ASAP is set */ 2960 2952 field |= TRB_SIA; 2961 - if (i > 0) 2953 + if (i == 0) { 2954 + if (start_cycle == 0) 2955 + field |= 0x1; 2956 + } else 2962 2957 field |= ep_ring->cycle_state; 2963 2958 first_trb = false; 2964 2959 } else { ··· 2976 2965 */ 2977 2966 if (j < trbs_per_td - 1) { 2978 2967 field |= TRB_CHAIN; 2968 + more_trbs_coming = true; 2979 2969 } else { 2980 2970 td->last_trb = ep_ring->enqueue; 2981 2971 field |= TRB_IOC; 2972 + more_trbs_coming = false; 2982 2973 } 2983 2974 2984 2975 /* Calculate TRB length */ ··· 2993 2980 length_field = TRB_LEN(trb_buff_len) | 2994 2981 remainder | 2995 2982 TRB_INTR_TARGET(0); 2996 - queue_trb(xhci, ep_ring, false, false, 2983 + queue_trb(xhci, ep_ring, false, more_trbs_coming, 2997 2984 lower_32_bits(addr), 2998 2985 upper_32_bits(addr), 2999 2986 length_field, ··· 3016 3003 } 3017 3004 } 3018 3005 3019 - wmb(); 3020 - start_trb->field[3] |= start_cycle; 3021 - 3022 - xhci_ring_ep_doorbell(xhci, slot_id, ep_index, urb->stream_id); 3006 + giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, 3007 + start_cycle, start_trb); 3023 3008 return 0; 3024 3009 } 3025 3010 ··· 3075 3064 * to set the polling interval (once the API is added). 3076 3065 */ 3077 3066 if (xhci_interval != ep_interval) { 3078 - if (!printk_ratelimit()) 3067 + if (printk_ratelimit()) 3079 3068 dev_dbg(&urb->dev->dev, "Driver uses different interval" 3080 3069 " (%d microframe%s) than xHCI " 3081 3070 "(%d microframe%s)\n",
+25 -35
drivers/usb/host/xhci.c
··· 226 226 static int xhci_setup_msix(struct xhci_hcd *xhci) 227 227 { 228 228 int i, ret = 0; 229 - struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 229 + struct usb_hcd *hcd = xhci_to_hcd(xhci); 230 + struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 230 231 231 232 /* 232 233 * calculate number of msi-x vectors supported. ··· 266 265 goto disable_msix; 267 266 } 268 267 268 + hcd->msix_enabled = 1; 269 269 return ret; 270 270 271 271 disable_msix: ··· 282 280 /* Free any IRQs and disable MSI-X */ 283 281 static void xhci_cleanup_msix(struct xhci_hcd *xhci) 284 282 { 285 - struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 283 + struct usb_hcd *hcd = xhci_to_hcd(xhci); 284 + struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 286 285 287 286 xhci_free_irq(xhci); 288 287 ··· 295 292 pci_disable_msi(pdev); 296 293 } 297 294 295 + hcd->msix_enabled = 0; 298 296 return; 299 297 } 300 298 ··· 512 508 spin_lock_irq(&xhci->lock); 513 509 xhci_halt(xhci); 514 510 xhci_reset(xhci); 515 - xhci_cleanup_msix(xhci); 516 511 spin_unlock_irq(&xhci->lock); 512 + 513 + xhci_cleanup_msix(xhci); 517 514 518 515 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 519 516 /* Tell the event ring poll function not to reschedule */ ··· 549 544 550 545 spin_lock_irq(&xhci->lock); 551 546 xhci_halt(xhci); 552 - xhci_cleanup_msix(xhci); 553 547 spin_unlock_irq(&xhci->lock); 548 + 549 + xhci_cleanup_msix(xhci); 554 550 555 551 xhci_dbg(xhci, "xhci_shutdown completed - status = %x\n", 556 552 xhci_readl(xhci, &xhci->op_regs->status)); ··· 653 647 int rc = 0; 654 648 struct usb_hcd *hcd = xhci_to_hcd(xhci); 655 649 u32 command; 650 + int i; 656 651 657 652 spin_lock_irq(&xhci->lock); 658 653 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); ··· 684 677 spin_unlock_irq(&xhci->lock); 685 678 return -ETIMEDOUT; 686 679 } 687 - /* step 5: remove core well power */ 688 - xhci_cleanup_msix(xhci); 689 680 spin_unlock_irq(&xhci->lock); 681 + 682 + /* step 5: remove core well power */ 683 + /* synchronize irq when using MSI-X */ 684 + if (xhci->msix_entries) { 685 + for (i = 0; i < xhci->msix_count; i++) 686 + synchronize_irq(xhci->msix_entries[i].vector); 687 + } 690 688 691 689 return rc; 692 690 } ··· 706 694 { 707 695 u32 command, temp = 0; 708 696 struct usb_hcd *hcd = xhci_to_hcd(xhci); 709 - struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 710 697 int old_state, retval; 711 698 712 699 old_state = hcd->state; ··· 740 729 xhci_dbg(xhci, "Stop HCD\n"); 741 730 xhci_halt(xhci); 742 731 xhci_reset(xhci); 743 - if (hibernated) 744 - xhci_cleanup_msix(xhci); 745 732 spin_unlock_irq(&xhci->lock); 733 + xhci_cleanup_msix(xhci); 746 734 747 735 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 748 736 /* Tell the event ring poll function not to reschedule */ ··· 775 765 return retval; 776 766 } 777 767 778 - spin_unlock_irq(&xhci->lock); 779 - /* Re-setup MSI-X */ 780 - if (hcd->irq) 781 - free_irq(hcd->irq, hcd); 782 - hcd->irq = -1; 783 - 784 - retval = xhci_setup_msix(xhci); 785 - if (retval) 786 - /* fall back to msi*/ 787 - retval = xhci_setup_msi(xhci); 788 - 789 - if (retval) { 790 - /* fall back to legacy interrupt*/ 791 - retval = request_irq(pdev->irq, &usb_hcd_irq, IRQF_SHARED, 792 - hcd->irq_descr, hcd); 793 - if (retval) { 794 - xhci_err(xhci, "request interrupt %d failed\n", 795 - pdev->irq); 796 - return retval; 797 - } 798 - hcd->irq = pdev->irq; 799 - } 800 - 801 - spin_lock_irq(&xhci->lock); 802 768 /* step 4: set Run/Stop bit */ 803 769 command = xhci_readl(xhci, &xhci->op_regs->command); 804 770 command |= CMD_RUN; ··· 2431 2445 xhci_err(xhci, "Error while assigning device slot ID\n"); 2432 2446 return 0; 2433 2447 } 2434 - /* xhci_alloc_virt_device() does not touch rings; no need to lock */ 2435 - if (!xhci_alloc_virt_device(xhci, xhci->slot_id, udev, GFP_KERNEL)) { 2448 + /* xhci_alloc_virt_device() does not touch rings; no need to lock. 2449 + * Use GFP_NOIO, since this function can be called from 2450 + * xhci_discover_or_reset_device(), which may be called as part of 2451 + * mass storage driver error handling. 2452 + */ 2453 + if (!xhci_alloc_virt_device(xhci, xhci->slot_id, udev, GFP_NOIO)) { 2436 2454 /* Disable slot, if we can do it without mem alloc */ 2437 2455 xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); 2438 2456 spin_lock_irqsave(&xhci->lock, flags);
+6 -10
drivers/usb/host/xhci.h
··· 436 436 /** 437 437 * struct doorbell_array 438 438 * 439 + * Bits 0 - 7: Endpoint target 440 + * Bits 8 - 15: RsvdZ 441 + * Bits 16 - 31: Stream ID 442 + * 439 443 * Section 5.6 440 444 */ 441 445 struct xhci_doorbell_array { 442 446 u32 doorbell[256]; 443 447 }; 444 448 445 - #define DB_TARGET_MASK 0xFFFFFF00 446 - #define DB_STREAM_ID_MASK 0x0000FFFF 447 - #define DB_TARGET_HOST 0x0 448 - #define DB_STREAM_ID_HOST 0x0 449 - #define DB_MASK (0xff << 8) 450 - 451 - /* Endpoint Target - bits 0:7 */ 452 - #define EPI_TO_DB(p) (((p) + 1) & 0xff) 453 - #define STREAM_ID_TO_DB(p) (((p) & 0xffff) << 16) 454 - 449 + #define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16)) 450 + #define DB_VALUE_HOST 0x00000000 455 451 456 452 /** 457 453 * struct xhci_protocol_caps
+1
include/linux/usb/hcd.h
··· 112 112 /* Flags that get set only during HCD registration or removal. */ 113 113 unsigned rh_registered:1;/* is root hub registered? */ 114 114 unsigned rh_pollable:1; /* may we poll the root hub? */ 115 + unsigned msix_enabled:1; /* driver has MSI-X enabled? */ 115 116 116 117 /* The next flag is a stopgap, to be removed when all the HCDs 117 118 * support the new root-hub polling mechanism. */