Skip to content

Commit 1c36cf9

Browse files
paravmellanoxjgunthorpe
authored andcommitted
IB/core: Store default GID property per-table instead of per-entry
There are at max one or two default GIDs for RoCE. Instead of storing a default GID property for all the GIDs, store default GID indices as individual bit per table. This allows a future simplification to get rid of the GID property field. Signed-off-by: Parav Pandit <parav@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent a1a4cae commit 1c36cf9

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

drivers/infiniband/core/cache.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ enum gid_attr_find_mask {
6868

6969
enum gid_table_entry_props {
7070
GID_TABLE_ENTRY_INVALID = 1UL << 0,
71-
GID_TABLE_ENTRY_DEFAULT = 1UL << 1,
7271
};
7372

7473
struct ib_gid_table_entry {
@@ -79,7 +78,7 @@ struct ib_gid_table_entry {
7978
};
8079

8180
struct ib_gid_table {
82-
int sz;
81+
int sz;
8382
/* In RoCE, adding a GID to the table requires:
8483
* (a) Find if this GID is already exists.
8584
* (b) Find a free space.
@@ -94,10 +93,12 @@ struct ib_gid_table {
9493
* rwlock. readers must hold only rwlock. All writers must be in a
9594
* sleepable context.
9695
*/
97-
struct mutex lock;
96+
struct mutex lock;
9897
/* rwlock protects data_vec[ix]->props. */
99-
rwlock_t rwlock;
100-
struct ib_gid_table_entry *data_vec;
98+
rwlock_t rwlock;
99+
/* bit field, each bit indicates the index of default GID */
100+
u32 default_gid_indices;
101+
struct ib_gid_table_entry *data_vec;
101102
};
102103

103104
static void dispatch_gid_change_event(struct ib_device *ib_dev, u8 port)
@@ -135,6 +136,19 @@ bool rdma_is_zero_gid(const union ib_gid *gid)
135136
}
136137
EXPORT_SYMBOL(rdma_is_zero_gid);
137138

139+
/** is_gid_index_default - Check if a given index belongs to
140+
* reserved default GIDs or not.
141+
* @table: GID table pointer
142+
* @index: Index to check in GID table
143+
* Returns true if index is one of the reserved default GID index otherwise
144+
* returns false.
145+
*/
146+
static bool is_gid_index_default(const struct ib_gid_table *table,
147+
unsigned int index)
148+
{
149+
return index < 32 && (BIT(index) & table->default_gid_indices);
150+
}
151+
138152
int ib_cache_gid_parse_type_str(const char *buf)
139153
{
140154
unsigned int i;
@@ -308,7 +322,7 @@ static int find_gid(struct ib_gid_table *table, const union ib_gid *gid,
308322
if (pempty && empty < 0) {
309323
if (data->props & GID_TABLE_ENTRY_INVALID &&
310324
(default_gid ==
311-
!!(data->props & GID_TABLE_ENTRY_DEFAULT))) {
325+
is_gid_index_default(table, curr_index))) {
312326
/*
313327
* Found an invalid (free) entry; allocate it.
314328
* If default GID is requested, then our
@@ -346,8 +360,7 @@ static int find_gid(struct ib_gid_table *table, const union ib_gid *gid,
346360
continue;
347361

348362
if (mask & GID_ATTR_FIND_MASK_DEFAULT &&
349-
!!(data->props & GID_TABLE_ENTRY_DEFAULT) !=
350-
default_gid)
363+
is_gid_index_default(table, curr_index) != default_gid)
351364
continue;
352365

353366
found = curr_index;
@@ -795,11 +808,9 @@ static void gid_table_reserve_default(struct ib_device *ib_dev, u8 port,
795808

796809
roce_gid_type_mask = roce_gid_type_mask_support(ib_dev, port);
797810
num_default_gids = hweight_long(roce_gid_type_mask);
798-
for (i = 0; i < num_default_gids && i < table->sz; i++) {
799-
struct ib_gid_table_entry *entry = &table->data_vec[i];
800-
801-
entry->props |= GID_TABLE_ENTRY_DEFAULT;
802-
}
811+
/* Reserve starting indices for default GIDs */
812+
for (i = 0; i < num_default_gids && i < table->sz; i++)
813+
table->default_gid_indices |= BIT(i);
803814
}
804815

805816

0 commit comments

Comments
 (0)