All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Elder <paul.elder@ideasonboard.com>
To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com
Cc: Paul Elder <paul.elder@ideasonboard.com>,
	b-liu@ti.com, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	balbi@kernel.org, stern@rowland.harvard.edu, rogerq@ti.com
Subject: [PATCH 6/6] usb: gadget: uvc: allow ioctl to send response in status stage
Date: Tue,  9 Oct 2018 22:49:03 -0400	[thread overview]
Message-ID: <20181010024903.1633-7-paul.elder@ideasonboard.com> (raw)
In-Reply-To: <20181010024903.1633-1-paul.elder@ideasonboard.com>

We now have a mechanism to signal the UDC driver to reply to a control
OUT request with STALL or ACK, and we have packaged the setup stage data
and the data stage data of a control OUT request into a single
UVC_EVENT_DATA for userspace to consume. The ioctl UVCIOC_SEND_RESPONSE
in the case of a control OUT request sends a response to the data stage,
and so the ioctl now notifies the UDC driver to reply with STALL or ACK.
In the case of a control IN request, the ioctl sends the UVC data as
before.

Also tell the UDC to delay the status stage for this to work.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 drivers/usb/gadget/function/f_uvc.c    |  5 +++--
 drivers/usb/gadget/function/uvc_v4l2.c | 20 +++++++++++++++++---
 drivers/usb/gadget/udc/core.c          |  5 +++++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 9df3eac440ea..ff89a76a7417 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -209,14 +209,15 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req)
 	struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
 
 	if (uvc->event_setup_out) {
-		uvc->event_setup_out = 0;
-
 		memset(&v4l2_event, 0, sizeof(v4l2_event));
 		v4l2_event.type = UVC_EVENT_DATA;
 		uvc_event->data.length = req->actual;
 		memcpy(&uvc_event->data.data, req->buf, req->actual);
 		memcpy(&uvc_event->data.setup, &uvc->control_setup,
 		       sizeof(uvc_event->data.setup));
+
+		usb_ep_delay_status(ep);
+
 		v4l2_event_queue(&uvc->vdev, &v4l2_event);
 	}
 }
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 2e2251bdef03..caa6412c0bda 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -37,10 +37,24 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
 
 	/*
 	 * For control OUT transfers the request has been enqueued synchronously
-	 * by the setup handler, there's nothing to be done here.
+	 * by the setup handler, we just need to tell the UDC whether to ACK or
+	 * STALL the control transfer.
 	 */
-	if (uvc->event_setup_out)
-		return 0;
+	if (uvc->event_setup_out) {
+		struct usb_ep *ep = cdev->gadget->ep0;
+		bool stall = data->length < 0;
+
+		/*
+		 * The length field carries the control request status.
+		 * Negative values signal a STALL and zero values an ACK.
+		 * Positive values are not valid as there is no data to send
+		 * back in the status stage.
+		 */
+		if (data->length > 0)
+			return -EINVAL;
+
+		return usb_ep_send_response(ep, stall);
+	}
 
 	if (data->length < 0)
 		return usb_ep_set_halt(cdev->gadget->ep0);
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 1ec5ce6b43cd..0f62a3f1aa29 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1369,6 +1369,11 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
 			driver->function);
 
+	if (!udc->gadget->ep0->ops->send_response) {
+		dev_warn(&udc->dev, "UDC doesn't implement send_response\n");
+		dev_warn(&udc->dev, "Proper operation can't be guaranteed\n");
+	}
+
 	udc->driver = driver;
 	udc->dev.driver = &driver->driver;
 	udc->gadget->dev.driver = &driver->driver;
-- 
2.18.0


WARNING: multiple messages have this Message-ID (diff)
From: Paul Elder <paul.elder@ideasonboard.com>
To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com
Cc: Paul Elder <paul.elder@ideasonboard.com>,
	b-liu@ti.com, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	balbi@kernel.org, stern@rowland.harvard.edu, rogerq@ti.com
Subject: [6/6] usb: gadget: uvc: allow ioctl to send response in status stage
Date: Tue,  9 Oct 2018 22:49:03 -0400	[thread overview]
Message-ID: <20181010024903.1633-7-paul.elder@ideasonboard.com> (raw)

We now have a mechanism to signal the UDC driver to reply to a control
OUT request with STALL or ACK, and we have packaged the setup stage data
and the data stage data of a control OUT request into a single
UVC_EVENT_DATA for userspace to consume. The ioctl UVCIOC_SEND_RESPONSE
in the case of a control OUT request sends a response to the data stage,
and so the ioctl now notifies the UDC driver to reply with STALL or ACK.
In the case of a control IN request, the ioctl sends the UVC data as
before.

Also tell the UDC to delay the status stage for this to work.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 drivers/usb/gadget/function/f_uvc.c    |  5 +++--
 drivers/usb/gadget/function/uvc_v4l2.c | 20 +++++++++++++++++---
 drivers/usb/gadget/udc/core.c          |  5 +++++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c
index 9df3eac440ea..ff89a76a7417 100644
--- a/drivers/usb/gadget/function/f_uvc.c
+++ b/drivers/usb/gadget/function/f_uvc.c
@@ -209,14 +209,15 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req)
 	struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
 
 	if (uvc->event_setup_out) {
-		uvc->event_setup_out = 0;
-
 		memset(&v4l2_event, 0, sizeof(v4l2_event));
 		v4l2_event.type = UVC_EVENT_DATA;
 		uvc_event->data.length = req->actual;
 		memcpy(&uvc_event->data.data, req->buf, req->actual);
 		memcpy(&uvc_event->data.setup, &uvc->control_setup,
 		       sizeof(uvc_event->data.setup));
+
+		usb_ep_delay_status(ep);
+
 		v4l2_event_queue(&uvc->vdev, &v4l2_event);
 	}
 }
diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c
index 2e2251bdef03..caa6412c0bda 100644
--- a/drivers/usb/gadget/function/uvc_v4l2.c
+++ b/drivers/usb/gadget/function/uvc_v4l2.c
@@ -37,10 +37,24 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
 
 	/*
 	 * For control OUT transfers the request has been enqueued synchronously
-	 * by the setup handler, there's nothing to be done here.
+	 * by the setup handler, we just need to tell the UDC whether to ACK or
+	 * STALL the control transfer.
 	 */
-	if (uvc->event_setup_out)
-		return 0;
+	if (uvc->event_setup_out) {
+		struct usb_ep *ep = cdev->gadget->ep0;
+		bool stall = data->length < 0;
+
+		/*
+		 * The length field carries the control request status.
+		 * Negative values signal a STALL and zero values an ACK.
+		 * Positive values are not valid as there is no data to send
+		 * back in the status stage.
+		 */
+		if (data->length > 0)
+			return -EINVAL;
+
+		return usb_ep_send_response(ep, stall);
+	}
 
 	if (data->length < 0)
 		return usb_ep_set_halt(cdev->gadget->ep0);
diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 1ec5ce6b43cd..0f62a3f1aa29 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1369,6 +1369,11 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
 			driver->function);
 
+	if (!udc->gadget->ep0->ops->send_response) {
+		dev_warn(&udc->dev, "UDC doesn't implement send_response\n");
+		dev_warn(&udc->dev, "Proper operation can't be guaranteed\n");
+	}
+
 	udc->driver = driver;
 	udc->dev.driver = &driver->driver;
 	udc->gadget->dev.driver = &driver->driver;

  parent reply	other threads:[~2018-10-10  2:49 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10  2:48 [PATCH 0/6] usb: gadget: add mechanism to asynchronously validate data stage of ctrl out request Paul Elder
2018-10-10  2:48 ` [PATCH 1/6] usb: uvc: include videodev2.h in g_uvc.h Paul Elder
2018-10-10  2:48   ` [1/6] " Paul Elder
2018-10-10 13:42   ` [PATCH 1/6] " Laurent Pinchart
2018-10-10 13:42     ` [1/6] " Laurent Pinchart
2018-10-10  2:48 ` [PATCH 2/6] usb: gadget: uvc: enqueue usb request in setup handler for control OUT Paul Elder
2018-10-10  2:48   ` [2/6] " Paul Elder
2018-10-10  2:49 ` [PATCH 3/6] usb: gadget: uvc: package setup and data for control OUT requests Paul Elder
2018-10-10  2:49   ` [3/6] " Paul Elder
2018-10-10  2:49 ` [PATCH 4/6] usb: gadget: add functions to signal udc driver to delay status stage Paul Elder
2018-10-10  2:49   ` [4/6] " Paul Elder
2018-10-11 16:10   ` [PATCH 4/6] " Bin Liu
2018-10-11 16:10     ` [4/6] " Bin Liu
2018-10-17 23:45     ` [PATCH 4/6] " Laurent Pinchart
2018-10-17 23:45       ` [4/6] " Laurent Pinchart
2018-10-18 12:46       ` [PATCH 4/6] " Bin Liu
2018-10-18 12:46         ` [4/6] " Bin Liu
2018-10-18 14:07       ` [PATCH 4/6] " Alan Stern
2018-10-18 14:07         ` [4/6] " Alan Stern
2018-11-01 23:40         ` [PATCH 4/6] " Paul Elder
2018-11-01 23:40           ` [4/6] " Paul Elder
2018-11-02 12:44           ` [PATCH 4/6] " Laurent Pinchart
2018-11-02 12:44             ` [4/6] " Laurent Pinchart
     [not found]             ` <87h8gzy5y7.fsf@linux.intel.com>
2018-11-02 14:36               ` [PATCH 4/6] " Laurent Pinchart
2018-11-02 14:36                 ` [4/6] " Laurent Pinchart
2018-11-02 16:18                 ` [PATCH 4/6] " Alan Stern
2018-11-02 16:18                   ` [4/6] " Alan Stern
2018-11-02 17:10                   ` [PATCH 4/6] " Laurent Pinchart
2018-11-02 17:10                     ` [4/6] " Laurent Pinchart
2018-11-02 19:46                     ` [PATCH 4/6] " Alan Stern
2018-11-02 19:46                       ` [4/6] " Alan Stern
2018-11-06 11:24                       ` [PATCH 4/6] " Felipe Balbi
2018-11-06 11:24                         ` [4/6] " Felipe Balbi
2018-11-06 15:01                         ` [PATCH 4/6] " Alan Stern
2018-11-06 15:01                           ` [4/6] " Alan Stern
2018-11-07  6:53                           ` [PATCH 4/6] " Felipe Balbi
2018-11-07  6:53                             ` [4/6] " Felipe Balbi
2018-11-06 11:17                     ` [PATCH 4/6] " Felipe Balbi
2018-11-06 11:17                       ` [4/6] " Felipe Balbi
2018-11-06 14:51                       ` [PATCH 4/6] " Alan Stern
2018-11-06 14:51                         ` [4/6] " Alan Stern
2018-11-07  7:00                         ` [PATCH 4/6] " Felipe Balbi
2018-11-07  7:00                           ` [4/6] " Felipe Balbi
2018-11-07 16:23                           ` [PATCH 4/6] " Alan Stern
2018-11-07 16:23                             ` [4/6] " Alan Stern
2018-12-14  3:47                             ` [PATCH 4/6] " Paul Elder
2018-12-14  3:47                               ` [4/6] " Paul Elder
2018-12-14 15:35                               ` [PATCH 4/6] " Alan Stern
2018-12-14 15:35                                 ` [4/6] " Alan Stern
2018-10-10  2:49 ` [PATCH 5/6] usb: musb: gadget: implement send_response Paul Elder
2018-10-10  2:49   ` [5/6] " Paul Elder
2018-10-11 16:07   ` [PATCH 5/6] " Bin Liu
2018-10-11 16:07     ` [5/6] " Bin Liu
2018-10-31 23:26     ` [PATCH 5/6] " Paul Elder
2018-10-31 23:26       ` [5/6] " Paul Elder
2018-10-10  2:49 ` Paul Elder [this message]
2018-10-10  2:49   ` [6/6] usb: gadget: uvc: allow ioctl to send response in status stage Paul Elder
2018-10-10 12:57 ` [PATCH 0/6] usb: gadget: add mechanism to asynchronously validate data stage of ctrl out request Laurent Pinchart
2018-10-11 19:31 ` Bin Liu
2018-10-17 23:42   ` Laurent Pinchart
2018-10-18 12:40     ` Bin Liu

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=20181010024903.1633-7-paul.elder@ideasonboard.com \
    --to=paul.elder@ideasonboard.com \
    --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=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.