37 #include <linux/export.h>
38 #include <linux/slab.h>
39 #include <linux/bitops.h>
40 #include <linux/random.h>
49 .name =
"ib_multicast",
51 .remove = mcast_remove_one
139 ret =
memcmp(mgid->
raw, group->
rec.mgid.raw,
sizeof *mgid);
153 int allow_duplicates)
164 ret =
memcmp(group->
rec.mgid.raw, cur_group->
rec.mgid.raw,
165 sizeof group->
rec.mgid);
170 else if (allow_duplicates)
175 rb_link_node(&group->
node, parent, link);
180 static void deref_port(
struct mcast_port *port)
186 static void release_group(
struct mcast_group *group)
194 spin_unlock_irqrestore(&port->
lock, flags);
198 spin_unlock_irqrestore(&port->
lock, flags);
219 spin_unlock_irqrestore(&group->
lock, flags);
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)
248 for (i = 0; i < 3; i++)
250 leave_state |= (0x1 <<
i);
252 return leave_state & group->
rec.join_state;
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);
308 if (check_selector(comp_mask,
349 static int send_leave(
struct mcast_group *group,
u8 leave_state)
356 rec.join_state = leave_state;
365 group, &group->
query);
377 adjust_membership(group, join_state, 1);
387 spin_lock_irq(&group->
lock);
388 list_del_init(&member->
list);
389 spin_unlock_irq(&group->
lock);
393 static void process_group_error(
struct mcast_group *group)
401 group->
port->port_num,
404 spin_lock_irq(&group->
lock);
413 list_del_init(&member->
list);
414 adjust_membership(group, member->
multicast.rec.join_state, -1);
416 spin_unlock_irq(&group->
lock);
420 deref_member(member);
423 spin_lock_irq(&group->
lock);
426 group->
rec.join_state = 0;
429 spin_unlock_irq(&group->
lock);
442 spin_lock_irq(&group->
lock);
447 spin_unlock_irq(&group->
lock);
448 process_group_error(group);
455 join_state = multicast->
rec.join_state;
458 if (join_state == (group->
rec.join_state & join_state)) {
459 status = cmp_rec(&group->
rec, &multicast->
rec,
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);
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))
491 spin_unlock_irq(&group->
lock);
492 release_group(group);
499 static void process_join_error(
struct mcast_group *group,
int status)
504 spin_lock_irq(&group->
lock);
509 list_del_init(&member->
list);
510 spin_unlock_irq(&group->
lock);
512 deref_member(member);
516 spin_unlock_irq(&group->
lock);
526 process_join_error(group, status);
531 spin_lock_irq(&group->
port->lock);
536 if (!
memcmp(&mgid0, &group->
rec.mgid,
sizeof mgid0)) {
538 mcast_insert(group->
port, group, 1);
540 spin_unlock_irq(&group->
port->lock);
542 mcast_work_handler(&group->
work);
550 if (status && group->
retries > 0 &&
554 mcast_work_handler(&group->
work);
564 is_mgid0 = !
memcmp(&mgid0, mgid,
sizeof mgid0);
567 group = mcast_find(port, mgid);
570 spin_unlock_irqrestore(&port->
lock, flags);
573 group = kzalloc(
sizeof *group, gfp_mask);
579 group->
rec.mgid = *mgid;
587 cur_group = mcast_insert(port, group, is_mgid0);
595 spin_unlock_irqrestore(&port->
lock, flags);
624 member =
kmalloc(
sizeof *member, gfp_mask);
628 ib_sa_client_get(client);
634 init_completion(&member->
comp);
639 &rec->
mgid, gfp_mask);
640 if (!member->
group) {
656 ib_sa_client_put(client);
668 group = member->
group;
670 spin_lock_irq(&group->
lock);
672 adjust_membership(group, multicast->
rec.join_state, -1);
674 list_del_init(&member->
list);
678 spin_unlock_irq(&group->
lock);
682 spin_unlock_irq(&group->
lock);
683 release_group(group);
686 deref_member(member);
688 ib_sa_client_put(member->
client);
708 group = mcast_find(port, mgid);
713 spin_unlock_irqrestore(&port->
lock, flags);
731 memset(ah_attr, 0,
sizeof *ah_attr);
733 ah_attr->
sl = rec->
sl;
740 ah_attr->
grh.sgid_index = (
u8) gid_index;
749 static void mcast_groups_event(
struct mcast_port *port,
759 spin_lock(&group->
lock);
766 spin_unlock(&group->
lock);
768 spin_unlock_irqrestore(&port->
lock, flags);
782 index =
event->element.port_num - dev->
start_port;
784 switch (event->
event) {
799 static void mcast_add_one(
struct ib_device *device)
825 port = &dev->
port[
i];
830 init_completion(&port->
comp);
847 static void mcast_remove_one(
struct ib_device *device)
863 port = &dev->
port[
i];