diff options
author | Joel Fernandes <joelf@ti.com> | 2013-08-17 22:42:22 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-08-21 07:27:58 -0400 |
commit | 257aff515409f9455edff3a946344e71baf9e116 (patch) | |
tree | 01dea1b98b5d1534a2530698171e414e2bb1dfda | |
parent | b4eba0ca341fb6ad0199ab3f2244aa7e0c4cb34d (diff) |
crypto: scatterwalk - Add support for calculating number of SG elements
Crypto layer only passes nbytes to encrypt but in omap-aes driver we need to
know number of SG elements to pass to dmaengine slave API. We add function for
the same to scatterwalk library.
Signed-off-by: Joel Fernandes <joelf@ti.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/scatterwalk.c | 22 | ||||
-rw-r--r-- | include/crypto/scatterwalk.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c index 7281b8a93ad3..79ca2278c2a3 100644 --- a/crypto/scatterwalk.c +++ b/crypto/scatterwalk.c | |||
@@ -124,3 +124,25 @@ void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | |||
124 | scatterwalk_done(&walk, out, 0); | 124 | scatterwalk_done(&walk, out, 0); |
125 | } | 125 | } |
126 | EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); | 126 | EXPORT_SYMBOL_GPL(scatterwalk_map_and_copy); |
127 | |||
128 | int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes) | ||
129 | { | ||
130 | int offset = 0, n = 0; | ||
131 | |||
132 | /* num_bytes is too small */ | ||
133 | if (num_bytes < sg->length) | ||
134 | return -1; | ||
135 | |||
136 | do { | ||
137 | offset += sg->length; | ||
138 | n++; | ||
139 | sg = scatterwalk_sg_next(sg); | ||
140 | |||
141 | /* num_bytes is too large */ | ||
142 | if (unlikely(!sg && (num_bytes < offset))) | ||
143 | return -1; | ||
144 | } while (sg && (num_bytes > offset)); | ||
145 | |||
146 | return n; | ||
147 | } | ||
148 | EXPORT_SYMBOL_GPL(scatterwalk_bytes_sglen); | ||
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h index 3744d2a642df..13621cc8cf4c 100644 --- a/include/crypto/scatterwalk.h +++ b/include/crypto/scatterwalk.h | |||
@@ -113,4 +113,6 @@ void scatterwalk_done(struct scatter_walk *walk, int out, int more); | |||
113 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, | 113 | void scatterwalk_map_and_copy(void *buf, struct scatterlist *sg, |
114 | unsigned int start, unsigned int nbytes, int out); | 114 | unsigned int start, unsigned int nbytes, int out); |
115 | 115 | ||
116 | int scatterwalk_bytes_sglen(struct scatterlist *sg, int num_bytes); | ||
117 | |||
116 | #endif /* _CRYPTO_SCATTERWALK_H */ | 118 | #endif /* _CRYPTO_SCATTERWALK_H */ |