Skip to contentSkip to conversation

usb: dwc3: gadget: Fix fullspeed interval setting

PATCH New Thinh Nguyen 1 participant 3 messages Feb 8, 2021

Subsystems (3)
lore
Share & tools
lore

Thinh Nguyen

author maintainer
#0 lore raw

cover usb: dwc3: gadget: Fix fullspeed interval setting

The dwc3 driver did not account for operating in fullspeed when setting DEPCFG.bInterval_m1. This series fixes it.

Note that for some bInterval, some IP versions may not exhibit invalid behavior from the invalid DEPCFG.bInterval_m1 setting, which may mask this issue.

Thinh Nguyen (2):
usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1
usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt

 drivers/usb/dwc3/gadget.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

base-commit: d8c849037d9398abe6a5f5d065eafc777eb3bdaf

Signature · 1 line
2.28.0
author maintainer
#1 lore raw

PATCH 1/2 usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1

Valid range for DEPCFG.bInterval_m1 is from 0 to 13, and it must be set to 0 when the controller operates in full-speed. See the programming guide for DEPCFG command section 3.2.2.1 (v3.30a).

Fixes 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver")
---
 drivers/usb/dwc3/gadget.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +11 -1
index 97d707b4f384..d0f8d3ec855f 100644
@@ -605,7 +605,17 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action)
 		params.param0 |= DWC3_DEPCFG_FIFO_NUMBER(dep->number >> 1);
 
 	if (desc->bInterval) {
-		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(desc->bInterval - 1);
+		u8 bInterval_m1;
+
+		/*
+		 * Valid range for DEPCFG.bInterval_m1 is from 0 to 13, and it
+		 * must be set to 0 when the controller operates in full-speed.
+		 */
+		bInterval_m1 = min_t(u8, desc->bInterval - 1, 13);
+		if (dwc->gadget->speed == USB_SPEED_FULL)
+			bInterval_m1 = 0;
+
+		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(bInterval_m1);
 		dep->interval = 1 << (desc->bInterval - 1);
 	}
 
Signature · 1 line
2.28.0
author maintainer
#2 lore raw

PATCH 2/2 usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt

In reply to Thinh Nguyen

The dep->interval captures the number of frames/microframes per interval from bInterval. Fullspeed interrupt endpoint bInterval is the number of frames per interval and not 2^(bInterval - 1). So fix it here. This change is only for debugging purpose and should not affect the interrupt endpoint operation.

Fixes 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver")
---
 drivers/usb/dwc3/gadget.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/dwc3/gadget.c +6 -1
index d0f8d3ec855f..aebcf8ec0716 100644
@@ -615,8 +615,13 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action)
 		if (dwc->gadget->speed == USB_SPEED_FULL)
 			bInterval_m1 = 0;
 
+		if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT &&
+		    dwc->gadget->speed == USB_SPEED_FULL)
+			dep->interval = desc->bInterval;
+		else
+			dep->interval = 1 << (desc->bInterval - 1);
+
 		params.param1 |= DWC3_DEPCFG_BINTERVAL_M1(bInterval_m1);
-		dep->interval = 1 << (desc->bInterval - 1);
 	}
 
 	return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, &params);
Signature · 1 line
2.28.0