diff options
author | Sean Hefty <sean.hefty@intel.com> | 2013-05-29 13:09:21 -0400 |
---|---|---|
committer | Roland Dreier <roland@purestorage.com> | 2013-06-21 02:35:29 -0400 |
commit | fbaa1a6d852aa6878059acb18cbc336746795a56 (patch) | |
tree | 3da9248af00863f148351949dabae52be77b1d23 | |
parent | 01602f113f7ceee51e04edd1db972b79bedfe3aa (diff) |
RDMA/cma: Merge cma_get/save_net_info
With the removal of SDP related code, we can merge cma_get_net_info()
with cma_save_net_info(), since we're only ever dealing with a single
header format.
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
-rw-r--r-- | drivers/infiniband/core/cma.c | 124 |
1 files changed, 69 insertions, 55 deletions
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index daec9319502d..112a192eae9c 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c | |||
@@ -810,59 +810,87 @@ static inline int cma_any_port(struct sockaddr *addr) | |||
810 | return !cma_port(addr); | 810 | return !cma_port(addr); |
811 | } | 811 | } |
812 | 812 | ||
813 | static int cma_get_net_info(void *hdr, enum rdma_port_space ps, | 813 | static void cma_save_ib_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
814 | u8 *ip_ver, __be16 *port, | 814 | struct ib_sa_path_rec *path) |
815 | union cma_ip_addr **src, union cma_ip_addr **dst) | ||
816 | { | 815 | { |
817 | if (((struct cma_hdr *) hdr)->cma_version != CMA_VERSION) | 816 | struct sockaddr_ib *listen_ib, *ib; |
818 | return -EINVAL; | ||
819 | 817 | ||
820 | *ip_ver = cma_get_ip_ver(hdr); | 818 | listen_ib = (struct sockaddr_ib *) &listen_id->route.addr.src_addr; |
821 | *port = ((struct cma_hdr *) hdr)->port; | 819 | ib = (struct sockaddr_ib *) &id->route.addr.src_addr; |
822 | *src = &((struct cma_hdr *) hdr)->src_addr; | 820 | ib->sib_family = listen_ib->sib_family; |
823 | *dst = &((struct cma_hdr *) hdr)->dst_addr; | 821 | ib->sib_pkey = path->pkey; |
822 | ib->sib_flowinfo = path->flow_label; | ||
823 | memcpy(&ib->sib_addr, &path->sgid, 16); | ||
824 | ib->sib_sid = listen_ib->sib_sid; | ||
825 | ib->sib_sid_mask = cpu_to_be64(0xffffffffffffffffULL); | ||
826 | ib->sib_scope_id = listen_ib->sib_scope_id; | ||
824 | 827 | ||
825 | if (*ip_ver != 4 && *ip_ver != 6) | 828 | ib = (struct sockaddr_ib *) &id->route.addr.dst_addr; |
826 | return -EINVAL; | 829 | ib->sib_family = listen_ib->sib_family; |
827 | return 0; | 830 | ib->sib_pkey = path->pkey; |
831 | ib->sib_flowinfo = path->flow_label; | ||
832 | memcpy(&ib->sib_addr, &path->dgid, 16); | ||
828 | } | 833 | } |
829 | 834 | ||
830 | static void cma_save_net_info(struct rdma_addr *addr, | 835 | static void cma_save_ip4_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, |
831 | struct rdma_addr *listen_addr, | 836 | struct cma_hdr *hdr) |
832 | u8 ip_ver, __be16 port, | ||
833 | union cma_ip_addr *src, union cma_ip_addr *dst) | ||
834 | { | 837 | { |
835 | struct sockaddr_in *listen4, *ip4; | 838 | struct sockaddr_in *listen4, *ip4; |
839 | |||
840 | listen4 = (struct sockaddr_in *) &listen_id->route.addr.src_addr; | ||
841 | ip4 = (struct sockaddr_in *) &id->route.addr.src_addr; | ||
842 | ip4->sin_family = listen4->sin_family; | ||
843 | ip4->sin_addr.s_addr = hdr->dst_addr.ip4.addr; | ||
844 | ip4->sin_port = listen4->sin_port; | ||
845 | |||
846 | ip4 = (struct sockaddr_in *) &id->route.addr.dst_addr; | ||
847 | ip4->sin_family = listen4->sin_family; | ||
848 | ip4->sin_addr.s_addr = hdr->src_addr.ip4.addr; | ||
849 | ip4->sin_port = hdr->port; | ||
850 | } | ||
851 | |||
852 | static void cma_save_ip6_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, | ||
853 | struct cma_hdr *hdr) | ||
854 | { | ||
836 | struct sockaddr_in6 *listen6, *ip6; | 855 | struct sockaddr_in6 *listen6, *ip6; |
837 | 856 | ||
838 | switch (ip_ver) { | 857 | listen6 = (struct sockaddr_in6 *) &listen_id->route.addr.src_addr; |
858 | ip6 = (struct sockaddr_in6 *) &id->route.addr.src_addr; | ||
859 | ip6->sin6_family = listen6->sin6_family; | ||
860 | ip6->sin6_addr = hdr->dst_addr.ip6; | ||
861 | ip6->sin6_port = listen6->sin6_port; | ||
862 | |||
863 | ip6 = (struct sockaddr_in6 *) &id->route.addr.dst_addr; | ||
864 | ip6->sin6_family = listen6->sin6_family; | ||
865 | ip6->sin6_addr = hdr->src_addr.ip6; | ||
866 | ip6->sin6_port = hdr->port; | ||
867 | } | ||
868 | |||
869 | static int cma_save_net_info(struct rdma_cm_id *id, struct rdma_cm_id *listen_id, | ||
870 | struct ib_cm_event *ib_event) | ||
871 | { | ||
872 | struct cma_hdr *hdr; | ||
873 | |||
874 | if (listen_id->route.addr.src_addr.ss_family == AF_IB) { | ||
875 | cma_save_ib_info(id, listen_id, ib_event->param.req_rcvd.primary_path); | ||
876 | return 0; | ||
877 | } | ||
878 | |||
879 | hdr = ib_event->private_data; | ||
880 | if (hdr->cma_version != CMA_VERSION) | ||
881 | return -EINVAL; | ||
882 | |||
883 | switch (cma_get_ip_ver(hdr)) { | ||
839 | case 4: | 884 | case 4: |
840 | listen4 = (struct sockaddr_in *) &listen_addr->src_addr; | 885 | cma_save_ip4_info(id, listen_id, hdr); |
841 | ip4 = (struct sockaddr_in *) &addr->src_addr; | ||
842 | ip4->sin_family = listen4->sin_family; | ||
843 | ip4->sin_addr.s_addr = dst->ip4.addr; | ||
844 | ip4->sin_port = listen4->sin_port; | ||
845 | |||
846 | ip4 = (struct sockaddr_in *) &addr->dst_addr; | ||
847 | ip4->sin_family = listen4->sin_family; | ||
848 | ip4->sin_addr.s_addr = src->ip4.addr; | ||
849 | ip4->sin_port = port; | ||
850 | break; | 886 | break; |
851 | case 6: | 887 | case 6: |
852 | listen6 = (struct sockaddr_in6 *) &listen_addr->src_addr; | 888 | cma_save_ip6_info(id, listen_id, hdr); |
853 | ip6 = (struct sockaddr_in6 *) &addr->src_addr; | ||
854 | ip6->sin6_family = listen6->sin6_family; | ||
855 | ip6->sin6_addr = dst->ip6; | ||
856 | ip6->sin6_port = listen6->sin6_port; | ||
857 | |||
858 | ip6 = (struct sockaddr_in6 *) &addr->dst_addr; | ||
859 | ip6->sin6_family = listen6->sin6_family; | ||
860 | ip6->sin6_addr = src->ip6; | ||
861 | ip6->sin6_port = port; | ||
862 | break; | 889 | break; |
863 | default: | 890 | default: |
864 | break; | 891 | return -EINVAL; |
865 | } | 892 | } |
893 | return 0; | ||
866 | } | 894 | } |
867 | 895 | ||
868 | static inline int cma_user_data_offset(enum rdma_port_space ps) | 896 | static inline int cma_user_data_offset(enum rdma_port_space ps) |
@@ -1129,23 +1157,16 @@ static struct rdma_id_private *cma_new_conn_id(struct rdma_cm_id *listen_id, | |||
1129 | struct rdma_id_private *id_priv; | 1157 | struct rdma_id_private *id_priv; |
1130 | struct rdma_cm_id *id; | 1158 | struct rdma_cm_id *id; |
1131 | struct rdma_route *rt; | 1159 | struct rdma_route *rt; |
1132 | union cma_ip_addr *src, *dst; | ||
1133 | __be16 port; | ||
1134 | u8 ip_ver; | ||
1135 | int ret; | 1160 | int ret; |
1136 | 1161 | ||
1137 | if (cma_get_net_info(ib_event->private_data, listen_id->ps, | ||
1138 | &ip_ver, &port, &src, &dst)) | ||
1139 | return NULL; | ||
1140 | |||
1141 | id = rdma_create_id(listen_id->event_handler, listen_id->context, | 1162 | id = rdma_create_id(listen_id->event_handler, listen_id->context, |
1142 | listen_id->ps, ib_event->param.req_rcvd.qp_type); | 1163 | listen_id->ps, ib_event->param.req_rcvd.qp_type); |
1143 | if (IS_ERR(id)) | 1164 | if (IS_ERR(id)) |
1144 | return NULL; | 1165 | return NULL; |
1145 | 1166 | ||
1146 | id_priv = container_of(id, struct rdma_id_private, id); | 1167 | id_priv = container_of(id, struct rdma_id_private, id); |
1147 | cma_save_net_info(&id->route.addr, &listen_id->route.addr, | 1168 | if (cma_save_net_info(id, listen_id, ib_event)) |
1148 | ip_ver, port, src, dst); | 1169 | goto err; |
1149 | 1170 | ||
1150 | rt = &id->route; | 1171 | rt = &id->route; |
1151 | rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; | 1172 | rt->num_paths = ib_event->param.req_rcvd.alternate_path ? 2 : 1; |
@@ -1182,9 +1203,6 @@ static struct rdma_id_private *cma_new_udp_id(struct rdma_cm_id *listen_id, | |||
1182 | { | 1203 | { |
1183 | struct rdma_id_private *id_priv; | 1204 | struct rdma_id_private *id_priv; |
1184 | struct rdma_cm_id *id; | 1205 | struct rdma_cm_id *id; |
1185 | union cma_ip_addr *src, *dst; | ||
1186 | __be16 port; | ||
1187 | u8 ip_ver; | ||
1188 | int ret; | 1206 | int ret; |
1189 | 1207 | ||
1190 | id = rdma_create_id(listen_id->event_handler, listen_id->context, | 1208 | id = rdma_create_id(listen_id->event_handler, listen_id->context, |
@@ -1193,13 +1211,9 @@ static struct rdma_id_private *cma_new_udp_id(struct rdma_cm_id *listen_id, | |||
1193 | return NULL; | 1211 | return NULL; |
1194 | 1212 | ||
1195 | id_priv = container_of(id, struct rdma_id_private, id); | 1213 | id_priv = container_of(id, struct rdma_id_private, id); |
1196 | if (cma_get_net_info(ib_event->private_data, listen_id->ps, | 1214 | if (cma_save_net_info(id, listen_id, ib_event)) |
1197 | &ip_ver, &port, &src, &dst)) | ||
1198 | goto err; | 1215 | goto err; |
1199 | 1216 | ||
1200 | cma_save_net_info(&id->route.addr, &listen_id->route.addr, | ||
1201 | ip_ver, port, src, dst); | ||
1202 | |||
1203 | if (!cma_any_addr((struct sockaddr *) &id->route.addr.src_addr)) { | 1217 | if (!cma_any_addr((struct sockaddr *) &id->route.addr.src_addr)) { |
1204 | ret = cma_translate_addr(cma_src_addr(id_priv), &id->route.addr.dev_addr); | 1218 | ret = cma_translate_addr(cma_src_addr(id_priv), &id->route.addr.dev_addr); |
1205 | if (ret) | 1219 | if (ret) |