Skip to content

usb: dock USB Ethernet Wake-on-LAN (cdc_ncm pattern filters + USB 3 per-function remote wake) - #1233

Closed
RyanTheTide wants to merge 2 commits into
integration/aurorafrom
usb/cdc-ncm-wol
Closed

RyanTheTide wants to merge 2 commits into
integration/aurorafrom
usb/cdc-ncm-wol

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Wake-on-LAN through a dock's USB Ethernet (CDC NCM), found on the J616s (M4 Pro) with a Plugable UD-ULTC4K dock (DisplayLink 17e9:6011). Before this, ethtool enu1u2i5 showed no Wake-on line and nothing on the network could wake the Mac.

Two causes, two commits:

  1. usb: core: arm remote wakeup for every function of a USB 3 device. On USB 3 the host arms remote wake per function, with FUNCTION_SUSPEND sent to the first interface of each function. usb_enable_remote_wakeup() only armed interface 0 (it had a FIXME for exactly this case). On this dock interface 0 is the DisplayLink display function. The NCM Ethernet sits at interfaces 5-6 (DFU is 1, UAC2 audio is 2-4), so it was never armed. Now every function gets armed (each IAD's bFirstInterface, plus every interface outside an IAD) and every function gets disarmed on resume. The status of interface 0 is still the return value. Failures on other functions are only logged.
  2. net: usb: cdc_ncm: support Wake-on-LAN with the CDC pattern filters. The dock's CDC Ethernet descriptor reports bNumberPowerFilters 8. The driver now offers wol g when the function has pattern filters and the configuration supports remote wakeup. Before a system sleep it loads three magic-packet patterns: UDP/IPv4, EtherType 0x0842 and UDP/IPv6. The destination address is not compared. Each pattern is checked with GET_ETHERNET_PM_PATTERN_FILTER, and all of them are cleared (wLength 0) at resume, so runtime autosuspend is unchanged. cdc_mbim and huawei_cdc_ncm report no WoL.

Default behaviour is unchanged: WoL is off until someone runs ethtool -s <if> wol g or sets NetworkManager 802-3-ethernet.wake-on-lan magic.

Receipts

(J616s results follow in a comment below.)

🤖 Generated with Claude Code

A USB 3 device enables remote wakeup per function: the host arms each
function with SET_FEATURE(FUNCTION_SUSPEND) addressed to the first
interface of that function. usb_enable_remote_wakeup() only ever sent it
to interface 0 and carried a FIXME for devices whose interface
association descriptors show more than one function.

Docks are such devices. The Plugable UD-ULTC4K (DisplayLink 17e9:6011)
has a vendor display function at interface 0, DFU at 1, UAC2 audio at
2-4 and its CDC NCM Ethernet at 5-6. With wakeup enabled on the dock
only the display function was armed, so its Ethernet could never wake
the host from system sleep.

Send FUNCTION_SUSPEND to the first interface of every function: the
bFirstInterface of each association, and every interface outside one.
Do the same when disarming, so a resumed device leaves function suspend
on all of them. The result of the request to the first interface is
still the return value. A failure on another function is only logged, so
a device that rejects the request there keeps working as it did.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
The CDC Ethernet functional descriptor gives the number of power
management pattern filters a function has (bNumberPowerFilters). While
the function is suspended with remote wakeup enabled, it compares every
received frame with the loaded patterns and wakes the host on a match
(SET/GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER, which NCM takes over
from ECM). cdc_ncm loaded none and had no ethtool WoL operations, so
"ethtool -s <dev> wol g" failed and a dock's NCM Ethernet could not wake
the host.

Offer WAKE_MAGIC when the function has pattern filters and its
configuration supports remote wakeup. Setting it enables wakeup on the
USB device, as other USB Ethernet drivers do. Before a system sleep,
load one pattern for each usual framing of a magic packet: UDP over IPv4
without options, the 0x0842 EtherType, and UDP over IPv6 without
extension headers. The destination address is left out of the
comparison, so broadcast and directed magic packets both match. Each
pattern is read back with GET, since a pattern that does not fit leaves
its filter inactive. The patterns are removed at resume, so they never
affect runtime autosuspend.

Only the generic cdc_ncm driver offers WoL. cdc_mbim and huawei_cdc_ncm
share the ethtool operations but have no Ethernet descriptor and report
no WoL support.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #1235. On the hardware the UD-ULTC4K STALLs every CDC PM pattern-filter request (even though bNumberPowerFilters is 8) and matches magic packets by itself, so the pattern-filter loading here never worked. #1235 carries the hardware receipts.

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.

1 participant