-
Notifications
You must be signed in to change notification settings - Fork 7.5k
USB: Implement USB Ethernet Device gadget (ECM protocol) #4147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@finikorg : Thanks for the patch! I'm not sure how much of it I'll be able to review though, I mostly keep an eye on USB things because I'd like to have an USB CDC driver for ARM devices to be implemented, but I don't have enough experience doing that myself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@finikorg it all looks like WIP,
can you please open an issue and describe your work, like: - add ethernet emulation device, add CDC-ECM driver, add RNDIS driver. I guess ethernet emulator can also be used with CDC-EEM driver and it would be good to synchronize the work on it with @loicpoulain
|
||
static struct eth_emu_context eth_emu_ctx; | ||
|
||
static int eth_emu_init(struct device *dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eth_emu does not need to depend on usb, I think it would be better to separate it from this PR and move to drivers/ethernet/, @jukkar your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move it to some other place if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jukkar @tbursztyka @rveerama1 could you check this virtual ethernet device? Commit: 745a7f0111b741bc735a00e90c86bae581b235fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also #4461 (comment)
@finikorg can you please rebase? |
@nashif Actually I am trying to rebase it now and reuse composite device framework. |
@nashif @jfischer-phytec-iot rebased to work with new interface |
@laperie Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at it quickly, will do more closely later.
subsys/usb/usb_descriptor.c
Outdated
@@ -59,6 +59,23 @@ struct dev_common_descriptor { | |||
struct usb_ep_descriptor if1_out_ep; | |||
} __packed cdc_acm_cfg; | |||
#endif | |||
#ifdef CONFIG_USB_DEVICE_NETWORK_ECM | |||
struct usb_cdc_ecm_config { | |||
struct usb_association_descriptor iad; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
association descriptor is necessary for composite device only, see above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfischer-phytec-iot fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is not increasing the debug level, it is adding more information, so please fix the commit message
referring to
|
then we have a few commits where you
Please squash them, when a source file is introduced, it had to be buildable, no need to split the commits this way. I am referring to
|
menu "USB Device Networking support" | ||
depends on USB_DEVICE_STACK | ||
|
||
config USB_DEVICE_NETWORK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the idea behind this kconfig option? it has no description and is automatically selected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nashif idea here is that we implement some other functions (RNDIS, etc). Common code is built whenever network function is enabled. I have working solution with several functions where it does make sense
You just added netusb.c, so why are you refactoring it in a followup commit? Why not squash this
into where the file was introduced? When reviewing this commit by commit, it just makes reviews very difficult, please submit less commits that are self-contained rather than bit and pieces in many more commits without a good reason. |
@nashif for some reason I cannot reply directly to comments due to this **** github interface, so I reply in my comment here. I squashed most of the commits together. I left emulation device commit separate since it may be reworked to be included to networking codebase. |
I squashed even more, only Ethernet emulation device left separate. |
Add extra debug information to USB commands. Signed-off-by: Andrei Emeltchenko <[email protected]>
There is no particular reason this spot in usb_dw_tx() cannot be reached by racing threads on the same endpoint, though existing API usage in the tree is all unithreaded. The FIFO state read at the top of the function must still be true at the bottom or else the packet byte count will be corrupt. Also, as described in an existing comment, the databook has some scary-sounding warnings about access to the registers during FIFO operations, even if they "should" be on separate endpoints and unrelated. Signed-off-by: Andy Ross <[email protected]>
…oint." This reverts commit 1da0a9e. The workaround caused a severe performance penalty, and only worked for USB packets of 4-15 bytes in length (16+ byte packets weren't subject to the hardware bug). Single-byte packets (very common for cdc_acm serial port transfers) would still be duplicated sometimes. The upcoming DMA implementation does not share the performance penalty, and also is not subject to the bug for those sizes of packets (though it DOES still have a problem with single-byte packets!). Signed-off-by: Andy Ross <[email protected]>
The designware hardware in dedicated FIFO mode (which is all we support right now for lack of shared-FIFO hardware) has one hardware FIFO per IN (i.e. transmit) endpoint. But it doesn't assign them on its own, it's the drivers responsibility to populate the TxFNum field of the DIEPCTL registers with integer indices corresponding to the desired FIFO. We weren't doing that, which meant that all IN endpoints were sharing the same FIFO zero which is supposed to be dedicated to EP0 control transfers. The net effect is that sometimes outbound transfers would be corrupted, showing data from the wrong endpoint. More often that not this would leak from control transfers over to the higher-bandwidth bulk endpoints of the application, but occasionally you'd see a control transfer itself get borked and the USB device would glitch. Get this right and set the FIFOs properly. Signed-off-by: Andy Ross <[email protected]>
The Designware FIFO is filled in units of 32 bit words, but the buffer we are passed is not guaranteed to be a multiple of 4 bytes long, nor aligned on a 4-byte boundary. So in theory we are reading 0-3 bytes of unused garbage from the end of the array. That's currently benign on supported platforms with this hardware, which all support misaligned reads. But not all do. And the incoming arrival of memory protection opens the possibility that those extra bytes would cross a protection boundary and cause a crash or security bug. Do this right. (Note that this is fixed to little endian byte order. The Designware databook is frustratingly silent on the endianness it expects, but existing hardware I can see is definitely LE and I see a few spots in the Linux dwc2 driver that likewise assume LE). Signed-off-by: Andy Ross <[email protected]>
The enable and clear NAK bit can be legally written together, do it in just one write. Signed-off-by: Andy Ross <[email protected]>
Add USB device configuration for CDC ECM Signed-off-by: Andrei Emeltchenko <[email protected]>
Ethernet emulation device allows to use networking interface for interaction with USB endpoints. Signed-off-by: Andrei Emeltchenko <[email protected]>
Add composite device skeleton with ECM function implemented. Signed-off-by: Andrei Emeltchenko <[email protected]>
Add netusb and composite netusb build check configurations. Signed-off-by: Andrei Emeltchenko <[email protected]>
Signed-off-by: Andrei Emeltchenko <[email protected]>
rebased against the latest upstream |
Use documentation defined values for virtual devices MAC addresses in Zephyr and Host OS. Signed-off-by: Andrei Emeltchenko <[email protected]>
The situation when FIFO is not empty is not a bug and it is spamming console when only bugs are enabled. Signed-off-by: Andrei Emeltchenko <[email protected]>
Adding sleep before TX FIFO flash fixes splitting networking packets sent over USB endpoints making ECM broken since there is no flow control other then frame sizes. Signed-off-by: Andrei Emeltchenko <[email protected]>
@finikorg Andrei, can you please move dw driver relevant commits in a separate PR. I fear that dw driver fixes here will be overlooked and someone begins to fix dw driver, thx |
dw should be fine here if we merge this...
recheck |
|
||
net_hexdump_frags("<", pkt); | ||
|
||
if (!pkt->frags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If pkt->frags
is NULL, the net_pkt_ll()
call below will crash: it calls net_pkt_ip_data()
, which dereferences pkt->frags
. I could fix this, but I don't know the intent of this code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in PR #4641
@finikorg If using a device with this driver enabled on Windows, what kind of windows driver can be used to support the device? |
I could not make it working in Windows, it is better to use MS RNDIS. |
First revision of CDC ECM gadget device.
TODO: Re-use composite device headers and implement common register_function() methods