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 /* Algorithm resource per hardware SEC queue */
15 dma_addr_t c_ivin_dma
;
17 dma_addr_t out_mac_dma
;
20 /* Cipher request of SEC private */
21 struct sec_cipher_req
{
22 struct hisi_acc_hw_sgl
*c_in
;
24 struct hisi_acc_hw_sgl
*c_out
;
26 struct skcipher_request
*sk_req
;
33 dma_addr_t out_mac_dma
;
34 struct aead_request
*aead_req
;
37 /* SEC request of Crypto */
39 struct sec_sqe sec_sqe
;
41 struct sec_qp_ctx
*qp_ctx
;
43 struct sec_cipher_req c_req
;
44 struct sec_aead_req aead_req
;
49 /* Status of the SEC request */
54 * struct sec_req_op - Operations for SEC request
55 * @buf_map: DMA map the SGL buffers of the request
56 * @buf_unmap: DMA unmap the SGL buffers of the request
57 * @bd_fill: Fill the SEC queue BD
58 * @bd_send: Send the SEC BD into the hardware queue
59 * @callback: Call back for the request
60 * @process: Main processing logic of Skcipher
63 int (*buf_map
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
64 void (*buf_unmap
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
65 void (*do_transfer
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
66 int (*bd_fill
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
67 int (*bd_send
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
68 void (*callback
)(struct sec_ctx
*ctx
, struct sec_req
*req
, int err
);
69 int (*process
)(struct sec_ctx
*ctx
, struct sec_req
*req
);
72 /* SEC auth context */
79 struct crypto_shash
*hash_tfm
;
82 /* SEC cipher context which cipher's relatives */
83 struct sec_cipher_ctx
{
94 /* SEC queue context which defines queue's relatives */
97 struct sec_req
*req_list
[QM_Q_DEPTH
];
99 struct sec_alg_res res
[QM_Q_DEPTH
];
101 struct mutex req_lock
;
102 struct hisi_acc_sgl_pool
*c_in_pool
;
103 struct hisi_acc_sgl_pool
*c_out_pool
;
104 atomic_t pending_reqs
;
112 /* SEC Crypto TFM context which defines queue and cipher .etc relatives */
114 struct sec_qp_ctx
*qp_ctx
;
116 const struct sec_req_op
*req_op
;
118 /* Half queues for encipher, and half for decipher */
121 /* Threshold for fake busy, trigger to return -EBUSY to user */
124 /* Currrent cyclic index to select a queue for encipher */
125 atomic_t enc_qcyclic
;
127 /* Currrent cyclic index to select a queue for decipher */
128 atomic_t dec_qcyclic
;
130 enum sec_alg_type alg_type
;
131 struct sec_cipher_ctx c_ctx
;
132 struct sec_auth_ctx a_ctx
;
141 enum sec_debug_file_index
{
147 struct sec_debug_file
{
148 enum sec_debug_file_index index
;
160 struct sec_debug_file files
[SEC_DEBUG_FILE_NUM
];
165 struct list_head list
;
166 struct sec_debug debug
;
169 unsigned long status
;
172 struct sec_dev
*sec_find_device(int node
);
173 int sec_register_to_crypto(void);
174 void sec_unregister_from_crypto(void);