ehca_hca.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * HCA query functions
  5. *
  6. * Authors: Heiko J Schick <schickhj@de.ibm.com>
  7. * Christoph Raisch <raisch@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 "ehca_tools.h"
  42. #include "hcp_if.h"
  43. int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
  44. {
  45. int ret = 0;
  46. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  47. ib_device);
  48. struct hipz_query_hca *rblock;
  49. rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
  50. if (!rblock) {
  51. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  52. return -ENOMEM;
  53. }
  54. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
  55. ehca_err(&shca->ib_device, "Can't query device properties");
  56. ret = -EINVAL;
  57. goto query_device1;
  58. }
  59. memset(props, 0, sizeof(struct ib_device_attr));
  60. props->fw_ver = rblock->hw_ver;
  61. props->max_mr_size = rblock->max_mr_size;
  62. props->vendor_id = rblock->vendor_id >> 8;
  63. props->vendor_part_id = rblock->vendor_part_id >> 16;
  64. props->hw_ver = rblock->hw_ver;
  65. props->max_qp = min_t(int, rblock->max_qp, INT_MAX);
  66. props->max_qp_wr = min_t(int, rblock->max_wqes_wq, INT_MAX);
  67. props->max_sge = min_t(int, rblock->max_sge, INT_MAX);
  68. props->max_sge_rd = min_t(int, rblock->max_sge_rd, INT_MAX);
  69. props->max_cq = min_t(int, rblock->max_cq, INT_MAX);
  70. props->max_cqe = min_t(int, rblock->max_cqe, INT_MAX);
  71. props->max_mr = min_t(int, rblock->max_mr, INT_MAX);
  72. props->max_mw = min_t(int, rblock->max_mw, INT_MAX);
  73. props->max_pd = min_t(int, rblock->max_pd, INT_MAX);
  74. props->max_ah = min_t(int, rblock->max_ah, INT_MAX);
  75. props->max_fmr = min_t(int, rblock->max_mr, INT_MAX);
  76. props->max_srq = 0;
  77. props->max_srq_wr = 0;
  78. props->max_srq_sge = 0;
  79. props->max_pkeys = 16;
  80. props->local_ca_ack_delay
  81. = rblock->local_ca_ack_delay;
  82. props->max_raw_ipv6_qp
  83. = min_t(int, rblock->max_raw_ipv6_qp, INT_MAX);
  84. props->max_raw_ethy_qp
  85. = min_t(int, rblock->max_raw_ethy_qp, INT_MAX);
  86. props->max_mcast_grp
  87. = min_t(int, rblock->max_mcast_grp, INT_MAX);
  88. props->max_mcast_qp_attach
  89. = min_t(int, rblock->max_mcast_qp_attach, INT_MAX);
  90. props->max_total_mcast_qp_attach
  91. = min_t(int, rblock->max_total_mcast_qp_attach, INT_MAX);
  92. query_device1:
  93. kfree(rblock);
  94. return ret;
  95. }
  96. int ehca_query_port(struct ib_device *ibdev,
  97. u8 port, struct ib_port_attr *props)
  98. {
  99. int ret = 0;
  100. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  101. ib_device);
  102. struct hipz_query_port *rblock;
  103. rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
  104. if (!rblock) {
  105. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  106. return -ENOMEM;
  107. }
  108. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  109. ehca_err(&shca->ib_device, "Can't query port properties");
  110. ret = -EINVAL;
  111. goto query_port1;
  112. }
  113. memset(props, 0, sizeof(struct ib_port_attr));
  114. props->state = rblock->state;
  115. switch (rblock->max_mtu) {
  116. case 0x1:
  117. props->active_mtu = props->max_mtu = IB_MTU_256;
  118. break;
  119. case 0x2:
  120. props->active_mtu = props->max_mtu = IB_MTU_512;
  121. break;
  122. case 0x3:
  123. props->active_mtu = props->max_mtu = IB_MTU_1024;
  124. break;
  125. case 0x4:
  126. props->active_mtu = props->max_mtu = IB_MTU_2048;
  127. break;
  128. case 0x5:
  129. props->active_mtu = props->max_mtu = IB_MTU_4096;
  130. break;
  131. default:
  132. ehca_err(&shca->ib_device, "Unknown MTU size: %x.",
  133. rblock->max_mtu);
  134. break;
  135. }
  136. props->gid_tbl_len = rblock->gid_tbl_len;
  137. props->max_msg_sz = rblock->max_msg_sz;
  138. props->bad_pkey_cntr = rblock->bad_pkey_cntr;
  139. props->qkey_viol_cntr = rblock->qkey_viol_cntr;
  140. props->pkey_tbl_len = rblock->pkey_tbl_len;
  141. props->lid = rblock->lid;
  142. props->sm_lid = rblock->sm_lid;
  143. props->lmc = rblock->lmc;
  144. props->sm_sl = rblock->sm_sl;
  145. props->subnet_timeout = rblock->subnet_timeout;
  146. props->init_type_reply = rblock->init_type_reply;
  147. props->active_width = IB_WIDTH_12X;
  148. props->active_speed = 0x1;
  149. query_port1:
  150. kfree(rblock);
  151. return ret;
  152. }
  153. int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
  154. {
  155. int ret = 0;
  156. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca, ib_device);
  157. struct hipz_query_port *rblock;
  158. if (index > 16) {
  159. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  160. return -EINVAL;
  161. }
  162. rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
  163. if (!rblock) {
  164. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  165. return -ENOMEM;
  166. }
  167. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  168. ehca_err(&shca->ib_device, "Can't query port properties");
  169. ret = -EINVAL;
  170. goto query_pkey1;
  171. }
  172. memcpy(pkey, &rblock->pkey_entries + index, sizeof(u16));
  173. query_pkey1:
  174. kfree(rblock);
  175. return ret;
  176. }
  177. int ehca_query_gid(struct ib_device *ibdev, u8 port,
  178. int index, union ib_gid *gid)
  179. {
  180. int ret = 0;
  181. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  182. ib_device);
  183. struct hipz_query_port *rblock;
  184. if (index > 255) {
  185. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  186. return -EINVAL;
  187. }
  188. rblock = kzalloc(H_CB_ALIGNMENT, GFP_KERNEL);
  189. if (!rblock) {
  190. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  191. return -ENOMEM;
  192. }
  193. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  194. ehca_err(&shca->ib_device, "Can't query port properties");
  195. ret = -EINVAL;
  196. goto query_gid1;
  197. }
  198. memcpy(&gid->raw[0], &rblock->gid_prefix, sizeof(u64));
  199. memcpy(&gid->raw[8], &rblock->guid_entries[index], sizeof(u64));
  200. query_gid1:
  201. kfree(rblock);
  202. return ret;
  203. }
  204. int ehca_modify_port(struct ib_device *ibdev,
  205. u8 port, int port_modify_mask,
  206. struct ib_port_modify *props)
  207. {
  208. /* Not implemented yet */
  209. return -EFAULT;
  210. }