diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml index 8589631085..be1765aa4d 100644 --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml @@ -56,6 +56,7 @@ properties: - pci14e4,4433 # BCM4387 - pci14e4,4434 # BCM4388 - pci14e4,4441 # BCM4389 + - pci14e4,4449 # BCM4383 - pci14e4,449d # BCM43752 reg: diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie-cp.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie-cp.yaml index 0b8ed61f08..005f1d4541 100644 --- a/Documentation/devicetree/bindings/pci/google,gs201-pcie-cp.yaml +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie-cp.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/pci/google,gs201-pcie-cp.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 PCIe GEN4A_0 (modem link) +title: Google gs201 and zumapro PCIe modem link maintainers: - Derek Ross @@ -17,21 +17,48 @@ description: | at a fixed window. The modem's control lines are described in a "modem" child node. + zumapro (Tensor G4, Pixel 9a) connects the same modem through PCIe GEN3A_0 + in its HSI1 block, a two-lane Gen3 root complex. It has no I/A sequencer + and no secure monitor translation: the host programs its outbound address + translation itself, and its two-lane PHY has a driver of its own. + allOf: - $ref: /schemas/pci/pci-host-bridge.yaml# + - if: + properties: + compatible: + const: google,gs201-pcie-cp + then: + properties: + reg: + minItems: 4 + reg-names: + minItems: 4 + required: + - samsung,sysreg + else: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 properties: compatible: - const: google,gs201-pcie-cp + enum: + - google,gs201-pcie-cp + - google,zumapro-pcie-cp reg: + minItems: 3 items: - description: sub-controller (ELBI) registers - description: DesignWare DBI registers - description: endpoint configuration space window - - description: I/A sequencer registers + - description: I/A sequencer registers (gs201) reg-names: + minItems: 3 items: - const: elbi - const: dbi @@ -84,7 +111,8 @@ properties: - description: offset of the PHY isolation control register description: PMU and the PHY isolation control register. The PHY driver releases - isolation; this controller sets it again once the link is down. + isolation. On gs201 this controller sets it again once the link is + down; on zumapro the PHY stays out of isolation, as stock leaves it. memory-region: maxItems: 1 @@ -99,7 +127,9 @@ properties: - items: - description: HSI1 system registers - description: offset of the shareability control register - description: SYSREG_HSI1 and its PCIe shareability (I/O coherency) register. + description: + SYSREG_HSI1 and its PCIe shareability (I/O coherency) register. + Optional on zumapro, whose link then runs without I/O coherency. modem: type: object @@ -164,7 +194,6 @@ required: - phys - reset-gpios - samsung,pmu-syscon - - samsung,sysreg unevaluatedProperties: false @@ -215,3 +244,32 @@ examples: cp2ap-phone-active-gpios = <&gpa8 4 GPIO_ACTIVE_HIGH>; }; }; + - | + #include + #include + + pcie@12100000 { + compatible = "google,zumapro-pcie-cp"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x14e00000 0x40000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + reg = <0x12100000 0x1400>, <0x12400000 0x381000>, + <0x40ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + interrupts = , + , + , + , + , + ; + interrupt-names = "ctrl", "msi0", "msi1", "msi2", "msi3", "msi4"; + phys = <&pcie_0_phy>; + phy-names = "pcie"; + memory-region = <&cp_msi_rmem>; + reset-gpios = <&gph0 0 GPIO_ACTIVE_LOW>; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + num-lanes = <2>; + max-link-speed = <3>; + }; diff --git a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml index 89e65f2a1f..19181b1434 100644 --- a/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml +++ b/Documentation/devicetree/bindings/pci/google,gs201-pcie.yaml @@ -4,26 +4,47 @@ $id: http://devicetree.org/schemas/pci/google,gs201-pcie.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Google gs201 PCIe host controller +title: Google gs201 and zuma PCIe host controllers maintainers: - Derek Ross description: - The PCIe controllers of the Google gs201 (Tensor G2) SoC are Synopsys - DesignWare cores (IP version 0x984500) in a Samsung wrapper. The wrapper + The PCIe controllers of the Google gs201 (Tensor G2) and zuma (Tensor G3) + SoCs are Synopsys DesignWare cores (IP versions 0x984500 and 0x986500) in + a Samsung wrapper. The wrapper adds a sub-control block (ELBI) with link training control and interrupt status, and an I/A sequencer that re-locks the PHY clock-data recovery when - the link leaves L1.2. Legacy INTx interrupts are demultiplexed from the - controller interrupt by a child interrupt controller. + the link leaves L1.2. zuma's Wi-Fi controller runs without the I/A, as on + stock. zumapro's (Tensor G4) Wi-Fi controller is the same as zuma's, at + the same addresses and with the same register map, so it uses zuma's + compatible as a fallback. Legacy INTx interrupts are demultiplexed from + the controller interrupt by a child interrupt controller. allOf: - $ref: /schemas/pci/pci-host-bridge.yaml# - $ref: /schemas/pci/snps,dw-pcie-common.yaml# + - if: + properties: + compatible: + contains: + const: google,zuma-pcie + then: + properties: + reg: + maxItems: 3 + reg-names: + maxItems: 3 properties: compatible: - const: google,gs201-pcie + oneOf: + - enum: + - google,gs201-pcie + - google,zuma-pcie + - items: + - const: google,zumapro-pcie + - const: google,zuma-pcie reg: minItems: 3 diff --git a/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml new file mode 100644 index 0000000000..01d79d3632 --- /dev/null +++ b/Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/google,zuma-pcie-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Google zuma PCIe Gen3 PHY + +maintainers: + - Brett-Michael Green + +description: + The one-lane PCIe Gen3 PHY of the Google zuma (Tensor G3) SoC's second + PCIe controller, which connects the Wi-Fi chip on Pixel 8 phones. Its + reference clock comes from an external PLL in the UDBG block, selected as + the PHY's input clock in the controller's SOC block. The PMU isolates the + PHY until it is released. zumapro (Tensor G4) has the same PHY for its + Wi-Fi controller, programmed with the same sequence, so it uses zuma's + compatible as a fallback. + + zumapro's first PCIe controller, which connects the modem on the Pixel 9a, + has a two-lane Gen3 PHY with the same register blocks. It has its own + external PLL controls and power-down sequence and two lanes of PMA + registers, so it has a compatible of its own. + +properties: + compatible: + oneOf: + - const: google,zuma-pcie-phy + - items: + - const: google,zumapro-pcie-phy + - const: google,zuma-pcie-phy + - const: google,zumapro-pcie-gen3x2-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>; + }; + - | + phy@12140000 { + compatible = "google,zumapro-pcie-gen3x2-phy"; + reg = <0x12140000 0x3000>, <0x12120000 0x5000>, + <0x12101400 0x10>, <0x12130000 0xd000>, + <0x12110000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + #phy-cells = <0>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index d5c748f6f6..1a68316b1c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11169,6 +11169,7 @@ F: Documentation/devicetree/bindings/clock/google,gs201-clock.yaml F: Documentation/devicetree/bindings/clock/google,zuma-clock.yaml F: Documentation/devicetree/bindings/clock/google,zumapro* F: Documentation/devicetree/bindings/phy/google,lga-usb-phy.yaml +F: Documentation/devicetree/bindings/phy/google,zuma-pcie-phy.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-dtzpc.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu.yaml F: Documentation/devicetree/bindings/soc/google/google,gs101-pmu-intr-gen.yaml @@ -11181,6 +11182,7 @@ F: drivers/clk/samsung/clk-zumapro.c F: drivers/phy/phy-google-usb.c F: drivers/soc/samsung/gs101-pmu.c F: drivers/phy/samsung/phy-gs101-ufs.c +F: drivers/phy/samsung/phy-zuma-pcie.c F: drivers/phy/samsung/phy-zumapro-ufs.c F: drivers/thermal/samsung/gs101_acpm_tmu.c F: drivers/usb/dwc3/dwc3-google.c diff --git a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts index 6ed1514cba..b822ba3077 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-husky.dts +++ b/arch/arm64/boot/dts/exynos/google/zuma-husky.dts @@ -65,6 +65,24 @@ height-mm = <155>; }; + /* + * WL_REG_ON of the BCM4398 (gph3-4, stock's wl_reg_on). Modelled as + * the root port's supply so the PCI pwrctrl core switches it around + * link training; bcmdhd waits 200 ms after raising it. With pcie_1 + * disabled nothing enables it, so the chip stays off. + */ + wlan_pwr: regulator-wlan { + compatible = "regulator-fixed"; + regulator-name = "wlan-reg-on"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + gpio = <&gph3 4 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <200000>; + pinctrl-0 = <&wlan_reg_on>; + pinctrl-names = "default"; + }; + chosen { /* * ABL requires bootargs to exist; it appends its own after these. @@ -149,6 +167,19 @@ reg = <0x0 0xfac00000 (1344 * 2992 * 4)>; no-map; }; + + /* + * All of the Wi-Fi chip's DMA buffers come from this pool, below + * 4 GiB, as on the Pixel 7 Pro: it keeps driver bugs and stray + * pointers away from the rest of RAM. It does not confine the + * chip's own firmware. + */ + wifi_dma_pool: wifi-dma-pool { + compatible = "restricted-dma-pool"; + size = <0x1000000>; + alignment = <0x0 0x200000>; + alloc-ranges = <0x0 0x80000000 0x80000000>; + }; }; }; @@ -176,6 +207,69 @@ }; }; +/* + * Wi-Fi: the BCM4398 on pcie_1, one Gen3 lane as on stock. Its DMA + * buffers come from wifi_dma_pool. + */ +&pcie_1 { + pinctrl-0 = <&pcie1_clkreq>, <&pcie1_perst>, <&wlan_dev_wake>, + <&wlan_host_wake>; + status = "okay"; + + pcie@0,0 { + compatible = "pciclass,0604"; + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <0x01 0xff>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + vpcie3v3-supply = <&wlan_pwr>; + + wifi@0,0 { + compatible = "pci14e4,4444"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "google,zuma-husky"; + memory-region = <&wifi_dma_pool>; + }; + }; +}; + +&pcie_1_phy { + status = "okay"; +}; + +&pinctrl_far_alive { + wlan_host_wake: wlan-host-wake-pins { + samsung,pins = "gpa5-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; +}; + +&pinctrl_hsi2 { + wlan_reg_on: wlan-reg-on-pins { + samsung,pins = "gph3-4"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; + + wlan_dev_wake: wlan-dev-wake-pins { + samsung,pins = "gph3-5"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; +}; + &spi20 { status = "okay"; diff --git a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi index 74b6905631..cb9a1349aa 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma-pinctrl.dtsi @@ -319,6 +319,24 @@ }; }; +&pinctrl_far_alive { + gpa5: gpa5-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&gic>; + interrupts = , + , + , + , + , + , + , + ; + }; +}; + &pinctrl_peric0 { gpp0: gpp0-gpio-bank { gpio-controller; @@ -585,6 +603,39 @@ }; }; +&pinctrl_hsi2 { + gph3: gph3-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + gph4: gph4-gpio-bank { + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + pcie1_clkreq: pcie1-clkreq-pins { + samsung,pins = "gph3-1"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + samsung,pin-pud-pdn = ; + }; + + pcie1_perst: pcie1-perst-pins { + samsung,pins = "gph3-0"; + samsung,pin-function = ; + samsung,pin-pud = ; + samsung,pin-drv = ; + samsung,pin-con-pdn = ; + }; +}; + &pinctrl_hsi2ufs { gph5: gph5-gpio-bank { gpio-controller; diff --git a/arch/arm64/boot/dts/exynos/google/zuma.dtsi b/arch/arm64/boot/dts/exynos/google/zuma.dtsi index 21c184ae87..17fa18b069 100644 --- a/arch/arm64/boot/dts/exynos/google/zuma.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zuma.dtsi @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -26,7 +27,9 @@ aliases { pinctrl0 = &pinctrl_gpio_alive; pinctrl1 = &pinctrl_custom_alive; + pinctrl2 = &pinctrl_far_alive; pinctrl8 = &pinctrl_hsi1; + pinctrl9 = &pinctrl_hsi2; pinctrl10 = &pinctrl_hsi2ufs; pinctrl11 = &pinctrl_peric0; pinctrl12 = &pinctrl_peric1; @@ -303,7 +306,8 @@ compatible = "simple-bus"; #address-cells = <1>; #size-cells = <1>; - ranges = <0x0 0x0 0x0 0x40000000>; + /* Registers below 1 GiB, PCIe windows at 0x40000000-0x7fffffff */ + ranges = <0x0 0x0 0x0 0x80000000>; /* * ABL hands over with both cluster watchdogs counting (30 s); @@ -620,6 +624,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>; @@ -628,6 +640,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>, @@ -757,6 +821,18 @@ }; }; + pinctrl_far_alive: pinctrl@154e0000 { + compatible = "google,zuma-pinctrl"; + reg = <0x154e0000 0x1000>; + clocks = <&cmu_apm CLK_GOUT_APM_GPIO_FAR_ALIVE>; + clock-names = "pclk"; + + wakeup-interrupt-controller { + compatible = "google,zuma-wakeup-eint", + "google,zumapro-wakeup-eint"; + }; + }; + apm_sram: sram@15700000 { compatible = "mmio-sram"; reg = <0x15700000 0x58000>; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts index f66e006084..5e7eb363fb 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu.dts @@ -147,6 +147,19 @@ regulator-boot-on; regulator-always-on; }; + + /* + * WL_REG_ON (gph3-4), the Wi-Fi chip's power enable (stock's + * pcie,wlan-gpio), raised 150 ms before the PCIe PHY is configured. + * It is the root port's supply, so the PCI pwrctrl core switches it. + */ + wlan_reg_on: regulator-wlan-reg-on { + compatible = "regulator-fixed"; + regulator-name = "wlan-reg-on"; + gpio = <&gph3 4 GPIO_ACTIVE_HIGH>; + enable-active-high; + startup-delay-us = <150000>; + }; }; &{/reserved-memory} { @@ -169,6 +182,19 @@ alignment = <0x0 0x00200000>; alloc-ranges = <0x0 0x98000000 0x06000000>; }; + + /* + * All of the Wi-Fi chip's DMA buffers come from this pool. It keeps + * driver bugs away from the rest of RAM; it does not confine the + * chip's own firmware, as the HSI2 System MMU and S2MPU see PCIe and + * UFS on the same VID and cannot enforce on it. + */ + wifi_dma_pool: wifi-dma-pool { + compatible = "restricted-dma-pool"; + size = <0x01000000>; + alignment = <0x0 0x00200000>; + alloc-ranges = <0x0 0x80000000 0x80000000>; + }; }; &acpm_ipc { @@ -536,6 +562,78 @@ }; }; +/* + * The Samsung S5300 modem on pcie_0, with its control lines from stock's + * cpif node (Google's GPL zumapro-board-cp-s5300-sit.dtsi and the 9a's + * board overlay) and the memory it shares with the host from stock's + * cp_shmem node. Raw levels, as Google's CPIF drives them. The link + * driver (pcie-gs201-cp) drives the lines while the modem node is + * enabled; the modem driver (CPIF) takes them, and the memory, when an + * overlay disables it. Nothing reaches the controller, the PHY or the + * lines until the link driver is loaded with allow_hw=1. + */ +&pcie_0 { + memory-region = <&cp_msi_rmem>; + status = "okay"; + + modem { + compatible = "samsung,s5300-modem"; + memory-region = <&cp_rmem>, <&cp_msi_rmem>, <&cp_rmem_1>; + ap2cp-pda-active-gpios = <&gpp16 2 GPIO_ACTIVE_HIGH>; + ap2cp-cp-pwr-on-gpios = <&gpp12 2 GPIO_ACTIVE_HIGH>; + ap2cp-nreset-gpios = <&gpp12 3 GPIO_ACTIVE_HIGH>; + ap2cp-cp-wrst-gpios = <&gpp16 3 GPIO_ACTIVE_HIGH>; + ap2cp-pm-wrst-gpios = <&gpp8 3 GPIO_ACTIVE_HIGH>; + ap2cp-wakeup-gpios = <&gpp16 0 GPIO_ACTIVE_HIGH>; + ap2cp-dump-noti-gpios = <&gpp16 1 GPIO_ACTIVE_HIGH>; + cp2ap-cp-wrst-gpios = <&gpa7 3 GPIO_ACTIVE_HIGH>; + cp2ap-ps-hold-gpios = <&gpa5 0 GPIO_ACTIVE_HIGH>; + cp2ap-wakeup-gpios = <&gpa5 1 GPIO_ACTIVE_HIGH>; + cp2ap-phone-active-gpios = <&gpa5 2 GPIO_ACTIVE_HIGH>; + }; +}; + +&pcie_0_phy { + status = "okay"; +}; + +/* + * Wi-Fi: the BCM4383 on pcie_1, one lane at Gen2, the chip's own limit + * (its LnkCap reads 5 GT/s). Its DMA buffers come from wifi_dma_pool. + */ +&pcie_1 { + max-link-speed = <2>; + status = "okay"; + + pcie@0,0 { + compatible = "pciclass,0604"; + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + bus-range = <0x01 0xff>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + vpcie3v3-supply = <&wlan_reg_on>; + /* + * No I/A sequencer re-locks the PHY after L1: with ASPM on, the + * link entered L1 and config reads of the chip returned all ones. + */ + aspm-no-l0s; + aspm-no-l1; + + wifi@0,0 { + compatible = "pci14e4,4449"; + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "google,zumapro-tegu"; + memory-region = <&wifi_dma_pool>; + }; + }; +}; + +&pcie_1_phy { + status = "okay"; +}; + &pinctrl_alive { status = "okay"; @@ -559,6 +657,8 @@ }; &pinctrl_far_alive { + pinctrl-0 = <&cp2ap_float>, <&cp2ap_wakeup_up>; + pinctrl-names = "default"; status = "okay"; bt_host_wake: bt-host-wake-pins { @@ -566,6 +666,22 @@ samsung,pin-function = ; samsung,pin-pud = ; }; + + /* + * The modem's PS_HOLD and PHONE_ACTIVE float, as stock leaves them. + * The bootloader leaves the bank pulled down, which hid both lines + * from the host until the modem drove them high. + */ + cp2ap_float: cp2ap-float-pins { + samsung,pins = "gpa5-0", "gpa5-2"; + samsung,pin-pud = ; + }; + + /* The modem's wake line, pulled up as the Pixel 7's bootloader leaves it */ + cp2ap_wakeup_up: cp2ap-wakeup-up-pins { + samsung,pins = "gpa5-1"; + samsung,pin-pud = ; + }; }; &pinctrl_hsi1 { diff --git a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi index be17249e58..3d3126ab93 100644 --- a/arch/arm64/boot/dts/exynos/google/zumapro.dtsi +++ b/arch/arm64/boot/dts/exynos/google/zumapro.dtsi @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -1192,6 +1193,72 @@ gpio-controller; #gpio-cells = <2>; }; + + /* Stock's pcie0 pins, selected by the link driver */ + pcie0_clkreq: pcie0-clkreq-pins { + samsung,pins = "gph0-1"; + samsung,pin-function = <2>; + samsung,pin-pud = <3>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + samsung,pin-pud-pdn = <3>; + }; + + pcie0_perst: pcie0-perst-pins { + samsung,pins = "gph0-0"; + samsung,pin-function = <1>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + }; + }; + + /* + * The modem's controller (stock's pcie_0, ch-num 0) in HSI1: + * the zuma family's root complex with two Gen3 lanes. The host + * programs its outbound iATU; there is no secure-ATU SMC on + * zumapro. No clocks: stock's node names none. + */ + pcie_0: pcie@12100000 { + compatible = "google,zumapro-pcie-cp"; + reg = <0x0 0x12100000 0x1400>, + <0x0 0x12400000 0x381000>, + <0x0 0x40ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + /* PCI 0x14e00000 = CPU 0x40000000, the host's iATU region 1 */ + ranges = <0x82000000 0x0 0x14e00000 0x0 0x40000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = , + , + , + , + , + ; + interrupt-names = "ctrl", "msi0", "msi1", "msi2", "msi3", "msi4"; + phys = <&pcie_0_phy>; + phy-names = "pcie"; + pinctrl-0 = <&pcie0_clkreq>, <&pcie0_perst>; + pinctrl-names = "active"; + reset-gpios = <&gph0 0 GPIO_ACTIVE_LOW>; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + num-lanes = <2>; + max-link-speed = <3>; + status = "disabled"; + }; + + pcie_0_phy: phy@12140000 { + compatible = "google,zumapro-pcie-gen3x2-phy"; + reg = <0x0 0x12140000 0x3000>, + <0x0 0x12120000 0x5000>, + <0x0 0x12101400 0x10>, + <0x0 0x12130000 0xd000>, + <0x0 0x12110000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec4>; + #phy-cells = <0>; + status = "disabled"; }; cmu_hsi2: clock-controller@13000000 { @@ -1228,6 +1295,24 @@ gpio-controller; #gpio-cells = <2>; }; + + /* Stock's pcie1 pins, the same as zuma's */ + pcie1_clkreq: pcie1-clkreq-pins { + samsung,pins = "gph3-1"; + samsung,pin-function = <2>; + samsung,pin-pud = <3>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + samsung,pin-pud-pdn = <3>; + }; + + pcie1_perst: pcie1-perst-pins { + samsung,pins = "gph3-0"; + samsung,pin-function = <1>; + samsung,pin-pud = <0>; + samsung,pin-drv = <3>; + samsung,pin-con-pdn = <3>; + }; }; pinctrl_hsi2ufs: pinctrl@13060000 { @@ -1260,6 +1345,66 @@ }; }; + /* + * The Wi-Fi chip's controller (stock's pcie_1, ch-num 1), zuma's + * controller at zuma's addresses: one Gen3 lane, no I/A, not + * cache coherent. Its interrupts are its legacy INTx; stock's + * MSI lines are unused. + */ + pcie_1: pcie@13120000 { + compatible = "google,zumapro-pcie", "google,zuma-pcie"; + reg = <0x0 0x13120000 0x1400>, + <0x0 0x13400000 0x381000>, + <0x0 0x60ffe000 0x2000>; + reg-names = "elbi", "dbi", "config"; + #address-cells = <3>; + #size-cells = <2>; + device_type = "pci"; + ranges = <0x82000000 0x0 0x60000000 0x0 0x60000000 0x0 0xff0000>; + bus-range = <0x00 0xff>; + interrupts = ; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_1_intc 1>, + <0 0 0 2 &pcie_1_intc 2>, + <0 0 0 3 &pcie_1_intc 3>, + <0 0 0 4 &pcie_1_intc 4>; + clocks = <&cmu_hsi2 CLK_GOUT_PCIE1_CTL_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_DBI_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_SLV_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_MSTR_ACLK>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_UDBG_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_PAL_APB>, + <&cmu_hsi2 CLK_GOUT_PCIE1_PHY_REF>; + phys = <&pcie_1_phy>; + phy-names = "pcie"; + pinctrl-0 = <&pcie1_clkreq>, <&pcie1_perst>; + pinctrl-names = "default"; + reset-gpios = <&gph3 0 GPIO_ACTIVE_LOW>; + num-lanes = <1>; + max-link-speed = <3>; + status = "disabled"; + + pcie_1_intc: legacy-interrupt-controller { + #address-cells = <0>; + interrupt-controller; + #interrupt-cells = <1>; + }; + }; + + pcie_1_phy: phy@13160000 { + compatible = "google,zumapro-pcie-phy", "google,zuma-pcie-phy"; + reg = <0x0 0x13160000 0x3000>, + <0x0 0x13140000 0x5000>, + <0x0 0x13121400 0x10>, + <0x0 0x13150000 0xd000>, + <0x0 0x13130000 0x5000>; + reg-names = "pma", "pcs", "rst", "udbg", "soc"; + samsung,pmu-syscon = <&pmu_system_controller 0x3ec8>; + #phy-cells = <0>; + status = "disabled"; + }; + ufs: ufs@13200000 { compatible = "google,zumapro-ufs"; reg = <0x0 0x13200000 0x200>, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h index f41d87dd55..0ced0b8c26 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bus.h @@ -133,6 +133,7 @@ struct brcmf_bus_msgbuf { u16 max_flowrings; u16 max_submissionrings; u16 max_completionrings; + u32 d2h_sync; }; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c index 8d386c0422..f57a5dfcce 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; @@ -3526,7 +3555,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; @@ -7758,7 +7788,7 @@ static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp) struct ieee80211_supported_band *band; u16 max_interfaces = 0; bool gscan; - __le32 bandlist[3]; + __le32 bandlist[4]; /* count, then up to 2.4, 5 and 6 GHz */ u32 n_bands; int err, i; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c index e2a628dc32..a97013c00b 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c @@ -2,6 +2,7 @@ /* * Copyright (c) 2014 Broadcom Corporation */ +#include #include #include #include @@ -20,6 +21,7 @@ /* SOC Interconnect types (aka chip types) */ #define SOCI_SB 0 #define SOCI_AI 1 +#define SOCI_NCI 6 /* PL-368 DMP definitions */ #define DMP_DESC_TYPE_MSK 0x0000000F @@ -229,11 +231,60 @@ struct sbsocramregs { #define ARMCR4_BSZ_MULT 8192 #define ARMCR4_BLK_1K_MASK 0x200 +/* + * NCI ("Booker") backplane, as on the BCM4398. Chipcommon's eromptr points + * at EROM2, a list of interface descriptors grouped by core. Each core's + * info word and interface count sit either in EROM1 (just below EROM2) or + * in the OOB router (OOBR, at the 8 KiB boundary below it); OOBR cores also + * have a DMP control word, which takes the clock and core flags that the AI + * backplane keeps in the wrapper's ioctrl. Each interface is a network + * interface (NI) node with its own reset control. Register layout from + * Broadcom's GPL bcmdhd (nciutils.c, hal_nci_cmn.h, hndoobr.h). + */ +#define NCI_OOBR_BASE(erom2) ((erom2) & ~0x1fffU) +#define NCI_EROM1_BASE(erom2) ((erom2) & ~0xfffU) +#define NCI_OOBR_CAP 0x0 +#define NCI_OOBR_CAP_CORECNT 0x1f +#define NCI_CI_COREID GENMASK(11, 0) +#define NCI_CI_REV GENMASK(19, 12) +#define NCI_CI_ISBP BIT(27) +#define NCI_IC_IFACECNT GENMASK(15, 12) +#define NCI_ID0_NODEPTR GENMASK(31, 3) +#define NCI_ID1_WORDOFFSET GENMASK(31, 28) +#define NCI_ID1_EROM1 BIT(27) +#define NCI_ID1_MASTER BIT(26) +#define NCI_ID1_NADDR GENMASK(25, 24) +#define NCI_ID1_BPID GENMASK(23, 20) +#define NCI_ID1_COREPTR GENMASK(12, 0) +#define NCI_BPID_BOOKER 0 +#define NCI_BPID_PMNI_FIRST 2 +#define NCI_BPID_PMNI_LAST 8 +#define NCI_SP_BASE GENMASK(31, 8) +#define NCI_SP_BOUND BIT(6) +#define NCI_SP_64BIT BIT(5) +#define NCI_EROM_END 0xffffffff +#define NCI_DMPCTRL 0x8 +#define NCI_NI_RESET_CTL 0x140 +#define NCI_NI_RESET_ENTRY BIT(0) +#define NCI_MAX_IFACES 16 +#define NCI_RESET_TIMEOUT_US 5000 + +struct brcmf_nci_iface { + u32 node; + bool booker; + bool pmni; + bool shared; +}; + struct brcmf_core_priv { struct brcmf_core pub; u32 wrapbase; struct list_head list; struct brcmf_chip_priv *chip; + /* NCI only: the DMP control word (0 if none) and the NI nodes */ + u32 dmpctrl; + u8 nifaces; + struct brcmf_nci_iface ifaces[NCI_MAX_IFACES]; }; struct brcmf_chip_priv { @@ -505,6 +556,96 @@ static void brcmf_chip_ai_resetcore(struct brcmf_core_priv *core, u32 prereset, } } +/* Update the DMP control word, which holds the AI ioctrl bits on NCI */ +static void brcmf_chip_nci_cflags(struct brcmf_core_priv *core, u32 mask, + u32 val) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 regdata; + + if (!core->dmpctrl) + return; + + regdata = ci->ops->read32(ci->ctx, core->dmpctrl); + ci->ops->write32(ci->ctx, core->dmpctrl, (regdata & ~mask) | val); + ci->ops->read32(ci->ctx, core->dmpctrl); +} + +/* Put each of the core's own NI nodes into reset, or take them out */ +static void brcmf_chip_nci_reset_ifaces(struct brcmf_core_priv *core, + bool reset) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 addr, regdata; + int i, us; + + for (i = core->nifaces - 1; i >= 0; i--) { + if (core->ifaces[i].shared || !core->ifaces[i].node) + continue; + + addr = core->ifaces[i].node + NCI_NI_RESET_CTL; + regdata = ci->ops->read32(ci->ctx, addr); + if (reset) + regdata |= NCI_NI_RESET_ENTRY; + else + regdata &= ~NCI_NI_RESET_ENTRY; + ci->ops->write32(ci->ctx, addr, regdata); + + for (us = 0; us < NCI_RESET_TIMEOUT_US; us += 10) { + regdata = ci->ops->read32(ci->ctx, addr); + if (!!(regdata & NCI_NI_RESET_ENTRY) == reset) + break; + udelay(10); + } + if (us >= NCI_RESET_TIMEOUT_US) + brcmf_err("core %#x: NI %#x reset %d timed out (%#x)\n", + core->pub.id, core->ifaces[i].node, reset, + regdata); + } +} + +static bool brcmf_chip_nci_iscoreup(struct brcmf_core_priv *core) +{ + struct brcmf_chip_priv *ci = core->chip; + u32 regdata; + + if (!core->wrapbase) + return true; + + regdata = ci->ops->read32(ci->ctx, core->wrapbase + NCI_NI_RESET_CTL); + + return !(regdata & NCI_NI_RESET_ENTRY); +} + +/* bcmdhd's nci_core_reset_enable(), less the final release */ +static void brcmf_chip_nci_coredisable(struct brcmf_core_priv *core, + u32 prereset, u32 reset) +{ + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, 0); + udelay(1); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), + prereset); + brcmf_chip_nci_reset_ifaces(core, true); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), reset); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_CLK, BCMA_IOCTL_CLK); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, BCMA_IOCTL_FGC); + udelay(1); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, 0); +} + +static void brcmf_chip_nci_resetcore(struct brcmf_core_priv *core, + u32 prereset, u32 reset, u32 postreset) +{ + brcmf_chip_nci_coredisable(core, prereset, reset); + brcmf_chip_nci_reset_ifaces(core, false); + brcmf_chip_nci_cflags(core, ~(BCMA_IOCTL_FGC | BCMA_IOCTL_CLK), + postreset); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_CLK, BCMA_IOCTL_CLK); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, BCMA_IOCTL_FGC); + udelay(1); + brcmf_chip_nci_cflags(core, BCMA_IOCTL_FGC, 0); +} + char *brcmf_chip_name(u32 id, u32 rev, char *buf, uint len) { const char *fmt; @@ -683,6 +824,7 @@ static u32 brcmf_chip_sysmem_ramsize(struct brcmf_core_priv *sysmem) switch (sysmem->chip->pub.chip) { case BRCM_CC_4389_CHIP_ID: + case BRCM_CC_4398_CHIP_ID: /* Count the RAM banks only, and skip the ROM banks in * front of them. */ @@ -784,8 +926,12 @@ static u32 brcmf_chip_tcm_rambase(struct brcmf_chip_priv *ci) return 0x170000; case BRCM_CC_4378_CHIP_ID: return 0x352000; + case BRCM_CC_4383_CHIP_ID: + return 0x6e0000; case BRCM_CC_4387_CHIP_ID: return 0x740000; + case BRCM_CC_4398_CHIP_ID: + return 0x2a0000; default: brcmf_err("unknown chip: %s\n", ci->pub.name); break; @@ -1002,6 +1148,148 @@ int brcmf_chip_dmp_erom_scan(struct brcmf_chip_priv *ci) return 0; } +/* Skip a slave interface's address descriptors; return the core's base */ +static u32 brcmf_chip_nci_slave_addrs(struct brcmf_chip_priv *ci, u32 *addr, + u32 naddr) +{ + u32 adesc, base = 0; + u32 i; + + for (i = 0; i < naddr; i++) { + adesc = ci->ops->read32(ci->ctx, *addr); + *addr += 4; + if (i == 0) + base = adesc & NCI_SP_BASE; + if (adesc & NCI_SP_64BIT) + *addr += 12; /* base high, bound low and high */ + else if (adesc & NCI_SP_BOUND) + *addr += 4; /* bound */ + } + + return base; +} + +/* An APB NI that several cores share is not one core's to reset */ +static void brcmf_chip_nci_mark_shared(struct brcmf_chip_priv *ci) +{ + struct brcmf_core_priv *a, *b; + int i, j; + + list_for_each_entry(a, &ci->cores, list) { + for (i = 0; i < a->nifaces; i++) { + if (!a->ifaces[i].pmni || !a->ifaces[i].node) + continue; + list_for_each_entry(b, &ci->cores, list) { + if (b == a) + continue; + for (j = 0; j < b->nifaces; j++) + if (b->ifaces[j].pmni && + b->ifaces[j].node == a->ifaces[i].node) + a->ifaces[i].shared = true; + } + } + } +} + +static int brcmf_chip_nci_erom_scan(struct brcmf_chip_priv *ci) +{ + u32 erom2, erom1, oobr, addr, ptr, coreinfo, ifcfg, desc0, desc1; + u32 ncores, base, wordoffset, naddr; + struct brcmf_core_priv *core; + struct brcmf_core *pub; + u8 i, nifaces; + u16 id; + + erom2 = ci->ops->read32(ci->ctx, + CORE_CC_REG(ci->pub.enum_base, eromptr)); + erom1 = NCI_EROM1_BASE(erom2); + oobr = NCI_OOBR_BASE(erom2); + ncores = (erom2 - erom1) / 8 + + (ci->ops->read32(ci->ctx, oobr + NCI_OOBR_CAP) & + NCI_OOBR_CAP_CORECNT); + brcmf_dbg(INFO, "NCI: EROM2 %#x, EROM1 %#x, OOBR %#x, %u cores\n", + erom2, erom1, oobr, ncores); + + addr = erom2; + while (ci->num_cores < ncores) { + desc0 = ci->ops->read32(ci->ctx, addr); + if (desc0 == NCI_EROM_END) + break; + + /* The first interface's second word locates the core info */ + desc1 = ci->ops->read32(ci->ctx, addr + 4); + ptr = FIELD_GET(NCI_ID1_COREPTR, desc1); + ptr += (desc1 & NCI_ID1_EROM1) ? erom1 : oobr; + coreinfo = ci->ops->read32(ci->ctx, ptr); + ifcfg = ci->ops->read32(ci->ctx, ptr + 4); + + id = FIELD_GET(NCI_CI_COREID, coreinfo); + if (id < 0xff) + id |= 0x800; /* Broadcom's cores */ + nifaces = FIELD_GET(NCI_IC_IFACECNT, ifcfg); + if (nifaces > NCI_MAX_IFACES) { + brcmf_err("NCI: core %#x has %u interfaces\n", id, + nifaces); + return -EFAULT; + } + + pub = brcmf_chip_add_core(ci, id, 0, 0); + if (IS_ERR(pub)) + return PTR_ERR(pub); + ci->num_cores++; + pub->rev = FIELD_GET(NCI_CI_REV, coreinfo); + core = container_of(pub, struct brcmf_core_priv, pub); + if (!(desc1 & NCI_ID1_EROM1)) + core->dmpctrl = ptr + NCI_DMPCTRL; + core->nifaces = nifaces; + + wordoffset = 0; + for (i = 0; i < nifaces; i++) { + struct brcmf_nci_iface *ifc = &core->ifaces[i]; + u8 bpid; + + desc0 = ci->ops->read32(ci->ctx, addr); + desc1 = ci->ops->read32(ci->ctx, addr + 4); + addr += 8; + + bpid = FIELD_GET(NCI_ID1_BPID, desc1); + ifc->node = desc0 & NCI_ID0_NODEPTR; + ifc->booker = bpid == NCI_BPID_BOOKER; + ifc->pmni = !(desc1 & NCI_ID1_MASTER) && + bpid >= NCI_BPID_PMNI_FIRST && + bpid <= NCI_BPID_PMNI_LAST; + wordoffset = FIELD_GET(NCI_ID1_WORDOFFSET, desc1); + + if (desc1 & NCI_ID1_MASTER) + continue; + + naddr = FIELD_GET(NCI_ID1_NADDR, desc1) + 1; + base = brcmf_chip_nci_slave_addrs(ci, &addr, naddr); + /* Registers: the APB slave, or a bridge's own slave */ + if (!pub->base && (ifc->pmni || (coreinfo & NCI_CI_ISBP))) + pub->base = base; + } + + /* The first Booker interface is the core's wrapper */ + for (i = 0; i < nifaces; i++) + if (core->ifaces[i].booker) { + core->wrapbase = core->ifaces[i].node; + break; + } + + brcmf_dbg(INFO, "NCI: core %#x rev %u base %#x wrap %#x dmpctrl %#x, %u interfaces\n", + pub->id, pub->rev, pub->base, core->wrapbase, + core->dmpctrl, nifaces); + + if (!wordoffset) + break; + } + + brcmf_chip_nci_mark_shared(ci); + + return 0; +} + u32 brcmf_chip_enum_base(u16 devid) { return SI_ENUM_BASE_DEFAULT; @@ -1034,7 +1322,8 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci) brcmf_chip_name(ci->pub.chip, ci->pub.chiprev, ci->pub.name, sizeof(ci->pub.name)); brcmf_dbg(INFO, "found %s chip: %s\n", - socitype == SOCI_SB ? "SB" : "AXI", ci->pub.name); + socitype == SOCI_SB ? "SB" : socitype == SOCI_NCI ? "NCI" : "AXI", + ci->pub.name); if (socitype == SOCI_SB) { if (ci->pub.chip != BRCM_CC_4329_CHIP_ID) { @@ -1081,6 +1370,14 @@ static int brcmf_chip_recognition(struct brcmf_chip_priv *ci) ci->resetcore = brcmf_chip_ai_resetcore; brcmf_chip_dmp_erom_scan(ci); + } else if (socitype == SOCI_NCI) { + ci->iscoreup = brcmf_chip_nci_iscoreup; + ci->coredisable = brcmf_chip_nci_coredisable; + ci->resetcore = brcmf_chip_nci_resetcore; + + ret = brcmf_chip_nci_erom_scan(ci); + if (ret) + return ret; } else { brcmf_err("chip backplane type %u is not supported\n", socitype); @@ -1124,8 +1421,13 @@ static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id) case BCMA_CORE_ARM_CA7: cpu = container_of(core, struct brcmf_core_priv, pub); - /* clear all IOCTL bits except HALT bit */ - val = chip->ops->read32(chip->ctx, cpu->wrapbase + BCMA_IOCTL); + /* clear all IOCTL bits except HALT bit (DMP control on NCI) */ + if (chip->resetcore == brcmf_chip_nci_resetcore) + val = cpu->dmpctrl ? + chip->ops->read32(chip->ctx, cpu->dmpctrl) : 0; + else + val = chip->ops->read32(chip->ctx, + cpu->wrapbase + BCMA_IOCTL); val &= ARMCR4_BCMA_IOCTL_CPUHALT; brcmf_chip_resetcore(core, val, ARMCR4_BCMA_IOCTL_CPUHALT, ARMCR4_BCMA_IOCTL_CPUHALT); @@ -1411,6 +1713,18 @@ static bool brcmf_chip_ca7_set_active(struct brcmf_chip_priv *chip, u32 rstvec) /* restore ARM */ core = brcmf_chip_get_core(&chip->pub, BCMA_CORE_ARM_CA7); + if (chip->resetcore == brcmf_chip_nci_resetcore) { + /* + * set_passive left the CA7 out of reset and halted; on NCI, + * as Broadcom's driver does, clearing the halt is enough + * (dhdpcie_bus_download_state()). Resetting it again keeps a + * second firmware download from starting. + */ + brcmf_chip_nci_cflags(container_of(core, struct brcmf_core_priv, + pub), + ARMCR4_BCMA_IOCTL_CPUHALT, 0); + return true; + } brcmf_chip_resetcore(core, ARMCR4_BCMA_IOCTL_CPUHALT, 0, 0); return true; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c index b6027d83e6..f7165dfc36 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c @@ -412,8 +412,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) brcmf_c_set_joinpref_default(ifp); /* Setup event_msgs, enable E_IF */ - err = brcmf_fil_iovar_data_get(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_get_event_mask(ifp); if (err) { bphy_err(drvr, "Get event_msgs error (%d)\n", err); goto done; @@ -425,8 +424,7 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) * that all vendors have. */ setbit(fweh->event_mask, BRCMF_E_IF); - err = brcmf_fil_iovar_data_set(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_set_event_mask(ifp); if (err) { bphy_err(drvr, "Set event_msgs error (%d)\n", err); goto done; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c index bff2f5c62e..85c1ef8ff4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c @@ -161,10 +161,15 @@ static void brcmf_feat_wlc_version_overrides(struct brcmf_pub *drv) * Versioned "join" parameters (wl_extjoin_params_v1_t), by the * same WLC version test as Broadcom's driver (bcmdhd * wl_cfg80211.c, MIN_JOINEXT_V1_*): 14.2 or 14.4, 16.1 and later - * on 16, or 17 and later. Only the BCM4389 for now; its 20.101.90 - * firmware reports 14.4 and rejects the unversioned layout. + * on 16, or 17 and later. The BCM4389 (its 20.101.90 firmware + * reports 14.4 and rejects the unversioned layout) and the Pixel + * 9a's BCM4383 (20.123.13: the unversioned "join" and SET_SSID + * both fail with -52), and the Pixel 8 Pro's BCM4398 (24.100, + * WLC version 18.2). */ - if (drv->bus_if->chip == BRCM_CC_4389_CHIP_ID && + if ((drv->bus_if->chip == BRCM_CC_4389_CHIP_ID || + drv->bus_if->chip == BRCM_CC_4383_CHIP_ID || + drv->bus_if->chip == BRCM_CC_4398_CHIP_ID) && ((major == 14 && (minor == 2 || minor == 4)) || (major == 16 && minor >= 1) || major >= 17)) feat_flags |= BIT(BRCMF_FEAT_JOIN_V1); @@ -353,16 +358,45 @@ void brcmf_feat_attach(struct brcmf_pub *drvr) brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa"); brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_SCAN_V2, "scan_ver"); + if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_SCAN_V2)) { + struct { + __le16 version; + __le16 length; + __le16 major; + } scan_ver = {}; + + err = brcmf_fil_iovar_data_get(ifp, "scan_ver", &scan_ver, + sizeof(scan_ver)); + brcmf_dbg(INFO, "scan interface version %u\n", + le16_to_cpu(scan_ver.major)); + if (!err && le16_to_cpu(scan_ver.major) == 3) + ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_V3); + else if (!err && le16_to_cpu(scan_ver.major) >= 4) + ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_V4); + } brcmf_feat_wlc_version_overrides(drvr); brcmf_feat_firmware_overrides(drvr); brcmf_fwvid_feat_attach(ifp); - /* Host-built 802.3 + LLC/SNAP TX headers: only the BCM4389 for now */ - if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID) + /* Host-built 802.3 + LLC/SNAP TX headers: the BCM4389 and BCM4398 for now */ + if (drvr->bus_if->chip != BRCM_CC_4389_CHIP_ID && + drvr->bus_if->chip != BRCM_CC_4398_CHIP_ID) drvr->feat_flags &= ~BIT(BRCMF_FEAT_HOST_SFHLLC); + /* + * The BCM4383's firmware (20.123.13 on the Pixel 9a) and the + * BCM4398's (24.100 on the Pixel 8 Pro) advertise the supplicant + * offload but refuse the key: brcmf_set_wsec() fails with "failed to + * change PSK in firmware" and the join never gets past + * authentication. Leave the handshakes to the host. + */ + if (drvr->bus_if->chip == BRCM_CC_4383_CHIP_ID || + drvr->bus_if->chip == BRCM_CC_4398_CHIP_ID) + drvr->feat_flags &= ~(BIT(BRCMF_FEAT_FWSUP) | BIT(BRCMF_FEAT_SAE) | + BIT(BRCMF_FEAT_FWAUTH)); + if (drvr->settings->feature_disable) { brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", ifp->drvr->feat_flags, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h index 8ebd231169..be20a6336c 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.h @@ -32,6 +32,8 @@ * DUMP_OBSS: Firmware has capable to dump obss info to support ACS * SCAN_V2: Version 2 scan params * SAE_EXT: SAE authentication handled by user-space supplicant + * SCAN_V3: Version 3 scan params (the v2 layout, with the pad as ssid_type) + * SCAN_V4: Version 4 scan params (scan_type_ext after scan_type) */ #define BRCMF_FEAT_LIST \ BRCMF_FEAT_DEF(MBSS) \ @@ -61,7 +63,9 @@ BRCMF_FEAT_DEF(PMKID_V3) \ BRCMF_FEAT_DEF(SAE_EXT) \ BRCMF_FEAT_DEF(JOIN_V1) \ - BRCMF_FEAT_DEF(HOST_SFHLLC) + BRCMF_FEAT_DEF(HOST_SFHLLC) \ + BRCMF_FEAT_DEF(SCAN_V3) \ + BRCMF_FEAT_DEF(SCAN_V4) /* * Quirks: diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c index 1cff4ba769..f6de0f0f36 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.c @@ -430,6 +430,81 @@ void brcmf_fweh_unregister(struct brcmf_pub *drvr, drvr->fweh->evt_handler[evt_handler_idx] = NULL; } +/* + * Newer firmware (the BCM4398's 24.100) has dropped the "event_msgs" iovar + * for "event_msgs_ext", whose mask is preceded by a small header, as + * Broadcom's driver and the Cypress vendor code use it. + */ +struct brcmf_fweh_eventmsgs_ext { + u8 ver; + u8 command; + u8 len; + u8 maxgetsize; + u8 mask[]; +}; + +#define BRCMF_EVENTMSGS_EXT_VER 1 +#define BRCMF_EVENTMSGS_EXT_SET_MASK 3 + +int brcmf_fweh_get_event_mask(struct brcmf_if *ifp) +{ + struct brcmf_fweh_info *fweh = ifp->drvr->fweh; + struct brcmf_fweh_eventmsgs_ext *msg; + u32 msglen; + int err; + + err = brcmf_fil_iovar_data_get(ifp, "event_msgs", fweh->event_mask, + fweh->event_mask_len); + if (err != -EBADE) + return err; + + msglen = sizeof(*msg) + fweh->event_mask_len; + msg = kzalloc(msglen, GFP_KERNEL); + if (!msg) + return -ENOMEM; + msg->ver = BRCMF_EVENTMSGS_EXT_VER; + msg->len = fweh->event_mask_len; + msg->maxgetsize = fweh->event_mask_len; + + err = brcmf_fil_iovar_data_get(ifp, "event_msgs_ext", msg, msglen); + if (!err) { + memcpy(fweh->event_mask, msg->mask, + min_t(uint, msg->len, fweh->event_mask_len)); + fweh->event_msgs_ext = true; + brcmf_dbg(EVENT, "using event_msgs_ext (%u bytes)\n", msg->len); + } + kfree(msg); + + return err; +} + +int brcmf_fweh_set_event_mask(struct brcmf_if *ifp) +{ + struct brcmf_fweh_info *fweh = ifp->drvr->fweh; + struct brcmf_fweh_eventmsgs_ext *msg; + u32 msglen; + int err; + + if (!fweh->event_msgs_ext) + return brcmf_fil_iovar_data_set(ifp, "event_msgs", + fweh->event_mask, + fweh->event_mask_len); + + msglen = sizeof(*msg) + fweh->event_mask_len; + msg = kzalloc(msglen, GFP_KERNEL); + if (!msg) + return -ENOMEM; + msg->ver = BRCMF_EVENTMSGS_EXT_VER; + msg->command = BRCMF_EVENTMSGS_EXT_SET_MASK; + msg->len = fweh->event_mask_len; + memcpy(msg->mask, fweh->event_mask, fweh->event_mask_len); + + err = brcmf_fil_iovar_data_set(ifp, "event_msgs_ext", msg, msglen); + kfree(msg); + + return err; +} + /** * brcmf_fweh_activate_events() - enables firmware events registered. * @@ -459,8 +534,7 @@ int brcmf_fweh_activate_events(struct brcmf_if *ifp) if (!brcmf_fwvid_activate_events(ifp)) return 0; - err = brcmf_fil_iovar_data_set(ifp, "event_msgs", fweh->event_mask, - fweh->event_mask_len); + err = brcmf_fweh_set_event_mask(ifp); if (err) bphy_err(fweh->drvr, "Set event_msgs error (%d)\n", err); return err; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h index e327dd58d2..7dc26ab185 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fweh.h @@ -336,6 +336,8 @@ struct brcmf_fweh_event_map { struct brcmf_fweh_info { struct brcmf_pub *drvr; bool p2pdev_setup_ongoing; + /* the firmware takes "event_msgs_ext" rather than "event_msgs" */ + bool event_msgs_ext; struct work_struct event_work; spinlock_t evt_q_lock; struct list_head event_q; @@ -357,6 +359,8 @@ int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code, void brcmf_fweh_unregister(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code); int brcmf_fweh_activate_events(struct brcmf_if *ifp); +int brcmf_fweh_get_event_mask(struct brcmf_if *ifp); +int brcmf_fweh_set_event_mask(struct brcmf_if *ifp); void brcmf_fweh_process_event(struct brcmf_pub *drvr, struct brcmf_event *event_packet, u32 packet_len, gfp_t gfp); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index f346f7c71a..0fe42ec7a4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -19,6 +19,8 @@ #define BRCMF_ARP_OL_PEER_AUTO_REPLY 0x00000008 #define BRCMF_BSS_INFO_VERSION 109 /* curr ver of brcmf_bss_info_le struct */ +/* v114 (the BCM4398's firmware): v109 with EHT fields appended */ +#define BRCMF_BSS_INFO_VERSION_114 114 #define BRCMF_BSS_RSSI_ON_CHANNEL 0x0004 #define BRCMF_STA_BRCM 0x00000001 /* Running a Broadcom driver */ @@ -49,6 +51,10 @@ /* size of brcmf_scan_params not including variable length array */ #define BRCMF_SCAN_PARAMS_FIXED_SIZE 64 #define BRCMF_SCAN_PARAMS_V2_FIXED_SIZE 72 +#define BRCMF_SCAN_PARAMS_VERSION_V3 3 +#define BRCMF_SCAN_PARAMS_VERSION_V4 4 +/* v4: scan_type_ext follows scan_type, at the v2 offset of nprobes */ +#define BRCMF_SCAN_PARAMS_V4_EXT_OFFSET 52 /* version of brcmf_scan_params structure */ #define BRCMF_SCAN_PARAMS_VERSION_V2 2 @@ -72,6 +78,8 @@ #define DOT11_BSSTYPE_ANY 2 #define BRCMF_ESCAN_REQ_VERSION 1 #define BRCMF_ESCAN_REQ_VERSION_V2 2 +#define BRCMF_ESCAN_REQ_VERSION_V3 3 +#define BRCMF_ESCAN_REQ_VERSION_V4 4 #define BRCMF_MAXRATES_IN_SET 16 /* max # of rates in rateset */ diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index cefa63de17..93eebe6ceb 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -290,6 +290,9 @@ struct brcmf_msgbuf { u16 ioctl_seq_no; u32 reqid; u32 h2d_seqnum[BRCMF_NROF_H2D_COMMON_MSGRINGS]; + /* D2H sync (bcmdhd dhd_prot_d2h_sync_*()): mode, and next epochs */ + u32 d2h_sync; + u32 d2h_seqnum[BRCMF_NROF_COMMON_MSGRINGS]; wait_queue_head_t ioctl_resp_wait; bool ctl_completed; @@ -317,6 +320,8 @@ struct brcmf_msgbuf_pktid { struct brcmf_msgbuf_pktids { u32 array_size; u32 last_allocated_idx; + /* IDs 1 to nr_ctrl: the ioctl response and event buffers only */ + u32 nr_ctrl; enum dma_data_direction direction; struct brcmf_msgbuf_pktid *array; }; @@ -361,10 +366,10 @@ static int brcmf_msgbuf_alloc_pktid(struct device *dev, struct brcmf_msgbuf_pktids *pktids, struct sk_buff *skb, u16 data_offset, - dma_addr_t *physaddr, u32 *idx) + dma_addr_t *physaddr, u32 *idx, bool ctrl) { struct brcmf_msgbuf_pktid *array; - u32 count; + u32 first, end, count; array = pktids->array; @@ -376,21 +381,30 @@ brcmf_msgbuf_alloc_pktid(struct device *dev, return -ENOMEM; } - *idx = pktids->last_allocated_idx; + /* + * Packet ID 0 means "no packet" to the firmware: never hand it out. + * Control buffers get the lowest IDs: Broadcom's driver numbers them + * in a map of their own (1024 IDs), and a firmware that checks them + * against that traps on a larger one ("Invalid pktid"). + */ + first = ctrl ? 1 : pktids->nr_ctrl + 1; + end = ctrl ? pktids->nr_ctrl + 1 : pktids->array_size; + *idx = ctrl ? end - 1 : pktids->last_allocated_idx; + if (*idx < first || *idx >= end) + *idx = end - 1; - /* Packet ID 0 means "no packet" to the firmware: never hand it out. */ - count = 1; + count = 0; do { (*idx)++; - if (*idx == pktids->array_size) - *idx = 1; + if (*idx >= end) + *idx = first; if (array[*idx].allocated.counter == 0) if (atomic_cmpxchg(&array[*idx].allocated, 0, 1) == 0) break; count++; - } while (count < pktids->array_size); + } while (count < end - first); - if (count == pktids->array_size) { + if (count == end - first) { dma_unmap_single(dev, *physaddr, skb->len - data_offset, pktids->direction); return -ENOMEM; @@ -400,7 +414,8 @@ brcmf_msgbuf_alloc_pktid(struct device *dev, array[*idx].physaddr = *physaddr; array[*idx].skb = skb; - pktids->last_allocated_idx = *idx; + if (!ctrl) + pktids->last_allocated_idx = *idx; return 0; } @@ -856,7 +871,7 @@ static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u16 flowid) if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->tx_pktids, skb, sfh ? 0 : ETH_HLEN, - &physaddr, &pktid)) { + &physaddr, &pktid, false)) { if (sfh) brcmf_msgbuf_sfh_llc_remove(skb); brcmf_flowring_reinsert(flow, flowid, skb); @@ -1093,7 +1108,7 @@ static u32 brcmf_msgbuf_rxbuf_data_post(struct brcmf_msgbuf *msgbuf, u32 count) pktlen = skb->len; if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->rx_pktids, skb, 0, - &physaddr, &pktid)) { + &physaddr, &pktid, false)) { dev_kfree_skb_any(skb); bphy_err(drvr, "No PKTID available !!\n"); brcmf_commonring_write_cancel(commonring, alloced - i); @@ -1205,7 +1220,7 @@ brcmf_msgbuf_rxbuf_ctrl_post(struct brcmf_msgbuf *msgbuf, bool event_buf, pktlen = skb->len; if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, msgbuf->rx_pktids, skb, 0, - &physaddr, &pktid)) { + &physaddr, &pktid, true)) { dev_kfree_skb_any(skb); bphy_err(drvr, "No PKTID available !!\n"); brcmf_commonring_write_cancel(commonring, alloced - i); @@ -1509,9 +1524,55 @@ static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) } -static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, - struct brcmf_commonring *commonring) +#define BRCMF_MSGBUF_D2H_EPOCH_MODULO 253 +#define BRCMF_MSGBUF_D2H_EPOCH_INIT 254 +#define BRCMF_MSGBUF_D2H_SYNC_SEQNUM 0x20000 +#define BRCMF_MSGBUF_D2H_SYNC_XORCSUM 0x40000 +#define BRCMF_MSGBUF_D2H_SYNC_TRIES 512 +#define BRCMF_MSGBUF_D2H_SYNC_STEPS 5 + +/* + * With DMA'd ring indices the firmware can publish a completion's index + * before the item itself has landed in host memory. Firmware that asks for + * D2H sync stamps each item with a sequence number (its epoch) and, in + * XORCSUM mode, a checksum making the XOR of the item's words zero; the + * host waits for both before reading the item, as Broadcom's driver does + * (dhd_prot_d2h_sync_seqnum() and dhd_prot_d2h_sync_xorcsum()). An item + * that never completes is skipped, as there. + */ +static bool brcmf_msgbuf_d2h_sync(struct brcmf_msgbuf *msgbuf, u32 ringid, + void *item, u16 len) +{ + u8 want = msgbuf->d2h_seqnum[ringid] % BRCMF_MSGBUF_D2H_EPOCH_MODULO; + struct msgbuf_common_hdr *hdr = item; + u32 step, tries, csum, i; + + for (step = 1; step <= BRCMF_MSGBUF_D2H_SYNC_STEPS; step++) { + for (tries = 0; tries < BRCMF_MSGBUF_D2H_SYNC_TRIES; tries++) { + if (READ_ONCE(hdr->rsvd0) == want) { + csum = 0; + if (msgbuf->d2h_sync & BRCMF_MSGBUF_D2H_SYNC_XORCSUM) + for (i = 0; i < len / 4; i++) + csum ^= READ_ONCE(((u32 *)item)[i]); + if (!csum) { + msgbuf->d2h_seqnum[ringid]++; + dma_rmb(); + return true; + } + } + udelay(step); + } + } + + brcmf_err("D2H ring %u: item never completed (epoch %u, want %u)\n", + ringid, READ_ONCE(hdr->rsvd0), want); + msgbuf->d2h_seqnum[ringid]++; + return false; +} + +static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, u32 ringid) { + struct brcmf_commonring *commonring = msgbuf->commonrings[ringid]; void *buf; u16 count; u16 processed; @@ -1523,8 +1584,11 @@ static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, processed = 0; while (count) { - brcmf_msgbuf_process_msgtype(msgbuf, - buf + msgbuf->rx_dataoffset); + if (!msgbuf->d2h_sync || + brcmf_msgbuf_d2h_sync(msgbuf, ringid, buf, + brcmf_commonring_len_item(commonring))) + brcmf_msgbuf_process_msgtype(msgbuf, + buf + msgbuf->rx_dataoffset); buf += brcmf_commonring_len_item(commonring); processed++; if (processed == BRCMF_MSGBUF_UPDATE_RX_PTR_THRS) { @@ -1580,7 +1644,6 @@ int brcmf_proto_msgbuf_rx_trigger(struct device *dev) struct brcmf_pub *drvr = bus_if->drvr; struct brcmf_msgbuf *msgbuf; struct brcmf_commonring *commonring; - void *buf; u32 flowid; int qlen; @@ -1588,12 +1651,9 @@ int brcmf_proto_msgbuf_rx_trigger(struct device *dev) return -ENODEV; msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_RX_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_TX_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); - buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_CONTROL_COMPLETE]; - brcmf_msgbuf_process_rx(msgbuf, buf); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_RX_COMPLETE); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_TX_COMPLETE); + brcmf_msgbuf_process_rx(msgbuf, BRCMF_D2H_MSGRING_CONTROL_COMPLETE); for_each_set_bit(flowid, msgbuf->txstatus_done_map, msgbuf->max_flowrings) { @@ -1813,6 +1873,14 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) goto fail; msgbuf->rx_dataoffset = if_msgbuf->rx_dataoffset; + msgbuf->d2h_sync = if_msgbuf->d2h_sync; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_CONTROL_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_TX_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + msgbuf->d2h_seqnum[BRCMF_D2H_MSGRING_RX_COMPLETE] = + BRCMF_MSGBUF_D2H_EPOCH_INIT; + brcmf_dbg(MSGBUF, "D2H sync mode 0x%x\n", msgbuf->d2h_sync); msgbuf->max_ioctlrespbuf = BRCMF_MSGBUF_MAX_IOCTLRESPBUF_POST; msgbuf->max_eventbuf = BRCMF_MSGBUF_MAX_EVENTBUF_POST; @@ -1822,8 +1890,8 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) */ msgbuf->max_rxbufpost = min_t(u32, if_msgbuf->max_rxbufpost, NR_RX_PKTIDS - 1 - - msgbuf->max_ioctlrespbuf - - msgbuf->max_eventbuf); + 2 * (msgbuf->max_ioctlrespbuf + + msgbuf->max_eventbuf)); msgbuf->tx_pktids = brcmf_msgbuf_init_pktids(NR_TX_PKTIDS, DMA_TO_DEVICE); @@ -1833,6 +1901,9 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) DMA_FROM_DEVICE); if (!msgbuf->rx_pktids) goto fail; + /* Twice the control buffers: each is reposted before it is freed */ + msgbuf->rx_pktids->nr_ctrl = 2 * (msgbuf->max_ioctlrespbuf + + msgbuf->max_eventbuf); msgbuf->flow = brcmf_flowring_attach(drvr->bus_if->dev, if_msgbuf->max_flowrings); diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 5e3aed4ae8..f53ded28ba 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -74,6 +74,10 @@ BRCMF_FW_CLM_DEF(4378B1, "brcmfmac4378b1-pcie"); BRCMF_FW_CLM_DEF(4378B3, "brcmfmac4378b3-pcie"); BRCMF_FW_CLM_DEF(4387C2, "brcmfmac4387c2-pcie"); BRCMF_FW_CLM_DEF(4389C1, "brcmfmac4389c1-pcie"); +/* BCM4383 rev 2 (Pixel 9a): the owner's firmware set, with CLM and TXCAP blobs */ +BRCMF_FW_CLM_DEF(4383, "brcmfmac4383-pcie"); +/* BCM4398 rev 3, d0 (Pixel 8 Pro): the owner's firmware set */ +BRCMF_FW_CLM_DEF(4398D0, "brcmfmac4398d0-pcie"); BRCMF_FW_CLM_DEF(54591, "brcmfmac54591-pcie"); /* firmware config files */ @@ -116,6 +120,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { BRCMF_FW_ENTRY(BRCM_CC_4378_CHIP_ID, 0xFFFFFFE0, 4378B3), /* revision ID 5 */ BRCMF_FW_ENTRY(BRCM_CC_4387_CHIP_ID, 0xFFFFFFFF, 4387C2), /* revision ID 7 */ BRCMF_FW_ENTRY(BRCM_CC_4389_CHIP_ID, 0xFFFFFFFF, 4389C1), + BRCMF_FW_ENTRY(BRCM_CC_4383_CHIP_ID, 0xFFFFFFFF, 4383), + BRCMF_FW_ENTRY(BRCM_CC_4398_CHIP_ID, 0xFFFFFFF8, 4398D0), }; #define BRCMF_PCIE_FW_UP_TIMEOUT 5000 /* msec */ @@ -166,6 +172,8 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_PCIE_SRPWR_DMN1_ARMBP BIT(1) #define BRCMF_PCIE_SRPWR_DMN2_MACAUX BIT(2) #define BRCMF_PCIE_SRPWR_DMN3_MACMAIN BIT(3) +#define BRCMF_PCIE_SRPWR_DMN4_MACSCAN BIT(4) +#define BRCMF_PCIE_SRPWR_DMN6_SAQM BIT(6) #define BRCMF_PCIE_SRPWR_DMN_ALL (BRCMF_PCIE_SRPWR_DMN0_PCIE | \ BRCMF_PCIE_SRPWR_DMN1_ARMBP | \ BRCMF_PCIE_SRPWR_DMN2_MACAUX | \ @@ -239,10 +247,13 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { BRCMF_PCIE_64_MB_INT_D2H7_DB1) #define BRCMF_PCIE_SHARED_VERSION_7 7 +#define BRCMF_PCIE_SHARED_VERSION_9 9 #define BRCMF_PCIE_MIN_SHARED_VERSION 5 -#define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_7 +#define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_9 #define BRCMF_PCIE_SHARED_VERSION_MASK 0x00FF #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000 +#define BRCMF_PCIE_SHARED_D2H_SYNC_SEQNUM 0x20000 +#define BRCMF_PCIE_SHARED_D2H_SYNC_XORCSUM 0x40000 #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000 #define BRCMF_PCIE_SHARED_USE_MAILBOX 0x2000000 #define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000 @@ -264,6 +275,12 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = { #define BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET 68 /* shared area revision >= 6: host capabilities, read by the firmware */ #define BRCMF_SHARED_HOST_CAP_OFFSET 84 +#define BRCMF_SHARED_EWP_INFO_ADDR_OFFSET 128 +#define BRCMF_SHARED_AGGR_HOST_CAP_OFFSET 133 +#define BRCMF_SHARED_VERSION_9_SIZE 140 + +#define BRCMF_EWP_INFO_VERSION 1 +#define BRCMF_EWP_INIT_END 2 #define BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY 0x00000400 #define BRCMF_HOSTCAP_DS_NO_OOB_DW 0x00001000 @@ -833,22 +850,48 @@ brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid) /* - * Chips with several backplane power domains (the BCM4389 here) power the + * The BCM4389 and the BCM4398 after it are reset, told the host is ready and + * serviced the way Broadcom's driver does for its multi-backplane chips. + */ +static bool brcmf_pcie_is_4389_family(struct brcmf_pciedev_info *devinfo) +{ + return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID || + devinfo->pdev->device == BRCM_PCIE_4398_DEVICE_ID; +} + +/* + * Chips with several backplane power domains (the BCM4389 and BCM4398) power the * ARM/backplane and MAC domains down unless the host asks for them, and * a chip reset drops the host's requests. Backplane accesses to a domain * that is off fault, and read back as 0xffffffff. */ +static u32 brcmf_pcie_srpwr_domains(struct brcmf_pciedev_info *devinfo) +{ + switch (devinfo->pdev->device) { + case BRCM_PCIE_4389_DEVICE_ID: + return BRCMF_PCIE_SRPWR_DMN_ALL; + case BRCM_PCIE_4398_DEVICE_ID: + /* and the scan MAC and SAQM domains (si_srpwr_domain_all_mask()) */ + return BRCMF_PCIE_SRPWR_DMN_ALL | BRCMF_PCIE_SRPWR_DMN4_MACSCAN | + BRCMF_PCIE_SRPWR_DMN6_SAQM; + default: + return 0; + } +} + static bool brcmf_pcie_has_srpwr(struct brcmf_pciedev_info *devinfo) { - return devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID; + return brcmf_pcie_srpwr_domains(devinfo); } static void brcmf_pcie_srpwr_request(struct brcmf_pciedev_info *devinfo) { u32 reg = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + BRCMF_PCIE_PCIE2REG_POWERCTL; - u32 req = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_REQON_SHIFT; - u32 up = BRCMF_PCIE_SRPWR_DMN_ALL << BRCMF_PCIE_SRPWR_STATUS_SHIFT; + u32 req = brcmf_pcie_srpwr_domains(devinfo) << + BRCMF_PCIE_SRPWR_REQON_SHIFT; + u32 up = brcmf_pcie_srpwr_domains(devinfo) << + BRCMF_PCIE_SRPWR_STATUS_SHIFT; u32 dar = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + BRCMF_PCIE_64_PCIE2REG_DAR_POWERCTL; u32 val; @@ -905,6 +948,19 @@ static void brcmf_pcie_set_bar_coherent(struct brcmf_pciedev_info *devinfo) */ #define BRCMF_PCIE_SSCTRL_SSRESET_STATUS BIT(13) +/* + * Chips Broadcom's driver resets with a function 0 FLR rather than the + * chipcommon watchdog (bcmdhd dhdpcie_dongle_reset(), cc_wd_reset false). + * The BCM4383 shares the chip with its Bluetooth: while BT_REG_ON holds the + * chip up, the watchdog reset leaves the WLAN cores in a state where the + * downloaded firmware never comes up, and an F0 FLR leaves Bluetooth alone. + */ +static bool brcmf_pcie_reset_by_flr(struct brcmf_pciedev_info *devinfo) +{ + return brcmf_pcie_is_4389_family(devinfo) || + devinfo->pdev->device == BRCM_PCIE_4383_DEVICE_ID; +} + static int brcmf_pcie_flr(struct brcmf_pciedev_info *devinfo) { struct pci_dev *pdev = devinfo->pdev; @@ -971,13 +1027,13 @@ static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo) val); /* Watchdog reset, with all power domains up as it starts. The - * BCM4389 is reset the way Broadcom's driver resets it, with an - * FLR: after a chipcommon watchdog reset its ARM does not boot a - * second firmware download. + * BCM4389 and BCM4383 are reset the way Broadcom's driver resets + * them, with an FLR: after a chipcommon watchdog reset the BCM4389's + * ARM does not boot a second firmware download, and the BCM4383's + * doesn't while its Bluetooth is on. */ brcmf_pcie_srpwr_request(devinfo); - if (devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID || - brcmf_pcie_flr(devinfo)) { + if (!brcmf_pcie_reset_by_flr(devinfo) || brcmf_pcie_flr(devinfo)) { brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); WRITECC32(devinfo, watchdog, 4); msleep(100); @@ -1216,6 +1272,14 @@ static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo, return; addr = console->base_addr + BRCMF_CONSOLE_WRITEIDX_OFFSET; newidx = brcmf_pcie_read_tcm32(devinfo, addr); + if (newidx >= console->bufsize) { + /* A dead link reads all ones, and read_idx wraps at bufsize, + * so the loop below would never meet it. + */ + brcmf_err(bus, "console write index %u out of range (%u)\n", + newidx, console->bufsize); + return; + } while (newidx != console->read_idx) { addr = console->buf_addr + console->read_idx; ch = brcmf_pcie_read_tcm8(devinfo, addr); @@ -1258,6 +1322,14 @@ static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo) devinfo->reginfo->int_fn0); } +/* API9 firmware defers TX allocation until host ready, as does BCM4389. */ +static bool +brcmf_pcie_early_hostready(struct brcmf_pciedev_info *devinfo) +{ + return brcmf_pcie_is_4389_family(devinfo) || + devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9; +} + static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo) { if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) { @@ -1266,8 +1338,7 @@ static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo) /* bcmdhd dhd_bus_hostready() writes this value */ brcmf_pcie_write_reg32(devinfo, devinfo->reginfo->h2d_mailbox_1, - devinfo->pdev->device == - BRCM_PCIE_4389_DEVICE_ID ? + brcmf_pcie_is_4389_family(devinfo) ? 0x12345678 : 1); } } @@ -1373,7 +1444,7 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg) * (dhd_bus_handle_intx_ahead_dma_indices()). */ if (devinfo->dma_idx_sz && - devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + brcmf_pcie_is_4389_family(devinfo) && devinfo->state == BRCMFMAC_PCIE_STATE_UP) { usleep_range(500, 1000); brcmf_pcie_rx_process(devinfo); @@ -1640,6 +1711,56 @@ static void brcmf_pcie_release_ringbuffers(struct brcmf_pciedev_info *devinfo) } +static bool +brcmf_pcie_valid_ram_range(struct brcmf_pciedev_info *devinfo, u32 addr, + u32 len) +{ + u64 end = (u64)addr + len; + + return len && addr >= devinfo->ci->rambase && end <= BIT_ULL(32) && + end <= (u64)devinfo->ci->rambase + devinfo->ci->ramsize; +} + +/* API9 must describe every ring and its fallback TCM indices in RAM. */ +static bool +brcmf_pcie_api9_valid_ringinfo(struct brcmf_pciedev_info *devinfo, + const struct brcmf_pcie_dhi_ringinfo *ringinfo) +{ + u32 h2d = le16_to_cpu(ringinfo->max_submissionrings); + u32 d2h = le16_to_cpu(ringinfo->max_completionrings); + u32 flows = le16_to_cpu(ringinfo->max_flowrings); + u32 ptrs[] = { + le32_to_cpu(ringinfo->h2d_w_idx_ptr), + le32_to_cpu(ringinfo->h2d_r_idx_ptr), + le32_to_cpu(ringinfo->d2h_w_idx_ptr), + le32_to_cpu(ringinfo->d2h_r_idx_ptr), + }; + u32 ringmem = le32_to_cpu(ringinfo->ringmem); + u32 count; + u32 i; + + if (!flows || flows > 512 || + h2d < flows + BRCMF_NROF_H2D_COMMON_MSGRINGS || + d2h < BRCMF_NROF_D2H_COMMON_MSGRINGS) + return false; + if (ringmem & 3 || + !brcmf_pcie_valid_ram_range(devinfo, ringmem, + BRCMF_NROF_COMMON_MSGRINGS * + BRCMF_RING_MEM_SZ)) + return false; + + /* Allocation failure falls back to four-byte-spaced TCM indices. */ + for (i = 0; i < ARRAY_SIZE(ptrs); i++) { + count = i < 2 ? h2d : d2h; + if (ptrs[i] & 3 || + !brcmf_pcie_valid_ram_range(devinfo, ptrs[i], + count * sizeof(u32))) + return false; + } + + return true; +} + static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) { struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); @@ -1659,8 +1780,18 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo) u16 max_submissionrings; u16 max_completionrings; + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9 && + (devinfo->shared.ring_info_addr & 3 || + !brcmf_pcie_valid_ram_range(devinfo, + devinfo->shared.ring_info_addr, + sizeof(ringinfo)))) + return -EINVAL; + brcmf_pcie_copy_dev_tomem(devinfo, devinfo->shared.ring_info_addr, &ringinfo, sizeof(ringinfo)); + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9 && + !brcmf_pcie_api9_valid_ringinfo(devinfo, &ringinfo)) + return -EINVAL; if (devinfo->shared.version >= 6) { max_submissionrings = le16_to_cpu(ringinfo.max_submissionrings); max_flowrings = le16_to_cpu(ringinfo.max_flowrings); @@ -1855,6 +1986,7 @@ static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); u64 address; u32 addr; + u8 aggr_cap = 0; devinfo->shared.scratch = dma_alloc_coherent(&devinfo->pdev->dev, @@ -1873,7 +2005,14 @@ static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo) BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET; brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN); - if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) { + if (brcmf_pcie_early_hostready(devinfo)) { + /* API9 uses the legacy ring-update slots for host SCB offload. */ + if (devinfo->shared.version == BRCMF_PCIE_SHARED_VERSION_9) { + addr = devinfo->shared.tcm_base_address + + BRCMF_SHARED_AGGR_HOST_CAP_OFFSET; + brcmf_pcie_copy_mem_todev(devinfo, addr, &aggr_cap, + sizeof(aggr_cap)); + } brcmf_pcie_set_host_cap(devinfo); return 0; } @@ -1920,11 +2059,8 @@ static int brcmf_pcie_preinit(struct device *dev) brcmf_dbg(PCIE, "Enter\n"); brcmf_pcie_intr_enable(buspub->devinfo); - /* The BCM4389 was told host ready right after its rings were set - * up; its firmware traps on a second one (_hnd_die from - * pciedev_handle_hostready_intr), so ring it only once. - */ - if (buspub->devinfo->pdev->device != BRCM_PCIE_4389_DEVICE_ID) + /* The early path already notified firmware after setting up the rings. */ + if (!brcmf_pcie_early_hostready(buspub->devinfo)) brcmf_pcie_hostready(buspub->devinfo); return 0; @@ -2092,6 +2228,30 @@ brcmf_pcie_adjust_ramsize(struct brcmf_pciedev_info *devinfo, u8 *data, } +/* Check firmware's EWP initialization result before setting up host DMA. */ +static int brcmf_pcie_api9_ready(struct brcmf_pciedev_info *devinfo) +{ + u32 addr = devinfo->shared.tcm_base_address; + u32 ewp; + + if (!(devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1)) + return -EOPNOTSUPP; + if (!brcmf_pcie_valid_ram_range(devinfo, addr, + BRCMF_SHARED_VERSION_9_SIZE)) + return -EINVAL; + + ewp = brcmf_pcie_read_tcm32(devinfo, + addr + BRCMF_SHARED_EWP_INFO_ADDR_OFFSET); + if (!ewp || ewp & 3 || !brcmf_pcie_valid_ram_range(devinfo, ewp, 2)) + return -EINVAL; + if (brcmf_pcie_read_tcm8(devinfo, ewp) != BRCMF_EWP_INFO_VERSION) + return -EPROTONOSUPPORT; + if (brcmf_pcie_read_tcm8(devinfo, ewp + 1) != BRCMF_EWP_INIT_END) + return -EIO; + + return 0; +} + static int brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, u32 sharedram_addr) @@ -2099,10 +2259,16 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, struct brcmf_bus *bus = dev_get_drvdata(&devinfo->pdev->dev); struct brcmf_pcie_shared_info *shared; u32 addr; + int ret; shared = &devinfo->shared; shared->tcm_base_address = sharedram_addr; + /* The version is unknown until this first bounded metadata read. */ + if (sharedram_addr & 3 || + !brcmf_pcie_valid_ram_range(devinfo, sharedram_addr, sizeof(u32))) + return -EINVAL; + shared->flags = brcmf_pcie_read_tcm32(devinfo, sharedram_addr); shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK); brcmf_dbg(PCIE, "shared flags 0x%08x\n", shared->flags); @@ -2123,7 +2289,7 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, * The BCM4389 firmware does not, and ignores the DAR doorbells. */ if (devinfo->reginfo == &brcmf_reginfo_64 && - devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID && + brcmf_pcie_early_hostready(devinfo) && !(shared->flags & BRCMF_PCIE_SHARED_DAR)) { devinfo->reginfo = &brcmf_reginfo_64_nodar; brcmf_dbg(PCIE, "no DAR: doorbells at 0x%x/0x%x\n", @@ -2132,12 +2298,22 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo, } brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version); if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) || - (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) { + (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION) || + shared->version == 8) { brcmf_err(bus, "Unsupported PCIE version %d\n", shared->version); return -EINVAL; } + if (shared->version == BRCMF_PCIE_SHARED_VERSION_9) { + ret = brcmf_pcie_api9_ready(devinfo); + if (ret) { + brcmf_err(bus, "API9 firmware initialization failed: %d\n", + ret); + return ret; + } + } + /* check firmware support dma indicies */ if (shared->flags & BRCMF_PCIE_SHARED_DMA_INDEX) { if (shared->flags & BRCMF_PCIE_SHARED_DMA_2B_IDX) @@ -2190,6 +2366,43 @@ brcmf_pcie_provide_random_bytes(struct brcmf_pciedev_info *devinfo, u32 address) BRCMF_RANDOM_SEED_LENGTH); } +/* + * Before the host lets go of firmware that supports it, Broadcom's driver + * makes it trap on purpose by writing a magic number to the PCIe core's + * H2D doorbell 1 of function 3 ("DB7"): in its trap handler the firmware + * holds the chip's power resources high, which a new firmware needs to boot. + * Without it the always-on domain keeps the old firmware's PMU state across + * WL_REG_ON and an FLR, and a second download never starts + * (dhd_pcie.c dhdpcie_fw_trap(), DHD_DONGLE_TRAP_IN_DETACH). + */ +#define BRCMF_SHARED_FLAGS2_OFFSET 80 +#define BRCMF_PCIE_SHARED2_TRAP_ON_HOST_DB7 0x00040000 +#define BRCMF_PCIE_PCIE2REG_H2D3_DOORBELL1 0x174 +#define BRCMF_PCIE_DB7_MAGIC_DPC_TRAP 0xdead0002 +#define BRCMF_PCIE_DB7_TRAP_WAIT_MS 100 + +static void brcmf_pcie_db7_trap(struct brcmf_pciedev_info *devinfo) +{ + u32 flags2; + + if (devinfo->pdev->device != BRCM_PCIE_4398_DEVICE_ID || + !devinfo->shared.tcm_base_address) + return; + + flags2 = brcmf_pcie_read_tcm32(devinfo, + devinfo->shared.tcm_base_address + + BRCMF_SHARED_FLAGS2_OFFSET); + if (flags2 == 0xffffffff || + !(flags2 & BRCMF_PCIE_SHARED2_TRAP_ON_HOST_DB7)) + return; + + brcmf_dbg(PCIE, "DB7 trap before release\n"); + brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + BRCMF_PCIE_PCIE2REG_H2D3_DOORBELL1, + BRCMF_PCIE_DB7_MAGIC_DPC_TRAP); + msleep(BRCMF_PCIE_DB7_TRAP_WAIT_MS); +} + static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, const struct firmware *fw, void *nvram, u32 nvram_len) @@ -2261,6 +2474,37 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo, brcmf_dbg(PCIE, "Wait for FW init\n"); sharedram_addr = sharedram_addr_written; loop_counter = BRCMF_PCIE_FW_UP_TIMEOUT / 50; + /* + * The BCM4398's firmware writes an interim address to the last word + * of RAM before the real one, and signals the end of its boot with a + * mailbox interrupt, which Google's driver waits for (dhd_pcie.c + * dhdpcie_wait_readshared_area_addr(), "boot intr"). Interrupts are + * not set up yet, so poll for it. + */ + if (devinfo->pdev->device == BRCM_PCIE_4398_DEVICE_ID) { + u32 mbint = BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + devinfo->reginfo->mailboxint; + u32 intstatus = 0; + + brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); + while (loop_counter) { + intstatus = brcmf_pcie_read_reg32(devinfo, mbint); + if (intstatus && intstatus != 0xffffffff) + break; + msleep(50); + loop_counter--; + } + brcmf_dbg(PCIE, "boot interrupt %#x after %u ms\n", intstatus, + (BRCMF_PCIE_FW_UP_TIMEOUT / 50 - loop_counter) * 50); + if (intstatus && intstatus != 0xffffffff) + brcmf_pcie_write_reg32(devinfo, + BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET + + devinfo->reginfo->mailboxint, + intstatus); + sharedram_addr = brcmf_pcie_read_ram32(devinfo, + devinfo->ci->ramsize - + 4); + } while ((sharedram_addr == sharedram_addr_written) && (loop_counter)) { msleep(50); sharedram_addr = brcmf_pcie_read_ram32(devinfo, @@ -2723,14 +2967,10 @@ static void brcmf_pcie_setup(struct device *dev, int ret, ret = brcmf_pcie_request_irq(devinfo); if (ret) goto fail; - devinfo->poll_enabled = devinfo->pdev->device == - BRCM_PCIE_4389_DEVICE_ID; + devinfo->poll_enabled = brcmf_pcie_is_4389_family(devinfo); - /* Broadcom's driver rings host ready as soon as the common rings - * are set up, before it posts any buffer (bcmdhd dhd_prot_init(), - * hostrdy_after_init), and the BCM4389 was told so in host_cap. - */ - if (devinfo->pdev->device == BRCM_PCIE_4389_DEVICE_ID) + /* Notify early firmware before its deferred TX-buffer allocation. */ + if (brcmf_pcie_early_hostready(devinfo)) brcmf_pcie_hostready(devinfo); /* hook the commonrings in the bus structure. */ @@ -2748,6 +2988,9 @@ static void brcmf_pcie_setup(struct device *dev, int ret, bus->msgbuf->rx_dataoffset = devinfo->shared.rx_dataoffset; bus->msgbuf->max_rxbufpost = devinfo->shared.max_rxbufpost; + bus->msgbuf->d2h_sync = devinfo->shared.flags & + (BRCMF_PCIE_SHARED_D2H_SYNC_SEQNUM | + BRCMF_PCIE_SHARED_D2H_SYNC_XORCSUM); bus->msgbuf->max_flowrings = devinfo->shared.max_flowrings; init_waitqueue_head(&devinfo->mbdata_resp_wait); @@ -3174,6 +3417,7 @@ brcmf_pcie_remove(struct pci_dev *pdev) kfree(bus->msgbuf); kfree(bus); + brcmf_pcie_db7_trap(devinfo); brcmf_pcie_release_irq(devinfo); brcmf_pcie_release_scratchbuffers(devinfo); brcmf_pcie_release_ringbuffers(devinfo); @@ -3398,6 +3642,8 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { BRCMF_PCIE_DEVICE(BRCM_PCIE_4378_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4387_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_4389_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4383_DEVICE_ID, WCC_SEED), + BRCMF_PCIE_DEVICE(BRCM_PCIE_4398_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(BRCM_PCIE_43752_DEVICE_ID, WCC_SEED), BRCMF_PCIE_DEVICE(CY_PCIE_54591_DEVICE_ID, CYW), { /* end: all zeroes */ } diff --git a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h index bcb68ae6b1..c453d6d0f2 100644 --- a/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h +++ b/drivers/net/wireless/broadcom/brcm80211/include/brcm_hw_ids.h @@ -56,6 +56,8 @@ #define BRCM_CC_43752_CHIP_ID 43752 #define BRCM_CC_4377_CHIP_ID 0x4377 #define BRCM_CC_4378_CHIP_ID 0x4378 +#define BRCM_CC_4383_CHIP_ID 0x4383 +#define BRCM_CC_4398_CHIP_ID 0x4398 #define BRCM_CC_4387_CHIP_ID 0x4387 #define BRCM_CC_4389_CHIP_ID 0x4389 #define CY_CC_4373_CHIP_ID 0x4373 @@ -99,6 +101,8 @@ #define BRCM_PCIE_43752_DEVICE_ID 0x449d #define BRCM_PCIE_4377_DEVICE_ID 0x4488 #define BRCM_PCIE_4378_DEVICE_ID 0x4425 +#define BRCM_PCIE_4383_DEVICE_ID 0x4449 +#define BRCM_PCIE_4398_DEVICE_ID 0x4444 #define BRCM_PCIE_4387_DEVICE_ID 0x4433 #define BRCM_PCIE_4389_DEVICE_ID 0x4441 #define CY_PCIE_54591_DEVICE_ID 0x4417 diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index 31de17d0e3..f5226c8db0 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -404,17 +404,19 @@ config PCI_EXYNOS functions to implement the driver. config PCIE_GS201_CP - tristate "Google gs201 PCIe for the modem (bring-up)" + tristate "Google gs201 and zumapro PCIe for the modem (bring-up)" depends on ARCH_EXYNOS || COMPILE_TEST depends on OF && PCI_MSI && HAVE_ARM_SMCCC select PCIE_DW select EXYNOS_PMU select MFD_SYSCON help - Bring-up driver for PCIe GEN4A_0 of Google's gs201 (Tensor G2), the - link to the Samsung S5300 modem. It powers the modem through its - control lines and trains the link one debugfs step at a time, for - testing on a bench; it does not register a PCI host yet. + Bring-up driver for the link to the Samsung S5300 modem: PCIe + GEN4A_0 of Google's gs201 (Tensor G2, Pixel 7) and GEN3A_0 of + zumapro (Tensor G4, Pixel 9a), whose two-lane PHY is driven by + PHY_ZUMA_PCIE. It powers the modem through its control lines and + trains the link one debugfs step at a time, for testing on a + bench, or on request of the modem driver (EXYNOS_MODEM_IF). config PCIE_GS201 tristate "Google gs201 PCIe controller (host mode)" @@ -424,9 +426,10 @@ config PCIE_GS201 select PCI_PWRCTRL_GENERIC help Say Y here to enable support for the PCIe controller of the Google - gs201 (Tensor G2) SoC in host mode. Pixel 7 phones connect their - Wi-Fi chip to it. The controller uses the DesignWare core plus a - Samsung wrapper, and needs the gs201 PCIe PHY driver. + gs201 (Tensor G2) and zuma (Tensor G3) SoCs in host mode. Pixel 7 + and Pixel 8 phones connect their Wi-Fi chip to it. The controller + uses the DesignWare core plus a Samsung wrapper, and needs the gs201 + or zuma PCIe PHY driver. config PCIE_GS201_SYSMMU tristate "Google gs201 PCIe System MMU as a DMA window" diff --git a/drivers/pci/controller/dwc/pcie-gs201-cp.c b/drivers/pci/controller/dwc/pcie-gs201-cp.c index 7990508fb0..1d1cacce4f 100644 --- a/drivers/pci/controller/dwc/pcie-gs201-cp.c +++ b/drivers/pci/controller/dwc/pcie-gs201-cp.c @@ -36,7 +36,8 @@ * it is disabled, the modem driver owns the lines) * link_up PHY out of isolation, PHY and controller setup, PERST# * release, LTSSM, wait for L0 (Gen1 unless "link_up 3") - * atu the secure-ATU SMC (config and memory windows) + * atu the secure-ATU SMC (config and memory windows); on zumapro + * the host's own iATU * id read the endpoint's vendor/device ID through the config window * bus register the PCI host bridge and scan it (first time), with * the DWC MSI controller aimed at the modem's MSI page; after @@ -56,6 +57,28 @@ * The "status" file only reads GPIO levels and the PMU isolation bit, plus * controller registers once the PHY is out of isolation (an ELBI access * while it is isolated hangs the SoC, as found on the Wi-Fi link). + * + * zumapro (Tensor G4, "google,zumapro-pcie-cp") connects the Pixel 9a's + * S5300 through HSI1 GEN3A_0, the zuma family's root complex, with the + * two-lane PHY of phy-zuma-pcie. Its steps follow Google's GPL driver for + * the zuma family (google-modules/soc/gs/drivers/pci/controller/dwc/ + * pcie-exynos-rc.c: exynos_pcie_rc_poweron(), _establish_link(), + * _poweroff(), _rd_other_conf() and _prog_viewport_*()), and differ from + * gs201's in these places: + * - RC mode, the soft power reset and the slave NAK are written before + * the PHY is configured (zuma's CAL does them inside its PHY + * configuration, which the PHY driver leaves to the host), and the PHY + * is calibrated, its PLL and bias held on, once the link has trained; + * - APP_XFER_PENDING is raised from training to the end of link_up and + * around each read of the endpoint's configuration space; + * - the port logic is set for two lanes; + * - the PHY leaves isolation at the first link_up and stays out, as + * stock's node has no use-phy-isol-en: link_down powers it down, and + * its power_off returns its input clock to the oscillator first, so + * that ELBI is clocked until the next power_on; + * - no secure-ATU SMC: the host programs the unrolled outbound iATU; + * - I/O coherency only when samsung,sysreg is given. + * * Copyright (C) 2021 Samsung Electronics Co., Ltd. (sequences) */ @@ -76,6 +99,7 @@ #include #include #include +#include #include #include #include @@ -126,6 +150,9 @@ MODULE_PARM_DESC(watch_lines, "Log every edge on the modem's cp2ap lines, with i #define CP_ELBI_L1_REQ_NAK_MASTER BIT(4) #define CP_ELBI_MSTR_PEND_SEL_NAK 0x474 #define CP_ELBI_DBI_L1_EXIT_DISABLE 0x1078 +#define CP_ELBI_APP_XFER_PENDING 0x074 /* zumapro */ +#define CP_ELBI_SOFT_RESET_ALL 0xf /* zumapro: written as a word */ +#define CP_ELBI_SLV_PEND_SEL_NAK 0x3d8 /* zumapro */ /* PMU PHY control (PHY_CTRL_PCIE_GEN4_0): bit 0 set = isolation bypassed */ #define CP_PMU_PHY_BYPASS BIT(0) @@ -142,6 +169,21 @@ MODULE_PARM_DESC(watch_lines, "Log every edge on the modem's cp2ap lines, with i /* Secure ATU: the outbound iATU is programmed by EL3 (Google's exynos_smc()) */ #define CP_SMC_SECURE_ATU_SETUP 0x820020d8 +/* zumapro: the unrolled outbound iATU, DBI + 0x300000, 0x200 per region */ +#define CP_ATU_OB(r, reg) (0x300000 + (r) * 0x200 + (reg)) +#define CP_ATU_CR1 0x00 +#define CP_ATU_CR2 0x04 +#define CP_ATU_LOWER_BASE 0x08 +#define CP_ATU_UPPER_BASE 0x0c +#define CP_ATU_LIMIT 0x10 +#define CP_ATU_LOWER_TARGET 0x14 +#define CP_ATU_UPPER_TARGET 0x18 +#define CP_ATU_TYPE_MEM 0x0 +#define CP_ATU_TYPE_CFG0 0x4 +#define CP_ATU_ENABLE BIT(31) +#define CP_ATU_BUS(x) (((x) & 0xff) << 24) +#define CP_ATU_MEM_SIZE SZ_2M /* Google's limit */ + #define CP_PERST_DELAY_US 18000 /* modem: 18-20 ms, Wi-Fi 20 */ #define CP_LINK_POLL_US 10 #define CP_LINK_TIMEOUT_US 48000 @@ -191,6 +233,26 @@ static const char * const cp_input_names[CP_NUM_INPUTS] = { #define CP_ROOT_WIN_REGS 7 /* ARRAY_SIZE(cp_root_win_offs) */ +/** + * struct gs201_pcie_cp_data - what differs between the SoCs + * @zuma_ctrl: the zuma family's controller steps: RC mode, the soft power + * reset and the slave NAK before the PHY configuration; + * APP_XFER_PENDING from training to the end of link_up and around + * endpoint configuration reads; two lanes in the port logic; and + * phy_calibrate() once the link has trained + * @phy_bypass_once: the PHY leaves isolation at the first link_up and + * stays out until the driver goes away + * @host_atu: no secure-ATU SMC; the host programs the outbound iATU + * @sysreg_optional: without samsung,sysreg the link runs without I/O + * coherency + */ +struct gs201_pcie_cp_data { + bool zuma_ctrl; + bool phy_bypass_once; + bool host_atu; + bool sysreg_optional; +}; + struct gs201_pcie_cp { struct device *dev; struct dw_pcie pci; /* only for the DBI helpers */ @@ -248,6 +310,9 @@ struct gs201_pcie_cp { struct pci_saved_state *ep_state; /* its config after the scan */ u32 root_win[CP_ROOT_WIN_REGS]; /* root port windows after the scan */ bool root_win_saved; + const struct gs201_pcie_cp_data *data; + phys_addr_t cfg_phys; /* host_atu: the config window */ + resource_size_t cfg_size; }; /* @@ -472,10 +537,21 @@ static int cp_cfg_read(struct pci_bus *bus, unsigned int devfn, int where, { struct gs201_pcie_cp *cp = bus->sysdata; unsigned long flags; + bool xfer; int ret; raw_spin_lock_irqsave(&cp->cfg_lock, flags); + /* + * zumapro: as Google's exynos_pcie_rc_rd_other_conf(), hold the link + * out of L1 while an endpoint read is in flight. cfg_ep_ok means the + * link is up, so ELBI is reachable. + */ + xfer = cp->data->zuma_ctrl && !pci_is_root_bus(bus) && cp->cfg_ep_ok; + if (xfer) + cp_elbi_write(cp, CP_ELBI_APP_XFER_PENDING, 1); ret = pci_generic_config_read(bus, devfn, where, size, val); + if (xfer) + cp_elbi_write(cp, CP_ELBI_APP_XFER_PENDING, 0); raw_spin_unlock_irqrestore(&cp->cfg_lock, flags); /* @@ -937,6 +1013,54 @@ static void cp_ctrl_irq(struct gs201_pcie_cp *cp, bool on) cp->ctrl_irq_on = on; } +/* + * zumapro: exynos_pcie_rc_poweroff() from PERST# on, while the PHY still + * runs: LTSSM off, APP_XFER_PENDING dropped, the controller's interrupts + * off and a soft power reset pulse; then phy_power_off(), which returns the + * PHY's input clock to the oscillator and powers the PHY down. ELBI stays + * clocked from there to the next phy_power_on(), whose controller steps + * come before the PHY's (cp_zuma_link_prepare()). Also the cleanup after a + * failed try. + */ +static void cp_zuma_phy_off(struct gs201_pcie_cp *cp) +{ + u32 val; + + if (!cp->phy_on) + return; + gpiod_direction_output(cp->perst, 1); + cp_elbi_write(cp, CP_ELBI_LTSSM_EN, 0); + cp_elbi_write(cp, CP_ELBI_APP_XFER_PENDING, 0); + cp_elbi_write(cp, CP_ELBI_IRQ0_EN, 0); + cp_elbi_write(cp, CP_ELBI_IRQ1_EN, 0); + cp_elbi_write(cp, CP_ELBI_IRQ2_EN, 0); + val = cp_elbi_read(cp, CP_ELBI_SOFT_RESET); + cp_elbi_write(cp, CP_ELBI_SOFT_RESET, val & ~CP_ELBI_SOFT_PWR_RESET); + usleep_range(20, 40); + cp_elbi_write(cp, CP_ELBI_SOFT_RESET, val | CP_ELBI_SOFT_PWR_RESET); + phy_power_off(cp->phy); + cp->phy_on = false; +} + +/* + * zumapro: the link down with the PHY powered down but left out of + * isolation, as stock. DBI is closed to readers until the next link_up. + */ +static void cp_zuma_link_down(struct gs201_pcie_cp *cp) +{ + bool was_on = cp->phy_on; + + cp_ctrl_irq(cp, false); /* reads ELBI: before anything else */ + cp_cfg_allow(cp, false, false); + cp_msi_irqs(cp, false); + cp_zuma_phy_off(cp); + cp_dbi_allow(cp, false); + if (was_on) + dev_info(cp->dev, "link down, PHY powered down\n"); + cp->link_up = false; + cp->atu_done = false; +} + /* * exynos_pcie_rc_poweroff(): PERST#, LTSSM off, a soft power reset of the * controller, PHY power-down; then isolation, as on suspend. @@ -946,6 +1070,11 @@ static void cp_link_down(struct gs201_pcie_cp *cp) bool was_inited = cp->phy_inited; u32 val; + if (cp->data->phy_bypass_once) { + cp_zuma_link_down(cp); + return; + } + cp_ctrl_irq(cp, false); /* reads ELBI: before anything else */ cp_cfg_allow(cp, false, false); cp_msi_irqs(cp, false); @@ -1016,12 +1145,78 @@ static int cp_link_settle(struct gs201_pcie_cp *cp, unsigned int speed, return 0; } +/* + * zumapro: exynos_pcie_rc_poweron() and _establish_link() up to the LTSSM. + * The CAL writes RC mode, the soft power reset and the slave NAK in the + * middle of its PHY configuration, after the external PLL has locked; the + * PHY driver leaves ELBI to the host, so they come first, as pcie-gs201.c + * does on zuma's Wi-Fi link. ELBI is clocked here: the PHY is out of + * isolation, and it is powered down with its input clock on the + * oscillator (boot, or the last phy_power_off()). + */ +static int cp_zuma_link_prepare(struct gs201_pcie_cp *cp, unsigned int speed) +{ + struct dw_pcie *pci = &cp->pci; + u32 val; + int ret; + + cp_elbi_write(cp, CP_ELBI_DEVICE_TYPE, CP_ELBI_DEVICE_TYPE_RC); + cp_elbi_write(cp, CP_ELBI_SOFT_RESET, CP_ELBI_SOFT_RESET_ALL); + cp_elbi_write(cp, CP_ELBI_SOFT_RESET, + CP_ELBI_SOFT_RESET_ALL & ~CP_ELBI_SOFT_PWR_RESET); + fsleep(10); + cp_elbi_write(cp, CP_ELBI_SOFT_RESET, CP_ELBI_SOFT_RESET_ALL); + fsleep(10); + cp_elbi_write(cp, CP_ELBI_SLV_PEND_SEL_NAK, 1); + + ret = phy_power_on(cp->phy); /* power-down clear, CAL, lock checks */ + if (ret) + return ret; + cp->phy_on = true; + + /* "EQ off" before PERST# release, as Google (again in cp_setup_dbi()) */ + dw_pcie_writel_dbi(pci, GEN3_RELATED_OFF, 0x12000); + gpiod_set_value_cansleep(cp->perst, 0); + fsleep(CP_PERST_DELAY_US); + + cp_elbi_rmw(cp, CP_ELBI_REQ_EXIT_L1_MODE, 0, + CP_ELBI_APP_REQ_EXIT_L1 | CP_ELBI_L1_REQ_NAK_MASTER); + cp_elbi_write(cp, CP_ELBI_LINKDOWN_RST_SEL, CP_ELBI_LINKDOWN_RST_MANUAL); + cp_elbi_write(cp, CP_ELBI_APP_XFER_PENDING, 1); /* to the end of link_up */ + cp_elbi_rmw(cp, CP_ELBI_QCH_SEL, CP_ELBI_QCH_GATING_MASK, 0); + cp_elbi_write(cp, CP_ELBI_MSTR_PEND_SEL_NAK, 1); + cp_elbi_write(cp, CP_ELBI_DBI_L1_EXIT_DISABLE, 1); + + cp_setup_dbi(cp, speed); + if (cp->sysreg) + cp_set_iocc(cp, true); + + if (cp->num_lanes == 2) { + val = dw_pcie_readl_dbi(pci, PCIE_PORT_LINK_CONTROL); + val = (val & ~PORT_LINK_MODE_MASK) | PORT_LINK_MODE_2_LANES; + dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val); + val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL); + val = (val & ~PORT_LOGIC_LINK_WIDTH_MASK) | + PORT_LOGIC_LINK_WIDTH_2_LANES; + dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val); + } + + return 0; +} + /* exynos_pcie_rc_establish_link(), one try */ static int cp_link_try(struct gs201_pcie_cp *cp, unsigned int speed, bool last) { u32 val; int ret; + if (cp->data->zuma_ctrl) { + ret = cp_zuma_link_prepare(cp, speed); + if (ret) + return ret; + goto ltssm; + } + ret = phy_power_on(cp->phy); /* power-down clear, CAL, lock checks */ if (ret) return ret; @@ -1055,6 +1250,7 @@ static int cp_link_try(struct gs201_pcie_cp *cp, unsigned int speed, bool last) cp_setup_dbi(cp, speed); cp_set_iocc(cp, true); +ltssm: cp_elbi_write(cp, CP_ELBI_LTSSM_EN, 1); ret = readl_poll_timeout(cp->elbi + CP_ELBI_LTSSM_STATE, val, FIELD_GET(CP_ELBI_LTSSM_MASK, val) == @@ -1080,6 +1276,10 @@ static int cp_link_up(struct gs201_pcie_cp *cp, unsigned int speed) if (cp->has_lines && !cp->cp_powered) dev_warn(cp->dev, "modem not powered (cp_on): expect no link\n"); + /* zumapro: the PHY stays initialized; only a powered-down one trains */ + if (cp->data->phy_bypass_once && cp->phy_on) + return -EBUSY; + if (!cp->phy_inited) { /* PERST# asserted and CLKREQ# in its function before the PHY */ gpiod_direction_output(cp->perst, 1); @@ -1094,19 +1294,32 @@ static int cp_link_up(struct gs201_pcie_cp *cp, unsigned int speed) return ret; cp_dbi_allow(cp, true); cp->phy_inited = true; + } else if (cp->data->phy_bypass_once) { + cp_dbi_allow(cp, true); } for (try = 1; try <= CP_LINK_TRIES; try++) { ret = cp_link_try(cp, speed, try == CP_LINK_TRIES); if (!ret) break; + if (cp->data->zuma_ctrl) { + cp_zuma_phy_off(cp); + continue; + } gpiod_set_value_cansleep(cp->perst, 1); cp_elbi_write(cp, CP_ELBI_LTSSM_EN, 0); phy_power_off(cp->phy); cp->phy_on = false; } - if (ret) + if (ret) { + if (cp->data->phy_bypass_once) /* PHY down: DBI closed */ + cp_dbi_allow(cp, false); return ret; + } + + /* zumapro: PLL and bias held on (Google's poweron, channel 0) */ + if (cp->data->zuma_ctrl) + phy_calibrate(cp->phy); cap = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); lnksta = cap ? dw_pcie_readw_dbi(pci, cap + PCI_EXP_LNKSTA) : 0; @@ -1118,6 +1331,8 @@ static int cp_link_up(struct gs201_pcie_cp *cp, unsigned int speed) cp_elbi_write(cp, CP_ELBI_IRQ0, cp_elbi_read(cp, CP_ELBI_IRQ0)); cp_elbi_write(cp, CP_ELBI_IRQ1, cp_elbi_read(cp, CP_ELBI_IRQ1)); cp_elbi_write(cp, CP_ELBI_IRQ2, cp_elbi_read(cp, CP_ELBI_IRQ2)); + if (cp->data->zuma_ctrl) + cp_elbi_write(cp, CP_ELBI_APP_XFER_PENDING, 0); cp->link_up = true; cp_cfg_allow(cp, true, false); cp_ctrl_irq(cp, true); @@ -1125,6 +1340,57 @@ static int cp_link_up(struct gs201_pcie_cp *cp, unsigned int speed) return 0; } +/* + * zumapro: exynos_pcie_rc_prog_viewport_cfg0() and _mem_outbound(), in + * place of the secure-ATU SMC. Region 0 maps the config window to bus 1 + * (the modem, device 0), region 1 the first 2 MiB of the memory window, + * Google's limit. The controller's soft power reset clears both, so this + * runs after every link_up. + */ +static int cp_host_atu(struct gs201_pcie_cp *cp) +{ + struct dw_pcie *pci = &cp->pci; + struct resource_entry *win; + u64 cpu, pci_addr; + + win = resource_list_first_type(&cp->bridge->windows, IORESOURCE_MEM); + if (!win) + return -EINVAL; + cpu = win->res->start; + pci_addr = cpu - win->offset; + + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_LOWER_BASE), + lower_32_bits(cp->cfg_phys)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_UPPER_BASE), + upper_32_bits(cp->cfg_phys)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_LIMIT), + lower_32_bits(cp->cfg_phys + cp->cfg_size - 1)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_LOWER_TARGET), CP_ATU_BUS(1)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_UPPER_TARGET), 0); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_CR1), CP_ATU_TYPE_CFG0); + dw_pcie_writel_dbi(pci, CP_ATU_OB(0, CP_ATU_CR2), CP_ATU_ENABLE); + + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_CR1), CP_ATU_TYPE_MEM); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_LOWER_BASE), + lower_32_bits(cpu)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_UPPER_BASE), + upper_32_bits(cpu)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_LIMIT), + lower_32_bits(cpu + CP_ATU_MEM_SIZE - 1)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_LOWER_TARGET), + lower_32_bits(pci_addr)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_UPPER_TARGET), + upper_32_bits(pci_addr)); + dw_pcie_writel_dbi(pci, CP_ATU_OB(1, CP_ATU_CR2), CP_ATU_ENABLE); + + dev_info(cp->dev, "iATU: config %pa to bus 1, memory %#llx to PCI %#llx (2 MiB)\n", + &cp->cfg_phys, cpu, pci_addr); + cp->atu_done = true; + cp_cfg_allow(cp, true, true); + + return 0; +} + static int cp_secure_atu(struct gs201_pcie_cp *cp) { struct arm_smccc_res res; @@ -1277,7 +1543,7 @@ int gs201_pcie_cp_poweron(unsigned int speed) ret = cp_link_up(cp, speed); if (!ret) - ret = cp_secure_atu(cp); + ret = cp->data->host_atu ? cp_host_atu(cp) : cp_secure_atu(cp); if (ret) goto err; @@ -1353,6 +1619,44 @@ bool gs201_pcie_cp_link_ok(void) } EXPORT_SYMBOL_GPL(gs201_pcie_cp_link_ok); +/** + * gs201_pcie_cp_doorbell() - write the modem's doorbell and read it back + * @addr: the doorbell register in the modem's BAR window (ioremapped) + * @val: the interrupt number to ring + * @readback: the register's value after the write + * + * The BAR window is reachable only while the endpoint is (link up, iATU + * set), and an access while the PHY is isolated or powered down can hang + * the SoC. The modem driver checks the link before it writes, but the CP + * can ask for the link to go down between its check and its access, and + * its read-back loop on the register (a millisecond per try, up to 100) + * spans that window. cfg_lock serializes the access against + * cp_link_down(), which clears cfg_ep_ok under it before it touches + * PERST#, the PHY or the isolation. + * + * Return: 0, -ENODEV before probe, -ENOLINK while the endpoint is not + * reachable (the caller reserves the doorbell for the next link up). + */ +int gs201_pcie_cp_doorbell(void __iomem *addr, u32 val, u32 *readback) +{ + struct gs201_pcie_cp *cp = READ_ONCE(gs201_cp); + unsigned long flags; + int ret = -ENOLINK; + + if (!cp) + return -ENODEV; + raw_spin_lock_irqsave(&cp->cfg_lock, flags); + if (cp->cfg_ep_ok) { + writel(val, addr); + *readback = readl(addr); + ret = 0; + } + raw_spin_unlock_irqrestore(&cp->cfg_lock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(gs201_pcie_cp_doorbell); + /** * gs201_pcie_cp_check_msi_addr() - check the modem driver's MSI target * @addr: the MSI page the modem driver expects @@ -1635,7 +1939,11 @@ static ssize_t cp_ctl_write(struct file *file, const char __user *ubuf, } else if (!strcmp(cmd, "link_down")) { cp_link_down(cp); } else if (!strcmp(cmd, "atu")) { - ret = cp->link_up ? cp_secure_atu(cp) : -ENOLINK; + if (!cp->link_up) + ret = -ENOLINK; + else + ret = cp->data->host_atu ? cp_host_atu(cp) : + cp_secure_atu(cp); } else if (!strcmp(cmd, "id")) { ret = cp->atu_done ? cp_read_id(cp) : -ENOLINK; } else if (!strcmp(cmd, "bus")) { @@ -1699,7 +2007,8 @@ static int cp_status_show(struct seq_file *s, void *unused) (unsigned int)FIELD_GET(PCI_EXP_LNKSTA_NLW, lnksta), cp->speed); } - if (cp->phy_inited) + /* zumapro: the controller only while the PHY is powered */ + if (cp->data->phy_bypass_once ? cp->phy_on : cp->phy_inited) seq_printf(s, "LTSSM %#lx, IRQ0/1/2 %#x %#x %#x\n", FIELD_GET(CP_ELBI_LTSSM_MASK, cp_elbi_read(cp, CP_ELBI_LTSSM_STATE)), @@ -1806,6 +2115,22 @@ static int cp_get_lines(struct gs201_pcie_cp *cp) i < CP_NUM_OUTPUTS ? cp_output_names[i] : "input"); } +/* The shareability register for I/O coherency; zumapro may run without */ +static int cp_get_sysreg(struct gs201_pcie_cp *cp) +{ + struct device_node *np = cp->dev->of_node; + + if (cp->data->sysreg_optional && + !of_property_present(np, "samsung,sysreg")) + return 0; + cp->sysreg = syscon_regmap_lookup_by_phandle_args(np, "samsung,sysreg", + 1, &cp->sysreg_offset); + if (IS_ERR(cp->sysreg)) + return dev_err_probe(cp->dev, PTR_ERR(cp->sysreg), "no sysreg\n"); + + return 0; +} + static int gs201_pcie_cp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1818,6 +2143,9 @@ static int gs201_pcie_cp_probe(struct platform_device *pdev) if (!cp) return -ENOMEM; cp->dev = dev; + cp->data = device_get_match_data(dev); + if (!cp->data) + return -ENODEV; mutex_init(&cp->lock); raw_spin_lock_init(&cp->cfg_lock); raw_spin_lock_init(&cp->dbi_lock); @@ -1840,11 +2168,15 @@ static int gs201_pcie_cp_probe(struct platform_device *pdev) cp->cfg = devm_platform_ioremap_resource_byname(pdev, "config"); if (IS_ERR(cp->cfg)) return PTR_ERR(cp->cfg); + if (cp->data->host_atu) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "config"); + cp->cfg_phys = res->start; + cp->cfg_size = resource_size(res); + } - cp->sysreg = syscon_regmap_lookup_by_phandle_args(np, "samsung,sysreg", - 1, &cp->sysreg_offset); - if (IS_ERR(cp->sysreg)) - return dev_err_probe(dev, PTR_ERR(cp->sysreg), "no sysreg\n"); + ret = cp_get_sysreg(cp); + if (ret) + return ret; cp->pmu = exynos_get_pmu_regmap_by_phandle(np, "samsung,pmu-syscon"); if (IS_ERR(cp->pmu)) @@ -1950,6 +2282,10 @@ static void gs201_pcie_cp_remove(struct platform_device *pdev) cp_ep_forget(cp); cp_bus_remove(cp); cp_link_down(cp); + if (cp->phy_inited) { /* phy_bypass_once */ + phy_exit(cp->phy); + cp->phy_inited = false; + } if (cp->msi_ready) { dw_pcie_free_msi(&cp->pci.pp); cp->msi_ready = false; @@ -1967,8 +2303,19 @@ static void gs201_pcie_cp_shutdown(struct platform_device *pdev) gs201_pcie_cp_remove(pdev); } +static const struct gs201_pcie_cp_data gs201_pcie_cp_data = { +}; + +static const struct gs201_pcie_cp_data zumapro_pcie_cp_data = { + .zuma_ctrl = true, + .phy_bypass_once = true, + .host_atu = true, + .sysreg_optional = true, +}; + static const struct of_device_id gs201_pcie_cp_of_match[] = { - { .compatible = "google,gs201-pcie-cp" }, + { .compatible = "google,gs201-pcie-cp", .data = &gs201_pcie_cp_data }, + { .compatible = "google,zumapro-pcie-cp", .data = &zumapro_pcie_cp_data }, { } }; MODULE_DEVICE_TABLE(of, gs201_pcie_cp_of_match); @@ -1985,5 +2332,5 @@ static struct platform_driver gs201_pcie_cp_driver = { }; module_platform_driver(gs201_pcie_cp_driver); -MODULE_DESCRIPTION("Google gs201 PCIe GEN4A_0 (modem) bring-up"); +MODULE_DESCRIPTION("Google gs201 and zumapro PCIe modem link bring-up"); MODULE_LICENSE("GPL"); diff --git a/drivers/pci/controller/dwc/pcie-gs201.c b/drivers/pci/controller/dwc/pcie-gs201.c index af650d7638..b114c6be96 100644 --- a/drivers/pci/controller/dwc/pcie-gs201.c +++ b/drivers/pci/controller/dwc/pcie-gs201.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * PCIe host controller driver for the Google gs201 (Tensor G2) SoC + * PCIe host controller driver for the Google gs201 (Tensor G2) and zuma + * (Tensor G3) SoCs * * The controller is a Synopsys DesignWare core (IP version 0x984500) in a * Samsung wrapper ("ELBI" sub-control registers, a link-training helper @@ -69,9 +70,11 @@ #define GS201_ELBI_SOFT_RESET 0x3a4 #define GS201_ELBI_SOFT_PWR_RESET BIT(1) #define GS201_ELBI_SOFT_NON_STICKY_RESET BIT(3) +#define GS201_ELBI_SOFT_RESET_ALL GENMASK(3, 0) #define GS201_ELBI_QCH_SEL 0x3a8 #define GS201_ELBI_QCH_GATING_MASK GENMASK(11, 0) #define GS201_ELBI_REQ_EXIT_L1_MODE 0x3bc +#define GS201_ELBI_SLV_PEND_SEL_NAK 0x3d8 #define GS201_ELBI_APP_REQ_EXIT_L1_MODE BIT(0) #define GS201_ELBI_L1_REQ_NAK_MASTER BIT(4) #define GS201_ELBI_MSTR_PEND_SEL_NAK 0x474 @@ -163,8 +166,25 @@ module_param(cmu_acg_off, bool, 0444); MODULE_PARM_DESC(cmu_acg_off, "Clear CMU_HSI2 automatic clock gating in stage 1, as Google's gs201 driver does (default: false)"); +/** + * struct gs201_pcie_soc_data - what differs between the SoCs + * @ctrl_reset_before_phy: the controller's soft power reset and RC mode are + * set before the PHY configuration, and not again after it. zuma's + * CAL does them in the middle of its PHY configuration; gs201's + * establish_link() does them after. + * @pwr_reset_before_phy_off: the power-down turns the LTSSM off and pulses + * the soft power reset before the PHY powers down, as Google's + * exynos_pcie_rc_poweroff() does for the zuma family. Only zumapro so + * far: it hasn't run on a zuma board here. + */ +struct gs201_pcie_soc_data { + bool ctrl_reset_before_phy; + bool pwr_reset_before_phy_off; +}; + struct gs201_pcie { struct dw_pcie pci; + const struct gs201_pcie_soc_data *data; void __iomem *elbi; void __iomem *ia; void __iomem *cmu; @@ -569,11 +589,33 @@ static int gs201_pcie_stage_wake(struct gs201_pcie *gp) return 0; } +/* + * zuma's CAL: RC mode and a soft power reset pulse, written as whole words + * as Google does, and NAKs for slave requests while AXI is pending. + */ +static void gs201_pcie_ctrl_reset_early(struct gs201_pcie *gp) +{ + gs201_trace(gp, "about to write ELBI 0x080 = 4 (root complex) and pulse the soft power reset (ELBI 0x3a4)"); + gs201_elbi_writel(gp, GS201_ELBI_DEVICE_TYPE, GS201_ELBI_DEVICE_TYPE_RC); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, GS201_ELBI_SOFT_RESET_ALL); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + GS201_ELBI_SOFT_RESET_ALL & ~GS201_ELBI_SOFT_PWR_RESET); + fsleep(10); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, GS201_ELBI_SOFT_RESET_ALL); + fsleep(10); + + gs201_trace(gp, "about to write ELBI 0x3d8 = 1 (slave pending NAK)"); + gs201_elbi_writel(gp, GS201_ELBI_SLV_PEND_SEL_NAK, 1); +} + /* Stage 3: Google's PHY configuration, then the I/A sequencer */ static int gs201_pcie_stage_phy(struct gs201_pcie *gp) { int ret; + if (gp->data->ctrl_reset_before_phy) + gs201_pcie_ctrl_reset_early(gp); + gs201_trace(gp, "phy_power_on: power-down clear, CAL table, lock checks"); ret = phy_power_on(gp->phy); if (ret) @@ -607,6 +649,9 @@ static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) struct device *dev = gp->pci.dev; u32 val; + if (gp->data->ctrl_reset_before_phy) + goto perst; + gs201_trace(gp, "about to pulse the soft power reset (ELBI 0x3a4 bit 1)"); val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, @@ -631,8 +676,9 @@ static void gs201_pcie_stage_ctrl(struct gs201_pcie *gp, bool release_perst) gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, val | GS201_ELBI_SOFT_NON_STICKY_RESET); +perst: if (release_perst) { - gs201_trace(gp, "about to release PERST# (gph2-0) and wait 20 ms"); + gs201_trace(gp, "about to release PERST# and wait 20 ms"); gpiod_set_value_cansleep(gp->perst, 0); fsleep(GS201_PERST_DELAY_US); } @@ -689,9 +735,31 @@ static int gs201_pcie_bringup(struct gs201_pcie *gp, unsigned int last, return 0; } +/* + * zuma's exynos_pcie_rc_poweroff(): LTSSM off and a soft power reset pulse + * while the PHY still runs, before it is powered down + */ +static void gs201_pcie_pwr_reset_before_phy_off(struct gs201_pcie *gp) +{ + u32 val; + + if (!gp->data->pwr_reset_before_phy_off || !gp->phy_on) + return; + + gs201_trace(gp, "LTSSM off, soft power reset pulse (ELBI 0x054, 0x3a4 bit 1)"); + gs201_elbi_writel(gp, GS201_ELBI_LTSSM_EN, 0); + val = gs201_elbi_readl(gp, GS201_ELBI_SOFT_RESET); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val & ~GS201_ELBI_SOFT_PWR_RESET); + usleep_range(20, 40); + gs201_elbi_writel(gp, GS201_ELBI_SOFT_RESET, + val | GS201_ELBI_SOFT_PWR_RESET); +} + /* Undo what the stages did, in reverse; the PHY stays out of isolation */ static void gs201_pcie_bringdown(struct gs201_pcie *gp) { + gs201_pcie_pwr_reset_before_phy_off(gp); gs201_pcie_phy_off(gp); if (gp->phy_inited) { gs201_trace(gp, "phy_exit"); @@ -818,7 +886,7 @@ static int gs201_pcie_host_init(struct dw_pcie_rp *pp) } if (!pp->skip_pwrctrl_off) { - gs201_trace(gp, "about to power the endpoint (WL_REG_ON, gph2-4, 200 ms)"); + gs201_trace(gp, "about to power the endpoint (WL_REG_ON and its startup delay)"); ret = pci_pwrctrl_power_on_devices(dev); if (ret) goto err_pwrctrl_destroy; @@ -1101,6 +1169,7 @@ static int gs201_pcie_probe(struct platform_device *pdev) return -ENOMEM; raw_spin_lock_init(&gp->lock); + gp->data = of_device_get_match_data(dev); pci = &gp->pci; pci->dev = dev; @@ -1186,8 +1255,22 @@ static void gs201_pcie_remove(struct platform_device *pdev) gs201_pcie_remove_irq(gp); } +static const struct gs201_pcie_soc_data gs201_pcie_data = { +}; + +static const struct gs201_pcie_soc_data zuma_pcie_data = { + .ctrl_reset_before_phy = true, +}; + +static const struct gs201_pcie_soc_data zumapro_pcie_data = { + .ctrl_reset_before_phy = true, + .pwr_reset_before_phy_off = true, +}; + static const struct of_device_id gs201_pcie_of_match[] = { - { .compatible = "google,gs201-pcie" }, + { .compatible = "google,gs201-pcie", .data = &gs201_pcie_data }, + { .compatible = "google,zumapro-pcie", .data = &zumapro_pcie_data }, + { .compatible = "google,zuma-pcie", .data = &zuma_pcie_data }, { } }; MODULE_DEVICE_TABLE(of, gs201_pcie_of_match); diff --git a/drivers/phy/samsung/Kconfig b/drivers/phy/samsung/Kconfig index a9cada8097..9e726d4528 100644 --- a/drivers/phy/samsung/Kconfig +++ b/drivers/phy/samsung/Kconfig @@ -39,6 +39,20 @@ config PHY_GS201_PCIE SoC. It is used by the gs201 PCIe controller driver, which connects the Wi-Fi chip on Pixel 7 phones. +config PHY_ZUMA_PCIE + tristate "Google zuma PCIe PHY driver" + depends on OF && (ARCH_EXYNOS || COMPILE_TEST) + depends on EXYNOS_PMU || COMPILE_TEST + select GENERIC_PHY + help + Enable support for the PCIe Gen3 PHYs of the Google zuma (Tensor G3) + and zumapro (Tensor G4) SoCs: the one-lane PHY that connects the + Wi-Fi chip on Pixel 8 phones and on the Pixel 9a, and zumapro's + two-lane PHY that connects the Pixel 9a's modem. They are used by + the gs201 PCIe controller driver. Each PHY is programmed from + stock's register tables, and its power-down isolation is released + through the PMU. + config PHY_GS201_MIPI_DCPHY tristate "Google gs201 MIPI DC-PHY receiver driver" depends on OF && (ARCH_EXYNOS || COMPILE_TEST) diff --git a/drivers/phy/samsung/Makefile b/drivers/phy/samsung/Makefile index a24c25524c..56e77422a7 100644 --- a/drivers/phy/samsung/Makefile +++ b/drivers/phy/samsung/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO) += phy-exynos-dp-video.o obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO) += phy-exynos-mipi-video.o obj-$(CONFIG_PHY_EXYNOS_PCIE) += phy-exynos-pcie.o obj-$(CONFIG_PHY_GS201_PCIE) += phy-gs201-pcie.o +obj-$(CONFIG_PHY_ZUMA_PCIE) += phy-zuma-pcie.o obj-$(CONFIG_PHY_GS201_MIPI_DCPHY) += phy-gs201-mipi-dcphy-rx.o obj-$(CONFIG_PHY_SAMSUNG_UFS) += phy-exynos-ufs.o phy-exynos-ufs-y += phy-gs101-ufs.o diff --git a/drivers/phy/samsung/phy-zuma-pcie.c b/drivers/phy/samsung/phy-zuma-pcie.c new file mode 100644 index 0000000000..f086aae4f6 --- /dev/null +++ b/drivers/phy/samsung/phy-zuma-pcie.c @@ -0,0 +1,823 @@ +// 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), and + * the two-lane PHY of zumapro's first controller (the modem's). Their + * reference clock comes from an external PLL in the UDBG block, selected in + * the controller's SOC block. The register sequences are Samsung's "CAL ver + * 0.2" for zuma, channel 1 and channel 0, taken from the driver Google + * builds for zuma and zumapro (pcie-exynos-zuma-rc-cal.c and + * pcie-exynos-rc.c in google-modules/soc/gs/drivers/pci/controller/dwc). + * Most PMA registers have no public names, so the tables keep Samsung's raw + * offsets and values. + * + * Copyright (C) 2021 Samsung Electronics Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Bring-up tracing, as in the gs201 PHY driver: with trace=1 every step + * that touches the hardware is logged before it happens, and the driver + * sleeps trace_delay_ms after each line so that a reader of /dev/kmsg + * receives it before a possible bus hang stops the CPU. + */ +static bool trace; +module_param(trace, bool, 0644); +MODULE_PARM_DESC(trace, "Log every hardware step before doing it (bring-up)"); + +static unsigned int trace_delay_ms = 20; +module_param(trace_delay_ms, uint, 0644); +MODULE_PARM_DESC(trace_delay_ms, "Sleep after each trace line, in ms (default 20)"); + +/* + * PMU PHY control: bit 0 clear isolates the PHY; bit 10 tells the PMU the + * PHY has been configured + */ +#define ZUMA_PMU_PHY_BYPASS BIT(0) +#define ZUMA_PMU_PHY_CONFIGURED BIT(10) + +/* PHY reset block, in the controller's sub-control (ELBI) space at +0x1400 */ +#define ZUMA_PHY_RST_CMN 0x0 +#define ZUMA_PHY_RST_INIT 0x4 +#define ZUMA_PHY_RST_PORT 0x8 + +/* SOC block: the PHY's input clock */ +#define ZUMA_SOC_CLK_MODE 0x4000 +#define ZUMA_SOC_CLK_MODE_VAL 0x15 +#define ZUMA_SOC_CLK_MODE_SEL GENMASK(1, 0) +#define ZUMA_SOC_CLK_SEL 0x4004 +#define ZUMA_SOC_CLK_SEL_TCXO BIT(2) +#define ZUMA_SOC_CLK_SEL_EXT_PLL GENMASK(5, 4) + +/* UDBG block: the external PLL */ +#define ZUMA_UDBG_EXT_PLL 0xc700 +#define ZUMA_UDBG_EXT_PLL_EN BIT(0) +#define ZUMA_UDBG_EXT_PLL_RESETB_OVR BIT(1) +#define ZUMA_UDBG_EXT_PLL_STATUS 0xc734 +#define ZUMA_UDBG_EXT_PLL_LOCK BIT(2) +#define ZUMA_UDBG_LINK_CTRL 0xc800 +#define ZUMA_UDBG_LINK_CTRL_VAL 0x421 + +/* UDBG block, two-lane PHY: its external PLL's own controls */ +#define ZUMA_X2_UDBG_EXT_PLL_STATUS 0xc704 +#define ZUMA_X2_UDBG_EXT_PLL_LOCK BIT(3) +#define ZUMA_X2_UDBG_EXT_PLL_CTRL 0xc710 +#define ZUMA_X2_UDBG_EXT_PLL_INIT BIT(1) +#define ZUMA_X2_UDBG_EXT_PLL_L2_GATE GENMASK(9, 8) +#define ZUMA_X2_UDBG_LINK_CTRL_CLR GENMASK(6, 5) + +/* 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) + +/* PMA registers of the two-lane PHY used outside the tables */ +#define ZUMA_X2_PMA_LANE_STRIDE 0x1000 +#define ZUMA_X2_PMA_LANES 2 +#define ZUMA_X2_PMA_PLL_ENGAGED 0x0260 +#define ZUMA_X2_PMA_PLL_ENGAGED_BIT BIT(2) +#define ZUMA_X2_PMA_PLL_LOCK_SIG 0x0600 +#define ZUMA_X2_PMA_PLL_LOCK_SIG_MASK GENMASK(5, 4) +#define ZUMA_X2_PMA_PLL_LOCK_SIG_OFF BIT(5) + +/* PCS PLL and bias control of the two-lane PHY */ +#define ZUMA_X2_PCS_PLL_BIAS 0x150 +#define ZUMA_X2_PCS_PLL_BIAS_ON 0x000300d5 +#define ZUMA_X2_PCS_PLL_OFF_BIAS_ON 0x000300d9 +#define ZUMA_X2_PCS_PLL_OFF_BIAS_OFF 0x000300de + +/* 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), one-lane PHY, after the lane: + * the link went down on L1 substate exits without these. + */ +static const struct zuma_pcie_phy_reg zuma_pma_lane_bcm[] = { + { 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 }, +}; + +/* + * The two-lane PHY's common PMA block: the one-lane table with 0x510 + * written first, as channel 0's CAL does + */ +static const struct zuma_pcie_phy_reg zuma_x2_pma_common[] = { + { 0x0000, 0x88 }, { 0x001c, 0x66 }, { 0x01f4, 0x00 }, { 0x0510, 0x81 }, + { 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 two-lane PHY's PCS: the generic timer values, no Wi-Fi quirks */ +static const struct zuma_pcie_phy_reg zuma_x2_pcs[] = { + { 0x190, 0x100b0604 }, + /* L1.2 without CLKREQ# */ + { 0x154, 0x000700d5 }, + { 0x100, 0x16400000 }, { 0x104, 0x08600000 }, { 0x114, 0x18500000 }, + { 0x124, 0x60700000 }, { 0x174, 0x00000007 }, { 0x178, 0x00000100 }, + { 0x17c, 0x00000010 }, +}; + +struct zuma_pcie_phy { + struct device *dev; + void __iomem *pma; + void __iomem *pcs; + void __iomem *rst; + void __iomem *udbg; + void __iomem *soc; + struct regmap *pmu; + u32 pmu_offset; + bool stock_link_steps; +}; + +/** + * struct zuma_pcie_phy_data - per-PHY steps + * @ops: the PHY's sequences: the one-lane PHY's (channel 1 in Google's + * CAL) or the two-lane PHY's (channel 0) + * @stock_link_steps: one-lane PHY: mark the PHY configured in the PMU at + * the end of power_on and return its input clock to the oscillator at + * power_off, as Google's exynos_pcie_rc_establish_link() and + * exynos_pcie_rc_poweroff() do. Only zumapro so far: zuma does them in + * Google's driver too, but they haven't run on a zuma board here. + */ +struct zuma_pcie_phy_data { + const struct phy_ops *ops; + bool stock_link_steps; +}; + +static __printf(2, 3) void zuma_phy_trace(struct zuma_pcie_phy *zp, + const char *fmt, ...) +{ + struct va_format vaf; + va_list args; + + if (!trace) + return; + + va_start(args, fmt); + vaf.fmt = fmt; + vaf.va = &args; + dev_info(zp->dev, "trace: %pV\n", &vaf); + va_end(args); + + if (trace_delay_ms) + msleep(trace_delay_ms); +} + +static void zuma_pcie_phy_write_table(void __iomem *base, + const struct zuma_pcie_phy_reg *tbl, + size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + writel(tbl[i].val, base + tbl[i].off); +} + +static void zuma_pcie_phy_rmw(void __iomem *reg, u32 clr, u32 set) +{ + writel((readl(reg) & ~clr) | set, reg); +} + +static bool zuma_pcie_phy_wait(struct zuma_pcie_phy *zp, const char *what, + void __iomem *base, u32 off, u32 bit) +{ + u32 val; + + zuma_phy_trace(zp, "about to poll %#x for %s (up to %u us)", off, what, + ZUMA_PHY_LOCK_TIMEOUT_US); + + return !readl_poll_timeout_atomic(base + off, val, val & bit, 10, + ZUMA_PHY_LOCK_TIMEOUT_US); +} + +/* exynos_pcie_rc_phy_all_pwrdn(), channel 1 */ +static void zuma_pcie_phy_pwrdn(struct zuma_pcie_phy *zp) +{ + zuma_phy_trace(zp, "about to read PMA 0x204 (first PMA access) and power the PHY down"); + zuma_pcie_phy_rmw(zp->pma + ZUMA_PMA_CLK_CTRL, ZUMA_PMA_CLK_CTRL_GATE, 0); + zuma_pcie_phy_write_table(zp->pma, zuma_pma_pwrdn, + ARRAY_SIZE(zuma_pma_pwrdn)); + udelay(1); + writel(0xff, zp->pma + 0x0208); + udelay(1); + writel(0x0a, zp->pma + 0x0580); + writel(0xaa, zp->pma + 0x0928); + /* Common bias and PLL off */ + writel(0x0a, zp->pma + ZUMA_PMA_CMN_BIAS); + fsleep(50); + + zuma_phy_trace(zp, "about to read UDBG 0xc700 (first UDBG access): gate the external PLL"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, ZUMA_UDBG_EXT_PLL_EN, 0); + fsleep(10); +} + +/* exynos_pcie_rc_phy_all_pwrdn_clear(), channel 1 */ +static void zuma_pcie_phy_pwrdn_clear(struct zuma_pcie_phy *zp) +{ + size_t i; + + zuma_phy_trace(zp, "about to ungate the external PLL (UDBG 0xc700) and clear the power-downs"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, ZUMA_UDBG_EXT_PLL_EN); + fsleep(100); + writel(0x00, zp->pma + ZUMA_PMA_CMN_BIAS); + writel(0x55, zp->pma + 0x0928); + writel(0x02, zp->pma + 0x0580); + writel(0x00, zp->pma + 0x0208); + for (i = 0; i < ARRAY_SIZE(zuma_pma_pwrdn); i++) + writel(0, zp->pma + zuma_pma_pwrdn[i].off); + fsleep(10); +} + +/* Select the external PLL as the PHY's input clock */ +static void zuma_pcie_phy_sel_ext_pll(struct zuma_pcie_phy *zp) +{ + 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); +} + +/* Pulse the PMA resets: asserted while 1 is written, then let go */ +static void zuma_pcie_phy_pma_reset(struct zuma_pcie_phy *zp) +{ + 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); +} + +static void zuma_pcie_phy_pma_release(struct zuma_pcie_phy *zp) +{ + 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); +} + +/* + * The PLL, CDR and offset calibration checks. As in Google's CAL, a check + * that times out is reported and the sequence goes on. + */ +static void zuma_pcie_phy_lock_checks(struct zuma_pcie_phy *zp, + void __iomem *pma, bool ext) +{ + bool pll, cdr, oc; + + pll = zuma_pcie_phy_wait(zp, "PLL lock", pma, ZUMA_PMA_PLL_STATUS, + ZUMA_PMA_PLL_LOCK); + cdr = zuma_pcie_phy_wait(zp, "CDR lock", pma, ZUMA_PMA_CDR_STATUS, + ZUMA_PMA_CDR_LOCK); + oc = zuma_pcie_phy_wait(zp, "offset calibration", 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); +} + +/* exynos_pcie_rc_pcie_phy_config(), channel 1, less its ELBI writes */ +static void zuma_pcie_phy_config(struct zuma_pcie_phy *zp) +{ + bool 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_pcie_phy_sel_ext_pll(zp); + zuma_pcie_phy_pma_reset(zp); + + 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_write_table(zp->pma, zuma_pma_lane_bcm, + ARRAY_SIZE(zuma_pma_lane_bcm)); + 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_pcie_phy_pma_release(zp); + zuma_pcie_phy_lock_checks(zp, zp->pma, ext); + + writel(0, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); +} + +/* PMU: take the PHY out of isolation. Nothing puts it back. */ +static int zuma_pcie_phy_bypass(struct zuma_pcie_phy *zp) +{ + 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; +} + +/* exynos_pcie_rc_establish_link(): mark the PHY configured */ +static int zuma_pcie_phy_mark_configured(struct zuma_pcie_phy *zp) +{ + int ret; + + zuma_phy_trace(zp, "about to set PMU %#x bit 10 (PHY configured, SMC)", + zp->pmu_offset); + ret = regmap_update_bits(zp->pmu, zp->pmu_offset, + ZUMA_PMU_PHY_CONFIGURED, + ZUMA_PMU_PHY_CONFIGURED); + if (ret) { + dev_err(zp->dev, "PMU write failed: %d\n", ret); + return ret; + } + zuma_phy_trace(zp, "PHY configured"); + + return 0; +} + +static int zuma_pcie_phy_init(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + int ret; + + ret = zuma_pcie_phy_bypass(zp); + if (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); + + if (!zp->stock_link_steps) + return 0; + + return zuma_pcie_phy_mark_configured(zp); +} + +static int zuma_pcie_phy_power_off(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + /* + * exynos_pcie_rc_poweroff(): put the PHY's input clock back on the + * oscillator before the power-down + */ + if (zp->stock_link_steps) { + zuma_phy_trace(zp, "about to return the PHY clock to the oscillator (SOC 0x4000)"); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_MODE, + ZUMA_SOC_CLK_MODE_SEL, 0); + } + + zuma_pcie_phy_pwrdn(zp); + + return 0; +} + +static const struct phy_ops zuma_pcie_phy_ops = { + .init = zuma_pcie_phy_init, + .power_on = zuma_pcie_phy_power_on, + .power_off = zuma_pcie_phy_power_off, + .owner = THIS_MODULE, +}; + +/* + * The two-lane PHY (zumapro's channel 0, the modem's link). Its CAL adds + * i * 0x1000 to its PMA base for lane i in its lane loop and never takes + * it back, so after the loop, with two lanes, the lock checks and the + * input clock gate land 0x1000 above the same accesses on the one-lane + * PHY (0x1a80, 0x25c0, 0x240c and 0x132c). That is what stock runs, and + * what brought the modem's link up here, so it is kept. + */ + +/* exynos_pcie_rc_phy_all_pwrdn(), channel 0 */ +static void zuma_pcie_phy_x2_pwrdn(struct zuma_pcie_phy *zp) +{ + unsigned int lane; + u32 pcs, val; + + 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); + + writel(ZUMA_X2_PCS_PLL_OFF_BIAS_ON, zp->pcs + ZUMA_X2_PCS_PLL_BIAS); + udelay(5); + pcs = readl(zp->pcs + ZUMA_X2_PCS_PLL_BIAS); + + for (lane = 0; lane < ZUMA_X2_PMA_LANES; lane++) { + zuma_pcie_phy_write_table(zp->pma + lane * ZUMA_X2_PMA_LANE_STRIDE, + zuma_pma_pwrdn, + ARRAY_SIZE(zuma_pma_pwrdn)); + udelay(1); + } + writel(0xff, zp->pma + 0x0208); + writel(0xff, zp->pma + 0x0228); + 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); + + /* + * Force the PLL lock signal off. The CAL clears bits 5:4 into a value + * it then replaces with the register ORed with 0x20, so only bit 5 is + * set: that is what runs, so it is what this does. + */ + zuma_pcie_phy_rmw(zp->pma + ZUMA_X2_PMA_PLL_LOCK_SIG, 0, + ZUMA_X2_PMA_PLL_LOCK_SIG_OFF); + + writel(ZUMA_X2_PCS_PLL_OFF_BIAS_OFF, zp->pcs + ZUMA_X2_PCS_PLL_BIAS); + udelay(5); + val = readl(zp->pcs + ZUMA_X2_PCS_PLL_BIAS); + dev_dbg(zp->dev, "power-down: PCS 0x150 %#x then %#x\n", pcs, val); + + /* The external PLL goes off only once the PMA PLL has let go of it */ + if (readl_poll_timeout_atomic(zp->pma + ZUMA_X2_PMA_PLL_ENGAGED, val, + !(val & ZUMA_X2_PMA_PLL_ENGAGED_BIT), + 1, 100)) { + dev_err(zp->dev, "power-down: the PMA PLL did not turn off, external PLL left on\n"); + return; + } + + zuma_phy_trace(zp, "about to turn the external PLL off (UDBG 0xc700)"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, 0, + ZUMA_UDBG_EXT_PLL_RESETB_OVR); + fsleep(10); +} + +/* exynos_pcie_rc_phy_all_pwrdn_clear(), channel 0 */ +static void zuma_pcie_phy_x2_pwrdn_clear(struct zuma_pcie_phy *zp) +{ + unsigned int lane; + size_t i; + + zuma_phy_trace(zp, "about to start the external PLL (UDBG 0xc700), clear the power-downs"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_EXT_PLL, + ZUMA_UDBG_EXT_PLL_RESETB_OVR, 0); + fsleep(100); + /* Let the PLL lock signal through again */ + zuma_pcie_phy_rmw(zp->pma + ZUMA_X2_PMA_PLL_LOCK_SIG, + ZUMA_X2_PMA_PLL_LOCK_SIG_MASK, 0); + writel(0x00, zp->pma + ZUMA_PMA_CMN_BIAS); + writel(0x55, zp->pma + 0x0928); + writel(0x02, zp->pma + 0x0580); + writel(0x00, zp->pma + 0x0208); + writel(0x00, zp->pma + 0x0228); + for (lane = 0; lane < ZUMA_X2_PMA_LANES; lane++) + for (i = 0; i < ARRAY_SIZE(zuma_pma_pwrdn); i++) + writel(0, zp->pma + lane * ZUMA_X2_PMA_LANE_STRIDE + + zuma_pma_pwrdn[i].off); + fsleep(10); +} + +/* exynos_pcie_rc_pcie_phy_config(), channel 0, two lanes, less its ELBI writes */ +static void zuma_pcie_phy_x2_config(struct zuma_pcie_phy *zp) +{ + void __iomem *pma_after_loop = zp->pma + ZUMA_X2_PMA_LANE_STRIDE; + unsigned int lane; + bool ext; + + zuma_phy_trace(zp, "about to ungate the PHY clock, start the external PLL (UDBG 0xc710)"); + writel(ZUMA_PMA_INPUT_CLK_UNGATE, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_X2_UDBG_EXT_PLL_CTRL, + ZUMA_X2_UDBG_EXT_PLL_INIT, 0); + 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_X2_UDBG_EXT_PLL_STATUS, + ZUMA_X2_UDBG_EXT_PLL_LOCK); + + zuma_pcie_phy_sel_ext_pll(zp); + zuma_pcie_phy_pma_reset(zp); + + zuma_phy_trace(zp, "about to write the PMA tables (common, two lanes)"); + zuma_pcie_phy_write_table(zp->pma, zuma_x2_pma_common, + ARRAY_SIZE(zuma_x2_pma_common)); + for (lane = 0; lane < ZUMA_X2_PMA_LANES; lane++) + zuma_pcie_phy_write_table(zp->pma + lane * ZUMA_X2_PMA_LANE_STRIDE, + zuma_pma_lane, + ARRAY_SIZE(zuma_pma_lane)); + + zuma_phy_trace(zp, "about to write the PCS table"); + zuma_pcie_phy_write_table(zp->pcs, zuma_x2_pcs, ARRAY_SIZE(zuma_x2_pcs)); + + zuma_pcie_phy_pma_release(zp); + zuma_pcie_phy_lock_checks(zp, pma_after_loop, ext); + + zuma_phy_trace(zp, "about to gate the external PLL clock in L2 (UDBG 0xc710)"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_X2_UDBG_EXT_PLL_CTRL, + ZUMA_X2_UDBG_EXT_PLL_L2_GATE, + ZUMA_X2_UDBG_EXT_PLL_L2_GATE); + writel(0, pma_after_loop + ZUMA_PMA_INPUT_CLK_GATE); +} + +static int zuma_pcie_phy_x2_init(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + int ret; + + ret = zuma_pcie_phy_bypass(zp); + if (ret) + return ret; + + zuma_pcie_phy_x2_pwrdn(zp); + zuma_phy_trace(zp, "PHY out of isolation and powered down"); + + return 0; +} + +static int zuma_pcie_phy_x2_power_on(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + int ret; + + zuma_phy_trace(zp, "about to write SOC 0x4000 (first SOC access)"); + writel(ZUMA_SOC_CLK_MODE_VAL, zp->soc + ZUMA_SOC_CLK_MODE); + + zuma_pcie_phy_x2_pwrdn_clear(zp); + zuma_pcie_phy_x2_config(zp); + + /* exynos_pcie_rc_establish_link(), channel 0, before PERST# */ + ret = zuma_pcie_phy_mark_configured(zp); + if (ret) + return ret; + + zuma_phy_trace(zp, "about to clear UDBG 0xc800 bits 6:5, gate the PHY clock (PMA 0x32c)"); + zuma_pcie_phy_rmw(zp->udbg + ZUMA_UDBG_LINK_CTRL, + ZUMA_X2_UDBG_LINK_CTRL_CLR, 0); + writel(0, zp->pma + ZUMA_PMA_INPUT_CLK_GATE); + + return 0; +} + +/* + * exynos_pcie_rc_poweron(), channel 0, once the link is up: keep the PLL + * and bias on, so that the power-down turns them off in a known order. + * The host calls phy_calibrate() after the link has trained. + */ +static int zuma_pcie_phy_x2_calibrate(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_phy_trace(zp, "about to write PCS 0x150 (PLL and bias on)"); + writel(ZUMA_X2_PCS_PLL_BIAS_ON, zp->pcs + ZUMA_X2_PCS_PLL_BIAS); + + return 0; +} + +/* + * exynos_pcie_rc_poweroff(), both channels: put the clock selected in SOC + * 0x4000 back on the oscillator before the power-down, as the one-lane + * PHY does on zumapro. power_on selects the PHY's clock there, and the + * power-down then stops the external PLL behind it. The host writes ELBI + * before the next phy_power_on(); with the PHY's clock still selected, a + * second power cycle hung the SoC there, after a first one that started + * from the boot setting had passed. power_on writes SOC 0x4000 again + * first. + */ +static int zuma_pcie_phy_x2_power_off(struct phy *phy) +{ + struct zuma_pcie_phy *zp = phy_get_drvdata(phy); + + zuma_phy_trace(zp, "about to return the PHY clock to the oscillator (SOC 0x4000)"); + zuma_pcie_phy_rmw(zp->soc + ZUMA_SOC_CLK_MODE, ZUMA_SOC_CLK_MODE_SEL, 0); + zuma_pcie_phy_x2_pwrdn(zp); + + return 0; +} + +static const struct phy_ops zuma_pcie_phy_x2_ops = { + .init = zuma_pcie_phy_x2_init, + .power_on = zuma_pcie_phy_x2_power_on, + .power_off = zuma_pcie_phy_x2_power_off, + .calibrate = zuma_pcie_phy_x2_calibrate, + .owner = THIS_MODULE, +}; + +static int zuma_pcie_phy_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + const struct zuma_pcie_phy_data *data; + struct phy_provider *provider; + struct zuma_pcie_phy *zp; + struct phy *phy; + int ret; + + data = device_get_match_data(dev); + if (!data) + return -ENODEV; + + zp = devm_kzalloc(dev, sizeof(*zp), GFP_KERNEL); + if (!zp) + return -ENOMEM; + + zp->dev = dev; + zp->stock_link_steps = data->stock_link_steps; + + /* Only mappings here: the PHY is not touched until phy_init() */ + zp->pma = devm_platform_ioremap_resource_byname(pdev, "pma"); + if (IS_ERR(zp->pma)) + return PTR_ERR(zp->pma); + + zp->pcs = devm_platform_ioremap_resource_byname(pdev, "pcs"); + if (IS_ERR(zp->pcs)) + return PTR_ERR(zp->pcs); + + zp->rst = devm_platform_ioremap_resource_byname(pdev, "rst"); + if (IS_ERR(zp->rst)) + return PTR_ERR(zp->rst); + + zp->udbg = devm_platform_ioremap_resource_byname(pdev, "udbg"); + if (IS_ERR(zp->udbg)) + return PTR_ERR(zp->udbg); + + zp->soc = devm_platform_ioremap_resource_byname(pdev, "soc"); + if (IS_ERR(zp->soc)) + return PTR_ERR(zp->soc); + + zp->pmu = exynos_get_pmu_regmap_by_phandle(dev->of_node, + "samsung,pmu-syscon"); + if (IS_ERR(zp->pmu)) + return dev_err_probe(dev, PTR_ERR(zp->pmu), + "failed to get the PMU regmap\n"); + + ret = of_property_read_u32_index(dev->of_node, "samsung,pmu-syscon", 1, + &zp->pmu_offset); + if (ret) + return dev_err_probe(dev, ret, + "missing PMU PHY control offset\n"); + + phy = devm_phy_create(dev, NULL, data->ops); + if (IS_ERR(phy)) + return dev_err_probe(dev, PTR_ERR(phy), "failed to create PHY\n"); + + phy_set_drvdata(phy, zp); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + + return PTR_ERR_OR_ZERO(provider); +} + +static const struct zuma_pcie_phy_data zuma_pcie_phy_data = { + .ops = &zuma_pcie_phy_ops, +}; + +static const struct zuma_pcie_phy_data zumapro_pcie_phy_data = { + .ops = &zuma_pcie_phy_ops, + .stock_link_steps = true, +}; + +static const struct zuma_pcie_phy_data zumapro_pcie_gen3x2_phy_data = { + .ops = &zuma_pcie_phy_x2_ops, +}; + +static const struct of_device_id zuma_pcie_phy_of_match[] = { + { .compatible = "google,zumapro-pcie-gen3x2-phy", .data = &zumapro_pcie_gen3x2_phy_data }, + { .compatible = "google,zumapro-pcie-phy", .data = &zumapro_pcie_phy_data }, + { .compatible = "google,zuma-pcie-phy", .data = &zuma_pcie_phy_data }, + { } +}; +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/google/cpif/Kconfig b/drivers/soc/google/cpif/Kconfig index 6c618fa9c9..c0209f8c02 100644 --- a/drivers/soc/google/cpif/Kconfig +++ b/drivers/soc/google/cpif/Kconfig @@ -57,7 +57,10 @@ config LINK_DEVICE_PCIE_IOCC The gs201 modem link driver turns IO coherency on for the link at every link-up, before the modem may DMA, so the packet processor treats its cacheable regions as coherent, as stock does - (pantah_defconfig: CONFIG_LINK_DEVICE_PCIE_IOCC=y). + (pantah_defconfig: CONFIG_LINK_DEVICE_PCIE_IOCC=y). On zumapro it + does so only when the device tree gives it samsung,sysreg; a link + without it sets pktproc_dl_use_hw_iocc and pktproc_ul_use_hw_iocc + to 0 and keeps the packet processor's regions uncached. config CP_PKTPROC bool "Packet processor, downlink (bring-up)" diff --git a/drivers/soc/google/cpif/link_device.c b/drivers/soc/google/cpif/link_device.c index 86dfab96cb..01d7fd80f2 100644 --- a/drivers/soc/google/cpif/link_device.c +++ b/drivers/soc/google/cpif/link_device.c @@ -4415,8 +4415,10 @@ struct link_device *create_link_device(struct platform_device *pdev, u32 link_ty return ld; error: - if (mld->dummy_net) + if (mld->dummy_net) { + napi_disable(&mld->mld_napi); free_netdev(mld->dummy_net); + } kfree(mld); mif_err("xxx\n"); return NULL; diff --git a/drivers/soc/google/cpif/link_rx_pktproc.c b/drivers/soc/google/cpif/link_rx_pktproc.c index 9581e13bb2..ebaf595e13 100644 --- a/drivers/soc/google/cpif/link_rx_pktproc.c +++ b/drivers/soc/google/cpif/link_rx_pktproc.c @@ -1816,11 +1816,23 @@ static int pktproc_get_info(struct pktproc_adaptor *ppa, struct device_node *np) } #endif - /* Check if config and dt are consistent */ - if (ppa->use_hw_iocc != IS_ENABLED(CONFIG_LINK_DEVICE_PCIE_IOCC)) { + /* + * Check if config and dt are consistent. A link without IO coherency + * (zumapro's without samsung,sysreg) says use_hw_iocc 0, and is fine + * as long as its buffers are uncached: the cache maintenance that + * cached buffers would need is built only without + * LINK_DEVICE_PCIE_IOCC. pktproc_create() refuses cached info and + * descriptor regions without IO coherency either way. + */ + if (ppa->use_hw_iocc && !IS_ENABLED(CONFIG_LINK_DEVICE_PCIE_IOCC)) { mif_err("PCIe IOCC config and dt are inconsistent\n"); return -EINVAL; } + if (!ppa->use_hw_iocc && ppa->buff_rgn_cached && + IS_ENABLED(CONFIG_LINK_DEVICE_PCIE_IOCC)) { + mif_err("cached buffers without IOCC need LINK_DEVICE_PCIE_IOCC off\n"); + return -EINVAL; + } pktproc_adjust_size(ppa); diff --git a/drivers/soc/google/cpif/link_tx_pktproc.c b/drivers/soc/google/cpif/link_tx_pktproc.c index 5cef061970..a04f982edf 100644 --- a/drivers/soc/google/cpif/link_tx_pktproc.c +++ b/drivers/soc/google/cpif/link_tx_pktproc.c @@ -422,7 +422,7 @@ int pktproc_create_ul(struct platform_device *pdev, struct mem_link_device *mld, return ret; } -#if !IS_ENABLED(CONFIG_LINK_DEVICE_PCIE_IOCC) + /* The uplink has no cache maintenance, whatever the config */ if (!ppa_ul->use_hw_iocc && ppa_ul->info_rgn_cached) { mif_err("cannot support sw iocc based caching on info region\n"); return -EINVAL; @@ -437,7 +437,6 @@ int pktproc_create_ul(struct platform_device *pdev, struct mem_link_device *mld, mif_err("cannot support sw iocc based caching on buff region\n"); return -EINVAL; } -#endif /* Get base addr */ mif_info("memaddr:0x%lx memsize:0x%08x\n", memaddr, memsize); diff --git a/drivers/soc/google/cpif/pcie-gs201-compat.c b/drivers/soc/google/cpif/pcie-gs201-compat.c index b580059a45..1cbef16cb6 100644 --- a/drivers/soc/google/cpif/pcie-gs201-compat.c +++ b/drivers/soc/google/cpif/pcie-gs201-compat.c @@ -115,6 +115,12 @@ void exynos_pcie_rc_force_linkdown_work(int ch_num) gs201_pcie_cp_force_linkdown(); } +/* The doorbell write under the controller's link lock (see gs201_pcie_cp_doorbell()) */ +int exynos_pcie_rc_doorbell(int ch_num, void __iomem *addr, u32 val, u32 *readback) +{ + return cp_ch_ok(ch_num) ? gs201_pcie_cp_doorbell(addr, val, readback) : -ENODEV; +} + int exynos_pcie_rc_chk_link_status(int ch_num) { return cp_ch_ok(ch_num) && gs201_pcie_cp_link_ok(); diff --git a/drivers/soc/google/cpif/s51xx_pcie.c b/drivers/soc/google/cpif/s51xx_pcie.c index 8608a63e43..b84e12031f 100644 --- a/drivers/soc/google/cpif/s51xx_pcie.c +++ b/drivers/soc/google/cpif/s51xx_pcie.c @@ -114,9 +114,21 @@ inline int s51xx_pcie_send_doorbell_int(struct pci_dev *pdev, int int_num) } send_doorbell_again: - iowrite32(int_num, s51xx_pcie->doorbell_addr); - - reg = ioread32(s51xx_pcie->doorbell_addr); + /* + * The write and its read-back go through the link driver, under the + * lock its link-down takes, so that a power-off the modem asked for + * can't take the link down between the check above and the access: + * an access to the modem's window with the link down can hang the + * SoC. When the link went down meanwhile, the doorbell is kept for + * the next link up, as pcie_send_ap2cp_irq() does when the link is + * already down. + */ + if (exynos_pcie_rc_doorbell(s51xx_pcie->pcie_channel_num, + s51xx_pcie->doorbell_addr, int_num, ®)) { + mif_info_limited("Reserve doorbell interrupt: link went down\n"); + mc->reserve_doorbell_int = true; + return 0; + } /* debugging: * mif_info("s51xx_pcie.doorbell_addr = 0x%p - diff --git a/drivers/soc/google/cpif/s51xx_pcie.h b/drivers/soc/google/cpif/s51xx_pcie.h index d8b3b92c2e..81c7dcccb3 100644 --- a/drivers/soc/google/cpif/s51xx_pcie.h +++ b/drivers/soc/google/cpif/s51xx_pcie.h @@ -48,6 +48,7 @@ struct s51xx_pcie { //extern struct s51xx_pcie s5100pcie; extern int exynos_pcie_rc_chk_link_status(int ch_num); +extern int exynos_pcie_rc_doorbell(int ch_num, void __iomem *addr, u32 val, u32 *readback); extern int exynos_pcie_rc_l1ss_ctrl(int enable, int id, int ch_num); extern int exynos_pcie_poweron(int ch_num, int spd, int width); diff --git a/drivers/soc/samsung/gs101-pmu.c b/drivers/soc/samsung/gs101-pmu.c index 9ee77754d0..6cf15a30b5 100644 --- a/drivers/soc/samsung/gs101-pmu.c +++ b/drivers/soc/samsung/gs101-pmu.c @@ -344,6 +344,8 @@ const struct exynos_pmu_data gs101_pmu_data = { #define ZUMA_HSI0_STATUS 0x2a84 #define ZUMA_PAD_CTRL_NFC_CLK 0x3e84 #define ZUMA_PHY_CTRL_UFS 0x3ec0 +#define ZUMA_PHY_CTRL_PCIE0 0x3ec4 +#define ZUMA_PHY_CTRL_PCIE1 0x3ec8 static const struct regmap_range zuma_pmu_registers[] = { /* reboot mode */ @@ -359,6 +361,8 @@ 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_PCIE0, ZUMA_PHY_CTRL_PCIE0), + regmap_reg_range(ZUMA_PHY_CTRL_PCIE1, ZUMA_PHY_CTRL_PCIE1), /* a hint TF-A reads, not a status register: see zuma_pmu_regmap_init() */ regmap_reg_range(ZUMA_PMU_INFORM0, ZUMA_PMU_INFORM0), /* Tensor G4's NFC reference clock pad, a clock of clk-exynos-clkout */ diff --git a/include/linux/soc/google/gs201-pcie-cp.h b/include/linux/soc/google/gs201-pcie-cp.h index 015f379931..2e37df02a5 100644 --- a/include/linux/soc/google/gs201-pcie-cp.h +++ b/include/linux/soc/google/gs201-pcie-cp.h @@ -34,6 +34,7 @@ struct gs201_pcie_cp_event { int gs201_pcie_cp_poweron(unsigned int speed); void gs201_pcie_cp_poweroff(void); bool gs201_pcie_cp_link_ok(void); +int gs201_pcie_cp_doorbell(void __iomem *addr, u32 val, u32 *readback); int gs201_pcie_cp_check_msi_addr(u64 addr); int gs201_pcie_cp_register_queue(irq_handler_t handler, void *ctx, int *irq); void gs201_pcie_cp_set_perst_level(int level); @@ -49,6 +50,8 @@ void gs201_pcie_cp_dump(void); static inline int gs201_pcie_cp_poweron(unsigned int speed) { return -ENODEV; } static inline void gs201_pcie_cp_poweroff(void) { } static inline bool gs201_pcie_cp_link_ok(void) { return false; } +static inline int gs201_pcie_cp_doorbell(void __iomem *addr, u32 val, + u32 *readback) { return -ENODEV; } static inline int gs201_pcie_cp_check_msi_addr(u64 addr) { return -ENODEV; } static inline int gs201_pcie_cp_register_queue(irq_handler_t handler, void *ctx, int *irq)