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 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 69 | /* |
| 70 | * This should be called with the mcast_mutex held |
| 71 | */ |
| 72 | static void __ipoib_mcast_schedule_join_thread(struct ipoib_dev_priv *priv, |
| 73 | struct ipoib_mcast *mcast, |
| 74 | bool delay) |
| 75 | { |
| 76 | if (!test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 77 | return; |
| 78 | |
| 79 | /* |
| 80 | * We will be scheduling *something*, so cancel whatever is |
| 81 | * currently scheduled first |
| 82 | */ |
| 83 | cancel_delayed_work(&priv->mcast_task); |
| 84 | if (mcast && delay) { |
| 85 | /* |
| 86 | * We had a failure and want to schedule a retry later |
| 87 | */ |
| 88 | mcast->backoff *= 2; |
| 89 | if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) |
| 90 | mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; |
| 91 | mcast->delay_until = jiffies + (mcast->backoff * HZ); |
| 92 | /* |
| 93 | * Mark this mcast for its delay, but restart the |
| 94 | * task immediately. The join task will make sure to |
| 95 | * clear out all entries without delays, and then |
| 96 | * schedule itself to run again when the earliest |
| 97 | * delay expires |
| 98 | */ |
| 99 | queue_delayed_work(priv->wq, &priv->mcast_task, 0); |
| 100 | } else if (delay) { |
| 101 | /* |
| 102 | * Special case of retrying after a failure to |
| 103 | * allocate the broadcast multicast group, wait |
| 104 | * 1 second and try again |
| 105 | */ |
| 106 | queue_delayed_work(priv->wq, &priv->mcast_task, HZ); |
| 107 | } else |
| 108 | queue_delayed_work(priv->wq, &priv->mcast_task, 0); |
| 109 | } |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static void ipoib_mcast_free(struct ipoib_mcast *mcast) |
| 112 | { |
| 113 | struct net_device *dev = mcast->dev; |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 114 | int tx_dropped = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 116 | ipoib_dbg_mcast(netdev_priv(dev), "deleting multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 117 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 119 | /* remove all neigh connected to this mcast */ |
| 120 | ipoib_del_neighs_by_gid(dev, mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | if (mcast->ah) |
| 123 | ipoib_put_ah(mcast->ah); |
| 124 | |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 125 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
| 126 | ++tx_dropped; |
Roland Dreier | 8c608a3 | 2005-11-07 10:49:38 -0800 | [diff] [blame] | 127 | dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue)); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 130 | netif_tx_lock_bh(dev); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 131 | dev->stats.tx_dropped += tx_dropped; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 132 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | kfree(mcast); |
| 135 | } |
| 136 | |
| 137 | static struct ipoib_mcast *ipoib_mcast_alloc(struct net_device *dev, |
| 138 | int can_sleep) |
| 139 | { |
| 140 | struct ipoib_mcast *mcast; |
| 141 | |
Roland Dreier | de6eb66 | 2005-11-02 07:23:14 -0800 | [diff] [blame] | 142 | mcast = kzalloc(sizeof *mcast, can_sleep ? GFP_KERNEL : GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (!mcast) |
| 144 | return NULL; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | mcast->dev = dev; |
| 147 | mcast->created = jiffies; |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 148 | mcast->delay_until = jiffies; |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 149 | mcast->backoff = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | INIT_LIST_HEAD(&mcast->list); |
| 152 | INIT_LIST_HEAD(&mcast->neigh_list); |
| 153 | skb_queue_head_init(&mcast->pkt_queue); |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | return mcast; |
| 156 | } |
| 157 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 158 | 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] | 159 | { |
| 160 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 161 | struct rb_node *n = priv->multicast_tree.rb_node; |
| 162 | |
| 163 | while (n) { |
| 164 | struct ipoib_mcast *mcast; |
| 165 | int ret; |
| 166 | |
| 167 | mcast = rb_entry(n, struct ipoib_mcast, rb_node); |
| 168 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 169 | ret = memcmp(mgid, mcast->mcmember.mgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | sizeof (union ib_gid)); |
| 171 | if (ret < 0) |
| 172 | n = n->rb_left; |
| 173 | else if (ret > 0) |
| 174 | n = n->rb_right; |
| 175 | else |
| 176 | return mcast; |
| 177 | } |
| 178 | |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | static int __ipoib_mcast_add(struct net_device *dev, struct ipoib_mcast *mcast) |
| 183 | { |
| 184 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 185 | struct rb_node **n = &priv->multicast_tree.rb_node, *pn = NULL; |
| 186 | |
| 187 | while (*n) { |
| 188 | struct ipoib_mcast *tmcast; |
| 189 | int ret; |
| 190 | |
| 191 | pn = *n; |
| 192 | tmcast = rb_entry(pn, struct ipoib_mcast, rb_node); |
| 193 | |
| 194 | ret = memcmp(mcast->mcmember.mgid.raw, tmcast->mcmember.mgid.raw, |
| 195 | sizeof (union ib_gid)); |
| 196 | if (ret < 0) |
| 197 | n = &pn->rb_left; |
| 198 | else if (ret > 0) |
| 199 | n = &pn->rb_right; |
| 200 | else |
| 201 | return -EEXIST; |
| 202 | } |
| 203 | |
| 204 | rb_link_node(&mcast->rb_node, pn, n); |
| 205 | rb_insert_color(&mcast->rb_node, &priv->multicast_tree); |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast, |
| 211 | struct ib_sa_mcmember_rec *mcmember) |
| 212 | { |
| 213 | struct net_device *dev = mcast->dev; |
| 214 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Eli Cohen | 7343b23 | 2006-02-27 20:47:43 -0800 | [diff] [blame] | 215 | struct ipoib_ah *ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | int ret; |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 217 | int set_qkey = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | mcast->mcmember = *mcmember; |
| 220 | |
Patrick McHardy | bea1e22 | 2012-08-30 07:01:30 +0000 | [diff] [blame] | 221 | /* Set the multicast MTU and cached Q_Key before we attach if it's |
| 222 | * the broadcast group. |
| 223 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | if (!memcmp(mcast->mcmember.mgid.raw, priv->dev->broadcast + 4, |
| 225 | sizeof (union ib_gid))) { |
Jack Morgenstein | e1d50dc | 2008-05-20 15:41:09 -0700 | [diff] [blame] | 226 | spin_lock_irq(&priv->lock); |
| 227 | if (!priv->broadcast) { |
| 228 | spin_unlock_irq(&priv->lock); |
| 229 | return -EAGAIN; |
| 230 | } |
Patrick McHardy | bea1e22 | 2012-08-30 07:01:30 +0000 | [diff] [blame] | 231 | priv->mcast_mtu = IPOIB_UD_MTU(ib_mtu_enum_to_int(priv->broadcast->mcmember.mtu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | priv->qkey = be32_to_cpu(priv->broadcast->mcmember.qkey); |
Jack Morgenstein | e1d50dc | 2008-05-20 15:41:09 -0700 | [diff] [blame] | 233 | spin_unlock_irq(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | priv->tx_wr.wr.ud.remote_qkey = priv->qkey; |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 235 | set_qkey = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
| 239 | if (test_and_set_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 240 | ipoib_warn(priv, "multicast group %pI6 already attached\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 241 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | ret = ipoib_mcast_attach(dev, be16_to_cpu(mcast->mcmember.mlid), |
Eli Cohen | d0de136 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 247 | &mcast->mcmember.mgid, set_qkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | if (ret < 0) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 249 | ipoib_warn(priv, "couldn't attach QP to multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 250 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags); |
| 253 | return ret; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | { |
| 258 | struct ib_ah_attr av = { |
| 259 | .dlid = be16_to_cpu(mcast->mcmember.mlid), |
| 260 | .port_num = priv->port, |
| 261 | .sl = mcast->mcmember.sl, |
| 262 | .ah_flags = IB_AH_GRH, |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 263 | .static_rate = mcast->mcmember.rate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .grh = { |
| 265 | .flow_label = be32_to_cpu(mcast->mcmember.flow_label), |
| 266 | .hop_limit = mcast->mcmember.hop_limit, |
| 267 | .sgid_index = 0, |
| 268 | .traffic_class = mcast->mcmember.traffic_class |
| 269 | } |
| 270 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | av.grh.dgid = mcast->mcmember.mgid; |
| 272 | |
Eli Cohen | 7343b23 | 2006-02-27 20:47:43 -0800 | [diff] [blame] | 273 | ah = ipoib_create_ah(dev, priv->pd, &av); |
Mike Marciniszyn | 3874397 | 2011-11-21 08:43:54 -0500 | [diff] [blame] | 274 | if (IS_ERR(ah)) { |
| 275 | ipoib_warn(priv, "ib_address_create failed %ld\n", |
| 276 | -PTR_ERR(ah)); |
| 277 | /* use original error */ |
| 278 | return PTR_ERR(ah); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } else { |
Or Gerlitz | 624d01f | 2006-07-24 10:42:00 +0300 | [diff] [blame] | 280 | spin_lock_irq(&priv->lock); |
| 281 | mcast->ah = ah; |
| 282 | spin_unlock_irq(&priv->lock); |
| 283 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 284 | 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] | 285 | mcast->mcmember.mgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | mcast->ah->ah, |
| 287 | be16_to_cpu(mcast->mcmember.mlid), |
| 288 | mcast->mcmember.sl); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /* actually send any queued packets */ |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 293 | netif_tx_lock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
| 295 | struct sk_buff *skb = skb_dequeue(&mcast->pkt_queue); |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 296 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 297 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | skb->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | if (dev_queue_xmit(skb)) |
| 301 | ipoib_warn(priv, "dev_queue_xmit failed to requeue packet\n"); |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 302 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 303 | netif_tx_lock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 305 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 310 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | ipoib_mcast_sendonly_join_complete(int status, |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 312 | struct ib_sa_multicast *multicast) |
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 | struct ipoib_mcast *mcast = multicast->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct net_device *dev = mcast->dev; |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 316 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 317 | |
| 318 | /* |
| 319 | * We have to take the mutex to force mcast_sendonly_join to |
| 320 | * return from ib_sa_multicast_join and set mcast->mc to a |
| 321 | * valid value. Otherwise we were racing with ourselves in |
| 322 | * that we might fail here, but get a valid return from |
| 323 | * ib_sa_multicast_join after we had cleared mcast->mc here, |
| 324 | * resulting in mis-matched joins and leaves and a deadlock |
| 325 | */ |
| 326 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 328 | /* We trap for port events ourselves. */ |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 329 | if (status == -ENETRESET) { |
| 330 | status = 0; |
| 331 | goto out; |
| 332 | } |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | if (!status) |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 335 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 336 | |
| 337 | if (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (mcast->logcount++ < 20) |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 339 | ipoib_dbg_mcast(netdev_priv(dev), "sendonly multicast " |
| 340 | "join failed for %pI6, status %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 341 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* Flush out any queued packets */ |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 344 | netif_tx_lock_bh(dev); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 345 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 346 | ++dev->stats.tx_dropped; |
Roland Dreier | 8c608a3 | 2005-11-07 10:49:38 -0800 | [diff] [blame] | 347 | dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue)); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 348 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 349 | netif_tx_unlock_bh(dev); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 350 | __ipoib_mcast_schedule_join_thread(priv, mcast, 1); |
| 351 | } else { |
| 352 | mcast->backoff = 1; |
| 353 | mcast->delay_until = jiffies; |
| 354 | __ipoib_mcast_schedule_join_thread(priv, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 356 | out: |
| 357 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 358 | if (status) |
| 359 | mcast->mc = NULL; |
| 360 | complete(&mcast->done); |
| 361 | mutex_unlock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 362 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) |
| 366 | { |
| 367 | struct net_device *dev = mcast->dev; |
| 368 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 369 | struct ib_sa_mcmember_rec rec = { |
| 370 | #if 0 /* Some SMs don't support send-only yet */ |
| 371 | .join_state = 4 |
| 372 | #else |
| 373 | .join_state = 1 |
| 374 | #endif |
| 375 | }; |
| 376 | int ret = 0; |
| 377 | |
| 378 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 379 | ipoib_dbg_mcast(priv, "device shutting down, no sendonly " |
| 380 | "multicast joins\n"); |
| 381 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 382 | complete(&mcast->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return -ENODEV; |
| 384 | } |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | rec.mgid = mcast->mcmember.mgid; |
| 387 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 388 | rec.pkey = cpu_to_be16(priv->pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 390 | mutex_lock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 391 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, |
| 392 | priv->port, &rec, |
| 393 | IB_SA_MCMEMBER_REC_MGID | |
| 394 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 395 | IB_SA_MCMEMBER_REC_PKEY | |
| 396 | IB_SA_MCMEMBER_REC_JOIN_STATE, |
| 397 | GFP_ATOMIC, |
| 398 | ipoib_mcast_sendonly_join_complete, |
| 399 | mcast); |
| 400 | if (IS_ERR(mcast->mc)) { |
| 401 | ret = PTR_ERR(mcast->mc); |
| 402 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 403 | ipoib_warn(priv, "ib_sa_join_multicast for sendonly join " |
| 404 | "failed (ret = %d)\n", ret); |
| 405 | complete(&mcast->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } else { |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 407 | ipoib_dbg_mcast(priv, "no multicast record for %pI6, starting " |
| 408 | "sendonly join\n", mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 410 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | return ret; |
| 413 | } |
| 414 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 415 | void ipoib_mcast_carrier_on_task(struct work_struct *work) |
| 416 | { |
| 417 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 418 | carrier_on_task); |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 419 | struct ib_port_attr attr; |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 420 | |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 421 | if (ib_query_port(priv->ca, priv->port, &attr) || |
| 422 | attr.state != IB_PORT_ACTIVE) { |
| 423 | ipoib_dbg(priv, "Keeping carrier off until IB port is active\n"); |
| 424 | return; |
| 425 | } |
| 426 | |
Doug Ledford | 894021a | 2015-02-21 19:27:02 -0500 | [diff] [blame] | 427 | /* |
| 428 | * Take rtnl_lock to avoid racing with ipoib_stop() and |
| 429 | * turning the carrier back on while a device is being |
| 430 | * removed. However, ipoib_stop() will attempt to flush |
| 431 | * the workqueue while holding the rtnl lock, so loop |
| 432 | * on trylock until either we get the lock or we see |
| 433 | * FLAG_OPER_UP go away as that signals that we are bailing |
| 434 | * and can safely ignore the carrier on work. |
| 435 | */ |
| 436 | while (!rtnl_trylock()) { |
| 437 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
| 438 | return; |
| 439 | else |
| 440 | msleep(20); |
| 441 | } |
Doug Ledford | c84ca6d | 2015-02-21 19:27:01 -0500 | [diff] [blame] | 442 | if (!ipoib_cm_admin_enabled(priv->dev)) |
| 443 | dev_set_mtu(priv->dev, min(priv->mcast_mtu, priv->admin_mtu)); |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 444 | netif_carrier_on(priv->dev); |
| 445 | rtnl_unlock(); |
| 446 | } |
| 447 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 448 | static int ipoib_mcast_join_complete(int status, |
| 449 | struct ib_sa_multicast *multicast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 451 | struct ipoib_mcast *mcast = multicast->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | struct net_device *dev = mcast->dev; |
| 453 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 454 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 455 | ipoib_dbg_mcast(priv, "join completion for %pI6 (status %d)\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 456 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 458 | /* |
| 459 | * We have to take the mutex to force mcast_join to |
| 460 | * return from ib_sa_multicast_join and set mcast->mc to a |
| 461 | * valid value. Otherwise we were racing with ourselves in |
| 462 | * that we might fail here, but get a valid return from |
| 463 | * ib_sa_multicast_join after we had cleared mcast->mc here, |
| 464 | * resulting in mis-matched joins and leaves and a deadlock |
| 465 | */ |
| 466 | mutex_lock(&mcast_mutex); |
| 467 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 468 | /* We trap for port events ourselves. */ |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 469 | if (status == -ENETRESET) { |
| 470 | status = 0; |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 471 | goto out; |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 472 | } |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 473 | |
| 474 | if (!status) |
| 475 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 476 | |
| 477 | if (!status) { |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 478 | mcast->backoff = 1; |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 479 | mcast->delay_until = jiffies; |
| 480 | __ipoib_mcast_schedule_join_thread(priv, NULL, 0); |
Shirley Ma | 55c9add | 2007-03-08 14:59:30 -0800 | [diff] [blame] | 481 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 482 | /* |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 483 | * Defer carrier on work to priv->wq to avoid a |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 484 | * deadlock on rtnl_lock here. |
| 485 | */ |
| 486 | if (mcast == priv->broadcast) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 487 | queue_work(priv->wq, &priv->carrier_on_task); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 488 | } else { |
| 489 | if (mcast->logcount++ < 20) { |
| 490 | if (status == -ETIMEDOUT || status == -EAGAIN) { |
| 491 | ipoib_dbg_mcast(priv, "multicast join failed for %pI6, status %d\n", |
| 492 | mcast->mcmember.mgid.raw, status); |
| 493 | } else { |
| 494 | ipoib_warn(priv, "multicast join failed for %pI6, status %d\n", |
| 495 | mcast->mcmember.mgid.raw, status); |
| 496 | } |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 497 | } |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 498 | |
| 499 | /* Requeue this join task with a backoff delay */ |
| 500 | __ipoib_mcast_schedule_join_thread(priv, mcast, 1); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 501 | } |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 502 | out: |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 503 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 504 | if (status) |
| 505 | mcast->mc = NULL; |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 506 | complete(&mcast->done); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 507 | mutex_unlock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 508 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, |
| 512 | int create) |
| 513 | { |
| 514 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 515 | struct ib_sa_mcmember_rec rec = { |
| 516 | .join_state = 1 |
| 517 | }; |
| 518 | ib_sa_comp_mask comp_mask; |
| 519 | int ret = 0; |
| 520 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 521 | ipoib_dbg_mcast(priv, "joining MGID %pI6\n", mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | rec.mgid = mcast->mcmember.mgid; |
| 524 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 525 | rec.pkey = cpu_to_be16(priv->pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | comp_mask = |
| 528 | IB_SA_MCMEMBER_REC_MGID | |
| 529 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 530 | IB_SA_MCMEMBER_REC_PKEY | |
| 531 | IB_SA_MCMEMBER_REC_JOIN_STATE; |
| 532 | |
| 533 | if (create) { |
| 534 | comp_mask |= |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 535 | IB_SA_MCMEMBER_REC_QKEY | |
| 536 | IB_SA_MCMEMBER_REC_MTU_SELECTOR | |
| 537 | IB_SA_MCMEMBER_REC_MTU | |
| 538 | IB_SA_MCMEMBER_REC_TRAFFIC_CLASS | |
| 539 | IB_SA_MCMEMBER_REC_RATE_SELECTOR | |
| 540 | IB_SA_MCMEMBER_REC_RATE | |
| 541 | IB_SA_MCMEMBER_REC_SL | |
| 542 | IB_SA_MCMEMBER_REC_FLOW_LABEL | |
| 543 | IB_SA_MCMEMBER_REC_HOP_LIMIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | rec.qkey = priv->broadcast->mcmember.qkey; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 546 | rec.mtu_selector = IB_SA_EQ; |
| 547 | rec.mtu = priv->broadcast->mcmember.mtu; |
| 548 | rec.traffic_class = priv->broadcast->mcmember.traffic_class; |
| 549 | rec.rate_selector = IB_SA_EQ; |
| 550 | rec.rate = priv->broadcast->mcmember.rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | rec.sl = priv->broadcast->mcmember.sl; |
| 552 | rec.flow_label = priv->broadcast->mcmember.flow_label; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 553 | rec.hop_limit = priv->broadcast->mcmember.hop_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 556 | mutex_lock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 557 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port, |
| 558 | &rec, comp_mask, GFP_KERNEL, |
| 559 | ipoib_mcast_join_complete, mcast); |
| 560 | if (IS_ERR(mcast->mc)) { |
| 561 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 562 | ret = PTR_ERR(mcast->mc); |
| 563 | ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 564 | __ipoib_mcast_schedule_join_thread(priv, mcast, 1); |
| 565 | complete(&mcast->done); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 566 | } |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 567 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 570 | void ipoib_mcast_join_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 572 | struct ipoib_dev_priv *priv = |
| 573 | container_of(work, struct ipoib_dev_priv, mcast_task.work); |
| 574 | struct net_device *dev = priv->dev; |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 575 | struct ib_port_attr port_attr; |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 576 | unsigned long delay_until = 0; |
| 577 | struct ipoib_mcast *mcast = NULL; |
| 578 | int create = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | if (!test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 581 | return; |
| 582 | |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 583 | if (ib_query_port(priv->ca, priv->port, &port_attr) || |
| 584 | port_attr.state != IB_PORT_ACTIVE) { |
| 585 | ipoib_dbg(priv, "port state is not ACTIVE (state = %d) suspending join task\n", |
| 586 | port_attr.state); |
| 587 | return; |
| 588 | } |
Alex Estrin | 68f9d83 | 2014-08-20 11:15:08 -0400 | [diff] [blame] | 589 | priv->local_lid = port_attr.lid; |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | 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] | 592 | ipoib_warn(priv, "ib_query_gid() failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | else |
| 594 | memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); |
| 595 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 596 | /* |
| 597 | * We have to hold the mutex to keep from racing with the join |
| 598 | * completion threads on setting flags on mcasts, and we have |
| 599 | * to hold the priv->lock because dev_flush will remove entries |
| 600 | * out from underneath us, so at a minimum we need the lock |
| 601 | * through the time that we do the for_each loop of the mcast |
| 602 | * list or else dev_flush can make us oops. |
| 603 | */ |
| 604 | mutex_lock(&mcast_mutex); |
| 605 | spin_lock_irq(&priv->lock); |
| 606 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
| 607 | goto out; |
| 608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (!priv->broadcast) { |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 610 | struct ipoib_mcast *broadcast; |
| 611 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 612 | broadcast = ipoib_mcast_alloc(dev, 0); |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 613 | if (!broadcast) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | ipoib_warn(priv, "failed to allocate broadcast group\n"); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 615 | /* |
| 616 | * Restart us after a 1 second delay to retry |
| 617 | * creating our broadcast group and attaching to |
| 618 | * it. Until this succeeds, this ipoib dev is |
| 619 | * completely stalled (multicast wise). |
| 620 | */ |
| 621 | __ipoib_mcast_schedule_join_thread(priv, NULL, 1); |
| 622 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 625 | memcpy(broadcast->mcmember.mgid.raw, priv->dev->broadcast + 4, |
| 626 | sizeof (union ib_gid)); |
| 627 | priv->broadcast = broadcast; |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | __ipoib_mcast_add(dev, priv->broadcast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 633 | if (IS_ERR_OR_NULL(priv->broadcast->mc) && |
| 634 | !test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags)) { |
| 635 | mcast = priv->broadcast; |
| 636 | create = 0; |
| 637 | if (mcast->backoff > 1 && |
| 638 | time_before(jiffies, mcast->delay_until)) { |
| 639 | delay_until = mcast->delay_until; |
| 640 | mcast = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 643 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 646 | /* |
| 647 | * We'll never get here until the broadcast group is both allocated |
| 648 | * and attached |
| 649 | */ |
| 650 | list_for_each_entry(mcast, &priv->multicast_list, list) { |
| 651 | if (IS_ERR_OR_NULL(mcast->mc) && |
| 652 | !test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags) && |
| 653 | !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
| 654 | if (mcast->backoff == 1 || |
| 655 | time_after_eq(jiffies, mcast->delay_until)) |
| 656 | /* Found the next unjoined group */ |
| 657 | break; |
| 658 | else if (!delay_until || |
| 659 | time_before(mcast->delay_until, delay_until)) |
| 660 | delay_until = mcast->delay_until; |
| 661 | } |
| 662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 664 | if (&mcast->list == &priv->multicast_list) { |
| 665 | /* |
| 666 | * All done, unless we have delayed work from |
| 667 | * backoff retransmissions, but we will get |
| 668 | * restarted when the time is right, so we are |
| 669 | * done for now |
| 670 | */ |
| 671 | mcast = NULL; |
| 672 | ipoib_dbg_mcast(priv, "successfully joined all " |
| 673 | "multicast groups\n"); |
| 674 | } |
| 675 | |
| 676 | out: |
| 677 | if (mcast) { |
| 678 | init_completion(&mcast->done); |
| 679 | set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 680 | } |
| 681 | spin_unlock_irq(&priv->lock); |
| 682 | mutex_unlock(&mcast_mutex); |
| 683 | if (mcast) { |
| 684 | if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) |
| 685 | ipoib_mcast_sendonly_join(mcast); |
| 686 | else |
| 687 | ipoib_mcast_join(dev, mcast, create); |
| 688 | } |
| 689 | if (delay_until) |
| 690 | queue_delayed_work(priv->wq, &priv->mcast_task, |
| 691 | delay_until - jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | int ipoib_mcast_start_thread(struct net_device *dev) |
| 695 | { |
| 696 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 697 | |
| 698 | ipoib_dbg_mcast(priv, "starting multicast thread\n"); |
| 699 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 700 | mutex_lock(&mcast_mutex); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 701 | set_bit(IPOIB_MCAST_RUN, &priv->flags); |
| 702 | __ipoib_mcast_schedule_join_thread(priv, NULL, 0); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 703 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 708 | int ipoib_mcast_stop_thread(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
| 710 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
| 712 | ipoib_dbg_mcast(priv, "stopping multicast thread\n"); |
| 713 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 714 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
| 716 | cancel_delayed_work(&priv->mcast_task); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 717 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 719 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) |
| 725 | { |
| 726 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | int ret = 0; |
| 728 | |
Sean Hefty | e07832b | 2007-03-19 14:31:36 -0800 | [diff] [blame] | 729 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 730 | ipoib_warn(priv, "ipoib_mcast_leave on an in-flight join\n"); |
| 731 | |
| 732 | if (!IS_ERR_OR_NULL(mcast->mc)) |
Sean Hefty | e07832b | 2007-03-19 14:31:36 -0800 | [diff] [blame] | 733 | ib_sa_free_multicast(mcast->mc); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 734 | else |
| 735 | ipoib_dbg(priv, "ipoib_mcast_leave with mcast->mc invalid\n"); |
Sean Hefty | e07832b | 2007-03-19 14:31:36 -0800 | [diff] [blame] | 736 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 737 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 738 | ipoib_dbg_mcast(priv, "leaving MGID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 739 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 741 | /* Remove ourselves from the multicast group */ |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 742 | ret = ib_detach_mcast(priv->qp, &mcast->mcmember.mgid, |
| 743 | be16_to_cpu(mcast->mcmember.mlid)); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 744 | if (ret) |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 745 | ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 746 | } else if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) |
| 747 | ipoib_dbg(priv, "leaving with no mcmember but not a " |
| 748 | "SENDONLY join\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | return 0; |
| 751 | } |
| 752 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 753 | void ipoib_mcast_send(struct net_device *dev, u8 *daddr, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
| 755 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 756 | struct ipoib_mcast *mcast; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 757 | unsigned long flags; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 758 | void *mgid = daddr + 4; |
David S. Miller | 700db99 | 2012-07-05 21:08:05 -0700 | [diff] [blame] | 759 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 760 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Or Gerlitz | b3e2749 | 2008-03-11 16:10:02 +0200 | [diff] [blame] | 762 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags) || |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 763 | !priv->broadcast || |
| 764 | !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 765 | ++dev->stats.tx_dropped; |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 766 | dev_kfree_skb_any(skb); |
| 767 | goto unlock; |
| 768 | } |
| 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | mcast = __ipoib_mcast_find(dev, mgid); |
| 771 | if (!mcast) { |
| 772 | /* Let's create a new send only group now */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 773 | 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] | 774 | mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | mcast = ipoib_mcast_alloc(dev, 0); |
| 777 | if (!mcast) { |
| 778 | ipoib_warn(priv, "unable to allocate memory for " |
| 779 | "multicast structure\n"); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 780 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | dev_kfree_skb_any(skb); |
| 782 | goto out; |
| 783 | } |
| 784 | |
| 785 | set_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags); |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 786 | memcpy(mcast->mcmember.mgid.raw, mgid, sizeof (union ib_gid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | __ipoib_mcast_add(dev, mcast); |
| 788 | list_add_tail(&mcast->list, &priv->multicast_list); |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 789 | __ipoib_mcast_schedule_join_thread(priv, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | if (!mcast->ah) { |
| 793 | if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE) |
| 794 | skb_queue_tail(&mcast->pkt_queue, skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 795 | else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 796 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | dev_kfree_skb_any(skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | /* |
| 800 | * If lookup completes between here and out:, don't |
| 801 | * want to send packet twice. |
| 802 | */ |
| 803 | mcast = NULL; |
| 804 | } |
| 805 | |
| 806 | out: |
| 807 | if (mcast && mcast->ah) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 808 | struct ipoib_neigh *neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 810 | spin_unlock_irqrestore(&priv->lock, flags); |
| 811 | neigh = ipoib_neigh_get(dev, daddr); |
| 812 | spin_lock_irqsave(&priv->lock, flags); |
| 813 | if (!neigh) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 814 | neigh = ipoib_neigh_alloc(daddr, dev); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 815 | if (neigh) { |
| 816 | kref_get(&mcast->ah->ref); |
| 817 | neigh->ah = mcast->ah; |
| 818 | list_add_tail(&neigh->list, &mcast->neigh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 821 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 823 | if (neigh) |
| 824 | ipoib_neigh_put(neigh); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 825 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 828 | unlock: |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 829 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | void ipoib_mcast_dev_flush(struct net_device *dev) |
| 833 | { |
| 834 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 835 | LIST_HEAD(remove_list); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 836 | struct ipoib_mcast *mcast, *tmcast; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | unsigned long flags; |
| 838 | |
| 839 | ipoib_dbg_mcast(priv, "flushing multicast list\n"); |
| 840 | |
| 841 | spin_lock_irqsave(&priv->lock, flags); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 844 | list_del(&mcast->list); |
| 845 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 846 | list_add_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | if (priv->broadcast) { |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 850 | rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 851 | list_add_tail(&priv->broadcast->list, &remove_list); |
| 852 | priv->broadcast = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | spin_unlock_irqrestore(&priv->lock, flags); |
| 856 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 857 | /* |
| 858 | * make sure the in-flight joins have finished before we attempt |
| 859 | * to leave |
| 860 | */ |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 861 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 862 | if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 863 | wait_for_completion(&mcast->done); |
| 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 866 | ipoib_mcast_leave(dev, mcast); |
| 867 | ipoib_mcast_free(mcast); |
| 868 | } |
| 869 | } |
| 870 | |
Jiri Pirko | 3e4aa12f8 | 2010-03-22 03:21:39 +0000 | [diff] [blame] | 871 | 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] | 872 | { |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 873 | /* reserved QPN, prefix, scope */ |
| 874 | if (memcmp(addr, broadcast, 6)) |
| 875 | return 0; |
| 876 | /* signature lower, pkey */ |
| 877 | if (memcmp(addr + 7, broadcast + 7, 3)) |
| 878 | return 0; |
| 879 | return 1; |
| 880 | } |
| 881 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 882 | void ipoib_mcast_restart_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 884 | struct ipoib_dev_priv *priv = |
| 885 | container_of(work, struct ipoib_dev_priv, restart_task); |
| 886 | struct net_device *dev = priv->dev; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 887 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | struct ipoib_mcast *mcast, *tmcast; |
| 889 | LIST_HEAD(remove_list); |
| 890 | unsigned long flags; |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 891 | struct ib_sa_mcmember_rec rec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 893 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
| 894 | /* |
| 895 | * shortcut...on shutdown flush is called next, just |
| 896 | * let it do all the work |
| 897 | */ |
| 898 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 900 | ipoib_dbg_mcast(priv, "restarting multicast task\n"); |
Roland Dreier | 4e0ab20 | 2015-01-30 15:38:46 -0800 | [diff] [blame] | 901 | |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 902 | local_irq_save(flags); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 903 | netif_addr_lock(dev); |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 904 | spin_lock(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | /* |
| 907 | * Unfortunately, the networking core only gives us a list of all of |
| 908 | * the multicast hardware addresses. We need to figure out which ones |
| 909 | * are new and which ones have been removed |
| 910 | */ |
| 911 | |
| 912 | /* Clear out the found flag */ |
| 913 | list_for_each_entry(mcast, &priv->multicast_list, list) |
| 914 | clear_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 915 | |
| 916 | /* Mark all of the entries that are found or don't exist */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 917 | netdev_for_each_mc_addr(ha, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | union ib_gid mgid; |
| 919 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 920 | if (!ipoib_mcast_addr_is_valid(ha->addr, dev->broadcast)) |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 921 | continue; |
| 922 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 923 | memcpy(mgid.raw, ha->addr + 4, sizeof mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | mcast = __ipoib_mcast_find(dev, &mgid); |
| 926 | if (!mcast || test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
| 927 | struct ipoib_mcast *nmcast; |
| 928 | |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 929 | /* ignore group which is directly joined by userspace */ |
| 930 | if (test_bit(IPOIB_FLAG_UMCAST, &priv->flags) && |
| 931 | !ib_sa_get_mcmember_rec(priv->ca, priv->port, &mgid, &rec)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 932 | ipoib_dbg_mcast(priv, "ignoring multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 933 | mgid.raw); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 934 | continue; |
| 935 | } |
| 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | /* Not found or send-only group, let's add a new entry */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 938 | ipoib_dbg_mcast(priv, "adding multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 939 | mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | nmcast = ipoib_mcast_alloc(dev, 0); |
| 942 | if (!nmcast) { |
| 943 | ipoib_warn(priv, "unable to allocate memory for multicast structure\n"); |
| 944 | continue; |
| 945 | } |
| 946 | |
| 947 | set_bit(IPOIB_MCAST_FLAG_FOUND, &nmcast->flags); |
| 948 | |
| 949 | nmcast->mcmember.mgid = mgid; |
| 950 | |
| 951 | if (mcast) { |
| 952 | /* Destroy the send only entry */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 953 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | rb_replace_node(&mcast->rb_node, |
| 956 | &nmcast->rb_node, |
| 957 | &priv->multicast_tree); |
| 958 | } else |
| 959 | __ipoib_mcast_add(dev, nmcast); |
| 960 | |
| 961 | list_add_tail(&nmcast->list, &priv->multicast_list); |
| 962 | } |
| 963 | |
| 964 | if (mcast) |
| 965 | set_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 966 | } |
| 967 | |
| 968 | /* Remove all of the entries don't exist anymore */ |
| 969 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
| 970 | if (!test_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags) && |
| 971 | !test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 972 | ipoib_dbg_mcast(priv, "deleting multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 973 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 976 | |
| 977 | /* Move to the remove list */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 978 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | } |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 981 | |
| 982 | spin_unlock(&priv->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 983 | netif_addr_unlock(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 984 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 986 | /* |
| 987 | * make sure the in-flight joins have finished before we attempt |
| 988 | * to leave |
| 989 | */ |
| 990 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) |
| 991 | if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
| 992 | wait_for_completion(&mcast->done); |
| 993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 995 | ipoib_mcast_leave(mcast->dev, mcast); |
| 996 | ipoib_mcast_free(mcast); |
| 997 | } |
Roland Dreier | 962121b | 2015-01-30 15:39:11 -0800 | [diff] [blame] | 998 | |
Doug Ledford | 6991141 | 2015-02-21 19:27:05 -0500 | [diff] [blame^] | 999 | /* |
| 1000 | * Double check that we are still up |
| 1001 | */ |
| 1002 | if (test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
| 1003 | spin_lock_irqsave(&priv->lock, flags); |
| 1004 | __ipoib_mcast_schedule_join_thread(priv, NULL, 0); |
| 1005 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1006 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 1009 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 1010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev) |
| 1012 | { |
| 1013 | struct ipoib_mcast_iter *iter; |
| 1014 | |
| 1015 | iter = kmalloc(sizeof *iter, GFP_KERNEL); |
| 1016 | if (!iter) |
| 1017 | return NULL; |
| 1018 | |
| 1019 | iter->dev = dev; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 1020 | memset(iter->mgid.raw, 0, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
| 1022 | if (ipoib_mcast_iter_next(iter)) { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 1023 | kfree(iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | return NULL; |
| 1025 | } |
| 1026 | |
| 1027 | return iter; |
| 1028 | } |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter) |
| 1031 | { |
| 1032 | struct ipoib_dev_priv *priv = netdev_priv(iter->dev); |
| 1033 | struct rb_node *n; |
| 1034 | struct ipoib_mcast *mcast; |
| 1035 | int ret = 1; |
| 1036 | |
| 1037 | spin_lock_irq(&priv->lock); |
| 1038 | |
| 1039 | n = rb_first(&priv->multicast_tree); |
| 1040 | |
| 1041 | while (n) { |
| 1042 | mcast = rb_entry(n, struct ipoib_mcast, rb_node); |
| 1043 | |
| 1044 | if (memcmp(iter->mgid.raw, mcast->mcmember.mgid.raw, |
| 1045 | sizeof (union ib_gid)) < 0) { |
| 1046 | iter->mgid = mcast->mcmember.mgid; |
| 1047 | iter->created = mcast->created; |
| 1048 | iter->queuelen = skb_queue_len(&mcast->pkt_queue); |
| 1049 | iter->complete = !!mcast->ah; |
| 1050 | iter->send_only = !!(mcast->flags & (1 << IPOIB_MCAST_FLAG_SENDONLY)); |
| 1051 | |
| 1052 | ret = 0; |
| 1053 | |
| 1054 | break; |
| 1055 | } |
| 1056 | |
| 1057 | n = rb_next(n); |
| 1058 | } |
| 1059 | |
| 1060 | spin_unlock_irq(&priv->lock); |
| 1061 | |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, |
| 1066 | union ib_gid *mgid, |
| 1067 | unsigned long *created, |
| 1068 | unsigned int *queuelen, |
| 1069 | unsigned int *complete, |
| 1070 | unsigned int *send_only) |
| 1071 | { |
| 1072 | *mgid = iter->mgid; |
| 1073 | *created = iter->created; |
| 1074 | *queuelen = iter->queuelen; |
| 1075 | *complete = iter->complete; |
| 1076 | *send_only = iter->send_only; |
| 1077 | } |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 1078 | |
| 1079 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |