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 struct ipoib_mcast_iter
{
61 struct net_device
*dev
;
63 unsigned long created
;
64 unsigned int queuelen
;
65 unsigned int complete
;
66 unsigned int send_only
;
69 static void ipoib_mcast_free(struct ipoib_mcast
*mcast
)
71 struct net_device
*dev
= mcast
->dev
;
72 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
73 struct ipoib_neigh
*neigh
, *tmp
;
77 ipoib_dbg_mcast(netdev_priv(dev
),
78 "deleting multicast group " IPOIB_GID_FMT
"\n",
79 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
81 spin_lock_irqsave(&priv
->lock
, flags
);
83 list_for_each_entry_safe(neigh
, tmp
, &mcast
->neigh_list
, list
) {
85 * It's safe to call ipoib_put_ah() inside priv->lock
86 * here, because we know that mcast->ah will always
87 * hold one more reference, so ipoib_put_ah() will
88 * never do more than decrement the ref count.
91 ipoib_put_ah(neigh
->ah
);
92 ipoib_neigh_free(dev
, neigh
);
95 spin_unlock_irqrestore(&priv
->lock
, flags
);
98 ipoib_put_ah(mcast
->ah
);
100 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
102 dev_kfree_skb_any(skb_dequeue(&mcast
->pkt_queue
));
105 spin_lock_irqsave(&priv
->tx_lock
, flags
);
106 dev
->stats
.tx_dropped
+= tx_dropped
;
107 spin_unlock_irqrestore(&priv
->tx_lock
, flags
);
112 static struct ipoib_mcast
*ipoib_mcast_alloc(struct net_device
*dev
,
115 struct ipoib_mcast
*mcast
;
117 mcast
= kzalloc(sizeof *mcast
, can_sleep
? GFP_KERNEL
: GFP_ATOMIC
);
122 mcast
->created
= jiffies
;
125 INIT_LIST_HEAD(&mcast
->list
);
126 INIT_LIST_HEAD(&mcast
->neigh_list
);
127 skb_queue_head_init(&mcast
->pkt_queue
);
132 static struct ipoib_mcast
*__ipoib_mcast_find(struct net_device
*dev
, void *mgid
)
134 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
135 struct rb_node
*n
= priv
->multicast_tree
.rb_node
;
138 struct ipoib_mcast
*mcast
;
141 mcast
= rb_entry(n
, struct ipoib_mcast
, rb_node
);
143 ret
= memcmp(mgid
, mcast
->mcmember
.mgid
.raw
,
144 sizeof (union ib_gid
));
156 static int __ipoib_mcast_add(struct net_device
*dev
, struct ipoib_mcast
*mcast
)
158 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
159 struct rb_node
**n
= &priv
->multicast_tree
.rb_node
, *pn
= NULL
;
162 struct ipoib_mcast
*tmcast
;
166 tmcast
= rb_entry(pn
, struct ipoib_mcast
, rb_node
);
168 ret
= memcmp(mcast
->mcmember
.mgid
.raw
, tmcast
->mcmember
.mgid
.raw
,
169 sizeof (union ib_gid
));
178 rb_link_node(&mcast
->rb_node
, pn
, n
);
179 rb_insert_color(&mcast
->rb_node
, &priv
->multicast_tree
);
184 static int ipoib_mcast_join_finish(struct ipoib_mcast
*mcast
,
185 struct ib_sa_mcmember_rec
*mcmember
)
187 struct net_device
*dev
= mcast
->dev
;
188 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
192 mcast
->mcmember
= *mcmember
;
194 /* Set the cached Q_Key before we attach if it's the broadcast group */
195 if (!memcmp(mcast
->mcmember
.mgid
.raw
, priv
->dev
->broadcast
+ 4,
196 sizeof (union ib_gid
))) {
197 priv
->qkey
= be32_to_cpu(priv
->broadcast
->mcmember
.qkey
);
198 priv
->tx_wr
.wr
.ud
.remote_qkey
= priv
->qkey
;
201 if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
202 if (test_and_set_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
)) {
203 ipoib_warn(priv
, "multicast group " IPOIB_GID_FMT
204 " already attached\n",
205 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
210 ret
= ipoib_mcast_attach(dev
, be16_to_cpu(mcast
->mcmember
.mlid
),
211 &mcast
->mcmember
.mgid
);
213 ipoib_warn(priv
, "couldn't attach QP to multicast group "
215 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
217 clear_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
);
223 struct ib_ah_attr av
= {
224 .dlid
= be16_to_cpu(mcast
->mcmember
.mlid
),
225 .port_num
= priv
->port
,
226 .sl
= mcast
->mcmember
.sl
,
227 .ah_flags
= IB_AH_GRH
,
228 .static_rate
= mcast
->mcmember
.rate
,
230 .flow_label
= be32_to_cpu(mcast
->mcmember
.flow_label
),
231 .hop_limit
= mcast
->mcmember
.hop_limit
,
233 .traffic_class
= mcast
->mcmember
.traffic_class
236 av
.grh
.dgid
= mcast
->mcmember
.mgid
;
238 ah
= ipoib_create_ah(dev
, priv
->pd
, &av
);
240 ipoib_warn(priv
, "ib_address_create failed\n");
242 spin_lock_irq(&priv
->lock
);
244 spin_unlock_irq(&priv
->lock
);
246 ipoib_dbg_mcast(priv
, "MGID " IPOIB_GID_FMT
247 " AV %p, LID 0x%04x, SL %d\n",
248 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
250 be16_to_cpu(mcast
->mcmember
.mlid
),
255 /* actually send any queued packets */
256 spin_lock_irq(&priv
->tx_lock
);
257 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
258 struct sk_buff
*skb
= skb_dequeue(&mcast
->pkt_queue
);
259 spin_unlock_irq(&priv
->tx_lock
);
263 if (!skb
->dst
|| !skb
->dst
->neighbour
) {
264 /* put pseudoheader back on for next time */
265 skb_push(skb
, sizeof (struct ipoib_pseudoheader
));
268 if (dev_queue_xmit(skb
))
269 ipoib_warn(priv
, "dev_queue_xmit failed to requeue packet\n");
270 spin_lock_irq(&priv
->tx_lock
);
272 spin_unlock_irq(&priv
->tx_lock
);
278 ipoib_mcast_sendonly_join_complete(int status
,
279 struct ib_sa_multicast
*multicast
)
281 struct ipoib_mcast
*mcast
= multicast
->context
;
282 struct net_device
*dev
= mcast
->dev
;
283 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
285 /* We trap for port events ourselves. */
286 if (status
== -ENETRESET
)
290 status
= ipoib_mcast_join_finish(mcast
, &multicast
->rec
);
293 if (mcast
->logcount
++ < 20)
294 ipoib_dbg_mcast(netdev_priv(dev
), "multicast join failed for "
295 IPOIB_GID_FMT
", status %d\n",
296 IPOIB_GID_ARG(mcast
->mcmember
.mgid
), status
);
298 /* Flush out any queued packets */
299 spin_lock_irq(&priv
->tx_lock
);
300 while (!skb_queue_empty(&mcast
->pkt_queue
)) {
301 ++dev
->stats
.tx_dropped
;
302 dev_kfree_skb_any(skb_dequeue(&mcast
->pkt_queue
));
304 spin_unlock_irq(&priv
->tx_lock
);
306 /* Clear the busy flag so we try again */
307 status
= test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY
,
313 static int ipoib_mcast_sendonly_join(struct ipoib_mcast
*mcast
)
315 struct net_device
*dev
= mcast
->dev
;
316 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
317 struct ib_sa_mcmember_rec rec
= {
318 #if 0 /* Some SMs don't support send-only yet */
326 if (!test_bit(IPOIB_FLAG_OPER_UP
, &priv
->flags
)) {
327 ipoib_dbg_mcast(priv
, "device shutting down, no multicast joins\n");
331 if (test_and_set_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
)) {
332 ipoib_dbg_mcast(priv
, "multicast entry busy, skipping\n");
336 rec
.mgid
= mcast
->mcmember
.mgid
;
337 rec
.port_gid
= priv
->local_gid
;
338 rec
.pkey
= cpu_to_be16(priv
->pkey
);
340 mcast
->mc
= ib_sa_join_multicast(&ipoib_sa_client
, priv
->ca
,
342 IB_SA_MCMEMBER_REC_MGID
|
343 IB_SA_MCMEMBER_REC_PORT_GID
|
344 IB_SA_MCMEMBER_REC_PKEY
|
345 IB_SA_MCMEMBER_REC_JOIN_STATE
,
347 ipoib_mcast_sendonly_join_complete
,
349 if (IS_ERR(mcast
->mc
)) {
350 ret
= PTR_ERR(mcast
->mc
);
351 clear_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
);
352 ipoib_warn(priv
, "ib_sa_join_multicast failed (ret = %d)\n",
355 ipoib_dbg_mcast(priv
, "no multicast record for " IPOIB_GID_FMT
357 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
363 static int ipoib_mcast_join_complete(int status
,
364 struct ib_sa_multicast
*multicast
)
366 struct ipoib_mcast
*mcast
= multicast
->context
;
367 struct net_device
*dev
= mcast
->dev
;
368 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
370 ipoib_dbg_mcast(priv
, "join completion for " IPOIB_GID_FMT
372 IPOIB_GID_ARG(mcast
->mcmember
.mgid
), status
);
374 /* We trap for port events ourselves. */
375 if (status
== -ENETRESET
)
379 status
= ipoib_mcast_join_finish(mcast
, &multicast
->rec
);
383 mutex_lock(&mcast_mutex
);
384 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
385 queue_delayed_work(ipoib_workqueue
,
386 &priv
->mcast_task
, 0);
387 mutex_unlock(&mcast_mutex
);
389 if (mcast
== priv
->broadcast
)
390 netif_carrier_on(dev
);
395 if (mcast
->logcount
++ < 20) {
396 if (status
== -ETIMEDOUT
) {
397 ipoib_dbg_mcast(priv
, "multicast join failed for " IPOIB_GID_FMT
399 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
402 ipoib_warn(priv
, "multicast join failed for "
403 IPOIB_GID_FMT
", status %d\n",
404 IPOIB_GID_ARG(mcast
->mcmember
.mgid
),
410 if (mcast
->backoff
> IPOIB_MAX_BACKOFF_SECONDS
)
411 mcast
->backoff
= IPOIB_MAX_BACKOFF_SECONDS
;
413 /* Clear the busy flag so we try again */
414 status
= test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
);
416 mutex_lock(&mcast_mutex
);
417 spin_lock_irq(&priv
->lock
);
418 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
419 queue_delayed_work(ipoib_workqueue
, &priv
->mcast_task
,
420 mcast
->backoff
* HZ
);
421 spin_unlock_irq(&priv
->lock
);
422 mutex_unlock(&mcast_mutex
);
427 static void ipoib_mcast_join(struct net_device
*dev
, struct ipoib_mcast
*mcast
,
430 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
431 struct ib_sa_mcmember_rec rec
= {
434 ib_sa_comp_mask comp_mask
;
437 ipoib_dbg_mcast(priv
, "joining MGID " IPOIB_GID_FMT
"\n",
438 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
440 rec
.mgid
= mcast
->mcmember
.mgid
;
441 rec
.port_gid
= priv
->local_gid
;
442 rec
.pkey
= cpu_to_be16(priv
->pkey
);
445 IB_SA_MCMEMBER_REC_MGID
|
446 IB_SA_MCMEMBER_REC_PORT_GID
|
447 IB_SA_MCMEMBER_REC_PKEY
|
448 IB_SA_MCMEMBER_REC_JOIN_STATE
;
452 IB_SA_MCMEMBER_REC_QKEY
|
453 IB_SA_MCMEMBER_REC_MTU_SELECTOR
|
454 IB_SA_MCMEMBER_REC_MTU
|
455 IB_SA_MCMEMBER_REC_TRAFFIC_CLASS
|
456 IB_SA_MCMEMBER_REC_RATE_SELECTOR
|
457 IB_SA_MCMEMBER_REC_RATE
|
458 IB_SA_MCMEMBER_REC_SL
|
459 IB_SA_MCMEMBER_REC_FLOW_LABEL
|
460 IB_SA_MCMEMBER_REC_HOP_LIMIT
;
462 rec
.qkey
= priv
->broadcast
->mcmember
.qkey
;
463 rec
.mtu_selector
= IB_SA_EQ
;
464 rec
.mtu
= priv
->broadcast
->mcmember
.mtu
;
465 rec
.traffic_class
= priv
->broadcast
->mcmember
.traffic_class
;
466 rec
.rate_selector
= IB_SA_EQ
;
467 rec
.rate
= priv
->broadcast
->mcmember
.rate
;
468 rec
.sl
= priv
->broadcast
->mcmember
.sl
;
469 rec
.flow_label
= priv
->broadcast
->mcmember
.flow_label
;
470 rec
.hop_limit
= priv
->broadcast
->mcmember
.hop_limit
;
473 set_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
);
474 mcast
->mc
= ib_sa_join_multicast(&ipoib_sa_client
, priv
->ca
, priv
->port
,
475 &rec
, comp_mask
, GFP_KERNEL
,
476 ipoib_mcast_join_complete
, mcast
);
477 if (IS_ERR(mcast
->mc
)) {
478 clear_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
);
479 ret
= PTR_ERR(mcast
->mc
);
480 ipoib_warn(priv
, "ib_sa_join_multicast failed, status %d\n", ret
);
483 if (mcast
->backoff
> IPOIB_MAX_BACKOFF_SECONDS
)
484 mcast
->backoff
= IPOIB_MAX_BACKOFF_SECONDS
;
486 mutex_lock(&mcast_mutex
);
487 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
488 queue_delayed_work(ipoib_workqueue
,
490 mcast
->backoff
* HZ
);
491 mutex_unlock(&mcast_mutex
);
495 void ipoib_mcast_join_task(struct work_struct
*work
)
497 struct ipoib_dev_priv
*priv
=
498 container_of(work
, struct ipoib_dev_priv
, mcast_task
.work
);
499 struct net_device
*dev
= priv
->dev
;
501 if (!test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
504 if (ib_query_gid(priv
->ca
, priv
->port
, 0, &priv
->local_gid
))
505 ipoib_warn(priv
, "ib_query_gid() failed\n");
507 memcpy(priv
->dev
->dev_addr
+ 4, priv
->local_gid
.raw
, sizeof (union ib_gid
));
510 struct ib_port_attr attr
;
512 if (!ib_query_port(priv
->ca
, priv
->port
, &attr
))
513 priv
->local_lid
= attr
.lid
;
515 ipoib_warn(priv
, "ib_query_port failed\n");
518 if (!priv
->broadcast
) {
519 struct ipoib_mcast
*broadcast
;
521 broadcast
= ipoib_mcast_alloc(dev
, 1);
523 ipoib_warn(priv
, "failed to allocate broadcast group\n");
524 mutex_lock(&mcast_mutex
);
525 if (test_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
526 queue_delayed_work(ipoib_workqueue
,
527 &priv
->mcast_task
, HZ
);
528 mutex_unlock(&mcast_mutex
);
532 spin_lock_irq(&priv
->lock
);
533 memcpy(broadcast
->mcmember
.mgid
.raw
, priv
->dev
->broadcast
+ 4,
534 sizeof (union ib_gid
));
535 priv
->broadcast
= broadcast
;
537 __ipoib_mcast_add(dev
, priv
->broadcast
);
538 spin_unlock_irq(&priv
->lock
);
541 if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &priv
->broadcast
->flags
)) {
542 if (!test_bit(IPOIB_MCAST_FLAG_BUSY
, &priv
->broadcast
->flags
))
543 ipoib_mcast_join(dev
, priv
->broadcast
, 0);
548 struct ipoib_mcast
*mcast
= NULL
;
550 spin_lock_irq(&priv
->lock
);
551 list_for_each_entry(mcast
, &priv
->multicast_list
, list
) {
552 if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)
553 && !test_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
)
554 && !test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
)) {
555 /* Found the next unjoined group */
559 spin_unlock_irq(&priv
->lock
);
561 if (&mcast
->list
== &priv
->multicast_list
) {
566 ipoib_mcast_join(dev
, mcast
, 1);
570 priv
->mcast_mtu
= ib_mtu_enum_to_int(priv
->broadcast
->mcmember
.mtu
) -
573 if (!ipoib_cm_admin_enabled(dev
))
574 dev
->mtu
= min(priv
->mcast_mtu
, priv
->admin_mtu
);
576 ipoib_dbg_mcast(priv
, "successfully joined all multicast groups\n");
578 clear_bit(IPOIB_MCAST_RUN
, &priv
->flags
);
581 int ipoib_mcast_start_thread(struct net_device
*dev
)
583 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
585 ipoib_dbg_mcast(priv
, "starting multicast thread\n");
587 mutex_lock(&mcast_mutex
);
588 if (!test_and_set_bit(IPOIB_MCAST_RUN
, &priv
->flags
))
589 queue_delayed_work(ipoib_workqueue
, &priv
->mcast_task
, 0);
590 mutex_unlock(&mcast_mutex
);
592 spin_lock_irq(&priv
->lock
);
593 set_bit(IPOIB_MCAST_STARTED
, &priv
->flags
);
594 spin_unlock_irq(&priv
->lock
);
599 int ipoib_mcast_stop_thread(struct net_device
*dev
, int flush
)
601 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
603 ipoib_dbg_mcast(priv
, "stopping multicast thread\n");
605 spin_lock_irq(&priv
->lock
);
606 clear_bit(IPOIB_MCAST_STARTED
, &priv
->flags
);
607 spin_unlock_irq(&priv
->lock
);
609 mutex_lock(&mcast_mutex
);
610 clear_bit(IPOIB_MCAST_RUN
, &priv
->flags
);
611 cancel_delayed_work(&priv
->mcast_task
);
612 mutex_unlock(&mcast_mutex
);
615 flush_workqueue(ipoib_workqueue
);
620 static int ipoib_mcast_leave(struct net_device
*dev
, struct ipoib_mcast
*mcast
)
622 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
625 if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
))
626 ib_sa_free_multicast(mcast
->mc
);
628 if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED
, &mcast
->flags
)) {
629 ipoib_dbg_mcast(priv
, "leaving MGID " IPOIB_GID_FMT
"\n",
630 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
632 /* Remove ourselves from the multicast group */
633 ret
= ipoib_mcast_detach(dev
, be16_to_cpu(mcast
->mcmember
.mlid
),
634 &mcast
->mcmember
.mgid
);
636 ipoib_warn(priv
, "ipoib_mcast_detach failed (result = %d)\n", ret
);
642 void ipoib_mcast_send(struct net_device
*dev
, void *mgid
, struct sk_buff
*skb
)
644 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
645 struct ipoib_mcast
*mcast
;
648 * We can only be called from ipoib_start_xmit, so we're
649 * inside tx_lock -- no need to save/restore flags.
651 spin_lock(&priv
->lock
);
653 <<<<<<< HEAD
:drivers
/infiniband
/ulp
/ipoib
/ipoib_multicast
.c
654 if (!test_bit(IPOIB_MCAST_STARTED
, &priv
->flags
) ||
656 if (!test_bit(IPOIB_FLAG_OPER_UP
, &priv
->flags
) ||
657 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/infiniband
/ulp
/ipoib
/ipoib_multicast
.c
659 !test_bit(IPOIB_MCAST_FLAG_ATTACHED
, &priv
->broadcast
->flags
)) {
660 ++dev
->stats
.tx_dropped
;
661 dev_kfree_skb_any(skb
);
665 mcast
= __ipoib_mcast_find(dev
, mgid
);
667 /* Let's create a new send only group now */
668 ipoib_dbg_mcast(priv
, "setting up send only multicast group for "
669 IPOIB_GID_FMT
"\n", IPOIB_GID_RAW_ARG(mgid
));
671 mcast
= ipoib_mcast_alloc(dev
, 0);
673 ipoib_warn(priv
, "unable to allocate memory for "
674 "multicast structure\n");
675 ++dev
->stats
.tx_dropped
;
676 dev_kfree_skb_any(skb
);
680 set_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
);
681 memcpy(mcast
->mcmember
.mgid
.raw
, mgid
, sizeof (union ib_gid
));
682 __ipoib_mcast_add(dev
, mcast
);
683 list_add_tail(&mcast
->list
, &priv
->multicast_list
);
687 if (skb_queue_len(&mcast
->pkt_queue
) < IPOIB_MAX_MCAST_QUEUE
)
688 skb_queue_tail(&mcast
->pkt_queue
, skb
);
690 ++dev
->stats
.tx_dropped
;
691 dev_kfree_skb_any(skb
);
694 if (test_bit(IPOIB_MCAST_FLAG_BUSY
, &mcast
->flags
))
695 ipoib_dbg_mcast(priv
, "no address vector, "
696 "but multicast join already started\n");
697 else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
))
698 ipoib_mcast_sendonly_join(mcast
);
701 * If lookup completes between here and out:, don't
702 * want to send packet twice.
708 if (mcast
&& mcast
->ah
) {
710 skb
->dst
->neighbour
&&
711 !*to_ipoib_neigh(skb
->dst
->neighbour
)) {
712 struct ipoib_neigh
*neigh
= ipoib_neigh_alloc(skb
->dst
->neighbour
,
716 kref_get(&mcast
->ah
->ref
);
717 neigh
->ah
= mcast
->ah
;
718 list_add_tail(&neigh
->list
, &mcast
->neigh_list
);
722 ipoib_send(dev
, skb
, mcast
->ah
, IB_MULTICAST_QPN
);
726 spin_unlock(&priv
->lock
);
729 void ipoib_mcast_dev_flush(struct net_device
*dev
)
731 struct ipoib_dev_priv
*priv
= netdev_priv(dev
);
732 LIST_HEAD(remove_list
);
733 struct ipoib_mcast
*mcast
, *tmcast
;
736 ipoib_dbg_mcast(priv
, "flushing multicast list\n");
738 spin_lock_irqsave(&priv
->lock
, flags
);
740 list_for_each_entry_safe(mcast
, tmcast
, &priv
->multicast_list
, list
) {
741 list_del(&mcast
->list
);
742 rb_erase(&mcast
->rb_node
, &priv
->multicast_tree
);
743 list_add_tail(&mcast
->list
, &remove_list
);
746 if (priv
->broadcast
) {
747 rb_erase(&priv
->broadcast
->rb_node
, &priv
->multicast_tree
);
748 list_add_tail(&priv
->broadcast
->list
, &remove_list
);
749 priv
->broadcast
= NULL
;
752 spin_unlock_irqrestore(&priv
->lock
, flags
);
754 list_for_each_entry_safe(mcast
, tmcast
, &remove_list
, list
) {
755 ipoib_mcast_leave(dev
, mcast
);
756 ipoib_mcast_free(mcast
);
760 void ipoib_mcast_restart_task(struct work_struct
*work
)
762 struct ipoib_dev_priv
*priv
=
763 container_of(work
, struct ipoib_dev_priv
, restart_task
);
764 struct net_device
*dev
= priv
->dev
;
765 struct dev_mc_list
*mclist
;
766 struct ipoib_mcast
*mcast
, *tmcast
;
767 LIST_HEAD(remove_list
);
769 struct ib_sa_mcmember_rec rec
;
771 ipoib_dbg_mcast(priv
, "restarting multicast task\n");
773 ipoib_mcast_stop_thread(dev
, 0);
775 local_irq_save(flags
);
777 spin_lock(&priv
->lock
);
780 * Unfortunately, the networking core only gives us a list of all of
781 * the multicast hardware addresses. We need to figure out which ones
782 * are new and which ones have been removed
785 /* Clear out the found flag */
786 list_for_each_entry(mcast
, &priv
->multicast_list
, list
)
787 clear_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
);
789 /* Mark all of the entries that are found or don't exist */
790 for (mclist
= dev
->mc_list
; mclist
; mclist
= mclist
->next
) {
793 memcpy(mgid
.raw
, mclist
->dmi_addr
+ 4, sizeof mgid
);
795 mcast
= __ipoib_mcast_find(dev
, &mgid
);
796 if (!mcast
|| test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
797 struct ipoib_mcast
*nmcast
;
799 /* ignore group which is directly joined by userspace */
800 if (test_bit(IPOIB_FLAG_UMCAST
, &priv
->flags
) &&
801 !ib_sa_get_mcmember_rec(priv
->ca
, priv
->port
, &mgid
, &rec
)) {
802 ipoib_dbg_mcast(priv
, "ignoring multicast entry for mgid "
803 IPOIB_GID_FMT
"\n", IPOIB_GID_ARG(mgid
));
807 /* Not found or send-only group, let's add a new entry */
808 ipoib_dbg_mcast(priv
, "adding multicast entry for mgid "
809 IPOIB_GID_FMT
"\n", IPOIB_GID_ARG(mgid
));
811 nmcast
= ipoib_mcast_alloc(dev
, 0);
813 ipoib_warn(priv
, "unable to allocate memory for multicast structure\n");
817 set_bit(IPOIB_MCAST_FLAG_FOUND
, &nmcast
->flags
);
819 nmcast
->mcmember
.mgid
= mgid
;
822 /* Destroy the send only entry */
823 list_move_tail(&mcast
->list
, &remove_list
);
825 rb_replace_node(&mcast
->rb_node
,
827 &priv
->multicast_tree
);
829 __ipoib_mcast_add(dev
, nmcast
);
831 list_add_tail(&nmcast
->list
, &priv
->multicast_list
);
835 set_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
);
838 /* Remove all of the entries don't exist anymore */
839 list_for_each_entry_safe(mcast
, tmcast
, &priv
->multicast_list
, list
) {
840 if (!test_bit(IPOIB_MCAST_FLAG_FOUND
, &mcast
->flags
) &&
841 !test_bit(IPOIB_MCAST_FLAG_SENDONLY
, &mcast
->flags
)) {
842 ipoib_dbg_mcast(priv
, "deleting multicast group " IPOIB_GID_FMT
"\n",
843 IPOIB_GID_ARG(mcast
->mcmember
.mgid
));
845 rb_erase(&mcast
->rb_node
, &priv
->multicast_tree
);
847 /* Move to the remove list */
848 list_move_tail(&mcast
->list
, &remove_list
);
852 spin_unlock(&priv
->lock
);
853 netif_tx_unlock(dev
);
854 local_irq_restore(flags
);
856 /* We have to cancel outside of the spinlock */
857 list_for_each_entry_safe(mcast
, tmcast
, &remove_list
, list
) {
858 ipoib_mcast_leave(mcast
->dev
, mcast
);
859 ipoib_mcast_free(mcast
);
862 if (test_bit(IPOIB_FLAG_ADMIN_UP
, &priv
->flags
))
863 ipoib_mcast_start_thread(dev
);
866 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
868 struct ipoib_mcast_iter
*ipoib_mcast_iter_init(struct net_device
*dev
)
870 struct ipoib_mcast_iter
*iter
;
872 iter
= kmalloc(sizeof *iter
, GFP_KERNEL
);
877 memset(iter
->mgid
.raw
, 0, 16);
879 if (ipoib_mcast_iter_next(iter
)) {
887 int ipoib_mcast_iter_next(struct ipoib_mcast_iter
*iter
)
889 struct ipoib_dev_priv
*priv
= netdev_priv(iter
->dev
);
891 struct ipoib_mcast
*mcast
;
894 spin_lock_irq(&priv
->lock
);
896 n
= rb_first(&priv
->multicast_tree
);
899 mcast
= rb_entry(n
, struct ipoib_mcast
, rb_node
);
901 if (memcmp(iter
->mgid
.raw
, mcast
->mcmember
.mgid
.raw
,
902 sizeof (union ib_gid
)) < 0) {
903 iter
->mgid
= mcast
->mcmember
.mgid
;
904 iter
->created
= mcast
->created
;
905 iter
->queuelen
= skb_queue_len(&mcast
->pkt_queue
);
906 iter
->complete
= !!mcast
->ah
;
907 iter
->send_only
= !!(mcast
->flags
& (1 << IPOIB_MCAST_FLAG_SENDONLY
));
917 spin_unlock_irq(&priv
->lock
);
922 void ipoib_mcast_iter_read(struct ipoib_mcast_iter
*iter
,
924 unsigned long *created
,
925 unsigned int *queuelen
,
926 unsigned int *complete
,
927 unsigned int *send_only
)
930 *created
= iter
->created
;
931 *queuelen
= iter
->queuelen
;
932 *complete
= iter
->complete
;
933 *send_only
= iter
->send_only
;
936 #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */