linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bin Liu <b-liu@ti.com>
To: Paul Elder <paul.elder@ideasonboard.com>
Cc: <laurent.pinchart@ideasonboard.com>,
	<kieran.bingham@ideasonboard.com>, <drinkcat@chromium.org>,
	<balbi@kernel.org>, <gregkh@linuxfoundation.org>,
	<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] usb: gadget: musb: fix short isoc packets with inventra dma
Date: Wed, 9 Jan 2019 09:02:15 -0600	[thread overview]
Message-ID: <20190109150215.GJ25910@uda0271908> (raw)
In-Reply-To: <20190109071009.27625-1-paul.elder@ideasonboard.com>

Hi Paul,

On Wed, Jan 09, 2019 at 02:10:09AM -0500, Paul Elder wrote:
> 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 <paul.elder@ideasonboard.com>
> ---
> 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 | 19 +++++--------------
>  drivers/usb/musb/musbhsdma.c   | 21 +++++++++++----------
>  2 files changed, 16 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> index eae8b1b1b45b..496643f54faa 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...
> @@ -493,8 +482,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 short 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);

Sorry I didn't catch this in the last review, but this change seems not
required, isn't it? In the first version of the patch, the code is
'returned' in the 'if (musb_dma_inventra())' branch above, doesn't reach
here.

Regards,
-Bin.

  reply	other threads:[~2019-01-09 15:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09  7:10 [PATCH v2] usb: gadget: musb: fix short isoc packets with inventra dma Paul Elder
2019-01-09 15:02 ` Bin Liu [this message]
2019-01-11  5:31   ` Paul Elder
2019-01-15 16:35     ` Bin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190109150215.GJ25910@uda0271908 \
    --to=b-liu@ti.com \
    --cc=balbi@kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=paul.elder@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).