36 #include <linux/rbtree.h>
42 #define CM_CLEANUP_CACHE_TIMEOUT (5 * HZ)
107 struct rb_root *sl_id_map = &to_mdev(ibdev)->sriov.sl_id_map;
112 rb_entry(node,
struct id_map_entry, node);
114 if (id_map_entry->
sl_cm_id > sl_cm_id)
116 else if (id_map_entry->
sl_cm_id < sl_cm_id)
118 else if (id_map_entry->
slave_id > slave_id)
120 else if (id_map_entry->
slave_id < slave_id)
132 struct id_map_entry *db_ent, *found_ent;
143 if (found_ent && found_ent == ent)
157 struct id_map_entry *ent, *found_ent;
164 if (found_ent && found_ent == ent)
171 static void sl_id_map_add(
struct ib_device *ibdev,
struct id_map_entry *
new)
173 struct rb_root *sl_id_map = &to_mdev(ibdev)->sriov.sl_id_map;
175 struct id_map_entry *ent;
177 int sl_cm_id =
new->sl_cm_id;
179 ent = id_map_find_by_sl_id(ibdev, slave_id, sl_cm_id);
181 pr_debug(
"overriding existing sl_id_map entry (cm_id = %x)\n",
191 ent =
rb_entry(parent,
struct id_map_entry, node);
199 rb_link_node(&new->node, parent, link);
203 static struct id_map_entry *
204 id_map_alloc(
struct ib_device *ibdev,
int slave_id,
u32 sl_cm_id)
208 struct id_map_entry *ent;
213 mlx4_ib_warn(ibdev,
"Couldn't allocate id cache entry - out of memory\n");
220 ent->
dev = to_mdev(ibdev);
230 sl_id_map_add(ibdev, ent);
244 mlx4_ib_warn(ibdev,
"No more space in the idr (err:0x%x)\n", ret);
248 static struct id_map_entry *
249 id_map_get(
struct ib_device *ibdev,
int *pv_cm_id,
int sl_cm_id,
int slave_id)
251 struct id_map_entry *ent;
255 if (*pv_cm_id == -1) {
256 ent = id_map_find_by_sl_id(ibdev, sl_cm_id, slave_id);
266 static void schedule_delayed(
struct ib_device *ibdev,
struct id_map_entry *
id)
275 id->scheduled_delete = 1;
285 struct id_map_entry *
id;
289 sl_cm_id = get_local_comm_id(mad);
293 id = id_map_alloc(ibdev, slave_id, sl_cm_id);
295 mlx4_ib_warn(ibdev,
"%s: id{slave: %d, sl_cm_id: 0x%x} Failed to id_map_alloc\n",
296 __func__, slave_id, sl_cm_id);
302 id = id_map_get(ibdev, &pv_cm_id, slave_id, sl_cm_id);
306 pr_debug(
"id{slave: %d, sl_cm_id: 0x%x} is NULL!\n",
311 set_local_comm_id(mad, id->
pv_cm_id);
314 schedule_delayed(ibdev,
id);
316 id_map_find_del(ibdev, pv_cm_id);
325 struct id_map_entry *
id;
330 gid = gid_from_req_msg(ibdev, mad);
333 mlx4_ib_warn(ibdev,
"failed matching slave_id by gid (0x%llx)\n",
334 gid.global.interface_id);
340 pv_cm_id = get_remote_comm_id(mad);
341 id = id_map_get(ibdev, (
int *)&pv_cm_id, -1, -1);
344 pr_debug(
"Couldn't find an entry for pv_cm_id 0x%x\n", pv_cm_id);
348 *slave =
id->slave_id;
349 set_remote_comm_id(mad, id->
sl_cm_id);
352 schedule_delayed(ibdev,
id);
355 id_map_find_del(ibdev, (
int) pv_cm_id);
364 INIT_LIST_HEAD(&dev->
sriov.cm_list);
379 struct id_map_entry *
map, *tmp_map;
399 struct id_map_entry *ent =
401 struct id_map_entry, node);
406 list_splice_init(&dev->
sriov.cm_list, &lh);
411 struct id_map_entry *ent =
412 rb_entry(nd,
struct id_map_entry, node);
415 list_move_tail(&ent->
list, &lh);
426 list_move_tail(&map->
list, &lh);