]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: gadget: f_sourcesink: Support maxburst configurability for bulk endpoints
authorKrishna Kurapati <krishna.kurapati@oss.qualcomm.com>
Sat, 27 Dec 2025 14:52:24 +0000 (20:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 7 Jan 2026 15:13:25 +0000 (16:13 +0100)
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@oss.qualcomm.com>
Link: https://patch.msgid.link/20251227145224.2091397-1-krishna.kurapati@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/usb/gadget-testing.rst
drivers/usb/gadget/function/f_sourcesink.c
drivers/usb/gadget/function/g_zero.h

index 01a128d664cb1114c4c3c3efd62b54216c2124b5..a6e8292f320a4b02ca0fbf7a1c79f85aa2b91a0e 100644 (file)
@@ -687,6 +687,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
        =============== ==================================
index 44c644877d3d6c8d367325d1f26c7fd36be8198f..22104e9c6cab0d024485a022dd45b6852a206e3d 100644 (file)
@@ -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 @@ end:
 
 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,
index 98b8462ad5381486d88aa89d92e44ad76a8c9fc6..7bd66004821f870617addf64f69769263089ea39 100644 (file)
@@ -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;