summaryrefslogtreecommitdiffstats
path: root/drivers/crypto/caam/sg_sw_sec4.h
diff options
context:
space:
mode:
authorYuan Kang <Yuan.Kang@freescale.com>2012-06-22 19:48:49 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2012-06-27 14:42:05 +0800
commit643b39b031f546c7c3c60ef360b8260aa2b32762 (patch)
tree71658c6a049937d65b48ebe7bc9a159eb655885a /drivers/crypto/caam/sg_sw_sec4.h
parentb0e09bae37eeacb213d9baf8fcb4d48934a4ada5 (diff)
downloadblackbird-op-linux-643b39b031f546c7c3c60ef360b8260aa2b32762.tar.gz
blackbird-op-linux-643b39b031f546c7c3c60ef360b8260aa2b32762.zip
crypto: caam - chaining support
support chained scatterlists for aead, ablkcipher and ahash. Signed-off-by: Yuan Kang <Yuan.Kang@freescale.com> - fix dma unmap leak - un-unlikely src == dst, due to experience with AF_ALG Signed-off-by: Kudupudi Ugendreshwar <B38865@freescale.com> Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/caam/sg_sw_sec4.h')
-rw-r--r--drivers/crypto/caam/sg_sw_sec4.h44
1 files changed, 39 insertions, 5 deletions
diff --git a/drivers/crypto/caam/sg_sw_sec4.h b/drivers/crypto/caam/sg_sw_sec4.h
index 2dda9e3a5e67..e0037c8ee243 100644
--- a/drivers/crypto/caam/sg_sw_sec4.h
+++ b/drivers/crypto/caam/sg_sw_sec4.h
@@ -37,7 +37,7 @@ sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg),
sg_dma_len(sg), offset);
sec4_sg_ptr++;
- sg = sg_next(sg);
+ sg = scatterwalk_sg_next(sg);
sg_count--;
}
return sec4_sg_ptr - 1;
@@ -56,7 +56,8 @@ static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
}
/* count number of elements in scatterlist */
-static inline int __sg_count(struct scatterlist *sg_list, int nbytes)
+static inline int __sg_count(struct scatterlist *sg_list, int nbytes,
+ bool *chained)
{
struct scatterlist *sg = sg_list;
int sg_nents = 0;
@@ -65,7 +66,7 @@ static inline int __sg_count(struct scatterlist *sg_list, int nbytes)
sg_nents++;
nbytes -= sg->length;
if (!sg_is_last(sg) && (sg + 1)->length == 0)
- BUG(); /* Not support chaining */
+ *chained = true;
sg = scatterwalk_sg_next(sg);
}
@@ -73,9 +74,10 @@ static inline int __sg_count(struct scatterlist *sg_list, int nbytes)
}
/* derive number of elements in scatterlist, but return 0 for 1 */
-static inline int sg_count(struct scatterlist *sg_list, int nbytes)
+static inline int sg_count(struct scatterlist *sg_list, int nbytes,
+ bool *chained)
{
- int sg_nents = __sg_count(sg_list, nbytes);
+ int sg_nents = __sg_count(sg_list, nbytes, chained);
if (likely(sg_nents == 1))
return 0;
@@ -83,6 +85,38 @@ static inline int sg_count(struct scatterlist *sg_list, int nbytes)
return sg_nents;
}
+static int dma_map_sg_chained(struct device *dev, struct scatterlist *sg,
+ unsigned int nents, enum dma_data_direction dir,
+ bool chained)
+{
+ if (unlikely(chained)) {
+ int i;
+ for (i = 0; i < nents; i++) {
+ dma_map_sg(dev, sg, 1, dir);
+ sg = scatterwalk_sg_next(sg);
+ }
+ } else {
+ dma_map_sg(dev, sg, nents, dir);
+ }
+ return nents;
+}
+
+static int dma_unmap_sg_chained(struct device *dev, struct scatterlist *sg,
+ unsigned int nents, enum dma_data_direction dir,
+ bool chained)
+{
+ if (unlikely(chained)) {
+ int i;
+ for (i = 0; i < nents; i++) {
+ dma_unmap_sg(dev, sg, 1, dir);
+ sg = scatterwalk_sg_next(sg);
+ }
+ } else {
+ dma_unmap_sg(dev, sg, nents, dir);
+ }
+ return nents;
+}
+
/* Copy from len bytes of sg to dest, starting from beginning */
static inline void sg_copy(u8 *dest, struct scatterlist *sg, unsigned int len)
{
OpenPOWER on IntegriCloud