[][openwrt][mt7988][crypto][Refactor tport setting for packets to EIP197]

[Description]
Refactor tport setting for packets to EIP197.
In previous version, we use skb_hnat_cdrt and magic tag to determine
whether a packet should be send to EIP197. However, for packets that
performed segement in GSO, headroom data is not consistent with the
original packet. To ensure that only inline mode packets be sent to
EIP197. We use skb->inner_protocol for determination in this patch.
XFRM callback function for inline mode will set the skb->inner_protocol.

[Release-log]
N/A


Change-Id: I6ef1d7f2044ead78d8a756bc012226573758069d
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8494301
diff --git a/package-21.02/kernel/crypto-eip/src/xfrm-offload.c b/package-21.02/kernel/crypto-eip/src/xfrm-offload.c
index ba89eda..99bbfee 100644
--- a/package-21.02/kernel/crypto-eip/src/xfrm-offload.c
+++ b/package-21.02/kernel/crypto-eip/src/xfrm-offload.c
@@ -351,6 +351,14 @@
 	skb->dev = dst->dev;
 	/* Set magic tag for tport setting, reset to 0 after tport is set */
 	skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
+
+	/*
+	 * Since skb headroom may not be copy when segment, we cannot rely on
+	 * headroom data (ex. cdrt) to decide packets should send to EIP197.
+	 * Here is a workaround that only skb with inner_protocol = ESP will
+	 * be sent to EIP197.
+	 */
+	skb->inner_protocol = IPPROTO_ESP;
 	/*
 	 * Tx packet to EIP197.
 	 * To avoid conflict of SW and HW sequence number
diff --git a/target/linux/mediatek/patches-5.4/999-4102-mtk-crypto-offload-support.patch b/target/linux/mediatek/patches-5.4/999-4102-mtk-crypto-offload-support.patch
index 455ff04..e62c331 100644
--- a/target/linux/mediatek/patches-5.4/999-4102-mtk-crypto-offload-support.patch
+++ b/target/linux/mediatek/patches-5.4/999-4102-mtk-crypto-offload-support.patch
@@ -1,25 +1,25 @@
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
-@@ -1857,6 +1857,12 @@ static void mtk_tx_set_dma_desc_v3(struc
+@@ -1856,6 +1856,12 @@ static void mtk_tx_set_dma_desc_v3(struc
  
  	trace_printk("[%s] skb_shinfo(skb)->nr_frags=%x HNAT_SKB_CB2(skb)->magic=%x txd4=%x<-----\n",
  		     __func__, skb_shinfo(skb)->nr_frags, HNAT_SKB_CB2(skb)->magic, data);
 +
 +	/* forward to eip197 if this packet is going to encrypt */
-+	if (unlikely(skb_hnat_cdrt(skb) && is_magic_tag_valid(skb))) {
++	if (unlikely(skb->inner_protocol == IPPROTO_ESP && skb_hnat_cdrt(skb) && is_magic_tag_valid(skb))) {
 +		data &= ((~TX_DMA_TPORT_MASK) << TX_DMA_TPORT_SHIFT);
 +		data |= (EIP197_QDMA_TPORT & TX_DMA_TPORT_MASK) << TX_DMA_TPORT_SHIFT;
 +	}
  #endif
  	WRITE_ONCE(desc->txd4, data);
  
-@@ -1880,6 +1886,17 @@ static void mtk_tx_set_dma_desc_v3(struc
+@@ -1879,6 +1885,17 @@ static void mtk_tx_set_dma_desc_v3(struc
  
  	WRITE_ONCE(desc->txd7, 0);
  	WRITE_ONCE(desc->txd8, 0);
 +
 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
-+	if (unlikely(skb_hnat_cdrt(skb) && is_magic_tag_valid(skb))) {
++	if (unlikely(skb->inner_protocol == IPPROTO_ESP &&skb_hnat_cdrt(skb) && is_magic_tag_valid(skb))) {
 +		/* carry cdrt index for encryption */
 +		data = (skb_hnat_cdrt(skb) & TX_DMA_CDRT_MASK) << TX_DMA_CDRT_SHIFT;
 +		WRITE_ONCE(desc->txd8, data);
@@ -31,7 +31,7 @@
  }
  
  static void mtk_tx_set_dma_desc(struct sk_buff *skb, struct net_device *dev, void *txd,
-@@ -2307,6 +2324,7 @@ static int mtk_poll_rx(struct napi_struc
+@@ -2308,6 +2325,7 @@ static int mtk_poll_rx(struct napi_struc
  
  		skb_hnat_alg(skb) = 0;
  		skb_hnat_filled(skb) = 0;