developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 1 | --- 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 |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 13 | @@ -1076,6 +1076,9 @@ static unsigned int hnat_ipv4_get_nextho |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 14 | 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); |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 23 | @@ -1097,7 +1100,7 @@ static unsigned int hnat_ipv4_get_nextho |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 24 | * 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 | } |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 32 | @@ -1105,7 +1108,7 @@ static unsigned int hnat_ipv4_get_nextho |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 33 | 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(); |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 41 | @@ -1299,6 +1302,9 @@ static inline void hnat_fill_offload_eng |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 42 | */ |
| 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 | } |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 51 | @@ -1344,7 +1350,8 @@ static unsigned int skb_to_hnat_info(str |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 52 | 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 | } |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 61 | @@ -1744,7 +1751,8 @@ static unsigned int skb_to_hnat_info(str |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 62 | /* 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: |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 71 | @@ -1950,6 +1958,8 @@ hnat_entry_bind: |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 72 | |
| 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: |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 80 | @@ -2227,6 +2237,7 @@ int mtk_sw_nat_hook_rx(struct sk_buff *s |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 81 | |
| 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) |
developer | 84f378f | 2023-08-24 18:26:50 +0800 | [diff] [blame] | 88 | @@ -2313,7 +2324,8 @@ static unsigned int mtk_hnat_accel_type( |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 89 | * 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); |
developer | 5c85103 | 2023-09-04 11:13:18 +0800 | [diff] [blame] | 98 | @@ -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 |
developer | 4f0d2ba | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 114 | 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); |