Commit 4d867beb authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: sun8i-ss - use sg_nents_for_len

When testing with some large SG list, the sun8i-ss drivers always
fallback even if it can handle it.
So use sg_nents_for_len() which permits to see less SGs than needed.
Signed-off-by: default avatarCorentin Labbe <clabbe@baylibre.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent d86e3f37
...@@ -29,7 +29,8 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq) ...@@ -29,7 +29,8 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
if (areq->cryptlen == 0 || areq->cryptlen % 16) if (areq->cryptlen == 0 || areq->cryptlen % 16)
return true; return true;
if (sg_nents(areq->src) > 8 || sg_nents(areq->dst) > 8) if (sg_nents_for_len(areq->src, areq->cryptlen) > 8 ||
sg_nents_for_len(areq->dst, areq->cryptlen) > 8)
return true; return true;
sg = areq->src; sg = areq->src;
...@@ -169,6 +170,8 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) ...@@ -169,6 +170,8 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
int nr_sgs = 0; int nr_sgs = 0;
int nr_sgd = 0; int nr_sgd = 0;
int err = 0; int err = 0;
int nsgs = sg_nents_for_len(areq->src, areq->cryptlen);
int nsgd = sg_nents_for_len(areq->dst, areq->cryptlen);
int i; int i;
algt = container_of(alg, struct sun8i_ss_alg_template, alg.skcipher); algt = container_of(alg, struct sun8i_ss_alg_template, alg.skcipher);
...@@ -201,8 +204,7 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) ...@@ -201,8 +204,7 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
goto theend_key; goto theend_key;
} }
if (areq->src == areq->dst) { if (areq->src == areq->dst) {
nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src), nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_BIDIRECTIONAL);
DMA_BIDIRECTIONAL);
if (nr_sgs <= 0 || nr_sgs > 8) { if (nr_sgs <= 0 || nr_sgs > 8) {
dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs); dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
err = -EINVAL; err = -EINVAL;
...@@ -210,15 +212,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) ...@@ -210,15 +212,13 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
} }
nr_sgd = nr_sgs; nr_sgd = nr_sgs;
} else { } else {
nr_sgs = dma_map_sg(ss->dev, areq->src, sg_nents(areq->src), nr_sgs = dma_map_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
DMA_TO_DEVICE);
if (nr_sgs <= 0 || nr_sgs > 8) { if (nr_sgs <= 0 || nr_sgs > 8) {
dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs); dev_err(ss->dev, "Invalid sg number %d\n", nr_sgs);
err = -EINVAL; err = -EINVAL;
goto theend_iv; goto theend_iv;
} }
nr_sgd = dma_map_sg(ss->dev, areq->dst, sg_nents(areq->dst), nr_sgd = dma_map_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
DMA_FROM_DEVICE);
if (nr_sgd <= 0 || nr_sgd > 8) { if (nr_sgd <= 0 || nr_sgd > 8) {
dev_err(ss->dev, "Invalid sg number %d\n", nr_sgd); dev_err(ss->dev, "Invalid sg number %d\n", nr_sgd);
err = -EINVAL; err = -EINVAL;
...@@ -274,13 +274,10 @@ static int sun8i_ss_cipher(struct skcipher_request *areq) ...@@ -274,13 +274,10 @@ static int sun8i_ss_cipher(struct skcipher_request *areq)
theend_sgs: theend_sgs:
if (areq->src == areq->dst) { if (areq->src == areq->dst) {
dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src), dma_unmap_sg(ss->dev, areq->src, nsgs, DMA_BIDIRECTIONAL);
DMA_BIDIRECTIONAL);
} else { } else {
dma_unmap_sg(ss->dev, areq->src, sg_nents(areq->src), dma_unmap_sg(ss->dev, areq->src, nsgs, DMA_TO_DEVICE);
DMA_TO_DEVICE); dma_unmap_sg(ss->dev, areq->dst, nsgd, DMA_FROM_DEVICE);
dma_unmap_sg(ss->dev, areq->dst, sg_nents(areq->dst),
DMA_FROM_DEVICE);
} }
theend_iv: theend_iv:
......
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