* [PATCH 0/4] PCI: dwc: Add PTM sysfs support
@ 2025-02-18 14:36 Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2025-02-18 14:36 UTC (permalink / raw)
To: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring
Cc: Shradha Todi, linux-kernel, linux-arm-kernel, linux-perf-users,
linux-pci, linux-arm-msm, Manivannan Sadhasivam
Hi,
This series adds sysfs support for PCIe PTM in Synopsys Designware IPs.
First patch moves the common DWC struct definitions (dwc_pcie_vsec_id) to
include/pci/pcie-dwc.h from dwc-pcie-pmu driver. This allows reusing the same
definitions in pcie-designware-sysfs driver introduced in this series and also
in the debugfs series by Shradha [1].
Second patch adds support for searching the Vendor Specific Extended Capability
(VSEC) in the pcie-designware driver. This patch was originally based on
Shradha's patch [2], but modified to accept 'struct dwc_pcie_vsec_id' to avoid
iterating through the vsec_ids in the driver.
Third patch adds the actual sysfs support for PTM in a new file
pcie-designware-sysfs.c built along with pcie-designware.c.
Finally, fourth patch 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/devices/platform/1c10000.pcie/dwc/ptm/ptm_context_valid
EP
--
$ echo auto > /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_context_update
$ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_local_clock
159612570424
$ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_master_clock
159609466232
$ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_t1
159609466112
$ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_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.
Merging Strategy
================
I'd like to have an ACK from the perf maintainers to take the whole series
through PCI tree.
[1] https://lore.kernel.org/linux-pci/20250214105007.97582-1-shradha.t@samsung.com
[2] https://lore.kernel.org/linux-pci/20250214105007.97582-2-shradha.t@samsung.com
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
Manivannan Sadhasivam (4):
perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC)
PCI: dwc: Add sysfs support for PTM
PCI: qcom-ep: Mask PTM_UPDATING interrupt
Documentation/ABI/testing/sysfs-platform-dwc-pcie | 70 ++++++
MAINTAINERS | 2 +
drivers/pci/controller/dwc/Makefile | 2 +-
drivers/pci/controller/dwc/pcie-designware-ep.c | 3 +
drivers/pci/controller/dwc/pcie-designware-host.c | 4 +
drivers/pci/controller/dwc/pcie-designware-sysfs.c | 278 +++++++++++++++++++++
drivers/pci/controller/dwc/pcie-designware.c | 46 ++++
drivers/pci/controller/dwc/pcie-designware.h | 22 ++
drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 +
drivers/perf/dwc_pcie_pmu.c | 23 +-
include/linux/pcie-dwc.h | 42 ++++
11 files changed, 478 insertions(+), 22 deletions(-)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250218-pcie-qcom-ptm-bf6952f5c4e5
Best regards,
--
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 14:36 ` Manivannan Sadhasivam via B4 Relay
2025-02-18 16:31 ` Dmitry Baryshkov
2025-02-20 6:01 ` Shradha Todi
2025-02-18 14:36 ` [PATCH 2/4] PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC) Manivannan Sadhasivam via B4 Relay
` (3 subsequent siblings)
4 siblings, 2 replies; 13+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2025-02-18 14:36 UTC (permalink / raw)
To: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring
Cc: Shradha Todi, linux-kernel, linux-arm-kernel, linux-perf-users,
linux-pci, linux-arm-msm, Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Since these are common to all Desginware PCIe IPs, move them to a new
header, 'pcie-dwc.h' so that other drivers could make use of them.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
MAINTAINERS | 1 +
drivers/perf/dwc_pcie_pmu.c | 23 ++---------------------
include/linux/pcie-dwc.h | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 896a307fa065..b4d09d52a750 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18123,6 +18123,7 @@ S: Maintained
F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
F: drivers/pci/controller/dwc/*designware*
+F: include/linux/pcie-dwc.h
PCI DRIVER FOR TI DRA7XX/J721E
M: Vignesh Raghavendra <vigneshr@ti.com>
diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
index cccecae9823f..05b37ea7cf16 100644
--- a/drivers/perf/dwc_pcie_pmu.c
+++ b/drivers/perf/dwc_pcie_pmu.c
@@ -13,6 +13,7 @@
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/list.h>
+#include <linux/pcie-dwc.h>
#include <linux/perf_event.h>
#include <linux/pci.h>
#include <linux/platform_device.h>
@@ -99,26 +100,6 @@ struct dwc_pcie_dev_info {
struct list_head dev_node;
};
-struct dwc_pcie_pmu_vsec_id {
- u16 vendor_id;
- u16 vsec_id;
- u8 vsec_rev;
-};
-
-/*
- * VSEC IDs are allocated by the vendor, so a given ID may mean different
- * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
- */
-static const struct dwc_pcie_pmu_vsec_id dwc_pcie_pmu_vsec_ids[] = {
- { .vendor_id = PCI_VENDOR_ID_ALIBABA,
- .vsec_id = 0x02, .vsec_rev = 0x4 },
- { .vendor_id = PCI_VENDOR_ID_AMPERE,
- .vsec_id = 0x02, .vsec_rev = 0x4 },
- { .vendor_id = PCI_VENDOR_ID_QCOM,
- .vsec_id = 0x02, .vsec_rev = 0x4 },
- {} /* terminator */
-};
-
static ssize_t cpumask_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -529,7 +510,7 @@ static void dwc_pcie_unregister_pmu(void *data)
static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
{
- const struct dwc_pcie_pmu_vsec_id *vid;
+ const struct dwc_pcie_vsec_id *vid;
u16 vsec;
u32 val;
diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h
new file mode 100644
index 000000000000..261ae11d75a4
--- /dev/null
+++ b/include/linux/pcie-dwc.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021-2023 Alibaba Inc.
+ *
+ * Copyright 2025 Linaro Ltd.
+ * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ */
+
+#ifndef LINUX_PCIE_DWC_H
+#define LINUX_PCIE_DWC_H
+
+#include <linux/pci_ids.h>
+
+struct dwc_pcie_vsec_id {
+ u16 vendor_id;
+ u16 vsec_id;
+ u8 vsec_rev;
+};
+
+/*
+ * VSEC IDs are allocated by the vendor, so a given ID may mean different
+ * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
+ */
+static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
+ { .vendor_id = PCI_VENDOR_ID_ALIBABA,
+ .vsec_id = 0x02, .vsec_rev = 0x4 },
+ { .vendor_id = PCI_VENDOR_ID_AMPERE,
+ .vsec_id = 0x02, .vsec_rev = 0x4 },
+ { .vendor_id = PCI_VENDOR_ID_QCOM,
+ .vsec_id = 0x02, .vsec_rev = 0x4 },
+ {} /* terminator */
+};
+
+#endif /* LINUX_PCIE_DWC_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/4] PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC)
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 14:36 ` Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 3/4] PCI: dwc: Add sysfs support for PTM Manivannan Sadhasivam via B4 Relay
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2025-02-18 14:36 UTC (permalink / raw)
To: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring
Cc: Shradha Todi, linux-kernel, linux-arm-kernel, linux-perf-users,
linux-pci, linux-arm-msm, Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
dw_pcie_find_vsec_capability() is used by upcoming DWC APIs to find the
VSEC capabilities like PTM, RAS etc...
Co-developed-by: Shradha Todi <shradha.t@samsung.com>
Signed-off-by: Shradha Todi <shradha.t@samsung.com>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-designware.c | 40 ++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index 145e7f579072..a7c0671c6715 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -16,6 +16,7 @@
#include <linux/gpio/consumer.h>
#include <linux/ioport.h>
#include <linux/of.h>
+#include <linux/pcie-dwc.h>
#include <linux/platform_device.h>
#include <linux/sizes.h>
#include <linux/types.h>
@@ -283,6 +284,45 @@ u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap)
}
EXPORT_SYMBOL_GPL(dw_pcie_find_ext_capability);
+static u16 __dw_pcie_find_vsec_capability(struct dw_pcie *pci, u16 vendor_id,
+ u16 vsec_id)
+{
+ u16 vsec = 0;
+ u32 header;
+
+ if (vendor_id != dw_pcie_readw_dbi(pci, PCI_VENDOR_ID))
+ return 0;
+
+ while ((vsec = dw_pcie_find_next_ext_capability(pci, vsec,
+ PCI_EXT_CAP_ID_VNDR))) {
+ header = dw_pcie_readl_dbi(pci, vsec + PCI_VNDR_HEADER);
+ if (PCI_VNDR_HEADER_ID(header) == vsec_id)
+ return vsec;
+ }
+
+ return 0;
+}
+
+static u16 dw_pcie_find_vsec_capability(struct dw_pcie *pci,
+ const struct dwc_pcie_vsec_id *vsec_ids)
+{
+ const struct dwc_pcie_vsec_id *vid;
+ u16 vsec;
+ u32 header;
+
+ for (vid = vsec_ids; vid->vendor_id; vid++) {
+ vsec = __dw_pcie_find_vsec_capability(pci, vid->vendor_id,
+ vid->vsec_id);
+ if (vsec) {
+ header = dw_pcie_readl_dbi(pci, vsec + PCI_VNDR_HEADER);
+ if (PCI_VNDR_HEADER_REV(header) == vid->vsec_rev)
+ return vsec;
+ }
+ }
+
+ return 0;
+}
+
int dw_pcie_read(void __iomem *addr, int size, u32 *val)
{
if (!IS_ALIGNED((uintptr_t)addr, size)) {
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/4] PCI: dwc: Add sysfs support for PTM
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 2/4] PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC) Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 14:36 ` Manivannan Sadhasivam via B4 Relay
2025-02-18 17:54 ` Dmitry Baryshkov
2025-02-18 14:36 ` [PATCH 4/4] PCI: qcom-ep: Mask PTM_UPDATING interrupt Manivannan Sadhasivam via B4 Relay
2025-02-18 16:17 ` [PATCH 0/4] PCI: dwc: Add PTM sysfs support Frank Li
4 siblings, 1 reply; 13+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2025-02-18 14:36 UTC (permalink / raw)
To: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring
Cc: Shradha Todi, linux-kernel, linux-arm-kernel, linux-perf-users,
linux-pci, linux-arm-msm, Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Precision Time Management (PTM) mechanism defined in PCIe spec r6.0,
sec 6.22 allows precise coordination of timing information across multiple
components in a PCIe hierarchy with independent local time clocks.
While the PTM support itself is indicated by the presence of PTM Extended
Capability structure, Synopsys Designware IPs expose the PTM context
(timing information) through Vendor Specific Extended Capability (VSEC)
registers.
Hence, add the sysfs support to expose the PTM context information to
userspace from both PCIe RC and EP controllers. Below PTM context are
exposed through sysfs:
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
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
Documentation/ABI/testing/sysfs-platform-dwc-pcie | 70 ++++++
MAINTAINERS | 1 +
drivers/pci/controller/dwc/Makefile | 2 +-
drivers/pci/controller/dwc/pcie-designware-ep.c | 3 +
drivers/pci/controller/dwc/pcie-designware-host.c | 4 +
drivers/pci/controller/dwc/pcie-designware-sysfs.c | 278 +++++++++++++++++++++
drivers/pci/controller/dwc/pcie-designware.c | 6 +
drivers/pci/controller/dwc/pcie-designware.h | 22 ++
include/linux/pcie-dwc.h | 8 +
9 files changed, 393 insertions(+), 1 deletion(-)
diff --git a/Documentation/ABI/testing/sysfs-platform-dwc-pcie b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
new file mode 100644
index 000000000000..6b429108cd09
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
@@ -0,0 +1,70 @@
+What: /sys/devices/platform/*/dwc/ptm/ptm_local_clock
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM local clock in nanoseconds. Applicable for both Root
+ Complex and Endpoint mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_master_clock
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM master clock in nanoseconds. Applicable only for
+ Endpoint mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_t1
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM T1 timestamp in nanoseconds. Applicable only for
+ Endpoint mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_t2
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM T2 timestamp in nanoseconds. Applicable only for
+ Root Complex mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_t3
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM T3 timestamp in nanoseconds. Applicable only for
+ Root Complex mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_t4
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RO) PTM T4 timestamp in nanoseconds. Applicable only for
+ Endpoint mode.
+
+What: /sys/devices/platform/*/dwc/ptm/ptm_context_update
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RW) Control the PTM context update mode. Applicable only for
+ Endpoint mode.
+
+ 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/devices/platform/*/dwc/ptm/ptm_context_valid
+Date: February 2025
+Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+Description:
+ (RW) Control the PTM context validity (local clock timing).
+ Applicable only for Root Complex mode. 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
diff --git a/MAINTAINERS b/MAINTAINERS
index b4d09d52a750..1c3e21cfbc6e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -18120,6 +18120,7 @@ M: Jingoo Han <jingoohan1@gmail.com>
M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
L: linux-pci@vger.kernel.org
S: Maintained
+F: Documentation/ABI/testing/sysfs-platform-dwc-pcie
F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
F: drivers/pci/controller/dwc/*designware*
diff --git a/drivers/pci/controller/dwc/Makefile b/drivers/pci/controller/dwc/Makefile
index a8308d9ea986..3a962971249d 100644
--- a/drivers/pci/controller/dwc/Makefile
+++ b/drivers/pci/controller/dwc/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
-obj-$(CONFIG_PCIE_DW) += pcie-designware.o
+obj-$(CONFIG_PCIE_DW) += pcie-designware.o pcie-designware-sysfs.o
obj-$(CONFIG_PCIE_DW_HOST) += pcie-designware-host.o
obj-$(CONFIG_PCIE_DW_EP) += pcie-designware-ep.o
obj-$(CONFIG_PCIE_DW_PLAT) += pcie-designware-plat.o
diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c
index 8e07d432e74f..4bb7fd5d2fb0 100644
--- a/drivers/pci/controller/dwc/pcie-designware-ep.c
+++ b/drivers/pci/controller/dwc/pcie-designware-ep.c
@@ -666,6 +666,7 @@ void dw_pcie_ep_cleanup(struct dw_pcie_ep *ep)
{
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
+ pcie_designware_sysfs_exit(pci);
dw_pcie_edma_remove(pci);
}
EXPORT_SYMBOL_GPL(dw_pcie_ep_cleanup);
@@ -837,6 +838,8 @@ int dw_pcie_ep_init_registers(struct dw_pcie_ep *ep)
dw_pcie_ep_init_non_sticky_registers(pci);
+ pcie_designware_sysfs_init(pci, DW_PCIE_EP_TYPE);
+
return 0;
err_remove_edma:
diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c
index ffaded8f2df7..bd3195de923c 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -548,6 +548,8 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
if (pp->ops->post_init)
pp->ops->post_init(pp);
+ pcie_designware_sysfs_init(pci, DW_PCIE_RC_TYPE);
+
return 0;
err_stop_link:
@@ -572,6 +574,8 @@ void dw_pcie_host_deinit(struct dw_pcie_rp *pp)
{
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+ pcie_designware_sysfs_exit(pci);
+
pci_stop_root_bus(pp->bridge->bus);
pci_remove_root_bus(pp->bridge->bus);
diff --git a/drivers/pci/controller/dwc/pcie-designware-sysfs.c b/drivers/pci/controller/dwc/pcie-designware-sysfs.c
new file mode 100644
index 000000000000..1ba41163cf58
--- /dev/null
+++ b/drivers/pci/controller/dwc/pcie-designware-sysfs.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2025 Linaro Ltd.
+ * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+ */
+
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+
+#include "pcie-designware.h"
+
+static ssize_t ptm_context_update_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ u32 val;
+
+ if (sysfs_streq(buf, "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 (sysfs_streq(buf, "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 count;
+}
+
+static ssize_t ptm_context_update_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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))
+ return sysfs_emit(buf, "auto\n");
+
+ /*
+ * 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.
+ */
+ return sysfs_emit(buf, "manual\n");
+}
+
+static ssize_t ptm_context_valid_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ unsigned long arg;
+ u32 val;
+
+ if (kstrtoul(buf, 0, &arg) < 0)
+ return -EINVAL;
+
+ if (!!arg) {
+ 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 count;
+}
+
+static ssize_t ptm_context_valid_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ u32 val;
+
+ val = dw_pcie_readl_dbi(pci, pci->ptm_vsec_offset + PTM_RES_REQ_CTRL);
+
+ return sysfs_emit(buf, "%u\n", !!FIELD_GET(PTM_RES_CCONTEXT_VALID, val));
+}
+
+static ssize_t ptm_local_clock_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static ssize_t ptm_master_clock_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static ssize_t ptm_t1_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static ssize_t ptm_t2_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static ssize_t ptm_t3_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static ssize_t ptm_t4_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+ 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));
+
+ return sysfs_emit(buf, "%llu\n", ((u64) msb) << 32 | lsb);
+}
+
+static DEVICE_ATTR_RW(ptm_context_update);
+static DEVICE_ATTR_RW(ptm_context_valid);
+static DEVICE_ATTR_RO(ptm_local_clock);
+static DEVICE_ATTR_RO(ptm_master_clock);
+static DEVICE_ATTR_RO(ptm_t1);
+static DEVICE_ATTR_RO(ptm_t2);
+static DEVICE_ATTR_RO(ptm_t3);
+static DEVICE_ATTR_RO(ptm_t4);
+
+static struct attribute *ptm_attrs[] = {
+ &dev_attr_ptm_context_update.attr,
+ &dev_attr_ptm_context_valid.attr,
+ &dev_attr_ptm_local_clock.attr,
+ &dev_attr_ptm_master_clock.attr,
+ &dev_attr_ptm_t1.attr,
+ &dev_attr_ptm_t2.attr,
+ &dev_attr_ptm_t3.attr,
+ &dev_attr_ptm_t4.attr,
+ NULL
+};
+
+static umode_t ptm_attr_visible(struct kobject *kobj, struct attribute *attr,
+ int n)
+{
+ struct device *dev = container_of(kobj, struct device, kobj);
+ struct dw_pcie *pci = dev_get_drvdata(dev);
+
+ /* RC only needs local, t2 and t3 clocks and context_valid */
+ if ((attr == &dev_attr_ptm_t1.attr && pci->mode == DW_PCIE_RC_TYPE) ||
+ (attr == &dev_attr_ptm_t4.attr && pci->mode == DW_PCIE_RC_TYPE) ||
+ (attr == &dev_attr_ptm_master_clock.attr && pci->mode == DW_PCIE_RC_TYPE) ||
+ (attr == &dev_attr_ptm_context_update.attr && pci->mode == DW_PCIE_RC_TYPE))
+ return 0;
+
+ /* EP only needs local, master, t1, and t4 clocks and context_update */
+ if ((attr == &dev_attr_ptm_t2.attr && pci->mode == DW_PCIE_EP_TYPE) ||
+ (attr == &dev_attr_ptm_t3.attr && pci->mode == DW_PCIE_EP_TYPE) ||
+ (attr == &dev_attr_ptm_context_valid.attr && pci->mode == DW_PCIE_EP_TYPE))
+ return 0;
+
+ return attr->mode;
+}
+
+static const struct attribute_group ptm_attr_group = {
+ .name = "ptm",
+ .attrs = ptm_attrs,
+ .is_visible = ptm_attr_visible,
+};
+
+static const struct attribute_group *dwc_pcie_attr_groups[] = {
+ &ptm_attr_group,
+ NULL,
+};
+
+static void pcie_designware_sysfs_release(struct device *dev)
+{
+ kfree(dev);
+}
+
+void pcie_designware_sysfs_init(struct dw_pcie *pci,
+ enum dw_pcie_device_mode mode)
+{
+ struct device *dev;
+ int ret;
+
+ /* Check for capabilities before creating sysfs attrbutes */
+ ret = dw_pcie_find_ptm_capability(pci);
+ if (!ret) {
+ dev_dbg(pci->dev, "PTM capability not present\n");
+ return;
+ }
+
+ pci->ptm_vsec_offset = ret;
+ pci->mode = mode;
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return;
+
+ device_initialize(dev);
+ dev->groups = dwc_pcie_attr_groups;
+ dev->release = pcie_designware_sysfs_release;
+ dev->parent = pci->dev;
+ dev_set_drvdata(dev, pci);
+
+ ret = dev_set_name(dev, "dwc");
+ if (ret)
+ goto err_free;
+
+ ret = device_add(dev);
+ if (ret)
+ goto err_free;
+
+ pci->sysfs_dev = dev;
+
+ return;
+
+err_free:
+ put_device(dev);
+}
+
+void pcie_designware_sysfs_exit(struct dw_pcie *pci)
+{
+ if (pci->sysfs_dev)
+ device_unregister(pci->sysfs_dev);
+}
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
index a7c0671c6715..30825ec0648e 100644
--- a/drivers/pci/controller/dwc/pcie-designware.c
+++ b/drivers/pci/controller/dwc/pcie-designware.c
@@ -323,6 +323,12 @@ static u16 dw_pcie_find_vsec_capability(struct dw_pcie *pci,
return 0;
}
+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)) {
diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
index 501d9ddfea16..7d3cbdce37c8 100644
--- a/drivers/pci/controller/dwc/pcie-designware.h
+++ b/drivers/pci/controller/dwc/pcie-designware.h
@@ -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
@@ -439,6 +454,7 @@ struct dw_pcie_ops {
struct dw_pcie {
struct device *dev;
+ struct device *sysfs_dev;
void __iomem *dbi_base;
resource_size_t dbi_phys_addr;
void __iomem *dbi_base2;
@@ -464,6 +480,8 @@ struct dw_pcie {
struct reset_control_bulk_data app_rsts[DW_PCIE_NUM_APP_RSTS];
struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS];
struct gpio_desc *pe_rst;
+ u16 ptm_vsec_offset;
+ enum dw_pcie_device_mode mode;
bool suspended;
};
@@ -478,6 +496,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_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);
@@ -499,6 +518,9 @@ void dw_pcie_setup(struct dw_pcie *pci);
void dw_pcie_iatu_detect(struct dw_pcie *pci);
int dw_pcie_edma_detect(struct dw_pcie *pci);
void dw_pcie_edma_remove(struct dw_pcie *pci);
+void pcie_designware_sysfs_init(struct dw_pcie *pci,
+ enum dw_pcie_device_mode mode);
+void pcie_designware_sysfs_exit(struct dw_pcie *pci);
static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
{
diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h
index 261ae11d75a4..13835896290a 100644
--- a/include/linux/pcie-dwc.h
+++ b/include/linux/pcie-dwc.h
@@ -31,4 +31,12 @@ static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
{} /* terminator */
};
+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 },
+ { }
+};
+
#endif /* LINUX_PCIE_DWC_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/4] PCI: qcom-ep: Mask PTM_UPDATING interrupt
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
` (2 preceding siblings ...)
2025-02-18 14:36 ` [PATCH 3/4] PCI: dwc: Add sysfs support for PTM Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 14:36 ` Manivannan Sadhasivam via B4 Relay
2025-02-18 16:17 ` [PATCH 0/4] PCI: dwc: Add PTM sysfs support Frank Li
4 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam via B4 Relay @ 2025-02-18 14:36 UTC (permalink / raw)
To: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring
Cc: Shradha Todi, linux-kernel, linux-arm-kernel, linux-perf-users,
linux-pci, linux-arm-msm, Manivannan Sadhasivam
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
When 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.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index c08f64d7a825..940edb7be1b9 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] PCI: dwc: Add PTM sysfs support
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
` (3 preceding siblings ...)
2025-02-18 14:36 ` [PATCH 4/4] PCI: qcom-ep: Mask PTM_UPDATING interrupt Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 16:17 ` Frank Li
2025-02-19 7:49 ` Manivannan Sadhasivam
4 siblings, 1 reply; 13+ messages in thread
From: Frank Li @ 2025-02-18 16:17 UTC (permalink / raw)
To: manivannan.sadhasivam
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 08:06:39PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> Hi,
>
> This series adds sysfs support for PCIe PTM in Synopsys Designware IPs.
>
> First patch moves the common DWC struct definitions (dwc_pcie_vsec_id) to
> include/pci/pcie-dwc.h from dwc-pcie-pmu driver. This allows reusing the same
> definitions in pcie-designware-sysfs driver introduced in this series and also
> in the debugfs series by Shradha [1].
>
> Second patch adds support for searching the Vendor Specific Extended Capability
> (VSEC) in the pcie-designware driver. This patch was originally based on
> Shradha's patch [2], but modified to accept 'struct dwc_pcie_vsec_id' to avoid
> iterating through the vsec_ids in the driver.
>
> Third patch adds the actual sysfs support for PTM in a new file
> pcie-designware-sysfs.c built along with pcie-designware.c.
>
> Finally, fourth patch 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/devices/platform/1c10000.pcie/dwc/ptm/ptm_context_valid
>
> EP
> --
>
> $ echo auto > /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_context_update
>
> $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_local_clock
> 159612570424
>
> $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_master_clock
> 159609466232
>
> $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_t1
> 159609466112
>
> $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_t4
> 159609466518
I am not sure what real means by only show these number. It is quite
similar to network 1588, ptp. There were already linux-ptp
https://www.kernel.org/doc/html/v5.5/driver-api/ptp.html
Can we use similar method to sync local timer to master? I think it is real
purpuse of PTM.
Frank
>
> 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.
>
> Merging Strategy
> ================
>
> I'd like to have an ACK from the perf maintainers to take the whole series
> through PCI tree.
>
> [1] https://lore.kernel.org/linux-pci/20250214105007.97582-1-shradha.t@samsung.com
> [2] https://lore.kernel.org/linux-pci/20250214105007.97582-2-shradha.t@samsung.com
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> Manivannan Sadhasivam (4):
> perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
> PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC)
> PCI: dwc: Add sysfs support for PTM
> PCI: qcom-ep: Mask PTM_UPDATING interrupt
>
> Documentation/ABI/testing/sysfs-platform-dwc-pcie | 70 ++++++
> MAINTAINERS | 2 +
> drivers/pci/controller/dwc/Makefile | 2 +-
> drivers/pci/controller/dwc/pcie-designware-ep.c | 3 +
> drivers/pci/controller/dwc/pcie-designware-host.c | 4 +
> drivers/pci/controller/dwc/pcie-designware-sysfs.c | 278 +++++++++++++++++++++
> drivers/pci/controller/dwc/pcie-designware.c | 46 ++++
> drivers/pci/controller/dwc/pcie-designware.h | 22 ++
> drivers/pci/controller/dwc/pcie-qcom-ep.c | 8 +
> drivers/perf/dwc_pcie_pmu.c | 23 +-
> include/linux/pcie-dwc.h | 42 ++++
> 11 files changed, 478 insertions(+), 22 deletions(-)
> ---
> base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> change-id: 20250218-pcie-qcom-ptm-bf6952f5c4e5
>
> Best regards,
> --
> Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 16:31 ` Dmitry Baryshkov
2025-02-19 7:55 ` Manivannan Sadhasivam
2025-02-20 6:01 ` Shradha Todi
1 sibling, 1 reply; 13+ messages in thread
From: Dmitry Baryshkov @ 2025-02-18 16:31 UTC (permalink / raw)
To: manivannan.sadhasivam
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 08:06:40PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>
> Since these are common to all Desginware PCIe IPs, move them to a new
> header, 'pcie-dwc.h' so that other drivers could make use of them.
Which drivers are going to use it? Please provide an explanation.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> MAINTAINERS | 1 +
> drivers/perf/dwc_pcie_pmu.c | 23 ++---------------------
> include/linux/pcie-dwc.h | 34 ++++++++++++++++++++++++++++++++++
> 3 files changed, 37 insertions(+), 21 deletions(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 896a307fa065..b4d09d52a750 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18123,6 +18123,7 @@ S: Maintained
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
> F: drivers/pci/controller/dwc/*designware*
> +F: include/linux/pcie-dwc.h
>
> PCI DRIVER FOR TI DRA7XX/J721E
> M: Vignesh Raghavendra <vigneshr@ti.com>
> diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
> index cccecae9823f..05b37ea7cf16 100644
> --- a/drivers/perf/dwc_pcie_pmu.c
> +++ b/drivers/perf/dwc_pcie_pmu.c
> @@ -13,6 +13,7 @@
> #include <linux/errno.h>
> #include <linux/kernel.h>
> #include <linux/list.h>
> +#include <linux/pcie-dwc.h>
> #include <linux/perf_event.h>
> #include <linux/pci.h>
> #include <linux/platform_device.h>
> @@ -99,26 +100,6 @@ struct dwc_pcie_dev_info {
> struct list_head dev_node;
> };
>
> -struct dwc_pcie_pmu_vsec_id {
> - u16 vendor_id;
> - u16 vsec_id;
> - u8 vsec_rev;
> -};
> -
> -/*
> - * VSEC IDs are allocated by the vendor, so a given ID may mean different
> - * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> - */
> -static const struct dwc_pcie_pmu_vsec_id dwc_pcie_pmu_vsec_ids[] = {
> - { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - { .vendor_id = PCI_VENDOR_ID_AMPERE,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - { .vendor_id = PCI_VENDOR_ID_QCOM,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - {} /* terminator */
> -};
> -
> static ssize_t cpumask_show(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -529,7 +510,7 @@ static void dwc_pcie_unregister_pmu(void *data)
>
> static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
> {
> - const struct dwc_pcie_pmu_vsec_id *vid;
> + const struct dwc_pcie_vsec_id *vid;
> u16 vsec;
> u32 val;
>
> diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h
> new file mode 100644
> index 000000000000..261ae11d75a4
> --- /dev/null
> +++ b/include/linux/pcie-dwc.h
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2021-2023 Alibaba Inc.
> + *
> + * Copyright 2025 Linaro Ltd.
> + * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> + */
> +
> +#ifndef LINUX_PCIE_DWC_H
> +#define LINUX_PCIE_DWC_H
> +
> +#include <linux/pci_ids.h>
> +
> +struct dwc_pcie_vsec_id {
> + u16 vendor_id;
> + u16 vsec_id;
> + u8 vsec_rev;
> +};
> +
> +/*
> + * VSEC IDs are allocated by the vendor, so a given ID may mean different
> + * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> + */
> +static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
Having it in the header means that there are going to be several
copies of this data. Is that expected?
> + { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + { .vendor_id = PCI_VENDOR_ID_AMPERE,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + { .vendor_id = PCI_VENDOR_ID_QCOM,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + {} /* terminator */
> +};
> +
> +#endif /* LINUX_PCIE_DWC_H */
>
> --
> 2.25.1
>
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] PCI: dwc: Add sysfs support for PTM
2025-02-18 14:36 ` [PATCH 3/4] PCI: dwc: Add sysfs support for PTM Manivannan Sadhasivam via B4 Relay
@ 2025-02-18 17:54 ` Dmitry Baryshkov
2025-02-19 8:14 ` Manivannan Sadhasivam
0 siblings, 1 reply; 13+ messages in thread
From: Dmitry Baryshkov @ 2025-02-18 17:54 UTC (permalink / raw)
To: manivannan.sadhasivam
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 08:06:42PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>
> Precision Time Management (PTM) mechanism defined in PCIe spec r6.0,
> sec 6.22 allows precise coordination of timing information across multiple
> components in a PCIe hierarchy with independent local time clocks.
>
> While the PTM support itself is indicated by the presence of PTM Extended
> Capability structure, Synopsys Designware IPs expose the PTM context
> (timing information) through Vendor Specific Extended Capability (VSEC)
> registers.
>
> Hence, add the sysfs support to expose the PTM context information to
> userspace from both PCIe RC and EP controllers. Below PTM context are
> exposed through sysfs:
>
> 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
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> Documentation/ABI/testing/sysfs-platform-dwc-pcie | 70 ++++++
> MAINTAINERS | 1 +
> drivers/pci/controller/dwc/Makefile | 2 +-
> drivers/pci/controller/dwc/pcie-designware-ep.c | 3 +
> drivers/pci/controller/dwc/pcie-designware-host.c | 4 +
> drivers/pci/controller/dwc/pcie-designware-sysfs.c | 278 +++++++++++++++++++++
> drivers/pci/controller/dwc/pcie-designware.c | 6 +
> drivers/pci/controller/dwc/pcie-designware.h | 22 ++
> include/linux/pcie-dwc.h | 8 +
> 9 files changed, 393 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-platform-dwc-pcie b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
> new file mode 100644
> index 000000000000..6b429108cd09
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
Should be a class or just a ptm group in the PCIe controller device? How
generic are those attributes?
> @@ -0,0 +1,70 @@
> +What: /sys/devices/platform/*/dwc/ptm/ptm_local_clock
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM local clock in nanoseconds. Applicable for both Root
> + Complex and Endpoint mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_master_clock
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM master clock in nanoseconds. Applicable only for
> + Endpoint mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_t1
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM T1 timestamp in nanoseconds. Applicable only for
> + Endpoint mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_t2
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM T2 timestamp in nanoseconds. Applicable only for
> + Root Complex mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_t3
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM T3 timestamp in nanoseconds. Applicable only for
> + Root Complex mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_t4
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RO) PTM T4 timestamp in nanoseconds. Applicable only for
> + Endpoint mode.
> +
> +What: /sys/devices/platform/*/dwc/ptm/ptm_context_update
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RW) Control the PTM context update mode. Applicable only for
> + Endpoint mode.
> +
> + 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/devices/platform/*/dwc/ptm/ptm_context_valid
> +Date: February 2025
> +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> +Description:
> + (RW) Control the PTM context validity (local clock timing).
> + Applicable only for Root Complex mode. 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
> diff --git a/MAINTAINERS b/MAINTAINERS
> index b4d09d52a750..1c3e21cfbc6e 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18120,6 +18120,7 @@ M: Jingoo Han <jingoohan1@gmail.com>
> M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> L: linux-pci@vger.kernel.org
> S: Maintained
> +F: Documentation/ABI/testing/sysfs-platform-dwc-pcie
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
> F: drivers/pci/controller/dwc/*designware*
[...]
> +
> +static struct attribute *ptm_attrs[] = {
> + &dev_attr_ptm_context_update.attr,
> + &dev_attr_ptm_context_valid.attr,
> + &dev_attr_ptm_local_clock.attr,
> + &dev_attr_ptm_master_clock.attr,
> + &dev_attr_ptm_t1.attr,
> + &dev_attr_ptm_t2.attr,
> + &dev_attr_ptm_t3.attr,
> + &dev_attr_ptm_t4.attr,
> + NULL
> +};
> +
> +static umode_t ptm_attr_visible(struct kobject *kobj, struct attribute *attr,
> + int n)
> +{
> + struct device *dev = container_of(kobj, struct device, kobj);
> + struct dw_pcie *pci = dev_get_drvdata(dev);
> +
> + /* RC only needs local, t2 and t3 clocks and context_valid */
> + if ((attr == &dev_attr_ptm_t1.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> + (attr == &dev_attr_ptm_t4.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> + (attr == &dev_attr_ptm_master_clock.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> + (attr == &dev_attr_ptm_context_update.attr && pci->mode == DW_PCIE_RC_TYPE))
> + return 0;
The pci->mode checks definitely can be refactored to a top-level instead
of being repeated on each line.
> +
> + /* EP only needs local, master, t1, and t4 clocks and context_update */
> + if ((attr == &dev_attr_ptm_t2.attr && pci->mode == DW_PCIE_EP_TYPE) ||
> + (attr == &dev_attr_ptm_t3.attr && pci->mode == DW_PCIE_EP_TYPE) ||
> + (attr == &dev_attr_ptm_context_valid.attr && pci->mode == DW_PCIE_EP_TYPE))
> + return 0;
> +
> + return attr->mode;
I think it might be better to register two separate groups, one for RC,
one for EP and use presense of the corresponding capability in the
.is_visible callback to check if the PTM attributes should be visible at
all.
> +}
> +
> +static const struct attribute_group ptm_attr_group = {
> + .name = "ptm",
> + .attrs = ptm_attrs,
> + .is_visible = ptm_attr_visible,
> +};
> +
> +static const struct attribute_group *dwc_pcie_attr_groups[] = {
> + &ptm_attr_group,
> + NULL,
> +};
> +
> +static void pcie_designware_sysfs_release(struct device *dev)
> +{
> + kfree(dev);
> +}
> +
> +void pcie_designware_sysfs_init(struct dw_pcie *pci,
> + enum dw_pcie_device_mode mode)
> +{
> + struct device *dev;
> + int ret;
> +
> + /* Check for capabilities before creating sysfs attrbutes */
> + ret = dw_pcie_find_ptm_capability(pci);
> + if (!ret) {
> + dev_dbg(pci->dev, "PTM capability not present\n");
> + return;
> + }
> +
> + pci->ptm_vsec_offset = ret;
> + pci->mode = mode;
> +
> + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> + if (!dev)
> + return;
> +
> + device_initialize(dev);
> + dev->groups = dwc_pcie_attr_groups;
> + dev->release = pcie_designware_sysfs_release;
> + dev->parent = pci->dev;
> + dev_set_drvdata(dev, pci);
> +
> + ret = dev_set_name(dev, "dwc");
> + if (ret)
> + goto err_free;
> +
> + ret = device_add(dev);
> + if (ret)
> + goto err_free;
> +
> + pci->sysfs_dev = dev;
Why do you need to add a new device under the PCIe controller?
> +
> + return;
> +
> +err_free:
> + put_device(dev);
> +}
> +
> +void pcie_designware_sysfs_exit(struct dw_pcie *pci)
> +{
> + if (pci->sysfs_dev)
> + device_unregister(pci->sysfs_dev);
> +}
> diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
> index a7c0671c6715..30825ec0648e 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.c
> +++ b/drivers/pci/controller/dwc/pcie-designware.c
> @@ -323,6 +323,12 @@ static u16 dw_pcie_find_vsec_capability(struct dw_pcie *pci,
> return 0;
> }
>
> +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);
This API should go into the previous patch. Otherwise it will result in
unused function warnings.
> +
> int dw_pcie_read(void __iomem *addr, int size, u32 *val)
> {
> if (!IS_ALIGNED((uintptr_t)addr, size)) {
> diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h
> index 501d9ddfea16..7d3cbdce37c8 100644
> --- a/drivers/pci/controller/dwc/pcie-designware.h
> +++ b/drivers/pci/controller/dwc/pcie-designware.h
> @@ -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
> @@ -439,6 +454,7 @@ struct dw_pcie_ops {
>
> struct dw_pcie {
> struct device *dev;
> + struct device *sysfs_dev;
> void __iomem *dbi_base;
> resource_size_t dbi_phys_addr;
> void __iomem *dbi_base2;
> @@ -464,6 +480,8 @@ struct dw_pcie {
> struct reset_control_bulk_data app_rsts[DW_PCIE_NUM_APP_RSTS];
> struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS];
> struct gpio_desc *pe_rst;
> + u16 ptm_vsec_offset;
> + enum dw_pcie_device_mode mode;
> bool suspended;
> };
>
> @@ -478,6 +496,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_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);
> @@ -499,6 +518,9 @@ void dw_pcie_setup(struct dw_pcie *pci);
> void dw_pcie_iatu_detect(struct dw_pcie *pci);
> int dw_pcie_edma_detect(struct dw_pcie *pci);
> void dw_pcie_edma_remove(struct dw_pcie *pci);
> +void pcie_designware_sysfs_init(struct dw_pcie *pci,
> + enum dw_pcie_device_mode mode);
> +void pcie_designware_sysfs_exit(struct dw_pcie *pci);
>
> static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
> {
> diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h
> index 261ae11d75a4..13835896290a 100644
> --- a/include/linux/pcie-dwc.h
> +++ b/include/linux/pcie-dwc.h
> @@ -31,4 +31,12 @@ static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
> {} /* terminator */
> };
>
> +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 },
> + { }
> +};
> +
> #endif /* LINUX_PCIE_DWC_H */
>
> --
> 2.25.1
>
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/4] PCI: dwc: Add PTM sysfs support
2025-02-18 16:17 ` [PATCH 0/4] PCI: dwc: Add PTM sysfs support Frank Li
@ 2025-02-19 7:49 ` Manivannan Sadhasivam
0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2025-02-19 7:49 UTC (permalink / raw)
To: Frank Li
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 11:17:03AM -0500, Frank Li wrote:
> On Tue, Feb 18, 2025 at 08:06:39PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> > Hi,
> >
> > This series adds sysfs support for PCIe PTM in Synopsys Designware IPs.
> >
> > First patch moves the common DWC struct definitions (dwc_pcie_vsec_id) to
> > include/pci/pcie-dwc.h from dwc-pcie-pmu driver. This allows reusing the same
> > definitions in pcie-designware-sysfs driver introduced in this series and also
> > in the debugfs series by Shradha [1].
> >
> > Second patch adds support for searching the Vendor Specific Extended Capability
> > (VSEC) in the pcie-designware driver. This patch was originally based on
> > Shradha's patch [2], but modified to accept 'struct dwc_pcie_vsec_id' to avoid
> > iterating through the vsec_ids in the driver.
> >
> > Third patch adds the actual sysfs support for PTM in a new file
> > pcie-designware-sysfs.c built along with pcie-designware.c.
> >
> > Finally, fourth patch 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/devices/platform/1c10000.pcie/dwc/ptm/ptm_context_valid
> >
> > EP
> > --
> >
> > $ echo auto > /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_context_update
> >
> > $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_local_clock
> > 159612570424
> >
> > $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_master_clock
> > 159609466232
> >
> > $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_t1
> > 159609466112
> >
> > $ cat /sys/devices/platform/1c10000.pcie-ep/dwc/ptm/ptm_t4
> > 159609466518
>
>
> I am not sure what real means by only show these number.
These values are supposed to be consumed by the userspace applications to make
sure that whether the PTM feature is working as expected or not. For instance,
once the PTM dialog is established with PTM root, PTM requester's local clock
should be synchronized with PTM master clock. And these can be verified using
these sysfs attributes.
> It is quite
> similar to network 1588, ptp. There were already linux-ptp
> https://www.kernel.org/doc/html/v5.5/driver-api/ptp.html
>
PTP and PTM are different even though both are meant to synchronize times across
devices. PTM is limited to PCIe hierarchy and the actual synchronization is
performed at the hw level, limited to PCIe clock source (core_clk in DWC terms).
> Can we use similar method to sync local timer to master? I think it is real
> purpuse of PTM.
>
Actual synchronization happens in the hardware itself as I explained above.
Software is not intended to do anything (if not using any external master clock
source) to synchronize the clocks.
I think you are referring to synchronizing the global clock source (the one used
by the kernel) of the endpoint based on PTM. But I don't think that is what
intended by this feature.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
2025-02-18 16:31 ` Dmitry Baryshkov
@ 2025-02-19 7:55 ` Manivannan Sadhasivam
0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2025-02-19 7:55 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 06:31:02PM +0200, Dmitry Baryshkov wrote:
> On Tue, Feb 18, 2025 at 08:06:40PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> > From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> >
> > Since these are common to all Desginware PCIe IPs, move them to a new
> > header, 'pcie-dwc.h' so that other drivers could make use of them.
>
> Which drivers are going to use it? Please provide an explanation.
>
I can certainly add reference as 'upcoming pcie-designware-sysfs' driver.
> >
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> > MAINTAINERS | 1 +
> > drivers/perf/dwc_pcie_pmu.c | 23 ++---------------------
> > include/linux/pcie-dwc.h | 34 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 37 insertions(+), 21 deletions(-)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 896a307fa065..b4d09d52a750 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -18123,6 +18123,7 @@ S: Maintained
> > F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
> > F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
> > F: drivers/pci/controller/dwc/*designware*
> > +F: include/linux/pcie-dwc.h
> >
> > PCI DRIVER FOR TI DRA7XX/J721E
> > M: Vignesh Raghavendra <vigneshr@ti.com>
> > diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c
> > index cccecae9823f..05b37ea7cf16 100644
> > --- a/drivers/perf/dwc_pcie_pmu.c
> > +++ b/drivers/perf/dwc_pcie_pmu.c
> > @@ -13,6 +13,7 @@
> > #include <linux/errno.h>
> > #include <linux/kernel.h>
> > #include <linux/list.h>
> > +#include <linux/pcie-dwc.h>
> > #include <linux/perf_event.h>
> > #include <linux/pci.h>
> > #include <linux/platform_device.h>
> > @@ -99,26 +100,6 @@ struct dwc_pcie_dev_info {
> > struct list_head dev_node;
> > };
> >
> > -struct dwc_pcie_pmu_vsec_id {
> > - u16 vendor_id;
> > - u16 vsec_id;
> > - u8 vsec_rev;
> > -};
> > -
> > -/*
> > - * VSEC IDs are allocated by the vendor, so a given ID may mean different
> > - * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> > - */
> > -static const struct dwc_pcie_pmu_vsec_id dwc_pcie_pmu_vsec_ids[] = {
> > - { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - { .vendor_id = PCI_VENDOR_ID_AMPERE,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - { .vendor_id = PCI_VENDOR_ID_QCOM,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - {} /* terminator */
> > -};
> > -
> > static ssize_t cpumask_show(struct device *dev,
> > struct device_attribute *attr,
> > char *buf)
> > @@ -529,7 +510,7 @@ static void dwc_pcie_unregister_pmu(void *data)
> >
> > static u16 dwc_pcie_des_cap(struct pci_dev *pdev)
> > {
> > - const struct dwc_pcie_pmu_vsec_id *vid;
> > + const struct dwc_pcie_vsec_id *vid;
> > u16 vsec;
> > u32 val;
> >
> > diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h
> > new file mode 100644
> > index 000000000000..261ae11d75a4
> > --- /dev/null
> > +++ b/include/linux/pcie-dwc.h
> > @@ -0,0 +1,34 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright (C) 2021-2023 Alibaba Inc.
> > + *
> > + * Copyright 2025 Linaro Ltd.
> > + * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > + */
> > +
> > +#ifndef LINUX_PCIE_DWC_H
> > +#define LINUX_PCIE_DWC_H
> > +
> > +#include <linux/pci_ids.h>
> > +
> > +struct dwc_pcie_vsec_id {
> > + u16 vendor_id;
> > + u16 vsec_id;
> > + u8 vsec_rev;
> > +};
> > +
> > +/*
> > + * VSEC IDs are allocated by the vendor, so a given ID may mean different
> > + * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> > + */
> > +static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
>
> Having it in the header means that there are going to be several
> copies of this data. Is that expected?
>
Yes. I wanted to consolidate these ids in a single file to make it easy to track
them. Otherwise, these are spread across different subsystems, making it harder
to maintain.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 3/4] PCI: dwc: Add sysfs support for PTM
2025-02-18 17:54 ` Dmitry Baryshkov
@ 2025-02-19 8:14 ` Manivannan Sadhasivam
0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2025-02-19 8:14 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Shuai Xue, Jing Zhang, Will Deacon, Mark Rutland, Jingoo Han,
Bjorn Helgaas, Lorenzo Pieralisi, Krzysztof Wilczyński,
Rob Herring, Shradha Todi, linux-kernel, linux-arm-kernel,
linux-perf-users, linux-pci, linux-arm-msm
On Tue, Feb 18, 2025 at 07:54:24PM +0200, Dmitry Baryshkov wrote:
> On Tue, Feb 18, 2025 at 08:06:42PM +0530, Manivannan Sadhasivam via B4 Relay wrote:
> > From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> >
> > Precision Time Management (PTM) mechanism defined in PCIe spec r6.0,
> > sec 6.22 allows precise coordination of timing information across multiple
> > components in a PCIe hierarchy with independent local time clocks.
> >
> > While the PTM support itself is indicated by the presence of PTM Extended
> > Capability structure, Synopsys Designware IPs expose the PTM context
> > (timing information) through Vendor Specific Extended Capability (VSEC)
> > registers.
> >
> > Hence, add the sysfs support to expose the PTM context information to
> > userspace from both PCIe RC and EP controllers. Below PTM context are
> > exposed through sysfs:
> >
> > 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
> >
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> > Documentation/ABI/testing/sysfs-platform-dwc-pcie | 70 ++++++
> > MAINTAINERS | 1 +
> > drivers/pci/controller/dwc/Makefile | 2 +-
> > drivers/pci/controller/dwc/pcie-designware-ep.c | 3 +
> > drivers/pci/controller/dwc/pcie-designware-host.c | 4 +
> > drivers/pci/controller/dwc/pcie-designware-sysfs.c | 278 +++++++++++++++++++++
> > drivers/pci/controller/dwc/pcie-designware.c | 6 +
> > drivers/pci/controller/dwc/pcie-designware.h | 22 ++
> > include/linux/pcie-dwc.h | 8 +
> > 9 files changed, 393 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-platform-dwc-pcie b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
> > new file mode 100644
> > index 000000000000..6b429108cd09
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-platform-dwc-pcie
>
> Should be a class or just a ptm group in the PCIe controller device? How
> generic are those attributes?
>
Even though these are generic attributes, the way PTM support is exposed in
kernel right now makes it harder to make these as generic attributes. These
attributes are specific to RC/EP controllers and the generic PTM driver is for
endpoint devices. Maybe I could think of exposing it for RC/EP controller
drivers (not just DWC). But still then these would be exposed as a group under
each platform device.
> > @@ -0,0 +1,70 @@
> > +What: /sys/devices/platform/*/dwc/ptm/ptm_local_clock
> > +Date: February 2025
> > +Contact: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > +Description:
> > + (RO) PTM local clock in nanoseconds. Applicable for both Root
> > + Complex and Endpoint mode.
[...]
> > +static umode_t ptm_attr_visible(struct kobject *kobj, struct attribute *attr,
> > + int n)
> > +{
> > + struct device *dev = container_of(kobj, struct device, kobj);
> > + struct dw_pcie *pci = dev_get_drvdata(dev);
> > +
> > + /* RC only needs local, t2 and t3 clocks and context_valid */
> > + if ((attr == &dev_attr_ptm_t1.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> > + (attr == &dev_attr_ptm_t4.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> > + (attr == &dev_attr_ptm_master_clock.attr && pci->mode == DW_PCIE_RC_TYPE) ||
> > + (attr == &dev_attr_ptm_context_update.attr && pci->mode == DW_PCIE_RC_TYPE))
> > + return 0;
>
> The pci->mode checks definitely can be refactored to a top-level instead
> of being repeated on each line.
>
Ok.
> > +
> > + /* EP only needs local, master, t1, and t4 clocks and context_update */
> > + if ((attr == &dev_attr_ptm_t2.attr && pci->mode == DW_PCIE_EP_TYPE) ||
> > + (attr == &dev_attr_ptm_t3.attr && pci->mode == DW_PCIE_EP_TYPE) ||
> > + (attr == &dev_attr_ptm_context_valid.attr && pci->mode == DW_PCIE_EP_TYPE))
> > + return 0;
> > +
> > + return attr->mode;
>
> I think it might be better to register two separate groups, one for RC,
> one for EP and use presense of the corresponding capability in the
> .is_visible callback to check if the PTM attributes should be visible at
> all.
>
What benefit does it provide? I did thought about this idea, but then I didn't
find useful since the top level platform device (RC/EP) should itself
distinguish between PTM requester and responder. So one more differentiation
seemed overkill to me.
> > +}
> > +
> > +static const struct attribute_group ptm_attr_group = {
> > + .name = "ptm",
> > + .attrs = ptm_attrs,
> > + .is_visible = ptm_attr_visible,
> > +};
> > +
> > +static const struct attribute_group *dwc_pcie_attr_groups[] = {
> > + &ptm_attr_group,
> > + NULL,
> > +};
> > +
> > +static void pcie_designware_sysfs_release(struct device *dev)
> > +{
> > + kfree(dev);
> > +}
> > +
> > +void pcie_designware_sysfs_init(struct dw_pcie *pci,
> > + enum dw_pcie_device_mode mode)
> > +{
> > + struct device *dev;
> > + int ret;
> > +
> > + /* Check for capabilities before creating sysfs attrbutes */
> > + ret = dw_pcie_find_ptm_capability(pci);
> > + if (!ret) {
> > + dev_dbg(pci->dev, "PTM capability not present\n");
> > + return;
> > + }
> > +
> > + pci->ptm_vsec_offset = ret;
> > + pci->mode = mode;
> > +
> > + dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> > + if (!dev)
> > + return;
> > +
> > + device_initialize(dev);
> > + dev->groups = dwc_pcie_attr_groups;
> > + dev->release = pcie_designware_sysfs_release;
> > + dev->parent = pci->dev;
> > + dev_set_drvdata(dev, pci);
> > +
> > + ret = dev_set_name(dev, "dwc");
> > + if (ret)
> > + goto err_free;
> > +
> > + ret = device_add(dev);
> > + if (ret)
> > + goto err_free;
> > +
> > + pci->sysfs_dev = dev;
>
> Why do you need to add a new device under the PCIe controller?
>
Just because we cannot reference the 'struct dw_pcie' from the 'struct device'
belonging to the platform device. All the controller drivers are already setting
their own private structure as drvdata.
> > +
> > + return;
> > +
> > +err_free:
> > + put_device(dev);
> > +}
> > +
> > +void pcie_designware_sysfs_exit(struct dw_pcie *pci)
> > +{
> > + if (pci->sysfs_dev)
> > + device_unregister(pci->sysfs_dev);
> > +}
> > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
> > index a7c0671c6715..30825ec0648e 100644
> > --- a/drivers/pci/controller/dwc/pcie-designware.c
> > +++ b/drivers/pci/controller/dwc/pcie-designware.c
> > @@ -323,6 +323,12 @@ static u16 dw_pcie_find_vsec_capability(struct dw_pcie *pci,
> > return 0;
> > }
> >
> > +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);
>
> This API should go into the previous patch. Otherwise it will result in
> unused function warnings.
>
Yes, but that should be fine. Unused warnings are generally acceptable if the
function is defined in subsequent patch. Only rule is that the build should not
be broken when using defconfig.
Moreover, the previous patch just adds the VSEC helpers and I inherited them
from Shradha's patch. Clubbing PTM API would make it look like two separate
changes in a single patch.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
2025-02-18 16:31 ` Dmitry Baryshkov
@ 2025-02-20 6:01 ` Shradha Todi
2025-02-20 7:27 ` Manivannan Sadhasivam
1 sibling, 1 reply; 13+ messages in thread
From: Shradha Todi @ 2025-02-20 6:01 UTC (permalink / raw)
To: manivannan.sadhasivam, 'Shuai Xue', 'Jing Zhang',
'Will Deacon', 'Mark Rutland',
'Jingoo Han', 'Bjorn Helgaas',
'Lorenzo Pieralisi', 'Krzysztof Wilczyński',
'Rob Herring'
Cc: linux-kernel, linux-arm-kernel, linux-perf-users, linux-pci,
linux-arm-msm
> -----Original Message-----
> From: Manivannan Sadhasivam via B4 Relay <devnull+manivannan.sadhasivam.linaro.org@kernel.org>
> Sent: 18 February 2025 20:07
> To: Shuai Xue <xueshuai@linux.alibaba.com>; Jing Zhang <renyu.zj@linux.alibaba.com>; Will Deacon <will@kernel.org>; Mark Rutland
> <mark.rutland@arm.com>; Jingoo Han <jingoohan1@gmail.com>; Bjorn Helgaas <bhelgaas@google.com>; Lorenzo Pieralisi
> <lpieralisi@kernel.org>; Krzysztof Wilczyński <kw@linux.com>; Rob Herring <robh@kernel.org>
> Cc: Shradha Todi <shradha.t@samsung.com>; linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-perf-
> users@vger.kernel.org; linux-pci@vger.kernel.org; linux-arm-msm@vger.kernel.org; Manivannan Sadhasivam
> <manivannan.sadhasivam@linaro.org>
> Subject: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
>
> From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
>
> Since these are common to all Desginware PCIe IPs, move them to a new header, 'pcie-dwc.h' so that other drivers could make use of
> them.
>
> Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> ---
> MAINTAINERS | 1 +
> drivers/perf/dwc_pcie_pmu.c | 23 ++---------------------
> include/linux/pcie-dwc.h | 34 ++++++++++++++++++++++++++++++++++
> 3 files changed, 37 insertions(+), 21 deletions(-)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 896a307fa065..b4d09d52a750 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -18123,6 +18123,7 @@ S: Maintained
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
> F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
> F: drivers/pci/controller/dwc/*designware*
> +F: include/linux/pcie-dwc.h
>
> PCI DRIVER FOR TI DRA7XX/J721E
> M: Vignesh Raghavendra <vigneshr@ti.com>
> diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index cccecae9823f..05b37ea7cf16 100644
> --- a/drivers/perf/dwc_pcie_pmu.c
> +++ b/drivers/perf/dwc_pcie_pmu.c
> @@ -13,6 +13,7 @@
> #include <linux/errno.h>
> #include <linux/kernel.h>
> #include <linux/list.h>
> +#include <linux/pcie-dwc.h>
> #include <linux/perf_event.h>
> #include <linux/pci.h>
> #include <linux/platform_device.h>
> @@ -99,26 +100,6 @@ struct dwc_pcie_dev_info {
> struct list_head dev_node;
> };
>
> -struct dwc_pcie_pmu_vsec_id {
> - u16 vendor_id;
> - u16 vsec_id;
> - u8 vsec_rev;
> -};
> -
> -/*
> - * VSEC IDs are allocated by the vendor, so a given ID may mean different
> - * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> - */
> -static const struct dwc_pcie_pmu_vsec_id dwc_pcie_pmu_vsec_ids[] = {
> - { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - { .vendor_id = PCI_VENDOR_ID_AMPERE,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - { .vendor_id = PCI_VENDOR_ID_QCOM,
> - .vsec_id = 0x02, .vsec_rev = 0x4 },
> - {} /* terminator */
> -};
> -
> static ssize_t cpumask_show(struct device *dev,
> struct device_attribute *attr,
> char *buf)
> @@ -529,7 +510,7 @@ static void dwc_pcie_unregister_pmu(void *data)
>
> static u16 dwc_pcie_des_cap(struct pci_dev *pdev) {
> - const struct dwc_pcie_pmu_vsec_id *vid;
> + const struct dwc_pcie_vsec_id *vid;
> u16 vsec;
> u32 val;
>
> diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h new file mode 100644 index 000000000000..261ae11d75a4
> --- /dev/null
> +++ b/include/linux/pcie-dwc.h
> @@ -0,0 +1,34 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * Copyright (C) 2021-2023 Alibaba Inc.
> + *
> + * Copyright 2025 Linaro Ltd.
> + * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> + */
> +
> +#ifndef LINUX_PCIE_DWC_H
> +#define LINUX_PCIE_DWC_H
> +
> +#include <linux/pci_ids.h>
> +
> +struct dwc_pcie_vsec_id {
> + u16 vendor_id;
> + u16 vsec_id;
> + u8 vsec_rev;
> +};
> +
> +/*
> + * VSEC IDs are allocated by the vendor, so a given ID may mean
> +different
> + * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> + */
> +static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
Rename this to dwc_pcie_rasdes_vsec_ids? pmu was perf file specific but technically the vsec is rasdes.
> + { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + { .vendor_id = PCI_VENDOR_ID_AMPERE,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + { .vendor_id = PCI_VENDOR_ID_QCOM,
> + .vsec_id = 0x02, .vsec_rev = 0x4 },
> + {} /* terminator */
> +};
> +
> +#endif /* LINUX_PCIE_DWC_H */
>
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
2025-02-20 6:01 ` Shradha Todi
@ 2025-02-20 7:27 ` Manivannan Sadhasivam
0 siblings, 0 replies; 13+ messages in thread
From: Manivannan Sadhasivam @ 2025-02-20 7:27 UTC (permalink / raw)
To: Shradha Todi
Cc: 'Shuai Xue', 'Jing Zhang', 'Will Deacon',
'Mark Rutland', 'Jingoo Han',
'Bjorn Helgaas', 'Lorenzo Pieralisi',
'Krzysztof Wilczyński', 'Rob Herring',
linux-kernel, linux-arm-kernel, linux-perf-users, linux-pci,
linux-arm-msm
On Thu, Feb 20, 2025 at 11:31:49AM +0530, Shradha Todi wrote:
>
>
> > -----Original Message-----
> > From: Manivannan Sadhasivam via B4 Relay <devnull+manivannan.sadhasivam.linaro.org@kernel.org>
> > Sent: 18 February 2025 20:07
> > To: Shuai Xue <xueshuai@linux.alibaba.com>; Jing Zhang <renyu.zj@linux.alibaba.com>; Will Deacon <will@kernel.org>; Mark Rutland
> > <mark.rutland@arm.com>; Jingoo Han <jingoohan1@gmail.com>; Bjorn Helgaas <bhelgaas@google.com>; Lorenzo Pieralisi
> > <lpieralisi@kernel.org>; Krzysztof Wilczyński <kw@linux.com>; Rob Herring <robh@kernel.org>
> > Cc: Shradha Todi <shradha.t@samsung.com>; linux-kernel@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-perf-
> > users@vger.kernel.org; linux-pci@vger.kernel.org; linux-arm-msm@vger.kernel.org; Manivannan Sadhasivam
> > <manivannan.sadhasivam@linaro.org>
> > Subject: [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h'
> >
> > From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> >
> > Since these are common to all Desginware PCIe IPs, move them to a new header, 'pcie-dwc.h' so that other drivers could make use of
> > them.
> >
> > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > ---
> > MAINTAINERS | 1 +
> > drivers/perf/dwc_pcie_pmu.c | 23 ++---------------------
> > include/linux/pcie-dwc.h | 34 ++++++++++++++++++++++++++++++++++
> > 3 files changed, 37 insertions(+), 21 deletions(-)
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 896a307fa065..b4d09d52a750 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -18123,6 +18123,7 @@ S: Maintained
> > F: Documentation/devicetree/bindings/pci/snps,dw-pcie-ep.yaml
> > F: Documentation/devicetree/bindings/pci/snps,dw-pcie.yaml
> > F: drivers/pci/controller/dwc/*designware*
> > +F: include/linux/pcie-dwc.h
> >
> > PCI DRIVER FOR TI DRA7XX/J721E
> > M: Vignesh Raghavendra <vigneshr@ti.com>
> > diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index cccecae9823f..05b37ea7cf16 100644
> > --- a/drivers/perf/dwc_pcie_pmu.c
> > +++ b/drivers/perf/dwc_pcie_pmu.c
> > @@ -13,6 +13,7 @@
> > #include <linux/errno.h>
> > #include <linux/kernel.h>
> > #include <linux/list.h>
> > +#include <linux/pcie-dwc.h>
> > #include <linux/perf_event.h>
> > #include <linux/pci.h>
> > #include <linux/platform_device.h>
> > @@ -99,26 +100,6 @@ struct dwc_pcie_dev_info {
> > struct list_head dev_node;
> > };
> >
> > -struct dwc_pcie_pmu_vsec_id {
> > - u16 vendor_id;
> > - u16 vsec_id;
> > - u8 vsec_rev;
> > -};
> > -
> > -/*
> > - * VSEC IDs are allocated by the vendor, so a given ID may mean different
> > - * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> > - */
> > -static const struct dwc_pcie_pmu_vsec_id dwc_pcie_pmu_vsec_ids[] = {
> > - { .vendor_id = PCI_VENDOR_ID_ALIBABA,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - { .vendor_id = PCI_VENDOR_ID_AMPERE,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - { .vendor_id = PCI_VENDOR_ID_QCOM,
> > - .vsec_id = 0x02, .vsec_rev = 0x4 },
> > - {} /* terminator */
> > -};
> > -
> > static ssize_t cpumask_show(struct device *dev,
> > struct device_attribute *attr,
> > char *buf)
> > @@ -529,7 +510,7 @@ static void dwc_pcie_unregister_pmu(void *data)
> >
> > static u16 dwc_pcie_des_cap(struct pci_dev *pdev) {
> > - const struct dwc_pcie_pmu_vsec_id *vid;
> > + const struct dwc_pcie_vsec_id *vid;
> > u16 vsec;
> > u32 val;
> >
> > diff --git a/include/linux/pcie-dwc.h b/include/linux/pcie-dwc.h new file mode 100644 index 000000000000..261ae11d75a4
> > --- /dev/null
> > +++ b/include/linux/pcie-dwc.h
> > @@ -0,0 +1,34 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright (C) 2021-2023 Alibaba Inc.
> > + *
> > + * Copyright 2025 Linaro Ltd.
> > + * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > + */
> > +
> > +#ifndef LINUX_PCIE_DWC_H
> > +#define LINUX_PCIE_DWC_H
> > +
> > +#include <linux/pci_ids.h>
> > +
> > +struct dwc_pcie_vsec_id {
> > + u16 vendor_id;
> > + u16 vsec_id;
> > + u8 vsec_rev;
> > +};
> > +
> > +/*
> > + * VSEC IDs are allocated by the vendor, so a given ID may mean
> > +different
> > + * things to different vendors. See PCIe r6.0, sec 7.9.5.2.
> > + */
> > +static const struct dwc_pcie_vsec_id dwc_pcie_pmu_vsec_ids[] = {
>
> Rename this to dwc_pcie_rasdes_vsec_ids? pmu was perf file specific but technically the vsec is rasdes.
>
Sure.
- Mani
--
மணிவண்ணன் சதாசிவம்
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-02-20 7:32 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 14:36 [PATCH 0/4] PCI: dwc: Add PTM sysfs support Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 1/4] perf/dwc_pcie: Move common DWC struct definitions to 'pcie-dwc.h' Manivannan Sadhasivam via B4 Relay
2025-02-18 16:31 ` Dmitry Baryshkov
2025-02-19 7:55 ` Manivannan Sadhasivam
2025-02-20 6:01 ` Shradha Todi
2025-02-20 7:27 ` Manivannan Sadhasivam
2025-02-18 14:36 ` [PATCH 2/4] PCI: dwc: Add helper to find the Vendor Specific Extended Capability (VSEC) Manivannan Sadhasivam via B4 Relay
2025-02-18 14:36 ` [PATCH 3/4] PCI: dwc: Add sysfs support for PTM Manivannan Sadhasivam via B4 Relay
2025-02-18 17:54 ` Dmitry Baryshkov
2025-02-19 8:14 ` Manivannan Sadhasivam
2025-02-18 14:36 ` [PATCH 4/4] PCI: qcom-ep: Mask PTM_UPDATING interrupt Manivannan Sadhasivam via B4 Relay
2025-02-18 16:17 ` [PATCH 0/4] PCI: dwc: Add PTM sysfs support Frank Li
2025-02-19 7:49 ` Manivannan Sadhasivam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox