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