From patchwork Thu Aug 17 08:42:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lihuisong (C)" X-Patchwork-Id: 130461 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 426264308C; Thu, 17 Aug 2023 10:45:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C65DB40EE2; Thu, 17 Aug 2023 10:45:24 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 8F39140685 for ; Thu, 17 Aug 2023 10:45:22 +0200 (CEST) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RRJSt0F2fzrSwj; Thu, 17 Aug 2023 16:43:58 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 17 Aug 2023 16:45:19 +0800 From: Huisong Li To: CC: , , , , Subject: [PATCH v3 1/2] examples/ptpclient: add the check for PTP capability Date: Thu, 17 Aug 2023 16:42:25 +0800 Message-ID: <20230817084226.55327-2-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230817084226.55327-1-lihuisong@huawei.com> References: <20220628133959.21381-1-liudongdong3@huawei.com> <20230817084226.55327-1-lihuisong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected 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 If a port doesn't support PTP, there is no need to keep running app. So this patch adds the check for PTP capability. Fixes: 7a04a4f67dca ("examples/ptpclient: enable Rx timestamp offload") Cc: stable@dpdk.org Signed-off-by: Huisong Li Signed-off-by: Dongdong Liu --- examples/ptpclient/ptpclient.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c index cdf2da64df..181d8fb357 100644 --- a/examples/ptpclient/ptpclient.c +++ b/examples/ptpclient/ptpclient.c @@ -196,6 +196,11 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP) port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP; + else { + printf("port(%u) doesn't support PTP: %s\n", port, + strerror(-retval)); + return -ENOTSUP; + } if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) port_conf.txmode.offloads |= From patchwork Thu Aug 17 08:42:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lihuisong (C)" X-Patchwork-Id: 130462 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 608264308C; Thu, 17 Aug 2023 10:45:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 40F2543254; Thu, 17 Aug 2023 10:45:27 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 9645A40685 for ; Thu, 17 Aug 2023 10:45:24 +0200 (CEST) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RRJS14fQmzVkqr; Thu, 17 Aug 2023 16:43:13 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Thu, 17 Aug 2023 16:45:20 +0800 From: Huisong Li To: CC: , , , , Subject: [PATCH v3 2/2] ethdev: add the check for the valitity of timestamp offload Date: Thu, 17 Aug 2023 16:42:26 +0800 Message-ID: <20230817084226.55327-3-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230817084226.55327-1-lihuisong@huawei.com> References: <20220628133959.21381-1-liudongdong3@huawei.com> <20230817084226.55327-1-lihuisong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected 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 This patch adds the check for the valitity of timestamp offload. Signed-off-by: Huisong Li Signed-off-by: Dongdong Liu --- 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,