Skip to content

Commit 982213e

Browse files
committed
crypto: jh7110 - 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 <[email protected]>
1 parent 1a15d26 commit 982213e

File tree

4 files changed

+252
-205
lines changed

4 files changed

+252
-205
lines changed

drivers/crypto/starfive/jh7110-aes.c

Lines changed: 93 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
* Copyright (c) 2022 StarFive Technology
66
*/
77

8-
#include <linux/iopoll.h>
8+
#include <crypto/engine.h>
99
#include <crypto/gcm.h>
10-
#include <crypto/scatterwalk.h>
1110
#include <crypto/internal/aead.h>
1211
#include <crypto/internal/skcipher.h>
12+
#include <crypto/scatterwalk.h>
1313
#include "jh7110-cryp.h"
14+
#include <linux/err.h>
15+
#include <linux/iopoll.h>
16+
#include <linux/kernel.h>
17+
#include <linux/slab.h>
18+
#include <linux/string.h>
1419

1520
#define STARFIVE_AES_REGS_OFFSET 0x100
1621
#define STARFIVE_AES_AESDIO0R (STARFIVE_AES_REGS_OFFSET + 0x0)
@@ -554,8 +559,6 @@ static int starfive_aes_init_tfm(struct crypto_skcipher *tfm)
554559
crypto_skcipher_set_reqsize(tfm, sizeof(struct starfive_cryp_request_ctx) +
555560
sizeof(struct skcipher_request));
556561

557-
ctx->enginectx.op.do_one_request = starfive_aes_do_one_req;
558-
559562
return 0;
560563
}
561564

@@ -638,8 +641,6 @@ static int starfive_aes_aead_init_tfm(struct crypto_aead *tfm)
638641
crypto_aead_set_reqsize(tfm, sizeof(struct starfive_cryp_ctx) +
639642
sizeof(struct aead_request));
640643

641-
ctx->enginectx.op.do_one_request = starfive_aes_aead_do_one_req;
642-
643644
return 0;
644645
}
645646

@@ -844,15 +845,15 @@ static int starfive_aes_ccm_decrypt(struct aead_request *req)
844845
return starfive_aes_aead_crypt(req, STARFIVE_AES_MODE_CCM);
845846
}
846847

847-
static struct skcipher_alg skcipher_algs[] = {
848+
static struct skcipher_engine_alg skcipher_algs[] = {
848849
{
849-
.init = starfive_aes_init_tfm,
850-
.setkey = starfive_aes_setkey,
851-
.encrypt = starfive_aes_ecb_encrypt,
852-
.decrypt = starfive_aes_ecb_decrypt,
853-
.min_keysize = AES_MIN_KEY_SIZE,
854-
.max_keysize = AES_MAX_KEY_SIZE,
855-
.base = {
850+
.base.init = starfive_aes_init_tfm,
851+
.base.setkey = starfive_aes_setkey,
852+
.base.encrypt = starfive_aes_ecb_encrypt,
853+
.base.decrypt = starfive_aes_ecb_decrypt,
854+
.base.min_keysize = AES_MIN_KEY_SIZE,
855+
.base.max_keysize = AES_MAX_KEY_SIZE,
856+
.base.base = {
856857
.cra_name = "ecb(aes)",
857858
.cra_driver_name = "starfive-ecb-aes",
858859
.cra_priority = 200,
@@ -862,15 +863,18 @@ static struct skcipher_alg skcipher_algs[] = {
862863
.cra_alignmask = 0xf,
863864
.cra_module = THIS_MODULE,
864865
},
866+
.op = {
867+
.do_one_request = starfive_aes_do_one_req,
868+
},
865869
}, {
866-
.init = starfive_aes_init_tfm,
867-
.setkey = starfive_aes_setkey,
868-
.encrypt = starfive_aes_cbc_encrypt,
869-
.decrypt = starfive_aes_cbc_decrypt,
870-
.min_keysize = AES_MIN_KEY_SIZE,
871-
.max_keysize = AES_MAX_KEY_SIZE,
872-
.ivsize = AES_BLOCK_SIZE,
873-
.base = {
870+
.base.init = starfive_aes_init_tfm,
871+
.base.setkey = starfive_aes_setkey,
872+
.base.encrypt = starfive_aes_cbc_encrypt,
873+
.base.decrypt = starfive_aes_cbc_decrypt,
874+
.base.min_keysize = AES_MIN_KEY_SIZE,
875+
.base.max_keysize = AES_MAX_KEY_SIZE,
876+
.base.ivsize = AES_BLOCK_SIZE,
877+
.base.base = {
874878
.cra_name = "cbc(aes)",
875879
.cra_driver_name = "starfive-cbc-aes",
876880
.cra_priority = 200,
@@ -880,15 +884,18 @@ static struct skcipher_alg skcipher_algs[] = {
880884
.cra_alignmask = 0xf,
881885
.cra_module = THIS_MODULE,
882886
},
887+
.op = {
888+
.do_one_request = starfive_aes_do_one_req,
889+
},
883890
}, {
884-
.init = starfive_aes_init_tfm,
885-
.setkey = starfive_aes_setkey,
886-
.encrypt = starfive_aes_ctr_encrypt,
887-
.decrypt = starfive_aes_ctr_decrypt,
888-
.min_keysize = AES_MIN_KEY_SIZE,
889-
.max_keysize = AES_MAX_KEY_SIZE,
890-
.ivsize = AES_BLOCK_SIZE,
891-
.base = {
891+
.base.init = starfive_aes_init_tfm,
892+
.base.setkey = starfive_aes_setkey,
893+
.base.encrypt = starfive_aes_ctr_encrypt,
894+
.base.decrypt = starfive_aes_ctr_decrypt,
895+
.base.min_keysize = AES_MIN_KEY_SIZE,
896+
.base.max_keysize = AES_MAX_KEY_SIZE,
897+
.base.ivsize = AES_BLOCK_SIZE,
898+
.base.base = {
892899
.cra_name = "ctr(aes)",
893900
.cra_driver_name = "starfive-ctr-aes",
894901
.cra_priority = 200,
@@ -898,15 +905,18 @@ static struct skcipher_alg skcipher_algs[] = {
898905
.cra_alignmask = 0xf,
899906
.cra_module = THIS_MODULE,
900907
},
908+
.op = {
909+
.do_one_request = starfive_aes_do_one_req,
910+
},
901911
}, {
902-
.init = starfive_aes_init_tfm,
903-
.setkey = starfive_aes_setkey,
904-
.encrypt = starfive_aes_cfb_encrypt,
905-
.decrypt = starfive_aes_cfb_decrypt,
906-
.min_keysize = AES_MIN_KEY_SIZE,
907-
.max_keysize = AES_MAX_KEY_SIZE,
908-
.ivsize = AES_BLOCK_SIZE,
909-
.base = {
912+
.base.init = starfive_aes_init_tfm,
913+
.base.setkey = starfive_aes_setkey,
914+
.base.encrypt = starfive_aes_cfb_encrypt,
915+
.base.decrypt = starfive_aes_cfb_decrypt,
916+
.base.min_keysize = AES_MIN_KEY_SIZE,
917+
.base.max_keysize = AES_MAX_KEY_SIZE,
918+
.base.ivsize = AES_BLOCK_SIZE,
919+
.base.base = {
910920
.cra_name = "cfb(aes)",
911921
.cra_driver_name = "starfive-cfb-aes",
912922
.cra_priority = 200,
@@ -916,15 +926,18 @@ static struct skcipher_alg skcipher_algs[] = {
916926
.cra_alignmask = 0xf,
917927
.cra_module = THIS_MODULE,
918928
},
929+
.op = {
930+
.do_one_request = starfive_aes_do_one_req,
931+
},
919932
}, {
920-
.init = starfive_aes_init_tfm,
921-
.setkey = starfive_aes_setkey,
922-
.encrypt = starfive_aes_ofb_encrypt,
923-
.decrypt = starfive_aes_ofb_decrypt,
924-
.min_keysize = AES_MIN_KEY_SIZE,
925-
.max_keysize = AES_MAX_KEY_SIZE,
926-
.ivsize = AES_BLOCK_SIZE,
927-
.base = {
933+
.base.init = starfive_aes_init_tfm,
934+
.base.setkey = starfive_aes_setkey,
935+
.base.encrypt = starfive_aes_ofb_encrypt,
936+
.base.decrypt = starfive_aes_ofb_decrypt,
937+
.base.min_keysize = AES_MIN_KEY_SIZE,
938+
.base.max_keysize = AES_MAX_KEY_SIZE,
939+
.base.ivsize = AES_BLOCK_SIZE,
940+
.base.base = {
928941
.cra_name = "ofb(aes)",
929942
.cra_driver_name = "starfive-ofb-aes",
930943
.cra_priority = 200,
@@ -934,20 +947,23 @@ static struct skcipher_alg skcipher_algs[] = {
934947
.cra_alignmask = 0xf,
935948
.cra_module = THIS_MODULE,
936949
},
950+
.op = {
951+
.do_one_request = starfive_aes_do_one_req,
952+
},
937953
},
938954
};
939955

940-
static struct aead_alg aead_algs[] = {
941-
{
942-
.setkey = starfive_aes_aead_setkey,
943-
.setauthsize = starfive_aes_gcm_setauthsize,
944-
.encrypt = starfive_aes_gcm_encrypt,
945-
.decrypt = starfive_aes_gcm_decrypt,
946-
.init = starfive_aes_aead_init_tfm,
947-
.exit = starfive_aes_aead_exit_tfm,
948-
.ivsize = GCM_AES_IV_SIZE,
949-
.maxauthsize = AES_BLOCK_SIZE,
950-
.base = {
956+
static struct aead_engine_alg aead_algs[] = {
957+
{
958+
.base.setkey = starfive_aes_aead_setkey,
959+
.base.setauthsize = starfive_aes_gcm_setauthsize,
960+
.base.encrypt = starfive_aes_gcm_encrypt,
961+
.base.decrypt = starfive_aes_gcm_decrypt,
962+
.base.init = starfive_aes_aead_init_tfm,
963+
.base.exit = starfive_aes_aead_exit_tfm,
964+
.base.ivsize = GCM_AES_IV_SIZE,
965+
.base.maxauthsize = AES_BLOCK_SIZE,
966+
.base.base = {
951967
.cra_name = "gcm(aes)",
952968
.cra_driver_name = "starfive-gcm-aes",
953969
.cra_priority = 200,
@@ -957,16 +973,19 @@ static struct aead_alg aead_algs[] = {
957973
.cra_alignmask = 0xf,
958974
.cra_module = THIS_MODULE,
959975
},
976+
.op = {
977+
.do_one_request = starfive_aes_aead_do_one_req,
978+
},
960979
}, {
961-
.setkey = starfive_aes_aead_setkey,
962-
.setauthsize = starfive_aes_ccm_setauthsize,
963-
.encrypt = starfive_aes_ccm_encrypt,
964-
.decrypt = starfive_aes_ccm_decrypt,
965-
.init = starfive_aes_aead_init_tfm,
966-
.exit = starfive_aes_aead_exit_tfm,
967-
.ivsize = AES_BLOCK_SIZE,
968-
.maxauthsize = AES_BLOCK_SIZE,
969-
.base = {
980+
.base.setkey = starfive_aes_aead_setkey,
981+
.base.setauthsize = starfive_aes_ccm_setauthsize,
982+
.base.encrypt = starfive_aes_ccm_encrypt,
983+
.base.decrypt = starfive_aes_ccm_decrypt,
984+
.base.init = starfive_aes_aead_init_tfm,
985+
.base.exit = starfive_aes_aead_exit_tfm,
986+
.base.ivsize = AES_BLOCK_SIZE,
987+
.base.maxauthsize = AES_BLOCK_SIZE,
988+
.base.base = {
970989
.cra_name = "ccm(aes)",
971990
.cra_driver_name = "starfive-ccm-aes",
972991
.cra_priority = 200,
@@ -977,26 +996,29 @@ static struct aead_alg aead_algs[] = {
977996
.cra_alignmask = 0xf,
978997
.cra_module = THIS_MODULE,
979998
},
999+
.op = {
1000+
.do_one_request = starfive_aes_aead_do_one_req,
1001+
},
9801002
},
9811003
};
9821004

9831005
int starfive_aes_register_algs(void)
9841006
{
9851007
int ret;
9861008

987-
ret = crypto_register_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
1009+
ret = crypto_engine_register_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
9881010
if (ret)
9891011
return ret;
9901012

991-
ret = crypto_register_aeads(aead_algs, ARRAY_SIZE(aead_algs));
1013+
ret = crypto_engine_register_aeads(aead_algs, ARRAY_SIZE(aead_algs));
9921014
if (ret)
993-
crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
1015+
crypto_engine_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
9941016

9951017
return ret;
9961018
}
9971019

9981020
void starfive_aes_unregister_algs(void)
9991021
{
1000-
crypto_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs));
1001-
crypto_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
1022+
crypto_engine_unregister_aeads(aead_algs, ARRAY_SIZE(aead_algs));
1023+
crypto_engine_unregister_skciphers(skcipher_algs, ARRAY_SIZE(skcipher_algs));
10021024
}

drivers/crypto/starfive/jh7110-cryp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
*
88
*/
99

10+
#include <crypto/engine.h>
11+
#include "jh7110-cryp.h"
1012
#include <linux/clk.h>
11-
#include <linux/delay.h>
13+
#include <linux/completion.h>
14+
#include <linux/err.h>
1215
#include <linux/interrupt.h>
1316
#include <linux/iopoll.h>
17+
#include <linux/kernel.h>
1418
#include <linux/module.h>
1519
#include <linux/of_device.h>
1620
#include <linux/platform_device.h>
1721
#include <linux/pm_runtime.h>
1822
#include <linux/reset.h>
19-
20-
#include "jh7110-cryp.h"
23+
#include <linux/spinlock.h>
2124

2225
#define DRIVER_NAME "jh7110-crypto"
2326

drivers/crypto/starfive/jh7110-cryp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#define __STARFIVE_STR_H__
44

55
#include <crypto/aes.h>
6-
#include <crypto/engine.h>
76
#include <crypto/hash.h>
87
#include <crypto/scatterwalk.h>
98
#include <crypto/sha2.h>
@@ -151,7 +150,6 @@ union starfive_alg_cr {
151150
};
152151

153152
struct starfive_cryp_ctx {
154-
struct crypto_engine_ctx enginectx;
155153
struct starfive_cryp_dev *cryp;
156154
struct starfive_cryp_request_ctx *rctx;
157155

0 commit comments

Comments
 (0)