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