All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above
@ 2010-10-31  5:25 Anand Gadiyar
       [not found] ` <1288502759-18618-1-git-send-email-gadiyar-l0cyMroinI0@public.gmane.org>
  2010-11-05 12:26 ` Felipe Balbi
  0 siblings, 2 replies; 5+ messages in thread
From: Anand Gadiyar @ 2010-10-31  5:25 UTC (permalink / raw)
  To: linux-usb, linux-omap, Greg Kroah-Hartman
  Cc: Anand Gadiyar, Felipe Balbi, Ming Lei, Ajay Kumar Gupta, Mike Frysinger

The Inventra DMA engine in version 1.8 and later of the MUSB
controller cannot handle DMA addresses that are not aligned
to a 4 byte boundary. It ends up ignoring the last two bits
programmed in the DMA_ADDR register. This is a deliberate
design change in the controller and is documented in the
programming guide.

Earlier versions of the controller could handle these
accesses just fine.

Fail dma_channel_program if we see an unaligned address when
using the newer controllers, so that the caller can carry out
the transfer using PIO mode.
(Current callers already have this backup path in place).

Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Ming Lei <tom.leiming@gmail.com>
Cc: Ajay Kumar Gupta <ajay.gupta@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
---
Patch based on linux-next as of 20101029.

I believe Blackfin is also affected by this, but I'm not sure how
they're working around this. Mike?

 drivers/usb/musb/musbhsdma.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

Index: mainline/drivers/usb/musb/musbhsdma.c
===================================================================
--- mainline.orig/drivers/usb/musb/musbhsdma.c
+++ mainline/drivers/usb/musb/musbhsdma.c
@@ -158,6 +158,8 @@ static int dma_channel_program(struct dm
 				dma_addr_t dma_addr, u32 len)
 {
 	struct musb_dma_channel *musb_channel = channel->private_data;
+	struct musb_dma_controller *controller = musb_channel->controller;
+	struct musb *musb = controller->private_data;
 
 	DBG(2, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n",
 		musb_channel->epnum,
@@ -167,6 +169,18 @@ static int dma_channel_program(struct dm
 	BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
 		channel->status == MUSB_DMA_STATUS_BUSY);
 
+	/*
+	 * The DMA engine in RTL1.8 and above cannot handle
+	 * DMA addresses that are not aligned to a 4 byte boundary.
+	 * It ends up masking the last two bits of the address
+	 * programmed in DMA_ADDR.
+	 *
+	 * Fail such DMA transfers, so that the backup PIO mode
+	 * can carry out the transfer
+	 */
+	if ((musb->hwvers >= MUSB_HWVERS_1800) && (dma_addr %4))
+		return false;
+
 	channel->actual_len = 0;
 	musb_channel->start_addr = dma_addr;
 	musb_channel->len = len;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above
       [not found] ` <1288502759-18618-1-git-send-email-gadiyar-l0cyMroinI0@public.gmane.org>
@ 2010-10-31  9:59   ` Ming Lei
  2010-11-08  6:21     ` Anand Gadiyar
  2010-11-01 12:43   ` Sergei Shtylyov
  1 sibling, 1 reply; 5+ messages in thread
From: Ming Lei @ 2010-10-31  9:59 UTC (permalink / raw)
  To: Anand Gadiyar
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Greg Kroah-Hartman,
	Felipe Balbi, Ajay Kumar Gupta, Mike Frysinger,
	hemahk-l0cyMroinI0

Cc Hema

2010/10/31 Anand Gadiyar <gadiyar-l0cyMroinI0@public.gmane.org>:
> The Inventra DMA engine in version 1.8 and later of the MUSB
> controller cannot handle DMA addresses that are not aligned
> to a 4 byte boundary. It ends up ignoring the last two bits
> programmed in the DMA_ADDR register. This is a deliberate
> design change in the controller and is documented in the
> programming guide.
>
> Earlier versions of the controller could handle these
> accesses just fine.
>
> Fail dma_channel_program if we see an unaligned address when
> using the newer controllers, so that the caller can carry out
> the transfer using PIO mode.
> (Current callers already have this backup path in place).
>
> Signed-off-by: Anand Gadiyar <gadiyar-l0cyMroinI0@public.gmane.org>
> Cc: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
> Cc: Ming Lei <tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Ajay Kumar Gupta <ajay.gupta-l0cyMroinI0@public.gmane.org>
> Cc: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>

Tested-by: Ming Lei <tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

This patch is verified OK about g_ether function on beagle xM board,
but the revised patch "usb: musb: gadget: Unmapping the dma buffer
when switching to PIO mode" [1] should be applied first.

> ---
> Patch based on linux-next as of 20101029.
>
> I believe Blackfin is also affected by this, but I'm not sure how
> they're working around this. Mike?

MUSB on Blackfin will fallback to PIO too, so no any working around
for it, right?

>
>  drivers/usb/musb/musbhsdma.c |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> Index: mainline/drivers/usb/musb/musbhsdma.c
> ===================================================================
> --- mainline.orig/drivers/usb/musb/musbhsdma.c
> +++ mainline/drivers/usb/musb/musbhsdma.c
> @@ -158,6 +158,8 @@ static int dma_channel_program(struct dm
>                                dma_addr_t dma_addr, u32 len)
>  {
>        struct musb_dma_channel *musb_channel = channel->private_data;
> +       struct musb_dma_controller *controller = musb_channel->controller;
> +       struct musb *musb = controller->private_data;
>
>        DBG(2, "ep%d-%s pkt_sz %d, dma_addr 0x%x length %d, mode %d\n",
>                musb_channel->epnum,
> @@ -167,6 +169,18 @@ static int dma_channel_program(struct dm
>        BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
>                channel->status == MUSB_DMA_STATUS_BUSY);
>
> +       /*
> +        * The DMA engine in RTL1.8 and above cannot handle
> +        * DMA addresses that are not aligned to a 4 byte boundary.
> +        * It ends up masking the last two bits of the address
> +        * programmed in DMA_ADDR.
> +        *
> +        * Fail such DMA transfers, so that the backup PIO mode
> +        * can carry out the transfer
> +        */
> +       if ((musb->hwvers >= MUSB_HWVERS_1800) && (dma_addr %4))
> +               return false;
> +
>        channel->actual_len = 0;
>        musb_channel->start_addr = dma_addr;
>        musb_channel->len = len;
>

[1], http://marc.info/?l=linux-usb&m=128532510705381&w=2

-- 
Lei Ming
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above
       [not found] ` <1288502759-18618-1-git-send-email-gadiyar-l0cyMroinI0@public.gmane.org>
  2010-10-31  9:59   ` Ming Lei
@ 2010-11-01 12:43   ` Sergei Shtylyov
  1 sibling, 0 replies; 5+ messages in thread
From: Sergei Shtylyov @ 2010-11-01 12:43 UTC (permalink / raw)
  To: Anand Gadiyar
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, Greg Kroah-Hartman,
	Felipe Balbi, Ming Lei, Ajay Kumar Gupta, Mike Frysinger

Hello.

On 31-10-2010 8:25, Anand Gadiyar wrote:

> The Inventra DMA engine in version 1.8 and later of the MUSB
> controller cannot handle DMA addresses that are not aligned
> to a 4 byte boundary. It ends up ignoring the last two bits
> programmed in the DMA_ADDR register. This is a deliberate
> design change in the controller and is documented in the
> programming guide.

> Earlier versions of the controller could handle these
> accesses just fine.

> Fail dma_channel_program if we see an unaligned address when
> using the newer controllers, so that the caller can carry out
> the transfer using PIO mode.
> (Current callers already have this backup path in place).

> Signed-off-by: Anand Gadiyar<gadiyar-l0cyMroinI0@public.gmane.org>
> Cc: Felipe Balbi<balbi-l0cyMroinI0@public.gmane.org>
> Cc: Ming Lei<tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Ajay Kumar Gupta<ajay.gupta-l0cyMroinI0@public.gmane.org>
> Cc: Mike Frysinger<vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
[...]

> Index: mainline/drivers/usb/musb/musbhsdma.c
> ===================================================================
> --- mainline.orig/drivers/usb/musb/musbhsdma.c
> +++ mainline/drivers/usb/musb/musbhsdma.c
[...]
> @@ -167,6 +169,18 @@ static int dma_channel_program(struct dm
>   	BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN ||
>   		channel->status == MUSB_DMA_STATUS_BUSY);
>
> +	/*
> +	 * The DMA engine in RTL1.8 and above cannot handle
> +	 * DMA addresses that are not aligned to a 4 byte boundary.
> +	 * It ends up masking the last two bits of the address
> +	 * programmed in DMA_ADDR.
> +	 *
> +	 * Fail such DMA transfers, so that the backup PIO mode
> +	 * can carry out the transfer
> +	 */
> +	if ((musb->hwvers >= MUSB_HWVERS_1800) && (dma_addr %4))

    Also need space after %.

> +		return false;
> +

WBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above
  2010-10-31  5:25 [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above Anand Gadiyar
       [not found] ` <1288502759-18618-1-git-send-email-gadiyar-l0cyMroinI0@public.gmane.org>
@ 2010-11-05 12:26 ` Felipe Balbi
  1 sibling, 0 replies; 5+ messages in thread
From: Felipe Balbi @ 2010-11-05 12:26 UTC (permalink / raw)
  To: Gadiyar, Anand
  Cc: linux-usb, linux-omap, Greg Kroah-Hartman, Balbi, Felipe,
	Ming Lei, Gupta, Ajay Kumar, Mike Frysinger

On Sun, Oct 31, 2010 at 12:25:59AM -0500, Gadiyar, Anand wrote:
>The Inventra DMA engine in version 1.8 and later of the MUSB
>controller cannot handle DMA addresses that are not aligned
>to a 4 byte boundary. It ends up ignoring the last two bits
>programmed in the DMA_ADDR register. This is a deliberate
>design change in the controller and is documented in the
>programming guide.
>
>Earlier versions of the controller could handle these
>accesses just fine.
>
>Fail dma_channel_program if we see an unaligned address when
>using the newer controllers, so that the caller can carry out
>the transfer using PIO mode.
>(Current callers already have this backup path in place).
>
>Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
>Cc: Felipe Balbi <balbi@ti.com>
>Cc: Ming Lei <tom.leiming@gmail.com>
>Cc: Ajay Kumar Gupta <ajay.gupta@ti.com>
>Cc: Mike Frysinger <vapier@gentoo.org>

please fix comment from Sergei and resend without RFC.

-- 
balbi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above
  2010-10-31  9:59   ` Ming Lei
@ 2010-11-08  6:21     ` Anand Gadiyar
  0 siblings, 0 replies; 5+ messages in thread
From: Anand Gadiyar @ 2010-11-08  6:21 UTC (permalink / raw)
  To: Ming Lei
  Cc: linux-usb, linux-omap, Greg Kroah-Hartman, Felipe Balbi,
	Ajay Kumar Gupta, Mike Frysinger, hemahk

On 10/31/2010 3:29 PM, Ming Lei wrote:
> 2010/10/31 Anand Gadiyar<gadiyar@ti.com>:
>> The Inventra DMA engine in version 1.8 and later of the MUSB
>> controller cannot handle DMA addresses that are not aligned
>> to a 4 byte boundary. It ends up ignoring the last two bits
>> programmed in the DMA_ADDR register. This is a deliberate
>> design change in the controller and is documented in the
>> programming guide.
>>
>> Earlier versions of the controller could handle these
>> accesses just fine.
>>
>> Fail dma_channel_program if we see an unaligned address when
>> using the newer controllers, so that the caller can carry out
>> the transfer using PIO mode.
>> (Current callers already have this backup path in place).
>>
>> Signed-off-by: Anand Gadiyar<gadiyar@ti.com>
>> Cc: Felipe Balbi<balbi@ti.com>
>> Cc: Ming Lei<tom.leiming@gmail.com>
>> Cc: Ajay Kumar Gupta<ajay.gupta@ti.com>
>> Cc: Mike Frysinger<vapier@gentoo.org>
>
> Tested-by: Ming Lei<tom.leiming@gmail.com>
>
> This patch is verified OK about g_ether function on beagle xM board,
> but the revised patch "usb: musb: gadget: Unmapping the dma buffer
> when switching to PIO mode" [1] should be applied first.
>
>> ---
>> Patch based on linux-next as of 20101029.
>>
>> I believe Blackfin is also affected by this, but I'm not sure how
>> they're working around this. Mike?
>
> MUSB on Blackfin will fallback to PIO too, so no any working around
> for it, right?
>

I meant Blackfin should also have hit this issue so far. I'm making
a change based on the MUSB revision - so this change will affect 
Blackfin for sure - they use revision 1.9 and 2.0 I think. So I'm just 
wondering if they really are affected, or they've simply never hit this 
scenario before.

- Anand

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-08  6:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-31  5:25 [PATCH RFC] usb: musb: fail unaligned DMA transfers on v1.8 and above Anand Gadiyar
     [not found] ` <1288502759-18618-1-git-send-email-gadiyar-l0cyMroinI0@public.gmane.org>
2010-10-31  9:59   ` Ming Lei
2010-11-08  6:21     ` Anand Gadiyar
2010-11-01 12:43   ` Sergei Shtylyov
2010-11-05 12:26 ` Felipe Balbi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.