DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kalesh A P <kalesh-anakkur.purayil@broadcom.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, ajit.khaparde@broadcom.com
Subject: [dpdk-dev] [PATCH 11/11] net/bnxt: fix PTP support for thor
Date: Wed, 24 Feb 2021 21:25:53 +0530	[thread overview]
Message-ID: <20210224155553.26893-12-kalesh-anakkur.purayil@broadcom.com> (raw)
In-Reply-To: <20210224155553.26893-1-kalesh-anakkur.purayil@broadcom.com>

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

On Thor, Rx timestamp is present in the Rx completion record.
Only 32 bits of the timestamp is present in the completion.
The driver needs to periodically poll the current 48 bit
free running timer using the HWRM_PORT_TS_QUERY command.
It can combine the upper 16 bits from the HWRM response
with the lower 32 bits in the Rx completion to produce
the 48 bit timestamp for the Rx packet.

This patch adds an alarm thread to periodically poll the current 48 bit
free running timer using the HWRM_PORT_TS_QUERY command.
This avoids issuing the hwrm command from the rx handler.
This patch also handles the timer roll over condition.

Fixes: 6cbd89f9f3d8 ("net/bnxt: support PTP for Thor")
Cc: stable@dpdk.org

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
---
 drivers/net/bnxt/bnxt.h        |  8 +++++
 drivers/net/bnxt/bnxt_ethdev.c | 79 +++++++++++++++++++++++++++++++++++++++++-
 drivers/net/bnxt/bnxt_rxr.c    | 17 +++++----
 3 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h
index bf3459e..de1b4af 100644
--- a/drivers/net/bnxt/bnxt.h
+++ b/drivers/net/bnxt/bnxt.h
@@ -309,6 +309,7 @@ struct rte_flow {
 #define BNXT_PTP_FLAGS_PATH_TX		0x0
 #define BNXT_PTP_FLAGS_PATH_RX		0x1
 #define BNXT_PTP_FLAGS_CURRENT_TIME	0x2
+#define BNXT_PTP_CURRENT_TIME_MASK	0xFFFF00000000ULL
 
 struct bnxt_ptp_cfg {
 #define BNXT_GRCPF_REG_WINDOW_BASE_OUT  0x400
@@ -358,6 +359,7 @@ struct bnxt_ptp_cfg {
 
 	/* On Thor, the Rx timestamp is present in the Rx completion record */
 	uint64_t			rx_timestamp;
+	uint64_t			current_time;
 };
 
 struct bnxt_coal {
@@ -671,6 +673,12 @@ struct bnxt {
 #define BNXT_TRUFLOW_EN(bp)	((bp)->flags & BNXT_FLAG_TRUFLOW_EN)
 #define BNXT_GFID_ENABLED(bp)	((bp)->flags & BNXT_FLAG_GFID_ENABLE)
 
+	uint32_t			flags2;
+#define BNXT_FLAGS2_PTP_TIMESYNC_ENABLED	BIT(0)
+#define BNXT_FLAGS2_PTP_ALARM_SCHEDULED		BIT(1)
+#define BNXT_P5_PTP_TIMESYNC_ENABLED(bp)	\
+	((bp)->flags2 & BNXT_FLAGS2_PTP_TIMESYNC_ENABLED)
+
 	uint16_t		chip_num;
 #define CHIP_NUM_58818		0xd818
 #define BNXT_CHIP_SR2(bp)	((bp)->chip_num == CHIP_NUM_58818)
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index c4f334f..c1ba749 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1300,6 +1300,73 @@ static void bnxt_free_switch_domain(struct bnxt *bp)
 	}
 }
 
+static void bnxt_ptp_get_current_time(void *arg)
+{
+	struct bnxt *bp = arg;
+	struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+	int rc;
+
+	rc = is_bnxt_in_error(bp);
+	if (rc)
+		return;
+
+	if (!ptp)
+		return;
+
+	bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
+				&ptp->current_time);
+
+	rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
+	if (rc != 0) {
+		PMD_DRV_LOG(ERR, "Failed to re-schedule PTP alarm\n");
+		bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
+	}
+}
+
+static int bnxt_schedule_ptp_alarm(struct bnxt *bp)
+{
+	struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+	int rc;
+
+	if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED)
+		return 0;
+
+	bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
+				&ptp->current_time);
+
+	rc = rte_eal_alarm_set(US_PER_S, bnxt_ptp_get_current_time, (void *)bp);
+	return rc;
+}
+
+static void bnxt_cancel_ptp_alarm(struct bnxt *bp)
+{
+	if (bp->flags2 & BNXT_FLAGS2_PTP_ALARM_SCHEDULED) {
+		rte_eal_alarm_cancel(bnxt_ptp_get_current_time, (void *)bp);
+		bp->flags2 &= ~BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
+	}
+}
+
+static void bnxt_ptp_stop(struct bnxt *bp)
+{
+	bnxt_cancel_ptp_alarm(bp);
+	bp->flags2 &= ~BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
+}
+
+static int bnxt_ptp_start(struct bnxt *bp)
+{
+	int rc;
+
+	rc = bnxt_schedule_ptp_alarm(bp);
+	if (rc != 0) {
+		PMD_DRV_LOG(ERR, "Failed to schedule PTP alarm\n");
+	} else {
+		bp->flags2 |= BNXT_FLAGS2_PTP_TIMESYNC_ENABLED;
+		bp->flags2 |= BNXT_FLAGS2_PTP_ALARM_SCHEDULED;
+	}
+
+	return rc;
+}
+
 static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
 {
 	struct bnxt *bp = eth_dev->data->dev_private;
@@ -1330,6 +1397,9 @@ static int bnxt_dev_stop(struct rte_eth_dev *eth_dev)
 
 	bnxt_cancel_fw_health_check(bp);
 
+	if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
+		bnxt_cancel_ptp_alarm(bp);
+
 	/* Do not bring link down during reset recovery */
 	if (!is_bnxt_in_error(bp)) {
 		bnxt_dev_set_link_down_op(eth_dev);
@@ -1449,6 +1519,9 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
 
 	bnxt_schedule_fw_health_check(bp);
 
+	if (BNXT_P5_PTP_TIMESYNC_ENABLED(bp))
+		bnxt_schedule_ptp_alarm(bp);
+
 	return 0;
 
 error:
@@ -3323,8 +3396,10 @@ bnxt_timesync_enable(struct rte_eth_dev *dev)
 
 	if (!BNXT_CHIP_P5(bp))
 		bnxt_map_ptp_regs(bp);
+	else
+		rc = bnxt_ptp_start(bp);
 
-	return 0;
+	return rc;
 }
 
 static int
@@ -3344,6 +3419,8 @@ bnxt_timesync_disable(struct rte_eth_dev *dev)
 
 	if (!BNXT_CHIP_P5(bp))
 		bnxt_unmap_ptp_regs(bp);
+	else
+		bnxt_ptp_stop(bp);
 
 	return 0;
 }
diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c
index 4674f7c..3f530bd 100644
--- a/drivers/net/bnxt/bnxt_rxr.c
+++ b/drivers/net/bnxt/bnxt_rxr.c
@@ -603,9 +603,11 @@ bnxt_set_ol_flags(struct bnxt_rx_ring_info *rxr, struct rx_pkt_cmpl *rxcmp,
 static void
 bnxt_get_rx_ts_p5(struct bnxt *bp, uint32_t rx_ts_cmpl)
 {
-	uint64_t systime_cycles = 0;
+	struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+	uint64_t last_hwrm_time;
+	uint64_t pkt_time = 0;
 
-	if (!BNXT_CHIP_P5(bp))
+	if (!BNXT_CHIP_P5(bp) || !ptp)
 		return;
 
 	/* On Thor, Rx timestamps are provided directly in the
@@ -616,10 +618,13 @@ bnxt_get_rx_ts_p5(struct bnxt *bp, uint32_t rx_ts_cmpl)
 	 * from the HWRM response with the lower 32 bits in the
 	 * Rx completion to produce the 48 bit timestamp for the Rx packet
 	 */
-	bnxt_hwrm_port_ts_query(bp, BNXT_PTP_FLAGS_CURRENT_TIME,
-				&systime_cycles);
-	bp->ptp_cfg->rx_timestamp = (systime_cycles & 0xFFFF00000000);
-	bp->ptp_cfg->rx_timestamp |= rx_ts_cmpl;
+	last_hwrm_time = ptp->current_time;
+	pkt_time = (last_hwrm_time & BNXT_PTP_CURRENT_TIME_MASK) | rx_ts_cmpl;
+	if (rx_ts_cmpl < (uint32_t)last_hwrm_time) {
+		/* timer has rolled over */
+		pkt_time += (1ULL << 32);
+	}
+	ptp->rx_timestamp = pkt_time;
 }
 #endif
 
-- 
2.10.1


  parent reply	other threads:[~2021-02-24 15:35 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-24 15:55 [dpdk-dev] [PATCH 00/11] bnxt fixes Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 01/11] net/bnxt: remove unused macro Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 02/11] net/bnxt: fix vnic configuration Kalesh A P
2021-03-10 13:13   ` Ferruh Yigit
2021-03-10 13:15     ` Ferruh Yigit
2021-02-24 15:55 ` [dpdk-dev] [PATCH 03/11] net/bnxt: remove extra blank line Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 04/11] net/bnxt: update number of queues per vnic in single queue mode Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 05/11] net/bnxt: update HWRM structures Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 06/11] net/bnxt: update to new version of backing store Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 07/11] net/bnxt: log port id in async events Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 08/11] net/bnxt: handle echo request async message Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 09/11] net/bnxt: fix firmware fatal error handling Kalesh A P
2021-02-24 15:55 ` [dpdk-dev] [PATCH 10/11] net/bnxt: fix fw readiness check during recovery Kalesh A P
2021-02-24 15:55 ` Kalesh A P [this message]
2021-03-03 21:25 ` [dpdk-dev] [PATCH 00/11] bnxt fixes Ajit Khaparde
2021-03-10 13:18 ` Ferruh Yigit
2021-03-10 21:26   ` [dpdk-dev] [PATCH v2 00/12] " Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 01/12] devtools: update word list Ajit Khaparde
2021-03-12  0:08       ` Ferruh Yigit
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 02/12] net/bnxt: remove unused macro Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 03/12] net/bnxt: fix VNIC configuration Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 04/12] net/bnxt: remove extra blank line Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 05/12] net/bnxt: fix queues per VNIC Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 06/12] net/bnxt: update HWRM structures Ajit Khaparde
2021-03-12  0:08       ` Ferruh Yigit
2021-03-12  0:17         ` Ajit Khaparde
2021-03-12  0:26           ` Ferruh Yigit
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 07/12] net/bnxt: update to new version of backing store Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 08/12] net/bnxt: log port id in async events Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 09/12] net/bnxt: handle echo request async message Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 10/12] net/bnxt: fix firmware fatal error handling Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 11/12] net/bnxt: fix FW readiness check during recovery Ajit Khaparde
2021-03-10 21:26     ` [dpdk-dev] [PATCH v2 12/12] net/bnxt: fix PTP support for Thor Ajit Khaparde
2021-03-11 17:15     ` [dpdk-dev] [PATCH v2 00/12] bnxt fixes Ajit Khaparde
2021-03-12  5:58       ` [dpdk-dev] [PATCH v3 " Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 01/12] devtools: update word list Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 02/12] net/bnxt: remove unused macro Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 03/12] net/bnxt: fix VNIC configuration Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 04/12] net/bnxt: remove extra blank line Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 05/12] net/bnxt: fix queues per VNIC Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 06/12] net/bnxt: update HWRM structures Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 07/12] net/bnxt: update to new version of backing store Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 08/12] net/bnxt: log port id in async events Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 09/12] net/bnxt: handle echo request async message Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 10/12] net/bnxt: fix firmware fatal error handling Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 11/12] net/bnxt: fix FW readiness check during recovery Ajit Khaparde
2021-03-12  5:58         ` [dpdk-dev] [PATCH v3 12/12] net/bnxt: fix PTP support for Thor Ajit Khaparde
2021-03-12 15:19         ` [dpdk-dev] [PATCH v3 00/12] bnxt fixes Ajit Khaparde

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210224155553.26893-12-kalesh-anakkur.purayil@broadcom.com \
    --to=kalesh-anakkur.purayil@broadcom.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).