[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20251227145224.2091397-1-krishna.kurapati@oss.qualcomm.com>
Date: Sat, 27 Dec 2025 20:22:24 +0530
From: Krishna Kurapati <krishna.kurapati@....qualcomm.com>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jonathan Corbet <corbet@....net>
Cc: linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
Krishna Kurapati <krishna.kurapati@....qualcomm.com>
Subject: [PATCH] usb: gadget: f_sourcesink: Support maxburst configurability for bulk endpoints
Add support to configure maxburst via configfs for bulk endpoints.
Update gadget documentation describing the new configfs property.
Signed-off-by: Krishna Kurapati <krishna.kurapati@....qualcomm.com>
---
Note:
- Verified by checking bulk ep descriptors on host after changing values
via configfs.
- Ignored two checkpatch errors complaining usage of "unsigned" instead of
"unsinged int". This was done to maintain consistency in declaration of
variables in structures.
Documentation/usb/gadget-testing.rst | 1 +
drivers/usb/gadget/function/f_sourcesink.c | 52 ++++++++++++++++++++++
drivers/usb/gadget/function/g_zero.h | 1 +
3 files changed, 54 insertions(+)
diff --git a/Documentation/usb/gadget-testing.rst b/Documentation/usb/gadget-testing.rst
index 5f90af1fb573..e32c5ad29e2d 100644
--- a/Documentation/usb/gadget-testing.rst
+++ b/Documentation/usb/gadget-testing.rst
@@ -686,6 +686,7 @@ The SOURCESINK function provides these attributes in its function directory:
isoc_mult 0..2 (hs/ss only)
isoc_maxburst 0..15 (ss only)
bulk_buflen buffer length
+ bulk_maxburst 0..15 (ss only)
bulk_qlen depth of queue for bulk
iso_qlen depth of queue for iso
=============== ==================================
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index ec5fd25020fd..ca80b26e4fc9 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -46,6 +46,7 @@ struct f_sourcesink {
unsigned isoc_mult;
unsigned isoc_maxburst;
unsigned buflen;
+ unsigned bulk_maxburst;
unsigned bulk_qlen;
unsigned iso_qlen;
};
@@ -328,6 +329,12 @@ sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
source_sink_intf_alt0.bInterfaceNumber = id;
source_sink_intf_alt1.bInterfaceNumber = id;
+ if (ss->bulk_maxburst > 15)
+ ss->bulk_maxburst = 15;
+
+ ss_source_comp_desc.bMaxBurst = ss->bulk_maxburst;
+ ss_sink_comp_desc.bMaxBurst = ss->bulk_maxburst;
+
/* allocate bulk endpoints */
ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);
if (!ss->in_ep) {
@@ -853,6 +860,7 @@ static struct usb_function *source_sink_alloc_func(
ss->isoc_mult = ss_opts->isoc_mult;
ss->isoc_maxburst = ss_opts->isoc_maxburst;
ss->buflen = ss_opts->bulk_buflen;
+ ss->bulk_maxburst = ss_opts->bulk_maxburst;
ss->bulk_qlen = ss_opts->bulk_qlen;
ss->iso_qlen = ss_opts->iso_qlen;
@@ -1101,6 +1109,49 @@ static ssize_t f_ss_opts_isoc_maxburst_store(struct config_item *item,
CONFIGFS_ATTR(f_ss_opts_, isoc_maxburst);
+static ssize_t f_ss_opts_bulk_maxburst_show(struct config_item *item, char *page)
+{
+ struct f_ss_opts *opts = to_f_ss_opts(item);
+ int result;
+
+ mutex_lock(&opts->lock);
+ result = sysfs_emit(page, "%u\n", opts->bulk_maxburst);
+ mutex_unlock(&opts->lock);
+
+ return result;
+}
+
+static ssize_t f_ss_opts_bulk_maxburst_store(struct config_item *item,
+ const char *page, size_t len)
+{
+ struct f_ss_opts *opts = to_f_ss_opts(item);
+ int ret;
+ u8 num;
+
+ mutex_lock(&opts->lock);
+ if (opts->refcnt) {
+ ret = -EBUSY;
+ goto end;
+ }
+
+ ret = kstrtou8(page, 0, &num);
+ if (ret)
+ goto end;
+
+ if (num > 15) {
+ ret = -EINVAL;
+ goto end;
+ }
+
+ opts->bulk_maxburst = num;
+ ret = len;
+end:
+ mutex_unlock(&opts->lock);
+ return ret;
+}
+
+CONFIGFS_ATTR(f_ss_opts_, bulk_maxburst);
+
static ssize_t f_ss_opts_bulk_buflen_show(struct config_item *item, char *page)
{
struct f_ss_opts *opts = to_f_ss_opts(item);
@@ -1222,6 +1273,7 @@ static struct configfs_attribute *ss_attrs[] = {
&f_ss_opts_attr_isoc_mult,
&f_ss_opts_attr_isoc_maxburst,
&f_ss_opts_attr_bulk_buflen,
+ &f_ss_opts_attr_bulk_maxburst,
&f_ss_opts_attr_bulk_qlen,
&f_ss_opts_attr_iso_qlen,
NULL,
diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
index 98b8462ad538..7bd66004821f 100644
--- a/drivers/usb/gadget/function/g_zero.h
+++ b/drivers/usb/gadget/function/g_zero.h
@@ -34,6 +34,7 @@ struct f_ss_opts {
unsigned isoc_mult;
unsigned isoc_maxburst;
unsigned bulk_buflen;
+ unsigned bulk_maxburst;
unsigned bulk_qlen;
unsigned iso_qlen;
--
2.34.1
Powered by blists - more mailing lists