Lines Matching +full:re +full:- +full:attached
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 * attached to a new mgid for the first time. These are indexed by
13 * a red-black tree using the mgid. This data structure is searched
15 * qp is attached to the same mgid. It is cleaned up when the last qp
16 * is detached from the mcg. Each time a qp is attached to an mcg an
18 * of qp's that are attached to the mcg. The qp_list is used to replicate
25 * rxe_mcast_add - add multicast address to rxe device
37 ndev = rxe_ib_device_get_netdev(&rxe->ib_dev); in rxe_mcast_add()
39 return -ENODEV; in rxe_mcast_add()
41 ipv6_eth_mc_map((struct in6_addr *)mgid->raw, ll_addr); in rxe_mcast_add()
50 * rxe_mcast_del - delete multicast address from rxe device
62 ndev = rxe_ib_device_get_netdev(&rxe->ib_dev); in rxe_mcast_del()
64 return -ENODEV; in rxe_mcast_del()
66 ipv6_eth_mc_map((struct in6_addr *)mgid->raw, ll_addr); in rxe_mcast_del()
75 * __rxe_insert_mcg - insert an mcg into red-black tree (rxe->mcg_tree)
76 * @mcg: mcg object with an embedded red-black tree node
78 * Context: caller must hold a reference to mcg and rxe->mcg_lock and
83 struct rb_root *tree = &mcg->rxe->mcg_tree; in __rxe_insert_mcg()
84 struct rb_node **link = &tree->rb_node; in __rxe_insert_mcg()
93 cmp = memcmp(&tmp->mgid, &mcg->mgid, sizeof(mcg->mgid)); in __rxe_insert_mcg()
95 link = &(*link)->rb_left; in __rxe_insert_mcg()
97 link = &(*link)->rb_right; in __rxe_insert_mcg()
100 rb_link_node(&mcg->node, node, link); in __rxe_insert_mcg()
101 rb_insert_color(&mcg->node, tree); in __rxe_insert_mcg()
105 * __rxe_remove_mcg - remove an mcg from red-black tree holding lock
106 * @mcg: mcast group object with an embedded red-black tree node
108 * Context: caller must hold a reference to mcg and rxe->mcg_lock
112 rb_erase(&mcg->node, &mcg->rxe->mcg_tree); in __rxe_remove_mcg()
116 * __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock
120 * Context: caller must hold rxe->mcg_lock
126 struct rb_root *tree = &rxe->mcg_tree; in __rxe_lookup_mcg()
131 node = tree->rb_node; in __rxe_lookup_mcg()
136 cmp = memcmp(&mcg->mgid, mgid, sizeof(*mgid)); in __rxe_lookup_mcg()
139 node = node->rb_left; in __rxe_lookup_mcg()
141 node = node->rb_right; in __rxe_lookup_mcg()
147 kref_get(&mcg->ref_cnt); in __rxe_lookup_mcg()
155 * rxe_lookup_mcg - lookup up mcg in red-back tree
165 spin_lock_bh(&rxe->mcg_lock); in rxe_lookup_mcg()
167 spin_unlock_bh(&rxe->mcg_lock); in rxe_lookup_mcg()
173 * __rxe_init_mcg - initialize a new mcg
178 * Context: caller should hold rxe->mcg lock
183 kref_init(&mcg->ref_cnt); in __rxe_init_mcg()
184 memcpy(&mcg->mgid, mgid, sizeof(mcg->mgid)); in __rxe_init_mcg()
185 INIT_LIST_HEAD(&mcg->qp_list); in __rxe_init_mcg()
186 mcg->rxe = rxe; in __rxe_init_mcg()
190 * on the pointer that will be saved in the red-black tree in __rxe_init_mcg()
195 kref_get(&mcg->ref_cnt); in __rxe_init_mcg()
200 * rxe_get_mcg - lookup or allocate a mcg
211 if (rxe->attr.max_mcast_grp == 0) in rxe_get_mcg()
212 return ERR_PTR(-EINVAL); in rxe_get_mcg()
220 if (atomic_inc_return(&rxe->mcg_num) > rxe->attr.max_mcast_grp) { in rxe_get_mcg()
221 err = -ENOMEM; in rxe_get_mcg()
228 err = -ENOMEM; in rxe_get_mcg()
232 spin_lock_bh(&rxe->mcg_lock); in rxe_get_mcg()
233 /* re-check to see if someone else just added it */ in rxe_get_mcg()
236 spin_unlock_bh(&rxe->mcg_lock); in rxe_get_mcg()
237 atomic_dec(&rxe->mcg_num); in rxe_get_mcg()
243 spin_unlock_bh(&rxe->mcg_lock); in rxe_get_mcg()
252 atomic_dec(&rxe->mcg_num); in rxe_get_mcg()
257 * rxe_cleanup_mcg - cleanup mcg for kref_put
268 * __rxe_destroy_mcg - destroy mcg object holding rxe->mcg_lock
271 * Context: caller is holding rxe->mcg_lock
272 * no qp's are attached to mcg
276 struct rxe_dev *rxe = mcg->rxe; in __rxe_destroy_mcg()
278 /* remove mcg from red-black tree then drop ref */ in __rxe_destroy_mcg()
280 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in __rxe_destroy_mcg()
282 atomic_dec(&rxe->mcg_num); in __rxe_destroy_mcg()
286 * rxe_destroy_mcg - destroy mcg object
289 * Context: no qp's are attached to mcg
294 rxe_mcast_del(mcg->rxe, &mcg->mgid); in rxe_destroy_mcg()
296 spin_lock_bh(&mcg->rxe->mcg_lock); in rxe_destroy_mcg()
298 spin_unlock_bh(&mcg->rxe->mcg_lock); in rxe_destroy_mcg()
302 * __rxe_init_mca - initialize a new mca holding lock
307 * Context: caller must hold references on qp and mcg, rxe->mcg_lock
315 struct rxe_dev *rxe = to_rdev(qp->ibqp.device); in __rxe_init_mca()
318 n = atomic_inc_return(&rxe->mcg_attach); in __rxe_init_mca()
319 if (n > rxe->attr.max_total_mcast_qp_attach) { in __rxe_init_mca()
320 atomic_dec(&rxe->mcg_attach); in __rxe_init_mca()
321 return -ENOMEM; in __rxe_init_mca()
324 n = atomic_inc_return(&mcg->qp_num); in __rxe_init_mca()
325 if (n > rxe->attr.max_mcast_qp_attach) { in __rxe_init_mca()
326 atomic_dec(&mcg->qp_num); in __rxe_init_mca()
327 atomic_dec(&rxe->mcg_attach); in __rxe_init_mca()
328 return -ENOMEM; in __rxe_init_mca()
331 atomic_inc(&qp->mcg_num); in __rxe_init_mca()
334 mca->qp = qp; in __rxe_init_mca()
336 list_add_tail(&mca->qp_list, &mcg->qp_list); in __rxe_init_mca()
342 * rxe_attach_mcg - attach qp to mcg if not already attached
351 struct rxe_dev *rxe = mcg->rxe; in rxe_attach_mcg()
356 spin_lock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
357 list_for_each_entry(mca, &mcg->qp_list, qp_list) { in rxe_attach_mcg()
358 if (mca->qp == qp) { in rxe_attach_mcg()
359 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
363 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
368 return -ENOMEM; in rxe_attach_mcg()
370 spin_lock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
371 /* re-check to see if someone else just attached qp */ in rxe_attach_mcg()
372 list_for_each_entry(tmp, &mcg->qp_list, qp_list) { in rxe_attach_mcg()
373 if (tmp->qp == qp) { in rxe_attach_mcg()
384 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
389 * __rxe_cleanup_mca - cleanup mca object holding lock
393 * Context: caller must hold a reference to mcg and rxe->mcg_lock
397 list_del(&mca->qp_list); in __rxe_cleanup_mca()
399 atomic_dec(&mcg->qp_num); in __rxe_cleanup_mca()
400 atomic_dec(&mcg->rxe->mcg_attach); in __rxe_cleanup_mca()
401 atomic_dec(&mca->qp->mcg_num); in __rxe_cleanup_mca()
402 rxe_put(mca->qp); in __rxe_cleanup_mca()
408 * rxe_detach_mcg - detach qp from mcg
412 * Returns: 0 on success else an error if qp is not attached.
416 struct rxe_dev *rxe = mcg->rxe; in rxe_detach_mcg()
419 spin_lock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
420 list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) { in rxe_detach_mcg()
421 if (mca->qp == qp) { in rxe_detach_mcg()
424 /* if the number of qp's attached to the in rxe_detach_mcg()
430 if (atomic_read(&mcg->qp_num) <= 0) in rxe_detach_mcg()
433 spin_unlock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
439 spin_unlock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
440 return -EINVAL; in rxe_detach_mcg()
444 * rxe_attach_mcast - attach qp to multicast group (see IBA-11.3.1)
447 * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6)
454 struct rxe_dev *rxe = to_rdev(ibqp->device); in rxe_attach_mcast()
466 if (atomic_read(&mcg->qp_num) == 0) in rxe_attach_mcast()
469 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in rxe_attach_mcast()
475 * rxe_detach_mcast - detach qp from multicast group (see IBA-11.3.2)
478 * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6)
484 struct rxe_dev *rxe = to_rdev(ibqp->device); in rxe_detach_mcast()
491 return -EINVAL; in rxe_detach_mcast()
494 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in rxe_detach_mcast()