aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-05-07 13:49:18 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2015-05-11 03:06:46 -0400
commit959e6659b6f74ec1fa4d391a3b88d63dc0189f36 (patch)
tree13e716f492a528a093e061fec08e7ed74dbaddcc
parent7011a122383e36dab594406720fa1d089e0be8f9 (diff)
crypto: nx - add nx842 constraints
Add "constraints" for the NX-842 driver. The constraints are used to indicate what the current NX-842 platform driver is capable of. The constraints tell the NX-842 user what alignment, min and max length, and length multiple each provided buffers should conform to. These are required because the 842 hardware requires buffers to meet specific constraints that vary based on platform - for example, the pSeries max length is much lower than the PowerNV max length. 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-pseries.c10
-rw-r--r--drivers/crypto/nx/nx-842.c38
-rw-r--r--drivers/crypto/nx/nx-842.h2
-rw-r--r--include/linux/nx842.h9
4 files changed, 59 insertions, 0 deletions
diff --git a/drivers/crypto/nx/nx-842-pseries.c b/drivers/crypto/nx/nx-842-pseries.c
index 9b83c9e7fd73..cb481d81df06 100644
--- a/drivers/crypto/nx/nx-842-pseries.c
+++ b/drivers/crypto/nx/nx-842-pseries.c
@@ -40,6 +40,13 @@ MODULE_DESCRIPTION("842 H/W Compression driver for IBM Power processors");
40/* IO buffer must be 128 byte aligned */ 40/* IO buffer must be 128 byte aligned */
41#define IO_BUFFER_ALIGN 128 41#define IO_BUFFER_ALIGN 128
42 42
43static struct nx842_constraints nx842_pseries_constraints = {
44 .alignment = IO_BUFFER_ALIGN,
45 .multiple = DDE_BUFFER_LAST_MULT,
46 .minimum = IO_BUFFER_ALIGN,
47 .maximum = PAGE_SIZE, /* dynamic, max_sync_size */
48};
49
43struct nx842_header { 50struct nx842_header {
44 int blocks_nr; /* number of compressed blocks */ 51 int blocks_nr; /* number of compressed blocks */
45 int offset; /* offset of the first block (from beginning of header) */ 52 int offset; /* offset of the first block (from beginning of header) */
@@ -842,6 +849,8 @@ static int nx842_OF_upd_maxsyncop(struct nx842_devdata *devdata,
842 goto out; 849 goto out;
843 } 850 }
844 851
852 nx842_pseries_constraints.maximum = devdata->max_sync_size;
853
845 devdata->max_sync_sg = (unsigned int)min(maxsynccop->comp_sg_limit, 854 devdata->max_sync_sg = (unsigned int)min(maxsynccop->comp_sg_limit,
846 maxsynccop->decomp_sg_limit); 855 maxsynccop->decomp_sg_limit);
847 if (devdata->max_sync_sg < 1) { 856 if (devdata->max_sync_sg < 1) {
@@ -1115,6 +1124,7 @@ static struct attribute_group nx842_attribute_group = {
1115 1124
1116static struct nx842_driver nx842_pseries_driver = { 1125static struct nx842_driver nx842_pseries_driver = {
1117 .owner = THIS_MODULE, 1126 .owner = THIS_MODULE,
1127 .constraints = &nx842_pseries_constraints,
1118 .compress = nx842_pseries_compress, 1128 .compress = nx842_pseries_compress,
1119 .decompress = nx842_pseries_decompress, 1129 .decompress = nx842_pseries_decompress,
1120}; 1130};
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index f1f378eef373..160fe2d97336 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -86,6 +86,44 @@ static void put_driver(struct nx842_driver *driver)
86 module_put(driver->owner); 86 module_put(driver->owner);
87} 87}
88 88
89/**
90 * nx842_constraints
91 *
92 * This provides the driver's constraints. Different nx842 implementations
93 * may have varying requirements. The constraints are:
94 * @alignment: All buffers should be aligned to this
95 * @multiple: All buffer lengths should be a multiple of this
96 * @minimum: Buffer lengths must not be less than this amount
97 * @maximum: Buffer lengths must not be more than this amount
98 *
99 * The constraints apply to all buffers and lengths, both input and output,
100 * for both compression and decompression, except for the minimum which
101 * only applies to compression input and decompression output; the
102 * compressed data can be less than the minimum constraint. It can be
103 * assumed that compressed data will always adhere to the multiple
104 * constraint.
105 *
106 * The driver may succeed even if these constraints are violated;
107 * however the driver can return failure or suffer reduced performance
108 * if any constraint is not met.
109 */
110int nx842_constraints(struct nx842_constraints *c)
111{
112 struct nx842_driver *driver = get_driver();
113 int ret = 0;
114
115 if (!driver)
116 return -ENODEV;
117
118 BUG_ON(!c);
119 memcpy(c, driver->constraints, sizeof(*c));
120
121 put_driver(driver);
122
123 return ret;
124}
125EXPORT_SYMBOL_GPL(nx842_constraints);
126
89int nx842_compress(const unsigned char *in, unsigned int in_len, 127int nx842_compress(const unsigned char *in, unsigned int in_len,
90 unsigned char *out, unsigned int *out_len, 128 unsigned char *out, unsigned int *out_len,
91 void *wrkmem) 129 void *wrkmem)
diff --git a/drivers/crypto/nx/nx-842.h b/drivers/crypto/nx/nx-842.h
index 2a5d4e197c72..c6ceb0f1d04c 100644
--- a/drivers/crypto/nx/nx-842.h
+++ b/drivers/crypto/nx/nx-842.h
@@ -12,6 +12,8 @@
12struct nx842_driver { 12struct nx842_driver {
13 struct module *owner; 13 struct module *owner;
14 14
15 struct nx842_constraints *constraints;
16
15 int (*compress)(const unsigned char *in, unsigned int in_len, 17 int (*compress)(const unsigned char *in, unsigned int in_len,
16 unsigned char *out, unsigned int *out_len, 18 unsigned char *out, unsigned int *out_len,
17 void *wrkmem); 19 void *wrkmem);
diff --git a/include/linux/nx842.h b/include/linux/nx842.h
index d919c22b7fd6..aa1a97e90dea 100644
--- a/include/linux/nx842.h
+++ b/include/linux/nx842.h
@@ -5,6 +5,15 @@
5 5
6#define NX842_MEM_COMPRESS __NX842_PSERIES_MEM_COMPRESS 6#define NX842_MEM_COMPRESS __NX842_PSERIES_MEM_COMPRESS
7 7
8struct nx842_constraints {
9 int alignment;
10 int multiple;
11 int minimum;
12 int maximum;
13};
14
15int nx842_constraints(struct nx842_constraints *constraints);
16
8int nx842_compress(const unsigned char *in, unsigned int in_len, 17int nx842_compress(const unsigned char *in, unsigned int in_len,
9 unsigned char *out, unsigned int *out_len, void *wrkmem); 18 unsigned char *out, unsigned int *out_len, void *wrkmem);
10int nx842_decompress(const unsigned char *in, unsigned int in_len, 19int nx842_decompress(const unsigned char *in, unsigned int in_len,