diff --git a/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml b/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml new file mode 100644 index 0000000000..cd708ab082 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/google,zuma-clock.yaml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/clock/google,zuma-clock.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google Tensor G3 clock controllers + +maintainers: + - Brett-Michael Green + +description: | + CMU_TOP supplies the HSI0 NoC and peripheral clocks to CMU_HSI0 from its + shared PLLs. CMU_HSI0 supplies USI2, the touchscreen's SPI, from the HSI0 + peripheral clock; its NoC path also takes the board-level HSI0 ALT clock. + CMU_APM supplies the APM mailbox, its internal memory and the always-on + GPIO banks from the always-on ALV PLL and the oscillator. + The external oscillator supplies the PLL reference and the oscillator mux + paths. + Clock identifiers are defined in dt-bindings/clock/google,zuma.h. + +properties: + compatible: + enum: + - google,zuma-cmu-top + - google,zuma-cmu-apm + - google,zuma-cmu-hsi0 + + reg: + maxItems: 1 + + "#clock-cells": + const: 1 + + clocks: + minItems: 1 + maxItems: 4 + + clock-names: + minItems: 1 + maxItems: 4 + +required: + - compatible + - reg + - "#clock-cells" + - clocks + - clock-names + +allOf: + - if: + properties: + compatible: + enum: + - google,zuma-cmu-top + - google,zuma-cmu-apm + then: + properties: + clocks: + items: + - description: External oscillator reference clock + clock-names: + items: + - const: oscclk + - if: + properties: + compatible: + const: google,zuma-cmu-hsi0 + then: + properties: + clocks: + items: + - description: External oscillator reference clock + - description: HSI0 NoC clock from CMU_TOP + - description: HSI0 peripheral clock from CMU_TOP + - description: HSI0 ALT input clock + clock-names: + items: + - const: oscclk + - const: bus + - const: peri + - const: alt + +additionalProperties: false + +examples: + - | + #include + + cmu_top: clock-controller@26040000 { + compatible = "google,zuma-cmu-top"; + reg = <0x26040000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; + + clock-controller@11000000 { + compatible = "google,zuma-cmu-hsi0"; + reg = <0x11000000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>, <&cmu_top CLK_DOUT_HSI0_NOC>, + <&cmu_top CLK_DOUT_HSI0_PERI>, <&hsi0_alt>; + clock-names = "oscclk", "bus", "peri", "alt"; + }; + +... diff --git a/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml b/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml index 58a0301f09..9163560a19 100644 --- a/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml +++ b/Documentation/devicetree/bindings/firmware/google,gs101-acpm-ipc.yaml @@ -25,6 +25,7 @@ properties: enum: - google,gs101-acpm-ipc - google,gs201-acpm-ipc + - google,zuma-acpm-ipc - google,zumapro-acpm-ipc "#clock-cells": @@ -111,7 +112,9 @@ allOf: - if: properties: compatible: - const: google,zumapro-acpm-ipc + enum: + - google,zuma-acpm-ipc + - google,zumapro-acpm-ipc then: properties: pmic: false diff --git a/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml b/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml new file mode 100644 index 0000000000..5d5bf1e370 --- /dev/null +++ b/Documentation/devicetree/bindings/iommu/google,gs201-pcie-sysmmu.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iommu/google,gs201-pcie-sysmmu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 PCIe System MMU used as a DMA window + +maintainers: + - Derek Ross + +description: + The Samsung System MMU (version 8.1) in front of the gs201 PCIe GEN4A_1 + controller. It is programmed with a 1:1 mapping of one reserved memory + region, so the PCIe device can reach that region and nothing else. + +properties: + compatible: + const: google,gs201-pcie-sysmmu + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + google,dma-window: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The reserved memory region (typically the PCIe device's + restricted-dma-pool) that is the only memory the PCIe device may + access. Not memory-region, which would make the pool this node's own + DMA bounce buffer, placing the page table inside the window. + + google,vid: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 7 + default: 1 + description: + The System MMU virtual ID translated by default (stock uses 1). No + kernel code assigns the controller's VID, so this must be confirmed with + a negative test. + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include + sysmmu@145c0000 { + compatible = "google,gs201-pcie-sysmmu"; + reg = <0x145c0000 0x10000>; + interrupts = ; + clocks = <&cmu_hsi2 17>, <&cmu_hsi2 55>; + google,vid = <1>; + }; diff --git a/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml b/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml index d1a6c6eda1..559da23935 100644 --- a/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml @@ -27,6 +27,7 @@ properties: - items: - enum: - google,gs201-mbox + - google,zuma-mbox - google,zumapro-mbox - const: google,gs101-mbox diff --git a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml index 5419f15224..5a94a65452 100644 --- a/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml +++ b/Documentation/devicetree/bindings/mfd/samsung,s2mpg14-pmic.yaml @@ -10,8 +10,9 @@ maintainers: - W4HO <87742609+W4HO-ham@users.noreply.github.com> description: | - S2MPG14 is the main PMIC paired with Google's Tensor G4. Its LDO4M and - LDO25M outputs supply the analog and digital touchscreen power rails. + S2MPG14 is the main PMIC paired with Google's Tensor G3 and Tensor G4. + Its LDO4M and LDO25M outputs supply the analog and digital touchscreen + power rails. properties: compatible: diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml index 38e9a0444f..8589631085 100644 --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml @@ -125,6 +125,11 @@ properties: NVRAM. This would normally be filled in by the bootloader from platform configuration data. + memory-region: + maxItems: 1 + description: A restricted-dma-pool region that all DMA of a PCIe device + bounces through, for platforms that limit the device's DMA to it. + clocks: items: - description: External Low Power Clock input (32.768KHz) diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml new file mode 100644 index 0000000000..d967492b9f --- /dev/null +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml @@ -0,0 +1,173 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pci/google,gs201-pcie.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 and zuma PCIe host controllers + +maintainers: + - Derek Ross + +description: + 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. zuma's Wi-Fi controller runs without the I/A, as on + stock. Legacy INTx interrupts are demultiplexed from the controller + interrupt by a child interrupt controller. + +allOf: + - $ref: /schemas/pci/pci-host-bridge.yaml# + - $ref: /schemas/pci/snps,dw-pcie-common.yaml# + - if: + properties: + compatible: + const: google,zuma-pcie + then: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 + +properties: + compatible: + enum: + - google,gs201-pcie + - google,zuma-pcie + + reg: + minItems: 3 + items: + - description: External local bus interface (ELBI) registers + - description: Data Bus Interface (DBI) registers, with the unrolled + iATU at offset 0x300000 + - description: PCIe configuration space region + - description: I/A sequencer registers + + reg-names: + minItems: 3 + items: + - const: elbi + - const: dbi + - const: config + - const: ia + + interrupts: + maxItems: 1 + + clocks: + minItems: 1 + maxItems: 8 + + phys: + maxItems: 1 + + phy-names: + const: pcie + + dma-coherent: true + + samsung,cmu: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The HSI clock controller (CMU) of this controller. Google's driver + turns the CMU's global automatic clock gating off before using the + controller; the driver can do the same, and reads the PCIe gate and + Q-channel state from it for diagnostics. + + samsung,sysreg: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the HSI system register controller + - description: offset of this controller's shareability register + description: + Needed with dma-coherent, to make the controller's DMA shareable. + + num-lanes: + maximum: 2 + + max-link-speed: + maximum: 4 + + legacy-interrupt-controller: + type: object + additionalProperties: false + + properties: + "#address-cells": + const: 0 + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + + required: + - "#address-cells" + - interrupt-controller + - "#interrupt-cells" + +required: + - compatible + - reg + - reg-names + - interrupts + - "#interrupt-cells" + - interrupt-map + - interrupt-map-mask + - phys + - phy-names + - reset-gpios + - legacy-interrupt-controller + +unevaluatedProperties: false + +examples: + - | + #include + #include + #include + + soc { + #address-cells = <1>; + #size-cells = <1>; + + pcie@14520000 { + compatible = "google,gs201-pcie"; + reg = <0x14520000 0x1400>, <0x14800000 0x301000>, + <0x60ffe000 0x2000>, <0x14500000 0x1000>; + reg-names = "elbi", "dbi", "config", "ia"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x60000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = ; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_1_intc 0>, + <0 0 0 2 &pcie_1_intc 1>, + <0 0 0 3 &pcie_1_intc 2>, + <0 0 0 4 &pcie_1_intc 3>; + clocks = <&cmu_hsi2 CLK_GOUT_HSI2_PCIE_GEN4_1_PCIE_003_G4X2_DWC_PCIE_CTL_INST_0_DBI_ACLK_UG>; + phys = <&pcie_1_phy>; + phy-names = "pcie"; + reset-gpios = <&gph2 0 GPIO_ACTIVE_LOW>; + samsung,cmu = <&cmu_hsi2>; + samsung,sysreg = <&sysreg_hsi2 0x730>; + dma-coherent; + num-lanes = <1>; + max-link-speed = <2>; + + pcie_1_intc: legacy-interrupt-controller { + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml new file mode 100644 index 0000000000..d0292e6f6c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,gs201-pcie-phy.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/google,gs201-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google gs201 PCIe PHY + +maintainers: + - Derek Ross + +description: + The PCIe Gen4 PHY of the Google gs201 (Tensor G2) SoC. Each instance is a + two-lane Samsung PHY with its PMA and PCS register blocks, a debug block + that selects the reference clock, and three reset lines that live in the + sub-control space of the PCIe controller it serves. Its isolation is + controlled from the PMU. + +properties: + compatible: + const: google,gs201-pcie-phy + + reg: + items: + - description: PMA registers + - description: PCS registers + - description: PHY reset registers in the controller's sub-control space + - description: UDBG (reference clock and PLL selection) registers + + reg-names: + items: + - const: pma + - const: pcs + - const: rst + - const: udbg + + clocks: + minItems: 1 + maxItems: 5 + + "#phy-cells": + const: 0 + + samsung,pmu-syscon: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the PMU system controller + - description: offset of this PHY's control (isolation) register + description: + The PMU and the offset of PHY_CTRL_PCIE_GEN4_x for this instance. + +required: + - compatible + - reg + - reg-names + - "#phy-cells" + - samsung,pmu-syscon + +additionalProperties: false + +examples: + - | + #include + + phy@14550000 { + compatible = "google,gs201-pcie-phy"; + reg = <0x14550000 0x2000>, <0x14540000 0x1000>, + <0x14521400 0x10>, <0x14560000 0xd000>; + reg-names = "pma", "pcs", "rst", "udbg"; + clocks = <&cmu_hsi2 CLK_GOUT_HSI2_PCIE_GEN4_1_PCS_PMA_INST_0_PHY_UDBG_I_APB_PCLK>; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + #phy-cells = <0>; + }; diff --git a/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml new file mode 100644 index 0000000000..8003eb7b5e --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/google,zuma-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google zuma PCIe Gen3 PHY + +maintainers: + - Brett-Michael Green + +description: + The one-lane PCIe Gen3 PHY of the Google zuma (Tensor G3) SoC's second + PCIe controller, which connects the Wi-Fi chip on Pixel 8 phones. Its + reference clock comes from an external PLL in the UDBG block, selected as + the PHY's input clock in the controller's SOC block. The PMU isolates the + PHY until it is released. + +properties: + compatible: + const: google,zuma-pcie-phy + + reg: + items: + - description: PMA registers + - description: PCS registers + - description: PHY reset registers in the controller's sub-control space + - description: UDBG (external PLL) registers + - description: SOC (PHY input clock selection) registers + + reg-names: + items: + - const: pma + - const: pcs + - const: rst + - const: udbg + - const: soc + + "#phy-cells": + const: 0 + + samsung,pmu-syscon: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + - items: + - description: phandle of the PMU system controller + - description: offset of this PHY's control (isolation) register + description: + The PMU and the offset of this PHY's isolation control. + +required: + - compatible + - reg + - reg-names + - "#phy-cells" + - samsung,pmu-syscon + +additionalProperties: false + +examples: + - | + phy@13160000 { + compatible = "google,zuma-pcie-phy"; + reg = <0x13160000 0x3000>, <0x13140000 0x5000>, + <0x13121400 0x10>, <0x13150000 0xd000>, + <0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + }; diff --git a/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml b/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml index 9a2a8867b6..870ad437ff 100644 --- a/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml @@ -37,6 +37,7 @@ properties: - enum: - google,gs101-usi - google,gs201-usi + - google,zuma-usi - google,zumapro-usi - samsung,exynos2200-usi - samsung,exynosautov9-usi diff --git a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml index 5acd0e0efb..2a181df90c 100644 --- a/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml +++ b/Documentation/devicetree/bindings/soc/samsung/samsung,exynos-sysreg.yaml @@ -27,6 +27,7 @@ properties: - google,gs201-peric0-sysreg - google,gs201-peric1-sysreg - google,gs201-vgpio2ap-sysreg + - google,zuma-hsi0-sysreg - google,zuma-ufs-sysreg - google,zumapro-apm-sysreg - google,zumapro-hsi0-sysreg diff --git a/Documentation/devicetree/bindings/spi/samsung,spi.yaml b/Documentation/devicetree/bindings/spi/samsung,spi.yaml index 2cc3ba1341..7feee66b25 100644 --- a/Documentation/devicetree/bindings/spi/samsung,spi.yaml +++ b/Documentation/devicetree/bindings/spi/samsung,spi.yaml @@ -33,6 +33,7 @@ properties: - items: - enum: - google,gs201-spi + - google,zuma-spi - google,zumapro-spi - const: google,gs101-spi - const: samsung,exynos7-spi diff --git a/MAINTAINERS b/MAINTAINERS index 4841af951f..1a68316b1c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11166,8 +11166,10 @@ P: Documentation/process/maintainer-soc-clean-dts.rst C: irc://irc.oftc.net/pixel6-kernel-dev F: Documentation/devicetree/bindings/clock/google,gs101-clock.yaml F: Documentation/devicetree/bindings/clock/google,gs201-clock.yaml +F: Documentation/devicetree/bindings/clock/google,zuma-clock.yaml F: Documentation/devicetree/bindings/clock/google,zumapro* F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml +F: Documentation/devicetree/bindings/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 @@ -11175,15 +11177,18 @@ F: Documentation/devicetree/bindings/usb/google,lga-dwc3.yaml F: arch/arm64/boot/dts/exynos/google/ F: drivers/clk/samsung/clk-gs101.c F: drivers/clk/samsung/clk-gs201.c +F: drivers/clk/samsung/clk-zuma.c F: drivers/clk/samsung/clk-zumapro.c F: drivers/phy/phy-google-usb.c F: drivers/soc/samsung/gs101-pmu.c 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 F: include/dt-bindings/clock/google,gs101* F: include/dt-bindings/clock/google,gs201* +F: include/dt-bindings/clock/google,zuma.h F: include/dt-bindings/clock/google,zumapro* K: [gG]oogle.?[tT]ensor diff --git a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index 074eee930f..ce5f958c27 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -46,6 +46,24 @@ enable-active-high; }; + /* + * WL_REG_ON of the BCM4398 (gph3-4, stock's wl_reg_on). Modelled as + * the root port's supply so the PCI pwrctrl core switches it around + * link training; bcmdhd waits 200 ms after raising it. With pcie_1 + * disabled nothing enables it, so the chip stays off. + */ + wlan_pwr: regulator-wlan { + compatible = "regulator-fixed"; + regulator-name = "wlan-reg-on"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + gpio = <&gph3 4 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <200000>; + pinctrl-0 = <&wlan_reg_on>; + pinctrl-names = "default"; + }; + chosen { /* * ABL requires bootargs to exist; it appends its own after these. @@ -114,6 +132,130 @@ 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>; + }; + }; +}; + +/* + * The main PMIC, behind the ACPM firmware. Its regulators are described + * with their consumers, which run them through the firmware. + */ +&acpm_ipc { + pmic-1 { + compatible = "samsung,s2mpg14-pmic"; + + regulators { + touch_avdd: ldo4m { + regulator-name = "touch-avdd"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; + + touch_vdd: ldo25m { + regulator-name = "touch-vdd"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + }; + }; + }; +}; + +/* + * 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"; + + /* + * ST FTM5 (SALIXP, chip id 36 40), as stock's fts node: 10 MHz, + * manual chip select. Not stock's axis inversion: salixp already + * reports in the panel's orientation. + */ + touchscreen@0 { + compatible = "st,salixp"; + reg = <0>; + spi-max-frequency = <10000000>; + interrupt-parent = <&gpn0>; + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&touch_vdd>; + avdd-supply = <&touch_avdd>; + reset-gpios = <&gpp21 2 GPIO_ACTIVE_LOW>; + touchscreen-size-x = <1344>; + touchscreen-size-y = <2992>; + pinctrl-names = "default"; + pinctrl-0 = <&ts_irq &ts_reset>; }; }; @@ -141,3 +283,7 @@ &ufs_0_phy { status = "okay"; }; + +&usi2_hsi0 { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 724ef95913..92c5bbcd64 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -160,6 +160,123 @@ }; }; +&pinctrl_custom_alive { + gpn0: gpn0-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn1: gpn1-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn2: gpn2-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn3: gpn3-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn4: gpn4-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn5: gpn5-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn6: gpn6-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn7: gpn7-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn8: gpn8-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + gpn9: gpn9-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + ts_irq: ts-irq-pins { + samsung,pins = "gpn0-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + }; +}; + +&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; @@ -288,6 +405,90 @@ }; }; +&pinctrl_peric1 { + gpp19: gpp19-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp20: gpp20-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp21: gpp21-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp24: gpp24-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp22: gpp22-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpp23: gpp23-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + ts_reset: ts-reset-pins { + samsung,pins = "gpp21-2"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + }; +}; + +&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 92bef7f97d..88f0dbeeea 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -5,13 +5,17 @@ * Addresses, interrupts and reservations are the ones a retail Pixel 8 Pro * (husky) runs with: its live device tree and Google's GPL zuma tree * (android-gs-shusky-6.1-android16). Nothing here is copied from gs101 or - * gs201. No clock, pinctrl or power-domain providers yet: the bootloader - * leaves what first light needs running, and the board's bootargs carry - * clk_ignore_unused and pd_ignore_unused. + * gs201. The clock providers describe only the touchscreen SPI's path, and + * there are no power-domain providers yet: the bootloader leaves what the + * rest needs running, and the board's bootargs carry clk_ignore_unused and + * pd_ignore_unused. */ +#include +#include #include #include +#include / { compatible = "google,zuma"; @@ -22,8 +26,12 @@ /* The pin controllers are numbered as in Tensor G4's driver data. */ 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; }; /* @@ -146,6 +154,15 @@ }; }; + firmware { + acpm_ipc: power-management { + compatible = "google,zuma-acpm-ipc"; + #clock-cells = <1>; + mboxes = <&ap2apm_mailbox>; + shmem = <&apm_sram>; + }; + }; + psci { compatible = "arm,psci-1.0"; method = "smc"; @@ -269,11 +286,27 @@ clock-output-names = "ufs_ref_stub"; }; + oscclk: clock-oscclk { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24576000>; + clock-output-names = "oscclk"; + }; + + /* The CAL's nominal I_CLK_HSI0_ALT rate. */ + hsi0_alt: clock-hsi0-alt { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <213000000>; + clock-output-names = "hsi0-alt"; + }; + soc: soc@0 { compatible = "simple-bus"; #address-cells = <1>; #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); @@ -318,6 +351,28 @@ interrupts = ; }; + pinctrl_peric1: pinctrl@10c40000 { + compatible = "google,zuma-pinctrl"; + reg = <0x10c40000 0x1000>; + clocks = <&clk_gpio_stub>; + clock-names = "pclk"; + interrupts = ; + }; + + cmu_hsi0: clock-controller@11000000 { + compatible = "google,zuma-cmu-hsi0"; + reg = <0x11000000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>, <&cmu_top CLK_DOUT_HSI0_NOC>, + <&cmu_top CLK_DOUT_HSI0_PERI>, <&hsi0_alt>; + clock-names = "oscclk", "bus", "peri", "alt"; + }; + + sysreg_hsi0: syscon@11020000 { + compatible = "google,zuma-hsi0-sysreg", "syscon"; + reg = <0x11020000 0x10000>; + }; + /* * USB control block: Exynos 2200's link registers, with the * eUSB2 PHY below as its high-speed PHY. The USB3/DP combo PHY @@ -346,6 +401,33 @@ status = "disabled"; }; + usi2_hsi0: usi@111d00c0 { + compatible = "google,zuma-usi", "samsung,exynos850-usi"; + reg = <0x111d00c0 0x20>; + clocks = <&cmu_hsi0 CLK_GOUT_HSI0_USI2_PCLK>, + <&cmu_hsi0 CLK_GOUT_HSI0_USI2_IP>; + clock-names = "pclk", "ipclk"; + samsung,sysreg = <&sysreg_hsi0 0x101c>; + samsung,mode = ; + #address-cells = <1>; + #size-cells = <1>; + ranges; + status = "disabled"; + + spi20: spi@111d0000 { + compatible = "google,zuma-spi", "google,gs101-spi"; + /* USI control starts at 0xc0; do not claim it twice. */ + reg = <0x111d0000 0xc0>; + interrupts = ; + clocks = <&cmu_hsi0 CLK_GOUT_HSI0_USI2_PCLK>, + <&cmu_hsi0 CLK_GOUT_HSI0_USI2_IP>; + clock-names = "spi", "spi_busclk0"; + #address-cells = <1>; + #size-cells = <0>; + status = "disabled"; + }; + }; + /* * The DWC3 controller, in peripheral mode as on stock (which * wraps it in Google's exynos9-dwusb glue). On a normal boot @@ -371,6 +453,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>; @@ -379,6 +469,58 @@ interrupts = ; }; + /* + * The Wi-Fi chip's controller (stock's pcie_1, ch-num 1): one + * Gen3 lane, at the addresses of stock's pcie@13120000. Its + * interrupts are its legacy INTx; stock's MSI lines are unused. + */ + pcie_1: pcie@13120000 { + compatible = "google,zuma-pcie"; + reg = <0x13120000 0x1400>, + <0x13400000 0x381000>, + <0x60ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x60000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = ; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_1_intc 1>, + <0 0 0 2 &pcie_1_intc 2>, + <0 0 0 3 &pcie_1_intc 3>, + <0 0 0 4 &pcie_1_intc 4>; + phys = <&pcie_1_phy>; + phy-names = "pcie"; + pinctrl-0 = <&pcie1_clkreq>, <&pcie1_perst>; + pinctrl-names = "default"; + reset-gpios = <&gph3 0 GPIO_ACTIVE_LOW>; + num-lanes = <1>; + max-link-speed = <3>; + status = "disabled"; + + pcie_1_intc: legacy-interrupt-controller { + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + + pcie_1_phy: phy@13160000 { + compatible = "google,zuma-pcie-phy"; + reg = <0x13160000 0x3000>, + <0x13140000 0x5000>, + <0x13121400 0x10>, + <0x13150000 0xd000>, + <0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + status = "disabled"; + }; + ufs_0: ufs@13200000 { compatible = "google,zuma-ufs", "google,zumapro-ufs"; reg = <0x13200000 0x200>, @@ -413,6 +555,35 @@ status = "disabled"; }; + pinctrl_custom_alive: pinctrl@15060000 { + compatible = "google,zuma-pinctrl"; + reg = <0x15060000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_GPIO_CUSTOM_ALIVE>; + clock-names = "pclk"; + + wakeup-interrupt-controller { + compatible = "google,zuma-wakeup-eint", + "google,zumapro-wakeup-eint"; + }; + }; + + ap2apm_mailbox: mailbox@15110000 { + compatible = "google,zuma-mbox", "google,gs101-mbox"; + reg = <0x15110000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_MAILBOX_AP>; + clock-names = "pclk"; + interrupts = ; + #mbox-cells = <0>; + }; + + cmu_apm: clock-controller@15400000 { + compatible = "google,zuma-cmu-apm"; + reg = <0x15400000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; + /* Writes go through EL3 (SMC), as on gs101. */ pmu_system_controller: system-controller@15460000 { compatible = "google,zuma-pmu"; @@ -443,6 +614,41 @@ "google,zumapro-wakeup-eint"; }; }; + + 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>; + clocks = <&cmu_apm CLK_GOUT_APM_INTMEM_ACLK>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x15700000 0x58000>; + no-memory-wc; + + /* The APM firmware's window, as one block. */ + firmware-sram@0 { + reg = <0x0 0x58000>; + }; + }; + + cmu_top: clock-controller@26040000 { + compatible = "google,zuma-cmu-top"; + reg = <0x26040000 0x8000>; + #clock-cells = <1>; + clocks = <&oscclk>; + clock-names = "oscclk"; + }; }; }; diff --git a/drivers/clk/samsung/Makefile b/drivers/clk/samsung/Makefile index c2df88230e..0b299f87f8 100644 --- a/drivers/clk/samsung/Makefile +++ b/drivers/clk/samsung/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov9.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-exynosautov920.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-gs101.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-gs201.o +obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-zuma.o obj-$(CONFIG_EXYNOS_ARM64_COMMON_CLK) += clk-zumapro.o obj-$(CONFIG_EXYNOS_ACPM_CLK) += clk-acpm.o obj-$(CONFIG_S3C64XX_COMMON_CLK) += clk-s3c64xx.o diff --git a/drivers/clk/samsung/clk-zuma.c b/drivers/clk/samsung/clk-zuma.c new file mode 100644 index 0000000000..ccb80f62e4 --- /dev/null +++ b/drivers/clk/samsung/clk-zuma.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google Tensor G3 (zuma) clocks for the touchscreen and its PMIC. + * + * Register layout and parents derived from Google's GPL CMUCAL tables in + * cal-if/zuma/cmucal-{sfr,node}.c, Copyright 2022 Samsung Electronics Co., Ltd. + * Only the path from CMU_TOP to HSI0's USI2 is described, with CMU_APM's + * clocks for the APM mailbox, its SRAM and the always-on GPIO banks. PLLs, + * muxes and dividers keep their firmware settings, except USI2's own + * divider, which sets the SPI rate. No PLL rate table is supplied. + */ + +#include +#include +#include +#include +#include + +#include + +#include "clk.h" +#include "clk-exynos-arm64.h" +#include "clk-pll.h" + +/* CMU_TOP, 0x26040000. PLL CON3 is the read-only rate source. */ +static const struct samsung_pll_clock top_plls[] __initconst = { + PLL(pll_0517x, CLK_FOUT_SHARED0, "zuma_shared0", "oscclk", + 0x004, 0x14c, NULL), + PLL(pll_0517x, CLK_FOUT_SHARED1, "zuma_shared1", "oscclk", + 0x008, 0x18c, NULL), + PLL(pll_0518x, CLK_FOUT_SHARED2, "zuma_shared2", "oscclk", + 0x00c, 0x1cc, NULL), + PLL(pll_0518x, CLK_FOUT_SHARED3, "zuma_shared3", "oscclk", + 0x010, 0x20c, NULL), + PLL(pll_0518x, CLK_FOUT_SPARE, "zuma_spare", "oscclk", + 0x014, 0x24c, NULL), +}; + +static const struct samsung_fixed_factor_clock top_factors[] __initconst = { + FFACTOR(CLK_SHARED0_D4, "zuma_shared0_d4", "zuma_shared0", 1, 4, 0), + FFACTOR(CLK_SHARED1_D4, "zuma_shared1_d4", "zuma_shared1", 1, 4, 0), + FFACTOR(CLK_SHARED2_D2, "zuma_shared2_d2", "zuma_shared2", 1, 2, 0), + FFACTOR(CLK_SHARED3_D2, "zuma_shared3_d2", "zuma_shared3", 1, 2, 0), +}; + +PNAME(mout_hsi0_noc_parents) = { + "zuma_shared0_d4", "zuma_shared1_d4", "zuma_shared2_d2", + "zuma_shared3_d2", "zuma_spare", "oscclk", "oscclk", "oscclk", +}; + +PNAME(mout_hsi0_peri_parents) = { + "zuma_shared0_d4", "zuma_shared2_d2", "zuma_shared3_d2", "zuma_spare", +}; + +static const struct samsung_mux_clock top_muxes[] __initconst = { + MUX_F(CLK_MOUT_HSI0_NOC, "zuma_mout_hsi0_noc", mout_hsi0_noc_parents, + 0x1094, 0, 3, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_PERI, "zuma_mout_hsi0_peri", mout_hsi0_peri_parents, + 0x1098, 0, 2, 0, CLK_MUX_READ_ONLY), +}; + +/* The hardware order is mux -> gate -> divider. HSI0 is firmware-owned. */ +static const struct samsung_gate_clock top_ro_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_NOC, "zuma_gout_hsi0_noc", "zuma_mout_hsi0_noc", + 0x20bc, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_HSI0_PERI, "zuma_gout_hsi0_peri", "zuma_mout_hsi0_peri", + 0x20c0, 21, CLK_IGNORE_UNUSED, 0), +}; + +static const struct samsung_div_clock top_dividers[] __initconst = { + DIV_F(CLK_DOUT_HSI0_NOC, "zuma_dout_hsi0_noc", "zuma_gout_hsi0_noc", + 0x188c, 0, 4, 0, CLK_DIVIDER_READ_ONLY), + DIV_F(CLK_DOUT_HSI0_PERI, "zuma_dout_hsi0_peri", "zuma_gout_hsi0_peri", + 0x1890, 0, 4, 0, CLK_DIVIDER_READ_ONLY), +}; + +static const struct samsung_cmu_info top_cmu __initconst = { + .pll_clks = top_plls, + .nr_pll_clks = ARRAY_SIZE(top_plls), + .fixed_factor_clks = top_factors, + .nr_fixed_factor_clks = ARRAY_SIZE(top_factors), + .mux_clks = top_muxes, + .nr_mux_clks = ARRAY_SIZE(top_muxes), + .ro_gate_clks = top_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(top_ro_gates), + .div_clks = top_dividers, + .nr_div_clks = ARRAY_SIZE(top_dividers), + .nr_clk_ids = CLK_DOUT_HSI0_PERI + 1, +}; + +static void __init zuma_top_init(struct device_node *np) +{ + exynos_arm64_register_cmu(NULL, np, &top_cmu); +} + +CLK_OF_DECLARE(zuma_cmu_top, "google,zuma-cmu-top", zuma_top_init); + +/* + * CMU_APM, 0x15400000. The always-on domain is firmware-owned, so it is + * read-only. ALV runs at the oscillator times 32. + */ +static const struct samsung_fixed_rate_clock apm_fixed_clks[] __initconst = { + FRATE(CLK_APM_PLL_ALV_DIV2, "zuma_apm_pll_alv_div2", NULL, 0, 393216000), + FRATE(CLK_APM_PLL_ALV_DIV4, "zuma_apm_pll_alv_div4", NULL, 0, 196608000), + FRATE(CLK_APM_PLL_ALV_DIV8, "zuma_apm_pll_alv_div8", NULL, 0, 98304000), + FRATE(CLK_APM_PLL_ALV_DIV16, "zuma_apm_pll_alv_div16", NULL, 0, 49152000), +}; + +PNAME(mout_apm_funcsrc_parents) = { + "zuma_apm_pll_alv_div2", "zuma_apm_pll_alv_div4", + "zuma_apm_pll_alv_div16", "zuma_apm_pll_alv_div8", +}; + +PNAME(mout_apm_func_parents) = { + "oscclk", "zuma_mout_apm_funcsrc", "pad_clk_apm", "oscclk", +}; + +static const struct samsung_mux_clock apm_muxes[] __initconst = { + MUX_F(CLK_MOUT_APM_FUNCSRC, "zuma_mout_apm_funcsrc", + mout_apm_funcsrc_parents, 0x1004, 0, 2, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_APM_FUNC, "zuma_mout_apm_func", mout_apm_func_parents, + 0x1000, 0, 2, 0, CLK_MUX_READ_ONLY), +}; + +static const struct samsung_div_clock apm_dividers[] __initconst = { + DIV_F(CLK_DOUT_APM_NOC, "zuma_dout_apm_noc", "zuma_gout_apm_func", + 0x1808, 0, 3, 0, CLK_DIVIDER_READ_ONLY), +}; + +static const struct samsung_gate_clock apm_ro_gates[] __initconst = { + GATE(CLK_GOUT_APM_FUNC, "zuma_gout_apm_func", "zuma_mout_apm_func", + 0x20d4, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_MAILBOX_AP, "zuma_gout_apm_mailbox_ap", + "zuma_dout_apm_noc", 0x211c, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_INTMEM_ACLK, "zuma_gout_apm_intmem_aclk", + "zuma_dout_apm_noc", 0x2108, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_INTMEM_PCLK, "zuma_gout_apm_intmem_pclk", + "zuma_dout_apm_noc", 0x210c, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_ALIVE, "zuma_gout_apm_gpio_alive", + "zuma_dout_apm_noc", 0x20d8, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_FAR_ALIVE, "zuma_gout_apm_gpio_far_alive", + "zuma_dout_apm_noc", 0x20dc, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_APM_GPIO_CUSTOM_ALIVE, "zuma_gout_apm_gpio_custom_alive", + "zuma_dout_apm_noc", 0x2000, 21, CLK_IGNORE_UNUSED, 0), +}; + +static const struct samsung_cmu_info apm_cmu __initconst = { + .fixed_clks = apm_fixed_clks, + .nr_fixed_clks = ARRAY_SIZE(apm_fixed_clks), + .mux_clks = apm_muxes, + .nr_mux_clks = ARRAY_SIZE(apm_muxes), + .div_clks = apm_dividers, + .nr_div_clks = ARRAY_SIZE(apm_dividers), + .ro_gate_clks = apm_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(apm_ro_gates), + .nr_clk_ids = CLK_GOUT_APM_GPIO_CUSTOM_ALIVE + 1, +}; + +/* CMU_HSI0, 0x11000000. Firmware keeps the domain powered. */ +PNAME(mout_hsi0_noc_user_parents) = { "oscclk", "zuma_dout_hsi0_noc" }; + +PNAME(mout_hsi0_alt_user_parents) = { "oscclk", "zuma_gout_hsi0_alt" }; + +PNAME(mout_hsi0_noc_local_parents) = { + "zuma_mout_hsi0_noc_user", "zuma_mout_hsi0_alt_user", +}; + +PNAME(mout_hsi0_peri_user_parents) = { "oscclk", "zuma_dout_hsi0_peri" }; + +PNAME(mout_hsi0_usi2_parents) = { "zuma_mout_hsi0_peri_user", "oscclk" }; + +static const struct samsung_mux_clock hsi0_muxes[] __initconst = { + MUX_F(CLK_MOUT_HSI0_NOC_USER, "zuma_mout_hsi0_noc_user", + mout_hsi0_noc_user_parents, 0x620, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_ALT_USER, "zuma_mout_hsi0_alt_user", + mout_hsi0_alt_user_parents, 0x600, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_NOC_LOCAL, "zuma_mout_hsi0_noc_local", + mout_hsi0_noc_local_parents, 0x1000, 0, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_PERI_USER, "zuma_mout_hsi0_peri_user", + mout_hsi0_peri_user_parents, 0x680, 4, 1, 0, CLK_MUX_READ_ONLY), + MUX_F(CLK_MOUT_HSI0_USI2, "zuma_mout_hsi0_usi2", mout_hsi0_usi2_parents, + 0x101c, 0, 1, 0, CLK_MUX_READ_ONLY), +}; + +static const struct samsung_div_clock hsi0_dividers[] __initconst = { + DIV(CLK_DOUT_HSI0_USI2, "zuma_dout_hsi0_usi2", + "zuma_gout_hsi0_usi2_source", 0x181c, 0, 4), +}; + +static const struct samsung_gate_clock hsi0_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_USI2_SOURCE, "zuma_gout_hsi0_usi2_source", + "zuma_mout_hsi0_usi2", 0x2120, 21, CLK_IGNORE_UNUSED, 0), + GATE(CLK_GOUT_HSI0_USI2_IP, "zuma_gout_hsi0_usi2_ip", + "zuma_dout_hsi0_usi2", 0x20fc, 21, + CLK_IGNORE_UNUSED | CLK_SET_RATE_PARENT, 0), + GATE(CLK_GOUT_HSI0_USI2_PCLK, "zuma_gout_hsi0_usi2_pclk", + "zuma_mout_hsi0_noc_local", 0x2100, 21, CLK_IGNORE_UNUSED, 0), +}; + +/* Firmware-owned gates are observed, never switched. */ +static const struct samsung_gate_clock hsi0_ro_gates[] __initconst = { + GATE(CLK_GOUT_HSI0_ALT, "zuma_gout_hsi0_alt", "hsi0-alt", + 0x204c, 21, CLK_IGNORE_UNUSED, 0), +}; + +/* USI2's gates run in manual mode; the rest of HSI0 is left alone. */ +static const unsigned long hsi0_regs[] __initconst = { + 0x2120, 0x20fc, 0x2100, +}; + +static const struct samsung_cmu_info hsi0_cmu __initconst = { + .mux_clks = hsi0_muxes, + .nr_mux_clks = ARRAY_SIZE(hsi0_muxes), + .div_clks = hsi0_dividers, + .nr_div_clks = ARRAY_SIZE(hsi0_dividers), + .gate_clks = hsi0_gates, + .nr_gate_clks = ARRAY_SIZE(hsi0_gates), + .ro_gate_clks = hsi0_ro_gates, + .nr_ro_gate_clks = ARRAY_SIZE(hsi0_ro_gates), + .nr_clk_ids = CLK_GOUT_HSI0_USI2_PCLK + 1, + .clk_regs = hsi0_regs, + .nr_clk_regs = ARRAY_SIZE(hsi0_regs), + .clk_name = "bus", +}; + +static int __init zuma_cmu_probe(struct platform_device *pdev) +{ + const struct samsung_cmu_info *cmu = device_get_match_data(&pdev->dev); + + exynos_arm64_register_cmu(&pdev->dev, pdev->dev.of_node, cmu); + return 0; +} + +static const struct of_device_id zuma_cmu_match[] = { + { .compatible = "google,zuma-cmu-apm", .data = &apm_cmu }, + { .compatible = "google,zuma-cmu-hsi0", .data = &hsi0_cmu }, + { } +}; + +static struct platform_driver zuma_cmu_driver __refdata = { + .driver = { + .name = "zuma-cmu", + .of_match_table = zuma_cmu_match, + .suppress_bind_attrs = true, + }, + .probe = zuma_cmu_probe, +}; + +static int __init zuma_cmu_init(void) +{ + return platform_driver_register(&zuma_cmu_driver); +} +core_initcall(zuma_cmu_init); diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index 45f3a56168..dfac2a004c 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -42,6 +42,7 @@ #define ACPM_GS101_INITDATA_BASE 0xa000 #define ACPM_GS201_INITDATA_BASE 0xa000 +#define ACPM_ZUMA_INITDATA_BASE 0xa000 #define ACPM_ZUMAPRO_INITDATA_BASE 0xa000 /* Sanity limit for the channel count read from SRAM. */ @@ -738,9 +739,15 @@ static int acpm_channels_init(struct acpm_info *acpm) achan->chan = mbox_request_channel(cl, 0); if (IS_ERR(achan->chan)) { - dev_warn(dev, "chan %d: no mailbox channel (%pe), skipped\n", - i, achan->chan); + ret = PTR_ERR(achan->chan); achan->chan = NULL; + /* The mailbox may simply not have probed yet. */ + if (ret == -EPROBE_DEFER) + return dev_err_probe(dev, ret, + "chan %d: no mailbox channel yet\n", + i); + dev_warn(dev, "chan %d: no mailbox channel (%pe), skipped\n", + i, ERR_PTR(ret)); continue; } @@ -975,6 +982,11 @@ static const struct acpm_match_data acpm_gs201 = { .acpm_clk_dev_name = "gs201-acpm-clk", }; +static const struct acpm_match_data acpm_zuma = { + .initdata_base = ACPM_ZUMA_INITDATA_BASE, + .acpm_clk_dev_name = "zuma-acpm-clk", +}; + static const struct acpm_match_data acpm_zumapro = { .initdata_base = ACPM_ZUMAPRO_INITDATA_BASE, .acpm_clk_dev_name = "zumapro-acpm-clk", @@ -987,6 +999,9 @@ static const struct of_device_id acpm_match[] = { }, { .compatible = "google,gs201-acpm-ipc", .data = &acpm_gs201, + }, { + .compatible = "google,zuma-acpm-ipc", + .data = &acpm_zuma, }, { .compatible = "google,zumapro-acpm-ipc", .data = &acpm_zumapro, diff --git a/drivers/input/touchscreen/salixp.c b/drivers/input/touchscreen/salixp.c index c1752a8583..f7c665d96c 100644 --- a/drivers/input/touchscreen/salixp.c +++ b/drivers/input/touchscreen/salixp.c @@ -97,7 +97,7 @@ #define SALIXP_SCAN_ALL 0xff #define SALIXP_EVT_STATUS 0x43 #define SALIXP_ECHO_TYPE 0x01 -#define SALIXP_ECHO_MS 50 +#define SALIXP_ECHO_MS 2500 #define SALIXP_TOUCH_POLL_MS 10 #define SALIXP_TOUCH_LOG_MAX 8 #define SALIXP_CS_DELAY_US 10 @@ -431,9 +431,11 @@ static int salixp_poll_cx(struct salixp *ts) * and address 0x20000000, the same prefix as the flash commands, so * this does not send it. The echo is 0x43 0x01 followed by the * command. Stock treats a missing echo as failure after retries - * (ftsIO.c:523-547). This sends the scan command once and fails - * probe if the echo does not arrive. It does not send it again. - * No interrupt is requested. + * (ftsIO.c:523-547), waiting up to 2.5 s for it (TIEMOUT_ECHO in + * ftsCore.c:330). Husky's firmware reports a forced calibration + * first and echoes about 60 ms after the command. This sends the + * scan command once, stops at the echo and fails probe if it does + * not arrive. It does not send it again. No interrupt is requested. */ static int salixp_sense_on(struct salixp *ts) { @@ -460,7 +462,8 @@ static int salixp_sense_on(struct salixp *ts) return ret; deadline = ktime_add_ms(ktime_get(), SALIXP_ECHO_MS); - while (ktime_before(ktime_get(), deadline) && n < SALIXP_POLL_MAX_EVT) { + while (!echo && ktime_before(ktime_get(), deadline) && + n < SALIXP_POLL_MAX_EVT) { ret = salixp_read_fifo(ts, event); if (ret) return ret; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index 9371c14899..0ced0b8c26 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -87,6 +87,8 @@ struct brcmf_bus_dcmd { * @get_memdump: obtain device memory dump in provided buffer. * @get_blob: obtain a firmware blob. * @remove: initiate unbind of the device. + * @d2h_mb_data: mailbox data the device sent as a control message + * (optional). * * This structure provides an abstract interface towards the * bus specific driver. For control messages to common driver @@ -108,6 +110,7 @@ struct brcmf_bus_ops { void (*debugfs_create)(struct device *dev); int (*reset)(struct device *dev); void (*remove)(struct device *dev); + void (*d2h_mb_data)(struct device *dev, u32 data); }; @@ -130,6 +133,7 @@ struct brcmf_bus_msgbuf { u16 max_flowrings; u16 max_submissionrings; u16 max_completionrings; + u32 d2h_sync; }; @@ -282,6 +286,12 @@ int brcmf_bus_reset(struct brcmf_bus *bus) return bus->ops->reset(bus->dev); } +static inline void brcmf_bus_d2h_mb_data(struct brcmf_bus *bus, u32 data) +{ + if (bus->ops->d2h_mb_data) + bus->ops->d2h_mb_data(bus->dev, data); +} + static inline void brcmf_bus_remove(struct brcmf_bus *bus) { if (!bus->ops->remove) { diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 872c48806d..a34836a388 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; @@ -2377,6 +2406,76 @@ static void brcmf_set_join_pref(struct brcmf_if *ifp, bphy_err(drvr, "Set join_pref error (%d)\n", err); } +static u32 ssid_len_of(struct cfg80211_connect_params *sme) +{ + return min_t(u32, sme->ssid_len, IEEE80211_MAX_SSID_LEN); +} + +/* + * The "join" iovar with versioned parameters (wl_extjoin_params_v1_t), as + * Broadcom's driver fills it (bcmdhd wl_cfg80211.c + * wl_fillup_assoc_params_v1()). @chanspec 0 means no channel. + */ +static s32 brcmf_join_v1(struct brcmf_if *ifp, + struct cfg80211_connect_params *sme, u32 ssid_len, + u16 chanspec) +{ + struct brcmf_pub *drvr = ifp->drvr; + struct brcmf_ext_join_params_v1_le *jp; + size_t len; + s32 err; + + len = offsetof(struct brcmf_ext_join_params_v1_le, assoc_le) + + offsetof(struct brcmf_assoc_params_v1_le, chanspec_list); + if (chanspec) + len += sizeof(u16); + + /* room for the one chanspec */ + jp = kzalloc(sizeof(*jp) + sizeof(__le16), GFP_KERNEL); + if (!jp) + return -ENOMEM; + + jp->ssid_le.SSID_len = cpu_to_le32(ssid_len); + memcpy(jp->ssid_le.SSID, sme->ssid, ssid_len); + + jp->scan_le.scan_type = -1; + jp->scan_le.home_time = cpu_to_le32(-1); + if (chanspec) { + jp->scan_le.active_time = + cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS); + jp->scan_le.passive_time = + cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS); + jp->scan_le.nprobes = + cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS / + BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS); + jp->assoc_le.chanspec_num = cpu_to_le32(1); + jp->assoc_le.chanspec_list[0] = cpu_to_le16(chanspec); + } else { + jp->scan_le.active_time = cpu_to_le32(-1); + jp->scan_le.passive_time = cpu_to_le32(-1); + jp->scan_le.nprobes = cpu_to_le32(-1); + } + + if (sme->bssid) + memcpy(jp->assoc_le.bssid, sme->bssid, ETH_ALEN); + else + eth_broadcast_addr(jp->assoc_le.bssid); + + /* get the firmware's own error code for the log */ + ifp->fwil_fwerr = true; + err = brcmf_fil_bsscfg_data_set(ifp, "join", jp, len); + ifp->fwil_fwerr = false; + kfree(jp); + + if (err) + bphy_err(drvr, "join (v1, chanspec 0x%04x, %zu bytes) failed: firmware error %d\n", + chanspec, len, err); + else + brcmf_dbg(CONN, "join (v1, chanspec 0x%04x) sent\n", chanspec); + + return err ? -EBADE : 0; +} + static s32 brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, struct cfg80211_connect_params *sme) @@ -2531,6 +2630,15 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, if (err) goto done; } + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_JOIN_V1)) { + brcmf_set_join_pref(ifp, &sme->bss_select); + err = brcmf_join_v1(ifp, sme, ssid_len_of(sme), + cfg->channel ? chanspec : 0); + if (!err) + goto done; + goto set_ssid; + } + /* Join with specific BSSID and cached SSID * If SSID is zero join based on BSSID only */ @@ -2594,6 +2702,8 @@ brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev, /* This is it. join command worked, we are done */ goto done; +set_ssid: + ssid_len = ssid_len_of(sme); /* join command failed, fallback to set ssid */ memset(&join_params, 0, sizeof(join_params)); join_params_size = sizeof(join_params.ssid_le); @@ -3436,7 +3546,8 @@ static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg) bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf; if (bss_list->count != 0 && - bss_list->version != BRCMF_BSS_INFO_VERSION) { + bss_list->version != BRCMF_BSS_INFO_VERSION && + bss_list->version != BRCMF_BSS_INFO_VERSION_114) { bphy_err(drvr, "Version %d != WL_BSS_INFO_VERSION\n", bss_list->version); return -EOPNOTSUPP; @@ -7068,6 +7179,11 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg, band = wiphy->bands[NL80211_BAND_2GHZ]; } else if (ch.band == BRCMU_CHAN_BAND_5G) { band = wiphy->bands[NL80211_BAND_5GHZ]; + } else if (ch.band == BRCMU_CHAN_BAND_6G) { + /* 6 GHz is not supported yet */ + brcmf_dbg(INFO, "skipping 6 GHz chanspec 0x%x\n", + ch.chspec); + continue; } else { bphy_err(drvr, "Invalid channel Spec. 0x%x.\n", ch.chspec); @@ -7663,7 +7779,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 75b0af85f7..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 @@ -162,6 +164,19 @@ struct sbconfig { #define SRCI_SRBSZ_SHIFT 0 #define SR_BSZ_BASE 14 +/* SYSMEM coreinfo as laid out on the BCM4389: RAM bank count in bits 4:0, + * ROM bank count in bits 9:5, and the ROM banks come first in the bank + * index space. Core revision 12 moved both counts up. + */ +#define SYSMEM_SRCI_SRNB_MASK 0x0000001f +#define SYSMEM_SRCI_SRNB_SHIFT 0 +#define SYSMEM_SRCI_ROMNB_MASK 0x000003e0 +#define SYSMEM_SRCI_ROMNB_SHIFT 5 +#define SYSMEM_SRCI_NEW_SRNB_MASK 0x00ff0000 +#define SYSMEM_SRCI_NEW_SRNB_SHIFT 16 +#define SYSMEM_SRCI_NEW_ROMNB_MASK 0xff000000 +#define SYSMEM_SRCI_NEW_ROMNB_SHIFT 24 + struct sbsocramregs { u32 coreinfo; u32 bwalloc; @@ -216,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 { @@ -492,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; @@ -660,19 +814,46 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem) u32 coreinfo; u32 idx; u32 nb; + u32 nrb; u32 banksize; if (!brcmf_chip_iscoreup(&sysmem->pub)) brcmf_chip_resetcore(&sysmem->pub, 0, 0, 0); coreinfo = brcmf_chip_core_read32(sysmem, SYSMEMREGOFFS(coreinfo)); - nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT; + + switch (sysmem->chip->pub.chip) { + case BRCM_CC_4389_CHIP_ID: + case BRCM_CC_4398_CHIP_ID: + /* Count the RAM banks only, and skip the ROM banks in + * front of them. + */ + if (sysmem->pub.rev >= 12) { + nb = (coreinfo & SYSMEM_SRCI_NEW_SRNB_MASK) >> + SYSMEM_SRCI_NEW_SRNB_SHIFT; + nrb = (coreinfo & SYSMEM_SRCI_NEW_ROMNB_MASK) >> + SYSMEM_SRCI_NEW_ROMNB_SHIFT; + } else { + nb = (coreinfo & SYSMEM_SRCI_SRNB_MASK) >> + SYSMEM_SRCI_SRNB_SHIFT; + nrb = (coreinfo & SYSMEM_SRCI_ROMNB_MASK) >> + SYSMEM_SRCI_ROMNB_SHIFT; + } + break; + default: + nb = (coreinfo & SRCI_SRNB_MASK) >> SRCI_SRNB_SHIFT; + nrb = 0; + break; + } for (idx = 0; idx < nb; idx++) { - brcmf_chip_socram_banksize(sysmem, idx, &banksize); + brcmf_chip_socram_banksize(sysmem, nrb + idx, &banksize); memsize += banksize; } + brcmf_dbg(INFO, "SYSMEM rev %u coreinfo 0x%08x: %u ROM, %u RAM banks\n", + sysmem->pub.rev, coreinfo, nrb, nb); + return memsize; } @@ -745,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; @@ -963,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; @@ -995,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) { @@ -1042,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); @@ -1085,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); @@ -1372,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/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c index d2ae679856..ee38264ef9 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c @@ -1186,7 +1186,8 @@ void brcmf_bus_cancel_reset_work(struct brcmf_bus *bus_if) { mutex_lock(&bus_if->bus_reset_lock); bus_if->removing = true; - if (bus_if->drvr) + /* bus_reset is only initialised once the bus has started */ + if (bus_if->drvr && bus_if->drvr->bus_reset.func) cancel_work_sync(&bus_if->drvr->bus_reset); mutex_unlock(&bus_if->bus_reset_lock); } diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index 488364ef8f..85c1ef8ff4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -45,6 +45,7 @@ static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { { BRCMF_FEAT_SAE, "sae " }, { BRCMF_FEAT_FWAUTH, "idauth" }, { BRCMF_FEAT_SAE_EXT, "sae_ext" }, + { BRCMF_FEAT_HOST_SFHLLC, "host_sfhllc" }, }; #ifdef DEBUG @@ -156,6 +157,23 @@ static void brcmf_feat_wlc_version_overrides(struct brcmf_pub *drv) brcmf_dbg(INFO, "WLC version: %d.%d\n", major, minor); + /* + * Versioned "join" parameters (wl_extjoin_params_v1_t), by the + * same WLC version test as Broadcom's driver (bcmdhd + * wl_cfg80211.c, MIN_JOINEXT_V1_*): 14.2 or 14.4, 16.1 and later + * on 16, or 17 and later. 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 || + 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); + for (i = 0; i < ARRAY_SIZE(brcmf_feat_wlcfeat_map); i++) { e = &brcmf_feat_wlcfeat_map[i]; if (major > e->min_ver_major || @@ -340,12 +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: 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 31f8695ca4..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) \ @@ -59,7 +61,11 @@ BRCMF_FEAT_DEF(SCAN_V2) \ BRCMF_FEAT_DEF(PMKID_V2) \ BRCMF_FEAT_DEF(PMKID_V3) \ - BRCMF_FEAT_DEF(SAE_EXT) + BRCMF_FEAT_DEF(SAE_EXT) \ + BRCMF_FEAT_DEF(JOIN_V1) \ + 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 e74a23e118..be19134f07 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -19,6 +19,8 @@ #define BRCMF_ARP_OL_PEER_AUTO_REPLY 0x00000008 #define BRCMF_BSS_INFO_VERSION 109 /* curr ver of brcmf_bss_info_le struct */ +/* v114 (the BCM4398's firmware): v109 with EHT fields appended */ +#define BRCMF_BSS_INFO_VERSION_114 114 #define BRCMF_BSS_RSSI_ON_CHANNEL 0x0004 #define BRCMF_STA_BRCM 0x00000001 /* Running a Broadcom driver */ @@ -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 */ @@ -533,6 +541,34 @@ struct brcmf_ext_join_params_le { struct brcmf_assoc_params_le assoc_le; }; +/** + * struct brcmf_assoc_params_v1_le - versioned association parameters. + * + * @version: structure version (left 0, as Broadcom's driver does). + * @flags: ASSOC_HINT_BSSID_PRESENT etc. + * @bssid: target BSSID, or broadcast. + * @bssid_cnt: 0: use @chanspec_num and the single @bssid. + * @chanspec_num: 0: all channels, else count of @chanspec_list entries. + * @chanspec_list: chanspecs. + */ +struct brcmf_assoc_params_v1_le { + __le16 version; + __le16 flags; + u8 bssid[ETH_ALEN]; + __le16 bssid_cnt; + __le32 chanspec_num; + __le16 chanspec_list[]; +}; + +/* extended join params, versioned (wl_extjoin_params_v1_t) */ +struct brcmf_ext_join_params_v1_le { + __le16 version; + __le16 pad; + struct brcmf_ssid_le ssid_le; + struct brcmf_join_scan_params_le scan_le; + struct brcmf_assoc_params_v1_le assoc_le; +}; + struct brcmf_wsec_key { u32 index; /* key index */ u32 len; /* key length */ diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index 069ba70166..93eebe6ceb 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ #include "proto.h" #include "msgbuf.h" #include "commonring.h" +#include "feature.h" #include "flowring.h" #include "bus.h" #include "tracepoint.h" @@ -47,9 +49,11 @@ #define MSGBUF_TYPE_RX_CMPLT 0x12 #define MSGBUF_TYPE_LPBK_DMAXFER 0x13 #define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14 +#define MSGBUF_TYPE_H2D_MAILBOX_DATA 0x23 +#define MSGBUF_TYPE_D2H_MAILBOX_DATA 0x24 #define NR_TX_PKTIDS 2048 -#define NR_RX_PKTIDS 1024 +#define NR_RX_PKTIDS 2048 #define BRCMF_IOCTL_REQ_PKTID 0xFFFE @@ -62,6 +66,9 @@ #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_11 0x02 #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07 +/* TX post: the data buffer starts with a host-built 802.3 + LLC/SNAP header */ +#define BRCMF_MSGBUF_TXPOST_FLAGS_HOST_SFH_LLC 0x10 +#define BRCMF_MSGBUF_SFH_LLC_LEN 8 #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5 #define BRCMF_MSGBUF_TX_FLUSH_CNT1 32 @@ -73,6 +80,13 @@ #define BRCMF_MAX_TXSTATUS_WAIT_RETRIES 10 +/* Sequence number ("epoch") in the common header of each message on the + * H2D control and rxpost submission rings, modulo 253; the first message + * carries 1. + */ +#define BRCMF_MSGBUF_H2D_EPOCH_MODULO 253 +#define BRCMF_MSGBUF_H2D_EPOCH_INIT (BRCMF_MSGBUF_H2D_EPOCH_MODULO + 1) + struct msgbuf_common_hdr { u8 msgtype; u8 ifidx; @@ -126,6 +140,23 @@ struct msgbuf_completion_hdr { __le16 flow_ring_id; }; +/* + * Mailbox data as control messages, for firmware that doesn't use the + * shared-memory mailbox (Broadcom's h2d_mailbox_data and d2h_mailbox_data). + */ +struct msgbuf_h2d_mailbox_data { + struct msgbuf_common_hdr msg; + __le32 mb_data; + __le32 rsvd[7]; +}; + +struct msgbuf_d2h_mailbox_data { + struct msgbuf_common_hdr msg; + struct msgbuf_completion_hdr compl_hdr; + __le32 mb_data; + __le32 rsvd; +}; + /* Data struct for the MSGBUF_TYPE_GEN_STATUS */ struct msgbuf_gen_status { struct msgbuf_common_hdr msg; @@ -258,6 +289,10 @@ struct brcmf_msgbuf { u16 data_seq_no; 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; @@ -285,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; }; @@ -292,6 +329,15 @@ struct brcmf_msgbuf_pktids { static void brcmf_msgbuf_rxbuf_ioctlresp_post(struct brcmf_msgbuf *msgbuf); +/* Called with the ring's write slot reserved, once the message is final. */ +static void brcmf_msgbuf_set_epoch(struct brcmf_msgbuf *msgbuf, u32 ringid, + struct msgbuf_common_hdr *msg) +{ + msg->rsvd0 = msgbuf->h2d_seqnum[ringid] % BRCMF_MSGBUF_H2D_EPOCH_MODULO; + msgbuf->h2d_seqnum[ringid]++; +} + + static struct brcmf_msgbuf_pktids * brcmf_msgbuf_init_pktids(u32 nr_array_entries, enum dma_data_direction direction) @@ -320,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; @@ -335,20 +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; count = 0; do { (*idx)++; - if (*idx == pktids->array_size) - *idx = 0; + 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; @@ -358,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; } @@ -371,7 +428,7 @@ brcmf_msgbuf_get_pktid(struct device *dev, struct brcmf_msgbuf_pktids *pktids, struct brcmf_msgbuf_pktid *pktid; struct sk_buff *skb; - if (idx >= pktids->array_size) { + if (idx == 0 || idx >= pktids->array_size) { brcmf_err("Invalid packet id %d (max %d)\n", idx, pktids->array_size); return NULL; @@ -451,6 +508,7 @@ static int brcmf_msgbuf_tx_ioctl(struct brcmf_pub *drvr, int ifidx, msgbuf->reqid++; request = (struct msgbuf_ioctl_req_hdr *)ret_ptr; + memset(request, 0, sizeof(*request)); request->msg.msgtype = MSGBUF_TYPE_IOCTLPTR_REQ; request->msg.ifidx = (u8)ifidx; request->msg.flags = 0; @@ -463,6 +521,8 @@ static int brcmf_msgbuf_tx_ioctl(struct brcmf_pub *drvr, int ifidx, request->input_buf_len = cpu_to_le16(buf_len); request->req_buf_addr.high_addr = cpu_to_le32(msgbuf->ioctbuf_phys_hi); request->req_buf_addr.low_addr = cpu_to_le32(msgbuf->ioctbuf_phys_lo); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &request->msg); if (buf) memcpy(msgbuf->ioctbuf, buf, buf_len); else @@ -642,6 +702,7 @@ brcmf_msgbuf_flowring_create_worker(struct brcmf_msgbuf *msgbuf, } create = (struct msgbuf_tx_flowring_create_req *)ret_ptr; + memset(create, 0, sizeof(*create)); create->msg.msgtype = MSGBUF_TYPE_FLOW_RING_CREATE; create->msg.ifidx = work->ifidx; create->msg.request_id = 0; @@ -655,6 +716,8 @@ brcmf_msgbuf_flowring_create_worker(struct brcmf_msgbuf *msgbuf, create->flow_ring_addr.low_addr = cpu_to_le32(address & 0xffffffff); create->max_items = cpu_to_le16(BRCMF_H2D_TXFLOWRING_MAX_ITEM); create->len_item = cpu_to_le16(BRCMF_H2D_TXFLOWRING_ITEMSIZE); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &create->msg); brcmf_dbg(MSGBUF, "Send Flow Create Req flow ID %d for peer %pM prio %d ifindex %d\n", flowid, work->da, create->tid, work->ifidx); @@ -718,6 +781,60 @@ static u32 brcmf_msgbuf_flowring_create(struct brcmf_msgbuf *msgbuf, int ifidx, } +/* + * Host short-form header + LLC (firmware capability "host_sfhllc"): the + * host turns the Ethernet frame into 802.3 + LLC/SNAP (RFC 1042, or + * bridge-tunnel for the 802.1H types) before posting it, as Broadcom's + * driver does (bcmdhd dhd_common.c dhd_ether_to_8023_hdr(), dhd_msgbuf.c + * BCMPCIE_TXPOST_FLAGS_HOST_SFH_LLC), and turns it back on completion. + */ +static int brcmf_msgbuf_sfh_llc_insert(struct sk_buff *skb) +{ + u8 *p; + u16 type; + + if (skb->len < ETH_HLEN) + return -EINVAL; + if (skb_headroom(skb) < BRCMF_MSGBUF_SFH_LLC_LEN && + pskb_expand_head(skb, BRCMF_MSGBUF_SFH_LLC_LEN, 0, GFP_ATOMIC)) + return -ENOMEM; + + type = get_unaligned_be16(skb->data + 2 * ETH_ALEN); + p = skb_push(skb, BRCMF_MSGBUF_SFH_LLC_LEN); + memmove(p, p + BRCMF_MSGBUF_SFH_LLC_LEN, 2 * ETH_ALEN); + put_unaligned_be16(skb->len - ETH_HLEN, p + 2 * ETH_ALEN); + p += ETH_HLEN; + p[0] = 0xaa; + p[1] = 0xaa; + p[2] = 0x03; + p[3] = 0x00; + p[4] = 0x00; + p[5] = (type == 0x80f3 || type == 0x8137) ? 0xf8 : 0x00; + put_unaligned_be16(type, p + 6); + return 0; +} + +static void brcmf_msgbuf_sfh_llc_remove(struct sk_buff *skb) +{ + u8 *p = skb->data; + u16 type; + + if (skb->len < ETH_HLEN + BRCMF_MSGBUF_SFH_LLC_LEN || + get_unaligned_be16(p + 2 * ETH_ALEN) >= ETH_P_802_3_MIN || + p[ETH_HLEN] != 0xaa || p[ETH_HLEN + 1] != 0xaa) + return; + + type = get_unaligned_be16(p + ETH_HLEN + 6); + memmove(p + BRCMF_MSGBUF_SFH_LLC_LEN, p, 2 * ETH_ALEN); + p = skb_pull(skb, BRCMF_MSGBUF_SFH_LLC_LEN); + put_unaligned_be16(type, p + 2 * ETH_ALEN); +} + +static bool brcmf_msgbuf_sfh_llc(struct brcmf_msgbuf *msgbuf) +{ + return msgbuf->drvr->feat_flags & BIT(BRCMF_FEAT_HOST_SFHLLC); +} + static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) { struct brcmf_flowring *flow = msgbuf->flow; @@ -730,6 +847,8 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) u32 pktid; struct msgbuf_tx_msghdr *tx_msghdr; u64 address; + u8 ethhdr[ETH_HLEN]; + bool sfh; commonring = msgbuf->flowrings[flowid]; if (!brcmf_commonring_write_available(commonring)) @@ -746,9 +865,15 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) break; } skb_orphan(skb); + memcpy(ethhdr, skb->data, ETH_HLEN); + sfh = brcmf_msgbuf_sfh_llc(msgbuf) && + !brcmf_msgbuf_sfh_llc_insert(skb); if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, - msgbuf->tx_pktids, skb, ETH_HLEN, - &physaddr, &pktid)) { + msgbuf->tx_pktids, skb, + sfh ? 0 : ETH_HLEN, + &physaddr, &pktid, false)) { + if (sfh) + brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); bphy_err(drvr, "No PKTID available !!\n"); break; @@ -757,6 +882,8 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) if (!ret_ptr) { brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, msgbuf->tx_pktids, pktid); + if (sfh) + brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); break; } @@ -768,11 +895,19 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) tx_msghdr->msg.request_id = cpu_to_le32(pktid + 1); tx_msghdr->msg.ifidx = brcmf_flowring_ifidx_get(flow, flowid); tx_msghdr->flags = BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3; + if (sfh) + tx_msghdr->flags |= + BRCMF_MSGBUF_TXPOST_FLAGS_HOST_SFH_LLC; tx_msghdr->flags |= (skb->priority & 0x07) << BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT; tx_msghdr->seg_cnt = 1; - memcpy(tx_msghdr->txhdr, skb->data, ETH_HLEN); - tx_msghdr->data_len = cpu_to_le16(skb->len - ETH_HLEN); + memcpy(tx_msghdr->txhdr, ethhdr, ETH_HLEN); + tx_msghdr->data_len = cpu_to_le16(sfh ? skb->len : + skb->len - ETH_HLEN); + if (get_unaligned_be16(ethhdr + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "TX EAPOL pktid %u flow %u len %u%s\n", + pktid, flowid, skb->len, + sfh ? " (802.3+LLC)" : ""); address = (u64)physaddr; tx_msghdr->data_buf_addr.high_addr = cpu_to_le32(address >> 32); tx_msghdr->data_buf_addr.low_addr = @@ -913,6 +1048,12 @@ brcmf_msgbuf_process_txstatus(struct brcmf_msgbuf *msgbuf, void *buf) msgbuf->tx_pktids, idx); if (!skb) return; + if (brcmf_msgbuf_sfh_llc(msgbuf)) + brcmf_msgbuf_sfh_llc_remove(skb); + if (skb->len >= ETH_HLEN && + get_unaligned_be16(skb->data + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "TX EAPOL done pktid %u status %u\n", idx, + le16_to_cpu(tx_status->compl_hdr.status)); if (!brcmf_msgbuf_get_flowid(msgbuf, flow_ring_id, &flowid)) { brcmf_txfinalize(brcmf_get_ifp(msgbuf->drvr, tx_status->msg.ifidx), @@ -967,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); @@ -996,6 +1137,8 @@ static u32 brcmf_msgbuf_rxbuf_data_post(struct brcmf_msgbuf *msgbuf, u32 count) cpu_to_le32(address >> 32); rx_bufpost->data_buf_addr.low_addr = cpu_to_le32(address & 0xffffffff); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_RXPOST_SUBMIT, + &rx_bufpost->msg); ret_ptr += brcmf_commonring_len_item(commonring); } @@ -1077,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); @@ -1096,6 +1239,8 @@ brcmf_msgbuf_rxbuf_ctrl_post(struct brcmf_msgbuf *msgbuf, bool event_buf, cpu_to_le32(address >> 32); rx_bufpost->host_buf_addr.low_addr = cpu_to_le32(address & 0xffffffff); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &rx_bufpost->msg); ret_ptr += brcmf_commonring_len_item(commonring); } @@ -1226,6 +1371,10 @@ brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf) return; } + if (skb->len >= ETH_HLEN && + get_unaligned_be16(skb->data + 2 * ETH_ALEN) == ETH_P_PAE) + brcmf_dbg(MSGBUF, "RX EAPOL pktid %u len %u flags 0x%x\n", idx, + skb->len, flags); skb->protocol = eth_type_trans(skb, ifp->ndev); brcmf_netif_rx(ifp, skb); } @@ -1323,6 +1472,7 @@ brcmf_msgbuf_process_flow_ring_delete_response(struct brcmf_msgbuf *msgbuf, static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) { struct brcmf_pub *drvr = msgbuf->drvr; + struct msgbuf_d2h_mailbox_data *mb_data; struct msgbuf_common_hdr *msg; msg = (struct msgbuf_common_hdr *)buf; @@ -1362,6 +1512,11 @@ static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) brcmf_dbg(MSGBUF, "MSGBUF_TYPE_RX_CMPLT\n"); brcmf_msgbuf_process_rx_complete(msgbuf, buf); break; + case MSGBUF_TYPE_D2H_MAILBOX_DATA: + brcmf_dbg(MSGBUF, "MSGBUF_TYPE_D2H_MAILBOX_DATA\n"); + mb_data = (struct msgbuf_d2h_mailbox_data *)buf; + brcmf_bus_d2h_mb_data(drvr->bus_if, le32_to_cpu(mb_data->mb_data)); + break; default: bphy_err(drvr, "Unsupported msgtype %d\n", msg->msgtype); break; @@ -1369,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; @@ -1383,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) { @@ -1401,22 +1605,55 @@ static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, } +/* Mailbox data for the device, sent as a control message. */ +int brcmf_proto_msgbuf_h2d_mb_data(struct device *dev, u32 data) +{ + struct brcmf_bus *bus_if = dev_get_drvdata(dev); + struct brcmf_pub *drvr = bus_if->drvr; + struct msgbuf_h2d_mailbox_data *mb_data; + struct brcmf_commonring *commonring; + struct brcmf_msgbuf *msgbuf; + int err; + + if (!drvr || !drvr->proto || !drvr->proto->pd) + return -EAGAIN; + msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + + commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; + brcmf_commonring_lock(commonring); + mb_data = brcmf_commonring_reserve_for_write(commonring); + if (!mb_data) { + brcmf_commonring_unlock(commonring); + return -ENOMEM; + } + memset(mb_data, 0, sizeof(*mb_data)); + mb_data->msg.msgtype = MSGBUF_TYPE_H2D_MAILBOX_DATA; + mb_data->mb_data = cpu_to_le32(data); + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &mb_data->msg); + err = brcmf_commonring_write_complete(commonring); + brcmf_commonring_unlock(commonring); + + return err; +} + + int brcmf_proto_msgbuf_rx_trigger(struct device *dev) { struct brcmf_bus *bus_if = dev_get_drvdata(dev); struct brcmf_pub *drvr = bus_if->drvr; - struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + struct brcmf_msgbuf *msgbuf; struct brcmf_commonring *commonring; - void *buf; u32 flowid; int qlen; - 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); + if (!drvr || !drvr->proto || !drvr->proto->pd) + return -ENODEV; + msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; + + 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) { @@ -1478,6 +1715,7 @@ void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid) } delete = (struct msgbuf_tx_flowring_delete_req *)ret_ptr; + memset(delete, 0, sizeof(*delete)); ifidx = brcmf_flowring_ifidx_get(msgbuf->flow, flowid); @@ -1488,6 +1726,8 @@ void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid) delete->flow_ring_id = cpu_to_le16(flowid + BRCMF_H2D_MSGRING_FLOWRING_IDSTART); delete->reason = 0; + brcmf_msgbuf_set_epoch(msgbuf, BRCMF_H2D_MSGRING_CONTROL_SUBMIT, + &delete->msg); brcmf_dbg(MSGBUF, "Send Flow Delete Req flow ID %d, ifindex %d\n", flowid, ifidx); @@ -1617,6 +1857,10 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) drvr->proto->pd = msgbuf; init_waitqueue_head(&msgbuf->ioctl_resp_wait); + msgbuf->h2d_seqnum[BRCMF_H2D_MSGRING_CONTROL_SUBMIT] = + BRCMF_MSGBUF_H2D_EPOCH_INIT; + msgbuf->h2d_seqnum[BRCMF_H2D_MSGRING_RXPOST_SUBMIT] = + BRCMF_MSGBUF_H2D_EPOCH_INIT; msgbuf->commonrings = (struct brcmf_commonring **)if_msgbuf->commonrings; @@ -1629,11 +1873,26 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) goto fail; msgbuf->rx_dataoffset = if_msgbuf->rx_dataoffset; - msgbuf->max_rxbufpost = if_msgbuf->max_rxbufpost; + msgbuf->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; + /* Data, ioctl response and event buffers share the rx packet IDs + * (ID 0 is never used): leave enough for the control buffers. + */ + msgbuf->max_rxbufpost = min_t(u32, if_msgbuf->max_rxbufpost, + NR_RX_PKTIDS - 1 - + 2 * (msgbuf->max_ioctlrespbuf + + msgbuf->max_eventbuf)); + msgbuf->tx_pktids = brcmf_msgbuf_init_pktids(NR_TX_PKTIDS, DMA_TO_DEVICE); if (!msgbuf->tx_pktids) @@ -1642,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/msgbuf.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h index 6a849f4a94..76dd36f6c8 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.h @@ -29,6 +29,7 @@ struct msgbuf_buf_addr { }; int brcmf_proto_msgbuf_rx_trigger(struct device *dev); +int brcmf_proto_msgbuf_h2d_mb_data(struct device *dev, u32 data); void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid); int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr); void brcmf_proto_msgbuf_detach(struct brcmf_pub *drvr); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 4093e7d519..969410ee3f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -9,12 +9,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -72,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 */ @@ -114,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 */ @@ -123,6 +131,10 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { /* backplane addres space accessed by BAR0 */ #define BRCMF_PCIE_BAR0_WINDOW 0x80 #define BRCMF_PCIE_BAR0_REG_SIZE 0x1000 +/* backplane address space accessed by BAR1 (PCI BAR 2, devinfo->tcm) */ +#define BRCMF_PCIE_BAR1_WINDOW 0x84 +/* largest TCM block copy done under one tcm_lock hold */ +#define BRCMF_PCIE_TCM_COPY_CHUNK 4096 #define BRCMF_PCIE_BAR0_WRAPPERBASE 0x70 #define BRCMF_PCIE_BAR0_WRAPBASE_DMP_OFFSET 0x1000 @@ -151,6 +163,25 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_0 0xA20 #define BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_1 0xA24 +/* Save/restore power domain requests, in the PCIe core's own registers, + * reached through BAR0 + BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET. + */ +#define BRCMF_PCIE_PCIE2REG_POWERCTL 0x1E8 +#define BRCMF_PCIE_64_PCIE2REG_DAR_POWERCTL 0xA0C +#define BRCMF_PCIE_SRPWR_DMN0_PCIE BIT(0) +#define BRCMF_PCIE_SRPWR_DMN1_ARMBP BIT(1) +#define BRCMF_PCIE_SRPWR_DMN2_MACAUX BIT(2) +#define BRCMF_PCIE_SRPWR_DMN3_MACMAIN BIT(3) +#define BRCMF_PCIE_SRPWR_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 | \ + BRCMF_PCIE_SRPWR_DMN3_MACMAIN) +#define BRCMF_PCIE_SRPWR_REQON_SHIFT 8 +#define BRCMF_PCIE_SRPWR_STATUS_SHIFT 16 +#define BRCMF_PCIE_SRPWR_TIMEOUT_US 15000 + #define BRCMF_PCIE2_INTA 0x01 #define BRCMF_PCIE2_INTB 0x02 @@ -216,12 +247,17 @@ 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 +#define BRCMF_PCIE_SHARED_DAR 0x80000000 #define BRCMF_PCIE_FLAGS_HTOD_SPLIT 0x4000 #define BRCMF_PCIE_FLAGS_DTOH_SPLIT 0x8000 @@ -237,6 +273,18 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET 56 #define BRCMF_SHARED_DMA_RINGUPD_LEN_OFFSET 64 #define BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET 68 +/* shared area revision >= 6: host capabilities, read by the firmware */ +#define BRCMF_SHARED_HOST_CAP_OFFSET 84 +#define BRCMF_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 +#define BRCMF_HOSTCAP_UR_FW_NO_TRAP 0x00800000 #define BRCMF_RING_H2D_RING_COUNT_OFFSET 0 #define BRCMF_RING_D2H_RING_COUNT_OFFSET 1 @@ -278,6 +326,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_CFGREG_MSI_DATA 0x64 #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL 0xBC #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL2 0xDC +#define BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL 0x88 +#define BRCMF_PCIE_SSCTRL_BAR_COHERENT 0x300 #define BRCMF_PCIE_CFGREG_RBAR_CTRL 0x228 #define BRCMF_PCIE_CFGREG_PML1_SUB_CTRL1 0x248 #define BRCMF_PCIE_CFGREG_REG_BAR2_CONFIG 0x4E0 @@ -341,6 +391,14 @@ struct brcmf_pciedev_info { const struct brcmf_pcie_reginfo *reginfo; void __iomem *regs; void __iomem *tcm; + struct delayed_work poll_work; + struct mutex rx_lock; /* one D2H ring processor at a time */ + unsigned int poll_left; + bool poll_enabled; + u32 tcm_size; + u32 tcm_win; + bool tcm_win_switch; + spinlock_t tcm_lock; u32 ram_base; u32 ram_size; struct brcmf_chip *ci; @@ -348,6 +406,12 @@ struct brcmf_pciedev_info { struct brcmf_pcie_shared_info shared; wait_queue_head_t mbdata_resp_wait; bool mbdata_completed; + /* Mailbox data travels as control messages (shared version >= 6). */ + bool mb_ctrlmsg; + /* A D3 ACK arrived as a control message; publish it after RX. */ + bool d3_ack_pending; + /* How the last D3 ACK arrived, for the log. */ + const char *d3_ack_via; bool irq_allocated; bool wowl_enabled; u8 dma_idx_sz; @@ -451,6 +515,25 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_default = { .int_fn0 = BRCMF_PCIE_MB_INT_FN0, }; +/* Core rev >= 64 with the doorbells in the PCIe core's own registers, for + * firmware that does not offer the DAR doorbells (BRCMF_PCIE_SHARED_DAR). + * + * From core rev 64 the FN0 bits (0x100, 0x200) are also the D2H4 doorbells. + * Broadcom's driver still reads the shared-memory D2H mailbox when either is + * set (dhdpcie_bus_process_mailbox_intr()), and firmware may post mailbox + * data, the D3 ACK among it, that way even when it otherwise sends it as a + * control message. + */ +static const struct brcmf_pcie_reginfo brcmf_reginfo_64_nodar = { + .intmask = BRCMF_PCIE_64_PCIE2REG_INTMASK, + .mailboxint = BRCMF_PCIE_64_PCIE2REG_MAILBOXINT, + .mailboxmask = BRCMF_PCIE_64_PCIE2REG_MAILBOXMASK, + .h2d_mailbox_0 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_0, + .h2d_mailbox_1 = BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_1, + .int_d2h_db = BRCMF_PCIE_64_MB_INT_D2H_DB, + .int_fn0 = BRCMF_PCIE_MB_INT_FN0, +}; + static const struct brcmf_pcie_reginfo brcmf_reginfo_64 = { .intmask = BRCMF_PCIE_64_PCIE2REG_INTMASK, .mailboxint = BRCMF_PCIE_64_PCIE2REG_MAILBOXINT, @@ -458,7 +541,7 @@ static const struct brcmf_pcie_reginfo brcmf_reginfo_64 = { .h2d_mailbox_0 = BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_0, .h2d_mailbox_1 = BRCMF_PCIE_64_PCIE2REG_H2D_MAILBOX_1, .int_d2h_db = BRCMF_PCIE_64_MB_INT_D2H_DB, - .int_fn0 = 0, + .int_fn0 = BRCMF_PCIE_MB_INT_FN0, }; static void brcmf_pcie_setup(struct device *dev, int ret, @@ -496,21 +579,86 @@ brcmf_pcie_write_reg32(struct brcmf_pciedev_info *devinfo, u32 reg_offset, } +/* + * devinfo->tcm maps tcm_size bytes of the chip's backplane, starting at the + * address in the BAR1 window register. The BCM4389 has 2.6 MiB of RAM at + * 0x200000, which crosses the 4 MiB BAR, so for chips whose RAM does not fit + * the BAR the window is moved to the tcm_size-aligned block that holds each + * access. Callers hold tcm_lock. + */ +static void __iomem * +brcmf_pcie_tcm_addr(struct brcmf_pciedev_info *devinfo, u32 addr) +{ + u32 win; + + lockdep_assert_held(&devinfo->tcm_lock); + + if (!devinfo->tcm_win_switch) + return devinfo->tcm + addr; + + win = addr & ~(devinfo->tcm_size - 1); + if (win != devinfo->tcm_win) { + pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_BAR1_WINDOW, + win); + devinfo->tcm_win = win; + } + + return devinfo->tcm + (addr - win); +} + +/* Bytes from addr up to the end of its window, at most chunk. */ +static u32 +brcmf_pcie_tcm_chunk(struct brcmf_pciedev_info *devinfo, u32 addr, u32 len) +{ + u32 chunk = min_t(u32, len, BRCMF_PCIE_TCM_COPY_CHUNK); + + if (devinfo->tcm_win_switch) + chunk = min_t(u32, chunk, + devinfo->tcm_size - (addr & (devinfo->tcm_size - 1))); + + return chunk; +} + +/* Point the BAR1 window back at backplane address 0, as after a reset. */ +static void brcmf_pcie_tcm_win_reset(struct brcmf_pciedev_info *devinfo) +{ + unsigned long flags; + + if (!devinfo->tcm_win_switch) + return; + + spin_lock_irqsave(&devinfo->tcm_lock, flags); + pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_BAR1_WINDOW, 0); + devinfo->tcm_win = 0; + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); +} + + static u8 brcmf_pcie_read_tcm8(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u8 val; - return (ioread8(address)); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread8(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + + return val; } static u16 brcmf_pcie_read_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u16 val; + + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread16(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); - return (ioread16(address)); + return val; } @@ -518,9 +666,11 @@ static void brcmf_pcie_write_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u16 value) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; - iowrite16(value, address); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + iowrite16(value, brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); } @@ -546,9 +696,14 @@ brcmf_pcie_write_idx(struct brcmf_pciedev_info *devinfo, u32 mem_offset, static u32 brcmf_pcie_read_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; + u32 val; - return (ioread32(address)); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + val = ioread32(brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + + return val; } @@ -556,18 +711,19 @@ static void brcmf_pcie_write_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u32 value) { - void __iomem *address = devinfo->tcm + mem_offset; + unsigned long flags; - iowrite32(value, address); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + iowrite32(value, brcmf_pcie_tcm_addr(devinfo, mem_offset)); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); } static u32 brcmf_pcie_read_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset) { - void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset; - - return (ioread32(addr)); + return brcmf_pcie_read_tcm32(devinfo, + devinfo->ci->rambase + mem_offset); } @@ -575,17 +731,34 @@ static void brcmf_pcie_write_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset, u32 value) { - void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset; + brcmf_pcie_write_tcm32(devinfo, devinfo->ci->rambase + mem_offset, + value); +} - iowrite32(value, addr); + +static void +brcmf_pcie_copy_mem_todev(struct brcmf_pciedev_info *devinfo, u32 mem_offset, + const void *srcaddr, u32 len) +{ + unsigned long flags; + u32 chunk; + + while (len) { + chunk = brcmf_pcie_tcm_chunk(devinfo, mem_offset, len); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + memcpy_toio(brcmf_pcie_tcm_addr(devinfo, mem_offset), srcaddr, + chunk); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + mem_offset += chunk; + srcaddr += chunk; + len -= chunk; + } } static void -brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, - void *dstaddr, u32 len) +brcmf_pcie_copy_tcm_chunk(void __iomem *address, void *dstaddr, u32 len) { - void __iomem *address = devinfo->tcm + mem_offset; __le32 *dst32; __le16 *dst16; u8 *dst8; @@ -622,6 +795,27 @@ brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, } +static void +brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset, + void *dstaddr, u32 len) +{ + unsigned long flags; + u32 chunk; + + while (len) { + chunk = brcmf_pcie_tcm_chunk(devinfo, mem_offset, len); + spin_lock_irqsave(&devinfo->tcm_lock, flags); + brcmf_pcie_copy_tcm_chunk(brcmf_pcie_tcm_addr(devinfo, + mem_offset), + dstaddr, chunk); + spin_unlock_irqrestore(&devinfo->tcm_lock, flags); + mem_offset += chunk; + dstaddr += chunk; + len -= chunk; + } +} + + #define READCC32(devinfo, reg) brcmf_pcie_read_reg32(devinfo, \ CHIPCREGOFFS(reg)) #define WRITECC32(devinfo, reg, value) brcmf_pcie_write_reg32(devinfo, \ @@ -655,6 +849,139 @@ brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid) } +/* + * 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 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_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; + + if (!brcmf_pcie_has_srpwr(devinfo)) + return; + + val = brcmf_pcie_read_reg32(devinfo, reg); + if (val == 0xffffffff) { + pci_err(devinfo->pdev, "power control reads 0xffffffff\n"); + return; + } + if ((val & req) != req) + brcmf_pcie_write_reg32(devinfo, reg, val | req); + + if (readl_poll_timeout(devinfo->regs + reg, val, (val & up) == up, 10, + BRCMF_PCIE_SRPWR_TIMEOUT_US)) + pci_warn(devinfo->pdev, "power domains not up, powerctl 0x%08x\n", + val); + else + brcmf_dbg(PCIE, "power domains up, powerctl 0x%08x\n", val); + + /* The ARM also needs the ARM/backplane domain requested through the + * DAR copy of the register, or it fails to boot from cold. + */ + val = brcmf_pcie_read_reg32(devinfo, dar); + req = BRCMF_PCIE_SRPWR_DMN1_ARMBP << BRCMF_PCIE_SRPWR_REQON_SHIFT; + if ((val & req) != req) + brcmf_pcie_write_reg32(devinfo, dar, val | req); +} + +/* The ARM CA7 needs host accesses through the BARs to be coherent. */ +static void brcmf_pcie_set_bar_coherent(struct brcmf_pciedev_info *devinfo) +{ + u32 val; + + if (!brcmf_pcie_has_srpwr(devinfo)) + return; + + pci_read_config_dword(devinfo->pdev, + BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, &val); + if ((val & BRCMF_PCIE_SSCTRL_BAR_COHERENT) != + BRCMF_PCIE_SSCTRL_BAR_COHERENT) + pci_write_config_dword(devinfo->pdev, + BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, + val | BRCMF_PCIE_SSCTRL_BAR_COHERENT); +} + +/* + * Function level reset as Broadcom's driver does it for the BCM4389 + * (bcmdhd dhd_pcie.c dhd_bus_perform_flr()): set Initiate FLR, wait 70 ms, + * clear it again, then wait for the subsystem reset status (config 0x88 + * bit 13) to clear, and restore the config space. + */ +#define BRCMF_PCIE_SSCTRL_SSRESET_STATUS BIT(13) + +static int brcmf_pcie_flr(struct brcmf_pciedev_info *devinfo) +{ + struct pci_dev *pdev = devinfo->pdev; + u32 cap, val; + int i; + + pcie_capability_read_dword(pdev, PCI_EXP_DEVCAP, &cap); + if (!(cap & PCI_EXP_DEVCAP_FLR)) + return -EOPNOTSUPP; + + pci_save_state(pdev); + pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR); + msleep(70); + pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL, + PCI_EXP_DEVCTL_BCR_FLR); + + for (i = 0; i < 200; i++) { + pci_read_config_dword(pdev, BRCMF_PCIE_CFGREG_SUBSYSTEM_CONTROL, + &val); + if (!(val & BRCMF_PCIE_SSCTRL_SSRESET_STATUS)) + break; + udelay(40); + } + pci_restore_state(pdev); + + if (val & BRCMF_PCIE_SSCTRL_SSRESET_STATUS) { + pci_err(pdev, "FLR did not complete, config 0x88 = 0x%08x\n", + val); + return -ETIMEDOUT; + } + brcmf_dbg(PCIE, "FLR done\n"); + return 0; +} + static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) { struct brcmf_core *core; @@ -686,16 +1013,27 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL, val); - /* Watchdog reset */ - brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); - WRITECC32(devinfo, watchdog, 4); - msleep(100); + /* Watchdog reset, with all power domains up as it starts. The + * BCM4389 is reset the way Broadcom's driver resets it, with an + * FLR: after a chipcommon watchdog reset its ARM does not boot a + * second firmware download. + */ + brcmf_pcie_srpwr_request(devinfo); + if (!brcmf_pcie_is_4389_family(devinfo) || brcmf_pcie_flr(devinfo)) { + brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); + WRITECC32(devinfo, watchdog, 4); + msleep(100); + } /* Restore ASPM */ brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL, lsc); + /* The reset dropped the power domain requests */ + brcmf_pcie_srpwr_request(devinfo); + brcmf_pcie_set_bar_coherent(devinfo); + core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_PCIE2); if (core->rev <= 13) { for (i = 0; i < ARRAY_SIZE(cfg_offset); i++) { @@ -711,6 +1049,8 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) val); } } + + brcmf_pcie_tcm_win_reset(devinfo); } @@ -730,6 +1070,8 @@ static void brcmf_pcie_attach(struct brcmf_pciedev_info *devinfo) static int brcmf_pcie_enter_download_state(struct brcmf_pciedev_info *devinfo) { + brcmf_pcie_tcm_win_reset(devinfo); + if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) { brcmf_pcie_select_core(devinfo, BCMA_CORE_ARM_CR4); brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX, @@ -770,6 +1112,14 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data) u32 cur_htod_mb_data; u32 i; + if (devinfo->mb_ctrlmsg) { + if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return -EIO; + /* Rings the doorbell through the control ring's callbacks. */ + return brcmf_proto_msgbuf_h2d_mb_data(&devinfo->pdev->dev, + htod_mb_data); + } + shared = &devinfo->shared; addr = shared->htod_mb_data_addr; cur_htod_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); @@ -799,21 +1149,9 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data) } -static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) +static void brcmf_pcie_process_mb_data(struct brcmf_pciedev_info *devinfo, + u32 dtoh_mb_data, bool in_ring) { - struct brcmf_pcie_shared_info *shared; - u32 addr; - u32 dtoh_mb_data; - - shared = &devinfo->shared; - addr = shared->dtoh_mb_data_addr; - dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); - - if (!dtoh_mb_data) - return; - - brcmf_pcie_write_tcm32(devinfo, addr, 0); - brcmf_dbg(PCIE, "D2H_MB_DATA: 0x%04x\n", dtoh_mb_data); if (dtoh_mb_data & BRCMF_D2H_DEV_DS_ENTER_REQ) { brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP REQ\n"); @@ -824,8 +1162,20 @@ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP EXIT\n"); if (dtoh_mb_data & BRCMF_D2H_DEV_D3_ACK) { brcmf_dbg(PCIE, "D2H_MB_DATA: D3 ACK\n"); - devinfo->mbdata_completed = true; - wake_up(&devinfo->mbdata_resp_wait); + devinfo->d3_ack_via = in_ring ? "control message" : + "shared-memory mailbox"; + if (in_ring) { + /* + * The message is still being processed: its ring read + * pointer isn't written back yet, and once the waiter + * sets STATE_DOWN that write is refused. Publish the + * ACK once RX processing is done (under rx_lock). + */ + devinfo->d3_ack_pending = true; + } else { + WRITE_ONCE(devinfo->mbdata_completed, true); + wake_up(&devinfo->mbdata_resp_wait); + } } if (dtoh_mb_data & BRCMF_D2H_DEV_FWHALT) { brcmf_dbg(PCIE, "D2H_MB_DATA: FW HALT\n"); @@ -834,6 +1184,36 @@ static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) } +/* The shared-memory D2H mailbox; the interrupt thread and the D3 wait poll it. */ +static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo) +{ + struct brcmf_pcie_shared_info *shared; + u32 addr; + u32 dtoh_mb_data; + + shared = &devinfo->shared; + addr = shared->dtoh_mb_data_addr; + if (!addr) + return; + + mutex_lock(&devinfo->rx_lock); + dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr); + if (dtoh_mb_data) { + brcmf_pcie_write_tcm32(devinfo, addr, 0); + brcmf_pcie_process_mb_data(devinfo, dtoh_mb_data, false); + } + mutex_unlock(&devinfo->rx_lock); +} + + +static void brcmf_pcie_d2h_mb_data(struct device *dev, u32 data) +{ + struct brcmf_bus *bus_if = dev_get_drvdata(dev); + + brcmf_pcie_process_mb_data(bus_if->bus_priv.pcie->devinfo, data, true); +} + + static void brcmf_pcie_bus_console_init(struct brcmf_pciedev_info *devinfo) { struct brcmf_pcie_shared_info *shared; @@ -878,6 +1258,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); @@ -920,11 +1308,25 @@ 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) + if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) { + brcmf_dbg(PCIE, "host ready on 0x%x\n", + devinfo->reginfo->h2d_mailbox_1); + /* bcmdhd dhd_bus_hostready() writes this value */ brcmf_pcie_write_reg32(devinfo, - devinfo->reginfo->h2d_mailbox_1, 1); + devinfo->reginfo->h2d_mailbox_1, + brcmf_pcie_is_4389_family(devinfo) ? + 0x12345678 : 1); + } } static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg) @@ -940,6 +1342,73 @@ static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg) } +/* Process the D2H rings; the interrupt thread and the poll both get here. */ +static void brcmf_pcie_rx_process(struct brcmf_pciedev_info *devinfo) +{ + struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); + + mutex_lock(&devinfo->rx_lock); + if (devinfo->state == BRCMFMAC_PCIE_STATE_UP && bus && bus->drvr && + bus->drvr->proto) + brcmf_proto_msgbuf_rx_trigger(&devinfo->pdev->dev); + /* + * The rings' read pointers are written back now, so a D3 ACK that + * came as a control message can be published. + */ + if (devinfo->d3_ack_pending) { + devinfo->d3_ack_pending = false; + WRITE_ONCE(devinfo->mbdata_completed, true); + wake_up(&devinfo->mbdata_resp_wait); + } + mutex_unlock(&devinfo->rx_lock); +} + +/* + * BCM4389 on INTx: completions were seen to go unprocessed until a later + * interrupt (ioctl timeouts, a control ring that looks stuck). Broadcom's + * driver re-runs its interrupt work after INTx with DMA'd indices + * (dhd_bus_handle_intx_ahead_dma_indices()). Do the same, more often: after + * each interrupt and each doorbell, look at the D2H rings every 10 ms for + * the next 500 ms. + */ +#define BRCMF_PCIE_POLL_MS 10 +#define BRCMF_PCIE_POLL_COUNT 50 + +static void brcmf_pcie_kick_poll(struct brcmf_pciedev_info *devinfo) +{ + if (!devinfo->poll_enabled || + devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return; + WRITE_ONCE(devinfo->poll_left, BRCMF_PCIE_POLL_COUNT); + mod_delayed_work(system_wq, &devinfo->poll_work, + msecs_to_jiffies(BRCMF_PCIE_POLL_MS)); +} + +static void brcmf_pcie_poll_worker(struct work_struct *work) +{ + struct brcmf_pciedev_info *devinfo = + container_of(to_delayed_work(work), struct brcmf_pciedev_info, + poll_work); + u32 status; + unsigned int left; + + if (devinfo->state != BRCMFMAC_PCIE_STATE_UP) + return; + + status = brcmf_pcie_read_reg32(devinfo, devinfo->reginfo->mailboxint); + if (status & devinfo->reginfo->int_d2h_db) + brcmf_dbg(PCIE, "poll: mailboxint 0x%08x pending without an interrupt\n", + status); + brcmf_pcie_rx_process(devinfo); + + left = READ_ONCE(devinfo->poll_left); + if (left) { + WRITE_ONCE(devinfo->poll_left, left - 1); + queue_delayed_work(system_wq, &devinfo->poll_work, + msecs_to_jiffies(BRCMF_PCIE_POLL_MS)); + } +} + static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) { struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)arg; @@ -954,14 +1423,24 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) if (status & devinfo->reginfo->int_fn0) brcmf_pcie_handle_mb_data(devinfo); if (status & devinfo->reginfo->int_d2h_db) { - if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) - brcmf_proto_msgbuf_rx_trigger( - &devinfo->pdev->dev); + brcmf_pcie_rx_process(devinfo); + /* With INTx and DMA'd indices the interrupt can + * overtake the index update it announces; Broadcom's + * driver looks again later + * (dhd_bus_handle_intx_ahead_dma_indices()). + */ + if (devinfo->dma_idx_sz && + brcmf_pcie_is_4389_family(devinfo) && + devinfo->state == BRCMFMAC_PCIE_STATE_UP) { + usleep_range(500, 1000); + brcmf_pcie_rx_process(devinfo); + } } } brcmf_pcie_bus_console_read(devinfo, false); if (devinfo->state == BRCMFMAC_PCIE_STATE_UP) brcmf_pcie_intr_enable(devinfo); + brcmf_pcie_kick_poll(devinfo); devinfo->in_irq = false; return IRQ_HANDLED; } @@ -1066,6 +1545,7 @@ static int brcmf_pcie_ring_mb_ring_bell(void *ctx) brcmf_dbg(PCIE, "RING !\n"); /* Any arbitrary value will do, lets use 1 */ brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->h2d_mailbox_0, 1); + brcmf_pcie_kick_poll(devinfo); return 0; } @@ -1217,6 +1697,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); @@ -1236,8 +1766,18 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) u16 max_submissionrings; u16 max_completionrings; - memcpy_fromio(&ringinfo, devinfo->tcm + devinfo->shared.ring_info_addr, - sizeof(ringinfo)); + 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); @@ -1259,8 +1799,10 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) devinfo->idxbuf = dma_alloc_coherent(&devinfo->pdev->dev, bufsz, &devinfo->idxbuf_dmahandle, GFP_KERNEL); - if (!devinfo->idxbuf) + if (!devinfo->idxbuf) { + brcmf_err(bus, "no DMA memory for ring indices, using TCM\n"); devinfo->dma_idx_sz = 0; + } } if (devinfo->dma_idx_sz == 0) { @@ -1310,8 +1852,9 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) ringinfo.d2h_r_idx_hostaddr.high_addr = cpu_to_le32(address >> 32); - memcpy_toio(devinfo->tcm + devinfo->shared.ring_info_addr, - &ringinfo, sizeof(ringinfo)); + brcmf_pcie_copy_mem_todev(devinfo, + devinfo->shared.ring_info_addr, + &ringinfo, sizeof(ringinfo)); brcmf_dbg(PCIE, "Using host memory indices\n"); } @@ -1401,11 +1944,35 @@ brcmf_pcie_release_scratchbuffers(struct brcmf_pciedev_info *devinfo) } } +/* + * Tell the firmware what the host does, as Broadcom's driver does for shared + * area revision 6 and later (bcmdhd dhd_msgbuf.c dhd_set_host_cap()): the + * IPC revision in use, that a host-ready doorbell will come, that there is + * no device-wake (no deep sleep), and not to trap on an unsupported + * request. + */ +static void brcmf_pcie_set_host_cap(struct brcmf_pciedev_info *devinfo) +{ + u32 cap = devinfo->shared.version; + + if (devinfo->shared.version < 6) + return; + + if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) + cap |= BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY; + cap |= BRCMF_HOSTCAP_DS_NO_OOB_DW | BRCMF_HOSTCAP_UR_FW_NO_TRAP; + + brcmf_pcie_write_tcm32(devinfo, devinfo->shared.tcm_base_address + + BRCMF_SHARED_HOST_CAP_OFFSET, cap); + brcmf_dbg(PCIE, "host capabilities 0x%08x\n", cap); +} + static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) { struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); u64 address; u32 addr; + u8 aggr_cap = 0; devinfo->shared.scratch = dma_alloc_coherent(&devinfo->pdev->dev, @@ -1424,6 +1991,18 @@ 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 (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; + } + devinfo->shared.ringupd = dma_alloc_coherent(&devinfo->pdev->dev, BRCMF_DMA_D2H_RINGUPD_BUF_LEN, @@ -1466,7 +2045,9 @@ static int brcmf_pcie_preinit(struct device *dev) brcmf_dbg(PCIE, "Enter\n"); brcmf_pcie_intr_enable(buspub->devinfo); - brcmf_pcie_hostready(buspub->devinfo); + /* The early path already notified firmware after setting up the rings. */ + if (!brcmf_pcie_early_hostready(buspub->devinfo)) + brcmf_pcie_hostready(buspub->devinfo); return 0; } @@ -1557,7 +2138,19 @@ static int brcmf_pcie_reset(struct device *dev) struct brcmf_fw_request *fwreq; int err; + /* + * Stop everything that processes the rings before brcmf_detach() + * frees the protocol layer: the interrupt thread, the D2H poll and + * the console timer. As in brcmf_pcie_remove(); STATE_DOWN keeps the + * interrupt thread and the poll from re-arming. brcmf_pcie_setup() + * sets it UP again. + */ + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + brcmf_pcie_fwcon_timer(devinfo, false); brcmf_pcie_intr_disable(devinfo); + if (devinfo->irq_allocated) + synchronize_irq(devinfo->pdev->irq); + cancel_delayed_work_sync(&devinfo->poll_work); brcmf_pcie_bus_console_read(devinfo, true); @@ -1595,6 +2188,7 @@ static const struct brcmf_bus_ops brcmf_pcie_bus_ops = { .get_blob = brcmf_pcie_get_blob, .reset = brcmf_pcie_reset, .debugfs_create = brcmf_pcie_debugfs_create, + .d2h_mb_data = brcmf_pcie_d2h_mb_data, }; @@ -1620,6 +2214,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) @@ -1627,20 +2245,61 @@ 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); + + /* + * From shared version 6 Broadcom's driver exchanges mailbox data + * (D3 inform and ack, deep sleep) as control messages, unless the + * firmware asks for the shared-memory mailbox. The BCM4389 firmware + * doesn't, and ignores the TCM mailbox. + */ + devinfo->mb_ctrlmsg = shared->version >= 6 && + !(shared->flags & BRCMF_PCIE_SHARED_USE_MAILBOX); + brcmf_dbg(PCIE, "mailbox data as %s\n", + devinfo->mb_ctrlmsg ? "control messages" : "TCM mailbox"); + + /* Broadcom's driver rings the DAR doorbells only when the firmware + * offers them, and the core's own H2D mailbox registers otherwise. + * The BCM4389 firmware does not, and ignores the DAR doorbells. + */ + if (devinfo->reginfo == &brcmf_reginfo_64 && + 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", + devinfo->reginfo->h2d_mailbox_0, + devinfo->reginfo->h2d_mailbox_1); + } brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version); if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) || - (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) { + (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) @@ -1689,7 +2348,45 @@ brcmf_pcie_provide_random_bytes(struct brcmf_pciedev_info *devinfo, u32 address) u8 randbuf[BRCMF_RANDOM_SEED_LENGTH]; get_random_bytes(randbuf, BRCMF_RANDOM_SEED_LENGTH); - memcpy_toio(devinfo->tcm + address, randbuf, BRCMF_RANDOM_SEED_LENGTH); + brcmf_pcie_copy_mem_todev(devinfo, address, randbuf, + BRCMF_RANDOM_SEED_LENGTH); +} + +/* + * 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, @@ -1710,8 +2407,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, return err; brcmf_dbg(PCIE, "Download FW %s\n", devinfo->fw_name); - memcpy_toio(devinfo->tcm + devinfo->ci->rambase, - (void *)fw->data, fw->size); + brcmf_pcie_copy_mem_todev(devinfo, devinfo->ci->rambase, fw->data, + fw->size); resetintr = get_unaligned_le32(fw->data); release_firmware(fw); @@ -1725,7 +2422,7 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Download NVRAM %s\n", devinfo->nvram_name); address = devinfo->ci->rambase + devinfo->ci->ramsize - nvram_len; - memcpy_toio(devinfo->tcm + address, nvram, nvram_len); + brcmf_pcie_copy_mem_todev(devinfo, address, nvram, nvram_len); brcmf_fw_nvram_free(nvram); if (devinfo->fwseed) { @@ -1741,8 +2438,8 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Download random seed\n"); address -= sizeof(footer); - memcpy_toio(devinfo->tcm + address, &footer, - sizeof(footer)); + brcmf_pcie_copy_mem_todev(devinfo, address, &footer, + sizeof(footer)); address -= rand_len; brcmf_pcie_provide_random_bytes(devinfo, address); @@ -1763,6 +2460,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, @@ -1802,6 +2530,20 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) pci_set_master(pdev); + /* The dongle takes 64-bit host addresses in every ring and buffer + * descriptor. Without this the PCI default 32-bit mask applies, and + * every allocation from a restricted DMA pool placed above 4 GiB + * fails. + */ + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (err) { + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (err) { + brcmf_err(bus, "no usable DMA mask: %d\n", err); + return err; + } + } + /* Bar-0 mapped address */ bar0_addr = pci_resource_start(pdev, 0); /* Bar-1 mapped address */ @@ -1816,6 +2558,7 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) devinfo->regs = ioremap(bar0_addr, BRCMF_PCIE_REG_MAP_SIZE); devinfo->tcm = ioremap(bar1_addr, bar1_size); + devinfo->tcm_size = bar1_size; if (!devinfo->regs || !devinfo->tcm) { brcmf_err(bus, "ioremap() failed (%p,%p)\n", devinfo->regs, @@ -1875,7 +2618,18 @@ static void brcmf_pcie_buscore_write32(void *ctx, u32 addr, u32 value) static int brcmf_pcie_buscoreprep(void *ctx) { - return brcmf_pcie_get_resource(ctx); + struct brcmf_pciedev_info *devinfo = ctx; + int err; + + err = brcmf_pcie_get_resource(devinfo); + if (err) + return err; + + /* before the first access to a core outside the always-on domain */ + brcmf_pcie_srpwr_request(devinfo); + brcmf_pcie_set_bar_coherent(devinfo); + + return 0; } @@ -2199,6 +2953,11 @@ static void brcmf_pcie_setup(struct device *dev, int ret, ret = brcmf_pcie_request_irq(devinfo); if (ret) goto fail; + devinfo->poll_enabled = brcmf_pcie_is_4389_family(devinfo); + + /* 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. */ for (i = 0; i < BRCMF_NROF_COMMON_MSGRINGS; i++) @@ -2215,6 +2974,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); @@ -2448,6 +3210,20 @@ static const struct brcmf_pcie_drvdata drvdata[] = { /* Forward declaration for pci_match_id() call */ static const struct pci_device_id brcmf_pcie_devid_table[]; +static void brcmf_pcie_tcm_win_setup(struct brcmf_pciedev_info *devinfo) +{ + u32 end = devinfo->ci->rambase + devinfo->ci->ramsize - 1; + + /* RAM that ends inside the BAR is reached without moving it. */ + if (end < devinfo->tcm_size || !is_power_of_2(devinfo->tcm_size)) + return; + + devinfo->tcm_win_switch = true; + brcmf_pcie_tcm_win_reset(devinfo); + brcmf_dbg(PCIE, "RAM 0x%x-0x%x does not fit the %u KiB BAR, moving its window\n", + devinfo->ci->rambase, end, devinfo->tcm_size / 1024); +} + static int brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -2474,6 +3250,9 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) return ret; devinfo->pdev = pdev; + spin_lock_init(&devinfo->tcm_lock); + mutex_init(&devinfo->rx_lock); + INIT_DELAYED_WORK(&devinfo->poll_work, brcmf_pcie_poll_worker); pcie_bus_dev = NULL; devinfo->ci = brcmf_chip_attach(devinfo, pdev->device, &brcmf_pcie_buscore_ops); @@ -2483,6 +3262,8 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto fail; } + brcmf_pcie_tcm_win_setup(devinfo); + core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_PCIE2); if (core->rev >= 64) devinfo->reginfo = &brcmf_reginfo_64; @@ -2605,6 +3386,7 @@ brcmf_pcie_remove(struct pci_dev *pdev) brcmf_pcie_fwcon_timer(devinfo, false); devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + cancel_delayed_work_sync(&devinfo->poll_work); if (devinfo->ci) brcmf_pcie_intr_disable(devinfo); @@ -2621,6 +3403,7 @@ brcmf_pcie_remove(struct pci_dev *pdev) kfree(bus->msgbuf); kfree(bus); + brcmf_pcie_db7_trap(devinfo); brcmf_pcie_release_irq(devinfo); brcmf_pcie_release_scratchbuffers(devinfo); brcmf_pcie_release_ringbuffers(devinfo); @@ -2642,10 +3425,33 @@ brcmf_pcie_remove(struct pci_dev *pdev) #ifdef CONFIG_PM +/* + * Wait for the D3 ACK. It may come as a control message or in the + * shared-memory mailbox, with or without an interrupt, so look at both every + * 2 ms, as Broadcom's driver does when it asks for no ACK interrupt. + */ +static bool brcmf_pcie_wait_d3_ack(struct brcmf_pciedev_info *devinfo) +{ + unsigned long deadline = jiffies + BRCMF_PCIE_MBDATA_TIMEOUT; + + do { + brcmf_pcie_handle_mb_data(devinfo); + brcmf_pcie_rx_process(devinfo); + if (wait_event_timeout(devinfo->mbdata_resp_wait, + READ_ONCE(devinfo->mbdata_completed), + msecs_to_jiffies(2))) + return true; + } while (time_before(jiffies, deadline)); + + return READ_ONCE(devinfo->mbdata_completed); +} + static int brcmf_pcie_pm_enter_D3(struct device *dev) { struct brcmf_pciedev_info *devinfo; struct brcmf_bus *bus; + ktime_t start; + int err; brcmf_dbg(PCIE, "Enter\n"); @@ -2655,18 +3461,55 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev) brcmf_pcie_fwcon_timer(devinfo, false); brcmf_bus_change_state(bus, BRCMF_BUS_DOWN); - devinfo->mbdata_completed = false; - brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM); + WRITE_ONCE(devinfo->mbdata_completed, false); + devinfo->d3_ack_via = NULL; + start = ktime_get(); + err = brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM); + if (err) { + /* Nothing reached the device: just carry on. */ + brcmf_err(bus, "Failed to send D3 inform: %d\n", err); + brcmf_bus_change_state(bus, BRCMF_BUS_UP); + brcmf_pcie_fwcon_timer(devinfo, true); + return err; + } - wait_event_timeout(devinfo->mbdata_resp_wait, devinfo->mbdata_completed, - BRCMF_PCIE_MBDATA_TIMEOUT); - if (!devinfo->mbdata_completed) { - brcmf_err(bus, "Timeout on response for entering D3 substate\n"); + if (!brcmf_pcie_wait_d3_ack(devinfo)) { + brcmf_err(bus, "Timeout on response for entering D3 substate (%lld ms, mailboxint 0x%08x)\n", + ktime_ms_delta(ktime_get(), start), + brcmf_pcie_read_reg32(devinfo, + devinfo->reginfo->mailboxint)); + /* + * The device may have taken the inform and stopped. Broadcom's + * driver gives up on it here and has the whole stack + * restarted; a host-ready doorbell is no cure (an inform still + * queued puts it to sleep again, and this firmware traps on an + * unexpected host ready), and brcmfmac's own bus reset doesn't + * bring this chip back. Leave recovery to a reload of the + * stack, which power-cycles the chip. + */ + brcmf_err(bus, "device unresponsive after D3 inform; reload the driver stack to recover\n"); brcmf_bus_change_state(bus, BRCMF_BUS_UP); return -EIO; } + dev_dbg(dev, "D3 ACK by %s after %lld us\n", devinfo->d3_ack_via, + ktime_us_delta(ktime_get(), start)); + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + /* + * The interrupt thread that published the ACK may still be running + * and, having seen STATE_UP, unmask the interrupt or kick the poll. + * Let it finish before masking. + */ + if (devinfo->irq_allocated) + synchronize_irq(devinfo->pdev->irq); + /* Nothing to poll until resume; the worker would only see DOWN. */ + cancel_delayed_work_sync(&devinfo->poll_work); + /* As Broadcom's driver: no device interrupts until resume. */ + brcmf_pcie_intr_disable(devinfo); + brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->mailboxint, + brcmf_pcie_read_reg32(devinfo, + devinfo->reginfo->mailboxint)); return 0; } @@ -2688,15 +3531,29 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev) /* Check if device is still up and running, if so we are ready */ if (brcmf_pcie_read_reg32(devinfo, devinfo->reginfo->intmask) != 0) { brcmf_dbg(PCIE, "Try to wakeup device....\n"); - if (brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM)) + /* + * With mailbox data as control messages there is no D0 inform: + * the host-ready doorbell below resumes the device. + */ + if (!devinfo->mb_ctrlmsg && + brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM)) goto cleanup; brcmf_dbg(PCIE, "Hot resume, continue....\n"); + dev_dbg(dev, "hot resume\n"); devinfo->state = BRCMFMAC_PCIE_STATE_UP; + devinfo->d3_ack_pending = false; brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); brcmf_bus_change_state(bus, BRCMF_BUS_UP); brcmf_pcie_intr_enable(devinfo); brcmf_pcie_hostready(devinfo); brcmf_pcie_fwcon_timer(devinfo, true); + /* + * Completions the device posted while the interrupt was off + * would otherwise wait for the next interrupt. + */ + brcmf_pcie_handle_mb_data(devinfo); + brcmf_pcie_rx_process(devinfo); + brcmf_pcie_kick_poll(devinfo); return 0; } @@ -2706,6 +3563,7 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev) pdev = devinfo->pdev; brcmf_pcie_remove(pdev); + dev_dbg(dev, "device lost its state in sleep, probing again\n"); err = brcmf_pcie_probe(pdev, NULL); if (err) __brcmf_err(NULL, __func__, "probe after resume failed, err=%d\n", err); @@ -2770,6 +3628,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/brcmutil/d11.c b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c index 1e2b1e487e..ab33f7a13b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmutil/d11.c @@ -228,6 +228,9 @@ static void brcmu_d11ac_decchspec(struct brcmu_chan *ch) case BRCMU_CHSPEC_D11AC_BND_2G: ch->band = BRCMU_CHAN_BAND_2G; break; + case BRCMU_CHSPEC_D11AC_BND_6G: + ch->band = BRCMU_CHAN_BAND_6G; + break; default: WARN_ONCE(1, "Invalid chanspec 0x%04x\n", ch->chspec); break; diff --git a/drivers/net/wireless/broadcom/brcm80211/include/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/net/wireless/broadcom/brcm80211/include/brcmu_d11.h b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h index f634402385..c8ef37342b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h +++ b/drivers/net/wireless/broadcom/brcm80211/include/brcmu_d11.h @@ -82,11 +82,13 @@ #define BRCMU_CHSPEC_D11AC_BND_SHIFT 14 #define BRCMU_CHSPEC_D11AC_BND_2G 0x0000 #define BRCMU_CHSPEC_D11AC_BND_3G 0x4000 +#define BRCMU_CHSPEC_D11AC_BND_6G BRCMU_CHSPEC_D11AC_BND_3G #define BRCMU_CHSPEC_D11AC_BND_4G 0x8000 #define BRCMU_CHSPEC_D11AC_BND_5G 0xc000 #define BRCMU_CHAN_BAND_2G 0 #define BRCMU_CHAN_BAND_5G 1 +#define BRCMU_CHAN_BAND_6G 2 enum brcmu_chan_bw { BRCMU_CHAN_BW_20, diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index dcfbe7e229..5697af1a14 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -403,6 +403,28 @@ config PCI_EXYNOS hardware and therefore the driver re-uses the DesignWare core functions to implement the driver. +config PCIE_GS201 + tristate "Google gs201 PCIe controller (host mode)" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on PCI_MSI + select PCIE_DW_HOST + select PCI_PWRCTRL_GENERIC + help + Say Y here to enable support for the PCIe controller of the Google + gs201 (Tensor G2) 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" + depends on PCIE_GS201 + help + Confine the DMA of the device on the gs201 PCIe GEN4A_1 controller + (the Pixel 7 Wi-Fi chip) to one reserved memory region, with the + System MMU that sits in front of the controller. The region is + mapped 1:1, so the device driver keeps using physical addresses. + config PCIE_FU740 bool "SiFive FU740 PCIe controller" depends on PCI_MSI diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile index d4f88cfc62..cee2d114d7 100644 --- a/drivers/pci/controller/dwc/Makefile +++ b/drivers/pci/controller/dwc/Makefile @@ -9,6 +9,8 @@ obj-$(CONFIG_PCIE_ANDES_QILAI) += pcie-andes-qilai.o obj-$(CONFIG_PCIE_ESWIN) += pcie-eswin.o obj-$(CONFIG_PCI_DRA7XX) += pci-dra7xx.o obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o +obj-$(CONFIG_PCIE_GS201) += pcie-gs201.o +obj-$(CONFIG_PCIE_GS201_SYSMMU) += pcie-gs201-sysmmu.o obj-$(CONFIG_PCIE_FU740) += pcie-fu740.o obj-$(CONFIG_PCI_IMX6) += pci-imx6.o obj-$(CONFIG_PCIE_NXP_S32G) += pcie-nxp-s32g.o diff --git a/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c new file mode 100644 index 0000000000..c3a865c668 --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-gs201-sysmmu.c @@ -0,0 +1,389 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * DMA window for the Google gs201 PCIe GEN4A_1 (Wi-Fi) controller + * + * The HSI2 block has a Samsung System MMU (version 8.1) in front of the + * PCIe channel 1 master. Stock Android translates the Wi-Fi chip's DMA + * through it (VID 1). Here it is used as a firewall instead: one first-level + * table that maps a single reserved region 1:1 (IOVA = PA), so the device + * keeps using physical addresses but cannot reach anything else. Any other + * access is a translation fault, logged by this driver. + * + * Register map, table format and enable sequence follow Google's driver, + * google-modules/soc/gs/drivers/iommu/exynos-pcie-iommu-whi.[ch] + * (__sysmmu_enable_nocount(), __sysmmu_set_ptbase(), the fault handler). + * + * The "mode" parameter stages the bring-up: + * 0 read the registers and log them, change nothing (default) + * 1 enforce: map the region from google,dma-window, nothing else + * 2 enforce with an empty table (every DMA faults; a negative test) + * 3 map everything 1:1 except the region (only DMA into the region + * faults; a negative test that is safe to run on every VID) + * + * Which VID the PCIe master's traffic carries is not programmed by any + * kernel code (stock or here); "vids" selects the VIDs to translate, and a + * fault line names the VID it came from. Measured on cheetah: both the PCIe + * master (AxID 0x0) and the UFS host controller (AxID 0x2) arrive on VID 0, + * so this SysMMU cannot confine the PCIe device without also confining + * storage. VID 0 is refused unless allow_vid0 is set (debug only). + * + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_MMU_CTRL 0x0000 +#define REG_MMU_CFG 0x0004 +#define REG_MMU_STATUS 0x0008 +#define REG_MMU_VERSION 0x0034 +#define REG_INT_STATUS 0x0060 +#define REG_INT_CLEAR 0x0064 +/* With VM (CAPA1 bit 14) the fault registers are per VID, 0x10 apart */ +#define REG_FAULT_ADDR_VA(n) (0x1000 + (n) * 0x10) +#define REG_FAULT_INFO0(n) (0x1004 + (n) * 0x10) +#define REG_MMU_TLB_CFG0 0x2004 +#define REG_MMU_CTRL_VID(n) (0x8000 + (n) * 0x1000) +#define REG_MMU_CFG_VID(n) (0x8004 + (n) * 0x1000) +#define REG_PT_BASE_PPN_VID(n) (0x800c + (n) * 0x1000) +#define REG_MMU_FLUSH_VID(n) (0x8010 + (n) * 0x1000) + +#define CTRL_ENABLE 0x5 +#define CTRL_MMU_ENABLE BIT(0) +#define CTRL_FAULT_STALL_MODE BIT(3) + +#define MMU_RAW_VER(reg) (((reg) >> 17) & 0x7fff) +#define MMU_MAJ_VER(val) ((val) >> 11) +#define MMU_MIN_VER(val) (((val) >> 4) & 0x7f) + +/* 36-bit IOVA, 1 MiB first-level sections, 256 KiB-aligned table */ +#define NUM_LV1ENTRIES SZ_64K +#define LV1_TABLE_SIZE (NUM_LV1ENTRIES * sizeof(u32)) +#define SECT_ORDER 20 +#define SECT_SIZE BIT(SECT_ORDER) +#define PG_ENT_SHIFT 4 +#define LV1_SECT 2 +#define LV1_SHAREABLE BIT(6) +#define PT_BASE_SHIFT 12 + +static unsigned int mode; +module_param(mode, uint, 0444); +MODULE_PARM_DESC(mode, "0: log only (default), 1: map the DMA region only, 2: empty table, 3: everything but the DMA region (negative tests)"); + +static bool stall; +module_param(stall, bool, 0444); +MODULE_PARM_DESC(stall, "Leave the VID in stall-on-fault mode (default: error response)"); + +static unsigned int vids; +module_param(vids, uint, 0444); +MODULE_PARM_DESC(vids, "Bitmask of VIDs to translate (default: the DT's google,vid only); with mode=3, 0xff finds the one the controller uses"); + +static bool allow_vid0; +module_param(allow_vid0, bool, 0444); +MODULE_PARM_DESC(allow_vid0, "Debug only: allow translating VID 0, which also carries UFS (storage) traffic"); + +static bool shareable = true; +module_param(shareable, bool, 0444); +MODULE_PARM_DESC(shareable, "Mark the mapped sections shareable (the controller is cache coherent)"); + +struct gs201_sysmmu { + struct device *dev; + void __iomem *base; + struct clk_bulk_data *clks; + int num_clks; + u32 vid; + u32 vid_mask; + u32 *table; + dma_addr_t table_dma; + u32 saved_ctrl; + u32 saved_ctrl_vid[8]; + bool enforcing; +}; + +static void gs201_sysmmu_dump(struct gs201_sysmmu *mmu, const char *when) +{ + u32 ver = readl(mmu->base + REG_MMU_VERSION); + unsigned int v; + + dev_info(mmu->dev, "%s: version %#x (v%u.%u) ctrl %#x cfg %#x status %#x int %#x\n", + when, ver, MMU_MAJ_VER(MMU_RAW_VER(ver)), + MMU_MIN_VER(MMU_RAW_VER(ver)), + readl(mmu->base + REG_MMU_CTRL), + readl(mmu->base + REG_MMU_CFG), + readl(mmu->base + REG_MMU_STATUS), + readl(mmu->base + REG_INT_STATUS)); + + for (v = 0; v < 8; v++) { + if (!(BIT(v) & (mmu->vid_mask | BIT(mmu->vid)))) + continue; + /* pt_base is printed as an address: PPN << 12 */ + dev_info(mmu->dev, "%s: VID %u ctrl %#x cfg %#x table at %#llx\n", + when, v, readl(mmu->base + REG_MMU_CTRL_VID(v)), + readl(mmu->base + REG_MMU_CFG_VID(v)), + (u64)readl(mmu->base + REG_PT_BASE_PPN_VID(v)) << + PT_BASE_SHIFT); + } +} + +static irqreturn_t gs201_sysmmu_irq(int irq, void *data) +{ + struct gs201_sysmmu *mmu = data; + u32 status, info; + unsigned int v; + u64 addr; + + status = readl(mmu->base + REG_INT_STATUS); + if (!status) + return IRQ_NONE; + + /* Four interrupt bits per VID: PTW access, page fault, multi-hit, access */ + v = __ffs(status) / 4; + addr = readl(mmu->base + REG_FAULT_ADDR_VA(v)); + info = readl(mmu->base + REG_FAULT_INFO0(v)); + addr |= (u64)((info >> 28) & 0xf) << 32; + + dev_err_ratelimited(mmu->dev, + "blocked %s at %#llx (int %#x, VID %u, type %u, AxID %#x)\n", + (info & BIT(20)) ? "WRITE" : "READ", addr, status, + v, __ffs(status) % 4, info & 0xffff); + + writel(status, mmu->base + REG_INT_CLEAR); + return IRQ_HANDLED; +} + +static int gs201_sysmmu_build_table(struct gs201_sysmmu *mmu) +{ + struct reserved_mem *rmem = NULL; + struct device_node *np; + phys_addr_t pa, end; + u32 ent; + + /* + * Not "memory-region": for a restricted-dma-pool that would make the + * pool this device's own bounce buffer, and the table, mapped below, + * would be bounced into the very window the PCIe device may write. + */ + np = of_parse_phandle(mmu->dev->of_node, "google,dma-window", 0); + if (np) { + rmem = of_reserved_mem_lookup(np); + of_node_put(np); + } + if (!rmem) + return dev_err_probe(mmu->dev, -EINVAL, + "no google,dma-window to allow\n"); + + if (!IS_ALIGNED(rmem->base, SECT_SIZE) || + !IS_ALIGNED(rmem->size, SECT_SIZE) || + rmem->base + rmem->size > BIT_ULL(36)) + return dev_err_probe(mmu->dev, -EINVAL, + "region %pa + %pa is not 1 MiB sections below 64 GiB\n", + &rmem->base, &rmem->size); + + /* 256 KiB, naturally aligned (Google: "FLPD must be aligned in 256KB") */ + mmu->table = (u32 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(LV1_TABLE_SIZE)); + if (!mmu->table) + return -ENOMEM; + + end = rmem->base + rmem->size; + if (mode == 3) { + for (ent = 0; ent < NUM_LV1ENTRIES; ent++) { + pa = (phys_addr_t)ent << SECT_ORDER; + if (pa >= rmem->base && pa < end) + continue; + mmu->table[ent] = (u32)(pa >> PG_ENT_SHIFT) | LV1_SECT | + (shareable ? LV1_SHAREABLE : 0); + } + dev_info(mmu->dev, "blocking only %pa..%pa, everything else 1:1\n", + &rmem->base, &end); + } else if (mode == 1) { + for (pa = rmem->base; pa < end; pa += SECT_SIZE) { + ent = (u32)(pa >> PG_ENT_SHIFT) | LV1_SECT; + if (shareable) + ent |= LV1_SHAREABLE; + mmu->table[pa >> SECT_ORDER] = ent; + } + dev_info(mmu->dev, "allowing %pa..%pa (%llu sections)\n", + &rmem->base, &end, + (u64)(rmem->size >> SECT_ORDER)); + } else { + dev_info(mmu->dev, "empty table: every DMA will fault\n"); + } + + /* The table walker is not coherent: map it for the device (cleans). */ + mmu->table_dma = dma_map_single(mmu->dev, mmu->table, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + if (dma_mapping_error(mmu->dev, mmu->table_dma)) { + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + mmu->table = NULL; + return -ENOMEM; + } + if (mmu->table_dma != virt_to_phys(mmu->table) || + (mmu->table_dma < end && + mmu->table_dma + LV1_TABLE_SIZE > rmem->base)) { + dev_err(mmu->dev, "table at %pad is bounced or inside the window\n", + &mmu->table_dma); + dma_unmap_single(mmu->dev, mmu->table_dma, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + mmu->table = NULL; + return -EINVAL; + } + dev_info(mmu->dev, "table at %pad (outside the window)\n", + &mmu->table_dma); + return 0; +} + +static void gs201_sysmmu_enable(struct gs201_sysmmu *mmu) +{ + unsigned int v; + u32 ctrl; + + mmu->saved_ctrl = readl(mmu->base + REG_MMU_CTRL); + + /* As __sysmmu_enable_nocount(): TLB0, table base, flush, enable */ + writel(0, mmu->base + REG_MMU_TLB_CFG0); + for (v = 0; v < 8; v++) { + if (!(BIT(v) & mmu->vid_mask)) + continue; + writel(mmu->table_dma >> PT_BASE_SHIFT, + mmu->base + REG_PT_BASE_PPN_VID(v)); + writel(1, mmu->base + REG_MMU_FLUSH_VID(v)); + } + writel(mmu->saved_ctrl | CTRL_ENABLE, mmu->base + REG_MMU_CTRL); + + for (v = 0; v < 8; v++) { + if (!(BIT(v) & mmu->vid_mask)) + continue; + ctrl = readl(mmu->base + REG_MMU_CTRL_VID(v)); + mmu->saved_ctrl_vid[v] = ctrl; + if (stall) + ctrl |= CTRL_FAULT_STALL_MODE; + else + ctrl &= ~CTRL_FAULT_STALL_MODE; + writel(ctrl | CTRL_MMU_ENABLE, mmu->base + REG_MMU_CTRL_VID(v)); + writel(1, mmu->base + REG_MMU_FLUSH_VID(v)); + } + mmu->enforcing = true; +} + +static void gs201_sysmmu_disable(struct gs201_sysmmu *mmu) +{ + unsigned int v; + + if (!mmu->enforcing) + return; + for (v = 0; v < 8; v++) + if (BIT(v) & mmu->vid_mask) + writel(mmu->saved_ctrl_vid[v], + mmu->base + REG_MMU_CTRL_VID(v)); + writel(mmu->saved_ctrl, mmu->base + REG_MMU_CTRL); + mmu->enforcing = false; +} + +static int gs201_sysmmu_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct gs201_sysmmu *mmu; + int irq, ret; + + mmu = devm_kzalloc(dev, sizeof(*mmu), GFP_KERNEL); + if (!mmu) + return -ENOMEM; + mmu->dev = dev; + platform_set_drvdata(pdev, mmu); + + mmu->vid = 1; + of_property_read_u32(dev->of_node, "google,vid", &mmu->vid); + if (mmu->vid > 7) + return dev_err_probe(dev, -EINVAL, "bad VID %u\n", mmu->vid); + mmu->vid_mask = (vids & 0xff) ?: BIT(mmu->vid); + /* + * On gs201 the UFS host controller's DMA also arrives on VID 0 (and + * so did the PCIe controller's, measured). Translating VID 0 with + * anything short of a full 1:1 map starves storage and wedges the + * phone, so never do it by default. + */ + if (mode && (mmu->vid_mask & BIT(0)) && !allow_vid0) + return dev_err_probe(dev, -EPERM, + "refusing to translate VID 0 (shared with UFS); allow_vid0=1 to override\n"); + + mmu->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(mmu->base)) + return PTR_ERR(mmu->base); + + ret = devm_clk_bulk_get_all_enabled(dev, &mmu->clks); + if (ret < 0) + return dev_err_probe(dev, ret, "clocks\n"); + mmu->num_clks = ret; + + gs201_sysmmu_dump(mmu, "probe"); + if (!mode) + return 0; + if (mode > 3) + return dev_err_probe(dev, -EINVAL, "bad mode %u\n", mode); + + ret = dma_set_mask(dev, DMA_BIT_MASK(36)); + if (ret) + return ret; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + ret = devm_request_irq(dev, irq, gs201_sysmmu_irq, 0, dev_name(dev), + mmu); + if (ret) + return ret; + + ret = gs201_sysmmu_build_table(mmu); + if (ret) + return ret; + + gs201_sysmmu_enable(mmu); + gs201_sysmmu_dump(mmu, "enforcing"); + return 0; +} + +static void gs201_sysmmu_remove(struct platform_device *pdev) +{ + struct gs201_sysmmu *mmu = platform_get_drvdata(pdev); + + gs201_sysmmu_disable(mmu); + if (mmu->table) { + dma_unmap_single(mmu->dev, mmu->table_dma, LV1_TABLE_SIZE, + DMA_TO_DEVICE); + free_pages((unsigned long)mmu->table, + get_order(LV1_TABLE_SIZE)); + } +} + +static const struct of_device_id gs201_sysmmu_of_match[] = { + { .compatible = "google,gs201-pcie-sysmmu" }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_sysmmu_of_match); + +static struct platform_driver gs201_sysmmu_driver = { + .probe = gs201_sysmmu_probe, + .remove = gs201_sysmmu_remove, + .driver = { + .name = "gs201-pcie-sysmmu", + .of_match_table = gs201_sysmmu_of_match, + /* unbinding while the device is busy would drop the firewall */ + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(gs201_sysmmu_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe System MMU as a DMA window"); +MODULE_LICENSE("GPL"); diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c new file mode 100644 index 0000000000..98238660b2 --- /dev/null +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -0,0 +1,1256 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 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 + * called I/A, and a sysreg for cache coherency). The sequence follows the + * driver Google builds for gs201, google-modules/soc/gs/drivers/pci/ + * controller/dwc-whi/pcie-exynos-rc.c (exynos_pcie_rc_resumed_phydown(), + * exynos_pcie_rc_poweron() and exynos_pcie_rc_establish_link()). + * + * Only legacy INTx interrupts are supported, which is what the Pixel 7 Wi-Fi + * uses on stock firmware too. + * + * Bring-up runs in numbered stages, each touching one more part of the + * hardware. The stop_after parameter ends probe after a given stage, and + * trace=1 logs every hardware step before it happens, so that a bus hang + * can be pinned to one register access. + * + * Copyright (C) 2020 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pcie-designware.h" + +/* ELBI (sub-control) registers */ +#define GS201_ELBI_IRQ0 0x000 +#define GS201_ELBI_IRQ0_INTA BIT(14) +#define GS201_ELBI_IRQ0_INTB BIT(16) +#define GS201_ELBI_IRQ0_INTC BIT(18) +#define GS201_ELBI_IRQ0_INTD BIT(20) +#define GS201_ELBI_IRQ1 0x004 +#define GS201_ELBI_IRQ1_LINK_DOWN BIT(10) +#define GS201_ELBI_IRQ2 0x008 +#define GS201_ELBI_IRQ2_CPL_TIMEOUT BIT(24) +#define GS201_ELBI_IRQ0_EN 0x010 +#define GS201_ELBI_IRQ1_EN 0x014 +#define GS201_ELBI_IRQ2_EN 0x018 +#define GS201_ELBI_LTSSM_EN 0x054 +#define GS201_ELBI_DEVICE_TYPE 0x080 +#define GS201_ELBI_DEVICE_TYPE_RC 0x4 +#define GS201_ELBI_LTSSM_STATE 0x2c8 +#define GS201_ELBI_LTSSM_STATE_MASK GENMASK(5, 0) +#define GS201_ELBI_PM_DSTATE 0x2e8 +#define GS201_ELBI_PM_DSTATE_MASK GENMASK(1, 0) +#define GS201_ELBI_IA_IRQ_SEL 0x388 +#define GS201_ELBI_IA_IRQ_LINK_UP BIT(10) +#define GS201_ELBI_LINKDOWN_RST_SEL 0x3a0 +#define GS201_ELBI_LINKDOWN_RST_MANUAL BIT(1) +#define GS201_ELBI_SOFT_RESET 0x3a4 +#define GS201_ELBI_SOFT_PWR_RESET BIT(1) +#define GS201_ELBI_SOFT_NON_STICKY_RESET BIT(3) +#define GS201_ELBI_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 +#define GS201_ELBI_HISTORY_CTRL 0xc00 +#define GS201_ELBI_HISTORY_ENABLE GENMASK(1, 0) +#define GS201_ELBI_HISTORY_COND_SEL BIT(2) +#define GS201_ELBI_STATE_POWER_S 0xc04 +#define GS201_ELBI_STATE_POWER_M 0xc08 +#define GS201_ELBI_HISTORY(n) (0xc0c + 4 * (n)) +#define GS201_ELBI_HISTORY_NUM 32 +#define GS201_HISTORY_LTSSM GENMASK(21, 16) +#define GS201_HISTORY_DSTATE GENMASK(10, 8) +#define GS201_HISTORY_L1SUB GENMASK(2, 0) +#define GS201_ELBI_DBI_L1_EXIT_DISABLE 0x1078 + +/* INTA..INTD are every other bit from 14 (the bits in between: deassert) */ +#define GS201_ELBI_IRQ0_INTX_BIT(n) BIT(14 + 2 * (n)) + +/* DBI port logic registers used by Samsung's setup */ +#define GS201_DBI_AUX_CLK_FREQ 0xb40 +#define GS201_DBI_AUX_CLK_FREQ_26MHZ 26 + +/* SYSREG_HSI2 shareability control for this controller */ +#define GS201_SYSREG_SHARABLE_MASK GENMASK(1, 0) +#define GS201_SYSREG_SHARABLE_ENABLE 0x3 + +/* CMU_HSI2 registers, for the optional automatic clock gating switch */ +#define GS201_CMU_OPTION 0x0800 +#define GS201_CMU_OPTION_AUTO_GATING BIT(28) +#define GS201_CMU_GATE_FIRST 0x2000 +#define GS201_CMU_GATE_LAST 0x20f8 +#define GS201_CMU_QCH_PCIE_FIRST 0x3040 +#define GS201_CMU_QCH_PCIE_LAST 0x3064 + +/* Samsung's root port IDs */ +#define GS201_PCIE_VENDOR_ID PCI_VENDOR_ID_SAMSUNG +#define GS201_PCIE_DEVICE_ID 0xeced + +/* Google waits 20 ms after releasing PERST# before link training */ +#define GS201_PERST_DELAY_US 20000 + +/* Google polls 4800 x 10 us for L0, then retries the whole sequence */ +#define GS201_LINK_POLL_US 10 +#define GS201_LINK_TIMEOUT_US 48000 +#define GS201_LINK_TRIES 3 + +/* + * Bring-up stages. Each one adds hardware accesses to the previous ones; + * stop_after=N ends probe after stage N, with no host bridge registered. + */ +enum gs201_stage { + GS201_STAGE_NONE, /* 0: resources only, no hardware access */ + GS201_STAGE_CLOCKS, /* 1: clock references (+ optional CMU switch) */ + GS201_STAGE_WAKE, /* 2: PHY out of isolation, first PHY and ELBI accesses */ + GS201_STAGE_PHY, /* 3: PHY configuration, lock checks, I/A */ + GS201_STAGE_CTRL, /* 4: soft resets, ELBI and DBI setup */ + GS201_STAGE_LINK, /* 5: WL_REG_ON, PERST#, training, enumeration */ +}; + +static const char * const gs201_stage_names[] = { + [GS201_STAGE_NONE] = "resources", + [GS201_STAGE_CLOCKS] = "clocks", + [GS201_STAGE_WAKE] = "PHY isolation off, first PHY/ELBI access", + [GS201_STAGE_PHY] = "PHY configuration", + [GS201_STAGE_CTRL] = "controller setup", + [GS201_STAGE_LINK] = "link", +}; + +static unsigned int stop_after = GS201_STAGE_LINK; +module_param(stop_after, uint, 0444); +MODULE_PARM_DESC(stop_after, + "End probe after this bring-up stage: 0 resources, 1 clocks, 2 PHY isolation off + first register access, 3 PHY config, 4 controller setup, 5 link (default)"); + +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +static bool use_ia = true; +module_param(use_ia, bool, 0444); +MODULE_PARM_DESC(use_ia, + "Program the I/A CDR-lock sequencer, as stock does (default: true)"); + +static bool cmu_acg_off; +module_param(cmu_acg_off, bool, 0444); +MODULE_PARM_DESC(cmu_acg_off, + "Clear CMU_HSI2 automatic clock gating in stage 1, as Google's gs201 driver does (default: false)"); + +/** + * struct gs201_pcie_soc_data - what differs between the SoCs + * @ctrl_reset_before_phy: the controller's soft power reset and RC mode are + * set before the PHY configuration, and not again after it. zuma's + * CAL does them in the middle of its PHY configuration; gs201's + * establish_link() does them after. + */ +struct gs201_pcie_soc_data { + bool ctrl_reset_before_phy; +}; + +struct gs201_pcie { + struct dw_pcie pci; + const struct gs201_pcie_soc_data *data; + void __iomem *elbi; + void __iomem *ia; + void __iomem *cmu; + resource_size_t elbi_phys; + resource_size_t ia_phys; + resource_size_t pma_phys; + struct regmap *sysreg; + u32 sysreg_offset; + struct clk_bulk_data *clks; + int num_clks; + int clks_on; + struct phy *phy; + struct gpio_desc *perst; + bool coherent; + bool phy_inited; + bool phy_on; + int irq; + struct irq_domain *intx_domain; + raw_spinlock_t lock; +}; + +#define to_gs201_pcie(x) dev_get_drvdata((x)->dev) + +/* + * Log a step before it touches the hardware, then give the log reader time + * to pick it up: if the next access hangs the bus, this line is the last + * one that leaves the phone. + */ +static __printf(2, 3) void gs201_trace(struct gs201_pcie *gp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(gp->pci.dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static u32 gs201_elbi_readl(struct gs201_pcie *gp, u32 reg) +{ + return readl(gp->elbi + reg); +} + +static void gs201_elbi_writel(struct gs201_pcie *gp, u32 reg, u32 val) +{ + writel(val, gp->elbi + reg); +} + +static void gs201_elbi_rmw(struct gs201_pcie *gp, u32 reg, u32 clr, u32 set) +{ + gs201_elbi_writel(gp, reg, (gs201_elbi_readl(gp, reg) & ~clr) | set); +} + +/* + * I/A: a small sequencer next to the controller that re-locks the PHY's CDR + * when the link leaves L1.2. Stock programs it on every link up + * (exynos_pcie_rc_use_ia()). The words are Samsung's microcode; the first + * three entries are the physical bases of the ELBI, the PMA and the I/A. + */ +static const struct { u16 off; u32 val; } gs201_ia_seq[] = { + { 0x040, 0x00023000 }, /* loop interval, 0x3000 bus clocks */ + { 0x100, 0x50000004 }, { 0x104, 0x00000100 }, /* SQ0 data mask */ + { 0x108, 0x20420008 }, { 0x10c, 0x00000100 }, /* SQ1 check CDR done */ + { 0x110, 0x50000004 }, { 0x114, 0x00000400 }, /* SQ2 data mask */ + { 0x118, 0x10000008 }, { 0x11c, 0x00000000 }, /* SQ3 loop */ + { 0x120, 0x40020008 }, { 0x124, 0x00000100 }, /* SQ4 CDR_EN 0 */ + { 0x128, 0x50000004 }, { 0x12c, 0x000000f0 }, /* SQ5 AFC toggle */ + { 0x130, 0x20d10fc0 }, { 0x134, 0x000000f0 }, /* SQ6 check CDR done */ + { 0x138, 0x40010a48 }, { 0x13c, 0x00000020 }, /* SQ7 CDR_EN 0x20 */ + { 0x140, 0x40010a48 }, { 0x144, 0x00000030 }, /* SQ8 CDR_EN 0x30 */ + { 0x148, 0x40010a48 }, { 0x14c, 0x00000000 }, /* SQ9 CDR_EN 0 */ + { 0x150, 0x40010bf4 }, { 0x154, 0x00000005 }, /* SQ10 AFC toggle */ + { 0x158, 0x40010bf4 }, { 0x15c, 0x00000004 }, /* SQ11 AFC toggle */ + { 0x160, 0x30010fc0 }, { 0x164, 0x000000f0 }, /* SQ12 check CDR done */ + { 0x168, 0x40010bf4 }, { 0x16c, 0x00000005 }, /* SQ13 AFC toggle */ + { 0x170, 0x40000008 }, { 0x174, 0x00000400 }, /* SQ14 clear IRQ */ + { 0x178, 0x80000000 }, { 0x17c, 0x00000000 }, /* SQ15 back to idle */ +}; + +#define GS201_IA_EN 0x000 +#define GS201_IA_ELBI_BASE 0x030 +#define GS201_IA_PMA_BASE 0x034 +#define GS201_IA_IA_BASE 0x038 + +#define GS201_IA_EN 0x000 +#define GS201_IA_ELBI_BASE 0x030 +#define GS201_IA_PMA_BASE 0x034 +#define GS201_IA_IA_BASE 0x038 + +static void gs201_pcie_ia_program(struct gs201_pcie *gp) +{ + unsigned int i; + + if (!gp->ia || !use_ia) + return; + + gs201_trace(gp, "about to program the I/A sequencer (ELBI 0x388, I/A 0x000-0x17c) and start it"); + gs201_elbi_writel(gp, GS201_ELBI_IA_IRQ_SEL, GS201_ELBI_IA_IRQ_LINK_UP); + + writel(lower_32_bits(gp->elbi_phys), gp->ia + GS201_IA_ELBI_BASE); + writel(lower_32_bits(gp->pma_phys), gp->ia + GS201_IA_PMA_BASE); + writel(lower_32_bits(gp->ia_phys), gp->ia + GS201_IA_IA_BASE); + + for (i = 0; i < ARRAY_SIZE(gs201_ia_seq); i++) + writel(gs201_ia_seq[i].val, gp->ia + gs201_ia_seq[i].off); + + writel(1, gp->ia + GS201_IA_EN); +} + +static void gs201_pcie_ia_disable(struct gs201_pcie *gp) +{ + if (!gp->ia || !use_ia) + return; + + gs201_trace(gp, "about to stop the I/A sequencer"); + writel(0, gp->ia + GS201_IA_EN); +} + +static void gs201_pcie_set_iocc(struct gs201_pcie *gp, bool enable) +{ + struct dw_pcie *pci = &gp->pci; + + if (!gp->sysreg) + return; + + gs201_trace(gp, "about to %s IOCC (DBI 0x8e8, SYSREG_HSI2 %#x)", + enable ? "enable" : "disable", gp->sysreg_offset); + + /* AxCACHE[1] = 1 for every master port */ + dw_pcie_writel_dbi(pci, COHERENCY_CONTROL_3_OFF, + enable ? 0x10101010 : 0); + + regmap_update_bits(gp->sysreg, gp->sysreg_offset, + GS201_SYSREG_SHARABLE_MASK, + enable ? GS201_SYSREG_SHARABLE_ENABLE : 0); +} + +/* + * Google's driver programs the coherency once after the root port setup and + * again once the endpoint is enumerated (exynos_pcie_rc_establish_link() and + * the end of exynos_pcie_rc_probe()). Do the same, and print what the + * registers hold, since a device that is marked dma-coherent but is not + * snooped sees stale ring memory. + */ +static void gs201_pcie_check_iocc(struct gs201_pcie *gp, const char *when) +{ + struct dw_pcie *pci = &gp->pci; + u32 shr = 0; + + if (!gp->sysreg || !gp->coherent) + return; + + gs201_pcie_set_iocc(gp, true); + regmap_read(gp->sysreg, gp->sysreg_offset, &shr); + dev_info(pci->dev, "IOCC %s: AxCACHE 0x%08x, shareability 0x%x\n", when, + dw_pcie_readl_dbi(pci, COHERENCY_CONTROL_3_OFF), shr); +} + +static void gs201_pcie_setup_elbi(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to set up ELBI 0x3bc 0x3a0 0x3a8 0x474 0x1078 and the LTSSM history"); + gs201_elbi_rmw(gp, GS201_ELBI_REQ_EXIT_L1_MODE, 0, + GS201_ELBI_APP_REQ_EXIT_L1_MODE | + GS201_ELBI_L1_REQ_NAK_MASTER); + gs201_elbi_writel(gp, GS201_ELBI_LINKDOWN_RST_SEL, + GS201_ELBI_LINKDOWN_RST_MANUAL); + /* Q-channel: no clock gating requests from the controller */ + gs201_elbi_rmw(gp, GS201_ELBI_QCH_SEL, GS201_ELBI_QCH_GATING_MASK, 0); + /* NAK slave requests while AXI is pending */ + gs201_elbi_writel(gp, GS201_ELBI_MSTR_PEND_SEL_NAK, 1); + /* Keep DBI accesses from forcing an L1 exit (aux clock in L1.2) */ + gs201_elbi_writel(gp, GS201_ELBI_DBI_L1_EXIT_DISABLE, 1); + + /* LTSSM history buffer, for debugging failed training */ + gs201_elbi_rmw(gp, GS201_ELBI_HISTORY_CTRL, + GS201_ELBI_HISTORY_COND_SEL, 0); + gs201_elbi_writel(gp, GS201_ELBI_STATE_POWER_S, 0xffffffff); + gs201_elbi_writel(gp, GS201_ELBI_STATE_POWER_M, 0xffffffff); + gs201_elbi_rmw(gp, GS201_ELBI_HISTORY_CTRL, 0, + GS201_ELBI_HISTORY_ENABLE); +} + +static void gs201_pcie_setup_dbi(struct gs201_pcie *gp) +{ + struct dw_pcie *pci = &gp->pci; + u8 cap; + u32 val; + + gs201_trace(gp, "about to read DBI 0x000 and 0x8f8 (first DBI read)"); + dev_info(pci->dev, "DBI ID %#010x, DWC version %#010x\n", + dw_pcie_readl_dbi(pci, PCI_VENDOR_ID), + dw_pcie_readl_dbi(pci, PCIE_VERSION_NUMBER)); + + gs201_trace(gp, "about to walk the DBI capability list and write the root port setup"); + cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + + dw_pcie_dbi_ro_wr_en(pci); + + dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, GS201_PCIE_VENDOR_ID); + dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, GS201_PCIE_DEVICE_ID); + + /* Gen3 equalization off: the link is Gen2 at most on this board */ + dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, + GEN3_RELATED_OFF_GEN3_EQ_DISABLE | + GEN3_RELATED_OFF_RXEQ_RGRDLESS_RXTS); + + dw_pcie_writel_dbi(pci, GS201_DBI_AUX_CLK_FREQ, + GS201_DBI_AUX_CLK_FREQ_26MHZ); + + if (cap) { + /* L1 exit latency 64 us or more, as stock */ + val = dw_pcie_readl_dbi(pci, cap + PCI_EXP_LNKCAP); + val &= ~PCI_EXP_LNKCAP_L1EL; + val |= FIELD_PREP(PCI_EXP_LNKCAP_L1EL, 7); + dw_pcie_writel_dbi(pci, cap + PCI_EXP_LNKCAP, val); + + /* Completion timeout range B (16-55 ms), as stock */ + val = dw_pcie_readl_dbi(pci, cap + PCI_EXP_DEVCTL2); + val &= ~PCI_EXP_DEVCTL2_COMP_TIMEOUT; + val |= 0x5; + dw_pcie_writel_dbi(pci, cap + PCI_EXP_DEVCTL2, val); + } else { + dev_warn(pci->dev, "no PCIe capability in DBI\n"); + } + + dw_pcie_dbi_ro_wr_dis(pci); +} + +static enum dw_pcie_ltssm gs201_pcie_get_ltssm(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + + return FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); +} + +static bool gs201_pcie_link_up(struct dw_pcie *pci) +{ + enum dw_pcie_ltssm ltssm = gs201_pcie_get_ltssm(pci); + + /* Same window as Google's exynos_pcie_rc_link_up() */ + return ltssm >= DW_PCIE_LTSSM_RCVRY_LOCK && + ltssm <= DW_PCIE_LTSSM_L1_IDLE; +} + +static void gs201_pcie_enable_irqs(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to clear ELBI IRQ0-2 and enable link-down and completion-timeout interrupts"); + + /* Clear anything latched during training */ + gs201_elbi_writel(gp, GS201_ELBI_IRQ0, + gs201_elbi_readl(gp, GS201_ELBI_IRQ0)); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1, + gs201_elbi_readl(gp, GS201_ELBI_IRQ1)); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2, + gs201_elbi_readl(gp, GS201_ELBI_IRQ2)); + + gs201_elbi_rmw(gp, GS201_ELBI_IRQ1_EN, 0, GS201_ELBI_IRQ1_LINK_DOWN); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ2_EN, 0, GS201_ELBI_IRQ2_CPL_TIMEOUT); +} + +static void gs201_pcie_disable_irqs(struct gs201_pcie *gp) +{ + gs201_elbi_writel(gp, GS201_ELBI_IRQ0_EN, 0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1_EN, 0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2_EN, 0); +} + +/* Print the LTSSM history buffer, oldest entry first */ +static void gs201_pcie_dump_history(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + int i; + + for (i = GS201_ELBI_HISTORY_NUM - 1; i >= 0; i--) { + u32 h = gs201_elbi_readl(gp, GS201_ELBI_HISTORY(i)); + + dev_info(dev, "history: LTSSM %#04lx L1sub %lu D%lu\n", + FIELD_GET(GS201_HISTORY_LTSSM, h), + FIELD_GET(GS201_HISTORY_L1SUB, h), + FIELD_GET(GS201_HISTORY_DSTATE, h)); + } +} + +/* ---- Bring-up stages ------------------------------------------------- */ + +static void gs201_pcie_dump_cmu(struct gs201_pcie *gp, u32 first, u32 last) +{ + struct device *dev = gp->pci.dev; + u32 off; + + for (off = first; off <= last; off += 0x20) { + u32 v[8] = { }; + int i; + + for (i = 0; i < 8 && off + 4 * i <= last; i++) + v[i] = readl(gp->cmu + off + 4 * i); + + dev_info(dev, "CMU_HSI2 %#06x: %08x %08x %08x %08x %08x %08x %08x %08x\n", + off, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); + } +} + +/* + * Stage 1. The CMU_HSI2 gates run on automatic (Q-channel) gating, so the + * clock references below are bookkeeping and do not switch anything. + * Google's gs201 driver also clears the CMU's global automatic clock gating + * before using this controller; that is opt-in here (cmu_acg_off=1), + * because UFS lives in the same CMU. + */ +static int gs201_pcie_stage_clocks(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + u32 opt; + int ret; + + if (gp->cmu) { + gs201_trace(gp, "about to read CMU_HSI2 CONTROLLER_OPTION (0x14400800)"); + opt = readl(gp->cmu + GS201_CMU_OPTION); + dev_info(dev, "CMU_HSI2 option %#010x (automatic gating %s)\n", + opt, opt & GS201_CMU_OPTION_AUTO_GATING ? "on" : "off"); + + if (trace) { + gs201_trace(gp, "about to read the CMU_HSI2 gate and PCIe Q-channel registers"); + gs201_pcie_dump_cmu(gp, GS201_CMU_GATE_FIRST, + GS201_CMU_GATE_LAST); + gs201_pcie_dump_cmu(gp, GS201_CMU_QCH_PCIE_FIRST, + GS201_CMU_QCH_PCIE_LAST); + } + + if (cmu_acg_off && (opt & GS201_CMU_OPTION_AUTO_GATING)) { + gs201_trace(gp, "about to clear CMU_HSI2 option bit 28 (automatic clock gating; UFS shares this CMU)"); + writel(opt & ~GS201_CMU_OPTION_AUTO_GATING, + gp->cmu + GS201_CMU_OPTION); + dev_info(dev, "CMU_HSI2 automatic clock gating off (%#010x)\n", + readl(gp->cmu + GS201_CMU_OPTION)); + } + } else if (cmu_acg_off) { + dev_warn(dev, "cmu_acg_off needs samsung,cmu in the DT; skipped\n"); + } + + for (; gp->clks_on < gp->num_clks; gp->clks_on++) { + gs201_trace(gp, "enable clk %pC", gp->clks[gp->clks_on].clk); + ret = clk_prepare_enable(gp->clks[gp->clks_on].clk); + if (ret) + return ret; + } + + return 0; +} + +static void gs201_pcie_clocks_off(struct gs201_pcie *gp) +{ + while (gp->clks_on > 0) + clk_disable_unprepare(gp->clks[--gp->clks_on].clk); +} + +/* + * Stage 2. The bootloader leaves the PHY isolated in the PMU, and while it + * is isolated an ELBI access hangs the SoC (this is what hung the phone at + * W1.2 and W1.3). So the PHY driver releases isolation first (secure PMU + * write through the SMC), powers the PHY down as Google's probe does, and + * only then is the controller's ELBI touched. + */ +static int gs201_pcie_stage_wake(struct gs201_pcie *gp) +{ + struct dw_pcie *pci = &gp->pci; + int ret; + + if (!gp->phy_inited) { + gs201_trace(gp, "phy_init: PMU isolation off (SMC), then PHY power-down"); + phy_set_bus_width(gp->phy, pci->num_lanes ?: 1); + ret = phy_init(gp->phy); + if (ret) { + dev_err(pci->dev, "PHY init failed: %d\n", ret); + return ret; + } + gp->phy_inited = true; + } + + gs201_trace(gp, "about to write ELBI 0x010-0x018 (first ELBI access: interrupt enables off)"); + gs201_pcie_disable_irqs(gp); + + gs201_trace(gp, "about to write ELBI 0x054 (LTSSM off)"); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + + gs201_trace(gp, "about to read ELBI 0x3a8 0x3a4 0x080 (first ELBI reads)"); + dev_info(pci->dev, "ELBI QCH_SEL %#x SOFT_RESET %#x DEVICE_TYPE %#x\n", + gs201_elbi_readl(gp, GS201_ELBI_QCH_SEL), + gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET), + gs201_elbi_readl(gp, GS201_ELBI_DEVICE_TYPE)); + + return 0; +} + +/* + * 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) + return ret; + + gp->phy_on = true; + gs201_pcie_ia_program(gp); + + return 0; +} + +static void gs201_pcie_phy_off(struct gs201_pcie *gp) +{ + if (!gp->phy_on) + return; + + gs201_pcie_ia_disable(gp); + gs201_trace(gp, "phy_power_off: PHY power-down"); + phy_power_off(gp->phy); + gp->phy_on = false; +} + +/* + * Stage 4: the controller's soft resets and RC mode (Google's + * establish_link), then the ELBI and DBI setup and cache coherency. In the + * full bring-up PERST# is released between the resets and the setup, as + * Google does. + */ +static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) +{ + struct device *dev = gp->pci.dev; + u32 val; + + 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, + val & ~GS201_ELBI_SOFT_PWR_RESET); + mdelay(1); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_PWR_RESET); + + phy_calibrate(gp->phy); + + gs201_trace(gp, "about to write ELBI 0x080 = 4 (root complex)"); + gs201_elbi_writel(gp, GS201_ELBI_DEVICE_TYPE, GS201_ELBI_DEVICE_TYPE_RC); + + gs201_trace(gp, "about to pulse the non-sticky reset (ELBI 0x3a4 bit 3)"); + val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_NON_STICKY_RESET); + usleep_range(10, 12); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val & ~GS201_ELBI_SOFT_NON_STICKY_RESET); + mdelay(1); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_NON_STICKY_RESET); + +perst: + if (release_perst) { + gs201_trace(gp, "about to release PERST# and wait 20 ms"); + gpiod_set_value_cansleep(gp->perst, 0); + fsleep(GS201_PERST_DELAY_US); + } + + gs201_pcie_setup_elbi(gp); + gs201_pcie_setup_dbi(gp); + gs201_pcie_set_iocc(gp, gp->coherent); + + gs201_trace(gp, "about to read ELBI 0x2e8 and 0x2c8 (D-state, LTSSM)"); + dev_info(dev, "D-state %lu, LTSSM %#lx\n", + FIELD_GET(GS201_ELBI_PM_DSTATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_PM_DSTATE)), + FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE))); +} + +/* Stages 1 to @last (at most 4), each one announced */ +static int gs201_pcie_bringup(struct gs201_pcie *gp, unsigned int last, + bool release_perst) +{ + struct device *dev = gp->pci.dev; + unsigned int stage; + int ret = 0; + + for (stage = GS201_STAGE_CLOCKS; + stage <= min_t(unsigned int, last, GS201_STAGE_CTRL); stage++) { + dev_info(dev, "stage %u/%u: %s\n", stage, GS201_STAGE_LINK, + gs201_stage_names[stage]); + /* Give the log reader the stage line before the hardware */ + if (trace && trace_delay_ms) + msleep(trace_delay_ms); + + switch (stage) { + case GS201_STAGE_CLOCKS: + ret = gs201_pcie_stage_clocks(gp); + break; + case GS201_STAGE_WAKE: + ret = gs201_pcie_stage_wake(gp); + break; + case GS201_STAGE_PHY: + ret = gs201_pcie_stage_phy(gp); + break; + case GS201_STAGE_CTRL: + gs201_pcie_stage_ctrl(gp, release_perst); + break; + } + if (ret) { + dev_err(dev, "stage %u failed: %d\n", stage, ret); + return ret; + } + dev_info(dev, "stage %u done\n", stage); + } + + return 0; +} + +/* Undo what the stages did, in reverse; the PHY stays out of isolation */ +static void gs201_pcie_bringdown(struct gs201_pcie *gp) +{ + gs201_pcie_phy_off(gp); + if (gp->phy_inited) { + gs201_trace(gp, "phy_exit"); + phy_exit(gp->phy); + gp->phy_inited = false; + } + gs201_pcie_clocks_off(gp); +} + +static int gs201_pcie_start_link(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + struct device *dev = pci->dev; + unsigned int try; + u32 val; + int ret; + + for (try = 1; try <= GS201_LINK_TRIES; try++) { + gs201_trace(gp, "link try %u: about to write ELBI 0x054 = 1 and poll 0x2c8 for L0 (48 ms)", + try); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 1); + + ret = readl_poll_timeout(gp->elbi + GS201_ELBI_LTSSM_STATE, val, + FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, + val) == DW_PCIE_LTSSM_L0, + GS201_LINK_POLL_US, + GS201_LINK_TIMEOUT_US); + if (!ret) + break; + + dev_warn(dev, "link training failed (try %u), LTSSM %#lx\n", + try, FIELD_GET(GS201_ELBI_LTSSM_STATE_MASK, val)); + + if (try == GS201_LINK_TRIES) { + gs201_pcie_dump_history(gp); + break; + } + + /* + * As Google: PERST# low, LTSSM off, then the whole PHY and + * controller sequence again (the soft resets clear the + * root port setup, so the DWC part is redone too). + */ + gs201_trace(gp, "retry: PERST# low, LTSSM off, PHY and controller again"); + gpiod_set_value_cansleep(gp->perst, 1); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + gs201_pcie_phy_off(gp); + ret = gs201_pcie_stage_phy(gp); + if (ret) + return ret; + gs201_pcie_stage_ctrl(gp, true); + ret = dw_pcie_setup_rc(&pci->pp); + if (ret) + return ret; + } + + /* + * Leave the LTSSM running even on failure: dw_pcie_wait_for_link() + * reports the final state, and a card that shows up late can still + * train. + */ + if (!ret) { + dev_info(dev, "link up on try %u\n", try); + gs201_pcie_enable_irqs(gp); + gs201_pcie_check_iocc(gp, "after link up"); + } + + dev_dbg(dev, "D-state %lu, LTSSM %#x\n", + FIELD_GET(GS201_ELBI_PM_DSTATE_MASK, + gs201_elbi_readl(gp, GS201_ELBI_PM_DSTATE)), + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); + + return 0; +} + +static void gs201_pcie_stop_link(struct dw_pcie *pci) +{ + struct gs201_pcie *gp = to_gs201_pcie(pci); + + gs201_pcie_disable_irqs(gp); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); +} + +static const struct dw_pcie_ops gs201_pcie_dw_ops = { + .link_up = gs201_pcie_link_up, + .get_ltssm = gs201_pcie_get_ltssm, + .start_link = gs201_pcie_start_link, + .stop_link = gs201_pcie_stop_link, +}; + +static void gs201_pcie_irq_handler(struct irq_desc *desc); + +/* + * Stage 5 entry, from dw_pcie_host_init(): stages 1-2, the endpoint power + * (WL_REG_ON, 200 ms), stages 3-4 with PERST# released, then the DWC core + * sets up the root port and calls start_link. This is the order of + * Google's resumed_phydown(), poweron() and establish_link(). + */ +static int gs201_pcie_host_init(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct gs201_pcie *gp = to_gs201_pcie(pci); + struct device *dev = pci->dev; + int ret; + + gpiod_set_value_cansleep(gp->perst, 1); + + ret = gs201_pcie_bringup(gp, GS201_STAGE_WAKE, false); + if (ret) + goto err_bringdown; + + /* ELBI is reachable and its interrupt enables are off */ + irq_set_chained_handler_and_data(gp->irq, gs201_pcie_irq_handler, gp); + + dev_info(dev, "stage %u/%u: %s\n", GS201_STAGE_LINK, GS201_STAGE_LINK, + gs201_stage_names[GS201_STAGE_LINK]); + + /* Endpoint power (WL_REG_ON) through pwrctrl, before the PHY config */ + if (!pci->suspended) { + gs201_trace(gp, "about to create the pwrctrl device for the root port"); + ret = pci_pwrctrl_create_devices(dev); + if (ret) + goto err_unchain; + } + + if (!pp->skip_pwrctrl_off) { + gs201_trace(gp, "about to power the endpoint (WL_REG_ON and its startup delay)"); + ret = pci_pwrctrl_power_on_devices(dev); + if (ret) + goto err_pwrctrl_destroy; + } + + ret = gs201_pcie_stage_phy(gp); + if (ret) + goto err_pwrctrl_off; + + gs201_pcie_stage_ctrl(gp, true); + + gs201_trace(gp, "handing over to the DWC core (version, iATU, root port setup)"); + + return 0; + +err_pwrctrl_off: + if (!pp->skip_pwrctrl_off) + pci_pwrctrl_power_off_devices(dev); +err_pwrctrl_destroy: + if (ret != -EPROBE_DEFER && !pci->suspended) + pci_pwrctrl_destroy_devices(dev); +err_unchain: + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); +err_bringdown: + gpiod_set_value_cansleep(gp->perst, 1); + gs201_pcie_bringdown(gp); + return ret; +} + +static void gs201_pcie_host_deinit(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct gs201_pcie *gp = to_gs201_pcie(pci); + + gs201_trace(gp, "deinit: PERST# low, IOCC off, PHY off, endpoint off"); + gpiod_set_value_cansleep(gp->perst, 1); + gs201_pcie_disable_irqs(gp); + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); + gs201_pcie_set_iocc(gp, false); + gs201_pcie_bringdown(gp); + + if (!pp->skip_pwrctrl_off) + pci_pwrctrl_power_off_devices(pci->dev); + if (!pci->suspended) + pci_pwrctrl_destroy_devices(pci->dev); +} + +/* + * The Samsung wrapper raises MSIs on the shared line or on separate SPIs and + * needs its own glue; nothing on this board uses MSI. Claim MSI init so the + * DWC core does not take over the shared interrupt for iMSI-RX. Devices fall + * back to INTx. + */ +static int gs201_pcie_msi_init(struct dw_pcie_rp *pp) +{ + return 0; +} + +static const struct dw_pcie_host_ops gs201_pcie_host_ops = { + .init = gs201_pcie_host_init, + .deinit = gs201_pcie_host_deinit, + .msi_init = gs201_pcie_msi_init, +}; + +static void gs201_pcie_intx_mask(struct irq_data *d) +{ + struct gs201_pcie *gp = irq_data_get_irq_chip_data(d); + unsigned long flags; + + raw_spin_lock_irqsave(&gp->lock, flags); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ0_EN, + GS201_ELBI_IRQ0_INTX_BIT(irqd_to_hwirq(d)), 0); + raw_spin_unlock_irqrestore(&gp->lock, flags); +} + +static void gs201_pcie_intx_unmask(struct irq_data *d) +{ + struct gs201_pcie *gp = irq_data_get_irq_chip_data(d); + unsigned long flags; + + raw_spin_lock_irqsave(&gp->lock, flags); + gs201_elbi_rmw(gp, GS201_ELBI_IRQ0_EN, 0, + GS201_ELBI_IRQ0_INTX_BIT(irqd_to_hwirq(d))); + raw_spin_unlock_irqrestore(&gp->lock, flags); +} + +static struct irq_chip gs201_pcie_intx_chip = { + .name = "gs201-pcie-intx", + .irq_mask = gs201_pcie_intx_mask, + .irq_unmask = gs201_pcie_intx_unmask, +}; + +static int gs201_pcie_intx_map(struct irq_domain *domain, unsigned int irq, + irq_hw_number_t hwirq) +{ + irq_set_chip_and_handler(irq, &gs201_pcie_intx_chip, handle_level_irq); + irq_set_chip_data(irq, domain->host_data); + + return 0; +} + +static const struct irq_domain_ops gs201_pcie_intx_domain_ops = { + .map = gs201_pcie_intx_map, + .xlate = pci_irqd_intx_xlate, +}; + +static void gs201_pcie_irq_handler(struct irq_desc *desc) +{ + struct gs201_pcie *gp = irq_desc_get_handler_data(desc); + struct irq_chip *chip = irq_desc_get_chip(desc); + struct device *dev = gp->pci.dev; + unsigned long intx; + u32 irq0, irq1, irq2; + int bit; + + chained_irq_enter(chip, desc); + + /* The status bits are write-one-to-clear events */ + irq0 = gs201_elbi_readl(gp, GS201_ELBI_IRQ0); + gs201_elbi_writel(gp, GS201_ELBI_IRQ0, irq0); + irq1 = gs201_elbi_readl(gp, GS201_ELBI_IRQ1); + gs201_elbi_writel(gp, GS201_ELBI_IRQ1, irq1); + irq2 = gs201_elbi_readl(gp, GS201_ELBI_IRQ2); + gs201_elbi_writel(gp, GS201_ELBI_IRQ2, irq2); + + if (irq1 & GS201_ELBI_IRQ1_LINK_DOWN) + dev_err_ratelimited(dev, "link down (LTSSM %#x)\n", + gs201_elbi_readl(gp, GS201_ELBI_LTSSM_STATE)); + if (irq2 & GS201_ELBI_IRQ2_CPL_TIMEOUT) + dev_err_ratelimited(dev, "completion timeout\n"); + + intx = 0; + for (bit = 0; bit < PCI_NUM_INTX; bit++) + if (irq0 & GS201_ELBI_IRQ0_INTX_BIT(bit)) + intx |= BIT(bit); + + for_each_set_bit(bit, &intx, PCI_NUM_INTX) + generic_handle_domain_irq(gp->intx_domain, bit); + + chained_irq_exit(chip, desc); +} + +/* + * Only the INTx domain is created here; the chained handler is installed by + * host_init once the PHY is out of isolation and the ELBI interrupt enables + * are off, because the handler reads ELBI. + */ +static int gs201_pcie_init_irq(struct gs201_pcie *gp, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *intc; + + gp->irq = platform_get_irq(pdev, 0); + if (gp->irq < 0) + return gp->irq; + + intc = of_get_child_by_name(dev->of_node, "legacy-interrupt-controller"); + if (!intc) + return dev_err_probe(dev, -ENODEV, + "missing legacy-interrupt-controller\n"); + + gp->intx_domain = irq_domain_create_linear(of_fwnode_handle(intc), + PCI_NUM_INTX, + &gs201_pcie_intx_domain_ops, + gp); + of_node_put(intc); + if (!gp->intx_domain) + return -ENOMEM; + + return 0; +} + +static void gs201_pcie_remove_irq(struct gs201_pcie *gp) +{ + irq_set_chained_handler_and_data(gp->irq, NULL, NULL); + irq_domain_remove(gp->intx_domain); +} + +/* The I/A sequencer needs the PMA's physical address from the PHY node */ +static int gs201_pcie_get_ia(struct gs201_pcie *gp, + struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *phy_np; + struct resource *res, pma; + int idx, ret; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ia"); + if (!res) + return 0; + + phy_np = of_parse_phandle(dev->of_node, "phys", 0); + if (!phy_np) + return -ENODEV; + + idx = of_property_match_string(phy_np, "reg-names", "pma"); + ret = idx < 0 ? idx : of_address_to_resource(phy_np, idx, &pma); + of_node_put(phy_np); + if (ret) + return dev_err_probe(dev, ret, "no PMA address for I/A\n"); + + gp->ia = devm_ioremap_resource(dev, res); + if (IS_ERR(gp->ia)) + return PTR_ERR(gp->ia); + + gp->ia_phys = res->start; + gp->pma_phys = pma.start; + + return 0; +} + +/* + * Optional: CMU_HSI2, for the automatic clock gating switch and the gate + * dump. The clock driver owns (and has requested) that region, so it is + * mapped without a request. + */ +static int gs201_pcie_get_cmu(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + struct device_node *cmu_np; + struct resource res; + int ret; + + cmu_np = of_parse_phandle(dev->of_node, "samsung,cmu", 0); + if (!cmu_np) + return 0; + + ret = of_address_to_resource(cmu_np, 0, &res); + of_node_put(cmu_np); + if (ret) + return dev_err_probe(dev, ret, "bad samsung,cmu\n"); + + if (resource_size(&res) <= GS201_CMU_QCH_PCIE_LAST) + return dev_err_probe(dev, -EINVAL, "samsung,cmu region too small\n"); + + gp->cmu = devm_ioremap(dev, res.start, resource_size(&res)); + if (!gp->cmu) + return -ENOMEM; + + return 0; +} + +/* stop_after < 5: run the stages, report, undo, and do not bind */ +static int gs201_pcie_staged_probe(struct gs201_pcie *gp) +{ + struct device *dev = gp->pci.dev; + struct platform_device *pdev = to_platform_device(dev); + int ret; + + /* dw_pcie_host_init() is not called, so map the DBI for stage 4 */ + if (stop_after >= GS201_STAGE_CTRL) { + gp->pci.dbi_base = devm_platform_ioremap_resource_byname(pdev, "dbi"); + if (IS_ERR(gp->pci.dbi_base)) + return PTR_ERR(gp->pci.dbi_base); + } + + ret = gs201_pcie_bringup(gp, stop_after, false); + gs201_pcie_bringdown(gp); + if (ret) + return ret; + + dev_info(dev, "stopped after stage %u as asked (stop_after=%u); not binding\n", + stop_after, stop_after); + + return -ENODEV; +} + +static int gs201_pcie_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct gs201_pcie *gp; + struct dw_pcie *pci; + struct resource *res; + int ret; + + gp = devm_kzalloc(dev, sizeof(*gp), GFP_KERNEL); + if (!gp) + return -ENOMEM; + + raw_spin_lock_init(&gp->lock); + gp->data = of_device_get_match_data(dev); + + pci = &gp->pci; + pci->dev = dev; + pci->ops = &gs201_pcie_dw_ops; + pci->pp.ops = &gs201_pcie_host_ops; + + dev_info(dev, "stage 0/%u: %s (stop_after=%u, trace=%d, use_ia=%d, cmu_acg_off=%d)\n", + GS201_STAGE_LINK, gs201_stage_names[GS201_STAGE_NONE], + stop_after, trace, use_ia, cmu_acg_off); + + /* Mappings only: nothing below touches the hardware */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "elbi"); + gp->elbi = devm_ioremap_resource(dev, res); + if (IS_ERR(gp->elbi)) + return PTR_ERR(gp->elbi); + gp->elbi_phys = res->start; + /* Hand it to the DWC core, which would otherwise request it again. */ + pci->elbi_base = gp->elbi; + + ret = gs201_pcie_get_ia(gp, pdev); + if (ret) + return ret; + + ret = gs201_pcie_get_cmu(gp); + if (ret) + return ret; + + gp->coherent = of_dma_is_coherent(np); + if (gp->coherent) { + gp->sysreg = syscon_regmap_lookup_by_phandle_args(np, + "samsung,sysreg", + 1, + &gp->sysreg_offset); + if (IS_ERR(gp->sysreg)) + return dev_err_probe(dev, PTR_ERR(gp->sysreg), + "dma-coherent needs samsung,sysreg\n"); + } + + gp->num_clks = devm_clk_bulk_get_all(dev, &gp->clks); + if (gp->num_clks < 0) + return dev_err_probe(dev, gp->num_clks, "failed to get clocks\n"); + + gp->phy = devm_phy_get(dev, "pcie"); + if (IS_ERR(gp->phy)) + return dev_err_probe(dev, PTR_ERR(gp->phy), "failed to get PHY\n"); + + /* PERST# asserted (a GPIO, not the controller) until stage 5 */ + gp->perst = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(gp->perst)) + return dev_err_probe(dev, PTR_ERR(gp->perst), + "failed to get PERST# GPIO\n"); + + /* The DWC core reads num-lanes in host_init; stages need it earlier */ + if (of_property_read_u32(np, "num-lanes", &pci->num_lanes)) + pci->num_lanes = 1; + + platform_set_drvdata(pdev, gp); + + if (stop_after < GS201_STAGE_LINK) + return gs201_pcie_staged_probe(gp); + + ret = gs201_pcie_init_irq(gp, pdev); + if (ret) + return ret; + + ret = dw_pcie_host_init(&pci->pp); + if (ret) { + dev_err_probe(dev, ret, "failed to initialize host\n"); + gs201_pcie_remove_irq(gp); + return ret; + } + + gs201_pcie_check_iocc(gp, "after enumeration"); + + return 0; +} + +static void gs201_pcie_remove(struct platform_device *pdev) +{ + struct gs201_pcie *gp = platform_get_drvdata(pdev); + + dw_pcie_host_deinit(&gp->pci.pp); + gs201_pcie_remove_irq(gp); +} + +static const struct gs201_pcie_soc_data gs201_pcie_data = { +}; + +static const struct gs201_pcie_soc_data zuma_pcie_data = { + .ctrl_reset_before_phy = true, +}; + +static const struct of_device_id gs201_pcie_of_match[] = { + { .compatible = "google,gs201-pcie", .data = &gs201_pcie_data }, + { .compatible = "google,zuma-pcie", .data = &zuma_pcie_data }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_pcie_of_match); + +static struct platform_driver gs201_pcie_driver = { + .probe = gs201_pcie_probe, + .remove = gs201_pcie_remove, + .driver = { + .name = "gs201-pcie", + .of_match_table = gs201_pcie_of_match, + }, +}; +module_platform_driver(gs201_pcie_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe host controller driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/phy/samsung/Kconfig b/drivers/phy/samsung/Kconfig index 6849ced7ad..f07690fc91 100644 --- a/drivers/phy/samsung/Kconfig +++ b/drivers/phy/samsung/Kconfig @@ -29,6 +29,28 @@ config PHY_EXYNOS_PCIE Enable PCIe PHY support for Exynos SoC series. This driver provides PHY interface for Exynos PCIe controller. +config PHY_GS201_PCIE + tristate "Google gs201 PCIe PHY driver" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on EXYNOS_PMU || COMPILE_TEST + select GENERIC_PHY + help + Enable support for the PCIe Gen4 PHY of the Google gs201 (Tensor G2) + SoC. It is used by the gs201 PCIe controller driver, which connects + the Wi-Fi chip on Pixel 7 phones. + +config PHY_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 463585ec90..56e77422a7 100644 --- a/drivers/phy/samsung/Makefile +++ b/drivers/phy/samsung/Makefile @@ -2,6 +2,8 @@ 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-gs201-pcie.c b/drivers/phy/samsung/phy-gs201-pcie.c new file mode 100644 index 0000000000..4218f86745 --- /dev/null +++ b/drivers/phy/samsung/phy-gs201-pcie.c @@ -0,0 +1,635 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google gs201 (Tensor G2) PCIe Gen4 PHY driver + * + * The register sequence is Samsung's "CAL ver 210802" for gs201, taken from + * the driver Google builds for gs201 (pcie-exynos-gs201-rc-cal.c and + * pcie-exynos-rc.c in google-modules/soc/gs/drivers/pci/controller/dwc-whi). + * Most PMA registers have no public names, so the tables keep Samsung's raw + * offsets and values. + * + * Copyright (C) 2021 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Bring-up tracing: with trace=1 every step that touches the hardware is + * logged before it happens, and the driver sleeps trace_delay_ms after each + * line so that a reader of /dev/kmsg (dmesg -w over SSH) receives it before a + * possible bus hang stops the CPU. Both can be changed at runtime through + * /sys/module/phy_gs201_pcie/parameters/. + */ +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +static bool check_tcxo; +module_param(check_tcxo, bool, 0644); +MODULE_PARM_DESC(check_tcxo, + "Read PMU TCXO_BUF_CTRL in phy_init and set the bits Google's driver expects (default: off)"); + +/* + * PHY reset block, in the controller's sub-control (ELBI) space at +0x1400. + * All three are active low. INIT_RST is released before the PMA is + * programmed, the other two after it. + */ +#define GS201_PHY_RST_CMN 0x0 +#define GS201_PHY_RST_INIT 0x4 +#define GS201_PHY_RST_PORT 0x8 + +/* PMU PHY control (PHY_CTRL_PCIE_GEN4_x) */ +#define GS201_PMU_PHY_BYPASS BIT(0) /* 0 = isolated */ + +/* PMU TCXO_BUF_CTRL: Google checks these are set before using PCIe ch1 */ +#define GS201_PMU_TCXO_BUF_CTRL 0x3c10 +#define GS201_PMU_TCXO_PCIE_MASK (BIT(2) | BIT(3) | BIT(10)) + +/* PMA common registers used outside the tables */ +#define GS201_PMA_INPUT_CLK 0x0d8 +#define GS201_PMA_INPUT_CLK_VAL 0x28 +#define GS201_PMA_CMN_CTRL 0x400 +#define GS201_PMA_CMN_CTRL_PMA_EN BIT(7) +#define GS201_PMA_CMN_PWRDN0 0x404 +#define GS201_PMA_CMN_PWRDN1 0x408 +#define GS201_PMA_CMN_PWRDN2 0x40c +#define GS201_PMA_XO_CFG 0x5d0 +#define GS201_PMA_XO_CFG_EXT BIT(4) +#define GS201_PMA_XO_CFG_INT BIT(3) +#define GS201_PMA_OC_STATUS 0x5fc /* logged by Google before config */ +#define GS201_PMA_CMN_STATUS 0x3f0 +#define GS201_PMA_CMN_STATUS_PLL_LOCK BIT(3) +#define GS201_PMA_AFC_CAL_MODE 0xbf4 +#define GS201_PMA_AFC_CAL_RESTART 0x4 +#define GS201_PMA_OC_DONE 0xde8 +#define GS201_PMA_OC_DONE_MASK GENMASK(3, 0) +#define GS201_PMA_CDR_STATUS 0xe0c +#define GS201_PMA_CDR_LOCK BIT(2) +#define GS201_PMA_OC_STATUS2 0xe18 +#define GS201_PMA_OC_STATUS2_DONE BIT(7) +#define GS201_PMA_LN0_STATUS 0xfc0 + +/* PCS */ +#define GS201_PCS_BIFURCATION 0x004 +#define GS201_PCS_CLK_CTRL 0x008 +#define GS201_PCS_CLK_MUX_GLITCH_WA BIT(7) +#define GS201_PCS_ERIO_CLK_GATE_MASK GENMASK(5, 4) +#define GS201_PCS_L2_PWR 0x150 +#define GS201_PCS_RC_MODE 0x154 +#define GS201_PCS_L2_PWRDN_DELAY 0x170 +#define GS201_PCS_RATE_CTRL 0x184 +#define GS201_PCS_RATE_CTRL_SWITCH 0xb0 +#define GS201_PCS_PM_STATE 0x188 +#define GS201_PCS_PLL_BIAS_OFF_DELAY 0x190 +#define GS201_PCS_LANE_STRIDE 0x800 + +#define GS201_PMA_LANE_STRIDE 0x800 +#define GS201_PHY_MAX_LANES 2 + +/* Google polls the lock bits 10000 times, 1 us apart */ +#define GS201_PHY_LOCK_TIMEOUT_US 10000 + +struct gs201_pcie_phy_reg { + u16 off; + u8 val; +}; + +/* Common PMA block, 100 MHz LCPLL, RC mode, then the 38.4 MHz input clock */ +static const struct gs201_pcie_phy_reg gs201_pma_common[] = { + { 0x018, 0x50 }, { 0x048, 0x33 }, { 0x068, 0x01 }, { 0x070, 0x12 }, + { 0x08c, 0x00 }, { 0x090, 0x21 }, { 0x0b0, 0x14 }, { 0x0b8, 0x50 }, + { 0x0e0, 0x51 }, { 0x100, 0x00 }, { 0x104, 0x80 }, { 0x140, 0x38 }, + { 0x180, 0xa4 }, + { 0x188, 0x03 }, /* LCPLL 100 MHz, no divider */ + { 0x2a8, 0x38 }, { 0x2e4, 0x12 }, + /* PMA enable, aggregation (non-bifurcated) mode */ + { 0x400, 0x80 }, { 0x408, 0x20 }, { 0x550, 0x00 }, { 0x5a8, 0x00 }, + { 0x5ec, 0xff }, + /* PCIe type: RC */ + { 0x458, 0x02 }, /* 100 MHz clock on */ + { 0x5b0, 0x34 }, /* differential REFCLK source control */ + { 0x450, 0x20 }, /* extra delay when entering L1.2 */ + /* 38.4 MHz PHY input clock */ + { 0x0ac, 0x34 }, { 0x0b4, 0x34 }, { 0x0e0, 0x50 }, { 0x0f4, 0x00 }, + { 0x0f8, 0x08 }, { 0x104, 0xa0 }, { 0x11c, 0x19 }, { 0x124, 0x17 }, + { 0x220, 0x41 }, +}; + +/* Per-lane PMA block (offsets for lane 0; lane n adds n * 0x800) */ +static const struct gs201_pcie_phy_reg gs201_pma_lane[] = { + { 0x82c, 0x08 }, { 0x830, 0x24 }, { 0x878, 0x80 }, { 0x894, 0x40 }, + { 0x8c0, 0x00 }, { 0x8f4, 0x30 }, { 0x908, 0x05 }, { 0x90c, 0xe0 }, + { 0x914, 0xd4 }, { 0x91c, 0xd3 }, { 0x920, 0xce }, { 0x924, 0x01 }, + { 0x928, 0x35 }, { 0x92c, 0xba }, { 0x930, 0x41 }, { 0x934, 0x15 }, + { 0x938, 0x13 }, { 0x93c, 0x4e }, { 0x948, 0x43 }, { 0x94c, 0xfc }, + { 0x954, 0x10 }, { 0x958, 0x69 }, { 0x964, 0x40 }, { 0x9b4, 0xf6 }, + { 0x9c0, 0x2d }, { 0x9c4, 0xb7 }, { 0x9cc, 0x3c }, { 0x9dc, 0x7e }, + { 0xa40, 0x02 }, { 0xa70, 0x26 }, { 0xa74, 0x00 }, + { 0xb40, 0x06 }, { 0xb44, 0x06 }, { 0xb48, 0x04 }, { 0xb4c, 0x03 }, + { 0xb50, 0x03 }, { 0xb54, 0x03 }, { 0xb58, 0x03 }, { 0xb5c, 0x03 }, + { 0xc10, 0x1b }, { 0xc44, 0x10 }, { 0xc48, 0x10 }, { 0xc4c, 0x10 }, + { 0xc50, 0x10 }, { 0xc54, 0x02 }, { 0xc58, 0x02 }, { 0xc5c, 0x02 }, + { 0xc60, 0x02 }, { 0xc6c, 0x02 }, { 0xc70, 0x02 }, { 0xca8, 0xe7 }, + { 0xcac, 0x00 }, { 0xcb0, 0x0e }, { 0xccc, 0x1c }, { 0xcd4, 0x05 }, + { 0xcd8, 0x77 }, { 0xcdc, 0x7a }, { 0xdb4, 0x2f }, + /* RX tuning */ + { 0x8fc, 0x80 }, { 0x914, 0xf4 }, { 0x91c, 0xd3 }, { 0x920, 0xca }, + { 0x928, 0x3d }, { 0x92c, 0xb8 }, { 0x930, 0x41 }, { 0x934, 0x17 }, + { 0x93c, 0x4c }, { 0x948, 0x73 }, { 0x94c, 0xfc }, { 0x96c, 0x55 }, + { 0x988, 0x78 }, { 0x994, 0x3b }, { 0x9b4, 0xf6 }, { 0x9c4, 0xff }, + { 0x9c8, 0x20 }, { 0xa08, 0x2f }, { 0xb9c, 0x3f }, + /* TX termination resistor */ + { 0x9cc, 0x00 }, { 0xcd8, 0xff }, { 0xcdc, 0x6e }, + { 0x82c, 0x0f }, { 0x830, 0x60 }, { 0x834, 0x7e }, + /* Auto FBB */ + { 0xc08, 0x00 }, { 0xc10, 0x09 }, { 0xc40, 0x04 }, { 0xc70, 0x00 }, + /* DFE */ + { 0x9b4, 0x76 }, +}; + +/* 38.4 MHz input clock, per lane, written for both lanes of the PHY */ +static const struct gs201_pcie_phy_reg gs201_pma_lane_clk[] = { + { 0xbcc, 0x41 }, { 0xbd4, 0x41 }, { 0xbdc, 0x68 }, { 0xbe0, 0x00 }, + { 0xbe4, 0xd0 }, +}; + +/* PHY power-down, per lane (offsets for lane 0) */ +static const struct gs201_pcie_phy_reg gs201_pma_lane_pwrdn[] = { + { 0x800, 0x0a }, { 0x804, 0xbf }, { 0xa40, 0x02 }, { 0xa44, 0x2a }, + { 0xa48, 0xaa }, { 0xa4c, 0xa8 }, { 0xa50, 0x80 }, +}; + +/* + * PMA values right after the PHY reset. Google's driver compares them before + * every configuration ("check if PCIe PHY is being reset correctly"). + */ +static const struct gs201_pcie_phy_reg gs201_pma_reset_vals[] = { + { 0x010, 0x55 }, { 0x014, 0x51 }, { 0x040, 0x50 }, { 0x044, 0x0c }, + { 0x0d8, 0x28 }, { 0x1054, 0x77 }, +}; + +struct gs201_pcie_phy { + struct device *dev; + void __iomem *pma; + void __iomem *pcs; + void __iomem *rst; + void __iomem *udbg; + struct regmap *pmu; + u32 pmu_offset; + struct clk_bulk_data *clks; + int num_clks; +}; + +static __printf(2, 3) void gs201_phy_trace(struct gs201_pcie_phy *gp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(gp->dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static void gs201_pcie_phy_write_table(void __iomem *base, + const struct gs201_pcie_phy_reg *tbl, + size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + writel(tbl[i].val, base + tbl[i].off); +} + +static void gs201_pcie_phy_rmw(void __iomem *reg, u32 clr, u32 set) +{ + writel((readl(reg) & ~clr) | set, reg); +} + +static unsigned int gs201_pcie_phy_lanes(struct phy *phy) +{ + unsigned int lanes = phy_get_bus_width(phy); + + return clamp(lanes, 1U, (unsigned int)GS201_PHY_MAX_LANES); +} + +/* Power down both lanes and the PMA; the inverse of _pwrdn_clear() */ +static void gs201_pcie_phy_pwrdn(struct gs201_pcie_phy *gp) +{ + unsigned int lane; + + gs201_phy_trace(gp, "about to write PMA 0x404-0x40c and the lane power-down registers"); + writel(0xa8, gp->pma + GS201_PMA_CMN_PWRDN0); + writel(0x20, gp->pma + GS201_PMA_CMN_PWRDN1); + writel(0x0a, gp->pma + GS201_PMA_CMN_PWRDN2); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane_pwrdn, + ARRAY_SIZE(gs201_pma_lane_pwrdn)); + + gs201_phy_trace(gp, "about to read PMA 0x400 (first PMA read): disable the PMA"); + gs201_pcie_phy_rmw(gp->pma + GS201_PMA_CMN_CTRL, + GS201_PMA_CMN_CTRL_PMA_EN, 0); + + gs201_phy_trace(gp, "about to read PCS 0x184 (first PCS read): rate switching off"); + gs201_pcie_phy_rmw(gp->pcs + GS201_PCS_RATE_CTRL, + GS201_PCS_RATE_CTRL_SWITCH, 0); +} + +static void gs201_pcie_phy_pwrdn_clear(struct gs201_pcie_phy *gp) +{ + unsigned int lane; + size_t i; + + gs201_phy_trace(gp, "about to write PMA 0xd8 (input clock), then clear the power-downs"); + writel(GS201_PMA_INPUT_CLK_VAL, gp->pma + GS201_PMA_INPUT_CLK); + mdelay(1); + + writel(0, gp->pma + GS201_PMA_CMN_PWRDN0); + writel(0, gp->pma + GS201_PMA_CMN_PWRDN1); + writel(0, gp->pma + GS201_PMA_CMN_PWRDN2); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + for (i = 0; i < ARRAY_SIZE(gs201_pma_lane_pwrdn); i++) + writel(0, gp->pma + lane * GS201_PMA_LANE_STRIDE + + gs201_pma_lane_pwrdn[i].off); + + gs201_phy_trace(gp, "about to write PCS 0x184 (rate change and power-down reset)"); + writel(0, gp->pcs + GS201_PCS_RATE_CTRL); +} + +/* Google's debug check that the PMA came out of reset with its defaults */ +static void gs201_pcie_phy_check_reset(struct gs201_pcie_phy *gp) +{ + size_t i; + u32 val; + + gs201_phy_trace(gp, "about to read PMA reset defaults (0x10 0x14 0x40 0x44 0xd8 0x1054)"); + for (i = 0; i < ARRAY_SIZE(gs201_pma_reset_vals); i++) { + val = readl(gp->pma + gs201_pma_reset_vals[i].off); + if (val != gs201_pma_reset_vals[i].val) + dev_info(gp->dev, "PMA %#x after reset: %#x (expected %#x)\n", + gs201_pma_reset_vals[i].off, val, + gs201_pma_reset_vals[i].val); + } +} + +static void gs201_pcie_phy_config(struct gs201_pcie_phy *gp, unsigned int lanes) +{ + unsigned int lane; + + gs201_phy_trace(gp, "about to read PMA 0x5fc (OC status)"); + dev_dbg(gp->dev, "OC initial status %#x\n", + readl(gp->pma + GS201_PMA_OC_STATUS)); + + gs201_pcie_phy_check_reset(gp); + + /* Input clock path */ + writel(GS201_PMA_INPUT_CLK_VAL, gp->pma + GS201_PMA_INPUT_CLK); + + gs201_phy_trace(gp, "about to read-modify-write PCS 0x008 (clock mux glitch workaround)"); + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_rmw(gp->pcs + lane * GS201_PCS_LANE_STRIDE + + GS201_PCS_CLK_CTRL, 0, + GS201_PCS_CLK_MUX_GLITCH_WA); + + gs201_phy_trace(gp, "about to pulse the PHY resets (ELBI 0x1400-0x1408), release INIT_RST"); + writel(1, gp->rst + GS201_PHY_RST_INIT); + writel(1, gp->rst + GS201_PHY_RST_PORT); + writel(1, gp->rst + GS201_PHY_RST_CMN); + writel(0, gp->rst + GS201_PHY_RST_INIT); + writel(0, gp->rst + GS201_PHY_RST_PORT); + writel(0, gp->rst + GS201_PHY_RST_CMN); + udelay(10); + writel(1, gp->rst + GS201_PHY_RST_INIT); + udelay(10); + + gs201_phy_trace(gp, "about to write the PMA tables (common, %u lane(s), lane clocks)", + lanes); + gs201_pcie_phy_write_table(gp->pma, gs201_pma_common, + ARRAY_SIZE(gs201_pma_common)); + + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane, + ARRAY_SIZE(gs201_pma_lane)); + + for (lane = 0; lane < GS201_PHY_MAX_LANES; lane++) + gs201_pcie_phy_write_table(gp->pma + lane * GS201_PMA_LANE_STRIDE, + gs201_pma_lane_clk, + ARRAY_SIZE(gs201_pma_lane_clk)); + + gs201_phy_trace(gp, "about to write PCS 0x004 0x154 0x150 0x170 0x008 0x190"); + for (lane = 0; lane < lanes; lane++) { + void __iomem *pcs = gp->pcs + lane * GS201_PCS_LANE_STRIDE; + + writel(0x00000, pcs + GS201_PCS_BIFURCATION); + writel(0x700d5, pcs + GS201_PCS_RC_MODE); + writel(0x300ff, pcs + GS201_PCS_L2_PWR); + writel(0x40, pcs + GS201_PCS_L2_PWRDN_DELAY); + } + + /* ERIO clock gating in L1.2 */ + for (lane = 0; lane < lanes; lane++) + gs201_pcie_phy_rmw(gp->pcs + lane * GS201_PCS_LANE_STRIDE + + GS201_PCS_CLK_CTRL, + GS201_PCS_ERIO_CLK_GATE_MASK, + GS201_PCS_ERIO_CLK_GATE_MASK); + + /* PLL and bias enable off delay */ + writel(0x100b0808, gp->pcs + GS201_PCS_PLL_BIAS_OFF_DELAY); + + gs201_phy_trace(gp, "about to release CMN_RST and PORT_RST"); + writel(1, gp->rst + GS201_PHY_RST_CMN); + writel(1, gp->rst + GS201_PHY_RST_PORT); + + gs201_phy_trace(gp, "about to read-modify-write PMA 0x5d0 (external XO)"); + gs201_pcie_phy_rmw(gp->pma + GS201_PMA_XO_CFG, GS201_PMA_XO_CFG_INT, + GS201_PMA_XO_CFG_EXT); + + /* + * Restart AFC calibration from its simulated initial value instead of + * the previous result; Google found the stale value can flag AFC done + * too early and break CDR lock. + */ + writel(GS201_PMA_AFC_CAL_RESTART, gp->pma + GS201_PMA_AFC_CAL_MODE); +} + +static bool gs201_pcie_phy_wait(struct gs201_pcie_phy *gp, const char *what, + u32 off, u32 mask, u32 want) +{ + u32 val; + int ret; + + gs201_phy_trace(gp, "about to poll PMA %#x for %s (up to %u us)", off, + what, GS201_PHY_LOCK_TIMEOUT_US); + ret = readl_poll_timeout_atomic(gp->pma + off, val, (val & mask) == want, + 1, GS201_PHY_LOCK_TIMEOUT_US); + + return !ret; +} + +static void gs201_pcie_phy_check_lock(struct gs201_pcie_phy *gp) +{ + bool pll, cdr, oc; + + pll = gs201_pcie_phy_wait(gp, "PLL lock", GS201_PMA_CMN_STATUS, + GS201_PMA_CMN_STATUS_PLL_LOCK, + GS201_PMA_CMN_STATUS_PLL_LOCK); + cdr = gs201_pcie_phy_wait(gp, "CDR lock", GS201_PMA_CDR_STATUS, + GS201_PMA_CDR_LOCK, GS201_PMA_CDR_LOCK); + oc = gs201_pcie_phy_wait(gp, "offset calibration", GS201_PMA_OC_DONE, + GS201_PMA_OC_DONE_MASK, GS201_PMA_OC_DONE_MASK); + + /* CDR lock needs a link partner; without one only the PLL matters */ + dev_info(gp->dev, + "PLL lock %d, CDR lock %d, OC done %d (PMA 0x3f0 %#x 0xfc0 %#x, PCS 0x188 %#x)\n", + pll, cdr, oc, readl(gp->pma + GS201_PMA_CMN_STATUS), + readl(gp->pma + GS201_PMA_LN0_STATUS), + readl(gp->pcs + GS201_PCS_PM_STATE)); +} + +static int gs201_pcie_phy_clks_on(struct gs201_pcie_phy *gp) +{ + int i, ret; + + for (i = 0; i < gp->num_clks; i++) { + gs201_phy_trace(gp, "enable clk %pC", + gp->clks[i].clk); + ret = clk_prepare_enable(gp->clks[i].clk); + if (ret) { + while (--i >= 0) + clk_disable_unprepare(gp->clks[i].clk); + return ret; + } + } + + return 0; +} + +static void gs201_pcie_phy_check_tcxo(struct gs201_pcie_phy *gp) +{ + unsigned int val; + int ret; + + gs201_phy_trace(gp, "about to read PMU %#x (TCXO_BUF_CTRL)", + GS201_PMU_TCXO_BUF_CTRL); + ret = regmap_read(gp->pmu, GS201_PMU_TCXO_BUF_CTRL, &val); + if (ret) { + dev_warn(gp->dev, "cannot read TCXO_BUF_CTRL: %d\n", ret); + return; + } + + dev_info(gp->dev, "PMU TCXO_BUF_CTRL %#x\n", val); + if ((val & GS201_PMU_TCXO_PCIE_MASK) == GS201_PMU_TCXO_PCIE_MASK) + return; + + gs201_phy_trace(gp, "about to set PMU %#x bits %#lx (SMC)", + GS201_PMU_TCXO_BUF_CTRL, GS201_PMU_TCXO_PCIE_MASK); + ret = regmap_update_bits(gp->pmu, GS201_PMU_TCXO_BUF_CTRL, + GS201_PMU_TCXO_PCIE_MASK, + GS201_PMU_TCXO_PCIE_MASK); + if (ret) + dev_warn(gp->dev, "cannot set TCXO_BUF_CTRL: %d\n", ret); +} + +/* + * Init = Google's probe-time "resumed_phydown": take the PHY out of + * isolation and leave it powered down. This is the first access to the PMA + * and PCS. + */ +static int gs201_pcie_phy_init(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + int ret; + + ret = gs201_pcie_phy_clks_on(gp); + if (ret) + return ret; + + if (check_tcxo) + gs201_pcie_phy_check_tcxo(gp); + + gs201_phy_trace(gp, "about to set PMU %#x bit 0 (PHY isolation off, SMC)", + gp->pmu_offset); + ret = regmap_update_bits(gp->pmu, gp->pmu_offset, + GS201_PMU_PHY_BYPASS, GS201_PMU_PHY_BYPASS); + if (ret) { + dev_err(gp->dev, "PMU write failed: %d\n", ret); + clk_bulk_disable_unprepare(gp->num_clks, gp->clks); + return ret; + } + + gs201_pcie_phy_pwrdn(gp); + gs201_phy_trace(gp, "PHY out of isolation and powered down"); + + return 0; +} + +/* + * Google never isolates this PHY again after probe (use-phy-isol-con is not + * set for ch1), and DBI accesses hang while it is isolated. So exit leaves + * isolation off and only drops the clock references. + */ +static int gs201_pcie_phy_exit(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_phy_trace(gp, "exit: release clocks (isolation stays off, as stock)"); + clk_bulk_disable_unprepare(gp->num_clks, gp->clks); + + return 0; +} + +static int gs201_pcie_phy_power_on(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_pcie_phy_pwrdn_clear(gp); + gs201_pcie_phy_config(gp, gs201_pcie_phy_lanes(phy)); + gs201_pcie_phy_check_lock(gp); + gs201_phy_trace(gp, "PHY configured"); + + return 0; +} + +static int gs201_pcie_phy_power_off(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + + gs201_pcie_phy_pwrdn(gp); + + return 0; +} + +/* + * Called by the controller after its soft power reset: Google logs the PMA + * offset calibration state at that point. Exposed as a PHY "calibrate" op so + * the controller can trigger it at the right time. + */ +static int gs201_pcie_phy_calibrate(struct phy *phy) +{ + struct gs201_pcie_phy *gp = phy_get_drvdata(phy); + u32 val; + + gs201_phy_trace(gp, "about to read PMA 0xe18 (OC after soft power reset)"); + val = readl(gp->pma + GS201_PMA_OC_STATUS2); + if (!(val & GS201_PMA_OC_STATUS2_DONE)) + dev_info(gp->dev, + "OC not done after soft power reset: PMA 0x760 %#x 0xe0c %#x 0x3f0 %#x 0xfc0 %#x\n", + readl(gp->pma + 0x760), + readl(gp->pma + GS201_PMA_CDR_STATUS), + readl(gp->pma + GS201_PMA_CMN_STATUS), + readl(gp->pma + GS201_PMA_LN0_STATUS)); + + return 0; +} + +static const struct phy_ops gs201_pcie_phy_ops = { + .init = gs201_pcie_phy_init, + .exit = gs201_pcie_phy_exit, + .power_on = gs201_pcie_phy_power_on, + .power_off = gs201_pcie_phy_power_off, + .calibrate = gs201_pcie_phy_calibrate, + .owner = THIS_MODULE, +}; + +static int gs201_pcie_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *provider; + struct gs201_pcie_phy *gp; + struct phy *phy; + int ret; + + gp = devm_kzalloc(dev, sizeof(*gp), GFP_KERNEL); + if (!gp) + return -ENOMEM; + + gp->dev = dev; + + /* Only mappings here: the PHY is not touched until phy_init() */ + gp->pma = devm_platform_ioremap_resource_byname(pdev, "pma"); + if (IS_ERR(gp->pma)) + return PTR_ERR(gp->pma); + + gp->pcs = devm_platform_ioremap_resource_byname(pdev, "pcs"); + if (IS_ERR(gp->pcs)) + return PTR_ERR(gp->pcs); + + gp->rst = devm_platform_ioremap_resource_byname(pdev, "rst"); + if (IS_ERR(gp->rst)) + return PTR_ERR(gp->rst); + + gp->udbg = devm_platform_ioremap_resource_byname(pdev, "udbg"); + if (IS_ERR(gp->udbg)) + return PTR_ERR(gp->udbg); + + gp->pmu = exynos_get_pmu_regmap_by_phandle(dev->of_node, + "samsung,pmu-syscon"); + if (IS_ERR(gp->pmu)) + return dev_err_probe(dev, PTR_ERR(gp->pmu), + "failed to get the PMU regmap\n"); + + ret = of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1, + &gp->pmu_offset); + if (ret) + return dev_err_probe(dev, ret, + "missing PMU PHY control offset\n"); + + gp->num_clks = devm_clk_bulk_get_all(dev, &gp->clks); + if (gp->num_clks < 0) + return dev_err_probe(dev, gp->num_clks, "failed to get clocks\n"); + + phy = devm_phy_create(dev, NULL, &gs201_pcie_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY\n"); + + phy_set_drvdata(phy, gp); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id gs201_pcie_phy_of_match[] = { + { .compatible = "google,gs201-pcie-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, gs201_pcie_phy_of_match); + +static struct platform_driver gs201_pcie_phy_driver = { + .probe = gs201_pcie_phy_probe, + .driver = { + .name = "gs201-pcie-phy", + .of_match_table = gs201_pcie_phy_of_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(gs201_pcie_phy_driver); + +MODULE_DESCRIPTION("Google gs201 PCIe PHY driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/phy/samsung/phy-zuma-pcie.c b/drivers/phy/samsung/phy-zuma-pcie.c new file mode 100644 index 0000000000..a00239085e --- /dev/null +++ b/drivers/phy/samsung/phy-zuma-pcie.c @@ -0,0 +1,433 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google zuma (Tensor G3) PCIe Gen3 PHY driver + * + * The one-lane PHY of zuma's second PCIe controller (the Wi-Fi chip's). Its + * reference clock comes from an external PLL in the UDBG block, selected in + * the controller's SOC block. The register sequence is Samsung's "CAL ver + * 0.2" for zuma, channel 1, taken from the driver Google builds for zuma + * (pcie-exynos-zuma-rc-cal.c and pcie-exynos-rc.c in google-modules/soc/gs/ + * drivers/pci/controller/dwc). Most PMA registers have no public names, so + * the tables keep Samsung's raw offsets and values. + * + * Copyright (C) 2021 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Bring-up tracing, as in the gs201 PHY driver: with trace=1 every step + * that touches the hardware is logged before it happens, and the driver + * sleeps trace_delay_ms after each line so that a reader of /dev/kmsg + * receives it before a possible bus hang stops the CPU. + */ +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +/* PMU PHY control: bit 0 clear isolates the PHY */ +#define ZUMA_PMU_PHY_BYPASS BIT(0) + +/* PHY reset block, in the controller's sub-control (ELBI) space at +0x1400 */ +#define ZUMA_PHY_RST_CMN 0x0 +#define ZUMA_PHY_RST_INIT 0x4 +#define ZUMA_PHY_RST_PORT 0x8 + +/* SOC block: the PHY's input clock */ +#define ZUMA_SOC_CLK_MODE 0x4000 +#define ZUMA_SOC_CLK_MODE_VAL 0x15 +#define ZUMA_SOC_CLK_SEL 0x4004 +#define ZUMA_SOC_CLK_SEL_TCXO BIT(2) +#define ZUMA_SOC_CLK_SEL_EXT_PLL GENMASK(5, 4) + +/* UDBG block: the external PLL */ +#define ZUMA_UDBG_EXT_PLL 0xc700 +#define ZUMA_UDBG_EXT_PLL_EN BIT(0) +#define ZUMA_UDBG_EXT_PLL_RESETB_OVR BIT(1) +#define ZUMA_UDBG_EXT_PLL_STATUS 0xc734 +#define ZUMA_UDBG_EXT_PLL_LOCK BIT(2) +#define ZUMA_UDBG_LINK_CTRL 0xc800 +#define ZUMA_UDBG_LINK_CTRL_VAL 0x421 + +/* PMA registers used outside the tables */ +#define ZUMA_PMA_CMN_BIAS 0x000c +#define ZUMA_PMA_CLK_CTRL 0x0204 +#define ZUMA_PMA_CLK_CTRL_GATE GENMASK(3, 2) +#define ZUMA_PMA_INPUT_CLK_GATE 0x032c +#define ZUMA_PMA_INPUT_CLK_UNGATE 0x3 +#define ZUMA_PMA_LN_CTRL 0x1350 +#define ZUMA_PMA_PLL_STATUS 0x0a80 +#define ZUMA_PMA_PLL_LOCK BIT(0) +#define ZUMA_PMA_OC_STATUS 0x140c +#define ZUMA_PMA_OC_DONE BIT(7) +#define ZUMA_PMA_CDR_STATUS 0x15c0 +#define ZUMA_PMA_CDR_LOCK BIT(4) + +/* Google polls the lock bits 10000 times, 10 us apart */ +#define ZUMA_PHY_LOCK_TIMEOUT_US 100000 + +struct zuma_pcie_phy_reg { + u16 off; + u32 val; +}; + +/* PHY power-down (exynos_pcie_rc_phy_all_pwrdn(), channel 1), after 0x204 */ +static const struct zuma_pcie_phy_reg zuma_pma_pwrdn[] = { + { 0x1044, 0x2a }, { 0x1048, 0xaa }, { 0x104c, 0xa8 }, { 0x1050, 0x80 }, + { 0x185c, 0x0a }, +}; + +/* Common PMA block */ +static const struct zuma_pcie_phy_reg zuma_pma_common[] = { + { 0x0000, 0x88 }, { 0x001c, 0x66 }, { 0x01f4, 0x00 }, { 0x0514, 0x59 }, + { 0x051c, 0x11 }, { 0x062c, 0x0e }, { 0x0644, 0x22 }, { 0x0688, 0x03 }, + { 0x06d4, 0x28 }, { 0x0788, 0x64 }, { 0x078c, 0x64 }, { 0x0790, 0x50 }, + { 0x0794, 0x50 }, { 0x0944, 0x05 }, { 0x0948, 0x05 }, { 0x094c, 0x05 }, + { 0x0950, 0x05 }, + /* 38.4 MHz REFCLK to the external PLL path */ + { 0x0590, 0x02 }, { 0x07f8, 0xb0 }, { 0x0730, 0x08 }, + /* 7.68 us delay in L1.2 */ + { 0x0344, 0xc0 }, + /* L1.2 without CLKREQ# */ + { 0x0040, 0x04 }, { 0x0204, 0x03 }, { 0x02d4, 0x1f }, { 0x0358, 0x10 }, + /* ERIO on */ + { 0x0018, 0x01 }, + /* Lane */ + { 0x0514, 0x5b }, { 0x0608, 0x0c }, { 0x060c, 0x0f }, { 0x0610, 0x0f }, + { 0x0614, 0x0f }, { 0x0618, 0x0f }, { 0x0510, 0x80 }, { 0x0688, 0x03 }, + { 0x0644, 0x23 }, { 0x0624, 0x11 }, + /* PLL margin for ERIO at Gen1 and Gen2 */ + { 0x0630, 0x0f }, { 0x06d0, 0x53 }, +}; + +/* The lane's PMA block */ +static const struct zuma_pcie_phy_reg zuma_pma_lane[] = { + { 0x1140, 0x04 }, { 0x1144, 0x04 }, { 0x1148, 0x04 }, { 0x114c, 0x02 }, + { 0x1150, 0x00 }, { 0x1154, 0x00 }, { 0x1158, 0x00 }, { 0x115c, 0x00 }, + { 0x12cc, 0x1c }, { 0x12dc, 0x6c }, { 0x130c, 0x29 }, { 0x13b4, 0x2f }, + { 0x1a64, 0x05 }, { 0x1a68, 0x05 }, { 0x1a84, 0x05 }, { 0x1a88, 0x05 }, + { 0x1a98, 0x00 }, { 0x1a9c, 0x00 }, { 0x1aa8, 0x07 }, { 0x1ab8, 0x00 }, + { 0x1abc, 0x00 }, { 0x1af8, 0x90 }, { 0x1b34, 0x03 }, { 0x1bb0, 0x03 }, + { 0x1bb4, 0x03 }, { 0x1bc0, 0x06 }, { 0x1bc4, 0x06 }, { 0x1be8, 0x01 }, + { 0x1bf8, 0x04 }, { 0x1c98, 0x00 }, { 0x1ca4, 0x81 }, + /* + * Broadcom Wi-Fi (stock's ep-device-type 1): the link went down on + * L1 substate exits without these. + */ + { 0x1b20, 0x02 }, { 0x1340, 0x23 }, { 0x002c, 0x3c }, +}; + +/* PCS, with Google's Broadcom Wi-Fi timer values */ +static const struct zuma_pcie_phy_reg zuma_pcs[] = { + { 0x190, 0x100b0604 }, + /* L1.2 without CLKREQ# */ + { 0x154, 0x000700d5 }, + { 0x100, 0x16400000 }, { 0x104, 0x08600000 }, { 0x114, 0x18500000 }, + { 0x124, 0x60700000 }, { 0x174, 0x00000007 }, { 0x178, 0x00000100 }, + { 0x17c, 0x00000700 }, { 0x110, 0x01600202 }, +}; + +struct zuma_pcie_phy { + struct device *dev; + void __iomem *pma; + void __iomem *pcs; + void __iomem *rst; + void __iomem *udbg; + void __iomem *soc; + struct regmap *pmu; + u32 pmu_offset; +}; + +static __printf(2, 3) void zuma_phy_trace(struct zuma_pcie_phy *zp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(zp->dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static void zuma_pcie_phy_write_table(void __iomem *base, + const struct zuma_pcie_phy_reg *tbl, + size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + writel(tbl[i].val, base + tbl[i].off); +} + +static void zuma_pcie_phy_rmw(void __iomem *reg, u32 clr, u32 set) +{ + writel((readl(reg) & ~clr) | set, reg); +} + +static bool zuma_pcie_phy_wait(struct zuma_pcie_phy *zp, const char *what, + void __iomem *base, u32 off, u32 bit) +{ + u32 val; + + zuma_phy_trace(zp, "about to poll %#x for %s (up to %u us)", off, what, + ZUMA_PHY_LOCK_TIMEOUT_US); + + return !readl_poll_timeout_atomic(base + off, val, val & bit, 10, + ZUMA_PHY_LOCK_TIMEOUT_US); +} + +/* exynos_pcie_rc_phy_all_pwrdn(), channel 1 */ +static void zuma_pcie_phy_pwrdn(struct zuma_pcie_phy *zp) +{ + zuma_phy_trace(zp, "about to read PMA 0x204 (first PMA access) and power the PHY down"); + zuma_pcie_phy_rmw(zp->pma + ZUMA_PMA_CLK_CTRL, ZUMA_PMA_CLK_CTRL_GATE, 0); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_pwrdn, + ARRAY_SIZE(zuma_pma_pwrdn)); + udelay(1); + writel(0xff, zp->pma + 0x0208); + udelay(1); + writel(0x0a, zp->pma + 0x0580); + writel(0xaa, zp->pma + 0x0928); + /* Common bias and PLL off */ + writel(0x0a, zp->pma + ZUMA_PMA_CMN_BIAS); + fsleep(50); + + zuma_phy_trace(zp, "about to read UDBG 0xc700 (first UDBG access): gate the external PLL"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, ZUMA_UDBG_EXT_PLL_EN, 0); + fsleep(10); +} + +/* exynos_pcie_rc_phy_all_pwrdn_clear(), channel 1 */ +static void zuma_pcie_phy_pwrdn_clear(struct zuma_pcie_phy *zp) +{ + size_t i; + + zuma_phy_trace(zp, "about to ungate the external PLL (UDBG 0xc700) and clear the power-downs"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, ZUMA_UDBG_EXT_PLL_EN); + fsleep(100); + writel(0x00, zp->pma + ZUMA_PMA_CMN_BIAS); + writel(0x55, zp->pma + 0x0928); + writel(0x02, zp->pma + 0x0580); + writel(0x00, zp->pma + 0x0208); + for (i = 0; i < ARRAY_SIZE(zuma_pma_pwrdn); i++) + writel(0, zp->pma + zuma_pma_pwrdn[i].off); + fsleep(10); +} + +/* exynos_pcie_rc_pcie_phy_config(), channel 1, less its ELBI writes */ +static void zuma_pcie_phy_config(struct zuma_pcie_phy *zp) +{ + bool pll, cdr, oc, ext; + + zuma_phy_trace(zp, "about to ungate the PHY input clock (PMA 0x32c) and start the external PLL"); + writel(ZUMA_PMA_INPUT_CLK_UNGATE, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, ZUMA_UDBG_EXT_PLL_EN); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, + ZUMA_UDBG_EXT_PLL_RESETB_OVR, 0); + + ext = zuma_pcie_phy_wait(zp, "the external PLL lock", zp->udbg, + ZUMA_UDBG_EXT_PLL_STATUS, + ZUMA_UDBG_EXT_PLL_LOCK); + + zuma_phy_trace(zp, "about to select the external PLL as the PHY input clock (SOC 0x4004)"); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_SEL, ZUMA_SOC_CLK_SEL_TCXO, 0); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_SEL, 0, + ZUMA_SOC_CLK_SEL_EXT_PLL); + + zuma_phy_trace(zp, "about to assert the PMA resets (ELBI 0x1400-0x1408)"); + writel(1, zp->rst + ZUMA_PHY_RST_INIT); + writel(1, zp->rst + ZUMA_PHY_RST_PORT); + writel(1, zp->rst + ZUMA_PHY_RST_CMN); + writel(0, zp->rst + ZUMA_PHY_RST_INIT); + writel(0, zp->rst + ZUMA_PHY_RST_PORT); + writel(0, zp->rst + ZUMA_PHY_RST_CMN); + + zuma_phy_trace(zp, "about to write the PMA tables (common, lane)"); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_common, + ARRAY_SIZE(zuma_pma_common)); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_lane, + ARRAY_SIZE(zuma_pma_lane)); + zuma_pcie_phy_rmw(zp->pma + ZUMA_PMA_LN_CTRL, 0, BIT(0)); + + zuma_phy_trace(zp, "about to write the PCS table"); + zuma_pcie_phy_write_table(zp->pcs, zuma_pcs, ARRAY_SIZE(zuma_pcs)); + + zuma_phy_trace(zp, "about to release the PMA resets"); + writel(1, zp->rst + ZUMA_PHY_RST_INIT); + fsleep(10); + writel(1, zp->rst + ZUMA_PHY_RST_PORT); + writel(1, zp->rst + ZUMA_PHY_RST_CMN); + + pll = zuma_pcie_phy_wait(zp, "PLL lock", zp->pma, ZUMA_PMA_PLL_STATUS, + ZUMA_PMA_PLL_LOCK); + cdr = zuma_pcie_phy_wait(zp, "CDR lock", zp->pma, ZUMA_PMA_CDR_STATUS, + ZUMA_PMA_CDR_LOCK); + oc = zuma_pcie_phy_wait(zp, "offset calibration", zp->pma, + ZUMA_PMA_OC_STATUS, ZUMA_PMA_OC_DONE); + + dev_info(zp->dev, + "external PLL lock %d, PLL lock %d, CDR lock %d, OC done %d\n", + ext, pll, cdr, oc); + + writel(0, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); +} + +static int zuma_pcie_phy_init(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + unsigned int val; + int ret; + + ret = regmap_read(zp->pmu, zp->pmu_offset, &val); + if (ret) { + dev_err(zp->dev, "PMU read failed: %d\n", ret); + return ret; + } + dev_info(zp->dev, "PMU PHY control %#x\n", val); + + zuma_phy_trace(zp, "about to set PMU %#x bit 0 (PHY isolation off, SMC)", + zp->pmu_offset); + ret = regmap_update_bits(zp->pmu, zp->pmu_offset, ZUMA_PMU_PHY_BYPASS, + ZUMA_PMU_PHY_BYPASS); + if (ret) { + dev_err(zp->dev, "PMU write failed: %d\n", ret); + return ret; + } + + zuma_pcie_phy_pwrdn(zp); + zuma_phy_trace(zp, "PHY out of isolation and powered down"); + + return 0; +} + +static int zuma_pcie_phy_power_on(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_phy_trace(zp, "about to write SOC 0x4000 (first SOC access)"); + writel(ZUMA_SOC_CLK_MODE_VAL, zp->soc + ZUMA_SOC_CLK_MODE); + + zuma_pcie_phy_pwrdn_clear(zp); + zuma_pcie_phy_config(zp); + + /* exynos_pcie_rc_establish_link(), channel 1, before PERST# */ + zuma_phy_trace(zp, "about to write UDBG 0xc800"); + writel(ZUMA_UDBG_LINK_CTRL_VAL, zp->udbg + ZUMA_UDBG_LINK_CTRL); + zuma_phy_trace(zp, "PHY configured"); + + return 0; +} + +static int zuma_pcie_phy_power_off(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_pcie_phy_pwrdn(zp); + + return 0; +} + +static const struct phy_ops zuma_pcie_phy_ops = { + .init = zuma_pcie_phy_init, + .power_on = zuma_pcie_phy_power_on, + .power_off = zuma_pcie_phy_power_off, + .owner = THIS_MODULE, +}; + +static int zuma_pcie_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct phy_provider *provider; + struct zuma_pcie_phy *zp; + struct phy *phy; + int ret; + + zp = devm_kzalloc(dev, sizeof(*zp), GFP_KERNEL); + if (!zp) + return -ENOMEM; + + zp->dev = dev; + + /* Only mappings here: the PHY is not touched until phy_init() */ + zp->pma = devm_platform_ioremap_resource_byname(pdev, "pma"); + if (IS_ERR(zp->pma)) + return PTR_ERR(zp->pma); + + zp->pcs = devm_platform_ioremap_resource_byname(pdev, "pcs"); + if (IS_ERR(zp->pcs)) + return PTR_ERR(zp->pcs); + + zp->rst = devm_platform_ioremap_resource_byname(pdev, "rst"); + if (IS_ERR(zp->rst)) + return PTR_ERR(zp->rst); + + zp->udbg = devm_platform_ioremap_resource_byname(pdev, "udbg"); + if (IS_ERR(zp->udbg)) + return PTR_ERR(zp->udbg); + + zp->soc = devm_platform_ioremap_resource_byname(pdev, "soc"); + if (IS_ERR(zp->soc)) + return PTR_ERR(zp->soc); + + zp->pmu = exynos_get_pmu_regmap_by_phandle(dev->of_node, + "samsung,pmu-syscon"); + if (IS_ERR(zp->pmu)) + return dev_err_probe(dev, PTR_ERR(zp->pmu), + "failed to get the PMU regmap\n"); + + ret = of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1, + &zp->pmu_offset); + if (ret) + return dev_err_probe(dev, ret, + "missing PMU PHY control offset\n"); + + phy = devm_phy_create(dev, NULL, &zuma_pcie_phy_ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY\n"); + + phy_set_drvdata(phy, zp); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id zuma_pcie_phy_of_match[] = { + { .compatible = "google,zuma-pcie-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, zuma_pcie_phy_of_match); + +static struct platform_driver zuma_pcie_phy_driver = { + .probe = zuma_pcie_phy_probe, + .driver = { + .name = "zuma-pcie-phy", + .of_match_table = zuma_pcie_phy_of_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(zuma_pcie_phy_driver); + +MODULE_DESCRIPTION("Google zuma PCIe Gen3 PHY driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index e357744d4a..a1fbaa2ecd 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -343,6 +343,7 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_CLUSTER1_NONCPU_INT_EN 0x1544 #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 +#define ZUMA_PHY_CTRL_PCIE1 0x3ec8 static const struct regmap_range zuma_pmu_registers[] = { /* reboot mode */ @@ -358,6 +359,7 @@ static const struct regmap_range zuma_pmu_registers[] = { /* PHY isolation */ regmap_reg_range(GS101_PHY_CTRL_USB20, GS101_PHY_CTRL_USB20), regmap_reg_range(ZUMA_PHY_CTRL_UFS, ZUMA_PHY_CTRL_UFS), + regmap_reg_range(ZUMA_PHY_CTRL_PCIE1, ZUMA_PHY_CTRL_PCIE1), /* a hint TF-A reads, not a status register: see zuma_pmu_regmap_init() */ regmap_reg_range(ZUMA_PMU_INFORM0, ZUMA_PMU_INFORM0), }; diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 870aae6592..4edda4cc02 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -1676,6 +1676,9 @@ static const struct platform_device_id s3c64xx_spi_driver_ids[] = { MODULE_DEVICE_TABLE(platform, s3c64xx_spi_driver_ids); static const struct of_device_id s3c64xx_spi_dt_match[] = { + { .compatible = "google,zuma-spi", + .data = &zumapro_spi_port_config, + }, { .compatible = "google,zumapro-spi", .data = &zumapro_spi_port_config, }, diff --git a/include/dt-bindings/clock/google,zuma.h b/include/dt-bindings/clock/google,zuma.h new file mode 100644 index 0000000000..45aef7817c --- /dev/null +++ b/include/dt-bindings/clock/google,zuma.h @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +#ifndef _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H +#define _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H + +/* CMU_TOP: the HSI0 NoC and peripheral clock paths. */ +#define CLK_FOUT_SHARED0 1 +#define CLK_FOUT_SHARED1 2 +#define CLK_FOUT_SHARED2 3 +#define CLK_FOUT_SHARED3 4 +#define CLK_FOUT_SPARE 5 +#define CLK_SHARED0_D4 6 +#define CLK_SHARED1_D4 7 +#define CLK_SHARED2_D2 8 +#define CLK_SHARED3_D2 9 +#define CLK_MOUT_HSI0_NOC 10 +#define CLK_GOUT_HSI0_NOC 11 +#define CLK_DOUT_HSI0_NOC 12 +#define CLK_MOUT_HSI0_PERI 13 +#define CLK_GOUT_HSI0_PERI 14 +#define CLK_DOUT_HSI0_PERI 15 + +/* CMU_HSI0: USI2, the touchscreen's SPI. */ +#define CLK_GOUT_HSI0_ALT 1 +#define CLK_MOUT_HSI0_NOC_USER 2 +#define CLK_MOUT_HSI0_ALT_USER 3 +#define CLK_MOUT_HSI0_NOC_LOCAL 4 +#define CLK_MOUT_HSI0_PERI_USER 5 +#define CLK_MOUT_HSI0_USI2 6 +#define CLK_GOUT_HSI0_USI2_SOURCE 7 +#define CLK_DOUT_HSI0_USI2 8 +#define CLK_GOUT_HSI0_USI2_IP 9 +#define CLK_GOUT_HSI0_USI2_PCLK 10 + +/* CMU_APM: the APM mailbox, its SRAM and the always-on GPIO banks. */ +#define CLK_APM_PLL_ALV_DIV2 1 +#define CLK_APM_PLL_ALV_DIV4 2 +#define CLK_APM_PLL_ALV_DIV8 3 +#define CLK_APM_PLL_ALV_DIV16 4 +#define CLK_MOUT_APM_FUNCSRC 5 +#define CLK_MOUT_APM_FUNC 6 +#define CLK_GOUT_APM_FUNC 7 +#define CLK_DOUT_APM_NOC 8 +#define CLK_GOUT_APM_MAILBOX_AP 9 +#define CLK_GOUT_APM_INTMEM_ACLK 10 +#define CLK_GOUT_APM_INTMEM_PCLK 11 +#define CLK_GOUT_APM_GPIO_ALIVE 12 +#define CLK_GOUT_APM_GPIO_FAR_ALIVE 13 +#define CLK_GOUT_APM_GPIO_CUSTOM_ALIVE 14 + +#endif /* _DT_BINDINGS_CLOCK_GOOGLE_ZUMA_H */