ehca_qp.c 43 KB

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