History

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

Pull USB fixes from Greg KH: "Here are a bunch of small USB fixes for reported problems and regressions for 6.9-rc2. Included in here are: - deadlock fixes for long-suffering issues - USB phy driver revert for reported problem - typec fixes for reported problems - duplicate id in dwc3 dropped - dwc2 driver fixes - udc driver warning fix - cdc-wdm race bugfix - other tiny USB bugfixes All of these have been in linux-next this past week with no reported issues" * tag 'usb-6.9-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (26 commits) USB: core: Fix deadlock in port "disable" sysfs attribute USB: core: Add hub_get() and hub_put() routines usb: typec: ucsi: Check capabilities before cable and identity discovery usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset usb: typec: ucsi_acpi: Refactor and fix DELL quirk usb: typec: ucsi: Ack unsupported commands usb: typec: ucsi: Check for notifications after init usb: typec: ucsi: Clear EVENT_PENDING under PPM lock usb: typec: Return size of buffer if pd_set operation succeeds usb: udc: remove warning when queue disabled ep usb: dwc3: pci: Drop duplicate ID usb: dwc3: Properly set system wakeup Revert "usb: phy: generic: Get the vbus supply" usb: cdc-wdm: close race between read and workqueue usb: dwc2: gadget: LPM flow fix usb: dwc2: gadget: Fix exiting from clock gating usb: dwc2: host: Fix ISOC flow in DDMA mode usb: dwc2: host: Fix remote wakeup from hibernation usb: dwc2: host: Fix hibernation flow USB: core: Fix deadlock in usb_deauthorize_interface() ...

Linus Torvalds committed 2 years ago

Commit ff789a22 parents 4e6e422 f4d196027 files · +376 −160Browse files

Unified · Split

27 files
  1. drivers/usb/class/cdc-wdm.c +5 −1
  2. drivers/usb/core/hub.c +16 −7
  3. drivers/usb/core/hub.h +2 −0
  4. drivers/usb/core/port.c +34 −4
  5. drivers/usb/core/sysfs.c +13 −3
  6. drivers/usb/dwc2/core.h +14 −0
  7. drivers/usb/dwc2/core_intr.c +48 −24
  8. drivers/usb/dwc2/gadget.c +10 −0
  9. drivers/usb/dwc2/hcd.c +40 −9
  10. drivers/usb/dwc2/hcd_ddma.c +11 −6
  11. drivers/usb/dwc2/hw.h +1 −1
  12. drivers/usb/dwc2/platform.c +1 −1
  13. drivers/usb/dwc3/core.c +2 −0
  14. drivers/usb/dwc3/core.h +2 −0
  15. drivers/usb/dwc3/dwc3-pci.c +0 −2
  16. drivers/usb/dwc3/gadget.c +10 −0
  17. drivers/usb/dwc3/host.c +11 −0
  18. drivers/usb/gadget/udc/core.c +3 −1
  19. drivers/usb/misc/usb-ljca.c +9 −13
  20. drivers/usb/phy/phy-generic.c +0 −7
  21. drivers/usb/storage/uas.c +13 −15
  22. drivers/usb/typec/class.c +6 −1
  23. drivers/usb/typec/tcpm/tcpm.c +3 −3
  24. drivers/usb/typec/ucsi/ucsi.c +72 −18
  25. drivers/usb/typec/ucsi/ucsi.h +3 −2
  26. drivers/usb/typec/ucsi/ucsi_acpi.c +33 −42
  27. drivers/usb/typec/ucsi/ucsi_glink.c +14 −0
drivers/usb/class/cdc-wdm.c+5−1
@@ -485,6 +485,7 @@ out_free_mem: · 484 unmodified lines
485485 static int service_outstanding_interrupt(struct wdm_device *desc)
486486 {
487487 int rv = 0;
488+ int used;
488489
489490 /* submit read urb only if the device is waiting for it */
490491 if (!desc->resp_count || !--desc->resp_count)
@@ -499,7 +500,10 @@ static int service_outstanding_interrupt(struct wdm_device *desc) · 8 unmodified lines
499500 goto out;
500501 }
501502
502− set_bit(WDM_RESPONDING, &desc->flags);
503+ used = test_and_set_bit(WDM_RESPONDING, &desc->flags);
504+ if (used)
505+ goto out;
506+
503507 spin_unlock_irq(&desc->iuspin);
504508 rv = usb_submit_urb(desc->response, GFP_KERNEL);
505509 spin_lock_irq(&desc->iuspin);
drivers/usb/core/hub.c+16−7
@@ -130,7 +130,6 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); · 129 unmodified lines
130130 #define HUB_DEBOUNCE_STEP 25
131131 #define HUB_DEBOUNCE_STABLE 100
132132
133−static void hub_release(struct kref *kref);
134133 static int usb_reset_and_verify_device(struct usb_device *udev);
135134 static int hub_port_disable(struct usb_hub *hub, int port1, int set_state);
136135 static bool hub_port_warm_reset_required(struct usb_hub *hub, int port1,
@@ -720,14 +719,14 @@ static void kick_hub_wq(struct usb_hub *hub) · 583 unmodified lines
720719 */
721720 intf = to_usb_interface(hub->intfdev);
722721 usb_autopm_get_interface_no_resume(intf);
723− kref_get(&hub->kref);
722+ hub_get(hub);
724723
725724 if (queue_work(hub_wq, &hub->events))
726725 return;
727726
728727 /* the work has already been scheduled */
729728 usb_autopm_put_interface_async(intf);
730− kref_put(&hub->kref, hub_release);
729+ hub_put(hub);
731730 }
732731
733732 void usb_kick_hub_wq(struct usb_device *hdev)
@@ -1095,7 +1094,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) · 361 unmodified lines
10951094 goto init2;
10961095 goto init3;
10971096 }
1098− kref_get(&hub->kref);
1097+ hub_get(hub);
10991098
11001099 /* The superspeed hub except for root hub has to use Hub Depth
11011100 * value as an offset into the route string to locate the bits
@@ -1343,7 +1342,7 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) · 241 unmodified lines
13431342 device_unlock(&hdev->dev);
13441343 }
13451344
1346− kref_put(&hub->kref, hub_release);
1345+ hub_put(hub);
13471346 }
13481347
13491348 /* Implement the continuations for the delays above */
@@ -1759,6 +1758,16 @@ static void hub_release(struct kref *kref) · 409 unmodified lines
17591758 kfree(hub);
17601759 }
17611760
1761+void hub_get(struct usb_hub *hub)
1762+{
1763+ kref_get(&hub->kref);
1764+}
1765+
1766+void hub_put(struct usb_hub *hub)
1767+{
1768+ kref_put(&hub->kref, hub_release);
1769+}
1770+
17621771 static unsigned highspeed_hubs;
17631772
17641773 static void hub_disconnect(struct usb_interface *intf)
@@ -1807,7 +1816,7 @@ static void hub_disconnect(struct usb_interface *intf) · 42 unmodified lines
18071816
18081817 onboard_hub_destroy_pdevs(&hub->onboard_hub_devs);
18091818
1810− kref_put(&hub->kref, hub_release);
1819+ hub_put(hub);
18111820 }
18121821
18131822 static bool hub_descriptor_is_sane(struct usb_host_interface *desc)
@@ -5934,7 +5943,7 @@ out_hdev_lock: · 4120 unmodified lines
59345943
59355944 /* Balance the stuff in kick_hub_wq() and allow autosuspend */
59365945 usb_autopm_put_interface(intf);
5937− kref_put(&hub->kref, hub_release);
5946+ hub_put(hub);
59385947
59395948 kcov_remote_stop();
59405949 }
drivers/usb/core/hub.h+2−0
@@ -129,6 +129,8 @@ extern void usb_hub_remove_port_device(struct usb_hub *hub, · 128 unmodified lines
129129 extern int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
130130 int port1, bool set);
131131 extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev);
132+extern void hub_get(struct usb_hub *hub);
133+extern void hub_put(struct usb_hub *hub);
132134 extern int hub_port_debounce(struct usb_hub *hub, int port1,
133135 bool must_be_connected);
134136 extern int usb_clear_port_feature(struct usb_device *hdev,
drivers/usb/core/port.c+34−4
@@ -56,11 +56,22 @@ static ssize_t disable_show(struct device *dev, · 55 unmodified lines
5656 u16 portstatus, unused;
5757 bool disabled;
5858 int rc;
59+ struct kernfs_node *kn;
5960
61+ hub_get(hub);
6062 rc = usb_autopm_get_interface(intf);
6163 if (rc < 0)
62− return rc;
64+ goto out_hub_get;
6365
66+ /*
67+ * Prevent deadlock if another process is concurrently
68+ * trying to unregister hdev.
69+ */
70+ kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
71+ if (!kn) {
72+ rc = -ENODEV;
73+ goto out_autopm;
74+ }
6475 usb_lock_device(hdev);
6576 if (hub->disconnected) {
6677 rc = -ENODEV;
@@ -70,9 +81,13 @@ static ssize_t disable_show(struct device *dev, · 3 unmodified lines
7081 usb_hub_port_status(hub, port1, &portstatus, &unused);
7182 disabled = !usb_port_is_power_on(hub, portstatus);
7283
73−out_hdev_lock:
84+ out_hdev_lock:
7485 usb_unlock_device(hdev);
86+ sysfs_unbreak_active_protection(kn);
87+ out_autopm:
7588 usb_autopm_put_interface(intf);
89+ out_hub_get:
90+ hub_put(hub);
7691
7792 if (rc)
7893 return rc;
@@ -90,15 +105,26 @@ static ssize_t disable_store(struct device *dev, struct device_attribute *attr, · 11 unmodified lines
90105 int port1 = port_dev->portnum;
91106 bool disabled;
92107 int rc;
108+ struct kernfs_node *kn;
93109
94110 rc = kstrtobool(buf, &disabled);
95111 if (rc)
96112 return rc;
97113
114+ hub_get(hub);
98115 rc = usb_autopm_get_interface(intf);
99116 if (rc < 0)
100− return rc;
117+ goto out_hub_get;
101118
119+ /*
120+ * Prevent deadlock if another process is concurrently
121+ * trying to unregister hdev.
122+ */
123+ kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
124+ if (!kn) {
125+ rc = -ENODEV;
126+ goto out_autopm;
127+ }
102128 usb_lock_device(hdev);
103129 if (hub->disconnected) {
104130 rc = -ENODEV;
@@ -119,9 +145,13 @@ static ssize_t disable_store(struct device *dev, struct device_attribute *attr, · 14 unmodified lines
119145 if (!rc)
120146 rc = count;
121147
122−out_hdev_lock:
148+ out_hdev_lock:
123149 usb_unlock_device(hdev);
150+ sysfs_unbreak_active_protection(kn);
151+ out_autopm:
124152 usb_autopm_put_interface(intf);
153+ out_hub_get:
154+ hub_put(hub);
125155
126156 return rc;
127157 }
drivers/usb/core/sysfs.c+13−3
@@ -1217,14 +1217,24 @@ static ssize_t interface_authorized_store(struct device *dev, · 1216 unmodified lines
12171217 {
12181218 struct usb_interface *intf = to_usb_interface(dev);
12191219 bool val;
1220+ struct kernfs_node *kn;
12201221
12211222 if (kstrtobool(buf, &val) != 0)
12221223 return -EINVAL;
12231224
1224− if (val)
1225+ if (val) {
12251226 usb_authorize_interface(intf);
1226− else
1227− usb_deauthorize_interface(intf);
1227+ } else {
1228+ /*
1229+ * Prevent deadlock if another process is concurrently
1230+ * trying to unregister intf.
1231+ */
1232+ kn = sysfs_break_active_protection(&dev->kobj, &attr->attr);
1233+ if (kn) {
1234+ usb_deauthorize_interface(intf);
1235+ sysfs_unbreak_active_protection(kn);
1236+ }
1237+ }
12281238
12291239 return count;
12301240 }
drivers/usb/dwc2/core.h+14−0
@@ -729,8 +729,14 @@ struct dwc2_dregs_backup { · 728 unmodified lines
729729 * struct dwc2_hregs_backup - Holds host registers state before
730730 * entering partial power down
731731 * @hcfg: Backup of HCFG register
732+ * @hflbaddr: Backup of HFLBADDR register
732733 * @haintmsk: Backup of HAINTMSK register
734+ * @hcchar: Backup of HCCHAR register
735+ * @hcsplt: Backup of HCSPLT register
733736 * @hcintmsk: Backup of HCINTMSK register
737+ * @hctsiz: Backup of HCTSIZ register
738+ * @hdma: Backup of HCDMA register
739+ * @hcdmab: Backup of HCDMAB register
734740 * @hprt0: Backup of HPTR0 register
735741 * @hfir: Backup of HFIR register
736742 * @hptxfsiz: Backup of HPTXFSIZ register
@@ -738,8 +744,14 @@ struct dwc2_dregs_backup { · 1 unmodified line
738744 */
739745 struct dwc2_hregs_backup {
740746 u32 hcfg;
747+ u32 hflbaddr;
741748 u32 haintmsk;
749+ u32 hcchar[MAX_EPS_CHANNELS];
750+ u32 hcsplt[MAX_EPS_CHANNELS];
742751 u32 hcintmsk[MAX_EPS_CHANNELS];
752+ u32 hctsiz[MAX_EPS_CHANNELS];
753+ u32 hcidma[MAX_EPS_CHANNELS];
754+ u32 hcidmab[MAX_EPS_CHANNELS];
743755 u32 hprt0;
744756 u32 hfir;
745757 u32 hptxfsiz;
@@ -1086,6 +1098,7 @@ struct dwc2_hsotg { · 340 unmodified lines
10861098 bool needs_byte_swap;
10871099
10881100 /* DWC OTG HW Release versions */
1101+#define DWC2_CORE_REV_4_30a 0x4f54430a
10891102 #define DWC2_CORE_REV_2_71a 0x4f54271a
10901103 #define DWC2_CORE_REV_2_72a 0x4f54272a
10911104 #define DWC2_CORE_REV_2_80a 0x4f54280a
@@ -1323,6 +1336,7 @@ int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg); · 231 unmodified lines
13231336 int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg);
13241337
13251338 void dwc2_enable_acg(struct dwc2_hsotg *hsotg);
1339+void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup);
13261340
13271341 /* This function should be called on every hardware interrupt. */
13281342 irqreturn_t dwc2_handle_common_intr(int irq, void *dev);
drivers/usb/dwc2/core_intr.c+48−24
@@ -297,7 +297,8 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg) · 296 unmodified lines
297297
298298 /* Exit gadget mode clock gating. */
299299 if (hsotg->params.power_down ==
300− DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
300+ DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended &&
301+ !hsotg->params.no_clock_gating)
301302 dwc2_gadget_exit_clock_gating(hsotg, 0);
302303 }
303304
@@ -322,10 +323,11 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg *hsotg) · 18 unmodified lines
322323 * @hsotg: Programming view of DWC_otg controller
323324 *
324325 */
325−static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg)
326+void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg, bool remotewakeup)
326327 {
327328 u32 glpmcfg;
328− u32 i = 0;
329+ u32 pcgctl;
330+ u32 dctl;
329331
330332 if (hsotg->lx_state != DWC2_L1) {
331333 dev_err(hsotg->dev, "Core isn't in DWC2_L1 state\n");
@@ -334,37 +336,57 @@ static void dwc2_wakeup_from_lpm_l1(struct dwc2_hsotg *hsotg) · 2 unmodified lines
334336
335337 glpmcfg = dwc2_readl(hsotg, GLPMCFG);
336338 if (dwc2_is_device_mode(hsotg)) {
337− dev_dbg(hsotg->dev, "Exit from L1 state\n");
339+ dev_dbg(hsotg->dev, "Exit from L1 state, remotewakeup=%d\n", remotewakeup);
338340 glpmcfg &= ~GLPMCFG_ENBLSLPM;
339− glpmcfg &= ~GLPMCFG_HIRD_THRES_EN;
341+ glpmcfg &= ~GLPMCFG_HIRD_THRES_MASK;
340342 dwc2_writel(hsotg, glpmcfg, GLPMCFG);
341343
342− do {
343− glpmcfg = dwc2_readl(hsotg, GLPMCFG);
344+ pcgctl = dwc2_readl(hsotg, PCGCTL);
345+ pcgctl &= ~PCGCTL_ENBL_SLEEP_GATING;
346+ dwc2_writel(hsotg, pcgctl, PCGCTL);
344347
345− if (!(glpmcfg & (GLPMCFG_COREL1RES_MASK |
346− GLPMCFG_L1RESUMEOK | GLPMCFG_SLPSTS)))
347− break;
348+ glpmcfg = dwc2_readl(hsotg, GLPMCFG);
349+ if (glpmcfg & GLPMCFG_ENBESL) {
350+ glpmcfg |= GLPMCFG_RSTRSLPSTS;
351+ dwc2_writel(hsotg, glpmcfg, GLPMCFG);
352+ }
353+
354+ if (remotewakeup) {
355+ if (dwc2_hsotg_wait_bit_set(hsotg, GLPMCFG, GLPMCFG_L1RESUMEOK, 1000)) {
356+ dev_warn(hsotg->dev, "%s: timeout GLPMCFG_L1RESUMEOK\n", __func__);
357+ goto fail;
358+ return;
359+ }
360+
361+ dctl = dwc2_readl(hsotg, DCTL);
362+ dctl |= DCTL_RMTWKUPSIG;
363+ dwc2_writel(hsotg, dctl, DCTL);
348364
349− udelay(1);
350− } while (++i < 200);
365+ if (dwc2_hsotg_wait_bit_set(hsotg, GINTSTS, GINTSTS_WKUPINT, 1000)) {
366+ dev_warn(hsotg->dev, "%s: timeout GINTSTS_WKUPINT\n", __func__);
367+ goto fail;
368+ return;
369+ }
370+ }
351371
352− if (i == 200) {
353− dev_err(hsotg->dev, "Failed to exit L1 sleep state in 200us.\n");
372+ glpmcfg = dwc2_readl(hsotg, GLPMCFG);
373+ if (glpmcfg & GLPMCFG_COREL1RES_MASK || glpmcfg & GLPMCFG_SLPSTS ||
374+ glpmcfg & GLPMCFG_L1RESUMEOK) {
375+ goto fail;
354376 return;
355377 }
356− dwc2_gadget_init_lpm(hsotg);
378+
379+ /* Inform gadget to exit from L1 */
380+ call_gadget(hsotg, resume);
381+ /* Change to L0 state */
382+ hsotg->lx_state = DWC2_L0;
383+ hsotg->bus_suspended = false;
384+fail: dwc2_gadget_init_lpm(hsotg);
357385 } else {
358386 /* TODO */
359387 dev_err(hsotg->dev, "Host side LPM is not supported.\n");
360388 return;
361389 }
362−
363− /* Change to L0 state */
364− hsotg->lx_state = DWC2_L0;
365−
366− /* Inform gadget to exit from L1 */
367− call_gadget(hsotg, resume);
368390 }
369391
370392 /*
@@ -385,7 +407,7 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) · 14 unmodified lines
385407 dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state);
386408
387409 if (hsotg->lx_state == DWC2_L1) {
388− dwc2_wakeup_from_lpm_l1(hsotg);
410+ dwc2_wakeup_from_lpm_l1(hsotg, false);
389411 return;
390412 }
391413
@@ -408,7 +430,8 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) · 16 unmodified lines
408430
409431 /* Exit gadget mode clock gating. */
410432 if (hsotg->params.power_down ==
411− DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
433+ DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended &&
434+ !hsotg->params.no_clock_gating)
412435 dwc2_gadget_exit_clock_gating(hsotg, 0);
413436 } else {
414437 /* Change to L0 state */
@@ -425,7 +448,8 @@ static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg) · 10 unmodified lines
425448 }
426449
427450 if (hsotg->params.power_down ==
428− DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended)
451+ DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended &&
452+ !hsotg->params.no_clock_gating)
429453 dwc2_host_exit_clock_gating(hsotg, 1);
430454
431455 /*
drivers/usb/dwc2/gadget.c+10−0
@@ -1415,6 +1415,10 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct usb_request *req, · 1414 unmodified lines
14151415 ep->name, req, req->length, req->buf, req->no_interrupt,
14161416 req->zero, req->short_not_ok);
14171417
1418+ if (hs->lx_state == DWC2_L1) {
1419+ dwc2_wakeup_from_lpm_l1(hs, true);
1420+ }
1421+
14181422 /* Prevent new request submission when controller is suspended */
14191423 if (hs->lx_state != DWC2_L0) {
14201424 dev_dbg(hs->dev, "%s: submit request only in active state\n",
@@ -3727,6 +3731,12 @@ irq_retry: · 2306 unmodified lines
37273731 if (hsotg->in_ppd && hsotg->lx_state == DWC2_L2)
37283732 dwc2_exit_partial_power_down(hsotg, 0, true);
37293733
3734+ /* Exit gadget mode clock gating. */
3735+ if (hsotg->params.power_down ==
3736+ DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended &&
3737+ !hsotg->params.no_clock_gating)
3738+ dwc2_gadget_exit_clock_gating(hsotg, 0);
3739+
37303740 hsotg->lx_state = DWC2_L0;
37313741 }
37323742
drivers/usb/dwc2/hcd.c+40−9
@@ -2701,8 +2701,11 @@ enum dwc2_transaction_type dwc2_hcd_select_transactions( · 2700 unmodified lines
27012701 hsotg->available_host_channels--;
27022702 }
27032703 qh = list_entry(qh_ptr, struct dwc2_qh, qh_list_entry);
2704− if (dwc2_assign_and_init_hc(hsotg, qh))
2704+ if (dwc2_assign_and_init_hc(hsotg, qh)) {
2705+ if (hsotg->params.uframe_sched)
2706+ hsotg->available_host_channels++;
27052707 break;
2708+ }
27062709
27072710 /*
27082711 * Move the QH from the periodic ready schedule to the
@@ -2735,8 +2738,11 @@ enum dwc2_transaction_type dwc2_hcd_select_transactions( · 26 unmodified lines
27352738 hsotg->available_host_channels--;
27362739 }
27372740
2738− if (dwc2_assign_and_init_hc(hsotg, qh))
2741+ if (dwc2_assign_and_init_hc(hsotg, qh)) {
2742+ if (hsotg->params.uframe_sched)
2743+ hsotg->available_host_channels++;
27392744 break;
2745+ }
27402746
27412747 /*
27422748 * Move the QH from the non-periodic inactive schedule to the
@@ -4143,6 +4149,8 @@ void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, · 1400 unmodified lines
41434149 urb->actual_length);
41444150
41454151 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
4152+ if (!hsotg->params.dma_desc_enable)
4153+ urb->start_frame = qtd->qh->start_active_frame;
41464154 urb->error_count = dwc2_hcd_urb_get_error_count(qtd->urb);
41474155 for (i = 0; i < urb->number_of_packets; ++i) {
41484156 urb->iso_frame_desc[i].actual_length =
@@ -4649,7 +4657,7 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, · 500 unmodified lines
46494657 }
46504658
46514659 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
4652− hsotg->bus_suspended) {
4660+ hsotg->bus_suspended && !hsotg->params.no_clock_gating) {
46534661 if (dwc2_is_device_mode(hsotg))
46544662 dwc2_gadget_exit_clock_gating(hsotg, 0);
46554663 else
@@ -5406,9 +5414,16 @@ int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg) · 750 unmodified lines
54065414 /* Backup Host regs */
54075415 hr = &hsotg->hr_backup;
54085416 hr->hcfg = dwc2_readl(hsotg, HCFG);
5417+ hr->hflbaddr = dwc2_readl(hsotg, HFLBADDR);
54095418 hr->haintmsk = dwc2_readl(hsotg, HAINTMSK);
5410− for (i = 0; i < hsotg->params.host_channels; ++i)
5419+ for (i = 0; i < hsotg->params.host_channels; ++i) {
5420+ hr->hcchar[i] = dwc2_readl(hsotg, HCCHAR(i));
5421+ hr->hcsplt[i] = dwc2_readl(hsotg, HCSPLT(i));
54115422 hr->hcintmsk[i] = dwc2_readl(hsotg, HCINTMSK(i));
5423+ hr->hctsiz[i] = dwc2_readl(hsotg, HCTSIZ(i));
5424+ hr->hcidma[i] = dwc2_readl(hsotg, HCDMA(i));
5425+ hr->hcidmab[i] = dwc2_readl(hsotg, HCDMAB(i));
5426+ }
54125427
54135428 hr->hprt0 = dwc2_read_hprt0(hsotg);
54145429 hr->hfir = dwc2_readl(hsotg, HFIR);
@@ -5442,10 +5457,17 @@ int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg) · 27 unmodified lines
54425457 hr->valid = false;
54435458
54445459 dwc2_writel(hsotg, hr->hcfg, HCFG);
5460+ dwc2_writel(hsotg, hr->hflbaddr, HFLBADDR);
54455461 dwc2_writel(hsotg, hr->haintmsk, HAINTMSK);
54465462
5447− for (i = 0; i < hsotg->params.host_channels; ++i)
5463+ for (i = 0; i < hsotg->params.host_channels; ++i) {
5464+ dwc2_writel(hsotg, hr->hcchar[i], HCCHAR(i));
5465+ dwc2_writel(hsotg, hr->hcsplt[i], HCSPLT(i));
54485466 dwc2_writel(hsotg, hr->hcintmsk[i], HCINTMSK(i));
5467+ dwc2_writel(hsotg, hr->hctsiz[i], HCTSIZ(i));
5468+ dwc2_writel(hsotg, hr->hcidma[i], HCDMA(i));
5469+ dwc2_writel(hsotg, hr->hcidmab[i], HCDMAB(i));
5470+ }
54495471
54505472 dwc2_writel(hsotg, hr->hprt0, HPRT0);
54515473 dwc2_writel(hsotg, hr->hfir, HFIR);
@@ -5610,10 +5632,12 @@ int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, · 158 unmodified lines
56105632 dwc2_writel(hsotg, hr->hcfg, HCFG);
56115633
56125634 /* De-assert Wakeup Logic */
5613− gpwrdn = dwc2_readl(hsotg, GPWRDN);
5614− gpwrdn &= ~GPWRDN_PMUACTV;
5615− dwc2_writel(hsotg, gpwrdn, GPWRDN);
5616− udelay(10);
5635+ if (!(rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) {
5636+ gpwrdn = dwc2_readl(hsotg, GPWRDN);
5637+ gpwrdn &= ~GPWRDN_PMUACTV;
5638+ dwc2_writel(hsotg, gpwrdn, GPWRDN);
5639+ udelay(10);
5640+ }
56175641
56185642 hprt0 = hr->hprt0;
56195643 hprt0 |= HPRT0_PWR;
@@ -5638,6 +5662,13 @@ int dwc2_host_exit_hibernation(struct dwc2_hsotg *hsotg, int rem_wakeup, · 18 unmodified lines
56385662 hprt0 |= HPRT0_RES;
56395663 dwc2_writel(hsotg, hprt0, HPRT0);
56405664
5665+ /* De-assert Wakeup Logic */
5666+ if ((rem_wakeup && hsotg->hw_params.snpsid >= DWC2_CORE_REV_4_30a)) {
5667+ gpwrdn = dwc2_readl(hsotg, GPWRDN);
5668+ gpwrdn &= ~GPWRDN_PMUACTV;
5669+ dwc2_writel(hsotg, gpwrdn, GPWRDN);
5670+ udelay(10);
5671+ }
56415672 /* Wait for Resume time and then program HPRT again */
56425673 mdelay(100);
56435674 hprt0 &= ~HPRT0_RES;
drivers/usb/dwc2/hcd_ddma.c+11−6
@@ -559,7 +559,7 @@ static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, · 558 unmodified lines
559559 idx = qh->td_last;
560560 inc = qh->host_interval;
561561 hsotg->frame_number = dwc2_hcd_get_frame_number(hsotg);
562− cur_idx = dwc2_frame_list_idx(hsotg->frame_number);
562+ cur_idx = idx;
563563 next_idx = dwc2_desclist_idx_inc(qh->td_last, inc, qh->dev_speed);
564564
565565 /*
@@ -866,6 +866,8 @@ static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg, · 300 unmodified lines
866866 {
867867 struct dwc2_dma_desc *dma_desc;
868868 struct dwc2_hcd_iso_packet_desc *frame_desc;
869+ u16 frame_desc_idx;
870+ struct urb *usb_urb = qtd->urb->priv;
869871 u16 remain = 0;
870872 int rc = 0;
871873
@@ -878,8 +880,11 @@ static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg, · 6 unmodified lines
878880 DMA_FROM_DEVICE);
879881
880882 dma_desc = &qh->desc_list[idx];
883+ frame_desc_idx = (idx - qtd->isoc_td_first) & (usb_urb->number_of_packets - 1);
881884
882− frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
885+ frame_desc = &qtd->urb->iso_descs[frame_desc_idx];
886+ if (idx == qtd->isoc_td_first)
887+ usb_urb->start_frame = dwc2_hcd_get_frame_number(hsotg);
883888 dma_desc->buf = (u32)(qtd->urb->dma + frame_desc->offset);
884889 if (chan->ep_is_in)
885890 remain = (dma_desc->status & HOST_DMA_ISOC_NBYTES_MASK) >>
@@ -900,7 +905,7 @@ static int dwc2_cmpl_host_isoc_dma_desc(struct dwc2_hsotg *hsotg, · 14 unmodified lines
900905 frame_desc->status = 0;
901906 }
902907
903− if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
908+ if (++qtd->isoc_frame_index == usb_urb->number_of_packets) {
904909 /*
905910 * urb->status is not used for isoc transfers here. The
906911 * individual frame_desc status are used instead.
@@ -1005,11 +1010,11 @@ static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, · 98 unmodified lines
10051010 return;
10061011 idx = dwc2_desclist_idx_inc(idx, qh->host_interval,
10071012 chan->speed);
1008− if (!rc)
1013+ if (rc == 0)
10091014 continue;
10101015
1011− if (rc == DWC2_CMPL_DONE)
1012− break;
1016+ if (rc == DWC2_CMPL_DONE || rc == DWC2_CMPL_STOP)
1017+ goto stop_scan;
10131018
10141019 /* rc == DWC2_CMPL_STOP */
10151020
drivers/usb/dwc2/hw.h+1−1
@@ -698,7 +698,7 @@ · 697 unmodified lines
698698 #define TXSTS_QTOP_TOKEN_MASK (0x3 << 25)
699699 #define TXSTS_QTOP_TOKEN_SHIFT 25
700700 #define TXSTS_QTOP_TERMINATE BIT(24)
701−#define TXSTS_QSPCAVAIL_MASK (0xff << 16)
701+#define TXSTS_QSPCAVAIL_MASK (0x7f << 16)
702702 #define TXSTS_QSPCAVAIL_SHIFT 16
703703 #define TXSTS_FSPCAVAIL_MASK (0xffff << 0)
704704 #define TXSTS_FSPCAVAIL_SHIFT 0
drivers/usb/dwc2/platform.c+1−1
@@ -331,7 +331,7 @@ static void dwc2_driver_remove(struct platform_device *dev) · 330 unmodified lines
331331
332332 /* Exit clock gating when driver is removed. */
333333 if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_NONE &&
334− hsotg->bus_suspended) {
334+ hsotg->bus_suspended && !hsotg->params.no_clock_gating) {
335335 if (dwc2_is_device_mode(hsotg))
336336 dwc2_gadget_exit_clock_gating(hsotg, 0);
337337 else
drivers/usb/dwc3/core.c+2−0
@@ -1519,6 +1519,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) · 1518 unmodified lines
15191519 else
15201520 dwc->sysdev = dwc->dev;
15211521
1522+ dwc->sys_wakeup = device_may_wakeup(dwc->sysdev);
1523+
15221524 ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
15231525 if (ret >= 0) {
15241526 dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
drivers/usb/dwc3/core.h+2−0
@@ -1133,6 +1133,7 @@ struct dwc3_scratchpad_array { · 1132 unmodified lines
11331133 * 3 - Reserved
11341134 * @dis_metastability_quirk: set to disable metastability quirk.
11351135 * @dis_split_quirk: set to disable split boundary.
1136+ * @sys_wakeup: set if the device may do system wakeup.
11361137 * @wakeup_configured: set if the device is configured for remote wakeup.
11371138 * @suspended: set to track suspend event due to U3/L2.
11381139 * @imod_interval: set the interrupt moderation interval in 250ns
@@ -1357,6 +1358,7 @@ struct dwc3 { · 218 unmodified lines
13571358
13581359 unsigned dis_split_quirk:1;
13591360 unsigned async_callbacks:1;
1361+ unsigned sys_wakeup:1;
13601362 unsigned wakeup_configured:1;
13611363 unsigned suspended:1;
13621364
drivers/usb/dwc3/dwc3-pci.c+0−2
@@ -51,7 +51,6 @@ · 50 unmodified lines
5151 #define PCI_DEVICE_ID_INTEL_MTLP 0x7ec1
5252 #define PCI_DEVICE_ID_INTEL_MTLS 0x7f6f
5353 #define PCI_DEVICE_ID_INTEL_MTL 0x7e7e
54−#define PCI_DEVICE_ID_INTEL_ARLH 0x7ec1
5554 #define PCI_DEVICE_ID_INTEL_ARLH_PCH 0x777e
5655 #define PCI_DEVICE_ID_INTEL_TGL 0x9a15
5756 #define PCI_DEVICE_ID_AMD_MR 0x163a
@@ -423,7 +422,6 @@ static const struct pci_device_id dwc3_pci_id_table[] = { · 365 unmodified lines
423422 { PCI_DEVICE_DATA(INTEL, MTLP, &dwc3_pci_intel_swnode) },
424423 { PCI_DEVICE_DATA(INTEL, MTL, &dwc3_pci_intel_swnode) },
425424 { PCI_DEVICE_DATA(INTEL, MTLS, &dwc3_pci_intel_swnode) },
426− { PCI_DEVICE_DATA(INTEL, ARLH, &dwc3_pci_intel_swnode) },
427425 { PCI_DEVICE_DATA(INTEL, ARLH_PCH, &dwc3_pci_intel_swnode) },
428426 { PCI_DEVICE_DATA(INTEL, TGL, &dwc3_pci_intel_swnode) },
429427
drivers/usb/dwc3/gadget.c+10−0
@@ -2955,6 +2955,9 @@ static int dwc3_gadget_start(struct usb_gadget *g, · 2954 unmodified lines
29552955 dwc->gadget_driver = driver;
29562956 spin_unlock_irqrestore(&dwc->lock, flags);
29572957
2958+ if (dwc->sys_wakeup)
2959+ device_wakeup_enable(dwc->sysdev);
2960+
29582961 return 0;
29592962 }
29602963
@@ -2970,6 +2973,9 @@ static int dwc3_gadget_stop(struct usb_gadget *g) · 9 unmodified lines
29702973 struct dwc3 *dwc = gadget_to_dwc(g);
29712974 unsigned long flags;
29722975
2976+ if (dwc->sys_wakeup)
2977+ device_wakeup_disable(dwc->sysdev);
2978+
29732979 spin_lock_irqsave(&dwc->lock, flags);
29742980 dwc->gadget_driver = NULL;
29752981 dwc->max_cfg_eps = 0;
@@ -4651,6 +4657,10 @@ int dwc3_gadget_init(struct dwc3 *dwc) · 1675 unmodified lines
46514657 else
46524658 dwc3_gadget_set_speed(dwc->gadget, dwc->maximum_speed);
46534659
4660+ /* No system wakeup if no gadget driver bound */
4661+ if (dwc->sys_wakeup)
4662+ device_wakeup_disable(dwc->sysdev);
4663+
46544664 return 0;
46554665
46564666 err5:
drivers/usb/dwc3/host.c+11−0
@@ -173,6 +173,14 @@ int dwc3_host_init(struct dwc3 *dwc) · 172 unmodified lines
173173 goto err;
174174 }
175175
176+ if (dwc->sys_wakeup) {
177+ /* Restore wakeup setting if switched from device */
178+ device_wakeup_enable(dwc->sysdev);
179+
180+ /* Pass on wakeup setting to the new xhci platform device */
181+ device_init_wakeup(&xhci->dev, true);
182+ }
183+
176184 return 0;
177185 err:
178186 platform_device_put(xhci);
@@ -181,6 +189,9 @@ err: · 2 unmodified lines
181189
182190 void dwc3_host_exit(struct dwc3 *dwc)
183191 {
192+ if (dwc->sys_wakeup)
193+ device_init_wakeup(&dwc->xhci->dev, false);
194+
184195 platform_device_unregister(dwc->xhci);
185196 dwc->xhci = NULL;
186197 }
drivers/usb/gadget/udc/core.c+3−1
@@ -292,7 +292,9 @@ int usb_ep_queue(struct usb_ep *ep, · 291 unmodified lines
292292 {
293293 int ret = 0;
294294
295− if (WARN_ON_ONCE(!ep->enabled && ep->address)) {
295+ if (!ep->enabled && ep->address) {
296+ pr_debug("USB gadget: queue request to disabled ep 0x%x (%s)\n",
297+ ep->address, ep->name);
296298 ret = -ESHUTDOWN;
297299 goto out;
298300 }
drivers/usb/misc/usb-ljca.c+9−13
@@ -518,8 +518,10 @@ static int ljca_new_client_device(struct ljca_adapter *adap, u8 type, u8 id, · 517 unmodified lines
518518 int ret;
519519
520520 client = kzalloc(sizeof *client, GFP_KERNEL);
521− if (!client)
521+ if (!client) {
522+ kfree(data);
522523 return -ENOMEM;
524+ }
523525
524526 client->type = type;
525527 client->id = id;
@@ -535,8 +537,10 @@ static int ljca_new_client_device(struct ljca_adapter *adap, u8 type, u8 id, · 9 unmodified lines
535537 auxdev->dev.release = ljca_auxdev_release;
536538
537539 ret = auxiliary_device_init(auxdev);
538− if (ret)
540+ if (ret) {
541+ kfree(data);
539542 goto err_free;
543+ }
540544
541545 ljca_auxdev_acpi_bind(adap, auxdev, adr, id);
542546
@@ -590,12 +594,8 @@ static int ljca_enumerate_gpio(struct ljca_adapter *adap) · 47 unmodified lines
590594 valid_pin[i] = get_unaligned_le32(&desc->bank_desc[i].valid_pins);
591595 bitmap_from_arr32(gpio_info->valid_pin_map, valid_pin, gpio_num);
592596
593− ret = ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio",
597+ return ljca_new_client_device(adap, LJCA_CLIENT_GPIO, 0, "ljca-gpio",
594598 gpio_info, LJCA_GPIO_ACPI_ADR);
595− if (ret)
596− kfree(gpio_info);
597−
598− return ret;
599599 }
600600
601601 static int ljca_enumerate_i2c(struct ljca_adapter *adap)
@@ -629,10 +629,8 @@ static int ljca_enumerate_i2c(struct ljca_adapter *adap) · 27 unmodified lines
629629 ret = ljca_new_client_device(adap, LJCA_CLIENT_I2C, i,
630630 "ljca-i2c", i2c_info,
631631 LJCA_I2C1_ACPI_ADR + i);
632− if (ret) {
633− kfree(i2c_info);
632+ if (ret)
634633 return ret;
635− }
636634 }
637635
638636 return 0;
@@ -669,10 +667,8 @@ static int ljca_enumerate_spi(struct ljca_adapter *adap) · 30 unmodified lines
669667 ret = ljca_new_client_device(adap, LJCA_CLIENT_SPI, i,
670668 "ljca-spi", spi_info,
671669 LJCA_SPI1_ACPI_ADR + i);
672− if (ret) {
673− kfree(spi_info);
670+ if (ret)
674671 return ret;
675− }
676672 }
677673
678674 return 0;
drivers/usb/phy/phy-generic.c+0−7
@@ -262,13 +262,6 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop) · 261 unmodified lines
262262 return dev_err_probe(dev, PTR_ERR(nop->vbus_draw),
263263 "could not get vbus regulator\n");
264264
265− nop->vbus_draw = devm_regulator_get_exclusive(dev, "vbus");
266− if (PTR_ERR(nop->vbus_draw) == -ENODEV)
267− nop->vbus_draw = NULL;
268− if (IS_ERR(nop->vbus_draw))
269− return dev_err_probe(dev, PTR_ERR(nop->vbus_draw),
270− "could not get vbus regulator\n");
271−
272265 nop->dev = dev;
273266 nop->phy.dev = nop->dev;
274267 nop->phy.label = "nop-xceiv";
drivers/usb/storage/uas.c+13−15
@@ -533,7 +533,7 @@ static struct urb *uas_alloc_cmd_urb(struct uas_dev_info *devinfo, gfp_t gfp, · 532 unmodified lines
533533 * daft to me.
534534 */
535535
536−static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp)
536+static int uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp)
537537 {
538538 struct uas_dev_info *devinfo = cmnd->device->hostdata;
539539 struct urb *urb;
@@ -541,30 +541,28 @@ static struct urb *uas_submit_sense_urb(struct scsi_cmnd *cmnd, gfp_t gfp) · 1 unmodified line
541541
542542 urb = uas_alloc_sense_urb(devinfo, gfp, cmnd);
543543 if (!urb)
544− return NULL;
544+ return -ENOMEM;
545545 usb_anchor_urb(urb, &devinfo->sense_urbs);
546546 err = usb_submit_urb(urb, gfp);
547547 if (err) {
548548 usb_unanchor_urb(urb);
549549 uas_log_cmd_state(cmnd, "sense submit err", err);
550550 usb_free_urb(urb);
551− return NULL;
552551 }
553− return urb;
552+ return err;
554553 }
555554
556555 static int uas_submit_urbs(struct scsi_cmnd *cmnd,
557556 struct uas_dev_info *devinfo)
558557 {
559558 struct uas_cmd_info *cmdinfo = scsi_cmd_priv(cmnd);
560− struct urb *urb;
561559 int err;
562560
563561 lockdep_assert_held(&devinfo->lock);
564562 if (cmdinfo->state & SUBMIT_STATUS_URB) {
565− urb = uas_submit_sense_urb(cmnd, GFP_ATOMIC);
566− if (!urb)
567− return SCSI_MLQUEUE_DEVICE_BUSY;
563+ err = uas_submit_sense_urb(cmnd, GFP_ATOMIC);
564+ if (err)
565+ return err;
568566 cmdinfo->state &= ~SUBMIT_STATUS_URB;
569567 }
570568
@@ -572,7 +570,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 1 unmodified line
572570 cmdinfo->data_in_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC,
573571 cmnd, DMA_FROM_DEVICE);
574572 if (!cmdinfo->data_in_urb)
575− return SCSI_MLQUEUE_DEVICE_BUSY;
573+ return -ENOMEM;
576574 cmdinfo->state &= ~ALLOC_DATA_IN_URB;
577575 }
578576
@@ -582,7 +580,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 3 unmodified lines
582580 if (err) {
583581 usb_unanchor_urb(cmdinfo->data_in_urb);
584582 uas_log_cmd_state(cmnd, "data in submit err", err);
585− return SCSI_MLQUEUE_DEVICE_BUSY;
583+ return err;
586584 }
587585 cmdinfo->state &= ~SUBMIT_DATA_IN_URB;
588586 cmdinfo->state |= DATA_IN_URB_INFLIGHT;
@@ -592,7 +590,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 3 unmodified lines
592590 cmdinfo->data_out_urb = uas_alloc_data_urb(devinfo, GFP_ATOMIC,
593591 cmnd, DMA_TO_DEVICE);
594592 if (!cmdinfo->data_out_urb)
595− return SCSI_MLQUEUE_DEVICE_BUSY;
593+ return -ENOMEM;
596594 cmdinfo->state &= ~ALLOC_DATA_OUT_URB;
597595 }
598596
@@ -602,7 +600,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 3 unmodified lines
602600 if (err) {
603601 usb_unanchor_urb(cmdinfo->data_out_urb);
604602 uas_log_cmd_state(cmnd, "data out submit err", err);
605− return SCSI_MLQUEUE_DEVICE_BUSY;
603+ return err;
606604 }
607605 cmdinfo->state &= ~SUBMIT_DATA_OUT_URB;
608606 cmdinfo->state |= DATA_OUT_URB_INFLIGHT;
@@ -611,7 +609,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 2 unmodified lines
611609 if (cmdinfo->state & ALLOC_CMD_URB) {
612610 cmdinfo->cmd_urb = uas_alloc_cmd_urb(devinfo, GFP_ATOMIC, cmnd);
613611 if (!cmdinfo->cmd_urb)
614− return SCSI_MLQUEUE_DEVICE_BUSY;
612+ return -ENOMEM;
615613 cmdinfo->state &= ~ALLOC_CMD_URB;
616614 }
617615
@@ -621,7 +619,7 @@ static int uas_submit_urbs(struct scsi_cmnd *cmnd, · 3 unmodified lines
621619 if (err) {
622620 usb_unanchor_urb(cmdinfo->cmd_urb);
623621 uas_log_cmd_state(cmnd, "cmd submit err", err);
624− return SCSI_MLQUEUE_DEVICE_BUSY;
622+ return err;
625623 }
626624 cmdinfo->cmd_urb = NULL;
627625 cmdinfo->state &= ~SUBMIT_CMD_URB;
@@ -698,7 +696,7 @@ static int uas_queuecommand_lck(struct scsi_cmnd *cmnd) · 70 unmodified lines
698696 * of queueing, no matter how fatal the error
699697 */
700698 if (err == -ENODEV) {
701− set_host_byte(cmnd, DID_ERROR);
699+ set_host_byte(cmnd, DID_NO_CONNECT);
702700 scsi_done(cmnd);
703701 goto zombie;
704702 }
drivers/usb/typec/class.c+6−1
@@ -1310,6 +1310,7 @@ static ssize_t select_usb_power_delivery_store(struct device *dev, · 1309 unmodified lines
13101310 {
13111311 struct typec_port *port = to_typec_port(dev);
13121312 struct usb_power_delivery *pd;
1313+ int ret;
13131314
13141315 if (!port->ops || !port->ops->pd_set)
13151316 return -EOPNOTSUPP;
@@ -1318,7 +1319,11 @@ static ssize_t select_usb_power_delivery_store(struct device *dev, · 2 unmodified lines
13181319 if (!pd)
13191320 return -EINVAL;
13201321
1321− return port->ops->pd_set(port, pd);
1322+ ret = port->ops->pd_set(port, pd);
1323+ if (ret)
1324+ return ret;
1325+
1326+ return size;
13221327 }
13231328
13241329 static ssize_t select_usb_power_delivery_show(struct device *dev,
drivers/usb/typec/tcpm/tcpm.c+3−3
@@ -6861,7 +6861,7 @@ static int tcpm_pd_set(struct typec_port *p, struct usb_power_delivery *pd) · 6860 unmodified lines
68616861
68626862 if (data->source_desc.pdo[0]) {
68636863 for (i = 0; i < PDO_MAX_OBJECTS && data->source_desc.pdo[i]; i++)
6864− port->snk_pdo[i] = data->source_desc.pdo[i];
6864+ port->src_pdo[i] = data->source_desc.pdo[i];
68656865 port->nr_src_pdo = i + 1;
68666866 }
68676867
@@ -6910,7 +6910,9 @@ static int tcpm_pd_set(struct typec_port *p, struct usb_power_delivery *pd) · 42 unmodified lines
69106910
69116911 port->port_source_caps = data->source_cap;
69126912 port->port_sink_caps = data->sink_cap;
6913+ typec_port_set_usb_power_delivery(p, NULL);
69136914 port->selected_pd = pd;
6915+ typec_port_set_usb_power_delivery(p, port->selected_pd);
69146916 unlock:
69156917 mutex_unlock(&port->lock);
69166918 return ret;
@@ -6943,9 +6945,7 @@ static void tcpm_port_unregister_pd(struct tcpm_port *port) · 26 unmodified lines
69436945 port->port_source_caps = NULL;
69446946 for (i = 0; i < port->pd_count; i++) {
69456947 usb_power_delivery_unregister_capabilities(port->pd_list[i]->sink_cap);
6946− kfree(port->pd_list[i]->sink_cap);
69476948 usb_power_delivery_unregister_capabilities(port->pd_list[i]->source_cap);
6948− kfree(port->pd_list[i]->source_cap);
69496949 devm_kfree(port->dev, port->pd_list[i]);
69506950 port->pd_list[i] = NULL;
69516951 usb_power_delivery_unregister(port->pds[i]);
drivers/usb/typec/ucsi/ucsi.c+72−18
@@ -151,8 +151,12 @@ static int ucsi_exec_command(struct ucsi *ucsi, u64 cmd) · 150 unmodified lines
151151 if (!(cci & UCSI_CCI_COMMAND_COMPLETE))
152152 return -EIO;
153153
154− if (cci & UCSI_CCI_NOT_SUPPORTED)
154+ if (cci & UCSI_CCI_NOT_SUPPORTED) {
155+ if (ucsi_acknowledge_command(ucsi) < 0)
156+ dev_err(ucsi->dev,
157+ "ACK of unsupported command failed\n");
155158 return -EOPNOTSUPP;
159+ }
156160
157161 if (cci & UCSI_CCI_ERROR) {
158162 if (cmd == UCSI_GET_ERROR_STATUS)
@@ -1133,17 +1137,21 @@ static int ucsi_check_cable(struct ucsi_connector *con) · 974 unmodified lines
11331137 if (ret < 0)
11341138 return ret;
11351139
1136− ret = ucsi_get_cable_identity(con);
1137− if (ret < 0)
1138− return ret;
1140+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE) {
1141+ ret = ucsi_get_cable_identity(con);
1142+ if (ret < 0)
1143+ return ret;
1144+ }
11391145
1140− ret = ucsi_register_plug(con);
1141− if (ret < 0)
1142− return ret;
1146+ if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_DETAILS) {
1147+ ret = ucsi_register_plug(con);
1148+ if (ret < 0)
1149+ return ret;
11431150
1144− ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
1145− if (ret < 0)
1146− return ret;
1151+ ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
1152+ if (ret < 0)
1153+ return ret;
1154+ }
11471155
11481156 return 0;
11491157 }
@@ -1189,8 +1197,10 @@ static void ucsi_handle_connector_change(struct work_struct *work) · 39 unmodified lines
11891197 ucsi_register_partner(con);
11901198 ucsi_partner_task(con, ucsi_check_connection, 1, HZ);
11911199 ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ);
1192− ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
1193− ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
1200+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
1201+ ucsi_partner_task(con, ucsi_get_partner_identity, 1, HZ);
1202+ if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
1203+ ucsi_partner_task(con, ucsi_check_cable, 1, HZ);
11941204
11951205 if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) ==
11961206 UCSI_CONSTAT_PWR_OPMODE_PD)
@@ -1215,11 +1225,11 @@ static void ucsi_handle_connector_change(struct work_struct *work) · 18 unmodified lines
12151225 if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
12161226 ucsi_partner_task(con, ucsi_check_altmodes, 1, 0);
12171227
1218− clear_bit(EVENT_PENDING, &con->ucsi->flags);
1219−
12201228 mutex_lock(&ucsi->ppm_lock);
1229+ clear_bit(EVENT_PENDING, &con->ucsi->flags);
12211230 ret = ucsi_acknowledge_connector_change(ucsi);
12221231 mutex_unlock(&ucsi->ppm_lock);
1232+
12231233 if (ret)
12241234 dev_err(ucsi->dev, "%s: ACK failed (%d)", __func__, ret);
12251235
@@ -1237,7 +1247,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num) · 11 unmodified lines
12371247 struct ucsi_connector *con = &ucsi->connector[num - 1];
12381248
12391249 if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
1240− dev_dbg(ucsi->dev, "Bogus connector change event\n");
1250+ dev_dbg(ucsi->dev, "Early connector change event\n");
12411251 return;
12421252 }
12431253
@@ -1260,13 +1270,47 @@ static int ucsi_reset_connector(struct ucsi_connector *con, bool hard) · 16 unmodified lines
12601270
12611271 static int ucsi_reset_ppm(struct ucsi *ucsi)
12621272 {
1263− u64 command = UCSI_PPM_RESET;
1273+ u64 command;
12641274 unsigned long tmo;
12651275 u32 cci;
12661276 int ret;
12671277
12681278 mutex_lock(&ucsi->ppm_lock);
12691279
1280+ ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
1281+ if (ret < 0)
1282+ goto out;
1283+
1284+ /*
1285+ * If UCSI_CCI_RESET_COMPLETE is already set we must clear
1286+ * the flag before we start another reset. Send a
1287+ * UCSI_SET_NOTIFICATION_ENABLE command to achieve this.
1288+ * Ignore a timeout and try the reset anyway if this fails.
1289+ */
1290+ if (cci & UCSI_CCI_RESET_COMPLETE) {
1291+ command = UCSI_SET_NOTIFICATION_ENABLE;
1292+ ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
1293+ sizeof(command));
1294+ if (ret < 0)
1295+ goto out;
1296+
1297+ tmo = jiffies + msecs_to_jiffies(UCSI_TIMEOUT_MS);
1298+ do {
1299+ ret = ucsi->ops->read(ucsi, UCSI_CCI,
1300+ &cci, sizeof(cci));
1301+ if (ret < 0)
1302+ goto out;
1303+ if (cci & UCSI_CCI_COMMAND_COMPLETE)
1304+ break;
1305+ if (time_is_before_jiffies(tmo))
1306+ break;
1307+ msleep(20);
1308+ } while (1);
1309+
1310+ WARN_ON(cci & UCSI_CCI_RESET_COMPLETE);
1311+ }
1312+
1313+ command = UCSI_PPM_RESET;
12701314 ret = ucsi->ops->async_write(ucsi, UCSI_CONTROL, &command,
12711315 sizeof(command));
12721316 if (ret < 0)
@@ -1589,8 +1633,10 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) · 316 unmodified lines
15891633 ucsi_register_partner(con);
15901634 ucsi_pwr_opmode_change(con);
15911635 ucsi_port_psy_changed(con);
1592− ucsi_get_partner_identity(con);
1593− ucsi_check_cable(con);
1636+ if (con->ucsi->cap.features & UCSI_CAP_GET_PD_MESSAGE)
1637+ ucsi_get_partner_identity(con);
1638+ if (con->ucsi->cap.features & UCSI_CAP_CABLE_DETAILS)
1639+ ucsi_check_cable(con);
15941640 }
15951641
15961642 /* Only notify USB controller if partner supports USB data */
@@ -1636,6 +1682,7 @@ static int ucsi_init(struct ucsi *ucsi) · 39 unmodified lines
16361682 {
16371683 struct ucsi_connector *con, *connector;
16381684 u64 command, ntfy;
1685+ u32 cci;
16391686 int ret;
16401687 int i;
16411688
@@ -1688,6 +1735,13 @@ static int ucsi_init(struct ucsi *ucsi) · 46 unmodified lines
16881735
16891736 ucsi->connector = connector;
16901737 ucsi->ntfy = ntfy;
1738+
1739+ ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
1740+ if (ret)
1741+ return ret;
1742+ if (UCSI_CCI_CONNECTOR(READ_ONCE(cci)))
1743+ ucsi_connector_change(ucsi, cci);
1744+
16911745 return 0;
16921746
16931747 err_unregister:
drivers/usb/typec/ucsi/ucsi.h+3−2
@@ -206,7 +206,7 @@ struct ucsi_capability { · 205 unmodified lines
206206 #define UCSI_CAP_ATTR_POWER_OTHER BIT(10)
207207 #define UCSI_CAP_ATTR_POWER_VBUS BIT(14)
208208 u8 num_connectors;
209− u8 features;
209+ u16 features;
210210 #define UCSI_CAP_SET_UOM BIT(0)
211211 #define UCSI_CAP_SET_PDM BIT(1)
212212 #define UCSI_CAP_ALT_MODE_DETAILS BIT(2)
@@ -215,7 +215,8 @@ struct ucsi_capability { · 2 unmodified lines
215215 #define UCSI_CAP_CABLE_DETAILS BIT(5)
216216 #define UCSI_CAP_EXT_SUPPLY_NOTIFICATIONS BIT(6)
217217 #define UCSI_CAP_PD_RESET BIT(7)
218− u16 reserved_1;
218+#define UCSI_CAP_GET_PD_MESSAGE BIT(8)
219+ u8 reserved_1;
219220 u8 num_alt_modes;
220221 u8 reserved_2;
221222 u16 bc_version;
drivers/usb/typec/ucsi/ucsi_acpi.c+33−42
@@ -23,10 +23,11 @@ struct ucsi_acpi { · 22 unmodified lines
2323 void *base;
2424 struct completion complete;
2525 unsigned long flags;
26+#define UCSI_ACPI_SUPPRESS_EVENT 0
27+#define UCSI_ACPI_COMMAND_PENDING 1
28+#define UCSI_ACPI_ACK_PENDING 2
2629 guid_t guid;
2730 u64 cmd;
28− bool dell_quirk_probed;
29− bool dell_quirk_active;
3031 };
3132
3233 static int ucsi_acpi_dsm(struct ucsi_acpi *ua, int func)
@@ -79,9 +80,9 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, · 46 unmodified lines
7980 int ret;
8081
8182 if (ack)
82− set_bit(ACK_PENDING, &ua->flags);
83+ set_bit(UCSI_ACPI_ACK_PENDING, &ua->flags);
8384 else
84− set_bit(COMMAND_PENDING, &ua->flags);
85+ set_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags);
8586
8687 ret = ucsi_acpi_async_write(ucsi, offset, val, val_len);
8788 if (ret)
@@ -92,9 +93,9 @@ static int ucsi_acpi_sync_write(struct ucsi *ucsi, unsigned int offset, · 4 unmodified lines
9293
9394 out_clear_bit:
9495 if (ack)
95− clear_bit(ACK_PENDING, &ua->flags);
96+ clear_bit(UCSI_ACPI_ACK_PENDING, &ua->flags);
9697 else
97− clear_bit(COMMAND_PENDING, &ua->flags);
98+ clear_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags);
9899
99100 return ret;
100101 }
@@ -129,51 +130,40 @@ static const struct ucsi_operations ucsi_zenbook_ops = { · 28 unmodified lines
129130 };
130131
131132 /*
132− * Some Dell laptops expect that an ACK command with the
133− * UCSI_ACK_CONNECTOR_CHANGE bit set is followed by a (separate)
134− * ACK command that only has the UCSI_ACK_COMMAND_COMPLETE bit set.
135− * If this is not done events are not delivered to OSPM and
136− * subsequent commands will timeout.
133+ * Some Dell laptops don't like ACK commands with the
134+ * UCSI_ACK_CONNECTOR_CHANGE but not the UCSI_ACK_COMMAND_COMPLETE
135+ * bit set. To work around this send a dummy command and bundle the
136+ * UCSI_ACK_CONNECTOR_CHANGE with the UCSI_ACK_COMMAND_COMPLETE
137+ * for the dummy command.
137138 */
138139 static int
139140 ucsi_dell_sync_write(struct ucsi *ucsi, unsigned int offset,
140141 const void *val, size_t val_len)
141142 {
142143 struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi);
143− u64 cmd = *(u64 *)val, ack = 0;
144+ u64 cmd = *(u64 *)val;
145+ u64 dummycmd = UCSI_GET_CAPABILITY;
144146 int ret;
145147
146− if (UCSI_COMMAND(cmd) == UCSI_ACK_CC_CI &&
147− cmd & UCSI_ACK_CONNECTOR_CHANGE)
148− ack = UCSI_ACK_CC_CI | UCSI_ACK_COMMAND_COMPLETE;
149−
150− ret = ucsi_acpi_sync_write(ucsi, offset, val, val_len);
151− if (ret != 0)
152− return ret;
153− if (ack == 0)
154− return ret;
155−
156− if (!ua->dell_quirk_probed) {
157− ua->dell_quirk_probed = true;
158−
159− cmd = UCSI_GET_CAPABILITY;
160− ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd,
161− sizeof(cmd));
162− if (ret == 0)
163− return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL,
164− &ack, sizeof(ack));
165− if (ret != -ETIMEDOUT)
148+ if (cmd == (UCSI_ACK_CC_CI | UCSI_ACK_CONNECTOR_CHANGE)) {
149+ cmd |= UCSI_ACK_COMMAND_COMPLETE;
150+
151+ /*
152+ * The UCSI core thinks it is sending a connector change ack
153+ * and will accept new connector change events. We don't want
154+ * this to happen for the dummy command as its response will
155+ * still report the very event that the core is trying to clear.
156+ */
157+ set_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags);
158+ ret = ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &dummycmd,
159+ sizeof(dummycmd));
160+ clear_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags);
161+
162+ if (ret < 0)
166163 return ret;
167−
168− ua->dell_quirk_active = true;
169− dev_err(ua->dev, "Firmware bug: Additional ACK required after ACKing a connector change.\n");
170− dev_err(ua->dev, "Firmware bug: Enabling workaround\n");
171164 }
172165
173− if (!ua->dell_quirk_active)
174− return ret;
175−
176− return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &ack, sizeof(ack));
166+ return ucsi_acpi_sync_write(ucsi, UCSI_CONTROL, &cmd, sizeof(cmd));
177167 }
178168
179169 static const struct ucsi_operations ucsi_dell_ops = {
@@ -209,13 +199,14 @@ static void ucsi_acpi_notify(acpi_handle handle, u32 event, void *data) · 29 unmodified lines
209199 if (ret)
210200 return;
211201
212− if (UCSI_CCI_CONNECTOR(cci))
202+ if (UCSI_CCI_CONNECTOR(cci) &&
203+ !test_bit(UCSI_ACPI_SUPPRESS_EVENT, &ua->flags))
213204 ucsi_connector_change(ua->ucsi, UCSI_CCI_CONNECTOR(cci));
214205
215206 if (cci & UCSI_CCI_ACK_COMPLETE && test_bit(ACK_PENDING, &ua->flags))
216207 complete(&ua->complete);
217208 if (cci & UCSI_CCI_COMMAND_COMPLETE &&
218− test_bit(COMMAND_PENDING, &ua->flags))
209+ test_bit(UCSI_ACPI_COMMAND_PENDING, &ua->flags))
219210 complete(&ua->complete);
220211 }
221212
drivers/usb/typec/ucsi/ucsi_glink.c+14−0
@@ -255,6 +255,20 @@ static void pmic_glink_ucsi_notify(struct work_struct *work) · 254 unmodified lines
255255 static void pmic_glink_ucsi_register(struct work_struct *work)
256256 {
257257 struct pmic_glink_ucsi *ucsi = container_of(work, struct pmic_glink_ucsi, register_work);
258+ int orientation;
259+ int i;
260+
261+ for (i = 0; i < PMIC_GLINK_MAX_PORTS; i++) {
262+ if (!ucsi->port_orientation[i])
263+ continue;
264+ orientation = gpiod_get_value(ucsi->port_orientation[i]);
265+
266+ if (orientation >= 0) {
267+ typec_switch_set(ucsi->port_switch[i],
268+ orientation ? TYPEC_ORIENTATION_REVERSE
269+ : TYPEC_ORIENTATION_NORMAL);
270+ }
271+ }
258272
259273 ucsi_register(ucsi->ucsi);
260274 }