xref: /freebsd/sys/dev/qat/include/qat_ocf_mem_pool.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1*78ee8d1cSJulian Grajkowski /* SPDX-License-Identifier: BSD-3-Clause */
2*78ee8d1cSJulian Grajkowski /* Copyright(c) 2007-2022 Intel Corporation */
3*78ee8d1cSJulian Grajkowski #ifndef _QAT_OCF_MEM_POOL_H_
4*78ee8d1cSJulian Grajkowski #define _QAT_OCF_MEM_POOL_H_
5*78ee8d1cSJulian Grajkowski 
6*78ee8d1cSJulian Grajkowski /* System headers */
7*78ee8d1cSJulian Grajkowski #include <sys/types.h>
8*78ee8d1cSJulian Grajkowski 
9*78ee8d1cSJulian Grajkowski /* QAT specific headers */
10*78ee8d1cSJulian Grajkowski #include "cpa.h"
11*78ee8d1cSJulian Grajkowski #include "cpa_cy_sym_dp.h"
12*78ee8d1cSJulian Grajkowski #include "icp_qat_fw_la.h"
13*78ee8d1cSJulian Grajkowski 
14*78ee8d1cSJulian Grajkowski #define QAT_OCF_MAX_LEN (64 * 1024)
15*78ee8d1cSJulian Grajkowski #define QAT_OCF_MAX_FLATS (32)
16*78ee8d1cSJulian Grajkowski #define QAT_OCF_MAX_DIGEST SHA512_DIGEST_LENGTH
17*78ee8d1cSJulian Grajkowski #define QAT_OCF_MAX_SYMREQ (256)
18*78ee8d1cSJulian Grajkowski #define QAT_OCF_MEM_POOL_SIZE ((QAT_OCF_MAX_SYMREQ * 2 + 1) * 2)
19*78ee8d1cSJulian Grajkowski #define QAT_OCF_MAXLEN 64 * 1024
20*78ee8d1cSJulian Grajkowski 
21*78ee8d1cSJulian Grajkowski /* Dedicated structure due to flexible arrays not allowed to be
22*78ee8d1cSJulian Grajkowski  * allocated on stack */
23*78ee8d1cSJulian Grajkowski struct qat_ocf_buffer_list {
24*78ee8d1cSJulian Grajkowski 	Cpa64U reserved0;
25*78ee8d1cSJulian Grajkowski 	Cpa32U numBuffers;
26*78ee8d1cSJulian Grajkowski 	Cpa32U reserved1;
27*78ee8d1cSJulian Grajkowski 	CpaPhysFlatBuffer flatBuffers[QAT_OCF_MAX_FLATS];
28*78ee8d1cSJulian Grajkowski };
29*78ee8d1cSJulian Grajkowski 
30*78ee8d1cSJulian Grajkowski struct qat_ocf_dma_mem {
31*78ee8d1cSJulian Grajkowski 	bus_dma_tag_t dma_tag;
32*78ee8d1cSJulian Grajkowski 	bus_dmamap_t dma_map;
33*78ee8d1cSJulian Grajkowski 	bus_dma_segment_t dma_seg;
34*78ee8d1cSJulian Grajkowski 	void *dma_vaddr;
35*78ee8d1cSJulian Grajkowski } __aligned(64);
36*78ee8d1cSJulian Grajkowski 
37*78ee8d1cSJulian Grajkowski struct qat_ocf_cookie {
38*78ee8d1cSJulian Grajkowski 	/* Source SGLs */
39*78ee8d1cSJulian Grajkowski 	struct qat_ocf_buffer_list src_buffers;
40*78ee8d1cSJulian Grajkowski 	/* Destination SGL */
41*78ee8d1cSJulian Grajkowski 	struct qat_ocf_buffer_list dst_buffers;
42*78ee8d1cSJulian Grajkowski 
43*78ee8d1cSJulian Grajkowski 	/* Cache OP data */
44*78ee8d1cSJulian Grajkowski 	CpaCySymDpOpData pOpdata;
45*78ee8d1cSJulian Grajkowski 
46*78ee8d1cSJulian Grajkowski 	/* IV max size taken from cryptdev */
47*78ee8d1cSJulian Grajkowski 	uint8_t qat_ocf_iv_buf[EALG_MAX_BLOCK_LEN];
48*78ee8d1cSJulian Grajkowski 	bus_addr_t qat_ocf_iv_buf_paddr;
49*78ee8d1cSJulian Grajkowski 	uint8_t qat_ocf_digest[QAT_OCF_MAX_DIGEST];
50*78ee8d1cSJulian Grajkowski 	bus_addr_t qat_ocf_digest_paddr;
51*78ee8d1cSJulian Grajkowski 	/* Used only in case of separated AAD and GCM, CCM and RC4 */
52*78ee8d1cSJulian Grajkowski 	uint8_t qat_ocf_gcm_aad[ICP_QAT_FW_CCM_GCM_AAD_SZ_MAX];
53*78ee8d1cSJulian Grajkowski 	bus_addr_t qat_ocf_gcm_aad_paddr;
54*78ee8d1cSJulian Grajkowski 
55*78ee8d1cSJulian Grajkowski 	/* Source SGLs */
56*78ee8d1cSJulian Grajkowski 	struct qat_ocf_dma_mem src_dma_mem;
57*78ee8d1cSJulian Grajkowski 	bus_addr_t src_buffer_list_paddr;
58*78ee8d1cSJulian Grajkowski 
59*78ee8d1cSJulian Grajkowski 	/* Destination SGL */
60*78ee8d1cSJulian Grajkowski 	struct qat_ocf_dma_mem dst_dma_mem;
61*78ee8d1cSJulian Grajkowski 	bus_addr_t dst_buffer_list_paddr;
62*78ee8d1cSJulian Grajkowski 
63*78ee8d1cSJulian Grajkowski 	/* AAD - used only if separated AAD is used by OCF and HW requires
64*78ee8d1cSJulian Grajkowski 	 * to have it at the beginning of source buffer */
65*78ee8d1cSJulian Grajkowski 	struct qat_ocf_dma_mem gcm_aad_dma_mem;
66*78ee8d1cSJulian Grajkowski 	bus_addr_t gcm_aad_buffer_list_paddr;
67*78ee8d1cSJulian Grajkowski 	CpaBoolean is_sep_aad_used;
68*78ee8d1cSJulian Grajkowski 
69*78ee8d1cSJulian Grajkowski 	/* Cache OP data */
70*78ee8d1cSJulian Grajkowski 	bus_addr_t pOpData_paddr;
71*78ee8d1cSJulian Grajkowski 	/* misc */
72*78ee8d1cSJulian Grajkowski 	struct cryptop *crp_op;
73*78ee8d1cSJulian Grajkowski 
74*78ee8d1cSJulian Grajkowski 	/* This cookie tag and map */
75*78ee8d1cSJulian Grajkowski 	bus_dma_tag_t dma_tag;
76*78ee8d1cSJulian Grajkowski 	bus_dmamap_t dma_map;
77*78ee8d1cSJulian Grajkowski };
78*78ee8d1cSJulian Grajkowski 
79*78ee8d1cSJulian Grajkowski struct qat_ocf_session {
80*78ee8d1cSJulian Grajkowski 	CpaCySymSessionCtx sessionCtx;
81*78ee8d1cSJulian Grajkowski 	Cpa32U sessionCtxSize;
82*78ee8d1cSJulian Grajkowski 	Cpa32U authLen;
83*78ee8d1cSJulian Grajkowski 	Cpa32U aadLen;
84*78ee8d1cSJulian Grajkowski };
85*78ee8d1cSJulian Grajkowski 
86*78ee8d1cSJulian Grajkowski struct qat_ocf_dsession {
87*78ee8d1cSJulian Grajkowski 	struct qat_ocf_instance *qatInstance;
88*78ee8d1cSJulian Grajkowski 	struct qat_ocf_session encSession;
89*78ee8d1cSJulian Grajkowski 	struct qat_ocf_session decSession;
90*78ee8d1cSJulian Grajkowski };
91*78ee8d1cSJulian Grajkowski 
92*78ee8d1cSJulian Grajkowski struct qat_ocf_load_cb_arg {
93*78ee8d1cSJulian Grajkowski 	struct cryptop *crp_op;
94*78ee8d1cSJulian Grajkowski 	struct qat_ocf_cookie *qat_cookie;
95*78ee8d1cSJulian Grajkowski 	CpaCySymDpOpData *pOpData;
96*78ee8d1cSJulian Grajkowski 	int error;
97*78ee8d1cSJulian Grajkowski };
98*78ee8d1cSJulian Grajkowski 
99*78ee8d1cSJulian Grajkowski struct qat_ocf_instance {
100*78ee8d1cSJulian Grajkowski 	CpaInstanceHandle cyInstHandle;
101*78ee8d1cSJulian Grajkowski 	struct mtx cyInstMtx;
102*78ee8d1cSJulian Grajkowski 	struct qat_ocf_dma_mem cookie_dmamem[QAT_OCF_MEM_POOL_SIZE];
103*78ee8d1cSJulian Grajkowski 	struct qat_ocf_cookie *cookie_pool[QAT_OCF_MEM_POOL_SIZE];
104*78ee8d1cSJulian Grajkowski 	struct qat_ocf_cookie *free_cookie[QAT_OCF_MEM_POOL_SIZE];
105*78ee8d1cSJulian Grajkowski 	int free_cookie_ptr;
106*78ee8d1cSJulian Grajkowski 	struct mtx cookie_pool_mtx;
107*78ee8d1cSJulian Grajkowski 	int32_t driver_id;
108*78ee8d1cSJulian Grajkowski };
109*78ee8d1cSJulian Grajkowski 
110*78ee8d1cSJulian Grajkowski /* Init/deinit */
111*78ee8d1cSJulian Grajkowski CpaStatus qat_ocf_cookie_pool_init(struct qat_ocf_instance *instance,
112*78ee8d1cSJulian Grajkowski 				   device_t dev);
113*78ee8d1cSJulian Grajkowski void qat_ocf_cookie_pool_deinit(struct qat_ocf_instance *instance);
114*78ee8d1cSJulian Grajkowski /* Alloc/free */
115*78ee8d1cSJulian Grajkowski CpaStatus qat_ocf_cookie_alloc(struct qat_ocf_instance *instance,
116*78ee8d1cSJulian Grajkowski 			       struct qat_ocf_cookie **buffers_out);
117*78ee8d1cSJulian Grajkowski void qat_ocf_cookie_free(struct qat_ocf_instance *instance,
118*78ee8d1cSJulian Grajkowski 			 struct qat_ocf_cookie *cookie);
119*78ee8d1cSJulian Grajkowski /* Pre/post sync */
120*78ee8d1cSJulian Grajkowski CpaStatus qat_ocf_cookie_dma_pre_sync(struct cryptop *crp,
121*78ee8d1cSJulian Grajkowski 				      CpaCySymDpOpData *pOpData);
122*78ee8d1cSJulian Grajkowski CpaStatus qat_ocf_cookie_dma_post_sync(struct cryptop *crp,
123*78ee8d1cSJulian Grajkowski 				       CpaCySymDpOpData *pOpData);
124*78ee8d1cSJulian Grajkowski /* Bus DMA unload */
125*78ee8d1cSJulian Grajkowski CpaStatus qat_ocf_cookie_dma_unload(struct cryptop *crp,
126*78ee8d1cSJulian Grajkowski 				    CpaCySymDpOpData *pOpData);
127*78ee8d1cSJulian Grajkowski /* Bus DMA load callbacks */
128*78ee8d1cSJulian Grajkowski void qat_ocf_crypto_load_buf_cb(void *_arg,
129*78ee8d1cSJulian Grajkowski 				bus_dma_segment_t *segs,
130*78ee8d1cSJulian Grajkowski 				int nseg,
131*78ee8d1cSJulian Grajkowski 				int error);
132*78ee8d1cSJulian Grajkowski void qat_ocf_crypto_load_obuf_cb(void *_arg,
133*78ee8d1cSJulian Grajkowski 				 bus_dma_segment_t *segs,
134*78ee8d1cSJulian Grajkowski 				 int nseg,
135*78ee8d1cSJulian Grajkowski 				 int error);
136*78ee8d1cSJulian Grajkowski void qat_ocf_crypto_load_aadbuf_cb(void *_arg,
137*78ee8d1cSJulian Grajkowski 				   bus_dma_segment_t *segs,
138*78ee8d1cSJulian Grajkowski 				   int nseg,
139*78ee8d1cSJulian Grajkowski 				   int error);
140*78ee8d1cSJulian Grajkowski 
141*78ee8d1cSJulian Grajkowski #endif /* _QAT_OCF_MEM_POOL_H_ */
142