| 1 |
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 |
/* |
| 3 |
* Copyright (c) 2005 Voltaire Inc. All rights reserved. |
| 4 |
* Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved. |
| 5 |
* Copyright (c) 1999-2019, Mellanox Technologies, Inc. All rights reserved. |
| 6 |
* Copyright (c) 2005-2006 Intel Corporation. All rights reserved. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <linux/completion.h> |
| 10 |
#include <linux/in.h> |
| 11 |
#include <linux/in6.h> |
| 12 |
#include <linux/mutex.h> |
| 13 |
#include <linux/random.h> |
| 14 |
#include <linux/rbtree.h> |
| 15 |
#include <linux/igmp.h> |
| 16 |
#include <linux/xarray.h> |
| 17 |
#include <linux/inetdevice.h> |
| 18 |
#include <linux/slab.h> |
| 19 |
#include <linux/module.h> |
| 20 |
#include <net/route.h> |
| 21 |
|
| 22 |
#include <net/net_namespace.h> |
| 23 |
#include <net/netns/generic.h> |
| 24 |
#include <net/netevent.h> |
| 25 |
#include <net/tcp.h> |
| 26 |
#include <net/ipv6.h> |
| 27 |
#include <net/ip_fib.h> |
| 28 |
#include <net/ip6_route.h> |
| 29 |
|
| 30 |
#include <rdma/rdma_cm.h> |
| 31 |
#include <rdma/rdma_cm_ib.h> |
| 32 |
#include <rdma/rdma_netlink.h> |
| 33 |
#include <rdma/ib.h> |
| 34 |
#include <rdma/ib_cache.h> |
| 35 |
#include <rdma/ib_cm.h> |
| 36 |
#include <rdma/ib_sa.h> |
| 37 |
#include <rdma/iw_cm.h> |
| 38 |
|
| 39 |
#include "core_priv.h" |
| 40 |
#include "cma_priv.h" |
| 41 |
#include "cma_trace.h" |
| 42 |
|
| 43 |
MODULE_AUTHOR("Sean Hefty"); |
| 44 |
MODULE_DESCRIPTION("Generic RDMA CM Agent"); |
| 45 |
MODULE_LICENSE("Dual BSD/GPL"); |
| 46 |
|
| 47 |
#define CMA_CM_RESPONSE_TIMEOUT 20 |
| 48 |
#define CMA_MAX_CM_RETRIES 15 |
| 49 |
#define CMA_IBOE_PACKET_LIFETIME 16 |
| 50 |
#define CMA_PREFERRED_ROCE_GID_TYPE IB_GID_TYPE_ROCE_UDP_ENCAP |
| 51 |
|
| 52 |
static const char * const cma_events[] = { |
| 53 |
[RDMA_CM_EVENT_ADDR_RESOLVED] = "address resolved", |
| 54 |
[RDMA_CM_EVENT_ADDR_ERROR] = "address error", |
| 55 |
[RDMA_CM_EVENT_ROUTE_RESOLVED] = "route resolved ", |
| 56 |
[RDMA_CM_EVENT_ROUTE_ERROR] = "route error", |
| 57 |
[RDMA_CM_EVENT_CONNECT_REQUEST] = "connect request", |
| 58 |
[RDMA_CM_EVENT_CONNECT_RESPONSE] = "connect response", |
| 59 |
[RDMA_CM_EVENT_CONNECT_ERROR] = "connect error", |
| 60 |
[RDMA_CM_EVENT_UNREACHABLE] = "unreachable", |
| 61 |
[RDMA_CM_EVENT_REJECTED] = "rejected", |
| 62 |
[RDMA_CM_EVENT_ESTABLISHED] = "established", |
| 63 |
[RDMA_CM_EVENT_DISCONNECTED] = "disconnected", |
| 64 |
[RDMA_CM_EVENT_DEVICE_REMOVAL] = "device removal", |
| 65 |
[RDMA_CM_EVENT_MULTICAST_JOIN] = "multicast join", |
| 66 |
[RDMA_CM_EVENT_MULTICAST_ERROR] = "multicast error", |
| 67 |
[RDMA_CM_EVENT_ADDR_CHANGE] = "address change", |
| 68 |
[RDMA_CM_EVENT_TIMEWAIT_EXIT] = "timewait exit", |
| 69 |
}; |
| 70 |
|
| 71 |
static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid, |
| 72 |
enum ib_gid_type gid_type); |
| 73 |
|
| 74 |
static void cma_netevent_work_handler(struct work_struct *_work); |
| 75 |
|
| 76 |
const char *__attribute_const__ rdma_event_msg(enum rdma_cm_event_type event) |
| 77 |
{ |
| 78 |
size_t index = event; |
| 79 |
|
| 80 |
return (index < ARRAY_SIZE(cma_events) && cma_events[index]) ? |
| 81 |
cma_events[index] : "unrecognized event"; |
| 82 |
} |
| 83 |
EXPORT_SYMBOL(rdma_event_msg); |
| 84 |
|
| 85 |
const char *__attribute_const__ rdma_reject_msg(struct rdma_cm_id *id, |
| 86 |
int reason) |
| 87 |
{ |
| 88 |
if (rdma_ib_or_roce(id->device, id->port_num)) |
| 89 |
return ibcm_reject_msg(reason); |
| 90 |
|
| 91 |
if (rdma_protocol_iwarp(id->device, id->port_num)) |
| 92 |
return iwcm_reject_msg(reason); |
| 93 |
|
| 94 |
WARN_ON_ONCE(1); |
| 95 |
return "unrecognized transport"; |
| 96 |
} |
| 97 |
EXPORT_SYMBOL(rdma_reject_msg); |
| 98 |
|
| 99 |
/** |
| 100 |
* rdma_is_consumer_reject - return true if the consumer rejected the connect |
| 101 |
* request. |
| 102 |
* @id: Communication identifier that received the REJECT event. |
| 103 |
* @reason: Value returned in the REJECT event status field. |
| 104 |
*/ |
| 105 |
static bool rdma_is_consumer_reject(struct rdma_cm_id *id, int reason) |
| 106 |
{ |
| 107 |
if (rdma_ib_or_roce(id->device, id->port_num)) |
| 108 |
return reason == IB_CM_REJ_CONSUMER_DEFINED; |
| 109 |
|
| 110 |
if (rdma_protocol_iwarp(id->device, id->port_num)) |
| 111 |
return reason == -ECONNREFUSED; |
| 112 |
|
| 113 |
WARN_ON_ONCE(1); |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
const void *rdma_consumer_reject_data(struct rdma_cm_id *id, |
| 118 |
struct rdma_cm_event *ev, u8 *data_len) |
| 119 |
{ |
| 120 |
const void *p; |
| 121 |
|
| 122 |
if (rdma_is_consumer_reject(id, ev->status)) { |
| 123 |
*data_len = ev->param.conn.private_data_len; |
| 124 |
p = ev->param.conn.private_data; |
| 125 |
} else { |
| 126 |
*data_len = 0; |
| 127 |
p = NULL; |
| 128 |
} |
| 129 |
return p; |
| 130 |
} |
| 131 |
EXPORT_SYMBOL(rdma_consumer_reject_data); |
| 132 |
|
| 133 |
/** |
| 134 |
* rdma_iw_cm_id() - return the iw_cm_id pointer for this cm_id. |
| 135 |
* @id: Communication Identifier |
| 136 |
*/ |
| 137 |
struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *id) |
| 138 |
{ |
| 139 |
struct rdma_id_private *id_priv; |
| 140 |
|
| 141 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 142 |
if (id->device->node_type == RDMA_NODE_RNIC) |
| 143 |
return id_priv->cm_id.iw; |
| 144 |
return NULL; |
| 145 |
} |
| 146 |
EXPORT_SYMBOL(rdma_iw_cm_id); |
| 147 |
|
| 148 |
static int cma_add_one(struct ib_device *device); |
| 149 |
static void cma_remove_one(struct ib_device *device, void *client_data); |
| 150 |
|
| 151 |
static struct ib_client cma_client = { |
| 152 |
.name = "cma", |
| 153 |
.add = cma_add_one, |
| 154 |
.remove = cma_remove_one |
| 155 |
}; |
| 156 |
|
| 157 |
static struct ib_sa_client sa_client; |
| 158 |
static LIST_HEAD(dev_list); |
| 159 |
static LIST_HEAD(listen_any_list); |
| 160 |
static DEFINE_MUTEX(lock); |
| 161 |
static struct rb_root id_table = RB_ROOT; |
| 162 |
/* Serialize operations of id_table tree */ |
| 163 |
static DEFINE_SPINLOCK(id_table_lock); |
| 164 |
static struct workqueue_struct *cma_wq; |
| 165 |
static unsigned int cma_pernet_id; |
| 166 |
|
| 167 |
struct cma_pernet { |
| 168 |
struct xarray tcp_ps; |
| 169 |
struct xarray udp_ps; |
| 170 |
struct xarray ipoib_ps; |
| 171 |
struct xarray ib_ps; |
| 172 |
}; |
| 173 |
|
| 174 |
static struct cma_pernet *cma_pernet(struct net *net) |
| 175 |
{ |
| 176 |
return net_generic(net, cma_pernet_id); |
| 177 |
} |
| 178 |
|
| 179 |
static |
| 180 |
struct xarray *cma_pernet_xa(struct net *net, enum rdma_ucm_port_space ps) |
| 181 |
{ |
| 182 |
struct cma_pernet *pernet = cma_pernet(net); |
| 183 |
|
| 184 |
switch (ps) { |
| 185 |
case RDMA_PS_TCP: |
| 186 |
return &pernet->tcp_ps; |
| 187 |
case RDMA_PS_UDP: |
| 188 |
return &pernet->udp_ps; |
| 189 |
case RDMA_PS_IPOIB: |
| 190 |
return &pernet->ipoib_ps; |
| 191 |
case RDMA_PS_IB: |
| 192 |
return &pernet->ib_ps; |
| 193 |
default: |
| 194 |
return NULL; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
struct id_table_entry { |
| 199 |
struct list_head id_list; |
| 200 |
struct rb_node rb_node; |
| 201 |
}; |
| 202 |
|
| 203 |
struct cma_device { |
| 204 |
struct list_head list; |
| 205 |
struct ib_device *device; |
| 206 |
struct completion comp; |
| 207 |
refcount_t refcount; |
| 208 |
struct list_head id_list; |
| 209 |
enum ib_gid_type *default_gid_type; |
| 210 |
u8 *default_roce_tos; |
| 211 |
}; |
| 212 |
|
| 213 |
struct rdma_bind_list { |
| 214 |
enum rdma_ucm_port_space ps; |
| 215 |
struct hlist_head owners; |
| 216 |
unsigned short port; |
| 217 |
}; |
| 218 |
|
| 219 |
static int cma_ps_alloc(struct net *net, enum rdma_ucm_port_space ps, |
| 220 |
struct rdma_bind_list *bind_list, int snum) |
| 221 |
{ |
| 222 |
struct xarray *xa = cma_pernet_xa(net, ps); |
| 223 |
|
| 224 |
return xa_insert(xa, snum, bind_list, GFP_KERNEL); |
| 225 |
} |
| 226 |
|
| 227 |
static struct rdma_bind_list *cma_ps_find(struct net *net, |
| 228 |
enum rdma_ucm_port_space ps, int snum) |
| 229 |
{ |
| 230 |
struct xarray *xa = cma_pernet_xa(net, ps); |
| 231 |
|
| 232 |
return xa_load(xa, snum); |
| 233 |
} |
| 234 |
|
| 235 |
static void cma_ps_remove(struct net *net, enum rdma_ucm_port_space ps, |
| 236 |
int snum) |
| 237 |
{ |
| 238 |
struct xarray *xa = cma_pernet_xa(net, ps); |
| 239 |
|
| 240 |
xa_erase(xa, snum); |
| 241 |
} |
| 242 |
|
| 243 |
enum { |
| 244 |
CMA_OPTION_AFONLY, |
| 245 |
}; |
| 246 |
|
| 247 |
void cma_dev_get(struct cma_device *cma_dev) |
| 248 |
{ |
| 249 |
refcount_inc(&cma_dev->refcount); |
| 250 |
} |
| 251 |
|
| 252 |
void cma_dev_put(struct cma_device *cma_dev) |
| 253 |
{ |
| 254 |
if (refcount_dec_and_test(&cma_dev->refcount)) |
| 255 |
complete(&cma_dev->comp); |
| 256 |
} |
| 257 |
|
| 258 |
struct cma_device *cma_enum_devices_by_ibdev(cma_device_filter filter, |
| 259 |
void *cookie) |
| 260 |
{ |
| 261 |
struct cma_device *cma_dev; |
| 262 |
struct cma_device *found_cma_dev = NULL; |
| 263 |
|
| 264 |
mutex_lock(&lock); |
| 265 |
|
| 266 |
list_for_each_entry(cma_dev, &dev_list, list) |
| 267 |
if (filter(cma_dev->device, cookie)) { |
| 268 |
found_cma_dev = cma_dev; |
| 269 |
break; |
| 270 |
} |
| 271 |
|
| 272 |
if (found_cma_dev) |
| 273 |
cma_dev_get(found_cma_dev); |
| 274 |
mutex_unlock(&lock); |
| 275 |
return found_cma_dev; |
| 276 |
} |
| 277 |
|
| 278 |
int cma_get_default_gid_type(struct cma_device *cma_dev, |
| 279 |
u32 port) |
| 280 |
{ |
| 281 |
if (!rdma_is_port_valid(cma_dev->device, port)) |
| 282 |
return -EINVAL; |
| 283 |
|
| 284 |
return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)]; |
| 285 |
} |
| 286 |
|
| 287 |
int cma_set_default_gid_type(struct cma_device *cma_dev, |
| 288 |
u32 port, |
| 289 |
enum ib_gid_type default_gid_type) |
| 290 |
{ |
| 291 |
unsigned long supported_gids; |
| 292 |
|
| 293 |
if (!rdma_is_port_valid(cma_dev->device, port)) |
| 294 |
return -EINVAL; |
| 295 |
|
| 296 |
if (default_gid_type == IB_GID_TYPE_IB && |
| 297 |
rdma_protocol_roce_eth_encap(cma_dev->device, port)) |
| 298 |
default_gid_type = IB_GID_TYPE_ROCE; |
| 299 |
|
| 300 |
supported_gids = roce_gid_type_mask_support(cma_dev->device, port); |
| 301 |
|
| 302 |
if (!(supported_gids & 1 << default_gid_type)) |
| 303 |
return -EINVAL; |
| 304 |
|
| 305 |
cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)] = |
| 306 |
default_gid_type; |
| 307 |
|
| 308 |
return 0; |
| 309 |
} |
| 310 |
|
| 311 |
int cma_get_default_roce_tos(struct cma_device *cma_dev, u32 port) |
| 312 |
{ |
| 313 |
if (!rdma_is_port_valid(cma_dev->device, port)) |
| 314 |
return -EINVAL; |
| 315 |
|
| 316 |
return cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)]; |
| 317 |
} |
| 318 |
|
| 319 |
int cma_set_default_roce_tos(struct cma_device *cma_dev, u32 port, |
| 320 |
u8 default_roce_tos) |
| 321 |
{ |
| 322 |
if (!rdma_is_port_valid(cma_dev->device, port)) |
| 323 |
return -EINVAL; |
| 324 |
|
| 325 |
cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)] = |
| 326 |
default_roce_tos; |
| 327 |
|
| 328 |
return 0; |
| 329 |
} |
| 330 |
struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev) |
| 331 |
{ |
| 332 |
return cma_dev->device; |
| 333 |
} |
| 334 |
|
| 335 |
/* |
| 336 |
* Device removal can occur at anytime, so we need extra handling to |
| 337 |
* serialize notifying the user of device removal with other callbacks. |
| 338 |
* We do this by disabling removal notification while a callback is in process, |
| 339 |
* and reporting it after the callback completes. |
| 340 |
*/ |
| 341 |
|
| 342 |
struct cma_multicast { |
| 343 |
struct rdma_id_private *id_priv; |
| 344 |
union { |
| 345 |
struct ib_sa_multicast *sa_mc; |
| 346 |
struct { |
| 347 |
struct work_struct work; |
| 348 |
struct rdma_cm_event event; |
| 349 |
} iboe_join; |
| 350 |
}; |
| 351 |
struct list_head list; |
| 352 |
void *context; |
| 353 |
struct sockaddr_storage addr; |
| 354 |
u8 join_state; |
| 355 |
}; |
| 356 |
|
| 357 |
struct cma_work { |
| 358 |
struct work_struct work; |
| 359 |
struct rdma_id_private *id; |
| 360 |
enum rdma_cm_state old_state; |
| 361 |
enum rdma_cm_state new_state; |
| 362 |
struct rdma_cm_event event; |
| 363 |
}; |
| 364 |
|
| 365 |
union cma_ip_addr { |
| 366 |
struct in6_addr ip6; |
| 367 |
struct { |
| 368 |
__be32 pad[3]; |
| 369 |
__be32 addr; |
| 370 |
} ip4; |
| 371 |
}; |
| 372 |
|
| 373 |
struct cma_hdr { |
| 374 |
u8 cma_version; |
| 375 |
u8 ip_version; /* IP version: 7:4 */ |
| 376 |
__be16 port; |
| 377 |
union cma_ip_addr src_addr; |
| 378 |
union cma_ip_addr dst_addr; |
| 379 |
}; |
| 380 |
|
| 381 |
#define CMA_VERSION 0x00 |
| 382 |
|
| 383 |
struct cma_req_info { |
| 384 |
struct sockaddr_storage listen_addr_storage; |
| 385 |
struct sockaddr_storage src_addr_storage; |
| 386 |
struct ib_device *device; |
| 387 |
union ib_gid local_gid; |
| 388 |
__be64 service_id; |
| 389 |
int port; |
| 390 |
bool has_gid; |
| 391 |
u16 pkey; |
| 392 |
}; |
| 393 |
|
| 394 |
static int cma_comp_exch(struct rdma_id_private *id_priv, |
| 395 |
enum rdma_cm_state comp, enum rdma_cm_state exch) |
| 396 |
{ |
| 397 |
unsigned long flags; |
| 398 |
int ret; |
| 399 |
|
| 400 |
/* |
| 401 |
* The FSM uses a funny double locking where state is protected by both |
| 402 |
* the handler_mutex and the spinlock. State is not allowed to change |
| 403 |
* to/from a handler_mutex protected value without also holding |
| 404 |
* handler_mutex. |
| 405 |
*/ |
| 406 |
if (comp == RDMA_CM_CONNECT || exch == RDMA_CM_CONNECT) |
| 407 |
lockdep_assert_held(&id_priv->handler_mutex); |
| 408 |
|
| 409 |
spin_lock_irqsave(&id_priv->lock, flags); |
| 410 |
if ((ret = (id_priv->state == comp))) |
| 411 |
id_priv->state = exch; |
| 412 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 413 |
return ret; |
| 414 |
} |
| 415 |
|
| 416 |
static inline u8 cma_get_ip_ver(const struct cma_hdr *hdr) |
| 417 |
{ |
| 418 |
return hdr->ip_version >> 4; |
| 419 |
} |
| 420 |
|
| 421 |
static void cma_set_ip_ver(struct cma_hdr *hdr, u8 ip_ver) |
| 422 |
{ |
| 423 |
hdr->ip_version = (ip_ver << 4) | (hdr->ip_version & 0xF); |
| 424 |
} |
| 425 |
|
| 426 |
static struct sockaddr *cma_src_addr(struct rdma_id_private *id_priv) |
| 427 |
{ |
| 428 |
return (struct sockaddr *)&id_priv->id.route.addr.src_addr; |
| 429 |
} |
| 430 |
|
| 431 |
static inline struct sockaddr *cma_dst_addr(struct rdma_id_private *id_priv) |
| 432 |
{ |
| 433 |
return (struct sockaddr *)&id_priv->id.route.addr.dst_addr; |
| 434 |
} |
| 435 |
|
| 436 |
static int cma_igmp_send(struct net_device *ndev, union ib_gid *mgid, bool join) |
| 437 |
{ |
| 438 |
struct in_device *in_dev = NULL; |
| 439 |
|
| 440 |
if (ndev) { |
| 441 |
rtnl_lock(); |
| 442 |
in_dev = __in_dev_get_rtnl(ndev); |
| 443 |
if (in_dev) { |
| 444 |
if (join) |
| 445 |
ip_mc_inc_group(in_dev, |
| 446 |
*(__be32 *)(mgid->raw + 12)); |
| 447 |
else |
| 448 |
ip_mc_dec_group(in_dev, |
| 449 |
*(__be32 *)(mgid->raw + 12)); |
| 450 |
} |
| 451 |
rtnl_unlock(); |
| 452 |
} |
| 453 |
return (in_dev) ? 0 : -ENODEV; |
| 454 |
} |
| 455 |
|
| 456 |
static int compare_netdev_and_ip(int ifindex_a, struct sockaddr *sa, |
| 457 |
struct id_table_entry *entry_b) |
| 458 |
{ |
| 459 |
struct rdma_id_private *id_priv = list_first_entry( |
| 460 |
&entry_b->id_list, struct rdma_id_private, id_list_entry); |
| 461 |
int ifindex_b = id_priv->id.route.addr.dev_addr.bound_dev_if; |
| 462 |
struct sockaddr *sb = cma_dst_addr(id_priv); |
| 463 |
|
| 464 |
if (ifindex_a != ifindex_b) |
| 465 |
return (ifindex_a > ifindex_b) ? 1 : -1; |
| 466 |
|
| 467 |
if (sa->sa_family != sb->sa_family) |
| 468 |
return sa->sa_family - sb->sa_family; |
| 469 |
|
| 470 |
if (sa->sa_family == AF_INET && |
| 471 |
__builtin_object_size(sa, 0) >= sizeof(struct sockaddr_in)) { |
| 472 |
return memcmp(&((struct sockaddr_in *)sa)->sin_addr, |
| 473 |
&((struct sockaddr_in *)sb)->sin_addr, |
| 474 |
sizeof(((struct sockaddr_in *)sa)->sin_addr)); |
| 475 |
} |
| 476 |
|
| 477 |
if (sa->sa_family == AF_INET6 && |
| 478 |
__builtin_object_size(sa, 0) >= sizeof(struct sockaddr_in6)) { |
| 479 |
return ipv6_addr_cmp(&((struct sockaddr_in6 *)sa)->sin6_addr, |
| 480 |
&((struct sockaddr_in6 *)sb)->sin6_addr); |
| 481 |
} |
| 482 |
|
| 483 |
return -1; |
| 484 |
} |
| 485 |
|
| 486 |
static int cma_add_id_to_tree(struct rdma_id_private *node_id_priv) |
| 487 |
{ |
| 488 |
struct rb_node **new, *parent = NULL; |
| 489 |
struct id_table_entry *this, *node; |
| 490 |
unsigned long flags; |
| 491 |
int result; |
| 492 |
|
| 493 |
node = kzalloc_obj(*node); |
| 494 |
if (!node) |
| 495 |
return -ENOMEM; |
| 496 |
|
| 497 |
spin_lock_irqsave(&id_table_lock, flags); |
| 498 |
new = &id_table.rb_node; |
| 499 |
while (*new) { |
| 500 |
this = container_of(*new, struct id_table_entry, rb_node); |
| 501 |
result = compare_netdev_and_ip( |
| 502 |
node_id_priv->id.route.addr.dev_addr.bound_dev_if, |
| 503 |
cma_dst_addr(node_id_priv), this); |
| 504 |
|
| 505 |
parent = *new; |
| 506 |
if (result < 0) |
| 507 |
new = &((*new)->rb_left); |
| 508 |
else if (result > 0) |
| 509 |
new = &((*new)->rb_right); |
| 510 |
else { |
| 511 |
list_add_tail(&node_id_priv->id_list_entry, |
| 512 |
&this->id_list); |
| 513 |
kfree(node); |
| 514 |
goto unlock; |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
INIT_LIST_HEAD(&node->id_list); |
| 519 |
list_add_tail(&node_id_priv->id_list_entry, &node->id_list); |
| 520 |
|
| 521 |
rb_link_node(&node->rb_node, parent, new); |
| 522 |
rb_insert_color(&node->rb_node, &id_table); |
| 523 |
|
| 524 |
unlock: |
| 525 |
spin_unlock_irqrestore(&id_table_lock, flags); |
| 526 |
return 0; |
| 527 |
} |
| 528 |
|
| 529 |
static struct id_table_entry * |
| 530 |
node_from_ndev_ip(struct rb_root *root, int ifindex, struct sockaddr *sa) |
| 531 |
{ |
| 532 |
struct rb_node *node = root->rb_node; |
| 533 |
struct id_table_entry *data; |
| 534 |
int result; |
| 535 |
|
| 536 |
while (node) { |
| 537 |
data = container_of(node, struct id_table_entry, rb_node); |
| 538 |
result = compare_netdev_and_ip(ifindex, sa, data); |
| 539 |
if (result < 0) |
| 540 |
node = node->rb_left; |
| 541 |
else if (result > 0) |
| 542 |
node = node->rb_right; |
| 543 |
else |
| 544 |
return data; |
| 545 |
} |
| 546 |
|
| 547 |
return NULL; |
| 548 |
} |
| 549 |
|
| 550 |
static void cma_remove_id_from_tree(struct rdma_id_private *id_priv) |
| 551 |
{ |
| 552 |
struct id_table_entry *data; |
| 553 |
unsigned long flags; |
| 554 |
|
| 555 |
spin_lock_irqsave(&id_table_lock, flags); |
| 556 |
if (list_empty(&id_priv->id_list_entry)) |
| 557 |
goto out; |
| 558 |
|
| 559 |
data = node_from_ndev_ip(&id_table, |
| 560 |
id_priv->id.route.addr.dev_addr.bound_dev_if, |
| 561 |
cma_dst_addr(id_priv)); |
| 562 |
if (!data) |
| 563 |
goto out; |
| 564 |
|
| 565 |
list_del_init(&id_priv->id_list_entry); |
| 566 |
if (list_empty(&data->id_list)) { |
| 567 |
rb_erase(&data->rb_node, &id_table); |
| 568 |
kfree(data); |
| 569 |
} |
| 570 |
out: |
| 571 |
spin_unlock_irqrestore(&id_table_lock, flags); |
| 572 |
} |
| 573 |
|
| 574 |
static void _cma_attach_to_dev(struct rdma_id_private *id_priv, |
| 575 |
struct cma_device *cma_dev) |
| 576 |
{ |
| 577 |
cma_dev_get(cma_dev); |
| 578 |
id_priv->cma_dev = cma_dev; |
| 579 |
id_priv->id.device = cma_dev->device; |
| 580 |
id_priv->id.route.addr.dev_addr.transport = |
| 581 |
rdma_node_get_transport(cma_dev->device->node_type); |
| 582 |
list_add_tail(&id_priv->device_item, &cma_dev->id_list); |
| 583 |
|
| 584 |
trace_cm_id_attach(id_priv, cma_dev->device); |
| 585 |
} |
| 586 |
|
| 587 |
static void cma_attach_to_dev(struct rdma_id_private *id_priv, |
| 588 |
struct cma_device *cma_dev) |
| 589 |
{ |
| 590 |
_cma_attach_to_dev(id_priv, cma_dev); |
| 591 |
id_priv->gid_type = |
| 592 |
cma_dev->default_gid_type[id_priv->id.port_num - |
| 593 |
rdma_start_port(cma_dev->device)]; |
| 594 |
} |
| 595 |
|
| 596 |
static void cma_release_dev(struct rdma_id_private *id_priv) |
| 597 |
{ |
| 598 |
mutex_lock(&lock); |
| 599 |
list_del_init(&id_priv->device_item); |
| 600 |
cma_dev_put(id_priv->cma_dev); |
| 601 |
id_priv->cma_dev = NULL; |
| 602 |
id_priv->id.device = NULL; |
| 603 |
if (id_priv->id.route.addr.dev_addr.sgid_attr) { |
| 604 |
rdma_put_gid_attr(id_priv->id.route.addr.dev_addr.sgid_attr); |
| 605 |
id_priv->id.route.addr.dev_addr.sgid_attr = NULL; |
| 606 |
} |
| 607 |
mutex_unlock(&lock); |
| 608 |
} |
| 609 |
|
| 610 |
static inline unsigned short cma_family(struct rdma_id_private *id_priv) |
| 611 |
{ |
| 612 |
return id_priv->id.route.addr.src_addr.ss_family; |
| 613 |
} |
| 614 |
|
| 615 |
static int cma_set_default_qkey(struct rdma_id_private *id_priv) |
| 616 |
{ |
| 617 |
struct ib_sa_mcmember_rec rec; |
| 618 |
int ret = 0; |
| 619 |
|
| 620 |
switch (id_priv->id.ps) { |
| 621 |
case RDMA_PS_UDP: |
| 622 |
case RDMA_PS_IB: |
| 623 |
id_priv->qkey = RDMA_UDP_QKEY; |
| 624 |
break; |
| 625 |
case RDMA_PS_IPOIB: |
| 626 |
ib_addr_get_mgid(&id_priv->id.route.addr.dev_addr, &rec.mgid); |
| 627 |
ret = ib_sa_get_mcmember_rec(id_priv->id.device, |
| 628 |
id_priv->id.port_num, &rec.mgid, |
| 629 |
&rec); |
| 630 |
if (!ret) |
| 631 |
id_priv->qkey = be32_to_cpu(rec.qkey); |
| 632 |
break; |
| 633 |
default: |
| 634 |
break; |
| 635 |
} |
| 636 |
return ret; |
| 637 |
} |
| 638 |
|
| 639 |
static int cma_set_qkey(struct rdma_id_private *id_priv, u32 qkey) |
| 640 |
{ |
| 641 |
if (!qkey || |
| 642 |
(id_priv->qkey && (id_priv->qkey != qkey))) |
| 643 |
return -EINVAL; |
| 644 |
|
| 645 |
id_priv->qkey = qkey; |
| 646 |
return 0; |
| 647 |
} |
| 648 |
|
| 649 |
static void cma_translate_ib(struct sockaddr_ib *sib, struct rdma_dev_addr *dev_addr) |
| 650 |
{ |
| 651 |
dev_addr->dev_type = ARPHRD_INFINIBAND; |
| 652 |
rdma_addr_set_sgid(dev_addr, (union ib_gid *) &sib->sib_addr); |
| 653 |
ib_addr_set_pkey(dev_addr, ntohs(sib->sib_pkey)); |
| 654 |
} |
| 655 |
|
| 656 |
static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_addr) |
| 657 |
{ |
| 658 |
int ret; |
| 659 |
|
| 660 |
if (addr->sa_family != AF_IB) { |
| 661 |
ret = rdma_translate_ip(addr, dev_addr); |
| 662 |
} else { |
| 663 |
cma_translate_ib((struct sockaddr_ib *) addr, dev_addr); |
| 664 |
ret = 0; |
| 665 |
} |
| 666 |
|
| 667 |
return ret; |
| 668 |
} |
| 669 |
|
| 670 |
static const struct ib_gid_attr * |
| 671 |
cma_validate_port(struct ib_device *device, u32 port, |
| 672 |
enum ib_gid_type gid_type, |
| 673 |
union ib_gid *gid, |
| 674 |
struct rdma_id_private *id_priv) |
| 675 |
{ |
| 676 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 677 |
const struct ib_gid_attr *sgid_attr = ERR_PTR(-ENODEV); |
| 678 |
int bound_if_index = dev_addr->bound_dev_if; |
| 679 |
int dev_type = dev_addr->dev_type; |
| 680 |
struct net_device *ndev = NULL; |
| 681 |
struct net_device *pdev = NULL; |
| 682 |
|
| 683 |
if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net)) |
| 684 |
goto out; |
| 685 |
|
| 686 |
if ((dev_type == ARPHRD_INFINIBAND) && !rdma_protocol_ib(device, port)) |
| 687 |
goto out; |
| 688 |
|
| 689 |
if ((dev_type != ARPHRD_INFINIBAND) && rdma_protocol_ib(device, port)) |
| 690 |
goto out; |
| 691 |
|
| 692 |
/* |
| 693 |
* For drivers that do not associate more than one net device with |
| 694 |
* their gid tables, such as iWARP drivers, it is sufficient to |
| 695 |
* return the first table entry. |
| 696 |
* |
| 697 |
* Other driver classes might be included in the future. |
| 698 |
*/ |
| 699 |
if (rdma_protocol_iwarp(device, port)) { |
| 700 |
sgid_attr = rdma_get_gid_attr(device, port, 0); |
| 701 |
if (IS_ERR(sgid_attr)) |
| 702 |
goto out; |
| 703 |
|
| 704 |
rcu_read_lock(); |
| 705 |
ndev = rcu_dereference(sgid_attr->ndev); |
| 706 |
if (ndev->ifindex != bound_if_index) { |
| 707 |
pdev = dev_get_by_index_rcu(dev_addr->net, bound_if_index); |
| 708 |
if (pdev) { |
| 709 |
if (is_vlan_dev(pdev)) { |
| 710 |
pdev = vlan_dev_real_dev(pdev); |
| 711 |
if (ndev->ifindex == pdev->ifindex) |
| 712 |
bound_if_index = pdev->ifindex; |
| 713 |
} |
| 714 |
if (is_vlan_dev(ndev)) { |
| 715 |
pdev = vlan_dev_real_dev(ndev); |
| 716 |
if (bound_if_index == pdev->ifindex) |
| 717 |
bound_if_index = ndev->ifindex; |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
if (!net_eq(dev_net(ndev), dev_addr->net) || |
| 722 |
ndev->ifindex != bound_if_index) { |
| 723 |
rdma_put_gid_attr(sgid_attr); |
| 724 |
sgid_attr = ERR_PTR(-ENODEV); |
| 725 |
} |
| 726 |
rcu_read_unlock(); |
| 727 |
goto out; |
| 728 |
} |
| 729 |
|
| 730 |
/* |
| 731 |
* For a RXE device, it should work with TUN device and normal ethernet |
| 732 |
* devices. Use driver_id to check if a device is a RXE device or not. |
| 733 |
* ARPHDR_NONE means a TUN device. |
| 734 |
*/ |
| 735 |
if (device->ops.driver_id == RDMA_DRIVER_RXE) { |
| 736 |
if ((dev_type == ARPHRD_NONE || dev_type == ARPHRD_ETHER) |
| 737 |
&& rdma_protocol_roce(device, port)) { |
| 738 |
ndev = dev_get_by_index(dev_addr->net, bound_if_index); |
| 739 |
if (!ndev) |
| 740 |
goto out; |
| 741 |
} |
| 742 |
} else { |
| 743 |
if (dev_type == ARPHRD_ETHER && rdma_protocol_roce(device, port)) { |
| 744 |
ndev = dev_get_by_index(dev_addr->net, bound_if_index); |
| 745 |
if (!ndev) |
| 746 |
goto out; |
| 747 |
} else { |
| 748 |
gid_type = IB_GID_TYPE_IB; |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
sgid_attr = rdma_find_gid_by_port(device, gid, gid_type, port, ndev); |
| 753 |
dev_put(ndev); |
| 754 |
out: |
| 755 |
return sgid_attr; |
| 756 |
} |
| 757 |
|
| 758 |
static void cma_bind_sgid_attr(struct rdma_id_private *id_priv, |
| 759 |
const struct ib_gid_attr *sgid_attr) |
| 760 |
{ |
| 761 |
WARN_ON(id_priv->id.route.addr.dev_addr.sgid_attr); |
| 762 |
id_priv->id.route.addr.dev_addr.sgid_attr = sgid_attr; |
| 763 |
} |
| 764 |
|
| 765 |
/** |
| 766 |
* cma_acquire_dev_by_src_ip - Acquire cma device, port, gid attribute |
| 767 |
* based on source ip address. |
| 768 |
* @id_priv: cm_id which should be bound to cma device |
| 769 |
* |
| 770 |
* cma_acquire_dev_by_src_ip() binds cm id to cma device, port and GID attribute |
| 771 |
* based on source IP address. It returns 0 on success or error code otherwise. |
| 772 |
* It is applicable to active and passive side cm_id. |
| 773 |
*/ |
| 774 |
static int cma_acquire_dev_by_src_ip(struct rdma_id_private *id_priv) |
| 775 |
{ |
| 776 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 777 |
const struct ib_gid_attr *sgid_attr; |
| 778 |
union ib_gid gid, iboe_gid, *gidp; |
| 779 |
struct cma_device *cma_dev; |
| 780 |
enum ib_gid_type gid_type; |
| 781 |
int ret = -ENODEV; |
| 782 |
u32 port; |
| 783 |
|
| 784 |
if (dev_addr->dev_type != ARPHRD_INFINIBAND && |
| 785 |
id_priv->id.ps == RDMA_PS_IPOIB) |
| 786 |
return -EINVAL; |
| 787 |
|
| 788 |
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 789 |
&iboe_gid); |
| 790 |
|
| 791 |
memcpy(&gid, dev_addr->src_dev_addr + |
| 792 |
rdma_addr_gid_offset(dev_addr), sizeof(gid)); |
| 793 |
|
| 794 |
mutex_lock(&lock); |
| 795 |
list_for_each_entry(cma_dev, &dev_list, list) { |
| 796 |
if (id_priv->restricted_node_type != RDMA_NODE_UNSPECIFIED && |
| 797 |
id_priv->restricted_node_type != cma_dev->device->node_type) |
| 798 |
continue; |
| 799 |
rdma_for_each_port (cma_dev->device, port) { |
| 800 |
gidp = rdma_protocol_roce(cma_dev->device, port) ? |
| 801 |
&iboe_gid : &gid; |
| 802 |
gid_type = cma_dev->default_gid_type[port - 1]; |
| 803 |
sgid_attr = cma_validate_port(cma_dev->device, port, |
| 804 |
gid_type, gidp, id_priv); |
| 805 |
if (!IS_ERR(sgid_attr)) { |
| 806 |
id_priv->id.port_num = port; |
| 807 |
cma_bind_sgid_attr(id_priv, sgid_attr); |
| 808 |
cma_attach_to_dev(id_priv, cma_dev); |
| 809 |
ret = 0; |
| 810 |
goto out; |
| 811 |
} |
| 812 |
} |
| 813 |
} |
| 814 |
out: |
| 815 |
mutex_unlock(&lock); |
| 816 |
return ret; |
| 817 |
} |
| 818 |
|
| 819 |
/** |
| 820 |
* cma_ib_acquire_dev - Acquire cma device, port and SGID attribute |
| 821 |
* @id_priv: cm id to bind to cma device |
| 822 |
* @listen_id_priv: listener cm id to match against |
| 823 |
* @req: Pointer to req structure containaining incoming |
| 824 |
* request information |
| 825 |
* cma_ib_acquire_dev() acquires cma device, port and SGID attribute when |
| 826 |
* rdma device matches for listen_id and incoming request. It also verifies |
| 827 |
* that a GID table entry is present for the source address. |
| 828 |
* Returns 0 on success, or returns error code otherwise. |
| 829 |
*/ |
| 830 |
static int cma_ib_acquire_dev(struct rdma_id_private *id_priv, |
| 831 |
const struct rdma_id_private *listen_id_priv, |
| 832 |
struct cma_req_info *req) |
| 833 |
{ |
| 834 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 835 |
const struct ib_gid_attr *sgid_attr; |
| 836 |
enum ib_gid_type gid_type; |
| 837 |
union ib_gid gid; |
| 838 |
|
| 839 |
if (dev_addr->dev_type != ARPHRD_INFINIBAND && |
| 840 |
id_priv->id.ps == RDMA_PS_IPOIB) |
| 841 |
return -EINVAL; |
| 842 |
|
| 843 |
if (rdma_protocol_roce(req->device, req->port)) |
| 844 |
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 845 |
&gid); |
| 846 |
else |
| 847 |
memcpy(&gid, dev_addr->src_dev_addr + |
| 848 |
rdma_addr_gid_offset(dev_addr), sizeof(gid)); |
| 849 |
|
| 850 |
gid_type = listen_id_priv->cma_dev->default_gid_type[req->port - 1]; |
| 851 |
sgid_attr = cma_validate_port(req->device, req->port, |
| 852 |
gid_type, &gid, id_priv); |
| 853 |
if (IS_ERR(sgid_attr)) |
| 854 |
return PTR_ERR(sgid_attr); |
| 855 |
|
| 856 |
id_priv->id.port_num = req->port; |
| 857 |
cma_bind_sgid_attr(id_priv, sgid_attr); |
| 858 |
/* Need to acquire lock to protect against reader |
| 859 |
* of cma_dev->id_list such as cma_netdev_callback() and |
| 860 |
* cma_process_remove(). |
| 861 |
*/ |
| 862 |
mutex_lock(&lock); |
| 863 |
cma_attach_to_dev(id_priv, listen_id_priv->cma_dev); |
| 864 |
mutex_unlock(&lock); |
| 865 |
rdma_restrack_add(&id_priv->res); |
| 866 |
return 0; |
| 867 |
} |
| 868 |
|
| 869 |
static int cma_iw_acquire_dev(struct rdma_id_private *id_priv, |
| 870 |
const struct rdma_id_private *listen_id_priv) |
| 871 |
{ |
| 872 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 873 |
const struct ib_gid_attr *sgid_attr; |
| 874 |
struct cma_device *cma_dev; |
| 875 |
enum ib_gid_type gid_type; |
| 876 |
int ret = -ENODEV; |
| 877 |
union ib_gid gid; |
| 878 |
u32 port; |
| 879 |
|
| 880 |
if (dev_addr->dev_type != ARPHRD_INFINIBAND && |
| 881 |
id_priv->id.ps == RDMA_PS_IPOIB) |
| 882 |
return -EINVAL; |
| 883 |
|
| 884 |
memcpy(&gid, dev_addr->src_dev_addr + |
| 885 |
rdma_addr_gid_offset(dev_addr), sizeof(gid)); |
| 886 |
|
| 887 |
mutex_lock(&lock); |
| 888 |
|
| 889 |
cma_dev = listen_id_priv->cma_dev; |
| 890 |
port = listen_id_priv->id.port_num; |
| 891 |
gid_type = listen_id_priv->gid_type; |
| 892 |
sgid_attr = cma_validate_port(cma_dev->device, port, |
| 893 |
gid_type, &gid, id_priv); |
| 894 |
if (!IS_ERR(sgid_attr)) { |
| 895 |
id_priv->id.port_num = port; |
| 896 |
cma_bind_sgid_attr(id_priv, sgid_attr); |
| 897 |
ret = 0; |
| 898 |
goto out; |
| 899 |
} |
| 900 |
|
| 901 |
list_for_each_entry(cma_dev, &dev_list, list) { |
| 902 |
rdma_for_each_port (cma_dev->device, port) { |
| 903 |
if (listen_id_priv->cma_dev == cma_dev && |
| 904 |
listen_id_priv->id.port_num == port) |
| 905 |
continue; |
| 906 |
|
| 907 |
gid_type = cma_dev->default_gid_type[port - 1]; |
| 908 |
sgid_attr = cma_validate_port(cma_dev->device, port, |
| 909 |
gid_type, &gid, id_priv); |
| 910 |
if (!IS_ERR(sgid_attr)) { |
| 911 |
id_priv->id.port_num = port; |
| 912 |
cma_bind_sgid_attr(id_priv, sgid_attr); |
| 913 |
ret = 0; |
| 914 |
goto out; |
| 915 |
} |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
out: |
| 920 |
if (!ret) { |
| 921 |
cma_attach_to_dev(id_priv, cma_dev); |
| 922 |
rdma_restrack_add(&id_priv->res); |
| 923 |
} |
| 924 |
|
| 925 |
mutex_unlock(&lock); |
| 926 |
return ret; |
| 927 |
} |
| 928 |
|
| 929 |
/* |
| 930 |
* Select the source IB device and address to reach the destination IB address. |
| 931 |
*/ |
| 932 |
static int cma_resolve_ib_dev(struct rdma_id_private *id_priv) |
| 933 |
{ |
| 934 |
struct cma_device *cma_dev, *cur_dev; |
| 935 |
struct sockaddr_ib *addr; |
| 936 |
union ib_gid gid, sgid, *dgid; |
| 937 |
unsigned int p; |
| 938 |
u16 pkey, index; |
| 939 |
enum ib_port_state port_state; |
| 940 |
int ret; |
| 941 |
int i; |
| 942 |
|
| 943 |
cma_dev = NULL; |
| 944 |
addr = (struct sockaddr_ib *) cma_dst_addr(id_priv); |
| 945 |
dgid = (union ib_gid *) &addr->sib_addr; |
| 946 |
pkey = ntohs(addr->sib_pkey); |
| 947 |
|
| 948 |
mutex_lock(&lock); |
| 949 |
list_for_each_entry(cur_dev, &dev_list, list) { |
| 950 |
rdma_for_each_port (cur_dev->device, p) { |
| 951 |
if (!rdma_cap_af_ib(cur_dev->device, p)) |
| 952 |
continue; |
| 953 |
|
| 954 |
if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index)) |
| 955 |
continue; |
| 956 |
|
| 957 |
if (ib_get_cached_port_state(cur_dev->device, p, &port_state)) |
| 958 |
continue; |
| 959 |
|
| 960 |
for (i = 0; i < cur_dev->device->port_data[p].immutable.gid_tbl_len; |
| 961 |
++i) { |
| 962 |
ret = rdma_query_gid(cur_dev->device, p, i, |
| 963 |
&gid); |
| 964 |
if (ret) |
| 965 |
continue; |
| 966 |
|
| 967 |
if (!memcmp(&gid, dgid, sizeof(gid))) { |
| 968 |
cma_dev = cur_dev; |
| 969 |
sgid = gid; |
| 970 |
id_priv->id.port_num = p; |
| 971 |
goto found; |
| 972 |
} |
| 973 |
|
| 974 |
if (!cma_dev && (gid.global.subnet_prefix == |
| 975 |
dgid->global.subnet_prefix) && |
| 976 |
port_state == IB_PORT_ACTIVE) { |
| 977 |
cma_dev = cur_dev; |
| 978 |
sgid = gid; |
| 979 |
id_priv->id.port_num = p; |
| 980 |
goto found; |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
} |
| 985 |
mutex_unlock(&lock); |
| 986 |
return -ENODEV; |
| 987 |
|
| 988 |
found: |
| 989 |
cma_attach_to_dev(id_priv, cma_dev); |
| 990 |
rdma_restrack_add(&id_priv->res); |
| 991 |
mutex_unlock(&lock); |
| 992 |
addr = (struct sockaddr_ib *)cma_src_addr(id_priv); |
| 993 |
memcpy(&addr->sib_addr, &sgid, sizeof(sgid)); |
| 994 |
cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); |
| 995 |
return 0; |
| 996 |
} |
| 997 |
|
| 998 |
static void cma_id_get(struct rdma_id_private *id_priv) |
| 999 |
{ |
| 1000 |
refcount_inc(&id_priv->refcount); |
| 1001 |
} |
| 1002 |
|
| 1003 |
static void cma_id_put(struct rdma_id_private *id_priv) |
| 1004 |
{ |
| 1005 |
if (refcount_dec_and_test(&id_priv->refcount)) |
| 1006 |
complete(&id_priv->comp); |
| 1007 |
} |
| 1008 |
|
| 1009 |
static struct rdma_id_private * |
| 1010 |
__rdma_create_id(struct net *net, rdma_cm_event_handler event_handler, |
| 1011 |
void *context, enum rdma_ucm_port_space ps, |
| 1012 |
enum ib_qp_type qp_type, const struct rdma_id_private *parent) |
| 1013 |
{ |
| 1014 |
struct rdma_id_private *id_priv; |
| 1015 |
|
| 1016 |
id_priv = kzalloc_obj(*id_priv); |
| 1017 |
if (!id_priv) |
| 1018 |
return ERR_PTR(-ENOMEM); |
| 1019 |
|
| 1020 |
id_priv->state = RDMA_CM_IDLE; |
| 1021 |
id_priv->restricted_node_type = RDMA_NODE_UNSPECIFIED; |
| 1022 |
id_priv->id.context = context; |
| 1023 |
id_priv->id.event_handler = event_handler; |
| 1024 |
id_priv->id.ps = ps; |
| 1025 |
id_priv->id.qp_type = qp_type; |
| 1026 |
id_priv->tos_set = false; |
| 1027 |
id_priv->timeout_set = false; |
| 1028 |
id_priv->min_rnr_timer_set = false; |
| 1029 |
id_priv->gid_type = IB_GID_TYPE_IB; |
| 1030 |
spin_lock_init(&id_priv->lock); |
| 1031 |
mutex_init(&id_priv->qp_mutex); |
| 1032 |
init_completion(&id_priv->comp); |
| 1033 |
refcount_set(&id_priv->refcount, 1); |
| 1034 |
mutex_init(&id_priv->handler_mutex); |
| 1035 |
INIT_LIST_HEAD(&id_priv->device_item); |
| 1036 |
INIT_LIST_HEAD(&id_priv->id_list_entry); |
| 1037 |
INIT_LIST_HEAD(&id_priv->listen_list); |
| 1038 |
INIT_LIST_HEAD(&id_priv->mc_list); |
| 1039 |
get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); |
| 1040 |
id_priv->id.route.addr.dev_addr.net = get_net(net); |
| 1041 |
id_priv->seq_num &= 0x00ffffff; |
| 1042 |
INIT_WORK(&id_priv->id.net_work, cma_netevent_work_handler); |
| 1043 |
|
| 1044 |
rdma_restrack_new(&id_priv->res, RDMA_RESTRACK_CM_ID); |
| 1045 |
if (parent) |
| 1046 |
rdma_restrack_parent_name(&id_priv->res, &parent->res); |
| 1047 |
|
| 1048 |
return id_priv; |
| 1049 |
} |
| 1050 |
|
| 1051 |
struct rdma_cm_id * |
| 1052 |
__rdma_create_kernel_id(struct net *net, rdma_cm_event_handler event_handler, |
| 1053 |
void *context, enum rdma_ucm_port_space ps, |
| 1054 |
enum ib_qp_type qp_type, const char *caller) |
| 1055 |
{ |
| 1056 |
struct rdma_id_private *ret; |
| 1057 |
|
| 1058 |
ret = __rdma_create_id(net, event_handler, context, ps, qp_type, NULL); |
| 1059 |
if (IS_ERR(ret)) |
| 1060 |
return ERR_CAST(ret); |
| 1061 |
|
| 1062 |
rdma_restrack_set_name(&ret->res, caller); |
| 1063 |
return &ret->id; |
| 1064 |
} |
| 1065 |
EXPORT_SYMBOL(__rdma_create_kernel_id); |
| 1066 |
|
| 1067 |
struct rdma_cm_id *rdma_create_user_id(rdma_cm_event_handler event_handler, |
| 1068 |
void *context, |
| 1069 |
enum rdma_ucm_port_space ps, |
| 1070 |
enum ib_qp_type qp_type) |
| 1071 |
{ |
| 1072 |
struct rdma_id_private *ret; |
| 1073 |
|
| 1074 |
ret = __rdma_create_id(current->nsproxy->net_ns, event_handler, context, |
| 1075 |
ps, qp_type, NULL); |
| 1076 |
if (IS_ERR(ret)) |
| 1077 |
return ERR_CAST(ret); |
| 1078 |
|
| 1079 |
rdma_restrack_set_name(&ret->res, NULL); |
| 1080 |
return &ret->id; |
| 1081 |
} |
| 1082 |
EXPORT_SYMBOL(rdma_create_user_id); |
| 1083 |
|
| 1084 |
static int cma_init_ud_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) |
| 1085 |
{ |
| 1086 |
struct ib_qp_attr qp_attr; |
| 1087 |
int qp_attr_mask, ret; |
| 1088 |
|
| 1089 |
qp_attr.qp_state = IB_QPS_INIT; |
| 1090 |
ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 1091 |
if (ret) |
| 1092 |
return ret; |
| 1093 |
|
| 1094 |
ret = ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 1095 |
if (ret) |
| 1096 |
return ret; |
| 1097 |
|
| 1098 |
qp_attr.qp_state = IB_QPS_RTR; |
| 1099 |
ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE); |
| 1100 |
if (ret) |
| 1101 |
return ret; |
| 1102 |
|
| 1103 |
qp_attr.qp_state = IB_QPS_RTS; |
| 1104 |
qp_attr.sq_psn = 0; |
| 1105 |
ret = ib_modify_qp(qp, &qp_attr, IB_QP_STATE | IB_QP_SQ_PSN); |
| 1106 |
|
| 1107 |
return ret; |
| 1108 |
} |
| 1109 |
|
| 1110 |
static int cma_init_conn_qp(struct rdma_id_private *id_priv, struct ib_qp *qp) |
| 1111 |
{ |
| 1112 |
struct ib_qp_attr qp_attr; |
| 1113 |
int qp_attr_mask, ret; |
| 1114 |
|
| 1115 |
qp_attr.qp_state = IB_QPS_INIT; |
| 1116 |
ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 1117 |
if (ret) |
| 1118 |
return ret; |
| 1119 |
|
| 1120 |
return ib_modify_qp(qp, &qp_attr, qp_attr_mask); |
| 1121 |
} |
| 1122 |
|
| 1123 |
int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, |
| 1124 |
struct ib_qp_init_attr *qp_init_attr) |
| 1125 |
{ |
| 1126 |
struct rdma_id_private *id_priv; |
| 1127 |
struct ib_qp *qp; |
| 1128 |
int ret; |
| 1129 |
|
| 1130 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 1131 |
if (id->device != pd->device) { |
| 1132 |
ret = -EINVAL; |
| 1133 |
goto out_err; |
| 1134 |
} |
| 1135 |
|
| 1136 |
qp_init_attr->port_num = id->port_num; |
| 1137 |
qp = ib_create_qp(pd, qp_init_attr); |
| 1138 |
if (IS_ERR(qp)) { |
| 1139 |
ret = PTR_ERR(qp); |
| 1140 |
goto out_err; |
| 1141 |
} |
| 1142 |
|
| 1143 |
if (id->qp_type == IB_QPT_UD) |
| 1144 |
ret = cma_init_ud_qp(id_priv, qp); |
| 1145 |
else |
| 1146 |
ret = cma_init_conn_qp(id_priv, qp); |
| 1147 |
if (ret) |
| 1148 |
goto out_destroy; |
| 1149 |
|
| 1150 |
id->qp = qp; |
| 1151 |
id_priv->qp_num = qp->qp_num; |
| 1152 |
id_priv->srq = (qp->srq != NULL); |
| 1153 |
trace_cm_qp_create(id_priv, pd, qp_init_attr, 0); |
| 1154 |
return 0; |
| 1155 |
out_destroy: |
| 1156 |
ib_destroy_qp(qp); |
| 1157 |
out_err: |
| 1158 |
trace_cm_qp_create(id_priv, pd, qp_init_attr, ret); |
| 1159 |
return ret; |
| 1160 |
} |
| 1161 |
EXPORT_SYMBOL(rdma_create_qp); |
| 1162 |
|
| 1163 |
void rdma_destroy_qp(struct rdma_cm_id *id) |
| 1164 |
{ |
| 1165 |
struct rdma_id_private *id_priv; |
| 1166 |
|
| 1167 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 1168 |
trace_cm_qp_destroy(id_priv); |
| 1169 |
mutex_lock(&id_priv->qp_mutex); |
| 1170 |
ib_destroy_qp(id_priv->id.qp); |
| 1171 |
id_priv->id.qp = NULL; |
| 1172 |
mutex_unlock(&id_priv->qp_mutex); |
| 1173 |
} |
| 1174 |
EXPORT_SYMBOL(rdma_destroy_qp); |
| 1175 |
|
| 1176 |
static int cma_modify_qp_rtr(struct rdma_id_private *id_priv, |
| 1177 |
struct rdma_conn_param *conn_param) |
| 1178 |
{ |
| 1179 |
struct ib_qp_attr qp_attr; |
| 1180 |
int qp_attr_mask, ret; |
| 1181 |
|
| 1182 |
mutex_lock(&id_priv->qp_mutex); |
| 1183 |
if (!id_priv->id.qp) { |
| 1184 |
ret = 0; |
| 1185 |
goto out; |
| 1186 |
} |
| 1187 |
|
| 1188 |
/* Need to update QP attributes from default values. */ |
| 1189 |
qp_attr.qp_state = IB_QPS_INIT; |
| 1190 |
ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 1191 |
if (ret) |
| 1192 |
goto out; |
| 1193 |
|
| 1194 |
ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
| 1195 |
if (ret) |
| 1196 |
goto out; |
| 1197 |
|
| 1198 |
qp_attr.qp_state = IB_QPS_RTR; |
| 1199 |
ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 1200 |
if (ret) |
| 1201 |
goto out; |
| 1202 |
|
| 1203 |
BUG_ON(id_priv->cma_dev->device != id_priv->id.device); |
| 1204 |
|
| 1205 |
if (conn_param) |
| 1206 |
qp_attr.max_dest_rd_atomic = conn_param->responder_resources; |
| 1207 |
ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
| 1208 |
out: |
| 1209 |
mutex_unlock(&id_priv->qp_mutex); |
| 1210 |
return ret; |
| 1211 |
} |
| 1212 |
|
| 1213 |
static int cma_modify_qp_rts(struct rdma_id_private *id_priv, |
| 1214 |
struct rdma_conn_param *conn_param) |
| 1215 |
{ |
| 1216 |
struct ib_qp_attr qp_attr; |
| 1217 |
int qp_attr_mask, ret; |
| 1218 |
|
| 1219 |
mutex_lock(&id_priv->qp_mutex); |
| 1220 |
if (!id_priv->id.qp) { |
| 1221 |
ret = 0; |
| 1222 |
goto out; |
| 1223 |
} |
| 1224 |
|
| 1225 |
qp_attr.qp_state = IB_QPS_RTS; |
| 1226 |
ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); |
| 1227 |
if (ret) |
| 1228 |
goto out; |
| 1229 |
|
| 1230 |
if (conn_param) |
| 1231 |
qp_attr.max_rd_atomic = conn_param->initiator_depth; |
| 1232 |
ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); |
| 1233 |
out: |
| 1234 |
mutex_unlock(&id_priv->qp_mutex); |
| 1235 |
return ret; |
| 1236 |
} |
| 1237 |
|
| 1238 |
static int cma_modify_qp_err(struct rdma_id_private *id_priv) |
| 1239 |
{ |
| 1240 |
struct ib_qp_attr qp_attr; |
| 1241 |
int ret; |
| 1242 |
|
| 1243 |
mutex_lock(&id_priv->qp_mutex); |
| 1244 |
if (!id_priv->id.qp) { |
| 1245 |
ret = 0; |
| 1246 |
goto out; |
| 1247 |
} |
| 1248 |
|
| 1249 |
qp_attr.qp_state = IB_QPS_ERR; |
| 1250 |
ret = ib_modify_qp(id_priv->id.qp, &qp_attr, IB_QP_STATE); |
| 1251 |
out: |
| 1252 |
mutex_unlock(&id_priv->qp_mutex); |
| 1253 |
return ret; |
| 1254 |
} |
| 1255 |
|
| 1256 |
static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv, |
| 1257 |
struct ib_qp_attr *qp_attr, int *qp_attr_mask) |
| 1258 |
{ |
| 1259 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 1260 |
int ret; |
| 1261 |
u16 pkey; |
| 1262 |
|
| 1263 |
if (rdma_cap_eth_ah(id_priv->id.device, id_priv->id.port_num)) |
| 1264 |
pkey = 0xffff; |
| 1265 |
else |
| 1266 |
pkey = ib_addr_get_pkey(dev_addr); |
| 1267 |
|
| 1268 |
ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, |
| 1269 |
pkey, &qp_attr->pkey_index); |
| 1270 |
if (ret) |
| 1271 |
return ret; |
| 1272 |
|
| 1273 |
qp_attr->port_num = id_priv->id.port_num; |
| 1274 |
*qp_attr_mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 1275 |
|
| 1276 |
if (id_priv->id.qp_type == IB_QPT_UD) { |
| 1277 |
ret = cma_set_default_qkey(id_priv); |
| 1278 |
if (ret) |
| 1279 |
return ret; |
| 1280 |
|
| 1281 |
qp_attr->qkey = id_priv->qkey; |
| 1282 |
*qp_attr_mask |= IB_QP_QKEY; |
| 1283 |
} else { |
| 1284 |
qp_attr->qp_access_flags = 0; |
| 1285 |
*qp_attr_mask |= IB_QP_ACCESS_FLAGS; |
| 1286 |
} |
| 1287 |
return 0; |
| 1288 |
} |
| 1289 |
|
| 1290 |
int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, |
| 1291 |
int *qp_attr_mask) |
| 1292 |
{ |
| 1293 |
struct rdma_id_private *id_priv; |
| 1294 |
int ret = 0; |
| 1295 |
|
| 1296 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 1297 |
if (rdma_cap_ib_cm(id->device, id->port_num)) { |
| 1298 |
if (!id_priv->cm_id.ib || (id_priv->id.qp_type == IB_QPT_UD)) |
| 1299 |
ret = cma_ib_init_qp_attr(id_priv, qp_attr, qp_attr_mask); |
| 1300 |
else |
| 1301 |
ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, |
| 1302 |
qp_attr_mask); |
| 1303 |
|
| 1304 |
if (qp_attr->qp_state == IB_QPS_RTR) |
| 1305 |
qp_attr->rq_psn = id_priv->seq_num; |
| 1306 |
} else if (rdma_cap_iw_cm(id->device, id->port_num)) { |
| 1307 |
if (!id_priv->cm_id.iw) { |
| 1308 |
qp_attr->qp_access_flags = 0; |
| 1309 |
*qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS; |
| 1310 |
} else |
| 1311 |
ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, |
| 1312 |
qp_attr_mask); |
| 1313 |
qp_attr->port_num = id_priv->id.port_num; |
| 1314 |
*qp_attr_mask |= IB_QP_PORT; |
| 1315 |
} else { |
| 1316 |
ret = -ENOSYS; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if ((*qp_attr_mask & IB_QP_TIMEOUT) && id_priv->timeout_set) |
| 1320 |
qp_attr->timeout = id_priv->timeout; |
| 1321 |
|
| 1322 |
if ((*qp_attr_mask & IB_QP_MIN_RNR_TIMER) && id_priv->min_rnr_timer_set) |
| 1323 |
qp_attr->min_rnr_timer = id_priv->min_rnr_timer; |
| 1324 |
|
| 1325 |
return ret; |
| 1326 |
} |
| 1327 |
EXPORT_SYMBOL(rdma_init_qp_attr); |
| 1328 |
|
| 1329 |
static inline bool cma_zero_addr(const struct sockaddr *addr) |
| 1330 |
{ |
| 1331 |
switch (addr->sa_family) { |
| 1332 |
case AF_INET: |
| 1333 |
return ipv4_is_zeronet(((struct sockaddr_in *)addr)->sin_addr.s_addr); |
| 1334 |
case AF_INET6: |
| 1335 |
return ipv6_addr_any(&((struct sockaddr_in6 *)addr)->sin6_addr); |
| 1336 |
case AF_IB: |
| 1337 |
return ib_addr_any(&((struct sockaddr_ib *)addr)->sib_addr); |
| 1338 |
default: |
| 1339 |
return false; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
static inline bool cma_loopback_addr(const struct sockaddr *addr) |
| 1344 |
{ |
| 1345 |
switch (addr->sa_family) { |
| 1346 |
case AF_INET: |
| 1347 |
return ipv4_is_loopback( |
| 1348 |
((struct sockaddr_in *)addr)->sin_addr.s_addr); |
| 1349 |
case AF_INET6: |
| 1350 |
return ipv6_addr_loopback( |
| 1351 |
&((struct sockaddr_in6 *)addr)->sin6_addr); |
| 1352 |
case AF_IB: |
| 1353 |
return ib_addr_loopback( |
| 1354 |
&((struct sockaddr_ib *)addr)->sib_addr); |
| 1355 |
default: |
| 1356 |
return false; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
|
| 1360 |
static inline bool cma_any_addr(const struct sockaddr *addr) |
| 1361 |
{ |
| 1362 |
return cma_zero_addr(addr) || cma_loopback_addr(addr); |
| 1363 |
} |
| 1364 |
|
| 1365 |
static int cma_addr_cmp(const struct sockaddr *src, const struct sockaddr *dst) |
| 1366 |
{ |
| 1367 |
if (src->sa_family != dst->sa_family) |
| 1368 |
return -1; |
| 1369 |
|
| 1370 |
switch (src->sa_family) { |
| 1371 |
case AF_INET: |
| 1372 |
return ((struct sockaddr_in *)src)->sin_addr.s_addr != |
| 1373 |
((struct sockaddr_in *)dst)->sin_addr.s_addr; |
| 1374 |
case AF_INET6: { |
| 1375 |
struct sockaddr_in6 *src_addr6 = (struct sockaddr_in6 *)src; |
| 1376 |
struct sockaddr_in6 *dst_addr6 = (struct sockaddr_in6 *)dst; |
| 1377 |
bool link_local; |
| 1378 |
|
| 1379 |
if (ipv6_addr_cmp(&src_addr6->sin6_addr, |
| 1380 |
&dst_addr6->sin6_addr)) |
| 1381 |
return 1; |
| 1382 |
link_local = ipv6_addr_type(&dst_addr6->sin6_addr) & |
| 1383 |
IPV6_ADDR_LINKLOCAL; |
| 1384 |
/* Link local must match their scope_ids */ |
| 1385 |
return link_local ? (src_addr6->sin6_scope_id != |
| 1386 |
dst_addr6->sin6_scope_id) : |
| 1387 |
0; |
| 1388 |
} |
| 1389 |
|
| 1390 |
default: |
| 1391 |
return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, |
| 1392 |
&((struct sockaddr_ib *) dst)->sib_addr); |
| 1393 |
} |
| 1394 |
} |
| 1395 |
|
| 1396 |
static __be16 cma_port(const struct sockaddr *addr) |
| 1397 |
{ |
| 1398 |
struct sockaddr_ib *sib; |
| 1399 |
|
| 1400 |
switch (addr->sa_family) { |
| 1401 |
case AF_INET: |
| 1402 |
return ((struct sockaddr_in *) addr)->sin_port; |
| 1403 |
case AF_INET6: |
| 1404 |
return ((struct sockaddr_in6 *) addr)->sin6_port; |
| 1405 |
case AF_IB: |
| 1406 |
sib = (struct sockaddr_ib *) addr; |
| 1407 |
return htons((u16) (be64_to_cpu(sib->sib_sid) & |
| 1408 |
be64_to_cpu(sib->sib_sid_mask))); |
| 1409 |
default: |
| 1410 |
return 0; |
| 1411 |
} |
| 1412 |
} |
| 1413 |
|
| 1414 |
static inline int cma_any_port(const struct sockaddr *addr) |
| 1415 |
{ |
| 1416 |
return !cma_port(addr); |
| 1417 |
} |
| 1418 |
|
| 1419 |
static void cma_save_ib_info(struct sockaddr *src_addr, |
| 1420 |
struct sockaddr *dst_addr, |
| 1421 |
const struct rdma_cm_id *listen_id, |
| 1422 |
const struct sa_path_rec *path) |
| 1423 |
{ |
| 1424 |
struct sockaddr_ib *listen_ib, *ib; |
| 1425 |
|
| 1426 |
listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; |
| 1427 |
if (src_addr) { |
| 1428 |
ib = (struct sockaddr_ib *)src_addr; |
| 1429 |
ib->sib_family = AF_IB; |
| 1430 |
if (path) { |
| 1431 |
ib->sib_pkey = path->pkey; |
| 1432 |
ib->sib_flowinfo = path->flow_label; |
| 1433 |
memcpy(&ib->sib_addr, &path->sgid, 16); |
| 1434 |
ib->sib_sid = path->service_id; |
| 1435 |
ib->sib_scope_id = 0; |
| 1436 |
} else { |
| 1437 |
ib->sib_pkey = listen_ib->sib_pkey; |
| 1438 |
ib->sib_flowinfo = listen_ib->sib_flowinfo; |
| 1439 |
ib->sib_addr = listen_ib->sib_addr; |
| 1440 |
ib->sib_sid = listen_ib->sib_sid; |
| 1441 |
ib->sib_scope_id = listen_ib->sib_scope_id; |
| 1442 |
} |
| 1443 |
ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); |
| 1444 |
} |
| 1445 |
if (dst_addr) { |
| 1446 |
ib = (struct sockaddr_ib *)dst_addr; |
| 1447 |
ib->sib_family = AF_IB; |
| 1448 |
if (path) { |
| 1449 |
ib->sib_pkey = path->pkey; |
| 1450 |
ib->sib_flowinfo = path->flow_label; |
| 1451 |
memcpy(&ib->sib_addr, &path->dgid, 16); |
| 1452 |
} |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
static void cma_save_ip4_info(struct sockaddr_in *src_addr, |
| 1457 |
struct sockaddr_in *dst_addr, |
| 1458 |
struct cma_hdr *hdr, |
| 1459 |
__be16 local_port) |
| 1460 |
{ |
| 1461 |
if (src_addr) { |
| 1462 |
*src_addr = (struct sockaddr_in) { |
| 1463 |
.sin_family = AF_INET, |
| 1464 |
.sin_addr.s_addr = hdr->dst_addr.ip4.addr, |
| 1465 |
.sin_port = local_port, |
| 1466 |
}; |
| 1467 |
} |
| 1468 |
|
| 1469 |
if (dst_addr) { |
| 1470 |
*dst_addr = (struct sockaddr_in) { |
| 1471 |
.sin_family = AF_INET, |
| 1472 |
.sin_addr.s_addr = hdr->src_addr.ip4.addr, |
| 1473 |
.sin_port = hdr->port, |
| 1474 |
}; |
| 1475 |
} |
| 1476 |
} |
| 1477 |
|
| 1478 |
static void cma_save_ip6_info(struct sockaddr_in6 *src_addr, |
| 1479 |
struct sockaddr_in6 *dst_addr, |
| 1480 |
struct cma_hdr *hdr, |
| 1481 |
__be16 local_port) |
| 1482 |
{ |
| 1483 |
if (src_addr) { |
| 1484 |
*src_addr = (struct sockaddr_in6) { |
| 1485 |
.sin6_family = AF_INET6, |
| 1486 |
.sin6_addr = hdr->dst_addr.ip6, |
| 1487 |
.sin6_port = local_port, |
| 1488 |
}; |
| 1489 |
} |
| 1490 |
|
| 1491 |
if (dst_addr) { |
| 1492 |
*dst_addr = (struct sockaddr_in6) { |
| 1493 |
.sin6_family = AF_INET6, |
| 1494 |
.sin6_addr = hdr->src_addr.ip6, |
| 1495 |
.sin6_port = hdr->port, |
| 1496 |
}; |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
static u16 cma_port_from_service_id(__be64 service_id) |
| 1501 |
{ |
| 1502 |
return (u16)be64_to_cpu(service_id); |
| 1503 |
} |
| 1504 |
|
| 1505 |
static int cma_save_ip_info(struct sockaddr *src_addr, |
| 1506 |
struct sockaddr *dst_addr, |
| 1507 |
const struct ib_cm_event *ib_event, |
| 1508 |
__be64 service_id) |
| 1509 |
{ |
| 1510 |
struct cma_hdr *hdr; |
| 1511 |
__be16 port; |
| 1512 |
|
| 1513 |
hdr = ib_event->private_data; |
| 1514 |
if (hdr->cma_version != CMA_VERSION) |
| 1515 |
return -EINVAL; |
| 1516 |
|
| 1517 |
port = htons(cma_port_from_service_id(service_id)); |
| 1518 |
|
| 1519 |
switch (cma_get_ip_ver(hdr)) { |
| 1520 |
case 4: |
| 1521 |
cma_save_ip4_info((struct sockaddr_in *)src_addr, |
| 1522 |
(struct sockaddr_in *)dst_addr, hdr, port); |
| 1523 |
break; |
| 1524 |
case 6: |
| 1525 |
cma_save_ip6_info((struct sockaddr_in6 *)src_addr, |
| 1526 |
(struct sockaddr_in6 *)dst_addr, hdr, port); |
| 1527 |
break; |
| 1528 |
default: |
| 1529 |
return -EAFNOSUPPORT; |
| 1530 |
} |
| 1531 |
|
| 1532 |
return 0; |
| 1533 |
} |
| 1534 |
|
| 1535 |
static int cma_save_net_info(struct sockaddr *src_addr, |
| 1536 |
struct sockaddr *dst_addr, |
| 1537 |
const struct rdma_cm_id *listen_id, |
| 1538 |
const struct ib_cm_event *ib_event, |
| 1539 |
sa_family_t sa_family, __be64 service_id) |
| 1540 |
{ |
| 1541 |
if (sa_family == AF_IB) { |
| 1542 |
if (ib_event->event == IB_CM_REQ_RECEIVED) |
| 1543 |
cma_save_ib_info(src_addr, dst_addr, listen_id, |
| 1544 |
ib_event->param.req_rcvd.primary_path); |
| 1545 |
else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) |
| 1546 |
cma_save_ib_info(src_addr, dst_addr, listen_id, NULL); |
| 1547 |
return 0; |
| 1548 |
} |
| 1549 |
|
| 1550 |
return cma_save_ip_info(src_addr, dst_addr, ib_event, service_id); |
| 1551 |
} |
| 1552 |
|
| 1553 |
static int cma_save_req_info(const struct ib_cm_event *ib_event, |
| 1554 |
struct cma_req_info *req) |
| 1555 |
{ |
| 1556 |
const struct ib_cm_req_event_param *req_param = |
| 1557 |
&ib_event->param.req_rcvd; |
| 1558 |
const struct ib_cm_sidr_req_event_param *sidr_param = |
| 1559 |
&ib_event->param.sidr_req_rcvd; |
| 1560 |
|
| 1561 |
switch (ib_event->event) { |
| 1562 |
case IB_CM_REQ_RECEIVED: |
| 1563 |
req->device = req_param->listen_id->device; |
| 1564 |
req->port = req_param->port; |
| 1565 |
memcpy(&req->local_gid, &req_param->primary_path->sgid, |
| 1566 |
sizeof(req->local_gid)); |
| 1567 |
req->has_gid = true; |
| 1568 |
req->service_id = req_param->primary_path->service_id; |
| 1569 |
req->pkey = be16_to_cpu(req_param->primary_path->pkey); |
| 1570 |
if (req->pkey != req_param->bth_pkey) |
| 1571 |
pr_warn_ratelimited("RDMA CMA: got different BTH P_Key (0x%x) and primary path P_Key (0x%x)\n" |
| 1572 |
"RDMA CMA: in the future this may cause the request to be dropped\n", |
| 1573 |
req_param->bth_pkey, req->pkey); |
| 1574 |
break; |
| 1575 |
case IB_CM_SIDR_REQ_RECEIVED: |
| 1576 |
req->device = sidr_param->listen_id->device; |
| 1577 |
req->port = sidr_param->port; |
| 1578 |
req->has_gid = false; |
| 1579 |
req->service_id = sidr_param->service_id; |
| 1580 |
req->pkey = sidr_param->pkey; |
| 1581 |
if (req->pkey != sidr_param->bth_pkey) |
| 1582 |
pr_warn_ratelimited("RDMA CMA: got different BTH P_Key (0x%x) and SIDR request payload P_Key (0x%x)\n" |
| 1583 |
"RDMA CMA: in the future this may cause the request to be dropped\n", |
| 1584 |
sidr_param->bth_pkey, req->pkey); |
| 1585 |
break; |
| 1586 |
default: |
| 1587 |
return -EINVAL; |
| 1588 |
} |
| 1589 |
|
| 1590 |
return 0; |
| 1591 |
} |
| 1592 |
|
| 1593 |
static bool validate_ipv4_net_dev(struct net_device *net_dev, |
| 1594 |
const struct sockaddr_in *dst_addr, |
| 1595 |
const struct sockaddr_in *src_addr) |
| 1596 |
{ |
| 1597 |
__be32 daddr = dst_addr->sin_addr.s_addr, |
| 1598 |
saddr = src_addr->sin_addr.s_addr; |
| 1599 |
struct fib_result res; |
| 1600 |
struct flowi4 fl4; |
| 1601 |
int err; |
| 1602 |
bool ret; |
| 1603 |
|
| 1604 |
if (ipv4_is_multicast(saddr) || ipv4_is_lbcast(saddr) || |
| 1605 |
ipv4_is_lbcast(daddr) || ipv4_is_zeronet(saddr) || |
| 1606 |
ipv4_is_zeronet(daddr) || ipv4_is_loopback(daddr) || |
| 1607 |
ipv4_is_loopback(saddr)) |
| 1608 |
return false; |
| 1609 |
|
| 1610 |
memset(&fl4, 0, sizeof(fl4)); |
| 1611 |
fl4.flowi4_oif = net_dev->ifindex; |
| 1612 |
fl4.daddr = daddr; |
| 1613 |
fl4.saddr = saddr; |
| 1614 |
|
| 1615 |
rcu_read_lock(); |
| 1616 |
err = fib_lookup(dev_net(net_dev), &fl4, &res, 0); |
| 1617 |
ret = err == 0 && FIB_RES_DEV(res) == net_dev; |
| 1618 |
rcu_read_unlock(); |
| 1619 |
|
| 1620 |
return ret; |
| 1621 |
} |
| 1622 |
|
| 1623 |
static bool validate_ipv6_net_dev(struct net_device *net_dev, |
| 1624 |
const struct sockaddr_in6 *dst_addr, |
| 1625 |
const struct sockaddr_in6 *src_addr) |
| 1626 |
{ |
| 1627 |
#if IS_ENABLED(CONFIG_IPV6) |
| 1628 |
const int strict = ipv6_addr_type(&dst_addr->sin6_addr) & |
| 1629 |
IPV6_ADDR_LINKLOCAL; |
| 1630 |
struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr, |
| 1631 |
&src_addr->sin6_addr, net_dev->ifindex, |
| 1632 |
NULL, strict); |
| 1633 |
bool ret; |
| 1634 |
|
| 1635 |
if (!rt) |
| 1636 |
return false; |
| 1637 |
|
| 1638 |
ret = rt->rt6i_idev->dev == net_dev; |
| 1639 |
ip6_rt_put(rt); |
| 1640 |
|
| 1641 |
return ret; |
| 1642 |
#else |
| 1643 |
return false; |
| 1644 |
#endif |
| 1645 |
} |
| 1646 |
|
| 1647 |
static bool validate_net_dev(struct net_device *net_dev, |
| 1648 |
const struct sockaddr *daddr, |
| 1649 |
const struct sockaddr *saddr) |
| 1650 |
{ |
| 1651 |
const struct sockaddr_in *daddr4 = (const struct sockaddr_in *)daddr; |
| 1652 |
const struct sockaddr_in *saddr4 = (const struct sockaddr_in *)saddr; |
| 1653 |
const struct sockaddr_in6 *daddr6 = (const struct sockaddr_in6 *)daddr; |
| 1654 |
const struct sockaddr_in6 *saddr6 = (const struct sockaddr_in6 *)saddr; |
| 1655 |
|
| 1656 |
switch (daddr->sa_family) { |
| 1657 |
case AF_INET: |
| 1658 |
return saddr->sa_family == AF_INET && |
| 1659 |
validate_ipv4_net_dev(net_dev, daddr4, saddr4); |
| 1660 |
|
| 1661 |
case AF_INET6: |
| 1662 |
return saddr->sa_family == AF_INET6 && |
| 1663 |
validate_ipv6_net_dev(net_dev, daddr6, saddr6); |
| 1664 |
|
| 1665 |
default: |
| 1666 |
return false; |
| 1667 |
} |
| 1668 |
} |
| 1669 |
|
| 1670 |
static struct net_device * |
| 1671 |
roce_get_net_dev_by_cm_event(const struct ib_cm_event *ib_event) |
| 1672 |
{ |
| 1673 |
const struct ib_gid_attr *sgid_attr = NULL; |
| 1674 |
struct net_device *ndev; |
| 1675 |
|
| 1676 |
if (ib_event->event == IB_CM_REQ_RECEIVED) |
| 1677 |
sgid_attr = ib_event->param.req_rcvd.ppath_sgid_attr; |
| 1678 |
else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) |
| 1679 |
sgid_attr = ib_event->param.sidr_req_rcvd.sgid_attr; |
| 1680 |
|
| 1681 |
if (!sgid_attr) |
| 1682 |
return NULL; |
| 1683 |
|
| 1684 |
rcu_read_lock(); |
| 1685 |
ndev = rdma_read_gid_attr_ndev_rcu(sgid_attr); |
| 1686 |
if (IS_ERR(ndev)) |
| 1687 |
ndev = NULL; |
| 1688 |
else |
| 1689 |
dev_hold(ndev); |
| 1690 |
rcu_read_unlock(); |
| 1691 |
return ndev; |
| 1692 |
} |
| 1693 |
|
| 1694 |
static struct net_device *cma_get_net_dev(const struct ib_cm_event *ib_event, |
| 1695 |
struct cma_req_info *req) |
| 1696 |
{ |
| 1697 |
struct sockaddr *listen_addr = |
| 1698 |
(struct sockaddr *)&req->listen_addr_storage; |
| 1699 |
struct sockaddr *src_addr = (struct sockaddr *)&req->src_addr_storage; |
| 1700 |
struct net_device *net_dev; |
| 1701 |
const union ib_gid *gid = req->has_gid ? &req->local_gid : NULL; |
| 1702 |
int err; |
| 1703 |
|
| 1704 |
err = cma_save_ip_info(listen_addr, src_addr, ib_event, |
| 1705 |
req->service_id); |
| 1706 |
if (err) |
| 1707 |
return ERR_PTR(err); |
| 1708 |
|
| 1709 |
if (rdma_protocol_roce(req->device, req->port)) |
| 1710 |
net_dev = roce_get_net_dev_by_cm_event(ib_event); |
| 1711 |
else |
| 1712 |
net_dev = ib_get_net_dev_by_params(req->device, req->port, |
| 1713 |
req->pkey, |
| 1714 |
gid, listen_addr); |
| 1715 |
if (!net_dev) |
| 1716 |
return ERR_PTR(-ENODEV); |
| 1717 |
|
| 1718 |
return net_dev; |
| 1719 |
} |
| 1720 |
|
| 1721 |
static enum rdma_ucm_port_space rdma_ps_from_service_id(__be64 service_id) |
| 1722 |
{ |
| 1723 |
return (be64_to_cpu(service_id) >> 16) & 0xffff; |
| 1724 |
} |
| 1725 |
|
| 1726 |
static bool cma_match_private_data(struct rdma_id_private *id_priv, |
| 1727 |
const struct cma_hdr *hdr) |
| 1728 |
{ |
| 1729 |
struct sockaddr *addr = cma_src_addr(id_priv); |
| 1730 |
__be32 ip4_addr; |
| 1731 |
struct in6_addr ip6_addr; |
| 1732 |
|
| 1733 |
if (cma_any_addr(addr) && !id_priv->afonly) |
| 1734 |
return true; |
| 1735 |
|
| 1736 |
switch (addr->sa_family) { |
| 1737 |
case AF_INET: |
| 1738 |
ip4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; |
| 1739 |
if (cma_get_ip_ver(hdr) != 4) |
| 1740 |
return false; |
| 1741 |
if (!cma_any_addr(addr) && |
| 1742 |
hdr->dst_addr.ip4.addr != ip4_addr) |
| 1743 |
return false; |
| 1744 |
break; |
| 1745 |
case AF_INET6: |
| 1746 |
ip6_addr = ((struct sockaddr_in6 *)addr)->sin6_addr; |
| 1747 |
if (cma_get_ip_ver(hdr) != 6) |
| 1748 |
return false; |
| 1749 |
if (!cma_any_addr(addr) && |
| 1750 |
memcmp(&hdr->dst_addr.ip6, &ip6_addr, sizeof(ip6_addr))) |
| 1751 |
return false; |
| 1752 |
break; |
| 1753 |
case AF_IB: |
| 1754 |
return true; |
| 1755 |
default: |
| 1756 |
return false; |
| 1757 |
} |
| 1758 |
|
| 1759 |
return true; |
| 1760 |
} |
| 1761 |
|
| 1762 |
static bool cma_protocol_roce(const struct rdma_cm_id *id) |
| 1763 |
{ |
| 1764 |
struct ib_device *device = id->device; |
| 1765 |
const u32 port_num = id->port_num ?: rdma_start_port(device); |
| 1766 |
|
| 1767 |
return rdma_protocol_roce(device, port_num); |
| 1768 |
} |
| 1769 |
|
| 1770 |
static bool cma_is_req_ipv6_ll(const struct cma_req_info *req) |
| 1771 |
{ |
| 1772 |
const struct sockaddr *daddr = |
| 1773 |
(const struct sockaddr *)&req->listen_addr_storage; |
| 1774 |
const struct sockaddr_in6 *daddr6 = (const struct sockaddr_in6 *)daddr; |
| 1775 |
|
| 1776 |
/* Returns true if the req is for IPv6 link local */ |
| 1777 |
return (daddr->sa_family == AF_INET6 && |
| 1778 |
(ipv6_addr_type(&daddr6->sin6_addr) & IPV6_ADDR_LINKLOCAL)); |
| 1779 |
} |
| 1780 |
|
| 1781 |
static bool cma_match_net_dev(const struct rdma_cm_id *id, |
| 1782 |
const struct net_device *net_dev, |
| 1783 |
const struct cma_req_info *req) |
| 1784 |
{ |
| 1785 |
const struct rdma_addr *addr = &id->route.addr; |
| 1786 |
|
| 1787 |
if (!net_dev) |
| 1788 |
/* This request is an AF_IB request */ |
| 1789 |
return (!id->port_num || id->port_num == req->port) && |
| 1790 |
(addr->src_addr.ss_family == AF_IB); |
| 1791 |
|
| 1792 |
/* |
| 1793 |
* If the request is not for IPv6 link local, allow matching |
| 1794 |
* request to any netdevice of the one or multiport rdma device. |
| 1795 |
*/ |
| 1796 |
if (!cma_is_req_ipv6_ll(req)) |
| 1797 |
return true; |
| 1798 |
/* |
| 1799 |
* Net namespaces must match, and if the listner is listening |
| 1800 |
* on a specific netdevice than netdevice must match as well. |
| 1801 |
*/ |
| 1802 |
if (net_eq(dev_net(net_dev), addr->dev_addr.net) && |
| 1803 |
(!!addr->dev_addr.bound_dev_if == |
| 1804 |
(addr->dev_addr.bound_dev_if == net_dev->ifindex))) |
| 1805 |
return true; |
| 1806 |
else |
| 1807 |
return false; |
| 1808 |
} |
| 1809 |
|
| 1810 |
static struct rdma_id_private *cma_find_listener( |
| 1811 |
const struct rdma_bind_list *bind_list, |
| 1812 |
const struct ib_cm_id *cm_id, |
| 1813 |
const struct ib_cm_event *ib_event, |
| 1814 |
const struct cma_req_info *req, |
| 1815 |
const struct net_device *net_dev) |
| 1816 |
{ |
| 1817 |
struct rdma_id_private *id_priv, *id_priv_dev; |
| 1818 |
|
| 1819 |
lockdep_assert_held(&lock); |
| 1820 |
|
| 1821 |
if (!bind_list) |
| 1822 |
return ERR_PTR(-EINVAL); |
| 1823 |
|
| 1824 |
hlist_for_each_entry(id_priv, &bind_list->owners, node) { |
| 1825 |
if (cma_match_private_data(id_priv, ib_event->private_data)) { |
| 1826 |
if (id_priv->id.device == cm_id->device && |
| 1827 |
cma_match_net_dev(&id_priv->id, net_dev, req)) |
| 1828 |
return id_priv; |
| 1829 |
list_for_each_entry(id_priv_dev, |
| 1830 |
&id_priv->listen_list, |
| 1831 |
listen_item) { |
| 1832 |
if (id_priv_dev->id.device == cm_id->device && |
| 1833 |
cma_match_net_dev(&id_priv_dev->id, |
| 1834 |
net_dev, req)) |
| 1835 |
return id_priv_dev; |
| 1836 |
} |
| 1837 |
} |
| 1838 |
} |
| 1839 |
|
| 1840 |
return ERR_PTR(-EINVAL); |
| 1841 |
} |
| 1842 |
|
| 1843 |
static struct rdma_id_private * |
| 1844 |
cma_ib_id_from_event(struct ib_cm_id *cm_id, |
| 1845 |
const struct ib_cm_event *ib_event, |
| 1846 |
struct cma_req_info *req, |
| 1847 |
struct net_device **net_dev) |
| 1848 |
{ |
| 1849 |
struct rdma_bind_list *bind_list; |
| 1850 |
struct rdma_id_private *id_priv; |
| 1851 |
int err; |
| 1852 |
|
| 1853 |
err = cma_save_req_info(ib_event, req); |
| 1854 |
if (err) |
| 1855 |
return ERR_PTR(err); |
| 1856 |
|
| 1857 |
*net_dev = cma_get_net_dev(ib_event, req); |
| 1858 |
if (IS_ERR(*net_dev)) { |
| 1859 |
if (PTR_ERR(*net_dev) == -EAFNOSUPPORT) { |
| 1860 |
/* Assuming the protocol is AF_IB */ |
| 1861 |
*net_dev = NULL; |
| 1862 |
} else { |
| 1863 |
return ERR_CAST(*net_dev); |
| 1864 |
} |
| 1865 |
} |
| 1866 |
|
| 1867 |
mutex_lock(&lock); |
| 1868 |
/* |
| 1869 |
* Net namespace might be getting deleted while route lookup, |
| 1870 |
* cm_id lookup is in progress. Therefore, perform netdevice |
| 1871 |
* validation, cm_id lookup under rcu lock. |
| 1872 |
* RCU lock along with netdevice state check, synchronizes with |
| 1873 |
* netdevice migrating to different net namespace and also avoids |
| 1874 |
* case where net namespace doesn't get deleted while lookup is in |
| 1875 |
* progress. |
| 1876 |
* If the device state is not IFF_UP, its properties such as ifindex |
| 1877 |
* and nd_net cannot be trusted to remain valid without rcu lock. |
| 1878 |
* net/core/dev.c change_net_namespace() ensures to synchronize with |
| 1879 |
* ongoing operations on net device after device is closed using |
| 1880 |
* synchronize_net(). |
| 1881 |
*/ |
| 1882 |
rcu_read_lock(); |
| 1883 |
if (*net_dev) { |
| 1884 |
/* |
| 1885 |
* If netdevice is down, it is likely that it is administratively |
| 1886 |
* down or it might be migrating to different namespace. |
| 1887 |
* In that case avoid further processing, as the net namespace |
| 1888 |
* or ifindex may change. |
| 1889 |
*/ |
| 1890 |
if (((*net_dev)->flags & IFF_UP) == 0) { |
| 1891 |
id_priv = ERR_PTR(-EHOSTUNREACH); |
| 1892 |
goto err; |
| 1893 |
} |
| 1894 |
|
| 1895 |
if (!validate_net_dev(*net_dev, |
| 1896 |
(struct sockaddr *)&req->src_addr_storage, |
| 1897 |
(struct sockaddr *)&req->listen_addr_storage)) { |
| 1898 |
id_priv = ERR_PTR(-EHOSTUNREACH); |
| 1899 |
goto err; |
| 1900 |
} |
| 1901 |
} |
| 1902 |
|
| 1903 |
bind_list = cma_ps_find(*net_dev ? dev_net(*net_dev) : &init_net, |
| 1904 |
rdma_ps_from_service_id(req->service_id), |
| 1905 |
cma_port_from_service_id(req->service_id)); |
| 1906 |
id_priv = cma_find_listener(bind_list, cm_id, ib_event, req, *net_dev); |
| 1907 |
err: |
| 1908 |
rcu_read_unlock(); |
| 1909 |
mutex_unlock(&lock); |
| 1910 |
if (IS_ERR(id_priv) && *net_dev) { |
| 1911 |
dev_put(*net_dev); |
| 1912 |
*net_dev = NULL; |
| 1913 |
} |
| 1914 |
return id_priv; |
| 1915 |
} |
| 1916 |
|
| 1917 |
static inline u8 cma_user_data_offset(struct rdma_id_private *id_priv) |
| 1918 |
{ |
| 1919 |
return cma_family(id_priv) == AF_IB ? 0 : sizeof(struct cma_hdr); |
| 1920 |
} |
| 1921 |
|
| 1922 |
static void cma_cancel_route(struct rdma_id_private *id_priv) |
| 1923 |
{ |
| 1924 |
if (rdma_cap_ib_sa(id_priv->id.device, id_priv->id.port_num)) { |
| 1925 |
if (id_priv->query) |
| 1926 |
ib_sa_cancel_query(id_priv->query_id, id_priv->query); |
| 1927 |
} |
| 1928 |
} |
| 1929 |
|
| 1930 |
static void _cma_cancel_listens(struct rdma_id_private *id_priv) |
| 1931 |
{ |
| 1932 |
struct rdma_id_private *dev_id_priv; |
| 1933 |
|
| 1934 |
lockdep_assert_held(&lock); |
| 1935 |
|
| 1936 |
/* |
| 1937 |
* Remove from listen_any_list to prevent added devices from spawning |
| 1938 |
* additional listen requests. |
| 1939 |
*/ |
| 1940 |
list_del_init(&id_priv->listen_any_item); |
| 1941 |
|
| 1942 |
while (!list_empty(&id_priv->listen_list)) { |
| 1943 |
dev_id_priv = |
| 1944 |
list_first_entry(&id_priv->listen_list, |
| 1945 |
struct rdma_id_private, listen_item); |
| 1946 |
/* sync with device removal to avoid duplicate destruction */ |
| 1947 |
list_del_init(&dev_id_priv->device_item); |
| 1948 |
list_del_init(&dev_id_priv->listen_item); |
| 1949 |
mutex_unlock(&lock); |
| 1950 |
|
| 1951 |
rdma_destroy_id(&dev_id_priv->id); |
| 1952 |
mutex_lock(&lock); |
| 1953 |
} |
| 1954 |
} |
| 1955 |
|
| 1956 |
static void cma_cancel_listens(struct rdma_id_private *id_priv) |
| 1957 |
{ |
| 1958 |
mutex_lock(&lock); |
| 1959 |
_cma_cancel_listens(id_priv); |
| 1960 |
mutex_unlock(&lock); |
| 1961 |
} |
| 1962 |
|
| 1963 |
static void cma_cancel_operation(struct rdma_id_private *id_priv, |
| 1964 |
enum rdma_cm_state state) |
| 1965 |
{ |
| 1966 |
switch (state) { |
| 1967 |
case RDMA_CM_ADDR_QUERY: |
| 1968 |
/* |
| 1969 |
* We can avoid doing the rdma_addr_cancel() based on state, |
| 1970 |
* only RDMA_CM_ADDR_QUERY has a work that could still execute. |
| 1971 |
* Notice that the addr_handler work could still be exiting |
| 1972 |
* outside this state, however due to the interaction with the |
| 1973 |
* handler_mutex the work is guaranteed not to touch id_priv |
| 1974 |
* during exit. |
| 1975 |
*/ |
| 1976 |
rdma_addr_cancel(&id_priv->id.route.addr.dev_addr); |
| 1977 |
break; |
| 1978 |
case RDMA_CM_ROUTE_QUERY: |
| 1979 |
cma_cancel_route(id_priv); |
| 1980 |
break; |
| 1981 |
case RDMA_CM_LISTEN: |
| 1982 |
if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev) |
| 1983 |
cma_cancel_listens(id_priv); |
| 1984 |
break; |
| 1985 |
default: |
| 1986 |
break; |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
static void cma_release_port(struct rdma_id_private *id_priv) |
| 1991 |
{ |
| 1992 |
struct rdma_bind_list *bind_list = id_priv->bind_list; |
| 1993 |
struct net *net = id_priv->id.route.addr.dev_addr.net; |
| 1994 |
|
| 1995 |
if (!bind_list) |
| 1996 |
return; |
| 1997 |
|
| 1998 |
mutex_lock(&lock); |
| 1999 |
hlist_del(&id_priv->node); |
| 2000 |
if (hlist_empty(&bind_list->owners)) { |
| 2001 |
cma_ps_remove(net, bind_list->ps, bind_list->port); |
| 2002 |
kfree(bind_list); |
| 2003 |
} |
| 2004 |
mutex_unlock(&lock); |
| 2005 |
} |
| 2006 |
|
| 2007 |
static void destroy_mc(struct rdma_id_private *id_priv, |
| 2008 |
struct cma_multicast *mc) |
| 2009 |
{ |
| 2010 |
bool send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); |
| 2011 |
|
| 2012 |
if (rdma_cap_ib_mcast(id_priv->id.device, id_priv->id.port_num)) |
| 2013 |
ib_sa_free_multicast(mc->sa_mc); |
| 2014 |
|
| 2015 |
if (rdma_protocol_roce(id_priv->id.device, id_priv->id.port_num)) { |
| 2016 |
struct rdma_cm_event *event = &mc->iboe_join.event; |
| 2017 |
struct rdma_dev_addr *dev_addr = |
| 2018 |
&id_priv->id.route.addr.dev_addr; |
| 2019 |
struct net_device *ndev = NULL; |
| 2020 |
|
| 2021 |
if (dev_addr->bound_dev_if) |
| 2022 |
ndev = dev_get_by_index(dev_addr->net, |
| 2023 |
dev_addr->bound_dev_if); |
| 2024 |
if (ndev && !send_only) { |
| 2025 |
enum ib_gid_type gid_type; |
| 2026 |
union ib_gid mgid; |
| 2027 |
|
| 2028 |
gid_type = id_priv->cma_dev->default_gid_type |
| 2029 |
[id_priv->id.port_num - |
| 2030 |
rdma_start_port( |
| 2031 |
id_priv->cma_dev->device)]; |
| 2032 |
cma_iboe_set_mgid((struct sockaddr *)&mc->addr, &mgid, |
| 2033 |
gid_type); |
| 2034 |
cma_igmp_send(ndev, &mgid, false); |
| 2035 |
} |
| 2036 |
dev_put(ndev); |
| 2037 |
|
| 2038 |
cancel_work_sync(&mc->iboe_join.work); |
| 2039 |
if (event->event == RDMA_CM_EVENT_MULTICAST_JOIN) |
| 2040 |
rdma_destroy_ah_attr(&event->param.ud.ah_attr); |
| 2041 |
} |
| 2042 |
kfree(mc); |
| 2043 |
} |
| 2044 |
|
| 2045 |
static void cma_leave_mc_groups(struct rdma_id_private *id_priv) |
| 2046 |
{ |
| 2047 |
struct cma_multicast *mc; |
| 2048 |
|
| 2049 |
while (!list_empty(&id_priv->mc_list)) { |
| 2050 |
mc = list_first_entry(&id_priv->mc_list, struct cma_multicast, |
| 2051 |
list); |
| 2052 |
list_del(&mc->list); |
| 2053 |
destroy_mc(id_priv, mc); |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
static void _destroy_id(struct rdma_id_private *id_priv, |
| 2058 |
enum rdma_cm_state state) |
| 2059 |
{ |
| 2060 |
cma_cancel_operation(id_priv, state); |
| 2061 |
|
| 2062 |
rdma_restrack_del(&id_priv->res); |
| 2063 |
cma_remove_id_from_tree(id_priv); |
| 2064 |
if (id_priv->cma_dev) { |
| 2065 |
if (rdma_cap_ib_cm(id_priv->id.device, 1)) { |
| 2066 |
if (id_priv->cm_id.ib) |
| 2067 |
ib_destroy_cm_id(id_priv->cm_id.ib); |
| 2068 |
} else if (rdma_cap_iw_cm(id_priv->id.device, 1)) { |
| 2069 |
if (id_priv->cm_id.iw) |
| 2070 |
iw_destroy_cm_id(id_priv->cm_id.iw); |
| 2071 |
} |
| 2072 |
cma_leave_mc_groups(id_priv); |
| 2073 |
cma_release_dev(id_priv); |
| 2074 |
} |
| 2075 |
|
| 2076 |
cma_release_port(id_priv); |
| 2077 |
cma_id_put(id_priv); |
| 2078 |
wait_for_completion(&id_priv->comp); |
| 2079 |
|
| 2080 |
if (id_priv->internal_id) |
| 2081 |
cma_id_put(id_priv->id.context); |
| 2082 |
|
| 2083 |
kfree(id_priv->id.route.path_rec); |
| 2084 |
kfree(id_priv->id.route.path_rec_inbound); |
| 2085 |
kfree(id_priv->id.route.path_rec_outbound); |
| 2086 |
kfree(id_priv->id.route.service_recs); |
| 2087 |
|
| 2088 |
put_net(id_priv->id.route.addr.dev_addr.net); |
| 2089 |
kfree(id_priv); |
| 2090 |
} |
| 2091 |
|
| 2092 |
/* |
| 2093 |
* destroy an ID from within the handler_mutex. This ensures that no other |
| 2094 |
* handlers can start running concurrently. |
| 2095 |
*/ |
| 2096 |
static void destroy_id_handler_unlock(struct rdma_id_private *id_priv) |
| 2097 |
__releases(&idprv->handler_mutex) |
| 2098 |
{ |
| 2099 |
enum rdma_cm_state state; |
| 2100 |
unsigned long flags; |
| 2101 |
|
| 2102 |
trace_cm_id_destroy(id_priv); |
| 2103 |
|
| 2104 |
/* |
| 2105 |
* Setting the state to destroyed under the handler mutex provides a |
| 2106 |
* fence against calling handler callbacks. If this is invoked due to |
| 2107 |
* the failure of a handler callback then it guarentees that no future |
| 2108 |
* handlers will be called. |
| 2109 |
*/ |
| 2110 |
lockdep_assert_held(&id_priv->handler_mutex); |
| 2111 |
spin_lock_irqsave(&id_priv->lock, flags); |
| 2112 |
state = id_priv->state; |
| 2113 |
id_priv->state = RDMA_CM_DESTROYING; |
| 2114 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 2115 |
mutex_unlock(&id_priv->handler_mutex); |
| 2116 |
_destroy_id(id_priv, state); |
| 2117 |
} |
| 2118 |
|
| 2119 |
void rdma_destroy_id(struct rdma_cm_id *id) |
| 2120 |
{ |
| 2121 |
struct rdma_id_private *id_priv = |
| 2122 |
container_of(id, struct rdma_id_private, id); |
| 2123 |
|
| 2124 |
mutex_lock(&id_priv->handler_mutex); |
| 2125 |
destroy_id_handler_unlock(id_priv); |
| 2126 |
} |
| 2127 |
EXPORT_SYMBOL(rdma_destroy_id); |
| 2128 |
|
| 2129 |
static int cma_rep_recv(struct rdma_id_private *id_priv) |
| 2130 |
{ |
| 2131 |
int ret; |
| 2132 |
|
| 2133 |
ret = cma_modify_qp_rtr(id_priv, NULL); |
| 2134 |
if (ret) |
| 2135 |
goto reject; |
| 2136 |
|
| 2137 |
ret = cma_modify_qp_rts(id_priv, NULL); |
| 2138 |
if (ret) |
| 2139 |
goto reject; |
| 2140 |
|
| 2141 |
trace_cm_send_rtu(id_priv); |
| 2142 |
ret = ib_send_cm_rtu(id_priv->cm_id.ib, NULL, 0); |
| 2143 |
if (ret) |
| 2144 |
goto reject; |
| 2145 |
|
| 2146 |
return 0; |
| 2147 |
reject: |
| 2148 |
pr_debug_ratelimited("RDMA CM: CONNECT_ERROR: failed to handle reply. status %d\n", ret); |
| 2149 |
cma_modify_qp_err(id_priv); |
| 2150 |
trace_cm_send_rej(id_priv); |
| 2151 |
ib_send_cm_rej(id_priv->cm_id.ib, IB_CM_REJ_CONSUMER_DEFINED, |
| 2152 |
NULL, 0, NULL, 0); |
| 2153 |
return ret; |
| 2154 |
} |
| 2155 |
|
| 2156 |
static void cma_set_rep_event_data(struct rdma_cm_event *event, |
| 2157 |
const struct ib_cm_rep_event_param *rep_data, |
| 2158 |
void *private_data) |
| 2159 |
{ |
| 2160 |
event->param.conn.private_data = private_data; |
| 2161 |
event->param.conn.private_data_len = IB_CM_REP_PRIVATE_DATA_SIZE; |
| 2162 |
event->param.conn.responder_resources = rep_data->responder_resources; |
| 2163 |
event->param.conn.initiator_depth = rep_data->initiator_depth; |
| 2164 |
event->param.conn.flow_control = rep_data->flow_control; |
| 2165 |
event->param.conn.rnr_retry_count = rep_data->rnr_retry_count; |
| 2166 |
event->param.conn.srq = rep_data->srq; |
| 2167 |
event->param.conn.qp_num = rep_data->remote_qpn; |
| 2168 |
|
| 2169 |
event->ece.vendor_id = rep_data->ece.vendor_id; |
| 2170 |
event->ece.attr_mod = rep_data->ece.attr_mod; |
| 2171 |
} |
| 2172 |
|
| 2173 |
static int cma_cm_event_handler(struct rdma_id_private *id_priv, |
| 2174 |
struct rdma_cm_event *event) |
| 2175 |
{ |
| 2176 |
int ret; |
| 2177 |
|
| 2178 |
lockdep_assert_held(&id_priv->handler_mutex); |
| 2179 |
|
| 2180 |
trace_cm_event_handler(id_priv, event); |
| 2181 |
ret = id_priv->id.event_handler(&id_priv->id, event); |
| 2182 |
trace_cm_event_done(id_priv, event, ret); |
| 2183 |
return ret; |
| 2184 |
} |
| 2185 |
|
| 2186 |
static int cma_ib_handler(struct ib_cm_id *cm_id, |
| 2187 |
const struct ib_cm_event *ib_event) |
| 2188 |
{ |
| 2189 |
struct rdma_id_private *id_priv = cm_id->context; |
| 2190 |
struct rdma_cm_event event = {}; |
| 2191 |
enum rdma_cm_state state; |
| 2192 |
int ret; |
| 2193 |
|
| 2194 |
mutex_lock(&id_priv->handler_mutex); |
| 2195 |
state = READ_ONCE(id_priv->state); |
| 2196 |
if ((ib_event->event != IB_CM_TIMEWAIT_EXIT && |
| 2197 |
state != RDMA_CM_CONNECT) || |
| 2198 |
(ib_event->event == IB_CM_TIMEWAIT_EXIT && |
| 2199 |
state != RDMA_CM_DISCONNECT)) |
| 2200 |
goto out; |
| 2201 |
|
| 2202 |
switch (ib_event->event) { |
| 2203 |
case IB_CM_REQ_ERROR: |
| 2204 |
case IB_CM_REP_ERROR: |
| 2205 |
event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 2206 |
event.status = -ETIMEDOUT; |
| 2207 |
break; |
| 2208 |
case IB_CM_REP_RECEIVED: |
| 2209 |
if (state == RDMA_CM_CONNECT && |
| 2210 |
(id_priv->id.qp_type != IB_QPT_UD)) { |
| 2211 |
trace_cm_prepare_mra(id_priv); |
| 2212 |
ib_prepare_cm_mra(cm_id); |
| 2213 |
} |
| 2214 |
if (id_priv->id.qp) { |
| 2215 |
event.status = cma_rep_recv(id_priv); |
| 2216 |
event.event = event.status ? RDMA_CM_EVENT_CONNECT_ERROR : |
| 2217 |
RDMA_CM_EVENT_ESTABLISHED; |
| 2218 |
} else { |
| 2219 |
event.event = RDMA_CM_EVENT_CONNECT_RESPONSE; |
| 2220 |
} |
| 2221 |
cma_set_rep_event_data(&event, &ib_event->param.rep_rcvd, |
| 2222 |
ib_event->private_data); |
| 2223 |
break; |
| 2224 |
case IB_CM_RTU_RECEIVED: |
| 2225 |
case IB_CM_USER_ESTABLISHED: |
| 2226 |
event.event = RDMA_CM_EVENT_ESTABLISHED; |
| 2227 |
break; |
| 2228 |
case IB_CM_DREQ_ERROR: |
| 2229 |
event.status = -ETIMEDOUT; |
| 2230 |
fallthrough; |
| 2231 |
case IB_CM_DREQ_RECEIVED: |
| 2232 |
case IB_CM_DREP_RECEIVED: |
| 2233 |
if (!cma_comp_exch(id_priv, RDMA_CM_CONNECT, |
| 2234 |
RDMA_CM_DISCONNECT)) |
| 2235 |
goto out; |
| 2236 |
event.event = RDMA_CM_EVENT_DISCONNECTED; |
| 2237 |
break; |
| 2238 |
case IB_CM_TIMEWAIT_EXIT: |
| 2239 |
event.event = RDMA_CM_EVENT_TIMEWAIT_EXIT; |
| 2240 |
break; |
| 2241 |
case IB_CM_MRA_RECEIVED: |
| 2242 |
/* ignore event */ |
| 2243 |
goto out; |
| 2244 |
case IB_CM_REJ_RECEIVED: |
| 2245 |
pr_debug_ratelimited("RDMA CM: REJECTED: %s\n", rdma_reject_msg(&id_priv->id, |
| 2246 |
ib_event->param.rej_rcvd.reason)); |
| 2247 |
cma_modify_qp_err(id_priv); |
| 2248 |
event.status = ib_event->param.rej_rcvd.reason; |
| 2249 |
event.event = RDMA_CM_EVENT_REJECTED; |
| 2250 |
event.param.conn.private_data = ib_event->private_data; |
| 2251 |
event.param.conn.private_data_len = IB_CM_REJ_PRIVATE_DATA_SIZE; |
| 2252 |
break; |
| 2253 |
default: |
| 2254 |
pr_err("RDMA CMA: unexpected IB CM event: %d\n", |
| 2255 |
ib_event->event); |
| 2256 |
goto out; |
| 2257 |
} |
| 2258 |
|
| 2259 |
ret = cma_cm_event_handler(id_priv, &event); |
| 2260 |
if (ret) { |
| 2261 |
/* Destroy the CM ID by returning a non-zero value. */ |
| 2262 |
id_priv->cm_id.ib = NULL; |
| 2263 |
destroy_id_handler_unlock(id_priv); |
| 2264 |
return ret; |
| 2265 |
} |
| 2266 |
out: |
| 2267 |
mutex_unlock(&id_priv->handler_mutex); |
| 2268 |
return 0; |
| 2269 |
} |
| 2270 |
|
| 2271 |
static struct rdma_id_private * |
| 2272 |
cma_ib_new_conn_id(const struct rdma_cm_id *listen_id, |
| 2273 |
const struct ib_cm_event *ib_event, |
| 2274 |
struct net_device *net_dev) |
| 2275 |
{ |
| 2276 |
struct rdma_id_private *listen_id_priv; |
| 2277 |
struct rdma_id_private *id_priv; |
| 2278 |
struct rdma_cm_id *id; |
| 2279 |
struct rdma_route *rt; |
| 2280 |
const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; |
| 2281 |
struct sa_path_rec *path = ib_event->param.req_rcvd.primary_path; |
| 2282 |
const __be64 service_id = |
| 2283 |
ib_event->param.req_rcvd.primary_path->service_id; |
| 2284 |
int ret; |
| 2285 |
|
| 2286 |
listen_id_priv = container_of(listen_id, struct rdma_id_private, id); |
| 2287 |
id_priv = __rdma_create_id(listen_id->route.addr.dev_addr.net, |
| 2288 |
listen_id->event_handler, listen_id->context, |
| 2289 |
listen_id->ps, |
| 2290 |
ib_event->param.req_rcvd.qp_type, |
| 2291 |
listen_id_priv); |
| 2292 |
if (IS_ERR(id_priv)) |
| 2293 |
return NULL; |
| 2294 |
|
| 2295 |
id = &id_priv->id; |
| 2296 |
if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, |
| 2297 |
(struct sockaddr *)&id->route.addr.dst_addr, |
| 2298 |
listen_id, ib_event, ss_family, service_id)) |
| 2299 |
goto err; |
| 2300 |
|
| 2301 |
rt = &id->route; |
| 2302 |
rt->num_pri_alt_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; |
| 2303 |
rt->path_rec = kmalloc_objs(*rt->path_rec, rt->num_pri_alt_paths); |
| 2304 |
if (!rt->path_rec) |
| 2305 |
goto err; |
| 2306 |
|
| 2307 |
rt->path_rec[0] = *path; |
| 2308 |
if (rt->num_pri_alt_paths == 2) |
| 2309 |
rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; |
| 2310 |
|
| 2311 |
if (net_dev) { |
| 2312 |
rdma_copy_src_l2_addr(&rt->addr.dev_addr, net_dev); |
| 2313 |
} else { |
| 2314 |
if (!cma_protocol_roce(listen_id) && |
| 2315 |
cma_any_addr(cma_src_addr(id_priv))) { |
| 2316 |
rt->addr.dev_addr.dev_type = ARPHRD_INFINIBAND; |
| 2317 |
rdma_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid); |
| 2318 |
ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey)); |
| 2319 |
} else if (!cma_any_addr(cma_src_addr(id_priv))) { |
| 2320 |
ret = cma_translate_addr(cma_src_addr(id_priv), &rt->addr.dev_addr); |
| 2321 |
if (ret) |
| 2322 |
goto err; |
| 2323 |
} |
| 2324 |
} |
| 2325 |
rdma_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid); |
| 2326 |
|
| 2327 |
id_priv->state = RDMA_CM_CONNECT; |
| 2328 |
return id_priv; |
| 2329 |
|
| 2330 |
err: |
| 2331 |
rdma_destroy_id(id); |
| 2332 |
return NULL; |
| 2333 |
} |
| 2334 |
|
| 2335 |
static struct rdma_id_private * |
| 2336 |
cma_ib_new_udp_id(const struct rdma_cm_id *listen_id, |
| 2337 |
const struct ib_cm_event *ib_event, |
| 2338 |
struct net_device *net_dev) |
| 2339 |
{ |
| 2340 |
const struct rdma_id_private *listen_id_priv; |
| 2341 |
struct rdma_id_private *id_priv; |
| 2342 |
struct rdma_cm_id *id; |
| 2343 |
const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; |
| 2344 |
struct net *net = listen_id->route.addr.dev_addr.net; |
| 2345 |
int ret; |
| 2346 |
|
| 2347 |
listen_id_priv = container_of(listen_id, struct rdma_id_private, id); |
| 2348 |
id_priv = __rdma_create_id(net, listen_id->event_handler, |
| 2349 |
listen_id->context, listen_id->ps, IB_QPT_UD, |
| 2350 |
listen_id_priv); |
| 2351 |
if (IS_ERR(id_priv)) |
| 2352 |
return NULL; |
| 2353 |
|
| 2354 |
id = &id_priv->id; |
| 2355 |
if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, |
| 2356 |
(struct sockaddr *)&id->route.addr.dst_addr, |
| 2357 |
listen_id, ib_event, ss_family, |
| 2358 |
ib_event->param.sidr_req_rcvd.service_id)) |
| 2359 |
goto err; |
| 2360 |
|
| 2361 |
if (net_dev) { |
| 2362 |
rdma_copy_src_l2_addr(&id->route.addr.dev_addr, net_dev); |
| 2363 |
} else { |
| 2364 |
if (!cma_any_addr(cma_src_addr(id_priv))) { |
| 2365 |
ret = cma_translate_addr(cma_src_addr(id_priv), |
| 2366 |
&id->route.addr.dev_addr); |
| 2367 |
if (ret) |
| 2368 |
goto err; |
| 2369 |
} |
| 2370 |
} |
| 2371 |
|
| 2372 |
id_priv->state = RDMA_CM_CONNECT; |
| 2373 |
return id_priv; |
| 2374 |
err: |
| 2375 |
rdma_destroy_id(id); |
| 2376 |
return NULL; |
| 2377 |
} |
| 2378 |
|
| 2379 |
static void cma_set_req_event_data(struct rdma_cm_event *event, |
| 2380 |
const struct ib_cm_req_event_param *req_data, |
| 2381 |
void *private_data, int offset) |
| 2382 |
{ |
| 2383 |
event->param.conn.private_data = private_data + offset; |
| 2384 |
event->param.conn.private_data_len = IB_CM_REQ_PRIVATE_DATA_SIZE - offset; |
| 2385 |
event->param.conn.responder_resources = req_data->responder_resources; |
| 2386 |
event->param.conn.initiator_depth = req_data->initiator_depth; |
| 2387 |
event->param.conn.flow_control = req_data->flow_control; |
| 2388 |
event->param.conn.retry_count = req_data->retry_count; |
| 2389 |
event->param.conn.rnr_retry_count = req_data->rnr_retry_count; |
| 2390 |
event->param.conn.srq = req_data->srq; |
| 2391 |
event->param.conn.qp_num = req_data->remote_qpn; |
| 2392 |
|
| 2393 |
event->ece.vendor_id = req_data->ece.vendor_id; |
| 2394 |
event->ece.attr_mod = req_data->ece.attr_mod; |
| 2395 |
} |
| 2396 |
|
| 2397 |
static int cma_ib_check_req_qp_type(const struct rdma_cm_id *id, |
| 2398 |
const struct ib_cm_event *ib_event) |
| 2399 |
{ |
| 2400 |
return (((ib_event->event == IB_CM_REQ_RECEIVED) && |
| 2401 |
(ib_event->param.req_rcvd.qp_type == id->qp_type)) || |
| 2402 |
((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) && |
| 2403 |
(id->qp_type == IB_QPT_UD)) || |
| 2404 |
(!id->qp_type)); |
| 2405 |
} |
| 2406 |
|
| 2407 |
static int cma_ib_req_handler(struct ib_cm_id *cm_id, |
| 2408 |
const struct ib_cm_event *ib_event) |
| 2409 |
{ |
| 2410 |
struct rdma_id_private *listen_id, *conn_id = NULL; |
| 2411 |
struct rdma_cm_event event = {}; |
| 2412 |
struct cma_req_info req = {}; |
| 2413 |
struct net_device *net_dev; |
| 2414 |
u8 offset; |
| 2415 |
int ret; |
| 2416 |
|
| 2417 |
listen_id = cma_ib_id_from_event(cm_id, ib_event, &req, &net_dev); |
| 2418 |
if (IS_ERR(listen_id)) |
| 2419 |
return PTR_ERR(listen_id); |
| 2420 |
|
| 2421 |
trace_cm_req_handler(listen_id, ib_event->event); |
| 2422 |
if (!cma_ib_check_req_qp_type(&listen_id->id, ib_event)) { |
| 2423 |
ret = -EINVAL; |
| 2424 |
goto net_dev_put; |
| 2425 |
} |
| 2426 |
|
| 2427 |
mutex_lock(&listen_id->handler_mutex); |
| 2428 |
if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) { |
| 2429 |
ret = -ECONNABORTED; |
| 2430 |
goto err_unlock; |
| 2431 |
} |
| 2432 |
|
| 2433 |
offset = cma_user_data_offset(listen_id); |
| 2434 |
event.event = RDMA_CM_EVENT_CONNECT_REQUEST; |
| 2435 |
if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) { |
| 2436 |
conn_id = cma_ib_new_udp_id(&listen_id->id, ib_event, net_dev); |
| 2437 |
event.param.ud.private_data = ib_event->private_data + offset; |
| 2438 |
event.param.ud.private_data_len = |
| 2439 |
IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; |
| 2440 |
} else { |
| 2441 |
conn_id = cma_ib_new_conn_id(&listen_id->id, ib_event, net_dev); |
| 2442 |
cma_set_req_event_data(&event, &ib_event->param.req_rcvd, |
| 2443 |
ib_event->private_data, offset); |
| 2444 |
} |
| 2445 |
if (!conn_id) { |
| 2446 |
ret = -ENOMEM; |
| 2447 |
goto err_unlock; |
| 2448 |
} |
| 2449 |
|
| 2450 |
mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); |
| 2451 |
ret = cma_ib_acquire_dev(conn_id, listen_id, &req); |
| 2452 |
if (ret) { |
| 2453 |
destroy_id_handler_unlock(conn_id); |
| 2454 |
goto err_unlock; |
| 2455 |
} |
| 2456 |
|
| 2457 |
conn_id->cm_id.ib = cm_id; |
| 2458 |
cm_id->context = conn_id; |
| 2459 |
cm_id->cm_handler = cma_ib_handler; |
| 2460 |
|
| 2461 |
ret = cma_cm_event_handler(conn_id, &event); |
| 2462 |
if (ret) { |
| 2463 |
/* Destroy the CM ID by returning a non-zero value. */ |
| 2464 |
conn_id->cm_id.ib = NULL; |
| 2465 |
mutex_unlock(&listen_id->handler_mutex); |
| 2466 |
destroy_id_handler_unlock(conn_id); |
| 2467 |
goto net_dev_put; |
| 2468 |
} |
| 2469 |
|
| 2470 |
if (READ_ONCE(conn_id->state) == RDMA_CM_CONNECT && |
| 2471 |
conn_id->id.qp_type != IB_QPT_UD) { |
| 2472 |
trace_cm_prepare_mra(cm_id->context); |
| 2473 |
ib_prepare_cm_mra(cm_id); |
| 2474 |
} |
| 2475 |
mutex_unlock(&conn_id->handler_mutex); |
| 2476 |
|
| 2477 |
err_unlock: |
| 2478 |
mutex_unlock(&listen_id->handler_mutex); |
| 2479 |
|
| 2480 |
net_dev_put: |
| 2481 |
dev_put(net_dev); |
| 2482 |
|
| 2483 |
return ret; |
| 2484 |
} |
| 2485 |
|
| 2486 |
__be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr) |
| 2487 |
{ |
| 2488 |
if (addr->sa_family == AF_IB) |
| 2489 |
return ((struct sockaddr_ib *) addr)->sib_sid; |
| 2490 |
|
| 2491 |
return cpu_to_be64(((u64)id->ps << 16) + be16_to_cpu(cma_port(addr))); |
| 2492 |
} |
| 2493 |
EXPORT_SYMBOL(rdma_get_service_id); |
| 2494 |
|
| 2495 |
void rdma_read_gids(struct rdma_cm_id *cm_id, union ib_gid *sgid, |
| 2496 |
union ib_gid *dgid) |
| 2497 |
{ |
| 2498 |
struct rdma_addr *addr = &cm_id->route.addr; |
| 2499 |
|
| 2500 |
if (!cm_id->device) { |
| 2501 |
if (sgid) |
| 2502 |
memset(sgid, 0, sizeof(*sgid)); |
| 2503 |
if (dgid) |
| 2504 |
memset(dgid, 0, sizeof(*dgid)); |
| 2505 |
return; |
| 2506 |
} |
| 2507 |
|
| 2508 |
if (rdma_protocol_roce(cm_id->device, cm_id->port_num)) { |
| 2509 |
if (sgid) |
| 2510 |
rdma_ip2gid((struct sockaddr *)&addr->src_addr, sgid); |
| 2511 |
if (dgid) |
| 2512 |
rdma_ip2gid((struct sockaddr *)&addr->dst_addr, dgid); |
| 2513 |
} else { |
| 2514 |
if (sgid) |
| 2515 |
rdma_addr_get_sgid(&addr->dev_addr, sgid); |
| 2516 |
if (dgid) |
| 2517 |
rdma_addr_get_dgid(&addr->dev_addr, dgid); |
| 2518 |
} |
| 2519 |
} |
| 2520 |
EXPORT_SYMBOL(rdma_read_gids); |
| 2521 |
|
| 2522 |
static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event) |
| 2523 |
{ |
| 2524 |
struct rdma_id_private *id_priv = iw_id->context; |
| 2525 |
struct rdma_cm_event event = {}; |
| 2526 |
int ret = 0; |
| 2527 |
struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; |
| 2528 |
struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; |
| 2529 |
|
| 2530 |
mutex_lock(&id_priv->handler_mutex); |
| 2531 |
if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) |
| 2532 |
goto out; |
| 2533 |
|
| 2534 |
switch (iw_event->event) { |
| 2535 |
case IW_CM_EVENT_CLOSE: |
| 2536 |
event.event = RDMA_CM_EVENT_DISCONNECTED; |
| 2537 |
break; |
| 2538 |
case IW_CM_EVENT_CONNECT_REPLY: |
| 2539 |
memcpy(cma_src_addr(id_priv), laddr, |
| 2540 |
rdma_addr_size(laddr)); |
| 2541 |
memcpy(cma_dst_addr(id_priv), raddr, |
| 2542 |
rdma_addr_size(raddr)); |
| 2543 |
switch (iw_event->status) { |
| 2544 |
case 0: |
| 2545 |
event.event = RDMA_CM_EVENT_ESTABLISHED; |
| 2546 |
event.param.conn.initiator_depth = iw_event->ird; |
| 2547 |
event.param.conn.responder_resources = iw_event->ord; |
| 2548 |
break; |
| 2549 |
case -ECONNRESET: |
| 2550 |
case -ECONNREFUSED: |
| 2551 |
event.event = RDMA_CM_EVENT_REJECTED; |
| 2552 |
break; |
| 2553 |
case -ETIMEDOUT: |
| 2554 |
event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 2555 |
break; |
| 2556 |
default: |
| 2557 |
event.event = RDMA_CM_EVENT_CONNECT_ERROR; |
| 2558 |
break; |
| 2559 |
} |
| 2560 |
break; |
| 2561 |
case IW_CM_EVENT_ESTABLISHED: |
| 2562 |
event.event = RDMA_CM_EVENT_ESTABLISHED; |
| 2563 |
event.param.conn.initiator_depth = iw_event->ird; |
| 2564 |
event.param.conn.responder_resources = iw_event->ord; |
| 2565 |
break; |
| 2566 |
default: |
| 2567 |
goto out; |
| 2568 |
} |
| 2569 |
|
| 2570 |
event.status = iw_event->status; |
| 2571 |
event.param.conn.private_data = iw_event->private_data; |
| 2572 |
event.param.conn.private_data_len = iw_event->private_data_len; |
| 2573 |
ret = cma_cm_event_handler(id_priv, &event); |
| 2574 |
if (ret) { |
| 2575 |
/* Destroy the CM ID by returning a non-zero value. */ |
| 2576 |
id_priv->cm_id.iw = NULL; |
| 2577 |
destroy_id_handler_unlock(id_priv); |
| 2578 |
return ret; |
| 2579 |
} |
| 2580 |
|
| 2581 |
out: |
| 2582 |
mutex_unlock(&id_priv->handler_mutex); |
| 2583 |
return ret; |
| 2584 |
} |
| 2585 |
|
| 2586 |
static int iw_conn_req_handler(struct iw_cm_id *cm_id, |
| 2587 |
struct iw_cm_event *iw_event) |
| 2588 |
{ |
| 2589 |
struct rdma_id_private *listen_id, *conn_id; |
| 2590 |
struct rdma_cm_event event = {}; |
| 2591 |
int ret = -ECONNABORTED; |
| 2592 |
struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; |
| 2593 |
struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; |
| 2594 |
|
| 2595 |
event.event = RDMA_CM_EVENT_CONNECT_REQUEST; |
| 2596 |
event.param.conn.private_data = iw_event->private_data; |
| 2597 |
event.param.conn.private_data_len = iw_event->private_data_len; |
| 2598 |
event.param.conn.initiator_depth = iw_event->ird; |
| 2599 |
event.param.conn.responder_resources = iw_event->ord; |
| 2600 |
|
| 2601 |
listen_id = cm_id->context; |
| 2602 |
|
| 2603 |
mutex_lock(&listen_id->handler_mutex); |
| 2604 |
if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) |
| 2605 |
goto out; |
| 2606 |
|
| 2607 |
/* Create a new RDMA id for the new IW CM ID */ |
| 2608 |
conn_id = __rdma_create_id(listen_id->id.route.addr.dev_addr.net, |
| 2609 |
listen_id->id.event_handler, |
| 2610 |
listen_id->id.context, RDMA_PS_TCP, |
| 2611 |
IB_QPT_RC, listen_id); |
| 2612 |
if (IS_ERR(conn_id)) { |
| 2613 |
ret = -ENOMEM; |
| 2614 |
goto out; |
| 2615 |
} |
| 2616 |
mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); |
| 2617 |
conn_id->state = RDMA_CM_CONNECT; |
| 2618 |
|
| 2619 |
ret = rdma_translate_ip(laddr, &conn_id->id.route.addr.dev_addr); |
| 2620 |
if (ret) { |
| 2621 |
mutex_unlock(&listen_id->handler_mutex); |
| 2622 |
destroy_id_handler_unlock(conn_id); |
| 2623 |
return ret; |
| 2624 |
} |
| 2625 |
|
| 2626 |
ret = cma_iw_acquire_dev(conn_id, listen_id); |
| 2627 |
if (ret) { |
| 2628 |
mutex_unlock(&listen_id->handler_mutex); |
| 2629 |
destroy_id_handler_unlock(conn_id); |
| 2630 |
return ret; |
| 2631 |
} |
| 2632 |
|
| 2633 |
conn_id->cm_id.iw = cm_id; |
| 2634 |
cm_id->context = conn_id; |
| 2635 |
cm_id->cm_handler = cma_iw_handler; |
| 2636 |
|
| 2637 |
memcpy(cma_src_addr(conn_id), laddr, rdma_addr_size(laddr)); |
| 2638 |
memcpy(cma_dst_addr(conn_id), raddr, rdma_addr_size(raddr)); |
| 2639 |
|
| 2640 |
ret = cma_cm_event_handler(conn_id, &event); |
| 2641 |
if (ret) { |
| 2642 |
/* User wants to destroy the CM ID */ |
| 2643 |
conn_id->cm_id.iw = NULL; |
| 2644 |
mutex_unlock(&listen_id->handler_mutex); |
| 2645 |
destroy_id_handler_unlock(conn_id); |
| 2646 |
return ret; |
| 2647 |
} |
| 2648 |
|
| 2649 |
mutex_unlock(&conn_id->handler_mutex); |
| 2650 |
|
| 2651 |
out: |
| 2652 |
mutex_unlock(&listen_id->handler_mutex); |
| 2653 |
return ret; |
| 2654 |
} |
| 2655 |
|
| 2656 |
static int cma_ib_listen(struct rdma_id_private *id_priv) |
| 2657 |
{ |
| 2658 |
struct sockaddr *addr; |
| 2659 |
struct ib_cm_id *id; |
| 2660 |
__be64 svc_id; |
| 2661 |
|
| 2662 |
addr = cma_src_addr(id_priv); |
| 2663 |
svc_id = rdma_get_service_id(&id_priv->id, addr); |
| 2664 |
id = ib_cm_insert_listen(id_priv->id.device, |
| 2665 |
cma_ib_req_handler, svc_id); |
| 2666 |
if (IS_ERR(id)) |
| 2667 |
return PTR_ERR(id); |
| 2668 |
id_priv->cm_id.ib = id; |
| 2669 |
|
| 2670 |
return 0; |
| 2671 |
} |
| 2672 |
|
| 2673 |
static int cma_iw_listen(struct rdma_id_private *id_priv, int backlog) |
| 2674 |
{ |
| 2675 |
int ret; |
| 2676 |
struct iw_cm_id *id; |
| 2677 |
|
| 2678 |
id = iw_create_cm_id(id_priv->id.device, |
| 2679 |
iw_conn_req_handler, |
| 2680 |
id_priv); |
| 2681 |
if (IS_ERR(id)) |
| 2682 |
return PTR_ERR(id); |
| 2683 |
|
| 2684 |
mutex_lock(&id_priv->qp_mutex); |
| 2685 |
id->tos = id_priv->tos; |
| 2686 |
id->tos_set = id_priv->tos_set; |
| 2687 |
mutex_unlock(&id_priv->qp_mutex); |
| 2688 |
id->afonly = id_priv->afonly; |
| 2689 |
id_priv->cm_id.iw = id; |
| 2690 |
|
| 2691 |
memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), |
| 2692 |
rdma_addr_size(cma_src_addr(id_priv))); |
| 2693 |
|
| 2694 |
ret = iw_cm_listen(id_priv->cm_id.iw, backlog); |
| 2695 |
|
| 2696 |
if (ret) { |
| 2697 |
iw_destroy_cm_id(id_priv->cm_id.iw); |
| 2698 |
id_priv->cm_id.iw = NULL; |
| 2699 |
} |
| 2700 |
|
| 2701 |
return ret; |
| 2702 |
} |
| 2703 |
|
| 2704 |
static int cma_listen_handler(struct rdma_cm_id *id, |
| 2705 |
struct rdma_cm_event *event) |
| 2706 |
{ |
| 2707 |
struct rdma_id_private *id_priv = id->context; |
| 2708 |
|
| 2709 |
/* Listening IDs are always destroyed on removal */ |
| 2710 |
if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) |
| 2711 |
return -1; |
| 2712 |
|
| 2713 |
id->context = id_priv->id.context; |
| 2714 |
id->event_handler = id_priv->id.event_handler; |
| 2715 |
trace_cm_event_handler(id_priv, event); |
| 2716 |
return id_priv->id.event_handler(id, event); |
| 2717 |
} |
| 2718 |
|
| 2719 |
static int cma_listen_on_dev(struct rdma_id_private *id_priv, |
| 2720 |
struct cma_device *cma_dev, |
| 2721 |
struct rdma_id_private **to_destroy) |
| 2722 |
{ |
| 2723 |
struct rdma_id_private *dev_id_priv; |
| 2724 |
struct net *net = id_priv->id.route.addr.dev_addr.net; |
| 2725 |
int ret; |
| 2726 |
|
| 2727 |
lockdep_assert_held(&lock); |
| 2728 |
|
| 2729 |
*to_destroy = NULL; |
| 2730 |
if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1)) |
| 2731 |
return 0; |
| 2732 |
if (id_priv->restricted_node_type != RDMA_NODE_UNSPECIFIED && |
| 2733 |
id_priv->restricted_node_type != cma_dev->device->node_type) |
| 2734 |
return 0; |
| 2735 |
|
| 2736 |
dev_id_priv = |
| 2737 |
__rdma_create_id(net, cma_listen_handler, id_priv, |
| 2738 |
id_priv->id.ps, id_priv->id.qp_type, id_priv); |
| 2739 |
if (IS_ERR(dev_id_priv)) |
| 2740 |
return PTR_ERR(dev_id_priv); |
| 2741 |
|
| 2742 |
dev_id_priv->restricted_node_type = id_priv->restricted_node_type; |
| 2743 |
dev_id_priv->state = RDMA_CM_ADDR_BOUND; |
| 2744 |
memcpy(cma_src_addr(dev_id_priv), cma_src_addr(id_priv), |
| 2745 |
rdma_addr_size(cma_src_addr(id_priv))); |
| 2746 |
|
| 2747 |
_cma_attach_to_dev(dev_id_priv, cma_dev); |
| 2748 |
rdma_restrack_add(&dev_id_priv->res); |
| 2749 |
cma_id_get(id_priv); |
| 2750 |
dev_id_priv->internal_id = 1; |
| 2751 |
dev_id_priv->afonly = id_priv->afonly; |
| 2752 |
mutex_lock(&id_priv->qp_mutex); |
| 2753 |
dev_id_priv->tos_set = id_priv->tos_set; |
| 2754 |
dev_id_priv->tos = id_priv->tos; |
| 2755 |
mutex_unlock(&id_priv->qp_mutex); |
| 2756 |
|
| 2757 |
ret = rdma_listen(&dev_id_priv->id, id_priv->backlog); |
| 2758 |
if (ret) |
| 2759 |
goto err_listen; |
| 2760 |
list_add_tail(&dev_id_priv->listen_item, &id_priv->listen_list); |
| 2761 |
return 0; |
| 2762 |
err_listen: |
| 2763 |
/* Caller must destroy this after releasing lock */ |
| 2764 |
*to_destroy = dev_id_priv; |
| 2765 |
dev_warn(&cma_dev->device->dev, "RDMA CMA: %s, error %d\n", __func__, ret); |
| 2766 |
return ret; |
| 2767 |
} |
| 2768 |
|
| 2769 |
static int cma_listen_on_all(struct rdma_id_private *id_priv) |
| 2770 |
{ |
| 2771 |
struct rdma_id_private *to_destroy; |
| 2772 |
struct cma_device *cma_dev; |
| 2773 |
int ret; |
| 2774 |
|
| 2775 |
mutex_lock(&lock); |
| 2776 |
list_add_tail(&id_priv->listen_any_item, &listen_any_list); |
| 2777 |
list_for_each_entry(cma_dev, &dev_list, list) { |
| 2778 |
ret = cma_listen_on_dev(id_priv, cma_dev, &to_destroy); |
| 2779 |
if (ret) { |
| 2780 |
/* Prevent racing with cma_process_remove() */ |
| 2781 |
if (to_destroy) |
| 2782 |
list_del_init(&to_destroy->device_item); |
| 2783 |
goto err_listen; |
| 2784 |
} |
| 2785 |
} |
| 2786 |
mutex_unlock(&lock); |
| 2787 |
return 0; |
| 2788 |
|
| 2789 |
err_listen: |
| 2790 |
_cma_cancel_listens(id_priv); |
| 2791 |
mutex_unlock(&lock); |
| 2792 |
if (to_destroy) |
| 2793 |
rdma_destroy_id(&to_destroy->id); |
| 2794 |
return ret; |
| 2795 |
} |
| 2796 |
|
| 2797 |
void rdma_set_service_type(struct rdma_cm_id *id, int tos) |
| 2798 |
{ |
| 2799 |
struct rdma_id_private *id_priv; |
| 2800 |
|
| 2801 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 2802 |
mutex_lock(&id_priv->qp_mutex); |
| 2803 |
id_priv->tos = (u8) tos; |
| 2804 |
id_priv->tos_set = true; |
| 2805 |
mutex_unlock(&id_priv->qp_mutex); |
| 2806 |
} |
| 2807 |
EXPORT_SYMBOL(rdma_set_service_type); |
| 2808 |
|
| 2809 |
/** |
| 2810 |
* rdma_set_ack_timeout() - Set the ack timeout of QP associated |
| 2811 |
* with a connection identifier. |
| 2812 |
* @id: Communication identifier to associated with service type. |
| 2813 |
* @timeout: Ack timeout to set a QP, expressed as 4.096 * 2^(timeout) usec. |
| 2814 |
* |
| 2815 |
* This function should be called before rdma_connect() on active side, |
| 2816 |
* and on passive side before rdma_accept(). It is applicable to primary |
| 2817 |
* path only. The timeout will affect the local side of the QP, it is not |
| 2818 |
* negotiated with remote side and zero disables the timer. In case it is |
| 2819 |
* set before rdma_resolve_route, the value will also be used to determine |
| 2820 |
* PacketLifeTime for RoCE. |
| 2821 |
* |
| 2822 |
* Return: 0 for success |
| 2823 |
*/ |
| 2824 |
int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout) |
| 2825 |
{ |
| 2826 |
struct rdma_id_private *id_priv; |
| 2827 |
|
| 2828 |
if (id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_INI) |
| 2829 |
return -EINVAL; |
| 2830 |
|
| 2831 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 2832 |
mutex_lock(&id_priv->qp_mutex); |
| 2833 |
id_priv->timeout = timeout; |
| 2834 |
id_priv->timeout_set = true; |
| 2835 |
mutex_unlock(&id_priv->qp_mutex); |
| 2836 |
|
| 2837 |
return 0; |
| 2838 |
} |
| 2839 |
EXPORT_SYMBOL(rdma_set_ack_timeout); |
| 2840 |
|
| 2841 |
/** |
| 2842 |
* rdma_set_min_rnr_timer() - Set the minimum RNR Retry timer of the |
| 2843 |
* QP associated with a connection identifier. |
| 2844 |
* @id: Communication identifier to associated with service type. |
| 2845 |
* @min_rnr_timer: 5-bit value encoded as Table 45: "Encoding for RNR NAK |
| 2846 |
* Timer Field" in the IBTA specification. |
| 2847 |
* |
| 2848 |
* This function should be called before rdma_connect() on active |
| 2849 |
* side, and on passive side before rdma_accept(). The timer value |
| 2850 |
* will be associated with the local QP. When it receives a send it is |
| 2851 |
* not read to handle, typically if the receive queue is empty, an RNR |
| 2852 |
* Retry NAK is returned to the requester with the min_rnr_timer |
| 2853 |
* encoded. The requester will then wait at least the time specified |
| 2854 |
* in the NAK before retrying. The default is zero, which translates |
| 2855 |
* to a minimum RNR Timer value of 655 ms. |
| 2856 |
* |
| 2857 |
* Return: 0 for success |
| 2858 |
*/ |
| 2859 |
int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer) |
| 2860 |
{ |
| 2861 |
struct rdma_id_private *id_priv; |
| 2862 |
|
| 2863 |
/* It is a five-bit value */ |
| 2864 |
if (min_rnr_timer & 0xe0) |
| 2865 |
return -EINVAL; |
| 2866 |
|
| 2867 |
if (WARN_ON(id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_TGT)) |
| 2868 |
return -EINVAL; |
| 2869 |
|
| 2870 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 2871 |
mutex_lock(&id_priv->qp_mutex); |
| 2872 |
id_priv->min_rnr_timer = min_rnr_timer; |
| 2873 |
id_priv->min_rnr_timer_set = true; |
| 2874 |
mutex_unlock(&id_priv->qp_mutex); |
| 2875 |
|
| 2876 |
return 0; |
| 2877 |
} |
| 2878 |
EXPORT_SYMBOL(rdma_set_min_rnr_timer); |
| 2879 |
|
| 2880 |
static int route_set_path_rec_inbound(struct cma_work *work, |
| 2881 |
struct sa_path_rec *path_rec) |
| 2882 |
{ |
| 2883 |
struct rdma_route *route = &work->id->id.route; |
| 2884 |
|
| 2885 |
if (!route->path_rec_inbound) { |
| 2886 |
route->path_rec_inbound = kzalloc_obj(*route->path_rec_inbound); |
| 2887 |
if (!route->path_rec_inbound) |
| 2888 |
return -ENOMEM; |
| 2889 |
} |
| 2890 |
|
| 2891 |
*route->path_rec_inbound = *path_rec; |
| 2892 |
return 0; |
| 2893 |
} |
| 2894 |
|
| 2895 |
static int route_set_path_rec_outbound(struct cma_work *work, |
| 2896 |
struct sa_path_rec *path_rec) |
| 2897 |
{ |
| 2898 |
struct rdma_route *route = &work->id->id.route; |
| 2899 |
|
| 2900 |
if (!route->path_rec_outbound) { |
| 2901 |
route->path_rec_outbound = kzalloc_obj(*route->path_rec_outbound); |
| 2902 |
if (!route->path_rec_outbound) |
| 2903 |
return -ENOMEM; |
| 2904 |
} |
| 2905 |
|
| 2906 |
*route->path_rec_outbound = *path_rec; |
| 2907 |
return 0; |
| 2908 |
} |
| 2909 |
|
| 2910 |
static void cma_query_handler(int status, struct sa_path_rec *path_rec, |
| 2911 |
unsigned int num_prs, void *context) |
| 2912 |
{ |
| 2913 |
struct cma_work *work = context; |
| 2914 |
struct rdma_route *route; |
| 2915 |
int i; |
| 2916 |
|
| 2917 |
route = &work->id->id.route; |
| 2918 |
|
| 2919 |
if (status) |
| 2920 |
goto fail; |
| 2921 |
|
| 2922 |
for (i = 0; i < num_prs; i++) { |
| 2923 |
if (!path_rec[i].flags || (path_rec[i].flags & IB_PATH_GMP)) |
| 2924 |
*route->path_rec = path_rec[i]; |
| 2925 |
else if (path_rec[i].flags & IB_PATH_INBOUND) |
| 2926 |
status = route_set_path_rec_inbound(work, &path_rec[i]); |
| 2927 |
else if (path_rec[i].flags & IB_PATH_OUTBOUND) |
| 2928 |
status = route_set_path_rec_outbound(work, |
| 2929 |
&path_rec[i]); |
| 2930 |
else |
| 2931 |
status = -EINVAL; |
| 2932 |
|
| 2933 |
if (status) |
| 2934 |
goto fail; |
| 2935 |
} |
| 2936 |
|
| 2937 |
route->num_pri_alt_paths = 1; |
| 2938 |
queue_work(cma_wq, &work->work); |
| 2939 |
return; |
| 2940 |
|
| 2941 |
fail: |
| 2942 |
work->old_state = RDMA_CM_ROUTE_QUERY; |
| 2943 |
work->new_state = RDMA_CM_ADDR_RESOLVED; |
| 2944 |
work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; |
| 2945 |
work->event.status = status; |
| 2946 |
pr_debug_ratelimited("RDMA CM: ROUTE_ERROR: failed to query path. status %d\n", |
| 2947 |
status); |
| 2948 |
queue_work(cma_wq, &work->work); |
| 2949 |
} |
| 2950 |
|
| 2951 |
static int cma_query_ib_route(struct rdma_id_private *id_priv, |
| 2952 |
unsigned long timeout_ms, struct cma_work *work) |
| 2953 |
{ |
| 2954 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 2955 |
struct sa_path_rec path_rec; |
| 2956 |
ib_sa_comp_mask comp_mask; |
| 2957 |
struct sockaddr_in6 *sin6; |
| 2958 |
struct sockaddr_ib *sib; |
| 2959 |
|
| 2960 |
memset(&path_rec, 0, sizeof path_rec); |
| 2961 |
|
| 2962 |
if (rdma_cap_opa_ah(id_priv->id.device, id_priv->id.port_num)) |
| 2963 |
path_rec.rec_type = SA_PATH_REC_TYPE_OPA; |
| 2964 |
else |
| 2965 |
path_rec.rec_type = SA_PATH_REC_TYPE_IB; |
| 2966 |
rdma_addr_get_sgid(dev_addr, &path_rec.sgid); |
| 2967 |
rdma_addr_get_dgid(dev_addr, &path_rec.dgid); |
| 2968 |
path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr)); |
| 2969 |
path_rec.numb_path = 1; |
| 2970 |
path_rec.reversible = 1; |
| 2971 |
path_rec.service_id = rdma_get_service_id(&id_priv->id, |
| 2972 |
cma_dst_addr(id_priv)); |
| 2973 |
|
| 2974 |
comp_mask = IB_SA_PATH_REC_DGID | IB_SA_PATH_REC_SGID | |
| 2975 |
IB_SA_PATH_REC_PKEY | IB_SA_PATH_REC_NUMB_PATH | |
| 2976 |
IB_SA_PATH_REC_REVERSIBLE | IB_SA_PATH_REC_SERVICE_ID; |
| 2977 |
|
| 2978 |
switch (cma_family(id_priv)) { |
| 2979 |
case AF_INET: |
| 2980 |
path_rec.qos_class = cpu_to_be16((u16) id_priv->tos); |
| 2981 |
comp_mask |= IB_SA_PATH_REC_QOS_CLASS; |
| 2982 |
break; |
| 2983 |
case AF_INET6: |
| 2984 |
sin6 = (struct sockaddr_in6 *) cma_src_addr(id_priv); |
| 2985 |
path_rec.traffic_class = (u8) (be32_to_cpu(sin6->sin6_flowinfo) >> 20); |
| 2986 |
comp_mask |= IB_SA_PATH_REC_TRAFFIC_CLASS; |
| 2987 |
break; |
| 2988 |
case AF_IB: |
| 2989 |
sib = (struct sockaddr_ib *) cma_src_addr(id_priv); |
| 2990 |
path_rec.traffic_class = (u8) (be32_to_cpu(sib->sib_flowinfo) >> 20); |
| 2991 |
comp_mask |= IB_SA_PATH_REC_TRAFFIC_CLASS; |
| 2992 |
break; |
| 2993 |
} |
| 2994 |
|
| 2995 |
id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, |
| 2996 |
id_priv->id.port_num, &path_rec, |
| 2997 |
comp_mask, timeout_ms, |
| 2998 |
GFP_KERNEL, cma_query_handler, |
| 2999 |
work, &id_priv->query); |
| 3000 |
|
| 3001 |
return (id_priv->query_id < 0) ? id_priv->query_id : 0; |
| 3002 |
} |
| 3003 |
|
| 3004 |
static void cma_iboe_join_work_handler(struct work_struct *work) |
| 3005 |
{ |
| 3006 |
struct cma_multicast *mc = |
| 3007 |
container_of(work, struct cma_multicast, iboe_join.work); |
| 3008 |
struct rdma_cm_event *event = &mc->iboe_join.event; |
| 3009 |
struct rdma_id_private *id_priv = mc->id_priv; |
| 3010 |
int ret; |
| 3011 |
|
| 3012 |
mutex_lock(&id_priv->handler_mutex); |
| 3013 |
if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || |
| 3014 |
READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) |
| 3015 |
goto out_unlock; |
| 3016 |
|
| 3017 |
ret = cma_cm_event_handler(id_priv, event); |
| 3018 |
WARN_ON(ret); |
| 3019 |
|
| 3020 |
out_unlock: |
| 3021 |
mutex_unlock(&id_priv->handler_mutex); |
| 3022 |
if (event->event == RDMA_CM_EVENT_MULTICAST_JOIN) |
| 3023 |
rdma_destroy_ah_attr(&event->param.ud.ah_attr); |
| 3024 |
} |
| 3025 |
|
| 3026 |
static void cma_work_handler(struct work_struct *_work) |
| 3027 |
{ |
| 3028 |
struct cma_work *work = container_of(_work, struct cma_work, work); |
| 3029 |
struct rdma_id_private *id_priv = work->id; |
| 3030 |
|
| 3031 |
mutex_lock(&id_priv->handler_mutex); |
| 3032 |
if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || |
| 3033 |
READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) |
| 3034 |
goto out_unlock; |
| 3035 |
if (work->old_state != 0 || work->new_state != 0) { |
| 3036 |
if (!cma_comp_exch(id_priv, work->old_state, work->new_state)) |
| 3037 |
goto out_unlock; |
| 3038 |
} |
| 3039 |
|
| 3040 |
if (cma_cm_event_handler(id_priv, &work->event)) { |
| 3041 |
cma_id_put(id_priv); |
| 3042 |
destroy_id_handler_unlock(id_priv); |
| 3043 |
goto out_free; |
| 3044 |
} |
| 3045 |
|
| 3046 |
out_unlock: |
| 3047 |
mutex_unlock(&id_priv->handler_mutex); |
| 3048 |
cma_id_put(id_priv); |
| 3049 |
out_free: |
| 3050 |
if (work->event.event == RDMA_CM_EVENT_MULTICAST_JOIN) |
| 3051 |
rdma_destroy_ah_attr(&work->event.param.ud.ah_attr); |
| 3052 |
kfree(work); |
| 3053 |
} |
| 3054 |
|
| 3055 |
static void cma_init_resolve_route_work(struct cma_work *work, |
| 3056 |
struct rdma_id_private *id_priv) |
| 3057 |
{ |
| 3058 |
work->id = id_priv; |
| 3059 |
INIT_WORK(&work->work, cma_work_handler); |
| 3060 |
work->old_state = RDMA_CM_ROUTE_QUERY; |
| 3061 |
work->new_state = RDMA_CM_ROUTE_RESOLVED; |
| 3062 |
work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; |
| 3063 |
} |
| 3064 |
|
| 3065 |
static void enqueue_resolve_addr_work(struct cma_work *work, |
| 3066 |
struct rdma_id_private *id_priv) |
| 3067 |
{ |
| 3068 |
/* Balances with cma_id_put() in cma_work_handler */ |
| 3069 |
cma_id_get(id_priv); |
| 3070 |
|
| 3071 |
work->id = id_priv; |
| 3072 |
INIT_WORK(&work->work, cma_work_handler); |
| 3073 |
work->old_state = RDMA_CM_ADDR_QUERY; |
| 3074 |
work->new_state = RDMA_CM_ADDR_RESOLVED; |
| 3075 |
work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; |
| 3076 |
|
| 3077 |
queue_work(cma_wq, &work->work); |
| 3078 |
} |
| 3079 |
|
| 3080 |
static int cma_resolve_ib_route(struct rdma_id_private *id_priv, |
| 3081 |
unsigned long timeout_ms) |
| 3082 |
{ |
| 3083 |
struct rdma_route *route = &id_priv->id.route; |
| 3084 |
struct cma_work *work; |
| 3085 |
int ret; |
| 3086 |
|
| 3087 |
work = kzalloc_obj(*work); |
| 3088 |
if (!work) |
| 3089 |
return -ENOMEM; |
| 3090 |
|
| 3091 |
cma_init_resolve_route_work(work, id_priv); |
| 3092 |
|
| 3093 |
if (!route->path_rec) |
| 3094 |
route->path_rec = kmalloc_obj(*route->path_rec); |
| 3095 |
if (!route->path_rec) { |
| 3096 |
ret = -ENOMEM; |
| 3097 |
goto err1; |
| 3098 |
} |
| 3099 |
|
| 3100 |
ret = cma_query_ib_route(id_priv, timeout_ms, work); |
| 3101 |
if (ret) |
| 3102 |
goto err2; |
| 3103 |
|
| 3104 |
return 0; |
| 3105 |
err2: |
| 3106 |
kfree(route->path_rec); |
| 3107 |
route->path_rec = NULL; |
| 3108 |
err1: |
| 3109 |
kfree(work); |
| 3110 |
return ret; |
| 3111 |
} |
| 3112 |
|
| 3113 |
static enum ib_gid_type cma_route_gid_type(enum rdma_network_type network_type, |
| 3114 |
unsigned long supported_gids, |
| 3115 |
enum ib_gid_type default_gid) |
| 3116 |
{ |
| 3117 |
if ((network_type == RDMA_NETWORK_IPV4 || |
| 3118 |
network_type == RDMA_NETWORK_IPV6) && |
| 3119 |
test_bit(IB_GID_TYPE_ROCE_UDP_ENCAP, &supported_gids)) |
| 3120 |
return IB_GID_TYPE_ROCE_UDP_ENCAP; |
| 3121 |
|
| 3122 |
return default_gid; |
| 3123 |
} |
| 3124 |
|
| 3125 |
/* |
| 3126 |
* cma_iboe_set_path_rec_l2_fields() is helper function which sets |
| 3127 |
* path record type based on GID type. |
| 3128 |
* It also sets up other L2 fields which includes destination mac address |
| 3129 |
* netdev ifindex, of the path record. |
| 3130 |
* It returns the netdev of the bound interface for this path record entry. |
| 3131 |
*/ |
| 3132 |
static struct net_device * |
| 3133 |
cma_iboe_set_path_rec_l2_fields(struct rdma_id_private *id_priv) |
| 3134 |
{ |
| 3135 |
struct rdma_route *route = &id_priv->id.route; |
| 3136 |
enum ib_gid_type gid_type = IB_GID_TYPE_ROCE; |
| 3137 |
struct rdma_addr *addr = &route->addr; |
| 3138 |
unsigned long supported_gids; |
| 3139 |
struct net_device *ndev; |
| 3140 |
|
| 3141 |
if (!addr->dev_addr.bound_dev_if) |
| 3142 |
return NULL; |
| 3143 |
|
| 3144 |
ndev = dev_get_by_index(addr->dev_addr.net, |
| 3145 |
addr->dev_addr.bound_dev_if); |
| 3146 |
if (!ndev) |
| 3147 |
return NULL; |
| 3148 |
|
| 3149 |
supported_gids = roce_gid_type_mask_support(id_priv->id.device, |
| 3150 |
id_priv->id.port_num); |
| 3151 |
gid_type = cma_route_gid_type(addr->dev_addr.network, |
| 3152 |
supported_gids, |
| 3153 |
id_priv->gid_type); |
| 3154 |
/* Use the hint from IP Stack to select GID Type */ |
| 3155 |
if (gid_type < ib_network_to_gid_type(addr->dev_addr.network)) |
| 3156 |
gid_type = ib_network_to_gid_type(addr->dev_addr.network); |
| 3157 |
route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type); |
| 3158 |
|
| 3159 |
route->path_rec->roce.route_resolved = true; |
| 3160 |
sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr); |
| 3161 |
return ndev; |
| 3162 |
} |
| 3163 |
|
| 3164 |
int rdma_set_ib_path(struct rdma_cm_id *id, |
| 3165 |
struct sa_path_rec *path_rec) |
| 3166 |
{ |
| 3167 |
struct rdma_id_private *id_priv; |
| 3168 |
struct net_device *ndev; |
| 3169 |
int ret; |
| 3170 |
|
| 3171 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 3172 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, |
| 3173 |
RDMA_CM_ROUTE_RESOLVED)) |
| 3174 |
return -EINVAL; |
| 3175 |
|
| 3176 |
id->route.path_rec = kmemdup(path_rec, sizeof(*path_rec), |
| 3177 |
GFP_KERNEL); |
| 3178 |
if (!id->route.path_rec) { |
| 3179 |
ret = -ENOMEM; |
| 3180 |
goto err; |
| 3181 |
} |
| 3182 |
|
| 3183 |
if (rdma_protocol_roce(id->device, id->port_num)) { |
| 3184 |
ndev = cma_iboe_set_path_rec_l2_fields(id_priv); |
| 3185 |
if (!ndev) { |
| 3186 |
ret = -ENODEV; |
| 3187 |
goto err_free; |
| 3188 |
} |
| 3189 |
dev_put(ndev); |
| 3190 |
} |
| 3191 |
|
| 3192 |
id->route.num_pri_alt_paths = 1; |
| 3193 |
return 0; |
| 3194 |
|
| 3195 |
err_free: |
| 3196 |
kfree(id->route.path_rec); |
| 3197 |
id->route.path_rec = NULL; |
| 3198 |
err: |
| 3199 |
cma_comp_exch(id_priv, RDMA_CM_ROUTE_RESOLVED, RDMA_CM_ADDR_RESOLVED); |
| 3200 |
return ret; |
| 3201 |
} |
| 3202 |
EXPORT_SYMBOL(rdma_set_ib_path); |
| 3203 |
|
| 3204 |
static int cma_resolve_iw_route(struct rdma_id_private *id_priv) |
| 3205 |
{ |
| 3206 |
struct cma_work *work; |
| 3207 |
|
| 3208 |
work = kzalloc_obj(*work); |
| 3209 |
if (!work) |
| 3210 |
return -ENOMEM; |
| 3211 |
|
| 3212 |
cma_init_resolve_route_work(work, id_priv); |
| 3213 |
queue_work(cma_wq, &work->work); |
| 3214 |
return 0; |
| 3215 |
} |
| 3216 |
|
| 3217 |
static int get_vlan_ndev_tc(struct net_device *vlan_ndev, int prio) |
| 3218 |
{ |
| 3219 |
struct net_device *dev; |
| 3220 |
|
| 3221 |
dev = vlan_dev_real_dev(vlan_ndev); |
| 3222 |
if (dev->num_tc) |
| 3223 |
return netdev_get_prio_tc_map(dev, prio); |
| 3224 |
|
| 3225 |
return (vlan_dev_get_egress_qos_mask(vlan_ndev, prio) & |
| 3226 |
VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; |
| 3227 |
} |
| 3228 |
|
| 3229 |
struct iboe_prio_tc_map { |
| 3230 |
int input_prio; |
| 3231 |
int output_tc; |
| 3232 |
bool found; |
| 3233 |
}; |
| 3234 |
|
| 3235 |
static int get_lower_vlan_dev_tc(struct net_device *dev, |
| 3236 |
struct netdev_nested_priv *priv) |
| 3237 |
{ |
| 3238 |
struct iboe_prio_tc_map *map = (struct iboe_prio_tc_map *)priv->data; |
| 3239 |
|
| 3240 |
if (is_vlan_dev(dev)) |
| 3241 |
map->output_tc = get_vlan_ndev_tc(dev, map->input_prio); |
| 3242 |
else if (dev->num_tc) |
| 3243 |
map->output_tc = netdev_get_prio_tc_map(dev, map->input_prio); |
| 3244 |
else |
| 3245 |
map->output_tc = 0; |
| 3246 |
/* We are interested only in first level VLAN device, so always |
| 3247 |
* return 1 to stop iterating over next level devices. |
| 3248 |
*/ |
| 3249 |
map->found = true; |
| 3250 |
return 1; |
| 3251 |
} |
| 3252 |
|
| 3253 |
static int iboe_tos_to_sl(struct net_device *ndev, int tos) |
| 3254 |
{ |
| 3255 |
struct iboe_prio_tc_map prio_tc_map = {}; |
| 3256 |
int prio = rt_tos2priority(tos); |
| 3257 |
struct netdev_nested_priv priv; |
| 3258 |
|
| 3259 |
/* If VLAN device, get it directly from the VLAN netdev */ |
| 3260 |
if (is_vlan_dev(ndev)) |
| 3261 |
return get_vlan_ndev_tc(ndev, prio); |
| 3262 |
|
| 3263 |
prio_tc_map.input_prio = prio; |
| 3264 |
priv.data = (void *)&prio_tc_map; |
| 3265 |
rcu_read_lock(); |
| 3266 |
netdev_walk_all_lower_dev_rcu(ndev, |
| 3267 |
get_lower_vlan_dev_tc, |
| 3268 |
&priv); |
| 3269 |
rcu_read_unlock(); |
| 3270 |
/* If map is found from lower device, use it; Otherwise |
| 3271 |
* continue with the current netdevice to get priority to tc map. |
| 3272 |
*/ |
| 3273 |
if (prio_tc_map.found) |
| 3274 |
return prio_tc_map.output_tc; |
| 3275 |
else if (ndev->num_tc) |
| 3276 |
return netdev_get_prio_tc_map(ndev, prio); |
| 3277 |
else |
| 3278 |
return 0; |
| 3279 |
} |
| 3280 |
|
| 3281 |
static __be32 cma_get_roce_udp_flow_label(struct rdma_id_private *id_priv) |
| 3282 |
{ |
| 3283 |
struct sockaddr_in6 *addr6; |
| 3284 |
u16 dport, sport; |
| 3285 |
u32 hash, fl; |
| 3286 |
|
| 3287 |
addr6 = (struct sockaddr_in6 *)cma_src_addr(id_priv); |
| 3288 |
fl = be32_to_cpu(addr6->sin6_flowinfo) & IB_GRH_FLOWLABEL_MASK; |
| 3289 |
if ((cma_family(id_priv) != AF_INET6) || !fl) { |
| 3290 |
dport = be16_to_cpu(cma_port(cma_dst_addr(id_priv))); |
| 3291 |
sport = be16_to_cpu(cma_port(cma_src_addr(id_priv))); |
| 3292 |
hash = (u32)sport * 31 + dport; |
| 3293 |
fl = hash & IB_GRH_FLOWLABEL_MASK; |
| 3294 |
} |
| 3295 |
|
| 3296 |
return cpu_to_be32(fl); |
| 3297 |
} |
| 3298 |
|
| 3299 |
static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) |
| 3300 |
{ |
| 3301 |
struct rdma_route *route = &id_priv->id.route; |
| 3302 |
struct rdma_addr *addr = &route->addr; |
| 3303 |
struct cma_work *work; |
| 3304 |
int ret; |
| 3305 |
struct net_device *ndev; |
| 3306 |
|
| 3307 |
u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - |
| 3308 |
rdma_start_port(id_priv->cma_dev->device)]; |
| 3309 |
u8 tos; |
| 3310 |
|
| 3311 |
mutex_lock(&id_priv->qp_mutex); |
| 3312 |
tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; |
| 3313 |
mutex_unlock(&id_priv->qp_mutex); |
| 3314 |
|
| 3315 |
work = kzalloc_obj(*work); |
| 3316 |
if (!work) |
| 3317 |
return -ENOMEM; |
| 3318 |
|
| 3319 |
route->path_rec = kzalloc_obj(*route->path_rec); |
| 3320 |
if (!route->path_rec) { |
| 3321 |
ret = -ENOMEM; |
| 3322 |
goto err1; |
| 3323 |
} |
| 3324 |
|
| 3325 |
route->num_pri_alt_paths = 1; |
| 3326 |
|
| 3327 |
ndev = cma_iboe_set_path_rec_l2_fields(id_priv); |
| 3328 |
if (!ndev) { |
| 3329 |
ret = -ENODEV; |
| 3330 |
goto err2; |
| 3331 |
} |
| 3332 |
|
| 3333 |
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 3334 |
&route->path_rec->sgid); |
| 3335 |
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, |
| 3336 |
&route->path_rec->dgid); |
| 3337 |
|
| 3338 |
if (((struct sockaddr *)&id_priv->id.route.addr.dst_addr)->sa_family != AF_IB) |
| 3339 |
/* TODO: get the hoplimit from the inet/inet6 device */ |
| 3340 |
route->path_rec->hop_limit = addr->dev_addr.hoplimit; |
| 3341 |
else |
| 3342 |
route->path_rec->hop_limit = 1; |
| 3343 |
route->path_rec->reversible = 1; |
| 3344 |
route->path_rec->pkey = cpu_to_be16(0xffff); |
| 3345 |
route->path_rec->mtu_selector = IB_SA_EQ; |
| 3346 |
route->path_rec->sl = iboe_tos_to_sl(ndev, tos); |
| 3347 |
route->path_rec->traffic_class = tos; |
| 3348 |
route->path_rec->mtu = iboe_get_mtu(ndev->mtu); |
| 3349 |
route->path_rec->rate_selector = IB_SA_EQ; |
| 3350 |
route->path_rec->rate = IB_RATE_PORT_CURRENT; |
| 3351 |
dev_put(ndev); |
| 3352 |
route->path_rec->packet_life_time_selector = IB_SA_EQ; |
| 3353 |
/* In case ACK timeout is set, use this value to calculate |
| 3354 |
* PacketLifeTime. As per IBTA 12.7.34, |
| 3355 |
* local ACK timeout = (2 * PacketLifeTime + Local CA’s ACK delay). |
| 3356 |
* Assuming a negligible local ACK delay, we can use |
| 3357 |
* PacketLifeTime = local ACK timeout/2 |
| 3358 |
* as a reasonable approximation for RoCE networks. |
| 3359 |
*/ |
| 3360 |
mutex_lock(&id_priv->qp_mutex); |
| 3361 |
if (id_priv->timeout_set && id_priv->timeout) |
| 3362 |
route->path_rec->packet_life_time = id_priv->timeout - 1; |
| 3363 |
else |
| 3364 |
route->path_rec->packet_life_time = CMA_IBOE_PACKET_LIFETIME; |
| 3365 |
mutex_unlock(&id_priv->qp_mutex); |
| 3366 |
|
| 3367 |
if (!route->path_rec->mtu) { |
| 3368 |
ret = -EINVAL; |
| 3369 |
goto err2; |
| 3370 |
} |
| 3371 |
|
| 3372 |
if (rdma_protocol_roce_udp_encap(id_priv->id.device, |
| 3373 |
id_priv->id.port_num)) |
| 3374 |
route->path_rec->flow_label = |
| 3375 |
cma_get_roce_udp_flow_label(id_priv); |
| 3376 |
|
| 3377 |
cma_init_resolve_route_work(work, id_priv); |
| 3378 |
queue_work(cma_wq, &work->work); |
| 3379 |
|
| 3380 |
return 0; |
| 3381 |
|
| 3382 |
err2: |
| 3383 |
kfree(route->path_rec); |
| 3384 |
route->path_rec = NULL; |
| 3385 |
route->num_pri_alt_paths = 0; |
| 3386 |
err1: |
| 3387 |
kfree(work); |
| 3388 |
return ret; |
| 3389 |
} |
| 3390 |
|
| 3391 |
int rdma_resolve_route(struct rdma_cm_id *id, unsigned long timeout_ms) |
| 3392 |
{ |
| 3393 |
struct rdma_id_private *id_priv; |
| 3394 |
enum rdma_cm_state state; |
| 3395 |
int ret; |
| 3396 |
|
| 3397 |
if (!timeout_ms) |
| 3398 |
return -EINVAL; |
| 3399 |
|
| 3400 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 3401 |
state = id_priv->state; |
| 3402 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, |
| 3403 |
RDMA_CM_ROUTE_QUERY) && |
| 3404 |
!cma_comp_exch(id_priv, RDMA_CM_ADDRINFO_RESOLVED, |
| 3405 |
RDMA_CM_ROUTE_QUERY)) |
| 3406 |
return -EINVAL; |
| 3407 |
|
| 3408 |
cma_id_get(id_priv); |
| 3409 |
if (rdma_cap_ib_sa(id->device, id->port_num)) |
| 3410 |
ret = cma_resolve_ib_route(id_priv, timeout_ms); |
| 3411 |
else if (rdma_protocol_roce(id->device, id->port_num)) { |
| 3412 |
ret = cma_resolve_iboe_route(id_priv); |
| 3413 |
if (!ret) |
| 3414 |
cma_add_id_to_tree(id_priv); |
| 3415 |
} |
| 3416 |
else if (rdma_protocol_iwarp(id->device, id->port_num)) |
| 3417 |
ret = cma_resolve_iw_route(id_priv); |
| 3418 |
else |
| 3419 |
ret = -ENOSYS; |
| 3420 |
|
| 3421 |
if (ret) |
| 3422 |
goto err; |
| 3423 |
|
| 3424 |
return 0; |
| 3425 |
err: |
| 3426 |
cma_comp_exch(id_priv, RDMA_CM_ROUTE_QUERY, state); |
| 3427 |
cma_id_put(id_priv); |
| 3428 |
return ret; |
| 3429 |
} |
| 3430 |
EXPORT_SYMBOL(rdma_resolve_route); |
| 3431 |
|
| 3432 |
static void cma_set_loopback(struct sockaddr *addr) |
| 3433 |
{ |
| 3434 |
switch (addr->sa_family) { |
| 3435 |
case AF_INET: |
| 3436 |
((struct sockaddr_in *) addr)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
| 3437 |
break; |
| 3438 |
case AF_INET6: |
| 3439 |
ipv6_addr_set(&((struct sockaddr_in6 *) addr)->sin6_addr, |
| 3440 |
0, 0, 0, htonl(1)); |
| 3441 |
break; |
| 3442 |
default: |
| 3443 |
ib_addr_set(&((struct sockaddr_ib *) addr)->sib_addr, |
| 3444 |
0, 0, 0, htonl(1)); |
| 3445 |
break; |
| 3446 |
} |
| 3447 |
} |
| 3448 |
|
| 3449 |
static int cma_bind_loopback(struct rdma_id_private *id_priv) |
| 3450 |
{ |
| 3451 |
struct cma_device *cma_dev, *cur_dev; |
| 3452 |
union ib_gid gid; |
| 3453 |
enum ib_port_state port_state; |
| 3454 |
unsigned int p; |
| 3455 |
u16 pkey; |
| 3456 |
int ret; |
| 3457 |
|
| 3458 |
cma_dev = NULL; |
| 3459 |
mutex_lock(&lock); |
| 3460 |
list_for_each_entry(cur_dev, &dev_list, list) { |
| 3461 |
if (cma_family(id_priv) == AF_IB && |
| 3462 |
!rdma_cap_ib_cm(cur_dev->device, 1)) |
| 3463 |
continue; |
| 3464 |
|
| 3465 |
if (!cma_dev) |
| 3466 |
cma_dev = cur_dev; |
| 3467 |
|
| 3468 |
rdma_for_each_port (cur_dev->device, p) { |
| 3469 |
if (!ib_get_cached_port_state(cur_dev->device, p, &port_state) && |
| 3470 |
port_state == IB_PORT_ACTIVE) { |
| 3471 |
cma_dev = cur_dev; |
| 3472 |
goto port_found; |
| 3473 |
} |
| 3474 |
} |
| 3475 |
} |
| 3476 |
|
| 3477 |
if (!cma_dev) { |
| 3478 |
ret = -ENODEV; |
| 3479 |
goto out; |
| 3480 |
} |
| 3481 |
|
| 3482 |
p = 1; |
| 3483 |
|
| 3484 |
port_found: |
| 3485 |
ret = rdma_query_gid(cma_dev->device, p, 0, &gid); |
| 3486 |
if (ret) |
| 3487 |
goto out; |
| 3488 |
|
| 3489 |
ret = ib_get_cached_pkey(cma_dev->device, p, 0, &pkey); |
| 3490 |
if (ret) |
| 3491 |
goto out; |
| 3492 |
|
| 3493 |
id_priv->id.route.addr.dev_addr.dev_type = |
| 3494 |
(rdma_protocol_ib(cma_dev->device, p)) ? |
| 3495 |
ARPHRD_INFINIBAND : ARPHRD_ETHER; |
| 3496 |
|
| 3497 |
rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); |
| 3498 |
ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); |
| 3499 |
id_priv->id.port_num = p; |
| 3500 |
cma_attach_to_dev(id_priv, cma_dev); |
| 3501 |
rdma_restrack_add(&id_priv->res); |
| 3502 |
cma_set_loopback(cma_src_addr(id_priv)); |
| 3503 |
out: |
| 3504 |
mutex_unlock(&lock); |
| 3505 |
return ret; |
| 3506 |
} |
| 3507 |
|
| 3508 |
static void addr_handler(int status, struct sockaddr *src_addr, |
| 3509 |
struct rdma_dev_addr *dev_addr, void *context) |
| 3510 |
{ |
| 3511 |
struct rdma_id_private *id_priv = context; |
| 3512 |
struct rdma_cm_event event = {}; |
| 3513 |
struct sockaddr *addr; |
| 3514 |
struct sockaddr_storage old_addr; |
| 3515 |
|
| 3516 |
mutex_lock(&id_priv->handler_mutex); |
| 3517 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, |
| 3518 |
RDMA_CM_ADDR_RESOLVED)) |
| 3519 |
goto out; |
| 3520 |
|
| 3521 |
/* |
| 3522 |
* Store the previous src address, so that if we fail to acquire |
| 3523 |
* matching rdma device, old address can be restored back, which helps |
| 3524 |
* to cancel the cma listen operation correctly. |
| 3525 |
*/ |
| 3526 |
addr = cma_src_addr(id_priv); |
| 3527 |
memcpy(&old_addr, addr, rdma_addr_size(addr)); |
| 3528 |
memcpy(addr, src_addr, rdma_addr_size(src_addr)); |
| 3529 |
if (!status && !id_priv->cma_dev) { |
| 3530 |
status = cma_acquire_dev_by_src_ip(id_priv); |
| 3531 |
if (status) |
| 3532 |
pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n", |
| 3533 |
status); |
| 3534 |
rdma_restrack_add(&id_priv->res); |
| 3535 |
} else if (status) { |
| 3536 |
pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to resolve IP. status %d\n", status); |
| 3537 |
} |
| 3538 |
|
| 3539 |
if (status) { |
| 3540 |
memcpy(addr, &old_addr, |
| 3541 |
rdma_addr_size((struct sockaddr *)&old_addr)); |
| 3542 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_RESOLVED, |
| 3543 |
RDMA_CM_ADDR_BOUND)) |
| 3544 |
goto out; |
| 3545 |
event.event = RDMA_CM_EVENT_ADDR_ERROR; |
| 3546 |
event.status = status; |
| 3547 |
} else |
| 3548 |
event.event = RDMA_CM_EVENT_ADDR_RESOLVED; |
| 3549 |
|
| 3550 |
if (cma_cm_event_handler(id_priv, &event)) { |
| 3551 |
destroy_id_handler_unlock(id_priv); |
| 3552 |
return; |
| 3553 |
} |
| 3554 |
out: |
| 3555 |
mutex_unlock(&id_priv->handler_mutex); |
| 3556 |
} |
| 3557 |
|
| 3558 |
static int cma_resolve_loopback(struct rdma_id_private *id_priv) |
| 3559 |
{ |
| 3560 |
struct cma_work *work; |
| 3561 |
union ib_gid gid; |
| 3562 |
int ret; |
| 3563 |
|
| 3564 |
work = kzalloc_obj(*work); |
| 3565 |
if (!work) |
| 3566 |
return -ENOMEM; |
| 3567 |
|
| 3568 |
if (!id_priv->cma_dev) { |
| 3569 |
ret = cma_bind_loopback(id_priv); |
| 3570 |
if (ret) |
| 3571 |
goto err; |
| 3572 |
} |
| 3573 |
|
| 3574 |
rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); |
| 3575 |
rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); |
| 3576 |
|
| 3577 |
enqueue_resolve_addr_work(work, id_priv); |
| 3578 |
return 0; |
| 3579 |
err: |
| 3580 |
kfree(work); |
| 3581 |
return ret; |
| 3582 |
} |
| 3583 |
|
| 3584 |
static int cma_resolve_ib_addr(struct rdma_id_private *id_priv) |
| 3585 |
{ |
| 3586 |
struct cma_work *work; |
| 3587 |
int ret; |
| 3588 |
|
| 3589 |
work = kzalloc_obj(*work); |
| 3590 |
if (!work) |
| 3591 |
return -ENOMEM; |
| 3592 |
|
| 3593 |
if (!id_priv->cma_dev) { |
| 3594 |
ret = cma_resolve_ib_dev(id_priv); |
| 3595 |
if (ret) |
| 3596 |
goto err; |
| 3597 |
} |
| 3598 |
|
| 3599 |
rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) |
| 3600 |
&(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); |
| 3601 |
|
| 3602 |
enqueue_resolve_addr_work(work, id_priv); |
| 3603 |
return 0; |
| 3604 |
err: |
| 3605 |
kfree(work); |
| 3606 |
return ret; |
| 3607 |
} |
| 3608 |
|
| 3609 |
int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse) |
| 3610 |
{ |
| 3611 |
struct rdma_id_private *id_priv; |
| 3612 |
unsigned long flags; |
| 3613 |
int ret; |
| 3614 |
|
| 3615 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 3616 |
spin_lock_irqsave(&id_priv->lock, flags); |
| 3617 |
if ((reuse && id_priv->state != RDMA_CM_LISTEN) || |
| 3618 |
id_priv->state == RDMA_CM_IDLE) { |
| 3619 |
id_priv->reuseaddr = reuse; |
| 3620 |
ret = 0; |
| 3621 |
} else { |
| 3622 |
ret = -EINVAL; |
| 3623 |
} |
| 3624 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 3625 |
return ret; |
| 3626 |
} |
| 3627 |
EXPORT_SYMBOL(rdma_set_reuseaddr); |
| 3628 |
|
| 3629 |
int rdma_set_afonly(struct rdma_cm_id *id, int afonly) |
| 3630 |
{ |
| 3631 |
struct rdma_id_private *id_priv; |
| 3632 |
unsigned long flags; |
| 3633 |
int ret; |
| 3634 |
|
| 3635 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 3636 |
spin_lock_irqsave(&id_priv->lock, flags); |
| 3637 |
if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) { |
| 3638 |
id_priv->options |= (1 << CMA_OPTION_AFONLY); |
| 3639 |
id_priv->afonly = afonly; |
| 3640 |
ret = 0; |
| 3641 |
} else { |
| 3642 |
ret = -EINVAL; |
| 3643 |
} |
| 3644 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 3645 |
return ret; |
| 3646 |
} |
| 3647 |
EXPORT_SYMBOL(rdma_set_afonly); |
| 3648 |
|
| 3649 |
static void cma_bind_port(struct rdma_bind_list *bind_list, |
| 3650 |
struct rdma_id_private *id_priv) |
| 3651 |
{ |
| 3652 |
struct sockaddr *addr; |
| 3653 |
struct sockaddr_ib *sib; |
| 3654 |
u64 sid, mask; |
| 3655 |
__be16 port; |
| 3656 |
|
| 3657 |
lockdep_assert_held(&lock); |
| 3658 |
|
| 3659 |
addr = cma_src_addr(id_priv); |
| 3660 |
port = htons(bind_list->port); |
| 3661 |
|
| 3662 |
switch (addr->sa_family) { |
| 3663 |
case AF_INET: |
| 3664 |
((struct sockaddr_in *) addr)->sin_port = port; |
| 3665 |
break; |
| 3666 |
case AF_INET6: |
| 3667 |
((struct sockaddr_in6 *) addr)->sin6_port = port; |
| 3668 |
break; |
| 3669 |
case AF_IB: |
| 3670 |
sib = (struct sockaddr_ib *) addr; |
| 3671 |
sid = be64_to_cpu(sib->sib_sid); |
| 3672 |
mask = be64_to_cpu(sib->sib_sid_mask); |
| 3673 |
sib->sib_sid = cpu_to_be64((sid & mask) | (u64) ntohs(port)); |
| 3674 |
sib->sib_sid_mask = cpu_to_be64(~0ULL); |
| 3675 |
break; |
| 3676 |
} |
| 3677 |
id_priv->bind_list = bind_list; |
| 3678 |
hlist_add_head(&id_priv->node, &bind_list->owners); |
| 3679 |
} |
| 3680 |
|
| 3681 |
static int cma_alloc_port(enum rdma_ucm_port_space ps, |
| 3682 |
struct rdma_id_private *id_priv, unsigned short snum) |
| 3683 |
{ |
| 3684 |
struct rdma_bind_list *bind_list; |
| 3685 |
int ret; |
| 3686 |
|
| 3687 |
lockdep_assert_held(&lock); |
| 3688 |
|
| 3689 |
bind_list = kzalloc_obj(*bind_list); |
| 3690 |
if (!bind_list) |
| 3691 |
return -ENOMEM; |
| 3692 |
|
| 3693 |
ret = cma_ps_alloc(id_priv->id.route.addr.dev_addr.net, ps, bind_list, |
| 3694 |
snum); |
| 3695 |
if (ret < 0) |
| 3696 |
goto err; |
| 3697 |
|
| 3698 |
bind_list->ps = ps; |
| 3699 |
bind_list->port = snum; |
| 3700 |
cma_bind_port(bind_list, id_priv); |
| 3701 |
return 0; |
| 3702 |
err: |
| 3703 |
kfree(bind_list); |
| 3704 |
return ret == -ENOSPC ? -EADDRNOTAVAIL : ret; |
| 3705 |
} |
| 3706 |
|
| 3707 |
static int cma_port_is_unique(struct rdma_bind_list *bind_list, |
| 3708 |
struct rdma_id_private *id_priv) |
| 3709 |
{ |
| 3710 |
struct rdma_id_private *cur_id; |
| 3711 |
struct sockaddr *daddr = cma_dst_addr(id_priv); |
| 3712 |
struct sockaddr *saddr = cma_src_addr(id_priv); |
| 3713 |
__be16 dport = cma_port(daddr); |
| 3714 |
|
| 3715 |
lockdep_assert_held(&lock); |
| 3716 |
|
| 3717 |
hlist_for_each_entry(cur_id, &bind_list->owners, node) { |
| 3718 |
struct sockaddr *cur_daddr = cma_dst_addr(cur_id); |
| 3719 |
struct sockaddr *cur_saddr = cma_src_addr(cur_id); |
| 3720 |
__be16 cur_dport = cma_port(cur_daddr); |
| 3721 |
|
| 3722 |
if (id_priv == cur_id) |
| 3723 |
continue; |
| 3724 |
|
| 3725 |
/* different dest port -> unique */ |
| 3726 |
if (!cma_any_port(daddr) && |
| 3727 |
!cma_any_port(cur_daddr) && |
| 3728 |
(dport != cur_dport)) |
| 3729 |
continue; |
| 3730 |
|
| 3731 |
/* different src address -> unique */ |
| 3732 |
if (!cma_any_addr(saddr) && |
| 3733 |
!cma_any_addr(cur_saddr) && |
| 3734 |
cma_addr_cmp(saddr, cur_saddr)) |
| 3735 |
continue; |
| 3736 |
|
| 3737 |
/* different dst address -> unique */ |
| 3738 |
if (!cma_any_addr(daddr) && |
| 3739 |
!cma_any_addr(cur_daddr) && |
| 3740 |
cma_addr_cmp(daddr, cur_daddr)) |
| 3741 |
continue; |
| 3742 |
|
| 3743 |
return -EADDRNOTAVAIL; |
| 3744 |
} |
| 3745 |
return 0; |
| 3746 |
} |
| 3747 |
|
| 3748 |
static int cma_alloc_any_port(enum rdma_ucm_port_space ps, |
| 3749 |
struct rdma_id_private *id_priv) |
| 3750 |
{ |
| 3751 |
static unsigned int last_used_port; |
| 3752 |
int low, high, remaining; |
| 3753 |
unsigned int rover; |
| 3754 |
struct net *net = id_priv->id.route.addr.dev_addr.net; |
| 3755 |
|
| 3756 |
lockdep_assert_held(&lock); |
| 3757 |
|
| 3758 |
inet_get_local_port_range(net, &low, &high); |
| 3759 |
remaining = (high - low) + 1; |
| 3760 |
rover = get_random_u32_inclusive(low, remaining + low - 1); |
| 3761 |
retry: |
| 3762 |
if (last_used_port != rover) { |
| 3763 |
struct rdma_bind_list *bind_list; |
| 3764 |
int ret; |
| 3765 |
|
| 3766 |
bind_list = cma_ps_find(net, ps, (unsigned short)rover); |
| 3767 |
|
| 3768 |
if (!bind_list) { |
| 3769 |
ret = cma_alloc_port(ps, id_priv, rover); |
| 3770 |
} else { |
| 3771 |
ret = cma_port_is_unique(bind_list, id_priv); |
| 3772 |
if (!ret) |
| 3773 |
cma_bind_port(bind_list, id_priv); |
| 3774 |
} |
| 3775 |
/* |
| 3776 |
* Remember previously used port number in order to avoid |
| 3777 |
* re-using same port immediately after it is closed. |
| 3778 |
*/ |
| 3779 |
if (!ret) |
| 3780 |
last_used_port = rover; |
| 3781 |
if (ret != -EADDRNOTAVAIL) |
| 3782 |
return ret; |
| 3783 |
} |
| 3784 |
if (--remaining) { |
| 3785 |
rover++; |
| 3786 |
if ((rover < low) || (rover > high)) |
| 3787 |
rover = low; |
| 3788 |
goto retry; |
| 3789 |
} |
| 3790 |
return -EADDRNOTAVAIL; |
| 3791 |
} |
| 3792 |
|
| 3793 |
/* |
| 3794 |
* Check that the requested port is available. This is called when trying to |
| 3795 |
* bind to a specific port, or when trying to listen on a bound port. In |
| 3796 |
* the latter case, the provided id_priv may already be on the bind_list, but |
| 3797 |
* we still need to check that it's okay to start listening. |
| 3798 |
*/ |
| 3799 |
static int cma_check_port(struct rdma_bind_list *bind_list, |
| 3800 |
struct rdma_id_private *id_priv, uint8_t reuseaddr) |
| 3801 |
{ |
| 3802 |
struct rdma_id_private *cur_id; |
| 3803 |
struct sockaddr *addr, *cur_addr; |
| 3804 |
|
| 3805 |
lockdep_assert_held(&lock); |
| 3806 |
|
| 3807 |
addr = cma_src_addr(id_priv); |
| 3808 |
hlist_for_each_entry(cur_id, &bind_list->owners, node) { |
| 3809 |
if (id_priv == cur_id) |
| 3810 |
continue; |
| 3811 |
|
| 3812 |
if (reuseaddr && cur_id->reuseaddr) |
| 3813 |
continue; |
| 3814 |
|
| 3815 |
cur_addr = cma_src_addr(cur_id); |
| 3816 |
if (id_priv->afonly && cur_id->afonly && |
| 3817 |
(addr->sa_family != cur_addr->sa_family)) |
| 3818 |
continue; |
| 3819 |
|
| 3820 |
if (cma_any_addr(addr) || cma_any_addr(cur_addr)) |
| 3821 |
return -EADDRNOTAVAIL; |
| 3822 |
|
| 3823 |
if (!cma_addr_cmp(addr, cur_addr)) |
| 3824 |
return -EADDRINUSE; |
| 3825 |
} |
| 3826 |
return 0; |
| 3827 |
} |
| 3828 |
|
| 3829 |
static int cma_use_port(enum rdma_ucm_port_space ps, |
| 3830 |
struct rdma_id_private *id_priv) |
| 3831 |
{ |
| 3832 |
struct rdma_bind_list *bind_list; |
| 3833 |
unsigned short snum; |
| 3834 |
int ret; |
| 3835 |
|
| 3836 |
lockdep_assert_held(&lock); |
| 3837 |
|
| 3838 |
snum = ntohs(cma_port(cma_src_addr(id_priv))); |
| 3839 |
if (snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) |
| 3840 |
return -EACCES; |
| 3841 |
|
| 3842 |
bind_list = cma_ps_find(id_priv->id.route.addr.dev_addr.net, ps, snum); |
| 3843 |
if (!bind_list) { |
| 3844 |
ret = cma_alloc_port(ps, id_priv, snum); |
| 3845 |
} else { |
| 3846 |
ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); |
| 3847 |
if (!ret) |
| 3848 |
cma_bind_port(bind_list, id_priv); |
| 3849 |
} |
| 3850 |
return ret; |
| 3851 |
} |
| 3852 |
|
| 3853 |
static enum rdma_ucm_port_space |
| 3854 |
cma_select_inet_ps(struct rdma_id_private *id_priv) |
| 3855 |
{ |
| 3856 |
switch (id_priv->id.ps) { |
| 3857 |
case RDMA_PS_TCP: |
| 3858 |
case RDMA_PS_UDP: |
| 3859 |
case RDMA_PS_IPOIB: |
| 3860 |
case RDMA_PS_IB: |
| 3861 |
return id_priv->id.ps; |
| 3862 |
default: |
| 3863 |
|
| 3864 |
return 0; |
| 3865 |
} |
| 3866 |
} |
| 3867 |
|
| 3868 |
static enum rdma_ucm_port_space |
| 3869 |
cma_select_ib_ps(struct rdma_id_private *id_priv) |
| 3870 |
{ |
| 3871 |
enum rdma_ucm_port_space ps = 0; |
| 3872 |
struct sockaddr_ib *sib; |
| 3873 |
u64 sid_ps, mask, sid; |
| 3874 |
|
| 3875 |
sib = (struct sockaddr_ib *) cma_src_addr(id_priv); |
| 3876 |
mask = be64_to_cpu(sib->sib_sid_mask) & RDMA_IB_IP_PS_MASK; |
| 3877 |
sid = be64_to_cpu(sib->sib_sid) & mask; |
| 3878 |
|
| 3879 |
if ((id_priv->id.ps == RDMA_PS_IB) && (sid == (RDMA_IB_IP_PS_IB & mask))) { |
| 3880 |
sid_ps = RDMA_IB_IP_PS_IB; |
| 3881 |
ps = RDMA_PS_IB; |
| 3882 |
} else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_TCP)) && |
| 3883 |
(sid == (RDMA_IB_IP_PS_TCP & mask))) { |
| 3884 |
sid_ps = RDMA_IB_IP_PS_TCP; |
| 3885 |
ps = RDMA_PS_TCP; |
| 3886 |
} else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_UDP)) && |
| 3887 |
(sid == (RDMA_IB_IP_PS_UDP & mask))) { |
| 3888 |
sid_ps = RDMA_IB_IP_PS_UDP; |
| 3889 |
ps = RDMA_PS_UDP; |
| 3890 |
} |
| 3891 |
|
| 3892 |
if (ps) { |
| 3893 |
sib->sib_sid = cpu_to_be64(sid_ps | ntohs(cma_port((struct sockaddr *) sib))); |
| 3894 |
sib->sib_sid_mask = cpu_to_be64(RDMA_IB_IP_PS_MASK | |
| 3895 |
be64_to_cpu(sib->sib_sid_mask)); |
| 3896 |
} |
| 3897 |
return ps; |
| 3898 |
} |
| 3899 |
|
| 3900 |
static int cma_get_port(struct rdma_id_private *id_priv) |
| 3901 |
{ |
| 3902 |
enum rdma_ucm_port_space ps; |
| 3903 |
int ret; |
| 3904 |
|
| 3905 |
if (cma_family(id_priv) != AF_IB) |
| 3906 |
ps = cma_select_inet_ps(id_priv); |
| 3907 |
else |
| 3908 |
ps = cma_select_ib_ps(id_priv); |
| 3909 |
if (!ps) |
| 3910 |
return -EPROTONOSUPPORT; |
| 3911 |
|
| 3912 |
mutex_lock(&lock); |
| 3913 |
if (cma_any_port(cma_src_addr(id_priv))) |
| 3914 |
ret = cma_alloc_any_port(ps, id_priv); |
| 3915 |
else |
| 3916 |
ret = cma_use_port(ps, id_priv); |
| 3917 |
mutex_unlock(&lock); |
| 3918 |
|
| 3919 |
return ret; |
| 3920 |
} |
| 3921 |
|
| 3922 |
static int cma_check_linklocal(struct rdma_dev_addr *dev_addr, |
| 3923 |
struct sockaddr *addr) |
| 3924 |
{ |
| 3925 |
#if IS_ENABLED(CONFIG_IPV6) |
| 3926 |
struct sockaddr_in6 *sin6; |
| 3927 |
|
| 3928 |
if (addr->sa_family != AF_INET6) |
| 3929 |
return 0; |
| 3930 |
|
| 3931 |
sin6 = (struct sockaddr_in6 *) addr; |
| 3932 |
|
| 3933 |
if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) |
| 3934 |
return 0; |
| 3935 |
|
| 3936 |
if (!sin6->sin6_scope_id) |
| 3937 |
return -EINVAL; |
| 3938 |
|
| 3939 |
dev_addr->bound_dev_if = sin6->sin6_scope_id; |
| 3940 |
#endif |
| 3941 |
return 0; |
| 3942 |
} |
| 3943 |
|
| 3944 |
int rdma_listen(struct rdma_cm_id *id, int backlog) |
| 3945 |
{ |
| 3946 |
struct rdma_id_private *id_priv = |
| 3947 |
container_of(id, struct rdma_id_private, id); |
| 3948 |
int ret; |
| 3949 |
|
| 3950 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_LISTEN)) { |
| 3951 |
struct sockaddr_in any_in = { |
| 3952 |
.sin_family = AF_INET, |
| 3953 |
.sin_addr.s_addr = htonl(INADDR_ANY), |
| 3954 |
}; |
| 3955 |
|
| 3956 |
/* For a well behaved ULP state will be RDMA_CM_IDLE */ |
| 3957 |
ret = rdma_bind_addr(id, (struct sockaddr *)&any_in); |
| 3958 |
if (ret) |
| 3959 |
return ret; |
| 3960 |
if (WARN_ON(!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, |
| 3961 |
RDMA_CM_LISTEN))) |
| 3962 |
return -EINVAL; |
| 3963 |
} |
| 3964 |
|
| 3965 |
/* |
| 3966 |
* Once the ID reaches RDMA_CM_LISTEN it is not allowed to be reusable |
| 3967 |
* any more, and has to be unique in the bind list. |
| 3968 |
*/ |
| 3969 |
if (id_priv->reuseaddr) { |
| 3970 |
mutex_lock(&lock); |
| 3971 |
ret = cma_check_port(id_priv->bind_list, id_priv, 0); |
| 3972 |
if (!ret) |
| 3973 |
id_priv->reuseaddr = 0; |
| 3974 |
mutex_unlock(&lock); |
| 3975 |
if (ret) |
| 3976 |
goto err; |
| 3977 |
} |
| 3978 |
|
| 3979 |
id_priv->backlog = backlog; |
| 3980 |
if (id_priv->cma_dev) { |
| 3981 |
if (rdma_cap_ib_cm(id->device, 1)) { |
| 3982 |
ret = cma_ib_listen(id_priv); |
| 3983 |
if (ret) |
| 3984 |
goto err; |
| 3985 |
} else if (rdma_cap_iw_cm(id->device, 1)) { |
| 3986 |
ret = cma_iw_listen(id_priv, backlog); |
| 3987 |
if (ret) |
| 3988 |
goto err; |
| 3989 |
} else { |
| 3990 |
ret = -ENOSYS; |
| 3991 |
goto err; |
| 3992 |
} |
| 3993 |
} else { |
| 3994 |
ret = cma_listen_on_all(id_priv); |
| 3995 |
if (ret) |
| 3996 |
goto err; |
| 3997 |
} |
| 3998 |
|
| 3999 |
return 0; |
| 4000 |
err: |
| 4001 |
id_priv->backlog = 0; |
| 4002 |
/* |
| 4003 |
* All the failure paths that lead here will not allow the req_handler's |
| 4004 |
* to have run. |
| 4005 |
*/ |
| 4006 |
cma_comp_exch(id_priv, RDMA_CM_LISTEN, RDMA_CM_ADDR_BOUND); |
| 4007 |
return ret; |
| 4008 |
} |
| 4009 |
EXPORT_SYMBOL(rdma_listen); |
| 4010 |
|
| 4011 |
static int rdma_bind_addr_dst(struct rdma_id_private *id_priv, |
| 4012 |
struct sockaddr *addr, const struct sockaddr *daddr) |
| 4013 |
{ |
| 4014 |
struct sockaddr *id_daddr; |
| 4015 |
int ret; |
| 4016 |
|
| 4017 |
if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6 && |
| 4018 |
addr->sa_family != AF_IB) |
| 4019 |
return -EAFNOSUPPORT; |
| 4020 |
|
| 4021 |
if (!cma_comp_exch(id_priv, RDMA_CM_IDLE, RDMA_CM_ADDR_BOUND)) |
| 4022 |
return -EINVAL; |
| 4023 |
|
| 4024 |
ret = cma_check_linklocal(&id_priv->id.route.addr.dev_addr, addr); |
| 4025 |
if (ret) |
| 4026 |
goto err1; |
| 4027 |
|
| 4028 |
memcpy(cma_src_addr(id_priv), addr, rdma_addr_size(addr)); |
| 4029 |
if (!cma_any_addr(addr)) { |
| 4030 |
ret = cma_translate_addr(addr, &id_priv->id.route.addr.dev_addr); |
| 4031 |
if (ret) |
| 4032 |
goto err1; |
| 4033 |
|
| 4034 |
ret = cma_acquire_dev_by_src_ip(id_priv); |
| 4035 |
if (ret) |
| 4036 |
goto err1; |
| 4037 |
} |
| 4038 |
|
| 4039 |
if (!(id_priv->options & (1 << CMA_OPTION_AFONLY))) { |
| 4040 |
if (addr->sa_family == AF_INET) |
| 4041 |
id_priv->afonly = 1; |
| 4042 |
#if IS_ENABLED(CONFIG_IPV6) |
| 4043 |
else if (addr->sa_family == AF_INET6) { |
| 4044 |
struct net *net = id_priv->id.route.addr.dev_addr.net; |
| 4045 |
|
| 4046 |
id_priv->afonly = net->ipv6.sysctl.bindv6only; |
| 4047 |
} |
| 4048 |
#endif |
| 4049 |
} |
| 4050 |
id_daddr = cma_dst_addr(id_priv); |
| 4051 |
if (daddr != id_daddr) |
| 4052 |
memcpy(id_daddr, daddr, rdma_addr_size(addr)); |
| 4053 |
id_daddr->sa_family = addr->sa_family; |
| 4054 |
|
| 4055 |
ret = cma_get_port(id_priv); |
| 4056 |
if (ret) |
| 4057 |
goto err2; |
| 4058 |
|
| 4059 |
if (!cma_any_addr(addr)) |
| 4060 |
rdma_restrack_add(&id_priv->res); |
| 4061 |
return 0; |
| 4062 |
err2: |
| 4063 |
if (id_priv->cma_dev) |
| 4064 |
cma_release_dev(id_priv); |
| 4065 |
err1: |
| 4066 |
cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_IDLE); |
| 4067 |
return ret; |
| 4068 |
} |
| 4069 |
|
| 4070 |
static int cma_bind_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, |
| 4071 |
const struct sockaddr *dst_addr) |
| 4072 |
{ |
| 4073 |
struct rdma_id_private *id_priv = |
| 4074 |
container_of(id, struct rdma_id_private, id); |
| 4075 |
struct sockaddr_storage zero_sock = {}; |
| 4076 |
|
| 4077 |
if (src_addr && src_addr->sa_family) |
| 4078 |
return rdma_bind_addr_dst(id_priv, src_addr, dst_addr); |
| 4079 |
|
| 4080 |
/* |
| 4081 |
* When the src_addr is not specified, automatically supply an any addr |
| 4082 |
*/ |
| 4083 |
zero_sock.ss_family = dst_addr->sa_family; |
| 4084 |
if (IS_ENABLED(CONFIG_IPV6) && dst_addr->sa_family == AF_INET6) { |
| 4085 |
struct sockaddr_in6 *src_addr6 = |
| 4086 |
(struct sockaddr_in6 *)&zero_sock; |
| 4087 |
struct sockaddr_in6 *dst_addr6 = |
| 4088 |
(struct sockaddr_in6 *)dst_addr; |
| 4089 |
|
| 4090 |
src_addr6->sin6_scope_id = dst_addr6->sin6_scope_id; |
| 4091 |
if (ipv6_addr_type(&dst_addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
| 4092 |
id->route.addr.dev_addr.bound_dev_if = |
| 4093 |
dst_addr6->sin6_scope_id; |
| 4094 |
} else if (dst_addr->sa_family == AF_IB) { |
| 4095 |
((struct sockaddr_ib *)&zero_sock)->sib_pkey = |
| 4096 |
((struct sockaddr_ib *)dst_addr)->sib_pkey; |
| 4097 |
} |
| 4098 |
return rdma_bind_addr_dst(id_priv, (struct sockaddr *)&zero_sock, dst_addr); |
| 4099 |
} |
| 4100 |
|
| 4101 |
/* |
| 4102 |
* If required, resolve the source address for bind and leave the id_priv in |
| 4103 |
* state RDMA_CM_ADDR_BOUND. This oddly uses the state to determine the prior |
| 4104 |
* calls made by ULP, a previously bound ID will not be re-bound and src_addr is |
| 4105 |
* ignored. |
| 4106 |
*/ |
| 4107 |
static int resolve_prepare_src(struct rdma_id_private *id_priv, |
| 4108 |
struct sockaddr *src_addr, |
| 4109 |
const struct sockaddr *dst_addr) |
| 4110 |
{ |
| 4111 |
int ret; |
| 4112 |
|
| 4113 |
if (!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_ADDR_QUERY)) { |
| 4114 |
/* For a well behaved ULP state will be RDMA_CM_IDLE */ |
| 4115 |
ret = cma_bind_addr(&id_priv->id, src_addr, dst_addr); |
| 4116 |
if (ret) |
| 4117 |
return ret; |
| 4118 |
if (WARN_ON(!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, |
| 4119 |
RDMA_CM_ADDR_QUERY))) |
| 4120 |
return -EINVAL; |
| 4121 |
|
| 4122 |
} else { |
| 4123 |
memcpy(cma_dst_addr(id_priv), dst_addr, rdma_addr_size(dst_addr)); |
| 4124 |
} |
| 4125 |
|
| 4126 |
if (cma_family(id_priv) != dst_addr->sa_family) { |
| 4127 |
ret = -EINVAL; |
| 4128 |
goto err_state; |
| 4129 |
} |
| 4130 |
return 0; |
| 4131 |
|
| 4132 |
err_state: |
| 4133 |
cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, RDMA_CM_ADDR_BOUND); |
| 4134 |
return ret; |
| 4135 |
} |
| 4136 |
|
| 4137 |
int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, |
| 4138 |
const struct sockaddr *dst_addr, unsigned long timeout_ms) |
| 4139 |
{ |
| 4140 |
struct rdma_id_private *id_priv = |
| 4141 |
container_of(id, struct rdma_id_private, id); |
| 4142 |
int ret; |
| 4143 |
|
| 4144 |
ret = resolve_prepare_src(id_priv, src_addr, dst_addr); |
| 4145 |
if (ret) |
| 4146 |
return ret; |
| 4147 |
|
| 4148 |
if (cma_any_addr(dst_addr)) { |
| 4149 |
ret = cma_resolve_loopback(id_priv); |
| 4150 |
} else { |
| 4151 |
if (dst_addr->sa_family == AF_IB) { |
| 4152 |
ret = cma_resolve_ib_addr(id_priv); |
| 4153 |
} else { |
| 4154 |
/* |
| 4155 |
* The FSM can return back to RDMA_CM_ADDR_BOUND after |
| 4156 |
* rdma_resolve_ip() is called, eg through the error |
| 4157 |
* path in addr_handler(). If this happens the existing |
| 4158 |
* request must be canceled before issuing a new one. |
| 4159 |
* Since canceling a request is a bit slow and this |
| 4160 |
* oddball path is rare, keep track once a request has |
| 4161 |
* been issued. The track turns out to be a permanent |
| 4162 |
* state since this is the only cancel as it is |
| 4163 |
* immediately before rdma_resolve_ip(). |
| 4164 |
*/ |
| 4165 |
if (id_priv->used_resolve_ip) |
| 4166 |
rdma_addr_cancel(&id->route.addr.dev_addr); |
| 4167 |
else |
| 4168 |
id_priv->used_resolve_ip = 1; |
| 4169 |
ret = rdma_resolve_ip(cma_src_addr(id_priv), dst_addr, |
| 4170 |
&id->route.addr.dev_addr, |
| 4171 |
timeout_ms, addr_handler, |
| 4172 |
false, id_priv); |
| 4173 |
} |
| 4174 |
} |
| 4175 |
if (ret) |
| 4176 |
goto err; |
| 4177 |
|
| 4178 |
return 0; |
| 4179 |
err: |
| 4180 |
cma_comp_exch(id_priv, RDMA_CM_ADDR_QUERY, RDMA_CM_ADDR_BOUND); |
| 4181 |
return ret; |
| 4182 |
} |
| 4183 |
EXPORT_SYMBOL(rdma_resolve_addr); |
| 4184 |
|
| 4185 |
int rdma_restrict_node_type(struct rdma_cm_id *id, u8 node_type) |
| 4186 |
{ |
| 4187 |
struct rdma_id_private *id_priv = |
| 4188 |
container_of(id, struct rdma_id_private, id); |
| 4189 |
int ret = 0; |
| 4190 |
|
| 4191 |
switch (node_type) { |
| 4192 |
case RDMA_NODE_UNSPECIFIED: |
| 4193 |
case RDMA_NODE_IB_CA: |
| 4194 |
case RDMA_NODE_RNIC: |
| 4195 |
break; |
| 4196 |
default: |
| 4197 |
return -EINVAL; |
| 4198 |
} |
| 4199 |
|
| 4200 |
mutex_lock(&lock); |
| 4201 |
if (READ_ONCE(id_priv->state) != RDMA_CM_IDLE) |
| 4202 |
ret = -EALREADY; |
| 4203 |
else |
| 4204 |
id_priv->restricted_node_type = node_type; |
| 4205 |
mutex_unlock(&lock); |
| 4206 |
|
| 4207 |
return ret; |
| 4208 |
} |
| 4209 |
EXPORT_SYMBOL(rdma_restrict_node_type); |
| 4210 |
|
| 4211 |
int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) |
| 4212 |
{ |
| 4213 |
struct rdma_id_private *id_priv = |
| 4214 |
container_of(id, struct rdma_id_private, id); |
| 4215 |
|
| 4216 |
return rdma_bind_addr_dst(id_priv, addr, cma_dst_addr(id_priv)); |
| 4217 |
} |
| 4218 |
EXPORT_SYMBOL(rdma_bind_addr); |
| 4219 |
|
| 4220 |
static int cma_format_hdr(void *hdr, struct rdma_id_private *id_priv) |
| 4221 |
{ |
| 4222 |
struct cma_hdr *cma_hdr; |
| 4223 |
|
| 4224 |
cma_hdr = hdr; |
| 4225 |
cma_hdr->cma_version = CMA_VERSION; |
| 4226 |
if (cma_family(id_priv) == AF_INET) { |
| 4227 |
struct sockaddr_in *src4, *dst4; |
| 4228 |
|
| 4229 |
src4 = (struct sockaddr_in *) cma_src_addr(id_priv); |
| 4230 |
dst4 = (struct sockaddr_in *) cma_dst_addr(id_priv); |
| 4231 |
|
| 4232 |
cma_set_ip_ver(cma_hdr, 4); |
| 4233 |
cma_hdr->src_addr.ip4.addr = src4->sin_addr.s_addr; |
| 4234 |
cma_hdr->dst_addr.ip4.addr = dst4->sin_addr.s_addr; |
| 4235 |
cma_hdr->port = src4->sin_port; |
| 4236 |
} else if (cma_family(id_priv) == AF_INET6) { |
| 4237 |
struct sockaddr_in6 *src6, *dst6; |
| 4238 |
|
| 4239 |
src6 = (struct sockaddr_in6 *) cma_src_addr(id_priv); |
| 4240 |
dst6 = (struct sockaddr_in6 *) cma_dst_addr(id_priv); |
| 4241 |
|
| 4242 |
cma_set_ip_ver(cma_hdr, 6); |
| 4243 |
cma_hdr->src_addr.ip6 = src6->sin6_addr; |
| 4244 |
cma_hdr->dst_addr.ip6 = dst6->sin6_addr; |
| 4245 |
cma_hdr->port = src6->sin6_port; |
| 4246 |
} |
| 4247 |
return 0; |
| 4248 |
} |
| 4249 |
|
| 4250 |
static int cma_sidr_rep_handler(struct ib_cm_id *cm_id, |
| 4251 |
const struct ib_cm_event *ib_event) |
| 4252 |
{ |
| 4253 |
struct rdma_id_private *id_priv = cm_id->context; |
| 4254 |
struct rdma_cm_event event = {}; |
| 4255 |
const struct ib_cm_sidr_rep_event_param *rep = |
| 4256 |
&ib_event->param.sidr_rep_rcvd; |
| 4257 |
int ret; |
| 4258 |
|
| 4259 |
mutex_lock(&id_priv->handler_mutex); |
| 4260 |
if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) |
| 4261 |
goto out; |
| 4262 |
|
| 4263 |
switch (ib_event->event) { |
| 4264 |
case IB_CM_SIDR_REQ_ERROR: |
| 4265 |
event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 4266 |
event.status = -ETIMEDOUT; |
| 4267 |
break; |
| 4268 |
case IB_CM_SIDR_REP_RECEIVED: |
| 4269 |
event.param.ud.private_data = ib_event->private_data; |
| 4270 |
event.param.ud.private_data_len = IB_CM_SIDR_REP_PRIVATE_DATA_SIZE; |
| 4271 |
if (rep->status != IB_SIDR_SUCCESS) { |
| 4272 |
event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 4273 |
event.status = ib_event->param.sidr_rep_rcvd.status; |
| 4274 |
pr_debug_ratelimited("RDMA CM: UNREACHABLE: bad SIDR reply. status %d\n", |
| 4275 |
event.status); |
| 4276 |
break; |
| 4277 |
} |
| 4278 |
ret = cma_set_qkey(id_priv, rep->qkey); |
| 4279 |
if (ret) { |
| 4280 |
pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to set qkey. status %d\n", ret); |
| 4281 |
event.event = RDMA_CM_EVENT_ADDR_ERROR; |
| 4282 |
event.status = ret; |
| 4283 |
break; |
| 4284 |
} |
| 4285 |
ib_init_ah_attr_from_path(id_priv->id.device, |
| 4286 |
id_priv->id.port_num, |
| 4287 |
id_priv->id.route.path_rec, |
| 4288 |
&event.param.ud.ah_attr, |
| 4289 |
rep->sgid_attr); |
| 4290 |
event.param.ud.qp_num = rep->qpn; |
| 4291 |
event.param.ud.qkey = rep->qkey; |
| 4292 |
event.event = RDMA_CM_EVENT_ESTABLISHED; |
| 4293 |
event.status = 0; |
| 4294 |
break; |
| 4295 |
default: |
| 4296 |
pr_err("RDMA CMA: unexpected IB CM event: %d\n", |
| 4297 |
ib_event->event); |
| 4298 |
goto out; |
| 4299 |
} |
| 4300 |
|
| 4301 |
ret = cma_cm_event_handler(id_priv, &event); |
| 4302 |
|
| 4303 |
rdma_destroy_ah_attr(&event.param.ud.ah_attr); |
| 4304 |
if (ret) { |
| 4305 |
/* Destroy the CM ID by returning a non-zero value. */ |
| 4306 |
id_priv->cm_id.ib = NULL; |
| 4307 |
destroy_id_handler_unlock(id_priv); |
| 4308 |
return ret; |
| 4309 |
} |
| 4310 |
out: |
| 4311 |
mutex_unlock(&id_priv->handler_mutex); |
| 4312 |
return 0; |
| 4313 |
} |
| 4314 |
|
| 4315 |
static int cma_resolve_ib_udp(struct rdma_id_private *id_priv, |
| 4316 |
struct rdma_conn_param *conn_param) |
| 4317 |
{ |
| 4318 |
struct ib_cm_sidr_req_param req; |
| 4319 |
struct ib_cm_id *id; |
| 4320 |
void *private_data; |
| 4321 |
u8 offset; |
| 4322 |
int ret; |
| 4323 |
|
| 4324 |
memset(&req, 0, sizeof req); |
| 4325 |
offset = cma_user_data_offset(id_priv); |
| 4326 |
if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) |
| 4327 |
return -EINVAL; |
| 4328 |
|
| 4329 |
if (req.private_data_len) { |
| 4330 |
private_data = kzalloc(req.private_data_len, GFP_ATOMIC); |
| 4331 |
if (!private_data) |
| 4332 |
return -ENOMEM; |
| 4333 |
} else { |
| 4334 |
private_data = NULL; |
| 4335 |
} |
| 4336 |
|
| 4337 |
if (conn_param->private_data && conn_param->private_data_len) |
| 4338 |
memcpy(private_data + offset, conn_param->private_data, |
| 4339 |
conn_param->private_data_len); |
| 4340 |
|
| 4341 |
if (private_data) { |
| 4342 |
ret = cma_format_hdr(private_data, id_priv); |
| 4343 |
if (ret) |
| 4344 |
goto out; |
| 4345 |
req.private_data = private_data; |
| 4346 |
} |
| 4347 |
|
| 4348 |
id = ib_create_cm_id(id_priv->id.device, cma_sidr_rep_handler, |
| 4349 |
id_priv); |
| 4350 |
if (IS_ERR(id)) { |
| 4351 |
ret = PTR_ERR(id); |
| 4352 |
goto out; |
| 4353 |
} |
| 4354 |
id_priv->cm_id.ib = id; |
| 4355 |
|
| 4356 |
req.path = id_priv->id.route.path_rec; |
| 4357 |
req.sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; |
| 4358 |
req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); |
| 4359 |
req.timeout_ms = 1 << (CMA_CM_RESPONSE_TIMEOUT - 8); |
| 4360 |
req.max_cm_retries = CMA_MAX_CM_RETRIES; |
| 4361 |
|
| 4362 |
trace_cm_send_sidr_req(id_priv); |
| 4363 |
ret = ib_send_cm_sidr_req(id_priv->cm_id.ib, &req); |
| 4364 |
if (ret) { |
| 4365 |
ib_destroy_cm_id(id_priv->cm_id.ib); |
| 4366 |
id_priv->cm_id.ib = NULL; |
| 4367 |
} |
| 4368 |
out: |
| 4369 |
kfree(private_data); |
| 4370 |
return ret; |
| 4371 |
} |
| 4372 |
|
| 4373 |
static int cma_connect_ib(struct rdma_id_private *id_priv, |
| 4374 |
struct rdma_conn_param *conn_param) |
| 4375 |
{ |
| 4376 |
struct ib_cm_req_param req; |
| 4377 |
struct rdma_route *route; |
| 4378 |
void *private_data; |
| 4379 |
struct ib_cm_id *id; |
| 4380 |
u8 offset; |
| 4381 |
int ret; |
| 4382 |
|
| 4383 |
memset(&req, 0, sizeof req); |
| 4384 |
offset = cma_user_data_offset(id_priv); |
| 4385 |
if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) |
| 4386 |
return -EINVAL; |
| 4387 |
|
| 4388 |
if (req.private_data_len) { |
| 4389 |
private_data = kzalloc(req.private_data_len, GFP_ATOMIC); |
| 4390 |
if (!private_data) |
| 4391 |
return -ENOMEM; |
| 4392 |
} else { |
| 4393 |
private_data = NULL; |
| 4394 |
} |
| 4395 |
|
| 4396 |
if (conn_param->private_data && conn_param->private_data_len) |
| 4397 |
memcpy(private_data + offset, conn_param->private_data, |
| 4398 |
conn_param->private_data_len); |
| 4399 |
|
| 4400 |
id = ib_create_cm_id(id_priv->id.device, cma_ib_handler, id_priv); |
| 4401 |
if (IS_ERR(id)) { |
| 4402 |
ret = PTR_ERR(id); |
| 4403 |
goto out; |
| 4404 |
} |
| 4405 |
id_priv->cm_id.ib = id; |
| 4406 |
|
| 4407 |
route = &id_priv->id.route; |
| 4408 |
if (private_data) { |
| 4409 |
ret = cma_format_hdr(private_data, id_priv); |
| 4410 |
if (ret) |
| 4411 |
goto out; |
| 4412 |
req.private_data = private_data; |
| 4413 |
} |
| 4414 |
|
| 4415 |
req.primary_path = &route->path_rec[0]; |
| 4416 |
req.primary_path_inbound = route->path_rec_inbound; |
| 4417 |
req.primary_path_outbound = route->path_rec_outbound; |
| 4418 |
if (route->num_pri_alt_paths == 2) |
| 4419 |
req.alternate_path = &route->path_rec[1]; |
| 4420 |
|
| 4421 |
req.ppath_sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; |
| 4422 |
/* Alternate path SGID attribute currently unsupported */ |
| 4423 |
req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); |
| 4424 |
req.qp_num = id_priv->qp_num; |
| 4425 |
req.qp_type = id_priv->id.qp_type; |
| 4426 |
req.starting_psn = id_priv->seq_num; |
| 4427 |
req.responder_resources = conn_param->responder_resources; |
| 4428 |
req.initiator_depth = conn_param->initiator_depth; |
| 4429 |
req.flow_control = conn_param->flow_control; |
| 4430 |
req.retry_count = min_t(u8, 7, conn_param->retry_count); |
| 4431 |
req.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); |
| 4432 |
req.remote_cm_response_timeout = CMA_CM_RESPONSE_TIMEOUT; |
| 4433 |
req.local_cm_response_timeout = CMA_CM_RESPONSE_TIMEOUT; |
| 4434 |
req.max_cm_retries = CMA_MAX_CM_RETRIES; |
| 4435 |
req.srq = id_priv->srq ? 1 : 0; |
| 4436 |
req.ece.vendor_id = id_priv->ece.vendor_id; |
| 4437 |
req.ece.attr_mod = id_priv->ece.attr_mod; |
| 4438 |
|
| 4439 |
trace_cm_send_req(id_priv); |
| 4440 |
ret = ib_send_cm_req(id_priv->cm_id.ib, &req); |
| 4441 |
out: |
| 4442 |
if (ret && !IS_ERR(id)) { |
| 4443 |
ib_destroy_cm_id(id); |
| 4444 |
id_priv->cm_id.ib = NULL; |
| 4445 |
} |
| 4446 |
|
| 4447 |
kfree(private_data); |
| 4448 |
return ret; |
| 4449 |
} |
| 4450 |
|
| 4451 |
static int cma_connect_iw(struct rdma_id_private *id_priv, |
| 4452 |
struct rdma_conn_param *conn_param) |
| 4453 |
{ |
| 4454 |
struct iw_cm_id *cm_id; |
| 4455 |
int ret; |
| 4456 |
struct iw_cm_conn_param iw_param; |
| 4457 |
|
| 4458 |
cm_id = iw_create_cm_id(id_priv->id.device, cma_iw_handler, id_priv); |
| 4459 |
if (IS_ERR(cm_id)) |
| 4460 |
return PTR_ERR(cm_id); |
| 4461 |
|
| 4462 |
mutex_lock(&id_priv->qp_mutex); |
| 4463 |
cm_id->tos = id_priv->tos; |
| 4464 |
cm_id->tos_set = id_priv->tos_set; |
| 4465 |
mutex_unlock(&id_priv->qp_mutex); |
| 4466 |
|
| 4467 |
id_priv->cm_id.iw = cm_id; |
| 4468 |
|
| 4469 |
memcpy(&cm_id->local_addr, cma_src_addr(id_priv), |
| 4470 |
rdma_addr_size(cma_src_addr(id_priv))); |
| 4471 |
memcpy(&cm_id->remote_addr, cma_dst_addr(id_priv), |
| 4472 |
rdma_addr_size(cma_dst_addr(id_priv))); |
| 4473 |
|
| 4474 |
ret = cma_modify_qp_rtr(id_priv, conn_param); |
| 4475 |
if (ret) |
| 4476 |
goto out; |
| 4477 |
|
| 4478 |
if (conn_param) { |
| 4479 |
iw_param.ord = conn_param->initiator_depth; |
| 4480 |
iw_param.ird = conn_param->responder_resources; |
| 4481 |
iw_param.private_data = conn_param->private_data; |
| 4482 |
iw_param.private_data_len = conn_param->private_data_len; |
| 4483 |
iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num; |
| 4484 |
} else { |
| 4485 |
memset(&iw_param, 0, sizeof iw_param); |
| 4486 |
iw_param.qpn = id_priv->qp_num; |
| 4487 |
} |
| 4488 |
ret = iw_cm_connect(cm_id, &iw_param); |
| 4489 |
out: |
| 4490 |
if (ret) { |
| 4491 |
iw_destroy_cm_id(cm_id); |
| 4492 |
id_priv->cm_id.iw = NULL; |
| 4493 |
} |
| 4494 |
return ret; |
| 4495 |
} |
| 4496 |
|
| 4497 |
/** |
| 4498 |
* rdma_connect_locked - Initiate an active connection request. |
| 4499 |
* @id: Connection identifier to connect. |
| 4500 |
* @conn_param: Connection information used for connected QPs. |
| 4501 |
* |
| 4502 |
* Same as rdma_connect() but can only be called from the |
| 4503 |
* RDMA_CM_EVENT_ROUTE_RESOLVED handler callback. |
| 4504 |
*/ |
| 4505 |
int rdma_connect_locked(struct rdma_cm_id *id, |
| 4506 |
struct rdma_conn_param *conn_param) |
| 4507 |
{ |
| 4508 |
struct rdma_id_private *id_priv = |
| 4509 |
container_of(id, struct rdma_id_private, id); |
| 4510 |
int ret; |
| 4511 |
|
| 4512 |
lockdep_assert_held(&id_priv->handler_mutex); |
| 4513 |
|
| 4514 |
if (!cma_comp_exch(id_priv, RDMA_CM_ROUTE_RESOLVED, RDMA_CM_CONNECT)) |
| 4515 |
return -EINVAL; |
| 4516 |
|
| 4517 |
if (!id->qp) { |
| 4518 |
id_priv->qp_num = conn_param->qp_num; |
| 4519 |
id_priv->srq = conn_param->srq; |
| 4520 |
} |
| 4521 |
|
| 4522 |
if (rdma_cap_ib_cm(id->device, id->port_num)) { |
| 4523 |
if (id->qp_type == IB_QPT_UD) |
| 4524 |
ret = cma_resolve_ib_udp(id_priv, conn_param); |
| 4525 |
else |
| 4526 |
ret = cma_connect_ib(id_priv, conn_param); |
| 4527 |
} else if (rdma_cap_iw_cm(id->device, id->port_num)) { |
| 4528 |
ret = cma_connect_iw(id_priv, conn_param); |
| 4529 |
} else { |
| 4530 |
ret = -ENOSYS; |
| 4531 |
} |
| 4532 |
if (ret) |
| 4533 |
goto err_state; |
| 4534 |
return 0; |
| 4535 |
err_state: |
| 4536 |
cma_comp_exch(id_priv, RDMA_CM_CONNECT, RDMA_CM_ROUTE_RESOLVED); |
| 4537 |
return ret; |
| 4538 |
} |
| 4539 |
EXPORT_SYMBOL(rdma_connect_locked); |
| 4540 |
|
| 4541 |
/** |
| 4542 |
* rdma_connect - Initiate an active connection request. |
| 4543 |
* @id: Connection identifier to connect. |
| 4544 |
* @conn_param: Connection information used for connected QPs. |
| 4545 |
* |
| 4546 |
* Users must have resolved a route for the rdma_cm_id to connect with by having |
| 4547 |
* called rdma_resolve_route before calling this routine. |
| 4548 |
* |
| 4549 |
* This call will either connect to a remote QP or obtain remote QP information |
| 4550 |
* for unconnected rdma_cm_id's. The actual operation is based on the |
| 4551 |
* rdma_cm_id's port space. |
| 4552 |
*/ |
| 4553 |
int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) |
| 4554 |
{ |
| 4555 |
struct rdma_id_private *id_priv = |
| 4556 |
container_of(id, struct rdma_id_private, id); |
| 4557 |
int ret; |
| 4558 |
|
| 4559 |
mutex_lock(&id_priv->handler_mutex); |
| 4560 |
ret = rdma_connect_locked(id, conn_param); |
| 4561 |
mutex_unlock(&id_priv->handler_mutex); |
| 4562 |
return ret; |
| 4563 |
} |
| 4564 |
EXPORT_SYMBOL(rdma_connect); |
| 4565 |
|
| 4566 |
/** |
| 4567 |
* rdma_connect_ece - Initiate an active connection request with ECE data. |
| 4568 |
* @id: Connection identifier to connect. |
| 4569 |
* @conn_param: Connection information used for connected QPs. |
| 4570 |
* @ece: ECE parameters |
| 4571 |
* |
| 4572 |
* See rdma_connect() explanation. |
| 4573 |
*/ |
| 4574 |
int rdma_connect_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, |
| 4575 |
struct rdma_ucm_ece *ece) |
| 4576 |
{ |
| 4577 |
struct rdma_id_private *id_priv = |
| 4578 |
container_of(id, struct rdma_id_private, id); |
| 4579 |
|
| 4580 |
id_priv->ece.vendor_id = ece->vendor_id; |
| 4581 |
id_priv->ece.attr_mod = ece->attr_mod; |
| 4582 |
|
| 4583 |
return rdma_connect(id, conn_param); |
| 4584 |
} |
| 4585 |
EXPORT_SYMBOL(rdma_connect_ece); |
| 4586 |
|
| 4587 |
static int cma_accept_ib(struct rdma_id_private *id_priv, |
| 4588 |
struct rdma_conn_param *conn_param) |
| 4589 |
{ |
| 4590 |
struct ib_cm_rep_param rep; |
| 4591 |
int ret; |
| 4592 |
|
| 4593 |
ret = cma_modify_qp_rtr(id_priv, conn_param); |
| 4594 |
if (ret) |
| 4595 |
goto out; |
| 4596 |
|
| 4597 |
ret = cma_modify_qp_rts(id_priv, conn_param); |
| 4598 |
if (ret) |
| 4599 |
goto out; |
| 4600 |
|
| 4601 |
memset(&rep, 0, sizeof rep); |
| 4602 |
rep.qp_num = id_priv->qp_num; |
| 4603 |
rep.starting_psn = id_priv->seq_num; |
| 4604 |
rep.private_data = conn_param->private_data; |
| 4605 |
rep.private_data_len = conn_param->private_data_len; |
| 4606 |
rep.responder_resources = conn_param->responder_resources; |
| 4607 |
rep.initiator_depth = conn_param->initiator_depth; |
| 4608 |
rep.failover_accepted = 0; |
| 4609 |
rep.flow_control = conn_param->flow_control; |
| 4610 |
rep.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); |
| 4611 |
rep.srq = id_priv->srq ? 1 : 0; |
| 4612 |
rep.ece.vendor_id = id_priv->ece.vendor_id; |
| 4613 |
rep.ece.attr_mod = id_priv->ece.attr_mod; |
| 4614 |
|
| 4615 |
trace_cm_send_rep(id_priv); |
| 4616 |
ret = ib_send_cm_rep(id_priv->cm_id.ib, &rep); |
| 4617 |
out: |
| 4618 |
return ret; |
| 4619 |
} |
| 4620 |
|
| 4621 |
static int cma_accept_iw(struct rdma_id_private *id_priv, |
| 4622 |
struct rdma_conn_param *conn_param) |
| 4623 |
{ |
| 4624 |
struct iw_cm_conn_param iw_param; |
| 4625 |
int ret; |
| 4626 |
|
| 4627 |
if (!conn_param) |
| 4628 |
return -EINVAL; |
| 4629 |
|
| 4630 |
ret = cma_modify_qp_rtr(id_priv, conn_param); |
| 4631 |
if (ret) |
| 4632 |
return ret; |
| 4633 |
|
| 4634 |
iw_param.ord = conn_param->initiator_depth; |
| 4635 |
iw_param.ird = conn_param->responder_resources; |
| 4636 |
iw_param.private_data = conn_param->private_data; |
| 4637 |
iw_param.private_data_len = conn_param->private_data_len; |
| 4638 |
if (id_priv->id.qp) |
| 4639 |
iw_param.qpn = id_priv->qp_num; |
| 4640 |
else |
| 4641 |
iw_param.qpn = conn_param->qp_num; |
| 4642 |
|
| 4643 |
return iw_cm_accept(id_priv->cm_id.iw, &iw_param); |
| 4644 |
} |
| 4645 |
|
| 4646 |
static int cma_send_sidr_rep(struct rdma_id_private *id_priv, |
| 4647 |
enum ib_cm_sidr_status status, u32 qkey, |
| 4648 |
const void *private_data, int private_data_len) |
| 4649 |
{ |
| 4650 |
struct ib_cm_sidr_rep_param rep; |
| 4651 |
int ret; |
| 4652 |
|
| 4653 |
memset(&rep, 0, sizeof rep); |
| 4654 |
rep.status = status; |
| 4655 |
if (status == IB_SIDR_SUCCESS) { |
| 4656 |
if (qkey) |
| 4657 |
ret = cma_set_qkey(id_priv, qkey); |
| 4658 |
else |
| 4659 |
ret = cma_set_default_qkey(id_priv); |
| 4660 |
if (ret) |
| 4661 |
return ret; |
| 4662 |
rep.qp_num = id_priv->qp_num; |
| 4663 |
rep.qkey = id_priv->qkey; |
| 4664 |
|
| 4665 |
rep.ece.vendor_id = id_priv->ece.vendor_id; |
| 4666 |
rep.ece.attr_mod = id_priv->ece.attr_mod; |
| 4667 |
} |
| 4668 |
|
| 4669 |
rep.private_data = private_data; |
| 4670 |
rep.private_data_len = private_data_len; |
| 4671 |
|
| 4672 |
trace_cm_send_sidr_rep(id_priv); |
| 4673 |
return ib_send_cm_sidr_rep(id_priv->cm_id.ib, &rep); |
| 4674 |
} |
| 4675 |
|
| 4676 |
/** |
| 4677 |
* rdma_accept - Called to accept a connection request or response. |
| 4678 |
* @id: Connection identifier associated with the request. |
| 4679 |
* @conn_param: Information needed to establish the connection. This must be |
| 4680 |
* provided if accepting a connection request. If accepting a connection |
| 4681 |
* response, this parameter must be NULL. |
| 4682 |
* |
| 4683 |
* Typically, this routine is only called by the listener to accept a connection |
| 4684 |
* request. It must also be called on the active side of a connection if the |
| 4685 |
* user is performing their own QP transitions. |
| 4686 |
* |
| 4687 |
* In the case of error, a reject message is sent to the remote side and the |
| 4688 |
* state of the qp associated with the id is modified to error, such that any |
| 4689 |
* previously posted receive buffers would be flushed. |
| 4690 |
* |
| 4691 |
* This function is for use by kernel ULPs and must be called from under the |
| 4692 |
* handler callback. |
| 4693 |
*/ |
| 4694 |
int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) |
| 4695 |
{ |
| 4696 |
struct rdma_id_private *id_priv = |
| 4697 |
container_of(id, struct rdma_id_private, id); |
| 4698 |
int ret; |
| 4699 |
|
| 4700 |
lockdep_assert_held(&id_priv->handler_mutex); |
| 4701 |
|
| 4702 |
if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) |
| 4703 |
return -EINVAL; |
| 4704 |
|
| 4705 |
if (!id->qp && conn_param) { |
| 4706 |
id_priv->qp_num = conn_param->qp_num; |
| 4707 |
id_priv->srq = conn_param->srq; |
| 4708 |
} |
| 4709 |
|
| 4710 |
if (rdma_cap_ib_cm(id->device, id->port_num)) { |
| 4711 |
if (id->qp_type == IB_QPT_UD) { |
| 4712 |
if (conn_param) |
| 4713 |
ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, |
| 4714 |
conn_param->qkey, |
| 4715 |
conn_param->private_data, |
| 4716 |
conn_param->private_data_len); |
| 4717 |
else |
| 4718 |
ret = cma_send_sidr_rep(id_priv, IB_SIDR_SUCCESS, |
| 4719 |
0, NULL, 0); |
| 4720 |
} else { |
| 4721 |
if (conn_param) |
| 4722 |
ret = cma_accept_ib(id_priv, conn_param); |
| 4723 |
else |
| 4724 |
ret = cma_rep_recv(id_priv); |
| 4725 |
} |
| 4726 |
} else if (rdma_cap_iw_cm(id->device, id->port_num)) { |
| 4727 |
ret = cma_accept_iw(id_priv, conn_param); |
| 4728 |
} else { |
| 4729 |
ret = -ENOSYS; |
| 4730 |
} |
| 4731 |
if (ret) |
| 4732 |
goto reject; |
| 4733 |
|
| 4734 |
return 0; |
| 4735 |
reject: |
| 4736 |
cma_modify_qp_err(id_priv); |
| 4737 |
rdma_reject(id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED); |
| 4738 |
return ret; |
| 4739 |
} |
| 4740 |
EXPORT_SYMBOL(rdma_accept); |
| 4741 |
|
| 4742 |
int rdma_accept_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, |
| 4743 |
struct rdma_ucm_ece *ece) |
| 4744 |
{ |
| 4745 |
struct rdma_id_private *id_priv = |
| 4746 |
container_of(id, struct rdma_id_private, id); |
| 4747 |
|
| 4748 |
id_priv->ece.vendor_id = ece->vendor_id; |
| 4749 |
id_priv->ece.attr_mod = ece->attr_mod; |
| 4750 |
|
| 4751 |
return rdma_accept(id, conn_param); |
| 4752 |
} |
| 4753 |
EXPORT_SYMBOL(rdma_accept_ece); |
| 4754 |
|
| 4755 |
void rdma_lock_handler(struct rdma_cm_id *id) |
| 4756 |
{ |
| 4757 |
struct rdma_id_private *id_priv = |
| 4758 |
container_of(id, struct rdma_id_private, id); |
| 4759 |
|
| 4760 |
mutex_lock(&id_priv->handler_mutex); |
| 4761 |
} |
| 4762 |
EXPORT_SYMBOL(rdma_lock_handler); |
| 4763 |
|
| 4764 |
void rdma_unlock_handler(struct rdma_cm_id *id) |
| 4765 |
{ |
| 4766 |
struct rdma_id_private *id_priv = |
| 4767 |
container_of(id, struct rdma_id_private, id); |
| 4768 |
|
| 4769 |
mutex_unlock(&id_priv->handler_mutex); |
| 4770 |
} |
| 4771 |
EXPORT_SYMBOL(rdma_unlock_handler); |
| 4772 |
|
| 4773 |
int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event) |
| 4774 |
{ |
| 4775 |
struct rdma_id_private *id_priv; |
| 4776 |
int ret; |
| 4777 |
|
| 4778 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 4779 |
if (!id_priv->cm_id.ib) |
| 4780 |
return -EINVAL; |
| 4781 |
|
| 4782 |
switch (id->device->node_type) { |
| 4783 |
case RDMA_NODE_IB_CA: |
| 4784 |
ret = ib_cm_notify(id_priv->cm_id.ib, event); |
| 4785 |
break; |
| 4786 |
default: |
| 4787 |
ret = 0; |
| 4788 |
break; |
| 4789 |
} |
| 4790 |
return ret; |
| 4791 |
} |
| 4792 |
EXPORT_SYMBOL(rdma_notify); |
| 4793 |
|
| 4794 |
int rdma_reject(struct rdma_cm_id *id, const void *private_data, |
| 4795 |
u8 private_data_len, u8 reason) |
| 4796 |
{ |
| 4797 |
struct rdma_id_private *id_priv; |
| 4798 |
int ret; |
| 4799 |
|
| 4800 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 4801 |
if (!id_priv->cm_id.ib) |
| 4802 |
return -EINVAL; |
| 4803 |
|
| 4804 |
if (rdma_cap_ib_cm(id->device, id->port_num)) { |
| 4805 |
if (id->qp_type == IB_QPT_UD) { |
| 4806 |
ret = cma_send_sidr_rep(id_priv, IB_SIDR_REJECT, 0, |
| 4807 |
private_data, private_data_len); |
| 4808 |
} else { |
| 4809 |
trace_cm_send_rej(id_priv); |
| 4810 |
ret = ib_send_cm_rej(id_priv->cm_id.ib, reason, NULL, 0, |
| 4811 |
private_data, private_data_len); |
| 4812 |
} |
| 4813 |
} else if (rdma_cap_iw_cm(id->device, id->port_num)) { |
| 4814 |
ret = iw_cm_reject(id_priv->cm_id.iw, |
| 4815 |
private_data, private_data_len); |
| 4816 |
} else { |
| 4817 |
ret = -ENOSYS; |
| 4818 |
} |
| 4819 |
|
| 4820 |
return ret; |
| 4821 |
} |
| 4822 |
EXPORT_SYMBOL(rdma_reject); |
| 4823 |
|
| 4824 |
int rdma_disconnect(struct rdma_cm_id *id) |
| 4825 |
{ |
| 4826 |
struct rdma_id_private *id_priv; |
| 4827 |
int ret; |
| 4828 |
|
| 4829 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 4830 |
if (!id_priv->cm_id.ib) |
| 4831 |
return -EINVAL; |
| 4832 |
|
| 4833 |
if (rdma_cap_ib_cm(id->device, id->port_num)) { |
| 4834 |
ret = cma_modify_qp_err(id_priv); |
| 4835 |
if (ret) |
| 4836 |
goto out; |
| 4837 |
/* Initiate or respond to a disconnect. */ |
| 4838 |
trace_cm_disconnect(id_priv); |
| 4839 |
if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) { |
| 4840 |
if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0)) |
| 4841 |
trace_cm_sent_drep(id_priv); |
| 4842 |
} else { |
| 4843 |
trace_cm_sent_dreq(id_priv); |
| 4844 |
} |
| 4845 |
} else if (rdma_cap_iw_cm(id->device, id->port_num)) { |
| 4846 |
ret = iw_cm_disconnect(id_priv->cm_id.iw, 0); |
| 4847 |
} else |
| 4848 |
ret = -EINVAL; |
| 4849 |
|
| 4850 |
out: |
| 4851 |
return ret; |
| 4852 |
} |
| 4853 |
EXPORT_SYMBOL(rdma_disconnect); |
| 4854 |
|
| 4855 |
static void cma_make_mc_event(int status, struct rdma_id_private *id_priv, |
| 4856 |
struct ib_sa_multicast *multicast, |
| 4857 |
struct rdma_cm_event *event, |
| 4858 |
struct cma_multicast *mc) |
| 4859 |
{ |
| 4860 |
struct rdma_dev_addr *dev_addr; |
| 4861 |
enum ib_gid_type gid_type; |
| 4862 |
struct net_device *ndev; |
| 4863 |
|
| 4864 |
if (status) |
| 4865 |
pr_debug_ratelimited("RDMA CM: MULTICAST_ERROR: failed to join multicast. status %d\n", |
| 4866 |
status); |
| 4867 |
|
| 4868 |
event->status = status; |
| 4869 |
event->param.ud.private_data = mc->context; |
| 4870 |
if (status) { |
| 4871 |
event->event = RDMA_CM_EVENT_MULTICAST_ERROR; |
| 4872 |
return; |
| 4873 |
} |
| 4874 |
|
| 4875 |
dev_addr = &id_priv->id.route.addr.dev_addr; |
| 4876 |
ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); |
| 4877 |
gid_type = |
| 4878 |
id_priv->cma_dev |
| 4879 |
->default_gid_type[id_priv->id.port_num - |
| 4880 |
rdma_start_port( |
| 4881 |
id_priv->cma_dev->device)]; |
| 4882 |
|
| 4883 |
event->event = RDMA_CM_EVENT_MULTICAST_JOIN; |
| 4884 |
if (ib_init_ah_from_mcmember(id_priv->id.device, id_priv->id.port_num, |
| 4885 |
&multicast->rec, ndev, gid_type, |
| 4886 |
&event->param.ud.ah_attr)) { |
| 4887 |
event->event = RDMA_CM_EVENT_MULTICAST_ERROR; |
| 4888 |
goto out; |
| 4889 |
} |
| 4890 |
|
| 4891 |
event->param.ud.qp_num = 0xFFFFFF; |
| 4892 |
event->param.ud.qkey = id_priv->qkey; |
| 4893 |
|
| 4894 |
out: |
| 4895 |
dev_put(ndev); |
| 4896 |
} |
| 4897 |
|
| 4898 |
static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast) |
| 4899 |
{ |
| 4900 |
struct cma_multicast *mc = multicast->context; |
| 4901 |
struct rdma_id_private *id_priv = mc->id_priv; |
| 4902 |
struct rdma_cm_event event = {}; |
| 4903 |
int ret = 0; |
| 4904 |
|
| 4905 |
mutex_lock(&id_priv->handler_mutex); |
| 4906 |
if (READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL || |
| 4907 |
READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING) |
| 4908 |
goto out; |
| 4909 |
|
| 4910 |
ret = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey)); |
| 4911 |
if (!ret) { |
| 4912 |
cma_make_mc_event(status, id_priv, multicast, &event, mc); |
| 4913 |
ret = cma_cm_event_handler(id_priv, &event); |
| 4914 |
} |
| 4915 |
rdma_destroy_ah_attr(&event.param.ud.ah_attr); |
| 4916 |
WARN_ON(ret); |
| 4917 |
|
| 4918 |
out: |
| 4919 |
mutex_unlock(&id_priv->handler_mutex); |
| 4920 |
return 0; |
| 4921 |
} |
| 4922 |
|
| 4923 |
static void cma_set_mgid(struct rdma_id_private *id_priv, |
| 4924 |
struct sockaddr *addr, union ib_gid *mgid) |
| 4925 |
{ |
| 4926 |
unsigned char mc_map[MAX_ADDR_LEN]; |
| 4927 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 4928 |
struct sockaddr_in *sin = (struct sockaddr_in *) addr; |
| 4929 |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) addr; |
| 4930 |
|
| 4931 |
if (cma_any_addr(addr)) { |
| 4932 |
memset(mgid, 0, sizeof *mgid); |
| 4933 |
} else if ((addr->sa_family == AF_INET6) && |
| 4934 |
((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFFF0FFFF) == |
| 4935 |
0xFF10A01B)) { |
| 4936 |
/* IPv6 address is an SA assigned MGID. */ |
| 4937 |
memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); |
| 4938 |
} else if (addr->sa_family == AF_IB) { |
| 4939 |
memcpy(mgid, &((struct sockaddr_ib *) addr)->sib_addr, sizeof *mgid); |
| 4940 |
} else if (addr->sa_family == AF_INET6) { |
| 4941 |
ipv6_ib_mc_map(&sin6->sin6_addr, dev_addr->broadcast, mc_map); |
| 4942 |
if (id_priv->id.ps == RDMA_PS_UDP) |
| 4943 |
mc_map[7] = 0x01; /* Use RDMA CM signature */ |
| 4944 |
*mgid = *(union ib_gid *) (mc_map + 4); |
| 4945 |
} else { |
| 4946 |
ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map); |
| 4947 |
if (id_priv->id.ps == RDMA_PS_UDP) |
| 4948 |
mc_map[7] = 0x01; /* Use RDMA CM signature */ |
| 4949 |
*mgid = *(union ib_gid *) (mc_map + 4); |
| 4950 |
} |
| 4951 |
} |
| 4952 |
|
| 4953 |
static int cma_join_ib_multicast(struct rdma_id_private *id_priv, |
| 4954 |
struct cma_multicast *mc) |
| 4955 |
{ |
| 4956 |
struct ib_sa_mcmember_rec rec; |
| 4957 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 4958 |
ib_sa_comp_mask comp_mask; |
| 4959 |
int ret; |
| 4960 |
|
| 4961 |
ib_addr_get_mgid(dev_addr, &rec.mgid); |
| 4962 |
ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num, |
| 4963 |
&rec.mgid, &rec); |
| 4964 |
if (ret) |
| 4965 |
return ret; |
| 4966 |
|
| 4967 |
if (!id_priv->qkey) { |
| 4968 |
ret = cma_set_default_qkey(id_priv); |
| 4969 |
if (ret) |
| 4970 |
return ret; |
| 4971 |
} |
| 4972 |
|
| 4973 |
cma_set_mgid(id_priv, (struct sockaddr *) &mc->addr, &rec.mgid); |
| 4974 |
rec.qkey = cpu_to_be32(id_priv->qkey); |
| 4975 |
rdma_addr_get_sgid(dev_addr, &rec.port_gid); |
| 4976 |
rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr)); |
| 4977 |
rec.join_state = mc->join_state; |
| 4978 |
|
| 4979 |
comp_mask = IB_SA_MCMEMBER_REC_MGID | IB_SA_MCMEMBER_REC_PORT_GID | |
| 4980 |
IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_JOIN_STATE | |
| 4981 |
IB_SA_MCMEMBER_REC_QKEY | IB_SA_MCMEMBER_REC_SL | |
| 4982 |
IB_SA_MCMEMBER_REC_FLOW_LABEL | |
| 4983 |
IB_SA_MCMEMBER_REC_TRAFFIC_CLASS; |
| 4984 |
|
| 4985 |
if (id_priv->id.ps == RDMA_PS_IPOIB) |
| 4986 |
comp_mask |= IB_SA_MCMEMBER_REC_RATE | |
| 4987 |
IB_SA_MCMEMBER_REC_RATE_SELECTOR | |
| 4988 |
IB_SA_MCMEMBER_REC_MTU_SELECTOR | |
| 4989 |
IB_SA_MCMEMBER_REC_MTU | |
| 4990 |
IB_SA_MCMEMBER_REC_HOP_LIMIT; |
| 4991 |
|
| 4992 |
mc->sa_mc = ib_sa_join_multicast(&sa_client, id_priv->id.device, |
| 4993 |
id_priv->id.port_num, &rec, comp_mask, |
| 4994 |
GFP_KERNEL, cma_ib_mc_handler, mc); |
| 4995 |
return PTR_ERR_OR_ZERO(mc->sa_mc); |
| 4996 |
} |
| 4997 |
|
| 4998 |
static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid, |
| 4999 |
enum ib_gid_type gid_type) |
| 5000 |
{ |
| 5001 |
struct sockaddr_in *sin = (struct sockaddr_in *)addr; |
| 5002 |
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; |
| 5003 |
|
| 5004 |
if (cma_any_addr(addr)) { |
| 5005 |
memset(mgid, 0, sizeof *mgid); |
| 5006 |
} else if (addr->sa_family == AF_INET6) { |
| 5007 |
memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); |
| 5008 |
} else { |
| 5009 |
mgid->raw[0] = |
| 5010 |
(gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) ? 0 : 0xff; |
| 5011 |
mgid->raw[1] = |
| 5012 |
(gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) ? 0 : 0x0e; |
| 5013 |
mgid->raw[2] = 0; |
| 5014 |
mgid->raw[3] = 0; |
| 5015 |
mgid->raw[4] = 0; |
| 5016 |
mgid->raw[5] = 0; |
| 5017 |
mgid->raw[6] = 0; |
| 5018 |
mgid->raw[7] = 0; |
| 5019 |
mgid->raw[8] = 0; |
| 5020 |
mgid->raw[9] = 0; |
| 5021 |
mgid->raw[10] = 0xff; |
| 5022 |
mgid->raw[11] = 0xff; |
| 5023 |
*(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr; |
| 5024 |
} |
| 5025 |
} |
| 5026 |
|
| 5027 |
static int cma_iboe_join_multicast(struct rdma_id_private *id_priv, |
| 5028 |
struct cma_multicast *mc) |
| 5029 |
{ |
| 5030 |
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; |
| 5031 |
int err = 0; |
| 5032 |
struct sockaddr *addr = (struct sockaddr *)&mc->addr; |
| 5033 |
struct net_device *ndev = NULL; |
| 5034 |
struct ib_sa_multicast ib = {}; |
| 5035 |
enum ib_gid_type gid_type; |
| 5036 |
bool send_only; |
| 5037 |
|
| 5038 |
send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); |
| 5039 |
|
| 5040 |
if (cma_zero_addr(addr)) |
| 5041 |
return -EINVAL; |
| 5042 |
|
| 5043 |
gid_type = id_priv->cma_dev->default_gid_type[id_priv->id.port_num - |
| 5044 |
rdma_start_port(id_priv->cma_dev->device)]; |
| 5045 |
cma_iboe_set_mgid(addr, &ib.rec.mgid, gid_type); |
| 5046 |
|
| 5047 |
ib.rec.pkey = cpu_to_be16(0xffff); |
| 5048 |
if (dev_addr->bound_dev_if) |
| 5049 |
ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); |
| 5050 |
if (!ndev) |
| 5051 |
return -ENODEV; |
| 5052 |
|
| 5053 |
ib.rec.rate = IB_RATE_PORT_CURRENT; |
| 5054 |
ib.rec.hop_limit = 1; |
| 5055 |
ib.rec.mtu = iboe_get_mtu(ndev->mtu); |
| 5056 |
|
| 5057 |
if (addr->sa_family == AF_INET) { |
| 5058 |
if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) { |
| 5059 |
ib.rec.hop_limit = IPV6_DEFAULT_HOPLIMIT; |
| 5060 |
if (!send_only) { |
| 5061 |
err = cma_igmp_send(ndev, &ib.rec.mgid, |
| 5062 |
true); |
| 5063 |
} |
| 5064 |
} |
| 5065 |
} else { |
| 5066 |
if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) |
| 5067 |
err = -ENOTSUPP; |
| 5068 |
} |
| 5069 |
dev_put(ndev); |
| 5070 |
if (err || !ib.rec.mtu) |
| 5071 |
return err ?: -EINVAL; |
| 5072 |
|
| 5073 |
if (!id_priv->qkey) |
| 5074 |
cma_set_default_qkey(id_priv); |
| 5075 |
|
| 5076 |
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, |
| 5077 |
&ib.rec.port_gid); |
| 5078 |
INIT_WORK(&mc->iboe_join.work, cma_iboe_join_work_handler); |
| 5079 |
cma_make_mc_event(0, id_priv, &ib, &mc->iboe_join.event, mc); |
| 5080 |
queue_work(cma_wq, &mc->iboe_join.work); |
| 5081 |
return 0; |
| 5082 |
} |
| 5083 |
|
| 5084 |
int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, |
| 5085 |
u8 join_state, void *context) |
| 5086 |
{ |
| 5087 |
struct rdma_id_private *id_priv = |
| 5088 |
container_of(id, struct rdma_id_private, id); |
| 5089 |
struct cma_multicast *mc; |
| 5090 |
int ret; |
| 5091 |
|
| 5092 |
/* Not supported for kernel QPs */ |
| 5093 |
if (WARN_ON(id->qp)) |
| 5094 |
return -EINVAL; |
| 5095 |
|
| 5096 |
/* ULP is calling this wrong. */ |
| 5097 |
if (!id->device || (READ_ONCE(id_priv->state) != RDMA_CM_ADDR_BOUND && |
| 5098 |
READ_ONCE(id_priv->state) != RDMA_CM_ADDR_RESOLVED)) |
| 5099 |
return -EINVAL; |
| 5100 |
|
| 5101 |
if (id_priv->id.qp_type != IB_QPT_UD) |
| 5102 |
return -EINVAL; |
| 5103 |
|
| 5104 |
mc = kzalloc_obj(*mc); |
| 5105 |
if (!mc) |
| 5106 |
return -ENOMEM; |
| 5107 |
|
| 5108 |
memcpy(&mc->addr, addr, rdma_addr_size(addr)); |
| 5109 |
mc->context = context; |
| 5110 |
mc->id_priv = id_priv; |
| 5111 |
mc->join_state = join_state; |
| 5112 |
|
| 5113 |
if (rdma_protocol_roce(id->device, id->port_num)) { |
| 5114 |
ret = cma_iboe_join_multicast(id_priv, mc); |
| 5115 |
if (ret) |
| 5116 |
goto out_err; |
| 5117 |
} else if (rdma_cap_ib_mcast(id->device, id->port_num)) { |
| 5118 |
ret = cma_join_ib_multicast(id_priv, mc); |
| 5119 |
if (ret) |
| 5120 |
goto out_err; |
| 5121 |
} else { |
| 5122 |
ret = -ENOSYS; |
| 5123 |
goto out_err; |
| 5124 |
} |
| 5125 |
|
| 5126 |
spin_lock(&id_priv->lock); |
| 5127 |
list_add(&mc->list, &id_priv->mc_list); |
| 5128 |
spin_unlock(&id_priv->lock); |
| 5129 |
|
| 5130 |
return 0; |
| 5131 |
out_err: |
| 5132 |
kfree(mc); |
| 5133 |
return ret; |
| 5134 |
} |
| 5135 |
EXPORT_SYMBOL(rdma_join_multicast); |
| 5136 |
|
| 5137 |
void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr) |
| 5138 |
{ |
| 5139 |
struct rdma_id_private *id_priv; |
| 5140 |
struct cma_multicast *mc; |
| 5141 |
|
| 5142 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 5143 |
spin_lock_irq(&id_priv->lock); |
| 5144 |
list_for_each_entry(mc, &id_priv->mc_list, list) { |
| 5145 |
if (memcmp(&mc->addr, addr, rdma_addr_size(addr)) != 0) |
| 5146 |
continue; |
| 5147 |
list_del(&mc->list); |
| 5148 |
spin_unlock_irq(&id_priv->lock); |
| 5149 |
|
| 5150 |
WARN_ON(id_priv->cma_dev->device != id->device); |
| 5151 |
destroy_mc(id_priv, mc); |
| 5152 |
return; |
| 5153 |
} |
| 5154 |
spin_unlock_irq(&id_priv->lock); |
| 5155 |
} |
| 5156 |
EXPORT_SYMBOL(rdma_leave_multicast); |
| 5157 |
|
| 5158 |
static int cma_netdev_change(struct net_device *ndev, struct rdma_id_private *id_priv) |
| 5159 |
{ |
| 5160 |
struct rdma_dev_addr *dev_addr; |
| 5161 |
struct cma_work *work; |
| 5162 |
|
| 5163 |
dev_addr = &id_priv->id.route.addr.dev_addr; |
| 5164 |
|
| 5165 |
if ((dev_addr->bound_dev_if == ndev->ifindex) && |
| 5166 |
(net_eq(dev_net(ndev), dev_addr->net)) && |
| 5167 |
memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) { |
| 5168 |
pr_info("RDMA CM addr change for ndev %s used by id %p\n", |
| 5169 |
ndev->name, &id_priv->id); |
| 5170 |
work = kzalloc_obj(*work); |
| 5171 |
if (!work) |
| 5172 |
return -ENOMEM; |
| 5173 |
|
| 5174 |
INIT_WORK(&work->work, cma_work_handler); |
| 5175 |
work->id = id_priv; |
| 5176 |
work->event.event = RDMA_CM_EVENT_ADDR_CHANGE; |
| 5177 |
cma_id_get(id_priv); |
| 5178 |
queue_work(cma_wq, &work->work); |
| 5179 |
} |
| 5180 |
|
| 5181 |
return 0; |
| 5182 |
} |
| 5183 |
|
| 5184 |
static int cma_netdev_callback(struct notifier_block *self, unsigned long event, |
| 5185 |
void *ptr) |
| 5186 |
{ |
| 5187 |
struct net_device *ndev = netdev_notifier_info_to_dev(ptr); |
| 5188 |
struct cma_device *cma_dev; |
| 5189 |
struct rdma_id_private *id_priv; |
| 5190 |
int ret = NOTIFY_DONE; |
| 5191 |
|
| 5192 |
if (event != NETDEV_BONDING_FAILOVER) |
| 5193 |
return NOTIFY_DONE; |
| 5194 |
|
| 5195 |
if (!netif_is_bond_master(ndev)) |
| 5196 |
return NOTIFY_DONE; |
| 5197 |
|
| 5198 |
mutex_lock(&lock); |
| 5199 |
list_for_each_entry(cma_dev, &dev_list, list) |
| 5200 |
list_for_each_entry(id_priv, &cma_dev->id_list, device_item) { |
| 5201 |
ret = cma_netdev_change(ndev, id_priv); |
| 5202 |
if (ret) |
| 5203 |
goto out; |
| 5204 |
} |
| 5205 |
|
| 5206 |
out: |
| 5207 |
mutex_unlock(&lock); |
| 5208 |
return ret; |
| 5209 |
} |
| 5210 |
|
| 5211 |
static void cma_netevent_work_handler(struct work_struct *_work) |
| 5212 |
{ |
| 5213 |
struct rdma_id_private *id_priv = |
| 5214 |
container_of(_work, struct rdma_id_private, id.net_work); |
| 5215 |
struct rdma_cm_event event = {}; |
| 5216 |
|
| 5217 |
mutex_lock(&id_priv->handler_mutex); |
| 5218 |
|
| 5219 |
if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || |
| 5220 |
READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) |
| 5221 |
goto out_unlock; |
| 5222 |
|
| 5223 |
event.event = RDMA_CM_EVENT_UNREACHABLE; |
| 5224 |
event.status = -ETIMEDOUT; |
| 5225 |
|
| 5226 |
if (cma_cm_event_handler(id_priv, &event)) { |
| 5227 |
__acquire(&id_priv->handler_mutex); |
| 5228 |
id_priv->cm_id.ib = NULL; |
| 5229 |
cma_id_put(id_priv); |
| 5230 |
destroy_id_handler_unlock(id_priv); |
| 5231 |
return; |
| 5232 |
} |
| 5233 |
|
| 5234 |
out_unlock: |
| 5235 |
mutex_unlock(&id_priv->handler_mutex); |
| 5236 |
cma_id_put(id_priv); |
| 5237 |
} |
| 5238 |
|
| 5239 |
static int cma_netevent_callback(struct notifier_block *self, |
| 5240 |
unsigned long event, void *ctx) |
| 5241 |
{ |
| 5242 |
struct id_table_entry *ips_node = NULL; |
| 5243 |
struct rdma_id_private *current_id; |
| 5244 |
struct neighbour *neigh = ctx; |
| 5245 |
unsigned long flags; |
| 5246 |
|
| 5247 |
if (event != NETEVENT_NEIGH_UPDATE) |
| 5248 |
return NOTIFY_DONE; |
| 5249 |
|
| 5250 |
spin_lock_irqsave(&id_table_lock, flags); |
| 5251 |
if (neigh->tbl->family == AF_INET6) { |
| 5252 |
struct sockaddr_in6 neigh_sock_6; |
| 5253 |
|
| 5254 |
neigh_sock_6.sin6_family = AF_INET6; |
| 5255 |
neigh_sock_6.sin6_addr = *(struct in6_addr *)neigh->primary_key; |
| 5256 |
ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, |
| 5257 |
(struct sockaddr *)&neigh_sock_6); |
| 5258 |
} else if (neigh->tbl->family == AF_INET) { |
| 5259 |
struct sockaddr_in neigh_sock_4; |
| 5260 |
|
| 5261 |
neigh_sock_4.sin_family = AF_INET; |
| 5262 |
neigh_sock_4.sin_addr.s_addr = *(__be32 *)(neigh->primary_key); |
| 5263 |
ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, |
| 5264 |
(struct sockaddr *)&neigh_sock_4); |
| 5265 |
} else |
| 5266 |
goto out; |
| 5267 |
|
| 5268 |
if (!ips_node) |
| 5269 |
goto out; |
| 5270 |
|
| 5271 |
list_for_each_entry(current_id, &ips_node->id_list, id_list_entry) { |
| 5272 |
if (!memcmp(current_id->id.route.addr.dev_addr.dst_dev_addr, |
| 5273 |
neigh->ha, ETH_ALEN)) |
| 5274 |
continue; |
| 5275 |
cma_id_get(current_id); |
| 5276 |
if (!queue_work(cma_wq, ¤t_id->id.net_work)) |
| 5277 |
cma_id_put(current_id); |
| 5278 |
} |
| 5279 |
out: |
| 5280 |
spin_unlock_irqrestore(&id_table_lock, flags); |
| 5281 |
return NOTIFY_DONE; |
| 5282 |
} |
| 5283 |
|
| 5284 |
static struct notifier_block cma_nb = { |
| 5285 |
.notifier_call = cma_netdev_callback |
| 5286 |
}; |
| 5287 |
|
| 5288 |
static struct notifier_block cma_netevent_cb = { |
| 5289 |
.notifier_call = cma_netevent_callback |
| 5290 |
}; |
| 5291 |
|
| 5292 |
static void cma_send_device_removal_put(struct rdma_id_private *id_priv) |
| 5293 |
{ |
| 5294 |
struct rdma_cm_event event = { .event = RDMA_CM_EVENT_DEVICE_REMOVAL }; |
| 5295 |
enum rdma_cm_state state; |
| 5296 |
unsigned long flags; |
| 5297 |
|
| 5298 |
mutex_lock(&id_priv->handler_mutex); |
| 5299 |
/* Record that we want to remove the device */ |
| 5300 |
spin_lock_irqsave(&id_priv->lock, flags); |
| 5301 |
state = id_priv->state; |
| 5302 |
if (state == RDMA_CM_DESTROYING || state == RDMA_CM_DEVICE_REMOVAL) { |
| 5303 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 5304 |
mutex_unlock(&id_priv->handler_mutex); |
| 5305 |
cma_id_put(id_priv); |
| 5306 |
return; |
| 5307 |
} |
| 5308 |
id_priv->state = RDMA_CM_DEVICE_REMOVAL; |
| 5309 |
spin_unlock_irqrestore(&id_priv->lock, flags); |
| 5310 |
|
| 5311 |
if (cma_cm_event_handler(id_priv, &event)) { |
| 5312 |
/* |
| 5313 |
* At this point the ULP promises it won't call |
| 5314 |
* rdma_destroy_id() concurrently |
| 5315 |
*/ |
| 5316 |
cma_id_put(id_priv); |
| 5317 |
mutex_unlock(&id_priv->handler_mutex); |
| 5318 |
trace_cm_id_destroy(id_priv); |
| 5319 |
_destroy_id(id_priv, state); |
| 5320 |
return; |
| 5321 |
} |
| 5322 |
mutex_unlock(&id_priv->handler_mutex); |
| 5323 |
|
| 5324 |
/* |
| 5325 |
* If this races with destroy then the thread that first assigns state |
| 5326 |
* to a destroying does the cancel. |
| 5327 |
*/ |
| 5328 |
cma_cancel_operation(id_priv, state); |
| 5329 |
cma_id_put(id_priv); |
| 5330 |
} |
| 5331 |
|
| 5332 |
static void cma_process_remove(struct cma_device *cma_dev) |
| 5333 |
{ |
| 5334 |
mutex_lock(&lock); |
| 5335 |
while (!list_empty(&cma_dev->id_list)) { |
| 5336 |
struct rdma_id_private *id_priv = list_first_entry( |
| 5337 |
&cma_dev->id_list, struct rdma_id_private, device_item); |
| 5338 |
|
| 5339 |
list_del_init(&id_priv->listen_item); |
| 5340 |
list_del_init(&id_priv->device_item); |
| 5341 |
cma_id_get(id_priv); |
| 5342 |
mutex_unlock(&lock); |
| 5343 |
|
| 5344 |
cma_send_device_removal_put(id_priv); |
| 5345 |
|
| 5346 |
mutex_lock(&lock); |
| 5347 |
} |
| 5348 |
mutex_unlock(&lock); |
| 5349 |
|
| 5350 |
cma_dev_put(cma_dev); |
| 5351 |
wait_for_completion(&cma_dev->comp); |
| 5352 |
} |
| 5353 |
|
| 5354 |
static bool cma_supported(struct ib_device *device) |
| 5355 |
{ |
| 5356 |
u32 i; |
| 5357 |
|
| 5358 |
rdma_for_each_port(device, i) { |
| 5359 |
if (rdma_cap_ib_cm(device, i) || rdma_cap_iw_cm(device, i)) |
| 5360 |
return true; |
| 5361 |
} |
| 5362 |
return false; |
| 5363 |
} |
| 5364 |
|
| 5365 |
static int cma_add_one(struct ib_device *device) |
| 5366 |
{ |
| 5367 |
struct rdma_id_private *to_destroy; |
| 5368 |
struct cma_device *cma_dev; |
| 5369 |
struct rdma_id_private *id_priv; |
| 5370 |
unsigned long supported_gids = 0; |
| 5371 |
int ret; |
| 5372 |
u32 i; |
| 5373 |
|
| 5374 |
if (!cma_supported(device)) |
| 5375 |
return -EOPNOTSUPP; |
| 5376 |
|
| 5377 |
cma_dev = kmalloc_obj(*cma_dev); |
| 5378 |
if (!cma_dev) |
| 5379 |
return -ENOMEM; |
| 5380 |
|
| 5381 |
cma_dev->device = device; |
| 5382 |
cma_dev->default_gid_type = kzalloc_objs(*cma_dev->default_gid_type, |
| 5383 |
device->phys_port_cnt); |
| 5384 |
if (!cma_dev->default_gid_type) { |
| 5385 |
ret = -ENOMEM; |
| 5386 |
goto free_cma_dev; |
| 5387 |
} |
| 5388 |
|
| 5389 |
cma_dev->default_roce_tos = kcalloc(device->phys_port_cnt, |
| 5390 |
sizeof(*cma_dev->default_roce_tos), |
| 5391 |
GFP_KERNEL); |
| 5392 |
if (!cma_dev->default_roce_tos) { |
| 5393 |
ret = -ENOMEM; |
| 5394 |
goto free_gid_type; |
| 5395 |
} |
| 5396 |
|
| 5397 |
rdma_for_each_port (device, i) { |
| 5398 |
supported_gids = roce_gid_type_mask_support(device, i); |
| 5399 |
WARN_ON(!supported_gids); |
| 5400 |
if (supported_gids & (1 << CMA_PREFERRED_ROCE_GID_TYPE)) |
| 5401 |
cma_dev->default_gid_type[i - rdma_start_port(device)] = |
| 5402 |
CMA_PREFERRED_ROCE_GID_TYPE; |
| 5403 |
else |
| 5404 |
cma_dev->default_gid_type[i - rdma_start_port(device)] = |
| 5405 |
find_first_bit(&supported_gids, BITS_PER_LONG); |
| 5406 |
cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0; |
| 5407 |
} |
| 5408 |
|
| 5409 |
init_completion(&cma_dev->comp); |
| 5410 |
refcount_set(&cma_dev->refcount, 1); |
| 5411 |
INIT_LIST_HEAD(&cma_dev->id_list); |
| 5412 |
ib_set_client_data(device, &cma_client, cma_dev); |
| 5413 |
|
| 5414 |
mutex_lock(&lock); |
| 5415 |
list_add_tail(&cma_dev->list, &dev_list); |
| 5416 |
list_for_each_entry(id_priv, &listen_any_list, listen_any_item) { |
| 5417 |
ret = cma_listen_on_dev(id_priv, cma_dev, &to_destroy); |
| 5418 |
if (ret) |
| 5419 |
goto free_listen; |
| 5420 |
} |
| 5421 |
mutex_unlock(&lock); |
| 5422 |
|
| 5423 |
trace_cm_add_one(device); |
| 5424 |
return 0; |
| 5425 |
|
| 5426 |
free_listen: |
| 5427 |
list_del(&cma_dev->list); |
| 5428 |
mutex_unlock(&lock); |
| 5429 |
|
| 5430 |
/* cma_process_remove() will delete to_destroy */ |
| 5431 |
cma_process_remove(cma_dev); |
| 5432 |
kfree(cma_dev->default_roce_tos); |
| 5433 |
free_gid_type: |
| 5434 |
kfree(cma_dev->default_gid_type); |
| 5435 |
|
| 5436 |
free_cma_dev: |
| 5437 |
kfree(cma_dev); |
| 5438 |
return ret; |
| 5439 |
} |
| 5440 |
|
| 5441 |
static void cma_remove_one(struct ib_device *device, void *client_data) |
| 5442 |
{ |
| 5443 |
struct cma_device *cma_dev = client_data; |
| 5444 |
|
| 5445 |
trace_cm_remove_one(device); |
| 5446 |
|
| 5447 |
mutex_lock(&lock); |
| 5448 |
list_del(&cma_dev->list); |
| 5449 |
mutex_unlock(&lock); |
| 5450 |
|
| 5451 |
cma_process_remove(cma_dev); |
| 5452 |
kfree(cma_dev->default_roce_tos); |
| 5453 |
kfree(cma_dev->default_gid_type); |
| 5454 |
kfree(cma_dev); |
| 5455 |
} |
| 5456 |
|
| 5457 |
static int cma_init_net(struct net *net) |
| 5458 |
{ |
| 5459 |
struct cma_pernet *pernet = cma_pernet(net); |
| 5460 |
|
| 5461 |
xa_init(&pernet->tcp_ps); |
| 5462 |
xa_init(&pernet->udp_ps); |
| 5463 |
xa_init(&pernet->ipoib_ps); |
| 5464 |
xa_init(&pernet->ib_ps); |
| 5465 |
|
| 5466 |
return 0; |
| 5467 |
} |
| 5468 |
|
| 5469 |
static void cma_exit_net(struct net *net) |
| 5470 |
{ |
| 5471 |
struct cma_pernet *pernet = cma_pernet(net); |
| 5472 |
|
| 5473 |
WARN_ON(!xa_empty(&pernet->tcp_ps)); |
| 5474 |
WARN_ON(!xa_empty(&pernet->udp_ps)); |
| 5475 |
WARN_ON(!xa_empty(&pernet->ipoib_ps)); |
| 5476 |
WARN_ON(!xa_empty(&pernet->ib_ps)); |
| 5477 |
} |
| 5478 |
|
| 5479 |
static struct pernet_operations cma_pernet_operations = { |
| 5480 |
.init = cma_init_net, |
| 5481 |
.exit = cma_exit_net, |
| 5482 |
.id = &cma_pernet_id, |
| 5483 |
.size = sizeof(struct cma_pernet), |
| 5484 |
}; |
| 5485 |
|
| 5486 |
static int __init cma_init(void) |
| 5487 |
{ |
| 5488 |
int ret; |
| 5489 |
|
| 5490 |
/* |
| 5491 |
* There is a rare lock ordering dependency in cma_netdev_callback() |
| 5492 |
* that only happens when bonding is enabled. Teach lockdep that rtnl |
| 5493 |
* must never be nested under lock so it can find these without having |
| 5494 |
* to test with bonding. |
| 5495 |
*/ |
| 5496 |
if (IS_ENABLED(CONFIG_LOCKDEP)) { |
| 5497 |
rtnl_lock(); |
| 5498 |
mutex_lock(&lock); |
| 5499 |
mutex_unlock(&lock); |
| 5500 |
rtnl_unlock(); |
| 5501 |
} |
| 5502 |
|
| 5503 |
cma_wq = alloc_ordered_workqueue("rdma_cm", WQ_MEM_RECLAIM); |
| 5504 |
if (!cma_wq) |
| 5505 |
return -ENOMEM; |
| 5506 |
|
| 5507 |
ret = register_pernet_subsys(&cma_pernet_operations); |
| 5508 |
if (ret) |
| 5509 |
goto err_wq; |
| 5510 |
|
| 5511 |
ib_sa_register_client(&sa_client); |
| 5512 |
register_netdevice_notifier(&cma_nb); |
| 5513 |
register_netevent_notifier(&cma_netevent_cb); |
| 5514 |
|
| 5515 |
ret = ib_register_client(&cma_client); |
| 5516 |
if (ret) |
| 5517 |
goto err; |
| 5518 |
|
| 5519 |
ret = cma_configfs_init(); |
| 5520 |
if (ret) |
| 5521 |
goto err_ib; |
| 5522 |
|
| 5523 |
return 0; |
| 5524 |
|
| 5525 |
err_ib: |
| 5526 |
ib_unregister_client(&cma_client); |
| 5527 |
err: |
| 5528 |
unregister_netevent_notifier(&cma_netevent_cb); |
| 5529 |
unregister_netdevice_notifier(&cma_nb); |
| 5530 |
ib_sa_unregister_client(&sa_client); |
| 5531 |
unregister_pernet_subsys(&cma_pernet_operations); |
| 5532 |
err_wq: |
| 5533 |
destroy_workqueue(cma_wq); |
| 5534 |
return ret; |
| 5535 |
} |
| 5536 |
|
| 5537 |
static void __exit cma_cleanup(void) |
| 5538 |
{ |
| 5539 |
cma_configfs_exit(); |
| 5540 |
ib_unregister_client(&cma_client); |
| 5541 |
unregister_netevent_notifier(&cma_netevent_cb); |
| 5542 |
unregister_netdevice_notifier(&cma_nb); |
| 5543 |
ib_sa_unregister_client(&sa_client); |
| 5544 |
unregister_pernet_subsys(&cma_pernet_operations); |
| 5545 |
destroy_workqueue(cma_wq); |
| 5546 |
} |
| 5547 |
|
| 5548 |
module_init(cma_init); |
| 5549 |
module_exit(cma_cleanup); |
| 5550 |
|
| 5551 |
static void cma_query_ib_service_handler(int status, |
| 5552 |
struct sa_service_rec *recs, |
| 5553 |
unsigned int num_recs, void *context) |
| 5554 |
{ |
| 5555 |
struct cma_work *work = context; |
| 5556 |
struct rdma_id_private *id_priv = work->id; |
| 5557 |
struct sockaddr_ib *addr; |
| 5558 |
|
| 5559 |
if (status) |
| 5560 |
goto fail; |
| 5561 |
|
| 5562 |
if (!num_recs) { |
| 5563 |
status = -ENOENT; |
| 5564 |
goto fail; |
| 5565 |
} |
| 5566 |
|
| 5567 |
if (id_priv->id.route.service_recs) { |
| 5568 |
status = -EALREADY; |
| 5569 |
goto fail; |
| 5570 |
} |
| 5571 |
|
| 5572 |
id_priv->id.route.service_recs = |
| 5573 |
kmalloc_objs(*recs, num_recs); |
| 5574 |
if (!id_priv->id.route.service_recs) { |
| 5575 |
status = -ENOMEM; |
| 5576 |
goto fail; |
| 5577 |
} |
| 5578 |
|
| 5579 |
id_priv->id.route.num_service_recs = num_recs; |
| 5580 |
memcpy(id_priv->id.route.service_recs, recs, sizeof(*recs) * num_recs); |
| 5581 |
|
| 5582 |
addr = (struct sockaddr_ib *)&id_priv->id.route.addr.dst_addr; |
| 5583 |
addr->sib_family = AF_IB; |
| 5584 |
addr->sib_addr = *(struct ib_addr *)&recs->gid; |
| 5585 |
addr->sib_pkey = recs->pkey; |
| 5586 |
addr->sib_sid = recs->id; |
| 5587 |
rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, |
| 5588 |
(union ib_gid *)&addr->sib_addr); |
| 5589 |
ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, |
| 5590 |
ntohs(addr->sib_pkey)); |
| 5591 |
|
| 5592 |
queue_work(cma_wq, &work->work); |
| 5593 |
return; |
| 5594 |
|
| 5595 |
fail: |
| 5596 |
work->old_state = RDMA_CM_ADDRINFO_QUERY; |
| 5597 |
work->new_state = RDMA_CM_ADDR_BOUND; |
| 5598 |
work->event.event = RDMA_CM_EVENT_ADDRINFO_ERROR; |
| 5599 |
work->event.status = status; |
| 5600 |
pr_debug_ratelimited( |
| 5601 |
"RDMA CM: SERVICE_ERROR: failed to query service record. status %d\n", |
| 5602 |
status); |
| 5603 |
queue_work(cma_wq, &work->work); |
| 5604 |
} |
| 5605 |
|
| 5606 |
static int cma_resolve_ib_service(struct rdma_id_private *id_priv, |
| 5607 |
struct rdma_ucm_ib_service *ibs) |
| 5608 |
{ |
| 5609 |
struct sa_service_rec sr = {}; |
| 5610 |
ib_sa_comp_mask mask = 0; |
| 5611 |
struct cma_work *work; |
| 5612 |
|
| 5613 |
work = kzalloc_obj(*work); |
| 5614 |
if (!work) |
| 5615 |
return -ENOMEM; |
| 5616 |
|
| 5617 |
cma_id_get(id_priv); |
| 5618 |
|
| 5619 |
work->id = id_priv; |
| 5620 |
INIT_WORK(&work->work, cma_work_handler); |
| 5621 |
work->old_state = RDMA_CM_ADDRINFO_QUERY; |
| 5622 |
work->new_state = RDMA_CM_ADDRINFO_RESOLVED; |
| 5623 |
work->event.event = RDMA_CM_EVENT_ADDRINFO_RESOLVED; |
| 5624 |
|
| 5625 |
if (ibs->flags & RDMA_USER_CM_IB_SERVICE_FLAG_ID) { |
| 5626 |
sr.id = cpu_to_be64(ibs->service_id); |
| 5627 |
mask |= IB_SA_SERVICE_REC_SERVICE_ID; |
| 5628 |
} |
| 5629 |
if (ibs->flags & RDMA_USER_CM_IB_SERVICE_FLAG_NAME) { |
| 5630 |
strscpy(sr.name, ibs->service_name, sizeof(sr.name)); |
| 5631 |
mask |= IB_SA_SERVICE_REC_SERVICE_NAME; |
| 5632 |
} |
| 5633 |
|
| 5634 |
id_priv->query_id = ib_sa_service_rec_get(&sa_client, |
| 5635 |
id_priv->id.device, |
| 5636 |
id_priv->id.port_num, |
| 5637 |
&sr, mask, |
| 5638 |
2000, GFP_KERNEL, |
| 5639 |
cma_query_ib_service_handler, |
| 5640 |
work, &id_priv->query); |
| 5641 |
|
| 5642 |
if (id_priv->query_id < 0) { |
| 5643 |
cma_id_put(id_priv); |
| 5644 |
kfree(work); |
| 5645 |
return id_priv->query_id; |
| 5646 |
} |
| 5647 |
|
| 5648 |
return 0; |
| 5649 |
} |
| 5650 |
|
| 5651 |
int rdma_resolve_ib_service(struct rdma_cm_id *id, |
| 5652 |
struct rdma_ucm_ib_service *ibs) |
| 5653 |
{ |
| 5654 |
struct rdma_id_private *id_priv; |
| 5655 |
int ret; |
| 5656 |
|
| 5657 |
id_priv = container_of(id, struct rdma_id_private, id); |
| 5658 |
if (!id_priv->cma_dev || |
| 5659 |
!cma_comp_exch(id_priv, RDMA_CM_ADDR_BOUND, RDMA_CM_ADDRINFO_QUERY)) |
| 5660 |
return -EINVAL; |
| 5661 |
|
| 5662 |
if (rdma_cap_ib_sa(id->device, id->port_num)) |
| 5663 |
ret = cma_resolve_ib_service(id_priv, ibs); |
| 5664 |
else |
| 5665 |
ret = -EOPNOTSUPP; |
| 5666 |
|
| 5667 |
if (ret) |
| 5668 |
goto err; |
| 5669 |
|
| 5670 |
return 0; |
| 5671 |
err: |
| 5672 |
cma_comp_exch(id_priv, RDMA_CM_ADDRINFO_QUERY, RDMA_CM_ADDR_BOUND); |
| 5673 |
return ret; |
| 5674 |
} |
| 5675 |
EXPORT_SYMBOL(rdma_resolve_ib_service); |