FAILED: patch "[PATCH] usb: cdnsp: fix wakeup from S3 after controller context loss" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x eae6460f617382044c5afe5ef202f4d8b2c099b5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090845-lyrically-primal-44f3@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From eae6460f617382044c5afe5ef202f4d8b2c099b5 Mon Sep 17 00:00:00 2001
From: Pawel Laszczak <[email protected]>
Date: Thu, 20 Aug 2026 12:45:31 +0200
Subject: [PATCH] usb: cdnsp: fix wakeup from S3 after controller context loss
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
drivers/usb/cdns3/cdnsp-gadget.c +106 -5
@@ -1338,7 +1338,6 @@ static int cdnsp_run(struct cdnsp_device *pdev, cdnsp_gadget_ep0_desc.wMaxPacketSize =cpu_to_le16 (512 ); - ret =cdnsp_start (pdev);if (ret) { ret = -ENODEV ;
@@ -1837,6 +1836,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1902,6 +1977,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2031,9 +2108,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)struct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2047,12 +2121,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power)struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || lost_power; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2060,9 +2160,10 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power) ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1510,6 +1510,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,int cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Sasha Levin
maintainerPATCH 1/3 xhci: Cleanup Candence controller PCI device and vendor ID usage
From: Mathias Nyman <[email protected]>
[ Upstream commit f28a7d7db247af8b9f1090bd6b1ca1fa48a3f0e4 ]
Use predefined PCI vendor ID constant for Cadence controller in pci_ids.h Rename the Candence device ID to match the pattern other PCI vendor and device IDs use
Stable-dep-of: eae6460f6173 ("usb: cdnsp: fix wakeup from S3 after controller context loss")
--- drivers/usb/host/xhci-pci.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-pci.c +3 -5
@@ -88,8 +88,7 @@#define PCI_DEVICE_ID_ASMEDIA_3042_XHCI 0x3042#define PCI_DEVICE_ID_ASMEDIA_3242_XHCI 0x3242 -#define PCI_DEVICE_ID_CADENCE 0x17CD -#define PCI_DEVICE_ID_CADENCE_SSP 0x0200 +#define PCI_DEVICE_ID_CDNS_SSP 0x0200static const char hcd_name[] ="xhci_hcd" ;
@@ -393,9 +392,8 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)if (pdev->device ==0x9203 ) xhci->quirks |=XHCI_TRB_OVERFETCH ; } - -if (pdev->vendor ==PCI_DEVICE_ID_CADENCE && - pdev->device ==PCI_DEVICE_ID_CADENCE_SSP ) +if (pdev->vendor ==PCI_VENDOR_ID_CDNS && + pdev->device ==PCI_DEVICE_ID_CDNS_SSP ) xhci->quirks |=XHCI_CDNS_SCTX_QUIRK ;/* xHC spec requires PCI devices to support D3hot and D3cold */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 usb: cdns3: rename hibernated argument of role->resume() to lost_power
From: Théo Lebrun <[email protected]>
[ Upstream commit 0bde749c58c72405c54a1eabf6266a0273377226 ]
The cdns_role_driver->resume() callback takes a second boolean argument named hibernated in its implementations. This is mistaken; the only potential caller is:
int cdns_resume(struct cdns *cdns)
{
/* ... */
if (cdns->roles[cdns->role]->resume)
cdns->roles[cdns->role]->resume(cdns, cdns_power_is_lost(cdns));
return 0;
}The argument can be true in cases outside of return from hibernation. Reflect the true meaning by renaming both arguments to lost_power.
Stable-dep-of: eae6460f6173 ("usb: cdnsp: fix wakeup from S3 after controller context loss")
--- drivers/usb/cdns3/cdns3-gadget.c | 4 ++-- drivers/usb/cdns3/cdnsp-gadget.c | 2 +- drivers/usb/cdns3/core.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/usb/cdns3/cdns3-gadget.c +2 -2
@@ -3479,7 +3479,7 @@ __must_hold(&cdns->lock)return 0 ; } -static int cdns3_gadget_resume (struct cdns *cdns,bool hibernated) +static int cdns3_gadget_resume (struct cdns *cdns,bool lost_power) {struct cdns3_device *priv_dev = cdns->gadget_dev;
@@ -3487,7 +3487,7 @@ static int cdns3_gadget_resume(struct cdns *cdns, bool hibernated)return 0 ;cdns3_gadget_config (priv_dev); -if (hibernated) +if (lost_power)writel (USB_CONF_DEVEN , &priv_dev->regs->usb_conf);return 0 ;
drivers/usb/cdns3/cdnsp-gadget.c +1 -1
@@ -2028,7 +2028,7 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)return 0 ; } -static int cdnsp_gadget_resume (struct cdns *cdns,bool hibernated) +static int cdnsp_gadget_resume (struct cdns *cdns,bool lost_power) {struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;
drivers/usb/cdns3/core.h +1 -1
@@ -30,7 +30,7 @@ struct cdns_role_driver {int (*start)(struct cdns *cdns);void (*stop)(struct cdns *cdns);int (*suspend)(struct cdns *cdns,bool do_wakeup); -int (*resume)(struct cdns *cdns,bool hibernated); +int (*resume)(struct cdns *cdns,bool lost_power);const char *name;#define CDNS_ROLE_STATE_INACTIVE 0#define CDNS_ROLE_STATE_ACTIVE 1
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 usb: cdnsp: fix wakeup from S3 after controller context loss
In reply to Sasha LevinFrom: Pawel Laszczak <[email protected]>
[ Upstream commit eae6460f617382044c5afe5ef202f4d8b2c099b5 ]
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
--- drivers/usb/cdns3/cdnsp-gadget.c | 110 +++++++++++++++++++++++++++++-- drivers/usb/cdns3/cdnsp-gadget.h | 1 + drivers/usb/cdns3/cdnsp-mem.c | 98 ++++++++++----------------- 3 files changed, 142 insertions(+), 67 deletions(-)
drivers/usb/cdns3/cdnsp-gadget.c +106 -4
@@ -1822,6 +1822,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1887,6 +1963,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2017,9 +2095,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)struct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2033,12 +2108,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power)struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || lost_power; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2046,9 +2147,10 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool lost_power) ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1509,6 +1509,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,int cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Signature · 1 line
2.53.0