Bug 212045 - dwc2 gadget mode read call blocks
Summary: dwc2 gadget mode read call blocks
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: USB (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Default virtual assignee for Drivers/USB
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-03 23:51 UTC by Tomasz Grobelny
Modified: 2021-03-10 20:38 UTC (History)
2 users (show)

See Also:
Kernel Version: 5.9
Subsystem:
Regression: No
Bisected commit-id:


Attachments
Dmesg (37 bytes, text/plain)
2021-03-04 20:01 UTC, Tomasz Grobelny
Details
Dmesg, hopefully correct this time (97.66 KB, text/plain)
2021-03-04 20:09 UTC, Tomasz Grobelny
Details

Description Tomasz Grobelny 2021-03-03 23:51:23 UTC
When implementing USB gadget on Odroid N2 I write descriptors for two endpoints so I get ep0, ep1 and ep2 files. I open those files and try to read from ep0 and ep2. While ep0 more or less works, for ep2 I get weird behaviour: the select() call returns 1 indicating that there is data to read and then read() call blocks. It happens even if I set the file descriptor to O_NONBLOCK. Here is the kernel log: https://pastebin.pl/view/aaa2d7f0
Comment 1 Artur Petrosyan 2021-03-04 14:42:54 UTC
According to Synopsys's security policy, the link to the kernel log is blocked. Could you please attach the kernel log to this thread?
Comment 2 Tomasz Grobelny 2021-03-04 20:01:02 UTC
Created attachment 295653 [details]
Dmesg
Comment 3 Tomasz Grobelny 2021-03-04 20:09:47 UTC
Created attachment 295655 [details]
Dmesg, hopefully correct this time
Comment 4 Minas Harutyunyan 2021-03-05 09:30:15 UTC
According to dmesg, you use follow EP's: ep0in, ep0out, ep1in and ep1out. Why you refer to not used ep2?
Comment 5 Tomasz Grobelny 2021-03-05 10:37:50 UTC
The files that functionfs exposes are ep0 (for reading, events), ep1 (for writing, direction: to host) and ep2 (for reading, direction: to gadget). Not sure how and why they are named in dmesg. You can find the gadget configuration here: https://github.com/tomasz-grobelny/AACS/blob/master/AAServer/src/descriptors.cpp - line 75 and 84:
                    .bEndpointAddress = 1 | USB_DIR_IN,
                    .bEndpointAddress = 2 | USB_DIR_OUT,

The code that fails/hangs is readWraper function here:
https://github.com/tomasz-grobelny/AACS/blob/master/AAServer/src/AaCommunicator.cpp:493

select succeeds for ep2 and the read blocks. Exactly same function works ok for ep0 for all 3 hosts that I tested on and the code works fully ok for 2 out of 3 hosts that I tested on. I also know that in principle the 3rd host also should work because it works with other devices.

Maybe lack of ep2 in the logs is something interesting?
Comment 6 Minas Harutyunyan 2021-03-10 09:59:45 UTC
I don't see any issue on dwc2 side based on driver debug logs - transfers are normally initiating and completing. Maybe something wrong in your function driver.
Comment 7 Tomasz Grobelny 2021-03-10 10:13:46 UTC
What do you mean by "function driver"? The userspace code that actually opens the ep0/ep1/ep2 files exposed by functionfs? It works correctly for other hosts.

I don't have any more data to argue it is dwc2, but still seems like an issue in kernel USB subsystem.

Another question that might help debugging it: is it the host that should open the ep2 endpoint? In other words: is it the host that is directly responsible for lack of any mention of ep2 in dmesg output after the device was reinitialized?
Comment 8 Minas Harutyunyan 2021-03-10 12:20:31 UTC
dwc2 in your case works as device. "It works correctly for other hosts." - do you mean "other devices"?
Your userspace application work on host or device side?
Comment 9 Tomasz Grobelny 2021-03-10 13:12:16 UTC
No, I mean other hosts. I connect my Odroid N2 working as device (and this is were my userspace code comes into play) to different hosts and for some of them it works perfectly (Linux host running openauto, headunit in my car), for some it fails as described above (my brother's car, different manufacturer of the headunit). The car's headunit itself works fine as connecting a phone using the same android auto protocol works ok.

I didn't (yet) have a chance to test on other hardware on device side.

I am wondering whether this lack of ep2 communication is due to the host doing something or not doing something it should do.
Comment 10 Minas Harutyunyan 2021-03-10 13:42:52 UTC
I can't comment anything on other host sides, sorry.
Comment 11 Tomasz Grobelny 2021-03-10 20:38:31 UTC
Ok, clear. But anyway, looking at kernel side only: the ep2 was exposed by functionfs, it was successfully opened by my code, select returned that there is data available for reading and then read blocked. Something is not quite right here, unless I am missing something.

Note You need to log in before you can comment on or make changes to this bug.