Skip to contentSkip to conversation

usb: gadget: net2280: Add support for PLX USB338X

PATCH Superseded Ricardo Ribalda Delgado 2 participants 3 messages May 14, 2014 USB

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 usb: gadget: net2280: Add support for PLX USB338X

This patch adds support for the PLX USB3380 and USB3382.

This driver is based on the driver from the manufacturer.

Since USB338X is register compatible with NET2280, I thought that it would be better to include this hardware into net2280 driver.

Manufacturer's driver only supported the USB33X, did not follow the Kernel Style and contain some trivial errors. This patch has tried to address this issues.

This patch has only been tested on USB338x hardware, but the merge has been done trying to not affect the behaviour of NET2280.

---
v2:
-use usb_ep_set_maxpacket_limit
-usb338x: Fix support for high speed

 drivers/usb/gadget/Kconfig   |   10 +-
 drivers/usb/gadget/net2280.c | 1110 ++++++++++++++++++++++++++++++++++++++----
 drivers/usb/gadget/net2280.h |   96 +++-
 include/linux/usb/usb338x.h  |  199 ++++++++
 4 files changed, 1323 insertions(+), 92 deletions(-)
 create mode 100644 include/linux/usb/usb338x.h
drivers/usb/gadget/Kconfig +9 -1
index 3557c7e..831af8f 100644
@@ -415,7 +415,7 @@ config USB_NET2272_DMA
 	  If unsure, say "N" here.  The driver works fine in PIO mode.
 
 config USB_NET2280
-	tristate "NetChip 228x"
+	tristate "NetChip 228x / PLX USB338x"
 	depends on PCI
 	help
 	   NetChip 2280 / 2282 is a PCI based USB peripheral controller which
@@ -425,6 +425,14 @@ config USB_NET2280
 	   (for control transfers) and several endpoints with dedicated
 	   functions.
 
+	   PLX 3380 / 3382 is a PCIe based USB peripheral controller which
+	   supports full, high speed USB 2.0 and super speed USB 3.0
+	   data transfers.
+
+	   It has eight configurable endpoints, as well as endpoint zero
+	   (for control transfers) and several endpoints with dedicated
+	   functions.
+
 	   Say "y" to link the driver statically, or "m" to build a
 	   dynamically linked module called "net2280" and force all
 	   gadget drivers to also be dynamically linked.
drivers/usb/gadget/net2280.c +1024 -86

1,494 lines not on this page · raw message

drivers/usb/gadget/net2280.h +91 -5

172 lines not on this page · raw message

include/linux/usb/usb338x.h new file +199 -0

199 lines not on this page · raw message

Signature · 1 line
2.0.0.rc0
#1 lore raw
Quoted 7 lines · Ricardo Ribalda Delgado

This patch adds support for the PLX USB3380 and USB3382.

This driver is based on the driver from the manufacturer.

Since USB338X is register compatible with NET2280, I thought that it would be better to include this hardware into net2280 driver.

Quoted 6 lines

Manufacturer's driver only supported the USB33X, did not follow the Kernel Style and contain some trivial errors. This patch has tried to address this issues.

This patch has only been tested on USB338x hardware, but the merge has been done trying to not affect the behaviour of NET2280.

trivial notes:

drivers/usb/gadget/net2280.c

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0

[]

drivers/usb/gadget/net2280.c net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) · line 158

Quoted 5 lines
drivers/usb/gadget/net2280.c +1 -0
@@ -148,6 +155,10 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
 	struct net2280_ep	*ep;
 	u32			max, tmp;
 	unsigned long		flags;
+	static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };

[]

drivers/usb/gadget/net2280.c static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0
@@ -361,6 +407,56 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)

[]

drivers/usb/gadget/net2280.c static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) · line 414

Quoted 5 lines
drivers/usb/gadget/net2280.c +5 -0
+static void ep_reset_338x(struct net2280_regs __iomem *regs,
+					struct net2280_ep *ep)
+{
+	u32 tmp, dmastat;
+	static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };

To avoid duplication, perhaps ep_bit should be
declared static const to the module instead of
declared in multiple functions.

drivers/usb/gadget/net2280.c net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) · line 997

Quoted 8 lines
drivers/usb/gadget/net2280.c +4 -0
@@ -874,8 +991,23 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
 	/* kickstart this i/o queue? */
 	if (list_empty (&ep->queue) && !ep->stopped) {
+		/* DMA request while EP halted */
+		if (ep->dma
+		    && (readl(&ep->regs->ep_rsp) & (1 << CLEAR_ENDPOINT_HALT))
+			&& (dev->pdev->vendor == 0x10b5)) {

Generally logical continuations are at the end-of-line like

		if (ep->dma &&
		    (readl(&ep->regs->ep_rsp) & (1 << CLEAR_ENDPOINT_HALT)) &&
		    (dev->pdev->vendor == 0x10b5)) {

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev)

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0
@@ -1820,7 +2149,122 @@ static void usb_reinit (struct net2280 *dev)

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev) · line 2181

Quoted 6 lines
drivers/usb/gadget/net2280.c +6 -0
+		if (dev->enhanced_mode) {
+			ep->cfg = &dev->epregs[ne[i]];
+			ep->regs =
+			    (struct net2280_ep_regs __iomem
+			     *)(((unsigned char *)&dev->epregs[ne[i]]) +
+				ep_reg_addr[i]);

I find this pretty difficult to read.
Temporaries might help.

Or maybe cast ep->cfg like

			ep->regs = (struct net2280_ep_regs __iomem *)
				   ((unsigned char *)ep->cfg + ep_reg_addr[i]);

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev) · line 2226

Quoted 4 lines
drivers/usb/gadget/net2280.c +4 -0
+	/* AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
+	   Hot Reset Exit Handshake may Fail in Specific Case using
+	   Default Register Settings. Workaround for Enumeration test.
+	 */

linux-kernel multi-line comment style is generally:

	/*
	 * comments...
	 */
#2 lore raw

Hello Joe

Thanks for your comments. I have already prepared a v3 with your
comments. I wait some hours for more comments and then I resubmit the patch to avoid spamming the list.

Thanks for your time!

Quoted 83 lines · Joe Perches
Quoted 7 lines · Ricardo Ribalda Delgado

This patch adds support for the PLX USB3380 and USB3382.

This driver is based on the driver from the manufacturer.

Since USB338X is register compatible with NET2280, I thought that it would be better to include this hardware into net2280 driver.

Quoted 6 lines

Manufacturer's driver only supported the USB33X, did not follow the Kernel Style and contain some trivial errors. This patch has tried to address this issues.

This patch has only been tested on USB338x hardware, but the merge has been done trying to not affect the behaviour of NET2280.

trivial notes:

drivers/usb/gadget/net2280.c

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0

[]

drivers/usb/gadget/net2280.c net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc) · line 158

Quoted 5 lines
drivers/usb/gadget/net2280.c +1 -0
@@ -148,6 +155,10 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
      struct net2280_ep       *ep;
      u32                     max, tmp;
      unsigned long           flags;
+     static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };

[]

drivers/usb/gadget/net2280.c static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0
@@ -361,6 +407,56 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)

[]

drivers/usb/gadget/net2280.c static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep) · line 414

Quoted 5 lines
drivers/usb/gadget/net2280.c +5 -0
+static void ep_reset_338x(struct net2280_regs __iomem *regs,
+                                     struct net2280_ep *ep)
+{
+     u32 tmp, dmastat;
+     static const u32 ep_bit[9] = { 0, 17, 2, 19, 4, 1, 18, 3, 20 };

To avoid duplication, perhaps ep_bit should be
declared static const to the module instead of
declared in multiple functions.

drivers/usb/gadget/net2280.c net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) · line 997

Quoted 8 lines
drivers/usb/gadget/net2280.c +4 -0
@@ -874,8 +991,23 @@ net2280_queue (struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 
      /* kickstart this i/o queue? */
      if (list_empty (&ep->queue) && !ep->stopped) {
+             /* DMA request while EP halted */
+             if (ep->dma
+                 && (readl(&ep->regs->ep_rsp) & (1 << CLEAR_ENDPOINT_HALT))
+                     && (dev->pdev->vendor == 0x10b5)) {

Generally logical continuations are at the end-of-line like

                if (ep->dma &&
                    (readl(&ep->regs->ep_rsp) & (1 << CLEAR_ENDPOINT_HALT)) &&
                    (dev->pdev->vendor == 0x10b5)) {

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev)

Quoted 1 line
drivers/usb/gadget/net2280.c +0 -0
@@ -1820,7 +2149,122 @@ static void usb_reinit (struct net2280 *dev)

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev) · line 2181

Quoted 6 lines
drivers/usb/gadget/net2280.c +6 -0
+             if (dev->enhanced_mode) {
+                     ep->cfg = &dev->epregs[ne[i]];
+                     ep->regs =
+                         (struct net2280_ep_regs __iomem
+                          *)(((unsigned char *)&dev->epregs[ne[i]]) +
+                             ep_reg_addr[i]);

I find this pretty difficult to read.
Temporaries might help.

Or maybe cast ep->cfg like

                        ep->regs = (struct net2280_ep_regs __iomem *)
                                   ((unsigned char *)ep->cfg + ep_reg_addr[i]);

[]

drivers/usb/gadget/net2280.c static void usb_reinit (struct net2280 *dev) · line 2226

Quoted 4 lines
drivers/usb/gadget/net2280.c +4 -0
+     /* AA_AB Errata. Issue 4. Workaround for SuperSpeed USB
+        Hot Reset Exit Handshake may Fail in Specific Case using
+        Default Register Settings. Workaround for Enumeration test.
+      */

linux-kernel multi-line comment style is generally:

        /*
         * comments...
         */
Signature · 1 line
Ricardo Ribalda