Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp409558imu; Tue, 8 Jan 2019 23:11:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN7DEAilZzQJrE1F8uiNny53Gd3JYHneteipnk4npkO4psmWDjWeXvyseDVjsnqbWAidlKzN X-Received: by 2002:a63:111c:: with SMTP id g28mr4338312pgl.85.1547017887459; Tue, 08 Jan 2019 23:11:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547017887; cv=none; d=google.com; s=arc-20160816; b=VrhcW0sT6qaDbusekiuSbgBzQlA925FiX3bhOxtjnx6GADMeHJgtx0+uZx8CZr2bPW IPP6oqCGHUvxy1QWJg1hloci50y/nQWXpVFzWzRIkduSsassKTsDJBhb7CGPPw+YhiX+ Ji5EwmtEK9ZqC6ECtJp+H6qEb57fhAnA0UzYH/u3I46yz9GAN6ChY7hhbG3ckvzX5ZnC Lk6I70UZHTQyFX5jF88JCht7v8UrYUAhXn5GdX0x4f88gYAhm87X3INWge1MuZM9z60e Cv+EpDXJE6TK8H82W2wTnIXOsAwbZbpgvAKRSsN/qVmue2PZdCY0a1kOMNA5VQewKOx3 hvJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o6as4vFfseHGhK7JgTTwXOFAKmGL+xnsl13ZupNfc/w=; b=IDYoDP+bVarZjBwaVkpLQmdn9wVjq7OZ2C+OhfIFanqfEb0Vgkbg1OF3jLPSKgWavC pjDXzYOvoepWecMgphdyoFFDtMVAFeefSn+u30/68zqxc6Ha3NfDjOowNuQ1D3nfuGED 1HKaY7koPRnqOfyZxK6Qbm/4v3VoJ6nPzM1Hge1X1Fv4d9aqC+Xw1qPJxyW/P1hvjHj5 Q5i4aJSqYoK32xb6D5UyYToKGjqSCRUU3BShtjO7Ie3HYLon8cspumTfhPwuPCLLT3EO WGy4DQAYlM3fDBuBt33S+Dql2ipETmwFz5+YNUVdi1xEjqTp+M4GsmBYzrldPxBsEHRF OPbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=uN7wmtxx; 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 v5si7368756pfe.52.2019.01.08.23.11.11; Tue, 08 Jan 2019 23:11:27 -0800 (PST) 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=uN7wmtxx; 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 S1729889AbfAIHKB (ORCPT + 99 others); Wed, 9 Jan 2019 02:10:01 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:50374 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729813AbfAIHKA (ORCPT ); Wed, 9 Jan 2019 02:10:00 -0500 Received: from localhost.localdomain (unknown [96.44.9.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 75C46586; Wed, 9 Jan 2019 08:09:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547017797; bh=F65Jw9KaCB9yBCblUHC/GxBM9uDweX8UJSoRBJkF0tA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uN7wmtxxAnV5NKZfiLGwMG1KjEga1BfSLFGqFFBHy2aGZXJQE5SK62tyP53Yth7O3 mGm4i+DoJvPxj5UHiF6HixM5jgqFkUtmTQY9CmpqlxEft6M38bQEtIUBfViSE5DvMG e5CdYLNjfVxUyA3ard14dDi2aole1iTo9J/jAa1I= From: Paul Elder To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Cc: Paul Elder , b-liu@ti.com, stern@rowland.harvard.edu, rogerq@ti.com, balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 6/6] usb: gadget: uvc: allow ioctl to send response in status stage Date: Wed, 9 Jan 2019 02:08:56 -0500 Message-Id: <20190109070856.27460-7-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190109070856.27460-1-paul.elder@ideasonboard.com> References: <20190109070856.27460-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- No change from v4 No change from v3 Changes from v2: - calling usb_ep_set_halt in uvc_send_response if data->length < 0 is now common for both IN and OUT transfers so make that check common - remove now unnecessary field setting for the usb_request to be queued for the status stage Changes from v1: - remove usb_ep_delay_status call from the old proposed API - changed portions of uvc_send_response to match v2 API - remove UDC warning that send_response is not implemented drivers/usb/gadget/function/f_uvc.c | 4 ++-- drivers/usb/gadget/function/uvc_v4l2.c | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index 58ed191f636e..053808b01d48 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -209,14 +209,13 @@ 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)); + v4l2_event_queue(&uvc->vdev, &v4l2_event); } } @@ -251,6 +250,7 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) */ req->length = uvc->event_length; req->zero = 0; + req->explicit_status = 1; usb_ep_queue(f->config->cdev->gadget->ep0, req, GFP_KERNEL); } else { struct v4l2_event v4l2_event; diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index ac48f49d9f10..353071869e15 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -35,15 +35,26 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data) struct usb_composite_dev *cdev = uvc->func.config->cdev; struct usb_request *req = uvc->control_req; + if (data->length < 0) + return usb_ep_set_halt(cdev->gadget->ep0); + /* * 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 (data->length < 0) - return usb_ep_set_halt(cdev->gadget->ep0); + if (uvc->event_setup_out) { + /* + * 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_queue(cdev->gadget->ep0, req, GFP_KERNEL); + } req->length = min_t(unsigned int, uvc->event_length, data->length); req->zero = data->length < uvc->event_length; -- 2.20.1