Skip to contentSkip to conversation

amd-xgbe: add hardware PTP timestamping support

PATCH Superseded Raju Rangoju 3 participants 4 messages Jul 14, 2025 – Jul 18, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

PATCH v2 1/1 amd-xgbe: add hardware PTP timestamping support

Adds complete support for hardware-based PTP (IEEE 1588) timestamping to the AMD XGBE driver.

- Initialize and configure the MAC PTP registers based on link speed and reference clock.
- Support both 50MHz and 125MHz PTP reference clocks.
- Update the driver interface and version data to support PTP clock frequency selection.

---
Changes since v1:
- address the comments received for xgbe_init_ptp()
- ensure reverse x-mass tree ordering of variables
- use macros instead for hardcoded numbers

 drivers/net/ethernet/amd/xgbe/xgbe-common.h |  10 ++
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c    | 145 ++++++++++++++++----
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c    |  15 +-
 drivers/net/ethernet/amd/xgbe/xgbe-pci.c    |   2 +
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c    |  70 +++++-----
 drivers/net/ethernet/amd/xgbe/xgbe.h        |  28 +++-
 6 files changed, 187 insertions(+), 83 deletions(-)
drivers/net/ethernet/amd/xgbe/xgbe-common.h +10 -0
index e54e3e36d3f9..009fbc9b11ce 100644
@@ -223,6 +223,10 @@
 #define MAC_TSSR			0x0d20
 #define MAC_TXSNR			0x0d30
 #define MAC_TXSSR			0x0d34
+#define MAC_TICNR                       0x0d58
+#define MAC_TICSNR                      0x0d5C
+#define MAC_TECNR                       0x0d60
+#define MAC_TECSNR                      0x0d64
 
 #define MAC_QTFCR_INC			4
 #define MAC_MACA_INC			4
@@ -428,6 +432,8 @@
 #define MAC_TSCR_SNAPTYPSEL_WIDTH	2
 #define MAC_TSCR_TSADDREG_INDEX		5
 #define MAC_TSCR_TSADDREG_WIDTH		1
+#define MAC_TSCR_TSUPDT_INDEX		3
+#define MAC_TSCR_TSUPDT_WIDTH		1
 #define MAC_TSCR_TSCFUPDT_INDEX		1
 #define MAC_TSCR_TSCFUPDT_WIDTH		1
 #define MAC_TSCR_TSCTRLSSR_INDEX	9
@@ -456,6 +462,10 @@
 #define MAC_TSSR_TXTSC_WIDTH		1
 #define MAC_TXSNR_TXTSSTSMIS_INDEX	31
 #define MAC_TXSNR_TXTSSTSMIS_WIDTH	1
+#define MAC_TICSNR_TSICSNS_INDEX	8
+#define MAC_TICSNR_TSICSNS_WIDTH	8
+#define MAC_TECSNR_TSECSNS_INDEX	8
+#define MAC_TECSNR_TSECSNS_WIDTH	8
 #define MAC_VLANHTR_VLHT_INDEX		0
 #define MAC_VLANHTR_VLHT_WIDTH		16
 #define MAC_VLANIR_VLTI_INDEX		20
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +116 -29

184 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-drv.c +5 -10
index 65447f9a0a59..a6b9d0cda48c 100644
@@ -1377,7 +1377,6 @@ static void xgbe_tx_tstamp(struct work_struct *work)
 						   struct xgbe_prv_data,
 						   tx_tstamp_work);
 	struct skb_shared_hwtstamps hwtstamps;
-	u64 nsec;
 	unsigned long flags;
 
 	spin_lock_irqsave(&pdata->tstamp_lock, flags);
@@ -1385,11 +1384,8 @@ static void xgbe_tx_tstamp(struct work_struct *work)
 		goto unlock;
 
 	if (pdata->tx_tstamp) {
-		nsec = timecounter_cyc2time(&pdata->tstamp_tc,
-					    pdata->tx_tstamp);
-
 		memset(&hwtstamps, 0, sizeof(hwtstamps));
-		hwtstamps.hwtstamp = ns_to_ktime(nsec);
+		hwtstamps.hwtstamp = ns_to_ktime(pdata->tx_tstamp);
 		skb_tstamp_tx(pdata->tx_tstamp_skb, &hwtstamps);
 	}
 
@@ -1776,6 +1772,9 @@ static int xgbe_open(struct net_device *netdev)
 	INIT_WORK(&pdata->stopdev_work, xgbe_stopdev);
 	INIT_WORK(&pdata->tx_tstamp_work, xgbe_tx_tstamp);
 
+	/* Initialize PTP timestamping and clock. */
+	pdata->hw_if.init_ptp(pdata);
+
 	ret = xgbe_alloc_memory(pdata);
 	if (ret)
 		goto err_ptpclk;
@@ -2546,12 +2545,8 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
 
 		if (XGMAC_GET_BITS(packet->attributes,
 				   RX_PACKET_ATTRIBUTES, RX_TSTAMP)) {
-			u64 nsec;
-
-			nsec = timecounter_cyc2time(&pdata->tstamp_tc,
-						    packet->rx_tstamp);
 			hwtstamps = skb_hwtstamps(skb);
-			hwtstamps->hwtstamp = ns_to_ktime(nsec);
+			hwtstamps->hwtstamp = ns_to_ktime(packet->rx_tstamp);
 		}
 
 		if (XGMAC_GET_BITS(packet->attributes,
drivers/net/ethernet/amd/xgbe/xgbe-pci.c +2 -0
index 097ec5e4f261..e3e1dca9856a 100644
@@ -414,6 +414,7 @@ static struct xgbe_version_data xgbe_v2a = {
 	.tx_max_fifo_size		= 229376,
 	.rx_max_fifo_size		= 229376,
 	.tx_tstamp_workaround		= 1,
+	.tstamp_ptp_clock_freq		= 1,
 	.ecc_support			= 1,
 	.i2c_support			= 1,
 	.irq_reissue_support		= 1,
@@ -430,6 +431,7 @@ static struct xgbe_version_data xgbe_v2b = {
 	.tx_max_fifo_size		= 65536,
 	.rx_max_fifo_size		= 65536,
 	.tx_tstamp_workaround		= 1,
+	.tstamp_ptp_clock_freq		= 1,
 	.ecc_support			= 1,
 	.i2c_support			= 1,
 	.irq_reissue_support		= 1,
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +31 -39

123 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe.h +23 -5
index 70169ea23c7f..33606333c9e3 100644
@@ -119,6 +119,14 @@
 #define XGBE_MSI_BASE_COUNT	4
 #define XGBE_MSI_MIN_COUNT	(XGBE_MSI_BASE_COUNT + 1)
 
+/* Initial PTP register values based on Link Speed. */
+#define MAC_TICNR_1G_INITVAL	0x10
+#define MAC_TECNR_1G_INITVAL	0x28
+
+#define MAC_TICSNR_10G_INITVAL	0x33
+#define MAC_TECNR_10G_INITVAL	0x14
+#define MAC_TECSNR_10G_INITVAL	0xCC
+
 /* PCI clock frequencies */
 #define XGBE_V2_DMA_CLOCK_FREQ	500000000	/* 500 MHz */
 #define XGBE_V2_PTP_CLOCK_FREQ	125000000	/* 125 MHz */
@@ -128,6 +136,11 @@
  */
 #define XGBE_TSTAMP_SSINC	20
 #define XGBE_TSTAMP_SNSINC	0
+#define XGBE_PTP_ACT_CLK_FREQ	500000000
+
+#define XGBE_V2_TSTAMP_SSINC	0xA
+#define XGBE_V2_TSTAMP_SNSINC	0
+#define XGBE_V2_PTP_ACT_CLK_FREQ	1000000000
 
 /* Driver PMT macros */
 #define XGMAC_DRIVER_CONTEXT	1
@@ -742,10 +755,16 @@ struct xgbe_hw_if {
 	void (*read_mmc_stats)(struct xgbe_prv_data *);
 
 	/* For Timestamp config */
-	int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
-	void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
-	void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
+	void (*init_ptp)(struct xgbe_prv_data *pdata);
+	void (*config_tstamp)(struct xgbe_prv_data *pdata,
+			      unsigned int mac_tscr);
+	void (*update_tstamp_addend)(struct xgbe_prv_data *pdata,
+				     unsigned int addend);
+	void (*set_tstamp_time)(struct xgbe_prv_data *pdata, unsigned int sec,
 				unsigned int nsec);
+	void (*update_tstamp_time)(struct xgbe_prv_data *pdata,
+				   unsigned int sec,
+				   unsigned int nsec);
 	u64 (*get_tstamp_time)(struct xgbe_prv_data *);
 	u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
 
@@ -946,6 +965,7 @@ struct xgbe_version_data {
 	unsigned int tx_max_fifo_size;
 	unsigned int rx_max_fifo_size;
 	unsigned int tx_tstamp_workaround;
+	unsigned int tstamp_ptp_clock_freq;
 	unsigned int ecc_support;
 	unsigned int i2c_support;
 	unsigned int irq_reissue_support;
@@ -1131,8 +1151,6 @@ struct xgbe_prv_data {
 	struct ptp_clock_info ptp_clock_info;
 	struct ptp_clock *ptp_clock;
 	struct hwtstamp_config tstamp_config;
-	struct cyclecounter tstamp_cc;
-	struct timecounter tstamp_tc;
 	unsigned int tstamp_addend;
 	struct work_struct tx_tstamp_work;
 	struct sk_buff *tx_tstamp_skb;
Signature · 1 line
2.34.1
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Raju Rangoju

Adds complete support for hardware-based PTP (IEEE 1588) timestamping to the AMD XGBE driver.

- Initialize and configure the MAC PTP registers based on link speed and reference clock.
- Support both 50MHz and 125MHz PTP reference clocks.
- Update the driver interface and version data to support PTP clock frequency selection.

Thanks,
Shyam

maintainer
#2 lore raw
In reply to Raju Rangoju
Quoted 6 lines · On Mon, 14 Jul 2025 12:28:11 +0530 Raju Rangoju wrote:
drivers/net/ethernet/amd/xgbe/xgbe.h +2 -3
 	/* For Timestamp config */
-	int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
-	void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
-	void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
+	void (*init_ptp)(struct xgbe_prv_data *pdata);
+	void (*config_tstamp)(struct xgbe_prv_data *pdata,

drivers/net/ethernet/amd/xgbe/xgbe.h struct xgbe_hw_if { · line 769

Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe.h +7 -0
+			      unsigned int mac_tscr);
+	void (*update_tstamp_addend)(struct xgbe_prv_data *pdata,
+				     unsigned int addend);
+	void (*set_tstamp_time)(struct xgbe_prv_data *pdata, unsigned int sec,
 				unsigned int nsec);
+	void (*update_tstamp_time)(struct xgbe_prv_data *pdata,
+				   unsigned int sec,
+				   unsigned int nsec);
 	u64 (*get_tstamp_time)(struct xgbe_prv_data *);
 	u64 (*get_tx_tstamp)(struct xgbe_prv_data *);

Please start with removing this abstraction / callbacks instead of starting to used them. They each seem to have only one function assigned, and there isn't even a null check before calling. They make the code harder to follow and review.

The removal should be a separate patch for ease of review.

Signature · 1 line
pw-bot: cr
author maintainer
#3 lore raw
Quoted 23 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 14 Jul 2025 12:28:11 +0530 Raju Rangoju wrote:

/* For Timestamp config */

drivers/net/ethernet/amd/xgbe/xgbe.h +2 -3
-	int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
-	void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
-	void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
+	void (*init_ptp)(struct xgbe_prv_data *pdata);
+	void (*config_tstamp)(struct xgbe_prv_data *pdata,

drivers/net/ethernet/amd/xgbe/xgbe.h struct xgbe_hw_if { · line 769

Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe.h +7 -0
+			      unsigned int mac_tscr);
+	void (*update_tstamp_addend)(struct xgbe_prv_data *pdata,
+				     unsigned int addend);
+	void (*set_tstamp_time)(struct xgbe_prv_data *pdata, unsigned int sec,
  				unsigned int nsec);
+	void (*update_tstamp_time)(struct xgbe_prv_data *pdata,
+				   unsigned int sec,
+				   unsigned int nsec);
  	u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  	u64 (*get_tx_tstamp)(struct xgbe_prv_data *);

Please start with removing this abstraction / callbacks instead of starting to used them. They each seem to have only one function assigned, and there isn't even a null check before calling. They make the code harder to follow and review.

Quoted 1 line

The removal should be a separate patch for ease of review.

Sure, I'll send a separate patch for addressing the callbacks. In the meantime, I'll re-spin this patch with the changes.