1935f6e3049dfe9176f3027079f9ddef51f3ec26
[dpdk.git] / lib / librte_ipsec / ipsec_sqn.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _IPSEC_SQN_H_
6 #define _IPSEC_SQN_H_
7
8 #define WINDOW_BUCKET_BITS              6 /* uint64_t */
9 #define WINDOW_BUCKET_SIZE              (1 << WINDOW_BUCKET_BITS)
10 #define WINDOW_BIT_LOC_MASK             (WINDOW_BUCKET_SIZE - 1)
11
12 /* minimum number of bucket, power of 2*/
13 #define WINDOW_BUCKET_MIN               2
14 #define WINDOW_BUCKET_MAX               (INT16_MAX + 1)
15
16 #define IS_ESN(sa)      ((sa)->sqn_mask == UINT64_MAX)
17
18 /*
19  * for given size, calculate required number of buckets.
20  */
21 static uint32_t
22 replay_num_bucket(uint32_t wsz)
23 {
24         uint32_t nb;
25
26         nb = rte_align32pow2(RTE_ALIGN_MUL_CEIL(wsz, WINDOW_BUCKET_SIZE) /
27                 WINDOW_BUCKET_SIZE);
28         nb = RTE_MAX(nb, (uint32_t)WINDOW_BUCKET_MIN);
29
30         return nb;
31 }
32
33 /**
34  * Based on number of buckets calculated required size for the
35  * structure that holds replay window and sequence number (RSN) information.
36  */
37 static size_t
38 rsn_size(uint32_t nb_bucket)
39 {
40         size_t sz;
41         struct replay_sqn *rsn;
42
43         sz = sizeof(*rsn) + nb_bucket * sizeof(rsn->window[0]);
44         sz = RTE_ALIGN_CEIL(sz, RTE_CACHE_LINE_SIZE);
45         return sz;
46 }
47
48 #endif /* _IPSEC_SQN_H_ */