Skip to contentSkip to conversation

amd-xgbe: add hardware PTP timestamping

PATCH Applied Raju Rangoju 2 participants 4 messages Jul 18, 2025 – Jul 21, 2025

Subsystems (3)
lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

v3 cover amd-xgbe: add hardware PTP timestamping

Remove the hwptp abstraction and associated callbacks from the struct xgbe_hw_if {} and move them to separate file after cleanup.

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

---
Changes since v2:
- add a new patch to clean up the existing abstraction and move to seperate file
- clean up the support patch as per review comments

---

Raju Rangoju (2):
and-xgbe: remove the abstraction for hwptp
amd-xgbe: add hardware PTP timestamping support

 drivers/net/ethernet/amd/xgbe/Makefile        |   2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-common.h   |  10 +
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c      | 126 ------
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c      | 204 +--------
 drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c | 401 ++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe-pci.c      |   2 +
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c      |  75 ++--
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  47 +-
 8 files changed, 487 insertions(+), 380 deletions(-)
 create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v3 1/2 and-xgbe: remove the abstraction for hwptp

Remove the hwptp abstraction and associated callbacks from the struct xgbe_hw_if {}.

The callback structure was only ever assigned a single function, without null checks. This cleanup inlines the logic and moves all the hwtstamp realted code a separate file, improving readability and maintainance.

---
 drivers/net/ethernet/amd/xgbe/Makefile        |   2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c      | 126 -------
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c      | 195 +----------
 drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c | 319 ++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c      |   4 +-
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  30 +-
 6 files changed, 345 insertions(+), 331 deletions(-)
 create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c
drivers/net/ethernet/amd/xgbe/Makefile +1 -1
index 620785ffbd51..5b0ab6240cf2 100644
@@ -3,7 +3,7 @@ obj-$(CONFIG_AMD_XGBE) += amd-xgbe.o
 
 amd-xgbe-objs := xgbe-main.o xgbe-drv.o xgbe-dev.o \
 		 xgbe-desc.o xgbe-ethtool.o xgbe-mdio.o \
-		 xgbe-ptp.o \
+		 xgbe-hwtstamp.o xgbe-ptp.o \
 		 xgbe-i2c.o xgbe-phy-v1.o xgbe-phy-v2.o \
 		 xgbe-platform.o
 
drivers/net/ethernet/amd/xgbe/xgbe-dev.c +0 -126

138 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-drv.c +1 -194

207 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c new file +319 -0

319 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +2 -2
index 978c4dd01fa0..3b8b4de8f91f 100644
@@ -20,7 +20,7 @@ static u64 xgbe_cc_read(const struct cyclecounter *cc)
 						   tstamp_cc);
 	u64 nsec;
 
-	nsec = pdata->hw_if.get_tstamp_time(pdata);
+	nsec = xgbe_get_tstamp_time(pdata);
 
 	return nsec;
 }
@@ -37,7 +37,7 @@ static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
 
 	spin_lock_irqsave(&pdata->tstamp_lock, flags);
 
-	pdata->hw_if.update_tstamp_addend(pdata, addend);
+	xgbe_update_tstamp_addend(pdata, addend);
 
 	spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
 
drivers/net/ethernet/amd/xgbe/xgbe.h +22 -8
index 70169ea23c7f..2341c7d213a7 100644
@@ -741,14 +741,6 @@ struct xgbe_hw_if {
 	void (*tx_mmc_int)(struct xgbe_prv_data *);
 	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,
-				unsigned int nsec);
-	u64 (*get_tstamp_time)(struct xgbe_prv_data *);
-	u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
-
 	/* For Data Center Bridging config */
 	void (*config_tc)(struct xgbe_prv_data *);
 	void (*config_dcb_tc)(struct xgbe_prv_data *);
@@ -1277,6 +1269,28 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
 void xgbe_restart_dev(struct xgbe_prv_data *pdata);
 void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
 
+/* For Timestamp config */
+int xgbe_config_tstamp(struct xgbe_prv_data *pdata, unsigned int mac_tscr);
+u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata);
+u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata);
+void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
+			struct xgbe_ring_desc *rdesc);
+void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
+			struct xgbe_ring_desc *rdesc);
+void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
+			       unsigned int addend);
+void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
+			  unsigned int nsec);
+int xgbe_config_tstamp(struct xgbe_prv_data *pdata, unsigned int mac_tscr);
+void xgbe_tx_tstamp(struct work_struct *work);
+int xgbe_get_hwtstamp_settings(struct xgbe_prv_data *pdata,
+			       struct ifreq *ifreq);
+int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
+			       struct ifreq *ifreq);
+void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata,
+			 struct sk_buff *skb,
+			 struct xgbe_packet_data *packet);
+
 #ifdef CONFIG_DEBUG_FS
 void xgbe_debugfs_init(struct xgbe_prv_data *);
 void xgbe_debugfs_exit(struct xgbe_prv_data *);
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH v3 2/2 amd-xgbe: add hardware PTP timestamping support

In reply to 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.

---
 drivers/net/ethernet/amd/xgbe/xgbe-common.h   |  10 ++
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c      |   9 +-
 drivers/net/ethernet/amd/xgbe/xgbe-hwtstamp.c | 148 ++++++++++++++----
 drivers/net/ethernet/amd/xgbe/xgbe-pci.c      |   2 +
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c      |  73 ++++-----
 drivers/net/ethernet/amd/xgbe/xgbe.h          |  23 ++-
 6 files changed, 179 insertions(+), 86 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-drv.c +4 -5
index 20d688a1962c..2e9b95a94f89 100644
@@ -1583,6 +1583,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. */
+	xgbe_init_ptp(pdata);
+
 	ret = xgbe_alloc_memory(pdata);
 	if (ret)
 		goto err_ptpclk;
@@ -2353,12 +2356,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-hwtstamp.c +115 -33

184 lines not on this page · raw message

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 +30 -43

125 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe.h +18 -5
index 2341c7d213a7..d7e03e292ec4 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
@@ -938,6 +951,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;
@@ -1123,8 +1137,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;
@@ -1270,7 +1282,7 @@ void xgbe_restart_dev(struct xgbe_prv_data *pdata);
 void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
 
 /* For Timestamp config */
-int xgbe_config_tstamp(struct xgbe_prv_data *pdata, unsigned int mac_tscr);
+void xgbe_config_tstamp(struct xgbe_prv_data *pdata, unsigned int mac_tscr);
 u64 xgbe_get_tstamp_time(struct xgbe_prv_data *pdata);
 u64 xgbe_get_tx_tstamp(struct xgbe_prv_data *pdata);
 void xgbe_get_rx_tstamp(struct xgbe_packet_data *packet,
@@ -1281,7 +1293,6 @@ void xgbe_update_tstamp_addend(struct xgbe_prv_data *pdata,
 			       unsigned int addend);
 void xgbe_set_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
 			  unsigned int nsec);
-int xgbe_config_tstamp(struct xgbe_prv_data *pdata, unsigned int mac_tscr);
 void xgbe_tx_tstamp(struct work_struct *work);
 int xgbe_get_hwtstamp_settings(struct xgbe_prv_data *pdata,
 			       struct ifreq *ifreq);
@@ -1290,7 +1301,9 @@ int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
 void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata,
 			 struct sk_buff *skb,
 			 struct xgbe_packet_data *packet);
-
+int xgbe_init_ptp(struct xgbe_prv_data *pdata);
+void xgbe_update_tstamp_time(struct xgbe_prv_data *pdata, unsigned int sec,
+			     unsigned int nsec);
 #ifdef CONFIG_DEBUG_FS
 void xgbe_debugfs_init(struct xgbe_prv_data *);
 void xgbe_debugfs_exit(struct xgbe_prv_data *);
Signature · 1 line
2.34.1
#3 lore raw
In reply to Raju Rangoju
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Sat, 19 Jul 2025 00:26:26 +0530 you wrote:

Remove the hwptp abstraction and associated callbacks from the struct xgbe_hw_if {} and move them to separate file after cleanup.

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

[...]

Here is the summary with links:
- [net-next,v3,1/2] and-xgbe: remove the abstraction for hwptp

    https://git.kernel.org/netdev/net-next/c/7564d3247aec
  - [net-next,v3,2/2] amd-xgbe: add hardware PTP timestamping support
    https://git.kernel.org/netdev/net-next/c/fbd47be098b5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html