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
35 ipv6_eth_mc_map((struct in6_addr *)mgid->raw, ll_addr); in rxe_mcast_add()
37 return dev_mc_add(rxe->ndev, ll_addr); in rxe_mcast_add()
41 * rxe_mcast_del - delete multicast address from rxe device
51 ipv6_eth_mc_map((struct in6_addr *)mgid->raw, ll_addr); in rxe_mcast_del()
53 return dev_mc_del(rxe->ndev, ll_addr); in rxe_mcast_del()
57 * __rxe_insert_mcg - insert an mcg into red-black tree (rxe->mcg_tree)
58 * @mcg: mcg object with an embedded red-black tree node
60 * Context: caller must hold a reference to mcg and rxe->mcg_lock and
65 struct rb_root *tree = &mcg->rxe->mcg_tree; in __rxe_insert_mcg()
66 struct rb_node **link = &tree->rb_node; in __rxe_insert_mcg()
75 cmp = memcmp(&tmp->mgid, &mcg->mgid, sizeof(mcg->mgid)); in __rxe_insert_mcg()
77 link = &(*link)->rb_left; in __rxe_insert_mcg()
79 link = &(*link)->rb_right; in __rxe_insert_mcg()
82 rb_link_node(&mcg->node, node, link); in __rxe_insert_mcg()
83 rb_insert_color(&mcg->node, tree); in __rxe_insert_mcg()
87 * __rxe_remove_mcg - remove an mcg from red-black tree holding lock
88 * @mcg: mcast group object with an embedded red-black tree node
90 * Context: caller must hold a reference to mcg and rxe->mcg_lock
94 rb_erase(&mcg->node, &mcg->rxe->mcg_tree); in __rxe_remove_mcg()
98 * __rxe_lookup_mcg - lookup mcg in rxe->mcg_tree while holding lock
102 * Context: caller must hold rxe->mcg_lock
108 struct rb_root *tree = &rxe->mcg_tree; in __rxe_lookup_mcg()
113 node = tree->rb_node; in __rxe_lookup_mcg()
118 cmp = memcmp(&mcg->mgid, mgid, sizeof(*mgid)); in __rxe_lookup_mcg()
121 node = node->rb_left; in __rxe_lookup_mcg()
123 node = node->rb_right; in __rxe_lookup_mcg()
129 kref_get(&mcg->ref_cnt); in __rxe_lookup_mcg()
137 * rxe_lookup_mcg - lookup up mcg in red-back tree
147 spin_lock_bh(&rxe->mcg_lock); in rxe_lookup_mcg()
149 spin_unlock_bh(&rxe->mcg_lock); in rxe_lookup_mcg()
155 * __rxe_init_mcg - initialize a new mcg
160 * Context: caller should hold rxe->mcg lock
165 kref_init(&mcg->ref_cnt); in __rxe_init_mcg()
166 memcpy(&mcg->mgid, mgid, sizeof(mcg->mgid)); in __rxe_init_mcg()
167 INIT_LIST_HEAD(&mcg->qp_list); in __rxe_init_mcg()
168 mcg->rxe = rxe; in __rxe_init_mcg()
172 * on the pointer that will be saved in the red-black tree in __rxe_init_mcg()
177 kref_get(&mcg->ref_cnt); in __rxe_init_mcg()
182 * rxe_get_mcg - lookup or allocate a mcg
193 if (rxe->attr.max_mcast_grp == 0) in rxe_get_mcg()
194 return ERR_PTR(-EINVAL); in rxe_get_mcg()
202 if (atomic_inc_return(&rxe->mcg_num) > rxe->attr.max_mcast_grp) { in rxe_get_mcg()
203 err = -ENOMEM; in rxe_get_mcg()
210 err = -ENOMEM; in rxe_get_mcg()
214 spin_lock_bh(&rxe->mcg_lock); in rxe_get_mcg()
215 /* re-check to see if someone else just added it */ in rxe_get_mcg()
218 spin_unlock_bh(&rxe->mcg_lock); in rxe_get_mcg()
219 atomic_dec(&rxe->mcg_num); in rxe_get_mcg()
225 spin_unlock_bh(&rxe->mcg_lock); in rxe_get_mcg()
234 atomic_dec(&rxe->mcg_num); in rxe_get_mcg()
239 * rxe_cleanup_mcg - cleanup mcg for kref_put
250 * __rxe_destroy_mcg - destroy mcg object holding rxe->mcg_lock
253 * Context: caller is holding rxe->mcg_lock
254 * no qp's are attached to mcg
258 struct rxe_dev *rxe = mcg->rxe; in __rxe_destroy_mcg()
260 /* remove mcg from red-black tree then drop ref */ in __rxe_destroy_mcg()
262 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in __rxe_destroy_mcg()
264 atomic_dec(&rxe->mcg_num); in __rxe_destroy_mcg()
268 * rxe_destroy_mcg - destroy mcg object
271 * Context: no qp's are attached to mcg
276 rxe_mcast_del(mcg->rxe, &mcg->mgid); in rxe_destroy_mcg()
278 spin_lock_bh(&mcg->rxe->mcg_lock); in rxe_destroy_mcg()
280 spin_unlock_bh(&mcg->rxe->mcg_lock); in rxe_destroy_mcg()
284 * __rxe_init_mca - initialize a new mca holding lock
289 * Context: caller must hold references on qp and mcg, rxe->mcg_lock
297 struct rxe_dev *rxe = to_rdev(qp->ibqp.device); in __rxe_init_mca()
300 n = atomic_inc_return(&rxe->mcg_attach); in __rxe_init_mca()
301 if (n > rxe->attr.max_total_mcast_qp_attach) { in __rxe_init_mca()
302 atomic_dec(&rxe->mcg_attach); in __rxe_init_mca()
303 return -ENOMEM; in __rxe_init_mca()
306 n = atomic_inc_return(&mcg->qp_num); in __rxe_init_mca()
307 if (n > rxe->attr.max_mcast_qp_attach) { in __rxe_init_mca()
308 atomic_dec(&mcg->qp_num); in __rxe_init_mca()
309 atomic_dec(&rxe->mcg_attach); in __rxe_init_mca()
310 return -ENOMEM; in __rxe_init_mca()
313 atomic_inc(&qp->mcg_num); in __rxe_init_mca()
316 mca->qp = qp; in __rxe_init_mca()
318 list_add_tail(&mca->qp_list, &mcg->qp_list); in __rxe_init_mca()
324 * rxe_attach_mcg - attach qp to mcg if not already attached
333 struct rxe_dev *rxe = mcg->rxe; in rxe_attach_mcg()
338 spin_lock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
339 list_for_each_entry(mca, &mcg->qp_list, qp_list) { in rxe_attach_mcg()
340 if (mca->qp == qp) { in rxe_attach_mcg()
341 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
345 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
350 return -ENOMEM; in rxe_attach_mcg()
352 spin_lock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
353 /* re-check to see if someone else just attached qp */ in rxe_attach_mcg()
354 list_for_each_entry(tmp, &mcg->qp_list, qp_list) { in rxe_attach_mcg()
355 if (tmp->qp == qp) { in rxe_attach_mcg()
366 spin_unlock_bh(&rxe->mcg_lock); in rxe_attach_mcg()
371 * __rxe_cleanup_mca - cleanup mca object holding lock
375 * Context: caller must hold a reference to mcg and rxe->mcg_lock
379 list_del(&mca->qp_list); in __rxe_cleanup_mca()
381 atomic_dec(&mcg->qp_num); in __rxe_cleanup_mca()
382 atomic_dec(&mcg->rxe->mcg_attach); in __rxe_cleanup_mca()
383 atomic_dec(&mca->qp->mcg_num); in __rxe_cleanup_mca()
384 rxe_put(mca->qp); in __rxe_cleanup_mca()
390 * rxe_detach_mcg - detach qp from mcg
394 * Returns: 0 on success else an error if qp is not attached.
398 struct rxe_dev *rxe = mcg->rxe; in rxe_detach_mcg()
401 spin_lock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
402 list_for_each_entry_safe(mca, tmp, &mcg->qp_list, qp_list) { in rxe_detach_mcg()
403 if (mca->qp == qp) { in rxe_detach_mcg()
406 /* if the number of qp's attached to the in rxe_detach_mcg()
412 if (atomic_read(&mcg->qp_num) <= 0) in rxe_detach_mcg()
415 spin_unlock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
421 spin_unlock_bh(&rxe->mcg_lock); in rxe_detach_mcg()
422 return -EINVAL; in rxe_detach_mcg()
426 * rxe_attach_mcast - attach qp to multicast group (see IBA-11.3.1)
429 * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6)
436 struct rxe_dev *rxe = to_rdev(ibqp->device); in rxe_attach_mcast()
448 if (atomic_read(&mcg->qp_num) == 0) in rxe_attach_mcast()
451 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in rxe_attach_mcast()
457 * rxe_detach_mcast - detach qp from multicast group (see IBA-11.3.2)
460 * @mlid: multicast LID, ignored for RoCEv2 (see IBA-A17.5.6)
466 struct rxe_dev *rxe = to_rdev(ibqp->device); in rxe_detach_mcast()
473 return -EINVAL; in rxe_detach_mcast()
476 kref_put(&mcg->ref_cnt, rxe_cleanup_mcg); in rxe_detach_mcast()