uverbs_marshall.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (c) 2005 Intel Corporation. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/export.h>
  33. #include <rdma/ib_marshall.h>
  34. #define OPA_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
  35. static int rdma_ah_conv_opa_to_ib(struct ib_device *dev,
  36. struct rdma_ah_attr *ib,
  37. struct rdma_ah_attr *opa)
  38. {
  39. struct ib_port_attr port_attr;
  40. int ret = 0;
  41. /* Do structure copy and the over-write fields */
  42. *ib = *opa;
  43. ib->type = RDMA_AH_ATTR_TYPE_IB;
  44. rdma_ah_set_grh(ib, NULL, 0, 0, 1, 0);
  45. if (ib_query_port(dev, opa->port_num, &port_attr)) {
  46. /* Set to default subnet to indicate error */
  47. rdma_ah_set_subnet_prefix(ib, OPA_DEFAULT_GID_PREFIX);
  48. ret = -EINVAL;
  49. } else {
  50. rdma_ah_set_subnet_prefix(ib,
  51. cpu_to_be64(port_attr.subnet_prefix));
  52. }
  53. rdma_ah_set_interface_id(ib, OPA_MAKE_ID(rdma_ah_get_dlid(opa)));
  54. return ret;
  55. }
  56. void ib_copy_ah_attr_to_user(struct ib_device *device,
  57. struct ib_uverbs_ah_attr *dst,
  58. struct rdma_ah_attr *ah_attr)
  59. {
  60. struct rdma_ah_attr *src = ah_attr;
  61. struct rdma_ah_attr conv_ah;
  62. memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
  63. if ((ah_attr->type == RDMA_AH_ATTR_TYPE_OPA) &&
  64. (rdma_ah_get_dlid(ah_attr) > be16_to_cpu(IB_LID_PERMISSIVE)) &&
  65. (!rdma_ah_conv_opa_to_ib(device, &conv_ah, ah_attr)))
  66. src = &conv_ah;
  67. dst->dlid = rdma_ah_get_dlid(src);
  68. dst->sl = rdma_ah_get_sl(src);
  69. dst->src_path_bits = rdma_ah_get_path_bits(src);
  70. dst->static_rate = rdma_ah_get_static_rate(src);
  71. dst->is_global = rdma_ah_get_ah_flags(src) &
  72. IB_AH_GRH ? 1 : 0;
  73. if (dst->is_global) {
  74. const struct ib_global_route *grh = rdma_ah_read_grh(src);
  75. memcpy(dst->grh.dgid, grh->dgid.raw, sizeof(grh->dgid));
  76. dst->grh.flow_label = grh->flow_label;
  77. dst->grh.sgid_index = grh->sgid_index;
  78. dst->grh.hop_limit = grh->hop_limit;
  79. dst->grh.traffic_class = grh->traffic_class;
  80. }
  81. dst->port_num = rdma_ah_get_port_num(src);
  82. dst->reserved = 0;
  83. }
  84. EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
  85. void ib_copy_qp_attr_to_user(struct ib_device *device,
  86. struct ib_uverbs_qp_attr *dst,
  87. struct ib_qp_attr *src)
  88. {
  89. dst->qp_state = src->qp_state;
  90. dst->cur_qp_state = src->cur_qp_state;
  91. dst->path_mtu = src->path_mtu;
  92. dst->path_mig_state = src->path_mig_state;
  93. dst->qkey = src->qkey;
  94. dst->rq_psn = src->rq_psn;
  95. dst->sq_psn = src->sq_psn;
  96. dst->dest_qp_num = src->dest_qp_num;
  97. dst->qp_access_flags = src->qp_access_flags;
  98. dst->max_send_wr = src->cap.max_send_wr;
  99. dst->max_recv_wr = src->cap.max_recv_wr;
  100. dst->max_send_sge = src->cap.max_send_sge;
  101. dst->max_recv_sge = src->cap.max_recv_sge;
  102. dst->max_inline_data = src->cap.max_inline_data;
  103. ib_copy_ah_attr_to_user(device, &dst->ah_attr, &src->ah_attr);
  104. ib_copy_ah_attr_to_user(device, &dst->alt_ah_attr, &src->alt_ah_attr);
  105. dst->pkey_index = src->pkey_index;
  106. dst->alt_pkey_index = src->alt_pkey_index;
  107. dst->en_sqd_async_notify = src->en_sqd_async_notify;
  108. dst->sq_draining = src->sq_draining;
  109. dst->max_rd_atomic = src->max_rd_atomic;
  110. dst->max_dest_rd_atomic = src->max_dest_rd_atomic;
  111. dst->min_rnr_timer = src->min_rnr_timer;
  112. dst->port_num = src->port_num;
  113. dst->timeout = src->timeout;
  114. dst->retry_cnt = src->retry_cnt;
  115. dst->rnr_retry = src->rnr_retry;
  116. dst->alt_port_num = src->alt_port_num;
  117. dst->alt_timeout = src->alt_timeout;
  118. memset(dst->reserved, 0, sizeof(dst->reserved));
  119. }
  120. EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
  121. static void __ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
  122. struct sa_path_rec *src)
  123. {
  124. memcpy(dst->dgid, src->dgid.raw, sizeof(src->dgid));
  125. memcpy(dst->sgid, src->sgid.raw, sizeof(src->sgid));
  126. dst->dlid = htons(ntohl(sa_path_get_dlid(src)));
  127. dst->slid = htons(ntohl(sa_path_get_slid(src)));
  128. dst->raw_traffic = sa_path_get_raw_traffic(src);
  129. dst->flow_label = src->flow_label;
  130. dst->hop_limit = src->hop_limit;
  131. dst->traffic_class = src->traffic_class;
  132. dst->reversible = src->reversible;
  133. dst->numb_path = src->numb_path;
  134. dst->pkey = src->pkey;
  135. dst->sl = src->sl;
  136. dst->mtu_selector = src->mtu_selector;
  137. dst->mtu = src->mtu;
  138. dst->rate_selector = src->rate_selector;
  139. dst->rate = src->rate;
  140. dst->packet_life_time = src->packet_life_time;
  141. dst->preference = src->preference;
  142. dst->packet_life_time_selector = src->packet_life_time_selector;
  143. }
  144. void ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
  145. struct sa_path_rec *src)
  146. {
  147. struct sa_path_rec rec;
  148. if (src->rec_type == SA_PATH_REC_TYPE_OPA) {
  149. sa_convert_path_opa_to_ib(&rec, src);
  150. __ib_copy_path_rec_to_user(dst, &rec);
  151. return;
  152. }
  153. __ib_copy_path_rec_to_user(dst, src);
  154. }
  155. EXPORT_SYMBOL(ib_copy_path_rec_to_user);
  156. void ib_copy_path_rec_from_user(struct sa_path_rec *dst,
  157. struct ib_user_path_rec *src)
  158. {
  159. u32 slid, dlid;
  160. memset(dst, 0, sizeof(*dst));
  161. if ((ib_is_opa_gid((union ib_gid *)src->sgid)) ||
  162. (ib_is_opa_gid((union ib_gid *)src->dgid))) {
  163. dst->rec_type = SA_PATH_REC_TYPE_OPA;
  164. slid = opa_get_lid_from_gid((union ib_gid *)src->sgid);
  165. dlid = opa_get_lid_from_gid((union ib_gid *)src->dgid);
  166. } else {
  167. dst->rec_type = SA_PATH_REC_TYPE_IB;
  168. slid = ntohs(src->slid);
  169. dlid = ntohs(src->dlid);
  170. }
  171. memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
  172. memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
  173. sa_path_set_dlid(dst, dlid);
  174. sa_path_set_slid(dst, slid);
  175. sa_path_set_raw_traffic(dst, src->raw_traffic);
  176. dst->flow_label = src->flow_label;
  177. dst->hop_limit = src->hop_limit;
  178. dst->traffic_class = src->traffic_class;
  179. dst->reversible = src->reversible;
  180. dst->numb_path = src->numb_path;
  181. dst->pkey = src->pkey;
  182. dst->sl = src->sl;
  183. dst->mtu_selector = src->mtu_selector;
  184. dst->mtu = src->mtu;
  185. dst->rate_selector = src->rate_selector;
  186. dst->rate = src->rate;
  187. dst->packet_life_time = src->packet_life_time;
  188. dst->preference = src->preference;
  189. dst->packet_life_time_selector = src->packet_life_time_selector;
  190. /* TODO: No need to set this */
  191. sa_path_set_dmac_zero(dst);
  192. }
  193. EXPORT_SYMBOL(ib_copy_path_rec_from_user);