1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef _CNXK_CRYPTODEV_OPS_H_
6 #define _CNXK_CRYPTODEV_OPS_H_
8 #include <rte_cryptodev.h>
9 #include <rte_event_crypto_adapter.h>
13 #define CNXK_CPT_MIN_HEADROOM_REQ 24
14 #define CNXK_CPT_MIN_TAILROOM_REQ 102
16 /* Default command timeout in seconds */
17 #define DEFAULT_COMMAND_TIMEOUT 4
19 #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
21 /* Macros to form words in CPT instruction */
22 #define CNXK_CPT_INST_W2(tag, tt, grp, rvu_pf_func) \
23 ((tag) | ((uint64_t)(tt) << 32) | ((uint64_t)(grp) << 34) | \
24 ((uint64_t)(rvu_pf_func) << 48))
25 #define CNXK_CPT_INST_W3(qord, wqe_ptr) \
26 (qord | ((uintptr_t)(wqe_ptr) >> 3) << 3)
28 struct cpt_qp_meta_info {
29 struct rte_mempool *pool;
33 #define CPT_OP_FLAGS_METABUF (1 << 1)
34 #define CPT_OP_FLAGS_AUTH_VERIFY (1 << 0)
35 #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
37 struct cpt_inflight_req {
39 struct rte_crypto_op *cop;
43 } __rte_aligned(ROC_ALIGN);
45 PLT_STATIC_ASSERT(sizeof(struct cpt_inflight_req) == ROC_CACHE_LINE_SZ);
47 struct pending_queue {
48 /** Array of pending requests */
49 struct cpt_inflight_req *req_queue;
50 /** Head of the queue to be used for enqueue */
52 /** Tail of the queue to be used for dequeue */
54 /** Pending queue mask */
56 /** Timeout to track h/w being unresponsive */
60 struct crypto_adpter_info {
62 /**< Set if queue pair is added to crypto adapter */
63 struct rte_mempool *req_mp;
64 /**< CPT inflight request mempool */
70 struct pending_queue pend_q;
72 struct rte_mempool *sess_mp;
73 /**< Session mempool */
74 struct rte_mempool *sess_mp_priv;
75 /**< Session private data mempool */
76 struct cpt_qp_meta_info meta_info;
77 /**< Metabuf info required to support operations on the queue pair */
78 struct roc_cpt_lmtline lmtline;
79 /**< Lmtline information */
80 struct crypto_adpter_info ca;
81 /**< Crypto adapter related info */
84 int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
85 struct rte_cryptodev_config *conf);
87 int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
89 void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
91 int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
93 void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
94 struct rte_cryptodev_info *info);
96 int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
97 const struct rte_cryptodev_qp_conf *conf,
98 int socket_id __rte_unused);
100 int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
102 unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
104 int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
105 struct rte_crypto_sym_xform *xform,
106 struct rte_cryptodev_sym_session *sess,
107 struct rte_mempool *pool);
109 int sym_session_configure(struct roc_cpt *roc_cpt, int driver_id,
110 struct rte_crypto_sym_xform *xform,
111 struct rte_cryptodev_sym_session *sess,
112 struct rte_mempool *pool);
114 void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev,
115 struct rte_cryptodev_sym_session *sess);
117 void sym_session_clear(int driver_id, struct rte_cryptodev_sym_session *sess);
119 unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
121 void cnxk_ae_session_clear(struct rte_cryptodev *dev,
122 struct rte_cryptodev_asym_session *sess);
123 int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
124 struct rte_crypto_asym_xform *xform,
125 struct rte_cryptodev_asym_session *sess);
126 void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
128 static inline union rte_event_crypto_metadata *
129 cnxk_event_crypto_mdata_get(struct rte_crypto_op *op)
131 union rte_event_crypto_metadata *ec_mdata;
133 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
134 ec_mdata = rte_cryptodev_sym_session_get_user_data(
136 else if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS &&
137 op->private_data_offset)
138 ec_mdata = (union rte_event_crypto_metadata
139 *)((uint8_t *)op + op->private_data_offset);
146 static __rte_always_inline void
147 pending_queue_advance(uint64_t *index, const uint64_t mask)
149 *index = (*index + 1) & mask;
152 static __rte_always_inline void
153 pending_queue_retreat(uint64_t *index, const uint64_t mask, uint64_t nb_entry)
155 *index = (*index - nb_entry) & mask;
158 static __rte_always_inline uint64_t
159 pending_queue_infl_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
162 * Mask is nb_desc - 1. Add nb_desc to head and mask to account for
163 * cases when tail > head, which happens during wrap around.
165 return ((head + mask + 1) - tail) & mask;
168 static __rte_always_inline uint64_t
169 pending_queue_free_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
171 /* mask is nb_desc - 1 */
172 return mask - pending_queue_infl_cnt(head, tail, mask);
175 #endif /* _CNXK_CRYPTODEV_OPS_H_ */