Skip to content

[follow-up to #24] wifi: brcmfmac: bound AWDL creation and validate its data path - #183

Merged
RyanTheTide merged 9 commits into
aurora-wipfrom
fix/pr24-review
Oct 8, 2026
Merged

RyanTheTide merged 9 commits into
aurora-wipfrom
fix/pr24-review

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Use the vif-event lock to arbitrate completion and timeout of asynchronous
AWDL creation. Defer cleanup of a failed registration to wiphy work, and
drain event and wiphy work before protocol teardown. Keep the netdevice
reference and validate its wiphy and AWDL role when requesting deletion.

Retain the vendor dcmd errno ABI rather than toggling shared fwil error
state around commands. Account for the 16-byte AWDL envelope in the MTU
and reject oversized Ethernet-II frames before writing an invalid 802.3
length. Route the per-frame measurement trace through dynamic debug.

Follow-up to #24; original contributor commits are preserved. These fixes are based on public Linux/PR source and Linux-side tests.

Validation: targeted arm64 driver build passed (object checks only); strict checkpatch passed for the final code changes with only the required Assisted-by trailer diagnostic excluded.

Hardware qualification is pending. No boot, suspend, fault-injection or firmware recovery pass is claimed. The publication gate is separate from runtime acceptance.

Any outstanding contributor certification on the original PR remains outstanding; no contributor sign-off was added by this follow-up.

🤖 Generated with Claude Code

brentkearney and others added 9 commits October 7, 2026 13:04
BCM4387 firmware implements AWDL (Apple Wireless Direct Link) and accepts
BRCMF_INTERFACE_TYPE_AWDL through interface_create, but nl80211 has no AWDL
iftype, so the interface cannot be created via add_virtual_intf(). Drive it
from a vendor command instead.

Creation is asynchronous, and has to be. nl80211 dispatches vendor commands
holding the wiphy mutex: NL80211_CMD_VENDOR sets NL80211_FLAG_NEED_WIPHY
without NL80211_FLAG_NO_WIPHY_MTX, unlike NL80211_CMD_NEW_INTERFACE which
sets NEED_RTNL | NO_WIPHY_MTX and takes the wiphy mutex itself, in that
order. Registering a netdev from the vendor command therefore deadlocks:

  nl80211_vendor_cmd                    <- holds wiphy mutex
   brcmf_awdl_add_vif
    brcmf_net_attach
     register_netdev                    <- takes RTNL
      register_netdevice
       call_netdevice_notifiers_info
        cfg80211_netdev_notifier_call
         mutex_lock                     <- wiphy mutex, already held

The task blocks in uninterruptible sleep while holding the RTNL, which
takes
down every netdev operation on the system; recovery needs a reboot. Using
cfg80211_register_netdevice() instead is not a fix either: it requires both
the RTNL and the wiphy mutex, and the vendor command holds only the latter,
so it trips ASSERT_RTNL and registers into an inconsistent state. Taking
the
RTNL explicitly would invert cfg80211's RTNL-then-wiphy order.

So brcmf_awdl_add_vif() only asks firmware for the interface and returns.
The netdev is registered later by brcmf_cfg80211_awdl_attach_pending(),
called from the fweh event worker, which runs on the system workqueue
holding neither lock. The vif event stays armed across the request because
brcmf_notify_vif_event() is what links the brcmf_if to the vif; without it
ndev->ieee80211_ptr is never set and cfg80211 ignores the netdev.

Userspace must wait for awdl0 to appear rather than assume the vendor
command created it.

Signed-off-by: Brent Kearney <[email protected]>
Bringing an AWDL interface up through brcmf_netdev_open() stops the
firmware
answering dcmds. Every subsequent command times out with -EIO, the
infrastructure STA link drops with it, and only a brcmfmac reload recovers
the device.

The standard open path runs station bring-up against the interface: a
toe_ol
iovar query, brcmf_cfg80211_up(), and then the multicast and promisc
configuration that ndo_set_rx_mode schedules via
_brcmf_set_multicast_list().
An AWDL bsscfg is not a station, and issuing that sequence against one
wedges
the firmware control path.

Give AWDL interfaces their own net_device_ops. brcmf_netdev_open_awdl()
checks the bus is up, clears the 802.1x pending count, and leaves the
carrier
off, touching no firmware state. ndo_set_rx_mode is omitted entirely so the
multicast worker never runs for these interfaces, and ndo_stop skips
brcmf_cfg80211_down() for the same reason the open path skips
brcmf_cfg80211_up().

awdl0 now comes up with the firmware still responsive and the STA link
undisturbed.

Signed-off-by: Brent Kearney <[email protected]>
brcmf_fil_cmd_data() collapses every firmware failure to -EBADE unless
ifp->fwil_fwerr is set, so a userspace probe driving iovars through the
Broadcom vendor dcmd passthrough cannot tell "no such iovar" from "bad
argument" from "not up". Set fwil_fwerr around the call and log the raw
BCME_* value.

This makes the passthrough usable for firmware exploration: the same probe
that previously reported EBADE for every failure now distinguishes
BCME_BADOPTION, BCME_BUFTOOSHORT, BCME_NOTFOUND and BCME_NOTREADY.

Signed-off-by: Brent Kearney <[email protected]>
brcmf_cfg80211_request_awdl_if() sent interface_create with MAC_USE
alone: no BSSID and no requested interface index. On BCM4387 that
yields an interface whose AWDL iovars stay unusable.

Send flags 0x1a (MAC_USE | IF_INDEX_USE | BSSID_USE) with an explicit
BSSID and if_index 2 instead. Firmware behaviour changes with those
arguments: the interface is created at the requested index (wl0.2),
awdl_peer_op returns data instead of BCME_NOMEM, and awdl_af_hdr,
awdl_config and awdl_af_rssi are accepted where they previously were
not.

The three values are module parameters so they can be swept without
rebuilding. Derive a MAC when the caller passes NULL rather than
sending MAC_USE with an all-zero address.

Signed-off-by: Brent Kearney <[email protected]>
nl80211 calls vendor commands holding the wiphy mutex and not the RTNL
(NL80211_CMD_VENDOR sets NEED_WIPHY without NO_WIPHY_MTX). Calling
brcmf_remove_interface() from brcmf_awdl_del_vif() therefore reaches
cfg80211_close_dependents(), which asserts the RTNL:

  RTNL: assertion failed at net/wireless/core.c (419)
   cfg80211_close_dependents
   brcmf_remove_interface
   brcmf_awdl_del_vif
   brcmf_cfg80211_vndr_cmds_awdl_handler

and then deadlocks the netdev layer against any concurrent RTNL holder,
leaving NetworkManager and ip(8) unkillable in D state.

Ask the firmware to drop the BSS and return. The BRCMF_E_IF_DEL event
lands in brcmf_fweh_event_worker(), a plain work item holding neither
lock, and brcmf_fweh_handle_if_event() removes the interface from there.
This mirrors brcmf_awdl_add_vif(), which defers brcmf_net_attach() to the
same worker for the same reason.

Signed-off-by: Brent Kearney <[email protected]>
AWDL data frames on the air are 802.3 + LLC/SNAP (OUI 00:17:f2, protocol
0x0800) + a 6-byte data header (03 04 <seq16> 00 00) + the real ethertype.
The kernel only speaks Ethernet II, so for is_awdl interfaces:

- RX: brcmf_rx_eth_type_trans() strips the encapsulation in place before
  eth_type_trans(). It is called from both delivery paths --
  brcmf_rx_hdrpull
  (BCDC) and the msgbuf RX completion (PCIe); a first attempt in hdrpull
  alone was dead code on PCIe. Frames that are already Ethernet II pass.
- TX: brcmf_awdl_encap() wraps Ethernet II in the same header with a
  per-interface incrementing sequence; needed_headroom grows by 16. Frames
  that already carry a length field (raw AF_PACKET senders building the
  encapsulation themselves) pass untouched.

Also log the destination MAC on each awdl0 TX completion so per-frame fates
can be read per peer (unicast to a MAC without a firmware peer entry
completes 0x0003 FW_TOSSED; with one, 0x0000 acked).

With this, EUI-64 neighbour pinning and awdl_peer_op ADD, a remote peer
completes TCP to us over firmware-native AWDL.

Signed-off-by: Brent Kearney <[email protected]>
brcmf_msgbuf_delete_flowring() gives up on outstanding frames after ~75 ms
and frees the ring; the firmware then completes them (tx_status 0x0006
EXPIRED) against a flow->rings[] slot that is already NULL. The awdl
txstatus log line dereferenced it (oops in
brcmf_flowring_ifidx_get from brcmf_msgbuf_process_rx on awdl-if destroy).
Look the ring up only if it still exists, and reject a flowring id beyond
max_flowrings before indexing.

Signed-off-by: Brent Kearney <[email protected]>
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Use the vif-event lock to arbitrate completion and timeout of asynchronous
AWDL creation. Defer cleanup of a failed registration to wiphy work, and
drain event and wiphy work before protocol teardown. Keep the netdevice
reference and validate its wiphy and AWDL role when requesting deletion.

Retain the vendor dcmd errno ABI rather than toggling shared fwil error
state around commands. Account for the 16-byte AWDL envelope in the MTU
and reject oversized Ethernet-II frames before writing an invalid 802.3
length. Route the per-frame measurement trace through dynamic debug.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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.

2 participants