hcp_if.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * Firmware Infiniband Interface code for POWER
  5. *
  6. * Authors: Christoph Raisch <raisch@de.ibm.com>
  7. * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  8. * Joachim Fenkes <fenkes@de.ibm.com>
  9. * Gerd Bayer <gerd.bayer@de.ibm.com>
  10. * Waleri Fomin <fomin@de.ibm.com>
  11. *
  12. * Copyright (c) 2005 IBM Corporation
  13. *
  14. * All rights reserved.
  15. *
  16. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  17. * BSD.
  18. *
  19. * OpenIB BSD License
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions are met:
  23. *
  24. * Redistributions of source code must retain the above copyright notice, this
  25. * list of conditions and the following disclaimer.
  26. *
  27. * Redistributions in binary form must reproduce the above copyright notice,
  28. * this list of conditions and the following disclaimer in the documentation
  29. * and/or other materials
  30. * provided with the distribution.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  36. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  39. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  40. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. * POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. #include <asm/hvcall.h>
  45. #include "ehca_tools.h"
  46. #include "hcp_if.h"
  47. #include "hcp_phyp.h"
  48. #include "hipz_fns.h"
  49. #include "ipz_pt_fn.h"
  50. #define H_ALL_RES_QP_ENHANCED_OPS EHCA_BMASK_IBM(9, 11)
  51. #define H_ALL_RES_QP_PTE_PIN EHCA_BMASK_IBM(12, 12)
  52. #define H_ALL_RES_QP_SERVICE_TYPE EHCA_BMASK_IBM(13, 15)
  53. #define H_ALL_RES_QP_STORAGE EHCA_BMASK_IBM(16, 17)
  54. #define H_ALL_RES_QP_LL_RQ_CQE_POSTING EHCA_BMASK_IBM(18, 18)
  55. #define H_ALL_RES_QP_LL_SQ_CQE_POSTING EHCA_BMASK_IBM(19, 21)
  56. #define H_ALL_RES_QP_SIGNALING_TYPE EHCA_BMASK_IBM(22, 23)
  57. #define H_ALL_RES_QP_UD_AV_LKEY_CTRL EHCA_BMASK_IBM(31, 31)
  58. #define H_ALL_RES_QP_SMALL_SQ_PAGE_SIZE EHCA_BMASK_IBM(32, 35)
  59. #define H_ALL_RES_QP_SMALL_RQ_PAGE_SIZE EHCA_BMASK_IBM(36, 39)
  60. #define H_ALL_RES_QP_RESOURCE_TYPE EHCA_BMASK_IBM(56, 63)
  61. #define H_ALL_RES_QP_MAX_OUTST_SEND_WR EHCA_BMASK_IBM(0, 15)
  62. #define H_ALL_RES_QP_MAX_OUTST_RECV_WR EHCA_BMASK_IBM(16, 31)
  63. #define H_ALL_RES_QP_MAX_SEND_SGE EHCA_BMASK_IBM(32, 39)
  64. #define H_ALL_RES_QP_MAX_RECV_SGE EHCA_BMASK_IBM(40, 47)
  65. #define H_ALL_RES_QP_UD_AV_LKEY EHCA_BMASK_IBM(32, 63)
  66. #define H_ALL_RES_QP_SRQ_QP_TOKEN EHCA_BMASK_IBM(0, 31)
  67. #define H_ALL_RES_QP_SRQ_QP_HANDLE EHCA_BMASK_IBM(0, 64)
  68. #define H_ALL_RES_QP_SRQ_LIMIT EHCA_BMASK_IBM(48, 63)
  69. #define H_ALL_RES_QP_SRQ_QPN EHCA_BMASK_IBM(40, 63)
  70. #define H_ALL_RES_QP_ACT_OUTST_SEND_WR EHCA_BMASK_IBM(16, 31)
  71. #define H_ALL_RES_QP_ACT_OUTST_RECV_WR EHCA_BMASK_IBM(48, 63)
  72. #define H_ALL_RES_QP_ACT_SEND_SGE EHCA_BMASK_IBM(8, 15)
  73. #define H_ALL_RES_QP_ACT_RECV_SGE EHCA_BMASK_IBM(24, 31)
  74. #define H_ALL_RES_QP_SQUEUE_SIZE_PAGES EHCA_BMASK_IBM(0, 31)
  75. #define H_ALL_RES_QP_RQUEUE_SIZE_PAGES EHCA_BMASK_IBM(32, 63)
  76. #define H_MP_INIT_TYPE EHCA_BMASK_IBM(44, 47)
  77. #define H_MP_SHUTDOWN EHCA_BMASK_IBM(48, 48)
  78. #define H_MP_RESET_QKEY_CTR EHCA_BMASK_IBM(49, 49)
  79. #define HCALL4_REGS_FORMAT "r4=%lx r5=%lx r6=%lx r7=%lx"
  80. #define HCALL7_REGS_FORMAT HCALL4_REGS_FORMAT " r8=%lx r9=%lx r10=%lx"
  81. #define HCALL9_REGS_FORMAT HCALL7_REGS_FORMAT " r11=%lx r12=%lx"
  82. static DEFINE_SPINLOCK(hcall_lock);
  83. static long ehca_plpar_hcall_norets(unsigned long opcode,
  84. unsigned long arg1,
  85. unsigned long arg2,
  86. unsigned long arg3,
  87. unsigned long arg4,
  88. unsigned long arg5,
  89. unsigned long arg6,
  90. unsigned long arg7)
  91. {
  92. long ret;
  93. int i, sleep_msecs;
  94. unsigned long flags = 0;
  95. if (unlikely(ehca_debug_level >= 2))
  96. ehca_gen_dbg("opcode=%lx " HCALL7_REGS_FORMAT,
  97. opcode, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
  98. for (i = 0; i < 5; i++) {
  99. /* serialize hCalls to work around firmware issue */
  100. if (ehca_lock_hcalls)
  101. spin_lock_irqsave(&hcall_lock, flags);
  102. ret = plpar_hcall_norets(opcode, arg1, arg2, arg3, arg4,
  103. arg5, arg6, arg7);
  104. if (ehca_lock_hcalls)
  105. spin_unlock_irqrestore(&hcall_lock, flags);
  106. if (H_IS_LONG_BUSY(ret)) {
  107. sleep_msecs = get_longbusy_msecs(ret);
  108. msleep_interruptible(sleep_msecs);
  109. continue;
  110. }
  111. if (ret < H_SUCCESS)
  112. ehca_gen_err("opcode=%lx ret=%li " HCALL7_REGS_FORMAT,
  113. opcode, ret, arg1, arg2, arg3,
  114. arg4, arg5, arg6, arg7);
  115. else
  116. if (unlikely(ehca_debug_level >= 2))
  117. ehca_gen_dbg("opcode=%lx ret=%li", opcode, ret);
  118. return ret;
  119. }
  120. return H_BUSY;
  121. }
  122. static long ehca_plpar_hcall9(unsigned long opcode,
  123. unsigned long *outs, /* array of 9 outputs */
  124. unsigned long arg1,
  125. unsigned long arg2,
  126. unsigned long arg3,
  127. unsigned long arg4,
  128. unsigned long arg5,
  129. unsigned long arg6,
  130. unsigned long arg7,
  131. unsigned long arg8,
  132. unsigned long arg9)
  133. {
  134. long ret;
  135. int i, sleep_msecs;
  136. unsigned long flags = 0;
  137. if (unlikely(ehca_debug_level >= 2))
  138. ehca_gen_dbg("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT, opcode,
  139. arg1, arg2, arg3, arg4, arg5,
  140. arg6, arg7, arg8, arg9);
  141. for (i = 0; i < 5; i++) {
  142. /* serialize hCalls to work around firmware issue */
  143. if (ehca_lock_hcalls)
  144. spin_lock_irqsave(&hcall_lock, flags);
  145. ret = plpar_hcall9(opcode, outs,
  146. arg1, arg2, arg3, arg4, arg5,
  147. arg6, arg7, arg8, arg9);
  148. if (ehca_lock_hcalls)
  149. spin_unlock_irqrestore(&hcall_lock, flags);
  150. if (H_IS_LONG_BUSY(ret)) {
  151. sleep_msecs = get_longbusy_msecs(ret);
  152. msleep_interruptible(sleep_msecs);
  153. continue;
  154. }
  155. if (ret < H_SUCCESS) {
  156. ehca_gen_err("INPUT -- opcode=%lx " HCALL9_REGS_FORMAT,
  157. opcode, arg1, arg2, arg3, arg4, arg5,
  158. arg6, arg7, arg8, arg9);
  159. ehca_gen_err("OUTPUT -- ret=%li " HCALL9_REGS_FORMAT,
  160. ret, outs[0], outs[1], outs[2], outs[3],
  161. outs[4], outs[5], outs[6], outs[7],
  162. outs[8]);
  163. } else if (unlikely(ehca_debug_level >= 2))
  164. ehca_gen_dbg("OUTPUT -- ret=%li " HCALL9_REGS_FORMAT,
  165. ret, outs[0], outs[1], outs[2], outs[3],
  166. outs[4], outs[5], outs[6], outs[7],
  167. outs[8]);
  168. return ret;
  169. }
  170. return H_BUSY;
  171. }
  172. u64 hipz_h_alloc_resource_eq(const struct ipz_adapter_handle adapter_handle,
  173. struct ehca_pfeq *pfeq,
  174. const u32 neq_control,
  175. const u32 number_of_entries,
  176. struct ipz_eq_handle *eq_handle,
  177. u32 *act_nr_of_entries,
  178. u32 *act_pages,
  179. u32 *eq_ist)
  180. {
  181. u64 ret;
  182. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  183. u64 allocate_controls;
  184. /* resource type */
  185. allocate_controls = 3ULL;
  186. /* ISN is associated */
  187. if (neq_control != 1)
  188. allocate_controls = (1ULL << (63 - 7)) | allocate_controls;
  189. else /* notification event queue */
  190. allocate_controls = (1ULL << 63) | allocate_controls;
  191. ret = ehca_plpar_hcall9(H_ALLOC_RESOURCE, outs,
  192. adapter_handle.handle, /* r4 */
  193. allocate_controls, /* r5 */
  194. number_of_entries, /* r6 */
  195. 0, 0, 0, 0, 0, 0);
  196. eq_handle->handle = outs[0];
  197. *act_nr_of_entries = (u32)outs[3];
  198. *act_pages = (u32)outs[4];
  199. *eq_ist = (u32)outs[5];
  200. if (ret == H_NOT_ENOUGH_RESOURCES)
  201. ehca_gen_err("Not enough resource - ret=%lli ", ret);
  202. return ret;
  203. }
  204. u64 hipz_h_reset_event(const struct ipz_adapter_handle adapter_handle,
  205. struct ipz_eq_handle eq_handle,
  206. const u64 event_mask)
  207. {
  208. return ehca_plpar_hcall_norets(H_RESET_EVENTS,
  209. adapter_handle.handle, /* r4 */
  210. eq_handle.handle, /* r5 */
  211. event_mask, /* r6 */
  212. 0, 0, 0, 0);
  213. }
  214. u64 hipz_h_alloc_resource_cq(const struct ipz_adapter_handle adapter_handle,
  215. struct ehca_cq *cq,
  216. struct ehca_alloc_cq_parms *param)
  217. {
  218. int rc;
  219. u64 ret;
  220. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  221. ret = ehca_plpar_hcall9(H_ALLOC_RESOURCE, outs,
  222. adapter_handle.handle, /* r4 */
  223. 2, /* r5 */
  224. param->eq_handle.handle, /* r6 */
  225. cq->token, /* r7 */
  226. param->nr_cqe, /* r8 */
  227. 0, 0, 0, 0);
  228. cq->ipz_cq_handle.handle = outs[0];
  229. param->act_nr_of_entries = (u32)outs[3];
  230. param->act_pages = (u32)outs[4];
  231. if (ret == H_SUCCESS) {
  232. rc = hcp_galpas_ctor(&cq->galpas, 0, outs[5], outs[6]);
  233. if (rc) {
  234. ehca_gen_err("Could not establish HW access. rc=%d paddr=%#lx",
  235. rc, outs[5]);
  236. ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  237. adapter_handle.handle, /* r4 */
  238. cq->ipz_cq_handle.handle, /* r5 */
  239. 0, 0, 0, 0, 0);
  240. ret = H_NO_MEM;
  241. }
  242. }
  243. if (ret == H_NOT_ENOUGH_RESOURCES)
  244. ehca_gen_err("Not enough resources. ret=%lli", ret);
  245. return ret;
  246. }
  247. u64 hipz_h_alloc_resource_qp(const struct ipz_adapter_handle adapter_handle,
  248. struct ehca_alloc_qp_parms *parms, int is_user)
  249. {
  250. int rc;
  251. u64 ret;
  252. u64 allocate_controls, max_r10_reg, r11, r12;
  253. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  254. allocate_controls =
  255. EHCA_BMASK_SET(H_ALL_RES_QP_ENHANCED_OPS, parms->ext_type)
  256. | EHCA_BMASK_SET(H_ALL_RES_QP_PTE_PIN, 0)
  257. | EHCA_BMASK_SET(H_ALL_RES_QP_SERVICE_TYPE, parms->servicetype)
  258. | EHCA_BMASK_SET(H_ALL_RES_QP_SIGNALING_TYPE, parms->sigtype)
  259. | EHCA_BMASK_SET(H_ALL_RES_QP_STORAGE, parms->qp_storage)
  260. | EHCA_BMASK_SET(H_ALL_RES_QP_SMALL_SQ_PAGE_SIZE,
  261. parms->squeue.page_size)
  262. | EHCA_BMASK_SET(H_ALL_RES_QP_SMALL_RQ_PAGE_SIZE,
  263. parms->rqueue.page_size)
  264. | EHCA_BMASK_SET(H_ALL_RES_QP_LL_RQ_CQE_POSTING,
  265. !!(parms->ll_comp_flags & LLQP_RECV_COMP))
  266. | EHCA_BMASK_SET(H_ALL_RES_QP_LL_SQ_CQE_POSTING,
  267. !!(parms->ll_comp_flags & LLQP_SEND_COMP))
  268. | EHCA_BMASK_SET(H_ALL_RES_QP_UD_AV_LKEY_CTRL,
  269. parms->ud_av_l_key_ctl)
  270. | EHCA_BMASK_SET(H_ALL_RES_QP_RESOURCE_TYPE, 1);
  271. max_r10_reg =
  272. EHCA_BMASK_SET(H_ALL_RES_QP_MAX_OUTST_SEND_WR,
  273. parms->squeue.max_wr + 1)
  274. | EHCA_BMASK_SET(H_ALL_RES_QP_MAX_OUTST_RECV_WR,
  275. parms->rqueue.max_wr + 1)
  276. | EHCA_BMASK_SET(H_ALL_RES_QP_MAX_SEND_SGE,
  277. parms->squeue.max_sge)
  278. | EHCA_BMASK_SET(H_ALL_RES_QP_MAX_RECV_SGE,
  279. parms->rqueue.max_sge);
  280. r11 = EHCA_BMASK_SET(H_ALL_RES_QP_SRQ_QP_TOKEN, parms->srq_token);
  281. if (parms->ext_type == EQPT_SRQ)
  282. r12 = EHCA_BMASK_SET(H_ALL_RES_QP_SRQ_LIMIT, parms->srq_limit);
  283. else
  284. r12 = EHCA_BMASK_SET(H_ALL_RES_QP_SRQ_QPN, parms->srq_qpn);
  285. ret = ehca_plpar_hcall9(H_ALLOC_RESOURCE, outs,
  286. adapter_handle.handle, /* r4 */
  287. allocate_controls, /* r5 */
  288. parms->send_cq_handle.handle,
  289. parms->recv_cq_handle.handle,
  290. parms->eq_handle.handle,
  291. ((u64)parms->token << 32) | parms->pd.value,
  292. max_r10_reg, r11, r12);
  293. parms->qp_handle.handle = outs[0];
  294. parms->real_qp_num = (u32)outs[1];
  295. parms->squeue.act_nr_wqes =
  296. (u16)EHCA_BMASK_GET(H_ALL_RES_QP_ACT_OUTST_SEND_WR, outs[2]);
  297. parms->rqueue.act_nr_wqes =
  298. (u16)EHCA_BMASK_GET(H_ALL_RES_QP_ACT_OUTST_RECV_WR, outs[2]);
  299. parms->squeue.act_nr_sges =
  300. (u8)EHCA_BMASK_GET(H_ALL_RES_QP_ACT_SEND_SGE, outs[3]);
  301. parms->rqueue.act_nr_sges =
  302. (u8)EHCA_BMASK_GET(H_ALL_RES_QP_ACT_RECV_SGE, outs[3]);
  303. parms->squeue.queue_size =
  304. (u32)EHCA_BMASK_GET(H_ALL_RES_QP_SQUEUE_SIZE_PAGES, outs[4]);
  305. parms->rqueue.queue_size =
  306. (u32)EHCA_BMASK_GET(H_ALL_RES_QP_RQUEUE_SIZE_PAGES, outs[4]);
  307. if (ret == H_SUCCESS) {
  308. rc = hcp_galpas_ctor(&parms->galpas, is_user, outs[6], outs[6]);
  309. if (rc) {
  310. ehca_gen_err("Could not establish HW access. rc=%d paddr=%#lx",
  311. rc, outs[6]);
  312. ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  313. adapter_handle.handle, /* r4 */
  314. parms->qp_handle.handle, /* r5 */
  315. 0, 0, 0, 0, 0);
  316. ret = H_NO_MEM;
  317. }
  318. }
  319. if (ret == H_NOT_ENOUGH_RESOURCES)
  320. ehca_gen_err("Not enough resources. ret=%lli", ret);
  321. return ret;
  322. }
  323. u64 hipz_h_query_port(const struct ipz_adapter_handle adapter_handle,
  324. const u8 port_id,
  325. struct hipz_query_port *query_port_response_block)
  326. {
  327. u64 ret;
  328. u64 r_cb = __pa(query_port_response_block);
  329. if (r_cb & (EHCA_PAGESIZE-1)) {
  330. ehca_gen_err("response block not page aligned");
  331. return H_PARAMETER;
  332. }
  333. ret = ehca_plpar_hcall_norets(H_QUERY_PORT,
  334. adapter_handle.handle, /* r4 */
  335. port_id, /* r5 */
  336. r_cb, /* r6 */
  337. 0, 0, 0, 0);
  338. if (ehca_debug_level >= 2)
  339. ehca_dmp(query_port_response_block, 64, "response_block");
  340. return ret;
  341. }
  342. u64 hipz_h_modify_port(const struct ipz_adapter_handle adapter_handle,
  343. const u8 port_id, const u32 port_cap,
  344. const u8 init_type, const int modify_mask)
  345. {
  346. u64 port_attributes = port_cap;
  347. if (modify_mask & IB_PORT_SHUTDOWN)
  348. port_attributes |= EHCA_BMASK_SET(H_MP_SHUTDOWN, 1);
  349. if (modify_mask & IB_PORT_INIT_TYPE)
  350. port_attributes |= EHCA_BMASK_SET(H_MP_INIT_TYPE, init_type);
  351. if (modify_mask & IB_PORT_RESET_QKEY_CNTR)
  352. port_attributes |= EHCA_BMASK_SET(H_MP_RESET_QKEY_CTR, 1);
  353. return ehca_plpar_hcall_norets(H_MODIFY_PORT,
  354. adapter_handle.handle, /* r4 */
  355. port_id, /* r5 */
  356. port_attributes, /* r6 */
  357. 0, 0, 0, 0);
  358. }
  359. u64 hipz_h_query_hca(const struct ipz_adapter_handle adapter_handle,
  360. struct hipz_query_hca *query_hca_rblock)
  361. {
  362. u64 r_cb = __pa(query_hca_rblock);
  363. if (r_cb & (EHCA_PAGESIZE-1)) {
  364. ehca_gen_err("response_block=%p not page aligned",
  365. query_hca_rblock);
  366. return H_PARAMETER;
  367. }
  368. return ehca_plpar_hcall_norets(H_QUERY_HCA,
  369. adapter_handle.handle, /* r4 */
  370. r_cb, /* r5 */
  371. 0, 0, 0, 0, 0);
  372. }
  373. u64 hipz_h_register_rpage(const struct ipz_adapter_handle adapter_handle,
  374. const u8 pagesize,
  375. const u8 queue_type,
  376. const u64 resource_handle,
  377. const u64 logical_address_of_page,
  378. u64 count)
  379. {
  380. return ehca_plpar_hcall_norets(H_REGISTER_RPAGES,
  381. adapter_handle.handle, /* r4 */
  382. (u64)queue_type | ((u64)pagesize) << 8,
  383. /* r5 */
  384. resource_handle, /* r6 */
  385. logical_address_of_page, /* r7 */
  386. count, /* r8 */
  387. 0, 0);
  388. }
  389. u64 hipz_h_register_rpage_eq(const struct ipz_adapter_handle adapter_handle,
  390. const struct ipz_eq_handle eq_handle,
  391. struct ehca_pfeq *pfeq,
  392. const u8 pagesize,
  393. const u8 queue_type,
  394. const u64 logical_address_of_page,
  395. const u64 count)
  396. {
  397. if (count != 1) {
  398. ehca_gen_err("Ppage counter=%llx", count);
  399. return H_PARAMETER;
  400. }
  401. return hipz_h_register_rpage(adapter_handle,
  402. pagesize,
  403. queue_type,
  404. eq_handle.handle,
  405. logical_address_of_page, count);
  406. }
  407. u64 hipz_h_query_int_state(const struct ipz_adapter_handle adapter_handle,
  408. u32 ist)
  409. {
  410. u64 ret;
  411. ret = ehca_plpar_hcall_norets(H_QUERY_INT_STATE,
  412. adapter_handle.handle, /* r4 */
  413. ist, /* r5 */
  414. 0, 0, 0, 0, 0);
  415. if (ret != H_SUCCESS && ret != H_BUSY)
  416. ehca_gen_err("Could not query interrupt state.");
  417. return ret;
  418. }
  419. u64 hipz_h_register_rpage_cq(const struct ipz_adapter_handle adapter_handle,
  420. const struct ipz_cq_handle cq_handle,
  421. struct ehca_pfcq *pfcq,
  422. const u8 pagesize,
  423. const u8 queue_type,
  424. const u64 logical_address_of_page,
  425. const u64 count,
  426. const struct h_galpa gal)
  427. {
  428. if (count != 1) {
  429. ehca_gen_err("Page counter=%llx", count);
  430. return H_PARAMETER;
  431. }
  432. return hipz_h_register_rpage(adapter_handle, pagesize, queue_type,
  433. cq_handle.handle, logical_address_of_page,
  434. count);
  435. }
  436. u64 hipz_h_register_rpage_qp(const struct ipz_adapter_handle adapter_handle,
  437. const struct ipz_qp_handle qp_handle,
  438. struct ehca_pfqp *pfqp,
  439. const u8 pagesize,
  440. const u8 queue_type,
  441. const u64 logical_address_of_page,
  442. const u64 count,
  443. const struct h_galpa galpa)
  444. {
  445. if (count > 1) {
  446. ehca_gen_err("Page counter=%llx", count);
  447. return H_PARAMETER;
  448. }
  449. return hipz_h_register_rpage(adapter_handle, pagesize, queue_type,
  450. qp_handle.handle, logical_address_of_page,
  451. count);
  452. }
  453. u64 hipz_h_disable_and_get_wqe(const struct ipz_adapter_handle adapter_handle,
  454. const struct ipz_qp_handle qp_handle,
  455. struct ehca_pfqp *pfqp,
  456. void **log_addr_next_sq_wqe2processed,
  457. void **log_addr_next_rq_wqe2processed,
  458. int dis_and_get_function_code)
  459. {
  460. u64 ret;
  461. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  462. ret = ehca_plpar_hcall9(H_DISABLE_AND_GETC, outs,
  463. adapter_handle.handle, /* r4 */
  464. dis_and_get_function_code, /* r5 */
  465. qp_handle.handle, /* r6 */
  466. 0, 0, 0, 0, 0, 0);
  467. if (log_addr_next_sq_wqe2processed)
  468. *log_addr_next_sq_wqe2processed = (void *)outs[0];
  469. if (log_addr_next_rq_wqe2processed)
  470. *log_addr_next_rq_wqe2processed = (void *)outs[1];
  471. return ret;
  472. }
  473. u64 hipz_h_modify_qp(const struct ipz_adapter_handle adapter_handle,
  474. const struct ipz_qp_handle qp_handle,
  475. struct ehca_pfqp *pfqp,
  476. const u64 update_mask,
  477. struct hcp_modify_qp_control_block *mqpcb,
  478. struct h_galpa gal)
  479. {
  480. u64 ret;
  481. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  482. ret = ehca_plpar_hcall9(H_MODIFY_QP, outs,
  483. adapter_handle.handle, /* r4 */
  484. qp_handle.handle, /* r5 */
  485. update_mask, /* r6 */
  486. __pa(mqpcb), /* r7 */
  487. 0, 0, 0, 0, 0);
  488. if (ret == H_NOT_ENOUGH_RESOURCES)
  489. ehca_gen_err("Insufficient resources ret=%lli", ret);
  490. return ret;
  491. }
  492. u64 hipz_h_query_qp(const struct ipz_adapter_handle adapter_handle,
  493. const struct ipz_qp_handle qp_handle,
  494. struct ehca_pfqp *pfqp,
  495. struct hcp_modify_qp_control_block *qqpcb,
  496. struct h_galpa gal)
  497. {
  498. return ehca_plpar_hcall_norets(H_QUERY_QP,
  499. adapter_handle.handle, /* r4 */
  500. qp_handle.handle, /* r5 */
  501. __pa(qqpcb), /* r6 */
  502. 0, 0, 0, 0);
  503. }
  504. u64 hipz_h_destroy_qp(const struct ipz_adapter_handle adapter_handle,
  505. struct ehca_qp *qp)
  506. {
  507. u64 ret;
  508. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  509. ret = hcp_galpas_dtor(&qp->galpas);
  510. if (ret) {
  511. ehca_gen_err("Could not destruct qp->galpas");
  512. return H_RESOURCE;
  513. }
  514. ret = ehca_plpar_hcall9(H_DISABLE_AND_GETC, outs,
  515. adapter_handle.handle, /* r4 */
  516. /* function code */
  517. 1, /* r5 */
  518. qp->ipz_qp_handle.handle, /* r6 */
  519. 0, 0, 0, 0, 0, 0);
  520. if (ret == H_HARDWARE)
  521. ehca_gen_err("HCA not operational. ret=%lli", ret);
  522. ret = ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  523. adapter_handle.handle, /* r4 */
  524. qp->ipz_qp_handle.handle, /* r5 */
  525. 0, 0, 0, 0, 0);
  526. if (ret == H_RESOURCE)
  527. ehca_gen_err("Resource still in use. ret=%lli", ret);
  528. return ret;
  529. }
  530. u64 hipz_h_define_aqp0(const struct ipz_adapter_handle adapter_handle,
  531. const struct ipz_qp_handle qp_handle,
  532. struct h_galpa gal,
  533. u32 port)
  534. {
  535. return ehca_plpar_hcall_norets(H_DEFINE_AQP0,
  536. adapter_handle.handle, /* r4 */
  537. qp_handle.handle, /* r5 */
  538. port, /* r6 */
  539. 0, 0, 0, 0);
  540. }
  541. u64 hipz_h_define_aqp1(const struct ipz_adapter_handle adapter_handle,
  542. const struct ipz_qp_handle qp_handle,
  543. struct h_galpa gal,
  544. u32 port, u32 * pma_qp_nr,
  545. u32 * bma_qp_nr)
  546. {
  547. u64 ret;
  548. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  549. ret = ehca_plpar_hcall9(H_DEFINE_AQP1, outs,
  550. adapter_handle.handle, /* r4 */
  551. qp_handle.handle, /* r5 */
  552. port, /* r6 */
  553. 0, 0, 0, 0, 0, 0);
  554. *pma_qp_nr = (u32)outs[0];
  555. *bma_qp_nr = (u32)outs[1];
  556. if (ret == H_ALIAS_EXIST)
  557. ehca_gen_err("AQP1 already exists. ret=%lli", ret);
  558. return ret;
  559. }
  560. u64 hipz_h_attach_mcqp(const struct ipz_adapter_handle adapter_handle,
  561. const struct ipz_qp_handle qp_handle,
  562. struct h_galpa gal,
  563. u16 mcg_dlid,
  564. u64 subnet_prefix, u64 interface_id)
  565. {
  566. u64 ret;
  567. ret = ehca_plpar_hcall_norets(H_ATTACH_MCQP,
  568. adapter_handle.handle, /* r4 */
  569. qp_handle.handle, /* r5 */
  570. mcg_dlid, /* r6 */
  571. interface_id, /* r7 */
  572. subnet_prefix, /* r8 */
  573. 0, 0);
  574. if (ret == H_NOT_ENOUGH_RESOURCES)
  575. ehca_gen_err("Not enough resources. ret=%lli", ret);
  576. return ret;
  577. }
  578. u64 hipz_h_detach_mcqp(const struct ipz_adapter_handle adapter_handle,
  579. const struct ipz_qp_handle qp_handle,
  580. struct h_galpa gal,
  581. u16 mcg_dlid,
  582. u64 subnet_prefix, u64 interface_id)
  583. {
  584. return ehca_plpar_hcall_norets(H_DETACH_MCQP,
  585. adapter_handle.handle, /* r4 */
  586. qp_handle.handle, /* r5 */
  587. mcg_dlid, /* r6 */
  588. interface_id, /* r7 */
  589. subnet_prefix, /* r8 */
  590. 0, 0);
  591. }
  592. u64 hipz_h_destroy_cq(const struct ipz_adapter_handle adapter_handle,
  593. struct ehca_cq *cq,
  594. u8 force_flag)
  595. {
  596. u64 ret;
  597. ret = hcp_galpas_dtor(&cq->galpas);
  598. if (ret) {
  599. ehca_gen_err("Could not destruct cp->galpas");
  600. return H_RESOURCE;
  601. }
  602. ret = ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  603. adapter_handle.handle, /* r4 */
  604. cq->ipz_cq_handle.handle, /* r5 */
  605. force_flag != 0 ? 1L : 0L, /* r6 */
  606. 0, 0, 0, 0);
  607. if (ret == H_RESOURCE)
  608. ehca_gen_err("H_FREE_RESOURCE failed ret=%lli ", ret);
  609. return ret;
  610. }
  611. u64 hipz_h_destroy_eq(const struct ipz_adapter_handle adapter_handle,
  612. struct ehca_eq *eq)
  613. {
  614. u64 ret;
  615. ret = hcp_galpas_dtor(&eq->galpas);
  616. if (ret) {
  617. ehca_gen_err("Could not destruct eq->galpas");
  618. return H_RESOURCE;
  619. }
  620. ret = ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  621. adapter_handle.handle, /* r4 */
  622. eq->ipz_eq_handle.handle, /* r5 */
  623. 0, 0, 0, 0, 0);
  624. if (ret == H_RESOURCE)
  625. ehca_gen_err("Resource in use. ret=%lli ", ret);
  626. return ret;
  627. }
  628. u64 hipz_h_alloc_resource_mr(const struct ipz_adapter_handle adapter_handle,
  629. const struct ehca_mr *mr,
  630. const u64 vaddr,
  631. const u64 length,
  632. const u32 access_ctrl,
  633. const struct ipz_pd pd,
  634. struct ehca_mr_hipzout_parms *outparms)
  635. {
  636. u64 ret;
  637. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  638. ret = ehca_plpar_hcall9(H_ALLOC_RESOURCE, outs,
  639. adapter_handle.handle, /* r4 */
  640. 5, /* r5 */
  641. vaddr, /* r6 */
  642. length, /* r7 */
  643. (((u64)access_ctrl) << 32ULL), /* r8 */
  644. pd.value, /* r9 */
  645. 0, 0, 0);
  646. outparms->handle.handle = outs[0];
  647. outparms->lkey = (u32)outs[2];
  648. outparms->rkey = (u32)outs[3];
  649. return ret;
  650. }
  651. u64 hipz_h_register_rpage_mr(const struct ipz_adapter_handle adapter_handle,
  652. const struct ehca_mr *mr,
  653. const u8 pagesize,
  654. const u8 queue_type,
  655. const u64 logical_address_of_page,
  656. const u64 count)
  657. {
  658. u64 ret;
  659. if (unlikely(ehca_debug_level >= 3)) {
  660. if (count > 1) {
  661. u64 *kpage;
  662. int i;
  663. kpage = __va(logical_address_of_page);
  664. for (i = 0; i < count; i++)
  665. ehca_gen_dbg("kpage[%d]=%p",
  666. i, (void *)kpage[i]);
  667. } else
  668. ehca_gen_dbg("kpage=%p",
  669. (void *)logical_address_of_page);
  670. }
  671. if ((count > 1) && (logical_address_of_page & (EHCA_PAGESIZE-1))) {
  672. ehca_gen_err("logical_address_of_page not on a 4k boundary "
  673. "adapter_handle=%llx mr=%p mr_handle=%llx "
  674. "pagesize=%x queue_type=%x "
  675. "logical_address_of_page=%llx count=%llx",
  676. adapter_handle.handle, mr,
  677. mr->ipz_mr_handle.handle, pagesize, queue_type,
  678. logical_address_of_page, count);
  679. ret = H_PARAMETER;
  680. } else
  681. ret = hipz_h_register_rpage(adapter_handle, pagesize,
  682. queue_type,
  683. mr->ipz_mr_handle.handle,
  684. logical_address_of_page, count);
  685. return ret;
  686. }
  687. u64 hipz_h_query_mr(const struct ipz_adapter_handle adapter_handle,
  688. const struct ehca_mr *mr,
  689. struct ehca_mr_hipzout_parms *outparms)
  690. {
  691. u64 ret;
  692. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  693. ret = ehca_plpar_hcall9(H_QUERY_MR, outs,
  694. adapter_handle.handle, /* r4 */
  695. mr->ipz_mr_handle.handle, /* r5 */
  696. 0, 0, 0, 0, 0, 0, 0);
  697. outparms->len = outs[0];
  698. outparms->vaddr = outs[1];
  699. outparms->acl = outs[4] >> 32;
  700. outparms->lkey = (u32)(outs[5] >> 32);
  701. outparms->rkey = (u32)(outs[5] & (0xffffffff));
  702. return ret;
  703. }
  704. u64 hipz_h_free_resource_mr(const struct ipz_adapter_handle adapter_handle,
  705. const struct ehca_mr *mr)
  706. {
  707. return ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  708. adapter_handle.handle, /* r4 */
  709. mr->ipz_mr_handle.handle, /* r5 */
  710. 0, 0, 0, 0, 0);
  711. }
  712. u64 hipz_h_reregister_pmr(const struct ipz_adapter_handle adapter_handle,
  713. const struct ehca_mr *mr,
  714. const u64 vaddr_in,
  715. const u64 length,
  716. const u32 access_ctrl,
  717. const struct ipz_pd pd,
  718. const u64 mr_addr_cb,
  719. struct ehca_mr_hipzout_parms *outparms)
  720. {
  721. u64 ret;
  722. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  723. ret = ehca_plpar_hcall9(H_REREGISTER_PMR, outs,
  724. adapter_handle.handle, /* r4 */
  725. mr->ipz_mr_handle.handle, /* r5 */
  726. vaddr_in, /* r6 */
  727. length, /* r7 */
  728. /* r8 */
  729. ((((u64)access_ctrl) << 32ULL) | pd.value),
  730. mr_addr_cb, /* r9 */
  731. 0, 0, 0);
  732. outparms->vaddr = outs[1];
  733. outparms->lkey = (u32)outs[2];
  734. outparms->rkey = (u32)outs[3];
  735. return ret;
  736. }
  737. u64 hipz_h_register_smr(const struct ipz_adapter_handle adapter_handle,
  738. const struct ehca_mr *mr,
  739. const struct ehca_mr *orig_mr,
  740. const u64 vaddr_in,
  741. const u32 access_ctrl,
  742. const struct ipz_pd pd,
  743. struct ehca_mr_hipzout_parms *outparms)
  744. {
  745. u64 ret;
  746. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  747. ret = ehca_plpar_hcall9(H_REGISTER_SMR, outs,
  748. adapter_handle.handle, /* r4 */
  749. orig_mr->ipz_mr_handle.handle, /* r5 */
  750. vaddr_in, /* r6 */
  751. (((u64)access_ctrl) << 32ULL), /* r7 */
  752. pd.value, /* r8 */
  753. 0, 0, 0, 0);
  754. outparms->handle.handle = outs[0];
  755. outparms->lkey = (u32)outs[2];
  756. outparms->rkey = (u32)outs[3];
  757. return ret;
  758. }
  759. u64 hipz_h_alloc_resource_mw(const struct ipz_adapter_handle adapter_handle,
  760. const struct ehca_mw *mw,
  761. const struct ipz_pd pd,
  762. struct ehca_mw_hipzout_parms *outparms)
  763. {
  764. u64 ret;
  765. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  766. ret = ehca_plpar_hcall9(H_ALLOC_RESOURCE, outs,
  767. adapter_handle.handle, /* r4 */
  768. 6, /* r5 */
  769. pd.value, /* r6 */
  770. 0, 0, 0, 0, 0, 0);
  771. outparms->handle.handle = outs[0];
  772. outparms->rkey = (u32)outs[3];
  773. return ret;
  774. }
  775. u64 hipz_h_query_mw(const struct ipz_adapter_handle adapter_handle,
  776. const struct ehca_mw *mw,
  777. struct ehca_mw_hipzout_parms *outparms)
  778. {
  779. u64 ret;
  780. unsigned long outs[PLPAR_HCALL9_BUFSIZE];
  781. ret = ehca_plpar_hcall9(H_QUERY_MW, outs,
  782. adapter_handle.handle, /* r4 */
  783. mw->ipz_mw_handle.handle, /* r5 */
  784. 0, 0, 0, 0, 0, 0, 0);
  785. outparms->rkey = (u32)outs[3];
  786. return ret;
  787. }
  788. u64 hipz_h_free_resource_mw(const struct ipz_adapter_handle adapter_handle,
  789. const struct ehca_mw *mw)
  790. {
  791. return ehca_plpar_hcall_norets(H_FREE_RESOURCE,
  792. adapter_handle.handle, /* r4 */
  793. mw->ipz_mw_handle.handle, /* r5 */
  794. 0, 0, 0, 0, 0);
  795. }
  796. u64 hipz_h_error_data(const struct ipz_adapter_handle adapter_handle,
  797. const u64 ressource_handle,
  798. void *rblock,
  799. unsigned long *byte_count)
  800. {
  801. u64 r_cb = __pa(rblock);
  802. if (r_cb & (EHCA_PAGESIZE-1)) {
  803. ehca_gen_err("rblock not page aligned.");
  804. return H_PARAMETER;
  805. }
  806. return ehca_plpar_hcall_norets(H_ERROR_DATA,
  807. adapter_handle.handle,
  808. ressource_handle,
  809. r_cb,
  810. 0, 0, 0, 0);
  811. }
  812. u64 hipz_h_eoi(int irq)
  813. {
  814. unsigned long xirr;
  815. iosync();
  816. xirr = (0xffULL << 24) | irq;
  817. return plpar_hcall_norets(H_EOI, xirr);
  818. }