From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F51DA0A0A for ; Thu, 20 May 2021 11:55:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 293EE410F7; Thu, 20 May 2021 11:55:34 +0200 (CEST) Received: from relay.smtp-ext.broadcom.com (lpdvacalvio01.broadcom.com [192.19.229.182]) by mails.dpdk.org (Postfix) with ESMTP id 9FA7F40041 for ; Thu, 20 May 2021 11:55:31 +0200 (CEST) Received: from dhcp-10-123-153-22.dhcp.broadcom.net (bgccx-dev-host-lnx2.bec.broadcom.net [10.123.153.22]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id 5A7A524710 for ; Thu, 20 May 2021 02:55:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 5A7A524710 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1621504531; bh=NMJRM9YktkTPsp7K2lCTBk6aU8q9Sv6GFwmLTY6hEq0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=I63DrSQ5II5THscZoHW3zaqroQrSZv4EktPy+niMEabNnIzje6k+LGjsHIC8TxyMS aGOUDyxwPjdZRMILRL71bYrKiQmOIAeDKK1fJLofANjjDu4kp4x5C+2k6DGbbSfTGQ VVKvK08Fp0IUF7+gla0VAMivur//qisaXHkT3GRM= From: Kalesh A P To: stable@dpdk.org Date: Thu, 20 May 2021 15:46:53 +0530 Message-Id: <20210520101654.3214-9-kalesh-anakkur.purayil@broadcom.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20210520101654.3214-1-kalesh-anakkur.purayil@broadcom.com> References: <20210520101654.3214-1-kalesh-anakkur.purayil@broadcom.com> Subject: [dpdk-stable] [PATCH 19.11 8/9] net/bnxt: fix PTP support for Thor X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Kalesh AP [ upstream commit 53f98141ee9d3a3406fe1281bbc993efd0c06575 ] 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") Signed-off-by: Kalesh AP Reviewed-by: Lance Richardson Acked-by: Ajit Khaparde --- drivers/net/bnxt/bnxt.h | 6 ++++ drivers/net/bnxt/bnxt_ethdev.c | 79 +++++++++++++++++++++++++++++++++++++++++- drivers/net/bnxt/bnxt_rxr.c | 17 +++++---- 3 files changed, 95 insertions(+), 7 deletions(-) diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index d5818e6..f68cbda 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -275,6 +275,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 @@ -324,6 +325,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 { @@ -522,6 +524,8 @@ struct bnxt { #define BNXT_FLAG_ADV_FLOW_MGMT BIT(23) #define BNXT_FLAG_NPAR_PF BIT(24) #define BNXT_FLAG_DFLT_MAC_SET BIT(26) +#define BNXT_FLAGS_PTP_TIMESYNC_ENABLED BIT(27) +#define BNXT_FLAGS_PTP_ALARM_SCHEDULED BIT(28) #define BNXT_PF(bp) (!((bp)->flags & BNXT_FLAG_VF)) #define BNXT_VF(bp) ((bp)->flags & BNXT_FLAG_VF) #define BNXT_NPAR(bp) ((bp)->flags & BNXT_FLAG_NPAR_PF) @@ -535,6 +539,8 @@ struct bnxt { #define BNXT_HAS_NQ(bp) BNXT_CHIP_THOR(bp) #define BNXT_HAS_RING_GRPS(bp) (!BNXT_CHIP_THOR(bp)) #define BNXT_HAS_DFLT_MAC_SET(bp) ((bp)->flags & BNXT_FLAG_DFLT_MAC_SET) +#define BNXT_THOR_PTP_TIMESYNC_ENABLED(bp) \ + ((bp)->flags & BNXT_FLAGS_PTP_TIMESYNC_ENABLED) uint32_t fw_cap; #define BNXT_FW_CAP_HOT_RESET BIT(0) diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c index a49ec72..1660782 100644 --- a/drivers/net/bnxt/bnxt_ethdev.c +++ b/drivers/net/bnxt/bnxt_ethdev.c @@ -942,6 +942,73 @@ static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev) return 0; } +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->flags &= ~BNXT_FLAGS_PTP_ALARM_SCHEDULED; + } +} + +static int bnxt_schedule_ptp_alarm(struct bnxt *bp) +{ + struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; + int rc; + + if (bp->flags & BNXT_FLAGS_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->flags & BNXT_FLAGS_PTP_ALARM_SCHEDULED) { + rte_eal_alarm_cancel(bnxt_ptp_get_current_time, (void *)bp); + bp->flags &= ~BNXT_FLAGS_PTP_ALARM_SCHEDULED; + } +} + +static void bnxt_ptp_stop(struct bnxt *bp) +{ + bnxt_cancel_ptp_alarm(bp); + bp->flags &= ~BNXT_FLAGS_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->flags |= BNXT_FLAGS_PTP_TIMESYNC_ENABLED; + bp->flags |= BNXT_FLAGS_PTP_ALARM_SCHEDULED; + } + + return rc; +} + /* Unload the driver, release resources */ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev) { @@ -962,6 +1029,9 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev) bnxt_cancel_fw_health_check(bp); + if (BNXT_THOR_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); @@ -1432,6 +1502,9 @@ static int bnxt_reta_query_op(struct rte_eth_dev *eth_dev, } } + if (BNXT_THOR_PTP_TIMESYNC_ENABLED(bp)) + bnxt_schedule_ptp_alarm(bp); + return 0; } @@ -3605,8 +3678,10 @@ bnxt_timesync_enable(struct rte_eth_dev *dev) if (!BNXT_CHIP_THOR(bp)) bnxt_map_ptp_regs(bp); + else + rc = bnxt_ptp_start(bp); - return 0; + return rc; } static int @@ -3626,6 +3701,8 @@ bnxt_timesync_disable(struct rte_eth_dev *dev) if (!BNXT_CHIP_THOR(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 dcdde44..8abd391 100644 --- a/drivers/net/bnxt/bnxt_rxr.c +++ b/drivers/net/bnxt/bnxt_rxr.c @@ -380,9 +380,11 @@ bnxt_parse_pkt_type(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1) static void bnxt_get_rx_ts_thor(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_THOR(bp)) + if (!BNXT_CHIP_THOR(bp) || !ptp) return; /* On Thor, Rx timestamps are provided directly in the @@ -393,10 +395,13 @@ bnxt_get_rx_ts_thor(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