Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 1 | /* |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 2 | * sfe.h |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 3 | * Shortcut forwarding engine. |
| 4 | * |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 5 | * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 6 | * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved. |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 7 | * |
| 8 | * Permission to use, copy, modify, and/or distribute this software for any |
| 9 | * purpose with or without fee is hereby granted, provided that the above |
| 10 | * copyright notice and this permission notice appear in all copies. |
| 11 | * |
Xiaoping Fan | a42c68b | 2015-08-07 18:00:39 -0700 | [diff] [blame] | 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Ratheesh Kannoth | 7a6a4ae | 2021-10-20 08:24:05 +0530 | [diff] [blame] | 21 | #ifndef __SFE_H |
| 22 | #define __SFE_H |
| 23 | |
| 24 | /* |
| 25 | * Maximum number of accelerated IPv4 or IPv6 connections |
| 26 | */ |
| 27 | #if defined(SFE_MEM_PROFILE_LOW) |
| 28 | #define SFE_MAX_CONNECTION_NUM 512 |
| 29 | #elif defined(SFE_MEM_PROFILE_MEDIUM) |
| 30 | #define SFE_MAX_CONNECTION_NUM 2048 |
| 31 | #else |
| 32 | #define SFE_MAX_CONNECTION_NUM 4096 |
| 33 | #endif |
| 34 | |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 35 | #define SFE_L2_PARSE_FLAGS_PPPOE_INGRESS 0x01 /* Indicates presence of a valid PPPoE header */ |
| 36 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 37 | /* |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 38 | * IPv6 address structure |
| 39 | */ |
| 40 | struct sfe_ipv6_addr { |
| 41 | __be32 addr[4]; |
| 42 | }; |
| 43 | |
| 44 | typedef union { |
| 45 | __be32 ip; |
| 46 | struct sfe_ipv6_addr ip6[1]; |
| 47 | } sfe_ip_addr_t; |
| 48 | |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 49 | typedef enum sfe_sync_reason { |
| 50 | SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */ |
| 51 | SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */ |
| 52 | SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */ |
| 53 | } sfe_sync_reason_t; |
| 54 | |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 55 | /* |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 56 | * VLAN header (aka VLAN tag) |
| 57 | */ |
| 58 | struct sfe_vlan_hdr { |
| 59 | u16 tpid; /* Tag Protocol Identifier */ |
| 60 | u16 tci; /* Tag Control Information */ |
| 61 | }; |
| 62 | |
| 63 | /* |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 64 | * Structure used to store L2 information |
| 65 | */ |
| 66 | struct sfe_l2_info { |
| 67 | u16 parse_flags; /* Flags indicating L2.5 headers presence */ |
| 68 | u16 l2_hdr_offset; /* Offset of L2 header */ |
| 69 | u16 l2_hdr_size; /* L2 header size */ |
| 70 | u16 pppoe_hdr_offset; /* PPPOE header offset */ |
| 71 | u16 protocol; /* L3 Protocol */ |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 72 | struct sfe_vlan_hdr vlan_hdr[SFE_MAX_VLAN_DEPTH]; |
| 73 | /* VLAN tag(s) of ingress packet */ |
| 74 | u8 vlan_hdr_cnt; /* Number of VLAN tags in the ingress packet */ |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 78 | * Structure used to sync connection stats/state back within the system. |
| 79 | * |
| 80 | * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing. |
| 81 | * 'src' is the creator of the connection. |
| 82 | */ |
| 83 | struct sfe_connection_sync { |
| 84 | struct net_device *src_dev; |
| 85 | struct net_device *dest_dev; |
| 86 | int is_v6; /* Is it for ipv6? */ |
| 87 | int protocol; /* IP protocol number (IPPROTO_...) */ |
| 88 | sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 89 | sfe_ip_addr_t src_ip_xlate; /* NATed source address */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 90 | __be16 src_port; /* Non-NAT source port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 91 | __be16 src_port_xlate; /* NATed source port */ |
| 92 | sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */ |
| 93 | sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 94 | __be16 dest_port; /* Non-NAT destination port */ |
Xiaoping Fan | 99cb4c1 | 2015-08-21 19:07:32 -0700 | [diff] [blame] | 95 | __be16 dest_port_xlate; /* NATed destination port */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 96 | u32 src_td_max_window; |
| 97 | u32 src_td_end; |
| 98 | u32 src_td_max_end; |
| 99 | u64 src_packet_count; |
| 100 | u64 src_byte_count; |
| 101 | u32 src_new_packet_count; |
| 102 | u32 src_new_byte_count; |
| 103 | u32 dest_td_max_window; |
| 104 | u32 dest_td_end; |
| 105 | u32 dest_td_max_end; |
| 106 | u64 dest_packet_count; |
| 107 | u64 dest_byte_count; |
| 108 | u32 dest_new_packet_count; |
| 109 | u32 dest_new_byte_count; |
Wayne Tan | bb7f178 | 2021-12-13 11:16:04 -0800 | [diff] [blame] | 110 | u32 reason; /* reason for stats sync message, i.e. destroy, flush, period sync */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 111 | u64 delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */ |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * connection mark structure |
| 116 | */ |
| 117 | struct sfe_connection_mark { |
| 118 | int protocol; |
| 119 | sfe_ip_addr_t src_ip; |
| 120 | sfe_ip_addr_t dest_ip; |
| 121 | __be16 src_port; |
| 122 | __be16 dest_port; |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 123 | u32 mark; |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /* |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 127 | * Expose the hook for the receive processing. |
| 128 | */ |
| 129 | extern int (*athrs_fast_nat_recv)(struct sk_buff *skb); |
| 130 | |
| 131 | /* |
| 132 | * Expose what should be a static flag in the TCP connection tracker. |
| 133 | */ |
| 134 | extern int nf_ct_tcp_no_window_check; |
| 135 | |
| 136 | /* |
Ken Zhu | 7e38d1a | 2021-11-30 17:31:46 -0800 | [diff] [blame] | 137 | * Check the fast transmit feasibility. |
| 138 | */ |
| 139 | bool sfe_fast_xmit_check(struct sk_buff *skb, netdev_features_t features); |
| 140 | |
| 141 | /* |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 142 | * This callback will be called in a timer |
| 143 | * at 100 times per second to sync stats back to |
| 144 | * Linux connection track. |
| 145 | * |
| 146 | * A RCU lock is taken to prevent this callback |
| 147 | * from unregistering. |
Xiaoping Fan | d44a5b4 | 2015-05-26 17:37:37 -0700 | [diff] [blame] | 148 | */ |
| 149 | typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *); |
| 150 | |
| 151 | /* |
| 152 | * IPv4 APIs used by connection manager |
| 153 | */ |
Amitesh Anand | 63be37d | 2021-12-24 20:51:48 +0530 | [diff] [blame] | 154 | int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 155 | int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg); |
| 156 | void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 157 | void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev); |
| 158 | void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 159 | void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg); |
Nitin Shetty | e6ed5b5 | 2021-12-27 14:50:11 +0530 | [diff] [blame] | 160 | bool sfe_dev_has_hw_csum(struct net_device *dev); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 161 | |
| 162 | #ifdef SFE_SUPPORT_IPV6 |
| 163 | /* |
| 164 | * IPv6 APIs used by connection manager |
| 165 | */ |
Suruchi Suman | 23a279d | 2021-11-16 15:13:09 +0530 | [diff] [blame] | 166 | int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 167 | int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg); |
| 168 | void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg); |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 169 | void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev); |
| 170 | void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback); |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 171 | void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg); |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 172 | #else |
Suruchi Suman | 23a279d | 2021-11-16 15:13:09 +0530 | [diff] [blame] | 173 | static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 174 | { |
| 175 | return 0; |
| 176 | } |
| 177 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 178 | static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 179 | { |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 180 | return 0; |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Suruchi Suman | 23a279d | 2021-11-16 15:13:09 +0530 | [diff] [blame] | 183 | static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 184 | { |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev) |
| 189 | { |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback) |
| 194 | { |
| 195 | return; |
| 196 | } |
| 197 | |
Ratheesh Kannoth | 89302a7 | 2021-10-20 08:10:37 +0530 | [diff] [blame] | 198 | static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg) |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 199 | { |
| 200 | return; |
| 201 | } |
| 202 | |
Xiaoping Fan | 978b377 | 2015-05-27 14:15:18 -0700 | [diff] [blame] | 203 | #endif |
Xiaoping Fan | 9b6bb33 | 2016-04-05 19:21:26 -0700 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * sfe_ipv6_addr_equal() |
| 207 | * compare ipv6 address |
| 208 | * |
| 209 | * return: 1, equal; 0, no equal |
| 210 | */ |
| 211 | static inline int sfe_ipv6_addr_equal(struct sfe_ipv6_addr *a, |
| 212 | struct sfe_ipv6_addr *b) |
| 213 | { |
| 214 | return a->addr[0] == b->addr[0] && |
| 215 | a->addr[1] == b->addr[1] && |
| 216 | a->addr[2] == b->addr[2] && |
| 217 | a->addr[3] == b->addr[3]; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * sfe_ipv4_addr_equal() |
| 222 | * compare ipv4 address |
| 223 | * |
| 224 | * return: 1, equal; 0, no equal |
| 225 | */ |
Xiaoping Fan | 6a1672f | 2016-08-17 19:58:12 -0700 | [diff] [blame] | 226 | #define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b)) |
Xiaoping Fan | 9b6bb33 | 2016-04-05 19:21:26 -0700 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * sfe_addr_equal() |
| 230 | * compare ipv4 or ipv6 address |
| 231 | * |
| 232 | * return: 1, equal; 0, no equal |
| 233 | */ |
| 234 | static inline int sfe_addr_equal(sfe_ip_addr_t *a, |
| 235 | sfe_ip_addr_t *b, int is_v4) |
| 236 | { |
| 237 | return is_v4 ? sfe_ipv4_addr_equal(a->ip, b->ip) : sfe_ipv6_addr_equal(a->ip6, b->ip6); |
| 238 | } |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 239 | |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 240 | /* |
| 241 | * sfe_l2_parse_flag_set() |
| 242 | * Set L2 parse flag |
| 243 | */ |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 244 | static inline void sfe_l2_parse_flag_set(struct sfe_l2_info *l2_info, u16 flag) |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 245 | { |
| 246 | l2_info->parse_flags |= flag; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * sfe_l2_parse_flag_get() |
| 251 | * Get L2 parse flag |
| 252 | */ |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 253 | static inline u16 sfe_l2_parse_flag_get(struct sfe_l2_info *l2_info) |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 254 | { |
| 255 | return l2_info->parse_flags; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * sfe_l2_parse_flag_check() |
| 260 | * Check L2 parse flag |
| 261 | */ |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 262 | static inline bool sfe_l2_parse_flag_check(struct sfe_l2_info *l2_info, u16 flag) |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 263 | { |
Guduri Prathyusha | 5f27e23 | 2022-01-06 14:39:04 +0530 | [diff] [blame] | 264 | return !!(l2_info->parse_flags & flag); |
Guduri Prathyusha | 647fe3e | 2021-11-22 19:17:51 +0530 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
| 268 | * sfe_l2_hdr_offset_get() |
| 269 | * Get L2 header offset |
| 270 | */ |
| 271 | static inline u16 sfe_l2_hdr_offset_get(struct sfe_l2_info *l2_info) |
| 272 | { |
| 273 | return l2_info->l2_hdr_offset; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * sfe_l2_hdr_offset_set() |
| 278 | * Set L2 header offset |
| 279 | */ |
| 280 | static inline void sfe_l2_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset) |
| 281 | { |
| 282 | l2_info->l2_hdr_offset = offset; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * sfe_l2_pppoe_hdr_offset_get() |
| 287 | * Get L2 PPPoE header offset |
| 288 | */ |
| 289 | static inline u16 sfe_l2_pppoe_hdr_offset_get(struct sfe_l2_info *l2_info) |
| 290 | { |
| 291 | return l2_info->pppoe_hdr_offset; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * sfe_l2_pppoe_hdr_offset_set() |
| 296 | * Set L2 PPPoE header offset |
| 297 | */ |
| 298 | static inline void sfe_l2_pppoe_hdr_offset_set(struct sfe_l2_info *l2_info, u16 offset) |
| 299 | { |
| 300 | l2_info->pppoe_hdr_offset = offset; |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * sfe_l2_hdr_size_get() |
| 305 | * Get L2 header size |
| 306 | */ |
| 307 | static inline u16 sfe_l2_hdr_size_get(struct sfe_l2_info *l2_info) |
| 308 | { |
| 309 | return l2_info->l2_hdr_size; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | * sfe_l2_hdr_size_set() |
| 314 | * Set L2 header size |
| 315 | */ |
| 316 | static inline void sfe_l2_hdr_size_set(struct sfe_l2_info *l2_info, u16 size) |
| 317 | { |
| 318 | l2_info->l2_hdr_size = size; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * sfe_l2_protocol_get() |
| 323 | * Get L2 protocol |
| 324 | */ |
| 325 | static inline u16 sfe_l2_protocol_get(struct sfe_l2_info *l2_info) |
| 326 | { |
| 327 | return l2_info->protocol; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * sfe_l2_protocol_set() |
| 332 | * Set L2 protocol |
| 333 | */ |
| 334 | static inline void sfe_l2_protocol_set(struct sfe_l2_info *l2_info, u16 proto) |
| 335 | { |
| 336 | l2_info->protocol = proto; |
| 337 | } |
| 338 | |
Ratheesh Kannoth | 24fb1db | 2021-10-20 07:28:06 +0530 | [diff] [blame] | 339 | int sfe_init_if(void); |
| 340 | void sfe_exit_if(void); |
Ratheesh Kannoth | 7a6a4ae | 2021-10-20 08:24:05 +0530 | [diff] [blame] | 341 | |
| 342 | #endif /* __SFE_H */ |