@@ -314,14 +314,13 @@ static void make_default_gid(struct net_device *dev, union ib_gid *gid)
314314int ib_cache_gid_add (struct ib_device * ib_dev , u8 port ,
315315 union ib_gid * gid , struct ib_gid_attr * attr )
316316{
317- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
318317 struct ib_gid_table * table ;
319318 int ix ;
320319 int ret = 0 ;
321320 struct net_device * idev ;
322321 int empty ;
323322
324- table = ports_table [port - rdma_start_port (ib_dev )];
323+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
325324
326325 if (!memcmp (gid , & zgid , sizeof (* gid )))
327326 return - EINVAL ;
@@ -369,11 +368,10 @@ int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
369368int ib_cache_gid_del (struct ib_device * ib_dev , u8 port ,
370369 union ib_gid * gid , struct ib_gid_attr * attr )
371370{
372- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
373371 struct ib_gid_table * table ;
374372 int ix ;
375373
376- table = ports_table [port - rdma_start_port (ib_dev )];
374+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
377375
378376 mutex_lock (& table -> lock );
379377 write_lock_irq (& table -> rwlock );
@@ -399,12 +397,11 @@ int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
399397int ib_cache_gid_del_all_netdev_gids (struct ib_device * ib_dev , u8 port ,
400398 struct net_device * ndev )
401399{
402- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
403400 struct ib_gid_table * table ;
404401 int ix ;
405402 bool deleted = false;
406403
407- table = ports_table [port - rdma_start_port (ib_dev )];
404+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
408405
409406 mutex_lock (& table -> lock );
410407 write_lock_irq (& table -> rwlock );
@@ -428,10 +425,9 @@ int ib_cache_gid_del_all_netdev_gids(struct ib_device *ib_dev, u8 port,
428425static int __ib_cache_gid_get (struct ib_device * ib_dev , u8 port , int index ,
429426 union ib_gid * gid , struct ib_gid_attr * attr )
430427{
431- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
432428 struct ib_gid_table * table ;
433429
434- table = ports_table [port - rdma_start_port (ib_dev )];
430+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
435431
436432 if (index < 0 || index >= table -> sz )
437433 return - EINVAL ;
@@ -455,14 +451,13 @@ static int _ib_cache_gid_table_find(struct ib_device *ib_dev,
455451 unsigned long mask ,
456452 u8 * port , u16 * index )
457453{
458- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
459454 struct ib_gid_table * table ;
460455 u8 p ;
461456 int local_index ;
462457 unsigned long flags ;
463458
464459 for (p = 0 ; p < ib_dev -> phys_port_cnt ; p ++ ) {
465- table = ports_table [p ];
460+ table = ib_dev -> cache . ports [p ]. gid ;
466461 read_lock_irqsave (& table -> rwlock , flags );
467462 local_index = find_gid (table , gid , val , false, mask , NULL );
468463 if (local_index >= 0 ) {
@@ -503,7 +498,6 @@ int ib_find_cached_gid_by_port(struct ib_device *ib_dev,
503498 u16 * index )
504499{
505500 int local_index ;
506- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
507501 struct ib_gid_table * table ;
508502 unsigned long mask = GID_ATTR_FIND_MASK_GID |
509503 GID_ATTR_FIND_MASK_GID_TYPE ;
@@ -514,7 +508,7 @@ int ib_find_cached_gid_by_port(struct ib_device *ib_dev,
514508 port > rdma_end_port (ib_dev ))
515509 return - ENOENT ;
516510
517- table = ports_table [port - rdma_start_port (ib_dev )];
511+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
518512
519513 if (ndev )
520514 mask |= GID_ATTR_FIND_MASK_NETDEV ;
@@ -562,21 +556,18 @@ static int ib_cache_gid_find_by_filter(struct ib_device *ib_dev,
562556 void * context ,
563557 u16 * index )
564558{
565- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
566559 struct ib_gid_table * table ;
567560 unsigned int i ;
568561 unsigned long flags ;
569562 bool found = false;
570563
571- if (!ports_table )
572- return - EOPNOTSUPP ;
573564
574565 if (port < rdma_start_port (ib_dev ) ||
575566 port > rdma_end_port (ib_dev ) ||
576567 !rdma_protocol_roce (ib_dev , port ))
577568 return - EPROTONOSUPPORT ;
578569
579- table = ports_table [port - rdma_start_port (ib_dev )];
570+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
580571
581572 read_lock_irqsave (& table -> rwlock , flags );
582573 for (i = 0 ; i < table -> sz ; i ++ ) {
@@ -668,14 +659,13 @@ void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
668659 unsigned long gid_type_mask ,
669660 enum ib_cache_gid_default_mode mode )
670661{
671- struct ib_gid_table * * ports_table = ib_dev -> cache .gid_cache ;
672662 union ib_gid gid ;
673663 struct ib_gid_attr gid_attr ;
674664 struct ib_gid_attr zattr_type = zattr ;
675665 struct ib_gid_table * table ;
676666 unsigned int gid_type ;
677667
678- table = ports_table [port - rdma_start_port (ib_dev )];
668+ table = ib_dev -> cache . ports [port - rdma_start_port (ib_dev )]. gid ;
679669
680670 make_default_gid (ndev , & gid );
681671 memset (& gid_attr , 0 , sizeof (gid_attr ));
@@ -766,71 +756,64 @@ static int gid_table_reserve_default(struct ib_device *ib_dev, u8 port,
766756static int _gid_table_setup_one (struct ib_device * ib_dev )
767757{
768758 u8 port ;
769- struct ib_gid_table * * table ;
759+ struct ib_gid_table * table ;
770760 int err = 0 ;
771761
772- table = kcalloc (ib_dev -> phys_port_cnt , sizeof (* table ), GFP_KERNEL );
773- if (!table )
774- return - ENOMEM ;
775-
776762 for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ ) {
777763 u8 rdma_port = port + rdma_start_port (ib_dev );
778764
779- table [ port ] =
765+ table =
780766 alloc_gid_table (
781767 ib_dev -> port_immutable [rdma_port ].gid_tbl_len );
782- if (!table [ port ] ) {
768+ if (!table ) {
783769 err = - ENOMEM ;
784770 goto rollback_table_setup ;
785771 }
786772
787773 err = gid_table_reserve_default (ib_dev ,
788774 port + rdma_start_port (ib_dev ),
789- table [ port ] );
775+ table );
790776 if (err )
791777 goto rollback_table_setup ;
778+ ib_dev -> cache .ports [port ].gid = table ;
792779 }
793780
794- ib_dev -> cache .gid_cache = table ;
795781 return 0 ;
796782
797783rollback_table_setup :
798784 for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ ) {
785+ table = ib_dev -> cache .ports [port ].gid ;
786+
799787 cleanup_gid_table_port (ib_dev , port + rdma_start_port (ib_dev ),
800- table [ port ] );
801- release_gid_table (table [ port ] );
788+ table );
789+ release_gid_table (table );
802790 }
803791
804- kfree (table );
805792 return err ;
806793}
807794
808795static void gid_table_release_one (struct ib_device * ib_dev )
809796{
810- struct ib_gid_table * * table = ib_dev -> cache . gid_cache ;
797+ struct ib_gid_table * table ;
811798 u8 port ;
812799
813- if (!table )
814- return ;
815-
816- for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ )
817- release_gid_table (table [port ]);
818-
819- kfree (table );
820- ib_dev -> cache .gid_cache = NULL ;
800+ for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ ) {
801+ table = ib_dev -> cache .ports [port ].gid ;
802+ release_gid_table (table );
803+ ib_dev -> cache .ports [port ].gid = NULL ;
804+ }
821805}
822806
823807static void gid_table_cleanup_one (struct ib_device * ib_dev )
824808{
825- struct ib_gid_table * * table = ib_dev -> cache . gid_cache ;
809+ struct ib_gid_table * table ;
826810 u8 port ;
827811
828- if (!table )
829- return ;
830-
831- for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ )
812+ for (port = 0 ; port < ib_dev -> phys_port_cnt ; port ++ ) {
813+ table = ib_dev -> cache .ports [port ].gid ;
832814 cleanup_gid_table_port (ib_dev , port + rdma_start_port (ib_dev ),
833- table [port ]);
815+ table );
816+ }
834817}
835818
836819static int gid_table_setup_one (struct ib_device * ib_dev )
@@ -860,12 +843,12 @@ int ib_get_cached_gid(struct ib_device *device,
860843{
861844 int res ;
862845 unsigned long flags ;
863- struct ib_gid_table * * ports_table = device -> cache .gid_cache ;
864- struct ib_gid_table * table = ports_table [port_num - rdma_start_port (device )];
846+ struct ib_gid_table * table ;
865847
866848 if (port_num < rdma_start_port (device ) || port_num > rdma_end_port (device ))
867849 return - EINVAL ;
868850
851+ table = device -> cache .ports [port_num - rdma_start_port (device )].gid ;
869852 read_lock_irqsave (& table -> rwlock , flags );
870853 res = __ib_cache_gid_get (device , port_num , index , gid , gid_attr );
871854 read_unlock_irqrestore (& table -> rwlock , flags );
@@ -917,7 +900,7 @@ int ib_get_cached_pkey(struct ib_device *device,
917900
918901 read_lock_irqsave (& device -> cache .lock , flags );
919902
920- cache = device -> cache .pkey_cache [port_num - rdma_start_port (device )];
903+ cache = device -> cache .ports [port_num - rdma_start_port (device )]. pkey ;
921904
922905 if (index < 0 || index >= cache -> table_len )
923906 ret = - EINVAL ;
@@ -946,7 +929,7 @@ int ib_find_cached_pkey(struct ib_device *device,
946929
947930 read_lock_irqsave (& device -> cache .lock , flags );
948931
949- cache = device -> cache .pkey_cache [port_num - rdma_start_port (device )];
932+ cache = device -> cache .ports [port_num - rdma_start_port (device )]. pkey ;
950933
951934 * index = -1 ;
952935
@@ -986,7 +969,7 @@ int ib_find_exact_cached_pkey(struct ib_device *device,
986969
987970 read_lock_irqsave (& device -> cache .lock , flags );
988971
989- cache = device -> cache .pkey_cache [port_num - rdma_start_port (device )];
972+ cache = device -> cache .ports [port_num - rdma_start_port (device )]. pkey ;
990973
991974 * index = -1 ;
992975
@@ -1014,7 +997,7 @@ int ib_get_cached_lmc(struct ib_device *device,
1014997 return - EINVAL ;
1015998
1016999 read_lock_irqsave (& device -> cache .lock , flags );
1017- * lmc = device -> cache .lmc_cache [port_num - rdma_start_port (device )];
1000+ * lmc = device -> cache .ports [port_num - rdma_start_port (device )]. lmc ;
10181001 read_unlock_irqrestore (& device -> cache .lock , flags );
10191002
10201003 return ret ;
@@ -1032,7 +1015,8 @@ int ib_get_cached_port_state(struct ib_device *device,
10321015 return - EINVAL ;
10331016
10341017 read_lock_irqsave (& device -> cache .lock , flags );
1035- * port_state = device -> cache .port_state_cache [port_num - rdma_start_port (device )];
1018+ * port_state = device -> cache .ports [port_num
1019+ - rdma_start_port (device )].port_state ;
10361020 read_unlock_irqrestore (& device -> cache .lock , flags );
10371021
10381022 return ret ;
@@ -1051,14 +1035,13 @@ static void ib_cache_update(struct ib_device *device,
10511035 int i ;
10521036 int ret ;
10531037 struct ib_gid_table * table ;
1054- struct ib_gid_table * * ports_table = device -> cache .gid_cache ;
10551038 bool use_roce_gid_table =
10561039 rdma_cap_roce_gid_table (device , port );
10571040
10581041 if (port < rdma_start_port (device ) || port > rdma_end_port (device ))
10591042 return ;
10601043
1061- table = ports_table [port - rdma_start_port (device )];
1044+ table = device -> cache . ports [port - rdma_start_port (device )]. gid ;
10621045
10631046 tprops = kmalloc (sizeof * tprops , GFP_KERNEL );
10641047 if (!tprops )
@@ -1110,9 +1093,10 @@ static void ib_cache_update(struct ib_device *device,
11101093
11111094 write_lock_irq (& device -> cache .lock );
11121095
1113- old_pkey_cache = device -> cache .pkey_cache [port - rdma_start_port (device )];
1096+ old_pkey_cache = device -> cache .ports [port -
1097+ rdma_start_port (device )].pkey ;
11141098
1115- device -> cache .pkey_cache [port - rdma_start_port (device )] = pkey_cache ;
1099+ device -> cache .ports [port - rdma_start_port (device )]. pkey = pkey_cache ;
11161100 if (!use_roce_gid_table ) {
11171101 write_lock (& table -> rwlock );
11181102 for (i = 0 ; i < gid_cache -> table_len ; i ++ ) {
@@ -1122,8 +1106,8 @@ static void ib_cache_update(struct ib_device *device,
11221106 write_unlock (& table -> rwlock );
11231107 }
11241108
1125- device -> cache .lmc_cache [port - rdma_start_port (device )] = tprops -> lmc ;
1126- device -> cache .port_state_cache [port - rdma_start_port (device )] =
1109+ device -> cache .ports [port - rdma_start_port (device )]. lmc = tprops -> lmc ;
1110+ device -> cache .ports [port - rdma_start_port (device )]. port_state =
11271111 tprops -> state ;
11281112
11291113 write_unlock_irq (& device -> cache .lock );
@@ -1177,26 +1161,17 @@ int ib_cache_setup_one(struct ib_device *device)
11771161
11781162 rwlock_init (& device -> cache .lock );
11791163
1180- device -> cache .pkey_cache =
1181- kzalloc (sizeof * device -> cache .pkey_cache *
1164+ device -> cache .ports =
1165+ kzalloc (sizeof ( * device -> cache .ports ) *
11821166 (rdma_end_port (device ) - rdma_start_port (device ) + 1 ), GFP_KERNEL );
1183- device -> cache .lmc_cache = kmalloc (sizeof * device -> cache .lmc_cache *
1184- (rdma_end_port (device ) -
1185- rdma_start_port (device ) + 1 ),
1186- GFP_KERNEL );
1187- device -> cache .port_state_cache = kmalloc (sizeof * device -> cache .port_state_cache *
1188- (rdma_end_port (device ) -
1189- rdma_start_port (device ) + 1 ),
1190- GFP_KERNEL );
1191- if (!device -> cache .pkey_cache || !device -> cache .port_state_cache ||
1192- !device -> cache .lmc_cache ) {
1167+ if (!device -> cache .ports ) {
11931168 err = - ENOMEM ;
1194- goto free ;
1169+ goto out ;
11951170 }
11961171
11971172 err = gid_table_setup_one (device );
11981173 if (err )
1199- goto free ;
1174+ goto out ;
12001175
12011176 for (p = 0 ; p <= rdma_end_port (device ) - rdma_start_port (device ); ++ p )
12021177 ib_cache_update (device , p + rdma_start_port (device ));
@@ -1211,10 +1186,7 @@ int ib_cache_setup_one(struct ib_device *device)
12111186
12121187err :
12131188 gid_table_cleanup_one (device );
1214- free :
1215- kfree (device -> cache .pkey_cache );
1216- kfree (device -> cache .lmc_cache );
1217- kfree (device -> cache .port_state_cache );
1189+ out :
12181190 return err ;
12191191}
12201192
@@ -1228,15 +1200,11 @@ void ib_cache_release_one(struct ib_device *device)
12281200 * all the device's resources when the cache could no
12291201 * longer be accessed.
12301202 */
1231- if (device -> cache .pkey_cache )
1232- for (p = 0 ;
1233- p <= rdma_end_port (device ) - rdma_start_port (device ); ++ p )
1234- kfree (device -> cache .pkey_cache [p ]);
1203+ for (p = 0 ; p <= rdma_end_port (device ) - rdma_start_port (device ); ++ p )
1204+ kfree (device -> cache .ports [p ].pkey );
12351205
12361206 gid_table_release_one (device );
1237- kfree (device -> cache .pkey_cache );
1238- kfree (device -> cache .lmc_cache );
1239- kfree (device -> cache .port_state_cache );
1207+ kfree (device -> cache .ports );
12401208}
12411209
12421210void ib_cache_cleanup_one (struct ib_device * device )
0 commit comments