devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Wesley Cheng <quic_wcheng@quicinc.com>,
	agross@kernel.org, andersson@kernel.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
	catalin.marinas@arm.com, will@kernel.org,
	mathias.nyman@intel.com, gregkh@linuxfoundation.org,
	lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
	tiwai@suse.com, srinivas.kandagatla@linaro.org,
	bgoswami@quicinc.com, Thinh.Nguyen@synopsys.com
Cc: linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org,
	alsa-devel@alsa-project.org, quic_jackp@quicinc.com,
	pierre-louis.bossart@linux.intel.com, oneukum@suse.com,
	albertccwang@google.com, o-takashi@sakamocchi.jp
Subject: Re: [PATCH v4 04/32] usb: host: xhci-mem: Cleanup pending secondary event ring events
Date: Thu, 3 Aug 2023 13:33:56 +0300	[thread overview]
Message-ID: <7b31b220-6fd5-0f5d-7e1a-df3f38bd792f@linux.intel.com> (raw)
In-Reply-To: <20230725023416.11205-5-quic_wcheng@quicinc.com>

On 25.7.2023 5.33, Wesley Cheng 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 updating the
> dequeue pointer to the last pending event trb.
> 
> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
> ---
>   drivers/usb/host/xhci-mem.c | 74 ++++++++++++++++++++++++++++++++++---
>   1 file changed, 69 insertions(+), 5 deletions(-)

This sounds more like ring handling code.
Maybe xhci-ring.c would be a better place

> 
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index c51150af22f2..6b01d56c176f 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -1799,17 +1799,85 @@ int xhci_alloc_erst(struct xhci_hcd *xhci,
>   	return 0;
>   }
>   
> +static void xhci_handle_sec_intr_events(struct xhci_hcd *xhci,
> +	struct xhci_ring *ring,	struct xhci_intr_reg __iomem *ir_set,
> +	struct xhci_erst *erst)
> +{

The function name is a bit misleading as it doesn't handle
any of the pending events, it just marks them all handled.

> +	union xhci_trb *erdp_trb, *current_trb;
> +	struct xhci_segment	*seg;
> +	u64 erdp_reg;
> +	u32 iman_reg;
> +	dma_addr_t deq;
> +	unsigned long segment_offset;
> +
> +	/* disable irq, ack pending interrupt and ack all pending events */
> +	iman_reg = readl_relaxed(&ir_set->irq_pending);
> +	iman_reg &= ~IMAN_IE;
> +	writel_relaxed(iman_reg, &ir_set->irq_pending);
> +	iman_reg = readl_relaxed(&ir_set->irq_pending);
> +	if (iman_reg & IMAN_IP)
> +		writel_relaxed(iman_reg, &ir_set->irq_pending);

maybe use xhci_disable_interrupter() helper, it does most of this already.

> +
> +	/* last acked event trb is in erdp reg  */
> +	erdp_reg = xhci_read_64(xhci, &ir_set->erst_dequeue);
> +	deq = (dma_addr_t)(erdp_reg & ~ERST_PTR_MASK);
> +	if (!deq) {
> +		xhci_dbg(xhci, "event ring handling not required\n");
> +		return;
> +	}
> +
> +	seg = ring->first_seg;
> +	segment_offset = deq - seg->dma;
> +
> +	/* find out virtual address of the last acked event trb */
> +	erdp_trb = current_trb = &seg->trbs[0] +
> +				(segment_offset/sizeof(*current_trb));
> +
> +	/* 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;
> +
> +	while (1) {
> +		/* last trb of the event ring: toggle cycle state */
> +		if (current_trb == &seg->trbs[TRBS_PER_SEGMENT - 1]) {
> +			ring->cycle_state ^= 1;
> +			current_trb = &seg->trbs[0];
> +		} else {
> +			current_trb++;
> +		}
> +
> +		/* cycle state transition */
> +		if ((le32_to_cpu(current_trb->event_cmd.flags) & TRB_CYCLE) !=
> +		    ring->cycle_state)
> +			break;
> +	}
> +
> +	if (erdp_trb != current_trb) {
> +		deq = xhci_trb_virt_to_dma(ring->deq_seg, current_trb);
> +		if (deq == 0)
> +			xhci_warn(xhci,
> +				"WARN invalid SW event ring dequeue ptr.\n");
> +		/* Update HC event ring dequeue pointer */
> +		erdp_reg &= ERST_PTR_MASK;
> +		erdp_reg |= ((u64) deq & (u64) ~ERST_PTR_MASK);
> +	}
> +
> +	/* Clear the event handler busy flag (RW1C); event ring is empty. */
> +	erdp_reg |= ERST_EHB;
> +	xhci_write_64(xhci, erdp_reg, &ir_set->erst_dequeue);

There are some helpers like inc_deq() and  xhci_update_erst_dequeue()
that could be used here.

> +}
> +
>   static void
>   xhci_free_interrupter(struct xhci_hcd *xhci, struct xhci_interrupter *ir)
>   {
>   	struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
>   	size_t erst_size;
> -	u64 tmp64;
>   	u32 tmp;
>   
>   	if (!ir)
>   		return;
>   
> +	xhci_handle_sec_intr_events(xhci, ir->event_ring, ir->ir_set, &ir->erst);

Cleaning up the interrupter event ring should be called earlier.
  
Probably from xhci_remove_secondary_interrupter(), before it calls xhci_free_interrupter()

Thanks
-Mathias



  reply	other threads:[~2023-08-03 10:33 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25  2:33 [PATCH v4 00/32] Introduce QC USB SND audio offloading support Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 01/32] xhci: add support to allocate several interrupters Wesley Cheng
2023-07-25  5:35   ` Greg KH
2023-07-25 10:00   ` Oliver Neukum
2023-07-25  2:33 ` [PATCH v4 02/32] xhci: add helper to stop endpoint and wait for completion Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 03/32] xhci: sideband: add initial api to register a sideband entity Wesley Cheng
2023-07-25  2:57   ` Randy Dunlap
2023-07-25  2:33 ` [PATCH v4 04/32] usb: host: xhci-mem: Cleanup pending secondary event ring events Wesley Cheng
2023-08-03 10:33   ` Mathias Nyman [this message]
2023-07-25  2:33 ` [PATCH v4 05/32] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 06/32] ASoC: Add SOC USB APIs for adding an USB backend Wesley Cheng
2023-07-25  8:10   ` Pierre-Louis Bossart
2023-07-25 23:17     ` Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 07/32] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 08/32] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Wesley Cheng
2023-07-25  8:27   ` Pierre-Louis Bossart
2023-08-07 23:39     ` Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 09/32] ASoC: qdsp6: q6afe: Increase APR timeout Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 10/32] ASoC: qcom: Add USB backend ASoC driver for Q6 Wesley Cheng
2023-07-25  8:45   ` Pierre-Louis Bossart
2023-08-08  0:50     ` Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 11/32] sound: usb: card: Introduce USB SND platform op callbacks Wesley Cheng
2023-07-25  6:55   ` Takashi Iwai
2023-07-25  2:33 ` [PATCH v4 12/32] sound: usb: Export USB SND APIs for modules Wesley Cheng
2023-07-25  5:04   ` Trilok Soni
2023-07-25  5:33   ` Greg KH
2023-07-25  6:52     ` Takashi Iwai
2023-07-25  2:33 ` [PATCH v4 13/32] dt-bindings: usb: dwc3: Add snps,num-hc-interrupters definition Wesley Cheng
2023-07-26 17:19   ` Rob Herring
2023-08-29  6:31   ` Krzysztof Kozlowski
2023-07-25  2:33 ` [PATCH v4 14/32] usb: dwc3: Add DT parameter to specify maximum number of interrupters Wesley Cheng
2023-07-25  2:33 ` [PATCH v4 15/32] usb: host: xhci-plat: Set XHCI max interrupters if property is present Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 16/32] sound: usb: pcm: Export fixed rate check USB SND API Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 17/32] sound: usb: qcom: Add USB QMI definitions Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 18/32] sound: usb: Introduce QC USB SND offloading support Wesley Cheng
2023-07-25  2:57   ` Randy Dunlap
2023-07-25  7:26   ` Takashi Iwai
2023-07-25 22:59     ` Wesley Cheng
2023-07-26 12:31       ` Takashi Iwai
2023-07-25  2:34 ` [PATCH v4 19/32] sound: usb: card: Check for support for requested audio format Wesley Cheng
2023-07-25  6:57   ` Takashi Iwai
2023-07-25  2:34 ` [PATCH v4 20/32] sound: soc: soc-usb: Add PCM format check API for USB backend Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 21/32] sound: soc: qcom: qusb6: Ensure PCM format is supported by USB audio device Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 22/32] sound: usb: Prevent starting of audio stream if in use Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 23/32] ASoC: dt-bindings: Add Q6USB backend bindings Wesley Cheng
2023-07-26  8:00   ` Krzysztof Kozlowski
2023-07-25  2:34 ` [PATCH v4 24/32] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Wesley Cheng
2023-07-25  4:26   ` Rob Herring
2023-07-25  2:34 ` [PATCH v4 25/32] ASoC: qcom: qdsp6: q6afe: Split USB AFE dev_token param into separate API Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 26/32] sound: Pass USB SND card and PCM information to SOC USB Wesley Cheng
2023-07-25  8:59   ` Pierre-Louis Bossart
2023-08-15  1:48     ` Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 27/32] sound: soc: qdsp6: Add SND kcontrol to select offload device Wesley Cheng
2023-07-25  9:16   ` Pierre-Louis Bossart
2023-07-26 23:06     ` Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 28/32] sound: soc: qdsp6: Add SND kcontrol for fetching offload status Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 29/32] sound: soc: qcom: q6usb: Add headphone jack for offload connection status Wesley Cheng
2023-07-25  9:10   ` Pierre-Louis Bossart
2023-08-16  1:11     ` Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 30/32] sound: usb: qc_audio_offload: Use card and PCM index from QMI request Wesley Cheng
2023-07-25  2:34 ` [PATCH v4 31/32] sound: usb: card: Allow for rediscovery of connected USB SND devices Wesley Cheng
2023-07-25  9:15   ` Pierre-Louis Bossart
2023-07-25  9:27     ` Takashi Iwai
2023-08-28 21:25       ` Wesley Cheng
2023-08-29 14:06         ` Takashi Iwai
2023-08-16  1:38     ` Wesley Cheng
2023-08-16 15:35       ` Pierre-Louis Bossart
2023-07-25  2:34 ` [PATCH v4 32/32] sound: soc: soc-usb: Rediscover USB SND devices on USB port add Wesley Cheng
2023-07-25  2:38 ` [PATCH v4 00/32] Introduce QC USB SND audio offloading support 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=7b31b220-6fd5-0f5d-7e1a-df3f38bd792f@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=agross@kernel.org \
    --cc=albertccwang@google.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andersson@kernel.org \
    --cc=bgoswami@quicinc.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=o-takashi@sakamocchi.jp \
    --cc=oneukum@suse.com \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=quic_jackp@quicinc.com \
    --cc=quic_wcheng@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    --cc=will@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).