Lines Matching +full:device +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
4 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
5 * Copyright (c) 1999-2019, Mellanox Technologies, Inc. All rights reserved.
6 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
65 [RDMA_CM_EVENT_DEVICE_REMOVAL] = "device removal",
84 const char *__attribute_const__ rdma_reject_msg(struct rdma_cm_id *id, in rdma_reject_msg() argument
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
101 * @id: Communication identifier that received the REJECT event.
104 static bool rdma_is_consumer_reject(struct rdma_cm_id *id, int reason) in rdma_is_consumer_reject() argument
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()
116 const void *rdma_consumer_reject_data(struct rdma_cm_id *id, in rdma_consumer_reject_data() argument
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.
134 * @id: Communication Identifier
136 struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *id) in rdma_iw_cm_id() argument
140 id_priv = container_of(id, struct rdma_id_private, id); in rdma_iw_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()
160 static int cma_add_one(struct ib_device *device);
161 static void cma_remove_one(struct ib_device *device, void *client_data);
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()
217 struct ib_device *device; member
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()
348 * Device removal can occur at anytime, so we need extra handling to
349 * serialize notifying the user of device removal with other callbacks.
371 struct rdma_id_private *id; member
398 struct ib_device *device; member
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()
483 return memcmp((char *)&((struct sockaddr_in *)sa)->sin_addr, in compare_netdev_and_ip()
484 (char *)&((struct sockaddr_in *)sb)->sin_addr, in compare_netdev_and_ip()
485 sizeof(((struct sockaddr_in *)sa)->sin_addr)); in compare_netdev_and_ip()
487 return ipv6_addr_cmp(&((struct sockaddr_in6 *)sa)->sin6_addr, in compare_netdev_and_ip()
488 &((struct sockaddr_in6 *)sb)->sin6_addr); in compare_netdev_and_ip()
500 return -ENOMEM; in cma_add_id_to_tree()
507 node_id_priv->id.route.addr.dev_addr.bound_dev_if, in cma_add_id_to_tree()
512 new = &((*new)->rb_left); in cma_add_id_to_tree()
514 new = &((*new)->rb_right); in cma_add_id_to_tree()
516 list_add_tail(&node_id_priv->id_list_entry, in cma_add_id_to_tree()
517 &this->id_list); in cma_add_id_to_tree()
523 INIT_LIST_HEAD(&node->id_list); in cma_add_id_to_tree()
524 list_add_tail(&node_id_priv->id_list_entry, &node->id_list); in cma_add_id_to_tree()
526 rb_link_node(&node->rb_node, parent, new); in cma_add_id_to_tree()
527 rb_insert_color(&node->rb_node, &id_table); in cma_add_id_to_tree()
537 struct rb_node *node = root->rb_node; in node_from_ndev_ip()
545 node = node->rb_left; in node_from_ndev_ip()
547 node = node->rb_right; in node_from_ndev_ip()
561 if (list_empty(&id_priv->id_list_entry)) in cma_remove_id_from_tree()
565 id_priv->id.route.addr.dev_addr.bound_dev_if, in cma_remove_id_from_tree()
570 list_del_init(&id_priv->id_list_entry); in cma_remove_id_from_tree()
571 if (list_empty(&data->id_list)) { in cma_remove_id_from_tree()
572 rb_erase(&data->rb_node, &id_table); in cma_remove_id_from_tree()
583 id_priv->cma_dev = cma_dev; in _cma_attach_to_dev()
584 id_priv->id.device = cma_dev->device; in _cma_attach_to_dev()
585 id_priv->id.route.addr.dev_addr.transport = in _cma_attach_to_dev()
586 rdma_node_get_transport(cma_dev->device->node_type); in _cma_attach_to_dev()
587 list_add_tail(&id_priv->device_item, &cma_dev->id_list); in _cma_attach_to_dev()
589 trace_cm_id_attach(id_priv, cma_dev->device); in _cma_attach_to_dev()
596 id_priv->gid_type = in cma_attach_to_dev()
597 cma_dev->default_gid_type[id_priv->id.port_num - in cma_attach_to_dev()
598 rdma_start_port(cma_dev->device)]; in cma_attach_to_dev()
604 list_del_init(&id_priv->device_item); in cma_release_dev()
605 cma_dev_put(id_priv->cma_dev); in cma_release_dev()
606 id_priv->cma_dev = NULL; in cma_release_dev()
607 id_priv->id.device = NULL; in cma_release_dev()
608 if (id_priv->id.route.addr.dev_addr.sgid_attr) { in cma_release_dev()
609 rdma_put_gid_attr(id_priv->id.route.addr.dev_addr.sgid_attr); in cma_release_dev()
610 id_priv->id.route.addr.dev_addr.sgid_attr = NULL; in cma_release_dev()
617 return id_priv->id.route.addr.src_addr.ss_family; in cma_family()
625 if (id_priv->qkey) { in cma_set_qkey()
626 if (qkey && id_priv->qkey != qkey) in cma_set_qkey()
627 return -EINVAL; in cma_set_qkey()
632 id_priv->qkey = qkey; in cma_set_qkey()
636 switch (id_priv->id.ps) { in cma_set_qkey()
639 id_priv->qkey = RDMA_UDP_QKEY; in cma_set_qkey()
642 ib_addr_get_mgid(&id_priv->id.route.addr.dev_addr, &rec.mgid); in cma_set_qkey()
643 ret = ib_sa_get_mcmember_rec(id_priv->id.device, in cma_set_qkey()
644 id_priv->id.port_num, &rec.mgid, in cma_set_qkey()
647 id_priv->qkey = be32_to_cpu(rec.qkey); in cma_set_qkey()
657 dev_addr->dev_type = ARPHRD_INFINIBAND; in cma_translate_ib()
658 rdma_addr_set_sgid(dev_addr, (union ib_gid *) &sib->sib_addr); in cma_translate_ib()
659 ib_addr_set_pkey(dev_addr, ntohs(sib->sib_pkey)); in cma_translate_ib()
666 if (addr->sa_family != AF_IB) { in cma_translate_addr()
677 cma_validate_port(struct ib_device *device, u32 port, in cma_validate_port() argument
682 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_validate_port()
683 int bound_if_index = dev_addr->bound_dev_if; in cma_validate_port()
685 int dev_type = dev_addr->dev_type; in cma_validate_port()
688 if (!rdma_dev_access_netns(device, id_priv->id.route.addr.dev_addr.net)) in cma_validate_port()
689 return ERR_PTR(-ENODEV); in cma_validate_port()
691 if ((dev_type == ARPHRD_INFINIBAND) && !rdma_protocol_ib(device, port)) in cma_validate_port()
692 return ERR_PTR(-ENODEV); in cma_validate_port()
694 if ((dev_type != ARPHRD_INFINIBAND) && rdma_protocol_ib(device, port)) in cma_validate_port()
695 return ERR_PTR(-ENODEV); in cma_validate_port()
697 if (dev_type == ARPHRD_ETHER && rdma_protocol_roce(device, port)) { in cma_validate_port()
698 ndev = dev_get_by_index(dev_addr->net, bound_if_index); in cma_validate_port()
700 return ERR_PTR(-ENODEV); in cma_validate_port()
705 sgid_attr = rdma_find_gid_by_port(device, gid, gid_type, port, ndev); in cma_validate_port()
714 WARN_ON(id_priv->id.route.addr.dev_addr.sgid_attr); in cma_bind_sgid_attr()
715 id_priv->id.route.addr.dev_addr.sgid_attr = sgid_attr; in cma_bind_sgid_attr()
719 * cma_acquire_dev_by_src_ip - Acquire cma device, port, gid attribute
721 * @id_priv: cm_id which should be bound to cma device
723 * cma_acquire_dev_by_src_ip() binds cm id to cma device, port and GID attribute
729 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_acquire_dev_by_src_ip()
734 int ret = -ENODEV; in cma_acquire_dev_by_src_ip()
737 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_acquire_dev_by_src_ip()
738 id_priv->id.ps == RDMA_PS_IPOIB) in cma_acquire_dev_by_src_ip()
739 return -EINVAL; in cma_acquire_dev_by_src_ip()
741 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_acquire_dev_by_src_ip()
744 memcpy(&gid, dev_addr->src_dev_addr + in cma_acquire_dev_by_src_ip()
749 rdma_for_each_port (cma_dev->device, port) { in cma_acquire_dev_by_src_ip()
750 gidp = rdma_protocol_roce(cma_dev->device, port) ? in cma_acquire_dev_by_src_ip()
752 gid_type = cma_dev->default_gid_type[port - 1]; in cma_acquire_dev_by_src_ip()
753 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_acquire_dev_by_src_ip()
756 id_priv->id.port_num = port; in cma_acquire_dev_by_src_ip()
770 * cma_ib_acquire_dev - Acquire cma device, port and SGID attribute
771 * @id_priv: cm id to bind to cma device
772 * @listen_id_priv: listener cm id to match against
775 * cma_ib_acquire_dev() acquires cma device, port and SGID attribute when
776 * rdma device matches for listen_id and incoming request. It also verifies
784 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_acquire_dev()
789 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_ib_acquire_dev()
790 id_priv->id.ps == RDMA_PS_IPOIB) in cma_ib_acquire_dev()
791 return -EINVAL; in cma_ib_acquire_dev()
793 if (rdma_protocol_roce(req->device, req->port)) in cma_ib_acquire_dev()
794 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_ib_acquire_dev()
797 memcpy(&gid, dev_addr->src_dev_addr + in cma_ib_acquire_dev()
800 gid_type = listen_id_priv->cma_dev->default_gid_type[req->port - 1]; in cma_ib_acquire_dev()
801 sgid_attr = cma_validate_port(req->device, req->port, in cma_ib_acquire_dev()
806 id_priv->id.port_num = req->port; in cma_ib_acquire_dev()
809 * of cma_dev->id_list such as cma_netdev_callback() and in cma_ib_acquire_dev()
813 cma_attach_to_dev(id_priv, listen_id_priv->cma_dev); in cma_ib_acquire_dev()
815 rdma_restrack_add(&id_priv->res); in cma_ib_acquire_dev()
822 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iw_acquire_dev()
826 int ret = -ENODEV; in cma_iw_acquire_dev()
830 if (dev_addr->dev_type != ARPHRD_INFINIBAND && in cma_iw_acquire_dev()
831 id_priv->id.ps == RDMA_PS_IPOIB) in cma_iw_acquire_dev()
832 return -EINVAL; in cma_iw_acquire_dev()
834 memcpy(&gid, dev_addr->src_dev_addr + in cma_iw_acquire_dev()
839 cma_dev = listen_id_priv->cma_dev; in cma_iw_acquire_dev()
840 port = listen_id_priv->id.port_num; in cma_iw_acquire_dev()
841 gid_type = listen_id_priv->gid_type; in cma_iw_acquire_dev()
842 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
845 id_priv->id.port_num = port; in cma_iw_acquire_dev()
852 rdma_for_each_port (cma_dev->device, port) { in cma_iw_acquire_dev()
853 if (listen_id_priv->cma_dev == cma_dev && in cma_iw_acquire_dev()
854 listen_id_priv->id.port_num == port) in cma_iw_acquire_dev()
857 gid_type = cma_dev->default_gid_type[port - 1]; in cma_iw_acquire_dev()
858 sgid_attr = cma_validate_port(cma_dev->device, port, in cma_iw_acquire_dev()
861 id_priv->id.port_num = port; in cma_iw_acquire_dev()
872 rdma_restrack_add(&id_priv->res); in cma_iw_acquire_dev()
880 * Select the source IB device and address to reach the destination IB address.
895 dgid = (union ib_gid *) &addr->sib_addr; in cma_resolve_ib_dev()
896 pkey = ntohs(addr->sib_pkey); in cma_resolve_ib_dev()
900 rdma_for_each_port (cur_dev->device, p) { in cma_resolve_ib_dev()
901 if (!rdma_cap_af_ib(cur_dev->device, p)) in cma_resolve_ib_dev()
904 if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index)) in cma_resolve_ib_dev()
907 if (ib_get_cached_port_state(cur_dev->device, p, &port_state)) in cma_resolve_ib_dev()
910 for (i = 0; i < cur_dev->device->port_data[p].immutable.gid_tbl_len; in cma_resolve_ib_dev()
912 ret = rdma_query_gid(cur_dev->device, p, i, in cma_resolve_ib_dev()
920 id_priv->id.port_num = p; in cma_resolve_ib_dev()
925 dgid->global.subnet_prefix) && in cma_resolve_ib_dev()
929 id_priv->id.port_num = p; in cma_resolve_ib_dev()
936 return -ENODEV; in cma_resolve_ib_dev()
940 rdma_restrack_add(&id_priv->res); in cma_resolve_ib_dev()
943 memcpy(&addr->sib_addr, &sgid, sizeof(sgid)); in cma_resolve_ib_dev()
944 cma_translate_ib(addr, &id_priv->id.route.addr.dev_addr); in cma_resolve_ib_dev()
950 refcount_inc(&id_priv->refcount); in cma_id_get()
955 if (refcount_dec_and_test(&id_priv->refcount)) in cma_id_put()
956 complete(&id_priv->comp); in cma_id_put()
968 return ERR_PTR(-ENOMEM); in __rdma_create_id()
970 id_priv->state = RDMA_CM_IDLE; in __rdma_create_id()
971 id_priv->id.context = context; in __rdma_create_id()
972 id_priv->id.event_handler = event_handler; in __rdma_create_id()
973 id_priv->id.ps = ps; in __rdma_create_id()
974 id_priv->id.qp_type = qp_type; in __rdma_create_id()
975 id_priv->tos_set = false; in __rdma_create_id()
976 id_priv->timeout_set = false; in __rdma_create_id()
977 id_priv->min_rnr_timer_set = false; in __rdma_create_id()
978 id_priv->gid_type = IB_GID_TYPE_IB; in __rdma_create_id()
979 spin_lock_init(&id_priv->lock); in __rdma_create_id()
980 mutex_init(&id_priv->qp_mutex); in __rdma_create_id()
981 init_completion(&id_priv->comp); in __rdma_create_id()
982 refcount_set(&id_priv->refcount, 1); in __rdma_create_id()
983 mutex_init(&id_priv->handler_mutex); in __rdma_create_id()
984 INIT_LIST_HEAD(&id_priv->device_item); in __rdma_create_id()
985 INIT_LIST_HEAD(&id_priv->id_list_entry); in __rdma_create_id()
986 INIT_LIST_HEAD(&id_priv->listen_list); in __rdma_create_id()
987 INIT_LIST_HEAD(&id_priv->mc_list); in __rdma_create_id()
988 get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num); in __rdma_create_id()
989 id_priv->id.route.addr.dev_addr.net = get_net(net); in __rdma_create_id()
990 id_priv->seq_num &= 0x00ffffff; in __rdma_create_id()
992 rdma_restrack_new(&id_priv->res, RDMA_RESTRACK_CM_ID); in __rdma_create_id()
994 rdma_restrack_parent_name(&id_priv->res, &parent->res); in __rdma_create_id()
1010 rdma_restrack_set_name(&ret->res, caller); in __rdma_create_kernel_id()
1011 return &ret->id; in __rdma_create_kernel_id()
1022 ret = __rdma_create_id(current->nsproxy->net_ns, event_handler, context, in rdma_create_user_id()
1027 rdma_restrack_set_name(&ret->res, NULL); in rdma_create_user_id()
1028 return &ret->id; in rdma_create_user_id()
1038 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_ud_qp()
1064 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_init_conn_qp()
1071 int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, in rdma_create_qp() argument
1078 id_priv = container_of(id, struct rdma_id_private, id); in rdma_create_qp()
1079 if (id->device != pd->device) { in rdma_create_qp()
1080 ret = -EINVAL; in rdma_create_qp()
1084 qp_init_attr->port_num = id->port_num; in rdma_create_qp()
1091 if (id->qp_type == IB_QPT_UD) in rdma_create_qp()
1098 id->qp = qp; in rdma_create_qp()
1099 id_priv->qp_num = qp->qp_num; in rdma_create_qp()
1100 id_priv->srq = (qp->srq != NULL); in rdma_create_qp()
1111 void rdma_destroy_qp(struct rdma_cm_id *id) in rdma_destroy_qp() argument
1115 id_priv = container_of(id, struct rdma_id_private, id); in rdma_destroy_qp()
1117 mutex_lock(&id_priv->qp_mutex); in rdma_destroy_qp()
1118 ib_destroy_qp(id_priv->id.qp); in rdma_destroy_qp()
1119 id_priv->id.qp = NULL; in rdma_destroy_qp()
1120 mutex_unlock(&id_priv->qp_mutex); in rdma_destroy_qp()
1130 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
1131 if (!id_priv->id.qp) { in cma_modify_qp_rtr()
1138 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1142 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1147 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rtr()
1151 BUG_ON(id_priv->cma_dev->device != id_priv->id.device); in cma_modify_qp_rtr()
1154 qp_attr.max_dest_rd_atomic = conn_param->responder_resources; in cma_modify_qp_rtr()
1155 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rtr()
1157 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rtr()
1167 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1168 if (!id_priv->id.qp) { in cma_modify_qp_rts()
1174 ret = rdma_init_qp_attr(&id_priv->id, &qp_attr, &qp_attr_mask); in cma_modify_qp_rts()
1179 qp_attr.max_rd_atomic = conn_param->initiator_depth; in cma_modify_qp_rts()
1180 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, qp_attr_mask); in cma_modify_qp_rts()
1182 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_rts()
1191 mutex_lock(&id_priv->qp_mutex); in cma_modify_qp_err()
1192 if (!id_priv->id.qp) { in cma_modify_qp_err()
1198 ret = ib_modify_qp(id_priv->id.qp, &qp_attr, IB_QP_STATE); in cma_modify_qp_err()
1200 mutex_unlock(&id_priv->qp_mutex); in cma_modify_qp_err()
1207 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_ib_init_qp_attr()
1211 if (rdma_cap_eth_ah(id_priv->id.device, id_priv->id.port_num)) in cma_ib_init_qp_attr()
1216 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, in cma_ib_init_qp_attr()
1217 pkey, &qp_attr->pkey_index); in cma_ib_init_qp_attr()
1221 qp_attr->port_num = id_priv->id.port_num; in cma_ib_init_qp_attr()
1224 if (id_priv->id.qp_type == IB_QPT_UD) { in cma_ib_init_qp_attr()
1229 qp_attr->qkey = id_priv->qkey; in cma_ib_init_qp_attr()
1232 qp_attr->qp_access_flags = 0; in cma_ib_init_qp_attr()
1238 int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, in rdma_init_qp_attr() argument
1244 id_priv = container_of(id, struct rdma_id_private, id); in rdma_init_qp_attr()
1245 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1246 if (!id_priv->cm_id.ib || (id_priv->id.qp_type == IB_QPT_UD)) in rdma_init_qp_attr()
1249 ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr, in rdma_init_qp_attr()
1252 if (qp_attr->qp_state == IB_QPS_RTR) in rdma_init_qp_attr()
1253 qp_attr->rq_psn = id_priv->seq_num; in rdma_init_qp_attr()
1254 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_init_qp_attr()
1255 if (!id_priv->cm_id.iw) { in rdma_init_qp_attr()
1256 qp_attr->qp_access_flags = 0; in rdma_init_qp_attr()
1259 ret = iw_cm_init_qp_attr(id_priv->cm_id.iw, qp_attr, in rdma_init_qp_attr()
1261 qp_attr->port_num = id_priv->id.port_num; in rdma_init_qp_attr()
1264 ret = -ENOSYS; in rdma_init_qp_attr()
1267 if ((*qp_attr_mask & IB_QP_TIMEOUT) && id_priv->timeout_set) in rdma_init_qp_attr()
1268 qp_attr->timeout = id_priv->timeout; in rdma_init_qp_attr()
1270 if ((*qp_attr_mask & IB_QP_MIN_RNR_TIMER) && id_priv->min_rnr_timer_set) in rdma_init_qp_attr()
1271 qp_attr->min_rnr_timer = id_priv->min_rnr_timer; in rdma_init_qp_attr()
1279 switch (addr->sa_family) { in cma_zero_addr()
1281 return ipv4_is_zeronet(((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_zero_addr()
1283 return ipv6_addr_any(&((struct sockaddr_in6 *)addr)->sin6_addr); in cma_zero_addr()
1285 return ib_addr_any(&((struct sockaddr_ib *)addr)->sib_addr); in cma_zero_addr()
1293 switch (addr->sa_family) { in cma_loopback_addr()
1296 ((struct sockaddr_in *)addr)->sin_addr.s_addr); in cma_loopback_addr()
1299 &((struct sockaddr_in6 *)addr)->sin6_addr); in cma_loopback_addr()
1302 &((struct sockaddr_ib *)addr)->sib_addr); in cma_loopback_addr()
1315 if (src->sa_family != dst->sa_family) in cma_addr_cmp()
1316 return -1; in cma_addr_cmp()
1318 switch (src->sa_family) { in cma_addr_cmp()
1320 return ((struct sockaddr_in *)src)->sin_addr.s_addr != in cma_addr_cmp()
1321 ((struct sockaddr_in *)dst)->sin_addr.s_addr; in cma_addr_cmp()
1327 if (ipv6_addr_cmp(&src_addr6->sin6_addr, in cma_addr_cmp()
1328 &dst_addr6->sin6_addr)) in cma_addr_cmp()
1330 link_local = ipv6_addr_type(&dst_addr6->sin6_addr) & in cma_addr_cmp()
1333 return link_local ? (src_addr6->sin6_scope_id != in cma_addr_cmp()
1334 dst_addr6->sin6_scope_id) : in cma_addr_cmp()
1339 return ib_addr_cmp(&((struct sockaddr_ib *) src)->sib_addr, in cma_addr_cmp()
1340 &((struct sockaddr_ib *) dst)->sib_addr); in cma_addr_cmp()
1348 switch (addr->sa_family) { in cma_port()
1350 return ((struct sockaddr_in *) addr)->sin_port; in cma_port()
1352 return ((struct sockaddr_in6 *) addr)->sin6_port; in cma_port()
1355 return htons((u16) (be64_to_cpu(sib->sib_sid) & in cma_port()
1356 be64_to_cpu(sib->sib_sid_mask))); in cma_port()
1374 listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; in cma_save_ib_info()
1377 ib->sib_family = AF_IB; in cma_save_ib_info()
1379 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1380 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1381 memcpy(&ib->sib_addr, &path->sgid, 16); in cma_save_ib_info()
1382 ib->sib_sid = path->service_id; in cma_save_ib_info()
1383 ib->sib_scope_id = 0; in cma_save_ib_info()
1385 ib->sib_pkey = listen_ib->sib_pkey; in cma_save_ib_info()
1386 ib->sib_flowinfo = listen_ib->sib_flowinfo; in cma_save_ib_info()
1387 ib->sib_addr = listen_ib->sib_addr; in cma_save_ib_info()
1388 ib->sib_sid = listen_ib->sib_sid; in cma_save_ib_info()
1389 ib->sib_scope_id = listen_ib->sib_scope_id; in cma_save_ib_info()
1391 ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); in cma_save_ib_info()
1395 ib->sib_family = AF_IB; in cma_save_ib_info()
1397 ib->sib_pkey = path->pkey; in cma_save_ib_info()
1398 ib->sib_flowinfo = path->flow_label; in cma_save_ib_info()
1399 memcpy(&ib->sib_addr, &path->dgid, 16); in cma_save_ib_info()
1412 .sin_addr.s_addr = hdr->dst_addr.ip4.addr, in cma_save_ip4_info()
1420 .sin_addr.s_addr = hdr->src_addr.ip4.addr, in cma_save_ip4_info()
1421 .sin_port = hdr->port, in cma_save_ip4_info()
1434 .sin6_addr = hdr->dst_addr.ip6, in cma_save_ip6_info()
1442 .sin6_addr = hdr->src_addr.ip6, in cma_save_ip6_info()
1443 .sin6_port = hdr->port, in cma_save_ip6_info()
1461 hdr = ib_event->private_data; in cma_save_ip_info()
1462 if (hdr->cma_version != CMA_VERSION) in cma_save_ip_info()
1463 return -EINVAL; in cma_save_ip_info()
1477 return -EAFNOSUPPORT; in cma_save_ip_info()
1490 if (ib_event->event == IB_CM_REQ_RECEIVED) in cma_save_net_info()
1492 ib_event->param.req_rcvd.primary_path); in cma_save_net_info()
1493 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in cma_save_net_info()
1505 &ib_event->param.req_rcvd; in cma_save_req_info()
1507 &ib_event->param.sidr_req_rcvd; in cma_save_req_info()
1509 switch (ib_event->event) { in cma_save_req_info()
1511 req->device = req_param->listen_id->device; in cma_save_req_info()
1512 req->port = req_param->port; in cma_save_req_info()
1513 memcpy(&req->local_gid, &req_param->primary_path->sgid, in cma_save_req_info()
1514 sizeof(req->local_gid)); in cma_save_req_info()
1515 req->has_gid = true; in cma_save_req_info()
1516 req->service_id = req_param->primary_path->service_id; in cma_save_req_info()
1517 req->pkey = be16_to_cpu(req_param->primary_path->pkey); in cma_save_req_info()
1518 if (req->pkey != req_param->bth_pkey) in cma_save_req_info()
1521 req_param->bth_pkey, req->pkey); in cma_save_req_info()
1524 req->device = sidr_param->listen_id->device; in cma_save_req_info()
1525 req->port = sidr_param->port; in cma_save_req_info()
1526 req->has_gid = false; in cma_save_req_info()
1527 req->service_id = sidr_param->service_id; in cma_save_req_info()
1528 req->pkey = sidr_param->pkey; in cma_save_req_info()
1529 if (req->pkey != sidr_param->bth_pkey) in cma_save_req_info()
1532 sidr_param->bth_pkey, req->pkey); in cma_save_req_info()
1535 return -EINVAL; in cma_save_req_info()
1545 __be32 daddr = dst_addr->sin_addr.s_addr, in validate_ipv4_net_dev()
1546 saddr = src_addr->sin_addr.s_addr; in validate_ipv4_net_dev()
1559 fl4.flowi4_oif = net_dev->ifindex; in validate_ipv4_net_dev()
1576 const int strict = ipv6_addr_type(&dst_addr->sin6_addr) & in validate_ipv6_net_dev()
1578 struct rt6_info *rt = rt6_lookup(dev_net(net_dev), &dst_addr->sin6_addr, in validate_ipv6_net_dev()
1579 &src_addr->sin6_addr, net_dev->ifindex, in validate_ipv6_net_dev()
1586 ret = rt->rt6i_idev->dev == net_dev; in validate_ipv6_net_dev()
1604 switch (daddr->sa_family) { in validate_net_dev()
1606 return saddr->sa_family == AF_INET && in validate_net_dev()
1610 return saddr->sa_family == AF_INET6 && in validate_net_dev()
1624 if (ib_event->event == IB_CM_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1625 sgid_attr = ib_event->param.req_rcvd.ppath_sgid_attr; in roce_get_net_dev_by_cm_event()
1626 else if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) in roce_get_net_dev_by_cm_event()
1627 sgid_attr = ib_event->param.sidr_req_rcvd.sgid_attr; in roce_get_net_dev_by_cm_event()
1646 (struct sockaddr *)&req->listen_addr_storage; in cma_get_net_dev()
1647 struct sockaddr *src_addr = (struct sockaddr *)&req->src_addr_storage; in cma_get_net_dev()
1649 const union ib_gid *gid = req->has_gid ? &req->local_gid : NULL; in cma_get_net_dev()
1653 req->service_id); in cma_get_net_dev()
1657 if (rdma_protocol_roce(req->device, req->port)) in cma_get_net_dev()
1660 net_dev = ib_get_net_dev_by_params(req->device, req->port, in cma_get_net_dev()
1661 req->pkey, in cma_get_net_dev()
1664 return ERR_PTR(-ENODEV); in cma_get_net_dev()
1681 if (cma_any_addr(addr) && !id_priv->afonly) in cma_match_private_data()
1684 switch (addr->sa_family) { in cma_match_private_data()
1686 ip4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; in cma_match_private_data()
1690 hdr->dst_addr.ip4.addr != ip4_addr) in cma_match_private_data()
1694 ip6_addr = ((struct sockaddr_in6 *)addr)->sin6_addr; in cma_match_private_data()
1698 memcmp(&hdr->dst_addr.ip6, &ip6_addr, sizeof(ip6_addr))) in cma_match_private_data()
1710 static bool cma_protocol_roce(const struct rdma_cm_id *id) in cma_protocol_roce() argument
1712 struct ib_device *device = id->device; in cma_protocol_roce() local
1713 const u32 port_num = id->port_num ?: rdma_start_port(device); in cma_protocol_roce()
1715 return rdma_protocol_roce(device, port_num); in cma_protocol_roce()
1721 (const struct sockaddr *)&req->listen_addr_storage; in cma_is_req_ipv6_ll()
1725 return (daddr->sa_family == AF_INET6 && in cma_is_req_ipv6_ll()
1726 (ipv6_addr_type(&daddr6->sin6_addr) & IPV6_ADDR_LINKLOCAL)); in cma_is_req_ipv6_ll()
1729 static bool cma_match_net_dev(const struct rdma_cm_id *id, in cma_match_net_dev() argument
1733 const struct rdma_addr *addr = &id->route.addr; in cma_match_net_dev()
1737 return (!id->port_num || id->port_num == req->port) && in cma_match_net_dev()
1738 (addr->src_addr.ss_family == AF_IB); in cma_match_net_dev()
1742 * request to any netdevice of the one or multiport rdma device. in cma_match_net_dev()
1750 if (net_eq(dev_net(net_dev), addr->dev_addr.net) && in cma_match_net_dev()
1751 (!!addr->dev_addr.bound_dev_if == in cma_match_net_dev()
1752 (addr->dev_addr.bound_dev_if == net_dev->ifindex))) in cma_match_net_dev()
1770 return ERR_PTR(-EINVAL); in cma_find_listener()
1772 hlist_for_each_entry(id_priv, &bind_list->owners, node) { in cma_find_listener()
1773 if (cma_match_private_data(id_priv, ib_event->private_data)) { in cma_find_listener()
1774 if (id_priv->id.device == cm_id->device && in cma_find_listener()
1775 cma_match_net_dev(&id_priv->id, net_dev, req)) in cma_find_listener()
1778 &id_priv->listen_list, in cma_find_listener()
1780 if (id_priv_dev->id.device == cm_id->device && in cma_find_listener()
1781 cma_match_net_dev(&id_priv_dev->id, in cma_find_listener()
1788 return ERR_PTR(-EINVAL); in cma_find_listener()
1807 if (PTR_ERR(*net_dev) == -EAFNOSUPPORT) { in cma_ib_id_from_event()
1824 * If the device state is not IFF_UP, its properties such as ifindex in cma_ib_id_from_event()
1827 * ongoing operations on net device after device is closed using in cma_ib_id_from_event()
1838 if (((*net_dev)->flags & IFF_UP) == 0) { in cma_ib_id_from_event()
1839 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1844 (struct sockaddr *)&req->src_addr_storage, in cma_ib_id_from_event()
1845 (struct sockaddr *)&req->listen_addr_storage)) { in cma_ib_id_from_event()
1846 id_priv = ERR_PTR(-EHOSTUNREACH); in cma_ib_id_from_event()
1852 rdma_ps_from_service_id(req->service_id), in cma_ib_id_from_event()
1853 cma_port_from_service_id(req->service_id)); in cma_ib_id_from_event()
1872 if (rdma_cap_ib_sa(id_priv->id.device, id_priv->id.port_num)) { in cma_cancel_route()
1873 if (id_priv->query) in cma_cancel_route()
1874 ib_sa_cancel_query(id_priv->query_id, id_priv->query); in cma_cancel_route()
1888 list_del_init(&id_priv->listen_any_item); in _cma_cancel_listens()
1890 while (!list_empty(&id_priv->listen_list)) { in _cma_cancel_listens()
1892 list_first_entry(&id_priv->listen_list, in _cma_cancel_listens()
1894 /* sync with device removal to avoid duplicate destruction */ in _cma_cancel_listens()
1895 list_del_init(&dev_id_priv->device_item); in _cma_cancel_listens()
1896 list_del_init(&dev_id_priv->listen_item); in _cma_cancel_listens()
1899 rdma_destroy_id(&dev_id_priv->id); in _cma_cancel_listens()
1924 rdma_addr_cancel(&id_priv->id.route.addr.dev_addr); in cma_cancel_operation()
1930 if (cma_any_addr(cma_src_addr(id_priv)) && !id_priv->cma_dev) in cma_cancel_operation()
1940 struct rdma_bind_list *bind_list = id_priv->bind_list; in cma_release_port()
1941 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_release_port()
1947 hlist_del(&id_priv->node); in cma_release_port()
1948 if (hlist_empty(&bind_list->owners)) { in cma_release_port()
1949 cma_ps_remove(net, bind_list->ps, bind_list->port); in cma_release_port()
1958 bool send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); in destroy_mc()
1960 if (rdma_cap_ib_mcast(id_priv->id.device, id_priv->id.port_num)) in destroy_mc()
1961 ib_sa_free_multicast(mc->sa_mc); in destroy_mc()
1963 if (rdma_protocol_roce(id_priv->id.device, id_priv->id.port_num)) { in destroy_mc()
1965 &id_priv->id.route.addr.dev_addr; in destroy_mc()
1968 if (dev_addr->bound_dev_if) in destroy_mc()
1969 ndev = dev_get_by_index(dev_addr->net, in destroy_mc()
1970 dev_addr->bound_dev_if); in destroy_mc()
1975 gid_type = id_priv->cma_dev->default_gid_type in destroy_mc()
1976 [id_priv->id.port_num - in destroy_mc()
1978 id_priv->cma_dev->device)]; in destroy_mc()
1979 cma_iboe_set_mgid((struct sockaddr *)&mc->addr, &mgid, in destroy_mc()
1985 cancel_work_sync(&mc->iboe_join.work); in destroy_mc()
1994 while (!list_empty(&id_priv->mc_list)) { in cma_leave_mc_groups()
1995 mc = list_first_entry(&id_priv->mc_list, struct cma_multicast, in cma_leave_mc_groups()
1997 list_del(&mc->list); in cma_leave_mc_groups()
2007 rdma_restrack_del(&id_priv->res); in _destroy_id()
2009 if (id_priv->cma_dev) { in _destroy_id()
2010 if (rdma_cap_ib_cm(id_priv->id.device, 1)) { in _destroy_id()
2011 if (id_priv->cm_id.ib) in _destroy_id()
2012 ib_destroy_cm_id(id_priv->cm_id.ib); in _destroy_id()
2013 } else if (rdma_cap_iw_cm(id_priv->id.device, 1)) { in _destroy_id()
2014 if (id_priv->cm_id.iw) in _destroy_id()
2015 iw_destroy_cm_id(id_priv->cm_id.iw); in _destroy_id()
2023 wait_for_completion(&id_priv->comp); in _destroy_id()
2025 if (id_priv->internal_id) in _destroy_id()
2026 cma_id_put(id_priv->id.context); in _destroy_id()
2028 kfree(id_priv->id.route.path_rec); in _destroy_id()
2029 kfree(id_priv->id.route.path_rec_inbound); in _destroy_id()
2030 kfree(id_priv->id.route.path_rec_outbound); in _destroy_id()
2032 put_net(id_priv->id.route.addr.dev_addr.net); in _destroy_id()
2037 * destroy an ID from within the handler_mutex. This ensures that no other
2041 __releases(&idprv->handler_mutex) in destroy_id_handler_unlock()
2054 lockdep_assert_held(&id_priv->handler_mutex); in destroy_id_handler_unlock()
2055 spin_lock_irqsave(&id_priv->lock, flags); in destroy_id_handler_unlock()
2056 state = id_priv->state; in destroy_id_handler_unlock()
2057 id_priv->state = RDMA_CM_DESTROYING; in destroy_id_handler_unlock()
2058 spin_unlock_irqrestore(&id_priv->lock, flags); in destroy_id_handler_unlock()
2059 mutex_unlock(&id_priv->handler_mutex); in destroy_id_handler_unlock()
2063 void rdma_destroy_id(struct rdma_cm_id *id) in rdma_destroy_id() argument
2066 container_of(id, struct rdma_id_private, id); in rdma_destroy_id()
2068 mutex_lock(&id_priv->handler_mutex); in rdma_destroy_id()
2086 ret = ib_send_cm_rtu(id_priv->cm_id.ib, NULL, 0); in cma_rep_recv()
2095 ib_send_cm_rej(id_priv->cm_id.ib, IB_CM_REJ_CONSUMER_DEFINED, in cma_rep_recv()
2104 event->param.conn.private_data = private_data; in cma_set_rep_event_data()
2105 event->param.conn.private_data_len = IB_CM_REP_PRIVATE_DATA_SIZE; in cma_set_rep_event_data()
2106 event->param.conn.responder_resources = rep_data->responder_resources; in cma_set_rep_event_data()
2107 event->param.conn.initiator_depth = rep_data->initiator_depth; in cma_set_rep_event_data()
2108 event->param.conn.flow_control = rep_data->flow_control; in cma_set_rep_event_data()
2109 event->param.conn.rnr_retry_count = rep_data->rnr_retry_count; in cma_set_rep_event_data()
2110 event->param.conn.srq = rep_data->srq; in cma_set_rep_event_data()
2111 event->param.conn.qp_num = rep_data->remote_qpn; in cma_set_rep_event_data()
2113 event->ece.vendor_id = rep_data->ece.vendor_id; in cma_set_rep_event_data()
2114 event->ece.attr_mod = rep_data->ece.attr_mod; in cma_set_rep_event_data()
2122 lockdep_assert_held(&id_priv->handler_mutex); in cma_cm_event_handler()
2125 ret = id_priv->id.event_handler(&id_priv->id, event); in cma_cm_event_handler()
2133 struct rdma_id_private *id_priv = cm_id->context; in cma_ib_handler()
2138 mutex_lock(&id_priv->handler_mutex); in cma_ib_handler()
2139 state = READ_ONCE(id_priv->state); in cma_ib_handler()
2140 if ((ib_event->event != IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
2142 (ib_event->event == IB_CM_TIMEWAIT_EXIT && in cma_ib_handler()
2146 switch (ib_event->event) { in cma_ib_handler()
2150 event.status = -ETIMEDOUT; in cma_ib_handler()
2154 (id_priv->id.qp_type != IB_QPT_UD)) { in cma_ib_handler()
2158 if (id_priv->id.qp) { in cma_ib_handler()
2165 cma_set_rep_event_data(&event, &ib_event->param.rep_rcvd, in cma_ib_handler()
2166 ib_event->private_data); in cma_ib_handler()
2173 event.status = -ETIMEDOUT; in cma_ib_handler()
2189 pr_debug_ratelimited("RDMA CM: REJECTED: %s\n", rdma_reject_msg(&id_priv->id, in cma_ib_handler()
2190 ib_event->param.rej_rcvd.reason)); in cma_ib_handler()
2192 event.status = ib_event->param.rej_rcvd.reason; in cma_ib_handler()
2194 event.param.conn.private_data = ib_event->private_data; in cma_ib_handler()
2199 ib_event->event); in cma_ib_handler()
2205 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_handler()
2206 id_priv->cm_id.ib = NULL; in cma_ib_handler()
2211 mutex_unlock(&id_priv->handler_mutex); in cma_ib_handler()
2222 struct rdma_cm_id *id; in cma_ib_new_conn_id() local
2224 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_conn_id()
2225 struct sa_path_rec *path = ib_event->param.req_rcvd.primary_path; in cma_ib_new_conn_id()
2227 ib_event->param.req_rcvd.primary_path->service_id; in cma_ib_new_conn_id()
2230 listen_id_priv = container_of(listen_id, struct rdma_id_private, id); in cma_ib_new_conn_id()
2231 id_priv = __rdma_create_id(listen_id->route.addr.dev_addr.net, in cma_ib_new_conn_id()
2232 listen_id->event_handler, listen_id->context, in cma_ib_new_conn_id()
2233 listen_id->ps, in cma_ib_new_conn_id()
2234 ib_event->param.req_rcvd.qp_type, in cma_ib_new_conn_id()
2239 id = &id_priv->id; in cma_ib_new_conn_id()
2240 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_conn_id()
2241 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_conn_id()
2245 rt = &id->route; in cma_ib_new_conn_id()
2246 rt->num_pri_alt_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; in cma_ib_new_conn_id()
2247 rt->path_rec = kmalloc_array(rt->num_pri_alt_paths, in cma_ib_new_conn_id()
2248 sizeof(*rt->path_rec), GFP_KERNEL); in cma_ib_new_conn_id()
2249 if (!rt->path_rec) in cma_ib_new_conn_id()
2252 rt->path_rec[0] = *path; in cma_ib_new_conn_id()
2253 if (rt->num_pri_alt_paths == 2) in cma_ib_new_conn_id()
2254 rt->path_rec[1] = *ib_event->param.req_rcvd.alternate_path; in cma_ib_new_conn_id()
2257 rdma_copy_src_l2_addr(&rt->addr.dev_addr, net_dev); in cma_ib_new_conn_id()
2261 rt->addr.dev_addr.dev_type = ARPHRD_INFINIBAND; in cma_ib_new_conn_id()
2262 rdma_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid); in cma_ib_new_conn_id()
2263 ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey)); in cma_ib_new_conn_id()
2265 ret = cma_translate_addr(cma_src_addr(id_priv), &rt->addr.dev_addr); in cma_ib_new_conn_id()
2270 rdma_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid); in cma_ib_new_conn_id()
2272 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_conn_id()
2276 rdma_destroy_id(id); in cma_ib_new_conn_id()
2287 struct rdma_cm_id *id; in cma_ib_new_udp_id() local
2288 const sa_family_t ss_family = listen_id->route.addr.src_addr.ss_family; in cma_ib_new_udp_id()
2289 struct net *net = listen_id->route.addr.dev_addr.net; in cma_ib_new_udp_id()
2292 listen_id_priv = container_of(listen_id, struct rdma_id_private, id); in cma_ib_new_udp_id()
2293 id_priv = __rdma_create_id(net, listen_id->event_handler, in cma_ib_new_udp_id()
2294 listen_id->context, listen_id->ps, IB_QPT_UD, in cma_ib_new_udp_id()
2299 id = &id_priv->id; in cma_ib_new_udp_id()
2300 if (cma_save_net_info((struct sockaddr *)&id->route.addr.src_addr, in cma_ib_new_udp_id()
2301 (struct sockaddr *)&id->route.addr.dst_addr, in cma_ib_new_udp_id()
2303 ib_event->param.sidr_req_rcvd.service_id)) in cma_ib_new_udp_id()
2307 rdma_copy_src_l2_addr(&id->route.addr.dev_addr, net_dev); in cma_ib_new_udp_id()
2311 &id->route.addr.dev_addr); in cma_ib_new_udp_id()
2317 id_priv->state = RDMA_CM_CONNECT; in cma_ib_new_udp_id()
2320 rdma_destroy_id(id); in cma_ib_new_udp_id()
2328 event->param.conn.private_data = private_data + offset; in cma_set_req_event_data()
2329 event->param.conn.private_data_len = IB_CM_REQ_PRIVATE_DATA_SIZE - offset; in cma_set_req_event_data()
2330 event->param.conn.responder_resources = req_data->responder_resources; in cma_set_req_event_data()
2331 event->param.conn.initiator_depth = req_data->initiator_depth; in cma_set_req_event_data()
2332 event->param.conn.flow_control = req_data->flow_control; in cma_set_req_event_data()
2333 event->param.conn.retry_count = req_data->retry_count; in cma_set_req_event_data()
2334 event->param.conn.rnr_retry_count = req_data->rnr_retry_count; in cma_set_req_event_data()
2335 event->param.conn.srq = req_data->srq; in cma_set_req_event_data()
2336 event->param.conn.qp_num = req_data->remote_qpn; in cma_set_req_event_data()
2338 event->ece.vendor_id = req_data->ece.vendor_id; in cma_set_req_event_data()
2339 event->ece.attr_mod = req_data->ece.attr_mod; in cma_set_req_event_data()
2342 static int cma_ib_check_req_qp_type(const struct rdma_cm_id *id, in cma_ib_check_req_qp_type() argument
2345 return (((ib_event->event == IB_CM_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2346 (ib_event->param.req_rcvd.qp_type == id->qp_type)) || in cma_ib_check_req_qp_type()
2347 ((ib_event->event == IB_CM_SIDR_REQ_RECEIVED) && in cma_ib_check_req_qp_type()
2348 (id->qp_type == IB_QPT_UD)) || in cma_ib_check_req_qp_type()
2349 (!id->qp_type)); in cma_ib_check_req_qp_type()
2366 trace_cm_req_handler(listen_id, ib_event->event); in cma_ib_req_handler()
2367 if (!cma_ib_check_req_qp_type(&listen_id->id, ib_event)) { in cma_ib_req_handler()
2368 ret = -EINVAL; in cma_ib_req_handler()
2372 mutex_lock(&listen_id->handler_mutex); in cma_ib_req_handler()
2373 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) { in cma_ib_req_handler()
2374 ret = -ECONNABORTED; in cma_ib_req_handler()
2380 if (ib_event->event == IB_CM_SIDR_REQ_RECEIVED) { in cma_ib_req_handler()
2381 conn_id = cma_ib_new_udp_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2382 event.param.ud.private_data = ib_event->private_data + offset; in cma_ib_req_handler()
2384 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE - offset; in cma_ib_req_handler()
2386 conn_id = cma_ib_new_conn_id(&listen_id->id, ib_event, net_dev); in cma_ib_req_handler()
2387 cma_set_req_event_data(&event, &ib_event->param.req_rcvd, in cma_ib_req_handler()
2388 ib_event->private_data, offset); in cma_ib_req_handler()
2391 ret = -ENOMEM; in cma_ib_req_handler()
2395 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in cma_ib_req_handler()
2402 conn_id->cm_id.ib = cm_id; in cma_ib_req_handler()
2403 cm_id->context = conn_id; in cma_ib_req_handler()
2404 cm_id->cm_handler = cma_ib_handler; in cma_ib_req_handler()
2408 /* Destroy the CM ID by returning a non-zero value. */ in cma_ib_req_handler()
2409 conn_id->cm_id.ib = NULL; in cma_ib_req_handler()
2410 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2415 if (READ_ONCE(conn_id->state) == RDMA_CM_CONNECT && in cma_ib_req_handler()
2416 conn_id->id.qp_type != IB_QPT_UD) { in cma_ib_req_handler()
2417 trace_cm_send_mra(cm_id->context); in cma_ib_req_handler()
2420 mutex_unlock(&conn_id->handler_mutex); in cma_ib_req_handler()
2423 mutex_unlock(&listen_id->handler_mutex); in cma_ib_req_handler()
2432 __be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_get_service_id() argument
2434 if (addr->sa_family == AF_IB) in rdma_get_service_id()
2435 return ((struct sockaddr_ib *) addr)->sib_sid; in rdma_get_service_id()
2437 return cpu_to_be64(((u64)id->ps << 16) + be16_to_cpu(cma_port(addr))); in rdma_get_service_id()
2444 struct rdma_addr *addr = &cm_id->route.addr; in rdma_read_gids()
2446 if (!cm_id->device) { in rdma_read_gids()
2454 if (rdma_protocol_roce(cm_id->device, cm_id->port_num)) { in rdma_read_gids()
2456 rdma_ip2gid((struct sockaddr *)&addr->src_addr, sgid); in rdma_read_gids()
2458 rdma_ip2gid((struct sockaddr *)&addr->dst_addr, dgid); in rdma_read_gids()
2461 rdma_addr_get_sgid(&addr->dev_addr, sgid); in rdma_read_gids()
2463 rdma_addr_get_dgid(&addr->dev_addr, dgid); in rdma_read_gids()
2470 struct rdma_id_private *id_priv = iw_id->context; in cma_iw_handler()
2473 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in cma_iw_handler()
2474 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in cma_iw_handler()
2476 mutex_lock(&id_priv->handler_mutex); in cma_iw_handler()
2477 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_iw_handler()
2480 switch (iw_event->event) { in cma_iw_handler()
2489 switch (iw_event->status) { in cma_iw_handler()
2492 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2493 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2495 case -ECONNRESET: in cma_iw_handler()
2496 case -ECONNREFUSED: in cma_iw_handler()
2499 case -ETIMEDOUT: in cma_iw_handler()
2509 event.param.conn.initiator_depth = iw_event->ird; in cma_iw_handler()
2510 event.param.conn.responder_resources = iw_event->ord; in cma_iw_handler()
2516 event.status = iw_event->status; in cma_iw_handler()
2517 event.param.conn.private_data = iw_event->private_data; in cma_iw_handler()
2518 event.param.conn.private_data_len = iw_event->private_data_len; in cma_iw_handler()
2521 /* Destroy the CM ID by returning a non-zero value. */ in cma_iw_handler()
2522 id_priv->cm_id.iw = NULL; in cma_iw_handler()
2528 mutex_unlock(&id_priv->handler_mutex); in cma_iw_handler()
2537 int ret = -ECONNABORTED; in iw_conn_req_handler()
2538 struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr; in iw_conn_req_handler()
2539 struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr; in iw_conn_req_handler()
2542 event.param.conn.private_data = iw_event->private_data; in iw_conn_req_handler()
2543 event.param.conn.private_data_len = iw_event->private_data_len; in iw_conn_req_handler()
2544 event.param.conn.initiator_depth = iw_event->ird; in iw_conn_req_handler()
2545 event.param.conn.responder_resources = iw_event->ord; in iw_conn_req_handler()
2547 listen_id = cm_id->context; in iw_conn_req_handler()
2549 mutex_lock(&listen_id->handler_mutex); in iw_conn_req_handler()
2550 if (READ_ONCE(listen_id->state) != RDMA_CM_LISTEN) in iw_conn_req_handler()
2553 /* Create a new RDMA id for the new IW CM ID */ in iw_conn_req_handler()
2554 conn_id = __rdma_create_id(listen_id->id.route.addr.dev_addr.net, in iw_conn_req_handler()
2555 listen_id->id.event_handler, in iw_conn_req_handler()
2556 listen_id->id.context, RDMA_PS_TCP, in iw_conn_req_handler()
2559 ret = -ENOMEM; in iw_conn_req_handler()
2562 mutex_lock_nested(&conn_id->handler_mutex, SINGLE_DEPTH_NESTING); in iw_conn_req_handler()
2563 conn_id->state = RDMA_CM_CONNECT; in iw_conn_req_handler()
2565 ret = rdma_translate_ip(laddr, &conn_id->id.route.addr.dev_addr); in iw_conn_req_handler()
2567 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2574 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2579 conn_id->cm_id.iw = cm_id; in iw_conn_req_handler()
2580 cm_id->context = conn_id; in iw_conn_req_handler()
2581 cm_id->cm_handler = cma_iw_handler; in iw_conn_req_handler()
2588 /* User wants to destroy the CM ID */ in iw_conn_req_handler()
2589 conn_id->cm_id.iw = NULL; in iw_conn_req_handler()
2590 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2595 mutex_unlock(&conn_id->handler_mutex); in iw_conn_req_handler()
2598 mutex_unlock(&listen_id->handler_mutex); in iw_conn_req_handler()
2605 struct ib_cm_id *id; in cma_ib_listen() local
2609 svc_id = rdma_get_service_id(&id_priv->id, addr); in cma_ib_listen()
2610 id = ib_cm_insert_listen(id_priv->id.device, in cma_ib_listen()
2612 if (IS_ERR(id)) in cma_ib_listen()
2613 return PTR_ERR(id); in cma_ib_listen()
2614 id_priv->cm_id.ib = id; in cma_ib_listen()
2622 struct iw_cm_id *id; in cma_iw_listen() local
2624 id = iw_create_cm_id(id_priv->id.device, in cma_iw_listen()
2627 if (IS_ERR(id)) in cma_iw_listen()
2628 return PTR_ERR(id); in cma_iw_listen()
2630 mutex_lock(&id_priv->qp_mutex); in cma_iw_listen()
2631 id->tos = id_priv->tos; in cma_iw_listen()
2632 id->tos_set = id_priv->tos_set; in cma_iw_listen()
2633 mutex_unlock(&id_priv->qp_mutex); in cma_iw_listen()
2634 id->afonly = id_priv->afonly; in cma_iw_listen()
2635 id_priv->cm_id.iw = id; in cma_iw_listen()
2637 memcpy(&id_priv->cm_id.iw->local_addr, cma_src_addr(id_priv), in cma_iw_listen()
2640 ret = iw_cm_listen(id_priv->cm_id.iw, backlog); in cma_iw_listen()
2643 iw_destroy_cm_id(id_priv->cm_id.iw); in cma_iw_listen()
2644 id_priv->cm_id.iw = NULL; in cma_iw_listen()
2650 static int cma_listen_handler(struct rdma_cm_id *id, in cma_listen_handler() argument
2653 struct rdma_id_private *id_priv = id->context; in cma_listen_handler()
2656 if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) in cma_listen_handler()
2657 return -1; in cma_listen_handler()
2659 id->context = id_priv->id.context; in cma_listen_handler()
2660 id->event_handler = id_priv->id.event_handler; in cma_listen_handler()
2662 return id_priv->id.event_handler(id, event); in cma_listen_handler()
2670 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_listen_on_dev()
2676 if (cma_family(id_priv) == AF_IB && !rdma_cap_ib_cm(cma_dev->device, 1)) in cma_listen_on_dev()
2681 id_priv->id.ps, id_priv->id.qp_type, id_priv); in cma_listen_on_dev()
2685 dev_id_priv->state = RDMA_CM_ADDR_BOUND; in cma_listen_on_dev()
2690 rdma_restrack_add(&dev_id_priv->res); in cma_listen_on_dev()
2692 dev_id_priv->internal_id = 1; in cma_listen_on_dev()
2693 dev_id_priv->afonly = id_priv->afonly; in cma_listen_on_dev()
2694 mutex_lock(&id_priv->qp_mutex); in cma_listen_on_dev()
2695 dev_id_priv->tos_set = id_priv->tos_set; in cma_listen_on_dev()
2696 dev_id_priv->tos = id_priv->tos; in cma_listen_on_dev()
2697 mutex_unlock(&id_priv->qp_mutex); in cma_listen_on_dev()
2699 ret = rdma_listen(&dev_id_priv->id, id_priv->backlog); in cma_listen_on_dev()
2702 list_add_tail(&dev_id_priv->listen_item, &id_priv->listen_list); in cma_listen_on_dev()
2707 dev_warn(&cma_dev->device->dev, "RDMA CMA: %s, error %d\n", __func__, ret); in cma_listen_on_dev()
2718 list_add_tail(&id_priv->listen_any_item, &listen_any_list); in cma_listen_on_all()
2724 list_del_init(&to_destroy->device_item); in cma_listen_on_all()
2735 rdma_destroy_id(&to_destroy->id); in cma_listen_on_all()
2739 void rdma_set_service_type(struct rdma_cm_id *id, int tos) in rdma_set_service_type() argument
2743 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_service_type()
2744 mutex_lock(&id_priv->qp_mutex); in rdma_set_service_type()
2745 id_priv->tos = (u8) tos; in rdma_set_service_type()
2746 id_priv->tos_set = true; in rdma_set_service_type()
2747 mutex_unlock(&id_priv->qp_mutex); in rdma_set_service_type()
2752 * rdma_set_ack_timeout() - Set the ack timeout of QP associated
2754 * @id: Communication identifier to associated with service type.
2766 int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout) in rdma_set_ack_timeout() argument
2770 if (id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_INI) in rdma_set_ack_timeout()
2771 return -EINVAL; in rdma_set_ack_timeout()
2773 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_ack_timeout()
2774 mutex_lock(&id_priv->qp_mutex); in rdma_set_ack_timeout()
2775 id_priv->timeout = timeout; in rdma_set_ack_timeout()
2776 id_priv->timeout_set = true; in rdma_set_ack_timeout()
2777 mutex_unlock(&id_priv->qp_mutex); in rdma_set_ack_timeout()
2784 * rdma_set_min_rnr_timer() - Set the minimum RNR Retry timer of the
2786 * @id: Communication identifier to associated with service type.
2787 * @min_rnr_timer: 5-bit value encoded as Table 45: "Encoding for RNR NAK
2801 int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer) in rdma_set_min_rnr_timer() argument
2805 /* It is a five-bit value */ in rdma_set_min_rnr_timer()
2807 return -EINVAL; in rdma_set_min_rnr_timer()
2809 if (WARN_ON(id->qp_type != IB_QPT_RC && id->qp_type != IB_QPT_XRC_TGT)) in rdma_set_min_rnr_timer()
2810 return -EINVAL; in rdma_set_min_rnr_timer()
2812 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_min_rnr_timer()
2813 mutex_lock(&id_priv->qp_mutex); in rdma_set_min_rnr_timer()
2814 id_priv->min_rnr_timer = min_rnr_timer; in rdma_set_min_rnr_timer()
2815 id_priv->min_rnr_timer_set = true; in rdma_set_min_rnr_timer()
2816 mutex_unlock(&id_priv->qp_mutex); in rdma_set_min_rnr_timer()
2825 struct rdma_route *route = &work->id->id.route; in route_set_path_rec_inbound()
2827 if (!route->path_rec_inbound) { in route_set_path_rec_inbound()
2828 route->path_rec_inbound = in route_set_path_rec_inbound()
2829 kzalloc(sizeof(*route->path_rec_inbound), GFP_KERNEL); in route_set_path_rec_inbound()
2830 if (!route->path_rec_inbound) in route_set_path_rec_inbound()
2834 *route->path_rec_inbound = *path_rec; in route_set_path_rec_inbound()
2840 struct rdma_route *route = &work->id->id.route; in route_set_path_rec_outbound()
2842 if (!route->path_rec_outbound) { in route_set_path_rec_outbound()
2843 route->path_rec_outbound = in route_set_path_rec_outbound()
2844 kzalloc(sizeof(*route->path_rec_outbound), GFP_KERNEL); in route_set_path_rec_outbound()
2845 if (!route->path_rec_outbound) in route_set_path_rec_outbound()
2849 *route->path_rec_outbound = *path_rec; in route_set_path_rec_outbound()
2859 route = &work->id->id.route; in cma_query_handler()
2866 *route->path_rec = path_rec[i]; in cma_query_handler()
2872 if (!route->path_rec) { in cma_query_handler()
2873 status = -EINVAL; in cma_query_handler()
2877 route->num_pri_alt_paths = 1; in cma_query_handler()
2878 queue_work(cma_wq, &work->work); in cma_query_handler()
2882 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_query_handler()
2883 work->new_state = RDMA_CM_ADDR_RESOLVED; in cma_query_handler()
2884 work->event.event = RDMA_CM_EVENT_ROUTE_ERROR; in cma_query_handler()
2885 work->event.status = status; in cma_query_handler()
2888 queue_work(cma_wq, &work->work); in cma_query_handler()
2894 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_query_ib_route()
2902 if (rdma_cap_opa_ah(id_priv->id.device, id_priv->id.port_num)) in cma_query_ib_route()
2911 path_rec.service_id = rdma_get_service_id(&id_priv->id, in cma_query_ib_route()
2920 path_rec.qos_class = cpu_to_be16((u16) id_priv->tos); in cma_query_ib_route()
2925 path_rec.traffic_class = (u8) (be32_to_cpu(sin6->sin6_flowinfo) >> 20); in cma_query_ib_route()
2930 path_rec.traffic_class = (u8) (be32_to_cpu(sib->sib_flowinfo) >> 20); in cma_query_ib_route()
2935 id_priv->query_id = ib_sa_path_rec_get(&sa_client, id_priv->id.device, in cma_query_ib_route()
2936 id_priv->id.port_num, &path_rec, in cma_query_ib_route()
2939 work, &id_priv->query); in cma_query_ib_route()
2941 return (id_priv->query_id < 0) ? id_priv->query_id : 0; in cma_query_ib_route()
2948 struct rdma_cm_event *event = &mc->iboe_join.event; in cma_iboe_join_work_handler()
2949 struct rdma_id_private *id_priv = mc->id_priv; in cma_iboe_join_work_handler()
2952 mutex_lock(&id_priv->handler_mutex); in cma_iboe_join_work_handler()
2953 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_iboe_join_work_handler()
2954 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_iboe_join_work_handler()
2961 mutex_unlock(&id_priv->handler_mutex); in cma_iboe_join_work_handler()
2962 if (event->event == RDMA_CM_EVENT_MULTICAST_JOIN) in cma_iboe_join_work_handler()
2963 rdma_destroy_ah_attr(&event->param.ud.ah_attr); in cma_iboe_join_work_handler()
2969 struct rdma_id_private *id_priv = work->id; in cma_work_handler()
2971 mutex_lock(&id_priv->handler_mutex); in cma_work_handler()
2972 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_work_handler()
2973 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_work_handler()
2975 if (work->old_state != 0 || work->new_state != 0) { in cma_work_handler()
2976 if (!cma_comp_exch(id_priv, work->old_state, work->new_state)) in cma_work_handler()
2980 if (cma_cm_event_handler(id_priv, &work->event)) { in cma_work_handler()
2987 mutex_unlock(&id_priv->handler_mutex); in cma_work_handler()
2990 if (work->event.event == RDMA_CM_EVENT_MULTICAST_JOIN) in cma_work_handler()
2991 rdma_destroy_ah_attr(&work->event.param.ud.ah_attr); in cma_work_handler()
2998 work->id = id_priv; in cma_init_resolve_route_work()
2999 INIT_WORK(&work->work, cma_work_handler); in cma_init_resolve_route_work()
3000 work->old_state = RDMA_CM_ROUTE_QUERY; in cma_init_resolve_route_work()
3001 work->new_state = RDMA_CM_ROUTE_RESOLVED; in cma_init_resolve_route_work()
3002 work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED; in cma_init_resolve_route_work()
3011 work->id = id_priv; in enqueue_resolve_addr_work()
3012 INIT_WORK(&work->work, cma_work_handler); in enqueue_resolve_addr_work()
3013 work->old_state = RDMA_CM_ADDR_QUERY; in enqueue_resolve_addr_work()
3014 work->new_state = RDMA_CM_ADDR_RESOLVED; in enqueue_resolve_addr_work()
3015 work->event.event = RDMA_CM_EVENT_ADDR_RESOLVED; in enqueue_resolve_addr_work()
3017 queue_work(cma_wq, &work->work); in enqueue_resolve_addr_work()
3023 struct rdma_route *route = &id_priv->id.route; in cma_resolve_ib_route()
3029 return -ENOMEM; in cma_resolve_ib_route()
3033 if (!route->path_rec) in cma_resolve_ib_route()
3034 route->path_rec = kmalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_ib_route()
3035 if (!route->path_rec) { in cma_resolve_ib_route()
3036 ret = -ENOMEM; in cma_resolve_ib_route()
3046 kfree(route->path_rec); in cma_resolve_ib_route()
3047 route->path_rec = NULL; in cma_resolve_ib_route()
3075 struct rdma_route *route = &id_priv->id.route; in cma_iboe_set_path_rec_l2_fields()
3077 struct rdma_addr *addr = &route->addr; in cma_iboe_set_path_rec_l2_fields()
3081 if (!addr->dev_addr.bound_dev_if) in cma_iboe_set_path_rec_l2_fields()
3084 ndev = dev_get_by_index(addr->dev_addr.net, in cma_iboe_set_path_rec_l2_fields()
3085 addr->dev_addr.bound_dev_if); in cma_iboe_set_path_rec_l2_fields()
3089 supported_gids = roce_gid_type_mask_support(id_priv->id.device, in cma_iboe_set_path_rec_l2_fields()
3090 id_priv->id.port_num); in cma_iboe_set_path_rec_l2_fields()
3091 gid_type = cma_route_gid_type(addr->dev_addr.network, in cma_iboe_set_path_rec_l2_fields()
3093 id_priv->gid_type); in cma_iboe_set_path_rec_l2_fields()
3095 if (gid_type < ib_network_to_gid_type(addr->dev_addr.network)) in cma_iboe_set_path_rec_l2_fields()
3096 gid_type = ib_network_to_gid_type(addr->dev_addr.network); in cma_iboe_set_path_rec_l2_fields()
3097 route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type); in cma_iboe_set_path_rec_l2_fields()
3099 route->path_rec->roce.route_resolved = true; in cma_iboe_set_path_rec_l2_fields()
3100 sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr); in cma_iboe_set_path_rec_l2_fields()
3104 int rdma_set_ib_path(struct rdma_cm_id *id, in rdma_set_ib_path() argument
3111 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_ib_path()
3114 return -EINVAL; in rdma_set_ib_path()
3116 id->route.path_rec = kmemdup(path_rec, sizeof(*path_rec), in rdma_set_ib_path()
3118 if (!id->route.path_rec) { in rdma_set_ib_path()
3119 ret = -ENOMEM; in rdma_set_ib_path()
3123 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_set_ib_path()
3126 ret = -ENODEV; in rdma_set_ib_path()
3132 id->route.num_pri_alt_paths = 1; in rdma_set_ib_path()
3136 kfree(id->route.path_rec); in rdma_set_ib_path()
3137 id->route.path_rec = NULL; in rdma_set_ib_path()
3150 return -ENOMEM; in cma_resolve_iw_route()
3153 queue_work(cma_wq, &work->work); in cma_resolve_iw_route()
3162 if (dev->num_tc) in get_vlan_ndev_tc()
3178 struct iboe_prio_tc_map *map = (struct iboe_prio_tc_map *)priv->data; in get_lower_vlan_dev_tc()
3181 map->output_tc = get_vlan_ndev_tc(dev, map->input_prio); in get_lower_vlan_dev_tc()
3182 else if (dev->num_tc) in get_lower_vlan_dev_tc()
3183 map->output_tc = netdev_get_prio_tc_map(dev, map->input_prio); in get_lower_vlan_dev_tc()
3185 map->output_tc = 0; in get_lower_vlan_dev_tc()
3186 /* We are interested only in first level VLAN device, so always in get_lower_vlan_dev_tc()
3189 map->found = true; in get_lower_vlan_dev_tc()
3199 /* If VLAN device, get it directly from the VLAN netdev */ in iboe_tos_to_sl()
3210 /* If map is found from lower device, use it; Otherwise in iboe_tos_to_sl()
3215 else if (ndev->num_tc) in iboe_tos_to_sl()
3228 fl = be32_to_cpu(addr6->sin6_flowinfo) & IB_GRH_FLOWLABEL_MASK; in cma_get_roce_udp_flow_label()
3241 struct rdma_route *route = &id_priv->id.route; in cma_resolve_iboe_route()
3242 struct rdma_addr *addr = &route->addr; in cma_resolve_iboe_route()
3247 u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - in cma_resolve_iboe_route()
3248 rdma_start_port(id_priv->cma_dev->device)]; in cma_resolve_iboe_route()
3251 mutex_lock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3252 tos = id_priv->tos_set ? id_priv->tos : default_roce_tos; in cma_resolve_iboe_route()
3253 mutex_unlock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3257 return -ENOMEM; in cma_resolve_iboe_route()
3259 route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL); in cma_resolve_iboe_route()
3260 if (!route->path_rec) { in cma_resolve_iboe_route()
3261 ret = -ENOMEM; in cma_resolve_iboe_route()
3265 route->num_pri_alt_paths = 1; in cma_resolve_iboe_route()
3269 ret = -ENODEV; in cma_resolve_iboe_route()
3273 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_resolve_iboe_route()
3274 &route->path_rec->sgid); in cma_resolve_iboe_route()
3275 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, in cma_resolve_iboe_route()
3276 &route->path_rec->dgid); in cma_resolve_iboe_route()
3278 if (((struct sockaddr *)&id_priv->id.route.addr.dst_addr)->sa_family != AF_IB) in cma_resolve_iboe_route()
3279 /* TODO: get the hoplimit from the inet/inet6 device */ in cma_resolve_iboe_route()
3280 route->path_rec->hop_limit = addr->dev_addr.hoplimit; in cma_resolve_iboe_route()
3282 route->path_rec->hop_limit = 1; in cma_resolve_iboe_route()
3283 route->path_rec->reversible = 1; in cma_resolve_iboe_route()
3284 route->path_rec->pkey = cpu_to_be16(0xffff); in cma_resolve_iboe_route()
3285 route->path_rec->mtu_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3286 route->path_rec->sl = iboe_tos_to_sl(ndev, tos); in cma_resolve_iboe_route()
3287 route->path_rec->traffic_class = tos; in cma_resolve_iboe_route()
3288 route->path_rec->mtu = iboe_get_mtu(ndev->mtu); in cma_resolve_iboe_route()
3289 route->path_rec->rate_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3290 route->path_rec->rate = iboe_get_rate(ndev); in cma_resolve_iboe_route()
3292 route->path_rec->packet_life_time_selector = IB_SA_EQ; in cma_resolve_iboe_route()
3300 mutex_lock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3301 if (id_priv->timeout_set && id_priv->timeout) in cma_resolve_iboe_route()
3302 route->path_rec->packet_life_time = id_priv->timeout - 1; in cma_resolve_iboe_route()
3304 route->path_rec->packet_life_time = CMA_IBOE_PACKET_LIFETIME; in cma_resolve_iboe_route()
3305 mutex_unlock(&id_priv->qp_mutex); in cma_resolve_iboe_route()
3307 if (!route->path_rec->mtu) { in cma_resolve_iboe_route()
3308 ret = -EINVAL; in cma_resolve_iboe_route()
3312 if (rdma_protocol_roce_udp_encap(id_priv->id.device, in cma_resolve_iboe_route()
3313 id_priv->id.port_num)) in cma_resolve_iboe_route()
3314 route->path_rec->flow_label = in cma_resolve_iboe_route()
3318 queue_work(cma_wq, &work->work); in cma_resolve_iboe_route()
3323 kfree(route->path_rec); in cma_resolve_iboe_route()
3324 route->path_rec = NULL; in cma_resolve_iboe_route()
3325 route->num_pri_alt_paths = 0; in cma_resolve_iboe_route()
3331 int rdma_resolve_route(struct rdma_cm_id *id, unsigned long timeout_ms) in rdma_resolve_route() argument
3337 return -EINVAL; in rdma_resolve_route()
3339 id_priv = container_of(id, struct rdma_id_private, id); in rdma_resolve_route()
3341 return -EINVAL; in rdma_resolve_route()
3344 if (rdma_cap_ib_sa(id->device, id->port_num)) in rdma_resolve_route()
3346 else if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_resolve_route()
3351 else if (rdma_protocol_iwarp(id->device, id->port_num)) in rdma_resolve_route()
3354 ret = -ENOSYS; in rdma_resolve_route()
3369 switch (addr->sa_family) { in cma_set_loopback()
3371 ((struct sockaddr_in *) addr)->sin_addr.s_addr = htonl(INADDR_LOOPBACK); in cma_set_loopback()
3374 ipv6_addr_set(&((struct sockaddr_in6 *) addr)->sin6_addr, in cma_set_loopback()
3378 ib_addr_set(&((struct sockaddr_ib *) addr)->sib_addr, in cma_set_loopback()
3397 !rdma_cap_ib_cm(cur_dev->device, 1)) in cma_bind_loopback()
3403 rdma_for_each_port (cur_dev->device, p) { in cma_bind_loopback()
3404 if (!ib_get_cached_port_state(cur_dev->device, p, &port_state) && in cma_bind_loopback()
3413 ret = -ENODEV; in cma_bind_loopback()
3420 ret = rdma_query_gid(cma_dev->device, p, 0, &gid); in cma_bind_loopback()
3424 ret = ib_get_cached_pkey(cma_dev->device, p, 0, &pkey); in cma_bind_loopback()
3428 id_priv->id.route.addr.dev_addr.dev_type = in cma_bind_loopback()
3429 (rdma_protocol_ib(cma_dev->device, p)) ? in cma_bind_loopback()
3432 rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_bind_loopback()
3433 ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); in cma_bind_loopback()
3434 id_priv->id.port_num = p; in cma_bind_loopback()
3436 rdma_restrack_add(&id_priv->res); in cma_bind_loopback()
3451 mutex_lock(&id_priv->handler_mutex); in addr_handler()
3458 * matching rdma device, old address can be restored back, which helps in addr_handler()
3464 if (!status && !id_priv->cma_dev) { in addr_handler()
3467 pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n", in addr_handler()
3469 rdma_restrack_add(&id_priv->res); in addr_handler()
3490 mutex_unlock(&id_priv->handler_mutex); in addr_handler()
3501 return -ENOMEM; in cma_resolve_loopback()
3503 if (!id_priv->cma_dev) { in cma_resolve_loopback()
3509 rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3510 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); in cma_resolve_loopback()
3526 return -ENOMEM; in cma_resolve_ib_addr()
3528 if (!id_priv->cma_dev) { in cma_resolve_ib_addr()
3534 rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) in cma_resolve_ib_addr()
3535 &(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); in cma_resolve_ib_addr()
3544 static int cma_bind_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, in cma_bind_addr() argument
3549 if (src_addr && src_addr->sa_family) in cma_bind_addr()
3550 return rdma_bind_addr(id, src_addr); in cma_bind_addr()
3555 zero_sock.ss_family = dst_addr->sa_family; in cma_bind_addr()
3556 if (IS_ENABLED(CONFIG_IPV6) && dst_addr->sa_family == AF_INET6) { in cma_bind_addr()
3562 src_addr6->sin6_scope_id = dst_addr6->sin6_scope_id; in cma_bind_addr()
3563 if (ipv6_addr_type(&dst_addr6->sin6_addr) & IPV6_ADDR_LINKLOCAL) in cma_bind_addr()
3564 id->route.addr.dev_addr.bound_dev_if = in cma_bind_addr()
3565 dst_addr6->sin6_scope_id; in cma_bind_addr()
3566 } else if (dst_addr->sa_family == AF_IB) { in cma_bind_addr()
3567 ((struct sockaddr_ib *)&zero_sock)->sib_pkey = in cma_bind_addr()
3568 ((struct sockaddr_ib *)dst_addr)->sib_pkey; in cma_bind_addr()
3570 return rdma_bind_addr(id, (struct sockaddr *)&zero_sock); in cma_bind_addr()
3576 * calls made by ULP, a previously bound ID will not be re-bound and src_addr is
3588 ret = cma_bind_addr(&id_priv->id, src_addr, dst_addr); in resolve_prepare_src()
3593 ret = -EINVAL; in resolve_prepare_src()
3598 if (cma_family(id_priv) != dst_addr->sa_family) { in resolve_prepare_src()
3599 ret = -EINVAL; in resolve_prepare_src()
3611 int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, in rdma_resolve_addr() argument
3615 container_of(id, struct rdma_id_private, id); in rdma_resolve_addr()
3625 if (dst_addr->sa_family == AF_IB) { in rdma_resolve_addr()
3639 if (id_priv->used_resolve_ip) in rdma_resolve_addr()
3640 rdma_addr_cancel(&id->route.addr.dev_addr); in rdma_resolve_addr()
3642 id_priv->used_resolve_ip = 1; in rdma_resolve_addr()
3644 &id->route.addr.dev_addr, in rdma_resolve_addr()
3659 int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse) in rdma_set_reuseaddr() argument
3665 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_reuseaddr()
3666 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_reuseaddr()
3667 if ((reuse && id_priv->state != RDMA_CM_LISTEN) || in rdma_set_reuseaddr()
3668 id_priv->state == RDMA_CM_IDLE) { in rdma_set_reuseaddr()
3669 id_priv->reuseaddr = reuse; in rdma_set_reuseaddr()
3672 ret = -EINVAL; in rdma_set_reuseaddr()
3674 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_reuseaddr()
3679 int rdma_set_afonly(struct rdma_cm_id *id, int afonly) in rdma_set_afonly() argument
3685 id_priv = container_of(id, struct rdma_id_private, id); in rdma_set_afonly()
3686 spin_lock_irqsave(&id_priv->lock, flags); in rdma_set_afonly()
3687 if (id_priv->state == RDMA_CM_IDLE || id_priv->state == RDMA_CM_ADDR_BOUND) { in rdma_set_afonly()
3688 id_priv->options |= (1 << CMA_OPTION_AFONLY); in rdma_set_afonly()
3689 id_priv->afonly = afonly; in rdma_set_afonly()
3692 ret = -EINVAL; in rdma_set_afonly()
3694 spin_unlock_irqrestore(&id_priv->lock, flags); in rdma_set_afonly()
3710 port = htons(bind_list->port); in cma_bind_port()
3712 switch (addr->sa_family) { in cma_bind_port()
3714 ((struct sockaddr_in *) addr)->sin_port = port; in cma_bind_port()
3717 ((struct sockaddr_in6 *) addr)->sin6_port = port; in cma_bind_port()
3721 sid = be64_to_cpu(sib->sib_sid); in cma_bind_port()
3722 mask = be64_to_cpu(sib->sib_sid_mask); in cma_bind_port()
3723 sib->sib_sid = cpu_to_be64((sid & mask) | (u64) ntohs(port)); in cma_bind_port()
3724 sib->sib_sid_mask = cpu_to_be64(~0ULL); in cma_bind_port()
3727 id_priv->bind_list = bind_list; in cma_bind_port()
3728 hlist_add_head(&id_priv->node, &bind_list->owners); in cma_bind_port()
3741 return -ENOMEM; in cma_alloc_port()
3743 ret = cma_ps_alloc(id_priv->id.route.addr.dev_addr.net, ps, bind_list, in cma_alloc_port()
3748 bind_list->ps = ps; in cma_alloc_port()
3749 bind_list->port = snum; in cma_alloc_port()
3754 return ret == -ENOSPC ? -EADDRNOTAVAIL : ret; in cma_alloc_port()
3767 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_port_is_unique()
3775 /* different dest port -> unique */ in cma_port_is_unique()
3781 /* different src address -> unique */ in cma_port_is_unique()
3787 /* different dst address -> unique */ in cma_port_is_unique()
3793 return -EADDRNOTAVAIL; in cma_port_is_unique()
3804 struct net *net = id_priv->id.route.addr.dev_addr.net; in cma_alloc_any_port()
3809 remaining = (high - low) + 1; in cma_alloc_any_port()
3827 * re-using same port immediately after it is closed. in cma_alloc_any_port()
3831 if (ret != -EADDRNOTAVAIL) in cma_alloc_any_port()
3834 if (--remaining) { in cma_alloc_any_port()
3840 return -EADDRNOTAVAIL; in cma_alloc_any_port()
3858 hlist_for_each_entry(cur_id, &bind_list->owners, node) { in cma_check_port()
3862 if (reuseaddr && cur_id->reuseaddr) in cma_check_port()
3866 if (id_priv->afonly && cur_id->afonly && in cma_check_port()
3867 (addr->sa_family != cur_addr->sa_family)) in cma_check_port()
3871 return -EADDRNOTAVAIL; in cma_check_port()
3874 return -EADDRINUSE; in cma_check_port()
3890 return -EACCES; in cma_use_port()
3892 bind_list = cma_ps_find(id_priv->id.route.addr.dev_addr.net, ps, snum); in cma_use_port()
3896 ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); in cma_use_port()
3906 switch (id_priv->id.ps) { in cma_select_inet_ps()
3911 return id_priv->id.ps; in cma_select_inet_ps()
3926 mask = be64_to_cpu(sib->sib_sid_mask) & RDMA_IB_IP_PS_MASK; in cma_select_ib_ps()
3927 sid = be64_to_cpu(sib->sib_sid) & mask; in cma_select_ib_ps()
3929 if ((id_priv->id.ps == RDMA_PS_IB) && (sid == (RDMA_IB_IP_PS_IB & mask))) { in cma_select_ib_ps()
3932 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_TCP)) && in cma_select_ib_ps()
3936 } else if (((id_priv->id.ps == RDMA_PS_IB) || (id_priv->id.ps == RDMA_PS_UDP)) && in cma_select_ib_ps()
3943 sib->sib_sid = cpu_to_be64(sid_ps | ntohs(cma_port((struct sockaddr *) sib))); in cma_select_ib_ps()
3944 sib->sib_sid_mask = cpu_to_be64(RDMA_IB_IP_PS_MASK | in cma_select_ib_ps()
3945 be64_to_cpu(sib->sib_sid_mask)); in cma_select_ib_ps()
3960 return -EPROTONOSUPPORT; in cma_get_port()
3978 if (addr->sa_family != AF_INET6) in cma_check_linklocal()
3983 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) in cma_check_linklocal()
3986 if (!sin6->sin6_scope_id) in cma_check_linklocal()
3987 return -EINVAL; in cma_check_linklocal()
3989 dev_addr->bound_dev_if = sin6->sin6_scope_id; in cma_check_linklocal()
3994 int rdma_listen(struct rdma_cm_id *id, int backlog) in rdma_listen() argument
3997 container_of(id, struct rdma_id_private, id); in rdma_listen()
4007 ret = rdma_bind_addr(id, (struct sockaddr *)&any_in); in rdma_listen()
4012 return -EINVAL; in rdma_listen()
4016 * Once the ID reaches RDMA_CM_LISTEN it is not allowed to be reusable in rdma_listen()
4019 if (id_priv->reuseaddr) { in rdma_listen()
4021 ret = cma_check_port(id_priv->bind_list, id_priv, 0); in rdma_listen()
4023 id_priv->reuseaddr = 0; in rdma_listen()
4029 id_priv->backlog = backlog; in rdma_listen()
4030 if (id_priv->cma_dev) { in rdma_listen()
4031 if (rdma_cap_ib_cm(id->device, 1)) { in rdma_listen()
4035 } else if (rdma_cap_iw_cm(id->device, 1)) { in rdma_listen()
4040 ret = -ENOSYS; in rdma_listen()
4051 id_priv->backlog = 0; in rdma_listen()
4061 int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_bind_addr() argument
4067 if (addr->sa_family != AF_INET && addr->sa_family != AF_INET6 && in rdma_bind_addr()
4068 addr->sa_family != AF_IB) in rdma_bind_addr()
4069 return -EAFNOSUPPORT; in rdma_bind_addr()
4071 id_priv = container_of(id, struct rdma_id_private, id); in rdma_bind_addr()
4073 return -EINVAL; in rdma_bind_addr()
4075 ret = cma_check_linklocal(&id->route.addr.dev_addr, addr); in rdma_bind_addr()
4081 ret = cma_translate_addr(addr, &id->route.addr.dev_addr); in rdma_bind_addr()
4090 if (!(id_priv->options & (1 << CMA_OPTION_AFONLY))) { in rdma_bind_addr()
4091 if (addr->sa_family == AF_INET) in rdma_bind_addr()
4092 id_priv->afonly = 1; in rdma_bind_addr()
4094 else if (addr->sa_family == AF_INET6) { in rdma_bind_addr()
4095 struct net *net = id_priv->id.route.addr.dev_addr.net; in rdma_bind_addr()
4097 id_priv->afonly = net->ipv6.sysctl.bindv6only; in rdma_bind_addr()
4102 daddr->sa_family = addr->sa_family; in rdma_bind_addr()
4109 rdma_restrack_add(&id_priv->res); in rdma_bind_addr()
4112 if (id_priv->cma_dev) in rdma_bind_addr()
4125 cma_hdr->cma_version = CMA_VERSION; in cma_format_hdr()
4133 cma_hdr->src_addr.ip4.addr = src4->sin_addr.s_addr; in cma_format_hdr()
4134 cma_hdr->dst_addr.ip4.addr = dst4->sin_addr.s_addr; in cma_format_hdr()
4135 cma_hdr->port = src4->sin_port; in cma_format_hdr()
4143 cma_hdr->src_addr.ip6 = src6->sin6_addr; in cma_format_hdr()
4144 cma_hdr->dst_addr.ip6 = dst6->sin6_addr; in cma_format_hdr()
4145 cma_hdr->port = src6->sin6_port; in cma_format_hdr()
4153 struct rdma_id_private *id_priv = cm_id->context; in cma_sidr_rep_handler()
4156 &ib_event->param.sidr_rep_rcvd; in cma_sidr_rep_handler()
4159 mutex_lock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
4160 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in cma_sidr_rep_handler()
4163 switch (ib_event->event) { in cma_sidr_rep_handler()
4166 event.status = -ETIMEDOUT; in cma_sidr_rep_handler()
4169 event.param.ud.private_data = ib_event->private_data; in cma_sidr_rep_handler()
4171 if (rep->status != IB_SIDR_SUCCESS) { in cma_sidr_rep_handler()
4173 event.status = ib_event->param.sidr_rep_rcvd.status; in cma_sidr_rep_handler()
4178 ret = cma_set_qkey(id_priv, rep->qkey); in cma_sidr_rep_handler()
4185 ib_init_ah_attr_from_path(id_priv->id.device, in cma_sidr_rep_handler()
4186 id_priv->id.port_num, in cma_sidr_rep_handler()
4187 id_priv->id.route.path_rec, in cma_sidr_rep_handler()
4189 rep->sgid_attr); in cma_sidr_rep_handler()
4190 event.param.ud.qp_num = rep->qpn; in cma_sidr_rep_handler()
4191 event.param.ud.qkey = rep->qkey; in cma_sidr_rep_handler()
4197 ib_event->event); in cma_sidr_rep_handler()
4205 /* Destroy the CM ID by returning a non-zero value. */ in cma_sidr_rep_handler()
4206 id_priv->cm_id.ib = NULL; in cma_sidr_rep_handler()
4211 mutex_unlock(&id_priv->handler_mutex); in cma_sidr_rep_handler()
4219 struct ib_cm_id *id; in cma_resolve_ib_udp() local
4226 if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) in cma_resolve_ib_udp()
4227 return -EINVAL; in cma_resolve_ib_udp()
4232 return -ENOMEM; in cma_resolve_ib_udp()
4237 if (conn_param->private_data && conn_param->private_data_len) in cma_resolve_ib_udp()
4238 memcpy(private_data + offset, conn_param->private_data, in cma_resolve_ib_udp()
4239 conn_param->private_data_len); in cma_resolve_ib_udp()
4248 id = ib_create_cm_id(id_priv->id.device, cma_sidr_rep_handler, in cma_resolve_ib_udp()
4250 if (IS_ERR(id)) { in cma_resolve_ib_udp()
4251 ret = PTR_ERR(id); in cma_resolve_ib_udp()
4254 id_priv->cm_id.ib = id; in cma_resolve_ib_udp()
4256 req.path = id_priv->id.route.path_rec; in cma_resolve_ib_udp()
4257 req.sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_resolve_ib_udp()
4258 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_resolve_ib_udp()
4259 req.timeout_ms = 1 << (CMA_CM_RESPONSE_TIMEOUT - 8); in cma_resolve_ib_udp()
4263 ret = ib_send_cm_sidr_req(id_priv->cm_id.ib, &req); in cma_resolve_ib_udp()
4265 ib_destroy_cm_id(id_priv->cm_id.ib); in cma_resolve_ib_udp()
4266 id_priv->cm_id.ib = NULL; in cma_resolve_ib_udp()
4279 struct ib_cm_id *id; in cma_connect_ib() local
4285 if (check_add_overflow(offset, conn_param->private_data_len, &req.private_data_len)) in cma_connect_ib()
4286 return -EINVAL; in cma_connect_ib()
4291 return -ENOMEM; in cma_connect_ib()
4296 if (conn_param->private_data && conn_param->private_data_len) in cma_connect_ib()
4297 memcpy(private_data + offset, conn_param->private_data, in cma_connect_ib()
4298 conn_param->private_data_len); in cma_connect_ib()
4300 id = ib_create_cm_id(id_priv->id.device, cma_ib_handler, id_priv); in cma_connect_ib()
4301 if (IS_ERR(id)) { in cma_connect_ib()
4302 ret = PTR_ERR(id); in cma_connect_ib()
4305 id_priv->cm_id.ib = id; in cma_connect_ib()
4307 route = &id_priv->id.route; in cma_connect_ib()
4315 req.primary_path = &route->path_rec[0]; in cma_connect_ib()
4316 req.primary_path_inbound = route->path_rec_inbound; in cma_connect_ib()
4317 req.primary_path_outbound = route->path_rec_outbound; in cma_connect_ib()
4318 if (route->num_pri_alt_paths == 2) in cma_connect_ib()
4319 req.alternate_path = &route->path_rec[1]; in cma_connect_ib()
4321 req.ppath_sgid_attr = id_priv->id.route.addr.dev_addr.sgid_attr; in cma_connect_ib()
4323 req.service_id = rdma_get_service_id(&id_priv->id, cma_dst_addr(id_priv)); in cma_connect_ib()
4324 req.qp_num = id_priv->qp_num; in cma_connect_ib()
4325 req.qp_type = id_priv->id.qp_type; in cma_connect_ib()
4326 req.starting_psn = id_priv->seq_num; in cma_connect_ib()
4327 req.responder_resources = conn_param->responder_resources; in cma_connect_ib()
4328 req.initiator_depth = conn_param->initiator_depth; in cma_connect_ib()
4329 req.flow_control = conn_param->flow_control; in cma_connect_ib()
4330 req.retry_count = min_t(u8, 7, conn_param->retry_count); in cma_connect_ib()
4331 req.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_connect_ib()
4335 req.srq = id_priv->srq ? 1 : 0; in cma_connect_ib()
4336 req.ece.vendor_id = id_priv->ece.vendor_id; in cma_connect_ib()
4337 req.ece.attr_mod = id_priv->ece.attr_mod; in cma_connect_ib()
4340 ret = ib_send_cm_req(id_priv->cm_id.ib, &req); in cma_connect_ib()
4342 if (ret && !IS_ERR(id)) { in cma_connect_ib()
4343 ib_destroy_cm_id(id); in cma_connect_ib()
4344 id_priv->cm_id.ib = NULL; in cma_connect_ib()
4358 cm_id = iw_create_cm_id(id_priv->id.device, cma_iw_handler, id_priv); in cma_connect_iw()
4362 mutex_lock(&id_priv->qp_mutex); in cma_connect_iw()
4363 cm_id->tos = id_priv->tos; in cma_connect_iw()
4364 cm_id->tos_set = id_priv->tos_set; in cma_connect_iw()
4365 mutex_unlock(&id_priv->qp_mutex); in cma_connect_iw()
4367 id_priv->cm_id.iw = cm_id; in cma_connect_iw()
4369 memcpy(&cm_id->local_addr, cma_src_addr(id_priv), in cma_connect_iw()
4371 memcpy(&cm_id->remote_addr, cma_dst_addr(id_priv), in cma_connect_iw()
4379 iw_param.ord = conn_param->initiator_depth; in cma_connect_iw()
4380 iw_param.ird = conn_param->responder_resources; in cma_connect_iw()
4381 iw_param.private_data = conn_param->private_data; in cma_connect_iw()
4382 iw_param.private_data_len = conn_param->private_data_len; in cma_connect_iw()
4383 iw_param.qpn = id_priv->id.qp ? id_priv->qp_num : conn_param->qp_num; in cma_connect_iw()
4386 iw_param.qpn = id_priv->qp_num; in cma_connect_iw()
4392 id_priv->cm_id.iw = NULL; in cma_connect_iw()
4398 * rdma_connect_locked - Initiate an active connection request.
4399 * @id: Connection identifier to connect.
4405 int rdma_connect_locked(struct rdma_cm_id *id, in rdma_connect_locked() argument
4409 container_of(id, struct rdma_id_private, id); in rdma_connect_locked()
4413 return -EINVAL; in rdma_connect_locked()
4415 if (!id->qp) { in rdma_connect_locked()
4416 id_priv->qp_num = conn_param->qp_num; in rdma_connect_locked()
4417 id_priv->srq = conn_param->srq; in rdma_connect_locked()
4420 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_connect_locked()
4421 if (id->qp_type == IB_QPT_UD) in rdma_connect_locked()
4425 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_connect_locked()
4428 ret = -ENOSYS; in rdma_connect_locked()
4440 * rdma_connect - Initiate an active connection request.
4441 * @id: Connection identifier to connect.
4451 int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) in rdma_connect() argument
4454 container_of(id, struct rdma_id_private, id); in rdma_connect()
4457 mutex_lock(&id_priv->handler_mutex); in rdma_connect()
4458 ret = rdma_connect_locked(id, conn_param); in rdma_connect()
4459 mutex_unlock(&id_priv->handler_mutex); in rdma_connect()
4465 * rdma_connect_ece - Initiate an active connection request with ECE data.
4466 * @id: Connection identifier to connect.
4472 int rdma_connect_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, in rdma_connect_ece() argument
4476 container_of(id, struct rdma_id_private, id); in rdma_connect_ece()
4478 id_priv->ece.vendor_id = ece->vendor_id; in rdma_connect_ece()
4479 id_priv->ece.attr_mod = ece->attr_mod; in rdma_connect_ece()
4481 return rdma_connect(id, conn_param); in rdma_connect_ece()
4500 rep.qp_num = id_priv->qp_num; in cma_accept_ib()
4501 rep.starting_psn = id_priv->seq_num; in cma_accept_ib()
4502 rep.private_data = conn_param->private_data; in cma_accept_ib()
4503 rep.private_data_len = conn_param->private_data_len; in cma_accept_ib()
4504 rep.responder_resources = conn_param->responder_resources; in cma_accept_ib()
4505 rep.initiator_depth = conn_param->initiator_depth; in cma_accept_ib()
4507 rep.flow_control = conn_param->flow_control; in cma_accept_ib()
4508 rep.rnr_retry_count = min_t(u8, 7, conn_param->rnr_retry_count); in cma_accept_ib()
4509 rep.srq = id_priv->srq ? 1 : 0; in cma_accept_ib()
4510 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_accept_ib()
4511 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_accept_ib()
4514 ret = ib_send_cm_rep(id_priv->cm_id.ib, &rep); in cma_accept_ib()
4526 return -EINVAL; in cma_accept_iw()
4532 iw_param.ord = conn_param->initiator_depth; in cma_accept_iw()
4533 iw_param.ird = conn_param->responder_resources; in cma_accept_iw()
4534 iw_param.private_data = conn_param->private_data; in cma_accept_iw()
4535 iw_param.private_data_len = conn_param->private_data_len; in cma_accept_iw()
4536 if (id_priv->id.qp) in cma_accept_iw()
4537 iw_param.qpn = id_priv->qp_num; in cma_accept_iw()
4539 iw_param.qpn = conn_param->qp_num; in cma_accept_iw()
4541 return iw_cm_accept(id_priv->cm_id.iw, &iw_param); in cma_accept_iw()
4557 rep.qp_num = id_priv->qp_num; in cma_send_sidr_rep()
4558 rep.qkey = id_priv->qkey; in cma_send_sidr_rep()
4560 rep.ece.vendor_id = id_priv->ece.vendor_id; in cma_send_sidr_rep()
4561 rep.ece.attr_mod = id_priv->ece.attr_mod; in cma_send_sidr_rep()
4568 return ib_send_cm_sidr_rep(id_priv->cm_id.ib, &rep); in cma_send_sidr_rep()
4572 * rdma_accept - Called to accept a connection request or response.
4573 * @id: Connection identifier associated with the request.
4583 * state of the qp associated with the id is modified to error, such that any
4589 int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param) in rdma_accept() argument
4592 container_of(id, struct rdma_id_private, id); in rdma_accept()
4595 lockdep_assert_held(&id_priv->handler_mutex); in rdma_accept()
4597 if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT) in rdma_accept()
4598 return -EINVAL; in rdma_accept()
4600 if (!id->qp && conn_param) { in rdma_accept()
4601 id_priv->qp_num = conn_param->qp_num; in rdma_accept()
4602 id_priv->srq = conn_param->srq; in rdma_accept()
4605 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_accept()
4606 if (id->qp_type == IB_QPT_UD) { in rdma_accept()
4609 conn_param->qkey, in rdma_accept()
4610 conn_param->private_data, in rdma_accept()
4611 conn_param->private_data_len); in rdma_accept()
4621 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_accept()
4624 ret = -ENOSYS; in rdma_accept()
4632 rdma_reject(id, NULL, 0, IB_CM_REJ_CONSUMER_DEFINED); in rdma_accept()
4637 int rdma_accept_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, in rdma_accept_ece() argument
4641 container_of(id, struct rdma_id_private, id); in rdma_accept_ece()
4643 id_priv->ece.vendor_id = ece->vendor_id; in rdma_accept_ece()
4644 id_priv->ece.attr_mod = ece->attr_mod; in rdma_accept_ece()
4646 return rdma_accept(id, conn_param); in rdma_accept_ece()
4650 void rdma_lock_handler(struct rdma_cm_id *id) in rdma_lock_handler() argument
4653 container_of(id, struct rdma_id_private, id); in rdma_lock_handler()
4655 mutex_lock(&id_priv->handler_mutex); in rdma_lock_handler()
4659 void rdma_unlock_handler(struct rdma_cm_id *id) in rdma_unlock_handler() argument
4662 container_of(id, struct rdma_id_private, id); in rdma_unlock_handler()
4664 mutex_unlock(&id_priv->handler_mutex); in rdma_unlock_handler()
4668 int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event) in rdma_notify() argument
4673 id_priv = container_of(id, struct rdma_id_private, id); in rdma_notify()
4674 if (!id_priv->cm_id.ib) in rdma_notify()
4675 return -EINVAL; in rdma_notify()
4677 switch (id->device->node_type) { in rdma_notify()
4679 ret = ib_cm_notify(id_priv->cm_id.ib, event); in rdma_notify()
4689 int rdma_reject(struct rdma_cm_id *id, const void *private_data, in rdma_reject() argument
4695 id_priv = container_of(id, struct rdma_id_private, id); in rdma_reject()
4696 if (!id_priv->cm_id.ib) in rdma_reject()
4697 return -EINVAL; in rdma_reject()
4699 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_reject()
4700 if (id->qp_type == IB_QPT_UD) { in rdma_reject()
4705 ret = ib_send_cm_rej(id_priv->cm_id.ib, reason, NULL, 0, in rdma_reject()
4708 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_reject()
4709 ret = iw_cm_reject(id_priv->cm_id.iw, in rdma_reject()
4712 ret = -ENOSYS; in rdma_reject()
4719 int rdma_disconnect(struct rdma_cm_id *id) in rdma_disconnect() argument
4724 id_priv = container_of(id, struct rdma_id_private, id); in rdma_disconnect()
4725 if (!id_priv->cm_id.ib) in rdma_disconnect()
4726 return -EINVAL; in rdma_disconnect()
4728 if (rdma_cap_ib_cm(id->device, id->port_num)) { in rdma_disconnect()
4734 if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0)) { in rdma_disconnect()
4735 if (!ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0)) in rdma_disconnect()
4740 } else if (rdma_cap_iw_cm(id->device, id->port_num)) { in rdma_disconnect()
4741 ret = iw_cm_disconnect(id_priv->cm_id.iw, 0); in rdma_disconnect()
4743 ret = -EINVAL; in rdma_disconnect()
4760 status = cma_set_qkey(id_priv, be32_to_cpu(multicast->rec.qkey)); in cma_make_mc_event()
4765 event->status = status; in cma_make_mc_event()
4766 event->param.ud.private_data = mc->context; in cma_make_mc_event()
4768 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4772 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_make_mc_event()
4773 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_make_mc_event()
4775 id_priv->cma_dev in cma_make_mc_event()
4776 ->default_gid_type[id_priv->id.port_num - in cma_make_mc_event()
4778 id_priv->cma_dev->device)]; in cma_make_mc_event()
4780 event->event = RDMA_CM_EVENT_MULTICAST_JOIN; in cma_make_mc_event()
4781 if (ib_init_ah_from_mcmember(id_priv->id.device, id_priv->id.port_num, in cma_make_mc_event()
4782 &multicast->rec, ndev, gid_type, in cma_make_mc_event()
4783 &event->param.ud.ah_attr)) { in cma_make_mc_event()
4784 event->event = RDMA_CM_EVENT_MULTICAST_ERROR; in cma_make_mc_event()
4788 event->param.ud.qp_num = 0xFFFFFF; in cma_make_mc_event()
4789 event->param.ud.qkey = be32_to_cpu(multicast->rec.qkey); in cma_make_mc_event()
4798 struct cma_multicast *mc = multicast->context; in cma_ib_mc_handler()
4799 struct rdma_id_private *id_priv = mc->id_priv; in cma_ib_mc_handler()
4803 mutex_lock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4804 if (READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL || in cma_ib_mc_handler()
4805 READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING) in cma_ib_mc_handler()
4814 mutex_unlock(&id_priv->handler_mutex); in cma_ib_mc_handler()
4822 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_set_mgid()
4828 } else if ((addr->sa_family == AF_INET6) && in cma_set_mgid()
4829 ((be32_to_cpu(sin6->sin6_addr.s6_addr32[0]) & 0xFFF0FFFF) == in cma_set_mgid()
4832 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_set_mgid()
4833 } else if (addr->sa_family == AF_IB) { in cma_set_mgid()
4834 memcpy(mgid, &((struct sockaddr_ib *) addr)->sib_addr, sizeof *mgid); in cma_set_mgid()
4835 } else if (addr->sa_family == AF_INET6) { in cma_set_mgid()
4836 ipv6_ib_mc_map(&sin6->sin6_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4837 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4841 ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map); in cma_set_mgid()
4842 if (id_priv->id.ps == RDMA_PS_UDP) in cma_set_mgid()
4852 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_join_ib_multicast()
4857 ret = ib_sa_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num, in cma_join_ib_multicast()
4866 cma_set_mgid(id_priv, (struct sockaddr *) &mc->addr, &rec.mgid); in cma_join_ib_multicast()
4867 rec.qkey = cpu_to_be32(id_priv->qkey); in cma_join_ib_multicast()
4870 rec.join_state = mc->join_state; in cma_join_ib_multicast()
4878 if (id_priv->id.ps == RDMA_PS_IPOIB) in cma_join_ib_multicast()
4885 mc->sa_mc = ib_sa_join_multicast(&sa_client, id_priv->id.device, in cma_join_ib_multicast()
4886 id_priv->id.port_num, &rec, comp_mask, in cma_join_ib_multicast()
4888 return PTR_ERR_OR_ZERO(mc->sa_mc); in cma_join_ib_multicast()
4899 } else if (addr->sa_family == AF_INET6) { in cma_iboe_set_mgid()
4900 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid); in cma_iboe_set_mgid()
4902 mgid->raw[0] = in cma_iboe_set_mgid()
4904 mgid->raw[1] = in cma_iboe_set_mgid()
4906 mgid->raw[2] = 0; in cma_iboe_set_mgid()
4907 mgid->raw[3] = 0; in cma_iboe_set_mgid()
4908 mgid->raw[4] = 0; in cma_iboe_set_mgid()
4909 mgid->raw[5] = 0; in cma_iboe_set_mgid()
4910 mgid->raw[6] = 0; in cma_iboe_set_mgid()
4911 mgid->raw[7] = 0; in cma_iboe_set_mgid()
4912 mgid->raw[8] = 0; in cma_iboe_set_mgid()
4913 mgid->raw[9] = 0; in cma_iboe_set_mgid()
4914 mgid->raw[10] = 0xff; in cma_iboe_set_mgid()
4915 mgid->raw[11] = 0xff; in cma_iboe_set_mgid()
4916 *(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr; in cma_iboe_set_mgid()
4923 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; in cma_iboe_join_multicast()
4925 struct sockaddr *addr = (struct sockaddr *)&mc->addr; in cma_iboe_join_multicast()
4931 send_only = mc->join_state == BIT(SENDONLY_FULLMEMBER_JOIN); in cma_iboe_join_multicast()
4934 return -EINVAL; in cma_iboe_join_multicast()
4936 gid_type = id_priv->cma_dev->default_gid_type[id_priv->id.port_num - in cma_iboe_join_multicast()
4937 rdma_start_port(id_priv->cma_dev->device)]; in cma_iboe_join_multicast()
4941 if (id_priv->id.ps == RDMA_PS_UDP) in cma_iboe_join_multicast()
4944 if (dev_addr->bound_dev_if) in cma_iboe_join_multicast()
4945 ndev = dev_get_by_index(dev_addr->net, dev_addr->bound_dev_if); in cma_iboe_join_multicast()
4947 return -ENODEV; in cma_iboe_join_multicast()
4951 ib.rec.mtu = iboe_get_mtu(ndev->mtu); in cma_iboe_join_multicast()
4953 if (addr->sa_family == AF_INET) { in cma_iboe_join_multicast()
4963 err = -ENOTSUPP; in cma_iboe_join_multicast()
4967 return err ?: -EINVAL; in cma_iboe_join_multicast()
4969 rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, in cma_iboe_join_multicast()
4971 INIT_WORK(&mc->iboe_join.work, cma_iboe_join_work_handler); in cma_iboe_join_multicast()
4972 cma_make_mc_event(0, id_priv, &ib, &mc->iboe_join.event, mc); in cma_iboe_join_multicast()
4973 queue_work(cma_wq, &mc->iboe_join.work); in cma_iboe_join_multicast()
4977 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, in rdma_join_multicast() argument
4981 container_of(id, struct rdma_id_private, id); in rdma_join_multicast()
4986 if (WARN_ON(id->qp)) in rdma_join_multicast()
4987 return -EINVAL; in rdma_join_multicast()
4990 if (!id->device || (READ_ONCE(id_priv->state) != RDMA_CM_ADDR_BOUND && in rdma_join_multicast()
4991 READ_ONCE(id_priv->state) != RDMA_CM_ADDR_RESOLVED)) in rdma_join_multicast()
4992 return -EINVAL; in rdma_join_multicast()
4996 return -ENOMEM; in rdma_join_multicast()
4998 memcpy(&mc->addr, addr, rdma_addr_size(addr)); in rdma_join_multicast()
4999 mc->context = context; in rdma_join_multicast()
5000 mc->id_priv = id_priv; in rdma_join_multicast()
5001 mc->join_state = join_state; in rdma_join_multicast()
5003 if (rdma_protocol_roce(id->device, id->port_num)) { in rdma_join_multicast()
5007 } else if (rdma_cap_ib_mcast(id->device, id->port_num)) { in rdma_join_multicast()
5012 ret = -ENOSYS; in rdma_join_multicast()
5016 spin_lock(&id_priv->lock); in rdma_join_multicast()
5017 list_add(&mc->list, &id_priv->mc_list); in rdma_join_multicast()
5018 spin_unlock(&id_priv->lock); in rdma_join_multicast()
5027 void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr) in rdma_leave_multicast() argument
5032 id_priv = container_of(id, struct rdma_id_private, id); in rdma_leave_multicast()
5033 spin_lock_irq(&id_priv->lock); in rdma_leave_multicast()
5034 list_for_each_entry(mc, &id_priv->mc_list, list) { in rdma_leave_multicast()
5035 if (memcmp(&mc->addr, addr, rdma_addr_size(addr)) != 0) in rdma_leave_multicast()
5037 list_del(&mc->list); in rdma_leave_multicast()
5038 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
5040 WARN_ON(id_priv->cma_dev->device != id->device); in rdma_leave_multicast()
5044 spin_unlock_irq(&id_priv->lock); in rdma_leave_multicast()
5053 dev_addr = &id_priv->id.route.addr.dev_addr; in cma_netdev_change()
5055 if ((dev_addr->bound_dev_if == ndev->ifindex) && in cma_netdev_change()
5056 (net_eq(dev_net(ndev), dev_addr->net)) && in cma_netdev_change()
5057 memcmp(dev_addr->src_dev_addr, ndev->dev_addr, ndev->addr_len)) { in cma_netdev_change()
5058 pr_info("RDMA CM addr change for ndev %s used by id %p\n", in cma_netdev_change()
5059 ndev->name, &id_priv->id); in cma_netdev_change()
5062 return -ENOMEM; in cma_netdev_change()
5064 INIT_WORK(&work->work, cma_work_handler); in cma_netdev_change()
5065 work->id = id_priv; in cma_netdev_change()
5066 work->event.event = RDMA_CM_EVENT_ADDR_CHANGE; in cma_netdev_change()
5068 queue_work(cma_wq, &work->work); in cma_netdev_change()
5090 list_for_each_entry(id_priv, &cma_dev->id_list, device_item) { in cma_netdev_callback()
5104 container_of(_work, struct rdma_id_private, id.net_work); in cma_netevent_work_handler()
5107 mutex_lock(&id_priv->handler_mutex); in cma_netevent_work_handler()
5109 if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING || in cma_netevent_work_handler()
5110 READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL) in cma_netevent_work_handler()
5114 event.status = -ETIMEDOUT; in cma_netevent_work_handler()
5117 __acquire(&id_priv->handler_mutex); in cma_netevent_work_handler()
5118 id_priv->cm_id.ib = NULL; in cma_netevent_work_handler()
5125 mutex_unlock(&id_priv->handler_mutex); in cma_netevent_work_handler()
5141 if (neigh->tbl->family == AF_INET6) { in cma_netevent_callback()
5145 neigh_sock_6.sin6_addr = *(struct in6_addr *)neigh->primary_key; in cma_netevent_callback()
5146 ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, in cma_netevent_callback()
5148 } else if (neigh->tbl->family == AF_INET) { in cma_netevent_callback()
5152 neigh_sock_4.sin_addr.s_addr = *(__be32 *)(neigh->primary_key); in cma_netevent_callback()
5153 ips_node = node_from_ndev_ip(&id_table, neigh->dev->ifindex, in cma_netevent_callback()
5161 list_for_each_entry(current_id, &ips_node->id_list, id_list_entry) { in cma_netevent_callback()
5162 if (!memcmp(current_id->id.route.addr.dev_addr.dst_dev_addr, in cma_netevent_callback()
5163 neigh->ha, ETH_ALEN)) in cma_netevent_callback()
5165 INIT_WORK(¤t_id->id.net_work, cma_netevent_work_handler); in cma_netevent_callback()
5167 queue_work(cma_wq, ¤t_id->id.net_work); in cma_netevent_callback()
5188 mutex_lock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5189 /* Record that we want to remove the device */ in cma_send_device_removal_put()
5190 spin_lock_irqsave(&id_priv->lock, flags); in cma_send_device_removal_put()
5191 state = id_priv->state; in cma_send_device_removal_put()
5193 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
5194 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5198 id_priv->state = RDMA_CM_DEVICE_REMOVAL; in cma_send_device_removal_put()
5199 spin_unlock_irqrestore(&id_priv->lock, flags); in cma_send_device_removal_put()
5207 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5212 mutex_unlock(&id_priv->handler_mutex); in cma_send_device_removal_put()
5225 while (!list_empty(&cma_dev->id_list)) { in cma_process_remove()
5227 &cma_dev->id_list, struct rdma_id_private, device_item); in cma_process_remove()
5229 list_del_init(&id_priv->listen_item); in cma_process_remove()
5230 list_del_init(&id_priv->device_item); in cma_process_remove()
5241 wait_for_completion(&cma_dev->comp); in cma_process_remove()
5244 static bool cma_supported(struct ib_device *device) in cma_supported() argument
5248 rdma_for_each_port(device, i) { in cma_supported()
5249 if (rdma_cap_ib_cm(device, i) || rdma_cap_iw_cm(device, i)) in cma_supported()
5255 static int cma_add_one(struct ib_device *device) in cma_add_one() argument
5264 if (!cma_supported(device)) in cma_add_one()
5265 return -EOPNOTSUPP; in cma_add_one()
5269 return -ENOMEM; in cma_add_one()
5271 cma_dev->device = device; in cma_add_one()
5272 cma_dev->default_gid_type = kcalloc(device->phys_port_cnt, in cma_add_one()
5273 sizeof(*cma_dev->default_gid_type), in cma_add_one()
5275 if (!cma_dev->default_gid_type) { in cma_add_one()
5276 ret = -ENOMEM; in cma_add_one()
5280 cma_dev->default_roce_tos = kcalloc(device->phys_port_cnt, in cma_add_one()
5281 sizeof(*cma_dev->default_roce_tos), in cma_add_one()
5283 if (!cma_dev->default_roce_tos) { in cma_add_one()
5284 ret = -ENOMEM; in cma_add_one()
5288 rdma_for_each_port (device, i) { in cma_add_one()
5289 supported_gids = roce_gid_type_mask_support(device, i); in cma_add_one()
5292 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
5295 cma_dev->default_gid_type[i - rdma_start_port(device)] = in cma_add_one()
5297 cma_dev->default_roce_tos[i - rdma_start_port(device)] = 0; in cma_add_one()
5300 init_completion(&cma_dev->comp); in cma_add_one()
5301 refcount_set(&cma_dev->refcount, 1); in cma_add_one()
5302 INIT_LIST_HEAD(&cma_dev->id_list); in cma_add_one()
5303 ib_set_client_data(device, &cma_client, cma_dev); in cma_add_one()
5306 list_add_tail(&cma_dev->list, &dev_list); in cma_add_one()
5314 trace_cm_add_one(device); in cma_add_one()
5318 list_del(&cma_dev->list); in cma_add_one()
5323 kfree(cma_dev->default_roce_tos); in cma_add_one()
5325 kfree(cma_dev->default_gid_type); in cma_add_one()
5332 static void cma_remove_one(struct ib_device *device, void *client_data) in cma_remove_one() argument
5336 trace_cm_remove_one(device); in cma_remove_one()
5339 list_del(&cma_dev->list); in cma_remove_one()
5343 kfree(cma_dev->default_roce_tos); in cma_remove_one()
5344 kfree(cma_dev->default_gid_type); in cma_remove_one()
5352 xa_init(&pernet->tcp_ps); in cma_init_net()
5353 xa_init(&pernet->udp_ps); in cma_init_net()
5354 xa_init(&pernet->ipoib_ps); in cma_init_net()
5355 xa_init(&pernet->ib_ps); in cma_init_net()
5364 WARN_ON(!xa_empty(&pernet->tcp_ps)); in cma_exit_net()
5365 WARN_ON(!xa_empty(&pernet->udp_ps)); in cma_exit_net()
5366 WARN_ON(!xa_empty(&pernet->ipoib_ps)); in cma_exit_net()
5367 WARN_ON(!xa_empty(&pernet->ib_ps)); in cma_exit_net()
5373 .id = &cma_pernet_id,
5396 return -ENOMEM; in cma_init()