All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Petar Stepanovic" <pstepanovic@axiado.com>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v8 3/6] usb: gadget: udc: crg: Add ring and transfer management
Date: Fri, 04 Dec 2026 01:53:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-248919@kernel.org> (raw)
In-Reply-To: <20261203-axiado-ax3000-usb-device-controller-v8-3-d5ff04febd4d@axiado.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] usb: crg-udc: inconsistent 64-bit ERDP register write ordering
- [Medium] usb: crg-udc: crg_udc_process_event_ring() clears EHB during
  mid-loop updates
- [Medium] usb: gadget: crg: hardcoded 1 ms IMOD in
  crg_udc_init_event_ring()
- [Medium] usb: gadget: crg: O(N) queue rescan in
  crg_udc_queue_pending_trbs()
- [Low] usb: crg-udc: is_event_ring_x_empty() returns false for NULL
  evt_dq_pt
- [Low] usb: crg-udc: crg_udc_init_event_ring() leaves dangling p_erst
  on error
--

commit 4a3fd79c321389033ba5d6fa8e483d94d81ca93b
Author: Petar Stepanovic <pstepanovic@axiado.com>

usb: gadget: udc: crg: Add ring and transfer management

This commit adds drivers/usb/gadget/udc/crg/crg-udc-ring.c implementing
event ring initialization and processing, TRB setup helpers, and transfer
ring management for the Axiado AX3000/AX3005 UDC.

> diff --git a/drivers/usb/gadget/udc/crg/crg-udc-ring.c b/drivers/usb/gadget/udc/crg/crg-udc-ring.c
> new file mode 100644
> index 0000000000000..6b2f0d2e781ed
> --- /dev/null
> +++ b/drivers/usb/gadget/udc/crg/crg-udc-ring.c
> @@ -0,0 +1,725 @@

[ ... ]

> +	writel(CRG_ERST_SIZE, &uicr->erstsz);
> +	writel(lower_32_bits(udc_event->erst.dma_addr), &uicr->erstbalo);
> +	writel(upper_32_bits(udc_event->erst.dma_addr), &uicr->erstbahi);
> +	writel(lower_32_bits(udc_event->event_ring.dma_addr) |
> +		       CRG_U3DC_ERDPLO_EHB,
> +	       &uicr->erdplo);
> +	writel(upper_32_bits(udc_event->event_ring.dma_addr), &uicr->erdphi);

[Severity: High]
Which write order commits the 64-bit Event Ring Dequeue Pointer on this
controller?  crg_udc_init_event_ring() writes erdplo (with
CRG_U3DC_ERDPLO_EHB set) before erdphi, whereas crg_udc_process_event_ring()
writes erdphi before erdplo in both its batch and final updates.

Because the probe path sets a 64-bit DMA mask, whichever path disagrees with
the hardware latch order can commit a torn 64-bit ERDP or clear EHB
prematurely, risking a corrupted dequeue pointer, stalled event processing,
or missed interrupts.  Also, crg_udc_init_event_ring() enables uicr->iman
before programming uicr->imod.

> +
> +	writel((CRG_U3DC_IMAN_INT_EN | CRG_U3DC_IMAN_INT_PEND), &uicr->iman);
> +	/* Interrupt moderation: 4000 * 250ns = 1ms */
> +	writel(4000, &uicr->imod);

[Severity: Medium]
Is hardcoding a 1 ms interrupt moderation interval (4000 * 250 ns) on the
sole event ring interrupter intended?  All 32 endpoints share a single
256-entry event ring (CRG_EVENT_RING_SIZE), so capping completions at 1,000
IRQs/sec adds up to 1 ms latency per transaction phase, introduces jitter on
125 us isochronous transfers, and risks event ring overflow under SuperSpeed
traffic.  Other xHCI-style USB3 UDC drivers (such as cdnsp and tegra-xudc)
default IMOD to 0.

> +	return 0;
> +
> +err_free_erst:
> +	/* Only free what this call allocated; a pre-existing erst is owned
> +	 * by an earlier successful init and released by crg_udc_free_resources().
> +	 */
> +	if (erst_allocated) {
> +		dma_free_coherent(crg_udc->dev, udc_event->erst.len,
> +				  udc_event->erst.cpu_addr,
> +				  udc_event->erst.dma_addr);
> +		udc_event->erst.cpu_addr = NULL;
> +	}
> +	return ret;
> +}

[Severity: Low]
When the event_ring allocation fails after erst was allocated, should this
error path also clear udc_event->p_erst, udc_event->erst.dma_addr, and
udc_event->erst.len?  Clearing only udc_event->erst.cpu_addr leaves p_erst
dangling and the remaining erst fields stale.

> +
> +static bool is_event_ring_x_empty(struct crg_gadget_dev *crg_udc, int index)
> +{
> +	struct crg_event_trb *event;
> +	struct crg_udc_event *udc_event;
> +
> +	udc_event = &crg_udc->udc_event[index];
> +	if (udc_event->evt_dq_pt) {
> +		event = (struct crg_event_trb *)udc_event->evt_dq_pt;
> +
> +		if (FIELD_GET(EVE_TRB_CYCLE_BIT_MASK,
> +			      le32_to_cpu(event->dw3)) != udc_event->ccs)
> +			return true;
> +	}
> +
> +	return false;
> +}

[Severity: Low]
Should is_event_ring_x_empty() return true when udc_event->evt_dq_pt is NULL?
Right now it falls through to return false, reporting an uninitialized or
freed ring as non-empty, which contradicts crg_udc_pending_event_count()
returning 0 for a NULL evt_dq_pt.  Unlike crg_udc_pending_event_count(), it
also reads DMA-written event->dw3 without READ_ONCE().

[ ... ]

> +int crg_udc_process_event_ring(struct crg_gadget_dev *crg_udc, int index,
> +			       unsigned long *flags)
> +{

[ ... ]

> +	val = readl(&uicr->iman);
> +	val |= CRG_U3DC_IMAN_INT_PEND;
> +	writel(val, &uicr->iman);

[ ... ]

> +		if (++processed % CRG_EVENT_RING_BATCH == 0) {
> +			erdp = event_trb_virt_to_dma(udc_event,
> +						     udc_event->evt_dq_pt);
> +			if (!dma_mapping_error(crg_udc->dev, erdp)) {
> +				writel(upper_32_bits(erdp), &uicr->erdphi);
> +				writel(lower_32_bits(erdp) |
> +					       CRG_U3DC_ERDPLO_EHB,
> +				       &uicr->erdplo);
> +			}

[Severity: Medium]
Can setting CRG_U3DC_ERDPLO_EHB on these mid-loop batch updates cause a
spurious trailing interrupt?  Clearing EHB while unprocessed events remain on
the ring lets hardware immediately re-assert IMAN_INT_PEND and STATUS_EINT,
and neither bit is cleared again before returning from the threaded IRQ
handler.  Omitting CRG_U3DC_ERDPLO_EHB here and clearing it only on the final
ERDP write after the loop finishes would avoid this.

[ ... ]

> +int crg_udc_queue_pending_trbs(struct crg_udc_ep *udc_ep_ptr)
> +{

[ ... ]

> +	list_for_each_entry(req, &udc_ep_ptr->queue, queue) {
> +		if (req->all_trbs_queued)
> +			continue;
> +
> +		/* A large request must finish its current TD before the next
> +		 * TD (or the next USB request) can be submitted: the event
> +		 * handler uses all_trbs_queued to complete the USB request.
> +		 */
> +		if (req->td_pending)
> +			return 0;
> +
> +		ret = crg_udc_build_td(udc_ep_ptr, req);

[Severity: Medium]
Does restarting this walk from the head of udc_ep_ptr->queue on every
completion cause O(N) lock hold times under udc_lock?  With
CRG_UDC_BULK_EP_TD_RING_SIZE at 1024, up to 1,022 in-flight requests can sit
ahead of waiting requests, leading to O(N^2) list traversal while draining a
saturated bulk queue with IRQs disabled.  Keeping a separate pending list or
tracking the first unqueued request would avoid rescanning requests that
already have all_trbs_queued set.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-axiado-ax3000-usb-device-controller-v8-0-d5ff04febd4d@axiado.com?part=3

  reply	other threads:[~2026-12-04  1:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:31 [PATCH v8 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) Petar Stepanovic
2026-12-04  1:31 ` [PATCH v8 1/6] dt-bindings: usb: gadget: udc: add Axiado AX3000 and AX3005 UDC Petar Stepanovic
2026-12-04  1:31 ` [PATCH v8 2/6] usb: gadget: udc: crg: Add hardware definitions and structs Petar Stepanovic
2026-12-04  1:53   ` sashiko-bot
2026-12-04  1:31 ` [PATCH v8 3/6] usb: gadget: udc: crg: Add ring and transfer management Petar Stepanovic
2026-12-04  1:53   ` sashiko-bot [this message]
2026-12-04  1:31 ` [PATCH v8 4/6] usb: gadget: udc: crg: Add endpoint 0 handling Petar Stepanovic
2026-12-04  2:03   ` sashiko-bot
2026-12-04  1:31 ` [PATCH v8 5/6] usb: gadget: udc: crg: Add gadget and endpoint operations Petar Stepanovic
2026-12-04  2:03   ` sashiko-bot
2026-12-04  1:31 ` [PATCH v8 6/6] usb: gadget: udc: crg: Add core driver and build integration Petar Stepanovic
2026-12-04  2:07   ` sashiko-bot
2026-12-04  2:07 ` [PATCH v8 0/6] Axiado AX3000 and AX3005 USB Device Controller (UDC) sashiko-bot

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=sashiko-outbox-248919@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pstepanovic@axiado.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.