ehca_hca.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 "ehca_iverbs.h"
  43. #include "hcp_if.h"
  44. int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)
  45. {
  46. int ret = 0;
  47. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  48. ib_device);
  49. struct hipz_query_hca *rblock;
  50. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  51. if (!rblock) {
  52. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  53. return -ENOMEM;
  54. }
  55. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
  56. ehca_err(&shca->ib_device, "Can't query device properties");
  57. ret = -EINVAL;
  58. goto query_device1;
  59. }
  60. memset(props, 0, sizeof(struct ib_device_attr));
  61. props->fw_ver = rblock->hw_ver;
  62. props->max_mr_size = rblock->max_mr_size;
  63. props->vendor_id = rblock->vendor_id >> 8;
  64. props->vendor_part_id = rblock->vendor_part_id >> 16;
  65. props->hw_ver = rblock->hw_ver;
  66. props->max_qp = min_t(int, rblock->max_qp, INT_MAX);
  67. props->max_qp_wr = min_t(int, rblock->max_wqes_wq, INT_MAX);
  68. props->max_sge = min_t(int, rblock->max_sge, INT_MAX);
  69. props->max_sge_rd = min_t(int, rblock->max_sge_rd, INT_MAX);
  70. props->max_cq = min_t(int, rblock->max_cq, INT_MAX);
  71. props->max_cqe = min_t(int, rblock->max_cqe, INT_MAX);
  72. props->max_mr = min_t(int, rblock->max_mr, INT_MAX);
  73. props->max_mw = min_t(int, rblock->max_mw, INT_MAX);
  74. props->max_pd = min_t(int, rblock->max_pd, INT_MAX);
  75. props->max_ah = min_t(int, rblock->max_ah, INT_MAX);
  76. props->max_fmr = min_t(int, rblock->max_mr, INT_MAX);
  77. props->max_srq = 0;
  78. props->max_srq_wr = 0;
  79. props->max_srq_sge = 0;
  80. props->max_pkeys = 16;
  81. props->local_ca_ack_delay
  82. = rblock->local_ca_ack_delay;
  83. props->max_raw_ipv6_qp
  84. = min_t(int, rblock->max_raw_ipv6_qp, INT_MAX);
  85. props->max_raw_ethy_qp
  86. = min_t(int, rblock->max_raw_ethy_qp, INT_MAX);
  87. props->max_mcast_grp
  88. = min_t(int, rblock->max_mcast_grp, INT_MAX);
  89. props->max_mcast_qp_attach
  90. = min_t(int, rblock->max_mcast_qp_attach, INT_MAX);
  91. props->max_total_mcast_qp_attach
  92. = min_t(int, rblock->max_total_mcast_qp_attach, INT_MAX);
  93. query_device1:
  94. ehca_free_fw_ctrlblock(rblock);
  95. return ret;
  96. }
  97. int ehca_query_port(struct ib_device *ibdev,
  98. u8 port, struct ib_port_attr *props)
  99. {
  100. int ret = 0;
  101. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  102. ib_device);
  103. struct hipz_query_port *rblock;
  104. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  105. if (!rblock) {
  106. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  107. return -ENOMEM;
  108. }
  109. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  110. ehca_err(&shca->ib_device, "Can't query port properties");
  111. ret = -EINVAL;
  112. goto query_port1;
  113. }
  114. memset(props, 0, sizeof(struct ib_port_attr));
  115. props->state = rblock->state;
  116. switch (rblock->max_mtu) {
  117. case 0x1:
  118. props->active_mtu = props->max_mtu = IB_MTU_256;
  119. break;
  120. case 0x2:
  121. props->active_mtu = props->max_mtu = IB_MTU_512;
  122. break;
  123. case 0x3:
  124. props->active_mtu = props->max_mtu = IB_MTU_1024;
  125. break;
  126. case 0x4:
  127. props->active_mtu = props->max_mtu = IB_MTU_2048;
  128. break;
  129. case 0x5:
  130. props->active_mtu = props->max_mtu = IB_MTU_4096;
  131. break;
  132. default:
  133. ehca_err(&shca->ib_device, "Unknown MTU size: %x.",
  134. rblock->max_mtu);
  135. break;
  136. }
  137. props->port_cap_flags = rblock->capability_mask;
  138. props->gid_tbl_len = rblock->gid_tbl_len;
  139. props->max_msg_sz = rblock->max_msg_sz;
  140. props->bad_pkey_cntr = rblock->bad_pkey_cntr;
  141. props->qkey_viol_cntr = rblock->qkey_viol_cntr;
  142. props->pkey_tbl_len = rblock->pkey_tbl_len;
  143. props->lid = rblock->lid;
  144. props->sm_lid = rblock->sm_lid;
  145. props->lmc = rblock->lmc;
  146. props->sm_sl = rblock->sm_sl;
  147. props->subnet_timeout = rblock->subnet_timeout;
  148. props->init_type_reply = rblock->init_type_reply;
  149. props->active_width = IB_WIDTH_12X;
  150. props->active_speed = 0x1;
  151. /* at the moment (logical) link state is always LINK_UP */
  152. props->phys_state = 0x5;
  153. query_port1:
  154. ehca_free_fw_ctrlblock(rblock);
  155. return ret;
  156. }
  157. int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
  158. {
  159. int ret = 0;
  160. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca, ib_device);
  161. struct hipz_query_port *rblock;
  162. if (index > 16) {
  163. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  164. return -EINVAL;
  165. }
  166. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  167. if (!rblock) {
  168. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  169. return -ENOMEM;
  170. }
  171. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  172. ehca_err(&shca->ib_device, "Can't query port properties");
  173. ret = -EINVAL;
  174. goto query_pkey1;
  175. }
  176. memcpy(pkey, &rblock->pkey_entries + index, sizeof(u16));
  177. query_pkey1:
  178. ehca_free_fw_ctrlblock(rblock);
  179. return ret;
  180. }
  181. int ehca_query_gid(struct ib_device *ibdev, u8 port,
  182. int index, union ib_gid *gid)
  183. {
  184. int ret = 0;
  185. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  186. ib_device);
  187. struct hipz_query_port *rblock;
  188. if (index > 255) {
  189. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  190. return -EINVAL;
  191. }
  192. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  193. if (!rblock) {
  194. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  195. return -ENOMEM;
  196. }
  197. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  198. ehca_err(&shca->ib_device, "Can't query port properties");
  199. ret = -EINVAL;
  200. goto query_gid1;
  201. }
  202. memcpy(&gid->raw[0], &rblock->gid_prefix, sizeof(u64));
  203. memcpy(&gid->raw[8], &rblock->guid_entries[index], sizeof(u64));
  204. query_gid1:
  205. ehca_free_fw_ctrlblock(rblock);
  206. return ret;
  207. }
  208. const u32 allowed_port_caps = (
  209. IB_PORT_SM | IB_PORT_LED_INFO_SUP | IB_PORT_CM_SUP |
  210. IB_PORT_SNMP_TUNNEL_SUP | IB_PORT_DEVICE_MGMT_SUP |
  211. IB_PORT_VENDOR_CLASS_SUP);
  212. int ehca_modify_port(struct ib_device *ibdev,
  213. u8 port, int port_modify_mask,
  214. struct ib_port_modify *props)
  215. {
  216. int ret = 0;
  217. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca, ib_device);
  218. struct hipz_query_port *rblock;
  219. u32 cap;
  220. u64 hret;
  221. if ((props->set_port_cap_mask | props->clr_port_cap_mask)
  222. & ~allowed_port_caps) {
  223. ehca_err(&shca->ib_device, "Non-changeable bits set in masks "
  224. "set=%x clr=%x allowed=%x", props->set_port_cap_mask,
  225. props->clr_port_cap_mask, allowed_port_caps);
  226. return -EINVAL;
  227. }
  228. if (mutex_lock_interruptible(&shca->modify_mutex))
  229. return -ERESTARTSYS;
  230. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  231. if (!rblock) {
  232. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  233. ret = -ENOMEM;
  234. goto modify_port1;
  235. }
  236. if (hipz_h_query_port(shca->ipz_hca_handle, port, rblock) != H_SUCCESS) {
  237. ehca_err(&shca->ib_device, "Can't query port properties");
  238. ret = -EINVAL;
  239. goto modify_port2;
  240. }
  241. cap = (rblock->capability_mask | props->set_port_cap_mask)
  242. & ~props->clr_port_cap_mask;
  243. hret = hipz_h_modify_port(shca->ipz_hca_handle, port,
  244. cap, props->init_type, port_modify_mask);
  245. if (hret != H_SUCCESS) {
  246. ehca_err(&shca->ib_device, "Modify port failed hret=%lx", hret);
  247. ret = -EINVAL;
  248. }
  249. modify_port2:
  250. ehca_free_fw_ctrlblock(rblock);
  251. modify_port1:
  252. mutex_unlock(&shca->modify_mutex);
  253. return ret;
  254. }