examples/ipsec-secgw: add app mode worker
[dpdk.git] / examples / ipsec-secgw / ipsec-secgw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2020 Marvell International Ltd.
3  */
4 #ifndef _IPSEC_SECGW_H_
5 #define _IPSEC_SECGW_H_
6
7 #include <stdbool.h>
8
9 #define NB_SOCKETS 4
10
11 #define MAX_PKT_BURST 32
12
13 #define RTE_LOGTYPE_IPSEC RTE_LOGTYPE_USER1
14
15 #if RTE_BYTE_ORDER != RTE_LITTLE_ENDIAN
16 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
17         (((uint64_t)((a) & 0xff) << 56) | \
18         ((uint64_t)((b) & 0xff) << 48) | \
19         ((uint64_t)((c) & 0xff) << 40) | \
20         ((uint64_t)((d) & 0xff) << 32) | \
21         ((uint64_t)((e) & 0xff) << 24) | \
22         ((uint64_t)((f) & 0xff) << 16) | \
23         ((uint64_t)((g) & 0xff) << 8)  | \
24         ((uint64_t)(h) & 0xff))
25 #else
26 #define __BYTES_TO_UINT64(a, b, c, d, e, f, g, h) \
27         (((uint64_t)((h) & 0xff) << 56) | \
28         ((uint64_t)((g) & 0xff) << 48) | \
29         ((uint64_t)((f) & 0xff) << 40) | \
30         ((uint64_t)((e) & 0xff) << 32) | \
31         ((uint64_t)((d) & 0xff) << 24) | \
32         ((uint64_t)((c) & 0xff) << 16) | \
33         ((uint64_t)((b) & 0xff) << 8) | \
34         ((uint64_t)(a) & 0xff))
35 #endif
36
37 #define ETHADDR(a, b, c, d, e, f) (__BYTES_TO_UINT64(a, b, c, d, e, f, 0, 0))
38
39 struct traffic_type {
40         const uint8_t *data[MAX_PKT_BURST * 2];
41         struct rte_mbuf *pkts[MAX_PKT_BURST * 2];
42         void *saptr[MAX_PKT_BURST * 2];
43         uint32_t res[MAX_PKT_BURST * 2];
44         uint32_t num;
45 };
46
47 struct ipsec_traffic {
48         struct traffic_type ipsec;
49         struct traffic_type ip4;
50         struct traffic_type ip6;
51 };
52
53 /* Fields optimized for devices without burst */
54 struct traffic_type_nb {
55         const uint8_t *data;
56         struct rte_mbuf *pkt;
57         uint32_t res;
58         uint32_t num;
59 };
60
61 struct ipsec_traffic_nb {
62         struct traffic_type_nb ipsec;
63         struct traffic_type_nb ip4;
64         struct traffic_type_nb ip6;
65 };
66
67 /* port/source ethernet addr and destination ethernet addr */
68 struct ethaddr_info {
69         uint64_t src, dst;
70 };
71
72 extern struct ethaddr_info ethaddr_tbl[RTE_MAX_ETHPORTS];
73
74 /* Port mask to identify the unprotected ports */
75 extern uint32_t unprotected_port_mask;
76
77 /* Index of SA in single mode */
78 extern uint32_t single_sa_idx;
79
80 extern volatile bool force_quit;
81
82 static inline uint8_t
83 is_unprotected_port(uint16_t port_id)
84 {
85         return unprotected_port_mask & (1 << port_id);
86 }
87
88 #endif /* _IPSEC_SECGW_H_ */