Skip to content

Commit 67b7702

Browse files
committed
crypto: sl3516 - 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 623814c commit 67b7702

3 files changed

Lines changed: 43 additions & 34 deletions

File tree

drivers/crypto/gemini/sl3516-ce-cipher.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
* ECB mode.
99
*/
1010

11-
#include <linux/crypto.h>
11+
#include <crypto/engine.h>
12+
#include <crypto/internal/skcipher.h>
13+
#include <crypto/scatterwalk.h>
1214
#include <linux/dma-mapping.h>
1315
#include <linux/delay.h>
16+
#include <linux/err.h>
1417
#include <linux/io.h>
18+
#include <linux/kernel.h>
1519
#include <linux/pm_runtime.h>
16-
#include <crypto/scatterwalk.h>
17-
#include <crypto/internal/skcipher.h>
20+
#include <linux/slab.h>
21+
#include <linux/string.h>
1822
#include "sl3516-ce.h"
1923

2024
/* sl3516_ce_need_fallback - check if a request can be handled by the CE */
@@ -105,7 +109,7 @@ static int sl3516_ce_cipher_fallback(struct skcipher_request *areq)
105109
struct sl3516_ce_alg_template *algt;
106110
int err;
107111

108-
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher);
112+
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher.base);
109113
algt->stat_fb++;
110114

111115
skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
@@ -136,7 +140,7 @@ static int sl3516_ce_cipher(struct skcipher_request *areq)
136140
int err = 0;
137141
int i;
138142

139-
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher);
143+
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher.base);
140144

141145
dev_dbg(ce->dev, "%s %s %u %x IV(%p %u) key=%u\n", __func__,
142146
crypto_tfm_alg_name(areq->base.tfm),
@@ -258,7 +262,7 @@ static int sl3516_ce_cipher(struct skcipher_request *areq)
258262
return err;
259263
}
260264

261-
static int sl3516_ce_handle_cipher_request(struct crypto_engine *engine, void *areq)
265+
int sl3516_ce_handle_cipher_request(struct crypto_engine *engine, void *areq)
262266
{
263267
int err;
264268
struct skcipher_request *breq = container_of(areq, struct skcipher_request, base);
@@ -318,7 +322,7 @@ int sl3516_ce_cipher_init(struct crypto_tfm *tfm)
318322

319323
memset(op, 0, sizeof(struct sl3516_ce_cipher_tfm_ctx));
320324

321-
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher);
325+
algt = container_of(alg, struct sl3516_ce_alg_template, alg.skcipher.base);
322326
op->ce = algt->ce;
323327

324328
op->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
@@ -335,8 +339,6 @@ int sl3516_ce_cipher_init(struct crypto_tfm *tfm)
335339
crypto_tfm_alg_driver_name(&sktfm->base),
336340
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(op->fallback_tfm)));
337341

338-
op->enginectx.op.do_one_request = sl3516_ce_handle_cipher_request;
339-
340342
err = pm_runtime_get_sync(op->ce->dev);
341343
if (err < 0)
342344
goto error_pm;

drivers/crypto/gemini/sl3516-ce-core.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
*
77
* Core file which registers crypto algorithms supported by the CryptoEngine
88
*/
9+
10+
#include <crypto/engine.h>
11+
#include <crypto/internal/rng.h>
12+
#include <crypto/internal/skcipher.h>
913
#include <linux/clk.h>
10-
#include <linux/crypto.h>
1114
#include <linux/debugfs.h>
1215
#include <linux/dev_printk.h>
1316
#include <linux/dma-mapping.h>
17+
#include <linux/err.h>
1418
#include <linux/interrupt.h>
1519
#include <linux/io.h>
1620
#include <linux/irq.h>
21+
#include <linux/kernel.h>
1722
#include <linux/module.h>
1823
#include <linux/of.h>
1924
#include <linux/of_device.h>
2025
#include <linux/platform_device.h>
2126
#include <linux/pm_runtime.h>
2227
#include <linux/reset.h>
23-
#include <crypto/internal/rng.h>
24-
#include <crypto/internal/skcipher.h>
2528

2629
#include "sl3516-ce.h"
2730

@@ -217,7 +220,7 @@ static struct sl3516_ce_alg_template ce_algs[] = {
217220
{
218221
.type = CRYPTO_ALG_TYPE_SKCIPHER,
219222
.mode = ECB_AES,
220-
.alg.skcipher = {
223+
.alg.skcipher.base = {
221224
.base = {
222225
.cra_name = "ecb(aes)",
223226
.cra_driver_name = "ecb-aes-sl3516",
@@ -236,11 +239,13 @@ static struct sl3516_ce_alg_template ce_algs[] = {
236239
.setkey = sl3516_ce_aes_setkey,
237240
.encrypt = sl3516_ce_skencrypt,
238241
.decrypt = sl3516_ce_skdecrypt,
239-
}
242+
},
243+
.alg.skcipher.op = {
244+
.do_one_request = sl3516_ce_handle_cipher_request,
245+
},
240246
},
241247
};
242248

243-
#ifdef CONFIG_CRYPTO_DEV_SL3516_DEBUG
244249
static int sl3516_ce_debugfs_show(struct seq_file *seq, void *v)
245250
{
246251
struct sl3516_ce_dev *ce = seq->private;
@@ -264,8 +269,8 @@ static int sl3516_ce_debugfs_show(struct seq_file *seq, void *v)
264269
switch (ce_algs[i].type) {
265270
case CRYPTO_ALG_TYPE_SKCIPHER:
266271
seq_printf(seq, "%s %s reqs=%lu fallback=%lu\n",
267-
ce_algs[i].alg.skcipher.base.cra_driver_name,
268-
ce_algs[i].alg.skcipher.base.cra_name,
272+
ce_algs[i].alg.skcipher.base.base.cra_driver_name,
273+
ce_algs[i].alg.skcipher.base.base.cra_name,
269274
ce_algs[i].stat_req, ce_algs[i].stat_fb);
270275
break;
271276
}
@@ -274,7 +279,6 @@ static int sl3516_ce_debugfs_show(struct seq_file *seq, void *v)
274279
}
275280

276281
DEFINE_SHOW_ATTRIBUTE(sl3516_ce_debugfs);
277-
#endif
278282

279283
static int sl3516_ce_register_algs(struct sl3516_ce_dev *ce)
280284
{
@@ -286,11 +290,11 @@ static int sl3516_ce_register_algs(struct sl3516_ce_dev *ce)
286290
switch (ce_algs[i].type) {
287291
case CRYPTO_ALG_TYPE_SKCIPHER:
288292
dev_info(ce->dev, "DEBUG: Register %s\n",
289-
ce_algs[i].alg.skcipher.base.cra_name);
290-
err = crypto_register_skcipher(&ce_algs[i].alg.skcipher);
293+
ce_algs[i].alg.skcipher.base.base.cra_name);
294+
err = crypto_engine_register_skcipher(&ce_algs[i].alg.skcipher);
291295
if (err) {
292296
dev_err(ce->dev, "Fail to register %s\n",
293-
ce_algs[i].alg.skcipher.base.cra_name);
297+
ce_algs[i].alg.skcipher.base.base.cra_name);
294298
ce_algs[i].ce = NULL;
295299
return err;
296300
}
@@ -313,8 +317,8 @@ static void sl3516_ce_unregister_algs(struct sl3516_ce_dev *ce)
313317
switch (ce_algs[i].type) {
314318
case CRYPTO_ALG_TYPE_SKCIPHER:
315319
dev_info(ce->dev, "Unregister %d %s\n", i,
316-
ce_algs[i].alg.skcipher.base.cra_name);
317-
crypto_unregister_skcipher(&ce_algs[i].alg.skcipher);
320+
ce_algs[i].alg.skcipher.base.base.cra_name);
321+
crypto_engine_unregister_skcipher(&ce_algs[i].alg.skcipher);
318322
break;
319323
}
320324
}
@@ -473,13 +477,20 @@ static int sl3516_ce_probe(struct platform_device *pdev)
473477

474478
pm_runtime_put_sync(ce->dev);
475479

480+
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SL3516_DEBUG)) {
481+
struct dentry *dbgfs_dir __maybe_unused;
482+
struct dentry *dbgfs_stats __maybe_unused;
483+
484+
/* Ignore error of debugfs */
485+
dbgfs_dir = debugfs_create_dir("sl3516", NULL);
486+
dbgfs_stats = debugfs_create_file("stats", 0444,
487+
dbgfs_dir, ce,
488+
&sl3516_ce_debugfs_fops);
476489
#ifdef CONFIG_CRYPTO_DEV_SL3516_DEBUG
477-
/* Ignore error of debugfs */
478-
ce->dbgfs_dir = debugfs_create_dir("sl3516", NULL);
479-
ce->dbgfs_stats = debugfs_create_file("stats", 0444,
480-
ce->dbgfs_dir, ce,
481-
&sl3516_ce_debugfs_fops);
490+
ce->dbgfs_dir = dbgfs_dir;
491+
ce->dbgfs_stats = dbgfs_stats;
482492
#endif
493+
}
483494

484495
return 0;
485496
error_pmuse:

drivers/crypto/gemini/sl3516-ce.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <crypto/engine.h>
1818
#include <crypto/scatterwalk.h>
1919
#include <crypto/skcipher.h>
20-
#include <linux/crypto.h>
2120
#include <linux/debugfs.h>
2221
#include <linux/hw_random.h>
2322

@@ -292,16 +291,12 @@ struct sl3516_ce_cipher_req_ctx {
292291

293292
/*
294293
* struct sl3516_ce_cipher_tfm_ctx - context for a skcipher TFM
295-
* @enginectx: crypto_engine used by this TFM
296294
* @key: pointer to key data
297295
* @keylen: len of the key
298296
* @ce: pointer to the private data of driver handling this TFM
299297
* @fallback_tfm: pointer to the fallback TFM
300-
*
301-
* enginectx must be the first element
302298
*/
303299
struct sl3516_ce_cipher_tfm_ctx {
304-
struct crypto_engine_ctx enginectx;
305300
u32 *key;
306301
u32 keylen;
307302
struct sl3516_ce_dev *ce;
@@ -324,7 +319,7 @@ struct sl3516_ce_alg_template {
324319
u32 mode;
325320
struct sl3516_ce_dev *ce;
326321
union {
327-
struct skcipher_alg skcipher;
322+
struct skcipher_engine_alg skcipher;
328323
} alg;
329324
unsigned long stat_req;
330325
unsigned long stat_fb;
@@ -345,3 +340,4 @@ int sl3516_ce_run_task(struct sl3516_ce_dev *ce,
345340

346341
int sl3516_ce_rng_register(struct sl3516_ce_dev *ce);
347342
void sl3516_ce_rng_unregister(struct sl3516_ce_dev *ce);
343+
int sl3516_ce_handle_cipher_request(struct crypto_engine *engine, void *areq);

0 commit comments

Comments
 (0)