blob: b96f08035b99a4f22f42ceb1905d370568028d66 [file] [log] [blame]
developer84f378f2023-08-24 18:26:50 +08001--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
2+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
developer0fb30d52023-12-04 09:51:36 +08003@@ -1144,6 +1144,8 @@ enum FoeIpAct {
developer84f378f2023-08-24 18:26:50 +08004 #define NR_EIP197_QDMA_TPORT 3
5 #define NR_TDMA_TPORT 4
6 #define NR_TDMA_QDMA_TPORT 5
7+#define NR_TDMA_EIP197_TPORT 8
8+#define NR_TDMA_EIP197_QDMA_TPORT 9
9 #define LAN_DEV_NAME hnat_priv->lan
10 #define LAN2_DEV_NAME hnat_priv->lan2
11 #define IS_WAN(dev) \
12--- a/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
13+++ b/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
developer960614b2023-11-03 18:27:24 +080014@@ -1101,7 +1101,8 @@ static unsigned int hnat_ipv4_get_nextho
developer84f378f2023-08-24 18:26:50 +080015 * outer header, we must update its outer mac header pointer
16 * before filling outer mac or it may screw up inner mac
17 */
developerdca80e32023-10-19 16:24:46 +080018- if (skb_hnat_tops(skb) && skb_hnat_is_encap(skb)) {
developer84f378f2023-08-24 18:26:50 +080019+ if ((skb_hnat_tops(skb) && skb_hnat_is_encap(skb))
20+ || (skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb))) {
21 skb_push(skb, sizeof(struct ethhdr));
22 skb_reset_mac_header(skb);
23 }
developer0fb30d52023-12-04 09:51:36 +080024@@ -1110,7 +1111,8 @@ static unsigned int hnat_ipv4_get_nextho
developer84f378f2023-08-24 18:26:50 +080025 memcpy(eth_hdr(skb)->h_source, out->dev_addr, ETH_ALEN);
developer0fb30d52023-12-04 09:51:36 +080026 eth_hdr(skb)->h_proto = htons(ETH_P_IP);
developer84f378f2023-08-24 18:26:50 +080027
developerdca80e32023-10-19 16:24:46 +080028- if (skb_hnat_tops(skb) && skb_hnat_is_encap(skb))
developer84f378f2023-08-24 18:26:50 +080029+ if ((skb_hnat_tops(skb) && skb_hnat_is_encap(skb))
30+ || (skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb)))
31 skb_pull(skb, sizeof(struct ethhdr));
32
33 rcu_read_unlock_bh();
developer0fb30d52023-12-04 09:51:36 +080034@@ -1258,6 +1260,38 @@ static inline void hnat_get_filled_unbin
developer84f378f2023-08-24 18:26:50 +080035 entry->bfib1.ps = 0;
36 }
37
38+/*
39+ * check offload engine data is prepared
40+ * return 0 for packets not related to offload engine
41+ * return positive value for offload engine prepared data done
42+ * return negative value for data is still constructing
43+ */
44+static inline int hnat_offload_engine_done(struct sk_buff *skb,
45+ struct flow_offload_hw_path *hw_path)
46+{
47+ struct dst_entry *dst = skb_dst(skb);
48+
49+ if ((skb_hnat_tops(skb) && !(hw_path->flags & FLOW_OFFLOAD_PATH_TNL))) {
50+ /* tunnel encap'ed */
51+ if (dst && dst_xfrm(dst))
52+ /*
53+ * skb not ready to bind since it is still needs
54+ * to be encrypted
55+ */
56+ return -1;
57+
58+ /* nothing need to be done further for this skb */
59+ return 1;
60+ }
61+
62+ if (skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb) && dst && !dst_xfrm(dst))
63+ /* crypto encrypted done */
64+ return 1;
65+
66+ /* no need for tunnel encapsulation or crypto encryption */
67+ return 0;
68+}
69+
70 static inline void hnat_qos_tnl(u32 id, const struct net_device *dev)
71 {
72 u32 cfg;
developer0fb30d52023-12-04 09:51:36 +080073@@ -1302,9 +1336,15 @@ static inline void hnat_fill_offload_eng
developer84f378f2023-08-24 18:26:50 +080074 * we fill in hnat tport and tops_entry for tunnel encapsulation
75 * offloading
76 */
77- entry->ipv4_hnapt.tport_id = NR_TDMA_QDMA_TPORT;
78+ if (skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb)) {
79+ entry->ipv4_hnapt.tport_id = NR_TDMA_EIP197_QDMA_TPORT;
80+ entry->ipv4_hnapt.cdrt_id = skb_hnat_cdrt(skb);
81+ } else {
82+ entry->ipv4_hnapt.tport_id = NR_TDMA_QDMA_TPORT;
83+ }
84 entry->ipv4_hnapt.tops_entry = skb_hnat_tops(skb);
85- } else if (skb_hnat_cdrt(skb)) {
86+
87+ } else if (skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb)) {
88 entry->ipv4_hnapt.tport_id = NR_EIP197_QDMA_TPORT;
89 entry->ipv4_hnapt.cdrt_id = skb_hnat_cdrt(skb);
90 } else {
developer0fb30d52023-12-04 09:51:36 +080091@@ -1405,6 +1445,7 @@ static unsigned int skb_to_hnat_info(str
developer84f378f2023-08-24 18:26:50 +080092 u32 port_id = 0;
93 u32 payload_len = 0;
94 int mape = 0;
95+ int ret;
developer960614b2023-11-03 18:27:24 +080096 struct mtk_mac *mac = netdev_priv(dev);
developer84f378f2023-08-24 18:26:50 +080097
98 ct = nf_ct_get(skb, &ctinfo);
developer0fb30d52023-12-04 09:51:36 +080099@@ -1422,9 +1463,12 @@ static unsigned int skb_to_hnat_info(str
developer84f378f2023-08-24 18:26:50 +0800100 if (whnat && is_hnat_pre_filled(foe))
101 return 0;
102
developerdca80e32023-10-19 16:24:46 +0800103- if (skb_hnat_tops(skb) && !(hw_path->flags & FLOW_OFFLOAD_PATH_TNL)) {
developer84f378f2023-08-24 18:26:50 +0800104+ ret = hnat_offload_engine_done(skb, hw_path);
105+ if (ret == 1) {
106 hnat_get_filled_unbind_entry(skb, &entry);
107 goto hnat_entry_bind;
108+ } else if (ret == -1) {
109+ return 0;
110 }
111
112 entry.bfib1.pkt_type = foe->udib1.pkt_type; /* Get packte type state*/
developer0fb30d52023-12-04 09:51:36 +0800113@@ -1870,7 +1914,9 @@ static unsigned int skb_to_hnat_info(str
developerdca80e32023-10-19 16:24:46 +0800114 /* Fill Layer2 Info.*/
developer84f378f2023-08-24 18:26:50 +0800115 entry = ppe_fill_L2_info(eth, entry, hw_path);
116
developerdca80e32023-10-19 16:24:46 +0800117- if (skb_hnat_tops(skb) && hw_path->flags & FLOW_OFFLOAD_PATH_TNL)
118+ if ((skb_hnat_tops(skb) && hw_path->flags & FLOW_OFFLOAD_PATH_TNL)
developer84f378f2023-08-24 18:26:50 +0800119+ || (!skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb)
developerdca80e32023-10-19 16:24:46 +0800120+ && skb_dst(skb) && dst_xfrm(skb_dst(skb))))
developer84f378f2023-08-24 18:26:50 +0800121 goto hnat_entry_skip_bind;
122
123 hnat_entry_bind:
developer0fb30d52023-12-04 09:51:36 +0800124@@ -2435,6 +2481,7 @@ int mtk_sw_nat_hook_rx(struct sk_buff *s
developer84f378f2023-08-24 18:26:50 +0800125 skb_hnat_alg(skb) = 0;
126 skb_hnat_set_tops(skb, 0);
127 skb_hnat_set_cdrt(skb, 0);
128+ skb_hnat_set_is_decrypt(skb, 0);
129 skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
130
131 if (skb_hnat_iface(skb) == FOE_MAGIC_WED0)
developer0fb30d52023-12-04 09:51:36 +0800132@@ -3244,7 +3291,8 @@ mtk_hnat_ipv4_nf_local_out(void *priv, s
developer84f378f2023-08-24 18:26:50 +0800133 entry->udib1.pkt_type = IPV6_6RD;
134 hnat_set_head_frags(state, skb, 0, hnat_set_alg);
135 } else if (is_magic_tag_valid(skb)
136- && (skb_hnat_cdrt(skb) || skb_hnat_tops(skb))) {
137+ && ((skb_hnat_cdrt(skb) && skb_hnat_is_encrypt(skb))
138+ || skb_hnat_tops(skb))) {
139 hnat_set_head_frags(state, skb, 0, hnat_set_alg);
140 } else {
141 hnat_set_head_frags(state, skb, 1, hnat_set_alg);
142--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
143+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
developer0fb30d52023-12-04 09:51:36 +0800144@@ -2324,10 +2324,11 @@ static int mtk_poll_rx(struct napi_struc
developer84f378f2023-08-24 18:26:50 +0800145
146 skb_hnat_alg(skb) = 0;
147 skb_hnat_filled(skb) = 0;
148- skb_hnat_set_cdrt(skb, 0);
149+ skb_hnat_set_cdrt(skb, RX_DMA_GET_CDRT(trxd.rxd7));
150 skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG;
151 skb_hnat_set_tops(skb, 0);
152 skb_hnat_set_is_decap(skb, 0);
developera78fb922023-09-04 09:48:45 +0800153+ skb_hnat_set_is_decrypt(skb, (skb_hnat_cdrt(skb) ? 1 : 0));
developer84f378f2023-08-24 18:26:50 +0800154
developer84f378f2023-08-24 18:26:50 +0800155 if (skb_hnat_reason(skb) == HIT_BIND_FORCE_TO_CPU) {
156 trace_printk("[%s] reason=0x%x(force to CPU) from WAN to Ext\n",
developer84f378f2023-08-24 18:26:50 +0800157--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
158+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
developer0fb30d52023-12-04 09:51:36 +0800159@@ -656,6 +656,9 @@
developer84f378f2023-08-24 18:26:50 +0800160 #define RX_DMA_GET_AGG_CNT_V2(_x) (((_x) >> 16) & 0xff)
161 #define RX_DMA_GET_TOPS_CRSN(_x) (((_x) >> 24) & 0xff)
162
163+/* PDMA V2 descriptor rxd7 */
164+#define RX_DMA_GET_CDRT(_x) (((_x) >> 8) & 0xff)
165+
166 /* PHY Polling and SMI Master Control registers */
167 #define MTK_PPSC 0x10000
168 #define PPSC_MDC_CFG GENMASK(29, 24)
169--- a/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
170+++ b/drivers/net/ethernet/mediatek/mtk_hnat/nf_hnat_mtk.h
171@@ -47,7 +47,8 @@ struct hnat_desc {
172 u32 tops : 6;
173 u32 is_decap : 1;
174 u32 cdrt : 8;
175- u32 resv3 : 4;
176+ u32 is_decrypt : 1;
177+ u32 resv3 : 3;
178 u32 magic_tag_protect : 16;
179 } __packed;
180 #elif defined(CONFIG_MEDIATEK_NETSYS_RX_V2)
181@@ -101,7 +102,10 @@ struct hnat_desc {
182 #define skb_hnat_set_tops(skb, tops) ((skb_hnat_tops(skb)) = (tops))
183 #define skb_hnat_set_is_decap(skb, is_decap) ((skb_hnat_is_decap(skb)) = (is_decap))
184 #define skb_hnat_cdrt(skb) (((struct hnat_desc *)((skb)->head))->cdrt)
185+#define skb_hnat_is_decrypt(skb) (((struct hnat_desc *)((skb)->head))->is_decrypt)
186+#define skb_hnat_is_encrypt(skb) (!skb_hnat_is_decrypt(skb))
187 #define skb_hnat_set_cdrt(skb, cdrt) ((skb_hnat_cdrt(skb)) = (cdrt))
188+#define skb_hnat_set_is_decrypt(skb, is_dec) ((skb_hnat_is_decrypt(skb)) = is_dec)
189 #else /* !defined(CONFIG_MEDIATEK_NETSYS_V3) */
190 #define skb_hnat_tops(skb) (0)
191 #define skb_hnat_is_decap(skb) (0)
192@@ -109,7 +113,10 @@ struct hnat_desc {
193 #define skb_hnat_set_tops(skb, tops)
194 #define skb_hnat_set_is_decap(skb, is_decap)
195 #define skb_hnat_cdrt(skb) (0)
196+#define skb_hnat_is_decrypt(skb) (0)
197+#define skb_hnat_is_encrypt(skb) (0)
198 #define skb_hnat_set_cdrt(skb, cdrt)
199+#define skb_hnat_set_is_decrypt(skb, is_dec)
200 #endif /* defined(CONFIG_MEDIATEK_NETSYS_V3) */
201 #define skb_hnat_magic(skb) (((struct hnat_desc *)(skb->head))->magic)
202 #define skb_hnat_reason(skb) (((struct hnat_desc *)(skb->head))->crsn)