On Thu, 5 Apr 2018, Guido Kiener wrote:
> > Well, I'm quite happy with the performance of the new ioctl functions
> > for generic read/write and I don't want to start a lengthy discussion
> > here.
> > However I need some expert knowledge and hints about the following
> > questions:
> > 1. We can detect short USB packages. A ZLP (Zero Length Package) can
> > happen when the previous package has the maximum packet length.
> > The driver could be simplified if it would be possible to detect ZLPs.
>
> How can it be simplified?
>
> [gk] A generic_read operation (from Bulk IN) could return immediately upon
> detecting a short package or a ZLP.
[The correct term is "packet", not "package".]
> When a driver reads a package with maximum package length then it cannot
> decide whether another package will follow or not.
Not true; it _can_ tell. If the total amount of data received so far
was less than the amount that the URB requested, then another packet
_will_ follow. If the total amount of data is equal to the amount
that the URB requested then another packet will _not_ follow.
(And if the total amount of data is larger than the amount that the
URB requested, an overrun error has occurred.)
> That means when I submit an URB with 4kB and the driver reads exactly 4kB +
> ZLP then the URB is completed but it does not signal that a ZLP was received
> as well. Submitting an extra URB will just wait for the next data package and
> does not return, since a ZLP is like an empty string.
This is incorrect, and it indicates a misunderstanding of how the USB
bulk protocol works.
Suppose you submit a 4-KB URB, and the driver reads exactly 4 KB. The
URB will be complete at that time; no ZLP will be sent because the
host will not ask the device to send any more packets.
In short, the device will send a bulk ZLP _only_ under the following
conditions:
The amount of data it wants to send is less than what the host
expects to receive, and the amount is a multiple of the maximum
packet length; or
The host wants to receive a zero-length message (rather
unlikely, but I suppose this could happen).
If your communication protocol does not allow the device to know how
much data the host expects to receive, but a ZLP can mess up the
protocol, then the protocol is buggy and needs to be fixed.
> Of course we can work around this problem when we read the header with a
> single URB and calculate the expected package size and then submit more URBs.
There should not be any problem to work around.
> > Is there any way (without changing the USB subsystem) to detect ZLPs?
>
> On an urb you send, just set URB_ZERO_PACKET, right? What else do you need?
>
> [gk] For Bulk OUT transfers the USBTMC protocol does not use ZLP. The
> generic_write operation works pretty well.
Bulk-OUT transfers never use ZLP, unless for some reason the host
wants to send a message containing no data.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html