@@ -90,8 +90,7 @@ struct sec_hw_error {
90
90
91
91
static const char sec_name [] = "hisi_sec2" ;
92
92
static struct dentry * sec_debugfs_root ;
93
- static LIST_HEAD (sec_list );
94
- static DEFINE_MUTEX (sec_list_lock );
93
+ static struct hisi_qm_list sec_devices ;
95
94
96
95
static const struct sec_hw_error sec_hw_errors [] = {
97
96
{.int_msk = BIT (0 ), .msg = "sec_axi_rresp_err_rint" },
@@ -106,37 +105,6 @@ static const struct sec_hw_error sec_hw_errors[] = {
106
105
{ /* sentinel */ }
107
106
};
108
107
109
- struct sec_dev * sec_find_device (int node )
110
- {
111
- #define SEC_NUMA_MAX_DISTANCE 100
112
- int min_distance = SEC_NUMA_MAX_DISTANCE ;
113
- int dev_node = 0 , free_qp_num = 0 ;
114
- struct sec_dev * sec , * ret = NULL ;
115
- struct hisi_qm * qm ;
116
- struct device * dev ;
117
-
118
- mutex_lock (& sec_list_lock );
119
- list_for_each_entry (sec , & sec_list , list ) {
120
- qm = & sec -> qm ;
121
- dev = & qm -> pdev -> dev ;
122
- #ifdef CONFIG_NUMA
123
- dev_node = dev -> numa_node ;
124
- if (dev_node < 0 )
125
- dev_node = 0 ;
126
- #endif
127
- if (node_distance (dev_node , node ) < min_distance ) {
128
- free_qp_num = hisi_qm_get_free_qp_num (qm );
129
- if (free_qp_num >= sec -> ctx_q_num ) {
130
- ret = sec ;
131
- min_distance = node_distance (dev_node , node );
132
- }
133
- }
134
- }
135
- mutex_unlock (& sec_list_lock );
136
-
137
- return ret ;
138
- }
139
-
140
108
static const char * const sec_dbg_file_name [] = {
141
109
[SEC_CURRENT_QM ] = "current_qm" ,
142
110
[SEC_CLEAR_ENABLE ] = "clear_enable" ,
@@ -239,27 +207,39 @@ static u32 ctx_q_num = SEC_CTX_Q_NUM_DEF;
239
207
module_param_cb (ctx_q_num , & sec_ctx_q_num_ops , & ctx_q_num , 0444 );
240
208
MODULE_PARM_DESC (ctx_q_num , "Queue num in ctx (24 default, 2, 4, ..., 32)" );
241
209
210
+ void sec_destroy_qps (struct hisi_qp * * qps , int qp_num )
211
+ {
212
+ hisi_qm_free_qps (qps , qp_num );
213
+ kfree (qps );
214
+ }
215
+
216
+ struct hisi_qp * * sec_create_qps (void )
217
+ {
218
+ int node = cpu_to_node (smp_processor_id ());
219
+ u32 ctx_num = ctx_q_num ;
220
+ struct hisi_qp * * qps ;
221
+ int ret ;
222
+
223
+ qps = kcalloc (ctx_num , sizeof (struct hisi_qp * ), GFP_KERNEL );
224
+ if (!qps )
225
+ return NULL ;
226
+
227
+ ret = hisi_qm_alloc_qps_node (& sec_devices , ctx_num , 0 , node , qps );
228
+ if (!ret )
229
+ return qps ;
230
+
231
+ kfree (qps );
232
+ return NULL ;
233
+ }
234
+
235
+
242
236
static const struct pci_device_id sec_dev_ids [] = {
243
237
{ PCI_DEVICE (PCI_VENDOR_ID_HUAWEI , SEC_PF_PCI_DEVICE_ID ) },
244
238
{ PCI_DEVICE (PCI_VENDOR_ID_HUAWEI , SEC_VF_PCI_DEVICE_ID ) },
245
239
{ 0 , }
246
240
};
247
241
MODULE_DEVICE_TABLE (pci , sec_dev_ids );
248
242
249
- static inline void sec_add_to_list (struct sec_dev * sec )
250
- {
251
- mutex_lock (& sec_list_lock );
252
- list_add_tail (& sec -> list , & sec_list );
253
- mutex_unlock (& sec_list_lock );
254
- }
255
-
256
- static inline void sec_remove_from_list (struct sec_dev * sec )
257
- {
258
- mutex_lock (& sec_list_lock );
259
- list_del (& sec -> list );
260
- mutex_unlock (& sec_list_lock );
261
- }
262
-
263
243
static u8 sec_get_endian (struct sec_dev * sec )
264
244
{
265
245
struct hisi_qm * qm = & sec -> qm ;
@@ -889,7 +869,7 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
889
869
if (ret )
890
870
pci_warn (pdev , "Failed to init debugfs!\n" );
891
871
892
- sec_add_to_list ( sec );
872
+ hisi_qm_add_to_list ( qm , & sec_devices );
893
873
894
874
ret = sec_register_to_crypto ();
895
875
if (ret < 0 ) {
@@ -900,7 +880,7 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
900
880
return 0 ;
901
881
902
882
err_remove_from_list :
903
- sec_remove_from_list ( sec );
883
+ hisi_qm_del_from_list ( qm , & sec_devices );
904
884
sec_debugfs_exit (sec );
905
885
hisi_qm_stop (qm );
906
886
@@ -1024,7 +1004,7 @@ static void sec_remove(struct pci_dev *pdev)
1024
1004
1025
1005
sec_unregister_from_crypto ();
1026
1006
1027
- sec_remove_from_list ( sec );
1007
+ hisi_qm_del_from_list ( qm , & sec_devices );
1028
1008
1029
1009
if (qm -> fun_type == QM_HW_PF && sec -> num_vfs )
1030
1010
(void )sec_sriov_disable (pdev );
@@ -1071,6 +1051,7 @@ static int __init sec_init(void)
1071
1051
{
1072
1052
int ret ;
1073
1053
1054
+ hisi_qm_init_list (& sec_devices );
1074
1055
sec_register_debugfs ();
1075
1056
1076
1057
ret = pci_register_driver (& sec_pci_driver );
0 commit comments