36 #include <linux/rtnetlink.h>
40 #include <linux/igmp.h>
44 #include <linux/slab.h>
50 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
51 static int mcast_debug_level;
55 "Enable multicast debug tracing if > 0");
69 static void ipoib_mcast_free(
struct ipoib_mcast *mcast)
81 ipoib_put_ah(mcast->
ah);
83 while (!skb_queue_empty(&mcast->
pkt_queue)) {
88 netif_tx_lock_bh(dev);
90 netif_tx_unlock_bh(dev);
108 INIT_LIST_HEAD(&mcast->
list);
167 static int ipoib_mcast_join_finish(
struct ipoib_mcast *mcast,
183 spin_lock_irq(&priv->
lock);
185 spin_unlock_irq(&priv->
lock);
190 spin_unlock_irq(&priv->
lock);
191 priv->
tx_wr.wr.ud.remote_qkey = priv->
qkey;
194 if (!ipoib_cm_admin_enabled(dev)) {
203 ipoib_warn(priv,
"multicast group %pI6 already attached\n",
212 ipoib_warn(priv,
"couldn't attach QP to multicast group %pI6\n",
223 .port_num = priv->
port,
226 .static_rate = mcast->
mcmember.rate,
229 .hop_limit = mcast->
mcmember.hop_limit,
231 .traffic_class = mcast->
mcmember.traffic_class
238 ipoib_warn(priv,
"ib_address_create failed %ld\n",
243 spin_lock_irq(&priv->
lock);
245 spin_unlock_irq(&priv->
lock);
256 netif_tx_lock_bh(dev);
257 while (!skb_queue_empty(&mcast->
pkt_queue)) {
260 netif_tx_unlock_bh(dev);
264 ipoib_warn(priv,
"dev_queue_xmit failed to requeue packet\n");
266 netif_tx_lock_bh(dev);
268 netif_tx_unlock_bh(dev);
274 ipoib_mcast_sendonly_join_complete(
int status,
285 status = ipoib_mcast_join_finish(mcast, &multicast->
rec);
289 ipoib_dbg_mcast(netdev_priv(dev),
"multicast join failed for %pI6, status %d\n",
293 netif_tx_lock_bh(dev);
294 while (!skb_queue_empty(&mcast->
pkt_queue)) {
295 ++dev->
stats.tx_dropped;
298 netif_tx_unlock_bh(dev);
307 static int ipoib_mcast_sendonly_join(
struct ipoib_mcast *mcast)
341 ipoib_mcast_sendonly_join_complete,
343 if (IS_ERR(mcast->
mc)) {
344 ret = PTR_ERR(mcast->
mc);
346 ipoib_warn(priv,
"ib_sa_join_multicast failed (ret = %d)\n",
369 ipoib_dbg(priv,
"Keeping carrier off until IB port is active\n");
378 static int ipoib_mcast_join_complete(
int status,
393 status = ipoib_mcast_join_finish(mcast, &multicast->
rec);
418 ipoib_warn(priv,
"multicast join failed for %pI6, status %d\n",
431 spin_lock_irq(&priv->
lock);
435 spin_unlock_irq(&priv->
lock);
489 ipoib_mcast_join_complete, mcast);
490 if (IS_ERR(mcast->
mc)) {
492 ret = PTR_ERR(mcast->
mc);
493 ipoib_warn(priv,
"ib_sa_join_multicast failed, status %d\n", ret);
537 broadcast = ipoib_mcast_alloc(dev, 1);
539 ipoib_warn(priv,
"failed to allocate broadcast group\n");
548 spin_lock_irq(&priv->
lock);
554 spin_unlock_irq(&priv->
lock);
559 ipoib_mcast_join(dev, priv->
broadcast, 0);
566 spin_lock_irq(&priv->
lock);
575 spin_unlock_irq(&priv->
lock);
582 ipoib_mcast_join(dev, mcast, 1);
638 ipoib_warn(priv,
"ib_detach_mcast failed (result = %d)\n", ret);
649 void *mgid = daddr + 4;
656 ++dev->
stats.tx_dropped;
661 mcast = __ipoib_mcast_find(dev, mgid);
664 ipoib_dbg_mcast(priv,
"setting up send only multicast group for %pI6\n",
667 mcast = ipoib_mcast_alloc(dev, 0);
669 ipoib_warn(priv,
"unable to allocate memory for "
670 "multicast structure\n");
671 ++dev->
stats.tx_dropped;
678 __ipoib_mcast_add(dev, mcast);
686 ++dev->
stats.tx_dropped;
692 "but multicast join already started\n");
694 ipoib_mcast_sendonly_join(mcast);
704 if (mcast && mcast->
ah) {
707 spin_unlock_irqrestore(&priv->
lock, flags);
713 kref_get(&mcast->
ah->ref);
714 neigh->
ah = mcast->
ah;
718 spin_unlock_irqrestore(&priv->
lock, flags);
721 ipoib_neigh_put(neigh);
726 spin_unlock_irqrestore(&priv->
lock, flags);
752 spin_unlock_irqrestore(&priv->
lock, flags);
755 ipoib_mcast_leave(dev, mcast);
756 ipoib_mcast_free(mcast);
760 static int ipoib_mcast_addr_is_valid(
const u8 *
addr,
const u8 *broadcast)
763 if (
memcmp(addr, broadcast, 6))
766 if (
memcmp(addr + 7, broadcast + 7, 3))
787 netif_addr_lock(dev);
788 spin_lock(&priv->
lock);
809 mcast = __ipoib_mcast_find(dev, &mgid);
825 nmcast = ipoib_mcast_alloc(dev, 0);
827 ipoib_warn(priv,
"unable to allocate memory for multicast structure\n");
837 list_move_tail(&mcast->
list, &remove_list);
843 __ipoib_mcast_add(dev, nmcast);
862 list_move_tail(&mcast->
list, &remove_list);
866 spin_unlock(&priv->
lock);
867 netif_addr_unlock(dev);
872 ipoib_mcast_leave(mcast->
dev, mcast);
873 ipoib_mcast_free(mcast);
880 #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
893 if (ipoib_mcast_iter_next(iter)) {
908 spin_lock_irq(&priv->
lock);
931 spin_unlock_irq(&priv->
lock);
939 unsigned int *queuelen,
941 unsigned int *send_only)