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: Corentin Labbe <clabbe@baylibre.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
d86e3f37a6
commit
4d867bebdc
|
@ -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)
|
||||||
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)
|
||||||
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)
|
||||||
}
|
}
|
||||||
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 @@ sgd_next:
|
||||||
|
|
||||||
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:
|
||||||
|
|
Loading…
Reference in New Issue