FAILED: patch "[PATCH] usb: cdnsp: fix wakeup from S3 after controller context loss" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-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-6.18.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 '2026090842-ploy-extras-6ca8@gregkh' --subject-prefix 'PATCH 6.18.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/1 usb: cdnsp: fix wakeup from S3 after controller context loss
From: 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
@@ -1820,6 +1820,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;
@@ -1885,6 +1961,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,
@@ -2015,9 +2093,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);
@@ -2031,12 +2106,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. */
@@ -2044,9 +2145,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