Skip to content

Commit

Permalink
IB/core: Store default GID property per-table instead of per-entry
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Parav Pandit authored and Jason Gunthorpe committed Jun 18, 2018
1 parent a1a4cae commit 1c36cf9
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions drivers/infiniband/core/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ enum gid_attr_find_mask {

enum gid_table_entry_props {
GID_TABLE_ENTRY_INVALID = 1UL << 0,
GID_TABLE_ENTRY_DEFAULT = 1UL << 1,
};

struct ib_gid_table_entry {
Expand All @@ -79,7 +78,7 @@ struct ib_gid_table_entry {
};

struct ib_gid_table {
int sz;
int sz;
/* In RoCE, adding a GID to the table requires:
* (a) Find if this GID is already exists.
* (b) Find a free space.
Expand All @@ -94,10 +93,12 @@ struct ib_gid_table {
* rwlock. readers must hold only rwlock. All writers must be in a
* sleepable context.
*/
struct mutex lock;
struct mutex lock;
/* rwlock protects data_vec[ix]->props. */
rwlock_t rwlock;
struct ib_gid_table_entry *data_vec;
rwlock_t rwlock;
/* bit field, each bit indicates the index of default GID */
u32 default_gid_indices;
struct ib_gid_table_entry *data_vec;
};

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

/** is_gid_index_default - Check if a given index belongs to
* reserved default GIDs or not.
* @table: GID table pointer
* @index: Index to check in GID table
* Returns true if index is one of the reserved default GID index otherwise
* returns false.
*/
static bool is_gid_index_default(const struct ib_gid_table *table,
unsigned int index)
{
return index < 32 && (BIT(index) & table->default_gid_indices);
}

int ib_cache_gid_parse_type_str(const char *buf)
{
unsigned int i;
Expand Down Expand Up @@ -308,7 +322,7 @@ static int find_gid(struct ib_gid_table *table, const union ib_gid *gid,
if (pempty && empty < 0) {
if (data->props & GID_TABLE_ENTRY_INVALID &&
(default_gid ==
!!(data->props & GID_TABLE_ENTRY_DEFAULT))) {
is_gid_index_default(table, curr_index))) {
/*
* Found an invalid (free) entry; allocate it.
* If default GID is requested, then our
Expand Down Expand Up @@ -346,8 +360,7 @@ static int find_gid(struct ib_gid_table *table, const union ib_gid *gid,
continue;

if (mask & GID_ATTR_FIND_MASK_DEFAULT &&
!!(data->props & GID_TABLE_ENTRY_DEFAULT) !=
default_gid)
is_gid_index_default(table, curr_index) != default_gid)
continue;

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

roce_gid_type_mask = roce_gid_type_mask_support(ib_dev, port);
num_default_gids = hweight_long(roce_gid_type_mask);
for (i = 0; i < num_default_gids && i < table->sz; i++) {
struct ib_gid_table_entry *entry = &table->data_vec[i];

entry->props |= GID_TABLE_ENTRY_DEFAULT;
}
/* Reserve starting indices for default GIDs */
for (i = 0; i < num_default_gids && i < table->sz; i++)
table->default_gid_indices |= BIT(i);
}


Expand Down

0 comments on commit 1c36cf9

Please sign in to comment.