usb: gadget: add SuperSpeed descriptor support
v3 cover usb: gadget: add SuperSpeed descriptor support
This series adds SuperSpeed descriptor support for the mass_storage and DFU gadget functions so they can operate correctly at SuperSpeed.
Dan Tran (2):
usb: gadget: mass_storage: add SuperSpeed descriptor support
usb: gadget: dfu: add SuperSpeed descriptor support
drivers/usb/gadget/f_dfu.c | 3 ++ drivers/usb/gadget/f_mass_storage.c | 28 ++++++++++++++-- drivers/usb/gadget/storage_common.c | 52 ++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 3 deletions(-)
base-commit: cc557af4553382f6f50e3ed62b9577054e7bc54f
Signature · 1 line
2.53.0
PATCH v3 1/2 usb: gadget: mass_storage: add SuperSpeed descriptor support
From: Dan Tran <[email protected]>
Add SS bulk endpoint descriptors (1024-byte MPS, bMaxBurst=15) to storage_common.c to support SuperSpeed connections. Extend fsg_ep_desc() to select them when operating at SuperSpeed, and wire up ss_descriptors in fsg_bind(). Free ss_descriptors in fsg_unbind() to match.
---
Changes in v3:
- Document and split the bMaxBurst calculation.
- Require superspeed capability when selecting the SuperSpeed descriptor.
Changes in v2:
- Removed internal Reviewed-by tags
drivers/usb/gadget/f_mass_storage.c | 28 ++++++++++++++-- drivers/usb/gadget/storage_common.c | 52 ++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-)
drivers/usb/gadget/f_mass_storage.c +26 -2
@@ -2226,14 +2226,16 @@ reset:/* Enable the endpoints */ d =fsg_ep_desc (common->gadget, - &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc, + &fsg_ss_bulk_in_desc); rc =enable_endpoint (common, fsg->bulk_in, d);if (rc) goto reset; fsg->bulk_in_enabled =1 ; d =fsg_ep_desc (common->gadget, - &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc, + &fsg_ss_bulk_out_desc); rc =enable_endpoint (common, fsg->bulk_out, d);if (rc) goto reset;
@@ -2654,6 +2656,7 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)fsg_common_release (fsg->common);free (fsg->function.descriptors);free (fsg->function.hs_descriptors); +free (fsg->function.ss_descriptors);kfree (fsg); }
@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) { +unsigned int max_burst; + +/* Calculate bMaxBurst, we know packet size is 1024 */ + max_burst = min_t(unsigned int, FSG_BUFLEN / 1024, 15); + + fsg_ss_bulk_in_desc.bEndpointAddress = + fsg_fs_bulk_in_desc.bEndpointAddress; + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst; + fsg_ss_bulk_out_desc.bEndpointAddress = + fsg_fs_bulk_out_desc.bEndpointAddress; + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst; + f->ss_descriptors =usb_copy_descriptors (fsg_ss_function); +if (unlikely (!f->ss_descriptors)) { +free (f->hs_descriptors); +free (f->descriptors); +return -ENOMEM ; + } + } +return 0 ; autoconf_fail:
drivers/usb/gadget/storage_common.c +51 -1
62 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
On 9/4/26 4:29 AM, Thinh Nguyen wrote:
Hello Thinh,
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2716
Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +2
-0@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) {
Nitpick -- you could invert the conditional here and reduce indent:
if (!gadget_is_superspeed(gadget))
return 0;
...
Quoted 10 lines
drivers/usb/gadget/f_mass_storage.c +10
-0+unsigned int max_burst; + +/* Calculate bMaxBurst, we know packet size is 1024 */ + max_burst = min_t(unsigned int, FSG_BUFLEN / 1024, 15); + + fsg_ss_bulk_in_desc.bEndpointAddress = + fsg_fs_bulk_in_desc.bEndpointAddress; + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst; + fsg_ss_bulk_out_desc.bEndpointAddress = + fsg_fs_bulk_out_desc.bEndpointAddress;
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2736
Quoted 10 lines
drivers/usb/gadget/f_mass_storage.c +9
-0+ fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst; + f->ss_descriptors =usb_copy_descriptors (fsg_ss_function); +if (unlikely (!f->ss_descriptors)) { +free (f->hs_descriptors); +free (f->descriptors); +return -ENOMEM ; + } + } +return 0 ;
The series looks good to me otherwise, I'd like to give Mattijs a chance to look at it and pick it.
Thank you !
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
Quoted 13 lines · Marek Vasut
On 9/4/26 4:29 AM, Thinh Nguyen wrote:
Hello Thinh,
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2716
Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +2
-0@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) {Nitpick -- you could invert the conditional here and reduce indent:
Quoted 5 lines
if (!gadget_is_superspeed(gadget))
return 0;...
But wouldn't that deviate further from the original Linux change? See:
4bb99b7c82ba ("usb: gadget: storage: add superspeed support")
BR,
Thinh
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
Hello Thinh,
Quoted 17 lines · Thinh Nguyen
Quoted 16 lines · Marek Vasut
On 9/4/26 4:29 AM, Thinh Nguyen wrote:
Hello Thinh,
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2716
Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +2
-0@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) {Nitpick -- you could invert the conditional here and reduce indent:
if (!gadget_is_superspeed(gadget))
return 0;
Quoted 7 lines
Quoted 2 lines
...
But wouldn't that deviate further from the original Linux change? See:
4bb99b7c82ba("usb: gadget: storage: add superspeed support")
I think we are past that point and the U-Boot code did already diverge quite a bit, but if this is pulled from some specific Linux commit and you want to retain the code similarity, then please at least include the aforementioned Linux commit reference in the commit message.
'From Linux 4bb99b7c82ba ("usb: gadget: storage: add superspeed support").' or something along these lines.
Thank you !
Signature · 2 lines
Best regards, Marek Vasut
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
Quoted 26 lines · Marek Vasut
Hello Thinh,
Quoted 23 lines · Thinh Nguyen
Quoted 13 lines · Marek Vasut
On 9/4/26 4:29 AM, Thinh Nguyen wrote:
Hello Thinh,
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2716
Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +2
-0@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) {Nitpick -- you could invert the conditional here and reduce indent:
Quoted 5 lines
if (!gadget_is_superspeed(gadget))
return 0;...
But wouldn't that deviate further from the original Linux change? See:
Quoted 6 lines
Quoted 1 line
4bb99b7c82ba("usb: gadget: storage: add superspeed support")I think we are past that point and the U-Boot code did already diverge quite a bit, but if this is pulled from some specific Linux commit and you want to retain the code similarity, then please at least include the aforementioned Linux commit reference in the commit message.
I've been (over-)zealous with keeping the code similar to the Linux commit.
Sorry if that was a problem.
To me it looks good this way.
Quoted 3 lines
'From Linux
4bb99b7c82ba("usb: gadget: storage: add superspeed support").' or something along these lines.
I can add that to the commit message when applying.
Quoted 6 lines
Thank you !
Signature · 2 lines
Best regards, Marek Vasut
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
Quoted 40 lines · Mattijs Korpershoek
Quoted 26 lines · Marek Vasut
Hello Thinh,
Quoted 23 lines · Thinh Nguyen
Quoted 13 lines · Marek Vasut
On 9/4/26 4:29 AM, Thinh Nguyen wrote:
Hello Thinh,
drivers/usb/gadget/f_mass_storage.c static int fsg_bind(struct usb_configuration *c, struct usb_function *f) · line 2716
Quoted 6 lines
drivers/usb/gadget/f_mass_storage.c +2
-0@@ -2709,6 +2712,27 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)return -ENOMEM ; } } + +if (gadget_is_superspeed (gadget)) {Nitpick -- you could invert the conditional here and reduce indent:
Quoted 5 lines
if (!gadget_is_superspeed(gadget))
return 0;...
But wouldn't that deviate further from the original Linux change? See:
Quoted 6 lines
Quoted 1 line
4bb99b7c82ba("usb: gadget: storage: add superspeed support")I think we are past that point and the U-Boot code did already diverge quite a bit, but if this is pulled from some specific Linux commit and you want to retain the code similarity, then please at least include the aforementioned Linux commit reference in the commit message.
I've been (over-)zealous with keeping the code similar to the Linux commit.
Sorry if that was a problem.
Quoted 7 lines
To me it looks good this way.
Quoted 3 lines
'From Linux
4bb99b7c82ba("usb: gadget: storage: add superspeed support").' or something along these lines.I can add that to the commit message when applying.
Please do and apply, thanks !
Re: [PATCH v3 1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
In reply to Thinh NguyenHi Thinh,
Thank you for the patch.
Quoted 9 lines · Thinh Nguyen
From: Dan Tran <[email protected]>
Add SS bulk endpoint descriptors (1024-byte MPS, bMaxBurst=15) to
storage_common.cto support SuperSpeed connections. Extendfsg_ep_desc()to select them when operating at SuperSpeed, and wire upss_descriptorsinfsg_bind(). Freess_descriptorsinfsg_unbind()to match.Signed-off-by Dan Tran <[email protected]>Signed-off-by Thinh Nguyen <[email protected]>
Quoted 1 line
---
PATCH v3 2/2 usb: gadget: dfu: add SuperSpeed descriptor support
In reply to Thinh NguyenFrom: Dan Tran <[email protected]>
Populate ss_descriptors to support SuperSpeed connections. DFU is control-only so no separate SS descriptor set is needed; reuse the same descriptors across all speeds.
---
Changes in v3:
- Remove the superspeed descriptor assignment from dfu_bind.
Changes in v2:
- Removed internal Reviewed-by tags
drivers/usb/gadget/f_dfu.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/gadget/f_dfu.c +3 -0
@@ -227,6 +227,7 @@ static inline void to_dfu_mode(struct f_dfu *f_dfu) f_dfu->usb_function.strings = dfu_strings; f_dfu->usb_function.hs_descriptors = f_dfu->function; f_dfu->usb_function.descriptors = f_dfu->function; + f_dfu->usb_function.ss_descriptors = f_dfu->function; f_dfu->dfu_state = DFU_STATE_dfuIDLE; }
@@ -235,6 +236,7 @@ static inline void to_runtime_mode(struct f_dfu *f_dfu) f_dfu->usb_function.strings =NULL ; f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; f_dfu->usb_function.descriptors = dfu_runtime_descs; + f_dfu->usb_function.ss_descriptors = dfu_runtime_descs; }static int handle_upload (struct usb_request *req,u16 len)
@@ -826,6 +828,7 @@ static int dfu_bind_config(struct usb_configuration *c) f_dfu->usb_function.name ="dfu" ; f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; f_dfu->usb_function.descriptors = dfu_runtime_descs; + f_dfu->usb_function.ss_descriptors = dfu_runtime_descs; f_dfu->usb_function.bind = dfu_bind; f_dfu->usb_function.unbind = dfu_unbind; f_dfu->usb_function.set_alt = dfu_set_alt;
Signature · 1 line
2.53.0
Re: [PATCH v3 2/2] usb: gadget: dfu: add SuperSpeed descriptor support
Hi Thinh,
Thank you for the patch.
Quoted 8 lines · Thinh Nguyen
From: Dan Tran <[email protected]>
Populate
ss_descriptorsto support SuperSpeed connections. DFU is control-only so no separate SS descriptor set is needed; reuse the same descriptors across all speeds.Signed-off-by Dan Tran <[email protected]>Signed-off-by Thinh Nguyen <[email protected]>
Quoted 40 lines
---
Changes in v3:
- Remove the superspeed descriptor assignment fromdfu_bind.Changes in v2:
- Removed internal Reviewed-by tagsdrivers/usb/gadget/f_dfu.c | 3 +++ 1 file changed, 3 insertions(+)drivers/usb/gadget/f_dfu.c +3
-0@@ -227,6 +227,7 @@ static inline void to_dfu_mode(struct f_dfu *f_dfu) f_dfu->usb_function.strings = dfu_strings; f_dfu->usb_function.hs_descriptors = f_dfu->function; f_dfu->usb_function.descriptors = f_dfu->function; + f_dfu->usb_function.ss_descriptors = f_dfu->function; f_dfu->dfu_state = DFU_STATE_dfuIDLE; }@@ -235,6 +236,7 @@ static inline void to_runtime_mode(struct f_dfu *f_dfu) f_dfu->usb_function.strings =NULL ; f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; f_dfu->usb_function.descriptors = dfu_runtime_descs; + f_dfu->usb_function.ss_descriptors = dfu_runtime_descs; }static int handle_upload (struct usb_request *req,u16 len)@@ -826,6 +828,7 @@ static int dfu_bind_config(struct usb_configuration *c) f_dfu->usb_function.name ="dfu" ; f_dfu->usb_function.hs_descriptors = dfu_runtime_descs; f_dfu->usb_function.descriptors = dfu_runtime_descs; + f_dfu->usb_function.ss_descriptors = dfu_runtime_descs; f_dfu->usb_function.bind = dfu_bind; f_dfu->usb_function.unbind = dfu_unbind; f_dfu->usb_function.set_alt = dfu_set_alt;Signature · 1 line
2.53.0
Hi,
Quoted 9 lines · Thinh Nguyen
This series adds SuperSpeed descriptor support for the
mass_storageand DFU gadget functions so they can operate correctly at SuperSpeed.Dan Tran (2):
usb: gadget:mass_storage: add SuperSpeed descriptor support
usb: gadget: dfu: add SuperSpeed descriptor support[...]
Thanks, Applied to https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/2] usb: gadget: mass_storage: add SuperSpeed descriptor support
https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/bc6f3f4b3882fec3eb21457ccaed993b40743725 [2/2] usb: gadget: dfu: add SuperSpeed descriptor support https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/6e3f574e576585b0250ac387475d59e581bb5d9f
--
Mattijs
Hi Mattijs, Marek,
Quoted 15 lines · Mattijs Korpershoek
Hi,
Quoted 9 lines · Thinh Nguyen
This series adds SuperSpeed descriptor support for the
mass_storageand DFU gadget functions so they can operate correctly at SuperSpeed.Dan Tran (2):
usb: gadget:mass_storage: add SuperSpeed descriptor support
usb: gadget: dfu: add SuperSpeed descriptor support[...]
Thanks, Applied to https://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowAKSmqcU$ (u-boot-dfu-next)
Quoted 7 lines
[1/2] usb: gadget:
mass_storage: add SuperSpeed descriptor supporthttps://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/bc6f3f4b3882fec3eb21457ccaed993b40743725__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowHhP3EuL$ [2/2] usb: gadget: dfu: add SuperSpeed descriptor support https://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/6e3f574e576585b0250ac387475d59e581bb5d9f__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowHPGt8hj$--
Mattijs
Just following up on these patches. They were previously applied to u-boot-dfu-next, but I don't see them there anymore or in mainline.
Do you know what happened to them, or whether they still need to be picked up?
Thanks,
Thinh
Hi Thinh,
Quoted 23 lines · Thinh Nguyen
Hi Mattijs, Marek,
Quoted 20 lines · Mattijs Korpershoek
Hi,
Quoted 9 lines · Thinh Nguyen
This series adds SuperSpeed descriptor support for the
mass_storageand DFU gadget functions so they can operate correctly at SuperSpeed.Dan Tran (2):
usb: gadget:mass_storage: add SuperSpeed descriptor support
usb: gadget: dfu: add SuperSpeed descriptor support[...]
Thanks, Applied to https://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowAKSmqcU$ (u-boot-dfu-next)
[1/2] usb: gadget:
mass_storage: add SuperSpeed descriptor supporthttps://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/bc6f3f4b3882fec3eb21457ccaed993b40743725__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowHhP3EuL$ [2/2] usb: gadget: dfu: add SuperSpeed descriptor support https://urldefense.com/v3/__https://git.u-boot-project.org/u-boot/custodians/u-boot-dfu/-/commit/6e3f574e576585b0250ac387475d59e581bb5d9f__;!!A4F2R9G_pg!eQmEMvzVBEkabPwypmYnbdrp3msonmGKhxGZywPB79oo8spNCka6P9eGAae6yp-Ce742VIzmiq9zTSF-cAgowHPGt8hj$
Quoted 5 lines
Quoted 2 lines
--
MattijsJust following up on these patches. They were previously applied to u-boot-dfu-next, but I don't see them there anymore or in mainline.
You are right, there are not there.
I'm terribly sorry. I completely missed to send a PR to Tom with this included and later on I rebased u-boot-dfu-next and dropped these patches.
Quoted 3 lines
Do you know what happened to them, or whether they still need to be picked up?
I'll apply them to u-boot-dfu and send a PR for main this week.
Again, I'm really sorry about this. This is the first time that it happens to me.
Thank you for your understanding.
Regards
Mattijs
Quoted 3 lines
Thanks,
Thinh