All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jung Daehwan <dh10.jung@samsung.com>
To: Puma Hsu <pumahsu@google.com>
Cc: Wesley Cheng <quic_wcheng@quicinc.com>,
	srinivas.kandagatla@linaro.org, mathias.nyman@intel.com,
	perex@perex.cz, conor+dt@kernel.org, dmitry.torokhov@gmail.com,
	corbet@lwn.net, broonie@kernel.org, lgirdwood@gmail.com,
	krzk+dt@kernel.org, pierre-louis.bossart@linux.intel.com,
	Thinh.Nguyen@synopsys.com, tiwai@suse.com, robh@kernel.org,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linux-sound@vger.kernel.org,
	linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v36 02/31] usb: host: xhci-mem: Cleanup pending secondary event ring events
Date: Tue, 1 Apr 2025 16:51:21 +0900	[thread overview]
Message-ID: <20250401075121.GC98772@ubuntu> (raw)
In-Reply-To: <CAGCq0LYh13qaPpuM0jPyu2LV+EXqJrfoKvD-TOuhkZYScFnTNg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 8311 bytes --]

On Fri, Mar 28, 2025 at 03:42:00PM +0800, Puma Hsu wrote:
> On Wed, Mar 19, 2025 at 8:53 AM Wesley Cheng <quic_wcheng@quicinc.com> wrote:
> >
> > As part of xHCI bus suspend, the xHCI is halted.  However, if there are
> > pending events in the secondary event ring, it is observed that the xHCI
> > controller stops responding to further commands upon host or device
> > initiated bus resume.  Iterate through all pending events and update the
> > dequeue pointer to the beginning of the event ring.
> >
> > Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
> 
> Tested-by: Puma Hsu <pumahsu@google.com>
> 

 Tested-by: Daehwan Jung <dh10.jung@samsung.com>

> > ---
> >  drivers/usb/host/xhci-mem.c  |  7 +++++-
> >  drivers/usb/host/xhci-ring.c | 47 ++++++++++++++++++++++++++++++------
> >  drivers/usb/host/xhci.c      |  2 +-
> >  drivers/usb/host/xhci.h      |  7 ++++++
> >  4 files changed, 54 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> > index d698095fc88d..daea0f76e844 100644
> > --- a/drivers/usb/host/xhci-mem.c
> > +++ b/drivers/usb/host/xhci-mem.c
> > @@ -1805,7 +1805,7 @@ xhci_remove_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
> >                 tmp &= ERST_SIZE_MASK;
> >                 writel(tmp, &ir->ir_set->erst_size);
> >
> > -               xhci_write_64(xhci, ERST_EHB, &ir->ir_set->erst_dequeue);
> > +               xhci_update_erst_dequeue(xhci, ir, true);
> >         }
> >  }
> >
> > @@ -1848,6 +1848,11 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup
> >                 return;
> >         }
> >
> > +       /*
> > +        * Cleanup secondary interrupter to ensure there are no pending events.
> > +        * This also updates event ring dequeue pointer back to the start.
> > +        */
> > +       xhci_skip_sec_intr_events(xhci, ir->event_ring, ir);
> >         intr_num = ir->intr_num;
> >
> >         xhci_remove_interrupter(xhci, ir);
> > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > index 5d64c297721c..bfef765dd78c 100644
> > --- a/drivers/usb/host/xhci-ring.c
> > +++ b/drivers/usb/host/xhci-ring.c
> > @@ -3054,9 +3054,9 @@ static int xhci_handle_event_trb(struct xhci_hcd *xhci, struct xhci_interrupter
> >   * - When all events have finished
> >   * - To avoid "Event Ring Full Error" condition
> >   */
> > -static void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
> > -                                    struct xhci_interrupter *ir,
> > -                                    bool clear_ehb)
> > +void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
> > +                             struct xhci_interrupter *ir,
> > +                             bool clear_ehb)
> >  {
> >         u64 temp_64;
> >         dma_addr_t deq;
> > @@ -3099,10 +3099,11 @@ static void xhci_clear_interrupt_pending(struct xhci_interrupter *ir)
> >   * Handle all OS-owned events on an interrupter event ring. It may drop
> >   * and reaquire xhci->lock between event processing.
> >   */
> > -static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
> > +static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir,
> > +                             bool skip_events)
> >  {
> >         int event_loop = 0;
> > -       int err;
> > +       int err = 0;
> >         u64 temp;
> >
> >         xhci_clear_interrupt_pending(ir);
> > @@ -3125,7 +3126,8 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir
> >
> >         /* Process all OS owned event TRBs on this event ring */
> >         while (unhandled_event_trb(ir->event_ring)) {
> > -               err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue);
> > +               if (!skip_events)
> > +                       err = xhci_handle_event_trb(xhci, ir, ir->event_ring->dequeue);
> >
> >                 /*
> >                  * If half a segment of events have been handled in one go then
> > @@ -3152,6 +3154,37 @@ static int xhci_handle_events(struct xhci_hcd *xhci, struct xhci_interrupter *ir
> >         return 0;
> >  }
> >
> > +/*
> > + * Move the event ring dequeue pointer to skip events kept in the secondary
> > + * event ring.  This is used to ensure that pending events in the ring are
> > + * acknowledged, so the xHCI HCD can properly enter suspend/resume.  The
> > + * secondary ring is typically maintained by an external component.
> > + */
> > +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci,
> > +                              struct xhci_ring *ring,  struct xhci_interrupter *ir)
> > +{
> > +       union xhci_trb *current_trb;
> > +       u64 erdp_reg;
> > +       dma_addr_t deq;
> > +
> > +       /* disable irq, ack pending interrupt and ack all pending events */
> > +       xhci_disable_interrupter(ir);
> > +
> > +       /* last acked event trb is in erdp reg  */
> > +       erdp_reg = xhci_read_64(xhci, &ir->ir_set->erst_dequeue);
> > +       deq = (dma_addr_t)(erdp_reg & ERST_PTR_MASK);
> > +       if (!deq) {
> > +               xhci_err(xhci, "event ring handling not required\n");
> > +               return;
> > +       }
> > +
> > +       current_trb = ir->event_ring->dequeue;
> > +       /* read cycle state of the last acked trb to find out CCS */
> > +       ring->cycle_state = le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYCLE;
> > +
> > +       xhci_handle_events(xhci, ir, true);
> > +}
> > +
> >  /*
> >   * xHCI spec says we can get an interrupt, and if the HC has an error condition,
> >   * we might get bad data out of the event ring.  Section 4.10.2.7 has a list of
> > @@ -3196,7 +3229,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
> >         writel(status, &xhci->op_regs->status);
> >
> >         /* This is the handler of the primary interrupter */
> > -       xhci_handle_events(xhci, xhci->interrupters[0]);
> > +       xhci_handle_events(xhci, xhci->interrupters[0], false);
> >  out:
> >         spin_unlock(&xhci->lock);
> >
> > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> > index 83a4adf57bae..61950a350432 100644
> > --- a/drivers/usb/host/xhci.c
> > +++ b/drivers/usb/host/xhci.c
> > @@ -335,7 +335,7 @@ static int xhci_enable_interrupter(struct xhci_interrupter *ir)
> >         return 0;
> >  }
> >
> > -static int xhci_disable_interrupter(struct xhci_interrupter *ir)
> > +int xhci_disable_interrupter(struct xhci_interrupter *ir)
> >  {
> >         u32 iman;
> >
> > diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> > index 39db228f0b84..3fa8669e3b2d 100644
> > --- a/drivers/usb/host/xhci.h
> > +++ b/drivers/usb/host/xhci.h
> > @@ -1856,6 +1856,9 @@ xhci_create_secondary_interrupter(struct usb_hcd *hcd, unsigned int segs,
> >                                   u32 imod_interval);
> >  void xhci_remove_secondary_interrupter(struct usb_hcd
> >                                        *hcd, struct xhci_interrupter *ir);
> > +void xhci_skip_sec_intr_events(struct xhci_hcd *xhci,
> > +                              struct xhci_ring *ring,
> > +                              struct xhci_interrupter *ir);
> >
> >  /* xHCI host controller glue */
> >  typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
> > @@ -1895,6 +1898,7 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci,
> >                 struct usb_tt *tt, gfp_t mem_flags);
> >  int xhci_set_interrupter_moderation(struct xhci_interrupter *ir,
> >                                     u32 imod_interval);
> > +int xhci_disable_interrupter(struct xhci_interrupter *ir);
> >
> >  /* xHCI ring, segment, TRB, and TD functions */
> >  dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
> > @@ -1939,6 +1943,9 @@ unsigned int count_trbs(u64 addr, u64 len);
> >  int xhci_stop_endpoint_sync(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
> >                             int suspend, gfp_t gfp_flags);
> >  void xhci_process_cancelled_tds(struct xhci_virt_ep *ep);
> > +void xhci_update_erst_dequeue(struct xhci_hcd *xhci,
> > +                             struct xhci_interrupter *ir,
> > +                             bool clear_ehb);
> >
> >  /* xHCI roothub code */
> >  void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
> >
> 
> 

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2025-04-01  7:42 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19  0:51 [PATCH v36 00/31] Introduce QC USB SND audio offloading support Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 01/31] xhci: sideband: add initial api to register a secondary interrupter entity Wesley Cheng
2025-03-27  6:27   ` Puma Hsu
2025-03-27  7:02     ` Greg KH
2025-03-27 10:14       ` Puma Hsu
2025-03-27 10:48         ` Greg KH
2025-03-28  4:08           ` Puma Hsu
2025-03-27 16:12         ` Wesley Cheng
2025-03-28  4:11           ` Puma Hsu
2025-04-01  2:23           ` Jung Daehwan
2025-04-01  6:55             ` Greg KH
2025-04-01  7:50               ` Jung Daehwan
2025-03-27 10:13   ` Puma Hsu
2025-03-19  0:51 ` [PATCH v36 02/31] usb: host: xhci-mem: Cleanup pending secondary event ring events Wesley Cheng
2025-03-28  7:42   ` Puma Hsu
2025-04-01  7:51     ` Jung Daehwan [this message]
2025-03-19  0:51 ` [PATCH v36 03/31] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Wesley Cheng
2025-03-28  7:43   ` Puma Hsu
2025-04-01  7:51     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 04/31] usb: host: xhci-plat: Set XHCI max interrupters if property is present Wesley Cheng
2025-03-28  7:44   ` Puma Hsu
2025-04-01  7:52     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 05/31] usb: host: xhci: Notify xHCI sideband on transfer ring free Wesley Cheng
2025-03-28  7:45   ` Puma Hsu
2025-04-01  7:52     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 06/31] usb: dwc3: Specify maximum number of XHCI interrupters Wesley Cheng
2025-03-28  7:46   ` Puma Hsu
2025-04-01  7:53     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 07/31] ALSA: Add USB audio device jack type Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 08/31] ALSA: usb-audio: Export USB SND APIs for modules Wesley Cheng
2025-03-28  7:47   ` Puma Hsu
2025-04-01  7:53     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 09/31] ALSA: usb-audio: Check for support for requested audio format Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 10/31] ALSA: usb-audio: Save UAC sample size information Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 11/31] ALSA: usb-audio: Prevent starting of audio stream if in use Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 12/31] ALSA: usb-audio: Introduce USB SND platform op callbacks Wesley Cheng
2025-03-28  7:48   ` Puma Hsu
2025-04-01  7:53     ` Jung Daehwan
2025-03-19  0:51 ` [PATCH v36 13/31] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 14/31] ASoC: Add SoC USB APIs for adding an USB backend Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 15/31] ASoC: usb: Add PCM format check API for " Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 16/31] ASoC: usb: Create SOC USB SND jack kcontrol Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 17/31] ASoC: usb: Fetch ASoC card and pcm device information Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 18/31] ASoC: usb: Rediscover USB SND devices on USB port add Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 19/31] ASoC: doc: Add documentation for SOC USB Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 20/31] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 21/31] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 22/31] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Wesley Cheng
2025-03-25  9:24   ` Stephan Gerhold
2025-03-25 23:18     ` Wesley Cheng
2025-03-26  9:57       ` Stephan Gerhold
2025-03-31 19:52         ` Wesley Cheng
2025-04-01  8:16           ` Stephan Gerhold
2025-04-01 23:47             ` Wesley Cheng
2025-04-02 14:41               ` Stephan Gerhold
2025-04-03  0:23                 ` Wesley Cheng
2025-04-03  0:54                   ` Wesley Cheng
2025-04-03 13:45                     ` Stephan Gerhold
2025-04-03 15:58                       ` Wesley Cheng
2025-04-03 18:00                         ` Stephan Gerhold
2025-04-03 21:00                           ` Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 23/31] ASoC: qcom: qdsp6: q6afe: Increase APR timeout Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 24/31] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 25/31] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 26/31] ASoC: qcom: qdsp6: Fetch USB offload mapped card and PCM device Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 27/31] ALSA: usb-audio: qcom: Add USB QMI definitions Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 28/31] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Wesley Cheng
2025-03-25  9:47   ` Stephan Gerhold
2025-03-26  1:32     ` Wesley Cheng
2025-03-26 10:09       ` Stephan Gerhold
2025-03-27 16:57         ` Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 29/31] ALSA: usb-audio: qcom: Don't allow USB offload path if PCM device is in use Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 30/31] ALSA: usb-audio: qcom: Add USB offload route kcontrol Wesley Cheng
2025-03-25 11:35   ` Stephan Gerhold
2025-03-26  1:42     ` Wesley Cheng
2025-03-19  0:51 ` [PATCH v36 31/31] ALSA: usb-audio: qcom: Notify USB audio devices on USB offload probing Wesley Cheng
2025-03-21 13:13 ` [PATCH v36 00/31] Introduce QC USB SND audio offloading support Luca Weiss
2025-03-21 20:06   ` Wesley Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250401075121.GC98772@ubuntu \
    --to=dh10.jung@samsung.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=pumahsu@google.com \
    --cc=quic_wcheng@quicinc.com \
    --cc=robh@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.