xref: /linux/include/linux/ccp.h (revision 63b945091a070d8d4275dc0f7699ba22cd5f9435)
1*63b94509STom Lendacky /*
2*63b94509STom Lendacky  * AMD Cryptographic Coprocessor (CCP) driver
3*63b94509STom Lendacky  *
4*63b94509STom Lendacky  * Copyright (C) 2013 Advanced Micro Devices, Inc.
5*63b94509STom Lendacky  *
6*63b94509STom Lendacky  * Author: Tom Lendacky <thomas.lendacky@amd.com>
7*63b94509STom Lendacky  *
8*63b94509STom Lendacky  * This program is free software; you can redistribute it and/or modify
9*63b94509STom Lendacky  * it under the terms of the GNU General Public License version 2 as
10*63b94509STom Lendacky  * published by the Free Software Foundation.
11*63b94509STom Lendacky  */
12*63b94509STom Lendacky 
13*63b94509STom Lendacky #ifndef __CPP_H__
14*63b94509STom Lendacky #define __CPP_H__
15*63b94509STom Lendacky 
16*63b94509STom Lendacky #include <linux/scatterlist.h>
17*63b94509STom Lendacky #include <linux/workqueue.h>
18*63b94509STom Lendacky #include <linux/list.h>
19*63b94509STom Lendacky #include <crypto/aes.h>
20*63b94509STom Lendacky #include <crypto/sha.h>
21*63b94509STom Lendacky 
22*63b94509STom Lendacky 
23*63b94509STom Lendacky struct ccp_device;
24*63b94509STom Lendacky struct ccp_cmd;
25*63b94509STom Lendacky 
26*63b94509STom Lendacky /**
27*63b94509STom Lendacky  * ccp_enqueue_cmd - queue an operation for processing by the CCP
28*63b94509STom Lendacky  *
29*63b94509STom Lendacky  * @cmd: ccp_cmd struct to be processed
30*63b94509STom Lendacky  *
31*63b94509STom Lendacky  * Refer to the ccp_cmd struct below for required fields.
32*63b94509STom Lendacky  *
33*63b94509STom Lendacky  * Queue a cmd to be processed by the CCP. If queueing the cmd
34*63b94509STom Lendacky  * would exceed the defined length of the cmd queue the cmd will
35*63b94509STom Lendacky  * only be queued if the CCP_CMD_MAY_BACKLOG flag is set and will
36*63b94509STom Lendacky  * result in a return code of -EBUSY.
37*63b94509STom Lendacky  *
38*63b94509STom Lendacky  * The callback routine specified in the ccp_cmd struct will be
39*63b94509STom Lendacky  * called to notify the caller of completion (if the cmd was not
40*63b94509STom Lendacky  * backlogged) or advancement out of the backlog. If the cmd has
41*63b94509STom Lendacky  * advanced out of the backlog the "err" value of the callback
42*63b94509STom Lendacky  * will be -EINPROGRESS. Any other "err" value during callback is
43*63b94509STom Lendacky  * the result of the operation.
44*63b94509STom Lendacky  *
45*63b94509STom Lendacky  * The cmd has been successfully queued if:
46*63b94509STom Lendacky  *   the return code is -EINPROGRESS or
47*63b94509STom Lendacky  *   the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set
48*63b94509STom Lendacky  */
49*63b94509STom Lendacky int ccp_enqueue_cmd(struct ccp_cmd *cmd);
50*63b94509STom Lendacky 
51*63b94509STom Lendacky 
52*63b94509STom Lendacky /***** AES engine *****/
53*63b94509STom Lendacky /**
54*63b94509STom Lendacky  * ccp_aes_type - AES key size
55*63b94509STom Lendacky  *
56*63b94509STom Lendacky  * @CCP_AES_TYPE_128: 128-bit key
57*63b94509STom Lendacky  * @CCP_AES_TYPE_192: 192-bit key
58*63b94509STom Lendacky  * @CCP_AES_TYPE_256: 256-bit key
59*63b94509STom Lendacky  */
60*63b94509STom Lendacky enum ccp_aes_type {
61*63b94509STom Lendacky 	CCP_AES_TYPE_128 = 0,
62*63b94509STom Lendacky 	CCP_AES_TYPE_192,
63*63b94509STom Lendacky 	CCP_AES_TYPE_256,
64*63b94509STom Lendacky 	CCP_AES_TYPE__LAST,
65*63b94509STom Lendacky };
66*63b94509STom Lendacky 
67*63b94509STom Lendacky /**
68*63b94509STom Lendacky  * ccp_aes_mode - AES operation mode
69*63b94509STom Lendacky  *
70*63b94509STom Lendacky  * @CCP_AES_MODE_ECB: ECB mode
71*63b94509STom Lendacky  * @CCP_AES_MODE_CBC: CBC mode
72*63b94509STom Lendacky  * @CCP_AES_MODE_OFB: OFB mode
73*63b94509STom Lendacky  * @CCP_AES_MODE_CFB: CFB mode
74*63b94509STom Lendacky  * @CCP_AES_MODE_CTR: CTR mode
75*63b94509STom Lendacky  * @CCP_AES_MODE_CMAC: CMAC mode
76*63b94509STom Lendacky  */
77*63b94509STom Lendacky enum ccp_aes_mode {
78*63b94509STom Lendacky 	CCP_AES_MODE_ECB = 0,
79*63b94509STom Lendacky 	CCP_AES_MODE_CBC,
80*63b94509STom Lendacky 	CCP_AES_MODE_OFB,
81*63b94509STom Lendacky 	CCP_AES_MODE_CFB,
82*63b94509STom Lendacky 	CCP_AES_MODE_CTR,
83*63b94509STom Lendacky 	CCP_AES_MODE_CMAC,
84*63b94509STom Lendacky 	CCP_AES_MODE__LAST,
85*63b94509STom Lendacky };
86*63b94509STom Lendacky 
87*63b94509STom Lendacky /**
88*63b94509STom Lendacky  * ccp_aes_mode - AES operation mode
89*63b94509STom Lendacky  *
90*63b94509STom Lendacky  * @CCP_AES_ACTION_DECRYPT: AES decrypt operation
91*63b94509STom Lendacky  * @CCP_AES_ACTION_ENCRYPT: AES encrypt operation
92*63b94509STom Lendacky  */
93*63b94509STom Lendacky enum ccp_aes_action {
94*63b94509STom Lendacky 	CCP_AES_ACTION_DECRYPT = 0,
95*63b94509STom Lendacky 	CCP_AES_ACTION_ENCRYPT,
96*63b94509STom Lendacky 	CCP_AES_ACTION__LAST,
97*63b94509STom Lendacky };
98*63b94509STom Lendacky 
99*63b94509STom Lendacky /**
100*63b94509STom Lendacky  * struct ccp_aes_engine - CCP AES operation
101*63b94509STom Lendacky  * @type: AES operation key size
102*63b94509STom Lendacky  * @mode: AES operation mode
103*63b94509STom Lendacky  * @action: AES operation (decrypt/encrypt)
104*63b94509STom Lendacky  * @key: key to be used for this AES operation
105*63b94509STom Lendacky  * @key_len: length in bytes of key
106*63b94509STom Lendacky  * @iv: IV to be used for this AES operation
107*63b94509STom Lendacky  * @iv_len: length in bytes of iv
108*63b94509STom Lendacky  * @src: data to be used for this operation
109*63b94509STom Lendacky  * @dst: data produced by this operation
110*63b94509STom Lendacky  * @src_len: length in bytes of data used for this operation
111*63b94509STom Lendacky  * @cmac_final: indicates final operation when running in CMAC mode
112*63b94509STom Lendacky  * @cmac_key: K1/K2 key used in final CMAC operation
113*63b94509STom Lendacky  * @cmac_key_len: length in bytes of cmac_key
114*63b94509STom Lendacky  *
115*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
116*63b94509STom Lendacky  *   - type, mode, action, key, key_len, src, dst, src_len
117*63b94509STom Lendacky  *   - iv, iv_len for any mode other than ECB
118*63b94509STom Lendacky  *   - cmac_final for CMAC mode
119*63b94509STom Lendacky  *   - cmac_key, cmac_key_len for CMAC mode if cmac_final is non-zero
120*63b94509STom Lendacky  *
121*63b94509STom Lendacky  * The iv variable is used as both input and output. On completion of the
122*63b94509STom Lendacky  * AES operation the new IV overwrites the old IV.
123*63b94509STom Lendacky  */
124*63b94509STom Lendacky struct ccp_aes_engine {
125*63b94509STom Lendacky 	enum ccp_aes_type type;
126*63b94509STom Lendacky 	enum ccp_aes_mode mode;
127*63b94509STom Lendacky 	enum ccp_aes_action action;
128*63b94509STom Lendacky 
129*63b94509STom Lendacky 	struct scatterlist *key;
130*63b94509STom Lendacky 	u32 key_len;		/* In bytes */
131*63b94509STom Lendacky 
132*63b94509STom Lendacky 	struct scatterlist *iv;
133*63b94509STom Lendacky 	u32 iv_len;		/* In bytes */
134*63b94509STom Lendacky 
135*63b94509STom Lendacky 	struct scatterlist *src, *dst;
136*63b94509STom Lendacky 	u32 src_len;		/* In bytes */
137*63b94509STom Lendacky 
138*63b94509STom Lendacky 	u32 cmac_final;		/* Indicates final cmac cmd */
139*63b94509STom Lendacky 	struct scatterlist *cmac_key;	/* K1/K2 cmac key required for
140*63b94509STom Lendacky 					 * final cmac cmd */
141*63b94509STom Lendacky 	u32 cmac_key_len;	/* In bytes */
142*63b94509STom Lendacky };
143*63b94509STom Lendacky 
144*63b94509STom Lendacky /***** XTS-AES engine *****/
145*63b94509STom Lendacky /**
146*63b94509STom Lendacky  * ccp_xts_aes_unit_size - XTS unit size
147*63b94509STom Lendacky  *
148*63b94509STom Lendacky  * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes
149*63b94509STom Lendacky  * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes
150*63b94509STom Lendacky  * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes
151*63b94509STom Lendacky  * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes
152*63b94509STom Lendacky  * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes
153*63b94509STom Lendacky  */
154*63b94509STom Lendacky enum ccp_xts_aes_unit_size {
155*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE_16 = 0,
156*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE_512,
157*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE_1024,
158*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE_2048,
159*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE_4096,
160*63b94509STom Lendacky 	CCP_XTS_AES_UNIT_SIZE__LAST,
161*63b94509STom Lendacky };
162*63b94509STom Lendacky 
163*63b94509STom Lendacky /**
164*63b94509STom Lendacky  * struct ccp_xts_aes_engine - CCP XTS AES operation
165*63b94509STom Lendacky  * @action: AES operation (decrypt/encrypt)
166*63b94509STom Lendacky  * @unit_size: unit size of the XTS operation
167*63b94509STom Lendacky  * @key: key to be used for this XTS AES operation
168*63b94509STom Lendacky  * @key_len: length in bytes of key
169*63b94509STom Lendacky  * @iv: IV to be used for this XTS AES operation
170*63b94509STom Lendacky  * @iv_len: length in bytes of iv
171*63b94509STom Lendacky  * @src: data to be used for this operation
172*63b94509STom Lendacky  * @dst: data produced by this operation
173*63b94509STom Lendacky  * @src_len: length in bytes of data used for this operation
174*63b94509STom Lendacky  * @final: indicates final XTS operation
175*63b94509STom Lendacky  *
176*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
177*63b94509STom Lendacky  *   - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final
178*63b94509STom Lendacky  *
179*63b94509STom Lendacky  * The iv variable is used as both input and output. On completion of the
180*63b94509STom Lendacky  * AES operation the new IV overwrites the old IV.
181*63b94509STom Lendacky  */
182*63b94509STom Lendacky struct ccp_xts_aes_engine {
183*63b94509STom Lendacky 	enum ccp_aes_action action;
184*63b94509STom Lendacky 	enum ccp_xts_aes_unit_size unit_size;
185*63b94509STom Lendacky 
186*63b94509STom Lendacky 	struct scatterlist *key;
187*63b94509STom Lendacky 	u32 key_len;		/* In bytes */
188*63b94509STom Lendacky 
189*63b94509STom Lendacky 	struct scatterlist *iv;
190*63b94509STom Lendacky 	u32 iv_len;		/* In bytes */
191*63b94509STom Lendacky 
192*63b94509STom Lendacky 	struct scatterlist *src, *dst;
193*63b94509STom Lendacky 	u32 src_len;		/* In bytes */
194*63b94509STom Lendacky 
195*63b94509STom Lendacky 	u32 final;
196*63b94509STom Lendacky };
197*63b94509STom Lendacky 
198*63b94509STom Lendacky /***** SHA engine *****/
199*63b94509STom Lendacky #define CCP_SHA_BLOCKSIZE               SHA256_BLOCK_SIZE
200*63b94509STom Lendacky #define CCP_SHA_CTXSIZE                 SHA256_DIGEST_SIZE
201*63b94509STom Lendacky 
202*63b94509STom Lendacky /**
203*63b94509STom Lendacky  * ccp_sha_type - type of SHA operation
204*63b94509STom Lendacky  *
205*63b94509STom Lendacky  * @CCP_SHA_TYPE_1: SHA-1 operation
206*63b94509STom Lendacky  * @CCP_SHA_TYPE_224: SHA-224 operation
207*63b94509STom Lendacky  * @CCP_SHA_TYPE_256: SHA-256 operation
208*63b94509STom Lendacky  */
209*63b94509STom Lendacky enum ccp_sha_type {
210*63b94509STom Lendacky 	CCP_SHA_TYPE_1 = 1,
211*63b94509STom Lendacky 	CCP_SHA_TYPE_224,
212*63b94509STom Lendacky 	CCP_SHA_TYPE_256,
213*63b94509STom Lendacky 	CCP_SHA_TYPE__LAST,
214*63b94509STom Lendacky };
215*63b94509STom Lendacky 
216*63b94509STom Lendacky /**
217*63b94509STom Lendacky  * struct ccp_sha_engine - CCP SHA operation
218*63b94509STom Lendacky  * @type: Type of SHA operation
219*63b94509STom Lendacky  * @ctx: current hash value
220*63b94509STom Lendacky  * @ctx_len: length in bytes of hash value
221*63b94509STom Lendacky  * @src: data to be used for this operation
222*63b94509STom Lendacky  * @src_len: length in bytes of data used for this operation
223*63b94509STom Lendacky  * @final: indicates final SHA operation
224*63b94509STom Lendacky  * @msg_bits: total length of the message in bits used in final SHA operation
225*63b94509STom Lendacky  *
226*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
227*63b94509STom Lendacky  *   - type, ctx, ctx_len, src, src_len, final
228*63b94509STom Lendacky  *   - msg_bits if final is non-zero
229*63b94509STom Lendacky  *
230*63b94509STom Lendacky  * The ctx variable is used as both input and output. On completion of the
231*63b94509STom Lendacky  * SHA operation the new hash value overwrites the old hash value.
232*63b94509STom Lendacky  */
233*63b94509STom Lendacky struct ccp_sha_engine {
234*63b94509STom Lendacky 	enum ccp_sha_type type;
235*63b94509STom Lendacky 
236*63b94509STom Lendacky 	struct scatterlist *ctx;
237*63b94509STom Lendacky 	u32 ctx_len;		/* In bytes */
238*63b94509STom Lendacky 
239*63b94509STom Lendacky 	struct scatterlist *src;
240*63b94509STom Lendacky 	u32 src_len;		/* In bytes */
241*63b94509STom Lendacky 
242*63b94509STom Lendacky 	u32 final;		/* Indicates final sha cmd */
243*63b94509STom Lendacky 	u64 msg_bits;		/* Message length in bits required for
244*63b94509STom Lendacky 				 * final sha cmd */
245*63b94509STom Lendacky };
246*63b94509STom Lendacky 
247*63b94509STom Lendacky /***** RSA engine *****/
248*63b94509STom Lendacky /**
249*63b94509STom Lendacky  * struct ccp_rsa_engine - CCP RSA operation
250*63b94509STom Lendacky  * @key_size: length in bits of RSA key
251*63b94509STom Lendacky  * @exp: RSA exponent
252*63b94509STom Lendacky  * @exp_len: length in bytes of exponent
253*63b94509STom Lendacky  * @mod: RSA modulus
254*63b94509STom Lendacky  * @mod_len: length in bytes of modulus
255*63b94509STom Lendacky  * @src: data to be used for this operation
256*63b94509STom Lendacky  * @dst: data produced by this operation
257*63b94509STom Lendacky  * @src_len: length in bytes of data used for this operation
258*63b94509STom Lendacky  *
259*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
260*63b94509STom Lendacky  *   - key_size, exp, exp_len, mod, mod_len, src, dst, src_len
261*63b94509STom Lendacky  */
262*63b94509STom Lendacky struct ccp_rsa_engine {
263*63b94509STom Lendacky 	u32 key_size;		/* In bits */
264*63b94509STom Lendacky 
265*63b94509STom Lendacky 	struct scatterlist *exp;
266*63b94509STom Lendacky 	u32 exp_len;		/* In bytes */
267*63b94509STom Lendacky 
268*63b94509STom Lendacky 	struct scatterlist *mod;
269*63b94509STom Lendacky 	u32 mod_len;		/* In bytes */
270*63b94509STom Lendacky 
271*63b94509STom Lendacky 	struct scatterlist *src, *dst;
272*63b94509STom Lendacky 	u32 src_len;		/* In bytes */
273*63b94509STom Lendacky };
274*63b94509STom Lendacky 
275*63b94509STom Lendacky /***** Passthru engine *****/
276*63b94509STom Lendacky /**
277*63b94509STom Lendacky  * ccp_passthru_bitwise - type of bitwise passthru operation
278*63b94509STom Lendacky  *
279*63b94509STom Lendacky  * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed
280*63b94509STom Lendacky  * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask
281*63b94509STom Lendacky  * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask
282*63b94509STom Lendacky  * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask
283*63b94509STom Lendacky  * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask
284*63b94509STom Lendacky  */
285*63b94509STom Lendacky enum ccp_passthru_bitwise {
286*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE_NOOP = 0,
287*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE_AND,
288*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE_OR,
289*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE_XOR,
290*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE_MASK,
291*63b94509STom Lendacky 	CCP_PASSTHRU_BITWISE__LAST,
292*63b94509STom Lendacky };
293*63b94509STom Lendacky 
294*63b94509STom Lendacky /**
295*63b94509STom Lendacky  * ccp_passthru_byteswap - type of byteswap passthru operation
296*63b94509STom Lendacky  *
297*63b94509STom Lendacky  * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed
298*63b94509STom Lendacky  * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words
299*63b94509STom Lendacky  * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words
300*63b94509STom Lendacky  */
301*63b94509STom Lendacky enum ccp_passthru_byteswap {
302*63b94509STom Lendacky 	CCP_PASSTHRU_BYTESWAP_NOOP = 0,
303*63b94509STom Lendacky 	CCP_PASSTHRU_BYTESWAP_32BIT,
304*63b94509STom Lendacky 	CCP_PASSTHRU_BYTESWAP_256BIT,
305*63b94509STom Lendacky 	CCP_PASSTHRU_BYTESWAP__LAST,
306*63b94509STom Lendacky };
307*63b94509STom Lendacky 
308*63b94509STom Lendacky /**
309*63b94509STom Lendacky  * struct ccp_passthru_engine - CCP pass-through operation
310*63b94509STom Lendacky  * @bit_mod: bitwise operation to perform
311*63b94509STom Lendacky  * @byte_swap: byteswap operation to perform
312*63b94509STom Lendacky  * @mask: mask to be applied to data
313*63b94509STom Lendacky  * @mask_len: length in bytes of mask
314*63b94509STom Lendacky  * @src: data to be used for this operation
315*63b94509STom Lendacky  * @dst: data produced by this operation
316*63b94509STom Lendacky  * @src_len: length in bytes of data used for this operation
317*63b94509STom Lendacky  * @final: indicate final pass-through operation
318*63b94509STom Lendacky  *
319*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
320*63b94509STom Lendacky  *   - bit_mod, byte_swap, src, dst, src_len
321*63b94509STom Lendacky  *   - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
322*63b94509STom Lendacky  */
323*63b94509STom Lendacky struct ccp_passthru_engine {
324*63b94509STom Lendacky 	enum ccp_passthru_bitwise bit_mod;
325*63b94509STom Lendacky 	enum ccp_passthru_byteswap byte_swap;
326*63b94509STom Lendacky 
327*63b94509STom Lendacky 	struct scatterlist *mask;
328*63b94509STom Lendacky 	u32 mask_len;		/* In bytes */
329*63b94509STom Lendacky 
330*63b94509STom Lendacky 	struct scatterlist *src, *dst;
331*63b94509STom Lendacky 	u32 src_len;		/* In bytes */
332*63b94509STom Lendacky 
333*63b94509STom Lendacky 	u32 final;
334*63b94509STom Lendacky };
335*63b94509STom Lendacky 
336*63b94509STom Lendacky /***** ECC engine *****/
337*63b94509STom Lendacky #define CCP_ECC_MODULUS_BYTES	48	/* 384-bits */
338*63b94509STom Lendacky #define CCP_ECC_MAX_OPERANDS	6
339*63b94509STom Lendacky #define CCP_ECC_MAX_OUTPUTS	3
340*63b94509STom Lendacky 
341*63b94509STom Lendacky /**
342*63b94509STom Lendacky  * ccp_ecc_function - type of ECC function
343*63b94509STom Lendacky  *
344*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication
345*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition
346*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse
347*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition
348*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication
349*63b94509STom Lendacky  * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling
350*63b94509STom Lendacky  */
351*63b94509STom Lendacky enum ccp_ecc_function {
352*63b94509STom Lendacky 	CCP_ECC_FUNCTION_MMUL_384BIT = 0,
353*63b94509STom Lendacky 	CCP_ECC_FUNCTION_MADD_384BIT,
354*63b94509STom Lendacky 	CCP_ECC_FUNCTION_MINV_384BIT,
355*63b94509STom Lendacky 	CCP_ECC_FUNCTION_PADD_384BIT,
356*63b94509STom Lendacky 	CCP_ECC_FUNCTION_PMUL_384BIT,
357*63b94509STom Lendacky 	CCP_ECC_FUNCTION_PDBL_384BIT,
358*63b94509STom Lendacky };
359*63b94509STom Lendacky 
360*63b94509STom Lendacky /**
361*63b94509STom Lendacky  * struct ccp_ecc_modular_math - CCP ECC modular math parameters
362*63b94509STom Lendacky  * @operand_1: first operand for the modular math operation
363*63b94509STom Lendacky  * @operand_1_len: length of the first operand
364*63b94509STom Lendacky  * @operand_2: second operand for the modular math operation
365*63b94509STom Lendacky  *	       (not used for CCP_ECC_FUNCTION_MINV_384BIT)
366*63b94509STom Lendacky  * @operand_2_len: length of the second operand
367*63b94509STom Lendacky  *	       (not used for CCP_ECC_FUNCTION_MINV_384BIT)
368*63b94509STom Lendacky  * @result: result of the modular math operation
369*63b94509STom Lendacky  * @result_len: length of the supplied result buffer
370*63b94509STom Lendacky  */
371*63b94509STom Lendacky struct ccp_ecc_modular_math {
372*63b94509STom Lendacky 	struct scatterlist *operand_1;
373*63b94509STom Lendacky 	unsigned int operand_1_len;	/* In bytes */
374*63b94509STom Lendacky 
375*63b94509STom Lendacky 	struct scatterlist *operand_2;
376*63b94509STom Lendacky 	unsigned int operand_2_len;	/* In bytes */
377*63b94509STom Lendacky 
378*63b94509STom Lendacky 	struct scatterlist *result;
379*63b94509STom Lendacky 	unsigned int result_len;	/* In bytes */
380*63b94509STom Lendacky };
381*63b94509STom Lendacky 
382*63b94509STom Lendacky /**
383*63b94509STom Lendacky  * struct ccp_ecc_point - CCP ECC point definition
384*63b94509STom Lendacky  * @x: the x coordinate of the ECC point
385*63b94509STom Lendacky  * @x_len: the length of the x coordinate
386*63b94509STom Lendacky  * @y: the y coordinate of the ECC point
387*63b94509STom Lendacky  * @y_len: the length of the y coordinate
388*63b94509STom Lendacky  */
389*63b94509STom Lendacky struct ccp_ecc_point {
390*63b94509STom Lendacky 	struct scatterlist *x;
391*63b94509STom Lendacky 	unsigned int x_len;	/* In bytes */
392*63b94509STom Lendacky 
393*63b94509STom Lendacky 	struct scatterlist *y;
394*63b94509STom Lendacky 	unsigned int y_len;	/* In bytes */
395*63b94509STom Lendacky };
396*63b94509STom Lendacky 
397*63b94509STom Lendacky /**
398*63b94509STom Lendacky  * struct ccp_ecc_point_math - CCP ECC point math parameters
399*63b94509STom Lendacky  * @point_1: the first point of the ECC point math operation
400*63b94509STom Lendacky  * @point_2: the second point of the ECC point math operation
401*63b94509STom Lendacky  *	     (only used for CCP_ECC_FUNCTION_PADD_384BIT)
402*63b94509STom Lendacky  * @domain_a: the a parameter of the ECC curve
403*63b94509STom Lendacky  * @domain_a_len: the length of the a parameter
404*63b94509STom Lendacky  * @scalar: the scalar parameter for the point match operation
405*63b94509STom Lendacky  *	    (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
406*63b94509STom Lendacky  * @scalar_len: the length of the scalar parameter
407*63b94509STom Lendacky  *		(only used for CCP_ECC_FUNCTION_PMUL_384BIT)
408*63b94509STom Lendacky  * @result: the point resulting from the point math operation
409*63b94509STom Lendacky  */
410*63b94509STom Lendacky struct ccp_ecc_point_math {
411*63b94509STom Lendacky 	struct ccp_ecc_point point_1;
412*63b94509STom Lendacky 	struct ccp_ecc_point point_2;
413*63b94509STom Lendacky 
414*63b94509STom Lendacky 	struct scatterlist *domain_a;
415*63b94509STom Lendacky 	unsigned int domain_a_len;	/* In bytes */
416*63b94509STom Lendacky 
417*63b94509STom Lendacky 	struct scatterlist *scalar;
418*63b94509STom Lendacky 	unsigned int scalar_len;	/* In bytes */
419*63b94509STom Lendacky 
420*63b94509STom Lendacky 	struct ccp_ecc_point result;
421*63b94509STom Lendacky };
422*63b94509STom Lendacky 
423*63b94509STom Lendacky /**
424*63b94509STom Lendacky  * struct ccp_ecc_engine - CCP ECC operation
425*63b94509STom Lendacky  * @function: ECC function to perform
426*63b94509STom Lendacky  * @mod: ECC modulus
427*63b94509STom Lendacky  * @mod_len: length in bytes of modulus
428*63b94509STom Lendacky  * @mm: module math parameters
429*63b94509STom Lendacky  * @pm: point math parameters
430*63b94509STom Lendacky  * @ecc_result: result of the ECC operation
431*63b94509STom Lendacky  *
432*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
433*63b94509STom Lendacky  *   - function, mod, mod_len
434*63b94509STom Lendacky  *   - operand, operand_len, operand_count, output, output_len, output_count
435*63b94509STom Lendacky  *   - ecc_result
436*63b94509STom Lendacky  */
437*63b94509STom Lendacky struct ccp_ecc_engine {
438*63b94509STom Lendacky 	enum ccp_ecc_function function;
439*63b94509STom Lendacky 
440*63b94509STom Lendacky 	struct scatterlist *mod;
441*63b94509STom Lendacky 	u32 mod_len;		/* In bytes */
442*63b94509STom Lendacky 
443*63b94509STom Lendacky 	union {
444*63b94509STom Lendacky 		struct ccp_ecc_modular_math mm;
445*63b94509STom Lendacky 		struct ccp_ecc_point_math pm;
446*63b94509STom Lendacky 	} u;
447*63b94509STom Lendacky 
448*63b94509STom Lendacky 	u16 ecc_result;
449*63b94509STom Lendacky };
450*63b94509STom Lendacky 
451*63b94509STom Lendacky 
452*63b94509STom Lendacky /**
453*63b94509STom Lendacky  * ccp_engine - CCP operation identifiers
454*63b94509STom Lendacky  *
455*63b94509STom Lendacky  * @CCP_ENGINE_AES: AES operation
456*63b94509STom Lendacky  * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation
457*63b94509STom Lendacky  * @CCP_ENGINE_RSVD1: unused
458*63b94509STom Lendacky  * @CCP_ENGINE_SHA: SHA operation
459*63b94509STom Lendacky  * @CCP_ENGINE_RSA: RSA operation
460*63b94509STom Lendacky  * @CCP_ENGINE_PASSTHRU: pass-through operation
461*63b94509STom Lendacky  * @CCP_ENGINE_ZLIB_DECOMPRESS: unused
462*63b94509STom Lendacky  * @CCP_ENGINE_ECC: ECC operation
463*63b94509STom Lendacky  */
464*63b94509STom Lendacky enum ccp_engine {
465*63b94509STom Lendacky 	CCP_ENGINE_AES = 0,
466*63b94509STom Lendacky 	CCP_ENGINE_XTS_AES_128,
467*63b94509STom Lendacky 	CCP_ENGINE_RSVD1,
468*63b94509STom Lendacky 	CCP_ENGINE_SHA,
469*63b94509STom Lendacky 	CCP_ENGINE_RSA,
470*63b94509STom Lendacky 	CCP_ENGINE_PASSTHRU,
471*63b94509STom Lendacky 	CCP_ENGINE_ZLIB_DECOMPRESS,
472*63b94509STom Lendacky 	CCP_ENGINE_ECC,
473*63b94509STom Lendacky 	CCP_ENGINE__LAST,
474*63b94509STom Lendacky };
475*63b94509STom Lendacky 
476*63b94509STom Lendacky /* Flag values for flags member of ccp_cmd */
477*63b94509STom Lendacky #define CCP_CMD_MAY_BACKLOG	0x00000001
478*63b94509STom Lendacky 
479*63b94509STom Lendacky /**
480*63b94509STom Lendacky  * struct ccp_cmd - CPP operation request
481*63b94509STom Lendacky  * @entry: list element (ccp driver use only)
482*63b94509STom Lendacky  * @work: work element used for callbacks (ccp driver use only)
483*63b94509STom Lendacky  * @ccp: CCP device to be run on (ccp driver use only)
484*63b94509STom Lendacky  * @ret: operation return code (ccp driver use only)
485*63b94509STom Lendacky  * @flags: cmd processing flags
486*63b94509STom Lendacky  * @engine: CCP operation to perform
487*63b94509STom Lendacky  * @engine_error: CCP engine return code
488*63b94509STom Lendacky  * @u: engine specific structures, refer to specific engine struct below
489*63b94509STom Lendacky  * @callback: operation completion callback function
490*63b94509STom Lendacky  * @data: parameter value to be supplied to the callback function
491*63b94509STom Lendacky  *
492*63b94509STom Lendacky  * Variables required to be set when calling ccp_enqueue_cmd():
493*63b94509STom Lendacky  *   - engine, callback
494*63b94509STom Lendacky  *   - See the operation structures below for what is required for each
495*63b94509STom Lendacky  *     operation.
496*63b94509STom Lendacky  */
497*63b94509STom Lendacky struct ccp_cmd {
498*63b94509STom Lendacky 	/* The list_head, work_struct, ccp and ret variables are for use
499*63b94509STom Lendacky 	 * by the CCP driver only.
500*63b94509STom Lendacky 	 */
501*63b94509STom Lendacky 	struct list_head entry;
502*63b94509STom Lendacky 	struct work_struct work;
503*63b94509STom Lendacky 	struct ccp_device *ccp;
504*63b94509STom Lendacky 	int ret;
505*63b94509STom Lendacky 
506*63b94509STom Lendacky 	u32 flags;
507*63b94509STom Lendacky 
508*63b94509STom Lendacky 	enum ccp_engine engine;
509*63b94509STom Lendacky 	u32 engine_error;
510*63b94509STom Lendacky 
511*63b94509STom Lendacky 	union {
512*63b94509STom Lendacky 		struct ccp_aes_engine aes;
513*63b94509STom Lendacky 		struct ccp_xts_aes_engine xts;
514*63b94509STom Lendacky 		struct ccp_sha_engine sha;
515*63b94509STom Lendacky 		struct ccp_rsa_engine rsa;
516*63b94509STom Lendacky 		struct ccp_passthru_engine passthru;
517*63b94509STom Lendacky 		struct ccp_ecc_engine ecc;
518*63b94509STom Lendacky 	} u;
519*63b94509STom Lendacky 
520*63b94509STom Lendacky 	/* Completion callback support */
521*63b94509STom Lendacky 	void (*callback)(void *data, int err);
522*63b94509STom Lendacky 	void *data;
523*63b94509STom Lendacky };
524*63b94509STom Lendacky 
525*63b94509STom Lendacky #endif
526