ehca_hca.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 <linux/gfp.h>
  42. #include "ehca_tools.h"
  43. #include "ehca_iverbs.h"
  44. #include "hcp_if.h"
  45. static unsigned int limit_uint(unsigned int value)
  46. {
  47. return min_t(unsigned int, value, INT_MAX);
  48. }
  49. int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
  50. struct ib_udata *uhw)
  51. {
  52. int i, ret = 0;
  53. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  54. ib_device);
  55. struct hipz_query_hca *rblock;
  56. static const u32 cap_mapping[] = {
  57. IB_DEVICE_RESIZE_MAX_WR, HCA_CAP_WQE_RESIZE,
  58. IB_DEVICE_BAD_PKEY_CNTR, HCA_CAP_BAD_P_KEY_CTR,
  59. IB_DEVICE_BAD_QKEY_CNTR, HCA_CAP_Q_KEY_VIOL_CTR,
  60. IB_DEVICE_RAW_MULTI, HCA_CAP_RAW_PACKET_MCAST,
  61. IB_DEVICE_AUTO_PATH_MIG, HCA_CAP_AUTO_PATH_MIG,
  62. IB_DEVICE_CHANGE_PHY_PORT, HCA_CAP_SQD_RTS_PORT_CHANGE,
  63. IB_DEVICE_UD_AV_PORT_ENFORCE, HCA_CAP_AH_PORT_NR_CHECK,
  64. IB_DEVICE_CURR_QP_STATE_MOD, HCA_CAP_CUR_QP_STATE_MOD,
  65. IB_DEVICE_SHUTDOWN_PORT, HCA_CAP_SHUTDOWN_PORT,
  66. IB_DEVICE_INIT_TYPE, HCA_CAP_INIT_TYPE,
  67. IB_DEVICE_PORT_ACTIVE_EVENT, HCA_CAP_PORT_ACTIVE_EVENT,
  68. };
  69. if (uhw->inlen || uhw->outlen)
  70. return -EINVAL;
  71. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  72. if (!rblock) {
  73. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  74. return -ENOMEM;
  75. }
  76. if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {
  77. ehca_err(&shca->ib_device, "Can't query device properties");
  78. ret = -EINVAL;
  79. goto query_device1;
  80. }
  81. memset(props, 0, sizeof(struct ib_device_attr));
  82. props->page_size_cap = shca->hca_cap_mr_pgsize;
  83. props->fw_ver = rblock->hw_ver;
  84. props->max_mr_size = rblock->max_mr_size;
  85. props->vendor_id = rblock->vendor_id >> 8;
  86. props->vendor_part_id = rblock->vendor_part_id >> 16;
  87. props->hw_ver = rblock->hw_ver;
  88. props->max_qp = limit_uint(rblock->max_qp);
  89. props->max_qp_wr = limit_uint(rblock->max_wqes_wq);
  90. props->max_sge = limit_uint(rblock->max_sge);
  91. props->max_sge_rd = limit_uint(rblock->max_sge_rd);
  92. props->max_cq = limit_uint(rblock->max_cq);
  93. props->max_cqe = limit_uint(rblock->max_cqe);
  94. props->max_mr = limit_uint(rblock->max_mr);
  95. props->max_mw = limit_uint(rblock->max_mw);
  96. props->max_pd = limit_uint(rblock->max_pd);
  97. props->max_ah = limit_uint(rblock->max_ah);
  98. props->max_ee = limit_uint(rblock->max_rd_ee_context);
  99. props->max_rdd = limit_uint(rblock->max_rd_domain);
  100. props->max_fmr = limit_uint(rblock->max_mr);
  101. props->max_qp_rd_atom = limit_uint(rblock->max_rr_qp);
  102. props->max_ee_rd_atom = limit_uint(rblock->max_rr_ee_context);
  103. props->max_res_rd_atom = limit_uint(rblock->max_rr_hca);
  104. props->max_qp_init_rd_atom = limit_uint(rblock->max_act_wqs_qp);
  105. props->max_ee_init_rd_atom = limit_uint(rblock->max_act_wqs_ee_context);
  106. if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {
  107. props->max_srq = limit_uint(props->max_qp);
  108. props->max_srq_wr = limit_uint(props->max_qp_wr);
  109. props->max_srq_sge = 3;
  110. }
  111. props->max_pkeys = 16;
  112. /* Some FW versions say 0 here; insert sensible value in that case */
  113. props->local_ca_ack_delay = rblock->local_ca_ack_delay ?
  114. min_t(u8, rblock->local_ca_ack_delay, 255) : 12;
  115. props->max_raw_ipv6_qp = limit_uint(rblock->max_raw_ipv6_qp);
  116. props->max_raw_ethy_qp = limit_uint(rblock->max_raw_ethy_qp);
  117. props->max_mcast_grp = limit_uint(rblock->max_mcast_grp);
  118. props->max_mcast_qp_attach = limit_uint(rblock->max_mcast_qp_attach);
  119. props->max_total_mcast_qp_attach
  120. = limit_uint(rblock->max_total_mcast_qp_attach);
  121. /* translate device capabilities */
  122. props->device_cap_flags = IB_DEVICE_SYS_IMAGE_GUID |
  123. IB_DEVICE_RC_RNR_NAK_GEN | IB_DEVICE_N_NOTIFY_CQ;
  124. for (i = 0; i < ARRAY_SIZE(cap_mapping); i += 2)
  125. if (rblock->hca_cap_indicators & cap_mapping[i + 1])
  126. props->device_cap_flags |= cap_mapping[i];
  127. query_device1:
  128. ehca_free_fw_ctrlblock(rblock);
  129. return ret;
  130. }
  131. static enum ib_mtu map_mtu(struct ehca_shca *shca, u32 fw_mtu)
  132. {
  133. switch (fw_mtu) {
  134. case 0x1:
  135. return IB_MTU_256;
  136. case 0x2:
  137. return IB_MTU_512;
  138. case 0x3:
  139. return IB_MTU_1024;
  140. case 0x4:
  141. return IB_MTU_2048;
  142. case 0x5:
  143. return IB_MTU_4096;
  144. default:
  145. ehca_err(&shca->ib_device, "Unknown MTU size: %x.",
  146. fw_mtu);
  147. return 0;
  148. }
  149. }
  150. static u8 map_number_of_vls(struct ehca_shca *shca, u32 vl_cap)
  151. {
  152. switch (vl_cap) {
  153. case 0x1:
  154. return 1;
  155. case 0x2:
  156. return 2;
  157. case 0x3:
  158. return 4;
  159. case 0x4:
  160. return 8;
  161. case 0x5:
  162. return 15;
  163. default:
  164. ehca_err(&shca->ib_device, "invalid Vl Capability: %x.",
  165. vl_cap);
  166. return 0;
  167. }
  168. }
  169. int ehca_query_port(struct ib_device *ibdev,
  170. u8 port, struct ib_port_attr *props)
  171. {
  172. int ret = 0;
  173. u64 h_ret;
  174. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  175. ib_device);
  176. struct hipz_query_port *rblock;
  177. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  178. if (!rblock) {
  179. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  180. return -ENOMEM;
  181. }
  182. h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);
  183. if (h_ret != H_SUCCESS) {
  184. ehca_err(&shca->ib_device, "Can't query port properties");
  185. ret = -EINVAL;
  186. goto query_port1;
  187. }
  188. memset(props, 0, sizeof(struct ib_port_attr));
  189. props->active_mtu = props->max_mtu = map_mtu(shca, rblock->max_mtu);
  190. props->port_cap_flags = rblock->capability_mask;
  191. props->gid_tbl_len = rblock->gid_tbl_len;
  192. if (rblock->max_msg_sz)
  193. props->max_msg_sz = rblock->max_msg_sz;
  194. else
  195. props->max_msg_sz = 0x1 << 31;
  196. props->bad_pkey_cntr = rblock->bad_pkey_cntr;
  197. props->qkey_viol_cntr = rblock->qkey_viol_cntr;
  198. props->pkey_tbl_len = rblock->pkey_tbl_len;
  199. props->lid = rblock->lid;
  200. props->sm_lid = rblock->sm_lid;
  201. props->lmc = rblock->lmc;
  202. props->sm_sl = rblock->sm_sl;
  203. props->subnet_timeout = rblock->subnet_timeout;
  204. props->init_type_reply = rblock->init_type_reply;
  205. props->max_vl_num = map_number_of_vls(shca, rblock->vl_cap);
  206. if (rblock->state && rblock->phys_width) {
  207. props->phys_state = rblock->phys_pstate;
  208. props->state = rblock->phys_state;
  209. props->active_width = rblock->phys_width;
  210. props->active_speed = rblock->phys_speed;
  211. } else {
  212. /* old firmware releases don't report physical
  213. * port info, so use default values
  214. */
  215. props->phys_state = 5;
  216. props->state = rblock->state;
  217. props->active_width = IB_WIDTH_12X;
  218. props->active_speed = IB_SPEED_SDR;
  219. }
  220. query_port1:
  221. ehca_free_fw_ctrlblock(rblock);
  222. return ret;
  223. }
  224. int ehca_query_sma_attr(struct ehca_shca *shca,
  225. u8 port, struct ehca_sma_attr *attr)
  226. {
  227. int ret = 0;
  228. u64 h_ret;
  229. struct hipz_query_port *rblock;
  230. rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC);
  231. if (!rblock) {
  232. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  233. return -ENOMEM;
  234. }
  235. h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);
  236. if (h_ret != H_SUCCESS) {
  237. ehca_err(&shca->ib_device, "Can't query port properties");
  238. ret = -EINVAL;
  239. goto query_sma_attr1;
  240. }
  241. memset(attr, 0, sizeof(struct ehca_sma_attr));
  242. attr->lid = rblock->lid;
  243. attr->lmc = rblock->lmc;
  244. attr->sm_sl = rblock->sm_sl;
  245. attr->sm_lid = rblock->sm_lid;
  246. attr->pkey_tbl_len = rblock->pkey_tbl_len;
  247. memcpy(attr->pkeys, rblock->pkey_entries, sizeof(attr->pkeys));
  248. query_sma_attr1:
  249. ehca_free_fw_ctrlblock(rblock);
  250. return ret;
  251. }
  252. int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)
  253. {
  254. int ret = 0;
  255. u64 h_ret;
  256. struct ehca_shca *shca;
  257. struct hipz_query_port *rblock;
  258. shca = container_of(ibdev, struct ehca_shca, ib_device);
  259. if (index > 16) {
  260. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  261. return -EINVAL;
  262. }
  263. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  264. if (!rblock) {
  265. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  266. return -ENOMEM;
  267. }
  268. h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);
  269. if (h_ret != H_SUCCESS) {
  270. ehca_err(&shca->ib_device, "Can't query port properties");
  271. ret = -EINVAL;
  272. goto query_pkey1;
  273. }
  274. memcpy(pkey, &rblock->pkey_entries + index, sizeof(u16));
  275. query_pkey1:
  276. ehca_free_fw_ctrlblock(rblock);
  277. return ret;
  278. }
  279. int ehca_query_gid(struct ib_device *ibdev, u8 port,
  280. int index, union ib_gid *gid)
  281. {
  282. int ret = 0;
  283. u64 h_ret;
  284. struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,
  285. ib_device);
  286. struct hipz_query_port *rblock;
  287. if (index < 0 || index > 255) {
  288. ehca_err(&shca->ib_device, "Invalid index: %x.", index);
  289. return -EINVAL;
  290. }
  291. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  292. if (!rblock) {
  293. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  294. return -ENOMEM;
  295. }
  296. h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);
  297. if (h_ret != H_SUCCESS) {
  298. ehca_err(&shca->ib_device, "Can't query port properties");
  299. ret = -EINVAL;
  300. goto query_gid1;
  301. }
  302. memcpy(&gid->raw[0], &rblock->gid_prefix, sizeof(u64));
  303. memcpy(&gid->raw[8], &rblock->guid_entries[index], sizeof(u64));
  304. query_gid1:
  305. ehca_free_fw_ctrlblock(rblock);
  306. return ret;
  307. }
  308. static const u32 allowed_port_caps = (
  309. IB_PORT_SM | IB_PORT_LED_INFO_SUP | IB_PORT_CM_SUP |
  310. IB_PORT_SNMP_TUNNEL_SUP | IB_PORT_DEVICE_MGMT_SUP |
  311. IB_PORT_VENDOR_CLASS_SUP);
  312. int ehca_modify_port(struct ib_device *ibdev,
  313. u8 port, int port_modify_mask,
  314. struct ib_port_modify *props)
  315. {
  316. int ret = 0;
  317. struct ehca_shca *shca;
  318. struct hipz_query_port *rblock;
  319. u32 cap;
  320. u64 hret;
  321. shca = container_of(ibdev, struct ehca_shca, ib_device);
  322. if ((props->set_port_cap_mask | props->clr_port_cap_mask)
  323. & ~allowed_port_caps) {
  324. ehca_err(&shca->ib_device, "Non-changeable bits set in masks "
  325. "set=%x clr=%x allowed=%x", props->set_port_cap_mask,
  326. props->clr_port_cap_mask, allowed_port_caps);
  327. return -EINVAL;
  328. }
  329. if (mutex_lock_interruptible(&shca->modify_mutex))
  330. return -ERESTARTSYS;
  331. rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  332. if (!rblock) {
  333. ehca_err(&shca->ib_device, "Can't allocate rblock memory.");
  334. ret = -ENOMEM;
  335. goto modify_port1;
  336. }
  337. hret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);
  338. if (hret != H_SUCCESS) {
  339. ehca_err(&shca->ib_device, "Can't query port properties");
  340. ret = -EINVAL;
  341. goto modify_port2;
  342. }
  343. cap = (rblock->capability_mask | props->set_port_cap_mask)
  344. & ~props->clr_port_cap_mask;
  345. hret = hipz_h_modify_port(shca->ipz_hca_handle, port,
  346. cap, props->init_type, port_modify_mask);
  347. if (hret != H_SUCCESS) {
  348. ehca_err(&shca->ib_device, "Modify port failed h_ret=%lli",
  349. hret);
  350. ret = -EINVAL;
  351. }
  352. modify_port2:
  353. ehca_free_fw_ctrlblock(rblock);
  354. modify_port1:
  355. mutex_unlock(&shca->modify_mutex);
  356. return ret;
  357. }