1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
263b94509STom Lendacky /*
363b94509STom Lendacky * AMD Cryptographic Coprocessor (CCP) driver
463b94509STom Lendacky *
5e652399eSGary R Hook * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
663b94509STom Lendacky *
763b94509STom Lendacky * Author: Tom Lendacky <thomas.lendacky@amd.com>
858ea8abfSGary R Hook * Author: Gary R Hook <gary.hook@amd.com>
963b94509STom Lendacky */
1063b94509STom Lendacky
11c8d283ffSPaul Bolle #ifndef __CCP_H__
12c8d283ffSPaul Bolle #define __CCP_H__
1363b94509STom Lendacky
1463b94509STom Lendacky #include <linux/scatterlist.h>
1563b94509STom Lendacky #include <linux/workqueue.h>
1663b94509STom Lendacky #include <linux/list.h>
1763b94509STom Lendacky #include <crypto/aes.h>
18*a24d22b2SEric Biggers #include <crypto/sha1.h>
19*a24d22b2SEric Biggers #include <crypto/sha2.h>
2063b94509STom Lendacky
2163b94509STom Lendacky struct ccp_device;
2263b94509STom Lendacky struct ccp_cmd;
2363b94509STom Lendacky
24720419f0SBrijesh Singh #if defined(CONFIG_CRYPTO_DEV_SP_CCP)
25db34cf91STom Lendacky
2663b94509STom Lendacky /**
27c9f21cb6STom Lendacky * ccp_present - check if a CCP device is present
28c9f21cb6STom Lendacky *
29c9f21cb6STom Lendacky * Returns zero if a CCP device is present, -ENODEV otherwise.
30c9f21cb6STom Lendacky */
31c9f21cb6STom Lendacky int ccp_present(void);
32c9f21cb6STom Lendacky
33c7019c4dSGary R Hook #define CCP_VSIZE 16
34c7019c4dSGary R Hook #define CCP_VMASK ((unsigned int)((1 << CCP_VSIZE) - 1))
35c7019c4dSGary R Hook #define CCP_VERSION(v, r) ((unsigned int)((v << CCP_VSIZE) \
36c7019c4dSGary R Hook | (r & CCP_VMASK)))
37c7019c4dSGary R Hook
38c7019c4dSGary R Hook /**
39c7019c4dSGary R Hook * ccp_version - get the version of the CCP
40c7019c4dSGary R Hook *
41c7019c4dSGary R Hook * Returns a positive version number, or zero if no CCP
42c7019c4dSGary R Hook */
43c7019c4dSGary R Hook unsigned int ccp_version(void);
44c7019c4dSGary R Hook
45c9f21cb6STom Lendacky /**
4663b94509STom Lendacky * ccp_enqueue_cmd - queue an operation for processing by the CCP
4763b94509STom Lendacky *
4863b94509STom Lendacky * @cmd: ccp_cmd struct to be processed
4963b94509STom Lendacky *
5063b94509STom Lendacky * Refer to the ccp_cmd struct below for required fields.
5163b94509STom Lendacky *
5263b94509STom Lendacky * Queue a cmd to be processed by the CCP. If queueing the cmd
5363b94509STom Lendacky * would exceed the defined length of the cmd queue the cmd will
5463b94509STom Lendacky * only be queued if the CCP_CMD_MAY_BACKLOG flag is set and will
5563b94509STom Lendacky * result in a return code of -EBUSY.
5663b94509STom Lendacky *
5763b94509STom Lendacky * The callback routine specified in the ccp_cmd struct will be
5863b94509STom Lendacky * called to notify the caller of completion (if the cmd was not
5963b94509STom Lendacky * backlogged) or advancement out of the backlog. If the cmd has
6063b94509STom Lendacky * advanced out of the backlog the "err" value of the callback
6163b94509STom Lendacky * will be -EINPROGRESS. Any other "err" value during callback is
6263b94509STom Lendacky * the result of the operation.
6363b94509STom Lendacky *
6463b94509STom Lendacky * The cmd has been successfully queued if:
6563b94509STom Lendacky * the return code is -EINPROGRESS or
6663b94509STom Lendacky * the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set
6763b94509STom Lendacky */
6863b94509STom Lendacky int ccp_enqueue_cmd(struct ccp_cmd *cmd);
6963b94509STom Lendacky
70720419f0SBrijesh Singh #else /* CONFIG_CRYPTO_DEV_CCP_SP_DEV is not enabled */
71db34cf91STom Lendacky
ccp_present(void)72c9f21cb6STom Lendacky static inline int ccp_present(void)
73c9f21cb6STom Lendacky {
74c9f21cb6STom Lendacky return -ENODEV;
75c9f21cb6STom Lendacky }
76c9f21cb6STom Lendacky
ccp_version(void)77c7019c4dSGary R Hook static inline unsigned int ccp_version(void)
78c7019c4dSGary R Hook {
79c7019c4dSGary R Hook return 0;
80c7019c4dSGary R Hook }
81c7019c4dSGary R Hook
ccp_enqueue_cmd(struct ccp_cmd * cmd)82db34cf91STom Lendacky static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd)
83db34cf91STom Lendacky {
84db34cf91STom Lendacky return -ENODEV;
85db34cf91STom Lendacky }
86db34cf91STom Lendacky
87720419f0SBrijesh Singh #endif /* CONFIG_CRYPTO_DEV_SP_CCP */
88db34cf91STom Lendacky
8963b94509STom Lendacky
9063b94509STom Lendacky /***** AES engine *****/
9163b94509STom Lendacky /**
9263b94509STom Lendacky * ccp_aes_type - AES key size
9363b94509STom Lendacky *
9463b94509STom Lendacky * @CCP_AES_TYPE_128: 128-bit key
9563b94509STom Lendacky * @CCP_AES_TYPE_192: 192-bit key
9663b94509STom Lendacky * @CCP_AES_TYPE_256: 256-bit key
9763b94509STom Lendacky */
9863b94509STom Lendacky enum ccp_aes_type {
9963b94509STom Lendacky CCP_AES_TYPE_128 = 0,
10063b94509STom Lendacky CCP_AES_TYPE_192,
10163b94509STom Lendacky CCP_AES_TYPE_256,
10263b94509STom Lendacky CCP_AES_TYPE__LAST,
10363b94509STom Lendacky };
10463b94509STom Lendacky
10563b94509STom Lendacky /**
10663b94509STom Lendacky * ccp_aes_mode - AES operation mode
10763b94509STom Lendacky *
10863b94509STom Lendacky * @CCP_AES_MODE_ECB: ECB mode
10963b94509STom Lendacky * @CCP_AES_MODE_CBC: CBC mode
11063b94509STom Lendacky * @CCP_AES_MODE_OFB: OFB mode
11163b94509STom Lendacky * @CCP_AES_MODE_CFB: CFB mode
11263b94509STom Lendacky * @CCP_AES_MODE_CTR: CTR mode
11363b94509STom Lendacky * @CCP_AES_MODE_CMAC: CMAC mode
11463b94509STom Lendacky */
11563b94509STom Lendacky enum ccp_aes_mode {
11663b94509STom Lendacky CCP_AES_MODE_ECB = 0,
11763b94509STom Lendacky CCP_AES_MODE_CBC,
11863b94509STom Lendacky CCP_AES_MODE_OFB,
11963b94509STom Lendacky CCP_AES_MODE_CFB,
12063b94509STom Lendacky CCP_AES_MODE_CTR,
12163b94509STom Lendacky CCP_AES_MODE_CMAC,
12236cf515bSGary R Hook CCP_AES_MODE_GHASH,
12336cf515bSGary R Hook CCP_AES_MODE_GCTR,
12436cf515bSGary R Hook CCP_AES_MODE_GCM,
12536cf515bSGary R Hook CCP_AES_MODE_GMAC,
12663b94509STom Lendacky CCP_AES_MODE__LAST,
12763b94509STom Lendacky };
12863b94509STom Lendacky
12963b94509STom Lendacky /**
13063b94509STom Lendacky * ccp_aes_mode - AES operation mode
13163b94509STom Lendacky *
13263b94509STom Lendacky * @CCP_AES_ACTION_DECRYPT: AES decrypt operation
13363b94509STom Lendacky * @CCP_AES_ACTION_ENCRYPT: AES encrypt operation
13463b94509STom Lendacky */
13563b94509STom Lendacky enum ccp_aes_action {
13663b94509STom Lendacky CCP_AES_ACTION_DECRYPT = 0,
13763b94509STom Lendacky CCP_AES_ACTION_ENCRYPT,
13863b94509STom Lendacky CCP_AES_ACTION__LAST,
13963b94509STom Lendacky };
14036cf515bSGary R Hook /* Overloaded field */
14136cf515bSGary R Hook #define CCP_AES_GHASHAAD CCP_AES_ACTION_DECRYPT
14236cf515bSGary R Hook #define CCP_AES_GHASHFINAL CCP_AES_ACTION_ENCRYPT
14363b94509STom Lendacky
14463b94509STom Lendacky /**
14563b94509STom Lendacky * struct ccp_aes_engine - CCP AES operation
14663b94509STom Lendacky * @type: AES operation key size
14763b94509STom Lendacky * @mode: AES operation mode
14863b94509STom Lendacky * @action: AES operation (decrypt/encrypt)
14963b94509STom Lendacky * @key: key to be used for this AES operation
15063b94509STom Lendacky * @key_len: length in bytes of key
15163b94509STom Lendacky * @iv: IV to be used for this AES operation
15263b94509STom Lendacky * @iv_len: length in bytes of iv
15363b94509STom Lendacky * @src: data to be used for this operation
15463b94509STom Lendacky * @dst: data produced by this operation
15563b94509STom Lendacky * @src_len: length in bytes of data used for this operation
15663b94509STom Lendacky * @cmac_final: indicates final operation when running in CMAC mode
15763b94509STom Lendacky * @cmac_key: K1/K2 key used in final CMAC operation
15863b94509STom Lendacky * @cmac_key_len: length in bytes of cmac_key
15963b94509STom Lendacky *
16063b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
16163b94509STom Lendacky * - type, mode, action, key, key_len, src, dst, src_len
16263b94509STom Lendacky * - iv, iv_len for any mode other than ECB
16363b94509STom Lendacky * - cmac_final for CMAC mode
16463b94509STom Lendacky * - cmac_key, cmac_key_len for CMAC mode if cmac_final is non-zero
16563b94509STom Lendacky *
16663b94509STom Lendacky * The iv variable is used as both input and output. On completion of the
16763b94509STom Lendacky * AES operation the new IV overwrites the old IV.
16863b94509STom Lendacky */
16963b94509STom Lendacky struct ccp_aes_engine {
17063b94509STom Lendacky enum ccp_aes_type type;
17163b94509STom Lendacky enum ccp_aes_mode mode;
17263b94509STom Lendacky enum ccp_aes_action action;
17363b94509STom Lendacky
1749f00baf7SGary R Hook u32 authsize;
1759f00baf7SGary R Hook
17663b94509STom Lendacky struct scatterlist *key;
17763b94509STom Lendacky u32 key_len; /* In bytes */
17863b94509STom Lendacky
17963b94509STom Lendacky struct scatterlist *iv;
18063b94509STom Lendacky u32 iv_len; /* In bytes */
18163b94509STom Lendacky
18263b94509STom Lendacky struct scatterlist *src, *dst;
18381a59f00STom Lendacky u64 src_len; /* In bytes */
18463b94509STom Lendacky
18563b94509STom Lendacky u32 cmac_final; /* Indicates final cmac cmd */
18663b94509STom Lendacky struct scatterlist *cmac_key; /* K1/K2 cmac key required for
18763b94509STom Lendacky * final cmac cmd */
18863b94509STom Lendacky u32 cmac_key_len; /* In bytes */
18936cf515bSGary R Hook
19036cf515bSGary R Hook u32 aad_len; /* In bytes */
19163b94509STom Lendacky };
19263b94509STom Lendacky
19363b94509STom Lendacky /***** XTS-AES engine *****/
19463b94509STom Lendacky /**
19563b94509STom Lendacky * ccp_xts_aes_unit_size - XTS unit size
19663b94509STom Lendacky *
19763b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_16: Unit size of 16 bytes
19863b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_512: Unit size of 512 bytes
19963b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_1024: Unit size of 1024 bytes
20063b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_2048: Unit size of 2048 bytes
20163b94509STom Lendacky * @CCP_XTS_AES_UNIT_SIZE_4096: Unit size of 4096 bytes
20263b94509STom Lendacky */
20363b94509STom Lendacky enum ccp_xts_aes_unit_size {
20463b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_16 = 0,
20563b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_512,
20663b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_1024,
20763b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_2048,
20863b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE_4096,
20963b94509STom Lendacky CCP_XTS_AES_UNIT_SIZE__LAST,
21063b94509STom Lendacky };
21163b94509STom Lendacky
21263b94509STom Lendacky /**
21363b94509STom Lendacky * struct ccp_xts_aes_engine - CCP XTS AES operation
21463b94509STom Lendacky * @action: AES operation (decrypt/encrypt)
21563b94509STom Lendacky * @unit_size: unit size of the XTS operation
21663b94509STom Lendacky * @key: key to be used for this XTS AES operation
21763b94509STom Lendacky * @key_len: length in bytes of key
21863b94509STom Lendacky * @iv: IV to be used for this XTS AES operation
21963b94509STom Lendacky * @iv_len: length in bytes of iv
22063b94509STom Lendacky * @src: data to be used for this operation
22163b94509STom Lendacky * @dst: data produced by this operation
22263b94509STom Lendacky * @src_len: length in bytes of data used for this operation
22363b94509STom Lendacky * @final: indicates final XTS operation
22463b94509STom Lendacky *
22563b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
22663b94509STom Lendacky * - action, unit_size, key, key_len, iv, iv_len, src, dst, src_len, final
22763b94509STom Lendacky *
22863b94509STom Lendacky * The iv variable is used as both input and output. On completion of the
22963b94509STom Lendacky * AES operation the new IV overwrites the old IV.
23063b94509STom Lendacky */
23163b94509STom Lendacky struct ccp_xts_aes_engine {
232e652399eSGary R Hook enum ccp_aes_type type;
23363b94509STom Lendacky enum ccp_aes_action action;
23463b94509STom Lendacky enum ccp_xts_aes_unit_size unit_size;
23563b94509STom Lendacky
23663b94509STom Lendacky struct scatterlist *key;
23763b94509STom Lendacky u32 key_len; /* In bytes */
23863b94509STom Lendacky
23963b94509STom Lendacky struct scatterlist *iv;
24063b94509STom Lendacky u32 iv_len; /* In bytes */
24163b94509STom Lendacky
24263b94509STom Lendacky struct scatterlist *src, *dst;
24381a59f00STom Lendacky u64 src_len; /* In bytes */
24463b94509STom Lendacky
24563b94509STom Lendacky u32 final;
24663b94509STom Lendacky };
24763b94509STom Lendacky
24863b94509STom Lendacky /***** SHA engine *****/
24963b94509STom Lendacky /**
25063b94509STom Lendacky * ccp_sha_type - type of SHA operation
25163b94509STom Lendacky *
25263b94509STom Lendacky * @CCP_SHA_TYPE_1: SHA-1 operation
25363b94509STom Lendacky * @CCP_SHA_TYPE_224: SHA-224 operation
25463b94509STom Lendacky * @CCP_SHA_TYPE_256: SHA-256 operation
25563b94509STom Lendacky */
25663b94509STom Lendacky enum ccp_sha_type {
25763b94509STom Lendacky CCP_SHA_TYPE_1 = 1,
25863b94509STom Lendacky CCP_SHA_TYPE_224,
25963b94509STom Lendacky CCP_SHA_TYPE_256,
260ccebcf3fSGary R Hook CCP_SHA_TYPE_384,
261ccebcf3fSGary R Hook CCP_SHA_TYPE_512,
26263b94509STom Lendacky CCP_SHA_TYPE__LAST,
26363b94509STom Lendacky };
26463b94509STom Lendacky
26563b94509STom Lendacky /**
26663b94509STom Lendacky * struct ccp_sha_engine - CCP SHA operation
26763b94509STom Lendacky * @type: Type of SHA operation
26863b94509STom Lendacky * @ctx: current hash value
26963b94509STom Lendacky * @ctx_len: length in bytes of hash value
27063b94509STom Lendacky * @src: data to be used for this operation
27163b94509STom Lendacky * @src_len: length in bytes of data used for this operation
272c11baa02STom Lendacky * @opad: data to be used for final HMAC operation
273c11baa02STom Lendacky * @opad_len: length in bytes of data used for final HMAC operation
274c11baa02STom Lendacky * @first: indicates first SHA operation
27563b94509STom Lendacky * @final: indicates final SHA operation
27663b94509STom Lendacky * @msg_bits: total length of the message in bits used in final SHA operation
27763b94509STom Lendacky *
27863b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
27963b94509STom Lendacky * - type, ctx, ctx_len, src, src_len, final
28063b94509STom Lendacky * - msg_bits if final is non-zero
28163b94509STom Lendacky *
28263b94509STom Lendacky * The ctx variable is used as both input and output. On completion of the
28363b94509STom Lendacky * SHA operation the new hash value overwrites the old hash value.
28463b94509STom Lendacky */
28563b94509STom Lendacky struct ccp_sha_engine {
28663b94509STom Lendacky enum ccp_sha_type type;
28763b94509STom Lendacky
28863b94509STom Lendacky struct scatterlist *ctx;
28963b94509STom Lendacky u32 ctx_len; /* In bytes */
29063b94509STom Lendacky
29163b94509STom Lendacky struct scatterlist *src;
29281a59f00STom Lendacky u64 src_len; /* In bytes */
29363b94509STom Lendacky
294c11baa02STom Lendacky struct scatterlist *opad;
295c11baa02STom Lendacky u32 opad_len; /* In bytes */
296c11baa02STom Lendacky
297c11baa02STom Lendacky u32 first; /* Indicates first sha cmd */
29863b94509STom Lendacky u32 final; /* Indicates final sha cmd */
29963b94509STom Lendacky u64 msg_bits; /* Message length in bits required for
30063b94509STom Lendacky * final sha cmd */
30163b94509STom Lendacky };
30263b94509STom Lendacky
303990672d4SGary R Hook /***** 3DES engine *****/
304990672d4SGary R Hook enum ccp_des3_mode {
305990672d4SGary R Hook CCP_DES3_MODE_ECB = 0,
306990672d4SGary R Hook CCP_DES3_MODE_CBC,
307990672d4SGary R Hook CCP_DES3_MODE_CFB,
308990672d4SGary R Hook CCP_DES3_MODE__LAST,
309990672d4SGary R Hook };
310990672d4SGary R Hook
311990672d4SGary R Hook enum ccp_des3_type {
312990672d4SGary R Hook CCP_DES3_TYPE_168 = 1,
313990672d4SGary R Hook CCP_DES3_TYPE__LAST,
314990672d4SGary R Hook };
315990672d4SGary R Hook
316990672d4SGary R Hook enum ccp_des3_action {
317990672d4SGary R Hook CCP_DES3_ACTION_DECRYPT = 0,
318990672d4SGary R Hook CCP_DES3_ACTION_ENCRYPT,
319990672d4SGary R Hook CCP_DES3_ACTION__LAST,
320990672d4SGary R Hook };
321990672d4SGary R Hook
322990672d4SGary R Hook /**
323990672d4SGary R Hook * struct ccp_des3_engine - CCP SHA operation
324990672d4SGary R Hook * @type: Type of 3DES operation
325990672d4SGary R Hook * @mode: cipher mode
326990672d4SGary R Hook * @action: 3DES operation (decrypt/encrypt)
327990672d4SGary R Hook * @key: key to be used for this 3DES operation
328990672d4SGary R Hook * @key_len: length of key (in bytes)
329990672d4SGary R Hook * @iv: IV to be used for this AES operation
330990672d4SGary R Hook * @iv_len: length in bytes of iv
331990672d4SGary R Hook * @src: input data to be used for this operation
332990672d4SGary R Hook * @src_len: length of input data used for this operation (in bytes)
333990672d4SGary R Hook * @dst: output data produced by this operation
334990672d4SGary R Hook *
335990672d4SGary R Hook * Variables required to be set when calling ccp_enqueue_cmd():
336990672d4SGary R Hook * - type, mode, action, key, key_len, src, dst, src_len
337990672d4SGary R Hook * - iv, iv_len for any mode other than ECB
338990672d4SGary R Hook *
339990672d4SGary R Hook * The iv variable is used as both input and output. On completion of the
340990672d4SGary R Hook * 3DES operation the new IV overwrites the old IV.
341990672d4SGary R Hook */
342990672d4SGary R Hook struct ccp_des3_engine {
343990672d4SGary R Hook enum ccp_des3_type type;
344990672d4SGary R Hook enum ccp_des3_mode mode;
345990672d4SGary R Hook enum ccp_des3_action action;
346990672d4SGary R Hook
347990672d4SGary R Hook struct scatterlist *key;
348990672d4SGary R Hook u32 key_len; /* In bytes */
349990672d4SGary R Hook
350990672d4SGary R Hook struct scatterlist *iv;
351990672d4SGary R Hook u32 iv_len; /* In bytes */
352990672d4SGary R Hook
353990672d4SGary R Hook struct scatterlist *src, *dst;
354990672d4SGary R Hook u64 src_len; /* In bytes */
355990672d4SGary R Hook };
356990672d4SGary R Hook
35763b94509STom Lendacky /***** RSA engine *****/
35863b94509STom Lendacky /**
35963b94509STom Lendacky * struct ccp_rsa_engine - CCP RSA operation
36063b94509STom Lendacky * @key_size: length in bits of RSA key
36163b94509STom Lendacky * @exp: RSA exponent
36263b94509STom Lendacky * @exp_len: length in bytes of exponent
36363b94509STom Lendacky * @mod: RSA modulus
36463b94509STom Lendacky * @mod_len: length in bytes of modulus
36563b94509STom Lendacky * @src: data to be used for this operation
36663b94509STom Lendacky * @dst: data produced by this operation
36763b94509STom Lendacky * @src_len: length in bytes of data used for this operation
36863b94509STom Lendacky *
36963b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
37063b94509STom Lendacky * - key_size, exp, exp_len, mod, mod_len, src, dst, src_len
37163b94509STom Lendacky */
37263b94509STom Lendacky struct ccp_rsa_engine {
37363b94509STom Lendacky u32 key_size; /* In bits */
37463b94509STom Lendacky
37563b94509STom Lendacky struct scatterlist *exp;
37663b94509STom Lendacky u32 exp_len; /* In bytes */
37763b94509STom Lendacky
37863b94509STom Lendacky struct scatterlist *mod;
37963b94509STom Lendacky u32 mod_len; /* In bytes */
38063b94509STom Lendacky
38163b94509STom Lendacky struct scatterlist *src, *dst;
38263b94509STom Lendacky u32 src_len; /* In bytes */
38363b94509STom Lendacky };
38463b94509STom Lendacky
38563b94509STom Lendacky /***** Passthru engine *****/
38663b94509STom Lendacky /**
38763b94509STom Lendacky * ccp_passthru_bitwise - type of bitwise passthru operation
38863b94509STom Lendacky *
38963b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_NOOP: no bitwise operation performed
39063b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_AND: perform bitwise AND of src with mask
39163b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_OR: perform bitwise OR of src with mask
39263b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_XOR: perform bitwise XOR of src with mask
39363b94509STom Lendacky * @CCP_PASSTHRU_BITWISE_MASK: overwrite with mask
39463b94509STom Lendacky */
39563b94509STom Lendacky enum ccp_passthru_bitwise {
39663b94509STom Lendacky CCP_PASSTHRU_BITWISE_NOOP = 0,
39763b94509STom Lendacky CCP_PASSTHRU_BITWISE_AND,
39863b94509STom Lendacky CCP_PASSTHRU_BITWISE_OR,
39963b94509STom Lendacky CCP_PASSTHRU_BITWISE_XOR,
40063b94509STom Lendacky CCP_PASSTHRU_BITWISE_MASK,
40163b94509STom Lendacky CCP_PASSTHRU_BITWISE__LAST,
40263b94509STom Lendacky };
40363b94509STom Lendacky
40463b94509STom Lendacky /**
40563b94509STom Lendacky * ccp_passthru_byteswap - type of byteswap passthru operation
40663b94509STom Lendacky *
40763b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_NOOP: no byte swapping performed
40863b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_32BIT: swap bytes within 32-bit words
40963b94509STom Lendacky * @CCP_PASSTHRU_BYTESWAP_256BIT: swap bytes within 256-bit words
41063b94509STom Lendacky */
41163b94509STom Lendacky enum ccp_passthru_byteswap {
41263b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_NOOP = 0,
41363b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_32BIT,
41463b94509STom Lendacky CCP_PASSTHRU_BYTESWAP_256BIT,
41563b94509STom Lendacky CCP_PASSTHRU_BYTESWAP__LAST,
41663b94509STom Lendacky };
41763b94509STom Lendacky
41863b94509STom Lendacky /**
41963b94509STom Lendacky * struct ccp_passthru_engine - CCP pass-through operation
42063b94509STom Lendacky * @bit_mod: bitwise operation to perform
42163b94509STom Lendacky * @byte_swap: byteswap operation to perform
42263b94509STom Lendacky * @mask: mask to be applied to data
42363b94509STom Lendacky * @mask_len: length in bytes of mask
42463b94509STom Lendacky * @src: data to be used for this operation
42563b94509STom Lendacky * @dst: data produced by this operation
42663b94509STom Lendacky * @src_len: length in bytes of data used for this operation
42763b94509STom Lendacky * @final: indicate final pass-through operation
42863b94509STom Lendacky *
42963b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
43063b94509STom Lendacky * - bit_mod, byte_swap, src, dst, src_len
43163b94509STom Lendacky * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
43263b94509STom Lendacky */
43363b94509STom Lendacky struct ccp_passthru_engine {
43463b94509STom Lendacky enum ccp_passthru_bitwise bit_mod;
43563b94509STom Lendacky enum ccp_passthru_byteswap byte_swap;
43663b94509STom Lendacky
43763b94509STom Lendacky struct scatterlist *mask;
43863b94509STom Lendacky u32 mask_len; /* In bytes */
43963b94509STom Lendacky
44063b94509STom Lendacky struct scatterlist *src, *dst;
44181a59f00STom Lendacky u64 src_len; /* In bytes */
44263b94509STom Lendacky
44363b94509STom Lendacky u32 final;
44463b94509STom Lendacky };
44563b94509STom Lendacky
44658ea8abfSGary R Hook /**
44758ea8abfSGary R Hook * struct ccp_passthru_nomap_engine - CCP pass-through operation
44858ea8abfSGary R Hook * without performing DMA mapping
44958ea8abfSGary R Hook * @bit_mod: bitwise operation to perform
45058ea8abfSGary R Hook * @byte_swap: byteswap operation to perform
45158ea8abfSGary R Hook * @mask: mask to be applied to data
45258ea8abfSGary R Hook * @mask_len: length in bytes of mask
45358ea8abfSGary R Hook * @src: data to be used for this operation
45458ea8abfSGary R Hook * @dst: data produced by this operation
45558ea8abfSGary R Hook * @src_len: length in bytes of data used for this operation
45658ea8abfSGary R Hook * @final: indicate final pass-through operation
45758ea8abfSGary R Hook *
45858ea8abfSGary R Hook * Variables required to be set when calling ccp_enqueue_cmd():
45958ea8abfSGary R Hook * - bit_mod, byte_swap, src, dst, src_len
46058ea8abfSGary R Hook * - mask, mask_len if bit_mod is not CCP_PASSTHRU_BITWISE_NOOP
46158ea8abfSGary R Hook */
46258ea8abfSGary R Hook struct ccp_passthru_nomap_engine {
46358ea8abfSGary R Hook enum ccp_passthru_bitwise bit_mod;
46458ea8abfSGary R Hook enum ccp_passthru_byteswap byte_swap;
46558ea8abfSGary R Hook
46658ea8abfSGary R Hook dma_addr_t mask;
46758ea8abfSGary R Hook u32 mask_len; /* In bytes */
46858ea8abfSGary R Hook
46958ea8abfSGary R Hook dma_addr_t src_dma, dst_dma;
47058ea8abfSGary R Hook u64 src_len; /* In bytes */
47158ea8abfSGary R Hook
47258ea8abfSGary R Hook u32 final;
47358ea8abfSGary R Hook };
47458ea8abfSGary R Hook
47563b94509STom Lendacky /***** ECC engine *****/
47663b94509STom Lendacky #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */
47763b94509STom Lendacky #define CCP_ECC_MAX_OPERANDS 6
47863b94509STom Lendacky #define CCP_ECC_MAX_OUTPUTS 3
47963b94509STom Lendacky
48063b94509STom Lendacky /**
48163b94509STom Lendacky * ccp_ecc_function - type of ECC function
48263b94509STom Lendacky *
48363b94509STom Lendacky * @CCP_ECC_FUNCTION_MMUL_384BIT: 384-bit modular multiplication
48463b94509STom Lendacky * @CCP_ECC_FUNCTION_MADD_384BIT: 384-bit modular addition
48563b94509STom Lendacky * @CCP_ECC_FUNCTION_MINV_384BIT: 384-bit multiplicative inverse
48663b94509STom Lendacky * @CCP_ECC_FUNCTION_PADD_384BIT: 384-bit point addition
48763b94509STom Lendacky * @CCP_ECC_FUNCTION_PMUL_384BIT: 384-bit point multiplication
48863b94509STom Lendacky * @CCP_ECC_FUNCTION_PDBL_384BIT: 384-bit point doubling
48963b94509STom Lendacky */
49063b94509STom Lendacky enum ccp_ecc_function {
49163b94509STom Lendacky CCP_ECC_FUNCTION_MMUL_384BIT = 0,
49263b94509STom Lendacky CCP_ECC_FUNCTION_MADD_384BIT,
49363b94509STom Lendacky CCP_ECC_FUNCTION_MINV_384BIT,
49463b94509STom Lendacky CCP_ECC_FUNCTION_PADD_384BIT,
49563b94509STom Lendacky CCP_ECC_FUNCTION_PMUL_384BIT,
49663b94509STom Lendacky CCP_ECC_FUNCTION_PDBL_384BIT,
49763b94509STom Lendacky };
49863b94509STom Lendacky
49963b94509STom Lendacky /**
50063b94509STom Lendacky * struct ccp_ecc_modular_math - CCP ECC modular math parameters
50163b94509STom Lendacky * @operand_1: first operand for the modular math operation
50263b94509STom Lendacky * @operand_1_len: length of the first operand
50363b94509STom Lendacky * @operand_2: second operand for the modular math operation
50463b94509STom Lendacky * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
50563b94509STom Lendacky * @operand_2_len: length of the second operand
50663b94509STom Lendacky * (not used for CCP_ECC_FUNCTION_MINV_384BIT)
50763b94509STom Lendacky * @result: result of the modular math operation
50863b94509STom Lendacky * @result_len: length of the supplied result buffer
50963b94509STom Lendacky */
51063b94509STom Lendacky struct ccp_ecc_modular_math {
51163b94509STom Lendacky struct scatterlist *operand_1;
51263b94509STom Lendacky unsigned int operand_1_len; /* In bytes */
51363b94509STom Lendacky
51463b94509STom Lendacky struct scatterlist *operand_2;
51563b94509STom Lendacky unsigned int operand_2_len; /* In bytes */
51663b94509STom Lendacky
51763b94509STom Lendacky struct scatterlist *result;
51863b94509STom Lendacky unsigned int result_len; /* In bytes */
51963b94509STom Lendacky };
52063b94509STom Lendacky
52163b94509STom Lendacky /**
52263b94509STom Lendacky * struct ccp_ecc_point - CCP ECC point definition
52363b94509STom Lendacky * @x: the x coordinate of the ECC point
52463b94509STom Lendacky * @x_len: the length of the x coordinate
52563b94509STom Lendacky * @y: the y coordinate of the ECC point
52663b94509STom Lendacky * @y_len: the length of the y coordinate
52763b94509STom Lendacky */
52863b94509STom Lendacky struct ccp_ecc_point {
52963b94509STom Lendacky struct scatterlist *x;
53063b94509STom Lendacky unsigned int x_len; /* In bytes */
53163b94509STom Lendacky
53263b94509STom Lendacky struct scatterlist *y;
53363b94509STom Lendacky unsigned int y_len; /* In bytes */
53463b94509STom Lendacky };
53563b94509STom Lendacky
53663b94509STom Lendacky /**
53763b94509STom Lendacky * struct ccp_ecc_point_math - CCP ECC point math parameters
53863b94509STom Lendacky * @point_1: the first point of the ECC point math operation
53963b94509STom Lendacky * @point_2: the second point of the ECC point math operation
54063b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PADD_384BIT)
54163b94509STom Lendacky * @domain_a: the a parameter of the ECC curve
54263b94509STom Lendacky * @domain_a_len: the length of the a parameter
54363b94509STom Lendacky * @scalar: the scalar parameter for the point match operation
54463b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
54563b94509STom Lendacky * @scalar_len: the length of the scalar parameter
54663b94509STom Lendacky * (only used for CCP_ECC_FUNCTION_PMUL_384BIT)
54763b94509STom Lendacky * @result: the point resulting from the point math operation
54863b94509STom Lendacky */
54963b94509STom Lendacky struct ccp_ecc_point_math {
55063b94509STom Lendacky struct ccp_ecc_point point_1;
55163b94509STom Lendacky struct ccp_ecc_point point_2;
55263b94509STom Lendacky
55363b94509STom Lendacky struct scatterlist *domain_a;
55463b94509STom Lendacky unsigned int domain_a_len; /* In bytes */
55563b94509STom Lendacky
55663b94509STom Lendacky struct scatterlist *scalar;
55763b94509STom Lendacky unsigned int scalar_len; /* In bytes */
55863b94509STom Lendacky
55963b94509STom Lendacky struct ccp_ecc_point result;
56063b94509STom Lendacky };
56163b94509STom Lendacky
56263b94509STom Lendacky /**
56363b94509STom Lendacky * struct ccp_ecc_engine - CCP ECC operation
56463b94509STom Lendacky * @function: ECC function to perform
56563b94509STom Lendacky * @mod: ECC modulus
56663b94509STom Lendacky * @mod_len: length in bytes of modulus
56763b94509STom Lendacky * @mm: module math parameters
56863b94509STom Lendacky * @pm: point math parameters
56963b94509STom Lendacky * @ecc_result: result of the ECC operation
57063b94509STom Lendacky *
57163b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
57263b94509STom Lendacky * - function, mod, mod_len
57363b94509STom Lendacky * - operand, operand_len, operand_count, output, output_len, output_count
57463b94509STom Lendacky * - ecc_result
57563b94509STom Lendacky */
57663b94509STom Lendacky struct ccp_ecc_engine {
57763b94509STom Lendacky enum ccp_ecc_function function;
57863b94509STom Lendacky
57963b94509STom Lendacky struct scatterlist *mod;
58063b94509STom Lendacky u32 mod_len; /* In bytes */
58163b94509STom Lendacky
58263b94509STom Lendacky union {
58363b94509STom Lendacky struct ccp_ecc_modular_math mm;
58463b94509STom Lendacky struct ccp_ecc_point_math pm;
58563b94509STom Lendacky } u;
58663b94509STom Lendacky
58763b94509STom Lendacky u16 ecc_result;
58863b94509STom Lendacky };
58963b94509STom Lendacky
59063b94509STom Lendacky
59163b94509STom Lendacky /**
59263b94509STom Lendacky * ccp_engine - CCP operation identifiers
59363b94509STom Lendacky *
59463b94509STom Lendacky * @CCP_ENGINE_AES: AES operation
59563b94509STom Lendacky * @CCP_ENGINE_XTS_AES: 128-bit XTS AES operation
59663b94509STom Lendacky * @CCP_ENGINE_RSVD1: unused
59763b94509STom Lendacky * @CCP_ENGINE_SHA: SHA operation
59863b94509STom Lendacky * @CCP_ENGINE_RSA: RSA operation
59963b94509STom Lendacky * @CCP_ENGINE_PASSTHRU: pass-through operation
60063b94509STom Lendacky * @CCP_ENGINE_ZLIB_DECOMPRESS: unused
60163b94509STom Lendacky * @CCP_ENGINE_ECC: ECC operation
60263b94509STom Lendacky */
60363b94509STom Lendacky enum ccp_engine {
60463b94509STom Lendacky CCP_ENGINE_AES = 0,
60563b94509STom Lendacky CCP_ENGINE_XTS_AES_128,
606990672d4SGary R Hook CCP_ENGINE_DES3,
60763b94509STom Lendacky CCP_ENGINE_SHA,
60863b94509STom Lendacky CCP_ENGINE_RSA,
60963b94509STom Lendacky CCP_ENGINE_PASSTHRU,
61063b94509STom Lendacky CCP_ENGINE_ZLIB_DECOMPRESS,
61163b94509STom Lendacky CCP_ENGINE_ECC,
61263b94509STom Lendacky CCP_ENGINE__LAST,
61363b94509STom Lendacky };
61463b94509STom Lendacky
61563b94509STom Lendacky /* Flag values for flags member of ccp_cmd */
61663b94509STom Lendacky #define CCP_CMD_MAY_BACKLOG 0x00000001
61758ea8abfSGary R Hook #define CCP_CMD_PASSTHRU_NO_DMA_MAP 0x00000002
61863b94509STom Lendacky
61963b94509STom Lendacky /**
620c8d283ffSPaul Bolle * struct ccp_cmd - CCP operation request
62163b94509STom Lendacky * @entry: list element (ccp driver use only)
62263b94509STom Lendacky * @work: work element used for callbacks (ccp driver use only)
6237c468447SGary R Hook * @ccp: CCP device to be run on
62463b94509STom Lendacky * @ret: operation return code (ccp driver use only)
62563b94509STom Lendacky * @flags: cmd processing flags
62663b94509STom Lendacky * @engine: CCP operation to perform
62763b94509STom Lendacky * @engine_error: CCP engine return code
62863b94509STom Lendacky * @u: engine specific structures, refer to specific engine struct below
62963b94509STom Lendacky * @callback: operation completion callback function
63063b94509STom Lendacky * @data: parameter value to be supplied to the callback function
63163b94509STom Lendacky *
63263b94509STom Lendacky * Variables required to be set when calling ccp_enqueue_cmd():
63363b94509STom Lendacky * - engine, callback
63463b94509STom Lendacky * - See the operation structures below for what is required for each
63563b94509STom Lendacky * operation.
63663b94509STom Lendacky */
63763b94509STom Lendacky struct ccp_cmd {
63863b94509STom Lendacky /* The list_head, work_struct, ccp and ret variables are for use
63963b94509STom Lendacky * by the CCP driver only.
64063b94509STom Lendacky */
64163b94509STom Lendacky struct list_head entry;
64263b94509STom Lendacky struct work_struct work;
64363b94509STom Lendacky struct ccp_device *ccp;
64463b94509STom Lendacky int ret;
64563b94509STom Lendacky
64663b94509STom Lendacky u32 flags;
64763b94509STom Lendacky
64863b94509STom Lendacky enum ccp_engine engine;
64963b94509STom Lendacky u32 engine_error;
65063b94509STom Lendacky
65163b94509STom Lendacky union {
65263b94509STom Lendacky struct ccp_aes_engine aes;
65363b94509STom Lendacky struct ccp_xts_aes_engine xts;
654990672d4SGary R Hook struct ccp_des3_engine des3;
65563b94509STom Lendacky struct ccp_sha_engine sha;
65663b94509STom Lendacky struct ccp_rsa_engine rsa;
65763b94509STom Lendacky struct ccp_passthru_engine passthru;
65858ea8abfSGary R Hook struct ccp_passthru_nomap_engine passthru_nomap;
65963b94509STom Lendacky struct ccp_ecc_engine ecc;
66063b94509STom Lendacky } u;
66163b94509STom Lendacky
66263b94509STom Lendacky /* Completion callback support */
66363b94509STom Lendacky void (*callback)(void *data, int err);
66463b94509STom Lendacky void *data;
66563b94509STom Lendacky };
66663b94509STom Lendacky
66763b94509STom Lendacky #endif
668