[v2,32/43] net/dpaa2: check if Soft parser is loaded

Message ID 20240918075056.1838654-33-vanshika.shukla@nxp.com (mailing list archive)
State Changes Requested
Delegated to: Thomas Monjalon
Headers
Series DPAA2 specific patches |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

vanshika.shukla@nxp.com Sept. 18, 2024, 7:50 a.m. UTC
From: Jun Yang <jun.yang@nxp.com>

Access sp instruction area to check if sp is loaded.

Signed-off-by: Jun Yang <jun.yang@nxp.com>
Signed-off-by: Vanshika Shukla <vanshika.shukla@nxp.com>
---
 drivers/net/dpaa2/dpaa2_ethdev.c |  4 ++
 drivers/net/dpaa2/dpaa2_ethdev.h |  2 +
 drivers/net/dpaa2/dpaa2_flow.c   | 88 ++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
  

Patch

diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 000d7da85c..21955ad903 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -2858,6 +2858,10 @@  dpaa2_dev_init(struct rte_eth_dev *eth_dev)
 			return ret;
 		}
 	}
+
+	ret = dpaa2_soft_parser_loaded();
+	if (ret > 0)
+		DPAA2_PMD_INFO("soft parser is loaded");
 	DPAA2_PMD_INFO("%s: netdev created, connected to %s",
 		eth_dev->data->name, dpaa2_dev->ep_name);
 
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.h b/drivers/net/dpaa2/dpaa2_ethdev.h
index eaa653d266..db918725a7 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.h
+++ b/drivers/net/dpaa2/dpaa2_ethdev.h
@@ -479,6 +479,8 @@  int dpaa2_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
 
 int dpaa2_dev_recycle_config(struct rte_eth_dev *eth_dev);
 int dpaa2_dev_recycle_deconfig(struct rte_eth_dev *eth_dev);
+int dpaa2_soft_parser_loaded(void);
+
 int dpaa2_dev_recycle_qp_setup(struct rte_dpaa2_device *dpaa2_dev,
 	uint16_t qidx, uint64_t cntx,
 	eth_rx_burst_t tx_lpbk, eth_tx_burst_t rx_lpbk,
diff --git a/drivers/net/dpaa2/dpaa2_flow.c b/drivers/net/dpaa2/dpaa2_flow.c
index 02938ad27b..a376acffcf 100644
--- a/drivers/net/dpaa2/dpaa2_flow.c
+++ b/drivers/net/dpaa2/dpaa2_flow.c
@@ -9,6 +9,7 @@ 
 #include <string.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <sys/mman.h>
 
 #include <rte_ethdev.h>
 #include <rte_log.h>
@@ -24,6 +25,7 @@ 
 
 static char *dpaa2_flow_control_log;
 static uint16_t dpaa2_flow_miss_flow_id; /* Default miss flow id is 0. */
+static int dpaa2_sp_loaded = -1;
 
 enum dpaa2_flow_entry_size {
 	DPAA2_FLOW_ENTRY_MIN_SIZE = (DPNI_MAX_KEY_SIZE / 2),
@@ -401,6 +403,92 @@  dpaa2_flow_fs_entry_log(const char *log_info,
 	DPAA2_FLOW_DUMP("\r\n");
 }
 
+/** For LX2160A, LS2088A and LS1088A*/
+#define WRIOP_CCSR_BASE 0x8b80000
+#define WRIOP_CCSR_CTLU_OFFSET 0
+#define WRIOP_CCSR_CTLU_PARSER_OFFSET 0
+#define WRIOP_CCSR_CTLU_PARSER_INGRESS_OFFSET 0
+
+#define WRIOP_INGRESS_PARSER_PHY \
+	(WRIOP_CCSR_BASE + WRIOP_CCSR_CTLU_OFFSET + \
+	WRIOP_CCSR_CTLU_PARSER_OFFSET + \
+	WRIOP_CCSR_CTLU_PARSER_INGRESS_OFFSET)
+
+struct dpaa2_parser_ccsr {
+	uint32_t psr_cfg;
+	uint32_t psr_idle;
+	uint32_t psr_pclm;
+	uint8_t psr_ver_min;
+	uint8_t psr_ver_maj;
+	uint8_t psr_id1_l;
+	uint8_t psr_id1_h;
+	uint32_t psr_rev2;
+	uint8_t rsv[0x2c];
+	uint8_t sp_ins[4032];
+};
+
+int
+dpaa2_soft_parser_loaded(void)
+{
+	int fd, i, ret = 0;
+	struct dpaa2_parser_ccsr *parser_ccsr = NULL;
+
+	dpaa2_flow_control_log = getenv("DPAA2_FLOW_CONTROL_LOG");
+
+	if (dpaa2_sp_loaded >= 0)
+		return dpaa2_sp_loaded;
+
+	fd = open("/dev/mem", O_RDWR | O_SYNC);
+	if (fd < 0) {
+		DPAA2_PMD_ERR("open \"/dev/mem\" ERROR(%d)", fd);
+		ret = fd;
+		goto exit;
+	}
+
+	parser_ccsr = mmap(NULL, sizeof(struct dpaa2_parser_ccsr),
+		PROT_READ | PROT_WRITE, MAP_SHARED, fd,
+		WRIOP_INGRESS_PARSER_PHY);
+	if (!parser_ccsr) {
+		DPAA2_PMD_ERR("Map 0x%" PRIx64 "(size=0x%x) failed",
+			(uint64_t)WRIOP_INGRESS_PARSER_PHY,
+			(uint32_t)sizeof(struct dpaa2_parser_ccsr));
+		ret = -ENOBUFS;
+		goto exit;
+	}
+
+	DPAA2_PMD_INFO("Parser ID:0x%02x%02x, Rev:major(%02x), minor(%02x)",
+		parser_ccsr->psr_id1_h, parser_ccsr->psr_id1_l,
+		parser_ccsr->psr_ver_maj, parser_ccsr->psr_ver_min);
+
+	if (dpaa2_flow_control_log) {
+		for (i = 0; i < 64; i++) {
+			DPAA2_FLOW_DUMP("%02x ",
+				parser_ccsr->sp_ins[i]);
+			if (!((i + 1) % 16))
+				DPAA2_FLOW_DUMP("\r\n");
+		}
+	}
+
+	for (i = 0; i < 16; i++) {
+		if (parser_ccsr->sp_ins[i]) {
+			dpaa2_sp_loaded = 1;
+			break;
+		}
+	}
+	if (dpaa2_sp_loaded < 0)
+		dpaa2_sp_loaded = 0;
+
+	ret = dpaa2_sp_loaded;
+
+exit:
+	if (parser_ccsr)
+		munmap(parser_ccsr, sizeof(struct dpaa2_parser_ccsr));
+	if (fd >= 0)
+		close(fd);
+
+	return ret;
+}
+
 static int
 dpaa2_flow_ip_address_extract(enum net_prot prot,
 	uint32_t field)