static void free_roce_gid_cache(struct ib_device *ib_dev, u8 port) { int i; struct ib_roce_gid_cache *cache = ib_dev->cache.roce_gid_cache[port - 1]; if (!cache) return; for (i = 0; i < cache->sz; ++i) { if (memcmp(&cache->data_vec[i].gid, &zgid, sizeof(cache->data_vec[i].gid))) write_gid(ib_dev, port, cache, i, &zgid, &zattr); } kfree(cache->data_vec); kfree(cache); }
int roce_del_all_netdev_gids(struct ib_device *ib_dev, u8 port, struct net_device *ndev) { struct ib_roce_gid_cache *cache; int ix; if (!ib_dev->cache.roce_gid_cache) return 0; cache = ib_dev->cache.roce_gid_cache[port - start_port(ib_dev)]; if (!cache || !cache->active) return -ENOSYS; mutex_lock(&cache->lock); for (ix = 0; ix < cache->sz; ix++) if (cache->data_vec[ix].attr.ndev == ndev) write_gid(ib_dev, port, cache, ix, &zgid, &zattr); mutex_unlock(&cache->lock); return 0; }
static int del_gid(struct ib_device *ib_dev, u8 port, struct ib_gid_table *table, int ix, bool default_gid) { return write_gid(ib_dev, port, table, ix, &zgid, &zattr, GID_TABLE_WRITE_ACTION_DEL, default_gid); }
void roce_gid_cache_set_default_gid(struct ib_device *ib_dev, u8 port, struct net_device *ndev, unsigned long gid_type_mask, enum roce_gid_cache_default_mode mode) { union ib_gid gid, current_gid; struct ib_gid_attr gid_attr; struct ib_roce_gid_cache *cache; unsigned int gid_type; unsigned int gid_index = 0; cache = ib_dev->cache.roce_gid_cache[port - 1]; /* Default GID management is not valid in RoCEv1 compat mode. * In general, this function should not write to entries that * are not defined as defaults. In upstream such logic exists * and this check should be moved elsewhere (gid_table_reserve_default) */ if (!roce_v1_noncompat_gid) return; if (!cache) return; if (roce_gid_cache_get_gid(ib_dev, port, 0, ¤t_gid, &gid_attr)) return; if (mode == ROCE_GID_CACHE_DEFAULT_MODE_DELETE && !memcmp(¤t_gid, &zgid, sizeof(zgid))) /* If gid at index 0 is 0, we assume that the entire table is * empty. */ return; rdma_make_default_gid(ndev, &gid, roce_v1_noncompat_gid ? true : false); /* compare current default gid to the new one. If identical, no further * action is needed. * Comparing gid index 0 is enough because it is updated iff the others * are. */ if (!memcmp(¤t_gid, &gid, sizeof(gid)) && mode == ROCE_GID_CACHE_DEFAULT_MODE_SET) return; memset(&gid_attr, 0, sizeof(gid_attr)); gid_attr.ndev = ndev; for (gid_type = 0; gid_type < IB_GID_TYPE_SIZE; ++gid_type) { if (1UL << gid_type & ~gid_type_mask) continue; gid_attr.gid_type = gid_type; mutex_lock(&cache->lock); /* First delete current gid */ if (mode == ROCE_GID_CACHE_DEFAULT_MODE_DELETE && write_gid(ib_dev, port, cache, gid_index, &zgid, &zattr)) { pr_warn("roce_gid_cache: can't delete index %d for default gid %pI6\n", gid_index, gid.raw); mutex_unlock(&cache->lock); ++gid_index; continue; } /* If needed, write the new default gid */ if (mode == ROCE_GID_CACHE_DEFAULT_MODE_SET && write_gid(ib_dev, port, cache, gid_index, &gid, &gid_attr)) pr_warn("roce_gid_cache: unable to add default gid %pI6\n", gid.raw); mutex_unlock(&cache->lock); ++gid_index; } }