Lines Matching +full:device +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
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.
64 [RDMA_CM_EVENT_DEVICE_REMOVAL] = "device removal",
83 const char *__attribute_const__ rdma_reject_msg(struct rdma_cm_id *id, in rdma_reject_msg() argument
86 if (rdma_ib_or_roce(id->device, id->port_num)) in rdma_reject_msg()
89 if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_reject_msg()
98 * rdma_is_consumer_reject - return true if the consumer rejected the connect
100 * @id: Communication identifier that received the REJECT event.
103 static bool rdma_is_consumer_reject(struct rdma_cm_id *id, int reason) in rdma_is_consumer_reject() argument
105 if (rdma_ib_or_roce(id->device, id->port_num)) in rdma_is_consumer_reject()
108 if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_is_consumer_reject()
109 return reason == -ECONNREFUSED; in rdma_is_consumer_reject()
115 const void *rdma_consumer_reject_data(struct rdma_cm_id *id, in rdma_consumer_reject_data() argument
120 if (rdma_is_consumer_reject(id, ev->status)) { in rdma_consumer_reject_data()
121 *data_len = ev->param.conn.private_data_len; in rdma_consumer_reject_data()
122 p = ev->param.conn.private_data; in rdma_consumer_reject_data()
132 * rdma_iw_cm_id() - return the iw_cm_id pointer for this cm_id.
133 * @id: Communication Identifier
135 struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *id) in rdma_iw_cm_id() argument
139 id_priv = container_of(id, struct rdma_id_private, id); in rdma_iw_cm_id()
140 if (id->device->node_type == RDMA_NODE_RNIC) in rdma_iw_cm_id()
141 return id_priv->cm_id.iw; in rdma_iw_cm_id()
147 * rdma_res_to_id() - return the rdma_cm_id pointer for this restrack.
155 return &id_priv->id; in rdma_res_to_id()
159 static int cma_add_one(struct ib_device *device);
160 static void cma_remove_one(struct ib_device *device, void *client_data);
194 return &pernet->tcp_ps; in cma_pernet_xa()
196 return &pernet->udp_ps; in cma_pernet_xa()
198 return &pernet->ipoib_ps; in cma_pernet_xa()
200 return &pernet->ib_ps; in cma_pernet_xa()
208 struct ib_device *device; member
224 struct ib_device *device; member
260 refcount_inc(&cma_dev->refcount); in cma_dev_get()
265 if (refcount_dec_and_test(&cma_dev->refcount)) in cma_dev_put()
266 complete(&cma_dev->comp); in cma_dev_put()
278 if (filter(cma_dev->device, cookie)) { in cma_enum_devices_by_ibdev()
292 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_get_default_gid_type()
293 return -EINVAL; in cma_get_default_gid_type()
295 return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)]; in cma_get_default_gid_type()
304 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_set_default_gid_type()
305 return -EINVAL; in cma_set_default_gid_type()
308 rdma_protocol_roce_eth_encap(cma_dev->device, port)) in cma_set_default_gid_type()
311 supported_gids = roce_gid_type_mask_support(cma_dev->device, port); in cma_set_default_gid_type()
314 return -EINVAL; in cma_set_default_gid_type()
316 cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)] = in cma_set_default_gid_type()
324 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_get_default_roce_tos()
325 return -EINVAL; in cma_get_default_roce_tos()
327 return cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)]; in cma_get_default_roce_tos()
333 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_set_default_roce_tos()
334 return -EINVAL; in cma_set_default_roce_tos()
336 cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)] = in cma_set_default_roce_tos()
343 return cma_dev->device; in cma_get_ib_dev()
347 * Device removal can occur at anytime, so we need extra handling to
348 * serialize notifying the user of device removal with other callbacks.
364 struct rdma_id_private *id; member
391 struct ib_device *device; member
412 lockdep_assert_held(&id_priv->handler_mutex); in cma_comp_exch()
414 spin_lock_irqsave(&id_priv->lock, flags); in cma_comp_exch()
415 if ((ret = (id_priv->state == comp))) in cma_comp_exch()
416 id_priv->state = exch; in cma_comp_exch()
417 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_comp_exch()
423 return hdr->ip_version >> 4; in cma_get_ip_ver()
428 hdr->ip_version = (ip_ver << 4) | (hdr->ip_version & 0xF); in cma_set_ip_ver()
441 *(__be32 *)(mgid->raw + 12)); in cma_igmp_send()
444 *(__be32 *)(mgid->raw + 12)); in cma_igmp_send()
448 return (in_dev) ? 0 : -ENODEV; in cma_igmp_send()
455 id_priv->cma_dev = cma_dev; in _cma_attach_to_dev()
456 id_priv->id.device = cma_dev->device; in _cma_attach_to_dev()
457 id_priv->id.route.addr.dev_addr.transport = in _cma_attach_to_dev()
458 rdma_node_get_transport(cma_dev->device->node_type); in _cma_attach_to_dev()
459 list_add_tail(&id_priv->list, &cma_dev->id_list); in _cma_attach_to_dev()
460 rdma_restrack_add(&id_priv->res); in _cma_attach_to_dev()
462 trace_cm_id_attach(id_priv, cma_dev->device); in _cma_attach_to_dev()
469 id_priv->gid_type = in cma_attach_to_dev()
470 cma_dev->default_gid_type[id_priv->id.port_num - in cma_attach_to_dev()
471 rdma_start_port(cma_dev->device)]; in cma_attach_to_dev()
477 list_del(&id_priv->list); in cma_release_dev()
478 cma_dev_put(id_priv->cma_dev); in cma_release_dev()
479 id_priv->cma_dev = NULL; in cma_release_dev()
485 return (struct sockaddr *) &id_priv->id.route.addr.src_addr; in cma_src_addr()
490 return (struct sockaddr *) &id_priv->id.route.addr.dst_addr; in cma_dst_addr()
495 return id_priv->id.route.addr.src_addr.ss_family; in cma_family()
503 if (id_priv->qkey) { in cma_set_qkey()
504 if (qkey && id_priv->qkey != qkey) in cma_set_qkey()
505 return -EINVAL; in cma_set_qkey()
510 id_priv->qkey = qkey; in cma_set_qkey()
514 switch (id_priv->id.ps) { in cma_set_qkey()
517 id_priv->qkey = RDMA_UDP_QKEY; in cma_set_qkey()
520 ib_addr_get_mgid(&id_priv->id.route.addr.dev_addr, &rec.mgid); in cma_set_qkey()
521 ret = ib_sa_get_mcmember_rec(id_priv->id.device, in cma_set_qkey()
522 id_priv->id.port_num, &rec.mgid, in cma_set_qkey()
525 id_priv->qkey = be32_to_cpu(rec.qkey); in cma_set_qkey()
535 dev_addr->dev_type = ARPHRD_INFINIBAND; in cma_translate_ib()
536 rdma_addr_set_sgid(dev_addr, (union ib_gid *) &sib->sib_addr); in cma_translate_ib()
537 ib_addr_set_pkey(dev_addr, ntohs(sib->sib_pkey)); in cma_translate_ib()
544 if (addr->sa_family != AF_IB) { in cma_translate_addr()
555 cma_validate_port(struct ib_device *device, u8 port, in cma_validate_port() argument
560 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_validate_port()
561 int bound_if_index = dev_addr->bound_dev_if; in cma_validate_port()
563 int dev_type = dev_addr->dev_type; in cma_validate_port()
566 if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net)) in cma_validate_port()
567 return ERR_PTR(-ENODEV); in cma_validate_port()
569 if ((dev_type == ARPHRD_INFINIBAND) && !rdma_protocol_ib(device, port)) in cma_validate_port()
570 return ERR_PTR(-ENODEV); in cma_validate_port()
572 if ((dev_type != ARPHRD_INFINIBAND) && rdma_protocol_ib(device, port)) in cma_validate_port()
573 return ERR_PTR(-ENODEV); in cma_validate_port()
575 if (dev_type == ARPHRD_ETHER && rdma_protocol_roce(device, port)) { in cma_validate_port()
576 ndev = dev_get_by_index(dev_addr->net, bound_if_index); in cma_validate_port()
578 return ERR_PTR(-ENODEV); in cma_validate_port()
583 sgid_attr = rdma_find_gid_by_port(device, gid, gid_type, port, ndev); in cma_validate_port()
592 WARN_ON(id_priv->id.route.addr.dev_addr.sgid_attr); in cma_bind_sgid_attr()
593 id_priv->id.route.addr.dev_addr.sgid_attr = sgid_attr; in cma_bind_sgid_attr()
597 * cma_acquire_dev_by_src_ip - Acquire cma device, port, gid attribute
599 * @id_priv: cm_id which should be bound to cma device
601 * cma_acquire_dev_by_src_ip() binds cm id to cma device, port and GID attribute
607 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_acquire_dev_by_src_ip()
612 int ret = -ENODEV; in cma_acquire_dev_by_src_ip()
615 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_acquire_dev_by_src_ip()
616 id_priv->id.ps == RDMA_PS_IPOIB) in cma_acquire_dev_by_src_ip()
617 return -EINVAL; in cma_acquire_dev_by_src_ip()
619 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_acquire_dev_by_src_ip()
622 memcpy(&gid, dev_addr->src_dev_addr + in cma_acquire_dev_by_src_ip()
627 rdma_for_each_port (cma_dev->device, port) { in cma_acquire_dev_by_src_ip()
628 gidp = rdma_protocol_roce(cma_dev->device, port) ? in cma_acquire_dev_by_src_ip()
630 gid_type = cma_dev->default_gid_type[port - 1]; in cma_acquire_dev_by_src_ip()
631 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_acquire_dev_by_src_ip()
634 id_priv->id.port_num = port; in cma_acquire_dev_by_src_ip()
648 * cma_ib_acquire_dev - Acquire cma device, port and SGID attribute
649 * @id_priv: cm id to bind to cma device
650 * @listen_id_priv: listener cm id to match against
653 * cma_ib_acquire_dev() acquires cma device, port and SGID attribute when
654 * rdma device matches for listen_id and incoming request. It also verifies
662 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_acquire_dev()
667 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_ib_acquire_dev()
668 id_priv->id.ps == RDMA_PS_IPOIB) in cma_ib_acquire_dev()
669 return -EINVAL; in cma_ib_acquire_dev()
671 if (rdma_protocol_roce(req->device, req->port)) in cma_ib_acquire_dev()
672 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_ib_acquire_dev()
675 memcpy(&gid, dev_addr->src_dev_addr + in cma_ib_acquire_dev()
678 gid_type = listen_id_priv->cma_dev->default_gid_type[req->port - 1]; in cma_ib_acquire_dev()
679 sgid_attr = cma_validate_port(req->device, req->port, in cma_ib_acquire_dev()
684 id_priv->id.port_num = req->port; in cma_ib_acquire_dev()
687 * of cma_dev->id_list such as cma_netdev_callback() and in cma_ib_acquire_dev()
691 cma_attach_to_dev(id_priv, listen_id_priv->cma_dev); in cma_ib_acquire_dev()
699 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iw_acquire_dev()
703 int ret = -ENODEV; in cma_iw_acquire_dev()
707 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_iw_acquire_dev()
708 id_priv->id.ps == RDMA_PS_IPOIB) in cma_iw_acquire_dev()
709 return -EINVAL; in cma_iw_acquire_dev()
711 memcpy(&gid, dev_addr->src_dev_addr + in cma_iw_acquire_dev()
716 cma_dev = listen_id_priv->cma_dev; in cma_iw_acquire_dev()
717 port = listen_id_priv->id.port_num; in cma_iw_acquire_dev()
718 gid_type = listen_id_priv->gid_type; in cma_iw_acquire_dev()
719 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
722 id_priv->id.port_num = port; in cma_iw_acquire_dev()
729 rdma_for_each_port (cma_dev->device, port) { in cma_iw_acquire_dev()
730 if (listen_id_priv->cma_dev == cma_dev && in cma_iw_acquire_dev()
731 listen_id_priv->id.port_num == port) in cma_iw_acquire_dev()
734 gid_type = cma_dev->default_gid_type[port - 1]; in cma_iw_acquire_dev()
735 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
738 id_priv->id.port_num = port; in cma_iw_acquire_dev()
755 * Select the source IB device and address to reach the destination IB address.
769 dgid = (union ib_gid *) &addr->sib_addr; in cma_resolve_ib_dev()
770 pkey = ntohs(addr->sib_pkey); in cma_resolve_ib_dev()
774 rdma_for_each_port (cur_dev->device, p) { in cma_resolve_ib_dev()
775 if (!rdma_cap_af_ib(cur_dev->device, p)) in cma_resolve_ib_dev()
778 if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index)) in cma_resolve_ib_dev()
781 if (ib_get_cached_port_state(cur_dev->device, p, &port_state)) in cma_resolve_ib_dev()
783 for (i = 0; !rdma_query_gid(cur_dev->device, in cma_resolve_ib_dev()
789 id_priv->id.port_num = p; in cma_resolve_ib_dev()
794 dgid->global.subnet_prefix) && in cma_resolve_ib_dev()
798 id_priv->id.port_num = p; in cma_resolve_ib_dev()
805 return -ENODEV; in cma_resolve_ib_dev()
811 memcpy(&addr->sib_addr, &sgid, sizeof(sgid)); in cma_resolve_ib_dev()
812 cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); in cma_resolve_ib_dev()
818 refcount_inc(&id_priv->refcount); in cma_id_get()
823 if (refcount_dec_and_test(&id_priv->refcount)) in cma_id_put()
824 complete(&id_priv->comp); in cma_id_put()
836 return ERR_PTR(-ENOMEM); in __rdma_create_id()
838 id_priv->state = RDMA_CM_IDLE; in __rdma_create_id()
839 id_priv->id.context = context; in __rdma_create_id()
840 id_priv->id.event_handler = event_handler; in __rdma_create_id()
841 id_priv->id.ps = ps; in __rdma_create_id()
842 id_priv->id.qp_type = qp_type; in __rdma_create_id()
843 id_priv->tos_set = false; in __rdma_create_id()
844 id_priv->timeout_set = false; in __rdma_create_id()
845 id_priv->gid_type = IB_GID_TYPE_IB; in __rdma_create_id()
846 spin_lock_init(&id_priv->lock); in __rdma_create_id()
847 mutex_init(&id_priv->qp_mutex); in __rdma_create_id()
848 init_completion(&id_priv->comp); in __rdma_create_id()
849 refcount_set(&id_priv->refcount, 1); in __rdma_create_id()
850 mutex_init(&id_priv->handler_mutex); in __rdma_create_id()
851 INIT_LIST_HEAD(&id_priv->listen_list); in __rdma_create_id()
852 INIT_LIST_HEAD(&id_priv->mc_list); in __rdma_create_id()
853 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); in __rdma_create_id()
854 id_priv->id.route.addr.dev_addr.net = get_net(net); in __rdma_create_id()
855 id_priv->seq_num &= 0x00ffffff; in __rdma_create_id()
857 rdma_restrack_new(&id_priv->res, RDMA_RESTRACK_CM_ID); in __rdma_create_id()
859 rdma_restrack_parent_name(&id_priv->res, &parent->res); in __rdma_create_id()
875 rdma_restrack_set_name(&ret->res, caller); in __rdma_create_kernel_id()
876 return &ret->id; in __rdma_create_kernel_id()
887 ret = __rdma_create_id(current->nsproxy->net_ns, event_handler, context, in rdma_create_user_id()
892 rdma_restrack_set_name(&ret->res, NULL); in rdma_create_user_id()
893 return &ret->id; in rdma_create_user_id()
903 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_ud_qp()
929 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_conn_qp()
936 int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, in rdma_create_qp() argument
943 id_priv = container_of(id, struct rdma_id_private, id); in rdma_create_qp()
944 if (id->device != pd->device) { in rdma_create_qp()
945 ret = -EINVAL; in rdma_create_qp()
949 qp_init_attr->port_num = id->port_num; in rdma_create_qp()
956 if (id->qp_type == IB_QPT_UD) in rdma_create_qp()
963 id->qp = qp; in rdma_create_qp()
964 id_priv->qp_num = qp->qp_num; in rdma_create_qp()
965 id_priv->srq = (qp->srq != NULL); in rdma_create_qp()
976 void rdma_destroy_qp(struct rdma_cm_id *id) in rdma_destroy_qp() argument
980 id_priv = container_of(id, struct rdma_id_private, id); in rdma_destroy_qp()
982 mutex_lock(&id_priv->qp_mutex); in rdma_destroy_qp()
983 ib_destroy_qp(id_priv->id.qp); in rdma_destroy_qp()
984 id_priv->id.qp = NULL; in rdma_destroy_qp()
985 mutex_unlock(&id_priv->qp_mutex); in rdma_destroy_qp()
995 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
996 if (!id_priv->id.qp) { in cma_modify_qp_rtr()
1003 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1007 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1012 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1016 BUG_ON(id_priv->cma_dev->device != id_priv->id.device); in cma_modify_qp_rtr()
1019 qp_attr.max_dest_rd_atomic = conn_param->responder_resources; in cma_modify_qp_rtr()
1020 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1022 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
1032 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1033 if (!id_priv->id.qp) { in cma_modify_qp_rts()
1039 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rts()
1044 qp_attr.max_rd_atomic = conn_param->initiator_depth; in cma_modify_qp_rts()
1045 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rts()
1047 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1056 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_err()
1057 if (!id_priv->id.qp) { in cma_modify_qp_err()
1063 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, IB_QP_STATE); in cma_modify_qp_err()
1065 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_err()
1072 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_init_qp_attr()
1076 if (rdma_cap_eth_ah(id_priv->id.device, id_priv->id.port_num)) in cma_ib_init_qp_attr()
1081 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, in cma_ib_init_qp_attr()
1082 pkey, &qp_attr->pkey_index); in cma_ib_init_qp_attr()
1086 qp_attr->port_num = id_priv->id.port_num; in cma_ib_init_qp_attr()
1089 if (id_priv->id.qp_type == IB_QPT_UD) { in cma_ib_init_qp_attr()
1094 qp_attr->qkey = id_priv->qkey; in cma_ib_init_qp_attr()
1097 qp_attr->qp_access_flags = 0; in cma_ib_init_qp_attr()
1103 int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, in rdma_init_qp_attr() argument
1109 id_priv = container_of(id, struct rdma_id_private, id); in rdma_init_qp_attr()
1110 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1111 if (!id_priv->cm_id.ib || (id_priv->id.qp_type == IB_QPT_UD)) in rdma_init_qp_attr()
1114 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, in rdma_init_qp_attr()
1117 if (qp_attr->qp_state == IB_QPS_RTR) in rdma_init_qp_attr()
1118 qp_attr->rq_psn = id_priv->seq_num; in rdma_init_qp_attr()
1119 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1120 if (!id_priv->cm_id.iw) { in rdma_init_qp_attr()
1121 qp_attr->qp_access_flags = 0; in rdma_init_qp_attr()
1124 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, in rdma_init_qp_attr()
1126 qp_attr->port_num = id_priv->id.port_num; in rdma_init_qp_attr()
1129 ret = -ENOSYS; in rdma_init_qp_attr()
1131 if ((*qp_attr_mask & IB_QP_TIMEOUT) && id_priv->timeout_set) in rdma_init_qp_attr()
1132 qp_attr->timeout = id_priv->timeout; in rdma_init_qp_attr()
1140 switch (addr->sa_family) { in cma_zero_addr()
1142 return ipv4_is_zeronet(((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_zero_addr()
1144 return ipv6_addr_any(&((struct sockaddr_in6 *)addr)->sin6_addr); in cma_zero_addr()
1146 return ib_addr_any(&((struct sockaddr_ib *)addr)->sib_addr); in cma_zero_addr()
1154 switch (addr->sa_family) { in cma_loopback_addr()
1157 ((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_loopback_addr()
1160 &((struct sockaddr_in6 *)addr)->sin6_addr); in cma_loopback_addr()
1163 &((struct sockaddr_ib *)addr)->sib_addr); in cma_loopback_addr()
1176 if (src->sa_family != dst->sa_family) in cma_addr_cmp()
1177 return -1; in cma_addr_cmp()
1179 switch (src->sa_family) { in cma_addr_cmp()
1181 return ((struct sockaddr_in *)src)->sin_addr.s_addr != in cma_addr_cmp()
1182 ((struct sockaddr_in *)dst)->sin_addr.s_addr; in cma_addr_cmp()
1188 if (ipv6_addr_cmp(&src_addr6->sin6_addr, in cma_addr_cmp()
1189 &dst_addr6->sin6_addr)) in cma_addr_cmp()
1191 link_local = ipv6_addr_type(&dst_addr6->sin6_addr) & in cma_addr_cmp()
1194 return link_local ? (src_addr6->sin6_scope_id != in cma_addr_cmp()
1195 dst_addr6->sin6_scope_id) : in cma_addr_cmp()
1200 return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, in cma_addr_cmp()
1201 &((struct sockaddr_ib *) dst)->sib_addr); in cma_addr_cmp()
1209 switch (addr->sa_family) { in cma_port()
1211 return ((struct sockaddr_in *) addr)->sin_port; in cma_port()
1213 return ((struct sockaddr_in6 *) addr)->sin6_port; in cma_port()
1216 return htons((u16) (be64_to_cpu(sib->sib_sid) & in cma_port()
1217 be64_to_cpu(sib->sib_sid_mask))); in cma_port()
1235 listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; in cma_save_ib_info()
1238 ib->sib_family = AF_IB; in cma_save_ib_info()
1240 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1241 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1242 memcpy(&ib->sib_addr, &path->sgid, 16); in cma_save_ib_info()
1243 ib->sib_sid = path->service_id; in cma_save_ib_info()
1244 ib->sib_scope_id = 0; in cma_save_ib_info()
1246 ib->sib_pkey = listen_ib->sib_pkey; in cma_save_ib_info()
1247 ib->sib_flowinfo = listen_ib->sib_flowinfo; in cma_save_ib_info()
1248 ib->sib_addr = listen_ib->sib_addr; in cma_save_ib_info()
1249 ib->sib_sid = listen_ib->sib_sid; in cma_save_ib_info()
1250 ib->sib_scope_id = listen_ib->sib_scope_id; in cma_save_ib_info()
1252 ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); in cma_save_ib_info()
1256 ib->sib_family = AF_IB; in cma_save_ib_info()
1258 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1259 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1260 memcpy(&ib->sib_addr, &path->dgid, 16); in cma_save_ib_info()
1273 .sin_addr.s_addr = hdr->dst_addr.ip4.addr, in cma_save_ip4_info()
1281 .sin_addr.s_addr = hdr->src_addr.ip4.addr, in cma_save_ip4_info()
1282 .sin_port = hdr->port, in cma_save_ip4_info()
1295 .sin6_addr = hdr->dst_addr.ip6, in cma_save_ip6_info()
1303 .sin6_addr = hdr->src_addr.ip6, in cma_save_ip6_info()
1304 .sin6_port = hdr->port, in cma_save_ip6_info()
1322 hdr = ib_event->private_data; in cma_save_ip_info()
1323 if (hdr->cma_version != CMA_VERSION) in cma_save_ip_info()
1324 return -EINVAL; in cma_save_ip_info()
1338 return -EAFNOSUPPORT; in cma_save_ip_info()
1351 if (ib_event->event == IB_CM_REQ_RECEIVED) in cma_save_net_info()
1353 ib_event->param.req_rcvd.primary_path); in cma_save_net_info()
1354 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in cma_save_net_info()
1366 &ib_event->param.req_rcvd; in cma_save_req_info()
1368 &ib_event->param.sidr_req_rcvd; in cma_save_req_info()
1370 switch (ib_event->event) { in cma_save_req_info()
1372 req->device = req_param->listen_id->device; in cma_save_req_info()
1373 req->port = req_param->port; in cma_save_req_info()
1374 memcpy(&req->local_gid, &req_param->primary_path->sgid, in cma_save_req_info()
1375 sizeof(req->local_gid)); in cma_save_req_info()
1376 req->has_gid = true; in cma_save_req_info()
1377 req->service_id = req_param->primary_path->service_id; in cma_save_req_info()
1378 req->pkey = be16_to_cpu(req_param->primary_path->pkey); in cma_save_req_info()
1379 if (req->pkey != req_param->bth_pkey) in cma_save_req_info()
1382 req_param->bth_pkey, req->pkey); in cma_save_req_info()
1385 req->device = sidr_param->listen_id->device; in cma_save_req_info()
1386 req->port = sidr_param->port; in cma_save_req_info()
1387 req->has_gid = false; in cma_save_req_info()
1388 req->service_id = sidr_param->service_id; in cma_save_req_info()
1389 req->pkey = sidr_param->pkey; in cma_save_req_info()
1390 if (req->pkey != sidr_param->bth_pkey) in cma_save_req_info()
1393 sidr_param->bth_pkey, req->pkey); in cma_save_req_info()
1396 return -EINVAL; in cma_save_req_info()
1406 __be32 daddr = dst_addr->sin_addr.s_addr, in validate_ipv4_net_dev()
1407 saddr = src_addr->sin_addr.s_addr; in validate_ipv4_net_dev()
1420 fl4.flowi4_iif = net_dev->ifindex; in validate_ipv4_net_dev()
1437 const int strict = ipv6_addr_type(&dst_addr->sin6_addr) & in validate_ipv6_net_dev()
1439 struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr, in validate_ipv6_net_dev()
1440 &src_addr->sin6_addr, net_dev->ifindex, in validate_ipv6_net_dev()
1447 ret = rt->rt6i_idev->dev == net_dev; in validate_ipv6_net_dev()
1465 switch (daddr->sa_family) { in validate_net_dev()
1467 return saddr->sa_family == AF_INET && in validate_net_dev()
1471 return saddr->sa_family == AF_INET6 && in validate_net_dev()
1485 if (ib_event->event == IB_CM_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1486 sgid_attr = ib_event->param.req_rcvd.ppath_sgid_attr; in roce_get_net_dev_by_cm_event()
1487 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1488 sgid_attr = ib_event->param.sidr_req_rcvd.sgid_attr; in roce_get_net_dev_by_cm_event()
1507 (struct sockaddr *)&req->listen_addr_storage; in cma_get_net_dev()
1508 struct sockaddr *src_addr = (struct sockaddr *)&req->src_addr_storage; in cma_get_net_dev()
1510 const union ib_gid *gid = req->has_gid ? &req->local_gid : NULL; in cma_get_net_dev()
1514 req->service_id); in cma_get_net_dev()
1518 if (rdma_protocol_roce(req->device, req->port)) in cma_get_net_dev()
1521 net_dev = ib_get_net_dev_by_params(req->device, req->port, in cma_get_net_dev()
1522 req->pkey, in cma_get_net_dev()
1525 return ERR_PTR(-ENODEV); in cma_get_net_dev()
1542 if (cma_any_addr(addr) && !id_priv->afonly) in cma_match_private_data()
1545 switch (addr->sa_family) { in cma_match_private_data()
1547 ip4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; in cma_match_private_data()
1551 hdr->dst_addr.ip4.addr != ip4_addr) in cma_match_private_data()
1555 ip6_addr = ((struct sockaddr_in6 *)addr)->sin6_addr; in cma_match_private_data()
1559 memcmp(&hdr->dst_addr.ip6, &ip6_addr, sizeof(ip6_addr))) in cma_match_private_data()
1571 static bool cma_protocol_roce(const struct rdma_cm_id *id) in cma_protocol_roce() argument
1573 struct ib_device *device = id->device; in cma_protocol_roce() local
1574 const int port_num = id->port_num ?: rdma_start_port(device); in cma_protocol_roce()
1576 return rdma_protocol_roce(device, port_num); in cma_protocol_roce()
1582 (const struct sockaddr *)&req->listen_addr_storage; in cma_is_req_ipv6_ll()
1586 return (daddr->sa_family == AF_INET6 && in cma_is_req_ipv6_ll()
1587 (ipv6_addr_type(&daddr6->sin6_addr) & IPV6_ADDR_LINKLOCAL)); in cma_is_req_ipv6_ll()
1590 static bool cma_match_net_dev(const struct rdma_cm_id *id, in cma_match_net_dev() argument
1594 const struct rdma_addr *addr = &id->route.addr; in cma_match_net_dev()
1598 return (!id->port_num || id->port_num == req->port) && in cma_match_net_dev()
1599 (addr->src_addr.ss_family == AF_IB); in cma_match_net_dev()
1603 * request to any netdevice of the one or multiport rdma device. in cma_match_net_dev()
1611 if (net_eq(dev_net(net_dev), addr->dev_addr.net) && in cma_match_net_dev()
1612 (!!addr->dev_addr.bound_dev_if == in cma_match_net_dev()
1613 (addr->dev_addr.bound_dev_if == net_dev->ifindex))) in cma_match_net_dev()
1631 return ERR_PTR(-EINVAL); in cma_find_listener()
1633 hlist_for_each_entry(id_priv, &bind_list->owners, node) { in cma_find_listener()
1634 if (cma_match_private_data(id_priv, ib_event->private_data)) { in cma_find_listener()
1635 if (id_priv->id.device == cm_id->device && in cma_find_listener()
1636 cma_match_net_dev(&id_priv->id, net_dev, req)) in cma_find_listener()
1639 &id_priv->listen_list, in cma_find_listener()
1641 if (id_priv_dev->id.device == cm_id->device && in cma_find_listener()
1642 cma_match_net_dev(&id_priv_dev->id, in cma_find_listener()
1649 return ERR_PTR(-EINVAL); in cma_find_listener()
1668 if (PTR_ERR(*net_dev) == -EAFNOSUPPORT) { in cma_ib_id_from_event()
1685 * If the device state is not IFF_UP, its properties such as ifindex in cma_ib_id_from_event()
1688 * ongoing operations on net device after device is closed using in cma_ib_id_from_event()
1699 if (((*net_dev)->flags & IFF_UP) == 0) { in cma_ib_id_from_event()
1700 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1705 (struct sockaddr *)&req->listen_addr_storage, in cma_ib_id_from_event()
1706 (struct sockaddr *)&req->src_addr_storage)) { in cma_ib_id_from_event()
1707 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1713 rdma_ps_from_service_id(req->service_id), in cma_ib_id_from_event()
1714 cma_port_from_service_id(req->service_id)); in cma_ib_id_from_event()
1733 if (rdma_cap_ib_sa(id_priv->id.device, id_priv->id.port_num)) { in cma_cancel_route()
1734 if (id_priv->query) in cma_cancel_route()
1735 ib_sa_cancel_query(id_priv->query_id, id_priv->query); in cma_cancel_route()
1748 list_del(&id_priv->list); in cma_cancel_listens()
1750 while (!list_empty(&id_priv->listen_list)) { in cma_cancel_listens()
1751 dev_id_priv = list_entry(id_priv->listen_list.next, in cma_cancel_listens()
1753 /* sync with device removal to avoid duplicate destruction */ in cma_cancel_listens()
1754 list_del_init(&dev_id_priv->list); in cma_cancel_listens()
1755 list_del(&dev_id_priv->listen_list); in cma_cancel_listens()
1758 rdma_destroy_id(&dev_id_priv->id); in cma_cancel_listens()
1769 rdma_addr_cancel(&id_priv->id.route.addr.dev_addr); in cma_cancel_operation()
1775 if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev) in cma_cancel_operation()
1785 struct rdma_bind_list *bind_list = id_priv->bind_list; in cma_release_port()
1786 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_release_port()
1792 hlist_del(&id_priv->node); in cma_release_port()
1793 if (hlist_empty(&bind_list->owners)) { in cma_release_port()
1794 cma_ps_remove(net, bind_list->ps, bind_list->port); in cma_release_port()
1803 if (rdma_cap_ib_mcast(id_priv->id.device, id_priv->id.port_num)) in destroy_mc()
1804 ib_sa_free_multicast(mc->sa_mc); in destroy_mc()
1806 if (rdma_protocol_roce(id_priv->id.device, id_priv->id.port_num)) { in destroy_mc()
1808 &id_priv->id.route.addr.dev_addr; in destroy_mc()
1811 if (dev_addr->bound_dev_if) in destroy_mc()
1812 ndev = dev_get_by_index(dev_addr->net, in destroy_mc()
1813 dev_addr->bound_dev_if); in destroy_mc()
1817 cma_set_mgid(id_priv, (struct sockaddr *)&mc->addr, in destroy_mc()
1830 while (!list_empty(&id_priv->mc_list)) { in cma_leave_mc_groups()
1831 mc = list_first_entry(&id_priv->mc_list, struct cma_multicast, in cma_leave_mc_groups()
1833 list_del(&mc->list); in cma_leave_mc_groups()
1843 if (id_priv->cma_dev) { in _destroy_id()
1844 if (rdma_cap_ib_cm(id_priv->id.device, 1)) { in _destroy_id()
1845 if (id_priv->cm_id.ib) in _destroy_id()
1846 ib_destroy_cm_id(id_priv->cm_id.ib); in _destroy_id()
1847 } else if (rdma_cap_iw_cm(id_priv->id.device, 1)) { in _destroy_id()
1848 if (id_priv->cm_id.iw) in _destroy_id()
1849 iw_destroy_cm_id(id_priv->cm_id.iw); in _destroy_id()
1857 wait_for_completion(&id_priv->comp); in _destroy_id()
1859 if (id_priv->internal_id) in _destroy_id()
1860 cma_id_put(id_priv->id.context); in _destroy_id()
1862 kfree(id_priv->id.route.path_rec); in _destroy_id()
1864 if (id_priv->id.route.addr.dev_addr.sgid_attr) in _destroy_id()
1865 rdma_put_gid_attr(id_priv->id.route.addr.dev_addr.sgid_attr); in _destroy_id()
1867 put_net(id_priv->id.route.addr.dev_addr.net); in _destroy_id()
1868 rdma_restrack_del(&id_priv->res); in _destroy_id()
1873 * destroy an ID from within the handler_mutex. This ensures that no other
1877 __releases(&idprv->handler_mutex) in destroy_id_handler_unlock()
1890 lockdep_assert_held(&id_priv->handler_mutex); in destroy_id_handler_unlock()
1891 spin_lock_irqsave(&id_priv->lock, flags); in destroy_id_handler_unlock()
1892 state = id_priv->state; in destroy_id_handler_unlock()
1893 id_priv->state = RDMA_CM_DESTROYING; in destroy_id_handler_unlock()
1894 spin_unlock_irqrestore(&id_priv->lock, flags); in destroy_id_handler_unlock()
1895 mutex_unlock(&id_priv->handler_mutex); in destroy_id_handler_unlock()
1899 void rdma_destroy_id(struct rdma_cm_id *id) in rdma_destroy_id() argument
1902 container_of(id, struct rdma_id_private, id); in rdma_destroy_id()
1904 mutex_lock(&id_priv->handler_mutex); in rdma_destroy_id()
1922 ret = ib_send_cm_rtu(id_priv->cm_id.ib, NULL, 0); in cma_rep_recv()
1931 ib_send_cm_rej(id_priv->cm_id.ib, IB_CM_REJ_CONSUMER_DEFINED, in cma_rep_recv()
1940 event->param.conn.private_data = private_data; in cma_set_rep_event_data()
1941 event->param.conn.private_data_len = IB_CM_REP_PRIVATE_DATA_SIZE; in cma_set_rep_event_data()
1942 event->param.conn.responder_resources = rep_data->responder_resources; in cma_set_rep_event_data()
1943 event->param.conn.initiator_depth = rep_data->initiator_depth; in cma_set_rep_event_data()
1944 event->param.conn.flow_control = rep_data->flow_control; in cma_set_rep_event_data()
1945 event->param.conn.rnr_retry_count = rep_data->rnr_retry_count; in cma_set_rep_event_data()
1946 event->param.conn.srq = rep_data->srq; in cma_set_rep_event_data()
1947 event->param.conn.qp_num = rep_data->remote_qpn; in cma_set_rep_event_data()
1949 event->ece.vendor_id = rep_data->ece.vendor_id; in cma_set_rep_event_data()
1950 event->ece.attr_mod = rep_data->ece.attr_mod; in cma_set_rep_event_data()
1958 lockdep_assert_held(&id_priv->handler_mutex); in cma_cm_event_handler()
1961 ret = id_priv->id.event_handler(&id_priv->id, event); in cma_cm_event_handler()
1969 struct rdma_id_private *id_priv = cm_id->context; in cma_ib_handler()
1974 mutex_lock(&id_priv->handler_mutex); in cma_ib_handler()
1975 state = READ_ONCE(id_priv->state); in cma_ib_handler()
1976 if ((ib_event->event != IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
1978 (ib_event->event == IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
1982 switch (ib_event->event) { in cma_ib_handler()
1986 event.status = -ETIMEDOUT; in cma_ib_handler()
1990 (id_priv->id.qp_type != IB_QPT_UD)) { in cma_ib_handler()
1994 if (id_priv->id.qp) { in cma_ib_handler()
2001 cma_set_rep_event_data(&event, &ib_event->param.rep_rcvd, in cma_ib_handler()
2002 ib_event->private_data); in cma_ib_handler()
2009 event.status = -ETIMEDOUT; in cma_ib_handler()
2025 pr_debug_ratelimited("RDMA CM: REJECTED: %s\n", rdma_reject_msg(&id_priv->id, in cma_ib_handler()
2026 ib_event->param.rej_rcvd.reason)); in cma_ib_handler()
2028 event.status = ib_event->param.rej_rcvd.reason; in cma_ib_handler()
2030 event.param.conn.private_data = ib_event->private_data; in cma_ib_handler()
2035 ib_event->event); in cma_ib_handler()
2041 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_handler()
2042 id_priv->cm_id.ib = NULL; in cma_ib_handler()
2047 mutex_unlock(&id_priv->handler_mutex); in cma_ib_handler()
2058 struct rdma_cm_id *id; in cma_ib_new_conn_id() local
2060 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_conn_id()
2061 struct sa_path_rec *path = ib_event->param.req_rcvd.primary_path; in cma_ib_new_conn_id()
2063 ib_event->param.req_rcvd.primary_path->service_id; in cma_ib_new_conn_id()
2066 listen_id_priv = container_of(listen_id, struct rdma_id_private, id); in cma_ib_new_conn_id()
2067 id_priv = __rdma_create_id(listen_id->route.addr.dev_addr.net, in cma_ib_new_conn_id()
2068 listen_id->event_handler, listen_id->context, in cma_ib_new_conn_id()
2069 listen_id->ps, in cma_ib_new_conn_id()
2070 ib_event->param.req_rcvd.qp_type, in cma_ib_new_conn_id()
2075 id = &id_priv->id; in cma_ib_new_conn_id()
2076 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_conn_id()
2077 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_conn_id()
2081 rt = &id->route; in cma_ib_new_conn_id()
2082 rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; in cma_ib_new_conn_id()
2083 rt->path_rec = kmalloc_array(rt->num_paths, sizeof(*rt->path_rec), in cma_ib_new_conn_id()
2085 if (!rt->path_rec) in cma_ib_new_conn_id()
2088 rt->path_rec[0] = *path; in cma_ib_new_conn_id()
2089 if (rt->num_paths == 2) in cma_ib_new_conn_id()
2090 rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; in cma_ib_new_conn_id()
2093 rdma_copy_src_l2_addr(&rt->addr.dev_addr, net_dev); in cma_ib_new_conn_id()
2097 rt->addr.dev_addr.dev_type = ARPHRD_INFINIBAND; in cma_ib_new_conn_id()
2098 rdma_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid); in cma_ib_new_conn_id()
2099 ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey)); in cma_ib_new_conn_id()
2101 ret = cma_translate_addr(cma_src_addr(id_priv), &rt->addr.dev_addr); in cma_ib_new_conn_id()
2106 rdma_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid); in cma_ib_new_conn_id()
2108 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_conn_id()
2112 rdma_destroy_id(id); in cma_ib_new_conn_id()
2123 struct rdma_cm_id *id; in cma_ib_new_udp_id() local
2124 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_udp_id()
2125 struct net *net = listen_id->route.addr.dev_addr.net; in cma_ib_new_udp_id()
2128 listen_id_priv = container_of(listen_id, struct rdma_id_private, id); in cma_ib_new_udp_id()
2129 id_priv = __rdma_create_id(net, listen_id->event_handler, in cma_ib_new_udp_id()
2130 listen_id->context, listen_id->ps, IB_QPT_UD, in cma_ib_new_udp_id()
2135 id = &id_priv->id; in cma_ib_new_udp_id()
2136 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_udp_id()
2137 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_udp_id()
2139 ib_event->param.sidr_req_rcvd.service_id)) in cma_ib_new_udp_id()
2143 rdma_copy_src_l2_addr(&id->route.addr.dev_addr, net_dev); in cma_ib_new_udp_id()
2147 &id->route.addr.dev_addr); in cma_ib_new_udp_id()
2153 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_udp_id()
2156 rdma_destroy_id(id); in cma_ib_new_udp_id()
2164 event->param.conn.private_data = private_data + offset; in cma_set_req_event_data()
2165 event->param.conn.private_data_len = IB_CM_REQ_PRIVATE_DATA_SIZE - offset; in cma_set_req_event_data()
2166 event->param.conn.responder_resources = req_data->responder_resources; in cma_set_req_event_data()
2167 event->param.conn.initiator_depth = req_data->initiator_depth; in cma_set_req_event_data()
2168 event->param.conn.flow_control = req_data->flow_control; in cma_set_req_event_data()
2169 event->param.conn.retry_count = req_data->retry_count; in cma_set_req_event_data()
2170 event->param.conn.rnr_retry_count = req_data->rnr_retry_count; in cma_set_req_event_data()
2171 event->param.conn.srq = req_data->srq; in cma_set_req_event_data()
2172 event->param.conn.qp_num = req_data->remote_qpn; in cma_set_req_event_data()
2174 event->ece.vendor_id = req_data->ece.vendor_id; in cma_set_req_event_data()
2175 event->ece.attr_mod = req_data->ece.attr_mod; in cma_set_req_event_data()
2178 static int cma_ib_check_req_qp_type(const struct rdma_cm_id *id, in cma_ib_check_req_qp_type() argument
2181 return (((ib_event->event == IB_CM_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2182 (ib_event->param.req_rcvd.qp_type == id->qp_type)) || in cma_ib_check_req_qp_type()
2183 ((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2184 (id->qp_type == IB_QPT_UD)) || in cma_ib_check_req_qp_type()
2185 (!id->qp_type)); in cma_ib_check_req_qp_type()
2202 trace_cm_req_handler(listen_id, ib_event->event); in cma_ib_req_handler()
2203 if (!cma_ib_check_req_qp_type(&listen_id->id, ib_event)) { in cma_ib_req_handler()
2204 ret = -EINVAL; in cma_ib_req_handler()
2208 mutex_lock(&listen_id->handler_mutex); in cma_ib_req_handler()
2209 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) { in cma_ib_req_handler()
2210 ret = -ECONNABORTED; in cma_ib_req_handler()
2216 if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) { in cma_ib_req_handler()
2217 conn_id = cma_ib_new_udp_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2218 event.param.ud.private_data = ib_event->private_data + offset; in cma_ib_req_handler()
2220 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; in cma_ib_req_handler()
2222 conn_id = cma_ib_new_conn_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2223 cma_set_req_event_data(&event, &ib_event->param.req_rcvd, in cma_ib_req_handler()
2224 ib_event->private_data, offset); in cma_ib_req_handler()
2227 ret = -ENOMEM; in cma_ib_req_handler()
2231 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in cma_ib_req_handler()
2238 conn_id->cm_id.ib = cm_id; in cma_ib_req_handler()
2239 cm_id->context = conn_id; in cma_ib_req_handler()
2240 cm_id->cm_handler = cma_ib_handler; in cma_ib_req_handler()
2244 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_req_handler()
2245 conn_id->cm_id.ib = NULL; in cma_ib_req_handler()
2246 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2251 if (READ_ONCE(conn_id->state) == RDMA_CM_CONNECT && in cma_ib_req_handler()
2252 conn_id->id.qp_type != IB_QPT_UD) { in cma_ib_req_handler()
2253 trace_cm_send_mra(cm_id->context); in cma_ib_req_handler()
2256 mutex_unlock(&conn_id->handler_mutex); in cma_ib_req_handler()
2259 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2268 __be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_get_service_id() argument
2270 if (addr->sa_family == AF_IB) in rdma_get_service_id()
2271 return ((struct sockaddr_ib *) addr)->sib_sid; in rdma_get_service_id()
2273 return cpu_to_be64(((u64)id->ps << 16) + be16_to_cpu(cma_port(addr))); in rdma_get_service_id()
2280 struct rdma_addr *addr = &cm_id->route.addr; in rdma_read_gids()
2282 if (!cm_id->device) { in rdma_read_gids()
2290 if (rdma_protocol_roce(cm_id->device, cm_id->port_num)) { in rdma_read_gids()
2292 rdma_ip2gid((struct sockaddr *)&addr->src_addr, sgid); in rdma_read_gids()
2294 rdma_ip2gid((struct sockaddr *)&addr->dst_addr, dgid); in rdma_read_gids()
2297 rdma_addr_get_sgid(&addr->dev_addr, sgid); in rdma_read_gids()
2299 rdma_addr_get_dgid(&addr->dev_addr, dgid); in rdma_read_gids()
2306 struct rdma_id_private *id_priv = iw_id->context; in cma_iw_handler()
2309 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in cma_iw_handler()
2310 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in cma_iw_handler()
2312 mutex_lock(&id_priv->handler_mutex); in cma_iw_handler()
2313 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_iw_handler()
2316 switch (iw_event->event) { in cma_iw_handler()
2325 switch (iw_event->status) { in cma_iw_handler()
2328 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2329 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2331 case -ECONNRESET: in cma_iw_handler()
2332 case -ECONNREFUSED: in cma_iw_handler()
2335 case -ETIMEDOUT: in cma_iw_handler()
2345 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2346 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2352 event.status = iw_event->status; in cma_iw_handler()
2353 event.param.conn.private_data = iw_event->private_data; in cma_iw_handler()
2354 event.param.conn.private_data_len = iw_event->private_data_len; in cma_iw_handler()
2357 /* Destroy the CM ID by returning a non-zero value. */ in cma_iw_handler()
2358 id_priv->cm_id.iw = NULL; in cma_iw_handler()
2364 mutex_unlock(&id_priv->handler_mutex); in cma_iw_handler()
2373 int ret = -ECONNABORTED; in iw_conn_req_handler()
2374 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in iw_conn_req_handler()
2375 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in iw_conn_req_handler()
2378 event.param.conn.private_data = iw_event->private_data; in iw_conn_req_handler()
2379 event.param.conn.private_data_len = iw_event->private_data_len; in iw_conn_req_handler()
2380 event.param.conn.initiator_depth = iw_event->ird; in iw_conn_req_handler()
2381 event.param.conn.responder_resources = iw_event->ord; in iw_conn_req_handler()
2383 listen_id = cm_id->context; in iw_conn_req_handler()
2385 mutex_lock(&listen_id->handler_mutex); in iw_conn_req_handler()
2386 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) in iw_conn_req_handler()
2389 /* Create a new RDMA id for the new IW CM ID */ in iw_conn_req_handler()
2390 conn_id = __rdma_create_id(listen_id->id.route.addr.dev_addr.net, in iw_conn_req_handler()
2391 listen_id->id.event_handler, in iw_conn_req_handler()
2392 listen_id->id.context, RDMA_PS_TCP, in iw_conn_req_handler()
2395 ret = -ENOMEM; in iw_conn_req_handler()
2398 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in iw_conn_req_handler()
2399 conn_id->state = RDMA_CM_CONNECT; in iw_conn_req_handler()
2401 ret = rdma_translate_ip(laddr, &conn_id->id.route.addr.dev_addr); in iw_conn_req_handler()
2403 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2410 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2415 conn_id->cm_id.iw = cm_id; in iw_conn_req_handler()
2416 cm_id->context = conn_id; in iw_conn_req_handler()
2417 cm_id->cm_handler = cma_iw_handler; in iw_conn_req_handler()
2424 /* User wants to destroy the CM ID */ in iw_conn_req_handler()
2425 conn_id->cm_id.iw = NULL; in iw_conn_req_handler()
2426 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2431 mutex_unlock(&conn_id->handler_mutex); in iw_conn_req_handler()
2434 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2441 struct ib_cm_id *id; in cma_ib_listen() local
2445 svc_id = rdma_get_service_id(&id_priv->id, addr); in cma_ib_listen()
2446 id = ib_cm_insert_listen(id_priv->id.device, in cma_ib_listen()
2448 if (IS_ERR(id)) in cma_ib_listen()
2449 return PTR_ERR(id); in cma_ib_listen()
2450 id_priv->cm_id.ib = id; in cma_ib_listen()
2458 struct iw_cm_id *id; in cma_iw_listen() local
2460 id = iw_create_cm_id(id_priv->id.device, in cma_iw_listen()
2463 if (IS_ERR(id)) in cma_iw_listen()
2464 return PTR_ERR(id); in cma_iw_listen()
2466 id->tos = id_priv->tos; in cma_iw_listen()
2467 id->tos_set = id_priv->tos_set; in cma_iw_listen()
2468 id_priv->cm_id.iw = id; in cma_iw_listen()
2470 memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), in cma_iw_listen()
2473 ret = iw_cm_listen(id_priv->cm_id.iw, backlog); in cma_iw_listen()
2476 iw_destroy_cm_id(id_priv->cm_id.iw); in cma_iw_listen()
2477 id_priv->cm_id.iw = NULL; in cma_iw_listen()
2483 static int cma_listen_handler(struct rdma_cm_id *id, in cma_listen_handler() argument
2486 struct rdma_id_private *id_priv = id->context; in cma_listen_handler()
2489 if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) in cma_listen_handler()
2490 return -1; in cma_listen_handler()
2492 id->context = id_priv->id.context; in cma_listen_handler()
2493 id->event_handler = id_priv->id.event_handler; in cma_listen_handler()
2495 return id_priv->id.event_handler(id, event); in cma_listen_handler()
2502 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_listen_on_dev()
2507 if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1)) in cma_listen_on_dev()
2512 id_priv->id.ps, id_priv->id.qp_type, id_priv); in cma_listen_on_dev()
2516 dev_id_priv->state = RDMA_CM_ADDR_BOUND; in cma_listen_on_dev()
2521 list_add_tail(&dev_id_priv->listen_list, &id_priv->listen_list); in cma_listen_on_dev()
2523 dev_id_priv->internal_id = 1; in cma_listen_on_dev()
2524 dev_id_priv->afonly = id_priv->afonly; in cma_listen_on_dev()
2525 dev_id_priv->tos_set = id_priv->tos_set; in cma_listen_on_dev()
2526 dev_id_priv->tos = id_priv->tos; in cma_listen_on_dev()
2528 ret = rdma_listen(&dev_id_priv->id, id_priv->backlog); in cma_listen_on_dev()
2530 dev_warn(&cma_dev->device->dev, in cma_listen_on_dev()
2539 list_add_tail(&id_priv->list, &listen_any_list); in cma_listen_on_all()
2545 void rdma_set_service_type(struct rdma_cm_id *id, int tos) in rdma_set_service_type() argument
2549 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_service_type()
2550 id_priv->tos = (u8) tos; in rdma_set_service_type()
2551 id_priv->tos_set = true; in rdma_set_service_type()
2556 * rdma_set_ack_timeout() - Set the ack timeout of QP associated
2558 * @id: Communication identifier to associated with service type.
2570 int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout) in rdma_set_ack_timeout() argument
2574 if (id->qp_type != IB_QPT_RC) in rdma_set_ack_timeout()
2575 return -EINVAL; in rdma_set_ack_timeout()
2577 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_ack_timeout()
2578 id_priv->timeout = timeout; in rdma_set_ack_timeout()
2579 id_priv->timeout_set = true; in rdma_set_ack_timeout()
2591 route = &work->id->id.route; in cma_query_handler()
2594 route->num_paths = 1; in cma_query_handler()
2595 *route->path_rec = *path_rec; in cma_query_handler()
2597 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_query_handler()
2598 work->new_state = RDMA_CM_ADDR_RESOLVED; in cma_query_handler()
2599 work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; in cma_query_handler()
2600 work->event.status = status; in cma_query_handler()
2605 queue_work(cma_wq, &work->work); in cma_query_handler()
2611 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_query_ib_route()
2619 if (rdma_cap_opa_ah(id_priv->id.device, id_priv->id.port_num)) in cma_query_ib_route()
2628 path_rec.service_id = rdma_get_service_id(&id_priv->id, in cma_query_ib_route()
2637 path_rec.qos_class = cpu_to_be16((u16) id_priv->tos); in cma_query_ib_route()
2642 path_rec.traffic_class = (u8) (be32_to_cpu(sin6->sin6_flowinfo) >> 20); in cma_query_ib_route()
2647 path_rec.traffic_class = (u8) (be32_to_cpu(sib->sib_flowinfo) >> 20); in cma_query_ib_route()
2652 id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, in cma_query_ib_route()
2653 id_priv->id.port_num, &path_rec, in cma_query_ib_route()
2656 work, &id_priv->query); in cma_query_ib_route()
2658 return (id_priv->query_id < 0) ? id_priv->query_id : 0; in cma_query_ib_route()
2664 struct rdma_id_private *id_priv = work->id; in cma_work_handler()
2666 mutex_lock(&id_priv->handler_mutex); in cma_work_handler()
2667 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_work_handler()
2668 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_work_handler()
2670 if (work->old_state != 0 || work->new_state != 0) { in cma_work_handler()
2671 if (!cma_comp_exch(id_priv, work->old_state, work->new_state)) in cma_work_handler()
2675 if (cma_cm_event_handler(id_priv, &work->event)) { in cma_work_handler()
2682 mutex_unlock(&id_priv->handler_mutex); in cma_work_handler()
2685 if (work->event.event == RDMA_CM_EVENT_MULTICAST_JOIN) in cma_work_handler()
2686 rdma_destroy_ah_attr(&work->event.param.ud.ah_attr); in cma_work_handler()
2693 work->id = id_priv; in cma_init_resolve_route_work()
2694 INIT_WORK(&work->work, cma_work_handler); in cma_init_resolve_route_work()
2695 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_init_resolve_route_work()
2696 work->new_state = RDMA_CM_ROUTE_RESOLVED; in cma_init_resolve_route_work()
2697 work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; in cma_init_resolve_route_work()
2706 work->id = id_priv; in enqueue_resolve_addr_work()
2707 INIT_WORK(&work->work, cma_work_handler); in enqueue_resolve_addr_work()
2708 work->old_state = RDMA_CM_ADDR_QUERY; in enqueue_resolve_addr_work()
2709 work->new_state = RDMA_CM_ADDR_RESOLVED; in enqueue_resolve_addr_work()
2710 work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; in enqueue_resolve_addr_work()
2712 queue_work(cma_wq, &work->work); in enqueue_resolve_addr_work()
2718 struct rdma_route *route = &id_priv->id.route; in cma_resolve_ib_route()
2724 return -ENOMEM; in cma_resolve_ib_route()
2728 route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_ib_route()
2729 if (!route->path_rec) { in cma_resolve_ib_route()
2730 ret = -ENOMEM; in cma_resolve_ib_route()
2740 kfree(route->path_rec); in cma_resolve_ib_route()
2741 route->path_rec = NULL; in cma_resolve_ib_route()
2769 struct rdma_route *route = &id_priv->id.route; in cma_iboe_set_path_rec_l2_fields()
2771 struct rdma_addr *addr = &route->addr; in cma_iboe_set_path_rec_l2_fields()
2775 if (!addr->dev_addr.bound_dev_if) in cma_iboe_set_path_rec_l2_fields()
2778 ndev = dev_get_by_index(addr->dev_addr.net, in cma_iboe_set_path_rec_l2_fields()
2779 addr->dev_addr.bound_dev_if); in cma_iboe_set_path_rec_l2_fields()
2783 supported_gids = roce_gid_type_mask_support(id_priv->id.device, in cma_iboe_set_path_rec_l2_fields()
2784 id_priv->id.port_num); in cma_iboe_set_path_rec_l2_fields()
2785 gid_type = cma_route_gid_type(addr->dev_addr.network, in cma_iboe_set_path_rec_l2_fields()
2787 id_priv->gid_type); in cma_iboe_set_path_rec_l2_fields()
2789 if (gid_type < ib_network_to_gid_type(addr->dev_addr.network)) in cma_iboe_set_path_rec_l2_fields()
2790 gid_type = ib_network_to_gid_type(addr->dev_addr.network); in cma_iboe_set_path_rec_l2_fields()
2791 route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type); in cma_iboe_set_path_rec_l2_fields()
2793 route->path_rec->roce.route_resolved = true; in cma_iboe_set_path_rec_l2_fields()
2794 sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr); in cma_iboe_set_path_rec_l2_fields()
2798 int rdma_set_ib_path(struct rdma_cm_id *id, in rdma_set_ib_path() argument
2805 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_ib_path()
2808 return -EINVAL; in rdma_set_ib_path()
2810 id->route.path_rec = kmemdup(path_rec, sizeof(*path_rec), in rdma_set_ib_path()
2812 if (!id->route.path_rec) { in rdma_set_ib_path()
2813 ret = -ENOMEM; in rdma_set_ib_path()
2817 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_set_ib_path()
2820 ret = -ENODEV; in rdma_set_ib_path()
2826 id->route.num_paths = 1; in rdma_set_ib_path()
2830 kfree(id->route.path_rec); in rdma_set_ib_path()
2831 id->route.path_rec = NULL; in rdma_set_ib_path()
2844 return -ENOMEM; in cma_resolve_iw_route()
2847 queue_work(cma_wq, &work->work); in cma_resolve_iw_route()
2856 if (dev->num_tc) in get_vlan_ndev_tc()
2872 struct iboe_prio_tc_map *map = (struct iboe_prio_tc_map *)priv->data; in get_lower_vlan_dev_tc()
2875 map->output_tc = get_vlan_ndev_tc(dev, map->input_prio); in get_lower_vlan_dev_tc()
2876 else if (dev->num_tc) in get_lower_vlan_dev_tc()
2877 map->output_tc = netdev_get_prio_tc_map(dev, map->input_prio); in get_lower_vlan_dev_tc()
2879 map->output_tc = 0; in get_lower_vlan_dev_tc()
2880 /* We are interested only in first level VLAN device, so always in get_lower_vlan_dev_tc()
2883 map->found = true; in get_lower_vlan_dev_tc()
2893 /* If VLAN device, get it directly from the VLAN netdev */ in iboe_tos_to_sl()
2904 /* If map is found from lower device, use it; Otherwise in iboe_tos_to_sl()
2909 else if (ndev->num_tc) in iboe_tos_to_sl()
2922 fl = be32_to_cpu(addr6->sin6_flowinfo) & IB_GRH_FLOWLABEL_MASK; in cma_get_roce_udp_flow_label()
2935 struct rdma_route *route = &id_priv->id.route; in cma_resolve_iboe_route()
2936 struct rdma_addr *addr = &route->addr; in cma_resolve_iboe_route()
2941 u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - in cma_resolve_iboe_route()
2942 rdma_start_port(id_priv->cma_dev->device)]; in cma_resolve_iboe_route()
2943 u8 tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; in cma_resolve_iboe_route()
2948 return -ENOMEM; in cma_resolve_iboe_route()
2950 route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_iboe_route()
2951 if (!route->path_rec) { in cma_resolve_iboe_route()
2952 ret = -ENOMEM; in cma_resolve_iboe_route()
2956 route->num_paths = 1; in cma_resolve_iboe_route()
2960 ret = -ENODEV; in cma_resolve_iboe_route()
2964 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_resolve_iboe_route()
2965 &route->path_rec->sgid); in cma_resolve_iboe_route()
2966 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, in cma_resolve_iboe_route()
2967 &route->path_rec->dgid); in cma_resolve_iboe_route()
2969 if (((struct sockaddr *)&id_priv->id.route.addr.dst_addr)->sa_family != AF_IB) in cma_resolve_iboe_route()
2970 /* TODO: get the hoplimit from the inet/inet6 device */ in cma_resolve_iboe_route()
2971 route->path_rec->hop_limit = addr->dev_addr.hoplimit; in cma_resolve_iboe_route()
2973 route->path_rec->hop_limit = 1; in cma_resolve_iboe_route()
2974 route->path_rec->reversible = 1; in cma_resolve_iboe_route()
2975 route->path_rec->pkey = cpu_to_be16(0xffff); in cma_resolve_iboe_route()
2976 route->path_rec->mtu_selector = IB_SA_EQ; in cma_resolve_iboe_route()
2977 route->path_rec->sl = iboe_tos_to_sl(ndev, tos); in cma_resolve_iboe_route()
2978 route->path_rec->traffic_class = tos; in cma_resolve_iboe_route()
2979 route->path_rec->mtu = iboe_get_mtu(ndev->mtu); in cma_resolve_iboe_route()
2980 route->path_rec->rate_selector = IB_SA_EQ; in cma_resolve_iboe_route()
2981 route->path_rec->rate = iboe_get_rate(ndev); in cma_resolve_iboe_route()
2983 route->path_rec->packet_life_time_selector = IB_SA_EQ; in cma_resolve_iboe_route()
2991 route->path_rec->packet_life_time = id_priv->timeout_set ? in cma_resolve_iboe_route()
2992 id_priv->timeout - 1 : CMA_IBOE_PACKET_LIFETIME; in cma_resolve_iboe_route()
2994 if (!route->path_rec->mtu) { in cma_resolve_iboe_route()
2995 ret = -EINVAL; in cma_resolve_iboe_route()
2999 if (rdma_protocol_roce_udp_encap(id_priv->id.device, in cma_resolve_iboe_route()
3000 id_priv->id.port_num)) in cma_resolve_iboe_route()
3001 route->path_rec->flow_label = in cma_resolve_iboe_route()
3005 queue_work(cma_wq, &work->work); in cma_resolve_iboe_route()
3010 kfree(route->path_rec); in cma_resolve_iboe_route()
3011 route->path_rec = NULL; in cma_resolve_iboe_route()
3012 route->num_paths = 0; in cma_resolve_iboe_route()
3018 int rdma_resolve_route(struct rdma_cm_id *id, unsigned long timeout_ms) in rdma_resolve_route() argument
3023 id_priv = container_of(id, struct rdma_id_private, id); in rdma_resolve_route()
3025 return -EINVAL; in rdma_resolve_route()
3028 if (rdma_cap_ib_sa(id->device, id->port_num)) in rdma_resolve_route()
3030 else if (rdma_protocol_roce(id->device, id->port_num)) in rdma_resolve_route()
3032 else if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_resolve_route()
3035 ret = -ENOSYS; in rdma_resolve_route()
3050 switch (addr->sa_family) { in cma_set_loopback()
3052 ((struct sockaddr_in *) addr)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); in cma_set_loopback()
3055 ipv6_addr_set(&((struct sockaddr_in6 *) addr)->sin6_addr, in cma_set_loopback()
3059 ib_addr_set(&((struct sockaddr_ib *) addr)->sib_addr, in cma_set_loopback()
3078 !rdma_cap_ib_cm(cur_dev->device, 1)) in cma_bind_loopback()
3084 rdma_for_each_port (cur_dev->device, p) { in cma_bind_loopback()
3085 if (!ib_get_cached_port_state(cur_dev->device, p, &port_state) && in cma_bind_loopback()
3094 ret = -ENODEV; in cma_bind_loopback()
3101 ret = rdma_query_gid(cma_dev->device, p, 0, &gid); in cma_bind_loopback()
3105 ret = ib_get_cached_pkey(cma_dev->device, p, 0, &pkey); in cma_bind_loopback()
3109 id_priv->id.route.addr.dev_addr.dev_type = in cma_bind_loopback()
3110 (rdma_protocol_ib(cma_dev->device, p)) ? in cma_bind_loopback()
3113 rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_bind_loopback()
3114 ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); in cma_bind_loopback()
3115 id_priv->id.port_num = p; in cma_bind_loopback()
3131 mutex_lock(&id_priv->handler_mutex); in addr_handler()
3138 * matching rdma device, old address can be restored back, which helps in addr_handler()
3144 if (!status && !id_priv->cma_dev) { in addr_handler()
3147 pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n", in addr_handler()
3169 mutex_unlock(&id_priv->handler_mutex); in addr_handler()
3180 return -ENOMEM; in cma_resolve_loopback()
3182 if (!id_priv->cma_dev) { in cma_resolve_loopback()
3188 rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3189 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3205 return -ENOMEM; in cma_resolve_ib_addr()
3207 if (!id_priv->cma_dev) { in cma_resolve_ib_addr()
3213 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) in cma_resolve_ib_addr()
3214 &(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); in cma_resolve_ib_addr()
3223 static int cma_bind_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, in cma_bind_addr() argument
3226 if (!src_addr || !src_addr->sa_family) { in cma_bind_addr()
3227 src_addr = (struct sockaddr *) &id->route.addr.src_addr; in cma_bind_addr()
3228 src_addr->sa_family = dst_addr->sa_family; in cma_bind_addr()
3230 dst_addr->sa_family == AF_INET6) { in cma_bind_addr()
3233 src_addr6->sin6_scope_id = dst_addr6->sin6_scope_id; in cma_bind_addr()
3234 if (ipv6_addr_type(&dst_addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL) in cma_bind_addr()
3235 id->route.addr.dev_addr.bound_dev_if = dst_addr6->sin6_scope_id; in cma_bind_addr()
3236 } else if (dst_addr->sa_family == AF_IB) { in cma_bind_addr()
3237 ((struct sockaddr_ib *) src_addr)->sib_pkey = in cma_bind_addr()
3238 ((struct sockaddr_ib *) dst_addr)->sib_pkey; in cma_bind_addr()
3241 return rdma_bind_addr(id, src_addr); in cma_bind_addr()
3247 * calls made by ULP, a previously bound ID will not be re-bound and src_addr is
3259 ret = cma_bind_addr(&id_priv->id, src_addr, dst_addr); in resolve_prepare_src()
3264 ret = -EINVAL; in resolve_prepare_src()
3269 if (cma_family(id_priv) != dst_addr->sa_family) { in resolve_prepare_src()
3270 ret = -EINVAL; in resolve_prepare_src()
3282 int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, in rdma_resolve_addr() argument
3286 container_of(id, struct rdma_id_private, id); in rdma_resolve_addr()
3296 if (dst_addr->sa_family == AF_IB) { in rdma_resolve_addr()
3300 &id->route.addr.dev_addr, in rdma_resolve_addr()
3315 int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse) in rdma_set_reuseaddr() argument
3321 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_reuseaddr()
3322 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_reuseaddr()
3323 if ((reuse && id_priv->state != RDMA_CM_LISTEN) || in rdma_set_reuseaddr()
3324 id_priv->state == RDMA_CM_IDLE) { in rdma_set_reuseaddr()
3325 id_priv->reuseaddr = reuse; in rdma_set_reuseaddr()
3328 ret = -EINVAL; in rdma_set_reuseaddr()
3330 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_reuseaddr()
3335 int rdma_set_afonly(struct rdma_cm_id *id, int afonly) in rdma_set_afonly() argument
3341 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_afonly()
3342 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_afonly()
3343 if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) { in rdma_set_afonly()
3344 id_priv->options |= (1 << CMA_OPTION_AFONLY); in rdma_set_afonly()
3345 id_priv->afonly = afonly; in rdma_set_afonly()
3348 ret = -EINVAL; in rdma_set_afonly()
3350 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_afonly()
3366 port = htons(bind_list->port); in cma_bind_port()
3368 switch (addr->sa_family) { in cma_bind_port()
3370 ((struct sockaddr_in *) addr)->sin_port = port; in cma_bind_port()
3373 ((struct sockaddr_in6 *) addr)->sin6_port = port; in cma_bind_port()
3377 sid = be64_to_cpu(sib->sib_sid); in cma_bind_port()
3378 mask = be64_to_cpu(sib->sib_sid_mask); in cma_bind_port()
3379 sib->sib_sid = cpu_to_be64((sid & mask) | (u64) ntohs(port)); in cma_bind_port()
3380 sib->sib_sid_mask = cpu_to_be64(~0ULL); in cma_bind_port()
3383 id_priv->bind_list = bind_list; in cma_bind_port()
3384 hlist_add_head(&id_priv->node, &bind_list->owners); in cma_bind_port()
3397 return -ENOMEM; in cma_alloc_port()
3399 ret = cma_ps_alloc(id_priv->id.route.addr.dev_addr.net, ps, bind_list, in cma_alloc_port()
3404 bind_list->ps = ps; in cma_alloc_port()
3405 bind_list->port = snum; in cma_alloc_port()
3410 return ret == -ENOSPC ? -EADDRNOTAVAIL : ret; in cma_alloc_port()
3423 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_port_is_unique()
3431 /* different dest port -> unique */ in cma_port_is_unique()
3437 /* different src address -> unique */ in cma_port_is_unique()
3443 /* different dst address -> unique */ in cma_port_is_unique()
3449 return -EADDRNOTAVAIL; in cma_port_is_unique()
3460 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_alloc_any_port()
3465 remaining = (high - low) + 1; in cma_alloc_any_port()
3483 * re-using same port immediately after it is closed. in cma_alloc_any_port()
3487 if (ret != -EADDRNOTAVAIL) in cma_alloc_any_port()
3490 if (--remaining) { in cma_alloc_any_port()
3496 return -EADDRNOTAVAIL; in cma_alloc_any_port()
3514 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_check_port()
3518 if (reuseaddr && cur_id->reuseaddr) in cma_check_port()
3522 if (id_priv->afonly && cur_id->afonly && in cma_check_port()
3523 (addr->sa_family != cur_addr->sa_family)) in cma_check_port()
3527 return -EADDRNOTAVAIL; in cma_check_port()
3530 return -EADDRINUSE; in cma_check_port()
3546 return -EACCES; in cma_use_port()
3548 bind_list = cma_ps_find(id_priv->id.route.addr.dev_addr.net, ps, snum); in cma_use_port()
3552 ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); in cma_use_port()
3562 switch (id_priv->id.ps) { in cma_select_inet_ps()
3567 return id_priv->id.ps; in cma_select_inet_ps()
3582 mask = be64_to_cpu(sib->sib_sid_mask) & RDMA_IB_IP_PS_MASK; in cma_select_ib_ps()
3583 sid = be64_to_cpu(sib->sib_sid) & mask; in cma_select_ib_ps()
3585 if ((id_priv->id.ps == RDMA_PS_IB) && (sid == (RDMA_IB_IP_PS_IB & mask))) { in cma_select_ib_ps()
3588 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_TCP)) && in cma_select_ib_ps()
3592 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_UDP)) && in cma_select_ib_ps()
3599 sib->sib_sid = cpu_to_be64(sid_ps | ntohs(cma_port((struct sockaddr *) sib))); in cma_select_ib_ps()
3600 sib->sib_sid_mask = cpu_to_be64(RDMA_IB_IP_PS_MASK | in cma_select_ib_ps()
3601 be64_to_cpu(sib->sib_sid_mask)); in cma_select_ib_ps()
3616 return -EPROTONOSUPPORT; in cma_get_port()
3634 if (addr->sa_family != AF_INET6) in cma_check_linklocal()
3639 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) in cma_check_linklocal()
3642 if (!sin6->sin6_scope_id) in cma_check_linklocal()
3643 return -EINVAL; in cma_check_linklocal()
3645 dev_addr->bound_dev_if = sin6->sin6_scope_id; in cma_check_linklocal()
3650 int rdma_listen(struct rdma_cm_id *id, int backlog) in rdma_listen() argument
3653 container_of(id, struct rdma_id_private, id); in rdma_listen()
3658 id->route.addr.src_addr.ss_family = AF_INET; in rdma_listen()
3659 ret = rdma_bind_addr(id, cma_src_addr(id_priv)); in rdma_listen()
3664 return -EINVAL; in rdma_listen()
3668 * Once the ID reaches RDMA_CM_LISTEN it is not allowed to be reusable in rdma_listen()
3671 if (id_priv->reuseaddr) { in rdma_listen()
3673 ret = cma_check_port(id_priv->bind_list, id_priv, 0); in rdma_listen()
3675 id_priv->reuseaddr = 0; in rdma_listen()
3681 id_priv->backlog = backlog; in rdma_listen()
3682 if (id->device) { in rdma_listen()
3683 if (rdma_cap_ib_cm(id->device, 1)) { in rdma_listen()
3687 } else if (rdma_cap_iw_cm(id->device, 1)) { in rdma_listen()
3692 ret = -ENOSYS; in rdma_listen()
3700 id_priv->backlog = 0; in rdma_listen()
3710 int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_bind_addr() argument
3716 if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6 && in rdma_bind_addr()
3717 addr->sa_family != AF_IB) in rdma_bind_addr()
3718 return -EAFNOSUPPORT; in rdma_bind_addr()
3720 id_priv = container_of(id, struct rdma_id_private, id); in rdma_bind_addr()
3722 return -EINVAL; in rdma_bind_addr()
3724 ret = cma_check_linklocal(&id->route.addr.dev_addr, addr); in rdma_bind_addr()
3730 ret = cma_translate_addr(addr, &id->route.addr.dev_addr); in rdma_bind_addr()
3739 if (!(id_priv->options & (1 << CMA_OPTION_AFONLY))) { in rdma_bind_addr()
3740 if (addr->sa_family == AF_INET) in rdma_bind_addr()
3741 id_priv->afonly = 1; in rdma_bind_addr()
3743 else if (addr->sa_family == AF_INET6) { in rdma_bind_addr()
3744 struct net *net = id_priv->id.route.addr.dev_addr.net; in rdma_bind_addr()
3746 id_priv->afonly = net->ipv6.sysctl.bindv6only; in rdma_bind_addr()
3751 daddr->sa_family = addr->sa_family; in rdma_bind_addr()
3759 if (id_priv->cma_dev) in rdma_bind_addr()
3772 cma_hdr->cma_version = CMA_VERSION; in cma_format_hdr()
3780 cma_hdr->src_addr.ip4.addr = src4->sin_addr.s_addr; in cma_format_hdr()
3781 cma_hdr->dst_addr.ip4.addr = dst4->sin_addr.s_addr; in cma_format_hdr()
3782 cma_hdr->port = src4->sin_port; in cma_format_hdr()
3790 cma_hdr->src_addr.ip6 = src6->sin6_addr; in cma_format_hdr()
3791 cma_hdr->dst_addr.ip6 = dst6->sin6_addr; in cma_format_hdr()
3792 cma_hdr->port = src6->sin6_port; in cma_format_hdr()
3800 struct rdma_id_private *id_priv = cm_id->context; in cma_sidr_rep_handler()
3803 &ib_event->param.sidr_rep_rcvd; in cma_sidr_rep_handler()
3806 mutex_lock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
3807 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_sidr_rep_handler()
3810 switch (ib_event->event) { in cma_sidr_rep_handler()
3813 event.status = -ETIMEDOUT; in cma_sidr_rep_handler()
3816 event.param.ud.private_data = ib_event->private_data; in cma_sidr_rep_handler()
3818 if (rep->status != IB_SIDR_SUCCESS) { in cma_sidr_rep_handler()
3820 event.status = ib_event->param.sidr_rep_rcvd.status; in cma_sidr_rep_handler()
3825 ret = cma_set_qkey(id_priv, rep->qkey); in cma_sidr_rep_handler()
3832 ib_init_ah_attr_from_path(id_priv->id.device, in cma_sidr_rep_handler()
3833 id_priv->id.port_num, in cma_sidr_rep_handler()
3834 id_priv->id.route.path_rec, in cma_sidr_rep_handler()
3836 rep->sgid_attr); in cma_sidr_rep_handler()
3837 event.param.ud.qp_num = rep->qpn; in cma_sidr_rep_handler()
3838 event.param.ud.qkey = rep->qkey; in cma_sidr_rep_handler()
3844 ib_event->event); in cma_sidr_rep_handler()
3852 /* Destroy the CM ID by returning a non-zero value. */ in cma_sidr_rep_handler()
3853 id_priv->cm_id.ib = NULL; in cma_sidr_rep_handler()
3858 mutex_unlock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
3866 struct ib_cm_id *id; in cma_resolve_ib_udp() local
3873 req.private_data_len = offset + conn_param->private_data_len; in cma_resolve_ib_udp()
3874 if (req.private_data_len < conn_param->private_data_len) in cma_resolve_ib_udp()
3875 return -EINVAL; in cma_resolve_ib_udp()
3880 return -ENOMEM; in cma_resolve_ib_udp()
3885 if (conn_param->private_data && conn_param->private_data_len) in cma_resolve_ib_udp()
3886 memcpy(private_data + offset, conn_param->private_data, in cma_resolve_ib_udp()
3887 conn_param->private_data_len); in cma_resolve_ib_udp()
3896 id = ib_create_cm_id(id_priv->id.device, cma_sidr_rep_handler, in cma_resolve_ib_udp()
3898 if (IS_ERR(id)) { in cma_resolve_ib_udp()
3899 ret = PTR_ERR(id); in cma_resolve_ib_udp()
3902 id_priv->cm_id.ib = id; in cma_resolve_ib_udp()
3904 req.path = id_priv->id.route.path_rec; in cma_resolve_ib_udp()
3905 req.sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_resolve_ib_udp()
3906 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_resolve_ib_udp()
3907 req.timeout_ms = 1 << (CMA_CM_RESPONSE_TIMEOUT - 8); in cma_resolve_ib_udp()
3911 ret = ib_send_cm_sidr_req(id_priv->cm_id.ib, &req); in cma_resolve_ib_udp()
3913 ib_destroy_cm_id(id_priv->cm_id.ib); in cma_resolve_ib_udp()
3914 id_priv->cm_id.ib = NULL; in cma_resolve_ib_udp()
3927 struct ib_cm_id *id; in cma_connect_ib() local
3933 req.private_data_len = offset + conn_param->private_data_len; in cma_connect_ib()
3934 if (req.private_data_len < conn_param->private_data_len) in cma_connect_ib()
3935 return -EINVAL; in cma_connect_ib()
3940 return -ENOMEM; in cma_connect_ib()
3945 if (conn_param->private_data && conn_param->private_data_len) in cma_connect_ib()
3946 memcpy(private_data + offset, conn_param->private_data, in cma_connect_ib()
3947 conn_param->private_data_len); in cma_connect_ib()
3949 id = ib_create_cm_id(id_priv->id.device, cma_ib_handler, id_priv); in cma_connect_ib()
3950 if (IS_ERR(id)) { in cma_connect_ib()
3951 ret = PTR_ERR(id); in cma_connect_ib()
3954 id_priv->cm_id.ib = id; in cma_connect_ib()
3956 route = &id_priv->id.route; in cma_connect_ib()
3964 req.primary_path = &route->path_rec[0]; in cma_connect_ib()
3965 if (route->num_paths == 2) in cma_connect_ib()
3966 req.alternate_path = &route->path_rec[1]; in cma_connect_ib()
3968 req.ppath_sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_connect_ib()
3970 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_connect_ib()
3971 req.qp_num = id_priv->qp_num; in cma_connect_ib()
3972 req.qp_type = id_priv->id.qp_type; in cma_connect_ib()
3973 req.starting_psn = id_priv->seq_num; in cma_connect_ib()
3974 req.responder_resources = conn_param->responder_resources; in cma_connect_ib()
3975 req.initiator_depth = conn_param->initiator_depth; in cma_connect_ib()
3976 req.flow_control = conn_param->flow_control; in cma_connect_ib()
3977 req.retry_count = min_t(u8, 7, conn_param->retry_count); in cma_connect_ib()
3978 req.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_connect_ib()
3982 req.srq = id_priv->srq ? 1 : 0; in cma_connect_ib()
3983 req.ece.vendor_id = id_priv->ece.vendor_id; in cma_connect_ib()
3984 req.ece.attr_mod = id_priv->ece.attr_mod; in cma_connect_ib()
3987 ret = ib_send_cm_req(id_priv->cm_id.ib, &req); in cma_connect_ib()
3989 if (ret && !IS_ERR(id)) { in cma_connect_ib()
3990 ib_destroy_cm_id(id); in cma_connect_ib()
3991 id_priv->cm_id.ib = NULL; in cma_connect_ib()
4005 cm_id = iw_create_cm_id(id_priv->id.device, cma_iw_handler, id_priv); in cma_connect_iw()
4009 cm_id->tos = id_priv->tos; in cma_connect_iw()
4010 cm_id->tos_set = id_priv->tos_set; in cma_connect_iw()
4011 id_priv->cm_id.iw = cm_id; in cma_connect_iw()
4013 memcpy(&cm_id->local_addr, cma_src_addr(id_priv), in cma_connect_iw()
4015 memcpy(&cm_id->remote_addr, cma_dst_addr(id_priv), in cma_connect_iw()
4023 iw_param.ord = conn_param->initiator_depth; in cma_connect_iw()
4024 iw_param.ird = conn_param->responder_resources; in cma_connect_iw()
4025 iw_param.private_data = conn_param->private_data; in cma_connect_iw()
4026 iw_param.private_data_len = conn_param->private_data_len; in cma_connect_iw()
4027 iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num; in cma_connect_iw()
4030 iw_param.qpn = id_priv->qp_num; in cma_connect_iw()
4036 id_priv->cm_id.iw = NULL; in cma_connect_iw()
4042 * rdma_connect_locked - Initiate an active connection request.
4043 * @id: Connection identifier to connect.
4049 int rdma_connect_locked(struct rdma_cm_id *id, in rdma_connect_locked() argument
4053 container_of(id, struct rdma_id_private, id); in rdma_connect_locked()
4057 return -EINVAL; in rdma_connect_locked()
4059 if (!id->qp) { in rdma_connect_locked()
4060 id_priv->qp_num = conn_param->qp_num; in rdma_connect_locked()
4061 id_priv->srq = conn_param->srq; in rdma_connect_locked()
4064 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_connect_locked()
4065 if (id->qp_type == IB_QPT_UD) in rdma_connect_locked()
4069 } else if (rdma_cap_iw_cm(id->device, id->port_num)) in rdma_connect_locked()
4072 ret = -ENOSYS; in rdma_connect_locked()
4083 * rdma_connect - Initiate an active connection request.
4084 * @id: Connection identifier to connect.
4094 int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) in rdma_connect() argument
4097 container_of(id, struct rdma_id_private, id); in rdma_connect()
4100 mutex_lock(&id_priv->handler_mutex); in rdma_connect()
4101 ret = rdma_connect_locked(id, conn_param); in rdma_connect()
4102 mutex_unlock(&id_priv->handler_mutex); in rdma_connect()
4108 * rdma_connect_ece - Initiate an active connection request with ECE data.
4109 * @id: Connection identifier to connect.
4115 int rdma_connect_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, in rdma_connect_ece() argument
4119 container_of(id, struct rdma_id_private, id); in rdma_connect_ece()
4121 id_priv->ece.vendor_id = ece->vendor_id; in rdma_connect_ece()
4122 id_priv->ece.attr_mod = ece->attr_mod; in rdma_connect_ece()
4124 return rdma_connect(id, conn_param); in rdma_connect_ece()
4143 rep.qp_num = id_priv->qp_num; in cma_accept_ib()
4144 rep.starting_psn = id_priv->seq_num; in cma_accept_ib()
4145 rep.private_data = conn_param->private_data; in cma_accept_ib()
4146 rep.private_data_len = conn_param->private_data_len; in cma_accept_ib()
4147 rep.responder_resources = conn_param->responder_resources; in cma_accept_ib()
4148 rep.initiator_depth = conn_param->initiator_depth; in cma_accept_ib()
4150 rep.flow_control = conn_param->flow_control; in cma_accept_ib()
4151 rep.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_accept_ib()
4152 rep.srq = id_priv->srq ? 1 : 0; in cma_accept_ib()
4153 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_accept_ib()
4154 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_accept_ib()
4157 ret = ib_send_cm_rep(id_priv->cm_id.ib, &rep); in cma_accept_ib()
4169 return -EINVAL; in cma_accept_iw()
4175 iw_param.ord = conn_param->initiator_depth; in cma_accept_iw()
4176 iw_param.ird = conn_param->responder_resources; in cma_accept_iw()
4177 iw_param.private_data = conn_param->private_data; in cma_accept_iw()
4178 iw_param.private_data_len = conn_param->private_data_len; in cma_accept_iw()
4179 if (id_priv->id.qp) { in cma_accept_iw()
4180 iw_param.qpn = id_priv->qp_num; in cma_accept_iw()
4182 iw_param.qpn = conn_param->qp_num; in cma_accept_iw()
4184 return iw_cm_accept(id_priv->cm_id.iw, &iw_param); in cma_accept_iw()
4200 rep.qp_num = id_priv->qp_num; in cma_send_sidr_rep()
4201 rep.qkey = id_priv->qkey; in cma_send_sidr_rep()
4203 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_send_sidr_rep()
4204 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_send_sidr_rep()
4211 return ib_send_cm_sidr_rep(id_priv->cm_id.ib, &rep); in cma_send_sidr_rep()
4215 * rdma_accept - Called to accept a connection request or response.
4216 * @id: Connection identifier associated with the request.
4226 * state of the qp associated with the id is modified to error, such that any
4232 int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) in rdma_accept() argument
4235 container_of(id, struct rdma_id_private, id); in rdma_accept()
4238 lockdep_assert_held(&id_priv->handler_mutex); in rdma_accept()
4240 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in rdma_accept()
4241 return -EINVAL; in rdma_accept()
4243 if (!id->qp && conn_param) { in rdma_accept()
4244 id_priv->qp_num = conn_param->qp_num; in rdma_accept()
4245 id_priv->srq = conn_param->srq; in rdma_accept()
4248 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_accept()
4249 if (id->qp_type == IB_QPT_UD) { in rdma_accept()
4252 conn_param->qkey, in rdma_accept()
4253 conn_param->private_data, in rdma_accept()
4254 conn_param->private_data_len); in rdma_accept()
4264 } else if (rdma_cap_iw_cm(id->device, id->port_num)) in rdma_accept()
4267 ret = -ENOSYS; in rdma_accept()
4275 rdma_reject(id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED); in rdma_accept()
4280 int rdma_accept_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, in rdma_accept_ece() argument
4284 container_of(id, struct rdma_id_private, id); in rdma_accept_ece()
4286 id_priv->ece.vendor_id = ece->vendor_id; in rdma_accept_ece()
4287 id_priv->ece.attr_mod = ece->attr_mod; in rdma_accept_ece()
4289 return rdma_accept(id, conn_param); in rdma_accept_ece()
4293 void rdma_lock_handler(struct rdma_cm_id *id) in rdma_lock_handler() argument
4296 container_of(id, struct rdma_id_private, id); in rdma_lock_handler()
4298 mutex_lock(&id_priv->handler_mutex); in rdma_lock_handler()
4302 void rdma_unlock_handler(struct rdma_cm_id *id) in rdma_unlock_handler() argument
4305 container_of(id, struct rdma_id_private, id); in rdma_unlock_handler()
4307 mutex_unlock(&id_priv->handler_mutex); in rdma_unlock_handler()
4311 int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event) in rdma_notify() argument
4316 id_priv = container_of(id, struct rdma_id_private, id); in rdma_notify()
4317 if (!id_priv->cm_id.ib) in rdma_notify()
4318 return -EINVAL; in rdma_notify()
4320 switch (id->device->node_type) { in rdma_notify()
4322 ret = ib_cm_notify(id_priv->cm_id.ib, event); in rdma_notify()
4332 int rdma_reject(struct rdma_cm_id *id, const void *private_data, in rdma_reject() argument
4338 id_priv = container_of(id, struct rdma_id_private, id); in rdma_reject()
4339 if (!id_priv->cm_id.ib) in rdma_reject()
4340 return -EINVAL; in rdma_reject()
4342 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_reject()
4343 if (id->qp_type == IB_QPT_UD) { in rdma_reject()
4348 ret = ib_send_cm_rej(id_priv->cm_id.ib, reason, NULL, 0, in rdma_reject()
4351 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_reject()
4352 ret = iw_cm_reject(id_priv->cm_id.iw, in rdma_reject()
4355 ret = -ENOSYS; in rdma_reject()
4361 int rdma_disconnect(struct rdma_cm_id *id) in rdma_disconnect() argument
4366 id_priv = container_of(id, struct rdma_id_private, id); in rdma_disconnect()
4367 if (!id_priv->cm_id.ib) in rdma_disconnect()
4368 return -EINVAL; in rdma_disconnect()
4370 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_disconnect()
4376 if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) { in rdma_disconnect()
4377 if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0)) in rdma_disconnect()
4382 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_disconnect()
4383 ret = iw_cm_disconnect(id_priv->cm_id.iw, 0); in rdma_disconnect()
4385 ret = -EINVAL; in rdma_disconnect()
4402 status = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey)); in cma_make_mc_event()
4407 event->status = status; in cma_make_mc_event()
4408 event->param.ud.private_data = mc->context; in cma_make_mc_event()
4410 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4414 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_make_mc_event()
4415 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_make_mc_event()
4417 id_priv->cma_dev in cma_make_mc_event()
4418 ->default_gid_type[id_priv->id.port_num - in cma_make_mc_event()
4420 id_priv->cma_dev->device)]; in cma_make_mc_event()
4422 event->event = RDMA_CM_EVENT_MULTICAST_JOIN; in cma_make_mc_event()
4423 if (ib_init_ah_from_mcmember(id_priv->id.device, id_priv->id.port_num, in cma_make_mc_event()
4424 &multicast->rec, ndev, gid_type, in cma_make_mc_event()
4425 &event->param.ud.ah_attr)) { in cma_make_mc_event()
4426 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4430 event->param.ud.qp_num = 0xFFFFFF; in cma_make_mc_event()
4431 event->param.ud.qkey = be32_to_cpu(multicast->rec.qkey); in cma_make_mc_event()
4440 struct cma_multicast *mc = multicast->context; in cma_ib_mc_handler()
4441 struct rdma_id_private *id_priv = mc->id_priv; in cma_ib_mc_handler()
4445 mutex_lock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4446 if (READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL || in cma_ib_mc_handler()
4447 READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING) in cma_ib_mc_handler()
4459 mutex_unlock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4467 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_set_mgid()
4473 } else if ((addr->sa_family == AF_INET6) && in cma_set_mgid()
4474 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFFF0FFFF) == in cma_set_mgid()
4477 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_set_mgid()
4478 } else if (addr->sa_family == AF_IB) { in cma_set_mgid()
4479 memcpy(mgid, &((struct sockaddr_ib *) addr)->sib_addr, sizeof *mgid); in cma_set_mgid()
4480 } else if (addr->sa_family == AF_INET6) { in cma_set_mgid()
4481 ipv6_ib_mc_map(&sin6->sin6_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4482 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4486 ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4487 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4497 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_join_ib_multicast()
4502 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num, in cma_join_ib_multicast()
4511 cma_set_mgid(id_priv, (struct sockaddr *) &mc->addr, &rec.mgid); in cma_join_ib_multicast()
4512 rec.qkey = cpu_to_be32(id_priv->qkey); in cma_join_ib_multicast()
4515 rec.join_state = mc->join_state; in cma_join_ib_multicast()
4519 id_priv->id.device, in cma_join_ib_multicast()
4520 id_priv->id.port_num))) { in cma_join_ib_multicast()
4522 &id_priv->id.device->dev, in cma_join_ib_multicast()
4524 id_priv->id.port_num); in cma_join_ib_multicast()
4525 return -EOPNOTSUPP; in cma_join_ib_multicast()
4534 if (id_priv->id.ps == RDMA_PS_IPOIB) in cma_join_ib_multicast()
4541 mc->sa_mc = ib_sa_join_multicast(&sa_client, id_priv->id.device, in cma_join_ib_multicast()
4542 id_priv->id.port_num, &rec, comp_mask, in cma_join_ib_multicast()
4544 return PTR_ERR_OR_ZERO(mc->sa_mc); in cma_join_ib_multicast()
4555 } else if (addr->sa_family == AF_INET6) { in cma_iboe_set_mgid()
4556 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_iboe_set_mgid()
4558 mgid->raw[0] = in cma_iboe_set_mgid()
4560 mgid->raw[1] = in cma_iboe_set_mgid()
4562 mgid->raw[2] = 0; in cma_iboe_set_mgid()
4563 mgid->raw[3] = 0; in cma_iboe_set_mgid()
4564 mgid->raw[4] = 0; in cma_iboe_set_mgid()
4565 mgid->raw[5] = 0; in cma_iboe_set_mgid()
4566 mgid->raw[6] = 0; in cma_iboe_set_mgid()
4567 mgid->raw[7] = 0; in cma_iboe_set_mgid()
4568 mgid->raw[8] = 0; in cma_iboe_set_mgid()
4569 mgid->raw[9] = 0; in cma_iboe_set_mgid()
4570 mgid->raw[10] = 0xff; in cma_iboe_set_mgid()
4571 mgid->raw[11] = 0xff; in cma_iboe_set_mgid()
4572 *(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr; in cma_iboe_set_mgid()
4580 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iboe_join_multicast()
4582 struct sockaddr *addr = (struct sockaddr *)&mc->addr; in cma_iboe_join_multicast()
4588 send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); in cma_iboe_join_multicast()
4591 return -EINVAL; in cma_iboe_join_multicast()
4595 return -ENOMEM; in cma_iboe_join_multicast()
4597 gid_type = id_priv->cma_dev->default_gid_type[id_priv->id.port_num - in cma_iboe_join_multicast()
4598 rdma_start_port(id_priv->cma_dev->device)]; in cma_iboe_join_multicast()
4602 if (id_priv->id.ps == RDMA_PS_UDP) in cma_iboe_join_multicast()
4605 if (dev_addr->bound_dev_if) in cma_iboe_join_multicast()
4606 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_iboe_join_multicast()
4608 err = -ENODEV; in cma_iboe_join_multicast()
4613 ib.rec.mtu = iboe_get_mtu(ndev->mtu); in cma_iboe_join_multicast()
4615 if (addr->sa_family == AF_INET) { in cma_iboe_join_multicast()
4625 err = -ENOTSUPP; in cma_iboe_join_multicast()
4630 err = -EINVAL; in cma_iboe_join_multicast()
4633 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_iboe_join_multicast()
4635 work->id = id_priv; in cma_iboe_join_multicast()
4636 INIT_WORK(&work->work, cma_work_handler); in cma_iboe_join_multicast()
4637 cma_make_mc_event(0, id_priv, &ib, &work->event, mc); in cma_iboe_join_multicast()
4640 queue_work(cma_wq, &work->work); in cma_iboe_join_multicast()
4648 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, in rdma_join_multicast() argument
4652 container_of(id, struct rdma_id_private, id); in rdma_join_multicast()
4657 if (WARN_ON(id->qp)) in rdma_join_multicast()
4658 return -EINVAL; in rdma_join_multicast()
4661 if (!id->device || (READ_ONCE(id_priv->state) != RDMA_CM_ADDR_BOUND && in rdma_join_multicast()
4662 READ_ONCE(id_priv->state) != RDMA_CM_ADDR_RESOLVED)) in rdma_join_multicast()
4663 return -EINVAL; in rdma_join_multicast()
4667 return -ENOMEM; in rdma_join_multicast()
4669 memcpy(&mc->addr, addr, rdma_addr_size(addr)); in rdma_join_multicast()
4670 mc->context = context; in rdma_join_multicast()
4671 mc->id_priv = id_priv; in rdma_join_multicast()
4672 mc->join_state = join_state; in rdma_join_multicast()
4674 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_join_multicast()
4678 } else if (rdma_cap_ib_mcast(id->device, id->port_num)) { in rdma_join_multicast()
4683 ret = -ENOSYS; in rdma_join_multicast()
4687 spin_lock(&id_priv->lock); in rdma_join_multicast()
4688 list_add(&mc->list, &id_priv->mc_list); in rdma_join_multicast()
4689 spin_unlock(&id_priv->lock); in rdma_join_multicast()
4698 void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_leave_multicast() argument
4703 id_priv = container_of(id, struct rdma_id_private, id); in rdma_leave_multicast()
4704 spin_lock_irq(&id_priv->lock); in rdma_leave_multicast()
4705 list_for_each_entry(mc, &id_priv->mc_list, list) { in rdma_leave_multicast()
4706 if (memcmp(&mc->addr, addr, rdma_addr_size(addr)) != 0) in rdma_leave_multicast()
4708 list_del(&mc->list); in rdma_leave_multicast()
4709 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
4711 WARN_ON(id_priv->cma_dev->device != id->device); in rdma_leave_multicast()
4715 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
4724 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_netdev_change()
4726 if ((dev_addr->bound_dev_if == ndev->ifindex) && in cma_netdev_change()
4727 (net_eq(dev_net(ndev), dev_addr->net)) && in cma_netdev_change()
4728 memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) { in cma_netdev_change()
4729 pr_info("RDMA CM addr change for ndev %s used by id %p\n", in cma_netdev_change()
4730 ndev->name, &id_priv->id); in cma_netdev_change()
4733 return -ENOMEM; in cma_netdev_change()
4735 INIT_WORK(&work->work, cma_work_handler); in cma_netdev_change()
4736 work->id = id_priv; in cma_netdev_change()
4737 work->event.event = RDMA_CM_EVENT_ADDR_CHANGE; in cma_netdev_change()
4739 queue_work(cma_wq, &work->work); in cma_netdev_change()
4761 list_for_each_entry(id_priv, &cma_dev->id_list, list) { in cma_netdev_callback()
4776 static int cma_add_one(struct ib_device *device) in cma_add_one() argument
4786 return -ENOMEM; in cma_add_one()
4788 cma_dev->device = device; in cma_add_one()
4789 cma_dev->default_gid_type = kcalloc(device->phys_port_cnt, in cma_add_one()
4790 sizeof(*cma_dev->default_gid_type), in cma_add_one()
4792 if (!cma_dev->default_gid_type) { in cma_add_one()
4793 ret = -ENOMEM; in cma_add_one()
4797 cma_dev->default_roce_tos = kcalloc(device->phys_port_cnt, in cma_add_one()
4798 sizeof(*cma_dev->default_roce_tos), in cma_add_one()
4800 if (!cma_dev->default_roce_tos) { in cma_add_one()
4801 ret = -ENOMEM; in cma_add_one()
4805 rdma_for_each_port (device, i) { in cma_add_one()
4806 supported_gids = roce_gid_type_mask_support(device, i); in cma_add_one()
4809 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
4812 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
4814 cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0; in cma_add_one()
4817 init_completion(&cma_dev->comp); in cma_add_one()
4818 refcount_set(&cma_dev->refcount, 1); in cma_add_one()
4819 INIT_LIST_HEAD(&cma_dev->id_list); in cma_add_one()
4820 ib_set_client_data(device, &cma_client, cma_dev); in cma_add_one()
4823 list_add_tail(&cma_dev->list, &dev_list); in cma_add_one()
4828 trace_cm_add_one(device); in cma_add_one()
4832 kfree(cma_dev->default_gid_type); in cma_add_one()
4845 mutex_lock(&id_priv->handler_mutex); in cma_send_device_removal_put()
4846 /* Record that we want to remove the device */ in cma_send_device_removal_put()
4847 spin_lock_irqsave(&id_priv->lock, flags); in cma_send_device_removal_put()
4848 state = id_priv->state; in cma_send_device_removal_put()
4850 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
4851 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
4855 id_priv->state = RDMA_CM_DEVICE_REMOVAL; in cma_send_device_removal_put()
4856 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
4864 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
4869 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
4882 while (!list_empty(&cma_dev->id_list)) { in cma_process_remove()
4884 &cma_dev->id_list, struct rdma_id_private, list); in cma_process_remove()
4886 list_del(&id_priv->listen_list); in cma_process_remove()
4887 list_del_init(&id_priv->list); in cma_process_remove()
4898 wait_for_completion(&cma_dev->comp); in cma_process_remove()
4901 static void cma_remove_one(struct ib_device *device, void *client_data) in cma_remove_one() argument
4905 trace_cm_remove_one(device); in cma_remove_one()
4908 list_del(&cma_dev->list); in cma_remove_one()
4912 kfree(cma_dev->default_roce_tos); in cma_remove_one()
4913 kfree(cma_dev->default_gid_type); in cma_remove_one()
4921 xa_init(&pernet->tcp_ps); in cma_init_net()
4922 xa_init(&pernet->udp_ps); in cma_init_net()
4923 xa_init(&pernet->ipoib_ps); in cma_init_net()
4924 xa_init(&pernet->ib_ps); in cma_init_net()
4933 WARN_ON(!xa_empty(&pernet->tcp_ps)); in cma_exit_net()
4934 WARN_ON(!xa_empty(&pernet->udp_ps)); in cma_exit_net()
4935 WARN_ON(!xa_empty(&pernet->ipoib_ps)); in cma_exit_net()
4936 WARN_ON(!xa_empty(&pernet->ib_ps)); in cma_exit_net()
4942 .id = &cma_pernet_id,
4965 return -ENOMEM; in cma_init()