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 D1F96A0547; Fri, 12 Mar 2021 07:00:02 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BB92F1608A9; Fri, 12 Mar 2021 06:58:48 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 1A85D16089B for ; Fri, 12 Mar 2021 06:58:42 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id d23so8204164plq.2 for ; Thu, 11 Mar 2021 21:58:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=Nvd/B7CQgTRXya/mNm0ns5S+iO/ccycB51MwEwmWEvI=; b=dxk5cyinIMpsiQdMSjdj71arrl1fg0dkcGEe95X1s1SaL+UmuC0xDafjTm9HV4PyZA m+tEaf3Yi3PlNL0ns3Y3x7AddPzCaM8kfdyQqNbgvY00NX6IAwqMZTFajPjtCBart6j7 3RYBq1dwMtUexzcZEQ+gH1/PFTtTt+/jlyFOA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=Nvd/B7CQgTRXya/mNm0ns5S+iO/ccycB51MwEwmWEvI=; b=esJ5MOWNdSy1YKMqhdOGyQQqIZMFoWqUBfe//lHZ2uK+R/jGuB45NMobZnuzTxRVaM 3s7BSNtlXf1uT8Dk2Sx6bDpwHJ42n8gIWjxEwxszW6P8dn0EQnmN3JFku6oXCBsHhknM 8QbK1goRZGULgKWf9ljkQEjiz//uGtfBKc8IdSGSNz1cG4o3gF8+zbWIGPYpmPusaJXz jwHKS1HZzrP92jshG0IfCbWOnhcEWmu6JzwTT0QZJtB9CikkaJ2XV94sRO5WE5sLdwn0 GF3i9gBxrwicRjK8+cAp0RWcScTEVoqSfkGpqYbaTeau8kFGSjdh3Jrt6i3jjcrAg4sV Gtcw== X-Gm-Message-State: AOAM531RBrjr8cmKKI07W4vsVU4+r7x74R83BWiN+d3pUSNmLD7C0RYc KCkzzkVANQqY8c3shddCjZFYYOuc5JSf/geppyMPNHQks6TGk1+wBPXb3J7X84u8TFgtldQBb1X c7BJLG+HiABHI1D2DTicX8U7ynzSDfzq14tdU562SDDjS/SzbyyNF/Bad96TX4u4f/w== X-Google-Smtp-Source: ABdhPJwfoRiQQeY/vp88vUiRiqIskwoKoPR/pup37CQ5UZlBssXjTajG3cHbTVoRLEQtNib+BgNBhA== X-Received: by 2002:a17:90b:4c87:: with SMTP id my7mr12640770pjb.162.1615528720497; Thu, 11 Mar 2021 21:58:40 -0800 (PST) Received: from localhost.localdomain ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 186sm4413173pfb.143.2021.03.11.21.58.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Mar 2021 21:58:39 -0800 (PST) From: Ajit Khaparde To: dev@dpdk.org Cc: ferruh.yigit@intel.com, Kalesh AP , stable@dpdk.org, Lance Richardson Date: Thu, 11 Mar 2021 21:58:19 -0800 Message-Id: <20210312055819.52789-13-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.21.1 (Apple Git-122.3) In-Reply-To: <20210312055819.52789-1-ajit.khaparde@broadcom.com> References: <20210312055819.52789-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="0000000000008e7e6505bd5097ad" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [dpdk-dev] [PATCH v3 12/12] net/bnxt: fix PTP support for Thor X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" --0000000000008e7e6505bd5097ad Content-Transfer-Encoding: 8bit From: Kalesh AP 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 Reviewed-by: Lance Richardson Acked-by: Ajit Khaparde --- 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 bf3459e830..de1b4af919 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 af146451a5..c55a2d8197 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: @@ -3351,8 +3424,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 @@ -3372,6 +3447,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 498811a732..30d22b7aba 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.21.1 (Apple Git-122.3) --0000000000008e7e6505bd5097ad--