diff options
author | LABBE Corentin <clabbe.montjoie@gmail.com> | 2015-09-23 07:55:28 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-10-01 09:56:56 -0400 |
commit | 640eec52abbcb962804e8ff0c69e9802b0b726c0 (patch) | |
tree | 182ee1002ce83dbdfd65ca5cef610e87b8ce585f | |
parent | 13fb8fd7a81923f7a64b4e688fe0bdaf1ea26adf (diff) |
crypto: sahara - dma_map_sg can handle chained SG
The sahara driver use two dma_map_sg path according to SG are chained
or not.
Since dma_map_sg can handle both case, clean the code with all
references to sg chained.
Thus removing the sahara_sha_unmap_sg function.
Signed-off-by: LABBE Corentin <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/sahara.c | 66 |
1 files changed, 13 insertions, 53 deletions
diff --git a/drivers/crypto/sahara.c b/drivers/crypto/sahara.c index cea241125938..804c0f5ce63a 100644 --- a/drivers/crypto/sahara.c +++ b/drivers/crypto/sahara.c | |||
@@ -173,7 +173,6 @@ struct sahara_aes_reqctx { | |||
173 | * @sg_in_idx: number of hw links | 173 | * @sg_in_idx: number of hw links |
174 | * @in_sg: scatterlist for input data | 174 | * @in_sg: scatterlist for input data |
175 | * @in_sg_chain: scatterlists for chained input data | 175 | * @in_sg_chain: scatterlists for chained input data |
176 | * @in_sg_chained: specifies if chained scatterlists are used or not | ||
177 | * @total: total number of bytes for transfer | 176 | * @total: total number of bytes for transfer |
178 | * @last: is this the last block | 177 | * @last: is this the last block |
179 | * @first: is this the first block | 178 | * @first: is this the first block |
@@ -191,7 +190,6 @@ struct sahara_sha_reqctx { | |||
191 | unsigned int sg_in_idx; | 190 | unsigned int sg_in_idx; |
192 | struct scatterlist *in_sg; | 191 | struct scatterlist *in_sg; |
193 | struct scatterlist in_sg_chain[2]; | 192 | struct scatterlist in_sg_chain[2]; |
194 | bool in_sg_chained; | ||
195 | size_t total; | 193 | size_t total; |
196 | unsigned int last; | 194 | unsigned int last; |
197 | unsigned int first; | 195 | unsigned int first; |
@@ -801,38 +799,19 @@ static int sahara_sha_hw_links_create(struct sahara_dev *dev, | |||
801 | return -EINVAL; | 799 | return -EINVAL; |
802 | } | 800 | } |
803 | 801 | ||
804 | if (rctx->in_sg_chained) { | 802 | sg = dev->in_sg; |
805 | i = start; | 803 | ret = dma_map_sg(dev->device, dev->in_sg, dev->nb_in_sg, DMA_TO_DEVICE); |
806 | sg = dev->in_sg; | 804 | if (!ret) |
807 | while (sg) { | 805 | return -EFAULT; |
808 | ret = dma_map_sg(dev->device, sg, 1, | 806 | |
809 | DMA_TO_DEVICE); | 807 | for (i = start; i < dev->nb_in_sg + start; i++) { |
810 | if (!ret) | 808 | dev->hw_link[i]->len = sg->length; |
811 | return -EFAULT; | 809 | dev->hw_link[i]->p = sg->dma_address; |
812 | 810 | if (i == (dev->nb_in_sg + start - 1)) { | |
813 | dev->hw_link[i]->len = sg->length; | 811 | dev->hw_link[i]->next = 0; |
814 | dev->hw_link[i]->p = sg->dma_address; | 812 | } else { |
815 | dev->hw_link[i]->next = dev->hw_phys_link[i + 1]; | 813 | dev->hw_link[i]->next = dev->hw_phys_link[i + 1]; |
816 | sg = sg_next(sg); | 814 | sg = sg_next(sg); |
817 | i += 1; | ||
818 | } | ||
819 | dev->hw_link[i-1]->next = 0; | ||
820 | } else { | ||
821 | sg = dev->in_sg; | ||
822 | ret = dma_map_sg(dev->device, dev->in_sg, dev->nb_in_sg, | ||
823 | DMA_TO_DEVICE); | ||
824 | if (!ret) | ||
825 | return -EFAULT; | ||
826 | |||
827 | for (i = start; i < dev->nb_in_sg + start; i++) { | ||
828 | dev->hw_link[i]->len = sg->length; | ||
829 | dev->hw_link[i]->p = sg->dma_address; | ||
830 | if (i == (dev->nb_in_sg + start - 1)) { | ||
831 | dev->hw_link[i]->next = 0; | ||
832 | } else { | ||
833 | dev->hw_link[i]->next = dev->hw_phys_link[i + 1]; | ||
834 | sg = sg_next(sg); | ||
835 | } | ||
836 | } | 815 | } |
837 | } | 816 | } |
838 | 817 | ||
@@ -980,7 +959,6 @@ static int sahara_sha_prepare_request(struct ahash_request *req) | |||
980 | rctx->total = req->nbytes + rctx->buf_cnt; | 959 | rctx->total = req->nbytes + rctx->buf_cnt; |
981 | rctx->in_sg = rctx->in_sg_chain; | 960 | rctx->in_sg = rctx->in_sg_chain; |
982 | 961 | ||
983 | rctx->in_sg_chained = true; | ||
984 | req->src = rctx->in_sg_chain; | 962 | req->src = rctx->in_sg_chain; |
985 | /* only data from previous operation */ | 963 | /* only data from previous operation */ |
986 | } else if (rctx->buf_cnt) { | 964 | } else if (rctx->buf_cnt) { |
@@ -991,13 +969,11 @@ static int sahara_sha_prepare_request(struct ahash_request *req) | |||
991 | /* buf was copied into rembuf above */ | 969 | /* buf was copied into rembuf above */ |
992 | sg_init_one(rctx->in_sg, rctx->rembuf, rctx->buf_cnt); | 970 | sg_init_one(rctx->in_sg, rctx->rembuf, rctx->buf_cnt); |
993 | rctx->total = rctx->buf_cnt; | 971 | rctx->total = rctx->buf_cnt; |
994 | rctx->in_sg_chained = false; | ||
995 | /* no data from previous operation */ | 972 | /* no data from previous operation */ |
996 | } else { | 973 | } else { |
997 | rctx->in_sg = req->src; | 974 | rctx->in_sg = req->src; |
998 | rctx->total = req->nbytes; | 975 | rctx->total = req->nbytes; |
999 | req->src = rctx->in_sg; | 976 | req->src = rctx->in_sg; |
1000 | rctx->in_sg_chained = false; | ||
1001 | } | 977 | } |
1002 | 978 | ||
1003 | /* on next call, we only have the remaining data in the buffer */ | 979 | /* on next call, we only have the remaining data in the buffer */ |
@@ -1006,23 +982,6 @@ static int sahara_sha_prepare_request(struct ahash_request *req) | |||
1006 | return -EINPROGRESS; | 982 | return -EINPROGRESS; |
1007 | } | 983 | } |
1008 | 984 | ||
1009 | static void sahara_sha_unmap_sg(struct sahara_dev *dev, | ||
1010 | struct sahara_sha_reqctx *rctx) | ||
1011 | { | ||
1012 | struct scatterlist *sg; | ||
1013 | |||
1014 | if (rctx->in_sg_chained) { | ||
1015 | sg = dev->in_sg; | ||
1016 | while (sg) { | ||
1017 | dma_unmap_sg(dev->device, sg, 1, DMA_TO_DEVICE); | ||
1018 | sg = sg_next(sg); | ||
1019 | } | ||
1020 | } else { | ||
1021 | dma_unmap_sg(dev->device, dev->in_sg, dev->nb_in_sg, | ||
1022 | DMA_TO_DEVICE); | ||
1023 | } | ||
1024 | } | ||
1025 | |||
1026 | static int sahara_sha_process(struct ahash_request *req) | 985 | static int sahara_sha_process(struct ahash_request *req) |
1027 | { | 986 | { |
1028 | struct sahara_dev *dev = dev_ptr; | 987 | struct sahara_dev *dev = dev_ptr; |
@@ -1062,7 +1021,8 @@ static int sahara_sha_process(struct ahash_request *req) | |||
1062 | } | 1021 | } |
1063 | 1022 | ||
1064 | if (rctx->sg_in_idx) | 1023 | if (rctx->sg_in_idx) |
1065 | sahara_sha_unmap_sg(dev, rctx); | 1024 | dma_unmap_sg(dev->device, dev->in_sg, dev->nb_in_sg, |
1025 | DMA_TO_DEVICE); | ||
1066 | 1026 | ||
1067 | memcpy(rctx->context, dev->context_base, rctx->context_size); | 1027 | memcpy(rctx->context, dev->context_base, rctx->context_size); |
1068 | 1028 | ||