Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crytpo: sun8i-ce - factor out prepare/unprepare from sun8i_ce_hash_run()

In order to make the ahash code more clear and modular, split the
monolithic sun8i_ce_hash_run() callback into two parts, prepare and
unprepare (therefore aligning it with the sun8i-ce skcipher code).

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ovidiu Panait and committed by
Herbert Xu
27d5a2d1 c3a61eea

+46 -16
+46 -16
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c
··· 313 313 return j; 314 314 } 315 315 316 - int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq) 316 + static int sun8i_ce_hash_prepare(struct ahash_request *areq, struct ce_task *cet) 317 317 { 318 - struct ahash_request *areq = container_of(breq, struct ahash_request, base); 319 318 struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); 320 319 struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg); 321 320 struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq); 322 321 struct sun8i_ce_alg_template *algt; 323 322 struct sun8i_ce_dev *ce; 324 - struct sun8i_ce_flow *chan; 325 - struct ce_task *cet; 326 323 struct scatterlist *sg; 327 - int nr_sgs, flow, err; 324 + int nr_sgs, err; 328 325 unsigned int len; 329 326 u32 common; 330 327 u64 byte_count; ··· 342 345 343 346 bf = (__le32 *)rctx->pad; 344 347 345 - flow = rctx->flow; 346 - chan = &ce->chanlist[flow]; 347 - 348 348 if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) 349 349 algt->stat_req++; 350 350 351 351 dev_dbg(ce->dev, "%s %s len=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->nbytes); 352 352 353 - cet = chan->tl; 354 353 memset(cet, 0, sizeof(struct ce_task)); 355 354 356 - cet->t_id = cpu_to_le32(flow); 355 + cet->t_id = cpu_to_le32(rctx->flow); 357 356 common = ce->variant->alg_hash[algt->ce_algo_id]; 358 357 common |= CE_COMM_INT; 359 358 cet->t_common_ctl = cpu_to_le32(common); ··· 427 434 else 428 435 cet->t_dlen = cpu_to_le32(areq->nbytes / 4 + j); 429 436 430 - err = sun8i_ce_run_task(ce, flow, crypto_ahash_alg_name(tfm)); 431 - 432 - dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE); 437 + return 0; 433 438 434 439 err_unmap_result: 435 440 dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len, 436 441 DMA_FROM_DEVICE); 437 - if (!err) 438 - memcpy(areq->result, rctx->result, crypto_ahash_digestsize(tfm)); 439 442 440 443 err_unmap_src: 441 444 dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); 442 445 443 446 err_out: 447 + return err; 448 + } 449 + 450 + static void sun8i_ce_hash_unprepare(struct ahash_request *areq, 451 + struct ce_task *cet) 452 + { 453 + struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq); 454 + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); 455 + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); 456 + struct sun8i_ce_dev *ce = ctx->ce; 457 + 458 + dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE); 459 + dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len, 460 + DMA_FROM_DEVICE); 461 + dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE); 462 + } 463 + 464 + int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req) 465 + { 466 + struct ahash_request *areq = ahash_request_cast(async_req); 467 + struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq); 468 + struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm); 469 + struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq); 470 + struct sun8i_ce_dev *ce = ctx->ce; 471 + struct sun8i_ce_flow *chan; 472 + int err; 473 + 474 + chan = &ce->chanlist[rctx->flow]; 475 + 476 + err = sun8i_ce_hash_prepare(areq, chan->tl); 477 + if (err) 478 + return err; 479 + 480 + err = sun8i_ce_run_task(ce, rctx->flow, crypto_ahash_alg_name(tfm)); 481 + 482 + sun8i_ce_hash_unprepare(areq, chan->tl); 483 + 484 + if (!err) 485 + memcpy(areq->result, rctx->result, 486 + crypto_ahash_digestsize(tfm)); 487 + 444 488 local_bh_disable(); 445 - crypto_finalize_hash_request(engine, breq, err); 489 + crypto_finalize_hash_request(engine, async_req, err); 446 490 local_bh_enable(); 447 491 448 492 return 0;