Patch to add configurable delay to PCIe bus scan (RK3399/RockPro64)
Here's a patch that adds support for configurable delay before running PCIe bus scan on RK3399 based devices and also set the delay to 1000ms on RockPro64. Delay can be set on device tree with bus-scan-delay-ms property in pcie0node or with pcie_rockchip_host.bus_scan_delay=NNN (NNN = delay in ms) parameter on kernel command line.
For me this delay was needed for LSI SAS2008 based host bus adapter cards (model LSI SAS9201-8i). The amount of delay seemed to vary a bit depending on kernel version. Maximum amount I've needed for getting things stable was about 830ms (IIRC) so 1000ms default in RP64 device tree felt like a safe bet here. Without delay (or too small delay) kernel would crash when scanning PCIe bus.
Here's a call trace of one crash for reference:
 rockchip_pcie_rd_conf+0x188/0x240
 pci_bus_read_config_dword+0xa0/0x138
 pci_bus_generic_read_dev_vendor_id+0x2c/0x1a0
 pci_bus_read_dev_vendor_id+0x48/0x68
 pci_scan_single_device+0x78/0xf8
 pci_scan_slot+0x34/0x128
 pci_scan_child_bus_extend+0x54/0x350
 pci_scan_bridge_extend+0x2fc/0x598
 pci_scan_child_bus_extend+0x204/0x350
 pci_scan_root_bus_bridge+0x58/0xe8
 rockchip_pcie_probe+0x3dc/0x5c0
 platform_drv_probe+0x50/0xa0
 really_probe+0x27c/0x468
 driver_probe_device+0x12c/0x148
 device_driver_attach+0x6c/0x90
 __driver_attach+0xb0/0x160
 bus_for_each_dev+0x74/0xc8
 driver_attach+0x20/0x28
 bus_add_driver+0x154/0x238
 driver_register+0x60/0x110
 __platform_driver_register+0x40/0x48
 rockchip_pcie_driver_init+0x18/0x20
 do_one_initcall+0x5c/0x1b0
 kernel_init_freeable+0x22c/0x2c0
 kernel_init+0x10/0x100
 ret_from_fork+0x10/0x1cNOTE: I also modified existing patch (0002-arm64-dts-rockchip-modify-pcie-node-rockpro64.patch) and removed bus-scan-delay-ms property addition from it to have the property and actual implementation in one patch. I've attached the modified older patch here too.
0002-arm64-dts-rockchip-modify-pcie-node-rockpro64.patch 0019-rockpro64-dts-rk-pcie-add-configurable-delay.patch