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