ehca_sqp.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * SQP functions
  5. *
  6. * Authors: Khadija Souissi <souissi@de.ibm.com>
  7. * Heiko J Schick <schickhj@de.ibm.com>
  8. *
  9. * Copyright (c) 2005 IBM Corporation
  10. *
  11. * All rights reserved.
  12. *
  13. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  14. * BSD.
  15. *
  16. * OpenIB BSD License
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted provided that the following conditions are met:
  20. *
  21. * Redistributions of source code must retain the above copyright notice, this
  22. * list of conditions and the following disclaimer.
  23. *
  24. * Redistributions in binary form must reproduce the above copyright notice,
  25. * this list of conditions and the following disclaimer in the documentation
  26. * and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  36. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  37. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. */
  41. #include <rdma/ib_mad.h>
  42. #include "ehca_classes.h"
  43. #include "ehca_tools.h"
  44. #include "ehca_iverbs.h"
  45. #include "hcp_if.h"
  46. #define IB_MAD_STATUS_REDIRECT cpu_to_be16(0x0002)
  47. #define IB_MAD_STATUS_UNSUP_VERSION cpu_to_be16(0x0004)
  48. #define IB_MAD_STATUS_UNSUP_METHOD cpu_to_be16(0x0008)
  49. #define IB_PMA_CLASS_PORT_INFO cpu_to_be16(0x0001)
  50. /**
  51. * ehca_define_sqp - Defines special queue pair 1 (GSI QP). When special queue
  52. * pair is created successfully, the corresponding port gets active.
  53. *
  54. * Define Special Queue pair 0 (SMI QP) is still not supported.
  55. *
  56. * @qp_init_attr: Queue pair init attributes with port and queue pair type
  57. */
  58. u64 ehca_define_sqp(struct ehca_shca *shca,
  59. struct ehca_qp *ehca_qp,
  60. struct ib_qp_init_attr *qp_init_attr)
  61. {
  62. u32 pma_qp_nr, bma_qp_nr;
  63. u64 ret;
  64. u8 port = qp_init_attr->port_num;
  65. int counter;
  66. shca->sport[port - 1].port_state = IB_PORT_DOWN;
  67. switch (qp_init_attr->qp_type) {
  68. case IB_QPT_SMI:
  69. /* function not supported yet */
  70. break;
  71. case IB_QPT_GSI:
  72. ret = hipz_h_define_aqp1(shca->ipz_hca_handle,
  73. ehca_qp->ipz_qp_handle,
  74. ehca_qp->galpas.kernel,
  75. (u32) qp_init_attr->port_num,
  76. &pma_qp_nr, &bma_qp_nr);
  77. if (ret != H_SUCCESS) {
  78. ehca_err(&shca->ib_device,
  79. "Can't define AQP1 for port %x. h_ret=%lli",
  80. port, ret);
  81. return ret;
  82. }
  83. shca->sport[port - 1].pma_qp_nr = pma_qp_nr;
  84. ehca_dbg(&shca->ib_device, "port=%x pma_qp_nr=%x",
  85. port, pma_qp_nr);
  86. break;
  87. default:
  88. ehca_err(&shca->ib_device, "invalid qp_type=%x",
  89. qp_init_attr->qp_type);
  90. return H_PARAMETER;
  91. }
  92. if (ehca_nr_ports < 0) /* autodetect mode */
  93. return H_SUCCESS;
  94. for (counter = 0;
  95. shca->sport[port - 1].port_state != IB_PORT_ACTIVE &&
  96. counter < ehca_port_act_time;
  97. counter++) {
  98. ehca_dbg(&shca->ib_device, "... wait until port %x is active",
  99. port);
  100. msleep_interruptible(1000);
  101. }
  102. if (counter == ehca_port_act_time) {
  103. ehca_err(&shca->ib_device, "Port %x is not active.", port);
  104. return H_HARDWARE;
  105. }
  106. return H_SUCCESS;
  107. }
  108. struct ib_perf {
  109. struct ib_mad_hdr mad_hdr;
  110. u8 reserved[40];
  111. u8 data[192];
  112. } __attribute__ ((packed));
  113. /* TC/SL/FL packed into 32 bits, as in ClassPortInfo */
  114. struct tcslfl {
  115. u32 tc:8;
  116. u32 sl:4;
  117. u32 fl:20;
  118. } __attribute__ ((packed));
  119. /* IP Version/TC/FL packed into 32 bits, as in GRH */
  120. struct vertcfl {
  121. u32 ver:4;
  122. u32 tc:8;
  123. u32 fl:20;
  124. } __attribute__ ((packed));
  125. static int ehca_process_perf(struct ib_device *ibdev, u8 port_num,
  126. struct ib_wc *in_wc, struct ib_grh *in_grh,
  127. struct ib_mad *in_mad, struct ib_mad *out_mad)
  128. {
  129. struct ib_perf *in_perf = (struct ib_perf *)in_mad;
  130. struct ib_perf *out_perf = (struct ib_perf *)out_mad;
  131. struct ib_class_port_info *poi =
  132. (struct ib_class_port_info *)out_perf->data;
  133. struct tcslfl *tcslfl =
  134. (struct tcslfl *)&poi->redirect_tcslfl;
  135. struct ehca_shca *shca =
  136. container_of(ibdev, struct ehca_shca, ib_device);
  137. struct ehca_sport *sport = &shca->sport[port_num - 1];
  138. ehca_dbg(ibdev, "method=%x", in_perf->mad_hdr.method);
  139. *out_mad = *in_mad;
  140. if (in_perf->mad_hdr.class_version != 1) {
  141. ehca_warn(ibdev, "Unsupported class_version=%x",
  142. in_perf->mad_hdr.class_version);
  143. out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_VERSION;
  144. goto perf_reply;
  145. }
  146. switch (in_perf->mad_hdr.method) {
  147. case IB_MGMT_METHOD_GET:
  148. case IB_MGMT_METHOD_SET:
  149. /* set class port info for redirection */
  150. out_perf->mad_hdr.attr_id = IB_PMA_CLASS_PORT_INFO;
  151. out_perf->mad_hdr.status = IB_MAD_STATUS_REDIRECT;
  152. memset(poi, 0, sizeof(*poi));
  153. poi->base_version = 1;
  154. poi->class_version = 1;
  155. poi->resp_time_value = 18;
  156. /* copy local routing information from WC where applicable */
  157. tcslfl->sl = in_wc->sl;
  158. poi->redirect_lid =
  159. sport->saved_attr.lid | in_wc->dlid_path_bits;
  160. poi->redirect_qp = sport->pma_qp_nr;
  161. poi->redirect_qkey = IB_QP1_QKEY;
  162. ehca_query_pkey(ibdev, port_num, in_wc->pkey_index,
  163. &poi->redirect_pkey);
  164. /* if request was globally routed, copy route info */
  165. if (in_grh) {
  166. struct vertcfl *vertcfl =
  167. (struct vertcfl *)&in_grh->version_tclass_flow;
  168. memcpy(poi->redirect_gid, in_grh->dgid.raw,
  169. sizeof(poi->redirect_gid));
  170. tcslfl->tc = vertcfl->tc;
  171. tcslfl->fl = vertcfl->fl;
  172. } else
  173. /* else only fill in default GID */
  174. ehca_query_gid(ibdev, port_num, 0,
  175. (union ib_gid *)&poi->redirect_gid);
  176. ehca_dbg(ibdev, "ehca_pma_lid=%x ehca_pma_qp=%x",
  177. sport->saved_attr.lid, sport->pma_qp_nr);
  178. break;
  179. case IB_MGMT_METHOD_GET_RESP:
  180. return IB_MAD_RESULT_FAILURE;
  181. default:
  182. out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_METHOD;
  183. break;
  184. }
  185. perf_reply:
  186. out_perf->mad_hdr.method = IB_MGMT_METHOD_GET_RESP;
  187. return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
  188. }
  189. int ehca_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
  190. struct ib_wc *in_wc, struct ib_grh *in_grh,
  191. struct ib_mad *in_mad, struct ib_mad *out_mad)
  192. {
  193. int ret;
  194. if (!port_num || port_num > ibdev->phys_port_cnt || !in_wc)
  195. return IB_MAD_RESULT_FAILURE;
  196. /* accept only pma request */
  197. if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)
  198. return IB_MAD_RESULT_SUCCESS;
  199. ehca_dbg(ibdev, "port_num=%x src_qp=%x", port_num, in_wc->src_qp);
  200. ret = ehca_process_perf(ibdev, port_num, in_wc, in_grh,
  201. in_mad, out_mad);
  202. return ret;
  203. }