Skip to content

Backport patches for Raspberry Pi dwc2 driver#4231

Merged
sairon merged 1 commit into
devfrom
backport-rpi-dwc2-fixes
Aug 14, 2025
Merged

Backport patches for Raspberry Pi dwc2 driver#4231
sairon merged 1 commit into
devfrom
backport-rpi-dwc2-fixes

Conversation

@sairon

@sairon sairon commented Aug 14, 2025

Copy link
Copy Markdown
Member

Raspberry Pi Linux update to 6.12.34 broke some USB devices, mostly USB-Serial converters connected to Yellow, but there are reports of some other peripherals connected to RPi boards too.

This is a known RPi upstream issue [1] fixed by a PR [2] that's not been merged to RPi stable kernel yet. Applying patches from this PR fixes the issues.

Fixes #4228, refs #4229

[1] raspberrypi/linux#6941
[2] raspberrypi/linux#6936

Summary by CodeRabbit

  • Bug Fixes
    • Improves reliability of USB devices on Raspberry Pi when connected via hubs, reducing data loss and intermittent failures with low/full‑speed interrupt peripherals.
    • Enhances stability of control transfers by enforcing the correct setup packet size, preventing stalls observed with certain devices.
    • Overall USB host behavior is more resilient under system latency, leading to fewer disconnects and errors during device enumeration and use.

Raspberry Pi Linux update to 6.12.34 broken some USB devices, mostly USB-Serial
converters connected to Yellow, but there are reports of some other peripherals
connected to RPi boards too.

This is a known RPi upstream issue [1] fixed by a PR [2] that's not been merged
to RPi stable kernel yet. Applying patches from this PR fixes the issues.

Fixes #4228, refs #4229

[1] raspberrypi/linux#6941
[2] raspberrypi/linux#6936
@coderabbitai

coderabbitai Bot commented Aug 14, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Patches modify DWC2 USB host controller behavior: masquerade split-interrupt endpoints as control during channel init and restore in interrupt handler; and enforce 8-byte max packet size for control setup stage in split-IN transfers. Changes are confined to drivers/usb/dwc2/hcd.c and drivers/usb/dwc2/hcd_intr.c.

Changes

Cohort / File(s) Summary
DWC2 split-interrupt masquerade
drivers/usb/dwc2/hcd.c, drivers/usb/dwc2/hcd_intr.c
In hc init, if do_split and ep is INTERRUPT, temporarily set ep_type to CONTROL to route via non-periodic path; in n_intr handler, restore original ep_type. Comments added; ~15 insertions.
DWC2 split-IN control setup max packet
drivers/usb/dwc2/hcd.c
In dwc2_hc_init_xfer Control Setup branch, set chan->max_packet = 8 alongside xfer_len = 8 for split-IN control setup.

Sequence Diagram(s)

sequenceDiagram
  participant USB_Device
  participant USB_Hub
  participant DWC2_HCD as DWC2 HCD
  participant Host

  Host->>DWC2_HCD: Initialize channel (INT endpoint, do_split)
  DWC2_HCD->>DWC2_HCD: Masquerade ep_type = CONTROL
  DWC2_HCD->>USB_Device: Schedule via non-periodic path
  USB_Device-->>DWC2_HCD: Transfer completes/interrupt
  DWC2_HCD->>DWC2_HCD: In interrupt, restore original ep_type

  Note over DWC2_HCD: For Control Setup (split-IN), set xfer_len=8, max_packet=8
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Resolve USB-Serial initialization failure and control message -32 errors on Raspberry Pi Yellow (Issue #4228)

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch backport-rpi-dwc2-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
buildroot-external/board/raspberrypi/patches/linux/0005-Fixup-usb-dwc2-limit-maximum-packet-size-for-split-I.patch (1)

10-13: Nit: fix minor grammar in commit message

Small improvement for clarity:

  • “Control Setup phase transfers needs” -> “Control Setup phase transfers need”
  • Consider hyphenating “8-byte” and “max-packet” for readability.

Proposed edit to the patch header text:

-Control Setup phase transfers needs an 8 byte maxpacket override, or
+Control Setup phase transfers need an 8-byte max-packet override, or
 drivers doing a GET with a small buffer as a split transaction would
 cause broken transfers.
buildroot-external/board/raspberrypi/patches/linux/0004-usb-dwc2-masquerade-split-interrupt-transfers.patch (1)

37-47: Optional: avoid mutating chan->ep_type by deriving HCCHAR EPTYPE locally

As an alternative design (to reduce state churn and the need to un-masquerade), you could compute the eptype used for HCCHAR without mutating chan->ep_type. This keeps channel state consistent and still routes via non-periodic.

Illustrative change inside the patch (for hcd.c):

-+    if (chan->do_split && chan->ep_type == USB_ENDPOINT_XFER_INT)
-+        chan->ep_type = USB_ENDPOINT_XFER_CONTROL;
-+
-     hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK;
+     {
+         u32 eptype = chan->ep_type;
+         if (chan->do_split && eptype == USB_ENDPOINT_XFER_INT)
+             eptype = USB_ENDPOINT_XFER_CONTROL;
+         hcchar |= eptype << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK;
+     }

Not required for correctness (your current approach is fine), but it’s a cleaner pattern and reduces the chance of future regressions if new code starts relying on chan->ep_type in this path.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a722bdf and 84f9b1a.

📒 Files selected for processing (2)
  • buildroot-external/board/raspberrypi/patches/linux/0004-usb-dwc2-masquerade-split-interrupt-transfers.patch (1 hunks)
  • buildroot-external/board/raspberrypi/patches/linux/0005-Fixup-usb-dwc2-limit-maximum-packet-size-for-split-I.patch (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Prepare build
🔇 Additional comments (3)
buildroot-external/board/raspberrypi/patches/linux/0005-Fixup-usb-dwc2-limit-maximum-packet-size-for-split-I.patch (2)

26-31: SETUP stage MPS override is correct and aligns with USB spec

Overriding chan->max_packet to 8 for CONTROL_SETUP is the right fix. SETUP is always 8 bytes regardless of ep0’s wMaxPacketSize and this prevents short-buffer split transactions from breaking.


26-31: Confirm max_packet is reset for subsequent CONTROL_DATA/STATUS stages

Because you temporarily set chan->max_packet = 8 in CONTROL_SETUP, please confirm that dwc2_hc_init_xfer sets chan->max_packet appropriately again for DWC2_CONTROL_DATA and DWC2_CONTROL_STATUS, so the 8-byte override doesn’t bleed into later stages.

buildroot-external/board/raspberrypi/patches/linux/0004-usb-dwc2-masquerade-split-interrupt-transfers.patch (1)

37-47: Masquerading INT-split as CONTROL to route via non-periodic looks good

The approach is consistent with the rationale: it nudges scheduling to the non-periodic path while leaving tokens intact. The early un-masquerade in the interrupt path (see Lines 59-61) prevents type confusion downstream.

Comment on lines +59 to +61
+ /* Un-masquerade the transfer type */
+ if (chan->do_split)
+ chan->ep_type = chan->qh->ep_type;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null-check for chan->qh before un-masquerading

dwc2_hc_n_intr() runs on channel interrupts; teardown/dequeue paths can momentarily leave chan->qh unset. Guarding avoids a potential NULL dereference.

Apply this diff within the patch:

-+    /* Un-masquerade the transfer type */
-+    if (chan->do_split)
-+        chan->ep_type = chan->qh->ep_type;
+     /* Un-masquerade the transfer type */
+     if (chan->do_split && chan->qh)
+         chan->ep_type = chan->qh->ep_type;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
+ /* Un-masquerade the transfer type */
+ if (chan->do_split)
+ chan->ep_type = chan->qh->ep_type;
/* Un-masquerade the transfer type */
if (chan->do_split && chan->qh)
chan->ep_type = chan->qh->ep_type;
🤖 Prompt for AI Agents
In
buildroot-external/board/raspberrypi/patches/linux/0004-usb-dwc2-masquerade-split-interrupt-transfers.patch
around lines 59 to 61, the code un-masquerades chan->ep_type by reading chan->qh
without checking for NULL; modify the condition to guard the access by checking
chan->qh (e.g., only assign chan->ep_type when chan->do_split && chan->qh) so
the interrupt path cannot dereference a NULL chan->qh.

@sairon sairon merged commit 17d811a into dev Aug 14, 2025
12 checks passed
@sairon sairon deleted the backport-rpi-dwc2-fixes branch August 14, 2025 15:33
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

board/raspberrypi Raspberry Pi Boards board/yellow Home Assistant Yellow cla-signed linux Linux kernel related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some USB-Serial adapters broken on Raspberry Pi/Yellow with OS 16.1

2 participants