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