aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-07-22 14:26:36 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-07-23 06:14:31 -0400
commitd31581a6e31f1c954704f081376e19c2014c45d3 (patch)
tree6270c1714ed20edbbefd90459cf7255c38942806
parent20fc311fc0e14d9f5ef72cfe785fd2b3f6339ab8 (diff)
crypto: nx - merge nx-compress and nx-compress-crypto
Merge the nx-842.c code into nx-842-crypto.c. This allows later patches to remove the 'platform' driver, and instead allow each platform driver to directly register with the crypto compression api. Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/nx/Kconfig17
-rw-r--r--drivers/crypto/nx/Makefile4
-rw-r--r--drivers/crypto/nx/nx-842-crypto.c70
-rw-r--r--drivers/crypto/nx/nx-842.c103
-rw-r--r--drivers/crypto/nx/nx-842.h28
5 files changed, 60 insertions, 162 deletions
diff --git a/drivers/crypto/nx/Kconfig b/drivers/crypto/nx/Kconfig
index e421c96c763a..ad7552a6998c 100644
--- a/drivers/crypto/nx/Kconfig
+++ b/drivers/crypto/nx/Kconfig
@@ -14,11 +14,14 @@ config CRYPTO_DEV_NX_ENCRYPT
14config CRYPTO_DEV_NX_COMPRESS 14config CRYPTO_DEV_NX_COMPRESS
15 tristate "Compression acceleration support" 15 tristate "Compression acceleration support"
16 default y 16 default y
17 select CRYPTO_ALGAPI
18 select 842_DECOMPRESS
17 help 19 help
18 Support for PowerPC Nest (NX) compression acceleration. This 20 Support for PowerPC Nest (NX) compression acceleration. This
19 module supports acceleration for compressing memory with the 842 21 module supports acceleration for compressing memory with the 842
20 algorithm. One of the platform drivers must be selected also. 22 algorithm using the cryptographic API. One of the platform
21 If you choose 'M' here, this module will be called nx_compress. 23 drivers must be selected also. If you choose 'M' here, this
24 module will be called nx_compress.
22 25
23if CRYPTO_DEV_NX_COMPRESS 26if CRYPTO_DEV_NX_COMPRESS
24 27
@@ -42,14 +45,4 @@ config CRYPTO_DEV_NX_COMPRESS_POWERNV
42 algorithm. This supports NX hardware on the PowerNV platform. 45 algorithm. This supports NX hardware on the PowerNV platform.
43 If you choose 'M' here, this module will be called nx_compress_powernv. 46 If you choose 'M' here, this module will be called nx_compress_powernv.
44 47
45config CRYPTO_DEV_NX_COMPRESS_CRYPTO
46 tristate "Compression acceleration cryptographic interface"
47 select CRYPTO_ALGAPI
48 select 842_DECOMPRESS
49 default y
50 help
51 Support for PowerPC Nest (NX) accelerators using the cryptographic
52 API. If you choose 'M' here, this module will be called
53 nx_compress_crypto.
54
55endif 48endif
diff --git a/drivers/crypto/nx/Makefile b/drivers/crypto/nx/Makefile
index e1684f5adb11..e29ee85b2431 100644
--- a/drivers/crypto/nx/Makefile
+++ b/drivers/crypto/nx/Makefile
@@ -13,9 +13,7 @@ nx-crypto-objs := nx.o \
13obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS) += nx-compress.o nx-compress-platform.o 13obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS) += nx-compress.o nx-compress-platform.o
14obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o 14obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_PSERIES) += nx-compress-pseries.o
15obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o 15obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_POWERNV) += nx-compress-powernv.o
16obj-$(CONFIG_CRYPTO_DEV_NX_COMPRESS_CRYPTO) += nx-compress-crypto.o 16nx-compress-objs := nx-842-crypto.o
17nx-compress-objs := nx-842.o
18nx-compress-platform-objs := nx-842-platform.o 17nx-compress-platform-objs := nx-842-platform.o
19nx-compress-pseries-objs := nx-842-pseries.o 18nx-compress-pseries-objs := nx-842-pseries.o
20nx-compress-powernv-objs := nx-842-powernv.o 19nx-compress-powernv-objs := nx-842-powernv.o
21nx-compress-crypto-objs := nx-842-crypto.o
diff --git a/drivers/crypto/nx/nx-842-crypto.c b/drivers/crypto/nx/nx-842-crypto.c
index 51ca168a82e9..4472e2001e79 100644
--- a/drivers/crypto/nx/nx-842-crypto.c
+++ b/drivers/crypto/nx/nx-842-crypto.c
@@ -13,6 +13,9 @@
13 * 13 *
14 * Copyright (C) IBM Corporation, 2011-2015 14 * Copyright (C) IBM Corporation, 2011-2015
15 * 15 *
16 * Designer of the Power data compression engine:
17 * Bulent Abali <abali@us.ibm.com>
18 *
16 * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com> 19 * Original Authors: Robert Jennings <rcj@linux.vnet.ibm.com>
17 * Seth Jennings <sjenning@linux.vnet.ibm.com> 20 * Seth Jennings <sjenning@linux.vnet.ibm.com>
18 * 21 *
@@ -162,24 +165,11 @@ static void nx842_crypto_exit(struct crypto_tfm *tfm)
162 free_page((unsigned long)ctx->dbounce); 165 free_page((unsigned long)ctx->dbounce);
163} 166}
164 167
165static int read_constraints(struct nx842_constraints *c) 168static void check_constraints(struct nx842_constraints *c)
166{ 169{
167 int ret;
168
169 ret = nx842_constraints(c);
170 if (ret) {
171 pr_err_ratelimited("could not get nx842 constraints : %d\n",
172 ret);
173 return ret;
174 }
175
176 /* limit maximum, to always have enough bounce buffer to decompress */ 170 /* limit maximum, to always have enough bounce buffer to decompress */
177 if (c->maximum > BOUNCE_BUFFER_SIZE) { 171 if (c->maximum > BOUNCE_BUFFER_SIZE)
178 c->maximum = BOUNCE_BUFFER_SIZE; 172 c->maximum = BOUNCE_BUFFER_SIZE;
179 pr_info_once("limiting nx842 maximum to %x\n", c->maximum);
180 }
181
182 return 0;
183} 173}
184 174
185static int nx842_crypto_add_header(struct nx842_crypto_header *hdr, u8 *buf) 175static int nx842_crypto_add_header(struct nx842_crypto_header *hdr, u8 *buf)
@@ -260,7 +250,9 @@ nospc:
260 timeout = ktime_add_ms(ktime_get(), COMP_BUSY_TIMEOUT); 250 timeout = ktime_add_ms(ktime_get(), COMP_BUSY_TIMEOUT);
261 do { 251 do {
262 dlen = tmplen; /* reset dlen, if we're retrying */ 252 dlen = tmplen; /* reset dlen, if we're retrying */
263 ret = nx842_compress(src, slen, dst, &dlen, ctx->wmem); 253 ret = nx842_platform_driver()->compress(src, slen,
254 dst, &dlen,
255 ctx->wmem);
264 /* possibly we should reduce the slen here, instead of 256 /* possibly we should reduce the slen here, instead of
265 * retrying with the dbounce buffer? 257 * retrying with the dbounce buffer?
266 */ 258 */
@@ -297,12 +289,14 @@ static int nx842_crypto_compress(struct crypto_tfm *tfm,
297 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 289 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
298 struct nx842_crypto_header *hdr = &ctx->header; 290 struct nx842_crypto_header *hdr = &ctx->header;
299 struct nx842_crypto_param p; 291 struct nx842_crypto_param p;
300 struct nx842_constraints c; 292 struct nx842_constraints c = *nx842_platform_driver()->constraints;
301 unsigned int groups, hdrsize, h; 293 unsigned int groups, hdrsize, h;
302 int ret, n; 294 int ret, n;
303 bool add_header; 295 bool add_header;
304 u16 ignore = 0; 296 u16 ignore = 0;
305 297
298 check_constraints(&c);
299
306 p.in = (u8 *)src; 300 p.in = (u8 *)src;
307 p.iremain = slen; 301 p.iremain = slen;
308 p.out = dst; 302 p.out = dst;
@@ -311,10 +305,6 @@ static int nx842_crypto_compress(struct crypto_tfm *tfm,
311 305
312 *dlen = 0; 306 *dlen = 0;
313 307
314 ret = read_constraints(&c);
315 if (ret)
316 return ret;
317
318 groups = min_t(unsigned int, NX842_CRYPTO_GROUP_MAX, 308 groups = min_t(unsigned int, NX842_CRYPTO_GROUP_MAX,
319 DIV_ROUND_UP(p.iremain, c.maximum)); 309 DIV_ROUND_UP(p.iremain, c.maximum));
320 hdrsize = NX842_CRYPTO_HEADER_SIZE(groups); 310 hdrsize = NX842_CRYPTO_HEADER_SIZE(groups);
@@ -381,8 +371,7 @@ static int decompress(struct nx842_crypto_ctx *ctx,
381 struct nx842_crypto_param *p, 371 struct nx842_crypto_param *p,
382 struct nx842_crypto_header_group *g, 372 struct nx842_crypto_header_group *g,
383 struct nx842_constraints *c, 373 struct nx842_constraints *c,
384 u16 ignore, 374 u16 ignore)
385 bool usehw)
386{ 375{
387 unsigned int slen = be32_to_cpu(g->compressed_length); 376 unsigned int slen = be32_to_cpu(g->compressed_length);
388 unsigned int required_len = be32_to_cpu(g->uncompressed_length); 377 unsigned int required_len = be32_to_cpu(g->uncompressed_length);
@@ -404,9 +393,6 @@ static int decompress(struct nx842_crypto_ctx *ctx,
404 393
405 src += padding; 394 src += padding;
406 395
407 if (!usehw)
408 goto usesw;
409
410 if (slen % c->multiple) 396 if (slen % c->multiple)
411 adj_slen = round_up(slen, c->multiple); 397 adj_slen = round_up(slen, c->multiple);
412 if (slen < c->minimum) 398 if (slen < c->minimum)
@@ -443,7 +429,9 @@ static int decompress(struct nx842_crypto_ctx *ctx,
443 timeout = ktime_add_ms(ktime_get(), DECOMP_BUSY_TIMEOUT); 429 timeout = ktime_add_ms(ktime_get(), DECOMP_BUSY_TIMEOUT);
444 do { 430 do {
445 dlen = tmplen; /* reset dlen, if we're retrying */ 431 dlen = tmplen; /* reset dlen, if we're retrying */
446 ret = nx842_decompress(src, slen, dst, &dlen, ctx->wmem); 432 ret = nx842_platform_driver()->decompress(src, slen,
433 dst, &dlen,
434 ctx->wmem);
447 } while (ret == -EBUSY && ktime_before(ktime_get(), timeout)); 435 } while (ret == -EBUSY && ktime_before(ktime_get(), timeout));
448 if (ret) { 436 if (ret) {
449usesw: 437usesw:
@@ -486,10 +474,11 @@ static int nx842_crypto_decompress(struct crypto_tfm *tfm,
486 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 474 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
487 struct nx842_crypto_header *hdr; 475 struct nx842_crypto_header *hdr;
488 struct nx842_crypto_param p; 476 struct nx842_crypto_param p;
489 struct nx842_constraints c; 477 struct nx842_constraints c = *nx842_platform_driver()->constraints;
490 int n, ret, hdr_len; 478 int n, ret, hdr_len;
491 u16 ignore = 0; 479 u16 ignore = 0;
492 bool usehw = true; 480
481 check_constraints(&c);
493 482
494 p.in = (u8 *)src; 483 p.in = (u8 *)src;
495 p.iremain = slen; 484 p.iremain = slen;
@@ -499,9 +488,6 @@ static int nx842_crypto_decompress(struct crypto_tfm *tfm,
499 488
500 *dlen = 0; 489 *dlen = 0;
501 490
502 if (read_constraints(&c))
503 usehw = false;
504
505 hdr = (struct nx842_crypto_header *)src; 491 hdr = (struct nx842_crypto_header *)src;
506 492
507 spin_lock_bh(&ctx->lock); 493 spin_lock_bh(&ctx->lock);
@@ -516,7 +502,7 @@ static int nx842_crypto_decompress(struct crypto_tfm *tfm,
516 .uncompressed_length = cpu_to_be32(p.oremain), 502 .uncompressed_length = cpu_to_be32(p.oremain),
517 }; 503 };
518 504
519 ret = decompress(ctx, &p, &g, &c, 0, usehw); 505 ret = decompress(ctx, &p, &g, &c, 0);
520 if (ret) 506 if (ret)
521 goto unlock; 507 goto unlock;
522 508
@@ -549,7 +535,7 @@ static int nx842_crypto_decompress(struct crypto_tfm *tfm,
549 if (n + 1 == hdr->groups) 535 if (n + 1 == hdr->groups)
550 ignore = be16_to_cpu(hdr->ignore); 536 ignore = be16_to_cpu(hdr->ignore);
551 537
552 ret = decompress(ctx, &p, &hdr->group[n], &c, ignore, usehw); 538 ret = decompress(ctx, &p, &hdr->group[n], &c, ignore);
553 if (ret) 539 if (ret)
554 goto unlock; 540 goto unlock;
555 } 541 }
@@ -583,6 +569,18 @@ static struct crypto_alg alg = {
583 569
584static int __init nx842_crypto_mod_init(void) 570static int __init nx842_crypto_mod_init(void)
585{ 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
586 return crypto_register_alg(&alg); 584 return crypto_register_alg(&alg);
587} 585}
588module_init(nx842_crypto_mod_init); 586module_init(nx842_crypto_mod_init);
@@ -590,11 +588,13 @@ module_init(nx842_crypto_mod_init);
590static void __exit nx842_crypto_mod_exit(void) 588static void __exit nx842_crypto_mod_exit(void)
591{ 589{
592 crypto_unregister_alg(&alg); 590 crypto_unregister_alg(&alg);
591
592 nx842_platform_driver_put();
593} 593}
594module_exit(nx842_crypto_mod_exit); 594module_exit(nx842_crypto_mod_exit);
595 595
596MODULE_LICENSE("GPL"); 596MODULE_LICENSE("GPL");
597MODULE_DESCRIPTION("IBM PowerPC Nest (NX) 842 Hardware Compression Interface"); 597MODULE_DESCRIPTION("IBM PowerPC Nest (NX) 842 Hardware Compression Driver");
598MODULE_ALIAS_CRYPTO("842"); 598MODULE_ALIAS_CRYPTO("842");
599MODULE_ALIAS_CRYPTO("842-nx"); 599MODULE_ALIAS_CRYPTO("842-nx");
600MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>"); 600MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
deleted file mode 100644
index 6e5e0d60d0c8..000000000000
--- a/drivers/crypto/nx/nx-842.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 * Driver frontend for IBM Power 842 compression accelerator
3 *
4 * Copyright (C) 2015 Dan Streetman, IBM Corp
5 *
6 * Designer of the Power data compression engine:
7 * Bulent Abali <abali@us.ibm.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include "nx-842.h"
23
24MODULE_LICENSE("GPL");
25MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.org>");
26MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors");
27
28/**
29 * nx842_constraints
30 *
31 * This provides the driver's constraints. Different nx842 implementations
32 * may have varying requirements. The constraints are:
33 * @alignment: All buffers should be aligned to this
34 * @multiple: All buffer lengths should be a multiple of this
35 * @minimum: Buffer lengths must not be less than this amount
36 * @maximum: Buffer lengths must not be more than this amount
37 *
38 * The constraints apply to all buffers and lengths, both input and output,
39 * for both compression and decompression, except for the minimum which
40 * only applies to compression input and decompression output; the
41 * compressed data can be less than the minimum constraint. It can be
42 * assumed that compressed data will always adhere to the multiple
43 * constraint.
44 *
45 * The driver may succeed even if these constraints are violated;
46 * however the driver can return failure or suffer reduced performance
47 * if any constraint is not met.
48 */
49int nx842_constraints(struct nx842_constraints *c)
50{
51 memcpy(c, nx842_platform_driver()->constraints, sizeof(*c));
52 return 0;
53}
54EXPORT_SYMBOL_GPL(nx842_constraints);
55
56/**
57 * nx842_workmem_size
58 *
59 * Get the amount of working memory the driver requires.
60 */
61size_t nx842_workmem_size(void)
62{
63 return nx842_platform_driver()->workmem_size;
64}
65EXPORT_SYMBOL_GPL(nx842_workmem_size);
66
67int nx842_compress(const unsigned char *in, unsigned int ilen,
68 unsigned char *out, unsigned int *olen, void *wmem)
69{
70 return nx842_platform_driver()->compress(in, ilen, out, olen, wmem);
71}
72EXPORT_SYMBOL_GPL(nx842_compress);
73
74int nx842_decompress(const unsigned char *in, unsigned int ilen,
75 unsigned char *out, unsigned int *olen, void *wmem)
76{
77 return nx842_platform_driver()->decompress(in, ilen, out, olen, wmem);
78}
79EXPORT_SYMBOL_GPL(nx842_decompress);
80
81static __init int nx842_init(void)
82{
83 request_module("nx-compress-powernv");
84 request_module("nx-compress-pseries");
85
86 /* we prevent loading if there's no platform driver, and we get the
87 * module that set it so it won't unload, so we don't need to check
88 * if it's set in any of the above functions
89 */
90 if (!nx842_platform_driver_get()) {
91 pr_err("no nx842 driver found.\n");
92 return -ENODEV;
93 }
94
95 return 0;
96}
97module_init(nx842_init);
98
99static void __exit nx842_exit(void)
100{
101 nx842_platform_driver_put();
102}
103module_exit(nx842_exit);
diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h
index ac0ea79d0f8b..c7dd0a4391e0 100644
--- a/drivers/crypto/nx/nx-842.h
+++ b/drivers/crypto/nx/nx-842.h
@@ -104,6 +104,25 @@ static inline unsigned long nx842_get_pa(void *addr)
104#define GET_FIELD(v, m) (((v) & (m)) >> MASK_LSH(m)) 104#define GET_FIELD(v, m) (((v) & (m)) >> MASK_LSH(m))
105#define SET_FIELD(v, m, val) (((v) & ~(m)) | (((val) << MASK_LSH(m)) & (m))) 105#define SET_FIELD(v, m, val) (((v) & ~(m)) | (((val) << MASK_LSH(m)) & (m)))
106 106
107/**
108 * This provides the driver's constraints. Different nx842 implementations
109 * may have varying requirements. The constraints are:
110 * @alignment: All buffers should be aligned to this
111 * @multiple: All buffer lengths should be a multiple of this
112 * @minimum: Buffer lengths must not be less than this amount
113 * @maximum: Buffer lengths must not be more than this amount
114 *
115 * The constraints apply to all buffers and lengths, both input and output,
116 * for both compression and decompression, except for the minimum which
117 * only applies to compression input and decompression output; the
118 * compressed data can be less than the minimum constraint. It can be
119 * assumed that compressed data will always adhere to the multiple
120 * constraint.
121 *
122 * The driver may succeed even if these constraints are violated;
123 * however the driver can return failure or suffer reduced performance
124 * if any constraint is not met.
125 */
107struct nx842_constraints { 126struct nx842_constraints {
108 int alignment; 127 int alignment;
109 int multiple; 128 int multiple;
@@ -132,13 +151,4 @@ void nx842_platform_driver_unset(struct nx842_driver *driver);
132bool nx842_platform_driver_get(void); 151bool nx842_platform_driver_get(void);
133void nx842_platform_driver_put(void); 152void nx842_platform_driver_put(void);
134 153
135size_t nx842_workmem_size(void);
136
137int nx842_constraints(struct nx842_constraints *constraints);
138
139int nx842_compress(const unsigned char *in, unsigned int in_len,
140 unsigned char *out, unsigned int *out_len, void *wrkmem);
141int nx842_decompress(const unsigned char *in, unsigned int in_len,
142 unsigned char *out, unsigned int *out_len, void *wrkmem);
143
144#endif /* __NX_842_H__ */ 154#endif /* __NX_842_H__ */