From: Arend van Spriel <arend.vanspriel@broadcom.com>
To: Soeren Coremans <sorencoremans@gmail.com>
Cc: linux-wireless@vger.kernel.org, arend.vanspriel@broadcom.com,
brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com
Subject: Re: [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors
Date: Thu, 26 Nov 2026 15:29:33 +0100 [thread overview]
Message-ID: <20261126142933.875175-4-arend.vanspriel@broadcom.com> (raw)
In-Reply-To: <20261105215954.184290-4-sorencoremans@gmail.com>
On Thu, 5 Nov 2026 22:59:54 +0100, Soeren Coremans <sorencoremans@gmail.com> wrote:
> brcmfmac registers no pci_error_handlers, so a fatal AER error leaves
> the device dead until reboot ("AER: can't recover (no error_detected
> callback)"). On a BCM4366 this happens after some firmware traps: the
> trap starts a driver reset, and about 0.7 s later the downstream port
> reports an FCP error.
>
> Add error handlers:
>
> - error_detected: mark the bus down, block the driver's own reset work
> and request a link reset.
> - slot_reset: restore the config space saved at probe, then check that
> the backplane answers; a wedged card would stall the CPU on every
> MMIO read during firmware download.
> - resume: re-probe the device from a work item. The link reset returns
> the chip to its power-on state, which brcmf_pcie_reset() does not
> fully re-initialise: after it, association failed in 5 of 9 runs,
> while 16 of 16 re-probes recovered.
>
> A dongle setup that fails while recovery is in progress no longer
> releases the driver, as that would race with the re-probe.
>
> Tested with aer_inject (FCP on the downstream port), alone and 0.3 s
> after a debugfs-triggered reset: WiFi back within 6-12 s in 16 of 16
> runs, on a BCM4366/4 (14e4:43c3) with a kernel built from the
> Ubuntu 7.0.0-42 source, which is based on v7.0.14.
>
> Also tested against real FCP errors, without injection: resets under WiFi
> traffic caused 3 in 47 runs, and all 3 recovered within 4-11 s.
>
> This relies on the console read fix earlier in this series: without it,
> a reset that is already running on the dead device never finishes, and
> error_detected() waits for it forever.
>
> Found and written with the help of an AI coding assistant (Claude Opus
> 5.5); the cover letter describes how.
>
> Signed-off-by: Soeren Coremans <sorencoremans@gmail.com>
> ---
> .../broadcom/brcm80211/brcmfmac/pcie.c | 128 +++++++++++++++++-
> 1 file changed, 127 insertions(+), 1 deletion(-)
[...]
> @@ -3153,11 +3160,117 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = {
> MODULE_DEVICE_TABLE(pci, brcmf_pcie_devid_table);
>
>
> +static pci_ers_result_t brcmf_pcie_error_detected(struct pci_dev *pdev,
> + pci_channel_state_t state)
> +{
> + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev);
> + struct brcmf_pciedev_info *devinfo;
> +
> + if (!bus)
> + return PCI_ERS_RESULT_DISCONNECT;
> + if (state == pci_channel_io_perm_failure)
> + return PCI_ERS_RESULT_DISCONNECT;
> + if (state == pci_channel_io_normal)
> + return PCI_ERS_RESULT_CAN_RECOVER;
> +
> + devinfo = bus->bus_priv.pcie->devinfo;
> + brcmf_err(bus, "PCIe link frozen, resetting\n");
> + WRITE_ONCE(devinfo->in_pci_recovery, true);
> + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN;
> + brcmf_bus_cancel_reset_work(bus);
> +
> + return PCI_ERS_RESULT_NEED_RESET;
> +}
This only drains the bus reset work. The firmware callback brcmf_pcie_setup()
queued by brcmf_pcie_reset() runs from the firmware loader and nothing here
waits for it. It can be in flight, e.g. polling for firmware init in
brcmf_pcie_download_fw_nvram(), or not have started yet. It then uses the
BAR0 window concurrently with slot_reset(), and the re-probe can free devinfo
and bus underneath it. Please make sure that callback has finished (or cannot
start) before the link is reset and the device re-probed.
Also, the setup failure path only tests in_pci_recovery before calling
device_release_driver(). If error_detected() runs after that test, the device
gets released between error_detected() and slot_reset(), which then finds no
drvdata and gives up.
[...]
> +static struct workqueue_struct *brcmf_pcie_err_wq;
> +
> +struct brcmf_pcie_reprobe {
> + struct work_struct work;
> + struct pci_dev *pdev;
> +};
> +
> +static void brcmf_pcie_reprobe_worker(struct work_struct *work)
> +{
> + struct brcmf_pcie_reprobe *rp =
> + container_of(work, struct brcmf_pcie_reprobe, work);
> + int err;
> +
> + err = device_reprobe(&rp->pdev->dev);
> + if (err)
> + pci_err(rp->pdev, "re-probe after PCIe error failed: %d\n", err);
> + pci_dev_put(rp->pdev);
> + kfree(rp);
> +}
> +
> +/* A link reset returns the chip to its power-on state, which only a full
> + * probe initialises correctly. The re-probe frees all driver data, so it
> + * runs from a work item that holds nothing but the PCI device.
> + */
> +static void brcmf_pcie_resume_from_error(struct pci_dev *pdev)
> +{
> + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev);
> + struct brcmf_pcie_reprobe *rp;
> +
> + if (!bus || !READ_ONCE(bus->bus_priv.pcie->devinfo->in_pci_recovery))
> + return;
> +
> + rp = kzalloc_obj(*rp);
> + if (!rp)
> + return;
> + brcmf_err(bus, "PCIe link recovered, re-probing\n");
> + INIT_WORK(&rp->work, brcmf_pcie_reprobe_worker);
> + rp->pdev = pci_dev_get(pdev);
> + queue_work(brcmf_pcie_err_wq, &rp->work);
> +}
> +
If recovery is abandoned (slot_reset() returns DISCONNECT, or the allocation
above fails) in_pci_recovery stays set, so later dongle setup failures are
ignored without releasing the driver, and the allocation failure is not even
logged.
brcmf_pcie_pm_leave_D3() already calls brcmf_pcie_remove() and
brcmf_pcie_probe() directly from a callback that runs under the device lock.
Is there a reason resume() cannot do the same instead of using a work item, a
dedicated workqueue and device_reprobe()?
The series "wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips"
(https://patchwork.kernel.org/series/1208304/) changes the same code. Its last
patch adds deep sleep state handling to brcmf_pcie_remove() and hooks on the ring
lock that wake the device. A re-probe after a link reset runs that remove path on a
device that does not answer, and error_detected() only sets devinfo->state to DOWN
and leaves the deep sleep state alone. The series also adds its own re-probe after
a resume through platform firmware. Please check recovery with that series applied,
and make sure an error during resume cannot start both re-probes. Whichever series
is applied second will need a rebase.
The commit message says brcmf_pcie_reset() is not enough after a link reset
and the cover letter leaves the cause open. I would like to know which part of
the probe-time setup is missing before settling on a full re-probe.
The pci_err() line in brcmf_pcie_reprobe_worker() and the brcmf_err() line in
brcmf_pcie_slot_reset() are 81 columns, see the checkpatch warning.
Regards,
Arend
next prev parent reply other threads:[~2026-11-26 14:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans
2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans
2026-11-26 14:29 ` Arend van Spriel
2026-11-05 21:59 ` [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window Soeren Coremans
2026-11-26 14:29 ` Arend van Spriel
2026-11-05 21:59 ` [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans
2026-11-26 14:29 ` Arend van Spriel [this message]
2026-11-26 14:29 ` [PATCH wireless-next 0/3] " Arend van Spriel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126142933.875175-4-arend.vanspriel@broadcom.com \
--to=arend.vanspriel@broadcom.com \
--cc=brcm80211-dev-list.pdl@broadcom.com \
--cc=brcm80211@lists.linux.dev \
--cc=linux-wireless@vger.kernel.org \
--cc=sorencoremans@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox