2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * $Id: ipoib_multicast.c 1362 2004-12-18 15:56:29Z roland $
37 #include <linux/skbuff.h>
38 #include <linux/rtnetlink.h>
41 #include <linux/igmp.h>
42 #include <linux/inetdevice.h>
43 #include <linux/delay.h>
44 #include <linux/completion.h>
50 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
51 static int mcast_debug_level
;
53 module_param(mcast_debug_level
, int, 0644);
54 MODULE_PARM_DESC(mcast_debug_level
,
55 "Enable multicast debug tracing if > 0");
58 static DEFINE_MUTEX(mcast_mutex
);
60 /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
62 struct ib_sa_mcmember_rec mcmember
;
65 struct rb_node rb_node
;
66 struct list_head list
;
67 struct completion done
;
70 struct ib_sa_query
*query
;
72 unsigned long created
;
73 unsigned long backoff
;
76 unsigned char logcount
;
78 struct list_head neigh_list
;
80 struct sk_buff_head pkt_queue
;
82 struct net_device
*dev
;
85 struct ipoib_mcast_iter
{
86 struct net_device
*dev
;
88 unsigned long created
;
89 unsigned int queuelen
;
90 unsigned int complete
;
91 unsigned int send_only
;
94 static void ipoib_mcast_free(struct ipoib_mcast
*mcast
)
96 struct net_device
*dev
= mcast
->dev
;
97 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
98 struct ipoib_neigh
*neigh
, *tmp
;
102 ipoib_dbg_mcast(netdev_priv(dev
),
103 "deleting multicast group " IPOIB_GID_FMT
"\n",
104 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
106 spin_lock_irqsave(&priv
->lock
, flags
);
108 list_for_each_entry_safe(neigh
, tmp
, &mcast
->neigh_list
, list
) {
110 * It's safe to call ipoib_put_ah() inside priv->lock
111 * here, because we know that mcast->ah will always
112 * hold one more reference, so ipoib_put_ah() will
113 * never do more than decrement the ref count.
116 ipoib_put_ah(neigh
->ah
);
117 ipoib_neigh_free(neigh
);
120 spin_unlock_irqrestore(&priv
->lock
, flags
);
123 ipoib_put_ah(mcast
->ah
);
125 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
127 dev_kfree_skb_any(skb_dequeue(&mcast
->pkt_queue
));
130 spin_lock_irqsave(&priv
->tx_lock
, flags
);
131 priv
->stats
.tx_dropped
+= tx_dropped
;
132 spin_unlock_irqrestore(&priv
->tx_lock
, flags
);
137 static struct ipoib_mcast
*ipoib_mcast_alloc(struct net_device
*dev
,
140 struct ipoib_mcast
*mcast
;
142 mcast
= kzalloc(sizeof *mcast
, can_sleep
? GFP_KERNEL
: GFP_ATOMIC
);
147 mcast
->created
= jiffies
;
150 INIT_LIST_HEAD(&mcast
->list
);
151 INIT_LIST_HEAD(&mcast
->neigh_list
);
152 skb_queue_head_init(&mcast
->pkt_queue
);
157 static struct ipoib_mcast
*__ipoib_mcast_find(struct net_device
*dev
, void *mgid
)
159 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
160 struct rb_node
*n
= priv
->multicast_tree
.rb_node
;
163 struct ipoib_mcast
*mcast
;
166 mcast
= rb_entry(n
, struct ipoib_mcast
, rb_node
);
168 ret
= memcmp(mgid
, mcast
->mcmember
.mgid
.raw
,
169 sizeof (union ib_gid
));
181 static int __ipoib_mcast_add(struct net_device
*dev
, struct ipoib_mcast
*mcast
)
183 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
184 struct rb_node
**n
= &priv
->multicast_tree
.rb_node
, *pn
= NULL
;
187 struct ipoib_mcast
*tmcast
;
191 tmcast
= rb_entry(pn
, struct ipoib_mcast
, rb_node
);
193 ret
= memcmp(mcast
->mcmember
.mgid
.raw
, tmcast
->mcmember
.mgid
.raw
,
194 sizeof (union ib_gid
));
203 rb_link_node(&mcast
->rb_node
, pn
, n
);
204 rb_insert_color(&mcast
->rb_node
, &priv
->multicast_tree
);
209 static int ipoib_mcast_join_finish(struct ipoib_mcast
*mcast
,
210 struct ib_sa_mcmember_rec
*mcmember
)
212 struct net_device
*dev
= mcast
->dev
;
213 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
217 mcast
->mcmember
= *mcmember
;
219 /* Set the cached Q_Key before we attach if it's the broadcast group */
220 if (!memcmp(mcast
->mcmember
.mgid
.raw
, priv
->dev
->broadcast
+ 4,
221 sizeof (union ib_gid
))) {
222 priv
->qkey
= be32_to_cpu(priv
->broadcast
->mcmember
.qkey
);
223 priv
->tx_wr
.wr
.ud
.remote_qkey
= priv
->qkey
;
226 if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
227 if (test_and_set_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
)) {
228 ipoib_warn(priv
, "multicast group " IPOIB_GID_FMT
229 " already attached\n",
230 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
235 ret
= ipoib_mcast_attach(dev
, be16_to_cpu(mcast
->mcmember
.mlid
),
236 &mcast
->mcmember
.mgid
);
238 ipoib_warn(priv
, "couldn't attach QP to multicast group "
240 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
242 clear_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
);
248 struct ib_ah_attr av
= {
249 .dlid
= be16_to_cpu(mcast
->mcmember
.mlid
),
250 .port_num
= priv
->port
,
251 .sl
= mcast
->mcmember
.sl
,
252 .ah_flags
= IB_AH_GRH
,
253 .static_rate
= mcast
->mcmember
.rate
,
255 .flow_label
= be32_to_cpu(mcast
->mcmember
.flow_label
),
256 .hop_limit
= mcast
->mcmember
.hop_limit
,
258 .traffic_class
= mcast
->mcmember
.traffic_class
261 av
.grh
.dgid
= mcast
->mcmember
.mgid
;
263 ah
= ipoib_create_ah(dev
, priv
->pd
, &av
);
265 ipoib_warn(priv
, "ib_address_create failed\n");
267 spin_lock_irq(&priv
->lock
);
269 spin_unlock_irq(&priv
->lock
);
271 ipoib_dbg_mcast(priv
, "MGID " IPOIB_GID_FMT
272 " AV %p, LID 0x%04x, SL %d\n",
273 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
275 be16_to_cpu(mcast
->mcmember
.mlid
),
280 /* actually send any queued packets */
281 spin_lock_irq(&priv
->tx_lock
);
282 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
283 struct sk_buff
*skb
= skb_dequeue(&mcast
->pkt_queue
);
284 spin_unlock_irq(&priv
->tx_lock
);
288 if (!skb
->dst
|| !skb
->dst
->neighbour
) {
289 /* put pseudoheader back on for next time */
290 skb_push(skb
, sizeof (struct ipoib_pseudoheader
));
293 if (dev_queue_xmit(skb
))
294 ipoib_warn(priv
, "dev_queue_xmit failed to requeue packet\n");
295 spin_lock_irq(&priv
->tx_lock
);
297 spin_unlock_irq(&priv
->tx_lock
);
303 ipoib_mcast_sendonly_join_complete(int status
,
304 struct ib_sa_mcmember_rec
*mcmember
,
307 struct ipoib_mcast
*mcast
= mcast_ptr
;
308 struct net_device
*dev
= mcast
->dev
;
309 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
312 ipoib_mcast_join_finish(mcast
, mcmember
);
314 if (mcast
->logcount
++ < 20)
315 ipoib_dbg_mcast(netdev_priv(dev
), "multicast join failed for "
316 IPOIB_GID_FMT
", status %d\n",
317 IPOIB_GID_ARG(mcast
->mcmember
.mgid
), status
);
319 /* Flush out any queued packets */
320 spin_lock_irq(&priv
->tx_lock
);
321 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
322 ++priv
->stats
.tx_dropped
;
323 dev_kfree_skb_any(skb_dequeue(&mcast
->pkt_queue
));
325 spin_unlock_irq(&priv
->tx_lock
);
327 /* Clear the busy flag so we try again */
328 clear_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
);
332 complete(&mcast
->done
);
335 static int ipoib_mcast_sendonly_join(struct ipoib_mcast
*mcast
)
337 struct net_device
*dev
= mcast
->dev
;
338 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
339 struct ib_sa_mcmember_rec rec
= {
340 #if 0 /* Some SMs don't support send-only yet */
348 if (!test_bit(IPOIB_FLAG_OPER_UP
, &priv
->flags
)) {
349 ipoib_dbg_mcast(priv
, "device shutting down, no multicast joins\n");
353 if (test_and_set_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
)) {
354 ipoib_dbg_mcast(priv
, "multicast entry busy, skipping\n");
358 rec
.mgid
= mcast
->mcmember
.mgid
;
359 rec
.port_gid
= priv
->local_gid
;
360 rec
.pkey
= cpu_to_be16(priv
->pkey
);
362 init_completion(&mcast
->done
);
364 ret
= ib_sa_mcmember_rec_set(&ipoib_sa_client
, priv
->ca
, priv
->port
, &rec
,
365 IB_SA_MCMEMBER_REC_MGID
|
366 IB_SA_MCMEMBER_REC_PORT_GID
|
367 IB_SA_MCMEMBER_REC_PKEY
|
368 IB_SA_MCMEMBER_REC_JOIN_STATE
,
370 ipoib_mcast_sendonly_join_complete
,
371 mcast
, &mcast
->query
);
373 ipoib_warn(priv
, "ib_sa_mcmember_rec_set failed (ret = %d)\n",
376 ipoib_dbg_mcast(priv
, "no multicast record for " IPOIB_GID_FMT
378 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
380 mcast
->query_id
= ret
;
386 static void ipoib_mcast_join_complete(int status
,
387 struct ib_sa_mcmember_rec
*mcmember
,
390 struct ipoib_mcast
*mcast
= mcast_ptr
;
391 struct net_device
*dev
= mcast
->dev
;
392 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
394 ipoib_dbg_mcast(priv
, "join completion for " IPOIB_GID_FMT
396 IPOIB_GID_ARG(mcast
->mcmember
.mgid
), status
);
398 if (!status
&& !ipoib_mcast_join_finish(mcast
, mcmember
)) {
400 mutex_lock(&mcast_mutex
);
401 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
402 queue_work(ipoib_workqueue
, &priv
->mcast_task
);
403 mutex_unlock(&mcast_mutex
);
404 complete(&mcast
->done
);
408 if (status
== -EINTR
) {
409 complete(&mcast
->done
);
413 if (status
&& mcast
->logcount
++ < 20) {
414 if (status
== -ETIMEDOUT
|| status
== -EINTR
) {
415 ipoib_dbg_mcast(priv
, "multicast join failed for " IPOIB_GID_FMT
417 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
420 ipoib_warn(priv
, "multicast join failed for "
421 IPOIB_GID_FMT
", status %d\n",
422 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
428 if (mcast
->backoff
> IPOIB_MAX_BACKOFF_SECONDS
)
429 mcast
->backoff
= IPOIB_MAX_BACKOFF_SECONDS
;
431 mutex_lock(&mcast_mutex
);
433 spin_lock_irq(&priv
->lock
);
436 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
)) {
437 if (status
== -ETIMEDOUT
)
438 queue_work(ipoib_workqueue
, &priv
->mcast_task
);
440 queue_delayed_work(ipoib_workqueue
, &priv
->mcast_task
,
441 mcast
->backoff
* HZ
);
443 complete(&mcast
->done
);
444 spin_unlock_irq(&priv
->lock
);
445 mutex_unlock(&mcast_mutex
);
450 static void ipoib_mcast_join(struct net_device
*dev
, struct ipoib_mcast
*mcast
,
453 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
454 struct ib_sa_mcmember_rec rec
= {
457 ib_sa_comp_mask comp_mask
;
460 ipoib_dbg_mcast(priv
, "joining MGID " IPOIB_GID_FMT
"\n",
461 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
463 rec
.mgid
= mcast
->mcmember
.mgid
;
464 rec
.port_gid
= priv
->local_gid
;
465 rec
.pkey
= cpu_to_be16(priv
->pkey
);
468 IB_SA_MCMEMBER_REC_MGID
|
469 IB_SA_MCMEMBER_REC_PORT_GID
|
470 IB_SA_MCMEMBER_REC_PKEY
|
471 IB_SA_MCMEMBER_REC_JOIN_STATE
;
475 IB_SA_MCMEMBER_REC_QKEY
|
476 IB_SA_MCMEMBER_REC_MTU_SELECTOR
|
477 IB_SA_MCMEMBER_REC_MTU
|
478 IB_SA_MCMEMBER_REC_TRAFFIC_CLASS
|
479 IB_SA_MCMEMBER_REC_RATE_SELECTOR
|
480 IB_SA_MCMEMBER_REC_RATE
|
481 IB_SA_MCMEMBER_REC_SL
|
482 IB_SA_MCMEMBER_REC_FLOW_LABEL
|
483 IB_SA_MCMEMBER_REC_HOP_LIMIT
;
485 rec
.qkey
= priv
->broadcast
->mcmember
.qkey
;
486 rec
.mtu_selector
= IB_SA_EQ
;
487 rec
.mtu
= priv
->broadcast
->mcmember
.mtu
;
488 rec
.traffic_class
= priv
->broadcast
->mcmember
.traffic_class
;
489 rec
.rate_selector
= IB_SA_EQ
;
490 rec
.rate
= priv
->broadcast
->mcmember
.rate
;
491 rec
.sl
= priv
->broadcast
->mcmember
.sl
;
492 rec
.flow_label
= priv
->broadcast
->mcmember
.flow_label
;
493 rec
.hop_limit
= priv
->broadcast
->mcmember
.hop_limit
;
496 init_completion(&mcast
->done
);
498 ret
= ib_sa_mcmember_rec_set(&ipoib_sa_client
, priv
->ca
, priv
->port
,
499 &rec
, comp_mask
, mcast
->backoff
* 1000,
500 GFP_ATOMIC
, ipoib_mcast_join_complete
,
501 mcast
, &mcast
->query
);
504 ipoib_warn(priv
, "ib_sa_mcmember_rec_set failed, status %d\n", ret
);
507 if (mcast
->backoff
> IPOIB_MAX_BACKOFF_SECONDS
)
508 mcast
->backoff
= IPOIB_MAX_BACKOFF_SECONDS
;
510 mutex_lock(&mcast_mutex
);
511 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
512 queue_delayed_work(ipoib_workqueue
,
514 mcast
->backoff
* HZ
);
515 mutex_unlock(&mcast_mutex
);
517 mcast
->query_id
= ret
;
520 void ipoib_mcast_join_task(void *dev_ptr
)
522 struct net_device
*dev
= dev_ptr
;
523 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
525 if (!test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
528 if (ib_query_gid(priv
->ca
, priv
->port
, 0, &priv
->local_gid
))
529 ipoib_warn(priv
, "ib_gid_entry_get() failed\n");
531 memcpy(priv
->dev
->dev_addr
+ 4, priv
->local_gid
.raw
, sizeof (union ib_gid
));
534 struct ib_port_attr attr
;
536 if (!ib_query_port(priv
->ca
, priv
->port
, &attr
)) {
537 priv
->local_lid
= attr
.lid
;
538 priv
->local_rate
= attr
.active_speed
*
539 ib_width_enum_to_int(attr
.active_width
);
541 ipoib_warn(priv
, "ib_query_port failed\n");
544 if (!priv
->broadcast
) {
545 struct ipoib_mcast
*broadcast
;
547 broadcast
= ipoib_mcast_alloc(dev
, 1);
549 ipoib_warn(priv
, "failed to allocate broadcast group\n");
550 mutex_lock(&mcast_mutex
);
551 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
552 queue_delayed_work(ipoib_workqueue
,
553 &priv
->mcast_task
, HZ
);
554 mutex_unlock(&mcast_mutex
);
558 spin_lock_irq(&priv
->lock
);
559 memcpy(broadcast
->mcmember
.mgid
.raw
, priv
->dev
->broadcast
+ 4,
560 sizeof (union ib_gid
));
561 priv
->broadcast
= broadcast
;
563 __ipoib_mcast_add(dev
, priv
->broadcast
);
564 spin_unlock_irq(&priv
->lock
);
567 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &priv
->broadcast
->flags
)) {
568 ipoib_mcast_join(dev
, priv
->broadcast
, 0);
573 struct ipoib_mcast
*mcast
= NULL
;
575 spin_lock_irq(&priv
->lock
);
576 list_for_each_entry(mcast
, &priv
->multicast_list
, list
) {
577 if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)
578 && !test_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
)
579 && !test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
)) {
580 /* Found the next unjoined group */
584 spin_unlock_irq(&priv
->lock
);
586 if (&mcast
->list
== &priv
->multicast_list
) {
591 ipoib_mcast_join(dev
, mcast
, 1);
595 priv
->mcast_mtu
= ib_mtu_enum_to_int(priv
->broadcast
->mcmember
.mtu
) -
597 dev
->mtu
= min(priv
->mcast_mtu
, priv
->admin_mtu
);
599 ipoib_dbg_mcast(priv
, "successfully joined all multicast groups\n");
601 clear_bit(IPOIB_MCAST_RUN
, &priv
->flags
);
602 netif_carrier_on(dev
);
605 int ipoib_mcast_start_thread(struct net_device
*dev
)
607 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
609 ipoib_dbg_mcast(priv
, "starting multicast thread\n");
611 mutex_lock(&mcast_mutex
);
612 if (!test_and_set_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
613 queue_work(ipoib_workqueue
, &priv
->mcast_task
);
614 mutex_unlock(&mcast_mutex
);
616 spin_lock_irq(&priv
->lock
);
617 set_bit(IPOIB_MCAST_STARTED
, &priv
->flags
);
618 spin_unlock_irq(&priv
->lock
);
623 static void wait_for_mcast_join(struct ipoib_dev_priv
*priv
,
624 struct ipoib_mcast
*mcast
)
626 spin_lock_irq(&priv
->lock
);
627 if (mcast
&& mcast
->query
) {
628 ib_sa_cancel_query(mcast
->query_id
, mcast
->query
);
630 spin_unlock_irq(&priv
->lock
);
631 ipoib_dbg_mcast(priv
, "waiting for MGID " IPOIB_GID_FMT
"\n",
632 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
633 wait_for_completion(&mcast
->done
);
636 spin_unlock_irq(&priv
->lock
);
639 int ipoib_mcast_stop_thread(struct net_device
*dev
, int flush
)
641 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
642 struct ipoib_mcast
*mcast
;
644 ipoib_dbg_mcast(priv
, "stopping multicast thread\n");
646 spin_lock_irq(&priv
->lock
);
647 clear_bit(IPOIB_MCAST_STARTED
, &priv
->flags
);
648 spin_unlock_irq(&priv
->lock
);
650 mutex_lock(&mcast_mutex
);
651 clear_bit(IPOIB_MCAST_RUN
, &priv
->flags
);
652 cancel_delayed_work(&priv
->mcast_task
);
653 mutex_unlock(&mcast_mutex
);
656 flush_workqueue(ipoib_workqueue
);
658 wait_for_mcast_join(priv
, priv
->broadcast
);
660 list_for_each_entry(mcast
, &priv
->multicast_list
, list
)
661 wait_for_mcast_join(priv
, mcast
);
666 static int ipoib_mcast_leave(struct net_device
*dev
, struct ipoib_mcast
*mcast
)
668 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
669 struct ib_sa_mcmember_rec rec
= {
674 if (!test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
))
677 ipoib_dbg_mcast(priv
, "leaving MGID " IPOIB_GID_FMT
"\n",
678 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
680 rec
.mgid
= mcast
->mcmember
.mgid
;
681 rec
.port_gid
= priv
->local_gid
;
682 rec
.pkey
= cpu_to_be16(priv
->pkey
);
684 /* Remove ourselves from the multicast group */
685 ret
= ipoib_mcast_detach(dev
, be16_to_cpu(mcast
->mcmember
.mlid
),
686 &mcast
->mcmember
.mgid
);
688 ipoib_warn(priv
, "ipoib_mcast_detach failed (result = %d)\n", ret
);
691 * Just make one shot at leaving and don't wait for a reply;
692 * if we fail, too bad.
694 ret
= ib_sa_mcmember_rec_delete(&ipoib_sa_client
, priv
->ca
, priv
->port
, &rec
,
695 IB_SA_MCMEMBER_REC_MGID
|
696 IB_SA_MCMEMBER_REC_PORT_GID
|
697 IB_SA_MCMEMBER_REC_PKEY
|
698 IB_SA_MCMEMBER_REC_JOIN_STATE
,
700 mcast
, &mcast
->query
);
702 ipoib_warn(priv
, "ib_sa_mcmember_rec_delete failed "
703 "for leave (result = %d)\n", ret
);
708 void ipoib_mcast_send(struct net_device
*dev
, void *mgid
, struct sk_buff
*skb
)
710 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
711 struct ipoib_mcast
*mcast
;
714 * We can only be called from ipoib_start_xmit, so we're
715 * inside tx_lock -- no need to save/restore flags.
717 spin_lock(&priv
->lock
);
719 if (!test_bit(IPOIB_MCAST_STARTED
, &priv
->flags
) ||
721 !test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &priv
->broadcast
->flags
)) {
722 ++priv
->stats
.tx_dropped
;
723 dev_kfree_skb_any(skb
);
727 mcast
= __ipoib_mcast_find(dev
, mgid
);
729 /* Let's create a new send only group now */
730 ipoib_dbg_mcast(priv
, "setting up send only multicast group for "
731 IPOIB_GID_FMT
"\n", IPOIB_GID_RAW_ARG(mgid
));
733 mcast
= ipoib_mcast_alloc(dev
, 0);
735 ipoib_warn(priv
, "unable to allocate memory for "
736 "multicast structure\n");
737 ++priv
->stats
.tx_dropped
;
738 dev_kfree_skb_any(skb
);
742 set_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
);
743 memcpy(mcast
->mcmember
.mgid
.raw
, mgid
, sizeof (union ib_gid
));
744 __ipoib_mcast_add(dev
, mcast
);
745 list_add_tail(&mcast
->list
, &priv
->multicast_list
);
749 if (skb_queue_len(&mcast
->pkt_queue
) < IPOIB_MAX_MCAST_QUEUE
)
750 skb_queue_tail(&mcast
->pkt_queue
, skb
);
752 ++priv
->stats
.tx_dropped
;
753 dev_kfree_skb_any(skb
);
757 ipoib_dbg_mcast(priv
, "no address vector, "
758 "but multicast join already started\n");
759 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
))
760 ipoib_mcast_sendonly_join(mcast
);
763 * If lookup completes between here and out:, don't
764 * want to send packet twice.
770 if (mcast
&& mcast
->ah
) {
772 skb
->dst
->neighbour
&&
773 !*to_ipoib_neigh(skb
->dst
->neighbour
)) {
774 struct ipoib_neigh
*neigh
= ipoib_neigh_alloc(skb
->dst
->neighbour
);
777 kref_get(&mcast
->ah
->ref
);
778 neigh
->ah
= mcast
->ah
;
779 list_add_tail(&neigh
->list
, &mcast
->neigh_list
);
783 ipoib_send(dev
, skb
, mcast
->ah
, IB_MULTICAST_QPN
);
787 spin_unlock(&priv
->lock
);
790 void ipoib_mcast_dev_flush(struct net_device
*dev
)
792 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
793 LIST_HEAD(remove_list
);
794 struct ipoib_mcast
*mcast
, *tmcast
;
797 ipoib_dbg_mcast(priv
, "flushing multicast list\n");
799 spin_lock_irqsave(&priv
->lock
, flags
);
801 list_for_each_entry_safe(mcast
, tmcast
, &priv
->multicast_list
, list
) {
802 list_del(&mcast
->list
);
803 rb_erase(&mcast
->rb_node
, &priv
->multicast_tree
);
804 list_add_tail(&mcast
->list
, &remove_list
);
807 if (priv
->broadcast
) {
808 rb_erase(&priv
->broadcast
->rb_node
, &priv
->multicast_tree
);
809 list_add_tail(&priv
->broadcast
->list
, &remove_list
);
810 priv
->broadcast
= NULL
;
813 spin_unlock_irqrestore(&priv
->lock
, flags
);
815 list_for_each_entry_safe(mcast
, tmcast
, &remove_list
, list
) {
816 ipoib_mcast_leave(dev
, mcast
);
817 ipoib_mcast_free(mcast
);
821 void ipoib_mcast_restart_task(void *dev_ptr
)
823 struct net_device
*dev
= dev_ptr
;
824 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
825 struct dev_mc_list
*mclist
;
826 struct ipoib_mcast
*mcast
, *tmcast
;
827 LIST_HEAD(remove_list
);
830 ipoib_dbg_mcast(priv
, "restarting multicast task\n");
832 ipoib_mcast_stop_thread(dev
, 0);
834 local_irq_save(flags
);
836 spin_lock(&priv
->lock
);
839 * Unfortunately, the networking core only gives us a list of all of
840 * the multicast hardware addresses. We need to figure out which ones
841 * are new and which ones have been removed
844 /* Clear out the found flag */
845 list_for_each_entry(mcast
, &priv
->multicast_list
, list
)
846 clear_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
);
848 /* Mark all of the entries that are found or don't exist */
849 for (mclist
= dev
->mc_list
; mclist
; mclist
= mclist
->next
) {
852 memcpy(mgid
.raw
, mclist
->dmi_addr
+ 4, sizeof mgid
);
854 /* Add in the P_Key */
855 mgid
.raw
[4] = (priv
->pkey
>> 8) & 0xff;
856 mgid
.raw
[5] = priv
->pkey
& 0xff;
858 mcast
= __ipoib_mcast_find(dev
, &mgid
);
859 if (!mcast
|| test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
860 struct ipoib_mcast
*nmcast
;
862 /* Not found or send-only group, let's add a new entry */
863 ipoib_dbg_mcast(priv
, "adding multicast entry for mgid "
864 IPOIB_GID_FMT
"\n", IPOIB_GID_ARG(mgid
));
866 nmcast
= ipoib_mcast_alloc(dev
, 0);
868 ipoib_warn(priv
, "unable to allocate memory for multicast structure\n");
872 set_bit(IPOIB_MCAST_FLAG_FOUND
, &nmcast
->flags
);
874 nmcast
->mcmember
.mgid
= mgid
;
877 /* Destroy the send only entry */
878 list_move_tail(&mcast
->list
, &remove_list
);
880 rb_replace_node(&mcast
->rb_node
,
882 &priv
->multicast_tree
);
884 __ipoib_mcast_add(dev
, nmcast
);
886 list_add_tail(&nmcast
->list
, &priv
->multicast_list
);
890 set_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
);
893 /* Remove all of the entries don't exist anymore */
894 list_for_each_entry_safe(mcast
, tmcast
, &priv
->multicast_list
, list
) {
895 if (!test_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
) &&
896 !test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
897 ipoib_dbg_mcast(priv
, "deleting multicast group " IPOIB_GID_FMT
"\n",
898 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
900 rb_erase(&mcast
->rb_node
, &priv
->multicast_tree
);
902 /* Move to the remove list */
903 list_move_tail(&mcast
->list
, &remove_list
);
907 spin_unlock(&priv
->lock
);
908 netif_tx_unlock(dev
);
909 local_irq_restore(flags
);
911 /* We have to cancel outside of the spinlock */
912 list_for_each_entry_safe(mcast
, tmcast
, &remove_list
, list
) {
913 wait_for_mcast_join(priv
, mcast
);
914 ipoib_mcast_leave(mcast
->dev
, mcast
);
915 ipoib_mcast_free(mcast
);
918 if (test_bit(IPOIB_FLAG_ADMIN_UP
, &priv
->flags
))
919 ipoib_mcast_start_thread(dev
);
922 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
924 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
)
926 struct ipoib_mcast_iter
*iter
;
928 iter
= kmalloc(sizeof *iter
, GFP_KERNEL
);
933 memset(iter
->mgid
.raw
, 0, 16);
935 if (ipoib_mcast_iter_next(iter
)) {
943 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
)
945 struct ipoib_dev_priv
*priv
= netdev_priv(iter
->dev
);
947 struct ipoib_mcast
*mcast
;
950 spin_lock_irq(&priv
->lock
);
952 n
= rb_first(&priv
->multicast_tree
);
955 mcast
= rb_entry(n
, struct ipoib_mcast
, rb_node
);
957 if (memcmp(iter
->mgid
.raw
, mcast
->mcmember
.mgid
.raw
,
958 sizeof (union ib_gid
)) < 0) {
959 iter
->mgid
= mcast
->mcmember
.mgid
;
960 iter
->created
= mcast
->created
;
961 iter
->queuelen
= skb_queue_len(&mcast
->pkt_queue
);
962 iter
->complete
= !!mcast
->ah
;
963 iter
->send_only
= !!(mcast
->flags
& (1 << IPOIB_MCAST_FLAG_SENDONLY
));
973 spin_unlock_irq(&priv
->lock
);
978 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
980 unsigned long *created
,
981 unsigned int *queuelen
,
982 unsigned int *complete
,
983 unsigned int *send_only
)
986 *created
= iter
->created
;
987 *queuelen
= iter
->queuelen
;
988 *complete
= iter
->complete
;
989 *send_only
= iter
->send_only
;
992 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */