[][openwrt][mt7988][tops][Fix L2TP/IPSec deadlock and check if TOPS HW exists]

[Description]
Fix HW issue between tunnel offload engine and crypto offload engine.

Check if TOPS HW exists before bring-up.

Sync from internal dev repo.
Commit-Id <5951d48c0b4fd965d66afddcb322f5244614076f>

[Release-log]
N/A

Change-Id: I132d67e23117f7bd14def1f8d42173eb0b7211f7
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8023635
diff --git a/package-21.02/kernel/tops/firmware/rebb/mt7988_mgmt/tops-mgmt.img b/package-21.02/kernel/tops/firmware/rebb/mt7988_mgmt/tops-mgmt.img
index 19b5af6..90b8be8 100644
--- a/package-21.02/kernel/tops/firmware/rebb/mt7988_mgmt/tops-mgmt.img
+++ b/package-21.02/kernel/tops/firmware/rebb/mt7988_mgmt/tops-mgmt.img
Binary files differ
diff --git a/package-21.02/kernel/tops/firmware/rebb/mt7988_offload/tops-offload.img b/package-21.02/kernel/tops/firmware/rebb/mt7988_offload/tops-offload.img
index 7021910..d562bc2 100644
--- a/package-21.02/kernel/tops/firmware/rebb/mt7988_offload/tops-offload.img
+++ b/package-21.02/kernel/tops/firmware/rebb/mt7988_offload/tops-offload.img
Binary files differ
diff --git a/package-21.02/kernel/tops/src/init.c b/package-21.02/kernel/tops/src/init.c
index 05a7fe4..62c7806 100644
--- a/package-21.02/kernel/tops/src/init.c
+++ b/package-21.02/kernel/tops/src/init.c
@@ -5,11 +5,13 @@
  * Author: Ren-Ting Wang <ren-ting.wang@mediatek.com>
  */
 
-#include <linux/of.h>
-#include <linux/err.h>
+#include <linux/debugfs.h>
 #include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
 #include <linux/module.h>
-#include <linux/debugfs.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 
@@ -29,6 +31,8 @@
 #include "tunnel.h"
 #include "wdt.h"
 
+#define EFUSE_TOPS_POWER_OFF		(0xD08)
+
 struct device *tops_dev;
 struct dentry *tops_debugfs_root;
 
@@ -200,8 +204,52 @@
 	},
 };
 
+static int __init mtk_tops_hw_disabled(void)
+{
+	struct platform_device *efuse_pdev;
+	struct device_node *efuse_node;
+	struct resource res;
+	void __iomem *efuse_base;
+	int ret = 0;
+
+	efuse_node = of_find_compatible_node(NULL, NULL, "mediatek,efuse");
+	if (!efuse_node)
+		return -ENODEV;
+
+	efuse_pdev = of_find_device_by_node(efuse_node);
+	if (!efuse_pdev) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	if (of_address_to_resource(efuse_node, 0, &res)) {
+		ret = -ENXIO;
+		goto out;
+	}
+
+	/* since we are not probed yet, we cannot use devm_* API */
+	efuse_base = ioremap(res.start, resource_size(&res));
+	if (!efuse_base) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	if (readl(efuse_base + EFUSE_TOPS_POWER_OFF))
+		ret = -ENODEV;
+
+	iounmap(efuse_base);
+
+out:
+	of_node_put(efuse_node);
+
+	return ret;
+}
+
 static int __init mtk_tops_init(void)
 {
+	if (mtk_tops_hw_disabled())
+		return -ENODEV;
+
 	tops_debugfs_root = debugfs_create_dir("tops", NULL);
 	if (IS_ERR(tops_debugfs_root)) {
 		TOPS_ERR("create tops debugfs root directory failed\n");
diff --git a/package-21.02/kernel/tops/src/tnl_offload.c b/package-21.02/kernel/tops/src/tnl_offload.c
index bd37faa..268e3ee 100644
--- a/package-21.02/kernel/tops/src/tnl_offload.c
+++ b/package-21.02/kernel/tops/src/tnl_offload.c
@@ -25,6 +25,7 @@
 #include <pce/cdrt.h>
 #include <pce/cls.h>
 #include <pce/dipfilter.h>
+#include <pce/netsys.h>
 #include <pce/pce.h>
 
 #include "internal.h"
@@ -508,9 +509,12 @@
 	} else {
 		/*
 		 * since CLS is already filled up with outer protocol rule
-		 * we only update CLS tport here to let matched packet stop by TOPS
+		 * we only update CLS tport here to let matched packet to go through
+		 * QDMA and specify the destination port to TOPS
 		 */
-		CLS_DESC_DATA(&tcls->cls->cdesc, tport_idx, 0x7);
+		CLS_DESC_DATA(&tcls->cls->cdesc, tport_idx, NR_EIP197_QDMA_TPORT);
+		CLS_DESC_DATA(&tcls->cls->cdesc, fport, PSE_PORT_TDMA);
+		CLS_DESC_DATA(&tcls->cls->cdesc, qid, 12);
 	}
 
 cls_entry_write: