Skip to contentSkip to conversation

igc: Add support for PCIe PTM

PATCH Superseded Vinicius Costa Gomes 3 participants 13 messages Mar 22, 2021 – Mar 23, 2021

Subsystems (4)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover igc: Add support for PCIe PTM

Hi,

Changes from v2:
- Now the PTM timestamps are retrieved synchronously with the

    ioctl();
  - Fixed some typos in constants;
  - The IGC_PTM_STAT register is write-1-to-clear, document this more
    clearly;

Changes from v1:
- This now should cross compile better, convert_art_ns_to_tsc() will

    only be used if CONFIG_X86_TSC is enabled;
  - PCIe PTM errors reported by the NIC are logged and PTM cycles are
    restarted in case an error is detected;

Original cover letter:

This adds support for PCIe PTM (Precision Time Measurement) to the igc driver. PCIe PTM allows the NIC and Host clocks to be compared more precisely, improving the clock synchronization accuracy.

Patch 1/3 reverts a commit that made pci_enable_ptm() private to the PCI subsystem, reverting makes it possible for it to be called from the drivers.

Patch 2/3 calls pci_enable_ptm() from the igc driver.

Patch 3/3 implements the PCIe PTM support. It adds a workqueue that reads the PTM registers periodically and collects the information so a subsequent call to getcrosststamp() has all the timestamps needed.

Some questions are raised (also pointed out in the commit message):

1. Using convert_art_ns_to_tsc() is too x86 specific, there should be a common way to create a 'system_counterval_t' from a timestamp.

2. convert_art_ns_to_tsc() says that it should only be used when X86_FEATURE_TSC_KNOWN_FREQ is true, but during tests it works even when it returns false. Should that check be done?

Cheers,

Vinicius Costa Gomes (3):
Revert "PCI: Make pci_enable_ptm() private"
igc: Enable PCIe PTM
igc: Add support for PTP getcrosststamp()

 drivers/net/ethernet/intel/igc/igc.h         |   1 +
 drivers/net/ethernet/intel/igc/igc_defines.h |  31 ++++
 drivers/net/ethernet/intel/igc/igc_main.c    |   6 +
 drivers/net/ethernet/intel/igc/igc_ptp.c     | 173 +++++++++++++++++++
 drivers/net/ethernet/intel/igc/igc_regs.h    |  23 +++
 drivers/pci/pci.h                            |   3 -
 include/linux/pci.h                          |   7 +
 7 files changed, 241 insertions(+), 3 deletions(-)
Signature · 1 line
2.31.0
#1 lore raw

PATCH v3 1/3 Revert "PCI: Make pci_enable_ptm() private"

Make pci_enable_ptm() accessible from the drivers.

Even if PTM still works on the platform I am using without calling this function, it might be possible that it's not always the case.

Exposing this to the driver enables the driver to use the 'ptm_enabled' field of 'pci_dev' to check if PTM is enabled or not.

This reverts commit ac6c26da29c12fa511c877c273ed5c939dc9e96c.

---
 drivers/pci/pci.h   | 3 ---
 include/linux/pci.h | 7 +++++++
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci.h +0 -3
index ef7c4661314f..2c61557e1cc1 100644
@@ -599,11 +599,8 @@ static inline void pcie_ecrc_get_policy(char *str) { }
 
 #ifdef CONFIG_PCIE_PTM
 void pci_ptm_init(struct pci_dev *dev);
-int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
 #else
 static inline void pci_ptm_init(struct pci_dev *dev) { }
-static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
-{ return -EINVAL; }
 #endif
 
 struct pci_dev_reset_methods {
include/linux/pci.h +7 -0
index 86c799c97b77..3d3dc07eac3b 100644
@@ -1610,6 +1610,13 @@ static inline bool pci_aer_available(void) { return false; }
 
 bool pci_ats_disabled(void);
 
+#ifdef CONFIG_PCIE_PTM
+int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
+#else
+static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
+{ return -EINVAL; }
+#endif
+
 void pci_cfg_access_lock(struct pci_dev *dev);
 bool pci_cfg_access_trylock(struct pci_dev *dev);
 void pci_cfg_access_unlock(struct pci_dev *dev);
Signature · 1 line
2.31.0
#2 lore raw

Re: [PATCH next-queue v3 1/3] Revert "PCI: Make pci_enable_ptm() private"

Quoted 5 lines · Vinicius Costa Gomes

Make pci_enable_ptm() accessible from the drivers.

Even if PTM still works on the platform I am using without calling this function, it might be possible that it's not always the case.

Quoted 7 lines

Exposing this to the driver enables the driver to use the 'ptm_enabled' field of 'pci_dev' to check if PTM is enabled or not.

This reverts commit ac6c26da29c12fa511c877c273ed5c939dc9e96c.

Without an EXPORT_SYMBOL_GPL this is not going to be very useful for your driver.

#3 lore raw

Re: [PATCH next-queue v3 1/3] Revert "PCI: Make pci_enable_ptm() private"

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Vinicius Costa Gomes

Make pci_enable_ptm() accessible from the drivers.

Even if PTM still works on the platform I am using without calling this function, it might be possible that it's not always the case.

Exposing this to the driver enables the driver to use the 'ptm_enabled' field of 'pci_dev' to check if PTM is enabled or not.

Quoted 7 lines
Quoted 4 lines

This reverts commit ac6c26da29c12fa511c877c273ed5c939dc9e96c.

Without an EXPORT_SYMBOL_GPL this is not going to be very useful for your driver.

Unless I am missing something here, the commit that made 'pci_enable_ptm()' private didn't remove the 'EXPORT_SYMBOL' from the function definition in drivers/pci/pcie/ptm.c.

Cheers,

Signature · 1 line
Vinicius
#4 lore raw

Re: [PATCH next-queue v3 1/3] Revert "PCI: Make pci_enable_ptm() private"

Quoted 6 lines · Vinicius Costa Gomes
Quoted 2 lines

Without an EXPORT_SYMBOL_GPL this is not going to be very useful for your driver.

Unless I am missing something here, the commit that made 'pci_enable_ptm()' private didn't remove the 'EXPORT_SYMBOL' from the function definition in drivers/pci/pcie/ptm.c.

OOPS, indeed. Looks like right now the function is nindeed exported, but has no single user at all.

#5 lore raw

Re: [PATCH next-queue v3 1/3] Revert "PCI: Make pci_enable_ptm() private"

In reply to Vinicius Costa Gomes
Quoted 4 lines · Vinicius Costa Gomes

Make pci_enable_ptm() accessible from the drivers.

Even if PTM still works on the platform I am using without calling this function, it might be possible that it's not always the case.

I don't understand the value of this paragraph. The rest of it makes good sense (although I think we might want to add a wrapper as I mentioned elsewhere).

Quoted 49 lines

Exposing this to the driver enables the driver to use the 'ptm_enabled' field of 'pci_dev' to check if PTM is enabled or not.

This reverts commit ac6c26da29c12fa511c877c273ed5c939dc9e96c.

---
 drivers/pci/pci.h   | 3 ---
 include/linux/pci.h | 7 +++++++
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/pci/pci.h +0 -3
index ef7c4661314f..2c61557e1cc1 100644
@@ -599,11 +599,8 @@ static inline void pcie_ecrc_get_policy(char *str) { }
 
 #ifdef CONFIG_PCIE_PTM
 void pci_ptm_init(struct pci_dev *dev);
-int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
 #else
 static inline void pci_ptm_init(struct pci_dev *dev) { }
-static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
-{ return -EINVAL; }
 #endif
 
 struct pci_dev_reset_methods {
include/linux/pci.h +7 -0
index 86c799c97b77..3d3dc07eac3b 100644
@@ -1610,6 +1610,13 @@ static inline bool pci_aer_available(void) { return false; }
 
 bool pci_ats_disabled(void);
 
+#ifdef CONFIG_PCIE_PTM
+int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
+#else
+static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
+{ return -EINVAL; }
+#endif
+
 void pci_cfg_access_lock(struct pci_dev *dev);
 bool pci_cfg_access_trylock(struct pci_dev *dev);
 void pci_cfg_access_unlock(struct pci_dev *dev);
Signature · 1 line
2.31.0
#6 lore raw

Re: [PATCH next-queue v3 1/3] Revert "PCI: Make pci_enable_ptm() private"

Quoted 10 lines · Bjorn Helgaas
Quoted 4 lines · Vinicius Costa Gomes

Make pci_enable_ptm() accessible from the drivers.

Even if PTM still works on the platform I am using without calling this function, it might be possible that it's not always the case.

I don't understand the value of this paragraph. The rest of it makes good sense (although I think we might want to add a wrapper as I mentioned elsewhere).

Sure. Will remove this paragraph, and add the helper as you mentioned. Thanks.

Cheers,

Signature · 1 line
Vinicius
#7 lore raw

PATCH v3 2/3 igc: Enable PCIe PTM

In reply to Vinicius Costa Gomes

In practice, enabling PTM also sets the enabled_ptm flag in the PCI device, the flag will be used for detecting if PTM is enabled before adding support for the SYSOFFSET_PRECISE ioctl() (which is added by implementing the getcrosststamp() PTP function).

---
 drivers/net/ethernet/intel/igc/igc_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/igc/igc_main.c +6 -0
index f77feadde8d2..04319ffae288 100644
@@ -12,6 +12,8 @@
 #include <net/pkt_sched.h>
 #include <linux/bpf_trace.h>
 #include <net/xdp_sock_drv.h>
+#include <linux/pci.h>
+
 #include <net/ipv6.h>
 
 #include "igc.h"
@@ -5792,6 +5794,10 @@ static int igc_probe(struct pci_dev *pdev,
 
 	pci_enable_pcie_error_reporting(pdev);
 
+	err = pci_enable_ptm(pdev, NULL);
+	if (err < 0)
+		dev_err(&pdev->dev, "PTM not supported\n");
+
 	pci_set_master(pdev);
 
 	err = -ENOMEM;
Signature · 1 line
2.31.0
#8 lore raw

Re: [PATCH next-queue v3 2/3] igc: Enable PCIe PTM

Quoted 4 lines · Vinicius Costa Gomes

In practice, enabling PTM also sets the enabled_ptm flag in the PCI device, the flag will be used for detecting if PTM is enabled before adding support for the SYSOFFSET_PRECISE ioctl() (which is added by implementing the getcrosststamp() PTP function).

I think you're referring to the "pci_dev.ptm_enabled" flag. I'm not sure what the connection to this patch is. The SYSOFFSET_PRECISE stuff also seems to belong with some other patch.

This patch merely enables PTM if it's supported (might be worth expanding Precision Time Measurement for context).

Quoted 32 lines
---
 drivers/net/ethernet/intel/igc/igc_main.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/intel/igc/igc_main.c +6 -0
index f77feadde8d2..04319ffae288 100644
@@ -12,6 +12,8 @@
 #include <net/pkt_sched.h>
 #include <linux/bpf_trace.h>
 #include <net/xdp_sock_drv.h>
+#include <linux/pci.h>
+
 #include <net/ipv6.h>
 
 #include "igc.h"
@@ -5792,6 +5794,10 @@ static int igc_probe(struct pci_dev *pdev,
 
 	pci_enable_pcie_error_reporting(pdev);
 
+	err = pci_enable_ptm(pdev, NULL);
+	if (err < 0)
+		dev_err(&pdev->dev, "PTM not supported\n");
+
 	pci_set_master(pdev);
 
 	err = -ENOMEM;
Signature · 1 line
2.31.0
#9 lore raw

Re: [PATCH next-queue v3 2/3] igc: Enable PCIe PTM

Quoted 9 lines · Bjorn Helgaas
Quoted 4 lines · Vinicius Costa Gomes

In practice, enabling PTM also sets the enabled_ptm flag in the PCI device, the flag will be used for detecting if PTM is enabled before adding support for the SYSOFFSET_PRECISE ioctl() (which is added by implementing the getcrosststamp() PTP function).

I think you're referring to the "pci_dev.ptm_enabled" flag. I'm not sure what the connection to this patch is. The SYSOFFSET_PRECISE stuff also seems to belong with some other patch.

Yeah, I will improve the commit message to make it clear that this patch is a preparation patch for the one that will add support for PTP_SYS_OFFSET_PRECISE/getcrosststamp() and what's the relation with PCIe PTM.

Quoted 3 lines

This patch merely enables PTM if it's supported (might be worth expanding Precision Time Measurement for context).

Yes. Will expand the definition in the commit message.

Cheers,

Signature · 1 line
Vinicius
#10 lore raw

PATCH v3 3/3 igc: Add support for PTP getcrosststamp()

In reply to Vinicius Costa Gomes

i225 has support for PCIe PTM, which allows us to implement support for the PTP_SYS_OFFSET_PRECISE ioctl(), implemented in the driver via the getcrosststamp() function.

The easiest way to expose the PTM registers would be to configure the PTM dialogs to run periodically, but the PTP_SYS_OFFSET_PRECISE ioctl() semantics are more aligned to using a kind of "one-shot" way of retrieving the PTM timestamps. But this causes a bit more code to be written: the trigger registers for the PTM dialogs are not cleared automatically.

i225 can be configured to send "fake" packets with the PTM information, adding support for handling these types of packets is left for the future.

PTM improves the accuracy of time synchronization, for example, using phc2sys. Before:

phc2sys[341.511]: CLOCK_REALTIME phc offset       289 s2 freq    +961 delay   2963
phc2sys[342.511]: CLOCK_REALTIME phc offset      -984 s2 freq    -225 delay   3517
phc2sys[343.511]: CLOCK_REALTIME phc offset       427 s2 freq    +891 delay   2312
phc2sys[344.511]: CLOCK_REALTIME phc offset       104 s2 freq    +696 delay   2575
phc2sys[345.511]: CLOCK_REALTIME phc offset       149 s2 freq    +772 delay   2388
phc2sys[346.511]: CLOCK_REALTIME phc offset        33 s2 freq    +701 delay   2359
phc2sys[347.511]: CLOCK_REALTIME phc offset      -216 s2 freq    +462 delay   2706
phc2sys[348.512]: CLOCK_REALTIME phc offset       140 s2 freq    +753 delay   2300
phc2sys[349.512]: CLOCK_REALTIME phc offset       -14 s2 freq    +641 delay   2385
phc2sys[350.512]: CLOCK_REALTIME phc offset      1048 s2 freq   +1699 delay   4303
phc2sys[351.512]: CLOCK_REALTIME phc offset     -1296 s2 freq    -331 delay   2846
phc2sys[352.512]: CLOCK_REALTIME phc offset      -912 s2 freq    -336 delay   4006
phc2sys[353.512]: CLOCK_REALTIME phc offset       880 s2 freq   +1183 delay   2338
phc2sys[354.512]: CLOCK_REALTIME phc offset       358 s2 freq    +925 delay   2348
phc2sys[355.512]: CLOCK_REALTIME phc offset      -211 s2 freq    +463 delay   2941
phc2sys[356.512]: CLOCK_REALTIME phc offset       234 s2 freq    +845 delay   2519
phc2sys[357.512]: CLOCK_REALTIME phc offset        45 s2 freq    +726 delay   2357
phc2sys[358.512]: CLOCK_REALTIME phc offset      -262 s2 freq    +433 delay   2821
phc2sys[359.512]: CLOCK_REALTIME phc offset      -424 s2 freq    +192 delay   3579
phc2sys[360.513]: CLOCK_REALTIME phc offset       134 s2 freq    +623 delay   3269
phc2sys[361.513]: CLOCK_REALTIME phc offset      -213 s2 freq    +316 delay   3999
phc2sys[362.513]: CLOCK_REALTIME phc offset      1023 s2 freq   +1488 delay   2614
phc2sys[363.513]: CLOCK_REALTIME phc offset        57 s2 freq    +829 delay   2332
phc2sys[364.513]: CLOCK_REALTIME phc offset      -126 s2 freq    +663 delay   2315
phc2sys[365.513]: CLOCK_REALTIME phc offset       -85 s2 freq    +666 delay   2449
phc2sys[366.513]: CLOCK_REALTIME phc offset      -193 s2 freq    +533 delay   2336
phc2sys[367.513]: CLOCK_REALTIME phc offset      -645 s2 freq     +23 delay   3870
phc2sys[368.513]: CLOCK_REALTIME phc offset       483 s2 freq    +957 delay   2342
phc2sys[369.513]: CLOCK_REALTIME phc offset      -166 s2 freq    +453 delay   3025
phc2sys[370.513]: CLOCK_REALTIME phc offset       327 s2 freq    +896 delay   2250

After:

phc2sys[617.838]: CLOCK_REALTIME phc offset       -25 s2 freq    +309 delay      0
phc2sys[618.838]: CLOCK_REALTIME phc offset       -43 s2 freq    +284 delay      0
phc2sys[619.838]: CLOCK_REALTIME phc offset       -12 s2 freq    +302 delay      0
phc2sys[620.838]: CLOCK_REALTIME phc offset        -2 s2 freq    +308 delay      0
phc2sys[621.838]: CLOCK_REALTIME phc offset        30 s2 freq    +340 delay      0
phc2sys[622.838]: CLOCK_REALTIME phc offset        14 s2 freq    +333 delay      0
phc2sys[623.839]: CLOCK_REALTIME phc offset        -3 s2 freq    +320 delay      0
phc2sys[624.839]: CLOCK_REALTIME phc offset         9 s2 freq    +331 delay      0
phc2sys[625.839]: CLOCK_REALTIME phc offset        -1 s2 freq    +324 delay      0
phc2sys[626.839]: CLOCK_REALTIME phc offset        -6 s2 freq    +318 delay      0
phc2sys[627.839]: CLOCK_REALTIME phc offset       -10 s2 freq    +313 delay      0
phc2sys[628.839]: CLOCK_REALTIME phc offset         7 s2 freq    +327 delay      0
phc2sys[629.839]: CLOCK_REALTIME phc offset         8 s2 freq    +330 delay      0
phc2sys[630.840]: CLOCK_REALTIME phc offset       -24 s2 freq    +300 delay      0
phc2sys[631.840]: CLOCK_REALTIME phc offset       -49 s2 freq    +268 delay      0
phc2sys[632.840]: CLOCK_REALTIME phc offset         6 s2 freq    +308 delay      0
phc2sys[633.840]: CLOCK_REALTIME phc offset        25 s2 freq    +329 delay      0
phc2sys[634.840]: CLOCK_REALTIME phc offset         5 s2 freq    +316 delay      0
phc2sys[635.840]: CLOCK_REALTIME phc offset        10 s2 freq    +323 delay      0
phc2sys[636.840]: CLOCK_REALTIME phc offset       -13 s2 freq    +303 delay      0
phc2sys[637.841]: CLOCK_REALTIME phc offset         4 s2 freq    +316 delay      0
phc2sys[638.841]: CLOCK_REALTIME phc offset        16 s2 freq    +329 delay      0
phc2sys[639.841]: CLOCK_REALTIME phc offset        31 s2 freq    +349 delay      0
phc2sys[640.841]: CLOCK_REALTIME phc offset       -21 s2 freq    +306 delay      0
phc2sys[641.841]: CLOCK_REALTIME phc offset       -14 s2 freq    +307 delay      0
phc2sys[642.841]: CLOCK_REALTIME phc offset       -24 s2 freq    +293 delay      0
phc2sys[643.841]: CLOCK_REALTIME phc offset        -6 s2 freq    +304 delay      0
phc2sys[644.842]: CLOCK_REALTIME phc offset        12 s2 freq    +320 delay      0
phc2sys[645.842]: CLOCK_REALTIME phc offset        12 s2 freq    +323 delay      0
phc2sys[646.842]: CLOCK_REALTIME phc offset       -12 s2 freq    +303 delay      0

One possible explanation is that when PTM is not enabled, and there's a lot of traffic in the PCIe fabric, some register reads will take more time than the others (see the variation the delay values).

---
 drivers/net/ethernet/intel/igc/igc.h         |   1 +
 drivers/net/ethernet/intel/igc/igc_defines.h |  31 ++++
 drivers/net/ethernet/intel/igc/igc_ptp.c     | 173 +++++++++++++++++++
 drivers/net/ethernet/intel/igc/igc_regs.h    |  23 +++
 4 files changed, 228 insertions(+)
drivers/net/ethernet/intel/igc/igc.h +1 -0
index b6d3277c6f52..1aa1562e5f48 100644
@@ -225,6 +225,7 @@ struct igc_adapter {
 	struct timecounter tc;
 	struct timespec64 prev_ptp_time; /* Pre-reset PTP clock */
 	ktime_t ptp_reset_start; /* Reset time in clock mono */
+	struct system_time_snapshot snapshot;
 
 	char fw_version[32];
 
drivers/net/ethernet/intel/igc/igc_defines.h +31 -0
index a344ba41ff3f..c426ed3542af 100644
@@ -478,6 +478,37 @@
 #define IGC_RXCSUM_CRCOFL	0x00000800   /* CRC32 offload enable */
 #define IGC_RXCSUM_PCSD		0x00002000   /* packet checksum disabled */
 
+/* PCIe PTM Control */
+#define IGC_PTM_CTRL_START_NOW	BIT(29) /* Start PTM Now */
+#define IGC_PTM_CTRL_EN		BIT(30) /* Enable PTM */
+#define IGC_PTM_CTRL_TRIG	BIT(31) /* PTM Cycle trigger */
+#define IGC_PTM_CTRL_SHRT_CYC(usec)	(((usec) & 0x1f) << 2)
+#define IGC_PTM_CTRL_PTM_TO(usec)	(((usec) & 0xff) << 8)
+
+#define IGC_PTM_SHORT_CYC_DEFAULT	10  /* Default Short/interrupted cycle interval */
+#define IGC_PTM_CYC_TIME_DEFAULT	5   /* Default PTM cycle time */
+#define IGC_PTM_TIMEOUT_DEFAULT		255 /* Default timeout for PTM errors */
+
+/* PCIe Digital Delay */
+#define IGC_PCIE_DIG_DELAY_DEFAULT	0x01440000
+
+/* PCIe PHY Delay */
+#define IGC_PCIE_PHY_DELAY_DEFAULT	0x40900000
+
+#define IGC_TIMADJ_ADJUST_METH		0x40000000
+
+/* PCIe PTM Status */
+#define IGC_PTM_STAT_VALID		BIT(0) /* PTM Status */
+#define IGC_PTM_STAT_RET_ERR		BIT(1) /* Root port timeout */
+#define IGC_PTM_STAT_BAD_PTM_RES	BIT(2) /* PTM Response msg instead of PTM Response Data */
+#define IGC_PTM_STAT_T4M1_OVFL		BIT(3) /* T4 minus T1 overflow */
+#define IGC_PTM_STAT_ADJUST_1ST		BIT(4) /* 1588 timer adjusted during 1st PTM cycle */
+#define IGC_PTM_STAT_ADJUST_CYC		BIT(5) /* 1588 timer adjusted during non-1st PTM cycle */
+
+/* PCIe PTM Cycle Control */
+#define IGC_PTM_CYCLE_CTRL_CYC_TIME(msec)	((msec) & 0x3ff) /* PTM Cycle Time (msec) */
+#define IGC_PTM_CYCLE_CTRL_AUTO_CYC_EN		BIT(31) /* PTM Cycle Control */
+
 /* GPY211 - I225 defines */
 #define GPY_MMD_MASK		0xFFFF0000
 #define GPY_MMD_SHIFT		16
drivers/net/ethernet/intel/igc/igc_ptp.c +173 -0

216 lines not on this page · raw message

drivers/net/ethernet/intel/igc/igc_regs.h +23 -0
index dd7f7d5e8325..75f288aa1c2e 100644
@@ -229,6 +229,29 @@
 #define IGC_TXSTMPL	0x0B618  /* Tx timestamp value Low - RO */
 #define IGC_TXSTMPH	0x0B61C  /* Tx timestamp value High - RO */
 
+#define IGC_TIMADJ	0x0B60C  /* Time Adjustment Offset Register */
+
+/* PCIe Registers */
+#define IGC_PTM_CTRL		0x12540  /* PTM Control */
+#define IGC_PTM_STAT		0x12544  /* PTM Status */
+#define IGC_PTM_CYCLE_CTRL	0x1254C  /* PTM Cycle Control */
+
+/* PTM Time registers */
+#define IGC_PTM_T1_TIM0_L	0x12558  /* T1 on Timer 0 Low */
+#define IGC_PTM_T1_TIM0_H	0x1255C  /* T1 on Timer 0 High */
+
+#define IGC_PTM_CURR_T2_L	0x1258C  /* Current T2 Low */
+#define IGC_PTM_CURR_T2_H	0x12590  /* Current T2 High */
+#define IGC_PTM_PREV_T2_L	0x12584  /* Previous T2 Low */
+#define IGC_PTM_PREV_T2_H	0x12588  /* Previous T2 High */
+#define IGC_PTM_PREV_T4M1	0x12578  /* T4 Minus T1 on previous PTM Cycle */
+#define IGC_PTM_CURR_T4M1	0x1257C  /* T4 Minus T1 on this PTM Cycle */
+#define IGC_PTM_PREV_T3M2	0x12580  /* T3 Minus T2 on previous PTM Cycle */
+#define IGC_PTM_TDELAY		0x12594  /* PTM PCIe Link Delay */
+
+#define IGC_PCIE_DIG_DELAY	0x12550  /* PCIe Digital Delay */
+#define IGC_PCIE_PHY_DELAY	0x12554  /* PCIe PHY Delay */
+
 /* Management registers */
 #define IGC_MANC	0x05820  /* Management Control - RW */
 
Signature · 1 line
2.31.0
#11 lore raw

Re: [PATCH next-queue v3 3/3] igc: Add support for PTP getcrosststamp()

drivers/net/ethernet/intel/igc/igc_ptp.c int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr) · line 764

Quoted 9 lines · Vinicius Costa Gomes

i225 has support for PCIe PTM, which allows us to implement support for the PTP_SYS_OFFSET_PRECISE ioctl(), implemented in the driver via the getcrosststamp() function.

drivers/net/ethernet/intel/igc/igc_ptp.c +5 -0
+static bool igc_is_ptm_supported(struct igc_adapter *adapter)
+{
+#if IS_ENABLED(CONFIG_X86_TSC) && IS_ENABLED(CONFIG_PCIE_PTM)
+	return adapter->pdev->ptm_enabled;
+#endif

It's not obvious why you make this x86-specific. Maybe a comment?

You shouldn't have to test for CONFIG_PCIE_PTM, either. We probably should have a pdev->ptm_enabled() predicate with a stub that returns false when CONFIG_PCIE_PTM is not set.

Quoted 13 lines
drivers/net/ethernet/intel/igc/igc_regs.h +12 -0
+	return false;
+}
 
+/* PCIe Registers */
+#define IGC_PTM_CTRL		0x12540  /* PTM Control */
+#define IGC_PTM_STAT		0x12544  /* PTM Status */
+#define IGC_PTM_CYCLE_CTRL	0x1254C  /* PTM Cycle Control */
+
+/* PTM Time registers */
+#define IGC_PTM_T1_TIM0_L	0x12558  /* T1 on Timer 0 Low */
+#define IGC_PTM_T1_TIM0_H	0x1255C  /* T1 on Timer 0 High */
+
+#define IGC_PTM_CURR_T2_L	0x1258C  /* Current T2 Low */

drivers/net/ethernet/intel/igc/igc_regs.h line 253

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_regs.h +10 -0
+#define IGC_PTM_CURR_T2_H	0x12590  /* Current T2 High */
+#define IGC_PTM_PREV_T2_L	0x12584  /* Previous T2 Low */
+#define IGC_PTM_PREV_T2_H	0x12588  /* Previous T2 High */
+#define IGC_PTM_PREV_T4M1	0x12578  /* T4 Minus T1 on previous PTM Cycle */
+#define IGC_PTM_CURR_T4M1	0x1257C  /* T4 Minus T1 on this PTM Cycle */
+#define IGC_PTM_PREV_T3M2	0x12580  /* T3 Minus T2 on previous PTM Cycle */
+#define IGC_PTM_TDELAY		0x12594  /* PTM PCIe Link Delay */
+
+#define IGC_PCIE_DIG_DELAY	0x12550  /* PCIe Digital Delay */
+#define IGC_PCIE_PHY_DELAY	0x12554  /* PCIe PHY Delay */

I assume the above are device-specific registers, right? Nothing that would be found in the PCIe base spec?

Bjorn

#12 lore raw

Re: [PATCH next-queue v3 3/3] igc: Add support for PTP getcrosststamp()

Quoted 5 lines · Bjorn Helgaas
Quoted 3 lines · Vinicius Costa Gomes

i225 has support for PCIe PTM, which allows us to implement support for the PTP_SYS_OFFSET_PRECISE ioctl(), implemented in the driver via the getcrosststamp() function.

Quoted 7 lines

drivers/net/ethernet/intel/igc/igc_ptp.c int igc_ptp_get_ts_config(struct net_device *netdev, struct ifreq *ifr) · line 764

Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_ptp.c +5 -0
+static bool igc_is_ptm_supported(struct igc_adapter *adapter)
+{
+#if IS_ENABLED(CONFIG_X86_TSC) && IS_ENABLED(CONFIG_PCIE_PTM)
+	return adapter->pdev->ptm_enabled;
+#endif

It's not obvious why you make this x86-specific. Maybe a comment?

Sure. Will add a comment.

Quoted 4 lines

You shouldn't have to test for CONFIG_PCIE_PTM, either. We probably should have a pdev->ptm_enabled() predicate with a stub that returns false when CONFIG_PCIE_PTM is not set.

Makes sense. Will add that predicate for next version.

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/intel/igc/igc_regs.h +17 -0
+	return false;
+}
 
+/* PCIe Registers */
+#define IGC_PTM_CTRL		0x12540  /* PTM Control */
+#define IGC_PTM_STAT		0x12544  /* PTM Status */
+#define IGC_PTM_CYCLE_CTRL	0x1254C  /* PTM Cycle Control */
+
+/* PTM Time registers */
+#define IGC_PTM_T1_TIM0_L	0x12558  /* T1 on Timer 0 Low */
+#define IGC_PTM_T1_TIM0_H	0x1255C  /* T1 on Timer 0 High */
+
+#define IGC_PTM_CURR_T2_L	0x1258C  /* Current T2 Low */
+#define IGC_PTM_CURR_T2_H	0x12590  /* Current T2 High */
+#define IGC_PTM_PREV_T2_L	0x12584  /* Previous T2 Low */
+#define IGC_PTM_PREV_T2_H	0x12588  /* Previous T2 High */
+#define IGC_PTM_PREV_T4M1	0x12578  /* T4 Minus T1 on previous PTM Cycle */
+#define IGC_PTM_CURR_T4M1	0x1257C  /* T4 Minus T1 on this PTM Cycle */
Quoted 8 lines

drivers/net/ethernet/intel/igc/igc_regs.h line 253

Quoted 5 lines
drivers/net/ethernet/intel/igc/igc_regs.h +5 -0
+#define IGC_PTM_PREV_T3M2	0x12580  /* T3 Minus T2 on previous PTM Cycle */
+#define IGC_PTM_TDELAY		0x12594  /* PTM PCIe Link Delay */
+
+#define IGC_PCIE_DIG_DELAY	0x12550  /* PCIe Digital Delay */
+#define IGC_PCIE_PHY_DELAY	0x12554  /* PCIe PHY Delay */

I assume the above are device-specific registers, right? Nothing that would be found in the PCIe base spec?

Yeah, these registers control the corrections the NIC hardware make to the timestamps based on the PCIe link delays from the NIC to its upstream PCIe port.

I don't remember seeing anything like that on the PCIe base spec. Will take another look to make sure.

Cheers,

Signature · 1 line
Vinicius