crypto: caam - use mapped_{src,dst}_nents for job descriptor
authorIuliana Prodan <iuliana.prodan@nxp.com>
Mon, 1 Apr 2019 12:36:12 +0000 (15:36 +0300)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
The mapped_{src,dst}_nents _returned_ from the dma_map_sg call (which
could be less than src/dst_nents) have to be used to generate the aead,
skcipher job descriptors.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit ba4cf71b6f1b0165f34888b17fe44f4235dd0132)
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
drivers/crypto/caam/caamalg.c

index 01db70e..308b852 100644 (file)
@@ -825,6 +825,8 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
  * aead_edesc - s/w-extended aead descriptor
  * @src_nents: number of segments in input s/w scatterlist
  * @dst_nents: number of segments in output s/w scatterlist
+ * @mapped_src_nents: number of segments in input h/w link table
+ * @mapped_dst_nents: number of segments in output h/w link table
  * @sec4_sg_bytes: length of dma mapped sec4_sg space
  * @sec4_sg_dma: bus physical mapped address of h/w link table
  * @sec4_sg: pointer to h/w link table
@@ -833,6 +835,8 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
 struct aead_edesc {
        int src_nents;
        int dst_nents;
+       int mapped_src_nents;
+       int mapped_dst_nents;
        int sec4_sg_bytes;
        dma_addr_t sec4_sg_dma;
        struct sec4_sg_entry *sec4_sg;
@@ -843,6 +847,8 @@ struct aead_edesc {
  * ablkcipher_edesc - s/w-extended ablkcipher descriptor
  * @src_nents: number of segments in input s/w scatterlist
  * @dst_nents: number of segments in output s/w scatterlist
+ * @mapped_src_nents: number of segments in input h/w link table
+ * @mapped_dst_nents: number of segments in output h/w link table
  * @iv_dma: dma address of iv for checking continuity and link table
  * @iv_dir: DMA mapping direction for IV
  * @sec4_sg_bytes: length of dma mapped sec4_sg space
@@ -854,6 +860,8 @@ struct aead_edesc {
 struct ablkcipher_edesc {
        int src_nents;
        int dst_nents;
+       int mapped_src_nents;
+       int mapped_dst_nents;
        dma_addr_t iv_dma;
        enum dma_data_direction iv_dir;
        int sec4_sg_bytes;
@@ -1072,11 +1080,12 @@ static void init_aead_job(struct aead_request *req,
        init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
 
        if (all_contig) {
-               src_dma = edesc->src_nents ? sg_dma_address(req->src) : 0;
+               src_dma = edesc->mapped_src_nents ? sg_dma_address(req->src) :
+                                                   0;
                in_options = 0;
        } else {
                src_dma = edesc->sec4_sg_dma;
-               sec4_sg_index += edesc->src_nents;
+               sec4_sg_index += edesc->mapped_src_nents;
                in_options = LDST_SGF;
        }
 
@@ -1087,7 +1096,7 @@ static void init_aead_job(struct aead_request *req,
        out_options = in_options;
 
        if (unlikely(req->src != req->dst)) {
-               if (edesc->dst_nents == 1) {
+               if (edesc->mapped_dst_nents == 1) {
                        dst_dma = sg_dma_address(req->dst);
                        out_options = 0;
                } else {
@@ -1222,11 +1231,11 @@ static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
                dst_dma = edesc->sec4_sg_dma + sizeof(struct sec4_sg_entry);
                out_options = LDST_SGF;
        } else {
-               if (edesc->dst_nents == 1) {
+               if (edesc->mapped_dst_nents == 1) {
                        dst_dma = sg_dma_address(req->dst);
                } else {
-                       dst_dma = edesc->sec4_sg_dma + (edesc->src_nents + 1) *
-                                 sizeof(struct sec4_sg_entry);
+                       dst_dma = edesc->sec4_sg_dma + (edesc->mapped_src_nents
+                                 + 1) * sizeof(struct sec4_sg_entry);
                        out_options = LDST_SGF;
                }
        }
@@ -1366,6 +1375,8 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
 
        edesc->src_nents = src_nents;
        edesc->dst_nents = dst_nents;
+       edesc->mapped_src_nents = mapped_src_nents;
+       edesc->mapped_dst_nents = mapped_dst_nents;
        edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
                         desc_bytes;
        *all_contig_ptr = !(mapped_src_nents > 1);
@@ -1637,6 +1648,8 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
 
        edesc->src_nents = src_nents;
        edesc->dst_nents = dst_nents;
+       edesc->mapped_src_nents = mapped_src_nents;
+       edesc->mapped_dst_nents = mapped_dst_nents;
        edesc->sec4_sg_bytes = sec4_sg_bytes;
        edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
                                                  desc_bytes);