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 9ED81A0353; Thu, 24 Feb 2022 09:02:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F78F41180; Thu, 24 Feb 2022 09:02:27 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id B66F64114D for ; Thu, 24 Feb 2022 09:02:26 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 21O6pKIK023579 for ; Thu, 24 Feb 2022 00:02:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=JlXkwJBDJgjrlBvBmUxHLK2jQKDukm+jEfApEa2lpaE=; b=jeSUs9rSbdIQ2d0BDG/SeVpT9n4jo2OTT4qiEZxSvQrNd1BKSGJo4F678FuLouM/0zjZ hvHiAVnz4o78qAfckoAEeeQstv9V42FMweGFHO/HIIaX6XWEVMMOMk1BA6PPvxEhBSrk a157ZGD7l+OAbNC4nXJooL0w4dTglHJboXv9d6Yr6rZY233+RuaN0/Gza231V88rDQYU uX0hDbQswWXBORIrhXfdJFpHoOuXYKR2mZwRFK4/NKwwzaSworoXAVrWN7hdifcysZjk TbwbzjJimfmfjjCac5WJ8P4HD2lXdn1o6qsntnWYISqNt4M00lQ6FwRNWYDTzN77E4uN YQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3edjernek3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 24 Feb 2022 00:02:24 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 24 Feb 2022 00:02:22 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 24 Feb 2022 00:02:22 -0800 Received: from localhost.localdomain (unknown [10.28.48.103]) by maili.marvell.com (Postfix) with ESMTP id 7F1043F70A1; Thu, 24 Feb 2022 00:02:20 -0800 (PST) From: Rakesh Kudurumalla To: Nithin Dabilpuram , Kiran Kumar K , Sunil Kumar Kori , Satha Rao CC: , , Rakesh Kudurumalla Subject: [PATCH 1/2] net/cnxk: add callback handler to read ptp timestamp Date: Thu, 24 Feb 2022 13:32:16 +0530 Message-ID: <20220224080217.2895297-1-rkudurumalla@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: vEJorEYcyqvLHAzubaR6v8t_yV6ewPzI X-Proofpoint-GUID: vEJorEYcyqvLHAzubaR6v8t_yV6ewPzI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-02-23_09,2022-02-23_01,2022-02-23_01 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 timestamp resolution for an incoming and outgoing packets is different for CN10k and CN9K.Added platform specific callback to retrieve timestamp in correct format when read by application Signed-off-by: Rakesh Kudurumalla --- drivers/net/cnxk/cn10k_ethdev.c | 23 +++++++++++++++++++++++ drivers/net/cnxk/cn10k_rx.h | 32 +++++++++++++++++++++++++++++++- drivers/net/cnxk/cn9k_ethdev.c | 21 +++++++++++++++++++++ drivers/net/cnxk/cn9k_rx.h | 30 +++++++++++++++++++++++++++++- 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/drivers/net/cnxk/cn10k_ethdev.c b/drivers/net/cnxk/cn10k_ethdev.c index c6890f3699..e57847ef3a 100644 --- a/drivers/net/cnxk/cn10k_ethdev.c +++ b/drivers/net/cnxk/cn10k_ethdev.c @@ -428,6 +428,27 @@ cn10k_nix_timesync_disable(struct rte_eth_dev *eth_dev) return 0; } +static int +cn10k_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev, + struct timespec *timestamp) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_timesync_info *tstamp = &dev->tstamp; + uint64_t ns; + + if (*tstamp->tx_tstamp == 0) + return -EINVAL; + + *tstamp->tx_tstamp = ((*tstamp->tx_tstamp >> 32) * NSEC_PER_SEC) + + (*tstamp->tx_tstamp & 0xFFFFFFFFUL); + ns = rte_timecounter_update(&dev->tx_tstamp_tc, *tstamp->tx_tstamp); + *timestamp = rte_ns_to_timespec(ns); + *tstamp->tx_tstamp = 0; + rte_wmb(); + + return 0; +} + static int cn10k_nix_dev_start(struct rte_eth_dev *eth_dev) { @@ -499,6 +520,8 @@ nix_eth_dev_ops_override(void) cnxk_eth_dev_ops.timesync_disable = cn10k_nix_timesync_disable; cnxk_eth_dev_ops.rx_metadata_negotiate = cn10k_nix_rx_metadata_negotiate; + cnxk_eth_dev_ops.timesync_read_tx_timestamp = + cn10k_nix_timesync_read_tx_timestamp; } static void diff --git a/drivers/net/cnxk/cn10k_rx.h b/drivers/net/cnxk/cn10k_rx.h index 2083c73879..abf280102b 100644 --- a/drivers/net/cnxk/cn10k_rx.h +++ b/drivers/net/cnxk/cn10k_rx.h @@ -432,6 +432,36 @@ nix_rx_nb_pkts(struct cn10k_eth_rxq *rxq, const uint64_t wdata, return RTE_MIN(pkts, available); } +static __rte_always_inline void +cn10k_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf, + struct cnxk_timesync_info *tstamp, + const uint8_t ts_enable, uint64_t *tstamp_ptr) +{ + if (ts_enable) { + mbuf->pkt_len -= CNXK_NIX_TIMESYNC_RX_OFFSET; + mbuf->data_len -= CNXK_NIX_TIMESYNC_RX_OFFSET; + + /* Reading the rx timestamp inserted by CGX, viz at + * starting of the packet data. + */ + *tstamp_ptr = ((*tstamp_ptr >> 32) * NSEC_PER_SEC) + + (*tstamp_ptr & 0xFFFFFFFFUL); + *cnxk_nix_timestamp_dynfield(mbuf, tstamp) = + rte_be_to_cpu_64(*tstamp_ptr); + /* RTE_MBUF_F_RX_IEEE1588_TMST flag needs to be set only in case + * PTP packets are received. + */ + if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) { + tstamp->rx_tstamp = + *cnxk_nix_timestamp_dynfield(mbuf, tstamp); + tstamp->rx_ready = 1; + mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP | + RTE_MBUF_F_RX_IEEE1588_TMST | + tstamp->rx_tstamp_dynflag; + } + } +} + static __rte_always_inline uint16_t cn10k_nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts, const uint16_t flags) @@ -486,7 +516,7 @@ cn10k_nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts, cn10k_nix_cqe_to_mbuf(cq, cq->tag, mbuf, lookup_mem, mbuf_init, flags); - cnxk_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, + cn10k_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, (flags & NIX_RX_OFFLOAD_TSTAMP_F), (uint64_t *)((uint8_t *)mbuf + data_off)); diff --git a/drivers/net/cnxk/cn9k_ethdev.c b/drivers/net/cnxk/cn9k_ethdev.c index d81f9ac80f..6b049b2897 100644 --- a/drivers/net/cnxk/cn9k_ethdev.c +++ b/drivers/net/cnxk/cn9k_ethdev.c @@ -450,6 +450,25 @@ cn9k_nix_dev_start(struct rte_eth_dev *eth_dev) return 0; } +static int +cn9k_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev, + struct timespec *timestamp) +{ + struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); + struct cnxk_timesync_info *tstamp = &dev->tstamp; + uint64_t ns; + + if (*tstamp->tx_tstamp == 0) + return -EINVAL; + + ns = rte_timecounter_update(&dev->tx_tstamp_tc, *tstamp->tx_tstamp); + *timestamp = rte_ns_to_timespec(ns); + *tstamp->tx_tstamp = 0; + rte_wmb(); + + return 0; +} + static int cn9k_nix_rx_metadata_negotiate(struct rte_eth_dev *eth_dev, uint64_t *features) { @@ -492,6 +511,8 @@ nix_eth_dev_ops_override(void) cnxk_eth_dev_ops.timesync_disable = cn9k_nix_timesync_disable; cnxk_eth_dev_ops.mtr_ops_get = NULL; cnxk_eth_dev_ops.rx_metadata_negotiate = cn9k_nix_rx_metadata_negotiate; + cnxk_eth_dev_ops.timesync_read_tx_timestamp = + cn9k_nix_timesync_read_tx_timestamp; } static void diff --git a/drivers/net/cnxk/cn9k_rx.h b/drivers/net/cnxk/cn9k_rx.h index 6b6c5bfbc2..25a4927a33 100644 --- a/drivers/net/cnxk/cn9k_rx.h +++ b/drivers/net/cnxk/cn9k_rx.h @@ -435,6 +435,34 @@ nix_rx_nb_pkts(struct cn9k_eth_rxq *rxq, const uint64_t wdata, return RTE_MIN(pkts, available); } +static __rte_always_inline void +cn9k_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf, + struct cnxk_timesync_info *tstamp, + const uint8_t ts_enable, uint64_t *tstamp_ptr) +{ + if (ts_enable) { + mbuf->pkt_len -= CNXK_NIX_TIMESYNC_RX_OFFSET; + mbuf->data_len -= CNXK_NIX_TIMESYNC_RX_OFFSET; + + /* Reading the rx timestamp inserted by CGX, viz at + * starting of the packet data. + */ + *cnxk_nix_timestamp_dynfield(mbuf, tstamp) = + rte_be_to_cpu_64(*tstamp_ptr); + /* RTE_MBUF_F_RX_IEEE1588_TMST flag needs to be set only in case + * PTP packets are received. + */ + if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) { + tstamp->rx_tstamp = + *cnxk_nix_timestamp_dynfield(mbuf, tstamp); + tstamp->rx_ready = 1; + mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP | + RTE_MBUF_F_RX_IEEE1588_TMST | + tstamp->rx_tstamp_dynflag; + } + } +} + static __rte_always_inline uint16_t cn9k_nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts, const uint16_t flags) @@ -463,7 +491,7 @@ cn9k_nix_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t pkts, cn9k_nix_cqe_to_mbuf(cq, cq->tag, mbuf, lookup_mem, mbuf_init, flags); - cnxk_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, + cn9k_nix_mbuf_to_tstamp(mbuf, rxq->tstamp, (flags & NIX_RX_OFFLOAD_TSTAMP_F), (uint64_t *)((uint8_t *)mbuf + data_off)); -- 2.25.1