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 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 274 | /* We trap for port events ourselves. */ |
| 275 | if (status == -ENETRESET) |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 276 | return 0; |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (!status) |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 279 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 280 | |
| 281 | if (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (mcast->logcount++ < 20) |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 283 | ipoib_dbg_mcast(netdev_priv(dev), "multicast join failed for %pI6, status %d\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 284 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* Flush out any queued packets */ |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 287 | netif_tx_lock_bh(dev); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 288 | while (!skb_queue_empty(&mcast->pkt_queue)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 289 | ++dev->stats.tx_dropped; |
Roland Dreier | 8c608a3 | 2005-11-07 10:49:38 -0800 | [diff] [blame] | 290 | dev_kfree_skb_any(skb_dequeue(&mcast->pkt_queue)); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 291 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 292 | netif_tx_unlock_bh(dev); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 293 | |
| 294 | /* Clear the busy flag so we try again */ |
| 295 | status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, |
| 296 | &mcast->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 298 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static int ipoib_mcast_sendonly_join(struct ipoib_mcast *mcast) |
| 302 | { |
| 303 | struct net_device *dev = mcast->dev; |
| 304 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 305 | struct ib_sa_mcmember_rec rec = { |
| 306 | #if 0 /* Some SMs don't support send-only yet */ |
| 307 | .join_state = 4 |
| 308 | #else |
| 309 | .join_state = 1 |
| 310 | #endif |
| 311 | }; |
| 312 | int ret = 0; |
| 313 | |
| 314 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 315 | ipoib_dbg_mcast(priv, "device shutting down, no multicast joins\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | return -ENODEV; |
| 317 | } |
| 318 | |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 319 | if (test_and_set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) { |
| 320 | ipoib_dbg_mcast(priv, "multicast entry busy, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | return -EBUSY; |
| 322 | } |
| 323 | |
| 324 | rec.mgid = mcast->mcmember.mgid; |
| 325 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 326 | rec.pkey = cpu_to_be16(priv->pkey); |
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 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, |
| 329 | priv->port, &rec, |
| 330 | IB_SA_MCMEMBER_REC_MGID | |
| 331 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 332 | IB_SA_MCMEMBER_REC_PKEY | |
| 333 | IB_SA_MCMEMBER_REC_JOIN_STATE, |
| 334 | GFP_ATOMIC, |
| 335 | ipoib_mcast_sendonly_join_complete, |
| 336 | mcast); |
| 337 | if (IS_ERR(mcast->mc)) { |
| 338 | ret = PTR_ERR(mcast->mc); |
| 339 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 340 | ipoib_warn(priv, "ib_sa_join_multicast failed (ret = %d)\n", |
| 341 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } else { |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 343 | ipoib_dbg_mcast(priv, "no multicast record for %pI6, starting join\n", |
| 344 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | return ret; |
| 348 | } |
| 349 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 350 | void ipoib_mcast_carrier_on_task(struct work_struct *work) |
| 351 | { |
| 352 | struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, |
| 353 | carrier_on_task); |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 354 | struct ib_port_attr attr; |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 355 | |
Moni Shoua | 5ee95120 | 2009-09-24 12:01:05 -0700 | [diff] [blame] | 356 | if (ib_query_port(priv->ca, priv->port, &attr) || |
| 357 | attr.state != IB_PORT_ACTIVE) { |
| 358 | ipoib_dbg(priv, "Keeping carrier off until IB port is active\n"); |
| 359 | return; |
| 360 | } |
| 361 | |
Doug Ledford | 894021a | 2015-02-21 19:27:02 -0500 | [diff] [blame] | 362 | /* |
| 363 | * Take rtnl_lock to avoid racing with ipoib_stop() and |
| 364 | * turning the carrier back on while a device is being |
| 365 | * removed. However, ipoib_stop() will attempt to flush |
| 366 | * the workqueue while holding the rtnl lock, so loop |
| 367 | * on trylock until either we get the lock or we see |
| 368 | * FLAG_OPER_UP go away as that signals that we are bailing |
| 369 | * and can safely ignore the carrier on work. |
| 370 | */ |
| 371 | while (!rtnl_trylock()) { |
| 372 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
| 373 | return; |
| 374 | else |
| 375 | msleep(20); |
| 376 | } |
Doug Ledford | c84ca6d | 2015-02-21 19:27:01 -0500 | [diff] [blame] | 377 | if (!ipoib_cm_admin_enabled(priv->dev)) |
| 378 | dev_set_mtu(priv->dev, min(priv->mcast_mtu, priv->admin_mtu)); |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 379 | netif_carrier_on(priv->dev); |
| 380 | rtnl_unlock(); |
| 381 | } |
| 382 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 383 | static int ipoib_mcast_join_complete(int status, |
| 384 | struct ib_sa_multicast *multicast) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 386 | struct ipoib_mcast *mcast = multicast->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | struct net_device *dev = mcast->dev; |
| 388 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 389 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 390 | ipoib_dbg_mcast(priv, "join completion for %pI6 (status %d)\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 391 | mcast->mcmember.mgid.raw, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 393 | /* We trap for port events ourselves. */ |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 394 | if (status == -ENETRESET) { |
| 395 | status = 0; |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 396 | goto out; |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 397 | } |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 398 | |
| 399 | if (!status) |
| 400 | status = ipoib_mcast_join_finish(mcast, &multicast->rec); |
| 401 | |
| 402 | if (!status) { |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 403 | mcast->backoff = 1; |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 404 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 406 | queue_delayed_work(priv->wq, &priv->mcast_task, 0); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 407 | mutex_unlock(&mcast_mutex); |
Shirley Ma | 55c9add | 2007-03-08 14:59:30 -0800 | [diff] [blame] | 408 | |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 409 | /* |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 410 | * Defer carrier on work to priv->wq to avoid a |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 411 | * deadlock on rtnl_lock here. |
| 412 | */ |
| 413 | if (mcast == priv->broadcast) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 414 | queue_work(priv->wq, &priv->carrier_on_task); |
Doug Ledford | 016d9fb | 2014-12-10 11:47:00 -0500 | [diff] [blame] | 415 | |
Doug Ledford | 016d9fb | 2014-12-10 11:47:00 -0500 | [diff] [blame] | 416 | status = 0; |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 417 | goto out; |
| 418 | } |
| 419 | |
| 420 | if (mcast->logcount++ < 20) { |
| 421 | if (status == -ETIMEDOUT || status == -EAGAIN) { |
| 422 | ipoib_dbg_mcast(priv, "multicast join failed for %pI6, status %d\n", |
| 423 | mcast->mcmember.mgid.raw, status); |
| 424 | } else { |
| 425 | ipoib_warn(priv, "multicast join failed for %pI6, status %d\n", |
| 426 | mcast->mcmember.mgid.raw, status); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | mcast->backoff *= 2; |
| 431 | if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) |
| 432 | mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; |
| 433 | |
| 434 | /* Clear the busy flag so we try again */ |
| 435 | status = test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
| 436 | |
| 437 | mutex_lock(&mcast_mutex); |
| 438 | spin_lock_irq(&priv->lock); |
| 439 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 440 | queue_delayed_work(priv->wq, &priv->mcast_task, |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 441 | mcast->backoff * HZ); |
Michael S. Tsirkin | 9acf6a8 | 2006-03-02 11:07:47 -0800 | [diff] [blame] | 442 | spin_unlock_irq(&priv->lock); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 443 | mutex_unlock(&mcast_mutex); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 444 | out: |
| 445 | complete(&mcast->done); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 446 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, |
| 450 | int create) |
| 451 | { |
| 452 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 453 | struct ib_sa_mcmember_rec rec = { |
| 454 | .join_state = 1 |
| 455 | }; |
| 456 | ib_sa_comp_mask comp_mask; |
| 457 | int ret = 0; |
| 458 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 459 | ipoib_dbg_mcast(priv, "joining MGID %pI6\n", mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | rec.mgid = mcast->mcmember.mgid; |
| 462 | rec.port_gid = priv->local_gid; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 463 | rec.pkey = cpu_to_be16(priv->pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | comp_mask = |
| 466 | IB_SA_MCMEMBER_REC_MGID | |
| 467 | IB_SA_MCMEMBER_REC_PORT_GID | |
| 468 | IB_SA_MCMEMBER_REC_PKEY | |
| 469 | IB_SA_MCMEMBER_REC_JOIN_STATE; |
| 470 | |
| 471 | if (create) { |
| 472 | comp_mask |= |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 473 | IB_SA_MCMEMBER_REC_QKEY | |
| 474 | IB_SA_MCMEMBER_REC_MTU_SELECTOR | |
| 475 | IB_SA_MCMEMBER_REC_MTU | |
| 476 | IB_SA_MCMEMBER_REC_TRAFFIC_CLASS | |
| 477 | IB_SA_MCMEMBER_REC_RATE_SELECTOR | |
| 478 | IB_SA_MCMEMBER_REC_RATE | |
| 479 | IB_SA_MCMEMBER_REC_SL | |
| 480 | IB_SA_MCMEMBER_REC_FLOW_LABEL | |
| 481 | IB_SA_MCMEMBER_REC_HOP_LIMIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | rec.qkey = priv->broadcast->mcmember.qkey; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 484 | rec.mtu_selector = IB_SA_EQ; |
| 485 | rec.mtu = priv->broadcast->mcmember.mtu; |
| 486 | rec.traffic_class = priv->broadcast->mcmember.traffic_class; |
| 487 | rec.rate_selector = IB_SA_EQ; |
| 488 | rec.rate = priv->broadcast->mcmember.rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | rec.sl = priv->broadcast->mcmember.sl; |
| 490 | rec.flow_label = priv->broadcast->mcmember.flow_label; |
Roland Dreier | d0df6d6 | 2006-09-22 15:22:56 -0700 | [diff] [blame] | 491 | rec.hop_limit = priv->broadcast->mcmember.hop_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Doug Ledford | 016d9fb | 2014-12-10 11:47:00 -0500 | [diff] [blame] | 494 | set_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 495 | init_completion(&mcast->done); |
| 496 | set_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags); |
| 497 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 498 | mcast->mc = ib_sa_join_multicast(&ipoib_sa_client, priv->ca, priv->port, |
| 499 | &rec, comp_mask, GFP_KERNEL, |
| 500 | ipoib_mcast_join_complete, mcast); |
| 501 | if (IS_ERR(mcast->mc)) { |
| 502 | clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags); |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 503 | complete(&mcast->done); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 504 | ret = PTR_ERR(mcast->mc); |
| 505 | ipoib_warn(priv, "ib_sa_join_multicast failed, status %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | mcast->backoff *= 2; |
| 508 | if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) |
| 509 | mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; |
| 510 | |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 511 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 513 | queue_delayed_work(priv->wq, &priv->mcast_task, |
Hal Rosenstock | ce5b65c | 2005-09-18 13:47:53 -0700 | [diff] [blame] | 514 | mcast->backoff * HZ); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 515 | mutex_unlock(&mcast_mutex); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 519 | void ipoib_mcast_join_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 521 | struct ipoib_dev_priv *priv = |
| 522 | container_of(work, struct ipoib_dev_priv, mcast_task.work); |
| 523 | struct net_device *dev = priv->dev; |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 524 | struct ib_port_attr port_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | if (!test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
| 527 | return; |
| 528 | |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 529 | if (ib_query_port(priv->ca, priv->port, &port_attr) || |
| 530 | port_attr.state != IB_PORT_ACTIVE) { |
| 531 | ipoib_dbg(priv, "port state is not ACTIVE (state = %d) suspending join task\n", |
| 532 | port_attr.state); |
| 533 | return; |
| 534 | } |
Alex Estrin | 68f9d83 | 2014-08-20 11:15:08 -0400 | [diff] [blame] | 535 | priv->local_lid = port_attr.lid; |
Erez Shitrit | 94232d9 | 2013-10-16 17:37:53 +0300 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | 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] | 538 | ipoib_warn(priv, "ib_query_gid() failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | else |
| 540 | memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (!priv->broadcast) { |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 543 | struct ipoib_mcast *broadcast; |
| 544 | |
Doug Ledford | 894021a | 2015-02-21 19:27:02 -0500 | [diff] [blame] | 545 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
Yossi Etigin | 50df48f | 2009-01-12 19:28:42 -0800 | [diff] [blame] | 546 | return; |
| 547 | |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 548 | broadcast = ipoib_mcast_alloc(dev, 1); |
| 549 | if (!broadcast) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | ipoib_warn(priv, "failed to allocate broadcast group\n"); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 551 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 553 | queue_delayed_work(priv->wq, &priv->mcast_task, |
| 554 | HZ); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 555 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return; |
| 557 | } |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | spin_lock_irq(&priv->lock); |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 560 | memcpy(broadcast->mcmember.mgid.raw, priv->dev->broadcast + 4, |
| 561 | sizeof (union ib_gid)); |
| 562 | priv->broadcast = broadcast; |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | __ipoib_mcast_add(dev, priv->broadcast); |
| 565 | spin_unlock_irq(&priv->lock); |
| 566 | } |
| 567 | |
| 568 | if (!test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 569 | if (!test_bit(IPOIB_MCAST_FLAG_BUSY, &priv->broadcast->flags)) |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 570 | ipoib_mcast_join(dev, priv->broadcast, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | |
| 574 | while (1) { |
| 575 | struct ipoib_mcast *mcast = NULL; |
| 576 | |
| 577 | spin_lock_irq(&priv->lock); |
| 578 | list_for_each_entry(mcast, &priv->multicast_list, list) { |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 579 | if (!test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags) |
| 580 | && !test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags) |
| 581 | && !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* Found the next unjoined group */ |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | spin_unlock_irq(&priv->lock); |
| 587 | |
| 588 | if (&mcast->list == &priv->multicast_list) { |
| 589 | /* All done */ |
| 590 | break; |
| 591 | } |
| 592 | |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 593 | ipoib_mcast_join(dev, mcast, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return; |
| 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n"); |
| 598 | |
| 599 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | int ipoib_mcast_start_thread(struct net_device *dev) |
| 603 | { |
| 604 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 605 | |
| 606 | ipoib_dbg_mcast(priv, "starting multicast thread\n"); |
| 607 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 608 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 610 | queue_delayed_work(priv->wq, &priv->mcast_task, 0); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 611 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame^] | 616 | int ipoib_mcast_stop_thread(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
| 618 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | ipoib_dbg_mcast(priv, "stopping multicast thread\n"); |
| 621 | |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 622 | mutex_lock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
| 624 | cancel_delayed_work(&priv->mcast_task); |
Ingo Molnar | 95ed644 | 2006-01-13 14:51:39 -0800 | [diff] [blame] | 625 | mutex_unlock(&mcast_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame^] | 627 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | static int ipoib_mcast_leave(struct net_device *dev, struct ipoib_mcast *mcast) |
| 633 | { |
| 634 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | int ret = 0; |
| 636 | |
Sean Hefty | e07832b | 2007-03-19 14:31:36 -0800 | [diff] [blame] | 637 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
| 638 | ib_sa_free_multicast(mcast->mc); |
| 639 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 640 | if (test_and_clear_bit(IPOIB_MCAST_FLAG_ATTACHED, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 641 | ipoib_dbg_mcast(priv, "leaving MGID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 642 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 644 | /* Remove ourselves from the multicast group */ |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 645 | ret = ib_detach_mcast(priv->qp, &mcast->mcmember.mgid, |
| 646 | be16_to_cpu(mcast->mcmember.mlid)); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 647 | if (ret) |
Roland Dreier | 9eae554 | 2008-07-14 23:48:50 -0700 | [diff] [blame] | 648 | ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 654 | 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] | 655 | { |
| 656 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 657 | struct ipoib_mcast *mcast; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 658 | unsigned long flags; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 659 | void *mgid = daddr + 4; |
David S. Miller | 700db99 | 2012-07-05 21:08:05 -0700 | [diff] [blame] | 660 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 661 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Or Gerlitz | b3e2749 | 2008-03-11 16:10:02 +0200 | [diff] [blame] | 663 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags) || |
Roland Dreier | 20b8338 | 2006-02-11 12:22:12 -0800 | [diff] [blame] | 664 | !priv->broadcast || |
| 665 | !test_bit(IPOIB_MCAST_FLAG_ATTACHED, &priv->broadcast->flags)) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 666 | ++dev->stats.tx_dropped; |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 667 | dev_kfree_skb_any(skb); |
| 668 | goto unlock; |
| 669 | } |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | mcast = __ipoib_mcast_find(dev, mgid); |
| 672 | if (!mcast) { |
| 673 | /* Let's create a new send only group now */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 674 | 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] | 675 | mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | mcast = ipoib_mcast_alloc(dev, 0); |
| 678 | if (!mcast) { |
| 679 | ipoib_warn(priv, "unable to allocate memory for " |
| 680 | "multicast structure\n"); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 681 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | dev_kfree_skb_any(skb); |
| 683 | goto out; |
| 684 | } |
| 685 | |
| 686 | set_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags); |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 687 | memcpy(mcast->mcmember.mgid.raw, mgid, sizeof (union ib_gid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | __ipoib_mcast_add(dev, mcast); |
| 689 | list_add_tail(&mcast->list, &priv->multicast_list); |
| 690 | } |
| 691 | |
| 692 | if (!mcast->ah) { |
| 693 | if (skb_queue_len(&mcast->pkt_queue) < IPOIB_MAX_MCAST_QUEUE) |
| 694 | skb_queue_tail(&mcast->pkt_queue, skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 695 | else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 696 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | dev_kfree_skb_any(skb); |
Michael S. Tsirkin | b36f170b6 | 2006-01-17 12:19:40 -0800 | [diff] [blame] | 698 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Sean Hefty | faec2f7 | 2007-02-15 17:00:17 -0800 | [diff] [blame] | 700 | if (test_bit(IPOIB_MCAST_FLAG_BUSY, &mcast->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | ipoib_dbg_mcast(priv, "no address vector, " |
| 702 | "but multicast join already started\n"); |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 703 | else if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) |
| 704 | ipoib_mcast_sendonly_join(mcast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | /* |
| 707 | * If lookup completes between here and out:, don't |
| 708 | * want to send packet twice. |
| 709 | */ |
| 710 | mcast = NULL; |
| 711 | } |
| 712 | |
| 713 | out: |
| 714 | if (mcast && mcast->ah) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 715 | struct ipoib_neigh *neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 717 | spin_unlock_irqrestore(&priv->lock, flags); |
| 718 | neigh = ipoib_neigh_get(dev, daddr); |
| 719 | spin_lock_irqsave(&priv->lock, flags); |
| 720 | if (!neigh) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 721 | neigh = ipoib_neigh_alloc(daddr, dev); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 722 | if (neigh) { |
| 723 | kref_get(&mcast->ah->ref); |
| 724 | neigh->ah = mcast->ah; |
| 725 | list_add_tail(&neigh->list, &mcast->neigh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 728 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 730 | if (neigh) |
| 731 | ipoib_neigh_put(neigh); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 732 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Michael S. Tsirkin | 479a079 | 2006-02-07 16:37:08 -0800 | [diff] [blame] | 735 | unlock: |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 736 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | void ipoib_mcast_dev_flush(struct net_device *dev) |
| 740 | { |
| 741 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 742 | LIST_HEAD(remove_list); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 743 | struct ipoib_mcast *mcast, *tmcast; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | unsigned long flags; |
| 745 | |
| 746 | ipoib_dbg_mcast(priv, "flushing multicast list\n"); |
| 747 | |
| 748 | spin_lock_irqsave(&priv->lock, flags); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 751 | list_del(&mcast->list); |
| 752 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 753 | list_add_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | if (priv->broadcast) { |
Roland Dreier | 3cd9656 | 2006-09-22 15:22:46 -0700 | [diff] [blame] | 757 | rb_erase(&priv->broadcast->rb_node, &priv->multicast_tree); |
Eli Cohen | 988bd50 | 2006-01-12 14:32:20 -0800 | [diff] [blame] | 758 | list_add_tail(&priv->broadcast->list, &remove_list); |
| 759 | priv->broadcast = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | spin_unlock_irqrestore(&priv->lock, flags); |
| 763 | |
Roland Dreier | 962121b | 2015-01-30 15:39:11 -0800 | [diff] [blame] | 764 | /* seperate between the wait to the leave*/ |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 765 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) |
Roland Dreier | e7a623d | 2015-01-30 15:39:20 -0800 | [diff] [blame] | 766 | if (test_bit(IPOIB_MCAST_JOIN_STARTED, &mcast->flags)) |
Erez Shitrit | a9c8ba5 | 2013-10-16 17:37:51 +0300 | [diff] [blame] | 767 | wait_for_completion(&mcast->done); |
| 768 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 770 | ipoib_mcast_leave(dev, mcast); |
| 771 | ipoib_mcast_free(mcast); |
| 772 | } |
| 773 | } |
| 774 | |
Jiri Pirko | 3e4aa12f8 | 2010-03-22 03:21:39 +0000 | [diff] [blame] | 775 | 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] | 776 | { |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 777 | /* reserved QPN, prefix, scope */ |
| 778 | if (memcmp(addr, broadcast, 6)) |
| 779 | return 0; |
| 780 | /* signature lower, pkey */ |
| 781 | if (memcmp(addr + 7, broadcast + 7, 3)) |
| 782 | return 0; |
| 783 | return 1; |
| 784 | } |
| 785 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 786 | void ipoib_mcast_restart_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 788 | struct ipoib_dev_priv *priv = |
| 789 | container_of(work, struct ipoib_dev_priv, restart_task); |
| 790 | struct net_device *dev = priv->dev; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 791 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | struct ipoib_mcast *mcast, *tmcast; |
| 793 | LIST_HEAD(remove_list); |
| 794 | unsigned long flags; |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 795 | struct ib_sa_mcmember_rec rec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
| 797 | ipoib_dbg_mcast(priv, "restarting multicast task\n"); |
| 798 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame^] | 799 | /* |
| 800 | * We're running on the priv->wq right now, so we can't call |
| 801 | * mcast_stop_thread as it wants to flush the wq and that |
| 802 | * will deadlock. We don't actually *need* to stop the |
| 803 | * thread here anyway, so just clear the run flag, cancel |
| 804 | * any delayed work, do our work, remove the old entries, |
| 805 | * then restart the thread. |
| 806 | */ |
| 807 | mutex_lock(&mcast_mutex); |
| 808 | clear_bit(IPOIB_MCAST_RUN, &priv->flags); |
| 809 | cancel_delayed_work(&priv->mcast_task); |
| 810 | mutex_unlock(&mcast_mutex); |
Roland Dreier | 4e0ab20 | 2015-01-30 15:38:46 -0800 | [diff] [blame] | 811 | |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 812 | local_irq_save(flags); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 813 | netif_addr_lock(dev); |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 814 | spin_lock(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | /* |
| 817 | * Unfortunately, the networking core only gives us a list of all of |
| 818 | * the multicast hardware addresses. We need to figure out which ones |
| 819 | * are new and which ones have been removed |
| 820 | */ |
| 821 | |
| 822 | /* Clear out the found flag */ |
| 823 | list_for_each_entry(mcast, &priv->multicast_list, list) |
| 824 | clear_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 825 | |
| 826 | /* Mark all of the entries that are found or don't exist */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 827 | netdev_for_each_mc_addr(ha, dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | union ib_gid mgid; |
| 829 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 830 | if (!ipoib_mcast_addr_is_valid(ha->addr, dev->broadcast)) |
Jason Gunthorpe | 5e47596 | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 831 | continue; |
| 832 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 833 | memcpy(mgid.raw, ha->addr + 4, sizeof mgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | mcast = __ipoib_mcast_find(dev, &mgid); |
| 836 | if (!mcast || test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
| 837 | struct ipoib_mcast *nmcast; |
| 838 | |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 839 | /* ignore group which is directly joined by userspace */ |
| 840 | if (test_bit(IPOIB_FLAG_UMCAST, &priv->flags) && |
| 841 | !ib_sa_get_mcmember_rec(priv->ca, priv->port, &mgid, &rec)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 842 | ipoib_dbg_mcast(priv, "ignoring multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 843 | mgid.raw); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 844 | continue; |
| 845 | } |
| 846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | /* Not found or send-only group, let's add a new entry */ |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 848 | ipoib_dbg_mcast(priv, "adding multicast entry for mgid %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 849 | mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
| 851 | nmcast = ipoib_mcast_alloc(dev, 0); |
| 852 | if (!nmcast) { |
| 853 | ipoib_warn(priv, "unable to allocate memory for multicast structure\n"); |
| 854 | continue; |
| 855 | } |
| 856 | |
| 857 | set_bit(IPOIB_MCAST_FLAG_FOUND, &nmcast->flags); |
| 858 | |
| 859 | nmcast->mcmember.mgid = mgid; |
| 860 | |
| 861 | if (mcast) { |
| 862 | /* Destroy the send only entry */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 863 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
| 865 | rb_replace_node(&mcast->rb_node, |
| 866 | &nmcast->rb_node, |
| 867 | &priv->multicast_tree); |
| 868 | } else |
| 869 | __ipoib_mcast_add(dev, nmcast); |
| 870 | |
| 871 | list_add_tail(&nmcast->list, &priv->multicast_list); |
| 872 | } |
| 873 | |
| 874 | if (mcast) |
| 875 | set_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags); |
| 876 | } |
| 877 | |
| 878 | /* Remove all of the entries don't exist anymore */ |
| 879 | list_for_each_entry_safe(mcast, tmcast, &priv->multicast_list, list) { |
| 880 | if (!test_bit(IPOIB_MCAST_FLAG_FOUND, &mcast->flags) && |
| 881 | !test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 882 | ipoib_dbg_mcast(priv, "deleting multicast group %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 883 | mcast->mcmember.mgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
| 885 | rb_erase(&mcast->rb_node, &priv->multicast_tree); |
| 886 | |
| 887 | /* Move to the remove list */ |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 888 | list_move_tail(&mcast->list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
Michael S. Tsirkin | 78bfe0b | 2006-01-11 11:47:34 -0800 | [diff] [blame] | 891 | |
| 892 | spin_unlock(&priv->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 893 | netif_addr_unlock(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 894 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Roland Dreier | 962121b | 2015-01-30 15:39:11 -0800 | [diff] [blame] | 896 | /* We have to cancel outside of the spinlock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { |
| 898 | ipoib_mcast_leave(mcast->dev, mcast); |
| 899 | ipoib_mcast_free(mcast); |
| 900 | } |
Roland Dreier | 962121b | 2015-01-30 15:39:11 -0800 | [diff] [blame] | 901 | |
Doug Ledford | 894021a | 2015-02-21 19:27:02 -0500 | [diff] [blame] | 902 | if (test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) |
Roland Dreier | 962121b | 2015-01-30 15:39:11 -0800 | [diff] [blame] | 903 | ipoib_mcast_start_thread(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 906 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | struct ipoib_mcast_iter *ipoib_mcast_iter_init(struct net_device *dev) |
| 909 | { |
| 910 | struct ipoib_mcast_iter *iter; |
| 911 | |
| 912 | iter = kmalloc(sizeof *iter, GFP_KERNEL); |
| 913 | if (!iter) |
| 914 | return NULL; |
| 915 | |
| 916 | iter->dev = dev; |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 917 | memset(iter->mgid.raw, 0, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | if (ipoib_mcast_iter_next(iter)) { |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 920 | kfree(iter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | return iter; |
| 925 | } |
| 926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | int ipoib_mcast_iter_next(struct ipoib_mcast_iter *iter) |
| 928 | { |
| 929 | struct ipoib_dev_priv *priv = netdev_priv(iter->dev); |
| 930 | struct rb_node *n; |
| 931 | struct ipoib_mcast *mcast; |
| 932 | int ret = 1; |
| 933 | |
| 934 | spin_lock_irq(&priv->lock); |
| 935 | |
| 936 | n = rb_first(&priv->multicast_tree); |
| 937 | |
| 938 | while (n) { |
| 939 | mcast = rb_entry(n, struct ipoib_mcast, rb_node); |
| 940 | |
| 941 | if (memcmp(iter->mgid.raw, mcast->mcmember.mgid.raw, |
| 942 | sizeof (union ib_gid)) < 0) { |
| 943 | iter->mgid = mcast->mcmember.mgid; |
| 944 | iter->created = mcast->created; |
| 945 | iter->queuelen = skb_queue_len(&mcast->pkt_queue); |
| 946 | iter->complete = !!mcast->ah; |
| 947 | iter->send_only = !!(mcast->flags & (1 << IPOIB_MCAST_FLAG_SENDONLY)); |
| 948 | |
| 949 | ret = 0; |
| 950 | |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | n = rb_next(n); |
| 955 | } |
| 956 | |
| 957 | spin_unlock_irq(&priv->lock); |
| 958 | |
| 959 | return ret; |
| 960 | } |
| 961 | |
| 962 | void ipoib_mcast_iter_read(struct ipoib_mcast_iter *iter, |
| 963 | union ib_gid *mgid, |
| 964 | unsigned long *created, |
| 965 | unsigned int *queuelen, |
| 966 | unsigned int *complete, |
| 967 | unsigned int *send_only) |
| 968 | { |
| 969 | *mgid = iter->mgid; |
| 970 | *created = iter->created; |
| 971 | *queuelen = iter->queuelen; |
| 972 | *complete = iter->complete; |
| 973 | *send_only = iter->send_only; |
| 974 | } |
Roland Dreier | 8ae5a8a | 2005-11-02 20:51:01 -0800 | [diff] [blame] | 975 | |
| 976 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |