[][Add PPPQ_MODE and PPPQ_PATH]

[Description]
Add PPPQ_MODE and PPPQ_PATH for qos_toggle

[Release-log]
N/A


Change-Id: Ie079e60651574b37e2762b29571806a729d983de
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6800513
diff --git a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
index d02a55b..95c7cd6 100644
--- a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
+++ b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
@@ -1103,6 +1103,9 @@
 #define IS_GMAC1_MODE ((hnat_priv->gmac_num == 1) ? 1 : 0)
 #define IS_HQOS_MODE (qos_toggle == 1)
 #define IS_PPPQ_MODE (qos_toggle == 2)		/* Per Port Per Queue */
+#define IS_PPPQ_PATH(dev, skb) \
+	((IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev)) || \
+	 (FROM_WED(skb) && IS_DSA_LAN(dev)))
 #define IS_HQOS_DL_MODE (IS_HQOS_MODE && qos_dl_toggle)
 #define IS_HQOS_UL_MODE (IS_HQOS_MODE && qos_ul_toggle)
 #define MAX_PPPQ_PORT_NUM	6
diff --git a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
index 1857e9b..32711b3 100644
--- a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
+++ b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
@@ -2526,8 +2526,8 @@
 		pr_info("Per-port-per-queue mode is going to be enabled!\n");
 		pr_info("PPPQ use qid 0~5 (scheduler 0).\n");
 		qos_toggle = 2;
-		qos_dl_toggle = 0;
-		qos_ul_toggle = 0;
+		qos_dl_toggle = 1;
+		qos_ul_toggle = 1;
 		hnat_qos_pppq_enable();
 	} else if (buf[0] == '3') {
 		hnat_qos_toggle_usage();
diff --git a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
index 0939f07..ddc8bb5 100644
--- a/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
+++ b/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
@@ -1445,8 +1445,10 @@
 						 hnat_priv->data->version == MTK_HNAT_V5) ?
 						 skb->mark & 0x7f : skb->mark & 0xf;
 #if defined(CONFIG_MEDIATEK_NETSYS_V3)
-					if ((IS_WAN(dev) && IS_HQOS_UL_MODE) ||
-					    (IS_LAN(dev) && IS_HQOS_DL_MODE))
+					if ((IS_HQOS_UL_MODE && IS_WAN(dev)) ||
+					    (IS_HQOS_DL_MODE && IS_LAN(dev)) ||
+					    (IS_PPPQ_MODE &&
+					     IS_PPPQ_PATH(dev, skb)))
 						entry.ipv4_hnapt.tport_id = 1;
 					else
 						entry.ipv4_hnapt.tport_id = 0;
@@ -1572,8 +1574,7 @@
 
 	if (IS_HQOS_MODE || skb->mark >= MAX_PPPQ_PORT_NUM)
 		qid = skb->mark & (MTK_QDMA_TX_MASK);
-	else if (IS_PPPQ_MODE && (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
-		 (FROM_WED(skb) && IS_DSA_LAN(dev))))
+	else if (IS_PPPQ_MODE && IS_PPPQ_PATH(dev, skb))
 		qid = port_id & MTK_QDMA_TX_MASK;
 	else
 		qid = 0;
@@ -1609,16 +1610,18 @@
 				entry.ipv4_hnapt.iblk2.fqos = 0;
 			else
 #if defined(CONFIG_MEDIATEK_NETSYS_V3)
-				if ((IS_WAN(dev) && IS_HQOS_UL_MODE) ||
-					(IS_LAN(dev) && IS_HQOS_DL_MODE))
+				if ((IS_HQOS_UL_MODE && IS_WAN(dev)) ||
+				    (IS_HQOS_DL_MODE && IS_LAN(dev)) ||
+				    (IS_PPPQ_MODE &&
+				     IS_PPPQ_PATH(dev, skb)))
 					entry.ipv4_hnapt.tport_id = 1;
 				else
 					entry.ipv4_hnapt.tport_id = 0;
 #else
 				entry.ipv4_hnapt.iblk2.fqos =
-					(!IS_PPPQ_MODE || (IS_PPPQ_MODE &&
-					 (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
-					 (FROM_WED(skb) && IS_DSA_LAN(dev)))));
+					(!IS_PPPQ_MODE ||
+					(IS_PPPQ_MODE &&
+					 IS_PPPQ_PATH(dev, skb)));
 #endif
 		} else {
 			entry.ipv4_hnapt.iblk2.fqos = 0;
@@ -1653,16 +1656,18 @@
 				entry.ipv6_5t_route.iblk2.fqos = 0;
 			else
 #if defined(CONFIG_MEDIATEK_NETSYS_V3)
-				if ((IS_WAN(dev) && IS_HQOS_UL_MODE) ||
-					(IS_LAN(dev) && IS_HQOS_DL_MODE))
+				if ((IS_HQOS_UL_MODE && IS_WAN(dev)) ||
+					(IS_HQOS_DL_MODE && IS_LAN(dev)) ||
+					(IS_PPPQ_MODE &&
+					 IS_PPPQ_PATH(dev, skb)))
 					entry.ipv6_5t_route.tport_id = 1;
 				else
 					entry.ipv6_5t_route.tport_id = 0;
 #else
 				entry.ipv6_5t_route.iblk2.fqos =
-					(!IS_PPPQ_MODE || (IS_PPPQ_MODE &&
-					 (IS_DSA_1G_LAN(dev) || IS_DSA_WAN(dev) ||
-					 (FROM_WED(skb) && IS_DSA_LAN(dev)))));
+					(!IS_PPPQ_MODE ||
+					 (IS_PPPQ_MODE &&
+					  IS_PPPQ_PATH(dev, skb)));
 #endif
 		} else {
 			entry.ipv6_5t_route.iblk2.fqos = 0;