392e8fd7b7ffe62f4c739e00984c467590567519
[dpdk.git] / lib / librte_ipsec / sa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _SA_H_
6 #define _SA_H_
7
8 #include <rte_rwlock.h>
9
10 #define IPSEC_MAX_HDR_SIZE      64
11 #define IPSEC_MAX_IV_SIZE       16
12 #define IPSEC_MAX_IV_QWORD      (IPSEC_MAX_IV_SIZE / sizeof(uint64_t))
13
14 /* padding alignment for different algorithms */
15 enum {
16         IPSEC_PAD_DEFAULT = 4,
17         IPSEC_PAD_AES_CBC = IPSEC_MAX_IV_SIZE,
18         IPSEC_PAD_AES_GCM = IPSEC_PAD_DEFAULT,
19         IPSEC_PAD_NULL = IPSEC_PAD_DEFAULT,
20 };
21
22 /* these definitions probably has to be in rte_crypto_sym.h */
23 union sym_op_ofslen {
24         uint64_t raw;
25         struct {
26                 uint32_t offset;
27                 uint32_t length;
28         };
29 };
30
31 union sym_op_data {
32 #ifdef __SIZEOF_INT128__
33         __uint128_t raw;
34 #endif
35         struct {
36                 uint8_t *va;
37                 rte_iova_t pa;
38         };
39 };
40
41 #define REPLAY_SQN_NUM          2
42 #define REPLAY_SQN_NEXT(n)      ((n) ^ 1)
43
44 struct replay_sqn {
45         rte_rwlock_t rwl;
46         uint64_t sqn;
47         __extension__ uint64_t window[0];
48 };
49
50 struct rte_ipsec_sa {
51         uint64_t type;     /* type of given SA */
52         uint64_t udata;    /* user defined */
53         uint32_t size;     /* size of given sa object */
54         uint32_t spi;
55         /* sqn calculations related */
56         uint64_t sqn_mask;
57         struct {
58                 uint32_t win_sz;
59                 uint16_t nb_bucket;
60                 uint16_t bucket_index_mask;
61         } replay;
62         /* template for crypto op fields */
63         struct {
64                 union sym_op_ofslen cipher;
65                 union sym_op_ofslen auth;
66         } ctp;
67         uint32_t salt;
68         uint8_t proto;    /* next proto */
69         uint8_t aad_len;
70         uint8_t hdr_len;
71         uint8_t hdr_l3_off;
72         uint8_t icv_len;
73         uint8_t sqh_len;
74         uint8_t iv_ofs; /* offset for algo-specific IV inside crypto op */
75         uint8_t iv_len;
76         uint8_t pad_align;
77
78         /* template for tunnel header */
79         uint8_t hdr[IPSEC_MAX_HDR_SIZE];
80
81         /*
82          * sqn and replay window
83          * In case of SA handled by multiple threads *sqn* cacheline
84          * could be shared by multiple cores.
85          * To minimise perfomance impact, we try to locate in a separate
86          * place from other frequently accesed data.
87          */
88         union {
89                 union {
90                         rte_atomic64_t atom;
91                         uint64_t raw;
92                 } outb;
93                 struct {
94                         uint32_t rdidx; /* read index */
95                         uint32_t wridx; /* write index */
96                         struct replay_sqn *rsn[REPLAY_SQN_NUM];
97                 } inb;
98         } sqn;
99
100 } __rte_cache_aligned;
101
102 int
103 ipsec_sa_pkt_func_select(const struct rte_ipsec_session *ss,
104         const struct rte_ipsec_sa *sa, struct rte_ipsec_sa_pkt_func *pf);
105
106 #endif /* _SA_H_ */