]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/crypto/hisilicon/sec2/sec.h
crypto: hisilicon/sec2 - Add iommu status check
[mirror_ubuntu-hirsute-kernel.git] / drivers / crypto / hisilicon / sec2 / sec.h
CommitLineData
416d8220
ZX
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2019 HiSilicon Limited. */
3
4#ifndef __HISI_SEC_V2_H
5#define __HISI_SEC_V2_H
6
7#include <linux/list.h>
8
9#include "../qm.h"
10#include "sec_crypto.h"
11
a181647c
ZX
12/* Algorithm resource per hardware SEC queue */
13struct sec_alg_res {
416d8220
ZX
14 u8 *c_ivin;
15 dma_addr_t c_ivin_dma;
2f072d75
ZX
16 u8 *out_mac;
17 dma_addr_t out_mac_dma;
416d8220
ZX
18};
19
20/* Cipher request of SEC private */
21struct sec_cipher_req {
22 struct hisi_acc_hw_sgl *c_in;
23 dma_addr_t c_in_dma;
24 struct hisi_acc_hw_sgl *c_out;
25 dma_addr_t c_out_dma;
416d8220
ZX
26 struct skcipher_request *sk_req;
27 u32 c_len;
28 bool encrypt;
29};
30
2f072d75
ZX
31struct sec_aead_req {
32 u8 *out_mac;
33 dma_addr_t out_mac_dma;
34 struct aead_request *aead_req;
35};
36
416d8220
ZX
37/* SEC request of Crypto */
38struct sec_req {
39 struct sec_sqe sec_sqe;
40 struct sec_ctx *ctx;
41 struct sec_qp_ctx *qp_ctx;
42
416d8220 43 struct sec_cipher_req c_req;
2f072d75
ZX
44 struct sec_aead_req aead_req;
45
416d8220
ZX
46 int err_type;
47 int req_id;
48
49 /* Status of the SEC request */
ca0d158d 50 bool fake_busy;
416d8220
ZX
51};
52
53/**
54 * struct sec_req_op - Operations for SEC request
416d8220
ZX
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
61 */
62struct sec_req_op {
416d8220
ZX
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);
310ea0ac 68 void (*callback)(struct sec_ctx *ctx, struct sec_req *req, int err);
416d8220
ZX
69 int (*process)(struct sec_ctx *ctx, struct sec_req *req);
70};
71
2f072d75
ZX
72/* SEC auth context */
73struct sec_auth_ctx {
74 dma_addr_t a_key_dma;
75 u8 *a_key;
76 u8 a_key_len;
77 u8 mac_len;
78 u8 a_alg;
79 struct crypto_shash *hash_tfm;
80};
81
416d8220
ZX
82/* SEC cipher context which cipher's relatives */
83struct sec_cipher_ctx {
84 u8 *c_key;
85 dma_addr_t c_key_dma;
86 sector_t iv_offset;
87 u32 c_gran_size;
88 u32 ivsize;
89 u8 c_mode;
90 u8 c_alg;
91 u8 c_key_len;
92};
93
94/* SEC queue context which defines queue's relatives */
95struct sec_qp_ctx {
96 struct hisi_qp *qp;
7c7d902a 97 struct sec_req *req_list[QM_Q_DEPTH];
416d8220 98 struct idr req_idr;
7c7d902a 99 struct sec_alg_res res[QM_Q_DEPTH];
416d8220
ZX
100 struct sec_ctx *ctx;
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;
105};
106
2f072d75
ZX
107enum sec_alg_type {
108 SEC_SKCIPHER,
109 SEC_AEAD
110};
111
416d8220
ZX
112/* SEC Crypto TFM context which defines queue and cipher .etc relatives */
113struct sec_ctx {
114 struct sec_qp_ctx *qp_ctx;
115 struct sec_dev *sec;
116 const struct sec_req_op *req_op;
117
118 /* Half queues for encipher, and half for decipher */
119 u32 hlf_q_num;
120
121 /* Threshold for fake busy, trigger to return -EBUSY to user */
122 u32 fake_req_limit;
123
124 /* Currrent cyclic index to select a queue for encipher */
125 atomic_t enc_qcyclic;
126
127 /* Currrent cyclic index to select a queue for decipher */
128 atomic_t dec_qcyclic;
2f072d75
ZX
129
130 enum sec_alg_type alg_type;
416d8220 131 struct sec_cipher_ctx c_ctx;
2f072d75 132 struct sec_auth_ctx a_ctx;
416d8220
ZX
133};
134
135enum sec_endian {
136 SEC_LE = 0,
137 SEC_32BE,
138 SEC_64BE
139};
140
1e9bc276
ZX
141enum sec_debug_file_index {
142 SEC_CURRENT_QM,
143 SEC_CLEAR_ENABLE,
144 SEC_DEBUG_FILE_NUM,
145};
146
147struct sec_debug_file {
148 enum sec_debug_file_index index;
149 spinlock_t lock;
150 struct hisi_qm *qm;
151};
152
153struct sec_dfx {
cb1eeb75
AB
154 atomic64_t send_cnt;
155 atomic64_t recv_cnt;
1e9bc276
ZX
156};
157
158struct sec_debug {
159 struct sec_dfx dfx;
160 struct sec_debug_file files[SEC_DEBUG_FILE_NUM];
161};
162
416d8220
ZX
163struct sec_dev {
164 struct hisi_qm qm;
165 struct list_head list;
1e9bc276 166 struct sec_debug debug;
416d8220 167 u32 ctx_q_num;
8824bc5e 168 bool iommu_used;
73bcb049 169 u32 num_vfs;
416d8220
ZX
170 unsigned long status;
171};
172
173struct sec_dev *sec_find_device(int node);
174int sec_register_to_crypto(void);
175void sec_unregister_from_crypto(void);
176#endif