@@ -293,8 +293,7 @@ static void ib_device_release(struct device *device)
293
293
WARN_ON (refcount_read (& dev -> refcount ));
294
294
ib_cache_release_one (dev );
295
295
ib_security_release_port_pkey_list (dev );
296
- kfree (dev -> port_pkey_list );
297
- kfree (dev -> port_immutable );
296
+ kfree (dev -> port_data );
298
297
xa_destroy (& dev -> client_data );
299
298
kfree (dev );
300
299
}
@@ -468,27 +467,31 @@ static int verify_immutable(const struct ib_device *dev, u8 port)
468
467
rdma_max_mad_size (dev , port ) != 0 );
469
468
}
470
469
471
- static int read_port_immutable (struct ib_device * device )
470
+ static int setup_port_data (struct ib_device * device )
472
471
{
473
472
unsigned int port ;
474
473
int ret ;
475
474
476
- /**
477
- * device->port_immutable is indexed directly by the port number to make
475
+ /*
476
+ * device->port_data is indexed directly by the port number to make
478
477
* access to this data as efficient as possible.
479
478
*
480
- * Therefore port_immutable is declared as a 1 based array with
481
- * potential empty slots at the beginning.
479
+ * Therefore port_data is declared as a 1 based array with potential
480
+ * empty slots at the beginning.
482
481
*/
483
- device -> port_immutable =
484
- kcalloc (rdma_end_port (device ) + 1 ,
485
- sizeof (* device -> port_immutable ), GFP_KERNEL );
486
- if (!device -> port_immutable )
482
+ device -> port_data = kcalloc (rdma_end_port (device ) + 1 ,
483
+ sizeof (* device -> port_data ), GFP_KERNEL );
484
+ if (!device -> port_data )
487
485
return - ENOMEM ;
488
486
489
487
rdma_for_each_port (device , port ) {
490
- ret = device -> ops .get_port_immutable (
491
- device , port , & device -> port_immutable [port ]);
488
+ struct ib_port_data * pdata = & device -> port_data [port ];
489
+
490
+ spin_lock_init (& pdata -> pkey_list_lock );
491
+ INIT_LIST_HEAD (& pdata -> pkey_list );
492
+
493
+ ret = device -> ops .get_port_immutable (device , port ,
494
+ & pdata -> immutable );
492
495
if (ret )
493
496
return ret ;
494
497
@@ -507,30 +510,6 @@ void ib_get_device_fw_str(struct ib_device *dev, char *str)
507
510
}
508
511
EXPORT_SYMBOL (ib_get_device_fw_str );
509
512
510
- static int setup_port_pkey_list (struct ib_device * device )
511
- {
512
- int i ;
513
-
514
- /**
515
- * device->port_pkey_list is indexed directly by the port number,
516
- * Therefore it is declared as a 1 based array with potential empty
517
- * slots at the beginning.
518
- */
519
- device -> port_pkey_list = kcalloc (rdma_end_port (device ) + 1 ,
520
- sizeof (* device -> port_pkey_list ),
521
- GFP_KERNEL );
522
-
523
- if (!device -> port_pkey_list )
524
- return - ENOMEM ;
525
-
526
- for (i = 0 ; i < (rdma_end_port (device ) + 1 ); i ++ ) {
527
- spin_lock_init (& device -> port_pkey_list [i ].list_lock );
528
- INIT_LIST_HEAD (& device -> port_pkey_list [i ].pkey_list );
529
- }
530
-
531
- return 0 ;
532
- }
533
-
534
513
static void ib_policy_change_task (struct work_struct * work )
535
514
{
536
515
struct ib_device * dev ;
@@ -668,10 +647,9 @@ static int setup_device(struct ib_device *device)
668
647
if (ret )
669
648
return ret ;
670
649
671
- ret = read_port_immutable (device );
650
+ ret = setup_port_data (device );
672
651
if (ret ) {
673
- dev_warn (& device -> dev ,
674
- "Couldn't create per port immutable data\n" );
652
+ dev_warn (& device -> dev , "Couldn't create per-port data\n" );
675
653
return ret ;
676
654
}
677
655
@@ -683,12 +661,6 @@ static int setup_device(struct ib_device *device)
683
661
return ret ;
684
662
}
685
663
686
- ret = setup_port_pkey_list (device );
687
- if (ret ) {
688
- dev_warn (& device -> dev , "Couldn't create per port_pkey_list\n" );
689
- return ret ;
690
- }
691
-
692
664
return 0 ;
693
665
}
694
666
@@ -1221,7 +1193,8 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1221
1193
if (!rdma_protocol_ib (device , port ))
1222
1194
continue ;
1223
1195
1224
- for (i = 0 ; i < device -> port_immutable [port ].gid_tbl_len ; ++ i ) {
1196
+ for (i = 0 ; i < device -> port_data [port ].immutable .gid_tbl_len ;
1197
+ ++ i ) {
1225
1198
ret = rdma_query_gid (device , port , i , & tmp_gid );
1226
1199
if (ret )
1227
1200
return ret ;
@@ -1253,7 +1226,8 @@ int ib_find_pkey(struct ib_device *device,
1253
1226
u16 tmp_pkey ;
1254
1227
int partial_ix = -1 ;
1255
1228
1256
- for (i = 0 ; i < device -> port_immutable [port_num ].pkey_tbl_len ; ++ i ) {
1229
+ for (i = 0 ; i < device -> port_data [port_num ].immutable .pkey_tbl_len ;
1230
+ ++ i ) {
1257
1231
ret = ib_query_pkey (device , port_num , i , & tmp_pkey );
1258
1232
if (ret )
1259
1233
return ret ;
0 commit comments