1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2014 - 2022 Intel Corporation */
3 #ifndef QAT_BL_H
4 #define QAT_BL_H
5 #include <linux/crypto.h>
6 #include <linux/scatterlist.h>
7 #include <linux/types.h>
8 
9 #define QAT_MAX_BUFF_DESC	4
10 
11 struct qat_alg_buf {
12 	u32 len;
13 	u32 resrvd;
14 	u64 addr;
15 } __packed;
16 
17 struct qat_alg_buf_list {
18 	u64 resrvd;
19 	u32 num_bufs;
20 	u32 num_mapped_bufs;
21 	struct qat_alg_buf buffers[];
22 } __packed;
23 
24 struct qat_alg_fixed_buf_list {
25 	struct qat_alg_buf_list sgl_hdr;
26 	struct qat_alg_buf descriptors[QAT_MAX_BUFF_DESC];
27 } __packed __aligned(64);
28 
29 struct qat_request_buffs {
30 	struct qat_alg_buf_list *bl;
31 	dma_addr_t blp;
32 	struct qat_alg_buf_list *blout;
33 	dma_addr_t bloutp;
34 	size_t sz;
35 	size_t sz_out;
36 	bool sgl_src_valid;
37 	bool sgl_dst_valid;
38 	struct qat_alg_fixed_buf_list sgl_src;
39 	struct qat_alg_fixed_buf_list sgl_dst;
40 };
41 
42 struct qat_sgl_to_bufl_params {
43 	dma_addr_t extra_dst_buff;
44 	size_t sz_extra_dst_buff;
45 	unsigned int sskip;
46 	unsigned int dskip;
47 };
48 
49 void qat_bl_free_bufl(struct adf_accel_dev *accel_dev,
50 		      struct qat_request_buffs *buf);
51 int qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev,
52 		       struct scatterlist *sgl,
53 		       struct scatterlist *sglout,
54 		       struct qat_request_buffs *buf,
55 		       struct qat_sgl_to_bufl_params *params,
56 		       gfp_t flags);
57 
58 static inline gfp_t qat_algs_alloc_flags(struct crypto_async_request *req)
59 {
60 	return req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
61 }
62 
63 int qat_bl_realloc_map_new_dst(struct adf_accel_dev *accel_dev,
64 			       struct scatterlist **newd,
65 			       unsigned int dlen,
66 			       struct qat_request_buffs *qat_bufs,
67 			       gfp_t gfp);
68 
69 #endif
70