mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
Wi-Fi: one WCN power transition at a time; an RX interrupt without a context no longer panics (FINDINGS 31n)
F50 #1, OpenWrt on 6.18.55, 1 hang in 20 reboots. pstore had an Oops in hard IRQ: pcie_rx_handle+0x34, "paging request at 00000000000030b8", reached from msi_irq_handle via mchn_hw_pop_link. The probe powers the chip off after it registered wlan0, outside RTNL. netifd opened the new AP interface 130 ms later, while that power-off was still in post_deinit. The open's power-on registered the channels, then the probe's power-off cleared sc2355_hif.hif and stopped the chip, and the next RX read through NULL. power_cnt was atomic; the transitions behind it were not. - sprd_iface_set_power holds hif->power_lock across the whole transition. - pcie_rx_handle drops a list without a context and logs it once. - sc2355_hif.hif uses a release store and acquire loads, and is cleared only after the channels are unregistered. - Review findings: probe's error paths and remove powered off after sprd_core_free had freed hif (now before), and a power-on that failed in post_init or the version sync stayed half up with the count at 0 (now undone). - The same change for 5.4: kernel/patches/wlan_combo-wcn-power-serialise.patch. F50-B, 6.18.55 with the fix: - 30 soft reboots, 0 Oops: 14 hotspot boots, plus 16 Wi-Fi client boots with a unit that opens wlan0 inside the probe's power-off (all 16 hit the window). - 30 hotspot restarts, 0 Oops. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn
This commit is contained in:
1 parent
c527f87e0b
commit
1f6e825b9e
6 files changed
+359
-9
No files matched your search
@@ -1797,6 +1797,79 @@ Ruled out or not reproduced on a running board:
|
||||
Still open: which access stalls the bus. A hang rate of about 2 in 50 boots needs a reproducer, or 100+ boots per
|
||||
variant, before a change (for example a delay or poll before the probe's first GPU read) can be measured.
|
||||
|
||||
### 31n. Wi-Fi powered off and on at the same time: an Oops in the RX interrupt
|
||||
F50 #1, OpenWrt from the card on 6.18.55 (main's code), 20 soft reboots: one hang (boot 11). This one left pstore:
|
||||
```
|
||||
15.494580 sprd-wlan: Power off WCN (1 time) <- end of the probe, wlan0 already registered
|
||||
15.494597 WCN PCIE: [+]mchn_deinit(7, 1) ... 9, 11, 4, 5: about 24 ms each
|
||||
15.543125 sprd-wlan: iface 'wlan0' deleted <- netifd: station iface out, AP iface in
|
||||
15.616675 ... iface 'wlan0'(5c:7d:..) type 3 added
|
||||
15.627387 misc wlan wlan0: iface_open
|
||||
15.627393 misc wlan wlan0: Power on WCN (0 time)
|
||||
15.627399 WCN BASEstart_marlin [MARLIN_WIFI]
|
||||
15.627422 sprd-wlan: pcie_post_init: register 6 ops <- while the probe is still in mchn_deinit(10)
|
||||
15.636823 sprd-wlan: ctx_id:0 cmd_id:9 [CMD_SYNC_VERSION]rsp received
|
||||
15.640183 WCN PCIE: [-]mchn_deinit(10) <- the probe's power-off goes on: hif = NULL
|
||||
15.640193 WCN BASEstop_marlin [MARLIN_WIFI]
|
||||
15.648698 Unable to handle kernel paging request at virtual address 00000000000030b8
|
||||
pc : pcie_rx_handle+0x34/0x1e0 [sprd_wlan_combo]
|
||||
lr : mchn_hw_pop_link+0x8c/0xa0 [wcn_bsp]
|
||||
mchn_hw_pop_link <- edma_rx_pop_isr <- hisrfunc <- msi_irq_handle <- sprd_pcie_msi_irq (CPU 0, swapper)
|
||||
Kernel panic - not syncing: Fatal exception in interrupt
|
||||
```
|
||||
The board did not reset after `panic=5`; it came back in Android about 8 minutes later.
|
||||
|
||||
The cause is in the driver, not the bus. `power_cnt` is atomic, the transitions behind it are not. The probe
|
||||
registers wlan0 and then powers the chip off from the probe thread, outside RTNL. OpenWrt's netifd replaced and
|
||||
opened the interface within 130 ms. The open's power-on saw the count at 0 and ran `start_marlin` + `post_init`
|
||||
while the probe's power-off was still in `post_deinit`. That power-off then finished: it cleared
|
||||
`sc2355_hif.hif` after `post_init` had set it, and `stop_marlin` powered the chip down under a live interface. The
|
||||
next RX MSI, on a channel the open had registered again, read `hif->rx_mgmt` through the NULL hif (`0x30b8`, a
|
||||
field offset from NULL). iface_open and iface_close are both under RTNL, so a hotspot or `wifi down/up` restart cannot do
|
||||
this; only the probe and remove can. main's PCIe post-init change (`wlan_combo-pcie-post-init-retry`) only
|
||||
restores the static channel table and did not widen the window. The 5.4 driver has the same code; Ubuntu's hostapd
|
||||
opens wlan0 about 10 s after the probe, which is why the Ubuntu boots never showed it.
|
||||
|
||||
Fix, both kernels (`upstream/modules/sprd_wlan_combo`, `kernel/patches/wlan_combo-wcn-power-serialise.patch`):
|
||||
- `sprd_iface_set_power` holds a mutex (`hif->power_lock`) across the whole transition, so an open waits for the
|
||||
probe's power-off and then powers on from scratch.
|
||||
- `pcie_rx_handle` drops a list that arrives without a context (no hif or no `rx_mgmt`) and logs once ("RX on
|
||||
channel N with no Wi-Fi context"). The TX pop handlers and `pcie_rx_fill_mbuf` already had such checks on 6.18
|
||||
(14c).
|
||||
- `sc2355_hif.hif` is published with a release store before the channels are registered, read with an acquire
|
||||
load, and cleared only after they are unregistered.
|
||||
- Found in review:
|
||||
- The probe's error paths and `remove` powered off after `sprd_core_free` had freed `priv`, and `hif` with it.
|
||||
They now power off first.
|
||||
- A power-on that failed in `post_init` or the version sync left the chip started with the count at 0, and
|
||||
after a failed sync the channels stayed registered too. It is now undone the way a power-off does.
|
||||
|
||||
Measured on F50-B (Ubuntu 24.04, 6.18.55 with the fix):
|
||||
- 30 soft reboots, each started only after `mu300-boot-ok` had confirmed the one before: 0 Oops, 0 "no Wi-Fi
|
||||
context" lines, pstore empty, every boot confirmed.
|
||||
- 14 boots in hotspot mode (AP up every time). A 15th, at 23:47, was the user unplugging the board and is not
|
||||
counted.
|
||||
- 16 boots as a Wi-Fi client (joined KEDI 5G every time). In these, a temporary unit opened wlan0 as soon as the
|
||||
driver registered it, to recreate the pstore boot's timing (Ubuntu's hostapd opens about 10 s later).
|
||||
- In all 16 the open came 1 to 16 ms after the probe's power-off began, about 140 ms before that power-off's
|
||||
`stop_marlin`. That is the window of the Oops. In all 16 the open's `start_marlin` came after it.
|
||||
- 30 hotspot restarts (`systemctl restart mu300-hotspot`, a full WCN power-off and power-on each): AP up after
|
||||
every one, 0 Oops.
|
||||
- The 6.18.55 and 7.2.9 modules build. The 5.4 patch applies after the others and compiles against the 5.4 tree;
|
||||
the module link was not run.
|
||||
|
||||
Not covered:
|
||||
- `edma_chn_deinit` (wcn_bsp) frees a channel's ring lock and mbuf pool after a bare `msleep(20)`, without masking
|
||||
the channel or `synchronize_irq`.
|
||||
- `mchn_hw_pop_link` reads `mchn->ops[chn]` twice.
|
||||
- An MSI still running on another CPU while a channel is torn down is therefore still possible. It is pre-existing
|
||||
and was not seen.
|
||||
- The 5.4 driver also lacks 6.18's TX-side checks (14c).
|
||||
|
||||
31m's silent hangs (the SoC stops at the Mali probe or at `crng init done`, no log) do not match this: here the
|
||||
kernel logged an Oops and panicked. A chip powered down by `stop_marlin` under a live PCIe link could stall a bus
|
||||
access, though, so this fix may remove some of that class. Not shown.
|
||||
|
||||
## Updating on the device
|
||||
|
||||
### 32. Old kernels, an idle IPA, and an update that ended in Android
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
sprd_wlan_combo: one WCN power transition at a time; an RX interrupt without a context is dropped, not a panic
|
||||
|
||||
power_cnt is atomic, the transitions behind it are not. The probe powers the chip off after it registered wlan0,
|
||||
outside RTNL, so userspace (hostapd, netifd) can open the interface meanwhile: the open's power-on ran
|
||||
start_marlin + post_init while the probe's power-off was still in post_deinit, which then cleared the channels and
|
||||
sc2355_hif.hif that post_init had just set; the next RX interrupt read hif->rx_mgmt from NULL in hard IRQ
|
||||
(pcie_rx_handle+0x34, "paging request at 00000000000030b8", seen under 6.18 in FINDINGS 31n; the 5.4 driver has
|
||||
the same code). sprd_iface_set_power holds a mutex across the transition; pcie_rx_handle drops a list that
|
||||
arrives with no context and logs it once; the context pointer is published with release/acquire.
|
||||
On the way: probe's error paths and remove powered off after sprd_core_free had freed hif (now before), and a
|
||||
power-on that failed in post_init or the version sync left the chip started, and after a failed sync the
|
||||
channels registered, with the count at 0 (now undone as a power-off does).
|
||||
|
||||
--- a/common/hif.h
|
||||
+++ b/common/hif.h
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef __HIF_H__
|
||||
#define __HIF_H__
|
||||
|
||||
+#include <linux/mutex.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <misc/marlin_platform.h>
|
||||
|
||||
@@ -117,6 +118,8 @@
|
||||
|
||||
int exit;
|
||||
atomic_t power_cnt;
|
||||
+ /* MU300: one WCN power transition at a time (sprd_iface_set_power) */
|
||||
+ struct mutex power_lock;
|
||||
int flag;
|
||||
int lastflag;
|
||||
u8 cp_asserted;
|
||||
@@ -289,6 +292,9 @@
|
||||
}
|
||||
|
||||
if (sprd_hif_post_init(hif)) {
|
||||
+ /* MU300: post_init unwound its channels; the chip was started, stop it as a power-off would */
|
||||
+ if (stop_marlin(MARLIN_WIFI))
|
||||
+ pr_err("stop_marlin failed!!\n");
|
||||
atomic_sub(1, &hif->power_cnt);
|
||||
return -ENODEV;
|
||||
}
|
||||
@@ -301,6 +307,15 @@
|
||||
}
|
||||
|
||||
if (sprd_sync_version(hif)) {
|
||||
+ /*
|
||||
+ * MU300: undo the power-on as sprd_hif_power_off() does. The vendor left the channels registered
|
||||
+ * and the chip started with the count at 0: the next power-on registered them again over live ones,
|
||||
+ * and a probe that failed here freed hif under channels that could still interrupt.
|
||||
+ */
|
||||
+ sprd_clean_work(hif->priv);
|
||||
+ sprd_hif_post_deinit(hif);
|
||||
+ if (stop_marlin(MARLIN_WIFI))
|
||||
+ pr_err("stop_marlin failed!!\n");
|
||||
atomic_sub(1, &hif->power_cnt);
|
||||
return -EIO;
|
||||
}
|
||||
--- a/common/iface.c
|
||||
+++ b/common/iface.c
|
||||
@@ -270,6 +270,15 @@
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
+ /*
|
||||
+ * MU300: power_cnt is atomic, the transitions behind it are not. Probe powers the chip off after it
|
||||
+ * registered wlan0, outside RTNL, so userspace (hostapd, netifd) can open the interface meanwhile: the
|
||||
+ * open's power-on (1st count) ran start_marlin + post_init while the probe's power-off (last count) was
|
||||
+ * still in post_deinit. post_deinit then cleared the channels and sc2355_hif.hif that post_init had just
|
||||
+ * set, stop_marlin powered the chip down, and the next RX interrupt read hif->rx_mgmt from NULL
|
||||
+ * (pcie_rx_handle+0x34, "paging request at 00000000000030b8", FINDINGS 31n). One transition at a time.
|
||||
+ */
|
||||
+ mutex_lock(&hif->power_lock);
|
||||
if (val) {
|
||||
sprd_wlan_power_status_sync(1, 1);
|
||||
ret = sprd_hif_power_on(hif);
|
||||
@@ -280,12 +289,14 @@
|
||||
else if (ret == -EIO)
|
||||
pr_err("SYNC cmd error!\n");
|
||||
|
||||
- return ret;
|
||||
+ goto out;
|
||||
}
|
||||
if (atomic_read(&hif->power_cnt) == 1)
|
||||
sprd_get_fw_info(hif->priv);
|
||||
} else
|
||||
sprd_hif_power_off(hif);
|
||||
+out:
|
||||
+ mutex_unlock(&hif->power_lock);
|
||||
return ret;
|
||||
}
|
||||
#ifdef DRV_RESET_SELF
|
||||
@@ -1768,6 +1779,7 @@
|
||||
iface_set_priv(priv);
|
||||
platform_set_drvdata(pdev, priv);
|
||||
hif = &priv->hif;
|
||||
+ mutex_init(&hif->power_lock);
|
||||
hif->priv = priv;
|
||||
hif->pdev = pdev;
|
||||
hif->ops = hif_ops;
|
||||
@@ -1790,9 +1802,10 @@
|
||||
ret = iface_core_init(&pdev->dev, priv);
|
||||
if (ret) {
|
||||
pr_err("%s core init failed: %d\n", __func__, ret);
|
||||
+ /* MU300: power off while hif still exists (sprd_core_free frees priv, and hif with it) */
|
||||
+ sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
- sprd_iface_set_power(hif, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1800,9 +1813,9 @@
|
||||
if (ret) {
|
||||
pr_err("%s notify init failed: %d\n", __func__, ret);
|
||||
iface_core_deinit(priv);
|
||||
+ sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
- sprd_iface_set_power(hif, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1829,11 +1842,12 @@
|
||||
|
||||
iface_notify_deinit(priv);
|
||||
iface_core_deinit(priv);
|
||||
+ /* MU300: power off while hif still exists (sprd_core_free frees priv, and hif and its lock with it) */
|
||||
+ pr_info("Power off WCN (%d time)\n", atomic_read(&hif->power_cnt));
|
||||
+ sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
iface_set_priv(NULL);
|
||||
- pr_info("Power off WCN (%d time)\n", atomic_read(&hif->power_cnt));
|
||||
- sprd_iface_set_power(hif, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
--- a/sc2355/pcie.c
|
||||
+++ b/sc2355/pcie.c
|
||||
@@ -372,7 +372,7 @@
|
||||
struct mbuf_t *tail, int num)
|
||||
{
|
||||
struct sprd_hif *hif = sc2355_pcie_get_hif();
|
||||
- struct rx_mgmt *rx_mgmt = (struct rx_mgmt *)hif->rx_mgmt;
|
||||
+ struct rx_mgmt *rx_mgmt;
|
||||
struct sprd_msg *msg = NULL;
|
||||
int buf_num = 0, len = 0, ret = 0;
|
||||
struct mbuf_t *pos = head;
|
||||
@@ -380,6 +380,20 @@
|
||||
pr_debug("%s: channel:%d head:%p tail:%p num:%d\n",
|
||||
__func__, chn, head, tail, num);
|
||||
|
||||
+ /*
|
||||
+ * MU300: an RX interrupt outside the channels' lifetime (post_init publishes hif before it registers
|
||||
+ * them, post_deinit clears it after it unregistered them, sprd_iface_set_power serialises the two).
|
||||
+ * Without hif there is no device to unmap the buffers from and no queue to hand them to, and the
|
||||
+ * channel's mbuf pool is already freed (no sprdwcn_bus_list_free): the data buffers of this one list
|
||||
+ * leak, and it is said once. A NULL here was a panic in hard IRQ (FINDINGS 31n).
|
||||
+ */
|
||||
+ rx_mgmt = hif ? (struct rx_mgmt *)READ_ONCE(hif->rx_mgmt) : NULL;
|
||||
+ if (unlikely(!rx_mgmt)) {
|
||||
+ pr_err_once("%s: RX on channel %d with no Wi-Fi context, %d buffer(s) dropped\n",
|
||||
+ __func__, chn, num);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
for (buf_num = num; buf_num > 0; buf_num--, pos = pos->next) {
|
||||
if (unlikely(!pos)) {
|
||||
pr_err("%s: NULL mbuf\n", __func__);
|
||||
@@ -646,7 +660,7 @@
|
||||
|
||||
struct sprd_hif *sc2355_pcie_get_hif(void)
|
||||
{
|
||||
- return (struct sprd_hif *)sc2355_hif.hif;
|
||||
+ return (struct sprd_hif *)smp_load_acquire(&sc2355_hif.hif);
|
||||
}
|
||||
|
||||
#define INTF_IS_PCIE \
|
||||
@@ -1994,7 +2008,8 @@
|
||||
{
|
||||
int ret = -EINVAL, chn = 0;
|
||||
|
||||
- sc2355_hif.hif = (void *)hif;
|
||||
+ /* MU300: published before any channel can interrupt (the RX/TX callbacks read it in hard IRQ) */
|
||||
+ smp_store_release(&sc2355_hif.hif, (void *)hif);
|
||||
/*
|
||||
* MU300 (from kanoqwq/mu300-linux): a failed/aborted earlier power cycle clears this pointer in the
|
||||
* error path below. The vendor driver only restores it in pcie_init(),
|
||||
@@ -2040,7 +2055,8 @@
|
||||
|
||||
for (chn = 0; chn < sc2355_hif.max_num; chn++)
|
||||
sprdwcn_bus_chn_deinit(&sc2355_hif.mchn_ops[chn]);
|
||||
- sc2355_hif.hif = NULL;
|
||||
+ /* MU300: cleared only after every channel is unregistered (the callbacks check for NULL) */
|
||||
+ WRITE_ONCE(sc2355_hif.hif, NULL);
|
||||
sc2355_hif.max_num = 0;
|
||||
|
||||
}
|
||||
@@ -417,5 +417,38 @@ class Rules(unittest.TestCase):
|
||||
for f in ('etc/init.d/mu300-ndp', 'opt/mu300/bin/ndp-learn', 'lib/netifd/proto/mu300cell-v6.sh'):
|
||||
self.assertTrue((LUCI_OVERLAY / f).stat().st_mode & 0o111, f)
|
||||
|
||||
def test_wifi_power_transitions_are_serialised(self):
|
||||
# FINDINGS 31n: the probe's power-off (outside RTNL) ran post_deinit while hostapd's open ran post_init;
|
||||
# post_deinit cleared the context post_init had just set, and the next RX interrupt read it as NULL in hard
|
||||
# IRQ. Both kernels' drivers hold a mutex across the power transition and drop RX with no context
|
||||
wlan = TOP / 'upstream' / 'modules' / 'sprd_wlan_combo'
|
||||
patch = (TOP / 'kernel' / 'patches' / 'wlan_combo-wcn-power-serialise.patch').read_text()
|
||||
hif = (wlan / 'common' / 'hif.h').read_text()
|
||||
iface = (wlan / 'common' / 'iface.c').read_text()
|
||||
pcie = (wlan / 'sc2355' / 'pcie.c').read_text()
|
||||
self.assertIn('\tstruct mutex power_lock;', hif)
|
||||
self.assertIn('+\tstruct mutex power_lock;', patch)
|
||||
for text, pre in ((iface, ''), (patch, '+')):
|
||||
self.assertIn(pre + '\tmutex_init(&hif->power_lock);', text)
|
||||
self.assertIn(pre + '\tmutex_lock(&hif->power_lock);', text)
|
||||
self.assertIn(pre + '\tmutex_unlock(&hif->power_lock);', text)
|
||||
body = iface[iface.index('int sprd_iface_set_power('):]
|
||||
body = body[:body.index('\n}\n')]
|
||||
# no return between the lock and the unlock
|
||||
self.assertNotIn('return ret;', body[:body.index('mutex_unlock')])
|
||||
rx = pcie[pcie.index('static int pcie_rx_handle('):]
|
||||
rx = rx[:rx.index('\n}\n')]
|
||||
guard = 'rx_mgmt = hif ? (struct rx_mgmt *)READ_ONCE(hif->rx_mgmt) : NULL;'
|
||||
self.assertLess(rx.index(guard), rx.index('if (unlikely(!rx_mgmt))'))
|
||||
self.assertLess(rx.index('if (unlikely(!rx_mgmt))'), rx.index('rx_mgmt->rx_list'))
|
||||
self.assertIn('+\t' + guard, patch)
|
||||
# remove powers off before sprd_core_free frees priv (and hif, and the lock in it)
|
||||
rm = iface[iface.index('int sprd_iface_remove('):]
|
||||
self.assertLess(rm.index('sprd_iface_set_power(hif, false);'), rm.index('sprd_core_free(priv);'))
|
||||
for text, pre in ((pcie, ''), (patch, '+')):
|
||||
self.assertIn(pre + '\tsmp_store_release(&sc2355_hif.hif, (void *)hif);', text)
|
||||
self.assertIn(pre + '\tWRITE_ONCE(sc2355_hif.hif, NULL);', text)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef __HIF_H__
|
||||
#define __HIF_H__
|
||||
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <misc/marlin_platform.h>
|
||||
|
||||
@@ -117,6 +118,8 @@ struct sprd_hif {
|
||||
|
||||
int exit;
|
||||
atomic_t power_cnt;
|
||||
/* MU300: one WCN power transition at a time (sprd_iface_set_power) */
|
||||
struct mutex power_lock;
|
||||
int flag;
|
||||
int lastflag;
|
||||
u8 cp_asserted;
|
||||
@@ -289,6 +292,9 @@ static inline int sprd_hif_power_on(struct sprd_hif *hif)
|
||||
}
|
||||
|
||||
if (sprd_hif_post_init(hif)) {
|
||||
/* MU300: post_init unwound its channels; the chip was started, stop it as a power-off would */
|
||||
if (stop_marlin(MARLIN_WIFI))
|
||||
pr_err("stop_marlin failed!!\n");
|
||||
atomic_sub(1, &hif->power_cnt);
|
||||
return -ENODEV;
|
||||
}
|
||||
@@ -301,6 +307,15 @@ static inline int sprd_hif_power_on(struct sprd_hif *hif)
|
||||
}
|
||||
|
||||
if (sprd_sync_version(hif)) {
|
||||
/*
|
||||
* MU300: undo the power-on as sprd_hif_power_off() does. The vendor left the channels registered
|
||||
* and the chip started with the count at 0: the next power-on registered them again over live ones,
|
||||
* and a probe that failed here freed hif under channels that could still interrupt.
|
||||
*/
|
||||
sprd_clean_work(hif->priv);
|
||||
sprd_hif_post_deinit(hif);
|
||||
if (stop_marlin(MARLIN_WIFI))
|
||||
pr_err("stop_marlin failed!!\n");
|
||||
atomic_sub(1, &hif->power_cnt);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@@ -266,6 +266,15 @@ int sprd_iface_set_power(struct sprd_hif *hif, int val)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/*
|
||||
* MU300: power_cnt is atomic, the transitions behind it are not. Probe powers the chip off after it
|
||||
* registered wlan0, outside RTNL, so userspace (hostapd, netifd) can open the interface meanwhile: the
|
||||
* open's power-on (1st count) ran start_marlin + post_init while the probe's power-off (last count) was
|
||||
* still in post_deinit. post_deinit then cleared the channels and sc2355_hif.hif that post_init had just
|
||||
* set, stop_marlin powered the chip down, and the next RX interrupt read hif->rx_mgmt from NULL
|
||||
* (pcie_rx_handle+0x34, "paging request at 00000000000030b8", FINDINGS 31n). One transition at a time.
|
||||
*/
|
||||
mutex_lock(&hif->power_lock);
|
||||
if (val) {
|
||||
sprd_wlan_power_status_sync(1, 1);
|
||||
ret = sprd_hif_power_on(hif);
|
||||
@@ -276,12 +285,14 @@ int sprd_iface_set_power(struct sprd_hif *hif, int val)
|
||||
else if (ret == -EIO)
|
||||
pr_err("SYNC cmd error!\n");
|
||||
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
if (atomic_read(&hif->power_cnt) == 1)
|
||||
sprd_get_fw_info(hif->priv);
|
||||
} else
|
||||
sprd_hif_power_off(hif);
|
||||
out:
|
||||
mutex_unlock(&hif->power_lock);
|
||||
return ret;
|
||||
}
|
||||
#ifdef DRV_RESET_SELF
|
||||
@@ -1770,6 +1781,7 @@ int sprd_iface_probe(struct platform_device *pdev,
|
||||
iface_set_priv(priv);
|
||||
platform_set_drvdata(pdev, priv);
|
||||
hif = &priv->hif;
|
||||
mutex_init(&hif->power_lock);
|
||||
hif->priv = priv;
|
||||
hif->pdev = pdev;
|
||||
hif->ops = hif_ops;
|
||||
@@ -1792,9 +1804,10 @@ int sprd_iface_probe(struct platform_device *pdev,
|
||||
ret = iface_core_init(&pdev->dev, priv);
|
||||
if (ret) {
|
||||
pr_err("%s core init failed: %d\n", __func__, ret);
|
||||
/* MU300: power off while hif still exists (sprd_core_free frees priv, and hif with it) */
|
||||
sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
sprd_iface_set_power(hif, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1802,9 +1815,9 @@ int sprd_iface_probe(struct platform_device *pdev,
|
||||
if (ret) {
|
||||
pr_err("%s notify init failed: %d\n", __func__, ret);
|
||||
iface_core_deinit(priv);
|
||||
sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
sprd_iface_set_power(hif, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1831,11 +1844,12 @@ int sprd_iface_remove(struct platform_device *pdev)
|
||||
|
||||
iface_notify_deinit(priv);
|
||||
iface_core_deinit(priv);
|
||||
/* MU300: power off while hif still exists (sprd_core_free frees priv, and hif and its lock with it) */
|
||||
pr_info("Power off WCN (%d time)\n", atomic_read(&hif->power_cnt));
|
||||
sprd_iface_set_power(hif, false);
|
||||
sprd_hif_deinit(hif);
|
||||
sprd_core_free(priv);
|
||||
iface_set_priv(NULL);
|
||||
pr_info("Power off WCN (%d time)\n", atomic_read(&hif->power_cnt));
|
||||
sprd_iface_set_power(hif, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ static int pcie_rx_handle(int chn, struct mbuf_t *head,
|
||||
struct mbuf_t *tail, int num)
|
||||
{
|
||||
struct sprd_hif *hif = sc2355_pcie_get_hif();
|
||||
struct rx_mgmt *rx_mgmt = (struct rx_mgmt *)hif->rx_mgmt;
|
||||
struct rx_mgmt *rx_mgmt;
|
||||
struct sprd_msg *msg = NULL;
|
||||
int buf_num = 0, len = 0, ret = 0;
|
||||
struct mbuf_t *pos = head;
|
||||
@@ -394,6 +394,20 @@ static int pcie_rx_handle(int chn, struct mbuf_t *head,
|
||||
pr_debug("%s: channel:%d head:%p tail:%p num:%d\n",
|
||||
__func__, chn, head, tail, num);
|
||||
|
||||
/*
|
||||
* MU300: an RX interrupt outside the channels' lifetime (post_init publishes hif before it registers
|
||||
* them, post_deinit clears it after it unregistered them, sprd_iface_set_power serialises the two).
|
||||
* Without hif there is no device to unmap the buffers from and no queue to hand them to, and the
|
||||
* channel's mbuf pool is already freed (no sprdwcn_bus_list_free): the data buffers of this one list
|
||||
* leak, and it is said once. A NULL here was a panic in hard IRQ (FINDINGS 31n).
|
||||
*/
|
||||
rx_mgmt = hif ? (struct rx_mgmt *)READ_ONCE(hif->rx_mgmt) : NULL;
|
||||
if (unlikely(!rx_mgmt)) {
|
||||
pr_err_once("%s: RX on channel %d with no Wi-Fi context, %d buffer(s) dropped\n",
|
||||
__func__, chn, num);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (buf_num = num; buf_num > 0; buf_num--, pos = pos->next) {
|
||||
if (unlikely(!pos)) {
|
||||
pr_err("%s: NULL mbuf\n", __func__);
|
||||
@@ -660,7 +674,7 @@ out:
|
||||
|
||||
struct sprd_hif *sc2355_pcie_get_hif(void)
|
||||
{
|
||||
return (struct sprd_hif *)sc2355_hif.hif;
|
||||
return (struct sprd_hif *)smp_load_acquire(&sc2355_hif.hif);
|
||||
}
|
||||
|
||||
#define INTF_IS_PCIE \
|
||||
@@ -2019,7 +2033,8 @@ int pcie_post_init(struct sprd_hif *hif)
|
||||
{
|
||||
int ret = -EINVAL, chn = 0;
|
||||
|
||||
sc2355_hif.hif = (void *)hif;
|
||||
/* MU300: published before any channel can interrupt (the RX/TX callbacks read it in hard IRQ) */
|
||||
smp_store_release(&sc2355_hif.hif, (void *)hif);
|
||||
/*
|
||||
* MU300 (from kanoqwq/mu300-linux): a failed/aborted earlier power cycle clears this pointer in the
|
||||
* error path below. The vendor driver only restores it in pcie_init(),
|
||||
@@ -2065,7 +2080,8 @@ void pcie_post_deinit(struct sprd_hif *hif)
|
||||
|
||||
for (chn = 0; chn < sc2355_hif.max_num; chn++)
|
||||
sprdwcn_bus_chn_deinit(&sc2355_hif.mchn_ops[chn]);
|
||||
sc2355_hif.hif = NULL;
|
||||
/* MU300: cleared only after every channel is unregistered (the callbacks check for NULL) */
|
||||
WRITE_ONCE(sc2355_hif.hif, NULL);
|
||||
sc2355_hif.max_num = 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user