Skip to content

Commit 980b570

Browse files
ardbiesheuvelherbertx
authored andcommitted
crypto: nx - Migrate to scomp API
The only remaining user of 842 compression has been migrated to the acomp compression API, and so the NX hardware driver has to follow suit, given that no users of the obsolete 'comp' API remain, and it is going to be removed. So migrate the NX driver code to scomp. These will be wrapped and exposed as acomp implementation via the crypto subsystem's acomp-to-scomp adaptation layer. Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent ddd0a42 commit 980b570

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

drivers/crypto/nx/nx-842.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ static int update_param(struct nx842_crypto_param *p,
101101
return 0;
102102
}
103103

104-
int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver)
104+
void *nx842_crypto_alloc_ctx(struct nx842_driver *driver)
105105
{
106-
struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
106+
struct nx842_crypto_ctx *ctx;
107+
108+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
109+
if (!ctx)
110+
return ERR_PTR(-ENOMEM);
107111

108112
spin_lock_init(&ctx->lock);
109113
ctx->driver = driver;
@@ -114,22 +118,23 @@ int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver)
114118
kfree(ctx->wmem);
115119
free_page((unsigned long)ctx->sbounce);
116120
free_page((unsigned long)ctx->dbounce);
117-
return -ENOMEM;
121+
kfree(ctx);
122+
return ERR_PTR(-ENOMEM);
118123
}
119124

120-
return 0;
125+
return ctx;
121126
}
122-
EXPORT_SYMBOL_GPL(nx842_crypto_init);
127+
EXPORT_SYMBOL_GPL(nx842_crypto_alloc_ctx);
123128

124-
void nx842_crypto_exit(struct crypto_tfm *tfm)
129+
void nx842_crypto_free_ctx(void *p)
125130
{
126-
struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
131+
struct nx842_crypto_ctx *ctx = p;
127132

128133
kfree(ctx->wmem);
129134
free_page((unsigned long)ctx->sbounce);
130135
free_page((unsigned long)ctx->dbounce);
131136
}
132-
EXPORT_SYMBOL_GPL(nx842_crypto_exit);
137+
EXPORT_SYMBOL_GPL(nx842_crypto_free_ctx);
133138

134139
static void check_constraints(struct nx842_constraints *c)
135140
{
@@ -246,11 +251,11 @@ static int compress(struct nx842_crypto_ctx *ctx,
246251
return update_param(p, slen, dskip + dlen);
247252
}
248253

249-
int nx842_crypto_compress(struct crypto_tfm *tfm,
254+
int nx842_crypto_compress(struct crypto_scomp *tfm,
250255
const u8 *src, unsigned int slen,
251-
u8 *dst, unsigned int *dlen)
256+
u8 *dst, unsigned int *dlen, void *pctx)
252257
{
253-
struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
258+
struct nx842_crypto_ctx *ctx = pctx;
254259
struct nx842_crypto_header *hdr =
255260
container_of(&ctx->header,
256261
struct nx842_crypto_header, hdr);
@@ -431,11 +436,11 @@ static int decompress(struct nx842_crypto_ctx *ctx,
431436
return update_param(p, slen + padding, dlen);
432437
}
433438

434-
int nx842_crypto_decompress(struct crypto_tfm *tfm,
439+
int nx842_crypto_decompress(struct crypto_scomp *tfm,
435440
const u8 *src, unsigned int slen,
436-
u8 *dst, unsigned int *dlen)
441+
u8 *dst, unsigned int *dlen, void *pctx)
437442
{
438-
struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
443+
struct nx842_crypto_ctx *ctx = pctx;
439444
struct nx842_crypto_header *hdr;
440445
struct nx842_crypto_param p;
441446
struct nx842_constraints c = *ctx->driver->constraints;

drivers/crypto/nx/nx-842.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#ifndef __NX_842_H__
44
#define __NX_842_H__
55

6-
#include <crypto/algapi.h>
76
#include <linux/kernel.h>
87
#include <linux/init.h>
98
#include <linux/module.h>
@@ -101,6 +100,8 @@
101100
#define LEN_ON_SIZE(pa, size) ((size) - ((pa) & ((size) - 1)))
102101
#define LEN_ON_PAGE(pa) LEN_ON_SIZE(pa, PAGE_SIZE)
103102

103+
struct crypto_scomp;
104+
104105
static inline unsigned long nx842_get_pa(void *addr)
105106
{
106107
if (!is_vmalloc_addr(addr))
@@ -182,13 +183,13 @@ struct nx842_crypto_ctx {
182183
struct nx842_driver *driver;
183184
};
184185

185-
int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver);
186-
void nx842_crypto_exit(struct crypto_tfm *tfm);
187-
int nx842_crypto_compress(struct crypto_tfm *tfm,
186+
void *nx842_crypto_alloc_ctx(struct nx842_driver *driver);
187+
void nx842_crypto_free_ctx(void *ctx);
188+
int nx842_crypto_compress(struct crypto_scomp *tfm,
188189
const u8 *src, unsigned int slen,
189-
u8 *dst, unsigned int *dlen);
190-
int nx842_crypto_decompress(struct crypto_tfm *tfm,
190+
u8 *dst, unsigned int *dlen, void *ctx);
191+
int nx842_crypto_decompress(struct crypto_scomp *tfm,
191192
const u8 *src, unsigned int slen,
192-
u8 *dst, unsigned int *dlen);
193+
u8 *dst, unsigned int *dlen, void *ctx);
193194

194195
#endif /* __NX_842_H__ */

drivers/crypto/nx/nx-common-powernv.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "nx-842.h"
1111

12+
#include <crypto/internal/scompress.h>
1213
#include <linux/timer.h>
1314

1415
#include <asm/prom.h>
@@ -1031,23 +1032,21 @@ static struct nx842_driver nx842_powernv_driver = {
10311032
.decompress = nx842_powernv_decompress,
10321033
};
10331034

1034-
static int nx842_powernv_crypto_init(struct crypto_tfm *tfm)
1035+
static void *nx842_powernv_crypto_alloc_ctx(void)
10351036
{
1036-
return nx842_crypto_init(tfm, &nx842_powernv_driver);
1037+
return nx842_crypto_alloc_ctx(&nx842_powernv_driver);
10371038
}
10381039

1039-
static struct crypto_alg nx842_powernv_alg = {
1040-
.cra_name = "842",
1041-
.cra_driver_name = "842-nx",
1042-
.cra_priority = 300,
1043-
.cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
1044-
.cra_ctxsize = sizeof(struct nx842_crypto_ctx),
1045-
.cra_module = THIS_MODULE,
1046-
.cra_init = nx842_powernv_crypto_init,
1047-
.cra_exit = nx842_crypto_exit,
1048-
.cra_u = { .compress = {
1049-
.coa_compress = nx842_crypto_compress,
1050-
.coa_decompress = nx842_crypto_decompress } }
1040+
static struct scomp_alg nx842_powernv_alg = {
1041+
.base.cra_name = "842",
1042+
.base.cra_driver_name = "842-nx",
1043+
.base.cra_priority = 300,
1044+
.base.cra_module = THIS_MODULE,
1045+
1046+
.alloc_ctx = nx842_powernv_crypto_alloc_ctx,
1047+
.free_ctx = nx842_crypto_free_ctx,
1048+
.compress = nx842_crypto_compress,
1049+
.decompress = nx842_crypto_decompress,
10511050
};
10521051

10531052
static __init int nx_compress_powernv_init(void)
@@ -1107,7 +1106,7 @@ static __init int nx_compress_powernv_init(void)
11071106
nx842_powernv_exec = nx842_exec_vas;
11081107
}
11091108

1110-
ret = crypto_register_alg(&nx842_powernv_alg);
1109+
ret = crypto_register_scomp(&nx842_powernv_alg);
11111110
if (ret) {
11121111
nx_delete_coprocs();
11131112
return ret;
@@ -1128,7 +1127,7 @@ static void __exit nx_compress_powernv_exit(void)
11281127
if (!nx842_ct)
11291128
vas_unregister_api_powernv();
11301129

1131-
crypto_unregister_alg(&nx842_powernv_alg);
1130+
crypto_unregister_scomp(&nx842_powernv_alg);
11321131

11331132
nx_delete_coprocs();
11341133
}

drivers/crypto/nx/nx-common-pseries.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/vio.h>
1212
#include <asm/hvcall.h>
1313
#include <asm/vas.h>
14+
#include <crypto/internal/scompress.h>
1415

1516
#include "nx-842.h"
1617
#include "nx_csbcpb.h" /* struct nx_csbcpb */
@@ -1008,23 +1009,21 @@ static struct nx842_driver nx842_pseries_driver = {
10081009
.decompress = nx842_pseries_decompress,
10091010
};
10101011

1011-
static int nx842_pseries_crypto_init(struct crypto_tfm *tfm)
1012+
static void *nx842_pseries_crypto_alloc_ctx(void)
10121013
{
1013-
return nx842_crypto_init(tfm, &nx842_pseries_driver);
1014+
return nx842_crypto_alloc_ctx(&nx842_pseries_driver);
10141015
}
10151016

1016-
static struct crypto_alg nx842_pseries_alg = {
1017-
.cra_name = "842",
1018-
.cra_driver_name = "842-nx",
1019-
.cra_priority = 300,
1020-
.cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
1021-
.cra_ctxsize = sizeof(struct nx842_crypto_ctx),
1022-
.cra_module = THIS_MODULE,
1023-
.cra_init = nx842_pseries_crypto_init,
1024-
.cra_exit = nx842_crypto_exit,
1025-
.cra_u = { .compress = {
1026-
.coa_compress = nx842_crypto_compress,
1027-
.coa_decompress = nx842_crypto_decompress } }
1017+
static struct scomp_alg nx842_pseries_alg = {
1018+
.base.cra_name = "842",
1019+
.base.cra_driver_name = "842-nx",
1020+
.base.cra_priority = 300,
1021+
.base.cra_module = THIS_MODULE,
1022+
1023+
.alloc_ctx = nx842_pseries_crypto_alloc_ctx,
1024+
.free_ctx = nx842_crypto_free_ctx,
1025+
.compress = nx842_crypto_compress,
1026+
.decompress = nx842_crypto_decompress,
10281027
};
10291028

10301029
static int nx842_probe(struct vio_dev *viodev,
@@ -1072,7 +1071,7 @@ static int nx842_probe(struct vio_dev *viodev,
10721071
if (ret)
10731072
goto error;
10741073

1075-
ret = crypto_register_alg(&nx842_pseries_alg);
1074+
ret = crypto_register_scomp(&nx842_pseries_alg);
10761075
if (ret) {
10771076
dev_err(&viodev->dev, "could not register comp alg: %d\n", ret);
10781077
goto error;
@@ -1120,7 +1119,7 @@ static void nx842_remove(struct vio_dev *viodev)
11201119
if (caps_feat)
11211120
sysfs_remove_group(&viodev->dev.kobj, &nxcop_caps_attr_group);
11221121

1123-
crypto_unregister_alg(&nx842_pseries_alg);
1122+
crypto_unregister_scomp(&nx842_pseries_alg);
11241123

11251124
of_reconfig_notifier_unregister(&nx842_of_nb);
11261125

@@ -1253,7 +1252,7 @@ static void __exit nx842_pseries_exit(void)
12531252

12541253
vas_unregister_api_pseries();
12551254

1256-
crypto_unregister_alg(&nx842_pseries_alg);
1255+
crypto_unregister_scomp(&nx842_pseries_alg);
12571256

12581257
spin_lock_irqsave(&devdata_spinlock, flags);
12591258
old_devdata = rcu_dereference_check(devdata,

0 commit comments

Comments
 (0)