usb: gadget: f_acm: make bInterfaceProtocol configurable
PATCH 1/1 usb: gadget: f_acm: make bInterfaceProtocol configurable
The bInterfaceProtocol is hardcoded to USB_CDC_ACM_PROTO_AT_V25TER. This will lead to problems with ModemManger which will gladly try to probe that port as a modem if the gadget also has a network function. ModemManager will try to send AT commands to the ACM port. Make the bInterfaceProtocol configurable.
This will also set bFunctionProtocol to the same value, see commit 5c8db070b448 ("USB: Change acm_iad_descriptor bFunctionProtocol to USB_CDC_ACM_PROTO_AT_V25TER") for more details.
---
See the following link for the filter logic:
https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/blob/main/src/mm-filter.c?ref_type=heads#L303
--- .../ABI/testing/configfs-usb-gadget-acm | 7 +++ drivers/usb/gadget/function/f_acm.c | 50 ++++++++++++++++++- drivers/usb/gadget/function/u_serial.h | 4 ++ 3 files changed, 59 insertions(+), 2 deletions(-)
Documentation/ABI/testing/configfs-usb-gadget-acm +7 -0
@@ -6,3 +6,10 @@ Description: This item contains just one readonly attribute: port_num. It contains the port number of the /dev/ttyGS<n> device associated with acm function's instance "name". + +What: /config/usb-gadget/gadget/functions/acm.name/protocol +Date: Aug 2024 +KernelVersion: 6.13 +Description: + Reported bInterfaceProtocol for the ACM device. For legacy + reasons, this defaults to 1 (USB_CDC_ACM_PROTO_AT_V25TER).
drivers/usb/gadget/function/f_acm.c +48 -2
106 lines not on this page · raw message
drivers/usb/gadget/function/u_serial.h +4 -0
@@ -17,6 +17,10 @@struct f_serial_opts {struct usb_function_instance func_inst;u8 port_num; +u8 protocol; + +struct mutex lock; +int refcnt; };/*
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerdrivers/usb/gadget/function/u_serial.h line 23
Quoted 7 lines · Michael Walle
struct
f_serial_opts{drivers/usb/gadget/function/u_serial.h +4
-0struct usb_function_instance func_inst;u8 port_num; +u8 protocol; + +struct mutex lock; +int refcnt;
Attempting to "roll your own" reference count is almost never a good idea. If you really need one, please use the proper in-kernel apis for this. But you need to justify it as well, I didn't see why this was needed at all.
thanks,
greg k-h
Hi Greg,
Quoted 13 lines · Greg Kroah-Hartman
drivers/usb/gadget/function/u_serial.h line 23
Quoted 7 lines · Michael Walle
struct
f_serial_opts{drivers/usb/gadget/function/u_serial.h +4
-0struct usb_function_instance func_inst;u8 port_num; +u8 protocol; + +struct mutex lock; +int refcnt;Attempting to "roll your own" reference count is almost never a good idea. If you really need one, please use the proper in-kernel apis for this. But you need to justify it as well, I didn't see why this was needed at all.
Honestly, I couldn't grok all that usb gadget magic, so I've looked at similar gadgets and took that from there:
grep refcnt drivers/usb/gadget/function/ -r
They are all doing the same, so maybe that code is old or didn't use the proper APIs back then.
The refcnt will prevent changing the options (the protocol here) while a gadget is still in use/bound.
-michael
Greg Kroah-Hartman
maintainerQuoted 17 lines · Michael Walle
Hi Greg,
Quoted 13 lines · Greg Kroah-Hartman
drivers/usb/gadget/function/u_serial.h line 23
Quoted 7 lines · Michael Walle
struct
f_serial_opts{drivers/usb/gadget/function/u_serial.h +4
-0struct usb_function_instance func_inst;u8 port_num; +u8 protocol; + +struct mutex lock; +int refcnt;Attempting to "roll your own" reference count is almost never a good idea. If you really need one, please use the proper in-kernel apis for this. But you need to justify it as well, I didn't see why this was needed at all.
Quoted 6 lines
Honestly, I couldn't grok all that usb gadget magic, so I've looked at similar gadgets and took that from there:
grep refcntdrivers/usb/gadget/function/-rThey are all doing the same, so maybe that code is old or didn't use the proper APIs back then.
It's old code, please do things properly.
thanks,
greg k-h
Hi Greg,
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Michael Walle
Hi Greg,
Quoted 13 lines · Greg Kroah-Hartman
drivers/usb/gadget/function/u_serial.h line 23
Quoted 7 lines · Michael Walle
struct
f_serial_opts{drivers/usb/gadget/function/u_serial.h +4
-0struct usb_function_instance func_inst;u8 port_num; +u8 protocol; + +struct mutex lock; +int refcnt;Attempting to "roll your own" reference count is almost never a good idea. If you really need one, please use the proper in-kernel apis for this. But you need to justify it as well, I didn't see why this was needed at all.
Quoted 8 lines
Quoted 6 lines
Honestly, I couldn't grok all that usb gadget magic, so I've looked at similar gadgets and took that from there:
grep refcntdrivers/usb/gadget/function/-rThey are all doing the same, so maybe that code is old or didn't use the proper APIs back then.
It's old code, please do things properly.
Sorry, I have to come back to this. What do you have in mind?
The mutex is needed in any case to protect the members of f_serial_ops from concurrent access between the .bind() and the configfs write.
Which leaves us with refcnt. I don't think refcount_t is suitable here. For example, refcount_inc() will warn if you increment from 0; which makes sense for resource reference counting. But doesn't make sense in this case; there is no resource handling or freeing if the refcnt is 0. It just prohibits the write to the configfs attribute if refcnt != 0, that is, there is at least one instance of the gadget function.
Maybe I should just rename "refcnt" to "users" and add a comment to the mutex what it will protect.
What do you think?
-michael