ehca_qp.c 50 KB

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