Skip to content

Conversation

@adamgreloch
Copy link
Member

Description

Various bug fixes that came up when probing the CYW4373E dongle composed of a TT hub and 3 internal devices, some of which contained class-specific functional descriptors that were incorrectly parsed.

Motivation and Context

These changes make it possible to run the CYW4373E driver (phoenix-rtos/phoenix-rtos-devices#596).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: nilee

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist
Copy link

Summary of Changes

Hello @adamgreloch, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical bugs related to USB Transaction Translators (TT) and improves the discovery of class-specific functional descriptors. These changes are essential for the proper operation of USB devices, specifically enabling the CYW4373E dongle by ensuring correct handling of hub communications and descriptor parsing, which were previously problematic.

Highlights

  • USB Transaction Translator (TT) Bug Fixes: Implemented workarounds for Transaction Translator (TT) related issues, particularly for tier 2 TTs where interrupt pipe notifications might not be reliably received. This includes conditional active polling for TT status.
  • Class-Specific Functional Descriptor Discovery: Enhanced the USB configuration parsing to correctly discover and store class-specific functional descriptors, which were previously ignored. A new generic descriptor type has been introduced for this purpose.
  • Error Logging Refinement: Adjusted error logging messages in usb/dev.c by removing redundant newline characters for cleaner output.
  • Improved Device Enumeration Robustness: Modified usb_devEnumerate to no longer return an error if driver binding fails, allowing the device to be marked as orphaned instead of halting the enumeration process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses bugs related to TT hubs and class-specific functional descriptor discovery in the USB subsystem. The changes include adding a generic descriptor structure, modifying the configuration descriptor parsing logic, and adding a workaround for TT hubs. The review focuses on correctness and potential issues arising from the introduced changes.

@github-actions
Copy link

github-actions bot commented Oct 21, 2025

Unit Test Results

9 462 tests  +1 504   8 873 ✅ +1 439   50m 56s ⏱️ + 10m 23s
  561 suites +   91     589 💤 +   65 
    1 files   ±    0       0 ❌ ±    0 

Results for commit ee3e540. ± Comparison against base commit 91853a6.

This pull request removes 207 and adds 1711 tests. Note that renamed tests count towards both.
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_abs.fabs_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.exp_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.frexp_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.ldexp_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.log10_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.log2_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_exp.log_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_frac.ceil_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_frac.floor_special_cond
phoenix-rtos-tests/libc/math ‑ armv7a7-imx6ull-evk:phoenix-rtos-tests/libc/math.math_frac.fmod_special_cond
…
flash ‑ aarch64a53-zynqmp-qemu:flash
flash ‑ armv7r5f-zynqmp-qemu:flash
phoenix-rtos-tests/cpp/hello-cpp ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/cpp/hello-cpp
phoenix-rtos-tests/initfini/main ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/initfini/main
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_in
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_in_big
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_inout
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_inout_big
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_out
phoenix-rtos-tests/ioctl/unit ‑ aarch64a53-zynqmp-qemu:phoenix-rtos-tests/ioctl/unit.ioctl.data_out_big
…

♻️ This comment has been updated with latest results.

Copy link

@julianuziemblo julianuziemblo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on armv7m7-imxrt117x-evk, DTR, works fine

one small nit/question, otherwise LGTM

usb/hub.c Outdated
condWait(hub_common.cond, hub_common.lock, HUB_TT_POLL_DELAY_MS);

/*
* hub_ttStatus may lead to usb_devEnumerate call which may call hub_conf that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show the problematic path that leads to the mutex lock? I can see another path leading to hub_ttRemove().
It appears that this lock protects both hub_common.events and hub_common.tts lists. Would introduction of separate locks for these lists fix this issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hub_ttStatus -> hub_portstatus -> hub_connectstatus -> hub_devConnected -> usb_devEnumerate -> hub_conf -> hub_ttAdd

The problem comes from the fact that hub_portstatus can be called from hub_ttStatus or from normal device discovery below, where it is assumed not to have the lock.

Actually, now I see that this workaround is still flawed (but to the other side), as hub_ttStatus now accesses hub_common.tts unsafely, so the mutex lock/unlock should be moved to hub_ttStatus for accessing the item from hub_common.tts.

A separate lock could help here a bit, but there is still a recursion with mutex over the same resource when calling hub_ttStatus. We would need a reentrant lock. Or deeply rework this architecture, but since this is just a workaround for x86 interrupt pipe problems, it may be easier to solve the root cause than that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the unlock/lock inside the hub_ttStatus and extended the comment

When tested on imxrt1170-evkb with Laird/Sterling LWB5+ plugged in
(internal TT hub + two internal devices), the workaround for the lack of
interrupt pipe notifications was not neeeded. It seems that ia32 is the
only platform suffering from this issue.

JIRA: RTOS-1121
Returning failure on bind causes the discovery of subsequent devices on
a given hub to fail.  This is still yet to be fixed with proper orphans
management.

JIRA: RTOS-1121
@ziemleszcz
Copy link
Contributor

Please combine two first commits.

* part of L2 TT workaround, the problem may be easier to solve itself in the root
*/
mutexUnlock(hub_common.lock);
hub_ttStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The 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_portstatus().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants