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