blob: e246b534f4fe3aa64836aa18f2219cc21defb6ec [file] [log] [blame]
Xiaoping Fand44a5b42015-05-26 17:37:37 -07001/*
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05302 * sfe.h
Xiaoping Fand44a5b42015-05-26 17:37:37 -07003 * Shortcut forwarding engine.
4 *
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05305 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
Guduri Prathyusha5f27e232022-01-06 14:39:04 +05306 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +05307 *
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 Fana42c68b2015-08-07 18:00:39 -070012 * 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 Kannoth24fb1db2021-10-20 07:28:06 +053017 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Xiaoping Fand44a5b42015-05-26 17:37:37 -070019 */
20
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +053021#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 Prathyusha647fe3e2021-11-22 19:17:51 +053035#define SFE_L2_PARSE_FLAGS_PPPOE_INGRESS 0x01 /* Indicates presence of a valid PPPoE header */
36
Parikshit Guned31a8202022-01-05 22:15:04 +053037/**
38 * SAWF_metadata information placement in mark field.
39 */
40#define SFE_SAWF_VALID_TAG 0xAA
41#define SFE_SAWF_TAG_SHIFT 0x18
42#define SFE_SAWF_SERVICE_CLASS_SHIFT 0x10
43#define SFE_SAWF_SERVICE_CLASS_MASK 0xff
44#define SFE_SAWF_MSDUQ_MASK 0xffff
45
46/**
47 * SAWF_metadata extraction.
48 */
49#define SFE_GET_SAWF_TAG(x) (x>>SFE_SAWF_TAG_SHIFT)
50#define SFE_GET_SAWF_SERVICE_CLASS(x) ((x>>SFE_SAWF_SERVICE_CLASS_SHIFT) & SFE_SAWF_SERVICE_CLASS_MASK)
51#define SFE_GET_SAWF_MSDUQ(x) (x & SFE_SAWF_MSDUQ_MASK)
52#define SFE_SAWF_TAG_IS_VALID(x) ((x == SFE_SAWF_VALID_TAG) ? true : false)
53
Xiaoping Fand44a5b42015-05-26 17:37:37 -070054/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070055 * IPv6 address structure
56 */
57struct sfe_ipv6_addr {
58 __be32 addr[4];
59};
60
61typedef union {
62 __be32 ip;
63 struct sfe_ipv6_addr ip6[1];
64} sfe_ip_addr_t;
65
Xiaoping Fan99cb4c12015-08-21 19:07:32 -070066typedef enum sfe_sync_reason {
67 SFE_SYNC_REASON_STATS, /* Sync is to synchronize stats */
68 SFE_SYNC_REASON_FLUSH, /* Sync is to flush a entry */
69 SFE_SYNC_REASON_DESTROY /* Sync is to destroy a entry(requested by connection manager) */
70} sfe_sync_reason_t;
71
Xiaoping Fand44a5b42015-05-26 17:37:37 -070072/*
Wayne Tanbb7f1782021-12-13 11:16:04 -080073 * VLAN header (aka VLAN tag)
74 */
75struct sfe_vlan_hdr {
76 u16 tpid; /* Tag Protocol Identifier */
77 u16 tci; /* Tag Control Information */
78};
79
80/*
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053081 * Structure used to store L2 information
82 */
83struct sfe_l2_info {
84 u16 parse_flags; /* Flags indicating L2.5 headers presence */
Nitin Shetty9af87d42022-02-11 16:25:29 +053085 u16 pppoe_session_id; /* PPPOE header offset */
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053086 u16 protocol; /* L3 Protocol */
Wayne Tanbb7f1782021-12-13 11:16:04 -080087 struct sfe_vlan_hdr vlan_hdr[SFE_MAX_VLAN_DEPTH];
88 /* VLAN tag(s) of ingress packet */
89 u8 vlan_hdr_cnt; /* Number of VLAN tags in the ingress packet */
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +053090};
91
92/*
Xiaoping Fand44a5b42015-05-26 17:37:37 -070093 * Structure used to sync connection stats/state back within the system.
94 *
95 * NOTE: The addresses here are NON-NAT addresses, i.e. the true endpoint addressing.
96 * 'src' is the creator of the connection.
97 */
98struct sfe_connection_sync {
99 struct net_device *src_dev;
100 struct net_device *dest_dev;
101 int is_v6; /* Is it for ipv6? */
102 int protocol; /* IP protocol number (IPPROTO_...) */
103 sfe_ip_addr_t src_ip; /* Non-NAT source address, i.e. the creator of the connection */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700104 sfe_ip_addr_t src_ip_xlate; /* NATed source address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700105 __be16 src_port; /* Non-NAT source port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700106 __be16 src_port_xlate; /* NATed source port */
107 sfe_ip_addr_t dest_ip; /* Non-NAT destination address, i.e. to whom the connection was created */
108 sfe_ip_addr_t dest_ip_xlate; /* NATed destination address */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700109 __be16 dest_port; /* Non-NAT destination port */
Xiaoping Fan99cb4c12015-08-21 19:07:32 -0700110 __be16 dest_port_xlate; /* NATed destination port */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700111 u32 src_td_max_window;
112 u32 src_td_end;
113 u32 src_td_max_end;
114 u64 src_packet_count;
115 u64 src_byte_count;
116 u32 src_new_packet_count;
117 u32 src_new_byte_count;
118 u32 dest_td_max_window;
119 u32 dest_td_end;
120 u32 dest_td_max_end;
121 u64 dest_packet_count;
122 u64 dest_byte_count;
123 u32 dest_new_packet_count;
124 u32 dest_new_byte_count;
Wayne Tanbb7f1782021-12-13 11:16:04 -0800125 u32 reason; /* reason for stats sync message, i.e. destroy, flush, period sync */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700126 u64 delta_jiffies; /* Time to be added to the current timeout to keep the connection alive */
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700127};
128
129/*
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700130 * Expose the hook for the receive processing.
131 */
132extern int (*athrs_fast_nat_recv)(struct sk_buff *skb);
133
134/*
135 * Expose what should be a static flag in the TCP connection tracker.
136 */
137extern int nf_ct_tcp_no_window_check;
138
139/*
Ken Zhu7e38d1a2021-11-30 17:31:46 -0800140 * Check the fast transmit feasibility.
141 */
142bool sfe_fast_xmit_check(struct sk_buff *skb, netdev_features_t features);
143
144/*
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700145 * This callback will be called in a timer
146 * at 100 times per second to sync stats back to
147 * Linux connection track.
148 *
149 * A RCU lock is taken to prevent this callback
150 * from unregistering.
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700151 */
152typedef void (*sfe_sync_rule_callback_t)(struct sfe_connection_sync *);
Ken Zhu7a43d882022-01-04 10:51:44 -0800153typedef void (*sfe_ipv4_many_sync_callback_t)(struct sfe_ipv4_msg *msg);
154typedef void (*sfe_ipv6_many_sync_callback_t)(struct sfe_ipv6_msg *msg);
Xiaoping Fand44a5b42015-05-26 17:37:37 -0700155
156/*
157 * IPv4 APIs used by connection manager
158 */
Amitesh Anand63be37d2021-12-24 20:51:48 +0530159int sfe_ipv4_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530160int sfe_ipv4_create_rule(struct sfe_ipv4_rule_create_msg *msg);
161void sfe_ipv4_destroy_rule(struct sfe_ipv4_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700162void sfe_ipv4_destroy_all_rules_for_dev(struct net_device *dev);
163void sfe_ipv4_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530164void sfe_ipv4_update_rule(struct sfe_ipv4_rule_create_msg *msg);
Nitin Shettye6ed5b52021-12-27 14:50:11 +0530165bool sfe_dev_has_hw_csum(struct net_device *dev);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700166
Ken Zhu7a43d882022-01-04 10:51:44 -0800167bool sfe_ipv4_sync_invoke(uint16_t index);
168void sfe_ipv4_register_many_sync_callback(sfe_ipv4_many_sync_callback_t cb);
169void sfe_ipv4_stats_convert(struct sfe_ipv4_conn_sync *sync_msg, struct sfe_connection_sync *sis);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700170#ifdef SFE_SUPPORT_IPV6
171/*
172 * IPv6 APIs used by connection manager
173 */
Suruchi Suman23a279d2021-11-16 15:13:09 +0530174int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530175int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg);
176void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg);
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700177void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev);
178void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback);
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530179void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg);
Ken Zhu7a43d882022-01-04 10:51:44 -0800180bool sfe_ipv6_sync_invoke(uint16_t index);
181void sfe_ipv6_register_many_sync_callback(sfe_ipv6_many_sync_callback_t cb);
182void sfe_ipv6_stats_convert(struct sfe_ipv6_conn_sync *sync_msg, struct sfe_connection_sync *sis);
Xiaoping Fan978b3772015-05-27 14:15:18 -0700183#else
Suruchi Suman23a279d2021-11-16 15:13:09 +0530184static inline int sfe_ipv6_recv(struct net_device *dev, struct sk_buff *skb, struct sfe_l2_info *l2_info, bool tun_outer)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700185{
186 return 0;
187}
188
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530189static inline int sfe_ipv6_create_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700190{
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700191 return 0;
Xiaoping Fan978b3772015-05-27 14:15:18 -0700192}
193
Suruchi Suman23a279d2021-11-16 15:13:09 +0530194static inline void sfe_ipv6_destroy_rule(struct sfe_ipv6_rule_destroy_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700195{
196 return;
197}
198
199static inline void sfe_ipv6_destroy_all_rules_for_dev(struct net_device *dev)
200{
201 return;
202}
203
204static inline void sfe_ipv6_register_sync_rule_callback(sfe_sync_rule_callback_t callback)
205{
206 return;
207}
208
Ratheesh Kannoth89302a72021-10-20 08:10:37 +0530209static inline void sfe_ipv6_update_rule(struct sfe_ipv6_rule_create_msg *msg)
Xiaoping Fan978b3772015-05-27 14:15:18 -0700210{
211 return;
212}
213
Ken Zhu7a43d882022-01-04 10:51:44 -0800214static inline bool sfe_ipv6_sync_invoke(uint16_t index)
215{
216 return false;
217}
218
219static inline void sfe_ipv6_register_many_sync_callback(sfe_ipv6_many_sync_callback_t cb)
220{
221 return;
222}
223
224static inline void sfe_ipv6_stats_convert(struct sfe_ipv6_conn_sync *sync_msg, struct sfe_connection_sync *sis)
225{
226 return;
227}
Xiaoping Fan978b3772015-05-27 14:15:18 -0700228#endif
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700229
230/*
231 * sfe_ipv6_addr_equal()
232 * compare ipv6 address
233 *
234 * return: 1, equal; 0, no equal
235 */
236static inline int sfe_ipv6_addr_equal(struct sfe_ipv6_addr *a,
237 struct sfe_ipv6_addr *b)
238{
239 return a->addr[0] == b->addr[0] &&
240 a->addr[1] == b->addr[1] &&
241 a->addr[2] == b->addr[2] &&
242 a->addr[3] == b->addr[3];
243}
244
245/*
246 * sfe_ipv4_addr_equal()
247 * compare ipv4 address
248 *
249 * return: 1, equal; 0, no equal
250 */
Xiaoping Fan6a1672f2016-08-17 19:58:12 -0700251#define sfe_ipv4_addr_equal(a, b) ((u32)(a) == (u32)(b))
Xiaoping Fan9b6bb332016-04-05 19:21:26 -0700252
253/*
254 * sfe_addr_equal()
255 * compare ipv4 or ipv6 address
256 *
257 * return: 1, equal; 0, no equal
258 */
259static inline int sfe_addr_equal(sfe_ip_addr_t *a,
260 sfe_ip_addr_t *b, int is_v4)
261{
262 return is_v4 ? sfe_ipv4_addr_equal(a->ip, b->ip) : sfe_ipv6_addr_equal(a->ip6, b->ip6);
263}
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530264
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530265/*
266 * sfe_l2_parse_flag_set()
267 * Set L2 parse flag
268 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530269static inline void sfe_l2_parse_flag_set(struct sfe_l2_info *l2_info, u16 flag)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530270{
271 l2_info->parse_flags |= flag;
272}
273
274/*
275 * sfe_l2_parse_flag_get()
276 * Get L2 parse flag
277 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530278static inline u16 sfe_l2_parse_flag_get(struct sfe_l2_info *l2_info)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530279{
280 return l2_info->parse_flags;
281}
282
283/*
284 * sfe_l2_parse_flag_check()
285 * Check L2 parse flag
286 */
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530287static inline bool sfe_l2_parse_flag_check(struct sfe_l2_info *l2_info, u16 flag)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530288{
Guduri Prathyusha5f27e232022-01-06 14:39:04 +0530289 return !!(l2_info->parse_flags & flag);
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530290}
291
292/*
Nitin Shetty9af87d42022-02-11 16:25:29 +0530293 * sfe_l2_pppoe_session_id_get()
294 * Get PPPPoE session ID from l2_info
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530295 */
Nitin Shetty9af87d42022-02-11 16:25:29 +0530296static inline u16 sfe_l2_pppoe_session_id_get(struct sfe_l2_info *l2_info)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530297{
Nitin Shetty9af87d42022-02-11 16:25:29 +0530298 return l2_info->pppoe_session_id;
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530299}
300
301/*
Nitin Shetty9af87d42022-02-11 16:25:29 +0530302 * sfe_l2_pppoe_session_id_set()
303 * Set PPPoE session ID to l2_info
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530304 */
Nitin Shetty9af87d42022-02-11 16:25:29 +0530305static inline void sfe_l2_pppoe_session_id_set(struct sfe_l2_info *l2_info, u16 session_id)
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530306{
Nitin Shetty9af87d42022-02-11 16:25:29 +0530307 l2_info->pppoe_session_id = session_id;
Guduri Prathyusha647fe3e2021-11-22 19:17:51 +0530308}
309
310/*
311 * sfe_l2_protocol_get()
312 * Get L2 protocol
313 */
314static inline u16 sfe_l2_protocol_get(struct sfe_l2_info *l2_info)
315{
316 return l2_info->protocol;
317}
318
319/*
320 * sfe_l2_protocol_set()
321 * Set L2 protocol
322 */
323static inline void sfe_l2_protocol_set(struct sfe_l2_info *l2_info, u16 proto)
324{
325 l2_info->protocol = proto;
326}
327
Ratheesh Kannoth24fb1db2021-10-20 07:28:06 +0530328int sfe_init_if(void);
329void sfe_exit_if(void);
Ratheesh Kannoth7a6a4ae2021-10-20 08:24:05 +0530330
331#endif /* __SFE_H */