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

crypto: hisilicon/qm - move 'CURRENT_QM' code to qm.c

Since the code related to 'CURRENT_QM' debugfs is exactly same in
sec/hpre/zip driver, move 'CURRENT_QM' to qm.c to reduce duplicate code.

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

authored by

Weili Qian and committed by
Herbert Xu
c4392b46 45bb26d9

+76 -200
-1
drivers/crypto/hisilicon/hpre/hpre.h
··· 26 26 }; 27 27 28 28 enum hpre_ctrl_dbgfs_file { 29 - HPRE_CURRENT_QM, 30 29 HPRE_CLEAR_ENABLE, 31 30 HPRE_CLUSTER_CTRL, 32 31 HPRE_DEBUG_FILE_NUM,
-61
drivers/crypto/hisilicon/hpre/hpre_main.c
··· 118 118 }; 119 119 120 120 static const char * const hpre_debug_file_name[] = { 121 - [HPRE_CURRENT_QM] = "current_qm", 122 121 [HPRE_CLEAR_ENABLE] = "rdclr_en", 123 122 [HPRE_CLUSTER_CTRL] = "cluster_ctrl", 124 123 }; ··· 406 407 unsigned long offset; 407 408 int i; 408 409 409 - /* clear current_qm */ 410 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 411 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 412 - 413 410 /* clear clusterX/cluster_ctrl */ 414 411 for (i = 0; i < clusters_num; i++) { 415 412 offset = HPRE_CLSTR_BASE + i * HPRE_CLSTR_ADDR_INTRVL; ··· 455 460 struct hpre *hpre = container_of(file->debug, struct hpre, debug); 456 461 457 462 return &hpre->qm; 458 - } 459 - 460 - static u32 hpre_current_qm_read(struct hpre_debugfs_file *file) 461 - { 462 - struct hisi_qm *qm = hpre_file_to_qm(file); 463 - 464 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 465 - } 466 - 467 - static int hpre_current_qm_write(struct hpre_debugfs_file *file, u32 val) 468 - { 469 - struct hisi_qm *qm = hpre_file_to_qm(file); 470 - u32 num_vfs = qm->vfs_num; 471 - u32 vfq_num, tmp; 472 - 473 - if (val > num_vfs) 474 - return -EINVAL; 475 - 476 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 477 - if (val == 0) { 478 - qm->debug.curr_qm_qp_num = qm->qp_num; 479 - } else { 480 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / num_vfs; 481 - if (val == num_vfs) { 482 - qm->debug.curr_qm_qp_num = 483 - qm->ctrl_qp_num - qm->qp_num - (num_vfs - 1) * vfq_num; 484 - } else { 485 - qm->debug.curr_qm_qp_num = vfq_num; 486 - } 487 - } 488 - 489 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 490 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 491 - 492 - tmp = val | 493 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 494 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 495 - 496 - tmp = val | 497 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 498 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 499 - 500 - return 0; 501 463 } 502 464 503 465 static u32 hpre_clear_enable_read(struct hpre_debugfs_file *file) ··· 512 560 513 561 spin_lock_irq(&file->lock); 514 562 switch (file->type) { 515 - case HPRE_CURRENT_QM: 516 - val = hpre_current_qm_read(file); 517 - break; 518 563 case HPRE_CLEAR_ENABLE: 519 564 val = hpre_clear_enable_read(file); 520 565 break; ··· 552 603 553 604 spin_lock_irq(&file->lock); 554 605 switch (file->type) { 555 - case HPRE_CURRENT_QM: 556 - ret = hpre_current_qm_write(file, val); 557 - if (ret) 558 - goto err_input; 559 - break; 560 606 case HPRE_CLEAR_ENABLE: 561 607 ret = hpre_clear_enable_write(file, val); 562 608 if (ret) ··· 689 745 static int hpre_ctrl_debug_init(struct hisi_qm *qm) 690 746 { 691 747 int ret; 692 - 693 - ret = hpre_create_debugfs_file(qm, NULL, HPRE_CURRENT_QM, 694 - HPRE_CURRENT_QM); 695 - if (ret) 696 - return ret; 697 748 698 749 ret = hpre_create_debugfs_file(qm, NULL, HPRE_CLEAR_ENABLE, 699 750 HPRE_CLEAR_ENABLE);
+73 -14
drivers/crypto/hisilicon/qm.c
··· 166 166 #define ACC_AM_ROB_ECC_INT_STS 0x300104 167 167 #define ACC_ROB_ECC_ERR_MULTPL BIT(1) 168 168 169 + #define QM_DFX_MB_CNT_VF 0x104010 170 + #define QM_DFX_DB_CNT_VF 0x104020 171 + #define QM_DFX_SQE_CNT_VF_SQN 0x104030 172 + #define QM_DFX_CQE_CNT_VF_CQN 0x104040 173 + #define QM_DFX_QN_SHIFT 16 174 + #define CURRENT_FUN_MASK GENMASK(5, 0) 175 + #define CURRENT_Q_MASK GENMASK(31, 16) 176 + 169 177 #define POLL_PERIOD 10 170 178 #define POLL_TIMEOUT 1000 171 179 #define WAIT_PERIOD_US_MAX 200 ··· 360 352 }; 361 353 362 354 static const char * const qm_debug_file_name[] = { 355 + [CURRENT_QM] = "current_qm", 363 356 [CURRENT_Q] = "current_q", 364 357 [CLEAR_ENABLE] = "clear_enable", 365 358 }; ··· 929 920 return 0; 930 921 } 931 922 923 + static u32 current_qm_read(struct debugfs_file *file) 924 + { 925 + struct hisi_qm *qm = file_to_qm(file); 926 + 927 + return readl(qm->io_base + QM_DFX_MB_CNT_VF); 928 + } 929 + 930 + static int current_qm_write(struct debugfs_file *file, u32 val) 931 + { 932 + struct hisi_qm *qm = file_to_qm(file); 933 + u32 vfq_num; 934 + u32 tmp; 935 + 936 + if (val > qm->vfs_num) 937 + return -EINVAL; 938 + 939 + /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 940 + if (!val) { 941 + qm->debug.curr_qm_qp_num = qm->qp_num; 942 + } else { 943 + vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num; 944 + 945 + if (val == qm->vfs_num) 946 + qm->debug.curr_qm_qp_num = 947 + qm->ctrl_qp_num - qm->qp_num - 948 + (qm->vfs_num - 1) * vfq_num; 949 + else 950 + qm->debug.curr_qm_qp_num = vfq_num; 951 + } 952 + 953 + writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 954 + writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 955 + 956 + tmp = val | 957 + (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 958 + writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 959 + 960 + tmp = val | 961 + (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 962 + writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 963 + 964 + return 0; 965 + } 966 + 932 967 static ssize_t qm_debug_read(struct file *filp, char __user *buf, 933 968 size_t count, loff_t *pos) 934 969 { ··· 984 931 985 932 mutex_lock(&file->lock); 986 933 switch (index) { 934 + case CURRENT_QM: 935 + val = current_qm_read(file); 936 + break; 987 937 case CURRENT_Q: 988 938 val = current_q_read(file); 989 939 break; ··· 1029 973 1030 974 mutex_lock(&file->lock); 1031 975 switch (index) { 976 + case CURRENT_QM: 977 + ret = current_qm_write(file, val); 978 + break; 1032 979 case CURRENT_Q: 1033 980 ret = current_q_write(file, val); 1034 - if (ret) 1035 - goto err_input; 1036 981 break; 1037 982 case CLEAR_ENABLE: 1038 983 ret = clear_enable_write(file, val); 1039 - if (ret) 1040 - goto err_input; 1041 984 break; 1042 985 default: 1043 986 ret = -EINVAL; 1044 - goto err_input; 1045 987 } 1046 988 mutex_unlock(&file->lock); 1047 989 1048 - return count; 990 + if (ret) 991 + return ret; 1049 992 1050 - err_input: 1051 - mutex_unlock(&file->lock); 1052 - return ret; 993 + return count; 1053 994 } 1054 995 1055 996 static const struct file_operations qm_debug_fops = { ··· 1584 1531 .write = qm_cmd_write, 1585 1532 }; 1586 1533 1587 - static void qm_create_debugfs_file(struct hisi_qm *qm, enum qm_debug_file index) 1534 + static void qm_create_debugfs_file(struct hisi_qm *qm, struct dentry *dir, 1535 + enum qm_debug_file index) 1588 1536 { 1589 - struct dentry *qm_d = qm->debug.qm_d; 1590 1537 struct debugfs_file *file = qm->debug.files + index; 1591 1538 1592 - debugfs_create_file(qm_debug_file_name[index], 0600, qm_d, file, 1539 + debugfs_create_file(qm_debug_file_name[index], 0600, dir, file, 1593 1540 &qm_debug_fops); 1594 1541 1595 1542 file->index = index; ··· 2985 2932 qm->debug.qm_d = qm_d; 2986 2933 2987 2934 /* only show this in PF */ 2988 - if (qm->fun_type == QM_HW_PF) 2935 + if (qm->fun_type == QM_HW_PF) { 2936 + qm_create_debugfs_file(qm, qm->debug.debug_root, CURRENT_QM); 2989 2937 for (i = CURRENT_Q; i < DEBUG_FILE_NUM; i++) 2990 - qm_create_debugfs_file(qm, i); 2938 + qm_create_debugfs_file(qm, qm_d, i); 2939 + } 2991 2940 2992 2941 debugfs_create_file("regs", 0444, qm->debug.qm_d, qm, &qm_regs_fops); 2993 2942 ··· 3016 2961 { 3017 2962 struct qm_dfx_registers *regs; 3018 2963 int i; 2964 + 2965 + /* clear current_qm */ 2966 + writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 2967 + writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 3019 2968 3020 2969 /* clear current_q */ 3021 2970 writel(0x0, qm->io_base + QM_DFX_SQE_CNT_VF_SQN);
+1 -8
drivers/crypto/hisilicon/qm.h
··· 51 51 #define PEH_AXUSER_CFG 0x401001 52 52 #define PEH_AXUSER_CFG_ENABLE 0xffffffff 53 53 54 - #define QM_DFX_MB_CNT_VF 0x104010 55 - #define QM_DFX_DB_CNT_VF 0x104020 56 - #define QM_DFX_SQE_CNT_VF_SQN 0x104030 57 - #define QM_DFX_CQE_CNT_VF_CQN 0x104040 58 - #define QM_DFX_QN_SHIFT 16 59 - #define CURRENT_FUN_MASK GENMASK(5, 0) 60 - #define CURRENT_Q_MASK GENMASK(31, 16) 61 - 62 54 #define QM_AXI_RRESP BIT(0) 63 55 #define QM_AXI_BRESP BIT(1) 64 56 #define QM_ECC_MBIT BIT(2) ··· 115 123 }; 116 124 117 125 enum qm_debug_file { 126 + CURRENT_QM, 118 127 CURRENT_Q, 119 128 CLEAR_ENABLE, 120 129 DEBUG_FILE_NUM,
-1
drivers/crypto/hisilicon/sec2/sec.h
··· 147 147 }; 148 148 149 149 enum sec_debug_file_index { 150 - SEC_CURRENT_QM, 151 150 SEC_CLEAR_ENABLE, 152 151 SEC_DEBUG_FILE_NUM, 153 152 };
+1 -58
drivers/crypto/hisilicon/sec2/sec_main.c
··· 151 151 }; 152 152 153 153 static const char * const sec_dbg_file_name[] = { 154 - [SEC_CURRENT_QM] = "current_qm", 155 154 [SEC_CLEAR_ENABLE] = "clear_enable", 156 155 }; 157 156 ··· 399 400 { 400 401 int i; 401 402 402 - /* clear current_qm */ 403 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 404 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 405 - 406 403 /* clear sec dfx regs */ 407 404 writel(0x1, qm->io_base + SEC_CTRL_CNT_CLR_CE); 408 405 for (i = 0; i < ARRAY_SIZE(sec_dfx_regs); i++) ··· 459 464 writel(val, qm->io_base + SEC_CONTROL_REG); 460 465 } 461 466 462 - static u32 sec_current_qm_read(struct sec_debug_file *file) 463 - { 464 - struct hisi_qm *qm = file->qm; 465 - 466 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 467 - } 468 - 469 - static int sec_current_qm_write(struct sec_debug_file *file, u32 val) 470 - { 471 - struct hisi_qm *qm = file->qm; 472 - u32 vfq_num; 473 - u32 tmp; 474 - 475 - if (val > qm->vfs_num) 476 - return -EINVAL; 477 - 478 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 479 - if (!val) { 480 - qm->debug.curr_qm_qp_num = qm->qp_num; 481 - } else { 482 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num; 483 - 484 - if (val == qm->vfs_num) 485 - qm->debug.curr_qm_qp_num = 486 - qm->ctrl_qp_num - qm->qp_num - 487 - (qm->vfs_num - 1) * vfq_num; 488 - else 489 - qm->debug.curr_qm_qp_num = vfq_num; 490 - } 491 - 492 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 493 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 494 - 495 - tmp = val | 496 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 497 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 498 - 499 - tmp = val | 500 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 501 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 502 - 503 - return 0; 504 - } 505 - 506 467 static u32 sec_clear_enable_read(struct sec_debug_file *file) 507 468 { 508 469 struct hisi_qm *qm = file->qm; ··· 493 542 spin_lock_irq(&file->lock); 494 543 495 544 switch (file->index) { 496 - case SEC_CURRENT_QM: 497 - val = sec_current_qm_read(file); 498 - break; 499 545 case SEC_CLEAR_ENABLE: 500 546 val = sec_clear_enable_read(file); 501 547 break; ··· 533 585 spin_lock_irq(&file->lock); 534 586 535 587 switch (file->index) { 536 - case SEC_CURRENT_QM: 537 - ret = sec_current_qm_write(file, val); 538 - if (ret) 539 - goto err_input; 540 - break; 541 588 case SEC_CLEAR_ENABLE: 542 589 ret = sec_clear_enable_write(file, val); 543 590 if (ret) ··· 617 674 int i; 618 675 619 676 if (qm->pdev->device == SEC_PF_PCI_DEVICE_ID) { 620 - for (i = SEC_CURRENT_QM; i < SEC_DEBUG_FILE_NUM; i++) { 677 + for (i = SEC_CLEAR_ENABLE; i < SEC_DEBUG_FILE_NUM; i++) { 621 678 spin_lock_init(&sec->debug.files[i].lock); 622 679 sec->debug.files[i].index = i; 623 680 sec->debug.files[i].qm = qm;
+1 -57
drivers/crypto/hisilicon/zip/zip_main.c
··· 137 137 }; 138 138 139 139 enum ctrl_debug_file_index { 140 - HZIP_CURRENT_QM, 141 140 HZIP_CLEAR_ENABLE, 142 141 HZIP_DEBUG_FILE_NUM, 143 142 }; 144 143 145 144 static const char * const ctrl_debug_file_name[] = { 146 - [HZIP_CURRENT_QM] = "current_qm", 147 145 [HZIP_CLEAR_ENABLE] = "clear_enable", 148 146 }; 149 147 ··· 360 362 return &hisi_zip->qm; 361 363 } 362 364 363 - static u32 current_qm_read(struct ctrl_debug_file *file) 364 - { 365 - struct hisi_qm *qm = file_to_qm(file); 366 - 367 - return readl(qm->io_base + QM_DFX_MB_CNT_VF); 368 - } 369 - 370 - static int current_qm_write(struct ctrl_debug_file *file, u32 val) 371 - { 372 - struct hisi_qm *qm = file_to_qm(file); 373 - u32 vfq_num; 374 - u32 tmp; 375 - 376 - if (val > qm->vfs_num) 377 - return -EINVAL; 378 - 379 - /* According PF or VF Dev ID to calculation curr_qm_qp_num and store */ 380 - if (val == 0) { 381 - qm->debug.curr_qm_qp_num = qm->qp_num; 382 - } else { 383 - vfq_num = (qm->ctrl_qp_num - qm->qp_num) / qm->vfs_num; 384 - if (val == qm->vfs_num) 385 - qm->debug.curr_qm_qp_num = qm->ctrl_qp_num - 386 - qm->qp_num - (qm->vfs_num - 1) * vfq_num; 387 - else 388 - qm->debug.curr_qm_qp_num = vfq_num; 389 - } 390 - 391 - writel(val, qm->io_base + QM_DFX_MB_CNT_VF); 392 - writel(val, qm->io_base + QM_DFX_DB_CNT_VF); 393 - 394 - tmp = val | 395 - (readl(qm->io_base + QM_DFX_SQE_CNT_VF_SQN) & CURRENT_Q_MASK); 396 - writel(tmp, qm->io_base + QM_DFX_SQE_CNT_VF_SQN); 397 - 398 - tmp = val | 399 - (readl(qm->io_base + QM_DFX_CQE_CNT_VF_CQN) & CURRENT_Q_MASK); 400 - writel(tmp, qm->io_base + QM_DFX_CQE_CNT_VF_CQN); 401 - 402 - return 0; 403 - } 404 - 405 365 static u32 clear_enable_read(struct ctrl_debug_file *file) 406 366 { 407 367 struct hisi_qm *qm = file_to_qm(file); ··· 393 437 394 438 spin_lock_irq(&file->lock); 395 439 switch (file->index) { 396 - case HZIP_CURRENT_QM: 397 - val = current_qm_read(file); 398 - break; 399 440 case HZIP_CLEAR_ENABLE: 400 441 val = clear_enable_read(file); 401 442 break; ··· 430 477 431 478 spin_lock_irq(&file->lock); 432 479 switch (file->index) { 433 - case HZIP_CURRENT_QM: 434 - ret = current_qm_write(file, val); 435 - if (ret) 436 - goto err_input; 437 - break; 438 480 case HZIP_CLEAR_ENABLE: 439 481 ret = clear_enable_write(file, val); 440 482 if (ret) ··· 527 579 struct hisi_zip *zip = container_of(qm, struct hisi_zip, qm); 528 580 int i; 529 581 530 - for (i = HZIP_CURRENT_QM; i < HZIP_DEBUG_FILE_NUM; i++) { 582 + for (i = HZIP_CLEAR_ENABLE; i < HZIP_DEBUG_FILE_NUM; i++) { 531 583 spin_lock_init(&zip->ctrl->files[i].lock); 532 584 zip->ctrl->files[i].ctrl = zip->ctrl; 533 585 zip->ctrl->files[i].index = i; ··· 573 625 static void hisi_zip_debug_regs_clear(struct hisi_qm *qm) 574 626 { 575 627 int i, j; 576 - 577 - /* clear current_qm */ 578 - writel(0x0, qm->io_base + QM_DFX_MB_CNT_VF); 579 - writel(0x0, qm->io_base + QM_DFX_DB_CNT_VF); 580 628 581 629 /* enable register read_clear bit */ 582 630 writel(HZIP_RD_CNT_CLR_CE_EN, qm->io_base + HZIP_SOFT_CTRL_CNT_CLR_CE);