From 1d48270c5632cc953cf2416348e17d32b260d927 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 28 Nov 2026 23:54:53 +1100 Subject: [PATCH] wifi: brcmfmac: pcie: skip pointer updates for unconfigured rings Flowring descriptors are zero-initialized and get their callbacks before brcmf_commonring_config() sets a nonzero depth. Updating a pointer on one of these rings reports a false "r_ptr 0 outside depth 0" error. Return -EIO quietly before reading either firmware index while the depth is zero. Keep the bounds check, error message and last good pointer for configured rings unchanged. Extend the shared TCM host controls to check that unconfigured flowrings neither read firmware indices nor log errors, and that out-of-range pointers on configured rings still report errors. Add a mutation that removes the unconfigured-ring guard. Fixes: 73d8f7cde268 ("wifi: brcmfmac: pcie: take ring pointers from the dongle only inside the ring") Signed-off-by: Ryan Murray --- .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ tools/asahi/brcmf-shared-tcm-tests.py | 13 ++++++++++++- tools/asahi/run-host-tests.py | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 0992446c01b22..ac9acda72b6a0 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1503,6 +1503,10 @@ static int brcmf_pcie_ring_mb_update_rptr(void *ctx) if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) return -EIO; + /* Flowrings are allocated before their depth is configured. */ + if (!commonring->depth) + return -EIO; + /* The dongle's index is only used inside the ring; keep the last good one */ ptr = devinfo->read_ptr(devinfo, ring->r_idx_addr); if (ptr >= commonring->depth) { @@ -1530,6 +1534,10 @@ static int brcmf_pcie_ring_mb_update_wptr(void *ctx) if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) return -EIO; + /* Flowrings are allocated before their depth is configured. */ + if (!commonring->depth) + return -EIO; + /* The dongle's index is only used inside the ring; keep the last good one */ ptr = devinfo->read_ptr(devinfo, ring->w_idx_addr); if (ptr >= commonring->depth) { diff --git a/tools/asahi/brcmf-shared-tcm-tests.py b/tools/asahi/brcmf-shared-tcm-tests.py index bc9242bb14fd1..11d30d870c714 100755 --- a/tools/asahi/brcmf-shared-tcm-tests.py +++ b/tools/asahi/brcmf-shared-tcm-tests.py @@ -209,7 +209,17 @@ def define(source, name): assert(rb->commonring.r_ptr == 63 && rb->commonring.w_ptr == 10); put16(rb->r_idx_addr, 64); put16(rb->w_idx_addr, 0xffff); assert(brcmf_pcie_ring_mb_update_rptr(rb) == -EIO && brcmf_pcie_ring_mb_update_wptr(rb) == -EIO); - assert(rb->commonring.r_ptr == 63 && rb->commonring.w_ptr == 10); cases++; + assert(rb->commonring.r_ptr == 63 && rb->commonring.w_ptr == 10 && errs == 2); cases++; + /* Allocated flowrings have no depth until configured: do not read or log their indices. */ + reset(); devinfo.state = BRCMFMAC_PCIE_STATE_UP; assert(!init() && !rings()); + rb = &devinfo.shared.flowrings[0]; assert(!rb->commonring.depth); + const u16 unconfigured_ptrs[] = { 0, 0xffff }; + for (unsigned i = 0; i < sizeof(unconfigured_ptrs) / sizeof(unconfigured_ptrs[0]); i++) { + put16(rb->r_idx_addr, unconfigured_ptrs[i]); put16(rb->w_idx_addr, unconfigured_ptrs[i]); + unsigned long before = reads; + assert(brcmf_pcie_ring_mb_update_rptr(rb) == -EIO && brcmf_pcie_ring_mb_update_wptr(rb) == -EIO); + assert(!rb->commonring.r_ptr && !rb->commonring.w_ptr && !errs && reads == before); cases++; + } /* A console descriptor or buffer outside the TCM leaves the console off; setup goes on. */ reset(); put32(SHARED + BRCMF_SHARED_CONSOLE_ADDR_OFFSET, TCM_SIZE - 4); assert(!init() && !devinfo.shared.console.base_addr); cases++; @@ -254,6 +264,7 @@ def define(source, name): '\tptr = devinfo->read_ptr(devinfo, ring->r_idx_addr);\n\tif (false) {'), 'wptr-depth': ('\tptr = devinfo->read_ptr(devinfo, ring->w_idx_addr);\n\tif (ptr >= commonring->depth) {', '\tptr = devinfo->read_ptr(devinfo, ring->w_idx_addr);\n\tif (false) {'), + 'unconfigured-depth': ('\tif (!commonring->depth)\n', '\tif (false)\n'), 'console-desc': ('\t !brcmf_pcie_tcm_range_valid(devinfo->tcm_size, console->base_addr,\n' '\t\t\t\t\tBRCMF_CONSOLE_WRITEIDX_OFFSET + 4)) {', '\t false) {'), 'console-none': ('\tif (!console->base_addr ||\n', '\tif (false ||\n'), diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index f0c3bffe5e7ae..0fefad61d81c4 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -189,7 +189,7 @@ def mutations(flag, names, base, expect=KILL): 'brcmf-roam-tests.py': [(out(), PASS)], 'brcmf-shared-tcm-tests.py': [(out(), PASS)] + mutations('--mutation', ('shared', 'htod-mb', 'dtoh-mb', 'ring-info', 'ring-mem', 'ring-idx', - 'flowring-idx', 'dma-counts', 'rptr-depth', 'wptr-depth', + 'flowring-idx', 'dma-counts', 'rptr-depth', 'wptr-depth', 'unconfigured-depth', 'console-desc', 'console-none', 'console-buf', 'console-widx', 'console-reinit'), out()), 'brcmf-sae-vendor-tests.py': [(out(), PASS)]