1 /* SPDX-License-Identifier: GPL-2.0 */
3 * amlogic.h - hardware cryptographic offloader for Amlogic SoC
5 * Copyright (C) 2018-2019 Corentin LABBE <clabbe@baylibre.com>
7 #include <crypto/aes.h>
8 #include <crypto/engine.h>
9 #include <crypto/skcipher.h>
10 #include <linux/debugfs.h>
11 #include <linux/crypto.h>
12 #include <linux/scatterlist.h>
15 #define MODE_AES_128 0x8
16 #define MODE_AES_192 0x9
17 #define MODE_AES_256 0xa
19 #define MESON_DECRYPT 0
20 #define MESON_ENCRYPT 1
22 #define MESON_OPMODE_ECB 0
23 #define MESON_OPMODE_CBC 1
29 #define DESC_LAST BIT(18)
30 #define DESC_ENCRYPTION BIT(28)
31 #define DESC_OWN BIT(31)
34 * struct meson_desc - Descriptor for DMA operations
35 * Note that without datasheet, some are unknown
36 * @t_status: Descriptor of the cipher operation (see description below)
37 * @t_src: Physical address of data to read
38 * @t_dst: Physical address of data to write
39 * t_status is segmented like this:
40 * @len: 0-16 length of data to operate
41 * @irq: 17 Ignored by hardware
42 * @eoc: 18 End means the descriptor is the last
44 * @mode: 20-23 Type of algorithm (AES, SHA)
47 * @op_mode: 26-27 Blockmode (CBC, ECB)
48 * @enc: 28 0 means decryption, 1 is for encryption
51 * @owner: 31 owner of the descriptor, 1 own by HW
60 * struct meson_flow - Information used by each flow
61 * @engine: ptr to the crypto_engine for this flow
62 * @keylen: keylen for this flow operation
63 * @complete: completion for the current task on this flow
64 * @status: set to 1 by interrupt if task is done
65 * @t_phy: Physical address of task
66 * @tl: pointer to the current ce_task for this flow
67 * @stat_req: number of request done by this flow
70 struct crypto_engine
*engine
;
71 struct completion complete
;
75 struct meson_desc
*tl
;
76 #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
77 unsigned long stat_req
;
82 * struct meson_dev - main container for all this driver information
83 * @base: base address of amlogic-crypto
84 * @busclk: bus clock for amlogic-crypto
85 * @dev: the platform device
86 * @chanlist: array of all flow
87 * @flow: flow to use in next request
88 * @irqs: IRQ numbers for amlogic-crypto
89 * @dbgfs_dir: Debugfs dentry for statistic directory
90 * @dbgfs_stats: Debugfs dentry for statistic counters
96 struct meson_flow
*chanlist
;
99 #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
100 struct dentry
*dbgfs_dir
;
105 * struct meson_cipher_req_ctx - context for a skcipher request
106 * @op_dir: direction (encrypt vs decrypt) for this request
107 * @flow: the flow to use for this request
109 struct meson_cipher_req_ctx
{
112 struct skcipher_request fallback_req
; // keep at the end
116 * struct meson_cipher_tfm_ctx - context for a skcipher TFM
117 * @key: pointer to key data
118 * @keylen: len of the key
119 * @keymode: The keymode(type and size of key) associated with this TFM
120 * @mc: pointer to the private data of driver handling this TFM
121 * @fallback_tfm: pointer to the fallback TFM
123 struct meson_cipher_tfm_ctx
{
127 struct meson_dev
*mc
;
128 struct crypto_skcipher
*fallback_tfm
;
132 * struct meson_alg_template - crypto_alg template
133 * @type: the CRYPTO_ALG_TYPE for this template
134 * @blockmode: the type of block operation
135 * @mc: pointer to the meson_dev structure associated with this template
136 * @alg: one of sub struct must be used
137 * @stat_req: number of request done on this template
138 * @stat_fb: total of all data len done on this template
140 struct meson_alg_template
{
144 struct skcipher_engine_alg skcipher
;
146 struct meson_dev
*mc
;
147 #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
148 unsigned long stat_req
;
149 unsigned long stat_fb
;
153 int meson_aes_setkey(struct crypto_skcipher
*tfm
, const u8
*key
,
154 unsigned int keylen
);
155 int meson_cipher_init(struct crypto_tfm
*tfm
);
156 void meson_cipher_exit(struct crypto_tfm
*tfm
);
157 int meson_skdecrypt(struct skcipher_request
*areq
);
158 int meson_skencrypt(struct skcipher_request
*areq
);
159 int meson_handle_cipher_request(struct crypto_engine
*engine
, void *areq
);