Skip to contentSkip to conversation

octeontx2-pf: Enable PTP PPS output support

PATCH Applied Sai Krishna 3 participants 3 messages Sep 12, 2023 – Sep 15, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 octeontx2-pf: Enable PTP PPS output support

From: Hariprasad Kelam <[email protected]>

PTP block supports generating PPS output signal on GPIO pin. This patch adds the support in the PTP PHC driver using standard periodic output interface.

User can enable/disable/configure PPS by writing to the below sysfs entry

echo perout.index start.sec start.nsec period.sec period.nsec > /sys/class/ptp/ptp0/period

Example to generate 50% duty cycle PPS signal:
echo 0 0 0 0 500000000 > /sys/class/ptp/ptp0/period

---
 .../net/ethernet/marvell/octeontx2/af/mbox.h  |  5 +-
 .../net/ethernet/marvell/octeontx2/af/ptp.c   | 86 +++++++++++++------
 .../ethernet/marvell/octeontx2/nic/otx2_ptp.c | 31 +++++--
 3 files changed, 85 insertions(+), 37 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +3 -2
index 6b5b06c2b4e9..c5bd7747fc0e 100644
@@ -1574,7 +1574,7 @@ enum ptp_op {
 	PTP_OP_GET_CLOCK = 1,
 	PTP_OP_GET_TSTMP = 2,
 	PTP_OP_SET_THRESH = 3,
-	PTP_OP_EXTTS_ON = 4,
+	PTP_OP_PPS_ON = 4,
 	PTP_OP_ADJTIME = 5,
 	PTP_OP_SET_CLOCK = 6,
 };
@@ -1584,7 +1584,8 @@ struct ptp_req {
 	u8 op;
 	s64 scaled_ppm;
 	u64 thresh;
-	int extts_on;
+	u64 period;
+	int pps_on;
 	s64 delta;
 	u64 clk;
 };
drivers/net/ethernet/marvell/octeontx2/af/ptp.c +59 -27

122 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +23 -8
index 3a72b0793d4a..63130ba37e9d 100644
@@ -175,7 +175,7 @@ static int ptp_set_thresh(struct otx2_ptp *ptp, u64 thresh)
 	return otx2_sync_mbox_msg(&ptp->nic->mbox);
 }
 
-static int ptp_extts_on(struct otx2_ptp *ptp, int on)
+static int ptp_pps_on(struct otx2_ptp *ptp, int on, u64 period)
 {
 	struct ptp_req *req;
 
@@ -186,8 +186,9 @@ static int ptp_extts_on(struct otx2_ptp *ptp, int on)
 	if (!req)
 		return -ENOMEM;
 
-	req->op = PTP_OP_EXTTS_ON;
-	req->extts_on = on;
+	req->op = PTP_OP_PPS_ON;
+	req->pps_on = on;
+	req->period = period;
 
 	return otx2_sync_mbox_msg(&ptp->nic->mbox);
 }
@@ -276,8 +277,8 @@ static int otx2_ptp_verify_pin(struct ptp_clock_info *ptp, unsigned int pin,
 	switch (func) {
 	case PTP_PF_NONE:
 	case PTP_PF_EXTTS:
-		break;
 	case PTP_PF_PEROUT:
+		break;
 	case PTP_PF_PHYSYNC:
 		return -1;
 	}
@@ -340,6 +341,7 @@ static int otx2_ptp_enable(struct ptp_clock_info *ptp_info,
 {
 	struct otx2_ptp *ptp = container_of(ptp_info, struct otx2_ptp,
 					    ptp_info);
+	u64 period = 0;
 	int pin;
 
 	if (!ptp->nic)
@@ -351,12 +353,24 @@ static int otx2_ptp_enable(struct ptp_clock_info *ptp_info,
 				   rq->extts.index);
 		if (pin < 0)
 			return -EBUSY;
-		if (on) {
-			ptp_extts_on(ptp, on);
+		if (on)
 			schedule_delayed_work(&ptp->extts_work, msecs_to_jiffies(200));
-		} else {
-			ptp_extts_on(ptp, on);
+		else
 			cancel_delayed_work_sync(&ptp->extts_work);
+
+		return 0;
+	case PTP_CLK_REQ_PEROUT:
+		if (rq->perout.flags)
+			return -EOPNOTSUPP;
+
+		if (rq->perout.index >= ptp_info->n_pins)
+			return -EINVAL;
+		if (on) {
+			period = rq->perout.period.sec * NSEC_PER_SEC +
+				 rq->perout.period.nsec;
+			ptp_pps_on(ptp, on, period);
+		} else {
+			ptp_pps_on(ptp, on, period);
 		}
 		return 0;
 	default:
@@ -411,6 +425,7 @@ int otx2_ptp_init(struct otx2_nic *pfvf)
 		.name           = "OcteonTX2 PTP",
 		.max_adj        = 1000000000ull,
 		.n_ext_ts       = 1,
+		.n_per_out      = 1,
 		.n_pins         = 1,
 		.pps            = 0,
 		.pin_config     = &ptp_ptr->extts_config,
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Sai Krishna
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +12 -0
+	case PTP_CLK_REQ_PEROUT:
+		if (rq->perout.flags)
+			return -EOPNOTSUPP;
+
+		if (rq->perout.index >= ptp_info->n_pins)
+			return -EINVAL;
+		if (on) {
+			period = rq->perout.period.sec * NSEC_PER_SEC +
+				 rq->perout.period.nsec;
+			ptp_pps_on(ptp, on, period);
+		} else {
+			ptp_pps_on(ptp, on, period);
 		}
 		return 0;
 	default:

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c int otx2_ptp_init(struct otx2_nic *pfvf) · line 428

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +1 -0
@@ -411,6 +425,7 @@ int otx2_ptp_init(struct otx2_nic *pfvf)
 		.name           = "OcteonTX2 PTP",
 		.max_adj        = 1000000000ull,
 		.n_ext_ts       = 1,
+		.n_per_out      = 1,

Thanks for using the "per_out" API for PPS output instead of...

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c int otx2_ptp_init(struct otx2_nic *pfvf) · line 430

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c +0 -0
 		.n_pins         = 1,
 		.pps            = 0,

this one (which has a misleading name) !

#2 lore raw
In reply to Sai Krishna
This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:

Quoted 9 lines · On Tue, 12 Sep 2023 23:21:16 +0530 you wrote:

From: Hariprasad Kelam <[email protected]>

PTP block supports generating PPS output signal on GPIO pin. This patch adds the support in the PTP PHC driver using standard periodic output interface.

User can enable/disable/configure PPS by writing to the below sysfs entry

[...]

Here is the summary with links:
- [net-next] octeontx2-pf: Enable PTP PPS output support

    https://git.kernel.org/netdev/net-next/c/35293cb392e6

You are awesome, thank you!

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