Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'usb-6.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB / Thunderbolt fixes from Greg KH:
"Here are some USB fixes for 6.4-rc3, as well as a driver core fix that
resolves a memory leak that shows up in USB devices easier than other
subsystems.

Included in here are:

- driver core memory leak as reported and tested by syzbot and
developers

- dwc3 driver fixes for reported problems

- xhci driver fixes for reported problems

- USB gadget driver reverts to resolve regressions

- usbtmc driver fix for syzbot reported problem

- thunderbolt driver fixes for reported issues

- other small USB fixes

All of these, except for the driver core fix, have been in linux-next
with no reported problems. The driver core fix was tested and verified
to solve the issue by syzbot and the original reporter"

* tag 'usb-6.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
driver core: class: properly reference count class_dev_iter()
xhci: Fix incorrect tracking of free space on transfer rings
xhci-pci: Only run d3cold avoidance quirk for s2idle
usb-storage: fix deadlock when a scsi command timeouts more than once
usb: dwc3: fix a test for error in dwc3_core_init()
usb: typec: tps6598x: Fix fault at module removal
usb: gadget: u_ether: Fix host MAC address case
usb: typec: altmodes/displayport: fix pin_assignment_show
Revert "usb: gadget: udc: core: Invoke usb_gadget_connect only when started"
Revert "usb: gadget: udc: core: Prevent redundant calls to pullup"
usb: gadget: drop superfluous ':' in doc string
usb: dwc3: debugfs: Resume dwc3 before accessing registers
USB: UHCI: adjust zhaoxin UHCI controllers OverCurrent bit value
usb: dwc3: fix gadget mode suspend interrupt handler issue
usb: dwc3: gadget: Improve dwc3_gadget_suspend() and dwc3_gadget_resume()
USB: usbtmc: Fix direction for 0-length ioctl control messages
thunderbolt: Clear registers properly when auto clear isn't in use

+327 -181
+2
drivers/base/class.c
··· 320 320 start_knode = &start->p->knode_class; 321 321 klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode); 322 322 iter->type = type; 323 + iter->sp = sp; 323 324 } 324 325 EXPORT_SYMBOL_GPL(class_dev_iter_init); 325 326 ··· 362 361 void class_dev_iter_exit(struct class_dev_iter *iter) 363 362 { 364 363 klist_iter_exit(&iter->ki); 364 + subsys_put(iter->sp); 365 365 } 366 366 EXPORT_SYMBOL_GPL(class_dev_iter_exit); 367 367
+24 -5
drivers/thunderbolt/nhi.c
··· 54 54 return bit; 55 55 } 56 56 57 + static void nhi_mask_interrupt(struct tb_nhi *nhi, int mask, int ring) 58 + { 59 + if (nhi->quirks & QUIRK_AUTO_CLEAR_INT) 60 + return; 61 + iowrite32(mask, nhi->iobase + REG_RING_INTERRUPT_MASK_CLEAR_BASE + ring); 62 + } 63 + 64 + static void nhi_clear_interrupt(struct tb_nhi *nhi, int ring) 65 + { 66 + if (nhi->quirks & QUIRK_AUTO_CLEAR_INT) 67 + ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + ring); 68 + else 69 + iowrite32(~0, nhi->iobase + REG_RING_INT_CLEAR + ring); 70 + } 71 + 57 72 /* 58 73 * ring_interrupt_active() - activate/deactivate interrupts for a single ring 59 74 * ··· 76 61 */ 77 62 static void ring_interrupt_active(struct tb_ring *ring, bool active) 78 63 { 79 - int reg = REG_RING_INTERRUPT_BASE + 80 - ring_interrupt_index(ring) / 32 * 4; 64 + int index = ring_interrupt_index(ring) / 32 * 4; 65 + int reg = REG_RING_INTERRUPT_BASE + index; 81 66 int interrupt_bit = ring_interrupt_index(ring) & 31; 82 67 int mask = 1 << interrupt_bit; 83 68 u32 old, new; ··· 138 123 "interrupt for %s %d is already %s\n", 139 124 RING_TYPE(ring), ring->hop, 140 125 active ? "enabled" : "disabled"); 141 - iowrite32(new, ring->nhi->iobase + reg); 126 + 127 + if (active) 128 + iowrite32(new, ring->nhi->iobase + reg); 129 + else 130 + nhi_mask_interrupt(ring->nhi, mask, index); 142 131 } 143 132 144 133 /* ··· 155 136 int i = 0; 156 137 /* disable interrupts */ 157 138 for (i = 0; i < RING_INTERRUPT_REG_COUNT(nhi); i++) 158 - iowrite32(0, nhi->iobase + REG_RING_INTERRUPT_BASE + 4 * i); 139 + nhi_mask_interrupt(nhi, ~0, 4 * i); 159 140 160 141 /* clear interrupt status bits */ 161 142 for (i = 0; i < RING_NOTIFY_REG_COUNT(nhi); i++) 162 - ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + 4 * i); 143 + nhi_clear_interrupt(nhi, 4 * i); 163 144 } 164 145 165 146 /* ring helper methods */
+2
drivers/thunderbolt/nhi_regs.h
··· 93 93 #define REG_RING_INTERRUPT_BASE 0x38200 94 94 #define RING_INTERRUPT_REG_COUNT(nhi) ((31 + 2 * nhi->hop_count) / 32) 95 95 96 + #define REG_RING_INTERRUPT_MASK_CLEAR_BASE 0x38208 97 + 96 98 #define REG_INT_THROTTLING_RATE 0x38c00 97 99 98 100 /* Interrupt Vector Allocation */
+2
drivers/usb/class/usbtmc.c
··· 1928 1928 1929 1929 if (request.req.wLength > USBTMC_BUFSIZE) 1930 1930 return -EMSGSIZE; 1931 + if (request.req.wLength == 0) /* Length-0 requests are never IN */ 1932 + request.req.bRequestType &= ~USB_DIR_IN; 1931 1933 1932 1934 is_in = request.req.bRequestType & USB_DIR_IN; 1933 1935
+1 -1
drivers/usb/dwc3/core.c
··· 1137 1137 1138 1138 dwc3_set_incr_burst_type(dwc); 1139 1139 1140 - dwc3_phy_power_on(dwc); 1140 + ret = dwc3_phy_power_on(dwc); 1141 1141 if (ret) 1142 1142 goto err_exit_phy; 1143 1143
+2
drivers/usb/dwc3/core.h
··· 1116 1116 * @dis_metastability_quirk: set to disable metastability quirk. 1117 1117 * @dis_split_quirk: set to disable split boundary. 1118 1118 * @wakeup_configured: set if the device is configured for remote wakeup. 1119 + * @suspended: set to track suspend event due to U3/L2. 1119 1120 * @imod_interval: set the interrupt moderation interval in 250ns 1120 1121 * increments or 0 to disable. 1121 1122 * @max_cfg_eps: current max number of IN eps used across all USB configs. ··· 1333 1332 unsigned dis_split_quirk:1; 1334 1333 unsigned async_callbacks:1; 1335 1334 unsigned wakeup_configured:1; 1335 + unsigned suspended:1; 1336 1336 1337 1337 u16 imod_interval; 1338 1338
+109
drivers/usb/dwc3/debugfs.c
··· 332 332 unsigned int current_mode; 333 333 unsigned long flags; 334 334 u32 reg; 335 + int ret; 336 + 337 + ret = pm_runtime_resume_and_get(dwc->dev); 338 + if (ret < 0) 339 + return ret; 335 340 336 341 spin_lock_irqsave(&dwc->lock, flags); 337 342 reg = dwc3_readl(dwc->regs, DWC3_GSTS); ··· 354 349 break; 355 350 } 356 351 spin_unlock_irqrestore(&dwc->lock, flags); 352 + 353 + pm_runtime_put_sync(dwc->dev); 357 354 358 355 return 0; 359 356 } ··· 402 395 struct dwc3 *dwc = s->private; 403 396 unsigned long flags; 404 397 u32 reg; 398 + int ret; 399 + 400 + ret = pm_runtime_resume_and_get(dwc->dev); 401 + if (ret < 0) 402 + return ret; 405 403 406 404 spin_lock_irqsave(&dwc->lock, flags); 407 405 reg = dwc3_readl(dwc->regs, DWC3_GCTL); ··· 425 413 default: 426 414 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg)); 427 415 } 416 + 417 + pm_runtime_put_sync(dwc->dev); 428 418 429 419 return 0; 430 420 } ··· 477 463 struct dwc3 *dwc = s->private; 478 464 unsigned long flags; 479 465 u32 reg; 466 + int ret; 467 + 468 + ret = pm_runtime_resume_and_get(dwc->dev); 469 + if (ret < 0) 470 + return ret; 480 471 481 472 spin_lock_irqsave(&dwc->lock, flags); 482 473 reg = dwc3_readl(dwc->regs, DWC3_DCTL); ··· 512 493 seq_printf(s, "UNKNOWN %d\n", reg); 513 494 } 514 495 496 + pm_runtime_put_sync(dwc->dev); 497 + 515 498 return 0; 516 499 } 517 500 ··· 530 509 unsigned long flags; 531 510 u32 testmode = 0; 532 511 char buf[32]; 512 + int ret; 533 513 534 514 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 535 515 return -EFAULT; ··· 548 526 else 549 527 testmode = 0; 550 528 529 + ret = pm_runtime_resume_and_get(dwc->dev); 530 + if (ret < 0) 531 + return ret; 532 + 551 533 spin_lock_irqsave(&dwc->lock, flags); 552 534 dwc3_gadget_set_test_mode(dwc, testmode); 553 535 spin_unlock_irqrestore(&dwc->lock, flags); 536 + 537 + pm_runtime_put_sync(dwc->dev); 554 538 555 539 return count; 556 540 } ··· 576 548 enum dwc3_link_state state; 577 549 u32 reg; 578 550 u8 speed; 551 + int ret; 552 + 553 + ret = pm_runtime_resume_and_get(dwc->dev); 554 + if (ret < 0) 555 + return ret; 579 556 580 557 spin_lock_irqsave(&dwc->lock, flags); 581 558 reg = dwc3_readl(dwc->regs, DWC3_GSTS); 582 559 if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { 583 560 seq_puts(s, "Not available\n"); 584 561 spin_unlock_irqrestore(&dwc->lock, flags); 562 + pm_runtime_put_sync(dwc->dev); 585 563 return 0; 586 564 } 587 565 ··· 599 565 dwc3_gadget_link_string(state) : 600 566 dwc3_gadget_hs_link_string(state)); 601 567 spin_unlock_irqrestore(&dwc->lock, flags); 568 + 569 + pm_runtime_put_sync(dwc->dev); 602 570 603 571 return 0; 604 572 } ··· 620 584 char buf[32]; 621 585 u32 reg; 622 586 u8 speed; 587 + int ret; 623 588 624 589 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) 625 590 return -EFAULT; ··· 640 603 else 641 604 return -EINVAL; 642 605 606 + ret = pm_runtime_resume_and_get(dwc->dev); 607 + if (ret < 0) 608 + return ret; 609 + 643 610 spin_lock_irqsave(&dwc->lock, flags); 644 611 reg = dwc3_readl(dwc->regs, DWC3_GSTS); 645 612 if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) { 646 613 spin_unlock_irqrestore(&dwc->lock, flags); 614 + pm_runtime_put_sync(dwc->dev); 647 615 return -EINVAL; 648 616 } 649 617 ··· 658 616 if (speed < DWC3_DSTS_SUPERSPEED && 659 617 state != DWC3_LINK_STATE_RECOV) { 660 618 spin_unlock_irqrestore(&dwc->lock, flags); 619 + pm_runtime_put_sync(dwc->dev); 661 620 return -EINVAL; 662 621 } 663 622 664 623 dwc3_gadget_set_link_state(dwc, state); 665 624 spin_unlock_irqrestore(&dwc->lock, flags); 625 + 626 + pm_runtime_put_sync(dwc->dev); 666 627 667 628 return count; 668 629 } ··· 690 645 unsigned long flags; 691 646 u32 mdwidth; 692 647 u32 val; 648 + int ret; 649 + 650 + ret = pm_runtime_resume_and_get(dwc->dev); 651 + if (ret < 0) 652 + return ret; 693 653 694 654 spin_lock_irqsave(&dwc->lock, flags); 695 655 val = dwc3_core_fifo_space(dep, DWC3_TXFIFO); ··· 707 657 seq_printf(s, "%u\n", val); 708 658 spin_unlock_irqrestore(&dwc->lock, flags); 709 659 660 + pm_runtime_put_sync(dwc->dev); 661 + 710 662 return 0; 711 663 } 712 664 ··· 719 667 unsigned long flags; 720 668 u32 mdwidth; 721 669 u32 val; 670 + int ret; 671 + 672 + ret = pm_runtime_resume_and_get(dwc->dev); 673 + if (ret < 0) 674 + return ret; 722 675 723 676 spin_lock_irqsave(&dwc->lock, flags); 724 677 val = dwc3_core_fifo_space(dep, DWC3_RXFIFO); ··· 736 679 seq_printf(s, "%u\n", val); 737 680 spin_unlock_irqrestore(&dwc->lock, flags); 738 681 682 + pm_runtime_put_sync(dwc->dev); 683 + 739 684 return 0; 740 685 } 741 686 ··· 747 688 struct dwc3 *dwc = dep->dwc; 748 689 unsigned long flags; 749 690 u32 val; 691 + int ret; 692 + 693 + ret = pm_runtime_resume_and_get(dwc->dev); 694 + if (ret < 0) 695 + return ret; 750 696 751 697 spin_lock_irqsave(&dwc->lock, flags); 752 698 val = dwc3_core_fifo_space(dep, DWC3_TXREQQ); 753 699 seq_printf(s, "%u\n", val); 754 700 spin_unlock_irqrestore(&dwc->lock, flags); 701 + 702 + pm_runtime_put_sync(dwc->dev); 755 703 756 704 return 0; 757 705 } ··· 769 703 struct dwc3 *dwc = dep->dwc; 770 704 unsigned long flags; 771 705 u32 val; 706 + int ret; 707 + 708 + ret = pm_runtime_resume_and_get(dwc->dev); 709 + if (ret < 0) 710 + return ret; 772 711 773 712 spin_lock_irqsave(&dwc->lock, flags); 774 713 val = dwc3_core_fifo_space(dep, DWC3_RXREQQ); 775 714 seq_printf(s, "%u\n", val); 776 715 spin_unlock_irqrestore(&dwc->lock, flags); 716 + 717 + pm_runtime_put_sync(dwc->dev); 777 718 778 719 return 0; 779 720 } ··· 791 718 struct dwc3 *dwc = dep->dwc; 792 719 unsigned long flags; 793 720 u32 val; 721 + int ret; 722 + 723 + ret = pm_runtime_resume_and_get(dwc->dev); 724 + if (ret < 0) 725 + return ret; 794 726 795 727 spin_lock_irqsave(&dwc->lock, flags); 796 728 val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ); 797 729 seq_printf(s, "%u\n", val); 798 730 spin_unlock_irqrestore(&dwc->lock, flags); 731 + 732 + pm_runtime_put_sync(dwc->dev); 799 733 800 734 return 0; 801 735 } ··· 813 733 struct dwc3 *dwc = dep->dwc; 814 734 unsigned long flags; 815 735 u32 val; 736 + int ret; 737 + 738 + ret = pm_runtime_resume_and_get(dwc->dev); 739 + if (ret < 0) 740 + return ret; 816 741 817 742 spin_lock_irqsave(&dwc->lock, flags); 818 743 val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ); 819 744 seq_printf(s, "%u\n", val); 820 745 spin_unlock_irqrestore(&dwc->lock, flags); 746 + 747 + pm_runtime_put_sync(dwc->dev); 821 748 822 749 return 0; 823 750 } ··· 835 748 struct dwc3 *dwc = dep->dwc; 836 749 unsigned long flags; 837 750 u32 val; 751 + int ret; 752 + 753 + ret = pm_runtime_resume_and_get(dwc->dev); 754 + if (ret < 0) 755 + return ret; 838 756 839 757 spin_lock_irqsave(&dwc->lock, flags); 840 758 val = dwc3_core_fifo_space(dep, DWC3_EVENTQ); 841 759 seq_printf(s, "%u\n", val); 842 760 spin_unlock_irqrestore(&dwc->lock, flags); 761 + 762 + pm_runtime_put_sync(dwc->dev); 843 763 844 764 return 0; 845 765 } ··· 892 798 struct dwc3 *dwc = dep->dwc; 893 799 unsigned long flags; 894 800 int i; 801 + int ret; 802 + 803 + ret = pm_runtime_resume_and_get(dwc->dev); 804 + if (ret < 0) 805 + return ret; 895 806 896 807 spin_lock_irqsave(&dwc->lock, flags); 897 808 if (dep->number <= 1) { ··· 926 827 out: 927 828 spin_unlock_irqrestore(&dwc->lock, flags); 928 829 830 + pm_runtime_put_sync(dwc->dev); 831 + 929 832 return 0; 930 833 } 931 834 ··· 940 839 u32 lower_32_bits; 941 840 u32 upper_32_bits; 942 841 u32 reg; 842 + int ret; 843 + 844 + ret = pm_runtime_resume_and_get(dwc->dev); 845 + if (ret < 0) 846 + return ret; 943 847 944 848 spin_lock_irqsave(&dwc->lock, flags); 945 849 reg = DWC3_GDBGLSPMUX_EPSELECT(dep->number); ··· 956 850 ep_info = ((u64)upper_32_bits << 32) | lower_32_bits; 957 851 seq_printf(s, "0x%016llx\n", ep_info); 958 852 spin_unlock_irqrestore(&dwc->lock, flags); 853 + 854 + pm_runtime_put_sync(dwc->dev); 959 855 960 856 return 0; 961 857 } ··· 1018 910 dwc->regset->regs = dwc3_regs; 1019 911 dwc->regset->nregs = ARRAY_SIZE(dwc3_regs); 1020 912 dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START; 913 + dwc->regset->dev = dwc->dev; 1021 914 1022 915 root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root); 1023 916 dwc->debug_root = root;
+45 -34
drivers/usb/dwc3/gadget.c
··· 2440 2440 return -EINVAL; 2441 2441 } 2442 2442 dwc3_resume_gadget(dwc); 2443 + dwc->suspended = false; 2443 2444 dwc->link_state = DWC3_LINK_STATE_U0; 2444 2445 } 2445 2446 ··· 2700 2699 return ret; 2701 2700 } 2702 2701 2702 + static int dwc3_gadget_soft_connect(struct dwc3 *dwc) 2703 + { 2704 + /* 2705 + * In the Synopsys DWC_usb31 1.90a programming guide section 2706 + * 4.1.9, it specifies that for a reconnect after a 2707 + * device-initiated disconnect requires a core soft reset 2708 + * (DCTL.CSftRst) before enabling the run/stop bit. 2709 + */ 2710 + dwc3_core_soft_reset(dwc); 2711 + 2712 + dwc3_event_buffers_setup(dwc); 2713 + __dwc3_gadget_start(dwc); 2714 + return dwc3_gadget_run_stop(dwc, true); 2715 + } 2716 + 2703 2717 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) 2704 2718 { 2705 2719 struct dwc3 *dwc = gadget_to_dwc(g); ··· 2753 2737 2754 2738 synchronize_irq(dwc->irq_gadget); 2755 2739 2756 - if (!is_on) { 2740 + if (!is_on) 2757 2741 ret = dwc3_gadget_soft_disconnect(dwc); 2758 - } else { 2759 - /* 2760 - * In the Synopsys DWC_usb31 1.90a programming guide section 2761 - * 4.1.9, it specifies that for a reconnect after a 2762 - * device-initiated disconnect requires a core soft reset 2763 - * (DCTL.CSftRst) before enabling the run/stop bit. 2764 - */ 2765 - dwc3_core_soft_reset(dwc); 2766 - 2767 - dwc3_event_buffers_setup(dwc); 2768 - __dwc3_gadget_start(dwc); 2769 - ret = dwc3_gadget_run_stop(dwc, true); 2770 - } 2742 + else 2743 + ret = dwc3_gadget_soft_connect(dwc); 2771 2744 2772 2745 pm_runtime_put(dwc->dev); 2773 2746 ··· 3943 3938 { 3944 3939 int reg; 3945 3940 3941 + dwc->suspended = false; 3942 + 3946 3943 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); 3947 3944 3948 3945 reg = dwc3_readl(dwc->regs, DWC3_DCTL); ··· 3968 3961 static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) 3969 3962 { 3970 3963 u32 reg; 3964 + 3965 + dwc->suspended = false; 3971 3966 3972 3967 /* 3973 3968 * Ideally, dwc3_reset_gadget() would trigger the function ··· 4189 4180 4190 4181 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo) 4191 4182 { 4183 + dwc->suspended = false; 4184 + 4192 4185 /* 4193 4186 * TODO take core out of low power mode when that's 4194 4187 * implemented. ··· 4288 4277 if (dwc->gadget->wakeup_armed) { 4289 4278 dwc3_gadget_enable_linksts_evts(dwc, false); 4290 4279 dwc3_resume_gadget(dwc); 4280 + dwc->suspended = false; 4291 4281 } 4292 4282 break; 4293 4283 case DWC3_LINK_STATE_U1: ··· 4315 4303 { 4316 4304 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; 4317 4305 4318 - if (dwc->link_state != next && next == DWC3_LINK_STATE_U3) 4306 + if (!dwc->suspended && next == DWC3_LINK_STATE_U3) { 4307 + dwc->suspended = true; 4319 4308 dwc3_suspend_gadget(dwc); 4309 + } 4320 4310 4321 4311 dwc->link_state = next; 4322 4312 } ··· 4669 4655 int dwc3_gadget_suspend(struct dwc3 *dwc) 4670 4656 { 4671 4657 unsigned long flags; 4658 + int ret; 4672 4659 4673 4660 if (!dwc->gadget_driver) 4674 4661 return 0; 4675 4662 4676 - dwc3_gadget_run_stop(dwc, false); 4663 + ret = dwc3_gadget_soft_disconnect(dwc); 4664 + if (ret) 4665 + goto err; 4677 4666 4678 4667 spin_lock_irqsave(&dwc->lock, flags); 4679 4668 dwc3_disconnect_gadget(dwc); 4680 - __dwc3_gadget_stop(dwc); 4681 4669 spin_unlock_irqrestore(&dwc->lock, flags); 4682 4670 4683 4671 return 0; 4672 + 4673 + err: 4674 + /* 4675 + * Attempt to reset the controller's state. Likely no 4676 + * communication can be established until the host 4677 + * performs a port reset. 4678 + */ 4679 + if (dwc->softconnect) 4680 + dwc3_gadget_soft_connect(dwc); 4681 + 4682 + return ret; 4684 4683 } 4685 4684 4686 4685 int dwc3_gadget_resume(struct dwc3 *dwc) 4687 4686 { 4688 - int ret; 4689 - 4690 4687 if (!dwc->gadget_driver || !dwc->softconnect) 4691 4688 return 0; 4692 4689 4693 - ret = __dwc3_gadget_start(dwc); 4694 - if (ret < 0) 4695 - goto err0; 4696 - 4697 - ret = dwc3_gadget_run_stop(dwc, true); 4698 - if (ret < 0) 4699 - goto err1; 4700 - 4701 - return 0; 4702 - 4703 - err1: 4704 - __dwc3_gadget_stop(dwc); 4705 - 4706 - err0: 4707 - return ret; 4690 + return dwc3_gadget_soft_connect(dwc); 4708 4691 } 4709 4692 4710 4693 void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
+3
drivers/usb/gadget/function/u_ether.c
··· 17 17 #include <linux/etherdevice.h> 18 18 #include <linux/ethtool.h> 19 19 #include <linux/if_vlan.h> 20 + #include <linux/string_helpers.h> 20 21 #include <linux/usb/composite.h> 21 22 22 23 #include "u_ether.h" ··· 965 964 966 965 dev = netdev_priv(net); 967 966 snprintf(host_addr, len, "%pm", dev->host_mac); 967 + 968 + string_upper(host_addr, host_addr); 968 969 969 970 return strlen(host_addr); 970 971 }
+62 -125
drivers/usb/gadget/udc/core.c
··· 37 37 * @vbus: for udcs who care about vbus status, this value is real vbus status; 38 38 * for udcs who do not care about vbus status, this value is always true 39 39 * @started: the UDC's started state. True if the UDC had started. 40 - * @connect_lock: protects udc->vbus, udc->started, gadget->connect, gadget->deactivate related 41 - * functions. usb_gadget_connect_locked, usb_gadget_disconnect_locked, 42 - * usb_udc_connect_control_locked, usb_gadget_udc_start_locked, usb_gadget_udc_stop_locked are 43 - * called with this lock held. 44 40 * 45 41 * This represents the internal data structure which is used by the UDC-class 46 42 * to hold information about udc driver and gadget together. ··· 48 52 struct list_head list; 49 53 bool vbus; 50 54 bool started; 51 - struct mutex connect_lock; 52 55 }; 53 56 54 57 static struct class *udc_class; ··· 687 692 } 688 693 EXPORT_SYMBOL_GPL(usb_gadget_vbus_disconnect); 689 694 690 - /* Internal version of usb_gadget_connect needs to be called with connect_lock held. */ 691 - static int usb_gadget_connect_locked(struct usb_gadget *gadget) 692 - __must_hold(&gadget->udc->connect_lock) 695 + /** 696 + * usb_gadget_connect - software-controlled connect to USB host 697 + * @gadget:the peripheral being connected 698 + * 699 + * Enables the D+ (or potentially D-) pullup. The host will start 700 + * enumerating this gadget when the pullup is active and a VBUS session 701 + * is active (the link is powered). 702 + * 703 + * Returns zero on success, else negative errno. 704 + */ 705 + int usb_gadget_connect(struct usb_gadget *gadget) 693 706 { 694 707 int ret = 0; 695 708 ··· 706 703 goto out; 707 704 } 708 705 709 - if (gadget->connected) 710 - goto out; 711 - 712 - if (gadget->deactivated || !gadget->udc->started) { 706 + if (gadget->deactivated) { 713 707 /* 714 708 * If gadget is deactivated we only save new state. 715 709 * Gadget will be connected automatically after activation. 716 - * 717 - * udc first needs to be started before gadget can be pulled up. 718 710 */ 719 711 gadget->connected = true; 720 712 goto out; ··· 724 726 725 727 return ret; 726 728 } 727 - 728 - /** 729 - * usb_gadget_connect - software-controlled connect to USB host 730 - * @gadget:the peripheral being connected 731 - * 732 - * Enables the D+ (or potentially D-) pullup. The host will start 733 - * enumerating this gadget when the pullup is active and a VBUS session 734 - * is active (the link is powered). 735 - * 736 - * Returns zero on success, else negative errno. 737 - */ 738 - int usb_gadget_connect(struct usb_gadget *gadget) 739 - { 740 - int ret; 741 - 742 - mutex_lock(&gadget->udc->connect_lock); 743 - ret = usb_gadget_connect_locked(gadget); 744 - mutex_unlock(&gadget->udc->connect_lock); 745 - 746 - return ret; 747 - } 748 729 EXPORT_SYMBOL_GPL(usb_gadget_connect); 749 - 750 - /* Internal version of usb_gadget_disconnect needs to be called with connect_lock held. */ 751 - static int usb_gadget_disconnect_locked(struct usb_gadget *gadget) 752 - __must_hold(&gadget->udc->connect_lock) 753 - { 754 - int ret = 0; 755 - 756 - if (!gadget->ops->pullup) { 757 - ret = -EOPNOTSUPP; 758 - goto out; 759 - } 760 - 761 - if (!gadget->connected) 762 - goto out; 763 - 764 - if (gadget->deactivated || !gadget->udc->started) { 765 - /* 766 - * If gadget is deactivated we only save new state. 767 - * Gadget will stay disconnected after activation. 768 - * 769 - * udc should have been started before gadget being pulled down. 770 - */ 771 - gadget->connected = false; 772 - goto out; 773 - } 774 - 775 - ret = gadget->ops->pullup(gadget, 0); 776 - if (!ret) 777 - gadget->connected = 0; 778 - 779 - mutex_lock(&udc_lock); 780 - if (gadget->udc->driver) 781 - gadget->udc->driver->disconnect(gadget); 782 - mutex_unlock(&udc_lock); 783 - 784 - out: 785 - trace_usb_gadget_disconnect(gadget, ret); 786 - 787 - return ret; 788 - } 789 730 790 731 /** 791 732 * usb_gadget_disconnect - software-controlled disconnect from USB host ··· 741 804 */ 742 805 int usb_gadget_disconnect(struct usb_gadget *gadget) 743 806 { 744 - int ret; 807 + int ret = 0; 745 808 746 - mutex_lock(&gadget->udc->connect_lock); 747 - ret = usb_gadget_disconnect_locked(gadget); 748 - mutex_unlock(&gadget->udc->connect_lock); 809 + if (!gadget->ops->pullup) { 810 + ret = -EOPNOTSUPP; 811 + goto out; 812 + } 813 + 814 + if (!gadget->connected) 815 + goto out; 816 + 817 + if (gadget->deactivated) { 818 + /* 819 + * If gadget is deactivated we only save new state. 820 + * Gadget will stay disconnected after activation. 821 + */ 822 + gadget->connected = false; 823 + goto out; 824 + } 825 + 826 + ret = gadget->ops->pullup(gadget, 0); 827 + if (!ret) 828 + gadget->connected = 0; 829 + 830 + mutex_lock(&udc_lock); 831 + if (gadget->udc->driver) 832 + gadget->udc->driver->disconnect(gadget); 833 + mutex_unlock(&udc_lock); 834 + 835 + out: 836 + trace_usb_gadget_disconnect(gadget, ret); 749 837 750 838 return ret; 751 839 } ··· 794 832 if (gadget->deactivated) 795 833 goto out; 796 834 797 - mutex_lock(&gadget->udc->connect_lock); 798 835 if (gadget->connected) { 799 - ret = usb_gadget_disconnect_locked(gadget); 836 + ret = usb_gadget_disconnect(gadget); 800 837 if (ret) 801 - goto unlock; 838 + goto out; 802 839 803 840 /* 804 841 * If gadget was being connected before deactivation, we want ··· 807 846 } 808 847 gadget->deactivated = true; 809 848 810 - unlock: 811 - mutex_unlock(&gadget->udc->connect_lock); 812 849 out: 813 850 trace_usb_gadget_deactivate(gadget, ret); 814 851 ··· 830 871 if (!gadget->deactivated) 831 872 goto out; 832 873 833 - mutex_lock(&gadget->udc->connect_lock); 834 874 gadget->deactivated = false; 835 875 836 876 /* ··· 837 879 * while it was being deactivated, we call usb_gadget_connect(). 838 880 */ 839 881 if (gadget->connected) 840 - ret = usb_gadget_connect_locked(gadget); 841 - mutex_unlock(&gadget->udc->connect_lock); 882 + ret = usb_gadget_connect(gadget); 842 883 843 884 out: 844 885 trace_usb_gadget_activate(gadget, ret); ··· 1078 1121 1079 1122 /* ------------------------------------------------------------------------- */ 1080 1123 1081 - /* Acquire connect_lock before calling this function. */ 1082 - static void usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) 1124 + static void usb_udc_connect_control(struct usb_udc *udc) 1083 1125 { 1084 - if (udc->vbus && udc->started) 1085 - usb_gadget_connect_locked(udc->gadget); 1126 + if (udc->vbus) 1127 + usb_gadget_connect(udc->gadget); 1086 1128 else 1087 - usb_gadget_disconnect_locked(udc->gadget); 1129 + usb_gadget_disconnect(udc->gadget); 1088 1130 } 1089 1131 1090 1132 /** ··· 1099 1143 { 1100 1144 struct usb_udc *udc = gadget->udc; 1101 1145 1102 - mutex_lock(&udc->connect_lock); 1103 1146 if (udc) { 1104 1147 udc->vbus = status; 1105 - usb_udc_connect_control_locked(udc); 1148 + usb_udc_connect_control(udc); 1106 1149 } 1107 - mutex_unlock(&udc->connect_lock); 1108 1150 } 1109 1151 EXPORT_SYMBOL_GPL(usb_udc_vbus_handler); 1110 1152 ··· 1124 1170 EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); 1125 1171 1126 1172 /** 1127 - * usb_gadget_udc_start_locked - tells usb device controller to start up 1173 + * usb_gadget_udc_start - tells usb device controller to start up 1128 1174 * @udc: The UDC to be started 1129 1175 * 1130 1176 * This call is issued by the UDC Class driver when it's about ··· 1135 1181 * necessary to have it powered on. 1136 1182 * 1137 1183 * Returns zero on success, else negative errno. 1138 - * 1139 - * Caller should acquire connect_lock before invoking this function. 1140 1184 */ 1141 - static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) 1142 - __must_hold(&udc->connect_lock) 1185 + static inline int usb_gadget_udc_start(struct usb_udc *udc) 1143 1186 { 1144 1187 int ret; 1145 1188 ··· 1153 1202 } 1154 1203 1155 1204 /** 1156 - * usb_gadget_udc_stop_locked - tells usb device controller we don't need it anymore 1205 + * usb_gadget_udc_stop - tells usb device controller we don't need it anymore 1157 1206 * @udc: The UDC to be stopped 1158 1207 * 1159 1208 * This call is issued by the UDC Class driver after calling ··· 1162 1211 * The details are implementation specific, but it can go as 1163 1212 * far as powering off UDC completely and disable its data 1164 1213 * line pullups. 1165 - * 1166 - * Caller should acquire connect lock before invoking this function. 1167 1214 */ 1168 - static inline void usb_gadget_udc_stop_locked(struct usb_udc *udc) 1169 - __must_hold(&udc->connect_lock) 1215 + static inline void usb_gadget_udc_stop(struct usb_udc *udc) 1170 1216 { 1171 1217 if (!udc->started) { 1172 1218 dev_err(&udc->dev, "UDC had already stopped\n"); ··· 1322 1374 1323 1375 udc->gadget = gadget; 1324 1376 gadget->udc = udc; 1325 - mutex_init(&udc->connect_lock); 1326 1377 1327 1378 udc->started = false; 1328 1379 ··· 1523 1576 if (ret) 1524 1577 goto err_bind; 1525 1578 1526 - mutex_lock(&udc->connect_lock); 1527 - ret = usb_gadget_udc_start_locked(udc); 1528 - if (ret) { 1529 - mutex_unlock(&udc->connect_lock); 1579 + ret = usb_gadget_udc_start(udc); 1580 + if (ret) 1530 1581 goto err_start; 1531 - } 1532 1582 usb_gadget_enable_async_callbacks(udc); 1533 - usb_udc_connect_control_locked(udc); 1534 - mutex_unlock(&udc->connect_lock); 1583 + usb_udc_connect_control(udc); 1535 1584 1536 1585 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 1537 1586 return 0; ··· 1558 1615 1559 1616 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); 1560 1617 1561 - mutex_lock(&udc->connect_lock); 1562 - usb_gadget_disconnect_locked(gadget); 1618 + usb_gadget_disconnect(gadget); 1563 1619 usb_gadget_disable_async_callbacks(udc); 1564 1620 if (gadget->irq) 1565 1621 synchronize_irq(gadget->irq); 1566 1622 udc->driver->unbind(gadget); 1567 - usb_gadget_udc_stop_locked(udc); 1568 - mutex_unlock(&udc->connect_lock); 1623 + usb_gadget_udc_stop(udc); 1569 1624 1570 1625 mutex_lock(&udc_lock); 1571 1626 driver->is_bound = false; ··· 1649 1708 } 1650 1709 1651 1710 if (sysfs_streq(buf, "connect")) { 1652 - mutex_lock(&udc->connect_lock); 1653 - usb_gadget_udc_start_locked(udc); 1654 - usb_gadget_connect_locked(udc->gadget); 1655 - mutex_unlock(&udc->connect_lock); 1711 + usb_gadget_udc_start(udc); 1712 + usb_gadget_connect(udc->gadget); 1656 1713 } else if (sysfs_streq(buf, "disconnect")) { 1657 - mutex_lock(&udc->connect_lock); 1658 - usb_gadget_disconnect_locked(udc->gadget); 1659 - usb_gadget_udc_stop_locked(udc); 1660 - mutex_unlock(&udc->connect_lock); 1714 + usb_gadget_disconnect(udc->gadget); 1715 + usb_gadget_udc_stop(udc); 1661 1716 } else { 1662 1717 dev_err(dev, "unsupported command '%s'\n", buf); 1663 1718 ret = -EINVAL;
+6 -4
drivers/usb/host/uhci-pci.c
··· 119 119 120 120 uhci->rh_numports = uhci_count_ports(hcd); 121 121 122 - /* Intel controllers report the OverCurrent bit active on. 123 - * VIA controllers report it active off, so we'll adjust the 124 - * bit value. (It's not standardized in the UHCI spec.) 122 + /* 123 + * Intel controllers report the OverCurrent bit active on. VIA 124 + * and ZHAOXIN controllers report it active off, so we'll adjust 125 + * the bit value. (It's not standardized in the UHCI spec.) 125 126 */ 126 - if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA) 127 + if (to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_VIA || 128 + to_pci_dev(uhci_dev(uhci))->vendor == PCI_VENDOR_ID_ZHAOXIN) 127 129 uhci->oc_low = 1; 128 130 129 131 /* HP's server management chip requires a longer port reset delay. */
+10 -2
drivers/usb/host/xhci-pci.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/acpi.h> 15 15 #include <linux/reset.h> 16 + #include <linux/suspend.h> 16 17 17 18 #include "xhci.h" 18 19 #include "xhci-trace.h" ··· 388 387 389 388 if (pdev->vendor == PCI_VENDOR_ID_AMD && 390 389 pdev->device == PCI_DEVICE_ID_AMD_RENOIR_XHCI) 391 - xhci->quirks |= XHCI_BROKEN_D3COLD; 390 + xhci->quirks |= XHCI_BROKEN_D3COLD_S2I; 392 391 393 392 if (pdev->vendor == PCI_VENDOR_ID_INTEL) { 394 393 xhci->quirks |= XHCI_LPM_SUPPORT; ··· 802 801 * Systems with the TI redriver that loses port status change events 803 802 * need to have the registers polled during D3, so avoid D3cold. 804 803 */ 805 - if (xhci->quirks & (XHCI_COMP_MODE_QUIRK | XHCI_BROKEN_D3COLD)) 804 + if (xhci->quirks & XHCI_COMP_MODE_QUIRK) 806 805 pci_d3cold_disable(pdev); 806 + 807 + #ifdef CONFIG_SUSPEND 808 + /* d3cold is broken, but only when s2idle is used */ 809 + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE && 810 + xhci->quirks & (XHCI_BROKEN_D3COLD_S2I)) 811 + pci_d3cold_disable(pdev); 812 + #endif 807 813 808 814 if (xhci->quirks & XHCI_PME_STUCK_QUIRK) 809 815 xhci_pme_quirk(hcd);
+28 -1
drivers/usb/host/xhci-ring.c
··· 276 276 trace_xhci_inc_enq(ring); 277 277 } 278 278 279 + static int xhci_num_trbs_to(struct xhci_segment *start_seg, union xhci_trb *start, 280 + struct xhci_segment *end_seg, union xhci_trb *end, 281 + unsigned int num_segs) 282 + { 283 + union xhci_trb *last_on_seg; 284 + int num = 0; 285 + int i = 0; 286 + 287 + do { 288 + if (start_seg == end_seg && end >= start) 289 + return num + (end - start); 290 + last_on_seg = &start_seg->trbs[TRBS_PER_SEGMENT - 1]; 291 + num += last_on_seg - start; 292 + start_seg = start_seg->next; 293 + start = start_seg->trbs; 294 + } while (i++ <= num_segs); 295 + 296 + return -EINVAL; 297 + } 298 + 279 299 /* 280 300 * Check to see if there's room to enqueue num_trbs on the ring and make sure 281 301 * enqueue pointer will not advance into dequeue segment. See rules above. ··· 2160 2140 u32 trb_comp_code) 2161 2141 { 2162 2142 struct xhci_ep_ctx *ep_ctx; 2143 + int trbs_freed; 2163 2144 2164 2145 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index); 2165 2146 ··· 2230 2209 } 2231 2210 2232 2211 /* Update ring dequeue pointer */ 2212 + trbs_freed = xhci_num_trbs_to(ep_ring->deq_seg, ep_ring->dequeue, 2213 + td->last_trb_seg, td->last_trb, 2214 + ep_ring->num_segs); 2215 + if (trbs_freed < 0) 2216 + xhci_dbg(xhci, "Failed to count freed trbs at TD finish\n"); 2217 + else 2218 + ep_ring->num_trbs_free += trbs_freed; 2233 2219 ep_ring->dequeue = td->last_trb; 2234 2220 ep_ring->deq_seg = td->last_trb_seg; 2235 - ep_ring->num_trbs_free += td->num_trbs - 1; 2236 2221 inc_deq(xhci, ep_ring); 2237 2222 2238 2223 return xhci_td_cleanup(xhci, td, ep_ring, td->status);
+1 -1
drivers/usb/host/xhci.h
··· 1901 1901 #define XHCI_DISABLE_SPARSE BIT_ULL(38) 1902 1902 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39) 1903 1903 #define XHCI_NO_SOFT_RETRY BIT_ULL(40) 1904 - #define XHCI_BROKEN_D3COLD BIT_ULL(41) 1904 + #define XHCI_BROKEN_D3COLD_S2I BIT_ULL(41) 1905 1905 #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42) 1906 1906 #define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(43) 1907 1907 #define XHCI_RESET_TO_DEFAULT BIT_ULL(44)
+21 -7
drivers/usb/storage/scsiglue.c
··· 406 406 ***********************************************************************/ 407 407 408 408 /* Command timeout and abort */ 409 - static int command_abort(struct scsi_cmnd *srb) 409 + static int command_abort_matching(struct us_data *us, struct scsi_cmnd *srb_match) 410 410 { 411 - struct us_data *us = host_to_us(srb->device->host); 412 - 413 - usb_stor_dbg(us, "%s called\n", __func__); 414 - 415 411 /* 416 412 * us->srb together with the TIMED_OUT, RESETTING, and ABORTING 417 413 * bits are protected by the host lock. 418 414 */ 419 415 scsi_lock(us_to_host(us)); 420 416 421 - /* Is this command still active? */ 422 - if (us->srb != srb) { 417 + /* is there any active pending command to abort ? */ 418 + if (!us->srb) { 423 419 scsi_unlock(us_to_host(us)); 424 420 usb_stor_dbg(us, "-- nothing to abort\n"); 421 + return SUCCESS; 422 + } 423 + 424 + /* Does the command match the passed srb if any ? */ 425 + if (srb_match && us->srb != srb_match) { 426 + scsi_unlock(us_to_host(us)); 427 + usb_stor_dbg(us, "-- pending command mismatch\n"); 425 428 return FAILED; 426 429 } 427 430 ··· 447 444 return SUCCESS; 448 445 } 449 446 447 + static int command_abort(struct scsi_cmnd *srb) 448 + { 449 + struct us_data *us = host_to_us(srb->device->host); 450 + 451 + usb_stor_dbg(us, "%s called\n", __func__); 452 + return command_abort_matching(us, srb); 453 + } 454 + 450 455 /* 451 456 * This invokes the transport reset mechanism to reset the state of the 452 457 * device ··· 465 454 int result; 466 455 467 456 usb_stor_dbg(us, "%s called\n", __func__); 457 + 458 + /* abort any pending command before reset */ 459 + command_abort_matching(us, NULL); 468 460 469 461 /* lock the device pointers and do the reset */ 470 462 mutex_lock(&(us->dev_mutex));
+4
drivers/usb/typec/altmodes/displayport.c
··· 516 516 517 517 mutex_unlock(&dp->lock); 518 518 519 + /* get_current_pin_assignments can return 0 when no matching pin assignments are found */ 520 + if (len == 0) 521 + len++; 522 + 519 523 buf[len - 1] = '\n'; 520 524 return len; 521 525 }
+3
drivers/usb/typec/tipd/core.c
··· 886 886 { 887 887 struct tps6598x *tps = i2c_get_clientdata(client); 888 888 889 + if (!client->irq) 890 + cancel_delayed_work_sync(&tps->wq_poll); 891 + 889 892 tps6598x_disconnect(tps, 0); 890 893 typec_unregister_port(tps->port); 891 894 usb_role_switch_put(tps->role_sw);
+1
include/linux/device/class.h
··· 74 74 struct class_dev_iter { 75 75 struct klist_iter ki; 76 76 const struct device_type *type; 77 + struct subsys_private *sp; 77 78 }; 78 79 79 80 int __must_check class_register(const struct class *class);
+1 -1
include/linux/usb/composite.h
··· 443 443 * @bcd_webusb_version: 0x0100 by default, WebUSB specification version 444 444 * @b_webusb_vendor_code: 0x0 by default, vendor code for WebUSB 445 445 * @landing_page: empty by default, landing page to announce in WebUSB 446 - * @use_webusb:: false by default, interested gadgets set it 446 + * @use_webusb: false by default, interested gadgets set it 447 447 * @os_desc_config: the configuration to be used with OS descriptors 448 448 * @setup_pending: true when setup request is queued but not completed 449 449 * @os_desc_pending: true when os_desc request is queued but not completed