diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml index 8589631085..be1765aa4d 100644 --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml @@ -56,6 +56,7 @@ properties: - pci14e4,4433 # BCM4387 - pci14e4,4434 # BCM4388 - pci14e4,4441 # BCM4389 + - pci14e4,4449 # BCM4383 - pci14e4,449d # BCM43752 reg: diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml index 89e65f2a1f..19181b1434 100644 --- a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml @@ -4,26 +4,47 @@ $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. zumapro's (Tensor G4) Wi-Fi controller is the same as zuma's, at + the same addresses and with the same register map, so it uses zuma's + compatible as a fallback. 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: + contains: + const: google,zuma-pcie + then: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 properties: compatible: - const: google,gs201-pcie + oneOf: + - enum: + - google,gs201-pcie + - google,zuma-pcie + - items: + - const: google,zumapro-pcie + - const: google,zuma-pcie reg: minItems: 3 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..544df73eba --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml @@ -0,0 +1,76 @@ +# 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. zumapro (Tensor G4) has the same PHY for its + Wi-Fi controller, programmed with the same sequence, so it uses zuma's + compatible as a fallback. + +properties: + compatible: + oneOf: + - const: google,zuma-pcie-phy + - items: + - const: google,zumapro-pcie-phy + - 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>; + }; 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/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index f9d30456ae..ab0af9b6fe 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -64,6 +64,24 @@ height-mm = <155>; }; + /* + * 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. @@ -148,6 +166,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>; + }; }; }; @@ -175,6 +206,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"; diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 2de5877971..2ca765b018 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -281,6 +281,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; @@ -480,6 +498,39 @@ }; }; +&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>; + }; + + 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 { 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 f46ad29ecc..fba08e0345 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 @@ -26,6 +27,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; @@ -302,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); @@ -531,6 +535,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>; @@ -539,6 +551,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>, @@ -633,6 +697,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>; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts index 76a95c1b05..9bde38dc25 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts @@ -147,6 +147,19 @@ regulator-boot-on; regulator-always-on; }; + + /* + * WL_REG_ON (gph3-4), the Wi-Fi chip's power enable (stock's + * pcie,wlan-gpio), raised 150 ms before the PCIe PHY is configured. + * It is the root port's supply, so the PCI pwrctrl core switches it. + */ + wlan_reg_on: regulator-wlan-reg-on { + compatible = "regulator-fixed"; + regulator-name = "wlan-reg-on"; + gpio = <&gph3 4 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <150000>; + }; }; &{/reserved-memory} { @@ -169,6 +182,19 @@ alignment = <0x0 0x00200000>; alloc-ranges = <0x0 0x98000000 0x06000000>; }; + + /* + * All of the Wi-Fi chip's DMA buffers come from this pool. It keeps + * driver bugs away from the rest of RAM; it does not confine the + * chip's own firmware, as the HSI2 System MMU and S2MPU see PCIe and + * UFS on the same VID and cannot enforce on it. + */ + wifi_dma_pool: wifi-dma-pool { + compatible = "restricted-dma-pool"; + size = <0x01000000>; + alignment = <0x0 0x00200000>; + alloc-ranges = <0x0 0x80000000 0x80000000>; + }; }; &acpm_ipc { @@ -466,6 +492,43 @@ }; }; +/* + * Wi-Fi: the BCM4383 on pcie_1, one lane at Gen2, the chip's own limit + * (its LnkCap reads 5 GT/s). Its DMA buffers come from wifi_dma_pool. + */ +&pcie_1 { + max-link-speed = <2>; + 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_reg_on>; + /* + * No I/A sequencer re-locks the PHY after L1: with ASPM on, the + * link entered L1 and config reads of the chip returned all ones. + */ + aspm-no-l0s; + aspm-no-l1; + + wifi@0,0 { + compatible = "pci14e4,4449"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "google,zumapro-tegu"; + memory-region = <&wifi_dma_pool>; + }; + }; +}; + +&pcie_1_phy { + status = "okay"; +}; + &pinctrl_alive { status = "okay"; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi index f8be1721dd..dd72aeec39 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -1180,6 +1181,24 @@ gpio-controller; #gpio-cells = <2>; }; + + /* Stock's pcie1 pins, the same as zuma's */ + pcie1_clkreq: pcie1-clkreq-pins { + samsung,pins = "gph3-1"; + samsung,pin-function = <2>; + samsung,pin-pud = <3>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + samsung,pin-pud-pdn = <3>; + }; + + pcie1_perst: pcie1-perst-pins { + samsung,pins = "gph3-0"; + samsung,pin-function = <1>; + samsung,pin-pud = <0>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + }; }; pinctrl_hsi2ufs: pinctrl@13060000 { @@ -1212,6 +1231,66 @@ }; }; + /* + * The Wi-Fi chip's controller (stock's pcie_1, ch-num 1), zuma's + * controller at zuma's addresses: one Gen3 lane, no I/A, not + * cache coherent. Its interrupts are its legacy INTx; stock's + * MSI lines are unused. + */ + pcie_1: pcie@13120000 { + compatible = "google,zumapro-pcie", "google,zuma-pcie"; + reg = <0x0 0x13120000 0x1400>, + <0x0 0x13400000 0x381000>, + <0x0 0x60ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x0 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>; + clocks = <&cmu_hsi2 CLK_GOUT_PCIE1_CTL_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_DBI_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_SLV_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_MSTR_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_UDBG_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_PAL_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_REF>; + 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,zumapro-pcie-phy", "google,zuma-pcie-phy"; + reg = <0x0 0x13160000 0x3000>, + <0x0 0x13140000 0x5000>, + <0x0 0x13121400 0x10>, + <0x0 0x13150000 0xd000>, + <0x0 0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + status = "disabled"; + }; + ufs: ufs@13200000 { compatible = "google,zumapro-ufs"; reg = <0x0 0x13200000 0x200>, 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/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 72ee403bab..a667663b50 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; @@ -3516,7 +3545,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; @@ -7748,7 +7778,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; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index e2a628dc32..a97013c00b 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; @@ -683,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. */ @@ -784,8 +926,12 @@ 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; + case BRCM_CC_4398_CHIP_ID: + return 0x2a0000; default: brcmf_err("unknown chip: %s\n", ci->pub.name); break; @@ -1002,6 +1148,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; @@ -1034,7 +1322,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) { @@ -1081,6 +1370,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); @@ -1124,8 +1421,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); @@ -1411,6 +1713,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; 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/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index bff2f5c62e..85c1ef8ff4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -161,10 +161,15 @@ 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), and the Pixel 8 Pro's BCM4398 (24.100, + * WLC version 18.2). */ - 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 || + 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); @@ -353,16 +358,45 @@ 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); 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) 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 || + drvr->bus_if->chip == BRCM_CC_4398_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/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/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); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index f346f7c71a..0fe42ec7a4 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 */ @@ -49,6 +51,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 +78,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 */ diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index cefa63de17..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; @@ -317,6 +320,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 +366,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 +381,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 +414,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 +871,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 +1108,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 +1220,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); @@ -1509,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; @@ -1523,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) { @@ -1580,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; @@ -1588,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) { @@ -1813,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; @@ -1822,8 +1890,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 +1901,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); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 5e3aed4ae8..f53ded28ba 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -74,6 +74,10 @@ 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"); +/* 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 */ @@ -116,6 +120,8 @@ 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), + BRCMF_FW_ENTRY(BRCM_CC_4398_CHIP_ID, 0xFFFFFFF8, 4398D0), }; #define BRCMF_PCIE_FW_UP_TIMEOUT 5000 /* msec */ @@ -166,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 | \ @@ -239,10 +247,13 @@ 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_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 @@ -264,6 +275,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 @@ -833,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; @@ -905,6 +948,19 @@ static void brcmf_pcie_set_bar_coherent(struct brcmf_pciedev_info *devinfo) */ #define BRCMF_PCIE_SSCTRL_SSRESET_STATUS BIT(13) +/* + * Chips Broadcom's driver resets with a function 0 FLR rather than the + * chipcommon watchdog (bcmdhd dhdpcie_dongle_reset(), cc_wd_reset false). + * The BCM4383 shares the chip with its Bluetooth: while BT_REG_ON holds the + * chip up, the watchdog reset leaves the WLAN cores in a state where the + * downloaded firmware never comes up, and an F0 FLR leaves Bluetooth alone. + */ +static bool brcmf_pcie_reset_by_flr(struct brcmf_pciedev_info *devinfo) +{ + return brcmf_pcie_is_4389_family(devinfo) || + devinfo->pdev->device == BRCM_PCIE_4383_DEVICE_ID; +} + static int brcmf_pcie_flr(struct brcmf_pciedev_info *devinfo) { struct pci_dev *pdev = devinfo->pdev; @@ -971,13 +1027,13 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) val); /* 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. + * BCM4389 and BCM4383 are reset the way Broadcom's driver resets + * them, with an FLR: after a chipcommon watchdog reset the BCM4389's + * ARM does not boot a second firmware download, and the BCM4383's + * doesn't while its Bluetooth is on. */ brcmf_pcie_srpwr_request(devinfo); - if (devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID || - brcmf_pcie_flr(devinfo)) { + if (!brcmf_pcie_reset_by_flr(devinfo) || brcmf_pcie_flr(devinfo)) { brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); WRITECC32(devinfo, watchdog, 4); msleep(100); @@ -1216,6 +1272,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); @@ -1258,6 +1322,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 brcmf_pcie_is_4389_family(devinfo) || + 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) { @@ -1266,8 +1338,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); } } @@ -1373,7 +1444,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); @@ -1640,6 +1711,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 +1780,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 +1986,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 +2005,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 +2059,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 +2228,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 +2259,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 +2289,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 +2298,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) @@ -2190,6 +2366,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) @@ -2261,6 +2474,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, @@ -2723,14 +2967,10 @@ 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); - /* 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. */ @@ -2748,6 +2988,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); @@ -3174,6 +3417,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); @@ -3398,6 +3642,8 @@ 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_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 */ } 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..c453d6d0f2 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,8 @@ #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_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 @@ -99,6 +101,8 @@ #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_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 diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index 31de17d0e3..43efbf32e2 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -424,9 +424,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..b114c6be96 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,25 @@ 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. + * @pwr_reset_before_phy_off: the power-down turns the LTSSM off and pulses + * the soft power reset before the PHY powers down, as Google's + * exynos_pcie_rc_poweroff() does for the zuma family. Only zumapro so + * far: it hasn't run on a zuma board here. + */ +struct gs201_pcie_soc_data { + bool ctrl_reset_before_phy; + bool pwr_reset_before_phy_off; +}; + 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 +589,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 +649,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 +676,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); } @@ -689,9 +735,31 @@ static int gs201_pcie_bringup(struct gs201_pcie *gp, unsigned int last, return 0; } +/* + * zuma's exynos_pcie_rc_poweroff(): LTSSM off and a soft power reset pulse + * while the PHY still runs, before it is powered down + */ +static void gs201_pcie_pwr_reset_before_phy_off(struct gs201_pcie *gp) +{ + u32 val; + + if (!gp->data->pwr_reset_before_phy_off || !gp->phy_on) + return; + + gs201_trace(gp, "LTSSM off, soft power reset pulse (ELBI 0x054, 0x3a4 bit 1)"); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val & ~GS201_ELBI_SOFT_PWR_RESET); + usleep_range(20, 40); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_PWR_RESET); +} + /* Undo what the stages did, in reverse; the PHY stays out of isolation */ static void gs201_pcie_bringdown(struct gs201_pcie *gp) { + gs201_pcie_pwr_reset_before_phy_off(gp); gs201_pcie_phy_off(gp); if (gp->phy_inited) { gs201_trace(gp, "phy_exit"); @@ -818,7 +886,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 +1169,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 +1255,22 @@ 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 gs201_pcie_soc_data zumapro_pcie_data = { + .ctrl_reset_before_phy = true, + .pwr_reset_before_phy_off = 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,zumapro-pcie", .data = &zumapro_pcie_data }, + { .compatible = "google,zuma-pcie", .data = &zuma_pcie_data }, { } }; MODULE_DEVICE_TABLE(of, gs201_pcie_of_match); 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..66a80c8399 --- /dev/null +++ b/drivers/phy/samsung/phy-zuma-pcie.c @@ -0,0 +1,485 @@ +// 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 +#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; bit 10 tells the PMU the + * PHY has been configured + */ +#define ZUMA_PMU_PHY_BYPASS BIT(0) +#define ZUMA_PMU_PHY_CONFIGURED BIT(10) + +/* 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_MODE_SEL GENMASK(1, 0) +#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; + bool stock_link_steps; +}; + +/** + * struct zuma_pcie_phy_data - per-SoC steps + * @stock_link_steps: mark the PHY configured in the PMU at the end of + * power_on and return its input clock to the oscillator at power_off, + * as Google's exynos_pcie_rc_establish_link() and + * exynos_pcie_rc_poweroff() do. Only zumapro so far: zuma does them in + * Google's driver too, but they haven't run on a zuma board here. + */ +struct zuma_pcie_phy_data { + bool stock_link_steps; +}; + +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); + int ret; + + 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); + + if (!zp->stock_link_steps) + return 0; + + /* exynos_pcie_rc_establish_link(): mark the PHY configured */ + zuma_phy_trace(zp, "about to set PMU %#x bit 10 (PHY configured, SMC)", + zp->pmu_offset); + ret = regmap_update_bits(zp->pmu, zp->pmu_offset, + ZUMA_PMU_PHY_CONFIGURED, + ZUMA_PMU_PHY_CONFIGURED); + if (ret) { + dev_err(zp->dev, "PMU write failed: %d\n", ret); + return ret; + } + 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); + + /* + * exynos_pcie_rc_poweroff(): put the PHY's input clock back on the + * oscillator before the power-down + */ + if (zp->stock_link_steps) { + zuma_phy_trace(zp, "about to return the PHY clock to the oscillator (SOC 0x4000)"); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_MODE, + ZUMA_SOC_CLK_MODE_SEL, 0); + } + + 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; + const struct zuma_pcie_phy_data *data; + 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; + data = device_get_match_data(dev); + zp->stock_link_steps = data && data->stock_link_steps; + + /* 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 zuma_pcie_phy_data zumapro_pcie_phy_data = { + .stock_link_steps = true, +}; + +static const struct of_device_id zuma_pcie_phy_of_match[] = { + { .compatible = "google,zumapro-pcie-phy", .data = &zumapro_pcie_phy_data }, + { .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"); diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index 9ee77754d0..40e26951c7 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -344,6 +344,7 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PAD_CTRL_NFC_CLK 0x3e84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 +#define ZUMA_PHY_CTRL_PCIE1 0x3ec8 static const struct regmap_range zuma_pmu_registers[] = { /* reboot mode */ @@ -359,6 +360,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), /* Tensor G4's NFC reference clock pad, a clock of clk-exynos-clkout */