Commit 5c727f92 authored by Christian Lamparter's avatar Christian Lamparter Committed by Herbert Xu

crypto: crypto4xx - refactor crypto4xx_copy_pkt_to_dst()

This patch refactors the crypto4xx_copy_pkt_to_dst() to use
scatterwalk_map_and_copy() to copy the processed data between
the crypto engine's scatter ring buffer and the destination
specified by the ablkcipher_request.

This also makes the crypto4xx_fill_one_page() function redundant.
Signed-off-by: default avatarChristian Lamparter <chunkeey@googlemail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent f2a13e7c
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <crypto/aes.h> #include <crypto/aes.h>
#include <crypto/ctr.h> #include <crypto/ctr.h>
#include <crypto/sha.h> #include <crypto/sha.h>
#include <crypto/scatterwalk.h>
#include "crypto4xx_reg_def.h" #include "crypto4xx_reg_def.h"
#include "crypto4xx_core.h" #include "crypto4xx_core.h"
#include "crypto4xx_sa.h" #include "crypto4xx_sa.h"
...@@ -481,111 +482,44 @@ static inline struct ce_sd *crypto4xx_get_sdp(struct crypto4xx_device *dev, ...@@ -481,111 +482,44 @@ static inline struct ce_sd *crypto4xx_get_sdp(struct crypto4xx_device *dev,
return (struct ce_sd *)(dev->sdr + sizeof(struct ce_sd) * idx); return (struct ce_sd *)(dev->sdr + sizeof(struct ce_sd) * idx);
} }
static u32 crypto4xx_fill_one_page(struct crypto4xx_device *dev,
dma_addr_t *addr, u32 *length,
u32 *idx, u32 *offset, u32 *nbytes)
{
u32 len;
if (*length > dev->scatter_buffer_size) {
memcpy(phys_to_virt(*addr),
dev->scatter_buffer_va +
*idx * dev->scatter_buffer_size + *offset,
dev->scatter_buffer_size);
*offset = 0;
*length -= dev->scatter_buffer_size;
*nbytes -= dev->scatter_buffer_size;
if (*idx == PPC4XX_LAST_SD)
*idx = 0;
else
(*idx)++;
*addr = *addr + dev->scatter_buffer_size;
return 1;
} else if (*length < dev->scatter_buffer_size) {
memcpy(phys_to_virt(*addr),
dev->scatter_buffer_va +
*idx * dev->scatter_buffer_size + *offset, *length);
if ((*offset + *length) == dev->scatter_buffer_size) {
if (*idx == PPC4XX_LAST_SD)
*idx = 0;
else
(*idx)++;
*nbytes -= *length;
*offset = 0;
} else {
*nbytes -= *length;
*offset += *length;
}
return 0;
} else {
len = (*nbytes <= dev->scatter_buffer_size) ?
(*nbytes) : dev->scatter_buffer_size;
memcpy(phys_to_virt(*addr),
dev->scatter_buffer_va +
*idx * dev->scatter_buffer_size + *offset,
len);
*offset = 0;
*nbytes -= len;
if (*idx == PPC4XX_LAST_SD)
*idx = 0;
else
(*idx)++;
return 0;
}
}
static void crypto4xx_copy_pkt_to_dst(struct crypto4xx_device *dev, static void crypto4xx_copy_pkt_to_dst(struct crypto4xx_device *dev,
struct ce_pd *pd, struct ce_pd *pd,
struct pd_uinfo *pd_uinfo, struct pd_uinfo *pd_uinfo,
u32 nbytes, u32 nbytes,
struct scatterlist *dst) struct scatterlist *dst)
{ {
dma_addr_t addr; unsigned int first_sd = pd_uinfo->first_sd;
u32 this_sd; unsigned int last_sd;
u32 offset; unsigned int overflow = 0;
u32 len; unsigned int to_copy;
u32 i; unsigned int dst_start = 0;
u32 sg_len;
struct scatterlist *sg; /*
* Because the scatter buffers are all neatly organized in one
* big continuous ringbuffer; scatterwalk_map_and_copy() can
* be instructed to copy a range of buffers in one go.
*/
this_sd = pd_uinfo->first_sd; last_sd = (first_sd + pd_uinfo->num_sd);
offset = 0; if (last_sd > PPC4XX_LAST_SD) {
i = 0; last_sd = PPC4XX_LAST_SD;
overflow = last_sd % PPC4XX_NUM_SD;
}
while (nbytes) { while (nbytes) {
sg = &dst[i]; void *buf = dev->scatter_buffer_va +
sg_len = sg->length; first_sd * PPC4XX_SD_BUFFER_SIZE;
addr = dma_map_page(dev->core_dev->device, sg_page(sg),
sg->offset, sg->length, DMA_TO_DEVICE); to_copy = min(nbytes, PPC4XX_SD_BUFFER_SIZE *
(1 + last_sd - first_sd));
if (offset == 0) { scatterwalk_map_and_copy(buf, dst, dst_start, to_copy, 1);
len = (nbytes <= sg->length) ? nbytes : sg->length; nbytes -= to_copy;
while (crypto4xx_fill_one_page(dev, &addr, &len,
&this_sd, &offset, &nbytes)) if (overflow) {
; first_sd = 0;
if (!nbytes) last_sd = overflow;
return; dst_start += to_copy;
i++; overflow = 0;
} else {
len = (nbytes <= (dev->scatter_buffer_size - offset)) ?
nbytes : (dev->scatter_buffer_size - offset);
len = (sg->length < len) ? sg->length : len;
while (crypto4xx_fill_one_page(dev, &addr, &len,
&this_sd, &offset, &nbytes))
;
if (!nbytes)
return;
sg_len -= len;
if (sg_len) {
addr += len;
while (crypto4xx_fill_one_page(dev, &addr,
&sg_len, &this_sd, &offset, &nbytes))
;
}
i++;
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment