Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp358759imm; Tue, 9 Oct 2018 19:50:25 -0700 (PDT) X-Google-Smtp-Source: ACcGV60RqCPWPeO43FuxU6qzSsmcRBsRKUgE/++q2jXD/wuThMufHPgWtM8jDtdfBiKD59B82TcR X-Received: by 2002:a17:902:64c2:: with SMTP id y2-v6mr31087865pli.35.1539139825820; Tue, 09 Oct 2018 19:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539139825; cv=none; d=google.com; s=arc-20160816; b=qHwMnPma5EMmMjjBtiMMx8mzIvtKkIUjDR5N2R8yTla086M1i25ED4D66tZGOZoSiW VjrS1Lb6ZUC5IyZN4WYKmvqo7IKemJtw8ByF+X+LwdvwYBGFdX5Zo12prqniFbhvv6fV 8ZbgGbabafDrcet1PlOlYjQNf46MH79fJzZP8TjVPulrfAbqiSFzI7tSzNYqB5gW+jpQ eLHggRQxLNmUSDiF0ptl2eTKwNIHc0hpqxbfZroyn2mFKvmlOb6F0N/iw/iUbd/HsI/o dYsZYkmURthjnshn7JJ1M5QZadqfNlOnE6WtRL5ESTeJ1EI4o+OLdMKwcBPqh0IwR81I sigw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=nyE/v2Gyriug3w7pfnEVCbt+lrioJVRkF2cic8faNXc=; b=KsT0dNpzyn494FgLVhN81cPrR5rJRw1Kc8DhxYKSRNdESh2N6nrwvohEfYnPUEAiec 4hWlrP0yBuT4j0PxgHajSu4rNH1AlWFXn/LYLXV6oh2iK7N2Z01BXX9/t5cQdVv/5KXa QDbpsFReC//1Ko5j1KxWzuZ8Xj7b8BneuLK2IUJY6vsVhufgeIRpVF4oOGjM/7Xpzfwu yizNTOv6iuPaWYbk69FdvCxpk6+TXBKmCFEnbjHggIDHVN4LAp1I39vJ82/pNFB7WdK+ kIAW55Xv8HXIIIkfA+C1U3JzozXZgVxuB0OFQcKjAUs6xtyE5fd2Z3VGX7xhluxw6VhI uDtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=FYnB8GPy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i23-v6si21783671pgl.230.2018.10.09.19.50.11; Tue, 09 Oct 2018 19:50:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=FYnB8GPy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbeJJKJ1 (ORCPT + 99 others); Wed, 10 Oct 2018 06:09:27 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:44324 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbeJJKJ1 (ORCPT ); Wed, 10 Oct 2018 06:09:27 -0400 Received: from garnet.amanokami.net (unknown [96.44.9.229]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E18EC1C3E; Wed, 10 Oct 2018 04:49:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1539139768; bh=JsxG7EJNzKYcwR9A4HHtrXqKQFblkhWA0v2DVZGe17w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FYnB8GPy1A+sLVazaXsMmQEU51x3iMWh8W9AxMGitLf+3WJQ8SzRx/dEc1V73muM1 bl8MnhTk4rAjS8J8rcs3K9kJtyRV1+AonqWaCLBISKDGrWFzv51bt8Y6Lg8HkZ9n14 KpAZMEfiBx52kx/PGQR92GXFK3sd6kx3tBo82NP4= From: Paul Elder To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Cc: Paul Elder , 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 Message-Id: <20181010024903.1633-7-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181010024903.1633-1-paul.elder@ideasonboard.com> References: <20181010024903.1633-1-paul.elder@ideasonboard.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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