From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Joakim Tjernlund <Joakim.Tjernlund@infinera.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"balbi@kernel.org" <balbi@kernel.org>
Subject: Re: dwc3 gadget and USB3
Date: Tue, 14 Mar 2023 00:49:07 +0000 [thread overview]
Message-ID: <20230314004902.fpkbhegd7j6znjx7@synopsys.com> (raw)
In-Reply-To: <3c0fc6880ee13c98577225b05aaf7ac9edf3adfe.camel@infinera.com>
On Sat, Mar 11, 2023, Joakim Tjernlund wrote:
> On Fri, 2023-03-10 at 22:58 +0000, Thinh Nguyen wrote:
> > On Fri, Mar 10, 2023, Joakim Tjernlund wrote:
> > > On Thu, 2023-03-09 at 21:09 +0000, Thinh Nguyen wrote:
> > > > On Thu, Mar 09, 2023, Joakim Tjernlund wrote:
> > > > > On Thu, 2023-03-09 at 19:56 +0000, Thinh Nguyen wrote:
> > > > > > On Thu, Mar 09, 2023, Joakim Tjernlund wrote:
> > > > > > > On Thu, 2023-03-09 at 17:32 +0100, Joakim Tjernlund wrote:
> > > > > > > > On Wed, 2023-03-08 at 22:26 +0100, Joakim Tjernlund wrote:
> > > > > > > > > On Wed, 2023-03-08 at 19:58 +0100, gregkh@linuxfoundation.org wrote:
> > > > > > > > > > On Wed, Mar 08, 2023 at 06:12:51PM +0000, Joakim Tjernlund wrote:
> > > > > > > > > > > On Wed, 2023-03-08 at 18:25 +0100, Greg KH wrote:
> > > > > > > > > > > > On Wed, Mar 08, 2023 at 05:10:17PM +0000, Joakim Tjernlund wrote:
> > > > > > > > > > > >
> >
> SNIP ...
>
> > >
> > >
> > > While I remember, I tried to create both a NCM and a ttyACM on top of my dwc3 gadget
> > > but then I got som bind error when activating the UDC. Is that expected ?
> > > I figured both could live on the same device and would just mux the two protocols.
> > >
> >
> > I'm not clear what you meant here. The gadget driver and the UDC driver
> > should be separated and abstracted from each other.
> >
> > Also, please note that all this talking points are based on the
> > assumption that the issue is due to the host putting the device in
> > suspend base on your experiment. We didn't review the logs.
> >
> > IMO, the best option should be to prevent suspend from the host side as
> > it looks like your device may operate in usb3 speed also?
> >
> > BR,
> > Thinh
>
> This script best explain I think:
> #! /bin/sh
>
> stop() {
> g="/sys/kernel/config/usb_gadget/g1"
> if [ -e "${g}"/UDC ]; then
> echo "" > "${g}"/UDC
> rm -f "${g}"/os_desc/c.1
> rm -f "${g}"/configs/c.1/ncm.usb0
> rm -f "${g}"/configs/c.1/acm.GS0
> [ -d "${g}"/configs/c.1/strings/0x409 ] && rmdir "${g}"/configs/c.1/strings/0x409
> [ -d "${g}"/functions/acm.GS0 ] && rmdir "${g}"/functions/acm.GS0
> [ -d "${g}"/functions/ncm.usb0 ] && rmdir "${g}"/functions/ncm.usb0
> [ -d "${g}"/c.1/strings ] && rmdir "${g}"/c.1/strings
> [ -d "${g}"/c.1/strings/0x409 ] && rmdir "${g}"/c.1/strings/0x409
> [ -d "${g}"/configs/c.1 ] && rmdir "${g}"/configs/c.1
> [ -d "${g}" ] && rmdir "${g}"
> fi
> }
>
> start() {
> mkdir -p /sys/kernel/config/usb_gadget/g1
> cd /sys/kernel/config/usb_gadget/g1
>
> ###############################
> # Populate Device-Level Stuff #
> ###############################
>
> #Setting device class/subclass/protocol to these values
> # alerts the OS that this is a composite device with
> # IADs in it's firmware.
> # ref: https://urldefense.com/v3/__https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-interface-association-descriptor__;!!A4F2R9G_pg!f2DmukBCz-n2dXRTDTd22YjHdXgKXWZwCLtuwoB4SdjW-U7s2s9Cyez4-JjmHJNzhetxdX06a6iohV_1yj7bpq2Ha28LvwALSw$
> echo "0xEF" > bDeviceClass
> echo "0x02" > bDeviceSubClass
> echo "0x01" > bDeviceProtocol
>
> echo "0x15A2" > idVendor
> echo "0x0001" > idProduct
>
> #mkdir strings/0x409
> #echo "1234567" > strings/0x409/serialnumber
> #echo "Infinera" > strings/0x409/manufacturer
> #echo "NDU" > strings/0x409/product
>
> #enable use of os_desc's (important for RNDIS & NCM enablement on Windows):
> echo 1 > os_desc/use
> echo 0xbc > os_desc/b_vendor_code #or 0xcd ?
> echo MSFT100 > os_desc/qw_sign
>
> #################################
> # Populate Individual Functions #
> #################################
>
> #The order functions are populated here will be reflected in the
> # order of descriptors written.
>
> #########
> # RNDIS #
> #########
> #Note! If RNDIS is enabled, it *has* to be the first function! Otherwise, Windows 10 will report error 10 (failed to start device).
> # (It's unclear why this is the case..)
> # https://urldefense.com/v3/__https://docs.microsoft.com/en-us/answers/questions/474108/does-rndis-need-to-be-listed-as-the-first-function.html__;!!A4F2R9G_pg!f2DmukBCz-n2dXRTDTd22YjHdXgKXWZwCLtuwoB4SdjW-U7s2s9Cyez4-JjmHJNzhetxdX06a6iohV_1yj7bpq2Ha28URWCTNQ$
> # https://urldefense.com/v3/__https://stackoverflow.com/questions/68365739/windows-rndis-compatible-device-does-rndis-need-to-be-listed-as-the-first-funct__;!!A4F2R9G_pg!f2DmukBCz-n2dXRTDTd22YjHdXgKXWZwCLtuwoB4SdjW-U7s2s9Cyez4-JjmHJNzhetxdX06a6iohV_1yj7bpq2Ha2-HtzzXog$
> if [ 0 = 1 ]
> then
> mkdir functions/rndis.usb0
> mkdir -p functions/rndis.usb0/os_desc/interface.rndis
>
> # Set compatible / sub-compatible id's so that Windows can match this
> # function to RNDIS6 driver more easily.
> echo RNDIS > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
> echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
>
> mkdir -p configs/c.1
> mkdir -p configs/c.1/strings/0x409
> echo "0xC0" > configs/c.1/bmAttributes # Self powered
> echo "conf1" > configs/c.1/strings/0x409/configuration
> ln -s functions/rndis.usb0 configs/c.1
> if [ ! -L os_desc/c.1 ]
> then
> ln -s configs/c.1 os_desc
> fi
> fi
>
> #########
> # NCM #
> #########
> #Usually I test with *either* RNDIS or NCM enabled, but not both, hence the if(0) here..
> if [ 1 = 1 ]
> then
> mkdir functions/ncm.usb0
> mkdir -p functions/ncm.usb0/os_desc/interface.ncm
> # Set compatible id so that Windows 10 can match this function to
> # NCM driver more easily.
> echo WINNCM > functions/ncm.usb0/os_desc/interface.ncm/compatible_id
>
> mkdir -p configs/c.1
> mkdir -p configs/c.1/strings/0x409
> echo "0xC0" > configs/c.1/bmAttributes # Self powered
> echo "conf1" > configs/c.1/strings/0x409/configuration
> ln -s functions/ncm.usb0 configs/c.1
> if [ ! -L os_desc/c.1 ]
> then
> ln -s configs/c.1 os_desc
> fi
> fi
>
> #########
> # ACM #
> #########
> if [ 1 = 1 ]
> then
> mkdir -p functions/acm.GS0
>
> mkdir -p configs/c.1
> mkdir -p configs/c.1/strings/0x409
> echo "0xC0" > configs/c.1/bmAttributes # Self powered
> ln -fs functions/acm.GS0 configs/c.1
> if [ ! -L os_desc/c.1 ]
> then
> ln -s configs/c.1 os_desc
> fi
> fi
>
> #Activate/bind USB gadget
> echo 2f00000.usb > UDC
> }
> command=$@
>
> case ${command} in
> start)
> echo "Starting usb-lc"
> start
> #ifconfig lc 169.254.100.101 netmask 255.255.255.252 # for debug
> ;;
> stop)
> echo "Stopping usb-lc"
> stop
> ;;
> restart)
> stop
> start
> ;;
>
> *)
> echo "Create USB Gadget device dual NCM and rndis V0.1.1 for MAC, Linux and Windows"
> exit 1
> ;;
> esac
>
>
> This gives me an error:
>
> ./config_gadget.sh start
> Starting usb-lc
> sh: write error: Device or resource busy
>
> the line causing that is:
> echo 2f00000.usb > UDC
>
> Just create either NCM or ACM works, but not both
Not sure. You may need to trace through the code path and see where it
fails.
BR,
Thinh
next prev parent reply other threads:[~2023-03-14 0:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 17:10 dwc3 gadget and USB3 Joakim Tjernlund
2023-03-08 17:25 ` Greg KH
2023-03-08 18:12 ` Joakim Tjernlund
2023-03-08 18:58 ` gregkh
2023-03-08 21:26 ` Joakim Tjernlund
2023-03-09 16:32 ` Joakim Tjernlund
2023-03-09 16:54 ` Joakim Tjernlund
2023-03-09 19:56 ` Thinh Nguyen
2023-03-09 20:50 ` Joakim Tjernlund
2023-03-09 21:09 ` Thinh Nguyen
2023-03-10 9:32 ` Joakim Tjernlund
2023-03-10 22:58 ` Thinh Nguyen
2023-03-11 17:17 ` Joakim Tjernlund
2023-03-14 0:49 ` Thinh Nguyen [this message]
2023-03-13 10:42 ` Joakim Tjernlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230314004902.fpkbhegd7j6znjx7@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=Joakim.Tjernlund@infinera.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox