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> |
Guy Shapiro | ddde896 | 2015-07-30 17:50:16 +0300 | [diff] [blame] | 51 | #include <net/addrconf.h> |
| 52 | #include <linux/inetdevice.h> |
| 53 | #include <rdma/ib_cache.h> |
Eli Cohen | 9c3c5f8 | 2016-03-11 22:58:39 +0200 | [diff] [blame] | 54 | #include <linux/pci.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 55 | |
Yan Burman | 4b48680 | 2013-02-19 15:40:23 +0000 | [diff] [blame] | 56 | #define DRV_VERSION "1.0.0" |
| 57 | |
| 58 | const char ipoib_driver_version[] = DRV_VERSION; |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | MODULE_AUTHOR("Roland Dreier"); |
| 61 | MODULE_DESCRIPTION("IP-over-InfiniBand net driver"); |
| 62 | MODULE_LICENSE("Dual BSD/GPL"); |
Yan Burman | 4b48680 | 2013-02-19 15:40:23 +0000 | [diff] [blame] | 63 | MODULE_VERSION(DRV_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 65 | int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE; |
| 66 | int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE; |
| 67 | |
| 68 | module_param_named(send_queue_size, ipoib_sendq_size, int, 0444); |
| 69 | MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue"); |
| 70 | module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444); |
| 71 | MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue"); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 74 | int ipoib_debug_level; |
| 75 | |
| 76 | module_param_named(debug_level, ipoib_debug_level, int, 0644); |
| 77 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); |
| 78 | #endif |
| 79 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 80 | struct ipoib_path_iter { |
| 81 | struct net_device *dev; |
| 82 | struct ipoib_path path; |
| 83 | }; |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static const u8 ipv4_bcast_addr[] = { |
| 86 | 0x00, 0xff, 0xff, 0xff, |
| 87 | 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00, |
| 88 | 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff |
| 89 | }; |
| 90 | |
| 91 | struct workqueue_struct *ipoib_workqueue; |
| 92 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 93 | struct ib_sa_client ipoib_sa_client; |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static void ipoib_add_one(struct ib_device *device); |
Haggai Eran | 7c1eb45 | 2015-07-30 17:50:14 +0300 | [diff] [blame] | 96 | static void ipoib_remove_one(struct ib_device *device, void *client_data); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 97 | static void ipoib_neigh_reclaim(struct rcu_head *rp); |
Guy Shapiro | ddde896 | 2015-07-30 17:50:16 +0300 | [diff] [blame] | 98 | static struct net_device *ipoib_get_net_dev_by_params( |
| 99 | struct ib_device *dev, u8 port, u16 pkey, |
| 100 | const union ib_gid *gid, const struct sockaddr *addr, |
| 101 | void *client_data); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 102 | static int ipoib_set_mac(struct net_device *dev, void *addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | static struct ib_client ipoib_client = { |
| 105 | .name = "ipoib", |
| 106 | .add = ipoib_add_one, |
Guy Shapiro | ddde896 | 2015-07-30 17:50:16 +0300 | [diff] [blame] | 107 | .remove = ipoib_remove_one, |
| 108 | .get_net_dev_by_params = ipoib_get_net_dev_by_params, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | }; |
| 110 | |
Shamir Rabinovitch | d20bfe2 | 2017-03-29 06:21:59 -0400 | [diff] [blame] | 111 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 112 | static int ipoib_netdev_event(struct notifier_block *this, |
| 113 | unsigned long event, void *ptr) |
| 114 | { |
| 115 | struct netdev_notifier_info *ni = ptr; |
| 116 | struct net_device *dev = ni->dev; |
| 117 | |
| 118 | if (dev->netdev_ops->ndo_open != ipoib_open) |
| 119 | return NOTIFY_DONE; |
| 120 | |
| 121 | switch (event) { |
| 122 | case NETDEV_REGISTER: |
| 123 | ipoib_create_debug_files(dev); |
| 124 | break; |
| 125 | case NETDEV_CHANGENAME: |
| 126 | ipoib_delete_debug_files(dev); |
| 127 | ipoib_create_debug_files(dev); |
| 128 | break; |
| 129 | case NETDEV_UNREGISTER: |
| 130 | ipoib_delete_debug_files(dev); |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | return NOTIFY_DONE; |
| 135 | } |
| 136 | #endif |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | int ipoib_open(struct net_device *dev) |
| 139 | { |
| 140 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 141 | |
| 142 | ipoib_dbg(priv, "bringing up interface\n"); |
| 143 | |
Michal Schmidt | 437708c | 2014-01-17 19:47:25 +0100 | [diff] [blame] | 144 | netif_carrier_off(dev); |
| 145 | |
Yossi Etigin | e028cc5 | 2009-04-20 13:58:08 -0700 | [diff] [blame] | 146 | set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Erez Shitrit | 3b56113 | 2016-05-25 22:02:07 +0300 | [diff] [blame] | 148 | priv->sm_fullmember_sendonly_support = false; |
| 149 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 150 | if (ipoib_ib_dev_open(dev)) { |
Alex Estrin | dd57c93 | 2014-08-06 14:40:32 -0400 | [diff] [blame] | 151 | if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) |
| 152 | return 0; |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 153 | goto err_disable; |
Alex Estrin | dd57c93 | 2014-08-06 14:40:32 -0400 | [diff] [blame] | 154 | } |
Yossi Etigin | fe25c56 | 2008-11-12 10:24:36 -0800 | [diff] [blame] | 155 | |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 156 | if (ipoib_ib_dev_up(dev)) |
| 157 | goto err_stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { |
| 160 | struct ipoib_dev_priv *cpriv; |
| 161 | |
| 162 | /* Bring up any child interfaces too */ |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 163 | down_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | list_for_each_entry(cpriv, &priv->child_intfs, list) { |
| 165 | int flags; |
| 166 | |
| 167 | flags = cpriv->dev->flags; |
| 168 | if (flags & IFF_UP) |
| 169 | continue; |
| 170 | |
| 171 | dev_change_flags(cpriv->dev, flags | IFF_UP); |
| 172 | } |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 173 | up_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | netif_start_queue(dev); |
| 177 | |
| 178 | return 0; |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 179 | |
| 180 | err_stop: |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 181 | ipoib_ib_dev_stop(dev); |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 182 | |
| 183 | err_disable: |
Roland Dreier | b8a1b1c | 2009-01-14 14:55:41 -0800 | [diff] [blame] | 184 | clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
| 185 | |
| 186 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int ipoib_stop(struct net_device *dev) |
| 190 | { |
| 191 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 192 | |
| 193 | ipoib_dbg(priv, "stopping interface\n"); |
| 194 | |
| 195 | clear_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); |
| 196 | |
| 197 | netif_stop_queue(dev); |
| 198 | |
Doug Ledford | efc82ee | 2015-02-21 19:27:04 -0500 | [diff] [blame] | 199 | ipoib_ib_dev_down(dev); |
| 200 | ipoib_ib_dev_stop(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { |
| 203 | struct ipoib_dev_priv *cpriv; |
| 204 | |
| 205 | /* Bring down any child interfaces too */ |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 206 | down_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | list_for_each_entry(cpriv, &priv->child_intfs, list) { |
| 208 | int flags; |
| 209 | |
| 210 | flags = cpriv->dev->flags; |
| 211 | if (!(flags & IFF_UP)) |
| 212 | continue; |
| 213 | |
| 214 | dev_change_flags(cpriv->dev, flags & ~IFF_UP); |
| 215 | } |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 216 | up_read(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 222 | static void ipoib_uninit(struct net_device *dev) |
| 223 | { |
| 224 | ipoib_dev_cleanup(dev); |
| 225 | } |
| 226 | |
David S. Miller | 9ca36f7 | 2011-11-16 18:05:50 -0500 | [diff] [blame] | 227 | 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] | 228 | { |
| 229 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 230 | |
| 231 | if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags)) |
Yuval Shaia | c426877 | 2015-07-12 01:24:09 -0700 | [diff] [blame] | 232 | features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO); |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 233 | |
| 234 | return features; |
| 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | static int ipoib_change_mtu(struct net_device *dev, int new_mtu) |
| 238 | { |
| 239 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 240 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 241 | /* dev->mtu > 2K ==> connected mode */ |
Pradeep Satyanarayana | 586a693 | 2007-12-21 13:08:23 -0800 | [diff] [blame] | 242 | if (ipoib_cm_admin_enabled(dev)) { |
| 243 | if (new_mtu > ipoib_cm_max_mtu(dev)) |
| 244 | return -EINVAL; |
| 245 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 246 | if (new_mtu > priv->mcast_mtu) |
| 247 | ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n", |
| 248 | priv->mcast_mtu); |
Pradeep Satyanarayana | 586a693 | 2007-12-21 13:08:23 -0800 | [diff] [blame] | 249 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 250 | dev->mtu = new_mtu; |
| 251 | return 0; |
| 252 | } |
| 253 | |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 254 | if (new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return -EINVAL; |
| 256 | |
| 257 | priv->admin_mtu = new_mtu; |
| 258 | |
| 259 | dev->mtu = min(priv->mcast_mtu, priv->admin_mtu); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
Guy Shapiro | ddde896 | 2015-07-30 17:50:16 +0300 | [diff] [blame] | 264 | /* Called with an RCU read lock taken */ |
| 265 | static bool ipoib_is_dev_match_addr_rcu(const struct sockaddr *addr, |
| 266 | struct net_device *dev) |
| 267 | { |
| 268 | struct net *net = dev_net(dev); |
| 269 | struct in_device *in_dev; |
| 270 | struct sockaddr_in *addr_in = (struct sockaddr_in *)addr; |
| 271 | struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr; |
| 272 | __be32 ret_addr; |
| 273 | |
| 274 | switch (addr->sa_family) { |
| 275 | case AF_INET: |
| 276 | in_dev = in_dev_get(dev); |
| 277 | if (!in_dev) |
| 278 | return false; |
| 279 | |
| 280 | ret_addr = inet_confirm_addr(net, in_dev, 0, |
| 281 | addr_in->sin_addr.s_addr, |
| 282 | RT_SCOPE_HOST); |
| 283 | in_dev_put(in_dev); |
| 284 | if (ret_addr) |
| 285 | return true; |
| 286 | |
| 287 | break; |
| 288 | case AF_INET6: |
| 289 | if (IS_ENABLED(CONFIG_IPV6) && |
| 290 | ipv6_chk_addr(net, &addr_in6->sin6_addr, dev, 1)) |
| 291 | return true; |
| 292 | |
| 293 | break; |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Find the master net_device on top of the given net_device. |
| 300 | * @dev: base IPoIB net_device |
| 301 | * |
| 302 | * Returns the master net_device with a reference held, or the same net_device |
| 303 | * if no master exists. |
| 304 | */ |
| 305 | static struct net_device *ipoib_get_master_net_dev(struct net_device *dev) |
| 306 | { |
| 307 | struct net_device *master; |
| 308 | |
| 309 | rcu_read_lock(); |
| 310 | master = netdev_master_upper_dev_get_rcu(dev); |
| 311 | if (master) |
| 312 | dev_hold(master); |
| 313 | rcu_read_unlock(); |
| 314 | |
| 315 | if (master) |
| 316 | return master; |
| 317 | |
| 318 | dev_hold(dev); |
| 319 | return dev; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Find a net_device matching the given address, which is an upper device of |
| 324 | * the given net_device. |
| 325 | * @addr: IP address to look for. |
| 326 | * @dev: base IPoIB net_device |
| 327 | * |
| 328 | * If found, returns the net_device with a reference held. Otherwise return |
| 329 | * NULL. |
| 330 | */ |
| 331 | static struct net_device *ipoib_get_net_dev_match_addr( |
| 332 | const struct sockaddr *addr, struct net_device *dev) |
| 333 | { |
| 334 | struct net_device *upper, |
| 335 | *result = NULL; |
| 336 | struct list_head *iter; |
| 337 | |
| 338 | rcu_read_lock(); |
| 339 | if (ipoib_is_dev_match_addr_rcu(addr, dev)) { |
| 340 | dev_hold(dev); |
| 341 | result = dev; |
| 342 | goto out; |
| 343 | } |
| 344 | |
| 345 | netdev_for_each_all_upper_dev_rcu(dev, upper, iter) { |
| 346 | if (ipoib_is_dev_match_addr_rcu(addr, upper)) { |
| 347 | dev_hold(upper); |
| 348 | result = upper; |
| 349 | break; |
| 350 | } |
| 351 | } |
| 352 | out: |
| 353 | rcu_read_unlock(); |
| 354 | return result; |
| 355 | } |
| 356 | |
| 357 | /* returns the number of IPoIB netdevs on top a given ipoib device matching a |
| 358 | * pkey_index and address, if one exists. |
| 359 | * |
| 360 | * @found_net_dev: contains a matching net_device if the return value >= 1, |
| 361 | * with a reference held. */ |
| 362 | static int ipoib_match_gid_pkey_addr(struct ipoib_dev_priv *priv, |
| 363 | const union ib_gid *gid, |
| 364 | u16 pkey_index, |
| 365 | const struct sockaddr *addr, |
| 366 | int nesting, |
| 367 | struct net_device **found_net_dev) |
| 368 | { |
| 369 | struct ipoib_dev_priv *child_priv; |
| 370 | struct net_device *net_dev = NULL; |
| 371 | int matches = 0; |
| 372 | |
| 373 | if (priv->pkey_index == pkey_index && |
| 374 | (!gid || !memcmp(gid, &priv->local_gid, sizeof(*gid)))) { |
| 375 | if (!addr) { |
| 376 | net_dev = ipoib_get_master_net_dev(priv->dev); |
| 377 | } else { |
| 378 | /* Verify the net_device matches the IP address, as |
| 379 | * IPoIB child devices currently share a GID. */ |
| 380 | net_dev = ipoib_get_net_dev_match_addr(addr, priv->dev); |
| 381 | } |
| 382 | if (net_dev) { |
| 383 | if (!*found_net_dev) |
| 384 | *found_net_dev = net_dev; |
| 385 | else |
| 386 | dev_put(net_dev); |
| 387 | ++matches; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /* Check child interfaces */ |
| 392 | down_read_nested(&priv->vlan_rwsem, nesting); |
| 393 | list_for_each_entry(child_priv, &priv->child_intfs, list) { |
| 394 | matches += ipoib_match_gid_pkey_addr(child_priv, gid, |
| 395 | pkey_index, addr, |
| 396 | nesting + 1, |
| 397 | found_net_dev); |
| 398 | if (matches > 1) |
| 399 | break; |
| 400 | } |
| 401 | up_read(&priv->vlan_rwsem); |
| 402 | |
| 403 | return matches; |
| 404 | } |
| 405 | |
| 406 | /* Returns the number of matching net_devs found (between 0 and 2). Also |
| 407 | * return the matching net_device in the @net_dev parameter, holding a |
| 408 | * reference to the net_device, if the number of matches >= 1 */ |
| 409 | static int __ipoib_get_net_dev_by_params(struct list_head *dev_list, u8 port, |
| 410 | u16 pkey_index, |
| 411 | const union ib_gid *gid, |
| 412 | const struct sockaddr *addr, |
| 413 | struct net_device **net_dev) |
| 414 | { |
| 415 | struct ipoib_dev_priv *priv; |
| 416 | int matches = 0; |
| 417 | |
| 418 | *net_dev = NULL; |
| 419 | |
| 420 | list_for_each_entry(priv, dev_list, list) { |
| 421 | if (priv->port != port) |
| 422 | continue; |
| 423 | |
| 424 | matches += ipoib_match_gid_pkey_addr(priv, gid, pkey_index, |
| 425 | addr, 0, net_dev); |
| 426 | if (matches > 1) |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | return matches; |
| 431 | } |
| 432 | |
| 433 | static struct net_device *ipoib_get_net_dev_by_params( |
| 434 | struct ib_device *dev, u8 port, u16 pkey, |
| 435 | const union ib_gid *gid, const struct sockaddr *addr, |
| 436 | void *client_data) |
| 437 | { |
| 438 | struct net_device *net_dev; |
| 439 | struct list_head *dev_list = client_data; |
| 440 | u16 pkey_index; |
| 441 | int matches; |
| 442 | int ret; |
| 443 | |
| 444 | if (!rdma_protocol_ib(dev, port)) |
| 445 | return NULL; |
| 446 | |
| 447 | ret = ib_find_cached_pkey(dev, port, pkey, &pkey_index); |
| 448 | if (ret) |
| 449 | return NULL; |
| 450 | |
| 451 | if (!dev_list) |
| 452 | return NULL; |
| 453 | |
| 454 | /* See if we can find a unique device matching the L2 parameters */ |
| 455 | matches = __ipoib_get_net_dev_by_params(dev_list, port, pkey_index, |
| 456 | gid, NULL, &net_dev); |
| 457 | |
| 458 | switch (matches) { |
| 459 | case 0: |
| 460 | return NULL; |
| 461 | case 1: |
| 462 | return net_dev; |
| 463 | } |
| 464 | |
| 465 | dev_put(net_dev); |
| 466 | |
| 467 | /* Couldn't find a unique device with L2 parameters only. Use L3 |
| 468 | * address to uniquely match the net device */ |
| 469 | matches = __ipoib_get_net_dev_by_params(dev_list, port, pkey_index, |
| 470 | gid, addr, &net_dev); |
| 471 | switch (matches) { |
| 472 | case 0: |
| 473 | return NULL; |
| 474 | default: |
| 475 | dev_warn_ratelimited(&dev->dev, |
| 476 | "duplicate IP address detected\n"); |
| 477 | /* Fall through */ |
| 478 | case 1: |
| 479 | return net_dev; |
| 480 | } |
| 481 | } |
| 482 | |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 483 | int ipoib_set_mode(struct net_device *dev, const char *buf) |
| 484 | { |
| 485 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 486 | |
| 487 | /* flush paths if we switch modes so that connections are restarted */ |
| 488 | if (IPOIB_CM_SUPPORTED(dev->dev_addr) && !strcmp(buf, "connected\n")) { |
| 489 | set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 490 | ipoib_warn(priv, "enabling connected mode " |
| 491 | "will cause multicast packet drops\n"); |
| 492 | netdev_update_features(dev); |
Erez Shitrit | edcd2a7 | 2015-06-07 13:36:11 +0300 | [diff] [blame] | 493 | dev_set_mtu(dev, ipoib_cm_max_mtu(dev)); |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 494 | rtnl_unlock(); |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 495 | priv->tx_wr.wr.send_flags &= ~IB_SEND_IP_CSUM; |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 496 | |
| 497 | ipoib_flush_paths(dev); |
Feras Daoud | 1626076 | 2016-12-28 14:47:23 +0200 | [diff] [blame] | 498 | return (!rtnl_trylock()) ? -EBUSY : 0; |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | if (!strcmp(buf, "datagram\n")) { |
| 502 | clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags); |
| 503 | netdev_update_features(dev); |
| 504 | dev_set_mtu(dev, min(priv->mcast_mtu, dev->mtu)); |
| 505 | rtnl_unlock(); |
| 506 | ipoib_flush_paths(dev); |
Feras Daoud | 1626076 | 2016-12-28 14:47:23 +0200 | [diff] [blame] | 507 | return (!rtnl_trylock()) ? -EBUSY : 0; |
Roland Dreier | 71d9c5f | 2012-10-02 21:23:43 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | |
Erez Shitrit | 546481c | 2016-08-28 10:58:31 +0300 | [diff] [blame] | 513 | struct ipoib_path *__path_find(struct net_device *dev, void *gid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
| 515 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 516 | struct rb_node *n = priv->path_tree.rb_node; |
| 517 | struct ipoib_path *path; |
| 518 | int ret; |
| 519 | |
| 520 | while (n) { |
| 521 | path = rb_entry(n, struct ipoib_path, rb_node); |
| 522 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 523 | ret = memcmp(gid, path->pathrec.dgid.raw, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | sizeof (union ib_gid)); |
| 525 | |
| 526 | if (ret < 0) |
| 527 | n = n->rb_left; |
| 528 | else if (ret > 0) |
| 529 | n = n->rb_right; |
| 530 | else |
| 531 | return path; |
| 532 | } |
| 533 | |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | static int __path_add(struct net_device *dev, struct ipoib_path *path) |
| 538 | { |
| 539 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 540 | struct rb_node **n = &priv->path_tree.rb_node; |
| 541 | struct rb_node *pn = NULL; |
| 542 | struct ipoib_path *tpath; |
| 543 | int ret; |
| 544 | |
| 545 | while (*n) { |
| 546 | pn = *n; |
| 547 | tpath = rb_entry(pn, struct ipoib_path, rb_node); |
| 548 | |
| 549 | ret = memcmp(path->pathrec.dgid.raw, tpath->pathrec.dgid.raw, |
| 550 | sizeof (union ib_gid)); |
| 551 | if (ret < 0) |
| 552 | n = &pn->rb_left; |
| 553 | else if (ret > 0) |
| 554 | n = &pn->rb_right; |
| 555 | else |
| 556 | return -EEXIST; |
| 557 | } |
| 558 | |
| 559 | rb_link_node(&path->rb_node, pn, n); |
| 560 | rb_insert_color(&path->rb_node, &priv->path_tree); |
| 561 | |
| 562 | list_add_tail(&path->list, &priv->path_list); |
| 563 | |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static void path_free(struct net_device *dev, struct ipoib_path *path) |
| 568 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | while ((skb = __skb_dequeue(&path->queue))) |
| 572 | dev_kfree_skb_irq(skb); |
| 573 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 574 | ipoib_dbg(netdev_priv(dev), "path_free\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 576 | /* remove all neigh connected to this path */ |
| 577 | ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | if (path->ah) |
| 580 | ipoib_put_ah(path->ah); |
| 581 | |
| 582 | kfree(path); |
| 583 | } |
| 584 | |
Roland Dreier | 1732b0e | 2005-11-07 10:33:11 -0800 | [diff] [blame] | 585 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 586 | |
| 587 | struct ipoib_path_iter *ipoib_path_iter_init(struct net_device *dev) |
| 588 | { |
| 589 | struct ipoib_path_iter *iter; |
| 590 | |
| 591 | iter = kmalloc(sizeof *iter, GFP_KERNEL); |
| 592 | if (!iter) |
| 593 | return NULL; |
| 594 | |
| 595 | iter->dev = dev; |
| 596 | memset(iter->path.pathrec.dgid.raw, 0, 16); |
| 597 | |
| 598 | if (ipoib_path_iter_next(iter)) { |
| 599 | kfree(iter); |
| 600 | return NULL; |
| 601 | } |
| 602 | |
| 603 | return iter; |
| 604 | } |
| 605 | |
| 606 | int ipoib_path_iter_next(struct ipoib_path_iter *iter) |
| 607 | { |
| 608 | struct ipoib_dev_priv *priv = netdev_priv(iter->dev); |
| 609 | struct rb_node *n; |
| 610 | struct ipoib_path *path; |
| 611 | int ret = 1; |
| 612 | |
| 613 | spin_lock_irq(&priv->lock); |
| 614 | |
| 615 | n = rb_first(&priv->path_tree); |
| 616 | |
| 617 | while (n) { |
| 618 | path = rb_entry(n, struct ipoib_path, rb_node); |
| 619 | |
| 620 | if (memcmp(iter->path.pathrec.dgid.raw, path->pathrec.dgid.raw, |
| 621 | sizeof (union ib_gid)) < 0) { |
| 622 | iter->path = *path; |
| 623 | ret = 0; |
| 624 | break; |
| 625 | } |
| 626 | |
| 627 | n = rb_next(n); |
| 628 | } |
| 629 | |
| 630 | spin_unlock_irq(&priv->lock); |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | void ipoib_path_iter_read(struct ipoib_path_iter *iter, |
| 636 | struct ipoib_path *path) |
| 637 | { |
| 638 | *path = iter->path; |
| 639 | } |
| 640 | |
| 641 | #endif /* CONFIG_INFINIBAND_IPOIB_DEBUG */ |
| 642 | |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 643 | void ipoib_mark_paths_invalid(struct net_device *dev) |
| 644 | { |
| 645 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 646 | struct ipoib_path *path, *tp; |
| 647 | |
| 648 | spin_lock_irq(&priv->lock); |
| 649 | |
| 650 | list_for_each_entry_safe(path, tp, &priv->path_list, list) { |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 651 | ipoib_dbg(priv, "mark path LID 0x%04x GID %pI6 invalid\n", |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 652 | be16_to_cpu(path->pathrec.dlid), |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 653 | path->pathrec.dgid.raw); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 654 | path->valid = 0; |
| 655 | } |
| 656 | |
| 657 | spin_unlock_irq(&priv->lock); |
| 658 | } |
| 659 | |
Erez Shitrit | 3b56113 | 2016-05-25 22:02:07 +0300 | [diff] [blame] | 660 | struct classport_info_context { |
| 661 | struct ipoib_dev_priv *priv; |
| 662 | struct completion done; |
| 663 | struct ib_sa_query *sa_query; |
| 664 | }; |
| 665 | |
| 666 | static void classport_info_query_cb(int status, struct ib_class_port_info *rec, |
| 667 | void *context) |
| 668 | { |
| 669 | struct classport_info_context *cb_ctx = context; |
| 670 | struct ipoib_dev_priv *priv; |
| 671 | |
| 672 | WARN_ON(!context); |
| 673 | |
| 674 | priv = cb_ctx->priv; |
| 675 | |
| 676 | if (status || !rec) { |
| 677 | pr_debug("device: %s failed query classport_info status: %d\n", |
| 678 | priv->dev->name, status); |
| 679 | /* keeps the default, will try next mcast_restart */ |
| 680 | priv->sm_fullmember_sendonly_support = false; |
| 681 | goto out; |
| 682 | } |
| 683 | |
| 684 | if (ib_get_cpi_capmask2(rec) & |
| 685 | IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT) { |
| 686 | pr_debug("device: %s enabled fullmember-sendonly for sendonly MCG\n", |
| 687 | priv->dev->name); |
| 688 | priv->sm_fullmember_sendonly_support = true; |
| 689 | } else { |
| 690 | pr_debug("device: %s disabled fullmember-sendonly for sendonly MCG\n", |
| 691 | priv->dev->name); |
| 692 | priv->sm_fullmember_sendonly_support = false; |
| 693 | } |
| 694 | |
| 695 | out: |
| 696 | complete(&cb_ctx->done); |
| 697 | } |
| 698 | |
| 699 | int ipoib_check_sm_sendonly_fullmember_support(struct ipoib_dev_priv *priv) |
| 700 | { |
| 701 | struct classport_info_context *callback_context; |
| 702 | int ret; |
| 703 | |
| 704 | callback_context = kmalloc(sizeof(*callback_context), GFP_KERNEL); |
| 705 | if (!callback_context) |
| 706 | return -ENOMEM; |
| 707 | |
| 708 | callback_context->priv = priv; |
| 709 | init_completion(&callback_context->done); |
| 710 | |
| 711 | ret = ib_sa_classport_info_rec_query(&ipoib_sa_client, |
| 712 | priv->ca, priv->port, 3000, |
| 713 | GFP_KERNEL, |
| 714 | classport_info_query_cb, |
| 715 | callback_context, |
| 716 | &callback_context->sa_query); |
| 717 | if (ret < 0) { |
| 718 | pr_info("%s failed to send ib_sa_classport_info query, ret: %d\n", |
| 719 | priv->dev->name, ret); |
| 720 | kfree(callback_context); |
| 721 | return ret; |
| 722 | } |
| 723 | |
| 724 | /* waiting for the callback to finish before returnning */ |
| 725 | wait_for_completion(&callback_context->done); |
| 726 | kfree(callback_context); |
| 727 | |
| 728 | return ret; |
| 729 | } |
| 730 | |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 731 | static void push_pseudo_header(struct sk_buff *skb, const char *daddr) |
| 732 | { |
| 733 | struct ipoib_pseudo_header *phdr; |
| 734 | |
| 735 | phdr = (struct ipoib_pseudo_header *)skb_push(skb, sizeof(*phdr)); |
| 736 | memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN); |
| 737 | } |
| 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | void ipoib_flush_paths(struct net_device *dev) |
| 740 | { |
| 741 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 742 | struct ipoib_path *path, *tp; |
| 743 | LIST_HEAD(remove_list); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 744 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 746 | netif_tx_lock_bh(dev); |
| 747 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
Robert P. J. Day | 157de22 | 2008-04-16 21:09:26 -0700 | [diff] [blame] | 749 | list_splice_init(&priv->path_list, &remove_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
| 751 | list_for_each_entry(path, &remove_list, list) |
| 752 | rb_erase(&path->rb_node, &priv->path_tree); |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | list_for_each_entry_safe(path, tp, &remove_list, list) { |
| 755 | if (path->query) |
| 756 | ib_sa_cancel_query(path->query_id, path->query); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 757 | spin_unlock_irqrestore(&priv->lock, flags); |
| 758 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | wait_for_completion(&path->done); |
| 760 | path_free(dev, path); |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 761 | netif_tx_lock_bh(dev); |
| 762 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 764 | |
| 765 | spin_unlock_irqrestore(&priv->lock, flags); |
| 766 | netif_tx_unlock_bh(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static void path_rec_completion(int status, |
| 770 | struct ib_sa_path_rec *pathrec, |
| 771 | void *path_ptr) |
| 772 | { |
| 773 | struct ipoib_path *path = path_ptr; |
| 774 | struct net_device *dev = path->dev; |
| 775 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 776 | struct ipoib_ah *ah = NULL; |
Roland Dreier | c9da4ba | 2008-09-25 15:26:15 -0700 | [diff] [blame] | 777 | struct ipoib_ah *old_ah = NULL; |
Michael S. Tsirkin | d04d01b | 2007-03-22 14:40:16 -0700 | [diff] [blame] | 778 | struct ipoib_neigh *neigh, *tn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | struct sk_buff_head skqueue; |
| 780 | struct sk_buff *skb; |
| 781 | unsigned long flags; |
| 782 | |
Roland Dreier | 843613b | 2007-02-26 12:57:08 -0800 | [diff] [blame] | 783 | if (!status) |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 784 | ipoib_dbg(priv, "PathRec LID 0x%04x for GID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 785 | be16_to_cpu(pathrec->dlid), pathrec->dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | else |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 787 | ipoib_dbg(priv, "PathRec status %d for GID %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 788 | status, path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | skb_queue_head_init(&skqueue); |
| 791 | |
| 792 | if (!status) { |
Sean Hefty | 46f1b3d | 2007-04-05 11:50:11 -0700 | [diff] [blame] | 793 | struct ib_ah_attr av; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
Sean Hefty | 46f1b3d | 2007-04-05 11:50:11 -0700 | [diff] [blame] | 795 | if (!ib_init_ah_from_path(priv->ca, priv->port, pathrec, &av)) |
| 796 | ah = ipoib_create_ah(dev, priv->pd, &av); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | spin_lock_irqsave(&priv->lock, flags); |
| 800 | |
Mike Marciniszyn | 3874397 | 2011-11-21 08:43:54 -0500 | [diff] [blame] | 801 | if (!IS_ERR_OR_NULL(ah)) { |
Erez Shitrit | 15e113d | 2017-11-14 14:51:53 +0200 | [diff] [blame] | 802 | /* |
| 803 | * pathrec.dgid is used as the database key from the LLADDR, |
| 804 | * it must remain unchanged even if the SA returns a different |
| 805 | * GID to use in the AH. |
| 806 | */ |
| 807 | if (memcmp(pathrec->dgid.raw, path->pathrec.dgid.raw, |
| 808 | sizeof(union ib_gid))) { |
| 809 | ipoib_dbg( |
| 810 | priv, |
| 811 | "%s got PathRec for gid %pI6 while asked for %pI6\n", |
| 812 | dev->name, pathrec->dgid.raw, |
| 813 | path->pathrec.dgid.raw); |
| 814 | memcpy(pathrec->dgid.raw, path->pathrec.dgid.raw, |
| 815 | sizeof(union ib_gid)); |
| 816 | } |
| 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | path->pathrec = *pathrec; |
| 819 | |
Roland Dreier | c9da4ba | 2008-09-25 15:26:15 -0700 | [diff] [blame] | 820 | old_ah = path->ah; |
| 821 | path->ah = ah; |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | ipoib_dbg(priv, "created address handle %p for LID 0x%04x, SL %d\n", |
| 824 | ah, be16_to_cpu(pathrec->dlid), pathrec->sl); |
| 825 | |
| 826 | while ((skb = __skb_dequeue(&path->queue))) |
| 827 | __skb_queue_tail(&skqueue, skb); |
| 828 | |
Michael S. Tsirkin | d04d01b | 2007-03-22 14:40:16 -0700 | [diff] [blame] | 829 | list_for_each_entry_safe(neigh, tn, &path->neigh_list, list) { |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 830 | if (neigh->ah) { |
| 831 | WARN_ON(neigh->ah != old_ah); |
| 832 | /* |
| 833 | * Dropping the ah reference inside |
| 834 | * priv->lock is safe here, because we |
| 835 | * will hold one more reference from |
| 836 | * the original value of path->ah (ie |
| 837 | * old_ah). |
| 838 | */ |
| 839 | ipoib_put_ah(neigh->ah); |
| 840 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | kref_get(&path->ah->ref); |
| 842 | neigh->ah = path->ah; |
| 843 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 844 | if (ipoib_cm_enabled(dev, neigh->daddr)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 845 | if (!ipoib_cm_get(neigh)) |
| 846 | ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, |
| 847 | path, |
| 848 | neigh)); |
| 849 | if (!ipoib_cm_get(neigh)) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 850 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 851 | continue; |
| 852 | } |
| 853 | } |
| 854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | while ((skb = __skb_dequeue(&neigh->queue))) |
| 856 | __skb_queue_tail(&skqueue, skb); |
| 857 | } |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 858 | path->valid = 1; |
Roland Dreier | 5872a9f | 2005-11-29 10:13:54 -0800 | [diff] [blame] | 859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Roland Dreier | 5872a9f | 2005-11-29 10:13:54 -0800 | [diff] [blame] | 861 | path->query = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | complete(&path->done); |
| 863 | |
| 864 | spin_unlock_irqrestore(&priv->lock, flags); |
| 865 | |
Roland Dreier | f72dd56 | 2013-02-25 09:42:15 -0800 | [diff] [blame] | 866 | if (IS_ERR_OR_NULL(ah)) |
| 867 | ipoib_del_neighs_by_gid(dev, path->pathrec.dgid.raw); |
| 868 | |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 869 | if (old_ah) |
| 870 | ipoib_put_ah(old_ah); |
| 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | while ((skb = __skb_dequeue(&skqueue))) { |
| 873 | skb->dev = dev; |
| 874 | if (dev_queue_xmit(skb)) |
| 875 | ipoib_warn(priv, "dev_queue_xmit failed " |
| 876 | "to requeue packet\n"); |
| 877 | } |
| 878 | } |
| 879 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 880 | 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] | 881 | { |
| 882 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 883 | struct ipoib_path *path; |
| 884 | |
Jack Morgenstein | 1401b53 | 2007-11-26 10:41:19 +0200 | [diff] [blame] | 885 | if (!priv->broadcast) |
| 886 | return NULL; |
| 887 | |
Roland Dreier | 21a3848 | 2005-11-02 10:07:59 -0800 | [diff] [blame] | 888 | path = kzalloc(sizeof *path, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | if (!path) |
| 890 | return NULL; |
| 891 | |
Roland Dreier | 21a3848 | 2005-11-02 10:07:59 -0800 | [diff] [blame] | 892 | path->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | skb_queue_head_init(&path->queue); |
| 895 | |
| 896 | INIT_LIST_HEAD(&path->neigh_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Jack Morgenstein | 37c22a7 | 2006-05-29 19:14:05 +0300 | [diff] [blame] | 898 | memcpy(path->pathrec.dgid.raw, gid, sizeof (union ib_gid)); |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 899 | path->pathrec.sgid = priv->local_gid; |
| 900 | path->pathrec.pkey = cpu_to_be16(priv->pkey); |
Sean Hefty | 8166883 | 2007-08-02 12:21:31 -0700 | [diff] [blame] | 901 | path->pathrec.numb_path = 1; |
| 902 | path->pathrec.traffic_class = priv->broadcast->mcmember.traffic_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | return path; |
| 905 | } |
| 906 | |
| 907 | static int path_rec_start(struct net_device *dev, |
| 908 | struct ipoib_path *path) |
| 909 | { |
| 910 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 911 | |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 912 | ipoib_dbg(priv, "Start path record lookup for %pI6\n", |
Harvey Harrison | fcace2f | 2008-10-28 22:37:22 -0700 | [diff] [blame] | 913 | path->pathrec.dgid.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Roland Dreier | 65c7edd | 2005-11-28 21:20:34 -0800 | [diff] [blame] | 915 | init_completion(&path->done); |
| 916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | path->query_id = |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 918 | ib_sa_path_rec_get(&ipoib_sa_client, priv->ca, priv->port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | &path->pathrec, |
| 920 | IB_SA_PATH_REC_DGID | |
| 921 | IB_SA_PATH_REC_SGID | |
| 922 | IB_SA_PATH_REC_NUMB_PATH | |
Sean Hefty | 8166883 | 2007-08-02 12:21:31 -0700 | [diff] [blame] | 923 | IB_SA_PATH_REC_TRAFFIC_CLASS | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | IB_SA_PATH_REC_PKEY, |
| 925 | 1000, GFP_ATOMIC, |
| 926 | path_rec_completion, |
| 927 | path, &path->query); |
| 928 | if (path->query_id < 0) { |
Or Gerlitz | 01b3fc8 | 2008-07-22 14:18:34 -0700 | [diff] [blame] | 929 | 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] | 930 | path->query = NULL; |
Yossi Etigin | 93a3ab9 | 2008-11-12 10:24:38 -0800 | [diff] [blame] | 931 | complete(&path->done); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | return path->query_id; |
| 933 | } |
| 934 | |
| 935 | return 0; |
| 936 | } |
| 937 | |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 938 | static struct ipoib_neigh *neigh_add_path(struct sk_buff *skb, u8 *daddr, |
| 939 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
| 941 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 942 | struct ipoib_path *path; |
| 943 | struct ipoib_neigh *neigh; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 944 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 946 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 947 | neigh = ipoib_neigh_alloc(daddr, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | if (!neigh) { |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 949 | spin_unlock_irqrestore(&priv->lock, flags); |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 950 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | dev_kfree_skb_any(skb); |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 952 | return NULL; |
| 953 | } |
| 954 | |
| 955 | /* To avoid race condition, make sure that the |
| 956 | * neigh will be added only once. |
| 957 | */ |
| 958 | if (unlikely(!list_empty(&neigh->list))) { |
| 959 | spin_unlock_irqrestore(&priv->lock, flags); |
| 960 | return neigh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 963 | path = __path_find(dev, daddr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | if (!path) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 965 | path = path_rec_create(dev, daddr + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | if (!path) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 967 | goto err_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
| 969 | __path_add(dev, path); |
| 970 | } |
| 971 | |
| 972 | list_add_tail(&neigh->list, &path->neigh_list); |
| 973 | |
Michael S. Tsirkin | 47f7a07 | 2006-01-17 09:22:05 -0800 | [diff] [blame] | 974 | if (path->ah) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | kref_get(&path->ah->ref); |
| 976 | neigh->ah = path->ah; |
| 977 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 978 | if (ipoib_cm_enabled(dev, neigh->daddr)) { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 979 | if (!ipoib_cm_get(neigh)) |
| 980 | ipoib_cm_set(neigh, ipoib_cm_create_tx(dev, path, neigh)); |
| 981 | if (!ipoib_cm_get(neigh)) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 982 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 983 | goto err_drop; |
| 984 | } |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 985 | if (skb_queue_len(&neigh->queue) < |
| 986 | IPOIB_MAX_PATH_REC_QUEUE) { |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 987 | push_pseudo_header(skb, neigh->daddr); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 988 | __skb_queue_tail(&neigh->queue, skb); |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 989 | } else { |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 990 | ipoib_warn(priv, "queue length limit %d. Packet drop.\n", |
| 991 | skb_queue_len(&neigh->queue)); |
| 992 | goto err_drop; |
| 993 | } |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 994 | } else { |
| 995 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 996 | ipoib_send(dev, skb, path->ah, IPOIB_QPN(daddr)); |
| 997 | ipoib_neigh_put(neigh); |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 998 | return NULL; |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 999 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | } else { |
| 1001 | neigh->ah = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | if (!path->query && path_rec_start(dev, path)) |
Jim Foraker | 49b8e74 | 2013-08-08 17:44:22 -0700 | [diff] [blame] | 1004 | goto err_path; |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1005 | if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
| 1006 | push_pseudo_header(skb, neigh->daddr); |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 1007 | __skb_queue_tail(&neigh->queue, skb); |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1008 | } else { |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 1009 | goto err_drop; |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1013 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1014 | ipoib_neigh_put(neigh); |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 1015 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1017 | err_path: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1018 | ipoib_neigh_free(neigh); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1019 | err_drop: |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 1020 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | dev_kfree_skb_any(skb); |
| 1022 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1023 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1024 | ipoib_neigh_put(neigh); |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 1025 | |
| 1026 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static void unicast_arp_send(struct sk_buff *skb, struct net_device *dev, |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1030 | struct ipoib_pseudo_header *phdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | { |
| 1032 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1033 | struct ipoib_path *path; |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1034 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1036 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1038 | path = __path_find(dev, phdr->hwaddr + 4); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 1039 | if (!path || !path->valid) { |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 1040 | int new_path = 0; |
| 1041 | |
| 1042 | if (!path) { |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1043 | path = path_rec_create(dev, phdr->hwaddr + 4); |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 1044 | new_path = 1; |
| 1045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | if (path) { |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 1047 | if (skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1048 | push_pseudo_header(skb, phdr->hwaddr); |
Erez Shitrit | 1e85b80 | 2015-04-02 13:39:03 +0300 | [diff] [blame] | 1049 | __skb_queue_tail(&path->queue, skb); |
| 1050 | } else { |
| 1051 | ++dev->stats.tx_dropped; |
| 1052 | dev_kfree_skb_any(skb); |
| 1053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
Yossi Etigin | ff79ae8 | 2008-11-12 10:24:39 -0800 | [diff] [blame] | 1055 | if (!path->query && path_rec_start(dev, path)) { |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1056 | spin_unlock_irqrestore(&priv->lock, flags); |
Jack Morgenstein | 71d98b4 | 2009-02-17 14:51:47 -0800 | [diff] [blame] | 1057 | if (new_path) |
| 1058 | path_free(dev, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | return; |
| 1060 | } else |
| 1061 | __path_add(dev, path); |
| 1062 | } else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 1063 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | dev_kfree_skb_any(skb); |
| 1065 | } |
| 1066 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1067 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | return; |
| 1069 | } |
| 1070 | |
Michael S. Tsirkin | 47f7a07 | 2006-01-17 09:22:05 -0800 | [diff] [blame] | 1071 | if (path->ah) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | ipoib_dbg(priv, "Send unicast ARP to %04x\n", |
| 1073 | be16_to_cpu(path->pathrec.dlid)); |
| 1074 | |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 1075 | spin_unlock_irqrestore(&priv->lock, flags); |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1076 | ipoib_send(dev, skb, path->ah, IPOIB_QPN(phdr->hwaddr)); |
Roland Dreier | 721d67c | 2009-09-05 20:23:40 -0700 | [diff] [blame] | 1077 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } else if ((path->query || !path_rec_start(dev, path)) && |
| 1079 | skb_queue_len(&path->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1080 | push_pseudo_header(skb, phdr->hwaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | __skb_queue_tail(&path->queue, skb); |
| 1082 | } else { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 1083 | ++dev->stats.tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | dev_kfree_skb_any(skb); |
| 1085 | } |
| 1086 | |
Roland Dreier | 943c246 | 2008-09-30 10:36:21 -0700 | [diff] [blame] | 1087 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1091 | { |
| 1092 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1093 | struct ipoib_neigh *neigh; |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1094 | struct ipoib_pseudo_header *phdr; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1095 | struct ipoib_header *header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | unsigned long flags; |
| 1097 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1098 | phdr = (struct ipoib_pseudo_header *) skb->data; |
| 1099 | skb_pull(skb, sizeof(*phdr)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1100 | header = (struct ipoib_header *) skb->data; |
| 1101 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1102 | if (unlikely(phdr->hwaddr[4] == 0xff)) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1103 | /* multicast, arrange "if" according to probability */ |
| 1104 | if ((header->proto != htons(ETH_P_IP)) && |
| 1105 | (header->proto != htons(ETH_P_IPV6)) && |
| 1106 | (header->proto != htons(ETH_P_ARP)) && |
Patrick McHardy | dc850b0 | 2013-04-17 06:18:29 +0000 | [diff] [blame] | 1107 | (header->proto != htons(ETH_P_RARP)) && |
| 1108 | (header->proto != htons(ETH_P_TIPC))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1109 | /* ethertype not supported by IPoIB */ |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 1110 | ++dev->stats.tx_dropped; |
| 1111 | dev_kfree_skb_any(skb); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1112 | return NETDEV_TX_OK; |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 1113 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1114 | /* Add in the P_Key for multicast*/ |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1115 | phdr->hwaddr[8] = (priv->pkey >> 8) & 0xff; |
| 1116 | phdr->hwaddr[9] = priv->pkey & 0xff; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1117 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1118 | neigh = ipoib_neigh_get(dev, phdr->hwaddr); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1119 | if (likely(neigh)) |
| 1120 | goto send_using_neigh; |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1121 | ipoib_mcast_send(dev, phdr->hwaddr, skb); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1122 | return NETDEV_TX_OK; |
David Miller | 17e6abe | 2011-12-02 16:52:44 +0000 | [diff] [blame] | 1123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1125 | /* unicast, arrange "switch" according to probability */ |
| 1126 | switch (header->proto) { |
| 1127 | case htons(ETH_P_IP): |
| 1128 | case htons(ETH_P_IPV6): |
Patrick McHardy | dc850b0 | 2013-04-17 06:18:29 +0000 | [diff] [blame] | 1129 | case htons(ETH_P_TIPC): |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1130 | neigh = ipoib_neigh_get(dev, phdr->hwaddr); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1131 | if (unlikely(!neigh)) { |
Erez Shitrit | ab43aaa | 2017-12-31 15:33:15 +0200 | [diff] [blame] | 1132 | neigh = neigh_add_path(skb, phdr->hwaddr, dev); |
| 1133 | if (likely(!neigh)) |
| 1134 | return NETDEV_TX_OK; |
Yossi Etigin | a50df39 | 2009-01-09 14:05:11 -0800 | [diff] [blame] | 1135 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1136 | break; |
| 1137 | case htons(ETH_P_ARP): |
| 1138 | case htons(ETH_P_RARP): |
| 1139 | /* for unicast ARP and RARP should always perform path find */ |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1140 | unicast_arp_send(skb, dev, phdr); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1141 | return NETDEV_TX_OK; |
| 1142 | default: |
| 1143 | /* ethertype not supported by IPoIB */ |
| 1144 | ++dev->stats.tx_dropped; |
| 1145 | dev_kfree_skb_any(skb); |
| 1146 | return NETDEV_TX_OK; |
| 1147 | } |
Michael S. Tsirkin | 8a7f752 | 2006-07-19 17:44:37 +0300 | [diff] [blame] | 1148 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1149 | send_using_neigh: |
| 1150 | /* note we now hold a ref to neigh */ |
| 1151 | if (ipoib_cm_get(neigh)) { |
| 1152 | if (ipoib_cm_up(neigh)) { |
| 1153 | ipoib_cm_send(dev, skb, ipoib_cm_get(neigh)); |
| 1154 | goto unref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1156 | } else if (neigh->ah) { |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1157 | ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(phdr->hwaddr)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1158 | goto unref; |
| 1159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1161 | if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1162 | push_pseudo_header(skb, phdr->hwaddr); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1163 | spin_lock_irqsave(&priv->lock, flags); |
| 1164 | __skb_queue_tail(&neigh->queue, skb); |
| 1165 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | } else { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1167 | ++dev->stats.tx_dropped; |
| 1168 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1170 | |
| 1171 | unref: |
| 1172 | ipoib_neigh_put(neigh); |
| 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | return NETDEV_TX_OK; |
| 1175 | } |
| 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | static void ipoib_timeout(struct net_device *dev) |
| 1178 | { |
| 1179 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1180 | |
Roland Dreier | 4b2d319 | 2005-10-18 12:20:06 -0700 | [diff] [blame] | 1181 | ipoib_warn(priv, "transmit timeout: latency %d msecs\n", |
Florian Westphal | 4d0e965 | 2016-05-03 16:30:59 +0200 | [diff] [blame] | 1182 | jiffies_to_msecs(jiffies - dev_trans_start(dev))); |
Roland Dreier | 4b2d319 | 2005-10-18 12:20:06 -0700 | [diff] [blame] | 1183 | ipoib_warn(priv, "queue stopped %d, tx_head %u, tx_tail %u\n", |
| 1184 | netif_queue_stopped(dev), |
| 1185 | priv->tx_head, priv->tx_tail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | /* XXX reset QP, etc. */ |
| 1187 | } |
| 1188 | |
| 1189 | static int ipoib_hard_header(struct sk_buff *skb, |
| 1190 | struct net_device *dev, |
| 1191 | unsigned short type, |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 1192 | const void *daddr, const void *saddr, unsigned len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | { |
| 1194 | struct ipoib_header *header; |
| 1195 | |
| 1196 | header = (struct ipoib_header *) skb_push(skb, sizeof *header); |
| 1197 | |
| 1198 | header->proto = htons(type); |
| 1199 | header->reserved = 0; |
| 1200 | |
| 1201 | /* |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1202 | * we don't rely on dst_entry structure, always stuff the |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1203 | * destination address into skb hard header so we can figure out where |
Roland Dreier | 936d7de | 2012-02-07 14:51:21 +0000 | [diff] [blame] | 1204 | * to send the packet later. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | */ |
Erez Shitrit | 2e539fa | 2017-02-01 19:10:05 +0200 | [diff] [blame] | 1206 | push_pseudo_header(skb, daddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1208 | return IPOIB_HARD_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | static void ipoib_set_mcast_list(struct net_device *dev) |
| 1212 | { |
| 1213 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1214 | |
Leonid Arsh | 7a343d4 | 2006-03-23 19:52:51 +0200 | [diff] [blame] | 1215 | if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags)) { |
| 1216 | ipoib_dbg(priv, "IPOIB_FLAG_OPER_UP not set"); |
| 1217 | return; |
| 1218 | } |
| 1219 | |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1220 | queue_work(priv->wq, &priv->restart_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 1223 | static int ipoib_get_iflink(const struct net_device *dev) |
| 1224 | { |
| 1225 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1226 | |
Erez Shitrit | 2c15395 | 2015-04-16 16:34:34 +0300 | [diff] [blame] | 1227 | /* parent interface */ |
| 1228 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) |
| 1229 | return dev->ifindex; |
| 1230 | |
| 1231 | /* child/vlan interface */ |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 1232 | return priv->parent->ifindex; |
| 1233 | } |
| 1234 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1235 | static u32 ipoib_addr_hash(struct ipoib_neigh_hash *htbl, u8 *daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1237 | /* |
| 1238 | * Use only the address parts that contributes to spreading |
| 1239 | * The subnet prefix is not used as one can not connect to |
| 1240 | * same remote port (GUID) using the same remote QPN via two |
| 1241 | * different subnets. |
| 1242 | */ |
| 1243 | /* qpn octets[1:4) & port GUID octets[12:20) */ |
Shlomo Pongratz | 9d1ad66 | 2013-02-19 15:40:22 +0000 | [diff] [blame] | 1244 | u32 *d32 = (u32 *) daddr; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1245 | u32 hv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Shlomo Pongratz | 9d1ad66 | 2013-02-19 15:40:22 +0000 | [diff] [blame] | 1247 | hv = jhash_3words(d32[3], d32[4], IPOIB_QPN_MASK & d32[0], 0); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1248 | return hv & htbl->mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1251 | struct ipoib_neigh *ipoib_neigh_get(struct net_device *dev, u8 *daddr) |
| 1252 | { |
| 1253 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1254 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1255 | struct ipoib_neigh_hash *htbl; |
| 1256 | struct ipoib_neigh *neigh = NULL; |
| 1257 | u32 hash_val; |
| 1258 | |
| 1259 | rcu_read_lock_bh(); |
| 1260 | |
| 1261 | htbl = rcu_dereference_bh(ntbl->htbl); |
| 1262 | |
| 1263 | if (!htbl) |
| 1264 | goto out_unlock; |
| 1265 | |
| 1266 | hash_val = ipoib_addr_hash(htbl, daddr); |
| 1267 | for (neigh = rcu_dereference_bh(htbl->buckets[hash_val]); |
| 1268 | neigh != NULL; |
| 1269 | neigh = rcu_dereference_bh(neigh->hnext)) { |
| 1270 | if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) { |
| 1271 | /* found, take one ref on behalf of the caller */ |
| 1272 | if (!atomic_inc_not_zero(&neigh->refcnt)) { |
| 1273 | /* deleted */ |
| 1274 | neigh = NULL; |
| 1275 | goto out_unlock; |
| 1276 | } |
Erez Shitrit | 61c78eea | 2016-06-04 15:15:19 +0300 | [diff] [blame] | 1277 | |
| 1278 | if (likely(skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE)) |
| 1279 | neigh->alive = jiffies; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1280 | goto out_unlock; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | out_unlock: |
| 1285 | rcu_read_unlock_bh(); |
| 1286 | return neigh; |
| 1287 | } |
| 1288 | |
| 1289 | static void __ipoib_reap_neigh(struct ipoib_dev_priv *priv) |
| 1290 | { |
| 1291 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1292 | struct ipoib_neigh_hash *htbl; |
| 1293 | unsigned long neigh_obsolete; |
| 1294 | unsigned long dt; |
| 1295 | unsigned long flags; |
| 1296 | int i; |
Christoph Lameter | bd99b2e | 2015-09-24 12:00:05 -0500 | [diff] [blame] | 1297 | LIST_HEAD(remove_list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1298 | |
| 1299 | if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
| 1300 | return; |
| 1301 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1302 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1303 | |
| 1304 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1305 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1306 | |
| 1307 | if (!htbl) |
| 1308 | goto out_unlock; |
| 1309 | |
| 1310 | /* neigh is obsolete if it was idle for two GC periods */ |
| 1311 | dt = 2 * arp_tbl.gc_interval; |
| 1312 | neigh_obsolete = jiffies - dt; |
| 1313 | /* handle possible race condition */ |
| 1314 | if (test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
| 1315 | goto out_unlock; |
| 1316 | |
| 1317 | for (i = 0; i < htbl->size; i++) { |
| 1318 | struct ipoib_neigh *neigh; |
| 1319 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 1320 | |
| 1321 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1322 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1323 | /* was the neigh idle for two GC periods */ |
| 1324 | if (time_after(neigh_obsolete, neigh->alive)) { |
Christoph Lameter | bd99b2e | 2015-09-24 12:00:05 -0500 | [diff] [blame] | 1325 | |
Christoph Lameter | 432c55f | 2015-12-21 08:42:54 -0600 | [diff] [blame] | 1326 | ipoib_check_and_add_mcast_sendonly(priv, neigh->daddr + 4, &remove_list); |
Christoph Lameter | bd99b2e | 2015-09-24 12:00:05 -0500 | [diff] [blame] | 1327 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1328 | rcu_assign_pointer(*np, |
| 1329 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1330 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1331 | /* remove from path/mc list */ |
Feras Daoud | b2e7d1f | 2016-12-28 14:47:27 +0200 | [diff] [blame] | 1332 | list_del_init(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1333 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 1334 | } else { |
| 1335 | np = &neigh->hnext; |
| 1336 | } |
| 1337 | |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1342 | spin_unlock_irqrestore(&priv->lock, flags); |
Erez Shitrit | 50be28d | 2016-01-07 09:28:08 +0200 | [diff] [blame] | 1343 | ipoib_mcast_remove_list(&remove_list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | static void ipoib_reap_neigh(struct work_struct *work) |
| 1347 | { |
| 1348 | struct ipoib_dev_priv *priv = |
| 1349 | container_of(work, struct ipoib_dev_priv, neigh_reap_task.work); |
| 1350 | |
| 1351 | __ipoib_reap_neigh(priv); |
| 1352 | |
| 1353 | if (!test_bit(IPOIB_STOP_NEIGH_GC, &priv->flags)) |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1354 | queue_delayed_work(priv->wq, &priv->neigh_reap_task, |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1355 | arp_tbl.gc_interval); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | static struct ipoib_neigh *ipoib_neigh_ctor(u8 *daddr, |
Moni Shoua | 732a217 | 2007-10-09 19:43:36 -0700 | [diff] [blame] | 1360 | struct net_device *dev) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1361 | { |
| 1362 | struct ipoib_neigh *neigh; |
| 1363 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1364 | neigh = kzalloc(sizeof *neigh, GFP_ATOMIC); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1365 | if (!neigh) |
| 1366 | return NULL; |
| 1367 | |
Moni Shoua | 732a217 | 2007-10-09 19:43:36 -0700 | [diff] [blame] | 1368 | neigh->dev = dev; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1369 | memcpy(&neigh->daddr, daddr, sizeof(neigh->daddr)); |
Roland Dreier | 82b3991 | 2006-12-12 14:48:18 -0800 | [diff] [blame] | 1370 | skb_queue_head_init(&neigh->queue); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1371 | INIT_LIST_HEAD(&neigh->list); |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1372 | ipoib_cm_set(neigh, NULL); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1373 | /* one ref on behalf of the caller */ |
| 1374 | atomic_set(&neigh->refcnt, 1); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1375 | |
| 1376 | return neigh; |
| 1377 | } |
| 1378 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1379 | struct ipoib_neigh *ipoib_neigh_alloc(u8 *daddr, |
| 1380 | struct net_device *dev) |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1381 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1382 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1383 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1384 | struct ipoib_neigh_hash *htbl; |
| 1385 | struct ipoib_neigh *neigh; |
| 1386 | u32 hash_val; |
| 1387 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1388 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1389 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1390 | if (!htbl) { |
| 1391 | neigh = NULL; |
| 1392 | goto out_unlock; |
| 1393 | } |
| 1394 | |
| 1395 | /* need to add a new neigh, but maybe some other thread succeeded? |
| 1396 | * recalc hash, maybe hash resize took place so we do a search |
| 1397 | */ |
| 1398 | hash_val = ipoib_addr_hash(htbl, daddr); |
| 1399 | for (neigh = rcu_dereference_protected(htbl->buckets[hash_val], |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1400 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1401 | neigh != NULL; |
| 1402 | neigh = rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1403 | lockdep_is_held(&priv->lock))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1404 | if (memcmp(daddr, neigh->daddr, INFINIBAND_ALEN) == 0) { |
| 1405 | /* found, take one ref on behalf of the caller */ |
| 1406 | if (!atomic_inc_not_zero(&neigh->refcnt)) { |
| 1407 | /* deleted */ |
| 1408 | neigh = NULL; |
| 1409 | break; |
| 1410 | } |
| 1411 | neigh->alive = jiffies; |
| 1412 | goto out_unlock; |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | neigh = ipoib_neigh_ctor(daddr, dev); |
| 1417 | if (!neigh) |
| 1418 | goto out_unlock; |
| 1419 | |
| 1420 | /* one ref on behalf of the hash table */ |
| 1421 | atomic_inc(&neigh->refcnt); |
| 1422 | neigh->alive = jiffies; |
| 1423 | /* put in hash */ |
| 1424 | rcu_assign_pointer(neigh->hnext, |
| 1425 | rcu_dereference_protected(htbl->buckets[hash_val], |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1426 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1427 | rcu_assign_pointer(htbl->buckets[hash_val], neigh); |
| 1428 | atomic_inc(&ntbl->entries); |
| 1429 | |
| 1430 | out_unlock: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1431 | |
| 1432 | return neigh; |
| 1433 | } |
| 1434 | |
| 1435 | void ipoib_neigh_dtor(struct ipoib_neigh *neigh) |
| 1436 | { |
| 1437 | /* neigh reference count was dropprd to zero */ |
| 1438 | struct net_device *dev = neigh->dev; |
| 1439 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1440 | struct sk_buff *skb; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1441 | if (neigh->ah) |
| 1442 | ipoib_put_ah(neigh->ah); |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1443 | while ((skb = __skb_dequeue(&neigh->queue))) { |
Roland Dreier | de90351 | 2007-09-28 15:33:51 -0700 | [diff] [blame] | 1444 | ++dev->stats.tx_dropped; |
Michael S. Tsirkin | 2745b5b | 2006-11-16 14:16:47 +0200 | [diff] [blame] | 1445 | dev_kfree_skb_any(skb); |
| 1446 | } |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 1447 | if (ipoib_cm_get(neigh)) |
| 1448 | ipoib_cm_destroy_tx(ipoib_cm_get(neigh)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1449 | ipoib_dbg(netdev_priv(dev), |
| 1450 | "neigh free for %06x %pI6\n", |
| 1451 | IPOIB_QPN(neigh->daddr), |
| 1452 | neigh->daddr + 4); |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1453 | kfree(neigh); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1454 | if (atomic_dec_and_test(&priv->ntbl.entries)) { |
| 1455 | if (test_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags)) |
| 1456 | complete(&priv->ntbl.flushed); |
| 1457 | } |
Michael S. Tsirkin | d2e0655 | 2006-04-04 19:59:40 +0300 | [diff] [blame] | 1458 | } |
| 1459 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1460 | static void ipoib_neigh_reclaim(struct rcu_head *rp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1462 | /* Called as a result of removal from hash table */ |
| 1463 | struct ipoib_neigh *neigh = container_of(rp, struct ipoib_neigh, rcu); |
| 1464 | /* note TX context may hold another ref */ |
| 1465 | ipoib_neigh_put(neigh); |
| 1466 | } |
| 1467 | |
| 1468 | void ipoib_neigh_free(struct ipoib_neigh *neigh) |
| 1469 | { |
| 1470 | struct net_device *dev = neigh->dev; |
| 1471 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1472 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1473 | struct ipoib_neigh_hash *htbl; |
| 1474 | struct ipoib_neigh __rcu **np; |
| 1475 | struct ipoib_neigh *n; |
| 1476 | u32 hash_val; |
| 1477 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1478 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1479 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1480 | if (!htbl) |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1481 | return; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1482 | |
| 1483 | hash_val = ipoib_addr_hash(htbl, neigh->daddr); |
| 1484 | np = &htbl->buckets[hash_val]; |
| 1485 | for (n = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1486 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1487 | n != NULL; |
Shlomo Pongratz | 6c723a6 | 2012-08-13 14:39:50 +0000 | [diff] [blame] | 1488 | n = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1489 | lockdep_is_held(&priv->lock))) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1490 | if (n == neigh) { |
| 1491 | /* found */ |
| 1492 | rcu_assign_pointer(*np, |
| 1493 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1494 | lockdep_is_held(&priv->lock))); |
Jim Foraker | 49b8e74 | 2013-08-08 17:44:22 -0700 | [diff] [blame] | 1495 | /* remove from parent list */ |
Feras Daoud | b2e7d1f | 2016-12-28 14:47:27 +0200 | [diff] [blame] | 1496 | list_del_init(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1497 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1498 | return; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1499 | } else { |
| 1500 | np = &n->hnext; |
| 1501 | } |
| 1502 | } |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | static int ipoib_neigh_hash_init(struct ipoib_dev_priv *priv) |
| 1506 | { |
| 1507 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1508 | struct ipoib_neigh_hash *htbl; |
Bart Van Assche | 5237496 | 2015-05-26 15:03:48 +0200 | [diff] [blame] | 1509 | struct ipoib_neigh __rcu **buckets; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1510 | u32 size; |
| 1511 | |
| 1512 | clear_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); |
| 1513 | ntbl->htbl = NULL; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1514 | htbl = kzalloc(sizeof(*htbl), GFP_KERNEL); |
| 1515 | if (!htbl) |
| 1516 | return -ENOMEM; |
| 1517 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1518 | size = roundup_pow_of_two(arp_tbl.gc_thresh3); |
| 1519 | buckets = kzalloc(size * sizeof(*buckets), GFP_KERNEL); |
| 1520 | if (!buckets) { |
| 1521 | kfree(htbl); |
| 1522 | return -ENOMEM; |
| 1523 | } |
| 1524 | htbl->size = size; |
| 1525 | htbl->mask = (size - 1); |
| 1526 | htbl->buckets = buckets; |
Bart Van Assche | 5237496 | 2015-05-26 15:03:48 +0200 | [diff] [blame] | 1527 | RCU_INIT_POINTER(ntbl->htbl, htbl); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1528 | htbl->ntbl = ntbl; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1529 | atomic_set(&ntbl->entries, 0); |
| 1530 | |
| 1531 | /* start garbage collection */ |
| 1532 | clear_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 1533 | queue_delayed_work(priv->wq, &priv->neigh_reap_task, |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1534 | arp_tbl.gc_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1539 | static void neigh_hash_free_rcu(struct rcu_head *head) |
| 1540 | { |
| 1541 | struct ipoib_neigh_hash *htbl = container_of(head, |
| 1542 | struct ipoib_neigh_hash, |
| 1543 | rcu); |
| 1544 | struct ipoib_neigh __rcu **buckets = htbl->buckets; |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1545 | struct ipoib_neigh_table *ntbl = htbl->ntbl; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1546 | |
| 1547 | kfree(buckets); |
| 1548 | kfree(htbl); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1549 | complete(&ntbl->deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid) |
| 1553 | { |
| 1554 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1555 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1556 | struct ipoib_neigh_hash *htbl; |
| 1557 | unsigned long flags; |
| 1558 | int i; |
| 1559 | |
| 1560 | /* remove all neigh connected to a given path or mcast */ |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1561 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1562 | |
| 1563 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1564 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1565 | |
| 1566 | if (!htbl) |
| 1567 | goto out_unlock; |
| 1568 | |
| 1569 | for (i = 0; i < htbl->size; i++) { |
| 1570 | struct ipoib_neigh *neigh; |
| 1571 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 1572 | |
| 1573 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1574 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1575 | /* delete neighs belong to this parent */ |
| 1576 | if (!memcmp(gid, neigh->daddr + 4, sizeof (union ib_gid))) { |
| 1577 | rcu_assign_pointer(*np, |
| 1578 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1579 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1580 | /* remove from parent list */ |
Feras Daoud | b2e7d1f | 2016-12-28 14:47:27 +0200 | [diff] [blame] | 1581 | list_del_init(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1582 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 1583 | } else { |
| 1584 | np = &neigh->hnext; |
| 1585 | } |
| 1586 | |
| 1587 | } |
| 1588 | } |
| 1589 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1590 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | static void ipoib_flush_neighs(struct ipoib_dev_priv *priv) |
| 1594 | { |
| 1595 | struct ipoib_neigh_table *ntbl = &priv->ntbl; |
| 1596 | struct ipoib_neigh_hash *htbl; |
| 1597 | unsigned long flags; |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1598 | int i, wait_flushed = 0; |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1599 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1600 | init_completion(&priv->ntbl.flushed); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1601 | |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1602 | spin_lock_irqsave(&priv->lock, flags); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1603 | |
| 1604 | htbl = rcu_dereference_protected(ntbl->htbl, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1605 | lockdep_is_held(&priv->lock)); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1606 | if (!htbl) |
| 1607 | goto out_unlock; |
| 1608 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1609 | wait_flushed = atomic_read(&priv->ntbl.entries); |
| 1610 | if (!wait_flushed) |
| 1611 | goto free_htbl; |
| 1612 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1613 | for (i = 0; i < htbl->size; i++) { |
| 1614 | struct ipoib_neigh *neigh; |
| 1615 | struct ipoib_neigh __rcu **np = &htbl->buckets[i]; |
| 1616 | |
| 1617 | while ((neigh = rcu_dereference_protected(*np, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1618 | lockdep_is_held(&priv->lock))) != NULL) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1619 | rcu_assign_pointer(*np, |
| 1620 | rcu_dereference_protected(neigh->hnext, |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1621 | lockdep_is_held(&priv->lock))); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1622 | /* remove from path/mc list */ |
Feras Daoud | b2e7d1f | 2016-12-28 14:47:27 +0200 | [diff] [blame] | 1623 | list_del_init(&neigh->list); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1624 | call_rcu(&neigh->rcu, ipoib_neigh_reclaim); |
| 1625 | } |
| 1626 | } |
| 1627 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1628 | free_htbl: |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1629 | rcu_assign_pointer(ntbl->htbl, NULL); |
| 1630 | call_rcu(&htbl->rcu, neigh_hash_free_rcu); |
| 1631 | |
| 1632 | out_unlock: |
Shlomo Pongratz | b5120a6 | 2012-08-29 15:14:34 +0000 | [diff] [blame] | 1633 | spin_unlock_irqrestore(&priv->lock, flags); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1634 | if (wait_flushed) |
| 1635 | wait_for_completion(&priv->ntbl.flushed); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static void ipoib_neigh_hash_uninit(struct net_device *dev) |
| 1639 | { |
| 1640 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1641 | int stopped; |
| 1642 | |
| 1643 | ipoib_dbg(priv, "ipoib_neigh_hash_uninit\n"); |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1644 | init_completion(&priv->ntbl.deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1645 | set_bit(IPOIB_NEIGH_TBL_FLUSH, &priv->flags); |
| 1646 | |
| 1647 | /* Stop GC if called at init fail need to cancel work */ |
| 1648 | stopped = test_and_set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 1649 | if (!stopped) |
| 1650 | cancel_delayed_work(&priv->neigh_reap_task); |
| 1651 | |
Shlomo Pongratz | 66172c0 | 2012-08-29 15:14:33 +0000 | [diff] [blame] | 1652 | ipoib_flush_neighs(priv); |
| 1653 | |
| 1654 | wait_for_completion(&priv->ntbl.deleted); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port) |
| 1659 | { |
| 1660 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1661 | |
| 1662 | /* Allocate RX/TX "rings" to hold queued skbs */ |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1663 | priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | GFP_KERNEL); |
| 1665 | if (!priv->rx_ring) { |
| 1666 | printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n", |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1667 | ca->name, ipoib_recvq_size); |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1668 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
Joe Perches | 948579c | 2010-11-05 03:07:36 +0000 | [diff] [blame] | 1671 | priv->tx_ring = vzalloc(ipoib_sendq_size * sizeof *priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | if (!priv->tx_ring) { |
| 1673 | printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n", |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 1674 | ca->name, ipoib_sendq_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | goto out_rx_ring_cleanup; |
| 1676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Michael S. Tsirkin | 1b52496 | 2007-08-16 15:36:16 +0300 | [diff] [blame] | 1678 | /* priv->tx_head, tx_tail & tx_outstanding are already 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
| 1680 | if (ipoib_ib_dev_init(dev, ca, port)) |
| 1681 | goto out_tx_ring_cleanup; |
| 1682 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1683 | /* |
| 1684 | * Must be after ipoib_ib_dev_init so we can allocate a per |
| 1685 | * device wq there and use it here |
| 1686 | */ |
| 1687 | if (ipoib_neigh_hash_init(priv) < 0) |
| 1688 | goto out_dev_uninit; |
| 1689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | return 0; |
| 1691 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1692 | out_dev_uninit: |
| 1693 | ipoib_ib_dev_cleanup(dev); |
| 1694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | out_tx_ring_cleanup: |
Roland Dreier | 10313cb | 2008-03-12 07:51:03 -0700 | [diff] [blame] | 1696 | vfree(priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
| 1698 | out_rx_ring_cleanup: |
| 1699 | kfree(priv->rx_ring); |
| 1700 | |
| 1701 | out: |
| 1702 | return -ENOMEM; |
| 1703 | } |
| 1704 | |
| 1705 | void ipoib_dev_cleanup(struct net_device *dev) |
| 1706 | { |
| 1707 | struct ipoib_dev_priv *priv = netdev_priv(dev), *cpriv, *tcpriv; |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1708 | LIST_HEAD(head); |
| 1709 | |
| 1710 | ASSERT_RTNL(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | /* Delete any child interfaces first */ |
| 1713 | list_for_each_entry_safe(cpriv, tcpriv, &priv->child_intfs, list) { |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1714 | /* Stop GC on child */ |
| 1715 | set_bit(IPOIB_STOP_NEIGH_GC, &cpriv->flags); |
| 1716 | cancel_delayed_work(&cpriv->neigh_reap_task); |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1717 | unregister_netdevice_queue(cpriv->dev, &head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | } |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1719 | unregister_netdevice_many(&head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | |
Doug Ledford | be7aa66 | 2015-02-21 19:27:00 -0500 | [diff] [blame] | 1721 | /* |
| 1722 | * Must be before ipoib_ib_dev_cleanup or we delete an in use |
| 1723 | * work queue |
| 1724 | */ |
| 1725 | ipoib_neigh_hash_uninit(dev); |
| 1726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | ipoib_ib_dev_cleanup(dev); |
| 1728 | |
Hal Rosenstock | 92a6b34 | 2005-08-13 20:50:27 -0700 | [diff] [blame] | 1729 | kfree(priv->rx_ring); |
Roland Dreier | 10313cb | 2008-03-12 07:51:03 -0700 | [diff] [blame] | 1730 | vfree(priv->tx_ring); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | |
Hal Rosenstock | 92a6b34 | 2005-08-13 20:50:27 -0700 | [diff] [blame] | 1732 | priv->rx_ring = NULL; |
| 1733 | priv->tx_ring = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Eli Cohen | 9c3c5f8 | 2016-03-11 22:58:39 +0200 | [diff] [blame] | 1736 | static int ipoib_set_vf_link_state(struct net_device *dev, int vf, int link_state) |
| 1737 | { |
| 1738 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1739 | |
| 1740 | return ib_set_vf_link_state(priv->ca, vf, priv->port, link_state); |
| 1741 | } |
| 1742 | |
| 1743 | static int ipoib_get_vf_config(struct net_device *dev, int vf, |
| 1744 | struct ifla_vf_info *ivf) |
| 1745 | { |
| 1746 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1747 | int err; |
| 1748 | |
| 1749 | err = ib_get_vf_config(priv->ca, vf, priv->port, ivf); |
| 1750 | if (err) |
| 1751 | return err; |
| 1752 | |
| 1753 | ivf->vf = vf; |
| 1754 | |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | static int ipoib_set_vf_guid(struct net_device *dev, int vf, u64 guid, int type) |
| 1759 | { |
| 1760 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1761 | |
| 1762 | if (type != IFLA_VF_IB_NODE_GUID && type != IFLA_VF_IB_PORT_GUID) |
| 1763 | return -EINVAL; |
| 1764 | |
| 1765 | return ib_set_vf_guid(priv->ca, vf, priv->port, guid, type); |
| 1766 | } |
| 1767 | |
| 1768 | static int ipoib_get_vf_stats(struct net_device *dev, int vf, |
| 1769 | struct ifla_vf_stats *vf_stats) |
| 1770 | { |
| 1771 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1772 | |
| 1773 | return ib_get_vf_stats(priv->ca, vf, priv->port, vf_stats); |
| 1774 | } |
| 1775 | |
Stephen Hemminger | 3b04ddd | 2007-10-09 01:40:57 -0700 | [diff] [blame] | 1776 | static const struct header_ops ipoib_header_ops = { |
| 1777 | .create = ipoib_hard_header, |
| 1778 | }; |
| 1779 | |
Eli Cohen | 9c3c5f8 | 2016-03-11 22:58:39 +0200 | [diff] [blame] | 1780 | static const struct net_device_ops ipoib_netdev_ops_pf = { |
| 1781 | .ndo_uninit = ipoib_uninit, |
| 1782 | .ndo_open = ipoib_open, |
| 1783 | .ndo_stop = ipoib_stop, |
| 1784 | .ndo_change_mtu = ipoib_change_mtu, |
| 1785 | .ndo_fix_features = ipoib_fix_features, |
| 1786 | .ndo_start_xmit = ipoib_start_xmit, |
| 1787 | .ndo_tx_timeout = ipoib_timeout, |
| 1788 | .ndo_set_rx_mode = ipoib_set_mcast_list, |
| 1789 | .ndo_get_iflink = ipoib_get_iflink, |
| 1790 | .ndo_set_vf_link_state = ipoib_set_vf_link_state, |
| 1791 | .ndo_get_vf_config = ipoib_get_vf_config, |
| 1792 | .ndo_get_vf_stats = ipoib_get_vf_stats, |
| 1793 | .ndo_set_vf_guid = ipoib_set_vf_guid, |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1794 | .ndo_set_mac_address = ipoib_set_mac, |
Eli Cohen | 9c3c5f8 | 2016-03-11 22:58:39 +0200 | [diff] [blame] | 1795 | }; |
| 1796 | |
| 1797 | static const struct net_device_ops ipoib_netdev_ops_vf = { |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1798 | .ndo_uninit = ipoib_uninit, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1799 | .ndo_open = ipoib_open, |
| 1800 | .ndo_stop = ipoib_stop, |
| 1801 | .ndo_change_mtu = ipoib_change_mtu, |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 1802 | .ndo_fix_features = ipoib_fix_features, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1803 | .ndo_start_xmit = ipoib_start_xmit, |
| 1804 | .ndo_tx_timeout = ipoib_timeout, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 1805 | .ndo_set_rx_mode = ipoib_set_mcast_list, |
Nicolas Dichtel | 5aa7add | 2015-04-02 17:07:07 +0200 | [diff] [blame] | 1806 | .ndo_get_iflink = ipoib_get_iflink, |
Stephen Hemminger | fe8114e | 2009-03-20 19:35:32 +0000 | [diff] [blame] | 1807 | }; |
| 1808 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 1809 | void ipoib_setup(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | { |
| 1811 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1812 | |
Eli Cohen | 9c3c5f8 | 2016-03-11 22:58:39 +0200 | [diff] [blame] | 1813 | if (priv->hca_caps & IB_DEVICE_VIRTUAL_FUNCTION) |
| 1814 | dev->netdev_ops = &ipoib_netdev_ops_vf; |
| 1815 | else |
| 1816 | dev->netdev_ops = &ipoib_netdev_ops_pf; |
| 1817 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1818 | dev->header_ops = &ipoib_header_ops; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1819 | |
Eli Cohen | 82c24c1 | 2008-04-16 21:09:32 -0700 | [diff] [blame] | 1820 | ipoib_set_ethtool_ops(dev); |
| 1821 | |
Michal Schmidt | 7f1a386 | 2013-08-21 18:50:22 +0200 | [diff] [blame] | 1822 | netif_napi_add(dev, &priv->napi, ipoib_poll, NAPI_POLL_WEIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1824 | dev->watchdog_timeo = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1826 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | |
Paolo Abeni | fc791b6 | 2016-10-13 18:26:56 +0200 | [diff] [blame] | 1828 | dev->hard_header_len = IPOIB_HARD_LEN; |
Roland Dreier | 2337f80 | 2007-10-23 19:57:54 -0700 | [diff] [blame] | 1829 | dev->addr_len = INFINIBAND_ALEN; |
| 1830 | dev->type = ARPHRD_INFINIBAND; |
| 1831 | dev->tx_queue_len = ipoib_sendq_size * 2; |
Eli Cohen | eb14032f | 2008-01-30 18:30:46 +0200 | [diff] [blame] | 1832 | dev->features = (NETIF_F_VLAN_CHALLENGED | |
Eli Cohen | eb14032f | 2008-01-30 18:30:46 +0200 | [diff] [blame] | 1833 | NETIF_F_HIGHDMA); |
Eric Dumazet | 0287587 | 2014-10-05 18:38:35 -0700 | [diff] [blame] | 1834 | netif_keep_dst(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN); |
| 1837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | priv->dev = dev; |
| 1839 | |
| 1840 | spin_lock_init(&priv->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
Erez Shitrit | f47944c | 2013-10-16 17:37:49 +0300 | [diff] [blame] | 1842 | init_rwsem(&priv->vlan_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
| 1844 | INIT_LIST_HEAD(&priv->path_list); |
| 1845 | INIT_LIST_HEAD(&priv->child_intfs); |
| 1846 | INIT_LIST_HEAD(&priv->dead_ahs); |
| 1847 | INIT_LIST_HEAD(&priv->multicast_list); |
| 1848 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1849 | INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task); |
Yossi Etigin | e8224e4 | 2008-09-16 11:57:45 -0700 | [diff] [blame] | 1850 | INIT_WORK(&priv->carrier_on_task, ipoib_mcast_carrier_on_task); |
Moni Shoua | ee1e2c8 | 2008-07-14 23:48:49 -0700 | [diff] [blame] | 1851 | INIT_WORK(&priv->flush_light, ipoib_ib_dev_flush_light); |
| 1852 | INIT_WORK(&priv->flush_normal, ipoib_ib_dev_flush_normal); |
| 1853 | INIT_WORK(&priv->flush_heavy, ipoib_ib_dev_flush_heavy); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1854 | INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task); |
| 1855 | INIT_DELAYED_WORK(&priv->ah_reap_task, ipoib_reap_ah); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 1856 | INIT_DELAYED_WORK(&priv->neigh_reap_task, ipoib_reap_neigh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | struct ipoib_dev_priv *ipoib_intf_alloc(const char *name) |
| 1860 | { |
| 1861 | struct net_device *dev; |
| 1862 | |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 1863 | dev = alloc_netdev((int)sizeof(struct ipoib_dev_priv), name, |
| 1864 | NET_NAME_UNKNOWN, ipoib_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | if (!dev) |
| 1866 | return NULL; |
| 1867 | |
| 1868 | return netdev_priv(dev); |
| 1869 | } |
| 1870 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1871 | static ssize_t show_pkey(struct device *dev, |
| 1872 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1874 | struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
| 1876 | return sprintf(buf, "0x%04x\n", priv->pkey); |
| 1877 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1878 | static DEVICE_ATTR(pkey, S_IRUGO, show_pkey, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1880 | static ssize_t show_umcast(struct device *dev, |
| 1881 | struct device_attribute *attr, char *buf) |
| 1882 | { |
| 1883 | struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(dev)); |
| 1884 | |
| 1885 | return sprintf(buf, "%d\n", test_bit(IPOIB_FLAG_UMCAST, &priv->flags)); |
| 1886 | } |
| 1887 | |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1888 | void ipoib_set_umcast(struct net_device *ndev, int umcast_val) |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1889 | { |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1890 | struct ipoib_dev_priv *priv = netdev_priv(ndev); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1891 | |
| 1892 | if (umcast_val > 0) { |
| 1893 | set_bit(IPOIB_FLAG_UMCAST, &priv->flags); |
| 1894 | ipoib_warn(priv, "ignoring multicast groups joined directly " |
| 1895 | "by userspace\n"); |
| 1896 | } else |
| 1897 | clear_bit(IPOIB_FLAG_UMCAST, &priv->flags); |
Or Gerlitz | 862096a | 2012-09-27 12:06:02 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | static ssize_t set_umcast(struct device *dev, |
| 1901 | struct device_attribute *attr, |
| 1902 | const char *buf, size_t count) |
| 1903 | { |
| 1904 | unsigned long umcast_val = simple_strtoul(buf, NULL, 0); |
| 1905 | |
| 1906 | ipoib_set_umcast(to_net_dev(dev), umcast_val); |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 1907 | |
| 1908 | return count; |
| 1909 | } |
| 1910 | static DEVICE_ATTR(umcast, S_IWUSR | S_IRUGO, show_umcast, set_umcast); |
| 1911 | |
| 1912 | int ipoib_add_umcast_attr(struct net_device *dev) |
| 1913 | { |
| 1914 | return device_create_file(&dev->dev, &dev_attr_umcast); |
| 1915 | } |
| 1916 | |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1917 | static void set_base_guid(struct ipoib_dev_priv *priv, union ib_gid *gid) |
| 1918 | { |
| 1919 | struct ipoib_dev_priv *child_priv; |
| 1920 | struct net_device *netdev = priv->dev; |
| 1921 | |
Mark Bloch | 9b29953 | 2016-06-04 15:15:22 +0300 | [diff] [blame] | 1922 | netif_addr_lock_bh(netdev); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1923 | |
| 1924 | memcpy(&priv->local_gid.global.interface_id, |
| 1925 | &gid->global.interface_id, |
| 1926 | sizeof(gid->global.interface_id)); |
| 1927 | memcpy(netdev->dev_addr + 4, &priv->local_gid, sizeof(priv->local_gid)); |
| 1928 | clear_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); |
| 1929 | |
Mark Bloch | 9b29953 | 2016-06-04 15:15:22 +0300 | [diff] [blame] | 1930 | netif_addr_unlock_bh(netdev); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1931 | |
| 1932 | if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { |
| 1933 | down_read(&priv->vlan_rwsem); |
| 1934 | list_for_each_entry(child_priv, &priv->child_intfs, list) |
| 1935 | set_base_guid(child_priv, gid); |
| 1936 | up_read(&priv->vlan_rwsem); |
| 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | static int ipoib_check_lladdr(struct net_device *dev, |
| 1941 | struct sockaddr_storage *ss) |
| 1942 | { |
| 1943 | union ib_gid *gid = (union ib_gid *)(ss->__data + 4); |
| 1944 | int ret = 0; |
| 1945 | |
Mark Bloch | 9b29953 | 2016-06-04 15:15:22 +0300 | [diff] [blame] | 1946 | netif_addr_lock_bh(dev); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1947 | |
| 1948 | /* Make sure the QPN, reserved and subnet prefix match the current |
| 1949 | * lladdr, it also makes sure the lladdr is unicast. |
| 1950 | */ |
| 1951 | if (memcmp(dev->dev_addr, ss->__data, |
| 1952 | 4 + sizeof(gid->global.subnet_prefix)) || |
| 1953 | gid->global.interface_id == 0) |
| 1954 | ret = -EINVAL; |
| 1955 | |
Mark Bloch | 9b29953 | 2016-06-04 15:15:22 +0300 | [diff] [blame] | 1956 | netif_addr_unlock_bh(dev); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 1957 | |
| 1958 | return ret; |
| 1959 | } |
| 1960 | |
| 1961 | static int ipoib_set_mac(struct net_device *dev, void *addr) |
| 1962 | { |
| 1963 | struct ipoib_dev_priv *priv = netdev_priv(dev); |
| 1964 | struct sockaddr_storage *ss = addr; |
| 1965 | int ret; |
| 1966 | |
| 1967 | if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) |
| 1968 | return -EBUSY; |
| 1969 | |
| 1970 | ret = ipoib_check_lladdr(dev, ss); |
| 1971 | if (ret) |
| 1972 | return ret; |
| 1973 | |
| 1974 | set_base_guid(priv, (union ib_gid *)(ss->__data + 4)); |
| 1975 | |
| 1976 | queue_work(ipoib_workqueue, &priv->flush_light); |
| 1977 | |
| 1978 | return 0; |
| 1979 | } |
| 1980 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1981 | static ssize_t create_child(struct device *dev, |
| 1982 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | const char *buf, size_t count) |
| 1984 | { |
| 1985 | int pkey; |
| 1986 | int ret; |
| 1987 | |
| 1988 | if (sscanf(buf, "%i", &pkey) != 1) |
| 1989 | return -EINVAL; |
| 1990 | |
Or Gerlitz | 3d790a4 | 2013-07-18 14:02:31 +0300 | [diff] [blame] | 1991 | if (pkey <= 0 || pkey > 0xffff || pkey == 0x8000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | return -EINVAL; |
| 1993 | |
Roland Dreier | 4ce0593 | 2005-08-19 12:03:17 -0700 | [diff] [blame] | 1994 | /* |
| 1995 | * Set the full membership bit, so that we join the right |
| 1996 | * broadcast group, etc. |
| 1997 | */ |
| 1998 | pkey |= 0x8000; |
| 1999 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2000 | ret = ipoib_vlan_add(to_net_dev(dev), pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | |
| 2002 | return ret ? ret : count; |
| 2003 | } |
Or Gerlitz | 7a52b34 | 2010-06-06 04:59:16 +0000 | [diff] [blame] | 2004 | static DEVICE_ATTR(create_child, S_IWUSR, NULL, create_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2006 | static ssize_t delete_child(struct device *dev, |
| 2007 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | const char *buf, size_t count) |
| 2009 | { |
| 2010 | int pkey; |
| 2011 | int ret; |
| 2012 | |
| 2013 | if (sscanf(buf, "%i", &pkey) != 1) |
| 2014 | return -EINVAL; |
| 2015 | |
| 2016 | if (pkey < 0 || pkey > 0xffff) |
| 2017 | return -EINVAL; |
| 2018 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2019 | ret = ipoib_vlan_delete(to_net_dev(dev), pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | |
| 2021 | return ret ? ret : count; |
| 2022 | |
| 2023 | } |
Or Gerlitz | 7a52b34 | 2010-06-06 04:59:16 +0000 | [diff] [blame] | 2024 | static DEVICE_ATTR(delete_child, S_IWUSR, NULL, delete_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
| 2026 | int ipoib_add_pkey_attr(struct net_device *dev) |
| 2027 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2028 | return device_create_file(&dev->dev, &dev_attr_pkey); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 2031 | int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca) |
| 2032 | { |
Or Gerlitz | 4a061b2 | 2015-12-18 10:59:46 +0200 | [diff] [blame] | 2033 | priv->hca_caps = hca->attrs.device_cap_flags; |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 2034 | |
| 2035 | if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) { |
Yuval Shaia | 5faba54 | 2016-07-20 01:30:06 -0700 | [diff] [blame] | 2036 | priv->dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
Michał Mirosław | 3d96c74 | 2011-04-19 00:43:20 +0000 | [diff] [blame] | 2037 | |
| 2038 | if (priv->hca_caps & IB_DEVICE_UD_TSO) |
| 2039 | priv->dev->hw_features |= NETIF_F_TSO; |
| 2040 | |
| 2041 | priv->dev->features |= priv->dev->hw_features; |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Or Gerlitz | 83bb63f | 2008-10-22 15:49:49 -0700 | [diff] [blame] | 2044 | return 0; |
| 2045 | } |
| 2046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | static struct net_device *ipoib_add_port(const char *format, |
| 2048 | struct ib_device *hca, u8 port) |
| 2049 | { |
| 2050 | struct ipoib_dev_priv *priv; |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 2051 | struct ib_port_attr attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | int result = -ENOMEM; |
| 2053 | |
| 2054 | priv = ipoib_intf_alloc(format); |
| 2055 | if (!priv) |
| 2056 | goto alloc_mem_failed; |
| 2057 | |
| 2058 | SET_NETDEV_DEV(priv->dev, hca->dma_device); |
Eli Cohen | c3aa9b1 | 2010-09-20 07:05:06 +0000 | [diff] [blame] | 2059 | priv->dev->dev_id = port - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Amir Vadai | 58e9cc9 | 2015-07-01 14:31:01 +0300 | [diff] [blame] | 2061 | result = ib_query_port(hca, port, &attr); |
| 2062 | if (!result) |
Shirley Ma | bc7b3a3 | 2008-04-23 11:55:45 -0700 | [diff] [blame] | 2063 | priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu); |
| 2064 | else { |
| 2065 | printk(KERN_WARNING "%s: ib_query_port %d failed\n", |
| 2066 | hca->name, port); |
| 2067 | goto device_init_failed; |
| 2068 | } |
| 2069 | |
| 2070 | /* MTU will be reset when mcast join happens */ |
| 2071 | priv->dev->mtu = IPOIB_UD_MTU(priv->max_ib_mtu); |
| 2072 | priv->mcast_mtu = priv->admin_mtu = priv->dev->mtu; |
| 2073 | |
David Miller | 596b9b6 | 2011-07-25 00:01:25 +0000 | [diff] [blame] | 2074 | priv->dev->neigh_priv_len = sizeof(struct ipoib_neigh); |
| 2075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | result = ib_query_pkey(hca, port, 0, &priv->pkey); |
| 2077 | if (result) { |
| 2078 | printk(KERN_WARNING "%s: ib_query_pkey port %d failed (ret = %d)\n", |
| 2079 | hca->name, port, result); |
Eli Cohen | ca6de17 | 2007-08-21 18:46:10 +0300 | [diff] [blame] | 2080 | goto device_init_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Amir Vadai | 58e9cc9 | 2015-07-01 14:31:01 +0300 | [diff] [blame] | 2083 | result = ipoib_set_dev_features(priv, hca); |
| 2084 | if (result) |
Eli Cohen | 6046136 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 2085 | goto device_init_failed; |
Vladimir Sokolovsky | af40da8 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 2086 | |
Roland Dreier | 4ce0593 | 2005-08-19 12:03:17 -0700 | [diff] [blame] | 2087 | /* |
| 2088 | * Set the full membership bit, so that we join the right |
| 2089 | * broadcast group, etc. |
| 2090 | */ |
| 2091 | priv->pkey |= 0x8000; |
| 2092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | priv->dev->broadcast[8] = priv->pkey >> 8; |
| 2094 | priv->dev->broadcast[9] = priv->pkey & 0xff; |
| 2095 | |
Matan Barak | 55ee3ab | 2015-10-15 18:38:45 +0300 | [diff] [blame] | 2096 | result = ib_query_gid(hca, port, 0, &priv->local_gid, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | if (result) { |
| 2098 | printk(KERN_WARNING "%s: ib_query_gid port %d failed (ret = %d)\n", |
| 2099 | hca->name, port, result); |
Eli Cohen | ca6de17 | 2007-08-21 18:46:10 +0300 | [diff] [blame] | 2100 | goto device_init_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | } else |
| 2102 | memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); |
Mark Bloch | 492a7e6 | 2016-05-18 16:42:43 +0300 | [diff] [blame] | 2103 | set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | result = ipoib_dev_init(priv->dev, hca, port); |
| 2106 | if (result < 0) { |
| 2107 | printk(KERN_WARNING "%s: failed to initialize port %d (ret = %d)\n", |
| 2108 | hca->name, port, result); |
| 2109 | goto device_init_failed; |
| 2110 | } |
| 2111 | |
| 2112 | INIT_IB_EVENT_HANDLER(&priv->event_handler, |
| 2113 | priv->ca, ipoib_event); |
| 2114 | result = ib_register_event_handler(&priv->event_handler); |
| 2115 | if (result < 0) { |
| 2116 | printk(KERN_WARNING "%s: ib_register_event_handler failed for " |
| 2117 | "port %d (ret = %d)\n", |
| 2118 | hca->name, port, result); |
| 2119 | goto event_failed; |
| 2120 | } |
| 2121 | |
Alex Estrin | e405d2e | 2018-02-01 10:55:41 -0800 | [diff] [blame] | 2122 | /* call event handler to ensure pkey in sync */ |
| 2123 | queue_work(ipoib_workqueue, &priv->flush_heavy); |
| 2124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | result = register_netdev(priv->dev); |
| 2126 | if (result) { |
| 2127 | printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n", |
| 2128 | hca->name, port, result); |
| 2129 | goto register_failed; |
| 2130 | } |
| 2131 | |
Michael S. Tsirkin | 839fcab | 2007-02-05 22:12:23 +0200 | [diff] [blame] | 2132 | if (ipoib_cm_add_mode_attr(priv->dev)) |
| 2133 | goto sysfs_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | if (ipoib_add_pkey_attr(priv->dev)) |
| 2135 | goto sysfs_failed; |
Or Gerlitz | 335a64a5a | 2007-10-08 10:13:00 +0200 | [diff] [blame] | 2136 | if (ipoib_add_umcast_attr(priv->dev)) |
| 2137 | goto sysfs_failed; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2138 | if (device_create_file(&priv->dev->dev, &dev_attr_create_child)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | goto sysfs_failed; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 2140 | if (device_create_file(&priv->dev->dev, &dev_attr_delete_child)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | goto sysfs_failed; |
| 2142 | |
| 2143 | return priv->dev; |
| 2144 | |
| 2145 | sysfs_failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | unregister_netdev(priv->dev); |
| 2147 | |
| 2148 | register_failed: |
| 2149 | ib_unregister_event_handler(&priv->event_handler); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 2150 | flush_workqueue(ipoib_workqueue); |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 2151 | /* Stop GC if started before flush */ |
| 2152 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 2153 | cancel_delayed_work(&priv->neigh_reap_task); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 2154 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | |
| 2156 | event_failed: |
| 2157 | ipoib_dev_cleanup(priv->dev); |
| 2158 | |
| 2159 | device_init_failed: |
| 2160 | free_netdev(priv->dev); |
| 2161 | |
| 2162 | alloc_mem_failed: |
| 2163 | return ERR_PTR(result); |
| 2164 | } |
| 2165 | |
| 2166 | static void ipoib_add_one(struct ib_device *device) |
| 2167 | { |
| 2168 | struct list_head *dev_list; |
| 2169 | struct net_device *dev; |
| 2170 | struct ipoib_dev_priv *priv; |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 2171 | int p; |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 2172 | int count = 0; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL); |
| 2175 | if (!dev_list) |
| 2176 | return; |
| 2177 | |
| 2178 | INIT_LIST_HEAD(dev_list); |
| 2179 | |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 2180 | for (p = rdma_start_port(device); p <= rdma_end_port(device); ++p) { |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 2181 | if (!rdma_protocol_ib(device, p)) |
Eli Cohen | 7b4c876 | 2010-09-27 17:51:11 -0700 | [diff] [blame] | 2182 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | dev = ipoib_add_port("ib%d", device, p); |
| 2184 | if (!IS_ERR(dev)) { |
| 2185 | priv = netdev_priv(dev); |
| 2186 | list_add_tail(&priv->list, dev_list); |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 2187 | count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | } |
| 2189 | } |
| 2190 | |
Michael Wang | 8e37ab6 | 2015-05-05 14:50:24 +0200 | [diff] [blame] | 2191 | if (!count) { |
| 2192 | kfree(dev_list); |
| 2193 | return; |
| 2194 | } |
| 2195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | ib_set_client_data(device, &ipoib_client, dev_list); |
| 2197 | } |
| 2198 | |
Haggai Eran | 7c1eb45 | 2015-07-30 17:50:14 +0300 | [diff] [blame] | 2199 | static void ipoib_remove_one(struct ib_device *device, void *client_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
| 2201 | struct ipoib_dev_priv *priv, *tmp; |
Haggai Eran | 7c1eb45 | 2015-07-30 17:50:14 +0300 | [diff] [blame] | 2202 | struct list_head *dev_list = client_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | |
Itai Garbi | 5a2815f | 2013-02-19 15:40:24 +0000 | [diff] [blame] | 2204 | if (!dev_list) |
| 2205 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | |
| 2207 | list_for_each_entry_safe(priv, tmp, dev_list, list) { |
| 2208 | ib_unregister_event_handler(&priv->event_handler); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 2209 | flush_workqueue(ipoib_workqueue); |
Roland Dreier | a77a57a | 2008-08-19 15:01:32 -0700 | [diff] [blame] | 2210 | |
Erez Shitrit | 198b12f | 2016-06-04 15:15:20 +0300 | [diff] [blame] | 2211 | /* mark interface in the middle of destruction */ |
| 2212 | set_bit(IPOIB_FLAG_GOING_DOWN, &priv->flags); |
| 2213 | |
Roland Dreier | a77a57a | 2008-08-19 15:01:32 -0700 | [diff] [blame] | 2214 | rtnl_lock(); |
| 2215 | dev_change_flags(priv->dev, priv->dev->flags & ~IFF_UP); |
| 2216 | rtnl_unlock(); |
| 2217 | |
Shlomo Pongratz | b63b70d | 2012-07-24 17:05:22 +0000 | [diff] [blame] | 2218 | /* Stop GC */ |
| 2219 | set_bit(IPOIB_STOP_NEIGH_GC, &priv->flags); |
| 2220 | cancel_delayed_work(&priv->neigh_reap_task); |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 2221 | flush_workqueue(priv->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | |
| 2223 | unregister_netdev(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | free_netdev(priv->dev); |
| 2225 | } |
Michael S. Tsirkin | 06c56e4 | 2005-09-01 09:19:02 -0700 | [diff] [blame] | 2226 | |
| 2227 | kfree(dev_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Shamir Rabinovitch | d20bfe2 | 2017-03-29 06:21:59 -0400 | [diff] [blame] | 2230 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 2231 | static struct notifier_block ipoib_netdev_notifier = { |
| 2232 | .notifier_call = ipoib_netdev_event, |
| 2233 | }; |
| 2234 | #endif |
| 2235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | static int __init ipoib_init_module(void) |
| 2237 | { |
| 2238 | int ret; |
| 2239 | |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 2240 | ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size); |
| 2241 | ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE); |
| 2242 | ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE); |
| 2243 | |
| 2244 | ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size); |
| 2245 | ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE); |
Hagen Paul Pfeifer | 732eacc | 2010-10-26 14:22:23 -0700 | [diff] [blame] | 2246 | 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] | 2247 | #ifdef CONFIG_INFINIBAND_IPOIB_CM |
| 2248 | ipoib_max_conn_qp = min(ipoib_max_conn_qp, IPOIB_CM_MAX_CONN_QP); |
| 2249 | #endif |
Shirley Ma | 0f48525 | 2006-04-10 09:43:58 -0700 | [diff] [blame] | 2250 | |
Eli Cohen | f89271da | 2008-07-14 23:48:44 -0700 | [diff] [blame] | 2251 | /* |
| 2252 | * When copying small received packets, we only copy from the |
| 2253 | * linear data part of the SKB, so we rely on this condition. |
| 2254 | */ |
| 2255 | BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE); |
| 2256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | ret = ipoib_register_debugfs(); |
| 2258 | if (ret) |
| 2259 | return ret; |
| 2260 | |
| 2261 | /* |
Doug Ledford | 0b39578 | 2015-02-21 19:27:03 -0500 | [diff] [blame] | 2262 | * We create a global workqueue here that is used for all flush |
| 2263 | * operations. However, if you attempt to flush a workqueue |
| 2264 | * from a task on that same workqueue, it deadlocks the system. |
| 2265 | * We want to be able to flush the tasks associated with a |
| 2266 | * specific net device, so we also create a workqueue for each |
| 2267 | * netdevice. We queue up the tasks for that device only on |
| 2268 | * its private workqueue, and we only queue up flush events |
| 2269 | * on our global flush workqueue. This avoids the deadlocks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | */ |
Bhaktipriya Shridhar | 855cda6 | 2016-08-15 23:44:26 +0530 | [diff] [blame] | 2271 | ipoib_workqueue = alloc_ordered_workqueue("ipoib_flush", |
| 2272 | WQ_MEM_RECLAIM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | if (!ipoib_workqueue) { |
| 2274 | ret = -ENOMEM; |
| 2275 | goto err_fs; |
| 2276 | } |
| 2277 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 2278 | ib_sa_register_client(&ipoib_sa_client); |
| 2279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | ret = ib_register_client(&ipoib_client); |
| 2281 | if (ret) |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 2282 | goto err_sa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 2284 | ret = ipoib_netlink_init(); |
| 2285 | if (ret) |
| 2286 | goto err_client; |
| 2287 | |
Shamir Rabinovitch | d20bfe2 | 2017-03-29 06:21:59 -0400 | [diff] [blame] | 2288 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 2289 | register_netdevice_notifier(&ipoib_netdev_notifier); |
| 2290 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | return 0; |
| 2292 | |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 2293 | err_client: |
| 2294 | ib_unregister_client(&ipoib_client); |
| 2295 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 2296 | err_sa: |
| 2297 | ib_sa_unregister_client(&ipoib_sa_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | destroy_workqueue(ipoib_workqueue); |
| 2299 | |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 2300 | err_fs: |
| 2301 | ipoib_unregister_debugfs(); |
| 2302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | return ret; |
| 2304 | } |
| 2305 | |
| 2306 | static void __exit ipoib_cleanup_module(void) |
| 2307 | { |
Shamir Rabinovitch | d20bfe2 | 2017-03-29 06:21:59 -0400 | [diff] [blame] | 2308 | #ifdef CONFIG_INFINIBAND_IPOIB_DEBUG |
| 2309 | unregister_netdevice_notifier(&ipoib_netdev_notifier); |
| 2310 | #endif |
Or Gerlitz | 9baa0b0 | 2012-09-13 05:56:36 +0000 | [diff] [blame] | 2311 | ipoib_netlink_fini(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | ib_unregister_client(&ipoib_client); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 2313 | ib_sa_unregister_client(&ipoib_sa_client); |
Roland Dreier | 9adec1a | 2005-04-16 15:26:07 -0700 | [diff] [blame] | 2314 | ipoib_unregister_debugfs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | destroy_workqueue(ipoib_workqueue); |
| 2316 | } |
| 2317 | |
| 2318 | module_init(ipoib_init_module); |
| 2319 | module_exit(ipoib_cleanup_module); |