mempool: fix slow allocation of large mempools
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev_hw_access.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef _OTX2_CRYPTODEV_HW_ACCESS_H_
6 #define _OTX2_CRYPTODEV_HW_ACCESS_H_
7
8 #include <stdint.h>
9
10 #include <rte_cryptodev.h>
11 #include <rte_memory.h>
12
13 #include "cpt_common.h"
14 #include "cpt_hw_types.h"
15 #include "cpt_mcode_defines.h"
16
17 #include "otx2_dev.h"
18
19 /* CPT instruction queue length */
20 #define OTX2_CPT_IQ_LEN                 8200
21
22 #define OTX2_CPT_DEFAULT_CMD_QLEN       OTX2_CPT_IQ_LEN
23
24 /* Mask which selects all engine groups */
25 #define OTX2_CPT_ENG_GRPS_MASK          0xFF
26
27 /* Register offsets */
28
29 /* LMT LF registers */
30 #define OTX2_LMT_LF_LMTLINE(a)          (0x0ull | (uint64_t)(a) << 3)
31
32 /* CPT LF registers */
33 #define OTX2_CPT_LF_CTL                 0x10ull
34 #define OTX2_CPT_LF_INPROG              0x40ull
35 #define OTX2_CPT_LF_MISC_INT            0xb0ull
36 #define OTX2_CPT_LF_MISC_INT_ENA_W1S    0xd0ull
37 #define OTX2_CPT_LF_MISC_INT_ENA_W1C    0xe0ull
38 #define OTX2_CPT_LF_Q_BASE              0xf0ull
39 #define OTX2_CPT_LF_Q_SIZE              0x100ull
40 #define OTX2_CPT_LF_Q_GRP_PTR           0x120ull
41 #define OTX2_CPT_LF_NQ(a)               (0x400ull | (uint64_t)(a) << 3)
42
43 #define OTX2_CPT_AF_LF_CTL(a)           (0x27000ull | (uint64_t)(a) << 3)
44
45 #define OTX2_CPT_LF_BAR2(vf, q_id) \
46                 ((vf)->otx2_dev.bar2 + \
47                  ((RVU_BLOCK_ADDR_CPT0 << 20) | ((q_id) << 12)))
48
49 #define OTX2_CPT_QUEUE_HI_PRIO 0x1
50
51 union otx2_cpt_lf_ctl {
52         uint64_t u;
53         struct {
54                 uint64_t ena                         : 1;
55                 uint64_t fc_ena                      : 1;
56                 uint64_t fc_up_crossing              : 1;
57                 uint64_t reserved_3_3                : 1;
58                 uint64_t fc_hyst_bits                : 4;
59                 uint64_t reserved_8_63               : 56;
60         } s;
61 };
62
63 union otx2_cpt_lf_inprog {
64         uint64_t u;
65         struct {
66                 uint64_t inflight                    : 9;
67                 uint64_t reserved_9_15               : 7;
68                 uint64_t eena                        : 1;
69                 uint64_t grp_drp                     : 1;
70                 uint64_t reserved_18_30              : 13;
71                 uint64_t grb_partial                 : 1;
72                 uint64_t grb_cnt                     : 8;
73                 uint64_t gwb_cnt                     : 8;
74                 uint64_t reserved_48_63              : 16;
75         } s;
76 };
77
78 union otx2_cpt_lf_q_base {
79         uint64_t u;
80         struct {
81                 uint64_t fault                       : 1;
82                 uint64_t stopped                     : 1;
83                 uint64_t reserved_2_6                : 5;
84                 uint64_t addr                        : 46;
85                 uint64_t reserved_53_63              : 11;
86         } s;
87 };
88
89 union otx2_cpt_lf_q_size {
90         uint64_t u;
91         struct {
92                 uint64_t size_div40                  : 15;
93                 uint64_t reserved_15_63              : 49;
94         } s;
95 };
96
97 union otx2_cpt_af_lf_ctl {
98         uint64_t u;
99         struct {
100                 uint64_t pri                         : 1;
101                 uint64_t reserved_1_8                : 8;
102                 uint64_t pf_func_inst                : 1;
103                 uint64_t cont_err                    : 1;
104                 uint64_t reserved_11_15              : 5;
105                 uint64_t nixtx_en                    : 1;
106                 uint64_t reserved_17_47              : 31;
107                 uint64_t grp                         : 8;
108                 uint64_t reserved_56_63              : 8;
109         } s;
110 };
111
112 union otx2_cpt_lf_q_grp_ptr {
113         uint64_t u;
114         struct {
115                 uint64_t dq_ptr                      : 15;
116                 uint64_t reserved_31_15              : 17;
117                 uint64_t nq_ptr                      : 15;
118                 uint64_t reserved_47_62              : 16;
119                 uint64_t xq_xor                      : 1;
120         } s;
121 };
122
123 /*
124  * Enumeration cpt_9x_comp_e
125  *
126  * CPT 9X Completion Enumeration
127  * Enumerates the values of CPT_RES_S[COMPCODE].
128  */
129 enum cpt_9x_comp_e {
130         CPT_9X_COMP_E_NOTDONE = 0x00,
131         CPT_9X_COMP_E_GOOD = 0x01,
132         CPT_9X_COMP_E_FAULT = 0x02,
133         CPT_9X_COMP_E_HWERR = 0x04,
134         CPT_9X_COMP_E_INSTERR = 0x05,
135         CPT_9X_COMP_E_LAST_ENTRY = 0x06
136 };
137
138 struct otx2_cpt_qp {
139         uint32_t id;
140         /**< Queue pair id */
141         uintptr_t base;
142         /**< Base address where BAR is mapped */
143         void *lmtline;
144         /**< Address of LMTLINE */
145         rte_iova_t lf_nq_reg;
146         /**< LF enqueue register address */
147         struct pending_queue pend_q;
148         /**< Pending queue */
149         struct rte_mempool *sess_mp;
150         /**< Session mempool */
151         struct rte_mempool *sess_mp_priv;
152         /**< Session private data mempool */
153         struct cpt_qp_meta_info meta_info;
154         /**< Metabuf info required to support operations on the queue pair */
155         rte_iova_t iq_dma_addr;
156         /**< Instruction queue address */
157 };
158
159 void otx2_cpt_err_intr_unregister(const struct rte_cryptodev *dev);
160
161 int otx2_cpt_err_intr_register(const struct rte_cryptodev *dev);
162
163 int otx2_cpt_iq_enable(const struct rte_cryptodev *dev,
164                        const struct otx2_cpt_qp *qp, uint8_t grp_mask,
165                        uint8_t pri, uint32_t size_div40);
166
167 void otx2_cpt_iq_disable(struct otx2_cpt_qp *qp);
168
169 #endif /* _OTX2_CRYPTODEV_HW_ACCESS_H_ */