-
Notifications
You must be signed in to change notification settings - Fork 8
usb: fix TT bugs and class-specific functional descriptor discovery #38
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
Open
adamgreloch
wants to merge
4
commits into
master
Choose a base branch
from
adamgreloch/tt-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
65075cb
usb/hub: fix deadlock on successful TT enumeration
adamgreloch c511e39
usb/hub: make TT workaround opt-in
adamgreloch 3896e32
usb/dev: handle class-specific functional descriptors
adamgreloch ee3e540
usb/dev: ignore failure to bind the driver
adamgreloch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,10 @@ | |
| #undef USB_LOG_TAG | ||
| #define USB_LOG_TAG "usbhub" | ||
|
|
||
| #ifndef USB_HUB_TT_WORKAROUND | ||
| #define USB_HUB_TT_WORKAROUND 0 | ||
| #endif | ||
|
|
||
|
|
||
| typedef struct _hub_event { | ||
| struct _hub_event *next, *prev; | ||
|
|
@@ -59,6 +63,9 @@ struct { | |
| } hub_common; | ||
|
|
||
|
|
||
| static void hub_portstatus(usb_dev_t *hub, int port); | ||
|
|
||
|
|
||
| static int hub_getDesc(usb_dev_t *hub, char *buf, size_t len) | ||
| { | ||
| usb_setup_packet_t setup = (usb_setup_packet_t) { | ||
|
|
@@ -177,13 +184,6 @@ static int hub_interruptInit(usb_dev_t *hub) | |
| } | ||
|
|
||
|
|
||
| static int hub_isTT(usb_dev_t *dev) | ||
| { | ||
| /* TODO support MTTs */ | ||
| return dev->desc.bDeviceClass == USB_CLASS_HUB && dev->desc.bDeviceProtocol == USB_HUB_PROTO_SINGLE_TT; | ||
| } | ||
|
|
||
|
|
||
| static int hub_requestStatus(usb_dev_t *hub) | ||
| { | ||
| return usb_transferSubmit(hub->statusTransfer, hub->irqPipe, NULL); | ||
|
|
@@ -262,6 +262,14 @@ static int hub_portDebounce(usb_dev_t *hub, int port) | |
| } | ||
|
|
||
|
|
||
| #if USB_HUB_TT_WORKAROUND | ||
| static int hub_isTT(usb_dev_t *dev) | ||
| { | ||
| /* TODO support MTTs */ | ||
| return dev->desc.bDeviceClass == USB_CLASS_HUB && dev->desc.bDeviceProtocol == USB_HUB_PROTO_SINGLE_TT; | ||
| } | ||
|
|
||
|
|
||
| static void hub_ttAdd(usb_dev_t *hub) | ||
| { | ||
| mutexLock(hub_common.lock); | ||
|
|
@@ -278,12 +286,45 @@ static void hub_ttRemove(usb_dev_t *hub) | |
| } | ||
|
|
||
|
|
||
| static void _hub_ttStatus(void) | ||
| { | ||
| usb_dev_t *hub; | ||
| int i; | ||
|
|
||
| hub = hub_common.tts; | ||
| if (hub == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| do { | ||
| for (i = 0; i < hub->nports; i++) { | ||
| mutexUnlock(hub_common.lock); | ||
| /* | ||
| * hub_portstatus may lead to usb_devEnumerate call which may call hub_conf that | ||
| * tries to obtain this lock via hub_ttAdd: | ||
| * | ||
| * hub_portstatus -> hub_connectstatus -> hub_devConnected -> usb_devEnumerate -> hub_conf -> hub_ttAdd | ||
| * | ||
| * FIXME? It may be better to separate the enumeration | ||
| * from the connect status polling logic, but as this polling loop is a | ||
| * part of L2 TT workaround, the problem may be easier to solve itself in the root | ||
| */ | ||
| hub_portstatus(hub, i + 1); | ||
| mutexLock(hub_common.lock); | ||
| } | ||
| } while ((hub = hub->next) != hub_common.tts); | ||
| } | ||
| #endif | ||
|
|
||
|
|
||
| static void hub_devDisconnect(usb_dev_t *dev, bool silent) | ||
| { | ||
| usb_devDisconnected(dev, silent); | ||
| #if USB_HUB_TT_WORKAROUND | ||
| if (hub_isTT(dev)) { | ||
| hub_ttRemove(dev); | ||
| } | ||
| #endif | ||
| usb_devDisconnected(dev, silent); | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -399,24 +440,6 @@ static uint32_t hub_getStatus(usb_dev_t *hub) | |
| } | ||
|
|
||
|
|
||
| static void hub_ttStatus(void) | ||
| { | ||
| usb_dev_t *hub; | ||
| int i; | ||
|
|
||
| hub = hub_common.tts; | ||
| if (hub == NULL) { | ||
| return; | ||
| } | ||
|
|
||
| do { | ||
| for (i = 0; i < hub->nports; i++) { | ||
| hub_portstatus(hub, i + 1); | ||
| } | ||
| } while ((hub = hub->next) != hub_common.tts); | ||
| } | ||
|
|
||
|
|
||
| static void hub_thread(void *args) | ||
| { | ||
| hub_event_t *ev; | ||
|
|
@@ -426,8 +449,12 @@ static void hub_thread(void *args) | |
| for (;;) { | ||
| mutexLock(hub_common.lock); | ||
| while (hub_common.events == NULL) { | ||
| #if USB_HUB_TT_WORKAROUND | ||
| condWait(hub_common.cond, hub_common.lock, HUB_TT_POLL_DELAY_MS); | ||
| hub_ttStatus(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another approach that avoids the deadlock is to iterate over all hubs and inject an artificial event for each, rather than invoking |
||
| _hub_ttStatus(); | ||
| #else | ||
| condWait(hub_common.cond, hub_common.lock, 0); | ||
| #endif | ||
| } | ||
| ev = hub_common.events; | ||
| LIST_REMOVE(&hub_common.events, ev); | ||
|
|
@@ -495,14 +522,16 @@ int hub_conf(usb_dev_t *hub) | |
| if (hub_interruptInit(hub) != 0) | ||
| return -EINVAL; | ||
|
|
||
| #if USB_HUB_TT_WORKAROUND | ||
| if (hub_isTT(hub)) { | ||
| // FIXME Interrupt pipe notifications from tier 2 TTs never come, which is | ||
| // either a quirk in currently tested hw or an issue in the hcd driver | ||
|
|
||
| // In addition to request an interrupt request, actively poll the status as well | ||
| // for as a workaround | ||
| /* | ||
| * FIXME Interrupt pipe notifications from tier 2 TTs never come on ia32, | ||
| * which is either a quirk in currently tested hw or an issue in the hcd driver. | ||
| * As a workaround, try to receive interrupt requests AND actively poll the status. | ||
| */ | ||
adamgreloch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| hub_ttAdd(hub); | ||
| } | ||
| #endif | ||
|
|
||
| return hub_requestStatus(hub); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.