1c12cfe62SVolodymyr Fialko /* SPDX-License-Identifier: BSD-3-Clause
2c12cfe62SVolodymyr Fialko * Copyright(C) 2023 Marvell.
3c12cfe62SVolodymyr Fialko */
4c12cfe62SVolodymyr Fialko
5c12cfe62SVolodymyr Fialko #ifndef PDCP_REORDER_H
6c12cfe62SVolodymyr Fialko #define PDCP_REORDER_H
7c12cfe62SVolodymyr Fialko
8c12cfe62SVolodymyr Fialko #include <rte_reorder.h>
9c12cfe62SVolodymyr Fialko
10c12cfe62SVolodymyr Fialko struct pdcp_reorder {
11c12cfe62SVolodymyr Fialko struct rte_reorder_buffer *buf;
12c12cfe62SVolodymyr Fialko bool is_active;
13c12cfe62SVolodymyr Fialko };
14c12cfe62SVolodymyr Fialko
15*af42b2d1SVolodymyr Fialko int pdcp_reorder_create(struct pdcp_reorder *reorder, size_t nb_elem, void *mem, size_t mem_size);
16*af42b2d1SVolodymyr Fialko
17*af42b2d1SVolodymyr Fialko /* NOTE: replace with `rte_reorder_memory_footprint_get` after DPDK 23.07 */
18*af42b2d1SVolodymyr Fialko #define SIZE_OF_REORDER_BUFFER (4 * RTE_CACHE_LINE_SIZE)
19*af42b2d1SVolodymyr Fialko static inline size_t
pdcp_reorder_memory_footprint_get(size_t nb_elem)20*af42b2d1SVolodymyr Fialko pdcp_reorder_memory_footprint_get(size_t nb_elem)
21*af42b2d1SVolodymyr Fialko {
22*af42b2d1SVolodymyr Fialko return SIZE_OF_REORDER_BUFFER + (2 * nb_elem * sizeof(struct rte_mbuf *));
23*af42b2d1SVolodymyr Fialko }
24c12cfe62SVolodymyr Fialko
25c12cfe62SVolodymyr Fialko static inline uint32_t
pdcp_reorder_get_sequential(struct pdcp_reorder * reorder,struct rte_mbuf ** mbufs,uint32_t max_mbufs)26c12cfe62SVolodymyr Fialko pdcp_reorder_get_sequential(struct pdcp_reorder *reorder, struct rte_mbuf **mbufs,
27c12cfe62SVolodymyr Fialko uint32_t max_mbufs)
28c12cfe62SVolodymyr Fialko {
29c12cfe62SVolodymyr Fialko return rte_reorder_drain(reorder->buf, mbufs, max_mbufs);
30c12cfe62SVolodymyr Fialko }
31c12cfe62SVolodymyr Fialko
32c12cfe62SVolodymyr Fialko static inline uint32_t
pdcp_reorder_up_to_get(struct pdcp_reorder * reorder,struct rte_mbuf ** mbufs,uint32_t max_mbufs,uint32_t seqn)33c12cfe62SVolodymyr Fialko pdcp_reorder_up_to_get(struct pdcp_reorder *reorder, struct rte_mbuf **mbufs,
34c12cfe62SVolodymyr Fialko uint32_t max_mbufs, uint32_t seqn)
35c12cfe62SVolodymyr Fialko {
36c12cfe62SVolodymyr Fialko return rte_reorder_drain_up_to_seqn(reorder->buf, mbufs, max_mbufs, seqn);
37c12cfe62SVolodymyr Fialko }
38c12cfe62SVolodymyr Fialko
39c12cfe62SVolodymyr Fialko static inline void
pdcp_reorder_start(struct pdcp_reorder * reorder,uint32_t min_seqn)40c12cfe62SVolodymyr Fialko pdcp_reorder_start(struct pdcp_reorder *reorder, uint32_t min_seqn)
41c12cfe62SVolodymyr Fialko {
42c12cfe62SVolodymyr Fialko int ret;
43c12cfe62SVolodymyr Fialko
44c12cfe62SVolodymyr Fialko reorder->is_active = true;
45c12cfe62SVolodymyr Fialko
46c12cfe62SVolodymyr Fialko ret = rte_reorder_min_seqn_set(reorder->buf, min_seqn);
47c12cfe62SVolodymyr Fialko RTE_VERIFY(ret == 0);
48c12cfe62SVolodymyr Fialko }
49c12cfe62SVolodymyr Fialko
50c12cfe62SVolodymyr Fialko static inline void
pdcp_reorder_stop(struct pdcp_reorder * reorder)51c12cfe62SVolodymyr Fialko pdcp_reorder_stop(struct pdcp_reorder *reorder)
52c12cfe62SVolodymyr Fialko {
53c12cfe62SVolodymyr Fialko reorder->is_active = false;
54c12cfe62SVolodymyr Fialko }
55c12cfe62SVolodymyr Fialko
56c12cfe62SVolodymyr Fialko static inline void
pdcp_reorder_insert(struct pdcp_reorder * reorder,struct rte_mbuf * mbuf,rte_reorder_seqn_t pkt_count)57c12cfe62SVolodymyr Fialko pdcp_reorder_insert(struct pdcp_reorder *reorder, struct rte_mbuf *mbuf,
58c12cfe62SVolodymyr Fialko rte_reorder_seqn_t pkt_count)
59c12cfe62SVolodymyr Fialko {
60c12cfe62SVolodymyr Fialko int ret;
61c12cfe62SVolodymyr Fialko
62c12cfe62SVolodymyr Fialko *rte_reorder_seqn(mbuf) = pkt_count;
63c12cfe62SVolodymyr Fialko
64c12cfe62SVolodymyr Fialko ret = rte_reorder_insert(reorder->buf, mbuf);
65c12cfe62SVolodymyr Fialko RTE_VERIFY(ret == 0);
66c12cfe62SVolodymyr Fialko }
67c12cfe62SVolodymyr Fialko
68c12cfe62SVolodymyr Fialko #endif /* PDCP_REORDER_H */
69