@@ -293,8 +293,7 @@ static void ib_device_release(struct device *device)
293293 WARN_ON (refcount_read (& dev -> refcount ));
294294 ib_cache_release_one (dev );
295295 ib_security_release_port_pkey_list (dev );
296- kfree (dev -> port_pkey_list );
297- kfree (dev -> port_immutable );
296+ kfree (dev -> port_data );
298297 xa_destroy (& dev -> client_data );
299298 kfree (dev );
300299}
@@ -468,27 +467,31 @@ static int verify_immutable(const struct ib_device *dev, u8 port)
468467 rdma_max_mad_size (dev , port ) != 0 );
469468}
470469
471- static int read_port_immutable (struct ib_device * device )
470+ static int setup_port_data (struct ib_device * device )
472471{
473472 unsigned int port ;
474473 int ret ;
475474
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
478477 * access to this data as efficient as possible.
479478 *
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.
482481 */
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 )
487485 return - ENOMEM ;
488486
489487 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 );
492495 if (ret )
493496 return ret ;
494497
@@ -507,30 +510,6 @@ void ib_get_device_fw_str(struct ib_device *dev, char *str)
507510}
508511EXPORT_SYMBOL (ib_get_device_fw_str );
509512
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-
534513static void ib_policy_change_task (struct work_struct * work )
535514{
536515 struct ib_device * dev ;
@@ -668,10 +647,9 @@ static int setup_device(struct ib_device *device)
668647 if (ret )
669648 return ret ;
670649
671- ret = read_port_immutable (device );
650+ ret = setup_port_data (device );
672651 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" );
675653 return ret ;
676654 }
677655
@@ -683,12 +661,6 @@ static int setup_device(struct ib_device *device)
683661 return ret ;
684662 }
685663
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-
692664 return 0 ;
693665}
694666
@@ -1221,7 +1193,8 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,
12211193 if (!rdma_protocol_ib (device , port ))
12221194 continue ;
12231195
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 ) {
12251198 ret = rdma_query_gid (device , port , i , & tmp_gid );
12261199 if (ret )
12271200 return ret ;
@@ -1253,7 +1226,8 @@ int ib_find_pkey(struct ib_device *device,
12531226 u16 tmp_pkey ;
12541227 int partial_ix = -1 ;
12551228
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 ) {
12571231 ret = ib_query_pkey (device , port_num , i , & tmp_pkey );
12581232 if (ret )
12591233 return ret ;
0 commit comments