[dpdk-dev] [PATCH v3 25/52] common/cnxk: add nix ptp support

Nithin Dabilpuram ndabilpuram at marvell.com
Thu Apr 1 14:37:50 CEST 2021


From: Sunil Kumar Kori <skori at marvell.com>

Add support to enable/disable Rx and Tx PTP timestamping
support. Also provide API's to register ptp info callbacks
to get config change update from Kernel.

Signed-off-by: Sunil Kumar Kori <skori at marvell.com>
---
 drivers/common/cnxk/meson.build   |   1 +
 drivers/common/cnxk/roc_nix.h     |  16 +++++
 drivers/common/cnxk/roc_nix_ptp.c | 122 ++++++++++++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map   |   6 ++
 4 files changed, 145 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_nix_ptp.c

diff --git a/drivers/common/cnxk/meson.build b/drivers/common/cnxk/meson.build
index f6a8880..d01cf0b 100644
--- a/drivers/common/cnxk/meson.build
+++ b/drivers/common/cnxk/meson.build
@@ -20,6 +20,7 @@ sources = files('roc_dev.c',
 		'roc_nix_mac.c',
 		'roc_nix_mcast.c',
 		'roc_nix_npc.c',
+		'roc_nix_ptp.c',
 		'roc_nix_queue.c',
 		'roc_nix_rss.c',
 		'roc_npa.c',
diff --git a/drivers/common/cnxk/roc_nix.h b/drivers/common/cnxk/roc_nix.h
index 83388ce..3cc1797 100644
--- a/drivers/common/cnxk/roc_nix.h
+++ b/drivers/common/cnxk/roc_nix.h
@@ -17,6 +17,11 @@ enum roc_nix_sq_max_sqe_sz {
 	roc_nix_maxsqesz_w8 = NIX_MAXSQESZ_W8,
 };
 
+/* Range to adjust PTP frequency. Valid range is
+ * (-ROC_NIX_PTP_FREQ_ADJUST, ROC_NIX_PTP_FREQ_ADJUST)
+ */
+#define ROC_NIX_PTP_FREQ_ADJUST (1 << 9)
+
 /* NIX LF RX offload configuration flags.
  * These are input flags to roc_nix_lf_alloc:rx_cfg
  */
@@ -244,6 +249,17 @@ int __roc_api roc_nix_cq_fini(struct roc_nix_cq *cq);
 int __roc_api roc_nix_sq_init(struct roc_nix *roc_nix, struct roc_nix_sq *sq);
 int __roc_api roc_nix_sq_fini(struct roc_nix_sq *sq);
 
+/* PTP */
+int __roc_api roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable);
+int __roc_api roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable);
+int __roc_api roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock,
+				     uint64_t *tsc, uint8_t is_pmu);
+int __roc_api roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix,
+					   int64_t delta);
+int __roc_api roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix,
+					   ptp_info_update_t ptp_update);
+void __roc_api roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix);
+
 /* MCAST*/
 int __roc_api roc_nix_mcast_mcam_entry_alloc(struct roc_nix *roc_nix,
 					     uint16_t nb_entries,
diff --git a/drivers/common/cnxk/roc_nix_ptp.c b/drivers/common/cnxk/roc_nix_ptp.c
new file mode 100644
index 0000000..03c4c6e
--- /dev/null
+++ b/drivers/common/cnxk/roc_nix_ptp.c
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2021 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+#define PTP_FREQ_ADJUST (1 << 9)
+
+static inline struct mbox *
+get_mbox(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	return dev->mbox;
+}
+
+int
+roc_nix_ptp_rx_ena_dis(struct roc_nix *roc_nix, int enable)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+
+	if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
+		return NIX_ERR_PARAM;
+
+	if (enable)
+		mbox_alloc_msg_cgx_ptp_rx_enable(mbox);
+	else
+		mbox_alloc_msg_cgx_ptp_rx_disable(mbox);
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_ptp_tx_ena_dis(struct roc_nix *roc_nix, int enable)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+
+	if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
+		return NIX_ERR_PARAM;
+
+	if (enable)
+		mbox_alloc_msg_nix_lf_ptp_tx_enable(mbox);
+	else
+		mbox_alloc_msg_nix_lf_ptp_tx_disable(mbox);
+
+	return mbox_process(mbox);
+}
+
+int
+roc_nix_ptp_clock_read(struct roc_nix *roc_nix, uint64_t *clock, uint64_t *tsc,
+		       uint8_t is_pmu)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct ptp_req *req;
+	struct ptp_rsp *rsp;
+	int rc = -ENOSPC;
+
+	req = mbox_alloc_msg_ptp_op(mbox);
+	if (req == NULL)
+		return rc;
+	req->op = PTP_OP_GET_CLOCK;
+	req->is_pmu = is_pmu;
+	rc = mbox_process_msg(mbox, (void *)&rsp);
+	if (rc)
+		return rc;
+
+	if (clock)
+		*clock = rsp->clk;
+
+	if (tsc)
+		*tsc = rsp->tsc;
+
+	return 0;
+}
+
+int
+roc_nix_ptp_sync_time_adjust(struct roc_nix *roc_nix, int64_t delta)
+{
+	struct mbox *mbox = get_mbox(roc_nix);
+	struct ptp_req *req;
+	struct ptp_rsp *rsp;
+	int rc = -ENOSPC;
+
+	if (roc_nix_is_vf_or_sdp(roc_nix) || roc_nix_is_lbk(roc_nix))
+		return NIX_ERR_PARAM;
+
+	if ((delta <= -PTP_FREQ_ADJUST) || (delta >= PTP_FREQ_ADJUST))
+		return NIX_ERR_INVALID_RANGE;
+
+	req = mbox_alloc_msg_ptp_op(mbox);
+	if (req == NULL)
+		return rc;
+	req->op = PTP_OP_ADJFINE;
+	req->scaled_ppm = delta;
+
+	return mbox_process_msg(mbox, (void *)&rsp);
+}
+
+int
+roc_nix_ptp_info_cb_register(struct roc_nix *roc_nix,
+			     ptp_info_update_t ptp_update)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	if (ptp_update == NULL)
+		return NIX_ERR_PARAM;
+
+	dev->ops->ptp_info_update = (ptp_info_t)ptp_update;
+	return 0;
+}
+
+void
+roc_nix_ptp_info_cb_unregister(struct roc_nix *roc_nix)
+{
+	struct nix *nix = roc_nix_to_nix_priv(roc_nix);
+	struct dev *dev = &nix->dev;
+
+	dev->ops->ptp_info_update = NULL;
+}
diff --git a/drivers/common/cnxk/version.map b/drivers/common/cnxk/version.map
index 14601a8..66a1a82 100644
--- a/drivers/common/cnxk/version.map
+++ b/drivers/common/cnxk/version.map
@@ -55,6 +55,12 @@ INTERNAL {
 	roc_nix_npc_promisc_ena_dis;
 	roc_nix_npc_rx_ena_dis;
 	roc_nix_npc_mcast_config;
+	roc_nix_ptp_clock_read;
+	roc_nix_ptp_info_cb_register;
+	roc_nix_ptp_info_cb_unregister;
+	roc_nix_ptp_rx_ena_dis;
+	roc_nix_ptp_sync_time_adjust;
+	roc_nix_ptp_tx_ena_dis;
 	roc_nix_ras_intr_ena_dis;
 	roc_nix_register_cq_irqs;
 	roc_nix_register_queue_irqs;
-- 
2.8.4



More information about the dev mailing list