DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huisong Li <lihuisong@huawei.com>
To: <dev@dpdk.org>
Cc: <thomas@monjalon.net>, <ferruh.yigit@amd.com>,
	<andrew.rybchenko@oktetlabs.ru>, <liuyonglong@huawei.com>,
	<lihuisong@huawei.com>
Subject: [PATCH v3 2/2] ethdev: add the check for the valitity of timestamp offload
Date: Thu, 17 Aug 2023 16:42:26 +0800	[thread overview]
Message-ID: <20230817084226.55327-3-lihuisong@huawei.com> (raw)
In-Reply-To: <20230817084226.55327-1-lihuisong@huawei.com>

This patch adds the check for the valitity of timestamp offload.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
---
 lib/ethdev/rte_ethdev.c | 57 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 0840d2b594..77fa71047a 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -5996,6 +5996,34 @@ rte_eth_dev_set_mc_addr_list(uint16_t port_id,
 	return ret;
 }
 
+static int
+rte_eth_timestamp_offload_valid(struct rte_eth_dev *dev)
+{
+	struct rte_eth_dev_info dev_info;
+	struct rte_eth_rxmode *rxmode;
+	int ret;
+
+	ret = rte_eth_dev_info_get(dev->data->port_id, &dev_info);
+	if (ret != 0) {
+		RTE_ETHDEV_LOG(ERR, "Cannot get port (%u) device information.\n",
+			       dev->data->port_id);
+		return ret;
+	}
+
+	if ((dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP) == 0) {
+		RTE_ETHDEV_LOG(ERR, "Driver does not support PTP.\n");
+		return -ENOTSUP;
+	}
+
+	rxmode = &dev->data->dev_conf.rxmode;
+	if ((rxmode->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) == 0) {
+		RTE_ETHDEV_LOG(ERR, "Please enable 'RTE_ETH_RX_OFFLOAD_TIMESTAMP' offload.\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 int
 rte_eth_timesync_enable(uint16_t port_id)
 {
@@ -6005,6 +6033,10 @@ rte_eth_timesync_enable(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_enable == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev));
@@ -6023,6 +6055,10 @@ rte_eth_timesync_disable(uint16_t port_id)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_disable == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev));
@@ -6049,6 +6085,10 @@ rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
 		return -EINVAL;
 	}
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_read_rx_timestamp == NULL)
 		return -ENOTSUP;
 
@@ -6078,9 +6118,12 @@ rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
 		return -EINVAL;
 	}
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_read_tx_timestamp == NULL)
 		return -ENOTSUP;
-
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp)
 			       (dev, timestamp));
 
@@ -6099,6 +6142,10 @@ rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_adjust_time == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev, delta));
@@ -6124,6 +6171,10 @@ rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
 		return -EINVAL;
 	}
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_read_time == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev,
@@ -6150,6 +6201,10 @@ rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
 		return -EINVAL;
 	}
 
+	ret = rte_eth_timestamp_offload_valid(dev);
+	if (ret != 0)
+		return ret;
+
 	if (*dev->dev_ops->timesync_write_time == NULL)
 		return -ENOTSUP;
 	ret = eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev,
-- 
2.33.0


  parent reply	other threads:[~2023-08-17  8:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28 13:39 [PATCH 0/3] some bugfixes for PTP Dongdong Liu
2022-06-28 13:39 ` [PATCH 1/3] examples/ptpclient: add the check for PTP capability Dongdong Liu
2022-06-28 13:39 ` [PATCH 2/3] net/hns3: fix fail to receive PTP packet Dongdong Liu
2022-06-28 13:39 ` [PATCH 3/3] ethdev: add the check for the valitity of timestamp offload Dongdong Liu
2022-07-02  8:17 ` [PATCH v2 0/3] some bugfixes for PTP Dongdong Liu
2022-07-02  8:17   ` [PATCH v2 1/3] examples/ptpclient: add the check for PTP capability Dongdong Liu
2022-07-02  8:17   ` [PATCH v2 2/3] net/hns3: fix fail to receive PTP packet Dongdong Liu
2022-07-02  8:17   ` [PATCH v2 3/3] ethdev: add the check for the valitity of timestamp offload Dongdong Liu
2022-07-06 14:57     ` Andrew Rybchenko
2022-07-07  2:05       ` lihuisong (C)
2023-08-17  8:42 ` [PATCH v3 0/2] ethdev: add the check for PTP capability Huisong Li
2023-08-17  8:42   ` [PATCH v3 1/2] examples/ptpclient: " Huisong Li
2023-09-15 17:29     ` Ferruh Yigit
2023-09-21  9:18       ` lihuisong (C)
2023-09-21 11:02         ` Ferruh Yigit
2023-09-21 11:22           ` Hemant Agrawal
2023-10-20  4:05             ` lihuisong (C)
2023-09-21 11:36           ` lihuisong (C)
2023-08-17  8:42   ` Huisong Li [this message]
2023-09-15 17:46   ` [PATCH v3 0/2] ethdev: " Ferruh Yigit
2023-09-21 10:02     ` lihuisong (C)
2023-09-21 11:06       ` Ferruh Yigit
2023-09-21 11:17         ` Hemant Agrawal
2023-10-20  3:58           ` lihuisong (C)
2023-11-01 23:39             ` Ferruh Yigit
2023-11-23 11:40               ` lihuisong (C)
2023-11-01 23:39           ` Ferruh Yigit
2023-09-21 11:59         ` lihuisong (C)
2023-11-01 23:39           ` Ferruh Yigit
2023-11-23 11:56             ` lihuisong (C)
2024-01-11  6:25               ` lihuisong (C)
2024-01-26 16:54                 ` Ferruh Yigit
2024-01-27  1:52                   ` lihuisong (C)
2024-01-29 11:16                     ` Ferruh Yigit
2024-01-29 13:58                       ` lihuisong (C)
2024-01-29 15:00                         ` Ferruh Yigit

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=20230817084226.55327-3-lihuisong@huawei.com \
    --to=lihuisong@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=liuyonglong@huawei.com \
    --cc=thomas@monjalon.net \
    /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).