kernel_samsung_a53x/drivers/pci
Manivannan Sadhasivam cf04e2b31c PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio
commit 840b7a5edf88fe678c60dee88a135647c0ea4375 upstream.

Rockchip platforms use 'GPIO_ACTIVE_HIGH' flag in the devicetree definition
for ep_gpio. This means, whatever the logical value set by the driver for
the ep_gpio, physical line will output the same logic level.

For instance,

  gpiod_set_value_cansleep(rockchip->ep_gpio, 0); --> Level low
  gpiod_set_value_cansleep(rockchip->ep_gpio, 1); --> Level high

But while requesting the ep_gpio, GPIOD_OUT_HIGH flag is currently used.
Now, this also causes the physical line to output 'high' creating trouble
for endpoint devices during host reboot.

When host reboot happens, the ep_gpio will initially output 'low' due to
the GPIO getting reset to its POR value. Then during host controller probe,
it will output 'high' due to GPIOD_OUT_HIGH flag. Then during
rockchip_pcie_host_init_port(), it will first output 'low' and then 'high'
indicating the completion of controller initialization.

On the endpoint side, each output 'low' of ep_gpio is accounted for PERST#
assert and 'high' for PERST# deassert. With the above mentioned flow during
host reboot, endpoint will witness below state changes for PERST#:

  (1) PERST# assert - GPIO POR state
  (2) PERST# deassert - GPIOD_OUT_HIGH while requesting GPIO
  (3) PERST# assert - rockchip_pcie_host_init_port()
  (4) PERST# deassert - rockchip_pcie_host_init_port()

Now the time interval between (2) and (3) is very short as both happen
during the driver probe(), and this results in a race in the endpoint.
Because, before completing the PERST# deassertion in (2), endpoint got
another PERST# assert in (3).

A proper way to fix this issue is to change the GPIOD_OUT_HIGH flag in (2)
to GPIOD_OUT_LOW. Because the usual convention is to request the GPIO with
a state corresponding to its 'initial/default' value and let the driver
change the state of the GPIO when required.

As per that, the ep_gpio should be requested with GPIOD_OUT_LOW as it
corresponds to the POR value of '0' (PERST# assert in the endpoint). Then
the driver can change the state of the ep_gpio later in
rockchip_pcie_host_init_port() as per the initialization sequence.

This fixes the firmware crash issue in Qcom based modems connected to
Rockpro64 based board.

Fixes: e77f847df54c ("PCI: rockchip: Add Rockchip PCIe controller support")
Closes: https://lore.kernel.org/mhi/20240402045647.GG2933@thinkpad/
Link: https://lore.kernel.org/linux-pci/20240416-pci-rockchip-perst-fix-v1-1-4800b1d4d954@linaro.org
Reported-by: Slark Xiao <slark_xiao@163.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Cc: stable@vger.kernel.org	# v4.9
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-23 23:20:14 +01:00
..
controller PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio 2024-11-23 23:20:14 +01:00
endpoint
hotplug
pcie PCI/EDR: Align EDR_PORT_LOCATE_DSM with PCI Firmware r3.3 2024-11-19 12:27:04 +01:00
switch PCI: switchtec: Fix an error handling path in switchtec_pci_probe() 2024-11-19 08:44:52 +01:00
access.c
ats.c
bus.c
ecam.c
host-bridge.c
iov.c
irq.c
Kconfig
Makefile
mmap.c
msi.c PCI/MSI: Prevent MSI hardware interrupt number truncation 2024-11-18 22:25:37 +01:00
of.c
p2pdma.c
pci-acpi.c
pci-bridge-emul.c
pci-bridge-emul.h
pci-driver.c Manual Revert: PCI: Drop pci_device_remove() test of pci_dev->driver 2024-11-19 10:17:16 +01:00
pci-label.c
pci-mid.c
pci-pf-stub.c
pci-stub.c
pci-sysfs.c
pci.c PCI/PM: Avoid D3cold for HP Pavilion 17 PC/1972 PCIe Ports 2024-11-19 14:19:07 +01:00
pci.h PCI/ERR: Cache RCEC EA Capability offset in pci_init_capabilities() 2024-11-19 09:22:18 +01:00
probe.c PCI/ERR: Cache RCEC EA Capability offset in pci_init_capabilities() 2024-11-19 09:22:18 +01:00
proc.c
quirks.c Manual Revert: PCI/ASPM: Make Intel DG2 L1 acceptable latency unlimited 2024-11-19 10:37:22 +01:00
remove.c
rom.c
search.c
setup-bus.c PCI: Fix resource double counting on remove & rescan 2024-11-23 23:20:10 +01:00
setup-irq.c
setup-res.c PCI: Work around Intel I210 ROM BAR overlap defect 2024-11-19 09:22:33 +01:00
slot.c
syscall.c
vc.c
vpd.c
xen-pcifront.c