From 8ff899d9fb6590d9f91d1659cc5e8aac00657aee Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:49:20 -0400 Subject: [PATCH 01/75] firmware: samsung: acpm: defer while the mailbox is missing The channel loop skips a channel that gets no mailbox, so that one bad channel doesn't fail the rest. -EPROBE_DEFER isn't such a channel: it only means the mailbox driver hasn't probed yet. When ACPM probes first, every channel is skipped, the probe succeeds with "16 channels, 0 usable" and never retries, and everything behind ACPM fails for the whole boot. On the Pixel 8 Pro the touchscreen then can't enable its supply ("error -ENODEV: enabling vdd"). This happens when a module load or `udevadm trigger` binds ACPM ahead of the mailbox, or with fw_devlink=permissive, which drops the supplier ordering. Return -EPROBE_DEFER from the probe instead, so it runs again once the mailbox is there. Keep skipping the channels for any other error, and the ones whose queues are outside the SRAM. The channels already requested are freed by the devm action, and the per-channel buffers are devm allocations. Fixes: c8e4c99a7852 ("firmware: samsung: acpm: skip channels the AP cannot use") Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/firmware/samsung/exynos-acpm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index 45f3a56168..cbe830b986 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -738,9 +738,15 @@ static int acpm_channels_init(struct acpm_info *acpm) achan->chan = mbox_request_channel(cl, 0); if (IS_ERR(achan->chan)) { - dev_warn(dev, "chan %d: no mailbox channel (%pe), skipped\n", - i, achan->chan); + ret = PTR_ERR(achan->chan); achan->chan = NULL; + /* The mailbox may simply not have probed yet. */ + if (ret == -EPROBE_DEFER) + return dev_err_probe(dev, ret, + "chan %d: no mailbox channel yet\n", + i); + dev_warn(dev, "chan %d: no mailbox channel (%pe), skipped\n", + i, ERR_PTR(ret)); continue; } From 758c3248af21e9cbb16ea4ca4f45dce9287f4557 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:19:47 -0400 Subject: [PATCH 02/75] dt-bindings: clock: google: Add the Tensor G3 TOP and HSI0 CMUs Document zuma's (Tensor G3) CMU_TOP and CMU_HSI0 as far as the touchscreen's SPI needs them: CMU_TOP's HSI0 NoC and peripheral clocks, and CMU_HSI0's USI2 clocks with the NoC path its bus clock comes from. HSI0 takes the board-level ALT clock as an input. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../bindings/clock/google,zuma-clock.yaml | 107 ++++++++++++++++++ MAINTAINERS | 2 + include/dt-bindings/clock/google,zuma.h | 50 ++++++++ 3 files changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/google,zuma-clock.yaml create mode 100644 include/dt-bindings/clock/google,zuma.h diff --git a/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml b/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml new file mode 100644 index 0000000000..cd708ab082 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/google,zuma-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google Tensor G3 clock controllers + +maintainers: + - Brett-Michael Green + +description: | + CMU_TOP supplies the HSI0 NoC and peripheral clocks to CMU_HSI0 from its + shared PLLs. CMU_HSI0 supplies USI2, the touchscreen's SPI, from the HSI0 + peripheral clock; its NoC path also takes the board-level HSI0 ALT clock. + CMU_APM supplies the APM mailbox, its internal memory and the always-on + GPIO banks from the always-on ALV PLL and the oscillator. + The external oscillator supplies the PLL reference and the oscillator mux + paths. + Clock identifiers are defined in dt-bindings/clock/google,zuma.h. + +properties: + compatible: + enum: + - google,zuma-cmu-top + - google,zuma-cmu-apm + - google,zuma-cmu-hsi0 + + reg: + maxItems: 1 + + "#clock-cells": + const: 1 + + clocks: + minItems: 1 + maxItems: 4 + + clock-names: + minItems: 1 + maxItems: 4 + +required: + - compatible + - reg + - "#clock-cells" + - clocks + - clock-names + +allOf: + - if: + properties: + compatible: + enum: + - google,zuma-cmu-top + - google,zuma-cmu-apm + then: + properties: + clocks: + items: + - description: External oscillator reference clock + clock-names: + items: + - const: oscclk + - if: + properties: + compatible: + const: google,zuma-cmu-hsi0 + then: + properties: + clocks: + items: + - description: External oscillator reference clock + - description: HSI0 NoC clock from CMU_TOP + - description: HSI0 peripheral clock from CMU_TOP + - description: HSI0 ALT input clock + clock-names: + items: + - const: oscclk + - const: bus + - const: peri + - const: alt + +additionalProperties: false + +examples: + - | + #include + + cmu_top: clock-controller@26040000 { + compatible = "google,zuma-cmu-top"; + reg = <0x26040000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; + + clock-controller@11000000 { + compatible = "google,zuma-cmu-hsi0"; + reg = <0x11000000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>, <&cmu_top CLK_DOUT_HSI0_NOC>, + <&cmu_top CLK_DOUT_HSI0_PERI>, <&hsi0_alt>; + clock-names = "oscclk", "bus", "peri", "alt"; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index 4841af951f..06e037ea99 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11166,6 +11166,7 @@ P: Documentation/process/maintainer-soc-clean-dts.rst C: irc://irc.oftc.net/pixel6-kernel-dev F: Documentation/devicetree/bindings/clock/google,gs101-clock.yaml F: Documentation/devicetree/bindings/clock/google,gs201-clock.yaml +F: Documentation/devicetree/bindings/clock/google,zuma-clock.yaml F: Documentation/devicetree/bindings/clock/google,zumapro* F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-dtzpc.yaml @@ -11184,6 +11185,7 @@ F: drivers/thermal/samsung/gs101_acpm_tmu.c F: drivers/usb/dwc3/dwc3-google.c F: include/dt-bindings/clock/google,gs101* F: include/dt-bindings/clock/google,gs201* +F: include/dt-bindings/clock/google,zuma.h F: include/dt-bindings/clock/google,zumapro* K: [gG]oogle.?[tT]ensor diff --git a/include/dt-bindings/clock/google,zuma.h b/include/dt-bindings/clock/google,zuma.h new file mode 100644 index 0000000000..45aef7817c --- /dev/null +++ b/include/dt-bindings/clock/google,zuma.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +#ifndef _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H +#define _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H + +/* CMU_TOP: the HSI0 NoC and peripheral clock paths. */ +#define CLK_FOUT_SHARED0 1 +#define CLK_FOUT_SHARED1 2 +#define CLK_FOUT_SHARED2 3 +#define CLK_FOUT_SHARED3 4 +#define CLK_FOUT_SPARE 5 +#define CLK_SHARED0_D4 6 +#define CLK_SHARED1_D4 7 +#define CLK_SHARED2_D2 8 +#define CLK_SHARED3_D2 9 +#define CLK_MOUT_HSI0_NOC 10 +#define CLK_GOUT_HSI0_NOC 11 +#define CLK_DOUT_HSI0_NOC 12 +#define CLK_MOUT_HSI0_PERI 13 +#define CLK_GOUT_HSI0_PERI 14 +#define CLK_DOUT_HSI0_PERI 15 + +/* CMU_HSI0: USI2, the touchscreen's SPI. */ +#define CLK_GOUT_HSI0_ALT 1 +#define CLK_MOUT_HSI0_NOC_USER 2 +#define CLK_MOUT_HSI0_ALT_USER 3 +#define CLK_MOUT_HSI0_NOC_LOCAL 4 +#define CLK_MOUT_HSI0_PERI_USER 5 +#define CLK_MOUT_HSI0_USI2 6 +#define CLK_GOUT_HSI0_USI2_SOURCE 7 +#define CLK_DOUT_HSI0_USI2 8 +#define CLK_GOUT_HSI0_USI2_IP 9 +#define CLK_GOUT_HSI0_USI2_PCLK 10 + +/* CMU_APM: the APM mailbox, its SRAM and the always-on GPIO banks. */ +#define CLK_APM_PLL_ALV_DIV2 1 +#define CLK_APM_PLL_ALV_DIV4 2 +#define CLK_APM_PLL_ALV_DIV8 3 +#define CLK_APM_PLL_ALV_DIV16 4 +#define CLK_MOUT_APM_FUNCSRC 5 +#define CLK_MOUT_APM_FUNC 6 +#define CLK_GOUT_APM_FUNC 7 +#define CLK_DOUT_APM_NOC 8 +#define CLK_GOUT_APM_MAILBOX_AP 9 +#define CLK_GOUT_APM_INTMEM_ACLK 10 +#define CLK_GOUT_APM_INTMEM_PCLK 11 +#define CLK_GOUT_APM_GPIO_ALIVE 12 +#define CLK_GOUT_APM_GPIO_FAR_ALIVE 13 +#define CLK_GOUT_APM_GPIO_CUSTOM_ALIVE 14 + +#endif /* _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H */ From f66fd615e20e58738f2335ee1bee4f73b6d87010 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:19:47 -0400 Subject: [PATCH 03/75] clk: samsung: Add the Tensor G3 touchscreen SPI clocks zuma has no clock driver, and the bootloader leaves HSI0's USI2, the touchscreen's SPI, at 399.36 MHz (PLL_SHARED2 / 2). The SPI controller takes its rate from the CMU, so the bus would run at a quarter of that, far above the 10 MHz stock gives the touch controller. Describe the path from CMU_TOP's shared PLLs to USI2, with registers and parents from Google's GPL CMUCAL tables for zuma. Only USI2's divider and its three gates are written; the PLLs, muxes and the other dividers and gates are read-only and keep their firmware settings. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- MAINTAINERS | 1 + drivers/clk/samsung/Makefile | 1 + drivers/clk/samsung/clk-zuma.c | 253 +++++++++++++++++++++++++++++++++ 3 files changed, 255 insertions(+) create mode 100644 drivers/clk/samsung/clk-zuma.c diff --git a/MAINTAINERS b/MAINTAINERS index 06e037ea99..d5c748f6f6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11176,6 +11176,7 @@ F: Documentation/devicetree/bindings/usb/google,lga-dwc3.yaml F: arch/arm64/boot/dts/exynos/google/ F: drivers/clk/samsung/clk-gs101.c F: drivers/clk/samsung/clk-gs201.c +F: drivers/clk/samsung/clk-zuma.c F: drivers/clk/samsung/clk-zumapro.c F: drivers/phy/phy-google-usb.c F: drivers/soc/samsung/gs101-pmu.c diff --git a/drivers/clk/samsung/Makefile b/drivers/clk/samsung/Makefile index c2df88230e..0b299f87f8 100644 --- a/drivers/clk/samsung/Makefile +++ b/drivers/clk/samsung/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov9.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov920.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-gs101.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-gs201.o +obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-zuma.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-zumapro.o obj-$(CONFIG_EXYNOS_ACPM_CLK) += clk-acpm.o obj-$(CONFIG_S3C64XX_COMMON_CLK) += clk-s3c64xx.o diff --git a/drivers/clk/samsung/clk-zuma.c b/drivers/clk/samsung/clk-zuma.c new file mode 100644 index 0000000000..ccb80f62e4 --- /dev/null +++ b/drivers/clk/samsung/clk-zuma.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google Tensor G3 (zuma) clocks for the touchscreen and its PMIC. + * + * Register layout and parents derived from Google's GPL CMUCAL tables in + * cal-if/zuma/cmucal-{sfr,node}.c, Copyright 2022 Samsung Electronics Co., Ltd. + * Only the path from CMU_TOP to HSI0's USI2 is described, with CMU_APM's + * clocks for the APM mailbox, its SRAM and the always-on GPIO banks. PLLs, + * muxes and dividers keep their firmware settings, except USI2's own + * divider, which sets the SPI rate. No PLL rate table is supplied. + */ + +#include +#include +#include +#include +#include + +#include + +#include "clk.h" +#include "clk-exynos-arm64.h" +#include "clk-pll.h" + +/* CMU_TOP, 0x26040000. PLL CON3 is the read-only rate source. */ +static const struct samsung_pll_clock top_plls[] __initconst = { + PLL(pll_0517x, CLK_FOUT_SHARED0, "zuma_shared0", "oscclk", + 0x004, 0x14c, NULL), + PLL(pll_0517x, CLK_FOUT_SHARED1, "zuma_shared1", "oscclk", + 0x008, 0x18c, NULL), + PLL(pll_0518x, CLK_FOUT_SHARED2, "zuma_shared2", "oscclk", + 0x00c, 0x1cc, NULL), + PLL(pll_0518x, CLK_FOUT_SHARED3, "zuma_shared3", "oscclk", + 0x010, 0x20c, NULL), + PLL(pll_0518x, CLK_FOUT_SPARE, "zuma_spare", "oscclk", + 0x014, 0x24c, NULL), +}; + +static const struct samsung_fixed_factor_clock top_factors[] __initconst = { + FFACTOR(CLK_SHARED0_D4, "zuma_shared0_d4", "zuma_shared0", 1, 4, 0), + FFACTOR(CLK_SHARED1_D4, "zuma_shared1_d4", "zuma_shared1", 1, 4, 0), + FFACTOR(CLK_SHARED2_D2, "zuma_shared2_d2", "zuma_shared2", 1, 2, 0), + FFACTOR(CLK_SHARED3_D2, "zuma_shared3_d2", "zuma_shared3", 1, 2, 0), +}; + +PNAME(mout_hsi0_noc_parents) = { + "zuma_shared0_d4", "zuma_shared1_d4", "zuma_shared2_d2", + "zuma_shared3_d2", "zuma_spare", "oscclk", "oscclk", "oscclk", +}; + +PNAME(mout_hsi0_peri_parents) = { + "zuma_shared0_d4", "zuma_shared2_d2", "zuma_shared3_d2", "zuma_spare", +}; + +static const struct samsung_mux_clock top_muxes[] __initconst = { + MUX_F(CLK_MOUT_HSI0_NOC, "zuma_mout_hsi0_noc", mout_hsi0_noc_parents, + 0x1094, 0, 3, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_PERI, "zuma_mout_hsi0_peri", mout_hsi0_peri_parents, + 0x1098, 0, 2, 0, CLK_MUX_READ_ONLY), +}; + +/* The hardware order is mux -> gate -> divider. HSI0 is firmware-owned. */ +static const struct samsung_gate_clock top_ro_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_NOC, "zuma_gout_hsi0_noc", "zuma_mout_hsi0_noc", + 0x20bc, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_HSI0_PERI, "zuma_gout_hsi0_peri", "zuma_mout_hsi0_peri", + 0x20c0, 21, CLK_IGNORE_UNUSED, 0), +}; + +static const struct samsung_div_clock top_dividers[] __initconst = { + DIV_F(CLK_DOUT_HSI0_NOC, "zuma_dout_hsi0_noc", "zuma_gout_hsi0_noc", + 0x188c, 0, 4, 0, CLK_DIVIDER_READ_ONLY), + DIV_F(CLK_DOUT_HSI0_PERI, "zuma_dout_hsi0_peri", "zuma_gout_hsi0_peri", + 0x1890, 0, 4, 0, CLK_DIVIDER_READ_ONLY), +}; + +static const struct samsung_cmu_info top_cmu __initconst = { + .pll_clks = top_plls, + .nr_pll_clks = ARRAY_SIZE(top_plls), + .fixed_factor_clks = top_factors, + .nr_fixed_factor_clks = ARRAY_SIZE(top_factors), + .mux_clks = top_muxes, + .nr_mux_clks = ARRAY_SIZE(top_muxes), + .ro_gate_clks = top_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(top_ro_gates), + .div_clks = top_dividers, + .nr_div_clks = ARRAY_SIZE(top_dividers), + .nr_clk_ids = CLK_DOUT_HSI0_PERI + 1, +}; + +static void __init zuma_top_init(struct device_node *np) +{ + exynos_arm64_register_cmu(NULL, np, &top_cmu); +} + +CLK_OF_DECLARE(zuma_cmu_top, "google,zuma-cmu-top", zuma_top_init); + +/* + * CMU_APM, 0x15400000. The always-on domain is firmware-owned, so it is + * read-only. ALV runs at the oscillator times 32. + */ +static const struct samsung_fixed_rate_clock apm_fixed_clks[] __initconst = { + FRATE(CLK_APM_PLL_ALV_DIV2, "zuma_apm_pll_alv_div2", NULL, 0, 393216000), + FRATE(CLK_APM_PLL_ALV_DIV4, "zuma_apm_pll_alv_div4", NULL, 0, 196608000), + FRATE(CLK_APM_PLL_ALV_DIV8, "zuma_apm_pll_alv_div8", NULL, 0, 98304000), + FRATE(CLK_APM_PLL_ALV_DIV16, "zuma_apm_pll_alv_div16", NULL, 0, 49152000), +}; + +PNAME(mout_apm_funcsrc_parents) = { + "zuma_apm_pll_alv_div2", "zuma_apm_pll_alv_div4", + "zuma_apm_pll_alv_div16", "zuma_apm_pll_alv_div8", +}; + +PNAME(mout_apm_func_parents) = { + "oscclk", "zuma_mout_apm_funcsrc", "pad_clk_apm", "oscclk", +}; + +static const struct samsung_mux_clock apm_muxes[] __initconst = { + MUX_F(CLK_MOUT_APM_FUNCSRC, "zuma_mout_apm_funcsrc", + mout_apm_funcsrc_parents, 0x1004, 0, 2, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_APM_FUNC, "zuma_mout_apm_func", mout_apm_func_parents, + 0x1000, 0, 2, 0, CLK_MUX_READ_ONLY), +}; + +static const struct samsung_div_clock apm_dividers[] __initconst = { + DIV_F(CLK_DOUT_APM_NOC, "zuma_dout_apm_noc", "zuma_gout_apm_func", + 0x1808, 0, 3, 0, CLK_DIVIDER_READ_ONLY), +}; + +static const struct samsung_gate_clock apm_ro_gates[] __initconst = { + GATE(CLK_GOUT_APM_FUNC, "zuma_gout_apm_func", "zuma_mout_apm_func", + 0x20d4, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_MAILBOX_AP, "zuma_gout_apm_mailbox_ap", + "zuma_dout_apm_noc", 0x211c, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_INTMEM_ACLK, "zuma_gout_apm_intmem_aclk", + "zuma_dout_apm_noc", 0x2108, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_INTMEM_PCLK, "zuma_gout_apm_intmem_pclk", + "zuma_dout_apm_noc", 0x210c, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_ALIVE, "zuma_gout_apm_gpio_alive", + "zuma_dout_apm_noc", 0x20d8, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_FAR_ALIVE, "zuma_gout_apm_gpio_far_alive", + "zuma_dout_apm_noc", 0x20dc, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_CUSTOM_ALIVE, "zuma_gout_apm_gpio_custom_alive", + "zuma_dout_apm_noc", 0x2000, 21, CLK_IGNORE_UNUSED, 0), +}; + +static const struct samsung_cmu_info apm_cmu __initconst = { + .fixed_clks = apm_fixed_clks, + .nr_fixed_clks = ARRAY_SIZE(apm_fixed_clks), + .mux_clks = apm_muxes, + .nr_mux_clks = ARRAY_SIZE(apm_muxes), + .div_clks = apm_dividers, + .nr_div_clks = ARRAY_SIZE(apm_dividers), + .ro_gate_clks = apm_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(apm_ro_gates), + .nr_clk_ids = CLK_GOUT_APM_GPIO_CUSTOM_ALIVE + 1, +}; + +/* CMU_HSI0, 0x11000000. Firmware keeps the domain powered. */ +PNAME(mout_hsi0_noc_user_parents) = { "oscclk", "zuma_dout_hsi0_noc" }; + +PNAME(mout_hsi0_alt_user_parents) = { "oscclk", "zuma_gout_hsi0_alt" }; + +PNAME(mout_hsi0_noc_local_parents) = { + "zuma_mout_hsi0_noc_user", "zuma_mout_hsi0_alt_user", +}; + +PNAME(mout_hsi0_peri_user_parents) = { "oscclk", "zuma_dout_hsi0_peri" }; + +PNAME(mout_hsi0_usi2_parents) = { "zuma_mout_hsi0_peri_user", "oscclk" }; + +static const struct samsung_mux_clock hsi0_muxes[] __initconst = { + MUX_F(CLK_MOUT_HSI0_NOC_USER, "zuma_mout_hsi0_noc_user", + mout_hsi0_noc_user_parents, 0x620, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_ALT_USER, "zuma_mout_hsi0_alt_user", + mout_hsi0_alt_user_parents, 0x600, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_NOC_LOCAL, "zuma_mout_hsi0_noc_local", + mout_hsi0_noc_local_parents, 0x1000, 0, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_PERI_USER, "zuma_mout_hsi0_peri_user", + mout_hsi0_peri_user_parents, 0x680, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_USI2, "zuma_mout_hsi0_usi2", mout_hsi0_usi2_parents, + 0x101c, 0, 1, 0, CLK_MUX_READ_ONLY), +}; + +static const struct samsung_div_clock hsi0_dividers[] __initconst = { + DIV(CLK_DOUT_HSI0_USI2, "zuma_dout_hsi0_usi2", + "zuma_gout_hsi0_usi2_source", 0x181c, 0, 4), +}; + +static const struct samsung_gate_clock hsi0_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_USI2_SOURCE, "zuma_gout_hsi0_usi2_source", + "zuma_mout_hsi0_usi2", 0x2120, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_HSI0_USI2_IP, "zuma_gout_hsi0_usi2_ip", + "zuma_dout_hsi0_usi2", 0x20fc, 21, + CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0), + GATE(CLK_GOUT_HSI0_USI2_PCLK, "zuma_gout_hsi0_usi2_pclk", + "zuma_mout_hsi0_noc_local", 0x2100, 21, CLK_IGNORE_UNUSED, 0), +}; + +/* Firmware-owned gates are observed, never switched. */ +static const struct samsung_gate_clock hsi0_ro_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_ALT, "zuma_gout_hsi0_alt", "hsi0-alt", + 0x204c, 21, CLK_IGNORE_UNUSED, 0), +}; + +/* USI2's gates run in manual mode; the rest of HSI0 is left alone. */ +static const unsigned long hsi0_regs[] __initconst = { + 0x2120, 0x20fc, 0x2100, +}; + +static const struct samsung_cmu_info hsi0_cmu __initconst = { + .mux_clks = hsi0_muxes, + .nr_mux_clks = ARRAY_SIZE(hsi0_muxes), + .div_clks = hsi0_dividers, + .nr_div_clks = ARRAY_SIZE(hsi0_dividers), + .gate_clks = hsi0_gates, + .nr_gate_clks = ARRAY_SIZE(hsi0_gates), + .ro_gate_clks = hsi0_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(hsi0_ro_gates), + .nr_clk_ids = CLK_GOUT_HSI0_USI2_PCLK + 1, + .clk_regs = hsi0_regs, + .nr_clk_regs = ARRAY_SIZE(hsi0_regs), + .clk_name = "bus", +}; + +static int __init zuma_cmu_probe(struct platform_device *pdev) +{ + const struct samsung_cmu_info *cmu = device_get_match_data(&pdev->dev); + + exynos_arm64_register_cmu(&pdev->dev, pdev->dev.of_node, cmu); + return 0; +} + +static const struct of_device_id zuma_cmu_match[] = { + { .compatible = "google,zuma-cmu-apm", .data = &apm_cmu }, + { .compatible = "google,zuma-cmu-hsi0", .data = &hsi0_cmu }, + { } +}; + +static struct platform_driver zuma_cmu_driver __refdata = { + .driver = { + .name = "zuma-cmu", + .of_match_table = zuma_cmu_match, + .suppress_bind_attrs = true, + }, + .probe = zuma_cmu_probe, +}; + +static int __init zuma_cmu_init(void) +{ + return platform_driver_register(&zuma_cmu_driver); +} +core_initcall(zuma_cmu_init); From 854bed5c3bf75e18584b5aaff35693d7dc852f26 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:19:47 -0400 Subject: [PATCH 04/75] arm64: dts: exynos: google: zuma: add CMU_TOP and CMU_HSI0 Add the 24.576 MHz oscillator, HSI0's ALT input at the CAL's nominal 213 MHz, and the TOP and HSI0 clock controllers. Nothing consumes them yet; the touchscreen's SPI will. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- arch/arm64/boot/dts/exynos/google/zuma.dtsi | 40 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index 92bef7f97d..f76de50ad2 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -5,11 +5,13 @@ * Addresses, interrupts and reservations are the ones a retail Pixel 8 Pro * (husky) runs with: its live device tree and Google's GPL zuma tree * (android-gs-shusky-6.1-android16). Nothing here is copied from gs101 or - * gs201. No clock, pinctrl or power-domain providers yet: the bootloader - * leaves what first light needs running, and the board's bootargs carry - * clk_ignore_unused and pd_ignore_unused. + * gs201. The clock providers describe only the touchscreen SPI's path, and + * there are no power-domain providers yet: the bootloader leaves what the + * rest needs running, and the board's bootargs carry clk_ignore_unused and + * pd_ignore_unused. */ +#include #include #include @@ -269,6 +271,21 @@ clock-output-names = "ufs_ref_stub"; }; + oscclk: clock-oscclk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24576000>; + clock-output-names = "oscclk"; + }; + + /* The CAL's nominal I_CLK_HSI0_ALT rate. */ + hsi0_alt: clock-hsi0-alt { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <213000000>; + clock-output-names = "hsi0-alt"; + }; + soc: soc@0 { compatible = "simple-bus"; #address-cells = <1>; @@ -318,6 +335,15 @@ interrupts = ; }; + cmu_hsi0: clock-controller@11000000 { + compatible = "google,zuma-cmu-hsi0"; + reg = <0x11000000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>, <&cmu_top CLK_DOUT_HSI0_NOC>, + <&cmu_top CLK_DOUT_HSI0_PERI>, <&hsi0_alt>; + clock-names = "oscclk", "bus", "peri", "alt"; + }; + /* * USB control block: Exynos 2200's link registers, with the * eUSB2 PHY below as its high-speed PHY. The USB3/DP combo PHY @@ -443,6 +469,14 @@ "google,zumapro-wakeup-eint"; }; }; + + cmu_top: clock-controller@26040000 { + compatible = "google,zuma-cmu-top"; + reg = <0x26040000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; }; }; From 7d071ca3af21d84d4844a239bbf021e974d087e8 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:41 -0400 Subject: [PATCH 05/75] dt-bindings: mailbox: google,gs101-mbox: Add the Tensor G3 mailbox zuma's (Tensor G3) AP-to-APM mailbox is gs101's, as on gs201 and Tensor G4: same registers, one interrupt and one bus clock. Document it with gs101's compatible as the fallback. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml b/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml index d1a6c6eda1..559da23935 100644 --- a/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml @@ -27,6 +27,7 @@ properties: - items: - enum: - google,gs201-mbox + - google,zuma-mbox - google,zumapro-mbox - const: google,gs101-mbox From 44b4edb997aefa4fc35f1e7b08e12bd1720c2978 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:41 -0400 Subject: [PATCH 06/75] dt-bindings: firmware: google,gs101-acpm-ipc: Add the Tensor G3 zuma's (Tensor G3) ACPM firmware speaks the same protocol, from the same shared memory layout, as Tensor G4's, and its main PMIC is the same S2MPG14. Document its compatible, with the S2MPG14 as its main PMIC. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml b/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml index 58a0301f09..9163560a19 100644 --- a/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml +++ b/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml @@ -25,6 +25,7 @@ properties: enum: - google,gs101-acpm-ipc - google,gs201-acpm-ipc + - google,zuma-acpm-ipc - google,zumapro-acpm-ipc "#clock-cells": @@ -111,7 +112,9 @@ allOf: - if: properties: compatible: - const: google,zumapro-acpm-ipc + enum: + - google,zuma-acpm-ipc + - google,zumapro-acpm-ipc then: properties: pmic: false From 4bb3b99881765ad649ba9da1348f30dcda57d7b2 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:41 -0400 Subject: [PATCH 07/75] dt-bindings: mfd: samsung,s2mpg14-pmic: Tensor G3 uses it too The Pixel 8 Pro's (Tensor G3) main PMIC is the S2MPG14, at the same ACPM channel and with the same touchscreen rails on LDO4M and LDO25M. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml index 5419f15224..5a94a65452 100644 --- a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml +++ b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml @@ -10,8 +10,9 @@ maintainers: - W4HO <87742609+W4HO-ham@users.noreply.github.com> description: | - S2MPG14 is the main PMIC paired with Google's Tensor G4. Its LDO4M and - LDO25M outputs supply the analog and digital touchscreen power rails. + S2MPG14 is the main PMIC paired with Google's Tensor G3 and Tensor G4. + Its LDO4M and LDO25M outputs supply the analog and digital touchscreen + power rails. properties: compatible: From 007666e4605bfc9312e4b10b5afd5978b04f4c02 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:42 -0400 Subject: [PATCH 08/75] firmware: samsung: acpm: Add the Tensor G3 zuma's ACPM firmware keeps its channel table at 0xa000 in the APM SRAM, as stock's device tree gives it (initdata-base). Add zuma's match data. No driver binds its clocks device yet. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/firmware/samsung/exynos-acpm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index cbe830b986..dfac2a004c 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -42,6 +42,7 @@ #define ACPM_GS101_INITDATA_BASE 0xa000 #define ACPM_GS201_INITDATA_BASE 0xa000 +#define ACPM_ZUMA_INITDATA_BASE 0xa000 #define ACPM_ZUMAPRO_INITDATA_BASE 0xa000 /* Sanity limit for the channel count read from SRAM. */ @@ -981,6 +982,11 @@ static const struct acpm_match_data acpm_gs201 = { .acpm_clk_dev_name = "gs201-acpm-clk", }; +static const struct acpm_match_data acpm_zuma = { + .initdata_base = ACPM_ZUMA_INITDATA_BASE, + .acpm_clk_dev_name = "zuma-acpm-clk", +}; + static const struct acpm_match_data acpm_zumapro = { .initdata_base = ACPM_ZUMAPRO_INITDATA_BASE, .acpm_clk_dev_name = "zumapro-acpm-clk", @@ -993,6 +999,9 @@ static const struct of_device_id acpm_match[] = { }, { .compatible = "google,gs201-acpm-ipc", .data = &acpm_gs201, + }, { + .compatible = "google,zuma-acpm-ipc", + .data = &acpm_zuma, }, { .compatible = "google,zumapro-acpm-ipc", .data = &acpm_zumapro, From 0e0bb4e123859dd4deb1f9188fe2cac48f13ac3f Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:47 -0400 Subject: [PATCH 09/75] arm64: dts: exynos: google: zuma: add ACPM and its mailbox Add CMU_APM, the AP-to-APM mailbox (SPI 80), the APM SRAM and the ACPM firmware node, at the addresses stock's acpm_ipc node gives them. CMU_APM is read-only: it only names the mailbox's and the SRAM's clocks, which the always-on domain keeps running. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- arch/arm64/boot/dts/exynos/google/zuma.dtsi | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index f76de50ad2..d5d71ee26b 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -148,6 +148,15 @@ }; }; + firmware { + acpm_ipc: power-management { + compatible = "google,zuma-acpm-ipc"; + #clock-cells = <1>; + mboxes = <&ap2apm_mailbox>; + shmem = <&apm_sram>; + }; + }; + psci { compatible = "arm,psci-1.0"; method = "smc"; @@ -439,6 +448,23 @@ status = "disabled"; }; + ap2apm_mailbox: mailbox@15110000 { + compatible = "google,zuma-mbox", "google,gs101-mbox"; + reg = <0x15110000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_MAILBOX_AP>; + clock-names = "pclk"; + interrupts = ; + #mbox-cells = <0>; + }; + + cmu_apm: clock-controller@15400000 { + compatible = "google,zuma-cmu-apm"; + reg = <0x15400000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; + /* Writes go through EL3 (SMC), as on gs101. */ pmu_system_controller: system-controller@15460000 { compatible = "google,zuma-pmu"; @@ -470,6 +496,21 @@ }; }; + apm_sram: sram@15700000 { + compatible = "mmio-sram"; + reg = <0x15700000 0x58000>; + clocks = <&cmu_apm CLK_GOUT_APM_INTMEM_ACLK>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x15700000 0x58000>; + no-memory-wc; + + /* The APM firmware's window, as one block. */ + firmware-sram@0 { + reg = <0x0 0x58000>; + }; + }; + cmu_top: clock-controller@26040000 { compatible = "google,zuma-cmu-top"; reg = <0x26040000 0x8000>; From 432721d869bd80e58a0e430ceef77a665388a09f Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:23:48 -0400 Subject: [PATCH 10/75] arm64: dts: exynos: google: zuma-husky: add the main PMIC Describe the S2MPG14 behind ACPM. No regulators yet: each will come with its consumer, starting with the touchscreen's. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- arch/arm64/boot/dts/exynos/google/zuma-husky.dts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index 074eee930f..283481bb0a 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -117,6 +117,19 @@ }; }; +/* + * The main PMIC, behind the ACPM firmware. Its regulators are described + * with their consumers, which run them through the firmware. + */ +&acpm_ipc { + pmic-1 { + compatible = "samsung,s2mpg14-pmic"; + + regulators { + }; + }; +}; + &usb_dwc3 { status = "okay"; }; From f3c18eb19b5697addbd5f2d5b5fe49d4f4642aa6 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:34:26 -0400 Subject: [PATCH 11/75] dt-bindings: soc: samsung: exynos-usi: Add the Tensor G3 USI zuma's (Tensor G3) USI blocks are Exynos850-style, like Tensor G4's: the mode lives in a system register, and the block's own control sits at offset 0xc0. Document zuma's compatible with the Exynos850 fallback. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml b/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml index 9a2a8867b6..870ad437ff 100644 --- a/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml @@ -37,6 +37,7 @@ properties: - enum: - google,gs101-usi - google,gs201-usi + - google,zuma-usi - google,zumapro-usi - samsung,exynos2200-usi - samsung,exynosautov9-usi From 2e8ef92624f1e82d94f4d0fafd7726b541ca563c Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:34:26 -0400 Subject: [PATCH 12/75] dt-bindings: soc: samsung: exynos-sysreg: Add the Tensor G3 HSI0 sysreg HSI0's system registers hold the USI mode of the touchscreen's USI2. Like zuma's UFS sysreg, it takes no clock: HSI0 is firmware-owned. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml index 5acd0e0efb..2a181df90c 100644 --- a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml @@ -27,6 +27,7 @@ properties: - google,gs201-peric0-sysreg - google,gs201-peric1-sysreg - google,gs201-vgpio2ap-sysreg + - google,zuma-hsi0-sysreg - google,zuma-ufs-sysreg - google,zumapro-apm-sysreg - google,zumapro-hsi0-sysreg From 00691ba4d118e38c5882d451d083cb9e5a9b8262 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:34:34 -0400 Subject: [PATCH 13/75] spi: dt-bindings: samsung: Add the Tensor G3 SPI zuma's (Tensor G3) SPI controllers are gs101-style, as on Tensor G4. Document zuma's compatible with gs101's as the fallback. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- Documentation/devicetree/bindings/spi/samsung,spi.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/spi/samsung,spi.yaml b/Documentation/devicetree/bindings/spi/samsung,spi.yaml index 2cc3ba1341..7feee66b25 100644 --- a/Documentation/devicetree/bindings/spi/samsung,spi.yaml +++ b/Documentation/devicetree/bindings/spi/samsung,spi.yaml @@ -33,6 +33,7 @@ properties: - items: - enum: - google,gs201-spi + - google,zuma-spi - google,zumapro-spi - const: google,gs101-spi - const: samsung,exynos7-spi From 5bbb7384be201f232f88bb1fdae50c489dafc329 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:34:34 -0400 Subject: [PATCH 14/75] spi: s3c64xx: Add the Tensor G3 zuma's (Tensor G3) SPI controllers match Tensor G4's: rate from the CMU, 64-byte FIFOs, 32-bit access. Stock drives the Pixel 8 Pro's touchscreen with manual chip select (samsung,spi-chip-select-mode = <0>), as the Pixel 9a's, so use Tensor G4's port configuration, which holds native chip select for a whole message. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/spi/spi-s3c64xx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 870aae6592..4edda4cc02 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1676,6 +1676,9 @@ static const struct platform_device_id s3c64xx_spi_driver_ids[] = { MODULE_DEVICE_TABLE(platform, s3c64xx_spi_driver_ids); static const struct of_device_id s3c64xx_spi_dt_match[] = { + { .compatible = "google,zuma-spi", + .data = &zumapro_spi_port_config, + }, { .compatible = "google,zumapro-spi", .data = &zumapro_spi_port_config, }, From 8872c6ac3e7b985de4795a8a5b3f568ffb252a6e Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:36:41 -0400 Subject: [PATCH 15/75] arm64: dts: exynos: google: zuma: add the CUSTOM_ALIVE and PERIC1 pin controllers Add the CUSTOM_ALIVE controller at 0x15060000 (gpn0-gpn9, one wake-up interrupt each, SPI 0 to 9) and PERIC1 at 0x10c40000 (gpp19-gpp24, SPI 649), with the banks and interrupts of stock's live device tree, as controllers 1 and 12 of the driver's zuma data. CUSTOM_ALIVE's bus clock comes from CMU_APM; PERIC1 takes the bus-clock stand-in, as PERIC0 does. The touchscreen's attention line is on gpn0 and its reset on gpp21. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../boot/dts/exynos/google/zuma-pinctrl.dtsi | 136 ++++++++++++++++++ arch/arm64/boot/dts/exynos/google/zuma.dtsi | 22 +++ 2 files changed, 158 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 724ef95913..508c1171d2 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -160,6 +160,98 @@ }; }; +&pinctrl_custom_alive { + gpn0: gpn0-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn1: gpn1-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn2: gpn2-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn3: gpn3-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn4: gpn4-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn5: gpn5-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn6: gpn6-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn7: gpn7-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn8: gpn8-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn9: gpn9-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; +}; + &pinctrl_peric0 { gpp0: gpp0-gpio-bank { gpio-controller; @@ -288,6 +380,50 @@ }; }; +&pinctrl_peric1 { + gpp19: gpp19-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp20: gpp20-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp21: gpp21-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp24: gpp24-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp22: gpp22-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp23: gpp23-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; +}; + &pinctrl_hsi2ufs { gph5: gph5-gpio-bank { gpio-controller; diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index d5d71ee26b..043ce2c917 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -24,8 +24,10 @@ /* The pin controllers are numbered as in Tensor G4's driver data. */ aliases { pinctrl0 = &pinctrl_gpio_alive; + pinctrl1 = &pinctrl_custom_alive; pinctrl10 = &pinctrl_hsi2ufs; pinctrl11 = &pinctrl_peric0; + pinctrl12 = &pinctrl_peric1; }; /* @@ -344,6 +346,14 @@ interrupts = ; }; + pinctrl_peric1: pinctrl@10c40000 { + compatible = "google,zuma-pinctrl"; + reg = <0x10c40000 0x1000>; + clocks = <&clk_gpio_stub>; + clock-names = "pclk"; + interrupts = ; + }; + cmu_hsi0: clock-controller@11000000 { compatible = "google,zuma-cmu-hsi0"; reg = <0x11000000 0x8000>; @@ -448,6 +458,18 @@ status = "disabled"; }; + pinctrl_custom_alive: pinctrl@15060000 { + compatible = "google,zuma-pinctrl"; + reg = <0x15060000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_GPIO_CUSTOM_ALIVE>; + clock-names = "pclk"; + + wakeup-interrupt-controller { + compatible = "google,zuma-wakeup-eint", + "google,zumapro-wakeup-eint"; + }; + }; + ap2apm_mailbox: mailbox@15110000 { compatible = "google,zuma-mbox", "google,gs101-mbox"; reg = <0x15110000 0x1000>; From 52acfb34b6003f56f685896574eef31d5913d20c Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:36:41 -0400 Subject: [PATCH 16/75] arm64: dts: exynos: google: zuma: add HSI0's USI2 and its SPI Add HSI0's system registers and USI2 at 0x111d00c0 with its SPI controller (SPI 408), clocked from CMU_HSI0, as stock's spi@111D0000 (usi-offset 0x101c). This is the touchscreen's bus. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- arch/arm64/boot/dts/exynos/google/zuma.dtsi | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index 043ce2c917..2e76d03326 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -14,6 +14,7 @@ #include #include #include +#include / { compatible = "google,zuma"; @@ -363,6 +364,11 @@ clock-names = "oscclk", "bus", "peri", "alt"; }; + sysreg_hsi0: syscon@11020000 { + compatible = "google,zuma-hsi0-sysreg", "syscon"; + reg = <0x11020000 0x10000>; + }; + /* * USB control block: Exynos 2200's link registers, with the * eUSB2 PHY below as its high-speed PHY. The USB3/DP combo PHY @@ -391,6 +397,33 @@ status = "disabled"; }; + usi2_hsi0: usi@111d00c0 { + compatible = "google,zuma-usi", "samsung,exynos850-usi"; + reg = <0x111d00c0 0x20>; + clocks = <&cmu_hsi0 CLK_GOUT_HSI0_USI2_PCLK>, + <&cmu_hsi0 CLK_GOUT_HSI0_USI2_IP>; + clock-names = "pclk", "ipclk"; + samsung,sysreg = <&sysreg_hsi0 0x101c>; + samsung,mode = ; + #address-cells = <1>; + #size-cells = <1>; + ranges; + status = "disabled"; + + spi20: spi@111d0000 { + compatible = "google,zuma-spi", "google,gs101-spi"; + /* USI control starts at 0xc0; do not claim it twice. */ + reg = <0x111d0000 0xc0>; + interrupts = ; + clocks = <&cmu_hsi0 CLK_GOUT_HSI0_USI2_PCLK>, + <&cmu_hsi0 CLK_GOUT_HSI0_USI2_IP>; + clock-names = "spi", "spi_busclk0"; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + }; + /* * The DWC3 controller, in peripheral mode as on stock (which * wraps it in Google's exynos9-dwusb glue). On a normal boot From d95d58e530d9f33f4f2c08b4c577e5b633d3ae0f Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 07:50:09 -0400 Subject: [PATCH 17/75] Input: salixp: stop at the scan echo, and wait up to stock's 2.5 s The Pixel 8 Pro's FTM5 firmware first reports a forced calibration (status 43 05 01) after the scan command, then echoes the command about 60 ms after it was sent, past the 50 ms window. Probe then failed with "turning sensing on". Wait up to 2.5 s, as stock's checkEcho does (TIEMOUT_ECHO), and stop polling once the echo arrives, so the longer window costs nothing when the firmware answers promptly. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/input/touchscreen/salixp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/input/touchscreen/salixp.c b/drivers/input/touchscreen/salixp.c index c1752a8583..f7c665d96c 100644 --- a/drivers/input/touchscreen/salixp.c +++ b/drivers/input/touchscreen/salixp.c @@ -97,7 +97,7 @@ #define SALIXP_SCAN_ALL 0xff #define SALIXP_EVT_STATUS 0x43 #define SALIXP_ECHO_TYPE 0x01 -#define SALIXP_ECHO_MS 50 +#define SALIXP_ECHO_MS 2500 #define SALIXP_TOUCH_POLL_MS 10 #define SALIXP_TOUCH_LOG_MAX 8 #define SALIXP_CS_DELAY_US 10 @@ -431,9 +431,11 @@ static int salixp_poll_cx(struct salixp *ts) * and address 0x20000000, the same prefix as the flash commands, so * this does not send it. The echo is 0x43 0x01 followed by the * command. Stock treats a missing echo as failure after retries - * (ftsIO.c:523-547). This sends the scan command once and fails - * probe if the echo does not arrive. It does not send it again. - * No interrupt is requested. + * (ftsIO.c:523-547), waiting up to 2.5 s for it (TIEMOUT_ECHO in + * ftsCore.c:330). Husky's firmware reports a forced calibration + * first and echoes about 60 ms after the command. This sends the + * scan command once, stops at the echo and fails probe if it does + * not arrive. It does not send it again. No interrupt is requested. */ static int salixp_sense_on(struct salixp *ts) { @@ -460,7 +462,8 @@ static int salixp_sense_on(struct salixp *ts) return ret; deadline = ktime_add_ms(ktime_get(), SALIXP_ECHO_MS); - while (ktime_before(ktime_get(), deadline) && n < SALIXP_POLL_MAX_EVT) { + while (!echo && ktime_before(ktime_get(), deadline) && + n < SALIXP_POLL_MAX_EVT) { ret = salixp_read_fifo(ts, event); if (ret) return ret; From 10c6a39cfdcb58689a0fb786a58d41094a9ca5d0 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Fri, 30 Oct 2026 16:36:42 -0400 Subject: [PATCH 18/75] arm64: dts: exynos: google: zuma-husky: add the touchscreen The Pixel 8 Pro's touchscreen is an ST FTM5 (SALIXP, chip id 36 40) on USI2's SPI, as in stock's fts node: 10 MHz, attention on gpn0-0, reset on gpp21-2, 1344 x 2992. Its rails are the main PMIC's LDO25M (1.8 V digital) and LDO4M (3.3 V analog), which the firmware leaves off and at those voltages. Pin them there, as stock does. Stock's node inverts both axes, but salixp already reports in the panel's orientation: with stock's inversion, a tap at the top-left came in at the bottom-right. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../boot/dts/exynos/google/zuma-husky.dts | 39 +++++++++++++++++++ .../boot/dts/exynos/google/zuma-pinctrl.dtsi | 14 +++++++ 2 files changed, 53 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index 283481bb0a..29b9a11b98 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -126,10 +126,45 @@ compatible = "samsung,s2mpg14-pmic"; regulators { + touch_avdd: ldo4m { + regulator-name = "touch-avdd"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + + touch_vdd: ldo25m { + regulator-name = "touch-vdd"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + }; }; }; }; +&spi20 { + status = "okay"; + + /* + * ST FTM5 (SALIXP, chip id 36 40), as stock's fts node: 10 MHz, + * manual chip select. Not stock's axis inversion: salixp already + * reports in the panel's orientation. + */ + touchscreen@0 { + compatible = "st,salixp"; + reg = <0>; + spi-max-frequency = <10000000>; + interrupt-parent = <&gpn0>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&touch_vdd>; + avdd-supply = <&touch_avdd>; + reset-gpios = <&gpp21 2 GPIO_ACTIVE_LOW>; + touchscreen-size-x = <1344>; + touchscreen-size-y = <2992>; + pinctrl-names = "default"; + pinctrl-0 = <&ts_irq &ts_reset>; + }; +}; + &usb_dwc3 { status = "okay"; }; @@ -154,3 +189,7 @@ &ufs_0_phy { status = "okay"; }; + +&usi2_hsi0 { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 508c1171d2..a88e0eaa20 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -250,6 +250,13 @@ interrupt-parent = <&gic>; interrupts = ; }; + + ts_irq: ts-irq-pins { + samsung,pins = "gpn0-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + }; }; &pinctrl_peric0 { @@ -422,6 +429,13 @@ interrupt-controller; #interrupt-cells = <2>; }; + + ts_reset: ts-reset-pins { + samsung,pins = "gpp21-2"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + }; }; &pinctrl_hsi2ufs { From 51554d8fd3163676297c84d375c388ea7992372f Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 11 Oct 2026 22:39:15 -0400 Subject: [PATCH 19/75] dt-bindings: phy: add Google gs201 PCIe PHY The gs201 (Tensor G2) PCIe Gen4 PHY is a two-lane Samsung PHY with PMA and PCS register blocks, a debug block that selects its reference clock, and three reset lines inside the sub-control space of the controller it serves. Its isolation is a PMU register, so the PMU phandle carries the offset of this instance's PHY_CTRL_PCIE_GEN4_x register. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../bindings/phy/google,gs201-pcie-phy.yaml | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml new file mode 100644 index 0000000000..d0292e6f6c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/google,gs201-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 PCIe PHY + +maintainers: + - Derek Ross + +description: + The PCIe Gen4 PHY of the Google gs201 (Tensor G2) SoC. Each instance is a + two-lane Samsung PHY with its PMA and PCS register blocks, a debug block + that selects the reference clock, and three reset lines that live in the + sub-control space of the PCIe controller it serves. Its isolation is + controlled from the PMU. + +properties: + compatible: + const: google,gs201-pcie-phy + + reg: + items: + - description: PMA registers + - description: PCS registers + - description: PHY reset registers in the controller's sub-control space + - description: UDBG (reference clock and PLL selection) registers + + reg-names: + items: + - const: pma + - const: pcs + - const: rst + - const: udbg + + clocks: + minItems: 1 + maxItems: 5 + + "#phy-cells": + const: 0 + + samsung,pmu-syscon: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the PMU system controller + - description: offset of this PHY's control (isolation) register + description: + The PMU and the offset of PHY_CTRL_PCIE_GEN4_x for this instance. + +required: + - compatible + - reg + - reg-names + - "#phy-cells" + - samsung,pmu-syscon + +additionalProperties: false + +examples: + - | + #include + + phy@14550000 { + compatible = "google,gs201-pcie-phy"; + reg = <0x14550000 0x2000>, <0x14540000 0x1000>, + <0x14521400 0x10>, <0x14560000 0xd000>; + reg-names = "pma", "pcs", "rst", "udbg"; + clocks = <&cmu_hsi2 CLK_GOUT_HSI2_PCIE_GEN4_1_PCS_PMA_INST_0_PHY_UDBG_I_APB_PCLK>; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + #phy-cells = <0>; + }; From d182a22f7176c759263178a1527476e2037f1d9d Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 11 Oct 2026 22:39:16 -0400 Subject: [PATCH 20/75] dt-bindings: PCI: add Google gs201 PCIe host controller The gs201 (Tensor G2) PCIe controllers are DesignWare cores in a Samsung wrapper: an ELBI sub-control block for link training and interrupt status, and an I/A sequencer that re-locks the PHY clock-data recovery when the link leaves L1.2. INTx is demultiplexed from the controller interrupt, so the node has a legacy-interrupt-controller child. The I/A region is not one of the generic DesignWare register names, so the binding refers to snps,dw-pcie-common.yaml rather than snps,dw-pcie.yaml and lists its own reg-names. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../bindings/pci/google,gs201-pcie.yaml | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml new file mode 100644 index 0000000000..89e65f2a1f --- /dev/null +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/google,gs201-pcie.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 PCIe host controller + +maintainers: + - Derek Ross + +description: + The PCIe controllers of the Google gs201 (Tensor G2) SoC are Synopsys + DesignWare cores (IP version 0x984500) in a Samsung wrapper. The wrapper + adds a sub-control block (ELBI) with link training control and interrupt + status, and an I/A sequencer that re-locks the PHY clock-data recovery when + the link leaves L1.2. Legacy INTx interrupts are demultiplexed from the + controller interrupt by a child interrupt controller. + +allOf: + - $ref: /schemas/pci/pci-host-bridge.yaml# + - $ref: /schemas/pci/snps,dw-pcie-common.yaml# + +properties: + compatible: + const: google,gs201-pcie + + reg: + minItems: 3 + items: + - description: External local bus interface (ELBI) registers + - description: Data Bus Interface (DBI) registers, with the unrolled + iATU at offset 0x300000 + - description: PCIe configuration space region + - description: I/A sequencer registers + + reg-names: + minItems: 3 + items: + - const: elbi + - const: dbi + - const: config + - const: ia + + interrupts: + maxItems: 1 + + clocks: + minItems: 1 + maxItems: 8 + + phys: + maxItems: 1 + + phy-names: + const: pcie + + dma-coherent: true + + samsung,cmu: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The HSI clock controller (CMU) of this controller. Google's driver + turns the CMU's global automatic clock gating off before using the + controller; the driver can do the same, and reads the PCIe gate and + Q-channel state from it for diagnostics. + + samsung,sysreg: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the HSI system register controller + - description: offset of this controller's shareability register + description: + Needed with dma-coherent, to make the controller's DMA shareable. + + num-lanes: + maximum: 2 + + max-link-speed: + maximum: 4 + + legacy-interrupt-controller: + type: object + additionalProperties: false + + properties: + "#address-cells": + const: 0 + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + + required: + - "#address-cells" + - interrupt-controller + - "#interrupt-cells" + +required: + - compatible + - reg + - reg-names + - interrupts + - "#interrupt-cells" + - interrupt-map + - interrupt-map-mask + - phys + - phy-names + - reset-gpios + - legacy-interrupt-controller + +unevaluatedProperties: false + +examples: + - | + #include + #include + #include + + soc { + #address-cells = <1>; + #size-cells = <1>; + + pcie@14520000 { + compatible = "google,gs201-pcie"; + reg = <0x14520000 0x1400>, <0x14800000 0x301000>, + <0x60ffe000 0x2000>, <0x14500000 0x1000>; + reg-names = "elbi", "dbi", "config", "ia"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x60000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = ; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_1_intc 0>, + <0 0 0 2 &pcie_1_intc 1>, + <0 0 0 3 &pcie_1_intc 2>, + <0 0 0 4 &pcie_1_intc 3>; + clocks = <&cmu_hsi2 CLK_GOUT_HSI2_PCIE_GEN4_1_PCIE_003_G4X2_DWC_PCIE_CTL_INST_0_DBI_ACLK_UG>; + phys = <&pcie_1_phy>; + phy-names = "pcie"; + reset-gpios = <&gph2 0 GPIO_ACTIVE_LOW>; + samsung,cmu = <&cmu_hsi2>; + samsung,sysreg = <&sysreg_hsi2 0x730>; + dma-coherent; + num-lanes = <1>; + max-link-speed = <2>; + + pcie_1_intc: legacy-interrupt-controller { + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + }; From 0fded069ae29e7a4906f8adeb51480b67400ac87 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 11 Oct 2026 22:39:17 -0400 Subject: [PATCH 21/75] dt-bindings: net: wireless: brcm,bcm4329-fmac: allow a restricted DMA pool A PCIe Wi-Fi chip runs firmware that parses untrusted frames. Platforms that confine the chip's DMA to one region (with an IOMMU-less firewall such as the Google gs201 S2MPU) describe that region as a restricted-dma-pool and point the device node at it, as is already done for other PCIe Wi-Fi bindings. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml index 38e9a0444f..8589631085 100644 --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml @@ -125,6 +125,11 @@ properties: NVRAM. This would normally be filled in by the bootloader from platform configuration data. + memory-region: + maxItems: 1 + description: A restricted-dma-pool region that all DMA of a PCIe device + bounces through, for platforms that limit the device's DMA to it. + clocks: items: - description: External Low Power Clock input (32.768KHz) From bf6c5d8353f3a5cc0caced35468b17e4707ded8c Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 10:27:01 -0400 Subject: [PATCH 22/75] dt-bindings: iommu: add the Google gs201 PCIe System MMU as a DMA window The System MMU in front of the gs201 PCIe GEN4A_1 controller (the Pixel 7 Wi-Fi link), described for use as a DMA window: a 1:1 mapping of one reserved memory region, with the VID the controller's traffic uses. The window is a plain phandle property, google,dma-window: memory-region on this node would attach a restricted-dma-pool to the SysMMU device itself, which would then bounce its page table into the window. google,vid is the default VID to translate, which still has to be confirmed by a negative test. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../iommu/google,gs201-pcie-sysmmu.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml diff --git a/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml b/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml new file mode 100644 index 0000000000..5d5bf1e370 --- /dev/null +++ b/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iommu/google,gs201-pcie-sysmmu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 PCIe System MMU used as a DMA window + +maintainers: + - Derek Ross + +description: + The Samsung System MMU (version 8.1) in front of the gs201 PCIe GEN4A_1 + controller. It is programmed with a 1:1 mapping of one reserved memory + region, so the PCIe device can reach that region and nothing else. + +properties: + compatible: + const: google,gs201-pcie-sysmmu + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + google,dma-window: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The reserved memory region (typically the PCIe device's + restricted-dma-pool) that is the only memory the PCIe device may + access. Not memory-region, which would make the pool this node's own + DMA bounce buffer, placing the page table inside the window. + + google,vid: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 7 + default: 1 + description: + The System MMU virtual ID translated by default (stock uses 1). No + kernel code assigns the controller's VID, so this must be confirmed with + a negative test. + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include + sysmmu@145c0000 { + compatible = "google,gs201-pcie-sysmmu"; + reg = <0x145c0000 0x10000>; + interrupts = ; + clocks = <&cmu_hsi2 17>, <&cmu_hsi2 55>; + google,vid = <1>; + }; From 7458df756cacc139f6e0abdf08dd0acb633a8fea Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 11 Oct 2026 22:39:16 -0400 Subject: [PATCH 23/75] phy: samsung: add Google gs201 PCIe PHY driver Add a driver for the PCIe Gen4 PHY of the Google gs201 (Tensor G2) SoC, which connects the Wi-Fi chip on Pixel 7 phones. The bootloader leaves the PHY isolated in the PMU and does not train the link, so the whole Samsung init sequence is needed. phy_init() is Google's probe-time step: release the PMU isolation (a secure register, written through the PMU regmap's SMC path) and power the PHY down. phy_power_on() clears the power-down and runs "CAL ver 210802": PHY resets, the common PMA block for a 100 MHz LCPLL with a 38.4 MHz input clock, the per-lane tables, PCS settings for root complex mode, the external XO selection and an AFC calibration restart, then polls the PLL, CDR and offset calibration status. phy_calibrate() reports the offset calibration after the controller's soft power reset. The sequence follows the driver Google builds for gs201 (google-modules/soc/gs/drivers/pci/controller/dwc-whi: pcie-exynos-gs201-rc-cal.c and pcie-exynos-rc.c, Copyright Samsung Electronics). Most PMA registers have no public names, so the tables keep the raw offsets. As on stock, the PHY is not isolated again after init: controller register accesses hang the SoC while it is isolated. For bring-up, trace=1 logs every hardware step before it happens (with a short sleep so a remote log reader receives the line before a possible bus hang), and check_tcxo=1 reads and fixes the PMU TCXO buffer bits that Google's driver checks. The controller sets the lane count with phy_set_bus_width(); the default is one lane, as on Pixel 7. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/phy/samsung/Kconfig | 10 + drivers/phy/samsung/Makefile | 1 + drivers/phy/samsung/phy-gs201-pcie.c | 635 +++++++++++++++++++++++++++ 3 files changed, 646 insertions(+) create mode 100644 drivers/phy/samsung/phy-gs201-pcie.c diff --git a/drivers/phy/samsung/Kconfig b/drivers/phy/samsung/Kconfig index 6849ced7ad..a9cada8097 100644 --- a/drivers/phy/samsung/Kconfig +++ b/drivers/phy/samsung/Kconfig @@ -29,6 +29,16 @@ config PHY_EXYNOS_PCIE Enable PCIe PHY support for Exynos SoC series. This driver provides PHY interface for Exynos PCIe controller. +config PHY_GS201_PCIE + tristate "Google gs201 PCIe PHY driver" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on EXYNOS_PMU || COMPILE_TEST + select GENERIC_PHY + help + Enable support for the PCIe Gen4 PHY of the Google gs201 (Tensor G2) + SoC. It is used by the gs201 PCIe controller driver, which connects + the Wi-Fi chip on Pixel 7 phones. + config PHY_GS201_MIPI_DCPHY tristate "Google gs201 MIPI DC-PHY receiver driver" depends on OF && (ARCH_EXYNOS || COMPILE_TEST) diff --git a/drivers/phy/samsung/Makefile b/drivers/phy/samsung/Makefile index 463585ec90..a24c25524c 100644 --- a/drivers/phy/samsung/Makefile +++ b/drivers/phy/samsung/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o obj-$(CONFIG_PHY_EXYNOS_PCIE) += phy-exynos-pcie.o +obj-$(CONFIG_PHY_GS201_PCIE) += phy-gs201-pcie.o obj-$(CONFIG_PHY_GS201_MIPI_DCPHY) += phy-gs201-mipi-dcphy-rx.o obj-$(CONFIG_PHY_SAMSUNG_UFS) += phy-exynos-ufs.o phy-exynos-ufs-y += phy-gs101-ufs.o diff --git a/drivers/phy/samsung/phy-gs201-pcie.c b/drivers/phy/samsung/phy-gs201-pcie.c new file mode 100644 index 0000000000..4218f86745 --- /dev/null +++ b/drivers/phy/samsung/phy-gs201-pcie.c @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google gs201 (Tensor G2) PCIe Gen4 PHY driver + * + * The register sequence is Samsung's "CAL ver 210802" for gs201, taken from + * the driver Google builds for gs201 (pcie-exynos-gs201-rc-cal.c and + * pcie-exynos-rc.c in google-modules/soc/gs/drivers/pci/controller/dwc-whi). + * Most PMA registers have no public names, so the tables keep Samsung's raw + * offsets and values. + * + * Copyright (C) 2021 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Bring-up tracing: with trace=1 every step that touches the hardware is + * logged before it happens, and the driver sleeps trace_delay_ms after each + * line so that a reader of /dev/kmsg (dmesg -w over SSH) receives it before a + * possible bus hang stops the CPU. Both can be changed at runtime through + * /sys/module/phy_gs201_pcie/parameters/. + */ +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +static bool check_tcxo; +module_param(check_tcxo, bool, 0644); +MODULE_PARM_DESC(check_tcxo, + "Read PMU TCXO_BUF_CTRL in phy_init and set the bits Google's driver expects (default: off)"); + +/* + * PHY reset block, in the controller's sub-control (ELBI) space at +0x1400. + * All three are active low. INIT_RST is released before the PMA is + * programmed, the other two after it. + */ +#define GS201_PHY_RST_CMN 0x0 +#define GS201_PHY_RST_INIT 0x4 +#define GS201_PHY_RST_PORT 0x8 + +/* PMU PHY control (PHY_CTRL_PCIE_GEN4_x) */ +#define GS201_PMU_PHY_BYPASS BIT(0) /* 0 = isolated */ + +/* PMU TCXO_BUF_CTRL: Google checks these are set before using PCIe ch1 */ +#define GS201_PMU_TCXO_BUF_CTRL 0x3c10 +#define GS201_PMU_TCXO_PCIE_MASK (BIT(2) | BIT(3) | BIT(10)) + +/* PMA common registers used outside the tables */ +#define GS201_PMA_INPUT_CLK 0x0d8 +#define GS201_PMA_INPUT_CLK_VAL 0x28 +#define GS201_PMA_CMN_CTRL 0x400 +#define GS201_PMA_CMN_CTRL_PMA_EN BIT(7) +#define GS201_PMA_CMN_PWRDN0 0x404 +#define GS201_PMA_CMN_PWRDN1 0x408 +#define GS201_PMA_CMN_PWRDN2 0x40c +#define GS201_PMA_XO_CFG 0x5d0 +#define GS201_PMA_XO_CFG_EXT BIT(4) +#define GS201_PMA_XO_CFG_INT BIT(3) +#define GS201_PMA_OC_STATUS 0x5fc /* logged by Google before config */ +#define GS201_PMA_CMN_STATUS 0x3f0 +#define GS201_PMA_CMN_STATUS_PLL_LOCK BIT(3) +#define GS201_PMA_AFC_CAL_MODE 0xbf4 +#define GS201_PMA_AFC_CAL_RESTART 0x4 +#define GS201_PMA_OC_DONE 0xde8 +#define GS201_PMA_OC_DONE_MASK GENMASK(3, 0) +#define GS201_PMA_CDR_STATUS 0xe0c +#define GS201_PMA_CDR_LOCK BIT(2) +#define GS201_PMA_OC_STATUS2 0xe18 +#define GS201_PMA_OC_STATUS2_DONE BIT(7) +#define GS201_PMA_LN0_STATUS 0xfc0 + +/* PCS */ +#define GS201_PCS_BIFURCATION 0x004 +#define GS201_PCS_CLK_CTRL 0x008 +#define GS201_PCS_CLK_MUX_GLITCH_WA BIT(7) +#define GS201_PCS_ERIO_CLK_GATE_MASK GENMASK(5, 4) +#define GS201_PCS_L2_PWR 0x150 +#define GS201_PCS_RC_MODE 0x154 +#define GS201_PCS_L2_PWRDN_DELAY 0x170 +#define GS201_PCS_RATE_CTRL 0x184 +#define GS201_PCS_RATE_CTRL_SWITCH 0xb0 +#define GS201_PCS_PM_STATE 0x188 +#define GS201_PCS_PLL_BIAS_OFF_DELAY 0x190 +#define GS201_PCS_LANE_STRIDE 0x800 + +#define GS201_PMA_LANE_STRIDE 0x800 +#define GS201_PHY_MAX_LANES 2 + +/* Google polls the lock bits 10000 times, 1 us apart */ +#define GS201_PHY_LOCK_TIMEOUT_US 10000 + +struct gs201_pcie_phy_reg { + u16 off; + u8 val; +}; + +/* Common PMA block, 100 MHz LCPLL, RC mode, then the 38.4 MHz input clock */ +static const struct gs201_pcie_phy_reg gs201_pma_common[] = { + { 0x018, 0x50 }, { 0x048, 0x33 }, { 0x068, 0x01 }, { 0x070, 0x12 }, + { 0x08c, 0x00 }, { 0x090, 0x21 }, { 0x0b0, 0x14 }, { 0x0b8, 0x50 }, + { 0x0e0, 0x51 }, { 0x100, 0x00 }, { 0x104, 0x80 }, { 0x140, 0x38 }, + { 0x180, 0xa4 }, + { 0x188, 0x03 }, /* LCPLL 100 MHz, no divider */ + { 0x2a8, 0x38 }, { 0x2e4, 0x12 }, + /* PMA enable, aggregation (non-bifurcated) mode */ + { 0x400, 0x80 }, { 0x408, 0x20 }, { 0x550, 0x00 }, { 0x5a8, 0x00 }, + { 0x5ec, 0xff }, + /* PCIe type: RC */ + { 0x458, 0x02 }, /* 100 MHz clock on */ + { 0x5b0, 0x34 }, /* differential REFCLK source control */ + { 0x450, 0x20 }, /* extra delay when entering L1.2 */ + /* 38.4 MHz PHY input clock */ + { 0x0ac, 0x34 }, { 0x0b4, 0x34 }, { 0x0e0, 0x50 }, { 0x0f4, 0x00 }, + { 0x0f8, 0x08 }, { 0x104, 0xa0 }, { 0x11c, 0x19 }, { 0x124, 0x17 }, + { 0x220, 0x41 }, +}; + +/* Per-lane PMA block (offsets for lane 0; lane n adds n * 0x800) */ +static const struct gs201_pcie_phy_reg gs201_pma_lane[] = { + { 0x82c, 0x08 }, { 0x830, 0x24 }, { 0x878, 0x80 }, { 0x894, 0x40 }, + { 0x8c0, 0x00 }, { 0x8f4, 0x30 }, { 0x908, 0x05 }, { 0x90c, 0xe0 }, + { 0x914, 0xd4 }, { 0x91c, 0xd3 }, { 0x920, 0xce }, { 0x924, 0x01 }, + { 0x928, 0x35 }, { 0x92c, 0xba }, { 0x930, 0x41 }, { 0x934, 0x15 }, + { 0x938, 0x13 }, { 0x93c, 0x4e }, { 0x948, 0x43 }, { 0x94c, 0xfc }, + { 0x954, 0x10 }, { 0x958, 0x69 }, { 0x964, 0x40 }, { 0x9b4, 0xf6 }, + { 0x9c0, 0x2d }, { 0x9c4, 0xb7 }, { 0x9cc, 0x3c }, { 0x9dc, 0x7e }, + { 0xa40, 0x02 }, { 0xa70, 0x26 }, { 0xa74, 0x00 }, + { 0xb40, 0x06 }, { 0xb44, 0x06 }, { 0xb48, 0x04 }, { 0xb4c, 0x03 }, + { 0xb50, 0x03 }, { 0xb54, 0x03 }, { 0xb58, 0x03 }, { 0xb5c, 0x03 }, + { 0xc10, 0x1b }, { 0xc44, 0x10 }, { 0xc48, 0x10 }, { 0xc4c, 0x10 }, + { 0xc50, 0x10 }, { 0xc54, 0x02 }, { 0xc58, 0x02 }, { 0xc5c, 0x02 }, + { 0xc60, 0x02 }, { 0xc6c, 0x02 }, { 0xc70, 0x02 }, { 0xca8, 0xe7 }, + { 0xcac, 0x00 }, { 0xcb0, 0x0e }, { 0xccc, 0x1c }, { 0xcd4, 0x05 }, + { 0xcd8, 0x77 }, { 0xcdc, 0x7a }, { 0xdb4, 0x2f }, + /* RX tuning */ + { 0x8fc, 0x80 }, { 0x914, 0xf4 }, { 0x91c, 0xd3 }, { 0x920, 0xca }, + { 0x928, 0x3d }, { 0x92c, 0xb8 }, { 0x930, 0x41 }, { 0x934, 0x17 }, + { 0x93c, 0x4c }, { 0x948, 0x73 }, { 0x94c, 0xfc }, { 0x96c, 0x55 }, + { 0x988, 0x78 }, { 0x994, 0x3b }, { 0x9b4, 0xf6 }, { 0x9c4, 0xff }, + { 0x9c8, 0x20 }, { 0xa08, 0x2f }, { 0xb9c, 0x3f }, + /* TX termination resistor */ + { 0x9cc, 0x00 }, { 0xcd8, 0xff }, { 0xcdc, 0x6e }, + { 0x82c, 0x0f }, { 0x830, 0x60 }, { 0x834, 0x7e }, + /* Auto FBB */ + { 0xc08, 0x00 }, { 0xc10, 0x09 }, { 0xc40, 0x04 }, { 0xc70, 0x00 }, + /* DFE */ + { 0x9b4, 0x76 }, +}; + +/* 38.4 MHz input clock, per lane, written for both lanes of the PHY */ +static const struct gs201_pcie_phy_reg gs201_pma_lane_clk[] = { + { 0xbcc, 0x41 }, { 0xbd4, 0x41 }, { 0xbdc, 0x68 }, { 0xbe0, 0x00 }, + { 0xbe4, 0xd0 }, +}; + +/* PHY power-down, per lane (offsets for lane 0) */ +static const struct gs201_pcie_phy_reg gs201_pma_lane_pwrdn[] = { + { 0x800, 0x0a }, { 0x804, 0xbf }, { 0xa40, 0x02 }, { 0xa44, 0x2a }, + { 0xa48, 0xaa }, { 0xa4c, 0xa8 }, { 0xa50, 0x80 }, +}; + +/* + * PMA values right after the PHY reset. Google's driver compares them before + * every configuration ("check if PCIe PHY is being reset correctly"). + */ +static const struct gs201_pcie_phy_reg gs201_pma_reset_vals[] = { + { 0x010, 0x55 }, { 0x014, 0x51 }, { 0x040, 0x50 }, { 0x044, 0x0c }, + { 0x0d8, 0x28 }, { 0x1054, 0x77 }, +}; + +struct gs201_pcie_phy { + struct device *dev; + void __iomem *pma; + void __iomem *pcs; + void __iomem *rst; + void __iomem *udbg; + struct regmap *pmu; + u32 pmu_offset; + struct clk_bulk_data *clks; + int num_clks; +}; + +static __printf(2, 3) void gs201_phy_trace(struct gs201_pcie_phy *gp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(gp->dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static void gs201_pcie_phy_write_table(void __iomem *base, + const struct gs201_pcie_phy_reg *tbl, + size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + writel(tbl[i].val, base + tbl[i].off); +} + +static void gs201_pcie_phy_rmw(void __iomem *reg, u32 clr, u32 set) +{ + writel((readl(reg) & ~clr) | set, reg); +} + +static unsigned int gs201_pcie_phy_lanes(struct phy *phy) +{ + unsigned int lanes = phy_get_bus_width(phy); + + return clamp(lanes, 1U, (unsigned int)GS201_PHY_MAX_LANES); +} + +/* Power down both lanes and the PMA; the inverse of _pwrdn_clear() */ +static void gs201_pcie_phy_pwrdn(struct gs201_pcie_phy *gp) +{ + unsigned int lane; + + gs201_phy_trace(gp, "about to write PMA 0x404-0x40c and the lane power-down registers"); + writel(0xa8, gp->pma + GS201_PMA_CMN_PWRDN0); + writel(0x20, gp->pma + GS201_PMA_CMN_PWRDN1); + writel(0x0a, gp->pma + GS201_PMA_CMN_PWRDN2); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane_pwrdn, + ARRAY_SIZE(gs201_pma_lane_pwrdn)); + + gs201_phy_trace(gp, "about to read PMA 0x400 (first PMA read): disable the PMA"); + gs201_pcie_phy_rmw(gp->pma + GS201_PMA_CMN_CTRL, + GS201_PMA_CMN_CTRL_PMA_EN, 0); + + gs201_phy_trace(gp, "about to read PCS 0x184 (first PCS read): rate switching off"); + gs201_pcie_phy_rmw(gp->pcs + GS201_PCS_RATE_CTRL, + GS201_PCS_RATE_CTRL_SWITCH, 0); +} + +static void gs201_pcie_phy_pwrdn_clear(struct gs201_pcie_phy *gp) +{ + unsigned int lane; + size_t i; + + gs201_phy_trace(gp, "about to write PMA 0xd8 (input clock), then clear the power-downs"); + writel(GS201_PMA_INPUT_CLK_VAL, gp->pma + GS201_PMA_INPUT_CLK); + mdelay(1); + + writel(0, gp->pma + GS201_PMA_CMN_PWRDN0); + writel(0, gp->pma + GS201_PMA_CMN_PWRDN1); + writel(0, gp->pma + GS201_PMA_CMN_PWRDN2); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + for (i = 0; i < ARRAY_SIZE(gs201_pma_lane_pwrdn); i++) + writel(0, gp->pma + lane * GS201_PMA_LANE_STRIDE + + gs201_pma_lane_pwrdn[i].off); + + gs201_phy_trace(gp, "about to write PCS 0x184 (rate change and power-down reset)"); + writel(0, gp->pcs + GS201_PCS_RATE_CTRL); +} + +/* Google's debug check that the PMA came out of reset with its defaults */ +static void gs201_pcie_phy_check_reset(struct gs201_pcie_phy *gp) +{ + size_t i; + u32 val; + + gs201_phy_trace(gp, "about to read PMA reset defaults (0x10 0x14 0x40 0x44 0xd8 0x1054)"); + for (i = 0; i < ARRAY_SIZE(gs201_pma_reset_vals); i++) { + val = readl(gp->pma + gs201_pma_reset_vals[i].off); + if (val != gs201_pma_reset_vals[i].val) + dev_info(gp->dev, "PMA %#x after reset: %#x (expected %#x)\n", + gs201_pma_reset_vals[i].off, val, + gs201_pma_reset_vals[i].val); + } +} + +static void gs201_pcie_phy_config(struct gs201_pcie_phy *gp, unsigned int lanes) +{ + unsigned int lane; + + gs201_phy_trace(gp, "about to read PMA 0x5fc (OC status)"); + dev_dbg(gp->dev, "OC initial status %#x\n", + readl(gp->pma + GS201_PMA_OC_STATUS)); + + gs201_pcie_phy_check_reset(gp); + + /* Input clock path */ + writel(GS201_PMA_INPUT_CLK_VAL, gp->pma + GS201_PMA_INPUT_CLK); + + gs201_phy_trace(gp, "about to read-modify-write PCS 0x008 (clock mux glitch workaround)"); + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_rmw(gp->pcs + lane * GS201_PCS_LANE_STRIDE + + GS201_PCS_CLK_CTRL, 0, + GS201_PCS_CLK_MUX_GLITCH_WA); + + gs201_phy_trace(gp, "about to pulse the PHY resets (ELBI 0x1400-0x1408), release INIT_RST"); + writel(1, gp->rst + GS201_PHY_RST_INIT); + writel(1, gp->rst + GS201_PHY_RST_PORT); + writel(1, gp->rst + GS201_PHY_RST_CMN); + writel(0, gp->rst + GS201_PHY_RST_INIT); + writel(0, gp->rst + GS201_PHY_RST_PORT); + writel(0, gp->rst + GS201_PHY_RST_CMN); + udelay(10); + writel(1, gp->rst + GS201_PHY_RST_INIT); + udelay(10); + + gs201_phy_trace(gp, "about to write the PMA tables (common, %u lane(s), lane clocks)", + lanes); + gs201_pcie_phy_write_table(gp->pma, gs201_pma_common, + ARRAY_SIZE(gs201_pma_common)); + + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane, + ARRAY_SIZE(gs201_pma_lane)); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane_clk, + ARRAY_SIZE(gs201_pma_lane_clk)); + + gs201_phy_trace(gp, "about to write PCS 0x004 0x154 0x150 0x170 0x008 0x190"); + for (lane = 0; lane < lanes; lane++) { + void __iomem *pcs = gp->pcs + lane * GS201_PCS_LANE_STRIDE; + + writel(0x00000, pcs + GS201_PCS_BIFURCATION); + writel(0x700d5, pcs + GS201_PCS_RC_MODE); + writel(0x300ff, pcs + GS201_PCS_L2_PWR); + writel(0x40, pcs + GS201_PCS_L2_PWRDN_DELAY); + } + + /* ERIO clock gating in L1.2 */ + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_rmw(gp->pcs + lane * GS201_PCS_LANE_STRIDE + + GS201_PCS_CLK_CTRL, + GS201_PCS_ERIO_CLK_GATE_MASK, + GS201_PCS_ERIO_CLK_GATE_MASK); + + /* PLL and bias enable off delay */ + writel(0x100b0808, gp->pcs + GS201_PCS_PLL_BIAS_OFF_DELAY); + + gs201_phy_trace(gp, "about to release CMN_RST and PORT_RST"); + writel(1, gp->rst + GS201_PHY_RST_CMN); + writel(1, gp->rst + GS201_PHY_RST_PORT); + + gs201_phy_trace(gp, "about to read-modify-write PMA 0x5d0 (external XO)"); + gs201_pcie_phy_rmw(gp->pma + GS201_PMA_XO_CFG, GS201_PMA_XO_CFG_INT, + GS201_PMA_XO_CFG_EXT); + + /* + * Restart AFC calibration from its simulated initial value instead of + * the previous result; Google found the stale value can flag AFC done + * too early and break CDR lock. + */ + writel(GS201_PMA_AFC_CAL_RESTART, gp->pma + GS201_PMA_AFC_CAL_MODE); +} + +static bool gs201_pcie_phy_wait(struct gs201_pcie_phy *gp, const char *what, + u32 off, u32 mask, u32 want) +{ + u32 val; + int ret; + + gs201_phy_trace(gp, "about to poll PMA %#x for %s (up to %u us)", off, + what, GS201_PHY_LOCK_TIMEOUT_US); + ret = readl_poll_timeout_atomic(gp->pma + off, val, (val & mask) == want, + 1, GS201_PHY_LOCK_TIMEOUT_US); + + return !ret; +} + +static void gs201_pcie_phy_check_lock(struct gs201_pcie_phy *gp) +{ + bool pll, cdr, oc; + + pll = gs201_pcie_phy_wait(gp, "PLL lock", GS201_PMA_CMN_STATUS, + GS201_PMA_CMN_STATUS_PLL_LOCK, + GS201_PMA_CMN_STATUS_PLL_LOCK); + cdr = gs201_pcie_phy_wait(gp, "CDR lock", GS201_PMA_CDR_STATUS, + GS201_PMA_CDR_LOCK, GS201_PMA_CDR_LOCK); + oc = gs201_pcie_phy_wait(gp, "offset calibration", GS201_PMA_OC_DONE, + GS201_PMA_OC_DONE_MASK, GS201_PMA_OC_DONE_MASK); + + /* CDR lock needs a link partner; without one only the PLL matters */ + dev_info(gp->dev, + "PLL lock %d, CDR lock %d, OC done %d (PMA 0x3f0 %#x 0xfc0 %#x, PCS 0x188 %#x)\n", + pll, cdr, oc, readl(gp->pma + GS201_PMA_CMN_STATUS), + readl(gp->pma + GS201_PMA_LN0_STATUS), + readl(gp->pcs + GS201_PCS_PM_STATE)); +} + +static int gs201_pcie_phy_clks_on(struct gs201_pcie_phy *gp) +{ + int i, ret; + + for (i = 0; i < gp->num_clks; i++) { + gs201_phy_trace(gp, "enable clk %pC", + gp->clks[i].clk); + ret = clk_prepare_enable(gp->clks[i].clk); + if (ret) { + while (--i >= 0) + clk_disable_unprepare(gp->clks[i].clk); + return ret; + } + } + + return 0; +} + +static void gs201_pcie_phy_check_tcxo(struct gs201_pcie_phy *gp) +{ + unsigned int val; + int ret; + + gs201_phy_trace(gp, "about to read PMU %#x (TCXO_BUF_CTRL)", + GS201_PMU_TCXO_BUF_CTRL); + ret = regmap_read(gp->pmu, GS201_PMU_TCXO_BUF_CTRL, &val); + if (ret) { + dev_warn(gp->dev, "cannot read TCXO_BUF_CTRL: %d\n", ret); + return; + } + + dev_info(gp->dev, "PMU TCXO_BUF_CTRL %#x\n", val); + if ((val & GS201_PMU_TCXO_PCIE_MASK) == GS201_PMU_TCXO_PCIE_MASK) + return; + + gs201_phy_trace(gp, "about to set PMU %#x bits %#lx (SMC)", + GS201_PMU_TCXO_BUF_CTRL, GS201_PMU_TCXO_PCIE_MASK); + ret = regmap_update_bits(gp->pmu, GS201_PMU_TCXO_BUF_CTRL, + GS201_PMU_TCXO_PCIE_MASK, + GS201_PMU_TCXO_PCIE_MASK); + if (ret) + dev_warn(gp->dev, "cannot set TCXO_BUF_CTRL: %d\n", ret); +} + +/* + * Init = Google's probe-time "resumed_phydown": take the PHY out of + * isolation and leave it powered down. This is the first access to the PMA + * and PCS. + */ +static int gs201_pcie_phy_init(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + int ret; + + ret = gs201_pcie_phy_clks_on(gp); + if (ret) + return ret; + + if (check_tcxo) + gs201_pcie_phy_check_tcxo(gp); + + gs201_phy_trace(gp, "about to set PMU %#x bit 0 (PHY isolation off, SMC)", + gp->pmu_offset); + ret = regmap_update_bits(gp->pmu, gp->pmu_offset, + GS201_PMU_PHY_BYPASS, GS201_PMU_PHY_BYPASS); + if (ret) { + dev_err(gp->dev, "PMU write failed: %d\n", ret); + clk_bulk_disable_unprepare(gp->num_clks, gp->clks); + return ret; + } + + gs201_pcie_phy_pwrdn(gp); + gs201_phy_trace(gp, "PHY out of isolation and powered down"); + + return 0; +} + +/* + * Google never isolates this PHY again after probe (use-phy-isol-con is not + * set for ch1), and DBI accesses hang while it is isolated. So exit leaves + * isolation off and only drops the clock references. + */ +static int gs201_pcie_phy_exit(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_phy_trace(gp, "exit: release clocks (isolation stays off, as stock)"); + clk_bulk_disable_unprepare(gp->num_clks, gp->clks); + + return 0; +} + +static int gs201_pcie_phy_power_on(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_pcie_phy_pwrdn_clear(gp); + gs201_pcie_phy_config(gp, gs201_pcie_phy_lanes(phy)); + gs201_pcie_phy_check_lock(gp); + gs201_phy_trace(gp, "PHY configured"); + + return 0; +} + +static int gs201_pcie_phy_power_off(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_pcie_phy_pwrdn(gp); + + return 0; +} + +/* + * Called by the controller after its soft power reset: Google logs the PMA + * offset calibration state at that point. Exposed as a PHY "calibrate" op so + * the controller can trigger it at the right time. + */ +static int gs201_pcie_phy_calibrate(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + u32 val; + + gs201_phy_trace(gp, "about to read PMA 0xe18 (OC after soft power reset)"); + val = readl(gp->pma + GS201_PMA_OC_STATUS2); + if (!(val & GS201_PMA_OC_STATUS2_DONE)) + dev_info(gp->dev, + "OC not done after soft power reset: PMA 0x760 %#x 0xe0c %#x 0x3f0 %#x 0xfc0 %#x\n", + readl(gp->pma + 0x760), + readl(gp->pma + GS201_PMA_CDR_STATUS), + readl(gp->pma + GS201_PMA_CMN_STATUS), + readl(gp->pma + GS201_PMA_LN0_STATUS)); + + return 0; +} + +static const struct phy_ops gs201_pcie_phy_ops = { + .init = gs201_pcie_phy_init, + .exit = gs201_pcie_phy_exit, + .power_on = gs201_pcie_phy_power_on, + .power_off = gs201_pcie_phy_power_off, + .calibrate = gs201_pcie_phy_calibrate, + .owner = THIS_MODULE, +}; + +static int gs201_pcie_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *provider; + struct gs201_pcie_phy *gp; + struct phy *phy; + int ret; + + gp = devm_kzalloc(dev, sizeof(*gp), GFP_KERNEL); + if (!gp) + return -ENOMEM; + + gp->dev = dev; + + /* Only mappings here: the PHY is not touched until phy_init() */ + gp->pma = devm_platform_ioremap_resource_byname(pdev, "pma"); + if (IS_ERR(gp->pma)) + return PTR_ERR(gp->pma); + + gp->pcs = devm_platform_ioremap_resource_byname(pdev, "pcs"); + if (IS_ERR(gp->pcs)) + return PTR_ERR(gp->pcs); + + gp->rst = devm_platform_ioremap_resource_byname(pdev, "rst"); + if (IS_ERR(gp->rst)) + return PTR_ERR(gp->rst); + + gp->udbg = devm_platform_ioremap_resource_byname(pdev, "udbg"); + if (IS_ERR(gp->udbg)) + return PTR_ERR(gp->udbg); + + gp->pmu = exynos_get_pmu_regmap_by_phandle(dev->of_node, + "samsung,pmu-syscon"); + if (IS_ERR(gp->pmu)) + return dev_err_probe(dev, PTR_ERR(gp->pmu), + "failed to get the PMU regmap\n"); + + ret = of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1, + &gp->pmu_offset); + if (ret) + return dev_err_probe(dev, ret, + "missing PMU PHY control offset\n"); + + gp->num_clks = devm_clk_bulk_get_all(dev, &gp->clks); + if (gp->num_clks < 0) + return dev_err_probe(dev, gp->num_clks, "failed to get clocks\n"); + + phy = devm_phy_create(dev, NULL, &gs201_pcie_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY\n"); + + phy_set_drvdata(phy, gp); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id gs201_pcie_phy_of_match[] = { + { .compatible = "google,gs201-pcie-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_pcie_phy_of_match); + +static struct platform_driver gs201_pcie_phy_driver = { + .probe = gs201_pcie_phy_probe, + .driver = { + .name = "gs201-pcie-phy", + .of_match_table = gs201_pcie_phy_of_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(gs201_pcie_phy_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe PHY driver"); +MODULE_LICENSE("GPL"); From f0681e1ac7643062acd9d15fd52344115ab69ec3 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sun, 11 Oct 2026 22:39:17 -0400 Subject: [PATCH 24/75] PCI: dwc: add Google gs201 PCIe host controller driver Add a host driver for the PCIe controllers of the Google gs201 (Tensor G2) SoC. Pixel 7 phones connect their BCM4389 Wi-Fi to the HSI2 controller (GEN4A_1), one lane at Gen2. The sequence follows the driver Google builds for gs201 (google-modules/soc/gs/drivers/pci/controller/dwc-whi/pcie-exynos-rc.c: resumed_phydown(), poweron() and establish_link()). Order matters: the bootloader leaves the PHY isolated, and any access to the controller's ELBI registers hangs the SoC until the PHY driver has released it. So: PHY init (isolation off, power-down) before the first ELBI access, then endpoint power through the pwrctrl core (WL_REG_ON, 200 ms), the PHY configuration and the I/A sequencer, the soft power and non-sticky resets with the device type set to root complex, PERST# release and 20 ms, the wrapper setup (exit-L1 request, manual link-down reset, no Q-channel clock gating, NAK on pending AXI), Gen3 equalization off, DMA cache coherency through the HSI2 sysreg, and finally the LTSSM, polled for L0 in the ELBI. As on stock, a failed attempt redoes the PHY and controller sequence; the last failure prints the LTSSM history buffer. Only INTx is supported, which is what the stock Wi-Fi driver uses: the ELBI interrupt status is demultiplexed into a four-line INTx domain, and link-down and completion-timeout events are logged. The chained handler is installed only once ELBI is reachable. A no-op msi_init keeps the DesignWare core from claiming the shared interrupt for its iMSI-RX, so devices fall back to INTx. Bring-up aids: the sequence runs in numbered stages and stop_after=N ends probe after stage N without binding (0 resources, 1 clocks, 2 PHY isolation off and first register access, 3 PHY configuration, 4 controller setup, 5 link); trace=1 logs every hardware step before it happens; use_ia=0 skips the I/A sequencer; cmu_acg_off=1 clears the CMU_HSI2 global automatic clock gating, as Google's driver does, through the optional samsung,cmu phandle. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/pci/controller/dwc/Kconfig | 12 + drivers/pci/controller/dwc/Makefile | 1 + drivers/pci/controller/dwc/pcie-gs201.c | 1182 +++++++++++++++++++++++ 3 files changed, 1195 insertions(+) create mode 100644 drivers/pci/controller/dwc/pcie-gs201.c diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index dcfbe7e229..329e17e67d 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -403,6 +403,18 @@ config PCI_EXYNOS hardware and therefore the driver re-uses the DesignWare core functions to implement the driver. +config PCIE_GS201 + tristate "Google gs201 PCIe controller (host mode)" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on PCI_MSI + select PCIE_DW_HOST + select PCI_PWRCTRL_GENERIC + help + Say Y here to enable support for the PCIe controller of the Google + gs201 (Tensor G2) SoC in host mode. Pixel 7 phones connect their + Wi-Fi chip to it. The controller uses the DesignWare core plus a + Samsung wrapper, and needs the gs201 PCIe PHY driver. + config PCIE_FU740 bool "SiFive FU740 PCIe controller" depends on PCI_MSI diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile index d4f88cfc62..b09cc858e2 100644 --- a/drivers/pci/controller/dwc/Makefile +++ b/drivers/pci/controller/dwc/Makefile @@ -9,6 +9,7 @@ obj-$(CONFIG_PCIE_ANDES_QILAI) += pcie-andes-qilai.o obj-$(CONFIG_PCIE_ESWIN) += pcie-eswin.o obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o +obj-$(CONFIG_PCIE_GS201) += pcie-gs201.o obj-$(CONFIG_PCIE_FU740) += pcie-fu740.o obj-$(CONFIG_PCI_IMX6) += pci-imx6.o obj-$(CONFIG_PCIE_NXP_S32G) += pcie-nxp-s32g.o diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c new file mode 100644 index 0000000000..2a9dac62cc --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -0,0 +1,1182 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * PCIe host controller driver for the Google gs201 (Tensor G2) SoC + * + * The controller is a Synopsys DesignWare core (IP version 0x984500) in a + * Samsung wrapper ("ELBI" sub-control registers, a link-training helper + * called I/A, and a sysreg for cache coherency). The sequence follows the + * driver Google builds for gs201, google-modules/soc/gs/drivers/pci/ + * controller/dwc-whi/pcie-exynos-rc.c (exynos_pcie_rc_resumed_phydown(), + * exynos_pcie_rc_poweron() and exynos_pcie_rc_establish_link()). + * + * Only legacy INTx interrupts are supported, which is what the Pixel 7 Wi-Fi + * uses on stock firmware too. + * + * Bring-up runs in numbered stages, each touching one more part of the + * hardware. The stop_after parameter ends probe after a given stage, and + * trace=1 logs every hardware step before it happens, so that a bus hang + * can be pinned to one register access. + * + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" + +/* ELBI (sub-control) registers */ +#define GS201_ELBI_IRQ0 0x000 +#define GS201_ELBI_IRQ0_INTA BIT(14) +#define GS201_ELBI_IRQ0_INTB BIT(16) +#define GS201_ELBI_IRQ0_INTC BIT(18) +#define GS201_ELBI_IRQ0_INTD BIT(20) +#define GS201_ELBI_IRQ1 0x004 +#define GS201_ELBI_IRQ1_LINK_DOWN BIT(10) +#define GS201_ELBI_IRQ2 0x008 +#define GS201_ELBI_IRQ2_CPL_TIMEOUT BIT(24) +#define GS201_ELBI_IRQ0_EN 0x010 +#define GS201_ELBI_IRQ1_EN 0x014 +#define GS201_ELBI_IRQ2_EN 0x018 +#define GS201_ELBI_LTSSM_EN 0x054 +#define GS201_ELBI_DEVICE_TYPE 0x080 +#define GS201_ELBI_DEVICE_TYPE_RC 0x4 +#define GS201_ELBI_LTSSM_STATE 0x2c8 +#define GS201_ELBI_LTSSM_STATE_MASK GENMASK(5, 0) +#define GS201_ELBI_PM_DSTATE 0x2e8 +#define GS201_ELBI_PM_DSTATE_MASK GENMASK(1, 0) +#define GS201_ELBI_IA_IRQ_SEL 0x388 +#define GS201_ELBI_IA_IRQ_LINK_UP BIT(10) +#define GS201_ELBI_LINKDOWN_RST_SEL 0x3a0 +#define GS201_ELBI_LINKDOWN_RST_MANUAL BIT(1) +#define GS201_ELBI_SOFT_RESET 0x3a4 +#define GS201_ELBI_SOFT_PWR_RESET BIT(1) +#define GS201_ELBI_SOFT_NON_STICKY_RESET BIT(3) +#define GS201_ELBI_QCH_SEL 0x3a8 +#define GS201_ELBI_QCH_GATING_MASK GENMASK(11, 0) +#define GS201_ELBI_REQ_EXIT_L1_MODE 0x3bc +#define GS201_ELBI_APP_REQ_EXIT_L1_MODE BIT(0) +#define GS201_ELBI_L1_REQ_NAK_MASTER BIT(4) +#define GS201_ELBI_MSTR_PEND_SEL_NAK 0x474 +#define GS201_ELBI_HISTORY_CTRL 0xc00 +#define GS201_ELBI_HISTORY_ENABLE GENMASK(1, 0) +#define GS201_ELBI_HISTORY_COND_SEL BIT(2) +#define GS201_ELBI_STATE_POWER_S 0xc04 +#define GS201_ELBI_STATE_POWER_M 0xc08 +#define GS201_ELBI_HISTORY(n) (0xc0c + 4 * (n)) +#define GS201_ELBI_HISTORY_NUM 32 +#define GS201_HISTORY_LTSSM GENMASK(21, 16) +#define GS201_HISTORY_DSTATE GENMASK(10, 8) +#define GS201_HISTORY_L1SUB GENMASK(2, 0) +#define GS201_ELBI_DBI_L1_EXIT_DISABLE 0x1078 + +/* INTA..INTD are every other bit from 14 (the bits in between: deassert) */ +#define GS201_ELBI_IRQ0_INTX_BIT(n) BIT(14 + 2 * (n)) + +/* DBI port logic registers used by Samsung's setup */ +#define GS201_DBI_AUX_CLK_FREQ 0xb40 +#define GS201_DBI_AUX_CLK_FREQ_26MHZ 26 + +/* SYSREG_HSI2 shareability control for this controller */ +#define GS201_SYSREG_SHARABLE_MASK GENMASK(1, 0) +#define GS201_SYSREG_SHARABLE_ENABLE 0x3 + +/* CMU_HSI2 registers, for the optional automatic clock gating switch */ +#define GS201_CMU_OPTION 0x0800 +#define GS201_CMU_OPTION_AUTO_GATING BIT(28) +#define GS201_CMU_GATE_FIRST 0x2000 +#define GS201_CMU_GATE_LAST 0x20f8 +#define GS201_CMU_QCH_PCIE_FIRST 0x3040 +#define GS201_CMU_QCH_PCIE_LAST 0x3064 + +/* Samsung's root port IDs */ +#define GS201_PCIE_VENDOR_ID PCI_VENDOR_ID_SAMSUNG +#define GS201_PCIE_DEVICE_ID 0xeced + +/* Google waits 20 ms after releasing PERST# before link training */ +#define GS201_PERST_DELAY_US 20000 + +/* Google polls 4800 x 10 us for L0, then retries the whole sequence */ +#define GS201_LINK_POLL_US 10 +#define GS201_LINK_TIMEOUT_US 48000 +#define GS201_LINK_TRIES 3 + +/* + * Bring-up stages. Each one adds hardware accesses to the previous ones; + * stop_after=N ends probe after stage N, with no host bridge registered. + */ +enum gs201_stage { + GS201_STAGE_NONE, /* 0: resources only, no hardware access */ + GS201_STAGE_CLOCKS, /* 1: clock references (+ optional CMU switch) */ + GS201_STAGE_WAKE, /* 2: PHY out of isolation, first PHY and ELBI accesses */ + GS201_STAGE_PHY, /* 3: PHY configuration, lock checks, I/A */ + GS201_STAGE_CTRL, /* 4: soft resets, ELBI and DBI setup */ + GS201_STAGE_LINK, /* 5: WL_REG_ON, PERST#, training, enumeration */ +}; + +static const char * const gs201_stage_names[] = { + [GS201_STAGE_NONE] = "resources", + [GS201_STAGE_CLOCKS] = "clocks", + [GS201_STAGE_WAKE] = "PHY isolation off, first PHY/ELBI access", + [GS201_STAGE_PHY] = "PHY configuration", + [GS201_STAGE_CTRL] = "controller setup", + [GS201_STAGE_LINK] = "link", +}; + +static unsigned int stop_after = GS201_STAGE_LINK; +module_param(stop_after, uint, 0444); +MODULE_PARM_DESC(stop_after, + "End probe after this bring-up stage: 0 resources, 1 clocks, 2 PHY isolation off + first register access, 3 PHY config, 4 controller setup, 5 link (default)"); + +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +static bool use_ia = true; +module_param(use_ia, bool, 0444); +MODULE_PARM_DESC(use_ia, + "Program the I/A CDR-lock sequencer, as stock does (default: true)"); + +static bool cmu_acg_off; +module_param(cmu_acg_off, bool, 0444); +MODULE_PARM_DESC(cmu_acg_off, + "Clear CMU_HSI2 automatic clock gating in stage 1, as Google's gs201 driver does (default: false)"); + +struct gs201_pcie { + struct dw_pcie pci; + void __iomem *elbi; + void __iomem *ia; + void __iomem *cmu; + resource_size_t elbi_phys; + resource_size_t ia_phys; + resource_size_t pma_phys; + struct regmap *sysreg; + u32 sysreg_offset; + struct clk_bulk_data *clks; + int num_clks; + int clks_on; + struct phy *phy; + struct gpio_desc *perst; + bool coherent; + bool phy_inited; + bool phy_on; + int irq; + struct irq_domain *intx_domain; + raw_spinlock_t lock; +}; + +#define to_gs201_pcie(x) dev_get_drvdata((x)->dev) + +/* + * Log a step before it touches the hardware, then give the log reader time + * to pick it up: if the next access hangs the bus, this line is the last + * one that leaves the phone. + */ +static __printf(2, 3) void gs201_trace(struct gs201_pcie *gp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(gp->pci.dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static u32 gs201_elbi_readl(struct gs201_pcie *gp, u32 reg) +{ + return readl(gp->elbi + reg); +} + +static void gs201_elbi_writel(struct gs201_pcie *gp, u32 reg, u32 val) +{ + writel(val, gp->elbi + reg); +} + +static void gs201_elbi_rmw(struct gs201_pcie *gp, u32 reg, u32 clr, u32 set) +{ + gs201_elbi_writel(gp, reg, (gs201_elbi_readl(gp, reg) & ~clr) | set); +} + +/* + * I/A: a small sequencer next to the controller that re-locks the PHY's CDR + * when the link leaves L1.2. Stock programs it on every link up + * (exynos_pcie_rc_use_ia()). The words are Samsung's microcode; the first + * three entries are the physical bases of the ELBI, the PMA and the I/A. + */ +static const struct { u16 off; u32 val; } gs201_ia_seq[] = { + { 0x040, 0x00023000 }, /* loop interval, 0x3000 bus clocks */ + { 0x100, 0x50000004 }, { 0x104, 0x00000100 }, /* SQ0 data mask */ + { 0x108, 0x20420008 }, { 0x10c, 0x00000100 }, /* SQ1 check CDR done */ + { 0x110, 0x50000004 }, { 0x114, 0x00000400 }, /* SQ2 data mask */ + { 0x118, 0x10000008 }, { 0x11c, 0x00000000 }, /* SQ3 loop */ + { 0x120, 0x40020008 }, { 0x124, 0x00000100 }, /* SQ4 CDR_EN 0 */ + { 0x128, 0x50000004 }, { 0x12c, 0x000000f0 }, /* SQ5 AFC toggle */ + { 0x130, 0x20d10fc0 }, { 0x134, 0x000000f0 }, /* SQ6 check CDR done */ + { 0x138, 0x40010a48 }, { 0x13c, 0x00000020 }, /* SQ7 CDR_EN 0x20 */ + { 0x140, 0x40010a48 }, { 0x144, 0x00000030 }, /* SQ8 CDR_EN 0x30 */ + { 0x148, 0x40010a48 }, { 0x14c, 0x00000000 }, /* SQ9 CDR_EN 0 */ + { 0x150, 0x40010bf4 }, { 0x154, 0x00000005 }, /* SQ10 AFC toggle */ + { 0x158, 0x40010bf4 }, { 0x15c, 0x00000004 }, /* SQ11 AFC toggle */ + { 0x160, 0x30010fc0 }, { 0x164, 0x000000f0 }, /* SQ12 check CDR done */ + { 0x168, 0x40010bf4 }, { 0x16c, 0x00000005 }, /* SQ13 AFC toggle */ + { 0x170, 0x40000008 }, { 0x174, 0x00000400 }, /* SQ14 clear IRQ */ + { 0x178, 0x80000000 }, { 0x17c, 0x00000000 }, /* SQ15 back to idle */ +}; + +#define GS201_IA_EN 0x000 +#define GS201_IA_ELBI_BASE 0x030 +#define GS201_IA_PMA_BASE 0x034 +#define GS201_IA_IA_BASE 0x038 + +#define GS201_IA_EN 0x000 +#define GS201_IA_ELBI_BASE 0x030 +#define GS201_IA_PMA_BASE 0x034 +#define GS201_IA_IA_BASE 0x038 + +static void gs201_pcie_ia_program(struct gs201_pcie *gp) +{ + unsigned int i; + + if (!gp->ia || !use_ia) + return; + + gs201_trace(gp, "about to program the I/A sequencer (ELBI 0x388, I/A 0x000-0x17c) and start it"); + gs201_elbi_writel(gp, GS201_ELBI_IA_IRQ_SEL, GS201_ELBI_IA_IRQ_LINK_UP); + + writel(lower_32_bits(gp->elbi_phys), gp->ia + GS201_IA_ELBI_BASE); + writel(lower_32_bits(gp->pma_phys), gp->ia + GS201_IA_PMA_BASE); + writel(lower_32_bits(gp->ia_phys), gp->ia + GS201_IA_IA_BASE); + + for (i = 0; i < ARRAY_SIZE(gs201_ia_seq); i++) + writel(gs201_ia_seq[i].val, gp->ia + gs201_ia_seq[i].off); + + writel(1, gp->ia + GS201_IA_EN); +} + +static void gs201_pcie_ia_disable(struct gs201_pcie *gp) +{ + if (!gp->ia || !use_ia) + return; + + gs201_trace(gp, "about to stop the I/A sequencer"); + writel(0, gp->ia + GS201_IA_EN); +} + +static void gs201_pcie_set_iocc(struct gs201_pcie *gp, bool enable) +{ + struct dw_pcie *pci = &gp->pci; + + if (!gp->sysreg) + return; + + gs201_trace(gp, "about to %s IOCC (DBI 0x8e8, SYSREG_HSI2 %#x)", + enable ? "enable" : "disable", gp->sysreg_offset); + + /* AxCACHE[1] = 1 for every master port */ + dw_pcie_writel_dbi(pci, COHERENCY_CONTROL_3_OFF, + enable ? 0x10101010 : 0); + + regmap_update_bits(gp->sysreg, gp->sysreg_offset, + GS201_SYSREG_SHARABLE_MASK, + enable ? GS201_SYSREG_SHARABLE_ENABLE : 0); +} + +static void gs201_pcie_setup_elbi(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to set up ELBI 0x3bc 0x3a0 0x3a8 0x474 0x1078 and the LTSSM history"); + gs201_elbi_rmw(gp, GS201_ELBI_REQ_EXIT_L1_MODE, 0, + GS201_ELBI_APP_REQ_EXIT_L1_MODE | + GS201_ELBI_L1_REQ_NAK_MASTER); + gs201_elbi_writel(gp, GS201_ELBI_LINKDOWN_RST_SEL, + GS201_ELBI_LINKDOWN_RST_MANUAL); + /* Q-channel: no clock gating requests from the controller */ + gs201_elbi_rmw(gp, GS201_ELBI_QCH_SEL, GS201_ELBI_QCH_GATING_MASK, 0); + /* NAK slave requests while AXI is pending */ + gs201_elbi_writel(gp, GS201_ELBI_MSTR_PEND_SEL_NAK, 1); + /* Keep DBI accesses from forcing an L1 exit (aux clock in L1.2) */ + gs201_elbi_writel(gp, GS201_ELBI_DBI_L1_EXIT_DISABLE, 1); + + /* LTSSM history buffer, for debugging failed training */ + gs201_elbi_rmw(gp, GS201_ELBI_HISTORY_CTRL, + GS201_ELBI_HISTORY_COND_SEL, 0); + gs201_elbi_writel(gp, GS201_ELBI_STATE_POWER_S, 0xffffffff); + gs201_elbi_writel(gp, GS201_ELBI_STATE_POWER_M, 0xffffffff); + gs201_elbi_rmw(gp, GS201_ELBI_HISTORY_CTRL, 0, + GS201_ELBI_HISTORY_ENABLE); +} + +static void gs201_pcie_setup_dbi(struct gs201_pcie *gp) +{ + struct dw_pcie *pci = &gp->pci; + u8 cap; + u32 val; + + gs201_trace(gp, "about to read DBI 0x000 and 0x8f8 (first DBI read)"); + dev_info(pci->dev, "DBI ID %#010x, DWC version %#010x\n", + dw_pcie_readl_dbi(pci, PCI_VENDOR_ID), + dw_pcie_readl_dbi(pci, PCIE_VERSION_NUMBER)); + + gs201_trace(gp, "about to walk the DBI capability list and write the root port setup"); + cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + + dw_pcie_dbi_ro_wr_en(pci); + + dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, GS201_PCIE_VENDOR_ID); + dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, GS201_PCIE_DEVICE_ID); + + /* Gen3 equalization off: the link is Gen2 at most on this board */ + dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, + GEN3_RELATED_OFF_GEN3_EQ_DISABLE | + GEN3_RELATED_OFF_RXEQ_RGRDLESS_RXTS); + + dw_pcie_writel_dbi(pci, GS201_DBI_AUX_CLK_FREQ, + GS201_DBI_AUX_CLK_FREQ_26MHZ); + + if (cap) { + /* L1 exit latency 64 us or more, as stock */ + val = dw_pcie_readl_dbi(pci, cap + PCI_EXP_LNKCAP); + val &= ~PCI_EXP_LNKCAP_L1EL; + val |= FIELD_PREP(PCI_EXP_LNKCAP_L1EL, 7); + dw_pcie_writel_dbi(pci, cap + PCI_EXP_LNKCAP, val); + + /* Completion timeout range B (16-55 ms), as stock */ + val = dw_pcie_readl_dbi(pci, cap + PCI_EXP_DEVCTL2); + val &= ~PCI_EXP_DEVCTL2_COMP_TIMEOUT; + val |= 0x5; + dw_pcie_writel_dbi(pci, cap + PCI_EXP_DEVCTL2, val); + } else { + dev_warn(pci->dev, "no PCIe capability in DBI\n"); + } + + dw_pcie_dbi_ro_wr_dis(pci); +} + +static enum dw_pcie_ltssm gs201_pcie_get_ltssm(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + + return FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); +} + +static bool gs201_pcie_link_up(struct dw_pcie *pci) +{ + enum dw_pcie_ltssm ltssm = gs201_pcie_get_ltssm(pci); + + /* Same window as Google's exynos_pcie_rc_link_up() */ + return ltssm >= DW_PCIE_LTSSM_RCVRY_LOCK && + ltssm <= DW_PCIE_LTSSM_L1_IDLE; +} + +static void gs201_pcie_enable_irqs(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to clear ELBI IRQ0-2 and enable link-down and completion-timeout interrupts"); + + /* Clear anything latched during training */ + gs201_elbi_writel(gp, GS201_ELBI_IRQ0, + gs201_elbi_readl(gp, GS201_ELBI_IRQ0)); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1, + gs201_elbi_readl(gp, GS201_ELBI_IRQ1)); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2, + gs201_elbi_readl(gp, GS201_ELBI_IRQ2)); + + gs201_elbi_rmw(gp, GS201_ELBI_IRQ1_EN, 0, GS201_ELBI_IRQ1_LINK_DOWN); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ2_EN, 0, GS201_ELBI_IRQ2_CPL_TIMEOUT); +} + +static void gs201_pcie_disable_irqs(struct gs201_pcie *gp) +{ + gs201_elbi_writel(gp, GS201_ELBI_IRQ0_EN, 0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1_EN, 0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2_EN, 0); +} + +/* Print the LTSSM history buffer, oldest entry first */ +static void gs201_pcie_dump_history(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + int i; + + for (i = GS201_ELBI_HISTORY_NUM - 1; i >= 0; i--) { + u32 h = gs201_elbi_readl(gp, GS201_ELBI_HISTORY(i)); + + dev_info(dev, "history: LTSSM %#04lx L1sub %lu D%lu\n", + FIELD_GET(GS201_HISTORY_LTSSM, h), + FIELD_GET(GS201_HISTORY_L1SUB, h), + FIELD_GET(GS201_HISTORY_DSTATE, h)); + } +} + +/* ---- Bring-up stages ------------------------------------------------- */ + +static void gs201_pcie_dump_cmu(struct gs201_pcie *gp, u32 first, u32 last) +{ + struct device *dev = gp->pci.dev; + u32 off; + + for (off = first; off <= last; off += 0x20) { + u32 v[8] = { }; + int i; + + for (i = 0; i < 8 && off + 4 * i <= last; i++) + v[i] = readl(gp->cmu + off + 4 * i); + + dev_info(dev, "CMU_HSI2 %#06x: %08x %08x %08x %08x %08x %08x %08x %08x\n", + off, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); + } +} + +/* + * Stage 1. The CMU_HSI2 gates run on automatic (Q-channel) gating, so the + * clock references below are bookkeeping and do not switch anything. + * Google's gs201 driver also clears the CMU's global automatic clock gating + * before using this controller; that is opt-in here (cmu_acg_off=1), + * because UFS lives in the same CMU. + */ +static int gs201_pcie_stage_clocks(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + u32 opt; + int ret; + + if (gp->cmu) { + gs201_trace(gp, "about to read CMU_HSI2 CONTROLLER_OPTION (0x14400800)"); + opt = readl(gp->cmu + GS201_CMU_OPTION); + dev_info(dev, "CMU_HSI2 option %#010x (automatic gating %s)\n", + opt, opt & GS201_CMU_OPTION_AUTO_GATING ? "on" : "off"); + + if (trace) { + gs201_trace(gp, "about to read the CMU_HSI2 gate and PCIe Q-channel registers"); + gs201_pcie_dump_cmu(gp, GS201_CMU_GATE_FIRST, + GS201_CMU_GATE_LAST); + gs201_pcie_dump_cmu(gp, GS201_CMU_QCH_PCIE_FIRST, + GS201_CMU_QCH_PCIE_LAST); + } + + if (cmu_acg_off && (opt & GS201_CMU_OPTION_AUTO_GATING)) { + gs201_trace(gp, "about to clear CMU_HSI2 option bit 28 (automatic clock gating; UFS shares this CMU)"); + writel(opt & ~GS201_CMU_OPTION_AUTO_GATING, + gp->cmu + GS201_CMU_OPTION); + dev_info(dev, "CMU_HSI2 automatic clock gating off (%#010x)\n", + readl(gp->cmu + GS201_CMU_OPTION)); + } + } else if (cmu_acg_off) { + dev_warn(dev, "cmu_acg_off needs samsung,cmu in the DT; skipped\n"); + } + + for (; gp->clks_on < gp->num_clks; gp->clks_on++) { + gs201_trace(gp, "enable clk %pC", gp->clks[gp->clks_on].clk); + ret = clk_prepare_enable(gp->clks[gp->clks_on].clk); + if (ret) + return ret; + } + + return 0; +} + +static void gs201_pcie_clocks_off(struct gs201_pcie *gp) +{ + while (gp->clks_on > 0) + clk_disable_unprepare(gp->clks[--gp->clks_on].clk); +} + +/* + * Stage 2. The bootloader leaves the PHY isolated in the PMU, and while it + * is isolated an ELBI access hangs the SoC (this is what hung the phone at + * W1.2 and W1.3). So the PHY driver releases isolation first (secure PMU + * write through the SMC), powers the PHY down as Google's probe does, and + * only then is the controller's ELBI touched. + */ +static int gs201_pcie_stage_wake(struct gs201_pcie *gp) +{ + struct dw_pcie *pci = &gp->pci; + int ret; + + if (!gp->phy_inited) { + gs201_trace(gp, "phy_init: PMU isolation off (SMC), then PHY power-down"); + phy_set_bus_width(gp->phy, pci->num_lanes ?: 1); + ret = phy_init(gp->phy); + if (ret) { + dev_err(pci->dev, "PHY init failed: %d\n", ret); + return ret; + } + gp->phy_inited = true; + } + + gs201_trace(gp, "about to write ELBI 0x010-0x018 (first ELBI access: interrupt enables off)"); + gs201_pcie_disable_irqs(gp); + + gs201_trace(gp, "about to write ELBI 0x054 (LTSSM off)"); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + + gs201_trace(gp, "about to read ELBI 0x3a8 0x3a4 0x080 (first ELBI reads)"); + dev_info(pci->dev, "ELBI QCH_SEL %#x SOFT_RESET %#x DEVICE_TYPE %#x\n", + gs201_elbi_readl(gp, GS201_ELBI_QCH_SEL), + gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET), + gs201_elbi_readl(gp, GS201_ELBI_DEVICE_TYPE)); + + return 0; +} + +/* Stage 3: Google's PHY configuration, then the I/A sequencer */ +static int gs201_pcie_stage_phy(struct gs201_pcie *gp) +{ + int ret; + + gs201_trace(gp, "phy_power_on: power-down clear, CAL table, lock checks"); + ret = phy_power_on(gp->phy); + if (ret) + return ret; + + gp->phy_on = true; + gs201_pcie_ia_program(gp); + + return 0; +} + +static void gs201_pcie_phy_off(struct gs201_pcie *gp) +{ + if (!gp->phy_on) + return; + + gs201_pcie_ia_disable(gp); + gs201_trace(gp, "phy_power_off: PHY power-down"); + phy_power_off(gp->phy); + gp->phy_on = false; +} + +/* + * Stage 4: the controller's soft resets and RC mode (Google's + * establish_link), then the ELBI and DBI setup and cache coherency. In the + * full bring-up PERST# is released between the resets and the setup, as + * Google does. + */ +static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) +{ + struct device *dev = gp->pci.dev; + u32 val; + + gs201_trace(gp, "about to pulse the soft power reset (ELBI 0x3a4 bit 1)"); + val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val & ~GS201_ELBI_SOFT_PWR_RESET); + mdelay(1); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_PWR_RESET); + + phy_calibrate(gp->phy); + + gs201_trace(gp, "about to write ELBI 0x080 = 4 (root complex)"); + gs201_elbi_writel(gp, GS201_ELBI_DEVICE_TYPE, GS201_ELBI_DEVICE_TYPE_RC); + + gs201_trace(gp, "about to pulse the non-sticky reset (ELBI 0x3a4 bit 3)"); + val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_NON_STICKY_RESET); + usleep_range(10, 12); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val & ~GS201_ELBI_SOFT_NON_STICKY_RESET); + mdelay(1); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_NON_STICKY_RESET); + + if (release_perst) { + gs201_trace(gp, "about to release PERST# (gph2-0) and wait 20 ms"); + gpiod_set_value_cansleep(gp->perst, 0); + fsleep(GS201_PERST_DELAY_US); + } + + gs201_pcie_setup_elbi(gp); + gs201_pcie_setup_dbi(gp); + gs201_pcie_set_iocc(gp, gp->coherent); + + gs201_trace(gp, "about to read ELBI 0x2e8 and 0x2c8 (D-state, LTSSM)"); + dev_info(dev, "D-state %lu, LTSSM %#lx\n", + FIELD_GET(GS201_ELBI_PM_DSTATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_PM_DSTATE)), + FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE))); +} + +/* Stages 1 to @last (at most 4), each one announced */ +static int gs201_pcie_bringup(struct gs201_pcie *gp, unsigned int last, + bool release_perst) +{ + struct device *dev = gp->pci.dev; + unsigned int stage; + int ret = 0; + + for (stage = GS201_STAGE_CLOCKS; + stage <= min_t(unsigned int, last, GS201_STAGE_CTRL); stage++) { + dev_info(dev, "stage %u/%u: %s\n", stage, GS201_STAGE_LINK, + gs201_stage_names[stage]); + /* Give the log reader the stage line before the hardware */ + if (trace && trace_delay_ms) + msleep(trace_delay_ms); + + switch (stage) { + case GS201_STAGE_CLOCKS: + ret = gs201_pcie_stage_clocks(gp); + break; + case GS201_STAGE_WAKE: + ret = gs201_pcie_stage_wake(gp); + break; + case GS201_STAGE_PHY: + ret = gs201_pcie_stage_phy(gp); + break; + case GS201_STAGE_CTRL: + gs201_pcie_stage_ctrl(gp, release_perst); + break; + } + if (ret) { + dev_err(dev, "stage %u failed: %d\n", stage, ret); + return ret; + } + dev_info(dev, "stage %u done\n", stage); + } + + return 0; +} + +/* Undo what the stages did, in reverse; the PHY stays out of isolation */ +static void gs201_pcie_bringdown(struct gs201_pcie *gp) +{ + gs201_pcie_phy_off(gp); + if (gp->phy_inited) { + gs201_trace(gp, "phy_exit"); + phy_exit(gp->phy); + gp->phy_inited = false; + } + gs201_pcie_clocks_off(gp); +} + +static int gs201_pcie_start_link(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + struct device *dev = pci->dev; + unsigned int try; + u32 val; + int ret; + + for (try = 1; try <= GS201_LINK_TRIES; try++) { + gs201_trace(gp, "link try %u: about to write ELBI 0x054 = 1 and poll 0x2c8 for L0 (48 ms)", + try); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 1); + + ret = readl_poll_timeout(gp->elbi + GS201_ELBI_LTSSM_STATE, val, + FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + val) == DW_PCIE_LTSSM_L0, + GS201_LINK_POLL_US, + GS201_LINK_TIMEOUT_US); + if (!ret) + break; + + dev_warn(dev, "link training failed (try %u), LTSSM %#lx\n", + try, FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, val)); + + if (try == GS201_LINK_TRIES) { + gs201_pcie_dump_history(gp); + break; + } + + /* + * As Google: PERST# low, LTSSM off, then the whole PHY and + * controller sequence again (the soft resets clear the + * root port setup, so the DWC part is redone too). + */ + gs201_trace(gp, "retry: PERST# low, LTSSM off, PHY and controller again"); + gpiod_set_value_cansleep(gp->perst, 1); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + gs201_pcie_phy_off(gp); + ret = gs201_pcie_stage_phy(gp); + if (ret) + return ret; + gs201_pcie_stage_ctrl(gp, true); + ret = dw_pcie_setup_rc(&pci->pp); + if (ret) + return ret; + } + + /* + * Leave the LTSSM running even on failure: dw_pcie_wait_for_link() + * reports the final state, and a card that shows up late can still + * train. + */ + if (!ret) { + dev_info(dev, "link up on try %u\n", try); + gs201_pcie_enable_irqs(gp); + } + + dev_dbg(dev, "D-state %lu, LTSSM %#x\n", + FIELD_GET(GS201_ELBI_PM_DSTATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_PM_DSTATE)), + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); + + return 0; +} + +static void gs201_pcie_stop_link(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + + gs201_pcie_disable_irqs(gp); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); +} + +static const struct dw_pcie_ops gs201_pcie_dw_ops = { + .link_up = gs201_pcie_link_up, + .get_ltssm = gs201_pcie_get_ltssm, + .start_link = gs201_pcie_start_link, + .stop_link = gs201_pcie_stop_link, +}; + +static void gs201_pcie_irq_handler(struct irq_desc *desc); + +/* + * Stage 5 entry, from dw_pcie_host_init(): stages 1-2, the endpoint power + * (WL_REG_ON, 200 ms), stages 3-4 with PERST# released, then the DWC core + * sets up the root port and calls start_link. This is the order of + * Google's resumed_phydown(), poweron() and establish_link(). + */ +static int gs201_pcie_host_init(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct gs201_pcie *gp = to_gs201_pcie(pci); + struct device *dev = pci->dev; + int ret; + + gpiod_set_value_cansleep(gp->perst, 1); + + ret = gs201_pcie_bringup(gp, GS201_STAGE_WAKE, false); + if (ret) + goto err_bringdown; + + /* ELBI is reachable and its interrupt enables are off */ + irq_set_chained_handler_and_data(gp->irq, gs201_pcie_irq_handler, gp); + + dev_info(dev, "stage %u/%u: %s\n", GS201_STAGE_LINK, GS201_STAGE_LINK, + gs201_stage_names[GS201_STAGE_LINK]); + + /* Endpoint power (WL_REG_ON) through pwrctrl, before the PHY config */ + if (!pci->suspended) { + gs201_trace(gp, "about to create the pwrctrl device for the root port"); + ret = pci_pwrctrl_create_devices(dev); + if (ret) + goto err_unchain; + } + + if (!pp->skip_pwrctrl_off) { + gs201_trace(gp, "about to power the endpoint (WL_REG_ON, gph2-4, 200 ms)"); + ret = pci_pwrctrl_power_on_devices(dev); + if (ret) + goto err_pwrctrl_destroy; + } + + ret = gs201_pcie_stage_phy(gp); + if (ret) + goto err_pwrctrl_off; + + gs201_pcie_stage_ctrl(gp, true); + + gs201_trace(gp, "handing over to the DWC core (version, iATU, root port setup)"); + + return 0; + +err_pwrctrl_off: + if (!pp->skip_pwrctrl_off) + pci_pwrctrl_power_off_devices(dev); +err_pwrctrl_destroy: + if (ret != -EPROBE_DEFER && !pci->suspended) + pci_pwrctrl_destroy_devices(dev); +err_unchain: + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); +err_bringdown: + gpiod_set_value_cansleep(gp->perst, 1); + gs201_pcie_bringdown(gp); + return ret; +} + +static void gs201_pcie_host_deinit(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct gs201_pcie *gp = to_gs201_pcie(pci); + + gs201_trace(gp, "deinit: PERST# low, IOCC off, PHY off, endpoint off"); + gpiod_set_value_cansleep(gp->perst, 1); + gs201_pcie_disable_irqs(gp); + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); + gs201_pcie_set_iocc(gp, false); + gs201_pcie_bringdown(gp); + + if (!pp->skip_pwrctrl_off) + pci_pwrctrl_power_off_devices(pci->dev); + if (!pci->suspended) + pci_pwrctrl_destroy_devices(pci->dev); +} + +/* + * The Samsung wrapper raises MSIs on the shared line or on separate SPIs and + * needs its own glue; nothing on this board uses MSI. Claim MSI init so the + * DWC core does not take over the shared interrupt for iMSI-RX. Devices fall + * back to INTx. + */ +static int gs201_pcie_msi_init(struct dw_pcie_rp *pp) +{ + return 0; +} + +static const struct dw_pcie_host_ops gs201_pcie_host_ops = { + .init = gs201_pcie_host_init, + .deinit = gs201_pcie_host_deinit, + .msi_init = gs201_pcie_msi_init, +}; + +static void gs201_pcie_intx_mask(struct irq_data *d) +{ + struct gs201_pcie *gp = irq_data_get_irq_chip_data(d); + unsigned long flags; + + raw_spin_lock_irqsave(&gp->lock, flags); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ0_EN, + GS201_ELBI_IRQ0_INTX_BIT(irqd_to_hwirq(d)), 0); + raw_spin_unlock_irqrestore(&gp->lock, flags); +} + +static void gs201_pcie_intx_unmask(struct irq_data *d) +{ + struct gs201_pcie *gp = irq_data_get_irq_chip_data(d); + unsigned long flags; + + raw_spin_lock_irqsave(&gp->lock, flags); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ0_EN, 0, + GS201_ELBI_IRQ0_INTX_BIT(irqd_to_hwirq(d))); + raw_spin_unlock_irqrestore(&gp->lock, flags); +} + +static struct irq_chip gs201_pcie_intx_chip = { + .name = "gs201-pcie-intx", + .irq_mask = gs201_pcie_intx_mask, + .irq_unmask = gs201_pcie_intx_unmask, +}; + +static int gs201_pcie_intx_map(struct irq_domain *domain, unsigned int irq, + irq_hw_number_t hwirq) +{ + irq_set_chip_and_handler(irq, &gs201_pcie_intx_chip, handle_level_irq); + irq_set_chip_data(irq, domain->host_data); + + return 0; +} + +static const struct irq_domain_ops gs201_pcie_intx_domain_ops = { + .map = gs201_pcie_intx_map, + .xlate = pci_irqd_intx_xlate, +}; + +static void gs201_pcie_irq_handler(struct irq_desc *desc) +{ + struct gs201_pcie *gp = irq_desc_get_handler_data(desc); + struct irq_chip *chip = irq_desc_get_chip(desc); + struct device *dev = gp->pci.dev; + unsigned long intx; + u32 irq0, irq1, irq2; + int bit; + + chained_irq_enter(chip, desc); + + /* The status bits are write-one-to-clear events */ + irq0 = gs201_elbi_readl(gp, GS201_ELBI_IRQ0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ0, irq0); + irq1 = gs201_elbi_readl(gp, GS201_ELBI_IRQ1); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1, irq1); + irq2 = gs201_elbi_readl(gp, GS201_ELBI_IRQ2); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2, irq2); + + if (irq1 & GS201_ELBI_IRQ1_LINK_DOWN) + dev_err_ratelimited(dev, "link down (LTSSM %#x)\n", + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); + if (irq2 & GS201_ELBI_IRQ2_CPL_TIMEOUT) + dev_err_ratelimited(dev, "completion timeout\n"); + + intx = 0; + for (bit = 0; bit < PCI_NUM_INTX; bit++) + if (irq0 & GS201_ELBI_IRQ0_INTX_BIT(bit)) + intx |= BIT(bit); + + for_each_set_bit(bit, &intx, PCI_NUM_INTX) + generic_handle_domain_irq(gp->intx_domain, bit); + + chained_irq_exit(chip, desc); +} + +/* + * Only the INTx domain is created here; the chained handler is installed by + * host_init once the PHY is out of isolation and the ELBI interrupt enables + * are off, because the handler reads ELBI. + */ +static int gs201_pcie_init_irq(struct gs201_pcie *gp, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *intc; + + gp->irq = platform_get_irq(pdev, 0); + if (gp->irq < 0) + return gp->irq; + + intc = of_get_child_by_name(dev->of_node, "legacy-interrupt-controller"); + if (!intc) + return dev_err_probe(dev, -ENODEV, + "missing legacy-interrupt-controller\n"); + + gp->intx_domain = irq_domain_create_linear(of_fwnode_handle(intc), + PCI_NUM_INTX, + &gs201_pcie_intx_domain_ops, + gp); + of_node_put(intc); + if (!gp->intx_domain) + return -ENOMEM; + + return 0; +} + +static void gs201_pcie_remove_irq(struct gs201_pcie *gp) +{ + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); + irq_domain_remove(gp->intx_domain); +} + +/* The I/A sequencer needs the PMA's physical address from the PHY node */ +static int gs201_pcie_get_ia(struct gs201_pcie *gp, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *phy_np; + struct resource *res, pma; + int idx, ret; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ia"); + if (!res) + return 0; + + phy_np = of_parse_phandle(dev->of_node, "phys", 0); + if (!phy_np) + return -ENODEV; + + idx = of_property_match_string(phy_np, "reg-names", "pma"); + ret = idx < 0 ? idx : of_address_to_resource(phy_np, idx, &pma); + of_node_put(phy_np); + if (ret) + return dev_err_probe(dev, ret, "no PMA address for I/A\n"); + + gp->ia = devm_ioremap_resource(dev, res); + if (IS_ERR(gp->ia)) + return PTR_ERR(gp->ia); + + gp->ia_phys = res->start; + gp->pma_phys = pma.start; + + return 0; +} + +/* + * Optional: CMU_HSI2, for the automatic clock gating switch and the gate + * dump. The clock driver owns (and has requested) that region, so it is + * mapped without a request. + */ +static int gs201_pcie_get_cmu(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + struct device_node *cmu_np; + struct resource res; + int ret; + + cmu_np = of_parse_phandle(dev->of_node, "samsung,cmu", 0); + if (!cmu_np) + return 0; + + ret = of_address_to_resource(cmu_np, 0, &res); + of_node_put(cmu_np); + if (ret) + return dev_err_probe(dev, ret, "bad samsung,cmu\n"); + + if (resource_size(&res) <= GS201_CMU_QCH_PCIE_LAST) + return dev_err_probe(dev, -EINVAL, "samsung,cmu region too small\n"); + + gp->cmu = devm_ioremap(dev, res.start, resource_size(&res)); + if (!gp->cmu) + return -ENOMEM; + + return 0; +} + +/* stop_after < 5: run the stages, report, undo, and do not bind */ +static int gs201_pcie_staged_probe(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + struct platform_device *pdev = to_platform_device(dev); + int ret; + + /* dw_pcie_host_init() is not called, so map the DBI for stage 4 */ + if (stop_after >= GS201_STAGE_CTRL) { + gp->pci.dbi_base = devm_platform_ioremap_resource_byname(pdev, "dbi"); + if (IS_ERR(gp->pci.dbi_base)) + return PTR_ERR(gp->pci.dbi_base); + } + + ret = gs201_pcie_bringup(gp, stop_after, false); + gs201_pcie_bringdown(gp); + if (ret) + return ret; + + dev_info(dev, "stopped after stage %u as asked (stop_after=%u); not binding\n", + stop_after, stop_after); + + return -ENODEV; +} + +static int gs201_pcie_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct gs201_pcie *gp; + struct dw_pcie *pci; + struct resource *res; + int ret; + + gp = devm_kzalloc(dev, sizeof(*gp), GFP_KERNEL); + if (!gp) + return -ENOMEM; + + raw_spin_lock_init(&gp->lock); + + pci = &gp->pci; + pci->dev = dev; + pci->ops = &gs201_pcie_dw_ops; + pci->pp.ops = &gs201_pcie_host_ops; + + dev_info(dev, "stage 0/%u: %s (stop_after=%u, trace=%d, use_ia=%d, cmu_acg_off=%d)\n", + GS201_STAGE_LINK, gs201_stage_names[GS201_STAGE_NONE], + stop_after, trace, use_ia, cmu_acg_off); + + /* Mappings only: nothing below touches the hardware */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi"); + gp->elbi = devm_ioremap_resource(dev, res); + if (IS_ERR(gp->elbi)) + return PTR_ERR(gp->elbi); + gp->elbi_phys = res->start; + /* Hand it to the DWC core, which would otherwise request it again. */ + pci->elbi_base = gp->elbi; + + ret = gs201_pcie_get_ia(gp, pdev); + if (ret) + return ret; + + ret = gs201_pcie_get_cmu(gp); + if (ret) + return ret; + + gp->coherent = of_dma_is_coherent(np); + if (gp->coherent) { + gp->sysreg = syscon_regmap_lookup_by_phandle_args(np, + "samsung,sysreg", + 1, + &gp->sysreg_offset); + if (IS_ERR(gp->sysreg)) + return dev_err_probe(dev, PTR_ERR(gp->sysreg), + "dma-coherent needs samsung,sysreg\n"); + } + + gp->num_clks = devm_clk_bulk_get_all(dev, &gp->clks); + if (gp->num_clks < 0) + return dev_err_probe(dev, gp->num_clks, "failed to get clocks\n"); + + gp->phy = devm_phy_get(dev, "pcie"); + if (IS_ERR(gp->phy)) + return dev_err_probe(dev, PTR_ERR(gp->phy), "failed to get PHY\n"); + + /* PERST# asserted (a GPIO, not the controller) until stage 5 */ + gp->perst = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gp->perst)) + return dev_err_probe(dev, PTR_ERR(gp->perst), + "failed to get PERST# GPIO\n"); + + /* The DWC core reads num-lanes in host_init; stages need it earlier */ + if (of_property_read_u32(np, "num-lanes", &pci->num_lanes)) + pci->num_lanes = 1; + + platform_set_drvdata(pdev, gp); + + if (stop_after < GS201_STAGE_LINK) + return gs201_pcie_staged_probe(gp); + + ret = gs201_pcie_init_irq(gp, pdev); + if (ret) + return ret; + + ret = dw_pcie_host_init(&pci->pp); + if (ret) { + dev_err_probe(dev, ret, "failed to initialize host\n"); + gs201_pcie_remove_irq(gp); + return ret; + } + + return 0; +} + +static void gs201_pcie_remove(struct platform_device *pdev) +{ + struct gs201_pcie *gp = platform_get_drvdata(pdev); + + dw_pcie_host_deinit(&gp->pci.pp); + gs201_pcie_remove_irq(gp); +} + +static const struct of_device_id gs201_pcie_of_match[] = { + { .compatible = "google,gs201-pcie" }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_pcie_of_match); + +static struct platform_driver gs201_pcie_driver = { + .probe = gs201_pcie_probe, + .remove = gs201_pcie_remove, + .driver = { + .name = "gs201-pcie", + .of_match_table = gs201_pcie_of_match, + }, +}; +module_platform_driver(gs201_pcie_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe host controller driver"); +MODULE_LICENSE("GPL"); From 2748b4cabd0520b8674e21f9970d72ec84590779 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:45:27 -0400 Subject: [PATCH 25/75] PCI: dwc: gs201: program the coherency again after link up Google's driver programs the I/O coherency (AxCACHE in DBI 0x8e8 and the HSI2 shareability in SYSREG_HSI2 0x730) after the root port setup in exynos_pcie_rc_establish_link(), and once more at the end of exynos_pcie_rc_probe(), after the endpoint is enumerated. We did it once, before the link came up. The Wi-Fi chip is dma-coherent through this bridge. If the coherency were not in effect, the chip would read stale ring memory and the host would not see what the chip writes, which is how the first BCM4389 runs fail. Program it again after link up and after enumeration, and print the two registers, so the log shows what is in effect. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/pci/controller/dwc/pcie-gs201.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c index 2a9dac62cc..af650d7638 100644 --- a/drivers/pci/controller/dwc/pcie-gs201.c +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -311,6 +311,27 @@ static void gs201_pcie_set_iocc(struct gs201_pcie *gp, bool enable) enable ? GS201_SYSREG_SHARABLE_ENABLE : 0); } +/* + * Google's driver programs the coherency once after the root port setup and + * again once the endpoint is enumerated (exynos_pcie_rc_establish_link() and + * the end of exynos_pcie_rc_probe()). Do the same, and print what the + * registers hold, since a device that is marked dma-coherent but is not + * snooped sees stale ring memory. + */ +static void gs201_pcie_check_iocc(struct gs201_pcie *gp, const char *when) +{ + struct dw_pcie *pci = &gp->pci; + u32 shr = 0; + + if (!gp->sysreg || !gp->coherent) + return; + + gs201_pcie_set_iocc(gp, true); + regmap_read(gp->sysreg, gp->sysreg_offset, &shr); + dev_info(pci->dev, "IOCC %s: AxCACHE 0x%08x, shareability 0x%x\n", when, + dw_pcie_readl_dbi(pci, COHERENCY_CONTROL_3_OFF), shr); +} + static void gs201_pcie_setup_elbi(struct gs201_pcie *gp) { gs201_trace(gp, "about to set up ELBI 0x3bc 0x3a0 0x3a8 0x474 0x1078 and the LTSSM history"); @@ -735,6 +756,7 @@ static int gs201_pcie_start_link(struct dw_pcie *pci) if (!ret) { dev_info(dev, "link up on try %u\n", try); gs201_pcie_enable_irqs(gp); + gs201_pcie_check_iocc(gp, "after link up"); } dev_dbg(dev, "D-state %lu, LTSSM %#x\n", @@ -1151,6 +1173,8 @@ static int gs201_pcie_probe(struct platform_device *pdev) return ret; } + gs201_pcie_check_iocc(gp, "after enumeration"); + return 0; } From 93ede0e6b2634574b2454f89e78774f320edd7fe Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 10:27:01 -0400 Subject: [PATCH 26/75] PCI: dwc: gs201: add a System MMU DMA window for the GEN4A_1 controller The Wi-Fi chip on the gs201 PCIe GEN4A_1 controller can DMA anywhere in RAM: there is no IOMMU in use and the HSI2 S2MPU is left open (CTRL0 = 0). Stock Android puts the controller's traffic through the HSI2 PCIe System MMU (0x145c0000, version 8.1, VID 1). Use that System MMU as a firewall rather than a translator: one first-level table (36-bit IOVA, 1 MiB sections, 256 KiB aligned) that maps a single reserved region 1:1, so the device driver keeps using physical addresses and nothing outside the region is reachable. The register map, table format and enable sequence follow Google's exynos-pcie-iommu-whi driver; faults are reported from the System MMU interrupt with the address and direction. A mode parameter stages the bring-up: 0 only logs the registers (default), 1 enforces, 2 enforces with an empty table as a negative test. The window comes from "google,dma-window", not "memory-region": for a restricted-dma-pool, memory-region would also make the pool the SysMMU node's own swiotlb, so mapping the first-level table for the walker would bounce it into the very window the PCIe device may write, and the device could rewrite its own page table. A table that was bounced or overlaps the window is refused. An enforced empty table did not stop the Wi-Fi chip's DMA on VID 1. No kernel code assigns the controller's VID (stock 1:1 maps every buffer, so it never notices a bypass either), so the driver also: - has "vids", a bitmask of VIDs to translate (default: google,vid); - has mode 3, a 1:1 map of everything except the window, which only blocks DMA into the window and is therefore safe on every VID; - reads the fault address and info from the faulting VID's registers (0x1000 + 0x10 * vid with VM support), not always VID 1's; - restores each VID's CTRL on remove rather than writing 0. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/pci/controller/dwc/Kconfig | 9 + drivers/pci/controller/dwc/Makefile | 1 + .../pci/controller/dwc/pcie-gs201-sysmmu.c | 373 ++++++++++++++++++ 3 files changed, 383 insertions(+) create mode 100644 drivers/pci/controller/dwc/pcie-gs201-sysmmu.c diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index 329e17e67d..3a3f5b8b6a 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -415,6 +415,15 @@ config PCIE_GS201 Wi-Fi chip to it. The controller uses the DesignWare core plus a Samsung wrapper, and needs the gs201 PCIe PHY driver. +config PCIE_GS201_SYSMMU + tristate "Google gs201 PCIe System MMU as a DMA window" + depends on PCIE_GS201 + help + Confine the DMA of the device on the gs201 PCIe GEN4A_1 controller + (the Pixel 7 Wi-Fi chip) to one reserved memory region, with the + System MMU that sits in front of the controller. The region is + mapped 1:1, so the device driver keeps using physical addresses. + config PCIE_FU740 bool "SiFive FU740 PCIe controller" depends on PCI_MSI diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile index b09cc858e2..cee2d114d7 100644 --- a/drivers/pci/controller/dwc/Makefile +++ b/drivers/pci/controller/dwc/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_PCIE_ESWIN) += pcie-eswin.o obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o obj-$(CONFIG_PCIE_GS201) += pcie-gs201.o +obj-$(CONFIG_PCIE_GS201_SYSMMU) += pcie-gs201-sysmmu.o obj-$(CONFIG_PCIE_FU740) += pcie-fu740.o obj-$(CONFIG_PCI_IMX6) += pci-imx6.o obj-$(CONFIG_PCIE_NXP_S32G) += pcie-nxp-s32g.o diff --git a/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c new file mode 100644 index 0000000000..25583eab50 --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c @@ -0,0 +1,373 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * DMA window for the Google gs201 PCIe GEN4A_1 (Wi-Fi) controller + * + * The HSI2 block has a Samsung System MMU (version 8.1) in front of the + * PCIe channel 1 master. Stock Android translates the Wi-Fi chip's DMA + * through it (VID 1). Here it is used as a firewall instead: one first-level + * table that maps a single reserved region 1:1 (IOVA = PA), so the device + * keeps using physical addresses but cannot reach anything else. Any other + * access is a translation fault, logged by this driver. + * + * Register map, table format and enable sequence follow Google's driver, + * google-modules/soc/gs/drivers/iommu/exynos-pcie-iommu-whi.[ch] + * (__sysmmu_enable_nocount(), __sysmmu_set_ptbase(), the fault handler). + * + * The "mode" parameter stages the bring-up: + * 0 read the registers and log them, change nothing (default) + * 1 enforce: map the region from google,dma-window, nothing else + * 2 enforce with an empty table (every DMA faults; a negative test) + * 3 map everything 1:1 except the region (only DMA into the region + * faults; a negative test that is safe to run on every VID) + * + * Which VID the PCIe master's traffic carries is not programmed by any + * kernel code (stock or here); "vids" selects the VIDs to translate, and a + * fault line names the VID it came from. + * + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_MMU_CTRL 0x0000 +#define REG_MMU_CFG 0x0004 +#define REG_MMU_STATUS 0x0008 +#define REG_MMU_VERSION 0x0034 +#define REG_INT_STATUS 0x0060 +#define REG_INT_CLEAR 0x0064 +/* With VM (CAPA1 bit 14) the fault registers are per VID, 0x10 apart */ +#define REG_FAULT_ADDR_VA(n) (0x1000 + (n) * 0x10) +#define REG_FAULT_INFO0(n) (0x1004 + (n) * 0x10) +#define REG_MMU_TLB_CFG0 0x2004 +#define REG_MMU_CTRL_VID(n) (0x8000 + (n) * 0x1000) +#define REG_MMU_CFG_VID(n) (0x8004 + (n) * 0x1000) +#define REG_PT_BASE_PPN_VID(n) (0x800c + (n) * 0x1000) +#define REG_MMU_FLUSH_VID(n) (0x8010 + (n) * 0x1000) + +#define CTRL_ENABLE 0x5 +#define CTRL_MMU_ENABLE BIT(0) +#define CTRL_FAULT_STALL_MODE BIT(3) + +#define MMU_RAW_VER(reg) (((reg) >> 17) & 0x7fff) +#define MMU_MAJ_VER(val) ((val) >> 11) +#define MMU_MIN_VER(val) (((val) >> 4) & 0x7f) + +/* 36-bit IOVA, 1 MiB first-level sections, 256 KiB-aligned table */ +#define NUM_LV1ENTRIES SZ_64K +#define LV1_TABLE_SIZE (NUM_LV1ENTRIES * sizeof(u32)) +#define SECT_ORDER 20 +#define SECT_SIZE BIT(SECT_ORDER) +#define PG_ENT_SHIFT 4 +#define LV1_SECT 2 +#define LV1_SHAREABLE BIT(6) +#define PT_BASE_SHIFT 12 + +static unsigned int mode; +module_param(mode, uint, 0444); +MODULE_PARM_DESC(mode, "0: log only (default), 1: map the DMA region only, 2: empty table, 3: everything but the DMA region (negative tests)"); + +static bool stall; +module_param(stall, bool, 0444); +MODULE_PARM_DESC(stall, "Leave the VID in stall-on-fault mode (default: error response)"); + +static unsigned int vids; +module_param(vids, uint, 0444); +MODULE_PARM_DESC(vids, "Bitmask of VIDs to translate (default: the DT's google,vid only); with mode=3, 0xff finds the one the controller uses"); + +static bool shareable = true; +module_param(shareable, bool, 0444); +MODULE_PARM_DESC(shareable, "Mark the mapped sections shareable (the controller is cache coherent)"); + +struct gs201_sysmmu { + struct device *dev; + void __iomem *base; + struct clk_bulk_data *clks; + int num_clks; + u32 vid; + u32 vid_mask; + u32 *table; + dma_addr_t table_dma; + u32 saved_ctrl; + u32 saved_ctrl_vid[8]; + bool enforcing; +}; + +static void gs201_sysmmu_dump(struct gs201_sysmmu *mmu, const char *when) +{ + u32 ver = readl(mmu->base + REG_MMU_VERSION); + unsigned int v; + + dev_info(mmu->dev, "%s: version %#x (v%u.%u) ctrl %#x cfg %#x status %#x int %#x\n", + when, ver, MMU_MAJ_VER(MMU_RAW_VER(ver)), + MMU_MIN_VER(MMU_RAW_VER(ver)), + readl(mmu->base + REG_MMU_CTRL), + readl(mmu->base + REG_MMU_CFG), + readl(mmu->base + REG_MMU_STATUS), + readl(mmu->base + REG_INT_STATUS)); + + for (v = 0; v < 8; v++) { + if (!(BIT(v) & (mmu->vid_mask | BIT(mmu->vid)))) + continue; + /* pt_base is printed as an address: PPN << 12 */ + dev_info(mmu->dev, "%s: VID %u ctrl %#x cfg %#x table at %#llx\n", + when, v, readl(mmu->base + REG_MMU_CTRL_VID(v)), + readl(mmu->base + REG_MMU_CFG_VID(v)), + (u64)readl(mmu->base + REG_PT_BASE_PPN_VID(v)) << + PT_BASE_SHIFT); + } +} + +static irqreturn_t gs201_sysmmu_irq(int irq, void *data) +{ + struct gs201_sysmmu *mmu = data; + u32 status, info; + unsigned int v; + u64 addr; + + status = readl(mmu->base + REG_INT_STATUS); + if (!status) + return IRQ_NONE; + + /* Four interrupt bits per VID: PTW access, page fault, multi-hit, access */ + v = __ffs(status) / 4; + addr = readl(mmu->base + REG_FAULT_ADDR_VA(v)); + info = readl(mmu->base + REG_FAULT_INFO0(v)); + addr |= (u64)((info >> 28) & 0xf) << 32; + + dev_err_ratelimited(mmu->dev, + "blocked %s at %#llx (int %#x, VID %u, type %u, AxID %#x)\n", + (info & BIT(20)) ? "WRITE" : "READ", addr, status, + v, __ffs(status) % 4, info & 0xffff); + + writel(status, mmu->base + REG_INT_CLEAR); + return IRQ_HANDLED; +} + +static int gs201_sysmmu_build_table(struct gs201_sysmmu *mmu) +{ + struct reserved_mem *rmem = NULL; + struct device_node *np; + phys_addr_t pa, end; + u32 ent; + + /* + * Not "memory-region": for a restricted-dma-pool that would make the + * pool this device's own bounce buffer, and the table, mapped below, + * would be bounced into the very window the PCIe device may write. + */ + np = of_parse_phandle(mmu->dev->of_node, "google,dma-window", 0); + if (np) { + rmem = of_reserved_mem_lookup(np); + of_node_put(np); + } + if (!rmem) + return dev_err_probe(mmu->dev, -EINVAL, + "no google,dma-window to allow\n"); + + if (!IS_ALIGNED(rmem->base, SECT_SIZE) || + !IS_ALIGNED(rmem->size, SECT_SIZE) || + rmem->base + rmem->size > BIT_ULL(36)) + return dev_err_probe(mmu->dev, -EINVAL, + "region %pa + %pa is not 1 MiB sections below 64 GiB\n", + &rmem->base, &rmem->size); + + /* 256 KiB, naturally aligned (Google: "FLPD must be aligned in 256KB") */ + mmu->table = (u32 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(LV1_TABLE_SIZE)); + if (!mmu->table) + return -ENOMEM; + + end = rmem->base + rmem->size; + if (mode == 3) { + for (ent = 0; ent < NUM_LV1ENTRIES; ent++) { + pa = (phys_addr_t)ent << SECT_ORDER; + if (pa >= rmem->base && pa < end) + continue; + mmu->table[ent] = (u32)(pa >> PG_ENT_SHIFT) | LV1_SECT | + (shareable ? LV1_SHAREABLE : 0); + } + dev_info(mmu->dev, "blocking only %pa..%pa, everything else 1:1\n", + &rmem->base, &end); + } else if (mode == 1) { + for (pa = rmem->base; pa < end; pa += SECT_SIZE) { + ent = (u32)(pa >> PG_ENT_SHIFT) | LV1_SECT; + if (shareable) + ent |= LV1_SHAREABLE; + mmu->table[pa >> SECT_ORDER] = ent; + } + dev_info(mmu->dev, "allowing %pa..%pa (%llu sections)\n", + &rmem->base, &end, + (u64)(rmem->size >> SECT_ORDER)); + } else { + dev_info(mmu->dev, "empty table: every DMA will fault\n"); + } + + /* The table walker is not coherent: map it for the device (cleans). */ + mmu->table_dma = dma_map_single(mmu->dev, mmu->table, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + if (dma_mapping_error(mmu->dev, mmu->table_dma)) { + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + mmu->table = NULL; + return -ENOMEM; + } + if (mmu->table_dma != virt_to_phys(mmu->table) || + (mmu->table_dma < end && + mmu->table_dma + LV1_TABLE_SIZE > rmem->base)) { + dev_err(mmu->dev, "table at %pad is bounced or inside the window\n", + &mmu->table_dma); + dma_unmap_single(mmu->dev, mmu->table_dma, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + mmu->table = NULL; + return -EINVAL; + } + dev_info(mmu->dev, "table at %pad (outside the window)\n", + &mmu->table_dma); + return 0; +} + +static void gs201_sysmmu_enable(struct gs201_sysmmu *mmu) +{ + unsigned int v; + u32 ctrl; + + mmu->saved_ctrl = readl(mmu->base + REG_MMU_CTRL); + + /* As __sysmmu_enable_nocount(): TLB0, table base, flush, enable */ + writel(0, mmu->base + REG_MMU_TLB_CFG0); + for (v = 0; v < 8; v++) { + if (!(BIT(v) & mmu->vid_mask)) + continue; + writel(mmu->table_dma >> PT_BASE_SHIFT, + mmu->base + REG_PT_BASE_PPN_VID(v)); + writel(1, mmu->base + REG_MMU_FLUSH_VID(v)); + } + writel(mmu->saved_ctrl | CTRL_ENABLE, mmu->base + REG_MMU_CTRL); + + for (v = 0; v < 8; v++) { + if (!(BIT(v) & mmu->vid_mask)) + continue; + ctrl = readl(mmu->base + REG_MMU_CTRL_VID(v)); + mmu->saved_ctrl_vid[v] = ctrl; + if (stall) + ctrl |= CTRL_FAULT_STALL_MODE; + else + ctrl &= ~CTRL_FAULT_STALL_MODE; + writel(ctrl | CTRL_MMU_ENABLE, mmu->base + REG_MMU_CTRL_VID(v)); + writel(1, mmu->base + REG_MMU_FLUSH_VID(v)); + } + mmu->enforcing = true; +} + +static void gs201_sysmmu_disable(struct gs201_sysmmu *mmu) +{ + unsigned int v; + + if (!mmu->enforcing) + return; + for (v = 0; v < 8; v++) + if (BIT(v) & mmu->vid_mask) + writel(mmu->saved_ctrl_vid[v], + mmu->base + REG_MMU_CTRL_VID(v)); + writel(mmu->saved_ctrl, mmu->base + REG_MMU_CTRL); + mmu->enforcing = false; +} + +static int gs201_sysmmu_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct gs201_sysmmu *mmu; + int irq, ret; + + mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL); + if (!mmu) + return -ENOMEM; + mmu->dev = dev; + platform_set_drvdata(pdev, mmu); + + mmu->vid = 1; + of_property_read_u32(dev->of_node, "google,vid", &mmu->vid); + if (mmu->vid > 7) + return dev_err_probe(dev, -EINVAL, "bad VID %u\n", mmu->vid); + mmu->vid_mask = (vids & 0xff) ?: BIT(mmu->vid); + + mmu->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(mmu->base)) + return PTR_ERR(mmu->base); + + ret = devm_clk_bulk_get_all_enabled(dev, &mmu->clks); + if (ret < 0) + return dev_err_probe(dev, ret, "clocks\n"); + mmu->num_clks = ret; + + gs201_sysmmu_dump(mmu, "probe"); + if (!mode) + return 0; + if (mode > 3) + return dev_err_probe(dev, -EINVAL, "bad mode %u\n", mode); + + ret = dma_set_mask(dev, DMA_BIT_MASK(36)); + if (ret) + return ret; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + ret = devm_request_irq(dev, irq, gs201_sysmmu_irq, 0, dev_name(dev), + mmu); + if (ret) + return ret; + + ret = gs201_sysmmu_build_table(mmu); + if (ret) + return ret; + + gs201_sysmmu_enable(mmu); + gs201_sysmmu_dump(mmu, "enforcing"); + return 0; +} + +static void gs201_sysmmu_remove(struct platform_device *pdev) +{ + struct gs201_sysmmu *mmu = platform_get_drvdata(pdev); + + gs201_sysmmu_disable(mmu); + if (mmu->table) { + dma_unmap_single(mmu->dev, mmu->table_dma, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + } +} + +static const struct of_device_id gs201_sysmmu_of_match[] = { + { .compatible = "google,gs201-pcie-sysmmu" }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_sysmmu_of_match); + +static struct platform_driver gs201_sysmmu_driver = { + .probe = gs201_sysmmu_probe, + .remove = gs201_sysmmu_remove, + .driver = { + .name = "gs201-pcie-sysmmu", + .of_match_table = gs201_sysmmu_of_match, + /* unbinding while the device is busy would drop the firewall */ + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(gs201_sysmmu_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe System MMU as a DMA window"); +MODULE_LICENSE("GPL"); From 530c8c744cdcd855df2c316a35068cba541b989c Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 11:15:06 -0400 Subject: [PATCH 27/75] PCI: dwc: gs201: refuse to translate SysMMU VID 0 by default Negative tests on cheetah showed that the PCIe controller's DMA (AxID 0x0) and the UFS host controller's (AxID 0x2) both arrive on VID 0. An empty or window-only table on VID 0 blocked the UFS transfer request list, storage stalled and the phone wedged. Refuse any mode that would translate VID 0 unless the debug parameter allow_vid0 is set, and document the measurement. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/pci/controller/dwc/pcie-gs201-sysmmu.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c index 25583eab50..c3a865c668 100644 --- a/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c +++ b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c @@ -22,7 +22,10 @@ * * Which VID the PCIe master's traffic carries is not programmed by any * kernel code (stock or here); "vids" selects the VIDs to translate, and a - * fault line names the VID it came from. + * fault line names the VID it came from. Measured on cheetah: both the PCIe + * master (AxID 0x0) and the UFS host controller (AxID 0x2) arrive on VID 0, + * so this SysMMU cannot confine the PCIe device without also confining + * storage. VID 0 is refused unless allow_vid0 is set (debug only). * * Copyright (C) 2020 Samsung Electronics Co., Ltd. */ @@ -83,6 +86,10 @@ static unsigned int vids; module_param(vids, uint, 0444); MODULE_PARM_DESC(vids, "Bitmask of VIDs to translate (default: the DT's google,vid only); with mode=3, 0xff finds the one the controller uses"); +static bool allow_vid0; +module_param(allow_vid0, bool, 0444); +MODULE_PARM_DESC(allow_vid0, "Debug only: allow translating VID 0, which also carries UFS (storage) traffic"); + static bool shareable = true; module_param(shareable, bool, 0444); MODULE_PARM_DESC(shareable, "Mark the mapped sections shareable (the controller is cache coherent)"); @@ -301,6 +308,15 @@ static int gs201_sysmmu_probe(struct platform_device *pdev) if (mmu->vid > 7) return dev_err_probe(dev, -EINVAL, "bad VID %u\n", mmu->vid); mmu->vid_mask = (vids & 0xff) ?: BIT(mmu->vid); + /* + * On gs201 the UFS host controller's DMA also arrives on VID 0 (and + * so did the PCIe controller's, measured). Translating VID 0 with + * anything short of a full 1:1 map starves storage and wedges the + * phone, so never do it by default. + */ + if (mode && (mmu->vid_mask & BIT(0)) && !allow_vid0) + return dev_err_probe(dev, -EPERM, + "refusing to translate VID 0 (shared with UFS); allow_vid0=1 to override\n"); mmu->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(mmu->base)) From 4566d0f88b3bba09b2ae8e55ad6d6c41760e9b6d Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:29:51 -0400 Subject: [PATCH 28/75] wifi: brcmfmac: chip: size the BCM4389 SYSMEM from its RAM banks brcmfmac decodes the SYSMEM core's coreinfo register with the SOCRAM layout (bank count in bits 7:4) and sizes banks from index 0. On the BCM4389 the SYSMEM coreinfo holds the RAM bank count in bits 4:0 and the ROM bank count in bits 9:5 (bits 23:16 and 31:24 from core revision 12), and the ROM banks come first in the bank index space. That is how Broadcom's own driver sizes it (bcmdhd siutils.c si_sysmem_size(), sbsysmem.h), and what Google's Pixel 7 Pro logs at boot: si_sysmem_size: coreinfo:0x115 num_rom_banks:8 num_ram_baks:21 sysmem_banksize: bankidx:8 bankinfo:0xf00060f banksize:131072(0x20000) ... DHD: dongle ram size is set to 2752512(orig 2752512) at 0x200000 With the SOCRAM decoding, coreinfo 0x115 reads as one bank, and bank 0 is a ROM bank. The register dump of the failed load has the NVRAM length token (0xe8b4174b, the same as stock's) and 0x23a2d0, which is 0x240000 minus the 23856-byte NVRAM: brcmfmac sized the RAM at 256 KiB instead of 2688 KiB, and wrote the NVRAM and the random seed into the 1.7 MB firmware image it had just downloaded to 0x200000. The firmware crashed on start, and the shared RAM address read back as 0xffffffff: brcmf_pcie_download_fw_nvram: Invalid shared RAM address 0xffffffff Decode the BCM4389 the way Broadcom's driver does: count only the RAM banks and skip the ROM banks in front of them. Other SYSMEM chips (BCM4365/4366 family) keep the current decoding. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/chip.c | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index 75b0af85f7..e2a628dc32 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c @@ -162,6 +162,19 @@ struct sbconfig { #define SRCI_SRBSZ_SHIFT 0 #define SR_BSZ_BASE 14 +/* SYSMEM coreinfo as laid out on the BCM4389: RAM bank count in bits 4:0, + * ROM bank count in bits 9:5, and the ROM banks come first in the bank + * index space. Core revision 12 moved both counts up. + */ +#define SYSMEM_SRCI_SRNB_MASK 0x0000001f +#define SYSMEM_SRCI_SRNB_SHIFT 0 +#define SYSMEM_SRCI_ROMNB_MASK 0x000003e0 +#define SYSMEM_SRCI_ROMNB_SHIFT 5 +#define SYSMEM_SRCI_NEW_SRNB_MASK 0x00ff0000 +#define SYSMEM_SRCI_NEW_SRNB_SHIFT 16 +#define SYSMEM_SRCI_NEW_ROMNB_MASK 0xff000000 +#define SYSMEM_SRCI_NEW_ROMNB_SHIFT 24 + struct sbsocramregs { u32 coreinfo; u32 bwalloc; @@ -660,19 +673,45 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem) u32 coreinfo; u32 idx; u32 nb; + u32 nrb; u32 banksize; if (!brcmf_chip_iscoreup(&sysmem->pub)) brcmf_chip_resetcore(&sysmem->pub, 0, 0, 0); coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo)); - nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT; + + switch (sysmem->chip->pub.chip) { + case BRCM_CC_4389_CHIP_ID: + /* Count the RAM banks only, and skip the ROM banks in + * front of them. + */ + if (sysmem->pub.rev >= 12) { + nb = (coreinfo & SYSMEM_SRCI_NEW_SRNB_MASK) >> + SYSMEM_SRCI_NEW_SRNB_SHIFT; + nrb = (coreinfo & SYSMEM_SRCI_NEW_ROMNB_MASK) >> + SYSMEM_SRCI_NEW_ROMNB_SHIFT; + } else { + nb = (coreinfo & SYSMEM_SRCI_SRNB_MASK) >> + SYSMEM_SRCI_SRNB_SHIFT; + nrb = (coreinfo & SYSMEM_SRCI_ROMNB_MASK) >> + SYSMEM_SRCI_ROMNB_SHIFT; + } + break; + default: + nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT; + nrb = 0; + break; + } for (idx = 0; idx < nb; idx++) { - brcmf_chip_socram_banksize(sysmem, idx, &banksize); + brcmf_chip_socram_banksize(sysmem, nrb + idx, &banksize); memsize += banksize; } + brcmf_dbg(INFO, "SYSMEM rev %u coreinfo 0x%08x: %u ROM, %u RAM banks\n", + sysmem->pub.rev, coreinfo, nrb, nb); + return memsize; } From cb8e4f8f002cc7caea04a04219199edbc101ac53 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:32:09 -0400 Subject: [PATCH 29/75] wifi: brcmfmac: pcie: move the BAR1 window for RAM beyond the BAR brcmfmac reaches the chip's RAM through PCI BAR 2 (Broadcom's "BAR1") and assumes it maps the backplane from address 0. The BCM4389 has 2688 KiB of RAM at 0x200000, up to 0x49ffff, behind a 4 MiB BAR. The top of RAM, where the NVRAM, the random seed and the shared-area handshake word go, is beyond the BAR, and brcmfmac's accesses there land past the end of its ioremap(). The BAR maps the 4 MiB-aligned block of backplane space named by the BAR1 window register (PCI config 0x84). Broadcom's own driver moves it for every TCM access when RAM does not fit (bcmdhd dhd_pcie.c dhdpcie_bar1_window_switch_enab(), dhdpcie_bus_chkandshift_bpoffset(), pcicfg.h PCI_BAR1_WIN), and points it back at 0 before the download (dhdpcie_bus_download_state()). On the Pixel 7 Pro it logs the random seed TLV at 0x49a248. Do the same: when RAM ends beyond the BAR, route every TCM access through one helper that moves the window under a spinlock, split block copies at window edges (and into 4 KiB pieces, so the 1.7 MB firmware download does not hold the lock throughout), and reset the window before the download and after a chip reset. Chips whose RAM fits the BAR take the same path with the window left alone. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 199 +++++++++++++++--- 1 file changed, 171 insertions(+), 28 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 4093e7d519..2173182e1a 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -123,6 +123,10 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { /* backplane addres space accessed by BAR0 */ #define BRCMF_PCIE_BAR0_WINDOW 0x80 #define BRCMF_PCIE_BAR0_REG_SIZE 0x1000 +/* backplane address space accessed by BAR1 (PCI BAR 2, devinfo->tcm) */ +#define BRCMF_PCIE_BAR1_WINDOW 0x84 +/* largest TCM block copy done under one tcm_lock hold */ +#define BRCMF_PCIE_TCM_COPY_CHUNK 4096 #define BRCMF_PCIE_BAR0_WRAPPERBASE 0x70 #define BRCMF_PCIE_BAR0_WRAPBASE_DMP_OFFSET 0x1000 @@ -341,6 +345,10 @@ struct brcmf_pciedev_info { const struct brcmf_pcie_reginfo *reginfo; void __iomem *regs; void __iomem *tcm; + u32 tcm_size; + u32 tcm_win; + bool tcm_win_switch; + spinlock_t tcm_lock; u32 ram_base; u32 ram_size; struct brcmf_chip *ci; @@ -496,21 +504,86 @@ brcmf_pcie_write_reg32(struct brcmf_pciedev_info *devinfo, u32 reg_offset, } +/* + * devinfo->tcm maps tcm_size bytes of the chip's backplane, starting at the + * address in the BAR1 window register. The BCM4389 has 2.6 MiB of RAM at + * 0x200000, which crosses the 4 MiB BAR, so for chips whose RAM does not fit + * the BAR the window is moved to the tcm_size-aligned block that holds each + * access. Callers hold tcm_lock. + */ +static void __iomem * +brcmf_pcie_tcm_addr(struct brcmf_pciedev_info *devinfo, u32 addr) +{ + u32 win; + + lockdep_assert_held(&devinfo->tcm_lock); + + if (!devinfo->tcm_win_switch) + return devinfo->tcm + addr; + + win = addr & ~(devinfo->tcm_size - 1); + if (win != devinfo->tcm_win) { + pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_BAR1_WINDOW, + win); + devinfo->tcm_win = win; + } + + return devinfo->tcm + (addr - win); +} + +/* Bytes from addr up to the end of its window, at most chunk. */ +static u32 +brcmf_pcie_tcm_chunk(struct brcmf_pciedev_info *devinfo, u32 addr, u32 len) +{ + u32 chunk = min_t(u32, len, BRCMF_PCIE_TCM_COPY_CHUNK); + + if (devinfo->tcm_win_switch) + chunk = min_t(u32, chunk, + devinfo->tcm_size - (addr & (devinfo->tcm_size - 1))); + + return chunk; +} + +/* Point the BAR1 window back at backplane address 0, as after a reset. */ +static void brcmf_pcie_tcm_win_reset(struct brcmf_pciedev_info *devinfo) +{ + unsigned long flags; + + if (!devinfo->tcm_win_switch) + return; + + spin_lock_irqsave(&devinfo->tcm_lock, flags); + pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_BAR1_WINDOW, 0); + devinfo->tcm_win = 0; + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); +} + + static u8 brcmf_pcie_read_tcm8(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u8 val; + + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread8(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); - return (ioread8(address)); + return val; } static u16 brcmf_pcie_read_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u16 val; - return (ioread16(address)); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread16(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + + return val; } @@ -518,9 +591,11 @@ static void brcmf_pcie_write_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u16 value) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; - iowrite16(value, address); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + iowrite16(value, brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); } @@ -546,9 +621,14 @@ brcmf_pcie_write_idx(struct brcmf_pciedev_info *devinfo, u32 mem_offset, static u32 brcmf_pcie_read_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u32 val; - return (ioread32(address)); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread32(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + + return val; } @@ -556,18 +636,19 @@ static void brcmf_pcie_write_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u32 value) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; - iowrite32(value, address); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + iowrite32(value, brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); } static u32 brcmf_pcie_read_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset; - - return (ioread32(addr)); + return brcmf_pcie_read_tcm32(devinfo, + devinfo->ci->rambase + mem_offset); } @@ -575,17 +656,34 @@ static void brcmf_pcie_write_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u32 value) { - void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset; + brcmf_pcie_write_tcm32(devinfo, devinfo->ci->rambase + mem_offset, + value); +} - iowrite32(value, addr); + +static void +brcmf_pcie_copy_mem_todev(struct brcmf_pciedev_info *devinfo, u32 mem_offset, + const void *srcaddr, u32 len) +{ + unsigned long flags; + u32 chunk; + + while (len) { + chunk = brcmf_pcie_tcm_chunk(devinfo, mem_offset, len); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + memcpy_toio(brcmf_pcie_tcm_addr(devinfo, mem_offset), srcaddr, + chunk); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + mem_offset += chunk; + srcaddr += chunk; + len -= chunk; + } } static void -brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, - void *dstaddr, u32 len) +brcmf_pcie_copy_tcm_chunk(void __iomem *address, void *dstaddr, u32 len) { - void __iomem *address = devinfo->tcm + mem_offset; __le32 *dst32; __le16 *dst16; u8 *dst8; @@ -622,6 +720,27 @@ brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, } +static void +brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, + void *dstaddr, u32 len) +{ + unsigned long flags; + u32 chunk; + + while (len) { + chunk = brcmf_pcie_tcm_chunk(devinfo, mem_offset, len); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + brcmf_pcie_copy_tcm_chunk(brcmf_pcie_tcm_addr(devinfo, + mem_offset), + dstaddr, chunk); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + mem_offset += chunk; + dstaddr += chunk; + len -= chunk; + } +} + + #define READCC32(devinfo, reg) brcmf_pcie_read_reg32(devinfo, \ CHIPCREGOFFS(reg)) #define WRITECC32(devinfo, reg, value) brcmf_pcie_write_reg32(devinfo, \ @@ -711,6 +830,8 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) val); } } + + brcmf_pcie_tcm_win_reset(devinfo); } @@ -730,6 +851,8 @@ static void brcmf_pcie_attach(struct brcmf_pciedev_info *devinfo) static int brcmf_pcie_enter_download_state(struct brcmf_pciedev_info *devinfo) { + brcmf_pcie_tcm_win_reset(devinfo); + if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) { brcmf_pcie_select_core(devinfo, BCMA_CORE_ARM_CR4); brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX, @@ -1236,8 +1359,8 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) u16 max_submissionrings; u16 max_completionrings; - memcpy_fromio(&ringinfo, devinfo->tcm + devinfo->shared.ring_info_addr, - sizeof(ringinfo)); + brcmf_pcie_copy_dev_tomem(devinfo, devinfo->shared.ring_info_addr, + &ringinfo, sizeof(ringinfo)); if (devinfo->shared.version >= 6) { max_submissionrings = le16_to_cpu(ringinfo.max_submissionrings); max_flowrings = le16_to_cpu(ringinfo.max_flowrings); @@ -1310,8 +1433,9 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) ringinfo.d2h_r_idx_hostaddr.high_addr = cpu_to_le32(address >> 32); - memcpy_toio(devinfo->tcm + devinfo->shared.ring_info_addr, - &ringinfo, sizeof(ringinfo)); + brcmf_pcie_copy_mem_todev(devinfo, + devinfo->shared.ring_info_addr, + &ringinfo, sizeof(ringinfo)); brcmf_dbg(PCIE, "Using host memory indices\n"); } @@ -1689,7 +1813,8 @@ brcmf_pcie_provide_random_bytes(struct brcmf_pciedev_info *devinfo, u32 address) u8 randbuf[BRCMF_RANDOM_SEED_LENGTH]; get_random_bytes(randbuf, BRCMF_RANDOM_SEED_LENGTH); - memcpy_toio(devinfo->tcm + address, randbuf, BRCMF_RANDOM_SEED_LENGTH); + brcmf_pcie_copy_mem_todev(devinfo, address, randbuf, + BRCMF_RANDOM_SEED_LENGTH); } static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, @@ -1710,8 +1835,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, return err; brcmf_dbg(PCIE, "Download FW %s\n", devinfo->fw_name); - memcpy_toio(devinfo->tcm + devinfo->ci->rambase, - (void *)fw->data, fw->size); + brcmf_pcie_copy_mem_todev(devinfo, devinfo->ci->rambase, fw->data, + fw->size); resetintr = get_unaligned_le32(fw->data); release_firmware(fw); @@ -1725,7 +1850,7 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Download NVRAM %s\n", devinfo->nvram_name); address = devinfo->ci->rambase + devinfo->ci->ramsize - nvram_len; - memcpy_toio(devinfo->tcm + address, nvram, nvram_len); + brcmf_pcie_copy_mem_todev(devinfo, address, nvram, nvram_len); brcmf_fw_nvram_free(nvram); if (devinfo->fwseed) { @@ -1741,8 +1866,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Download random seed\n"); address -= sizeof(footer); - memcpy_toio(devinfo->tcm + address, &footer, - sizeof(footer)); + brcmf_pcie_copy_mem_todev(devinfo, address, &footer, + sizeof(footer)); address -= rand_len; brcmf_pcie_provide_random_bytes(devinfo, address); @@ -1816,6 +1941,7 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) devinfo->regs = ioremap(bar0_addr, BRCMF_PCIE_REG_MAP_SIZE); devinfo->tcm = ioremap(bar1_addr, bar1_size); + devinfo->tcm_size = bar1_size; if (!devinfo->regs || !devinfo->tcm) { brcmf_err(bus, "ioremap() failed (%p,%p)\n", devinfo->regs, @@ -2448,6 +2574,20 @@ static const struct brcmf_pcie_drvdata drvdata[] = { /* Forward declaration for pci_match_id() call */ static const struct pci_device_id brcmf_pcie_devid_table[]; +static void brcmf_pcie_tcm_win_setup(struct brcmf_pciedev_info *devinfo) +{ + u32 end = devinfo->ci->rambase + devinfo->ci->ramsize - 1; + + /* RAM that ends inside the BAR is reached without moving it. */ + if (end < devinfo->tcm_size || !is_power_of_2(devinfo->tcm_size)) + return; + + devinfo->tcm_win_switch = true; + brcmf_pcie_tcm_win_reset(devinfo); + brcmf_dbg(PCIE, "RAM 0x%x-0x%x does not fit the %u KiB BAR, moving its window\n", + devinfo->ci->rambase, end, devinfo->tcm_size / 1024); +} + static int brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -2474,6 +2614,7 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) return ret; devinfo->pdev = pdev; + spin_lock_init(&devinfo->tcm_lock); pcie_bus_dev = NULL; devinfo->ci = brcmf_chip_attach(devinfo, pdev->device, &brcmf_pcie_buscore_ops); @@ -2483,6 +2624,8 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto fail; } + brcmf_pcie_tcm_win_setup(devinfo); + core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_PCIE2); if (core->rev >= 64) devinfo->reginfo = &brcmf_reginfo_64; From 476106a011671ead14867e6dbd4a0051652b47a1 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:33:06 -0400 Subject: [PATCH 30/75] wifi: brcmfmac: pcie: request the BCM4389 power domains after reset The BCM4389 splits its backplane into save/restore power domains: PCIe, ARM/backplane, MAC aux and MAC main. Unless the host requests them, the chip's PMU may keep the ARM/backplane and MAC domains off, and a chip reset drops the host's requests. Backplane accesses to a domain that is off fault and read back as 0xffffffff, which also hides behind a warm chip that some earlier driver had left powered. Google's driver (bcmdhd) treats the 4378/4387/4389 family as multi- backplane chips (siutils.h MULTIBP_CAP()). It requests all four domains through the powerctl register (bits 11:8, status in 19:16) of the PCIe core, at BAR0 + 0x2000 + 0x1e8, before it resets the chip (dhd_pcie.c dhd_bus_pcie_pwr_req_reload_war(), siutils.c si_srpwr_request() and si_srpwr_domain_all_mask()), and on PCIe core revision 68 and later also asserts the ARM/backplane domain in the DAR copy of the register, because "ARM fails to boot" from cold without it (dhd_pcie.c dhd_bus_pcie_pwr_req_wl_domain(), pcie_core.h DAR_PCIE_PWR_CTRL()). The Pixel 7 Pro's BCM4389 has PCIe core revision 72. For the ARM CA7 it also sets the BAR coherent-access bits in PCI config 0x88 (dhd_pcie.c "CA7 requires coherent bits on", pcicfg.h PCIE_BARCOHERENTACCEN_MASK). For the BCM4389, request all four domains (and the DAR one) once the BARs are mapped, before brcmfmac first touches a core, and again before and after the watchdog reset; and set the coherent-access bits. The requests stay on while the driver is bound, which costs idle power but keeps every backplane access safe; releasing them once the firmware runs is left for later. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 105 +++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 2173182e1a..1c59610366 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -155,6 +156,23 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_0 0xA20 #define BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_1 0xA24 +/* Save/restore power domain requests, in the PCIe core's own registers, + * reached through BAR0 + BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET. + */ +#define BRCMF_PCIE_PCIE2REG_POWERCTL 0x1E8 +#define BRCMF_PCIE_64_PCIE2REG_DAR_POWERCTL 0xA0C +#define BRCMF_PCIE_SRPWR_DMN0_PCIE BIT(0) +#define BRCMF_PCIE_SRPWR_DMN1_ARMBP BIT(1) +#define BRCMF_PCIE_SRPWR_DMN2_MACAUX BIT(2) +#define BRCMF_PCIE_SRPWR_DMN3_MACMAIN BIT(3) +#define BRCMF_PCIE_SRPWR_DMN_ALL (BRCMF_PCIE_SRPWR_DMN0_PCIE | \ + BRCMF_PCIE_SRPWR_DMN1_ARMBP | \ + BRCMF_PCIE_SRPWR_DMN2_MACAUX | \ + BRCMF_PCIE_SRPWR_DMN3_MACMAIN) +#define BRCMF_PCIE_SRPWR_REQON_SHIFT 8 +#define BRCMF_PCIE_SRPWR_STATUS_SHIFT 16 +#define BRCMF_PCIE_SRPWR_TIMEOUT_US 15000 + #define BRCMF_PCIE2_INTA 0x01 #define BRCMF_PCIE2_INTB 0x02 @@ -282,6 +300,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_CFGREG_MSI_DATA 0x64 #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL 0xBC #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL2 0xDC +#define BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL 0x88 +#define BRCMF_PCIE_SSCTRL_BAR_COHERENT 0x300 #define BRCMF_PCIE_CFGREG_RBAR_CTRL 0x228 #define BRCMF_PCIE_CFGREG_PML1_SUB_CTRL1 0x248 #define BRCMF_PCIE_CFGREG_REG_BAR2_CONFIG 0x4E0 @@ -774,6 +794,71 @@ brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid) } +/* + * Chips with several backplane power domains (the BCM4389 here) power the + * ARM/backplane and MAC domains down unless the host asks for them, and + * a chip reset drops the host's requests. Backplane accesses to a domain + * that is off fault, and read back as 0xffffffff. + */ +static bool brcmf_pcie_has_srpwr(struct brcmf_pciedev_info *devinfo) +{ + return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID; +} + +static void brcmf_pcie_srpwr_request(struct brcmf_pciedev_info *devinfo) +{ + u32 reg = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + BRCMF_PCIE_PCIE2REG_POWERCTL; + u32 req = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_REQON_SHIFT; + u32 up = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_STATUS_SHIFT; + u32 dar = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + BRCMF_PCIE_64_PCIE2REG_DAR_POWERCTL; + u32 val; + + if (!brcmf_pcie_has_srpwr(devinfo)) + return; + + val = brcmf_pcie_read_reg32(devinfo, reg); + if (val == 0xffffffff) { + pci_err(devinfo->pdev, "power control reads 0xffffffff\n"); + return; + } + if ((val & req) != req) + brcmf_pcie_write_reg32(devinfo, reg, val | req); + + if (readl_poll_timeout(devinfo->regs + reg, val, (val & up) == up, 10, + BRCMF_PCIE_SRPWR_TIMEOUT_US)) + pci_warn(devinfo->pdev, "power domains not up, powerctl 0x%08x\n", + val); + else + brcmf_dbg(PCIE, "power domains up, powerctl 0x%08x\n", val); + + /* The ARM also needs the ARM/backplane domain requested through the + * DAR copy of the register, or it fails to boot from cold. + */ + val = brcmf_pcie_read_reg32(devinfo, dar); + req = BRCMF_PCIE_SRPWR_DMN1_ARMBP << BRCMF_PCIE_SRPWR_REQON_SHIFT; + if ((val & req) != req) + brcmf_pcie_write_reg32(devinfo, dar, val | req); +} + +/* The ARM CA7 needs host accesses through the BARs to be coherent. */ +static void brcmf_pcie_set_bar_coherent(struct brcmf_pciedev_info *devinfo) +{ + u32 val; + + if (!brcmf_pcie_has_srpwr(devinfo)) + return; + + pci_read_config_dword(devinfo->pdev, + BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, &val); + if ((val & BRCMF_PCIE_SSCTRL_BAR_COHERENT) != + BRCMF_PCIE_SSCTRL_BAR_COHERENT) + pci_write_config_dword(devinfo->pdev, + BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, + val | BRCMF_PCIE_SSCTRL_BAR_COHERENT); +} + static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) { struct brcmf_core *core; @@ -805,7 +890,8 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL, val); - /* Watchdog reset */ + /* Watchdog reset, with all power domains up as it starts */ + brcmf_pcie_srpwr_request(devinfo); brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); WRITECC32(devinfo, watchdog, 4); msleep(100); @@ -815,6 +901,10 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL, lsc); + /* The reset dropped the power domain requests */ + brcmf_pcie_srpwr_request(devinfo); + brcmf_pcie_set_bar_coherent(devinfo); + core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_PCIE2); if (core->rev <= 13) { for (i = 0; i < ARRAY_SIZE(cfg_offset); i++) { @@ -2001,7 +2091,18 @@ static void brcmf_pcie_buscore_write32(void *ctx, u32 addr, u32 value) static int brcmf_pcie_buscoreprep(void *ctx) { - return brcmf_pcie_get_resource(ctx); + struct brcmf_pciedev_info *devinfo = ctx; + int err; + + err = brcmf_pcie_get_resource(devinfo); + if (err) + return err; + + /* before the first access to a core outside the always-on domain */ + brcmf_pcie_srpwr_request(devinfo); + brcmf_pcie_set_bar_coherent(devinfo); + + return 0; } From fcfab987c12e592311ae22d9bed75818fdf5300e Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:33:49 -0400 Subject: [PATCH 31/75] wifi: brcmfmac: msgbuf: put sequence numbers in H2D control messages Broadcom's driver puts a sequence number in the common header of every message it writes to the H2D control submit and rxpost submit rings: the byte brcmfmac calls rsvd0 is cmn_msg_hdr_t.epoch, set to the ring's seqnum modulo 253, with seqnum starting at 254 and counting up per message (bcmdhd bcmmsgbuf.h H2D_EPOCH_MODULO/H2D_EPOCH_INIT_VAL, dhd_msgbuf.c dhd_prot_h2d_sync_init() and every ioctl, buffer post and flow ring create/delete request). Tx flow rings carry none. The BCM4389 firmware Google ships (20.101.90) checks these numbers: it has an "h2d livelock error" trap for messages whose number does not arrive, and brcmfmac leaves the byte at 0. Number the messages the same way, after a message is final so a cancelled slot does not use a number. While here, clear the ioctl and flow ring create/delete slots before filling them, as the buffer posts already do, so no stale bytes from an earlier message are left in the fields brcmfmac does not set. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/msgbuf.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index 069ba70166..d9fa303bdd 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -73,6 +73,13 @@ #define BRCMF_MAX_TXSTATUS_WAIT_RETRIES 10 +/* Sequence number ("epoch") in the common header of each message on the + * H2D control and rxpost submission rings, modulo 253; the first message + * carries 1. + */ +#define BRCMF_MSGBUF_H2D_EPOCH_MODULO 253 +#define BRCMF_MSGBUF_H2D_EPOCH_INIT (BRCMF_MSGBUF_H2D_EPOCH_MODULO + 1) + struct msgbuf_common_hdr { u8 msgtype; u8 ifidx; @@ -258,6 +265,7 @@ struct brcmf_msgbuf { u16 data_seq_no; u16 ioctl_seq_no; u32 reqid; + u32 h2d_seqnum[BRCMF_NROF_H2D_COMMON_MSGRINGS]; wait_queue_head_t ioctl_resp_wait; bool ctl_completed; @@ -292,6 +300,15 @@ struct brcmf_msgbuf_pktids { static void brcmf_msgbuf_rxbuf_ioctlresp_post(struct brcmf_msgbuf *msgbuf); +/* Called with the ring's write slot reserved, once the message is final. */ +static void brcmf_msgbuf_set_epoch(struct brcmf_msgbuf *msgbuf, u32 ringid, + struct msgbuf_common_hdr *msg) +{ + msg->rsvd0 = msgbuf->h2d_seqnum[ringid] % BRCMF_MSGBUF_H2D_EPOCH_MODULO; + msgbuf->h2d_seqnum[ringid]++; +} + + static struct brcmf_msgbuf_pktids * brcmf_msgbuf_init_pktids(u32 nr_array_entries, enum dma_data_direction direction) @@ -451,6 +468,7 @@ static int brcmf_msgbuf_tx_ioctl(struct brcmf_pub *drvr, int ifidx, msgbuf->reqid++; request = (struct msgbuf_ioctl_req_hdr *)ret_ptr; + memset(request, 0, sizeof(*request)); request->msg.msgtype = MSGBUF_TYPE_IOCTLPTR_REQ; request->msg.ifidx = (u8)ifidx; request->msg.flags = 0; @@ -463,6 +481,8 @@ static int brcmf_msgbuf_tx_ioctl(struct brcmf_pub *drvr, int ifidx, request->input_buf_len = cpu_to_le16(buf_len); request->req_buf_addr.high_addr = cpu_to_le32(msgbuf->ioctbuf_phys_hi); request->req_buf_addr.low_addr = cpu_to_le32(msgbuf->ioctbuf_phys_lo); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &request->msg); if (buf) memcpy(msgbuf->ioctbuf, buf, buf_len); else @@ -642,6 +662,7 @@ brcmf_msgbuf_flowring_create_worker(struct brcmf_msgbuf *msgbuf, } create = (struct msgbuf_tx_flowring_create_req *)ret_ptr; + memset(create, 0, sizeof(*create)); create->msg.msgtype = MSGBUF_TYPE_FLOW_RING_CREATE; create->msg.ifidx = work->ifidx; create->msg.request_id = 0; @@ -655,6 +676,8 @@ brcmf_msgbuf_flowring_create_worker(struct brcmf_msgbuf *msgbuf, create->flow_ring_addr.low_addr = cpu_to_le32(address & 0xffffffff); create->max_items = cpu_to_le16(BRCMF_H2D_TXFLOWRING_MAX_ITEM); create->len_item = cpu_to_le16(BRCMF_H2D_TXFLOWRING_ITEMSIZE); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &create->msg); brcmf_dbg(MSGBUF, "Send Flow Create Req flow ID %d for peer %pM prio %d ifindex %d\n", flowid, work->da, create->tid, work->ifidx); @@ -996,6 +1019,8 @@ static u32 brcmf_msgbuf_rxbuf_data_post(struct brcmf_msgbuf *msgbuf, u32 count) cpu_to_le32(address >> 32); rx_bufpost->data_buf_addr.low_addr = cpu_to_le32(address & 0xffffffff); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_RXPOST_SUBMIT, + &rx_bufpost->msg); ret_ptr += brcmf_commonring_len_item(commonring); } @@ -1096,6 +1121,8 @@ brcmf_msgbuf_rxbuf_ctrl_post(struct brcmf_msgbuf *msgbuf, bool event_buf, cpu_to_le32(address >> 32); rx_bufpost->host_buf_addr.low_addr = cpu_to_le32(address & 0xffffffff); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &rx_bufpost->msg); ret_ptr += brcmf_commonring_len_item(commonring); } @@ -1478,6 +1505,7 @@ void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid) } delete = (struct msgbuf_tx_flowring_delete_req *)ret_ptr; + memset(delete, 0, sizeof(*delete)); ifidx = brcmf_flowring_ifidx_get(msgbuf->flow, flowid); @@ -1488,6 +1516,8 @@ void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid) delete->flow_ring_id = cpu_to_le16(flowid + BRCMF_H2D_MSGRING_FLOWRING_IDSTART); delete->reason = 0; + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &delete->msg); brcmf_dbg(MSGBUF, "Send Flow Delete Req flow ID %d, ifindex %d\n", flowid, ifidx); @@ -1617,6 +1647,10 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) drvr->proto->pd = msgbuf; init_waitqueue_head(&msgbuf->ioctl_resp_wait); + msgbuf->h2d_seqnum[BRCMF_H2D_MSGRING_CONTROL_SUBMIT] = + BRCMF_MSGBUF_H2D_EPOCH_INIT; + msgbuf->h2d_seqnum[BRCMF_H2D_MSGRING_RXPOST_SUBMIT] = + BRCMF_MSGBUF_H2D_EPOCH_INIT; msgbuf->commonrings = (struct brcmf_commonring **)if_msgbuf->commonrings; From 6db9e17bbbb86bc926443f2f33c8c5f0cfb3f011 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:34:25 -0400 Subject: [PATCH 32/75] wifi: brcmfmac: msgbuf: never use packet ID 0 brcmfmac hands out packet IDs (the request_id of tx and rx buffer posts) from a ring of array slots, and slot 0 comes round as soon as the ring wraps. Broadcom's driver reserves ID 0 as "invalid" and never gives it to a packet (bcmdhd dhd_msgbuf.c DHD_PKTID_INVALID, and its locker array, whose slot 0 is never allocated). Firmware written against that driver may treat a buffer posted with ID 0 as no buffer. Skip slot 0 when allocating, and reject ID 0 in completions. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index d9fa303bdd..22d43ec039 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -354,11 +354,12 @@ brcmf_msgbuf_alloc_pktid(struct device *dev, *idx = pktids->last_allocated_idx; - count = 0; + /* Packet ID 0 means "no packet" to the firmware: never hand it out. */ + count = 1; do { (*idx)++; if (*idx == pktids->array_size) - *idx = 0; + *idx = 1; if (array[*idx].allocated.counter == 0) if (atomic_cmpxchg(&array[*idx].allocated, 0, 1) == 0) break; @@ -388,7 +389,7 @@ brcmf_msgbuf_get_pktid(struct device *dev, struct brcmf_msgbuf_pktids *pktids, struct brcmf_msgbuf_pktid *pktid; struct sk_buff *skb; - if (idx >= pktids->array_size) { + if (idx == 0 || idx >= pktids->array_size) { brcmf_err("Invalid packet id %d (max %d)\n", idx, pktids->array_size); return NULL; From c39b07720b9949b6fe6ab3d8183b2abefe896e13 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 00:34:41 -0400 Subject: [PATCH 33/75] wifi: brcmfmac: don't cancel the bus reset work before it exists drvr->bus_reset is initialised in brcmf_bus_started(), after the firmware is up. When the firmware fails to start, the PCIe setup path unbinds the device, and brcmf_pcie_remove() calls brcmf_bus_cancel_reset_work(), which runs cancel_work_sync() on a work item that was never initialised and trips the check in __flush_work(): WARNING: kernel/workqueue.c:4409 at __flush_work+0x27c/0x2a4 Call trace: __flush_work+0x27c/0x2a4 (P) __cancel_work_sync+0xbc/0x1dc cancel_work_sync+0x14/0x24 brcmf_bus_cancel_reset_work+0x38/0x50 [brcmfmac] brcmf_pcie_remove+0x6c/0x168 [brcmfmac] pci_device_remove+0x48/0xdc device_release_driver_internal+0x16c/0x27c device_release_driver+0x18/0x24 brcmf_pcie_setup+0x434/0xa4c [brcmfmac] brcmf_bus_schedule_reset() already treats a NULL work function as "not armable yet". Use the same test before cancelling: there is nothing to cancel when the work was never set up. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c index d2ae679856..ee38264ef9 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c @@ -1186,7 +1186,8 @@ void brcmf_bus_cancel_reset_work(struct brcmf_bus *bus_if) { mutex_lock(&bus_if->bus_reset_lock); bus_if->removing = true; - if (bus_if->drvr) + /* bus_reset is only initialised once the bus has started */ + if (bus_if->drvr && bus_if->drvr->bus_reset.func) cancel_work_sync(&bus_if->drvr->bus_reset); mutex_unlock(&bus_if->bus_reset_lock); } From 68ff652fc0a6ccbc9b1ecc69294b1f4748652008 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:26:47 -0400 Subject: [PATCH 34/75] wifi: brcmfmac: pcie: use a 64-bit DMA mask brcmfmac never sets a DMA mask, so the PCI default of 32 bits applies, although every ring and buffer descriptor it hands the dongle carries a 64-bit host address (msgbuf_buf_addr high_addr/low_addr). Google's driver for the same chips sets a 64-bit mask (bcmdhd dhd_pcie_linux.c dhdpcie_pci_probe(), DMA_BIT_MASK(64)). With a restricted DMA pool (reserved-memory "restricted-dma-pool") every coherent allocation is carved from the pool, and dma-direct rejects the pool if it is not reachable under the coherent mask. On the Pixel 7 Pro the 16 MiB pool is placed at 0xaff000000, so all allocations failed: the DMA index buffer silently ("Using TCM indices"), then the first common ring: brcmf_pcie_init_ringbuffers: Allocating ring buffers failed Ask for 64 bits and fall back to 32. Hosts that cannot address all of it describe that with dma-ranges on the bridge, which the DMA core applies on top of the mask. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../wireless/broadcom/brcm80211/brcmfmac/pcie.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 1c59610366..c9431c81e9 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -2017,6 +2018,20 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) pci_set_master(pdev); + /* The dongle takes 64-bit host addresses in every ring and buffer + * descriptor. Without this the PCI default 32-bit mask applies, and + * every allocation from a restricted DMA pool placed above 4 GiB + * fails. + */ + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (err) { + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (err) { + brcmf_err(bus, "no usable DMA mask: %d\n", err); + return err; + } + } + /* Bar-0 mapped address */ bar0_addr = pci_resource_start(pdev, 0); /* Bar-1 mapped address */ From 0efc1f43fbce642b60bfecbaeac7c2eb15416187 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:26:54 -0400 Subject: [PATCH 35/75] wifi: brcmfmac: pcie: say why the ring indices fall back to TCM When the firmware offers DMA'd ring indices (BRCMF_PCIE_SHARED_DMA_INDEX) but the index buffer cannot be allocated, brcmfmac quietly uses the indices in device memory instead, which hides a DMA setup problem and makes every ring update a PCIe read. Log the fallback as an error, and log the shared-area flags at PCIe debug level so the firmware's capabilities can be read from a debug log. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index c9431c81e9..b4f7d90382 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1473,8 +1473,10 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) devinfo->idxbuf = dma_alloc_coherent(&devinfo->pdev->dev, bufsz, &devinfo->idxbuf_dmahandle, GFP_KERNEL); - if (!devinfo->idxbuf) + if (!devinfo->idxbuf) { + brcmf_err(bus, "no DMA memory for ring indices, using TCM\n"); devinfo->dma_idx_sz = 0; + } } if (devinfo->dma_idx_sz == 0) { @@ -1848,6 +1850,7 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, shared->flags = brcmf_pcie_read_tcm32(devinfo, sharedram_addr); shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK); + brcmf_dbg(PCIE, "shared flags 0x%08x\n", shared->flags); brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version); if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) || (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) { From c54878a2278c784b0272d8d2bc4d4b7dc33c74bb Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:35:25 -0400 Subject: [PATCH 36/75] wifi: brcmfmac: pcie: ring the core doorbells when the firmware has no DAR For PCIe core revision 64 and later brcmfmac rings the H2D doorbells through the DAR ("direct access register") copies at 0xa20/0xa24. Broadcom's own driver uses those only when the firmware offers them (PCIE_SHARED_DAR, bit 31 of the shared-area flags) and the host enables them; otherwise it rings the core's own mailbox registers at 0x140 (DB0) and 0x144 (DB1, host ready), whatever the core revision (bcmdhd dhd_pcie.c dhd_bus_db0_addr_get(), dhd_bus_db1_addr_get(), dhd_pcie.h DAR_ACTIVE(), pcie_core.h PCIH2D_MailBox/PCIH2D_DB1). The Pixel 7 Pro's BCM4389 (PCIe core rev 72) firmware does not offer DAR (shared flags 0x70050107; stock logs "FW supports DAR ? N"). With the DAR doorbells it never saw a ring update or the host-ready ring: the rxpost ring stayed unread and the first ioctl timed out. For the BCM4389 without the DAR flag, switch to the core mailbox registers once the shared flags are known. Other rev >= 64 chips keep the DAR doorbells they are known to work with. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index b4f7d90382..7436f67f1d 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -245,6 +245,7 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000 #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000 #define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000 +#define BRCMF_PCIE_SHARED_DAR 0x80000000 #define BRCMF_PCIE_FLAGS_HTOD_SPLIT 0x4000 #define BRCMF_PCIE_FLAGS_DTOH_SPLIT 0x8000 @@ -480,6 +481,19 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_default = { .int_fn0 = BRCMF_PCIE_MB_INT_FN0, }; +/* Core rev >= 64 with the doorbells in the PCIe core's own registers, for + * firmware that does not offer the DAR doorbells (BRCMF_PCIE_SHARED_DAR). + */ +static const struct brcmf_pcie_reginfo brcmf_reginfo_64_nodar = { + .intmask = BRCMF_PCIE_64_PCIE2REG_INTMASK, + .mailboxint = BRCMF_PCIE_64_PCIE2REG_MAILBOXINT, + .mailboxmask = BRCMF_PCIE_64_PCIE2REG_MAILBOXMASK, + .h2d_mailbox_0 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_0, + .h2d_mailbox_1 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_1, + .int_d2h_db = BRCMF_PCIE_64_MB_INT_D2H_DB, + .int_fn0 = 0, +}; + static const struct brcmf_pcie_reginfo brcmf_reginfo_64 = { .intmask = BRCMF_PCIE_64_PCIE2REG_INTMASK, .mailboxint = BRCMF_PCIE_64_PCIE2REG_MAILBOXINT, @@ -1851,6 +1865,19 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, shared->flags = brcmf_pcie_read_tcm32(devinfo, sharedram_addr); shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK); brcmf_dbg(PCIE, "shared flags 0x%08x\n", shared->flags); + + /* Broadcom's driver rings the DAR doorbells only when the firmware + * offers them, and the core's own H2D mailbox registers otherwise. + * The BCM4389 firmware does not, and ignores the DAR doorbells. + */ + if (devinfo->reginfo == &brcmf_reginfo_64 && + devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + !(shared->flags & BRCMF_PCIE_SHARED_DAR)) { + devinfo->reginfo = &brcmf_reginfo_64_nodar; + brcmf_dbg(PCIE, "no DAR: doorbells at 0x%x/0x%x\n", + devinfo->reginfo->h2d_mailbox_0, + devinfo->reginfo->h2d_mailbox_1); + } brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version); if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) || (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) { From f25dc0adcc00f706cc1af77b085a84342e75466f Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:35:56 -0400 Subject: [PATCH 37/75] wifi: brcmfmac: pcie: write the host capabilities for the BCM4389 From shared area revision 6 on, Broadcom's driver writes a host capability word into the shared area (host_cap, offset 84) before it uses the rings: the IPC revision in use, "host ready will be rung" when the firmware supports it, the device-wake mode, and "don't trap on an unsupported request" (bcmdhd dhd_msgbuf.c dhd_set_host_cap(), bcmpcie.h pciedev_shared_t and HOSTCAP_*). brcmfmac writes nothing there. It does write a "ring update" buffer address and length at offsets 64 and 68, a field of older shared areas. In the revision 6/7 layout those offsets are host_scb_addr, and the high half of the buffer address lands in host_scb_size (offset 72); on the Pixel 7 Pro, with DMA memory above 4 GiB, that makes the size non-zero. For the BCM4389 (revision 7 firmware), write host_cap the way bcmdhd does with device wake off (version | ENABLE_HOSTRDY when offered | DS_NO_OOB_DW | UR_FW_NO_TRAP), and leave the legacy ring update fields alone. Other chips are unchanged. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 7436f67f1d..8235c50a1c 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -261,6 +261,12 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET 56 #define BRCMF_SHARED_DMA_RINGUPD_LEN_OFFSET 64 #define BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET 68 +/* shared area revision >= 6: host capabilities, read by the firmware */ +#define BRCMF_SHARED_HOST_CAP_OFFSET 84 + +#define BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY 0x00000400 +#define BRCMF_HOSTCAP_DS_NO_OOB_DW 0x00001000 +#define BRCMF_HOSTCAP_UR_FW_NO_TRAP 0x00800000 #define BRCMF_RING_H2D_RING_COUNT_OFFSET 0 #define BRCMF_RING_D2H_RING_COUNT_OFFSET 1 @@ -1632,6 +1638,29 @@ brcmf_pcie_release_scratchbuffers(struct brcmf_pciedev_info *devinfo) } } +/* + * Tell the firmware what the host does, as Broadcom's driver does for shared + * area revision 6 and later (bcmdhd dhd_msgbuf.c dhd_set_host_cap()): the + * IPC revision in use, that a host-ready doorbell will come, that there is + * no device-wake (no deep sleep), and not to trap on an unsupported + * request. + */ +static void brcmf_pcie_set_host_cap(struct brcmf_pciedev_info *devinfo) +{ + u32 cap = devinfo->shared.version; + + if (devinfo->shared.version < 6) + return; + + if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) + cap |= BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY; + cap |= BRCMF_HOSTCAP_DS_NO_OOB_DW | BRCMF_HOSTCAP_UR_FW_NO_TRAP; + + brcmf_pcie_write_tcm32(devinfo, devinfo->shared.tcm_base_address + + BRCMF_SHARED_HOST_CAP_OFFSET, cap); + brcmf_dbg(PCIE, "host capabilities 0x%08x\n", cap); +} + static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) { struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); @@ -1655,6 +1684,11 @@ static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET; brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN); + if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) { + brcmf_pcie_set_host_cap(devinfo); + return 0; + } + devinfo->shared.ringupd = dma_alloc_coherent(&devinfo->pdev->dev, BRCMF_DMA_D2H_RINGUPD_BUF_LEN, From ff267f46c7f0ba14e6ec287cb502f9a22efca044 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:36:16 -0400 Subject: [PATCH 38/75] wifi: brcmfmac: msgbuf: keep rx packet IDs for the control buffers Rx data buffers, ioctl response buffers and event buffers all take their packet IDs from one pool of 1024. The firmware sets how many data buffers the host may post (max_rxbufpost); the BCM4389's says 1535 (Google's driver posts 2040 with a larger pool). brcmfmac then fills the whole rx ID pool with data buffers before it posts the ioctl response and event buffers, and those fail: brcmf_msgbuf_rxbuf_ctrl_post: No PKTID available !! after which no ioctl can complete. Make the rx pool 2048 IDs, and cap the data buffers so the eight ioctl response and eight event buffers (and the unused ID 0) always fit. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index 22d43ec039..fe1edc8ff8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -49,7 +49,7 @@ #define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14 #define NR_TX_PKTIDS 2048 -#define NR_RX_PKTIDS 1024 +#define NR_RX_PKTIDS 2048 #define BRCMF_IOCTL_REQ_PKTID 0xFFFE @@ -1664,11 +1664,18 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) goto fail; msgbuf->rx_dataoffset = if_msgbuf->rx_dataoffset; - msgbuf->max_rxbufpost = if_msgbuf->max_rxbufpost; msgbuf->max_ioctlrespbuf = BRCMF_MSGBUF_MAX_IOCTLRESPBUF_POST; msgbuf->max_eventbuf = BRCMF_MSGBUF_MAX_EVENTBUF_POST; + /* Data, ioctl response and event buffers share the rx packet IDs + * (ID 0 is never used): leave enough for the control buffers. + */ + msgbuf->max_rxbufpost = min_t(u32, if_msgbuf->max_rxbufpost, + NR_RX_PKTIDS - 1 - + msgbuf->max_ioctlrespbuf - + msgbuf->max_eventbuf); + msgbuf->tx_pktids = brcmf_msgbuf_init_pktids(NR_TX_PKTIDS, DMA_TO_DEVICE); if (!msgbuf->tx_pktids) From b6c0700375e31beae1a800e691228f3fbb219d5b Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 01:46:53 -0400 Subject: [PATCH 39/75] wifi: brcmfmac: pcie: ring host ready early, and only once, on the BCM4389 Broadcom's driver rings the host-ready doorbell (DB1) right after the common rings are set up and before it posts any buffer (bcmdhd dhd_msgbuf.c dhd_prot_init(), hostrdy_after_init set in dhd_pcie.c dhdpcie_bus_attach()). brcmfmac rings it only in preinit, after the rx and control buffers are already posted. For the BCM4389, which is told in host_cap that host ready will come, ring it once the interrupt is set up as well. With the PCIe debug level on, log the host-ready doorbell. Broadcom's driver rings it only once, and brcmfmac's preinit must not ring it a second time: the 20.101.90 firmware dies on that, with its console showing THREADX TRAP INFO: Thread: main_thread ... TRAP 4(326dc8): pc 27489a, lr 27488d, sp 327020 ... dfsr 80f, dfar 0 and the firmware's symbol map puts pc/lr in _hnd_die, with pciedev_handle_hostready_intr+0x75 (0x2315f1) and pciedev_dpc on the stack: a deliberate stop in the host-ready handler, 20 ms after the second doorbell. So skip the preinit host ready for the BCM4389, and write the value Broadcom's driver writes (0x12345678, dhd_bus_hostready()). Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 8235c50a1c..bb45ab2523 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1156,9 +1156,16 @@ static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo) static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo) { - if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) + if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) { + brcmf_dbg(PCIE, "host ready on 0x%x\n", + devinfo->reginfo->h2d_mailbox_1); + /* bcmdhd dhd_bus_hostready() writes this value */ brcmf_pcie_write_reg32(devinfo, - devinfo->reginfo->h2d_mailbox_1, 1); + devinfo->reginfo->h2d_mailbox_1, + devinfo->pdev->device == + BRCM_PCIE_4389_DEVICE_ID ? + 0x12345678 : 1); + } } static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg) @@ -1731,7 +1738,12 @@ static int brcmf_pcie_preinit(struct device *dev) brcmf_dbg(PCIE, "Enter\n"); brcmf_pcie_intr_enable(buspub->devinfo); - brcmf_pcie_hostready(buspub->devinfo); + /* The BCM4389 was told host ready right after its rings were set + * up; its firmware traps on a second one (_hnd_die from + * pciedev_handle_hostready_intr), so ring it only once. + */ + if (buspub->devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID) + brcmf_pcie_hostready(buspub->devinfo); return 0; } @@ -2506,6 +2518,13 @@ static void brcmf_pcie_setup(struct device *dev, int ret, if (ret) goto fail; + /* Broadcom's driver rings host ready as soon as the common rings + * are set up, before it posts any buffer (bcmdhd dhd_prot_init(), + * hostrdy_after_init), and the BCM4389 was told so in host_cap. + */ + if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) + brcmf_pcie_hostready(devinfo); + /* hook the commonrings in the bus structure. */ for (i = 0; i < BRCMF_NROF_COMMON_MSGRINGS; i++) bus->msgbuf->commonrings[i] = From d34798b1df4ea3f3efaf2fa26353f9f44908c7c6 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 02:50:26 -0400 Subject: [PATCH 40/75] wifi: brcmfmac: pcie: look at the rings again after an INTx on the BCM4389 With legacy INTx and ring indices that the dongle DMAs into host memory, the doorbell interrupt can arrive before the index update it announces has landed. Broadcom's driver handles that by running its interrupt work again shortly after (dhd_pcie.c dhd_bus_handle_intx_ahead_dma_indices()); brcmfmac reads the indices once, may see nothing new, and then waits for a doorbell that does not come. For the BCM4389 with DMA'd indices, process the rings a second time about a millisecond later. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index bb45ab2523..568083b02f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1198,6 +1198,18 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) brcmf_proto_msgbuf_rx_trigger( &devinfo->pdev->dev); + /* With INTx and DMA'd indices the interrupt can + * overtake the index update it announces; Broadcom's + * driver looks again later + * (dhd_bus_handle_intx_ahead_dma_indices()). + */ + if (devinfo->dma_idx_sz && + devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + devinfo->state == BRCMFMAC_PCIE_STATE_UP) { + usleep_range(500, 1000); + brcmf_proto_msgbuf_rx_trigger( + &devinfo->pdev->dev); + } } } brcmf_pcie_bus_console_read(devinfo, false); From 4d0a4893d65a91d0d21ddcc6195914382a7b330e Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 09:36:18 -0400 Subject: [PATCH 41/75] wifi: brcmfmac: pcie: reset the BCM4389 with an FLR brcmfmac resets the chip with the ChipCommon watchdog, at probe and at remove. On the Pixel 7 Pro that is enough for a chip fresh from WL_REG_ON, but after "modprobe -r brcmfmac; modprobe brcmfmac" (the chip stays powered) the next download fails: brcmf_pcie_download_fw_nvram: FW failed to initialize Broadcom's driver never uses the watchdog on this chip: it resets the function with an FLR, both when it attaches and when it is removed (bcmdhd dhd_pcie.c dhdpcie_dongle_reset() -> dhd_bus_perform_flr(), which sets Initiate FLR, waits 70 ms, clears it, polls the subsystem reset status in config 0x88 bit 13 and restores the config space); the stock boot log shows that sequence ("Perform FLR", "FLR Succedeed"). Do the same for the BCM4389, keeping the power-domain requests around it and falling back to the watchdog if the function cannot do FLR. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 568083b02f..1b7a25b734 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -880,6 +880,48 @@ static void brcmf_pcie_set_bar_coherent(struct brcmf_pciedev_info *devinfo) val | BRCMF_PCIE_SSCTRL_BAR_COHERENT); } +/* + * Function level reset as Broadcom's driver does it for the BCM4389 + * (bcmdhd dhd_pcie.c dhd_bus_perform_flr()): set Initiate FLR, wait 70 ms, + * clear it again, then wait for the subsystem reset status (config 0x88 + * bit 13) to clear, and restore the config space. + */ +#define BRCMF_PCIE_SSCTRL_SSRESET_STATUS BIT(13) + +static int brcmf_pcie_flr(struct brcmf_pciedev_info *devinfo) +{ + struct pci_dev *pdev = devinfo->pdev; + u32 cap, val; + int i; + + pcie_capability_read_dword(pdev, PCI_EXP_DEVCAP, &cap); + if (!(cap & PCI_EXP_DEVCAP_FLR)) + return -EOPNOTSUPP; + + pci_save_state(pdev); + pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); + msleep(70); + pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_BCR_FLR); + + for (i = 0; i < 200; i++) { + pci_read_config_dword(pdev, BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, + &val); + if (!(val & BRCMF_PCIE_SSCTRL_SSRESET_STATUS)) + break; + udelay(40); + } + pci_restore_state(pdev); + + if (val & BRCMF_PCIE_SSCTRL_SSRESET_STATUS) { + pci_err(pdev, "FLR did not complete, config 0x88 = 0x%08x\n", + val); + return -ETIMEDOUT; + } + brcmf_dbg(PCIE, "FLR done\n"); + return 0; +} + static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) { struct brcmf_core *core; @@ -911,11 +953,18 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL, val); - /* Watchdog reset, with all power domains up as it starts */ + /* Watchdog reset, with all power domains up as it starts. The + * BCM4389 is reset the way Broadcom's driver resets it, with an + * FLR: after a chipcommon watchdog reset its ARM does not boot a + * second firmware download. + */ brcmf_pcie_srpwr_request(devinfo); - brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); - WRITECC32(devinfo, watchdog, 4); - msleep(100); + if (devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID || + brcmf_pcie_flr(devinfo)) { + brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); + WRITECC32(devinfo, watchdog, 4); + msleep(100); + } /* Restore ASPM */ brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); From 138b3d4d8522aefd534d9c55348c439492319908 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 10:05:08 -0400 Subject: [PATCH 42/75] wifi: brcmfmac: use the versioned join parameters on the BCM4389 Firmware with a WLC interface version of 14.2, 14.4, 16.1+ or 17+ takes the "join" iovar in its versioned layout, wl_extjoin_params_v1_t: a version/pad word in front, and association parameters that start with version and flags and carry a bssid_cnt before chanspec_num. Broadcom's driver picks that layout by this WLC version test (bcmdhd wl_cfg80211.c, MIN_JOINEXT_V1_* and wl_fillup_assoc_params_v1()); the version fields are left 0. The Pixel 7 Pro's BCM4389 firmware (20.101.90) reports WLC 14.4 and rejects brcmfmac's unversioned join, and the WLC_SET_SSID fallback after it, so association never starts: brcmf_cfg80211_connect: BRCMF_C_SET_SSID failed (-52) Add a JOIN_V1 feature, set from "wlc_ver" by the same test, for the BCM4389 only, and send the versioned join when it is set. Log the firmware's own error code if the join fails. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 81 +++++++++++++++++++ .../broadcom/brcm80211/brcmfmac/feature.c | 12 +++ .../broadcom/brcm80211/brcmfmac/feature.h | 3 +- .../broadcom/brcm80211/brcmfmac/fwil_types.h | 28 +++++++ 4 files changed, 123 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 872c48806d..a6c7896428 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -2377,6 +2377,76 @@ static void brcmf_set_join_pref(struct brcmf_if *ifp, bphy_err(drvr, "Set join_pref error (%d)\n", err); } +static u32 ssid_len_of(struct cfg80211_connect_params *sme) +{ + return min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN); +} + +/* + * The "join" iovar with versioned parameters (wl_extjoin_params_v1_t), as + * Broadcom's driver fills it (bcmdhd wl_cfg80211.c + * wl_fillup_assoc_params_v1()). @chanspec 0 means no channel. + */ +static s32 brcmf_join_v1(struct brcmf_if *ifp, + struct cfg80211_connect_params *sme, u32 ssid_len, + u16 chanspec) +{ + struct brcmf_pub *drvr = ifp->drvr; + struct brcmf_ext_join_params_v1_le *jp; + size_t len; + s32 err; + + len = offsetof(struct brcmf_ext_join_params_v1_le, assoc_le) + + offsetof(struct brcmf_assoc_params_v1_le, chanspec_list); + if (chanspec) + len += sizeof(u16); + + /* room for the one chanspec */ + jp = kzalloc(sizeof(*jp) + sizeof(__le16), GFP_KERNEL); + if (!jp) + return -ENOMEM; + + jp->ssid_le.SSID_len = cpu_to_le32(ssid_len); + memcpy(jp->ssid_le.SSID, sme->ssid, ssid_len); + + jp->scan_le.scan_type = -1; + jp->scan_le.home_time = cpu_to_le32(-1); + if (chanspec) { + jp->scan_le.active_time = + cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); + jp->scan_le.passive_time = + cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); + jp->scan_le.nprobes = + cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / + BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); + jp->assoc_le.chanspec_num = cpu_to_le32(1); + jp->assoc_le.chanspec_list[0] = cpu_to_le16(chanspec); + } else { + jp->scan_le.active_time = cpu_to_le32(-1); + jp->scan_le.passive_time = cpu_to_le32(-1); + jp->scan_le.nprobes = cpu_to_le32(-1); + } + + if (sme->bssid) + memcpy(jp->assoc_le.bssid, sme->bssid, ETH_ALEN); + else + eth_broadcast_addr(jp->assoc_le.bssid); + + /* get the firmware's own error code for the log */ + ifp->fwil_fwerr = true; + err = brcmf_fil_bsscfg_data_set(ifp, "join", jp, len); + ifp->fwil_fwerr = false; + kfree(jp); + + if (err) + bphy_err(drvr, "join (v1, chanspec 0x%04x, %zu bytes) failed: firmware error %d\n", + chanspec, len, err); + else + brcmf_dbg(CONN, "join (v1, chanspec 0x%04x) sent\n", chanspec); + + return err ? -EBADE : 0; +} + static s32 brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, struct cfg80211_connect_params *sme) @@ -2531,6 +2601,15 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, if (err) goto done; } + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_JOIN_V1)) { + brcmf_set_join_pref(ifp, &sme->bss_select); + err = brcmf_join_v1(ifp, sme, ssid_len_of(sme), + cfg->channel ? chanspec : 0); + if (!err) + goto done; + goto set_ssid; + } + /* Join with specific BSSID and cached SSID * If SSID is zero join based on BSSID only */ @@ -2594,6 +2673,8 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, /* This is it. join command worked, we are done */ goto done; +set_ssid: + ssid_len = ssid_len_of(sme); /* join command failed, fallback to set ssid */ memset(&join_params, 0, sizeof(join_params)); join_params_size = sizeof(join_params.ssid_le); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index 488364ef8f..9d1bdc7c32 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -156,6 +156,18 @@ static void brcmf_feat_wlc_version_overrides(struct brcmf_pub *drv) brcmf_dbg(INFO, "WLC version: %d.%d\n", major, minor); + /* + * Versioned "join" parameters (wl_extjoin_params_v1_t), by the + * same WLC version test as Broadcom's driver (bcmdhd + * wl_cfg80211.c, MIN_JOINEXT_V1_*): 14.2 or 14.4, 16.1 and later + * on 16, or 17 and later. Only the BCM4389 for now; its 20.101.90 + * firmware reports 14.4 and rejects the unversioned layout. + */ + if (drv->bus_if->chip == BRCM_CC_4389_CHIP_ID && + ((major == 14 && (minor == 2 || minor == 4)) || + (major == 16 && minor >= 1) || major >= 17)) + feat_flags |= BIT(BRCMF_FEAT_JOIN_V1); + for (i = 0; i < ARRAY_SIZE(brcmf_feat_wlcfeat_map); i++) { e = &brcmf_feat_wlcfeat_map[i]; if (major > e->min_ver_major || diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h index 31f8695ca4..014cf6f477 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h @@ -59,7 +59,8 @@ BRCMF_FEAT_DEF(SCAN_V2) \ BRCMF_FEAT_DEF(PMKID_V2) \ BRCMF_FEAT_DEF(PMKID_V3) \ - BRCMF_FEAT_DEF(SAE_EXT) + BRCMF_FEAT_DEF(SAE_EXT) \ + BRCMF_FEAT_DEF(JOIN_V1) /* * Quirks: diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index e74a23e118..11a86d292b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -533,6 +533,34 @@ struct brcmf_ext_join_params_le { struct brcmf_assoc_params_le assoc_le; }; +/** + * struct brcmf_assoc_params_v1_le - versioned association parameters. + * + * @version: structure version (left 0, as Broadcom's driver does). + * @flags: ASSOC_HINT_BSSID_PRESENT etc. + * @bssid: target BSSID, or broadcast. + * @bssid_cnt: 0: use @chanspec_num and the single @bssid. + * @chanspec_num: 0: all channels, else count of @chanspec_list entries. + * @chanspec_list: chanspecs. + */ +struct brcmf_assoc_params_v1_le { + __le16 version; + __le16 flags; + u8 bssid[ETH_ALEN]; + __le16 bssid_cnt; + __le32 chanspec_num; + __le16 chanspec_list[]; +}; + +/* extended join params, versioned (wl_extjoin_params_v1_t) */ +struct brcmf_ext_join_params_v1_le { + __le16 version; + __le16 pad; + struct brcmf_ssid_le ssid_le; + struct brcmf_join_scan_params_le scan_le; + struct brcmf_assoc_params_v1_le assoc_le; +}; + struct brcmf_wsec_key { u32 index; /* key index */ u32 len; /* key length */ From 123b5adfa9a71d9098aa3ac2f01acf37b150b2e8 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 10:14:28 -0400 Subject: [PATCH 43/75] wifi: brcmfmac: msgbuf: build the 802.3/LLC TX header on the host for the BCM4389 Firmware that advertises the "host_sfhllc" capability (the BCM4389's 20.101.90 does) expects the host to turn each TX frame into 802.3 + LLC/SNAP itself: Broadcom's driver then posts the whole converted frame, keeps the original Ethernet header in the post's txhdr, and sets BCMPCIE_TXPOST_FLAGS_HOST_SFH_LLC (0x10) (bcmdhd dhd_msgbuf.c dhd_prot_txdata(), dhd_common.c dhd_ether_to_8023_hdr(), and the reverse on TX completion). brcmfmac posts the payload only, behind the Ethernet header. Add a HOST_SFHLLC feature from the "cap" string, BCM4389 only (it can be turned off with feature_disable), and when it is set convert TX frames that way (RFC 1042, or bridge-tunnel for the 802.1H types) and convert them back before completion, so the 802.1X pending count still sees ETH_P_PAE. At the msgbuf debug level, log EAPOL frames in both directions. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/feature.c | 5 + .../broadcom/brcm80211/brcmfmac/feature.h | 3 +- .../broadcom/brcm80211/brcmfmac/msgbuf.c | 93 ++++++++++++++++++- 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index 9d1bdc7c32..bff2f5c62e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -45,6 +45,7 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_SAE, "sae " }, { BRCMF_FEAT_FWAUTH, "idauth" }, { BRCMF_FEAT_SAE_EXT, "sae_ext" }, + { BRCMF_FEAT_HOST_SFHLLC, "host_sfhllc" }, }; #ifdef DEBUG @@ -358,6 +359,10 @@ void brcmf_feat_attach(struct brcmf_pub *drvr) brcmf_fwvid_feat_attach(ifp); + /* Host-built 802.3 + LLC/SNAP TX headers: only the BCM4389 for now */ + if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID) + drvr->feat_flags &= ~BIT(BRCMF_FEAT_HOST_SFHLLC); + if (drvr->settings->feature_disable) { brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", ifp->drvr->feat_flags, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h index 014cf6f477..8ebd231169 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h @@ -60,7 +60,8 @@ BRCMF_FEAT_DEF(PMKID_V2) \ BRCMF_FEAT_DEF(PMKID_V3) \ BRCMF_FEAT_DEF(SAE_EXT) \ - BRCMF_FEAT_DEF(JOIN_V1) + BRCMF_FEAT_DEF(JOIN_V1) \ + BRCMF_FEAT_DEF(HOST_SFHLLC) /* * Quirks: diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index fe1edc8ff8..caa68ffe70 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ #include "proto.h" #include "msgbuf.h" #include "commonring.h" +#include "feature.h" #include "flowring.h" #include "bus.h" #include "tracepoint.h" @@ -62,6 +64,9 @@ #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 0x02 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07 +/* TX post: the data buffer starts with a host-built 802.3 + LLC/SNAP header */ +#define BRCMF_MSGBUF_TXPOST_FLAGS_HOST_SFH_LLC 0x10 +#define BRCMF_MSGBUF_SFH_LLC_LEN 8 #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5 #define BRCMF_MSGBUF_TX_FLUSH_CNT1 32 @@ -742,6 +747,60 @@ static u32 brcmf_msgbuf_flowring_create(struct brcmf_msgbuf *msgbuf, int ifidx, } +/* + * Host short-form header + LLC (firmware capability "host_sfhllc"): the + * host turns the Ethernet frame into 802.3 + LLC/SNAP (RFC 1042, or + * bridge-tunnel for the 802.1H types) before posting it, as Broadcom's + * driver does (bcmdhd dhd_common.c dhd_ether_to_8023_hdr(), dhd_msgbuf.c + * BCMPCIE_TXPOST_FLAGS_HOST_SFH_LLC), and turns it back on completion. + */ +static int brcmf_msgbuf_sfh_llc_insert(struct sk_buff *skb) +{ + u8 *p; + u16 type; + + if (skb->len < ETH_HLEN) + return -EINVAL; + if (skb_headroom(skb) < BRCMF_MSGBUF_SFH_LLC_LEN && + pskb_expand_head(skb, BRCMF_MSGBUF_SFH_LLC_LEN, 0, GFP_ATOMIC)) + return -ENOMEM; + + type = get_unaligned_be16(skb->data + 2 * ETH_ALEN); + p = skb_push(skb, BRCMF_MSGBUF_SFH_LLC_LEN); + memmove(p, p + BRCMF_MSGBUF_SFH_LLC_LEN, 2 * ETH_ALEN); + put_unaligned_be16(skb->len - ETH_HLEN, p + 2 * ETH_ALEN); + p += ETH_HLEN; + p[0] = 0xaa; + p[1] = 0xaa; + p[2] = 0x03; + p[3] = 0x00; + p[4] = 0x00; + p[5] = (type == 0x80f3 || type == 0x8137) ? 0xf8 : 0x00; + put_unaligned_be16(type, p + 6); + return 0; +} + +static void brcmf_msgbuf_sfh_llc_remove(struct sk_buff *skb) +{ + u8 *p = skb->data; + u16 type; + + if (skb->len < ETH_HLEN + BRCMF_MSGBUF_SFH_LLC_LEN || + get_unaligned_be16(p + 2 * ETH_ALEN) >= ETH_P_802_3_MIN || + p[ETH_HLEN] != 0xaa || p[ETH_HLEN + 1] != 0xaa) + return; + + type = get_unaligned_be16(p + ETH_HLEN + 6); + memmove(p + BRCMF_MSGBUF_SFH_LLC_LEN, p, 2 * ETH_ALEN); + p = skb_pull(skb, BRCMF_MSGBUF_SFH_LLC_LEN); + put_unaligned_be16(type, p + 2 * ETH_ALEN); +} + +static bool brcmf_msgbuf_sfh_llc(struct brcmf_msgbuf *msgbuf) +{ + return msgbuf->drvr->feat_flags & BIT(BRCMF_FEAT_HOST_SFHLLC); +} + static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) { struct brcmf_flowring *flow = msgbuf->flow; @@ -754,6 +813,8 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) u32 pktid; struct msgbuf_tx_msghdr *tx_msghdr; u64 address; + u8 ethhdr[ETH_HLEN]; + bool sfh; commonring = msgbuf->flowrings[flowid]; if (!brcmf_commonring_write_available(commonring)) @@ -770,9 +831,15 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) break; } skb_orphan(skb); + memcpy(ethhdr, skb->data, ETH_HLEN); + sfh = brcmf_msgbuf_sfh_llc(msgbuf) && + !brcmf_msgbuf_sfh_llc_insert(skb); if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, - msgbuf->tx_pktids, skb, ETH_HLEN, + msgbuf->tx_pktids, skb, + sfh ? 0 : ETH_HLEN, &physaddr, &pktid)) { + if (sfh) + brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); bphy_err(drvr, "No PKTID available !!\n"); break; @@ -781,6 +848,8 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) if (!ret_ptr) { brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, msgbuf->tx_pktids, pktid); + if (sfh) + brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); break; } @@ -792,11 +861,19 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) tx_msghdr->msg.request_id = cpu_to_le32(pktid + 1); tx_msghdr->msg.ifidx = brcmf_flowring_ifidx_get(flow, flowid); tx_msghdr->flags = BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3; + if (sfh) + tx_msghdr->flags |= + BRCMF_MSGBUF_TXPOST_FLAGS_HOST_SFH_LLC; tx_msghdr->flags |= (skb->priority & 0x07) << BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT; tx_msghdr->seg_cnt = 1; - memcpy(tx_msghdr->txhdr, skb->data, ETH_HLEN); - tx_msghdr->data_len = cpu_to_le16(skb->len - ETH_HLEN); + memcpy(tx_msghdr->txhdr, ethhdr, ETH_HLEN); + tx_msghdr->data_len = cpu_to_le16(sfh ? skb->len : + skb->len - ETH_HLEN); + if (get_unaligned_be16(ethhdr + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "TX EAPOL pktid %u flow %u len %u%s\n", + pktid, flowid, skb->len, + sfh ? " (802.3+LLC)" : ""); address = (u64)physaddr; tx_msghdr->data_buf_addr.high_addr = cpu_to_le32(address >> 32); tx_msghdr->data_buf_addr.low_addr = @@ -937,6 +1014,12 @@ brcmf_msgbuf_process_txstatus(struct brcmf_msgbuf *msgbuf, void *buf) msgbuf->tx_pktids, idx); if (!skb) return; + if (brcmf_msgbuf_sfh_llc(msgbuf)) + brcmf_msgbuf_sfh_llc_remove(skb); + if (skb->len >= ETH_HLEN && + get_unaligned_be16(skb->data + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "TX EAPOL done pktid %u status %u\n", idx, + le16_to_cpu(tx_status->compl_hdr.status)); if (!brcmf_msgbuf_get_flowid(msgbuf, flow_ring_id, &flowid)) { brcmf_txfinalize(brcmf_get_ifp(msgbuf->drvr, tx_status->msg.ifidx), @@ -1254,6 +1337,10 @@ brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf) return; } + if (skb->len >= ETH_HLEN && + get_unaligned_be16(skb->data + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "RX EAPOL pktid %u len %u flags 0x%x\n", idx, + skb->len, flags); skb->protocol = eth_type_trans(skb, ifp->ndev); brcmf_netif_rx(ifp, skb); } From f9d7eebf575a180d5fa2923ea695b5c5b8f23470 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 10:15:32 -0400 Subject: [PATCH 44/75] wifi: brcmfmac: pcie: poll the D2H rings after interrupts on the BCM4389 On the Pixel 7 Pro (INTx, DMA'd ring indices) control completions go unprocessed until some later interrupt: ioctls time out every 2 s ("Timeout on response for query command") while others succeed, P2P device creation misses its interface event, and association stalls. Broadcom's driver does not rely on the interrupt alone with INTx and DMA'd indices: it runs its interrupt work again shortly after (dhd_pcie.c dhd_bus_handle_intx_ahead_dma_indices()). For the BCM4389, after each interrupt and each doorbell, process the D2H rings every 10 ms for the next 500 ms, from a delayed work, with a mutex so the poll and the interrupt thread never process a ring at the same time. At the PCIe debug level, log when the poll finds a doorbell pending that no interrupt delivered. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/pcie.c | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 1b7a25b734..666ca1b36b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -373,6 +373,10 @@ struct brcmf_pciedev_info { const struct brcmf_pcie_reginfo *reginfo; void __iomem *regs; void __iomem *tcm; + struct delayed_work poll_work; + struct mutex rx_lock; /* one D2H ring processor at a time */ + unsigned int poll_left; + bool poll_enabled; u32 tcm_size; u32 tcm_win; bool tcm_win_switch; @@ -1230,6 +1234,61 @@ static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg) } +/* Process the D2H rings; the interrupt thread and the poll both get here. */ +static void brcmf_pcie_rx_process(struct brcmf_pciedev_info *devinfo) +{ + mutex_lock(&devinfo->rx_lock); + if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) + brcmf_proto_msgbuf_rx_trigger(&devinfo->pdev->dev); + mutex_unlock(&devinfo->rx_lock); +} + +/* + * BCM4389 on INTx: completions were seen to go unprocessed until a later + * interrupt (ioctl timeouts, a control ring that looks stuck). Broadcom's + * driver re-runs its interrupt work after INTx with DMA'd indices + * (dhd_bus_handle_intx_ahead_dma_indices()). Do the same, more often: after + * each interrupt and each doorbell, look at the D2H rings every 10 ms for + * the next 500 ms. + */ +#define BRCMF_PCIE_POLL_MS 10 +#define BRCMF_PCIE_POLL_COUNT 50 + +static void brcmf_pcie_kick_poll(struct brcmf_pciedev_info *devinfo) +{ + if (!devinfo->poll_enabled || + devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return; + WRITE_ONCE(devinfo->poll_left, BRCMF_PCIE_POLL_COUNT); + mod_delayed_work(system_wq, &devinfo->poll_work, + msecs_to_jiffies(BRCMF_PCIE_POLL_MS)); +} + +static void brcmf_pcie_poll_worker(struct work_struct *work) +{ + struct brcmf_pciedev_info *devinfo = + container_of(to_delayed_work(work), struct brcmf_pciedev_info, + poll_work); + u32 status; + unsigned int left; + + if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return; + + status = brcmf_pcie_read_reg32(devinfo, devinfo->reginfo->mailboxint); + if (status & devinfo->reginfo->int_d2h_db) + brcmf_dbg(PCIE, "poll: mailboxint 0x%08x pending without an interrupt\n", + status); + brcmf_pcie_rx_process(devinfo); + + left = READ_ONCE(devinfo->poll_left); + if (left) { + WRITE_ONCE(devinfo->poll_left, left - 1); + queue_delayed_work(system_wq, &devinfo->poll_work, + msecs_to_jiffies(BRCMF_PCIE_POLL_MS)); + } +} + static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) { struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)arg; @@ -1244,9 +1303,7 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) if (status & devinfo->reginfo->int_fn0) brcmf_pcie_handle_mb_data(devinfo); if (status & devinfo->reginfo->int_d2h_db) { - if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) - brcmf_proto_msgbuf_rx_trigger( - &devinfo->pdev->dev); + brcmf_pcie_rx_process(devinfo); /* With INTx and DMA'd indices the interrupt can * overtake the index update it announces; Broadcom's * driver looks again later @@ -1256,14 +1313,14 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && devinfo->state == BRCMFMAC_PCIE_STATE_UP) { usleep_range(500, 1000); - brcmf_proto_msgbuf_rx_trigger( - &devinfo->pdev->dev); + brcmf_pcie_rx_process(devinfo); } } } brcmf_pcie_bus_console_read(devinfo, false); if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) brcmf_pcie_intr_enable(devinfo); + brcmf_pcie_kick_poll(devinfo); devinfo->in_irq = false; return IRQ_HANDLED; } @@ -1368,6 +1425,7 @@ static int brcmf_pcie_ring_mb_ring_bell(void *ctx) brcmf_dbg(PCIE, "RING !\n"); /* Any arbitrary value will do, lets use 1 */ brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->h2d_mailbox_0, 1); + brcmf_pcie_kick_poll(devinfo); return 0; } @@ -2578,6 +2636,8 @@ static void brcmf_pcie_setup(struct device *dev, int ret, ret = brcmf_pcie_request_irq(devinfo); if (ret) goto fail; + devinfo->poll_enabled = devinfo->pdev->device == + BRCM_PCIE_4389_DEVICE_ID; /* Broadcom's driver rings host ready as soon as the common rings * are set up, before it posts any buffer (bcmdhd dhd_prot_init(), @@ -2875,6 +2935,8 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) devinfo->pdev = pdev; spin_lock_init(&devinfo->tcm_lock); + mutex_init(&devinfo->rx_lock); + INIT_DELAYED_WORK(&devinfo->poll_work, brcmf_pcie_poll_worker); pcie_bus_dev = NULL; devinfo->ci = brcmf_chip_attach(devinfo, pdev->device, &brcmf_pcie_buscore_ops); @@ -3008,6 +3070,7 @@ brcmf_pcie_remove(struct pci_dev *pdev) brcmf_pcie_fwcon_timer(devinfo, false); devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + cancel_delayed_work_sync(&devinfo->poll_work); if (devinfo->ci) brcmf_pcie_intr_disable(devinfo); From 09eb64d943b553b9b8aeeae94d5f423d21d8db41 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 11:26:37 -0400 Subject: [PATCH 45/75] wifi: brcmutil: decode the 6 GHz band in d11ac chanspecs Firmware for 6 GHz capable chips such as the BCM4389 reports 6 GHz chanspecs (band field 0x4000, e.g. 0x5001 for 6 GHz channel 1, 20 MHz) in its chanspec list. brcmu_d11ac_decchspec() only knew the 2.4 and 5 GHz bands and hit WARN_ONCE("Invalid chanspec") during wiphy setup. Add BRCMU_CHAN_BAND_6G and decode band 0x4000 (historically named 3G in this header) as 6 GHz. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c | 3 +++ drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c index 1e2b1e487e..ab33f7a13b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c @@ -228,6 +228,9 @@ static void brcmu_d11ac_decchspec(struct brcmu_chan *ch) case BRCMU_CHSPEC_D11AC_BND_2G: ch->band = BRCMU_CHAN_BAND_2G; break; + case BRCMU_CHSPEC_D11AC_BND_6G: + ch->band = BRCMU_CHAN_BAND_6G; + break; default: WARN_ONCE(1, "Invalid chanspec 0x%04x\n", ch->chspec); break; diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h index f634402385..c8ef37342b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h +++ b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h @@ -82,11 +82,13 @@ #define BRCMU_CHSPEC_D11AC_BND_SHIFT 14 #define BRCMU_CHSPEC_D11AC_BND_2G 0x0000 #define BRCMU_CHSPEC_D11AC_BND_3G 0x4000 +#define BRCMU_CHSPEC_D11AC_BND_6G BRCMU_CHSPEC_D11AC_BND_3G #define BRCMU_CHSPEC_D11AC_BND_4G 0x8000 #define BRCMU_CHSPEC_D11AC_BND_5G 0xc000 #define BRCMU_CHAN_BAND_2G 0 #define BRCMU_CHAN_BAND_5G 1 +#define BRCMU_CHAN_BAND_6G 2 enum brcmu_chan_bw { BRCMU_CHAN_BW_20, From b4bda13c90b5befba2d52c35bcb26097adc50abc Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 11:26:37 -0400 Subject: [PATCH 46/75] wifi: brcmfmac: skip 6 GHz chanspecs when building the channel list brcmf_construct_chaninfo() only fills the 2.4 and 5 GHz bands. Now that 6 GHz chanspecs decode as such, skip them quietly instead of logging "Invalid channel Spec." for each one, until 6 GHz support is added. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index a6c7896428..2b172f7e35 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -7149,6 +7149,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, band = wiphy->bands[NL80211_BAND_2GHZ]; } else if (ch.band == BRCMU_CHAN_BAND_5G) { band = wiphy->bands[NL80211_BAND_5GHZ]; + } else if (ch.band == BRCMU_CHAN_BAND_6G) { + /* 6 GHz is not supported yet */ + brcmf_dbg(INFO, "skipping 6 GHz chanspec 0x%x\n", + ch.chspec); + continue; } else { bphy_err(drvr, "Invalid channel Spec. 0x%x.\n", ch.chspec); From c4c0e412c676fc8346d429418a3e91776058ec63 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 12:54:27 -0400 Subject: [PATCH 47/75] wifi: brcmfmac: pcie: exchange mailbox data as control messages From shared version 6, Broadcom's driver sends and receives mailbox data (D3 inform, D3 ack, deep sleep requests) as control-ring messages (MSGBUF_TYPE_H2D_MAILBOX_DATA and D2H_MAILBOX_DATA), unless the firmware sets PCIE_SHARED_USE_MAILBOX. The BCM4389 firmware reports shared flags 0x70050107: version 7, no USE_MAILBOX. It ignores the D3 inform written to the TCM mailbox, so every system suspend timed out waiting for the D3 ack and failed with -EIO, and its D2H mailbox messages were logged as unsupported. Send and receive mailbox data as control messages for such firmware. There is no D0 inform on resume; the host-ready doorbell resumes the device. The D3 ack then arrives while the control completion ring is being processed. Waking the suspend path at that point lets it set STATE_DOWN before the ring's read pointer is written back, and that write is then refused. Publish the ack at the end of RX processing, under rx_lock, which serialises the interrupt thread and the poll worker. While at it, fail the suspend at once when the D3 inform can't be sent rather than waiting for an ack that can't come, and stop the poll worker once the device is in D3. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/bus.h | 9 ++ .../broadcom/brcm80211/brcmfmac/msgbuf.c | 56 ++++++++ .../broadcom/brcm80211/brcmfmac/msgbuf.h | 1 + .../broadcom/brcm80211/brcmfmac/pcie.c | 121 ++++++++++++++---- 4 files changed, 164 insertions(+), 23 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index 9371c14899..f41d87dd55 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -87,6 +87,8 @@ struct brcmf_bus_dcmd { * @get_memdump: obtain device memory dump in provided buffer. * @get_blob: obtain a firmware blob. * @remove: initiate unbind of the device. + * @d2h_mb_data: mailbox data the device sent as a control message + * (optional). * * This structure provides an abstract interface towards the * bus specific driver. For control messages to common driver @@ -108,6 +110,7 @@ struct brcmf_bus_ops { void (*debugfs_create)(struct device *dev); int (*reset)(struct device *dev); void (*remove)(struct device *dev); + void (*d2h_mb_data)(struct device *dev, u32 data); }; @@ -282,6 +285,12 @@ int brcmf_bus_reset(struct brcmf_bus *bus) return bus->ops->reset(bus->dev); } +static inline void brcmf_bus_d2h_mb_data(struct brcmf_bus *bus, u32 data) +{ + if (bus->ops->d2h_mb_data) + bus->ops->d2h_mb_data(bus->dev, data); +} + static inline void brcmf_bus_remove(struct brcmf_bus *bus) { if (!bus->ops->remove) { diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index caa68ffe70..b632911357 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -49,6 +49,8 @@ #define MSGBUF_TYPE_RX_CMPLT 0x12 #define MSGBUF_TYPE_LPBK_DMAXFER 0x13 #define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14 +#define MSGBUF_TYPE_H2D_MAILBOX_DATA 0x23 +#define MSGBUF_TYPE_D2H_MAILBOX_DATA 0x24 #define NR_TX_PKTIDS 2048 #define NR_RX_PKTIDS 2048 @@ -138,6 +140,23 @@ struct msgbuf_completion_hdr { __le16 flow_ring_id; }; +/* + * Mailbox data as control messages, for firmware that doesn't use the + * shared-memory mailbox (Broadcom's h2d_mailbox_data and d2h_mailbox_data). + */ +struct msgbuf_h2d_mailbox_data { + struct msgbuf_common_hdr msg; + __le32 mb_data; + __le32 rsvd[7]; +}; + +struct msgbuf_d2h_mailbox_data { + struct msgbuf_common_hdr msg; + struct msgbuf_completion_hdr compl_hdr; + __le32 mb_data; + __le32 rsvd; +}; + /* Data struct for the MSGBUF_TYPE_GEN_STATUS */ struct msgbuf_gen_status { struct msgbuf_common_hdr msg; @@ -1438,6 +1457,7 @@ brcmf_msgbuf_process_flow_ring_delete_response(struct brcmf_msgbuf *msgbuf, static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) { struct brcmf_pub *drvr = msgbuf->drvr; + struct msgbuf_d2h_mailbox_data *mb_data; struct msgbuf_common_hdr *msg; msg = (struct msgbuf_common_hdr *)buf; @@ -1477,6 +1497,11 @@ static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) brcmf_dbg(MSGBUF, "MSGBUF_TYPE_RX_CMPLT\n"); brcmf_msgbuf_process_rx_complete(msgbuf, buf); break; + case MSGBUF_TYPE_D2H_MAILBOX_DATA: + brcmf_dbg(MSGBUF, "MSGBUF_TYPE_D2H_MAILBOX_DATA\n"); + mb_data = (struct msgbuf_d2h_mailbox_data *)buf; + brcmf_bus_d2h_mb_data(drvr->bus_if, le32_to_cpu(mb_data->mb_data)); + break; default: bphy_err(drvr, "Unsupported msgtype %d\n", msg->msgtype); break; @@ -1516,6 +1541,37 @@ static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, } +/* Mailbox data for the device, sent as a control message. */ +int brcmf_proto_msgbuf_h2d_mb_data(struct device *dev, u32 data) +{ + struct brcmf_bus *bus_if = dev_get_drvdata(dev); + struct brcmf_pub *drvr = bus_if->drvr; + struct msgbuf_h2d_mailbox_data *mb_data; + struct brcmf_commonring *commonring; + struct brcmf_msgbuf *msgbuf; + int err; + + if (!drvr || !drvr->proto || !drvr->proto->pd) + return -EAGAIN; + msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + + commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; + brcmf_commonring_lock(commonring); + mb_data = brcmf_commonring_reserve_for_write(commonring); + if (!mb_data) { + brcmf_commonring_unlock(commonring); + return -ENOMEM; + } + memset(mb_data, 0, sizeof(*mb_data)); + mb_data->msg.msgtype = MSGBUF_TYPE_H2D_MAILBOX_DATA; + mb_data->mb_data = cpu_to_le32(data); + err = brcmf_commonring_write_complete(commonring); + brcmf_commonring_unlock(commonring); + + return err; +} + + int brcmf_proto_msgbuf_rx_trigger(struct device *dev) { struct brcmf_bus *bus_if = dev_get_drvdata(dev); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h index 6a849f4a94..76dd36f6c8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h @@ -29,6 +29,7 @@ struct msgbuf_buf_addr { }; int brcmf_proto_msgbuf_rx_trigger(struct device *dev); +int brcmf_proto_msgbuf_h2d_mb_data(struct device *dev, u32 data); void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid); int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr); void brcmf_proto_msgbuf_detach(struct brcmf_pub *drvr); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 666ca1b36b..2906d1d927 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -244,6 +244,7 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_SHARED_VERSION_MASK 0x00FF #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000 #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000 +#define BRCMF_PCIE_SHARED_USE_MAILBOX 0x2000000 #define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000 #define BRCMF_PCIE_SHARED_DAR 0x80000000 @@ -388,6 +389,10 @@ struct brcmf_pciedev_info { struct brcmf_pcie_shared_info shared; wait_queue_head_t mbdata_resp_wait; bool mbdata_completed; + /* Mailbox data travels as control messages (shared version >= 6). */ + bool mb_ctrlmsg; + /* A D3 ACK arrived as a control message; publish it after RX. */ + bool d3_ack_pending; bool irq_allocated; bool wowl_enabled; u8 dma_idx_sz; @@ -1057,6 +1062,14 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data) u32 cur_htod_mb_data; u32 i; + if (devinfo->mb_ctrlmsg) { + if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return -EIO; + /* Rings the doorbell through the control ring's callbacks. */ + return brcmf_proto_msgbuf_h2d_mb_data(&devinfo->pdev->dev, + htod_mb_data); + } + shared = &devinfo->shared; addr = shared->htod_mb_data_addr; cur_htod_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); @@ -1086,21 +1099,9 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data) } -static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) +static void brcmf_pcie_process_mb_data(struct brcmf_pciedev_info *devinfo, + u32 dtoh_mb_data) { - struct brcmf_pcie_shared_info *shared; - u32 addr; - u32 dtoh_mb_data; - - shared = &devinfo->shared; - addr = shared->dtoh_mb_data_addr; - dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); - - if (!dtoh_mb_data) - return; - - brcmf_pcie_write_tcm32(devinfo, addr, 0); - brcmf_dbg(PCIE, "D2H_MB_DATA: 0x%04x\n", dtoh_mb_data); if (dtoh_mb_data & BRCMF_D2H_DEV_DS_ENTER_REQ) { brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP REQ\n"); @@ -1111,8 +1112,18 @@ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP EXIT\n"); if (dtoh_mb_data & BRCMF_D2H_DEV_D3_ACK) { brcmf_dbg(PCIE, "D2H_MB_DATA: D3 ACK\n"); - devinfo->mbdata_completed = true; - wake_up(&devinfo->mbdata_resp_wait); + if (devinfo->mb_ctrlmsg) { + /* + * The message is still being processed: its ring read + * pointer isn't written back yet, and once the waiter + * sets STATE_DOWN that write is refused. Publish the + * ACK once RX processing is done (under rx_lock). + */ + devinfo->d3_ack_pending = true; + } else { + WRITE_ONCE(devinfo->mbdata_completed, true); + wake_up(&devinfo->mbdata_resp_wait); + } } if (dtoh_mb_data & BRCMF_D2H_DEV_FWHALT) { brcmf_dbg(PCIE, "D2H_MB_DATA: FW HALT\n"); @@ -1121,6 +1132,32 @@ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) } +static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) +{ + struct brcmf_pcie_shared_info *shared; + u32 addr; + u32 dtoh_mb_data; + + shared = &devinfo->shared; + addr = shared->dtoh_mb_data_addr; + dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); + + if (!dtoh_mb_data) + return; + + brcmf_pcie_write_tcm32(devinfo, addr, 0); + brcmf_pcie_process_mb_data(devinfo, dtoh_mb_data); +} + + +static void brcmf_pcie_d2h_mb_data(struct device *dev, u32 data) +{ + struct brcmf_bus *bus_if = dev_get_drvdata(dev); + + brcmf_pcie_process_mb_data(bus_if->bus_priv.pcie->devinfo, data); +} + + static void brcmf_pcie_bus_console_init(struct brcmf_pciedev_info *devinfo) { struct brcmf_pcie_shared_info *shared; @@ -1240,6 +1277,15 @@ static void brcmf_pcie_rx_process(struct brcmf_pciedev_info *devinfo) mutex_lock(&devinfo->rx_lock); if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) brcmf_proto_msgbuf_rx_trigger(&devinfo->pdev->dev); + /* + * The rings' read pointers are written back now, so a D3 ACK that + * came as a control message can be published. + */ + if (devinfo->d3_ack_pending) { + devinfo->d3_ack_pending = false; + WRITE_ONCE(devinfo->mbdata_completed, true); + wake_up(&devinfo->mbdata_resp_wait); + } mutex_unlock(&devinfo->rx_lock); } @@ -1991,6 +2037,7 @@ static const struct brcmf_bus_ops brcmf_pcie_bus_ops = { .get_blob = brcmf_pcie_get_blob, .reset = brcmf_pcie_reset, .debugfs_create = brcmf_pcie_debugfs_create, + .d2h_mb_data = brcmf_pcie_d2h_mb_data, }; @@ -2031,6 +2078,17 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK); brcmf_dbg(PCIE, "shared flags 0x%08x\n", shared->flags); + /* + * From shared version 6 Broadcom's driver exchanges mailbox data + * (D3 inform and ack, deep sleep) as control messages, unless the + * firmware asks for the shared-memory mailbox. The BCM4389 firmware + * doesn't, and ignores the TCM mailbox. + */ + devinfo->mb_ctrlmsg = shared->version >= 6 && + !(shared->flags & BRCMF_PCIE_SHARED_USE_MAILBOX); + brcmf_dbg(PCIE, "mailbox data as %s\n", + devinfo->mb_ctrlmsg ? "control messages" : "TCM mailbox"); + /* Broadcom's driver rings the DAR doorbells only when the firmware * offers them, and the core's own H2D mailbox registers otherwise. * The BCM4389 firmware does not, and ignores the DAR doorbells. @@ -3112,6 +3170,7 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) { struct brcmf_pciedev_info *devinfo; struct brcmf_bus *bus; + int err; brcmf_dbg(PCIE, "Enter\n"); @@ -3121,20 +3180,31 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) brcmf_pcie_fwcon_timer(devinfo, false); brcmf_bus_change_state(bus, BRCMF_BUS_DOWN); - devinfo->mbdata_completed = false; - brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM); + WRITE_ONCE(devinfo->mbdata_completed, false); + err = brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM); + if (err) { + brcmf_err(bus, "Failed to send D3 inform: %d\n", err); + goto restore; + } - wait_event_timeout(devinfo->mbdata_resp_wait, devinfo->mbdata_completed, + wait_event_timeout(devinfo->mbdata_resp_wait, + READ_ONCE(devinfo->mbdata_completed), BRCMF_PCIE_MBDATA_TIMEOUT); - if (!devinfo->mbdata_completed) { + if (!READ_ONCE(devinfo->mbdata_completed)) { brcmf_err(bus, "Timeout on response for entering D3 substate\n"); - brcmf_bus_change_state(bus, BRCMF_BUS_UP); - return -EIO; + err = -EIO; + goto restore; } devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + /* Nothing to poll until resume; the worker would only see DOWN. */ + cancel_delayed_work_sync(&devinfo->poll_work); return 0; + +restore: + brcmf_bus_change_state(bus, BRCMF_BUS_UP); + return err; } @@ -3154,7 +3224,12 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev) /* Check if device is still up and running, if so we are ready */ if (brcmf_pcie_read_reg32(devinfo, devinfo->reginfo->intmask) != 0) { brcmf_dbg(PCIE, "Try to wakeup device....\n"); - if (brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM)) + /* + * With mailbox data as control messages there is no D0 inform: + * the host-ready doorbell below resumes the device. + */ + if (!devinfo->mb_ctrlmsg && + brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM)) goto cleanup; brcmf_dbg(PCIE, "Hot resume, continue....\n"); devinfo->state = BRCMFMAC_PCIE_STATE_UP; From 5d19db648131e4da9f7a4d6800ad7809777f0f28 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 20:51:30 -0400 Subject: [PATCH 48/75] wifi: brcmfmac: pcie: catch the D3 ACK in shared memory, recover from a missed one On a Pixel 7 Pro (BCM4389, PCIe core rev >= 64, shared version 7) the first suspend with Wi-Fi up failed: the D3 inform went out as a control message, the dongle stopped its DMA engines right after it, and no D3 ACK was ever seen, neither on the control completion ring (its write index didn't move) nor anywhere brcmfmac looked. The suspend failed with -EIO, and the dongle stayed in D3: every later command timed out, and the host-to-dongle mailbox interrupt (FN0_0 in the dongle's DAR intstatus) stayed pending until a reboot. Broadcom's driver reads the shared-memory D2H mailbox whenever FN0_0 or FN0_1 is set, on rev >= 64 cores too, where those bits double as the D2H4 doorbells, and while waiting for a D3 ACK without an interrupt it polls that mailbox every millisecond. brcmfmac never reads it on rev >= 64 cores (int_fn0 = 0). Do both: - set int_fn0 for the rev >= 64 register sets, so the interrupt thread reads the shared-memory mailbox, under rx_lock; - wait for the D3 ACK by polling the shared-memory mailbox and the control completion ring every 2 ms, besides the wake-up; - once acknowledged, disable and clear the device's interrupts, as Broadcom's driver does. A missed ACK must not kill Wi-Fi: Broadcom's driver reports a hang and the firmware is reloaded. Ring the host-ready doorbell and request a bus reset (firmware reload, no memory dump) through a new brcmf_bus_request_reset(). Restart the firmware console timer when the inform couldn't be sent. On a hot resume, look at the mailbox and rings once and restart the poll, so nothing posted while interrupts were off waits for the next interrupt. The D3 path logs one dev_dbg() line per suspend and resume, which CONFIG_BRCMDBG builds print without the ring dumps of debug=0x80000. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/bus.h | 1 + .../broadcom/brcm80211/brcmfmac/core.c | 15 +++ .../broadcom/brcm80211/brcmfmac/pcie.c | 109 ++++++++++++++---- 3 files changed, 103 insertions(+), 22 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index f41d87dd55..34fe674df5 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -323,6 +323,7 @@ void brcmf_dev_reset(struct device *dev); void brcmf_dev_coredump(struct device *dev); /* Indication that firmware has halted or crashed */ void brcmf_fw_crashed(struct device *dev); +void brcmf_bus_request_reset(struct device *dev); /* Configure the "global" bus state used by upper layers */ void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c index ee38264ef9..5ec4e547da 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c @@ -1468,6 +1468,21 @@ void brcmf_fw_crashed(struct device *dev) brcmf_bus_schedule_reset(bus_if); } +/** + * brcmf_bus_request_reset() - reload the firmware for a bus driver + * @dev: the bus device + * + * For a device that stopped answering without reporting a crash, so no + * memory dump is taken. + */ +void brcmf_bus_request_reset(struct device *dev) +{ + struct brcmf_bus *bus_if = dev_get_drvdata(dev); + + if (bus_if) + brcmf_bus_schedule_reset(bus_if); +} + void brcmf_detach(struct device *dev) { s32 i; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 2906d1d927..e863aaa17d 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -393,6 +393,8 @@ struct brcmf_pciedev_info { bool mb_ctrlmsg; /* A D3 ACK arrived as a control message; publish it after RX. */ bool d3_ack_pending; + /* How the last D3 ACK arrived, for the log. */ + const char *d3_ack_via; bool irq_allocated; bool wowl_enabled; u8 dma_idx_sz; @@ -498,6 +500,12 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_default = { /* Core rev >= 64 with the doorbells in the PCIe core's own registers, for * firmware that does not offer the DAR doorbells (BRCMF_PCIE_SHARED_DAR). + * + * From core rev 64 the FN0 bits (0x100, 0x200) are also the D2H4 doorbells. + * Broadcom's driver still reads the shared-memory D2H mailbox when either is + * set (dhdpcie_bus_process_mailbox_intr()), and firmware may post mailbox + * data, the D3 ACK among it, that way even when it otherwise sends it as a + * control message. */ static const struct brcmf_pcie_reginfo brcmf_reginfo_64_nodar = { .intmask = BRCMF_PCIE_64_PCIE2REG_INTMASK, @@ -506,7 +514,7 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_64_nodar = { .h2d_mailbox_0 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_0, .h2d_mailbox_1 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_1, .int_d2h_db = BRCMF_PCIE_64_MB_INT_D2H_DB, - .int_fn0 = 0, + .int_fn0 = BRCMF_PCIE_MB_INT_FN0, }; static const struct brcmf_pcie_reginfo brcmf_reginfo_64 = { @@ -516,7 +524,7 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_64 = { .h2d_mailbox_0 = BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_0, .h2d_mailbox_1 = BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_1, .int_d2h_db = BRCMF_PCIE_64_MB_INT_D2H_DB, - .int_fn0 = 0, + .int_fn0 = BRCMF_PCIE_MB_INT_FN0, }; static void brcmf_pcie_setup(struct device *dev, int ret, @@ -1100,7 +1108,7 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data) static void brcmf_pcie_process_mb_data(struct brcmf_pciedev_info *devinfo, - u32 dtoh_mb_data) + u32 dtoh_mb_data, bool in_ring) { brcmf_dbg(PCIE, "D2H_MB_DATA: 0x%04x\n", dtoh_mb_data); if (dtoh_mb_data & BRCMF_D2H_DEV_DS_ENTER_REQ) { @@ -1112,7 +1120,9 @@ static void brcmf_pcie_process_mb_data(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP EXIT\n"); if (dtoh_mb_data & BRCMF_D2H_DEV_D3_ACK) { brcmf_dbg(PCIE, "D2H_MB_DATA: D3 ACK\n"); - if (devinfo->mb_ctrlmsg) { + devinfo->d3_ack_via = in_ring ? "control message" : + "shared-memory mailbox"; + if (in_ring) { /* * The message is still being processed: its ring read * pointer isn't written back yet, and once the waiter @@ -1132,6 +1142,7 @@ static void brcmf_pcie_process_mb_data(struct brcmf_pciedev_info *devinfo, } +/* The shared-memory D2H mailbox; the interrupt thread and the D3 wait poll it. */ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) { struct brcmf_pcie_shared_info *shared; @@ -1140,13 +1151,16 @@ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) shared = &devinfo->shared; addr = shared->dtoh_mb_data_addr; - dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); - - if (!dtoh_mb_data) + if (!addr) return; - brcmf_pcie_write_tcm32(devinfo, addr, 0); - brcmf_pcie_process_mb_data(devinfo, dtoh_mb_data); + mutex_lock(&devinfo->rx_lock); + dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); + if (dtoh_mb_data) { + brcmf_pcie_write_tcm32(devinfo, addr, 0); + brcmf_pcie_process_mb_data(devinfo, dtoh_mb_data, false); + } + mutex_unlock(&devinfo->rx_lock); } @@ -1154,7 +1168,7 @@ static void brcmf_pcie_d2h_mb_data(struct device *dev, u32 data) { struct brcmf_bus *bus_if = dev_get_drvdata(dev); - brcmf_pcie_process_mb_data(bus_if->bus_priv.pcie->devinfo, data); + brcmf_pcie_process_mb_data(bus_if->bus_priv.pcie->devinfo, data, true); } @@ -3166,10 +3180,32 @@ brcmf_pcie_remove(struct pci_dev *pdev) #ifdef CONFIG_PM +/* + * Wait for the D3 ACK. It may come as a control message or in the + * shared-memory mailbox, with or without an interrupt, so look at both every + * 2 ms, as Broadcom's driver does when it asks for no ACK interrupt. + */ +static bool brcmf_pcie_wait_d3_ack(struct brcmf_pciedev_info *devinfo) +{ + unsigned long deadline = jiffies + BRCMF_PCIE_MBDATA_TIMEOUT; + + do { + brcmf_pcie_handle_mb_data(devinfo); + brcmf_pcie_rx_process(devinfo); + if (wait_event_timeout(devinfo->mbdata_resp_wait, + READ_ONCE(devinfo->mbdata_completed), + msecs_to_jiffies(2))) + return true; + } while (time_before(jiffies, deadline)); + + return READ_ONCE(devinfo->mbdata_completed); +} + static int brcmf_pcie_pm_enter_D3(struct device *dev) { struct brcmf_pciedev_info *devinfo; struct brcmf_bus *bus; + ktime_t start; int err; brcmf_dbg(PCIE, "Enter\n"); @@ -3181,30 +3217,49 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) brcmf_bus_change_state(bus, BRCMF_BUS_DOWN); WRITE_ONCE(devinfo->mbdata_completed, false); + devinfo->d3_ack_via = NULL; + start = ktime_get(); err = brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM); if (err) { + /* Nothing reached the device: just carry on. */ brcmf_err(bus, "Failed to send D3 inform: %d\n", err); - goto restore; + brcmf_bus_change_state(bus, BRCMF_BUS_UP); + brcmf_pcie_fwcon_timer(devinfo, true); + return err; } - wait_event_timeout(devinfo->mbdata_resp_wait, - READ_ONCE(devinfo->mbdata_completed), - BRCMF_PCIE_MBDATA_TIMEOUT); - if (!READ_ONCE(devinfo->mbdata_completed)) { - brcmf_err(bus, "Timeout on response for entering D3 substate\n"); - err = -EIO; - goto restore; + if (!brcmf_pcie_wait_d3_ack(devinfo)) { + brcmf_err(bus, "Timeout on response for entering D3 substate (%lld ms, mailboxint 0x%08x)\n", + ktime_ms_delta(ktime_get(), start), + brcmf_pcie_read_reg32(devinfo, + devinfo->reginfo->mailboxint)); + /* + * The device may have taken the inform and stopped, or may + * still act on it: the host-ready doorbell is how Broadcom's + * driver brings a device back from D3, but an inform still + * queued would put it to sleep again. Reload the firmware, as + * Broadcom's driver does after a missed D3 ACK, so a failed + * suspend doesn't leave Wi-Fi dead. + */ + brcmf_pcie_hostready(devinfo); + brcmf_bus_change_state(bus, BRCMF_BUS_UP); + brcmf_bus_request_reset(dev); + return -EIO; } + dev_dbg(dev, "D3 ACK by %s after %lld us\n", devinfo->d3_ack_via, + ktime_us_delta(ktime_get(), start)); + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; /* Nothing to poll until resume; the worker would only see DOWN. */ cancel_delayed_work_sync(&devinfo->poll_work); + /* As Broadcom's driver: no device interrupts until resume. */ + brcmf_pcie_intr_disable(devinfo); + brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->mailboxint, + brcmf_pcie_read_reg32(devinfo, + devinfo->reginfo->mailboxint)); return 0; - -restore: - brcmf_bus_change_state(bus, BRCMF_BUS_UP); - return err; } @@ -3232,12 +3287,21 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev) brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM)) goto cleanup; brcmf_dbg(PCIE, "Hot resume, continue....\n"); + dev_dbg(dev, "hot resume\n"); devinfo->state = BRCMFMAC_PCIE_STATE_UP; + devinfo->d3_ack_pending = false; brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); brcmf_bus_change_state(bus, BRCMF_BUS_UP); brcmf_pcie_intr_enable(devinfo); brcmf_pcie_hostready(devinfo); brcmf_pcie_fwcon_timer(devinfo, true); + /* + * Completions the device posted while the interrupt was off + * would otherwise wait for the next interrupt. + */ + brcmf_pcie_handle_mb_data(devinfo); + brcmf_pcie_rx_process(devinfo); + brcmf_pcie_kick_poll(devinfo); return 0; } @@ -3247,6 +3311,7 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev) pdev = devinfo->pdev; brcmf_pcie_remove(pdev); + dev_dbg(dev, "device lost its state in sleep, probing again\n"); err = brcmf_pcie_probe(pdev, NULL); if (err) __brcmf_err(NULL, __func__, "probe after resume failed, err=%d\n", err); From cf5bb06c3b6efc9c046c7c38c18f6d6d9485a03b Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 12 Oct 2026 21:09:53 -0400 Subject: [PATCH 49/75] wifi: brcmfmac: pcie: stop ring processing before a bus reset A bus reset through debugfs (echo 1 > .../ieee80211/phy0/reset) on a Pixel 7 Pro (BCM4389) oopsed in the D2H poll worker: Workqueue: events brcmf_pcie_poll_worker [brcmfmac] pc : brcmf_proto_msgbuf_rx_trigger+0x24/0x144 [brcmfmac] brcmf_pcie_reset() only masks the device's interrupts before brcmf_detach() frees the protocol layer. The interrupt thread, the poll worker and the console timer stay live and keep processing the rings through freed memory; the worker died holding rx_lock, and the system wedged. Stop them first, as brcmf_pcie_remove() does: set STATE_DOWN so nothing re-arms, stop the console timer, mask and synchronise the interrupt, cancel the poll. brcmf_pcie_setup() brings the state back up. Also make the RX path refuse to run without a protocol layer. The missed-D3-ACK path no longer requests a bus reset. A firmware re-download without a power cycle hasn't been shown to work on this chip (a driver-only reload failed with "FW failed to initialize"; a reload of the whole stack, which cycles WL_REG_ON, works), and the host-ready doorbell it rang can trap this firmware. Log that the stack needs a reload instead, as Broadcom's driver leaves it to a full restart. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- .../broadcom/brcm80211/brcmfmac/bus.h | 1 - .../broadcom/brcm80211/brcmfmac/core.c | 15 --------- .../broadcom/brcm80211/brcmfmac/msgbuf.c | 6 +++- .../broadcom/brcm80211/brcmfmac/pcie.c | 33 ++++++++++++++----- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index 34fe674df5..f41d87dd55 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -323,7 +323,6 @@ void brcmf_dev_reset(struct device *dev); void brcmf_dev_coredump(struct device *dev); /* Indication that firmware has halted or crashed */ void brcmf_fw_crashed(struct device *dev); -void brcmf_bus_request_reset(struct device *dev); /* Configure the "global" bus state used by upper layers */ void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c index 5ec4e547da..ee38264ef9 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c @@ -1468,21 +1468,6 @@ void brcmf_fw_crashed(struct device *dev) brcmf_bus_schedule_reset(bus_if); } -/** - * brcmf_bus_request_reset() - reload the firmware for a bus driver - * @dev: the bus device - * - * For a device that stopped answering without reporting a crash, so no - * memory dump is taken. - */ -void brcmf_bus_request_reset(struct device *dev) -{ - struct brcmf_bus *bus_if = dev_get_drvdata(dev); - - if (bus_if) - brcmf_bus_schedule_reset(bus_if); -} - void brcmf_detach(struct device *dev) { s32 i; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index b632911357..b4885fd05e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -1576,12 +1576,16 @@ int brcmf_proto_msgbuf_rx_trigger(struct device *dev) { struct brcmf_bus *bus_if = dev_get_drvdata(dev); struct brcmf_pub *drvr = bus_if->drvr; - struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + struct brcmf_msgbuf *msgbuf; struct brcmf_commonring *commonring; void *buf; u32 flowid; int qlen; + if (!drvr || !drvr->proto || !drvr->proto->pd) + return -ENODEV; + msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_RX_COMPLETE]; brcmf_msgbuf_process_rx(msgbuf, buf); buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_TX_COMPLETE]; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index e863aaa17d..bcb390ae8e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1288,8 +1288,11 @@ static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg) /* Process the D2H rings; the interrupt thread and the poll both get here. */ static void brcmf_pcie_rx_process(struct brcmf_pciedev_info *devinfo) { + struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); + mutex_lock(&devinfo->rx_lock); - if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) + if (devinfo->state == BRCMFMAC_PCIE_STATE_UP && bus && bus->drvr && + bus->drvr->proto) brcmf_proto_msgbuf_rx_trigger(&devinfo->pdev->dev); /* * The rings' read pointers are written back now, so a D3 ACK that @@ -2013,7 +2016,19 @@ static int brcmf_pcie_reset(struct device *dev) struct brcmf_fw_request *fwreq; int err; + /* + * Stop everything that processes the rings before brcmf_detach() + * frees the protocol layer: the interrupt thread, the D2H poll and + * the console timer. As in brcmf_pcie_remove(); STATE_DOWN keeps the + * interrupt thread and the poll from re-arming. brcmf_pcie_setup() + * sets it UP again. + */ + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + brcmf_pcie_fwcon_timer(devinfo, false); brcmf_pcie_intr_disable(devinfo); + if (devinfo->irq_allocated) + synchronize_irq(devinfo->pdev->irq); + cancel_delayed_work_sync(&devinfo->poll_work); brcmf_pcie_bus_console_read(devinfo, true); @@ -3234,16 +3249,16 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) brcmf_pcie_read_reg32(devinfo, devinfo->reginfo->mailboxint)); /* - * The device may have taken the inform and stopped, or may - * still act on it: the host-ready doorbell is how Broadcom's - * driver brings a device back from D3, but an inform still - * queued would put it to sleep again. Reload the firmware, as - * Broadcom's driver does after a missed D3 ACK, so a failed - * suspend doesn't leave Wi-Fi dead. + * The device may have taken the inform and stopped. Broadcom's + * driver gives up on it here and has the whole stack + * restarted; a host-ready doorbell is no cure (an inform still + * queued puts it to sleep again, and this firmware traps on an + * unexpected host ready), and brcmfmac's own bus reset doesn't + * bring this chip back. Leave recovery to a reload of the + * stack, which power-cycles the chip. */ - brcmf_pcie_hostready(devinfo); + brcmf_err(bus, "device unresponsive after D3 inform; reload the driver stack to recover\n"); brcmf_bus_change_state(bus, BRCMF_BUS_UP); - brcmf_bus_request_reset(dev); return -EIO; } From ab81c9033c3e8de91f5dd1ee4573c5a877044e1b Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Tue, 13 Oct 2026 08:15:07 -0400 Subject: [PATCH 50/75] wifi: brcmfmac: msgbuf: number the H2D mailbox data messages On a Pixel 7 Pro (BCM4389, firmware 20.101.90) every system suspend with Wi-Fi up failed in brcmf_pcie_pm_enter_D3(): brcmf_pcie_pm_enter_D3: Timeout on response for entering D3 substate (1999 ms, mailboxint 0x00000000) brcmf_pcie_pm_enter_D3: device unresponsive after D3 inform; reload the driver stack to recover The D3 inform went out as an H2D mailbox data message on the control submit ring, but the dongle never consumed it: its read index of that ring stayed on the inform's slot while the host's write index moved on, so no D3 ACK came, neither on the control completion ring nor in the shared-memory mailbox, and every control message queued after the inform timed out. This firmware checks the sequence number ("epoch") in the common header of each control submit item and waits on an item whose number doesn't match. brcmf_proto_msgbuf_h2d_mb_data() never set it, so the inform went out with 0 and the ring stalled on it. It also didn't advance the ring's sequence, which would have put every later control message off by one. Broadcom's driver numbers mailbox data like every other control message (bcm4389 dhd_msgbuf.c, dhd_prot_h2d_mbdata_send_ctrlmsg()). Stamp the epoch on H2D mailbox data, as the ioctl, buffer post and flow ring requests already do. Fixes: 812288601b45 ("wifi: brcmfmac: pcie: exchange mailbox data as control messages") Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index b4885fd05e..cefa63de17 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -1565,6 +1565,8 @@ int brcmf_proto_msgbuf_h2d_mb_data(struct device *dev, u32 data) memset(mb_data, 0, sizeof(*mb_data)); mb_data->msg.msgtype = MSGBUF_TYPE_H2D_MAILBOX_DATA; mb_data->mb_data = cpu_to_le32(data); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &mb_data->msg); err = brcmf_commonring_write_complete(commonring); brcmf_commonring_unlock(commonring); From 216e9c9a44e8ad39853ccd80c12980191b740a6a Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Tue, 13 Oct 2026 08:15:07 -0400 Subject: [PATCH 51/75] wifi: brcmfmac: pcie: let the interrupt thread finish before masking for D3 brcmf_pcie_pm_enter_D3() masks and clears the device's interrupts once the D3 ACK is in. When the ACK came as a control message, it is published from brcmf_pcie_rx_process() in the interrupt thread, which then goes on: it reads the state, re-enables the interrupt while it is still STATE_UP and kicks the D2H poll. If that happens after the suspend path masked the interrupt, the device is left unmasked across D3, and a later interrupt in D3 runs the handler against a sleeping device. Synchronise with the interrupt after setting STATE_DOWN and before cancelling the poll and masking, so whatever the thread did is undone and nothing re-arms. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Derek Ross --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index bcb390ae8e..5e3aed4ae8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -3266,6 +3266,13 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) ktime_us_delta(ktime_get(), start)); devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + /* + * The interrupt thread that published the ACK may still be running + * and, having seen STATE_UP, unmask the interrupt or kick the poll. + * Let it finish before masking. + */ + if (devinfo->irq_allocated) + synchronize_irq(devinfo->pdev->irq); /* Nothing to poll until resume; the worker would only see DOWN. */ cancel_delayed_work_sync(&devinfo->poll_work); /* As Broadcom's driver: no device interrupts until resume. */ From 1907d988178ab319f7f9a2c1c5c14d51929ca6c8 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:28:24 -0647 Subject: [PATCH 52/75] wifi: brcmfmac: pcie: support shared-memory version 9 firmware The Pixel 9a's BCM4383 firmware (20.123.13) speaks shared-memory ("PCIe IPC") version 9. Accept it next to version 7, keyed on the version the firmware reports rather than on a chip, and do what Broadcom's driver does for it: - read the EWP info block the shared area points to (offset 128) and refuse to go on unless the firmware says its initialisation ended, so a stalled firmware fails cleanly instead of leaving rings pointing nowhere; - bound every ring-info read and the fallback TCM index arrays to the chip's RAM before trusting them; - ring host-ready right after the common rings are set up, before any buffer is posted (the 4389 path, now keyed on the version too), and leave the aggregation host capability byte (offset 133) at zero; - the no-DAR doorbells by the same test. Version 8 stays refused: its layout is not known here. For the BCM4389 nothing changes: brcmf_pcie_early_hostready() is true for it by device id as before, and the version 9 checks do not run on its version 7 firmware. Tested on the Pixel 9a (BCM4383, API9): the firmware comes up, scans, joins a WPA2 network and passes traffic. Not yet booted on the Pixel 7 Pro. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../broadcom/brcm80211/brcmfmac/pcie.c | 145 ++++++++++++++++-- 1 file changed, 131 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 5e3aed4ae8..98671bf534 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -239,8 +239,9 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { BRCMF_PCIE_64_MB_INT_D2H7_DB1) #define BRCMF_PCIE_SHARED_VERSION_7 7 +#define BRCMF_PCIE_SHARED_VERSION_9 9 #define BRCMF_PCIE_MIN_SHARED_VERSION 5 -#define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_7 +#define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_9 #define BRCMF_PCIE_SHARED_VERSION_MASK 0x00FF #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000 #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000 @@ -264,6 +265,12 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET 68 /* shared area revision >= 6: host capabilities, read by the firmware */ #define BRCMF_SHARED_HOST_CAP_OFFSET 84 +#define BRCMF_SHARED_EWP_INFO_ADDR_OFFSET 128 +#define BRCMF_SHARED_AGGR_HOST_CAP_OFFSET 133 +#define BRCMF_SHARED_VERSION_9_SIZE 140 + +#define BRCMF_EWP_INFO_VERSION 1 +#define BRCMF_EWP_INIT_END 2 #define BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY 0x00000400 #define BRCMF_HOSTCAP_DS_NO_OOB_DW 0x00001000 @@ -1258,6 +1265,14 @@ static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo) devinfo->reginfo->int_fn0); } +/* API9 firmware defers TX allocation until host ready, as does BCM4389. */ +static bool +brcmf_pcie_early_hostready(struct brcmf_pciedev_info *devinfo) +{ + return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID || + devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9; +} + static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo) { if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) { @@ -1640,6 +1655,56 @@ static void brcmf_pcie_release_ringbuffers(struct brcmf_pciedev_info *devinfo) } +static bool +brcmf_pcie_valid_ram_range(struct brcmf_pciedev_info *devinfo, u32 addr, + u32 len) +{ + u64 end = (u64)addr + len; + + return len && addr >= devinfo->ci->rambase && end <= BIT_ULL(32) && + end <= (u64)devinfo->ci->rambase + devinfo->ci->ramsize; +} + +/* API9 must describe every ring and its fallback TCM indices in RAM. */ +static bool +brcmf_pcie_api9_valid_ringinfo(struct brcmf_pciedev_info *devinfo, + const struct brcmf_pcie_dhi_ringinfo *ringinfo) +{ + u32 h2d = le16_to_cpu(ringinfo->max_submissionrings); + u32 d2h = le16_to_cpu(ringinfo->max_completionrings); + u32 flows = le16_to_cpu(ringinfo->max_flowrings); + u32 ptrs[] = { + le32_to_cpu(ringinfo->h2d_w_idx_ptr), + le32_to_cpu(ringinfo->h2d_r_idx_ptr), + le32_to_cpu(ringinfo->d2h_w_idx_ptr), + le32_to_cpu(ringinfo->d2h_r_idx_ptr), + }; + u32 ringmem = le32_to_cpu(ringinfo->ringmem); + u32 count; + u32 i; + + if (!flows || flows > 512 || + h2d < flows + BRCMF_NROF_H2D_COMMON_MSGRINGS || + d2h < BRCMF_NROF_D2H_COMMON_MSGRINGS) + return false; + if (ringmem & 3 || + !brcmf_pcie_valid_ram_range(devinfo, ringmem, + BRCMF_NROF_COMMON_MSGRINGS * + BRCMF_RING_MEM_SZ)) + return false; + + /* Allocation failure falls back to four-byte-spaced TCM indices. */ + for (i = 0; i < ARRAY_SIZE(ptrs); i++) { + count = i < 2 ? h2d : d2h; + if (ptrs[i] & 3 || + !brcmf_pcie_valid_ram_range(devinfo, ptrs[i], + count * sizeof(u32))) + return false; + } + + return true; +} + static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) { struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); @@ -1659,8 +1724,18 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) u16 max_submissionrings; u16 max_completionrings; + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9 && + (devinfo->shared.ring_info_addr & 3 || + !brcmf_pcie_valid_ram_range(devinfo, + devinfo->shared.ring_info_addr, + sizeof(ringinfo)))) + return -EINVAL; + brcmf_pcie_copy_dev_tomem(devinfo, devinfo->shared.ring_info_addr, &ringinfo, sizeof(ringinfo)); + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9 && + !brcmf_pcie_api9_valid_ringinfo(devinfo, &ringinfo)) + return -EINVAL; if (devinfo->shared.version >= 6) { max_submissionrings = le16_to_cpu(ringinfo.max_submissionrings); max_flowrings = le16_to_cpu(ringinfo.max_flowrings); @@ -1855,6 +1930,7 @@ static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); u64 address; u32 addr; + u8 aggr_cap = 0; devinfo->shared.scratch = dma_alloc_coherent(&devinfo->pdev->dev, @@ -1873,7 +1949,14 @@ static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET; brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN); - if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) { + if (brcmf_pcie_early_hostready(devinfo)) { + /* API9 uses the legacy ring-update slots for host SCB offload. */ + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9) { + addr = devinfo->shared.tcm_base_address + + BRCMF_SHARED_AGGR_HOST_CAP_OFFSET; + brcmf_pcie_copy_mem_todev(devinfo, addr, &aggr_cap, + sizeof(aggr_cap)); + } brcmf_pcie_set_host_cap(devinfo); return 0; } @@ -1920,11 +2003,8 @@ static int brcmf_pcie_preinit(struct device *dev) brcmf_dbg(PCIE, "Enter\n"); brcmf_pcie_intr_enable(buspub->devinfo); - /* The BCM4389 was told host ready right after its rings were set - * up; its firmware traps on a second one (_hnd_die from - * pciedev_handle_hostready_intr), so ring it only once. - */ - if (buspub->devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID) + /* The early path already notified firmware after setting up the rings. */ + if (!brcmf_pcie_early_hostready(buspub->devinfo)) brcmf_pcie_hostready(buspub->devinfo); return 0; @@ -2092,6 +2172,30 @@ brcmf_pcie_adjust_ramsize(struct brcmf_pciedev_info *devinfo, u8 *data, } +/* Check firmware's EWP initialization result before setting up host DMA. */ +static int brcmf_pcie_api9_ready(struct brcmf_pciedev_info *devinfo) +{ + u32 addr = devinfo->shared.tcm_base_address; + u32 ewp; + + if (!(devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1)) + return -EOPNOTSUPP; + if (!brcmf_pcie_valid_ram_range(devinfo, addr, + BRCMF_SHARED_VERSION_9_SIZE)) + return -EINVAL; + + ewp = brcmf_pcie_read_tcm32(devinfo, + addr + BRCMF_SHARED_EWP_INFO_ADDR_OFFSET); + if (!ewp || ewp & 3 || !brcmf_pcie_valid_ram_range(devinfo, ewp, 2)) + return -EINVAL; + if (brcmf_pcie_read_tcm8(devinfo, ewp) != BRCMF_EWP_INFO_VERSION) + return -EPROTONOSUPPORT; + if (brcmf_pcie_read_tcm8(devinfo, ewp + 1) != BRCMF_EWP_INIT_END) + return -EIO; + + return 0; +} + static int brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, u32 sharedram_addr) @@ -2099,10 +2203,16 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); struct brcmf_pcie_shared_info *shared; u32 addr; + int ret; shared = &devinfo->shared; shared->tcm_base_address = sharedram_addr; + /* The version is unknown until this first bounded metadata read. */ + if (sharedram_addr & 3 || + !brcmf_pcie_valid_ram_range(devinfo, sharedram_addr, sizeof(u32))) + return -EINVAL; + shared->flags = brcmf_pcie_read_tcm32(devinfo, sharedram_addr); shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK); brcmf_dbg(PCIE, "shared flags 0x%08x\n", shared->flags); @@ -2123,7 +2233,7 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, * The BCM4389 firmware does not, and ignores the DAR doorbells. */ if (devinfo->reginfo == &brcmf_reginfo_64 && - devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + brcmf_pcie_early_hostready(devinfo) && !(shared->flags & BRCMF_PCIE_SHARED_DAR)) { devinfo->reginfo = &brcmf_reginfo_64_nodar; brcmf_dbg(PCIE, "no DAR: doorbells at 0x%x/0x%x\n", @@ -2132,12 +2242,22 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, } brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version); if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) || - (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) { + (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION) || + shared->version == 8) { brcmf_err(bus, "Unsupported PCIE version %d\n", shared->version); return -EINVAL; } + if (shared->version == BRCMF_PCIE_SHARED_VERSION_9) { + ret = brcmf_pcie_api9_ready(devinfo); + if (ret) { + brcmf_err(bus, "API9 firmware initialization failed: %d\n", + ret); + return ret; + } + } + /* check firmware support dma indicies */ if (shared->flags & BRCMF_PCIE_SHARED_DMA_INDEX) { if (shared->flags & BRCMF_PCIE_SHARED_DMA_2B_IDX) @@ -2726,11 +2846,8 @@ static void brcmf_pcie_setup(struct device *dev, int ret, devinfo->poll_enabled = devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID; - /* Broadcom's driver rings host ready as soon as the common rings - * are set up, before it posts any buffer (bcmdhd dhd_prot_init(), - * hostrdy_after_init), and the BCM4389 was told so in host_cap. - */ - if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) + /* Notify early firmware before its deferred TX-buffer allocation. */ + if (brcmf_pcie_early_hostready(devinfo)) brcmf_pcie_hostready(devinfo); /* hook the commonrings in the bus structure. */ From 52a0623ea79656f75d6e0e91c0fa7f1afcbf5624 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:28:51 -0647 Subject: [PATCH 53/75] wifi: brcmfmac: add BCM4383 PCIe support The BCM4383 (PCI 14e4:4449, chip id 0x4383, rev 2) is the Wi-Fi chip in the Pixel 9a. Add its ids, its SYSMEM base (0x6e0000, from the firmware's load address) and the firmware name "brcmfmac4383-pcie" with the CLM blob, and two firmware-keyed quirks for its 20.123.13 firmware: - it takes only the versioned "join" parameters: the unversioned iovar and SET_SSID both fail with -52, so enable BRCMF_FEAT_JOIN_V1 by the same WLC version test as for the BCM4389; - it advertises the supplicant offload but refuses the key ("failed to change PSK in firmware"), so leave FWSUP, SAE and FWAUTH off and let the host do the handshakes. Tested on the Pixel 9a with the owner's firmware set: wlan0 comes up, scans, joins a WPA2 network through iwd and passes traffic, with no module parameters. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- .../broadcom/brcm80211/brcmfmac/chip.c | 2 ++ .../broadcom/brcm80211/brcmfmac/feature.c | 19 ++++++++++++++++--- .../broadcom/brcm80211/brcmfmac/pcie.c | 4 ++++ .../broadcom/brcm80211/include/brcm_hw_ids.h | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index e2a628dc32..d0fed7b6a4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c @@ -784,6 +784,8 @@ static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci) return 0x170000; case BRCM_CC_4378_CHIP_ID: return 0x352000; + case BRCM_CC_4383_CHIP_ID: + return 0x6e0000; case BRCM_CC_4387_CHIP_ID: return 0x740000; default: diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index bff2f5c62e..145b576395 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -161,10 +161,13 @@ static void brcmf_feat_wlc_version_overrides(struct brcmf_pub *drv) * Versioned "join" parameters (wl_extjoin_params_v1_t), by the * same WLC version test as Broadcom's driver (bcmdhd * wl_cfg80211.c, MIN_JOINEXT_V1_*): 14.2 or 14.4, 16.1 and later - * on 16, or 17 and later. Only the BCM4389 for now; its 20.101.90 - * firmware reports 14.4 and rejects the unversioned layout. + * on 16, or 17 and later. The BCM4389 (its 20.101.90 firmware + * reports 14.4 and rejects the unversioned layout) and the Pixel + * 9a's BCM4383 (20.123.13: the unversioned "join" and SET_SSID + * both fail with -52). */ - if (drv->bus_if->chip == BRCM_CC_4389_CHIP_ID && + if ((drv->bus_if->chip == BRCM_CC_4389_CHIP_ID || + drv->bus_if->chip == BRCM_CC_4383_CHIP_ID) && ((major == 14 && (minor == 2 || minor == 4)) || (major == 16 && minor >= 1) || major >= 17)) feat_flags |= BIT(BRCMF_FEAT_JOIN_V1); @@ -363,6 +366,16 @@ void brcmf_feat_attach(struct brcmf_pub *drvr) if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID) drvr->feat_flags &= ~BIT(BRCMF_FEAT_HOST_SFHLLC); + /* + * The BCM4383's firmware (20.123.13 on the Pixel 9a) advertises the + * supplicant offload but refuses the key: brcmf_set_wsec() fails with + * "failed to change PSK in firmware" and the join never gets past + * authentication. Leave the handshakes to the host. + */ + if (drvr->bus_if->chip == BRCM_CC_4383_CHIP_ID) + drvr->feat_flags &= ~(BIT(BRCMF_FEAT_FWSUP) | BIT(BRCMF_FEAT_SAE) | + BIT(BRCMF_FEAT_FWAUTH)); + if (drvr->settings->feature_disable) { brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", ifp->drvr->feat_flags, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 98671bf534..785a8f13cb 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -74,6 +74,8 @@ BRCMF_FW_CLM_DEF(4378B1, "brcmfmac4378b1-pcie"); BRCMF_FW_CLM_DEF(4378B3, "brcmfmac4378b3-pcie"); BRCMF_FW_CLM_DEF(4387C2, "brcmfmac4387c2-pcie"); BRCMF_FW_CLM_DEF(4389C1, "brcmfmac4389c1-pcie"); +/* BCM4383 rev 2 (Pixel 9a): the owner's firmware set, with CLM and TXCAP blobs */ +BRCMF_FW_CLM_DEF(4383, "brcmfmac4383-pcie"); BRCMF_FW_CLM_DEF(54591, "brcmfmac54591-pcie"); /* firmware config files */ @@ -116,6 +118,7 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { BRCMF_FW_ENTRY(BRCM_CC_4378_CHIP_ID, 0xFFFFFFE0, 4378B3), /* revision ID 5 */ BRCMF_FW_ENTRY(BRCM_CC_4387_CHIP_ID, 0xFFFFFFFF, 4387C2), /* revision ID 7 */ BRCMF_FW_ENTRY(BRCM_CC_4389_CHIP_ID, 0xFFFFFFFF, 4389C1), + BRCMF_FW_ENTRY(BRCM_CC_4383_CHIP_ID, 0xFFFFFFFF, 4383), }; #define BRCMF_PCIE_FW_UP_TIMEOUT 5000 /* msec */ @@ -3515,6 +3518,7 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { BRCMF_PCIE_DEVICE(BRCM_PCIE_4378_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4389_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4383_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_43752_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(CY_PCIE_54591_DEVICE_ID, CYW), { /* end: all zeroes */ } diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h index bcb68ae6b1..7cbe571c39 100644 --- a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h +++ b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h @@ -56,6 +56,7 @@ #define BRCM_CC_43752_CHIP_ID 43752 #define BRCM_CC_4377_CHIP_ID 0x4377 #define BRCM_CC_4378_CHIP_ID 0x4378 +#define BRCM_CC_4383_CHIP_ID 0x4383 #define BRCM_CC_4387_CHIP_ID 0x4387 #define BRCM_CC_4389_CHIP_ID 0x4389 #define CY_CC_4373_CHIP_ID 0x4373 @@ -99,6 +100,7 @@ #define BRCM_PCIE_43752_DEVICE_ID 0x449d #define BRCM_PCIE_4377_DEVICE_ID 0x4488 #define BRCM_PCIE_4378_DEVICE_ID 0x4425 +#define BRCM_PCIE_4383_DEVICE_ID 0x4449 #define BRCM_PCIE_4387_DEVICE_ID 0x4433 #define BRCM_PCIE_4389_DEVICE_ID 0x4441 #define CY_PCIE_54591_DEVICE_ID 0x4417 From 0281392ec21dad66a408c4ee256e55d022bdbb8b Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:30:53 -0647 Subject: [PATCH 54/75] wifi: brcmfmac: pcie: bound the console read when the device reads all ones brcmf_pcie_bus_console_read() reads the firmware's console write index and walks read_idx up to it, wrapping at bufsize. When the device is gone the index reads 0xffffffff, which read_idx never reaches, and the walk never ends. Seen on a BCM4383 after s2idle on the Pixel 9a: the chip does not come back, the reset work entered this loop from brcmf_pcie_reset() and spun one CPU at 100 % with a stream of "CONSOLE:" lines of 0xff bytes. A later rmmod then blocked in cancel_work_sync() for good, holding the device lock, so the next shutdown would have hung in device_shutdown(). Return when the write index is outside the console buffer. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com> --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 785a8f13cb..4ca80e15e8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -1226,6 +1226,14 @@ static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo, return; addr = console->base_addr + BRCMF_CONSOLE_WRITEIDX_OFFSET; newidx = brcmf_pcie_read_tcm32(devinfo, addr); + if (newidx >= console->bufsize) { + /* A dead link reads all ones, and read_idx wraps at bufsize, + * so the loop below would never meet it. + */ + brcmf_err(bus, "console write index %u out of range (%u)\n", + newidx, console->bufsize); + return; + } while (newidx != console->read_idx) { addr = console->buf_addr + console->read_idx; ch = brcmf_pcie_read_tcm8(devinfo, addr); From d57b5375dd90c15758ad133b080aab4e16a2b491 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:09:49 -0400 Subject: [PATCH 55/75] arm64: dts: exynos: google: zuma: add the HSI2 and FAR_ALIVE pin controllers Add HSI2's pin controller at 0x13040000 (gph3 and gph4, SPI 432) and FAR_ALIVE at 0x154e0000 (gpa5, one wake-up interrupt per pin, SPI 60 to 67), with the banks and interrupts of stock's live device tree, as controllers 9 and 2 of the driver's zuma data. FAR_ALIVE's bus clock comes from CMU_APM; HSI2 takes the bus-clock stand-in, as HSI2UFS does. The Wi-Fi chip's PCIe reset, clock request, enable and wake lines are on gph3, and its host wake on gpa5. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../boot/dts/exynos/google/zuma-pinctrl.dtsi | 34 +++++++++++++++++++ arch/arm64/boot/dts/exynos/google/zuma.dtsi | 22 ++++++++++++ 2 files changed, 56 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index a88e0eaa20..4b4162ec44 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -259,6 +259,24 @@ }; }; +&pinctrl_far_alive { + gpa5: gpa5-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = , + , + , + , + , + , + , + ; + }; +}; + &pinctrl_peric0 { gpp0: gpp0-gpio-bank { gpio-controller; @@ -438,6 +456,22 @@ }; }; +&pinctrl_hsi2 { + gph3: gph3-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gph4: gph4-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; +}; + &pinctrl_hsi2ufs { gph5: gph5-gpio-bank { gpio-controller; diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index 2e76d03326..3fb6ccd1e0 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -26,6 +26,8 @@ aliases { pinctrl0 = &pinctrl_gpio_alive; pinctrl1 = &pinctrl_custom_alive; + pinctrl2 = &pinctrl_far_alive; + pinctrl9 = &pinctrl_hsi2; pinctrl10 = &pinctrl_hsi2ufs; pinctrl11 = &pinctrl_peric0; pinctrl12 = &pinctrl_peric1; @@ -449,6 +451,14 @@ reg = <0x13020000 0x1000>; }; + pinctrl_hsi2: pinctrl@13040000 { + compatible = "google,zuma-pinctrl"; + reg = <0x13040000 0x1000>; + clocks = <&clk_gpio_stub>; + clock-names = "pclk"; + interrupts = ; + }; + pinctrl_hsi2ufs: pinctrl@13060000 { compatible = "google,zuma-pinctrl"; reg = <0x13060000 0x1000>; @@ -551,6 +561,18 @@ }; }; + pinctrl_far_alive: pinctrl@154e0000 { + compatible = "google,zuma-pinctrl"; + reg = <0x154e0000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_GPIO_FAR_ALIVE>; + clock-names = "pclk"; + + wakeup-interrupt-controller { + compatible = "google,zuma-wakeup-eint", + "google,zumapro-wakeup-eint"; + }; + }; + apm_sram: sram@15700000 { compatible = "mmio-sram"; reg = <0x15700000 0x58000>; From b439e2b45abdeefd25d356205f9473cf401bf857 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:09:56 -0400 Subject: [PATCH 56/75] soc: samsung: gs101-pmu: zuma: allow the Wi-Fi PCIe PHY's isolation register zuma's PCIe PHY for its second controller (the Wi-Fi chip's) is isolated through PMU offset 0x3ec8, as stock's pcie@13120000 gives it (pmu-offset). Its PHY driver releases the isolation, so add the register to zuma's PMU regmap, next to UFS's. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/soc/samsung/gs101-pmu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index e357744d4a..a1fbaa2ecd 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -343,6 +343,7 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_CLUSTER1_NONCPU_INT_EN 0x1544 #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 +#define ZUMA_PHY_CTRL_PCIE1 0x3ec8 static const struct regmap_range zuma_pmu_registers[] = { /* reboot mode */ @@ -358,6 +359,7 @@ static const struct regmap_range zuma_pmu_registers[] = { /* PHY isolation */ regmap_reg_range(GS101_PHY_CTRL_USB20, GS101_PHY_CTRL_USB20), regmap_reg_range(ZUMA_PHY_CTRL_UFS, ZUMA_PHY_CTRL_UFS), + regmap_reg_range(ZUMA_PHY_CTRL_PCIE1, ZUMA_PHY_CTRL_PCIE1), /* a hint TF-A reads, not a status register: see zuma_pmu_regmap_init() */ regmap_reg_range(ZUMA_PMU_INFORM0, ZUMA_PMU_INFORM0), }; From b6b0046d290a9f290d5a8079712582bcba27e08a Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:21 -0400 Subject: [PATCH 57/75] dt-bindings: phy: Add the Google zuma PCIe Gen3 PHY zuma's (Tensor G3) second PCIe controller, the Wi-Fi chip's, has a one-lane Gen3 PHY clocked from an external PLL in the UDBG block and selected in the controller's SOC block, isolated by the PMU until it is released. Its registers are the PMA, the PCS, the PHY resets in the controller's sub-control space, the UDBG and the SOC block, at the addresses of stock's pcie@13120000. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../bindings/phy/google,zuma-pcie-phy.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml new file mode 100644 index 0000000000..8003eb7b5e --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/google,zuma-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google zuma PCIe Gen3 PHY + +maintainers: + - Brett-Michael Green + +description: + The one-lane PCIe Gen3 PHY of the Google zuma (Tensor G3) SoC's second + PCIe controller, which connects the Wi-Fi chip on Pixel 8 phones. Its + reference clock comes from an external PLL in the UDBG block, selected as + the PHY's input clock in the controller's SOC block. The PMU isolates the + PHY until it is released. + +properties: + compatible: + const: google,zuma-pcie-phy + + reg: + items: + - description: PMA registers + - description: PCS registers + - description: PHY reset registers in the controller's sub-control space + - description: UDBG (external PLL) registers + - description: SOC (PHY input clock selection) registers + + reg-names: + items: + - const: pma + - const: pcs + - const: rst + - const: udbg + - const: soc + + "#phy-cells": + const: 0 + + samsung,pmu-syscon: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the PMU system controller + - description: offset of this PHY's control (isolation) register + description: + The PMU and the offset of this PHY's isolation control. + +required: + - compatible + - reg + - reg-names + - "#phy-cells" + - samsung,pmu-syscon + +additionalProperties: false + +examples: + - | + phy@13160000 { + compatible = "google,zuma-pcie-phy"; + reg = <0x13160000 0x3000>, <0x13140000 0x5000>, + <0x13121400 0x10>, <0x13150000 0xd000>, + <0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + }; From 84921d6f93e42b4cb4b60981f6aabe2080015fdf Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:21 -0400 Subject: [PATCH 58/75] phy: samsung: Add the Google zuma PCIe Gen3 PHY driver Add a driver for the one-lane Gen3 PHY of zuma's (Tensor G3) second PCIe controller, which connects the Pixel 8's Wi-Fi chip. The sequence is Samsung's CAL for zuma, channel 1, from the driver Google builds for zuma (pcie-exynos-zuma-rc-cal.c and pcie-exynos-rc.c): - init: release the PMU isolation, then power the PHY down (phy_all_pwrdn); - power_on: select the clock mode in the SOC block, clear the power downs, start the external PLL and wait for its lock, select it as the PHY's input clock, program the PMA and PCS in reset, release the resets and wait for the PLL, CDR and offset calibration, then write UDBG 0xc800 as establish_link does before PERST#; - power_off: power the PHY down again. The CAL also sets the controller's RC mode and soft power reset in the middle of this; those are the controller driver's, in its ELBI space. The PMA and PCS values for a Broadcom endpoint (stock's ep-device-type 1) are used, since that is what this controller connects. As in the gs201 PHY driver, trace=1 logs every step before it touches the hardware, for bring-up. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- MAINTAINERS | 2 + drivers/phy/samsung/Kconfig | 12 + drivers/phy/samsung/Makefile | 1 + drivers/phy/samsung/phy-zuma-pcie.c | 433 ++++++++++++++++++++++++++++ 4 files changed, 448 insertions(+) create mode 100644 drivers/phy/samsung/phy-zuma-pcie.c diff --git a/MAINTAINERS b/MAINTAINERS index d5c748f6f6..1a68316b1c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11169,6 +11169,7 @@ F: Documentation/devicetree/bindings/clock/google,gs201-clock.yaml F: Documentation/devicetree/bindings/clock/google,zuma-clock.yaml F: Documentation/devicetree/bindings/clock/google,zumapro* F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml +F: Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-dtzpc.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml @@ -11181,6 +11182,7 @@ F: drivers/clk/samsung/clk-zumapro.c F: drivers/phy/phy-google-usb.c F: drivers/soc/samsung/gs101-pmu.c F: drivers/phy/samsung/phy-gs101-ufs.c +F: drivers/phy/samsung/phy-zuma-pcie.c F: drivers/phy/samsung/phy-zumapro-ufs.c F: drivers/thermal/samsung/gs101_acpm_tmu.c F: drivers/usb/dwc3/dwc3-google.c diff --git a/drivers/phy/samsung/Kconfig b/drivers/phy/samsung/Kconfig index a9cada8097..f07690fc91 100644 --- a/drivers/phy/samsung/Kconfig +++ b/drivers/phy/samsung/Kconfig @@ -39,6 +39,18 @@ config PHY_GS201_PCIE SoC. It is used by the gs201 PCIe controller driver, which connects the Wi-Fi chip on Pixel 7 phones. +config PHY_ZUMA_PCIE + tristate "Google zuma PCIe PHY driver" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on EXYNOS_PMU || COMPILE_TEST + select GENERIC_PHY + help + Enable support for the one-lane PCIe Gen3 PHY of the Google zuma + (Tensor G3) SoC. It is used by the gs201 PCIe controller driver, + which connects the Wi-Fi chip on Pixel 8 phones. The PHY is + programmed from stock's register tables, and its power-down + isolation is released through the PMU. + config PHY_GS201_MIPI_DCPHY tristate "Google gs201 MIPI DC-PHY receiver driver" depends on OF && (ARCH_EXYNOS || COMPILE_TEST) diff --git a/drivers/phy/samsung/Makefile b/drivers/phy/samsung/Makefile index a24c25524c..56e77422a7 100644 --- a/drivers/phy/samsung/Makefile +++ b/drivers/phy/samsung/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o obj-$(CONFIG_PHY_EXYNOS_PCIE) += phy-exynos-pcie.o obj-$(CONFIG_PHY_GS201_PCIE) += phy-gs201-pcie.o +obj-$(CONFIG_PHY_ZUMA_PCIE) += phy-zuma-pcie.o obj-$(CONFIG_PHY_GS201_MIPI_DCPHY) += phy-gs201-mipi-dcphy-rx.o obj-$(CONFIG_PHY_SAMSUNG_UFS) += phy-exynos-ufs.o phy-exynos-ufs-y += phy-gs101-ufs.o diff --git a/drivers/phy/samsung/phy-zuma-pcie.c b/drivers/phy/samsung/phy-zuma-pcie.c new file mode 100644 index 0000000000..a00239085e --- /dev/null +++ b/drivers/phy/samsung/phy-zuma-pcie.c @@ -0,0 +1,433 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google zuma (Tensor G3) PCIe Gen3 PHY driver + * + * The one-lane PHY of zuma's second PCIe controller (the Wi-Fi chip's). Its + * reference clock comes from an external PLL in the UDBG block, selected in + * the controller's SOC block. The register sequence is Samsung's "CAL ver + * 0.2" for zuma, channel 1, taken from the driver Google builds for zuma + * (pcie-exynos-zuma-rc-cal.c and pcie-exynos-rc.c in google-modules/soc/gs/ + * drivers/pci/controller/dwc). Most PMA registers have no public names, so + * the tables keep Samsung's raw offsets and values. + * + * Copyright (C) 2021 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Bring-up tracing, as in the gs201 PHY driver: with trace=1 every step + * that touches the hardware is logged before it happens, and the driver + * sleeps trace_delay_ms after each line so that a reader of /dev/kmsg + * receives it before a possible bus hang stops the CPU. + */ +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +/* PMU PHY control: bit 0 clear isolates the PHY */ +#define ZUMA_PMU_PHY_BYPASS BIT(0) + +/* PHY reset block, in the controller's sub-control (ELBI) space at +0x1400 */ +#define ZUMA_PHY_RST_CMN 0x0 +#define ZUMA_PHY_RST_INIT 0x4 +#define ZUMA_PHY_RST_PORT 0x8 + +/* SOC block: the PHY's input clock */ +#define ZUMA_SOC_CLK_MODE 0x4000 +#define ZUMA_SOC_CLK_MODE_VAL 0x15 +#define ZUMA_SOC_CLK_SEL 0x4004 +#define ZUMA_SOC_CLK_SEL_TCXO BIT(2) +#define ZUMA_SOC_CLK_SEL_EXT_PLL GENMASK(5, 4) + +/* UDBG block: the external PLL */ +#define ZUMA_UDBG_EXT_PLL 0xc700 +#define ZUMA_UDBG_EXT_PLL_EN BIT(0) +#define ZUMA_UDBG_EXT_PLL_RESETB_OVR BIT(1) +#define ZUMA_UDBG_EXT_PLL_STATUS 0xc734 +#define ZUMA_UDBG_EXT_PLL_LOCK BIT(2) +#define ZUMA_UDBG_LINK_CTRL 0xc800 +#define ZUMA_UDBG_LINK_CTRL_VAL 0x421 + +/* PMA registers used outside the tables */ +#define ZUMA_PMA_CMN_BIAS 0x000c +#define ZUMA_PMA_CLK_CTRL 0x0204 +#define ZUMA_PMA_CLK_CTRL_GATE GENMASK(3, 2) +#define ZUMA_PMA_INPUT_CLK_GATE 0x032c +#define ZUMA_PMA_INPUT_CLK_UNGATE 0x3 +#define ZUMA_PMA_LN_CTRL 0x1350 +#define ZUMA_PMA_PLL_STATUS 0x0a80 +#define ZUMA_PMA_PLL_LOCK BIT(0) +#define ZUMA_PMA_OC_STATUS 0x140c +#define ZUMA_PMA_OC_DONE BIT(7) +#define ZUMA_PMA_CDR_STATUS 0x15c0 +#define ZUMA_PMA_CDR_LOCK BIT(4) + +/* Google polls the lock bits 10000 times, 10 us apart */ +#define ZUMA_PHY_LOCK_TIMEOUT_US 100000 + +struct zuma_pcie_phy_reg { + u16 off; + u32 val; +}; + +/* PHY power-down (exynos_pcie_rc_phy_all_pwrdn(), channel 1), after 0x204 */ +static const struct zuma_pcie_phy_reg zuma_pma_pwrdn[] = { + { 0x1044, 0x2a }, { 0x1048, 0xaa }, { 0x104c, 0xa8 }, { 0x1050, 0x80 }, + { 0x185c, 0x0a }, +}; + +/* Common PMA block */ +static const struct zuma_pcie_phy_reg zuma_pma_common[] = { + { 0x0000, 0x88 }, { 0x001c, 0x66 }, { 0x01f4, 0x00 }, { 0x0514, 0x59 }, + { 0x051c, 0x11 }, { 0x062c, 0x0e }, { 0x0644, 0x22 }, { 0x0688, 0x03 }, + { 0x06d4, 0x28 }, { 0x0788, 0x64 }, { 0x078c, 0x64 }, { 0x0790, 0x50 }, + { 0x0794, 0x50 }, { 0x0944, 0x05 }, { 0x0948, 0x05 }, { 0x094c, 0x05 }, + { 0x0950, 0x05 }, + /* 38.4 MHz REFCLK to the external PLL path */ + { 0x0590, 0x02 }, { 0x07f8, 0xb0 }, { 0x0730, 0x08 }, + /* 7.68 us delay in L1.2 */ + { 0x0344, 0xc0 }, + /* L1.2 without CLKREQ# */ + { 0x0040, 0x04 }, { 0x0204, 0x03 }, { 0x02d4, 0x1f }, { 0x0358, 0x10 }, + /* ERIO on */ + { 0x0018, 0x01 }, + /* Lane */ + { 0x0514, 0x5b }, { 0x0608, 0x0c }, { 0x060c, 0x0f }, { 0x0610, 0x0f }, + { 0x0614, 0x0f }, { 0x0618, 0x0f }, { 0x0510, 0x80 }, { 0x0688, 0x03 }, + { 0x0644, 0x23 }, { 0x0624, 0x11 }, + /* PLL margin for ERIO at Gen1 and Gen2 */ + { 0x0630, 0x0f }, { 0x06d0, 0x53 }, +}; + +/* The lane's PMA block */ +static const struct zuma_pcie_phy_reg zuma_pma_lane[] = { + { 0x1140, 0x04 }, { 0x1144, 0x04 }, { 0x1148, 0x04 }, { 0x114c, 0x02 }, + { 0x1150, 0x00 }, { 0x1154, 0x00 }, { 0x1158, 0x00 }, { 0x115c, 0x00 }, + { 0x12cc, 0x1c }, { 0x12dc, 0x6c }, { 0x130c, 0x29 }, { 0x13b4, 0x2f }, + { 0x1a64, 0x05 }, { 0x1a68, 0x05 }, { 0x1a84, 0x05 }, { 0x1a88, 0x05 }, + { 0x1a98, 0x00 }, { 0x1a9c, 0x00 }, { 0x1aa8, 0x07 }, { 0x1ab8, 0x00 }, + { 0x1abc, 0x00 }, { 0x1af8, 0x90 }, { 0x1b34, 0x03 }, { 0x1bb0, 0x03 }, + { 0x1bb4, 0x03 }, { 0x1bc0, 0x06 }, { 0x1bc4, 0x06 }, { 0x1be8, 0x01 }, + { 0x1bf8, 0x04 }, { 0x1c98, 0x00 }, { 0x1ca4, 0x81 }, + /* + * Broadcom Wi-Fi (stock's ep-device-type 1): the link went down on + * L1 substate exits without these. + */ + { 0x1b20, 0x02 }, { 0x1340, 0x23 }, { 0x002c, 0x3c }, +}; + +/* PCS, with Google's Broadcom Wi-Fi timer values */ +static const struct zuma_pcie_phy_reg zuma_pcs[] = { + { 0x190, 0x100b0604 }, + /* L1.2 without CLKREQ# */ + { 0x154, 0x000700d5 }, + { 0x100, 0x16400000 }, { 0x104, 0x08600000 }, { 0x114, 0x18500000 }, + { 0x124, 0x60700000 }, { 0x174, 0x00000007 }, { 0x178, 0x00000100 }, + { 0x17c, 0x00000700 }, { 0x110, 0x01600202 }, +}; + +struct zuma_pcie_phy { + struct device *dev; + void __iomem *pma; + void __iomem *pcs; + void __iomem *rst; + void __iomem *udbg; + void __iomem *soc; + struct regmap *pmu; + u32 pmu_offset; +}; + +static __printf(2, 3) void zuma_phy_trace(struct zuma_pcie_phy *zp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(zp->dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static void zuma_pcie_phy_write_table(void __iomem *base, + const struct zuma_pcie_phy_reg *tbl, + size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + writel(tbl[i].val, base + tbl[i].off); +} + +static void zuma_pcie_phy_rmw(void __iomem *reg, u32 clr, u32 set) +{ + writel((readl(reg) & ~clr) | set, reg); +} + +static bool zuma_pcie_phy_wait(struct zuma_pcie_phy *zp, const char *what, + void __iomem *base, u32 off, u32 bit) +{ + u32 val; + + zuma_phy_trace(zp, "about to poll %#x for %s (up to %u us)", off, what, + ZUMA_PHY_LOCK_TIMEOUT_US); + + return !readl_poll_timeout_atomic(base + off, val, val & bit, 10, + ZUMA_PHY_LOCK_TIMEOUT_US); +} + +/* exynos_pcie_rc_phy_all_pwrdn(), channel 1 */ +static void zuma_pcie_phy_pwrdn(struct zuma_pcie_phy *zp) +{ + zuma_phy_trace(zp, "about to read PMA 0x204 (first PMA access) and power the PHY down"); + zuma_pcie_phy_rmw(zp->pma + ZUMA_PMA_CLK_CTRL, ZUMA_PMA_CLK_CTRL_GATE, 0); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_pwrdn, + ARRAY_SIZE(zuma_pma_pwrdn)); + udelay(1); + writel(0xff, zp->pma + 0x0208); + udelay(1); + writel(0x0a, zp->pma + 0x0580); + writel(0xaa, zp->pma + 0x0928); + /* Common bias and PLL off */ + writel(0x0a, zp->pma + ZUMA_PMA_CMN_BIAS); + fsleep(50); + + zuma_phy_trace(zp, "about to read UDBG 0xc700 (first UDBG access): gate the external PLL"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, ZUMA_UDBG_EXT_PLL_EN, 0); + fsleep(10); +} + +/* exynos_pcie_rc_phy_all_pwrdn_clear(), channel 1 */ +static void zuma_pcie_phy_pwrdn_clear(struct zuma_pcie_phy *zp) +{ + size_t i; + + zuma_phy_trace(zp, "about to ungate the external PLL (UDBG 0xc700) and clear the power-downs"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, ZUMA_UDBG_EXT_PLL_EN); + fsleep(100); + writel(0x00, zp->pma + ZUMA_PMA_CMN_BIAS); + writel(0x55, zp->pma + 0x0928); + writel(0x02, zp->pma + 0x0580); + writel(0x00, zp->pma + 0x0208); + for (i = 0; i < ARRAY_SIZE(zuma_pma_pwrdn); i++) + writel(0, zp->pma + zuma_pma_pwrdn[i].off); + fsleep(10); +} + +/* exynos_pcie_rc_pcie_phy_config(), channel 1, less its ELBI writes */ +static void zuma_pcie_phy_config(struct zuma_pcie_phy *zp) +{ + bool pll, cdr, oc, ext; + + zuma_phy_trace(zp, "about to ungate the PHY input clock (PMA 0x32c) and start the external PLL"); + writel(ZUMA_PMA_INPUT_CLK_UNGATE, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, ZUMA_UDBG_EXT_PLL_EN); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, + ZUMA_UDBG_EXT_PLL_RESETB_OVR, 0); + + ext = zuma_pcie_phy_wait(zp, "the external PLL lock", zp->udbg, + ZUMA_UDBG_EXT_PLL_STATUS, + ZUMA_UDBG_EXT_PLL_LOCK); + + zuma_phy_trace(zp, "about to select the external PLL as the PHY input clock (SOC 0x4004)"); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_SEL, ZUMA_SOC_CLK_SEL_TCXO, 0); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_SEL, 0, + ZUMA_SOC_CLK_SEL_EXT_PLL); + + zuma_phy_trace(zp, "about to assert the PMA resets (ELBI 0x1400-0x1408)"); + writel(1, zp->rst + ZUMA_PHY_RST_INIT); + writel(1, zp->rst + ZUMA_PHY_RST_PORT); + writel(1, zp->rst + ZUMA_PHY_RST_CMN); + writel(0, zp->rst + ZUMA_PHY_RST_INIT); + writel(0, zp->rst + ZUMA_PHY_RST_PORT); + writel(0, zp->rst + ZUMA_PHY_RST_CMN); + + zuma_phy_trace(zp, "about to write the PMA tables (common, lane)"); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_common, + ARRAY_SIZE(zuma_pma_common)); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_lane, + ARRAY_SIZE(zuma_pma_lane)); + zuma_pcie_phy_rmw(zp->pma + ZUMA_PMA_LN_CTRL, 0, BIT(0)); + + zuma_phy_trace(zp, "about to write the PCS table"); + zuma_pcie_phy_write_table(zp->pcs, zuma_pcs, ARRAY_SIZE(zuma_pcs)); + + zuma_phy_trace(zp, "about to release the PMA resets"); + writel(1, zp->rst + ZUMA_PHY_RST_INIT); + fsleep(10); + writel(1, zp->rst + ZUMA_PHY_RST_PORT); + writel(1, zp->rst + ZUMA_PHY_RST_CMN); + + pll = zuma_pcie_phy_wait(zp, "PLL lock", zp->pma, ZUMA_PMA_PLL_STATUS, + ZUMA_PMA_PLL_LOCK); + cdr = zuma_pcie_phy_wait(zp, "CDR lock", zp->pma, ZUMA_PMA_CDR_STATUS, + ZUMA_PMA_CDR_LOCK); + oc = zuma_pcie_phy_wait(zp, "offset calibration", zp->pma, + ZUMA_PMA_OC_STATUS, ZUMA_PMA_OC_DONE); + + dev_info(zp->dev, + "external PLL lock %d, PLL lock %d, CDR lock %d, OC done %d\n", + ext, pll, cdr, oc); + + writel(0, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); +} + +static int zuma_pcie_phy_init(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + unsigned int val; + int ret; + + ret = regmap_read(zp->pmu, zp->pmu_offset, &val); + if (ret) { + dev_err(zp->dev, "PMU read failed: %d\n", ret); + return ret; + } + dev_info(zp->dev, "PMU PHY control %#x\n", val); + + zuma_phy_trace(zp, "about to set PMU %#x bit 0 (PHY isolation off, SMC)", + zp->pmu_offset); + ret = regmap_update_bits(zp->pmu, zp->pmu_offset, ZUMA_PMU_PHY_BYPASS, + ZUMA_PMU_PHY_BYPASS); + if (ret) { + dev_err(zp->dev, "PMU write failed: %d\n", ret); + return ret; + } + + zuma_pcie_phy_pwrdn(zp); + zuma_phy_trace(zp, "PHY out of isolation and powered down"); + + return 0; +} + +static int zuma_pcie_phy_power_on(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_phy_trace(zp, "about to write SOC 0x4000 (first SOC access)"); + writel(ZUMA_SOC_CLK_MODE_VAL, zp->soc + ZUMA_SOC_CLK_MODE); + + zuma_pcie_phy_pwrdn_clear(zp); + zuma_pcie_phy_config(zp); + + /* exynos_pcie_rc_establish_link(), channel 1, before PERST# */ + zuma_phy_trace(zp, "about to write UDBG 0xc800"); + writel(ZUMA_UDBG_LINK_CTRL_VAL, zp->udbg + ZUMA_UDBG_LINK_CTRL); + zuma_phy_trace(zp, "PHY configured"); + + return 0; +} + +static int zuma_pcie_phy_power_off(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_pcie_phy_pwrdn(zp); + + return 0; +} + +static const struct phy_ops zuma_pcie_phy_ops = { + .init = zuma_pcie_phy_init, + .power_on = zuma_pcie_phy_power_on, + .power_off = zuma_pcie_phy_power_off, + .owner = THIS_MODULE, +}; + +static int zuma_pcie_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *provider; + struct zuma_pcie_phy *zp; + struct phy *phy; + int ret; + + zp = devm_kzalloc(dev, sizeof(*zp), GFP_KERNEL); + if (!zp) + return -ENOMEM; + + zp->dev = dev; + + /* Only mappings here: the PHY is not touched until phy_init() */ + zp->pma = devm_platform_ioremap_resource_byname(pdev, "pma"); + if (IS_ERR(zp->pma)) + return PTR_ERR(zp->pma); + + zp->pcs = devm_platform_ioremap_resource_byname(pdev, "pcs"); + if (IS_ERR(zp->pcs)) + return PTR_ERR(zp->pcs); + + zp->rst = devm_platform_ioremap_resource_byname(pdev, "rst"); + if (IS_ERR(zp->rst)) + return PTR_ERR(zp->rst); + + zp->udbg = devm_platform_ioremap_resource_byname(pdev, "udbg"); + if (IS_ERR(zp->udbg)) + return PTR_ERR(zp->udbg); + + zp->soc = devm_platform_ioremap_resource_byname(pdev, "soc"); + if (IS_ERR(zp->soc)) + return PTR_ERR(zp->soc); + + zp->pmu = exynos_get_pmu_regmap_by_phandle(dev->of_node, + "samsung,pmu-syscon"); + if (IS_ERR(zp->pmu)) + return dev_err_probe(dev, PTR_ERR(zp->pmu), + "failed to get the PMU regmap\n"); + + ret = of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1, + &zp->pmu_offset); + if (ret) + return dev_err_probe(dev, ret, + "missing PMU PHY control offset\n"); + + phy = devm_phy_create(dev, NULL, &zuma_pcie_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY\n"); + + phy_set_drvdata(phy, zp); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id zuma_pcie_phy_of_match[] = { + { .compatible = "google,zuma-pcie-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, zuma_pcie_phy_of_match); + +static struct platform_driver zuma_pcie_phy_driver = { + .probe = zuma_pcie_phy_probe, + .driver = { + .name = "zuma-pcie-phy", + .of_match_table = zuma_pcie_phy_of_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(zuma_pcie_phy_driver); + +MODULE_DESCRIPTION("Google zuma PCIe Gen3 PHY driver"); +MODULE_LICENSE("GPL"); From 668c25f8bd2680ec1e82579959bf1b86ae7666ed Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:21 -0400 Subject: [PATCH 59/75] dt-bindings: PCI: google,gs201-pcie: Add the zuma controller zuma's (Tensor G3) PCIe controllers are the same DesignWare core in the same Samsung wrapper as gs201's, at IP version 0x986500. Its Wi-Fi controller runs without the I/A sequencer, as on stock (use-ia false), so it has three register regions. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../bindings/pci/google,gs201-pcie.yaml | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml index 89e65f2a1f..d967492b9f 100644 --- a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml @@ -4,26 +4,40 @@ $id: http://devicetree.org/schemas/pci/google,gs201-pcie.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 PCIe host controller +title: Google gs201 and zuma PCIe host controllers maintainers: - Derek Ross description: - The PCIe controllers of the Google gs201 (Tensor G2) SoC are Synopsys - DesignWare cores (IP version 0x984500) in a Samsung wrapper. The wrapper + The PCIe controllers of the Google gs201 (Tensor G2) and zuma (Tensor G3) + SoCs are Synopsys DesignWare cores (IP versions 0x984500 and 0x986500) in + a Samsung wrapper. The wrapper adds a sub-control block (ELBI) with link training control and interrupt status, and an I/A sequencer that re-locks the PHY clock-data recovery when - the link leaves L1.2. Legacy INTx interrupts are demultiplexed from the - controller interrupt by a child interrupt controller. + the link leaves L1.2. zuma's Wi-Fi controller runs without the I/A, as on + stock. Legacy INTx interrupts are demultiplexed from the controller + interrupt by a child interrupt controller. allOf: - $ref: /schemas/pci/pci-host-bridge.yaml# - $ref: /schemas/pci/snps,dw-pcie-common.yaml# + - if: + properties: + compatible: + const: google,zuma-pcie + then: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 properties: compatible: - const: google,gs201-pcie + enum: + - google,gs201-pcie + - google,zuma-pcie reg: minItems: 3 From 9527c85ee14c65bf824560bc15a00ba33efe2c70 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:21 -0400 Subject: [PATCH 60/75] PCI: dwc: gs201: Add zuma zuma's (Tensor G3) Wi-Fi controller follows gs201's sequence, with one difference in order: zuma's CAL sets RC mode, pulses the soft power reset and enables the slave pending NAK in the middle of the PHY configuration, and establish_link() does not reset the controller again afterwards. Do these before the PHY's power_on on zuma, and skip the later soft resets. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/pci/controller/dwc/Kconfig | 7 +-- drivers/pci/controller/dwc/pcie-gs201.c | 58 +++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index 3a3f5b8b6a..5697af1a14 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -411,9 +411,10 @@ config PCIE_GS201 select PCI_PWRCTRL_GENERIC help Say Y here to enable support for the PCIe controller of the Google - gs201 (Tensor G2) SoC in host mode. Pixel 7 phones connect their - Wi-Fi chip to it. The controller uses the DesignWare core plus a - Samsung wrapper, and needs the gs201 PCIe PHY driver. + gs201 (Tensor G2) and zuma (Tensor G3) SoCs in host mode. Pixel 7 + and Pixel 8 phones connect their Wi-Fi chip to it. The controller + uses the DesignWare core plus a Samsung wrapper, and needs the gs201 + or zuma PCIe PHY driver. config PCIE_GS201_SYSMMU tristate "Google gs201 PCIe System MMU as a DMA window" diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c index af650d7638..98238660b2 100644 --- a/drivers/pci/controller/dwc/pcie-gs201.c +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * PCIe host controller driver for the Google gs201 (Tensor G2) SoC + * PCIe host controller driver for the Google gs201 (Tensor G2) and zuma + * (Tensor G3) SoCs * * The controller is a Synopsys DesignWare core (IP version 0x984500) in a * Samsung wrapper ("ELBI" sub-control registers, a link-training helper @@ -69,9 +70,11 @@ #define GS201_ELBI_SOFT_RESET 0x3a4 #define GS201_ELBI_SOFT_PWR_RESET BIT(1) #define GS201_ELBI_SOFT_NON_STICKY_RESET BIT(3) +#define GS201_ELBI_SOFT_RESET_ALL GENMASK(3, 0) #define GS201_ELBI_QCH_SEL 0x3a8 #define GS201_ELBI_QCH_GATING_MASK GENMASK(11, 0) #define GS201_ELBI_REQ_EXIT_L1_MODE 0x3bc +#define GS201_ELBI_SLV_PEND_SEL_NAK 0x3d8 #define GS201_ELBI_APP_REQ_EXIT_L1_MODE BIT(0) #define GS201_ELBI_L1_REQ_NAK_MASTER BIT(4) #define GS201_ELBI_MSTR_PEND_SEL_NAK 0x474 @@ -163,8 +166,20 @@ module_param(cmu_acg_off, bool, 0444); MODULE_PARM_DESC(cmu_acg_off, "Clear CMU_HSI2 automatic clock gating in stage 1, as Google's gs201 driver does (default: false)"); +/** + * struct gs201_pcie_soc_data - what differs between the SoCs + * @ctrl_reset_before_phy: the controller's soft power reset and RC mode are + * set before the PHY configuration, and not again after it. zuma's + * CAL does them in the middle of its PHY configuration; gs201's + * establish_link() does them after. + */ +struct gs201_pcie_soc_data { + bool ctrl_reset_before_phy; +}; + struct gs201_pcie { struct dw_pcie pci; + const struct gs201_pcie_soc_data *data; void __iomem *elbi; void __iomem *ia; void __iomem *cmu; @@ -569,11 +584,33 @@ static int gs201_pcie_stage_wake(struct gs201_pcie *gp) return 0; } +/* + * zuma's CAL: RC mode and a soft power reset pulse, written as whole words + * as Google does, and NAKs for slave requests while AXI is pending. + */ +static void gs201_pcie_ctrl_reset_early(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to write ELBI 0x080 = 4 (root complex) and pulse the soft power reset (ELBI 0x3a4)"); + gs201_elbi_writel(gp, GS201_ELBI_DEVICE_TYPE, GS201_ELBI_DEVICE_TYPE_RC); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, GS201_ELBI_SOFT_RESET_ALL); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + GS201_ELBI_SOFT_RESET_ALL & ~GS201_ELBI_SOFT_PWR_RESET); + fsleep(10); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, GS201_ELBI_SOFT_RESET_ALL); + fsleep(10); + + gs201_trace(gp, "about to write ELBI 0x3d8 = 1 (slave pending NAK)"); + gs201_elbi_writel(gp, GS201_ELBI_SLV_PEND_SEL_NAK, 1); +} + /* Stage 3: Google's PHY configuration, then the I/A sequencer */ static int gs201_pcie_stage_phy(struct gs201_pcie *gp) { int ret; + if (gp->data->ctrl_reset_before_phy) + gs201_pcie_ctrl_reset_early(gp); + gs201_trace(gp, "phy_power_on: power-down clear, CAL table, lock checks"); ret = phy_power_on(gp->phy); if (ret) @@ -607,6 +644,9 @@ static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) struct device *dev = gp->pci.dev; u32 val; + if (gp->data->ctrl_reset_before_phy) + goto perst; + gs201_trace(gp, "about to pulse the soft power reset (ELBI 0x3a4 bit 1)"); val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, @@ -631,8 +671,9 @@ static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, val | GS201_ELBI_SOFT_NON_STICKY_RESET); +perst: if (release_perst) { - gs201_trace(gp, "about to release PERST# (gph2-0) and wait 20 ms"); + gs201_trace(gp, "about to release PERST# and wait 20 ms"); gpiod_set_value_cansleep(gp->perst, 0); fsleep(GS201_PERST_DELAY_US); } @@ -818,7 +859,7 @@ static int gs201_pcie_host_init(struct dw_pcie_rp *pp) } if (!pp->skip_pwrctrl_off) { - gs201_trace(gp, "about to power the endpoint (WL_REG_ON, gph2-4, 200 ms)"); + gs201_trace(gp, "about to power the endpoint (WL_REG_ON and its startup delay)"); ret = pci_pwrctrl_power_on_devices(dev); if (ret) goto err_pwrctrl_destroy; @@ -1101,6 +1142,7 @@ static int gs201_pcie_probe(struct platform_device *pdev) return -ENOMEM; raw_spin_lock_init(&gp->lock); + gp->data = of_device_get_match_data(dev); pci = &gp->pci; pci->dev = dev; @@ -1186,8 +1228,16 @@ static void gs201_pcie_remove(struct platform_device *pdev) gs201_pcie_remove_irq(gp); } +static const struct gs201_pcie_soc_data gs201_pcie_data = { +}; + +static const struct gs201_pcie_soc_data zuma_pcie_data = { + .ctrl_reset_before_phy = true, +}; + static const struct of_device_id gs201_pcie_of_match[] = { - { .compatible = "google,gs201-pcie" }, + { .compatible = "google,gs201-pcie", .data = &gs201_pcie_data }, + { .compatible = "google,zuma-pcie", .data = &zuma_pcie_data }, { } }; MODULE_DEVICE_TABLE(of, gs201_pcie_of_match); From 4cd429e335ee0546a350a0139142068a6f1608ab Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:31 -0400 Subject: [PATCH 61/75] arm64: dts: exynos: google: zuma: add the Wi-Fi PCIe controller and PHY Add zuma's second PCIe controller (stock's pcie_1, ch-num 1) and its Gen3 PHY, disabled, at the addresses of stock's pcie@13120000: one lane, Gen3, PERST# on gph3-0 and CLKREQ# on gph3-1 with stock's pin settings, and the PHY's isolation at PMU offset 0x3ec8. Legacy INTx is demultiplexed from the controller's interrupt (SPI 439). As on stock, the controller is not cache coherent and runs without the I/A. Its memory window and config space are at 0x60000000, so the soc bus now maps the first 2 GiB, as on gs201. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../boot/dts/exynos/google/zuma-pinctrl.dtsi | 17 ++++++ arch/arm64/boot/dts/exynos/google/zuma.dtsi | 56 ++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 4b4162ec44..92c5bbcd64 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -470,6 +470,23 @@ interrupt-controller; #interrupt-cells = <2>; }; + + pcie1_clkreq: pcie1-clkreq-pins { + samsung,pins = "gph3-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; + + pcie1_perst: pcie1-perst-pins { + samsung,pins = "gph3-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + }; }; &pinctrl_hsi2ufs { diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index 3fb6ccd1e0..88f0dbeeea 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -304,7 +305,8 @@ compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; - ranges = <0x0 0x0 0x0 0x40000000>; + /* Registers below 1 GiB, PCIe windows at 0x40000000-0x7fffffff */ + ranges = <0x0 0x0 0x0 0x80000000>; /* * ABL hands over with both cluster watchdogs counting (30 s); @@ -467,6 +469,58 @@ interrupts = ; }; + /* + * The Wi-Fi chip's controller (stock's pcie_1, ch-num 1): one + * Gen3 lane, at the addresses of stock's pcie@13120000. Its + * interrupts are its legacy INTx; stock's MSI lines are unused. + */ + pcie_1: pcie@13120000 { + compatible = "google,zuma-pcie"; + reg = <0x13120000 0x1400>, + <0x13400000 0x381000>, + <0x60ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x60000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = ; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_1_intc 1>, + <0 0 0 2 &pcie_1_intc 2>, + <0 0 0 3 &pcie_1_intc 3>, + <0 0 0 4 &pcie_1_intc 4>; + phys = <&pcie_1_phy>; + phy-names = "pcie"; + pinctrl-0 = <&pcie1_clkreq>, <&pcie1_perst>; + pinctrl-names = "default"; + reset-gpios = <&gph3 0 GPIO_ACTIVE_LOW>; + num-lanes = <1>; + max-link-speed = <3>; + status = "disabled"; + + pcie_1_intc: legacy-interrupt-controller { + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + + pcie_1_phy: phy@13160000 { + compatible = "google,zuma-pcie-phy"; + reg = <0x13160000 0x3000>, + <0x13140000 0x5000>, + <0x13121400 0x10>, + <0x13150000 0xd000>, + <0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + status = "disabled"; + }; + ufs_0: ufs@13200000 { compatible = "google,zuma-ufs", "google,zumapro-ufs"; reg = <0x13200000 0x200>, From e5d7406a544e57ef0cfe0aaa36d564626339ba35 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:09 -0400 Subject: [PATCH 62/75] wifi: brcmfmac: chip: support the NCI backplane The BCM4398 (Pixel 8 Pro) reports backplane type 6, NCI ("Booker"), which brcmfmac rejected ("chip backplane type 6 is not supported"). On NCI, chipcommon's eromptr points at EROM2, a list of interface descriptors grouped by core. Each core's info word and interface count sit in EROM1 or in the OOB router (OOBR); OOBR cores also have a DMP control word that takes the clock and core flags the AI backplane keeps in the wrapper's ioctrl. Each interface is a network interface (NI) node with its own reset control. Scan that into brcmfmac's core list (the base is a core's APB slave, or a bridge's own slave; the wrapper its first Booker interface) and implement iscoreup, coredisable and resetcore on it, after Broadcom's GPL bcmdhd (nciutils.c, hal_nci_cmn.h, hndoobr.h). An APB NI shared by several cores is left out of a core's reset. Read the CA7's halt bit from its DMP control word, and start a halted CA7 by clearing that bit only, as bcmdhd does for NCI chips (dhdpcie_bus_download_state()): resetting it again keeps a second firmware download from starting. On the Pixel 8 Pro the scan finds 46 cores, and the RAM base and size and chipcommon revision match bcmdhd's. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/chip.c | 315 +++++++++++++++++- 1 file changed, 312 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index d0fed7b6a4..c7278d2503 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c @@ -2,6 +2,7 @@ /* * Copyright (c) 2014 Broadcom Corporation */ +#include #include #include #include @@ -20,6 +21,7 @@ /* SOC Interconnect types (aka chip types) */ #define SOCI_SB 0 #define SOCI_AI 1 +#define SOCI_NCI 6 /* PL-368 DMP definitions */ #define DMP_DESC_TYPE_MSK 0x0000000F @@ -229,11 +231,60 @@ struct sbsocramregs { #define ARMCR4_BSZ_MULT 8192 #define ARMCR4_BLK_1K_MASK 0x200 +/* + * NCI ("Booker") backplane, as on the BCM4398. Chipcommon's eromptr points + * at EROM2, a list of interface descriptors grouped by core. Each core's + * info word and interface count sit either in EROM1 (just below EROM2) or + * in the OOB router (OOBR, at the 8 KiB boundary below it); OOBR cores also + * have a DMP control word, which takes the clock and core flags that the AI + * backplane keeps in the wrapper's ioctrl. Each interface is a network + * interface (NI) node with its own reset control. Register layout from + * Broadcom's GPL bcmdhd (nciutils.c, hal_nci_cmn.h, hndoobr.h). + */ +#define NCI_OOBR_BASE(erom2) ((erom2) & ~0x1fffU) +#define NCI_EROM1_BASE(erom2) ((erom2) & ~0xfffU) +#define NCI_OOBR_CAP 0x0 +#define NCI_OOBR_CAP_CORECNT 0x1f +#define NCI_CI_COREID GENMASK(11, 0) +#define NCI_CI_REV GENMASK(19, 12) +#define NCI_CI_ISBP BIT(27) +#define NCI_IC_IFACECNT GENMASK(15, 12) +#define NCI_ID0_NODEPTR GENMASK(31, 3) +#define NCI_ID1_WORDOFFSET GENMASK(31, 28) +#define NCI_ID1_EROM1 BIT(27) +#define NCI_ID1_MASTER BIT(26) +#define NCI_ID1_NADDR GENMASK(25, 24) +#define NCI_ID1_BPID GENMASK(23, 20) +#define NCI_ID1_COREPTR GENMASK(12, 0) +#define NCI_BPID_BOOKER 0 +#define NCI_BPID_PMNI_FIRST 2 +#define NCI_BPID_PMNI_LAST 8 +#define NCI_SP_BASE GENMASK(31, 8) +#define NCI_SP_BOUND BIT(6) +#define NCI_SP_64BIT BIT(5) +#define NCI_EROM_END 0xffffffff +#define NCI_DMPCTRL 0x8 +#define NCI_NI_RESET_CTL 0x140 +#define NCI_NI_RESET_ENTRY BIT(0) +#define NCI_MAX_IFACES 16 +#define NCI_RESET_TIMEOUT_US 5000 + +struct brcmf_nci_iface { + u32 node; + bool booker; + bool pmni; + bool shared; +}; + struct brcmf_core_priv { struct brcmf_core pub; u32 wrapbase; struct list_head list; struct brcmf_chip_priv *chip; + /* NCI only: the DMP control word (0 if none) and the NI nodes */ + u32 dmpctrl; + u8 nifaces; + struct brcmf_nci_iface ifaces[NCI_MAX_IFACES]; }; struct brcmf_chip_priv { @@ -505,6 +556,96 @@ static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset, } } +/* Update the DMP control word, which holds the AI ioctrl bits on NCI */ +static void brcmf_chip_nci_cflags(struct brcmf_core_priv *core, u32 mask, + u32 val) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 regdata; + + if (!core->dmpctrl) + return; + + regdata = ci->ops->read32(ci->ctx, core->dmpctrl); + ci->ops->write32(ci->ctx, core->dmpctrl, (regdata & ~mask) | val); + ci->ops->read32(ci->ctx, core->dmpctrl); +} + +/* Put each of the core's own NI nodes into reset, or take them out */ +static void brcmf_chip_nci_reset_ifaces(struct brcmf_core_priv *core, + bool reset) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 addr, regdata; + int i, us; + + for (i = core->nifaces - 1; i >= 0; i--) { + if (core->ifaces[i].shared || !core->ifaces[i].node) + continue; + + addr = core->ifaces[i].node + NCI_NI_RESET_CTL; + regdata = ci->ops->read32(ci->ctx, addr); + if (reset) + regdata |= NCI_NI_RESET_ENTRY; + else + regdata &= ~NCI_NI_RESET_ENTRY; + ci->ops->write32(ci->ctx, addr, regdata); + + for (us = 0; us < NCI_RESET_TIMEOUT_US; us += 10) { + regdata = ci->ops->read32(ci->ctx, addr); + if (!!(regdata & NCI_NI_RESET_ENTRY) == reset) + break; + udelay(10); + } + if (us >= NCI_RESET_TIMEOUT_US) + brcmf_err("core %#x: NI %#x reset %d timed out (%#x)\n", + core->pub.id, core->ifaces[i].node, reset, + regdata); + } +} + +static bool brcmf_chip_nci_iscoreup(struct brcmf_core_priv *core) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 regdata; + + if (!core->wrapbase) + return true; + + regdata = ci->ops->read32(ci->ctx, core->wrapbase + NCI_NI_RESET_CTL); + + return !(regdata & NCI_NI_RESET_ENTRY); +} + +/* bcmdhd's nci_core_reset_enable(), less the final release */ +static void brcmf_chip_nci_coredisable(struct brcmf_core_priv *core, + u32 prereset, u32 reset) +{ + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, 0); + udelay(1); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), + prereset); + brcmf_chip_nci_reset_ifaces(core, true); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), reset); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_CLK, BCMA_IOCTL_CLK); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, BCMA_IOCTL_FGC); + udelay(1); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, 0); +} + +static void brcmf_chip_nci_resetcore(struct brcmf_core_priv *core, + u32 prereset, u32 reset, u32 postreset) +{ + brcmf_chip_nci_coredisable(core, prereset, reset); + brcmf_chip_nci_reset_ifaces(core, false); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), + postreset); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_CLK, BCMA_IOCTL_CLK); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, BCMA_IOCTL_FGC); + udelay(1); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, 0); +} + char *brcmf_chip_name(u32 id, u32 rev, char *buf, uint len) { const char *fmt; @@ -1004,6 +1145,148 @@ int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci) return 0; } +/* Skip a slave interface's address descriptors; return the core's base */ +static u32 brcmf_chip_nci_slave_addrs(struct brcmf_chip_priv *ci, u32 *addr, + u32 naddr) +{ + u32 adesc, base = 0; + u32 i; + + for (i = 0; i < naddr; i++) { + adesc = ci->ops->read32(ci->ctx, *addr); + *addr += 4; + if (i == 0) + base = adesc & NCI_SP_BASE; + if (adesc & NCI_SP_64BIT) + *addr += 12; /* base high, bound low and high */ + else if (adesc & NCI_SP_BOUND) + *addr += 4; /* bound */ + } + + return base; +} + +/* An APB NI that several cores share is not one core's to reset */ +static void brcmf_chip_nci_mark_shared(struct brcmf_chip_priv *ci) +{ + struct brcmf_core_priv *a, *b; + int i, j; + + list_for_each_entry(a, &ci->cores, list) { + for (i = 0; i < a->nifaces; i++) { + if (!a->ifaces[i].pmni || !a->ifaces[i].node) + continue; + list_for_each_entry(b, &ci->cores, list) { + if (b == a) + continue; + for (j = 0; j < b->nifaces; j++) + if (b->ifaces[j].pmni && + b->ifaces[j].node == a->ifaces[i].node) + a->ifaces[i].shared = true; + } + } + } +} + +static int brcmf_chip_nci_erom_scan(struct brcmf_chip_priv *ci) +{ + u32 erom2, erom1, oobr, addr, ptr, coreinfo, ifcfg, desc0, desc1; + u32 ncores, base, wordoffset, naddr; + struct brcmf_core_priv *core; + struct brcmf_core *pub; + u8 i, nifaces; + u16 id; + + erom2 = ci->ops->read32(ci->ctx, + CORE_CC_REG(ci->pub.enum_base, eromptr)); + erom1 = NCI_EROM1_BASE(erom2); + oobr = NCI_OOBR_BASE(erom2); + ncores = (erom2 - erom1) / 8 + + (ci->ops->read32(ci->ctx, oobr + NCI_OOBR_CAP) & + NCI_OOBR_CAP_CORECNT); + brcmf_dbg(INFO, "NCI: EROM2 %#x, EROM1 %#x, OOBR %#x, %u cores\n", + erom2, erom1, oobr, ncores); + + addr = erom2; + while (ci->num_cores < ncores) { + desc0 = ci->ops->read32(ci->ctx, addr); + if (desc0 == NCI_EROM_END) + break; + + /* The first interface's second word locates the core info */ + desc1 = ci->ops->read32(ci->ctx, addr + 4); + ptr = FIELD_GET(NCI_ID1_COREPTR, desc1); + ptr += (desc1 & NCI_ID1_EROM1) ? erom1 : oobr; + coreinfo = ci->ops->read32(ci->ctx, ptr); + ifcfg = ci->ops->read32(ci->ctx, ptr + 4); + + id = FIELD_GET(NCI_CI_COREID, coreinfo); + if (id < 0xff) + id |= 0x800; /* Broadcom's cores */ + nifaces = FIELD_GET(NCI_IC_IFACECNT, ifcfg); + if (nifaces > NCI_MAX_IFACES) { + brcmf_err("NCI: core %#x has %u interfaces\n", id, + nifaces); + return -EFAULT; + } + + pub = brcmf_chip_add_core(ci, id, 0, 0); + if (IS_ERR(pub)) + return PTR_ERR(pub); + ci->num_cores++; + pub->rev = FIELD_GET(NCI_CI_REV, coreinfo); + core = container_of(pub, struct brcmf_core_priv, pub); + if (!(desc1 & NCI_ID1_EROM1)) + core->dmpctrl = ptr + NCI_DMPCTRL; + core->nifaces = nifaces; + + wordoffset = 0; + for (i = 0; i < nifaces; i++) { + struct brcmf_nci_iface *ifc = &core->ifaces[i]; + u8 bpid; + + desc0 = ci->ops->read32(ci->ctx, addr); + desc1 = ci->ops->read32(ci->ctx, addr + 4); + addr += 8; + + bpid = FIELD_GET(NCI_ID1_BPID, desc1); + ifc->node = desc0 & NCI_ID0_NODEPTR; + ifc->booker = bpid == NCI_BPID_BOOKER; + ifc->pmni = !(desc1 & NCI_ID1_MASTER) && + bpid >= NCI_BPID_PMNI_FIRST && + bpid <= NCI_BPID_PMNI_LAST; + wordoffset = FIELD_GET(NCI_ID1_WORDOFFSET, desc1); + + if (desc1 & NCI_ID1_MASTER) + continue; + + naddr = FIELD_GET(NCI_ID1_NADDR, desc1) + 1; + base = brcmf_chip_nci_slave_addrs(ci, &addr, naddr); + /* Registers: the APB slave, or a bridge's own slave */ + if (!pub->base && (ifc->pmni || (coreinfo & NCI_CI_ISBP))) + pub->base = base; + } + + /* The first Booker interface is the core's wrapper */ + for (i = 0; i < nifaces; i++) + if (core->ifaces[i].booker) { + core->wrapbase = core->ifaces[i].node; + break; + } + + brcmf_dbg(INFO, "NCI: core %#x rev %u base %#x wrap %#x dmpctrl %#x, %u interfaces\n", + pub->id, pub->rev, pub->base, core->wrapbase, + core->dmpctrl, nifaces); + + if (!wordoffset) + break; + } + + brcmf_chip_nci_mark_shared(ci); + + return 0; +} + u32 brcmf_chip_enum_base(u16 devid) { return SI_ENUM_BASE_DEFAULT; @@ -1036,7 +1319,8 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci) brcmf_chip_name(ci->pub.chip, ci->pub.chiprev, ci->pub.name, sizeof(ci->pub.name)); brcmf_dbg(INFO, "found %s chip: %s\n", - socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name); + socitype == SOCI_SB ? "SB" : socitype == SOCI_NCI ? "NCI" : "AXI", + ci->pub.name); if (socitype == SOCI_SB) { if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) { @@ -1083,6 +1367,14 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci) ci->resetcore = brcmf_chip_ai_resetcore; brcmf_chip_dmp_erom_scan(ci); + } else if (socitype == SOCI_NCI) { + ci->iscoreup = brcmf_chip_nci_iscoreup; + ci->coredisable = brcmf_chip_nci_coredisable; + ci->resetcore = brcmf_chip_nci_resetcore; + + ret = brcmf_chip_nci_erom_scan(ci); + if (ret) + return ret; } else { brcmf_err("chip backplane type %u is not supported\n", socitype); @@ -1126,8 +1418,13 @@ static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id) case BCMA_CORE_ARM_CA7: cpu = container_of(core, struct brcmf_core_priv, pub); - /* clear all IOCTL bits except HALT bit */ - val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL); + /* clear all IOCTL bits except HALT bit (DMP control on NCI) */ + if (chip->resetcore == brcmf_chip_nci_resetcore) + val = cpu->dmpctrl ? + chip->ops->read32(chip->ctx, cpu->dmpctrl) : 0; + else + val = chip->ops->read32(chip->ctx, + cpu->wrapbase + BCMA_IOCTL); val &= ARMCR4_BCMA_IOCTL_CPUHALT; brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT, ARMCR4_BCMA_IOCTL_CPUHALT); @@ -1413,6 +1710,18 @@ static bool brcmf_chip_ca7_set_active(struct brcmf_chip_priv *chip, u32 rstvec) /* restore ARM */ core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CA7); + if (chip->resetcore == brcmf_chip_nci_resetcore) { + /* + * set_passive left the CA7 out of reset and halted; on NCI, + * as Broadcom's driver does, clearing the halt is enough + * (dhdpcie_bus_download_state()). Resetting it again keeps a + * second firmware download from starting. + */ + brcmf_chip_nci_cflags(container_of(core, struct brcmf_core_priv, + pub), + ARMCR4_BCMA_IOCTL_CPUHALT, 0); + return true; + } brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0); return true; From a6d6cda3d52e7d84691a8a3f8dc922c536f0e8ff Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:09 -0400 Subject: [PATCH 63/75] wifi: brcmfmac: msgbuf: give control buffers the lowest packet IDs Broadcom's driver numbers the ioctl response and event buffers in a map of their own, of 1024 IDs (dhd_msgbuf.c pktid_ctrl_map), and the BCM4398's firmware checks them against that: with data, ioctl response and event buffers sharing one pool, the first event buffer posted after 1023 data buffers got ID 1025 and the firmware trapped ("pciedev_host_pktid_audit(pktid_type=0): Invalid pktid<1025>"). Reserve IDs 1 to 2 * (ioctl response + event buffers) for the control buffers (each is reposted before it is freed), and keep the data buffers above them. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/msgbuf.c | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index cefa63de17..5a8988668f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -317,6 +317,8 @@ struct brcmf_msgbuf_pktid { struct brcmf_msgbuf_pktids { u32 array_size; u32 last_allocated_idx; + /* IDs 1 to nr_ctrl: the ioctl response and event buffers only */ + u32 nr_ctrl; enum dma_data_direction direction; struct brcmf_msgbuf_pktid *array; }; @@ -361,10 +363,10 @@ static int brcmf_msgbuf_alloc_pktid(struct device *dev, struct brcmf_msgbuf_pktids *pktids, struct sk_buff *skb, u16 data_offset, - dma_addr_t *physaddr, u32 *idx) + dma_addr_t *physaddr, u32 *idx, bool ctrl) { struct brcmf_msgbuf_pktid *array; - u32 count; + u32 first, end, count; array = pktids->array; @@ -376,21 +378,30 @@ brcmf_msgbuf_alloc_pktid(struct device *dev, return -ENOMEM; } - *idx = pktids->last_allocated_idx; + /* + * Packet ID 0 means "no packet" to the firmware: never hand it out. + * Control buffers get the lowest IDs: Broadcom's driver numbers them + * in a map of their own (1024 IDs), and a firmware that checks them + * against that traps on a larger one ("Invalid pktid"). + */ + first = ctrl ? 1 : pktids->nr_ctrl + 1; + end = ctrl ? pktids->nr_ctrl + 1 : pktids->array_size; + *idx = ctrl ? end - 1 : pktids->last_allocated_idx; + if (*idx < first || *idx >= end) + *idx = end - 1; - /* Packet ID 0 means "no packet" to the firmware: never hand it out. */ - count = 1; + count = 0; do { (*idx)++; - if (*idx == pktids->array_size) - *idx = 1; + if (*idx >= end) + *idx = first; if (array[*idx].allocated.counter == 0) if (atomic_cmpxchg(&array[*idx].allocated, 0, 1) == 0) break; count++; - } while (count < pktids->array_size); + } while (count < end - first); - if (count == pktids->array_size) { + if (count == end - first) { dma_unmap_single(dev, *physaddr, skb->len - data_offset, pktids->direction); return -ENOMEM; @@ -400,7 +411,8 @@ brcmf_msgbuf_alloc_pktid(struct device *dev, array[*idx].physaddr = *physaddr; array[*idx].skb = skb; - pktids->last_allocated_idx = *idx; + if (!ctrl) + pktids->last_allocated_idx = *idx; return 0; } @@ -856,7 +868,7 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->tx_pktids, skb, sfh ? 0 : ETH_HLEN, - &physaddr, &pktid)) { + &physaddr, &pktid, false)) { if (sfh) brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); @@ -1093,7 +1105,7 @@ static u32 brcmf_msgbuf_rxbuf_data_post(struct brcmf_msgbuf *msgbuf, u32 count) pktlen = skb->len; if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->rx_pktids, skb, 0, - &physaddr, &pktid)) { + &physaddr, &pktid, false)) { dev_kfree_skb_any(skb); bphy_err(drvr, "No PKTID available !!\n"); brcmf_commonring_write_cancel(commonring, alloced - i); @@ -1205,7 +1217,7 @@ brcmf_msgbuf_rxbuf_ctrl_post(struct brcmf_msgbuf *msgbuf, bool event_buf, pktlen = skb->len; if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->rx_pktids, skb, 0, - &physaddr, &pktid)) { + &physaddr, &pktid, true)) { dev_kfree_skb_any(skb); bphy_err(drvr, "No PKTID available !!\n"); brcmf_commonring_write_cancel(commonring, alloced - i); @@ -1822,8 +1834,8 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) */ msgbuf->max_rxbufpost = min_t(u32, if_msgbuf->max_rxbufpost, NR_RX_PKTIDS - 1 - - msgbuf->max_ioctlrespbuf - - msgbuf->max_eventbuf); + 2 * (msgbuf->max_ioctlrespbuf + + msgbuf->max_eventbuf)); msgbuf->tx_pktids = brcmf_msgbuf_init_pktids(NR_TX_PKTIDS, DMA_TO_DEVICE); @@ -1833,6 +1845,9 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) DMA_FROM_DEVICE); if (!msgbuf->rx_pktids) goto fail; + /* Twice the control buffers: each is reposted before it is freed */ + msgbuf->rx_pktids->nr_ctrl = 2 * (msgbuf->max_ioctlrespbuf + + msgbuf->max_eventbuf); msgbuf->flow = brcmf_flowring_attach(drvr->bus_if->dev, if_msgbuf->max_flowrings); From efb7c6bc1ec6400003a8280e7a4f47ec8677b6ae Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:09 -0400 Subject: [PATCH 64/75] wifi: brcmfmac: msgbuf: wait for D2H items the firmware has finished With DMA'd ring indices the firmware can publish a completion's index before the item itself has reached host memory. Firmware that asks for D2H sync (PCIE_SHARED_D2H_SYNC_SEQNUM or _XORCSUM; the BCM4398's asks for XORCSUM) stamps each item with a sequence number in its epoch byte and, in XORCSUM mode, makes the XOR of the item's words zero. Wait for both before handling an item, as Broadcom's driver does (dhd_prot_d2h_sync_seqnum() and dhd_prot_d2h_sync_xorcsum()), with the same stepped retries, and skip an item that never completes, as there. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/bus.h | 1 + .../broadcom/brcm80211/brcmfmac/msgbuf.c | 78 ++++++++++++++++--- .../broadcom/brcm80211/brcmfmac/pcie.c | 5 ++ 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index f41d87dd55..0ced0b8c26 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -133,6 +133,7 @@ struct brcmf_bus_msgbuf { u16 max_flowrings; u16 max_submissionrings; u16 max_completionrings; + u32 d2h_sync; }; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index 5a8988668f..93eebe6ceb 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -290,6 +290,9 @@ struct brcmf_msgbuf { u16 ioctl_seq_no; u32 reqid; u32 h2d_seqnum[BRCMF_NROF_H2D_COMMON_MSGRINGS]; + /* D2H sync (bcmdhd dhd_prot_d2h_sync_*()): mode, and next epochs */ + u32 d2h_sync; + u32 d2h_seqnum[BRCMF_NROF_COMMON_MSGRINGS]; wait_queue_head_t ioctl_resp_wait; bool ctl_completed; @@ -1521,9 +1524,55 @@ static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) } -static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, - struct brcmf_commonring *commonring) +#define BRCMF_MSGBUF_D2H_EPOCH_MODULO 253 +#define BRCMF_MSGBUF_D2H_EPOCH_INIT 254 +#define BRCMF_MSGBUF_D2H_SYNC_SEQNUM 0x20000 +#define BRCMF_MSGBUF_D2H_SYNC_XORCSUM 0x40000 +#define BRCMF_MSGBUF_D2H_SYNC_TRIES 512 +#define BRCMF_MSGBUF_D2H_SYNC_STEPS 5 + +/* + * With DMA'd ring indices the firmware can publish a completion's index + * before the item itself has landed in host memory. Firmware that asks for + * D2H sync stamps each item with a sequence number (its epoch) and, in + * XORCSUM mode, a checksum making the XOR of the item's words zero; the + * host waits for both before reading the item, as Broadcom's driver does + * (dhd_prot_d2h_sync_seqnum() and dhd_prot_d2h_sync_xorcsum()). An item + * that never completes is skipped, as there. + */ +static bool brcmf_msgbuf_d2h_sync(struct brcmf_msgbuf *msgbuf, u32 ringid, + void *item, u16 len) +{ + u8 want = msgbuf->d2h_seqnum[ringid] % BRCMF_MSGBUF_D2H_EPOCH_MODULO; + struct msgbuf_common_hdr *hdr = item; + u32 step, tries, csum, i; + + for (step = 1; step <= BRCMF_MSGBUF_D2H_SYNC_STEPS; step++) { + for (tries = 0; tries < BRCMF_MSGBUF_D2H_SYNC_TRIES; tries++) { + if (READ_ONCE(hdr->rsvd0) == want) { + csum = 0; + if (msgbuf->d2h_sync & BRCMF_MSGBUF_D2H_SYNC_XORCSUM) + for (i = 0; i < len / 4; i++) + csum ^= READ_ONCE(((u32 *)item)[i]); + if (!csum) { + msgbuf->d2h_seqnum[ringid]++; + dma_rmb(); + return true; + } + } + udelay(step); + } + } + + brcmf_err("D2H ring %u: item never completed (epoch %u, want %u)\n", + ringid, READ_ONCE(hdr->rsvd0), want); + msgbuf->d2h_seqnum[ringid]++; + return false; +} + +static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, u32 ringid) { + struct brcmf_commonring *commonring = msgbuf->commonrings[ringid]; void *buf; u16 count; u16 processed; @@ -1535,8 +1584,11 @@ static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, processed = 0; while (count) { - brcmf_msgbuf_process_msgtype(msgbuf, - buf + msgbuf->rx_dataoffset); + if (!msgbuf->d2h_sync || + brcmf_msgbuf_d2h_sync(msgbuf, ringid, buf, + brcmf_commonring_len_item(commonring))) + brcmf_msgbuf_process_msgtype(msgbuf, + buf + msgbuf->rx_dataoffset); buf += brcmf_commonring_len_item(commonring); processed++; if (processed == BRCMF_MSGBUF_UPDATE_RX_PTR_THRS) { @@ -1592,7 +1644,6 @@ int brcmf_proto_msgbuf_rx_trigger(struct device *dev) struct brcmf_pub *drvr = bus_if->drvr; struct brcmf_msgbuf *msgbuf; struct brcmf_commonring *commonring; - void *buf; u32 flowid; int qlen; @@ -1600,12 +1651,9 @@ int brcmf_proto_msgbuf_rx_trigger(struct device *dev) return -ENODEV; msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_RX_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_TX_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_CONTROL_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_RX_COMPLETE); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_TX_COMPLETE); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_CONTROL_COMPLETE); for_each_set_bit(flowid, msgbuf->txstatus_done_map, msgbuf->max_flowrings) { @@ -1825,6 +1873,14 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) goto fail; msgbuf->rx_dataoffset = if_msgbuf->rx_dataoffset; + msgbuf->d2h_sync = if_msgbuf->d2h_sync; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_CONTROL_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_TX_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_RX_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + brcmf_dbg(MSGBUF, "D2H sync mode 0x%x\n", msgbuf->d2h_sync); msgbuf->max_ioctlrespbuf = BRCMF_MSGBUF_MAX_IOCTLRESPBUF_POST; msgbuf->max_eventbuf = BRCMF_MSGBUF_MAX_EVENTBUF_POST; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 4ca80e15e8..c11f6272fa 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -247,6 +247,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_9 #define BRCMF_PCIE_SHARED_VERSION_MASK 0x00FF #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000 +#define BRCMF_PCIE_SHARED_D2H_SYNC_SEQNUM 0x20000 +#define BRCMF_PCIE_SHARED_D2H_SYNC_XORCSUM 0x40000 #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000 #define BRCMF_PCIE_SHARED_USE_MAILBOX 0x2000000 #define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000 @@ -2876,6 +2878,9 @@ static void brcmf_pcie_setup(struct device *dev, int ret, bus->msgbuf->rx_dataoffset = devinfo->shared.rx_dataoffset; bus->msgbuf->max_rxbufpost = devinfo->shared.max_rxbufpost; + bus->msgbuf->d2h_sync = devinfo->shared.flags & + (BRCMF_PCIE_SHARED_D2H_SYNC_SEQNUM | + BRCMF_PCIE_SHARED_D2H_SYNC_XORCSUM); bus->msgbuf->max_flowrings = devinfo->shared.max_flowrings; init_waitqueue_head(&devinfo->mbdata_resp_wait); From 544fe362cf83433007ac907fc85b958179bb58cb Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:09 -0400 Subject: [PATCH 65/75] wifi: brcmfmac: fall back to event_msgs_ext The BCM4398's 24.100 firmware has dropped the "event_msgs" iovar (getting it fails, and brcmfmac stopped there: "Get event_msgs error (-52)"). Broadcom's driver uses "event_msgs_ext", whose mask is preceded by a small header, as brcmfmac's Cypress code already sends it. When the firmware rejects "event_msgs", read the mask with "event_msgs_ext" and keep using it to set the mask. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/common.c | 6 +- .../broadcom/brcm80211/brcmfmac/fweh.c | 78 ++++++++++++++++++- .../broadcom/brcm80211/brcmfmac/fweh.h | 4 + 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c index b6027d83e6..f7165dfc36 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c @@ -412,8 +412,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) brcmf_c_set_joinpref_default(ifp); /* Setup event_msgs, enable E_IF */ - err = brcmf_fil_iovar_data_get(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_get_event_mask(ifp); if (err) { bphy_err(drvr, "Get event_msgs error (%d)\n", err); goto done; @@ -425,8 +424,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) * that all vendors have. */ setbit(fweh->event_mask, BRCMF_E_IF); - err = brcmf_fil_iovar_data_set(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_set_event_mask(ifp); if (err) { bphy_err(drvr, "Set event_msgs error (%d)\n", err); goto done; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c index 1cff4ba769..f6de0f0f36 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c @@ -430,6 +430,81 @@ void brcmf_fweh_unregister(struct brcmf_pub *drvr, drvr->fweh->evt_handler[evt_handler_idx] = NULL; } +/* + * Newer firmware (the BCM4398's 24.100) has dropped the "event_msgs" iovar + * for "event_msgs_ext", whose mask is preceded by a small header, as + * Broadcom's driver and the Cypress vendor code use it. + */ +struct brcmf_fweh_eventmsgs_ext { + u8 ver; + u8 command; + u8 len; + u8 maxgetsize; + u8 mask[]; +}; + +#define BRCMF_EVENTMSGS_EXT_VER 1 +#define BRCMF_EVENTMSGS_EXT_SET_MASK 3 + +int brcmf_fweh_get_event_mask(struct brcmf_if *ifp) +{ + struct brcmf_fweh_info *fweh = ifp->drvr->fweh; + struct brcmf_fweh_eventmsgs_ext *msg; + u32 msglen; + int err; + + err = brcmf_fil_iovar_data_get(ifp, "event_msgs", fweh->event_mask, + fweh->event_mask_len); + if (err != -EBADE) + return err; + + msglen = sizeof(*msg) + fweh->event_mask_len; + msg = kzalloc(msglen, GFP_KERNEL); + if (!msg) + return -ENOMEM; + msg->ver = BRCMF_EVENTMSGS_EXT_VER; + msg->len = fweh->event_mask_len; + msg->maxgetsize = fweh->event_mask_len; + + err = brcmf_fil_iovar_data_get(ifp, "event_msgs_ext", msg, msglen); + if (!err) { + memcpy(fweh->event_mask, msg->mask, + min_t(uint, msg->len, fweh->event_mask_len)); + fweh->event_msgs_ext = true; + brcmf_dbg(EVENT, "using event_msgs_ext (%u bytes)\n", msg->len); + } + kfree(msg); + + return err; +} + +int brcmf_fweh_set_event_mask(struct brcmf_if *ifp) +{ + struct brcmf_fweh_info *fweh = ifp->drvr->fweh; + struct brcmf_fweh_eventmsgs_ext *msg; + u32 msglen; + int err; + + if (!fweh->event_msgs_ext) + return brcmf_fil_iovar_data_set(ifp, "event_msgs", + fweh->event_mask, + fweh->event_mask_len); + + msglen = sizeof(*msg) + fweh->event_mask_len; + msg = kzalloc(msglen, GFP_KERNEL); + if (!msg) + return -ENOMEM; + msg->ver = BRCMF_EVENTMSGS_EXT_VER; + msg->command = BRCMF_EVENTMSGS_EXT_SET_MASK; + msg->len = fweh->event_mask_len; + memcpy(msg->mask, fweh->event_mask, fweh->event_mask_len); + + err = brcmf_fil_iovar_data_set(ifp, "event_msgs_ext", msg, msglen); + kfree(msg); + + return err; +} + /** * brcmf_fweh_activate_events() - enables firmware events registered. * @@ -459,8 +534,7 @@ int brcmf_fweh_activate_events(struct brcmf_if *ifp) if (!brcmf_fwvid_activate_events(ifp)) return 0; - err = brcmf_fil_iovar_data_set(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_set_event_mask(ifp); if (err) bphy_err(fweh->drvr, "Set event_msgs error (%d)\n", err); return err; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h index e327dd58d2..7dc26ab185 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h @@ -336,6 +336,8 @@ struct brcmf_fweh_event_map { struct brcmf_fweh_info { struct brcmf_pub *drvr; bool p2pdev_setup_ongoing; + /* the firmware takes "event_msgs_ext" rather than "event_msgs" */ + bool event_msgs_ext; struct work_struct event_work; spinlock_t evt_q_lock; struct list_head event_q; @@ -357,6 +359,8 @@ int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code, void brcmf_fweh_unregister(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code); int brcmf_fweh_activate_events(struct brcmf_if *ifp); +int brcmf_fweh_get_event_mask(struct brcmf_if *ifp); +int brcmf_fweh_set_event_mask(struct brcmf_if *ifp); void brcmf_fweh_process_event(struct brcmf_pub *drvr, struct brcmf_event *event_packet, u32 packet_len, gfp_t gfp); From 662e5d80c9679647409a8cdd92d89cb94cebfece Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:09 -0400 Subject: [PATCH 66/75] wifi: brcmfmac: cfg80211: make room for a third band GET_BANDLIST returns the number of bands and then the bands. Firmware with a 6 GHz band, like the BCM4398's, reports three, and fails the call when the buffer only has room for two ("could not obtain band info: err=-52"). Only 2.4 and 5 GHz are set up from it, as before. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 2b172f7e35..2ae9360573 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -7749,7 +7749,7 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) struct ieee80211_supported_band *band; u16 max_interfaces = 0; bool gscan; - __le32 bandlist[3]; + __le32 bandlist[4]; /* count, then up to 2.4, 5 and 6 GHz */ u32 n_bands; int err, i; From 6bdf17ec25c84a2600cb64fdaba531bb82cec864 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 67/75] wifi: brcmfmac: scan interface versions 3 and 4 "scan_ver" reports the scan interface's major version. Version 3 keeps the version 2 layout with its pad byte used as ssid_type; version 4 adds scan_type_ext after scan_type. The BCM4398's firmware reports 3 and rejects version 2 requests (brcmf_run_escan: error -52). Read the major version, and send version 3 or 4 escan parameters when the firmware asks for them, as Broadcom's driver does (wl_cfgscan.c, scan_params_ver). Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 31 ++++++++++++++++++- .../broadcom/brcm80211/brcmfmac/feature.c | 16 ++++++++++ .../broadcom/brcm80211/brcmfmac/feature.h | 6 +++- .../broadcom/brcm80211/brcmfmac/fwil_types.h | 6 ++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 2ae9360573..5f4ae66d0e 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -1469,7 +1469,36 @@ brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp, params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION_V2); - if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) { + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V3)) { + /* The v2 layout; its pad byte is ssid_type, 0 for the default */ + params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION_V3); + params->params_v2_le.version = + cpu_to_le16(BRCMF_SCAN_PARAMS_VERSION_V3); + } else if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V4)) { + struct brcmf_escan_params_le *params_v4; + u8 *v2 = (u8 *)¶ms->params_v2_le; + u16 len = le16_to_cpu(params->params_v2_le.length); + u8 *v4; + + params_size += sizeof(__le32); + params_v4 = kzalloc(params_size, GFP_KERNEL); + if (!params_v4) { + err = -ENOMEM; + goto exit_params; + } + params_v4->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION_V4); + v4 = (u8 *)¶ms_v4->params_v2_le; + memcpy(v4, v2, BRCMF_SCAN_PARAMS_V4_EXT_OFFSET); + memcpy(v4 + BRCMF_SCAN_PARAMS_V4_EXT_OFFSET + sizeof(__le32), + v2 + BRCMF_SCAN_PARAMS_V4_EXT_OFFSET, + len - BRCMF_SCAN_PARAMS_V4_EXT_OFFSET); + params_v4->params_v2_le.version = + cpu_to_le16(BRCMF_SCAN_PARAMS_VERSION_V4); + params_v4->params_v2_le.length = + cpu_to_le16(len + sizeof(__le32)); + kfree(params); + params = params_v4; + } else if (!brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) { struct brcmf_escan_params_le *params_v1; params_size -= BRCMF_SCAN_PARAMS_V2_FIXED_SIZE; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index 145b576395..afac815ca9 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -356,6 +356,22 @@ void brcmf_feat_attach(struct brcmf_pub *drvr) brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa"); brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_SCAN_V2, "scan_ver"); + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) { + struct { + __le16 version; + __le16 length; + __le16 major; + } scan_ver = {}; + + err = brcmf_fil_iovar_data_get(ifp, "scan_ver", &scan_ver, + sizeof(scan_ver)); + brcmf_dbg(INFO, "scan interface version %u\n", + le16_to_cpu(scan_ver.major)); + if (!err && le16_to_cpu(scan_ver.major) == 3) + ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_V3); + else if (!err && le16_to_cpu(scan_ver.major) >= 4) + ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_V4); + } brcmf_feat_wlc_version_overrides(drvr); brcmf_feat_firmware_overrides(drvr); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h index 8ebd231169..be20a6336c 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h @@ -32,6 +32,8 @@ * DUMP_OBSS: Firmware has capable to dump obss info to support ACS * SCAN_V2: Version 2 scan params * SAE_EXT: SAE authentication handled by user-space supplicant + * SCAN_V3: Version 3 scan params (the v2 layout, with the pad as ssid_type) + * SCAN_V4: Version 4 scan params (scan_type_ext after scan_type) */ #define BRCMF_FEAT_LIST \ BRCMF_FEAT_DEF(MBSS) \ @@ -61,7 +63,9 @@ BRCMF_FEAT_DEF(PMKID_V3) \ BRCMF_FEAT_DEF(SAE_EXT) \ BRCMF_FEAT_DEF(JOIN_V1) \ - BRCMF_FEAT_DEF(HOST_SFHLLC) + BRCMF_FEAT_DEF(HOST_SFHLLC) \ + BRCMF_FEAT_DEF(SCAN_V3) \ + BRCMF_FEAT_DEF(SCAN_V4) /* * Quirks: diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index 11a86d292b..8ebfceeb84 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -49,6 +49,10 @@ /* size of brcmf_scan_params not including variable length array */ #define BRCMF_SCAN_PARAMS_FIXED_SIZE 64 #define BRCMF_SCAN_PARAMS_V2_FIXED_SIZE 72 +#define BRCMF_SCAN_PARAMS_VERSION_V3 3 +#define BRCMF_SCAN_PARAMS_VERSION_V4 4 +/* v4: scan_type_ext follows scan_type, at the v2 offset of nprobes */ +#define BRCMF_SCAN_PARAMS_V4_EXT_OFFSET 52 /* version of brcmf_scan_params structure */ #define BRCMF_SCAN_PARAMS_VERSION_V2 2 @@ -72,6 +76,8 @@ #define DOT11_BSSTYPE_ANY 2 #define BRCMF_ESCAN_REQ_VERSION 1 #define BRCMF_ESCAN_REQ_VERSION_V2 2 +#define BRCMF_ESCAN_REQ_VERSION_V3 3 +#define BRCMF_ESCAN_REQ_VERSION_V4 4 #define BRCMF_MAXRATES_IN_SET 16 /* max # of rates in rateset */ From d02f7a20f55d900372afff3cbd34b7cd1362ca7e Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 68/75] wifi: brcmfmac: accept version 114 BSS info The BCM4398's firmware reports scan results as wl_bss_info version 114: version 109 with EHT fields appended, so every field brcmfmac reads is where it was, and the IEs are found from ie_offset as before. Accept it rather than dropping every result ("Version 114 != WL_BSS_INFO_VERSION"). Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 3 ++- drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 5f4ae66d0e..a34836a388 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c @@ -3546,7 +3546,8 @@ static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; if (bss_list->count != 0 && - bss_list->version != BRCMF_BSS_INFO_VERSION) { + bss_list->version != BRCMF_BSS_INFO_VERSION && + bss_list->version != BRCMF_BSS_INFO_VERSION_114) { bphy_err(drvr, "Version %d != WL_BSS_INFO_VERSION\n", bss_list->version); return -EOPNOTSUPP; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index 8ebfceeb84..be19134f07 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -19,6 +19,8 @@ #define BRCMF_ARP_OL_PEER_AUTO_REPLY 0x00000008 #define BRCMF_BSS_INFO_VERSION 109 /* curr ver of brcmf_bss_info_le struct */ +/* v114 (the BCM4398's firmware): v109 with EHT fields appended */ +#define BRCMF_BSS_INFO_VERSION_114 114 #define BRCMF_BSS_RSSI_ON_CHANNEL 0x0004 #define BRCMF_STA_BRCM 0x00000001 /* Running a Broadcom driver */ From 865361dadfc4b0a95b6d50c561f30635987f7aaf Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 69/75] wifi: brcmfmac: add the BCM4398 chip id, RAM base and firmware name The Pixel 8 Pro's Wi-Fi chip is a BCM4398 (PCIe device 0x4444), rev 3 (d0). Bcmdhd puts its 4 MiB of RAM at 0x2a0000; it sizes its SYSMEM like the BCM4389's. Add the ids, the RAM base and the firmware name for d0 and later. The PCI id is added once the chip is supported. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 3 +++ drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 3 +++ drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h | 2 ++ 3 files changed, 8 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index c7278d2503..a97013c00b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c @@ -824,6 +824,7 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem) switch (sysmem->chip->pub.chip) { case BRCM_CC_4389_CHIP_ID: + case BRCM_CC_4398_CHIP_ID: /* Count the RAM banks only, and skip the ROM banks in * front of them. */ @@ -929,6 +930,8 @@ static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci) return 0x6e0000; case BRCM_CC_4387_CHIP_ID: return 0x740000; + case BRCM_CC_4398_CHIP_ID: + return 0x2a0000; default: brcmf_err("unknown chip: %s\n", ci->pub.name); break; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index c11f6272fa..6acd9c83b8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -76,6 +76,8 @@ BRCMF_FW_CLM_DEF(4387C2, "brcmfmac4387c2-pcie"); BRCMF_FW_CLM_DEF(4389C1, "brcmfmac4389c1-pcie"); /* BCM4383 rev 2 (Pixel 9a): the owner's firmware set, with CLM and TXCAP blobs */ BRCMF_FW_CLM_DEF(4383, "brcmfmac4383-pcie"); +/* BCM4398 rev 3, d0 (Pixel 8 Pro): the owner's firmware set */ +BRCMF_FW_CLM_DEF(4398D0, "brcmfmac4398d0-pcie"); BRCMF_FW_CLM_DEF(54591, "brcmfmac54591-pcie"); /* firmware config files */ @@ -119,6 +121,7 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { BRCMF_FW_ENTRY(BRCM_CC_4387_CHIP_ID, 0xFFFFFFFF, 4387C2), /* revision ID 7 */ BRCMF_FW_ENTRY(BRCM_CC_4389_CHIP_ID, 0xFFFFFFFF, 4389C1), BRCMF_FW_ENTRY(BRCM_CC_4383_CHIP_ID, 0xFFFFFFFF, 4383), + BRCMF_FW_ENTRY(BRCM_CC_4398_CHIP_ID, 0xFFFFFFF8, 4398D0), }; #define BRCMF_PCIE_FW_UP_TIMEOUT 5000 /* msec */ diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h index 7cbe571c39..c453d6d0f2 100644 --- a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h +++ b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h @@ -57,6 +57,7 @@ #define BRCM_CC_4377_CHIP_ID 0x4377 #define BRCM_CC_4378_CHIP_ID 0x4378 #define BRCM_CC_4383_CHIP_ID 0x4383 +#define BRCM_CC_4398_CHIP_ID 0x4398 #define BRCM_CC_4387_CHIP_ID 0x4387 #define BRCM_CC_4389_CHIP_ID 0x4389 #define CY_CC_4373_CHIP_ID 0x4373 @@ -101,6 +102,7 @@ #define BRCM_PCIE_4377_DEVICE_ID 0x4488 #define BRCM_PCIE_4378_DEVICE_ID 0x4425 #define BRCM_PCIE_4383_DEVICE_ID 0x4449 +#define BRCM_PCIE_4398_DEVICE_ID 0x4444 #define BRCM_PCIE_4387_DEVICE_ID 0x4433 #define BRCM_PCIE_4389_DEVICE_ID 0x4441 #define CY_PCIE_54591_DEVICE_ID 0x4417 From d68abb2f040f5d95e253c74c4342c3b2e7ed0f3c Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 70/75] wifi: brcmfmac: pcie: handle the BCM4398 like the BCM4389 The BCM4398 follows the BCM4389 in Broadcom's driver: it is reset with an FLR, told the host is ready with the same value, and serviced with the same INTx follow-ups and ring polling. It also splits its backplane into save/restore power domains, with two more than the BCM4389: the scan MAC and the SAQM (si_srpwr_domain_all_mask()). Key those paths on a helper covering both chips, and request the BCM4398's six domains. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/pcie.c | 49 ++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 6acd9c83b8..d56650a340 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -172,6 +172,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_SRPWR_DMN1_ARMBP BIT(1) #define BRCMF_PCIE_SRPWR_DMN2_MACAUX BIT(2) #define BRCMF_PCIE_SRPWR_DMN3_MACMAIN BIT(3) +#define BRCMF_PCIE_SRPWR_DMN4_MACSCAN BIT(4) +#define BRCMF_PCIE_SRPWR_DMN6_SAQM BIT(6) #define BRCMF_PCIE_SRPWR_DMN_ALL (BRCMF_PCIE_SRPWR_DMN0_PCIE | \ BRCMF_PCIE_SRPWR_DMN1_ARMBP | \ BRCMF_PCIE_SRPWR_DMN2_MACAUX | \ @@ -848,22 +850,48 @@ brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid) /* - * Chips with several backplane power domains (the BCM4389 here) power the + * The BCM4389 and the BCM4398 after it are reset, told the host is ready and + * serviced the way Broadcom's driver does for its multi-backplane chips. + */ +static bool brcmf_pcie_is_4389_family(struct brcmf_pciedev_info *devinfo) +{ + return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID || + devinfo->pdev->device == BRCM_PCIE_4398_DEVICE_ID; +} + +/* + * Chips with several backplane power domains (the BCM4389 and BCM4398) power the * ARM/backplane and MAC domains down unless the host asks for them, and * a chip reset drops the host's requests. Backplane accesses to a domain * that is off fault, and read back as 0xffffffff. */ +static u32 brcmf_pcie_srpwr_domains(struct brcmf_pciedev_info *devinfo) +{ + switch (devinfo->pdev->device) { + case BRCM_PCIE_4389_DEVICE_ID: + return BRCMF_PCIE_SRPWR_DMN_ALL; + case BRCM_PCIE_4398_DEVICE_ID: + /* and the scan MAC and SAQM domains (si_srpwr_domain_all_mask()) */ + return BRCMF_PCIE_SRPWR_DMN_ALL | BRCMF_PCIE_SRPWR_DMN4_MACSCAN | + BRCMF_PCIE_SRPWR_DMN6_SAQM; + default: + return 0; + } +} + static bool brcmf_pcie_has_srpwr(struct brcmf_pciedev_info *devinfo) { - return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID; + return brcmf_pcie_srpwr_domains(devinfo); } static void brcmf_pcie_srpwr_request(struct brcmf_pciedev_info *devinfo) { u32 reg = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + BRCMF_PCIE_PCIE2REG_POWERCTL; - u32 req = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_REQON_SHIFT; - u32 up = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_STATUS_SHIFT; + u32 req = brcmf_pcie_srpwr_domains(devinfo) << + BRCMF_PCIE_SRPWR_REQON_SHIFT; + u32 up = brcmf_pcie_srpwr_domains(devinfo) << + BRCMF_PCIE_SRPWR_STATUS_SHIFT; u32 dar = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + BRCMF_PCIE_64_PCIE2REG_DAR_POWERCTL; u32 val; @@ -991,8 +1019,7 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) * second firmware download. */ brcmf_pcie_srpwr_request(devinfo); - if (devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID || - brcmf_pcie_flr(devinfo)) { + if (!brcmf_pcie_is_4389_family(devinfo) || brcmf_pcie_flr(devinfo)) { brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); WRITECC32(devinfo, watchdog, 4); msleep(100); @@ -1285,7 +1312,7 @@ static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo) static bool brcmf_pcie_early_hostready(struct brcmf_pciedev_info *devinfo) { - return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID || + return brcmf_pcie_is_4389_family(devinfo) || devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9; } @@ -1297,8 +1324,7 @@ static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo) /* bcmdhd dhd_bus_hostready() writes this value */ brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->h2d_mailbox_1, - devinfo->pdev->device == - BRCM_PCIE_4389_DEVICE_ID ? + brcmf_pcie_is_4389_family(devinfo) ? 0x12345678 : 1); } } @@ -1404,7 +1430,7 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) * (dhd_bus_handle_intx_ahead_dma_indices()). */ if (devinfo->dma_idx_sz && - devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + brcmf_pcie_is_4389_family(devinfo) && devinfo->state == BRCMFMAC_PCIE_STATE_UP) { usleep_range(500, 1000); brcmf_pcie_rx_process(devinfo); @@ -2859,8 +2885,7 @@ static void brcmf_pcie_setup(struct device *dev, int ret, ret = brcmf_pcie_request_irq(devinfo); if (ret) goto fail; - devinfo->poll_enabled = devinfo->pdev->device == - BRCM_PCIE_4389_DEVICE_ID; + devinfo->poll_enabled = brcmf_pcie_is_4389_family(devinfo); /* Notify early firmware before its deferred TX-buffer allocation. */ if (brcmf_pcie_early_hostready(devinfo)) From 7075fdc1bc67485dd91af0fe14ec8a1e5859257a Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 71/75] wifi: brcmfmac: pcie: wait for the BCM4398's boot interrupt The BCM4398's firmware writes an interim address to the last word of RAM before its shared area's, and signals the end of its boot with a mailbox interrupt, which Broadcom's driver waits for before it reads the address (dhdpcie_wait_readshared_area_addr(), "recd. boot intr"). brcmfmac took the interim address and failed the firmware's API checks. Interrupts are not set up yet at that point, so poll the PCIe core's mailbox status through BAR0's fixed window onto it, then read the address. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/pcie.c | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index d56650a340..e63d9a8f29 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -2423,6 +2423,37 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Wait for FW init\n"); sharedram_addr = sharedram_addr_written; loop_counter = BRCMF_PCIE_FW_UP_TIMEOUT / 50; + /* + * The BCM4398's firmware writes an interim address to the last word + * of RAM before the real one, and signals the end of its boot with a + * mailbox interrupt, which Google's driver waits for (dhd_pcie.c + * dhdpcie_wait_readshared_area_addr(), "boot intr"). Interrupts are + * not set up yet, so poll for it. + */ + if (devinfo->pdev->device == BRCM_PCIE_4398_DEVICE_ID) { + u32 mbint = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + devinfo->reginfo->mailboxint; + u32 intstatus = 0; + + brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); + while (loop_counter) { + intstatus = brcmf_pcie_read_reg32(devinfo, mbint); + if (intstatus && intstatus != 0xffffffff) + break; + msleep(50); + loop_counter--; + } + brcmf_dbg(PCIE, "boot interrupt %#x after %u ms\n", intstatus, + (BRCMF_PCIE_FW_UP_TIMEOUT / 50 - loop_counter) * 50); + if (intstatus && intstatus != 0xffffffff) + brcmf_pcie_write_reg32(devinfo, + BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + devinfo->reginfo->mailboxint, + intstatus); + sharedram_addr = brcmf_pcie_read_ram32(devinfo, + devinfo->ci->ramsize - + 4); + } while ((sharedram_addr == sharedram_addr_written) && (loop_counter)) { msleep(50); sharedram_addr = brcmf_pcie_read_ram32(devinfo, From 9c9a2f0dceba1c55810a4a349523e04cdec6b798 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 72/75] wifi: brcmfmac: pcie: make the BCM4398's firmware trap before release The BCM4398's always-on domain keeps its state across WL_REG_ON, an FLR and a PMU watchdog reset, and after a firmware has run, a second download never starts: reloading the driver needed a reboot. Broadcom's driver makes the firmware trap on purpose before it lets go of it, by writing a magic number to the PCIe core's H2D doorbell 1 of function 3 ("DB7"), and in its trap handler the firmware holds the power resources high so that the next one boots (dhdpcie_fw_trap(), DHD_DONGLE_TRAP_IN_DETACH). Do the same on remove when the firmware supports it (PCIE_SHARED2_TRAP_ON_HOST_DB7). With it, brcmfmac reloads, with or without the PCIe controller, load and run the firmware again. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/pcie.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index e63d9a8f29..3f5ea978cd 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -2352,6 +2352,43 @@ brcmf_pcie_provide_random_bytes(struct brcmf_pciedev_info *devinfo, u32 address) BRCMF_RANDOM_SEED_LENGTH); } +/* + * Before the host lets go of firmware that supports it, Broadcom's driver + * makes it trap on purpose by writing a magic number to the PCIe core's + * H2D doorbell 1 of function 3 ("DB7"): in its trap handler the firmware + * holds the chip's power resources high, which a new firmware needs to boot. + * Without it the always-on domain keeps the old firmware's PMU state across + * WL_REG_ON and an FLR, and a second download never starts + * (dhd_pcie.c dhdpcie_fw_trap(), DHD_DONGLE_TRAP_IN_DETACH). + */ +#define BRCMF_SHARED_FLAGS2_OFFSET 80 +#define BRCMF_PCIE_SHARED2_TRAP_ON_HOST_DB7 0x00040000 +#define BRCMF_PCIE_PCIE2REG_H2D3_DOORBELL1 0x174 +#define BRCMF_PCIE_DB7_MAGIC_DPC_TRAP 0xdead0002 +#define BRCMF_PCIE_DB7_TRAP_WAIT_MS 100 + +static void brcmf_pcie_db7_trap(struct brcmf_pciedev_info *devinfo) +{ + u32 flags2; + + if (devinfo->pdev->device != BRCM_PCIE_4398_DEVICE_ID || + !devinfo->shared.tcm_base_address) + return; + + flags2 = brcmf_pcie_read_tcm32(devinfo, + devinfo->shared.tcm_base_address + + BRCMF_SHARED_FLAGS2_OFFSET); + if (flags2 == 0xffffffff || + !(flags2 & BRCMF_PCIE_SHARED2_TRAP_ON_HOST_DB7)) + return; + + brcmf_dbg(PCIE, "DB7 trap before release\n"); + brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + BRCMF_PCIE_PCIE2REG_H2D3_DOORBELL1, + BRCMF_PCIE_DB7_MAGIC_DPC_TRAP); + msleep(BRCMF_PCIE_DB7_TRAP_WAIT_MS); +} + static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, const struct firmware *fw, void *nvram, u32 nvram_len) @@ -3366,6 +3403,7 @@ brcmf_pcie_remove(struct pci_dev *pdev) kfree(bus->msgbuf); kfree(bus); + brcmf_pcie_db7_trap(devinfo); brcmf_pcie_release_irq(devinfo); brcmf_pcie_release_scratchbuffers(devinfo); brcmf_pcie_release_ringbuffers(devinfo); From e158cd7415706e3c8ae38a5bf5428ac770bedf3c Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:10 -0400 Subject: [PATCH 73/75] wifi: brcmfmac: BCM4398 firmware quirks The BCM4398's 24.100 firmware (WLC version 18.2): - takes the versioned join parameters only, by the same WLC version test as the BCM4389 and BCM4383; - advertises the supplicant offload but refuses the key, as the BCM4383's does ("failed to change PSK in firmware"): leave the handshakes to the host; - advertises host_sfhllc and relies on it: given plain Ethernet frames it traps in its transmit path (a null write in txq_hw_fill() while encrypting the first aggregated frame). Build the 802.3/LLC header on the host, as for the BCM4389. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../broadcom/brcm80211/brcmfmac/feature.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index afac815ca9..85c1ef8ff4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -164,10 +164,12 @@ static void brcmf_feat_wlc_version_overrides(struct brcmf_pub *drv) * on 16, or 17 and later. The BCM4389 (its 20.101.90 firmware * reports 14.4 and rejects the unversioned layout) and the Pixel * 9a's BCM4383 (20.123.13: the unversioned "join" and SET_SSID - * both fail with -52). + * both fail with -52), and the Pixel 8 Pro's BCM4398 (24.100, + * WLC version 18.2). */ if ((drv->bus_if->chip == BRCM_CC_4389_CHIP_ID || - drv->bus_if->chip == BRCM_CC_4383_CHIP_ID) && + drv->bus_if->chip == BRCM_CC_4383_CHIP_ID || + drv->bus_if->chip == BRCM_CC_4398_CHIP_ID) && ((major == 14 && (minor == 2 || minor == 4)) || (major == 16 && minor >= 1) || major >= 17)) feat_flags |= BIT(BRCMF_FEAT_JOIN_V1); @@ -378,17 +380,20 @@ void brcmf_feat_attach(struct brcmf_pub *drvr) brcmf_fwvid_feat_attach(ifp); - /* Host-built 802.3 + LLC/SNAP TX headers: only the BCM4389 for now */ - if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID) + /* Host-built 802.3 + LLC/SNAP TX headers: the BCM4389 and BCM4398 for now */ + if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID && + drvr->bus_if->chip != BRCM_CC_4398_CHIP_ID) drvr->feat_flags &= ~BIT(BRCMF_FEAT_HOST_SFHLLC); /* - * The BCM4383's firmware (20.123.13 on the Pixel 9a) advertises the - * supplicant offload but refuses the key: brcmf_set_wsec() fails with - * "failed to change PSK in firmware" and the join never gets past + * The BCM4383's firmware (20.123.13 on the Pixel 9a) and the + * BCM4398's (24.100 on the Pixel 8 Pro) advertise the supplicant + * offload but refuse the key: brcmf_set_wsec() fails with "failed to + * change PSK in firmware" and the join never gets past * authentication. Leave the handshakes to the host. */ - if (drvr->bus_if->chip == BRCM_CC_4383_CHIP_ID) + if (drvr->bus_if->chip == BRCM_CC_4383_CHIP_ID || + drvr->bus_if->chip == BRCM_CC_4398_CHIP_ID) drvr->feat_flags &= ~(BIT(BRCMF_FEAT_FWSUP) | BIT(BRCMF_FEAT_SAE) | BIT(BRCMF_FEAT_FWAUTH)); From 99923e0362d5b6b68f4db950c1bc76b3ae265eb0 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 11:45:11 -0400 Subject: [PATCH 74/75] wifi: brcmfmac: add BCM4398 PCIe support Add the BCM4398's PCIe id. On the Pixel 8 Pro (firmware 24.100.671.86.2 from the device's factory image) it joins WPA2, passes 50 to 87 Mbit/s down and 47 to 70 Mbit/s up on 2.4 GHz, stays up across idle and deep sleep, and survives driver reloads. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 3f5ea978cd..969410ee3f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -3629,6 +3629,7 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4389_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4383_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4398_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_43752_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(CY_PCIE_54591_DEVICE_ID, CYW), { /* end: all zeroes */ } From 717fba4f36faa98baa6285573e676bc7bfcf7751 Mon Sep 17 00:00:00 2001 From: Brett-Michael Green Date: Sat, 31 Oct 2026 08:15:31 -0400 Subject: [PATCH 75/75] arm64: dts: exynos: google: zuma-husky: enable the BCM4398 Wi-Fi The Pixel 8 Pro's BCM4398 sits on pcie_1. As stock's wlan node gives them: WL_REG_ON on gph3-4 (as the root port's supply, so the PCI pwrctrl core switches it around link training, with bcmdhd's 200 ms), device wake on gph3-5 and host wake on gpa5-1. Its DMA buffers come from a restricted pool below 4 GiB, as on the Pixel 7 Pro. Assisted-by: LLM Signed-off-by: Brett-Michael Green --- .../boot/dts/exynos/google/zuma-husky.dts | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index 29b9a11b98..ce5f958c27 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -46,6 +46,24 @@ enable-active-high; }; + /* + * WL_REG_ON of the BCM4398 (gph3-4, stock's wl_reg_on). Modelled as + * the root port's supply so the PCI pwrctrl core switches it around + * link training; bcmdhd waits 200 ms after raising it. With pcie_1 + * disabled nothing enables it, so the chip stays off. + */ + wlan_pwr: regulator-wlan { + compatible = "regulator-fixed"; + regulator-name = "wlan-reg-on"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + gpio = <&gph3 4 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <200000>; + pinctrl-0 = <&wlan_reg_on>; + pinctrl-names = "default"; + }; + chosen { /* * ABL requires bootargs to exist; it appends its own after these. @@ -114,6 +132,19 @@ reg = <0x0 0xfac00000 (1344 * 2992 * 4)>; no-map; }; + + /* + * All of the Wi-Fi chip's DMA buffers come from this pool, below + * 4 GiB, as on the Pixel 7 Pro: it keeps driver bugs and stray + * pointers away from the rest of RAM. It does not confine the + * chip's own firmware. + */ + wifi_dma_pool: wifi-dma-pool { + compatible = "restricted-dma-pool"; + size = <0x1000000>; + alignment = <0x0 0x200000>; + alloc-ranges = <0x0 0x80000000 0x80000000>; + }; }; }; @@ -141,6 +172,69 @@ }; }; +/* + * Wi-Fi: the BCM4398 on pcie_1, one Gen3 lane as on stock. Its DMA + * buffers come from wifi_dma_pool. + */ +&pcie_1 { + pinctrl-0 = <&pcie1_clkreq>, <&pcie1_perst>, <&wlan_dev_wake>, + <&wlan_host_wake>; + status = "okay"; + + pcie@0,0 { + compatible = "pciclass,0604"; + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <0x01 0xff>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + vpcie3v3-supply = <&wlan_pwr>; + + wifi@0,0 { + compatible = "pci14e4,4444"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "google,zuma-husky"; + memory-region = <&wifi_dma_pool>; + }; + }; +}; + +&pcie_1_phy { + status = "okay"; +}; + +&pinctrl_far_alive { + wlan_host_wake: wlan-host-wake-pins { + samsung,pins = "gpa5-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; +}; + +&pinctrl_hsi2 { + wlan_reg_on: wlan-reg-on-pins { + samsung,pins = "gph3-4"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; + + wlan_dev_wake: wlan-dev-wake-pins { + samsung,pins = "gph3-5"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; +}; + &spi20 { status = "okay";