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 00A84A034F; Mon, 6 Dec 2021 13:19:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 790534274A; Mon, 6 Dec 2021 13:18:40 +0100 (CET) Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by mails.dpdk.org (Postfix) with ESMTP id 0659241186 for ; Mon, 6 Dec 2021 13:18:31 +0100 (CET) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D64B01A12E9; Mon, 6 Dec 2021 13:18:30 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 7E9ED1A036C; Mon, 6 Dec 2021 13:18:30 +0100 (CET) Received: from lsv03274.swis.in-blr01.nxp.com (lsv03274.swis.in-blr01.nxp.com [92.120.147.114]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id DC744183AD0B; Mon, 6 Dec 2021 20:18:29 +0800 (+08) From: nipun.gupta@nxp.com To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@intel.com, hemant.agrawal@nxp.com, Jun Yang , Nipun Gupta Subject: [PATCH 09/17] bus/fslmc: add and scan dprc devices Date: Mon, 6 Dec 2021 17:48:16 +0530 Message-Id: <20211206121824.3493-10-nipun.gupta@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211206121824.3493-1-nipun.gupta@nxp.com> References: <20211206121824.3493-1-nipun.gupta@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP 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 From: Jun Yang In order to get connection endpoint of each objects, scan the dprc object. Signed-off-by: Jun Yang Signed-off-by: Nipun Gupta --- drivers/bus/fslmc/fslmc_bus.c | 15 ++- drivers/bus/fslmc/fslmc_vfio.c | 18 +++- drivers/bus/fslmc/mc/dprc.c | 129 +++++++++++++++++++++++ drivers/bus/fslmc/mc/fsl_dprc.h | 46 ++++++++ drivers/bus/fslmc/mc/fsl_dprc_cmd.h | 48 +++++++++ drivers/bus/fslmc/meson.build | 4 +- drivers/bus/fslmc/portal/dpaa2_hw_dprc.c | 100 ++++++++++++++++++ drivers/bus/fslmc/portal/dpaa2_hw_pvt.h | 12 +++ drivers/bus/fslmc/rte_fslmc.h | 10 +- 9 files changed, 374 insertions(+), 8 deletions(-) create mode 100644 drivers/bus/fslmc/mc/dprc.c create mode 100644 drivers/bus/fslmc/mc/fsl_dprc.h create mode 100644 drivers/bus/fslmc/mc/fsl_dprc_cmd.h create mode 100644 drivers/bus/fslmc/portal/dpaa2_hw_dprc.c diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index a0ef24cdc8..a3c0d838c4 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * - * Copyright 2016,2018-2019 NXP + * Copyright 2016,2018-2021 NXP * */ @@ -136,10 +136,6 @@ scan_one_fslmc_device(char *dev_name) if (!dev_name) return ret; - /* Ignore the Container name itself */ - if (!strncmp("dprc", dev_name, 4)) - return 0; - /* Creating a temporary copy to perform cut-parse over string */ dup_dev_name = strdup(dev_name); if (!dup_dev_name) { @@ -197,6 +193,8 @@ scan_one_fslmc_device(char *dev_name) dev->dev_type = DPAA2_MUX; else if (!strncmp("dprtc", t_ptr, 5)) dev->dev_type = DPAA2_DPRTC; + else if (!strncmp("dprc", t_ptr, 4)) + dev->dev_type = DPAA2_DPRC; else dev->dev_type = DPAA2_UNKNOWN; @@ -339,6 +337,13 @@ rte_fslmc_scan(void) goto scan_fail; } + /* Scan the DPRC container object */ + ret = scan_one_fslmc_device(fslmc_container); + if (ret != 0) { + /* Error in parsing directory - exit gracefully */ + goto scan_fail_cleanup; + } + while ((entry = readdir(dir)) != NULL) { if (entry->d_name[0] == '.' || entry->d_type != DT_DIR) continue; diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index b4704eeae4..1b89a56bbc 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2015-2016 Freescale Semiconductor, Inc. All rights reserved. - * Copyright 2016-2019 NXP + * Copyright 2016-2021 NXP * */ @@ -728,6 +728,7 @@ fslmc_process_iodevices(struct rte_dpaa2_device *dev) case DPAA2_BPOOL: case DPAA2_DPRTC: case DPAA2_MUX: + case DPAA2_DPRC: TAILQ_FOREACH(object, &dpaa2_obj_list, next) { if (dev->dev_type == object->dev_type) object->create(dev_fd, &device_info, @@ -881,6 +882,21 @@ fslmc_vfio_process_group(void) return -1; } + /* Search for DPRC device next as it updates endpoint of + * other devices. + */ + current_device = 0; + RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) { + if (dev->dev_type == DPAA2_DPRC) { + ret = fslmc_process_iodevices(dev); + if (ret) { + DPAA2_BUS_ERR("Unable to process dprc"); + return -1; + } + TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next); + } + } + current_device = 0; RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) { diff --git a/drivers/bus/fslmc/mc/dprc.c b/drivers/bus/fslmc/mc/dprc.c new file mode 100644 index 0000000000..491081c7c8 --- /dev/null +++ b/drivers/bus/fslmc/mc/dprc.c @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) + * + * Copyright 2013-2016 Freescale Semiconductor Inc. + * Copyright 2016-2021 NXP + * + */ +#include +#include +#include +#include + +/** @addtogroup dprc + * @{ + */ + +/** + * dprc_open() - Open DPRC object for use + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @container_id: Container ID to open + * @token: Returned token of DPRC object + * + * Return: '0' on Success; Error code otherwise. + * + * @warning Required before any operation on the object. + */ +int dprc_open(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + int container_id, + uint16_t *token) +{ + struct mc_command cmd = { 0 }; + struct dprc_cmd_open *cmd_params; + int err; + + /* prepare command */ + cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, + 0); + cmd_params = (struct dprc_cmd_open *)cmd.params; + cmd_params->container_id = cpu_to_le32(container_id); + + /* send command to mc*/ + err = mc_send_command(mc_io, &cmd); + if (err) + return err; + + /* retrieve response parameters */ + *token = mc_cmd_hdr_read_token(&cmd); + + return 0; +} + +/** + * dprc_close() - Close the control session of the object + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPRC object + * + * After this function is called, no further operations are + * allowed on the object without opening a new control session. + * + * Return: '0' on Success; Error code otherwise. + */ +int dprc_close(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + uint16_t token) +{ + struct mc_command cmd = { 0 }; + + /* prepare command */ + cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, + token); + + /* send command to mc*/ + return mc_send_command(mc_io, &cmd); +} + +/** + * dprc_get_connection() - Get connected endpoint and link status if connection + * exists. + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPRC object + * @endpoint1: Endpoint 1 configuration parameters + * @endpoint2: Returned endpoint 2 configuration parameters + * @state: Returned link state: + * 1 - link is up; + * 0 - link is down; + * -1 - no connection (endpoint2 information is irrelevant) + * + * Return: '0' on Success; -ENAVAIL if connection does not exist. + */ +int dprc_get_connection(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + uint16_t token, + const struct dprc_endpoint *endpoint1, + struct dprc_endpoint *endpoint2, + int *state) +{ + struct mc_command cmd = { 0 }; + struct dprc_cmd_get_connection *cmd_params; + struct dprc_rsp_get_connection *rsp_params; + int err, i; + + /* prepare command */ + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, + cmd_flags, + token); + cmd_params = (struct dprc_cmd_get_connection *)cmd.params; + cmd_params->ep1_id = cpu_to_le32(endpoint1->id); + cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id); + for (i = 0; i < 16; i++) + cmd_params->ep1_type[i] = endpoint1->type[i]; + + /* send command to mc*/ + err = mc_send_command(mc_io, &cmd); + if (err) + return err; + + /* retrieve response parameters */ + rsp_params = (struct dprc_rsp_get_connection *)cmd.params; + endpoint2->id = le32_to_cpu(rsp_params->ep2_id); + endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id); + *state = le32_to_cpu(rsp_params->state); + for (i = 0; i < 16; i++) + endpoint2->type[i] = rsp_params->ep2_type[i]; + + return 0; +} diff --git a/drivers/bus/fslmc/mc/fsl_dprc.h b/drivers/bus/fslmc/mc/fsl_dprc.h new file mode 100644 index 0000000000..177210c2d4 --- /dev/null +++ b/drivers/bus/fslmc/mc/fsl_dprc.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) + * + * Copyright 2013-2016 Freescale Semiconductor Inc. + * Copyright 2016-2021 NXP + * + */ +#ifndef _FSL_DPRC_H +#define _FSL_DPRC_H + +/** @addtogroup dprc Data Path Resource Container API + * Contains DPRC API for managing and querying DPAA resources + * @{ + */ + +struct fsl_mc_io; + +int dprc_open(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + int container_id, + uint16_t *token); + +int dprc_close(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + uint16_t token); + +/** + * struct dprc_endpoint - Endpoint description for link connect/disconnect + * operations + * @type: Endpoint object type: NULL terminated string + * @id: Endpoint object ID + * @if_id: Interface ID; should be set for endpoints with multiple + * interfaces ("dpsw", "dpdmux"); for others, always set to 0 + */ +struct dprc_endpoint { + char type[16]; + int id; + uint16_t if_id; +}; + +int dprc_get_connection(struct fsl_mc_io *mc_io, + uint32_t cmd_flags, + uint16_t token, + const struct dprc_endpoint *endpoint1, + struct dprc_endpoint *endpoint2, + int *state); +#endif /* _FSL_DPRC_H */ diff --git a/drivers/bus/fslmc/mc/fsl_dprc_cmd.h b/drivers/bus/fslmc/mc/fsl_dprc_cmd.h new file mode 100644 index 0000000000..6efa5634d2 --- /dev/null +++ b/drivers/bus/fslmc/mc/fsl_dprc_cmd.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) + * + * Copyright 2013-2016 Freescale Semiconductor Inc. + * Copyright 2016-2021 NXP + * + */ + +#ifndef _FSL_DPRC_CMD_H +#define _FSL_DPRC_CMD_H + +/* Minimal supported DPRC Version */ +#define DPRC_VER_MAJOR 6 +#define DPRC_VER_MINOR 6 + +/* Command versioning */ +#define DPRC_CMD_BASE_VERSION 1 +#define DPRC_CMD_ID_OFFSET 4 + +#define DPRC_CMD(id) ((id << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION) + +/* Command IDs */ +#define DPRC_CMDID_CLOSE DPRC_CMD(0x800) +#define DPRC_CMDID_OPEN DPRC_CMD(0x805) +#define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C) + +#pragma pack(push, 1) +struct dprc_cmd_open { + uint32_t container_id; +}; + +struct dprc_cmd_get_connection { + uint32_t ep1_id; + uint16_t ep1_interface_id; + uint16_t pad; + + uint8_t ep1_type[16]; +}; + +struct dprc_rsp_get_connection { + uint64_t pad[3]; + uint32_t ep2_id; + uint16_t ep2_interface_id; + uint16_t pad1; + uint8_t ep2_type[16]; + uint32_t state; +}; +#pragma pack(pop) +#endif /* _FSL_DPRC_CMD_H */ diff --git a/drivers/bus/fslmc/meson.build b/drivers/bus/fslmc/meson.build index 54be76f516..162ca286fe 100644 --- a/drivers/bus/fslmc/meson.build +++ b/drivers/bus/fslmc/meson.build @@ -1,5 +1,5 @@ # SPDX-License-Identifier: BSD-3-Clause -# Copyright 2018 NXP +# Copyright 2018,2021 NXP if not is_linux build = false @@ -16,10 +16,12 @@ sources = files( 'mc/dpdmai.c', 'mc/dpio.c', 'mc/dpmng.c', + 'mc/dprc.c', 'mc/mc_sys.c', 'portal/dpaa2_hw_dpbp.c', 'portal/dpaa2_hw_dpci.c', 'portal/dpaa2_hw_dpio.c', + 'portal/dpaa2_hw_dprc.c', 'qbman/qbman_portal.c', 'qbman/qbman_debug.c', ) diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c b/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c new file mode 100644 index 0000000000..ca1d0304d5 --- /dev/null +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright 2021 NXP + * + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include "portal/dpaa2_hw_pvt.h" + +TAILQ_HEAD(dprc_dev_list, dpaa2_dprc_dev); +static struct dprc_dev_list dprc_dev_list + = TAILQ_HEAD_INITIALIZER(dprc_dev_list); /*!< DPRC device list */ + +static int +rte_dpaa2_create_dprc_device(int vdev_fd __rte_unused, + struct vfio_device_info *obj_info __rte_unused, + int dprc_id) +{ + struct dpaa2_dprc_dev *dprc_node; + struct dprc_endpoint endpoint1, endpoint2; + struct rte_dpaa2_device *dev, *dev_tmp; + int ret; + + /* Allocate DPAA2 dprc handle */ + dprc_node = rte_malloc(NULL, sizeof(struct dpaa2_dprc_dev), 0); + if (!dprc_node) { + DPAA2_BUS_ERR("Memory allocation failed for DPRC Device"); + return -ENOMEM; + } + + /* Open the dprc object */ + dprc_node->dprc.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX); + dprc_node->dprc_id = dprc_id; + ret = dprc_open(&dprc_node->dprc, + CMD_PRI_LOW, dprc_id, &dprc_node->token); + if (ret) { + DPAA2_BUS_ERR("Resource alloc failure with err code: %d", ret); + rte_free(dprc_node); + return ret; + } + + RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_tmp) { + if (dev->dev_type == DPAA2_ETH) { + int link_state; + + memset(&endpoint1, 0, sizeof(struct dprc_endpoint)); + memset(&endpoint2, 0, sizeof(struct dprc_endpoint)); + strcpy(endpoint1.type, "dpni"); + endpoint1.id = dev->object_id; + ret = dprc_get_connection(&dprc_node->dprc, + CMD_PRI_LOW, + dprc_node->token, + &endpoint1, &endpoint2, + &link_state); + if (ret) { + DPAA2_BUS_ERR("dpni.%d connection failed!", + dev->object_id); + dprc_close(&dprc_node->dprc, CMD_PRI_LOW, + dprc_node->token); + rte_free(dprc_node); + return ret; + } + + if (!strcmp(endpoint2.type, "dpmac")) + dev->ep_dev_type = DPAA2_MAC; + else if (!strcmp(endpoint2.type, "dpni")) + dev->ep_dev_type = DPAA2_ETH; + else if (!strcmp(endpoint2.type, "dpdmux")) + dev->ep_dev_type = DPAA2_MUX; + else + dev->ep_dev_type = DPAA2_UNKNOWN; + + dev->ep_object_id = endpoint2.id; + } else { + dev->ep_dev_type = DPAA2_UNKNOWN; + } + sprintf(dev->ep_name, "%s.%d", endpoint2.type, endpoint2.id); + } + + TAILQ_INSERT_TAIL(&dprc_dev_list, dprc_node, next); + + return 0; +} + +static struct rte_dpaa2_object rte_dpaa2_dprc_obj = { + .dev_type = DPAA2_DPRC, + .create = rte_dpaa2_create_dprc_device, +}; + +RTE_PMD_REGISTER_DPAA2_OBJECT(dprc, rte_dpaa2_dprc_obj); diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_pvt.h b/drivers/bus/fslmc/portal/dpaa2_hw_pvt.h index b1bba1ac36..8cb4d404aa 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_pvt.h +++ b/drivers/bus/fslmc/portal/dpaa2_hw_pvt.h @@ -187,6 +187,18 @@ struct swp_active_dqs { extern struct swp_active_dqs rte_global_active_dqs_list[NUM_MAX_SWP]; +/** + * A structure describing a DPAA2 container. + */ +struct dpaa2_dprc_dev { + TAILQ_ENTRY(dpaa2_dprc_dev) next; + /**< Pointer to Next device instance */ + const char *name; + struct fsl_mc_io dprc; /** handle to DPRC portal object */ + uint16_t token; + uint32_t dprc_id; /*HW ID for DPRC object */ +}; + struct dpaa2_dpci_dev { TAILQ_ENTRY(dpaa2_dpci_dev) next; /**< Pointer to Next device instance */ diff --git a/drivers/bus/fslmc/rte_fslmc.h b/drivers/bus/fslmc/rte_fslmc.h index 729f360646..12b586b13b 100644 --- a/drivers/bus/fslmc/rte_fslmc.h +++ b/drivers/bus/fslmc/rte_fslmc.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * - * Copyright 2016,2019 NXP + * Copyright 2016,2021 NXP * */ @@ -37,6 +37,9 @@ extern "C" { #include +#include "portal/dpaa2_hw_pvt.h" +#include "portal/dpaa2_hw_dpio.h" + #define FSLMC_OBJECT_MAX_LEN 32 /**< Length of each device on bus */ #define DPAA2_INVALID_MBUF_SEQN 0 @@ -88,6 +91,8 @@ enum rte_dpaa2_dev_type { DPAA2_QDMA, /**< DPDMAI type device */ DPAA2_MUX, /**< DPDMUX type device */ DPAA2_DPRTC, /**< DPRTC type device */ + DPAA2_DPRC, /**< DPRC type device */ + DPAA2_MAC, /**< DPMAC type device */ /* Unknown device placeholder */ DPAA2_UNKNOWN, DPAA2_DEVTYPE_MAX, @@ -122,6 +127,9 @@ struct rte_dpaa2_device { }; enum rte_dpaa2_dev_type dev_type; /**< Device Type */ uint16_t object_id; /**< DPAA2 Object ID */ + enum rte_dpaa2_dev_type ep_dev_type; /**< Endpoint Device Type */ + uint16_t ep_object_id; /**< Endpoint DPAA2 Object ID */ + char ep_name[RTE_DEV_NAME_MAX_LEN]; struct rte_intr_handle *intr_handle; /**< Interrupt handle */ struct rte_dpaa2_driver *driver; /**< Associated driver */ char name[FSLMC_OBJECT_MAX_LEN]; /**< DPAA2 Object name*/ -- 2.17.1