1e0ab0865SAnkur Dwivedi /* SPDX-License-Identifier: BSD-3-Clause
2e0ab0865SAnkur Dwivedi * Copyright(C) 2021 Marvell.
3e0ab0865SAnkur Dwivedi */
4e0ab0865SAnkur Dwivedi
5e0ab0865SAnkur Dwivedi #ifndef _CN9K_CRYPTODEV_OPS_H_
6e0ab0865SAnkur Dwivedi #define _CN9K_CRYPTODEV_OPS_H_
7e0ab0865SAnkur Dwivedi
81094dd94SDavid Marchand #include <rte_compat.h>
9af668035SAkhil Goyal #include <cryptodev_pmd.h>
10e0ab0865SAnkur Dwivedi
11*26bb5c4dSAnoob Joseph #include <hw/cpt.h>
12*26bb5c4dSAnoob Joseph
13*26bb5c4dSAnoob Joseph #if defined(__aarch64__)
14*26bb5c4dSAnoob Joseph #include "roc_io.h"
15*26bb5c4dSAnoob Joseph #else
16*26bb5c4dSAnoob Joseph #include "roc_io_generic.h"
17*26bb5c4dSAnoob Joseph #endif
18*26bb5c4dSAnoob Joseph
19e0ab0865SAnkur Dwivedi extern struct rte_cryptodev_ops cn9k_cpt_ops;
20e0ab0865SAnkur Dwivedi
21*26bb5c4dSAnoob Joseph static inline void
cn9k_cpt_inst_submit(struct cpt_inst_s * inst,uint64_t lmtline,uint64_t io_addr)22*26bb5c4dSAnoob Joseph cn9k_cpt_inst_submit(struct cpt_inst_s *inst, uint64_t lmtline, uint64_t io_addr)
23*26bb5c4dSAnoob Joseph {
24*26bb5c4dSAnoob Joseph uint64_t lmt_status;
25*26bb5c4dSAnoob Joseph
26*26bb5c4dSAnoob Joseph do {
27*26bb5c4dSAnoob Joseph /* Copy CPT command to LMTLINE */
28*26bb5c4dSAnoob Joseph roc_lmt_mov64((void *)lmtline, inst);
29*26bb5c4dSAnoob Joseph
30*26bb5c4dSAnoob Joseph /*
31*26bb5c4dSAnoob Joseph * Make sure compiler does not reorder memcpy and ldeor.
32*26bb5c4dSAnoob Joseph * LMTST transactions are always flushed from the write
33*26bb5c4dSAnoob Joseph * buffer immediately, a DMB is not required to push out
34*26bb5c4dSAnoob Joseph * LMTSTs.
35*26bb5c4dSAnoob Joseph */
36*26bb5c4dSAnoob Joseph rte_io_wmb();
37*26bb5c4dSAnoob Joseph lmt_status = roc_lmt_submit_ldeor(io_addr);
38*26bb5c4dSAnoob Joseph } while (lmt_status == 0);
39*26bb5c4dSAnoob Joseph }
40*26bb5c4dSAnoob Joseph
41*26bb5c4dSAnoob Joseph static __plt_always_inline void
cn9k_cpt_inst_submit_dual(struct cpt_inst_s * inst,uint64_t lmtline,uint64_t io_addr)42*26bb5c4dSAnoob Joseph cn9k_cpt_inst_submit_dual(struct cpt_inst_s *inst, uint64_t lmtline, uint64_t io_addr)
43*26bb5c4dSAnoob Joseph {
44*26bb5c4dSAnoob Joseph uint64_t lmt_status;
45*26bb5c4dSAnoob Joseph
46*26bb5c4dSAnoob Joseph do {
47*26bb5c4dSAnoob Joseph /* Copy 2 CPT inst_s to LMTLINE */
48*26bb5c4dSAnoob Joseph #if defined(RTE_ARCH_ARM64)
49*26bb5c4dSAnoob Joseph volatile const __uint128_t *src128 = (const __uint128_t *)inst;
50*26bb5c4dSAnoob Joseph volatile __uint128_t *dst128 = (__uint128_t *)lmtline;
51*26bb5c4dSAnoob Joseph
52*26bb5c4dSAnoob Joseph dst128[0] = src128[0];
53*26bb5c4dSAnoob Joseph dst128[1] = src128[1];
54*26bb5c4dSAnoob Joseph dst128[2] = src128[2];
55*26bb5c4dSAnoob Joseph dst128[3] = src128[3];
56*26bb5c4dSAnoob Joseph dst128[4] = src128[4];
57*26bb5c4dSAnoob Joseph dst128[5] = src128[5];
58*26bb5c4dSAnoob Joseph dst128[6] = src128[6];
59*26bb5c4dSAnoob Joseph dst128[7] = src128[7];
60*26bb5c4dSAnoob Joseph #else
61*26bb5c4dSAnoob Joseph roc_lmt_mov_seg((void *)lmtline, inst, 8);
62*26bb5c4dSAnoob Joseph #endif
63*26bb5c4dSAnoob Joseph
64*26bb5c4dSAnoob Joseph /*
65*26bb5c4dSAnoob Joseph * Make sure compiler does not reorder memcpy and ldeor.
66*26bb5c4dSAnoob Joseph * LMTST transactions are always flushed from the write
67*26bb5c4dSAnoob Joseph * buffer immediately, a DMB is not required to push out
68*26bb5c4dSAnoob Joseph * LMTSTs.
69*26bb5c4dSAnoob Joseph */
70*26bb5c4dSAnoob Joseph rte_io_wmb();
71*26bb5c4dSAnoob Joseph lmt_status = roc_lmt_submit_ldeor(io_addr);
72*26bb5c4dSAnoob Joseph } while (lmt_status == 0);
73*26bb5c4dSAnoob Joseph }
74*26bb5c4dSAnoob Joseph
7575ee5745SAnoob Joseph void cn9k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev);
7675ee5745SAnoob Joseph
774f7154d6SShijith Thotton __rte_internal
7880bb303dSVolodymyr Fialko uint16_t cn9k_cpt_crypto_adapter_enqueue(uintptr_t base,
794f7154d6SShijith Thotton struct rte_crypto_op *op);
804f7154d6SShijith Thotton __rte_internal
814f7154d6SShijith Thotton uintptr_t cn9k_cpt_crypto_adapter_dequeue(uintptr_t get_work1);
824f7154d6SShijith Thotton
83e0ab0865SAnkur Dwivedi #endif /* _CN9K_CRYPTODEV_OPS_H_ */
84