|
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[] = {
|
@@ -196,43 +195,17 @@ static u32 hpre_pf_q_num = HPRE_PF_DEF_Q_NUM;
|
196 | 195 | module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444);
|
197 | 196 | MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)");
|
198 | 197 |
|
199 |
| -static inline void hpre_add_to_list(struct hpre *hpre) |
| 198 | +struct hisi_qp *hpre_create_qp(void) |
200 | 199 | {
|
201 |
| - mutex_lock(&hpre_list_lock); |
202 |
| - list_add_tail(&hpre->list, &hpre_list); |
203 |
| - mutex_unlock(&hpre_list_lock); |
204 |
| -} |
205 |
| - |
206 |
| -static inline void hpre_remove_from_list(struct hpre *hpre) |
207 |
| -{ |
208 |
| - mutex_lock(&hpre_list_lock); |
209 |
| - list_del(&hpre->list); |
210 |
| - mutex_unlock(&hpre_list_lock); |
211 |
| -} |
212 |
| - |
213 |
| -struct hpre *hpre_find_device(int node) |
214 |
| -{ |
215 |
| - struct hpre *hpre, *ret = NULL; |
216 |
| - int min_distance = INT_MAX; |
217 |
| - struct device *dev; |
218 |
| - int dev_node = 0; |
| 200 | + int node = cpu_to_node(smp_processor_id()); |
| 201 | + struct hisi_qp *qp = NULL; |
| 202 | + int ret; |
219 | 203 |
|
220 |
| - mutex_lock(&hpre_list_lock); |
221 |
| - list_for_each_entry(hpre, &hpre_list, list) { |
222 |
| - dev = &hpre->qm.pdev->dev; |
223 |
| -#ifdef CONFIG_NUMA |
224 |
| - dev_node = dev->numa_node; |
225 |
| - if (dev_node < 0) |
226 |
| - dev_node = 0; |
227 |
| -#endif |
228 |
| - if (node_distance(dev_node, node) < min_distance) { |
229 |
| - ret = hpre; |
230 |
| - min_distance = node_distance(dev_node, node); |
231 |
| - } |
232 |
| - } |
233 |
| - mutex_unlock(&hpre_list_lock); |
| 204 | + ret = hisi_qm_alloc_qps_node(&hpre_devices, 1, 0, node, &qp); |
| 205 | + if (!ret) |
| 206 | + return qp; |
234 | 207 |
|
235 |
| - return ret; |
| 208 | + return NULL; |
236 | 209 | }
|
237 | 210 |
|
238 | 211 | static int hpre_cfg_by_dsm(struct hisi_qm *qm)
|
@@ -799,17 +772,17 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
799 | 772 | if (ret)
|
800 | 773 | dev_warn(&pdev->dev, "init debugfs fail!\n");
|
801 | 774 |
|
802 |
| - hpre_add_to_list(hpre); |
| 775 | + hisi_qm_add_to_list(qm, &hpre_devices); |
803 | 776 |
|
804 | 777 | ret = hpre_algs_register();
|
805 | 778 | if (ret < 0) {
|
806 |
| - hpre_remove_from_list(hpre); |
807 | 779 | pci_err(pdev, "fail to register algs to crypto!\n");
|
808 | 780 | goto err_with_qm_start;
|
809 | 781 | }
|
810 | 782 | return 0;
|
811 | 783 |
|
812 | 784 | err_with_qm_start:
|
| 785 | + hisi_qm_del_from_list(qm, &hpre_devices); |
813 | 786 | hisi_qm_stop(qm);
|
814 | 787 |
|
815 | 788 | err_with_err_init:
|
@@ -929,7 +902,7 @@ static void hpre_remove(struct pci_dev *pdev)
|
929 | 902 | int ret;
|
930 | 903 |
|
931 | 904 | hpre_algs_unregister();
|
932 |
| - hpre_remove_from_list(hpre); |
| 905 | + hisi_qm_del_from_list(qm, &hpre_devices); |
933 | 906 | if (qm->fun_type == QM_HW_PF && hpre->num_vfs != 0) {
|
934 | 907 | ret = hpre_sriov_disable(pdev);
|
935 | 908 | if (ret) {
|
@@ -979,6 +952,7 @@ static int __init hpre_init(void)
|
979 | 952 | {
|
980 | 953 | int ret;
|
981 | 954 |
|
| 955 | + hisi_qm_init_list(&hpre_devices); |
982 | 956 | hpre_register_debugfs();
|
983 | 957 |
|
984 | 958 | ret = pci_register_driver(&hpre_pci_driver);
|
|
0 commit comments