Skip to content

Commit 4dd4d5e

Browse files
committed
crypto: amlogic - Use new crypto_engine_op interface
Use the new crypto_engine_op interface where the callback is stored in the algorithm object. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 4c19e8f commit 4dd4d5e

3 files changed

Lines changed: 47 additions & 29 deletions

File tree

drivers/crypto/amlogic/amlogic-gxl-cipher.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static int meson_cipher_do_fallback(struct skcipher_request *areq)
6565
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
6666
struct meson_alg_template *algt;
6767

68-
algt = container_of(alg, struct meson_alg_template, alg.skcipher);
68+
algt = container_of(alg, struct meson_alg_template, alg.skcipher.base);
6969
algt->stat_fb++;
7070
#endif
7171
skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
@@ -101,7 +101,7 @@ static int meson_cipher(struct skcipher_request *areq)
101101
void *backup_iv = NULL, *bkeyiv;
102102
u32 v;
103103

104-
algt = container_of(alg, struct meson_alg_template, alg.skcipher);
104+
algt = container_of(alg, struct meson_alg_template, alg.skcipher.base);
105105

106106
dev_dbg(mc->dev, "%s %s %u %x IV(%u) key=%u flow=%d\n", __func__,
107107
crypto_tfm_alg_name(areq->base.tfm),
@@ -258,8 +258,7 @@ static int meson_cipher(struct skcipher_request *areq)
258258
return err;
259259
}
260260

261-
static int meson_handle_cipher_request(struct crypto_engine *engine,
262-
void *areq)
261+
int meson_handle_cipher_request(struct crypto_engine *engine, void *areq)
263262
{
264263
int err;
265264
struct skcipher_request *breq = container_of(areq, struct skcipher_request, base);
@@ -318,7 +317,7 @@ int meson_cipher_init(struct crypto_tfm *tfm)
318317

319318
memset(op, 0, sizeof(struct meson_cipher_tfm_ctx));
320319

321-
algt = container_of(alg, struct meson_alg_template, alg.skcipher);
320+
algt = container_of(alg, struct meson_alg_template, alg.skcipher.base);
322321
op->mc = algt->mc;
323322

324323
op->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
@@ -331,8 +330,6 @@ int meson_cipher_init(struct crypto_tfm *tfm)
331330
sktfm->reqsize = sizeof(struct meson_cipher_req_ctx) +
332331
crypto_skcipher_reqsize(op->fallback_tfm);
333332

334-
op->enginectx.op.do_one_request = meson_handle_cipher_request;
335-
336333
return 0;
337334
}
338335

drivers/crypto/amlogic/amlogic-gxl-core.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
*
77
* Core file which registers crypto algorithms supported by the hardware.
88
*/
9+
10+
#include <crypto/engine.h>
11+
#include <crypto/internal/skcipher.h>
912
#include <linux/clk.h>
10-
#include <linux/crypto.h>
11-
#include <linux/io.h>
13+
#include <linux/dma-mapping.h>
14+
#include <linux/err.h>
1215
#include <linux/interrupt.h>
16+
#include <linux/io.h>
1317
#include <linux/irq.h>
18+
#include <linux/kernel.h>
1419
#include <linux/module.h>
1520
#include <linux/of.h>
1621
#include <linux/of_device.h>
1722
#include <linux/platform_device.h>
18-
#include <crypto/internal/skcipher.h>
19-
#include <linux/dma-mapping.h>
2023

2124
#include "amlogic-gxl.h"
2225

@@ -47,7 +50,7 @@ static struct meson_alg_template mc_algs[] = {
4750
{
4851
.type = CRYPTO_ALG_TYPE_SKCIPHER,
4952
.blockmode = MESON_OPMODE_CBC,
50-
.alg.skcipher = {
53+
.alg.skcipher.base = {
5154
.base = {
5255
.cra_name = "cbc(aes)",
5356
.cra_driver_name = "cbc-aes-gxl",
@@ -68,12 +71,15 @@ static struct meson_alg_template mc_algs[] = {
6871
.setkey = meson_aes_setkey,
6972
.encrypt = meson_skencrypt,
7073
.decrypt = meson_skdecrypt,
71-
}
74+
},
75+
.alg.skcipher.op = {
76+
.do_one_request = meson_handle_cipher_request,
77+
},
7278
},
7379
{
7480
.type = CRYPTO_ALG_TYPE_SKCIPHER,
7581
.blockmode = MESON_OPMODE_ECB,
76-
.alg.skcipher = {
82+
.alg.skcipher.base = {
7783
.base = {
7884
.cra_name = "ecb(aes)",
7985
.cra_driver_name = "ecb-aes-gxl",
@@ -93,33 +99,43 @@ static struct meson_alg_template mc_algs[] = {
9399
.setkey = meson_aes_setkey,
94100
.encrypt = meson_skencrypt,
95101
.decrypt = meson_skdecrypt,
96-
}
102+
},
103+
.alg.skcipher.op = {
104+
.do_one_request = meson_handle_cipher_request,
105+
},
97106
},
98107
};
99108

100-
#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
101109
static int meson_debugfs_show(struct seq_file *seq, void *v)
102110
{
103-
struct meson_dev *mc = seq->private;
111+
struct meson_dev *mc __maybe_unused = seq->private;
104112
int i;
105113

106114
for (i = 0; i < MAXFLOW; i++)
107-
seq_printf(seq, "Channel %d: nreq %lu\n", i, mc->chanlist[i].stat_req);
115+
seq_printf(seq, "Channel %d: nreq %lu\n", i,
116+
#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
117+
mc->chanlist[i].stat_req);
118+
#else
119+
0ul);
120+
#endif
108121

109122
for (i = 0; i < ARRAY_SIZE(mc_algs); i++) {
110123
switch (mc_algs[i].type) {
111124
case CRYPTO_ALG_TYPE_SKCIPHER:
112125
seq_printf(seq, "%s %s %lu %lu\n",
113-
mc_algs[i].alg.skcipher.base.cra_driver_name,
114-
mc_algs[i].alg.skcipher.base.cra_name,
126+
mc_algs[i].alg.skcipher.base.base.cra_driver_name,
127+
mc_algs[i].alg.skcipher.base.base.cra_name,
128+
#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
115129
mc_algs[i].stat_req, mc_algs[i].stat_fb);
130+
#else
131+
0ul, 0ul);
132+
#endif
116133
break;
117134
}
118135
}
119136
return 0;
120137
}
121138
DEFINE_SHOW_ATTRIBUTE(meson_debugfs);
122-
#endif
123139

124140
static void meson_free_chanlist(struct meson_dev *mc, int i)
125141
{
@@ -183,10 +199,10 @@ static int meson_register_algs(struct meson_dev *mc)
183199
mc_algs[i].mc = mc;
184200
switch (mc_algs[i].type) {
185201
case CRYPTO_ALG_TYPE_SKCIPHER:
186-
err = crypto_register_skcipher(&mc_algs[i].alg.skcipher);
202+
err = crypto_engine_register_skcipher(&mc_algs[i].alg.skcipher);
187203
if (err) {
188204
dev_err(mc->dev, "Fail to register %s\n",
189-
mc_algs[i].alg.skcipher.base.cra_name);
205+
mc_algs[i].alg.skcipher.base.base.cra_name);
190206
mc_algs[i].mc = NULL;
191207
return err;
192208
}
@@ -206,7 +222,7 @@ static void meson_unregister_algs(struct meson_dev *mc)
206222
continue;
207223
switch (mc_algs[i].type) {
208224
case CRYPTO_ALG_TYPE_SKCIPHER:
209-
crypto_unregister_skcipher(&mc_algs[i].alg.skcipher);
225+
crypto_engine_unregister_skcipher(&mc_algs[i].alg.skcipher);
210226
break;
211227
}
212228
}
@@ -264,10 +280,16 @@ static int meson_crypto_probe(struct platform_device *pdev)
264280
if (err)
265281
goto error_alg;
266282

283+
if (IS_ENABLED(CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG)) {
284+
struct dentry *dbgfs_dir;
285+
286+
dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL);
287+
debugfs_create_file("stats", 0444, dbgfs_dir, mc, &meson_debugfs_fops);
288+
267289
#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
268-
mc->dbgfs_dir = debugfs_create_dir("gxl-crypto", NULL);
269-
debugfs_create_file("stats", 0444, mc->dbgfs_dir, mc, &meson_debugfs_fops);
290+
mc->dbgfs_dir = dbgfs_dir;
270291
#endif
292+
}
271293

272294
return 0;
273295
error_alg:

drivers/crypto/amlogic/amlogic-gxl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ struct meson_cipher_req_ctx {
114114

115115
/*
116116
* struct meson_cipher_tfm_ctx - context for a skcipher TFM
117-
* @enginectx: crypto_engine used by this TFM
118117
* @key: pointer to key data
119118
* @keylen: len of the key
120119
* @keymode: The keymode(type and size of key) associated with this TFM
121120
* @mc: pointer to the private data of driver handling this TFM
122121
* @fallback_tfm: pointer to the fallback TFM
123122
*/
124123
struct meson_cipher_tfm_ctx {
125-
struct crypto_engine_ctx enginectx;
126124
u32 *key;
127125
u32 keylen;
128126
u32 keymode;
@@ -143,7 +141,7 @@ struct meson_alg_template {
143141
u32 type;
144142
u32 blockmode;
145143
union {
146-
struct skcipher_alg skcipher;
144+
struct skcipher_engine_alg skcipher;
147145
} alg;
148146
struct meson_dev *mc;
149147
#ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
@@ -160,3 +158,4 @@ int meson_cipher_init(struct crypto_tfm *tfm);
160158
void meson_cipher_exit(struct crypto_tfm *tfm);
161159
int meson_skdecrypt(struct skcipher_request *areq);
162160
int meson_skencrypt(struct skcipher_request *areq);
161+
int meson_handle_cipher_request(struct crypto_engine *engine, void *areq);

0 commit comments

Comments
 (0)