ehca_qp.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  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. resp->offset = queue->offset;
  263. }
  264. /*
  265. * init_qp_queue initializes/constructs r/squeue and registers queue pages.
  266. */
  267. static inline int init_qp_queue(struct ehca_shca *shca,
  268. struct ehca_pd *pd,
  269. struct ehca_qp *my_qp,
  270. struct ipz_queue *queue,
  271. int q_type,
  272. u64 expected_hret,
  273. struct ehca_alloc_queue_parms *parms,
  274. int wqe_size)
  275. {
  276. int ret, cnt, ipz_rc, nr_q_pages;
  277. void *vpage;
  278. u64 rpage, h_ret;
  279. struct ib_device *ib_dev = &shca->ib_device;
  280. struct ipz_adapter_handle ipz_hca_handle = shca->ipz_hca_handle;
  281. if (!parms->queue_size)
  282. return 0;
  283. if (parms->is_small) {
  284. nr_q_pages = 1;
  285. ipz_rc = ipz_queue_ctor(pd, queue, nr_q_pages,
  286. 128 << parms->page_size,
  287. wqe_size, parms->act_nr_sges, 1);
  288. } else {
  289. nr_q_pages = parms->queue_size;
  290. ipz_rc = ipz_queue_ctor(pd, queue, nr_q_pages,
  291. EHCA_PAGESIZE, wqe_size,
  292. parms->act_nr_sges, 0);
  293. }
  294. if (!ipz_rc) {
  295. ehca_err(ib_dev, "Cannot allocate page for queue. ipz_rc=%i",
  296. ipz_rc);
  297. return -EBUSY;
  298. }
  299. /* register queue pages */
  300. for (cnt = 0; cnt < nr_q_pages; cnt++) {
  301. vpage = ipz_qpageit_get_inc(queue);
  302. if (!vpage) {
  303. ehca_err(ib_dev, "ipz_qpageit_get_inc() "
  304. "failed p_vpage= %p", vpage);
  305. ret = -EINVAL;
  306. goto init_qp_queue1;
  307. }
  308. rpage = virt_to_abs(vpage);
  309. h_ret = hipz_h_register_rpage_qp(ipz_hca_handle,
  310. my_qp->ipz_qp_handle,
  311. NULL, 0, q_type,
  312. rpage, parms->is_small ? 0 : 1,
  313. my_qp->galpas.kernel);
  314. if (cnt == (nr_q_pages - 1)) { /* last page! */
  315. if (h_ret != expected_hret) {
  316. ehca_err(ib_dev, "hipz_qp_register_rpage() "
  317. "h_ret=%li", h_ret);
  318. ret = ehca2ib_return_code(h_ret);
  319. goto init_qp_queue1;
  320. }
  321. vpage = ipz_qpageit_get_inc(&my_qp->ipz_rqueue);
  322. if (vpage) {
  323. ehca_err(ib_dev, "ipz_qpageit_get_inc() "
  324. "should not succeed vpage=%p", vpage);
  325. ret = -EINVAL;
  326. goto init_qp_queue1;
  327. }
  328. } else {
  329. if (h_ret != H_PAGE_REGISTERED) {
  330. ehca_err(ib_dev, "hipz_qp_register_rpage() "
  331. "h_ret=%li", h_ret);
  332. ret = ehca2ib_return_code(h_ret);
  333. goto init_qp_queue1;
  334. }
  335. }
  336. }
  337. ipz_qeit_reset(queue);
  338. return 0;
  339. init_qp_queue1:
  340. ipz_queue_dtor(pd, queue);
  341. return ret;
  342. }
  343. static inline int ehca_calc_wqe_size(int act_nr_sge, int is_llqp)
  344. {
  345. if (is_llqp)
  346. return 128 << act_nr_sge;
  347. else
  348. return offsetof(struct ehca_wqe,
  349. u.nud.sg_list[act_nr_sge]);
  350. }
  351. static void ehca_determine_small_queue(struct ehca_alloc_queue_parms *queue,
  352. int req_nr_sge, int is_llqp)
  353. {
  354. u32 wqe_size, q_size;
  355. int act_nr_sge = req_nr_sge;
  356. if (!is_llqp)
  357. /* round up #SGEs so WQE size is a power of 2 */
  358. for (act_nr_sge = 4; act_nr_sge <= 252;
  359. act_nr_sge = 4 + 2 * act_nr_sge)
  360. if (act_nr_sge >= req_nr_sge)
  361. break;
  362. wqe_size = ehca_calc_wqe_size(act_nr_sge, is_llqp);
  363. q_size = wqe_size * (queue->max_wr + 1);
  364. if (q_size <= 512)
  365. queue->page_size = 2;
  366. else if (q_size <= 1024)
  367. queue->page_size = 3;
  368. else
  369. queue->page_size = 0;
  370. queue->is_small = (queue->page_size != 0);
  371. }
  372. /*
  373. * Create an ib_qp struct that is either a QP or an SRQ, depending on
  374. * the value of the is_srq parameter. If init_attr and srq_init_attr share
  375. * fields, the field out of init_attr is used.
  376. */
  377. static struct ehca_qp *internal_create_qp(
  378. struct ib_pd *pd,
  379. struct ib_qp_init_attr *init_attr,
  380. struct ib_srq_init_attr *srq_init_attr,
  381. struct ib_udata *udata, int is_srq)
  382. {
  383. struct ehca_qp *my_qp;
  384. struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
  385. struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
  386. ib_device);
  387. struct ib_ucontext *context = NULL;
  388. u64 h_ret;
  389. int is_llqp = 0, has_srq = 0;
  390. int qp_type, max_send_sge, max_recv_sge, ret;
  391. /* h_call's out parameters */
  392. struct ehca_alloc_qp_parms parms;
  393. u32 swqe_size = 0, rwqe_size = 0, ib_qp_num;
  394. unsigned long flags;
  395. memset(&parms, 0, sizeof(parms));
  396. qp_type = init_attr->qp_type;
  397. if (init_attr->sq_sig_type != IB_SIGNAL_REQ_WR &&
  398. init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) {
  399. ehca_err(pd->device, "init_attr->sg_sig_type=%x not allowed",
  400. init_attr->sq_sig_type);
  401. return ERR_PTR(-EINVAL);
  402. }
  403. /* save LLQP info */
  404. if (qp_type & 0x80) {
  405. is_llqp = 1;
  406. parms.ext_type = EQPT_LLQP;
  407. parms.ll_comp_flags = qp_type & LLQP_COMP_MASK;
  408. }
  409. qp_type &= 0x1F;
  410. init_attr->qp_type &= 0x1F;
  411. /* handle SRQ base QPs */
  412. if (init_attr->srq) {
  413. struct ehca_qp *my_srq =
  414. container_of(init_attr->srq, struct ehca_qp, ib_srq);
  415. has_srq = 1;
  416. parms.ext_type = EQPT_SRQBASE;
  417. parms.srq_qpn = my_srq->real_qp_num;
  418. }
  419. if (is_llqp && has_srq) {
  420. ehca_err(pd->device, "LLQPs can't have an SRQ");
  421. return ERR_PTR(-EINVAL);
  422. }
  423. /* handle SRQs */
  424. if (is_srq) {
  425. parms.ext_type = EQPT_SRQ;
  426. parms.srq_limit = srq_init_attr->attr.srq_limit;
  427. if (init_attr->cap.max_recv_sge > 3) {
  428. ehca_err(pd->device, "no more than three SGEs "
  429. "supported for SRQ pd=%p max_sge=%x",
  430. pd, init_attr->cap.max_recv_sge);
  431. return ERR_PTR(-EINVAL);
  432. }
  433. }
  434. /* check QP type */
  435. if (qp_type != IB_QPT_UD &&
  436. qp_type != IB_QPT_UC &&
  437. qp_type != IB_QPT_RC &&
  438. qp_type != IB_QPT_SMI &&
  439. qp_type != IB_QPT_GSI) {
  440. ehca_err(pd->device, "wrong QP Type=%x", qp_type);
  441. return ERR_PTR(-EINVAL);
  442. }
  443. if (is_llqp) {
  444. switch (qp_type) {
  445. case IB_QPT_RC:
  446. if ((init_attr->cap.max_send_wr > 255) ||
  447. (init_attr->cap.max_recv_wr > 255)) {
  448. ehca_err(pd->device,
  449. "Invalid Number of max_sq_wr=%x "
  450. "or max_rq_wr=%x for RC LLQP",
  451. init_attr->cap.max_send_wr,
  452. init_attr->cap.max_recv_wr);
  453. return ERR_PTR(-EINVAL);
  454. }
  455. break;
  456. case IB_QPT_UD:
  457. if (!EHCA_BMASK_GET(HCA_CAP_UD_LL_QP, shca->hca_cap)) {
  458. ehca_err(pd->device, "UD LLQP not supported "
  459. "by this adapter");
  460. return ERR_PTR(-ENOSYS);
  461. }
  462. if (!(init_attr->cap.max_send_sge <= 5
  463. && init_attr->cap.max_send_sge >= 1
  464. && init_attr->cap.max_recv_sge <= 5
  465. && init_attr->cap.max_recv_sge >= 1)) {
  466. ehca_err(pd->device,
  467. "Invalid Number of max_send_sge=%x "
  468. "or max_recv_sge=%x for UD LLQP",
  469. init_attr->cap.max_send_sge,
  470. init_attr->cap.max_recv_sge);
  471. return ERR_PTR(-EINVAL);
  472. } else if (init_attr->cap.max_send_wr > 255) {
  473. ehca_err(pd->device,
  474. "Invalid Number of "
  475. "max_send_wr=%x for UD QP_TYPE=%x",
  476. init_attr->cap.max_send_wr, qp_type);
  477. return ERR_PTR(-EINVAL);
  478. }
  479. break;
  480. default:
  481. ehca_err(pd->device, "unsupported LL QP Type=%x",
  482. qp_type);
  483. return ERR_PTR(-EINVAL);
  484. break;
  485. }
  486. } else {
  487. int max_sge = (qp_type == IB_QPT_UD || qp_type == IB_QPT_SMI
  488. || qp_type == IB_QPT_GSI) ? 250 : 252;
  489. if (init_attr->cap.max_send_sge > max_sge
  490. || init_attr->cap.max_recv_sge > max_sge) {
  491. ehca_err(pd->device, "Invalid number of SGEs requested "
  492. "send_sge=%x recv_sge=%x max_sge=%x",
  493. init_attr->cap.max_send_sge,
  494. init_attr->cap.max_recv_sge, max_sge);
  495. return ERR_PTR(-EINVAL);
  496. }
  497. }
  498. if (pd->uobject && udata)
  499. context = pd->uobject->context;
  500. my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL);
  501. if (!my_qp) {
  502. ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd);
  503. return ERR_PTR(-ENOMEM);
  504. }
  505. spin_lock_init(&my_qp->spinlock_s);
  506. spin_lock_init(&my_qp->spinlock_r);
  507. my_qp->qp_type = qp_type;
  508. my_qp->ext_type = parms.ext_type;
  509. if (init_attr->recv_cq)
  510. my_qp->recv_cq =
  511. container_of(init_attr->recv_cq, struct ehca_cq, ib_cq);
  512. if (init_attr->send_cq)
  513. my_qp->send_cq =
  514. container_of(init_attr->send_cq, struct ehca_cq, ib_cq);
  515. do {
  516. if (!idr_pre_get(&ehca_qp_idr, GFP_KERNEL)) {
  517. ret = -ENOMEM;
  518. ehca_err(pd->device, "Can't reserve idr resources.");
  519. goto create_qp_exit0;
  520. }
  521. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  522. ret = idr_get_new(&ehca_qp_idr, my_qp, &my_qp->token);
  523. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  524. } while (ret == -EAGAIN);
  525. if (ret) {
  526. ret = -ENOMEM;
  527. ehca_err(pd->device, "Can't allocate new idr entry.");
  528. goto create_qp_exit0;
  529. }
  530. if (my_qp->token > 0x1FFFFFF) {
  531. ret = -EINVAL;
  532. ehca_err(pd->device, "Invalid number of qp");
  533. goto create_qp_exit1;
  534. }
  535. if (has_srq)
  536. parms.srq_token = my_qp->token;
  537. parms.servicetype = ibqptype2servicetype(qp_type);
  538. if (parms.servicetype < 0) {
  539. ret = -EINVAL;
  540. ehca_err(pd->device, "Invalid qp_type=%x", qp_type);
  541. goto create_qp_exit1;
  542. }
  543. if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
  544. parms.sigtype = HCALL_SIGT_EVERY;
  545. else
  546. parms.sigtype = HCALL_SIGT_BY_WQE;
  547. /* UD_AV CIRCUMVENTION */
  548. max_send_sge = init_attr->cap.max_send_sge;
  549. max_recv_sge = init_attr->cap.max_recv_sge;
  550. if (parms.servicetype == ST_UD && !is_llqp) {
  551. max_send_sge += 2;
  552. max_recv_sge += 2;
  553. }
  554. parms.token = my_qp->token;
  555. parms.eq_handle = shca->eq.ipz_eq_handle;
  556. parms.pd = my_pd->fw_pd;
  557. if (my_qp->send_cq)
  558. parms.send_cq_handle = my_qp->send_cq->ipz_cq_handle;
  559. if (my_qp->recv_cq)
  560. parms.recv_cq_handle = my_qp->recv_cq->ipz_cq_handle;
  561. parms.squeue.max_wr = init_attr->cap.max_send_wr;
  562. parms.rqueue.max_wr = init_attr->cap.max_recv_wr;
  563. parms.squeue.max_sge = max_send_sge;
  564. parms.rqueue.max_sge = max_recv_sge;
  565. if (EHCA_BMASK_GET(HCA_CAP_MINI_QP, shca->hca_cap)) {
  566. if (HAS_SQ(my_qp))
  567. ehca_determine_small_queue(
  568. &parms.squeue, max_send_sge, is_llqp);
  569. if (HAS_RQ(my_qp))
  570. ehca_determine_small_queue(
  571. &parms.rqueue, max_recv_sge, is_llqp);
  572. parms.qp_storage =
  573. (parms.squeue.is_small || parms.rqueue.is_small);
  574. }
  575. h_ret = hipz_h_alloc_resource_qp(shca->ipz_hca_handle, &parms);
  576. if (h_ret != H_SUCCESS) {
  577. ehca_err(pd->device, "h_alloc_resource_qp() failed h_ret=%li",
  578. h_ret);
  579. ret = ehca2ib_return_code(h_ret);
  580. goto create_qp_exit1;
  581. }
  582. ib_qp_num = my_qp->real_qp_num = parms.real_qp_num;
  583. my_qp->ipz_qp_handle = parms.qp_handle;
  584. my_qp->galpas = parms.galpas;
  585. swqe_size = ehca_calc_wqe_size(parms.squeue.act_nr_sges, is_llqp);
  586. rwqe_size = ehca_calc_wqe_size(parms.rqueue.act_nr_sges, is_llqp);
  587. switch (qp_type) {
  588. case IB_QPT_RC:
  589. if (is_llqp) {
  590. parms.squeue.act_nr_sges = 1;
  591. parms.rqueue.act_nr_sges = 1;
  592. }
  593. break;
  594. case IB_QPT_UD:
  595. case IB_QPT_GSI:
  596. case IB_QPT_SMI:
  597. /* UD circumvention */
  598. if (is_llqp) {
  599. parms.squeue.act_nr_sges = 1;
  600. parms.rqueue.act_nr_sges = 1;
  601. } else {
  602. parms.squeue.act_nr_sges -= 2;
  603. parms.rqueue.act_nr_sges -= 2;
  604. }
  605. if (IB_QPT_GSI == qp_type || IB_QPT_SMI == qp_type) {
  606. parms.squeue.act_nr_wqes = init_attr->cap.max_send_wr;
  607. parms.rqueue.act_nr_wqes = init_attr->cap.max_recv_wr;
  608. parms.squeue.act_nr_sges = init_attr->cap.max_send_sge;
  609. parms.rqueue.act_nr_sges = init_attr->cap.max_recv_sge;
  610. ib_qp_num = (qp_type == IB_QPT_SMI) ? 0 : 1;
  611. }
  612. break;
  613. default:
  614. break;
  615. }
  616. /* initialize r/squeue and register queue pages */
  617. if (HAS_SQ(my_qp)) {
  618. ret = init_qp_queue(
  619. shca, my_pd, my_qp, &my_qp->ipz_squeue, 0,
  620. HAS_RQ(my_qp) ? H_PAGE_REGISTERED : H_SUCCESS,
  621. &parms.squeue, swqe_size);
  622. if (ret) {
  623. ehca_err(pd->device, "Couldn't initialize squeue "
  624. "and pages ret=%i", ret);
  625. goto create_qp_exit2;
  626. }
  627. }
  628. if (HAS_RQ(my_qp)) {
  629. ret = init_qp_queue(
  630. shca, my_pd, my_qp, &my_qp->ipz_rqueue, 1,
  631. H_SUCCESS, &parms.rqueue, rwqe_size);
  632. if (ret) {
  633. ehca_err(pd->device, "Couldn't initialize rqueue "
  634. "and pages ret=%i", ret);
  635. goto create_qp_exit3;
  636. }
  637. }
  638. if (is_srq) {
  639. my_qp->ib_srq.pd = &my_pd->ib_pd;
  640. my_qp->ib_srq.device = my_pd->ib_pd.device;
  641. my_qp->ib_srq.srq_context = init_attr->qp_context;
  642. my_qp->ib_srq.event_handler = init_attr->event_handler;
  643. } else {
  644. my_qp->ib_qp.qp_num = ib_qp_num;
  645. my_qp->ib_qp.pd = &my_pd->ib_pd;
  646. my_qp->ib_qp.device = my_pd->ib_pd.device;
  647. my_qp->ib_qp.recv_cq = init_attr->recv_cq;
  648. my_qp->ib_qp.send_cq = init_attr->send_cq;
  649. my_qp->ib_qp.qp_type = qp_type;
  650. my_qp->ib_qp.srq = init_attr->srq;
  651. my_qp->ib_qp.qp_context = init_attr->qp_context;
  652. my_qp->ib_qp.event_handler = init_attr->event_handler;
  653. }
  654. init_attr->cap.max_inline_data = 0; /* not supported yet */
  655. init_attr->cap.max_recv_sge = parms.rqueue.act_nr_sges;
  656. init_attr->cap.max_recv_wr = parms.rqueue.act_nr_wqes;
  657. init_attr->cap.max_send_sge = parms.squeue.act_nr_sges;
  658. init_attr->cap.max_send_wr = parms.squeue.act_nr_wqes;
  659. my_qp->init_attr = *init_attr;
  660. /* NOTE: define_apq0() not supported yet */
  661. if (qp_type == IB_QPT_GSI) {
  662. h_ret = ehca_define_sqp(shca, my_qp, init_attr);
  663. if (h_ret != H_SUCCESS) {
  664. ret = ehca2ib_return_code(h_ret);
  665. goto create_qp_exit4;
  666. }
  667. }
  668. if (my_qp->send_cq) {
  669. ret = ehca_cq_assign_qp(my_qp->send_cq, my_qp);
  670. if (ret) {
  671. ehca_err(pd->device,
  672. "Couldn't assign qp to send_cq ret=%i", ret);
  673. goto create_qp_exit4;
  674. }
  675. }
  676. /* copy queues, galpa data to user space */
  677. if (context && udata) {
  678. struct ehca_create_qp_resp resp;
  679. memset(&resp, 0, sizeof(resp));
  680. resp.qp_num = my_qp->real_qp_num;
  681. resp.token = my_qp->token;
  682. resp.qp_type = my_qp->qp_type;
  683. resp.ext_type = my_qp->ext_type;
  684. resp.qkey = my_qp->qkey;
  685. resp.real_qp_num = my_qp->real_qp_num;
  686. if (HAS_SQ(my_qp))
  687. queue2resp(&resp.ipz_squeue, &my_qp->ipz_squeue);
  688. if (HAS_RQ(my_qp))
  689. queue2resp(&resp.ipz_rqueue, &my_qp->ipz_rqueue);
  690. resp.fw_handle_ofs = (u32)
  691. (my_qp->galpas.user.fw_handle & (PAGE_SIZE - 1));
  692. if (ib_copy_to_udata(udata, &resp, sizeof resp)) {
  693. ehca_err(pd->device, "Copy to udata failed");
  694. ret = -EINVAL;
  695. goto create_qp_exit4;
  696. }
  697. }
  698. return my_qp;
  699. create_qp_exit4:
  700. if (HAS_RQ(my_qp))
  701. ipz_queue_dtor(my_pd, &my_qp->ipz_rqueue);
  702. create_qp_exit3:
  703. if (HAS_SQ(my_qp))
  704. ipz_queue_dtor(my_pd, &my_qp->ipz_squeue);
  705. create_qp_exit2:
  706. hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
  707. create_qp_exit1:
  708. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  709. idr_remove(&ehca_qp_idr, my_qp->token);
  710. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  711. create_qp_exit0:
  712. kmem_cache_free(qp_cache, my_qp);
  713. return ERR_PTR(ret);
  714. }
  715. struct ib_qp *ehca_create_qp(struct ib_pd *pd,
  716. struct ib_qp_init_attr *qp_init_attr,
  717. struct ib_udata *udata)
  718. {
  719. struct ehca_qp *ret;
  720. ret = internal_create_qp(pd, qp_init_attr, NULL, udata, 0);
  721. return IS_ERR(ret) ? (struct ib_qp *)ret : &ret->ib_qp;
  722. }
  723. static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
  724. struct ib_uobject *uobject);
  725. struct ib_srq *ehca_create_srq(struct ib_pd *pd,
  726. struct ib_srq_init_attr *srq_init_attr,
  727. struct ib_udata *udata)
  728. {
  729. struct ib_qp_init_attr qp_init_attr;
  730. struct ehca_qp *my_qp;
  731. struct ib_srq *ret;
  732. struct ehca_shca *shca = container_of(pd->device, struct ehca_shca,
  733. ib_device);
  734. struct hcp_modify_qp_control_block *mqpcb;
  735. u64 hret, update_mask;
  736. /* For common attributes, internal_create_qp() takes its info
  737. * out of qp_init_attr, so copy all common attrs there.
  738. */
  739. memset(&qp_init_attr, 0, sizeof(qp_init_attr));
  740. qp_init_attr.event_handler = srq_init_attr->event_handler;
  741. qp_init_attr.qp_context = srq_init_attr->srq_context;
  742. qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
  743. qp_init_attr.qp_type = IB_QPT_RC;
  744. qp_init_attr.cap.max_recv_wr = srq_init_attr->attr.max_wr;
  745. qp_init_attr.cap.max_recv_sge = srq_init_attr->attr.max_sge;
  746. my_qp = internal_create_qp(pd, &qp_init_attr, srq_init_attr, udata, 1);
  747. if (IS_ERR(my_qp))
  748. return (struct ib_srq *)my_qp;
  749. /* copy back return values */
  750. srq_init_attr->attr.max_wr = qp_init_attr.cap.max_recv_wr;
  751. srq_init_attr->attr.max_sge = qp_init_attr.cap.max_recv_sge;
  752. /* drive SRQ into RTR state */
  753. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  754. if (!mqpcb) {
  755. ehca_err(pd->device, "Could not get zeroed page for mqpcb "
  756. "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
  757. ret = ERR_PTR(-ENOMEM);
  758. goto create_srq1;
  759. }
  760. mqpcb->qp_state = EHCA_QPS_INIT;
  761. mqpcb->prim_phys_port = 1;
  762. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  763. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  764. my_qp->ipz_qp_handle,
  765. &my_qp->pf,
  766. update_mask,
  767. mqpcb, my_qp->galpas.kernel);
  768. if (hret != H_SUCCESS) {
  769. ehca_err(pd->device, "Could not modify SRQ to INIT"
  770. "ehca_qp=%p qp_num=%x h_ret=%li",
  771. my_qp, my_qp->real_qp_num, hret);
  772. goto create_srq2;
  773. }
  774. mqpcb->qp_enable = 1;
  775. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
  776. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  777. my_qp->ipz_qp_handle,
  778. &my_qp->pf,
  779. update_mask,
  780. mqpcb, my_qp->galpas.kernel);
  781. if (hret != H_SUCCESS) {
  782. ehca_err(pd->device, "Could not enable SRQ"
  783. "ehca_qp=%p qp_num=%x h_ret=%li",
  784. my_qp, my_qp->real_qp_num, hret);
  785. goto create_srq2;
  786. }
  787. mqpcb->qp_state = EHCA_QPS_RTR;
  788. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  789. hret = hipz_h_modify_qp(shca->ipz_hca_handle,
  790. my_qp->ipz_qp_handle,
  791. &my_qp->pf,
  792. update_mask,
  793. mqpcb, my_qp->galpas.kernel);
  794. if (hret != H_SUCCESS) {
  795. ehca_err(pd->device, "Could not modify SRQ to RTR"
  796. "ehca_qp=%p qp_num=%x h_ret=%li",
  797. my_qp, my_qp->real_qp_num, hret);
  798. goto create_srq2;
  799. }
  800. ehca_free_fw_ctrlblock(mqpcb);
  801. return &my_qp->ib_srq;
  802. create_srq2:
  803. ret = ERR_PTR(ehca2ib_return_code(hret));
  804. ehca_free_fw_ctrlblock(mqpcb);
  805. create_srq1:
  806. internal_destroy_qp(pd->device, my_qp, my_qp->ib_srq.uobject);
  807. return ret;
  808. }
  809. /*
  810. * prepare_sqe_rts called by internal_modify_qp() at trans sqe -> rts
  811. * set purge bit of bad wqe and subsequent wqes to avoid reentering sqe
  812. * returns total number of bad wqes in bad_wqe_cnt
  813. */
  814. static int prepare_sqe_rts(struct ehca_qp *my_qp, struct ehca_shca *shca,
  815. int *bad_wqe_cnt)
  816. {
  817. u64 h_ret;
  818. struct ipz_queue *squeue;
  819. void *bad_send_wqe_p, *bad_send_wqe_v;
  820. u64 q_ofs;
  821. struct ehca_wqe *wqe;
  822. int qp_num = my_qp->ib_qp.qp_num;
  823. /* get send wqe pointer */
  824. h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle,
  825. my_qp->ipz_qp_handle, &my_qp->pf,
  826. &bad_send_wqe_p, NULL, 2);
  827. if (h_ret != H_SUCCESS) {
  828. ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed"
  829. " ehca_qp=%p qp_num=%x h_ret=%li",
  830. my_qp, qp_num, h_ret);
  831. return ehca2ib_return_code(h_ret);
  832. }
  833. bad_send_wqe_p = (void *)((u64)bad_send_wqe_p & (~(1L << 63)));
  834. ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p",
  835. qp_num, bad_send_wqe_p);
  836. /* convert wqe pointer to vadr */
  837. bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p);
  838. if (ehca_debug_level)
  839. ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num);
  840. squeue = &my_qp->ipz_squeue;
  841. if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) {
  842. ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x"
  843. " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p);
  844. return -EFAULT;
  845. }
  846. /* loop sets wqe's purge bit */
  847. wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs);
  848. *bad_wqe_cnt = 0;
  849. while (wqe->optype != 0xff && wqe->wqef != 0xff) {
  850. if (ehca_debug_level)
  851. ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num);
  852. wqe->nr_of_data_seg = 0; /* suppress data access */
  853. wqe->wqef = WQEF_PURGE; /* WQE to be purged */
  854. q_ofs = ipz_queue_advance_offset(squeue, q_ofs);
  855. wqe = (struct ehca_wqe *)ipz_qeit_calc(squeue, q_ofs);
  856. *bad_wqe_cnt = (*bad_wqe_cnt)+1;
  857. }
  858. /*
  859. * bad wqe will be reprocessed and ignored when pol_cq() is called,
  860. * i.e. nr of wqes with flush error status is one less
  861. */
  862. ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x",
  863. qp_num, (*bad_wqe_cnt)-1);
  864. wqe->wqef = 0;
  865. return 0;
  866. }
  867. /*
  868. * internal_modify_qp with circumvention to handle aqp0 properly
  869. * smi_reset2init indicates if this is an internal reset-to-init-call for
  870. * smi. This flag must always be zero if called from ehca_modify_qp()!
  871. * This internal func was intorduced to avoid recursion of ehca_modify_qp()!
  872. */
  873. static int internal_modify_qp(struct ib_qp *ibqp,
  874. struct ib_qp_attr *attr,
  875. int attr_mask, int smi_reset2init)
  876. {
  877. enum ib_qp_state qp_cur_state, qp_new_state;
  878. int cnt, qp_attr_idx, ret = 0;
  879. enum ib_qp_statetrans statetrans;
  880. struct hcp_modify_qp_control_block *mqpcb;
  881. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  882. struct ehca_shca *shca =
  883. container_of(ibqp->pd->device, struct ehca_shca, ib_device);
  884. u64 update_mask;
  885. u64 h_ret;
  886. int bad_wqe_cnt = 0;
  887. int squeue_locked = 0;
  888. unsigned long flags = 0;
  889. /* do query_qp to obtain current attr values */
  890. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  891. if (!mqpcb) {
  892. ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
  893. "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
  894. return -ENOMEM;
  895. }
  896. h_ret = hipz_h_query_qp(shca->ipz_hca_handle,
  897. my_qp->ipz_qp_handle,
  898. &my_qp->pf,
  899. mqpcb, my_qp->galpas.kernel);
  900. if (h_ret != H_SUCCESS) {
  901. ehca_err(ibqp->device, "hipz_h_query_qp() failed "
  902. "ehca_qp=%p qp_num=%x h_ret=%li",
  903. my_qp, ibqp->qp_num, h_ret);
  904. ret = ehca2ib_return_code(h_ret);
  905. goto modify_qp_exit1;
  906. }
  907. qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state);
  908. if (qp_cur_state == -EINVAL) { /* invalid qp state */
  909. ret = -EINVAL;
  910. ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x "
  911. "ehca_qp=%p qp_num=%x",
  912. mqpcb->qp_state, my_qp, ibqp->qp_num);
  913. goto modify_qp_exit1;
  914. }
  915. /*
  916. * circumvention to set aqp0 initial state to init
  917. * as expected by IB spec
  918. */
  919. if (smi_reset2init == 0 &&
  920. ibqp->qp_type == IB_QPT_SMI &&
  921. qp_cur_state == IB_QPS_RESET &&
  922. (attr_mask & IB_QP_STATE) &&
  923. attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */
  924. struct ib_qp_attr smiqp_attr = {
  925. .qp_state = IB_QPS_INIT,
  926. .port_num = my_qp->init_attr.port_num,
  927. .pkey_index = 0,
  928. .qkey = 0
  929. };
  930. int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT |
  931. IB_QP_PKEY_INDEX | IB_QP_QKEY;
  932. int smirc = internal_modify_qp(
  933. ibqp, &smiqp_attr, smiqp_attr_mask, 1);
  934. if (smirc) {
  935. ehca_err(ibqp->device, "SMI RESET -> INIT failed. "
  936. "ehca_modify_qp() rc=%i", smirc);
  937. ret = H_PARAMETER;
  938. goto modify_qp_exit1;
  939. }
  940. qp_cur_state = IB_QPS_INIT;
  941. ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded");
  942. }
  943. /* is transmitted current state equal to "real" current state */
  944. if ((attr_mask & IB_QP_CUR_STATE) &&
  945. qp_cur_state != attr->cur_qp_state) {
  946. ret = -EINVAL;
  947. ehca_err(ibqp->device,
  948. "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>"
  949. " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x",
  950. attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num);
  951. goto modify_qp_exit1;
  952. }
  953. ehca_dbg(ibqp->device, "ehca_qp=%p qp_num=%x current qp_state=%x "
  954. "new qp_state=%x attribute_mask=%x",
  955. my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask);
  956. qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state;
  957. if (!smi_reset2init &&
  958. !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type,
  959. attr_mask)) {
  960. ret = -EINVAL;
  961. ehca_err(ibqp->device,
  962. "Invalid qp transition new_state=%x cur_state=%x "
  963. "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state,
  964. qp_cur_state, my_qp, ibqp->qp_num, attr_mask);
  965. goto modify_qp_exit1;
  966. }
  967. mqpcb->qp_state = ib2ehca_qp_state(qp_new_state);
  968. if (mqpcb->qp_state)
  969. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  970. else {
  971. ret = -EINVAL;
  972. ehca_err(ibqp->device, "Invalid new qp state=%x "
  973. "ehca_qp=%p qp_num=%x",
  974. qp_new_state, my_qp, ibqp->qp_num);
  975. goto modify_qp_exit1;
  976. }
  977. /* retrieve state transition struct to get req and opt attrs */
  978. statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state);
  979. if (statetrans < 0) {
  980. ret = -EINVAL;
  981. ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x "
  982. "new_qp_state=%x State_xsition=%x ehca_qp=%p "
  983. "qp_num=%x", qp_cur_state, qp_new_state,
  984. statetrans, my_qp, ibqp->qp_num);
  985. goto modify_qp_exit1;
  986. }
  987. qp_attr_idx = ib2ehcaqptype(ibqp->qp_type);
  988. if (qp_attr_idx < 0) {
  989. ret = qp_attr_idx;
  990. ehca_err(ibqp->device,
  991. "Invalid QP type=%x ehca_qp=%p qp_num=%x",
  992. ibqp->qp_type, my_qp, ibqp->qp_num);
  993. goto modify_qp_exit1;
  994. }
  995. ehca_dbg(ibqp->device,
  996. "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x",
  997. my_qp, ibqp->qp_num, statetrans);
  998. /* eHCA2 rev2 and higher require the SEND_GRH_FLAG to be set
  999. * in non-LL UD QPs.
  1000. */
  1001. if ((my_qp->qp_type == IB_QPT_UD) &&
  1002. (my_qp->ext_type != EQPT_LLQP) &&
  1003. (statetrans == IB_QPST_INIT2RTR) &&
  1004. (shca->hw_level >= 0x22)) {
  1005. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
  1006. mqpcb->send_grh_flag = 1;
  1007. }
  1008. /* sqe -> rts: set purge bit of bad wqe before actual trans */
  1009. if ((my_qp->qp_type == IB_QPT_UD ||
  1010. my_qp->qp_type == IB_QPT_GSI ||
  1011. my_qp->qp_type == IB_QPT_SMI) &&
  1012. statetrans == IB_QPST_SQE2RTS) {
  1013. /* mark next free wqe if kernel */
  1014. if (!ibqp->uobject) {
  1015. struct ehca_wqe *wqe;
  1016. /* lock send queue */
  1017. spin_lock_irqsave(&my_qp->spinlock_s, flags);
  1018. squeue_locked = 1;
  1019. /* mark next free wqe */
  1020. wqe = (struct ehca_wqe *)
  1021. ipz_qeit_get(&my_qp->ipz_squeue);
  1022. wqe->optype = wqe->wqef = 0xff;
  1023. ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p",
  1024. ibqp->qp_num, wqe);
  1025. }
  1026. ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt);
  1027. if (ret) {
  1028. ehca_err(ibqp->device, "prepare_sqe_rts() failed "
  1029. "ehca_qp=%p qp_num=%x ret=%i",
  1030. my_qp, ibqp->qp_num, ret);
  1031. goto modify_qp_exit2;
  1032. }
  1033. }
  1034. /*
  1035. * enable RDMA_Atomic_Control if reset->init und reliable con
  1036. * this is necessary since gen2 does not provide that flag,
  1037. * but pHyp requires it
  1038. */
  1039. if (statetrans == IB_QPST_RESET2INIT &&
  1040. (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) {
  1041. mqpcb->rdma_atomic_ctrl = 3;
  1042. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1);
  1043. }
  1044. /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */
  1045. if (statetrans == IB_QPST_INIT2RTR &&
  1046. (ibqp->qp_type == IB_QPT_UC) &&
  1047. !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) {
  1048. mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */
  1049. update_mask |=
  1050. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  1051. }
  1052. if (attr_mask & IB_QP_PKEY_INDEX) {
  1053. if (attr->pkey_index >= 16) {
  1054. ret = -EINVAL;
  1055. ehca_err(ibqp->device, "Invalid pkey_index=%x. "
  1056. "ehca_qp=%p qp_num=%x max_pkey_index=f",
  1057. attr->pkey_index, my_qp, ibqp->qp_num);
  1058. goto modify_qp_exit2;
  1059. }
  1060. mqpcb->prim_p_key_idx = attr->pkey_index;
  1061. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1);
  1062. }
  1063. if (attr_mask & IB_QP_PORT) {
  1064. if (attr->port_num < 1 || attr->port_num > shca->num_ports) {
  1065. ret = -EINVAL;
  1066. ehca_err(ibqp->device, "Invalid port=%x. "
  1067. "ehca_qp=%p qp_num=%x num_ports=%x",
  1068. attr->port_num, my_qp, ibqp->qp_num,
  1069. shca->num_ports);
  1070. goto modify_qp_exit2;
  1071. }
  1072. mqpcb->prim_phys_port = attr->port_num;
  1073. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1);
  1074. }
  1075. if (attr_mask & IB_QP_QKEY) {
  1076. mqpcb->qkey = attr->qkey;
  1077. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1);
  1078. }
  1079. if (attr_mask & IB_QP_AV) {
  1080. mqpcb->dlid = attr->ah_attr.dlid;
  1081. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1);
  1082. mqpcb->source_path_bits = attr->ah_attr.src_path_bits;
  1083. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1);
  1084. mqpcb->service_level = attr->ah_attr.sl;
  1085. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
  1086. if (ehca_calc_ipd(shca, my_qp->init_attr.port_num,
  1087. attr->ah_attr.static_rate,
  1088. &mqpcb->max_static_rate)) {
  1089. ret = -EINVAL;
  1090. goto modify_qp_exit2;
  1091. }
  1092. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
  1093. /*
  1094. * Always supply the GRH flag, even if it's zero, to give the
  1095. * hypervisor a clear "yes" or "no" instead of a "perhaps"
  1096. */
  1097. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
  1098. /*
  1099. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  1100. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  1101. */
  1102. if (attr->ah_attr.ah_flags == IB_AH_GRH) {
  1103. mqpcb->send_grh_flag = 1;
  1104. mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
  1105. update_mask |=
  1106. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
  1107. for (cnt = 0; cnt < 16; cnt++)
  1108. mqpcb->dest_gid.byte[cnt] =
  1109. attr->ah_attr.grh.dgid.raw[cnt];
  1110. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1);
  1111. mqpcb->flow_label = attr->ah_attr.grh.flow_label;
  1112. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1);
  1113. mqpcb->hop_limit = attr->ah_attr.grh.hop_limit;
  1114. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1);
  1115. mqpcb->traffic_class = attr->ah_attr.grh.traffic_class;
  1116. update_mask |=
  1117. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1);
  1118. }
  1119. }
  1120. if (attr_mask & IB_QP_PATH_MTU) {
  1121. mqpcb->path_mtu = attr->path_mtu;
  1122. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1);
  1123. }
  1124. if (attr_mask & IB_QP_TIMEOUT) {
  1125. mqpcb->timeout = attr->timeout;
  1126. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1);
  1127. }
  1128. if (attr_mask & IB_QP_RETRY_CNT) {
  1129. mqpcb->retry_count = attr->retry_cnt;
  1130. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1);
  1131. }
  1132. if (attr_mask & IB_QP_RNR_RETRY) {
  1133. mqpcb->rnr_retry_count = attr->rnr_retry;
  1134. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1);
  1135. }
  1136. if (attr_mask & IB_QP_RQ_PSN) {
  1137. mqpcb->receive_psn = attr->rq_psn;
  1138. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1);
  1139. }
  1140. if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
  1141. mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ?
  1142. attr->max_dest_rd_atomic : 2;
  1143. update_mask |=
  1144. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  1145. }
  1146. if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
  1147. mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ?
  1148. attr->max_rd_atomic : 2;
  1149. update_mask |=
  1150. EHCA_BMASK_SET
  1151. (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1);
  1152. }
  1153. if (attr_mask & IB_QP_ALT_PATH) {
  1154. if (attr->alt_port_num < 1
  1155. || attr->alt_port_num > shca->num_ports) {
  1156. ret = -EINVAL;
  1157. ehca_err(ibqp->device, "Invalid alt_port=%x. "
  1158. "ehca_qp=%p qp_num=%x num_ports=%x",
  1159. attr->alt_port_num, my_qp, ibqp->qp_num,
  1160. shca->num_ports);
  1161. goto modify_qp_exit2;
  1162. }
  1163. mqpcb->alt_phys_port = attr->alt_port_num;
  1164. if (attr->alt_pkey_index >= 16) {
  1165. ret = -EINVAL;
  1166. ehca_err(ibqp->device, "Invalid alt_pkey_index=%x. "
  1167. "ehca_qp=%p qp_num=%x max_pkey_index=f",
  1168. attr->pkey_index, my_qp, ibqp->qp_num);
  1169. goto modify_qp_exit2;
  1170. }
  1171. mqpcb->alt_p_key_idx = attr->alt_pkey_index;
  1172. mqpcb->timeout_al = attr->alt_timeout;
  1173. mqpcb->dlid_al = attr->alt_ah_attr.dlid;
  1174. mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
  1175. mqpcb->service_level_al = attr->alt_ah_attr.sl;
  1176. if (ehca_calc_ipd(shca, my_qp->init_attr.port_num,
  1177. attr->alt_ah_attr.static_rate,
  1178. &mqpcb->max_static_rate_al)) {
  1179. ret = -EINVAL;
  1180. goto modify_qp_exit2;
  1181. }
  1182. /* OpenIB doesn't support alternate retry counts - copy them */
  1183. mqpcb->retry_count_al = mqpcb->retry_count;
  1184. mqpcb->rnr_retry_count_al = mqpcb->rnr_retry_count;
  1185. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_ALT_PHYS_PORT, 1)
  1186. | EHCA_BMASK_SET(MQPCB_MASK_ALT_P_KEY_IDX, 1)
  1187. | EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT_AL, 1)
  1188. | EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1)
  1189. | EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1)
  1190. | EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1)
  1191. | EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1)
  1192. | EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT_AL, 1)
  1193. | EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT_AL, 1);
  1194. /*
  1195. * Always supply the GRH flag, even if it's zero, to give the
  1196. * hypervisor a clear "yes" or "no" instead of a "perhaps"
  1197. */
  1198. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1);
  1199. /*
  1200. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  1201. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  1202. */
  1203. if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) {
  1204. mqpcb->send_grh_flag_al = 1;
  1205. for (cnt = 0; cnt < 16; cnt++)
  1206. mqpcb->dest_gid_al.byte[cnt] =
  1207. attr->alt_ah_attr.grh.dgid.raw[cnt];
  1208. mqpcb->source_gid_idx_al =
  1209. attr->alt_ah_attr.grh.sgid_index;
  1210. mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label;
  1211. mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit;
  1212. mqpcb->traffic_class_al =
  1213. attr->alt_ah_attr.grh.traffic_class;
  1214. update_mask |=
  1215. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1)
  1216. | EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1)
  1217. | EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1)
  1218. | EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1) |
  1219. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1);
  1220. }
  1221. }
  1222. if (attr_mask & IB_QP_MIN_RNR_TIMER) {
  1223. mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer;
  1224. update_mask |=
  1225. EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1);
  1226. }
  1227. if (attr_mask & IB_QP_SQ_PSN) {
  1228. mqpcb->send_psn = attr->sq_psn;
  1229. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1);
  1230. }
  1231. if (attr_mask & IB_QP_DEST_QPN) {
  1232. mqpcb->dest_qp_nr = attr->dest_qp_num;
  1233. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1);
  1234. }
  1235. if (attr_mask & IB_QP_PATH_MIG_STATE) {
  1236. if (attr->path_mig_state != IB_MIG_REARM
  1237. && attr->path_mig_state != IB_MIG_MIGRATED) {
  1238. ret = -EINVAL;
  1239. ehca_err(ibqp->device, "Invalid mig_state=%x",
  1240. attr->path_mig_state);
  1241. goto modify_qp_exit2;
  1242. }
  1243. mqpcb->path_migration_state = attr->path_mig_state + 1;
  1244. update_mask |=
  1245. EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
  1246. }
  1247. if (attr_mask & IB_QP_CAP) {
  1248. mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1;
  1249. update_mask |=
  1250. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1);
  1251. mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1;
  1252. update_mask |=
  1253. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1);
  1254. /* no support for max_send/recv_sge yet */
  1255. }
  1256. if (ehca_debug_level)
  1257. ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num);
  1258. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1259. my_qp->ipz_qp_handle,
  1260. &my_qp->pf,
  1261. update_mask,
  1262. mqpcb, my_qp->galpas.kernel);
  1263. if (h_ret != H_SUCCESS) {
  1264. ret = ehca2ib_return_code(h_ret);
  1265. ehca_err(ibqp->device, "hipz_h_modify_qp() failed h_ret=%li "
  1266. "ehca_qp=%p qp_num=%x", h_ret, my_qp, ibqp->qp_num);
  1267. goto modify_qp_exit2;
  1268. }
  1269. if ((my_qp->qp_type == IB_QPT_UD ||
  1270. my_qp->qp_type == IB_QPT_GSI ||
  1271. my_qp->qp_type == IB_QPT_SMI) &&
  1272. statetrans == IB_QPST_SQE2RTS) {
  1273. /* doorbell to reprocessing wqes */
  1274. iosync(); /* serialize GAL register access */
  1275. hipz_update_sqa(my_qp, bad_wqe_cnt-1);
  1276. ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt);
  1277. }
  1278. if (statetrans == IB_QPST_RESET2INIT ||
  1279. statetrans == IB_QPST_INIT2INIT) {
  1280. mqpcb->qp_enable = 1;
  1281. mqpcb->qp_state = EHCA_QPS_INIT;
  1282. update_mask = 0;
  1283. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
  1284. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1285. my_qp->ipz_qp_handle,
  1286. &my_qp->pf,
  1287. update_mask,
  1288. mqpcb,
  1289. my_qp->galpas.kernel);
  1290. if (h_ret != H_SUCCESS) {
  1291. ret = ehca2ib_return_code(h_ret);
  1292. ehca_err(ibqp->device, "ENABLE in context of "
  1293. "RESET_2_INIT failed! Maybe you didn't get "
  1294. "a LID h_ret=%li ehca_qp=%p qp_num=%x",
  1295. h_ret, my_qp, ibqp->qp_num);
  1296. goto modify_qp_exit2;
  1297. }
  1298. }
  1299. if (statetrans == IB_QPST_ANY2RESET) {
  1300. ipz_qeit_reset(&my_qp->ipz_rqueue);
  1301. ipz_qeit_reset(&my_qp->ipz_squeue);
  1302. }
  1303. if (attr_mask & IB_QP_QKEY)
  1304. my_qp->qkey = attr->qkey;
  1305. modify_qp_exit2:
  1306. if (squeue_locked) { /* this means: sqe -> rts */
  1307. spin_unlock_irqrestore(&my_qp->spinlock_s, flags);
  1308. my_qp->sqerr_purgeflag = 1;
  1309. }
  1310. modify_qp_exit1:
  1311. ehca_free_fw_ctrlblock(mqpcb);
  1312. return ret;
  1313. }
  1314. int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
  1315. struct ib_udata *udata)
  1316. {
  1317. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  1318. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1319. ib_pd);
  1320. u32 cur_pid = current->tgid;
  1321. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1322. my_pd->ownpid != cur_pid) {
  1323. ehca_err(ibqp->pd->device, "Invalid caller pid=%x ownpid=%x",
  1324. cur_pid, my_pd->ownpid);
  1325. return -EINVAL;
  1326. }
  1327. return internal_modify_qp(ibqp, attr, attr_mask, 0);
  1328. }
  1329. int ehca_query_qp(struct ib_qp *qp,
  1330. struct ib_qp_attr *qp_attr,
  1331. int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr)
  1332. {
  1333. struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
  1334. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1335. ib_pd);
  1336. struct ehca_shca *shca = container_of(qp->device, struct ehca_shca,
  1337. ib_device);
  1338. struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
  1339. struct hcp_modify_qp_control_block *qpcb;
  1340. u32 cur_pid = current->tgid;
  1341. int cnt, ret = 0;
  1342. u64 h_ret;
  1343. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1344. my_pd->ownpid != cur_pid) {
  1345. ehca_err(qp->device, "Invalid caller pid=%x ownpid=%x",
  1346. cur_pid, my_pd->ownpid);
  1347. return -EINVAL;
  1348. }
  1349. if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) {
  1350. ehca_err(qp->device, "Invalid attribute mask "
  1351. "ehca_qp=%p qp_num=%x qp_attr_mask=%x ",
  1352. my_qp, qp->qp_num, qp_attr_mask);
  1353. return -EINVAL;
  1354. }
  1355. qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1356. if (!qpcb) {
  1357. ehca_err(qp->device, "Out of memory for qpcb "
  1358. "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
  1359. return -ENOMEM;
  1360. }
  1361. h_ret = hipz_h_query_qp(adapter_handle,
  1362. my_qp->ipz_qp_handle,
  1363. &my_qp->pf,
  1364. qpcb, my_qp->galpas.kernel);
  1365. if (h_ret != H_SUCCESS) {
  1366. ret = ehca2ib_return_code(h_ret);
  1367. ehca_err(qp->device, "hipz_h_query_qp() failed "
  1368. "ehca_qp=%p qp_num=%x h_ret=%li",
  1369. my_qp, qp->qp_num, h_ret);
  1370. goto query_qp_exit1;
  1371. }
  1372. qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state);
  1373. qp_attr->qp_state = qp_attr->cur_qp_state;
  1374. if (qp_attr->cur_qp_state == -EINVAL) {
  1375. ret = -EINVAL;
  1376. ehca_err(qp->device, "Got invalid ehca_qp_state=%x "
  1377. "ehca_qp=%p qp_num=%x",
  1378. qpcb->qp_state, my_qp, qp->qp_num);
  1379. goto query_qp_exit1;
  1380. }
  1381. if (qp_attr->qp_state == IB_QPS_SQD)
  1382. qp_attr->sq_draining = 1;
  1383. qp_attr->qkey = qpcb->qkey;
  1384. qp_attr->path_mtu = qpcb->path_mtu;
  1385. qp_attr->path_mig_state = qpcb->path_migration_state - 1;
  1386. qp_attr->rq_psn = qpcb->receive_psn;
  1387. qp_attr->sq_psn = qpcb->send_psn;
  1388. qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field;
  1389. qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1;
  1390. qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1;
  1391. /* UD_AV CIRCUMVENTION */
  1392. if (my_qp->qp_type == IB_QPT_UD) {
  1393. qp_attr->cap.max_send_sge =
  1394. qpcb->actual_nr_sges_in_sq_wqe - 2;
  1395. qp_attr->cap.max_recv_sge =
  1396. qpcb->actual_nr_sges_in_rq_wqe - 2;
  1397. } else {
  1398. qp_attr->cap.max_send_sge =
  1399. qpcb->actual_nr_sges_in_sq_wqe;
  1400. qp_attr->cap.max_recv_sge =
  1401. qpcb->actual_nr_sges_in_rq_wqe;
  1402. }
  1403. qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size;
  1404. qp_attr->dest_qp_num = qpcb->dest_qp_nr;
  1405. qp_attr->pkey_index =
  1406. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx);
  1407. qp_attr->port_num =
  1408. EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port);
  1409. qp_attr->timeout = qpcb->timeout;
  1410. qp_attr->retry_cnt = qpcb->retry_count;
  1411. qp_attr->rnr_retry = qpcb->rnr_retry_count;
  1412. qp_attr->alt_pkey_index =
  1413. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx);
  1414. qp_attr->alt_port_num = qpcb->alt_phys_port;
  1415. qp_attr->alt_timeout = qpcb->timeout_al;
  1416. qp_attr->max_dest_rd_atomic = qpcb->rdma_nr_atomic_resp_res;
  1417. qp_attr->max_rd_atomic = qpcb->rdma_atomic_outst_dest_qp;
  1418. /* primary av */
  1419. qp_attr->ah_attr.sl = qpcb->service_level;
  1420. if (qpcb->send_grh_flag) {
  1421. qp_attr->ah_attr.ah_flags = IB_AH_GRH;
  1422. }
  1423. qp_attr->ah_attr.static_rate = qpcb->max_static_rate;
  1424. qp_attr->ah_attr.dlid = qpcb->dlid;
  1425. qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits;
  1426. qp_attr->ah_attr.port_num = qp_attr->port_num;
  1427. /* primary GRH */
  1428. qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class;
  1429. qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit;
  1430. qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx;
  1431. qp_attr->ah_attr.grh.flow_label = qpcb->flow_label;
  1432. for (cnt = 0; cnt < 16; cnt++)
  1433. qp_attr->ah_attr.grh.dgid.raw[cnt] =
  1434. qpcb->dest_gid.byte[cnt];
  1435. /* alternate AV */
  1436. qp_attr->alt_ah_attr.sl = qpcb->service_level_al;
  1437. if (qpcb->send_grh_flag_al) {
  1438. qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH;
  1439. }
  1440. qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al;
  1441. qp_attr->alt_ah_attr.dlid = qpcb->dlid_al;
  1442. qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al;
  1443. /* alternate GRH */
  1444. qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al;
  1445. qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al;
  1446. qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al;
  1447. qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al;
  1448. for (cnt = 0; cnt < 16; cnt++)
  1449. qp_attr->alt_ah_attr.grh.dgid.raw[cnt] =
  1450. qpcb->dest_gid_al.byte[cnt];
  1451. /* return init attributes given in ehca_create_qp */
  1452. if (qp_init_attr)
  1453. *qp_init_attr = my_qp->init_attr;
  1454. if (ehca_debug_level)
  1455. ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num);
  1456. query_qp_exit1:
  1457. ehca_free_fw_ctrlblock(qpcb);
  1458. return ret;
  1459. }
  1460. int ehca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  1461. enum ib_srq_attr_mask attr_mask, struct ib_udata *udata)
  1462. {
  1463. struct ehca_qp *my_qp =
  1464. container_of(ibsrq, struct ehca_qp, ib_srq);
  1465. struct ehca_pd *my_pd =
  1466. container_of(ibsrq->pd, struct ehca_pd, ib_pd);
  1467. struct ehca_shca *shca =
  1468. container_of(ibsrq->pd->device, struct ehca_shca, ib_device);
  1469. struct hcp_modify_qp_control_block *mqpcb;
  1470. u64 update_mask;
  1471. u64 h_ret;
  1472. int ret = 0;
  1473. u32 cur_pid = current->tgid;
  1474. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1475. my_pd->ownpid != cur_pid) {
  1476. ehca_err(ibsrq->pd->device, "Invalid caller pid=%x ownpid=%x",
  1477. cur_pid, my_pd->ownpid);
  1478. return -EINVAL;
  1479. }
  1480. mqpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1481. if (!mqpcb) {
  1482. ehca_err(ibsrq->device, "Could not get zeroed page for mqpcb "
  1483. "ehca_qp=%p qp_num=%x ", my_qp, my_qp->real_qp_num);
  1484. return -ENOMEM;
  1485. }
  1486. update_mask = 0;
  1487. if (attr_mask & IB_SRQ_LIMIT) {
  1488. attr_mask &= ~IB_SRQ_LIMIT;
  1489. update_mask |=
  1490. EHCA_BMASK_SET(MQPCB_MASK_CURR_SRQ_LIMIT, 1)
  1491. | EHCA_BMASK_SET(MQPCB_MASK_QP_AFF_ASYN_EV_LOG_REG, 1);
  1492. mqpcb->curr_srq_limit =
  1493. EHCA_BMASK_SET(MQPCB_CURR_SRQ_LIMIT, attr->srq_limit);
  1494. mqpcb->qp_aff_asyn_ev_log_reg =
  1495. EHCA_BMASK_SET(QPX_AAELOG_RESET_SRQ_LIMIT, 1);
  1496. }
  1497. /* by now, all bits in attr_mask should have been cleared */
  1498. if (attr_mask) {
  1499. ehca_err(ibsrq->device, "invalid attribute mask bits set "
  1500. "attr_mask=%x", attr_mask);
  1501. ret = -EINVAL;
  1502. goto modify_srq_exit0;
  1503. }
  1504. if (ehca_debug_level)
  1505. ehca_dmp(mqpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
  1506. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle, my_qp->ipz_qp_handle,
  1507. NULL, update_mask, mqpcb,
  1508. my_qp->galpas.kernel);
  1509. if (h_ret != H_SUCCESS) {
  1510. ret = ehca2ib_return_code(h_ret);
  1511. ehca_err(ibsrq->device, "hipz_h_modify_qp() failed h_ret=%li "
  1512. "ehca_qp=%p qp_num=%x",
  1513. h_ret, my_qp, my_qp->real_qp_num);
  1514. }
  1515. modify_srq_exit0:
  1516. ehca_free_fw_ctrlblock(mqpcb);
  1517. return ret;
  1518. }
  1519. int ehca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr)
  1520. {
  1521. struct ehca_qp *my_qp = container_of(srq, struct ehca_qp, ib_srq);
  1522. struct ehca_pd *my_pd = container_of(srq->pd, struct ehca_pd, ib_pd);
  1523. struct ehca_shca *shca = container_of(srq->device, struct ehca_shca,
  1524. ib_device);
  1525. struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
  1526. struct hcp_modify_qp_control_block *qpcb;
  1527. u32 cur_pid = current->tgid;
  1528. int ret = 0;
  1529. u64 h_ret;
  1530. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1531. my_pd->ownpid != cur_pid) {
  1532. ehca_err(srq->device, "Invalid caller pid=%x ownpid=%x",
  1533. cur_pid, my_pd->ownpid);
  1534. return -EINVAL;
  1535. }
  1536. qpcb = ehca_alloc_fw_ctrlblock(GFP_KERNEL);
  1537. if (!qpcb) {
  1538. ehca_err(srq->device, "Out of memory for qpcb "
  1539. "ehca_qp=%p qp_num=%x", my_qp, my_qp->real_qp_num);
  1540. return -ENOMEM;
  1541. }
  1542. h_ret = hipz_h_query_qp(adapter_handle, my_qp->ipz_qp_handle,
  1543. NULL, qpcb, my_qp->galpas.kernel);
  1544. if (h_ret != H_SUCCESS) {
  1545. ret = ehca2ib_return_code(h_ret);
  1546. ehca_err(srq->device, "hipz_h_query_qp() failed "
  1547. "ehca_qp=%p qp_num=%x h_ret=%li",
  1548. my_qp, my_qp->real_qp_num, h_ret);
  1549. goto query_srq_exit1;
  1550. }
  1551. srq_attr->max_wr = qpcb->max_nr_outst_recv_wr - 1;
  1552. srq_attr->max_sge = qpcb->actual_nr_sges_in_rq_wqe;
  1553. srq_attr->srq_limit = EHCA_BMASK_GET(
  1554. MQPCB_CURR_SRQ_LIMIT, qpcb->curr_srq_limit);
  1555. if (ehca_debug_level)
  1556. ehca_dmp(qpcb, 4*70, "qp_num=%x", my_qp->real_qp_num);
  1557. query_srq_exit1:
  1558. ehca_free_fw_ctrlblock(qpcb);
  1559. return ret;
  1560. }
  1561. static int internal_destroy_qp(struct ib_device *dev, struct ehca_qp *my_qp,
  1562. struct ib_uobject *uobject)
  1563. {
  1564. struct ehca_shca *shca = container_of(dev, struct ehca_shca, ib_device);
  1565. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1566. ib_pd);
  1567. u32 cur_pid = current->tgid;
  1568. u32 qp_num = my_qp->real_qp_num;
  1569. int ret;
  1570. u64 h_ret;
  1571. u8 port_num;
  1572. enum ib_qp_type qp_type;
  1573. unsigned long flags;
  1574. if (uobject) {
  1575. if (my_qp->mm_count_galpa ||
  1576. my_qp->mm_count_rqueue || my_qp->mm_count_squeue) {
  1577. ehca_err(dev, "Resources still referenced in "
  1578. "user space qp_num=%x", qp_num);
  1579. return -EINVAL;
  1580. }
  1581. if (my_pd->ownpid != cur_pid) {
  1582. ehca_err(dev, "Invalid caller pid=%x ownpid=%x",
  1583. cur_pid, my_pd->ownpid);
  1584. return -EINVAL;
  1585. }
  1586. }
  1587. if (my_qp->send_cq) {
  1588. ret = ehca_cq_unassign_qp(my_qp->send_cq, qp_num);
  1589. if (ret) {
  1590. ehca_err(dev, "Couldn't unassign qp from "
  1591. "send_cq ret=%i qp_num=%x cq_num=%x", ret,
  1592. qp_num, my_qp->send_cq->cq_number);
  1593. return ret;
  1594. }
  1595. }
  1596. write_lock_irqsave(&ehca_qp_idr_lock, flags);
  1597. idr_remove(&ehca_qp_idr, my_qp->token);
  1598. write_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  1599. h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
  1600. if (h_ret != H_SUCCESS) {
  1601. ehca_err(dev, "hipz_h_destroy_qp() failed h_ret=%li "
  1602. "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num);
  1603. return ehca2ib_return_code(h_ret);
  1604. }
  1605. port_num = my_qp->init_attr.port_num;
  1606. qp_type = my_qp->init_attr.qp_type;
  1607. /* no support for IB_QPT_SMI yet */
  1608. if (qp_type == IB_QPT_GSI) {
  1609. struct ib_event event;
  1610. ehca_info(dev, "device %s: port %x is inactive.",
  1611. shca->ib_device.name, port_num);
  1612. event.device = &shca->ib_device;
  1613. event.event = IB_EVENT_PORT_ERR;
  1614. event.element.port_num = port_num;
  1615. shca->sport[port_num - 1].port_state = IB_PORT_DOWN;
  1616. ib_dispatch_event(&event);
  1617. }
  1618. if (HAS_RQ(my_qp))
  1619. ipz_queue_dtor(my_pd, &my_qp->ipz_rqueue);
  1620. if (HAS_SQ(my_qp))
  1621. ipz_queue_dtor(my_pd, &my_qp->ipz_squeue);
  1622. kmem_cache_free(qp_cache, my_qp);
  1623. return 0;
  1624. }
  1625. int ehca_destroy_qp(struct ib_qp *qp)
  1626. {
  1627. return internal_destroy_qp(qp->device,
  1628. container_of(qp, struct ehca_qp, ib_qp),
  1629. qp->uobject);
  1630. }
  1631. int ehca_destroy_srq(struct ib_srq *srq)
  1632. {
  1633. return internal_destroy_qp(srq->device,
  1634. container_of(srq, struct ehca_qp, ib_srq),
  1635. srq->uobject);
  1636. }
  1637. int ehca_init_qp_cache(void)
  1638. {
  1639. qp_cache = kmem_cache_create("ehca_cache_qp",
  1640. sizeof(struct ehca_qp), 0,
  1641. SLAB_HWCACHE_ALIGN,
  1642. NULL);
  1643. if (!qp_cache)
  1644. return -ENOMEM;
  1645. return 0;
  1646. }
  1647. void ehca_cleanup_qp_cache(void)
  1648. {
  1649. if (qp_cache)
  1650. kmem_cache_destroy(qp_cache);
  1651. }