History

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

Linus Torvalds committed 3 years ago

Commit 2dd0d982 parents 98be58a ddaf09819 files · +309 −163Browse files

Unified · Split

19 files
  1. drivers/base/class.c +2 −0
  2. drivers/thunderbolt/nhi.c +24 −5
  3. drivers/thunderbolt/nhi_regs.h +2 −0
  4. drivers/usb/class/usbtmc.c +2 −0
  5. drivers/usb/dwc3/core.c +1 −1
  6. drivers/usb/dwc3/core.h +2 −0
  7. drivers/usb/dwc3/debugfs.c +109 −0
  8. drivers/usb/dwc3/gadget.c +45 −34
  9. drivers/usb/gadget/function/u_ether.c +3 −0
  10. drivers/usb/gadget/udc/core.c +44 −107
  11. drivers/usb/host/uhci-pci.c +6 −4
  12. drivers/usb/host/xhci-pci.c +10 −2
  13. drivers/usb/host/xhci-ring.c +28 −1
  14. drivers/usb/host/xhci.h +1 −1
  15. drivers/usb/storage/scsiglue.c +21 −7
  16. drivers/usb/typec/altmodes/displayport.c +4 −0
  17. drivers/usb/typec/tipd/core.c +3 −0
  18. include/linux/device/class.h +1 −0
  19. include/linux/usb/composite.h +1 −1
drivers/base/class.c+2−0
@@ -320,6 +320,7 @@ void class_dev_iter_init(struct class_dev_iter *iter, const struct class *class, · 319 unmodified lines
320320 start_knode = &start->p->knode_class;
321321 klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode);
322322 iter->type = type;
323+ iter->sp = sp;
323324 }
324325 EXPORT_SYMBOL_GPL(class_dev_iter_init);
325326
@@ -361,6 +362,7 @@ EXPORT_SYMBOL_GPL(class_dev_iter_next); · 35 unmodified lines
361362 void class_dev_iter_exit(struct class_dev_iter *iter)
362363 {
363364 klist_iter_exit(&iter->ki);
365+ subsys_put(iter->sp);
364366 }
365367 EXPORT_SYMBOL_GPL(class_dev_iter_exit);
366368
drivers/thunderbolt/nhi.c+24−5
@@ -54,6 +54,21 @@ static int ring_interrupt_index(const struct tb_ring *ring) · 53 unmodified lines
5454 return bit;
5555 }
5656
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+
5772 /*
5873 * ring_interrupt_active() - activate/deactivate interrupts for a single ring
5974 *
@@ -61,8 +76,8 @@ static int ring_interrupt_index(const struct tb_ring *ring) · 1 unmodified line
6176 */
6277 static void ring_interrupt_active(struct tb_ring *ring, bool active)
6378 {
64− int reg = REG_RING_INTERRUPT_BASE +
65− ring_interrupt_index(ring) / 32 * 4;
79+ int index = ring_interrupt_index(ring) / 32 * 4;
80+ int reg = REG_RING_INTERRUPT_BASE + index;
6681 int interrupt_bit = ring_interrupt_index(ring) & 31;
6782 int mask = 1 << interrupt_bit;
6883 u32 old, new;
@@ -123,7 +138,11 @@ static void ring_interrupt_active(struct tb_ring *ring, bool active) · 54 unmodified lines
123138 "interrupt for %s %d is already %s\n",
124139 RING_TYPE(ring), ring->hop,
125140 active ? "enabled" : "disabled");
126− iowrite32(new, ring->nhi->iobase + reg);
141+
142+ if (active)
143+ iowrite32(new, ring->nhi->iobase + reg);
144+ else
145+ nhi_mask_interrupt(ring->nhi, mask, index);
127146 }
128147
129148 /*
@@ -136,11 +155,11 @@ static void nhi_disable_interrupts(struct tb_nhi *nhi) · 6 unmodified lines
136155 int i = 0;
137156 /* disable interrupts */
138157 for (i = 0; i < RING_INTERRUPT_REG_COUNT(nhi); i++)
139− iowrite32(0, nhi->iobase + REG_RING_INTERRUPT_BASE + 4 * i);
158+ nhi_mask_interrupt(nhi, ~0, 4 * i);
140159
141160 /* clear interrupt status bits */
142161 for (i = 0; i < RING_NOTIFY_REG_COUNT(nhi); i++)
143− ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + 4 * i);
162+ nhi_clear_interrupt(nhi, 4 * i);
144163 }
145164
146165 /* ring helper methods */
drivers/thunderbolt/nhi_regs.h+2−0
@@ -93,6 +93,8 @@ struct ring_desc { · 92 unmodified lines
9393 #define REG_RING_INTERRUPT_BASE 0x38200
9494 #define RING_INTERRUPT_REG_COUNT(nhi) ((31 + 2 * nhi->hop_count) / 32)
9595
96+#define REG_RING_INTERRUPT_MASK_CLEAR_BASE 0x38208
97+
9698 #define REG_INT_THROTTLING_RATE 0x38c00
9799
98100 /* Interrupt Vector Allocation */
drivers/usb/class/usbtmc.c+2−0
@@ -1928,6 +1928,8 @@ static int usbtmc_ioctl_request(struct usbtmc_device_data *data, · 1927 unmodified lines
19281928
19291929 if (request.req.wLength > USBTMC_BUFSIZE)
19301930 return -EMSGSIZE;
1931+ if (request.req.wLength == 0) /* Length-0 requests are never IN */
1932+ request.req.bRequestType &= ~USB_DIR_IN;
19311933
19321934 is_in = request.req.bRequestType & USB_DIR_IN;
19331935
drivers/usb/dwc3/core.c+1−1
@@ -1137,7 +1137,7 @@ static int dwc3_core_init(struct dwc3 *dwc) · 1136 unmodified lines
11371137
11381138 dwc3_set_incr_burst_type(dwc);
11391139
1140− dwc3_phy_power_on(dwc);
1140+ ret = dwc3_phy_power_on(dwc);
11411141 if (ret)
11421142 goto err_exit_phy;
11431143
drivers/usb/dwc3/core.h+2−0
@@ -1116,6 +1116,7 @@ struct dwc3_scratchpad_array { · 1115 unmodified lines
11161116 * @dis_metastability_quirk: set to disable metastability quirk.
11171117 * @dis_split_quirk: set to disable split boundary.
11181118 * @wakeup_configured: set if the device is configured for remote wakeup.
1119+ * @suspended: set to track suspend event due to U3/L2.
11191120 * @imod_interval: set the interrupt moderation interval in 250ns
11201121 * increments or 0 to disable.
11211122 * @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1332,6 +1333,7 @@ struct dwc3 { · 210 unmodified lines
13321333 unsigned dis_split_quirk:1;
13331334 unsigned async_callbacks:1;
13341335 unsigned wakeup_configured:1;
1336+ unsigned suspended:1;
13351337
13361338 u16 imod_interval;
13371339
drivers/usb/dwc3/debugfs.c+109−0
@@ -332,6 +332,11 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused) · 331 unmodified lines
332332 unsigned int current_mode;
333333 unsigned long flags;
334334 u32 reg;
335+ int ret;
336+
337+ ret = pm_runtime_resume_and_get(dwc->dev);
338+ if (ret < 0)
339+ return ret;
335340
336341 spin_lock_irqsave(&dwc->lock, flags);
337342 reg = dwc3_readl(dwc->regs, DWC3_GSTS);
@@ -350,6 +355,8 @@ static int dwc3_lsp_show(struct seq_file *s, void *unused) · 12 unmodified lines
350355 }
351356 spin_unlock_irqrestore(&dwc->lock, flags);
352357
358+ pm_runtime_put_sync(dwc->dev);
359+
353360 return 0;
354361 }
355362
@@ -395,6 +402,11 @@ static int dwc3_mode_show(struct seq_file *s, void *unused) · 39 unmodified lines
395402 struct dwc3 *dwc = s->private;
396403 unsigned long flags;
397404 u32 reg;
405+ int ret;
406+
407+ ret = pm_runtime_resume_and_get(dwc->dev);
408+ if (ret < 0)
409+ return ret;
398410
399411 spin_lock_irqsave(&dwc->lock, flags);
400412 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
@@ -414,6 +426,8 @@ static int dwc3_mode_show(struct seq_file *s, void *unused) · 13 unmodified lines
414426 seq_printf(s, "UNKNOWN %08x\n", DWC3_GCTL_PRTCAP(reg));
415427 }
416428
429+ pm_runtime_put_sync(dwc->dev);
430+
417431 return 0;
418432 }
419433
@@ -463,6 +477,11 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused) · 43 unmodified lines
463477 struct dwc3 *dwc = s->private;
464478 unsigned long flags;
465479 u32 reg;
480+ int ret;
481+
482+ ret = pm_runtime_resume_and_get(dwc->dev);
483+ if (ret < 0)
484+ return ret;
466485
467486 spin_lock_irqsave(&dwc->lock, flags);
468487 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
@@ -493,6 +512,8 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused) · 24 unmodified lines
493512 seq_printf(s, "UNKNOWN %d\n", reg);
494513 }
495514
515+ pm_runtime_put_sync(dwc->dev);
516+
496517 return 0;
497518 }
498519
@@ -509,6 +530,7 @@ static ssize_t dwc3_testmode_write(struct file *file, · 10 unmodified lines
509530 unsigned long flags;
510531 u32 testmode = 0;
511532 char buf[32];
533+ int ret;
512534
513535 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
514536 return -EFAULT;
@@ -526,10 +548,16 @@ static ssize_t dwc3_testmode_write(struct file *file, · 11 unmodified lines
526548 else
527549 testmode = 0;
528550
551+ ret = pm_runtime_resume_and_get(dwc->dev);
552+ if (ret < 0)
553+ return ret;
554+
529555 spin_lock_irqsave(&dwc->lock, flags);
530556 dwc3_gadget_set_test_mode(dwc, testmode);
531557 spin_unlock_irqrestore(&dwc->lock, flags);
532558
559+ pm_runtime_put_sync(dwc->dev);
560+
533561 return count;
534562 }
535563
@@ -548,12 +576,18 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) · 12 unmodified lines
548576 enum dwc3_link_state state;
549577 u32 reg;
550578 u8 speed;
579+ int ret;
580+
581+ ret = pm_runtime_resume_and_get(dwc->dev);
582+ if (ret < 0)
583+ return ret;
551584
552585 spin_lock_irqsave(&dwc->lock, flags);
553586 reg = dwc3_readl(dwc->regs, DWC3_GSTS);
554587 if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) {
555588 seq_puts(s, "Not available\n");
556589 spin_unlock_irqrestore(&dwc->lock, flags);
590+ pm_runtime_put_sync(dwc->dev);
557591 return 0;
558592 }
559593
@@ -566,6 +600,8 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) · 6 unmodified lines
566600 dwc3_gadget_hs_link_string(state));
567601 spin_unlock_irqrestore(&dwc->lock, flags);
568602
603+ pm_runtime_put_sync(dwc->dev);
604+
569605 return 0;
570606 }
571607
@@ -584,6 +620,7 @@ static ssize_t dwc3_link_state_write(struct file *file, · 12 unmodified lines
584620 char buf[32];
585621 u32 reg;
586622 u8 speed;
623+ int ret;
587624
588625 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
589626 return -EFAULT;
@@ -603,10 +640,15 @@ static ssize_t dwc3_link_state_write(struct file *file, · 13 unmodified lines
603640 else
604641 return -EINVAL;
605642
643+ ret = pm_runtime_resume_and_get(dwc->dev);
644+ if (ret < 0)
645+ return ret;
646+
606647 spin_lock_irqsave(&dwc->lock, flags);
607648 reg = dwc3_readl(dwc->regs, DWC3_GSTS);
608649 if (DWC3_GSTS_CURMOD(reg) != DWC3_GSTS_CURMOD_DEVICE) {
609650 spin_unlock_irqrestore(&dwc->lock, flags);
651+ pm_runtime_put_sync(dwc->dev);
610652 return -EINVAL;
611653 }
612654
@@ -616,12 +658,15 @@ static ssize_t dwc3_link_state_write(struct file *file, · 3 unmodified lines
616658 if (speed < DWC3_DSTS_SUPERSPEED &&
617659 state != DWC3_LINK_STATE_RECOV) {
618660 spin_unlock_irqrestore(&dwc->lock, flags);
661+ pm_runtime_put_sync(dwc->dev);
619662 return -EINVAL;
620663 }
621664
622665 dwc3_gadget_set_link_state(dwc, state);
623666 spin_unlock_irqrestore(&dwc->lock, flags);
624667
668+ pm_runtime_put_sync(dwc->dev);
669+
625670 return count;
626671 }
627672
@@ -645,6 +690,11 @@ static int dwc3_tx_fifo_size_show(struct seq_file *s, void *unused) · 17 unmodified lines
645690 unsigned long flags;
646691 u32 mdwidth;
647692 u32 val;
693+ int ret;
694+
695+ ret = pm_runtime_resume_and_get(dwc->dev);
696+ if (ret < 0)
697+ return ret;
648698
649699 spin_lock_irqsave(&dwc->lock, flags);
650700 val = dwc3_core_fifo_space(dep, DWC3_TXFIFO);
@@ -657,6 +707,8 @@ static int dwc3_tx_fifo_size_show(struct seq_file *s, void *unused) · 6 unmodified lines
657707 seq_printf(s, "%u\n", val);
658708 spin_unlock_irqrestore(&dwc->lock, flags);
659709
710+ pm_runtime_put_sync(dwc->dev);
711+
660712 return 0;
661713 }
662714
@@ -667,6 +719,11 @@ static int dwc3_rx_fifo_size_show(struct seq_file *s, void *unused) · 4 unmodified lines
667719 unsigned long flags;
668720 u32 mdwidth;
669721 u32 val;
722+ int ret;
723+
724+ ret = pm_runtime_resume_and_get(dwc->dev);
725+ if (ret < 0)
726+ return ret;
670727
671728 spin_lock_irqsave(&dwc->lock, flags);
672729 val = dwc3_core_fifo_space(dep, DWC3_RXFIFO);
@@ -679,6 +736,8 @@ static int dwc3_rx_fifo_size_show(struct seq_file *s, void *unused) · 6 unmodified lines
679736 seq_printf(s, "%u\n", val);
680737 spin_unlock_irqrestore(&dwc->lock, flags);
681738
739+ pm_runtime_put_sync(dwc->dev);
740+
682741 return 0;
683742 }
684743
@@ -688,12 +747,19 @@ static int dwc3_tx_request_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines
688747 struct dwc3 *dwc = dep->dwc;
689748 unsigned long flags;
690749 u32 val;
750+ int ret;
751+
752+ ret = pm_runtime_resume_and_get(dwc->dev);
753+ if (ret < 0)
754+ return ret;
691755
692756 spin_lock_irqsave(&dwc->lock, flags);
693757 val = dwc3_core_fifo_space(dep, DWC3_TXREQQ);
694758 seq_printf(s, "%u\n", val);
695759 spin_unlock_irqrestore(&dwc->lock, flags);
696760
761+ pm_runtime_put_sync(dwc->dev);
762+
697763 return 0;
698764 }
699765
@@ -703,12 +769,19 @@ static int dwc3_rx_request_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines
703769 struct dwc3 *dwc = dep->dwc;
704770 unsigned long flags;
705771 u32 val;
772+ int ret;
773+
774+ ret = pm_runtime_resume_and_get(dwc->dev);
775+ if (ret < 0)
776+ return ret;
706777
707778 spin_lock_irqsave(&dwc->lock, flags);
708779 val = dwc3_core_fifo_space(dep, DWC3_RXREQQ);
709780 seq_printf(s, "%u\n", val);
710781 spin_unlock_irqrestore(&dwc->lock, flags);
711782
783+ pm_runtime_put_sync(dwc->dev);
784+
712785 return 0;
713786 }
714787
@@ -718,12 +791,19 @@ static int dwc3_rx_info_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines
718791 struct dwc3 *dwc = dep->dwc;
719792 unsigned long flags;
720793 u32 val;
794+ int ret;
795+
796+ ret = pm_runtime_resume_and_get(dwc->dev);
797+ if (ret < 0)
798+ return ret;
721799
722800 spin_lock_irqsave(&dwc->lock, flags);
723801 val = dwc3_core_fifo_space(dep, DWC3_RXINFOQ);
724802 seq_printf(s, "%u\n", val);
725803 spin_unlock_irqrestore(&dwc->lock, flags);
726804
805+ pm_runtime_put_sync(dwc->dev);
806+
727807 return 0;
728808 }
729809
@@ -733,12 +813,19 @@ static int dwc3_descriptor_fetch_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines
733813 struct dwc3 *dwc = dep->dwc;
734814 unsigned long flags;
735815 u32 val;
816+ int ret;
817+
818+ ret = pm_runtime_resume_and_get(dwc->dev);
819+ if (ret < 0)
820+ return ret;
736821
737822 spin_lock_irqsave(&dwc->lock, flags);
738823 val = dwc3_core_fifo_space(dep, DWC3_DESCFETCHQ);
739824 seq_printf(s, "%u\n", val);
740825 spin_unlock_irqrestore(&dwc->lock, flags);
741826
827+ pm_runtime_put_sync(dwc->dev);
828+
742829 return 0;
743830 }
744831
@@ -748,12 +835,19 @@ static int dwc3_event_queue_show(struct seq_file *s, void *unused) · 3 unmodified lines
748835 struct dwc3 *dwc = dep->dwc;
749836 unsigned long flags;
750837 u32 val;
838+ int ret;
839+
840+ ret = pm_runtime_resume_and_get(dwc->dev);
841+ if (ret < 0)
842+ return ret;
751843
752844 spin_lock_irqsave(&dwc->lock, flags);
753845 val = dwc3_core_fifo_space(dep, DWC3_EVENTQ);
754846 seq_printf(s, "%u\n", val);
755847 spin_unlock_irqrestore(&dwc->lock, flags);
756848
849+ pm_runtime_put_sync(dwc->dev);
850+
757851 return 0;
758852 }
759853
@@ -798,6 +892,11 @@ static int dwc3_trb_ring_show(struct seq_file *s, void *unused) · 38 unmodified lines
798892 struct dwc3 *dwc = dep->dwc;
799893 unsigned long flags;
800894 int i;
895+ int ret;
896+
897+ ret = pm_runtime_resume_and_get(dwc->dev);
898+ if (ret < 0)
899+ return ret;
801900
802901 spin_lock_irqsave(&dwc->lock, flags);
803902 if (dep->number <= 1) {
@@ -827,6 +926,8 @@ static int dwc3_trb_ring_show(struct seq_file *s, void *unused) · 23 unmodified lines
827926 out:
828927 spin_unlock_irqrestore(&dwc->lock, flags);
829928
929+ pm_runtime_put_sync(dwc->dev);
930+
830931 return 0;
831932 }
832933
@@ -839,6 +940,11 @@ static int dwc3_ep_info_register_show(struct seq_file *s, void *unused) · 6 unmodified lines
839940 u32 lower_32_bits;
840941 u32 upper_32_bits;
841942 u32 reg;
943+ int ret;
944+
945+ ret = pm_runtime_resume_and_get(dwc->dev);
946+ if (ret < 0)
947+ return ret;
842948
843949 spin_lock_irqsave(&dwc->lock, flags);
844950 reg = DWC3_GDBGLSPMUX_EPSELECT(dep->number);
@@ -851,6 +957,8 @@ static int dwc3_ep_info_register_show(struct seq_file *s, void *unused) · 6 unmodified lines
851957 seq_printf(s, "0x%016llx\n", ep_info);
852958 spin_unlock_irqrestore(&dwc->lock, flags);
853959
960+ pm_runtime_put_sync(dwc->dev);
961+
854962 return 0;
855963 }
856964
@@ -910,6 +1018,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc) · 53 unmodified lines
9101018 dwc->regset->regs = dwc3_regs;
9111019 dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
9121020 dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START;
1021+ dwc->regset->dev = dwc->dev;
9131022
9141023 root = debugfs_create_dir(dev_name(dwc->dev), usb_debug_root);
9151024 dwc->debug_root = root;
drivers/usb/dwc3/gadget.c+45−34
@@ -2440,6 +2440,7 @@ static int dwc3_gadget_func_wakeup(struct usb_gadget *g, int intf_id) · 2439 unmodified lines
24402440 return -EINVAL;
24412441 }
24422442 dwc3_resume_gadget(dwc);
2443+ dwc->suspended = false;
24432444 dwc->link_state = DWC3_LINK_STATE_U0;
24442445 }
24452446
@@ -2699,6 +2700,21 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc) · 253 unmodified lines
26992700 return ret;
27002701 }
27012702
2703+static int dwc3_gadget_soft_connect(struct dwc3 *dwc)
2704+{
2705+ /*
2706+ * In the Synopsys DWC_usb31 1.90a programming guide section
2707+ * 4.1.9, it specifies that for a reconnect after a
2708+ * device-initiated disconnect requires a core soft reset
2709+ * (DCTL.CSftRst) before enabling the run/stop bit.
2710+ */
2711+ dwc3_core_soft_reset(dwc);
2712+
2713+ dwc3_event_buffers_setup(dwc);
2714+ __dwc3_gadget_start(dwc);
2715+ return dwc3_gadget_run_stop(dwc, true);
2716+}
2717+
27022718 static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
27032719 {
27042720 struct dwc3 *dwc = gadget_to_dwc(g);
@@ -2737,21 +2753,10 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) · 32 unmodified lines
27372753
27382754 synchronize_irq(dwc->irq_gadget);
27392755
2740− if (!is_on) {
2756+ if (!is_on)
27412757 ret = dwc3_gadget_soft_disconnect(dwc);
2742− } else {
2743− /*
2744− * In the Synopsys DWC_usb31 1.90a programming guide section
2745− * 4.1.9, it specifies that for a reconnect after a
2746− * device-initiated disconnect requires a core soft reset
2747− * (DCTL.CSftRst) before enabling the run/stop bit.
2748− */
2749− dwc3_core_soft_reset(dwc);
2750−
2751− dwc3_event_buffers_setup(dwc);
2752− __dwc3_gadget_start(dwc);
2753− ret = dwc3_gadget_run_stop(dwc, true);
2754− }
2758+ else
2759+ ret = dwc3_gadget_soft_connect(dwc);
27552760
27562761 pm_runtime_put(dwc->dev);
27572762
@@ -3938,6 +3943,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) · 1180 unmodified lines
39383943 {
39393944 int reg;
39403945
3946+ dwc->suspended = false;
3947+
39413948 dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET);
39423949
39433950 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
@@ -3962,6 +3969,8 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) · 18 unmodified lines
39623969 {
39633970 u32 reg;
39643971
3972+ dwc->suspended = false;
3973+
39653974 /*
39663975 * Ideally, dwc3_reset_gadget() would trigger the function
39673976 * drivers to stop any active transfers through ep disable.
@@ -4180,6 +4189,8 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) · 212 unmodified lines
41804189
41814190 static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc, unsigned int evtinfo)
41824191 {
4192+ dwc->suspended = false;
4193+
41834194 /*
41844195 * TODO take core out of low power mode when that's
41854196 * implemented.
@@ -4277,6 +4288,7 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, · 91 unmodified lines
42774288 if (dwc->gadget->wakeup_armed) {
42784289 dwc3_gadget_enable_linksts_evts(dwc, false);
42794290 dwc3_resume_gadget(dwc);
4291+ dwc->suspended = false;
42804292 }
42814293 break;
42824294 case DWC3_LINK_STATE_U1:
@@ -4303,8 +4315,10 @@ static void dwc3_gadget_suspend_interrupt(struct dwc3 *dwc, · 20 unmodified lines
43034315 {
43044316 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
43054317
4306− if (dwc->link_state != next && next == DWC3_LINK_STATE_U3)
4318+ if (!dwc->suspended && next == DWC3_LINK_STATE_U3) {
4319+ dwc->suspended = true;
43074320 dwc3_suspend_gadget(dwc);
4321+ }
43084322
43094323 dwc->link_state = next;
43104324 }
@@ -4655,42 +4669,39 @@ void dwc3_gadget_exit(struct dwc3 *dwc) · 344 unmodified lines
46554669 int dwc3_gadget_suspend(struct dwc3 *dwc)
46564670 {
46574671 unsigned long flags;
4672+ int ret;
46584673
46594674 if (!dwc->gadget_driver)
46604675 return 0;
46614676
4662− dwc3_gadget_run_stop(dwc, false);
4677+ ret = dwc3_gadget_soft_disconnect(dwc);
4678+ if (ret)
4679+ goto err;
46634680
46644681 spin_lock_irqsave(&dwc->lock, flags);
46654682 dwc3_disconnect_gadget(dwc);
4666− __dwc3_gadget_stop(dwc);
46674683 spin_unlock_irqrestore(&dwc->lock, flags);
46684684
46694685 return 0;
4686+
4687+err:
4688+ /*
4689+ * Attempt to reset the controller's state. Likely no
4690+ * communication can be established until the host
4691+ * performs a port reset.
4692+ */
4693+ if (dwc->softconnect)
4694+ dwc3_gadget_soft_connect(dwc);
4695+
4696+ return ret;
46704697 }
46714698
46724699 int dwc3_gadget_resume(struct dwc3 *dwc)
46734700 {
4674− int ret;
4675−
46764701 if (!dwc->gadget_driver || !dwc->softconnect)
46774702 return 0;
46784703
4679− ret = __dwc3_gadget_start(dwc);
4680− if (ret < 0)
4681− goto err0;
4682−
4683− ret = dwc3_gadget_run_stop(dwc, true);
4684− if (ret < 0)
4685− goto err1;
4686−
4687− return 0;
4688−
4689−err1:
4690− __dwc3_gadget_stop(dwc);
4691−
4692−err0:
4693− return ret;
4704+ return dwc3_gadget_soft_connect(dwc);
46944705 }
46954706
46964707 void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
drivers/usb/gadget/function/u_ether.c+3−0
@@ -17,6 +17,7 @@ · 16 unmodified lines
1717 #include <linux/etherdevice.h>
1818 #include <linux/ethtool.h>
1919 #include <linux/if_vlan.h>
20+#include <linux/string_helpers.h>
2021 #include <linux/usb/composite.h>
2122
2223 #include "u_ether.h"
@@ -965,6 +966,8 @@ int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len) · 942 unmodified lines
965966 dev = netdev_priv(net);
966967 snprintf(host_addr, len, "%pm", dev->host_mac);
967968
969+ string_upper(host_addr, host_addr);
970+
968971 return strlen(host_addr);
969972 }
970973 EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc);
drivers/usb/gadget/udc/core.c+44−107
@@ -37,10 +37,6 @@ static const struct bus_type gadget_bus_type; · 36 unmodified lines
3737 * @vbus: for udcs who care about vbus status, this value is real vbus status;
3838 * for udcs who do not care about vbus status, this value is always true
3939 * @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.
4440 *
4541 * This represents the internal data structure which is used by the UDC-class
4642 * to hold information about udc driver and gadget together.
@@ -52,7 +48,6 @@ struct usb_udc { · 5 unmodified lines
5248 struct list_head list;
5349 bool vbus;
5450 bool started;
55− struct mutex connect_lock;
5651 };
5752
5853 static struct class *udc_class;
@@ -692,9 +687,17 @@ out: · 633 unmodified lines
692687 }
693688 EXPORT_SYMBOL_GPL(usb_gadget_vbus_disconnect);
694689
695−/* Internal version of usb_gadget_connect needs to be called with connect_lock held. */
696−static int usb_gadget_connect_locked(struct usb_gadget *gadget)
697− __must_hold(&gadget->udc->connect_lock)
690+/**
691+ * usb_gadget_connect - software-controlled connect to USB host
692+ * @gadget:the peripheral being connected
693+ *
694+ * Enables the D+ (or potentially D-) pullup. The host will start
695+ * enumerating this gadget when the pullup is active and a VBUS session
696+ * is active (the link is powered).
697+ *
698+ * Returns zero on success, else negative errno.
699+ */
700+int usb_gadget_connect(struct usb_gadget *gadget)
698701 {
699702 int ret = 0;
700703
@@ -703,15 +706,10 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget) · 2 unmodified lines
703706 goto out;
704707 }
705708
706− if (gadget->connected)
707− goto out;
708−
709− if (gadget->deactivated || !gadget->udc->started) {
709+ if (gadget->deactivated) {
710710 /*
711711 * If gadget is deactivated we only save new state.
712712 * Gadget will be connected automatically after activation.
713− *
714− * udc first needs to be started before gadget can be pulled up.
715713 */
716714 gadget->connected = true;
717715 goto out;
@@ -726,32 +724,22 @@ out: · 8 unmodified lines
726724
727725 return ret;
728726 }
727+EXPORT_SYMBOL_GPL(usb_gadget_connect);
729728
730729 /**
731− * usb_gadget_connect - software-controlled connect to USB host
732− * @gadget:the peripheral being connected
730+ * usb_gadget_disconnect - software-controlled disconnect from USB host
731+ * @gadget:the peripheral being disconnected
733732 *
734− * Enables the D+ (or potentially D-) pullup. The host will start
735− * enumerating this gadget when the pullup is active and a VBUS session
736− * is active (the link is powered).
733+ * Disables the D+ (or potentially D-) pullup, which the host may see
734+ * as a disconnect (when a VBUS session is active). Not all systems
735+ * support software pullup controls.
736+ *
737+ * Following a successful disconnect, invoke the ->disconnect() callback
738+ * for the current gadget driver so that UDC drivers don't need to.
737739 *
738740 * Returns zero on success, else negative errno.
739741 */
740−int usb_gadget_connect(struct usb_gadget *gadget)
741−{
742− int ret;
743−
744− mutex_lock(&gadget->udc->connect_lock);
745− ret = usb_gadget_connect_locked(gadget);
746− mutex_unlock(&gadget->udc->connect_lock);
747−
748− return ret;
749−}
750−EXPORT_SYMBOL_GPL(usb_gadget_connect);
751−
752−/* Internal version of usb_gadget_disconnect needs to be called with connect_lock held. */
753−static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
754− __must_hold(&gadget->udc->connect_lock)
742+int usb_gadget_disconnect(struct usb_gadget *gadget)
755743 {
756744 int ret = 0;
757745
@@ -763,12 +751,10 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget) · 5 unmodified lines
763751 if (!gadget->connected)
764752 goto out;
765753
766− if (gadget->deactivated || !gadget->udc->started) {
754+ if (gadget->deactivated) {
767755 /*
768756 * If gadget is deactivated we only save new state.
769757 * Gadget will stay disconnected after activation.
770− *
771− * udc should have been started before gadget being pulled down.
772758 */
773759 gadget->connected = false;
774760 goto out;
@@ -788,30 +774,6 @@ out: · 13 unmodified lines
788774
789775 return ret;
790776 }
791−
792−/**
793− * usb_gadget_disconnect - software-controlled disconnect from USB host
794− * @gadget:the peripheral being disconnected
795− *
796− * Disables the D+ (or potentially D-) pullup, which the host may see
797− * as a disconnect (when a VBUS session is active). Not all systems
798− * support software pullup controls.
799− *
800− * Following a successful disconnect, invoke the ->disconnect() callback
801− * for the current gadget driver so that UDC drivers don't need to.
802− *
803− * Returns zero on success, else negative errno.
804− */
805−int usb_gadget_disconnect(struct usb_gadget *gadget)
806−{
807− int ret;
808−
809− mutex_lock(&gadget->udc->connect_lock);
810− ret = usb_gadget_disconnect_locked(gadget);
811− mutex_unlock(&gadget->udc->connect_lock);
812−
813− return ret;
814−}
815777 EXPORT_SYMBOL_GPL(usb_gadget_disconnect);
816778
817779 /**
@@ -832,11 +794,10 @@ int usb_gadget_deactivate(struct usb_gadget *gadget) · 14 unmodified lines
832794 if (gadget->deactivated)
833795 goto out;
834796
835− mutex_lock(&gadget->udc->connect_lock);
836797 if (gadget->connected) {
837− ret = usb_gadget_disconnect_locked(gadget);
798+ ret = usb_gadget_disconnect(gadget);
838799 if (ret)
839− goto unlock;
800+ goto out;
840801
841802 /*
842803 * If gadget was being connected before deactivation, we want
@@ -846,8 +807,6 @@ int usb_gadget_deactivate(struct usb_gadget *gadget) · 3 unmodified lines
846807 }
847808 gadget->deactivated = true;
848809
849−unlock:
850− mutex_unlock(&gadget->udc->connect_lock);
851810 out:
852811 trace_usb_gadget_deactivate(gadget, ret);
853812
@@ -871,7 +830,6 @@ int usb_gadget_activate(struct usb_gadget *gadget) · 17 unmodified lines
871830 if (!gadget->deactivated)
872831 goto out;
873832
874− mutex_lock(&gadget->udc->connect_lock);
875833 gadget->deactivated = false;
876834
877835 /*
@@ -879,8 +837,7 @@ int usb_gadget_activate(struct usb_gadget *gadget) · 1 unmodified line
879837 * while it was being deactivated, we call usb_gadget_connect().
880838 */
881839 if (gadget->connected)
882− ret = usb_gadget_connect_locked(gadget);
883− mutex_unlock(&gadget->udc->connect_lock);
840+ ret = usb_gadget_connect(gadget);
884841
885842 out:
886843 trace_usb_gadget_activate(gadget, ret);
@@ -1121,13 +1078,12 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state); · 234 unmodified lines
11211078
11221079 /* ------------------------------------------------------------------------- */
11231080
1124−/* Acquire connect_lock before calling this function. */
1125−static void usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock)
1081+static void usb_udc_connect_control(struct usb_udc *udc)
11261082 {
1127− if (udc->vbus && udc->started)
1128− usb_gadget_connect_locked(udc->gadget);
1083+ if (udc->vbus)
1084+ usb_gadget_connect(udc->gadget);
11291085 else
1130− usb_gadget_disconnect_locked(udc->gadget);
1086+ usb_gadget_disconnect(udc->gadget);
11311087 }
11321088
11331089 /**
@@ -1143,12 +1099,10 @@ void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) · 9 unmodified lines
11431099 {
11441100 struct usb_udc *udc = gadget->udc;
11451101
1146− mutex_lock(&udc->connect_lock);
11471102 if (udc) {
11481103 udc->vbus = status;
1149− usb_udc_connect_control_locked(udc);
1104+ usb_udc_connect_control(udc);
11501105 }
1151− mutex_unlock(&udc->connect_lock);
11521106 }
11531107 EXPORT_SYMBOL_GPL(usb_udc_vbus_handler);
11541108
@@ -1170,7 +1124,7 @@ void usb_gadget_udc_reset(struct usb_gadget *gadget, · 15 unmodified lines
11701124 EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
11711125
11721126 /**
1173− * usb_gadget_udc_start_locked - tells usb device controller to start up
1127+ * usb_gadget_udc_start - tells usb device controller to start up
11741128 * @udc: The UDC to be started
11751129 *
11761130 * This call is issued by the UDC Class driver when it's about
@@ -1181,11 +1135,8 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset); · 4 unmodified lines
11811135 * necessary to have it powered on.
11821136 *
11831137 * Returns zero on success, else negative errno.
1184− *
1185− * Caller should acquire connect_lock before invoking this function.
11861138 */
1187−static inline int usb_gadget_udc_start_locked(struct usb_udc *udc)
1188− __must_hold(&udc->connect_lock)
1139+static inline int usb_gadget_udc_start(struct usb_udc *udc)
11891140 {
11901141 int ret;
11911142
@@ -1202,7 +1153,7 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) · 10 unmodified lines
12021153 }
12031154
12041155 /**
1205− * usb_gadget_udc_stop_locked - tells usb device controller we don't need it anymore
1156+ * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
12061157 * @udc: The UDC to be stopped
12071158 *
12081159 * This call is issued by the UDC Class driver after calling
@@ -1211,11 +1162,8 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) · 2 unmodified lines
12111162 * The details are implementation specific, but it can go as
12121163 * far as powering off UDC completely and disable its data
12131164 * line pullups.
1214− *
1215− * Caller should acquire connect lock before invoking this function.
12161165 */
1217−static inline void usb_gadget_udc_stop_locked(struct usb_udc *udc)
1218− __must_hold(&udc->connect_lock)
1166+static inline void usb_gadget_udc_stop(struct usb_udc *udc)
12191167 {
12201168 if (!udc->started) {
12211169 dev_err(&udc->dev, "UDC had already stopped\n");
@@ -1374,7 +1322,6 @@ int usb_add_gadget(struct usb_gadget *gadget) · 152 unmodified lines
13741322
13751323 udc->gadget = gadget;
13761324 gadget->udc = udc;
1377− mutex_init(&udc->connect_lock);
13781325
13791326 udc->started = false;
13801327
@@ -1576,15 +1523,11 @@ static int gadget_bind_driver(struct device *dev) · 195 unmodified lines
15761523 if (ret)
15771524 goto err_bind;
15781525
1579− mutex_lock(&udc->connect_lock);
1580− ret = usb_gadget_udc_start_locked(udc);
1581− if (ret) {
1582− mutex_unlock(&udc->connect_lock);
1526+ ret = usb_gadget_udc_start(udc);
1527+ if (ret)
15831528 goto err_start;
1584− }
15851529 usb_gadget_enable_async_callbacks(udc);
1586− usb_udc_connect_control_locked(udc);
1587− mutex_unlock(&udc->connect_lock);
1530+ usb_udc_connect_control(udc);
15881531
15891532 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
15901533 return 0;
@@ -1615,14 +1558,12 @@ static void gadget_unbind_driver(struct device *dev) · 24 unmodified lines
16151558
16161559 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
16171560
1618− mutex_lock(&udc->connect_lock);
1619− usb_gadget_disconnect_locked(gadget);
1561+ usb_gadget_disconnect(gadget);
16201562 usb_gadget_disable_async_callbacks(udc);
16211563 if (gadget->irq)
16221564 synchronize_irq(gadget->irq);
16231565 udc->driver->unbind(gadget);
1624− usb_gadget_udc_stop_locked(udc);
1625− mutex_unlock(&udc->connect_lock);
1566+ usb_gadget_udc_stop(udc);
16261567
16271568 mutex_lock(&udc_lock);
16281569 driver->is_bound = false;
@@ -1708,15 +1649,11 @@ static ssize_t soft_connect_store(struct device *dev, · 79 unmodified lines
17081649 }
17091650
17101651 if (sysfs_streq(buf, "connect")) {
1711− mutex_lock(&udc->connect_lock);
1712− usb_gadget_udc_start_locked(udc);
1713− usb_gadget_connect_locked(udc->gadget);
1714− mutex_unlock(&udc->connect_lock);
1652+ usb_gadget_udc_start(udc);
1653+ usb_gadget_connect(udc->gadget);
17151654 } else if (sysfs_streq(buf, "disconnect")) {
1716− mutex_lock(&udc->connect_lock);
1717− usb_gadget_disconnect_locked(udc->gadget);
1718− usb_gadget_udc_stop_locked(udc);
1719− mutex_unlock(&udc->connect_lock);
1655+ usb_gadget_disconnect(udc->gadget);
1656+ usb_gadget_udc_stop(udc);
17201657 } else {
17211658 dev_err(dev, "unsupported command '%s'\n", buf);
17221659 ret = -EINVAL;
drivers/usb/host/uhci-pci.c+6−4
@@ -119,11 +119,13 @@ static int uhci_pci_init(struct usb_hcd *hcd) · 118 unmodified lines
119119
120120 uhci->rh_numports = uhci_count_ports(hcd);
121121
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.)
125126 */
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)
127129 uhci->oc_low = 1;
128130
129131 /* HP's server management chip requires a longer port reset delay. */
drivers/usb/host/xhci-pci.c+10−2
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/module.h>
1414 #include <linux/acpi.h>
1515 #include <linux/reset.h>
16+#include <linux/suspend.h>
1617
1718 #include "xhci.h"
1819 #include "xhci-trace.h"
@@ -387,7 +388,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) · 368 unmodified lines
387388
388389 if (pdev->vendor == PCI_VENDOR_ID_AMD &&
389390 pdev->device == PCI_DEVICE_ID_AMD_RENOIR_XHCI)
390− xhci->quirks |= XHCI_BROKEN_D3COLD;
391+ xhci->quirks |= XHCI_BROKEN_D3COLD_S2I;
391392
392393 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
393394 xhci->quirks |= XHCI_LPM_SUPPORT;
@@ -801,9 +802,16 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) · 407 unmodified lines
801802 * Systems with the TI redriver that loses port status change events
802803 * need to have the registers polled during D3, so avoid D3cold.
803804 */
804− if (xhci->quirks & (XHCI_COMP_MODE_QUIRK | XHCI_BROKEN_D3COLD))
805+ if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
805806 pci_d3cold_disable(pdev);
806807
808+#ifdef CONFIG_SUSPEND
809+ /* d3cold is broken, but only when s2idle is used */
810+ if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
811+ xhci->quirks & (XHCI_BROKEN_D3COLD_S2I))
812+ pci_d3cold_disable(pdev);
813+#endif
814+
807815 if (xhci->quirks & XHCI_PME_STUCK_QUIRK)
808816 xhci_pme_quirk(hcd);
809817
drivers/usb/host/xhci-ring.c+28−1
@@ -276,6 +276,26 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, · 275 unmodified lines
276276 trace_xhci_inc_enq(ring);
277277 }
278278
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+
279299 /*
280300 * Check to see if there's room to enqueue num_trbs on the ring and make sure
281301 * enqueue pointer will not advance into dequeue segment. See rules above.
@@ -2140,6 +2160,7 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 1858 unmodified lines
21402160 u32 trb_comp_code)
21412161 {
21422162 struct xhci_ep_ctx *ep_ctx;
2163+ int trbs_freed;
21432164
21442165 ep_ctx = xhci_get_ep_ctx(xhci, ep->vdev->out_ctx, ep->ep_index);
21452166
@@ -2209,9 +2230,15 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, · 63 unmodified lines
22092230 }
22102231
22112232 /* Update ring dequeue pointer */
2233+ trbs_freed = xhci_num_trbs_to(ep_ring->deq_seg, ep_ring->dequeue,
2234+ td->last_trb_seg, td->last_trb,
2235+ ep_ring->num_segs);
2236+ if (trbs_freed < 0)
2237+ xhci_dbg(xhci, "Failed to count freed trbs at TD finish\n");
2238+ else
2239+ ep_ring->num_trbs_free += trbs_freed;
22122240 ep_ring->dequeue = td->last_trb;
22132241 ep_ring->deq_seg = td->last_trb_seg;
2214− ep_ring->num_trbs_free += td->num_trbs - 1;
22152242 inc_deq(xhci, ep_ring);
22162243
22172244 return xhci_td_cleanup(xhci, td, ep_ring, td->status);
drivers/usb/host/xhci.h+1−1
@@ -1901,7 +1901,7 @@ struct xhci_hcd { · 1900 unmodified lines
19011901 #define XHCI_DISABLE_SPARSE BIT_ULL(38)
19021902 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39)
19031903 #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)
19051905 #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42)
19061906 #define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(43)
19071907 #define XHCI_RESET_TO_DEFAULT BIT_ULL(44)
drivers/usb/storage/scsiglue.c+21−7
@@ -406,22 +406,25 @@ static DEF_SCSI_QCMD(queuecommand) · 405 unmodified lines
406406 ***********************************************************************/
407407
408408 /* 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)
410410 {
411− struct us_data *us = host_to_us(srb->device->host);
412−
413− usb_stor_dbg(us, "%s called\n", __func__);
414−
415411 /*
416412 * us->srb together with the TIMED_OUT, RESETTING, and ABORTING
417413 * bits are protected by the host lock.
418414 */
419415 scsi_lock(us_to_host(us));
420416
421− /* Is this command still active? */
422− if (us->srb != srb) {
417+ /* is there any active pending command to abort ? */
418+ if (!us->srb) {
423419 scsi_unlock(us_to_host(us));
424420 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");
425428 return FAILED;
426429 }
427430
@@ -444,6 +447,14 @@ static int command_abort(struct scsi_cmnd *srb) · 16 unmodified lines
444447 return SUCCESS;
445448 }
446449
450+static int command_abort(struct scsi_cmnd *srb)
451+{
452+ struct us_data *us = host_to_us(srb->device->host);
453+
454+ usb_stor_dbg(us, "%s called\n", __func__);
455+ return command_abort_matching(us, srb);
456+}
457+
447458 /*
448459 * This invokes the transport reset mechanism to reset the state of the
449460 * device
@@ -455,6 +466,9 @@ static int device_reset(struct scsi_cmnd *srb) · 5 unmodified lines
455466
456467 usb_stor_dbg(us, "%s called\n", __func__);
457468
469+ /* abort any pending command before reset */
470+ command_abort_matching(us, NULL);
471+
458472 /* lock the device pointers and do the reset */
459473 mutex_lock(&(us->dev_mutex));
460474 result = us->transport_reset(us);
drivers/usb/typec/altmodes/displayport.c+4−0
@@ -516,6 +516,10 @@ static ssize_t pin_assignment_show(struct device *dev, · 515 unmodified lines
516516
517517 mutex_unlock(&dp->lock);
518518
519+ /* get_current_pin_assignments can return 0 when no matching pin assignments are found */
520+ if (len == 0)
521+ len++;
522+
519523 buf[len - 1] = '\n';
520524 return len;
521525 }
drivers/usb/typec/tipd/core.c+3−0
@@ -886,6 +886,9 @@ static void tps6598x_remove(struct i2c_client *client) · 885 unmodified lines
886886 {
887887 struct tps6598x *tps = i2c_get_clientdata(client);
888888
889+ if (!client->irq)
890+ cancel_delayed_work_sync(&tps->wq_poll);
891+
889892 tps6598x_disconnect(tps, 0);
890893 typec_unregister_port(tps->port);
891894 usb_role_switch_put(tps->role_sw);
include/linux/device/class.h+1−0
@@ -74,6 +74,7 @@ struct class { · 73 unmodified lines
7474 struct class_dev_iter {
7575 struct klist_iter ki;
7676 const struct device_type *type;
77+ struct subsys_private *sp;
7778 };
7879
7980 int __must_check class_register(const struct class *class);
include/linux/usb/composite.h+1−1
@@ -443,7 +443,7 @@ static inline struct usb_composite_driver *to_cdriver( · 442 unmodified lines
443443 * @bcd_webusb_version: 0x0100 by default, WebUSB specification version
444444 * @b_webusb_vendor_code: 0x0 by default, vendor code for WebUSB
445445 * @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
447447 * @os_desc_config: the configuration to be used with OS descriptors
448448 * @setup_pending: true when setup request is queued but not completed
449449 * @os_desc_pending: true when os_desc request is queued but not completed