From: Alan Stern <stern@rowland.harvard.edu>
To: Paul Elder <paul.elder@ideasonboard.com>
Cc: laurent.pinchart@ideasonboard.com,
<kieran.bingham@ideasonboard.com>, <b-liu@ti.com>,
<rogerq@ti.com>, <balbi@kernel.org>, <gregkh@linuxfoundation.org>,
<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 4/6] usb: gadget: add mechanism to specify an explicit status stage
Date: Wed, 9 Jan 2019 14:06:31 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.44L0.1901091359020.1205-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <20190109070856.27460-5-paul.elder@ideasonboard.com>
On Wed, 9 Jan 2019, Paul Elder wrote:
> A usb gadget function driver may or may not want to delay the status
> stage of a control OUT request. An instance where it might want to is to
> asynchronously validate the data of a class-specific request.
>
> A function driver that wants an explicit status stage should set the
> newly added explicit_status flag of the usb_request corresponding to the
> data stage. Later on, the function driver can explicitly complete the
> status stage by enqueueing a usb_request for ACK, or calling
> usb_ep_set_halt() for STALL.
>
> To support both explicit and implicit status stages, a UDC driver must
> call the newly added usb_gadget_control_complete function right before
> calling usb_gadget_giveback_request. To support the explicit status
> stage, it might then check what stage the usb_request was queued in, and
> for control IN ACK the host's zero-length data packet, or for control
> OUT send a zero-length DATA1 ACK packet.
>
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> v4 Acked-by: Alan Stern <stern@rowland.harvard.edu>
> v1 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This looks good and has passed my tests so far. Can you check your uvc
changes using dummy_hcd with the patch below?
Alan Stern
Index: usb-4.x/drivers/usb/gadget/udc/dummy_hcd.c
===================================================================
--- usb-4.x.orig/drivers/usb/gadget/udc/dummy_hcd.c
+++ usb-4.x/drivers/usb/gadget/udc/dummy_hcd.c
@@ -88,6 +88,7 @@ struct dummy_ep {
unsigned wedged:1;
unsigned already_seen:1;
unsigned setup_stage:1;
+ unsigned status_stage:1;
unsigned stream_en:1;
};
@@ -1037,7 +1038,7 @@ static void init_dummy_udc_hw(struct dum
ep->ep.ops = &dummy_ep_ops;
list_add_tail(&ep->ep.ep_list, &dum->gadget.ep_list);
ep->halted = ep->wedged = ep->already_seen =
- ep->setup_stage = 0;
+ ep->setup_stage = ep->status_stage = 0;
usb_ep_set_maxpacket_limit(&ep->ep, ~0);
ep->ep.max_streams = 16;
ep->last_io = jiffies;
@@ -1386,6 +1387,7 @@ static int transfer(struct dummy_hcd *du
struct dummy *dum = dum_hcd->dum;
struct dummy_request *req;
int sent = 0;
+ bool is_ep0 = (ep == &dum->ep[0]);
top:
/* if there's no request queued, the device is NAKing; return */
@@ -1407,6 +1409,11 @@ top:
* terminate reads.
*/
host_len = urb->transfer_buffer_length - urb->actual_length;
+ if (ep->status_stage)
+ host_len = 0;
+ else if (is_ep0 && host_len == 0)
+ ep->status_stage = 1;
+
dev_len = req->req.length - req->req.actual;
len = min(host_len, dev_len);
@@ -1471,6 +1478,12 @@ top:
req->req.status = 0;
}
+ /* Truncated control-IN => start the status stage */
+ if (*status == 0 && is_ep0 && !ep->status_stage) {
+ ep->status_stage = 1;
+ *status = -EINPROGRESS;
+ }
+
/*
* many requests terminate without a short packet.
* send a zlp if demanded by flags.
@@ -1486,6 +1499,8 @@ top:
if (urb->transfer_flags & URB_ZERO_PACKET &&
!to_host)
rescan = 1;
+ else if (is_ep0 && !ep->status_stage)
+ ep->status_stage = rescan = 1;
else
*status = 0;
}
@@ -1496,6 +1511,9 @@ top:
list_del_init(&req->queue);
spin_unlock(&dum->lock);
+ if (is_ep0)
+ usb_gadget_control_complete(&dum->gadget,
+ &req->req);
usb_gadget_giveback_request(&ep->ep, &req->req);
spin_lock(&dum->lock);
@@ -1849,6 +1867,7 @@ restart:
ep->already_seen = 1;
if (ep == &dum->ep[0] && urb->error_count) {
ep->setup_stage = 1; /* a new urb */
+ ep->status_stage = 0;
urb->error_count = 0;
}
if (ep->halted && !ep->setup_stage) {
next prev parent reply other threads:[~2019-01-09 19:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 7:08 [PATCH v5 0/6] usb: gadget: add mechanism to asynchronously validate data stage of ctrl out request Paul Elder
2019-01-09 7:08 ` [PATCH v5 1/6] usb: uvc: include videodev2.h in g_uvc.h Paul Elder
2019-01-09 7:08 ` [PATCH v5 2/6] usb: gadget: uvc: enqueue usb request in setup handler for control OUT Paul Elder
2019-01-09 7:08 ` [PATCH v5 3/6] usb: gadget: uvc: package setup and data for control OUT requests Paul Elder
2019-01-09 7:08 ` [PATCH v5 4/6] usb: gadget: add mechanism to specify an explicit status stage Paul Elder
2019-01-09 19:06 ` Alan Stern [this message]
2019-01-11 8:23 ` Paul Elder
2019-01-11 15:50 ` Alan Stern
2019-01-14 5:11 ` Paul Elder
2019-01-14 15:24 ` Alan Stern
2019-01-16 5:00 ` Paul Elder
2019-01-16 15:06 ` Alan Stern
2019-01-18 16:31 ` Paul Elder
2019-01-18 16:52 ` Alan Stern
2019-01-20 17:59 ` Paul Elder
2019-01-23 21:10 ` Alan Stern
2019-01-24 2:48 ` Paul Elder
2019-01-09 7:08 ` [PATCH v5 5/6] usb: musb: gadget: implement optional " Paul Elder
2019-01-09 7:08 ` [PATCH v5 6/6] usb: gadget: uvc: allow ioctl to send response in " Paul Elder
2019-01-10 20:39 ` [PATCH v5 0/6] usb: gadget: add mechanism to asynchronously validate data stage of ctrl out request Alan Stern
2019-01-11 8:43 ` Paul Elder
2019-01-11 18:32 ` Alan Stern
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=Pine.LNX.4.44L0.1901091359020.1205-100000@iolanthe.rowland.org \
--to=stern@rowland.harvard.edu \
--cc=b-liu@ti.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kieran.bingham@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=paul.elder@ideasonboard.com \
--cc=rogerq@ti.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;
as well as URLs for NNTP newsgroup(s).