mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards
@ 2023-05-03 10:19 Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 1/4] usb: dwc2: Port support for USB FIFO devicetree properties from Linux v6.3 Oleksij Rempel
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 10:19 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

This patch series addresses the initial issue of USB Mass Storage (UMS)
mode not working on PRTT1L boards by improving USB FIFO handling in the
DWC2 driver, fixing multiplier handling in endpoint setup, and adding
support for multiple gadgets, including UMS, fastboot, and ACM gadgets.
The changes include porting support for USB FIFO devicetree properties
and FIFO configuration from Linux kernel v6.3. These patches were tested
on a PRTT1C board (based on stm32mp151) with the following command:
usbgadget -S '/dev/mmc1(mmc1)' -s -A '' -b

Michael Grzeschik (1):
  usb: dwc2: fix multiplier handling in endpoint setup

Oleksij Rempel (3):
  usb: dwc2: Port support for USB FIFO devicetree properties from Linux
    v6.3
  usb: dwc2: Port FIFO configuration sync from Linux v6.3
  arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple
    gadgets support

 arch/arm/dts/stm32mp151-prtt1l.dtsi |  1 +
 drivers/usb/dwc2/core.c             | 27 ++++++++++++++++++++
 drivers/usb/dwc2/dwc2.c             |  1 +
 drivers/usb/dwc2/dwc2.h             |  1 +
 drivers/usb/dwc2/gadget.c           | 38 +++++++++++------------------
 5 files changed, 44 insertions(+), 24 deletions(-)

-- 
2.39.2




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

* [PATCH v1 1/4] usb: dwc2: Port support for USB FIFO devicetree properties from Linux v6.3
  2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
@ 2023-05-03 10:19 ` Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 2/4] usb: dwc2: Port FIFO configuration sync " Oleksij Rempel
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 10:19 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

This patch ports the support for "g-rx-fifo-size", "g-np-tx-fifo-size",
and "g-tx-fifo-size" devicetree properties from Linux kernel v6.3. These
properties are required for proper FIFO configuration of different USB
endpoints in the gadget mode.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/usb/dwc2/core.c | 27 +++++++++++++++++++++++++++
 drivers/usb/dwc2/dwc2.c |  1 +
 drivers/usb/dwc2/dwc2.h |  1 +
 3 files changed, 29 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 9edd56d483..b198ba6bf8 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -188,6 +188,33 @@ void dwc2_set_default_params(struct dwc2 *dwc2)
 	}
 }
 
+void dwc2_get_device_properties(struct dwc2 *dwc2)
+{
+	struct dwc2_core_params *p = &dwc2->params;
+	struct device_node *np = dwc2->dev->of_node;
+	int num;
+
+	if ((dwc2->dr_mode == USB_DR_MODE_PERIPHERAL) ||
+	    (dwc2->dr_mode == USB_DR_MODE_OTG)) {
+		of_property_read_u32(np, "g-rx-fifo-size",
+					 &p->g_rx_fifo_size);
+
+		of_property_read_u32(np, "g-np-tx-fifo-size",
+					 &p->g_np_tx_fifo_size);
+
+		num = of_property_count_elems_of_size(np, "g-tx-fifo-size", sizeof(u32));
+		if (num > 0) {
+			num = min(num, 15);
+			memset(p->g_tx_fifo_size, 0,
+			       sizeof(p->g_tx_fifo_size));
+			of_property_read_u32_array(np,
+						       "g-tx-fifo-size",
+						       &p->g_tx_fifo_size[1],
+						       num);
+		}
+	}
+}
+
 int dwc2_check_core_version(struct dwc2 *dwc2)
 {
 	struct dwc2_hw_params *hw = &dwc2->hw_params;
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index ff4842ce62..3564cdd1d1 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -148,6 +148,7 @@ static int dwc2_probe(struct device *dev)
 		goto error;
 
 	dwc2_set_default_params(dwc2);
+	dwc2_get_device_properties(dwc2);
 
 	set_params = of_device_get_match_data(dev);
 	if (set_params)
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 15d4b69759..2e740a890e 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -9,6 +9,7 @@
 
 /* Core functions */
 void dwc2_set_default_params(struct dwc2 *dwc2);
+void dwc2_get_device_properties(struct dwc2 *dwc2);
 int dwc2_check_core_version(struct dwc2 *dwc2);
 void dwc2_get_hwparams(struct dwc2 *dwc2);
 
-- 
2.39.2




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

* [PATCH v1 2/4] usb: dwc2: Port FIFO configuration sync from Linux v6.3
  2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 1/4] usb: dwc2: Port support for USB FIFO devicetree properties from Linux v6.3 Oleksij Rempel
@ 2023-05-03 10:19 ` Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 3/4] usb: dwc2: fix multiplier handling in endpoint setup Oleksij Rempel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 10:19 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

This patch ports the FIFO configuration from Linux kernel v6.3. The
change mainly syncs the code with the kernel and removes an unused
register read and value assignment in the first step of the loop
(txfsz = dwc2_readl(dwc2, DPTXFSIZN(ep));).

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/usb/dwc2/gadget.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 028f3c877a..bb55888abf 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1549,9 +1549,8 @@ static void dwc2_gadget_setup_fifo(struct dwc2 *dwc2)
 	u32 np_tx_fifo_size = dwc2->params.g_np_tx_fifo_size;
 	u32 rx_fifo_size = dwc2->params.g_rx_fifo_size;
 	u32 fifo_size = dwc2->hw_params.total_fifo_size;
-	u32 *tx_fifo_size = dwc2->params.g_tx_fifo_size;
-	u32 size, depth;
-	u32 txfsz;
+	u32 *txfsz = dwc2->params.g_tx_fifo_size;
+	u32 size, val;
 
 	/* Reset fifo map if not correctly cleared during previous session */
 	WARN_ON(dwc2->fifo_map);
@@ -1578,19 +1577,17 @@ static void dwc2_gadget_setup_fifo(struct dwc2 *dwc2)
 	 * them to endpoints dynamically according to maxpacket size value of
 	 * given endpoint.
 	 */
-
-	for (ep = 1; ep < dwc2->num_eps; ep++) {
-		txfsz = dwc2_readl(dwc2, DPTXFSIZN(ep));
-		depth = tx_fifo_size[ep];
-
-		if (addr + depth > fifo_size)
-			dwc2_err(dwc2, "insufficient fifo memory\n");
-
-		txfsz = depth << FIFOSIZE_DEPTH_SHIFT;
-		txfsz |= addr & 0xffff;
-		dwc2_writel(dwc2, txfsz, DPTXFSIZN(ep));
-
-		addr += depth;
+	for (ep = 1; ep < DWC2_MAX_EPS_CHANNELS; ep++) {
+		if (!txfsz[ep])
+			continue;
+		val = addr;
+		val |= txfsz[ep] << FIFOSIZE_DEPTH_SHIFT;
+		WARN_ONCE(addr + txfsz[ep] > fifo_size,
+			  "insufficient fifo memory");
+		addr += txfsz[ep];
+
+		dwc2_writel(dwc2, val, DPTXFSIZN(ep));
+		val = dwc2_readl(dwc2, DPTXFSIZN(ep));
 	}
 
 	dwc2_writel(dwc2, dwc2->hw_params.total_fifo_size |
-- 
2.39.2




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

* [PATCH v1 3/4] usb: dwc2: fix multiplier handling in endpoint setup
  2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 1/4] usb: dwc2: Port support for USB FIFO devicetree properties from Linux v6.3 Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 2/4] usb: dwc2: Port FIFO configuration sync " Oleksij Rempel
@ 2023-05-03 10:19 ` Oleksij Rempel
  2023-05-03 10:19 ` [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support Oleksij Rempel
  2023-05-05  6:39 ` [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Sascha Hauer
  4 siblings, 0 replies; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 10:19 UTC (permalink / raw)
  To: barebox; +Cc: Jules Maselbas, Oleksij Rempel

From: Michael Grzeschik <m.grzeschik@pengutronix.de>

If the multiplier is 0 in the descriptor bitfield the multiplier count
is one. For calculating the multiplier count the extra function
usb_endpoint_maxp_mult should be used. Rework the dwc2 driver to use it
and make multi packages work.

While at it, we also remove the USB_EP_MAXP_MULT and
USB_ENDPOINT_MAXP_MASK macros that would stay left unused and are
defined in include/usb/ch9.ch anyway.

Tested-by: Jules Maselbas <jmaselbas@kalray.eu>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/usb/dwc2/gadget.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bb55888abf..00323d2d90 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -14,13 +14,6 @@
 #define spin_lock_irqsave(lock, flags) (void)(flags)
 #define spin_unlock_irqrestore(lock, flags) (void)(flags)
 
-#ifndef USB_ENDPOINT_MAXP_MASK
-#define USB_ENDPOINT_MAXP_MASK	0x07ff
-#endif
-#ifndef USB_EP_MAXP_MULT
-#define USB_EP_MAXP_MULT(m)	(((m) & 0x1800) >> 11)
-#endif
-
 static void kill_all_requests(struct dwc2 *, struct dwc2_ep *, int);
 
 static inline struct dwc2_ep *index_to_ep(struct dwc2 *dwc2,
@@ -484,7 +477,7 @@ static int dwc2_ep_enable(struct usb_ep *ep,
 
 	ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 	mps = usb_endpoint_maxp(desc) & USB_ENDPOINT_MAXP_MASK;
-	mc =  USB_EP_MAXP_MULT(usb_endpoint_maxp(desc));
+	mc = usb_endpoint_maxp_mult(desc);
 
 	/* note, we handle this here instead of dwc2_set_ep_maxpacket */
 	epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index);
-- 
2.39.2




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

* [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support
  2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
                   ` (2 preceding siblings ...)
  2023-05-03 10:19 ` [PATCH v1 3/4] usb: dwc2: fix multiplier handling in endpoint setup Oleksij Rempel
@ 2023-05-03 10:19 ` Oleksij Rempel
  2023-05-03 10:25   ` Ahmad Fatoum
  2023-05-05  6:39 ` [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Sascha Hauer
  4 siblings, 1 reply; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 10:19 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

This patch configures the USB gadget FIFOs of PRTT1L boards to support
multiple gadgets at the same time. The configuration was tested with the
"usbgadget -S '/dev/mmc1(mmc1)' -s -A '' -b" command.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/arm/dts/stm32mp151-prtt1l.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/stm32mp151-prtt1l.dtsi b/arch/arm/dts/stm32mp151-prtt1l.dtsi
index 98a9c20d6d..fecd068fc0 100644
--- a/arch/arm/dts/stm32mp151-prtt1l.dtsi
+++ b/arch/arm/dts/stm32mp151-prtt1l.dtsi
@@ -56,6 +56,7 @@
 	phys = <&usbphyc_port1 0>;
 	phy-names = "usb2-phy";
 	status = "okay";
+	g-tx-fifo-size = <128 128 128 16>;
 };
 
 &usbphyc {
-- 
2.39.2




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

* Re: [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support
  2023-05-03 10:19 ` [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support Oleksij Rempel
@ 2023-05-03 10:25   ` Ahmad Fatoum
  2023-05-03 11:01     ` Oleksij Rempel
  0 siblings, 1 reply; 8+ messages in thread
From: Ahmad Fatoum @ 2023-05-03 10:25 UTC (permalink / raw)
  To: Oleksij Rempel, barebox

Hello Oleksij,

On 03.05.23 12:19, Oleksij Rempel wrote:
> This patch configures the USB gadget FIFOs of PRTT1L boards to support
> multiple gadgets at the same time. The configuration was tested with the
> "usbgadget -S '/dev/mmc1(mmc1)' -s -A '' -b" command.

What's the downside on configuring the FIFO this way globally
in stm32mp151.dtsi? Should the same be done for Linux?

> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  arch/arm/dts/stm32mp151-prtt1l.dtsi | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/dts/stm32mp151-prtt1l.dtsi b/arch/arm/dts/stm32mp151-prtt1l.dtsi
> index 98a9c20d6d..fecd068fc0 100644
> --- a/arch/arm/dts/stm32mp151-prtt1l.dtsi
> +++ b/arch/arm/dts/stm32mp151-prtt1l.dtsi
> @@ -56,6 +56,7 @@
>  	phys = <&usbphyc_port1 0>;
>  	phy-names = "usb2-phy";
>  	status = "okay";
> +	g-tx-fifo-size = <128 128 128 16>;
>  };
>  
>  &usbphyc {

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




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

* Re: [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support
  2023-05-03 10:25   ` Ahmad Fatoum
@ 2023-05-03 11:01     ` Oleksij Rempel
  0 siblings, 0 replies; 8+ messages in thread
From: Oleksij Rempel @ 2023-05-03 11:01 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hello Ahmad,

On Wed, May 03, 2023 at 12:25:03PM +0200, Ahmad Fatoum wrote:
> Hello Oleksij,
> 
> On 03.05.23 12:19, Oleksij Rempel wrote:
> > This patch configures the USB gadget FIFOs of PRTT1L boards to support
> > multiple gadgets at the same time. The configuration was tested with the
> > "usbgadget -S '/dev/mmc1(mmc1)' -s -A '' -b" command.
> 
> What's the downside on configuring the FIFO this way globally
> in stm32mp151.dtsi? Should the same be done for Linux?

I do not know. It seems to be the use-case and SoC specific. Probably doing
this type of configuration in the devicetree is not the best idea at
all, but currently it is only way to do it in kernel, so let's do it in
barebox too.

> > Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > ---
> >  arch/arm/dts/stm32mp151-prtt1l.dtsi | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/arm/dts/stm32mp151-prtt1l.dtsi b/arch/arm/dts/stm32mp151-prtt1l.dtsi
> > index 98a9c20d6d..fecd068fc0 100644
> > --- a/arch/arm/dts/stm32mp151-prtt1l.dtsi
> > +++ b/arch/arm/dts/stm32mp151-prtt1l.dtsi
> > @@ -56,6 +56,7 @@
> >  	phys = <&usbphyc_port1 0>;
> >  	phy-names = "usb2-phy";
> >  	status = "okay";
> > +	g-tx-fifo-size = <128 128 128 16>;
> >  };
> >  
> >  &usbphyc {
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

* Re: [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards
  2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
                   ` (3 preceding siblings ...)
  2023-05-03 10:19 ` [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support Oleksij Rempel
@ 2023-05-05  6:39 ` Sascha Hauer
  4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2023-05-05  6:39 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Wed, May 03, 2023 at 12:19:15PM +0200, Oleksij Rempel wrote:
> This patch series addresses the initial issue of USB Mass Storage (UMS)
> mode not working on PRTT1L boards by improving USB FIFO handling in the
> DWC2 driver, fixing multiplier handling in endpoint setup, and adding
> support for multiple gadgets, including UMS, fastboot, and ACM gadgets.
> The changes include porting support for USB FIFO devicetree properties
> and FIFO configuration from Linux kernel v6.3. These patches were tested
> on a PRTT1C board (based on stm32mp151) with the following command:
> usbgadget -S '/dev/mmc1(mmc1)' -s -A '' -b
> 
> Michael Grzeschik (1):
>   usb: dwc2: fix multiplier handling in endpoint setup
> 
> Oleksij Rempel (3):
>   usb: dwc2: Port support for USB FIFO devicetree properties from Linux
>     v6.3
>   usb: dwc2: Port FIFO configuration sync from Linux v6.3
>   arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple
>     gadgets support

Applied, thanks

Sascha

> 
>  arch/arm/dts/stm32mp151-prtt1l.dtsi |  1 +
>  drivers/usb/dwc2/core.c             | 27 ++++++++++++++++++++
>  drivers/usb/dwc2/dwc2.c             |  1 +
>  drivers/usb/dwc2/dwc2.h             |  1 +
>  drivers/usb/dwc2/gadget.c           | 38 +++++++++++------------------
>  5 files changed, 44 insertions(+), 24 deletions(-)
> 
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2023-05-05  6:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 10:19 [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Oleksij Rempel
2023-05-03 10:19 ` [PATCH v1 1/4] usb: dwc2: Port support for USB FIFO devicetree properties from Linux v6.3 Oleksij Rempel
2023-05-03 10:19 ` [PATCH v1 2/4] usb: dwc2: Port FIFO configuration sync " Oleksij Rempel
2023-05-03 10:19 ` [PATCH v1 3/4] usb: dwc2: fix multiplier handling in endpoint setup Oleksij Rempel
2023-05-03 10:19 ` [PATCH v1 4/4] arm: dts: stm32mp151-prtt1l: Configure USB gadget FIFOs for multiple gadgets support Oleksij Rempel
2023-05-03 10:25   ` Ahmad Fatoum
2023-05-03 11:01     ` Oleksij Rempel
2023-05-05  6:39 ` [PATCH v1 0/4] Improve USB FIFO handling and enable UMS mode on PRTT1L boards Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox