Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2691412imj; Mon, 11 Feb 2019 07:05:35 -0800 (PST) X-Google-Smtp-Source: AHgI3IboogEmqzDEM1mEw9ORqEZy7qlFxqmk562X2Le/N7q1a63B6Kfm1oJCx9JigoTsjIWOnxuh X-Received: by 2002:a63:da14:: with SMTP id c20mr32674160pgh.233.1549897535821; Mon, 11 Feb 2019 07:05:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897535; cv=none; d=google.com; s=arc-20160816; b=AVL5a28NQuQrY7ivFDh9rIFeE/tsxcekBQyNziDybJ85cN/KZQdLomNFe3WrlYxXHd 4GPhKWHoPBy2w7Ggn6+YmD31szEjZCyAyYeKq34FtcQLB0p1gYzkHq4wDBQs78ouNqyE 9yT5BX8Tcr4FXXnQPG9KlQiLmuiBht+C5cpExTS0C9A4gIumeP7fIMRjNIkQKFKPycY4 Ks9Dxu7A8OpkGFKprqsNQE548oNKefIhIfITjGnRJ1zT1YEkPSobdonrXUVvtKa1Sss6 xcFlqhEw2fvVmaLbOhzg7rY8SaBr6M3o1DFWLz1xRIhakUYlzCow80Aen9oK2FlyP3Cf pOBw== 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=e12hzjOdw8w7mvQ48fHaPb02JHqiPdyWU4+GSiB/6Lw=; b=y2hMzRxCns6KKRgqzltaZ9O48YSuiWRBsQVjHLkqt/bqyOpwyxtJJc+LXkn9SgdgSw B8TJ6zQPljPNQ0Nib8OUWR7r2ZNyFo6No4HkB8mxpMI7a1GGqw+EhCCQkVfjU8usIRqg I+dsIse6VRnYO0wd3hTucx1llp5moe8eYZwoKWOFK+soQqB8beuMtzGZ7rMpvaE02ZbB O6NApItwcRfdezrd18UFwFd07kZcuDCGN2RDZv+pmz1L7xh843F/lOmTSvmpUAd2axHI P4eu0S6IX03TlGHOywfT8fE2Qznr5tbCHhxzidbjaiKg1wVqpl7pEfYuUCn4bP8OSXDY g8Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bNrjbFuk; 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 e8si10412888pfc.248.2019.02.11.07.05.18; Mon, 11 Feb 2019 07:05:35 -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=bNrjbFuk; 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 S2390752AbfBKPET (ORCPT + 99 others); Mon, 11 Feb 2019 10:04:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:53214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390743AbfBKPEQ (ORCPT ); Mon, 11 Feb 2019 10:04:16 -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 785DA222B1; Mon, 11 Feb 2019 15:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897456; bh=IoJfbleuqX7emJ+16Td9msXUctHxndTl6HIVHYpn3fE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bNrjbFukbhX1XxcGMWKH7qjSBdv/pjJLUa4FakbwJhqOZWtVJKL0V2UZCgOCtStEV wvlSig9VpkRKzxw+1uRz1rTmMZAs5XvHjrv9GbA9y77k0/FsfkCZxAkmnDUAFqmRt1 rnK8D25ee0HpHQkfhewTaoIXw4HLKhGhXqSWn510= 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.14 188/205] usb: gadget: musb: fix short isoc packets with inventra dma Date: Mon, 11 Feb 2019 15:19:46 +0100 Message-Id: <20190211141840.700280636@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 @@ -477,13 +477,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); @@ -501,16 +498,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 @@ -320,12 +320,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); @@ -337,11 +335,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); }