Skip to contentSkip to conversation

usb: gadget: cdns3: Fix cdns3_ep_config() by setting ep.maxpacket

PATCH Superseded Siddharth Vadapalli 2 participants 4 messages Oct 7, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: cdns3: Fix cdns3_ep_config() by setting ep.maxpacket

The function cdns3_ep_config() calculates the maximum packet size based on the Endpoint Type and the Gadget Speed and stores it in the variable "max_packet_size". This value is then programmed in the USB Controller for the corresponding Endpoint. This may result in a mismatch between the maximum packet size programmed in the USB controller and the maximum packet size seen by the UDC Core via "maxpacket" member of "struct usb_ep". Additionally, since TD_SIZE is calculated in cdns3_ep_run_transfer() on the basis of the maximum packet size stored in the "maxpacket" member of "struct usb_ep", it may lead to an incorrect value of TD_SIZE when compared with what the USB controller actually expects (max_packet_size).

Fix this by using usb_ep_set_maxpacket_limit().

Fixes 7e91f6ccdc84 ("usb: Add Cadence USB3 host and gadget driver")

---

Hello,

This patch is based on commit
dd4d130c8e clk: renesas: rcar-gen3: Fix SSCG caching replacement with MDSEL/PE caching of the master branch of U-Boot.

Patch has been tested on AM642-EVM.

Regards,
Siddharth.

 drivers/usb/cdns3/gadget.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/cdns3/gadget.c +8 -0
index ac7e469469..b0b08768d9 100644
@@ -1637,6 +1637,14 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep)
 	else
 		priv_ep->trb_burst_size = 16;
 
+	/*
+	 * The Endpoint is configured to handle a maximum packet size of
+	 * max_packet_size. Hence, set priv_ep->endpoint.maxpacket to
+	 * max_packet_size. This is necessary to ensure that the TD_SIZE
+	 * is calculated correctly in cdns3_ep_run_transfer().
+	 */
+	usb_ep_set_maxpacket_limit(&priv_ep->endpoint, max_packet_size);
+
 	ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1,
 					     !!priv_ep->dir);
 	if (ret) {
Signature · 1 line
2.40.1
reviewer
#1 lore raw
Quoted 37 lines · Siddharth Vadapalli

The function cdns3_ep_config() calculates the maximum packet size based on the Endpoint Type and the Gadget Speed and stores it in the variable "max_packet_size". This value is then programmed in the USB Controller for the corresponding Endpoint. This may result in a mismatch between the maximum packet size programmed in the USB controller and the maximum packet size seen by the UDC Core via "maxpacket" member of "struct usb_ep". Additionally, since TD_SIZE is calculated in cdns3_ep_run_transfer() on the basis of the maximum packet size stored in the "maxpacket" member of "struct usb_ep", it may lead to an incorrect value of TD_SIZE when compared with what the USB controller actually expects (max_packet_size).

Fix this by using usb_ep_set_maxpacket_limit().

Fixes 7e91f6ccdc84 ("usb: Add Cadence USB3 host and gadget driver")

---

Hello,

This patch is based on commit
dd4d130c8e clk: renesas: rcar-gen3: Fix SSCG caching replacement with MDSEL/PE caching of the master branch of U-Boot.

Patch has been tested on AM642-EVM.

Regards,
Siddharth.

 drivers/usb/cdns3/gadget.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/cdns3/gadget.c +0 -0
index ac7e469469..b0b08768d9 100644
@@ -1637,6 +1637,14 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep)
 	else

drivers/usb/cdns3/gadget.c void cdns3_ep_config(struct cdns3_endpoint *priv_ep) · line 1647

Quoted 10 lines
drivers/usb/cdns3/gadget.c +8 -0
 		priv_ep->trb_burst_size = 16;
 
+	/*
+	 * The Endpoint is configured to handle a maximum packet size of
+	 * max_packet_size. Hence, set priv_ep->endpoint.maxpacket to
+	 * max_packet_size. This is necessary to ensure that the TD_SIZE
+	 * is calculated correctly in cdns3_ep_run_transfer().
+	 */
+	usb_ep_set_maxpacket_limit(&priv_ep->endpoint, max_packet_size);
+

from include/linux/usb/gadget.h

* struct usb_ep - device side representation of USB endpoint
...
* @maxpacket:The maximum packet size used on this endpoint. The initial
* value can sometimes be reduced (hardware allowing), according to
* the endpoint descriptor used to configure the endpoint.
* @maxpacket_limit:The maximum packet size value which can be handled by this
* endpoint. It's set once by UDC driver when endpoint is initialized, and
* should not be changed. Should not be confused with maxpacket.

What you want to change is ep->maxpacket and not ep->maxpacket_limit as that is fixed for a particular UDC.

how about?

	priv-ep->endpoint.maxpacket = max_packet_size;
Quoted 3 lines
drivers/usb/cdns3/gadget.c +0 -0
 	ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1,
 					     !!priv_ep->dir);
 	if (ret) {
Signature · 2 lines
cheers,
-roger
#2 lore raw

On Mon, Oct 07, 2024 at 03:02:34PM +0300, Roger Quadros wrote:

Hello Roger,

Quoted 12 lines · Siddharth Vadapalli
Quoted 11 lines

The function cdns3_ep_config() calculates the maximum packet size based on the Endpoint Type and the Gadget Speed and stores it in the variable "max_packet_size". This value is then programmed in the USB Controller for the corresponding Endpoint. This may result in a mismatch between the maximum packet size programmed in the USB controller and the maximum packet size seen by the UDC Core via "maxpacket" member of "struct usb_ep". Additionally, since TD_SIZE is calculated in cdns3_ep_run_transfer() on the basis of the maximum packet size stored in the "maxpacket" member of "struct usb_ep", it may lead to an incorrect value of TD_SIZE when compared with what the USB controller actually expects (max_packet_size).

[...]

Quoted 28 lines
Quoted 6 lines
drivers/usb/cdns3/gadget.c +0 -0
index ac7e469469..b0b08768d9 100644
@@ -1637,6 +1637,14 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep)
 	else

drivers/usb/cdns3/gadget.c void cdns3_ep_config(struct cdns3_endpoint *priv_ep) · line 1647

Quoted 10 lines
drivers/usb/cdns3/gadget.c +8 -0
 		priv_ep->trb_burst_size = 16;
 
+	/*
+	 * The Endpoint is configured to handle a maximum packet size of
+	 * max_packet_size. Hence, set priv_ep->endpoint.maxpacket to
+	 * max_packet_size. This is necessary to ensure that the TD_SIZE
+	 * is calculated correctly in cdns3_ep_run_transfer().
+	 */
+	usb_ep_set_maxpacket_limit(&priv_ep->endpoint, max_packet_size);
+

from include/linux/usb/gadget.h

* struct usb_ep - device side representation of USB endpoint
...
* @maxpacket:The maximum packet size used on this endpoint. The initial
* value can sometimes be reduced (hardware allowing), according to
* the endpoint descriptor used to configure the endpoint.
* @maxpacket_limit:The maximum packet size value which can be handled by this
* endpoint. It's set once by UDC driver when endpoint is initialized, and
* should not be changed. Should not be confused with maxpacket.

Quoted 5 lines

What you want to change is ep->maxpacket and not ep->maxpacket_limit as that is fixed for a particular UDC.

how about?

	priv-ep->endpoint.maxpacket = max_packet_size;

Yes, this is accurate. I will post the v2 patch with this change. Thank you for reviewing the patch.

Regards,
Siddharth.

#3 lore raw
Quoted 3 lines · Siddharth Vadapalli

On Mon, Oct 07, 2024 at 03:02:34PM +0300, Roger Quadros wrote:

Hello Roger,

[...]

Quoted 11 lines
Quoted 11 lines

from include/linux/usb/gadget.h

* struct usb_ep - device side representation of USB endpoint
...
* @maxpacket:The maximum packet size used on this endpoint. The initial
* value can sometimes be reduced (hardware allowing), according to
* the endpoint descriptor used to configure the endpoint.
* @maxpacket_limit:The maximum packet size value which can be handled by this
* endpoint. It's set once by UDC driver when endpoint is initialized, and
* should not be changed. Should not be confused with maxpacket.

Quoted 8 lines
Quoted 5 lines

What you want to change is ep->maxpacket and not ep->maxpacket_limit as that is fixed for a particular UDC.

how about?

	priv-ep->endpoint.maxpacket = max_packet_size;

Yes, this is accurate. I will post the v2 patch with this change. Thank you for reviewing the patch.

I have implemented your feedback and have posted the v2 patch at:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]

Regards,
Siddharth.