Skip to content

[USB Gadget] Pass mode switch to kernel and other safety changes#2763

Open
sunshineinabox wants to merge 2 commits into
ROCKNIX:nextfrom
sunshineinabox:USBGadget_several
Open

[USB Gadget] Pass mode switch to kernel and other safety changes#2763
sunshineinabox wants to merge 2 commits into
ROCKNIX:nextfrom
sunshineinabox:USBGadget_several

Conversation

@sunshineinabox
Copy link
Copy Markdown
Collaborator

Summary

  • What is the goal of this PR?
  1. Main goal was to pass mode switching to kernel to avoid mismatch
  2. Added safety check before host mode is enabled
  3. Hardening for UDC setting

Testing

  • How was this tested? Tested only on Mangmi Air X

Additional Context

  • Add any other information that might be helpful for the reviewer (e.g., performance implications, potential risks, specific areas to focus on.)

AI Usage

While ROCKNIX doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? NO

@loki666 loki666 requested a review from stolen May 24, 2026 15:31
@stolen
Copy link
Copy Markdown
Contributor

stolen commented May 24, 2026

Needs to be checked at least on rk3326 and rk3566.
Looks good otherwise

@loki666
Copy link
Copy Markdown
Contributor

loki666 commented May 24, 2026

quick test on H700, no issues, both network and file transfer works

@stolen
Copy link
Copy Markdown
Contributor

stolen commented May 25, 2026

Well, thigs are broken on rk3326:

  • boot with usbgadget disabled
  • connect cable to PC
  • usbgadget network
  • usbgadget disabled
  • try to open NETWORK SETTINGS in ES
  • Oops in dmesg, everything is frozen, all network-related stuff is in uninterruptible sleep
ROCKNIX:~ # usbgadget 
disabled
ROCKNIX:~ # usbgadget network
ROCKNIX:~ # usbgadget disabled
[   58.552109] Internal error: Oops: 0000000096000006 [#1] SMP
[   58.552626] Modules linked in: mali_kbase(O) snd_seq snd_seq_device algif_aead ntfs3 exfat rocknix_singleadc_joypad hantro_vpu v4l2_jpeg v4l2_vp9 videobuf2_dma_contig v4l2_h264 snd_soc_simple_amplifier nfnetlink
[   58.554353] CPU: 0 UID: 0 PID: 2633 Comm: (udev-worker) Tainted: G        W  O       6.12.79 #1
[   58.555150] Tainted: [W]=WARN, [O]=OOT_MODULE
[   58.555550] Hardware name: Generic EE clone (DT)
[   58.555973] pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[   58.556606] pc : eth_get_drvinfo+0x44/0x7c
[   58.557011] lr : eth_get_drvinfo+0x3c/0x7c
[   58.557402] sp : ffff800084b3bb10
[   58.557713] x29: ffff800084b3bb10 x28: ffff00000201ee40 x27: 0000000000000000
[   58.558371] x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000004000
[   58.559032] x23: 0000fffff8b1eed0 x22: 0000000000000000 x21: ffff800080e1eb60
[   58.559689] x20: ffff000003edc000 x19: ffff0000264a2408 x18: 0000000000000000
[   58.560347] x17: 0000000000000000 x16: 0000000000000000 x15: 0000fffff8b1eed0
[   58.561005] x14: 0000000000000000 x13: 0000000000000030 x12: 0101010101010101
[   58.561664] x11: 7f7f7f7f7f7f7f7f x10: 0000800080c5fc08 x9 : 0000000000000030
[   58.562325] x8 : 0101010101010101 x7 : 0000000000000020 x6 : ffff0000264a242c
[   58.562981] x5 : 0000000000383030 x4 : 000000000000001f x3 : 0000000000000008
[   58.563643] x2 : 0000000000000020 x1 : ffff80008102a7f8 x0 : 0000000000000000
[   58.564304] Call trace:
[   58.564541]  eth_get_drvinfo+0x44/0x7c
[   58.564910]  ethtool_get_drvinfo+0x50/0x1c0
[   58.565316]  __dev_ethtool+0x788/0x1d20
[   58.565689]  dev_ethtool+0x100/0x240
[   58.566034]  dev_ioctl+0x318/0x4f4
[   58.566374]  sock_do_ioctl+0x8c/0xd0
[   58.566718]  sock_ioctl+0x288/0x348
[   58.567040]  __arm64_sys_ioctl+0xa0/0xd8
[   58.567415]  invoke_syscall.constprop.0+0x3c/0xe4
[   58.567866]  el0_svc_common.constprop.0+0x34/0xcc
[   58.568313]  do_el0_svc+0x18/0x20
[   58.568631]  el0_svc+0x20/0xcc
[   58.568940]  el0t_64_sync_handler+0x118/0x124
[   58.569348]  el0t_64_sync+0x14c/0x150
[   58.569708] Code: 911fe021 9410b2f9 f944ce80 d2800402 (f9403401) 
[   58.570265] ---[ end trace 0000000000000000 ]---
ls: /sys/devices/platform/ff300000.usb/supplier:platform:*usb2phy: No such file or directory
cat: can't open '/sys/devices/platform//extcon/*/cable.*/name': No such file or directory


ROCKNIX:~ # ps afx | grep "   D"
     48 ?        D      0:00  \_ [kworker/u16:3+events_power_efficient]
   6909 ttyS2    S+     0:00  \_ grep --color=auto    D
    226 ?        Ds     0:05 /usr/lib/systemd/systemd-resolved
    528 ?        Dsl    0:00 /usr/sbin/NetworkManager --no-daemon
   1110 ?        Ds     0:09 /bin/sh /usr/lib/autostart/quirks/devices/Generic EE clone/bin/battery_led_status
   1667 ?        Dl     0:17  \_ emulationstation --log-path /var/log --no-splash

I need to check without this patch too

@sunshineinabox
Copy link
Copy Markdown
Collaborator Author

I think I sitll have my r36s I'll take a look as well

@stolen
Copy link
Copy Markdown
Contributor

stolen commented May 25, 2026

I need to check without this patch too

Same behaviour without this patch.

@sunshineinabox please hide these:

ls: /sys/devices/platform/ff300000.usb/supplier:platform:*usb2phy: No such file or directory
cat: can't open '/sys/devices/platform//extcon/*/cable.*/name': No such file or directory

@stolen
Copy link
Copy Markdown
Contributor

stolen commented May 26, 2026

Checked on rk3566 (rg503).
Gadget was very broken, and is still very broken. So, no degradation here :)

Copy link
Copy Markdown
Contributor

@stolen stolen left a comment

Choose a reason for hiding this comment

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

LGTM

@loki666
Copy link
Copy Markdown
Contributor

loki666 commented May 27, 2026

@sunshineinabox would the PR qualify as a bugfix, I mean does it fix issues on some device ?
or is more like "better safe than sorry" changes

@sunshineinabox
Copy link
Copy Markdown
Collaborator Author

@sunshineinabox would the PR qualify as a bugfix, I mean does it fix issues on some device ? or is more like "better safe than sorry" changes

The role switch portion actually is a bug on Mangmi Air X (maybe other qc devices as well) when connected to computer I was not able to switch between widget types. The vbus portion of it is a safety check. I imagine most people aren’t connecting their devices to PC so not sure how high priority it would be.

@loki666
Copy link
Copy Markdown
Contributor

loki666 commented May 28, 2026

Yeah probably best to have it after freeze

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.

3 participants