aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-06-12 10:58:47 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-06-15 06:15:57 -0400
commit2c6f6eabc0bfcea0a62370038da713e3873cff31 (patch)
tree7c82b26a28581a9502c59a96e8f8a4fc5b94df2f
parent32be6d3e362b896c81aae7c635d44e5a91406ce2 (diff)
crypto: nx - replace NX842_MEM_COMPRESS with function
Replace the NX842_MEM_COMPRESS define with a function that returns the specific platform driver's required working memory size. The common nx-842.c driver refuses to load if there is no platform driver present, so instead of defining an approximate working memory size that's the maximum approximate size of both platform driver's size requirements, the platform driver can directly provide its specific, i.e. sizeof(struct nx842_workmem), size requirements which the 842-nx crypto compression driver will use. This saves memory by both reducing the required size of each driver to the specific sizeof() amount, as well as using the specific loaded platform driver's required amount, instead of the maximum of both. Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--drivers/crypto/nx/nx-842-crypto.c2
-rw-r--r--drivers/crypto/nx/nx-842-powernv.c11
-rw-r--r--drivers/crypto/nx/nx-842-pseries.c7
-rw-r--r--drivers/crypto/nx/nx-842.c11
-rw-r--r--drivers/crypto/nx/nx-842.h9
5 files changed, 25 insertions, 15 deletions
diff --git a/drivers/crypto/nx/nx-842-crypto.c b/drivers/crypto/nx/nx-842-crypto.c
index 95066f336b26..d53a1dcd7b4e 100644
--- a/drivers/crypto/nx/nx-842-crypto.c
+++ b/drivers/crypto/nx/nx-842-crypto.c
@@ -136,7 +136,7 @@ static int nx842_crypto_init(struct crypto_tfm *tfm)
136{ 136{
137 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm); 137 struct nx842_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
138 138
139 ctx->wmem = kmalloc(NX842_MEM_COMPRESS, GFP_KERNEL); 139 ctx->wmem = kmalloc(nx842_workmem_size(), GFP_KERNEL);
140 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 140 ctx->sbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
141 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER); 141 ctx->dbounce = (u8 *)__get_free_pages(GFP_KERNEL, BOUNCE_BUFFER_ORDER);
142 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) { 142 if (!ctx->wmem || !ctx->sbounce || !ctx->dbounce) {
diff --git a/drivers/crypto/nx/nx-842-powernv.c b/drivers/crypto/nx/nx-842-powernv.c
index c388dba7da64..33b3b0abf4ae 100644
--- a/drivers/crypto/nx/nx-842-powernv.c
+++ b/drivers/crypto/nx/nx-842-powernv.c
@@ -367,7 +367,8 @@ static int wait_for_csb(struct nx842_workmem *wmem,
367 * @inlen: input buffer size 367 * @inlen: input buffer size
368 * @out: output buffer pointer 368 * @out: output buffer pointer
369 * @outlenp: output buffer size pointer 369 * @outlenp: output buffer size pointer
370 * @workmem: working memory buffer pointer, must be at least NX842_MEM_COMPRESS 370 * @workmem: working memory buffer pointer, size determined by
371 * nx842_powernv_driver.workmem_size
371 * @fc: function code, see CCW Function Codes in nx-842.h 372 * @fc: function code, see CCW Function Codes in nx-842.h
372 * 373 *
373 * Returns: 374 * Returns:
@@ -477,7 +478,8 @@ static int nx842_powernv_function(const unsigned char *in, unsigned int inlen,
477 * @inlen: input buffer size 478 * @inlen: input buffer size
478 * @out: output buffer pointer 479 * @out: output buffer pointer
479 * @outlenp: output buffer size pointer 480 * @outlenp: output buffer size pointer
480 * @workmem: working memory buffer pointer, must be at least NX842_MEM_COMPRESS 481 * @workmem: working memory buffer pointer, size determined by
482 * nx842_powernv_driver.workmem_size
481 * 483 *
482 * Returns: see @nx842_powernv_function() 484 * Returns: see @nx842_powernv_function()
483 */ 485 */
@@ -504,7 +506,8 @@ static int nx842_powernv_compress(const unsigned char *in, unsigned int inlen,
504 * @inlen: input buffer size 506 * @inlen: input buffer size
505 * @out: output buffer pointer 507 * @out: output buffer pointer
506 * @outlenp: output buffer size pointer 508 * @outlenp: output buffer size pointer
507 * @workmem: working memory buffer pointer, must be at least NX842_MEM_COMPRESS 509 * @workmem: working memory buffer pointer, size determined by
510 * nx842_powernv_driver.workmem_size
508 * 511 *
509 * Returns: see @nx842_powernv_function() 512 * Returns: see @nx842_powernv_function()
510 */ 513 */
@@ -572,6 +575,7 @@ static struct nx842_constraints nx842_powernv_constraints = {
572static struct nx842_driver nx842_powernv_driver = { 575static struct nx842_driver nx842_powernv_driver = {
573 .name = KBUILD_MODNAME, 576 .name = KBUILD_MODNAME,
574 .owner = THIS_MODULE, 577 .owner = THIS_MODULE,
578 .workmem_size = sizeof(struct nx842_workmem),
575 .constraints = &nx842_powernv_constraints, 579 .constraints = &nx842_powernv_constraints,
576 .compress = nx842_powernv_compress, 580 .compress = nx842_powernv_compress,
577 .decompress = nx842_powernv_decompress, 581 .decompress = nx842_powernv_decompress,
@@ -582,7 +586,6 @@ static __init int nx842_powernv_init(void)
582 struct device_node *dn; 586 struct device_node *dn;
583 587
584 /* verify workmem size/align restrictions */ 588 /* verify workmem size/align restrictions */
585 BUILD_BUG_ON(sizeof(struct nx842_workmem) > NX842_MEM_COMPRESS);
586 BUILD_BUG_ON(WORKMEM_ALIGN % CRB_ALIGN); 589 BUILD_BUG_ON(WORKMEM_ALIGN % CRB_ALIGN);
587 BUILD_BUG_ON(CRB_ALIGN % DDE_ALIGN); 590 BUILD_BUG_ON(CRB_ALIGN % DDE_ALIGN);
588 BUILD_BUG_ON(CRB_SIZE % DDE_ALIGN); 591 BUILD_BUG_ON(CRB_SIZE % DDE_ALIGN);
diff --git a/drivers/crypto/nx/nx-842-pseries.c b/drivers/crypto/nx/nx-842-pseries.c
index 41bc551ccaf3..da52d8edefb3 100644
--- a/drivers/crypto/nx/nx-842-pseries.c
+++ b/drivers/crypto/nx/nx-842-pseries.c
@@ -284,7 +284,7 @@ static int nx842_validate_result(struct device *dev,
284 * @out: Pointer to output buffer 284 * @out: Pointer to output buffer
285 * @outlen: Length of output buffer 285 * @outlen: Length of output buffer
286 * @wrkmem: ptr to buffer for working memory, size determined by 286 * @wrkmem: ptr to buffer for working memory, size determined by
287 * NX842_MEM_COMPRESS 287 * nx842_pseries_driver.workmem_size
288 * 288 *
289 * Returns: 289 * Returns:
290 * 0 Success, output of length @outlen stored in the buffer at @out 290 * 0 Success, output of length @outlen stored in the buffer at @out
@@ -411,7 +411,7 @@ unlock:
411 * @out: Pointer to output buffer 411 * @out: Pointer to output buffer
412 * @outlen: Length of output buffer 412 * @outlen: Length of output buffer
413 * @wrkmem: ptr to buffer for working memory, size determined by 413 * @wrkmem: ptr to buffer for working memory, size determined by
414 * NX842_MEM_COMPRESS 414 * nx842_pseries_driver.workmem_size
415 * 415 *
416 * Returns: 416 * Returns:
417 * 0 Success, output of length @outlen stored in the buffer at @out 417 * 0 Success, output of length @outlen stored in the buffer at @out
@@ -963,6 +963,7 @@ static struct attribute_group nx842_attribute_group = {
963static struct nx842_driver nx842_pseries_driver = { 963static struct nx842_driver nx842_pseries_driver = {
964 .name = KBUILD_MODNAME, 964 .name = KBUILD_MODNAME,
965 .owner = THIS_MODULE, 965 .owner = THIS_MODULE,
966 .workmem_size = sizeof(struct nx842_workmem),
966 .constraints = &nx842_pseries_constraints, 967 .constraints = &nx842_pseries_constraints,
967 .compress = nx842_pseries_compress, 968 .compress = nx842_pseries_compress,
968 .decompress = nx842_pseries_decompress, 969 .decompress = nx842_pseries_decompress,
@@ -1084,8 +1085,6 @@ static int __init nx842_init(void)
1084 1085
1085 pr_info("Registering IBM Power 842 compression driver\n"); 1086 pr_info("Registering IBM Power 842 compression driver\n");
1086 1087
1087 BUILD_BUG_ON(sizeof(struct nx842_workmem) > NX842_MEM_COMPRESS);
1088
1089 if (!of_find_compatible_node(NULL, NULL, "ibm,compression")) 1088 if (!of_find_compatible_node(NULL, NULL, "ibm,compression"))
1090 return -ENODEV; 1089 return -ENODEV;
1091 1090
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index 9f391d64c722..6e5e0d60d0c8 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -53,6 +53,17 @@ int nx842_constraints(struct nx842_constraints *c)
53} 53}
54EXPORT_SYMBOL_GPL(nx842_constraints); 54EXPORT_SYMBOL_GPL(nx842_constraints);
55 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
56int nx842_compress(const unsigned char *in, unsigned int ilen, 67int nx842_compress(const unsigned char *in, unsigned int ilen,
57 unsigned char *out, unsigned int *olen, void *wmem) 68 unsigned char *out, unsigned int *olen, void *wmem)
58{ 69{
diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h
index 4dbac11c2aa5..f6821b65b7ce 100644
--- a/drivers/crypto/nx/nx-842.h
+++ b/drivers/crypto/nx/nx-842.h
@@ -11,12 +11,6 @@
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/ratelimit.h> 12#include <linux/ratelimit.h>
13 13
14#define __NX842_PSERIES_MEM_COMPRESS (10240)
15#define __NX842_POWERNV_MEM_COMPRESS (1024)
16
17#define NX842_MEM_COMPRESS (max_t(unsigned int, \
18 __NX842_PSERIES_MEM_COMPRESS, __NX842_POWERNV_MEM_COMPRESS))
19
20/* Restrictions on Data Descriptor List (DDL) and Entry (DDE) buffers 14/* Restrictions on Data Descriptor List (DDL) and Entry (DDE) buffers
21 * 15 *
22 * From NX P8 workbook, sec 4.9.1 "842 details" 16 * From NX P8 workbook, sec 4.9.1 "842 details"
@@ -119,6 +113,7 @@ struct nx842_constraints {
119struct nx842_driver { 113struct nx842_driver {
120 char *name; 114 char *name;
121 struct module *owner; 115 struct module *owner;
116 size_t workmem_size;
122 117
123 struct nx842_constraints *constraints; 118 struct nx842_constraints *constraints;
124 119
@@ -136,6 +131,8 @@ void nx842_platform_driver_unset(struct nx842_driver *driver);
136bool nx842_platform_driver_get(void); 131bool nx842_platform_driver_get(void);
137void nx842_platform_driver_put(void); 132void nx842_platform_driver_put(void);
138 133
134size_t nx842_workmem_size(void);
135
139int nx842_constraints(struct nx842_constraints *constraints); 136int nx842_constraints(struct nx842_constraints *constraints);
140 137
141int nx842_compress(const unsigned char *in, unsigned int in_len, 138int nx842_compress(const unsigned char *in, unsigned int in_len,