aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-07-22 14:26:38 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-07-23 06:14:33 -0400
commit03952d98015326a07ae1cf7adb4c43265ec4058f (patch)
tree43a084753bc291c1bde18d02de4ce5557691d832
parent174d66d4725879b80f8af0bda2b218c2892a9ddb (diff)
crypto: nx - make platform drivers directly register with crypto
Remove the common 'platform' registration module, and move the crypto compression driver registration into each of the pSeries and PowerNV platform NX 842 drivers. Change the nx-842.c code into simple common functions that each platform driver uses to perform constraints-based buffer changes, i.e. realigning and/or resizing buffers to match the driver's hardware requirements. The common 'platform' module was my mistake to create - since each platform driver will only load/operate when running on its own platform (i.e. a pSeries platform or a PowerNV platform), they can directly register with the crypto subsystem, using the same alg and driver name. This removes unneeded complexity. Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/nx/Makefile6
-rw-r--r--drivers/crypto/nx/nx-842-platform.c84
-rw-r--r--drivers/crypto/nx/nx-842-powernv.c29
-rw-r--r--drivers/crypto/nx/nx-842-pseries.c38
-rw-r--r--drivers/crypto/nx/nx-842.c105
-rw-r--r--drivers/crypto/nx/nx-842.h43
6 files changed, 114 insertions, 191 deletions
diff --git a/drivers/crypto/nx/Makefile b/drivers/crypto/nx/Makefile
index ffcc86c44e15..b727821c8ed4 100644
--- a/drivers/crypto/nx/Makefile
+++ b/drivers/crypto/nx/Makefile
@@ -10,10 +10,8 @@ nx-crypto-objs := nx.o \
10 nx-sha256.o \ 10 nx-sha256.o \
11 nx-sha512.o 11 nx-sha512.o
12 12
13obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS) += nx-compress.o nx-compress-platform.o 13obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o nx-compress.o
14obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o 14obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o nx-compress.o
15obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o
16nx-compress-objs := nx-842.o 15nx-compress-objs := nx-842.o
17nx-compress-platform-objs := nx-842-platform.o
18nx-compress-pseries-objs := nx-842-pseries.o 16nx-compress-pseries-objs := nx-842-pseries.o
19nx-compress-powernv-objs := nx-842-powernv.o 17nx-compress-powernv-objs := nx-842-powernv.o
diff --git a/drivers/crypto/nx/nx-842-platform.c b/drivers/crypto/nx/nx-842-platform.c
deleted file mode 100644
index 664f13dd06ed..000000000000
--- a/drivers/crypto/nx/nx-842-platform.c
+++ /dev/null
@@ -1,84 +0,0 @@
1
2#include "nx-842.h"
3
4/* this is needed, separate from the main nx-842.c driver, because that main
5 * driver loads the platform drivers during its init(), and it expects one
6 * (or none) of the platform drivers to set this pointer to its driver.
7 * That means this pointer can't be in the main nx-842 driver, because it
8 * wouldn't be accessible until after the main driver loaded, which wouldn't
9 * be possible as it's waiting for the platform driver to load. So place it
10 * here.
11 */
12static struct nx842_driver *driver;
13static DEFINE_SPINLOCK(driver_lock);
14
15struct nx842_driver *nx842_platform_driver(void)
16{
17 return driver;
18}
19EXPORT_SYMBOL_GPL(nx842_platform_driver);
20
21bool nx842_platform_driver_set(struct nx842_driver *_driver)
22{
23 bool ret = false;
24
25 spin_lock(&driver_lock);
26
27 if (!driver) {
28 driver = _driver;
29 ret = true;
30 } else
31 WARN(1, "can't set platform driver, already set to %s\n",
32 driver->name);
33
34 spin_unlock(&driver_lock);
35 return ret;
36}
37EXPORT_SYMBOL_GPL(nx842_platform_driver_set);
38
39/* only call this from the platform driver exit function */
40void nx842_platform_driver_unset(struct nx842_driver *_driver)
41{
42 spin_lock(&driver_lock);
43
44 if (driver == _driver)
45 driver = NULL;
46 else if (driver)
47 WARN(1, "can't unset platform driver %s, currently set to %s\n",
48 _driver->name, driver->name);
49 else
50 WARN(1, "can't unset platform driver, already unset\n");
51
52 spin_unlock(&driver_lock);
53}
54EXPORT_SYMBOL_GPL(nx842_platform_driver_unset);
55
56bool nx842_platform_driver_get(void)
57{
58 bool ret = false;
59
60 spin_lock(&driver_lock);
61
62 if (driver)
63 ret = try_module_get(driver->owner);
64
65 spin_unlock(&driver_lock);
66
67 return ret;
68}
69EXPORT_SYMBOL_GPL(nx842_platform_driver_get);
70
71void nx842_platform_driver_put(void)
72{
73 spin_lock(&driver_lock);
74
75 if (driver)
76 module_put(driver->owner);
77
78 spin_unlock(&driver_lock);
79}
80EXPORT_SYMBOL_GPL(nx842_platform_driver_put);
81
82MODULE_LICENSE("GPL");
83MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
84MODULE_DESCRIPTION("842 H/W Compression platform driver");
diff --git a/drivers/crypto/nx/nx-842-powernv.c b/drivers/crypto/nx/nx-842-powernv.c
index 7e474562058d..684ce51d2d68 100644
--- a/drivers/crypto/nx/nx-842-powernv.c
+++ b/drivers/crypto/nx/nx-842-powernv.c
@@ -26,6 +26,8 @@
26MODULE_LICENSE("GPL"); 26MODULE_LICENSE("GPL");
27MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); 27MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
28MODULE_DESCRIPTION("842 H/W Compression driver for IBM PowerNV processors"); 28MODULE_DESCRIPTION("842 H/W Compression driver for IBM PowerNV processors");
29MODULE_ALIAS_CRYPTO("842");
30MODULE_ALIAS_CRYPTO("842-nx");
29 31
30#define WORKMEM_ALIGN (CRB_ALIGN) 32#define WORKMEM_ALIGN (CRB_ALIGN)
31#define CSB_WAIT_MAX (5000) /* ms */ 33#define CSB_WAIT_MAX (5000) /* ms */
@@ -581,9 +583,29 @@ static struct nx842_driver nx842_powernv_driver = {
581 .decompress = nx842_powernv_decompress, 583 .decompress = nx842_powernv_decompress,
582}; 584};
583 585
586static int nx842_powernv_crypto_init(struct crypto_tfm *tfm)
587{
588 return nx842_crypto_init(tfm, &nx842_powernv_driver);
589}
590
591static struct crypto_alg nx842_powernv_alg = {
592 .cra_name = "842",
593 .cra_driver_name = "842-nx",
594 .cra_priority = 300,
595 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
596 .cra_ctxsize = sizeof(struct nx842_crypto_ctx),
597 .cra_module = THIS_MODULE,
598 .cra_init = nx842_powernv_crypto_init,
599 .cra_exit = nx842_crypto_exit,
600 .cra_u = { .compress = {
601 .coa_compress = nx842_crypto_compress,
602 .coa_decompress = nx842_crypto_decompress } }
603};
604
584static __init int nx842_powernv_init(void) 605static __init int nx842_powernv_init(void)
585{ 606{
586 struct device_node *dn; 607 struct device_node *dn;
608 int ret;
587 609
588 /* verify workmem size/align restrictions */ 610 /* verify workmem size/align restrictions */
589 BUILD_BUG_ON(WORKMEM_ALIGN % CRB_ALIGN); 611 BUILD_BUG_ON(WORKMEM_ALIGN % CRB_ALIGN);
@@ -600,7 +622,8 @@ static __init int nx842_powernv_init(void)
600 if (!nx842_ct) 622 if (!nx842_ct)
601 return -ENODEV; 623 return -ENODEV;
602 624
603 if (!nx842_platform_driver_set(&nx842_powernv_driver)) { 625 ret = crypto_register_alg(&nx842_powernv_alg);
626 if (ret) {
604 struct nx842_coproc *coproc, *n; 627 struct nx842_coproc *coproc, *n;
605 628
606 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) { 629 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
@@ -608,7 +631,7 @@ static __init int nx842_powernv_init(void)
608 kfree(coproc); 631 kfree(coproc);
609 } 632 }
610 633
611 return -EEXIST; 634 return ret;
612 } 635 }
613 636
614 return 0; 637 return 0;
@@ -619,7 +642,7 @@ static void __exit nx842_powernv_exit(void)
619{ 642{
620 struct nx842_coproc *coproc, *n; 643 struct nx842_coproc *coproc, *n;
621 644
622 nx842_platform_driver_unset(&nx842_powernv_driver); 645 crypto_unregister_alg(&nx842_powernv_alg);
623 646
624 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) { 647 list_for_each_entry_safe(coproc, n, &nx842_coprocs, list) {
625 list_del(&coproc->list); 648 list_del(&coproc->list);
diff --git a/drivers/crypto/nx/nx-842-pseries.c b/drivers/crypto/nx/nx-842-pseries.c
index 4b7bd8fb6a6b..b6a26907e11f 100644
--- a/drivers/crypto/nx/nx-842-pseries.c
+++ b/drivers/crypto/nx/nx-842-pseries.c
@@ -29,6 +29,8 @@
29MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
30MODULE_AUTHOR("Robert Jennings <rcj@linux.vnet.ibm.com>"); 30MODULE_AUTHOR("Robert Jennings <rcj@linux.vnet.ibm.com>");
31MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors"); 31MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors");
32MODULE_ALIAS_CRYPTO("842");
33MODULE_ALIAS_CRYPTO("842-nx");
32 34
33static struct nx842_constraints nx842_pseries_constraints = { 35static struct nx842_constraints nx842_pseries_constraints = {
34 .alignment = DDE_BUFFER_ALIGN, 36 .alignment = DDE_BUFFER_ALIGN,
@@ -957,6 +959,25 @@ static struct nx842_driver nx842_pseries_driver = {
957 .decompress = nx842_pseries_decompress, 959 .decompress = nx842_pseries_decompress,
958}; 960};
959 961
962static int nx842_pseries_crypto_init(struct crypto_tfm *tfm)
963{
964 return nx842_crypto_init(tfm, &nx842_pseries_driver);
965}
966
967static struct crypto_alg nx842_pseries_alg = {
968 .cra_name = "842",
969 .cra_driver_name = "842-nx",
970 .cra_priority = 300,
971 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
972 .cra_ctxsize = sizeof(struct nx842_crypto_ctx),
973 .cra_module = THIS_MODULE,
974 .cra_init = nx842_pseries_crypto_init,
975 .cra_exit = nx842_crypto_exit,
976 .cra_u = { .compress = {
977 .coa_compress = nx842_crypto_compress,
978 .coa_decompress = nx842_crypto_decompress } }
979};
980
960static int nx842_probe(struct vio_dev *viodev, 981static int nx842_probe(struct vio_dev *viodev,
961 const struct vio_device_id *id) 982 const struct vio_device_id *id)
962{ 983{
@@ -1002,6 +1023,12 @@ static int nx842_probe(struct vio_dev *viodev,
1002 if (ret) 1023 if (ret)
1003 goto error; 1024 goto error;
1004 1025
1026 ret = crypto_register_alg(&nx842_pseries_alg);
1027 if (ret) {
1028 dev_err(&viodev->dev, "could not register comp alg: %d\n", ret);
1029 goto error;
1030 }
1031
1005 rcu_read_lock(); 1032 rcu_read_lock();
1006 dev_set_drvdata(&viodev->dev, rcu_dereference(devdata)); 1033 dev_set_drvdata(&viodev->dev, rcu_dereference(devdata));
1007 rcu_read_unlock(); 1034 rcu_read_unlock();
@@ -1031,6 +1058,8 @@ static int nx842_remove(struct vio_dev *viodev)
1031 pr_info("Removing IBM Power 842 compression device\n"); 1058 pr_info("Removing IBM Power 842 compression device\n");
1032 sysfs_remove_group(&viodev->dev.kobj, &nx842_attribute_group); 1059 sysfs_remove_group(&viodev->dev.kobj, &nx842_attribute_group);
1033 1060
1061 crypto_unregister_alg(&nx842_pseries_alg);
1062
1034 spin_lock_irqsave(&devdata_mutex, flags); 1063 spin_lock_irqsave(&devdata_mutex, flags);
1035 old_devdata = rcu_dereference_check(devdata, 1064 old_devdata = rcu_dereference_check(devdata,
1036 lockdep_is_held(&devdata_mutex)); 1065 lockdep_is_held(&devdata_mutex));
@@ -1083,12 +1112,6 @@ static int __init nx842_pseries_init(void)
1083 return ret; 1112 return ret;
1084 } 1113 }
1085 1114
1086 if (!nx842_platform_driver_set(&nx842_pseries_driver)) {
1087 vio_unregister_driver(&nx842_vio_driver);
1088 kfree(new_devdata);
1089 return -EEXIST;
1090 }
1091
1092 return 0; 1115 return 0;
1093} 1116}
1094 1117
@@ -1099,7 +1122,8 @@ static void __exit nx842_pseries_exit(void)
1099 struct nx842_devdata *old_devdata; 1122 struct nx842_devdata *old_devdata;
1100 unsigned long flags; 1123 unsigned long flags;
1101 1124
1102 nx842_platform_driver_unset(&nx842_pseries_driver); 1125 crypto_unregister_alg(&nx842_pseries_alg);
1126
1103 spin_lock_irqsave(&devdata_mutex, flags); 1127 spin_lock_irqsave(&devdata_mutex, flags);
1104 old_devdata = rcu_dereference_check(devdata, 1128 old_devdata = rcu_dereference_check(devdata,
1105 lockdep_is_held(&devdata_mutex)); 1129 lockdep_is_held(&devdata_mutex));
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index 4472e2001e79..046c1c45411b 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -57,12 +57,8 @@
57 57
58#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 58#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
59 59
60#include <linux/init.h>
61#include <linux/module.h>
62#include <linux/crypto.h>
63#include <linux/vmalloc.h> 60#include <linux/vmalloc.h>
64#include <linux/sw842.h> 61#include <linux/sw842.h>
65#include <linux/ratelimit.h>
66#include <linux/spinlock.h> 62#include <linux/spinlock.h>
67 63
68#include "nx-842.h" 64#include "nx-842.h"
@@ -74,7 +70,6 @@
74 * buffer, and passed directly to the hardware to decompress. 70 * buffer, and passed directly to the hardware to decompress.
75 */ 71 */
76#define NX842_CRYPTO_MAGIC (0xf842) 72#define NX842_CRYPTO_MAGIC (0xf842)
77#define NX842_CRYPTO_GROUP_MAX (0x20)
78#define NX842_CRYPTO_HEADER_SIZE(g) \ 73#define NX842_CRYPTO_HEADER_SIZE(g) \
79 (sizeof(struct nx842_crypto_header) + \ 74 (sizeof(struct nx842_crypto_header) + \
80 sizeof(struct nx842_crypto_header_group) * (g)) 75 sizeof(struct nx842_crypto_header_group) * (g))
@@ -90,19 +85,6 @@
90#define COMP_BUSY_TIMEOUT (250) /* ms */ 85#define COMP_BUSY_TIMEOUT (250) /* ms */
91#define DECOMP_BUSY_TIMEOUT (50) /* ms */ 86#define DECOMP_BUSY_TIMEOUT (50) /* ms */
92 87
93struct nx842_crypto_header_group {
94 __be16 padding; /* unused bytes at start of group */
95 __be32 compressed_length; /* compressed bytes in group */
96 __be32 uncompressed_length; /* bytes after decompression */
97} __packed;
98
99struct nx842_crypto_header {
100 __be16 magic; /* NX842_CRYPTO_MAGIC */
101 __be16 ignore; /* decompressed end bytes to ignore */
102 u8 groups; /* total groups in this header */
103 struct nx842_crypto_header_group group[];
104} __packed;
105
106struct nx842_crypto_param { 88struct nx842_crypto_param {
107 u8 *in; 89 u8 *in;
108 unsigned int iremain; 90 unsigned int iremain;
@@ -128,22 +110,13 @@ static int update_param(struct nx842_crypto_param *p,
128 return 0; 110 return 0;
129} 111}
130 112
131struct nx842_crypto_ctx { 113int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver)
132 spinlock_t lock;
133
134 u8 *wmem;
135 u8 *sbounce, *dbounce;
136
137 struct nx842_crypto_header header;
138 struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
139};
140
141static int nx842_crypto_init(struct crypto_tfm *tfm)
142{ 114{
143 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 115 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
144 116
145 spin_lock_init(&ctx->lock); 117 spin_lock_init(&ctx->lock);
146 ctx->wmem = kmalloc(nx842_workmem_size(), GFP_KERNEL); 118 ctx->driver = driver;
119 ctx->wmem = kmalloc(driver->workmem_size, GFP_KERNEL);
147 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 120 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
148 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 121 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
149 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { 122 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {
@@ -155,8 +128,9 @@ static int nx842_crypto_init(struct crypto_tfm *tfm)
155 128
156 return 0; 129 return 0;
157} 130}
131EXPORT_SYMBOL_GPL(nx842_crypto_init);
158 132
159static void nx842_crypto_exit(struct crypto_tfm *tfm) 133void nx842_crypto_exit(struct crypto_tfm *tfm)
160{ 134{
161 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 135 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
162 136
@@ -164,6 +138,7 @@ static void nx842_crypto_exit(struct crypto_tfm *tfm)
164 free_page((unsigned long)ctx->sbounce); 138 free_page((unsigned long)ctx->sbounce);
165 free_page((unsigned long)ctx->dbounce); 139 free_page((unsigned long)ctx->dbounce);
166} 140}
141EXPORT_SYMBOL_GPL(nx842_crypto_exit);
167 142
168static void check_constraints(struct nx842_constraints *c) 143static void check_constraints(struct nx842_constraints *c)
169{ 144{
@@ -250,9 +225,7 @@ nospc:
250 timeout = ktime_add_ms(ktime_get(), COMP_BUSY_TIMEOUT); 225 timeout = ktime_add_ms(ktime_get(), COMP_BUSY_TIMEOUT);
251 do { 226 do {
252 dlen = tmplen; /* reset dlen, if we're retrying */ 227 dlen = tmplen; /* reset dlen, if we're retrying */
253 ret = nx842_platform_driver()->compress(src, slen, 228 ret = ctx->driver->compress(src, slen, dst, &dlen, ctx->wmem);
254 dst, &dlen,
255 ctx->wmem);
256 /* possibly we should reduce the slen here, instead of 229 /* possibly we should reduce the slen here, instead of
257 * retrying with the dbounce buffer? 230 * retrying with the dbounce buffer?
258 */ 231 */
@@ -282,14 +255,14 @@ nospc:
282 return update_param(p, slen, dskip + dlen); 255 return update_param(p, slen, dskip + dlen);
283} 256}
284 257
285static int nx842_crypto_compress(struct crypto_tfm *tfm, 258int nx842_crypto_compress(struct crypto_tfm *tfm,
286 const u8 *src, unsigned int slen, 259 const u8 *src, unsigned int slen,
287 u8 *dst, unsigned int *dlen) 260 u8 *dst, unsigned int *dlen)
288{ 261{
289 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 262 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
290 struct nx842_crypto_header *hdr = &ctx->header; 263 struct nx842_crypto_header *hdr = &ctx->header;
291 struct nx842_crypto_param p; 264 struct nx842_crypto_param p;
292 struct nx842_constraints c = *nx842_platform_driver()->constraints; 265 struct nx842_constraints c = *ctx->driver->constraints;
293 unsigned int groups, hdrsize, h; 266 unsigned int groups, hdrsize, h;
294 int ret, n; 267 int ret, n;
295 bool add_header; 268 bool add_header;
@@ -366,6 +339,7 @@ unlock:
366 spin_unlock_bh(&ctx->lock); 339 spin_unlock_bh(&ctx->lock);
367 return ret; 340 return ret;
368} 341}
342EXPORT_SYMBOL_GPL(nx842_crypto_compress);
369 343
370static int decompress(struct nx842_crypto_ctx *ctx, 344static int decompress(struct nx842_crypto_ctx *ctx,
371 struct nx842_crypto_param *p, 345 struct nx842_crypto_param *p,
@@ -429,9 +403,7 @@ static int decompress(struct nx842_crypto_ctx *ctx,
429 timeout = ktime_add_ms(ktime_get(), DECOMP_BUSY_TIMEOUT); 403 timeout = ktime_add_ms(ktime_get(), DECOMP_BUSY_TIMEOUT);
430 do { 404 do {
431 dlen = tmplen; /* reset dlen, if we're retrying */ 405 dlen = tmplen; /* reset dlen, if we're retrying */
432 ret = nx842_platform_driver()->decompress(src, slen, 406 ret = ctx->driver->decompress(src, slen, dst, &dlen, ctx->wmem);
433 dst, &dlen,
434 ctx->wmem);
435 } while (ret == -EBUSY && ktime_before(ktime_get(), timeout)); 407 } while (ret == -EBUSY && ktime_before(ktime_get(), timeout));
436 if (ret) { 408 if (ret) {
437usesw: 409usesw:
@@ -467,14 +439,14 @@ usesw:
467 return update_param(p, slen + padding, dlen); 439 return update_param(p, slen + padding, dlen);
468} 440}
469 441
470static int nx842_crypto_decompress(struct crypto_tfm *tfm, 442int nx842_crypto_decompress(struct crypto_tfm *tfm,
471 const u8 *src, unsigned int slen, 443 const u8 *src, unsigned int slen,
472 u8 *dst, unsigned int *dlen) 444 u8 *dst, unsigned int *dlen)
473{ 445{
474 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 446 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
475 struct nx842_crypto_header *hdr; 447 struct nx842_crypto_header *hdr;
476 struct nx842_crypto_param p; 448 struct nx842_crypto_param p;
477 struct nx842_constraints c = *nx842_platform_driver()->constraints; 449 struct nx842_constraints c = *ctx->driver->constraints;
478 int n, ret, hdr_len; 450 int n, ret, hdr_len;
479 u16 ignore = 0; 451 u16 ignore = 0;
480 452
@@ -552,49 +524,8 @@ unlock:
552 524
553 return ret; 525 return ret;
554} 526}
555 527EXPORT_SYMBOL_GPL(nx842_crypto_decompress);
556static struct crypto_alg alg = {
557 .cra_name = "842",
558 .cra_driver_name = "842-nx",
559 .cra_priority = 300,
560 .cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
561 .cra_ctxsize = sizeof(struct nx842_crypto_ctx),
562 .cra_module = THIS_MODULE,
563 .cra_init = nx842_crypto_init,
564 .cra_exit = nx842_crypto_exit,
565 .cra_u = { .compress = {
566 .coa_compress = nx842_crypto_compress,
567 .coa_decompress = nx842_crypto_decompress } }
568};
569
570static int __init nx842_crypto_mod_init(void)
571{
572 request_module("nx-compress-powernv");
573 request_module("nx-compress-pseries");
574
575 /* we prevent loading/registering if there's no platform driver,
576 * and we get the platform module that set it so it won't unload,
577 * so we don't need to check if it's set in any of our functions
578 */
579 if (!nx842_platform_driver_get()) {
580 pr_err("no nx842 platform driver found.\n");
581 return -ENODEV;
582 }
583
584 return crypto_register_alg(&alg);
585}
586module_init(nx842_crypto_mod_init);
587
588static void __exit nx842_crypto_mod_exit(void)
589{
590 crypto_unregister_alg(&alg);
591
592 nx842_platform_driver_put();
593}
594module_exit(nx842_crypto_mod_exit);
595 528
596MODULE_LICENSE("GPL"); 529MODULE_LICENSE("GPL");
597MODULE_DESCRIPTION("IBM PowerPC Nest (NX) 842 Hardware Compression Driver"); 530MODULE_DESCRIPTION("IBM PowerPC Nest (NX) 842 Hardware Compression Driver");
598MODULE_ALIAS_CRYPTO("842");
599MODULE_ALIAS_CRYPTO("842-nx");
600MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); 531MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h
index c7dd0a4391e0..a4eee3bba937 100644
--- a/drivers/crypto/nx/nx-842.h
+++ b/drivers/crypto/nx/nx-842.h
@@ -3,8 +3,9 @@
3#define __NX_842_H__ 3#define __NX_842_H__
4 4
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/init.h>
6#include <linux/module.h> 7#include <linux/module.h>
7#include <linux/sw842.h> 8#include <linux/crypto.h>
8#include <linux/of.h> 9#include <linux/of.h>
9#include <linux/slab.h> 10#include <linux/slab.h>
10#include <linux/io.h> 11#include <linux/io.h>
@@ -145,10 +146,40 @@ struct nx842_driver {
145 void *wrkmem); 146 void *wrkmem);
146}; 147};
147 148
148struct nx842_driver *nx842_platform_driver(void); 149struct nx842_crypto_header_group {
149bool nx842_platform_driver_set(struct nx842_driver *driver); 150 __be16 padding; /* unused bytes at start of group */
150void nx842_platform_driver_unset(struct nx842_driver *driver); 151 __be32 compressed_length; /* compressed bytes in group */
151bool nx842_platform_driver_get(void); 152 __be32 uncompressed_length; /* bytes after decompression */
152void nx842_platform_driver_put(void); 153} __packed;
154
155struct nx842_crypto_header {
156 __be16 magic; /* NX842_CRYPTO_MAGIC */
157 __be16 ignore; /* decompressed end bytes to ignore */
158 u8 groups; /* total groups in this header */
159 struct nx842_crypto_header_group group[];
160} __packed;
161
162#define NX842_CRYPTO_GROUP_MAX (0x20)
163
164struct nx842_crypto_ctx {
165 spinlock_t lock;
166
167 u8 *wmem;
168 u8 *sbounce, *dbounce;
169
170 struct nx842_crypto_header header;
171 struct nx842_crypto_header_group group[NX842_CRYPTO_GROUP_MAX];
172
173 struct nx842_driver *driver;
174};
175
176int nx842_crypto_init(struct crypto_tfm *tfm, struct nx842_driver *driver);
177void nx842_crypto_exit(struct crypto_tfm *tfm);
178int nx842_crypto_compress(struct crypto_tfm *tfm,
179 const u8 *src, unsigned int slen,
180 u8 *dst, unsigned int *dlen);
181int nx842_crypto_decompress(struct crypto_tfm *tfm,
182 const u8 *src, unsigned int slen,
183 u8 *dst, unsigned int *dlen);
153 184
154#endif /* __NX_842_H__ */ 185#endif /* __NX_842_H__ */