diff options
author | Ryder Lee <ryder.lee@mediatek.com> | 2017-03-09 03:11:15 +0100 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-03-16 10:58:53 +0100 |
commit | 3d21c41f7e9b51c70d37b316f11cf5cce9dd3311 (patch) | |
tree | 57a1fccf9f7d5e9399a2c8af74f4b9e743795249 /drivers/crypto/mediatek/mtk-sha.c | |
parent | crypto: mediatek - make mtk_sha_xmit() more generic (diff) | |
download | linux-3d21c41f7e9b51c70d37b316f11cf5cce9dd3311.tar.xz linux-3d21c41f7e9b51c70d37b316f11cf5cce9dd3311.zip |
crypto: mediatek - simplify descriptor ring management
This patch replaces cmd_pos/res_pos with pointer cmd_next/res_next.
In old code, we must to add one to shift ring to the next segment, and
then use this value to caculate current offset from ring base for each
DMA operation. Now these pointers helps us to simplify flow, so we just
need to move pointers and check the boundaries of ring.
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/mediatek/mtk-sha.c')
-rw-r--r-- | drivers/crypto/mediatek/mtk-sha.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/drivers/crypto/mediatek/mtk-sha.c b/drivers/crypto/mediatek/mtk-sha.c index ef6fb201f70d..0884d6243cbc 100644 --- a/drivers/crypto/mediatek/mtk-sha.c +++ b/drivers/crypto/mediatek/mtk-sha.c @@ -152,6 +152,21 @@ static inline void mtk_sha_write(struct mtk_cryp *cryp, writel_relaxed(value, cryp->base + offset); } +static inline void mtk_sha_ring_shift(struct mtk_ring *ring, + struct mtk_desc **cmd_curr, + struct mtk_desc **res_curr, + int *count) +{ + *cmd_curr = ring->cmd_next++; + *res_curr = ring->res_next++; + (*count)++; + + if (ring->cmd_next == ring->cmd_base + MTK_DESC_NUM) { + ring->cmd_next = ring->cmd_base; + ring->res_next = ring->res_base; + } +} + static struct mtk_cryp *mtk_sha_find_dev(struct mtk_sha_ctx *tctx) { struct mtk_cryp *cryp = NULL; @@ -426,8 +441,7 @@ static int mtk_sha_xmit(struct mtk_cryp *cryp, struct mtk_sha_rec *sha, { struct mtk_sha_reqctx *ctx = ahash_request_ctx(sha->req); struct mtk_ring *ring = cryp->ring[sha->id]; - struct mtk_desc *cmd = ring->cmd_base + ring->cmd_pos; - struct mtk_desc *res = ring->res_base + ring->res_pos; + struct mtk_desc *cmd, *res; int err, count = 0; err = mtk_sha_info_update(cryp, sha, len1, len2); @@ -435,6 +449,8 @@ static int mtk_sha_xmit(struct mtk_cryp *cryp, struct mtk_sha_rec *sha, return err; /* Fill in the command/result descriptors */ + mtk_sha_ring_shift(ring, &cmd, &res, &count); + res->hdr = MTK_DESC_FIRST | MTK_DESC_BUF_LEN(len1); cmd->hdr = MTK_DESC_FIRST | MTK_DESC_BUF_LEN(len1) | MTK_DESC_CT_LEN(ctx->ct_size); @@ -443,25 +459,12 @@ static int mtk_sha_xmit(struct mtk_cryp *cryp, struct mtk_sha_rec *sha, cmd->ct_hdr = ctx->ct_hdr; cmd->tfm = cpu_to_le32(ctx->tfm_dma); - if (++ring->cmd_pos == MTK_DESC_NUM) - ring->cmd_pos = 0; - - ring->res_pos = ring->cmd_pos; - count++; - if (len2) { - cmd = ring->cmd_base + ring->cmd_pos; - res = ring->res_base + ring->res_pos; + mtk_sha_ring_shift(ring, &cmd, &res, &count); res->hdr = MTK_DESC_BUF_LEN(len2); cmd->hdr = MTK_DESC_BUF_LEN(len2); cmd->buf = cpu_to_le32(addr2); - - if (++ring->cmd_pos == MTK_DESC_NUM) - ring->cmd_pos = 0; - - ring->res_pos = ring->cmd_pos; - count++; } cmd->hdr |= MTK_DESC_LAST; |