Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved. |
Roland Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 3 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
| 4 | * Copyright (c) 2004 Voltaire, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 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: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 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. |
| 24 | * |
| 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 |
| 32 | * SOFTWARE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include <linux/skbuff.h> |
| 36 | #include <linux/rtnetlink.h> |
Paul Gortmaker | fec14d2 | 2011-08-30 12:32:52 -0400 | [diff] [blame] | 37 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/ip.h> |
| 39 | #include <linux/in.h> |
| 40 | #include <linux/igmp.h> |
| 41 | #include <linux/inetdevice.h> |
| 42 | #include <linux/delay.h> |
| 43 | #include <linux/completion.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 46 | #include <net/dst.h> |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include "ipoib.h" |
| 49 | |
| 50 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 51 | static int mcast_debug_level; |
| 52 | |
| 53 | module_param(mcast_debug_level, int, 0644); |
| 54 | MODULE_PARM_DESC(mcast_debug_level, |
| 55 | "Enable multicast debug tracing if > 0"); |
| 56 | #endif |
| 57 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 58 | static DEFINE_MUTEX(mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | struct ipoib_mcast_iter { |
| 61 | struct net_device *dev; |
| 62 | union ib_gid mgid; |
| 63 | unsigned long created; |
| 64 | unsigned int queuelen; |
| 65 | unsigned int complete; |
| 66 | unsigned int send_only; |
| 67 | }; |
| 68 | |
| 69 | static void ipoib_mcast_free(struct ipoib_mcast *mcast) |
| 70 | { |
| 71 | struct net_device *dev = mcast->dev; |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 72 | int tx_dropped = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 74 | ipoib_dbg_mcast(netdev_priv(dev), "deleting multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 75 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 77 | /* remove all neigh connected to this mcast */ |
| 78 | ipoib_del_neighs_by_gid(dev, mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (mcast->ah) |
| 81 | ipoib_put_ah(mcast->ah); |
| 82 | |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 83 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
| 84 | ++tx_dropped; |
Roland Dreier | 8c608a3 | 2005-11-07 10:49:38 -0800 | [diff] [blame] | 85 | dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue)); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 88 | netif_tx_lock_bh(dev); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 89 | dev->stats.tx_dropped += tx_dropped; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 90 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | kfree(mcast); |
| 93 | } |
| 94 | |
| 95 | static struct ipoib_mcast *ipoib_mcast_alloc(struct net_device *dev, |
| 96 | int can_sleep) |
| 97 | { |
| 98 | struct ipoib_mcast *mcast; |
| 99 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 100 | mcast = kzalloc(sizeof *mcast, can_sleep ? GFP_KERNEL : GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | if (!mcast) |
| 102 | return NULL; |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | mcast->dev = dev; |
| 105 | mcast->created = jiffies; |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 106 | mcast->backoff = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | INIT_LIST_HEAD(&mcast->list); |
| 109 | INIT_LIST_HEAD(&mcast->neigh_list); |
| 110 | skb_queue_head_init(&mcast->pkt_queue); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | return mcast; |
| 113 | } |
| 114 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 115 | static struct ipoib_mcast *__ipoib_mcast_find(struct net_device *dev, void *mgid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
| 117 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 118 | struct rb_node *n = priv->multicast_tree.rb_node; |
| 119 | |
| 120 | while (n) { |
| 121 | struct ipoib_mcast *mcast; |
| 122 | int ret; |
| 123 | |
| 124 | mcast = rb_entry(n, struct ipoib_mcast, rb_node); |
| 125 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 126 | ret = memcmp(mgid, mcast->mcmember.mgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | sizeof (union ib_gid)); |
| 128 | if (ret < 0) |
| 129 | n = n->rb_left; |
| 130 | else if (ret > 0) |
| 131 | n = n->rb_right; |
| 132 | else |
| 133 | return mcast; |
| 134 | } |
| 135 | |
| 136 | return NULL; |
| 137 | } |
| 138 | |
| 139 | static int __ipoib_mcast_add(struct net_device *dev, struct ipoib_mcast *mcast) |
| 140 | { |
| 141 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 142 | struct rb_node **n = &priv->multicast_tree.rb_node, *pn = NULL; |
| 143 | |
| 144 | while (*n) { |
| 145 | struct ipoib_mcast *tmcast; |
| 146 | int ret; |
| 147 | |
| 148 | pn = *n; |
| 149 | tmcast = rb_entry(pn, struct ipoib_mcast, rb_node); |
| 150 | |
| 151 | ret = memcmp(mcast->mcmember.mgid.raw, tmcast->mcmember.mgid.raw, |
| 152 | sizeof (union ib_gid)); |
| 153 | if (ret < 0) |
| 154 | n = &pn->rb_left; |
| 155 | else if (ret > 0) |
| 156 | n = &pn->rb_right; |
| 157 | else |
| 158 | return -EEXIST; |
| 159 | } |
| 160 | |
| 161 | rb_link_node(&mcast->rb_node, pn, n); |
| 162 | rb_insert_color(&mcast->rb_node, &priv->multicast_tree); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast, |
| 168 | struct ib_sa_mcmember_rec *mcmember) |
| 169 | { |
| 170 | struct net_device *dev = mcast->dev; |
| 171 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Eli Cohen | 7343b23 | 2006-02-27 20:47:43 -0800 | [diff] [blame] | 172 | struct ipoib_ah *ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | int ret; |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 174 | int set_qkey = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | mcast->mcmember = *mcmember; |
| 177 | |
Patrick McHardy | bea1e22 | 2012-08-30 07:01:30 +0000 | [diff] [blame] | 178 | /* Set the multicast MTU and cached Q_Key before we attach if it's |
| 179 | * the broadcast group. |
| 180 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (!memcmp(mcast->mcmember.mgid.raw, priv->dev->broadcast + 4, |
| 182 | sizeof (union ib_gid))) { |
Jack Morgenstein | e1d50dc | 2008-05-20 15:41:09 -0700 | [diff] [blame] | 183 | spin_lock_irq(&priv->lock); |
| 184 | if (!priv->broadcast) { |
| 185 | spin_unlock_irq(&priv->lock); |
| 186 | return -EAGAIN; |
| 187 | } |
Patrick McHardy | bea1e22 | 2012-08-30 07:01:30 +0000 | [diff] [blame] | 188 | priv->mcast_mtu = IPOIB_UD_MTU(ib_mtu_enum_to_int(priv->broadcast->mcmember.mtu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | priv->qkey = be32_to_cpu(priv->broadcast->mcmember.qkey); |
Jack Morgenstein | e1d50dc | 2008-05-20 15:41:09 -0700 | [diff] [blame] | 190 | spin_unlock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | priv->tx_wr.wr.ud.remote_qkey = priv->qkey; |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 192 | set_qkey = 1; |
Patrick McHardy | bea1e22 | 2012-08-30 07:01:30 +0000 | [diff] [blame] | 193 | |
| 194 | if (!ipoib_cm_admin_enabled(dev)) { |
| 195 | rtnl_lock(); |
| 196 | dev_set_mtu(dev, min(priv->mcast_mtu, priv->admin_mtu)); |
| 197 | rtnl_unlock(); |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
| 202 | if (test_and_set_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 203 | ipoib_warn(priv, "multicast group %pI6 already attached\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 204 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | ret = ipoib_mcast_attach(dev, be16_to_cpu(mcast->mcmember.mlid), |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 210 | &mcast->mcmember.mgid, set_qkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (ret < 0) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 212 | ipoib_warn(priv, "couldn't attach QP to multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 213 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags); |
| 216 | return ret; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | { |
| 221 | struct ib_ah_attr av = { |
| 222 | .dlid = be16_to_cpu(mcast->mcmember.mlid), |
| 223 | .port_num = priv->port, |
| 224 | .sl = mcast->mcmember.sl, |
| 225 | .ah_flags = IB_AH_GRH, |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 226 | .static_rate = mcast->mcmember.rate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | .grh = { |
| 228 | .flow_label = be32_to_cpu(mcast->mcmember.flow_label), |
| 229 | .hop_limit = mcast->mcmember.hop_limit, |
| 230 | .sgid_index = 0, |
| 231 | .traffic_class = mcast->mcmember.traffic_class |
| 232 | } |
| 233 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | av.grh.dgid = mcast->mcmember.mgid; |
| 235 | |
Eli Cohen | 7343b23 | 2006-02-27 20:47:43 -0800 | [diff] [blame] | 236 | ah = ipoib_create_ah(dev, priv->pd, &av); |
Mike Marciniszyn | 3874397 | 2011-11-21 08:43:54 -0500 | [diff] [blame] | 237 | if (IS_ERR(ah)) { |
| 238 | ipoib_warn(priv, "ib_address_create failed %ld\n", |
| 239 | -PTR_ERR(ah)); |
| 240 | /* use original error */ |
| 241 | return PTR_ERR(ah); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } else { |
Or Gerlitz | 624d01f | 2006-07-24 10:42:00 +0300 | [diff] [blame] | 243 | spin_lock_irq(&priv->lock); |
| 244 | mcast->ah = ah; |
| 245 | spin_unlock_irq(&priv->lock); |
| 246 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 247 | ipoib_dbg_mcast(priv, "MGID %pI6 AV %p, LID 0x%04x, SL %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 248 | mcast->mcmember.mgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | mcast->ah->ah, |
| 250 | be16_to_cpu(mcast->mcmember.mlid), |
| 251 | mcast->mcmember.sl); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /* actually send any queued packets */ |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 256 | netif_tx_lock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
| 258 | struct sk_buff *skb = skb_dequeue(&mcast->pkt_queue); |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 259 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 260 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | skb->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (dev_queue_xmit(skb)) |
| 264 | ipoib_warn(priv, "dev_queue_xmit failed to requeue packet\n"); |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 265 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 266 | netif_tx_lock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 268 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 273 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | ipoib_mcast_sendonly_join_complete(int status, |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 275 | struct ib_sa_multicast *multicast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 277 | struct ipoib_mcast *mcast = multicast->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct net_device *dev = mcast->dev; |
| 279 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 280 | /* We trap for port events ourselves. */ |
| 281 | if (status == -ENETRESET) |
| 282 | return 0; |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | if (!status) |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 285 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 286 | |
| 287 | if (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (mcast->logcount++ < 20) |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 289 | ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for %pI6, status %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 290 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | /* Flush out any queued packets */ |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 293 | netif_tx_lock_bh(dev); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 294 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 295 | ++dev->stats.tx_dropped; |
Roland Dreier | 8c608a3 | 2005-11-07 10:49:38 -0800 | [diff] [blame] | 296 | dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue)); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 297 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 298 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | /* Clear the busy flag so we try again */ |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 301 | status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, |
| 302 | &mcast->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 304 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) |
| 308 | { |
| 309 | struct net_device *dev = mcast->dev; |
| 310 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 311 | struct ib_sa_mcmember_rec rec = { |
| 312 | #if 0 /* Some SMs don't support send-only yet */ |
| 313 | .join_state = 4 |
| 314 | #else |
| 315 | .join_state = 1 |
| 316 | #endif |
| 317 | }; |
| 318 | int ret = 0; |
| 319 | |
| 320 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
| 321 | ipoib_dbg_mcast(priv, "device shutting down, no multicast joins\n"); |
| 322 | return -ENODEV; |
| 323 | } |
| 324 | |
| 325 | if (test_and_set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) { |
| 326 | ipoib_dbg_mcast(priv, "multicast entry busy, skipping\n"); |
| 327 | return -EBUSY; |
| 328 | } |
| 329 | |
| 330 | rec.mgid = mcast->mcmember.mgid; |
| 331 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 332 | rec.pkey = cpu_to_be16(priv->pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 334 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, |
| 335 | priv->port, &rec, |
| 336 | IB_SA_MCMEMBER_REC_MGID | |
| 337 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 338 | IB_SA_MCMEMBER_REC_PKEY | |
| 339 | IB_SA_MCMEMBER_REC_JOIN_STATE, |
| 340 | GFP_ATOMIC, |
| 341 | ipoib_mcast_sendonly_join_complete, |
| 342 | mcast); |
| 343 | if (IS_ERR(mcast->mc)) { |
| 344 | ret = PTR_ERR(mcast->mc); |
| 345 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 346 | ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | ret); |
| 348 | } else { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 349 | ipoib_dbg_mcast(priv, "no multicast record for %pI6, starting join\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 350 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | return ret; |
| 354 | } |
| 355 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 356 | void ipoib_mcast_carrier_on_task(struct work_struct *work) |
| 357 | { |
| 358 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 359 | carrier_on_task); |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 360 | struct ib_port_attr attr; |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 361 | |
| 362 | /* |
| 363 | * Take rtnl_lock to avoid racing with ipoib_stop() and |
| 364 | * turning the carrier back on while a device is being |
| 365 | * removed. |
| 366 | */ |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 367 | if (ib_query_port(priv->ca, priv->port, &attr) || |
| 368 | attr.state != IB_PORT_ACTIVE) { |
| 369 | ipoib_dbg(priv, "Keeping carrier off until IB port is active\n"); |
| 370 | return; |
| 371 | } |
| 372 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 373 | rtnl_lock(); |
| 374 | netif_carrier_on(priv->dev); |
| 375 | rtnl_unlock(); |
| 376 | } |
| 377 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 378 | static int ipoib_mcast_join_complete(int status, |
| 379 | struct ib_sa_multicast *multicast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 381 | struct ipoib_mcast *mcast = multicast->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | struct net_device *dev = mcast->dev; |
| 383 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 384 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 385 | ipoib_dbg_mcast(priv, "join completion for %pI6 (status %d)\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 386 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 388 | /* We trap for port events ourselves. */ |
| 389 | if (status == -ENETRESET) |
| 390 | return 0; |
| 391 | |
| 392 | if (!status) |
| 393 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 394 | |
| 395 | if (!status) { |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 396 | mcast->backoff = 1; |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 397 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 399 | queue_delayed_work(ipoib_workqueue, |
| 400 | &priv->mcast_task, 0); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 401 | mutex_unlock(&mcast_mutex); |
Shirley Ma | 55c9add | 2007-03-08 14:59:30 -0800 | [diff] [blame] | 402 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 403 | /* |
| 404 | * Defer carrier on work to ipoib_workqueue to avoid a |
| 405 | * deadlock on rtnl_lock here. |
| 406 | */ |
| 407 | if (mcast == priv->broadcast) |
| 408 | queue_work(ipoib_workqueue, &priv->carrier_on_task); |
Shirley Ma | 55c9add | 2007-03-08 14:59:30 -0800 | [diff] [blame] | 409 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 410 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 413 | if (mcast->logcount++ < 20) { |
Yossi Etigin | 3c20962 | 2009-01-16 13:42:59 -0800 | [diff] [blame] | 414 | if (status == -ETIMEDOUT || status == -EAGAIN) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 415 | ipoib_dbg_mcast(priv, "multicast join failed for %pI6, status %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 416 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } else { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 418 | ipoib_warn(priv, "multicast join failed for %pI6, status %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 419 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | mcast->backoff *= 2; |
| 424 | if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) |
| 425 | mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; |
| 426 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 427 | /* Clear the busy flag so we try again */ |
| 428 | status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 429 | |
Michael S. Tsirkin | 9acf6a8 | 2006-03-02 11:07:47 -0800 | [diff] [blame] | 430 | mutex_lock(&mcast_mutex); |
Michael S. Tsirkin | 9acf6a8 | 2006-03-02 11:07:47 -0800 | [diff] [blame] | 431 | spin_lock_irq(&priv->lock); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 432 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 433 | queue_delayed_work(ipoib_workqueue, &priv->mcast_task, |
| 434 | mcast->backoff * HZ); |
Michael S. Tsirkin | 9acf6a8 | 2006-03-02 11:07:47 -0800 | [diff] [blame] | 435 | spin_unlock_irq(&priv->lock); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 436 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 438 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, |
| 442 | int create) |
| 443 | { |
| 444 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 445 | struct ib_sa_mcmember_rec rec = { |
| 446 | .join_state = 1 |
| 447 | }; |
| 448 | ib_sa_comp_mask comp_mask; |
| 449 | int ret = 0; |
| 450 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 451 | ipoib_dbg_mcast(priv, "joining MGID %pI6\n", mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | rec.mgid = mcast->mcmember.mgid; |
| 454 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 455 | rec.pkey = cpu_to_be16(priv->pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
| 457 | comp_mask = |
| 458 | IB_SA_MCMEMBER_REC_MGID | |
| 459 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 460 | IB_SA_MCMEMBER_REC_PKEY | |
| 461 | IB_SA_MCMEMBER_REC_JOIN_STATE; |
| 462 | |
| 463 | if (create) { |
| 464 | comp_mask |= |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 465 | IB_SA_MCMEMBER_REC_QKEY | |
| 466 | IB_SA_MCMEMBER_REC_MTU_SELECTOR | |
| 467 | IB_SA_MCMEMBER_REC_MTU | |
| 468 | IB_SA_MCMEMBER_REC_TRAFFIC_CLASS | |
| 469 | IB_SA_MCMEMBER_REC_RATE_SELECTOR | |
| 470 | IB_SA_MCMEMBER_REC_RATE | |
| 471 | IB_SA_MCMEMBER_REC_SL | |
| 472 | IB_SA_MCMEMBER_REC_FLOW_LABEL | |
| 473 | IB_SA_MCMEMBER_REC_HOP_LIMIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | rec.qkey = priv->broadcast->mcmember.qkey; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 476 | rec.mtu_selector = IB_SA_EQ; |
| 477 | rec.mtu = priv->broadcast->mcmember.mtu; |
| 478 | rec.traffic_class = priv->broadcast->mcmember.traffic_class; |
| 479 | rec.rate_selector = IB_SA_EQ; |
| 480 | rec.rate = priv->broadcast->mcmember.rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | rec.sl = priv->broadcast->mcmember.sl; |
| 482 | rec.flow_label = priv->broadcast->mcmember.flow_label; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 483 | rec.hop_limit = priv->broadcast->mcmember.hop_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 486 | set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 487 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port, |
| 488 | &rec, comp_mask, GFP_KERNEL, |
| 489 | ipoib_mcast_join_complete, mcast); |
| 490 | if (IS_ERR(mcast->mc)) { |
| 491 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 492 | ret = PTR_ERR(mcast->mc); |
| 493 | ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | mcast->backoff *= 2; |
| 496 | if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) |
| 497 | mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; |
| 498 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 499 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 501 | queue_delayed_work(ipoib_workqueue, |
| 502 | &priv->mcast_task, |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 503 | mcast->backoff * HZ); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 504 | mutex_unlock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 508 | void ipoib_mcast_join_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 510 | struct ipoib_dev_priv *priv = |
| 511 | container_of(work, struct ipoib_dev_priv, mcast_task.work); |
| 512 | struct net_device *dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | if (!test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 515 | return; |
| 516 | |
| 517 | if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid)) |
Michael S. Tsirkin | 24bd1e4 | 2007-05-18 16:12:54 +0300 | [diff] [blame] | 518 | ipoib_warn(priv, "ib_query_gid() failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | else |
| 520 | memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); |
| 521 | |
| 522 | { |
| 523 | struct ib_port_attr attr; |
| 524 | |
Roland Dreier | 658bcef | 2007-02-21 20:28:05 -0800 | [diff] [blame] | 525 | if (!ib_query_port(priv->ca, priv->port, &attr)) |
| 526 | priv->local_lid = attr.lid; |
| 527 | else |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 528 | ipoib_warn(priv, "ib_query_port failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | if (!priv->broadcast) { |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 532 | struct ipoib_mcast *broadcast; |
| 533 | |
Yossi Etigin | 50df48f | 2009-01-12 19:28:42 -0800 | [diff] [blame] | 534 | if (!test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) |
| 535 | return; |
| 536 | |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 537 | broadcast = ipoib_mcast_alloc(dev, 1); |
| 538 | if (!broadcast) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | ipoib_warn(priv, "failed to allocate broadcast group\n"); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 540 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 542 | queue_delayed_work(ipoib_workqueue, |
| 543 | &priv->mcast_task, HZ); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 544 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | return; |
| 546 | } |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | spin_lock_irq(&priv->lock); |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 549 | memcpy(broadcast->mcmember.mgid.raw, priv->dev->broadcast + 4, |
| 550 | sizeof (union ib_gid)); |
| 551 | priv->broadcast = broadcast; |
| 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | __ipoib_mcast_add(dev, priv->broadcast); |
| 554 | spin_unlock_irq(&priv->lock); |
| 555 | } |
| 556 | |
| 557 | if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 558 | if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags)) |
| 559 | ipoib_mcast_join(dev, priv->broadcast, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | return; |
| 561 | } |
| 562 | |
| 563 | while (1) { |
| 564 | struct ipoib_mcast *mcast = NULL; |
| 565 | |
| 566 | spin_lock_irq(&priv->lock); |
| 567 | list_for_each_entry(mcast, &priv->multicast_list, list) { |
| 568 | if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags) |
| 569 | && !test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags) |
| 570 | && !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
| 571 | /* Found the next unjoined group */ |
| 572 | break; |
| 573 | } |
| 574 | } |
| 575 | spin_unlock_irq(&priv->lock); |
| 576 | |
| 577 | if (&mcast->list == &priv->multicast_list) { |
| 578 | /* All done */ |
| 579 | break; |
| 580 | } |
| 581 | |
| 582 | ipoib_mcast_join(dev, mcast, 1); |
| 583 | return; |
| 584 | } |
| 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n"); |
| 587 | |
| 588 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | int ipoib_mcast_start_thread(struct net_device *dev) |
| 592 | { |
| 593 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 594 | |
| 595 | ipoib_dbg_mcast(priv, "starting multicast thread\n"); |
| 596 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 597 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags)) |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 599 | queue_delayed_work(ipoib_workqueue, &priv->mcast_task, 0); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 600 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Roland Dreier | 8d2cae0 | 2005-09-20 10:52:04 -0700 | [diff] [blame] | 605 | int ipoib_mcast_stop_thread(struct net_device *dev, int flush) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
| 607 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
| 609 | ipoib_dbg_mcast(priv, "stopping multicast thread\n"); |
| 610 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 611 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
| 613 | cancel_delayed_work(&priv->mcast_task); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 614 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Roland Dreier | 8d2cae0 | 2005-09-20 10:52:04 -0700 | [diff] [blame] | 616 | if (flush) |
| 617 | flush_workqueue(ipoib_workqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) |
| 623 | { |
| 624 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | int ret = 0; |
| 626 | |
Sean Hefty | e07832b | 2007-03-19 14:31:36 -0800 | [diff] [blame] | 627 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
| 628 | ib_sa_free_multicast(mcast->mc); |
| 629 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 630 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 631 | ipoib_dbg_mcast(priv, "leaving MGID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 632 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 634 | /* Remove ourselves from the multicast group */ |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 635 | ret = ib_detach_mcast(priv->qp, &mcast->mcmember.mgid, |
| 636 | be16_to_cpu(mcast->mcmember.mlid)); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 637 | if (ret) |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 638 | ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 639 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 644 | void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
| 646 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 647 | struct ipoib_mcast *mcast; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 648 | unsigned long flags; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 649 | void *mgid = daddr + 4; |
David S. Miller | 700db99 | 2012-07-05 21:08:05 -0700 | [diff] [blame] | 650 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 651 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Or Gerlitz | b3e2749 | 2008-03-11 16:10:02 +0200 | [diff] [blame] | 653 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags) || |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 654 | !priv->broadcast || |
| 655 | !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 656 | ++dev->stats.tx_dropped; |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 657 | dev_kfree_skb_any(skb); |
| 658 | goto unlock; |
| 659 | } |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | mcast = __ipoib_mcast_find(dev, mgid); |
| 662 | if (!mcast) { |
| 663 | /* Let's create a new send only group now */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 664 | ipoib_dbg_mcast(priv, "setting up send only multicast group for %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 665 | mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | mcast = ipoib_mcast_alloc(dev, 0); |
| 668 | if (!mcast) { |
| 669 | ipoib_warn(priv, "unable to allocate memory for " |
| 670 | "multicast structure\n"); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 671 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | dev_kfree_skb_any(skb); |
| 673 | goto out; |
| 674 | } |
| 675 | |
| 676 | set_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags); |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 677 | memcpy(mcast->mcmember.mgid.raw, mgid, sizeof (union ib_gid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | __ipoib_mcast_add(dev, mcast); |
| 679 | list_add_tail(&mcast->list, &priv->multicast_list); |
| 680 | } |
| 681 | |
| 682 | if (!mcast->ah) { |
| 683 | if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE) |
| 684 | skb_queue_tail(&mcast->pkt_queue, skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 685 | else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 686 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | dev_kfree_skb_any(skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 690 | if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | ipoib_dbg_mcast(priv, "no address vector, " |
| 692 | "but multicast join already started\n"); |
| 693 | else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) |
| 694 | ipoib_mcast_sendonly_join(mcast); |
| 695 | |
| 696 | /* |
| 697 | * If lookup completes between here and out:, don't |
| 698 | * want to send packet twice. |
| 699 | */ |
| 700 | mcast = NULL; |
| 701 | } |
| 702 | |
| 703 | out: |
| 704 | if (mcast && mcast->ah) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 705 | struct ipoib_neigh *neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 707 | spin_unlock_irqrestore(&priv->lock, flags); |
| 708 | neigh = ipoib_neigh_get(dev, daddr); |
| 709 | spin_lock_irqsave(&priv->lock, flags); |
| 710 | if (!neigh) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 711 | neigh = ipoib_neigh_alloc(daddr, dev); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 712 | if (neigh) { |
| 713 | kref_get(&mcast->ah->ref); |
| 714 | neigh->ah = mcast->ah; |
| 715 | list_add_tail(&neigh->list, &mcast->neigh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 718 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 720 | if (neigh) |
| 721 | ipoib_neigh_put(neigh); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 722 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 725 | unlock: |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 726 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | void ipoib_mcast_dev_flush(struct net_device *dev) |
| 730 | { |
| 731 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 732 | LIST_HEAD(remove_list); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 733 | struct ipoib_mcast *mcast, *tmcast; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | unsigned long flags; |
| 735 | |
| 736 | ipoib_dbg_mcast(priv, "flushing multicast list\n"); |
| 737 | |
| 738 | spin_lock_irqsave(&priv->lock, flags); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 741 | list_del(&mcast->list); |
| 742 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 743 | list_add_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | if (priv->broadcast) { |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 747 | rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 748 | list_add_tail(&priv->broadcast->list, &remove_list); |
| 749 | priv->broadcast = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | spin_unlock_irqrestore(&priv->lock, flags); |
| 753 | |
| 754 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 755 | ipoib_mcast_leave(dev, mcast); |
| 756 | ipoib_mcast_free(mcast); |
| 757 | } |
| 758 | } |
| 759 | |
Jiri Pirko | 3e4aa12 | 2010-03-22 03:21:39 +0000 | [diff] [blame] | 760 | static int ipoib_mcast_addr_is_valid(const u8 *addr, const u8 *broadcast) |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 761 | { |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 762 | /* reserved QPN, prefix, scope */ |
| 763 | if (memcmp(addr, broadcast, 6)) |
| 764 | return 0; |
| 765 | /* signature lower, pkey */ |
| 766 | if (memcmp(addr + 7, broadcast + 7, 3)) |
| 767 | return 0; |
| 768 | return 1; |
| 769 | } |
| 770 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 771 | void ipoib_mcast_restart_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 773 | struct ipoib_dev_priv *priv = |
| 774 | container_of(work, struct ipoib_dev_priv, restart_task); |
| 775 | struct net_device *dev = priv->dev; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 776 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | struct ipoib_mcast *mcast, *tmcast; |
| 778 | LIST_HEAD(remove_list); |
| 779 | unsigned long flags; |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 780 | struct ib_sa_mcmember_rec rec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | ipoib_dbg_mcast(priv, "restarting multicast task\n"); |
| 783 | |
Roland Dreier | 8d2cae0 | 2005-09-20 10:52:04 -0700 | [diff] [blame] | 784 | ipoib_mcast_stop_thread(dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 786 | local_irq_save(flags); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 787 | netif_addr_lock(dev); |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 788 | spin_lock(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | /* |
| 791 | * Unfortunately, the networking core only gives us a list of all of |
| 792 | * the multicast hardware addresses. We need to figure out which ones |
| 793 | * are new and which ones have been removed |
| 794 | */ |
| 795 | |
| 796 | /* Clear out the found flag */ |
| 797 | list_for_each_entry(mcast, &priv->multicast_list, list) |
| 798 | clear_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 799 | |
| 800 | /* Mark all of the entries that are found or don't exist */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 801 | netdev_for_each_mc_addr(ha, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | union ib_gid mgid; |
| 803 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 804 | if (!ipoib_mcast_addr_is_valid(ha->addr, dev->broadcast)) |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 805 | continue; |
| 806 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 807 | memcpy(mgid.raw, ha->addr + 4, sizeof mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | mcast = __ipoib_mcast_find(dev, &mgid); |
| 810 | if (!mcast || test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
| 811 | struct ipoib_mcast *nmcast; |
| 812 | |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 813 | /* ignore group which is directly joined by userspace */ |
| 814 | if (test_bit(IPOIB_FLAG_UMCAST, &priv->flags) && |
| 815 | !ib_sa_get_mcmember_rec(priv->ca, priv->port, &mgid, &rec)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 816 | ipoib_dbg_mcast(priv, "ignoring multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 817 | mgid.raw); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 818 | continue; |
| 819 | } |
| 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | /* Not found or send-only group, let's add a new entry */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 822 | ipoib_dbg_mcast(priv, "adding multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 823 | mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | nmcast = ipoib_mcast_alloc(dev, 0); |
| 826 | if (!nmcast) { |
| 827 | ipoib_warn(priv, "unable to allocate memory for multicast structure\n"); |
| 828 | continue; |
| 829 | } |
| 830 | |
| 831 | set_bit(IPOIB_MCAST_FLAG_FOUND, &nmcast->flags); |
| 832 | |
| 833 | nmcast->mcmember.mgid = mgid; |
| 834 | |
| 835 | if (mcast) { |
| 836 | /* Destroy the send only entry */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 837 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | rb_replace_node(&mcast->rb_node, |
| 840 | &nmcast->rb_node, |
| 841 | &priv->multicast_tree); |
| 842 | } else |
| 843 | __ipoib_mcast_add(dev, nmcast); |
| 844 | |
| 845 | list_add_tail(&nmcast->list, &priv->multicast_list); |
| 846 | } |
| 847 | |
| 848 | if (mcast) |
| 849 | set_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 850 | } |
| 851 | |
| 852 | /* Remove all of the entries don't exist anymore */ |
| 853 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
| 854 | if (!test_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags) && |
| 855 | !test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 856 | ipoib_dbg_mcast(priv, "deleting multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 857 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | |
| 859 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 860 | |
| 861 | /* Move to the remove list */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 862 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 865 | |
| 866 | spin_unlock(&priv->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 867 | netif_addr_unlock(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 868 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | /* We have to cancel outside of the spinlock */ |
| 871 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 872 | ipoib_mcast_leave(mcast->dev, mcast); |
| 873 | ipoib_mcast_free(mcast); |
| 874 | } |
| 875 | |
| 876 | if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) |
| 877 | ipoib_mcast_start_thread(dev); |
| 878 | } |
| 879 | |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 880 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev) |
| 883 | { |
| 884 | struct ipoib_mcast_iter *iter; |
| 885 | |
| 886 | iter = kmalloc(sizeof *iter, GFP_KERNEL); |
| 887 | if (!iter) |
| 888 | return NULL; |
| 889 | |
| 890 | iter->dev = dev; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 891 | memset(iter->mgid.raw, 0, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | if (ipoib_mcast_iter_next(iter)) { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 894 | kfree(iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | return NULL; |
| 896 | } |
| 897 | |
| 898 | return iter; |
| 899 | } |
| 900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter) |
| 902 | { |
| 903 | struct ipoib_dev_priv *priv = netdev_priv(iter->dev); |
| 904 | struct rb_node *n; |
| 905 | struct ipoib_mcast *mcast; |
| 906 | int ret = 1; |
| 907 | |
| 908 | spin_lock_irq(&priv->lock); |
| 909 | |
| 910 | n = rb_first(&priv->multicast_tree); |
| 911 | |
| 912 | while (n) { |
| 913 | mcast = rb_entry(n, struct ipoib_mcast, rb_node); |
| 914 | |
| 915 | if (memcmp(iter->mgid.raw, mcast->mcmember.mgid.raw, |
| 916 | sizeof (union ib_gid)) < 0) { |
| 917 | iter->mgid = mcast->mcmember.mgid; |
| 918 | iter->created = mcast->created; |
| 919 | iter->queuelen = skb_queue_len(&mcast->pkt_queue); |
| 920 | iter->complete = !!mcast->ah; |
| 921 | iter->send_only = !!(mcast->flags & (1 << IPOIB_MCAST_FLAG_SENDONLY)); |
| 922 | |
| 923 | ret = 0; |
| 924 | |
| 925 | break; |
| 926 | } |
| 927 | |
| 928 | n = rb_next(n); |
| 929 | } |
| 930 | |
| 931 | spin_unlock_irq(&priv->lock); |
| 932 | |
| 933 | return ret; |
| 934 | } |
| 935 | |
| 936 | void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, |
| 937 | union ib_gid *mgid, |
| 938 | unsigned long *created, |
| 939 | unsigned int *queuelen, |
| 940 | unsigned int *complete, |
| 941 | unsigned int *send_only) |
| 942 | { |
| 943 | *mgid = iter->mgid; |
| 944 | *created = iter->created; |
| 945 | *queuelen = iter->queuelen; |
| 946 | *complete = iter->complete; |
| 947 | *send_only = iter->send_only; |
| 948 | } |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 949 | |
| 950 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |