2 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 int rxe_mcast_get_grp(struct rxe_dev
*rxe
, union ib_gid
*mgid
,
38 struct rxe_mc_grp
**grp_p
)
41 struct rxe_mc_grp
*grp
;
43 if (rxe
->attr
.max_mcast_qp_attach
== 0) {
48 grp
= rxe_pool_get_key(&rxe
->mc_grp_pool
, mgid
);
52 grp
= rxe_alloc(&rxe
->mc_grp_pool
);
58 INIT_LIST_HEAD(&grp
->qp_list
);
59 spin_lock_init(&grp
->mcg_lock
);
62 rxe_add_key(grp
, mgid
);
64 err
= rxe_mcast_add(rxe
, mgid
);
78 int rxe_mcast_add_grp_elem(struct rxe_dev
*rxe
, struct rxe_qp
*qp
,
79 struct rxe_mc_grp
*grp
)
82 struct rxe_mc_elem
*elem
;
84 /* check to see of the qp is already a member of the group */
85 spin_lock_bh(&qp
->grp_lock
);
86 spin_lock_bh(&grp
->mcg_lock
);
87 list_for_each_entry(elem
, &grp
->qp_list
, qp_list
) {
94 if (grp
->num_qp
>= rxe
->attr
.max_mcast_qp_attach
) {
99 elem
= rxe_alloc(&rxe
->mc_elem_pool
);
105 /* each qp holds a ref on the grp */
112 list_add(&elem
->qp_list
, &grp
->qp_list
);
113 list_add(&elem
->grp_list
, &qp
->grp_list
);
117 spin_unlock_bh(&grp
->mcg_lock
);
118 spin_unlock_bh(&qp
->grp_lock
);
122 int rxe_mcast_drop_grp_elem(struct rxe_dev
*rxe
, struct rxe_qp
*qp
,
125 struct rxe_mc_grp
*grp
;
126 struct rxe_mc_elem
*elem
, *tmp
;
128 grp
= rxe_pool_get_key(&rxe
->mc_grp_pool
, mgid
);
132 spin_lock_bh(&qp
->grp_lock
);
133 spin_lock_bh(&grp
->mcg_lock
);
135 list_for_each_entry_safe(elem
, tmp
, &grp
->qp_list
, qp_list
) {
136 if (elem
->qp
== qp
) {
137 list_del(&elem
->qp_list
);
138 list_del(&elem
->grp_list
);
141 spin_unlock_bh(&grp
->mcg_lock
);
142 spin_unlock_bh(&qp
->grp_lock
);
144 rxe_drop_ref(grp
); /* ref held by QP */
145 rxe_drop_ref(grp
); /* ref from get_key */
150 spin_unlock_bh(&grp
->mcg_lock
);
151 spin_unlock_bh(&qp
->grp_lock
);
152 rxe_drop_ref(grp
); /* ref from get_key */
157 void rxe_drop_all_mcast_groups(struct rxe_qp
*qp
)
159 struct rxe_mc_grp
*grp
;
160 struct rxe_mc_elem
*elem
;
163 spin_lock_bh(&qp
->grp_lock
);
164 if (list_empty(&qp
->grp_list
)) {
165 spin_unlock_bh(&qp
->grp_lock
);
168 elem
= list_first_entry(&qp
->grp_list
, struct rxe_mc_elem
,
170 list_del(&elem
->grp_list
);
171 spin_unlock_bh(&qp
->grp_lock
);
174 spin_lock_bh(&grp
->mcg_lock
);
175 list_del(&elem
->qp_list
);
177 spin_unlock_bh(&grp
->mcg_lock
);
183 void rxe_mc_cleanup(struct rxe_pool_entry
*arg
)
185 struct rxe_mc_grp
*grp
= container_of(arg
, typeof(*grp
), pelem
);
186 struct rxe_dev
*rxe
= grp
->rxe
;
189 rxe_mcast_delete(rxe
, &grp
->mgid
);