Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005 Voltaire Inc. All rights reserved. |
| 3 | * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved. |
| 4 | * Copyright (c) 1999-2005, Mellanox Technologies, Inc. All rights reserved. |
| 5 | * Copyright (c) 2005-2006 Intel Corporation. All rights reserved. |
| 6 | * |
Sean Hefty | a947491 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 7 | * This software is available to you under a choice of one of two |
| 8 | * licenses. You may choose to be licensed under the terms of the GNU |
| 9 | * General Public License (GPL) Version 2, available from the file |
| 10 | * COPYING in the main directory of this source tree, or the |
| 11 | * OpenIB.org BSD license below: |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 12 | * |
Sean Hefty | a947491 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 13 | * Redistribution and use in source and binary forms, with or |
| 14 | * without modification, are permitted provided that the following |
| 15 | * conditions are met: |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 16 | * |
Sean Hefty | a947491 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 17 | * - Redistributions of source code must retain the above |
| 18 | * copyright notice, this list of conditions and the following |
| 19 | * disclaimer. |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 20 | * |
Sean Hefty | a947491 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 21 | * - Redistributions in binary form must reproduce the above |
| 22 | * copyright notice, this list of conditions and the following |
| 23 | * disclaimer in the documentation and/or other materials |
| 24 | * provided with the distribution. |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 25 | * |
Sean Hefty | a947491 | 2008-07-14 23:48:43 -0700 | [diff] [blame] | 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 27 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 29 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 30 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 31 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 32 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 33 | * SOFTWARE. |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #include <linux/completion.h> |
| 37 | #include <linux/in.h> |
| 38 | #include <linux/in6.h> |
| 39 | #include <linux/mutex.h> |
| 40 | #include <linux/random.h> |
| 41 | #include <linux/idr.h> |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 42 | #include <linux/inetdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Paul Gortmaker | e4dd23d | 2011-05-27 15:35:46 -0400 | [diff] [blame] | 44 | #include <linux/module.h> |
Amir Vadai | 366cddb | 2012-04-04 21:33:29 +0000 | [diff] [blame] | 45 | #include <net/route.h> |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 46 | |
| 47 | #include <net/tcp.h> |
Aleksey Senin | 1f5175a | 2008-12-24 10:16:45 -0800 | [diff] [blame] | 48 | #include <net/ipv6.h> |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 49 | |
| 50 | #include <rdma/rdma_cm.h> |
| 51 | #include <rdma/rdma_cm_ib.h> |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 52 | #include <rdma/rdma_netlink.h> |
Sean Hefty | 2e2d190 | 2013-05-29 10:09:09 -0700 | [diff] [blame] | 53 | #include <rdma/ib.h> |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 54 | #include <rdma/ib_cache.h> |
| 55 | #include <rdma/ib_cm.h> |
| 56 | #include <rdma/ib_sa.h> |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 57 | #include <rdma/iw_cm.h> |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 58 | |
| 59 | MODULE_AUTHOR("Sean Hefty"); |
| 60 | MODULE_DESCRIPTION("Generic RDMA CM Agent"); |
| 61 | MODULE_LICENSE("Dual BSD/GPL"); |
| 62 | |
| 63 | #define CMA_CM_RESPONSE_TIMEOUT 20 |
Michael S. Tsirkin | d5bb759 | 2006-09-13 15:01:54 +0300 | [diff] [blame] | 64 | #define CMA_MAX_CM_RETRIES 15 |
Sean Hefty | dcb3f97 | 2007-08-01 14:47:16 -0700 | [diff] [blame] | 65 | #define CMA_CM_MRA_SETTING (IB_CM_MRA_FLAG_DELAY | 24) |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 66 | #define CMA_IBOE_PACKET_LIFETIME 18 |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 67 | |
| 68 | static void cma_add_one(struct ib_device *device); |
| 69 | static void cma_remove_one(struct ib_device *device); |
| 70 | |
| 71 | static struct ib_client cma_client = { |
| 72 | .name = "cma", |
| 73 | .add = cma_add_one, |
| 74 | .remove = cma_remove_one |
| 75 | }; |
| 76 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 77 | static struct ib_sa_client sa_client; |
Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 78 | static struct rdma_addr_client addr_client; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 79 | static LIST_HEAD(dev_list); |
| 80 | static LIST_HEAD(listen_any_list); |
| 81 | static DEFINE_MUTEX(lock); |
| 82 | static struct workqueue_struct *cma_wq; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 83 | static DEFINE_IDR(tcp_ps); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 84 | static DEFINE_IDR(udp_ps); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 85 | static DEFINE_IDR(ipoib_ps); |
Sean Hefty | 2d2e941 | 2011-05-28 21:56:39 -0700 | [diff] [blame] | 86 | static DEFINE_IDR(ib_ps); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 87 | |
| 88 | struct cma_device { |
| 89 | struct list_head list; |
| 90 | struct ib_device *device; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 91 | struct completion comp; |
| 92 | atomic_t refcount; |
| 93 | struct list_head id_list; |
| 94 | }; |
| 95 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 96 | struct rdma_bind_list { |
| 97 | struct idr *ps; |
| 98 | struct hlist_head owners; |
| 99 | unsigned short port; |
| 100 | }; |
| 101 | |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 102 | enum { |
| 103 | CMA_OPTION_AFONLY, |
| 104 | }; |
| 105 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 106 | /* |
| 107 | * Device removal can occur at anytime, so we need extra handling to |
| 108 | * serialize notifying the user of device removal with other callbacks. |
| 109 | * We do this by disabling removal notification while a callback is in process, |
| 110 | * and reporting it after the callback completes. |
| 111 | */ |
| 112 | struct rdma_id_private { |
| 113 | struct rdma_cm_id id; |
| 114 | |
| 115 | struct rdma_bind_list *bind_list; |
| 116 | struct hlist_node node; |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 117 | struct list_head list; /* listen_any_list or cma_device.list */ |
| 118 | struct list_head listen_list; /* per device listens */ |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 119 | struct cma_device *cma_dev; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 120 | struct list_head mc_list; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 121 | |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 122 | int internal_id; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 123 | enum rdma_cm_state state; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 124 | spinlock_t lock; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 125 | struct mutex qp_mutex; |
| 126 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 127 | struct completion comp; |
| 128 | atomic_t refcount; |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 129 | struct mutex handler_mutex; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 130 | |
| 131 | int backlog; |
| 132 | int timeout_ms; |
| 133 | struct ib_sa_query *query; |
| 134 | int query_id; |
| 135 | union { |
| 136 | struct ib_cm_id *ib; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 137 | struct iw_cm_id *iw; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 138 | } cm_id; |
| 139 | |
| 140 | u32 seq_num; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 141 | u32 qkey; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 142 | u32 qp_num; |
Nir Muchtar | 83e9502 | 2011-01-13 13:56:04 +0000 | [diff] [blame] | 143 | pid_t owner; |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 144 | u32 options; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 145 | u8 srq; |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 146 | u8 tos; |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 147 | u8 reuseaddr; |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 148 | u8 afonly; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 151 | struct cma_multicast { |
| 152 | struct rdma_id_private *id_priv; |
| 153 | union { |
| 154 | struct ib_sa_multicast *ib; |
| 155 | } multicast; |
| 156 | struct list_head list; |
| 157 | void *context; |
Roland Dreier | 3f44675 | 2008-08-04 11:02:14 -0700 | [diff] [blame] | 158 | struct sockaddr_storage addr; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 159 | struct kref mcref; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 162 | struct cma_work { |
| 163 | struct work_struct work; |
| 164 | struct rdma_id_private *id; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 165 | enum rdma_cm_state old_state; |
| 166 | enum rdma_cm_state new_state; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 167 | struct rdma_cm_event event; |
| 168 | }; |
| 169 | |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 170 | struct cma_ndev_work { |
| 171 | struct work_struct work; |
| 172 | struct rdma_id_private *id; |
| 173 | struct rdma_cm_event event; |
| 174 | }; |
| 175 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 176 | struct iboe_mcast_work { |
| 177 | struct work_struct work; |
| 178 | struct rdma_id_private *id; |
| 179 | struct cma_multicast *mc; |
| 180 | }; |
| 181 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 182 | union cma_ip_addr { |
| 183 | struct in6_addr ip6; |
| 184 | struct { |
Al Viro | 1b90c13 | 2008-03-29 03:10:28 +0000 | [diff] [blame] | 185 | __be32 pad[3]; |
| 186 | __be32 addr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 187 | } ip4; |
| 188 | }; |
| 189 | |
| 190 | struct cma_hdr { |
| 191 | u8 cma_version; |
| 192 | u8 ip_version; /* IP version: 7:4 */ |
Al Viro | 1b90c13 | 2008-03-29 03:10:28 +0000 | [diff] [blame] | 193 | __be16 port; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 194 | union cma_ip_addr src_addr; |
| 195 | union cma_ip_addr dst_addr; |
| 196 | }; |
| 197 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 198 | #define CMA_VERSION 0x00 |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 199 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 200 | static int cma_comp(struct rdma_id_private *id_priv, enum rdma_cm_state comp) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 201 | { |
| 202 | unsigned long flags; |
| 203 | int ret; |
| 204 | |
| 205 | spin_lock_irqsave(&id_priv->lock, flags); |
| 206 | ret = (id_priv->state == comp); |
| 207 | spin_unlock_irqrestore(&id_priv->lock, flags); |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static int cma_comp_exch(struct rdma_id_private *id_priv, |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 212 | enum rdma_cm_state comp, enum rdma_cm_state exch) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 213 | { |
| 214 | unsigned long flags; |
| 215 | int ret; |
| 216 | |
| 217 | spin_lock_irqsave(&id_priv->lock, flags); |
| 218 | if ((ret = (id_priv->state == comp))) |
| 219 | id_priv->state = exch; |
| 220 | spin_unlock_irqrestore(&id_priv->lock, flags); |
| 221 | return ret; |
| 222 | } |
| 223 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 224 | static enum rdma_cm_state cma_exch(struct rdma_id_private *id_priv, |
| 225 | enum rdma_cm_state exch) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 226 | { |
| 227 | unsigned long flags; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 228 | enum rdma_cm_state old; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 229 | |
| 230 | spin_lock_irqsave(&id_priv->lock, flags); |
| 231 | old = id_priv->state; |
| 232 | id_priv->state = exch; |
| 233 | spin_unlock_irqrestore(&id_priv->lock, flags); |
| 234 | return old; |
| 235 | } |
| 236 | |
| 237 | static inline u8 cma_get_ip_ver(struct cma_hdr *hdr) |
| 238 | { |
| 239 | return hdr->ip_version >> 4; |
| 240 | } |
| 241 | |
| 242 | static inline void cma_set_ip_ver(struct cma_hdr *hdr, u8 ip_ver) |
| 243 | { |
| 244 | hdr->ip_version = (ip_ver << 4) | (hdr->ip_version & 0xF); |
| 245 | } |
| 246 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 247 | static void cma_attach_to_dev(struct rdma_id_private *id_priv, |
| 248 | struct cma_device *cma_dev) |
| 249 | { |
| 250 | atomic_inc(&cma_dev->refcount); |
| 251 | id_priv->cma_dev = cma_dev; |
| 252 | id_priv->id.device = cma_dev->device; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 253 | id_priv->id.route.addr.dev_addr.transport = |
| 254 | rdma_node_get_transport(cma_dev->device->node_type); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 255 | list_add_tail(&id_priv->list, &cma_dev->id_list); |
| 256 | } |
| 257 | |
| 258 | static inline void cma_deref_dev(struct cma_device *cma_dev) |
| 259 | { |
| 260 | if (atomic_dec_and_test(&cma_dev->refcount)) |
| 261 | complete(&cma_dev->comp); |
| 262 | } |
| 263 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 264 | static inline void release_mc(struct kref *kref) |
| 265 | { |
| 266 | struct cma_multicast *mc = container_of(kref, struct cma_multicast, mcref); |
| 267 | |
| 268 | kfree(mc->multicast.ib); |
| 269 | kfree(mc); |
| 270 | } |
| 271 | |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 272 | static void cma_release_dev(struct rdma_id_private *id_priv) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 273 | { |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 274 | mutex_lock(&lock); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 275 | list_del(&id_priv->list); |
| 276 | cma_deref_dev(id_priv->cma_dev); |
| 277 | id_priv->cma_dev = NULL; |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 278 | mutex_unlock(&lock); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 281 | static inline struct sockaddr *cma_src_addr(struct rdma_id_private *id_priv) |
| 282 | { |
| 283 | return (struct sockaddr *) &id_priv->id.route.addr.src_addr; |
| 284 | } |
| 285 | |
| 286 | static inline struct sockaddr *cma_dst_addr(struct rdma_id_private *id_priv) |
| 287 | { |
| 288 | return (struct sockaddr *) &id_priv->id.route.addr.dst_addr; |
| 289 | } |
| 290 | |
| 291 | static inline unsigned short cma_family(struct rdma_id_private *id_priv) |
| 292 | { |
| 293 | return id_priv->id.route.addr.src_addr.ss_family; |
| 294 | } |
| 295 | |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 296 | static int cma_set_qkey(struct rdma_id_private *id_priv, u32 qkey) |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 297 | { |
| 298 | struct ib_sa_mcmember_rec rec; |
| 299 | int ret = 0; |
| 300 | |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 301 | if (id_priv->qkey) { |
| 302 | if (qkey && id_priv->qkey != qkey) |
| 303 | return -EINVAL; |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 304 | return 0; |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | if (qkey) { |
| 308 | id_priv->qkey = qkey; |
| 309 | return 0; |
| 310 | } |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 311 | |
| 312 | switch (id_priv->id.ps) { |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 313 | case RDMA_PS_UDP: |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 314 | case RDMA_PS_IB: |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 315 | id_priv->qkey = RDMA_UDP_QKEY; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 316 | break; |
| 317 | case RDMA_PS_IPOIB: |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 318 | ib_addr_get_mgid(&id_priv->id.route.addr.dev_addr, &rec.mgid); |
| 319 | ret = ib_sa_get_mcmember_rec(id_priv->id.device, |
| 320 | id_priv->id.port_num, &rec.mgid, |
| 321 | &rec); |
| 322 | if (!ret) |
| 323 | id_priv->qkey = be32_to_cpu(rec.qkey); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 324 | break; |
| 325 | default: |
| 326 | break; |
| 327 | } |
| 328 | return ret; |
| 329 | } |
| 330 | |
Sean Hefty | 680f920 | 2013-05-29 10:09:12 -0700 | [diff] [blame] | 331 | static void cma_translate_ib(struct sockaddr_ib *sib, struct rdma_dev_addr *dev_addr) |
| 332 | { |
| 333 | dev_addr->dev_type = ARPHRD_INFINIBAND; |
| 334 | rdma_addr_set_sgid(dev_addr, (union ib_gid *) &sib->sib_addr); |
| 335 | ib_addr_set_pkey(dev_addr, ntohs(sib->sib_pkey)); |
| 336 | } |
| 337 | |
| 338 | static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_addr) |
| 339 | { |
| 340 | int ret; |
| 341 | |
| 342 | if (addr->sa_family != AF_IB) { |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 343 | ret = rdma_translate_ip(addr, dev_addr, NULL); |
Sean Hefty | 680f920 | 2013-05-29 10:09:12 -0700 | [diff] [blame] | 344 | } else { |
| 345 | cma_translate_ib((struct sockaddr_ib *) addr, dev_addr); |
| 346 | ret = 0; |
| 347 | } |
| 348 | |
| 349 | return ret; |
| 350 | } |
| 351 | |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 352 | static int cma_acquire_dev(struct rdma_id_private *id_priv, |
| 353 | struct rdma_id_private *listen_id_priv) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 354 | { |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 355 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 356 | struct cma_device *cma_dev; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 357 | union ib_gid gid, iboe_gid; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 358 | int ret = -ENODEV; |
Doug Ledford | 29f27e8 | 2013-09-24 17:16:27 -0400 | [diff] [blame] | 359 | u8 port, found_port; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 360 | enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ? |
| 361 | IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 362 | |
Moni Shoua | 2efdd6a | 2011-07-12 11:23:15 +0000 | [diff] [blame] | 363 | if (dev_ll != IB_LINK_LAYER_INFINIBAND && |
| 364 | id_priv->id.ps == RDMA_PS_IPOIB) |
| 365 | return -EINVAL; |
| 366 | |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 367 | mutex_lock(&lock); |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 368 | rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 369 | &iboe_gid); |
| 370 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 371 | memcpy(&gid, dev_addr->src_dev_addr + |
| 372 | rdma_addr_gid_offset(dev_addr), sizeof gid); |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 373 | if (listen_id_priv && |
| 374 | rdma_port_get_link_layer(listen_id_priv->id.device, |
| 375 | listen_id_priv->id.port_num) == dev_ll) { |
| 376 | cma_dev = listen_id_priv->cma_dev; |
| 377 | port = listen_id_priv->id.port_num; |
| 378 | if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB && |
| 379 | rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET) |
| 380 | ret = ib_find_cached_gid(cma_dev->device, &iboe_gid, |
| 381 | &found_port, NULL); |
| 382 | else |
| 383 | ret = ib_find_cached_gid(cma_dev->device, &gid, |
| 384 | &found_port, NULL); |
| 385 | |
| 386 | if (!ret && (port == found_port)) { |
| 387 | id_priv->id.port_num = found_port; |
| 388 | goto out; |
| 389 | } |
| 390 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 391 | list_for_each_entry(cma_dev, &dev_list, list) { |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 392 | for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) { |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 393 | if (listen_id_priv && |
| 394 | listen_id_priv->cma_dev == cma_dev && |
| 395 | listen_id_priv->id.port_num == port) |
| 396 | continue; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 397 | if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) { |
| 398 | if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB && |
| 399 | rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET) |
Doug Ledford | 29f27e8 | 2013-09-24 17:16:27 -0400 | [diff] [blame] | 400 | ret = ib_find_cached_gid(cma_dev->device, &iboe_gid, &found_port, NULL); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 401 | else |
Doug Ledford | 29f27e8 | 2013-09-24 17:16:27 -0400 | [diff] [blame] | 402 | ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 403 | |
Doug Ledford | 29f27e8 | 2013-09-24 17:16:27 -0400 | [diff] [blame] | 404 | if (!ret && (port == found_port)) { |
| 405 | id_priv->id.port_num = found_port; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 406 | goto out; |
shefty | 63f05be | 2012-11-28 20:39:52 +0000 | [diff] [blame] | 407 | } |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 408 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 411 | |
| 412 | out: |
| 413 | if (!ret) |
| 414 | cma_attach_to_dev(id_priv, cma_dev); |
| 415 | |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 416 | mutex_unlock(&lock); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 417 | return ret; |
| 418 | } |
| 419 | |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 420 | /* |
| 421 | * Select the source IB device and address to reach the destination IB address. |
| 422 | */ |
| 423 | static int cma_resolve_ib_dev(struct rdma_id_private *id_priv) |
| 424 | { |
| 425 | struct cma_device *cma_dev, *cur_dev; |
| 426 | struct sockaddr_ib *addr; |
| 427 | union ib_gid gid, sgid, *dgid; |
| 428 | u16 pkey, index; |
Paul Bolle | 8fb488d7 | 2013-07-24 15:06:07 -0700 | [diff] [blame] | 429 | u8 p; |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 430 | int i; |
| 431 | |
| 432 | cma_dev = NULL; |
| 433 | addr = (struct sockaddr_ib *) cma_dst_addr(id_priv); |
| 434 | dgid = (union ib_gid *) &addr->sib_addr; |
| 435 | pkey = ntohs(addr->sib_pkey); |
| 436 | |
| 437 | list_for_each_entry(cur_dev, &dev_list, list) { |
| 438 | if (rdma_node_get_transport(cur_dev->device->node_type) != RDMA_TRANSPORT_IB) |
| 439 | continue; |
| 440 | |
| 441 | for (p = 1; p <= cur_dev->device->phys_port_cnt; ++p) { |
| 442 | if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index)) |
| 443 | continue; |
| 444 | |
| 445 | for (i = 0; !ib_get_cached_gid(cur_dev->device, p, i, &gid); i++) { |
| 446 | if (!memcmp(&gid, dgid, sizeof(gid))) { |
| 447 | cma_dev = cur_dev; |
| 448 | sgid = gid; |
Paul Bolle | 8fb488d7 | 2013-07-24 15:06:07 -0700 | [diff] [blame] | 449 | id_priv->id.port_num = p; |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 450 | goto found; |
| 451 | } |
| 452 | |
| 453 | if (!cma_dev && (gid.global.subnet_prefix == |
| 454 | dgid->global.subnet_prefix)) { |
| 455 | cma_dev = cur_dev; |
| 456 | sgid = gid; |
Paul Bolle | 8fb488d7 | 2013-07-24 15:06:07 -0700 | [diff] [blame] | 457 | id_priv->id.port_num = p; |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if (!cma_dev) |
| 464 | return -ENODEV; |
| 465 | |
| 466 | found: |
| 467 | cma_attach_to_dev(id_priv, cma_dev); |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 468 | addr = (struct sockaddr_ib *) cma_src_addr(id_priv); |
| 469 | memcpy(&addr->sib_addr, &sgid, sizeof sgid); |
| 470 | cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); |
| 471 | return 0; |
| 472 | } |
| 473 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 474 | static void cma_deref_id(struct rdma_id_private *id_priv) |
| 475 | { |
| 476 | if (atomic_dec_and_test(&id_priv->refcount)) |
| 477 | complete(&id_priv->comp); |
| 478 | } |
| 479 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 480 | static int cma_disable_callback(struct rdma_id_private *id_priv, |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 481 | enum rdma_cm_state state) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 482 | { |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 483 | mutex_lock(&id_priv->handler_mutex); |
| 484 | if (id_priv->state != state) { |
| 485 | mutex_unlock(&id_priv->handler_mutex); |
| 486 | return -EINVAL; |
| 487 | } |
| 488 | return 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler, |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 492 | void *context, enum rdma_port_space ps, |
| 493 | enum ib_qp_type qp_type) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 494 | { |
| 495 | struct rdma_id_private *id_priv; |
| 496 | |
| 497 | id_priv = kzalloc(sizeof *id_priv, GFP_KERNEL); |
| 498 | if (!id_priv) |
| 499 | return ERR_PTR(-ENOMEM); |
| 500 | |
Nir Muchtar | 83e9502 | 2011-01-13 13:56:04 +0000 | [diff] [blame] | 501 | id_priv->owner = task_pid_nr(current); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 502 | id_priv->state = RDMA_CM_IDLE; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 503 | id_priv->id.context = context; |
| 504 | id_priv->id.event_handler = event_handler; |
| 505 | id_priv->id.ps = ps; |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 506 | id_priv->id.qp_type = qp_type; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 507 | spin_lock_init(&id_priv->lock); |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 508 | mutex_init(&id_priv->qp_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 509 | init_completion(&id_priv->comp); |
| 510 | atomic_set(&id_priv->refcount, 1); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 511 | mutex_init(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 512 | INIT_LIST_HEAD(&id_priv->listen_list); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 513 | INIT_LIST_HEAD(&id_priv->mc_list); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 514 | get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); |
| 515 | |
| 516 | return &id_priv->id; |
| 517 | } |
| 518 | EXPORT_SYMBOL(rdma_create_id); |
| 519 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 520 | static int cma_init_ud_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 521 | { |
| 522 | struct ib_qp_attr qp_attr; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 523 | int qp_attr_mask, ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 524 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 525 | qp_attr.qp_state = IB_QPS_INIT; |
| 526 | ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 527 | if (ret) |
| 528 | return ret; |
| 529 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 530 | ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 531 | if (ret) |
| 532 | return ret; |
| 533 | |
| 534 | qp_attr.qp_state = IB_QPS_RTR; |
| 535 | ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE); |
| 536 | if (ret) |
| 537 | return ret; |
| 538 | |
| 539 | qp_attr.qp_state = IB_QPS_RTS; |
| 540 | qp_attr.sq_psn = 0; |
| 541 | ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_SQ_PSN); |
| 542 | |
| 543 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 546 | static int cma_init_conn_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 547 | { |
| 548 | struct ib_qp_attr qp_attr; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 549 | int qp_attr_mask, ret; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 550 | |
| 551 | qp_attr.qp_state = IB_QPS_INIT; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 552 | ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 553 | if (ret) |
| 554 | return ret; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 555 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 556 | return ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 557 | } |
| 558 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 559 | int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, |
| 560 | struct ib_qp_init_attr *qp_init_attr) |
| 561 | { |
| 562 | struct rdma_id_private *id_priv; |
| 563 | struct ib_qp *qp; |
| 564 | int ret; |
| 565 | |
| 566 | id_priv = container_of(id, struct rdma_id_private, id); |
| 567 | if (id->device != pd->device) |
| 568 | return -EINVAL; |
| 569 | |
| 570 | qp = ib_create_qp(pd, qp_init_attr); |
| 571 | if (IS_ERR(qp)) |
| 572 | return PTR_ERR(qp); |
| 573 | |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 574 | if (id->qp_type == IB_QPT_UD) |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 575 | ret = cma_init_ud_qp(id_priv, qp); |
| 576 | else |
| 577 | ret = cma_init_conn_qp(id_priv, qp); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 578 | if (ret) |
| 579 | goto err; |
| 580 | |
| 581 | id->qp = qp; |
| 582 | id_priv->qp_num = qp->qp_num; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 583 | id_priv->srq = (qp->srq != NULL); |
| 584 | return 0; |
| 585 | err: |
| 586 | ib_destroy_qp(qp); |
| 587 | return ret; |
| 588 | } |
| 589 | EXPORT_SYMBOL(rdma_create_qp); |
| 590 | |
| 591 | void rdma_destroy_qp(struct rdma_cm_id *id) |
| 592 | { |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 593 | struct rdma_id_private *id_priv; |
| 594 | |
| 595 | id_priv = container_of(id, struct rdma_id_private, id); |
| 596 | mutex_lock(&id_priv->qp_mutex); |
| 597 | ib_destroy_qp(id_priv->id.qp); |
| 598 | id_priv->id.qp = NULL; |
| 599 | mutex_unlock(&id_priv->qp_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 600 | } |
| 601 | EXPORT_SYMBOL(rdma_destroy_qp); |
| 602 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 603 | static int cma_modify_qp_rtr(struct rdma_id_private *id_priv, |
| 604 | struct rdma_conn_param *conn_param) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 605 | { |
| 606 | struct ib_qp_attr qp_attr; |
| 607 | int qp_attr_mask, ret; |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 608 | union ib_gid sgid; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 609 | |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 610 | mutex_lock(&id_priv->qp_mutex); |
| 611 | if (!id_priv->id.qp) { |
| 612 | ret = 0; |
| 613 | goto out; |
| 614 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 615 | |
| 616 | /* Need to update QP attributes from default values. */ |
| 617 | qp_attr.qp_state = IB_QPS_INIT; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 618 | ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 619 | if (ret) |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 620 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 621 | |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 622 | ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 623 | if (ret) |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 624 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 625 | |
| 626 | qp_attr.qp_state = IB_QPS_RTR; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 627 | ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 628 | if (ret) |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 629 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 630 | |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 631 | ret = ib_query_gid(id_priv->id.device, id_priv->id.port_num, |
| 632 | qp_attr.ah_attr.grh.sgid_index, &sgid); |
| 633 | if (ret) |
| 634 | goto out; |
| 635 | |
| 636 | if (rdma_node_get_transport(id_priv->cma_dev->device->node_type) |
| 637 | == RDMA_TRANSPORT_IB && |
| 638 | rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num) |
| 639 | == IB_LINK_LAYER_ETHERNET) { |
| 640 | ret = rdma_addr_find_smac_by_sgid(&sgid, qp_attr.smac, NULL); |
| 641 | |
| 642 | if (ret) |
| 643 | goto out; |
| 644 | } |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 645 | if (conn_param) |
| 646 | qp_attr.max_dest_rd_atomic = conn_param->responder_resources; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 647 | ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
| 648 | out: |
| 649 | mutex_unlock(&id_priv->qp_mutex); |
| 650 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 653 | static int cma_modify_qp_rts(struct rdma_id_private *id_priv, |
| 654 | struct rdma_conn_param *conn_param) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 655 | { |
| 656 | struct ib_qp_attr qp_attr; |
| 657 | int qp_attr_mask, ret; |
| 658 | |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 659 | mutex_lock(&id_priv->qp_mutex); |
| 660 | if (!id_priv->id.qp) { |
| 661 | ret = 0; |
| 662 | goto out; |
| 663 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 664 | |
| 665 | qp_attr.qp_state = IB_QPS_RTS; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 666 | ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 667 | if (ret) |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 668 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 669 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 670 | if (conn_param) |
| 671 | qp_attr.max_rd_atomic = conn_param->initiator_depth; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 672 | ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
| 673 | out: |
| 674 | mutex_unlock(&id_priv->qp_mutex); |
| 675 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 678 | static int cma_modify_qp_err(struct rdma_id_private *id_priv) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 679 | { |
| 680 | struct ib_qp_attr qp_attr; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 681 | int ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 682 | |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 683 | mutex_lock(&id_priv->qp_mutex); |
| 684 | if (!id_priv->id.qp) { |
| 685 | ret = 0; |
| 686 | goto out; |
| 687 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 688 | |
| 689 | qp_attr.qp_state = IB_QPS_ERR; |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 690 | ret = ib_modify_qp(id_priv->id.qp, &qp_attr, IB_QP_STATE); |
| 691 | out: |
| 692 | mutex_unlock(&id_priv->qp_mutex); |
| 693 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 696 | static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv, |
| 697 | struct ib_qp_attr *qp_attr, int *qp_attr_mask) |
| 698 | { |
| 699 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 700 | int ret; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 701 | u16 pkey; |
| 702 | |
| 703 | if (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num) == |
| 704 | IB_LINK_LAYER_INFINIBAND) |
| 705 | pkey = ib_addr_get_pkey(dev_addr); |
| 706 | else |
| 707 | pkey = 0xffff; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 708 | |
| 709 | ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 710 | pkey, &qp_attr->pkey_index); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 711 | if (ret) |
| 712 | return ret; |
| 713 | |
| 714 | qp_attr->port_num = id_priv->id.port_num; |
| 715 | *qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 716 | |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 717 | if (id_priv->id.qp_type == IB_QPT_UD) { |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 718 | ret = cma_set_qkey(id_priv, 0); |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 719 | if (ret) |
| 720 | return ret; |
| 721 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 722 | qp_attr->qkey = id_priv->qkey; |
| 723 | *qp_attr_mask |= IB_QP_QKEY; |
| 724 | } else { |
| 725 | qp_attr->qp_access_flags = 0; |
| 726 | *qp_attr_mask |= IB_QP_ACCESS_FLAGS; |
| 727 | } |
| 728 | return 0; |
| 729 | } |
| 730 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 731 | int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, |
| 732 | int *qp_attr_mask) |
| 733 | { |
| 734 | struct rdma_id_private *id_priv; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 735 | int ret = 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 736 | |
| 737 | id_priv = container_of(id, struct rdma_id_private, id); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 738 | switch (rdma_node_get_transport(id_priv->id.device->node_type)) { |
| 739 | case RDMA_TRANSPORT_IB: |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 740 | if (!id_priv->cm_id.ib || (id_priv->id.qp_type == IB_QPT_UD)) |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 741 | ret = cma_ib_init_qp_attr(id_priv, qp_attr, qp_attr_mask); |
| 742 | else |
| 743 | ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, |
| 744 | qp_attr_mask); |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 745 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 746 | if (qp_attr->qp_state == IB_QPS_RTR) |
| 747 | qp_attr->rq_psn = id_priv->seq_num; |
| 748 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 749 | case RDMA_TRANSPORT_IWARP: |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 750 | if (!id_priv->cm_id.iw) { |
Dotan Barak | 8f07653 | 2007-07-17 17:58:57 +0300 | [diff] [blame] | 751 | qp_attr->qp_access_flags = 0; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 752 | *qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS; |
| 753 | } else |
| 754 | ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, |
| 755 | qp_attr_mask); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 756 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 757 | default: |
| 758 | ret = -ENOSYS; |
| 759 | break; |
| 760 | } |
| 761 | |
| 762 | return ret; |
| 763 | } |
| 764 | EXPORT_SYMBOL(rdma_init_qp_attr); |
| 765 | |
| 766 | static inline int cma_zero_addr(struct sockaddr *addr) |
| 767 | { |
Sean Hefty | 2e2d190 | 2013-05-29 10:09:09 -0700 | [diff] [blame] | 768 | switch (addr->sa_family) { |
| 769 | case AF_INET: |
| 770 | return ipv4_is_zeronet(((struct sockaddr_in *)addr)->sin_addr.s_addr); |
| 771 | case AF_INET6: |
| 772 | return ipv6_addr_any(&((struct sockaddr_in6 *) addr)->sin6_addr); |
| 773 | case AF_IB: |
| 774 | return ib_addr_any(&((struct sockaddr_ib *) addr)->sib_addr); |
| 775 | default: |
| 776 | return 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
| 780 | static inline int cma_loopback_addr(struct sockaddr *addr) |
| 781 | { |
Sean Hefty | 2e2d190 | 2013-05-29 10:09:09 -0700 | [diff] [blame] | 782 | switch (addr->sa_family) { |
| 783 | case AF_INET: |
| 784 | return ipv4_is_loopback(((struct sockaddr_in *) addr)->sin_addr.s_addr); |
| 785 | case AF_INET6: |
| 786 | return ipv6_addr_loopback(&((struct sockaddr_in6 *) addr)->sin6_addr); |
| 787 | case AF_IB: |
| 788 | return ib_addr_loopback(&((struct sockaddr_ib *) addr)->sib_addr); |
| 789 | default: |
| 790 | return 0; |
| 791 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | static inline int cma_any_addr(struct sockaddr *addr) |
| 795 | { |
| 796 | return cma_zero_addr(addr) || cma_loopback_addr(addr); |
| 797 | } |
| 798 | |
Hefty, Sean | 43b752d | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 799 | static int cma_addr_cmp(struct sockaddr *src, struct sockaddr *dst) |
| 800 | { |
| 801 | if (src->sa_family != dst->sa_family) |
| 802 | return -1; |
| 803 | |
| 804 | switch (src->sa_family) { |
| 805 | case AF_INET: |
| 806 | return ((struct sockaddr_in *) src)->sin_addr.s_addr != |
| 807 | ((struct sockaddr_in *) dst)->sin_addr.s_addr; |
Sean Hefty | 2e2d190 | 2013-05-29 10:09:09 -0700 | [diff] [blame] | 808 | case AF_INET6: |
Hefty, Sean | 43b752d | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 809 | return ipv6_addr_cmp(&((struct sockaddr_in6 *) src)->sin6_addr, |
| 810 | &((struct sockaddr_in6 *) dst)->sin6_addr); |
Sean Hefty | 2e2d190 | 2013-05-29 10:09:09 -0700 | [diff] [blame] | 811 | default: |
| 812 | return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, |
| 813 | &((struct sockaddr_ib *) dst)->sib_addr); |
Hefty, Sean | 43b752d | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 817 | static __be16 cma_port(struct sockaddr *addr) |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 818 | { |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 819 | struct sockaddr_ib *sib; |
| 820 | |
| 821 | switch (addr->sa_family) { |
| 822 | case AF_INET: |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 823 | return ((struct sockaddr_in *) addr)->sin_port; |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 824 | case AF_INET6: |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 825 | return ((struct sockaddr_in6 *) addr)->sin6_port; |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 826 | case AF_IB: |
| 827 | sib = (struct sockaddr_ib *) addr; |
| 828 | return htons((u16) (be64_to_cpu(sib->sib_sid) & |
| 829 | be64_to_cpu(sib->sib_sid_mask))); |
| 830 | default: |
| 831 | return 0; |
| 832 | } |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 835 | static inline int cma_any_port(struct sockaddr *addr) |
| 836 | { |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 837 | return !cma_port(addr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 840 | static void cma_save_ib_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
| 841 | struct ib_sa_path_rec *path) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 842 | { |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 843 | struct sockaddr_ib *listen_ib, *ib; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 844 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 845 | listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; |
| 846 | ib = (struct sockaddr_ib *) &id->route.addr.src_addr; |
| 847 | ib->sib_family = listen_ib->sib_family; |
| 848 | ib->sib_pkey = path->pkey; |
| 849 | ib->sib_flowinfo = path->flow_label; |
| 850 | memcpy(&ib->sib_addr, &path->sgid, 16); |
| 851 | ib->sib_sid = listen_ib->sib_sid; |
| 852 | ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); |
| 853 | ib->sib_scope_id = listen_ib->sib_scope_id; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 854 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 855 | ib = (struct sockaddr_ib *) &id->route.addr.dst_addr; |
| 856 | ib->sib_family = listen_ib->sib_family; |
| 857 | ib->sib_pkey = path->pkey; |
| 858 | ib->sib_flowinfo = path->flow_label; |
| 859 | memcpy(&ib->sib_addr, &path->dgid, 16); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 862 | static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
| 863 | struct cma_hdr *hdr) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 864 | { |
| 865 | struct sockaddr_in *listen4, *ip4; |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 866 | |
| 867 | listen4 = (struct sockaddr_in *) &listen_id->route.addr.src_addr; |
| 868 | ip4 = (struct sockaddr_in *) &id->route.addr.src_addr; |
| 869 | ip4->sin_family = listen4->sin_family; |
| 870 | ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr; |
| 871 | ip4->sin_port = listen4->sin_port; |
| 872 | |
| 873 | ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr; |
| 874 | ip4->sin_family = listen4->sin_family; |
| 875 | ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr; |
| 876 | ip4->sin_port = hdr->port; |
| 877 | } |
| 878 | |
| 879 | static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
| 880 | struct cma_hdr *hdr) |
| 881 | { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 882 | struct sockaddr_in6 *listen6, *ip6; |
| 883 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 884 | listen6 = (struct sockaddr_in6 *) &listen_id->route.addr.src_addr; |
| 885 | ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr; |
| 886 | ip6->sin6_family = listen6->sin6_family; |
| 887 | ip6->sin6_addr = hdr->dst_addr.ip6; |
| 888 | ip6->sin6_port = listen6->sin6_port; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 889 | |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 890 | ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr; |
| 891 | ip6->sin6_family = listen6->sin6_family; |
| 892 | ip6->sin6_addr = hdr->src_addr.ip6; |
| 893 | ip6->sin6_port = hdr->port; |
| 894 | } |
| 895 | |
| 896 | static int cma_save_net_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
| 897 | struct ib_cm_event *ib_event) |
| 898 | { |
| 899 | struct cma_hdr *hdr; |
| 900 | |
Sean Hefty | 5eb695c | 2013-07-24 15:06:09 -0700 | [diff] [blame] | 901 | if ((listen_id->route.addr.src_addr.ss_family == AF_IB) && |
| 902 | (ib_event->event == IB_CM_REQ_RECEIVED)) { |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 903 | cma_save_ib_info(id, listen_id, ib_event->param.req_rcvd.primary_path); |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | hdr = ib_event->private_data; |
| 908 | if (hdr->cma_version != CMA_VERSION) |
| 909 | return -EINVAL; |
| 910 | |
| 911 | switch (cma_get_ip_ver(hdr)) { |
| 912 | case 4: |
| 913 | cma_save_ip4_info(id, listen_id, hdr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 914 | break; |
| 915 | case 6: |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 916 | cma_save_ip6_info(id, listen_id, hdr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 917 | break; |
| 918 | default: |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 919 | return -EINVAL; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 920 | } |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 921 | return 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 924 | static inline int cma_user_data_offset(struct rdma_id_private *id_priv) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 925 | { |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 926 | return cma_family(id_priv) == AF_IB ? 0 : sizeof(struct cma_hdr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 929 | static void cma_cancel_route(struct rdma_id_private *id_priv) |
| 930 | { |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 931 | switch (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num)) { |
| 932 | case IB_LINK_LAYER_INFINIBAND: |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 933 | if (id_priv->query) |
| 934 | ib_sa_cancel_query(id_priv->query_id, id_priv->query); |
| 935 | break; |
| 936 | default: |
| 937 | break; |
| 938 | } |
| 939 | } |
| 940 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 941 | static void cma_cancel_listens(struct rdma_id_private *id_priv) |
| 942 | { |
| 943 | struct rdma_id_private *dev_id_priv; |
| 944 | |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 945 | /* |
| 946 | * Remove from listen_any_list to prevent added devices from spawning |
| 947 | * additional listen requests. |
| 948 | */ |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 949 | mutex_lock(&lock); |
| 950 | list_del(&id_priv->list); |
| 951 | |
| 952 | while (!list_empty(&id_priv->listen_list)) { |
| 953 | dev_id_priv = list_entry(id_priv->listen_list.next, |
| 954 | struct rdma_id_private, listen_list); |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 955 | /* sync with device removal to avoid duplicate destruction */ |
| 956 | list_del_init(&dev_id_priv->list); |
| 957 | list_del(&dev_id_priv->listen_list); |
| 958 | mutex_unlock(&lock); |
| 959 | |
| 960 | rdma_destroy_id(&dev_id_priv->id); |
| 961 | mutex_lock(&lock); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 962 | } |
| 963 | mutex_unlock(&lock); |
| 964 | } |
| 965 | |
| 966 | static void cma_cancel_operation(struct rdma_id_private *id_priv, |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 967 | enum rdma_cm_state state) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 968 | { |
| 969 | switch (state) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 970 | case RDMA_CM_ADDR_QUERY: |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 971 | rdma_addr_cancel(&id_priv->id.route.addr.dev_addr); |
| 972 | break; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 973 | case RDMA_CM_ROUTE_QUERY: |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 974 | cma_cancel_route(id_priv); |
| 975 | break; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 976 | case RDMA_CM_LISTEN: |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 977 | if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 978 | cma_cancel_listens(id_priv); |
| 979 | break; |
| 980 | default: |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | static void cma_release_port(struct rdma_id_private *id_priv) |
| 986 | { |
| 987 | struct rdma_bind_list *bind_list = id_priv->bind_list; |
| 988 | |
| 989 | if (!bind_list) |
| 990 | return; |
| 991 | |
| 992 | mutex_lock(&lock); |
| 993 | hlist_del(&id_priv->node); |
| 994 | if (hlist_empty(&bind_list->owners)) { |
| 995 | idr_remove(bind_list->ps, bind_list->port); |
| 996 | kfree(bind_list); |
| 997 | } |
| 998 | mutex_unlock(&lock); |
| 999 | } |
| 1000 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 1001 | static void cma_leave_mc_groups(struct rdma_id_private *id_priv) |
| 1002 | { |
| 1003 | struct cma_multicast *mc; |
| 1004 | |
| 1005 | while (!list_empty(&id_priv->mc_list)) { |
| 1006 | mc = container_of(id_priv->mc_list.next, |
| 1007 | struct cma_multicast, list); |
| 1008 | list_del(&mc->list); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1009 | switch (rdma_port_get_link_layer(id_priv->cma_dev->device, id_priv->id.port_num)) { |
| 1010 | case IB_LINK_LAYER_INFINIBAND: |
| 1011 | ib_sa_free_multicast(mc->multicast.ib); |
| 1012 | kfree(mc); |
| 1013 | break; |
| 1014 | case IB_LINK_LAYER_ETHERNET: |
| 1015 | kref_put(&mc->mcref, release_mc); |
| 1016 | break; |
| 1017 | default: |
| 1018 | break; |
| 1019 | } |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1023 | void rdma_destroy_id(struct rdma_cm_id *id) |
| 1024 | { |
| 1025 | struct rdma_id_private *id_priv; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1026 | enum rdma_cm_state state; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1027 | |
| 1028 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1029 | state = cma_exch(id_priv, RDMA_CM_DESTROYING); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1030 | cma_cancel_operation(id_priv, state); |
| 1031 | |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 1032 | /* |
| 1033 | * Wait for any active callback to finish. New callbacks will find |
| 1034 | * the id_priv state set to destroying and abort. |
| 1035 | */ |
| 1036 | mutex_lock(&id_priv->handler_mutex); |
| 1037 | mutex_unlock(&id_priv->handler_mutex); |
| 1038 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1039 | if (id_priv->cma_dev) { |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1040 | switch (rdma_node_get_transport(id_priv->id.device->node_type)) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1041 | case RDMA_TRANSPORT_IB: |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1042 | if (id_priv->cm_id.ib) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1043 | ib_destroy_cm_id(id_priv->cm_id.ib); |
| 1044 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1045 | case RDMA_TRANSPORT_IWARP: |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1046 | if (id_priv->cm_id.iw) |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1047 | iw_destroy_cm_id(id_priv->cm_id.iw); |
| 1048 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1049 | default: |
| 1050 | break; |
| 1051 | } |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 1052 | cma_leave_mc_groups(id_priv); |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 1053 | cma_release_dev(id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | cma_release_port(id_priv); |
| 1057 | cma_deref_id(id_priv); |
| 1058 | wait_for_completion(&id_priv->comp); |
| 1059 | |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 1060 | if (id_priv->internal_id) |
| 1061 | cma_deref_id(id_priv->id.context); |
| 1062 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1063 | kfree(id_priv->id.route.path_rec); |
| 1064 | kfree(id_priv); |
| 1065 | } |
| 1066 | EXPORT_SYMBOL(rdma_destroy_id); |
| 1067 | |
| 1068 | static int cma_rep_recv(struct rdma_id_private *id_priv) |
| 1069 | { |
| 1070 | int ret; |
| 1071 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 1072 | ret = cma_modify_qp_rtr(id_priv, NULL); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1073 | if (ret) |
| 1074 | goto reject; |
| 1075 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 1076 | ret = cma_modify_qp_rts(id_priv, NULL); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1077 | if (ret) |
| 1078 | goto reject; |
| 1079 | |
| 1080 | ret = ib_send_cm_rtu(id_priv->cm_id.ib, NULL, 0); |
| 1081 | if (ret) |
| 1082 | goto reject; |
| 1083 | |
| 1084 | return 0; |
| 1085 | reject: |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 1086 | cma_modify_qp_err(id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1087 | ib_send_cm_rej(id_priv->cm_id.ib, IB_CM_REJ_CONSUMER_DEFINED, |
| 1088 | NULL, 0, NULL, 0); |
| 1089 | return ret; |
| 1090 | } |
| 1091 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1092 | static void cma_set_rep_event_data(struct rdma_cm_event *event, |
| 1093 | struct ib_cm_rep_event_param *rep_data, |
| 1094 | void *private_data) |
| 1095 | { |
| 1096 | event->param.conn.private_data = private_data; |
| 1097 | event->param.conn.private_data_len = IB_CM_REP_PRIVATE_DATA_SIZE; |
| 1098 | event->param.conn.responder_resources = rep_data->responder_resources; |
| 1099 | event->param.conn.initiator_depth = rep_data->initiator_depth; |
| 1100 | event->param.conn.flow_control = rep_data->flow_control; |
| 1101 | event->param.conn.rnr_retry_count = rep_data->rnr_retry_count; |
| 1102 | event->param.conn.srq = rep_data->srq; |
| 1103 | event->param.conn.qp_num = rep_data->remote_qpn; |
| 1104 | } |
| 1105 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1106 | static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event) |
| 1107 | { |
| 1108 | struct rdma_id_private *id_priv = cm_id->context; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1109 | struct rdma_cm_event event; |
| 1110 | int ret = 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1111 | |
Amir Vadai | 38ca83a | 2008-07-22 14:14:23 -0700 | [diff] [blame] | 1112 | if ((ib_event->event != IB_CM_TIMEWAIT_EXIT && |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1113 | cma_disable_callback(id_priv, RDMA_CM_CONNECT)) || |
Amir Vadai | 38ca83a | 2008-07-22 14:14:23 -0700 | [diff] [blame] | 1114 | (ib_event->event == IB_CM_TIMEWAIT_EXIT && |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1115 | cma_disable_callback(id_priv, RDMA_CM_DISCONNECT))) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 1116 | return 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1117 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1118 | memset(&event, 0, sizeof event); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1119 | switch (ib_event->event) { |
| 1120 | case IB_CM_REQ_ERROR: |
| 1121 | case IB_CM_REP_ERROR: |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1122 | event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 1123 | event.status = -ETIMEDOUT; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1124 | break; |
| 1125 | case IB_CM_REP_RECEIVED: |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 1126 | if (id_priv->id.qp) { |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1127 | event.status = cma_rep_recv(id_priv); |
| 1128 | event.event = event.status ? RDMA_CM_EVENT_CONNECT_ERROR : |
| 1129 | RDMA_CM_EVENT_ESTABLISHED; |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 1130 | } else { |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1131 | event.event = RDMA_CM_EVENT_CONNECT_RESPONSE; |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 1132 | } |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1133 | cma_set_rep_event_data(&event, &ib_event->param.rep_rcvd, |
| 1134 | ib_event->private_data); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1135 | break; |
| 1136 | case IB_CM_RTU_RECEIVED: |
Sean Hefty | 0fe313b | 2006-11-30 16:37:15 -0800 | [diff] [blame] | 1137 | case IB_CM_USER_ESTABLISHED: |
| 1138 | event.event = RDMA_CM_EVENT_ESTABLISHED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1139 | break; |
| 1140 | case IB_CM_DREQ_ERROR: |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1141 | event.status = -ETIMEDOUT; /* fall through */ |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1142 | case IB_CM_DREQ_RECEIVED: |
| 1143 | case IB_CM_DREP_RECEIVED: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1144 | if (!cma_comp_exch(id_priv, RDMA_CM_CONNECT, |
| 1145 | RDMA_CM_DISCONNECT)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1146 | goto out; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1147 | event.event = RDMA_CM_EVENT_DISCONNECTED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1148 | break; |
| 1149 | case IB_CM_TIMEWAIT_EXIT: |
Amir Vadai | 38ca83a | 2008-07-22 14:14:23 -0700 | [diff] [blame] | 1150 | event.event = RDMA_CM_EVENT_TIMEWAIT_EXIT; |
| 1151 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1152 | case IB_CM_MRA_RECEIVED: |
| 1153 | /* ignore event */ |
| 1154 | goto out; |
| 1155 | case IB_CM_REJ_RECEIVED: |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 1156 | cma_modify_qp_err(id_priv); |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1157 | event.status = ib_event->param.rej_rcvd.reason; |
| 1158 | event.event = RDMA_CM_EVENT_REJECTED; |
| 1159 | event.param.conn.private_data = ib_event->private_data; |
| 1160 | event.param.conn.private_data_len = IB_CM_REJ_PRIVATE_DATA_SIZE; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1161 | break; |
| 1162 | default: |
Roland Dreier | 468f223 | 2008-07-14 23:48:47 -0700 | [diff] [blame] | 1163 | printk(KERN_ERR "RDMA CMA: unexpected IB CM event: %d\n", |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1164 | ib_event->event); |
| 1165 | goto out; |
| 1166 | } |
| 1167 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1168 | ret = id_priv->id.event_handler(&id_priv->id, &event); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1169 | if (ret) { |
| 1170 | /* Destroy the CM ID by returning a non-zero value. */ |
| 1171 | id_priv->cm_id.ib = NULL; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1172 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1173 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1174 | rdma_destroy_id(&id_priv->id); |
| 1175 | return ret; |
| 1176 | } |
| 1177 | out: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1178 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1179 | return ret; |
| 1180 | } |
| 1181 | |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1182 | static struct rdma_id_private *cma_new_conn_id(struct rdma_cm_id *listen_id, |
| 1183 | struct ib_cm_event *ib_event) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1184 | { |
| 1185 | struct rdma_id_private *id_priv; |
| 1186 | struct rdma_cm_id *id; |
| 1187 | struct rdma_route *rt; |
Or Gerlitz | 64c5e61 | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1188 | int ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1189 | |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1190 | id = rdma_create_id(listen_id->event_handler, listen_id->context, |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 1191 | listen_id->ps, ib_event->param.req_rcvd.qp_type); |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1192 | if (IS_ERR(id)) |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1193 | return NULL; |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1194 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1195 | id_priv = container_of(id, struct rdma_id_private, id); |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 1196 | if (cma_save_net_info(id, listen_id, ib_event)) |
| 1197 | goto err; |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1198 | |
| 1199 | rt = &id->route; |
| 1200 | rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; |
| 1201 | rt->path_rec = kmalloc(sizeof *rt->path_rec * rt->num_paths, |
| 1202 | GFP_KERNEL); |
| 1203 | if (!rt->path_rec) |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1204 | goto err; |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1205 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1206 | rt->path_rec[0] = *ib_event->param.req_rcvd.primary_path; |
| 1207 | if (rt->num_paths == 2) |
| 1208 | rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; |
| 1209 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1210 | if (cma_any_addr(cma_src_addr(id_priv))) { |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1211 | rt->addr.dev_addr.dev_type = ARPHRD_INFINIBAND; |
| 1212 | rdma_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid); |
Sean Hefty | 46ea506 | 2011-12-06 21:15:18 +0000 | [diff] [blame] | 1213 | ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey)); |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1214 | } else { |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1215 | ret = cma_translate_addr(cma_src_addr(id_priv), &rt->addr.dev_addr); |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1216 | if (ret) |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1217 | goto err; |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1218 | } |
| 1219 | rdma_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1220 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1221 | id_priv->state = RDMA_CM_CONNECT; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1222 | return id_priv; |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1223 | |
Krishna Kumar | 3f168d2 | 2006-09-29 12:09:51 -0700 | [diff] [blame] | 1224 | err: |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1225 | rdma_destroy_id(id); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1226 | return NULL; |
| 1227 | } |
| 1228 | |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1229 | static struct rdma_id_private *cma_new_udp_id(struct rdma_cm_id *listen_id, |
| 1230 | struct ib_cm_event *ib_event) |
| 1231 | { |
| 1232 | struct rdma_id_private *id_priv; |
| 1233 | struct rdma_cm_id *id; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1234 | int ret; |
| 1235 | |
| 1236 | id = rdma_create_id(listen_id->event_handler, listen_id->context, |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 1237 | listen_id->ps, IB_QPT_UD); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1238 | if (IS_ERR(id)) |
| 1239 | return NULL; |
| 1240 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1241 | id_priv = container_of(id, struct rdma_id_private, id); |
Sean Hefty | fbaa1a6 | 2013-05-29 10:09:21 -0700 | [diff] [blame] | 1242 | if (cma_save_net_info(id, listen_id, ib_event)) |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1243 | goto err; |
| 1244 | |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1245 | if (!cma_any_addr((struct sockaddr *) &id->route.addr.src_addr)) { |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1246 | ret = cma_translate_addr(cma_src_addr(id_priv), &id->route.addr.dev_addr); |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 1247 | if (ret) |
| 1248 | goto err; |
| 1249 | } |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1250 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1251 | id_priv->state = RDMA_CM_CONNECT; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1252 | return id_priv; |
| 1253 | err: |
| 1254 | rdma_destroy_id(id); |
| 1255 | return NULL; |
| 1256 | } |
| 1257 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1258 | static void cma_set_req_event_data(struct rdma_cm_event *event, |
| 1259 | struct ib_cm_req_event_param *req_data, |
| 1260 | void *private_data, int offset) |
| 1261 | { |
| 1262 | event->param.conn.private_data = private_data + offset; |
| 1263 | event->param.conn.private_data_len = IB_CM_REQ_PRIVATE_DATA_SIZE - offset; |
| 1264 | event->param.conn.responder_resources = req_data->responder_resources; |
| 1265 | event->param.conn.initiator_depth = req_data->initiator_depth; |
| 1266 | event->param.conn.flow_control = req_data->flow_control; |
| 1267 | event->param.conn.retry_count = req_data->retry_count; |
| 1268 | event->param.conn.rnr_retry_count = req_data->rnr_retry_count; |
| 1269 | event->param.conn.srq = req_data->srq; |
| 1270 | event->param.conn.qp_num = req_data->remote_qpn; |
| 1271 | } |
| 1272 | |
Hefty, Sean | 9595480 | 2011-10-06 09:32:33 -0700 | [diff] [blame] | 1273 | static int cma_check_req_qp_type(struct rdma_cm_id *id, struct ib_cm_event *ib_event) |
| 1274 | { |
Sean Hefty | 4dd81e8 | 2012-06-14 20:49:09 +0000 | [diff] [blame] | 1275 | return (((ib_event->event == IB_CM_REQ_RECEIVED) && |
Hefty, Sean | 9595480 | 2011-10-06 09:32:33 -0700 | [diff] [blame] | 1276 | (ib_event->param.req_rcvd.qp_type == id->qp_type)) || |
| 1277 | ((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) && |
| 1278 | (id->qp_type == IB_QPT_UD)) || |
| 1279 | (!id->qp_type)); |
| 1280 | } |
| 1281 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1282 | static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event) |
| 1283 | { |
| 1284 | struct rdma_id_private *listen_id, *conn_id; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1285 | struct rdma_cm_event event; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1286 | int offset, ret; |
| 1287 | |
| 1288 | listen_id = cm_id->context; |
Hefty, Sean | 9595480 | 2011-10-06 09:32:33 -0700 | [diff] [blame] | 1289 | if (!cma_check_req_qp_type(&listen_id->id, ib_event)) |
| 1290 | return -EINVAL; |
| 1291 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1292 | if (cma_disable_callback(listen_id, RDMA_CM_LISTEN)) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 1293 | return -ECONNABORTED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1294 | |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1295 | memset(&event, 0, sizeof event); |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 1296 | offset = cma_user_data_offset(listen_id); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1297 | event.event = RDMA_CM_EVENT_CONNECT_REQUEST; |
Hefty, Sean | 9595480 | 2011-10-06 09:32:33 -0700 | [diff] [blame] | 1298 | if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) { |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 1299 | conn_id = cma_new_udp_id(&listen_id->id, ib_event); |
| 1300 | event.param.ud.private_data = ib_event->private_data + offset; |
| 1301 | event.param.ud.private_data_len = |
| 1302 | IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; |
| 1303 | } else { |
| 1304 | conn_id = cma_new_conn_id(&listen_id->id, ib_event); |
| 1305 | cma_set_req_event_data(&event, &ib_event->param.req_rcvd, |
| 1306 | ib_event->private_data, offset); |
| 1307 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1308 | if (!conn_id) { |
| 1309 | ret = -ENOMEM; |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1310 | goto err1; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1313 | mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 1314 | ret = cma_acquire_dev(conn_id, listen_id); |
Krishna Kumar | a1a733f | 2006-10-17 10:09:11 +0530 | [diff] [blame] | 1315 | if (ret) |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1316 | goto err2; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1317 | |
| 1318 | conn_id->cm_id.ib = cm_id; |
| 1319 | cm_id->context = conn_id; |
| 1320 | cm_id->cm_handler = cma_ib_handler; |
| 1321 | |
Sean Hefty | 25ae21a | 2011-02-23 08:11:32 -0800 | [diff] [blame] | 1322 | /* |
| 1323 | * Protect against the user destroying conn_id from another thread |
| 1324 | * until we're done accessing it. |
| 1325 | */ |
| 1326 | atomic_inc(&conn_id->refcount); |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1327 | ret = conn_id->id.event_handler(&conn_id->id, &event); |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1328 | if (ret) |
| 1329 | goto err3; |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1330 | /* |
| 1331 | * Acquire mutex to prevent user executing rdma_destroy_id() |
| 1332 | * while we're accessing the cm_id. |
| 1333 | */ |
| 1334 | mutex_lock(&lock); |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1335 | if (cma_comp(conn_id, RDMA_CM_CONNECT) && |
| 1336 | (conn_id->id.qp_type != IB_QPT_UD)) |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1337 | ib_send_cm_mra(cm_id, CMA_CM_MRA_SETTING, NULL, 0); |
| 1338 | mutex_unlock(&lock); |
| 1339 | mutex_unlock(&conn_id->handler_mutex); |
| 1340 | mutex_unlock(&listen_id->handler_mutex); |
| 1341 | cma_deref_id(conn_id); |
| 1342 | return 0; |
| 1343 | |
| 1344 | err3: |
| 1345 | cma_deref_id(conn_id); |
Krishna Kumar | a1a733f | 2006-10-17 10:09:11 +0530 | [diff] [blame] | 1346 | /* Destroy the CM ID by returning a non-zero value. */ |
| 1347 | conn_id->cm_id.ib = NULL; |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1348 | err2: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1349 | cma_exch(conn_id, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1350 | mutex_unlock(&conn_id->handler_mutex); |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1351 | err1: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1352 | mutex_unlock(&listen_id->handler_mutex); |
Sean Hefty | b6cec8a | 2012-04-25 17:42:35 +0000 | [diff] [blame] | 1353 | if (conn_id) |
| 1354 | rdma_destroy_id(&conn_id->id); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1355 | return ret; |
| 1356 | } |
| 1357 | |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 1358 | __be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1359 | { |
Sean Hefty | 496ce3c | 2013-05-29 10:09:19 -0700 | [diff] [blame] | 1360 | if (addr->sa_family == AF_IB) |
| 1361 | return ((struct sockaddr_ib *) addr)->sib_sid; |
| 1362 | |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 1363 | return cpu_to_be64(((u64)id->ps << 16) + be16_to_cpu(cma_port(addr))); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1364 | } |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 1365 | EXPORT_SYMBOL(rdma_get_service_id); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1366 | |
| 1367 | static void cma_set_compare_data(enum rdma_port_space ps, struct sockaddr *addr, |
| 1368 | struct ib_cm_compare_data *compare) |
| 1369 | { |
| 1370 | struct cma_hdr *cma_data, *cma_mask; |
Al Viro | 1b90c13 | 2008-03-29 03:10:28 +0000 | [diff] [blame] | 1371 | __be32 ip4_addr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1372 | struct in6_addr ip6_addr; |
| 1373 | |
| 1374 | memset(compare, 0, sizeof *compare); |
| 1375 | cma_data = (void *) compare->data; |
| 1376 | cma_mask = (void *) compare->mask; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1377 | |
| 1378 | switch (addr->sa_family) { |
| 1379 | case AF_INET: |
| 1380 | ip4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 1381 | cma_set_ip_ver(cma_data, 4); |
| 1382 | cma_set_ip_ver(cma_mask, 0xF); |
| 1383 | if (!cma_any_addr(addr)) { |
| 1384 | cma_data->dst_addr.ip4.addr = ip4_addr; |
| 1385 | cma_mask->dst_addr.ip4.addr = htonl(~0); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1386 | } |
| 1387 | break; |
| 1388 | case AF_INET6: |
| 1389 | ip6_addr = ((struct sockaddr_in6 *) addr)->sin6_addr; |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 1390 | cma_set_ip_ver(cma_data, 6); |
| 1391 | cma_set_ip_ver(cma_mask, 0xF); |
| 1392 | if (!cma_any_addr(addr)) { |
| 1393 | cma_data->dst_addr.ip6 = ip6_addr; |
| 1394 | memset(&cma_mask->dst_addr.ip6, 0xFF, |
| 1395 | sizeof cma_mask->dst_addr.ip6); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1396 | } |
| 1397 | break; |
| 1398 | default: |
| 1399 | break; |
| 1400 | } |
| 1401 | } |
| 1402 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1403 | static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event) |
| 1404 | { |
| 1405 | struct rdma_id_private *id_priv = iw_id->context; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1406 | struct rdma_cm_event event; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1407 | int ret = 0; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1408 | struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; |
| 1409 | struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1410 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1411 | if (cma_disable_callback(id_priv, RDMA_CM_CONNECT)) |
Sean Hefty | be65f08 | 2007-05-07 11:49:12 -0700 | [diff] [blame] | 1412 | return 0; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1413 | |
Sean Hefty | be65f08 | 2007-05-07 11:49:12 -0700 | [diff] [blame] | 1414 | memset(&event, 0, sizeof event); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1415 | switch (iw_event->event) { |
| 1416 | case IW_CM_EVENT_CLOSE: |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1417 | event.event = RDMA_CM_EVENT_DISCONNECTED; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1418 | break; |
| 1419 | case IW_CM_EVENT_CONNECT_REPLY: |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1420 | memcpy(cma_src_addr(id_priv), laddr, |
| 1421 | rdma_addr_size(laddr)); |
| 1422 | memcpy(cma_dst_addr(id_priv), raddr, |
| 1423 | rdma_addr_size(raddr)); |
Steve Wise | 881a045 | 2006-12-15 16:50:17 -0600 | [diff] [blame] | 1424 | switch (iw_event->status) { |
| 1425 | case 0: |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1426 | event.event = RDMA_CM_EVENT_ESTABLISHED; |
Kumar Sanghvi | 3ebeebc | 2011-09-25 20:17:43 +0530 | [diff] [blame] | 1427 | event.param.conn.initiator_depth = iw_event->ird; |
| 1428 | event.param.conn.responder_resources = iw_event->ord; |
Steve Wise | 881a045 | 2006-12-15 16:50:17 -0600 | [diff] [blame] | 1429 | break; |
| 1430 | case -ECONNRESET: |
| 1431 | case -ECONNREFUSED: |
| 1432 | event.event = RDMA_CM_EVENT_REJECTED; |
| 1433 | break; |
| 1434 | case -ETIMEDOUT: |
| 1435 | event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 1436 | break; |
| 1437 | default: |
| 1438 | event.event = RDMA_CM_EVENT_CONNECT_ERROR; |
| 1439 | break; |
| 1440 | } |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1441 | break; |
| 1442 | case IW_CM_EVENT_ESTABLISHED: |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1443 | event.event = RDMA_CM_EVENT_ESTABLISHED; |
Kumar Sanghvi | 3ebeebc | 2011-09-25 20:17:43 +0530 | [diff] [blame] | 1444 | event.param.conn.initiator_depth = iw_event->ird; |
| 1445 | event.param.conn.responder_resources = iw_event->ord; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1446 | break; |
| 1447 | default: |
| 1448 | BUG_ON(1); |
| 1449 | } |
| 1450 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1451 | event.status = iw_event->status; |
| 1452 | event.param.conn.private_data = iw_event->private_data; |
| 1453 | event.param.conn.private_data_len = iw_event->private_data_len; |
| 1454 | ret = id_priv->id.event_handler(&id_priv->id, &event); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1455 | if (ret) { |
| 1456 | /* Destroy the CM ID by returning a non-zero value. */ |
| 1457 | id_priv->cm_id.iw = NULL; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1458 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1459 | mutex_unlock(&id_priv->handler_mutex); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1460 | rdma_destroy_id(&id_priv->id); |
| 1461 | return ret; |
| 1462 | } |
| 1463 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1464 | mutex_unlock(&id_priv->handler_mutex); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1465 | return ret; |
| 1466 | } |
| 1467 | |
| 1468 | static int iw_conn_req_handler(struct iw_cm_id *cm_id, |
| 1469 | struct iw_cm_event *iw_event) |
| 1470 | { |
| 1471 | struct rdma_cm_id *new_cm_id; |
| 1472 | struct rdma_id_private *listen_id, *conn_id; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1473 | struct rdma_cm_event event; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1474 | int ret; |
Steve Wise | 8d8293c | 2007-10-29 11:34:05 -0500 | [diff] [blame] | 1475 | struct ib_device_attr attr; |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1476 | struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; |
| 1477 | struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1478 | |
| 1479 | listen_id = cm_id->context; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1480 | if (cma_disable_callback(listen_id, RDMA_CM_LISTEN)) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 1481 | return -ECONNABORTED; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1482 | |
| 1483 | /* Create a new RDMA id for the new IW CM ID */ |
| 1484 | new_cm_id = rdma_create_id(listen_id->id.event_handler, |
| 1485 | listen_id->id.context, |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 1486 | RDMA_PS_TCP, IB_QPT_RC); |
Julia Lawall | 10f3206 | 2008-04-16 21:09:25 -0700 | [diff] [blame] | 1487 | if (IS_ERR(new_cm_id)) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1488 | ret = -ENOMEM; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | conn_id = container_of(new_cm_id, struct rdma_id_private, id); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1492 | mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1493 | conn_id->state = RDMA_CM_CONNECT; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1494 | |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1495 | ret = rdma_translate_ip(laddr, &conn_id->id.route.addr.dev_addr, NULL); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1496 | if (ret) { |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1497 | mutex_unlock(&conn_id->handler_mutex); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1498 | rdma_destroy_id(new_cm_id); |
| 1499 | goto out; |
| 1500 | } |
| 1501 | |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 1502 | ret = cma_acquire_dev(conn_id, listen_id); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1503 | if (ret) { |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1504 | mutex_unlock(&conn_id->handler_mutex); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1505 | rdma_destroy_id(new_cm_id); |
| 1506 | goto out; |
| 1507 | } |
| 1508 | |
| 1509 | conn_id->cm_id.iw = cm_id; |
| 1510 | cm_id->context = conn_id; |
| 1511 | cm_id->cm_handler = cma_iw_handler; |
| 1512 | |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1513 | memcpy(cma_src_addr(conn_id), laddr, rdma_addr_size(laddr)); |
| 1514 | memcpy(cma_dst_addr(conn_id), raddr, rdma_addr_size(raddr)); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1515 | |
Steve Wise | 8d8293c | 2007-10-29 11:34:05 -0500 | [diff] [blame] | 1516 | ret = ib_query_device(conn_id->id.device, &attr); |
| 1517 | if (ret) { |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1518 | mutex_unlock(&conn_id->handler_mutex); |
Steve Wise | 8d8293c | 2007-10-29 11:34:05 -0500 | [diff] [blame] | 1519 | rdma_destroy_id(new_cm_id); |
| 1520 | goto out; |
| 1521 | } |
| 1522 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1523 | memset(&event, 0, sizeof event); |
| 1524 | event.event = RDMA_CM_EVENT_CONNECT_REQUEST; |
| 1525 | event.param.conn.private_data = iw_event->private_data; |
| 1526 | event.param.conn.private_data_len = iw_event->private_data_len; |
Kumar Sanghvi | 3ebeebc | 2011-09-25 20:17:43 +0530 | [diff] [blame] | 1527 | event.param.conn.initiator_depth = iw_event->ird; |
| 1528 | event.param.conn.responder_resources = iw_event->ord; |
Sean Hefty | 25ae21a | 2011-02-23 08:11:32 -0800 | [diff] [blame] | 1529 | |
| 1530 | /* |
| 1531 | * Protect against the user destroying conn_id from another thread |
| 1532 | * until we're done accessing it. |
| 1533 | */ |
| 1534 | atomic_inc(&conn_id->refcount); |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 1535 | ret = conn_id->id.event_handler(&conn_id->id, &event); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1536 | if (ret) { |
| 1537 | /* User wants to destroy the CM ID */ |
| 1538 | conn_id->cm_id.iw = NULL; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1539 | cma_exch(conn_id, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1540 | mutex_unlock(&conn_id->handler_mutex); |
Sean Hefty | 25ae21a | 2011-02-23 08:11:32 -0800 | [diff] [blame] | 1541 | cma_deref_id(conn_id); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1542 | rdma_destroy_id(&conn_id->id); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1543 | goto out; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1544 | } |
| 1545 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1546 | mutex_unlock(&conn_id->handler_mutex); |
Sean Hefty | 25ae21a | 2011-02-23 08:11:32 -0800 | [diff] [blame] | 1547 | cma_deref_id(conn_id); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1548 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1549 | out: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1550 | mutex_unlock(&listen_id->handler_mutex); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1551 | return ret; |
| 1552 | } |
| 1553 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1554 | static int cma_ib_listen(struct rdma_id_private *id_priv) |
| 1555 | { |
| 1556 | struct ib_cm_compare_data compare_data; |
| 1557 | struct sockaddr *addr; |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1558 | struct ib_cm_id *id; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1559 | __be64 svc_id; |
| 1560 | int ret; |
| 1561 | |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1562 | id = ib_create_cm_id(id_priv->id.device, cma_req_handler, id_priv); |
| 1563 | if (IS_ERR(id)) |
| 1564 | return PTR_ERR(id); |
| 1565 | |
| 1566 | id_priv->cm_id.ib = id; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1567 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1568 | addr = cma_src_addr(id_priv); |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 1569 | svc_id = rdma_get_service_id(&id_priv->id, addr); |
Sean Hefty | 406b6a2 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 1570 | if (cma_any_addr(addr) && !id_priv->afonly) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1571 | ret = ib_cm_listen(id_priv->cm_id.ib, svc_id, 0, NULL); |
| 1572 | else { |
| 1573 | cma_set_compare_data(id_priv->id.ps, addr, &compare_data); |
| 1574 | ret = ib_cm_listen(id_priv->cm_id.ib, svc_id, 0, &compare_data); |
| 1575 | } |
| 1576 | |
| 1577 | if (ret) { |
| 1578 | ib_destroy_cm_id(id_priv->cm_id.ib); |
| 1579 | id_priv->cm_id.ib = NULL; |
| 1580 | } |
| 1581 | |
| 1582 | return ret; |
| 1583 | } |
| 1584 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1585 | static int cma_iw_listen(struct rdma_id_private *id_priv, int backlog) |
| 1586 | { |
| 1587 | int ret; |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1588 | struct iw_cm_id *id; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1589 | |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 1590 | id = iw_create_cm_id(id_priv->id.device, |
| 1591 | iw_conn_req_handler, |
| 1592 | id_priv); |
| 1593 | if (IS_ERR(id)) |
| 1594 | return PTR_ERR(id); |
| 1595 | |
| 1596 | id_priv->cm_id.iw = id; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1597 | |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 1598 | memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), |
| 1599 | rdma_addr_size(cma_src_addr(id_priv))); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1600 | |
| 1601 | ret = iw_cm_listen(id_priv->cm_id.iw, backlog); |
| 1602 | |
| 1603 | if (ret) { |
| 1604 | iw_destroy_cm_id(id_priv->cm_id.iw); |
| 1605 | id_priv->cm_id.iw = NULL; |
| 1606 | } |
| 1607 | |
| 1608 | return ret; |
| 1609 | } |
| 1610 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1611 | static int cma_listen_handler(struct rdma_cm_id *id, |
| 1612 | struct rdma_cm_event *event) |
| 1613 | { |
| 1614 | struct rdma_id_private *id_priv = id->context; |
| 1615 | |
| 1616 | id->context = id_priv->id.context; |
| 1617 | id->event_handler = id_priv->id.event_handler; |
| 1618 | return id_priv->id.event_handler(id, event); |
| 1619 | } |
| 1620 | |
| 1621 | static void cma_listen_on_dev(struct rdma_id_private *id_priv, |
| 1622 | struct cma_device *cma_dev) |
| 1623 | { |
| 1624 | struct rdma_id_private *dev_id_priv; |
| 1625 | struct rdma_cm_id *id; |
| 1626 | int ret; |
| 1627 | |
Sean Hefty | 94d0c93 | 2013-05-29 10:09:24 -0700 | [diff] [blame] | 1628 | if (cma_family(id_priv) == AF_IB && |
| 1629 | rdma_node_get_transport(cma_dev->device->node_type) != RDMA_TRANSPORT_IB) |
| 1630 | return; |
| 1631 | |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 1632 | id = rdma_create_id(cma_listen_handler, id_priv, id_priv->id.ps, |
| 1633 | id_priv->id.qp_type); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1634 | if (IS_ERR(id)) |
| 1635 | return; |
| 1636 | |
| 1637 | dev_id_priv = container_of(id, struct rdma_id_private, id); |
| 1638 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1639 | dev_id_priv->state = RDMA_CM_ADDR_BOUND; |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1640 | memcpy(cma_src_addr(dev_id_priv), cma_src_addr(id_priv), |
| 1641 | rdma_addr_size(cma_src_addr(id_priv))); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1642 | |
| 1643 | cma_attach_to_dev(dev_id_priv, cma_dev); |
| 1644 | list_add_tail(&dev_id_priv->listen_list, &id_priv->listen_list); |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 1645 | atomic_inc(&id_priv->refcount); |
| 1646 | dev_id_priv->internal_id = 1; |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 1647 | dev_id_priv->afonly = id_priv->afonly; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1648 | |
| 1649 | ret = rdma_listen(id, id_priv->backlog); |
| 1650 | if (ret) |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 1651 | printk(KERN_WARNING "RDMA CMA: cma_listen_on_dev, error %d, " |
Roland Dreier | 468f223 | 2008-07-14 23:48:47 -0700 | [diff] [blame] | 1652 | "listening on device %s\n", ret, cma_dev->device->name); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | static void cma_listen_on_all(struct rdma_id_private *id_priv) |
| 1656 | { |
| 1657 | struct cma_device *cma_dev; |
| 1658 | |
| 1659 | mutex_lock(&lock); |
| 1660 | list_add_tail(&id_priv->list, &listen_any_list); |
| 1661 | list_for_each_entry(cma_dev, &dev_list, list) |
| 1662 | cma_listen_on_dev(id_priv, cma_dev); |
| 1663 | mutex_unlock(&lock); |
| 1664 | } |
| 1665 | |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1666 | void rdma_set_service_type(struct rdma_cm_id *id, int tos) |
| 1667 | { |
| 1668 | struct rdma_id_private *id_priv; |
| 1669 | |
| 1670 | id_priv = container_of(id, struct rdma_id_private, id); |
| 1671 | id_priv->tos = (u8) tos; |
| 1672 | } |
| 1673 | EXPORT_SYMBOL(rdma_set_service_type); |
| 1674 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1675 | static void cma_query_handler(int status, struct ib_sa_path_rec *path_rec, |
| 1676 | void *context) |
| 1677 | { |
| 1678 | struct cma_work *work = context; |
| 1679 | struct rdma_route *route; |
| 1680 | |
| 1681 | route = &work->id->id.route; |
| 1682 | |
| 1683 | if (!status) { |
| 1684 | route->num_paths = 1; |
| 1685 | *route->path_rec = *path_rec; |
| 1686 | } else { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1687 | work->old_state = RDMA_CM_ROUTE_QUERY; |
| 1688 | work->new_state = RDMA_CM_ADDR_RESOLVED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1689 | work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; |
Sean Hefty | 8f0472d | 2006-09-29 11:57:09 -0700 | [diff] [blame] | 1690 | work->event.status = status; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | queue_work(cma_wq, &work->work); |
| 1694 | } |
| 1695 | |
| 1696 | static int cma_query_ib_route(struct rdma_id_private *id_priv, int timeout_ms, |
| 1697 | struct cma_work *work) |
| 1698 | { |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1699 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1700 | struct ib_sa_path_rec path_rec; |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1701 | ib_sa_comp_mask comp_mask; |
| 1702 | struct sockaddr_in6 *sin6; |
Sean Hefty | f68194c | 2013-05-29 10:09:18 -0700 | [diff] [blame] | 1703 | struct sockaddr_ib *sib; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1704 | |
| 1705 | memset(&path_rec, 0, sizeof path_rec); |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1706 | rdma_addr_get_sgid(dev_addr, &path_rec.sgid); |
| 1707 | rdma_addr_get_dgid(dev_addr, &path_rec.dgid); |
| 1708 | path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr)); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1709 | path_rec.numb_path = 1; |
Sean Hefty | 962063e | 2007-02-21 16:40:44 -0800 | [diff] [blame] | 1710 | path_rec.reversible = 1; |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 1711 | path_rec.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1712 | |
| 1713 | comp_mask = IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID | |
| 1714 | IB_SA_PATH_REC_PKEY | IB_SA_PATH_REC_NUMB_PATH | |
| 1715 | IB_SA_PATH_REC_REVERSIBLE | IB_SA_PATH_REC_SERVICE_ID; |
| 1716 | |
Sean Hefty | f68194c | 2013-05-29 10:09:18 -0700 | [diff] [blame] | 1717 | switch (cma_family(id_priv)) { |
| 1718 | case AF_INET: |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1719 | path_rec.qos_class = cpu_to_be16((u16) id_priv->tos); |
| 1720 | comp_mask |= IB_SA_PATH_REC_QOS_CLASS; |
Sean Hefty | f68194c | 2013-05-29 10:09:18 -0700 | [diff] [blame] | 1721 | break; |
| 1722 | case AF_INET6: |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 1723 | sin6 = (struct sockaddr_in6 *) cma_src_addr(id_priv); |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1724 | path_rec.traffic_class = (u8) (be32_to_cpu(sin6->sin6_flowinfo) >> 20); |
| 1725 | comp_mask |= IB_SA_PATH_REC_TRAFFIC_CLASS; |
Sean Hefty | f68194c | 2013-05-29 10:09:18 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | case AF_IB: |
| 1728 | sib = (struct sockaddr_ib *) cma_src_addr(id_priv); |
| 1729 | path_rec.traffic_class = (u8) (be32_to_cpu(sib->sib_flowinfo) >> 20); |
| 1730 | comp_mask |= IB_SA_PATH_REC_TRAFFIC_CLASS; |
| 1731 | break; |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1732 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1733 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 1734 | id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, |
Sean Hefty | a81c994 | 2007-08-08 15:51:06 -0700 | [diff] [blame] | 1735 | id_priv->id.port_num, &path_rec, |
| 1736 | comp_mask, timeout_ms, |
| 1737 | GFP_KERNEL, cma_query_handler, |
| 1738 | work, &id_priv->query); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1739 | |
| 1740 | return (id_priv->query_id < 0) ? id_priv->query_id : 0; |
| 1741 | } |
| 1742 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1743 | static void cma_work_handler(struct work_struct *_work) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1744 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1745 | struct cma_work *work = container_of(_work, struct cma_work, work); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1746 | struct rdma_id_private *id_priv = work->id; |
| 1747 | int destroy = 0; |
| 1748 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1749 | mutex_lock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1750 | if (!cma_comp_exch(id_priv, work->old_state, work->new_state)) |
| 1751 | goto out; |
| 1752 | |
| 1753 | if (id_priv->id.event_handler(&id_priv->id, &work->event)) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1754 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1755 | destroy = 1; |
| 1756 | } |
| 1757 | out: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 1758 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1759 | cma_deref_id(id_priv); |
| 1760 | if (destroy) |
| 1761 | rdma_destroy_id(&id_priv->id); |
| 1762 | kfree(work); |
| 1763 | } |
| 1764 | |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 1765 | static void cma_ndev_work_handler(struct work_struct *_work) |
| 1766 | { |
| 1767 | struct cma_ndev_work *work = container_of(_work, struct cma_ndev_work, work); |
| 1768 | struct rdma_id_private *id_priv = work->id; |
| 1769 | int destroy = 0; |
| 1770 | |
| 1771 | mutex_lock(&id_priv->handler_mutex); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1772 | if (id_priv->state == RDMA_CM_DESTROYING || |
| 1773 | id_priv->state == RDMA_CM_DEVICE_REMOVAL) |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 1774 | goto out; |
| 1775 | |
| 1776 | if (id_priv->id.event_handler(&id_priv->id, &work->event)) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1777 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 1778 | destroy = 1; |
| 1779 | } |
| 1780 | |
| 1781 | out: |
| 1782 | mutex_unlock(&id_priv->handler_mutex); |
| 1783 | cma_deref_id(id_priv); |
| 1784 | if (destroy) |
| 1785 | rdma_destroy_id(&id_priv->id); |
| 1786 | kfree(work); |
| 1787 | } |
| 1788 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1789 | static int cma_resolve_ib_route(struct rdma_id_private *id_priv, int timeout_ms) |
| 1790 | { |
| 1791 | struct rdma_route *route = &id_priv->id.route; |
| 1792 | struct cma_work *work; |
| 1793 | int ret; |
| 1794 | |
| 1795 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 1796 | if (!work) |
| 1797 | return -ENOMEM; |
| 1798 | |
| 1799 | work->id = id_priv; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1800 | INIT_WORK(&work->work, cma_work_handler); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1801 | work->old_state = RDMA_CM_ROUTE_QUERY; |
| 1802 | work->new_state = RDMA_CM_ROUTE_RESOLVED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1803 | work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; |
| 1804 | |
| 1805 | route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); |
| 1806 | if (!route->path_rec) { |
| 1807 | ret = -ENOMEM; |
| 1808 | goto err1; |
| 1809 | } |
| 1810 | |
| 1811 | ret = cma_query_ib_route(id_priv, timeout_ms, work); |
| 1812 | if (ret) |
| 1813 | goto err2; |
| 1814 | |
| 1815 | return 0; |
| 1816 | err2: |
| 1817 | kfree(route->path_rec); |
| 1818 | route->path_rec = NULL; |
| 1819 | err1: |
| 1820 | kfree(work); |
| 1821 | return ret; |
| 1822 | } |
| 1823 | |
| 1824 | int rdma_set_ib_paths(struct rdma_cm_id *id, |
| 1825 | struct ib_sa_path_rec *path_rec, int num_paths) |
| 1826 | { |
| 1827 | struct rdma_id_private *id_priv; |
| 1828 | int ret; |
| 1829 | |
| 1830 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1831 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, |
| 1832 | RDMA_CM_ROUTE_RESOLVED)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1833 | return -EINVAL; |
| 1834 | |
Julia Lawall | 9893e74 | 2010-05-15 23:22:38 +0200 | [diff] [blame] | 1835 | id->route.path_rec = kmemdup(path_rec, sizeof *path_rec * num_paths, |
| 1836 | GFP_KERNEL); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1837 | if (!id->route.path_rec) { |
| 1838 | ret = -ENOMEM; |
| 1839 | goto err; |
| 1840 | } |
| 1841 | |
Sean Hefty | ae2d929 | 2010-03-25 19:12:36 +0000 | [diff] [blame] | 1842 | id->route.num_paths = num_paths; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1843 | return 0; |
| 1844 | err: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1845 | cma_comp_exch(id_priv, RDMA_CM_ROUTE_RESOLVED, RDMA_CM_ADDR_RESOLVED); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1846 | return ret; |
| 1847 | } |
| 1848 | EXPORT_SYMBOL(rdma_set_ib_paths); |
| 1849 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1850 | static int cma_resolve_iw_route(struct rdma_id_private *id_priv, int timeout_ms) |
| 1851 | { |
| 1852 | struct cma_work *work; |
| 1853 | |
| 1854 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 1855 | if (!work) |
| 1856 | return -ENOMEM; |
| 1857 | |
| 1858 | work->id = id_priv; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1859 | INIT_WORK(&work->work, cma_work_handler); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1860 | work->old_state = RDMA_CM_ROUTE_QUERY; |
| 1861 | work->new_state = RDMA_CM_ROUTE_RESOLVED; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1862 | work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; |
| 1863 | queue_work(cma_wq, &work->work); |
| 1864 | return 0; |
| 1865 | } |
| 1866 | |
Eyal Perry | eb072c4 | 2013-11-06 15:37:24 +0200 | [diff] [blame] | 1867 | static int iboe_tos_to_sl(struct net_device *ndev, int tos) |
| 1868 | { |
| 1869 | int prio; |
| 1870 | struct net_device *dev; |
| 1871 | |
| 1872 | prio = rt_tos2priority(tos); |
| 1873 | dev = ndev->priv_flags & IFF_802_1Q_VLAN ? |
| 1874 | vlan_dev_real_dev(ndev) : ndev; |
| 1875 | |
| 1876 | if (dev->num_tc) |
| 1877 | return netdev_get_prio_tc_map(dev, prio); |
| 1878 | |
| 1879 | #if IS_ENABLED(CONFIG_VLAN_8021Q) |
| 1880 | if (ndev->priv_flags & IFF_802_1Q_VLAN) |
| 1881 | return (vlan_dev_get_egress_qos_mask(ndev, prio) & |
| 1882 | VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 1883 | #endif |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1887 | static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) |
| 1888 | { |
| 1889 | struct rdma_route *route = &id_priv->id.route; |
| 1890 | struct rdma_addr *addr = &route->addr; |
| 1891 | struct cma_work *work; |
| 1892 | int ret; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1893 | struct net_device *ndev = NULL; |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1894 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1895 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1896 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 1897 | if (!work) |
| 1898 | return -ENOMEM; |
| 1899 | |
| 1900 | work->id = id_priv; |
| 1901 | INIT_WORK(&work->work, cma_work_handler); |
| 1902 | |
| 1903 | route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL); |
| 1904 | if (!route->path_rec) { |
| 1905 | ret = -ENOMEM; |
| 1906 | goto err1; |
| 1907 | } |
| 1908 | |
| 1909 | route->num_paths = 1; |
| 1910 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1911 | if (addr->dev_addr.bound_dev_if) |
| 1912 | ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if); |
| 1913 | if (!ndev) { |
| 1914 | ret = -ENODEV; |
| 1915 | goto err2; |
| 1916 | } |
| 1917 | |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1918 | route->path_rec->vlan_id = rdma_vlan_dev_vlan_id(ndev); |
| 1919 | memcpy(route->path_rec->dmac, addr->dev_addr.dst_dev_addr, ETH_ALEN); |
| 1920 | memcpy(route->path_rec->smac, ndev->dev_addr, ndev->addr_len); |
Eli Cohen | af7bd46 | 2010-08-26 17:18:59 +0300 | [diff] [blame] | 1921 | |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 1922 | rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 1923 | &route->path_rec->sgid); |
| 1924 | rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, |
| 1925 | &route->path_rec->dgid); |
Eli Cohen | af7bd46 | 2010-08-26 17:18:59 +0300 | [diff] [blame] | 1926 | |
| 1927 | route->path_rec->hop_limit = 1; |
| 1928 | route->path_rec->reversible = 1; |
| 1929 | route->path_rec->pkey = cpu_to_be16(0xffff); |
| 1930 | route->path_rec->mtu_selector = IB_SA_EQ; |
Eyal Perry | eb072c4 | 2013-11-06 15:37:24 +0200 | [diff] [blame] | 1931 | route->path_rec->sl = iboe_tos_to_sl(ndev, id_priv->tos); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1932 | route->path_rec->mtu = iboe_get_mtu(ndev->mtu); |
| 1933 | route->path_rec->rate_selector = IB_SA_EQ; |
| 1934 | route->path_rec->rate = iboe_get_rate(ndev); |
| 1935 | dev_put(ndev); |
| 1936 | route->path_rec->packet_life_time_selector = IB_SA_EQ; |
| 1937 | route->path_rec->packet_life_time = CMA_IBOE_PACKET_LIFETIME; |
| 1938 | if (!route->path_rec->mtu) { |
| 1939 | ret = -EINVAL; |
| 1940 | goto err2; |
| 1941 | } |
| 1942 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1943 | work->old_state = RDMA_CM_ROUTE_QUERY; |
| 1944 | work->new_state = RDMA_CM_ROUTE_RESOLVED; |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1945 | work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; |
| 1946 | work->event.status = 0; |
| 1947 | |
| 1948 | queue_work(cma_wq, &work->work); |
| 1949 | |
| 1950 | return 0; |
| 1951 | |
| 1952 | err2: |
| 1953 | kfree(route->path_rec); |
| 1954 | route->path_rec = NULL; |
| 1955 | err1: |
| 1956 | kfree(work); |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1960 | int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms) |
| 1961 | { |
| 1962 | struct rdma_id_private *id_priv; |
| 1963 | int ret; |
| 1964 | |
| 1965 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1966 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, RDMA_CM_ROUTE_QUERY)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1967 | return -EINVAL; |
| 1968 | |
| 1969 | atomic_inc(&id_priv->refcount); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1970 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 1971 | case RDMA_TRANSPORT_IB: |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 1972 | switch (rdma_port_get_link_layer(id->device, id->port_num)) { |
| 1973 | case IB_LINK_LAYER_INFINIBAND: |
| 1974 | ret = cma_resolve_ib_route(id_priv, timeout_ms); |
| 1975 | break; |
| 1976 | case IB_LINK_LAYER_ETHERNET: |
| 1977 | ret = cma_resolve_iboe_route(id_priv); |
| 1978 | break; |
| 1979 | default: |
| 1980 | ret = -ENOSYS; |
| 1981 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1982 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 1983 | case RDMA_TRANSPORT_IWARP: |
| 1984 | ret = cma_resolve_iw_route(id_priv, timeout_ms); |
| 1985 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1986 | default: |
| 1987 | ret = -ENOSYS; |
| 1988 | break; |
| 1989 | } |
| 1990 | if (ret) |
| 1991 | goto err; |
| 1992 | |
| 1993 | return 0; |
| 1994 | err: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 1995 | cma_comp_exch(id_priv, RDMA_CM_ROUTE_QUERY, RDMA_CM_ADDR_RESOLVED); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 1996 | cma_deref_id(id_priv); |
| 1997 | return ret; |
| 1998 | } |
| 1999 | EXPORT_SYMBOL(rdma_resolve_route); |
| 2000 | |
Sean Hefty | 6a3e362 | 2013-05-29 10:09:13 -0700 | [diff] [blame] | 2001 | static void cma_set_loopback(struct sockaddr *addr) |
| 2002 | { |
| 2003 | switch (addr->sa_family) { |
| 2004 | case AF_INET: |
| 2005 | ((struct sockaddr_in *) addr)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
| 2006 | break; |
| 2007 | case AF_INET6: |
| 2008 | ipv6_addr_set(&((struct sockaddr_in6 *) addr)->sin6_addr, |
| 2009 | 0, 0, 0, htonl(1)); |
| 2010 | break; |
| 2011 | default: |
| 2012 | ib_addr_set(&((struct sockaddr_ib *) addr)->sib_addr, |
| 2013 | 0, 0, 0, htonl(1)); |
| 2014 | break; |
| 2015 | } |
| 2016 | } |
| 2017 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2018 | static int cma_bind_loopback(struct rdma_id_private *id_priv) |
| 2019 | { |
Sean Hefty | b0569e4 | 2013-05-29 10:09:15 -0700 | [diff] [blame] | 2020 | struct cma_device *cma_dev, *cur_dev; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2021 | struct ib_port_attr port_attr; |
Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 2022 | union ib_gid gid; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2023 | u16 pkey; |
| 2024 | int ret; |
| 2025 | u8 p; |
| 2026 | |
Sean Hefty | b0569e4 | 2013-05-29 10:09:15 -0700 | [diff] [blame] | 2027 | cma_dev = NULL; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2028 | mutex_lock(&lock); |
Sean Hefty | b0569e4 | 2013-05-29 10:09:15 -0700 | [diff] [blame] | 2029 | list_for_each_entry(cur_dev, &dev_list, list) { |
| 2030 | if (cma_family(id_priv) == AF_IB && |
| 2031 | rdma_node_get_transport(cur_dev->device->node_type) != RDMA_TRANSPORT_IB) |
| 2032 | continue; |
| 2033 | |
| 2034 | if (!cma_dev) |
| 2035 | cma_dev = cur_dev; |
| 2036 | |
| 2037 | for (p = 1; p <= cur_dev->device->phys_port_cnt; ++p) { |
| 2038 | if (!ib_query_port(cur_dev->device, p, &port_attr) && |
| 2039 | port_attr.state == IB_PORT_ACTIVE) { |
| 2040 | cma_dev = cur_dev; |
| 2041 | goto port_found; |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | |
| 2046 | if (!cma_dev) { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2047 | ret = -ENODEV; |
| 2048 | goto out; |
| 2049 | } |
Krishna Kumar | e82153b | 2006-10-16 10:09:01 +0530 | [diff] [blame] | 2050 | |
| 2051 | p = 1; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2052 | |
| 2053 | port_found: |
Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 2054 | ret = ib_get_cached_gid(cma_dev->device, p, 0, &gid); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2055 | if (ret) |
| 2056 | goto out; |
| 2057 | |
| 2058 | ret = ib_get_cached_pkey(cma_dev->device, p, 0, &pkey); |
| 2059 | if (ret) |
| 2060 | goto out; |
| 2061 | |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 2062 | id_priv->id.route.addr.dev_addr.dev_type = |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 2063 | (rdma_port_get_link_layer(cma_dev->device, p) == IB_LINK_LAYER_INFINIBAND) ? |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 2064 | ARPHRD_INFINIBAND : ARPHRD_ETHER; |
| 2065 | |
| 2066 | rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2067 | ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); |
| 2068 | id_priv->id.port_num = p; |
| 2069 | cma_attach_to_dev(id_priv, cma_dev); |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2070 | cma_set_loopback(cma_src_addr(id_priv)); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2071 | out: |
| 2072 | mutex_unlock(&lock); |
| 2073 | return ret; |
| 2074 | } |
| 2075 | |
| 2076 | static void addr_handler(int status, struct sockaddr *src_addr, |
| 2077 | struct rdma_dev_addr *dev_addr, void *context) |
| 2078 | { |
| 2079 | struct rdma_id_private *id_priv = context; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 2080 | struct rdma_cm_event event; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2081 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 2082 | memset(&event, 0, sizeof event); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2083 | mutex_lock(&id_priv->handler_mutex); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2084 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, |
| 2085 | RDMA_CM_ADDR_RESOLVED)) |
Sean Hefty | 61a73c7 | 2006-09-01 15:33:55 -0700 | [diff] [blame] | 2086 | goto out; |
Sean Hefty | 61a73c7 | 2006-09-01 15:33:55 -0700 | [diff] [blame] | 2087 | |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 2088 | memcpy(cma_src_addr(id_priv), src_addr, rdma_addr_size(src_addr)); |
Sean Hefty | 61a73c7 | 2006-09-01 15:33:55 -0700 | [diff] [blame] | 2089 | if (!status && !id_priv->cma_dev) |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 2090 | status = cma_acquire_dev(id_priv, NULL); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2091 | |
| 2092 | if (status) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2093 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, |
| 2094 | RDMA_CM_ADDR_BOUND)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2095 | goto out; |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 2096 | event.event = RDMA_CM_EVENT_ADDR_ERROR; |
| 2097 | event.status = status; |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 2098 | } else |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 2099 | event.event = RDMA_CM_EVENT_ADDR_RESOLVED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2100 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 2101 | if (id_priv->id.event_handler(&id_priv->id, &event)) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2102 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2103 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2104 | cma_deref_id(id_priv); |
| 2105 | rdma_destroy_id(&id_priv->id); |
| 2106 | return; |
| 2107 | } |
| 2108 | out: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2109 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2110 | cma_deref_id(id_priv); |
| 2111 | } |
| 2112 | |
| 2113 | static int cma_resolve_loopback(struct rdma_id_private *id_priv) |
| 2114 | { |
| 2115 | struct cma_work *work; |
Michael S. Tsirkin | f0ee340 | 2006-07-14 00:23:52 -0700 | [diff] [blame] | 2116 | union ib_gid gid; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2117 | int ret; |
| 2118 | |
| 2119 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 2120 | if (!work) |
| 2121 | return -ENOMEM; |
| 2122 | |
| 2123 | if (!id_priv->cma_dev) { |
| 2124 | ret = cma_bind_loopback(id_priv); |
| 2125 | if (ret) |
| 2126 | goto err; |
| 2127 | } |
| 2128 | |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 2129 | rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); |
| 2130 | rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2131 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2132 | work->id = id_priv; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 2133 | INIT_WORK(&work->work, cma_work_handler); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2134 | work->old_state = RDMA_CM_ADDR_QUERY; |
| 2135 | work->new_state = RDMA_CM_ADDR_RESOLVED; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2136 | work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; |
| 2137 | queue_work(cma_wq, &work->work); |
| 2138 | return 0; |
| 2139 | err: |
| 2140 | kfree(work); |
| 2141 | return ret; |
| 2142 | } |
| 2143 | |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 2144 | static int cma_resolve_ib_addr(struct rdma_id_private *id_priv) |
| 2145 | { |
| 2146 | struct cma_work *work; |
| 2147 | int ret; |
| 2148 | |
| 2149 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 2150 | if (!work) |
| 2151 | return -ENOMEM; |
| 2152 | |
| 2153 | if (!id_priv->cma_dev) { |
| 2154 | ret = cma_resolve_ib_dev(id_priv); |
| 2155 | if (ret) |
| 2156 | goto err; |
| 2157 | } |
| 2158 | |
| 2159 | rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) |
| 2160 | &(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); |
| 2161 | |
| 2162 | work->id = id_priv; |
| 2163 | INIT_WORK(&work->work, cma_work_handler); |
| 2164 | work->old_state = RDMA_CM_ADDR_QUERY; |
| 2165 | work->new_state = RDMA_CM_ADDR_RESOLVED; |
| 2166 | work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; |
| 2167 | queue_work(cma_wq, &work->work); |
| 2168 | return 0; |
| 2169 | err: |
| 2170 | kfree(work); |
| 2171 | return ret; |
| 2172 | } |
| 2173 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2174 | static int cma_bind_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, |
| 2175 | struct sockaddr *dst_addr) |
| 2176 | { |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2177 | if (!src_addr || !src_addr->sa_family) { |
| 2178 | src_addr = (struct sockaddr *) &id->route.addr.src_addr; |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 2179 | src_addr->sa_family = dst_addr->sa_family; |
| 2180 | if (dst_addr->sa_family == AF_INET6) { |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2181 | ((struct sockaddr_in6 *) src_addr)->sin6_scope_id = |
| 2182 | ((struct sockaddr_in6 *) dst_addr)->sin6_scope_id; |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 2183 | } else if (dst_addr->sa_family == AF_IB) { |
| 2184 | ((struct sockaddr_ib *) src_addr)->sib_pkey = |
| 2185 | ((struct sockaddr_ib *) dst_addr)->sib_pkey; |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | return rdma_bind_addr(id, src_addr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, |
| 2192 | struct sockaddr *dst_addr, int timeout_ms) |
| 2193 | { |
| 2194 | struct rdma_id_private *id_priv; |
| 2195 | int ret; |
| 2196 | |
| 2197 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2198 | if (id_priv->state == RDMA_CM_IDLE) { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2199 | ret = cma_bind_addr(id, src_addr, dst_addr); |
| 2200 | if (ret) |
| 2201 | return ret; |
| 2202 | } |
| 2203 | |
Sean Hefty | 4ae7152 | 2013-05-29 10:09:16 -0700 | [diff] [blame] | 2204 | if (cma_family(id_priv) != dst_addr->sa_family) |
| 2205 | return -EINVAL; |
| 2206 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2207 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_ADDR_QUERY)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2208 | return -EINVAL; |
| 2209 | |
| 2210 | atomic_inc(&id_priv->refcount); |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2211 | memcpy(cma_dst_addr(id_priv), dst_addr, rdma_addr_size(dst_addr)); |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 2212 | if (cma_any_addr(dst_addr)) { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2213 | ret = cma_resolve_loopback(id_priv); |
Sean Hefty | f17df3b | 2013-05-29 10:09:17 -0700 | [diff] [blame] | 2214 | } else { |
| 2215 | if (dst_addr->sa_family == AF_IB) { |
| 2216 | ret = cma_resolve_ib_addr(id_priv); |
| 2217 | } else { |
| 2218 | ret = rdma_resolve_ip(&addr_client, cma_src_addr(id_priv), |
| 2219 | dst_addr, &id->route.addr.dev_addr, |
| 2220 | timeout_ms, addr_handler, id_priv); |
| 2221 | } |
| 2222 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2223 | if (ret) |
| 2224 | goto err; |
| 2225 | |
| 2226 | return 0; |
| 2227 | err: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2228 | cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, RDMA_CM_ADDR_BOUND); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2229 | cma_deref_id(id_priv); |
| 2230 | return ret; |
| 2231 | } |
| 2232 | EXPORT_SYMBOL(rdma_resolve_addr); |
| 2233 | |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2234 | int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse) |
| 2235 | { |
| 2236 | struct rdma_id_private *id_priv; |
| 2237 | unsigned long flags; |
| 2238 | int ret; |
| 2239 | |
| 2240 | id_priv = container_of(id, struct rdma_id_private, id); |
| 2241 | spin_lock_irqsave(&id_priv->lock, flags); |
Sean Hefty | c8dea2f9 | 2013-05-29 10:09:08 -0700 | [diff] [blame] | 2242 | if (reuse || id_priv->state == RDMA_CM_IDLE) { |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2243 | id_priv->reuseaddr = reuse; |
| 2244 | ret = 0; |
| 2245 | } else { |
| 2246 | ret = -EINVAL; |
| 2247 | } |
| 2248 | spin_unlock_irqrestore(&id_priv->lock, flags); |
| 2249 | return ret; |
| 2250 | } |
| 2251 | EXPORT_SYMBOL(rdma_set_reuseaddr); |
| 2252 | |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2253 | int rdma_set_afonly(struct rdma_cm_id *id, int afonly) |
| 2254 | { |
| 2255 | struct rdma_id_private *id_priv; |
| 2256 | unsigned long flags; |
| 2257 | int ret; |
| 2258 | |
| 2259 | id_priv = container_of(id, struct rdma_id_private, id); |
| 2260 | spin_lock_irqsave(&id_priv->lock, flags); |
| 2261 | if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) { |
| 2262 | id_priv->options |= (1 << CMA_OPTION_AFONLY); |
| 2263 | id_priv->afonly = afonly; |
| 2264 | ret = 0; |
| 2265 | } else { |
| 2266 | ret = -EINVAL; |
| 2267 | } |
| 2268 | spin_unlock_irqrestore(&id_priv->lock, flags); |
| 2269 | return ret; |
| 2270 | } |
| 2271 | EXPORT_SYMBOL(rdma_set_afonly); |
| 2272 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2273 | static void cma_bind_port(struct rdma_bind_list *bind_list, |
| 2274 | struct rdma_id_private *id_priv) |
| 2275 | { |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2276 | struct sockaddr *addr; |
| 2277 | struct sockaddr_ib *sib; |
| 2278 | u64 sid, mask; |
| 2279 | __be16 port; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2280 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2281 | addr = cma_src_addr(id_priv); |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2282 | port = htons(bind_list->port); |
| 2283 | |
| 2284 | switch (addr->sa_family) { |
| 2285 | case AF_INET: |
| 2286 | ((struct sockaddr_in *) addr)->sin_port = port; |
| 2287 | break; |
| 2288 | case AF_INET6: |
| 2289 | ((struct sockaddr_in6 *) addr)->sin6_port = port; |
| 2290 | break; |
| 2291 | case AF_IB: |
| 2292 | sib = (struct sockaddr_ib *) addr; |
| 2293 | sid = be64_to_cpu(sib->sib_sid); |
| 2294 | mask = be64_to_cpu(sib->sib_sid_mask); |
| 2295 | sib->sib_sid = cpu_to_be64((sid & mask) | (u64) ntohs(port)); |
| 2296 | sib->sib_sid_mask = cpu_to_be64(~0ULL); |
| 2297 | break; |
| 2298 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2299 | id_priv->bind_list = bind_list; |
| 2300 | hlist_add_head(&id_priv->node, &bind_list->owners); |
| 2301 | } |
| 2302 | |
| 2303 | static int cma_alloc_port(struct idr *ps, struct rdma_id_private *id_priv, |
| 2304 | unsigned short snum) |
| 2305 | { |
| 2306 | struct rdma_bind_list *bind_list; |
Tejun Heo | 3b069c5 | 2013-02-27 17:04:16 -0800 | [diff] [blame] | 2307 | int ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2308 | |
Sean Hefty | cb164b8 | 2007-03-05 12:50:17 -0800 | [diff] [blame] | 2309 | bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2310 | if (!bind_list) |
| 2311 | return -ENOMEM; |
| 2312 | |
Tejun Heo | 3b069c5 | 2013-02-27 17:04:16 -0800 | [diff] [blame] | 2313 | ret = idr_alloc(ps, bind_list, snum, snum + 1, GFP_KERNEL); |
| 2314 | if (ret < 0) |
| 2315 | goto err; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2316 | |
| 2317 | bind_list->ps = ps; |
Tejun Heo | 3b069c5 | 2013-02-27 17:04:16 -0800 | [diff] [blame] | 2318 | bind_list->port = (unsigned short)ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2319 | cma_bind_port(bind_list, id_priv); |
| 2320 | return 0; |
Tejun Heo | 3b069c5 | 2013-02-27 17:04:16 -0800 | [diff] [blame] | 2321 | err: |
Sean Hefty | aedec08 | 2007-01-29 16:41:23 -0800 | [diff] [blame] | 2322 | kfree(bind_list); |
Tejun Heo | 3b069c5 | 2013-02-27 17:04:16 -0800 | [diff] [blame] | 2323 | return ret == -ENOSPC ? -EADDRNOTAVAIL : ret; |
Sean Hefty | aedec08 | 2007-01-29 16:41:23 -0800 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv) |
| 2327 | { |
Tetsuo Handa | 5d7220e8 | 2010-04-15 11:29:04 +0900 | [diff] [blame] | 2328 | static unsigned int last_used_port; |
| 2329 | int low, high, remaining; |
| 2330 | unsigned int rover; |
Sean Hefty | aedec08 | 2007-01-29 16:41:23 -0800 | [diff] [blame] | 2331 | |
Eric W. Biederman | 0bbf87d | 2013-09-28 14:10:59 -0700 | [diff] [blame] | 2332 | inet_get_local_port_range(&init_net, &low, &high); |
Tetsuo Handa | 5d7220e8 | 2010-04-15 11:29:04 +0900 | [diff] [blame] | 2333 | remaining = (high - low) + 1; |
Aruna-Hewapathirane | 63862b5 | 2014-01-11 07:15:59 -0500 | [diff] [blame] | 2334 | rover = prandom_u32() % remaining + low; |
Tetsuo Handa | 5d7220e8 | 2010-04-15 11:29:04 +0900 | [diff] [blame] | 2335 | retry: |
| 2336 | if (last_used_port != rover && |
| 2337 | !idr_find(ps, (unsigned short) rover)) { |
| 2338 | int ret = cma_alloc_port(ps, id_priv, rover); |
| 2339 | /* |
| 2340 | * Remember previously used port number in order to avoid |
| 2341 | * re-using same port immediately after it is closed. |
| 2342 | */ |
| 2343 | if (!ret) |
| 2344 | last_used_port = rover; |
| 2345 | if (ret != -EADDRNOTAVAIL) |
| 2346 | return ret; |
Sean Hefty | aedec08 | 2007-01-29 16:41:23 -0800 | [diff] [blame] | 2347 | } |
Tetsuo Handa | 5d7220e8 | 2010-04-15 11:29:04 +0900 | [diff] [blame] | 2348 | if (--remaining) { |
| 2349 | rover++; |
| 2350 | if ((rover < low) || (rover > high)) |
| 2351 | rover = low; |
| 2352 | goto retry; |
| 2353 | } |
| 2354 | return -EADDRNOTAVAIL; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2357 | /* |
| 2358 | * Check that the requested port is available. This is called when trying to |
| 2359 | * bind to a specific port, or when trying to listen on a bound port. In |
| 2360 | * the latter case, the provided id_priv may already be on the bind_list, but |
| 2361 | * we still need to check that it's okay to start listening. |
| 2362 | */ |
| 2363 | static int cma_check_port(struct rdma_bind_list *bind_list, |
| 2364 | struct rdma_id_private *id_priv, uint8_t reuseaddr) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2365 | { |
| 2366 | struct rdma_id_private *cur_id; |
Hefty, Sean | 43b752d | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2367 | struct sockaddr *addr, *cur_addr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2368 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2369 | addr = cma_src_addr(id_priv); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 2370 | hlist_for_each_entry(cur_id, &bind_list->owners, node) { |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2371 | if (id_priv == cur_id) |
| 2372 | continue; |
| 2373 | |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2374 | if ((cur_id->state != RDMA_CM_LISTEN) && reuseaddr && |
| 2375 | cur_id->reuseaddr) |
| 2376 | continue; |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2377 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2378 | cur_addr = cma_src_addr(cur_id); |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2379 | if (id_priv->afonly && cur_id->afonly && |
| 2380 | (addr->sa_family != cur_addr->sa_family)) |
| 2381 | continue; |
| 2382 | |
| 2383 | if (cma_any_addr(addr) || cma_any_addr(cur_addr)) |
| 2384 | return -EADDRNOTAVAIL; |
| 2385 | |
| 2386 | if (!cma_addr_cmp(addr, cur_addr)) |
| 2387 | return -EADDRINUSE; |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2388 | } |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
| 2392 | static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv) |
| 2393 | { |
| 2394 | struct rdma_bind_list *bind_list; |
| 2395 | unsigned short snum; |
| 2396 | int ret; |
| 2397 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2398 | snum = ntohs(cma_port(cma_src_addr(id_priv))); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2399 | if (snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) |
| 2400 | return -EACCES; |
| 2401 | |
| 2402 | bind_list = idr_find(ps, snum); |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2403 | if (!bind_list) { |
| 2404 | ret = cma_alloc_port(ps, id_priv, snum); |
| 2405 | } else { |
| 2406 | ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); |
| 2407 | if (!ret) |
| 2408 | cma_bind_port(bind_list, id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2409 | } |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2410 | return ret; |
| 2411 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2412 | |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2413 | static int cma_bind_listen(struct rdma_id_private *id_priv) |
| 2414 | { |
| 2415 | struct rdma_bind_list *bind_list = id_priv->bind_list; |
| 2416 | int ret = 0; |
| 2417 | |
| 2418 | mutex_lock(&lock); |
| 2419 | if (bind_list->owners.first->next) |
| 2420 | ret = cma_check_port(bind_list, id_priv, 0); |
| 2421 | mutex_unlock(&lock); |
| 2422 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2425 | static struct idr *cma_select_inet_ps(struct rdma_id_private *id_priv) |
| 2426 | { |
| 2427 | switch (id_priv->id.ps) { |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2428 | case RDMA_PS_TCP: |
| 2429 | return &tcp_ps; |
| 2430 | case RDMA_PS_UDP: |
| 2431 | return &udp_ps; |
| 2432 | case RDMA_PS_IPOIB: |
| 2433 | return &ipoib_ps; |
| 2434 | case RDMA_PS_IB: |
| 2435 | return &ib_ps; |
| 2436 | default: |
| 2437 | return NULL; |
| 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | static struct idr *cma_select_ib_ps(struct rdma_id_private *id_priv) |
| 2442 | { |
| 2443 | struct idr *ps = NULL; |
| 2444 | struct sockaddr_ib *sib; |
| 2445 | u64 sid_ps, mask, sid; |
| 2446 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2447 | sib = (struct sockaddr_ib *) cma_src_addr(id_priv); |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2448 | mask = be64_to_cpu(sib->sib_sid_mask) & RDMA_IB_IP_PS_MASK; |
| 2449 | sid = be64_to_cpu(sib->sib_sid) & mask; |
| 2450 | |
| 2451 | if ((id_priv->id.ps == RDMA_PS_IB) && (sid == (RDMA_IB_IP_PS_IB & mask))) { |
| 2452 | sid_ps = RDMA_IB_IP_PS_IB; |
| 2453 | ps = &ib_ps; |
| 2454 | } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_TCP)) && |
| 2455 | (sid == (RDMA_IB_IP_PS_TCP & mask))) { |
| 2456 | sid_ps = RDMA_IB_IP_PS_TCP; |
| 2457 | ps = &tcp_ps; |
| 2458 | } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_UDP)) && |
| 2459 | (sid == (RDMA_IB_IP_PS_UDP & mask))) { |
| 2460 | sid_ps = RDMA_IB_IP_PS_UDP; |
| 2461 | ps = &udp_ps; |
| 2462 | } |
| 2463 | |
| 2464 | if (ps) { |
| 2465 | sib->sib_sid = cpu_to_be64(sid_ps | ntohs(cma_port((struct sockaddr *) sib))); |
| 2466 | sib->sib_sid_mask = cpu_to_be64(RDMA_IB_IP_PS_MASK | |
| 2467 | be64_to_cpu(sib->sib_sid_mask)); |
| 2468 | } |
| 2469 | return ps; |
| 2470 | } |
| 2471 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2472 | static int cma_get_port(struct rdma_id_private *id_priv) |
| 2473 | { |
| 2474 | struct idr *ps; |
| 2475 | int ret; |
| 2476 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2477 | if (cma_family(id_priv) != AF_IB) |
Sean Hefty | 58afdcb | 2013-05-29 10:09:11 -0700 | [diff] [blame] | 2478 | ps = cma_select_inet_ps(id_priv); |
| 2479 | else |
| 2480 | ps = cma_select_ib_ps(id_priv); |
| 2481 | if (!ps) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2482 | return -EPROTONOSUPPORT; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2483 | |
| 2484 | mutex_lock(&lock); |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2485 | if (cma_any_port(cma_src_addr(id_priv))) |
Sean Hefty | aedec08 | 2007-01-29 16:41:23 -0800 | [diff] [blame] | 2486 | ret = cma_alloc_any_port(ps, id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2487 | else |
| 2488 | ret = cma_use_port(ps, id_priv); |
| 2489 | mutex_unlock(&lock); |
| 2490 | |
| 2491 | return ret; |
| 2492 | } |
| 2493 | |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2494 | static int cma_check_linklocal(struct rdma_dev_addr *dev_addr, |
| 2495 | struct sockaddr *addr) |
| 2496 | { |
Roland Dreier | d90f9b3 | 2012-07-05 22:39:34 -0700 | [diff] [blame] | 2497 | #if IS_ENABLED(CONFIG_IPV6) |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2498 | struct sockaddr_in6 *sin6; |
| 2499 | |
| 2500 | if (addr->sa_family != AF_INET6) |
| 2501 | return 0; |
| 2502 | |
| 2503 | sin6 = (struct sockaddr_in6 *) addr; |
Somnath Kotur | 5462edd | 2013-11-16 09:30:01 +0530 | [diff] [blame] | 2504 | |
| 2505 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) |
| 2506 | return 0; |
| 2507 | |
| 2508 | if (!sin6->sin6_scope_id) |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2509 | return -EINVAL; |
| 2510 | |
| 2511 | dev_addr->bound_dev_if = sin6->sin6_scope_id; |
| 2512 | #endif |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2516 | int rdma_listen(struct rdma_cm_id *id, int backlog) |
| 2517 | { |
| 2518 | struct rdma_id_private *id_priv; |
| 2519 | int ret; |
| 2520 | |
| 2521 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2522 | if (id_priv->state == RDMA_CM_IDLE) { |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2523 | id->route.addr.src_addr.ss_family = AF_INET; |
| 2524 | ret = rdma_bind_addr(id, cma_src_addr(id_priv)); |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2525 | if (ret) |
| 2526 | return ret; |
| 2527 | } |
| 2528 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2529 | if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_LISTEN)) |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2530 | return -EINVAL; |
| 2531 | |
| 2532 | if (id_priv->reuseaddr) { |
| 2533 | ret = cma_bind_listen(id_priv); |
| 2534 | if (ret) |
| 2535 | goto err; |
| 2536 | } |
| 2537 | |
| 2538 | id_priv->backlog = backlog; |
| 2539 | if (id->device) { |
| 2540 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 2541 | case RDMA_TRANSPORT_IB: |
| 2542 | ret = cma_ib_listen(id_priv); |
| 2543 | if (ret) |
| 2544 | goto err; |
| 2545 | break; |
| 2546 | case RDMA_TRANSPORT_IWARP: |
| 2547 | ret = cma_iw_listen(id_priv, backlog); |
| 2548 | if (ret) |
| 2549 | goto err; |
| 2550 | break; |
| 2551 | default: |
| 2552 | ret = -ENOSYS; |
| 2553 | goto err; |
| 2554 | } |
| 2555 | } else |
| 2556 | cma_listen_on_all(id_priv); |
| 2557 | |
| 2558 | return 0; |
| 2559 | err: |
| 2560 | id_priv->backlog = 0; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2561 | cma_comp_exch(id_priv, RDMA_CM_LISTEN, RDMA_CM_ADDR_BOUND); |
Hefty, Sean | a9bb791 | 2011-05-09 22:06:10 -0700 | [diff] [blame] | 2562 | return ret; |
| 2563 | } |
| 2564 | EXPORT_SYMBOL(rdma_listen); |
| 2565 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2566 | int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) |
| 2567 | { |
| 2568 | struct rdma_id_private *id_priv; |
| 2569 | int ret; |
| 2570 | |
Sean Hefty | 680f920 | 2013-05-29 10:09:12 -0700 | [diff] [blame] | 2571 | if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6 && |
| 2572 | addr->sa_family != AF_IB) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2573 | return -EAFNOSUPPORT; |
| 2574 | |
| 2575 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2576 | if (!cma_comp_exch(id_priv, RDMA_CM_IDLE, RDMA_CM_ADDR_BOUND)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2577 | return -EINVAL; |
| 2578 | |
Sean Hefty | d14714d | 2009-11-19 16:46:25 -0800 | [diff] [blame] | 2579 | ret = cma_check_linklocal(&id->route.addr.dev_addr, addr); |
| 2580 | if (ret) |
| 2581 | goto err1; |
| 2582 | |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 2583 | memcpy(cma_src_addr(id_priv), addr, rdma_addr_size(addr)); |
Sean Hefty | 8523c04 | 2010-02-08 16:41:15 -0800 | [diff] [blame] | 2584 | if (!cma_any_addr(addr)) { |
Sean Hefty | 680f920 | 2013-05-29 10:09:12 -0700 | [diff] [blame] | 2585 | ret = cma_translate_addr(addr, &id->route.addr.dev_addr); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2586 | if (ret) |
Krishna Kumar | 255d0c1 | 2006-10-24 13:22:28 -0700 | [diff] [blame] | 2587 | goto err1; |
| 2588 | |
Doug Ledford | be9130c | 2013-09-24 17:16:28 -0400 | [diff] [blame] | 2589 | ret = cma_acquire_dev(id_priv, NULL); |
Krishna Kumar | 255d0c1 | 2006-10-24 13:22:28 -0700 | [diff] [blame] | 2590 | if (ret) |
| 2591 | goto err1; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2594 | if (!(id_priv->options & (1 << CMA_OPTION_AFONLY))) { |
| 2595 | if (addr->sa_family == AF_INET) |
| 2596 | id_priv->afonly = 1; |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2597 | #if IS_ENABLED(CONFIG_IPV6) |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2598 | else if (addr->sa_family == AF_INET6) |
| 2599 | id_priv->afonly = init_net.ipv6.sysctl.bindv6only; |
Sean Hefty | 5b0ec99 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2600 | #endif |
Sean Hefty | 6860212 | 2012-06-14 20:31:39 +0000 | [diff] [blame] | 2601 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2602 | ret = cma_get_port(id_priv); |
| 2603 | if (ret) |
Krishna Kumar | 255d0c1 | 2006-10-24 13:22:28 -0700 | [diff] [blame] | 2604 | goto err2; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2605 | |
| 2606 | return 0; |
Krishna Kumar | 255d0c1 | 2006-10-24 13:22:28 -0700 | [diff] [blame] | 2607 | err2: |
Sean Hefty | a396d43 | 2011-02-23 09:05:39 -0800 | [diff] [blame] | 2608 | if (id_priv->cma_dev) |
| 2609 | cma_release_dev(id_priv); |
Krishna Kumar | 255d0c1 | 2006-10-24 13:22:28 -0700 | [diff] [blame] | 2610 | err1: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2611 | cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_IDLE); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2612 | return ret; |
| 2613 | } |
| 2614 | EXPORT_SYMBOL(rdma_bind_addr); |
| 2615 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2616 | static int cma_format_hdr(void *hdr, struct rdma_id_private *id_priv) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2617 | { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2618 | struct cma_hdr *cma_hdr; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2619 | |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 2620 | cma_hdr = hdr; |
| 2621 | cma_hdr->cma_version = CMA_VERSION; |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2622 | if (cma_family(id_priv) == AF_INET) { |
Aleksey Senin | 1f5175a | 2008-12-24 10:16:45 -0800 | [diff] [blame] | 2623 | struct sockaddr_in *src4, *dst4; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2624 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2625 | src4 = (struct sockaddr_in *) cma_src_addr(id_priv); |
| 2626 | dst4 = (struct sockaddr_in *) cma_dst_addr(id_priv); |
Aleksey Senin | 1f5175a | 2008-12-24 10:16:45 -0800 | [diff] [blame] | 2627 | |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 2628 | cma_set_ip_ver(cma_hdr, 4); |
| 2629 | cma_hdr->src_addr.ip4.addr = src4->sin_addr.s_addr; |
| 2630 | cma_hdr->dst_addr.ip4.addr = dst4->sin_addr.s_addr; |
| 2631 | cma_hdr->port = src4->sin_port; |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2632 | } else if (cma_family(id_priv) == AF_INET6) { |
Aleksey Senin | 1f5175a | 2008-12-24 10:16:45 -0800 | [diff] [blame] | 2633 | struct sockaddr_in6 *src6, *dst6; |
| 2634 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2635 | src6 = (struct sockaddr_in6 *) cma_src_addr(id_priv); |
| 2636 | dst6 = (struct sockaddr_in6 *) cma_dst_addr(id_priv); |
Aleksey Senin | 1f5175a | 2008-12-24 10:16:45 -0800 | [diff] [blame] | 2637 | |
Sean Hefty | 01602f1 | 2013-05-29 10:09:20 -0700 | [diff] [blame] | 2638 | cma_set_ip_ver(cma_hdr, 6); |
| 2639 | cma_hdr->src_addr.ip6 = src6->sin6_addr; |
| 2640 | cma_hdr->dst_addr.ip6 = dst6->sin6_addr; |
| 2641 | cma_hdr->port = src6->sin6_port; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2642 | } |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2646 | static int cma_sidr_rep_handler(struct ib_cm_id *cm_id, |
| 2647 | struct ib_cm_event *ib_event) |
| 2648 | { |
| 2649 | struct rdma_id_private *id_priv = cm_id->context; |
| 2650 | struct rdma_cm_event event; |
| 2651 | struct ib_cm_sidr_rep_event_param *rep = &ib_event->param.sidr_rep_rcvd; |
| 2652 | int ret = 0; |
| 2653 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2654 | if (cma_disable_callback(id_priv, RDMA_CM_CONNECT)) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 2655 | return 0; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2656 | |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 2657 | memset(&event, 0, sizeof event); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2658 | switch (ib_event->event) { |
| 2659 | case IB_CM_SIDR_REQ_ERROR: |
| 2660 | event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 2661 | event.status = -ETIMEDOUT; |
| 2662 | break; |
| 2663 | case IB_CM_SIDR_REP_RECEIVED: |
| 2664 | event.param.ud.private_data = ib_event->private_data; |
| 2665 | event.param.ud.private_data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE; |
| 2666 | if (rep->status != IB_SIDR_SUCCESS) { |
| 2667 | event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 2668 | event.status = ib_event->param.sidr_rep_rcvd.status; |
| 2669 | break; |
| 2670 | } |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 2671 | ret = cma_set_qkey(id_priv, rep->qkey); |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 2672 | if (ret) { |
| 2673 | event.event = RDMA_CM_EVENT_ADDR_ERROR; |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 2674 | event.status = ret; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2675 | break; |
| 2676 | } |
| 2677 | ib_init_ah_from_path(id_priv->id.device, id_priv->id.port_num, |
| 2678 | id_priv->id.route.path_rec, |
| 2679 | &event.param.ud.ah_attr); |
| 2680 | event.param.ud.qp_num = rep->qpn; |
| 2681 | event.param.ud.qkey = rep->qkey; |
| 2682 | event.event = RDMA_CM_EVENT_ESTABLISHED; |
| 2683 | event.status = 0; |
| 2684 | break; |
| 2685 | default: |
Roland Dreier | 468f223 | 2008-07-14 23:48:47 -0700 | [diff] [blame] | 2686 | printk(KERN_ERR "RDMA CMA: unexpected IB CM event: %d\n", |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2687 | ib_event->event); |
| 2688 | goto out; |
| 2689 | } |
| 2690 | |
| 2691 | ret = id_priv->id.event_handler(&id_priv->id, &event); |
| 2692 | if (ret) { |
| 2693 | /* Destroy the CM ID by returning a non-zero value. */ |
| 2694 | id_priv->cm_id.ib = NULL; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2695 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2696 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2697 | rdma_destroy_id(&id_priv->id); |
| 2698 | return ret; |
| 2699 | } |
| 2700 | out: |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2701 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2702 | return ret; |
| 2703 | } |
| 2704 | |
| 2705 | static int cma_resolve_ib_udp(struct rdma_id_private *id_priv, |
| 2706 | struct rdma_conn_param *conn_param) |
| 2707 | { |
| 2708 | struct ib_cm_sidr_req_param req; |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2709 | struct ib_cm_id *id; |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2710 | void *private_data; |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2711 | int offset, ret; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2712 | |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2713 | memset(&req, 0, sizeof req); |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2714 | offset = cma_user_data_offset(id_priv); |
| 2715 | req.private_data_len = offset + conn_param->private_data_len; |
Sean Hefty | 04ded16 | 2011-12-06 21:17:11 +0000 | [diff] [blame] | 2716 | if (req.private_data_len < conn_param->private_data_len) |
| 2717 | return -EINVAL; |
| 2718 | |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2719 | if (req.private_data_len) { |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2720 | private_data = kzalloc(req.private_data_len, GFP_ATOMIC); |
| 2721 | if (!private_data) |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2722 | return -ENOMEM; |
| 2723 | } else { |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2724 | private_data = NULL; |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2725 | } |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2726 | |
| 2727 | if (conn_param->private_data && conn_param->private_data_len) |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2728 | memcpy(private_data + offset, conn_param->private_data, |
| 2729 | conn_param->private_data_len); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2730 | |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2731 | if (private_data) { |
| 2732 | ret = cma_format_hdr(private_data, id_priv); |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2733 | if (ret) |
| 2734 | goto out; |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2735 | req.private_data = private_data; |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2736 | } |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2737 | |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2738 | id = ib_create_cm_id(id_priv->id.device, cma_sidr_rep_handler, |
| 2739 | id_priv); |
| 2740 | if (IS_ERR(id)) { |
| 2741 | ret = PTR_ERR(id); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2742 | goto out; |
| 2743 | } |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2744 | id_priv->cm_id.ib = id; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2745 | |
Sean Hefty | f475383 | 2013-05-29 10:09:14 -0700 | [diff] [blame] | 2746 | req.path = id_priv->id.route.path_rec; |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 2747 | req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2748 | req.timeout_ms = 1 << (CMA_CM_RESPONSE_TIMEOUT - 8); |
| 2749 | req.max_cm_retries = CMA_MAX_CM_RETRIES; |
| 2750 | |
| 2751 | ret = ib_send_cm_sidr_req(id_priv->cm_id.ib, &req); |
| 2752 | if (ret) { |
| 2753 | ib_destroy_cm_id(id_priv->cm_id.ib); |
| 2754 | id_priv->cm_id.ib = NULL; |
| 2755 | } |
| 2756 | out: |
Sean Hefty | e511d1a | 2013-07-24 15:06:08 -0700 | [diff] [blame] | 2757 | kfree(private_data); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2758 | return ret; |
| 2759 | } |
| 2760 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2761 | static int cma_connect_ib(struct rdma_id_private *id_priv, |
| 2762 | struct rdma_conn_param *conn_param) |
| 2763 | { |
| 2764 | struct ib_cm_req_param req; |
| 2765 | struct rdma_route *route; |
| 2766 | void *private_data; |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2767 | struct ib_cm_id *id; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2768 | int offset, ret; |
| 2769 | |
| 2770 | memset(&req, 0, sizeof req); |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2771 | offset = cma_user_data_offset(id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2772 | req.private_data_len = offset + conn_param->private_data_len; |
Sean Hefty | 04ded16 | 2011-12-06 21:17:11 +0000 | [diff] [blame] | 2773 | if (req.private_data_len < conn_param->private_data_len) |
| 2774 | return -EINVAL; |
| 2775 | |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2776 | if (req.private_data_len) { |
| 2777 | private_data = kzalloc(req.private_data_len, GFP_ATOMIC); |
| 2778 | if (!private_data) |
| 2779 | return -ENOMEM; |
| 2780 | } else { |
| 2781 | private_data = NULL; |
| 2782 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2783 | |
| 2784 | if (conn_param->private_data && conn_param->private_data_len) |
| 2785 | memcpy(private_data + offset, conn_param->private_data, |
| 2786 | conn_param->private_data_len); |
| 2787 | |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2788 | id = ib_create_cm_id(id_priv->id.device, cma_ib_handler, id_priv); |
| 2789 | if (IS_ERR(id)) { |
| 2790 | ret = PTR_ERR(id); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2791 | goto out; |
| 2792 | } |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2793 | id_priv->cm_id.ib = id; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2794 | |
| 2795 | route = &id_priv->id.route; |
Sean Hefty | e8160e1 | 2013-05-29 10:09:22 -0700 | [diff] [blame] | 2796 | if (private_data) { |
| 2797 | ret = cma_format_hdr(private_data, id_priv); |
| 2798 | if (ret) |
| 2799 | goto out; |
| 2800 | req.private_data = private_data; |
| 2801 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2802 | |
| 2803 | req.primary_path = &route->path_rec[0]; |
| 2804 | if (route->num_paths == 2) |
| 2805 | req.alternate_path = &route->path_rec[1]; |
| 2806 | |
Sean Hefty | cf53936 | 2013-05-29 10:09:28 -0700 | [diff] [blame] | 2807 | req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2808 | req.qp_num = id_priv->qp_num; |
Sean Hefty | 18c441a | 2011-05-28 23:26:06 -0700 | [diff] [blame] | 2809 | req.qp_type = id_priv->id.qp_type; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2810 | req.starting_psn = id_priv->seq_num; |
| 2811 | req.responder_resources = conn_param->responder_resources; |
| 2812 | req.initiator_depth = conn_param->initiator_depth; |
| 2813 | req.flow_control = conn_param->flow_control; |
Sean Hefty | 4ede178 | 2012-10-03 23:42:31 +0000 | [diff] [blame] | 2814 | req.retry_count = min_t(u8, 7, conn_param->retry_count); |
| 2815 | req.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2816 | req.remote_cm_response_timeout = CMA_CM_RESPONSE_TIMEOUT; |
| 2817 | req.local_cm_response_timeout = CMA_CM_RESPONSE_TIMEOUT; |
| 2818 | req.max_cm_retries = CMA_MAX_CM_RETRIES; |
| 2819 | req.srq = id_priv->srq ? 1 : 0; |
| 2820 | |
| 2821 | ret = ib_send_cm_req(id_priv->cm_id.ib, &req); |
| 2822 | out: |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2823 | if (ret && !IS_ERR(id)) { |
| 2824 | ib_destroy_cm_id(id); |
Krishna Kumar | 675a027 | 2006-09-29 11:47:06 -0700 | [diff] [blame] | 2825 | id_priv->cm_id.ib = NULL; |
| 2826 | } |
| 2827 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2828 | kfree(private_data); |
| 2829 | return ret; |
| 2830 | } |
| 2831 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2832 | static int cma_connect_iw(struct rdma_id_private *id_priv, |
| 2833 | struct rdma_conn_param *conn_param) |
| 2834 | { |
| 2835 | struct iw_cm_id *cm_id; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2836 | int ret; |
| 2837 | struct iw_cm_conn_param iw_param; |
| 2838 | |
| 2839 | cm_id = iw_create_cm_id(id_priv->id.device, cma_iw_handler, id_priv); |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2840 | if (IS_ERR(cm_id)) |
| 2841 | return PTR_ERR(cm_id); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2842 | |
| 2843 | id_priv->cm_id.iw = cm_id; |
| 2844 | |
Steve Wise | 24d44a3 | 2013-07-04 16:10:44 +0530 | [diff] [blame] | 2845 | memcpy(&cm_id->local_addr, cma_src_addr(id_priv), |
| 2846 | rdma_addr_size(cma_src_addr(id_priv))); |
| 2847 | memcpy(&cm_id->remote_addr, cma_dst_addr(id_priv), |
| 2848 | rdma_addr_size(cma_dst_addr(id_priv))); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2849 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 2850 | ret = cma_modify_qp_rtr(id_priv, conn_param); |
Krishna Kumar | 675a027 | 2006-09-29 11:47:06 -0700 | [diff] [blame] | 2851 | if (ret) |
| 2852 | goto out; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2853 | |
Hefty, Sean | f45ee80 | 2011-10-06 09:33:04 -0700 | [diff] [blame] | 2854 | if (conn_param) { |
| 2855 | iw_param.ord = conn_param->initiator_depth; |
| 2856 | iw_param.ird = conn_param->responder_resources; |
| 2857 | iw_param.private_data = conn_param->private_data; |
| 2858 | iw_param.private_data_len = conn_param->private_data_len; |
| 2859 | iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num; |
| 2860 | } else { |
| 2861 | memset(&iw_param, 0, sizeof iw_param); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2862 | iw_param.qpn = id_priv->qp_num; |
Hefty, Sean | f45ee80 | 2011-10-06 09:33:04 -0700 | [diff] [blame] | 2863 | } |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2864 | ret = iw_cm_connect(cm_id, &iw_param); |
| 2865 | out: |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 2866 | if (ret) { |
Krishna Kumar | 675a027 | 2006-09-29 11:47:06 -0700 | [diff] [blame] | 2867 | iw_destroy_cm_id(cm_id); |
| 2868 | id_priv->cm_id.iw = NULL; |
| 2869 | } |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2870 | return ret; |
| 2871 | } |
| 2872 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2873 | int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) |
| 2874 | { |
| 2875 | struct rdma_id_private *id_priv; |
| 2876 | int ret; |
| 2877 | |
| 2878 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2879 | if (!cma_comp_exch(id_priv, RDMA_CM_ROUTE_RESOLVED, RDMA_CM_CONNECT)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2880 | return -EINVAL; |
| 2881 | |
| 2882 | if (!id->qp) { |
| 2883 | id_priv->qp_num = conn_param->qp_num; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2884 | id_priv->srq = conn_param->srq; |
| 2885 | } |
| 2886 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2887 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 2888 | case RDMA_TRANSPORT_IB: |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 2889 | if (id->qp_type == IB_QPT_UD) |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2890 | ret = cma_resolve_ib_udp(id_priv, conn_param); |
| 2891 | else |
| 2892 | ret = cma_connect_ib(id_priv, conn_param); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2893 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2894 | case RDMA_TRANSPORT_IWARP: |
| 2895 | ret = cma_connect_iw(id_priv, conn_param); |
| 2896 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2897 | default: |
| 2898 | ret = -ENOSYS; |
| 2899 | break; |
| 2900 | } |
| 2901 | if (ret) |
| 2902 | goto err; |
| 2903 | |
| 2904 | return 0; |
| 2905 | err: |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2906 | cma_comp_exch(id_priv, RDMA_CM_CONNECT, RDMA_CM_ROUTE_RESOLVED); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2907 | return ret; |
| 2908 | } |
| 2909 | EXPORT_SYMBOL(rdma_connect); |
| 2910 | |
| 2911 | static int cma_accept_ib(struct rdma_id_private *id_priv, |
| 2912 | struct rdma_conn_param *conn_param) |
| 2913 | { |
| 2914 | struct ib_cm_rep_param rep; |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 2915 | int ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2916 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 2917 | ret = cma_modify_qp_rtr(id_priv, conn_param); |
| 2918 | if (ret) |
| 2919 | goto out; |
Sean Hefty | 0fe313b | 2006-11-30 16:37:15 -0800 | [diff] [blame] | 2920 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 2921 | ret = cma_modify_qp_rts(id_priv, conn_param); |
| 2922 | if (ret) |
| 2923 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2924 | |
| 2925 | memset(&rep, 0, sizeof rep); |
| 2926 | rep.qp_num = id_priv->qp_num; |
| 2927 | rep.starting_psn = id_priv->seq_num; |
| 2928 | rep.private_data = conn_param->private_data; |
| 2929 | rep.private_data_len = conn_param->private_data_len; |
| 2930 | rep.responder_resources = conn_param->responder_resources; |
| 2931 | rep.initiator_depth = conn_param->initiator_depth; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2932 | rep.failover_accepted = 0; |
| 2933 | rep.flow_control = conn_param->flow_control; |
Sean Hefty | 4ede178 | 2012-10-03 23:42:31 +0000 | [diff] [blame] | 2934 | rep.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2935 | rep.srq = id_priv->srq ? 1 : 0; |
| 2936 | |
Sean Hefty | 0fe313b | 2006-11-30 16:37:15 -0800 | [diff] [blame] | 2937 | ret = ib_send_cm_rep(id_priv->cm_id.ib, &rep); |
| 2938 | out: |
| 2939 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2942 | static int cma_accept_iw(struct rdma_id_private *id_priv, |
| 2943 | struct rdma_conn_param *conn_param) |
| 2944 | { |
| 2945 | struct iw_cm_conn_param iw_param; |
| 2946 | int ret; |
| 2947 | |
Sean Hefty | 5851bb8 | 2008-01-04 10:47:12 -0800 | [diff] [blame] | 2948 | ret = cma_modify_qp_rtr(id_priv, conn_param); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 2949 | if (ret) |
| 2950 | return ret; |
| 2951 | |
| 2952 | iw_param.ord = conn_param->initiator_depth; |
| 2953 | iw_param.ird = conn_param->responder_resources; |
| 2954 | iw_param.private_data = conn_param->private_data; |
| 2955 | iw_param.private_data_len = conn_param->private_data_len; |
| 2956 | if (id_priv->id.qp) { |
| 2957 | iw_param.qpn = id_priv->qp_num; |
| 2958 | } else |
| 2959 | iw_param.qpn = conn_param->qp_num; |
| 2960 | |
| 2961 | return iw_cm_accept(id_priv->cm_id.iw, &iw_param); |
| 2962 | } |
| 2963 | |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2964 | static int cma_send_sidr_rep(struct rdma_id_private *id_priv, |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 2965 | enum ib_cm_sidr_status status, u32 qkey, |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2966 | const void *private_data, int private_data_len) |
| 2967 | { |
| 2968 | struct ib_cm_sidr_rep_param rep; |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 2969 | int ret; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2970 | |
| 2971 | memset(&rep, 0, sizeof rep); |
| 2972 | rep.status = status; |
| 2973 | if (status == IB_SIDR_SUCCESS) { |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 2974 | ret = cma_set_qkey(id_priv, qkey); |
Yossi Etigin | d2ca39f | 2009-04-08 13:42:33 -0700 | [diff] [blame] | 2975 | if (ret) |
| 2976 | return ret; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2977 | rep.qp_num = id_priv->qp_num; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 2978 | rep.qkey = id_priv->qkey; |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 2979 | } |
| 2980 | rep.private_data = private_data; |
| 2981 | rep.private_data_len = private_data_len; |
| 2982 | |
| 2983 | return ib_send_cm_sidr_rep(id_priv->cm_id.ib, &rep); |
| 2984 | } |
| 2985 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2986 | int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) |
| 2987 | { |
| 2988 | struct rdma_id_private *id_priv; |
| 2989 | int ret; |
| 2990 | |
| 2991 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 83e9502 | 2011-01-13 13:56:04 +0000 | [diff] [blame] | 2992 | |
| 2993 | id_priv->owner = task_pid_nr(current); |
| 2994 | |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 2995 | if (!cma_comp(id_priv, RDMA_CM_CONNECT)) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 2996 | return -EINVAL; |
| 2997 | |
| 2998 | if (!id->qp && conn_param) { |
| 2999 | id_priv->qp_num = conn_param->qp_num; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3000 | id_priv->srq = conn_param->srq; |
| 3001 | } |
| 3002 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3003 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 3004 | case RDMA_TRANSPORT_IB: |
Hefty, Sean | f45ee80 | 2011-10-06 09:33:04 -0700 | [diff] [blame] | 3005 | if (id->qp_type == IB_QPT_UD) { |
| 3006 | if (conn_param) |
| 3007 | ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 3008 | conn_param->qkey, |
Hefty, Sean | f45ee80 | 2011-10-06 09:33:04 -0700 | [diff] [blame] | 3009 | conn_param->private_data, |
| 3010 | conn_param->private_data_len); |
| 3011 | else |
| 3012 | ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 3013 | 0, NULL, 0); |
Hefty, Sean | f45ee80 | 2011-10-06 09:33:04 -0700 | [diff] [blame] | 3014 | } else { |
| 3015 | if (conn_param) |
| 3016 | ret = cma_accept_ib(id_priv, conn_param); |
| 3017 | else |
| 3018 | ret = cma_rep_recv(id_priv); |
| 3019 | } |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3020 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3021 | case RDMA_TRANSPORT_IWARP: |
| 3022 | ret = cma_accept_iw(id_priv, conn_param); |
| 3023 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3024 | default: |
| 3025 | ret = -ENOSYS; |
| 3026 | break; |
| 3027 | } |
| 3028 | |
| 3029 | if (ret) |
| 3030 | goto reject; |
| 3031 | |
| 3032 | return 0; |
| 3033 | reject: |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 3034 | cma_modify_qp_err(id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3035 | rdma_reject(id, NULL, 0); |
| 3036 | return ret; |
| 3037 | } |
| 3038 | EXPORT_SYMBOL(rdma_accept); |
| 3039 | |
Sean Hefty | 0fe313b | 2006-11-30 16:37:15 -0800 | [diff] [blame] | 3040 | int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event) |
| 3041 | { |
| 3042 | struct rdma_id_private *id_priv; |
| 3043 | int ret; |
| 3044 | |
| 3045 | id_priv = container_of(id, struct rdma_id_private, id); |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 3046 | if (!id_priv->cm_id.ib) |
Sean Hefty | 0fe313b | 2006-11-30 16:37:15 -0800 | [diff] [blame] | 3047 | return -EINVAL; |
| 3048 | |
| 3049 | switch (id->device->node_type) { |
| 3050 | case RDMA_NODE_IB_CA: |
| 3051 | ret = ib_cm_notify(id_priv->cm_id.ib, event); |
| 3052 | break; |
| 3053 | default: |
| 3054 | ret = 0; |
| 3055 | break; |
| 3056 | } |
| 3057 | return ret; |
| 3058 | } |
| 3059 | EXPORT_SYMBOL(rdma_notify); |
| 3060 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3061 | int rdma_reject(struct rdma_cm_id *id, const void *private_data, |
| 3062 | u8 private_data_len) |
| 3063 | { |
| 3064 | struct rdma_id_private *id_priv; |
| 3065 | int ret; |
| 3066 | |
| 3067 | id_priv = container_of(id, struct rdma_id_private, id); |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 3068 | if (!id_priv->cm_id.ib) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3069 | return -EINVAL; |
| 3070 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3071 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 3072 | case RDMA_TRANSPORT_IB: |
Sean Hefty | b26f9b9 | 2010-04-01 17:08:41 +0000 | [diff] [blame] | 3073 | if (id->qp_type == IB_QPT_UD) |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 3074 | ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 0, |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 3075 | private_data, private_data_len); |
| 3076 | else |
| 3077 | ret = ib_send_cm_rej(id_priv->cm_id.ib, |
| 3078 | IB_CM_REJ_CONSUMER_DEFINED, NULL, |
| 3079 | 0, private_data, private_data_len); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3080 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3081 | case RDMA_TRANSPORT_IWARP: |
| 3082 | ret = iw_cm_reject(id_priv->cm_id.iw, |
| 3083 | private_data, private_data_len); |
| 3084 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3085 | default: |
| 3086 | ret = -ENOSYS; |
| 3087 | break; |
| 3088 | } |
| 3089 | return ret; |
| 3090 | } |
| 3091 | EXPORT_SYMBOL(rdma_reject); |
| 3092 | |
| 3093 | int rdma_disconnect(struct rdma_cm_id *id) |
| 3094 | { |
| 3095 | struct rdma_id_private *id_priv; |
| 3096 | int ret; |
| 3097 | |
| 3098 | id_priv = container_of(id, struct rdma_id_private, id); |
Jack Morgenstein | 0c9361f | 2011-07-17 10:46:47 +0000 | [diff] [blame] | 3099 | if (!id_priv->cm_id.ib) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3100 | return -EINVAL; |
| 3101 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3102 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 3103 | case RDMA_TRANSPORT_IB: |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 3104 | ret = cma_modify_qp_err(id_priv); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3105 | if (ret) |
| 3106 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3107 | /* Initiate or respond to a disconnect. */ |
| 3108 | if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) |
| 3109 | ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0); |
| 3110 | break; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3111 | case RDMA_TRANSPORT_IWARP: |
| 3112 | ret = iw_cm_disconnect(id_priv->cm_id.iw, 0); |
| 3113 | break; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3114 | default: |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 3115 | ret = -EINVAL; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3116 | break; |
| 3117 | } |
| 3118 | out: |
| 3119 | return ret; |
| 3120 | } |
| 3121 | EXPORT_SYMBOL(rdma_disconnect); |
| 3122 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3123 | static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast) |
| 3124 | { |
| 3125 | struct rdma_id_private *id_priv; |
| 3126 | struct cma_multicast *mc = multicast->context; |
| 3127 | struct rdma_cm_event event; |
| 3128 | int ret; |
| 3129 | |
| 3130 | id_priv = mc->id_priv; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3131 | if (cma_disable_callback(id_priv, RDMA_CM_ADDR_BOUND) && |
| 3132 | cma_disable_callback(id_priv, RDMA_CM_ADDR_RESOLVED)) |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 3133 | return 0; |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3134 | |
Sean Hefty | 5c43813 | 2013-05-29 10:09:23 -0700 | [diff] [blame] | 3135 | if (!status) |
| 3136 | status = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey)); |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 3137 | mutex_lock(&id_priv->qp_mutex); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3138 | if (!status && id_priv->id.qp) |
| 3139 | status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid, |
Sean Hefty | 46ea506 | 2011-12-06 21:15:18 +0000 | [diff] [blame] | 3140 | be16_to_cpu(multicast->rec.mlid)); |
Sean Hefty | c548338 | 2007-09-24 13:19:09 -0700 | [diff] [blame] | 3141 | mutex_unlock(&id_priv->qp_mutex); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3142 | |
| 3143 | memset(&event, 0, sizeof event); |
| 3144 | event.status = status; |
| 3145 | event.param.ud.private_data = mc->context; |
| 3146 | if (!status) { |
| 3147 | event.event = RDMA_CM_EVENT_MULTICAST_JOIN; |
| 3148 | ib_init_ah_from_mcmember(id_priv->id.device, |
| 3149 | id_priv->id.port_num, &multicast->rec, |
| 3150 | &event.param.ud.ah_attr); |
| 3151 | event.param.ud.qp_num = 0xFFFFFF; |
| 3152 | event.param.ud.qkey = be32_to_cpu(multicast->rec.qkey); |
| 3153 | } else |
| 3154 | event.event = RDMA_CM_EVENT_MULTICAST_ERROR; |
| 3155 | |
| 3156 | ret = id_priv->id.event_handler(&id_priv->id, &event); |
| 3157 | if (ret) { |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3158 | cma_exch(id_priv, RDMA_CM_DESTROYING); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3159 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3160 | rdma_destroy_id(&id_priv->id); |
| 3161 | return 0; |
| 3162 | } |
Sean Hefty | 8aa0860 | 2007-05-07 11:49:00 -0700 | [diff] [blame] | 3163 | |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3164 | mutex_unlock(&id_priv->handler_mutex); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3165 | return 0; |
| 3166 | } |
| 3167 | |
| 3168 | static void cma_set_mgid(struct rdma_id_private *id_priv, |
| 3169 | struct sockaddr *addr, union ib_gid *mgid) |
| 3170 | { |
| 3171 | unsigned char mc_map[MAX_ADDR_LEN]; |
| 3172 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 3173 | struct sockaddr_in *sin = (struct sockaddr_in *) addr; |
| 3174 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr; |
| 3175 | |
| 3176 | if (cma_any_addr(addr)) { |
| 3177 | memset(mgid, 0, sizeof *mgid); |
| 3178 | } else if ((addr->sa_family == AF_INET6) && |
Jason Gunthorpe | 1c9b281 | 2009-11-19 12:55:21 -0800 | [diff] [blame] | 3179 | ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFFF0FFFF) == |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3180 | 0xFF10A01B)) { |
| 3181 | /* IPv6 address is an SA assigned MGID. */ |
| 3182 | memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); |
Sean Hefty | 5bc2b7b | 2013-05-29 10:09:33 -0700 | [diff] [blame] | 3183 | } else if (addr->sa_family == AF_IB) { |
| 3184 | memcpy(mgid, &((struct sockaddr_ib *) addr)->sib_addr, sizeof *mgid); |
Jason Gunthorpe | e2e6269 | 2009-11-19 12:55:22 -0800 | [diff] [blame] | 3185 | } else if ((addr->sa_family == AF_INET6)) { |
| 3186 | ipv6_ib_mc_map(&sin6->sin6_addr, dev_addr->broadcast, mc_map); |
| 3187 | if (id_priv->id.ps == RDMA_PS_UDP) |
| 3188 | mc_map[7] = 0x01; /* Use RDMA CM signature */ |
| 3189 | *mgid = *(union ib_gid *) (mc_map + 4); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3190 | } else { |
Rolf Manderscheid | a9e527e | 2007-12-10 13:38:41 -0700 | [diff] [blame] | 3191 | ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3192 | if (id_priv->id.ps == RDMA_PS_UDP) |
| 3193 | mc_map[7] = 0x01; /* Use RDMA CM signature */ |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3194 | *mgid = *(union ib_gid *) (mc_map + 4); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | static int cma_join_ib_multicast(struct rdma_id_private *id_priv, |
| 3199 | struct cma_multicast *mc) |
| 3200 | { |
| 3201 | struct ib_sa_mcmember_rec rec; |
| 3202 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 3203 | ib_sa_comp_mask comp_mask; |
| 3204 | int ret; |
| 3205 | |
| 3206 | ib_addr_get_mgid(dev_addr, &rec.mgid); |
| 3207 | ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num, |
| 3208 | &rec.mgid, &rec); |
| 3209 | if (ret) |
| 3210 | return ret; |
| 3211 | |
Sean Hefty | 5bc2b7b | 2013-05-29 10:09:33 -0700 | [diff] [blame] | 3212 | ret = cma_set_qkey(id_priv, 0); |
| 3213 | if (ret) |
| 3214 | return ret; |
| 3215 | |
Roland Dreier | 3f44675 | 2008-08-04 11:02:14 -0700 | [diff] [blame] | 3216 | cma_set_mgid(id_priv, (struct sockaddr *) &mc->addr, &rec.mgid); |
Sean Hefty | 5bc2b7b | 2013-05-29 10:09:33 -0700 | [diff] [blame] | 3217 | rec.qkey = cpu_to_be32(id_priv->qkey); |
Sean Hefty | 6f8372b | 2009-11-19 13:26:06 -0800 | [diff] [blame] | 3218 | rdma_addr_get_sgid(dev_addr, &rec.port_gid); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3219 | rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr)); |
| 3220 | rec.join_state = 1; |
| 3221 | |
| 3222 | comp_mask = IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID | |
| 3223 | IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_JOIN_STATE | |
| 3224 | IB_SA_MCMEMBER_REC_QKEY | IB_SA_MCMEMBER_REC_SL | |
| 3225 | IB_SA_MCMEMBER_REC_FLOW_LABEL | |
| 3226 | IB_SA_MCMEMBER_REC_TRAFFIC_CLASS; |
| 3227 | |
Yossi Etigin | 84adeee | 2009-04-01 13:55:32 -0700 | [diff] [blame] | 3228 | if (id_priv->id.ps == RDMA_PS_IPOIB) |
| 3229 | comp_mask |= IB_SA_MCMEMBER_REC_RATE | |
Dotan Barak | 2a22fb8 | 2012-08-30 09:09:55 +0000 | [diff] [blame] | 3230 | IB_SA_MCMEMBER_REC_RATE_SELECTOR | |
| 3231 | IB_SA_MCMEMBER_REC_MTU_SELECTOR | |
| 3232 | IB_SA_MCMEMBER_REC_MTU | |
| 3233 | IB_SA_MCMEMBER_REC_HOP_LIMIT; |
Yossi Etigin | 84adeee | 2009-04-01 13:55:32 -0700 | [diff] [blame] | 3234 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3235 | mc->multicast.ib = ib_sa_join_multicast(&sa_client, id_priv->id.device, |
| 3236 | id_priv->id.port_num, &rec, |
| 3237 | comp_mask, GFP_KERNEL, |
| 3238 | cma_ib_mc_handler, mc); |
Rusty Russell | 8c6ffba | 2013-07-15 11:20:32 +0930 | [diff] [blame] | 3239 | return PTR_ERR_OR_ZERO(mc->multicast.ib); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3240 | } |
| 3241 | |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 3242 | static void iboe_mcast_work_handler(struct work_struct *work) |
| 3243 | { |
| 3244 | struct iboe_mcast_work *mw = container_of(work, struct iboe_mcast_work, work); |
| 3245 | struct cma_multicast *mc = mw->mc; |
| 3246 | struct ib_sa_multicast *m = mc->multicast.ib; |
| 3247 | |
| 3248 | mc->multicast.ib->context = mc; |
| 3249 | cma_ib_mc_handler(0, m); |
| 3250 | kref_put(&mc->mcref, release_mc); |
| 3251 | kfree(mw); |
| 3252 | } |
| 3253 | |
| 3254 | static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid) |
| 3255 | { |
| 3256 | struct sockaddr_in *sin = (struct sockaddr_in *)addr; |
| 3257 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; |
| 3258 | |
| 3259 | if (cma_any_addr(addr)) { |
| 3260 | memset(mgid, 0, sizeof *mgid); |
| 3261 | } else if (addr->sa_family == AF_INET6) { |
| 3262 | memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); |
| 3263 | } else { |
| 3264 | mgid->raw[0] = 0xff; |
| 3265 | mgid->raw[1] = 0x0e; |
| 3266 | mgid->raw[2] = 0; |
| 3267 | mgid->raw[3] = 0; |
| 3268 | mgid->raw[4] = 0; |
| 3269 | mgid->raw[5] = 0; |
| 3270 | mgid->raw[6] = 0; |
| 3271 | mgid->raw[7] = 0; |
| 3272 | mgid->raw[8] = 0; |
| 3273 | mgid->raw[9] = 0; |
| 3274 | mgid->raw[10] = 0xff; |
| 3275 | mgid->raw[11] = 0xff; |
| 3276 | *(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr; |
| 3277 | } |
| 3278 | } |
| 3279 | |
| 3280 | static int cma_iboe_join_multicast(struct rdma_id_private *id_priv, |
| 3281 | struct cma_multicast *mc) |
| 3282 | { |
| 3283 | struct iboe_mcast_work *work; |
| 3284 | struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 3285 | int err; |
| 3286 | struct sockaddr *addr = (struct sockaddr *)&mc->addr; |
| 3287 | struct net_device *ndev = NULL; |
| 3288 | |
| 3289 | if (cma_zero_addr((struct sockaddr *)&mc->addr)) |
| 3290 | return -EINVAL; |
| 3291 | |
| 3292 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 3293 | if (!work) |
| 3294 | return -ENOMEM; |
| 3295 | |
| 3296 | mc->multicast.ib = kzalloc(sizeof(struct ib_sa_multicast), GFP_KERNEL); |
| 3297 | if (!mc->multicast.ib) { |
| 3298 | err = -ENOMEM; |
| 3299 | goto out1; |
| 3300 | } |
| 3301 | |
| 3302 | cma_iboe_set_mgid(addr, &mc->multicast.ib->rec.mgid); |
| 3303 | |
| 3304 | mc->multicast.ib->rec.pkey = cpu_to_be16(0xffff); |
| 3305 | if (id_priv->id.ps == RDMA_PS_UDP) |
| 3306 | mc->multicast.ib->rec.qkey = cpu_to_be32(RDMA_UDP_QKEY); |
| 3307 | |
| 3308 | if (dev_addr->bound_dev_if) |
| 3309 | ndev = dev_get_by_index(&init_net, dev_addr->bound_dev_if); |
| 3310 | if (!ndev) { |
| 3311 | err = -ENODEV; |
| 3312 | goto out2; |
| 3313 | } |
| 3314 | mc->multicast.ib->rec.rate = iboe_get_rate(ndev); |
| 3315 | mc->multicast.ib->rec.hop_limit = 1; |
| 3316 | mc->multicast.ib->rec.mtu = iboe_get_mtu(ndev->mtu); |
| 3317 | dev_put(ndev); |
| 3318 | if (!mc->multicast.ib->rec.mtu) { |
| 3319 | err = -EINVAL; |
| 3320 | goto out2; |
| 3321 | } |
Moni Shoua | 7b85627 | 2013-12-12 18:03:12 +0200 | [diff] [blame] | 3322 | rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 3323 | &mc->multicast.ib->rec.port_gid); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 3324 | work->id = id_priv; |
| 3325 | work->mc = mc; |
| 3326 | INIT_WORK(&work->work, iboe_mcast_work_handler); |
| 3327 | kref_get(&mc->mcref); |
| 3328 | queue_work(cma_wq, &work->work); |
| 3329 | |
| 3330 | return 0; |
| 3331 | |
| 3332 | out2: |
| 3333 | kfree(mc->multicast.ib); |
| 3334 | out1: |
| 3335 | kfree(work); |
| 3336 | return err; |
| 3337 | } |
| 3338 | |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3339 | int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, |
| 3340 | void *context) |
| 3341 | { |
| 3342 | struct rdma_id_private *id_priv; |
| 3343 | struct cma_multicast *mc; |
| 3344 | int ret; |
| 3345 | |
| 3346 | id_priv = container_of(id, struct rdma_id_private, id); |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3347 | if (!cma_comp(id_priv, RDMA_CM_ADDR_BOUND) && |
| 3348 | !cma_comp(id_priv, RDMA_CM_ADDR_RESOLVED)) |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3349 | return -EINVAL; |
| 3350 | |
| 3351 | mc = kmalloc(sizeof *mc, GFP_KERNEL); |
| 3352 | if (!mc) |
| 3353 | return -ENOMEM; |
| 3354 | |
Sean Hefty | ef56086 | 2013-05-29 10:09:10 -0700 | [diff] [blame] | 3355 | memcpy(&mc->addr, addr, rdma_addr_size(addr)); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3356 | mc->context = context; |
| 3357 | mc->id_priv = id_priv; |
| 3358 | |
| 3359 | spin_lock(&id_priv->lock); |
| 3360 | list_add(&mc->list, &id_priv->mc_list); |
| 3361 | spin_unlock(&id_priv->lock); |
| 3362 | |
| 3363 | switch (rdma_node_get_transport(id->device->node_type)) { |
| 3364 | case RDMA_TRANSPORT_IB: |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 3365 | switch (rdma_port_get_link_layer(id->device, id->port_num)) { |
| 3366 | case IB_LINK_LAYER_INFINIBAND: |
| 3367 | ret = cma_join_ib_multicast(id_priv, mc); |
| 3368 | break; |
| 3369 | case IB_LINK_LAYER_ETHERNET: |
| 3370 | kref_init(&mc->mcref); |
| 3371 | ret = cma_iboe_join_multicast(id_priv, mc); |
| 3372 | break; |
| 3373 | default: |
| 3374 | ret = -EINVAL; |
| 3375 | } |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3376 | break; |
| 3377 | default: |
| 3378 | ret = -ENOSYS; |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | if (ret) { |
| 3383 | spin_lock_irq(&id_priv->lock); |
| 3384 | list_del(&mc->list); |
| 3385 | spin_unlock_irq(&id_priv->lock); |
| 3386 | kfree(mc); |
| 3387 | } |
| 3388 | return ret; |
| 3389 | } |
| 3390 | EXPORT_SYMBOL(rdma_join_multicast); |
| 3391 | |
| 3392 | void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr) |
| 3393 | { |
| 3394 | struct rdma_id_private *id_priv; |
| 3395 | struct cma_multicast *mc; |
| 3396 | |
| 3397 | id_priv = container_of(id, struct rdma_id_private, id); |
| 3398 | spin_lock_irq(&id_priv->lock); |
| 3399 | list_for_each_entry(mc, &id_priv->mc_list, list) { |
Sean Hefty | ef56086 | 2013-05-29 10:09:10 -0700 | [diff] [blame] | 3400 | if (!memcmp(&mc->addr, addr, rdma_addr_size(addr))) { |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3401 | list_del(&mc->list); |
| 3402 | spin_unlock_irq(&id_priv->lock); |
| 3403 | |
| 3404 | if (id->qp) |
| 3405 | ib_detach_mcast(id->qp, |
| 3406 | &mc->multicast.ib->rec.mgid, |
Sean Hefty | 46ea506 | 2011-12-06 21:15:18 +0000 | [diff] [blame] | 3407 | be16_to_cpu(mc->multicast.ib->rec.mlid)); |
Eli Cohen | 3c86aa7 | 2010-10-13 21:26:51 +0200 | [diff] [blame] | 3408 | if (rdma_node_get_transport(id_priv->cma_dev->device->node_type) == RDMA_TRANSPORT_IB) { |
| 3409 | switch (rdma_port_get_link_layer(id->device, id->port_num)) { |
| 3410 | case IB_LINK_LAYER_INFINIBAND: |
| 3411 | ib_sa_free_multicast(mc->multicast.ib); |
| 3412 | kfree(mc); |
| 3413 | break; |
| 3414 | case IB_LINK_LAYER_ETHERNET: |
| 3415 | kref_put(&mc->mcref, release_mc); |
| 3416 | break; |
| 3417 | default: |
| 3418 | break; |
| 3419 | } |
| 3420 | } |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3421 | return; |
| 3422 | } |
| 3423 | } |
| 3424 | spin_unlock_irq(&id_priv->lock); |
| 3425 | } |
| 3426 | EXPORT_SYMBOL(rdma_leave_multicast); |
| 3427 | |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3428 | static int cma_netdev_change(struct net_device *ndev, struct rdma_id_private *id_priv) |
| 3429 | { |
| 3430 | struct rdma_dev_addr *dev_addr; |
| 3431 | struct cma_ndev_work *work; |
| 3432 | |
| 3433 | dev_addr = &id_priv->id.route.addr.dev_addr; |
| 3434 | |
Sean Hefty | 6266ed6 | 2009-11-19 12:55:22 -0800 | [diff] [blame] | 3435 | if ((dev_addr->bound_dev_if == ndev->ifindex) && |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3436 | memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) { |
| 3437 | printk(KERN_INFO "RDMA CM addr change for ndev %s used by id %p\n", |
| 3438 | ndev->name, &id_priv->id); |
| 3439 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 3440 | if (!work) |
| 3441 | return -ENOMEM; |
| 3442 | |
| 3443 | INIT_WORK(&work->work, cma_ndev_work_handler); |
| 3444 | work->id = id_priv; |
| 3445 | work->event.event = RDMA_CM_EVENT_ADDR_CHANGE; |
| 3446 | atomic_inc(&id_priv->refcount); |
| 3447 | queue_work(cma_wq, &work->work); |
| 3448 | } |
| 3449 | |
| 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | static int cma_netdev_callback(struct notifier_block *self, unsigned long event, |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 3454 | void *ptr) |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3455 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 3456 | struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3457 | struct cma_device *cma_dev; |
| 3458 | struct rdma_id_private *id_priv; |
| 3459 | int ret = NOTIFY_DONE; |
| 3460 | |
| 3461 | if (dev_net(ndev) != &init_net) |
| 3462 | return NOTIFY_DONE; |
| 3463 | |
| 3464 | if (event != NETDEV_BONDING_FAILOVER) |
| 3465 | return NOTIFY_DONE; |
| 3466 | |
| 3467 | if (!(ndev->flags & IFF_MASTER) || !(ndev->priv_flags & IFF_BONDING)) |
| 3468 | return NOTIFY_DONE; |
| 3469 | |
| 3470 | mutex_lock(&lock); |
| 3471 | list_for_each_entry(cma_dev, &dev_list, list) |
| 3472 | list_for_each_entry(id_priv, &cma_dev->id_list, list) { |
| 3473 | ret = cma_netdev_change(ndev, id_priv); |
| 3474 | if (ret) |
| 3475 | goto out; |
| 3476 | } |
| 3477 | |
| 3478 | out: |
| 3479 | mutex_unlock(&lock); |
| 3480 | return ret; |
| 3481 | } |
| 3482 | |
| 3483 | static struct notifier_block cma_nb = { |
| 3484 | .notifier_call = cma_netdev_callback |
| 3485 | }; |
| 3486 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3487 | static void cma_add_one(struct ib_device *device) |
| 3488 | { |
| 3489 | struct cma_device *cma_dev; |
| 3490 | struct rdma_id_private *id_priv; |
| 3491 | |
| 3492 | cma_dev = kmalloc(sizeof *cma_dev, GFP_KERNEL); |
| 3493 | if (!cma_dev) |
| 3494 | return; |
| 3495 | |
| 3496 | cma_dev->device = device; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3497 | |
| 3498 | init_completion(&cma_dev->comp); |
| 3499 | atomic_set(&cma_dev->refcount, 1); |
| 3500 | INIT_LIST_HEAD(&cma_dev->id_list); |
| 3501 | ib_set_client_data(device, &cma_client, cma_dev); |
| 3502 | |
| 3503 | mutex_lock(&lock); |
| 3504 | list_add_tail(&cma_dev->list, &dev_list); |
| 3505 | list_for_each_entry(id_priv, &listen_any_list, list) |
| 3506 | cma_listen_on_dev(id_priv, cma_dev); |
| 3507 | mutex_unlock(&lock); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | static int cma_remove_id_dev(struct rdma_id_private *id_priv) |
| 3511 | { |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 3512 | struct rdma_cm_event event; |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3513 | enum rdma_cm_state state; |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3514 | int ret = 0; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3515 | |
| 3516 | /* Record that we want to remove the device */ |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3517 | state = cma_exch(id_priv, RDMA_CM_DEVICE_REMOVAL); |
| 3518 | if (state == RDMA_CM_DESTROYING) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3519 | return 0; |
| 3520 | |
| 3521 | cma_cancel_operation(id_priv, state); |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3522 | mutex_lock(&id_priv->handler_mutex); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3523 | |
| 3524 | /* Check for destruction from another callback. */ |
Nir Muchtar | 550e5ca | 2011-05-20 11:46:11 -0700 | [diff] [blame] | 3525 | if (!cma_comp(id_priv, RDMA_CM_DEVICE_REMOVAL)) |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3526 | goto out; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3527 | |
Sean Hefty | a1b1b61 | 2006-11-30 16:33:14 -0800 | [diff] [blame] | 3528 | memset(&event, 0, sizeof event); |
| 3529 | event.event = RDMA_CM_EVENT_DEVICE_REMOVAL; |
Or Gerlitz | de910bd | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 3530 | ret = id_priv->id.event_handler(&id_priv->id, &event); |
| 3531 | out: |
| 3532 | mutex_unlock(&id_priv->handler_mutex); |
| 3533 | return ret; |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | static void cma_process_remove(struct cma_device *cma_dev) |
| 3537 | { |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3538 | struct rdma_id_private *id_priv; |
| 3539 | int ret; |
| 3540 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3541 | mutex_lock(&lock); |
| 3542 | while (!list_empty(&cma_dev->id_list)) { |
| 3543 | id_priv = list_entry(cma_dev->id_list.next, |
| 3544 | struct rdma_id_private, list); |
| 3545 | |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 3546 | list_del(&id_priv->listen_list); |
Krishna Kumar | 94de178 | 2006-09-29 12:03:35 -0700 | [diff] [blame] | 3547 | list_del_init(&id_priv->list); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3548 | atomic_inc(&id_priv->refcount); |
| 3549 | mutex_unlock(&lock); |
| 3550 | |
Sean Hefty | d02d1f5 | 2007-10-09 11:12:34 -0700 | [diff] [blame] | 3551 | ret = id_priv->internal_id ? 1 : cma_remove_id_dev(id_priv); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3552 | cma_deref_id(id_priv); |
| 3553 | if (ret) |
| 3554 | rdma_destroy_id(&id_priv->id); |
| 3555 | |
| 3556 | mutex_lock(&lock); |
| 3557 | } |
| 3558 | mutex_unlock(&lock); |
| 3559 | |
| 3560 | cma_deref_dev(cma_dev); |
| 3561 | wait_for_completion(&cma_dev->comp); |
| 3562 | } |
| 3563 | |
| 3564 | static void cma_remove_one(struct ib_device *device) |
| 3565 | { |
| 3566 | struct cma_device *cma_dev; |
| 3567 | |
| 3568 | cma_dev = ib_get_client_data(device, &cma_client); |
| 3569 | if (!cma_dev) |
| 3570 | return; |
| 3571 | |
| 3572 | mutex_lock(&lock); |
| 3573 | list_del(&cma_dev->list); |
| 3574 | mutex_unlock(&lock); |
| 3575 | |
| 3576 | cma_process_remove(cma_dev); |
| 3577 | kfree(cma_dev); |
| 3578 | } |
| 3579 | |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3580 | static int cma_get_id_stats(struct sk_buff *skb, struct netlink_callback *cb) |
| 3581 | { |
| 3582 | struct nlmsghdr *nlh; |
| 3583 | struct rdma_cm_id_stats *id_stats; |
| 3584 | struct rdma_id_private *id_priv; |
| 3585 | struct rdma_cm_id *id = NULL; |
| 3586 | struct cma_device *cma_dev; |
| 3587 | int i_dev = 0, i_id = 0; |
| 3588 | |
| 3589 | /* |
| 3590 | * We export all of the IDs as a sequence of messages. Each |
| 3591 | * ID gets its own netlink message. |
| 3592 | */ |
| 3593 | mutex_lock(&lock); |
| 3594 | |
| 3595 | list_for_each_entry(cma_dev, &dev_list, list) { |
| 3596 | if (i_dev < cb->args[0]) { |
| 3597 | i_dev++; |
| 3598 | continue; |
| 3599 | } |
| 3600 | |
| 3601 | i_id = 0; |
| 3602 | list_for_each_entry(id_priv, &cma_dev->id_list, list) { |
| 3603 | if (i_id < cb->args[1]) { |
| 3604 | i_id++; |
| 3605 | continue; |
| 3606 | } |
| 3607 | |
| 3608 | id_stats = ibnl_put_msg(skb, &nlh, cb->nlh->nlmsg_seq, |
| 3609 | sizeof *id_stats, RDMA_NL_RDMA_CM, |
Tatyana Nikolova | 30dc5e6 | 2014-03-26 17:07:35 -0500 | [diff] [blame^] | 3610 | RDMA_NL_RDMA_CM_ID_STATS, |
| 3611 | NLM_F_MULTI); |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3612 | if (!id_stats) |
| 3613 | goto out; |
| 3614 | |
| 3615 | memset(id_stats, 0, sizeof *id_stats); |
| 3616 | id = &id_priv->id; |
| 3617 | id_stats->node_type = id->route.addr.dev_addr.dev_type; |
| 3618 | id_stats->port_num = id->port_num; |
| 3619 | id_stats->bound_dev_if = |
| 3620 | id->route.addr.dev_addr.bound_dev_if; |
| 3621 | |
Sean Hefty | ce117ff | 2013-05-29 10:09:34 -0700 | [diff] [blame] | 3622 | if (ibnl_put_attr(skb, nlh, |
| 3623 | rdma_addr_size(cma_src_addr(id_priv)), |
| 3624 | cma_src_addr(id_priv), |
| 3625 | RDMA_NL_RDMA_CM_ATTR_SRC_ADDR)) |
| 3626 | goto out; |
| 3627 | if (ibnl_put_attr(skb, nlh, |
| 3628 | rdma_addr_size(cma_src_addr(id_priv)), |
| 3629 | cma_dst_addr(id_priv), |
| 3630 | RDMA_NL_RDMA_CM_ATTR_DST_ADDR)) |
| 3631 | goto out; |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3632 | |
Nir Muchtar | 83e9502 | 2011-01-13 13:56:04 +0000 | [diff] [blame] | 3633 | id_stats->pid = id_priv->owner; |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3634 | id_stats->port_space = id->ps; |
| 3635 | id_stats->cm_state = id_priv->state; |
| 3636 | id_stats->qp_num = id_priv->qp_num; |
| 3637 | id_stats->qp_type = id->qp_type; |
| 3638 | |
| 3639 | i_id++; |
| 3640 | } |
| 3641 | |
| 3642 | cb->args[1] = 0; |
| 3643 | i_dev++; |
| 3644 | } |
| 3645 | |
| 3646 | out: |
| 3647 | mutex_unlock(&lock); |
| 3648 | cb->args[0] = i_dev; |
| 3649 | cb->args[1] = i_id; |
| 3650 | |
| 3651 | return skb->len; |
| 3652 | } |
| 3653 | |
| 3654 | static const struct ibnl_client_cbs cma_cb_table[] = { |
Gao feng | 809d5fc | 2012-10-04 20:15:49 +0000 | [diff] [blame] | 3655 | [RDMA_NL_RDMA_CM_ID_STATS] = { .dump = cma_get_id_stats, |
| 3656 | .module = THIS_MODULE }, |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3657 | }; |
| 3658 | |
Peter Huewe | 716abb1 | 2009-06-23 10:38:42 -0700 | [diff] [blame] | 3659 | static int __init cma_init(void) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3660 | { |
Tetsuo Handa | 5d7220e8 | 2010-04-15 11:29:04 +0900 | [diff] [blame] | 3661 | int ret; |
Stephen Hemminger | 227b60f | 2007-10-10 17:30:46 -0700 | [diff] [blame] | 3662 | |
Sean Hefty | c7f743a | 2007-02-01 12:23:37 -0800 | [diff] [blame] | 3663 | cma_wq = create_singlethread_workqueue("rdma_cm"); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3664 | if (!cma_wq) |
| 3665 | return -ENOMEM; |
| 3666 | |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 3667 | ib_sa_register_client(&sa_client); |
Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 3668 | rdma_addr_register_client(&addr_client); |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3669 | register_netdevice_notifier(&cma_nb); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 3670 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3671 | ret = ib_register_client(&cma_client); |
| 3672 | if (ret) |
| 3673 | goto err; |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3674 | |
| 3675 | if (ibnl_add_client(RDMA_NL_RDMA_CM, RDMA_NL_RDMA_CM_NUM_OPS, cma_cb_table)) |
| 3676 | printk(KERN_WARNING "RDMA CMA: failed to add netlink callback\n"); |
| 3677 | |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3678 | return 0; |
| 3679 | |
| 3680 | err: |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3681 | unregister_netdevice_notifier(&cma_nb); |
Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 3682 | rdma_addr_unregister_client(&addr_client); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 3683 | ib_sa_unregister_client(&sa_client); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3684 | destroy_workqueue(cma_wq); |
| 3685 | return ret; |
| 3686 | } |
| 3687 | |
Peter Huewe | 716abb1 | 2009-06-23 10:38:42 -0700 | [diff] [blame] | 3688 | static void __exit cma_cleanup(void) |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3689 | { |
Nir Muchtar | 753f618 | 2011-01-03 15:33:53 +0000 | [diff] [blame] | 3690 | ibnl_remove_client(RDMA_NL_RDMA_CM); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3691 | ib_unregister_client(&cma_client); |
Or Gerlitz | dd5bdff | 2008-07-22 14:14:22 -0700 | [diff] [blame] | 3692 | unregister_netdevice_notifier(&cma_nb); |
Sean Hefty | 7a118df | 2006-10-31 11:12:59 -0800 | [diff] [blame] | 3693 | rdma_addr_unregister_client(&addr_client); |
Michael S. Tsirkin | c1a0b23 | 2006-08-21 16:40:12 -0700 | [diff] [blame] | 3694 | ib_sa_unregister_client(&sa_client); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3695 | destroy_workqueue(cma_wq); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3696 | idr_destroy(&tcp_ps); |
Sean Hefty | 628e5f6 | 2006-11-30 16:44:16 -0800 | [diff] [blame] | 3697 | idr_destroy(&udp_ps); |
Sean Hefty | c8f6a36 | 2007-02-15 17:00:18 -0800 | [diff] [blame] | 3698 | idr_destroy(&ipoib_ps); |
Sean Hefty | 2d2e941 | 2011-05-28 21:56:39 -0700 | [diff] [blame] | 3699 | idr_destroy(&ib_ps); |
Sean Hefty | e51060f | 2006-06-17 20:37:29 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | module_init(cma_init); |
| 3703 | module_exit(cma_cleanup); |