ehca_qp.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * QP functions
  5. *
  6. * Authors: Joachim Fenkes <fenkes@de.ibm.com>
  7. * Stefan Roscher <stefan.roscher@de.ibm.com>
  8. * Waleri Fomin <fomin@de.ibm.com>
  9. * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  10. * Reinhard Ernst <rernst@de.ibm.com>
  11. * Heiko J Schick <schickhj@de.ibm.com>
  12. *
  13. * Copyright (c) 2005 IBM Corporation
  14. *
  15. * All rights reserved.
  16. *
  17. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  18. * BSD.
  19. *
  20. * OpenIB BSD License
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions are met:
  24. *
  25. * Redistributions of source code must retain the above copyright notice, this
  26. * list of conditions and the following disclaimer.
  27. *
  28. * Redistributions in binary form must reproduce the above copyright notice,
  29. * this list of conditions and the following disclaimer in the documentation
  30. * and/or other materials
  31. * provided with the distribution.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  37. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  38. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  40. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  41. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43. * POSSIBILITY OF SUCH DAMAGE.
  44. */
  45. #include <asm/current.h>
  46. #include "ehca_classes.h"
  47. #include "ehca_tools.h"
  48. #include "ehca_qes.h"
  49. #include "ehca_iverbs.h"
  50. #include "hcp_if.h"
  51. #include "hipz_fns.h"
  52. static struct kmem_cache *qp_cache;
  53. /*
  54. * attributes not supported by query qp
  55. */
  56. #define QP_ATTR_QUERY_NOT_SUPPORTED (IB_QP_MAX_DEST_RD_ATOMIC | \
  57. IB_QP_MAX_QP_RD_ATOMIC | \
  58. IB_QP_ACCESS_FLAGS | \
  59. IB_QP_EN_SQD_ASYNC_NOTIFY)
  60. /*
  61. * ehca (internal) qp state values
  62. */
  63. enum ehca_qp_state {
  64. EHCA_QPS_RESET = 1,
  65. EHCA_QPS_INIT = 2,
  66. EHCA_QPS_RTR = 3,
  67. EHCA_QPS_RTS = 5,
  68. EHCA_QPS_SQD = 6,
  69. EHCA_QPS_SQE = 8,
  70. EHCA_QPS_ERR = 128
  71. };
  72. /*
  73. * qp state transitions as defined by IB Arch Rel 1.1 page 431
  74. */
  75. enum ib_qp_statetrans {
  76. IB_QPST_ANY2RESET,
  77. IB_QPST_ANY2ERR,
  78. IB_QPST_RESET2INIT,
  79. IB_QPST_INIT2RTR,
  80. IB_QPST_INIT2INIT,
  81. IB_QPST_RTR2RTS,
  82. IB_QPST_RTS2SQD,
  83. IB_QPST_RTS2RTS,
  84. IB_QPST_SQD2RTS,
  85. IB_QPST_SQE2RTS,
  86. IB_QPST_SQD2SQD,
  87. IB_QPST_MAX /* nr of transitions, this must be last!!! */
  88. };
  89. /*
  90. * ib2ehca_qp_state maps IB to ehca qp_state
  91. * returns ehca qp state corresponding to given ib qp state
  92. */
  93. static inline enum ehca_qp_state ib2ehca_qp_state(enum ib_qp_state ib_qp_state)
  94. {
  95. switch (ib_qp_state) {
  96. case IB_QPS_RESET:
  97. return EHCA_QPS_RESET;
  98. case IB_QPS_INIT:
  99. return EHCA_QPS_INIT;
  100. case IB_QPS_RTR:
  101. return EHCA_QPS_RTR;
  102. case IB_QPS_RTS:
  103. return EHCA_QPS_RTS;
  104. case IB_QPS_SQD:
  105. return EHCA_QPS_SQD;
  106. case IB_QPS_SQE:
  107. return EHCA_QPS_SQE;
  108. case IB_QPS_ERR:
  109. return EHCA_QPS_ERR;
  110. default:
  111. ehca_gen_err("invalid ib_qp_state=%x", ib_qp_state);
  112. return -EINVAL;
  113. }
  114. }
  115. /*
  116. * ehca2ib_qp_state maps ehca to IB qp_state
  117. * returns ib qp state corresponding to given ehca qp state
  118. */
  119. static inline enum ib_qp_state ehca2ib_qp_state(enum ehca_qp_state
  120. ehca_qp_state)
  121. {
  122. switch (ehca_qp_state) {
  123. case EHCA_QPS_RESET:
  124. return IB_QPS_RESET;
  125. case EHCA_QPS_INIT:
  126. return IB_QPS_INIT;
  127. case EHCA_QPS_RTR:
  128. return IB_QPS_RTR;
  129. case EHCA_QPS_RTS:
  130. return IB_QPS_RTS;
  131. case EHCA_QPS_SQD:
  132. return IB_QPS_SQD;
  133. case EHCA_QPS_SQE:
  134. return IB_QPS_SQE;
  135. case EHCA_QPS_ERR:
  136. return IB_QPS_ERR;
  137. default:
  138. ehca_gen_err("invalid ehca_qp_state=%x", ehca_qp_state);
  139. return -EINVAL;
  140. }
  141. }
  142. /*
  143. * ehca_qp_type used as index for req_attr and opt_attr of
  144. * struct ehca_modqp_statetrans
  145. */
  146. enum ehca_qp_type {
  147. QPT_RC = 0,
  148. QPT_UC = 1,
  149. QPT_UD = 2,
  150. QPT_SQP = 3,
  151. QPT_MAX
  152. };
  153. /*
  154. * ib2ehcaqptype maps Ib to ehca qp_type
  155. * returns ehca qp type corresponding to ib qp type
  156. */
  157. static inline enum ehca_qp_type ib2ehcaqptype(enum ib_qp_type ibqptype)
  158. {
  159. switch (ibqptype) {
  160. case IB_QPT_SMI:
  161. case IB_QPT_GSI:
  162. return QPT_SQP;
  163. case IB_QPT_RC:
  164. return QPT_RC;
  165. case IB_QPT_UC:
  166. return QPT_UC;
  167. case IB_QPT_UD:
  168. return QPT_UD;
  169. default:
  170. ehca_gen_err("Invalid ibqptype=%x", ibqptype);
  171. return -EINVAL;
  172. }
  173. }
  174. static inline enum ib_qp_statetrans get_modqp_statetrans(int ib_fromstate,
  175. int ib_tostate)
  176. {
  177. int index = -EINVAL;
  178. switch (ib_tostate) {
  179. case IB_QPS_RESET:
  180. index = IB_QPST_ANY2RESET;
  181. break;
  182. case IB_QPS_INIT:
  183. switch (ib_fromstate) {
  184. case IB_QPS_RESET:
  185. index = IB_QPST_RESET2INIT;
  186. break;
  187. case IB_QPS_INIT:
  188. index = IB_QPST_INIT2INIT;
  189. break;
  190. }
  191. break;
  192. case IB_QPS_RTR:
  193. if (ib_fromstate == IB_QPS_INIT)
  194. index = IB_QPST_INIT2RTR;
  195. break;
  196. case IB_QPS_RTS:
  197. switch (ib_fromstate) {
  198. case IB_QPS_RTR:
  199. index = IB_QPST_RTR2RTS;
  200. break;
  201. case IB_QPS_RTS:
  202. index = IB_QPST_RTS2RTS;
  203. break;
  204. case IB_QPS_SQD:
  205. index = IB_QPST_SQD2RTS;
  206. break;
  207. case IB_QPS_SQE:
  208. index = IB_QPST_SQE2RTS;
  209. break;
  210. }
  211. break;
  212. case IB_QPS_SQD:
  213. if (ib_fromstate == IB_QPS_RTS)
  214. index = IB_QPST_RTS2SQD;
  215. break;
  216. case IB_QPS_SQE:
  217. break;
  218. case IB_QPS_ERR:
  219. index = IB_QPST_ANY2ERR;
  220. break;
  221. default:
  222. break;
  223. }
  224. return index;
  225. }
  226. /*
  227. * ibqptype2servicetype returns hcp service type corresponding to given
  228. * ib qp type used by create_qp()
  229. */
  230. static inline int ibqptype2servicetype(enum ib_qp_type ibqptype)
  231. {
  232. switch (ibqptype) {
  233. case IB_QPT_SMI:
  234. case IB_QPT_GSI:
  235. return ST_UD;
  236. case IB_QPT_RC:
  237. return ST_RC;
  238. case IB_QPT_UC:
  239. return ST_UC;
  240. case IB_QPT_UD:
  241. return ST_UD;
  242. case IB_QPT_RAW_IPV6:
  243. return -EINVAL;
  244. case IB_QPT_RAW_ETY:
  245. return -EINVAL;
  246. default:
  247. ehca_gen_err("Invalid ibqptype=%x", ibqptype);
  248. return -EINVAL;
  249. }
  250. }
  251. /*
  252. * init userspace queue info from ipz_queue data
  253. */
  254. static inline void queue2resp(struct ipzu_queue_resp *resp,
  255. struct ipz_queue *queue)
  256. {
  257. resp->qe_size = queue->qe_size;
  258. resp->act_nr_of_sg = queue->act_nr_of_sg;
  259. resp->queue_length = queue->queue_length;
  260. resp->pagesize = queue->pagesize;
  261. resp->toggle_state = queue->toggle_state;
  262. }
  263. static inline int ll_qp_msg_size(int nr_sge)
  264. {
  265. return 128 << nr_sge;
  266. }
  267. /*
  268. * init_qp_queue initializes/constructs r/squeue and registers queue pages.
  269. */
  270. static inline int init_qp_queue(struct ehca_shca *shca,
  271. struct ehca_qp *my_qp,
  272. struct ipz_queue *queue,
  273. int q_type,
  274. u64 expected_hret,
  275. int nr_q_pages,
  276. int wqe_size,
  277. int nr_sges)
  278. {
  279. int ret, cnt, ipz_rc;
  280. void *vpage;
  281. u64 rpage, h_ret;
  282. struct ib_device *ib_dev = &shca->ib_device;
  283. struct ipz_adapter_handle ipz_hca_handle = shca->ipz_hca_handle;
  284. if (!nr_q_pages)
  285. return 0;
  286. ipz_rc = ipz_queue_ctor(queue, nr_q_pages, EHCA_PAGESIZE,
  287. wqe_size, nr_sges);
  288. if (!ipz_rc) {
  289. ehca_err(ib_dev, "Cannot allocate page for queue. ipz_rc=%x",
  290. ipz_rc);
  291. return -EBUSY;
  292. }
  293. /* register queue pages */
  294. for (cnt = 0; cnt < nr_q_pages; cnt++) {
  295. vpage = ipz_qpageit_get_inc(queue);
  296. if (!vpage) {
  297. ehca_err(ib_dev, "ipz_qpageit_get_inc() "
  298. "failed p_vpage= %p", vpage);
  299. ret = -EINVAL;
  300. goto init_qp_queue1;
  301. }
  302. rpage = virt_to_abs(vpage);
  303. h_ret = hipz_h_register_rpage_qp(ipz_hca_handle,
  304. my_qp->ipz_qp_handle,
  305. NULL, 0, q_type,
  306. rpage, 1,
  307. my_qp->galpas.kernel);
  308. if (cnt == (nr_q_pages - 1)) { /* last page! */
  309. if (h_ret != expected_hret) {
  310. ehca_err(ib_dev, "hipz_qp_register_rpage() "
  311. "h_ret= %lx ", h_ret);
  312. ret = ehca2ib_return_code(h_ret);
  313. goto init_qp_queue1;
  314. }
  315. vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue);
  316. if (vpage) {
  317. ehca_err(ib_dev, "ipz_qpageit_get_inc() "
  318. "should not succeed vpage=%p", vpage);
  319. ret = -EINVAL;
  320. goto init_qp_queue1;
  321. }
  322. } else {
  323. if (h_ret != H_PAGE_REGISTERED) {
  324. ehca_err(ib_dev, "hipz_qp_register_rpage() "
  325. "h_ret= %lx ", h_ret);
  326. ret = ehca2ib_return_code(h_ret);
  327. goto init_qp_queue1;
  328. }
  329. }
  330. }
  331. ipz_qeit_reset(queue);
  332. return 0;
  333. init_qp_queue1:
  334. ipz_queue_dtor(queue);
  335. return ret;
  336. }
  337. /*
  338. * Create an ib_qp struct that is either a QP or an SRQ, depending on
  339. * the value of the is_srq parameter. If init_attr and srq_init_attr share
  340. * fields, the field out of init_attr is used.
  341. */
  342. static struct ehca_qp *internal_create_qp(
  343. struct ib_pd *pd,
  344. struct ib_qp_init_attr *init_attr,
  345. struct ib_srq_init_attr *srq_init_attr,
  346. struct ib_udata *udata, int is_srq)
  347. {
  348. struct ehca_qp *my_qp;
  349. struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
  350. struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
  351. ib_device);
  352. struct ib_ucontext *context = NULL;
  353. u64 h_ret;
  354. int is_llqp = 0, has_srq = 0;
  355. int qp_type, max_send_sge, max_recv_sge, ret;
  356. /* h_call's out parameters */
  357. struct ehca_alloc_qp_parms parms;
  358. u32 swqe_size = 0, rwqe_size = 0, ib_qp_num;
  359. unsigned long flags;
  360. memset(&parms, 0, sizeof(parms));
  361. qp_type = init_attr->qp_type;
  362. if (init_attr->sq_sig_type != IB_SIGNAL_REQ_WR &&
  363. init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) {
  364. ehca_err(pd->device, "init_attr->sg_sig_type=%x not allowed",
  365. init_attr->sq_sig_type);
  366. return ERR_PTR(-EINVAL);
  367. }
  368. /* save LLQP info */
  369. if (qp_type & 0x80) {
  370. is_llqp = 1;
  371. parms.ext_type = EQPT_LLQP;
  372. parms.ll_comp_flags = qp_type & LLQP_COMP_MASK;
  373. }
  374. qp_type &= 0x1F;
  375. init_attr->qp_type &= 0x1F;
  376. /* handle SRQ base QPs */
  377. if (init_attr->srq) {
  378. struct ehca_qp *my_srq =
  379. container_of(init_attr->srq, struct ehca_qp, ib_srq);
  380. has_srq = 1;
  381. parms.ext_type = EQPT_SRQBASE;
  382. parms.srq_qpn = my_srq->real_qp_num;
  383. parms.srq_token = my_srq->token;
  384. }
  385. if (is_llqp && has_srq) {
  386. ehca_err(pd->device, "LLQPs can't have an SRQ");
  387. return ERR_PTR(-EINVAL);
  388. }
  389. /* handle SRQs */
  390. if (is_srq) {
  391. parms.ext_type = EQPT_SRQ;
  392. parms.srq_limit = srq_init_attr->attr.srq_limit;
  393. if (init_attr->cap.max_recv_sge > 3) {
  394. ehca_err(pd->device, "no more than three SGEs "
  395. "supported for SRQ pd=%p max_sge=%x",
  396. pd, init_attr->cap.max_recv_sge);
  397. return ERR_PTR(-EINVAL);
  398. }
  399. }
  400. /* check QP type */
  401. if (qp_type != IB_QPT_UD &&
  402. qp_type != IB_QPT_UC &&
  403. qp_type != IB_QPT_RC &&
  404. qp_type != IB_QPT_SMI &&
  405. qp_type != IB_QPT_GSI) {
  406. ehca_err(pd->device, "wrong QP Type=%x", qp_type);
  407. return ERR_PTR(-EINVAL);
  408. }
  409. if (is_llqp) {
  410. switch (qp_type) {
  411. case IB_QPT_RC:
  412. if ((init_attr->cap.max_send_wr > 255) ||
  413. (init_attr->cap.max_recv_wr > 255)) {
  414. ehca_err(pd->device,
  415. "Invalid Number of max_sq_wr=%x "
  416. "or max_rq_wr=%x for RC LLQP",
  417. init_attr->cap.max_send_wr,
  418. init_attr->cap.max_recv_wr);
  419. return ERR_PTR(-EINVAL);
  420. }
  421. break;
  422. case IB_QPT_UD:
  423. if (!EHCA_BMASK_GET(HCA_CAP_UD_LL_QP, shca->hca_cap)) {
  424. ehca_err(pd->device, "UD LLQP not supported "
  425. "by this adapter");
  426. return ERR_PTR(-ENOSYS);
  427. }
  428. if (!(init_attr->cap.max_send_sge <= 5
  429. && init_attr->cap.max_send_sge >= 1
  430. && init_attr->cap.max_recv_sge <= 5
  431. && init_attr->cap.max_recv_sge >= 1)) {
  432. ehca_err(pd->device,
  433. "Invalid Number of max_send_sge=%x "
  434. "or max_recv_sge=%x for UD LLQP",
  435. init_attr->cap.max_send_sge,
  436. init_attr->cap.max_recv_sge);
  437. return ERR_PTR(-EINVAL);
  438. } else if (init_attr->cap.max_send_wr > 255) {
  439. ehca_err(pd->device,
  440. "Invalid Number of "
  441. "ax_send_wr=%x for UD QP_TYPE=%x",
  442. init_attr->cap.max_send_wr, qp_type);
  443. return ERR_PTR(-EINVAL);
  444. }
  445. break;
  446. default:
  447. ehca_err(pd->device, "unsupported LL QP Type=%x",
  448. qp_type);
  449. return ERR_PTR(-EINVAL);
  450. break;
  451. }
  452. }
  453. if (pd->uobject && udata)
  454. context = pd->uobject->context;
  455. my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL);
  456. if (!my_qp) {
  457. ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd);
  458. return ERR_PTR(-ENOMEM);
  459. }
  460. spin_lock_init(&my_qp->spinlock_s);
  461. spin_lock_init(&my_qp->spinlock_r);
  462. my_qp->qp_type = qp_type;
  463. my_qp->ext_type = parms.ext_type;
  464. if (init_attr->recv_cq)
  465. my_qp->recv_cq =
  466. container_of(init_attr->recv_cq, struct ehca_cq, ib_cq);
  467. if (init_attr->send_cq)
  468. my_qp->send_cq =
  469. container_of(init_attr->send_cq, struct ehca_cq, ib_cq);
  470. do {
  471. if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) {
  472. ret = -ENOMEM;
  473. ehca_err(pd->device, "Can't reserve idr resources.");
  474. goto create_qp_exit0;
  475. }
  476. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  477. ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token);
  478. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  479. } while (ret == -EAGAIN);
  480. if (ret) {
  481. ret = -ENOMEM;
  482. ehca_err(pd->device, "Can't allocate new idr entry.");
  483. goto create_qp_exit0;
  484. }
  485. parms.servicetype = ibqptype2servicetype(qp_type);
  486. if (parms.servicetype < 0) {
  487. ret = -EINVAL;
  488. ehca_err(pd->device, "Invalid qp_type=%x", qp_type);
  489. goto create_qp_exit0;
  490. }
  491. if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
  492. parms.sigtype = HCALL_SIGT_EVERY;
  493. else
  494. parms.sigtype = HCALL_SIGT_BY_WQE;
  495. /* UD_AV CIRCUMVENTION */
  496. max_send_sge = init_attr->cap.max_send_sge;
  497. max_recv_sge = init_attr->cap.max_recv_sge;
  498. if (parms.servicetype == ST_UD && !is_llqp) {
  499. max_send_sge += 2;
  500. max_recv_sge += 2;
  501. }
  502. parms.token = my_qp->token;
  503. parms.eq_handle = shca->eq.ipz_eq_handle;
  504. parms.pd = my_pd->fw_pd;
  505. if (my_qp->send_cq)
  506. parms.send_cq_handle = my_qp->send_cq->ipz_cq_handle;
  507. if (my_qp->recv_cq)
  508. parms.recv_cq_handle = my_qp->recv_cq->ipz_cq_handle;
  509. parms.max_send_wr = init_attr->cap.max_send_wr;
  510. parms.max_recv_wr = init_attr->cap.max_recv_wr;
  511. parms.max_send_sge = max_send_sge;
  512. parms.max_recv_sge = max_recv_sge;
  513. h_ret = hipz_h_alloc_resource_qp(shca->ipz_hca_handle, &parms);
  514. if (h_ret != H_SUCCESS) {
  515. ehca_err(pd->device, "h_alloc_resource_qp() failed h_ret=%lx",
  516. h_ret);
  517. ret = ehca2ib_return_code(h_ret);
  518. goto create_qp_exit1;
  519. }
  520. ib_qp_num = my_qp->real_qp_num = parms.real_qp_num;
  521. my_qp->ipz_qp_handle = parms.qp_handle;
  522. my_qp->galpas = parms.galpas;
  523. switch (qp_type) {
  524. case IB_QPT_RC:
  525. if (!is_llqp) {
  526. swqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
  527. (parms.act_nr_send_sges)]);
  528. rwqe_size = offsetof(struct ehca_wqe, u.nud.sg_list[
  529. (parms.act_nr_recv_sges)]);
  530. } else { /* for LLQP we need to use msg size, not wqe size */
  531. swqe_size = ll_qp_msg_size(max_send_sge);
  532. rwqe_size = ll_qp_msg_size(max_recv_sge);
  533. parms.act_nr_send_sges = 1;
  534. parms.act_nr_recv_sges = 1;
  535. }
  536. break;
  537. case IB_QPT_UC:
  538. swqe_size = offsetof(struct ehca_wqe,
  539. u.nud.sg_list[parms.act_nr_send_sges]);
  540. rwqe_size = offsetof(struct ehca_wqe,
  541. u.nud.sg_list[parms.act_nr_recv_sges]);
  542. break;
  543. case IB_QPT_UD:
  544. case IB_QPT_GSI:
  545. case IB_QPT_SMI:
  546. if (is_llqp) {
  547. swqe_size = ll_qp_msg_size(parms.act_nr_send_sges);
  548. rwqe_size = ll_qp_msg_size(parms.act_nr_recv_sges);
  549. parms.act_nr_send_sges = 1;
  550. parms.act_nr_recv_sges = 1;
  551. } else {
  552. /* UD circumvention */
  553. parms.act_nr_send_sges -= 2;
  554. parms.act_nr_recv_sges -= 2;
  555. swqe_size = offsetof(struct ehca_wqe, u.ud_av.sg_list[
  556. parms.act_nr_send_sges]);
  557. rwqe_size = offsetof(struct ehca_wqe, u.ud_av.sg_list[
  558. parms.act_nr_recv_sges]);
  559. }
  560. if (IB_QPT_GSI == qp_type || IB_QPT_SMI == qp_type) {
  561. parms.act_nr_send_wqes = init_attr->cap.max_send_wr;
  562. parms.act_nr_recv_wqes = init_attr->cap.max_recv_wr;
  563. parms.act_nr_send_sges = init_attr->cap.max_send_sge;
  564. parms.act_nr_recv_sges = init_attr->cap.max_recv_sge;
  565. ib_qp_num = (qp_type == IB_QPT_SMI) ? 0 : 1;
  566. }
  567. break;
  568. default:
  569. break;
  570. }
  571. /* initialize r/squeue and register queue pages */
  572. if (HAS_SQ(my_qp)) {
  573. ret = init_qp_queue(
  574. shca, my_qp, &my_qp->ipz_squeue, 0,
  575. HAS_RQ(my_qp) ? H_PAGE_REGISTERED : H_SUCCESS,
  576. parms.nr_sq_pages, swqe_size,
  577. parms.act_nr_send_sges);
  578. if (ret) {
  579. ehca_err(pd->device, "Couldn't initialize squeue "
  580. "and pages ret=%x", ret);
  581. goto create_qp_exit2;
  582. }
  583. }
  584. if (HAS_RQ(my_qp)) {
  585. ret = init_qp_queue(
  586. shca, my_qp, &my_qp->ipz_rqueue, 1,
  587. H_SUCCESS, parms.nr_rq_pages, rwqe_size,
  588. parms.act_nr_recv_sges);
  589. if (ret) {
  590. ehca_err(pd->device, "Couldn't initialize rqueue "
  591. "and pages ret=%x", ret);
  592. goto create_qp_exit3;
  593. }
  594. }
  595. if (is_srq) {
  596. my_qp->ib_srq.pd = &my_pd->ib_pd;
  597. my_qp->ib_srq.device = my_pd->ib_pd.device;
  598. my_qp->ib_srq.srq_context = init_attr->qp_context;
  599. my_qp->ib_srq.event_handler = init_attr->event_handler;
  600. } else {
  601. my_qp->ib_qp.qp_num = ib_qp_num;
  602. my_qp->ib_qp.pd = &my_pd->ib_pd;
  603. my_qp->ib_qp.device = my_pd->ib_pd.device;
  604. my_qp->ib_qp.recv_cq = init_attr->recv_cq;
  605. my_qp->ib_qp.send_cq = init_attr->send_cq;
  606. my_qp->ib_qp.qp_type = qp_type;
  607. my_qp->ib_qp.srq = init_attr->srq;
  608. my_qp->ib_qp.qp_context = init_attr->qp_context;
  609. my_qp->ib_qp.event_handler = init_attr->event_handler;
  610. }
  611. init_attr->cap.max_inline_data = 0; /* not supported yet */
  612. init_attr->cap.max_recv_sge = parms.act_nr_recv_sges;
  613. init_attr->cap.max_recv_wr = parms.act_nr_recv_wqes;
  614. init_attr->cap.max_send_sge = parms.act_nr_send_sges;
  615. init_attr->cap.max_send_wr = parms.act_nr_send_wqes;
  616. my_qp->init_attr = *init_attr;
  617. /* NOTE: define_apq0() not supported yet */
  618. if (qp_type == IB_QPT_GSI) {
  619. h_ret = ehca_define_sqp(shca, my_qp, init_attr);
  620. if (h_ret != H_SUCCESS) {
  621. ehca_err(pd->device, "ehca_define_sqp() failed rc=%lx",
  622. h_ret);
  623. ret = ehca2ib_return_code(h_ret);
  624. goto create_qp_exit4;
  625. }
  626. }
  627. if (my_qp->send_cq) {
  628. ret = ehca_cq_assign_qp(my_qp->send_cq, my_qp);
  629. if (ret) {
  630. ehca_err(pd->device,
  631. "Couldn't assign qp to send_cq ret=%x", ret);
  632. goto create_qp_exit4;
  633. }
  634. }
  635. /* copy queues, galpa data to user space */
  636. if (context && udata) {
  637. struct ehca_create_qp_resp resp;
  638. memset(&resp, 0, sizeof(resp));
  639. resp.qp_num = my_qp->real_qp_num;
  640. resp.token = my_qp->token;
  641. resp.qp_type = my_qp->qp_type;
  642. resp.ext_type = my_qp->ext_type;
  643. resp.qkey = my_qp->qkey;
  644. resp.real_qp_num = my_qp->real_qp_num;
  645. if (HAS_SQ(my_qp))
  646. queue2resp(&resp.ipz_squeue, &my_qp->ipz_squeue);
  647. if (HAS_RQ(my_qp))
  648. queue2resp(&resp.ipz_rqueue, &my_qp->ipz_rqueue);
  649. if (ib_copy_to_udata(udata, &resp, sizeof resp)) {
  650. ehca_err(pd->device, "Copy to udata failed");
  651. ret = -EINVAL;
  652. goto create_qp_exit4;
  653. }
  654. }
  655. return my_qp;
  656. create_qp_exit4:
  657. if (HAS_RQ(my_qp))
  658. ipz_queue_dtor(&my_qp->ipz_rqueue);
  659. create_qp_exit3:
  660. if (HAS_SQ(my_qp))
  661. ipz_queue_dtor(&my_qp->ipz_squeue);
  662. create_qp_exit2:
  663. hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
  664. create_qp_exit1:
  665. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  666. idr_remove(&ehca_qp_idr, my_qp->token);
  667. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  668. create_qp_exit0:
  669. kmem_cache_free(qp_cache, my_qp);
  670. return ERR_PTR(ret);
  671. }
  672. struct ib_qp *ehca_create_qp(struct ib_pd *pd,
  673. struct ib_qp_init_attr *qp_init_attr,
  674. struct ib_udata *udata)
  675. {
  676. struct ehca_qp *ret;
  677. ret = internal_create_qp(pd, qp_init_attr, NULL, udata, 0);
  678. return IS_ERR(ret) ? (struct ib_qp *)ret : &ret->ib_qp;
  679. }
  680. static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
  681. struct ib_uobject *uobject);
  682. struct ib_srq *ehca_create_srq(struct ib_pd *pd,
  683. struct ib_srq_init_attr *srq_init_attr,
  684. struct ib_udata *udata)
  685. {
  686. struct ib_qp_init_attr qp_init_attr;
  687. struct ehca_qp *my_qp;
  688. struct ib_srq *ret;
  689. struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
  690. ib_device);
  691. struct hcp_modify_qp_control_block *mqpcb;
  692. u64 hret, update_mask;
  693. /* For common attributes, internal_create_qp() takes its info
  694. * out of qp_init_attr, so copy all common attrs there.
  695. */
  696. memset(&qp_init_attr, 0, sizeof(qp_init_attr));
  697. qp_init_attr.event_handler = srq_init_attr->event_handler;
  698. qp_init_attr.qp_context = srq_init_attr->srq_context;
  699. qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
  700. qp_init_attr.qp_type = IB_QPT_RC;
  701. qp_init_attr.cap.max_recv_wr = srq_init_attr->attr.max_wr;
  702. qp_init_attr.cap.max_recv_sge = srq_init_attr->attr.max_sge;
  703. my_qp = internal_create_qp(pd, &qp_init_attr, srq_init_attr, udata, 1);
  704. if (IS_ERR(my_qp))
  705. return (struct ib_srq *)my_qp;
  706. /* copy back return values */
  707. srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr;
  708. srq_init_attr->attr.max_sge = qp_init_attr.cap.max_recv_sge;
  709. /* drive SRQ into RTR state */
  710. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  711. if (!mqpcb) {
  712. ehca_err(pd->device, "Could not get zeroed page for mqpcb "
  713. "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
  714. ret = ERR_PTR(-ENOMEM);
  715. goto create_srq1;
  716. }
  717. mqpcb->qp_state = EHCA_QPS_INIT;
  718. mqpcb->prim_phys_port = 1;
  719. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  720. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  721. my_qp->ipz_qp_handle,
  722. &my_qp->pf,
  723. update_mask,
  724. mqpcb, my_qp->galpas.kernel);
  725. if (hret != H_SUCCESS) {
  726. ehca_err(pd->device, "Could not modify SRQ to INIT"
  727. "ehca_qp=%p qp_num=%x hret=%lx",
  728. my_qp, my_qp->real_qp_num, hret);
  729. goto create_srq2;
  730. }
  731. mqpcb->qp_enable = 1;
  732. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
  733. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  734. my_qp->ipz_qp_handle,
  735. &my_qp->pf,
  736. update_mask,
  737. mqpcb, my_qp->galpas.kernel);
  738. if (hret != H_SUCCESS) {
  739. ehca_err(pd->device, "Could not enable SRQ"
  740. "ehca_qp=%p qp_num=%x hret=%lx",
  741. my_qp, my_qp->real_qp_num, hret);
  742. goto create_srq2;
  743. }
  744. mqpcb->qp_state = EHCA_QPS_RTR;
  745. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  746. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  747. my_qp->ipz_qp_handle,
  748. &my_qp->pf,
  749. update_mask,
  750. mqpcb, my_qp->galpas.kernel);
  751. if (hret != H_SUCCESS) {
  752. ehca_err(pd->device, "Could not modify SRQ to RTR"
  753. "ehca_qp=%p qp_num=%x hret=%lx",
  754. my_qp, my_qp->real_qp_num, hret);
  755. goto create_srq2;
  756. }
  757. return &my_qp->ib_srq;
  758. create_srq2:
  759. ret = ERR_PTR(ehca2ib_return_code(hret));
  760. ehca_free_fw_ctrlblock(mqpcb);
  761. create_srq1:
  762. internal_destroy_qp(pd->device, my_qp, my_qp->ib_srq.uobject);
  763. return ret;
  764. }
  765. /*
  766. * prepare_sqe_rts called by internal_modify_qp() at trans sqe -> rts
  767. * set purge bit of bad wqe and subsequent wqes to avoid reentering sqe
  768. * returns total number of bad wqes in bad_wqe_cnt
  769. */
  770. static int prepare_sqe_rts(struct ehca_qp *my_qp, struct ehca_shca *shca,
  771. int *bad_wqe_cnt)
  772. {
  773. u64 h_ret;
  774. struct ipz_queue *squeue;
  775. void *bad_send_wqe_p, *bad_send_wqe_v;
  776. u64 q_ofs;
  777. struct ehca_wqe *wqe;
  778. int qp_num = my_qp->ib_qp.qp_num;
  779. /* get send wqe pointer */
  780. h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle,
  781. my_qp->ipz_qp_handle, &my_qp->pf,
  782. &bad_send_wqe_p, NULL, 2);
  783. if (h_ret != H_SUCCESS) {
  784. ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed"
  785. " ehca_qp=%p qp_num=%x h_ret=%lx",
  786. my_qp, qp_num, h_ret);
  787. return ehca2ib_return_code(h_ret);
  788. }
  789. bad_send_wqe_p = (void *)((u64)bad_send_wqe_p & (~(1L << 63)));
  790. ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p",
  791. qp_num, bad_send_wqe_p);
  792. /* convert wqe pointer to vadr */
  793. bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p);
  794. if (ehca_debug_level)
  795. ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num);
  796. squeue = &my_qp->ipz_squeue;
  797. if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) {
  798. ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x"
  799. " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p);
  800. return -EFAULT;
  801. }
  802. /* loop sets wqe's purge bit */
  803. wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs);
  804. *bad_wqe_cnt = 0;
  805. while (wqe->optype != 0xff && wqe->wqef != 0xff) {
  806. if (ehca_debug_level)
  807. ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num);
  808. wqe->nr_of_data_seg = 0; /* suppress data access */
  809. wqe->wqef = WQEF_PURGE; /* WQE to be purged */
  810. q_ofs = ipz_queue_advance_offset(squeue, q_ofs);
  811. wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs);
  812. *bad_wqe_cnt = (*bad_wqe_cnt)+1;
  813. }
  814. /*
  815. * bad wqe will be reprocessed and ignored when pol_cq() is called,
  816. * i.e. nr of wqes with flush error status is one less
  817. */
  818. ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x",
  819. qp_num, (*bad_wqe_cnt)-1);
  820. wqe->wqef = 0;
  821. return 0;
  822. }
  823. /*
  824. * internal_modify_qp with circumvention to handle aqp0 properly
  825. * smi_reset2init indicates if this is an internal reset-to-init-call for
  826. * smi. This flag must always be zero if called from ehca_modify_qp()!
  827. * This internal func was intorduced to avoid recursion of ehca_modify_qp()!
  828. */
  829. static int internal_modify_qp(struct ib_qp *ibqp,
  830. struct ib_qp_attr *attr,
  831. int attr_mask, int smi_reset2init)
  832. {
  833. enum ib_qp_state qp_cur_state, qp_new_state;
  834. int cnt, qp_attr_idx, ret = 0;
  835. enum ib_qp_statetrans statetrans;
  836. struct hcp_modify_qp_control_block *mqpcb;
  837. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  838. struct ehca_shca *shca =
  839. container_of(ibqp->pd->device, struct ehca_shca, ib_device);
  840. u64 update_mask;
  841. u64 h_ret;
  842. int bad_wqe_cnt = 0;
  843. int squeue_locked = 0;
  844. unsigned long flags = 0;
  845. /* do query_qp to obtain current attr values */
  846. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  847. if (!mqpcb) {
  848. ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
  849. "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
  850. return -ENOMEM;
  851. }
  852. h_ret = hipz_h_query_qp(shca->ipz_hca_handle,
  853. my_qp->ipz_qp_handle,
  854. &my_qp->pf,
  855. mqpcb, my_qp->galpas.kernel);
  856. if (h_ret != H_SUCCESS) {
  857. ehca_err(ibqp->device, "hipz_h_query_qp() failed "
  858. "ehca_qp=%p qp_num=%x h_ret=%lx",
  859. my_qp, ibqp->qp_num, h_ret);
  860. ret = ehca2ib_return_code(h_ret);
  861. goto modify_qp_exit1;
  862. }
  863. qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state);
  864. if (qp_cur_state == -EINVAL) { /* invalid qp state */
  865. ret = -EINVAL;
  866. ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x "
  867. "ehca_qp=%p qp_num=%x",
  868. mqpcb->qp_state, my_qp, ibqp->qp_num);
  869. goto modify_qp_exit1;
  870. }
  871. /*
  872. * circumvention to set aqp0 initial state to init
  873. * as expected by IB spec
  874. */
  875. if (smi_reset2init == 0 &&
  876. ibqp->qp_type == IB_QPT_SMI &&
  877. qp_cur_state == IB_QPS_RESET &&
  878. (attr_mask & IB_QP_STATE) &&
  879. attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */
  880. struct ib_qp_attr smiqp_attr = {
  881. .qp_state = IB_QPS_INIT,
  882. .port_num = my_qp->init_attr.port_num,
  883. .pkey_index = 0,
  884. .qkey = 0
  885. };
  886. int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT |
  887. IB_QP_PKEY_INDEX | IB_QP_QKEY;
  888. int smirc = internal_modify_qp(
  889. ibqp, &smiqp_attr, smiqp_attr_mask, 1);
  890. if (smirc) {
  891. ehca_err(ibqp->device, "SMI RESET -> INIT failed. "
  892. "ehca_modify_qp() rc=%x", smirc);
  893. ret = H_PARAMETER;
  894. goto modify_qp_exit1;
  895. }
  896. qp_cur_state = IB_QPS_INIT;
  897. ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded");
  898. }
  899. /* is transmitted current state equal to "real" current state */
  900. if ((attr_mask & IB_QP_CUR_STATE) &&
  901. qp_cur_state != attr->cur_qp_state) {
  902. ret = -EINVAL;
  903. ehca_err(ibqp->device,
  904. "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>"
  905. " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x",
  906. attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num);
  907. goto modify_qp_exit1;
  908. }
  909. ehca_dbg(ibqp->device, "ehca_qp=%p qp_num=%x current qp_state=%x "
  910. "new qp_state=%x attribute_mask=%x",
  911. my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask);
  912. qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state;
  913. if (!smi_reset2init &&
  914. !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type,
  915. attr_mask)) {
  916. ret = -EINVAL;
  917. ehca_err(ibqp->device,
  918. "Invalid qp transition new_state=%x cur_state=%x "
  919. "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state,
  920. qp_cur_state, my_qp, ibqp->qp_num, attr_mask);
  921. goto modify_qp_exit1;
  922. }
  923. mqpcb->qp_state = ib2ehca_qp_state(qp_new_state);
  924. if (mqpcb->qp_state)
  925. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  926. else {
  927. ret = -EINVAL;
  928. ehca_err(ibqp->device, "Invalid new qp state=%x "
  929. "ehca_qp=%p qp_num=%x",
  930. qp_new_state, my_qp, ibqp->qp_num);
  931. goto modify_qp_exit1;
  932. }
  933. /* retrieve state transition struct to get req and opt attrs */
  934. statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state);
  935. if (statetrans < 0) {
  936. ret = -EINVAL;
  937. ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x "
  938. "new_qp_state=%x State_xsition=%x ehca_qp=%p "
  939. "qp_num=%x", qp_cur_state, qp_new_state,
  940. statetrans, my_qp, ibqp->qp_num);
  941. goto modify_qp_exit1;
  942. }
  943. qp_attr_idx = ib2ehcaqptype(ibqp->qp_type);
  944. if (qp_attr_idx < 0) {
  945. ret = qp_attr_idx;
  946. ehca_err(ibqp->device,
  947. "Invalid QP type=%x ehca_qp=%p qp_num=%x",
  948. ibqp->qp_type, my_qp, ibqp->qp_num);
  949. goto modify_qp_exit1;
  950. }
  951. ehca_dbg(ibqp->device,
  952. "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x",
  953. my_qp, ibqp->qp_num, statetrans);
  954. /* eHCA2 rev2 and higher require the SEND_GRH_FLAG to be set
  955. * in non-LL UD QPs.
  956. */
  957. if ((my_qp->qp_type == IB_QPT_UD) &&
  958. (my_qp->ext_type != EQPT_LLQP) &&
  959. (statetrans == IB_QPST_INIT2RTR) &&
  960. (shca->hw_level >= 0x22)) {
  961. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
  962. mqpcb->send_grh_flag = 1;
  963. }
  964. /* sqe -> rts: set purge bit of bad wqe before actual trans */
  965. if ((my_qp->qp_type == IB_QPT_UD ||
  966. my_qp->qp_type == IB_QPT_GSI ||
  967. my_qp->qp_type == IB_QPT_SMI) &&
  968. statetrans == IB_QPST_SQE2RTS) {
  969. /* mark next free wqe if kernel */
  970. if (!ibqp->uobject) {
  971. struct ehca_wqe *wqe;
  972. /* lock send queue */
  973. spin_lock_irqsave(&my_qp->spinlock_s, flags);
  974. squeue_locked = 1;
  975. /* mark next free wqe */
  976. wqe = (struct ehca_wqe *)
  977. ipz_qeit_get(&my_qp->ipz_squeue);
  978. wqe->optype = wqe->wqef = 0xff;
  979. ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p",
  980. ibqp->qp_num, wqe);
  981. }
  982. ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt);
  983. if (ret) {
  984. ehca_err(ibqp->device, "prepare_sqe_rts() failed "
  985. "ehca_qp=%p qp_num=%x ret=%x",
  986. my_qp, ibqp->qp_num, ret);
  987. goto modify_qp_exit2;
  988. }
  989. }
  990. /*
  991. * enable RDMA_Atomic_Control if reset->init und reliable con
  992. * this is necessary since gen2 does not provide that flag,
  993. * but pHyp requires it
  994. */
  995. if (statetrans == IB_QPST_RESET2INIT &&
  996. (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) {
  997. mqpcb->rdma_atomic_ctrl = 3;
  998. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1);
  999. }
  1000. /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */
  1001. if (statetrans == IB_QPST_INIT2RTR &&
  1002. (ibqp->qp_type == IB_QPT_UC) &&
  1003. !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) {
  1004. mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */
  1005. update_mask |=
  1006. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  1007. }
  1008. if (attr_mask & IB_QP_PKEY_INDEX) {
  1009. mqpcb->prim_p_key_idx = attr->pkey_index;
  1010. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1);
  1011. }
  1012. if (attr_mask & IB_QP_PORT) {
  1013. if (attr->port_num < 1 || attr->port_num > shca->num_ports) {
  1014. ret = -EINVAL;
  1015. ehca_err(ibqp->device, "Invalid port=%x. "
  1016. "ehca_qp=%p qp_num=%x num_ports=%x",
  1017. attr->port_num, my_qp, ibqp->qp_num,
  1018. shca->num_ports);
  1019. goto modify_qp_exit2;
  1020. }
  1021. mqpcb->prim_phys_port = attr->port_num;
  1022. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1);
  1023. }
  1024. if (attr_mask & IB_QP_QKEY) {
  1025. mqpcb->qkey = attr->qkey;
  1026. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1);
  1027. }
  1028. if (attr_mask & IB_QP_AV) {
  1029. int ah_mult = ib_rate_to_mult(attr->ah_attr.static_rate);
  1030. int ehca_mult = ib_rate_to_mult(shca->sport[my_qp->
  1031. init_attr.port_num].rate);
  1032. mqpcb->dlid = attr->ah_attr.dlid;
  1033. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1);
  1034. mqpcb->source_path_bits = attr->ah_attr.src_path_bits;
  1035. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1);
  1036. mqpcb->service_level = attr->ah_attr.sl;
  1037. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
  1038. if (ah_mult < ehca_mult)
  1039. mqpcb->max_static_rate = (ah_mult > 0) ?
  1040. ((ehca_mult - 1) / ah_mult) : 0;
  1041. else
  1042. mqpcb->max_static_rate = 0;
  1043. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
  1044. /*
  1045. * Always supply the GRH flag, even if it's zero, to give the
  1046. * hypervisor a clear "yes" or "no" instead of a "perhaps"
  1047. */
  1048. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
  1049. /*
  1050. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  1051. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  1052. */
  1053. if (attr->ah_attr.ah_flags == IB_AH_GRH) {
  1054. mqpcb->send_grh_flag = 1;
  1055. mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
  1056. update_mask |=
  1057. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
  1058. for (cnt = 0; cnt < 16; cnt++)
  1059. mqpcb->dest_gid.byte[cnt] =
  1060. attr->ah_attr.grh.dgid.raw[cnt];
  1061. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1);
  1062. mqpcb->flow_label = attr->ah_attr.grh.flow_label;
  1063. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1);
  1064. mqpcb->hop_limit = attr->ah_attr.grh.hop_limit;
  1065. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1);
  1066. mqpcb->traffic_class = attr->ah_attr.grh.traffic_class;
  1067. update_mask |=
  1068. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1);
  1069. }
  1070. }
  1071. if (attr_mask & IB_QP_PATH_MTU) {
  1072. mqpcb->path_mtu = attr->path_mtu;
  1073. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1);
  1074. }
  1075. if (attr_mask & IB_QP_TIMEOUT) {
  1076. mqpcb->timeout = attr->timeout;
  1077. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1);
  1078. }
  1079. if (attr_mask & IB_QP_RETRY_CNT) {
  1080. mqpcb->retry_count = attr->retry_cnt;
  1081. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1);
  1082. }
  1083. if (attr_mask & IB_QP_RNR_RETRY) {
  1084. mqpcb->rnr_retry_count = attr->rnr_retry;
  1085. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1);
  1086. }
  1087. if (attr_mask & IB_QP_RQ_PSN) {
  1088. mqpcb->receive_psn = attr->rq_psn;
  1089. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1);
  1090. }
  1091. if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
  1092. mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ?
  1093. attr->max_dest_rd_atomic : 2;
  1094. update_mask |=
  1095. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  1096. }
  1097. if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
  1098. mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ?
  1099. attr->max_rd_atomic : 2;
  1100. update_mask |=
  1101. EHCA_BMASK_SET
  1102. (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1);
  1103. }
  1104. if (attr_mask & IB_QP_ALT_PATH) {
  1105. int ah_mult = ib_rate_to_mult(attr->alt_ah_attr.static_rate);
  1106. int ehca_mult = ib_rate_to_mult(
  1107. shca->sport[my_qp->init_attr.port_num].rate);
  1108. mqpcb->dlid_al = attr->alt_ah_attr.dlid;
  1109. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1);
  1110. mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
  1111. update_mask |=
  1112. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1);
  1113. mqpcb->service_level_al = attr->alt_ah_attr.sl;
  1114. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1);
  1115. if (ah_mult < ehca_mult)
  1116. mqpcb->max_static_rate = (ah_mult > 0) ?
  1117. ((ehca_mult - 1) / ah_mult) : 0;
  1118. else
  1119. mqpcb->max_static_rate_al = 0;
  1120. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1);
  1121. /*
  1122. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  1123. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  1124. */
  1125. if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) {
  1126. mqpcb->send_grh_flag_al = 1 << 31;
  1127. update_mask |=
  1128. EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1);
  1129. mqpcb->source_gid_idx_al =
  1130. attr->alt_ah_attr.grh.sgid_index;
  1131. update_mask |=
  1132. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1);
  1133. for (cnt = 0; cnt < 16; cnt++)
  1134. mqpcb->dest_gid_al.byte[cnt] =
  1135. attr->alt_ah_attr.grh.dgid.raw[cnt];
  1136. update_mask |=
  1137. EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1);
  1138. mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label;
  1139. update_mask |=
  1140. EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1);
  1141. mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit;
  1142. update_mask |=
  1143. EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1);
  1144. mqpcb->traffic_class_al =
  1145. attr->alt_ah_attr.grh.traffic_class;
  1146. update_mask |=
  1147. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1);
  1148. }
  1149. }
  1150. if (attr_mask & IB_QP_MIN_RNR_TIMER) {
  1151. mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer;
  1152. update_mask |=
  1153. EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1);
  1154. }
  1155. if (attr_mask & IB_QP_SQ_PSN) {
  1156. mqpcb->send_psn = attr->sq_psn;
  1157. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1);
  1158. }
  1159. if (attr_mask & IB_QP_DEST_QPN) {
  1160. mqpcb->dest_qp_nr = attr->dest_qp_num;
  1161. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1);
  1162. }
  1163. if (attr_mask & IB_QP_PATH_MIG_STATE) {
  1164. mqpcb->path_migration_state = attr->path_mig_state;
  1165. update_mask |=
  1166. EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
  1167. }
  1168. if (attr_mask & IB_QP_CAP) {
  1169. mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1;
  1170. update_mask |=
  1171. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1);
  1172. mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1;
  1173. update_mask |=
  1174. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1);
  1175. /* no support for max_send/recv_sge yet */
  1176. }
  1177. if (ehca_debug_level)
  1178. ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num);
  1179. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1180. my_qp->ipz_qp_handle,
  1181. &my_qp->pf,
  1182. update_mask,
  1183. mqpcb, my_qp->galpas.kernel);
  1184. if (h_ret != H_SUCCESS) {
  1185. ret = ehca2ib_return_code(h_ret);
  1186. ehca_err(ibqp->device, "hipz_h_modify_qp() failed rc=%lx "
  1187. "ehca_qp=%p qp_num=%x", h_ret, my_qp, ibqp->qp_num);
  1188. goto modify_qp_exit2;
  1189. }
  1190. if ((my_qp->qp_type == IB_QPT_UD ||
  1191. my_qp->qp_type == IB_QPT_GSI ||
  1192. my_qp->qp_type == IB_QPT_SMI) &&
  1193. statetrans == IB_QPST_SQE2RTS) {
  1194. /* doorbell to reprocessing wqes */
  1195. iosync(); /* serialize GAL register access */
  1196. hipz_update_sqa(my_qp, bad_wqe_cnt-1);
  1197. ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt);
  1198. }
  1199. if (statetrans == IB_QPST_RESET2INIT ||
  1200. statetrans == IB_QPST_INIT2INIT) {
  1201. mqpcb->qp_enable = 1;
  1202. mqpcb->qp_state = EHCA_QPS_INIT;
  1203. update_mask = 0;
  1204. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
  1205. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1206. my_qp->ipz_qp_handle,
  1207. &my_qp->pf,
  1208. update_mask,
  1209. mqpcb,
  1210. my_qp->galpas.kernel);
  1211. if (h_ret != H_SUCCESS) {
  1212. ret = ehca2ib_return_code(h_ret);
  1213. ehca_err(ibqp->device, "ENABLE in context of "
  1214. "RESET_2_INIT failed! Maybe you didn't get "
  1215. "a LID h_ret=%lx ehca_qp=%p qp_num=%x",
  1216. h_ret, my_qp, ibqp->qp_num);
  1217. goto modify_qp_exit2;
  1218. }
  1219. }
  1220. if (statetrans == IB_QPST_ANY2RESET) {
  1221. ipz_qeit_reset(&my_qp->ipz_rqueue);
  1222. ipz_qeit_reset(&my_qp->ipz_squeue);
  1223. }
  1224. if (attr_mask & IB_QP_QKEY)
  1225. my_qp->qkey = attr->qkey;
  1226. modify_qp_exit2:
  1227. if (squeue_locked) { /* this means: sqe -> rts */
  1228. spin_unlock_irqrestore(&my_qp->spinlock_s, flags);
  1229. my_qp->sqerr_purgeflag = 1;
  1230. }
  1231. modify_qp_exit1:
  1232. ehca_free_fw_ctrlblock(mqpcb);
  1233. return ret;
  1234. }
  1235. int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
  1236. struct ib_udata *udata)
  1237. {
  1238. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  1239. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1240. ib_pd);
  1241. u32 cur_pid = current->tgid;
  1242. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1243. my_pd->ownpid != cur_pid) {
  1244. ehca_err(ibqp->pd->device, "Invalid caller pid=%x ownpid=%x",
  1245. cur_pid, my_pd->ownpid);
  1246. return -EINVAL;
  1247. }
  1248. return internal_modify_qp(ibqp, attr, attr_mask, 0);
  1249. }
  1250. int ehca_query_qp(struct ib_qp *qp,
  1251. struct ib_qp_attr *qp_attr,
  1252. int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr)
  1253. {
  1254. struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
  1255. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1256. ib_pd);
  1257. struct ehca_shca *shca = container_of(qp->device, struct ehca_shca,
  1258. ib_device);
  1259. struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
  1260. struct hcp_modify_qp_control_block *qpcb;
  1261. u32 cur_pid = current->tgid;
  1262. int cnt, ret = 0;
  1263. u64 h_ret;
  1264. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1265. my_pd->ownpid != cur_pid) {
  1266. ehca_err(qp->device, "Invalid caller pid=%x ownpid=%x",
  1267. cur_pid, my_pd->ownpid);
  1268. return -EINVAL;
  1269. }
  1270. if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) {
  1271. ehca_err(qp->device, "Invalid attribute mask "
  1272. "ehca_qp=%p qp_num=%x qp_attr_mask=%x ",
  1273. my_qp, qp->qp_num, qp_attr_mask);
  1274. return -EINVAL;
  1275. }
  1276. qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1277. if (!qpcb) {
  1278. ehca_err(qp->device, "Out of memory for qpcb "
  1279. "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
  1280. return -ENOMEM;
  1281. }
  1282. h_ret = hipz_h_query_qp(adapter_handle,
  1283. my_qp->ipz_qp_handle,
  1284. &my_qp->pf,
  1285. qpcb, my_qp->galpas.kernel);
  1286. if (h_ret != H_SUCCESS) {
  1287. ret = ehca2ib_return_code(h_ret);
  1288. ehca_err(qp->device, "hipz_h_query_qp() failed "
  1289. "ehca_qp=%p qp_num=%x h_ret=%lx",
  1290. my_qp, qp->qp_num, h_ret);
  1291. goto query_qp_exit1;
  1292. }
  1293. qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state);
  1294. qp_attr->qp_state = qp_attr->cur_qp_state;
  1295. if (qp_attr->cur_qp_state == -EINVAL) {
  1296. ret = -EINVAL;
  1297. ehca_err(qp->device, "Got invalid ehca_qp_state=%x "
  1298. "ehca_qp=%p qp_num=%x",
  1299. qpcb->qp_state, my_qp, qp->qp_num);
  1300. goto query_qp_exit1;
  1301. }
  1302. if (qp_attr->qp_state == IB_QPS_SQD)
  1303. qp_attr->sq_draining = 1;
  1304. qp_attr->qkey = qpcb->qkey;
  1305. qp_attr->path_mtu = qpcb->path_mtu;
  1306. qp_attr->path_mig_state = qpcb->path_migration_state;
  1307. qp_attr->rq_psn = qpcb->receive_psn;
  1308. qp_attr->sq_psn = qpcb->send_psn;
  1309. qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field;
  1310. qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1;
  1311. qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1;
  1312. /* UD_AV CIRCUMVENTION */
  1313. if (my_qp->qp_type == IB_QPT_UD) {
  1314. qp_attr->cap.max_send_sge =
  1315. qpcb->actual_nr_sges_in_sq_wqe - 2;
  1316. qp_attr->cap.max_recv_sge =
  1317. qpcb->actual_nr_sges_in_rq_wqe - 2;
  1318. } else {
  1319. qp_attr->cap.max_send_sge =
  1320. qpcb->actual_nr_sges_in_sq_wqe;
  1321. qp_attr->cap.max_recv_sge =
  1322. qpcb->actual_nr_sges_in_rq_wqe;
  1323. }
  1324. qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size;
  1325. qp_attr->dest_qp_num = qpcb->dest_qp_nr;
  1326. qp_attr->pkey_index =
  1327. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx);
  1328. qp_attr->port_num =
  1329. EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port);
  1330. qp_attr->timeout = qpcb->timeout;
  1331. qp_attr->retry_cnt = qpcb->retry_count;
  1332. qp_attr->rnr_retry = qpcb->rnr_retry_count;
  1333. qp_attr->alt_pkey_index =
  1334. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx);
  1335. qp_attr->alt_port_num = qpcb->alt_phys_port;
  1336. qp_attr->alt_timeout = qpcb->timeout_al;
  1337. qp_attr->max_dest_rd_atomic = qpcb->rdma_nr_atomic_resp_res;
  1338. qp_attr->max_rd_atomic = qpcb->rdma_atomic_outst_dest_qp;
  1339. /* primary av */
  1340. qp_attr->ah_attr.sl = qpcb->service_level;
  1341. if (qpcb->send_grh_flag) {
  1342. qp_attr->ah_attr.ah_flags = IB_AH_GRH;
  1343. }
  1344. qp_attr->ah_attr.static_rate = qpcb->max_static_rate;
  1345. qp_attr->ah_attr.dlid = qpcb->dlid;
  1346. qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits;
  1347. qp_attr->ah_attr.port_num = qp_attr->port_num;
  1348. /* primary GRH */
  1349. qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class;
  1350. qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit;
  1351. qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx;
  1352. qp_attr->ah_attr.grh.flow_label = qpcb->flow_label;
  1353. for (cnt = 0; cnt < 16; cnt++)
  1354. qp_attr->ah_attr.grh.dgid.raw[cnt] =
  1355. qpcb->dest_gid.byte[cnt];
  1356. /* alternate AV */
  1357. qp_attr->alt_ah_attr.sl = qpcb->service_level_al;
  1358. if (qpcb->send_grh_flag_al) {
  1359. qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH;
  1360. }
  1361. qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al;
  1362. qp_attr->alt_ah_attr.dlid = qpcb->dlid_al;
  1363. qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al;
  1364. /* alternate GRH */
  1365. qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al;
  1366. qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al;
  1367. qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al;
  1368. qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al;
  1369. for (cnt = 0; cnt < 16; cnt++)
  1370. qp_attr->alt_ah_attr.grh.dgid.raw[cnt] =
  1371. qpcb->dest_gid_al.byte[cnt];
  1372. /* return init attributes given in ehca_create_qp */
  1373. if (qp_init_attr)
  1374. *qp_init_attr = my_qp->init_attr;
  1375. if (ehca_debug_level)
  1376. ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num);
  1377. query_qp_exit1:
  1378. ehca_free_fw_ctrlblock(qpcb);
  1379. return ret;
  1380. }
  1381. int ehca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  1382. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata)
  1383. {
  1384. struct ehca_qp *my_qp =
  1385. container_of(ibsrq, struct ehca_qp, ib_srq);
  1386. struct ehca_pd *my_pd =
  1387. container_of(ibsrq->pd, struct ehca_pd, ib_pd);
  1388. struct ehca_shca *shca =
  1389. container_of(ibsrq->pd->device, struct ehca_shca, ib_device);
  1390. struct hcp_modify_qp_control_block *mqpcb;
  1391. u64 update_mask;
  1392. u64 h_ret;
  1393. int ret = 0;
  1394. u32 cur_pid = current->tgid;
  1395. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1396. my_pd->ownpid != cur_pid) {
  1397. ehca_err(ibsrq->pd->device, "Invalid caller pid=%x ownpid=%x",
  1398. cur_pid, my_pd->ownpid);
  1399. return -EINVAL;
  1400. }
  1401. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1402. if (!mqpcb) {
  1403. ehca_err(ibsrq->device, "Could not get zeroed page for mqpcb "
  1404. "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
  1405. return -ENOMEM;
  1406. }
  1407. update_mask = 0;
  1408. if (attr_mask & IB_SRQ_LIMIT) {
  1409. attr_mask &= ~IB_SRQ_LIMIT;
  1410. update_mask |=
  1411. EHCA_BMASK_SET(MQPCB_MASK_CURR_SRQ_LIMIT, 1)
  1412. | EHCA_BMASK_SET(MQPCB_MASK_QP_AFF_ASYN_EV_LOG_REG, 1);
  1413. mqpcb->curr_srq_limit =
  1414. EHCA_BMASK_SET(MQPCB_CURR_SRQ_LIMIT, attr->srq_limit);
  1415. mqpcb->qp_aff_asyn_ev_log_reg =
  1416. EHCA_BMASK_SET(QPX_AAELOG_RESET_SRQ_LIMIT, 1);
  1417. }
  1418. /* by now, all bits in attr_mask should have been cleared */
  1419. if (attr_mask) {
  1420. ehca_err(ibsrq->device, "invalid attribute mask bits set "
  1421. "attr_mask=%x", attr_mask);
  1422. ret = -EINVAL;
  1423. goto modify_srq_exit0;
  1424. }
  1425. if (ehca_debug_level)
  1426. ehca_dmp(mqpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
  1427. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, my_qp->ipz_qp_handle,
  1428. NULL, update_mask, mqpcb,
  1429. my_qp->galpas.kernel);
  1430. if (h_ret != H_SUCCESS) {
  1431. ret = ehca2ib_return_code(h_ret);
  1432. ehca_err(ibsrq->device, "hipz_h_modify_qp() failed rc=%lx "
  1433. "ehca_qp=%p qp_num=%x",
  1434. h_ret, my_qp, my_qp->real_qp_num);
  1435. }
  1436. modify_srq_exit0:
  1437. ehca_free_fw_ctrlblock(mqpcb);
  1438. return ret;
  1439. }
  1440. int ehca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr)
  1441. {
  1442. struct ehca_qp *my_qp = container_of(srq, struct ehca_qp, ib_srq);
  1443. struct ehca_pd *my_pd = container_of(srq->pd, struct ehca_pd, ib_pd);
  1444. struct ehca_shca *shca = container_of(srq->device, struct ehca_shca,
  1445. ib_device);
  1446. struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
  1447. struct hcp_modify_qp_control_block *qpcb;
  1448. u32 cur_pid = current->tgid;
  1449. int ret = 0;
  1450. u64 h_ret;
  1451. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1452. my_pd->ownpid != cur_pid) {
  1453. ehca_err(srq->device, "Invalid caller pid=%x ownpid=%x",
  1454. cur_pid, my_pd->ownpid);
  1455. return -EINVAL;
  1456. }
  1457. qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1458. if (!qpcb) {
  1459. ehca_err(srq->device, "Out of memory for qpcb "
  1460. "ehca_qp=%p qp_num=%x", my_qp, my_qp->real_qp_num);
  1461. return -ENOMEM;
  1462. }
  1463. h_ret = hipz_h_query_qp(adapter_handle, my_qp->ipz_qp_handle,
  1464. NULL, qpcb, my_qp->galpas.kernel);
  1465. if (h_ret != H_SUCCESS) {
  1466. ret = ehca2ib_return_code(h_ret);
  1467. ehca_err(srq->device, "hipz_h_query_qp() failed "
  1468. "ehca_qp=%p qp_num=%x h_ret=%lx",
  1469. my_qp, my_qp->real_qp_num, h_ret);
  1470. goto query_srq_exit1;
  1471. }
  1472. srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1;
  1473. srq_attr->srq_limit = EHCA_BMASK_GET(
  1474. MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit);
  1475. if (ehca_debug_level)
  1476. ehca_dmp(qpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
  1477. query_srq_exit1:
  1478. ehca_free_fw_ctrlblock(qpcb);
  1479. return ret;
  1480. }
  1481. static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
  1482. struct ib_uobject *uobject)
  1483. {
  1484. struct ehca_shca *shca = container_of(dev, struct ehca_shca, ib_device);
  1485. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1486. ib_pd);
  1487. u32 cur_pid = current->tgid;
  1488. u32 qp_num = my_qp->real_qp_num;
  1489. int ret;
  1490. u64 h_ret;
  1491. u8 port_num;
  1492. enum ib_qp_type qp_type;
  1493. unsigned long flags;
  1494. if (uobject) {
  1495. if (my_qp->mm_count_galpa ||
  1496. my_qp->mm_count_rqueue || my_qp->mm_count_squeue) {
  1497. ehca_err(dev, "Resources still referenced in "
  1498. "user space qp_num=%x", qp_num);
  1499. return -EINVAL;
  1500. }
  1501. if (my_pd->ownpid != cur_pid) {
  1502. ehca_err(dev, "Invalid caller pid=%x ownpid=%x",
  1503. cur_pid, my_pd->ownpid);
  1504. return -EINVAL;
  1505. }
  1506. }
  1507. if (my_qp->send_cq) {
  1508. ret = ehca_cq_unassign_qp(my_qp->send_cq, qp_num);
  1509. if (ret) {
  1510. ehca_err(dev, "Couldn't unassign qp from "
  1511. "send_cq ret=%x qp_num=%x cq_num=%x", ret,
  1512. qp_num, my_qp->send_cq->cq_number);
  1513. return ret;
  1514. }
  1515. }
  1516. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  1517. idr_remove(&ehca_qp_idr, my_qp->token);
  1518. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  1519. h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
  1520. if (h_ret != H_SUCCESS) {
  1521. ehca_err(dev, "hipz_h_destroy_qp() failed rc=%lx "
  1522. "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num);
  1523. return ehca2ib_return_code(h_ret);
  1524. }
  1525. port_num = my_qp->init_attr.port_num;
  1526. qp_type = my_qp->init_attr.qp_type;
  1527. /* no support for IB_QPT_SMI yet */
  1528. if (qp_type == IB_QPT_GSI) {
  1529. struct ib_event event;
  1530. ehca_info(dev, "device %s: port %x is inactive.",
  1531. shca->ib_device.name, port_num);
  1532. event.device = &shca->ib_device;
  1533. event.event = IB_EVENT_PORT_ERR;
  1534. event.element.port_num = port_num;
  1535. shca->sport[port_num - 1].port_state = IB_PORT_DOWN;
  1536. ib_dispatch_event(&event);
  1537. }
  1538. if (HAS_RQ(my_qp))
  1539. ipz_queue_dtor(&my_qp->ipz_rqueue);
  1540. if (HAS_SQ(my_qp))
  1541. ipz_queue_dtor(&my_qp->ipz_squeue);
  1542. kmem_cache_free(qp_cache, my_qp);
  1543. return 0;
  1544. }
  1545. int ehca_destroy_qp(struct ib_qp *qp)
  1546. {
  1547. return internal_destroy_qp(qp->device,
  1548. container_of(qp, struct ehca_qp, ib_qp),
  1549. qp->uobject);
  1550. }
  1551. int ehca_destroy_srq(struct ib_srq *srq)
  1552. {
  1553. return internal_destroy_qp(srq->device,
  1554. container_of(srq, struct ehca_qp, ib_srq),
  1555. srq->uobject);
  1556. }
  1557. int ehca_init_qp_cache(void)
  1558. {
  1559. qp_cache = kmem_cache_create("ehca_cache_qp",
  1560. sizeof(struct ehca_qp), 0,
  1561. SLAB_HWCACHE_ALIGN,
  1562. NULL);
  1563. if (!qp_cache)
  1564. return -ENOMEM;
  1565. return 0;
  1566. }
  1567. void ehca_cleanup_qp_cache(void)
  1568. {
  1569. if (qp_cache)
  1570. kmem_cache_destroy(qp_cache);
  1571. }