Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6325794ybx; Mon, 11 Nov 2019 07:27:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxMwelQi2s18vIofZC59y958QST9shlcInp+D1U+Jcm4Ahp1tOYMRPzaoqfAOy5McFEBlhR X-Received: by 2002:a05:6402:2042:: with SMTP id bc2mr26722970edb.167.1573486076914; Mon, 11 Nov 2019 07:27:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573486076; cv=none; d=google.com; s=arc-20160816; b=JM/XkmBAm2USFXkro5IgHYL8Jw0soVNwhTBms8vJBGIhnpwCu0AUxAyG82NBmoFMtk lfTyhfko200Mx4ftTNJWVRzkea9sB6IURPi5veNkN9IQbny7pscx0IByYsEP+tXZchEY TrmVInfVAEPJEBNeJzjYfkxUe53m5dHo+fR1+N2sJZ3DIy+x+uVRCy+qosqN2N3dVoN1 IlXcSDSkGFSig4a5JtWkuQ67kMz0D9qiQgfgGulK/gWEASrfNi3ottZ3DttGEbwFkVCl LztU/bVT0MSpeBdr9zWpFdgfgxlWDbYvSo93F3fyNTV+d6XKTp5is7C1jNVqBZzuIvOe WeBg== 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; bh=hY6tyipz+dmakMQi5EqBAPIs1ZqG5o+z3XZI84OwoA8=; b=a6OGtTTdib0CRNYCr8R1SqzvGtGC+TvicL1jLjxBoqXv2wXEvZooaCa6240+mBfe0y FfGUqdVQdKqU5+Rfw9SHIQCKKlx8Af9HXJI94CUn3uUhQZyqbaJWaRyrIBXyFIy1xMGU 3GVufZTja+69HbbrJPIwuMIohMyWFAqWZwx8KWP6BWeZPOjr1GUMgt3c26OkPydguniV avS7QWJ45vAqGBhUqy87nmPQdt/4+FGLF6U4xPzdDAxGAkwUGq+XXK1qG3skK7V7LvbH K0i+Ww7TVN/VgYdd6B2owLWLDJnD0eTabrnaKoj9dUaxObJqSfgusybHjJ5Be1KYYxFN osEQ== ARC-Authentication-Results: i=1; mx.google.com; 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 bs2si9821954edb.354.2019.11.11.07.27.33; Mon, 11 Nov 2019 07:27:56 -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; 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 S1726960AbfKKP05 (ORCPT + 99 others); Mon, 11 Nov 2019 10:26:57 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:51253 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbfKKP04 (ORCPT ); Mon, 11 Nov 2019 10:26:56 -0500 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.lab.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iUBac-0000i0-11; Mon, 11 Nov 2019 16:26:50 +0100 Received: from mol by dude02.lab.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1iUBaa-0003bS-Rg; Mon, 11 Nov 2019 16:26:48 +0100 From: Michael Olbrich To: linux-usb@vger.kernel.org Cc: Felipe Balbi , Thinh Nguyen , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, kernel@pengutronix.de, Michael Olbrich Subject: [PATCH 2/2] usb: dwc3: gadget: restart the transfer if a isoc request is queued too late Date: Mon, 11 Nov 2019 16:26:45 +0100 Message-Id: <20191111152645.13792-3-m.olbrich@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191111152645.13792-1-m.olbrich@pengutronix.de> References: <20191111152645.13792-1-m.olbrich@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mol@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, most gadget drivers handle isoc transfers on a best effort bases: If the request queue runs empty, then there will simply be gaps in the isoc data stream. The UVC gadget depends on this behaviour. It simply provides new requests when video frames are available and assumes that they are sent as soon as possible. The dwc3 gadget currently works differently: It assumes that there is a contiguous stream of requests without any gaps. If a request is too late, then it is dropped by the hardware. For the UVC gadget this means that a live stream stops after the first frame because all following requests are late. This patch changes the behaviour of the dwc3 gadget driver to match the expectations. If a request arrives too late, then the transfer will be restart to create the needed gap. A request is late if: 1. There are currently no requests queued in the hardware 2. The current frame number provided by DSTS does not match the frame number returned by the last transfer. If this happens transfers are stopped. The following XferNotReady provides the new correct frame number and restarts the transfer. Signed-off-by: Michael Olbrich --- drivers/usb/dwc3/gadget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index ac4673d91939..eb7f09929f28 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1473,6 +1473,14 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) return __dwc3_gadget_start_isoc(dep); } } + if ((dep->flags & DWC3_EP_TRANSFER_STARTED) && + list_empty(&dep->started_list) && + ((dep->frame_number & 0x3fff) != + __dwc3_gadget_get_frame(dwc))) { + dwc3_stop_active_transfer(dep, true, true); + dep->flags = DWC3_EP_ENABLED; + return 0; + } } return __dwc3_gadget_kick_transfer(dep, false); -- 2.20.1