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