PCI: Add PTM debugfs support
Subsystems (5)
v4 cover PCI: Add PTM debugfs support
Hi,
This series adds debugfs support to expose the PTM context available in the capable PCIe controllers. Support for enabling PTM in the requester/responder is already available in drivers/pci/pcie.c and this series expands that file to add debugfs support for the PTM context info.
The controller drivers are expected to call pcie_ptm_create_debugfs() with 'pcie_ptm_ops' callbacks populated to create the debugfs entries and call pcie_ptm_destroy_debugfs() to destroy them.
Patch 1 adds the necessary code in the drivers/pci/pcie.c to expose PTM context over debugfs and patch 2 adds PTM support in the DWC drivers (host and endpoint). Finally, patch 3 masks the PTM_UPDATING interrupt in the pcie-qcom-ep driver to avoid processing the interrupt for each PTM context update.
Testing
=======
This series is tested on Qcom SA8775p Ride Mx platform where one SA8775p acts as RC and another as EP with following instructions:
RC
--
$ echo 1 > /sys/kernel/debug/pcie_ptm_1c10000.pcie/context_valid
EP
--
$ echo auto > /sys/kernel/debug/pcie_ptm_1c10000.pcie-ep/context_update
$ cat /sys/kernel/debug/pcie_ptm_1c10000.pcie-ep/local_clock 159612570424
$ cat /sys/kernel/debug/pcie_ptm_1c10000.pcie-ep/master_clock 159609466232
$ cat /sys/kernel/debug/pcie_ptm_1c10000.pcie-ep/t1 159609466112
$ cat /sys/kernel/debug/pcie_ptm_1c10000.pcie-ep/t4 159609466518
NOTE: To make use of the PTM feature, the host PCIe client driver has to call 'pci_enable_ptm()' API during probe. This series was tested with enabling PTM in the MHI host driver with a local change (which will be upstreamed later). Technically, PTM could also be enabled in the pci_endpoint_test driver, but I didn't add the change as I'm not sure we'd want to add random PCIe features in the test driver without corresponding code in pci-epf-test driver.
Changes in v4:
- Fixed the build warning in patch 1/4
- Moved the dwc_pcie_ptm_vsec_ids defintion to pcie_designware.c to avoid -Wunused-const-variable warning. It also makes sense to keep it in the driver for now since there are no more users.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Switched to debugfs interface based on comments from Bjorn
- Added locking for context read/writes
- Rebased on top of v6.15-rc1
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
* Dropped the VSEC changes that got merged
* Moved the PTM sysfs code from drivers/pci/controller/dwc to drivers/pci/pcie/ptm.c to make it generic so that other controller drivers could also benefit from it.
* Rebased on top of pci/controller/dwc
---
Manivannan Sadhasivam (4):
PCI: Add debugfs support for exposing PTM context
PCI: dwc: Pass DWC PCIe mode to dwc_pcie_debugfs_init()
PCI: dwc: Add debugfs support for PTM context
PCI: qcom-ep: Mask PTM_UPDATING interrupt
Documentation/ABI/testing/debugfs-pcie-ptm | 70 +++++ MAINTAINERS | 1 + .../pci/controller/dwc/pcie-designware-debugfs.c | 252 ++++++++++++++++- drivers/pci/controller/dwc/pcie-designware-ep.c | 2 +- drivers/pci/controller/dwc/pcie-designware-host.c | 2 +- drivers/pci/controller/dwc/pcie-designware.c | 14 + drivers/pci/controller/dwc/pcie-designware.h | 24 +- drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 + drivers/pci/pcie/ptm.c | 300 +++++++++++++++++++++ include/linux/pci.h | 45 ++++ 10 files changed, 713 insertions(+), 5 deletions(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250324-pcie-ptm-e75b9b2ffcfb
Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>
PATCH v4 1/4 PCI: Add debugfs support for exposing PTM context
Precision Time Management (PTM) mechanism defined in PCIe spec r6.0, sec 6.21 allows precise coordination of timing information across multiple components in a PCIe hierarchy with independent local time clocks.
PCI core already supports enabling PTM in the root port and endpoint devices through PTM Extended Capability registers. But the PTM context supported by the PTM capable components such as Root Complex (RC) and Endpoint (EP) controllers were not exposed as of now.
Hence, add the debugfs support to expose the PTM context to userspace from both PCIe RC and EP controllers. Controller drivers are expected to call pcie_ptm_create_debugfs() to create the debugfs attributes for the PTM context and call pcie_ptm_destroy_debugfs() to destroy them. The drivers should also populate the relevant callbacks in the 'struct pcie_ptm_ops' structure based on the controller implementation.
Below PTM context are exposed through debugfs:
PCIe RC
=======
1. PTM Local clock
2. PTM T2 timestamp
3. PTM T3 timestamp
4. PTM Context valid
PCIe EP
=======
1. PTM Local clock
2. PTM T1 timestamp
3. PTM T4 timestamp
4. PTM Master clock
5. PTM Context update
--- Documentation/ABI/testing/debugfs-pcie-ptm | 70 +++++++ MAINTAINERS | 1 + drivers/pci/pcie/ptm.c | 300 +++++++++++++++++++++++++++++ include/linux/pci.h | 45 +++++ 4 files changed, 416 insertions(+)
Documentation/ABI/testing/debugfs-pcie-ptm new file +70 -0
@@ -0,0 +1,70 @@ +What: /sys/kernel/debug/pcie_ptm_*/local_clock +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM local clock in nanoseconds. Applicable for both Root + Complex and Endpoint controllers. + +What: /sys/kernel/debug/pcie_ptm_*/master_clock +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM master clock in nanoseconds. Applicable only for + Endpoint controllers. + +What: /sys/kernel/debug/pcie_ptm_*/t1 +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM T1 timestamp in nanoseconds. Applicable only for + Endpoint controllers. + +What: /sys/kernel/debug/pcie_ptm_*/t2 +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM T2 timestamp in nanoseconds. Applicable only for + Root Complex controllers. + +What: /sys/kernel/debug/pcie_ptm_*/t3 +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM T3 timestamp in nanoseconds. Applicable only for + Root Complex controllers. + +What: /sys/kernel/debug/pcie_ptm_*/t4 +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RO) PTM T4 timestamp in nanoseconds. Applicable only for + Endpoint controllers. + +What: /sys/kernel/debug/pcie_ptm_*/context_update +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RW) Control the PTM context update mode. Applicable only for + Endpoint controllers. + + Following values are supported: + + * auto = PTM context auto update trigger for every 10ms + + * manual = PTM context manual update. Writing 'manual' to this + file triggers PTM context update (default) + +What: /sys/kernel/debug/pcie_ptm_*/context_valid +Date: May 2025 +Contact: Manivannan Sadhasivam <[email protected]> +Description: + (RW) Control the PTM context validity (local clock timing). + Applicable only for Root Complex controllers. PTM context is + invalidated by hardware if the Root Complex enters low power + mode or changes link frequency. + + Following values are supported: + + * 0 = PTM context invalid (default) + + * 1 = PTM context valid
MAINTAINERS +1 -0
@@ -18641,6 +18641,7 @@ Q: https://patchwork.kernel.org/project/linux-pci/list/ B: https://bugzilla.kernel.org C: irc://irc.oftc.net/linux-pci T: git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git +F: Documentation/ABI/testing/debugfs-pcie-ptm F: Documentation/devicetree/bindings/pci/ F: drivers/pci/controller/ F: drivers/pci/pci-bridge-emul.c
drivers/pci/pcie/ptm.c +300 -0
309 lines not on this page · raw message
include/linux/pci.h +45 -0
57 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v4 1/4] PCI: Add debugfs support for exposing PTM context
Quoted 8 lines · Manivannan Sadhasivam
Precision Time Management (PTM) mechanism defined in PCIe spec r6.0, sec 6.21 allows precise coordination of timing information across multiple components in a PCIe hierarchy with independent local time clocks.
PCI core already supports enabling PTM in the root port and endpoint devices through PTM Extended Capability registers. But the PTM context supported by the PTM capable components such as Root Complex (RC) and Endpoint (EP) controllers were not exposed as of now.
IIUC, the PCIe spec defines the PTM link protocol in terms of these timestamps, but it does not provide any visibility of them to software, so any visibility is device-specific. I think it's worth mentioning something to this effect.
Bjorn
Re: [PATCH v4 1/4] PCI: Add debugfs support for exposing PTM context
Quoted 10 lines · Bjorn Helgaas
Quoted 8 lines · Manivannan Sadhasivam
Precision Time Management (PTM) mechanism defined in PCIe spec r6.0, sec 6.21 allows precise coordination of timing information across multiple components in a PCIe hierarchy with independent local time clocks.
PCI core already supports enabling PTM in the root port and endpoint devices through PTM Extended Capability registers. But the PTM context supported by the PTM capable components such as Root Complex (RC) and Endpoint (EP) controllers were not exposed as of now.
Quoted 5 lines
IIUC, the PCIe spec defines the PTM link protocol in terms of these timestamps, but it does not provide any visibility of them to software, so any visibility is device-specific. I think it's worth mentioning something to this effect.
Added this info while applying the series, thanks!
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
Re: [PATCH v4 1/4] PCI: Add debugfs support for exposing PTM context
In reply to Manivannan SadhasivamQuoted 35 lines · Manivannan Sadhasivam
Precision Time Management (PTM) mechanism defined in PCIe spec r6.0, sec 6.21 allows precise coordination of timing information across multiple components in a PCIe hierarchy with independent local time clocks.
PCI core already supports enabling PTM in the root port and endpoint devices through PTM Extended Capability registers. But the PTM context supported by the PTM capable components such as Root Complex (RC) and Endpoint (EP) controllers were not exposed as of now.
Hence, add the debugfs support to expose the PTM context to userspace from both PCIe RC and EP controllers. Controller drivers are expected to call
pcie_ptm_create_debugfs()to create the debugfs attributes for the PTM context and callpcie_ptm_destroy_debugfs()to destroy them. The drivers should also populate the relevant callbacks in the 'structpcie_ptm_ops' structure based on the controller implementation.Below PTM context are exposed through debugfs:
PCIe RC
=======1. PTM Local clock
2. PTM T2 timestamp
3. PTM T3 timestamp
4. PTM Context validPCIe EP
=======1. PTM Local clock
2. PTM T1 timestamp
3. PTM T4 timestamp
4. PTM Master clock
5. PTM Context update
Quoted 7 lines
Signed-off-by Manivannan Sadhasivam <[email protected]>--- Documentation/ABI/testing/debugfs-pcie-ptm | 70 +++++++ MAINTAINERS | 1 + drivers/pci/pcie/ptm.c | 300 +++++++++++++++++++++++++++++ include/linux/pci.h | 45 +++++ 4 files changed, 416 insertions(+)
There's a build error on mainline from this commit:
drivers/pci/pcie/ptm.c:498:25: error: redefinition of 'pcie_ptm_create_debugfs'
498 | struct pci_ptm_debugfs *pcie_ptm_create_debugfs(struct device *dev, void *pdata,
| ^
./include/linux/pci.h:1915:2: note: previous definition is here
1915 | *pcie_ptm_create_debugfs(struct device *dev, void *pdata,
| ^
drivers/pci/pcie/ptm.c:546:6: error: redefinition of 'pcie_ptm_destroy_debugfs'
546 | void pcie_ptm_destroy_debugfs(struct pci_ptm_debugfs *ptm_debugfs)
| ^
./include/linux/pci.h:1918:1: note: previous definition is here
1918 | pcie_ptm_destroy_debugfs(struct pci_ptm_debugfs *ptm_debugfs) { }
| ^
This is with CONFIG_DEBUG_FS=n && CONFIG_PCIE_PTM=y.
- Eric
PATCH v4 2/4 PCI: dwc: Pass DWC PCIe mode to dwc_pcie_debugfs_init()
In reply to Manivannan SadhasivamUpcoming PTM debugfs interface relies on the DWC PCIe mode to expose the relevat debugfs attributes to userspace. So pass the mode to dwc_pcie_debugfs_init() API from host and ep drivers and save it in 'struct dw_pcie::mode'.
--- drivers/pci/controller/dwc/pcie-designware-debugfs.c | 4 +++- drivers/pci/controller/dwc/pcie-designware-ep.c | 2 +- drivers/pci/controller/dwc/pcie-designware-host.c | 2 +- drivers/pci/controller/dwc/pcie-designware.h | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +3 -1
@@ -651,7 +651,7 @@ void dwc_pcie_debugfs_deinit(struct dw_pcie *pci)debugfs_remove_recursive (pci->debugfs->debug_dir); } -void dwc_pcie_debugfs_init (struct dw_pcie *pci) +void dwc_pcie_debugfs_init (struct dw_pcie *pci,enum dw_pcie_device_mode mode) {char dirname[DWC_DEBUGFS_BUF_MAX ];struct device *dev = pci->dev;
@@ -674,4 +674,6 @@ void dwc_pcie_debugfs_init(struct dw_pcie *pci) err);dwc_pcie_ltssm_debugfs_init (pci, dir); + + pci->mode = mode; }
drivers/pci/controller/dwc/pcie-designware-ep.c +1 -1
@@ -1013,7 +1013,7 @@ int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep)dw_pcie_ep_init_non_sticky_registers (pci); -dwc_pcie_debugfs_init (pci); +dwc_pcie_debugfs_init (pci,DW_PCIE_EP_TYPE );return 0 ;
drivers/pci/controller/dwc/pcie-designware-host.c +1 -1
@@ -567,7 +567,7 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)if (pp->ops->post_init) pp->ops->post_init (pp); -dwc_pcie_debugfs_init (pci); +dwc_pcie_debugfs_init (pci,DW_PCIE_RC_TYPE );return 0 ;
drivers/pci/controller/dwc/pcie-designware.h +4 -2
@@ -503,6 +503,7 @@ struct dw_pcie {struct gpio_desc *pe_rst;bool suspended;struct debugfs_info *debugfs; +enum dw_pcie_device_mode mode;/* * If iATU input addresses are offset from CPU physical addresses,
@@ -871,10 +872,11 @@ dw_pcie_ep_get_func_from_ep(struct dw_pcie_ep *ep, u8 func_no)#endif #ifdef CONFIG_PCIE_DW_DEBUGFS -void dwc_pcie_debugfs_init (struct dw_pcie *pci); +void dwc_pcie_debugfs_init (struct dw_pcie *pci,enum dw_pcie_device_mode mode);void dwc_pcie_debugfs_deinit (struct dw_pcie *pci);#else -static inline void dwc_pcie_debugfs_init (struct dw_pcie *pci) +static inline void dwc_pcie_debugfs_init (struct dw_pcie *pci, +enum dw_pcie_device_mode mode) { }static inline void dwc_pcie_debugfs_deinit (struct dw_pcie *pci)
Signature · 1 line
2.43.0
Re: [PATCH v4 2/4] PCI: dwc: Pass DWC PCIe mode to dwc_pcie_debugfs_init()
Quoted 4 lines · Manivannan Sadhasivam
Upcoming PTM debugfs interface relies on the DWC PCIe mode to expose the relevat debugfs attributes to userspace. So pass the mode to
dwc_pcie_debugfs_init()API from host and ep drivers and save it in 'structdw_pcie::mode'.
s/relevat/relevant/
Re: [PATCH v4 2/4] PCI: dwc: Pass DWC PCIe mode to dwc_pcie_debugfs_init()
Quoted 7 lines · Bjorn Helgaas
Quoted 4 lines · Manivannan Sadhasivam
Upcoming PTM debugfs interface relies on the DWC PCIe mode to expose the relevat debugfs attributes to userspace. So pass the mode to
dwc_pcie_debugfs_init()API from host and ep drivers and save it in 'structdw_pcie::mode'.s/relevat/relevant/
Fixed while applying, thanks!
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்
PATCH v4 3/4 PCI: dwc: Add debugfs support for PTM context
In reply to Manivannan SadhasivamSynopsys Designware PCIe IPs support PTM capability as defined in the PCIe spec r6.0, sec 6.21. The PTM context information is exposed through Vendor Specific Extended Capability (VSEC) registers on supported controller implementation.
Hence, add support for exposing these context information to userspace through the debugfs interface for the DWC controllers (both RC and EP). Currently, only Qcom controllers are supported. For adding support for other DWC vendor controllers, dwc_pcie_ptm_vsec_ids[] needs to be extended.
--- .../pci/controller/dwc/pcie-designware-debugfs.c | 248 +++++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.c | 14 ++ drivers/pci/controller/dwc/pcie-designware.h | 18 ++ 3 files changed, 280 insertions(+)
drivers/pci/controller/dwc/pcie-designware-debugfs.c +248 -0
@@ -642,11 +642,257 @@ static void dwc_pcie_ltssm_debugfs_init(struct dw_pcie *pci, struct dentry *dir) &dwc_pcie_ltssm_status_ops); } +static int dw_pcie_ptm_check_capability (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + + pci->ptm_vsec_offset =dw_pcie_find_ptm_capability (pci); + +return pci->ptm_vsec_offset; +} + +static int dw_pcie_ptm_context_update_write (void *drvdata,u8 mode) +{ +struct dw_pcie *pci = drvdata; +u32 val; + +if (mode ==PCIE_PTM_CONTEXT_UPDATE_AUTO ) { + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); + val |=PTM_REQ_AUTO_UPDATE_ENABLED ; +dw_pcie_writel_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL , val); + }else if (mode ==PCIE_PTM_CONTEXT_UPDATE_MANUAL ) { + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); + val &= ~PTM_REQ_AUTO_UPDATE_ENABLED ; + val |=PTM_REQ_START_UPDATE ; +dw_pcie_writel_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL , val); + }else { +return -EINVAL ; + } + +return 0 ; +} + +static int dw_pcie_ptm_context_update_read (void *drvdata,u8 *mode) +{ +struct dw_pcie *pci = drvdata; +u32 val; + + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); +if (FIELD_GET (PTM_REQ_AUTO_UPDATE_ENABLED , val)) + *mode =PCIE_PTM_CONTEXT_UPDATE_AUTO ; +else +/* +* PTM_REQ_START_UPDATE is a self clearing register bit. So if +* PTM_REQ_AUTO_UPDATE_ENABLED is not set, then it implies that +* manual update is used. +*/ + *mode =PCIE_PTM_CONTEXT_UPDATE_MANUAL ; + +return 0 ; +} + +static int dw_pcie_ptm_context_valid_write (void *drvdata,bool valid) +{ +struct dw_pcie *pci = drvdata; +u32 val; + +if (valid) { + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); + val |=PTM_RES_CCONTEXT_VALID ; +dw_pcie_writel_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL , val); + }else { + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); + val &= ~PTM_RES_CCONTEXT_VALID ; +dw_pcie_writel_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL , val); + } + +return 0 ; +} + +static int dw_pcie_ptm_context_valid_read (void *drvdata,bool *valid) +{ +struct dw_pcie *pci = drvdata; +u32 val; + + val =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_RES_REQ_CTRL ); + *valid = !!FIELD_GET (PTM_RES_CCONTEXT_VALID , val); + +return 0 ; +} + +static int dw_pcie_ptm_local_clock_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_LOCAL_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_LOCAL_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_LOCAL_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static int dw_pcie_ptm_master_clock_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_MASTER_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_MASTER_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_MASTER_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static int dw_pcie_ptm_t1_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static int dw_pcie_ptm_t2_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T1_T2_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static int dw_pcie_ptm_t3_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static int dw_pcie_ptm_t4_read (void *drvdata,u64 *clock) +{ +struct dw_pcie *pci = drvdata; +u32 msb, lsb; + +do { + msb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_MSB ); + lsb =dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_LSB ); + }while (msb !=dw_pcie_readl_dbi (pci, pci->ptm_vsec_offset +PTM_T3_T4_MSB )); + + *clock = ((u64 ) msb) <<32 | lsb; + +return 0 ; +} + +static bool dw_pcie_ptm_context_update_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_EP_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_context_valid_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_RC_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_local_clock_visible (void *drvdata) +{ +/* PTM local clock is always visible */ +return true; +} + +static bool dw_pcie_ptm_master_clock_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_EP_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_t1_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_EP_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_t2_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_RC_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_t3_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_RC_TYPE ) ? true : false; +} + +static bool dw_pcie_ptm_t4_visible (void *drvdata) +{ +struct dw_pcie *pci = drvdata; + +return (pci->mode ==DW_PCIE_EP_TYPE ) ? true : false; +} + +const struct pcie_ptm_ops dw_pcie_ptm_ops = { + .check_capability = dw_pcie_ptm_check_capability, + .context_update_write = dw_pcie_ptm_context_update_write, + .context_update_read = dw_pcie_ptm_context_update_read, + .context_valid_write = dw_pcie_ptm_context_valid_write, + .context_valid_read = dw_pcie_ptm_context_valid_read, + .local_clock_read = dw_pcie_ptm_local_clock_read, + .master_clock_read = dw_pcie_ptm_master_clock_read, + .t1_read = dw_pcie_ptm_t1_read, + .t2_read = dw_pcie_ptm_t2_read, + .t3_read = dw_pcie_ptm_t3_read, + .t4_read = dw_pcie_ptm_t4_read, + .context_update_visible = dw_pcie_ptm_context_update_visible, + .context_valid_visible = dw_pcie_ptm_context_valid_visible, + .local_clock_visible = dw_pcie_ptm_local_clock_visible, + .master_clock_visible = dw_pcie_ptm_master_clock_visible, + .t1_visible = dw_pcie_ptm_t1_visible, + .t2_visible = dw_pcie_ptm_t2_visible, + .t3_visible = dw_pcie_ptm_t3_visible, + .t4_visible = dw_pcie_ptm_t4_visible, +}; +void dwc_pcie_debugfs_deinit (struct dw_pcie *pci) {if (!pci->debugfs)return ; +pcie_ptm_destroy_debugfs (pci->ptm_debugfs);dwc_pcie_rasdes_debugfs_deinit (pci);debugfs_remove_recursive (pci->debugfs->debug_dir); }
@@ -676,4 +922,6 @@ void dwc_pcie_debugfs_init(struct dw_pcie *pci, enum dw_pcie_device_mode mode)dwc_pcie_ltssm_debugfs_init (pci, dir); pci->mode = mode; + pci->ptm_debugfs =pcie_ptm_create_debugfs (pci->dev, pci, + &dw_pcie_ptm_ops); }
drivers/pci/controller/dwc/pcie-designware.c +14 -0
@@ -54,6 +54,14 @@ static const char * const dw_pcie_core_rsts[DW_PCIE_NUM_CORE_RSTS] = { [DW_PCIE_PWR_RST] = "pwr", }; +static const struct dwc_pcie_vsec_id dwc_pcie_ptm_vsec_ids[] = { + { .vendor_id =PCI_VENDOR_ID_QCOM ,/* EP */ + .vsec_id =0x03 , .vsec_rev =0x1 }, + { .vendor_id =PCI_VENDOR_ID_QCOM ,/* RC */ + .vsec_id =0x04 , .vsec_rev =0x1 }, + { } +}; +static int dw_pcie_get_clocks (struct dw_pcie *pci) {int i, ret;
@@ -330,6 +338,12 @@ u16 dw_pcie_find_rasdes_capability(struct dw_pcie *pci) }EXPORT_SYMBOL_GPL (dw_pcie_find_rasdes_capability); +u16 dw_pcie_find_ptm_capability (struct dw_pcie *pci) +{ +return dw_pcie_find_vsec_capability (pci, dwc_pcie_ptm_vsec_ids); +} +EXPORT_SYMBOL_GPL (dw_pcie_find_ptm_capability); +int dw_pcie_read (void __iomem *addr,int size,u32 *val) {if (!IS_ALIGNED ((uintptr_t )addr, size)) {
drivers/pci/controller/dwc/pcie-designware.h +18 -0
@@ -260,6 +260,21 @@#define PCIE_RAS_DES_EVENT_COUNTER_DATA 0xc +/* PTM register definitions */ +#define PTM_RES_REQ_CTRL 0x8 +#define PTM_RES_CCONTEXT_VALID BIT(0) +#define PTM_REQ_AUTO_UPDATE_ENABLED BIT(0) +#define PTM_REQ_START_UPDATE BIT(1) + +#define PTM_LOCAL_LSB 0x10 +#define PTM_LOCAL_MSB 0x14 +#define PTM_T1_T2_LSB 0x18 +#define PTM_T1_T2_MSB 0x1c +#define PTM_T3_T4_LSB 0x28 +#define PTM_T3_T4_MSB 0x2c +#define PTM_MASTER_LSB 0x38 +#define PTM_MASTER_MSB 0x3c +/* * The default address offset between dbi_base and atu_base. Root controller * drivers are not required to initialize atu_base if the offset matches this
@@ -504,6 +519,8 @@ struct dw_pcie {bool suspended;struct debugfs_info *debugfs;enum dw_pcie_device_mode mode; +u16 ptm_vsec_offset; +struct pci_ptm_debugfs *ptm_debugfs;/* * If iATU input addresses are offset from CPU physical addresses,
@@ -531,6 +548,7 @@ void dw_pcie_version_detect(struct dw_pcie *pci);u8 dw_pcie_find_capability (struct dw_pcie *pci,u8 cap);u16 dw_pcie_find_ext_capability (struct dw_pcie *pci,u8 cap);u16 dw_pcie_find_rasdes_capability (struct dw_pcie *pci); +u16 dw_pcie_find_ptm_capability (struct dw_pcie *pci);int dw_pcie_read (void __iomem *addr,int size,u32 *val);int dw_pcie_write (void __iomem *addr,int size,u32 val);
Signature · 1 line
2.43.0
Re: [PATCH v4 3/4] PCI: dwc: Add debugfs support for PTM context
Quoted 6 lines · Manivannan Sadhasivam
Synopsys Designware PCIe IPs support PTM capability as defined in the PCIe spec r6.0, sec 6.21. The PTM context information is exposed through Vendor Specific Extended Capability (VSEC) registers on supported controller implementation.
+const struct
pcie_ptm_opsdw_pcie_ptm_ops= {
Sparse complains:
CHECK drivers/pci/controller/dwc/pcie-designware-debugfs.cdrivers/pci/controller/dwc/pcie-designware-debugfs.c:868:27: warning: symbol 'dw_pcie_ptm_ops' was not declared. Should it be static?
I should have noticed this earlier, sorry. As of v6.16-rc1, this is now 852a1fdd34a8 ("PCI: dwc: Add debugfs support for PTM context") upstream.
Bjorn
Re: [PATCH v4 3/4] PCI: dwc: Add debugfs support for PTM context
Quoted 8 lines · Bjorn Helgaas
Quoted 6 lines · Manivannan Sadhasivam
Synopsys Designware PCIe IPs support PTM capability as defined in the PCIe spec r6.0, sec 6.21. The PTM context information is exposed through Vendor Specific Extended Capability (VSEC) registers on supported controller implementation.
+const struct
pcie_ptm_opsdw_pcie_ptm_ops= {
Quoted 8 lines
Sparse complains:
CHECK
drivers/pci/controller/dwc/pcie-designware-debugfs.cdrivers/pci/controller/dwc/pcie-designware-debugfs.c:868:27: warning: symbol 'dw_pcie_ptm_ops' was not declared. Should it be static?I should have noticed this earlier, sorry. As of v6.16-rc1, this is now
852a1fdd34a8("PCI: dwc: Add debugfs support for PTM context") upstream.
Keeping this warm so we remember to fix it eventually.
PATCH v4 4/4 PCI: qcom-ep: Mask PTM_UPDATING interrupt
In reply to Manivannan SadhasivamWhen PTM is enabled, PTM_UPDATING interrupt will be fired for each PTM context update, which will be once every 10ms in the case of auto context update. Since the interrupt is not strictly needed for making use of PTM, mask it to avoid the overhead of processing it.
--- drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pci/controller/dwc/pcie-qcom-ep.c +8 -0
@@ -60,6 +60,7 @@#define PARF_DEVICE_TYPE 0x1000#define PARF_BDF_TO_SID_CFG 0x2c00#define PARF_INT_ALL_5_MASK 0x2dcc +#define PARF_INT_ALL_3_MASK 0x2e18/* PARF_INT_ALL_{STATUS/CLEAR/MASK} register fields */ #define PARF_INT_ALL_LINK_DOWN BIT(1)
@@ -132,6 +133,9 @@/* PARF_INT_ALL_5_MASK fields */ #define PARF_INT_ALL_5_MHI_RAM_DATA_PARITY_ERR BIT(0) +/* PARF_INT_ALL_3_MASK fields */ +#define PARF_INT_ALL_3_PTM_UPDATING BIT(4) +/* ELBI registers */ #define ELBI_SYS_STTS 0x08#define ELBI_CS2_ENABLE 0xa4
@@ -497,6 +501,10 @@ static int qcom_pcie_perst_deassert(struct dw_pcie *pci)writel_relaxed (val, pcie_ep->parf +PARF_INT_ALL_5_MASK ); } + val =readl_relaxed (pcie_ep->parf +PARF_INT_ALL_3_MASK ); + val &= ~PARF_INT_ALL_3_PTM_UPDATING ; +writel_relaxed (val, pcie_ep->parf +PARF_INT_ALL_3_MASK ); + ret =dw_pcie_ep_init_registers (&pcie_ep->pci.ep);if (ret) {dev_err (dev,"Failed to complete initialization: %d\n" , ret);
Signature · 1 line
2.43.0
Manivannan Sadhasivam
AppliedQuoted 10 lines · Manivannan Sadhasivam
This series adds debugfs support to expose the PTM context available in the capable PCIe controllers. Support for enabling PTM in the requester/responder is already available in
drivers/pci/pcie.cand this series expands that file to add debugfs support for the PTM context info.The controller drivers are expected to call
pcie_ptm_create_debugfs()with 'pcie_ptm_ops' callbacks populated to create the debugfs entries and callpcie_ptm_destroy_debugfs()to destroy them.[...]
Applied, thanks!
[1/4] PCI: Add debugfs support for exposing PTM context
commit: 1130deffd29ab25da8091b573e173ef9d889e827
[2/4] PCI: dwc: Pass DWC PCIe mode to dwc_pcie_debugfs_init()
commit: d831581b3433909e9ce9fa0b4d4f79d357093830
[3/4] PCI: dwc: Add debugfs support for PTM context
commit: 287af93079f5cd8934b10d2e09e23ae4ca7320e6
[4/4] PCI: qcom-ep: Mask PTM_UPDATING interrupt
commit: 356fc3e997f3bf54448a8cb39b49c7d73959d166Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>