Skip to contentSkip to conversation

amd-xgbe: Add PPS periodic output support

PATCH Superseded Raju Rangoju 2 participants 3 messages Aug 22, 2025 – Aug 28, 2025

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Raju Rangoju

author maintainer
#0 lore raw

PATCH v2 1/1 amd-xgbe: Add PPS periodic output support

Add support for hardware PPS (Pulse Per Second) output to the AMD XGBE driver. The implementation enables flexible periodic output mode, exposing it via the PTP per_out interface.

The driver supports configuring PPS output using the standard PTP subsystem, allowing precise periodic signal generation for time synchronization applications.

The feature has been verified using the testptp tool and oscilloscope.

---
Changes since v1:
- add sanity check to prevent pps_out_num and aux_snap_num exceeding the limit

 drivers/net/ethernet/amd/xgbe/Makefile      |  2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-common.h | 60 +++++++++++++++++++--
 drivers/net/ethernet/amd/xgbe/xgbe-drv.c    | 15 ++++++
 drivers/net/ethernet/amd/xgbe/xgbe-pps.c    | 58 ++++++++++++++++++++
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c    | 34 +++++++++++-
 drivers/net/ethernet/amd/xgbe/xgbe.h        | 16 ++++++
 6 files changed, 180 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/amd/xgbe/xgbe-pps.c
drivers/net/ethernet/amd/xgbe/Makefile +1 -1
index 5b0ab6240cf2..d546a212806a 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-hwtstamp.o xgbe-ptp.o \
+		 xgbe-hwtstamp.o xgbe-ptp.o xgbe-pps.o\
 		 xgbe-i2c.o xgbe-phy-v1.o xgbe-phy-v2.o \
 		 xgbe-platform.o
 
drivers/net/ethernet/amd/xgbe/xgbe-common.h +57 -3

90 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-drv.c +15 -0
index 2e9b95a94f89..f0989aa01855 100644
@@ -691,6 +691,21 @@ void xgbe_get_all_hw_features(struct xgbe_prv_data *pdata)
 	hw_feat->pps_out_num  = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, PPSOUTNUM);
 	hw_feat->aux_snap_num = XGMAC_GET_BITS(mac_hfr2, MAC_HWF2R, AUXSNAPNUM);
 
+	/* Sanity check and warn if hardware reports more than supported */
+	if (hw_feat->pps_out_num > XGBE_MAX_PPS_OUT) {
+		dev_warn(pdata->dev,
+			 "Hardware reports %u PPS outputs, limiting to %u\n",
+			 hw_feat->pps_out_num, XGBE_MAX_PPS_OUT);
+		hw_feat->pps_out_num = XGBE_MAX_PPS_OUT;
+	}
+
+	if (hw_feat->aux_snap_num > XGBE_MAX_AUX_SNAP) {
+		dev_warn(pdata->dev,
+			 "Hardware reports %u aux snapshot inputs, limiting to %u\n",
+			 hw_feat->aux_snap_num, XGBE_MAX_AUX_SNAP);
+		hw_feat->aux_snap_num = XGBE_MAX_AUX_SNAP;
+	}
+
 	/* Translate the Hash Table size into actual number */
 	switch (hw_feat->hash_table_size) {
 	case 0:
drivers/net/ethernet/amd/xgbe/xgbe-pps.c new file +58 -0

58 lines not on this page · raw message

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +33 -1
index 3658afc7801d..b28f6a1d0e67 100644
@@ -106,7 +106,37 @@ static int xgbe_settime(struct ptp_clock_info *info,
 static int xgbe_enable(struct ptp_clock_info *info,
 		       struct ptp_clock_request *request, int on)
 {
-	return -EOPNOTSUPP;
+	struct xgbe_prv_data *pdata = container_of(info, struct xgbe_prv_data,
+						   ptp_clock_info);
+	struct xgbe_pps_config *pps_cfg;
+	unsigned long flags;
+	int ret;
+
+	dev_dbg(pdata->dev, "rq->type %d on %d\n", request->type, on);
+
+	if (request->type != PTP_CLK_REQ_PEROUT)
+		return -EOPNOTSUPP;
+
+	/* Reject requests with unsupported flags */
+	if (request->perout.flags)
+		return -EOPNOTSUPP;
+
+	/* Validate index against our limit */
+	if (request->perout.index >= XGBE_MAX_PPS_OUT)
+		return -EINVAL;
+
+	pps_cfg = &pdata->pps[request->perout.index];
+
+	pps_cfg->start.tv_sec = request->perout.start.sec;
+	pps_cfg->start.tv_nsec = request->perout.start.nsec;
+	pps_cfg->period.tv_sec = request->perout.period.sec;
+	pps_cfg->period.tv_nsec = request->perout.period.nsec;
+
+	spin_lock_irqsave(&pdata->tstamp_lock, flags);
+	ret = xgbe_pps_config(pdata, pps_cfg, request->perout.index, on);
+	spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
+
+	return ret;
 }
 
 void xgbe_ptp_register(struct xgbe_prv_data *pdata)
@@ -122,6 +152,8 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 	info->adjtime = xgbe_adjtime;
 	info->gettimex64 = xgbe_gettimex;
 	info->settime64 = xgbe_settime;
+	info->n_per_out = pdata->hw_feat.pps_out_num;
+	info->n_ext_ts = pdata->hw_feat.aux_snap_num;
 	info->enable = xgbe_enable;
 
 	clock = ptp_clock_register(info, pdata->dev);
drivers/net/ethernet/amd/xgbe/xgbe.h +16 -0
index d7e03e292ec4..e3f89fbe1154 100644
@@ -142,6 +142,10 @@
 #define XGBE_V2_TSTAMP_SNSINC	0
 #define XGBE_V2_PTP_ACT_CLK_FREQ	1000000000
 
+/* Define maximum supported values */
+#define XGBE_MAX_PPS_OUT	4
+#define XGBE_MAX_AUX_SNAP	4
+
 /* Driver PMT macros */
 #define XGMAC_DRIVER_CONTEXT	1
 #define XGMAC_IOCTL_CONTEXT	2
@@ -672,6 +676,11 @@ struct xgbe_ext_stats {
 	u64 rx_vxlan_csum_errors;
 };
 
+struct xgbe_pps_config {
+	struct timespec64 start;
+	struct timespec64 period;
+};
+
 struct xgbe_hw_if {
 	int (*tx_complete)(struct xgbe_ring_desc *);
 
@@ -1142,6 +1151,9 @@ struct xgbe_prv_data {
 	struct sk_buff *tx_tstamp_skb;
 	u64 tx_tstamp;
 
+	/* Pulse Per Second output */
+	struct xgbe_pps_config pps[XGBE_MAX_PPS_OUT];
+
 	/* DCB support */
 	struct ieee_ets *ets;
 	struct ieee_pfc *pfc;
@@ -1304,6 +1316,10 @@ void xgbe_prep_tx_tstamp(struct xgbe_prv_data *pdata,
 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);
+
+int xgbe_pps_config(struct xgbe_prv_data *pdata, struct xgbe_pps_config *cfg,
+		    int index, int on);
+
 #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
maintainer
#1 lore raw
Quoted 4 lines · On Fri, 22 Aug 2025 16:08:31 +0530 Raju Rangoju wrote:
drivers/net/ethernet/amd/xgbe/xgbe-common.h +4 -0
+#define PPSx_MASK(x) ({						\
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MAXIDX(__x), PPS_MINIDX(__x));		\
+})

drivers/net/ethernet/amd/xgbe/xgbe-common.h line 266

Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-common.h +10 -0
+#define PPSCMDx(x, val) ({					\
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MINIDX(__x) + 3, PPS_MINIDX(__x)) &		\
+	((val) << PPS_MINIDX(__x));				\
+})
+#define TRGTMODSELx(x, val) ({					\
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MAXIDX(__x) - 1, PPS_MAXIDX(__x) - 2) &	\
+	((val) << (PPS_MAXIDX(__x) - 2));			\
+})

These macros are way too gnarly, please simplify them.
For a start I'm not sure why you're making your life harder and try to have a shifted mask. Instead of masking the value before shifting.

Quoted 8 lines

static int xgbe_enable(struct ptp_clock_info *info,

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +4 -1
 		       struct ptp_clock_request *request, int on)
 {
-	return -EOPNOTSUPP;
+	struct xgbe_prv_data *pdata = container_of(info, struct xgbe_prv_data,
+						   ptp_clock_info);
+	struct xgbe_pps_config *pps_cfg;
+	unsigned long flags;

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c static int xgbe_settime(struct ptp_clock_info *info, · line 122

Quoted 10 lines
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +10 -0
+	int ret;
+
+	dev_dbg(pdata->dev, "rq->type %d on %d\n", request->type, on);
+
+	if (request->type != PTP_CLK_REQ_PEROUT)
+		return -EOPNOTSUPP;
+
+	/* Reject requests with unsupported flags */
+	if (request->perout.flags)
+		return -EOPNOTSUPP;

Are you sure kernel can actually send you any flags here? ops->supported_perout_flags exists

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c static int xgbe_settime(struct ptp_clock_info *info, · line 126

Quoted 3 lines
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +3 -0
+	/* Validate index against our limit */
+	if (request->perout.index >= XGBE_MAX_PPS_OUT)
+		return -EINVAL;

Are you sure kernel can send you an index higher than what driver registered as supported?

Signature · 1 line
pw-bot: cr
author maintainer
#2 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 10 lines · On Fri, 22 Aug 2025 16:08:31 +0530 Raju Rangoju wrote:
drivers/net/ethernet/amd/xgbe/xgbe-common.h +10 -0
+#define PPSx_MASK(x) ({						\
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MAXIDX(__x), PPS_MINIDX(__x));		\
+})
+#define PPSCMDx(x, val) ({					\
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MINIDX(__x) + 3, PPS_MINIDX(__x)) &		\
+	((val) << PPS_MINIDX(__x));				\
+})
+#define TRGTMODSELx(x, val) ({					\
Quoted 8 lines

drivers/net/ethernet/amd/xgbe/xgbe-common.h line 266

Quoted 4 lines
drivers/net/ethernet/amd/xgbe/xgbe-common.h +4 -0
+	unsigned int __x = (x);					\
+	GENMASK(PPS_MAXIDX(__x) - 1, PPS_MAXIDX(__x) - 2) &	\
+	((val) << (PPS_MAXIDX(__x) - 2));			\
+})

These macros are way too gnarly, please simplify them.
For a start I'm not sure why you're making your life harder and try to have a shifted mask. Instead of masking the value before shifting.

Sure, will simplify them v3.

Quoted 14 lines
Quoted 14 lines

static int xgbe_enable(struct ptp_clock_info *info,
struct ptp_clock_request *request, int on)
{

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +9 -1
-	return -EOPNOTSUPP;
+	struct xgbe_prv_data *pdata = container_of(info, struct xgbe_prv_data,
+						   ptp_clock_info);
+	struct xgbe_pps_config *pps_cfg;
+	unsigned long flags;
+	int ret;
+
+	dev_dbg(pdata->dev, "rq->type %d on %d\n", request->type, on);
+
+	if (request->type != PTP_CLK_REQ_PEROUT)
Quoted 8 lines

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c static int xgbe_settime(struct ptp_clock_info *info, · line 122

Quoted 5 lines
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +5 -0
+		return -EOPNOTSUPP;
+
+	/* Reject requests with unsupported flags */
+	if (request->perout.flags)
+		return -EOPNOTSUPP;

Are you sure kernel can actually send you any flags here? ops->supported_perout_flags exists

Yes, it looks like ops->supported_perout_flags is already taking care of this. Thanks, I'll drop the above check.

Quoted 7 lines

drivers/net/ethernet/amd/xgbe/xgbe-ptp.c static int xgbe_settime(struct ptp_clock_info *info, · line 126

Quoted 4 lines
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c +3 -0
+	/* Validate index against our limit */
+	if (request->perout.index >= XGBE_MAX_PPS_OUT)
+		return -EINVAL;

Are you sure kernel can send you an index higher than what driver registered as supported?

looks like kernel is already handling it and this extra check isn't needed anymore. I'll drop it. Thanks Jakub.