sv6160: generate CQM events ourselves so roaming can trigger

Autonomous roaming could never fire. The firmware stops delivering beacons
the moment it enters its connected-STA regime -- measured: the last
"RXCH: BCN" arrives during the pre-association scan and not one after it, and
"iw station dump" reports "beacon rx: 0" / "beacon signal avg: 0 dBm". Since
mac80211's software CQM is driven purely by beacons of the associated AP
(ieee80211_handle_beacon_sig), count_beacon_signal stayed 0 and no RSSI
threshold event was ever raised.

We then made it worse. mac80211 only refuses a CQM request when
IEEE80211_VIF_BEACON_FILTER is set without SUPPORTS_CQM_RSSI, and we declared
neither -- we set only IEEE80211_HW_CONNECTION_MONITOR. So mac80211 accepted
the request and then had no way to service it, and the supplicant waited
forever for an event that could not come. Measured with iwd: 0 autonomous
roams in 135 s with RoamThreshold=-35 against a -47 dBm link, with no
"CMD_SET_CQM not supported, falling back to polling" in its log. The vendor
rk915 avoids this by declaring BEACON_FILTER, so mac80211 returns -EOPNOTSUPP
and the supplicant polls RSSI instead.

Declare the beacon filtering honestly and do CQM in the driver, off the RSSI
of frames actually received from the AP (that path already works -- the same
value backs "signal avg" in the station dump). New cqm module parameter:

  0 = legacy: declare nothing. Kept only as an A/B control; autonomous
      roaming cannot work in this mode.
  1 = declare BEACON_FILTER only, so mac80211 returns -EOPNOTSUPP and the
      supplicant falls back to polling, like the vendor driver.
  2 = declare BEACON_FILTER | SUPPORTS_CQM_RSSI, take the threshold from
      BSS_CHANGED_CQM, and raise the events with ieee80211_cqm_rssi_notify()
      (default).

The threshold is also picked up from bss_conf at BSS_CHANGED_ASSOC, because
mac80211 only emits BSS_CHANGED_CQM while already associated and would
otherwise drop a threshold configured during the connect. The BSSID is
snapshotted rather than read back through sc->vif, since the RX path must
never dereference a VIF that may be tearing down.

Verified on hardware. The chain that was previously dead now runs end to end:

  sv6160: CQM: threshold -35 dBm, hysteresis 5 dB
  sv6160: CQM: RSSI -41 dBm below -35 dBm -> LOW
  iwd: station_roam_trigger_cb() -> station_roam_scan()
  iwd: StationDebug.Event(roam-scan-triggered)
  iwd: station_roam_timeout_rearm() Arming new roam timer for 5 seconds

Before the fix iwd's log stopped at the early neighbour report. Under stock
config it arms at iwd's real default: "CQM: threshold -70 dBm" then
"CQM: RSSI -41 dBm above -70 dBm -> HIGH".

Roam execution itself was already sound and is unchanged: 6/6 forced roams
via iwd's StationDebug.Roam, every one cross-channel (2437 -> 2412 -> 2462),
630-660 ms each, IP retained, tx_frames == tx_done_events, tx_resyncs 0,
token_bmp 0x000. Scanning while associated is likewise clean: 10/10 real
off-channel sweeps at 0% loss, and 120 s of roam-scanning every 5 s left
3109/3109 completions, 0 resyncs, oversize 0, rx_nomem 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Moos7zcsHdpW8DKMq2KM3G
This commit is contained in:
Paul KilarandClaude Opus 5 committed 2026-09-12 20:00:25 -04:00
1 parent af16910899
commit 3436f64c60
2 files changed
+130

No files matched your search

@@ -1061,6 +1061,26 @@ struct sv6160_softc {
/* Set once we have associated, so disconnect-only behaviour can be
* told apart from the identical-looking pre-first-connect state. */
bool was_connected;
/* Connection-quality monitoring.
* mac80211's software CQM is driven purely by beacons from the
* associated AP (ieee80211_handle_beacon_sig). This firmware delivers
* NO beacons once it enters its connected-STA regime -- measured: the
* last RXCH: BCN arrives during the pre-association scan and not one
* after it -- so count_beacon_signal stays 0, no threshold event is
* ever raised, and a supplicant never learns the link has weakened.
* That is why autonomous roaming never triggered while forced roams
* worked. We run CQM ourselves off the RSSI of frames actually
* received from the AP. The BSSID is snapshotted rather than read
* back through sc->vif, because the RX path must never dereference a
* VIF that may be tearing down (see vif_addr above). */
u8 cqm_bssid[ETH_ALEN];
s32 cqm_thold; /* dBm; 0 = CQM not configured */
u32 cqm_hyst; /* dB */
int cqm_avg_q3; /* EWMA of RSSI, 1/8 dBm units */
bool cqm_avg_valid;
int cqm_last_event; /* 0 none, -1 low, +1 high */
u32 cqm_events; /* debug: events raised */
u32 cqm_samples; /* debug: frames sampled */
struct ieee80211_channel channels[SV6160_NUM_CHANNELS];
struct ieee80211_rate rates[12];
struct ieee80211_supported_band band_2ghz;
@@ -397,6 +397,30 @@ static int mod_disc_skip;
module_param_named(disc_skip, mod_disc_skip, int, 0644);
MODULE_PARM_DESC(disc_skip, "Bisect the disconnect wedge: 1=skip SETKEY DEL, 2=skip cleared-BSSID VIF_CFG, 4=skip STA_DISCONN VIF_CFG");
/* Connection-quality monitoring, which is what makes autonomous roaming work.
*
* mac80211's software CQM counts beacons from the associated AP
* (ieee80211_handle_beacon_sig). This firmware stops delivering beacons the
* moment it enters its connected-STA regime, so that counter stays at 0 and
* mac80211 never raises a threshold event -- while still happily ACCEPTING a
* CQM request, because its refusal is gated on IEEE80211_VIF_BEACON_FILTER
* which we were not declaring. The supplicant then waits forever for an event
* that cannot come. Measured with iwd: 0 autonomous roams in 135 s with
* RoamThreshold=-35 against a -47 dBm link, no "falling back to polling" in
* iwd's log, while forced roams (StationDebug.Roam) worked 6/6.
*
* 0 = legacy behaviour: declare nothing (mac80211 accepts CQM, then starves
* it). Kept only as an A/B control -- autonomous roaming cannot work.
* 1 = declare BEACON_FILTER only, so mac80211 returns -EOPNOTSUPP and the
* supplicant falls back to polling RSSI. This is what the vendor
* driver does (its station dump omits the beacon fields entirely).
* 2 = declare BEACON_FILTER | SUPPORTS_CQM_RSSI and raise the events here
* from received-frame RSSI: event-driven, no polling (default).
*/
static int mod_cqm = 2;
module_param_named(cqm, mod_cqm, int, 0644);
MODULE_PARM_DESC(cqm, "Connection-quality monitoring: 0=off (no autonomous roaming), 1=declare beacon filtering so the supplicant polls, 2=driver-generated CQM events from RX RSSI (default)");
/* Override the rate mac80211 picked with a fixed HT MCS index (-1 = off).
*
* Diagnostic: the firmware honours whatever rate chain we hand it (measured,
@@ -2334,6 +2358,57 @@ int sv6160_rpu_roc(struct sv6160_softc *sc, u32 ctrl, u32 channel,
* and dispatches based on the event ID in the header.
* =================================================================== */
/* Feed one received frame's RSSI into our own connection-quality monitor.
*
* This stands in for mac80211's ieee80211_handle_beacon_sig(), which cannot
* work here because the firmware delivers no beacons while associated. Same
* shape as mac80211's: an exponential average of the AP's RSSI, with an event
* raised on each threshold crossing. Runs from the RX path, so it must not
* sleep -- ieee80211_cqm_rssi_notify() is safe from atomic context.
*/
static void sv6160_cqm_sample(struct sv6160_softc *sc,
const struct ieee80211_hdr *wh, s8 signal)
{
int avg;
if (mod_cqm < 2 || !sc->assoc || !sc->cqm_thold || !sc->vif)
return;
/* Only the AP we are associated to says anything about link quality. */
if (is_zero_ether_addr(sc->cqm_bssid) ||
!ether_addr_equal(wh->addr2, sc->cqm_bssid))
return;
/* EWMA in 1/8 dBm units. */
if (!sc->cqm_avg_valid) {
sc->cqm_avg_q3 = signal * 8;
sc->cqm_avg_valid = true;
} else {
sc->cqm_avg_q3 += (signal * 8 - sc->cqm_avg_q3) / 8;
}
sc->cqm_samples++;
avg = sc->cqm_avg_q3 / 8;
if (sc->cqm_last_event >= 0 &&
avg < sc->cqm_thold - (int)sc->cqm_hyst) {
sc->cqm_last_event = -1;
sc->cqm_events++;
dev_info(sc->dev, "CQM: RSSI %d dBm below %d dBm -> LOW\n",
avg, sc->cqm_thold);
ieee80211_cqm_rssi_notify(sc->vif,
NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
avg, GFP_ATOMIC);
} else if (sc->cqm_last_event <= 0 &&
avg > sc->cqm_thold + (int)sc->cqm_hyst) {
sc->cqm_last_event = 1;
sc->cqm_events++;
dev_info(sc->dev, "CQM: RSSI %d dBm above %d dBm -> HIGH\n",
avg, sc->cqm_thold);
ieee80211_cqm_rssi_notify(sc->vif,
NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
avg, GFP_ATOMIC);
}
}
/*
* Trim trailing padding from beacon/probe response IE region.
*
@@ -2560,6 +2635,8 @@ void sv6160_rpu_rx_frame(struct sv6160_softc *sc, struct sk_buff *skb)
rx_status->freq);
(void)ftype;
}
/* Must run before ieee80211_rx_irqsafe(), which consumes the skb. */
sv6160_cqm_sample(sc, wh, rx_status->signal);
ieee80211_rx_irqsafe(sc->hw, skb);
}
@@ -4217,6 +4294,17 @@ static int sv6160_mac_add_interface(struct ieee80211_hw *hw,
/* Snapshot the address while the VIF is guaranteed alive. */
memcpy(sc->vif_addr, vif->addr, ETH_ALEN);
/* Tell mac80211 the truth about beacons: this firmware filters them
* out once associated, so mac80211's beacon-driven software CQM can
* never fire. Declaring BEACON_FILTER makes it stop pretending --
* ieee80211_set_cqm_rssi_config() then refuses the request unless we
* also claim to do CQM ourselves, which is exactly what cqm=2 does
* (see the cqm module parameter). */
if (mod_cqm >= 1)
vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
if (mod_cqm >= 2)
vif->driver_flags |= IEEE80211_VIF_SUPPORTS_CQM_RSSI;
if (sc->is_rpu_ready) {
struct rpu_cmd_vif_cfg cfg;
int ret = sv6160_rpu_add_vif(sc, vif->addr, mode);
@@ -4592,6 +4680,15 @@ static void sv6160_mac_bss_info_changed(struct ieee80211_hw *hw,
sc->assoc = true; /* stop the connect-time RX keepalive */
cancel_delayed_work(&sc->rx_keepalive);
sc->was_connected = true;
/* Arm our own CQM against this AP. mac80211 only
* emits BSS_CHANGED_CQM while already associated, so a
* threshold the supplicant set during the connect would
* otherwise be missed -- take it from bss_conf here. */
ether_addr_copy(sc->cqm_bssid, info->bssid);
sc->cqm_thold = info->cqm_rssi_thold;
sc->cqm_hyst = info->cqm_rssi_hyst;
sc->cqm_avg_valid = false;
sc->cqm_last_event = 0;
dev_info(sc->dev, "Associated to %pM\n", info->bssid);
sv6160_rpu_vif_cfg(sc, info->bssid,
VIF_CFG_CONNECT_STATE | VIF_CFG_AID_CHANGED |
@@ -4602,6 +4699,9 @@ static void sv6160_mac_bss_info_changed(struct ieee80211_hw *hw,
sc->operating = false;
sc->assoc = false;
cancel_delayed_work(&sc->rx_keepalive);
eth_zero_addr(sc->cqm_bssid);
sc->cqm_avg_valid = false;
sc->cqm_last_event = 0;
dev_info(sc->dev, "Disassociated\n");
sv6160_tx_flush_link(sc, "disassociated");
if (!(mod_disc_skip & 4))
@@ -4611,6 +4711,16 @@ static void sv6160_mac_bss_info_changed(struct ieee80211_hw *hw,
}
}
if (changed & BSS_CHANGED_CQM) {
/* Only reaches us when we claimed SUPPORTS_CQM_RSSI (cqm=2). */
sc->cqm_thold = info->cqm_rssi_thold;
sc->cqm_hyst = info->cqm_rssi_hyst;
sc->cqm_avg_valid = false;
sc->cqm_last_event = 0;
dev_info(sc->dev, "CQM: threshold %d dBm, hysteresis %u dB\n",
sc->cqm_thold, sc->cqm_hyst);
}
if (changed & BSS_CHANGED_BEACON_ENABLED) {
if (info->enable_beacon)
sv6160_beacon_start(sc, info->beacon_int ?: 100);