Skip to content

Commit 640eec5

Browse files
montjoieherbertx
authored andcommitted
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 <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 13fb8fd commit 640eec5

File tree

1 file changed

+13
-53
lines changed

1 file changed

+13
-53
lines changed

drivers/crypto/sahara.c

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ struct sahara_aes_reqctx {
173173
* @sg_in_idx: number of hw links
174174
* @in_sg: scatterlist for input data
175175
* @in_sg_chain: scatterlists for chained input data
176-
* @in_sg_chained: specifies if chained scatterlists are used or not
177176
* @total: total number of bytes for transfer
178177
* @last: is this the last block
179178
* @first: is this the first block
@@ -191,7 +190,6 @@ struct sahara_sha_reqctx {
191190
unsigned int sg_in_idx;
192191
struct scatterlist *in_sg;
193192
struct scatterlist in_sg_chain[2];
194-
bool in_sg_chained;
195193
size_t total;
196194
unsigned int last;
197195
unsigned int first;
@@ -801,38 +799,19 @@ static int sahara_sha_hw_links_create(struct sahara_dev *dev,
801799
return -EINVAL;
802800
}
803801

804-
if (rctx->in_sg_chained) {
805-
i = start;
806-
sg = dev->in_sg;
807-
while (sg) {
808-
ret = dma_map_sg(dev->device, sg, 1,
809-
DMA_TO_DEVICE);
810-
if (!ret)
811-
return -EFAULT;
812-
813-
dev->hw_link[i]->len = sg->length;
814-
dev->hw_link[i]->p = sg->dma_address;
802+
sg = dev->in_sg;
803+
ret = dma_map_sg(dev->device, dev->in_sg, dev->nb_in_sg, DMA_TO_DEVICE);
804+
if (!ret)
805+
return -EFAULT;
806+
807+
for (i = start; i < dev->nb_in_sg + start; i++) {
808+
dev->hw_link[i]->len = sg->length;
809+
dev->hw_link[i]->p = sg->dma_address;
810+
if (i == (dev->nb_in_sg + start - 1)) {
811+
dev->hw_link[i]->next = 0;
812+
} else {
815813
dev->hw_link[i]->next = dev->hw_phys_link[i + 1];
816814
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-
}
836815
}
837816
}
838817

@@ -980,7 +959,6 @@ static int sahara_sha_prepare_request(struct ahash_request *req)
980959
rctx->total = req->nbytes + rctx->buf_cnt;
981960
rctx->in_sg = rctx->in_sg_chain;
982961

983-
rctx->in_sg_chained = true;
984962
req->src = rctx->in_sg_chain;
985963
/* only data from previous operation */
986964
} else if (rctx->buf_cnt) {
@@ -991,13 +969,11 @@ static int sahara_sha_prepare_request(struct ahash_request *req)
991969
/* buf was copied into rembuf above */
992970
sg_init_one(rctx->in_sg, rctx->rembuf, rctx->buf_cnt);
993971
rctx->total = rctx->buf_cnt;
994-
rctx->in_sg_chained = false;
995972
/* no data from previous operation */
996973
} else {
997974
rctx->in_sg = req->src;
998975
rctx->total = req->nbytes;
999976
req->src = rctx->in_sg;
1000-
rctx->in_sg_chained = false;
1001977
}
1002978

1003979
/* 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)
1006982
return -EINPROGRESS;
1007983
}
1008984

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-
1026985
static int sahara_sha_process(struct ahash_request *req)
1027986
{
1028987
struct sahara_dev *dev = dev_ptr;
@@ -1062,7 +1021,8 @@ static int sahara_sha_process(struct ahash_request *req)
10621021
}
10631022

10641023
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);
10661026

10671027
memcpy(rctx->context, dev->context_base, rctx->context_size);
10681028

0 commit comments

Comments
 (0)