From: "Neronin, Niklas" <niklas.neronin@linux.intel.com>
To: "Michał Pecio" <michal.pecio@gmail.com>
Cc: linux-usb@vger.kernel.org, mathias.nyman@linux.intel.com
Subject: Re: [PATCH 3/4] usb: xhci: rework and simplify trb_in_td()
Date: Thu, 20 Feb 2025 14:25:29 +0200 [thread overview]
Message-ID: <662c15fb-ab70-4283-9fb0-b4075fba926e@linux.intel.com> (raw)
In-Reply-To: <20250219095637.5bd6e9e4@foxbook>
On 19/02/2025 10.56, Michał Pecio wrote:
> Hi,
>
>> + /* Edge case, the TD wrapped around to the start segment. */
>> + if (xhci_trb_virt_to_dma(td->end_seg, td->end_trb) < dma &&
>> + dma < xhci_trb_virt_to_dma(td->start_seg, td->start_trb))
>> + return NULL;
>> + if (seg->dma <= dma && dma <= (seg->dma + TRB_SEGMENT_SIZE))
>
> It should be strict inequality for the upper bound here.
Thanks, you are correct. I'll change this to in_range64() and the bellow to !in_range64().
>
>> + /* Loop through segment which don't contain the DMA address. */
>> + while (dma < seg->dma || (seg->dma + TRB_SEGMENT_SIZE) <= dma) {
>
> Maybe a comment here? Something like:
>
> * At this point seg contains the dma and either:
> * a. start_seg != end_seg and seg can be anywhere
> * b. start_seg == end_seg in wraparound case and seg != start_seg
Sure, I'll add some comments.
>
>> + if (seg == td->start_seg) {
>> + if (dma < xhci_trb_virt_to_dma(td->start_seg, td->start_trb))
>> + return NULL;
>> + } else if (seg == td->end_seg) {
>> + if (xhci_trb_virt_to_dma(td->end_seg, td->end_trb) < dma)
>> + return NULL;
>> + }
>> + return seg;
>
> This should be corrent, but it's not something immediately obvious.
>
> Not sure if this new implementation is really simpler than the old one.
> I wonder if it wouldn't make sense to reorder this after the API change
> (patch 4/4) to allow emergency revert if something unexpected shows up.
I'll try this, the only issue is that the new API defines the range from;
'start_trb' in 'start_seg' to 'end_trb' in 'end_seg'.
But the current version does not use 'end_seg'. So, if check checkpatch.pl
does not complain about unused 'end_seg' variable I will swap patch 4 and 5 places.
>
> As for efficiency, those virt_to_dma translations aren't exactly free
> and there are two. Maybe it could be faster to translate dma to virt
> once and then compare.
I tried introducing xhci_dma_to_trb_virt() in this patch set, but decided against it.
In my opinion it is very minor optimization and I would rather introduce this function
in a separate patch set. I reworked trb_in_td() with this change in mind.
> Sometimes also sizeof(*) < sizeof(dma_addr_t).
This is an interesting idea. I just created a reverse xhci_virt_trb_to_dma(), i.e. xhci_dma_to_virt_trb().
I'll explore this idea. Thanks.
>
> Regards,
> Michal
next prev parent reply other threads:[~2025-02-20 12:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 10:34 [PATCH 0/4] usb: xhci: improve trb_in_td() Niklas Neronin
2025-02-06 10:34 ` [PATCH 1/4] usb: xhci: refactor trb_in_td() to be static Niklas Neronin
2025-02-06 10:34 ` [PATCH 2/4] usb: xhci: move debug capabilities from trb_in_td() to handle_tx_event() Niklas Neronin
2025-03-05 8:46 ` Michał Pecio
2025-03-05 9:17 ` Neronin, Niklas
2025-02-06 10:34 ` [PATCH 3/4] usb: xhci: rework and simplify trb_in_td() Niklas Neronin
2025-02-19 8:56 ` Michał Pecio
2025-02-19 14:25 ` Mathias Nyman
2025-02-20 12:14 ` [PATCH 5/4 RFC] An alternative dma_in_range() implementation Michał Pecio
2025-02-20 13:18 ` Neronin, Niklas
2025-02-20 12:25 ` Neronin, Niklas [this message]
2025-02-06 10:34 ` [PATCH 4/4] usb: xhci: modify trb_in_td() to be more modular Niklas Neronin
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=662c15fb-ab70-4283-9fb0-b4075fba926e@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=michal.pecio@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox