uverbs_marshall.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
  35. struct rdma_ah_attr *src)
  36. {
  37. memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
  38. dst->dlid = rdma_ah_get_dlid(src);
  39. dst->sl = rdma_ah_get_sl(src);
  40. dst->src_path_bits = rdma_ah_get_path_bits(src);
  41. dst->static_rate = rdma_ah_get_static_rate(src);
  42. dst->is_global = rdma_ah_get_ah_flags(src) &
  43. IB_AH_GRH ? 1 : 0;
  44. if (dst->is_global) {
  45. const struct ib_global_route *grh = rdma_ah_read_grh(src);
  46. memcpy(dst->grh.dgid, grh->dgid.raw, sizeof(grh->dgid));
  47. dst->grh.flow_label = grh->flow_label;
  48. dst->grh.sgid_index = grh->sgid_index;
  49. dst->grh.hop_limit = grh->hop_limit;
  50. dst->grh.traffic_class = grh->traffic_class;
  51. }
  52. dst->port_num = rdma_ah_get_port_num(src);
  53. dst->reserved = 0;
  54. }
  55. EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
  56. void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
  57. struct ib_qp_attr *src)
  58. {
  59. dst->qp_state = src->qp_state;
  60. dst->cur_qp_state = src->cur_qp_state;
  61. dst->path_mtu = src->path_mtu;
  62. dst->path_mig_state = src->path_mig_state;
  63. dst->qkey = src->qkey;
  64. dst->rq_psn = src->rq_psn;
  65. dst->sq_psn = src->sq_psn;
  66. dst->dest_qp_num = src->dest_qp_num;
  67. dst->qp_access_flags = src->qp_access_flags;
  68. dst->max_send_wr = src->cap.max_send_wr;
  69. dst->max_recv_wr = src->cap.max_recv_wr;
  70. dst->max_send_sge = src->cap.max_send_sge;
  71. dst->max_recv_sge = src->cap.max_recv_sge;
  72. dst->max_inline_data = src->cap.max_inline_data;
  73. ib_copy_ah_attr_to_user(&dst->ah_attr, &src->ah_attr);
  74. ib_copy_ah_attr_to_user(&dst->alt_ah_attr, &src->alt_ah_attr);
  75. dst->pkey_index = src->pkey_index;
  76. dst->alt_pkey_index = src->alt_pkey_index;
  77. dst->en_sqd_async_notify = src->en_sqd_async_notify;
  78. dst->sq_draining = src->sq_draining;
  79. dst->max_rd_atomic = src->max_rd_atomic;
  80. dst->max_dest_rd_atomic = src->max_dest_rd_atomic;
  81. dst->min_rnr_timer = src->min_rnr_timer;
  82. dst->port_num = src->port_num;
  83. dst->timeout = src->timeout;
  84. dst->retry_cnt = src->retry_cnt;
  85. dst->rnr_retry = src->rnr_retry;
  86. dst->alt_port_num = src->alt_port_num;
  87. dst->alt_timeout = src->alt_timeout;
  88. memset(dst->reserved, 0, sizeof(dst->reserved));
  89. }
  90. EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
  91. static void __ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
  92. struct sa_path_rec *src)
  93. {
  94. memcpy(dst->dgid, src->dgid.raw, sizeof(src->dgid));
  95. memcpy(dst->sgid, src->sgid.raw, sizeof(src->sgid));
  96. dst->dlid = htons(ntohl(sa_path_get_dlid(src)));
  97. dst->slid = htons(ntohl(sa_path_get_slid(src)));
  98. dst->raw_traffic = sa_path_get_raw_traffic(src);
  99. dst->flow_label = src->flow_label;
  100. dst->hop_limit = src->hop_limit;
  101. dst->traffic_class = src->traffic_class;
  102. dst->reversible = src->reversible;
  103. dst->numb_path = src->numb_path;
  104. dst->pkey = src->pkey;
  105. dst->sl = src->sl;
  106. dst->mtu_selector = src->mtu_selector;
  107. dst->mtu = src->mtu;
  108. dst->rate_selector = src->rate_selector;
  109. dst->rate = src->rate;
  110. dst->packet_life_time = src->packet_life_time;
  111. dst->preference = src->preference;
  112. dst->packet_life_time_selector = src->packet_life_time_selector;
  113. }
  114. void ib_copy_path_rec_to_user(struct ib_user_path_rec *dst,
  115. struct sa_path_rec *src)
  116. {
  117. struct sa_path_rec rec;
  118. if (src->rec_type == SA_PATH_REC_TYPE_OPA) {
  119. sa_convert_path_opa_to_ib(&rec, src);
  120. __ib_copy_path_rec_to_user(dst, &rec);
  121. return;
  122. }
  123. __ib_copy_path_rec_to_user(dst, src);
  124. }
  125. EXPORT_SYMBOL(ib_copy_path_rec_to_user);
  126. void ib_copy_path_rec_from_user(struct sa_path_rec *dst,
  127. struct ib_user_path_rec *src)
  128. {
  129. __be32 slid, dlid;
  130. memset(dst, 0, sizeof(*dst));
  131. if ((ib_is_opa_gid((union ib_gid *)src->sgid)) ||
  132. (ib_is_opa_gid((union ib_gid *)src->dgid))) {
  133. dst->rec_type = SA_PATH_REC_TYPE_OPA;
  134. slid = htonl(opa_get_lid_from_gid((union ib_gid *)src->sgid));
  135. dlid = htonl(opa_get_lid_from_gid((union ib_gid *)src->dgid));
  136. } else {
  137. dst->rec_type = SA_PATH_REC_TYPE_IB;
  138. slid = htonl(ntohs(src->slid));
  139. dlid = htonl(ntohs(src->dlid));
  140. }
  141. memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
  142. memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
  143. sa_path_set_dlid(dst, dlid);
  144. sa_path_set_slid(dst, slid);
  145. sa_path_set_raw_traffic(dst, src->raw_traffic);
  146. dst->flow_label = src->flow_label;
  147. dst->hop_limit = src->hop_limit;
  148. dst->traffic_class = src->traffic_class;
  149. dst->reversible = src->reversible;
  150. dst->numb_path = src->numb_path;
  151. dst->pkey = src->pkey;
  152. dst->sl = src->sl;
  153. dst->mtu_selector = src->mtu_selector;
  154. dst->mtu = src->mtu;
  155. dst->rate_selector = src->rate_selector;
  156. dst->rate = src->rate;
  157. dst->packet_life_time = src->packet_life_time;
  158. dst->preference = src->preference;
  159. dst->packet_life_time_selector = src->packet_life_time_selector;
  160. /* TODO: No need to set this */
  161. sa_path_set_dmac_zero(dst);
  162. sa_path_set_ndev(dst, NULL);
  163. sa_path_set_ifindex(dst, 0);
  164. }
  165. EXPORT_SYMBOL(ib_copy_path_rec_from_user);