Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4474648imm; Mon, 8 Oct 2018 23:34:12 -0700 (PDT) X-Google-Smtp-Source: ACcGV62JmoCBGeq+uJeTaJMTHuwSxArXCcOiHNZmrvl59QtrPvx4QUeMYTB3YEpekDBluxQ2/r31 X-Received: by 2002:a17:902:5ac9:: with SMTP id g9-v6mr27598513plm.311.1539066852108; Mon, 08 Oct 2018 23:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539066852; cv=none; d=google.com; s=arc-20160816; b=IhKTH2qyXm/WJD6erhxi32DTvB0M334GpcbHL5VuiiR54hDSVe4osuhes5nkJG1p7N 7vZy2HvfEicEZU/IfP37wRnVB6tSiy5Diq9q7ytR4amII8n9VJFw0pAk7X4Mm9xB8uW2 6S2aTMqfjsJxZIbTWd2OqsLPzjLeq5FzK+7piJsmDBIc0c31gN1117YzAlYvLZmfR3f6 VXIBChsIkjNJUP6n8ZBLAzWAaXyE8rnkv3IfLEo9W2aXJIVIV3QdSbnRo+UFw6SRlqmb LwSjNN1psoBTGNMivmmnnz2JvYUM/kS+1jXIckCKYyNddmY74MOT9zZqNqOHnVIrztm4 ECGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=7+FBvflhA1I3SnIsmZ4+j4W9kLBKCP6KkYuRS4Caw5U=; b=VXvBpWTT9CYaQdzs9Svw73lABk/Zps4cZOBwE+LzbJZyAXqlT3frlFEsWbhEbaXYpM gUhdVp8HS4410T+UXHLbdC3k3/3oN06EET8TMB6c5HPIkOjc1p2VEv8LMRedol9WZtPu F6LN6A/uBZeTpo2MrutbCCNChDaGVjW3kMikzFOLz7pHlt+AQmsy+xrPhIF75AzLzWtL ipHe4lQ99ukGiJ+Db17nCVV6fLnqm7bYlA4qkf2ywElCtkVK9Ierjfd5XjeU4W7Q9s1K gfw1N3CBB878ldtqRb8lXKAngv4GFx0OjwQrsMoZrvKdGHSS1NgOlebTQ2rUZwe5L1ZU hO1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=thNNvBRW; 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 v4-v6si19263667plp.247.2018.10.08.23.33.57; Mon, 08 Oct 2018 23:34:12 -0700 (PDT) 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=thNNvBRW; 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 S1726529AbeJINsj (ORCPT + 99 others); Tue, 9 Oct 2018 09:48:39 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:54266 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725835AbeJINsj (ORCPT ); Tue, 9 Oct 2018 09:48:39 -0400 Received: from garnet.amanokami.net (unknown [96.44.9.229]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 222BE6F8; Tue, 9 Oct 2018 08:33:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1539066795; bh=i1bPg/p3EQFWOWAOhFz7LUTieY1Y7qejoyXWffB4t7M=; h=From:To:Cc:Subject:Date:From; b=thNNvBRW5bnXZFIqKBUFGBHvdE6tgS1jFW7sSfluUqwoIs+LRThUORSb+RukA3krJ kRPV5rWI4vjGTvUVTpBdJc2Y7UHdNVGFcHbUtDZgiTTekPYA6ykjya2xoPqaD09bUp Fm2wxV+PwaPAtpaOVgL87SRqt6LHrMUKCFDH5Fnc= From: Paul Elder To: laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Cc: Paul Elder , Nicolas Boichat , b-liu@ti.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, balbi@kernel.org, balbi@ti.com Subject: [PATCH] usb: gadget: musb: fix short isoc packets with inventra dma for pandaboard es Date: Tue, 9 Oct 2018 02:32:20 -0400 Message-Id: <20181009063220.13745-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.18.0 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). 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, MUSB_TXCSR_TXPKTRDY is set in dma_controller_irq (musbhsdma.c), just like host mode transfers, then musb_g_tx forces the packet to be flushed, by setting MUSB_TXCSR_FLUSHFIFO. 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 I have forward-ported this patch from 2.6.34 to 4.19-rc1. Signed-off-by: Paul Elder --- drivers/usb/musb/musb_gadget.c | 21 ++++++++++++++------- drivers/usb/musb/musbhsdma.c | 21 +++++++++++---------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index eae8b1b1b45b..d3f33f449445 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -479,11 +479,16 @@ void musb_g_tx(struct musb *musb, u8 epnum) && (request->actual == request->length)) short_packet = true; - 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 (is_dma && (musb_dma_inventra(musb) || musb_dma_ux500(musb))) { + if (!dma->desired_mode || + request->actual % musb_ep->packet_sz) { + musb_dbg(musb, "%s Flushing (FIFO) EP : KPB\n", + musb_ep->end_point.name); + musb_writew(epio, MUSB_TXCSR, + csr | MUSB_TXCSR_FLUSHFIFO); + return; + } + } if (short_packet) { /* @@ -493,8 +498,10 @@ void musb_g_tx(struct musb *musb, u8 epnum) if (csr & MUSB_TXCSR_TXPKTRDY) return; - musb_writew(epio, MUSB_TXCSR, MUSB_TXCSR_MODE - | MUSB_TXCSR_TXPKTRDY); + musb_dbg(musb, "sending zero pkt (zero=%d, length=%d, actual=%d, dma->desired_mode=%d)\n", + request->zero, request->length, request->actual, + dma->desired_mode); + musb_writew(epio, MUSB_TXCSR, csr | MUSB_TXCSR_TXPKTRDY); request->zero = 0; } diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index a688f7f87829..e514d4700a6b 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.18.0