2021-07-10 09:14:33

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH v14 0/6] Re-introduce TX FIFO resize for larger EP bursting

Changes in V14:
- Adding missing comment for do_fifo_resize parameter.

Changes in V13:
- Added some more comments on the background of the APIs and how they work.
- Check for the do_fifo_resize flag before reading out the max number of fifos
DT property.

Changes in V12:
- Re-added change to add a stub for of_add_property(), and exporting it as well
so that it can be used by modules.
- Minor updates to some of the APIs, including updating comments, adding error
handling, etc...

Changes in V11:
- Added a DWC3 controller revision check to use a different calculation, based
on Ferry's testing.
- Removed descriptor loop in configfs, and utilize the fact that the ep->claimed
parameter is still valid as ep_autoconf_reset() isn't called at the time of
check_config()
- Fix compilation errors if CONFIG_OF is not defined
- Removed patch to add stubs for of_add_property()

Changes in V10:
- Fixed compilation errors in config where OF is not used (error due to
unknown symbol for of_add_property()). Add of_add_property() stub.
- Fixed compilation warning for incorrect argument being passed to dwc3_mdwidth

Changes in V9:
- Fixed incorrect patch in series. Removed changes in DTSI, as dwc3-qcom will
add the property by default from the kernel.

Changes in V8:
- Rebased to usb-testing
- Using devm_kzalloc for adding txfifo property in dwc3-qcom
- Removed DWC3 QCOM ACPI property for enabling the txfifo resize

Changes in V7:
- Added a new property tx-fifo-max-num for limiting how much fifo space the
resizing logic can allocate for endpoints with large burst values. This
can differ across platforms, and tie in closely with overall system latency.
- Added recommended checks for DWC32.
- Added changes to set the tx-fifo-resize property from dwc3-qcom by default
instead of modifying the current DTSI files.
- Added comments on all APIs/variables introduced.
- Updated the DWC3 YAML to include a better description of the tx-fifo-resize
property and added an entry for tx-fifo-max-num.

Changes in V6:
- Rebased patches to usb-testing.
- Renamed to PATCH series instead of RFC.
- Checking for fs_descriptors instead of ss_descriptors for determining the
endpoint count for a particular configuration.
- Re-ordered patch series to fix patch dependencies.

Changes in V5:
- Added check_config() logic, which is used to communicate the number of EPs
used in a particular configuration. Based on this, the DWC3 gadget driver
has the ability to know the maximum number of eps utilized in all configs.
This helps reduce unnecessary allocation to unused eps, and will catch fifo
allocation issues at bind() time.
- Fixed variable declaration to single line per variable, and reverse xmas.
- Created a helper for fifo clearing, which is used by ep0.c

Changes in V4:
- Removed struct dwc3* as an argument for dwc3_gadget_resize_tx_fifos()
- Removed WARN_ON(1) in case we run out of fifo space

Changes in V3:
- Removed "Reviewed-by" tags
- Renamed series back to RFC
- Modified logic to ensure that fifo_size is reset if we pass the minimum
threshold. Tested with binding multiple FDs requesting 6 FIFOs.

Changes in V2:
- Modified TXFIFO resizing logic to ensure that each EP is reserved a
FIFO.
- Removed dev_dbg() prints and fixed typos from patches
- Added some more description on the dt-bindings commit message

Currently, there is no functionality to allow for resizing the TXFIFOs, and
relying on the HW default setting for the TXFIFO depth. In most cases, the
HW default is probably sufficient, but for USB compositions that contain
multiple functions that require EP bursting, the default settings
might not be enough. Also to note, the current SW will assign an EP to a
function driver w/o checking to see if the TXFIFO size for that particular
EP is large enough. (this is a problem if there are multiple HW defined
values for the TXFIFO size)

It is mentioned in the SNPS databook that a minimum of TX FIFO depth = 3
is required for an EP that supports bursting. Otherwise, there may be
frequent occurences of bursts ending. For high bandwidth functions,
such as data tethering (protocols that support data aggregation), mass
storage, and media transfer protocol (over FFS), the bMaxBurst value can be
large, and a bigger TXFIFO depth may prove to be beneficial in terms of USB
throughput. (which can be associated to system access latency, etc...) It
allows for a more consistent burst of traffic, w/o any interruptions, as
data is readily available in the FIFO.

With testing done using the mass storage function driver, the results show
that with a larger TXFIFO depth, the bandwidth increased significantly.

Test Parameters:
- Platform: Qualcomm SM8150
- bMaxBurst = 6
- USB req size = 256kB
- Num of USB reqs = 16
- USB Speed = Super-Speed
- Function Driver: Mass Storage (w/ ramdisk)
- Test Application: CrystalDiskMark

Results:

TXFIFO Depth = 3 max packets

Test Case | Data Size | AVG tput (in MB/s)
-------------------------------------------
Sequential|1 GB x |
Read |9 loops | 193.60
| | 195.86
| | 184.77
| | 193.60
-------------------------------------------

TXFIFO Depth = 6 max packets

Test Case | Data Size | AVG tput (in MB/s)
-------------------------------------------
Sequential|1 GB x |
Read |9 loops | 287.35
| | 304.94
| | 289.64
| | 293.61
-------------------------------------------

Wesley Cheng (6):
usb: gadget: udc: core: Introduce check_config to verify USB
configuration
usb: gadget: configfs: Check USB configuration before adding
usb: dwc3: Resize TX FIFOs to meet EP bursting requirements
of: Add stub for of_add_property()
usb: dwc3: dwc3-qcom: Enable tx-fifo-resize property by default
dt-bindings: usb: dwc3: Update dwc3 TX fifo properties

.../devicetree/bindings/usb/snps,dwc3.yaml | 15 +-
drivers/of/base.c | 1 +
drivers/usb/dwc3/core.c | 15 ++
drivers/usb/dwc3/core.h | 16 ++
drivers/usb/dwc3/dwc3-qcom.c | 15 ++
drivers/usb/dwc3/ep0.c | 2 +
drivers/usb/dwc3/gadget.c | 232 +++++++++++++++++++++
drivers/usb/gadget/configfs.c | 4 +
drivers/usb/gadget/udc/core.c | 19 ++
include/linux/of.h | 5 +
include/linux/usb/gadget.h | 4 +
11 files changed, 326 insertions(+), 2 deletions(-)

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


2021-07-10 09:14:39

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH v14 4/6] of: Add stub for of_add_property()

If building with OF Kconfig disabled, this can lead to errors for
drivers utilizing of_add_property(). Add a stub for the add API, as
it exists for the remove variant as well, and to avoid compliation
issues. Also, export this API so that it can be used by modules.

Signed-off-by: Wesley Cheng <[email protected]>
---
drivers/of/base.c | 1 +
include/linux/of.h | 5 +++++
2 files changed, 6 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 48e941f..5883d63 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1821,6 +1821,7 @@ int of_add_property(struct device_node *np, struct property *prop)

return rc;
}
+EXPORT_SYMBOL_GPL(of_add_property);

int __of_remove_property(struct device_node *np, struct property *prop)
{
diff --git a/include/linux/of.h b/include/linux/of.h
index 9c2e71e..0e786b60 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -946,6 +946,11 @@ static inline int of_machine_is_compatible(const char *compat)
return 0;
}

+static inline int of_add_property(struct device_node *np, struct property *prop)
+{
+ return 0;
+}
+
static inline int of_remove_property(struct device_node *np, struct property *prop)
{
return 0;
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2021-07-10 09:14:43

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH v14 6/6] dt-bindings: usb: dwc3: Update dwc3 TX fifo properties

Update the tx-fifo-resize property with a better description, while
adding the tx-fifo-max-num, which is a new parameter allowing
adjustments for the maximum number of packets the txfifo resizing logic
can account for while resizing the endpoints.

Reviewed-by: Rob Herring <[email protected]>
Signed-off-by: Wesley Cheng <[email protected]>
---
Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml
index 41416fb..078fb78 100644
--- a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml
+++ b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml
@@ -289,10 +289,21 @@ properties:
maximum: 16

tx-fifo-resize:
- description: Determines if the FIFO *has* to be reallocated
- deprecated: true
+ description: Determines if the TX fifos can be dynamically resized depending
+ on the number of IN endpoints used and if bursting is supported. This
+ may help improve bandwidth on platforms with higher system latencies, as
+ increased fifo space allows for the controller to prefetch data into its
+ internal memory.
type: boolean

+ tx-fifo-max-num:
+ description: Specifies the max number of packets the txfifo resizing logic
+ can account for when higher endpoint bursting is used. (bMaxBurst > 6) The
+ higher the number, the more fifo space the txfifo resizing logic will
+ allocate for that endpoint.
+ $ref: /schemas/types.yaml#/definitions/uint8
+ minimum: 3
+
snps,incr-burst-type-adjustment:
description:
Value for INCR burst type of GSBUSCFG0 register, undefined length INCR
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2021-07-10 09:15:01

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH v14 5/6] usb: dwc3: dwc3-qcom: Enable tx-fifo-resize property by default

In order to take advantage of the TX fifo resizing logic, manually add
these properties to the DWC3 child node by default. This will allow
the DWC3 gadget to resize the TX fifos for the IN endpoints, which
help with performance.

Signed-off-by: Wesley Cheng <[email protected]>
---
drivers/usb/dwc3/dwc3-qcom.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 49e6ca9..2223b59 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -645,6 +645,7 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
struct device_node *np = pdev->dev.of_node, *dwc3_np;
struct device *dev = &pdev->dev;
+ struct property *prop;
int ret;

dwc3_np = of_get_compatible_child(np, "snps,dwc3");
@@ -653,6 +654,20 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
return -ENODEV;
}

+ prop = devm_kzalloc(dev, sizeof(*prop), GFP_KERNEL);
+ if (!prop) {
+ ret = -ENOMEM;
+ dev_err(dev, "unable to allocate memory for property\n");
+ goto node_put;
+ }
+
+ prop->name = "tx-fifo-resize";
+ ret = of_add_property(dwc3_np, prop);
+ if (ret) {
+ dev_err(dev, "unable to add property\n");
+ goto node_put;
+ }
+
ret = of_platform_populate(np, NULL, NULL, dev);
if (ret) {
dev_err(dev, "failed to register dwc3 core - %d\n", ret);
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2021-07-10 09:15:54

by Wesley Cheng

[permalink] [raw]
Subject: [PATCH v14 2/6] usb: gadget: configfs: Check USB configuration before adding

Ensure that the USB gadget is able to support the configuration being
added based on the number of endpoints required from all interfaces. This
is for accounting for any bandwidth or space limitations.

Signed-off-by: Wesley Cheng <[email protected]>
---
drivers/usb/gadget/configfs.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 15a607c..f4c7c82 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1404,6 +1404,10 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
goto err_purge_funcs;
}
}
+ ret = usb_gadget_check_config(cdev->gadget);
+ if (ret)
+ goto err_purge_funcs;
+
usb_ep_autoconfig_reset(cdev->gadget);
}
if (cdev->use_os_string) {
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project