Skip to contentSkip to conversation

PCI: cadence: Add LTSSM debugfs

PATCH Superseded Hans Zhang 2 participants 5 messages Mar 21 – Apr 6

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Hans Zhang

author maintainer
#0 lore raw

v2 cover PCI: cadence: Add LTSSM debugfs

Hi,

This series adds debugfs support to the Cadence PCIe controller driver, allowing users to read the current LTSSM state of the link for debugging purposes.

Patch 1 introduces a new flag 'is_hpa' in the cdns_pcie structure to distinguish HPA (High Performance Architecture IP) platforms, which have a different register layout for LTSSM status.

Patch 2 implements the debugfs file "ltssm_status" under a per-device directory. It reads the LTSSM state from the appropriate hardware register based on the 'is_hpa' flag and displays both a descriptive string and the raw value.

---
Changes for v2:
- s/DW_PCIE_LTSSM_NAME/CDNS_PCIE_LTSSM_NAME/
- S/January 2026/March 2026/
- EXPORT_SYMBOL_GPL(cdns_pcie_debugfs_init); // Resolve the following error issues.

Quoted 2 lines
Quoted 2 lines

ERROR: modpost: "cdns_pcie_debugfs_init" [drivers/pci/controller/cadence/pcie-cadence-host-mod.ko] undefined!
ERROR: modpost: "cdns_pcie_debugfs_init" [drivers/pci/controller/cadence/pcie-cadence-ep-mod.ko] undefined!

v1:
https://patchwork.kernel.org/project/linux-pci/cover/[email protected]/
---

Hans Zhang (2):
PCI: cadence: Add HPA architecture flag
PCI: cadence: Add debugfs property to provide LTSSM status of the PCIe
link

 Documentation/ABI/testing/debugfs-cdns-pcie   |   5 +
 drivers/pci/controller/cadence/Kconfig        |   9 +
 drivers/pci/controller/cadence/Makefile       |   1 +
 drivers/pci/controller/cadence/pci-sky1.c     |   1 +
 .../controller/cadence/pcie-cadence-debugfs.c | 214 ++++++++++++++++++
 .../pci/controller/cadence/pcie-cadence-ep.c  |   2 +
 .../cadence/pcie-cadence-host-hpa.c           |   8 +-
 .../controller/cadence/pcie-cadence-host.c    |   8 +-
 drivers/pci/controller/cadence/pcie-cadence.h | 147 ++++++++++++
 9 files changed, 393 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/debugfs-cdns-pcie
 create mode 100644 drivers/pci/controller/cadence/pcie-cadence-debugfs.c

base-commit: 1c9982b4961334c1edb0745a04cabd34bc2de675

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 1/2 PCI: cadence: Add HPA architecture flag

Add a boolean flag 'is_hpa' to the cdns_pcie structure to indicate that the controller is part of a Heterogeneous Processor Architecture (HPA) system. This flag will be used by subsequent patches to handle HPA-specific register layouts and behaviors.

---
 drivers/pci/controller/cadence/pci-sky1.c     | 1 +
 drivers/pci/controller/cadence/pcie-cadence.h | 2 ++
 2 files changed, 3 insertions(+)
drivers/pci/controller/cadence/pci-sky1.c +1 -0
index d8c216dc120d..2dd90118c351 100644
@@ -174,6 +174,7 @@ static int sky1_pcie_probe(struct platform_device *pdev)
 	cdns_pcie->reg_base = pcie->reg_base;
 	cdns_pcie->msg_res = pcie->msg_res;
 	cdns_pcie->is_rc = 1;
+	cdns_pcie->is_hpa = true;
 
 	reg_off = devm_kzalloc(dev, sizeof(*reg_off), GFP_KERNEL);
 	if (!reg_off)
drivers/pci/controller/cadence/pcie-cadence.h +2 -0
index 443033c607d7..c8cb19f7622f 100644
@@ -80,6 +80,7 @@ struct cdns_plat_pcie_of_data {
  * @msg_res: Region for send message to map PCI accesses
  * @dev: PCIe controller
  * @is_rc: tell whether the PCIe controller mode is Root Complex or Endpoint.
+ * @is_hpa: indicates if the architecture is HPA
  * @phy_count: number of supported PHY devices
  * @phy: list of pointers to specific PHY control blocks
  * @link: list of pointers to corresponding device link representations
@@ -93,6 +94,7 @@ struct cdns_pcie {
 	struct resource                      *msg_res;
 	struct device		             *dev;
 	bool			             is_rc;
+	bool				     is_hpa;
 	int			             phy_count;
 	struct phy		             **phy;
 	struct device_link	             **link;
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v2 2/2 PCI: cadence: Add debugfs property to provide LTSSM status of the PCIe link

In reply to Hans Zhang

Add the debugfs property to provide a view of the current link's LTSSM status from the Root Port device.

Test example:

  # cat /sys/kernel/debug/cdns_pcie_a0c0000.pcie/ltssm_status
  L0_STATE (0x29)
---
 Documentation/ABI/testing/debugfs-cdns-pcie   |   5 +
 drivers/pci/controller/cadence/Kconfig        |   9 +
 drivers/pci/controller/cadence/Makefile       |   1 +
 .../controller/cadence/pcie-cadence-debugfs.c | 214 ++++++++++++++++++
 .../pci/controller/cadence/pcie-cadence-ep.c  |   2 +
 .../cadence/pcie-cadence-host-hpa.c           |   8 +-
 .../controller/cadence/pcie-cadence-host.c    |   8 +-
 drivers/pci/controller/cadence/pcie-cadence.h | 145 ++++++++++++
 8 files changed, 390 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/debugfs-cdns-pcie
 create mode 100644 drivers/pci/controller/cadence/pcie-cadence-debugfs.c
Documentation/ABI/testing/debugfs-cdns-pcie new file +5 -0
new file mode 100644
index 000000000000..659ad2ab70e4
@@ -0,0 +1,5 @@
+What:		/sys/kernel/debug/cdns_pcie_<dev>/ltssm_status
+Date:		March 2026
+Contact:	Hans Zhang <[email protected]>
+Description:	(RO) Read will return the current PCIe LTSSM state in both
+		string and raw value.
drivers/pci/controller/cadence/Kconfig +9 -0
index 9e651d545973..b277c5f6e196 100644
@@ -6,6 +6,15 @@ menu "Cadence-based PCIe controllers"
 config PCIE_CADENCE
 	tristate
 
+config PCIE_CADENCE_DEBUGFS
+	bool "Cadence PCIe debugfs entries"
+	depends on DEBUG_FS
+	depends on PCIE_CADENCE_HOST || PCIE_CADENCE_EP
+	help
+	  Say Y here to enable debugfs entries for the PCIe controller. These
+	  entries provide various debug features related to the controller and
+	  the LTSSM status of link can be displayed.
+
 config PCIE_CADENCE_HOST
 	tristate
 	depends on OF
drivers/pci/controller/cadence/Makefile +1 -0
index b8ec1cecfaa8..2cdc4617e0c2 100644
@@ -4,6 +4,7 @@ pcie-cadence-host-mod-y := pcie-cadence-host-common.o pcie-cadence-host.o pcie-c
 pcie-cadence-ep-mod-y := pcie-cadence-ep.o
 
 obj-$(CONFIG_PCIE_CADENCE) = pcie-cadence-mod.o
+obj-$(CONFIG_PCIE_CADENCE_DEBUGFS) += pcie-cadence-debugfs.o
 obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host-mod.o
 obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep-mod.o
 obj-$(CONFIG_PCIE_CADENCE_PLAT) += pcie-cadence-plat.o
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +214 -0

214 lines not on this page · raw message

drivers/pci/controller/cadence/pcie-cadence-ep.c +2 -0
index c0e1194a936b..7849f63f53ab 100644
@@ -761,6 +761,8 @@ int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep)
 
 	pci_epc_init_notify(epc);
 
+	cdns_pcie_debugfs_init(pcie);
+
 	return 0;
 
  free_epc_mem:
drivers/pci/controller/cadence/pcie-cadence-host-hpa.c +7 -1
index 0f540bed58e8..38bd74d9e071 100644
@@ -360,7 +360,13 @@ int cdns_pcie_hpa_host_setup(struct cdns_pcie_rc *rc)
 	if (!bridge->ops)
 		bridge->ops = &cdns_pcie_hpa_host_ops;
 
-	return pci_host_probe(bridge);
+	ret = pci_host_probe(bridge);
+	if (ret)
+		return ret;
+
+	cdns_pcie_debugfs_init(pcie);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(cdns_pcie_hpa_host_setup);
 
drivers/pci/controller/cadence/pcie-cadence-host.c +7 -1
index db3154c1eccb..23ca1e703953 100644
@@ -416,7 +416,13 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc)
 	if (!bridge->ops)
 		bridge->ops = &cdns_pcie_host_ops;
 
-	return pci_host_probe(bridge);
+	ret = pci_host_probe(bridge);
+	if (ret)
+		return ret;
+
+	cdns_pcie_debugfs_init(pcie);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(cdns_pcie_host_setup);
 
drivers/pci/controller/cadence/pcie-cadence.h +145 -0

167 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v2 2/2] PCI: cadence: Add debugfs property to provide LTSSM status of the PCIe link

Quoted 27 lines · Hans Zhang

Add the debugfs property to provide a view of the current link's LTSSM status from the Root Port device.

Test example:

  # cat /sys/kernel/debug/cdns_pcie_a0c0000.pcie/ltssm_status
  L0_STATE (0x29)
---
 Documentation/ABI/testing/debugfs-cdns-pcie   |   5 +
 drivers/pci/controller/cadence/Kconfig        |   9 +
 drivers/pci/controller/cadence/Makefile       |   1 +
 .../controller/cadence/pcie-cadence-debugfs.c | 214 ++++++++++++++++++
 .../pci/controller/cadence/pcie-cadence-ep.c  |   2 +
 .../cadence/pcie-cadence-host-hpa.c           |   8 +-
 .../controller/cadence/pcie-cadence-host.c    |   8 +-
 drivers/pci/controller/cadence/pcie-cadence.h | 145 ++++++++++++
 8 files changed, 390 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/debugfs-cdns-pcie
 create mode 100644 drivers/pci/controller/cadence/pcie-cadence-debugfs.c
Documentation/ABI/testing/debugfs-cdns-pcie new file +0 -0
new file mode 100644
index 000000000000..659ad2ab70e4

Documentation/ABI/testing/debugfs-cdns-pcie line 5

Quoted 5 lines
Documentation/ABI/testing/debugfs-cdns-pcie new file +5 -0
@@ -0,0 +1,5 @@
+What:		/sys/kernel/debug/cdns_pcie_<dev>/ltssm_status
+Date:		March 2026
+Contact:	Hans Zhang <[email protected]>
+Description:	(RO) Read will return the current PCIe LTSSM state in both
+		string and raw value.

Entries should be aligned.

Quoted 54 lines
drivers/pci/controller/cadence/Kconfig +9 -0
index 9e651d545973..b277c5f6e196 100644
@@ -6,6 +6,15 @@ menu "Cadence-based PCIe controllers"
 config PCIE_CADENCE
 	tristate
 
+config PCIE_CADENCE_DEBUGFS
+	bool "Cadence PCIe debugfs entries"
+	depends on DEBUG_FS
+	depends on PCIE_CADENCE_HOST || PCIE_CADENCE_EP
+	help
+	  Say Y here to enable debugfs entries for the PCIe controller. These
+	  entries provide various debug features related to the controller and
+	  the LTSSM status of link can be displayed.
+
 config PCIE_CADENCE_HOST
 	tristate
 	depends on OF
drivers/pci/controller/cadence/Makefile +1 -0
index b8ec1cecfaa8..2cdc4617e0c2 100644
@@ -4,6 +4,7 @@ pcie-cadence-host-mod-y := pcie-cadence-host-common.o pcie-cadence-host.o pcie-c
 pcie-cadence-ep-mod-y := pcie-cadence-ep.o
 
 obj-$(CONFIG_PCIE_CADENCE) = pcie-cadence-mod.o
+obj-$(CONFIG_PCIE_CADENCE_DEBUGFS) += pcie-cadence-debugfs.o
 obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host-mod.o
 obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep-mod.o
 obj-$(CONFIG_PCIE_CADENCE_PLAT) += pcie-cadence-plat.o
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +16 -0
new file mode 100644
index 000000000000..16addd919eae
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence PCIe controller debugfs driver
+ *
+ * Copyright (C) 2026 Hans Zhang <[email protected]>
+ * Author: Hans Zhang <[email protected]>
+ */
+
+#include <linux/debugfs.h>
+
+#include "pcie-cadence.h"
+
+#define CDNS_DEBUGFS_BUF_MAX		128
+#define CDNS_PCIE_LGA_LTSSM_STATUS_MASK	GENMASK(29, 24)
+#define CDNS_PCIE_HPA_LTSSM_STATUS_MASK	GENMASK(27, 20)
+

[...]

Quoted 8 lines
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +8 -0
+static const struct file_operations cdns_pcie_ltssm_status_ops = {
+	.open = ltssm_status_open,
+	.read = seq_read,
+};
+
+static void cdns_pcie_ltssm_debugfs_init(struct cdns_pcie *pci, struct dentry *dir)
+{
+	debugfs_create_file("ltssm_status", 0444, dir, pci,

drivers/pci/controller/cadence/pcie-cadence-debugfs.c line 201

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +10 -0
+			    &cdns_pcie_ltssm_status_ops);
+}
+
+void cdns_pcie_debugfs_deinit(struct cdns_pcie *pci)
+{
+	if (!pci->debug_dir)
+		return;
+
+	debugfs_remove_recursive(pci->debug_dir);
+}

You've never called this API in any controller driver. So the debugfs entries are not cleaned up properly.

If you do so, please export this function also.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author maintainer
#4 lore raw

Re: [PATCH v2 2/2] PCI: cadence: Add debugfs property to provide LTSSM status of the PCIe link

Quoted 22 lines · Manivannan Sadhasivam
Quoted 21 lines · Hans Zhang

Add the debugfs property to provide a view of the current link's LTSSM status from the Root Port device.

Test example:

   # cat /sys/kernel/debug/cdns_pcie_a0c0000.pcie/ltssm_status
   L0_STATE (0x29)
---
  Documentation/ABI/testing/debugfs-cdns-pcie   |   5 +
  drivers/pci/controller/cadence/Kconfig        |   9 +
  drivers/pci/controller/cadence/Makefile       |   1 +
  .../controller/cadence/pcie-cadence-debugfs.c | 214 ++++++++++++++++++
  .../pci/controller/cadence/pcie-cadence-ep.c  |   2 +
  .../cadence/pcie-cadence-host-hpa.c           |   8 +-
  .../controller/cadence/pcie-cadence-host.c    |   8 +-
  drivers/pci/controller/cadence/pcie-cadence.h | 145 ++++++++++++
  8 files changed, 390 insertions(+), 2 deletions(-)

create mode 100644 Documentation/ABI/testing/debugfs-cdns-pcie create mode 100644 drivers/pci/controller/cadence/pcie-cadence-debugfs.c

Quoted 13 lines

Documentation/ABI/testing/debugfs-cdns-pcie line 5

Quoted 11 lines
Documentation/ABI/testing/debugfs-cdns-pcie new file +5 -0
new file mode 100644
index 000000000000..659ad2ab70e4
@@ -0,0 +1,5 @@
+What:		/sys/kernel/debug/cdns_pcie_<dev>/ltssm_status
+Date:		March 2026
+Contact:	Hans Zhang <[email protected]>
+Description:	(RO) Read will return the current PCIe LTSSM state in both
+		string and raw value.

Entries should be aligned.

Hi Mani,

From my code, it seems to be that of it. The tab size is 8. And it was copied from the file /sys/kernel/debug/dwc_pcie_<dev>/ltssm_status in the Documentation/ABI/testing/debugfs-dwc-pcie directory that I previously submitted.

Quoted 80 lines
Quoted 55 lines
drivers/pci/controller/cadence/Kconfig +9 -0
index 9e651d545973..b277c5f6e196 100644
@@ -6,6 +6,15 @@ menu "Cadence-based PCIe controllers"
  config PCIE_CADENCE
  	tristate
 
+config PCIE_CADENCE_DEBUGFS
+	bool "Cadence PCIe debugfs entries"
+	depends on DEBUG_FS
+	depends on PCIE_CADENCE_HOST || PCIE_CADENCE_EP
+	help
+	  Say Y here to enable debugfs entries for the PCIe controller. These
+	  entries provide various debug features related to the controller and
+	  the LTSSM status of link can be displayed.
+
  config PCIE_CADENCE_HOST
  	tristate
  	depends on OF
drivers/pci/controller/cadence/Makefile +1 -0
index b8ec1cecfaa8..2cdc4617e0c2 100644
@@ -4,6 +4,7 @@ pcie-cadence-host-mod-y := pcie-cadence-host-common.o pcie-cadence-host.o pcie-c
  pcie-cadence-ep-mod-y := pcie-cadence-ep.o
 
  obj-$(CONFIG_PCIE_CADENCE) = pcie-cadence-mod.o
+obj-$(CONFIG_PCIE_CADENCE_DEBUGFS) += pcie-cadence-debugfs.o
  obj-$(CONFIG_PCIE_CADENCE_HOST) += pcie-cadence-host-mod.o
  obj-$(CONFIG_PCIE_CADENCE_EP) += pcie-cadence-ep-mod.o
  obj-$(CONFIG_PCIE_CADENCE_PLAT) += pcie-cadence-plat.o
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +16 -0
new file mode 100644
index 000000000000..16addd919eae
@@ -0,0 +1,214 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence PCIe controller debugfs driver
+ *
+ * Copyright (C) 2026 Hans Zhang <[email protected]>
+ * Author: Hans Zhang <[email protected]>
+ */
+
+#include <linux/debugfs.h>
+
+#include "pcie-cadence.h"
+
+#define CDNS_DEBUGFS_BUF_MAX		128
+#define CDNS_PCIE_LGA_LTSSM_STATUS_MASK	GENMASK(29, 24)
+#define CDNS_PCIE_HPA_LTSSM_STATUS_MASK	GENMASK(27, 20)
+

[...]

Quoted 8 lines
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +8 -0
+static const struct file_operations cdns_pcie_ltssm_status_ops = {
+	.open = ltssm_status_open,
+	.read = seq_read,
+};
+
+static void cdns_pcie_ltssm_debugfs_init(struct cdns_pcie *pci, struct dentry *dir)
+{
+	debugfs_create_file("ltssm_status", 0444, dir, pci,

drivers/pci/controller/cadence/pcie-cadence-debugfs.c line 201

Quoted 10 lines
drivers/pci/controller/cadence/pcie-cadence-debugfs.c new file +10 -0
+			    &cdns_pcie_ltssm_status_ops);
+}
+
+void cdns_pcie_debugfs_deinit(struct cdns_pcie *pci)
+{
+	if (!pci->debug_dir)
+		return;
+
+	debugfs_remove_recursive(pci->debug_dir);
+}

You've never called this API in any controller driver. So the debugfs entries are not cleaned up properly.

Quoted 1 line

If you do so, please export this function also.

Thank you for pointing out the issue. It seems that the call to cdns_pcie_debugfs_deinit was omitted, and it needs to be exported as well. It will be fixed in the next version.

Best regards,
Hans

Quoted 3 lines

- Mani