blob: 360be7231e7af8e26bcf15ad7c23b00525442166 [file] [log] [blame]
developer4f0d2ba2023-08-21 17:33:25 +08001--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
2+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
3@@ -2316,6 +2316,7 @@ static int mtk_poll_rx(struct napi_struc
4
5 skb_hnat_alg(skb) = 0;
6 skb_hnat_filled(skb) = 0;
7+ skb_hnat_set_cdrt(skb, 0);
8 skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
9 skb_hnat_set_tops(skb, 0);
10 skb_hnat_set_is_decap(skb, 0);
11--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
12+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
developer84f378f2023-08-24 18:26:50 +080013@@ -1076,6 +1076,9 @@ static unsigned int hnat_ipv4_get_nextho
developer4f0d2ba2023-08-21 17:33:25 +080014 return 0;
15 }
16
17+ if (!skb_hnat_cdrt(skb) && dst && dst_xfrm(dst))
18+ return 0;
19+
20 rcu_read_lock_bh();
21 nexthop = (__force u32)rt_nexthop(rt, ip_hdr(skb)->daddr);
22 neigh = __ipv4_neigh_lookup_noref(dev, nexthop);
developer84f378f2023-08-24 18:26:50 +080023@@ -1097,7 +1100,7 @@ static unsigned int hnat_ipv4_get_nextho
developer4f0d2ba2023-08-21 17:33:25 +080024 * outer header, we must update its outer mac header pointer
25 * before filling outer mac or it may screw up inner mac
26 */
27- if (skb_hnat_tops(skb) && skb_hnat_is_encap(skb)) {
28+ if ((skb_hnat_tops(skb) && skb_hnat_is_encap(skb)) || skb_hnat_cdrt(skb)) {
29 skb_push(skb, sizeof(struct ethhdr));
30 skb_reset_mac_header(skb);
31 }
developer84f378f2023-08-24 18:26:50 +080032@@ -1105,7 +1108,7 @@ static unsigned int hnat_ipv4_get_nextho
developer4f0d2ba2023-08-21 17:33:25 +080033 memcpy(eth_hdr(skb)->h_dest, neigh->ha, ETH_ALEN);
34 memcpy(eth_hdr(skb)->h_source, out->dev_addr, ETH_ALEN);
35
36- if (skb_hnat_tops(skb) && skb_hnat_is_encap(skb))
37+ if ((skb_hnat_tops(skb) && skb_hnat_is_encap(skb)) || skb_hnat_cdrt(skb))
38 skb_pull(skb, sizeof(struct ethhdr));
39
40 rcu_read_unlock_bh();
developer84f378f2023-08-24 18:26:50 +080041@@ -1299,6 +1302,9 @@ static inline void hnat_fill_offload_eng
developer4f0d2ba2023-08-21 17:33:25 +080042 */
43 entry->ipv4_hnapt.tport_id = NR_TDMA_QDMA_TPORT;
44 entry->ipv4_hnapt.tops_entry = skb_hnat_tops(skb);
45+ } else if (skb_hnat_cdrt(skb)) {
46+ entry->ipv4_hnapt.tport_id = NR_EIP197_QDMA_TPORT;
47+ entry->ipv4_hnapt.cdrt_id = skb_hnat_cdrt(skb);
48 } else {
49 return;
50 }
developer84f378f2023-08-24 18:26:50 +080051@@ -1344,7 +1350,8 @@ static unsigned int skb_to_hnat_info(str
developer4f0d2ba2023-08-21 17:33:25 +080052 if (whnat && is_hnat_pre_filled(foe))
53 return 0;
54
55- if (skb_hnat_tops(skb) && !(hw_path->flags & FLOW_OFFLOAD_PATH_TNL)) {
56+ if ((skb_hnat_tops(skb) && !(hw_path->flags & FLOW_OFFLOAD_PATH_TNL))
57+ || (skb_hnat_cdrt(skb) && skb_dst(skb) && !dst_xfrm(skb_dst(skb)))) {
58 hnat_get_filled_unbind_entry(skb, &entry);
59 goto hnat_entry_bind;
60 }
developer84f378f2023-08-24 18:26:50 +080061@@ -1744,7 +1751,8 @@ static unsigned int skb_to_hnat_info(str
developer4f0d2ba2023-08-21 17:33:25 +080062 /* Fill Layer2 Info.*/
63 entry = ppe_fill_L2_info(eth, entry, hw_path);
64
65- if (skb_hnat_tops(skb) && hw_path->flags & FLOW_OFFLOAD_PATH_TNL)
66+ if ((skb_hnat_tops(skb) && hw_path->flags & FLOW_OFFLOAD_PATH_TNL)
67+ || (!skb_hnat_cdrt(skb) && skb_dst(skb) && dst_xfrm(skb_dst(skb))))
68 goto hnat_entry_skip_bind;
69
70 hnat_entry_bind:
developer84f378f2023-08-24 18:26:50 +080071@@ -1950,6 +1958,8 @@ hnat_entry_bind:
developer4f0d2ba2023-08-21 17:33:25 +080072
73 #if defined(CONFIG_MEDIATEK_NETSYS_V3)
74 hnat_fill_offload_engine_entry(skb, &entry, dev);
75+ if (skb_hnat_cdrt(skb))
76+ entry = ppe_fill_L2_info(eth, entry, hw_path);
77 #endif
78
79 hnat_entry_skip_bind:
developer84f378f2023-08-24 18:26:50 +080080@@ -2227,6 +2237,7 @@ int mtk_sw_nat_hook_rx(struct sk_buff *s
developer4f0d2ba2023-08-21 17:33:25 +080081
82 skb_hnat_alg(skb) = 0;
83 skb_hnat_set_tops(skb, 0);
84+ skb_hnat_set_cdrt(skb, 0);
85 skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
86
87 if (skb_hnat_iface(skb) == FOE_MAGIC_WED0)
developer84f378f2023-08-24 18:26:50 +080088@@ -2313,7 +2324,8 @@ static unsigned int mtk_hnat_accel_type(
developer4f0d2ba2023-08-21 17:33:25 +080089 * is from local_out which is also filtered in sanity check.
90 */
91 dst = skb_dst(skb);
92- if (dst && dst_xfrm(dst))
93+ if (dst && dst_xfrm(dst)
94+ && (!mtk_crypto_offloadable || !mtk_crypto_offloadable(skb)))
95 return 0;
96
97 ct = nf_ct_get(skb, &ctinfo);
developer84f378f2023-08-24 18:26:50 +080098@@ -3005,7 +3017,10 @@ mtk_hnat_ipv4_nf_local_out(void *priv, s
developer4f0d2ba2023-08-21 17:33:25 +080099 if (iph->protocol == IPPROTO_IPV6) {
100 entry->udib1.pkt_type = IPV6_6RD;
101 hnat_set_head_frags(state, skb, 0, hnat_set_alg);
102- } else if (!skb_hnat_tops(skb)) {
103+ } else if (is_magic_tag_valid(skb)
104+ && (skb_hnat_cdrt(skb) || skb_hnat_tops(skb))) {
105+ hnat_set_head_frags(state, skb, 0, hnat_set_alg);
106+ } else {
107 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
108 }
109
110--- a/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
111+++ b/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
112@@ -46,7 +46,8 @@ struct hnat_desc {
113 u32 amsdu : 1;
114 u32 tops : 6;
115 u32 is_decap : 1;
116- u32 resv3 : 12;
117+ u32 cdrt : 8;
118+ u32 resv3 : 4;
119 u32 magic_tag_protect : 16;
120 } __packed;
121 #elif defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
122@@ -99,12 +100,16 @@ struct hnat_desc {
123 #define skb_hnat_is_encap(skb) (!skb_hnat_is_decap(skb))
124 #define skb_hnat_set_tops(skb, tops) ((skb_hnat_tops(skb)) = (tops))
125 #define skb_hnat_set_is_decap(skb, is_decap) ((skb_hnat_is_decap(skb)) = (is_decap))
126+#define skb_hnat_cdrt(skb) (((struct hnat_desc *)((skb)->head))->cdrt)
127+#define skb_hnat_set_cdrt(skb, cdrt) ((skb_hnat_cdrt(skb)) = (cdrt))
128 #else /* !defined(CONFIG_MEDIATEK_NETSYS_V3) */
129 #define skb_hnat_tops(skb) (0)
130 #define skb_hnat_is_decap(skb) (0)
131 #define skb_hnat_is_encap(skb) (0)
132 #define skb_hnat_set_tops(skb, tops)
133 #define skb_hnat_set_is_decap(skb, is_decap)
134+#define skb_hnat_cdrt(skb) (0)
135+#define skb_hnat_set_cdrt(skb, cdrt)
136 #endif /* defined(CONFIG_MEDIATEK_NETSYS_V3) */
137 #define skb_hnat_magic(skb) (((struct hnat_desc *)(skb->head))->magic)
138 #define skb_hnat_reason(skb) (((struct hnat_desc *)(skb->head))->crsn)
139--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
140+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
141@@ -49,6 +49,8 @@ int (*mtk_tnl_decap_offload)(struct sk_b
142 EXPORT_SYMBOL(mtk_tnl_decap_offload);
143 bool (*mtk_tnl_decap_offloadable)(struct sk_buff *skb) = NULL;
144 EXPORT_SYMBOL(mtk_tnl_decap_offloadable);
145+bool (*mtk_crypto_offloadable)(struct sk_buff *skb) = NULL;
146+EXPORT_SYMBOL(mtk_crypto_offloadable);
147
148 static void hnat_sma_build_entry(struct timer_list *t)
149 {
150--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
151+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
152@@ -1087,6 +1087,8 @@ enum FoeIpAct {
153 #define NR_WDMA1_PORT 9
154 #define NR_WDMA2_PORT 13
155 #define NR_GMAC3_PORT 15
156+#define NR_EIP197_TPORT 2
157+#define NR_EIP197_QDMA_TPORT 3
158 #define NR_TDMA_TPORT 4
159 #define NR_TDMA_QDMA_TPORT 5
160 #define LAN_DEV_NAME hnat_priv->lan
161@@ -1233,6 +1235,7 @@ extern int qos_toggle;
162 extern int (*mtk_tnl_encap_offload)(struct sk_buff *skb);
163 extern int (*mtk_tnl_decap_offload)(struct sk_buff *skb);
164 extern bool (*mtk_tnl_decap_offloadable)(struct sk_buff *skb);
165+extern bool (*mtk_crypto_offloadable)(struct sk_buff *skb);
166
167 int ext_if_add(struct extdev_entry *ext_entry);
168 int ext_if_del(struct extdev_entry *ext_entry);