Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp922351imu; Wed, 16 Jan 2019 09:40:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN7X+c58WltL6COCClLG8f6YL2Fm416BKobvA4Lc0+2TPSYssELGEPzZ/wSa7rez3LevA4vQ X-Received: by 2002:a65:43c5:: with SMTP id n5mr10177823pgp.250.1547660403214; Wed, 16 Jan 2019 09:40:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547660403; cv=none; d=google.com; s=arc-20160816; b=gnSYwIfrDqgUXmN50Lo8p4p1W8UGV8Oq5kPPe4jUjS/tHgGQ7mZKwEfmedhAFEb0Vt M+K0sYbeKhdCeHqjOw5q6nIljVoNklbKuUcEREDbuJ4xnptoY033YYRtuK5ko2oXz4hJ JTTB+T+v1MwsMK6MkXIDWHcXwcmHvWU6/oO4sVf2Zv1O3MxTcjlhSZrRa7eoOZD4VBkm hFSMfgxnbyLvoxldYYFEqzpbIHh/cVr8SYynA8WNgEhzfvy5XeD4n4xK9Nbkd6QHVLis PxXfOFkG/6Xvrr/iKP2Nvj8Y+qMIyG1VDYgq4dmgqmujgiXwkxviKhZ2Tp80z2TqRFxv eUZg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jKzHbqZFCQzKpch0emxB7z4L+dp+bh/y5Vkq31nMeqk=; b=dFVxKCedNLjD7zYXYkavKicDeuw36NohMVsgs/17WEJ50kyOBoZvZE20iT77J5r0LV 1ZeDUivF2Em9zX+r/vhQtDMnjWZ1zDiucSdsw2vA05YOqMazHRvnMFA3jMVgDvlKe5F+ sSOkYR5cRyEKzP05khe66culwDLjrAUsm3/W6r2aXNK2wdvXRkegRvLlDdfkNWFoeBds qJrK3mHip8Vxoq2T1WwTLB8Aj7uA7+pa6JdUh87+DtnfZ2rgHhPkB20tJtAl2pCtzLNu dVxbbw8urraOhh110XguZbPQiYiBvHRBugzwz+NVVJW7rSmPTAwAGEWBPK73BkYon/4C NWkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=JyK6avjq; 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 m33si6298496pgl.379.2019.01.16.09.39.47; Wed, 16 Jan 2019 09:40:03 -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=JyK6avjq; 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 S1729131AbfAPACB (ORCPT + 99 others); Tue, 15 Jan 2019 19:02:01 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:49448 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728728AbfAPACB (ORCPT ); Tue, 15 Jan 2019 19:02:01 -0500 Received: from localhost.localdomain (unknown [96.44.9.117]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F25CE530; Wed, 16 Jan 2019 01:01:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547596919; bh=sg4t8JOjyLOwJH2mu0Q5VtvgoxoNuNHPOUq7xguwWug=; h=From:To:Cc:Subject:Date:From; b=JyK6avjqQHpHBBcI46E/FkKs3dFHAGs8rgAkA/O51mfk+MU1w6bFjeMa5ALs4D5Sc vhTiOCVQK3MchOIw5rpGktlTgTwjd9dNe6yyc1rYRyuffEn8fE5OQrcaaxmrnNtJf1 9uLwPPbPuSV5+3BUEAiRP280z79xnTWcJvQxnVfA= From: Paul Elder To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, b-liu@ti.com Cc: Paul Elder , drinkcat@chromium.org, balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] usb: gadget: musb: fix short isoc packets with inventra dma Date: Tue, 15 Jan 2019 19:01:45 -0500 Message-Id: <20190116000145.5816-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.20.1 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 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 Signed-off-by: Paul Elder --- Changes in v3: - remove unnecessary chunk for sending short packet Changes in v2: - no more flushing FIFO - greatly simplified short packet if guard in musb_g_tx, and removed unnecessary variables - minor indentation and wording changes drivers/usb/musb/musb_gadget.c | 13 +------------ drivers/usb/musb/musbhsdma.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index eae8b1b1b45b..ffe462a657b1 100644 --- 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 epnum) } 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 epnum) */ 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... diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index a688f7f87829..5fc6825745f2 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c @@ -346,12 +346,10 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) 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(int irq, void *private_data) */ 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); } -- 2.20.1