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/list.h>
10 #include "sec_crypto.h"
12 /* Cipher resource per hardware SEC queue */
13 struct sec_cipher_res {
15 dma_addr_t c_ivin_dma;
18 /* Cipher request of SEC private */
19 struct sec_cipher_req {
20 struct hisi_acc_hw_sgl *c_in;
22 struct hisi_acc_hw_sgl *c_out;
25 dma_addr_t c_ivin_dma;
26 struct skcipher_request *sk_req;
31 /* SEC request of Crypto */
33 struct sec_sqe sec_sqe;
35 struct sec_qp_ctx *qp_ctx;
37 /* Cipher supported only at present */
38 struct sec_cipher_req c_req;
42 /* Status of the SEC request */
47 * struct sec_req_op - Operations for SEC request
48 * @get_res: Get resources for TFM on the SEC device
49 * @resource_alloc: Allocate resources for queue context on the SEC device
50 * @resource_free: Free resources for queue context on the SEC device
51 * @buf_map: DMA map the SGL buffers of the request
52 * @buf_unmap: DMA unmap the SGL buffers of the request
53 * @bd_fill: Fill the SEC queue BD
54 * @bd_send: Send the SEC BD into the hardware queue
55 * @callback: Call back for the request
56 * @process: Main processing logic of Skcipher
59 int (*get_res)(struct sec_ctx *ctx, struct sec_req *req);
60 int (*resource_alloc)(struct sec_ctx *ctx, struct sec_qp_ctx *qp_ctx);
61 void (*resource_free)(struct sec_ctx *ctx, struct sec_qp_ctx *qp_ctx);
62 int (*buf_map)(struct sec_ctx *ctx, struct sec_req *req);
63 void (*buf_unmap)(struct sec_ctx *ctx, struct sec_req *req);
64 void (*do_transfer)(struct sec_ctx *ctx, struct sec_req *req);
65 int (*bd_fill)(struct sec_ctx *ctx, struct sec_req *req);
66 int (*bd_send)(struct sec_ctx *ctx, struct sec_req *req);
67 void (*callback)(struct sec_ctx *ctx, struct sec_req *req);
68 int (*process)(struct sec_ctx *ctx, struct sec_req *req);
71 /* SEC cipher context which cipher's relatives */
72 struct sec_cipher_ctx {
83 /* SEC queue context which defines queue's relatives */
86 struct sec_req **req_list;
90 struct mutex req_lock;
91 struct hisi_acc_sgl_pool *c_in_pool;
92 struct hisi_acc_sgl_pool *c_out_pool;
93 atomic_t pending_reqs;
96 /* SEC Crypto TFM context which defines queue and cipher .etc relatives */
98 struct sec_qp_ctx *qp_ctx;
100 const struct sec_req_op *req_op;
102 /* Half queues for encipher, and half for decipher */
105 /* Threshold for fake busy, trigger to return -EBUSY to user */
108 /* Currrent cyclic index to select a queue for encipher */
109 atomic_t enc_qcyclic;
111 /* Currrent cyclic index to select a queue for decipher */
112 atomic_t dec_qcyclic;
113 struct sec_cipher_ctx c_ctx;
122 enum sec_debug_file_index {
128 struct sec_debug_file {
129 enum sec_debug_file_index index;
141 struct sec_debug_file files[SEC_DEBUG_FILE_NUM];
146 struct list_head list;
147 struct sec_debug debug;
150 unsigned long status;
153 struct sec_dev *sec_find_device(int node);
154 int sec_register_to_crypto(void);
155 void sec_unregister_from_crypto(void);