2 * Copyright (c) 2006 Intel Corporation. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/completion.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/err.h>
36 #include <linux/interrupt.h>
37 #include <linux/export.h>
38 #include <linux/slab.h>
39 #include <linux/bitops.h>
40 #include <linux/random.h>
42 #include <rdma/ib_cache.h>
45 static void mcast_add_one(struct ib_device
*device
);
46 static void mcast_remove_one(struct ib_device
*device
);
48 static struct ib_client mcast_client
= {
49 .name
= "ib_multicast",
51 .remove
= mcast_remove_one
54 static struct ib_sa_client sa_client
;
55 static struct workqueue_struct
*mcast_wq
;
56 static union ib_gid mgid0
;
61 struct mcast_device
*dev
;
65 struct completion comp
;
70 struct ib_device
*device
;
71 struct ib_event_handler event_handler
;
74 struct mcast_port port
[0];
83 enum mcast_group_state
{
91 MCAST_INVALID_PKEY_INDEX
= 0xFFFF
97 struct ib_sa_mcmember_rec rec
;
99 struct mcast_port
*port
;
101 struct work_struct work
;
102 struct list_head pending_list
;
103 struct list_head active_list
;
104 struct mcast_member
*last_join
;
107 enum mcast_group_state state
;
108 struct ib_sa_query
*query
;
115 struct mcast_member
{
116 struct ib_sa_multicast multicast
;
117 struct ib_sa_client
*client
;
118 struct mcast_group
*group
;
119 struct list_head list
;
120 enum mcast_state state
;
122 struct completion comp
;
125 static void join_handler(int status
, struct ib_sa_mcmember_rec
*rec
,
127 static void leave_handler(int status
, struct ib_sa_mcmember_rec
*rec
,
130 static struct mcast_group
*mcast_find(struct mcast_port
*port
,
133 struct rb_node
*node
= port
->table
.rb_node
;
134 struct mcast_group
*group
;
138 group
= rb_entry(node
, struct mcast_group
, node
);
139 ret
= memcmp(mgid
->raw
, group
->rec
.mgid
.raw
, sizeof *mgid
);
144 node
= node
->rb_left
;
146 node
= node
->rb_right
;
151 static struct mcast_group
*mcast_insert(struct mcast_port
*port
,
152 struct mcast_group
*group
,
153 int allow_duplicates
)
155 struct rb_node
**link
= &port
->table
.rb_node
;
156 struct rb_node
*parent
= NULL
;
157 struct mcast_group
*cur_group
;
162 cur_group
= rb_entry(parent
, struct mcast_group
, node
);
164 ret
= memcmp(group
->rec
.mgid
.raw
, cur_group
->rec
.mgid
.raw
,
165 sizeof group
->rec
.mgid
);
167 link
= &(*link
)->rb_left
;
169 link
= &(*link
)->rb_right
;
170 else if (allow_duplicates
)
171 link
= &(*link
)->rb_left
;
175 rb_link_node(&group
->node
, parent
, link
);
176 rb_insert_color(&group
->node
, &port
->table
);
180 static void deref_port(struct mcast_port
*port
)
182 if (atomic_dec_and_test(&port
->refcount
))
183 complete(&port
->comp
);
186 static void release_group(struct mcast_group
*group
)
188 struct mcast_port
*port
= group
->port
;
191 spin_lock_irqsave(&port
->lock
, flags
);
192 if (atomic_dec_and_test(&group
->refcount
)) {
193 rb_erase(&group
->node
, &port
->table
);
194 spin_unlock_irqrestore(&port
->lock
, flags
);
198 spin_unlock_irqrestore(&port
->lock
, flags
);
201 static void deref_member(struct mcast_member
*member
)
203 if (atomic_dec_and_test(&member
->refcount
))
204 complete(&member
->comp
);
207 static void queue_join(struct mcast_member
*member
)
209 struct mcast_group
*group
= member
->group
;
212 spin_lock_irqsave(&group
->lock
, flags
);
213 list_add_tail(&member
->list
, &group
->pending_list
);
214 if (group
->state
== MCAST_IDLE
) {
215 group
->state
= MCAST_BUSY
;
216 atomic_inc(&group
->refcount
);
217 queue_work(mcast_wq
, &group
->work
);
219 spin_unlock_irqrestore(&group
->lock
, flags
);
223 * A multicast group has three types of members: full member, non member, and
224 * send only member. We need to keep track of the number of members of each
225 * type based on their join state. Adjust the number of members the belong to
226 * the specified join states.
228 static void adjust_membership(struct mcast_group
*group
, u8 join_state
, int inc
)
232 for (i
= 0; i
< 3; i
++, join_state
>>= 1)
233 if (join_state
& 0x1)
234 group
->members
[i
] += inc
;
238 * If a multicast group has zero members left for a particular join state, but
239 * the group is still a member with the SA, we need to leave that join state.
240 * Determine which join states we still belong to, but that do not have any
243 static u8
get_leave_state(struct mcast_group
*group
)
248 for (i
= 0; i
< 3; i
++)
249 if (!group
->members
[i
])
250 leave_state
|= (0x1 << i
);
252 return leave_state
& group
->rec
.join_state
;
255 static int check_selector(ib_sa_comp_mask comp_mask
,
256 ib_sa_comp_mask selector_mask
,
257 ib_sa_comp_mask value_mask
,
258 u8 selector
, u8 src_value
, u8 dst_value
)
262 if (!(comp_mask
& selector_mask
) || !(comp_mask
& value_mask
))
267 err
= (src_value
<= dst_value
);
270 err
= (src_value
>= dst_value
);
273 err
= (src_value
!= dst_value
);
283 static int cmp_rec(struct ib_sa_mcmember_rec
*src
,
284 struct ib_sa_mcmember_rec
*dst
, ib_sa_comp_mask comp_mask
)
286 /* MGID must already match */
288 if (comp_mask
& IB_SA_MCMEMBER_REC_PORT_GID
&&
289 memcmp(&src
->port_gid
, &dst
->port_gid
, sizeof src
->port_gid
))
291 if (comp_mask
& IB_SA_MCMEMBER_REC_QKEY
&& src
->qkey
!= dst
->qkey
)
293 if (comp_mask
& IB_SA_MCMEMBER_REC_MLID
&& src
->mlid
!= dst
->mlid
)
295 if (check_selector(comp_mask
, IB_SA_MCMEMBER_REC_MTU_SELECTOR
,
296 IB_SA_MCMEMBER_REC_MTU
, dst
->mtu_selector
,
299 if (comp_mask
& IB_SA_MCMEMBER_REC_TRAFFIC_CLASS
&&
300 src
->traffic_class
!= dst
->traffic_class
)
302 if (comp_mask
& IB_SA_MCMEMBER_REC_PKEY
&& src
->pkey
!= dst
->pkey
)
304 if (check_selector(comp_mask
, IB_SA_MCMEMBER_REC_RATE_SELECTOR
,
305 IB_SA_MCMEMBER_REC_RATE
, dst
->rate_selector
,
306 src
->rate
, dst
->rate
))
308 if (check_selector(comp_mask
,
309 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME_SELECTOR
,
310 IB_SA_MCMEMBER_REC_PACKET_LIFE_TIME
,
311 dst
->packet_life_time_selector
,
312 src
->packet_life_time
, dst
->packet_life_time
))
314 if (comp_mask
& IB_SA_MCMEMBER_REC_SL
&& src
->sl
!= dst
->sl
)
316 if (comp_mask
& IB_SA_MCMEMBER_REC_FLOW_LABEL
&&
317 src
->flow_label
!= dst
->flow_label
)
319 if (comp_mask
& IB_SA_MCMEMBER_REC_HOP_LIMIT
&&
320 src
->hop_limit
!= dst
->hop_limit
)
322 if (comp_mask
& IB_SA_MCMEMBER_REC_SCOPE
&& src
->scope
!= dst
->scope
)
325 /* join_state checked separately, proxy_join ignored */
330 static int send_join(struct mcast_group
*group
, struct mcast_member
*member
)
332 struct mcast_port
*port
= group
->port
;
335 group
->last_join
= member
;
336 ret
= ib_sa_mcmember_rec_query(&sa_client
, port
->dev
->device
,
337 port
->port_num
, IB_MGMT_METHOD_SET
,
338 &member
->multicast
.rec
,
339 member
->multicast
.comp_mask
,
340 3000, GFP_KERNEL
, join_handler
, group
,
343 group
->query_id
= ret
;
349 static int send_leave(struct mcast_group
*group
, u8 leave_state
)
351 struct mcast_port
*port
= group
->port
;
352 struct ib_sa_mcmember_rec rec
;
356 rec
.join_state
= leave_state
;
357 group
->leave_state
= leave_state
;
359 ret
= ib_sa_mcmember_rec_query(&sa_client
, port
->dev
->device
,
360 port
->port_num
, IB_SA_METHOD_DELETE
, &rec
,
361 IB_SA_MCMEMBER_REC_MGID
|
362 IB_SA_MCMEMBER_REC_PORT_GID
|
363 IB_SA_MCMEMBER_REC_JOIN_STATE
,
364 3000, GFP_KERNEL
, leave_handler
,
365 group
, &group
->query
);
367 group
->query_id
= ret
;
373 static void join_group(struct mcast_group
*group
, struct mcast_member
*member
,
376 member
->state
= MCAST_MEMBER
;
377 adjust_membership(group
, join_state
, 1);
378 group
->rec
.join_state
|= join_state
;
379 member
->multicast
.rec
= group
->rec
;
380 member
->multicast
.rec
.join_state
= join_state
;
381 list_move(&member
->list
, &group
->active_list
);
384 static int fail_join(struct mcast_group
*group
, struct mcast_member
*member
,
387 spin_lock_irq(&group
->lock
);
388 list_del_init(&member
->list
);
389 spin_unlock_irq(&group
->lock
);
390 return member
->multicast
.callback(status
, &member
->multicast
);
393 static void process_group_error(struct mcast_group
*group
)
395 struct mcast_member
*member
;
399 if (group
->state
== MCAST_PKEY_EVENT
)
400 ret
= ib_find_pkey(group
->port
->dev
->device
,
401 group
->port
->port_num
,
402 be16_to_cpu(group
->rec
.pkey
), &pkey_index
);
404 spin_lock_irq(&group
->lock
);
405 if (group
->state
== MCAST_PKEY_EVENT
&& !ret
&&
406 group
->pkey_index
== pkey_index
)
409 while (!list_empty(&group
->active_list
)) {
410 member
= list_entry(group
->active_list
.next
,
411 struct mcast_member
, list
);
412 atomic_inc(&member
->refcount
);
413 list_del_init(&member
->list
);
414 adjust_membership(group
, member
->multicast
.rec
.join_state
, -1);
415 member
->state
= MCAST_ERROR
;
416 spin_unlock_irq(&group
->lock
);
418 ret
= member
->multicast
.callback(-ENETRESET
,
420 deref_member(member
);
422 ib_sa_free_multicast(&member
->multicast
);
423 spin_lock_irq(&group
->lock
);
426 group
->rec
.join_state
= 0;
428 group
->state
= MCAST_BUSY
;
429 spin_unlock_irq(&group
->lock
);
432 static void mcast_work_handler(struct work_struct
*work
)
434 struct mcast_group
*group
;
435 struct mcast_member
*member
;
436 struct ib_sa_multicast
*multicast
;
440 group
= container_of(work
, typeof(*group
), work
);
442 spin_lock_irq(&group
->lock
);
443 while (!list_empty(&group
->pending_list
) ||
444 (group
->state
!= MCAST_BUSY
)) {
446 if (group
->state
!= MCAST_BUSY
) {
447 spin_unlock_irq(&group
->lock
);
448 process_group_error(group
);
452 member
= list_entry(group
->pending_list
.next
,
453 struct mcast_member
, list
);
454 multicast
= &member
->multicast
;
455 join_state
= multicast
->rec
.join_state
;
456 atomic_inc(&member
->refcount
);
458 if (join_state
== (group
->rec
.join_state
& join_state
)) {
459 status
= cmp_rec(&group
->rec
, &multicast
->rec
,
460 multicast
->comp_mask
);
462 join_group(group
, member
, join_state
);
464 list_del_init(&member
->list
);
465 spin_unlock_irq(&group
->lock
);
466 ret
= multicast
->callback(status
, multicast
);
468 spin_unlock_irq(&group
->lock
);
469 status
= send_join(group
, member
);
471 deref_member(member
);
474 ret
= fail_join(group
, member
, status
);
477 deref_member(member
);
479 ib_sa_free_multicast(&member
->multicast
);
480 spin_lock_irq(&group
->lock
);
483 join_state
= get_leave_state(group
);
485 group
->rec
.join_state
&= ~join_state
;
486 spin_unlock_irq(&group
->lock
);
487 if (send_leave(group
, join_state
))
490 group
->state
= MCAST_IDLE
;
491 spin_unlock_irq(&group
->lock
);
492 release_group(group
);
497 * Fail a join request if it is still active - at the head of the pending queue.
499 static void process_join_error(struct mcast_group
*group
, int status
)
501 struct mcast_member
*member
;
504 spin_lock_irq(&group
->lock
);
505 member
= list_entry(group
->pending_list
.next
,
506 struct mcast_member
, list
);
507 if (group
->last_join
== member
) {
508 atomic_inc(&member
->refcount
);
509 list_del_init(&member
->list
);
510 spin_unlock_irq(&group
->lock
);
511 ret
= member
->multicast
.callback(status
, &member
->multicast
);
512 deref_member(member
);
514 ib_sa_free_multicast(&member
->multicast
);
516 spin_unlock_irq(&group
->lock
);
519 static void join_handler(int status
, struct ib_sa_mcmember_rec
*rec
,
522 struct mcast_group
*group
= context
;
523 u16 pkey_index
= MCAST_INVALID_PKEY_INDEX
;
526 process_join_error(group
, status
);
528 int mgids_changed
, is_mgid0
;
529 ib_find_pkey(group
->port
->dev
->device
, group
->port
->port_num
,
530 be16_to_cpu(rec
->pkey
), &pkey_index
);
532 spin_lock_irq(&group
->port
->lock
);
533 if (group
->state
== MCAST_BUSY
&&
534 group
->pkey_index
== MCAST_INVALID_PKEY_INDEX
)
535 group
->pkey_index
= pkey_index
;
536 mgids_changed
= memcmp(&rec
->mgid
, &group
->rec
.mgid
,
537 sizeof(group
->rec
.mgid
));
540 rb_erase(&group
->node
, &group
->port
->table
);
541 is_mgid0
= !memcmp(&mgid0
, &group
->rec
.mgid
,
543 mcast_insert(group
->port
, group
, is_mgid0
);
545 spin_unlock_irq(&group
->port
->lock
);
547 mcast_work_handler(&group
->work
);
550 static void leave_handler(int status
, struct ib_sa_mcmember_rec
*rec
,
553 struct mcast_group
*group
= context
;
555 if (status
&& group
->retries
> 0 &&
556 !send_leave(group
, group
->leave_state
))
559 mcast_work_handler(&group
->work
);
562 static struct mcast_group
*acquire_group(struct mcast_port
*port
,
563 union ib_gid
*mgid
, gfp_t gfp_mask
)
565 struct mcast_group
*group
, *cur_group
;
569 is_mgid0
= !memcmp(&mgid0
, mgid
, sizeof mgid0
);
571 spin_lock_irqsave(&port
->lock
, flags
);
572 group
= mcast_find(port
, mgid
);
575 spin_unlock_irqrestore(&port
->lock
, flags
);
578 group
= kzalloc(sizeof *group
, gfp_mask
);
584 group
->rec
.mgid
= *mgid
;
585 group
->pkey_index
= MCAST_INVALID_PKEY_INDEX
;
586 INIT_LIST_HEAD(&group
->pending_list
);
587 INIT_LIST_HEAD(&group
->active_list
);
588 INIT_WORK(&group
->work
, mcast_work_handler
);
589 spin_lock_init(&group
->lock
);
591 spin_lock_irqsave(&port
->lock
, flags
);
592 cur_group
= mcast_insert(port
, group
, is_mgid0
);
597 atomic_inc(&port
->refcount
);
599 atomic_inc(&group
->refcount
);
600 spin_unlock_irqrestore(&port
->lock
, flags
);
605 * We serialize all join requests to a single group to make our lives much
606 * easier. Otherwise, two users could try to join the same group
607 * simultaneously, with different configurations, one could leave while the
608 * join is in progress, etc., which makes locking around error recovery
611 struct ib_sa_multicast
*
612 ib_sa_join_multicast(struct ib_sa_client
*client
,
613 struct ib_device
*device
, u8 port_num
,
614 struct ib_sa_mcmember_rec
*rec
,
615 ib_sa_comp_mask comp_mask
, gfp_t gfp_mask
,
616 int (*callback
)(int status
,
617 struct ib_sa_multicast
*multicast
),
620 struct mcast_device
*dev
;
621 struct mcast_member
*member
;
622 struct ib_sa_multicast
*multicast
;
625 dev
= ib_get_client_data(device
, &mcast_client
);
627 return ERR_PTR(-ENODEV
);
629 member
= kmalloc(sizeof *member
, gfp_mask
);
631 return ERR_PTR(-ENOMEM
);
633 ib_sa_client_get(client
);
634 member
->client
= client
;
635 member
->multicast
.rec
= *rec
;
636 member
->multicast
.comp_mask
= comp_mask
;
637 member
->multicast
.callback
= callback
;
638 member
->multicast
.context
= context
;
639 init_completion(&member
->comp
);
640 atomic_set(&member
->refcount
, 1);
641 member
->state
= MCAST_JOINING
;
643 member
->group
= acquire_group(&dev
->port
[port_num
- dev
->start_port
],
644 &rec
->mgid
, gfp_mask
);
645 if (!member
->group
) {
651 * The user will get the multicast structure in their callback. They
652 * could then free the multicast structure before we can return from
653 * this routine. So we save the pointer to return before queuing
656 multicast
= &member
->multicast
;
661 ib_sa_client_put(client
);
665 EXPORT_SYMBOL(ib_sa_join_multicast
);
667 void ib_sa_free_multicast(struct ib_sa_multicast
*multicast
)
669 struct mcast_member
*member
;
670 struct mcast_group
*group
;
672 member
= container_of(multicast
, struct mcast_member
, multicast
);
673 group
= member
->group
;
675 spin_lock_irq(&group
->lock
);
676 if (member
->state
== MCAST_MEMBER
)
677 adjust_membership(group
, multicast
->rec
.join_state
, -1);
679 list_del_init(&member
->list
);
681 if (group
->state
== MCAST_IDLE
) {
682 group
->state
= MCAST_BUSY
;
683 spin_unlock_irq(&group
->lock
);
684 /* Continue to hold reference on group until callback */
685 queue_work(mcast_wq
, &group
->work
);
687 spin_unlock_irq(&group
->lock
);
688 release_group(group
);
691 deref_member(member
);
692 wait_for_completion(&member
->comp
);
693 ib_sa_client_put(member
->client
);
696 EXPORT_SYMBOL(ib_sa_free_multicast
);
698 int ib_sa_get_mcmember_rec(struct ib_device
*device
, u8 port_num
,
699 union ib_gid
*mgid
, struct ib_sa_mcmember_rec
*rec
)
701 struct mcast_device
*dev
;
702 struct mcast_port
*port
;
703 struct mcast_group
*group
;
707 dev
= ib_get_client_data(device
, &mcast_client
);
711 port
= &dev
->port
[port_num
- dev
->start_port
];
712 spin_lock_irqsave(&port
->lock
, flags
);
713 group
= mcast_find(port
, mgid
);
717 ret
= -EADDRNOTAVAIL
;
718 spin_unlock_irqrestore(&port
->lock
, flags
);
722 EXPORT_SYMBOL(ib_sa_get_mcmember_rec
);
724 int ib_init_ah_from_mcmember(struct ib_device
*device
, u8 port_num
,
725 struct ib_sa_mcmember_rec
*rec
,
726 struct ib_ah_attr
*ah_attr
)
732 ret
= ib_find_cached_gid(device
, &rec
->port_gid
, &p
, &gid_index
);
736 memset(ah_attr
, 0, sizeof *ah_attr
);
737 ah_attr
->dlid
= be16_to_cpu(rec
->mlid
);
738 ah_attr
->sl
= rec
->sl
;
739 ah_attr
->port_num
= port_num
;
740 ah_attr
->static_rate
= rec
->rate
;
742 ah_attr
->ah_flags
= IB_AH_GRH
;
743 ah_attr
->grh
.dgid
= rec
->mgid
;
745 ah_attr
->grh
.sgid_index
= (u8
) gid_index
;
746 ah_attr
->grh
.flow_label
= be32_to_cpu(rec
->flow_label
);
747 ah_attr
->grh
.hop_limit
= rec
->hop_limit
;
748 ah_attr
->grh
.traffic_class
= rec
->traffic_class
;
752 EXPORT_SYMBOL(ib_init_ah_from_mcmember
);
754 static void mcast_groups_event(struct mcast_port
*port
,
755 enum mcast_group_state state
)
757 struct mcast_group
*group
;
758 struct rb_node
*node
;
761 spin_lock_irqsave(&port
->lock
, flags
);
762 for (node
= rb_first(&port
->table
); node
; node
= rb_next(node
)) {
763 group
= rb_entry(node
, struct mcast_group
, node
);
764 spin_lock(&group
->lock
);
765 if (group
->state
== MCAST_IDLE
) {
766 atomic_inc(&group
->refcount
);
767 queue_work(mcast_wq
, &group
->work
);
769 if (group
->state
!= MCAST_GROUP_ERROR
)
770 group
->state
= state
;
771 spin_unlock(&group
->lock
);
773 spin_unlock_irqrestore(&port
->lock
, flags
);
776 static void mcast_event_handler(struct ib_event_handler
*handler
,
777 struct ib_event
*event
)
779 struct mcast_device
*dev
;
782 dev
= container_of(handler
, struct mcast_device
, event_handler
);
783 if (rdma_port_get_link_layer(dev
->device
, event
->element
.port_num
) !=
784 IB_LINK_LAYER_INFINIBAND
)
787 index
= event
->element
.port_num
- dev
->start_port
;
789 switch (event
->event
) {
790 case IB_EVENT_PORT_ERR
:
791 case IB_EVENT_LID_CHANGE
:
792 case IB_EVENT_SM_CHANGE
:
793 case IB_EVENT_CLIENT_REREGISTER
:
794 mcast_groups_event(&dev
->port
[index
], MCAST_GROUP_ERROR
);
796 case IB_EVENT_PKEY_CHANGE
:
797 mcast_groups_event(&dev
->port
[index
], MCAST_PKEY_EVENT
);
804 static void mcast_add_one(struct ib_device
*device
)
806 struct mcast_device
*dev
;
807 struct mcast_port
*port
;
811 if (rdma_node_get_transport(device
->node_type
) != RDMA_TRANSPORT_IB
)
814 dev
= kmalloc(sizeof *dev
+ device
->phys_port_cnt
* sizeof *port
,
819 if (device
->node_type
== RDMA_NODE_IB_SWITCH
)
820 dev
->start_port
= dev
->end_port
= 0;
823 dev
->end_port
= device
->phys_port_cnt
;
826 for (i
= 0; i
<= dev
->end_port
- dev
->start_port
; i
++) {
827 if (rdma_port_get_link_layer(device
, dev
->start_port
+ i
) !=
828 IB_LINK_LAYER_INFINIBAND
)
830 port
= &dev
->port
[i
];
832 port
->port_num
= dev
->start_port
+ i
;
833 spin_lock_init(&port
->lock
);
834 port
->table
= RB_ROOT
;
835 init_completion(&port
->comp
);
836 atomic_set(&port
->refcount
, 1);
845 dev
->device
= device
;
846 ib_set_client_data(device
, &mcast_client
, dev
);
848 INIT_IB_EVENT_HANDLER(&dev
->event_handler
, device
, mcast_event_handler
);
849 ib_register_event_handler(&dev
->event_handler
);
852 static void mcast_remove_one(struct ib_device
*device
)
854 struct mcast_device
*dev
;
855 struct mcast_port
*port
;
858 dev
= ib_get_client_data(device
, &mcast_client
);
862 ib_unregister_event_handler(&dev
->event_handler
);
863 flush_workqueue(mcast_wq
);
865 for (i
= 0; i
<= dev
->end_port
- dev
->start_port
; i
++) {
866 if (rdma_port_get_link_layer(device
, dev
->start_port
+ i
) ==
867 IB_LINK_LAYER_INFINIBAND
) {
868 port
= &dev
->port
[i
];
870 wait_for_completion(&port
->comp
);
881 mcast_wq
= create_singlethread_workqueue("ib_mcast");
885 ib_sa_register_client(&sa_client
);
887 ret
= ib_register_client(&mcast_client
);
893 ib_sa_unregister_client(&sa_client
);
894 destroy_workqueue(mcast_wq
);
898 void mcast_cleanup(void)
900 ib_unregister_client(&mcast_client
);
901 ib_sa_unregister_client(&sa_client
);
902 destroy_workqueue(mcast_wq
);