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