crypto/nitrox: add burst enqueue and dequeue ops
[dpdk.git] / drivers / crypto / nitrox / nitrox_qp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef _NITROX_QP_H_
6 #define _NITROX_QP_H_
7
8 #include <stdbool.h>
9
10 #include <rte_io.h>
11
12 struct nitrox_softreq;
13
14 struct command_queue {
15         const struct rte_memzone *mz;
16         uint8_t *dbell_csr_addr;
17         uint8_t *ring;
18         uint8_t instr_size;
19 };
20
21 struct rid {
22         struct nitrox_softreq *sr;
23 };
24
25 struct nitrox_qp {
26         struct command_queue cmdq;
27         struct rid *ridq;
28         uint32_t count;
29         uint32_t head;
30         uint32_t tail;
31         struct rte_mempool *sr_mp;
32         struct rte_cryptodev_stats stats;
33         uint16_t qno;
34         rte_atomic16_t pending_count;
35 };
36
37 static inline uint16_t
38 nitrox_qp_free_count(struct nitrox_qp *qp)
39 {
40         uint16_t pending_count = rte_atomic16_read(&qp->pending_count);
41
42         RTE_ASSERT(qp->count >= pending_count);
43         return (qp->count - pending_count);
44 }
45
46 static inline bool
47 nitrox_qp_is_empty(struct nitrox_qp *qp)
48 {
49         return (rte_atomic16_read(&qp->pending_count) == 0);
50 }
51
52 static inline uint16_t
53 nitrox_qp_used_count(struct nitrox_qp *qp)
54 {
55         return rte_atomic16_read(&qp->pending_count);
56 }
57
58 static inline struct nitrox_softreq *
59 nitrox_qp_get_softreq(struct nitrox_qp *qp)
60 {
61         uint32_t tail = qp->tail % qp->count;
62
63         rte_smp_rmb();
64         return qp->ridq[tail].sr;
65 }
66
67 static inline void
68 nitrox_ring_dbell(struct nitrox_qp *qp, uint16_t cnt)
69 {
70         struct command_queue *cmdq = &qp->cmdq;
71
72         if (!cnt)
73                 return;
74
75         rte_io_wmb();
76         rte_write64(cnt, cmdq->dbell_csr_addr);
77 }
78
79 static inline void
80 nitrox_qp_enqueue(struct nitrox_qp *qp, void *instr, struct nitrox_softreq *sr)
81 {
82         uint32_t head = qp->head % qp->count;
83
84         qp->head++;
85         memcpy(&qp->cmdq.ring[head * qp->cmdq.instr_size],
86                instr, qp->cmdq.instr_size);
87         qp->ridq[head].sr = sr;
88         rte_smp_wmb();
89         rte_atomic16_inc(&qp->pending_count);
90 }
91
92 static inline void
93 nitrox_qp_dequeue(struct nitrox_qp *qp)
94 {
95         qp->tail++;
96         rte_atomic16_dec(&qp->pending_count);
97 }
98
99 int nitrox_qp_setup(struct nitrox_qp *qp, uint8_t *bar_addr,
100                     const char *dev_name, uint32_t nb_descriptors,
101                     uint8_t inst_size, int socket_id);
102 int nitrox_qp_release(struct nitrox_qp *qp, uint8_t *bar_addr);
103
104 #endif /* _NITROX_QP_H_ */