Skip to contentSkip to conversation

usb: musb: Fix fifo reads for dm816x with musb_dsps

PATCH Superseded Tony Lindgren 5 participants 8 messages Mar 18, 2015 – Apr 1, 2015 3 messages not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: musb: Fix fifo reads for dm816x with musb_dsps

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter:

asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4

While at it, let's also remove pointless cast of the driver data.

Cc Bin Liu <[email protected]>
Cc Brian Hutchinson <[email protected]>
Cc George Cherian <[email protected]>
---
 drivers/usb/musb/musb_dsps.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_dsps.c +36 -1
@@ -655,6 +655,36 @@ static int dsps_musb_reset(struct musb *musb)
 	return !session_restart;
 }
 
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+	void __iomem *fifo = hw_ep->fifo;
+	u32		val;
+	int		i;
+
+	/* Read for 32bit-aligned destination address */
+	if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+		readsl(fifo, dst, len >> 2);
+		dst += len & ~0x03;
+		len &= 0x03;
+	}
+	/*
+	 * Now read the remaining 1 to 3 byte or complete length if
+	 * unaligned address.
+	 */
+	if (len > 4) {
+		for (i = 0; i < (len >> 2); i++) {
+			*(u32 *)dst = musb_readl(fifo, 0);
+			dst += 4;
+		}
+		len &= 0x03;
+	}
+	if (len > 0) {
+		val = musb_readl(fifo, 0);
+		memcpy(dst, &val, len);
+	}
+}
+
 static struct musb_platform_ops dsps_ops = {
 	.quirks		= MUSB_INDEXED_EP,
 	.init		= dsps_musb_init,
@@ -802,6 +832,9 @@ static int dsps_probe(struct platform_device *pdev)
 	}
 	wrp = match->data;
 
+	if (of_device_is_compatible(pdev->dev.of_node, "ti,musb-dm816"))
+		dsps_ops.read_fifo = dsps_read_fifo32;
+
 	/* allocate glue */
 	glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
 	if (!glue)
@@ -878,7 +911,9 @@ static const struct dsps_musb_wrapper am33xx_driver_data = {
 
 static const struct of_device_id musb_dsps_of_match[] = {
 	{ .compatible = "ti,musb-am33xx",
-		.data = (void *) &am33xx_driver_data, },
+		.data = &am33xx_driver_data, },
+	{ .compatible = "ti,musb-dm816",
+		.data = &am33xx_driver_data, },
 	{  },
 };
 MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
Signature · 1 line
2.1.4
#1 lore raw

Hello.

Quoted 32 lines · Tony Lindgren

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter:

asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4

While at it, let's also remove pointless cast of the driver data.

Cc Bin Liu <[email protected]>
Cc Brian Hutchinson <[email protected]>
Cc George Cherian <[email protected]>
---
  drivers/usb/musb/musb_dsps.c | 37 ++++++++++++++++++++++++++++++++++++-
  1 file changed, 36 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_dsps.c +7 -0
@@ -655,6 +655,36 @@ static int dsps_musb_reset(struct musb *musb)
  	return !session_restart;
  }
 
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+	void __iomem *fifo = hw_ep->fifo;
+	u32		val;
+	int		i;
+

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 674

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+	/* Read for 32bit-aligned destination address */
+	if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+		readsl(fifo, dst, len >> 2);
+		dst += len & ~0x03;
+		len &= 0x03;
+	}
+	/*
+	 * Now read the remaining 1 to 3 byte or complete length if
+	 * unaligned address.
+	 */

This comment seems misplaced, it belongs before the next *if*.

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 679

Quoted 5 lines
drivers/usb/musb/musb_dsps.c +5 -0
+	if (len > 4) {
+		for (i = 0; i < (len >> 2); i++) {
+			*(u32 *)dst = musb_readl(fifo, 0);
+			dst += 4;
+		}

Not sure how this is different to using readsl().

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 690

Quoted 11 lines
drivers/usb/musb/musb_dsps.c +8 -0
+		len &= 0x03;
+	}
+	if (len > 0) {
+		val = musb_readl(fifo, 0);
+		memcpy(dst, &val, len);
+	}
+}
+
  static struct musb_platform_ops dsps_ops = {
  	.quirks		= MUSB_INDEXED_EP,
  	.init		= dsps_musb_init,

[...]

WBR, Sergei

A message that is not in the archive (sent off-list or not yet received): 550ACF61.5000909-M4DtvfQ/[email protected]

#3 lore raw
Quoted 5 lines · Sergei Shtylyov
Quoted 3 lines · Tony Lindgren

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

...

Quoted 30 lines
Quoted 9 lines
drivers/usb/musb/musb_dsps.c +7 -0
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+	void __iomem *fifo = hw_ep->fifo;
+	u32		val;
+	int		i;
+

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 674

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+	/* Read for 32bit-aligned destination address */
+	if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+		readsl(fifo, dst, len >> 2);
+		dst += len & ~0x03;
+		len &= 0x03;
+	}
+	/*
+	 * Now read the remaining 1 to 3 byte or complete length if
+	 * unaligned address.
+	 */

This comment seems misplaced, it belongs before the next *if*.

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 679

Quoted 5 lines
drivers/usb/musb/musb_dsps.c +5 -0
+	if (len > 4) {
+		for (i = 0; i < (len >> 2); i++) {
+			*(u32 *)dst = musb_readl(fifo, 0);
+			dst += 4;
+		}

Not sure how this is different to using readsl().

Quoted 7 lines

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 686

Quoted 7 lines
drivers/usb/musb/musb_dsps.c +7 -0
+		len &= 0x03;
+	}
+	if (len > 0) {
+		val = musb_readl(fifo, 0);
+		memcpy(dst, &val, len);
+	}
+}

Indeed, thanks for looking at it. That function in the TI kernel probably had something else for the 32-bit aligned case that got swapped to use readsl().

Looks like the following works just fine for me with a USB Ethernet and variable size ping test:

static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)

{
	void __iomem *fifo = hw_ep->fifo;

	if (len >= 4) {
		readsl(fifo, dst, len >> 2);
		dst += len & ~0x03;
		len &= 0x03;
	}

	/* Read any remaining 1 to 3 bytes */                                                                                
	if (len > 0) {
		u32 val = musb_readl(fifo, 0);
		memcpy(dst, &val, len);
	}
}

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to a message not in the archive
Quoted 45 lines · Sergei Shtylyov
Quoted 32 lines

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter:

asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4

While at it, let's also remove pointless cast of the driver data.

Cc Bin Liu <[email protected]>
Cc Brian Hutchinson <[email protected]>
Cc George Cherian <[email protected]>
---
  drivers/usb/musb/musb_dsps.c | 37 ++++++++++++++++++++++++++++++++++++-
  1 file changed, 36 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_dsps.c +7 -0
@@ -655,6 +655,36 @@ static int dsps_musb_reset(struct musb *musb)
      return !session_restart;
  }
 
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+    void __iomem *fifo = hw_ep->fifo;
+    u32        val;
+    int        i;
+

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 674

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+    /* Read for 32bit-aligned destination address */
+    if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+        readsl(fifo, dst, len >> 2);
+        dst += len & ~0x03;
+        len &= 0x03;
+    }
+    /*
+     * Now read the remaining 1 to 3 byte or complete length if
+     * unaligned address.
+     */

This comment seems misplaced, it belongs before the next *if*.

Quoted 7 lines

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 679

Quoted 5 lines
drivers/usb/musb/musb_dsps.c +5 -0
+    if (len > 4) {
+        for (i = 0; i < (len >> 2); i++) {
+            *(u32 *)dst = musb_readl(fifo, 0);
+            dst += 4;
+        }

Not sure how this is different to using readsl().

Ah, the default implementation of musb_readl() uses __raw_readl().
So you'd probably want to keep this loop, not readsl() call.

Quoted 11 lines

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 690

Quoted 11 lines
drivers/usb/musb/musb_dsps.c +8 -0
+        len &= 0x03;
+    }
+    if (len > 0) {
+        val = musb_readl(fifo, 0);
+        memcpy(dst, &val, len);
+    }
+}
+
  static struct musb_platform_ops dsps_ops = {
      .quirks        = MUSB_INDEXED_EP,
      .init        = dsps_musb_init,

[...]

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 550B0C3C.3080107-M4DtvfQ/[email protected]

#6 lore raw
Quoted 33 lines · Sergei Shtylyov
Quoted 31 lines · Sergei Shtylyov
Quoted 13 lines
drivers/usb/musb/musb_dsps.c +7 -0
@@ -655,6 +655,36 @@ static int dsps_musb_reset(struct musb *musb)
     return !session_restart;
 }
 
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+    void __iomem *fifo = hw_ep->fifo;
+    u32        val;
+    int        i;
+

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 674

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+    /* Read for 32bit-aligned destination address */
+    if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+        readsl(fifo, dst, len >> 2);
+        dst += len & ~0x03;
+        len &= 0x03;
+    }
+    /*
+     * Now read the remaining 1 to 3 byte or complete length if
+     * unaligned address.
+     */

This comment seems misplaced, it belongs before the next *if*.

Quoted 5 lines
drivers/usb/musb/musb_dsps.c +5 -0
+    if (len > 4) {
+        for (i = 0; i < (len >> 2); i++) {
+            *(u32 *)dst = musb_readl(fifo, 0);
+            dst += 4;
+        }
Quoted 4 lines
Quoted 1 line

Not sure how this is different to using readsl().

Ah, the default implementation of musb_readl() uses __raw_readl().
So you'd probably want to keep this loop, not readsl() call.

Not sure I follow you here.. Also include/asm-generic/io.h readsl() uses __raw_readl()?

It seems things work with what I posted, so a readsl() loop, then just read the remaining 1 to 3 bytes.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
Quoted 32 lines · Tony Lindgren
Quoted 31 lines
Quoted 31 lines
Quoted 13 lines
drivers/usb/musb/musb_dsps.c +7 -0
@@ -655,6 +655,36 @@ static int dsps_musb_reset(struct musb *musb)
      return !session_restart;
  }
 
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+    void __iomem *fifo = hw_ep->fifo;
+    u32        val;
+    int        i;
+

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 674

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+    /* Read for 32bit-aligned destination address */
+    if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+        readsl(fifo, dst, len >> 2);
+        dst += len & ~0x03;
+        len &= 0x03;
+    }
+    /*
+     * Now read the remaining 1 to 3 byte or complete length if
+     * unaligned address.
+     */

This comment seems misplaced, it belongs before the next *if*.

Quoted 5 lines
drivers/usb/musb/musb_dsps.c +5 -0
+    if (len > 4) {
+        for (i = 0; i < (len >> 2); i++) {
+            *(u32 *)dst = musb_readl(fifo, 0);
+            dst += 4;
+        }
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Not sure how this is different to using readsl().

Ah, the default implementation of musb_readl() uses __raw_readl().
So you'd probably want to keep this loop, not readsl() call.

Not sure I follow you here..

I just wrongly thought readsl() uses readl() internally. readl() is
supposed to swap bytes when needed (BE case), while __raw_readl() is not.

Quoted 2 lines

Also include/asm-generic/io.h readsl()
uses __raw_readl()?

Looking at the arch/arm/include/asm/io.h, readsl() is equivalent to
__raw_readsl() too. Forgot about this "asymmetry".

Quoted 2 lines

It seems things work with what I posted, so a readsl() loop, then just read the remaining 1 to 3 bytes.

In LE mode, there would have been no difference anyway.

Quoted 3 lines

Regards,

Tony

WBR, Sergei

A message that is not in the archive (sent off-list or not yet received): 1426718882-27187-1-git-send-email-tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org

#9 lore raw
Quoted 10 lines · On Wed, 18 Mar 2015 15:48:02 -0700 Tony Lindgren…

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter:

asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4

While at it, let's also remove pointless cast of the driver data.

This breaks my i386 allmodconfig build.

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 667

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+	void __iomem *fifo = hw_ep->fifo;
+	u32		val;
+	int		i;
+
+	/* Read for 32bit-aligned destination address */
+	if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+		readsl(fifo, dst, len >> 2);

akpm3:/usr/src/linux-4.0-rc6> grep -r readsl arch/x86 akpm3:/usr/src/linux-4.0-rc6>

Quoted 9 lines
drivers/usb/musb/musb_dsps.c +9 -0
+		dst += len & ~0x03;
+		len &= 0x03;
+	}
+	/*
+	 * Now read the remaining 1 to 3 byte or complete length if
+	 * unaligned address.
+	 */
+	if (len > 4) {
+		for (i = 0; i < (len >> 2); i++) {

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 686

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+			*(u32 *)dst = musb_readl(fifo, 0);
+			dst += 4;
+		}
+		len &= 0x03;
+	}
+	if (len > 0) {
+		val = musb_readl(fifo, 0);
+		memcpy(dst, &val, len);
+	}
+}

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw
Quoted 15 lines · Andrew Morton
Quoted 10 lines · On Wed, 18 Mar 2015 15:48:02 -0700 Tony Lindgren <[email protected]> wrote:

Looks like dm81xx can only do 32-bit fifo reads like am35x. Let's set up musb-dsps with a custom read_fifo function based on the compatible flag.

Otherwise we can get the following errors when starting dhclient on a asix USB Ethernet adapter:

asix 2-1:1.0 eth2: asix_rx_fixup() Bad Header Length 0xffff003c, offset 4

While at it, let's also remove pointless cast of the driver data.

This breaks my i386 allmodconfig build.

Quoted 13 lines

drivers/usb/musb/musb_dsps.c static int dsps_musb_reset(struct musb *musb) · line 667

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+/* Similar to am35x, dm81xx support only 32-bit read operation */
+static void dsps_read_fifo32(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
+{
+	void __iomem *fifo = hw_ep->fifo;
+	u32		val;
+	int		i;
+
+	/* Read for 32bit-aligned destination address */
+	if (likely((0x03 & (unsigned long)dst) == 0) && len >= 4) {
+		readsl(fifo, dst, len >> 2);

akpm3:/usr/src/linux-4.0-rc6> grep -r readsl arch/x86 akpm3:/usr/src/linux-4.0-rc6>

Yes sorry, the fix is to use ioread32_rep() instead. I already sent a fix for that on the 25th as:

"[PATCH 1/1] usb: musb: dsps: fix build on i386 when COMPILE_TEST is set"

https://www.marc.info/?l=linux-usb&m=142731859732737&w=1

Felipe, can you please get that into Linux next?

Regards,

Tony