Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 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 "ipoib.h" |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/module.h> |
| 38 | |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/slab.h> |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 41 | #include <linux/kernel.h> |
Roland Dreier | 10313cb | 2008-03-12 07:51:03 -0700 | [diff] [blame] | 42 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <linux/if_arp.h> /* For ARPHRD_xxx */ |
| 45 | |
| 46 | #include <linux/ip.h> |
| 47 | #include <linux/in.h> |
| 48 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 49 | #include <linux/jhash.h> |
| 50 | #include <net/arp.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 51 | |
Yan Burman | 4b48680 | 2013-02-19 15:40:23 +0000 | [diff] [blame] | 52 | #define DRV_VERSION "1.0.0" |
| 53 | |
| 54 | const char ipoib_driver_version[] = DRV_VERSION; |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | MODULE_AUTHOR("Roland Dreier"); |
| 57 | MODULE_DESCRIPTION("IP-over-InfiniBand net driver"); |
| 58 | MODULE_LICENSE("Dual BSD/GPL"); |
Yan Burman | 4b48680 | 2013-02-19 15:40:23 +0000 | [diff] [blame] | 59 | MODULE_VERSION(DRV_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 61 | int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE; |
| 62 | int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE; |
| 63 | |
| 64 | module_param_named(send_queue_size, ipoib_sendq_size, int, 0444); |
| 65 | MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue"); |
| 66 | module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444); |
| 67 | MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue"); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 70 | int ipoib_debug_level; |
| 71 | |
| 72 | module_param_named(debug_level, ipoib_debug_level, int, 0644); |
| 73 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); |
| 74 | #endif |
| 75 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 76 | struct ipoib_path_iter { |
| 77 | struct net_device *dev; |
| 78 | struct ipoib_path path; |
| 79 | }; |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static const u8 ipv4_bcast_addr[] = { |
| 82 | 0x00, 0xff, 0xff, 0xff, |
| 83 | 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00, |
| 84 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff |
| 85 | }; |
| 86 | |
| 87 | struct workqueue_struct *ipoib_workqueue; |
| 88 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 89 | struct ib_sa_client ipoib_sa_client; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | static void ipoib_add_one(struct ib_device *device); |
| 92 | static void ipoib_remove_one(struct ib_device *device); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 93 | static void ipoib_neigh_reclaim(struct rcu_head *rp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | static struct ib_client ipoib_client = { |
| 96 | .name = "ipoib", |
| 97 | .add = ipoib_add_one, |
| 98 | .remove = ipoib_remove_one |
| 99 | }; |
| 100 | |
| 101 | int ipoib_open(struct net_device *dev) |
| 102 | { |
| 103 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 104 | |
| 105 | ipoib_dbg(priv, "bringing up interface\n"); |
| 106 | |
Michal Schmidt | 437708c | 2014-01-17 19:47:25 +0100 | [diff] [blame] | 107 | netif_carrier_off(dev); |
| 108 | |
Yossi Etigin | e028cc5 | 2009-04-20 13:58:08 -0700 | [diff] [blame] | 109 | set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 111 | if (ipoib_ib_dev_open(dev)) { |
Alex Estrin | dd57c93 | 2014-08-06 14:40:32 -0400 | [diff] [blame] | 112 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) |
| 113 | return 0; |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 114 | goto err_disable; |
Alex Estrin | dd57c93 | 2014-08-06 14:40:32 -0400 | [diff] [blame] | 115 | } |
Yossi Etigin | fe25c56 | 2008-11-12 10:24:36 -0800 | [diff] [blame] | 116 | |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 117 | if (ipoib_ib_dev_up(dev)) |
| 118 | goto err_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { |
| 121 | struct ipoib_dev_priv *cpriv; |
| 122 | |
| 123 | /* Bring up any child interfaces too */ |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 124 | down_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | list_for_each_entry(cpriv, &priv->child_intfs, list) { |
| 126 | int flags; |
| 127 | |
| 128 | flags = cpriv->dev->flags; |
| 129 | if (flags & IFF_UP) |
| 130 | continue; |
| 131 | |
| 132 | dev_change_flags(cpriv->dev, flags | IFF_UP); |
| 133 | } |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 134 | up_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | netif_start_queue(dev); |
| 138 | |
| 139 | return 0; |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 140 | |
| 141 | err_stop: |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 142 | ipoib_ib_dev_stop(dev); |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 143 | |
| 144 | err_disable: |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 145 | clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
| 146 | |
| 147 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static int ipoib_stop(struct net_device *dev) |
| 151 | { |
| 152 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 153 | |
| 154 | ipoib_dbg(priv, "stopping interface\n"); |
| 155 | |
| 156 | clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
| 157 | |
| 158 | netif_stop_queue(dev); |
| 159 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 160 | ipoib_ib_dev_down(dev); |
| 161 | ipoib_ib_dev_stop(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { |
| 164 | struct ipoib_dev_priv *cpriv; |
| 165 | |
| 166 | /* Bring down any child interfaces too */ |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 167 | down_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | list_for_each_entry(cpriv, &priv->child_intfs, list) { |
| 169 | int flags; |
| 170 | |
| 171 | flags = cpriv->dev->flags; |
| 172 | if (!(flags & IFF_UP)) |
| 173 | continue; |
| 174 | |
| 175 | dev_change_flags(cpriv->dev, flags & ~IFF_UP); |
| 176 | } |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 177 | up_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 183 | static void ipoib_uninit(struct net_device *dev) |
| 184 | { |
| 185 | ipoib_dev_cleanup(dev); |
| 186 | } |
| 187 | |
David S. Miller | 9ca36f7 | 2011-11-16 18:05:50 -0500 | [diff] [blame] | 188 | static netdev_features_t ipoib_fix_features(struct net_device *dev, netdev_features_t features) |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 189 | { |
| 190 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 191 | |
| 192 | if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags)) |
| 193 | features &= ~(NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 194 | |
| 195 | return features; |
| 196 | } |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | static int ipoib_change_mtu(struct net_device *dev, int new_mtu) |
| 199 | { |
| 200 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 201 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 202 | /* dev->mtu > 2K ==> connected mode */ |
Pradeep Satyanarayana | 586a693 | 2007-12-21 13:08:23 -0800 | [diff] [blame] | 203 | if (ipoib_cm_admin_enabled(dev)) { |
| 204 | if (new_mtu > ipoib_cm_max_mtu(dev)) |
| 205 | return -EINVAL; |
| 206 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 207 | if (new_mtu > priv->mcast_mtu) |
| 208 | ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n", |
| 209 | priv->mcast_mtu); |
Pradeep Satyanarayana | 586a693 | 2007-12-21 13:08:23 -0800 | [diff] [blame] | 210 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 211 | dev->mtu = new_mtu; |
| 212 | return 0; |
| 213 | } |
| 214 | |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 215 | if (new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return -EINVAL; |
| 217 | |
| 218 | priv->admin_mtu = new_mtu; |
| 219 | |
| 220 | dev->mtu = min(priv->mcast_mtu, priv->admin_mtu); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 225 | int ipoib_set_mode(struct net_device *dev, const char *buf) |
| 226 | { |
| 227 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 228 | |
| 229 | /* flush paths if we switch modes so that connections are restarted */ |
| 230 | if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) { |
| 231 | set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 232 | ipoib_warn(priv, "enabling connected mode " |
| 233 | "will cause multicast packet drops\n"); |
| 234 | netdev_update_features(dev); |
| 235 | rtnl_unlock(); |
| 236 | priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM; |
| 237 | |
| 238 | ipoib_flush_paths(dev); |
| 239 | rtnl_lock(); |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | if (!strcmp(buf, "datagram\n")) { |
| 244 | clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 245 | netdev_update_features(dev); |
| 246 | dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu)); |
| 247 | rtnl_unlock(); |
| 248 | ipoib_flush_paths(dev); |
| 249 | rtnl_lock(); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 256 | static struct ipoib_path *__path_find(struct net_device *dev, void *gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
| 258 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 259 | struct rb_node *n = priv->path_tree.rb_node; |
| 260 | struct ipoib_path *path; |
| 261 | int ret; |
| 262 | |
| 263 | while (n) { |
| 264 | path = rb_entry(n, struct ipoib_path, rb_node); |
| 265 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 266 | ret = memcmp(gid, path->pathrec.dgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | sizeof (union ib_gid)); |
| 268 | |
| 269 | if (ret < 0) |
| 270 | n = n->rb_left; |
| 271 | else if (ret > 0) |
| 272 | n = n->rb_right; |
| 273 | else |
| 274 | return path; |
| 275 | } |
| 276 | |
| 277 | return NULL; |
| 278 | } |
| 279 | |
| 280 | static int __path_add(struct net_device *dev, struct ipoib_path *path) |
| 281 | { |
| 282 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 283 | struct rb_node **n = &priv->path_tree.rb_node; |
| 284 | struct rb_node *pn = NULL; |
| 285 | struct ipoib_path *tpath; |
| 286 | int ret; |
| 287 | |
| 288 | while (*n) { |
| 289 | pn = *n; |
| 290 | tpath = rb_entry(pn, struct ipoib_path, rb_node); |
| 291 | |
| 292 | ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw, |
| 293 | sizeof (union ib_gid)); |
| 294 | if (ret < 0) |
| 295 | n = &pn->rb_left; |
| 296 | else if (ret > 0) |
| 297 | n = &pn->rb_right; |
| 298 | else |
| 299 | return -EEXIST; |
| 300 | } |
| 301 | |
| 302 | rb_link_node(&path->rb_node, pn, n); |
| 303 | rb_insert_color(&path->rb_node, &priv->path_tree); |
| 304 | |
| 305 | list_add_tail(&path->list, &priv->path_list); |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static void path_free(struct net_device *dev, struct ipoib_path *path) |
| 311 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | while ((skb = __skb_dequeue(&path->queue))) |
| 315 | dev_kfree_skb_irq(skb); |
| 316 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 317 | ipoib_dbg(netdev_priv(dev), "path_free\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 319 | /* remove all neigh connected to this path */ |
| 320 | ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | if (path->ah) |
| 323 | ipoib_put_ah(path->ah); |
| 324 | |
| 325 | kfree(path); |
| 326 | } |
| 327 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 328 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 329 | |
| 330 | struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev) |
| 331 | { |
| 332 | struct ipoib_path_iter *iter; |
| 333 | |
| 334 | iter = kmalloc(sizeof *iter, GFP_KERNEL); |
| 335 | if (!iter) |
| 336 | return NULL; |
| 337 | |
| 338 | iter->dev = dev; |
| 339 | memset(iter->path.pathrec.dgid.raw, 0, 16); |
| 340 | |
| 341 | if (ipoib_path_iter_next(iter)) { |
| 342 | kfree(iter); |
| 343 | return NULL; |
| 344 | } |
| 345 | |
| 346 | return iter; |
| 347 | } |
| 348 | |
| 349 | int ipoib_path_iter_next(struct ipoib_path_iter *iter) |
| 350 | { |
| 351 | struct ipoib_dev_priv *priv = netdev_priv(iter->dev); |
| 352 | struct rb_node *n; |
| 353 | struct ipoib_path *path; |
| 354 | int ret = 1; |
| 355 | |
| 356 | spin_lock_irq(&priv->lock); |
| 357 | |
| 358 | n = rb_first(&priv->path_tree); |
| 359 | |
| 360 | while (n) { |
| 361 | path = rb_entry(n, struct ipoib_path, rb_node); |
| 362 | |
| 363 | if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw, |
| 364 | sizeof (union ib_gid)) < 0) { |
| 365 | iter->path = *path; |
| 366 | ret = 0; |
| 367 | break; |
| 368 | } |
| 369 | |
| 370 | n = rb_next(n); |
| 371 | } |
| 372 | |
| 373 | spin_unlock_irq(&priv->lock); |
| 374 | |
| 375 | return ret; |
| 376 | } |
| 377 | |
| 378 | void ipoib_path_iter_read(struct ipoib_path_iter *iter, |
| 379 | struct ipoib_path *path) |
| 380 | { |
| 381 | *path = iter->path; |
| 382 | } |
| 383 | |
| 384 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |
| 385 | |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 386 | void ipoib_mark_paths_invalid(struct net_device *dev) |
| 387 | { |
| 388 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 389 | struct ipoib_path *path, *tp; |
| 390 | |
| 391 | spin_lock_irq(&priv->lock); |
| 392 | |
| 393 | list_for_each_entry_safe(path, tp, &priv->path_list, list) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 394 | ipoib_dbg(priv, "mark path LID 0x%04x GID %pI6 invalid\n", |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 395 | be16_to_cpu(path->pathrec.dlid), |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 396 | path->pathrec.dgid.raw); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 397 | path->valid = 0; |
| 398 | } |
| 399 | |
| 400 | spin_unlock_irq(&priv->lock); |
| 401 | } |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | void ipoib_flush_paths(struct net_device *dev) |
| 404 | { |
| 405 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 406 | struct ipoib_path *path, *tp; |
| 407 | LIST_HEAD(remove_list); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 408 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 410 | netif_tx_lock_bh(dev); |
| 411 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Robert P. J. Day | 157de22 | 2008-04-16 21:09:26 -0700 | [diff] [blame] | 413 | list_splice_init(&priv->path_list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | list_for_each_entry(path, &remove_list, list) |
| 416 | rb_erase(&path->rb_node, &priv->path_tree); |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | list_for_each_entry_safe(path, tp, &remove_list, list) { |
| 419 | if (path->query) |
| 420 | ib_sa_cancel_query(path->query_id, path->query); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 421 | spin_unlock_irqrestore(&priv->lock, flags); |
| 422 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | wait_for_completion(&path->done); |
| 424 | path_free(dev, path); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 425 | netif_tx_lock_bh(dev); |
| 426 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 428 | |
| 429 | spin_unlock_irqrestore(&priv->lock, flags); |
| 430 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static void path_rec_completion(int status, |
| 434 | struct ib_sa_path_rec *pathrec, |
| 435 | void *path_ptr) |
| 436 | { |
| 437 | struct ipoib_path *path = path_ptr; |
| 438 | struct net_device *dev = path->dev; |
| 439 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 440 | struct ipoib_ah *ah = NULL; |
Roland Dreier | c9da4ba | 2008-09-25 15:26:15 -0700 | [diff] [blame] | 441 | struct ipoib_ah *old_ah = NULL; |
Michael S. Tsirkin | d04d01b | 2007-03-22 14:40:16 -0700 | [diff] [blame] | 442 | struct ipoib_neigh *neigh, *tn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | struct sk_buff_head skqueue; |
| 444 | struct sk_buff *skb; |
| 445 | unsigned long flags; |
| 446 | |
Roland Dreier | 843613b | 2007-02-26 12:57:08 -0800 | [diff] [blame] | 447 | if (!status) |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 448 | ipoib_dbg(priv, "PathRec LID 0x%04x for GID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 449 | be16_to_cpu(pathrec->dlid), pathrec->dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | else |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 451 | ipoib_dbg(priv, "PathRec status %d for GID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 452 | status, path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
| 454 | skb_queue_head_init(&skqueue); |
| 455 | |
| 456 | if (!status) { |
Sean Hefty | 46f1b3d | 2007-04-05 11:50:11 -0700 | [diff] [blame] | 457 | struct ib_ah_attr av; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Sean Hefty | 46f1b3d | 2007-04-05 11:50:11 -0700 | [diff] [blame] | 459 | if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av)) |
| 460 | ah = ipoib_create_ah(dev, priv->pd, &av); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | spin_lock_irqsave(&priv->lock, flags); |
| 464 | |
Mike Marciniszyn | 3874397 | 2011-11-21 08:43:54 -0500 | [diff] [blame] | 465 | if (!IS_ERR_OR_NULL(ah)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | path->pathrec = *pathrec; |
| 467 | |
Roland Dreier | c9da4ba | 2008-09-25 15:26:15 -0700 | [diff] [blame] | 468 | old_ah = path->ah; |
| 469 | path->ah = ah; |
| 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n", |
| 472 | ah, be16_to_cpu(pathrec->dlid), pathrec->sl); |
| 473 | |
| 474 | while ((skb = __skb_dequeue(&path->queue))) |
| 475 | __skb_queue_tail(&skqueue, skb); |
| 476 | |
Michael S. Tsirkin | d04d01b | 2007-03-22 14:40:16 -0700 | [diff] [blame] | 477 | list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) { |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 478 | if (neigh->ah) { |
| 479 | WARN_ON(neigh->ah != old_ah); |
| 480 | /* |
| 481 | * Dropping the ah reference inside |
| 482 | * priv->lock is safe here, because we |
| 483 | * will hold one more reference from |
| 484 | * the original value of path->ah (ie |
| 485 | * old_ah). |
| 486 | */ |
| 487 | ipoib_put_ah(neigh->ah); |
| 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | kref_get(&path->ah->ref); |
| 490 | neigh->ah = path->ah; |
| 491 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 492 | if (ipoib_cm_enabled(dev, neigh->daddr)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 493 | if (!ipoib_cm_get(neigh)) |
| 494 | ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, |
| 495 | path, |
| 496 | neigh)); |
| 497 | if (!ipoib_cm_get(neigh)) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 498 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 499 | continue; |
| 500 | } |
| 501 | } |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | while ((skb = __skb_dequeue(&neigh->queue))) |
| 504 | __skb_queue_tail(&skqueue, skb); |
| 505 | } |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 506 | path->valid = 1; |
Roland Dreier | 5872a9f | 2005-11-29 10:13:54 -0800 | [diff] [blame] | 507 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Roland Dreier | 5872a9f | 2005-11-29 10:13:54 -0800 | [diff] [blame] | 509 | path->query = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | complete(&path->done); |
| 511 | |
| 512 | spin_unlock_irqrestore(&priv->lock, flags); |
| 513 | |
Roland Dreier | f72dd56 | 2013-02-25 09:42:15 -0800 | [diff] [blame] | 514 | if (IS_ERR_OR_NULL(ah)) |
| 515 | ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw); |
| 516 | |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 517 | if (old_ah) |
| 518 | ipoib_put_ah(old_ah); |
| 519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | while ((skb = __skb_dequeue(&skqueue))) { |
| 521 | skb->dev = dev; |
| 522 | if (dev_queue_xmit(skb)) |
| 523 | ipoib_warn(priv, "dev_queue_xmit failed " |
| 524 | "to requeue packet\n"); |
| 525 | } |
| 526 | } |
| 527 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 528 | static struct ipoib_path *path_rec_create(struct net_device *dev, void *gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | { |
| 530 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 531 | struct ipoib_path *path; |
| 532 | |
Jack Morgenstein | 1401b53 | 2007-11-26 10:41:19 +0200 | [diff] [blame] | 533 | if (!priv->broadcast) |
| 534 | return NULL; |
| 535 | |
Roland Dreier | 21a3848 | 2005-11-02 10:07:59 -0800 | [diff] [blame] | 536 | path = kzalloc(sizeof *path, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | if (!path) |
| 538 | return NULL; |
| 539 | |
Roland Dreier | 21a3848 | 2005-11-02 10:07:59 -0800 | [diff] [blame] | 540 | path->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | skb_queue_head_init(&path->queue); |
| 543 | |
| 544 | INIT_LIST_HEAD(&path->neigh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 546 | memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid)); |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 547 | path->pathrec.sgid = priv->local_gid; |
| 548 | path->pathrec.pkey = cpu_to_be16(priv->pkey); |
Sean Hefty | 8166883 | 2007-08-02 12:21:31 -0700 | [diff] [blame] | 549 | path->pathrec.numb_path = 1; |
| 550 | path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | return path; |
| 553 | } |
| 554 | |
| 555 | static int path_rec_start(struct net_device *dev, |
| 556 | struct ipoib_path *path) |
| 557 | { |
| 558 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 559 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 560 | ipoib_dbg(priv, "Start path record lookup for %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 561 | path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Roland Dreier | 65c7edd | 2005-11-28 21:20:34 -0800 | [diff] [blame] | 563 | init_completion(&path->done); |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | path->query_id = |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 566 | ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | &path->pathrec, |
| 568 | IB_SA_PATH_REC_DGID | |
| 569 | IB_SA_PATH_REC_SGID | |
| 570 | IB_SA_PATH_REC_NUMB_PATH | |
Sean Hefty | 8166883 | 2007-08-02 12:21:31 -0700 | [diff] [blame] | 571 | IB_SA_PATH_REC_TRAFFIC_CLASS | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | IB_SA_PATH_REC_PKEY, |
| 573 | 1000, GFP_ATOMIC, |
| 574 | path_rec_completion, |
| 575 | path, &path->query); |
| 576 | if (path->query_id < 0) { |
Or Gerlitz | 01b3fc8 | 2008-07-22 14:18:34 -0700 | [diff] [blame] | 577 | ipoib_warn(priv, "ib_sa_path_rec_get failed: %d\n", path->query_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | path->query = NULL; |
Yossi Etigin | 93a3ab9 | 2008-11-12 10:24:38 -0800 | [diff] [blame] | 579 | complete(&path->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return path->query_id; |
| 581 | } |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 586 | static void neigh_add_path(struct sk_buff *skb, u8 *daddr, |
| 587 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
| 589 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 590 | struct ipoib_path *path; |
| 591 | struct ipoib_neigh *neigh; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 592 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 594 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 595 | neigh = ipoib_neigh_alloc(daddr, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | if (!neigh) { |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 597 | spin_unlock_irqrestore(&priv->lock, flags); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 598 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | dev_kfree_skb_any(skb); |
| 600 | return; |
| 601 | } |
| 602 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 603 | path = __path_find(dev, daddr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | if (!path) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 605 | path = path_rec_create(dev, daddr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | if (!path) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 607 | goto err_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
| 609 | __path_add(dev, path); |
| 610 | } |
| 611 | |
| 612 | list_add_tail(&neigh->list, &path->neigh_list); |
| 613 | |
Michael S. Tsirkin | 47f7a07 | 2006-01-17 09:22:05 -0800 | [diff] [blame] | 614 | if (path->ah) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | kref_get(&path->ah->ref); |
| 616 | neigh->ah = path->ah; |
| 617 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 618 | if (ipoib_cm_enabled(dev, neigh->daddr)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 619 | if (!ipoib_cm_get(neigh)) |
| 620 | ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh)); |
| 621 | if (!ipoib_cm_get(neigh)) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 622 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 623 | goto err_drop; |
| 624 | } |
| 625 | if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) |
| 626 | __skb_queue_tail(&neigh->queue, skb); |
| 627 | else { |
| 628 | ipoib_warn(priv, "queue length limit %d. Packet drop.\n", |
| 629 | skb_queue_len(&neigh->queue)); |
| 630 | goto err_drop; |
| 631 | } |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 632 | } else { |
| 633 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 634 | ipoib_send(dev, skb, path->ah, IPOIB_QPN(daddr)); |
| 635 | ipoib_neigh_put(neigh); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 636 | return; |
| 637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } else { |
| 639 | neigh->ah = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | if (!path->query && path_rec_start(dev, path)) |
Jim Foraker | 49b8e74 | 2013-08-08 17:44:22 -0700 | [diff] [blame] | 642 | goto err_path; |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 643 | if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) |
| 644 | __skb_queue_tail(&neigh->queue, skb); |
| 645 | else |
| 646 | goto err_drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 649 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 650 | ipoib_neigh_put(neigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return; |
| 652 | |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 653 | err_path: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 654 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 655 | err_drop: |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 656 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | dev_kfree_skb_any(skb); |
| 658 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 659 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 660 | ipoib_neigh_put(neigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev, |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 664 | struct ipoib_cb *cb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
| 666 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 667 | struct ipoib_path *path; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 668 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 670 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 672 | path = __path_find(dev, cb->hwaddr + 4); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 673 | if (!path || !path->valid) { |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 674 | int new_path = 0; |
| 675 | |
| 676 | if (!path) { |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 677 | path = path_rec_create(dev, cb->hwaddr + 4); |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 678 | new_path = 1; |
| 679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | if (path) { |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 681 | if (skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
| 682 | __skb_queue_tail(&path->queue, skb); |
| 683 | } else { |
| 684 | ++dev->stats.tx_dropped; |
| 685 | dev_kfree_skb_any(skb); |
| 686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Yossi Etigin | ff79ae8 | 2008-11-12 10:24:39 -0800 | [diff] [blame] | 688 | if (!path->query && path_rec_start(dev, path)) { |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 689 | spin_unlock_irqrestore(&priv->lock, flags); |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 690 | if (new_path) |
| 691 | path_free(dev, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return; |
| 693 | } else |
| 694 | __path_add(dev, path); |
| 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); |
| 698 | } |
| 699 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 700 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | |
Michael S. Tsirkin | 47f7a07 | 2006-01-17 09:22:05 -0800 | [diff] [blame] | 704 | if (path->ah) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | ipoib_dbg(priv, "Send unicast ARP to %04x\n", |
| 706 | be16_to_cpu(path->pathrec.dlid)); |
| 707 | |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 708 | spin_unlock_irqrestore(&priv->lock, flags); |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 709 | ipoib_send(dev, skb, path->ah, IPOIB_QPN(cb->hwaddr)); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 710 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } else if ((path->query || !path_rec_start(dev, path)) && |
| 712 | skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | __skb_queue_tail(&path->queue, skb); |
| 714 | } else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 715 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | dev_kfree_skb_any(skb); |
| 717 | } |
| 718 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 719 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 723 | { |
| 724 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 725 | struct ipoib_neigh *neigh; |
Eric Dumazet | b49fe36 | 2014-09-18 11:00:27 -0700 | [diff] [blame] | 726 | struct ipoib_cb *cb = ipoib_skb_cb(skb); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 727 | struct ipoib_header *header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | unsigned long flags; |
| 729 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 730 | header = (struct ipoib_header *) skb->data; |
| 731 | |
| 732 | if (unlikely(cb->hwaddr[4] == 0xff)) { |
| 733 | /* multicast, arrange "if" according to probability */ |
| 734 | if ((header->proto != htons(ETH_P_IP)) && |
| 735 | (header->proto != htons(ETH_P_IPV6)) && |
| 736 | (header->proto != htons(ETH_P_ARP)) && |
Patrick McHardy | dc850b0 | 2013-04-17 06:18:29 +0000 | [diff] [blame] | 737 | (header->proto != htons(ETH_P_RARP)) && |
| 738 | (header->proto != htons(ETH_P_TIPC))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 739 | /* ethertype not supported by IPoIB */ |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 740 | ++dev->stats.tx_dropped; |
| 741 | dev_kfree_skb_any(skb); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 742 | return NETDEV_TX_OK; |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 743 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 744 | /* Add in the P_Key for multicast*/ |
| 745 | cb->hwaddr[8] = (priv->pkey >> 8) & 0xff; |
| 746 | cb->hwaddr[9] = priv->pkey & 0xff; |
| 747 | |
| 748 | neigh = ipoib_neigh_get(dev, cb->hwaddr); |
| 749 | if (likely(neigh)) |
| 750 | goto send_using_neigh; |
| 751 | ipoib_mcast_send(dev, cb->hwaddr, skb); |
| 752 | return NETDEV_TX_OK; |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 755 | /* unicast, arrange "switch" according to probability */ |
| 756 | switch (header->proto) { |
| 757 | case htons(ETH_P_IP): |
| 758 | case htons(ETH_P_IPV6): |
Patrick McHardy | dc850b0 | 2013-04-17 06:18:29 +0000 | [diff] [blame] | 759 | case htons(ETH_P_TIPC): |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 760 | neigh = ipoib_neigh_get(dev, cb->hwaddr); |
| 761 | if (unlikely(!neigh)) { |
| 762 | neigh_add_path(skb, cb->hwaddr, dev); |
| 763 | return NETDEV_TX_OK; |
Yossi Etigin | a50df39 | 2009-01-09 14:05:11 -0800 | [diff] [blame] | 764 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 765 | break; |
| 766 | case htons(ETH_P_ARP): |
| 767 | case htons(ETH_P_RARP): |
| 768 | /* for unicast ARP and RARP should always perform path find */ |
| 769 | unicast_arp_send(skb, dev, cb); |
| 770 | return NETDEV_TX_OK; |
| 771 | default: |
| 772 | /* ethertype not supported by IPoIB */ |
| 773 | ++dev->stats.tx_dropped; |
| 774 | dev_kfree_skb_any(skb); |
| 775 | return NETDEV_TX_OK; |
| 776 | } |
Michael S. Tsirkin | 8a7f752 | 2006-07-19 17:44:37 +0300 | [diff] [blame] | 777 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 778 | send_using_neigh: |
| 779 | /* note we now hold a ref to neigh */ |
| 780 | if (ipoib_cm_get(neigh)) { |
| 781 | if (ipoib_cm_up(neigh)) { |
| 782 | ipoib_cm_send(dev, skb, ipoib_cm_get(neigh)); |
| 783 | goto unref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 785 | } else if (neigh->ah) { |
| 786 | ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(cb->hwaddr)); |
| 787 | goto unref; |
| 788 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 790 | if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
| 791 | spin_lock_irqsave(&priv->lock, flags); |
| 792 | __skb_queue_tail(&neigh->queue, skb); |
| 793 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } else { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 795 | ++dev->stats.tx_dropped; |
| 796 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 798 | |
| 799 | unref: |
| 800 | ipoib_neigh_put(neigh); |
| 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return NETDEV_TX_OK; |
| 803 | } |
| 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | static void ipoib_timeout(struct net_device *dev) |
| 806 | { |
| 807 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 808 | |
Roland Dreier | 4b2d319 | 2005-10-18 12:20:06 -0700 | [diff] [blame] | 809 | ipoib_warn(priv, "transmit timeout: latency %d msecs\n", |
| 810 | jiffies_to_msecs(jiffies - dev->trans_start)); |
| 811 | ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n", |
| 812 | netif_queue_stopped(dev), |
| 813 | priv->tx_head, priv->tx_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | /* XXX reset QP, etc. */ |
| 815 | } |
| 816 | |
| 817 | static int ipoib_hard_header(struct sk_buff *skb, |
| 818 | struct net_device *dev, |
| 819 | unsigned short type, |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 820 | const void *daddr, const void *saddr, unsigned len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
| 822 | struct ipoib_header *header; |
Eric Dumazet | b49fe36 | 2014-09-18 11:00:27 -0700 | [diff] [blame] | 823 | struct ipoib_cb *cb = ipoib_skb_cb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | header = (struct ipoib_header *) skb_push(skb, sizeof *header); |
| 826 | |
| 827 | header->proto = htons(type); |
| 828 | header->reserved = 0; |
| 829 | |
| 830 | /* |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 831 | * we don't rely on dst_entry structure, always stuff the |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 832 | * destination address into skb->cb so we can figure out where |
| 833 | * to send the packet later. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | */ |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 835 | memcpy(cb->hwaddr, daddr, INFINIBAND_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
Doug Ledford | 83bdd3b | 2013-04-01 21:25:30 +0000 | [diff] [blame] | 837 | return sizeof *header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static void ipoib_set_mcast_list(struct net_device *dev) |
| 841 | { |
| 842 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 843 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 844 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
| 845 | ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set"); |
| 846 | return; |
| 847 | } |
| 848 | |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 849 | queue_work(priv->wq, &priv->restart_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 852 | static int ipoib_get_iflink(const struct net_device *dev) |
| 853 | { |
| 854 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 855 | |
Erez Shitrit | 2c15395 | 2015-04-16 16:34:34 +0300 | [diff] [blame] | 856 | /* parent interface */ |
| 857 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) |
| 858 | return dev->ifindex; |
| 859 | |
| 860 | /* child/vlan interface */ |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 861 | return priv->parent->ifindex; |
| 862 | } |
| 863 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 864 | static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 866 | /* |
| 867 | * Use only the address parts that contributes to spreading |
| 868 | * The subnet prefix is not used as one can not connect to |
| 869 | * same remote port (GUID) using the same remote QPN via two |
| 870 | * different subnets. |
| 871 | */ |
| 872 | /* qpn octets[1:4) & port GUID octets[12:20) */ |
Shlomo Pongratz | 9d1ad66 | 2013-02-19 15:40:22 +0000 | [diff] [blame] | 873 | u32 *d32 = (u32 *) daddr; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 874 | u32 hv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Shlomo Pongratz | 9d1ad66 | 2013-02-19 15:40:22 +0000 | [diff] [blame] | 876 | hv = jhash_3words(d32[3], d32[4], IPOIB_QPN_MASK & d32[0], 0); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 877 | return hv & htbl->mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 880 | struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr) |
| 881 | { |
| 882 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 883 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 884 | struct ipoib_neigh_hash *htbl; |
| 885 | struct ipoib_neigh *neigh = NULL; |
| 886 | u32 hash_val; |
| 887 | |
| 888 | rcu_read_lock_bh(); |
| 889 | |
| 890 | htbl = rcu_dereference_bh(ntbl->htbl); |
| 891 | |
| 892 | if (!htbl) |
| 893 | goto out_unlock; |
| 894 | |
| 895 | hash_val = ipoib_addr_hash(htbl, daddr); |
| 896 | for (neigh = rcu_dereference_bh(htbl->buckets[hash_val]); |
| 897 | neigh != NULL; |
| 898 | neigh = rcu_dereference_bh(neigh->hnext)) { |
| 899 | if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) { |
| 900 | /* found, take one ref on behalf of the caller */ |
| 901 | if (!atomic_inc_not_zero(&neigh->refcnt)) { |
| 902 | /* deleted */ |
| 903 | neigh = NULL; |
| 904 | goto out_unlock; |
| 905 | } |
| 906 | neigh->alive = jiffies; |
| 907 | goto out_unlock; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | out_unlock: |
| 912 | rcu_read_unlock_bh(); |
| 913 | return neigh; |
| 914 | } |
| 915 | |
| 916 | static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv) |
| 917 | { |
| 918 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 919 | struct ipoib_neigh_hash *htbl; |
| 920 | unsigned long neigh_obsolete; |
| 921 | unsigned long dt; |
| 922 | unsigned long flags; |
| 923 | int i; |
| 924 | |
| 925 | if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
| 926 | return; |
| 927 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 928 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 929 | |
| 930 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 931 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 932 | |
| 933 | if (!htbl) |
| 934 | goto out_unlock; |
| 935 | |
| 936 | /* neigh is obsolete if it was idle for two GC periods */ |
| 937 | dt = 2 * arp_tbl.gc_interval; |
| 938 | neigh_obsolete = jiffies - dt; |
| 939 | /* handle possible race condition */ |
| 940 | if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
| 941 | goto out_unlock; |
| 942 | |
| 943 | for (i = 0; i < htbl->size; i++) { |
| 944 | struct ipoib_neigh *neigh; |
| 945 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 946 | |
| 947 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 948 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 949 | /* was the neigh idle for two GC periods */ |
| 950 | if (time_after(neigh_obsolete, neigh->alive)) { |
| 951 | rcu_assign_pointer(*np, |
| 952 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 953 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 954 | /* remove from path/mc list */ |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 955 | list_del(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 956 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 957 | } else { |
| 958 | np = &neigh->hnext; |
| 959 | } |
| 960 | |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 965 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void ipoib_reap_neigh(struct work_struct *work) |
| 969 | { |
| 970 | struct ipoib_dev_priv *priv = |
| 971 | container_of(work, struct ipoib_dev_priv, neigh_reap_task.work); |
| 972 | |
| 973 | __ipoib_reap_neigh(priv); |
| 974 | |
| 975 | if (!test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 976 | queue_delayed_work(priv->wq, &priv->neigh_reap_task, |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 977 | arp_tbl.gc_interval); |
| 978 | } |
| 979 | |
| 980 | |
| 981 | static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr, |
Moni Shoua | 732a217 | 2007-10-09 19:43:36 -0700 | [diff] [blame] | 982 | struct net_device *dev) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 983 | { |
| 984 | struct ipoib_neigh *neigh; |
| 985 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 986 | neigh = kzalloc(sizeof *neigh, GFP_ATOMIC); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 987 | if (!neigh) |
| 988 | return NULL; |
| 989 | |
Moni Shoua | 732a217 | 2007-10-09 19:43:36 -0700 | [diff] [blame] | 990 | neigh->dev = dev; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 991 | memcpy(&neigh->daddr, daddr, sizeof(neigh->daddr)); |
Roland Dreier | 82b3991 | 2006-12-12 14:48:18 -0800 | [diff] [blame] | 992 | skb_queue_head_init(&neigh->queue); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 993 | INIT_LIST_HEAD(&neigh->list); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 994 | ipoib_cm_set(neigh, NULL); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 995 | /* one ref on behalf of the caller */ |
| 996 | atomic_set(&neigh->refcnt, 1); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 997 | |
| 998 | return neigh; |
| 999 | } |
| 1000 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1001 | struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr, |
| 1002 | struct net_device *dev) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1003 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1004 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1005 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1006 | struct ipoib_neigh_hash *htbl; |
| 1007 | struct ipoib_neigh *neigh; |
| 1008 | u32 hash_val; |
| 1009 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1010 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1011 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1012 | if (!htbl) { |
| 1013 | neigh = NULL; |
| 1014 | goto out_unlock; |
| 1015 | } |
| 1016 | |
| 1017 | /* need to add a new neigh, but maybe some other thread succeeded? |
| 1018 | * recalc hash, maybe hash resize took place so we do a search |
| 1019 | */ |
| 1020 | hash_val = ipoib_addr_hash(htbl, daddr); |
| 1021 | for (neigh = rcu_dereference_protected(htbl->buckets[hash_val], |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1022 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1023 | neigh != NULL; |
| 1024 | neigh = rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1025 | lockdep_is_held(&priv->lock))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1026 | if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) { |
| 1027 | /* found, take one ref on behalf of the caller */ |
| 1028 | if (!atomic_inc_not_zero(&neigh->refcnt)) { |
| 1029 | /* deleted */ |
| 1030 | neigh = NULL; |
| 1031 | break; |
| 1032 | } |
| 1033 | neigh->alive = jiffies; |
| 1034 | goto out_unlock; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | neigh = ipoib_neigh_ctor(daddr, dev); |
| 1039 | if (!neigh) |
| 1040 | goto out_unlock; |
| 1041 | |
| 1042 | /* one ref on behalf of the hash table */ |
| 1043 | atomic_inc(&neigh->refcnt); |
| 1044 | neigh->alive = jiffies; |
| 1045 | /* put in hash */ |
| 1046 | rcu_assign_pointer(neigh->hnext, |
| 1047 | rcu_dereference_protected(htbl->buckets[hash_val], |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1048 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1049 | rcu_assign_pointer(htbl->buckets[hash_val], neigh); |
| 1050 | atomic_inc(&ntbl->entries); |
| 1051 | |
| 1052 | out_unlock: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1053 | |
| 1054 | return neigh; |
| 1055 | } |
| 1056 | |
| 1057 | void ipoib_neigh_dtor(struct ipoib_neigh *neigh) |
| 1058 | { |
| 1059 | /* neigh reference count was dropprd to zero */ |
| 1060 | struct net_device *dev = neigh->dev; |
| 1061 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1062 | struct sk_buff *skb; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1063 | if (neigh->ah) |
| 1064 | ipoib_put_ah(neigh->ah); |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1065 | while ((skb = __skb_dequeue(&neigh->queue))) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 1066 | ++dev->stats.tx_dropped; |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1067 | dev_kfree_skb_any(skb); |
| 1068 | } |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1069 | if (ipoib_cm_get(neigh)) |
| 1070 | ipoib_cm_destroy_tx(ipoib_cm_get(neigh)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1071 | ipoib_dbg(netdev_priv(dev), |
| 1072 | "neigh free for %06x %pI6\n", |
| 1073 | IPOIB_QPN(neigh->daddr), |
| 1074 | neigh->daddr + 4); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1075 | kfree(neigh); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1076 | if (atomic_dec_and_test(&priv->ntbl.entries)) { |
| 1077 | if (test_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags)) |
| 1078 | complete(&priv->ntbl.flushed); |
| 1079 | } |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1080 | } |
| 1081 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1082 | static void ipoib_neigh_reclaim(struct rcu_head *rp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1084 | /* Called as a result of removal from hash table */ |
| 1085 | struct ipoib_neigh *neigh = container_of(rp, struct ipoib_neigh, rcu); |
| 1086 | /* note TX context may hold another ref */ |
| 1087 | ipoib_neigh_put(neigh); |
| 1088 | } |
| 1089 | |
| 1090 | void ipoib_neigh_free(struct ipoib_neigh *neigh) |
| 1091 | { |
| 1092 | struct net_device *dev = neigh->dev; |
| 1093 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1094 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1095 | struct ipoib_neigh_hash *htbl; |
| 1096 | struct ipoib_neigh __rcu **np; |
| 1097 | struct ipoib_neigh *n; |
| 1098 | u32 hash_val; |
| 1099 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1100 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1101 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1102 | if (!htbl) |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1103 | return; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1104 | |
| 1105 | hash_val = ipoib_addr_hash(htbl, neigh->daddr); |
| 1106 | np = &htbl->buckets[hash_val]; |
| 1107 | for (n = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1108 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1109 | n != NULL; |
Shlomo Pongratz | 6c723a6 | 2012-08-13 14:39:50 +0000 | [diff] [blame] | 1110 | n = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1111 | lockdep_is_held(&priv->lock))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1112 | if (n == neigh) { |
| 1113 | /* found */ |
| 1114 | rcu_assign_pointer(*np, |
| 1115 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1116 | lockdep_is_held(&priv->lock))); |
Jim Foraker | 49b8e74 | 2013-08-08 17:44:22 -0700 | [diff] [blame] | 1117 | /* remove from parent list */ |
| 1118 | list_del(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1119 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1120 | return; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1121 | } else { |
| 1122 | np = &n->hnext; |
| 1123 | } |
| 1124 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) |
| 1128 | { |
| 1129 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1130 | struct ipoib_neigh_hash *htbl; |
Bart Van Assche | 5237496 | 2015-05-26 15:03:48 +0200 | [diff] [blame] | 1131 | struct ipoib_neigh __rcu **buckets; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1132 | u32 size; |
| 1133 | |
| 1134 | clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); |
| 1135 | ntbl->htbl = NULL; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1136 | htbl = kzalloc(sizeof(*htbl), GFP_KERNEL); |
| 1137 | if (!htbl) |
| 1138 | return -ENOMEM; |
| 1139 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1140 | size = roundup_pow_of_two(arp_tbl.gc_thresh3); |
| 1141 | buckets = kzalloc(size * sizeof(*buckets), GFP_KERNEL); |
| 1142 | if (!buckets) { |
| 1143 | kfree(htbl); |
| 1144 | return -ENOMEM; |
| 1145 | } |
| 1146 | htbl->size = size; |
| 1147 | htbl->mask = (size - 1); |
| 1148 | htbl->buckets = buckets; |
Bart Van Assche | 5237496 | 2015-05-26 15:03:48 +0200 | [diff] [blame] | 1149 | RCU_INIT_POINTER(ntbl->htbl, htbl); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1150 | htbl->ntbl = ntbl; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1151 | atomic_set(&ntbl->entries, 0); |
| 1152 | |
| 1153 | /* start garbage collection */ |
| 1154 | clear_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1155 | queue_delayed_work(priv->wq, &priv->neigh_reap_task, |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1156 | arp_tbl.gc_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1161 | static void neigh_hash_free_rcu(struct rcu_head *head) |
| 1162 | { |
| 1163 | struct ipoib_neigh_hash *htbl = container_of(head, |
| 1164 | struct ipoib_neigh_hash, |
| 1165 | rcu); |
| 1166 | struct ipoib_neigh __rcu **buckets = htbl->buckets; |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1167 | struct ipoib_neigh_table *ntbl = htbl->ntbl; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1168 | |
| 1169 | kfree(buckets); |
| 1170 | kfree(htbl); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1171 | complete(&ntbl->deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid) |
| 1175 | { |
| 1176 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1177 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1178 | struct ipoib_neigh_hash *htbl; |
| 1179 | unsigned long flags; |
| 1180 | int i; |
| 1181 | |
| 1182 | /* remove all neigh connected to a given path or mcast */ |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1183 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1184 | |
| 1185 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1186 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (!htbl) |
| 1189 | goto out_unlock; |
| 1190 | |
| 1191 | for (i = 0; i < htbl->size; i++) { |
| 1192 | struct ipoib_neigh *neigh; |
| 1193 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 1194 | |
| 1195 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1196 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1197 | /* delete neighs belong to this parent */ |
| 1198 | if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) { |
| 1199 | rcu_assign_pointer(*np, |
| 1200 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1201 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1202 | /* remove from parent list */ |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1203 | list_del(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1204 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 1205 | } else { |
| 1206 | np = &neigh->hnext; |
| 1207 | } |
| 1208 | |
| 1209 | } |
| 1210 | } |
| 1211 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1212 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | static void ipoib_flush_neighs(struct ipoib_dev_priv *priv) |
| 1216 | { |
| 1217 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1218 | struct ipoib_neigh_hash *htbl; |
| 1219 | unsigned long flags; |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1220 | int i, wait_flushed = 0; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1221 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1222 | init_completion(&priv->ntbl.flushed); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1223 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1224 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1225 | |
| 1226 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1227 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1228 | if (!htbl) |
| 1229 | goto out_unlock; |
| 1230 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1231 | wait_flushed = atomic_read(&priv->ntbl.entries); |
| 1232 | if (!wait_flushed) |
| 1233 | goto free_htbl; |
| 1234 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1235 | for (i = 0; i < htbl->size; i++) { |
| 1236 | struct ipoib_neigh *neigh; |
| 1237 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 1238 | |
| 1239 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1240 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1241 | rcu_assign_pointer(*np, |
| 1242 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1243 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1244 | /* remove from path/mc list */ |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1245 | list_del(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1246 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 1247 | } |
| 1248 | } |
| 1249 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1250 | free_htbl: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1251 | rcu_assign_pointer(ntbl->htbl, NULL); |
| 1252 | call_rcu(&htbl->rcu, neigh_hash_free_rcu); |
| 1253 | |
| 1254 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1255 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1256 | if (wait_flushed) |
| 1257 | wait_for_completion(&priv->ntbl.flushed); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | static void ipoib_neigh_hash_uninit(struct net_device *dev) |
| 1261 | { |
| 1262 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1263 | int stopped; |
| 1264 | |
| 1265 | ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n"); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1266 | init_completion(&priv->ntbl.deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1267 | set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); |
| 1268 | |
| 1269 | /* Stop GC if called at init fail need to cancel work */ |
| 1270 | stopped = test_and_set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1271 | if (!stopped) |
| 1272 | cancel_delayed_work(&priv->neigh_reap_task); |
| 1273 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1274 | ipoib_flush_neighs(priv); |
| 1275 | |
| 1276 | wait_for_completion(&priv->ntbl.deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port) |
| 1281 | { |
| 1282 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1283 | |
| 1284 | /* Allocate RX/TX "rings" to hold queued skbs */ |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1285 | priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | GFP_KERNEL); |
| 1287 | if (!priv->rx_ring) { |
| 1288 | printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n", |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1289 | ca->name, ipoib_recvq_size); |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1290 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
Joe Perches | 948579c | 2010-11-05 03:07:36 +0000 | [diff] [blame] | 1293 | priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | if (!priv->tx_ring) { |
| 1295 | printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n", |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1296 | ca->name, ipoib_sendq_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | goto out_rx_ring_cleanup; |
| 1298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 1300 | /* priv->tx_head, tx_tail & tx_outstanding are already 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
| 1302 | if (ipoib_ib_dev_init(dev, ca, port)) |
| 1303 | goto out_tx_ring_cleanup; |
| 1304 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1305 | /* |
| 1306 | * Must be after ipoib_ib_dev_init so we can allocate a per |
| 1307 | * device wq there and use it here |
| 1308 | */ |
| 1309 | if (ipoib_neigh_hash_init(priv) < 0) |
| 1310 | goto out_dev_uninit; |
| 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | return 0; |
| 1313 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1314 | out_dev_uninit: |
| 1315 | ipoib_ib_dev_cleanup(dev); |
| 1316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | out_tx_ring_cleanup: |
Roland Dreier | 10313cb | 2008-03-12 07:51:03 -0700 | [diff] [blame] | 1318 | vfree(priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | |
| 1320 | out_rx_ring_cleanup: |
| 1321 | kfree(priv->rx_ring); |
| 1322 | |
| 1323 | out: |
| 1324 | return -ENOMEM; |
| 1325 | } |
| 1326 | |
| 1327 | void ipoib_dev_cleanup(struct net_device *dev) |
| 1328 | { |
| 1329 | struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv; |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1330 | LIST_HEAD(head); |
| 1331 | |
| 1332 | ASSERT_RTNL(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 1334 | ipoib_delete_debug_files(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
| 1336 | /* Delete any child interfaces first */ |
| 1337 | list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1338 | /* Stop GC on child */ |
| 1339 | set_bit(IPOIB_STOP_NEIGH_GC, &cpriv->flags); |
| 1340 | cancel_delayed_work(&cpriv->neigh_reap_task); |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1341 | unregister_netdevice_queue(cpriv->dev, &head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1343 | unregister_netdevice_many(&head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1345 | /* |
| 1346 | * Must be before ipoib_ib_dev_cleanup or we delete an in use |
| 1347 | * work queue |
| 1348 | */ |
| 1349 | ipoib_neigh_hash_uninit(dev); |
| 1350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | ipoib_ib_dev_cleanup(dev); |
| 1352 | |
Hal Rosenstock | 92a6b34 | 2005-08-13 20:50:27 -0700 | [diff] [blame] | 1353 | kfree(priv->rx_ring); |
Roland Dreier | 10313cb | 2008-03-12 07:51:03 -0700 | [diff] [blame] | 1354 | vfree(priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | |
Hal Rosenstock | 92a6b34 | 2005-08-13 20:50:27 -0700 | [diff] [blame] | 1356 | priv->rx_ring = NULL; |
| 1357 | priv->tx_ring = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 1360 | static const struct header_ops ipoib_header_ops = { |
| 1361 | .create = ipoib_hard_header, |
| 1362 | }; |
| 1363 | |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1364 | static const struct net_device_ops ipoib_netdev_ops = { |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1365 | .ndo_uninit = ipoib_uninit, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1366 | .ndo_open = ipoib_open, |
| 1367 | .ndo_stop = ipoib_stop, |
| 1368 | .ndo_change_mtu = ipoib_change_mtu, |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 1369 | .ndo_fix_features = ipoib_fix_features, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1370 | .ndo_start_xmit = ipoib_start_xmit, |
| 1371 | .ndo_tx_timeout = ipoib_timeout, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1372 | .ndo_set_rx_mode = ipoib_set_mcast_list, |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 1373 | .ndo_get_iflink = ipoib_get_iflink, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1374 | }; |
| 1375 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1376 | void ipoib_setup(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | { |
| 1378 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1379 | |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1380 | dev->netdev_ops = &ipoib_netdev_ops; |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1381 | dev->header_ops = &ipoib_header_ops; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1382 | |
Eli Cohen | 82c24c1 | 2008-04-16 21:09:32 -0700 | [diff] [blame] | 1383 | ipoib_set_ethtool_ops(dev); |
| 1384 | |
Michal Schmidt | 7f1a386 | 2013-08-21 18:50:22 +0200 | [diff] [blame] | 1385 | netif_napi_add(dev, &priv->napi, ipoib_poll, NAPI_POLL_WEIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1387 | dev->watchdog_timeo = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1389 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 1391 | dev->hard_header_len = IPOIB_ENCAP_LEN; |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1392 | dev->addr_len = INFINIBAND_ALEN; |
| 1393 | dev->type = ARPHRD_INFINIBAND; |
| 1394 | dev->tx_queue_len = ipoib_sendq_size * 2; |
Eli Cohen | eb14032f | 2008-01-30 18:30:46 +0200 | [diff] [blame] | 1395 | dev->features = (NETIF_F_VLAN_CHALLENGED | |
Eli Cohen | eb14032f | 2008-01-30 18:30:46 +0200 | [diff] [blame] | 1396 | NETIF_F_HIGHDMA); |
Eric Dumazet | 0287587 | 2014-10-05 18:38:35 -0700 | [diff] [blame] | 1397 | netif_keep_dst(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN); |
| 1400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | priv->dev = dev; |
| 1402 | |
| 1403 | spin_lock_init(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 1405 | init_rwsem(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
| 1407 | INIT_LIST_HEAD(&priv->path_list); |
| 1408 | INIT_LIST_HEAD(&priv->child_intfs); |
| 1409 | INIT_LIST_HEAD(&priv->dead_ahs); |
| 1410 | INIT_LIST_HEAD(&priv->multicast_list); |
| 1411 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1412 | INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task); |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 1413 | INIT_WORK(&priv->carrier_on_task, ipoib_mcast_carrier_on_task); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 1414 | INIT_WORK(&priv->flush_light, ipoib_ib_dev_flush_light); |
| 1415 | INIT_WORK(&priv->flush_normal, ipoib_ib_dev_flush_normal); |
| 1416 | INIT_WORK(&priv->flush_heavy, ipoib_ib_dev_flush_heavy); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1417 | INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task); |
| 1418 | INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1419 | INIT_DELAYED_WORK(&priv->neigh_reap_task, ipoib_reap_neigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | struct ipoib_dev_priv *ipoib_intf_alloc(const char *name) |
| 1423 | { |
| 1424 | struct net_device *dev; |
| 1425 | |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 1426 | dev = alloc_netdev((int)sizeof(struct ipoib_dev_priv), name, |
| 1427 | NET_NAME_UNKNOWN, ipoib_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | if (!dev) |
| 1429 | return NULL; |
| 1430 | |
| 1431 | return netdev_priv(dev); |
| 1432 | } |
| 1433 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1434 | static ssize_t show_pkey(struct device *dev, |
| 1435 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1437 | struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | |
| 1439 | return sprintf(buf, "0x%04x\n", priv->pkey); |
| 1440 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1441 | static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1443 | static ssize_t show_umcast(struct device *dev, |
| 1444 | struct device_attribute *attr, char *buf) |
| 1445 | { |
| 1446 | struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev)); |
| 1447 | |
| 1448 | return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags)); |
| 1449 | } |
| 1450 | |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1451 | void ipoib_set_umcast(struct net_device *ndev, int umcast_val) |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1452 | { |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1453 | struct ipoib_dev_priv *priv = netdev_priv(ndev); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1454 | |
| 1455 | if (umcast_val > 0) { |
| 1456 | set_bit(IPOIB_FLAG_UMCAST, &priv->flags); |
| 1457 | ipoib_warn(priv, "ignoring multicast groups joined directly " |
| 1458 | "by userspace\n"); |
| 1459 | } else |
| 1460 | clear_bit(IPOIB_FLAG_UMCAST, &priv->flags); |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | static ssize_t set_umcast(struct device *dev, |
| 1464 | struct device_attribute *attr, |
| 1465 | const char *buf, size_t count) |
| 1466 | { |
| 1467 | unsigned long umcast_val = simple_strtoul(buf, NULL, 0); |
| 1468 | |
| 1469 | ipoib_set_umcast(to_net_dev(dev), umcast_val); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1470 | |
| 1471 | return count; |
| 1472 | } |
| 1473 | static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast); |
| 1474 | |
| 1475 | int ipoib_add_umcast_attr(struct net_device *dev) |
| 1476 | { |
| 1477 | return device_create_file(&dev->dev, &dev_attr_umcast); |
| 1478 | } |
| 1479 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1480 | static ssize_t create_child(struct device *dev, |
| 1481 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | const char *buf, size_t count) |
| 1483 | { |
| 1484 | int pkey; |
| 1485 | int ret; |
| 1486 | |
| 1487 | if (sscanf(buf, "%i", &pkey) != 1) |
| 1488 | return -EINVAL; |
| 1489 | |
Or Gerlitz | 3d790a4 | 2013-07-18 14:02:31 +0300 | [diff] [blame] | 1490 | if (pkey <= 0 || pkey > 0xffff || pkey == 0x8000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | return -EINVAL; |
| 1492 | |
Roland Dreier | 4ce0593 | 2005-08-19 12:03:17 -0700 | [diff] [blame] | 1493 | /* |
| 1494 | * Set the full membership bit, so that we join the right |
| 1495 | * broadcast group, etc. |
| 1496 | */ |
| 1497 | pkey |= 0x8000; |
| 1498 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1499 | ret = ipoib_vlan_add(to_net_dev(dev), pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
| 1501 | return ret ? ret : count; |
| 1502 | } |
Or Gerlitz | 7a52b34 | 2010-06-06 04:59:16 +0000 | [diff] [blame] | 1503 | static DEVICE_ATTR(create_child, S_IWUSR, NULL, create_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1505 | static ssize_t delete_child(struct device *dev, |
| 1506 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | const char *buf, size_t count) |
| 1508 | { |
| 1509 | int pkey; |
| 1510 | int ret; |
| 1511 | |
| 1512 | if (sscanf(buf, "%i", &pkey) != 1) |
| 1513 | return -EINVAL; |
| 1514 | |
| 1515 | if (pkey < 0 || pkey > 0xffff) |
| 1516 | return -EINVAL; |
| 1517 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1518 | ret = ipoib_vlan_delete(to_net_dev(dev), pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
| 1520 | return ret ? ret : count; |
| 1521 | |
| 1522 | } |
Or Gerlitz | 7a52b34 | 2010-06-06 04:59:16 +0000 | [diff] [blame] | 1523 | static DEVICE_ATTR(delete_child, S_IWUSR, NULL, delete_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | |
| 1525 | int ipoib_add_pkey_attr(struct net_device *dev) |
| 1526 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1527 | return device_create_file(&dev->dev, &dev_attr_pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 1530 | int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca) |
| 1531 | { |
| 1532 | struct ib_device_attr *device_attr; |
| 1533 | int result = -ENOMEM; |
| 1534 | |
| 1535 | device_attr = kmalloc(sizeof *device_attr, GFP_KERNEL); |
| 1536 | if (!device_attr) { |
| 1537 | printk(KERN_WARNING "%s: allocation of %zu bytes failed\n", |
| 1538 | hca->name, sizeof *device_attr); |
| 1539 | return result; |
| 1540 | } |
| 1541 | |
| 1542 | result = ib_query_device(hca, device_attr); |
| 1543 | if (result) { |
| 1544 | printk(KERN_WARNING "%s: ib_query_device failed (ret = %d)\n", |
| 1545 | hca->name, result); |
| 1546 | kfree(device_attr); |
| 1547 | return result; |
| 1548 | } |
| 1549 | priv->hca_caps = device_attr->device_cap_flags; |
| 1550 | |
| 1551 | kfree(device_attr); |
| 1552 | |
| 1553 | if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) { |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 1554 | priv->dev->hw_features = NETIF_F_SG | |
| 1555 | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
| 1556 | |
| 1557 | if (priv->hca_caps & IB_DEVICE_UD_TSO) |
| 1558 | priv->dev->hw_features |= NETIF_F_TSO; |
| 1559 | |
| 1560 | priv->dev->features |= priv->dev->hw_features; |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 1563 | return 0; |
| 1564 | } |
| 1565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | static struct net_device *ipoib_add_port(const char *format, |
| 1567 | struct ib_device *hca, u8 port) |
| 1568 | { |
| 1569 | struct ipoib_dev_priv *priv; |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 1570 | struct ib_port_attr attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | int result = -ENOMEM; |
| 1572 | |
| 1573 | priv = ipoib_intf_alloc(format); |
| 1574 | if (!priv) |
| 1575 | goto alloc_mem_failed; |
| 1576 | |
| 1577 | SET_NETDEV_DEV(priv->dev, hca->dma_device); |
Eli Cohen | c3aa9b1 | 2010-09-20 07:05:06 +0000 | [diff] [blame] | 1578 | priv->dev->dev_id = port - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 1580 | if (!ib_query_port(hca, port, &attr)) |
| 1581 | priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu); |
| 1582 | else { |
| 1583 | printk(KERN_WARNING "%s: ib_query_port %d failed\n", |
| 1584 | hca->name, port); |
| 1585 | goto device_init_failed; |
| 1586 | } |
| 1587 | |
| 1588 | /* MTU will be reset when mcast join happens */ |
| 1589 | priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu); |
| 1590 | priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu; |
| 1591 | |
David Miller | 596b9b6 | 2011-07-25 00:01:25 +0000 | [diff] [blame] | 1592 | priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh); |
| 1593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | result = ib_query_pkey(hca, port, 0, &priv->pkey); |
| 1595 | if (result) { |
| 1596 | printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n", |
| 1597 | hca->name, port, result); |
Eli Cohen | ca6de17 | 2007-08-21 18:46:10 +0300 | [diff] [blame] | 1598 | goto device_init_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 1601 | if (ipoib_set_dev_features(priv, hca)) |
Eli Cohen | 6046136 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 1602 | goto device_init_failed; |
Vladimir Sokolovsky | af40da8 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 1603 | |
Roland Dreier | 4ce0593 | 2005-08-19 12:03:17 -0700 | [diff] [blame] | 1604 | /* |
| 1605 | * Set the full membership bit, so that we join the right |
| 1606 | * broadcast group, etc. |
| 1607 | */ |
| 1608 | priv->pkey |= 0x8000; |
| 1609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | priv->dev->broadcast[8] = priv->pkey >> 8; |
| 1611 | priv->dev->broadcast[9] = priv->pkey & 0xff; |
| 1612 | |
| 1613 | result = ib_query_gid(hca, port, 0, &priv->local_gid); |
| 1614 | if (result) { |
| 1615 | printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n", |
| 1616 | hca->name, port, result); |
Eli Cohen | ca6de17 | 2007-08-21 18:46:10 +0300 | [diff] [blame] | 1617 | goto device_init_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | } else |
| 1619 | memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); |
| 1620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | result = ipoib_dev_init(priv->dev, hca, port); |
| 1622 | if (result < 0) { |
| 1623 | printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n", |
| 1624 | hca->name, port, result); |
| 1625 | goto device_init_failed; |
| 1626 | } |
| 1627 | |
| 1628 | INIT_IB_EVENT_HANDLER(&priv->event_handler, |
| 1629 | priv->ca, ipoib_event); |
| 1630 | result = ib_register_event_handler(&priv->event_handler); |
| 1631 | if (result < 0) { |
| 1632 | printk(KERN_WARNING "%s: ib_register_event_handler failed for " |
| 1633 | "port %d (ret = %d)\n", |
| 1634 | hca->name, port, result); |
| 1635 | goto event_failed; |
| 1636 | } |
| 1637 | |
| 1638 | result = register_netdev(priv->dev); |
| 1639 | if (result) { |
| 1640 | printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n", |
| 1641 | hca->name, port, result); |
| 1642 | goto register_failed; |
| 1643 | } |
| 1644 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 1645 | ipoib_create_debug_files(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1647 | if (ipoib_cm_add_mode_attr(priv->dev)) |
| 1648 | goto sysfs_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | if (ipoib_add_pkey_attr(priv->dev)) |
| 1650 | goto sysfs_failed; |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1651 | if (ipoib_add_umcast_attr(priv->dev)) |
| 1652 | goto sysfs_failed; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1653 | if (device_create_file(&priv->dev->dev, &dev_attr_create_child)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | goto sysfs_failed; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1655 | if (device_create_file(&priv->dev->dev, &dev_attr_delete_child)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | goto sysfs_failed; |
| 1657 | |
| 1658 | return priv->dev; |
| 1659 | |
| 1660 | sysfs_failed: |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 1661 | ipoib_delete_debug_files(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | unregister_netdev(priv->dev); |
| 1663 | |
| 1664 | register_failed: |
| 1665 | ib_unregister_event_handler(&priv->event_handler); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1666 | flush_workqueue(ipoib_workqueue); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1667 | /* Stop GC if started before flush */ |
| 1668 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1669 | cancel_delayed_work(&priv->neigh_reap_task); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1670 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | |
| 1672 | event_failed: |
| 1673 | ipoib_dev_cleanup(priv->dev); |
| 1674 | |
| 1675 | device_init_failed: |
| 1676 | free_netdev(priv->dev); |
| 1677 | |
| 1678 | alloc_mem_failed: |
| 1679 | return ERR_PTR(result); |
| 1680 | } |
| 1681 | |
| 1682 | static void ipoib_add_one(struct ib_device *device) |
| 1683 | { |
| 1684 | struct list_head *dev_list; |
| 1685 | struct net_device *dev; |
| 1686 | struct ipoib_dev_priv *priv; |
| 1687 | int s, e, p; |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 1688 | int count = 0; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); |
| 1691 | if (!dev_list) |
| 1692 | return; |
| 1693 | |
| 1694 | INIT_LIST_HEAD(dev_list); |
| 1695 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1696 | if (device->node_type == RDMA_NODE_IB_SWITCH) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | s = 0; |
| 1698 | e = 0; |
| 1699 | } else { |
| 1700 | s = 1; |
| 1701 | e = device->phys_port_cnt; |
| 1702 | } |
| 1703 | |
| 1704 | for (p = s; p <= e; ++p) { |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 1705 | if (!rdma_protocol_ib(device, p)) |
Eli Cohen | 7b4c876 | 2010-09-27 17:51:11 -0700 | [diff] [blame] | 1706 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | dev = ipoib_add_port("ib%d", device, p); |
| 1708 | if (!IS_ERR(dev)) { |
| 1709 | priv = netdev_priv(dev); |
| 1710 | list_add_tail(&priv->list, dev_list); |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 1711 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 1715 | if (!count) { |
| 1716 | kfree(dev_list); |
| 1717 | return; |
| 1718 | } |
| 1719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | ib_set_client_data(device, &ipoib_client, dev_list); |
| 1721 | } |
| 1722 | |
| 1723 | static void ipoib_remove_one(struct ib_device *device) |
| 1724 | { |
| 1725 | struct ipoib_dev_priv *priv, *tmp; |
| 1726 | struct list_head *dev_list; |
| 1727 | |
| 1728 | dev_list = ib_get_client_data(device, &ipoib_client); |
Itai Garbi | 5a2815f | 2013-02-19 15:40:24 +0000 | [diff] [blame] | 1729 | if (!dev_list) |
| 1730 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
| 1732 | list_for_each_entry_safe(priv, tmp, dev_list, list) { |
| 1733 | ib_unregister_event_handler(&priv->event_handler); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1734 | flush_workqueue(ipoib_workqueue); |
Roland Dreier | a77a57a | 2008-08-19 15:01:32 -0700 | [diff] [blame] | 1735 | |
| 1736 | rtnl_lock(); |
| 1737 | dev_change_flags(priv->dev, priv->dev->flags & ~IFF_UP); |
| 1738 | rtnl_unlock(); |
| 1739 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1740 | /* Stop GC */ |
| 1741 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1742 | cancel_delayed_work(&priv->neigh_reap_task); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1743 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | |
| 1745 | unregister_netdev(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | free_netdev(priv->dev); |
| 1747 | } |
Michael S. Tsirkin | 06c56e4 | 2005-09-01 09:19:02 -0700 | [diff] [blame] | 1748 | |
| 1749 | kfree(dev_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static int __init ipoib_init_module(void) |
| 1753 | { |
| 1754 | int ret; |
| 1755 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1756 | ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size); |
| 1757 | ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE); |
| 1758 | ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE); |
| 1759 | |
| 1760 | ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size); |
| 1761 | ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE); |
Hagen Paul Pfeifer | 732eacc | 2010-10-26 14:22:23 -0700 | [diff] [blame] | 1762 | ipoib_sendq_size = max3(ipoib_sendq_size, 2 * MAX_SEND_CQE, IPOIB_MIN_QUEUE_SIZE); |
Pradeep Satyanarayana | 68e995a | 2008-01-25 14:15:24 -0800 | [diff] [blame] | 1763 | #ifdef CONFIG_INFINIBAND_IPOIB_CM |
| 1764 | ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP); |
| 1765 | #endif |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1766 | |
Eli Cohen | f89271da | 2008-07-14 23:48:44 -0700 | [diff] [blame] | 1767 | /* |
| 1768 | * When copying small received packets, we only copy from the |
| 1769 | * linear data part of the SKB, so we rely on this condition. |
| 1770 | */ |
| 1771 | BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE); |
| 1772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | ret = ipoib_register_debugfs(); |
| 1774 | if (ret) |
| 1775 | return ret; |
| 1776 | |
| 1777 | /* |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1778 | * We create a global workqueue here that is used for all flush |
| 1779 | * operations. However, if you attempt to flush a workqueue |
| 1780 | * from a task on that same workqueue, it deadlocks the system. |
| 1781 | * We want to be able to flush the tasks associated with a |
| 1782 | * specific net device, so we also create a workqueue for each |
| 1783 | * netdevice. We queue up the tasks for that device only on |
| 1784 | * its private workqueue, and we only queue up flush events |
| 1785 | * on our global flush workqueue. This avoids the deadlocks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | */ |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1787 | ipoib_workqueue = create_singlethread_workqueue("ipoib_flush"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | if (!ipoib_workqueue) { |
| 1789 | ret = -ENOMEM; |
| 1790 | goto err_fs; |
| 1791 | } |
| 1792 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 1793 | ib_sa_register_client(&ipoib_sa_client); |
| 1794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | ret = ib_register_client(&ipoib_client); |
| 1796 | if (ret) |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 1797 | goto err_sa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1799 | ret = ipoib_netlink_init(); |
| 1800 | if (ret) |
| 1801 | goto err_client; |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1805 | err_client: |
| 1806 | ib_unregister_client(&ipoib_client); |
| 1807 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 1808 | err_sa: |
| 1809 | ib_sa_unregister_client(&ipoib_sa_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | destroy_workqueue(ipoib_workqueue); |
| 1811 | |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 1812 | err_fs: |
| 1813 | ipoib_unregister_debugfs(); |
| 1814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | return ret; |
| 1816 | } |
| 1817 | |
| 1818 | static void __exit ipoib_cleanup_module(void) |
| 1819 | { |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1820 | ipoib_netlink_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | ib_unregister_client(&ipoib_client); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 1822 | ib_sa_unregister_client(&ipoib_sa_client); |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 1823 | ipoib_unregister_debugfs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | destroy_workqueue(ipoib_workqueue); |
| 1825 | } |
| 1826 | |
| 1827 | module_init(ipoib_init_module); |
| 1828 | module_exit(ipoib_cleanup_module); |