Re: [PATCH] usb: misc: usbtest: fix pattern tests for scatterlists.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03.05.2016 17:37, Alan Stern wrote:
On Tue, 3 May 2016, Felipe Balbi wrote:

Hi,

Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> writes:
On Mon, 2 May 2016, Mathias Nyman wrote:

The current implemenentation restart the sent pattern for each entry in
the sg list. The receiving end expects a continuous pattern, and test
will fail unless scatterilst entries happen to be aligned with the
pattern

Ah.  We didn't spot this earlier because for non-xHCI controllers, the
scatterlist entries _must_ be aligned with the maxpacket size and
therefore with the pattern.

interesting. We actually found a similar issue with XHCI. scatterlist
has to be aligned to wMaxPacketSize but only before a link TRB. Mathias
has been working on a solution which involves memcpy()ing enough bytes
to align to wMaxPacketSize before the link TRB (it's very infrequent as
we have 256 TRBs per segment on XHCI), but if you know of a nicer way,
we're all ears :-)

You should be able to handle this without memcpy'ing anything.

If the individual scatterlist entries are large enough, you can simply
end the ring segment early.  Either put a link TRB before the physical
segment end, at the last point where the cumulative transfer size is
divisible by maxpacket, or else fill out from there to the end of the
segment with no-op TRBs.  Common case: Each scatterlist entry is a
multiple of 512 bytes and the maxpacket size is 1024.  Then you either
have to split the last entry in two or move it completely into the next
ring segment.

This approach doesn't work quite as well if the scatterlist entries are
very small.  For instance, if they are 8 bytes or smaller then you
might have to fill out the segment with 128 or more no-op TRBs, which
is not so good if the segment can hold only 256 TRBs.  I suppose we
could simply rule this out by requiring SG transfers to have a minimum
entry size of 128 bytes, or something like that.


First idea involved 3 steps to align the last trb.
1. If possible split the trb, doable if it contains a maxpacket boundary, else
2. Roll back to a maxpacket boundary trb, split it and set link trb mid segment.
3. If that is not possible use a bounce buffer.

While working on step 2 in noticed that I was rewriting way too much of xhci,
probably creating more regressions than solving alignment issues,
so current implementation just tries to split the trb, if it fails it will
use a bounce buffer.

And the bounce buffer part was a lot simpler than I first expected, I only
need to memcpy up to maxpacket size bytes in the worst case, and I can allocate a
maxpacket size bounce buffer in advance for every ring segment. I only need
to do a memcpy and dma map/unmap if bounce buffers are needed.

so far it passes all usbtest out tests, even with varying size scatterlists
with a small max side. In tranfsers are not yet ready

Once this is working, it can be optimized later with adding the mid-segment link
trb solution.

I'll post it as a RFC once I get the the in direction working

I hope most cases can be resolved by just splitting the TRB at maxpacket boundary.

-Mathias

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux