sdio: fix the -110 wedge (drop speculative TX-RX poll) + reach 802.11 auth

The multi-session -110/-16 DW MMC wedge is eliminated. Root cause: the
tx_rx_poll timer fired sv6160_trigger_rx() every 50ms for 3s after each
TX, forcing a SPECULATIVE rx_drain that read the firmware's never-zeroed
stale RECV_LEN; that CMD53 read of absent data timed out -110 and hard-
wedged the controller. It was a legacy workaround from when GPIO didn't
fire post-init; the deaf-radio gate is open now, so RX is pure-GPIO
(vendor model) and the poll is removed.

With the wedge gone the driver now scans, delivers beacons to cfg80211,
and reaches 802.11 authentication with a real AP (correct channel/MAC/
BSSID/STA_CONN, all verified).

Changes:
- sv6160_sdio.c: revert the 1-bit-SDIO force in device_init; keep the
  core-negotiated 4-bit path (the vendor's 1-bit is a suspend-only path,
  not init). Matches vendor sdio_device_init exactly.
- core: don't arm tx_rx_poll after TX (the wedge fix); rely on GPIO.
- core: sv6160_sdio_write_tx() writes the cmd_tx_ctrl descriptor and the
  frame body as two back-to-back CMD53s under ONE sdio_claim_host+lock,
  mirroring the vendor hal_send (the chip pairs the descriptor with the
  immediately-following CMD53; a split write let an RX drain slip between
  them and the frame was never transmitted).
- core: configure_filter now uses RCV_ALL_BCNS only for
  FIF_BCN_PRBRESP_PROMISC (scan) and RCV_ALL_NETWORK_ONLY otherwise,
  matching the vendor (was flooding all beacons during association).
- core/sdio: sdio_wedged flag + bring-up retry loop in mac_start and a
  runtime ieee80211_restart_hw recovery (mmc_hw_reset) for any residual
  wedge, matching the vendor rk915_sdio_power_cycle recovery model.

WIP: includes RXCH / bss_info_changed diagnostic logging (to be removed).
Open blocker: after the first auth TX the firmware RX goes silent, so the
AP's auth response is not received; investigating the post-TX host-wake
handshake.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012N7oe7HZVU4Fb4FtpBLDgk
This commit is contained in:
Paul KilarandClaude Opus 4.8 committed 2026-09-08 06:09:01 -04:00
1 parent 7125fb4b19
commit 34fa536ae3
3 files changed
+696 -466

No files matched your search

+53 -10
View File
@@ -139,8 +139,12 @@ enum rpu_cmd_tag {
RPU_CMD_VIF_CFG = 24,
RPU_CMD_TXQ_PARAMS = 26,
RPU_CMD_FW_PRIV_CMD = 42,
RPU_CMD_PATCH_FEATURES = 100,
};
/* PATCH_FEATURES feature_val flags (vendor host_rpu_if.h) */
#define LMAC_WATCHDOG_PHY_HANG_RESET_ENABLE 0x1
/* FW_PRIV_CMD sub-command IDs (firmware internal HOST_CMD routing) */
enum fw_priv_subcmd {
FW_PRIV_STATUS_QUERY = 1,
@@ -220,8 +224,18 @@ enum rpu_event_tag {
#define VIF_CFG_BASICRATES_CHANGED (1 << 0)
#define VIF_CFG_SHORTSLOT_CHANGED (1 << 1)
#define VIF_CFG_BCN_INT_CHANGED (1 << 11)
#define VIF_CFG_SHORTRETRY_CHANGED (1 << 7)
#define VIF_CFG_LONGRETRY_CHANGED (1 << 8)
#define VIF_CFG_DTIM_CHANGED (1 << 12)
#define VIF_CFG_OP_CHAN_CHANGED (1 << 15)
#define VIF_CFG_RCV_BCN_MODE_CHANGED (1 << 10)
/* Beacon receive mode (vendor host_rpu_if.h) — RCV_ALL_BCNS is promiscuous
* (every AP's beacons, needed only during a scan); RCV_ALL_NETWORK_ONLY keeps
* only the connected network's beacons. Flooding RCV_ALL_BCNS during
* association drowns the SDIO bus in beacon RX and wedges a concurrent TX. */
#define RCV_ALL_BCNS 0
#define RCV_ALL_NETWORK_ONLY 1
/* Connect state */
#define STA_CONN 0
@@ -273,7 +287,11 @@ struct rpu_cmd_reset {
__le32 reserv[2];
} __packed;
#define SV6160_MAX_NUM_SSIDS 4
/* Vendor uses ENABLE_SPLIT_MULT_SSID_SCAN → cmd_scan.ssids[1] (one SSID per
* scan command). Our old ssids[4] shifted p2p_probe/extra_ies_len by 108B and
* the firmware read them from the wrong offset (scan struct 390 vs vendor 296,
* found by the SDIO trace diff). */
#define SV6160_MAX_NUM_SSIDS 1
#define SV6160_MAX_SSID_LEN 32
struct rpu_scan_ssid {
@@ -358,11 +376,14 @@ struct rpu_fw_priv_cmd {
__le32 prod_test; /* 0x44 */
} __packed;
/* Matches vendor struct cmd_tx_pwr EXACTLY: { hdr, if_index, tx_pwr } = 36B.
* The old layout had an extra `band` field and the wrong field order, so the
* firmware read the power value as if_index — a wire-size mismatch (40 vs 36)
* found by the SDIO trace diff. */
struct rpu_cmd_tx_power {
struct rpu_msg_hdr hdr;
__le32 tx_power;
__le32 band; /* 0 = 2.4 GHz */
__le32 if_index;
__le32 tx_pwr;
} __packed;
struct rpu_cmd_ps {
@@ -372,15 +393,20 @@ struct rpu_cmd_ps {
__le32 listen_interval;
} __packed;
/* Matches vendor struct cmd_txq_params EXACTLY = 64B (all u32 + vif_addr[6]).
* The old layout was 44B with u16/u8 fields and no uapsd/vif_addr, so the
* firmware read 20 bytes short and misinterpreted every field — a wire-size
* mismatch (44 vs 64) found by the SDIO trace diff. */
struct rpu_cmd_txq_params {
struct rpu_msg_hdr hdr;
__le32 queue_num;
__le32 aifsn;
__le32 txop;
__le32 cwmin;
__le32 cwmax;
__le32 uapsd;
__le32 if_index;
__le32 queue;
__le16 txop;
__le16 cwmin;
__le16 cwmax;
u8 aifs;
u8 pad;
u8 vif_addr[6];
} __packed;
/* TX completion event (from firmware) */
@@ -553,6 +579,9 @@ struct sv6160_softc {
bool is_firmware_loaded;
bool is_started;
bool is_rpu_ready;
bool recovering; /* restart_hw recovery in flight */
bool bringup_active; /* mac_start retry loop running (owns recovery) */
struct work_struct recover_work; /* runtime SDIO-wedge recovery */
struct work_struct rx_work;
struct delayed_work rx_poll;
struct sk_buff_head rx_queue;
@@ -594,15 +623,24 @@ struct sv6160_softc {
struct dentry *debugfs_dir;
/* Smart RECV_LEN polling — detect stale vs new data without GPIO */
u16 last_recv_len; /* RECV_LEN from previous poll */
u16 last_recv_len; /* RECV_LEN of the last drained aggregate */
unsigned long last_drain_jiffies;/* when we last drained real RX data */
bool recv_len_failed; /* last CMD53 at this RECV_LEN timed out */
/* SDIO bus wedge tracking — a -110 CMD53 read timeout (stale RECV_LEN)
* or a persistent -16/-EBUSY leaves the DW MMC controller with DAT0
* stuck; every later op returns -16. The low-level I/O helpers set this
* so bring-up (and future runtime paths) can trigger the vendor-style
* mmc_hw_reset recovery (sv6160_sdio_fw_reboot) and retry. */
bool sdio_wedged;
/* mac80211 state */
struct ieee80211_vif *vif;
struct ieee80211_channel channels[SV6160_NUM_CHANNELS];
struct ieee80211_rate rates[12];
struct ieee80211_supported_band band_2ghz;
u32 rx_filter;
u8 bcn_rcv_mode; /* last RCV_* beacon mode sent (0xFF=unset) */
struct ieee80211_scan_request *scan_request;
bool scan_in_progress;
int scan_ch_idx; /* current channel in sweep */
@@ -630,6 +668,8 @@ int sv6160_sdio_writeb(struct sv6160_softc *sc, u8 addr, u8 val);
int sv6160_sdio_readb(struct sv6160_softc *sc, u8 addr, u8 *val);
int sv6160_sdio_write_data(struct sv6160_softc *sc, u32 addr,
void *buf, size_t len);
int sv6160_sdio_write_tx(struct sv6160_softc *sc, void *desc, size_t desc_len,
void *body, size_t body_len);
int sv6160_sdio_read_data(struct sv6160_softc *sc, u32 addr,
void *buf, size_t len);
@@ -638,6 +678,7 @@ int sv6160_rpu_send_cmd(struct sv6160_softc *sc, void *cmd, size_t len,
u32 id);
int sv6160_rpu_reset(struct sv6160_softc *sc);
int sv6160_rpu_fw_priv_init(struct sv6160_softc *sc);
int sv6160_rpu_patch_feature(struct sv6160_softc *sc, u32 feature_val);
int sv6160_rpu_fw_priv_nop(struct sv6160_softc *sc);
int sv6160_rpu_phy_thresh(struct sv6160_softc *sc);
int sv6160_rpu_tx_power(struct sv6160_softc *sc, u32 power_dbm);
@@ -663,6 +704,7 @@ void sv6160_rpu_process_rx_batch(struct sv6160_softc *sc, struct sk_buff *skb);
/* Firmware & Core */
int sv6160_boot_firmware(struct sv6160_softc *sc);
int sv6160_sdio_fw_reboot(struct sv6160_softc *sc);
int sv6160_core_init(struct sv6160_softc *sc);
void sv6160_core_exit(struct sv6160_softc *sc);
int sv6160_get_sdio_blksize(void);
@@ -670,6 +712,7 @@ int sv6160_get_sdio_blksize(void);
/* Data Path */
int sv6160_hci_tx(struct sv6160_softc *sc, struct sk_buff *skb, bool is_cmd);
void sv6160_rx_worker(struct work_struct *work);
void sv6160_rx_drain(struct sv6160_softc *sc);
/* Queue Control */
void sv6160_stop_queues(struct sv6160_softc *sc);
File diff suppressed because it is too large. Load diff
@@ -6,6 +6,7 @@
#include <linux/module.h>
#include <linux/mmc/sdio_func.h>
#include <linux/mmc/sdio_ids.h>
#include <linux/mmc/sdio.h>
#include <linux/mmc/host.h>
#include <linux/mmc/core.h>
#include <linux/pm_runtime.h>
@@ -22,32 +23,21 @@ static const struct sdio_device_id sv6160_id_table[] = {
};
MODULE_DEVICE_TABLE(sdio, sv6160_id_table);
/* GPIO interrupt handler — level-triggered (DTS: IRQ_TYPE_LEVEL_HIGH).
* Fires whenever GPIO is HIGH (data available). MUST disable_irq on
* EVERY call to prevent IRQ storms — level-triggered fires continuously
* while pin is HIGH. Re-enabled by rx_worker after clear+notify. */
static irqreturn_t sv6160_gpio_irq_handler(int irq, void *dev_id)
/* Threaded OOB host-wake IRQ (vendor rk915 model).
* Registered with a NULL primary handler + IRQF_ONESHOT, so the kernel masks
* the level line when it asserts, runs THIS in thread context, and unmasks it
* only when we return — after we have drained the aggregate and clear+notify'd
* the firmware (which de-asserts the line). This is the vendor's low-latency,
* kernel-managed masking model, replacing the old hardirq + workqueue + manual
* disable_irq/enable_irq scheme. */
static irqreturn_t sv6160_gpio_irq_thread(int irq, void *dev_id)
{
struct sv6160_softc *sc = dev_id;
/* Always disable to prevent level-triggered IRQ storm.
* Even before firmware is loaded, GPIO may be HIGH. */
disable_irq_nosync(irq);
if (sc && sc->is_firmware_loaded) {
sc->gpio_irq_disabled = true;
sc->gpio_irq_count++;
sc->gpio_irq_pending = true;
/* Do NOT reset the stale guard here. This is a LEVEL-triggered
* line and the firmware never zeroes RECV_LEN (§6), so after a
* drain the line re-asserts on the SAME stale length. Clobbering
* last_recv_len=0 on every such re-fire lets that stale value pass
* the guard, and the resulting CMD53 read of stale data is the
* -110 that hard-wedges the DW MMC host. rx_worker records the
* post-drain RECV_LEN into last_recv_len so the guard blocks the
* re-read; command-response wait loops clear it explicitly when
* they expect a fresh reply. */
schedule_work(&sc->rx_work);
sv6160_rx_drain(sc);
}
return IRQ_HANDLED;
@@ -71,11 +61,11 @@ static void sv6160_sdio_irq_handler(struct sdio_func *func)
}
/*
* SDIO device initialization — matches vendor rk915 BSP protocol:
* - Block size 512 (not 128)
* - CCCR interrupt enable
* - SDIO in-band interrupt mode (DATA1 line, NOT GPIO)
* - Function-specific interrupt enable
* SDIO device initialization — matches vendor rk915 BSP sdio_device_init():
* - CCCR 0x04 = 0x07 (interrupt enable, all functions + master)
* - CCCR 0x16 = 0x80 (route IRQ to the host-wake GPIO, not in-band DAT1)
* - Block size 512 in the core-negotiated 4-bit mode (bus width untouched)
* - reg34/reg33 = 0x02 (enable host interrupt generation), clear reg32
*/
static int sv6160_sdio_device_init(struct sdio_func *func)
{
@@ -101,6 +91,18 @@ static int sv6160_sdio_device_init(struct sdio_func *func)
else
dev_info(&func->dev, "CCCR 0x16=0x80: GPIO interrupt mode enabled\n");
/* Keep the core-negotiated 4-BIT bus width for the data path — this is
* what the vendor rk915 sdio_device_init() does (it never touches bus
* width). The vendor's 1-bit switch lives in sdio_disable_wide(), a
* SUSPEND-only path (io_ejtag) — "devices that remain active during a
* system suspend are put back into 1-bit mode". An earlier revision
* here force-switched to 1-bit at init after misreading that suspend
* path as the init path; 1-bit made the SDIO data path fragile
* (intermittent -110 CMD53 read timeouts that permanently wedge the DW
* MMC controller into -16/-EBUSY). The OOB host-wake GPIO IRQ we rely
* on is a separate physical line, independent of SDIO data bus width,
* so 4-bit does not affect async host-wake delivery. */
/* Set block size (configurable via sdio_blksize param, default 512) */
{
int blksize = sv6160_get_sdio_blksize();
@@ -129,6 +131,48 @@ static int sv6160_sdio_device_init(struct sdio_func *func)
return 0;
}
/*
* Re-boot the firmware from cold — mirrors the vendor's down_fw_in_probe=0
* model. The vendor downloads+starts the firmware at .start (interface up),
* immediately before RPU_CMD_RESET, so RESET always runs on a freshly-booted
* MCU. Our probe boots at insmod; by the time mac_start runs RESET the MCU
* has been running a while and (measured) the firmware's async host-wake gate
* (tx_enabled) is shut after our RESET while the vendor's is open. Resetting
* the MCU to WAIT_FW and re-uploading right before RESET replicates the vendor.
*
* The OOB host-wake GPIO IRQ is a separate GPIO line and survives the card
* reset; only the in-band SDIO IRQ is card-bound, and we do not depend on it.
*/
int sv6160_sdio_fw_reboot(struct sv6160_softc *sc)
{
struct sdio_func *func = sc->func;
int ret;
sc->is_firmware_loaded = false;
sdio_claim_host(func);
ret = mmc_hw_reset(func->card);
if (ret)
dev_warn(&func->dev, "fw_reboot: mmc_hw_reset failed: %d\n", ret);
func->enable_timeout = jiffies_to_msecs(HZ);
ret = sdio_enable_func(func);
sdio_release_host(func);
if (ret) {
dev_err(&func->dev, "fw_reboot: sdio_enable_func failed: %d\n", ret);
return ret;
}
ret = sv6160_sdio_device_init(func);
if (ret) {
dev_err(&func->dev, "fw_reboot: device_init failed: %d\n", ret);
return ret;
}
ret = sv6160_boot_firmware(sc);
dev_info(&func->dev, "fw_reboot: fresh firmware boot ret=%d\n", ret);
return ret;
}
/* PM Suspend/Resume */
static int __maybe_unused sv6160_pm_suspend(struct device *dev)
@@ -303,9 +347,14 @@ static int sv6160_probe(struct sdio_func *func,
}
if (sc->host_wake_irq > 0) {
ret = devm_request_irq(&func->dev, sc->host_wake_irq,
sv6160_gpio_irq_handler,
IRQF_NO_SUSPEND,
/* Vendor model: THREADED IRQ, NULL primary + IRQF_ONESHOT.
* The DTS trigger (LEVEL_HIGH) is kept; the kernel masks the
* level line on assert and unmasks after the thread drains
* and ACKs the firmware. IRQF_NO_SUSPEND keeps it live across
* system suspend for wake. */
ret = devm_request_threaded_irq(&func->dev, sc->host_wake_irq,
NULL, sv6160_gpio_irq_thread,
IRQF_ONESHOT | IRQF_NO_SUSPEND,
"sv6160", sc);
if (ret) {
dev_warn(&func->dev, "GPIO IRQ %d failed: %d\n",
@@ -313,7 +362,7 @@ static int sv6160_probe(struct sdio_func *func,
sc->host_wake_irq = 0;
} else {
enable_irq_wake(sc->host_wake_irq);
dev_info(&func->dev, "GPIO IRQ %d registered (level-triggered)\n",
dev_info(&func->dev, "GPIO IRQ %d registered (threaded, ONESHOT)\n",
sc->host_wake_irq);
}
}