1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 HiSilicon Limited. */
4 #ifndef __HISI_SEC_V2_H
5 #define __HISI_SEC_V2_H
7 #include <linux/hisi_acc_qm.h>
8 #include "sec_crypto.h"
10 /* Algorithm resource per hardware SEC queue */
15 dma_addr_t c_ivin_dma;
17 dma_addr_t a_ivin_dma;
19 dma_addr_t out_mac_dma;
23 /* Cipher request of SEC private */
24 struct sec_cipher_req {
25 struct hisi_acc_hw_sgl *c_out;
28 dma_addr_t c_ivin_dma;
29 struct skcipher_request *sk_req;
36 dma_addr_t out_mac_dma;
38 dma_addr_t a_ivin_dma;
39 struct aead_request *aead_req;
42 /* SEC request of Crypto */
45 struct sec_sqe sec_sqe;
46 struct sec_sqe3 sec_sqe3;
49 struct sec_qp_ctx *qp_ctx;
52 * Common parameter of the SEC request.
54 struct hisi_acc_hw_sgl *in;
56 struct sec_cipher_req c_req;
57 struct sec_aead_req aead_req;
58 struct list_head backlog_head;
64 /* Status of the SEC request */
70 * struct sec_req_op - Operations for SEC request
71 * @buf_map: DMA map the SGL buffers of the request
72 * @buf_unmap: DMA unmap the SGL buffers of the request
73 * @bd_fill: Fill the SEC queue BD
74 * @bd_send: Send the SEC BD into the hardware queue
75 * @callback: Call back for the request
76 * @process: Main processing logic of Skcipher
79 int (*buf_map)(struct sec_ctx *ctx, struct sec_req *req);
80 void (*buf_unmap)(struct sec_ctx *ctx, struct sec_req *req);
81 void (*do_transfer)(struct sec_ctx *ctx, struct sec_req *req);
82 int (*bd_fill)(struct sec_ctx *ctx, struct sec_req *req);
83 int (*bd_send)(struct sec_ctx *ctx, struct sec_req *req);
84 void (*callback)(struct sec_ctx *ctx, struct sec_req *req, int err);
85 int (*process)(struct sec_ctx *ctx, struct sec_req *req);
88 /* SEC auth context */
96 struct crypto_shash *hash_tfm;
97 struct crypto_aead *fallback_aead_tfm;
100 /* SEC cipher context which cipher's relatives */
101 struct sec_cipher_ctx {
103 dma_addr_t c_key_dma;
111 /* add software support */
113 struct crypto_sync_skcipher *fbtfm;
116 /* SEC queue context which defines queue's relatives */
119 struct sec_req **req_list;
121 struct sec_alg_res *res;
124 struct list_head backlog;
125 struct hisi_acc_sgl_pool *c_in_pool;
126 struct hisi_acc_sgl_pool *c_out_pool;
134 /* SEC Crypto TFM context which defines queue and cipher .etc relatives */
136 struct sec_qp_ctx *qp_ctx;
138 const struct sec_req_op *req_op;
139 struct hisi_qp **qps;
141 /* Half queues for encipher, and half for decipher */
144 /* Threshold for fake busy, trigger to return -EBUSY to user */
147 /* Current cyclic index to select a queue for encipher */
148 atomic_t enc_qcyclic;
150 /* Current cyclic index to select a queue for decipher */
151 atomic_t dec_qcyclic;
153 enum sec_alg_type alg_type;
155 struct sec_cipher_ctx c_ctx;
156 struct sec_auth_ctx a_ctx;
162 enum sec_debug_file_index {
167 struct sec_debug_file {
168 enum sec_debug_file_index index;
176 atomic64_t send_busy_cnt;
177 atomic64_t recv_busy_cnt;
178 atomic64_t err_bd_cnt;
179 atomic64_t invalid_req_cnt;
180 atomic64_t done_flag_cnt;
185 struct sec_debug_file files[SEC_DEBUG_FILE_NUM];
190 struct sec_debug debug;
196 SEC_QM_NFE_MASK_CAP = 0x0,
197 SEC_QM_RESET_MASK_CAP,
198 SEC_QM_OOO_SHUTDOWN_MASK_CAP,
202 SEC_OOO_SHUTDOWN_MASK_CAP,
205 SEC_CORE_TYPE_NUM_CAP,
207 SEC_CORES_PER_CLUSTER_NUM_CAP,
208 SEC_CORE_ENABLE_BITMAP,
209 SEC_DRV_ALG_BITMAP_LOW,
210 SEC_DRV_ALG_BITMAP_HIGH,
211 SEC_DEV_ALG_BITMAP_LOW,
212 SEC_DEV_ALG_BITMAP_HIGH,
213 SEC_CORE1_ALG_BITMAP_LOW,
214 SEC_CORE1_ALG_BITMAP_HIGH,
215 SEC_CORE2_ALG_BITMAP_LOW,
216 SEC_CORE2_ALG_BITMAP_HIGH,
217 SEC_CORE3_ALG_BITMAP_LOW,
218 SEC_CORE3_ALG_BITMAP_HIGH,
219 SEC_CORE4_ALG_BITMAP_LOW,
220 SEC_CORE4_ALG_BITMAP_HIGH,
223 void sec_destroy_qps(struct hisi_qp **qps, int qp_num);
224 struct hisi_qp **sec_create_qps(void);
225 int sec_register_to_crypto(struct hisi_qm *qm);
226 void sec_unregister_from_crypto(struct hisi_qm *qm);
227 u64 sec_get_alg_bitmap(struct hisi_qm *qm, u32 high, u32 low);