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 92C23A00C3 for ; Sat, 2 Jul 2022 10:18:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D3C6740A83; Sat, 2 Jul 2022 10:18:18 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 22A1542B75; Sat, 2 Jul 2022 10:18:17 +0200 (CEST) Received: from kwepemi500017.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LZlJh07ZnzkWZm; Sat, 2 Jul 2022 16:16:19 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemi500017.china.huawei.com (7.221.188.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 2 Jul 2022 16:18:15 +0800 From: Dongdong Liu To: , , , CC: , Huisong Li , Dongdong Liu Subject: [PATCH v2 3/3] ethdev: add the check for the valitity of timestamp offload Date: Sat, 2 Jul 2022 16:17:30 +0800 Message-ID: <20220702081730.1168-4-liudongdong3@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20220702081730.1168-1-liudongdong3@huawei.com> References: <20220628133959.21381-1-liudongdong3@huawei.com> <20220702081730.1168-1-liudongdong3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500017.china.huawei.com (7.221.188.110) X-CFilter-Loop: Reflected 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 From: Huisong Li 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 | 65 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 1979dc0850..9b8ba3a348 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -5167,15 +5167,48 @@ rte_eth_dev_set_mc_addr_list(uint16_t port_id, mc_addr_set, nb_mc_addr)); } +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) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev)); } @@ -5183,11 +5216,15 @@ int rte_eth_timesync_disable(uint16_t port_id) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev)); } @@ -5196,6 +5233,7 @@ rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp, uint32_t flags) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -5207,7 +5245,12 @@ rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp, return -EINVAL; } - RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP); + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, + -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp) (dev, timestamp, flags)); } @@ -5217,6 +5260,7 @@ rte_eth_timesync_read_tx_timestamp(uint16_t port_id, struct timespec *timestamp) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -5229,6 +5273,10 @@ rte_eth_timesync_read_tx_timestamp(uint16_t port_id, } RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp) (dev, timestamp)); } @@ -5237,11 +5285,16 @@ int rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev, delta)); } @@ -5249,6 +5302,7 @@ int rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -5261,6 +5315,10 @@ rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp) } RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev, timestamp)); } @@ -5269,6 +5327,7 @@ int rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; @@ -5281,6 +5340,10 @@ rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp) } RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP); + ret = rte_eth_timestamp_offload_valid(dev); + if (ret != 0) + return ret; + return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev, timestamp)); } -- 2.22.0