Commit 25e62655 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

IB/core: Reduce the places that use zgid

Instead of open coding memcmp() to check whether a given GID is zero or
not, use a helper function to do so, and replace instances of
memcpy(z,&zgid) with memset.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 7b74a83c
...@@ -125,6 +125,16 @@ const char *ib_cache_gid_type_str(enum ib_gid_type gid_type) ...@@ -125,6 +125,16 @@ const char *ib_cache_gid_type_str(enum ib_gid_type gid_type)
} }
EXPORT_SYMBOL(ib_cache_gid_type_str); EXPORT_SYMBOL(ib_cache_gid_type_str);
/** rdma_is_zero_gid - Check if given GID is zero or not.
* @gid: GID to check
* Returns true if given GID is zero, returns false otherwise.
*/
bool rdma_is_zero_gid(const union ib_gid *gid)
{
return !memcmp(gid, &zgid, sizeof(*gid));
}
EXPORT_SYMBOL(rdma_is_zero_gid);
int ib_cache_gid_parse_type_str(const char *buf) int ib_cache_gid_parse_type_str(const char *buf)
{ {
unsigned int i; unsigned int i;
...@@ -231,7 +241,7 @@ static int add_modify_gid(struct ib_gid_table *table, ...@@ -231,7 +241,7 @@ static int add_modify_gid(struct ib_gid_table *table,
* So ignore such behavior for IB link layer and don't * So ignore such behavior for IB link layer and don't
* fail the call, but don't add such entry to GID cache. * fail the call, but don't add such entry to GID cache.
*/ */
if (!memcmp(gid, &zgid, sizeof(*gid))) if (rdma_is_zero_gid(gid))
return 0; return 0;
} }
...@@ -264,7 +274,7 @@ static void del_gid(struct ib_device *ib_dev, u8 port, ...@@ -264,7 +274,7 @@ static void del_gid(struct ib_device *ib_dev, u8 port,
if (rdma_protocol_roce(ib_dev, port)) if (rdma_protocol_roce(ib_dev, port))
del_roce_gid(ib_dev, port, table, ix); del_roce_gid(ib_dev, port, table, ix);
memcpy(&table->data_vec[ix].gid, &zgid, sizeof(zgid)); memset(&table->data_vec[ix].gid, 0, sizeof(table->data_vec[ix].gid));
memset(&table->data_vec[ix].attr, 0, sizeof(table->data_vec[ix].attr)); memset(&table->data_vec[ix].attr, 0, sizeof(table->data_vec[ix].attr));
table->data_vec[ix].context = NULL; table->data_vec[ix].context = NULL;
} }
...@@ -363,7 +373,7 @@ static int __ib_cache_gid_add(struct ib_device *ib_dev, u8 port, ...@@ -363,7 +373,7 @@ static int __ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
* IB spec version 1.3 section 4.1.1 point (6) and * IB spec version 1.3 section 4.1.1 point (6) and
* section 12.7.10 and section 12.7.20 * section 12.7.10 and section 12.7.20
*/ */
if (!memcmp(gid, &zgid, sizeof(*gid))) if (rdma_is_zero_gid(gid))
return -EINVAL; return -EINVAL;
table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid; table = ib_dev->cache.ports[port - rdma_start_port(ib_dev)].gid;
...@@ -724,8 +734,7 @@ static void cleanup_gid_table_port(struct ib_device *ib_dev, u8 port, ...@@ -724,8 +734,7 @@ static void cleanup_gid_table_port(struct ib_device *ib_dev, u8 port,
mutex_lock(&table->lock); mutex_lock(&table->lock);
for (i = 0; i < table->sz; ++i) { for (i = 0; i < table->sz; ++i) {
if (memcmp(&table->data_vec[i].gid, &zgid, if (!rdma_is_zero_gid(&table->data_vec[i].gid)) {
sizeof(table->data_vec[i].gid))) {
del_gid(ib_dev, port, table, i); del_gid(ib_dev, port, table, i);
deleted = true; deleted = true;
} }
......
...@@ -276,7 +276,7 @@ static int mlx4_ib_add_gid(const union ib_gid *gid, ...@@ -276,7 +276,7 @@ static int mlx4_ib_add_gid(const union ib_gid *gid,
found = i; found = i;
break; break;
} }
if (free < 0 && !memcmp(&port_gid_table->gids[i].gid, &zgid, sizeof(*gid))) if (free < 0 && rdma_is_zero_gid(&port_gid_table->gids[i].gid))
free = i; /* HW has space */ free = i; /* HW has space */
} }
...@@ -345,7 +345,8 @@ static int mlx4_ib_del_gid(const struct ib_gid_attr *attr, void **context) ...@@ -345,7 +345,8 @@ static int mlx4_ib_del_gid(const struct ib_gid_attr *attr, void **context)
if (!ctx->refcount) { if (!ctx->refcount) {
unsigned int real_index = ctx->real_index; unsigned int real_index = ctx->real_index;
memcpy(&port_gid_table->gids[real_index].gid, &zgid, sizeof(zgid)); memset(&port_gid_table->gids[real_index].gid, 0,
sizeof(port_gid_table->gids[real_index].gid));
kfree(port_gid_table->gids[real_index].ctx); kfree(port_gid_table->gids[real_index].ctx);
port_gid_table->gids[real_index].ctx = NULL; port_gid_table->gids[real_index].ctx = NULL;
hw_update = 1; hw_update = 1;
......
...@@ -3078,7 +3078,7 @@ static int fill_gid_by_hw_index(struct mlx4_ib_dev *ibdev, u8 port_num, ...@@ -3078,7 +3078,7 @@ static int fill_gid_by_hw_index(struct mlx4_ib_dev *ibdev, u8 port_num,
memcpy(gid, &port_gid_table->gids[index].gid, sizeof(*gid)); memcpy(gid, &port_gid_table->gids[index].gid, sizeof(*gid));
*gid_type = port_gid_table->gids[index].gid_type; *gid_type = port_gid_table->gids[index].gid_type;
spin_unlock_irqrestore(&iboe->lock, flags); spin_unlock_irqrestore(&iboe->lock, flags);
if (!memcmp(gid, &zgid, sizeof(*gid))) if (rdma_is_zero_gid(gid))
return -ENOENT; return -ENOENT;
return 0; return 0;
......
...@@ -149,4 +149,5 @@ int ib_get_cached_port_state(struct ib_device *device, ...@@ -149,4 +149,5 @@ int ib_get_cached_port_state(struct ib_device *device,
u8 port_num, u8 port_num,
enum ib_port_state *port_active); enum ib_port_state *port_active);
bool rdma_is_zero_gid(const union ib_gid *gid);
#endif /* _IB_CACHE_H */ #endif /* _IB_CACHE_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment