[09/17] bus/fslmc: add and scan dprc devices

Message ID 20211206121824.3493-10-nipun.gupta@nxp.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series features and fixes on NXP eth devices |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nipun Gupta Dec. 6, 2021, 12:18 p.m. UTC
  From: Jun Yang <jun.yang@nxp.com>

In order to get connection endpoint of each objects,
scan the dprc object.

Signed-off-by: Jun Yang <jun.yang@nxp.com>
Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
---
 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
  

Patch

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 <fsl_mc_sys.h>
+#include <fsl_mc_cmd.h>
+#include <fsl_dprc.h>
+#include <fsl_dprc_cmd.h>
+
+/** @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 <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <errno.h>
+
+#include <rte_malloc.h>
+#include <rte_dev.h>
+
+#include <fslmc_logs.h>
+#include <rte_fslmc.h>
+#include <mc/fsl_dprc.h>
+#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 <fslmc_vfio.h>
 
+#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*/