[PATCH] USB: musb: respect usb_request->zero in control requests

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] USB: musb: respect usb_request->zero in control requests

Daniel Glöckner
In gadget mode the answer to a control request should be followed by
a zero-length packet if the amount transferred is an exact multiple of
the endpoint's packet size and the requests has its "zero" flag set.

This patch prevents the request from being immediately removed from the
queue when a control IN transfer ends on a full packet and "zero" is set.
The next time ep0_txstate is entered, a zero-length packet is queued and
the request is removed as fifo_count is 0.

Signed-off-by: Daniel Gl?ckner <[hidden email]>
---
 drivers/usb/musb/musb_gadget_ep0.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 7a67786..522efb3 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -511,7 +511,8 @@ static void ep0_txstate(struct musb *musb)
 
  /* update the flags */
  if (fifo_count < MUSB_MAX_END0_PACKET
- || request->actual == request->length) {
+ || (request->actual == request->length
+ && !request->zero)) {
  musb->ep0_state = MUSB_EP0_STAGE_STATUSOUT;
  csr |= MUSB_CSR0_P_DATAEND;
  } else
--
1.6.1.3


Reply | Threaded
Open this post in threaded view
|

[PATCH] USB: musb: respect usb_request->zero in control requests

Daniel Glöckner
On Tue, Nov 10, 2009 at 01:45:44PM -0500, Alan Stern wrote:
> I don't understand the code, but your description is wrong.  The
> response to a control-IN request should _not_ be followed by a ZLP even
> if the amount transferred is an exact multiple of the maxpacket size
> and the "zero" flag is set, provided the length is equal to the wLength
> value in the setup packet.
>
> ZLP's are used only to delimit _short_ transfers.  If the length is the
> same as what the host asked for, then it isn't short.

Drivers set the zero flag only on short transfers, usually like this:

        request->zero = (length < wLength);

See for example composite.c:composite_setup() right before usb_ep_queue
or file_storage.c:fsg_setup() right before ep0_queue.

  Daniel


--
Dipl.-Math. Daniel Gl?ckner, emlix GmbH, http://www.emlix.com
Fon +49 551 30664-0, Fax -11, Bahnhofsallee 1b, 37081 G?ttingen, Germany
Sitz der Gesellschaft: G?ttingen, Amtsgericht G?ttingen HR B 3160
Gesch?ftsf?hrung: Dr. Uwe Kracke, Ust-IdNr.: DE 205 198 055

emlix - your embedded linux partner