We are using IMX8MP in PCIe Endpoint configuration.
# uname -a
Linux ucm-imx8m-plus 5.10.72-00018-g63479fd7af5b-dirty #51 SMP PREEMPT Fri Aug 12 12:00:12 PDT 2022 aarch64 aarch64 aarch64 GNU/Linux
The IMX8MP is connected through the CompuLab development board through a PCIe cable
to the host PC 1-lane wide PCIe slot. The development board is booted first and the PCIe PLL is verified:
$ dmesg | grep pci
[ 0.176414] imx8-pcie-phy 32f00000.pcie-phy: failed to get imx pcie phy clock
[ 2.374044] imx6q-pcie 33800000.pcie_ep: supply epdev_on not found, using dummy regulator
[ 2.390547] imx6q-pcie 33800000.pcie_ep: PLL REF_CLK is used!.
[ 2.397023] imx6q-pcie 33800000.pcie_ep: PCIe PHY PLL clock is locked.
[ 2.431731] imx6q-pcie 33800000.pcie_ep: PCIe PLL locked after 0 us.
[ 2.611260] imx6q-pcie 33800000.pcie_ep: invalid resource
[ 2.611263] imx6q-pcie 33800000.pcie_ep: iATU unroll: enabled
The pci endpoint configuration script is run:
set -ex
PCIE_EP=`ls /sys/class/pci_epc/`
ls /sys/kernel/config/pci_ep/controllers
ls /sys/bus/pci-epf/drivers
ls /sys/kernel/config/pci_ep/functions
cd /sys/kernel/config/pci_ep/
echo 0 > controllers/${PCIE_EP}/start
mkdir -p functions/pci_epf_test/func1
ls functions/pci_epf_test/func1
cat functions/pci_epf_test/func1/vendorid
cat functions/pci_epf_test/func1/interrupt_pin
echo 0x1957 > functions/pci_epf_test/func1/vendorid
echo 0x81c0 > functions/pci_epf_test/func1/deviceid
echo 16 > functions/pci_epf_test/func1/msi_interrupts
echo 8 > functions/pci_epf_test/func1/msix_interrupts
rm -f controllers/${PCIE_EP}/func1
ln -s functions/pci_epf_test/func1 controllers/${PCIE_EP}/
echo 1 > controllers/${PCIE_EP}/start
The host computer is booted and the device appears on lspci:
$ sudo lspci -vxxx -d 0x1957:0x81c0
01:00.0 Unassigned class [ff00]: Freescale Semiconductor Inc Device 81c0
Flags: fast devsel, IRQ 27
Memory at feaf0000 (64-bit, non-prefetchable) [disabled] [size=64K]
[virtual] Expansion ROM at feae0000 [disabled] [size=64K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/16 Maskable+ 64bit+
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [148] #19
Capabilities: [158] L1 PM Substates
Kernel driver in use: pci-endpoint-test
00: 57 19 c0 81 00 00 10 00 00 00 00 ff 00 00 00 00
10: 04 00 af fe 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 ff 01 00 00
40: 01 50 c3 db 00 00 00 00 00 00 00 00 00 00 00 00
50: 05 70 88 01 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 10 00 02 00 00 80 28 00 10 20 11 00 13 cc 41 00
80: 00 00 11 10 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 1f 00 00 00 00 00 00 00 0e 00 00 00
a0: 03 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
When loading the pci_endpoint_test driver on the host system,
which calls pci_enable_device() and pci_set_master(), we see the bus
master bit and memory access bit in the command register (offset 0x04) are set:
sudo insmod ./pci_endpoint_test.ko
sudo lspci -vxxx -d 0x1957:0x81c0
01:00.0 Unassigned class [ff00]: Freescale Semiconductor Inc Device 81c0
Flags: bus master, fast devsel, latency 0, IRQ 27
Memory at feaf0000 (64-bit, non-prefetchable) [size=64K]
[virtual] Expansion ROM at feae0000 [disabled] [size=64K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable+ Count=1/16 Maskable+ 64bit+
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [148] #19
Capabilities: [158] L1 PM Substates
Kernel driver in use: pci-endpoint-test
00: 57 19 c0 81 06 04 10 00 00 00 00 ff 00 00 00 00
10: 04 00 af fe 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 ff 01 00 00
40: 01 50 c3 db 00 00 00 00 00 00 00 00 00 00 00 00
50: 05 70 89 01 04 80 e0 fe 00 00 00 00 21 40 00 00
60: fe ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 10 00 02 00 00 80 28 00 1f 20 11 00 13 cc 41 00
80: 00 00 11 10 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 1f 00 00 00 00 00 00 00 0e 00 00 00
a0: 03 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
sleep 2
sudo lspci -vxxx -d 0x1957:0x81c0
01:00.0 Unassigned class [ff00]: Freescale Semiconductor Inc Device 81c0
Flags: fast devsel, IRQ 27
Memory at feaf0000 (64-bit, non-prefetchable) [disabled] [size=64K]
[virtual] Expansion ROM at feae0000 [disabled] [size=64K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/16 Maskable+ 64bit+
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [148] #19
Capabilities: [158] L1 PM Substates
Kernel driver in use: pci-endpoint-test
00: 57 19 c0 81 00 00 10 00 00 00 00 ff 00 00 00 00
10: 04 00 af fe 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 40 00 00 00 00 00 00 00 ff 01 00 00
40: 01 50 c3 db 00 00 00 00 00 00 00 00 00 00 00 00
50: 05 70 88 01 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 10 00 02 00 00 80 28 00 10 20 11 00 13 cc 41 00
80: 00 00 11 10 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 1f 00 00 00 00 00 00 00 0e 00 00 00
a0: 03 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Mysteriously the command register is cleared. Since the PCI_COMMAND MEMORY access bit is cleared,
any reads from the memory mapped BAR0 space return 0xFFs.
I've traced the host PC kernel and verified that nothing is calling the pci_bus_write_config_(byte|word|dword) functions after exiting the driver probe function.
On the device I can check the HSIO registers to see the PCIe error and status registers:
After the driver module load:
# ./hsio
00: 00000033
04: 00002023 PLL_LOCK=1 PCIE_CTRL_PM_DSTATE=0 SMLH_LTSSM_STATE=0x11 PM_EN_CORE_CLK=1
08: 1fccc80c
0c: 80021000
10: 00000000
14: 00000000
18: 00000000
1c: 00000000
20: 00000000
24: 00000000
A few seconds later:
# ./hsio
00: 00000033
04: 0000201b PLL_LOCK=1 PCIE_CTRL_PM_DSTATE=0 SMLH_LTSSM_STATE=0x0d PM_EN_CORE_CLK=1
08: 1fccc80c
0c: 80021000
10: 00000000
14: 00000000
18: 00000000
1c: 00000000
20: 00000000
24: 00000000
Again immediately after that:
# ./hsio
00: 00000033
04: 00003023 PLL_LOCK=1 PCIE_CTRL_PM_DSTATE=4 SMLH_LTSSM_STATE=0x11 PM_EN_CORE_CLK=1
08: 1fccc80c
0c: 80021000
10: 00000003 LDD=1 LUD=1
14: 00000000
18: 00000000
1c: 00000000
20: 00000000
24: 00000000
The HSIO BLK_CTRL register PCIE controller status (GPR_REG1 0x04) changes when the problem occurs: The SMLH_LTSSM_STATE goes from 0x11 to 0x0d and back to 0x11. According to pcie-designware.h, the PORT_LOGIC_LTSSM_STATE_L0 is 0x11, and PORT_LOGIC_LTSSM_STATE_L2 is 0x15. Not sure what 0x0d could be.
The IMX8MPRM says merely "SMLH_LTSSM_STATE: PCIE link state".
The PCIE_CTRL_PM_DSTATE goes from 0 to 4, and stays there.
The IMX8MPRM says merely "PCIE_CTRL_PM_DSTATE: PCIE ctrl's pm dstate".
The register PCIE PME message and error detect register (GPR_REG4 0x10) also shows that the Link also appears to have gone down and back up, being both Link Down Detected (LDD) and Link Up Detected (LUD) are set.
Can anyone tell me what is going on here? What could be triggering the linkdown/linkup? What does SMLH_LTSSM_STATE=0x0d and PCIE_CTRL_PM_DSTATE=4 mean?