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

crypto: hisilicon/hpre - Optimize finding hpre device process

Optimize finding hpre device process according to priority of numa
distance.

Signed-off-by: Hui Tang <tanghui20@huawei.com>
Signed-off-by: Shukun Tan <tanshukun1@huawei.com>
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>
Reviewed-by: Zaibo Xu <xuzaibo@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Hui Tang and committed by
Herbert Xu
0f4146fa 18f1ab3f

+20 -55
+1 -2
drivers/crypto/hisilicon/hpre/hpre.h
··· 46 46 47 47 struct hpre { 48 48 struct hisi_qm qm; 49 - struct list_head list; 50 49 struct hpre_debug debug; 51 50 u32 num_vfs; 52 51 unsigned long status; ··· 75 76 __le32 rsvd1[_HPRE_SQE_ALIGN_EXT]; 76 77 }; 77 78 78 - struct hpre *hpre_find_device(int node); 79 + struct hisi_qp *hpre_create_qp(void); 79 80 int hpre_algs_register(void); 80 81 void hpre_algs_unregister(void); 81 82
+6 -14
drivers/crypto/hisilicon/hpre/hpre_crypto.c
··· 147 147 static struct hisi_qp *hpre_get_qp_and_start(void) 148 148 { 149 149 struct hisi_qp *qp; 150 - struct hpre *hpre; 151 150 int ret; 152 151 153 - /* find the proper hpre device, which is near the current CPU core */ 154 - hpre = hpre_find_device(cpu_to_node(smp_processor_id())); 155 - if (!hpre) { 156 - pr_err("Can not find proper hpre device!\n"); 157 - return ERR_PTR(-ENODEV); 158 - } 159 - 160 - qp = hisi_qm_create_qp(&hpre->qm, 0); 161 - if (IS_ERR(qp)) { 162 - pci_err(hpre->qm.pdev, "Can not create qp!\n"); 152 + qp = hpre_create_qp(); 153 + if (!qp) { 154 + pr_err("Can not create hpre qp!\n"); 163 155 return ERR_PTR(-ENODEV); 164 156 } 165 157 166 158 ret = hisi_qm_start_qp(qp, 0); 167 159 if (ret < 0) { 168 - hisi_qm_release_qp(qp); 169 - pci_err(hpre->qm.pdev, "Can not start qp!\n"); 160 + hisi_qm_free_qps(&qp, 1); 161 + pci_err(qp->qm->pdev, "Can not start qp!\n"); 170 162 return ERR_PTR(-EINVAL); 171 163 } 172 164 ··· 330 338 if (is_clear_all) { 331 339 idr_destroy(&ctx->req_idr); 332 340 kfree(ctx->req_list); 333 - hisi_qm_release_qp(ctx->qp); 341 + hisi_qm_free_qps(&ctx->qp, 1); 334 342 } 335 343 336 344 ctx->crt_g2_mode = false;
+13 -39
drivers/crypto/hisilicon/hpre/hpre_main.c
··· 82 82 83 83 #define HPRE_VIA_MSI_DSM 1 84 84 85 - static LIST_HEAD(hpre_list); 86 - static DEFINE_MUTEX(hpre_list_lock); 85 + static struct hisi_qm_list hpre_devices; 87 86 static const char hpre_name[] = "hisi_hpre"; 88 87 static struct dentry *hpre_debugfs_root; 89 88 static const struct pci_device_id hpre_dev_ids[] = { ··· 195 196 module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444); 196 197 MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)"); 197 198 198 - static inline void hpre_add_to_list(struct hpre *hpre) 199 + struct hisi_qp *hpre_create_qp(void) 199 200 { 200 - mutex_lock(&hpre_list_lock); 201 - list_add_tail(&hpre->list, &hpre_list); 202 - mutex_unlock(&hpre_list_lock); 203 - } 201 + int node = cpu_to_node(smp_processor_id()); 202 + struct hisi_qp *qp = NULL; 203 + int ret; 204 204 205 - static inline void hpre_remove_from_list(struct hpre *hpre) 206 - { 207 - mutex_lock(&hpre_list_lock); 208 - list_del(&hpre->list); 209 - mutex_unlock(&hpre_list_lock); 210 - } 205 + ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp); 206 + if (!ret) 207 + return qp; 211 208 212 - struct hpre *hpre_find_device(int node) 213 - { 214 - struct hpre *hpre, *ret = NULL; 215 - int min_distance = INT_MAX; 216 - struct device *dev; 217 - int dev_node = 0; 218 - 219 - mutex_lock(&hpre_list_lock); 220 - list_for_each_entry(hpre, &hpre_list, list) { 221 - dev = &hpre->qm.pdev->dev; 222 - #ifdef CONFIG_NUMA 223 - dev_node = dev->numa_node; 224 - if (dev_node < 0) 225 - dev_node = 0; 226 - #endif 227 - if (node_distance(dev_node, node) < min_distance) { 228 - ret = hpre; 229 - min_distance = node_distance(dev_node, node); 230 - } 231 - } 232 - mutex_unlock(&hpre_list_lock); 233 - 234 - return ret; 209 + return NULL; 235 210 } 236 211 237 212 static int hpre_cfg_by_dsm(struct hisi_qm *qm) ··· 772 799 if (ret) 773 800 dev_warn(&pdev->dev, "init debugfs fail!\n"); 774 801 775 - hpre_add_to_list(hpre); 802 + hisi_qm_add_to_list(qm, &hpre_devices); 776 803 777 804 ret = hpre_algs_register(); 778 805 if (ret < 0) { 779 - hpre_remove_from_list(hpre); 780 806 pci_err(pdev, "fail to register algs to crypto!\n"); 781 807 goto err_with_qm_start; 782 808 } 783 809 return 0; 784 810 785 811 err_with_qm_start: 812 + hisi_qm_del_from_list(qm, &hpre_devices); 786 813 hisi_qm_stop(qm); 787 814 788 815 err_with_err_init: ··· 902 929 int ret; 903 930 904 931 hpre_algs_unregister(); 905 - hpre_remove_from_list(hpre); 932 + hisi_qm_del_from_list(qm, &hpre_devices); 906 933 if (qm->fun_type == QM_HW_PF && hpre->num_vfs != 0) { 907 934 ret = hpre_sriov_disable(pdev); 908 935 if (ret) { ··· 952 979 { 953 980 int ret; 954 981 982 + hisi_qm_init_list(&hpre_devices); 955 983 hpre_register_debugfs(); 956 984 957 985 ret = pci_register_driver(&hpre_pci_driver);