| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 | 
|  | 2 | * | 
|  | 3 | * Copyright (c) 2019 MediaTek Inc. | 
|  | 4 | * Author: Harry Huang <harry.huang@mediatek.com> | 
|  | 5 | */ | 
|  | 6 |  | 
|  | 7 | #ifndef _RA_NAT_WANTED | 
|  | 8 | #define _RA_NAT_WANTED | 
|  | 9 |  | 
|  | 10 | #include <linux/ip.h> | 
|  | 11 | #include <linux/ipv6.h> | 
|  | 12 |  | 
|  | 13 |  | 
|  | 14 | #ifndef NEXTHDR_IPIP | 
|  | 15 | #define NEXTHDR_IPIP 4 | 
|  | 16 | #endif | 
|  | 17 |  | 
|  | 18 | #define hwnat_vlan_tx_tag_present(__skb)     ((__skb)->vlan_tci & VLAN_TAG_PRESENT) | 
|  | 19 | #define hwnat_vlan_tag_get(__skb)         ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) | 
|  | 20 |  | 
|  | 21 | #if defined(CONFIG_HW_NAT) | 
|  | 22 | extern void hwnat_magic_tag_set_zero(struct sk_buff *skb); | 
|  | 23 | extern void hwnat_check_magic_tag(struct sk_buff *skb); | 
|  | 24 | extern void hwnat_set_headroom_zero(struct sk_buff *skb); | 
|  | 25 | extern void hwnat_set_tailroom_zero(struct sk_buff *skb); | 
|  | 26 | extern void hwnat_copy_headroom(u8 *data, struct sk_buff *skb); | 
|  | 27 | extern void hwnat_copy_tailroom(u8 *data, int size, struct sk_buff *skb); | 
|  | 28 | extern void hwnat_setup_dma_ops(struct device *dev, bool coherent); | 
|  | 29 | #else | 
|  | 30 |  | 
|  | 31 | static inline void hwnat_magic_tag_set_zero(struct sk_buff *skb) | 
|  | 32 | { | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | static inline void hwnat_check_magic_tag(struct sk_buff *skb) | 
|  | 36 | { | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | static inline void hwnat_set_headroom_zero(struct sk_buff *skb) | 
|  | 40 | { | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | static inline void hwnat_set_tailroom_zero(struct sk_buff *skb) | 
|  | 44 | { | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | static inline void hwnat_copy_headroom(u8 *data, struct sk_buff *skb) | 
|  | 48 | { | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | static inline void hwnat_copy_tailroom(u8 *data, int size, struct sk_buff *skb) | 
|  | 52 | { | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | #endif | 
|  | 56 | enum foe_cpu_reason { | 
|  | 57 | TTL_0 = 0x02,		/* IPv4(IPv6) TTL(hop limit) = 0 */ | 
|  | 58 | /* IPv4(IPv6) has option(extension) header */ | 
|  | 59 | HAS_OPTION_HEADER = 0x03, | 
|  | 60 | NO_FLOW_IS_ASSIGNED = 0x07,	/* No flow is assigned */ | 
|  | 61 | /* IPv4 HNAT doesn't support IPv4 /w fragment */ | 
|  | 62 | IPV4_WITH_FRAGMENT = 0x08, | 
|  | 63 | /* IPv4 HNAPT/DS-Lite doesn't support IPv4 /w fragment */ | 
|  | 64 | IPV4_HNAPT_DSLITE_WITH_FRAGMENT = 0x09, | 
|  | 65 | /* IPv4 HNAPT/DS-Lite can't find TCP/UDP sport/dport */ | 
|  | 66 | IPV4_HNAPT_DSLITE_WITHOUT_TCP_UDP = 0x0A, | 
|  | 67 | /* IPv6 5T-route/6RD can't find TCP/UDP sport/dport */ | 
|  | 68 | IPV6_5T_6RD_WITHOUT_TCP_UDP = 0x0B, | 
|  | 69 | /* Ingress packet is TCP fin/syn/rst */ | 
|  | 70 | /*(for IPv4 NAPT/DS-Lite or IPv6 5T-route/6RD) */ | 
|  | 71 | TCP_FIN_SYN_RST = 0x0C, | 
|  | 72 | UN_HIT = 0x0D,		/* FOE Un-hit */ | 
|  | 73 | HIT_UNBIND = 0x0E,	/* FOE Hit unbind */ | 
|  | 74 | /* FOE Hit unbind & rate reach */ | 
|  | 75 | HIT_UNBIND_RATE_REACH = 0x0F, | 
|  | 76 | HIT_BIND_TCP_FIN = 0x10,	/* Hit bind PPE TCP FIN entry */ | 
|  | 77 | /* Hit bind PPE entry and TTL(hop limit) = 1 */ | 
|  | 78 | /* and TTL(hot limit) - 1 */ | 
|  | 79 | HIT_BIND_TTL_1 = 0x11, | 
|  | 80 | /* Hit bind and VLAN replacement violation */ | 
|  | 81 | /*(Ingress 1(0) VLAN layers and egress 4(3 or 4) VLAN layers) */ | 
|  | 82 | HIT_BIND_WITH_VLAN_VIOLATION = 0x12, | 
|  | 83 | /* Hit bind and keep alive with unicast old-header packet */ | 
|  | 84 | HIT_BIND_KEEPALIVE_UC_OLD_HDR = 0x13, | 
|  | 85 | /* Hit bind and keep alive with multicast new-header packet */ | 
|  | 86 | HIT_BIND_KEEPALIVE_MC_NEW_HDR = 0x14, | 
|  | 87 | /* Hit bind and keep alive with duplicate old-header packet */ | 
|  | 88 | HIT_BIND_KEEPALIVE_DUP_OLD_HDR = 0x15, | 
|  | 89 | /* FOE Hit bind & force to CPU */ | 
|  | 90 | HIT_BIND_FORCE_TO_CPU = 0x16, | 
|  | 91 | /* Hit bind and remove tunnel IP header, */ | 
|  | 92 | /* but inner IP has option/next header */ | 
|  | 93 | HIT_BIND_WITH_OPTION_HEADER = 0x17, | 
|  | 94 | /* Hit bind and exceed MTU */ | 
|  | 95 | HIT_BIND_EXCEED_MTU = 0x1C, | 
|  | 96 | HIT_BIND_PACKET_SAMPLING = 0x1B,	/*  PS packet */ | 
|  | 97 | /*  Switch clone multicast packet to CPU */ | 
|  | 98 | HIT_BIND_MULTICAST_TO_CPU = 0x18, | 
|  | 99 | /*  Switch clone multicast packet to GMAC1 & CPU */ | 
|  | 100 | HIT_BIND_MULTICAST_TO_GMAC_CPU = 0x19, | 
|  | 101 | HIT_PRE_BIND = 0x1A	/*  Pre-bind */ | 
|  | 102 | }; | 
|  | 103 |  | 
|  | 104 | #define MAX_IF_NUM 64 | 
|  | 105 |  | 
|  | 106 | struct dmad_rx_descinfo4 { | 
|  | 107 | uint32_t foe_entry_num:15; | 
|  | 108 | uint32_t rsv0:3; | 
|  | 109 | uint32_t CRSN:5; | 
|  | 110 | uint32_t rsv1:3; | 
|  | 111 | uint32_t SPORT:4; | 
|  | 112 | uint32_t ppe:1; | 
|  | 113 | uint32_t ALG:1; | 
|  | 114 | uint32_t IF:8; | 
|  | 115 | uint32_t WDMAID:2; | 
|  | 116 | uint32_t RXID:2; | 
|  | 117 | uint32_t WCID:10; | 
|  | 118 | uint32_t BSSID:6; | 
|  | 119 | uint32_t rsv3:4; | 
|  | 120 | uint16_t minfo:1; | 
|  | 121 | uint16_t ntype:3; | 
|  | 122 | uint16_t chid:8; | 
|  | 123 | uint16_t rsv4:4; | 
|  | 124 | u16 MAGIC_TAG_PROTECT; | 
|  | 125 | } __packed; | 
|  | 126 |  | 
|  | 127 | struct pdma_rx_desc_info4 { | 
|  | 128 | u16 MAGIC_TAG_PROTECT; | 
|  | 129 | uint32_t foe_entry_num:14; | 
|  | 130 | uint32_t CRSN:5; | 
|  | 131 | uint32_t SPORT:4; | 
|  | 132 | uint32_t rsv:6; | 
|  | 133 | uint32_t foe_entry_num_1:1; | 
|  | 134 | uint32_t ppe:1; | 
|  | 135 | uint32_t ALG:1; | 
|  | 136 | uint32_t IF:8; | 
|  | 137 | uint32_t WDMAID:2; | 
|  | 138 | uint32_t RXID:2; | 
|  | 139 | uint32_t WCID:10; | 
|  | 140 | uint32_t BSSID:6; | 
|  | 141 | uint32_t rsv2:4; | 
|  | 142 | uint16_t minfo:1; | 
|  | 143 | uint16_t ntype:3; | 
|  | 144 | uint16_t chid:8; | 
|  | 145 | uint16_t rsv3:4; | 
|  | 146 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 147 | u16 SOURCE; | 
|  | 148 | u16 DEST; | 
|  | 149 | #endif | 
|  | 150 | } __packed; | 
|  | 151 |  | 
|  | 152 | struct head_rx_descinfo4 { | 
|  | 153 | uint32_t foe_entry_num:14; | 
|  | 154 | uint32_t CRSN:5; | 
|  | 155 | uint32_t SPORT:4; | 
|  | 156 | uint32_t rsv:6; | 
|  | 157 | uint32_t foe_entry_num_1:1; | 
|  | 158 | uint32_t ppe:1; | 
|  | 159 | uint32_t ALG:1; | 
|  | 160 | uint32_t IF:8; | 
|  | 161 | uint32_t WDMAID:2; | 
|  | 162 | uint32_t RXID:2; | 
|  | 163 | uint32_t WCID:10; | 
|  | 164 | uint32_t BSSID:6; | 
|  | 165 | uint32_t rsv2:4; | 
|  | 166 | uint16_t minfo:1; | 
|  | 167 | uint16_t ntype:3; | 
|  | 168 | uint16_t chid:8; | 
|  | 169 | uint16_t rsv3:4; | 
|  | 170 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 171 | u16 SOURCE; | 
|  | 172 | u16 DEST; | 
|  | 173 | #endif | 
|  | 174 | u16 MAGIC_TAG_PROTECT; | 
|  | 175 | } __packed; | 
|  | 176 |  | 
|  | 177 | struct cb_rx_desc_info4 { | 
|  | 178 | u16 MAGIC_TAG_PROTECT0; | 
|  | 179 | uint32_t foe_entry_num:15; | 
|  | 180 | uint32_t CRSN:5; | 
|  | 181 | uint32_t SPORT:4; | 
|  | 182 | uint32_t ALG:1; | 
|  | 183 | uint32_t rsv:7; | 
|  | 184 | uint16_t IF:8; | 
|  | 185 | uint16_t WDMAID:2; | 
|  | 186 | uint16_t RXID:2; | 
|  | 187 | uint16_t WCID:10; | 
|  | 188 | uint16_t BSSID:6; | 
|  | 189 | uint16_t rsv1:4; | 
|  | 190 | uint16_t minfo:1; | 
|  | 191 | uint16_t ntype:3; | 
|  | 192 | uint16_t chid:8; | 
|  | 193 | uint16_t rsv2:4; | 
|  | 194 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 195 | u16 SOURCE; | 
|  | 196 | u16 DEST; | 
|  | 197 | #endif | 
|  | 198 | u16 MAGIC_TAG_PROTECT1; | 
|  | 199 | } __packed; | 
|  | 200 |  | 
|  | 201 |  | 
|  | 202 |  | 
|  | 203 | #define FOE_INFO_LEN		    12 | 
|  | 204 | #define WIFI_INFO_LEN		    6 | 
|  | 205 |  | 
|  | 206 |  | 
|  | 207 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 208 | #define FOE_INFO_LEN		    (6 + 4 + WIFI_INFO_LEN) | 
|  | 209 | #define FOE_MAGIC_FASTPATH	    0x77 | 
|  | 210 | #define FOE_MAGIC_L2TPPATH	    0x78 | 
|  | 211 | #endif | 
|  | 212 |  | 
|  | 213 | #define FOE_MAGIC_PCI		    0x73 | 
|  | 214 | #define FOE_MAGIC_WLAN		    0x74 | 
|  | 215 | #define FOE_MAGIC_GE		    0x75 | 
|  | 216 | #define FOE_MAGIC_PPE		    0x76 | 
|  | 217 | #define FOE_MAGIC_WED0		    0x78 | 
|  | 218 | #define FOE_MAGIC_WED1		    0x79 | 
|  | 219 | #define FOE_MAGIC_MED		    0x80 | 
|  | 220 | #define FOE_MAGIC_EDMA0		    0x81 | 
|  | 221 | #define FOE_MAGIC_EDMA1		    0x82 | 
|  | 222 | #define FOE_MAGIC_PPE0		    0x83 | 
|  | 223 | #define FOE_MAGIC_PPE1		    0x84 | 
|  | 224 | #define FOE_MAGIC_EDMARX	    0x85 | 
|  | 225 | #define FOE_MAGIC_RNDIS		    0x86 | 
| xj | 112b967 | 2022-01-25 16:13:48 +0800 | [diff] [blame] | 226 | #define FOE_MAGIC_SNPS		    0x87 | 
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 227 | #define TAG_PROTECT                 0x6789 | 
|  | 228 | #define USE_HEAD_ROOM               0 | 
|  | 229 | #define USE_TAIL_ROOM               1 | 
|  | 230 | #define USE_CB                      2 | 
|  | 231 | #define ALL_INFO_ERROR              3 | 
|  | 232 |  | 
|  | 233 | /**************************DMAD FORMAT********************************/ | 
|  | 234 | #define FOE_TAG_PROTECT(skb)  \ | 
|  | 235 | (((struct dmad_rx_descinfo4 *)((skb)->head))->MAGIC_TAG_PROTECT) | 
|  | 236 |  | 
|  | 237 | #define FOE_ENTRY_NUM(skb)  \ | 
|  | 238 | (((struct dmad_rx_descinfo4 *)((skb)->head))->foe_entry_num) | 
|  | 239 | #define FOE_ALG(skb)  \ | 
|  | 240 | (((struct dmad_rx_descinfo4 *)((skb)->head))->ALG) | 
|  | 241 | #define FOE_AI(skb)  \ | 
|  | 242 | (((struct dmad_rx_descinfo4 *)((skb)->head))->CRSN) | 
|  | 243 | #define FOE_SP(skb)  \ | 
|  | 244 | (((struct dmad_rx_descinfo4 *)((skb)->head))->SPORT) | 
|  | 245 | #define FOE_MAGIC_TAG(skb)  \ | 
|  | 246 | (((struct dmad_rx_descinfo4 *)((skb)->head))->IF) | 
|  | 247 | #define FOE_WDMA_ID(skb)  \ | 
|  | 248 | (((struct dmad_rx_descinfo4 *)((skb)->head))->WDMAID) | 
|  | 249 | #define FOE_RX_ID(skb)	(((struct dmad_rx_descinfo4 *)((skb)->head))->RXID) | 
|  | 250 | #define FOE_WC_ID(skb)	(((struct dmad_rx_descinfo4 *)((skb)->head))->WCID) | 
|  | 251 | #define FOE_BSS_ID(skb)	(((struct dmad_rx_descinfo4 *)((skb)->head))->BSSID) | 
|  | 252 | #define FOE_PPE(skb)	(((struct dmad_rx_descinfo4 *)((skb)->head))->ppe) | 
|  | 253 |  | 
|  | 254 | /***********************HEAD FORMAT*************************************/ | 
|  | 255 |  | 
|  | 256 | #define FOE_TAG_PROTECT_HEAD(skb)  \ | 
|  | 257 | (((struct head_rx_descinfo4 *)((skb)->head))->MAGIC_TAG_PROTECT) | 
|  | 258 | #define FOE_ENTRY_NUM_LSB_HEAD(skb)  \ | 
|  | 259 | (((struct head_rx_descinfo4 *)((skb)->head))->foe_entry_num) | 
|  | 260 | #define FOE_ENTRY_NUM_MSB_HEAD(skb)  \ | 
|  | 261 | (((struct head_rx_descinfo4 *)((skb)->head))->foe_entry_num_1) | 
|  | 262 |  | 
|  | 263 | #define FOE_ENTRY_NUM_HEAD(skb)  \ | 
|  | 264 | (((FOE_ENTRY_NUM_MSB_HEAD(skb) & 0x1) << 14) | FOE_ENTRY_NUM_LSB_HEAD(skb)) | 
|  | 265 |  | 
|  | 266 |  | 
|  | 267 | #define FOE_ALG_HEAD(skb)  \ | 
|  | 268 | (((struct head_rx_descinfo4 *)((skb)->head))->ALG) | 
|  | 269 | #define FOE_AI_HEAD(skb)  \ | 
|  | 270 | (((struct head_rx_descinfo4 *)((skb)->head))->CRSN) | 
|  | 271 | #define FOE_SP_HEAD(skb)  \ | 
|  | 272 | (((struct head_rx_descinfo4 *)((skb)->head))->SPORT) | 
|  | 273 | #define FOE_MAGIC_TAG_HEAD(skb)  \ | 
|  | 274 | (((struct head_rx_descinfo4 *)((skb)->head))->IF) | 
|  | 275 |  | 
|  | 276 |  | 
|  | 277 | #define FOE_WDMA_ID_HEAD(skb)  \ | 
|  | 278 | (((struct head_rx_descinfo4 *)((skb)->head))->WDMAID) | 
|  | 279 | #define FOE_RX_ID_HEAD(skb)  \ | 
|  | 280 | (((struct head_rx_descinfo4 *)((skb)->head))->RXID) | 
|  | 281 | #define FOE_WC_ID_HEAD(skb)  \ | 
|  | 282 | (((struct head_rx_descinfo4 *)((skb)->head))->WCID) | 
|  | 283 | #define FOE_BSS_ID_HEAD(skb)  \ | 
|  | 284 | (((struct head_rx_descinfo4 *)((skb)->head))->BSSID) | 
|  | 285 | #define FOE_PPE_HEAD(skb)  \ | 
|  | 286 | (((struct head_rx_descinfo4 *)((skb)->head))->PPE) | 
|  | 287 |  | 
|  | 288 | /****************************TAIL FORMAT***************************************/ | 
|  | 289 | #define FOE_TAG_PROTECT_TAIL(skb)  \ | 
|  | 290 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->MAGIC_TAG_PROTECT) | 
|  | 291 | #define FOE_ENTRY_NUM_LSB_TAIL(skb)  \ | 
|  | 292 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->foe_entry_num) | 
|  | 293 |  | 
|  | 294 | #define FOE_ENTRY_NUM_MSB_TAIL(skb)  \ | 
|  | 295 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->foe_entry_num_1) | 
|  | 296 | #define FOE_ENTRY_NUM_TAIL(skb)  \ | 
|  | 297 | (((FOE_ENTRY_NUM_MSB_TAIL(skb) & 0x1) << 14) | FOE_ENTRY_NUM_LSB_TAIL(skb)) | 
|  | 298 | #define FOE_ALG_TAIL(skb)  \ | 
|  | 299 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->ALG) | 
|  | 300 | #define FOE_AI_TAIL(skb)  \ | 
|  | 301 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->CRSN) | 
|  | 302 | #define FOE_SP_TAIL(skb)  \ | 
|  | 303 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->SPORT) | 
|  | 304 | #define FOE_MAGIC_TAG_TAIL(skb)  \ | 
|  | 305 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->IF) | 
|  | 306 |  | 
|  | 307 | #define FOE_WDMA_ID_TAIL(skb)  \ | 
|  | 308 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->WDMAID) | 
|  | 309 | #define FOE_RX_ID_TAIL(skb)  \ | 
|  | 310 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->RXID) | 
|  | 311 | #define FOE_WC_ID_TAIL(skb)  \ | 
|  | 312 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->WCID) | 
|  | 313 | #define FOE_BSS_ID_TAIL(skb)  \ | 
|  | 314 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->BSSID) | 
|  | 315 |  | 
|  | 316 | #define FOE_PPE_TAIL(skb)  \ | 
|  | 317 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->ppe) | 
|  | 318 | /*********************************************************************/ | 
|  | 319 | #define FOE_WDMA_ID_CB(skb)  \ | 
|  | 320 | (((struct cb_rx_desc_info4 *)((skb)->head))->WDMAID) | 
|  | 321 | #define FOE_RX_ID_CB(skb)  \ | 
|  | 322 | (((struct cb_rx_desc_info4 *)((skb)->head))->RXID) | 
|  | 323 | #define FOE_WC_ID_CB(skb)  \ | 
|  | 324 | (((struct cb_rx_desc_info4 *)((skb)->head))->WCID) | 
|  | 325 | #define FOE_BSS_ID_CB(skb)  \ | 
|  | 326 | (((struct cb_rx_desc_info4 *)((skb)->head))->BSSID) | 
|  | 327 |  | 
|  | 328 | #define FOE_MINFO(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->minfo) | 
|  | 329 | #define FOE_MINFO_NTYPE(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->ntype) | 
|  | 330 | #define FOE_MINFO_CHID(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->chid) | 
|  | 331 | #define FOE_MINFO_HEAD(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->minfo) | 
|  | 332 | #define FOE_MINFO_NTYPE_HEAD(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->ntype) | 
|  | 333 | #define FOE_MINFO_CHID_HEAD(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->chid) | 
|  | 334 |  | 
|  | 335 | #define FOE_MINFO_TAIL(skb)  \ | 
|  | 336 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->minfo) | 
|  | 337 | #define FOE_MINFO_NTYPE_TAIL(skb)  \ | 
|  | 338 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->ntype) | 
|  | 339 | #define FOE_MINFO_CHID_TAIL(skb)  \ | 
|  | 340 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->chid) | 
|  | 341 |  | 
|  | 342 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 343 | #define FOE_SOURCE(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->SOURCE) | 
|  | 344 | #define FOE_DEST(skb)	(((struct head_rx_descinfo4 *)((skb)->head))->DEST) | 
|  | 345 | #endif | 
|  | 346 |  | 
|  | 347 | #define IS_SPACE_AVAILABLE_HEAD(skb)  \ | 
|  | 348 | ((((skb_headroom(skb) >= FOE_INFO_LEN) ? 1 : 0))) | 
|  | 349 | #define IS_SPACE_AVAILABLE_HEAD(skb)  \ | 
|  | 350 | ((((skb_headroom(skb) >= FOE_INFO_LEN) ? 1 : 0))) | 
|  | 351 | #define FOE_INFO_START_ADDR_HEAD(skb)	(skb->head) | 
|  | 352 |  | 
|  | 353 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 354 | #define FOE_SOURCE_HEAD(skb)  \ | 
|  | 355 | (((struct head_rx_descinfo4 *)((skb)->head))->SOURCE) | 
|  | 356 | #define FOE_DEST_HEAD(skb)  \ | 
|  | 357 | (((struct head_rx_descinfo4 *)((skb)->head))->DEST) | 
|  | 358 | #endif | 
|  | 359 |  | 
|  | 360 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 361 | #define FOE_SOURCE_HEAD(skb)  \ | 
|  | 362 | (((struct head_rx_descinfo4 *)((skb)->head))->SOURCE) | 
|  | 363 | #define FOE_DEST_HEAD(skb)  \ | 
|  | 364 | (((struct head_rx_descinfo4 *)((skb)->head))->DEST) | 
|  | 365 | #endif | 
|  | 366 | #define IS_SPACE_AVAILABLE_TAIL(skb)  \ | 
|  | 367 | (((skb_tailroom(skb) >= FOE_INFO_LEN) ? 1 : 0)) | 
|  | 368 | #define IS_SPACE_AVAILABLE_TAIL(skb)  \ | 
|  | 369 | (((skb_tailroom(skb) >= FOE_INFO_LEN) ? 1 : 0)) | 
|  | 370 | #define FOE_INFO_START_ADDR_TAIL(skb)  \ | 
|  | 371 | ((unsigned char *)(long)(skb_end_pointer(skb) - FOE_INFO_LEN)) | 
|  | 372 |  | 
|  | 373 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 374 | #define FOE_SOURCE_TAIL(skb)  \ | 
|  | 375 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->SOURCE) | 
|  | 376 | #define FOE_DEST_TAIL(skb)  \ | 
|  | 377 | (((struct pdma_rx_desc_info4 *)((long)((skb_end_pointer(skb)) - FOE_INFO_LEN)))->DEST) | 
|  | 378 | #endif | 
|  | 379 |  | 
|  | 380 | /* change the position of skb_CB if necessary */ | 
|  | 381 | #define CB_OFFSET		    40 | 
|  | 382 | #define IS_SPACE_AVAILABLE_CB(skb)    1 | 
|  | 383 | #define FOE_INFO_START_ADDR_CB(skb)    (skb->cb +  CB_OFFSET) | 
|  | 384 | #define FOE_TAG_PROTECT_CB0(skb)  \ | 
|  | 385 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->MAGIC_TAG_PROTECT0) | 
|  | 386 | #define FOE_TAG_PROTECT_CB1(skb)  \ | 
|  | 387 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->MAGIC_TAG_PROTECT1) | 
|  | 388 | #define FOE_ENTRY_NUM_CB(skb)  \ | 
|  | 389 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->foe_entry_num) | 
|  | 390 | #define FOE_ALG_CB(skb)  \ | 
|  | 391 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->ALG) | 
|  | 392 | #define FOE_AI_CB(skb)  \ | 
|  | 393 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->CRSN) | 
|  | 394 | #define FOE_SP_CB(skb)  \ | 
|  | 395 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->SPORT) | 
|  | 396 | #define FOE_MAGIC_TAG_CB(skb)  \ | 
|  | 397 | (((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->IF) | 
|  | 398 |  | 
|  | 399 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 400 | #define FOE_SOURCE_CB(skb)	(((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->SOURCE) | 
|  | 401 | #define FOE_DEST_CB(skb)	(((struct cb_rx_desc_info4 *)((skb)->cb + CB_OFFSET))->DEST) | 
|  | 402 | #endif | 
|  | 403 |  | 
|  | 404 | #define IS_MAGIC_TAG_PROTECT_VALID_HEAD(skb)  \ | 
|  | 405 | (FOE_TAG_PROTECT_HEAD(skb) == TAG_PROTECT) | 
|  | 406 | #define IS_MAGIC_TAG_PROTECT_VALID_TAIL(skb)  \ | 
|  | 407 | (FOE_TAG_PROTECT_TAIL(skb) == TAG_PROTECT) | 
|  | 408 | #define IS_MAGIC_TAG_PROTECT_VALID_CB(skb)  \ | 
|  | 409 | ((FOE_TAG_PROTECT_CB0(skb) == TAG_PROTECT) && \ | 
|  | 410 | (FOE_TAG_PROTECT_CB0(skb) == FOE_TAG_PROTECT_CB1(skb))) | 
|  | 411 |  | 
|  | 412 | #define IS_IF_PCIE_WLAN_HEAD(skb)  \ | 
|  | 413 | ((FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_PCI) || \ | 
|  | 414 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_WLAN) || \ | 
|  | 415 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_GE) || \ | 
|  | 416 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_RNDIS) || \ | 
|  | 417 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_EDMARX)) | 
|  | 418 |  | 
|  | 419 | #define IS_IF_PCIE_WLAN_TAIL(skb)  \ | 
|  | 420 | ((FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_PCI) || \ | 
|  | 421 | (FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_WLAN) || \ | 
|  | 422 | (FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_RNDIS)) | 
|  | 423 |  | 
|  | 424 | #define IS_IF_PCIE_WLAN_CB(skb)  \ | 
|  | 425 | ((FOE_MAGIC_TAG_CB(skb) == FOE_MAGIC_PCI) || \ | 
|  | 426 | (FOE_MAGIC_TAG_CB(skb) == FOE_MAGIC_WLAN) || \ | 
|  | 427 | (FOE_MAGIC_TAG_CB(skb) == FOE_MAGIC_RNDIS)) | 
|  | 428 |  | 
|  | 429 | /* macros */ | 
|  | 430 | #define magic_tag_set_zero(skb) \ | 
|  | 431 | { \ | 
|  | 432 | if ((FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_PCI) || \ | 
|  | 433 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_WLAN) || \ | 
|  | 434 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_RNDIS) || \ | 
|  | 435 | (FOE_MAGIC_TAG_HEAD(skb) == FOE_MAGIC_GE)) { \ | 
|  | 436 | if (IS_SPACE_AVAILABLE_HEAD(skb)) \ | 
|  | 437 | FOE_MAGIC_TAG_HEAD(skb) = 0; \ | 
|  | 438 | } \ | 
|  | 439 | if ((FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_PCI) || \ | 
|  | 440 | (FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_WLAN) || \ | 
|  | 441 | (FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_RNDIS) || \ | 
|  | 442 | (FOE_MAGIC_TAG_TAIL(skb) == FOE_MAGIC_GE)) { \ | 
|  | 443 | if (IS_SPACE_AVAILABLE_TAIL(skb)) \ | 
|  | 444 | FOE_MAGIC_TAG_TAIL(skb) = 0; \ | 
|  | 445 | } \ | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | static inline void hwnat_set_l2tp_unhit(struct iphdr *iph, struct sk_buff *skb) | 
|  | 449 | { | 
|  | 450 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 451 | /* only clear headeroom for TCP OR not L2TP packets */ | 
|  | 452 | if ((iph->protocol == 0x6) || (ntohs(udp_hdr(skb)->dest) != 1701)) { | 
|  | 453 | if (IS_SPACE_AVAILABLE_HEAD(skb)) { | 
|  | 454 | FOE_MAGIC_TAG(skb) = 0; | 
|  | 455 | FOE_AI(skb) = UN_HIT; | 
|  | 456 | } | 
|  | 457 | } | 
|  | 458 | #endif | 
|  | 459 | } | 
|  | 460 |  | 
|  | 461 | static inline void hwnat_set_l2tp_fast_path(u32 l2tp_fast_path, u32 pptp_fast_path) | 
|  | 462 | { | 
|  | 463 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 464 | l2tp_fast_path = 1; | 
|  | 465 | pptp_fast_path = 0; | 
|  | 466 | #endif | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | static inline void hwnat_clear_l2tp_fast_path(u32 l2tp_fast_path) | 
|  | 470 | { | 
|  | 471 | #if defined(CONFIG_RA_HW_NAT_PPTP_L2TP) | 
|  | 472 | l2tp_fast_path = 0; | 
|  | 473 | #endif | 
|  | 474 | } | 
|  | 475 |  | 
|  | 476 | /* #define CONFIG_HW_NAT_IPI */ | 
|  | 477 | #if defined(CONFIG_HW_NAT_IPI) | 
|  | 478 | extern int debug_level; | 
|  | 479 | int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | 
|  | 480 | struct rps_dev_flow **rflowp); | 
|  | 481 | uint32_t ppe_extif_rx_handler(struct sk_buff *skb); | 
|  | 482 | int hitbind_force_to_cpu_handler(struct sk_buff *skb, struct foe_entry *entry); | 
|  | 483 | extern unsigned int ipidbg[num_possible_cpus()][10]; | 
|  | 484 | extern unsigned int ipidbg2[num_possible_cpus()][10]; | 
|  | 485 | /* #define HNAT_IPI_RXQUEUE	1 */ | 
|  | 486 | #define HNAT_IPI_DQ		1 | 
|  | 487 | #define HNAT_IPI_HASH_NORMAL	0 | 
|  | 488 | #define HNAT_IPI_HASH_VTAG		1 | 
|  | 489 | #define HNAT_IPI_HASH_FROM_EXTIF	2 | 
|  | 490 | #define HNAT_IPI_HASH_FROM_GMAC		4 | 
|  | 491 |  | 
|  | 492 | struct hnat_ipi_s { | 
|  | 493 | #if defined(HNAT_IPI_DQ) | 
|  | 494 | struct sk_buff_head     skb_input_queue; | 
|  | 495 | struct sk_buff_head     skb_process_queue; | 
|  | 496 | #elif defined(HNAT_IPI_RXQUEUE) | 
|  | 497 | atomic_t rx_queue_num; | 
|  | 498 | unsigned int rx_queue_ridx; | 
|  | 499 | unsigned int rx_queue_widx; | 
|  | 500 | struct sk_buff **rx_queue; | 
|  | 501 | #else | 
|  | 502 | /* unsigned int dummy0[0]; */ | 
|  | 503 | struct sk_buff_head     skb_ipi_queue; | 
|  | 504 | /* unsigned int dummy1[8]; */ | 
|  | 505 | #endif | 
|  | 506 | unsigned long time_rec, recv_time; | 
|  | 507 | unsigned int ipi_accum; | 
|  | 508 | /*hwnat ipi use*/ | 
|  | 509 | spinlock_t      ipilock; | 
|  | 510 | struct tasklet_struct smp_func_call_tsk; | 
|  | 511 | } ____cacheline_aligned_in_smp; | 
|  | 512 |  | 
|  | 513 | struct hnat_ipi_stat { | 
|  | 514 | unsigned long drop_pkt_num_from_extif; | 
|  | 515 | unsigned long drop_pkt_num_from_ppehit; | 
|  | 516 | unsigned int smp_call_cnt_from_extif; | 
|  | 517 | unsigned int smp_call_cnt_from_ppehit; | 
|  | 518 | atomic_t cpu_status; | 
|  | 519 | /* atomic_t cpu_status_from_extif; */ | 
|  | 520 | /* atomic_t cpu_status_from_ppehit; */ | 
|  | 521 |  | 
|  | 522 | /* atomic_t hook_status_from_extif; */ | 
|  | 523 | /* atomic_t hook_status_from_ppehit; */ | 
|  | 524 | } ____cacheline_aligned_in_smp; | 
|  | 525 |  | 
|  | 526 | #define cpu_status_from_extif	cpu_status | 
|  | 527 | #define cpu_status_from_ppehit	cpu_status | 
|  | 528 |  | 
|  | 529 | struct hnat_ipi_cfg { | 
|  | 530 | unsigned int enable_from_extif; | 
|  | 531 | unsigned int enable_from_ppehit; | 
|  | 532 | unsigned int queue_thresh_from_extif; | 
|  | 533 | unsigned int queue_thresh_from_ppehit; | 
|  | 534 | unsigned int drop_pkt_from_extif; | 
|  | 535 | unsigned int drop_pkt_from_ppehit; | 
|  | 536 | unsigned int ipi_cnt_mod_from_extif; | 
|  | 537 | unsigned int ipi_cnt_mod_from_ppehit; | 
|  | 538 | } ____cacheline_aligned_in_smp; | 
|  | 539 |  | 
|  | 540 | int hnat_ipi_init(void); | 
|  | 541 | int hnat_ipi_de_init(void); | 
|  | 542 | #endif | 
|  | 543 |  | 
|  | 544 | #define QDMA_RX		5 | 
|  | 545 | #define PDMA_RX		0 | 
|  | 546 |  | 
| rjw | 2e8229f | 2022-02-15 21:08:12 +0800 | [diff] [blame] | 547 | #if defined(CONFIG_HW_NAT) | 
|  | 548 | void mtk_hook_fast_path(struct net_device *dev); | 
|  | 549 | #endif | 
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 550 |  | 
|  | 551 | #endif |