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.

crypto: hisilicon - consolidate qp creation and start in hisi_qm_alloc_qps_node

Consolidate the creation and start of qp into the function
hisi_qm_alloc_qps_node. This change eliminates the need for
each module to perform these steps in two separate phases
(creation and start).

Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Weili Qian <qianweili@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Chenghai Huang and committed by
Herbert Xu
72f3bbeb 8cd9b608

+66 -96
+4 -36
drivers/crypto/hisilicon/hpre/hpre_crypto.c
··· 156 156 ktime_get_ts64(&hpre_req->req_time); 157 157 } 158 158 159 - static struct hisi_qp *hpre_get_qp_and_start(u8 type) 160 - { 161 - struct hisi_qp *qp; 162 - int ret; 163 - 164 - qp = hpre_create_qp(type); 165 - if (!qp) { 166 - pr_err("Can not create hpre qp!\n"); 167 - return ERR_PTR(-ENODEV); 168 - } 169 - 170 - ret = hisi_qm_start_qp(qp, 0); 171 - if (ret < 0) { 172 - hisi_qm_free_qps(&qp, 1); 173 - pci_err(qp->qm->pdev, "Can not start qp!\n"); 174 - return ERR_PTR(-EINVAL); 175 - } 176 - 177 - return qp; 178 - } 179 - 180 159 static int hpre_get_data_dma_addr(struct hpre_asym_request *hpre_req, 181 160 struct scatterlist *data, unsigned int len, 182 161 int is_src, dma_addr_t *tmp) ··· 295 316 296 317 static void hpre_ctx_clear(struct hpre_ctx *ctx, bool is_clear_all) 297 318 { 298 - if (is_clear_all) { 319 + if (is_clear_all) 299 320 hisi_qm_free_qps(&ctx->qp, 1); 300 - } 301 321 302 322 ctx->crt_g2_mode = false; 303 323 ctx->key_sz = 0; ··· 381 403 struct hisi_qp *qp; 382 404 struct hpre *hpre; 383 405 384 - qp = hpre_get_qp_and_start(type); 385 - if (IS_ERR(qp)) 386 - return PTR_ERR(qp); 406 + qp = hpre_create_qp(type); 407 + if (!qp) 408 + return -ENODEV; 387 409 388 - qp->qp_ctx = ctx; 389 410 qp->req_cb = hpre_alg_cb; 390 411 ctx->qp = qp; 391 412 ctx->dev = &qp->qm->pdev->dev; ··· 573 596 { 574 597 struct device *dev = ctx->dev; 575 598 unsigned int sz = ctx->key_sz; 576 - 577 - if (is_clear_all) 578 - hisi_qm_stop_qp(ctx->qp); 579 599 580 600 if (ctx->dh.g) { 581 601 dma_free_coherent(dev, sz, ctx->dh.g, ctx->dh.dma_g); ··· 914 940 unsigned int half_key_sz = ctx->key_sz >> 1; 915 941 struct device *dev = ctx->dev; 916 942 917 - if (is_clear_all) 918 - hisi_qm_stop_qp(ctx->qp); 919 - 920 943 if (ctx->rsa.pubkey) { 921 944 dma_free_coherent(dev, ctx->key_sz << 1, 922 945 ctx->rsa.pubkey, ctx->rsa.dma_pubkey); ··· 1082 1111 struct device *dev = ctx->dev; 1083 1112 unsigned int sz = ctx->key_sz; 1084 1113 unsigned int shift = sz << 1; 1085 - 1086 - if (is_clear_all) 1087 - hisi_qm_stop_qp(ctx->qp); 1088 1114 1089 1115 if (ctx->ecdh.p) { 1090 1116 /* ecdh: p->a->k->b */
+56 -14
drivers/crypto/hisilicon/qm.c
··· 3553 3553 } 3554 3554 EXPORT_SYMBOL_GPL(hisi_qm_dev_err_uninit); 3555 3555 3556 + static void qm_release_qp_nolock(struct hisi_qp *qp) 3557 + { 3558 + struct hisi_qm *qm = qp->qm; 3559 + 3560 + qm->qp_in_used--; 3561 + idr_remove(&qm->qp_idr, qp->qp_id); 3562 + } 3563 + 3556 3564 /** 3557 3565 * hisi_qm_free_qps() - free multiple queue pairs. 3558 3566 * @qps: The queue pairs need to be freed. ··· 3573 3565 if (!qps || qp_num <= 0) 3574 3566 return; 3575 3567 3576 - for (i = qp_num - 1; i >= 0; i--) 3577 - hisi_qm_release_qp(qps[i]); 3568 + down_write(&qps[0]->qm->qps_lock); 3569 + 3570 + for (i = qp_num - 1; i >= 0; i--) { 3571 + qm_stop_qp_nolock(qps[i]); 3572 + qm_release_qp_nolock(qps[i]); 3573 + } 3574 + 3575 + up_write(&qps[0]->qm->qps_lock); 3576 + qm_pm_put_sync(qps[0]->qm); 3578 3577 } 3579 3578 EXPORT_SYMBOL_GPL(hisi_qm_free_qps); 3580 3579 ··· 3593 3578 list_del(&res->list); 3594 3579 kfree(res); 3595 3580 } 3581 + } 3582 + 3583 + static int qm_get_and_start_qp(struct hisi_qm *qm, int qp_num, struct hisi_qp **qps, u8 *alg_type) 3584 + { 3585 + int i, ret; 3586 + 3587 + ret = qm_pm_get_sync(qm); 3588 + if (ret) 3589 + return ret; 3590 + 3591 + down_write(&qm->qps_lock); 3592 + for (i = 0; i < qp_num; i++) { 3593 + qps[i] = qm_create_qp_nolock(qm, alg_type[i]); 3594 + if (IS_ERR(qps[i])) { 3595 + ret = -ENODEV; 3596 + goto stop_and_free; 3597 + } 3598 + 3599 + ret = qm_start_qp_nolock(qps[i], 0); 3600 + if (ret) { 3601 + qm_release_qp_nolock(qps[i]); 3602 + goto stop_and_free; 3603 + } 3604 + } 3605 + up_write(&qm->qps_lock); 3606 + 3607 + return 0; 3608 + 3609 + stop_and_free: 3610 + for (i--; i >= 0; i--) { 3611 + qm_stop_qp_nolock(qps[i]); 3612 + qm_release_qp_nolock(qps[i]); 3613 + } 3614 + up_write(&qm->qps_lock); 3615 + qm_pm_put_sync(qm); 3616 + 3617 + return ret; 3596 3618 } 3597 3619 3598 3620 static int hisi_qm_sort_devices(int node, struct list_head *head, ··· 3685 3633 struct hisi_qm_resource *tmp; 3686 3634 int ret = -ENODEV; 3687 3635 LIST_HEAD(head); 3688 - int i; 3689 3636 3690 3637 if (!qps || !qm_list || qp_num <= 0) 3691 3638 return -EINVAL; ··· 3696 3645 } 3697 3646 3698 3647 list_for_each_entry(tmp, &head, list) { 3699 - for (i = 0; i < qp_num; i++) { 3700 - qps[i] = hisi_qm_create_qp(tmp->qm, alg_type[i]); 3701 - if (IS_ERR(qps[i])) { 3702 - hisi_qm_free_qps(qps, i); 3703 - break; 3704 - } 3705 - } 3706 - 3707 - if (i == qp_num) { 3708 - ret = 0; 3648 + ret = qm_get_and_start_qp(tmp->qm, qp_num, qps, alg_type); 3649 + if (!ret) 3709 3650 break; 3710 - } 3711 3651 } 3712 3652 3713 3653 mutex_unlock(&qm_list->lock);
-8
drivers/crypto/hisilicon/sec2/sec_crypto.c
··· 626 626 627 627 qp_ctx = &ctx->qp_ctx[qp_ctx_id]; 628 628 qp = ctx->qps[qp_ctx_id]; 629 - qp->qp_ctx = qp_ctx; 630 629 qp_ctx->qp = qp; 631 630 qp_ctx->ctx = ctx; 632 631 ··· 643 644 if (ret) 644 645 goto err_destroy_idr; 645 646 646 - ret = hisi_qm_start_qp(qp, 0); 647 - if (ret < 0) 648 - goto err_resource_free; 649 - 650 647 return 0; 651 648 652 - err_resource_free: 653 - sec_free_qp_ctx_resource(ctx, qp_ctx); 654 649 err_destroy_idr: 655 650 idr_destroy(&qp_ctx->req_idr); 656 651 return ret; ··· 653 660 static void sec_release_qp_ctx(struct sec_ctx *ctx, 654 661 struct sec_qp_ctx *qp_ctx) 655 662 { 656 - hisi_qm_stop_qp(qp_ctx->qp); 657 663 sec_free_qp_ctx_resource(ctx, qp_ctx); 658 664 idr_destroy(&qp_ctx->req_idr); 659 665 }
+6 -37
drivers/crypto/hisilicon/zip/zip_crypto.c
··· 352 352 return ret; 353 353 } 354 354 355 - static int hisi_zip_start_qp(struct hisi_qp *qp, struct hisi_zip_qp_ctx *qp_ctx, 356 - int alg_type, int req_type) 357 - { 358 - struct device *dev = &qp->qm->pdev->dev; 359 - int ret; 360 - 361 - qp->alg_type = alg_type; 362 - qp->qp_ctx = qp_ctx; 363 - 364 - ret = hisi_qm_start_qp(qp, 0); 365 - if (ret < 0) { 366 - dev_err(dev, "failed to start qp (%d)!\n", ret); 367 - return ret; 368 - } 369 - 370 - qp_ctx->qp = qp; 371 - 372 - return 0; 373 - } 374 - 375 - static void hisi_zip_release_qp(struct hisi_zip_qp_ctx *qp_ctx) 376 - { 377 - hisi_qm_stop_qp(qp_ctx->qp); 378 - hisi_qm_free_qps(&qp_ctx->qp, 1); 379 - } 380 - 381 355 static const struct hisi_zip_sqe_ops hisi_zip_ops = { 382 356 .sqe_type = 0x3, 383 357 .fill_addr = hisi_zip_fill_addr, ··· 370 396 struct hisi_zip_qp_ctx *qp_ctx; 371 397 u8 alg_type[HZIP_CTX_Q_NUM]; 372 398 struct hisi_zip *hisi_zip; 373 - int ret, i, j; 399 + int ret, i; 374 400 375 401 /* alg_type = 0 for compress, 1 for decompress in hw sqe */ 376 402 for (i = 0; i < HZIP_CTX_Q_NUM; i++) ··· 387 413 for (i = 0; i < HZIP_CTX_Q_NUM; i++) { 388 414 qp_ctx = &hisi_zip_ctx->qp_ctx[i]; 389 415 qp_ctx->ctx = hisi_zip_ctx; 390 - ret = hisi_zip_start_qp(qps[i], qp_ctx, i, req_type); 391 - if (ret) { 392 - for (j = i - 1; j >= 0; j--) 393 - hisi_qm_stop_qp(hisi_zip_ctx->qp_ctx[j].qp); 394 - 395 - hisi_qm_free_qps(qps, HZIP_CTX_Q_NUM); 396 - return ret; 397 - } 398 - 399 416 qp_ctx->zip_dev = hisi_zip; 400 417 qp_ctx->req_type = req_type; 418 + qp_ctx->qp = qps[i]; 401 419 } 402 420 403 421 hisi_zip_ctx->ops = &hisi_zip_ops; ··· 399 433 400 434 static void hisi_zip_ctx_exit(struct hisi_zip_ctx *hisi_zip_ctx) 401 435 { 436 + struct hisi_qp *qps[HZIP_CTX_Q_NUM] = { NULL }; 402 437 int i; 403 438 404 439 for (i = 0; i < HZIP_CTX_Q_NUM; i++) 405 - hisi_zip_release_qp(&hisi_zip_ctx->qp_ctx[i]); 440 + qps[i] = hisi_zip_ctx->qp_ctx[i].qp; 441 + 442 + hisi_qm_free_qps(qps, HZIP_CTX_Q_NUM); 406 443 } 407 444 408 445 static int hisi_zip_create_req_q(struct hisi_zip_ctx *ctx)
-1
include/linux/hisi_acc_qm.h
··· 466 466 467 467 struct hisi_qp_status qp_status; 468 468 struct hisi_qp_ops *hw_ops; 469 - void *qp_ctx; 470 469 void (*req_cb)(struct hisi_qp *qp, void *data); 471 470 void (*event_cb)(struct hisi_qp *qp); 472 471