From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 60BDFA0613 for ; Thu, 29 Aug 2019 12:45:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D914F1E89B; Thu, 29 Aug 2019 12:43:07 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 824B01DFEC for ; Thu, 29 Aug 2019 12:42:00 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6154020032A; Thu, 29 Aug 2019 12:42:00 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 23D61200321; Thu, 29 Aug 2019 12:41:58 +0200 (CEST) Received: from GDB1.ap.freescale.net (GDB1.ap.freescale.net [10.232.132.179]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 21C10402BE; Thu, 29 Aug 2019 18:41:55 +0800 (SGT) From: Sachin Saxena To: dev@dpdk.org Cc: thomas@monjalon.net, Priyanka Jain Date: Thu, 29 Aug 2019 15:57:31 +0530 Message-Id: <20190829102737.13267-25-sachin.saxena@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190829102737.13267-1-sachin.saxena@nxp.com> References: <20190827070730.11206-1-sachin.saxena@nxp.com> <20190829102737.13267-1-sachin.saxena@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH v2 24/30] net/dpaa2: add ptp driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" From: Priyanka Jain This patch adds the support for PTP driver for DPAA2 devices. To enable set CONFIG_RTE_LIBRTE_IEEE1588=y in config/defconfig_arm64-dpaa2-linuxapp-gc Signed-off-by: Priyanka Jain --- config/defconfig_arm64-dpaa2-linuxapp-gcc | 2 +- drivers/bus/fslmc/fslmc_bus.c | 2 + drivers/bus/fslmc/fslmc_vfio.c | 2 + drivers/bus/fslmc/rte_fslmc.h | 1 + drivers/net/dpaa2/Makefile | 1 + drivers/net/dpaa2/base/dpaa2_hw_dpni_annot.h | 2 +- drivers/net/dpaa2/dpaa2_ethdev.c | 9 + drivers/net/dpaa2/dpaa2_ethdev.h | 27 ++- drivers/net/dpaa2/dpaa2_ptp.c | 181 +++++++++++++++++++ drivers/net/dpaa2/meson.build | 1 + 10 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 drivers/net/dpaa2/dpaa2_ptp.c diff --git a/config/defconfig_arm64-dpaa2-linuxapp-gcc b/config/defconfig_arm64-dpaa2-linuxapp-gcc index b2543266a..5c7eddd5e 100644 --- a/config/defconfig_arm64-dpaa2-linuxapp-gcc +++ b/config/defconfig_arm64-dpaa2-linuxapp-gcc @@ -16,7 +16,7 @@ CONFIG_RTE_CACHE_LINE_SIZE=64 CONFIG_RTE_PKTMBUF_HEADROOM=128 # Enable IEEE1588, Keep it disable by default -CONFIG_RTE_LIBRTE_IEEE1588=n +CONFIG_RTE_LIBRTE_IEEE1588=y # Doesn't support NUMA CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES=n diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index a2f482516..9b2dd51c4 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -191,6 +191,8 @@ scan_one_fslmc_device(char *dev_name) dev->dev_type = DPAA2_QDMA; else if (!strncmp("dpdmux", t_ptr, 6)) dev->dev_type = DPAA2_MUX; + else if (!strncmp("dprtc", t_ptr, 5)) + dev->dev_type = DPAA2_DPRTC; else dev->dev_type = DPAA2_UNKNOWN; diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 9658fd84d..60c51d80e 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -612,6 +612,7 @@ fslmc_process_iodevices(struct rte_dpaa2_device *dev) case DPAA2_IO: case DPAA2_CI: case DPAA2_BPOOL: + case DPAA2_DPRTC: case DPAA2_MUX: TAILQ_FOREACH(object, &dpaa2_obj_list, next) { if (dev->dev_type == object->dev_type) @@ -768,6 +769,7 @@ fslmc_vfio_process_group(void) case DPAA2_CON: case DPAA2_CI: case DPAA2_BPOOL: + case DPAA2_DPRTC: case DPAA2_MUX: /* IN case of secondary processes, all control objects * like dpbp, dpcon, dpci are not initialized/required diff --git a/drivers/bus/fslmc/rte_fslmc.h b/drivers/bus/fslmc/rte_fslmc.h index 5cfb24505..31dfd1377 100644 --- a/drivers/bus/fslmc/rte_fslmc.h +++ b/drivers/bus/fslmc/rte_fslmc.h @@ -67,6 +67,7 @@ enum rte_dpaa2_dev_type { DPAA2_MPORTAL, /**< DPMCP type device */ DPAA2_QDMA, /**< DPDMAI type device */ DPAA2_MUX, /**< DPDMUX type device */ + DPAA2_DPRTC, /**< DPRTC type device */ /* Unknown device placeholder */ DPAA2_UNKNOWN, DPAA2_DEVTYPE_MAX, diff --git a/drivers/net/dpaa2/Makefile b/drivers/net/dpaa2/Makefile index 9b52fa1e5..0cc539dc5 100644 --- a/drivers/net/dpaa2/Makefile +++ b/drivers/net/dpaa2/Makefile @@ -38,6 +38,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += mc/dpni.c SRCS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += mc/dpkg.c SRCS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += mc/dpdmux.c SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) += mc/dprtc.c +SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) += dpaa2_ptp.c LDLIBS += -lrte_bus_fslmc LDLIBS += -lrte_mempool_dpaa2 diff --git a/drivers/net/dpaa2/base/dpaa2_hw_dpni_annot.h b/drivers/net/dpaa2/base/dpaa2_hw_dpni_annot.h index 0d6324183..699e4c089 100644 --- a/drivers/net/dpaa2/base/dpaa2_hw_dpni_annot.h +++ b/drivers/net/dpaa2/base/dpaa2_hw_dpni_annot.h @@ -279,7 +279,7 @@ struct dpaa2_faead { #define DPAA2_ETH_FAS_DISC 0x80000000 /* MACSEC frame */ #define DPAA2_ETH_FAS_MS 0x40000000 -#define DPAA2_ETH_FAS_PTP 0x08000000 +#define DPAA2_ETH_FAS_PTP BIT_POS(59) /* Ethernet multicast frame */ #define DPAA2_ETH_FAS_MC 0x04000000 /* Ethernet broadcast frame */ diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c index 5ba8c911b..72832a0f6 100644 --- a/drivers/net/dpaa2/dpaa2_ethdev.c +++ b/drivers/net/dpaa2/dpaa2_ethdev.c @@ -2178,6 +2178,15 @@ static struct eth_dev_ops dpaa2_ethdev_ops = { .rss_hash_update = dpaa2_dev_rss_hash_update, .rss_hash_conf_get = dpaa2_dev_rss_hash_conf_get, .filter_ctrl = dpaa2_dev_flow_ctrl, +#if defined(RTE_LIBRTE_IEEE1588) + .timesync_enable = dpaa2_timesync_enable, + .timesync_disable = dpaa2_timesync_disable, + .timesync_read_time = dpaa2_timesync_read_time, + .timesync_write_time = dpaa2_timesync_write_time, + .timesync_adjust_time = dpaa2_timesync_adjust_time, + .timesync_read_rx_timestamp = dpaa2_timesync_read_rx_timestamp, + .timesync_read_tx_timestamp = dpaa2_timesync_read_tx_timestamp, +#endif }; /* Populate the mac address from physically available (u-boot/firmware) and/or diff --git a/drivers/net/dpaa2/dpaa2_ethdev.h b/drivers/net/dpaa2/dpaa2_ethdev.h index 04a8ef8da..b51c35f89 100644 --- a/drivers/net/dpaa2/dpaa2_ethdev.h +++ b/drivers/net/dpaa2/dpaa2_ethdev.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. - * Copyright 2016 NXP + * Copyright 2016-2019 NXP * */ @@ -130,6 +130,17 @@ struct dpaa2_dev_priv { uint64_t qos_extract_param; uint64_t fs_extract_param[MAX_TCS]; } extract; + +#if defined(RTE_LIBRTE_IEEE1588) + /*stores timestamp of last received packet on dev*/ + uint64_t rx_timestamp; + /*stores timestamp of last received tx confirmation packet on dev*/ + uint64_t tx_timestamp; + /* stores pointer to next tx_conf queue that should be processed, + * it corresponds to last packet transmitted + */ + struct dpaa2_queue *next_tx_conf_queue; +#endif LIST_HEAD(, rte_flow) flows; /**< Configured flow rule handles. */ }; @@ -182,4 +193,18 @@ void dpaa2_dev_free_eqresp_buf(uint16_t eqresp_ci); void dpaa2_flow_clean(struct rte_eth_dev *dev); uint16_t dpaa2_dev_tx_conf(void *queue) __attribute__((unused)); +#if defined(RTE_LIBRTE_IEEE1588) +int dpaa2_timesync_enable(struct rte_eth_dev *dev); +int dpaa2_timesync_disable(struct rte_eth_dev *dev); +int dpaa2_timesync_read_time(struct rte_eth_dev *dev, + struct timespec *timestamp); +int dpaa2_timesync_write_time(struct rte_eth_dev *dev, + const struct timespec *timestamp); +int dpaa2_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta); +int dpaa2_timesync_read_rx_timestamp(struct rte_eth_dev *dev, + struct timespec *timestamp, + uint32_t flags __rte_unused); +int dpaa2_timesync_read_tx_timestamp(struct rte_eth_dev *dev, + struct timespec *timestamp); +#endif #endif /* _DPAA2_ETHDEV_H */ diff --git a/drivers/net/dpaa2/dpaa2_ptp.c b/drivers/net/dpaa2/dpaa2_ptp.c new file mode 100644 index 000000000..316912fe3 --- /dev/null +++ b/drivers/net/dpaa2/dpaa2_ptp.c @@ -0,0 +1,181 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2019 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +struct dpaa2_dprtc_dev { + struct fsl_mc_io dprtc; /** handle to DPRTC portal object */ + uint16_t token; + uint32_t dprtc_id; /*HW ID for DPRTC object */ +}; +static struct dpaa2_dprtc_dev *dprtc_dev; + +int dpaa2_timesync_enable(struct rte_eth_dev *dev __rte_unused) +{ + return 0; +} + +int dpaa2_timesync_disable(struct rte_eth_dev *dev __rte_unused) +{ + return 0; +} + +int dpaa2_timesync_read_time(struct rte_eth_dev *dev, + struct timespec *timestamp) +{ + uint64_t ns; + int ret = 0; + + RTE_SET_USED(dev); + + ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW, + dprtc_dev->token, &ns); + if (ret) { + DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret); + return ret; + } + + *timestamp = rte_ns_to_timespec(ns); + + return 0; +} + +int dpaa2_timesync_write_time(struct rte_eth_dev *dev, + const struct timespec *ts) +{ + uint64_t ns; + int ret = 0; + + RTE_SET_USED(dev); + + ns = rte_timespec_to_ns(ts); + + ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW, + dprtc_dev->token, ns); + if (ret) { + DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret); + return ret; + } + + return 0; +} + +int dpaa2_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta) +{ + uint64_t ns; + int ret = 0; + + RTE_SET_USED(dev); + + ret = dprtc_get_time(&dprtc_dev->dprtc, CMD_PRI_LOW, + dprtc_dev->token, &ns); + if (ret) { + DPAA2_PMD_ERR("dprtc_get_time failed ret: %d", ret); + return ret; + } + + ns += delta; + + ret = dprtc_set_time(&dprtc_dev->dprtc, CMD_PRI_LOW, + dprtc_dev->token, ns); + if (ret) { + DPAA2_PMD_ERR("dprtc_set_time failed ret: %d", ret); + return ret; + } + + return 0; +} + +int dpaa2_timesync_read_tx_timestamp(struct rte_eth_dev *dev, + struct timespec *timestamp) +{ + struct dpaa2_dev_priv *priv = dev->data->dev_private; + + if (priv->next_tx_conf_queue) + dpaa2_dev_tx_conf(priv->next_tx_conf_queue); + else + return -1; + *timestamp = rte_ns_to_timespec(priv->tx_timestamp); + + return 0; +} + +int dpaa2_timesync_read_rx_timestamp(struct rte_eth_dev *dev, + struct timespec *timestamp, + uint32_t flags __rte_unused) +{ + struct dpaa2_dev_priv *priv = dev->data->dev_private; + *timestamp = rte_ns_to_timespec(priv->rx_timestamp); + return 0; +} + +static int +dpaa2_create_dprtc_device(int vdev_fd __rte_unused, + struct vfio_device_info *obj_info __rte_unused, + int dprtc_id) +{ + struct dprtc_attr attr; + int ret; + + PMD_INIT_FUNC_TRACE(); + + /* Allocate DPAA2 dprtc handle */ + dprtc_dev = rte_malloc(NULL, sizeof(struct dpaa2_dprtc_dev), 0); + if (!dprtc_dev) { + DPAA2_PMD_ERR("Memory allocation failed for DPRTC Device"); + return -1; + } + + /* Open the dprtc object */ + dprtc_dev->dprtc.regs = rte_mcp_ptr_list[MC_PORTAL_INDEX]; + ret = dprtc_open(&dprtc_dev->dprtc, CMD_PRI_LOW, dprtc_id, + &dprtc_dev->token); + if (ret) { + DPAA2_PMD_ERR("Unable to open dprtc object: err(%d)", ret); + goto init_err; + } + + ret = dprtc_get_attributes(&dprtc_dev->dprtc, CMD_PRI_LOW, + dprtc_dev->token, &attr); + if (ret) { + DPAA2_PMD_ERR("Unable to get dprtc attr: err(%d)", ret); + goto init_err; + } + + dprtc_dev->dprtc_id = dprtc_id; + + return 0; + +init_err: + if (dprtc_dev) + rte_free(dprtc_dev); + + return -1; +} + +static struct rte_dpaa2_object rte_dpaa2_dprtc_obj = { + .dev_type = DPAA2_DPRTC, + .create = dpaa2_create_dprtc_device, +}; + +RTE_PMD_REGISTER_DPAA2_OBJECT(dprtc, rte_dpaa2_dprtc_obj); diff --git a/drivers/net/dpaa2/meson.build b/drivers/net/dpaa2/meson.build index 1184ce6b9..fc311e9f7 100644 --- a/drivers/net/dpaa2/meson.build +++ b/drivers/net/dpaa2/meson.build @@ -20,6 +20,7 @@ sources = files('base/dpaa2_hw_dpni.c', if dpdk_conf.has('RTE_LIBRTE_IEEE1588') sources += files('mc/dprtc.c') + sources += files('dpaa2_ptp.c') endif includes += include_directories('base', 'mc') -- 2.17.1