Compare commits
No files matched your search
@@ -8,6 +8,10 @@ Module.symvers
|
||||
.tmp_versions/
|
||||
*.bin
|
||||
!firmware/*.bin
|
||||
# ...except the patched variants, which gen_fw_patch.py reproduces from
|
||||
# the tracked ssv6160-fw.bin.orig (it verifies the bytes it rewrites).
|
||||
firmware/ssv6160-fw-patched.bin
|
||||
firmware/ssv6160-fw-p3only.bin
|
||||
repomix-output.xml
|
||||
patchrk915.py
|
||||
outstanding-issues.md
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
# Known issues
|
||||
|
||||
Open bugs in this driver, with the evidence gathered so far and — just as
|
||||
importantly — what has already been ruled out, so nobody re-runs a dead
|
||||
hypothesis. Everything here is measured on hardware (Gusgu H7, RK3326/PX30,
|
||||
kernel 6.18.45).
|
||||
|
||||
Closed issues are not listed; they live in the code comments next to the thing
|
||||
they explain, which is where someone reading that code will actually find them.
|
||||
|
||||
---
|
||||
|
||||
## 1. The wedge-prone mode (open, mitigated)
|
||||
|
||||
**Symptom.** The device intermittently enters a state in which TX wedges
|
||||
repeatedly, then leaves it again. In the state, each wedge looks like one of
|
||||
the two failures below. Outside it, the driver runs for hours without a single
|
||||
event.
|
||||
|
||||
**It is a mode, not bad luck.** From an 8 h soak (2180 cycles, rotating
|
||||
device-TX / device-RX / bidirectional load):
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| wedges | 55 |
|
||||
| span containing all 55 | **36 minutes** of a 480-minute run |
|
||||
| expected span if uniformly random | ~463 minutes |
|
||||
| inter-wedge gaps | median **28 s**; 48 of 54 under a minute |
|
||||
| rest of the run | 7+ hours, zero wedges |
|
||||
|
||||
A median gap of 28 s is roughly every other cycle. So the device does not
|
||||
suffer independent random failures — it switches into a regime where it fails
|
||||
near-periodically for about half an hour, then switches out.
|
||||
|
||||
**Impact, with the recovery ladder in place.** Each event now costs roughly a
|
||||
10-second outage instead of a dead radio. In that soak all 55 self-recovered
|
||||
with no intervention (50 of them in 10–11 s). Before the ladder, every one of
|
||||
them would have required an `unbind`/`bind` typed in over the serial console.
|
||||
So this is mitigated, not fixed: 55 brief dropouts inside half an hour is still
|
||||
user-visible.
|
||||
|
||||
### What has been ruled out
|
||||
|
||||
Each of these was tested with real sample sizes, not a single trial — this
|
||||
driver has bursty base rates and a single-trial A/B on it is worthless.
|
||||
|
||||
| hypothesis | evidence against |
|
||||
|---|---|
|
||||
| `tx_batch` size | ~1173 transfers at the maximum, zero wedges |
|
||||
| degraded SDIO write regime | 607+ transfers in the slow regime, zero wedges; and marginal probes pass in *both* regimes |
|
||||
| module reload churn | 12 reload rounds, 78 transfers, zero wedges |
|
||||
| concurrent TX+RX | 60 cycles of sustained bidirectional load, zero wedges |
|
||||
| suspend while the driver is unloaded | reboot + repeated auto-suspends, then 0/6 and 0/6 at two batch sizes |
|
||||
| **a wedge leaves residue that makes the next likelier** | `tx_batch=9` (last working value, so maximally marginal) used as a susceptibility probe, arms alternating: baseline **0/48** failures vs immediately-after-an-induced-wedge **0/48**. Eight wedges induced, each self-recovered, probe clean every time |
|
||||
|
||||
That last one matters most: the mode is **not self-sustaining**. Whatever
|
||||
drives it is external to the wedge itself.
|
||||
|
||||
### Scope limit on the reproducer — read this before using it
|
||||
|
||||
`tx_batch>9` wedges the device on demand and is genuinely useful: it is how the
|
||||
recovery ladder below was measured. But it reproduces the **fallout**
|
||||
(descriptors never completed, bus wedge, escalation) and **not the mode**. An
|
||||
induced wedge is a protocol violation — asking the firmware for more frames per
|
||||
descriptor than it honours. The natural burst is something else and cannot
|
||||
currently be summoned.
|
||||
|
||||
Do not conclude from "I induced a wedge and X happened" that X explains the
|
||||
natural bursts.
|
||||
|
||||
### Instrumentation waiting for the next natural burst
|
||||
|
||||
`dmesg` does not survive a reboot and this board has no ramoops
|
||||
(`CONFIG_PSTORE_RAM=y` but no reserved-memory region), so state is recorded to
|
||||
persistent storage instead:
|
||||
|
||||
- `/storage/flightrec.sh` → appends to `/storage/flight.log` every 60 s:
|
||||
uptime, battery %, AC online, signal, **SoC temperature**, and the descriptor
|
||||
counters (`tx_frames`, `tx_done_events`, `tx_resyncs`) plus escalation counts.
|
||||
- `/storage/.config/system.d/sv6160-boot.service` (enabled) loads this driver at
|
||||
boot and stamps `=== BOOT <date> ===` into the same log.
|
||||
|
||||
The open question that log is meant to answer: **what is different during the
|
||||
36 minutes?** Temperature and battery are the two obvious candidates that have
|
||||
never been measured *during* a burst — the soak's health lines only printed on
|
||||
non-wedge cycles, so there is no throughput or environment data from inside the
|
||||
one burst that has been captured.
|
||||
|
||||
---
|
||||
|
||||
## 2. Two distinct failures underneath it — do not conflate them
|
||||
|
||||
These share the mode above but have different signatures, different triggers
|
||||
and different fixes. Conflating them cost a full day of investigation.
|
||||
|
||||
### 2a. TX-completion link death
|
||||
|
||||
Descriptors are sent and never completed. The interface stays associated and
|
||||
keeps its IP, so it looks healthy from userspace while passing nothing.
|
||||
|
||||
- `tx_frames` climbs away from `tx_done_events`
|
||||
- `tx_resyncs` climbs
|
||||
- `token_bmp` shows descriptors held
|
||||
- **no** SDIO bus errors
|
||||
|
||||
Handled by `tx_resync_giveup` (default 3): three fruitless resyncs restart the
|
||||
hw. Verified on a live instance — 71 lost descriptors and 40+ resyncs, ssh dead;
|
||||
after the restart, ssh returned and the sent-vs-completed gap stayed at exactly
|
||||
77 across the next 971 frames, i.e. every new descriptor completed.
|
||||
|
||||
### 2b. Hard SDIO bus wedge
|
||||
|
||||
The bus itself stops responding.
|
||||
|
||||
- `TX write failed: -16`
|
||||
- `dwmmc_rockchip ff380000.mmc: Busy; trying anyway`
|
||||
- `mmc_host mmc2: Timeout sending command`
|
||||
- then every probe failing `-16` with no netdev
|
||||
|
||||
Handled by `host_rebind` (default 3): three bus recoveries inside 60 s means
|
||||
`restart_hw` cannot fix it, so the driver asks the driver core to re-bind the
|
||||
dw_mmc platform device, re-creating the host.
|
||||
|
||||
**Only re-creating the host clears this.** Measured on a real wedge:
|
||||
|
||||
| attempted | result |
|
||||
|---|---|
|
||||
| `ieee80211_restart_hw` | no effect on a hard wedge; on a softer one it made things *worse* (4→8 resyncs, 6→13 lost) — explained 2026-09-18: mac80211 re-enters `.start` without `.stop`, so the TX worker and resync kept writing to SDIO address 0 during the firmware re-upload; `mac_start` now quiesces first, re-measure |
|
||||
| `mmc_hw_reset` | returns **success** and does not help — with one function probed it is just `mmc_power_cycle` + `mmc_sdio_reinit_card`, and the bus dutifully renegotiates 400 kHz→50 MHz while staying wedged |
|
||||
| module reload | probe still fails `-16`, no interface |
|
||||
| `unbind`/`bind` of `ff380000.mmc` | **clears it, every time** |
|
||||
|
||||
Note the recovery cannot be hooked into `probe()`: once the bus is hard-wedged
|
||||
our probe is never entered at all. `sdio_bus_probe()` calls
|
||||
`sdio_set_block_size()` before `drv->probe`, that CMD52 fails `-EBUSY`, and the
|
||||
core logs "probe failed -16" without ever calling us — the failing reloads have
|
||||
no probe entry line in `dmesg`. The driver can only rescue the host while it
|
||||
still *holds* the device.
|
||||
|
||||
Corollary: only a test harness `rmmod`s a wedged driver. Production never does,
|
||||
which is why this state is far rarer in normal use than the investigation made
|
||||
it look.
|
||||
|
||||
---
|
||||
|
||||
## 3. Unexplained device reboot (open, low information)
|
||||
|
||||
The device rebooted once unattended with the battery at ~52 % and the charger
|
||||
reporting online. No crash record survives — see the ramoops note above — and
|
||||
`dmesg` had been cleared before the state was inspected, so the cause was not
|
||||
recoverable. The flight recorder in §1 exists partly to catch the next one:
|
||||
it records battery, voltage and AC state every minute, so a brownout should be
|
||||
visible in the run-up.
|
||||
|
||||
---
|
||||
|
||||
## 4. Throughput below the vendor reference (open, levers largely exhausted)
|
||||
|
||||
~1.75–1.9 MB/s TX and ~2.6 MB/s RX, against a 2.5 MB/s vendor BSP reference.
|
||||
|
||||
- `tx_batch` ships at 8 (`SV6160_TX_BATCH_MAX`), one below the firmware's real ceiling of 9.
|
||||
9 is worth ~3 % over 8 but is the last working value; 10 fails 6/6.
|
||||
- `descs_per_ac` cannot help: the limit is per-descriptor, proven by
|
||||
`descs_per_ac=1` + `tx_batch=16` (16 frames in flight, fewer than the 18 that
|
||||
`descs_per_ac=2` + `tx_batch=9` runs happily on) still stalling.
|
||||
- A-MSDU remains the one real lever and is blocked on the pull-model TX rewrite.
|
||||
- The 2× SDIO write-speed regime swing is closed as not-host-fixable; see the
|
||||
comment above `sv6160_tx_xfer_len()` for the full list of what was ruled out.
|
||||
|
||||
---
|
||||
|
||||
## 5. From the 2026-09-18 review: applied, and still open
|
||||
|
||||
Seven review passes over this branch, then a convergence pass over the fixes
|
||||
themselves. Commits `9de36d7` (driver), `48a253d` (the convergence fixes),
|
||||
`0e6129f`/`ac57ada` (tools), `f5a42b7`/`92cb227` (docs).
|
||||
|
||||
### Applied, and SOAKED (2026-09-19)
|
||||
|
||||
An 8-hour soak of `3f0f67e` on the handheld, **472 ifdown/ifup cycles inside a
|
||||
single module lifetime** — the coverage the old harness structurally could not
|
||||
provide, because it reloaded the module every trial and the unload freed the
|
||||
evidence a second later.
|
||||
|
||||
| | result |
|
||||
|---|---|
|
||||
| cycles | 472 ifdown/ifup, 472 reconnects, **0 failures** |
|
||||
| TX | 1,089,645 descriptors, completions **exactly 1:1** (final gap 0) |
|
||||
| per-AC credit leak (`<-- GATED`) | **0 cycles** — final ledger all `busy=0`, `sent==seen==done` |
|
||||
| wedges (gap persisting across a re-read) | **0** |
|
||||
| `tx_resyncs` / `tx_ebusy` / `rx_nomem` / `oversize` | **0, no growth over 8 h** |
|
||||
| recovery ladder | never fired: `tx_resync_giveup` 0, `host_rebind` 0 |
|
||||
| independent 60 s sampler | 469 samples, TX gap never outside ±2; SoC 45.0–53.3 °C; mains throughout |
|
||||
|
||||
That settles the lifecycle and accounting class: `.stop`/`.start` were
|
||||
re-entered 472 times on a module that stayed loaded, and the per-AC descriptor
|
||||
credit came back clean every time. Under the old harness this class was
|
||||
invisible for 8 hours.
|
||||
|
||||
**What it does NOT settle.** Do not read "0 wedges" as the wedge mode being
|
||||
fixed — §1 records that mode as bursty (55 wedges inside 36 minutes of a
|
||||
480-minute run, with 7+ clean hours either side), so a clean 8 hours is
|
||||
exactly what the quiet periods look like. It is encouraging, not evidence.
|
||||
The paired A/B below is still outstanding, and suspend was never exercised:
|
||||
the soak does not suspend.
|
||||
|
||||
(Harness note: `dmesg | grep -c "mac80211 stopped"` reads 21 at the end, not
|
||||
472 — the kernel ring wrapped and holds only the last ~1,400 s. 21 stops in
|
||||
that window at ~58 s/cycle is one per cycle, which is the actual evidence.)
|
||||
|
||||
### Applied, still needs an ordinary soak for anything not covered above
|
||||
|
||||
Lifecycle and accounting bugs an 8-hour soak did not see: `remove()` freed the
|
||||
softc under a live IRQ thread; `mac_stop`/`mac_flush` stranded
|
||||
`tx_outstanding_ac[]` and leaked batched skbs; the per-AC counter had no lock;
|
||||
the resync could free a frame a CMD53 was still reading; `cmd_gate=1`
|
||||
self-deadlocked the IRQ-thread drain; several firmware-supplied lengths were
|
||||
used without a lower bound.
|
||||
|
||||
Why the soak missed them is worth stating precisely, because the obvious
|
||||
version is wrong. A `rmmod`/`insmod` recovery *does* run `remove()`, `.stop`
|
||||
and `.flush` — `rmmod` → `sv6160_remove` → `ieee80211_unregister_hw` →
|
||||
`ieee80211_remove_interfaces` → `cfg80211_shutdown_all_interfaces` →
|
||||
`dev_close`, which both disconnects (→ `.flush`) and stops (→ `.stop`) — and
|
||||
`backtoours.sh` brings the interface back up afterwards. What it never does is
|
||||
run any of them on a module that then *stays loaded*: a credit or skb stranded
|
||||
by `.stop` is freed by the unload a second later, so "never returned for the
|
||||
module's life" leaves no trace, and the `.start` after a reload always meets a
|
||||
fresh softc. Only three or four of the findings were of that shape; the rest
|
||||
ran every cycle and survived because the knob that reaches them defaults off
|
||||
(`cmd_gate`, `wt_trace`), because the firmware never sent the input that trips
|
||||
them (runt `RX_SERIAS` links, event 32), or because the next unload erased the
|
||||
damage.
|
||||
|
||||
**Add an ifdown/ifup cycle to the harness before the next soak** — that is the
|
||||
gap, not the absence of `.stop`.
|
||||
|
||||
### Applied as experiments, needs a paired A/B
|
||||
|
||||
**Still outstanding after the 2026-09-19 soak** — that run exercised only the
|
||||
new build, with no paired arms, so neither change below has been compared
|
||||
against anything.
|
||||
|
||||
A/B against **`09fd788`**, the immediate pre-review parent. Not `a57846c`: that
|
||||
is the last *soaked* build, but four commits touch the driver source between
|
||||
the two (two of them `docs:`-prefixed; only `a7dfd19` changes executable
|
||||
code), so it
|
||||
cannot attribute a difference to either change below.
|
||||
|
||||
- **The `-EBUSY` back-off now drops `sc->lock`, not just the host claim.**
|
||||
`write_tx()`/`write_data()` slept up to 16 × 25 ms holding the mutex, and the
|
||||
RX drain takes that mutex *before* the host claim, so the "let RX interleave"
|
||||
the comment promised could never happen. The chip may hold DAT0 busy
|
||||
precisely because it wants its RX buffer collected, in which case the old
|
||||
code ran the 16 tries out into a declared wedge. **Candidate mechanism for
|
||||
the wedge mode in §1.**
|
||||
Caveat found afterwards, and the reason this needs more than a wedge count:
|
||||
`sc->lock` is the only thing serialising a control-command CMD53 against the
|
||||
TX descriptor/body pair, and that pair must reach the chip back-to-back
|
||||
because the firmware matches them by arrival order. A command landing
|
||||
between a failed descriptor attempt and its retry is a new way to mis-pair a
|
||||
frame. Measure `tx_ebusy` (debugfs `tx_tokens`) against
|
||||
frames-never-transmitted, not only against the wedge rate.
|
||||
- **The host-wake IRQ is no longer `IRQF_NO_SUSPEND`**, and the thread refuses
|
||||
to drain while `is_suspended`. `IRQF_NO_SUSPEND` is documented as
|
||||
incompatible with the `enable_irq_wake()` beside it, and the thread was
|
||||
issuing CMD53s to a host being clock-gated.
|
||||
Caveat: this changes suspend under RX load rather than simply fixing it. The
|
||||
thread now refuses to clear a level line that only de-asserts after a drain,
|
||||
so a host-wake pending at suspend time aborts the suspend, which then retries
|
||||
after `.resume`. Previously it drained (badly) through. Neither behaviour has
|
||||
been measured, and wake-on-GPIO through a real suspend has never been
|
||||
verified either way.
|
||||
|
||||
### Behaviour changes worth knowing before the soak
|
||||
|
||||
- `.start` on a dead card now blocks for seconds under rtnl and the wiphy lock
|
||||
instead of returning `-EIO` immediately, because the `is_firmware_loaded`
|
||||
gate had to go — it was what made an exhausted bring-up permanent until
|
||||
`rmmod`. Four bring-up attempts, each a full `mmc_hw_reset` plus image and
|
||||
patch upload, then the host re-create. Expect `ip link set wlan0 up` to hang
|
||||
a while on a wedged card rather than fail fast.
|
||||
- `fwpoke`/`fwpoke_when` are mode 0400, so a harness that echoes into
|
||||
`/sys/module/sv6160/parameters/` now gets `-EACCES`.
|
||||
- `RXCH: BCN` is `dev_dbg`, so beacon-arrival evidence needs dynamic debug.
|
||||
- `ieee80211_ready_on_channel()` makes remain-on-channel actually start for the
|
||||
first time, so off-channel management TX goes live.
|
||||
- `tx_bulk_done` in debugfs `tx_tokens` counts `RPU_EVENT_HOST_DATA_TX_DONE`
|
||||
(id 32). If it ever moves, this firmware does emit it — and the handler it
|
||||
replaced leaked every in-flight token, so that is worth knowing next time TX
|
||||
dies.
|
||||
|
||||
### What the convergence pass caught in the fixes themselves
|
||||
|
||||
Three of the thirteen fixes did not do what their own comments claimed, all
|
||||
caught only by re-reviewing the delta against its stated intent rather than
|
||||
re-reading the code:
|
||||
|
||||
- the probe-window fix ADDED a second `is_firmware_loaded = true` without
|
||||
removing the one in `boot_firmware`, so it closed nothing;
|
||||
- the runt-length guard went on the first RX link but not on the chain walk
|
||||
that re-enters with a firmware-supplied length;
|
||||
- the pre-restart quiesce left `rx_work`/`rx_poll` running, the path most
|
||||
likely to be queued when a wedge happens under scan traffic.
|
||||
|
||||
Two of the three are the same shape: a guard added to one of two paths reaching
|
||||
the same code.
|
||||
|
||||
### Known, not fixed
|
||||
|
||||
Each has a mechanism and no measurement behind it:
|
||||
|
||||
- While the firmware uploads, and between `boot_firmware` and `core_init`, the
|
||||
level host-wake line re-fires the (empty) IRQ thread continuously. The thread
|
||||
sleeps 1 ms per empty pass, which turns a spin into a ~1 kHz poll; disabling
|
||||
the IRQ across the upload would remove it.
|
||||
- Firmware upload chunks (`request_firmware` → vmalloc) and on-stack command
|
||||
structs go straight to `sdio_memcpy_toio()`, which cannot DMA either; dw_mmc
|
||||
falls back to PIO silently. Bouncing them through a kmalloc'd buffer (as
|
||||
`tx_dma` already does for frame bodies) would make the upload DMA and remove
|
||||
a swiotlb hazard.
|
||||
- `cmd_gate=1` was unusable until this review — it deadlocked the drain on the
|
||||
first queued command — so its 300 ms force-retire path has never run. Keep
|
||||
the default off until it has soak evidence.
|
||||
- `sv6160_scan_abort_local()` and the drain's SCAN_COMPLETE handler both do an
|
||||
unsynchronised `if (sc->scan_request) { ieee80211_scan_completed(); NULL; }`,
|
||||
and `recover_work` runs concurrently with the drain, so both can pass the
|
||||
test for one scan and trip `WARN_ON(!local->scan_req)`. Narrow and cosmetic,
|
||||
but it is surface this review added.
|
||||
- Zeroing `serias_next_len` on a truncated RX_SERIAS batch stops the chain, but
|
||||
the drain then reads `next == 0` as a clean end and rings the notify
|
||||
doorbell — telling the firmware we consumed a chain we abandoned, which this
|
||||
file elsewhere records as its own fatal outcome. `done_no_ack` exists for
|
||||
exactly that shape. Both outcomes are bad; the choice should be deliberate
|
||||
and right now it is not.
|
||||
- `bcn_timer` re-arms itself on `beacon_enabled && vif`, which `timer_delete_sync()`
|
||||
cannot stop, and nothing clears `beacon_enabled` on the way down. Pre-existing
|
||||
and shared with `mac_stop`; harmless today only because the TX worker's
|
||||
`is_rpu_ready` gate catches the frames. AP/IBSS only.
|
||||
|
||||
### No outside-model coverage
|
||||
|
||||
Both Codex passes died on the provider's usage limit, twice. Every reader of
|
||||
this branch so far has been some flavour of Claude, including the one that
|
||||
found three of the fixes inert. Re-run `/codex:adversarial-review` before
|
||||
upstreaming.
|
||||
|
||||
---
|
||||
|
||||
## Measurement rules for this driver
|
||||
|
||||
Learned the hard way; ignoring them has produced wrong conclusions in this repo
|
||||
more than once.
|
||||
|
||||
- **Never trust a single-trial A/B.** Base rates here are bursty. Two
|
||||
conclusions in this repo were published and later retracted on this basis.
|
||||
- **Never A/B throughput across a module reload.** A reload changes both the AP
|
||||
association and the write regime; the same binary has measured 0.65 and 1.83.
|
||||
- **Alternate arms every cycle and analyse paired.** Block designs measure the
|
||||
regime, not the variable.
|
||||
- **Verify a module parameter actually took effect.** `tx_batch` is clamped by
|
||||
`min3(mod_tx_batch, SV6160_TX_BATCH_MAX, …)`: it accepts 16, reads back 16,
|
||||
and runs at 8. Check frames-per-descriptor in debugfs before trusting any
|
||||
`tx_batch` result.
|
||||
- **Never infer driver state from a proxy.** Throughput is not wedge state — a
|
||||
starved link and a dead one look identical by bandwidth. A failed counter read
|
||||
is not a dead device. An absolute `dmesg` count is not a delta. Each of these
|
||||
produced a false "wedge detected" during this work; one of them nearly
|
||||
published the exact opposite of the truth.
|
||||
- **Keep sampling strides coprime with alternation periods.** A stride that
|
||||
divides the number of arms hides whole arms of an experiment and the log looks
|
||||
perfectly healthy while doing it.
|
||||
@@ -3,7 +3,14 @@
|
||||
**Repository:** `codeberg.org/aenertia/sv6160-rk915`
|
||||
**Target Platform:** Rockchip RK3326 (PX30) / ROCKNIX
|
||||
**Kernel:** Linux 6.18+ (Mainline)
|
||||
**Status:** SDIO bidirectional data path working. Scan in progress.
|
||||
**Status:** Usable. Associates with WPA2, gets a DHCP lease, roams between APs,
|
||||
survives suspend/resume, and sustains bidirectional traffic for hours — an 8-hour
|
||||
soak moved 2,149,692 TX descriptors with every one completed. The SDIO wedge that
|
||||
used to end a session now recovers automatically in about ten seconds.
|
||||
|
||||
Not yet prime-time: throughput is ~1.75-1.9 MB/s TX against a 2.5 MB/s vendor
|
||||
reference, and the wedge still happens (it is recovered from, not prevented).
|
||||
See [`KNOWN-ISSUES.md`](KNOWN-ISSUES.md).
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -22,21 +29,204 @@ and `SDIO_ARCHITECTURE.md` for the SDIO protocol specification.
|
||||
| Feature | Status |
|
||||
|---------|--------|
|
||||
| SDIO enumeration | Working |
|
||||
| Firmware upload (48KB) + patch (16KB) | Working |
|
||||
| Firmware upload (48056 B) + patch (16716 B) | Working |
|
||||
| Firmware state machine (M0_READY) | Working |
|
||||
| mac80211 registration (wlan0) | Working |
|
||||
| mac80211 registration | Working — note the interface index increments on every reload, so it is rarely `wlan0` |
|
||||
| SDIO CMD53 bidirectional data path | Working |
|
||||
| RPU command/event protocol | Working |
|
||||
| RPU_CMD_RESET → RESET_COMPLETE | Working |
|
||||
| FW_PRIV_INIT (SET_CONFIG) | Working |
|
||||
| NOP ping (data path verification) | Working |
|
||||
| NOP ping (`FW_PRIV_NOP`) | Implemented but **unused** — `sv6160_rpu_fw_priv_nop()` has no callers; the data path is verified by real traffic now |
|
||||
| VIF add/remove | Working |
|
||||
| Channel programming | Working |
|
||||
| WiFi scanning | SCAN_COMPLETE received; RX frames pending (rf_params fix) |
|
||||
| WiFi association | Not yet |
|
||||
| Data TX/RX | Not yet |
|
||||
| WPA key management | Not yet |
|
||||
| eFuse MAC address | Not yet (random MAC) |
|
||||
| WiFi scanning (native `RPU_CMD_SCAN`) | Working — finds all APs, beacons reach cfg80211 |
|
||||
| Frame TX | Working — every frame completes (`TX_DONE` 1:1) |
|
||||
| Frame RX (broadcast + unicast) | Working |
|
||||
| WiFi authentication | Working — `authenticated` ~10ms after the auth frame |
|
||||
| WiFi association | Working — `RX AssocResp status=0`, `associated` |
|
||||
| WPA2 key management | Working — 4-way handshake, CCMP group + pairwise keys |
|
||||
| DHCP / usable connection | Working — carries ssh, the link this was developed over |
|
||||
| Sustained link | Working — measured: 8h soak, 2,149,692 TX descriptors, all completed 1:1 |
|
||||
| Suspend / resume | Working — measured once: same BSS and IP across a real deep suspend. Measured before the 2026-09-18 change that dropped `IRQF_NO_SUSPEND` from the host-wake IRQ; re-verify (see KNOWN-ISSUES §5) |
|
||||
| Roaming | Working — measured on a real walk: 2 cross-channel roams, 40ms and 82ms handoffs, IP kept |
|
||||
| CQM (RSSI thresholds) | Working — raised from RX-frame RSSI; drives iwd's roam trigger |
|
||||
| Wedge recovery | Working — both failure modes self-recover unattended (see below) |
|
||||
| Lifecycle under ifdown/ifup | **Soaked 2026-09-19**: 472 cycles in one module lifetime, 1.09 M descriptors 1:1, zero credit leaks, zero wedges, recovery ladder never fired |
|
||||
| Power save | Measured and **deliberately rejected** — ~8mA of a ~365mA budget, PS measured *worse* |
|
||||
| A-MSDU | Not engaged — root-caused to a missing `SUPPORT_FAST_XMIT`; adding it does aggregate but the chip cannot carry the result. Dead end, see below |
|
||||
| MAC address | Stable and per-device — the factory MAC, via U-Boot into the DT; see below |
|
||||
|
||||
### A-MSDU: chased down, and it is a dead end
|
||||
|
||||
Root-caused rather than assumed, because the obvious explanations were all
|
||||
wrong.
|
||||
|
||||
**Why it never engaged: we do not set `IEEE80211_HW_SUPPORT_FAST_XMIT`.**
|
||||
`ieee80211_amsdu_aggregate()` has exactly one call site, inside
|
||||
`ieee80211_xmit_fast()`; mac80211 only builds `sta->fast_tx` when the driver
|
||||
advertises that flag, and `ieee80211_check_fast_xmit()` returns at its first
|
||||
line without it. So the aggregation code was structurally unreachable. We
|
||||
advertised `TX_AMSDU` -- "we can accept an A-MSDU" -- without the flag that
|
||||
makes mac80211 take the path that *builds* one.
|
||||
|
||||
Adding the flag does work: `tx_max_frame` went from 1542 to **3080**, i.e. two
|
||||
MSDUs in one frame, the first A-MSDU this driver has ever sent.
|
||||
|
||||
**And it is unusable.** Throughput collapsed from 0.77 MB/s to 0.02-0.08 MB/s,
|
||||
with `sdio_write_data(...) failed: -16` in the log and the host-rebind recovery
|
||||
firing. The chip cannot carry the larger frame bodies -- consistent with what
|
||||
is already known about this SDIO path, where padding a CMD53 to the block size
|
||||
kills the link and the vendor records that concatenating does too.
|
||||
|
||||
So A-MSDU is closed as a throughput lever, for a better reason than before.
|
||||
|
||||
Two earlier explanations, both refuted on hardware:
|
||||
|
||||
- *"the peer does not advertise a usable max_amsdu_len"* -- it does:
|
||||
`iw` decodes the AP's HT capabilities as `Max AMSDU length: 7935 bytes`.
|
||||
- *"the ADDBA Response clears the A-MSDU bit, so mac80211 latches
|
||||
`IEEE80211_TXQ_NO_AMSDU` on the TID"* -- refusing TX BlockAck entirely left
|
||||
`tx_max_frame` at 1542 while collapsing throughput 5x.
|
||||
|
||||
And the pull-model rewrite (`txq=1`) was built to unblock A-MSDU on the theory
|
||||
that the push shim drains the txq before mac80211 can aggregate. That theory
|
||||
was untestable: with fast-xmit off, no TX model could have produced an A-MSDU.
|
||||
The rewrite costs throughput and is correctly left off, but it was never the
|
||||
blocker.
|
||||
|
||||
**Testing note.** `SUPPORT_FAST_XMIT` is latched at probe from the `amsdu`
|
||||
parameter, so it must be passed to `insmod` -- setting it by sysfs afterwards
|
||||
silently measures the unflagged driver. Three runs were invalidated that way
|
||||
before the probe build was made to log its own flag state and the harness to
|
||||
discard any arm that could not prove it.
|
||||
|
||||
### Where the MAC comes from
|
||||
|
||||
It is the **factory** MAC and it is **per device**, despite the driver having a
|
||||
random fallback that never runs here.
|
||||
|
||||
The factory address lives in Rockchip vendor storage (tag `0x524B5644`, sector
|
||||
7296, item id 3) -- the same place the BSP read it from via
|
||||
`rockchip_wifi_mac_addr()`. Vendor U-Boot reads that, exports `ethaddr`, and
|
||||
`fdt_fixup_ethernet()` writes it into whatever `/aliases/ethernet0` resolves
|
||||
to; ROCKNIX points that alias at the wifi node. So the node arrives carrying
|
||||
`local-mac-address` and `of_get_mac_address()` picks it up:
|
||||
|
||||
sv6160 mmc2:0001:1: MAC 1e:28:78:e8:94:15 from device tree
|
||||
|
||||
`ethtool -P` reports the same value, and it survives reloads and reboots. The
|
||||
`1e:28:78:` prefix is common to the family; the low three bytes are per unit.
|
||||
Check it with:
|
||||
|
||||
od -tx1 /sys/firmware/devicetree/base/mmc@ff380000/wifi@1/local-mac-address
|
||||
|
||||
(`/proc/device-tree` is a symlink, so a plain `find` will not see that file.)
|
||||
|
||||
The driver's order is DT -> hash of the RK3326 OTP serial -> `eth_random_addr()`.
|
||||
Only the first step runs on this board.
|
||||
|
||||
**Reading the SV6160's own eFuse is not implemented, and would gain nothing
|
||||
here.** The registers are mapped (`EFUSE_CTRL` `0xC0000134`, offset in bits
|
||||
0-5, busy in bit 7; `EFUSE_RDATA` `0xC0000138`; MAC at eFuse offset `0x10`) and
|
||||
`fw_peek`'s `rw=0` is a plain load with no address validation in the firmware,
|
||||
so the MMIO is reachable -- our `0x10000000..0x1000BBB8` guard is self-imposed.
|
||||
It would need that guard widened, a write path for `EFUSE_CTRL` (only `rw=0`
|
||||
has ever been exercised), and busy-polling. The reason not to bother: the
|
||||
factory put the MAC in vendor storage, not in the chip's eFuse, which is why
|
||||
the BSP reads vendor storage too -- so the likely result is a blank eFuse and a
|
||||
fallback to the address we already have. It would only matter on a board with
|
||||
neither a vendor-storage MAC nor a DT property.
|
||||
|
||||
### Recovery ladder
|
||||
|
||||
The driver rescues itself from both wedge modes rather than needing a human:
|
||||
|
||||
| condition | action |
|
||||
|---|---|
|
||||
| 3 fruitless TX resyncs | restart the hw (`tx_resync_giveup`) |
|
||||
| 3 bus recoveries in 60s | re-create the SDIO host (`host_rebind`) |
|
||||
|
||||
In the 8-hour soak these fired 16 and 1 times respectively, and all 55 wedge
|
||||
events recovered without intervention — 50 of them within 10-11 seconds. Before
|
||||
it, each one needed an `unbind`/`bind` typed in over a serial console.
|
||||
|
||||
Two details fixed in the 2026-09-18 review, not yet re-soaked:
|
||||
|
||||
- The second rung counts only `-16`/`-110` bus faults. It used to count every
|
||||
recovery, so three TX-link deaths inside a minute (the wedge mode's median
|
||||
gap is 28 s) escalated to a host re-create instead of the `restart_hw` that
|
||||
was measured to fix that failure.
|
||||
- `ieee80211_restart_hw()` re-enters `.start` **without** calling `.stop`, so
|
||||
`mac_start` now quiesces the driver's own state first (TX worker, resync,
|
||||
command gate, descriptor pool). Before, the TX worker kept writing
|
||||
descriptors to SDIO address 0 while the firmware image was being uploaded
|
||||
to the same address, which is the likely reason `restart_hw` "made things
|
||||
worse" in KNOWN-ISSUES.
|
||||
|
||||
`echo 1|2 > /sys/kernel/debug/ieee80211/phy*/sv6160/recover` drives the two
|
||||
rungs by hand. It returns `-EINVAL` on any other input rather than silently
|
||||
running the shallow rung, `-EBUSY` when the host re-create one-shot is already
|
||||
spent or `host_rebind=0`, and `-ENODEV` for level 1 when the interface is down.
|
||||
|
||||
### History: how the encrypted data path was unblocked
|
||||
|
||||
This section used to describe the then-current blocker — association and the
|
||||
WPA handshake completed, but DHCP never did and the supplicant gave up. That is
|
||||
fixed; the driver now carries the ssh session it is developed over. The bugs
|
||||
behind it are recorded below because the techniques that found them (byte-diffing
|
||||
our command stream against the vendor's, and dumping raw bytes instead of
|
||||
reasoning about them) keep paying off.
|
||||
|
||||
### How association was unblocked
|
||||
|
||||
Four bugs. The first two were found by diffing our control-command stream
|
||||
against the vendor's byte for byte (`tools/rk915-wiredump.patch`); the last two
|
||||
by dumping raw bytes rather than reasoning about them:
|
||||
|
||||
1. `sv6160_rpu_vif_cfg()` never populated `vif_addr`, so every VIF_CFG told
|
||||
the firmware our MAC was `00:00:00:00:00:00`. `FW_PRIV_INIT` carries only
|
||||
the first octet of the MAC, so VIF_CFG/VIF_CTRL are the only way the
|
||||
firmware learns the whole address — and without it the LMAC cannot
|
||||
address-match a unicast frame. Broadcast beacons arrived; our auth
|
||||
response never did.
|
||||
2. `sv6160_mac_tx()` stashed the TX descriptor id at `skb->cb`, which *is*
|
||||
`struct ieee80211_tx_info` — overwriting mac80211's TX `flags` on every
|
||||
frame. Harmless-looking until the first data frame after association
|
||||
panicked the kernel in `skb_complete_wifi_ack`.
|
||||
3. The RX chain followed an `RX_SERIAS` batch header's next-length, which is
|
||||
really the length of the batch's own first sub-packet. That read a packet
|
||||
that never existed, and the CMD53 timeout wedged the DW MMC controller.
|
||||
4. TX descriptor ids came from a free-running counter. The firmware's table
|
||||
has 12 entries and it rejects anything beyond — saying so in an FW_ERROR
|
||||
event, `"[3243 F] Invalid desc id"` — then stops delivering *every* kind
|
||||
of event. The `-16` bus wedge was eleven seconds downstream of that fault,
|
||||
which is why it looked like a bus problem. Ids are now pooled tokens,
|
||||
freed on TX_DONE, as in the vendor's `get_token()`.
|
||||
|
||||
### Superseded: the scan-gating theory
|
||||
|
||||
Measured from the firmware's own counters (`fwpeek=1 sweep_base=0x1000BA98
|
||||
sweep_len=32`, which reads its TX/RX statistics block): reception starts when a
|
||||
scan starts and stops the instant `SCAN_COMPLETE` fires. `RPU_CMD_CHANNEL` tunes
|
||||
the radio but does **not** arm the receiver — in one capture the target AP's
|
||||
beacons arrived on channel 6 during a scan, `CH_PROG_DONE(ch=6)` completed 250ms
|
||||
later, and nothing was received again on that same channel.
|
||||
|
||||
So mac80211's authentication frame is transmitted into a window where nothing can
|
||||
be heard. The control path stays healthy throughout (`cmd_send`/`event_recv` keep
|
||||
climbing) and TX completes normally — only 802.11 reception is dead.
|
||||
|
||||
This is not a firmware limitation: the vendor driver's receiver is equally off
|
||||
when idle, yet it goes from idle to `authenticated` in 17ms with no scan anywhere
|
||||
in that window. `firmware/README.md` §12 has the captures.
|
||||
|
||||
### Known instability
|
||||
|
||||
Both faults that used to live here are fixed: the stale-RECV_LEN `-110` wedge
|
||||
(the guard that caused it now defaults off) and the per-beacon `WARN` in
|
||||
`ieee80211_rx_list`. What remains open — with the evidence and the ruled-out
|
||||
hypotheses — is in [`KNOWN-ISSUES.md`](KNOWN-ISSUES.md), chiefly that the wedge
|
||||
arrives in bursts whose trigger is still unidentified.
|
||||
|
||||
### Required Kernel Patch
|
||||
|
||||
@@ -106,13 +296,51 @@ make -C /path/to/kernel M=$PWD CONFIG_SV6160=m modules
|
||||
|
||||
## Module Parameters
|
||||
|
||||
| Parameter | Type | Default | Description |
|
||||
|-----------|------|---------|-------------|
|
||||
| `coalescing` | bool | true | Enable RX IRQ coalescing |
|
||||
| `rx_bundle` | int | 16 | Max RX packets per interrupt |
|
||||
| `sdio_blksize` | int | 512 | SDIO block size (try 64/128 for debugging) |
|
||||
| `mac_program` | string | — | Program eFuse MAC (xx:xx:xx:xx:xx:xx) |
|
||||
| `patch` | string | ssv6160-patch.bin | Firmware patch file name |
|
||||
31 in total; `modinfo sv6160` lists them all with descriptions. The ones that
|
||||
change behaviour rather than instrument it:
|
||||
|
||||
| Parameter | Default | Description |
|
||||
|-----------|---------|-------------|
|
||||
| `tx_stall_ms` | 3000 | Declare a TX descriptor stalled after this long and resync the pool |
|
||||
| `tx_quarantine_ms` | 3000 | Hold a resync-reclaimed descriptor id back this long before reuse |
|
||||
| `tx_resync_giveup` | 3 | Restart the hw after N fruitless resyncs (0 = never) |
|
||||
| `host_rebind` | 3 | Re-create the SDIO host after N bus recoveries in 60s (0 = off) |
|
||||
| `tx_batch` | 8 | Max frames per TX descriptor — **9 is the firmware's real ceiling**, see below |
|
||||
| `tx_dma` | 1 | Bounce TX bodies through an aligned buffer so dw_mmc can DMA them |
|
||||
| `descs_per_ac` | 2 | Descriptors in flight per AC |
|
||||
| `cqm` | 2 | Declare BEACON_FILTER/SUPPORTS_CQM_RSSI so RSSI events drive roaming |
|
||||
| `ba_rx` | 1 | Program RX BlockAck sessions to the firmware |
|
||||
| `coalescing` | true | Enable RX IRQ coalescing |
|
||||
| `rx_bundle` | 16 | Max RX packets processed per interrupt |
|
||||
| `patch` | ssv6160-patch.bin | Firmware patch file name |
|
||||
|
||||
The rest (`fwpeek`, `fwinfo`, `sweep_base`, `sweep_len`, `fwpoke`, `wiredump`,
|
||||
`trace`, `wt_trace`, `scan_passive`, `scan_single_ch`, `fixed_mcs`, `cmd_gate`,
|
||||
`vendor_bringup`, `rf_arm`, `txq`, `amsdu`, `chan_settle`, `sdio_blksize`,
|
||||
`fwpoke_when`) are diagnostics and experiments; several exist to keep a measured
|
||||
answer switchable rather than lost. `fwpoke` and `fwpoke_when` are insmod-only
|
||||
(mode 0400): they write firmware memory. `wiredump` and `wt_trace>=2` never dump
|
||||
the `SETKEY` payload, so no `dmesg` carries session keys, and the `WBODY`/`RXDATA`
|
||||
frame dumps stop after the 802.11 header plus IV.
|
||||
|
||||
`RXTAIL` is the exception and is deliberate: it prints the last 8 bytes of a
|
||||
decrypted frame, which is the only way to tell whether the firmware left a CCMP
|
||||
MIC there or ate 8 bytes of real payload. When the MIC is absent those 8 bytes
|
||||
ARE payload. It needs `wt_trace=1`, so it is opt-in, but scrub a capture taken
|
||||
with it before sharing.
|
||||
|
||||
**Older documents reference parameters that no longer exist.** `firmware/README.md`
|
||||
and `VENDOR-DRIVER-FINDINGS.md` mention `rx_chain`, `rf_keep`, `int_gen`,
|
||||
`system_rev`, `stale_guard`, `mac_program` and others. Those are records of
|
||||
experiments, not current knobs — each one's answer is now a comment next to the
|
||||
code it settled, and the parameter was culled. `modinfo` is the source of truth
|
||||
for what exists today.
|
||||
|
||||
**`tx_batch` warning.** It is clamped by
|
||||
`min3(mod_tx_batch, SV6160_TX_BATCH_MAX, …)`, so on a stock build it accepts 16,
|
||||
reads back 16, and runs at 8. Verify frames-per-descriptor in debugfs before
|
||||
trusting any `tx_batch` measurement — that trap invalidated ~1173 transfers of
|
||||
evidence once already.
|
||||
|
||||
## Architecture
|
||||
|
||||
@@ -159,17 +387,22 @@ address — a brief delay or RINTSTS check prevents premature CMD53 reads.
|
||||
|
||||
## Known Issues
|
||||
|
||||
1. **No WiFi beacon/probe frames yet** — SCAN_COMPLETE received and RX_SERIAS
|
||||
batches delivered, but sub-packets are all CMD_PROC_DONE (28 bytes), not
|
||||
802.11 frames. Root cause: rf_params was all zeros → radio not calibrated
|
||||
for RX. Fix: populated rf_params + LMAC_NO_SLEEP + PHY thresholds (testing).
|
||||
See [`KNOWN-ISSUES.md`](KNOWN-ISSUES.md) for the open bugs, the evidence behind
|
||||
them, and — most usefully — the hypotheses already ruled out with sample sizes,
|
||||
so none of them gets re-run by accident.
|
||||
|
||||
2. **SDIO in-band IRQ not firing** — Despite sdio_claim_irq + cap-sdio-irq,
|
||||
SDIO in-band interrupts never trigger. GPIO level-trigger IRQ is the working
|
||||
path (fires 5-9 times per scan cycle).
|
||||
In short: the SDIO wedge still occurs in bursts whose trigger is unidentified
|
||||
(six hypotheses eliminated), it is recovered from automatically rather than
|
||||
prevented, and throughput sits below the vendor reference with the obvious levers
|
||||
exhausted.
|
||||
|
||||
3. **-110 recovery** — Stale RECV_LEN causes CMD53 reads before DMA is ready.
|
||||
Graceful recovery: FIFO reset + skip (no clear+notify on failed reads).
|
||||
The three issues that used to be listed here — no beacons/probe frames, SDIO
|
||||
in-band IRQ not firing, and `-110` stale-RECV_LEN recovery — are all resolved.
|
||||
The first was uncalibrated `rf_params`; the last was the RX aggregate cap being
|
||||
4096 where the vendor uses 33280.
|
||||
|
||||
See [`VENDOR-DRIVER-FINDINGS.md`](VENDOR-DRIVER-FINDINGS.md) for measurements
|
||||
from the vendor-based driver on the same silicon.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+10
-1
@@ -1,5 +1,12 @@
|
||||
# SV6160 / RK915 SDIO Architecture
|
||||
|
||||
> **Status:** The register map, boot protocol, and packet sections below are
|
||||
> still the reference. The "Implementation Status" and "Current Blocker"
|
||||
> sections further down are a historical snapshot from commit 2303d96 — the
|
||||
> -110 CMD53 read timeout they describe was resolved on the
|
||||
> `sdio-rx-hardening` branch. See README.md and KNOWN-ISSUES.md for the
|
||||
> current state.
|
||||
|
||||
## Critical Finding: SDIO Address Space
|
||||
|
||||
The SDIO CMD53 protocol only supports **17-bit addresses** (0x00000 - 0x1FFFF = 128 KiB).
|
||||
@@ -133,7 +140,9 @@ Files studied from `stolen/rk915`:
|
||||
- `src/sdio.c` — `sdio_send_data()`/`sdio_recv_data()` SDIO I/O (ANALYZED)
|
||||
- `src/hal.c` — `hal_send()`/`rx_thread()` event dispatch (ANALYZED)
|
||||
|
||||
## Current Blocker: CMD53 Read Timeout (-110)
|
||||
## Historical: CMD53 Read Timeout (-110), resolved
|
||||
|
||||
See README.md for the current state; this section is kept for history only.
|
||||
|
||||
### Symptom
|
||||
SDIO CMD53 data reads at address 0 return -110 (ETIMEDOUT) on the XF40H's
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
# Findings from the vendor-based RK915 driver
|
||||
|
||||
Notes contributed from work on the *other* Linux driver for this chip — the
|
||||
out-of-tree mainline port of the Rockchip/Seekwave vendor BSP (the
|
||||
`sunshineinabox/rk915` 7.1 line, itself from `stolen/rk915`), running on a Gusgu
|
||||
H7 (RK3326/PX30). That driver is a different codebase from this clean-room one,
|
||||
but it targets the **same silicon and the same firmware**, and it has reached
|
||||
full association + bidirectional data, so it has run into walls this driver has
|
||||
not hit yet. This file records what was learned, in case it saves time here.
|
||||
|
||||
Contributed 2026-09; all data measured on hardware.
|
||||
|
||||
## Same firmware, confirmed
|
||||
|
||||
The firmware blobs are byte-identical to the vendor BSP's:
|
||||
|
||||
| this repo | md5 | vendor BSP name |
|
||||
|---|---|---|
|
||||
| `firmware/ssv6160-fw.bin` | `a0e5ed758324e15bc2ed62d0e29f12d8` | `rk915_fw.bin` |
|
||||
| `firmware/ssv6160-patch.bin` | `6c1f8ec692e153ca61617d0d2dd5cd4d` | `rk915_patch.bin` |
|
||||
|
||||
So this repo's firmware reverse-engineering applies directly to the vendor
|
||||
driver, and vice versa. The `firmware/README.md` register map matched the
|
||||
vendor driver's independently-derived SDIO register defines
|
||||
(NOTIFY=17, INT=32, WRITE_COMP=35, FW_STATE=64) exactly.
|
||||
|
||||
## Your reset-poll idea fixed the vendor driver's boot race
|
||||
|
||||
`sv6160_rpu_reset()` pumps the RX worker every 100 ms while waiting for
|
||||
RESET_COMPLETE, with the comment *"Poll the RX worker manually since SDIO
|
||||
interrupts may not be firing during early init."* The vendor port had the
|
||||
opposite — a bare `wait_event_timeout()` — and suffered an intermittent
|
||||
`RPUWIFI-UMAC: No reset complete after N ticks` on ~1 boot in 3. Adopting your
|
||||
approach (kick the RX thread on a 100 ms slice during the wait) fixed it. Thanks.
|
||||
|
||||
## The wall this driver will hit at the data path: an SDIO wedge under sustained RX
|
||||
|
||||
The single unsolved fault in the vendor driver is a hard throughput ceiling, and
|
||||
it is almost certainly the full form of the *"-110 that permanently kills DW MMC
|
||||
bus"* hazard already noted in `sv6160_core.c` (the `last_recv_len` / stale
|
||||
RECV_LEN guard) and Known Issue #3. Measured shape:
|
||||
|
||||
* **Rate-triggered.** Sustained transfer above roughly **15–29 KB/s** kills the
|
||||
link within seconds — either direction, a single TCP connection is enough.
|
||||
Below that rate the link is stable indefinitely (13 h+ observed). Bursty
|
||||
traffic with idle gaps is fine; it is continuous throughput that does it.
|
||||
|
||||
* **The chip is not asleep.** `FW_STATE` (SDIO reg 64) reads `M0_READY` (5)
|
||||
before, during and after the fault. Whatever happens, the MCU is alive.
|
||||
|
||||
* **The whole SDIO link wedges, not one transfer.** Instrumented a failing
|
||||
CMD53 write to also read RECV_LEN and FW_STATE at that instant: **both reads
|
||||
also return `-EBUSY` (-16).** So every transaction to the card — CMD52 read
|
||||
and CMD53 write alike — fails at once. The card has stopped servicing the bus.
|
||||
|
||||
* **Host-side retry does not help.** Retrying a busy write up to 8 times over
|
||||
~30 ms, dropping the host lock between attempts so the RX worker could drain,
|
||||
rescued **zero** writes. The wedge persists until the chip is **power-cycled**
|
||||
(the vendor driver's firmware-error recovery does exactly that, and the link
|
||||
then comes straight back).
|
||||
|
||||
* **Most consistent with RX buffer exhaustion.** It matches `rx_buf_pool`
|
||||
(`0x10006524`, max 15 entries) and `event_pending_count` (`0x10006520`) from
|
||||
`firmware/README.md`: the chip's RX pool fills faster than it is drained over
|
||||
SDIO, and past some fill level the SDIO slave stops responding. That is exactly
|
||||
why a rate threshold exists — below it the pool never saturates.
|
||||
|
||||
Ruled out on hardware, so they need not be re-tried: LMAC sleep (FW stays
|
||||
M0_READY); mac80211 power-save off (no change); a runtime `LPW_CTRL`
|
||||
(`0xC0001000`) bit-4 "disable clock gating" write via the firmware's register
|
||||
path (readback unchanged — that path does not reach the LPW block); host-side
|
||||
write/length-read retries (wedge outlasts them).
|
||||
|
||||
**A real fix needs the chip's RX flow-control / buffer-credit protocol**, which
|
||||
is not documented anywhere we have found. The proven workaround is to rate-limit
|
||||
(`rsync --bwlimit=15` moves a 24 MB image cleanly); it works precisely because it
|
||||
holds the chip under the saturation threshold.
|
||||
|
||||
## `length(61680) too long` / `0xF0F0` is the wedge, not a bad length
|
||||
|
||||
Worth knowing because this driver's RECV_LEN read has the same shape. The vendor
|
||||
driver's `rk915_read_data_len()` reads the two RECV_LEN bytes via CMD52 and folds
|
||||
them into a length. On a busy bus each byte read returns `-EBUSY`; cast to
|
||||
`u8`, `(u8)(-16)` is `0xF0`, so the two bytes combine to `0xF0F0` = **61680**,
|
||||
which then trips the "length too long" bound check. So `length(61680)` and a
|
||||
write failing `-16` are the **same event** — the `-EBUSY` wedge — reached from
|
||||
the read or the write side. The byte pattern is therefore **not diagnostic**: an
|
||||
idle-time `0xF0F0` can be the chip having slept (cured by keeping the LMAC awake),
|
||||
while an under-load `0xF0F0` is this bus wedge with the chip wide awake. Tell them
|
||||
apart by reading `FW_STATE` plus one more register at the failure — if both also
|
||||
return `-16`, it is the wedge.
|
||||
|
||||
---
|
||||
|
||||
## Checkpoint 2026-09-09: byte-level command diff against the vendor
|
||||
|
||||
Method that worked: instrument **both** drivers to dump their actual SDIO
|
||||
payloads (`wt_trace=2` on ours; `print_hex_dump` in the vendor's
|
||||
`sdio_send_data`/`sdio_recv_data`) and diff real bytes on the same hardware,
|
||||
against byte-identical firmware. Every real bug below came from that. Every
|
||||
conclusion reasoned forward from a mechanism instead turned out to be wrong.
|
||||
|
||||
### Bugs found and fixed
|
||||
|
||||
| Bug | Detail |
|
||||
|---|---|
|
||||
| **TX descriptor 512 vs 581** | The vendor's `cmd_tx_ctrl` ends with `unsigned int *p_frame_ddr_pointer[MAX_TX_CMDS]` — *host pointers*, 8B each on a 64-bit kernel = a 128B tail we omitted (453+128=581, wire `ALIGN(581,4)`=584). We wrote the 802.11 body after a 512B descriptor, so it began 72 bytes before where the firmware looks. |
|
||||
| **`RPU_CMD_PS` malformed and gratuitous** | Firmware `cmd_ps` is `{hdr; if_index; mode}` (36B); we sent a 40B struct, so it read `if_index=<our mode>`, `mode=200`. The vendor never sends this command at all — `rpu_prog_ps_state()` is a bare `return 0;`. Ours is now a no-op. |
|
||||
| **TX queue numbering inverted** | mac80211 numbers ACs `VO=0..BK=3`; the firmware numbers them `BK=0..VO=3`. The vendor maps every frame through `tx_queue_map()` (= `3-ac`, `src/tx.c:130`). We had no mapping: all TX went out on queue 0 = **Background** (the vendor's dumped assoc descriptor shows `queue_num=3` = Voice), and `conf_tx`/bring-up programmed the whole EDCA table onto inverted queues. |
|
||||
| **Multicast commands never sent** | `MCST_ADDR_CFG`(0x13) and `MCST_FLTR_CTRL`(0x14) were absent from our command enum. The vendor sends an explicit `MCAST_FILTER_DISABLE` whenever the address list is empty; we left the LMAC filter at its power-on default. |
|
||||
| **`.prepare_multicast` slept in atomic context** | mac80211 documents it as atomic; our send path takes a mutex and does a synchronous CMD53. Sending from there hung the board. The vendor can, because its `rpu_send()` only takes a `spin_lock_bh` and queues the buffer. Now the callback only snapshots the list; `.configure_filter` does the SDIO. |
|
||||
|
||||
### Proven identical (stop re-checking these)
|
||||
|
||||
CHANNEL payload (byte-for-byte, both drivers, incl. the ch11 variant), RESET
|
||||
payload (byte-for-byte except `system_rev`, now matchable via a module param),
|
||||
firmware + patch binaries (`a0e5ed75…` / `6c1f8ec6…`; our `ssv6160-fw.bin` ==
|
||||
vendor `rockchip/rk915_fw.bin`), RF calibration (neither `rk915_cal.bin` nor
|
||||
`rk915_rf_para.txt` exists on the device, so both run stock `rf_params`),
|
||||
`FW_PRIV` type=6, `VIF_CTRL` layout, TX descriptor rate fields
|
||||
(`num_rates=1, protection=0, preamble=1, retries=5, rate=2, spatial=1`),
|
||||
`bcn_rcv_mode` values and usage.
|
||||
|
||||
### Retraction: the "vendor CHANNEL takes 52ms, ours 1.6ms" signature is not real
|
||||
|
||||
Decoding the vendor's RX **event ids** (`rpu_msg_hdr.id` at offset 16) shows its
|
||||
`CH_PROG_DONE` (evid 18) arrives in **2.2ms** on an idle pipeline — the same
|
||||
ballpark as ours. The "52ms" was the first post-CHANNEL event being a
|
||||
`COMMAND_PROC_DONE` (evid 17), delivered on a ~53ms cadence when commands are
|
||||
queued; it is ack pacing, not RF work, and it varies (2 / 104 / 159 ms) with
|
||||
pipeline depth. Comparing gaps between untyped 28-byte reads produced a phantom
|
||||
that drove a lot of wasted effort. **Decode event ids before timing anything.**
|
||||
|
||||
### Where the problem now sits: TX works, unicast RX does not
|
||||
|
||||
Measured over 22s with the gate off:
|
||||
|
||||
```
|
||||
TX cmds (id=7) = 9 TX_DONE (evid=1) = 9 <-- perfect 1:1
|
||||
RX: 48 frames, ALL 400-420 bytes (evid=0) <-- beacons/probe-resps only
|
||||
53 x evid=17 PROC_DONE, 7 x evid=18 CH_PROG, 2 x evid=5, 1 x evid=8
|
||||
```
|
||||
|
||||
Every auth frame we transmit produces a TX_DONE, so the firmware **is**
|
||||
transmitting. Beacons arrive normally. But an auth reply would be ~60-90 bytes
|
||||
with its descriptor and **we receive no small frames at all** — the firmware
|
||||
never delivers a unicast frame to us. That retires TX, channel programming and
|
||||
the command stream as suspects.
|
||||
|
||||
Open question: why beacons but never unicast? Candidates not yet examined —
|
||||
whether the firmware needs the VIF in a particular state before forwarding
|
||||
non-beacon frames, and how it learns our full MAC for RX address matching
|
||||
(`VIF_CTRL` carries `vif_addr[6]`, while `FW_PRIV` carries only the first
|
||||
octet).
|
||||
|
||||
### Also refuted
|
||||
|
||||
`cmd_gate` — the vendor's control-command serialization (max 2 outstanding,
|
||||
retire on `COMMAND_PROC_DONE`) starves here and hard-hung the board twice; it
|
||||
is committed but **default off**. With the gate off the firmware acks ~76% of
|
||||
our commands (34 acks / 45 commands), so the LMAC does process them. Also no
|
||||
help: `rf_arm=1`, `int_gen=0`, and replicating the vendor's full pre-CHANNEL
|
||||
config sequence.
|
||||
|
||||
## The vendor's firmware self-report interface (2026-09-10)
|
||||
|
||||
The GPL vendor source is on disk and is the authority for anything fw-priv:
|
||||
`rocknix/build.ROCKNIX-RK3326.aarch64/build/rk915-86f0d0e07afe156651ce5eec3e315f66ef79a59f/`
|
||||
(`src/`, `inc/`, `shared/host_rpu_if.h`). The sub-command enum, the payload
|
||||
struct and the dump reply structs all live there; the `enum fw_priv_subcmd` in
|
||||
our `sv6160.h` predates it and is wrong.
|
||||
|
||||
### Using the vendor driver as a live control
|
||||
|
||||
`$D = /sys/kernel/debug/ieee80211/phyN/rk915`. Two writable files, and they
|
||||
take different vocabularies — cross-writing just gives "Invalid parameter name":
|
||||
|
||||
- `$D/params` takes **commands**: `read_fw_reg=ADDR,LEN`, `write_fw_reg=ADDR,VAL`,
|
||||
the `_lpw_` variants, `debug_mask=`, `econ_ps=`, `notify_pm=`, `simulate_fw_crash`.
|
||||
- `$D/fw_params` takes **parameters**: `echo_mode=`, `ejtag_mode=`, `debug_level=`,
|
||||
`debug_flag=`, `dis_wifi_isr_thd=`, `en_wifi_isr_thd=`, `dump_mem_info`.
|
||||
|
||||
A read is `echo read_fw_reg=0x1000BAA8,0x4 > $D/params` followed by
|
||||
`timeout 5 cat $D/fw_info`. **The value is in `fw_info`** (`1000baa8: 00001f83`).
|
||||
The `rk915: read fw reg ... val 0x0` dmesg line is only the request log and its
|
||||
`val` is always 0 — reading dmesg instead makes every address look like zero.
|
||||
Always put a `timeout` on the `cat`; it can block.
|
||||
|
||||
Healthy baseline, vendor associated and pulling ~180 frames/s: `0x1000BAA8`
|
||||
climbing continuously, `0x1000BBA8` = 0, `0x100064E4` = 0, `0x100054E4` = 0,
|
||||
`0x10005474` = 1 (doorbell armed).
|
||||
|
||||
Hazards, both measured: reading outside `0x10000000..0x1000BBB8` kills the
|
||||
firmware (recoverable with a `dwmmc_rockchip` unbind/bind), and
|
||||
`read_fw_reg=0x1000BA98,0x40` tipped rk915 into a permanent
|
||||
`rx_thread: error datalen: 0` flood. **Do not `rmmod rk915` during that flood** —
|
||||
it deadlocks the kernel and costs a physical power cycle. Silence the console
|
||||
with `dmesg -n 1` first, then unbind/bind.
|
||||
|
||||
### Also refuted (2026-09-10)
|
||||
|
||||
**`fw_priv` params are not the difference.** The vendor's `fw_priv_init()`
|
||||
(`src/rpu_if.c:943`) fills in only `production_test`, `fw_skip_rx_pkt_submit`,
|
||||
`wlan_mac_addr` and `p2p_mac_addr`; it leaves `params` zeroed, exactly as we do.
|
||||
The values `fw_params` prints are firmware defaults, read back live via
|
||||
FW_GET_PARAMS(9) — not something the driver pushes.
|
||||
|
||||
**`dis_wifi_isr_thd` does not gate RX.** Set to 1 on the working vendor
|
||||
mid-association: frames kept arriving at full rate and the link stayed up.
|
||||
|
||||
**Firmware logging does not exist to be enabled.** Reading `$D/fw_log` issues
|
||||
DUMP_FW_LOG(4), and it returns empty on the *working* vendor even at
|
||||
`debug_level=3` with `debug_flag=0xf`. This retires a long-standing "next lead".
|
||||
@@ -25,6 +25,9 @@
|
||||
#define SDIO_VENDOR_ID_SSV_ALT 0x0296
|
||||
#define SDIO_DEVICE_ID_SV6160_ALT 0x5348
|
||||
|
||||
/* RESET.system_rev, matching the vendor's hardcoded "GMI" byte for byte. */
|
||||
#define SV6160_VENDOR_SYSTEM_REV 0x494D47
|
||||
|
||||
/* Firmware file names */
|
||||
#define SV6160_FW_NAME "ssv6160-fw.bin"
|
||||
#define SV6160_PATCH_NAME "ssv6160-patch.bin"
|
||||
@@ -76,7 +79,27 @@ enum sv6160_fw_state {
|
||||
#define SV6160_NUM_CHANNELS 14
|
||||
#define SV6160_MAX_SCAN_CHANNELS 50
|
||||
#define SV6160_RF_PARAMS_SIZE 369
|
||||
#define SV6160_MAX_RX_SIZE 4096
|
||||
/* Largest single RX read the firmware can ask us to perform.
|
||||
*
|
||||
* This is the vendor's MAX_RX_SERIAS_BYTES verbatim:
|
||||
* MAX_RX_SERIAS_COUNT(16) * MAX_DATA_SIZE_2K(2048) + 512 = 33280
|
||||
* (rk915 inc/if_io.h:22-23, allocated once in init.c:145 and passed to
|
||||
* rk915_serias_read() as max_len). One "packet" in the chain is really an
|
||||
* aggregate of up to 16 sub-frames, so it is NOT bounded by the 2304-byte
|
||||
* 802.11 MTU.
|
||||
*
|
||||
* We had 4096 here, and that single number was the driver's worst bug. Under
|
||||
* real traffic the firmware aggregates more than that and advertises the size
|
||||
* in the previous packet header's upper 16 bits; the chain walk then hit
|
||||
* `rx_next_len > SV6160_MAX_RX_SIZE`, gave up, and left the data queued in the
|
||||
* firmware. The firmware waits for the host to collect it and NEVER ASSERTS
|
||||
* HOST-WAKE AGAIN -- so RX, TX_DONE and command replies all stop together,
|
||||
* permanently, which is what made TX descriptors look like they were leaking.
|
||||
* Captured at the moment of death:
|
||||
* RXLINK d=125 c=0 pktlen=2048 id=0 raw=0x1a000044 next=6656
|
||||
* RXEND d=125 chain_done=0 recvlen=2048 irqs=125
|
||||
* 6656 > 4096, so we dropped it; irqs and drains both stop at 125. */
|
||||
#define SV6160_MAX_RX_SIZE 33280
|
||||
|
||||
/* ===================================================================
|
||||
* Firmware Packet Dispatch Architecture
|
||||
@@ -134,13 +157,35 @@ enum rpu_cmd_tag {
|
||||
RPU_CMD_PS_ECON_CFG = 14,
|
||||
RPU_CMD_VIF_CTRL = 15,
|
||||
RPU_CMD_BA_SESSION_INFO = 18,
|
||||
RPU_CMD_MCST_ADDR_CFG = 19,
|
||||
RPU_CMD_MCST_FLTR_CTRL = 20,
|
||||
RPU_CMD_ROC_CTRL = 22,
|
||||
RPU_CMD_CHANNEL = 23,
|
||||
RPU_CMD_VIF_CFG = 24,
|
||||
RPU_CMD_TXQ_PARAMS = 26,
|
||||
/* Asks for the firmware's MAC/BB counters; the reply would come back as
|
||||
* RPU_EVENT_MAC_STATS, not as a MIB_STAT event, and the payload is a
|
||||
* bare header (rk915 rpu_prog_mib_stats). DO NOT SEND IT: this
|
||||
* firmware answers with RPU_EVENT_FW_ERROR "[27962 F] event
|
||||
* length(184) overflow" and no data, every time. Kept named so the id
|
||||
* is not mistaken for something else on the wire. See
|
||||
* sv6160_get_survey() for the measurement this would have provided. */
|
||||
RPU_CMD_MIB_STATS = 27,
|
||||
RPU_CMD_FW_PRIV_CMD = 42,
|
||||
RPU_CMD_PATCH_FEATURES = 100,
|
||||
};
|
||||
|
||||
/* Firmware transmit-queue numbering (vendor enum UMAC_QUEUE_NUM). NOTE this
|
||||
* runs opposite to mac80211's AC numbering -- see sv6160_tx_queue_map(). */
|
||||
#define SV6160_WLAN_AC_BK 0
|
||||
#define SV6160_WLAN_AC_BE 1
|
||||
#define SV6160_WLAN_AC_VI 2
|
||||
#define SV6160_WLAN_AC_VO 3
|
||||
#define SV6160_WLAN_AC_BCN 4
|
||||
|
||||
/* 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,
|
||||
@@ -167,6 +212,7 @@ enum rpu_event_tag {
|
||||
RPU_EVENT_RESET_COMPLETE = 8,
|
||||
RPU_EVENT_COMMAND_PROC_DONE = 17,
|
||||
RPU_EVENT_CH_PROG_DONE = 18,
|
||||
RPU_EVENT_MAC_STATS = 21, /* never arrives; see RPU_CMD_MIB_STATS */
|
||||
RPU_EVENT_ROC_STATUS = 24,
|
||||
RPU_EVENT_FW_ERROR = 25,
|
||||
RPU_EVENT_CALIBRATION_DONE = 28,
|
||||
@@ -186,12 +232,19 @@ enum rpu_event_tag {
|
||||
|
||||
/* Rate flags */
|
||||
#define ENABLE_11N_FORMAT 0x08
|
||||
#define MARK_RATE_AS_MCS 0x80
|
||||
#define ENABLE_SGI 0x04
|
||||
|
||||
/* Power save modes */
|
||||
#define PS_MODE_DISABLED 0
|
||||
#define PS_MODE_ENABLED 1
|
||||
#define PS_MODE_DEEP 2
|
||||
/* cmd_tx_ctrl rate-block encodings (vendor host_rpu_if.h) */
|
||||
#define MARK_RATE_AS_RATE 0x00
|
||||
#define USE_PROTECTION_NONE 0
|
||||
#define USE_PROTECTION_RTS 1
|
||||
#define USE_PROTECTION_CTS2SELF 2
|
||||
#define USE_SHORT_PREAMBLE 0
|
||||
#define DONT_USE_SHORT_PREAMBLE 1
|
||||
#define AMPDU_AGGR_DISABLED 0
|
||||
#define AMPDU_AGGR_ENABLED 1
|
||||
#define SV6160_MAX_TX_RATES 4
|
||||
#define MARK_RATE_AS_MCS 0x80
|
||||
|
||||
/* VIF control operations */
|
||||
#define VIF_ADD 1
|
||||
@@ -220,8 +273,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
|
||||
@@ -258,7 +321,14 @@ struct rpu_cmd_reset {
|
||||
__le32 unused2;
|
||||
u8 rf_params[SV6160_RF_PARAMS_SIZE];
|
||||
__le32 unused3;
|
||||
u8 bg_scan[48]; /* bgscan_params placeholder */
|
||||
/* struct bgscan_params: enabled(4) + channel_list[50] +
|
||||
* channel_flags[50] + scan_intval(4) + channel_dur(4) +
|
||||
* serv_channel_dur(4) + num_channels(4) = 120 bytes (packed).
|
||||
* This MUST be 120, not 48 — an undersized placeholder shifts every
|
||||
* field below (num_spatial_streams, antenna_sel, ...) to the wrong
|
||||
* offset, so the firmware reads garbage for antenna_sel/streams and
|
||||
* the radio comes up misconfigured (deaf receiver). */
|
||||
u8 bg_scan[120];
|
||||
u8 num_spatial_streams;
|
||||
__le32 system_rev;
|
||||
__le32 lmac_mode;
|
||||
@@ -266,7 +336,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 {
|
||||
@@ -341,43 +415,245 @@ struct rpu_cmd_vif_cfg {
|
||||
* +0x42: pad (2 bytes)
|
||||
* +0x44: prod_test
|
||||
*/
|
||||
struct rpu_fw_priv_cmd {
|
||||
struct rpu_msg_hdr hdr; /* 0x00-0x1B (28 bytes) */
|
||||
__le32 sub_cmd; /* 0x1C */
|
||||
u8 reserved[24]; /* 0x20-0x37 — firmware expects gap here */
|
||||
__le32 config_bitmap; /* 0x38 — bit3=sleep, bit4=PS, bit5=rate */
|
||||
u8 mac_addr[6]; /* 0x3C */
|
||||
u8 pad[2]; /* 0x42 */
|
||||
__le32 prod_test; /* 0x44 */
|
||||
/* Verified against the firmware's HOST_CMD handler and the vendor's
|
||||
* fw_priv_cmd: hdr(28), type@28, fw_reg_info@32 (reg,val,len,rw),
|
||||
* production_test@48, fw_skip_rx_pkt_submit@52, params_mask@56,
|
||||
* params[6]@60, sniffer@66, wlan_mac_addr@70, p2p_mac_addr@71 = 72B.
|
||||
*
|
||||
* NOTE offset 52 (fw_skip_rx_pkt_submit) is the word the firmware stores into
|
||||
* 0x100064E4 at 0x020099c4 -- its RX kill switch. Set to 1 and EVERY received
|
||||
* frame is freed instead of delivered. Keep it 0. */
|
||||
struct sv6160_fw_priv_cmd {
|
||||
struct rpu_msg_hdr hdr;
|
||||
__le32 type;
|
||||
__le32 reg_info[4]; /* fw_reg_info: reg, val, len, rw */
|
||||
__le32 production_test;
|
||||
__le32 fw_skip_rx_pkt_submit;
|
||||
__le32 params_mask;
|
||||
u8 params[6];
|
||||
__le32 sniffer;
|
||||
u8 wlan_mac_addr;
|
||||
u8 p2p_mac_addr;
|
||||
} __packed;
|
||||
|
||||
/* HOST_CMD (0x2A) sub-commands, vendor enum fw_priv_cmd_type
|
||||
* (rk915 shared/host_rpu_if.h:530). The whole list is here because most of
|
||||
* these ask the firmware to describe its own state, which is the only source
|
||||
* of truth we have for what the LMAC thinks it is doing. */
|
||||
#define FW_PRIV_DUMP_TXRX_COUNT_INFO 1
|
||||
#define FW_PRIV_DUMP_TXRX_BUF_INFO 2
|
||||
#define FW_PRIV_DUMP_REG_INFO 3
|
||||
#define FW_PRIV_DUMP_FW_LOG 4
|
||||
#define FW_PRIV_DUMP_TXRX_QUEUE_INFO 5
|
||||
#define FW_PRIV_INIT_CMD 6
|
||||
#define FW_PRIV_DUMP_FW_VERSION 7
|
||||
#define FW_PRIV_SET_PARAMS 8
|
||||
#define FW_PRIV_GET_PARAMS 9
|
||||
#define FW_PRIV_DUMP_MEM_INFO 10
|
||||
#define FW_PRIV_DUMP_IF_INFO 11
|
||||
|
||||
/* All fw-priv replies arrive as event 28 carrying dump_info{size,end,data[]}
|
||||
* (rk915 shared/host_rpu_if.h:1377). Most sub-commands put a plain text
|
||||
* report in data[]; DUMP_TXRX_COUNT_INFO and DUMP_IF_INFO put the two structs
|
||||
* below there instead. */
|
||||
|
||||
/* rk915 src/procfs.c:400 -- firmware tick unit is 25ns. */
|
||||
struct sv6160_fw_time_info {
|
||||
__le32 count;
|
||||
__le32 max_time;
|
||||
__le64 total_time;
|
||||
} __packed;
|
||||
|
||||
/* rk915 src/procfs.c:431. Only the head of the struct is decoded; the tail
|
||||
* (per-path timing, filter counts) is left to the hex dump. */
|
||||
struct sv6160_fw_txrx_count {
|
||||
__le32 cmd_tx_send;
|
||||
__le32 cmd_send;
|
||||
__le32 event_recv;
|
||||
__le32 event_rx_recv;
|
||||
__le32 event_rx_pkt_recv;
|
||||
__le32 event_rx_pkt_crc_ok;
|
||||
__le32 event_rx_pkt_crc_err;
|
||||
__le32 event_tx_done_recv;
|
||||
__le32 event_rx_serias;
|
||||
__le16 err_desc_id_lmac;
|
||||
__le16 err_desc_id_host;
|
||||
__le16 lpw_hang;
|
||||
__le16 lpw_hang_cnt;
|
||||
__le16 cmd_cnt_dur_lpw_hang;
|
||||
__le16 cmd_txcnt_dur_lpw_hang;
|
||||
__le16 cmd_rxcnt_dur_lpw_hang;
|
||||
struct sv6160_fw_time_info wifi_isr_info;
|
||||
struct sv6160_fw_time_info sdio_isr_info[4];
|
||||
struct sv6160_fw_time_info cmd_send_info;
|
||||
__le32 cmd_id;
|
||||
__le64 total_tick;
|
||||
struct sv6160_fw_time_info rx_notify;
|
||||
struct sv6160_fw_time_info rx_begin;
|
||||
struct sv6160_fw_time_info rx_end;
|
||||
struct sv6160_fw_time_info rx_interval;
|
||||
__le32 lpw_rx_q_min;
|
||||
__le16 wifi_int_disabled;
|
||||
} __packed;
|
||||
|
||||
/* rk915 src/procfs.c:406/419. MAX_IF is 2. */
|
||||
#define SV6160_FW_MAX_IF 2
|
||||
struct sv6160_fw_vif_info {
|
||||
__le32 if_ctrl; /* IF_ADD == 1 */
|
||||
__le32 if_idx;
|
||||
__le32 if_mode; /* IF_MODE_STA_BSS == 0 */
|
||||
__le32 if_conn_sta; /* STA_CONN == 0 */
|
||||
u8 if_addr[6];
|
||||
u8 bssid[6];
|
||||
__le32 key_ctrl; /* KEY_CTRL_ADD == 0 */
|
||||
__le32 key_type;
|
||||
} __packed;
|
||||
|
||||
struct sv6160_fw_if_info {
|
||||
__le32 num;
|
||||
struct sv6160_fw_vif_info vif_info[SV6160_FW_MAX_IF];
|
||||
} __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;
|
||||
|
||||
/* Multicast address programming / filter control. The vendor sends these
|
||||
* from prepare_multicast()/configure_filter() (rk915 src/umac_if.c:925,980);
|
||||
* we sent neither, so the LMAC's multicast filter was left at whatever the
|
||||
* firmware defaults to with an empty address list. Note the vendor sends an
|
||||
* explicit MCAST_FILTER_DISABLE whenever the list is empty. */
|
||||
#define WLAN_MCAST_ADDR_ADD 0
|
||||
#define WLAN_MCAST_ADDR_REM 1
|
||||
#define MCAST_FILTER_DISABLE 0
|
||||
#define MCAST_FILTER_ENABLE 1
|
||||
/* Vendor MCST_ADDR_LIMIT; above this it disables filtering instead. */
|
||||
#define SV6160_MCST_ADDR_LIMIT 8
|
||||
|
||||
/* Matches the firmware's struct cmd_mcst_addr_cfg = 38B (wire 40). */
|
||||
struct rpu_cmd_mcst_addr_cfg {
|
||||
struct rpu_msg_hdr hdr;
|
||||
__le32 op;
|
||||
u8 mac_addr[6];
|
||||
} __packed;
|
||||
|
||||
/* Matches the firmware's struct cmd_mcst_filter_ctrl = 32B. */
|
||||
struct rpu_cmd_mcst_filter_ctrl {
|
||||
struct rpu_msg_hdr hdr;
|
||||
__le32 ctrl;
|
||||
} __packed;
|
||||
|
||||
/* Matches the firmware's struct cmd_ps EXACTLY = 36B. The old layout
|
||||
* (ps_mode/idle_timeout_ms/listen_interval, 40B) was shifted by one field:
|
||||
* the firmware read our mode as if_index and our idle_timeout as the PS mode.
|
||||
* Note the vendor never sends this command at all (its rpu_prog_ps_state is a
|
||||
* stub), so this command is never sent and the struct is unused — kept
|
||||
* correct so re-enabling it is not a landmine. Power save is done entirely
|
||||
* with the PM bit in outgoing frames instead; see ps_doze in the softc. */
|
||||
struct rpu_cmd_ps {
|
||||
struct rpu_msg_hdr hdr;
|
||||
__le32 ps_mode;
|
||||
__le32 idle_timeout_ms;
|
||||
__le32 listen_interval;
|
||||
__le32 if_index;
|
||||
__le32 mode;
|
||||
} __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) */
|
||||
#define SV6160_MAX_TX_CMDS 16
|
||||
/* Most frames we will put in one TX descriptor. This is the firmware's own
|
||||
* limit (SV6160_MAX_TX_CMDS); the vendor likewise fills a descriptor with
|
||||
* whatever is queued for that AC up to its max_tx_cmds.
|
||||
*
|
||||
* It was 8, for no better reason than keeping tx_batch[] small, and that was
|
||||
* costing real throughput: uplink scales almost linearly with the batch,
|
||||
* measured over two interleaved rounds at 6 MB per run --
|
||||
* tx_batch=1 0.42 / 0.39 MB/s
|
||||
* tx_batch=2 0.66 / 0.69 MB/s
|
||||
* tx_batch=4 1.07 / 1.08 MB/s
|
||||
* tx_batch=8 1.37 / 1.50 MB/s
|
||||
* -- with no sign of flattening at 8.
|
||||
*
|
||||
* MEASURED CEILING: the firmware honours at most 9 frames per descriptor,
|
||||
* NOT the 16 its own SV6160_MAX_TX_CMDS advertises. Six trials at each value,
|
||||
* on a build where the cap is actually raised:
|
||||
* tx_batch= 8 0/6 stalled, 1.87 MB/s
|
||||
* tx_batch= 9 0/6 stalled, 1.77 MB/s (fills to 7.9 frames/descriptor)
|
||||
* tx_batch=10 6/6 stalled
|
||||
* tx_batch=12 6/6 stalled
|
||||
* tx_batch=16 stalled, and wedged the bus hard enough that recovery failed
|
||||
* A sharp cliff between 9 and 10, not a probability dial: 0/12 below, 12/12
|
||||
* above.
|
||||
*
|
||||
* ★ THE TRAP THAT COST A DAY, AND NEARLY PUT A FALSE RETRACTION IN THIS FILE:
|
||||
* tx_batch is clamped by min3(mod_tx_batch, SV6160_TX_BATCH_MAX, ...), so on a
|
||||
* build with this constant at 8 the parameter ACCEPTS 16, READS BACK 16, and
|
||||
* runs at 8. An attempt to replicate the ceiling on such a build found "no
|
||||
* stalls at 10/12/16" over ~1173 transfers and concluded the ceiling was an
|
||||
* artefact -- when in fact not one of those transfers had left batch 8. The
|
||||
* tell is frames/descriptor in debugfs tx_tokens: param=8 and param=16 both
|
||||
* gave 7.0, while param=2 gave 1.99. ALWAYS verify the cap actually moved
|
||||
* before trusting a tx_batch result.
|
||||
*
|
||||
* ★★ tx_batch>9 IS A RELIABLE REPRODUCER FOR THE LINK-DEATH / SDIO WEDGE, the
|
||||
* open bug that otherwise arrives hours apart with no warning. It produces
|
||||
* the exact signature -- descriptors sent and never completed (tx_frames >
|
||||
* tx_done_events) with tx_resyncs climbing -- and at 16 it escalates to the
|
||||
* full bus wedge: "TX write failed: -16", dwmmc "Busy; trying anyway", mmc2
|
||||
* "Timeout sending command", then every probe failing -16 with no netdev.
|
||||
*
|
||||
* Escalation measured on one of those real wedges:
|
||||
* ieee80211_restart_hw untestable once probe fails (no debugfs); separately
|
||||
* observed NOT clearing a softer wedge, taking it from
|
||||
* 4 to 8 resyncs and 6 to 13 lost descriptors
|
||||
* module reload FAILED -- probe still -16, no interface
|
||||
* SDIO unbind/bind of CLEARED it -- driver probes, associates, healthy
|
||||
* ff380000.mmc
|
||||
* So recovery has to reach the SDIO host, not just the 802.11 stack. Note
|
||||
* sv6160_trigger_recovery already calls mmc_hw_reset (dmesg shows the bus
|
||||
* renegotiating 400kHz->50MHz) and that is NOT enough; only tearing down and
|
||||
* re-creating the dw_mmc host brought it back. tx_resync_giveup escalates to
|
||||
* exactly the path that does not work, which is why it has never helped.
|
||||
*
|
||||
* 9 is worth about 3% over 8 -- 45 paired trials alternating the two every
|
||||
* cycle with no reload between the arms, median 1.873 -> 1.937 MB/s, 9 ahead
|
||||
* in 34 of 45, zero stalls -- but it is the LAST working value, and 10 fails
|
||||
* 6 times out of 6 into a wedge that needs an SDIO unbind/bind. Left at 8:
|
||||
* 3% does not pay for standing on the edge of that cliff. Every array here
|
||||
* scales off this constant (bodies[], batch[], tx_batch[][]; frm_status[] in
|
||||
* the event is already 16), so changing it stays a one-line edit. */
|
||||
/* Window over which repeated bus recoveries are counted. */
|
||||
#define SV6160_RECOVER_WINDOW_MS 60000
|
||||
|
||||
#define SV6160_TX_BATCH_MAX 8
|
||||
/* Most pieces mac80211 may hand us in one (A-)MSDU; we flatten them anyway,
|
||||
* this just bounds the copy. */
|
||||
#define SV6160_TX_MAX_FRAGS 8
|
||||
/* Scratch buffer the TX worker builds a descriptor in. Only the 581-byte
|
||||
* cmd_tx_ctrl goes here -- the frame body is written straight from skb->data in
|
||||
* the second half of the same SDIO transaction -- so this does not need to
|
||||
* track the RX aggregate size, which it used to be sized against. */
|
||||
#define SV6160_TX_CMD_BUF 4096
|
||||
|
||||
/*
|
||||
* TX control header — RPU_CMD_TX (id=7) from gamely BSP cmd_tx_ctrl.
|
||||
@@ -388,9 +664,26 @@ struct rpu_cmd_txq_params {
|
||||
* The old sv6160_cmd_tx_ctrl (44 bytes, pkt_type=0x2C) was incorrect —
|
||||
* HOST_DATA only generates event 32 (SDIO ack), no air TX.
|
||||
*/
|
||||
#define SV6160_TX_CMD_SIZE 512
|
||||
/* sizeof(struct sv6160_cmd_tx_ctrl) — must equal the vendor's
|
||||
* sizeof(struct cmd_tx_ctrl) = 581. Goes on the wire as ALIGN(581,4) = 584,
|
||||
* matching the vendor SDIO trace. Was 512 (the p_frame_ddr_pointer tail was
|
||||
* missing), which put the frame body 72 bytes before where the firmware
|
||||
* looks for it. */
|
||||
#define SV6160_TX_CMD_SIZE 581
|
||||
#define SV6160_MAC_HDR_SIZE 52
|
||||
|
||||
/* cmd_tx_ctrl.encrypt (vendor host_rpu_if.h). ENCRYPT_ENABLE is what tells
|
||||
* the firmware to run CCMP/TKIP over the frame body before it goes on the
|
||||
* air; with ENCRYPT_DISABLE it transmits whatever bytes we handed it. */
|
||||
#define SV6160_ENCRYPT_DISABLE 0
|
||||
#define SV6160_ENCRYPT_ENABLE 1
|
||||
|
||||
/* Layout of cmd_tx_ctrl.per_pkt_crypto_params[pkt][12] */
|
||||
#define SV6160_CRYPTO_SEQ_CTRL_OFFSET 0
|
||||
#define SV6160_CRYPTO_QOS_CTRL_OFFSET 2
|
||||
#define SV6160_CRYPTO_IV_OFFSET 4
|
||||
#define SV6160_CRYPTO_PARAMS_SIZE 12
|
||||
|
||||
struct sv6160_cmd_tx_ctrl {
|
||||
struct rpu_msg_hdr hdr; /* 28 bytes, hdr.id = RPU_CMD_TX */
|
||||
u8 if_index;
|
||||
@@ -417,9 +710,28 @@ struct sv6160_cmd_tx_ctrl {
|
||||
u8 config_mac_header[SV6160_MAC_HDR_SIZE];
|
||||
__le32 frame_ddr_pointer[SV6160_MAX_TX_CMDS];
|
||||
u8 per_pkt_crypto_params[SV6160_MAX_TX_CMDS][12];
|
||||
u8 _pad[0]; /* struct is zero-padded to SV6160_TX_CMD_SIZE */
|
||||
/* Vendor tail: `unsigned int *p_frame_ddr_pointer[MAX_TX_CMDS]`
|
||||
* (host_rpu_if.h) — an array of HOST pointers, so 8 bytes each on a
|
||||
* 64-bit kernel = 128 bytes. They are host-side bookkeeping the
|
||||
* firmware never dereferences, but they are part of the descriptor
|
||||
* that goes on the wire, and their size is what matters: they push
|
||||
* sizeof() to 581, whose ALIGN(,4) = 584 is exactly the descriptor
|
||||
* length seen in the vendor SDIO trace.
|
||||
*
|
||||
* The firmware locates the 802.11 frame body immediately after a
|
||||
* descriptor of THIS size. Omitting these 128 bytes made our
|
||||
* descriptor 512, so the body landed 72 bytes early and the firmware
|
||||
* consumed the whole MAC header plus the start of the auth body as
|
||||
* descriptor tail — frames went out malformed and the AP never ACKed
|
||||
* them (auth TX -> RETRY_LIMIT) even though RX was fine. */
|
||||
__le64 p_frame_ddr_pointer[SV6160_MAX_TX_CMDS];
|
||||
} __packed;
|
||||
|
||||
/* Must match the vendor's sizeof(struct cmd_tx_ctrl) exactly — the firmware
|
||||
* uses this size to find the frame body that follows the descriptor. */
|
||||
static_assert(sizeof(struct sv6160_cmd_tx_ctrl) == 581,
|
||||
"TX descriptor must be 581 bytes to match vendor cmd_tx_ctrl");
|
||||
|
||||
/* Key management constants */
|
||||
#define TOTAL_KEY_LEN 32
|
||||
#define RX_SEQ_SIZE 6
|
||||
@@ -463,6 +775,13 @@ struct rpu_event_tx_done {
|
||||
} __packed;
|
||||
|
||||
/* Block ACK session command */
|
||||
/* TX_POWER.tx_pwr. The vendor asks for 15 dBm on this board; we asked for 20,
|
||||
* which was the single differing byte in that command on the wire. */
|
||||
#define SV6160_DEFAULT_TX_POWER_DBM 15
|
||||
|
||||
#define BLOCK_ACK_SESSION_STOP 0
|
||||
#define BLOCK_ACK_SESSION_START 1
|
||||
|
||||
struct rpu_cmd_ba_session {
|
||||
struct rpu_msg_hdr hdr;
|
||||
__le32 if_index;
|
||||
@@ -538,17 +857,38 @@ struct sv6160_coalescing {
|
||||
* Driver State
|
||||
* =================================================================== */
|
||||
|
||||
/* rk915 shared/descriptors.h: NUM_ACS 5, NUM_TX_DESCS_PER_AC 2,
|
||||
* NUM_SPARE_TX_DESCS 2 -> NUM_TX_DESCS = 12. Valid descriptor ids are 0..11. */
|
||||
#define SV6160_NUM_ACS 5
|
||||
#define SV6160_TX_DESCS_PER_AC 2
|
||||
#define SV6160_NUM_SPARE_TX_DESCS 2
|
||||
/* How long a descriptor may sit in flight before the watchdog takes it back.
|
||||
* Long enough that a slow but genuine completion is never stolen (the measured
|
||||
* worst TX_DONE latency is a few ms), short enough that a lost one costs a
|
||||
* hiccup rather than the access category. */
|
||||
#define SV6160_TX_DONE_TIMEOUT_MS 1000
|
||||
|
||||
#define SV6160_NUM_TX_DESCS \
|
||||
((SV6160_NUM_ACS * SV6160_TX_DESCS_PER_AC) + SV6160_NUM_SPARE_TX_DESCS)
|
||||
|
||||
struct sv6160_softc {
|
||||
struct sdio_func *func;
|
||||
struct ieee80211_hw *hw;
|
||||
struct device *dev;
|
||||
struct mutex lock;
|
||||
/* Task holding sc->lock through sv6160_lock()/the RX drain. A path
|
||||
* reached from inside the drain (either entry: IRQ thread or rx_work)
|
||||
* compares against current and skips the mutex instead of deadlocking
|
||||
* on it -- the old current_work() test was NULL in the IRQ thread. */
|
||||
struct task_struct *lock_owner;
|
||||
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;
|
||||
struct sv6160_coalescing coalescing;
|
||||
struct workqueue_struct *wq;
|
||||
|
||||
@@ -557,7 +897,219 @@ struct sv6160_softc {
|
||||
struct completion chan_prog_done;
|
||||
struct completion cmd_done;
|
||||
int vif_index;
|
||||
u32 tx_desc_id;
|
||||
/* TX descriptor ids are TOKENS from a small fixed pool, not a counter.
|
||||
* The firmware's table is NUM_TX_DESCS entries and it rejects anything
|
||||
* outside it -- literally, in an FW_ERROR event: "[3243 F] Invalid desc
|
||||
* id". A free-running counter therefore faults the firmware the moment
|
||||
* it passes the end of the table, which is why TX completions stopped
|
||||
* after ~11 frames. Mirrors rk915 get_token()/free_token(). */
|
||||
/* Chain pointer carried by the LAST sub-packet of an RX_SERIAS batch.
|
||||
* The vendor clears the IRQ and rings the notify doorbell only when this
|
||||
* is zero; a non-zero value means more data is queued and must be read
|
||||
* first (hal_io.c rk915_serias_read, "End of the continuous rx 1"). */
|
||||
u32 serias_next_len;
|
||||
/* RX pipeline accounting (debugfs "rx_stats"). Bulk throughput sits at
|
||||
* a few KB/s while ping is fine, so what matters is how often the
|
||||
* firmware wakes us and how much each wake actually yields. */
|
||||
u32 rxs_drains; /* host-wakes serviced */
|
||||
u32 rxs_pkts; /* packets handed to mac80211 */
|
||||
u32 rxs_nodata; /* wake with no valid RECV_LEN */
|
||||
u32 rxs_chained; /* reads beyond the first */
|
||||
u32 rxs_gap_max_ms;
|
||||
/* Where a drain's time actually goes: waiting for sc->lock (i.e. behind
|
||||
* a TX/command CMD53) versus doing the SDIO reads. Separates "the
|
||||
* firmware is not signalling" from "we are too slow to come back". */
|
||||
u64 rxs_lock_us_sum;
|
||||
u32 rxs_lock_us_max;
|
||||
u64 rxs_busy_us_sum;
|
||||
u32 rxs_busy_us_max;
|
||||
/* Same question on the TX side: how long a frame spends in the write
|
||||
* path, and how often the card pushes back with -EBUSY (each retry
|
||||
* sleeps 20-25ms, so a handful of them stalls TCP outright). */
|
||||
u32 txs_frames;
|
||||
/* Frames the worker dequeued and tried to send, whether or not the
|
||||
* SDIO write happened -- txs_frames only counts writes that ran. */
|
||||
u32 txs_attempts;
|
||||
u32 tx_max_frame_seen;
|
||||
u32 txs_linearise_fail;
|
||||
u32 txs_txq_pulled;
|
||||
u64 txs_us_sum;
|
||||
u32 txs_us_max;
|
||||
u32 txs_ebusy;
|
||||
/* Where the 7.4 ms of an average sv6160_sdio_write_tx() actually goes:
|
||||
* waiting for sc->lock, waiting for the SDIO host, the descriptor
|
||||
* CMD53, and the frame-body CMD53s. */
|
||||
u64 txs_mutex_us_sum;
|
||||
u64 txs_claim_us_sum;
|
||||
u64 txs_desc_us_sum;
|
||||
u64 txs_body_us_sum;
|
||||
u64 txs_body_bytes;
|
||||
/* DMA eligibility of what we hand the SDIO core. dw_mmc refuses DMA
|
||||
* for a transfer whose scatterlist offset or length is not 4-byte
|
||||
* aligned (dw_mci_pre_dma_transfer: "if (sg->offset & 3 ||
|
||||
* sg->length & 3) return -EINVAL") and silently falls back to PIO,
|
||||
* and sg->offset is just offset_in_page() of the buffer we pass.
|
||||
* Counted because the uplink flips between a ~6 B/us and a ~1 B/us
|
||||
* write regime with identical bus settings, and PIO fallback is the
|
||||
* one host-side thing that produces exactly that ratio. */
|
||||
u32 txs_body_pio; /* body writes dw_mmc must PIO */
|
||||
u32 txs_desc_pio; /* descriptor writes ditto */
|
||||
/* Which descriptors the stall resync had to take back, so "the firmware
|
||||
* stopped completing" can be asked the obvious next questions: is it
|
||||
* always the same descriptor id, always the same AC, and how long had it
|
||||
* been outstanding? Per-id because a pattern only shows across many
|
||||
* stalls, and they are hours apart. */
|
||||
/* Deadline (jiffies) before which a descriptor id must NOT be handed out
|
||||
* again, or 0 when it is free. Set when a stall resync takes an id back
|
||||
* WITHOUT the firmware having completed it: the firmware still owns it
|
||||
* then, and reusing it immediately is what turned one stall into a
|
||||
* storm (see sv6160_get_token). */
|
||||
unsigned long tx_quarantine[SV6160_NUM_TX_DESCS];
|
||||
u32 txs_quarantined; /* ids held back */
|
||||
u32 txs_quarantine_hits; /* allocations deflected */
|
||||
u32 txs_quarantine_freed; /* released by a late completion */
|
||||
/* How late a completion for a reclaimed descriptor actually was, measured
|
||||
* from the moment the resync gave up on it. This is what says whether
|
||||
* tx_stall_ms is set too short: if these are all a few hundred ms, the
|
||||
* window is simply too tight and the "stall" is mostly our own timeout. */
|
||||
u32 txs_latecomp_max_ms;
|
||||
u64 txs_latecomp_sum_ms;
|
||||
u32 txs_latecomp_n;
|
||||
u32 txs_lost_desc[SV6160_NUM_TX_DESCS];
|
||||
u32 txs_lost_ac[SV6160_NUM_ACS];
|
||||
u32 txs_resync_age_max; /* ms, oldest ever lost */
|
||||
/* Rate asked for vs rate the firmware reports using. */
|
||||
u32 txs_ask_mcs[16];
|
||||
u32 txs_ask_legacy;
|
||||
u32 txs_use_mcs[16];
|
||||
u32 txs_use_legacy;
|
||||
u32 txs_use_none;
|
||||
u32 txs_rate_match;
|
||||
u32 txs_rate_nomatch;
|
||||
/* Times the worker stopped ALL mac80211 queues because one AC had no
|
||||
* descriptor left, and which AC caused it. */
|
||||
u32 txs_qstop;
|
||||
u32 txs_qstop_ac[SV6160_NUM_ACS];
|
||||
/* How long a genuine TX_DONE takes, and how many arrive for a descriptor
|
||||
* the watchdog already took back. If completions normally land in a few
|
||||
* ms and "late" stays 0, the watchdog is only catching real losses; if
|
||||
* late climbs, its timeout is stealing frames still in flight. */
|
||||
u32 txs_done_ms_max;
|
||||
u64 txs_done_ms_sum;
|
||||
u32 txs_done_n;
|
||||
u32 txs_late;
|
||||
/* Does a TX_DONE actually arrive for every frame? Count the events and
|
||||
* the entries our slot/desc_id matching throws away, so "the firmware
|
||||
* never completed it" can be told apart from "we discarded it". */
|
||||
u32 txs_done_events;
|
||||
u32 txs_done_entries;
|
||||
u32 txs_skip_noskb;
|
||||
u32 txs_skip_descmiss;
|
||||
/* Per-descriptor-id ledger, to settle the burst leak. A descriptor
|
||||
* that is stuck in flight shows up as sent[id] > done[id]; seen[id]
|
||||
* says whether the firmware ever sent a TX_DONE naming that id, which
|
||||
* is what separates "no completion ever came back" from "one came back
|
||||
* and the handler failed to match it". */
|
||||
u32 txs_sent_desc[SV6160_NUM_TX_DESCS];
|
||||
u32 txs_seen_desc[SV6160_NUM_TX_DESCS];
|
||||
u32 txs_done_desc[SV6160_NUM_TX_DESCS];
|
||||
/* When each descriptor went out, so a completion that never arrives can
|
||||
* be reclaimed instead of costing that AC a slot for ever. */
|
||||
unsigned long tx_desc_jiffies[SV6160_NUM_TX_DESCS];
|
||||
struct delayed_work tx_resync;
|
||||
/* When a TX completion last arrived, so a pipe that has gone entirely
|
||||
* silent can be told from one that is merely slow. */
|
||||
unsigned long last_tx_done;
|
||||
u32 txs_resyncs;
|
||||
u32 txs_resync_descs;
|
||||
/* Consecutive resyncs with no completion in between; reset by any real
|
||||
* TX_DONE and by losing the association. */
|
||||
u32 txs_resync_runs;
|
||||
u64 rxs_gap_sum_ms;
|
||||
unsigned long rxs_last_jiffies;
|
||||
unsigned long tx_token_bmp;
|
||||
/* Per-AC in-flight descriptor count, and the AC each token was taken
|
||||
* for (spare tokens are not AC-derivable from the id alone). */
|
||||
u8 tx_outstanding_ac[SV6160_NUM_ACS];
|
||||
u8 tx_token_ac[SV6160_NUM_TX_DESCS];
|
||||
/* Guards tx_token_bmp / tx_token_ac / tx_outstanding_ac / tx_quarantine.
|
||||
* get_token runs in the TX worker, free_token from the IRQ-thread drain
|
||||
* and the resync work, and a lost ++/-- on a per-AC count is permanent:
|
||||
* the AC either sits at its limit with nothing in flight (get_token
|
||||
* refuses it for good) or admits more than the firmware tolerates. */
|
||||
spinlock_t tx_token_lock;
|
||||
/* Set by the worker just before it publishes a descriptor, cleared when
|
||||
* sv6160_sdio_write_tx() returns. A reclaim path that sees it leaves
|
||||
* that descriptor alone: the CMD53 is still reading those skbs. */
|
||||
bool tx_writing[SV6160_NUM_TX_DESCS];
|
||||
u32 txs_bulk_done; /* event-32 bulk completions seen */
|
||||
|
||||
/* Control-command flow control, mirroring the vendor's rpu_send()
|
||||
* (rk915 src/rpu_if.c:755): never put more than
|
||||
* SV6160_MAX_OUTSTANDING_CTRL_REQ control commands on the bus at once.
|
||||
* Further commands queue on cmd_pending and are released as
|
||||
* RPU_EVENT_COMMAND_PROC_DONE retires the earlier ones. Without this
|
||||
* we wrote every command immediately, so a command could land while
|
||||
* the LMAC was still busy with the previous one. */
|
||||
#define SV6160_MAX_OUTSTANDING_CTRL_REQ 2
|
||||
spinlock_t cmd_gate_lock;
|
||||
unsigned int cmd_inflight;
|
||||
struct sk_buff_head cmd_pending;
|
||||
unsigned long cmd_sent_jiffies;
|
||||
u32 cmd_proc_done_count;
|
||||
u32 cmd_gate_queued;
|
||||
u32 cmd_gate_stalls;
|
||||
/* Times a command send cancelled a merely-QUEUED RX drain. The wake
|
||||
* itself survives (gpio_irq_pending is a latch and the host-wake IRQ
|
||||
* is level-triggered) -- see __sv6160_rpu_write_cmd. Kept as the
|
||||
* tripwire for that window, which has never been observed to open. */
|
||||
u32 cmds_rx_cancelled;
|
||||
/* Per-event-id census: how many arrived and in what size range. */
|
||||
#define SV6160_EV_CENSUS_MAX 48
|
||||
u32 evs_count[SV6160_EV_CENSUS_MAX];
|
||||
u16 evs_minlen[SV6160_EV_CENSUS_MAX];
|
||||
u16 evs_maxlen[SV6160_EV_CENSUS_MAX];
|
||||
u32 evs_out_of_range;
|
||||
u32 txs_done_short;
|
||||
u16 txs_done_short_len;
|
||||
#define SV6160_CMD_CENSUS_MAX 112
|
||||
/* Sequence numbers for the ordered trace (mod_trace). */
|
||||
#define SV6160_TRACE_EVENTS 260
|
||||
#define SV6160_TRACE_CMDS 120
|
||||
#define SV6160_TRACE_TX 80
|
||||
#define SV6160_TRACE_DRAINS 200
|
||||
u32 rxs_oversize;
|
||||
u32 rxs_nomem;
|
||||
/* One persistent RX aggregate buffer, like the vendor's
|
||||
* rx_serias_buf: every chain read lands here, so no SDIO read ever
|
||||
* depends on an allocation succeeding. */
|
||||
u8 *rx_buf;
|
||||
u32 evs_seq;
|
||||
u32 cmds_seq;
|
||||
u32 txs_trace_seq;
|
||||
u32 rxs_trace_seq;
|
||||
int trace_gen;
|
||||
u32 cmds_by_id[SV6160_CMD_CENSUS_MAX];
|
||||
u32 cmds_out_of_range;
|
||||
|
||||
/* Multicast addresses currently programmed into the LMAC, so they can
|
||||
* be removed again on the next prepare_multicast (vendor mc_filters). */
|
||||
u8 mc_filters[SV6160_MCST_ADDR_LIMIT][6];
|
||||
int mc_filter_count;
|
||||
u32 mc_filter_mode; /* 0xFF = unset */
|
||||
u32 use_short_slot; /* real ERP slot value */
|
||||
/* Snapshot taken by the atomic .prepare_multicast, applied later by
|
||||
* .configure_filter where sleeping is allowed. */
|
||||
u8 mc_pending[SV6160_MCST_ADDR_LIMIT][6];
|
||||
int mc_pending_count;
|
||||
bool mc_pending_valid;
|
||||
struct delayed_work cmd_gate_work;
|
||||
struct delayed_work fwpeek_work;
|
||||
/* Sub-command of the fw-priv request currently in flight. The reply
|
||||
* (event 28) carries no type field, so the decoder has to be told what
|
||||
* was asked for. Only the fwpeek worker issues these, one at a time
|
||||
* with a sleep in between, so a plain field is enough. */
|
||||
u32 fw_info_type;
|
||||
|
||||
/* TX deferred work (mac_tx runs in softirq, SDIO needs process ctx) */
|
||||
struct sk_buff_head tx_queue;
|
||||
@@ -566,38 +1118,110 @@ struct sv6160_softc {
|
||||
/* TX completion tracking */
|
||||
#define SV6160_TX_PENDING_MAX 64
|
||||
struct sk_buff *tx_pending[SV6160_TX_PENDING_MAX];
|
||||
/* Frames 1..n-1 of a batched descriptor. Frame 0 stays in
|
||||
* tx_pending[] and remains the single ownership token that TX_DONE and
|
||||
* the stall resync race for with cmpxchg; whoever claims it owns these
|
||||
* too, so the batching needs no new locking. */
|
||||
struct sk_buff *tx_batch[SV6160_NUM_TX_DESCS][SV6160_TX_BATCH_MAX - 1];
|
||||
u8 tx_batch_n[SV6160_NUM_TX_DESCS];
|
||||
u32 tx_pending_desc[SV6160_TX_PENDING_MAX]; /* desc_id owning each slot (verify on completion) */
|
||||
atomic_t tx_outstanding;
|
||||
|
||||
/* Power management */
|
||||
bool is_suspended;
|
||||
bool ps_enabled;
|
||||
struct delayed_work idle_work;
|
||||
unsigned long last_activity;
|
||||
|
||||
/* DW MMC controller registers (for debug diagnostics) */
|
||||
void __iomem *dwmmc_regs;
|
||||
/* Power save. There is no firmware command for it: the vendor's
|
||||
* rpu_prog_ps_state() is a bare `return 0;` and its whole session SDIO
|
||||
* trace contains no RPU_CMD_PS. The entire mechanism is the PM bit in
|
||||
* outgoing frames -- the AP then buffers for us and the chip can doze
|
||||
* between DTIMs. mac80211 drives the state through IEEE80211_CONF_PS
|
||||
* once we advertise IEEE80211_HW_SUPPORTS_PS, and only ever enables it
|
||||
* if userspace asks for it (`iw dev X set power_save on`). */
|
||||
bool ps_doze;
|
||||
u32 ps_pm_frames; /* frames sent with PM set */
|
||||
u32 ps_transitions; /* awake <-> doze changes */
|
||||
/* TX retry accounting. The firmware reports a per-frame retry count in
|
||||
* TX_DONE; aggregating it says whether slow uplink is airtime (retries)
|
||||
* or the SDIO write path. */
|
||||
u32 txs_retry_hist[8];
|
||||
u64 txs_retry_sum;
|
||||
u64 txs_retry_n;
|
||||
u32 txs_tx_failed; /* frm_status != SUCCESS */
|
||||
|
||||
/* GPIO interrupt */
|
||||
int host_wake_irq;
|
||||
bool gpio_irq_pending; /* GPIO fired, data ready */
|
||||
bool gpio_irq_disabled; /* level IRQ disabled by handler */
|
||||
u32 gpio_irq_count; /* total GPIO IRQs received */
|
||||
|
||||
/* debugfs */
|
||||
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 */
|
||||
/* After an RX_SERIAS batch the firmware re-presents the batch's FIRST
|
||||
* sub-packet length on a later lone host-wake, with no data behind it.
|
||||
* Measured twice: a 352B batch of (204,28,28,28) was followed ~690ms
|
||||
* later by a wake advertising 204, and a 1024B batch of (408,28,28,28)
|
||||
* by one advertising 408. Reading the absent bytes times out and wedges
|
||||
* the bus. last_recv_len cannot catch this -- it holds the aggregate,
|
||||
* not the sub-packet -- so remember the one length that actually gets
|
||||
* re-presented. */
|
||||
|
||||
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;
|
||||
/* Rolling window used to tell "one bad moment" from "restart_hw is not
|
||||
* fixing this" -- see sv6160_trigger_recovery. */
|
||||
unsigned long recover_window;
|
||||
u32 recover_count;
|
||||
|
||||
/* mac80211 state */
|
||||
struct ieee80211_vif *vif;
|
||||
/* Copy of vif->addr, taken in .add_interface while the VIF is alive.
|
||||
* VIF_CFG is also sent from paths that run during VIF teardown, where
|
||||
* dereferencing sc->vif rebooted the board; and wiphy->perm_addr is NOT
|
||||
* this address -- NetworkManager randomises the MAC per connection, so
|
||||
* perm_addr differs from the address actually on the air on every run. */
|
||||
u8 vif_addr[ETH_ALEN];
|
||||
/* BSSID the group key was filed under, kept because mac80211 clears
|
||||
* bss_conf.bssid before deleting the keys on a disconnect. */
|
||||
u8 key_bssid[ETH_ALEN];
|
||||
/* 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;
|
||||
u32 rx_filter;
|
||||
bool connecting; /* AP picked, not yet associated */
|
||||
u8 bcn_rcv_mode; /* last RCV_* beacon mode sent (0xFF=unset) */
|
||||
u8 cur_channel; /* last channel programmed (for VIF op_channel) */
|
||||
struct ieee80211_scan_request *scan_request;
|
||||
bool scan_in_progress;
|
||||
bool operating; /* a BSSID is programmed (connecting/associated) — hold the operating channel, don't sweep off it */
|
||||
bool assoc; /* association completed (STA_CONN sent) */
|
||||
int scan_ch_idx; /* current channel in sweep */
|
||||
struct delayed_work scan_work; /* channel-sweep scan worker */
|
||||
struct delayed_work scan_timeout;
|
||||
@@ -623,6 +1247,9 @@ 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,
|
||||
u8 *bounce,
|
||||
struct sk_buff **bodies, int n_bodies);
|
||||
int sv6160_sdio_read_data(struct sv6160_softc *sc, u32 addr,
|
||||
void *buf, size_t len);
|
||||
|
||||
@@ -631,11 +1258,10 @@ 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);
|
||||
int sv6160_rpu_ps_config(struct sv6160_softc *sc, int mode,
|
||||
u32 idle_timeout, u32 listen_interval);
|
||||
int sv6160_rpu_add_vif(struct sv6160_softc *sc, const u8 *mac_addr, int mode);
|
||||
int sv6160_rpu_remove_vif(struct sv6160_softc *sc);
|
||||
int sv6160_rpu_scan(struct sv6160_softc *sc,
|
||||
@@ -656,6 +1282,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);
|
||||
@@ -663,11 +1290,17 @@ 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);
|
||||
void sv6160_start_queues(struct sv6160_softc *sc);
|
||||
|
||||
/* Last-resort wedge recovery: ask the driver core to re-create the dw_mmc host
|
||||
* that owns our card. Takes the sdio_func, not the softc, because the wedge
|
||||
* that most needs it is the one where PROBE fails -16 and no softc exists. */
|
||||
bool sv6160_rebind_sdio_host(struct sdio_func *func);
|
||||
|
||||
/* PM Support */
|
||||
void sv6160_notify_pm(struct sv6160_softc *sc, int wakeup);
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,8 +6,11 @@
|
||||
#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>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/platform_device.h>
|
||||
@@ -21,33 +24,31 @@ 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;
|
||||
/* Reset stale guard so same-size events can be read.
|
||||
* BUT if the last read failed (-110), the RECV_LEN is
|
||||
* genuinely stale — don't reset, let the guard block it.
|
||||
* The -110 handler sends clear+notify which deasserts GPIO.
|
||||
* If GPIO re-fires despite recv_len_failed, the firmware
|
||||
* has new data at a different RECV_LEN which will pass
|
||||
* the guard naturally. */
|
||||
if (!sc->recv_len_failed)
|
||||
sc->last_recv_len = 0;
|
||||
schedule_work(&sc->rx_work);
|
||||
/* Nothing to drain into yet (firmware being uploaded, core_init not done)
|
||||
* or the host is on its way into suspend: leave the wake where it is.
|
||||
* The line is level-high and ONESHOT, so returning re-fires this thread
|
||||
* as soon as it is unmasked; the sleep turns that spin into a 1 ms poll
|
||||
* for the few ms either window lasts. Draining while suspended did
|
||||
* CMD53s against a host being clock-gated and set sdio_wedged. */
|
||||
if (!sc || !sc->is_firmware_loaded || sc->is_suspended) {
|
||||
usleep_range(1000, 2000);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
sc->gpio_irq_count++;
|
||||
dev_dbg(&sc->func->dev, "GPIOIRQ #%u\n", sc->gpio_irq_count);
|
||||
sc->gpio_irq_pending = true;
|
||||
sv6160_rx_drain(sc);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
@@ -62,18 +63,19 @@ static void sv6160_sdio_irq_handler(struct sdio_func *func)
|
||||
if (sc && sc->is_firmware_loaded) {
|
||||
sc->gpio_irq_count++; /* reuse counter for diagnostics */
|
||||
sc->gpio_irq_pending = true;
|
||||
if (!sc->recv_len_failed)
|
||||
sc->last_recv_len = 0;
|
||||
/* Do NOT reset last_recv_len — same reasoning as GPIO
|
||||
* handler. Only rpu_send_cmd resets the stale guard
|
||||
* (after sending a command that expects a response). */
|
||||
schedule_work(&sc->rx_work);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
@@ -87,12 +89,29 @@ static int sv6160_sdio_device_init(struct sdio_func *func)
|
||||
if (error)
|
||||
dev_warn(&func->dev, "CCCR IEN write failed: %d\n", error);
|
||||
|
||||
/* Do NOT set CCCR 0x16=0x80 (GPIO mode). Leave the firmware in
|
||||
* its default SDIO in-band interrupt mode (DATA1 line). GPIO IRQ
|
||||
* was observed to fire only during boot (4 edges), never for
|
||||
* command responses or RX data. SDIO in-band interrupts are the
|
||||
* standard mechanism and should work for all event types.
|
||||
* Register sdio_claim_irq() in probe instead. */
|
||||
/* Switch chip to GPIO interrupt mode (gamely BSP requirement).
|
||||
* MUST be set BEFORE firmware boot — the firmware reads this
|
||||
* during init to decide whether to signal via GPIO or SDIO DATA1.
|
||||
* Without this, WiFi RX frame events may never reach the host
|
||||
* even though command responses work via SDIO in-band. */
|
||||
sdio_f0_writeb(func, 0x80, 0x16, &error);
|
||||
if (error)
|
||||
dev_warn(&func->dev, "CCCR 0x16 GPIO mode write failed: %d\n",
|
||||
error);
|
||||
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) */
|
||||
{
|
||||
@@ -122,30 +141,85 @@ static int sv6160_sdio_device_init(struct sdio_func *func)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* PM Suspend/Resume */
|
||||
/*
|
||||
* 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);
|
||||
if (!ret)
|
||||
sc->is_firmware_loaded = true; /* IRQ paths may drain again */
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* PM Suspend/Resume
|
||||
*
|
||||
* These had never executed once before 2026-09-12: ROCKNIX's idle "suspend" is
|
||||
* /usr/bin/rocknix-fake-suspend, which only freezes and thaws processes and
|
||||
* never writes /sys/power/state, so the kernel PM path -- and therefore these
|
||||
* callbacks -- was never entered on this platform. They are logged because
|
||||
* there is otherwise no way to tell whether they ran at all.
|
||||
*/
|
||||
|
||||
static int __maybe_unused sv6160_pm_suspend(struct device *dev)
|
||||
{
|
||||
struct sdio_func *func = dev_to_sdio_func(dev);
|
||||
struct sv6160_softc *sc = sdio_get_drvdata(func);
|
||||
mmc_pm_flag_t flags = MMC_PM_KEEP_POWER;
|
||||
int ret;
|
||||
|
||||
if (!sc || !sc->is_firmware_loaded)
|
||||
return 0;
|
||||
|
||||
dev_info(sc->dev, "PM suspend: started=%d assoc=%d\n",
|
||||
sc->is_started, sc->assoc);
|
||||
sc->is_suspended = true;
|
||||
cancel_delayed_work_sync(&sc->idle_work);
|
||||
cancel_delayed_work_sync(&sc->rx_poll);
|
||||
cancel_work_sync(&sc->rx_work);
|
||||
|
||||
sv6160_stop_queues(sc);
|
||||
sv6160_rpu_ps_config(sc, PS_MODE_ENABLED, 200, 3);
|
||||
sv6160_notify_pm(sc, 0); /* sleep */
|
||||
|
||||
if (device_may_wakeup(dev))
|
||||
flags |= MMC_PM_WAKE_SDIO_IRQ;
|
||||
|
||||
return sdio_set_host_pm_flags(func, flags);
|
||||
ret = sdio_set_host_pm_flags(func, flags);
|
||||
dev_info(sc->dev, "PM suspend: keep_power%s -> %d\n",
|
||||
(flags & MMC_PM_WAKE_SDIO_IRQ) ? "+wake_sdio_irq" : "", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __maybe_unused sv6160_pm_resume(struct device *dev)
|
||||
@@ -156,16 +230,16 @@ static int __maybe_unused sv6160_pm_resume(struct device *dev)
|
||||
if (!sc || !sc->is_firmware_loaded)
|
||||
return 0;
|
||||
|
||||
dev_info(sc->dev, "PM resume: started=%d assoc=%d\n",
|
||||
sc->is_started, sc->assoc);
|
||||
sc->is_suspended = false;
|
||||
sv6160_notify_pm(sc, 1); /* wakeup */
|
||||
sv6160_rpu_ps_config(sc, PS_MODE_DISABLED, 0, 0);
|
||||
sv6160_start_queues(sc);
|
||||
|
||||
sc->last_activity = jiffies;
|
||||
if (sc->is_started) {
|
||||
schedule_work(&sc->rx_work);
|
||||
schedule_delayed_work(&sc->rx_poll, msecs_to_jiffies(10));
|
||||
schedule_delayed_work(&sc->idle_work, msecs_to_jiffies(5000));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -195,6 +269,24 @@ static int sv6160_probe(struct sdio_func *func,
|
||||
}
|
||||
|
||||
sdio_claim_host(func);
|
||||
|
||||
/*
|
||||
* Reset the MCU to the WAIT_FW state before uploading firmware.
|
||||
* On a warm start — a driver reload, or a prior driver (e.g. the
|
||||
* rk915 BSP port) that left the MCU running its firmware — the chip
|
||||
* is well past WAIT_FW, and the very first firmware-upload CMD53 write
|
||||
* to SDIO addr 0 times out (-110) because the running firmware is not
|
||||
* listening for an upload. mmc_hw_reset() re-runs the SDIO pwrseq
|
||||
* (toggles the chip reset GPIO) so the MCU comes up cold. The vendor
|
||||
* rk915 driver does the same in its probe/power-cycle path. Must be
|
||||
* called with the host claimed (it does not self-claim).
|
||||
*/
|
||||
ret = mmc_hw_reset(func->card);
|
||||
if (ret)
|
||||
dev_warn(&func->dev, "mmc_hw_reset failed: %d (continuing)\n", ret);
|
||||
/* the CIS re-parse after reset can leave a bogus 0 ms enable timeout */
|
||||
func->enable_timeout = jiffies_to_msecs(HZ);
|
||||
|
||||
ret = sdio_enable_func(func);
|
||||
if (ret) {
|
||||
dev_err(&func->dev, "sdio_enable_func failed: %d\n", ret);
|
||||
@@ -215,8 +307,43 @@ static int sv6160_probe(struct sdio_func *func,
|
||||
|
||||
/* Full SDIO device initialization (block size, interrupts, etc) */
|
||||
ret = sv6160_sdio_device_init(func);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
/* A bare -110 here is almost always one specific thing, and it
|
||||
* cost an afternoon to pin down: the system went through a real
|
||||
* (deep) suspend while NO driver was bound to this function.
|
||||
* Nothing then requested MMC_PM_KEEP_POWER, and on resume the
|
||||
* mmc2 host is never re-initialised at all -- the resume log
|
||||
* shows bus-speed/tuning lines for the storage host and none
|
||||
* for this one -- so the card is unreachable. The
|
||||
* mmc_hw_reset() above returns success and does not help,
|
||||
* because the problem is the host, not the card. Reloading the
|
||||
* module does not clear it either.
|
||||
*
|
||||
* Recovery is to power-cycle the controller:
|
||||
* echo ff380000.mmc > /sys/bus/platform/drivers/dwmmc_rockchip/unbind
|
||||
* echo ff380000.mmc > /sys/bus/platform/drivers/dwmmc_rockchip/bind
|
||||
* Keeping the driver loaded across suspend avoids it entirely;
|
||||
* that path is tested and works (link and IP survive).
|
||||
*/
|
||||
if (ret == -ETIMEDOUT)
|
||||
dev_err(&func->dev,
|
||||
"SDIO init timed out (-110). If the system suspended with this driver unloaded, the mmc host was not resumed; power-cycle it with unbind/bind on dwmmc_rockchip, or keep the driver loaded across suspend.\n");
|
||||
/* Do NOT try to escalate to sv6160_rebind_sdio_host() here. It
|
||||
* looks like the right place and it cannot work: once the bus is
|
||||
* hard-wedged this probe is never entered at all. sdio_bus_probe()
|
||||
* calls sdio_set_block_size() before drv->probe, that CMD52 fails
|
||||
* -EBUSY, and the core logs "probe with driver sv6160 failed with
|
||||
* error -16" without ever calling us -- verified on hardware, the
|
||||
* failing reloads have no probe entry line in dmesg.
|
||||
*
|
||||
* The driver can only rescue the host while it still HOLDS the
|
||||
* device, so the escalation lives in the bring-up retry path
|
||||
* instead. A driver that has been rmmod'ed on a wedged bus is
|
||||
* already past helping itself; that state needs the unbind/bind
|
||||
* below, by hand. (It is also not something production does --
|
||||
* only a test harness reloads a wedged driver.) */
|
||||
goto err_disable;
|
||||
}
|
||||
|
||||
/* Allocate mac80211 hardware struct */
|
||||
hw = ieee80211_alloc_hw(sizeof(struct sv6160_softc), &sv6160_ops);
|
||||
@@ -231,23 +358,6 @@ static int sv6160_probe(struct sdio_func *func,
|
||||
sc->dev = &func->dev;
|
||||
mutex_init(&sc->lock);
|
||||
|
||||
/* Map the DW MMC controller CTRL register for FIFO/DMA reset.
|
||||
* The SDIO host controller's parent device has the MMIO resource.
|
||||
* DW MMC CTRL register is at offset 0x000 from the controller base. */
|
||||
{
|
||||
struct device *host_dev = func->card->host->parent;
|
||||
struct resource *res;
|
||||
|
||||
res = platform_get_resource(to_platform_device(host_dev), IORESOURCE_MEM, 0);
|
||||
if (res) {
|
||||
sc->dwmmc_regs = devm_ioremap(&func->dev, res->start, 0x100);
|
||||
if (sc->dwmmc_regs)
|
||||
dev_info(&func->dev, "DW MMC regs mapped at %pa\n",
|
||||
&res->start);
|
||||
else
|
||||
dev_warn(&func->dev, "Failed to map DW MMC regs\n");
|
||||
}
|
||||
}
|
||||
|
||||
sdio_set_drvdata(func, sc);
|
||||
|
||||
@@ -278,9 +388,21 @@ 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. No IRQF_NO_SUSPEND: it is documented as
|
||||
* incompatible with the enable_irq_wake() below (suspend-and-
|
||||
* interrupts.rst), and it kept the thread draining a suspended
|
||||
* host. With the wake armed the PM core does NOT mask the line
|
||||
* for the suspend -- suspend_device_irq() takes the
|
||||
* irqd_is_wakeup_set() branch, sets IRQD_WAKEUP_ARMED and returns
|
||||
* before any __disable_irq(). The first assertion after that is
|
||||
* what disables it, marks it pending and aborts the suspend in
|
||||
* progress. The thread also refuses to drain while is_suspended. */
|
||||
ret = devm_request_threaded_irq(&func->dev, sc->host_wake_irq,
|
||||
NULL, sv6160_gpio_irq_thread,
|
||||
IRQF_ONESHOT,
|
||||
"sv6160", sc);
|
||||
if (ret) {
|
||||
dev_warn(&func->dev, "GPIO IRQ %d failed: %d\n",
|
||||
@@ -288,13 +410,17 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Boot firmware and register with mac80211 */
|
||||
/* Boot firmware and register with mac80211. Both IRQ paths are already
|
||||
* registered and gate on is_firmware_loaded, which core_init raises only
|
||||
* once the drain has its buffer, works and completion to land in. It
|
||||
* used to flip inside boot_firmware, before any of that existed, so an
|
||||
* early host-wake could drain into a NULL rx_buf. */
|
||||
ret = sv6160_boot_firmware(sc);
|
||||
if (ret == 0)
|
||||
ret = sv6160_core_init(sc);
|
||||
@@ -305,6 +431,35 @@ static int sv6160_probe(struct sdio_func *func,
|
||||
return 0;
|
||||
|
||||
err_free:
|
||||
/* Tear the interrupts down BEFORE ieee80211_free_hw(), which frees sc --
|
||||
* both handlers take sc as their data.
|
||||
*
|
||||
* The GPIO IRQ is devm-managed, so it would otherwise stay live until the
|
||||
* device unbinds, and that happens only after probe returns: a host-wake
|
||||
* arriving in that window would run the threaded handler against freed
|
||||
* memory. The in-band SDIO IRQ is not devm-managed at all, and leaving it
|
||||
* claimed is why the load after a failed probe reports
|
||||
* "sdio_claim_irq failed: -16" and silently drops to GPIO-only. Observed
|
||||
* exactly that after a probe that failed on a missing firmware file.
|
||||
*
|
||||
* sdio_release_irq() is safe even when the claim above failed; it is a
|
||||
* no-op on the handler and just clears the CCCR enable bit.
|
||||
*/
|
||||
if (sc->host_wake_irq > 0) {
|
||||
disable_irq_wake(sc->host_wake_irq);
|
||||
devm_free_irq(&func->dev, sc->host_wake_irq, sc);
|
||||
}
|
||||
sdio_claim_host(func);
|
||||
sdio_release_irq(func);
|
||||
sdio_release_host(func);
|
||||
/* Freeing the IRQs synchronises their handlers but does not flush a
|
||||
* work item one of them already queued (the in-band handler and the
|
||||
* drain's OOM re-arm both schedule rx_work), and core_init has run far
|
||||
* enough to have INIT_WORK'd it whenever the failure came from
|
||||
* register_hw. */
|
||||
sc->is_firmware_loaded = false;
|
||||
cancel_work_sync(&sc->rx_work);
|
||||
|
||||
pm_runtime_disable(&func->dev);
|
||||
ieee80211_free_hw(hw);
|
||||
err_disable:
|
||||
@@ -321,13 +476,29 @@ static void sv6160_remove(struct sdio_func *func)
|
||||
if (!sc)
|
||||
return;
|
||||
|
||||
sv6160_core_exit(sc);
|
||||
/* GPIO IRQ is freed automatically by devm */
|
||||
pm_runtime_disable(&func->dev);
|
||||
/* Stop both handlers dispatching BEFORE core_exit, whose last statement is
|
||||
* ieee80211_unregister_hw(): an event drained in that window reaches
|
||||
* handlers that call into a wiphy being torn down (SCAN_COMPLETE ->
|
||||
* ieee80211_scan_completed() after wiphy_unregister()'s final cancel).
|
||||
* Clearing the flag is enough and costs nothing here -- the only command
|
||||
* the teardown sends, remove_vif, is fire-and-forget and waits for no
|
||||
* reply. */
|
||||
sc->is_firmware_loaded = false;
|
||||
|
||||
sv6160_core_exit(sc);
|
||||
/* Now free them for real, still BEFORE ieee80211_free_hw() frees sc: devm
|
||||
* would do it only after this function returns, i.e. after the softc is
|
||||
* gone, and on the rung-2 host re-create that runs this remove() the level
|
||||
* line is typically stuck high with the thread mid-drain. */
|
||||
if (sc->host_wake_irq > 0) {
|
||||
disable_irq_wake(sc->host_wake_irq);
|
||||
devm_free_irq(&func->dev, sc->host_wake_irq, sc);
|
||||
}
|
||||
sdio_claim_host(func);
|
||||
sdio_release_irq(func);
|
||||
sdio_release_host(func);
|
||||
cancel_work_sync(&sc->rx_work); /* an in-band IRQ may have re-queued it */
|
||||
pm_runtime_disable(&func->dev);
|
||||
|
||||
ieee80211_free_hw(sc->hw);
|
||||
|
||||
|
||||
+828
-803
File diff suppressed because it is too large.
Load diff
Executable
BIN
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
"""Shared read/verify/apply/write logic for the firmware binary patch scripts.
|
||||
|
||||
Each patch is (name, file_offset, expected_original_bytes, replacement_bytes).
|
||||
Every site is verified against its expected original bytes before anything is
|
||||
written; a mismatch aborts (the firmware image is not the one the offsets
|
||||
describe).
|
||||
"""
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
|
||||
def apply_patches(patches, src, dst):
|
||||
data = bytearray(open(src, "rb").read())
|
||||
print(f"in : {src} ({len(data)} bytes, md5 {hashlib.md5(data).hexdigest()})")
|
||||
|
||||
for name, off, orig, _repl in patches:
|
||||
got = bytes(data[off:off + len(orig)])
|
||||
if got != orig:
|
||||
sys.exit(f"ABORT {name}: @0x{off:X} expected {orig.hex()} got {got.hex()}")
|
||||
|
||||
for name, off, orig, repl in patches:
|
||||
data[off:off + len(repl)] = repl
|
||||
print(f" applied {name}: @0x{off:X} {orig.hex()} -> {repl.hex()}")
|
||||
|
||||
open(dst, "wb").write(data)
|
||||
print(f"out: {dst} ({len(data)} bytes, md5 {hashlib.md5(data).hexdigest()})")
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Apply the "MAC-stays-enabled" RX-arming firmware patch to ssv6160-fw.bin.
|
||||
|
||||
Connected-mode RX on this firmware requires the MAC/PHY to be enabled
|
||||
(wifi_mac_enable, fcn.02000898). Only the scan path enables it — the scan
|
||||
handler / scan-stop call wifi_mac_enable(1) then wifi_mac_enable(0), so after
|
||||
any scan the MAC/PHY is powered DOWN and a fixed-channel connect finds a deaf
|
||||
receiver (RPU_CMD_CHANNEL never re-enables it). These patches turn the scan's
|
||||
two wifi_mac_enable(0) DISABLE calls into enable(1), so a scan leaves the
|
||||
MAC/PHY powered, plus keep the RF PLL tuned across scan-stop (P2):
|
||||
|
||||
M1 scan_handler exit wifi_mac_enable(0) -> (1) (li a0,0 -> li a0,1)
|
||||
M2 scan_stop wifi_mac_enable(0) -> (1) (li a0,0 -> li a0,1)
|
||||
P2 scan_stop RF_PLL-clear -> nop (keep RF tuned after scan)
|
||||
|
||||
Verified on hardware (SV6160/RK915, RK3326): with this fw AND the sv6160
|
||||
driver's connect_fix=9 (bit0 scan-hold + bit3 1-channel arm-scan on the
|
||||
operating channel), the CONNECTED-MODE RECEIVER ARMS — beacons arrive on the
|
||||
operating channel after discovery. Multi-channel scan still works (do NOT add
|
||||
P1 @0x782 or P3 @0x8CE — the full P1/P2/P3 set breaks scan/GPIO).
|
||||
|
||||
KNOWN LIMITATION (not fixed): the auth/assoc TX is still not ACKed by the AP
|
||||
(TX_DONE=RETRY_LIMIT) — connected-mode TX needs the firmware's PHY-ready gate
|
||||
(0x42048C00 & 0x100, in the CMD_CHANNEL worker) to pass, which it does not for
|
||||
this clean-room driver. So this arms RX but does not yet complete association.
|
||||
|
||||
Usage:
|
||||
python3 gen_fw_macfix.py [in=firmware/ssv6160-fw.bin] [out=firmware/ssv6160-fw-macfix.bin]
|
||||
"""
|
||||
import sys
|
||||
|
||||
from fw_patch_common import apply_patches
|
||||
|
||||
# (name, file_offset, expected_original, replacement)
|
||||
PATCHES = [
|
||||
("M1 scan_handler wifi_mac_enable(0)->(1)", 0x7AD6,
|
||||
bytes([0x01, 0x45]), bytes([0x05, 0x45])),
|
||||
("M2 scan_stop wifi_mac_enable(0)->(1)", 0x7AFE,
|
||||
bytes([0x01, 0x45]), bytes([0x05, 0x45])),
|
||||
("P2 scan_stop RF_PLL-clear -> nop", 0x7AFA,
|
||||
bytes([0x23, 0x2a, 0x07, 0x02]), bytes([0x13, 0x00, 0x00, 0x00])),
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
src = sys.argv[1] if len(sys.argv) > 1 else "firmware/ssv6160-fw.bin"
|
||||
dst = sys.argv[2] if len(sys.argv) > 2 else "firmware/ssv6160-fw-macfix.bin"
|
||||
apply_patches(PATCHES, src, dst)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Apply the §7 firmware binary patches to ssv6160-fw.bin.
|
||||
|
||||
These are RISC-V instruction NOPs that fix two firmware bugs the driver
|
||||
otherwise has to work around from the host side (see firmware/README.md §5-§7):
|
||||
|
||||
P1/P2 RF_PLL persistence: the firmware zeroes the RF PLL synthesizer
|
||||
(0x42000034) on rf_enable_disable and on scan_stop. NOP'ing both
|
||||
keeps the radio tuned so RPU_CMD_CHANNEL / post-scan TX land on the
|
||||
right frequency.
|
||||
P3 GPIO bit-19 persistence: wifi_mac_enable(a0=0) clears bit 19 of
|
||||
0x4009000C (GPIO RX-notification enable) whenever the MAC is toggled
|
||||
between commands, silently losing RX notifications. NOP'ing it keeps
|
||||
GPIO notifications armed.
|
||||
|
||||
Each site is verified against its expected original bytes before writing;
|
||||
a mismatch aborts (the firmware image is not the one these offsets describe).
|
||||
|
||||
Usage:
|
||||
python3 gen_fw_patch.py [in=firmware/ssv6160-fw.bin] [out=firmware/ssv6160-fw-patched.bin]
|
||||
"""
|
||||
import sys
|
||||
|
||||
from fw_patch_common import apply_patches
|
||||
|
||||
# (name, file_offset, expected_original, replacement)
|
||||
PATCHES = [
|
||||
("P1 rf_enable_disable RF_PLL-clear -> nop", 0x782,
|
||||
bytes([0x23, 0x2a, 0x07, 0x02]), bytes([0x13, 0x00, 0x00, 0x00])),
|
||||
("P2 scan_stop RF_PLL-clear -> nop", 0x7AFA,
|
||||
bytes([0x23, 0x2a, 0x07, 0x02]), bytes([0x13, 0x00, 0x00, 0x00])),
|
||||
("P3 GPIO bit19 persistence (c.nop x2)", 0x8CE,
|
||||
bytes([0xf9, 0x8f, 0xdc, 0xc6]), bytes([0x01, 0x00, 0x01, 0x00])),
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
src = sys.argv[1] if len(sys.argv) > 1 else "firmware/ssv6160-fw.bin"
|
||||
dst = sys.argv[2] if len(sys.argv) > 2 else "firmware/ssv6160-fw-patched.bin"
|
||||
apply_patches(PATCHES, src, dst)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,84 @@
|
||||
# tools
|
||||
|
||||
## `rk915-wiredump.patch`
|
||||
|
||||
Instruments the vendor rk915 driver to hex-dump every control command it sends,
|
||||
in the same `WIRECMD id=<n> len=<n>` + `WIRE <hex>` format the sv6160 driver
|
||||
emits under `wiredump=1`. That makes the two connect sequences directly
|
||||
diffable, command for command and byte for byte.
|
||||
|
||||
Apply it to a copy of the vendor source (do not edit the ROCKNIX build tree in
|
||||
place), build against the same kernel, and load with `wiredump=1`:
|
||||
|
||||
```sh
|
||||
cp -a .../build/rk915-<hash> /tmp/rk915v
|
||||
patch -d /tmp/rk915v -p0 < tools/rk915-wiredump.patch
|
||||
make -C <kernel-build-tree> M=/tmp/rk915v ARCH=arm64 \
|
||||
CROSS_COMPILE=aarch64-rocknix-linux-gnu- CONFIG_RK915=m modules
|
||||
# on the device
|
||||
rmmod rk915 && insmod rk915.ko wiredump=1 debug_mask=2
|
||||
```
|
||||
|
||||
`debug_mask=2` is `RK915_DBG_SCAN`, which makes the vendor log its scans — they
|
||||
are invisible at the default mask of 0, and their absence from a capture is
|
||||
easy to misread as "the vendor does not scan before authenticating". It does.
|
||||
|
||||
Drain dmesg continuously while capturing (`while true; do dmesg -c >> log;
|
||||
sleep 0.2; done &`); the ring buffer wraps well inside a single connect and
|
||||
will silently eat the window you care about.
|
||||
|
||||
|
||||
## `serctl.py`, `serial_capture.py`
|
||||
|
||||
Host-side serial console helpers (`/dev/ttyUSB0`, 1.5 Mbaud; override with
|
||||
`SV6160_SERIAL_PORT` / `SV6160_SERIAL_BAUD`). `serctl.py` runs one command on
|
||||
the device and exits with the command's own status (0-255), or 124 when the end
|
||||
marker never arrives inside the 25 s cap (124 as timeout(1) uses; 2 would
|
||||
collide with a real remote status) — a hung device is no longer
|
||||
indistinguishable from a successful one.
|
||||
|
||||
## `device/` — on-device harness scripts
|
||||
|
||||
These run **on the handheld**, not the build host, and are kept here because
|
||||
they encode operational knowledge that is otherwise easy to get wrong and is
|
||||
lost the moment the device is reflashed. Copy them to `/storage/`.
|
||||
|
||||
| script | purpose |
|
||||
|---|---|
|
||||
| `backtoours.sh` | Reload this driver, reconnect, and start the load-test listeners |
|
||||
| `sdioreset.sh` | Deep recovery: unbind/bind the WiFi MMC controller, then hand off to `backtoours.sh` |
|
||||
| `reloadp.sh` | Reload with explicit module parameters, e.g. `reloadp.sh "host_rebind=0"` |
|
||||
| `flightrec.sh` | Flight recorder — append device state to `/storage/flight.log` every 60s |
|
||||
|
||||
`backtoours.sh` needs to know which NetworkManager connection to bring up.
|
||||
It defaults to `sv6160-test`; override per device without editing the script:
|
||||
|
||||
```sh
|
||||
echo SSID=my-network > /storage/sv6160.conf
|
||||
```
|
||||
|
||||
Only the `SSID=` line is read (with `sed`), not the whole file sourced, and
|
||||
any surrounding quotes are stripped — the file is never executed.
|
||||
|
||||
Three traps these exist to avoid:
|
||||
|
||||
**Pick the interface by wdev, not by name.** Userspace sometimes adds a second,
|
||||
never-brought-up vif on our phy, and it can sort first — `ls /sys/class/net |
|
||||
grep wlan | head -1` then selects a dead interface and the run looks like a
|
||||
failed connect while the link is perfectly fine. `backtoours.sh` selects the
|
||||
lowest wdev on the sv6160 phy and waits for a real association.
|
||||
|
||||
**Never unbind `ff370000.mmc`.** That is mmc1 and it holds `/storage`. The WiFi
|
||||
controller is `ff380000.mmc` (mmc2). `sdioreset.sh` names only the latter and
|
||||
prints the `/storage` mount count across the unbind as a guard.
|
||||
|
||||
**Verify the listeners actually bound.** A previous run's `socat` can outlive
|
||||
the `pkill`, and a socat that loses the bind race dies silently — leaving the
|
||||
harness with no listeners while still reporting success.
|
||||
|
||||
`flightrec.sh` exists because `dmesg` does not survive a reboot and this board
|
||||
has no ramoops (`CONFIG_PSTORE_RAM=y` but no reserved-memory region), so an
|
||||
unexplained reboot otherwise leaves no evidence at all. Pair it with a boot unit
|
||||
in `/storage/.config/system.d/` so the driver loads at boot and each boot is
|
||||
stamped into the same log — ROCKNIX will otherwise auto-suspend a fresh boot
|
||||
before anyone can log in, and udev reclaims the card with the vendor `rk915`.
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/bin/sh
|
||||
# Reload our sv6160 driver and get back on the AP.
|
||||
exec > /storage/backtoours.txt 2>&1
|
||||
. /etc/profile 2>/dev/null
|
||||
# Which NetworkManager connection to bring up. Override per device:
|
||||
# echo SSID=my-network > /storage/sv6160.conf
|
||||
# Read the one value, do not source the file: it lives on the user-data
|
||||
# partition and this runs as root.
|
||||
SSID=$(sed -n 's/^SSID=//p' /storage/sv6160.conf 2>/dev/null | head -1 | sed 's/^"\(.*\)"$/\1/')
|
||||
: "${SSID:=sv6160-test}"
|
||||
set_setting system.suspend.enable 0 2>/dev/null
|
||||
# /lib/firmware is a tmpfs and is EMPTY after every reboot.
|
||||
cp -f /storage/sv6160/fw/ssv6160-fw.bin /storage/sv6160/fw/ssv6160-patch.bin /lib/firmware/ 2>/dev/null
|
||||
pkill socat 2>/dev/null
|
||||
nmcli radio wifi on >/dev/null 2>&1; sleep 2
|
||||
rmmod rk915 2>/dev/null; rmmod sv6160 2>/dev/null; sleep 3
|
||||
insmod /storage/sv6160/sv6160-crc.ko; rc=$?; echo "insmod rc=$rc"; sleep 7
|
||||
|
||||
# Our netdevs, lowest wdev first. NOT `ls | head -1`: userspace adds a second
|
||||
# managed vif on our phy that is never brought up, and its name can sort first
|
||||
# (seen as wlan0/wdev2 beside the live wlan4/wdev1), so head -1 picks a dead
|
||||
# interface and the run looks like a failed connect. mac80211 creates its own
|
||||
# interface at register_hw, so the lowest wdev on the sv6160 phy is ours.
|
||||
sv_ifaces() {
|
||||
for i in $(ls /sys/class/net | /usr/bin/grep -E "^wlan"); do
|
||||
phy=$(basename $(readlink -f /sys/class/net/$i/phy80211) 2>/dev/null)
|
||||
[ -n "$phy" ] || continue
|
||||
[ "$(basename $(readlink -f /sys/class/ieee80211/$phy/device/driver) 2>/dev/null)" = sv6160 ] || continue
|
||||
wdev=$(iw dev $i info 2>/dev/null | sed -n "s/.*wdev \(.*\)/\1/p")
|
||||
printf '%d %s\n' "$((wdev))" "$i"
|
||||
done | sort -n | awk "{print \$2}"
|
||||
}
|
||||
# An interface that is both associated and has an address.
|
||||
live_iface() {
|
||||
for i in $(sv_ifaces); do
|
||||
iw dev $i link 2>/dev/null | /usr/bin/grep -q "^Connected" || continue
|
||||
ip -4 -o addr show $i 2>/dev/null | /usr/bin/grep -q inet || continue
|
||||
echo $i; return
|
||||
done
|
||||
}
|
||||
|
||||
IFACES=$(sv_ifaces)
|
||||
echo "sv6160 interfaces: $IFACES"
|
||||
for i in $IFACES; do ip link set $i up 2>/dev/null; done
|
||||
PRIMARY=$(echo $IFACES | awk "{print \$1}")
|
||||
nmcli con up "$SSID" ifname $PRIMARY >/dev/null 2>&1 || nmcli con up "$SSID" >/dev/null 2>&1
|
||||
|
||||
# Wait for a real association rather than a fixed sleep.
|
||||
IF=""
|
||||
n=0
|
||||
while [ $n -lt 40 ]; do
|
||||
IF=$(live_iface)
|
||||
[ -n "$IF" ] && break
|
||||
n=$((n+1)); sleep 1
|
||||
done
|
||||
|
||||
if [ -n "$IF" ]; then
|
||||
echo "IF=$IF bss=$(iw dev $IF link 2>/dev/null | sed -n "s/^Connected to \([0-9a-f:]*\).*/\1/p") ip=$(ip -4 -o addr show $IF 2>/dev/null | sed -n "s/.*inet \([0-9.]*\)\/.*/\1/p") after=${n}s"
|
||||
else
|
||||
echo "IF= bss= ip= NOT CONNECTED after ${n}s (tried: $IFACES)"
|
||||
for i in $IFACES; do echo " $i: $(iw dev $i link 2>/dev/null | head -1)"; done
|
||||
fi
|
||||
|
||||
# Load-test listeners. Start them only once the ports are actually free: a
|
||||
# previous run's socat can outlive the pkill above by a moment, and a socat
|
||||
# that loses the bind race dies silently, leaving the harness with no listener.
|
||||
port_free() { ! netstat -ltn 2>/dev/null | /usr/bin/grep -q ":$1 "; }
|
||||
pkill socat 2>/dev/null
|
||||
n=0
|
||||
while [ $n -lt 15 ]; do
|
||||
port_free 5301 && port_free 5302 && break
|
||||
n=$((n+1)); sleep 1
|
||||
done
|
||||
socat -u TCP-LISTEN:5301,fork,reuseaddr /dev/null &
|
||||
socat -u /dev/zero TCP-LISTEN:5302,fork,reuseaddr &
|
||||
sleep 1
|
||||
if port_free 5301 || port_free 5302; then
|
||||
echo "WARNING: listeners did not bind (5301/5302)"
|
||||
else
|
||||
echo "listeners up on 5301/5302 (waited ${n}s)"
|
||||
fi
|
||||
echo "READY"
|
||||
wait
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# Flight recorder: append a line of state every 60s to a PERSISTENT file, so an
|
||||
# unexplained reboot leaves a record of the run-up to it. dmesg does not
|
||||
# survive a reboot and this board has no ramoops (CONFIG_PSTORE_RAM=y but no
|
||||
# reserved-memory region), so this is the only way to see what preceded one.
|
||||
LOG=/storage/flight.log
|
||||
while true; do
|
||||
# Resolve the debugfs path EVERY iteration. It was once resolved here at
|
||||
# start-up, which silently broke the whole point of this script: the phy
|
||||
# number changes on every driver reload and host re-create, so after the
|
||||
# first recovery the cached path was stale and every counter field logged
|
||||
# empty -- while the timestamp, temperature and signal kept looking healthy.
|
||||
# The recovery is exactly when the counters matter.
|
||||
D=$(find /sys/kernel/debug/ieee80211 -maxdepth 2 -name sv6160 2>/dev/null | head -1)
|
||||
up=$(cut -d. -f1 /proc/uptime)
|
||||
bat=$(cat /sys/class/power_supply/battery/capacity 2>/dev/null)
|
||||
vol=$(cat /sys/class/power_supply/battery/voltage_now 2>/dev/null)
|
||||
cur=$(cat /sys/class/power_supply/battery/current_now 2>/dev/null)
|
||||
ac=$(cat /sys/class/power_supply/rk817-charger/online 2>/dev/null)
|
||||
tf=$(/usr/bin/grep -m1 "^tx_frames" $D/tx_tokens 2>/dev/null | awk "{print \$2}")
|
||||
td=$(/usr/bin/grep -m1 "^tx_done_events" $D/tx_tokens 2>/dev/null | awk "{print \$2}")
|
||||
rs=$(/usr/bin/grep -m1 "^tx_resyncs" $D/tx_tokens 2>/dev/null | awk "{print \$2}")
|
||||
gu=$(dmesg | /usr/bin/grep -c "TX engine dead" 2>/dev/null)
|
||||
hr=$(dmesg | /usr/bin/grep -c "re-creating the SDIO host to clear" 2>/dev/null)
|
||||
# Only OUR interfaces (a foreign wlan can exist), and only one of them:
|
||||
# two connected names here would break every `iw dev $IF` below.
|
||||
IF=$(for i in $(ls /sys/class/net | /usr/bin/grep -E "^wlan"); do
|
||||
phy=$(basename $(readlink -f /sys/class/net/$i/phy80211) 2>/dev/null); [ -n "$phy" ] || continue
|
||||
[ "$(basename $(readlink -f /sys/class/ieee80211/$phy/device/driver) 2>/dev/null)" = sv6160 ] || continue
|
||||
iw dev $i link 2>/dev/null | /usr/bin/grep -q Connected && echo $i
|
||||
done | head -1)
|
||||
sig=$(iw dev $IF link 2>/dev/null | sed -n "s/.*signal: \(-[0-9]*\).*/\1/p")
|
||||
temp=$(cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null)
|
||||
[ -n "$D" ] || { tf=nodev; td=nodev; rs=nodev; }
|
||||
echo "$(date +%H:%M:%S) up=$up bat=$bat v=$vol i=$cur ac=$ac if=$IF sig=$sig temp=$temp tx=$tf done=$td resync=$rs giveup=$gu rebind=$hr" >> $LOG
|
||||
sleep 60
|
||||
done
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Reload our driver with explicit module parameters: /storage/reloadp.sh "host_rebind=0"
|
||||
exec > /storage/reloadp.txt 2>&1
|
||||
. /etc/profile 2>/dev/null
|
||||
set_setting system.suspend.enable 0 2>/dev/null
|
||||
cp -f /storage/sv6160/fw/ssv6160-fw.bin /storage/sv6160/fw/ssv6160-patch.bin /lib/firmware/ 2>/dev/null
|
||||
rmmod sv6160 2>/dev/null; rmmod rk915 2>/dev/null; sleep 2
|
||||
insmod /storage/sv6160/sv6160-crc.ko $1; rc=$?
|
||||
sleep 6
|
||||
echo "insmod rc=$rc params=[$1]"
|
||||
echo "probe_failures=$(dmesg | /usr/bin/grep -c "probe with driver sv6160 failed")"
|
||||
echo "ifaces=$(ls /sys/class/net | /usr/bin/grep -c wlan)"
|
||||
echo "RELOADP-DONE"
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# Deep SDIO reset: tear down and re-create the dw_mmc host for the WiFi slot,
|
||||
# which re-powers and re-enumerates the card. Strictly deeper than a module
|
||||
# reload, which leaves the host controller and card state untouched.
|
||||
#
|
||||
# ff380000.mmc is mmc2 = the WiFi controller. NEVER ff370000.mmc: that is
|
||||
# mmc1 and it holds /storage.
|
||||
exec > /storage/sdioreset.txt 2>&1
|
||||
DRV=/sys/bus/platform/drivers/dwmmc_rockchip
|
||||
rmmod sv6160 2>/dev/null; rmmod rk915 2>/dev/null; sleep 2
|
||||
echo "unbinding ff380000.mmc"
|
||||
echo ff380000.mmc > $DRV/unbind 2>&1; sleep 4
|
||||
echo "bound now: $(ls $DRV | /usr/bin/grep -c ff380000) storage mounts: $(mount | /usr/bin/grep -c storage)"
|
||||
echo ff380000.mmc > $DRV/bind 2>&1; sleep 6
|
||||
echo "rebound: $(ls $DRV | /usr/bin/grep -c ff380000)"
|
||||
if [ "$(ls $DRV | /usr/bin/grep -c ff380000)" != 1 ]; then
|
||||
echo "REBIND-FAILED: ff380000.mmc did not come back; not chaining into backtoours"
|
||||
exit 1
|
||||
fi
|
||||
rmmod rk915 2>/dev/null; sleep 1
|
||||
echo "SDIORESET-DONE"
|
||||
exec /storage/backtoours.sh
|
||||
@@ -0,0 +1,26 @@
|
||||
--- /home/pkilar/Devel/rocknix/build.ROCKNIX-RK3326.aarch64/build/rk915-86f0d0e07afe156651ce5eec3e315f66ef79a59f/src/hal.c 2026-08-08 03:02:20.000000000 -0400
|
||||
+++ /tmp/claude-1000/-home-pkilar-Devel-gusgu/c1ac0c7f-cdf3-4195-92c5-42ffe8e5463e/scratchpad/rk915v/src/hal.c 2026-09-10 21:47:17.950825261 -0400
|
||||
@@ -303,9 +303,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
+/* Byte-level wire dump of every control command, for diffing this driver's
|
||||
+ * connect sequence against a clean-room reimplementation. Off by default. */
|
||||
+unsigned int rk915_wiredump;
|
||||
+module_param_named(wiredump, rk915_wiredump, uint, 0644);
|
||||
+MODULE_PARM_DESC(wiredump, "hex-dump every control command payload (0=off)");
|
||||
+
|
||||
static void _hal_send(struct hal_priv *priv,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
+ if (rk915_wiredump && skb->len >= sizeof(struct host_rpu_msg_hdr)) {
|
||||
+ struct host_rpu_msg_hdr *h = (struct host_rpu_msg_hdr *)skb->data;
|
||||
+
|
||||
+ pr_info("WIRECMD id=%u len=%u\n", h->id, skb->len);
|
||||
+ print_hex_dump(KERN_INFO, "WIRE ", DUMP_PREFIX_NONE, 32, 1,
|
||||
+ skb->data,
|
||||
+ skb->len > 256 ? 256 : skb->len, false);
|
||||
+ }
|
||||
skb_queue_tail(&priv->txq, skb);
|
||||
//tasklet_schedule(&priv->tx_tasklet);
|
||||
hal_tx_queue_work(priv);
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run a shell command on the ROCKNIX device over the serial console.
|
||||
|
||||
Usage: serctl.py 'command' -> run, print output between markers
|
||||
serctl.py --raw -> just drain whatever the console emits
|
||||
Console: /dev/ttyUSB0 @ 1500000, root shell, no login.
|
||||
|
||||
Exit codes: 0 = remote command succeeded, 1-255 = remote command's own exit
|
||||
status, 124 = timeout, no end marker seen within the cap (124 because that is
|
||||
what timeout(1) uses, and because 2 collides with a real remote status -- `ls`
|
||||
on a missing path and `grep` on an error both exit 2, so a hung handheld would
|
||||
have been indistinguishable from those).
|
||||
"""
|
||||
import sys, time, serial, uuid
|
||||
|
||||
from serial_common import PORT, BAUD
|
||||
|
||||
def run(cmd, timeout=25.0):
|
||||
tag = "M" + uuid.uuid4().hex[:8].upper()
|
||||
with serial.Serial(PORT, BAUD, timeout=0.2) as s:
|
||||
s.reset_input_buffer()
|
||||
s.write(b"\n")
|
||||
time.sleep(0.25)
|
||||
s.reset_input_buffer()
|
||||
s.write(("echo __%s_S__; { %s ; } 2>&1; echo __RC_%s__$?; echo __%s_E__\n"
|
||||
% (tag, cmd, tag, tag)).encode())
|
||||
s.flush()
|
||||
buf = b""
|
||||
end = ("__%s_E__" % tag).encode()
|
||||
t0 = time.time()
|
||||
while time.time() - t0 < timeout:
|
||||
buf += s.read(4096)
|
||||
if end in buf:
|
||||
break
|
||||
else:
|
||||
raise TimeoutError("no end marker after %gs" % timeout)
|
||||
txt = buf.decode("utf-8", "replace")
|
||||
start = "__%s_S__" % tag
|
||||
stop = "__%s_E__" % tag
|
||||
if start in txt:
|
||||
txt = txt.split(start, 1)[1]
|
||||
# drop the echoed command line remnant up to first newline
|
||||
txt = txt.split("\n", 1)[1] if "\n" in txt else txt
|
||||
if stop in txt:
|
||||
txt = txt.split(stop, 1)[0]
|
||||
rc = 0
|
||||
rc_marker = "__RC_%s__" % tag
|
||||
if rc_marker in txt:
|
||||
before, after = txt.split(rc_marker, 1)
|
||||
digits = ""
|
||||
i = 0
|
||||
while i < len(after) and after[i].isdigit():
|
||||
digits += after[i]
|
||||
i += 1
|
||||
rc = int(digits) if digits else 0
|
||||
# drop the "__RC_<tag>__<digits>" line, including its newline
|
||||
rest = after[i:].split("\n", 1)
|
||||
txt = before + (rest[1] if len(rest) > 1 else "")
|
||||
return txt.replace("\r", ""), rc
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "--raw":
|
||||
with serial.Serial(PORT, BAUD, timeout=3) as s:
|
||||
sys.stdout.write(s.read(65536).decode("utf-8", "replace"))
|
||||
sys.exit(0)
|
||||
try:
|
||||
out, rc = run(" ".join(sys.argv[1:]))
|
||||
except TimeoutError as e:
|
||||
sys.stderr.write("TIMEOUT: %s\n" % e)
|
||||
sys.exit(124)
|
||||
print(out, end="")
|
||||
sys.exit(rc)
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run a command on the device and stream the serial console to a file,
|
||||
so a panic/oops that kills the box before /storage is flushed is still caught."""
|
||||
import serial, sys, time
|
||||
|
||||
from serial_common import PORT, BAUD
|
||||
|
||||
cmd = sys.argv[1]
|
||||
secs = float(sys.argv[2]) if len(sys.argv) > 2 else 90
|
||||
out = sys.argv[3] if len(sys.argv) > 3 else "/tmp/serial_capture.log"
|
||||
|
||||
with serial.Serial(PORT, BAUD, timeout=0.3) as s, open(out, "wb") as f:
|
||||
s.write(b"\n"); time.sleep(0.3); s.reset_input_buffer()
|
||||
# Level 4, not 8: oopses/warnings still reach the console, but the
|
||||
# driver's per-frame dev_info/dev_dbg does not. At 8 a chatty driver
|
||||
# floods this 1.5Mbaud line, printk backs up, and every process that
|
||||
# writes to the console wedges -- which is how a soak run once left the
|
||||
# handheld needing a power cycle.
|
||||
s.write(b"dmesg -n 4\n"); time.sleep(0.5)
|
||||
s.write((cmd + "\n").encode()); s.flush()
|
||||
t0 = time.time()
|
||||
n = 0
|
||||
while time.time() - t0 < secs:
|
||||
d = s.read(8192)
|
||||
if d:
|
||||
f.write(d); f.flush(); n += len(d)
|
||||
print(f"captured {n} bytes to {out}")
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Shared serial console settings for the device tooling scripts.
|
||||
|
||||
Override per host without editing these scripts:
|
||||
SV6160_SERIAL_PORT=/dev/ttyUSB1 SV6160_SERIAL_BAUD=115200 tools/serctl.py ...
|
||||
"""
|
||||
import os
|
||||
|
||||
PORT = os.environ.get("SV6160_SERIAL_PORT", "/dev/ttyUSB0")
|
||||
BAUD = int(os.environ.get("SV6160_SERIAL_BAUD", "1500000"))
|
||||
Reference in new issue
Block a user