Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2661212imj; Mon, 11 Feb 2019 06:38:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IbJQtguZD2y+U/IPjYsOJbTfRwg1CPhnBNIKLta3SaAlnAqbG6q0/qCrza9Li5iriCo+Wam X-Received: by 2002:a63:d547:: with SMTP id v7mr23682402pgi.339.1549895892076; Mon, 11 Feb 2019 06:38:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895892; cv=none; d=google.com; s=arc-20160816; b=PYRh5RMSlUumScXg8vTaLemhik6q5P++8D4gSICgDXOmvyuVhtiVDW33jzpgk6BZdP jxId93TtyzGWoeO9r+erwLtuEXX2hNiLN+4GT+bAupyxqZWuCBAaIZwrR2Gwx7qakgC8 9iX4f+Cfd9/a9zaIU0NQYKi3Gebs+hPGVQmso2KgUE3Bvc4HKuCcNn0HbHEpI/dmPgFR pdev+Ha7kvs8kg+D94FQC/PeYlv8LaeFnTh9Y3JC7QcEkOedbVesbhb6m/NzdlgVpRFD 6HdCjKEyxkcdUBfBinJA42CIHuWLHD4qjPZDbWODxp7NvdwWKHrpWAPvv2lVdnzV2lhr xq/A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=w51EOQ2PoC3cVRJ9SNKwHrSKHkDnwe017DNiA/rWc4s=; b=FufJMZtcSvUSeh07fxt+JfoHhwsxJ7q5H3XkkKpjNAKXDKKJCIeXcXoCcODEkcjkxQ 8KaFdG2Al1Rit12LouahBLuACWICsQdmWBcRHX9+Cp3IRPvQSnKD+DJ5k/jGKU7Xcowm ClyDuQPOCheQNgy9HGNsunfAD2Y+2iw5O1KqbCqmsO4y8WqJOJSF9mVqLzqqDFPONM6q f9UE7B9xPlvVM9P4cc5BK73sVwG3x5IgWhpcm8XNDpAucWsVftub/bEylgUZVlN2Xb7t PHBtHMLN6epTK2DWWE79Fc2kd/RXJKW8Tm9ebTDQLCC07J+X62kv5rF7U2To9p/TNohh hr9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m1KZqMIp; 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 p9si9642591pgc.448.2019.02.11.06.37.55; Mon, 11 Feb 2019 06:38:12 -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 header.i=@kernel.org header.s=default header.b=m1KZqMIp; 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 S1730971AbfBKOhF (ORCPT + 99 others); Mon, 11 Feb 2019 09:37:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:46318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731359AbfBKOhD (ORCPT ); Mon, 11 Feb 2019 09:37:03 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0C0020844; Mon, 11 Feb 2019 14:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895822; bh=jvFf9LLXffP+CHXHPgdApGzYbAC4EaYDA7MZW2ZqLqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m1KZqMIpshE1JkcRyzbsAKX1qp1e7+2uZE/OBtSelQPArrr0+r6Zsskx/6IYljtPf 8AZ4CpkXW+jKKDIrpjJs1Zs9UuvkeiBZUVuRSV96ycBhSOCBgV/hBizjJ7Y556/HDR KRA0/AUu2m1S5d3X5Q/tYP22N4tCBveFThZ9Uql8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Elder , Bin Liu Subject: [PATCH 4.20 334/352] usb: gadget: musb: fix short isoc packets with inventra dma Date: Mon, 11 Feb 2019 15:19:21 +0100 Message-Id: <20190211141908.238451545@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Elder commit c418fd6c01fbc5516a2cd1eaf1df1ec86869028a upstream. Handling short packets (length < max packet size) in the Inventra DMA engine in the MUSB driver causes the MUSB DMA controller to hang. An example of a problem that is caused by this problem is when streaming video out of a UVC gadget, only the first video frame is transferred. For short packets (mode-0 or mode-1 DMA), MUSB_TXCSR_TXPKTRDY must be set manually by the driver. This was previously done in musb_g_tx (musb_gadget.c), but incorrectly (all csr flags were cleared, and only MUSB_TXCSR_MODE and MUSB_TXCSR_TXPKTRDY were set). Fixing that problem allows some requests to be transferred correctly, but multiple requests were often put together in one USB packet, and caused problems if the packet size was not a multiple of 4. Instead, set MUSB_TXCSR_TXPKTRDY in dma_controller_irq (musbhsdma.c), just like host mode transfers. This topic was originally tackled by Nicolas Boichat [0] [1] and is discussed further at [2] as part of his GSoC project [3]. [0] https://groups.google.com/forum/?hl=en#!topic/beagleboard-gsoc/k8Azwfp75CU [1] https://gitorious.org/beagleboard-usbsniffer/beagleboard-usbsniffer-kernel/commit/b0be3b6cc195ba732189b04f1d43ec843c3e54c9?p=beagleboard-usbsniffer:beagleboard-usbsniffer-kernel.git;a=patch;h=b0be3b6cc195ba732189b04f1d43ec843c3e54c9 [2] http://beagleboard-usbsniffer.blogspot.com/2010/07/musb-isochronous-transfers-fixed.html [3] http://elinux.org/BeagleBoard/GSoC/USBSniffer Fixes: 550a7375fe72 ("USB: Add MUSB and TUSB support") Signed-off-by: Paul Elder Signed-off-by: Bin Liu Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_gadget.c | 13 +------------ drivers/usb/musb/musbhsdma.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 22 deletions(-) --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -452,13 +452,10 @@ void musb_g_tx(struct musb *musb, u8 epn } if (request) { - u8 is_dma = 0; - bool short_packet = false; trace_musb_req_tx(req); if (dma && (csr & MUSB_TXCSR_DMAENAB)) { - is_dma = 1; csr |= MUSB_TXCSR_P_WZC_BITS; csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_AUTOSET); @@ -476,16 +473,8 @@ void musb_g_tx(struct musb *musb, u8 epn */ if ((request->zero && request->length) && (request->length % musb_ep->packet_sz == 0) - && (request->actual == request->length)) - short_packet = true; + && (request->actual == request->length)) { - if ((musb_dma_inventra(musb) || musb_dma_ux500(musb)) && - (is_dma && (!dma->desired_mode || - (request->actual & - (musb_ep->packet_sz - 1))))) - short_packet = true; - - if (short_packet) { /* * On DMA completion, FIFO may not be * available yet... --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c @@ -346,12 +346,10 @@ static irqreturn_t dma_controller_irq(in channel->status = MUSB_DMA_STATUS_FREE; /* completed */ - if ((devctl & MUSB_DEVCTL_HM) - && (musb_channel->transmit) - && ((channel->desired_mode == 0) - || (channel->actual_len & - (musb_channel->max_packet_sz - 1))) - ) { + if (musb_channel->transmit && + (!channel->desired_mode || + (channel->actual_len % + musb_channel->max_packet_sz))) { u8 epnum = musb_channel->epnum; int offset = musb->io.ep_offset(epnum, MUSB_TXCSR); @@ -363,11 +361,14 @@ static irqreturn_t dma_controller_irq(in */ musb_ep_select(mbase, epnum); txcsr = musb_readw(mbase, offset); - txcsr &= ~(MUSB_TXCSR_DMAENAB + if (channel->desired_mode == 1) { + txcsr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_AUTOSET); - musb_writew(mbase, offset, txcsr); - /* Send out the packet */ - txcsr &= ~MUSB_TXCSR_DMAMODE; + musb_writew(mbase, offset, txcsr); + /* Send out the packet */ + txcsr &= ~MUSB_TXCSR_DMAMODE; + txcsr |= MUSB_TXCSR_DMAENAB; + } txcsr |= MUSB_TXCSR_TXPKTRDY; musb_writew(mbase, offset, txcsr); }