diff --git a/Documentation/networking/device_drivers/wifi/mt7932-neo.rst b/Documentation/networking/device_drivers/wifi/mt7932-neo.rst index 0387cb98098a3..220eff6fbbcad 100644 --- a/Documentation/networking/device_drivers/wifi/mt7932-neo.rst +++ b/Documentation/networking/device_drivers/wifi/mt7932-neo.rst @@ -53,7 +53,8 @@ performance policy. ``mt7932_bt_pcie`` defers its probe until ``mt7932-fullmac`` is bound to function 0, so the Bluetooth firmware always starts after the Wi-Fi firmware, as in the tested sequence, however the drivers are loaded. Bluetooth therefore -stays unbound while the Wi-Fi driver is missing or has failed. A device link +stays unbound while the Wi-Fi driver is missing or has failed, including when +a failed Wi-Fi function stays bound to keep DMA it could not stop. A device link makes the driver core unbind Bluetooth before Wi-Fi; unloading ``mt7932_bt_pcie`` does not affect Wi-Fi. The probe rejects a function that is not cold, which is what now prevents a reprobe after a failed or uncertain diff --git a/MAINTAINERS b/MAINTAINERS index 72b6e43702b5d..99987f9eca95b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1975,6 +1975,7 @@ F: Documentation/devicetree/bindings/power/apple,t8140-pmp-report.yaml F: Documentation/devicetree/bindings/soc/apple/apple,pmp.yaml F: drivers/pmdomain/apple/pmp-report.c F: drivers/soc/apple/pmp.rs +F: include/linux/mt7932.h F: include/linux/soc/apple/pmp-report.h F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-quiesced.yaml F: Documentation/devicetree/bindings/display/apple,dcp.yaml diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index da96e2f2c05e3..0456ec45b5ec0 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -27,14 +27,15 @@ config BT_MTK7932_PCIE tristate "J700 MT7932 PCIe Bluetooth transport" depends on BT && PCI && ARCH_APPLE && IOMMU_DMA depends on !KEXEC_CORE - depends on MT7932_FULLMAC != n + depends on MT7932_FULLMAC select FW_LOADER help Support the J700 Bluetooth PCIe function with locally installed firmware - and calibration. The function is probed once the Wi-Fi function is - bound to the mt7932-fullmac driver; the enable=0 parameter leaves it - unbound. Both functions appear before the root filesystem is mounted - and read their firmware when probed, so say M, like the Wi-Fi driver. + and calibration. The function is probed once the Wi-Fi function has + initialized under the mt7932-fullmac driver; the enable=0 parameter + leaves it unbound. Both functions appear before the root filesystem + is mounted and read their firmware when probed, so say M, like the + Wi-Fi driver. System suspend uses the firmware sleep handshake and preserves DMA storage. Hibernation and automatic firmware recovery are unsupported. Removal drains the PCI function before releasing device-visible memory; diff --git a/drivers/bluetooth/mt7932_bt_pcie.c b/drivers/bluetooth/mt7932_bt_pcie.c index f3ac19f810736..36655c25f88f5 100644 --- a/drivers/bluetooth/mt7932_bt_pcie.c +++ b/drivers/bluetooth/mt7932_bt_pcie.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1050,6 +1051,10 @@ static int bt7932_wait_for_wifi(struct pci_dev *pdev) strcmp(dev_driver_string(&wifi->dev), "mt7932-fullmac")) ret = dev_err_probe(&pdev->dev, -EPROBE_DEFER, "waiting for the Wi-Fi function\n"); + /* Initialization ends before the Wi-Fi probe returns. */ + else if (!mt7932_fullmac_ready(wifi)) + ret = dev_err_probe(&pdev->dev, -ENODEV, + "the Wi-Fi function failed to initialize\n"); else if (!device_link_add(&pdev->dev, &wifi->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) ret = -EINVAL; pci_dev_put(wifi); diff --git a/drivers/net/wireless/mediatek/mt7932/mt7932.c b/drivers/net/wireless/mediatek/mt7932/mt7932.c index 85440558e95a4..fa759a964e06c 100644 --- a/drivers/net/wireless/mediatek/mt7932/mt7932.c +++ b/drivers/net/wireless/mediatek/mt7932/mt7932.c @@ -3,6 +3,7 @@ * Clean-room contract: NEO_MT7932_DOWNLOAD_AND_NIC_CAP_CONTRACT.md. * All addresses here are BAR0 offsets, never chip/CPU physical addresses. */ +#include #include "mt7932.h" static int mt_ring_alloc(struct mt7932 *m, struct mt7932_ring *q, @@ -1251,6 +1252,8 @@ static int mt_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret = mt_reset_retained(&m); if (!ret) ret = mt_register_regulatory_gate(m); + if (!ret) + WRITE_ONCE(m->ready, true); retain: if (ret) { int error = ret; @@ -1293,6 +1296,27 @@ static struct pci_driver mt_driver = { .shutdown = mt_shutdown, .driver.suppress_bind_attrs = true, }; + +/** + * mt7932_fullmac_ready() - check that the Wi-Fi function is up + * @pdev: function 0 of the radio + * + * A Wi-Fi function whose initialization failed stays bound when its DMA + * could not be stopped, so being bound does not mean its firmware runs. + * + * Return: true if @pdev is bound to this driver and finished initialization. + */ +bool mt7932_fullmac_ready(struct pci_dev *pdev) +{ + struct mt7932 *m; + + if (!device_is_bound(&pdev->dev) || pdev->dev.driver != &mt_driver.driver) + return false; + m = pci_get_drvdata(pdev); + return m && READ_ONCE(m->ready); +} +EXPORT_SYMBOL_GPL(mt7932_fullmac_ready); + module_pci_driver(mt_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("J700 MT7932 firmware-owned cfg80211 station driver"); diff --git a/drivers/net/wireless/mediatek/mt7932/mt7932.h b/drivers/net/wireless/mediatek/mt7932/mt7932.h index f6fc1f235e619..93e7fa5629acb 100644 --- a/drivers/net/wireless/mediatek/mt7932/mt7932.h +++ b/drivers/net/wireless/mediatek/mt7932/mt7932.h @@ -76,6 +76,8 @@ struct mt7932 { u64 interrupts, packets; bool running; bool stopping; + /* Probe finished initialization; the Bluetooth function may start. */ + bool ready; bool irq_requested, vectors_allocated, wiphy_registered; bool dma_owned; struct completion reset_retry; diff --git a/include/linux/mt7932.h b/include/linux/mt7932.h new file mode 100644 index 0000000000000..9ab60efa49786 --- /dev/null +++ b/include/linux/mt7932.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Interface between the functions of the J700 MT7932 radio. + */ +#ifndef __LINUX_MT7932_H +#define __LINUX_MT7932_H + +#include + +struct pci_dev; + +bool mt7932_fullmac_ready(struct pci_dev *pdev); + +#endif /* __LINUX_MT7932_H */