Lines Matching +full:mc +full:- +full:sid
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.
87 if (rdma_ib_or_roce(id->device, id->port_num)) in rdma_reject_msg()
90 if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_reject_msg()
99 * rdma_is_consumer_reject - return true if the consumer rejected the connect
106 if (rdma_ib_or_roce(id->device, id->port_num)) in rdma_is_consumer_reject()
109 if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_is_consumer_reject()
110 return reason == -ECONNREFUSED; in rdma_is_consumer_reject()
121 if (rdma_is_consumer_reject(id, ev->status)) { in rdma_consumer_reject_data()
122 *data_len = ev->param.conn.private_data_len; in rdma_consumer_reject_data()
123 p = ev->param.conn.private_data; in rdma_consumer_reject_data()
133 * rdma_iw_cm_id() - return the iw_cm_id pointer for this cm_id.
141 if (id->device->node_type == RDMA_NODE_RNIC) in rdma_iw_cm_id()
142 return id_priv->cm_id.iw; in rdma_iw_cm_id()
148 * rdma_res_to_id() - return the rdma_cm_id pointer for this restrack.
156 return &id_priv->id; in rdma_res_to_id()
198 return &pernet->tcp_ps; in cma_pernet_xa()
200 return &pernet->udp_ps; in cma_pernet_xa()
202 return &pernet->ipoib_ps; in cma_pernet_xa()
204 return &pernet->ib_ps; in cma_pernet_xa()
261 refcount_inc(&cma_dev->refcount); in cma_dev_get()
266 if (refcount_dec_and_test(&cma_dev->refcount)) in cma_dev_put()
267 complete(&cma_dev->comp); in cma_dev_put()
279 if (filter(cma_dev->device, cookie)) { in cma_enum_devices_by_ibdev()
293 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_get_default_gid_type()
294 return -EINVAL; in cma_get_default_gid_type()
296 return cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)]; in cma_get_default_gid_type()
305 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_set_default_gid_type()
306 return -EINVAL; in cma_set_default_gid_type()
309 rdma_protocol_roce_eth_encap(cma_dev->device, port)) in cma_set_default_gid_type()
312 supported_gids = roce_gid_type_mask_support(cma_dev->device, port); in cma_set_default_gid_type()
315 return -EINVAL; in cma_set_default_gid_type()
317 cma_dev->default_gid_type[port - rdma_start_port(cma_dev->device)] = in cma_set_default_gid_type()
325 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_get_default_roce_tos()
326 return -EINVAL; in cma_get_default_roce_tos()
328 return cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)]; in cma_get_default_roce_tos()
334 if (!rdma_is_port_valid(cma_dev->device, port)) in cma_set_default_roce_tos()
335 return -EINVAL; in cma_set_default_roce_tos()
337 cma_dev->default_roce_tos[port - rdma_start_port(cma_dev->device)] = in cma_set_default_roce_tos()
344 return cma_dev->device; in cma_get_ib_dev()
419 lockdep_assert_held(&id_priv->handler_mutex); in cma_comp_exch()
421 spin_lock_irqsave(&id_priv->lock, flags); in cma_comp_exch()
422 if ((ret = (id_priv->state == comp))) in cma_comp_exch()
423 id_priv->state = exch; in cma_comp_exch()
424 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_comp_exch()
430 return hdr->ip_version >> 4; in cma_get_ip_ver()
435 hdr->ip_version = (ip_ver << 4) | (hdr->ip_version & 0xF); in cma_set_ip_ver()
440 return (struct sockaddr *)&id_priv->id.route.addr.src_addr; in cma_src_addr()
445 return (struct sockaddr *)&id_priv->id.route.addr.dst_addr; in cma_dst_addr()
458 *(__be32 *)(mgid->raw + 12)); in cma_igmp_send()
461 *(__be32 *)(mgid->raw + 12)); in cma_igmp_send()
465 return (in_dev) ? 0 : -ENODEV; in cma_igmp_send()
472 &entry_b->id_list, struct rdma_id_private, id_list_entry); in compare_netdev_and_ip()
473 int ifindex_b = id_priv->id.route.addr.dev_addr.bound_dev_if; in compare_netdev_and_ip()
477 return (ifindex_a > ifindex_b) ? 1 : -1; in compare_netdev_and_ip()
479 if (sa->sa_family != sb->sa_family) in compare_netdev_and_ip()
480 return sa->sa_family - sb->sa_family; in compare_netdev_and_ip()
482 if (sa->sa_family == AF_INET && in compare_netdev_and_ip()
484 return memcmp(&((struct sockaddr_in *)sa)->sin_addr, in compare_netdev_and_ip()
485 &((struct sockaddr_in *)sb)->sin_addr, in compare_netdev_and_ip()
486 sizeof(((struct sockaddr_in *)sa)->sin_addr)); in compare_netdev_and_ip()
489 if (sa->sa_family == AF_INET6 && in compare_netdev_and_ip()
491 return ipv6_addr_cmp(&((struct sockaddr_in6 *)sa)->sin6_addr, in compare_netdev_and_ip()
492 &((struct sockaddr_in6 *)sb)->sin6_addr); in compare_netdev_and_ip()
495 return -1; in compare_netdev_and_ip()
507 return -ENOMEM; in cma_add_id_to_tree()
514 node_id_priv->id.route.addr.dev_addr.bound_dev_if, in cma_add_id_to_tree()
519 new = &((*new)->rb_left); in cma_add_id_to_tree()
521 new = &((*new)->rb_right); in cma_add_id_to_tree()
523 list_add_tail(&node_id_priv->id_list_entry, in cma_add_id_to_tree()
524 &this->id_list); in cma_add_id_to_tree()
530 INIT_LIST_HEAD(&node->id_list); in cma_add_id_to_tree()
531 list_add_tail(&node_id_priv->id_list_entry, &node->id_list); in cma_add_id_to_tree()
533 rb_link_node(&node->rb_node, parent, new); in cma_add_id_to_tree()
534 rb_insert_color(&node->rb_node, &id_table); in cma_add_id_to_tree()
544 struct rb_node *node = root->rb_node; in node_from_ndev_ip()
552 node = node->rb_left; in node_from_ndev_ip()
554 node = node->rb_right; in node_from_ndev_ip()
568 if (list_empty(&id_priv->id_list_entry)) in cma_remove_id_from_tree()
572 id_priv->id.route.addr.dev_addr.bound_dev_if, in cma_remove_id_from_tree()
577 list_del_init(&id_priv->id_list_entry); in cma_remove_id_from_tree()
578 if (list_empty(&data->id_list)) { in cma_remove_id_from_tree()
579 rb_erase(&data->rb_node, &id_table); in cma_remove_id_from_tree()
590 id_priv->cma_dev = cma_dev; in _cma_attach_to_dev()
591 id_priv->id.device = cma_dev->device; in _cma_attach_to_dev()
592 id_priv->id.route.addr.dev_addr.transport = in _cma_attach_to_dev()
593 rdma_node_get_transport(cma_dev->device->node_type); in _cma_attach_to_dev()
594 list_add_tail(&id_priv->device_item, &cma_dev->id_list); in _cma_attach_to_dev()
596 trace_cm_id_attach(id_priv, cma_dev->device); in _cma_attach_to_dev()
603 id_priv->gid_type = in cma_attach_to_dev()
604 cma_dev->default_gid_type[id_priv->id.port_num - in cma_attach_to_dev()
605 rdma_start_port(cma_dev->device)]; in cma_attach_to_dev()
611 list_del_init(&id_priv->device_item); in cma_release_dev()
612 cma_dev_put(id_priv->cma_dev); in cma_release_dev()
613 id_priv->cma_dev = NULL; in cma_release_dev()
614 id_priv->id.device = NULL; in cma_release_dev()
615 if (id_priv->id.route.addr.dev_addr.sgid_attr) { in cma_release_dev()
616 rdma_put_gid_attr(id_priv->id.route.addr.dev_addr.sgid_attr); in cma_release_dev()
617 id_priv->id.route.addr.dev_addr.sgid_attr = NULL; in cma_release_dev()
624 return id_priv->id.route.addr.src_addr.ss_family; in cma_family()
632 switch (id_priv->id.ps) { in cma_set_default_qkey()
635 id_priv->qkey = RDMA_UDP_QKEY; in cma_set_default_qkey()
638 ib_addr_get_mgid(&id_priv->id.route.addr.dev_addr, &rec.mgid); in cma_set_default_qkey()
639 ret = ib_sa_get_mcmember_rec(id_priv->id.device, in cma_set_default_qkey()
640 id_priv->id.port_num, &rec.mgid, in cma_set_default_qkey()
643 id_priv->qkey = be32_to_cpu(rec.qkey); in cma_set_default_qkey()
654 (id_priv->qkey && (id_priv->qkey != qkey))) in cma_set_qkey()
655 return -EINVAL; in cma_set_qkey()
657 id_priv->qkey = qkey; in cma_set_qkey()
663 dev_addr->dev_type = ARPHRD_INFINIBAND; in cma_translate_ib()
664 rdma_addr_set_sgid(dev_addr, (union ib_gid *) &sib->sib_addr); in cma_translate_ib()
665 ib_addr_set_pkey(dev_addr, ntohs(sib->sib_pkey)); in cma_translate_ib()
672 if (addr->sa_family != AF_IB) { in cma_translate_addr()
688 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_validate_port()
689 const struct ib_gid_attr *sgid_attr = ERR_PTR(-ENODEV); in cma_validate_port()
690 int bound_if_index = dev_addr->bound_dev_if; in cma_validate_port()
691 int dev_type = dev_addr->dev_type; in cma_validate_port()
694 if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net)) in cma_validate_port()
716 ndev = rcu_dereference(sgid_attr->ndev); in cma_validate_port()
717 if (!net_eq(dev_net(ndev), dev_addr->net) || in cma_validate_port()
718 ndev->ifindex != bound_if_index) { in cma_validate_port()
720 sgid_attr = ERR_PTR(-ENODEV); in cma_validate_port()
727 ndev = dev_get_by_index(dev_addr->net, bound_if_index); in cma_validate_port()
743 WARN_ON(id_priv->id.route.addr.dev_addr.sgid_attr); in cma_bind_sgid_attr()
744 id_priv->id.route.addr.dev_addr.sgid_attr = sgid_attr; in cma_bind_sgid_attr()
748 * cma_acquire_dev_by_src_ip - Acquire cma device, port, gid attribute
758 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_acquire_dev_by_src_ip()
763 int ret = -ENODEV; in cma_acquire_dev_by_src_ip()
766 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_acquire_dev_by_src_ip()
767 id_priv->id.ps == RDMA_PS_IPOIB) in cma_acquire_dev_by_src_ip()
768 return -EINVAL; in cma_acquire_dev_by_src_ip()
770 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_acquire_dev_by_src_ip()
773 memcpy(&gid, dev_addr->src_dev_addr + in cma_acquire_dev_by_src_ip()
778 rdma_for_each_port (cma_dev->device, port) { in cma_acquire_dev_by_src_ip()
779 gidp = rdma_protocol_roce(cma_dev->device, port) ? in cma_acquire_dev_by_src_ip()
781 gid_type = cma_dev->default_gid_type[port - 1]; in cma_acquire_dev_by_src_ip()
782 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_acquire_dev_by_src_ip()
785 id_priv->id.port_num = port; in cma_acquire_dev_by_src_ip()
799 * cma_ib_acquire_dev - Acquire cma device, port and SGID attribute
813 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_acquire_dev()
818 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_ib_acquire_dev()
819 id_priv->id.ps == RDMA_PS_IPOIB) in cma_ib_acquire_dev()
820 return -EINVAL; in cma_ib_acquire_dev()
822 if (rdma_protocol_roce(req->device, req->port)) in cma_ib_acquire_dev()
823 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_ib_acquire_dev()
826 memcpy(&gid, dev_addr->src_dev_addr + in cma_ib_acquire_dev()
829 gid_type = listen_id_priv->cma_dev->default_gid_type[req->port - 1]; in cma_ib_acquire_dev()
830 sgid_attr = cma_validate_port(req->device, req->port, in cma_ib_acquire_dev()
835 id_priv->id.port_num = req->port; in cma_ib_acquire_dev()
838 * of cma_dev->id_list such as cma_netdev_callback() and in cma_ib_acquire_dev()
842 cma_attach_to_dev(id_priv, listen_id_priv->cma_dev); in cma_ib_acquire_dev()
844 rdma_restrack_add(&id_priv->res); in cma_ib_acquire_dev()
851 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iw_acquire_dev()
855 int ret = -ENODEV; in cma_iw_acquire_dev()
859 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_iw_acquire_dev()
860 id_priv->id.ps == RDMA_PS_IPOIB) in cma_iw_acquire_dev()
861 return -EINVAL; in cma_iw_acquire_dev()
863 memcpy(&gid, dev_addr->src_dev_addr + in cma_iw_acquire_dev()
868 cma_dev = listen_id_priv->cma_dev; in cma_iw_acquire_dev()
869 port = listen_id_priv->id.port_num; in cma_iw_acquire_dev()
870 gid_type = listen_id_priv->gid_type; in cma_iw_acquire_dev()
871 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
874 id_priv->id.port_num = port; in cma_iw_acquire_dev()
881 rdma_for_each_port (cma_dev->device, port) { in cma_iw_acquire_dev()
882 if (listen_id_priv->cma_dev == cma_dev && in cma_iw_acquire_dev()
883 listen_id_priv->id.port_num == port) in cma_iw_acquire_dev()
886 gid_type = cma_dev->default_gid_type[port - 1]; in cma_iw_acquire_dev()
887 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
890 id_priv->id.port_num = port; in cma_iw_acquire_dev()
901 rdma_restrack_add(&id_priv->res); in cma_iw_acquire_dev()
924 dgid = (union ib_gid *) &addr->sib_addr; in cma_resolve_ib_dev()
925 pkey = ntohs(addr->sib_pkey); in cma_resolve_ib_dev()
929 rdma_for_each_port (cur_dev->device, p) { in cma_resolve_ib_dev()
930 if (!rdma_cap_af_ib(cur_dev->device, p)) in cma_resolve_ib_dev()
933 if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index)) in cma_resolve_ib_dev()
936 if (ib_get_cached_port_state(cur_dev->device, p, &port_state)) in cma_resolve_ib_dev()
939 for (i = 0; i < cur_dev->device->port_data[p].immutable.gid_tbl_len; in cma_resolve_ib_dev()
941 ret = rdma_query_gid(cur_dev->device, p, i, in cma_resolve_ib_dev()
949 id_priv->id.port_num = p; in cma_resolve_ib_dev()
954 dgid->global.subnet_prefix) && in cma_resolve_ib_dev()
958 id_priv->id.port_num = p; in cma_resolve_ib_dev()
965 return -ENODEV; in cma_resolve_ib_dev()
969 rdma_restrack_add(&id_priv->res); in cma_resolve_ib_dev()
972 memcpy(&addr->sib_addr, &sgid, sizeof(sgid)); in cma_resolve_ib_dev()
973 cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); in cma_resolve_ib_dev()
979 refcount_inc(&id_priv->refcount); in cma_id_get()
984 if (refcount_dec_and_test(&id_priv->refcount)) in cma_id_put()
985 complete(&id_priv->comp); in cma_id_put()
997 return ERR_PTR(-ENOMEM); in __rdma_create_id()
999 id_priv->state = RDMA_CM_IDLE; in __rdma_create_id()
1000 id_priv->id.context = context; in __rdma_create_id()
1001 id_priv->id.event_handler = event_handler; in __rdma_create_id()
1002 id_priv->id.ps = ps; in __rdma_create_id()
1003 id_priv->id.qp_type = qp_type; in __rdma_create_id()
1004 id_priv->tos_set = false; in __rdma_create_id()
1005 id_priv->timeout_set = false; in __rdma_create_id()
1006 id_priv->min_rnr_timer_set = false; in __rdma_create_id()
1007 id_priv->gid_type = IB_GID_TYPE_IB; in __rdma_create_id()
1008 spin_lock_init(&id_priv->lock); in __rdma_create_id()
1009 mutex_init(&id_priv->qp_mutex); in __rdma_create_id()
1010 init_completion(&id_priv->comp); in __rdma_create_id()
1011 refcount_set(&id_priv->refcount, 1); in __rdma_create_id()
1012 mutex_init(&id_priv->handler_mutex); in __rdma_create_id()
1013 INIT_LIST_HEAD(&id_priv->device_item); in __rdma_create_id()
1014 INIT_LIST_HEAD(&id_priv->id_list_entry); in __rdma_create_id()
1015 INIT_LIST_HEAD(&id_priv->listen_list); in __rdma_create_id()
1016 INIT_LIST_HEAD(&id_priv->mc_list); in __rdma_create_id()
1017 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); in __rdma_create_id()
1018 id_priv->id.route.addr.dev_addr.net = get_net(net); in __rdma_create_id()
1019 id_priv->seq_num &= 0x00ffffff; in __rdma_create_id()
1021 rdma_restrack_new(&id_priv->res, RDMA_RESTRACK_CM_ID); in __rdma_create_id()
1023 rdma_restrack_parent_name(&id_priv->res, &parent->res); in __rdma_create_id()
1039 rdma_restrack_set_name(&ret->res, caller); in __rdma_create_kernel_id()
1040 return &ret->id; in __rdma_create_kernel_id()
1051 ret = __rdma_create_id(current->nsproxy->net_ns, event_handler, context, in rdma_create_user_id()
1056 rdma_restrack_set_name(&ret->res, NULL); in rdma_create_user_id()
1057 return &ret->id; in rdma_create_user_id()
1067 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_ud_qp()
1093 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_conn_qp()
1108 if (id->device != pd->device) { in rdma_create_qp()
1109 ret = -EINVAL; in rdma_create_qp()
1113 qp_init_attr->port_num = id->port_num; in rdma_create_qp()
1120 if (id->qp_type == IB_QPT_UD) in rdma_create_qp()
1127 id->qp = qp; in rdma_create_qp()
1128 id_priv->qp_num = qp->qp_num; in rdma_create_qp()
1129 id_priv->srq = (qp->srq != NULL); in rdma_create_qp()
1146 mutex_lock(&id_priv->qp_mutex); in rdma_destroy_qp()
1147 ib_destroy_qp(id_priv->id.qp); in rdma_destroy_qp()
1148 id_priv->id.qp = NULL; in rdma_destroy_qp()
1149 mutex_unlock(&id_priv->qp_mutex); in rdma_destroy_qp()
1159 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
1160 if (!id_priv->id.qp) { in cma_modify_qp_rtr()
1167 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1171 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1176 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1180 BUG_ON(id_priv->cma_dev->device != id_priv->id.device); in cma_modify_qp_rtr()
1183 qp_attr.max_dest_rd_atomic = conn_param->responder_resources; in cma_modify_qp_rtr()
1184 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1186 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
1196 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1197 if (!id_priv->id.qp) { in cma_modify_qp_rts()
1203 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rts()
1208 qp_attr.max_rd_atomic = conn_param->initiator_depth; in cma_modify_qp_rts()
1209 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rts()
1211 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1220 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_err()
1221 if (!id_priv->id.qp) { in cma_modify_qp_err()
1227 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, IB_QP_STATE); in cma_modify_qp_err()
1229 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_err()
1236 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_init_qp_attr()
1240 if (rdma_cap_eth_ah(id_priv->id.device, id_priv->id.port_num)) in cma_ib_init_qp_attr()
1245 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, in cma_ib_init_qp_attr()
1246 pkey, &qp_attr->pkey_index); in cma_ib_init_qp_attr()
1250 qp_attr->port_num = id_priv->id.port_num; in cma_ib_init_qp_attr()
1253 if (id_priv->id.qp_type == IB_QPT_UD) { in cma_ib_init_qp_attr()
1258 qp_attr->qkey = id_priv->qkey; in cma_ib_init_qp_attr()
1261 qp_attr->qp_access_flags = 0; in cma_ib_init_qp_attr()
1274 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1275 if (!id_priv->cm_id.ib || (id_priv->id.qp_type == IB_QPT_UD)) in rdma_init_qp_attr()
1278 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, in rdma_init_qp_attr()
1281 if (qp_attr->qp_state == IB_QPS_RTR) in rdma_init_qp_attr()
1282 qp_attr->rq_psn = id_priv->seq_num; in rdma_init_qp_attr()
1283 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1284 if (!id_priv->cm_id.iw) { in rdma_init_qp_attr()
1285 qp_attr->qp_access_flags = 0; in rdma_init_qp_attr()
1288 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, in rdma_init_qp_attr()
1290 qp_attr->port_num = id_priv->id.port_num; in rdma_init_qp_attr()
1293 ret = -ENOSYS; in rdma_init_qp_attr()
1296 if ((*qp_attr_mask & IB_QP_TIMEOUT) && id_priv->timeout_set) in rdma_init_qp_attr()
1297 qp_attr->timeout = id_priv->timeout; in rdma_init_qp_attr()
1299 if ((*qp_attr_mask & IB_QP_MIN_RNR_TIMER) && id_priv->min_rnr_timer_set) in rdma_init_qp_attr()
1300 qp_attr->min_rnr_timer = id_priv->min_rnr_timer; in rdma_init_qp_attr()
1308 switch (addr->sa_family) { in cma_zero_addr()
1310 return ipv4_is_zeronet(((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_zero_addr()
1312 return ipv6_addr_any(&((struct sockaddr_in6 *)addr)->sin6_addr); in cma_zero_addr()
1314 return ib_addr_any(&((struct sockaddr_ib *)addr)->sib_addr); in cma_zero_addr()
1322 switch (addr->sa_family) { in cma_loopback_addr()
1325 ((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_loopback_addr()
1328 &((struct sockaddr_in6 *)addr)->sin6_addr); in cma_loopback_addr()
1331 &((struct sockaddr_ib *)addr)->sib_addr); in cma_loopback_addr()
1344 if (src->sa_family != dst->sa_family) in cma_addr_cmp()
1345 return -1; in cma_addr_cmp()
1347 switch (src->sa_family) { in cma_addr_cmp()
1349 return ((struct sockaddr_in *)src)->sin_addr.s_addr != in cma_addr_cmp()
1350 ((struct sockaddr_in *)dst)->sin_addr.s_addr; in cma_addr_cmp()
1356 if (ipv6_addr_cmp(&src_addr6->sin6_addr, in cma_addr_cmp()
1357 &dst_addr6->sin6_addr)) in cma_addr_cmp()
1359 link_local = ipv6_addr_type(&dst_addr6->sin6_addr) & in cma_addr_cmp()
1362 return link_local ? (src_addr6->sin6_scope_id != in cma_addr_cmp()
1363 dst_addr6->sin6_scope_id) : in cma_addr_cmp()
1368 return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, in cma_addr_cmp()
1369 &((struct sockaddr_ib *) dst)->sib_addr); in cma_addr_cmp()
1377 switch (addr->sa_family) { in cma_port()
1379 return ((struct sockaddr_in *) addr)->sin_port; in cma_port()
1381 return ((struct sockaddr_in6 *) addr)->sin6_port; in cma_port()
1384 return htons((u16) (be64_to_cpu(sib->sib_sid) & in cma_port()
1385 be64_to_cpu(sib->sib_sid_mask))); in cma_port()
1403 listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; in cma_save_ib_info()
1406 ib->sib_family = AF_IB; in cma_save_ib_info()
1408 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1409 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1410 memcpy(&ib->sib_addr, &path->sgid, 16); in cma_save_ib_info()
1411 ib->sib_sid = path->service_id; in cma_save_ib_info()
1412 ib->sib_scope_id = 0; in cma_save_ib_info()
1414 ib->sib_pkey = listen_ib->sib_pkey; in cma_save_ib_info()
1415 ib->sib_flowinfo = listen_ib->sib_flowinfo; in cma_save_ib_info()
1416 ib->sib_addr = listen_ib->sib_addr; in cma_save_ib_info()
1417 ib->sib_sid = listen_ib->sib_sid; in cma_save_ib_info()
1418 ib->sib_scope_id = listen_ib->sib_scope_id; in cma_save_ib_info()
1420 ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); in cma_save_ib_info()
1424 ib->sib_family = AF_IB; in cma_save_ib_info()
1426 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1427 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1428 memcpy(&ib->sib_addr, &path->dgid, 16); in cma_save_ib_info()
1441 .sin_addr.s_addr = hdr->dst_addr.ip4.addr, in cma_save_ip4_info()
1449 .sin_addr.s_addr = hdr->src_addr.ip4.addr, in cma_save_ip4_info()
1450 .sin_port = hdr->port, in cma_save_ip4_info()
1463 .sin6_addr = hdr->dst_addr.ip6, in cma_save_ip6_info()
1471 .sin6_addr = hdr->src_addr.ip6, in cma_save_ip6_info()
1472 .sin6_port = hdr->port, in cma_save_ip6_info()
1490 hdr = ib_event->private_data; in cma_save_ip_info()
1491 if (hdr->cma_version != CMA_VERSION) in cma_save_ip_info()
1492 return -EINVAL; in cma_save_ip_info()
1506 return -EAFNOSUPPORT; in cma_save_ip_info()
1519 if (ib_event->event == IB_CM_REQ_RECEIVED) in cma_save_net_info()
1521 ib_event->param.req_rcvd.primary_path); in cma_save_net_info()
1522 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in cma_save_net_info()
1534 &ib_event->param.req_rcvd; in cma_save_req_info()
1536 &ib_event->param.sidr_req_rcvd; in cma_save_req_info()
1538 switch (ib_event->event) { in cma_save_req_info()
1540 req->device = req_param->listen_id->device; in cma_save_req_info()
1541 req->port = req_param->port; in cma_save_req_info()
1542 memcpy(&req->local_gid, &req_param->primary_path->sgid, in cma_save_req_info()
1543 sizeof(req->local_gid)); in cma_save_req_info()
1544 req->has_gid = true; in cma_save_req_info()
1545 req->service_id = req_param->primary_path->service_id; in cma_save_req_info()
1546 req->pkey = be16_to_cpu(req_param->primary_path->pkey); in cma_save_req_info()
1547 if (req->pkey != req_param->bth_pkey) in cma_save_req_info()
1550 req_param->bth_pkey, req->pkey); in cma_save_req_info()
1553 req->device = sidr_param->listen_id->device; in cma_save_req_info()
1554 req->port = sidr_param->port; in cma_save_req_info()
1555 req->has_gid = false; in cma_save_req_info()
1556 req->service_id = sidr_param->service_id; in cma_save_req_info()
1557 req->pkey = sidr_param->pkey; in cma_save_req_info()
1558 if (req->pkey != sidr_param->bth_pkey) in cma_save_req_info()
1561 sidr_param->bth_pkey, req->pkey); in cma_save_req_info()
1564 return -EINVAL; in cma_save_req_info()
1574 __be32 daddr = dst_addr->sin_addr.s_addr, in validate_ipv4_net_dev()
1575 saddr = src_addr->sin_addr.s_addr; in validate_ipv4_net_dev()
1588 fl4.flowi4_oif = net_dev->ifindex; in validate_ipv4_net_dev()
1605 const int strict = ipv6_addr_type(&dst_addr->sin6_addr) & in validate_ipv6_net_dev()
1607 struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr, in validate_ipv6_net_dev()
1608 &src_addr->sin6_addr, net_dev->ifindex, in validate_ipv6_net_dev()
1615 ret = rt->rt6i_idev->dev == net_dev; in validate_ipv6_net_dev()
1633 switch (daddr->sa_family) { in validate_net_dev()
1635 return saddr->sa_family == AF_INET && in validate_net_dev()
1639 return saddr->sa_family == AF_INET6 && in validate_net_dev()
1653 if (ib_event->event == IB_CM_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1654 sgid_attr = ib_event->param.req_rcvd.ppath_sgid_attr; in roce_get_net_dev_by_cm_event()
1655 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1656 sgid_attr = ib_event->param.sidr_req_rcvd.sgid_attr; in roce_get_net_dev_by_cm_event()
1675 (struct sockaddr *)&req->listen_addr_storage; in cma_get_net_dev()
1676 struct sockaddr *src_addr = (struct sockaddr *)&req->src_addr_storage; in cma_get_net_dev()
1678 const union ib_gid *gid = req->has_gid ? &req->local_gid : NULL; in cma_get_net_dev()
1682 req->service_id); in cma_get_net_dev()
1686 if (rdma_protocol_roce(req->device, req->port)) in cma_get_net_dev()
1689 net_dev = ib_get_net_dev_by_params(req->device, req->port, in cma_get_net_dev()
1690 req->pkey, in cma_get_net_dev()
1693 return ERR_PTR(-ENODEV); in cma_get_net_dev()
1710 if (cma_any_addr(addr) && !id_priv->afonly) in cma_match_private_data()
1713 switch (addr->sa_family) { in cma_match_private_data()
1715 ip4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; in cma_match_private_data()
1719 hdr->dst_addr.ip4.addr != ip4_addr) in cma_match_private_data()
1723 ip6_addr = ((struct sockaddr_in6 *)addr)->sin6_addr; in cma_match_private_data()
1727 memcmp(&hdr->dst_addr.ip6, &ip6_addr, sizeof(ip6_addr))) in cma_match_private_data()
1741 struct ib_device *device = id->device; in cma_protocol_roce()
1742 const u32 port_num = id->port_num ?: rdma_start_port(device); in cma_protocol_roce()
1750 (const struct sockaddr *)&req->listen_addr_storage; in cma_is_req_ipv6_ll()
1754 return (daddr->sa_family == AF_INET6 && in cma_is_req_ipv6_ll()
1755 (ipv6_addr_type(&daddr6->sin6_addr) & IPV6_ADDR_LINKLOCAL)); in cma_is_req_ipv6_ll()
1762 const struct rdma_addr *addr = &id->route.addr; in cma_match_net_dev()
1766 return (!id->port_num || id->port_num == req->port) && in cma_match_net_dev()
1767 (addr->src_addr.ss_family == AF_IB); in cma_match_net_dev()
1779 if (net_eq(dev_net(net_dev), addr->dev_addr.net) && in cma_match_net_dev()
1780 (!!addr->dev_addr.bound_dev_if == in cma_match_net_dev()
1781 (addr->dev_addr.bound_dev_if == net_dev->ifindex))) in cma_match_net_dev()
1799 return ERR_PTR(-EINVAL); in cma_find_listener()
1801 hlist_for_each_entry(id_priv, &bind_list->owners, node) { in cma_find_listener()
1802 if (cma_match_private_data(id_priv, ib_event->private_data)) { in cma_find_listener()
1803 if (id_priv->id.device == cm_id->device && in cma_find_listener()
1804 cma_match_net_dev(&id_priv->id, net_dev, req)) in cma_find_listener()
1807 &id_priv->listen_list, in cma_find_listener()
1809 if (id_priv_dev->id.device == cm_id->device && in cma_find_listener()
1810 cma_match_net_dev(&id_priv_dev->id, in cma_find_listener()
1817 return ERR_PTR(-EINVAL); in cma_find_listener()
1836 if (PTR_ERR(*net_dev) == -EAFNOSUPPORT) { in cma_ib_id_from_event()
1867 if (((*net_dev)->flags & IFF_UP) == 0) { in cma_ib_id_from_event()
1868 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1873 (struct sockaddr *)&req->src_addr_storage, in cma_ib_id_from_event()
1874 (struct sockaddr *)&req->listen_addr_storage)) { in cma_ib_id_from_event()
1875 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1881 rdma_ps_from_service_id(req->service_id), in cma_ib_id_from_event()
1882 cma_port_from_service_id(req->service_id)); in cma_ib_id_from_event()
1901 if (rdma_cap_ib_sa(id_priv->id.device, id_priv->id.port_num)) { in cma_cancel_route()
1902 if (id_priv->query) in cma_cancel_route()
1903 ib_sa_cancel_query(id_priv->query_id, id_priv->query); in cma_cancel_route()
1917 list_del_init(&id_priv->listen_any_item); in _cma_cancel_listens()
1919 while (!list_empty(&id_priv->listen_list)) { in _cma_cancel_listens()
1921 list_first_entry(&id_priv->listen_list, in _cma_cancel_listens()
1924 list_del_init(&dev_id_priv->device_item); in _cma_cancel_listens()
1925 list_del_init(&dev_id_priv->listen_item); in _cma_cancel_listens()
1928 rdma_destroy_id(&dev_id_priv->id); in _cma_cancel_listens()
1953 rdma_addr_cancel(&id_priv->id.route.addr.dev_addr); in cma_cancel_operation()
1959 if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev) in cma_cancel_operation()
1969 struct rdma_bind_list *bind_list = id_priv->bind_list; in cma_release_port()
1970 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_release_port()
1976 hlist_del(&id_priv->node); in cma_release_port()
1977 if (hlist_empty(&bind_list->owners)) { in cma_release_port()
1978 cma_ps_remove(net, bind_list->ps, bind_list->port); in cma_release_port()
1985 struct cma_multicast *mc) in destroy_mc() argument
1987 bool send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); in destroy_mc()
1989 if (rdma_cap_ib_mcast(id_priv->id.device, id_priv->id.port_num)) in destroy_mc()
1990 ib_sa_free_multicast(mc->sa_mc); in destroy_mc()
1992 if (rdma_protocol_roce(id_priv->id.device, id_priv->id.port_num)) { in destroy_mc()
1994 &id_priv->id.route.addr.dev_addr; in destroy_mc()
1997 if (dev_addr->bound_dev_if) in destroy_mc()
1998 ndev = dev_get_by_index(dev_addr->net, in destroy_mc()
1999 dev_addr->bound_dev_if); in destroy_mc()
2004 gid_type = id_priv->cma_dev->default_gid_type in destroy_mc()
2005 [id_priv->id.port_num - in destroy_mc()
2007 id_priv->cma_dev->device)]; in destroy_mc()
2008 cma_iboe_set_mgid((struct sockaddr *)&mc->addr, &mgid, in destroy_mc()
2014 cancel_work_sync(&mc->iboe_join.work); in destroy_mc()
2016 kfree(mc); in destroy_mc()
2021 struct cma_multicast *mc; in cma_leave_mc_groups() local
2023 while (!list_empty(&id_priv->mc_list)) { in cma_leave_mc_groups()
2024 mc = list_first_entry(&id_priv->mc_list, struct cma_multicast, in cma_leave_mc_groups()
2026 list_del(&mc->list); in cma_leave_mc_groups()
2027 destroy_mc(id_priv, mc); in cma_leave_mc_groups()
2036 rdma_restrack_del(&id_priv->res); in _destroy_id()
2038 if (id_priv->cma_dev) { in _destroy_id()
2039 if (rdma_cap_ib_cm(id_priv->id.device, 1)) { in _destroy_id()
2040 if (id_priv->cm_id.ib) in _destroy_id()
2041 ib_destroy_cm_id(id_priv->cm_id.ib); in _destroy_id()
2042 } else if (rdma_cap_iw_cm(id_priv->id.device, 1)) { in _destroy_id()
2043 if (id_priv->cm_id.iw) in _destroy_id()
2044 iw_destroy_cm_id(id_priv->cm_id.iw); in _destroy_id()
2052 wait_for_completion(&id_priv->comp); in _destroy_id()
2054 if (id_priv->internal_id) in _destroy_id()
2055 cma_id_put(id_priv->id.context); in _destroy_id()
2057 kfree(id_priv->id.route.path_rec); in _destroy_id()
2058 kfree(id_priv->id.route.path_rec_inbound); in _destroy_id()
2059 kfree(id_priv->id.route.path_rec_outbound); in _destroy_id()
2061 put_net(id_priv->id.route.addr.dev_addr.net); in _destroy_id()
2070 __releases(&idprv->handler_mutex) in destroy_id_handler_unlock()
2083 lockdep_assert_held(&id_priv->handler_mutex); in destroy_id_handler_unlock()
2084 spin_lock_irqsave(&id_priv->lock, flags); in destroy_id_handler_unlock()
2085 state = id_priv->state; in destroy_id_handler_unlock()
2086 id_priv->state = RDMA_CM_DESTROYING; in destroy_id_handler_unlock()
2087 spin_unlock_irqrestore(&id_priv->lock, flags); in destroy_id_handler_unlock()
2088 mutex_unlock(&id_priv->handler_mutex); in destroy_id_handler_unlock()
2097 mutex_lock(&id_priv->handler_mutex); in rdma_destroy_id()
2115 ret = ib_send_cm_rtu(id_priv->cm_id.ib, NULL, 0); in cma_rep_recv()
2124 ib_send_cm_rej(id_priv->cm_id.ib, IB_CM_REJ_CONSUMER_DEFINED, in cma_rep_recv()
2133 event->param.conn.private_data = private_data; in cma_set_rep_event_data()
2134 event->param.conn.private_data_len = IB_CM_REP_PRIVATE_DATA_SIZE; in cma_set_rep_event_data()
2135 event->param.conn.responder_resources = rep_data->responder_resources; in cma_set_rep_event_data()
2136 event->param.conn.initiator_depth = rep_data->initiator_depth; in cma_set_rep_event_data()
2137 event->param.conn.flow_control = rep_data->flow_control; in cma_set_rep_event_data()
2138 event->param.conn.rnr_retry_count = rep_data->rnr_retry_count; in cma_set_rep_event_data()
2139 event->param.conn.srq = rep_data->srq; in cma_set_rep_event_data()
2140 event->param.conn.qp_num = rep_data->remote_qpn; in cma_set_rep_event_data()
2142 event->ece.vendor_id = rep_data->ece.vendor_id; in cma_set_rep_event_data()
2143 event->ece.attr_mod = rep_data->ece.attr_mod; in cma_set_rep_event_data()
2151 lockdep_assert_held(&id_priv->handler_mutex); in cma_cm_event_handler()
2154 ret = id_priv->id.event_handler(&id_priv->id, event); in cma_cm_event_handler()
2162 struct rdma_id_private *id_priv = cm_id->context; in cma_ib_handler()
2167 mutex_lock(&id_priv->handler_mutex); in cma_ib_handler()
2168 state = READ_ONCE(id_priv->state); in cma_ib_handler()
2169 if ((ib_event->event != IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
2171 (ib_event->event == IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
2175 switch (ib_event->event) { in cma_ib_handler()
2179 event.status = -ETIMEDOUT; in cma_ib_handler()
2183 (id_priv->id.qp_type != IB_QPT_UD)) { in cma_ib_handler()
2187 if (id_priv->id.qp) { in cma_ib_handler()
2194 cma_set_rep_event_data(&event, &ib_event->param.rep_rcvd, in cma_ib_handler()
2195 ib_event->private_data); in cma_ib_handler()
2202 event.status = -ETIMEDOUT; in cma_ib_handler()
2218 pr_debug_ratelimited("RDMA CM: REJECTED: %s\n", rdma_reject_msg(&id_priv->id, in cma_ib_handler()
2219 ib_event->param.rej_rcvd.reason)); in cma_ib_handler()
2221 event.status = ib_event->param.rej_rcvd.reason; in cma_ib_handler()
2223 event.param.conn.private_data = ib_event->private_data; in cma_ib_handler()
2228 ib_event->event); in cma_ib_handler()
2234 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_handler()
2235 id_priv->cm_id.ib = NULL; in cma_ib_handler()
2240 mutex_unlock(&id_priv->handler_mutex); in cma_ib_handler()
2253 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_conn_id()
2254 struct sa_path_rec *path = ib_event->param.req_rcvd.primary_path; in cma_ib_new_conn_id()
2256 ib_event->param.req_rcvd.primary_path->service_id; in cma_ib_new_conn_id()
2260 id_priv = __rdma_create_id(listen_id->route.addr.dev_addr.net, in cma_ib_new_conn_id()
2261 listen_id->event_handler, listen_id->context, in cma_ib_new_conn_id()
2262 listen_id->ps, in cma_ib_new_conn_id()
2263 ib_event->param.req_rcvd.qp_type, in cma_ib_new_conn_id()
2268 id = &id_priv->id; in cma_ib_new_conn_id()
2269 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_conn_id()
2270 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_conn_id()
2274 rt = &id->route; in cma_ib_new_conn_id()
2275 rt->num_pri_alt_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; in cma_ib_new_conn_id()
2276 rt->path_rec = kmalloc_array(rt->num_pri_alt_paths, in cma_ib_new_conn_id()
2277 sizeof(*rt->path_rec), GFP_KERNEL); in cma_ib_new_conn_id()
2278 if (!rt->path_rec) in cma_ib_new_conn_id()
2281 rt->path_rec[0] = *path; in cma_ib_new_conn_id()
2282 if (rt->num_pri_alt_paths == 2) in cma_ib_new_conn_id()
2283 rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; in cma_ib_new_conn_id()
2286 rdma_copy_src_l2_addr(&rt->addr.dev_addr, net_dev); in cma_ib_new_conn_id()
2290 rt->addr.dev_addr.dev_type = ARPHRD_INFINIBAND; in cma_ib_new_conn_id()
2291 rdma_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid); in cma_ib_new_conn_id()
2292 ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey)); in cma_ib_new_conn_id()
2294 ret = cma_translate_addr(cma_src_addr(id_priv), &rt->addr.dev_addr); in cma_ib_new_conn_id()
2299 rdma_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid); in cma_ib_new_conn_id()
2301 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_conn_id()
2317 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_udp_id()
2318 struct net *net = listen_id->route.addr.dev_addr.net; in cma_ib_new_udp_id()
2322 id_priv = __rdma_create_id(net, listen_id->event_handler, in cma_ib_new_udp_id()
2323 listen_id->context, listen_id->ps, IB_QPT_UD, in cma_ib_new_udp_id()
2328 id = &id_priv->id; in cma_ib_new_udp_id()
2329 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_udp_id()
2330 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_udp_id()
2332 ib_event->param.sidr_req_rcvd.service_id)) in cma_ib_new_udp_id()
2336 rdma_copy_src_l2_addr(&id->route.addr.dev_addr, net_dev); in cma_ib_new_udp_id()
2340 &id->route.addr.dev_addr); in cma_ib_new_udp_id()
2346 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_udp_id()
2357 event->param.conn.private_data = private_data + offset; in cma_set_req_event_data()
2358 event->param.conn.private_data_len = IB_CM_REQ_PRIVATE_DATA_SIZE - offset; in cma_set_req_event_data()
2359 event->param.conn.responder_resources = req_data->responder_resources; in cma_set_req_event_data()
2360 event->param.conn.initiator_depth = req_data->initiator_depth; in cma_set_req_event_data()
2361 event->param.conn.flow_control = req_data->flow_control; in cma_set_req_event_data()
2362 event->param.conn.retry_count = req_data->retry_count; in cma_set_req_event_data()
2363 event->param.conn.rnr_retry_count = req_data->rnr_retry_count; in cma_set_req_event_data()
2364 event->param.conn.srq = req_data->srq; in cma_set_req_event_data()
2365 event->param.conn.qp_num = req_data->remote_qpn; in cma_set_req_event_data()
2367 event->ece.vendor_id = req_data->ece.vendor_id; in cma_set_req_event_data()
2368 event->ece.attr_mod = req_data->ece.attr_mod; in cma_set_req_event_data()
2374 return (((ib_event->event == IB_CM_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2375 (ib_event->param.req_rcvd.qp_type == id->qp_type)) || in cma_ib_check_req_qp_type()
2376 ((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2377 (id->qp_type == IB_QPT_UD)) || in cma_ib_check_req_qp_type()
2378 (!id->qp_type)); in cma_ib_check_req_qp_type()
2395 trace_cm_req_handler(listen_id, ib_event->event); in cma_ib_req_handler()
2396 if (!cma_ib_check_req_qp_type(&listen_id->id, ib_event)) { in cma_ib_req_handler()
2397 ret = -EINVAL; in cma_ib_req_handler()
2401 mutex_lock(&listen_id->handler_mutex); in cma_ib_req_handler()
2402 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) { in cma_ib_req_handler()
2403 ret = -ECONNABORTED; in cma_ib_req_handler()
2409 if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) { in cma_ib_req_handler()
2410 conn_id = cma_ib_new_udp_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2411 event.param.ud.private_data = ib_event->private_data + offset; in cma_ib_req_handler()
2413 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; in cma_ib_req_handler()
2415 conn_id = cma_ib_new_conn_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2416 cma_set_req_event_data(&event, &ib_event->param.req_rcvd, in cma_ib_req_handler()
2417 ib_event->private_data, offset); in cma_ib_req_handler()
2420 ret = -ENOMEM; in cma_ib_req_handler()
2424 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in cma_ib_req_handler()
2431 conn_id->cm_id.ib = cm_id; in cma_ib_req_handler()
2432 cm_id->context = conn_id; in cma_ib_req_handler()
2433 cm_id->cm_handler = cma_ib_handler; in cma_ib_req_handler()
2437 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_req_handler()
2438 conn_id->cm_id.ib = NULL; in cma_ib_req_handler()
2439 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2444 if (READ_ONCE(conn_id->state) == RDMA_CM_CONNECT && in cma_ib_req_handler()
2445 conn_id->id.qp_type != IB_QPT_UD) { in cma_ib_req_handler()
2446 trace_cm_send_mra(cm_id->context); in cma_ib_req_handler()
2449 mutex_unlock(&conn_id->handler_mutex); in cma_ib_req_handler()
2452 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2462 if (addr->sa_family == AF_IB) in rdma_get_service_id()
2463 return ((struct sockaddr_ib *) addr)->sib_sid; in rdma_get_service_id()
2465 return cpu_to_be64(((u64)id->ps << 16) + be16_to_cpu(cma_port(addr))); in rdma_get_service_id()
2472 struct rdma_addr *addr = &cm_id->route.addr; in rdma_read_gids()
2474 if (!cm_id->device) { in rdma_read_gids()
2482 if (rdma_protocol_roce(cm_id->device, cm_id->port_num)) { in rdma_read_gids()
2484 rdma_ip2gid((struct sockaddr *)&addr->src_addr, sgid); in rdma_read_gids()
2486 rdma_ip2gid((struct sockaddr *)&addr->dst_addr, dgid); in rdma_read_gids()
2489 rdma_addr_get_sgid(&addr->dev_addr, sgid); in rdma_read_gids()
2491 rdma_addr_get_dgid(&addr->dev_addr, dgid); in rdma_read_gids()
2498 struct rdma_id_private *id_priv = iw_id->context; in cma_iw_handler()
2501 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in cma_iw_handler()
2502 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in cma_iw_handler()
2504 mutex_lock(&id_priv->handler_mutex); in cma_iw_handler()
2505 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_iw_handler()
2508 switch (iw_event->event) { in cma_iw_handler()
2517 switch (iw_event->status) { in cma_iw_handler()
2520 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2521 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2523 case -ECONNRESET: in cma_iw_handler()
2524 case -ECONNREFUSED: in cma_iw_handler()
2527 case -ETIMEDOUT: in cma_iw_handler()
2537 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2538 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2544 event.status = iw_event->status; in cma_iw_handler()
2545 event.param.conn.private_data = iw_event->private_data; in cma_iw_handler()
2546 event.param.conn.private_data_len = iw_event->private_data_len; in cma_iw_handler()
2549 /* Destroy the CM ID by returning a non-zero value. */ in cma_iw_handler()
2550 id_priv->cm_id.iw = NULL; in cma_iw_handler()
2556 mutex_unlock(&id_priv->handler_mutex); in cma_iw_handler()
2565 int ret = -ECONNABORTED; in iw_conn_req_handler()
2566 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in iw_conn_req_handler()
2567 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in iw_conn_req_handler()
2570 event.param.conn.private_data = iw_event->private_data; in iw_conn_req_handler()
2571 event.param.conn.private_data_len = iw_event->private_data_len; in iw_conn_req_handler()
2572 event.param.conn.initiator_depth = iw_event->ird; in iw_conn_req_handler()
2573 event.param.conn.responder_resources = iw_event->ord; in iw_conn_req_handler()
2575 listen_id = cm_id->context; in iw_conn_req_handler()
2577 mutex_lock(&listen_id->handler_mutex); in iw_conn_req_handler()
2578 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) in iw_conn_req_handler()
2582 conn_id = __rdma_create_id(listen_id->id.route.addr.dev_addr.net, in iw_conn_req_handler()
2583 listen_id->id.event_handler, in iw_conn_req_handler()
2584 listen_id->id.context, RDMA_PS_TCP, in iw_conn_req_handler()
2587 ret = -ENOMEM; in iw_conn_req_handler()
2590 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in iw_conn_req_handler()
2591 conn_id->state = RDMA_CM_CONNECT; in iw_conn_req_handler()
2593 ret = rdma_translate_ip(laddr, &conn_id->id.route.addr.dev_addr); in iw_conn_req_handler()
2595 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2602 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2607 conn_id->cm_id.iw = cm_id; in iw_conn_req_handler()
2608 cm_id->context = conn_id; in iw_conn_req_handler()
2609 cm_id->cm_handler = cma_iw_handler; in iw_conn_req_handler()
2617 conn_id->cm_id.iw = NULL; in iw_conn_req_handler()
2618 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2623 mutex_unlock(&conn_id->handler_mutex); in iw_conn_req_handler()
2626 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2637 svc_id = rdma_get_service_id(&id_priv->id, addr); in cma_ib_listen()
2638 id = ib_cm_insert_listen(id_priv->id.device, in cma_ib_listen()
2642 id_priv->cm_id.ib = id; in cma_ib_listen()
2652 id = iw_create_cm_id(id_priv->id.device, in cma_iw_listen()
2658 mutex_lock(&id_priv->qp_mutex); in cma_iw_listen()
2659 id->tos = id_priv->tos; in cma_iw_listen()
2660 id->tos_set = id_priv->tos_set; in cma_iw_listen()
2661 mutex_unlock(&id_priv->qp_mutex); in cma_iw_listen()
2662 id->afonly = id_priv->afonly; in cma_iw_listen()
2663 id_priv->cm_id.iw = id; in cma_iw_listen()
2665 memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), in cma_iw_listen()
2668 ret = iw_cm_listen(id_priv->cm_id.iw, backlog); in cma_iw_listen()
2671 iw_destroy_cm_id(id_priv->cm_id.iw); in cma_iw_listen()
2672 id_priv->cm_id.iw = NULL; in cma_iw_listen()
2681 struct rdma_id_private *id_priv = id->context; in cma_listen_handler()
2684 if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) in cma_listen_handler()
2685 return -1; in cma_listen_handler()
2687 id->context = id_priv->id.context; in cma_listen_handler()
2688 id->event_handler = id_priv->id.event_handler; in cma_listen_handler()
2690 return id_priv->id.event_handler(id, event); in cma_listen_handler()
2698 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_listen_on_dev()
2704 if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1)) in cma_listen_on_dev()
2709 id_priv->id.ps, id_priv->id.qp_type, id_priv); in cma_listen_on_dev()
2713 dev_id_priv->state = RDMA_CM_ADDR_BOUND; in cma_listen_on_dev()
2718 rdma_restrack_add(&dev_id_priv->res); in cma_listen_on_dev()
2720 dev_id_priv->internal_id = 1; in cma_listen_on_dev()
2721 dev_id_priv->afonly = id_priv->afonly; in cma_listen_on_dev()
2722 mutex_lock(&id_priv->qp_mutex); in cma_listen_on_dev()
2723 dev_id_priv->tos_set = id_priv->tos_set; in cma_listen_on_dev()
2724 dev_id_priv->tos = id_priv->tos; in cma_listen_on_dev()
2725 mutex_unlock(&id_priv->qp_mutex); in cma_listen_on_dev()
2727 ret = rdma_listen(&dev_id_priv->id, id_priv->backlog); in cma_listen_on_dev()
2730 list_add_tail(&dev_id_priv->listen_item, &id_priv->listen_list); in cma_listen_on_dev()
2735 dev_warn(&cma_dev->device->dev, "RDMA CMA: %s, error %d\n", __func__, ret); in cma_listen_on_dev()
2746 list_add_tail(&id_priv->listen_any_item, &listen_any_list); in cma_listen_on_all()
2752 list_del_init(&to_destroy->device_item); in cma_listen_on_all()
2763 rdma_destroy_id(&to_destroy->id); in cma_listen_on_all()
2772 mutex_lock(&id_priv->qp_mutex); in rdma_set_service_type()
2773 id_priv->tos = (u8) tos; in rdma_set_service_type()
2774 id_priv->tos_set = true; in rdma_set_service_type()
2775 mutex_unlock(&id_priv->qp_mutex); in rdma_set_service_type()
2780 * rdma_set_ack_timeout() - Set the ack timeout of QP associated
2798 if (id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_INI) in rdma_set_ack_timeout()
2799 return -EINVAL; in rdma_set_ack_timeout()
2802 mutex_lock(&id_priv->qp_mutex); in rdma_set_ack_timeout()
2803 id_priv->timeout = timeout; in rdma_set_ack_timeout()
2804 id_priv->timeout_set = true; in rdma_set_ack_timeout()
2805 mutex_unlock(&id_priv->qp_mutex); in rdma_set_ack_timeout()
2812 * rdma_set_min_rnr_timer() - Set the minimum RNR Retry timer of the
2815 * @min_rnr_timer: 5-bit value encoded as Table 45: "Encoding for RNR NAK
2833 /* It is a five-bit value */ in rdma_set_min_rnr_timer()
2835 return -EINVAL; in rdma_set_min_rnr_timer()
2837 if (WARN_ON(id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_TGT)) in rdma_set_min_rnr_timer()
2838 return -EINVAL; in rdma_set_min_rnr_timer()
2841 mutex_lock(&id_priv->qp_mutex); in rdma_set_min_rnr_timer()
2842 id_priv->min_rnr_timer = min_rnr_timer; in rdma_set_min_rnr_timer()
2843 id_priv->min_rnr_timer_set = true; in rdma_set_min_rnr_timer()
2844 mutex_unlock(&id_priv->qp_mutex); in rdma_set_min_rnr_timer()
2853 struct rdma_route *route = &work->id->id.route; in route_set_path_rec_inbound()
2855 if (!route->path_rec_inbound) { in route_set_path_rec_inbound()
2856 route->path_rec_inbound = in route_set_path_rec_inbound()
2857 kzalloc(sizeof(*route->path_rec_inbound), GFP_KERNEL); in route_set_path_rec_inbound()
2858 if (!route->path_rec_inbound) in route_set_path_rec_inbound()
2859 return -ENOMEM; in route_set_path_rec_inbound()
2862 *route->path_rec_inbound = *path_rec; in route_set_path_rec_inbound()
2869 struct rdma_route *route = &work->id->id.route; in route_set_path_rec_outbound()
2871 if (!route->path_rec_outbound) { in route_set_path_rec_outbound()
2872 route->path_rec_outbound = in route_set_path_rec_outbound()
2873 kzalloc(sizeof(*route->path_rec_outbound), GFP_KERNEL); in route_set_path_rec_outbound()
2874 if (!route->path_rec_outbound) in route_set_path_rec_outbound()
2875 return -ENOMEM; in route_set_path_rec_outbound()
2878 *route->path_rec_outbound = *path_rec; in route_set_path_rec_outbound()
2889 route = &work->id->id.route; in cma_query_handler()
2896 *route->path_rec = path_rec[i]; in cma_query_handler()
2903 status = -EINVAL; in cma_query_handler()
2909 route->num_pri_alt_paths = 1; in cma_query_handler()
2910 queue_work(cma_wq, &work->work); in cma_query_handler()
2914 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_query_handler()
2915 work->new_state = RDMA_CM_ADDR_RESOLVED; in cma_query_handler()
2916 work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; in cma_query_handler()
2917 work->event.status = status; in cma_query_handler()
2920 queue_work(cma_wq, &work->work); in cma_query_handler()
2926 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_query_ib_route()
2934 if (rdma_cap_opa_ah(id_priv->id.device, id_priv->id.port_num)) in cma_query_ib_route()
2943 path_rec.service_id = rdma_get_service_id(&id_priv->id, in cma_query_ib_route()
2952 path_rec.qos_class = cpu_to_be16((u16) id_priv->tos); in cma_query_ib_route()
2957 path_rec.traffic_class = (u8) (be32_to_cpu(sin6->sin6_flowinfo) >> 20); in cma_query_ib_route()
2962 path_rec.traffic_class = (u8) (be32_to_cpu(sib->sib_flowinfo) >> 20); in cma_query_ib_route()
2967 id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, in cma_query_ib_route()
2968 id_priv->id.port_num, &path_rec, in cma_query_ib_route()
2971 work, &id_priv->query); in cma_query_ib_route()
2973 return (id_priv->query_id < 0) ? id_priv->query_id : 0; in cma_query_ib_route()
2978 struct cma_multicast *mc = in cma_iboe_join_work_handler() local
2980 struct rdma_cm_event *event = &mc->iboe_join.event; in cma_iboe_join_work_handler()
2981 struct rdma_id_private *id_priv = mc->id_priv; in cma_iboe_join_work_handler()
2984 mutex_lock(&id_priv->handler_mutex); in cma_iboe_join_work_handler()
2985 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_iboe_join_work_handler()
2986 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_iboe_join_work_handler()
2993 mutex_unlock(&id_priv->handler_mutex); in cma_iboe_join_work_handler()
2994 if (event->event == RDMA_CM_EVENT_MULTICAST_JOIN) in cma_iboe_join_work_handler()
2995 rdma_destroy_ah_attr(&event->param.ud.ah_attr); in cma_iboe_join_work_handler()
3001 struct rdma_id_private *id_priv = work->id; in cma_work_handler()
3003 mutex_lock(&id_priv->handler_mutex); in cma_work_handler()
3004 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_work_handler()
3005 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_work_handler()
3007 if (work->old_state != 0 || work->new_state != 0) { in cma_work_handler()
3008 if (!cma_comp_exch(id_priv, work->old_state, work->new_state)) in cma_work_handler()
3012 if (cma_cm_event_handler(id_priv, &work->event)) { in cma_work_handler()
3019 mutex_unlock(&id_priv->handler_mutex); in cma_work_handler()
3022 if (work->event.event == RDMA_CM_EVENT_MULTICAST_JOIN) in cma_work_handler()
3023 rdma_destroy_ah_attr(&work->event.param.ud.ah_attr); in cma_work_handler()
3030 work->id = id_priv; in cma_init_resolve_route_work()
3031 INIT_WORK(&work->work, cma_work_handler); in cma_init_resolve_route_work()
3032 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_init_resolve_route_work()
3033 work->new_state = RDMA_CM_ROUTE_RESOLVED; in cma_init_resolve_route_work()
3034 work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; in cma_init_resolve_route_work()
3043 work->id = id_priv; in enqueue_resolve_addr_work()
3044 INIT_WORK(&work->work, cma_work_handler); in enqueue_resolve_addr_work()
3045 work->old_state = RDMA_CM_ADDR_QUERY; in enqueue_resolve_addr_work()
3046 work->new_state = RDMA_CM_ADDR_RESOLVED; in enqueue_resolve_addr_work()
3047 work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; in enqueue_resolve_addr_work()
3049 queue_work(cma_wq, &work->work); in enqueue_resolve_addr_work()
3055 struct rdma_route *route = &id_priv->id.route; in cma_resolve_ib_route()
3061 return -ENOMEM; in cma_resolve_ib_route()
3065 if (!route->path_rec) in cma_resolve_ib_route()
3066 route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_ib_route()
3067 if (!route->path_rec) { in cma_resolve_ib_route()
3068 ret = -ENOMEM; in cma_resolve_ib_route()
3078 kfree(route->path_rec); in cma_resolve_ib_route()
3079 route->path_rec = NULL; in cma_resolve_ib_route()
3107 struct rdma_route *route = &id_priv->id.route; in cma_iboe_set_path_rec_l2_fields()
3109 struct rdma_addr *addr = &route->addr; in cma_iboe_set_path_rec_l2_fields()
3113 if (!addr->dev_addr.bound_dev_if) in cma_iboe_set_path_rec_l2_fields()
3116 ndev = dev_get_by_index(addr->dev_addr.net, in cma_iboe_set_path_rec_l2_fields()
3117 addr->dev_addr.bound_dev_if); in cma_iboe_set_path_rec_l2_fields()
3121 supported_gids = roce_gid_type_mask_support(id_priv->id.device, in cma_iboe_set_path_rec_l2_fields()
3122 id_priv->id.port_num); in cma_iboe_set_path_rec_l2_fields()
3123 gid_type = cma_route_gid_type(addr->dev_addr.network, in cma_iboe_set_path_rec_l2_fields()
3125 id_priv->gid_type); in cma_iboe_set_path_rec_l2_fields()
3127 if (gid_type < ib_network_to_gid_type(addr->dev_addr.network)) in cma_iboe_set_path_rec_l2_fields()
3128 gid_type = ib_network_to_gid_type(addr->dev_addr.network); in cma_iboe_set_path_rec_l2_fields()
3129 route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type); in cma_iboe_set_path_rec_l2_fields()
3131 route->path_rec->roce.route_resolved = true; in cma_iboe_set_path_rec_l2_fields()
3132 sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr); in cma_iboe_set_path_rec_l2_fields()
3146 return -EINVAL; in rdma_set_ib_path()
3148 id->route.path_rec = kmemdup(path_rec, sizeof(*path_rec), in rdma_set_ib_path()
3150 if (!id->route.path_rec) { in rdma_set_ib_path()
3151 ret = -ENOMEM; in rdma_set_ib_path()
3155 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_set_ib_path()
3158 ret = -ENODEV; in rdma_set_ib_path()
3164 id->route.num_pri_alt_paths = 1; in rdma_set_ib_path()
3168 kfree(id->route.path_rec); in rdma_set_ib_path()
3169 id->route.path_rec = NULL; in rdma_set_ib_path()
3182 return -ENOMEM; in cma_resolve_iw_route()
3185 queue_work(cma_wq, &work->work); in cma_resolve_iw_route()
3194 if (dev->num_tc) in get_vlan_ndev_tc()
3210 struct iboe_prio_tc_map *map = (struct iboe_prio_tc_map *)priv->data; in get_lower_vlan_dev_tc()
3213 map->output_tc = get_vlan_ndev_tc(dev, map->input_prio); in get_lower_vlan_dev_tc()
3214 else if (dev->num_tc) in get_lower_vlan_dev_tc()
3215 map->output_tc = netdev_get_prio_tc_map(dev, map->input_prio); in get_lower_vlan_dev_tc()
3217 map->output_tc = 0; in get_lower_vlan_dev_tc()
3221 map->found = true; in get_lower_vlan_dev_tc()
3247 else if (ndev->num_tc) in iboe_tos_to_sl()
3260 fl = be32_to_cpu(addr6->sin6_flowinfo) & IB_GRH_FLOWLABEL_MASK; in cma_get_roce_udp_flow_label()
3273 struct rdma_route *route = &id_priv->id.route; in cma_resolve_iboe_route()
3274 struct rdma_addr *addr = &route->addr; in cma_resolve_iboe_route()
3279 u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - in cma_resolve_iboe_route()
3280 rdma_start_port(id_priv->cma_dev->device)]; in cma_resolve_iboe_route()
3283 mutex_lock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3284 tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; in cma_resolve_iboe_route()
3285 mutex_unlock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3289 return -ENOMEM; in cma_resolve_iboe_route()
3291 route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_iboe_route()
3292 if (!route->path_rec) { in cma_resolve_iboe_route()
3293 ret = -ENOMEM; in cma_resolve_iboe_route()
3297 route->num_pri_alt_paths = 1; in cma_resolve_iboe_route()
3301 ret = -ENODEV; in cma_resolve_iboe_route()
3305 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_resolve_iboe_route()
3306 &route->path_rec->sgid); in cma_resolve_iboe_route()
3307 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, in cma_resolve_iboe_route()
3308 &route->path_rec->dgid); in cma_resolve_iboe_route()
3310 if (((struct sockaddr *)&id_priv->id.route.addr.dst_addr)->sa_family != AF_IB) in cma_resolve_iboe_route()
3312 route->path_rec->hop_limit = addr->dev_addr.hoplimit; in cma_resolve_iboe_route()
3314 route->path_rec->hop_limit = 1; in cma_resolve_iboe_route()
3315 route->path_rec->reversible = 1; in cma_resolve_iboe_route()
3316 route->path_rec->pkey = cpu_to_be16(0xffff); in cma_resolve_iboe_route()
3317 route->path_rec->mtu_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3318 route->path_rec->sl = iboe_tos_to_sl(ndev, tos); in cma_resolve_iboe_route()
3319 route->path_rec->traffic_class = tos; in cma_resolve_iboe_route()
3320 route->path_rec->mtu = iboe_get_mtu(ndev->mtu); in cma_resolve_iboe_route()
3321 route->path_rec->rate_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3322 route->path_rec->rate = IB_RATE_PORT_CURRENT; in cma_resolve_iboe_route()
3324 route->path_rec->packet_life_time_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3332 mutex_lock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3333 if (id_priv->timeout_set && id_priv->timeout) in cma_resolve_iboe_route()
3334 route->path_rec->packet_life_time = id_priv->timeout - 1; in cma_resolve_iboe_route()
3336 route->path_rec->packet_life_time = CMA_IBOE_PACKET_LIFETIME; in cma_resolve_iboe_route()
3337 mutex_unlock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3339 if (!route->path_rec->mtu) { in cma_resolve_iboe_route()
3340 ret = -EINVAL; in cma_resolve_iboe_route()
3344 if (rdma_protocol_roce_udp_encap(id_priv->id.device, in cma_resolve_iboe_route()
3345 id_priv->id.port_num)) in cma_resolve_iboe_route()
3346 route->path_rec->flow_label = in cma_resolve_iboe_route()
3350 queue_work(cma_wq, &work->work); in cma_resolve_iboe_route()
3355 kfree(route->path_rec); in cma_resolve_iboe_route()
3356 route->path_rec = NULL; in cma_resolve_iboe_route()
3357 route->num_pri_alt_paths = 0; in cma_resolve_iboe_route()
3369 return -EINVAL; in rdma_resolve_route()
3373 return -EINVAL; in rdma_resolve_route()
3376 if (rdma_cap_ib_sa(id->device, id->port_num)) in rdma_resolve_route()
3378 else if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_resolve_route()
3383 else if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_resolve_route()
3386 ret = -ENOSYS; in rdma_resolve_route()
3401 switch (addr->sa_family) { in cma_set_loopback()
3403 ((struct sockaddr_in *) addr)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); in cma_set_loopback()
3406 ipv6_addr_set(&((struct sockaddr_in6 *) addr)->sin6_addr, in cma_set_loopback()
3410 ib_addr_set(&((struct sockaddr_ib *) addr)->sib_addr, in cma_set_loopback()
3429 !rdma_cap_ib_cm(cur_dev->device, 1)) in cma_bind_loopback()
3435 rdma_for_each_port (cur_dev->device, p) { in cma_bind_loopback()
3436 if (!ib_get_cached_port_state(cur_dev->device, p, &port_state) && in cma_bind_loopback()
3445 ret = -ENODEV; in cma_bind_loopback()
3452 ret = rdma_query_gid(cma_dev->device, p, 0, &gid); in cma_bind_loopback()
3456 ret = ib_get_cached_pkey(cma_dev->device, p, 0, &pkey); in cma_bind_loopback()
3460 id_priv->id.route.addr.dev_addr.dev_type = in cma_bind_loopback()
3461 (rdma_protocol_ib(cma_dev->device, p)) ? in cma_bind_loopback()
3464 rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_bind_loopback()
3465 ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); in cma_bind_loopback()
3466 id_priv->id.port_num = p; in cma_bind_loopback()
3468 rdma_restrack_add(&id_priv->res); in cma_bind_loopback()
3483 mutex_lock(&id_priv->handler_mutex); in addr_handler()
3496 if (!status && !id_priv->cma_dev) { in addr_handler()
3501 rdma_restrack_add(&id_priv->res); in addr_handler()
3522 mutex_unlock(&id_priv->handler_mutex); in addr_handler()
3533 return -ENOMEM; in cma_resolve_loopback()
3535 if (!id_priv->cma_dev) { in cma_resolve_loopback()
3541 rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3542 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3558 return -ENOMEM; in cma_resolve_ib_addr()
3560 if (!id_priv->cma_dev) { in cma_resolve_ib_addr()
3566 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) in cma_resolve_ib_addr()
3567 &(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); in cma_resolve_ib_addr()
3583 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_reuseaddr()
3584 if ((reuse && id_priv->state != RDMA_CM_LISTEN) || in rdma_set_reuseaddr()
3585 id_priv->state == RDMA_CM_IDLE) { in rdma_set_reuseaddr()
3586 id_priv->reuseaddr = reuse; in rdma_set_reuseaddr()
3589 ret = -EINVAL; in rdma_set_reuseaddr()
3591 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_reuseaddr()
3603 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_afonly()
3604 if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) { in rdma_set_afonly()
3605 id_priv->options |= (1 << CMA_OPTION_AFONLY); in rdma_set_afonly()
3606 id_priv->afonly = afonly; in rdma_set_afonly()
3609 ret = -EINVAL; in rdma_set_afonly()
3611 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_afonly()
3621 u64 sid, mask; in cma_bind_port() local
3627 port = htons(bind_list->port); in cma_bind_port()
3629 switch (addr->sa_family) { in cma_bind_port()
3631 ((struct sockaddr_in *) addr)->sin_port = port; in cma_bind_port()
3634 ((struct sockaddr_in6 *) addr)->sin6_port = port; in cma_bind_port()
3638 sid = be64_to_cpu(sib->sib_sid); in cma_bind_port()
3639 mask = be64_to_cpu(sib->sib_sid_mask); in cma_bind_port()
3640 sib->sib_sid = cpu_to_be64((sid & mask) | (u64) ntohs(port)); in cma_bind_port()
3641 sib->sib_sid_mask = cpu_to_be64(~0ULL); in cma_bind_port()
3644 id_priv->bind_list = bind_list; in cma_bind_port()
3645 hlist_add_head(&id_priv->node, &bind_list->owners); in cma_bind_port()
3658 return -ENOMEM; in cma_alloc_port()
3660 ret = cma_ps_alloc(id_priv->id.route.addr.dev_addr.net, ps, bind_list, in cma_alloc_port()
3665 bind_list->ps = ps; in cma_alloc_port()
3666 bind_list->port = snum; in cma_alloc_port()
3671 return ret == -ENOSPC ? -EADDRNOTAVAIL : ret; in cma_alloc_port()
3684 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_port_is_unique()
3692 /* different dest port -> unique */ in cma_port_is_unique()
3698 /* different src address -> unique */ in cma_port_is_unique()
3704 /* different dst address -> unique */ in cma_port_is_unique()
3710 return -EADDRNOTAVAIL; in cma_port_is_unique()
3721 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_alloc_any_port()
3726 remaining = (high - low) + 1; in cma_alloc_any_port()
3727 rover = get_random_u32_inclusive(low, remaining + low - 1); in cma_alloc_any_port()
3744 * re-using same port immediately after it is closed. in cma_alloc_any_port()
3748 if (ret != -EADDRNOTAVAIL) in cma_alloc_any_port()
3751 if (--remaining) { in cma_alloc_any_port()
3757 return -EADDRNOTAVAIL; in cma_alloc_any_port()
3775 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_check_port()
3779 if (reuseaddr && cur_id->reuseaddr) in cma_check_port()
3783 if (id_priv->afonly && cur_id->afonly && in cma_check_port()
3784 (addr->sa_family != cur_addr->sa_family)) in cma_check_port()
3788 return -EADDRNOTAVAIL; in cma_check_port()
3791 return -EADDRINUSE; in cma_check_port()
3807 return -EACCES; in cma_use_port()
3809 bind_list = cma_ps_find(id_priv->id.route.addr.dev_addr.net, ps, snum); in cma_use_port()
3813 ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); in cma_use_port()
3823 switch (id_priv->id.ps) { in cma_select_inet_ps()
3828 return id_priv->id.ps; in cma_select_inet_ps()
3840 u64 sid_ps, mask, sid; in cma_select_ib_ps() local
3843 mask = be64_to_cpu(sib->sib_sid_mask) & RDMA_IB_IP_PS_MASK; in cma_select_ib_ps()
3844 sid = be64_to_cpu(sib->sib_sid) & mask; in cma_select_ib_ps()
3846 if ((id_priv->id.ps == RDMA_PS_IB) && (sid == (RDMA_IB_IP_PS_IB & mask))) { in cma_select_ib_ps()
3849 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_TCP)) && in cma_select_ib_ps()
3850 (sid == (RDMA_IB_IP_PS_TCP & mask))) { in cma_select_ib_ps()
3853 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_UDP)) && in cma_select_ib_ps()
3854 (sid == (RDMA_IB_IP_PS_UDP & mask))) { in cma_select_ib_ps()
3860 sib->sib_sid = cpu_to_be64(sid_ps | ntohs(cma_port((struct sockaddr *) sib))); in cma_select_ib_ps()
3861 sib->sib_sid_mask = cpu_to_be64(RDMA_IB_IP_PS_MASK | in cma_select_ib_ps()
3862 be64_to_cpu(sib->sib_sid_mask)); in cma_select_ib_ps()
3877 return -EPROTONOSUPPORT; in cma_get_port()
3895 if (addr->sa_family != AF_INET6) in cma_check_linklocal()
3900 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) in cma_check_linklocal()
3903 if (!sin6->sin6_scope_id) in cma_check_linklocal()
3904 return -EINVAL; in cma_check_linklocal()
3906 dev_addr->bound_dev_if = sin6->sin6_scope_id; in cma_check_linklocal()
3929 return -EINVAL; in rdma_listen()
3936 if (id_priv->reuseaddr) { in rdma_listen()
3938 ret = cma_check_port(id_priv->bind_list, id_priv, 0); in rdma_listen()
3940 id_priv->reuseaddr = 0; in rdma_listen()
3946 id_priv->backlog = backlog; in rdma_listen()
3947 if (id_priv->cma_dev) { in rdma_listen()
3948 if (rdma_cap_ib_cm(id->device, 1)) { in rdma_listen()
3952 } else if (rdma_cap_iw_cm(id->device, 1)) { in rdma_listen()
3957 ret = -ENOSYS; in rdma_listen()
3968 id_priv->backlog = 0; in rdma_listen()
3984 if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6 && in rdma_bind_addr_dst()
3985 addr->sa_family != AF_IB) in rdma_bind_addr_dst()
3986 return -EAFNOSUPPORT; in rdma_bind_addr_dst()
3989 return -EINVAL; in rdma_bind_addr_dst()
3991 ret = cma_check_linklocal(&id_priv->id.route.addr.dev_addr, addr); in rdma_bind_addr_dst()
3997 ret = cma_translate_addr(addr, &id_priv->id.route.addr.dev_addr); in rdma_bind_addr_dst()
4006 if (!(id_priv->options & (1 << CMA_OPTION_AFONLY))) { in rdma_bind_addr_dst()
4007 if (addr->sa_family == AF_INET) in rdma_bind_addr_dst()
4008 id_priv->afonly = 1; in rdma_bind_addr_dst()
4010 else if (addr->sa_family == AF_INET6) { in rdma_bind_addr_dst()
4011 struct net *net = id_priv->id.route.addr.dev_addr.net; in rdma_bind_addr_dst()
4013 id_priv->afonly = net->ipv6.sysctl.bindv6only; in rdma_bind_addr_dst()
4020 id_daddr->sa_family = addr->sa_family; in rdma_bind_addr_dst()
4027 rdma_restrack_add(&id_priv->res); in rdma_bind_addr_dst()
4030 if (id_priv->cma_dev) in rdma_bind_addr_dst()
4044 if (src_addr && src_addr->sa_family) in cma_bind_addr()
4050 zero_sock.ss_family = dst_addr->sa_family; in cma_bind_addr()
4051 if (IS_ENABLED(CONFIG_IPV6) && dst_addr->sa_family == AF_INET6) { in cma_bind_addr()
4057 src_addr6->sin6_scope_id = dst_addr6->sin6_scope_id; in cma_bind_addr()
4058 if (ipv6_addr_type(&dst_addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL) in cma_bind_addr()
4059 id->route.addr.dev_addr.bound_dev_if = in cma_bind_addr()
4060 dst_addr6->sin6_scope_id; in cma_bind_addr()
4061 } else if (dst_addr->sa_family == AF_IB) { in cma_bind_addr()
4062 ((struct sockaddr_ib *)&zero_sock)->sib_pkey = in cma_bind_addr()
4063 ((struct sockaddr_ib *)dst_addr)->sib_pkey; in cma_bind_addr()
4071 * calls made by ULP, a previously bound ID will not be re-bound and src_addr is
4082 ret = cma_bind_addr(&id_priv->id, src_addr, dst_addr); in resolve_prepare_src()
4087 return -EINVAL; in resolve_prepare_src()
4093 if (cma_family(id_priv) != dst_addr->sa_family) { in resolve_prepare_src()
4094 ret = -EINVAL; in resolve_prepare_src()
4118 if (dst_addr->sa_family == AF_IB) { in rdma_resolve_addr()
4132 if (id_priv->used_resolve_ip) in rdma_resolve_addr()
4133 rdma_addr_cancel(&id->route.addr.dev_addr); in rdma_resolve_addr()
4135 id_priv->used_resolve_ip = 1; in rdma_resolve_addr()
4137 &id->route.addr.dev_addr, in rdma_resolve_addr()
4166 cma_hdr->cma_version = CMA_VERSION; in cma_format_hdr()
4174 cma_hdr->src_addr.ip4.addr = src4->sin_addr.s_addr; in cma_format_hdr()
4175 cma_hdr->dst_addr.ip4.addr = dst4->sin_addr.s_addr; in cma_format_hdr()
4176 cma_hdr->port = src4->sin_port; in cma_format_hdr()
4184 cma_hdr->src_addr.ip6 = src6->sin6_addr; in cma_format_hdr()
4185 cma_hdr->dst_addr.ip6 = dst6->sin6_addr; in cma_format_hdr()
4186 cma_hdr->port = src6->sin6_port; in cma_format_hdr()
4194 struct rdma_id_private *id_priv = cm_id->context; in cma_sidr_rep_handler()
4197 &ib_event->param.sidr_rep_rcvd; in cma_sidr_rep_handler()
4200 mutex_lock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
4201 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_sidr_rep_handler()
4204 switch (ib_event->event) { in cma_sidr_rep_handler()
4207 event.status = -ETIMEDOUT; in cma_sidr_rep_handler()
4210 event.param.ud.private_data = ib_event->private_data; in cma_sidr_rep_handler()
4212 if (rep->status != IB_SIDR_SUCCESS) { in cma_sidr_rep_handler()
4214 event.status = ib_event->param.sidr_rep_rcvd.status; in cma_sidr_rep_handler()
4219 ret = cma_set_qkey(id_priv, rep->qkey); in cma_sidr_rep_handler()
4226 ib_init_ah_attr_from_path(id_priv->id.device, in cma_sidr_rep_handler()
4227 id_priv->id.port_num, in cma_sidr_rep_handler()
4228 id_priv->id.route.path_rec, in cma_sidr_rep_handler()
4230 rep->sgid_attr); in cma_sidr_rep_handler()
4231 event.param.ud.qp_num = rep->qpn; in cma_sidr_rep_handler()
4232 event.param.ud.qkey = rep->qkey; in cma_sidr_rep_handler()
4238 ib_event->event); in cma_sidr_rep_handler()
4246 /* Destroy the CM ID by returning a non-zero value. */ in cma_sidr_rep_handler()
4247 id_priv->cm_id.ib = NULL; in cma_sidr_rep_handler()
4252 mutex_unlock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
4267 if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) in cma_resolve_ib_udp()
4268 return -EINVAL; in cma_resolve_ib_udp()
4273 return -ENOMEM; in cma_resolve_ib_udp()
4278 if (conn_param->private_data && conn_param->private_data_len) in cma_resolve_ib_udp()
4279 memcpy(private_data + offset, conn_param->private_data, in cma_resolve_ib_udp()
4280 conn_param->private_data_len); in cma_resolve_ib_udp()
4289 id = ib_create_cm_id(id_priv->id.device, cma_sidr_rep_handler, in cma_resolve_ib_udp()
4295 id_priv->cm_id.ib = id; in cma_resolve_ib_udp()
4297 req.path = id_priv->id.route.path_rec; in cma_resolve_ib_udp()
4298 req.sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_resolve_ib_udp()
4299 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_resolve_ib_udp()
4300 req.timeout_ms = 1 << (CMA_CM_RESPONSE_TIMEOUT - 8); in cma_resolve_ib_udp()
4304 ret = ib_send_cm_sidr_req(id_priv->cm_id.ib, &req); in cma_resolve_ib_udp()
4306 ib_destroy_cm_id(id_priv->cm_id.ib); in cma_resolve_ib_udp()
4307 id_priv->cm_id.ib = NULL; in cma_resolve_ib_udp()
4326 if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) in cma_connect_ib()
4327 return -EINVAL; in cma_connect_ib()
4332 return -ENOMEM; in cma_connect_ib()
4337 if (conn_param->private_data && conn_param->private_data_len) in cma_connect_ib()
4338 memcpy(private_data + offset, conn_param->private_data, in cma_connect_ib()
4339 conn_param->private_data_len); in cma_connect_ib()
4341 id = ib_create_cm_id(id_priv->id.device, cma_ib_handler, id_priv); in cma_connect_ib()
4346 id_priv->cm_id.ib = id; in cma_connect_ib()
4348 route = &id_priv->id.route; in cma_connect_ib()
4356 req.primary_path = &route->path_rec[0]; in cma_connect_ib()
4357 req.primary_path_inbound = route->path_rec_inbound; in cma_connect_ib()
4358 req.primary_path_outbound = route->path_rec_outbound; in cma_connect_ib()
4359 if (route->num_pri_alt_paths == 2) in cma_connect_ib()
4360 req.alternate_path = &route->path_rec[1]; in cma_connect_ib()
4362 req.ppath_sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_connect_ib()
4364 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_connect_ib()
4365 req.qp_num = id_priv->qp_num; in cma_connect_ib()
4366 req.qp_type = id_priv->id.qp_type; in cma_connect_ib()
4367 req.starting_psn = id_priv->seq_num; in cma_connect_ib()
4368 req.responder_resources = conn_param->responder_resources; in cma_connect_ib()
4369 req.initiator_depth = conn_param->initiator_depth; in cma_connect_ib()
4370 req.flow_control = conn_param->flow_control; in cma_connect_ib()
4371 req.retry_count = min_t(u8, 7, conn_param->retry_count); in cma_connect_ib()
4372 req.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_connect_ib()
4376 req.srq = id_priv->srq ? 1 : 0; in cma_connect_ib()
4377 req.ece.vendor_id = id_priv->ece.vendor_id; in cma_connect_ib()
4378 req.ece.attr_mod = id_priv->ece.attr_mod; in cma_connect_ib()
4381 ret = ib_send_cm_req(id_priv->cm_id.ib, &req); in cma_connect_ib()
4385 id_priv->cm_id.ib = NULL; in cma_connect_ib()
4399 cm_id = iw_create_cm_id(id_priv->id.device, cma_iw_handler, id_priv); in cma_connect_iw()
4403 mutex_lock(&id_priv->qp_mutex); in cma_connect_iw()
4404 cm_id->tos = id_priv->tos; in cma_connect_iw()
4405 cm_id->tos_set = id_priv->tos_set; in cma_connect_iw()
4406 mutex_unlock(&id_priv->qp_mutex); in cma_connect_iw()
4408 id_priv->cm_id.iw = cm_id; in cma_connect_iw()
4410 memcpy(&cm_id->local_addr, cma_src_addr(id_priv), in cma_connect_iw()
4412 memcpy(&cm_id->remote_addr, cma_dst_addr(id_priv), in cma_connect_iw()
4420 iw_param.ord = conn_param->initiator_depth; in cma_connect_iw()
4421 iw_param.ird = conn_param->responder_resources; in cma_connect_iw()
4422 iw_param.private_data = conn_param->private_data; in cma_connect_iw()
4423 iw_param.private_data_len = conn_param->private_data_len; in cma_connect_iw()
4424 iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num; in cma_connect_iw()
4427 iw_param.qpn = id_priv->qp_num; in cma_connect_iw()
4433 id_priv->cm_id.iw = NULL; in cma_connect_iw()
4439 * rdma_connect_locked - Initiate an active connection request.
4454 return -EINVAL; in rdma_connect_locked()
4456 if (!id->qp) { in rdma_connect_locked()
4457 id_priv->qp_num = conn_param->qp_num; in rdma_connect_locked()
4458 id_priv->srq = conn_param->srq; in rdma_connect_locked()
4461 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_connect_locked()
4462 if (id->qp_type == IB_QPT_UD) in rdma_connect_locked()
4466 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_connect_locked()
4469 ret = -ENOSYS; in rdma_connect_locked()
4481 * rdma_connect - Initiate an active connection request.
4498 mutex_lock(&id_priv->handler_mutex); in rdma_connect()
4500 mutex_unlock(&id_priv->handler_mutex); in rdma_connect()
4506 * rdma_connect_ece - Initiate an active connection request with ECE data.
4519 id_priv->ece.vendor_id = ece->vendor_id; in rdma_connect_ece()
4520 id_priv->ece.attr_mod = ece->attr_mod; in rdma_connect_ece()
4541 rep.qp_num = id_priv->qp_num; in cma_accept_ib()
4542 rep.starting_psn = id_priv->seq_num; in cma_accept_ib()
4543 rep.private_data = conn_param->private_data; in cma_accept_ib()
4544 rep.private_data_len = conn_param->private_data_len; in cma_accept_ib()
4545 rep.responder_resources = conn_param->responder_resources; in cma_accept_ib()
4546 rep.initiator_depth = conn_param->initiator_depth; in cma_accept_ib()
4548 rep.flow_control = conn_param->flow_control; in cma_accept_ib()
4549 rep.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_accept_ib()
4550 rep.srq = id_priv->srq ? 1 : 0; in cma_accept_ib()
4551 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_accept_ib()
4552 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_accept_ib()
4555 ret = ib_send_cm_rep(id_priv->cm_id.ib, &rep); in cma_accept_ib()
4567 return -EINVAL; in cma_accept_iw()
4573 iw_param.ord = conn_param->initiator_depth; in cma_accept_iw()
4574 iw_param.ird = conn_param->responder_resources; in cma_accept_iw()
4575 iw_param.private_data = conn_param->private_data; in cma_accept_iw()
4576 iw_param.private_data_len = conn_param->private_data_len; in cma_accept_iw()
4577 if (id_priv->id.qp) in cma_accept_iw()
4578 iw_param.qpn = id_priv->qp_num; in cma_accept_iw()
4580 iw_param.qpn = conn_param->qp_num; in cma_accept_iw()
4582 return iw_cm_accept(id_priv->cm_id.iw, &iw_param); in cma_accept_iw()
4601 rep.qp_num = id_priv->qp_num; in cma_send_sidr_rep()
4602 rep.qkey = id_priv->qkey; in cma_send_sidr_rep()
4604 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_send_sidr_rep()
4605 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_send_sidr_rep()
4612 return ib_send_cm_sidr_rep(id_priv->cm_id.ib, &rep); in cma_send_sidr_rep()
4616 * rdma_accept - Called to accept a connection request or response.
4639 lockdep_assert_held(&id_priv->handler_mutex); in rdma_accept()
4641 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in rdma_accept()
4642 return -EINVAL; in rdma_accept()
4644 if (!id->qp && conn_param) { in rdma_accept()
4645 id_priv->qp_num = conn_param->qp_num; in rdma_accept()
4646 id_priv->srq = conn_param->srq; in rdma_accept()
4649 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_accept()
4650 if (id->qp_type == IB_QPT_UD) { in rdma_accept()
4653 conn_param->qkey, in rdma_accept()
4654 conn_param->private_data, in rdma_accept()
4655 conn_param->private_data_len); in rdma_accept()
4665 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_accept()
4668 ret = -ENOSYS; in rdma_accept()
4687 id_priv->ece.vendor_id = ece->vendor_id; in rdma_accept_ece()
4688 id_priv->ece.attr_mod = ece->attr_mod; in rdma_accept_ece()
4699 mutex_lock(&id_priv->handler_mutex); in rdma_lock_handler()
4708 mutex_unlock(&id_priv->handler_mutex); in rdma_unlock_handler()
4718 if (!id_priv->cm_id.ib) in rdma_notify()
4719 return -EINVAL; in rdma_notify()
4721 switch (id->device->node_type) { in rdma_notify()
4723 ret = ib_cm_notify(id_priv->cm_id.ib, event); in rdma_notify()
4740 if (!id_priv->cm_id.ib) in rdma_reject()
4741 return -EINVAL; in rdma_reject()
4743 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_reject()
4744 if (id->qp_type == IB_QPT_UD) { in rdma_reject()
4749 ret = ib_send_cm_rej(id_priv->cm_id.ib, reason, NULL, 0, in rdma_reject()
4752 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_reject()
4753 ret = iw_cm_reject(id_priv->cm_id.iw, in rdma_reject()
4756 ret = -ENOSYS; in rdma_reject()
4769 if (!id_priv->cm_id.ib) in rdma_disconnect()
4770 return -EINVAL; in rdma_disconnect()
4772 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_disconnect()
4778 if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) { in rdma_disconnect()
4779 if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0)) in rdma_disconnect()
4784 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_disconnect()
4785 ret = iw_cm_disconnect(id_priv->cm_id.iw, 0); in rdma_disconnect()
4787 ret = -EINVAL; in rdma_disconnect()
4797 struct cma_multicast *mc) in cma_make_mc_event() argument
4807 event->status = status; in cma_make_mc_event()
4808 event->param.ud.private_data = mc->context; in cma_make_mc_event()
4810 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4814 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_make_mc_event()
4815 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_make_mc_event()
4817 id_priv->cma_dev in cma_make_mc_event()
4818 ->default_gid_type[id_priv->id.port_num - in cma_make_mc_event()
4820 id_priv->cma_dev->device)]; in cma_make_mc_event()
4822 event->event = RDMA_CM_EVENT_MULTICAST_JOIN; in cma_make_mc_event()
4823 if (ib_init_ah_from_mcmember(id_priv->id.device, id_priv->id.port_num, in cma_make_mc_event()
4824 &multicast->rec, ndev, gid_type, in cma_make_mc_event()
4825 &event->param.ud.ah_attr)) { in cma_make_mc_event()
4826 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4830 event->param.ud.qp_num = 0xFFFFFF; in cma_make_mc_event()
4831 event->param.ud.qkey = id_priv->qkey; in cma_make_mc_event()
4839 struct cma_multicast *mc = multicast->context; in cma_ib_mc_handler() local
4840 struct rdma_id_private *id_priv = mc->id_priv; in cma_ib_mc_handler()
4844 mutex_lock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4845 if (READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL || in cma_ib_mc_handler()
4846 READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING) in cma_ib_mc_handler()
4849 ret = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey)); in cma_ib_mc_handler()
4851 cma_make_mc_event(status, id_priv, multicast, &event, mc); in cma_ib_mc_handler()
4858 mutex_unlock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4866 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_set_mgid()
4872 } else if ((addr->sa_family == AF_INET6) && in cma_set_mgid()
4873 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFFF0FFFF) == in cma_set_mgid()
4876 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_set_mgid()
4877 } else if (addr->sa_family == AF_IB) { in cma_set_mgid()
4878 memcpy(mgid, &((struct sockaddr_ib *) addr)->sib_addr, sizeof *mgid); in cma_set_mgid()
4879 } else if (addr->sa_family == AF_INET6) { in cma_set_mgid()
4880 ipv6_ib_mc_map(&sin6->sin6_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4881 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4885 ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4886 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4893 struct cma_multicast *mc) in cma_join_ib_multicast() argument
4896 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_join_ib_multicast()
4901 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num, in cma_join_ib_multicast()
4906 if (!id_priv->qkey) { in cma_join_ib_multicast()
4912 cma_set_mgid(id_priv, (struct sockaddr *) &mc->addr, &rec.mgid); in cma_join_ib_multicast()
4913 rec.qkey = cpu_to_be32(id_priv->qkey); in cma_join_ib_multicast()
4916 rec.join_state = mc->join_state; in cma_join_ib_multicast()
4924 if (id_priv->id.ps == RDMA_PS_IPOIB) in cma_join_ib_multicast()
4931 mc->sa_mc = ib_sa_join_multicast(&sa_client, id_priv->id.device, in cma_join_ib_multicast()
4932 id_priv->id.port_num, &rec, comp_mask, in cma_join_ib_multicast()
4933 GFP_KERNEL, cma_ib_mc_handler, mc); in cma_join_ib_multicast()
4934 return PTR_ERR_OR_ZERO(mc->sa_mc); in cma_join_ib_multicast()
4945 } else if (addr->sa_family == AF_INET6) { in cma_iboe_set_mgid()
4946 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_iboe_set_mgid()
4948 mgid->raw[0] = in cma_iboe_set_mgid()
4950 mgid->raw[1] = in cma_iboe_set_mgid()
4952 mgid->raw[2] = 0; in cma_iboe_set_mgid()
4953 mgid->raw[3] = 0; in cma_iboe_set_mgid()
4954 mgid->raw[4] = 0; in cma_iboe_set_mgid()
4955 mgid->raw[5] = 0; in cma_iboe_set_mgid()
4956 mgid->raw[6] = 0; in cma_iboe_set_mgid()
4957 mgid->raw[7] = 0; in cma_iboe_set_mgid()
4958 mgid->raw[8] = 0; in cma_iboe_set_mgid()
4959 mgid->raw[9] = 0; in cma_iboe_set_mgid()
4960 mgid->raw[10] = 0xff; in cma_iboe_set_mgid()
4961 mgid->raw[11] = 0xff; in cma_iboe_set_mgid()
4962 *(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr; in cma_iboe_set_mgid()
4967 struct cma_multicast *mc) in cma_iboe_join_multicast() argument
4969 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iboe_join_multicast()
4971 struct sockaddr *addr = (struct sockaddr *)&mc->addr; in cma_iboe_join_multicast()
4977 send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); in cma_iboe_join_multicast()
4980 return -EINVAL; in cma_iboe_join_multicast()
4982 gid_type = id_priv->cma_dev->default_gid_type[id_priv->id.port_num - in cma_iboe_join_multicast()
4983 rdma_start_port(id_priv->cma_dev->device)]; in cma_iboe_join_multicast()
4987 if (dev_addr->bound_dev_if) in cma_iboe_join_multicast()
4988 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_iboe_join_multicast()
4990 return -ENODEV; in cma_iboe_join_multicast()
4994 ib.rec.mtu = iboe_get_mtu(ndev->mtu); in cma_iboe_join_multicast()
4996 if (addr->sa_family == AF_INET) { in cma_iboe_join_multicast()
5006 err = -ENOTSUPP; in cma_iboe_join_multicast()
5010 return err ?: -EINVAL; in cma_iboe_join_multicast()
5012 if (!id_priv->qkey) in cma_iboe_join_multicast()
5015 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_iboe_join_multicast()
5017 INIT_WORK(&mc->iboe_join.work, cma_iboe_join_work_handler); in cma_iboe_join_multicast()
5018 cma_make_mc_event(0, id_priv, &ib, &mc->iboe_join.event, mc); in cma_iboe_join_multicast()
5019 queue_work(cma_wq, &mc->iboe_join.work); in cma_iboe_join_multicast()
5028 struct cma_multicast *mc; in rdma_join_multicast() local
5032 if (WARN_ON(id->qp)) in rdma_join_multicast()
5033 return -EINVAL; in rdma_join_multicast()
5036 if (!id->device || (READ_ONCE(id_priv->state) != RDMA_CM_ADDR_BOUND && in rdma_join_multicast()
5037 READ_ONCE(id_priv->state) != RDMA_CM_ADDR_RESOLVED)) in rdma_join_multicast()
5038 return -EINVAL; in rdma_join_multicast()
5040 if (id_priv->id.qp_type != IB_QPT_UD) in rdma_join_multicast()
5041 return -EINVAL; in rdma_join_multicast()
5043 mc = kzalloc(sizeof(*mc), GFP_KERNEL); in rdma_join_multicast()
5044 if (!mc) in rdma_join_multicast()
5045 return -ENOMEM; in rdma_join_multicast()
5047 memcpy(&mc->addr, addr, rdma_addr_size(addr)); in rdma_join_multicast()
5048 mc->context = context; in rdma_join_multicast()
5049 mc->id_priv = id_priv; in rdma_join_multicast()
5050 mc->join_state = join_state; in rdma_join_multicast()
5052 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_join_multicast()
5053 ret = cma_iboe_join_multicast(id_priv, mc); in rdma_join_multicast()
5056 } else if (rdma_cap_ib_mcast(id->device, id->port_num)) { in rdma_join_multicast()
5057 ret = cma_join_ib_multicast(id_priv, mc); in rdma_join_multicast()
5061 ret = -ENOSYS; in rdma_join_multicast()
5065 spin_lock(&id_priv->lock); in rdma_join_multicast()
5066 list_add(&mc->list, &id_priv->mc_list); in rdma_join_multicast()
5067 spin_unlock(&id_priv->lock); in rdma_join_multicast()
5071 kfree(mc); in rdma_join_multicast()
5079 struct cma_multicast *mc; in rdma_leave_multicast() local
5082 spin_lock_irq(&id_priv->lock); in rdma_leave_multicast()
5083 list_for_each_entry(mc, &id_priv->mc_list, list) { in rdma_leave_multicast()
5084 if (memcmp(&mc->addr, addr, rdma_addr_size(addr)) != 0) in rdma_leave_multicast()
5086 list_del(&mc->list); in rdma_leave_multicast()
5087 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
5089 WARN_ON(id_priv->cma_dev->device != id->device); in rdma_leave_multicast()
5090 destroy_mc(id_priv, mc); in rdma_leave_multicast()
5093 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
5102 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_netdev_change()
5104 if ((dev_addr->bound_dev_if == ndev->ifindex) && in cma_netdev_change()
5105 (net_eq(dev_net(ndev), dev_addr->net)) && in cma_netdev_change()
5106 memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) { in cma_netdev_change()
5108 ndev->name, &id_priv->id); in cma_netdev_change()
5111 return -ENOMEM; in cma_netdev_change()
5113 INIT_WORK(&work->work, cma_work_handler); in cma_netdev_change()
5114 work->id = id_priv; in cma_netdev_change()
5115 work->event.event = RDMA_CM_EVENT_ADDR_CHANGE; in cma_netdev_change()
5117 queue_work(cma_wq, &work->work); in cma_netdev_change()
5139 list_for_each_entry(id_priv, &cma_dev->id_list, device_item) { in cma_netdev_callback()
5156 mutex_lock(&id_priv->handler_mutex); in cma_netevent_work_handler()
5158 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_netevent_work_handler()
5159 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_netevent_work_handler()
5163 event.status = -ETIMEDOUT; in cma_netevent_work_handler()
5166 __acquire(&id_priv->handler_mutex); in cma_netevent_work_handler()
5167 id_priv->cm_id.ib = NULL; in cma_netevent_work_handler()
5174 mutex_unlock(&id_priv->handler_mutex); in cma_netevent_work_handler()
5190 if (neigh->tbl->family == AF_INET6) { in cma_netevent_callback()
5194 neigh_sock_6.sin6_addr = *(struct in6_addr *)neigh->primary_key; in cma_netevent_callback()
5195 ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, in cma_netevent_callback()
5197 } else if (neigh->tbl->family == AF_INET) { in cma_netevent_callback()
5201 neigh_sock_4.sin_addr.s_addr = *(__be32 *)(neigh->primary_key); in cma_netevent_callback()
5202 ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, in cma_netevent_callback()
5210 list_for_each_entry(current_id, &ips_node->id_list, id_list_entry) { in cma_netevent_callback()
5211 if (!memcmp(current_id->id.route.addr.dev_addr.dst_dev_addr, in cma_netevent_callback()
5212 neigh->ha, ETH_ALEN)) in cma_netevent_callback()
5214 INIT_WORK(¤t_id->id.net_work, cma_netevent_work_handler); in cma_netevent_callback()
5216 queue_work(cma_wq, ¤t_id->id.net_work); in cma_netevent_callback()
5237 mutex_lock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5239 spin_lock_irqsave(&id_priv->lock, flags); in cma_send_device_removal_put()
5240 state = id_priv->state; in cma_send_device_removal_put()
5242 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
5243 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5247 id_priv->state = RDMA_CM_DEVICE_REMOVAL; in cma_send_device_removal_put()
5248 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
5256 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5261 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5274 while (!list_empty(&cma_dev->id_list)) { in cma_process_remove()
5276 &cma_dev->id_list, struct rdma_id_private, device_item); in cma_process_remove()
5278 list_del_init(&id_priv->listen_item); in cma_process_remove()
5279 list_del_init(&id_priv->device_item); in cma_process_remove()
5290 wait_for_completion(&cma_dev->comp); in cma_process_remove()
5314 return -EOPNOTSUPP; in cma_add_one()
5318 return -ENOMEM; in cma_add_one()
5320 cma_dev->device = device; in cma_add_one()
5321 cma_dev->default_gid_type = kcalloc(device->phys_port_cnt, in cma_add_one()
5322 sizeof(*cma_dev->default_gid_type), in cma_add_one()
5324 if (!cma_dev->default_gid_type) { in cma_add_one()
5325 ret = -ENOMEM; in cma_add_one()
5329 cma_dev->default_roce_tos = kcalloc(device->phys_port_cnt, in cma_add_one()
5330 sizeof(*cma_dev->default_roce_tos), in cma_add_one()
5332 if (!cma_dev->default_roce_tos) { in cma_add_one()
5333 ret = -ENOMEM; in cma_add_one()
5341 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
5344 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
5346 cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0; in cma_add_one()
5349 init_completion(&cma_dev->comp); in cma_add_one()
5350 refcount_set(&cma_dev->refcount, 1); in cma_add_one()
5351 INIT_LIST_HEAD(&cma_dev->id_list); in cma_add_one()
5355 list_add_tail(&cma_dev->list, &dev_list); in cma_add_one()
5367 list_del(&cma_dev->list); in cma_add_one()
5372 kfree(cma_dev->default_roce_tos); in cma_add_one()
5374 kfree(cma_dev->default_gid_type); in cma_add_one()
5388 list_del(&cma_dev->list); in cma_remove_one()
5392 kfree(cma_dev->default_roce_tos); in cma_remove_one()
5393 kfree(cma_dev->default_gid_type); in cma_remove_one()
5401 xa_init(&pernet->tcp_ps); in cma_init_net()
5402 xa_init(&pernet->udp_ps); in cma_init_net()
5403 xa_init(&pernet->ipoib_ps); in cma_init_net()
5404 xa_init(&pernet->ib_ps); in cma_init_net()
5413 WARN_ON(!xa_empty(&pernet->tcp_ps)); in cma_exit_net()
5414 WARN_ON(!xa_empty(&pernet->udp_ps)); in cma_exit_net()
5415 WARN_ON(!xa_empty(&pernet->ipoib_ps)); in cma_exit_net()
5416 WARN_ON(!xa_empty(&pernet->ib_ps)); in cma_exit_net()
5445 return -ENOMEM; in cma_init()