blob: 75880edbf8754297f71e53c4e3b9f64448827054 [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);
developer5c851032023-09-04 11:13:18 +080098@@ -2709,6 +2721,14 @@ static unsigned int mtk_hnat_nf_post_rou
99 }
100 }
101
102+ /* we are not support protocols other than IPv4 TCP for crypto offload yet */
103+ if (skb_hnat_is_decrypt(skb)
104+ && (ntohs(skb->protocol) != ETH_P_IP
105+ || ip_hdr(skb)->protocol != IPPROTO_TCP)) {
106+ skb_hnat_alg(skb) = 1;
107+ return 0;
108+ }
109+
110 if (!IS_LAN_GRP(out) && !IS_WAN(out) && !IS_EXT(out))
111 is_virt_dev = true;
112
113@@ -3016,7 +3036,10 @@ mtk_hnat_ipv4_nf_local_out(void *priv, s
developer4f0d2ba2023-08-21 17:33:25 +0800114 if (iph->protocol == IPPROTO_IPV6) {
115 entry->udib1.pkt_type = IPV6_6RD;
116 hnat_set_head_frags(state, skb, 0, hnat_set_alg);
117- } else if (!skb_hnat_tops(skb)) {
118+ } else if (is_magic_tag_valid(skb)
119+ && (skb_hnat_cdrt(skb) || skb_hnat_tops(skb))) {
120+ hnat_set_head_frags(state, skb, 0, hnat_set_alg);
121+ } else {
122 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
123 }
124
125--- a/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
126+++ b/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
127@@ -46,7 +46,8 @@ struct hnat_desc {
128 u32 amsdu : 1;
129 u32 tops : 6;
130 u32 is_decap : 1;
131- u32 resv3 : 12;
132+ u32 cdrt : 8;
133+ u32 resv3 : 4;
134 u32 magic_tag_protect : 16;
135 } __packed;
136 #elif defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
137@@ -99,12 +100,16 @@ struct hnat_desc {
138 #define skb_hnat_is_encap(skb) (!skb_hnat_is_decap(skb))
139 #define skb_hnat_set_tops(skb, tops) ((skb_hnat_tops(skb)) = (tops))
140 #define skb_hnat_set_is_decap(skb, is_decap) ((skb_hnat_is_decap(skb)) = (is_decap))
141+#define skb_hnat_cdrt(skb) (((struct hnat_desc *)((skb)->head))->cdrt)
142+#define skb_hnat_set_cdrt(skb, cdrt) ((skb_hnat_cdrt(skb)) = (cdrt))
143 #else /* !defined(CONFIG_MEDIATEK_NETSYS_V3) */
144 #define skb_hnat_tops(skb) (0)
145 #define skb_hnat_is_decap(skb) (0)
146 #define skb_hnat_is_encap(skb) (0)
147 #define skb_hnat_set_tops(skb, tops)
148 #define skb_hnat_set_is_decap(skb, is_decap)
149+#define skb_hnat_cdrt(skb) (0)
150+#define skb_hnat_set_cdrt(skb, cdrt)
151 #endif /* defined(CONFIG_MEDIATEK_NETSYS_V3) */
152 #define skb_hnat_magic(skb) (((struct hnat_desc *)(skb->head))->magic)
153 #define skb_hnat_reason(skb) (((struct hnat_desc *)(skb->head))->crsn)
154--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
155+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
156@@ -49,6 +49,8 @@ int (*mtk_tnl_decap_offload)(struct sk_b
157 EXPORT_SYMBOL(mtk_tnl_decap_offload);
158 bool (*mtk_tnl_decap_offloadable)(struct sk_buff *skb) = NULL;
159 EXPORT_SYMBOL(mtk_tnl_decap_offloadable);
160+bool (*mtk_crypto_offloadable)(struct sk_buff *skb) = NULL;
161+EXPORT_SYMBOL(mtk_crypto_offloadable);
162
163 static void hnat_sma_build_entry(struct timer_list *t)
164 {
165--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
166+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
167@@ -1087,6 +1087,8 @@ enum FoeIpAct {
168 #define NR_WDMA1_PORT 9
169 #define NR_WDMA2_PORT 13
170 #define NR_GMAC3_PORT 15
171+#define NR_EIP197_TPORT 2
172+#define NR_EIP197_QDMA_TPORT 3
173 #define NR_TDMA_TPORT 4
174 #define NR_TDMA_QDMA_TPORT 5
175 #define LAN_DEV_NAME hnat_priv->lan
176@@ -1233,6 +1235,7 @@ extern int qos_toggle;
177 extern int (*mtk_tnl_encap_offload)(struct sk_buff *skb);
178 extern int (*mtk_tnl_decap_offload)(struct sk_buff *skb);
179 extern bool (*mtk_tnl_decap_offloadable)(struct sk_buff *skb);
180+extern bool (*mtk_crypto_offloadable)(struct sk_buff *skb);
181
182 int ext_if_add(struct extdev_entry *ext_entry);
183 int ext_if_del(struct extdev_entry *ext_entry);