ehca_qp.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  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. u64 q_ofs;
  667. struct ehca_wqe *wqe;
  668. int qp_num = my_qp->ib_qp.qp_num;
  669. /* get send wqe pointer */
  670. h_ret = hipz_h_disable_and_get_wqe(shca->ipz_hca_handle,
  671. my_qp->ipz_qp_handle, &my_qp->pf,
  672. &bad_send_wqe_p, NULL, 2);
  673. if (h_ret != H_SUCCESS) {
  674. ehca_err(&shca->ib_device, "hipz_h_disable_and_get_wqe() failed"
  675. " ehca_qp=%p qp_num=%x h_ret=%lx",
  676. my_qp, qp_num, h_ret);
  677. return ehca2ib_return_code(h_ret);
  678. }
  679. bad_send_wqe_p = (void*)((u64)bad_send_wqe_p & (~(1L<<63)));
  680. ehca_dbg(&shca->ib_device, "qp_num=%x bad_send_wqe_p=%p",
  681. qp_num, bad_send_wqe_p);
  682. /* convert wqe pointer to vadr */
  683. bad_send_wqe_v = abs_to_virt((u64)bad_send_wqe_p);
  684. if (ehca_debug_level)
  685. ehca_dmp(bad_send_wqe_v, 32, "qp_num=%x bad_wqe", qp_num);
  686. squeue = &my_qp->ipz_squeue;
  687. if (ipz_queue_abs_to_offset(squeue, (u64)bad_send_wqe_p, &q_ofs)) {
  688. ehca_err(&shca->ib_device, "failed to get wqe offset qp_num=%x"
  689. " bad_send_wqe_p=%p", qp_num, bad_send_wqe_p);
  690. return -EFAULT;
  691. }
  692. /* loop sets wqe's purge bit */
  693. wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
  694. *bad_wqe_cnt = 0;
  695. while (wqe->optype != 0xff && wqe->wqef != 0xff) {
  696. if (ehca_debug_level)
  697. ehca_dmp(wqe, 32, "qp_num=%x wqe", qp_num);
  698. wqe->nr_of_data_seg = 0; /* suppress data access */
  699. wqe->wqef = WQEF_PURGE; /* WQE to be purged */
  700. q_ofs = ipz_queue_advance_offset(squeue, q_ofs);
  701. wqe = (struct ehca_wqe*)ipz_qeit_calc(squeue, q_ofs);
  702. *bad_wqe_cnt = (*bad_wqe_cnt)+1;
  703. }
  704. /*
  705. * bad wqe will be reprocessed and ignored when pol_cq() is called,
  706. * i.e. nr of wqes with flush error status is one less
  707. */
  708. ehca_dbg(&shca->ib_device, "qp_num=%x flusherr_wqe_cnt=%x",
  709. qp_num, (*bad_wqe_cnt)-1);
  710. wqe->wqef = 0;
  711. return 0;
  712. }
  713. /*
  714. * internal_modify_qp with circumvention to handle aqp0 properly
  715. * smi_reset2init indicates if this is an internal reset-to-init-call for
  716. * smi. This flag must always be zero if called from ehca_modify_qp()!
  717. * This internal func was intorduced to avoid recursion of ehca_modify_qp()!
  718. */
  719. static int internal_modify_qp(struct ib_qp *ibqp,
  720. struct ib_qp_attr *attr,
  721. int attr_mask, int smi_reset2init)
  722. {
  723. enum ib_qp_state qp_cur_state, qp_new_state;
  724. int cnt, qp_attr_idx, ret = 0;
  725. enum ib_qp_statetrans statetrans;
  726. struct hcp_modify_qp_control_block *mqpcb;
  727. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  728. struct ehca_shca *shca =
  729. container_of(ibqp->pd->device, struct ehca_shca, ib_device);
  730. u64 update_mask;
  731. u64 h_ret;
  732. int bad_wqe_cnt = 0;
  733. int squeue_locked = 0;
  734. unsigned long spl_flags = 0;
  735. /* do query_qp to obtain current attr values */
  736. mqpcb = ehca_alloc_fw_ctrlblock();
  737. if (!mqpcb) {
  738. ehca_err(ibqp->device, "Could not get zeroed page for mqpcb "
  739. "ehca_qp=%p qp_num=%x ", my_qp, ibqp->qp_num);
  740. return -ENOMEM;
  741. }
  742. h_ret = hipz_h_query_qp(shca->ipz_hca_handle,
  743. my_qp->ipz_qp_handle,
  744. &my_qp->pf,
  745. mqpcb, my_qp->galpas.kernel);
  746. if (h_ret != H_SUCCESS) {
  747. ehca_err(ibqp->device, "hipz_h_query_qp() failed "
  748. "ehca_qp=%p qp_num=%x h_ret=%lx",
  749. my_qp, ibqp->qp_num, h_ret);
  750. ret = ehca2ib_return_code(h_ret);
  751. goto modify_qp_exit1;
  752. }
  753. qp_cur_state = ehca2ib_qp_state(mqpcb->qp_state);
  754. if (qp_cur_state == -EINVAL) { /* invalid qp state */
  755. ret = -EINVAL;
  756. ehca_err(ibqp->device, "Invalid current ehca_qp_state=%x "
  757. "ehca_qp=%p qp_num=%x",
  758. mqpcb->qp_state, my_qp, ibqp->qp_num);
  759. goto modify_qp_exit1;
  760. }
  761. /*
  762. * circumvention to set aqp0 initial state to init
  763. * as expected by IB spec
  764. */
  765. if (smi_reset2init == 0 &&
  766. ibqp->qp_type == IB_QPT_SMI &&
  767. qp_cur_state == IB_QPS_RESET &&
  768. (attr_mask & IB_QP_STATE) &&
  769. attr->qp_state == IB_QPS_INIT) { /* RESET -> INIT */
  770. struct ib_qp_attr smiqp_attr = {
  771. .qp_state = IB_QPS_INIT,
  772. .port_num = my_qp->init_attr.port_num,
  773. .pkey_index = 0,
  774. .qkey = 0
  775. };
  776. int smiqp_attr_mask = IB_QP_STATE | IB_QP_PORT |
  777. IB_QP_PKEY_INDEX | IB_QP_QKEY;
  778. int smirc = internal_modify_qp(
  779. ibqp, &smiqp_attr, smiqp_attr_mask, 1);
  780. if (smirc) {
  781. ehca_err(ibqp->device, "SMI RESET -> INIT failed. "
  782. "ehca_modify_qp() rc=%x", smirc);
  783. ret = H_PARAMETER;
  784. goto modify_qp_exit1;
  785. }
  786. qp_cur_state = IB_QPS_INIT;
  787. ehca_dbg(ibqp->device, "SMI RESET -> INIT succeeded");
  788. }
  789. /* is transmitted current state equal to "real" current state */
  790. if ((attr_mask & IB_QP_CUR_STATE) &&
  791. qp_cur_state != attr->cur_qp_state) {
  792. ret = -EINVAL;
  793. ehca_err(ibqp->device,
  794. "Invalid IB_QP_CUR_STATE attr->curr_qp_state=%x <>"
  795. " actual cur_qp_state=%x. ehca_qp=%p qp_num=%x",
  796. attr->cur_qp_state, qp_cur_state, my_qp, ibqp->qp_num);
  797. goto modify_qp_exit1;
  798. }
  799. ehca_dbg(ibqp->device,"ehca_qp=%p qp_num=%x current qp_state=%x "
  800. "new qp_state=%x attribute_mask=%x",
  801. my_qp, ibqp->qp_num, qp_cur_state, attr->qp_state, attr_mask);
  802. qp_new_state = attr_mask & IB_QP_STATE ? attr->qp_state : qp_cur_state;
  803. if (!smi_reset2init &&
  804. !ib_modify_qp_is_ok(qp_cur_state, qp_new_state, ibqp->qp_type,
  805. attr_mask)) {
  806. ret = -EINVAL;
  807. ehca_err(ibqp->device,
  808. "Invalid qp transition new_state=%x cur_state=%x "
  809. "ehca_qp=%p qp_num=%x attr_mask=%x", qp_new_state,
  810. qp_cur_state, my_qp, ibqp->qp_num, attr_mask);
  811. goto modify_qp_exit1;
  812. }
  813. if ((mqpcb->qp_state = ib2ehca_qp_state(qp_new_state)))
  814. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_STATE, 1);
  815. else {
  816. ret = -EINVAL;
  817. ehca_err(ibqp->device, "Invalid new qp state=%x "
  818. "ehca_qp=%p qp_num=%x",
  819. qp_new_state, my_qp, ibqp->qp_num);
  820. goto modify_qp_exit1;
  821. }
  822. /* retrieve state transition struct to get req and opt attrs */
  823. statetrans = get_modqp_statetrans(qp_cur_state, qp_new_state);
  824. if (statetrans < 0) {
  825. ret = -EINVAL;
  826. ehca_err(ibqp->device, "<INVALID STATE CHANGE> qp_cur_state=%x "
  827. "new_qp_state=%x State_xsition=%x ehca_qp=%p "
  828. "qp_num=%x", qp_cur_state, qp_new_state,
  829. statetrans, my_qp, ibqp->qp_num);
  830. goto modify_qp_exit1;
  831. }
  832. qp_attr_idx = ib2ehcaqptype(ibqp->qp_type);
  833. if (qp_attr_idx < 0) {
  834. ret = qp_attr_idx;
  835. ehca_err(ibqp->device,
  836. "Invalid QP type=%x ehca_qp=%p qp_num=%x",
  837. ibqp->qp_type, my_qp, ibqp->qp_num);
  838. goto modify_qp_exit1;
  839. }
  840. ehca_dbg(ibqp->device,
  841. "ehca_qp=%p qp_num=%x <VALID STATE CHANGE> qp_state_xsit=%x",
  842. my_qp, ibqp->qp_num, statetrans);
  843. /* sqe -> rts: set purge bit of bad wqe before actual trans */
  844. if ((my_qp->qp_type == IB_QPT_UD ||
  845. my_qp->qp_type == IB_QPT_GSI ||
  846. my_qp->qp_type == IB_QPT_SMI) &&
  847. statetrans == IB_QPST_SQE2RTS) {
  848. /* mark next free wqe if kernel */
  849. if (my_qp->uspace_squeue == 0) {
  850. struct ehca_wqe *wqe;
  851. /* lock send queue */
  852. spin_lock_irqsave(&my_qp->spinlock_s, spl_flags);
  853. squeue_locked = 1;
  854. /* mark next free wqe */
  855. wqe = (struct ehca_wqe*)
  856. ipz_qeit_get(&my_qp->ipz_squeue);
  857. wqe->optype = wqe->wqef = 0xff;
  858. ehca_dbg(ibqp->device, "qp_num=%x next_free_wqe=%p",
  859. ibqp->qp_num, wqe);
  860. }
  861. ret = prepare_sqe_rts(my_qp, shca, &bad_wqe_cnt);
  862. if (ret) {
  863. ehca_err(ibqp->device, "prepare_sqe_rts() failed "
  864. "ehca_qp=%p qp_num=%x ret=%x",
  865. my_qp, ibqp->qp_num, ret);
  866. goto modify_qp_exit2;
  867. }
  868. }
  869. /*
  870. * enable RDMA_Atomic_Control if reset->init und reliable con
  871. * this is necessary since gen2 does not provide that flag,
  872. * but pHyp requires it
  873. */
  874. if (statetrans == IB_QPST_RESET2INIT &&
  875. (ibqp->qp_type == IB_QPT_RC || ibqp->qp_type == IB_QPT_UC)) {
  876. mqpcb->rdma_atomic_ctrl = 3;
  877. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RDMA_ATOMIC_CTRL, 1);
  878. }
  879. /* circ. pHyp requires #RDMA/Atomic Resp Res for UC INIT -> RTR */
  880. if (statetrans == IB_QPST_INIT2RTR &&
  881. (ibqp->qp_type == IB_QPT_UC) &&
  882. !(attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)) {
  883. mqpcb->rdma_nr_atomic_resp_res = 1; /* default to 1 */
  884. update_mask |=
  885. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  886. }
  887. if (attr_mask & IB_QP_PKEY_INDEX) {
  888. mqpcb->prim_p_key_idx = attr->pkey_index;
  889. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_P_KEY_IDX, 1);
  890. }
  891. if (attr_mask & IB_QP_PORT) {
  892. if (attr->port_num < 1 || attr->port_num > shca->num_ports) {
  893. ret = -EINVAL;
  894. ehca_err(ibqp->device, "Invalid port=%x. "
  895. "ehca_qp=%p qp_num=%x num_ports=%x",
  896. attr->port_num, my_qp, ibqp->qp_num,
  897. shca->num_ports);
  898. goto modify_qp_exit2;
  899. }
  900. mqpcb->prim_phys_port = attr->port_num;
  901. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PRIM_PHYS_PORT, 1);
  902. }
  903. if (attr_mask & IB_QP_QKEY) {
  904. mqpcb->qkey = attr->qkey;
  905. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_QKEY, 1);
  906. }
  907. if (attr_mask & IB_QP_AV) {
  908. int ah_mult = ib_rate_to_mult(attr->ah_attr.static_rate);
  909. int ehca_mult = ib_rate_to_mult(shca->sport[my_qp->
  910. init_attr.port_num].rate);
  911. mqpcb->dlid = attr->ah_attr.dlid;
  912. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID, 1);
  913. mqpcb->source_path_bits = attr->ah_attr.src_path_bits;
  914. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS, 1);
  915. mqpcb->service_level = attr->ah_attr.sl;
  916. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL, 1);
  917. if (ah_mult < ehca_mult)
  918. mqpcb->max_static_rate = (ah_mult > 0) ?
  919. ((ehca_mult - 1) / ah_mult) : 0;
  920. else
  921. mqpcb->max_static_rate = 0;
  922. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
  923. /*
  924. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  925. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  926. */
  927. if (attr->ah_attr.ah_flags == IB_AH_GRH) {
  928. mqpcb->send_grh_flag = 1 << 31;
  929. update_mask |=
  930. EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
  931. mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
  932. update_mask |=
  933. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
  934. for (cnt = 0; cnt < 16; cnt++)
  935. mqpcb->dest_gid.byte[cnt] =
  936. attr->ah_attr.grh.dgid.raw[cnt];
  937. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_GID, 1);
  938. mqpcb->flow_label = attr->ah_attr.grh.flow_label;
  939. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL, 1);
  940. mqpcb->hop_limit = attr->ah_attr.grh.hop_limit;
  941. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT, 1);
  942. mqpcb->traffic_class = attr->ah_attr.grh.traffic_class;
  943. update_mask |=
  944. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS, 1);
  945. }
  946. }
  947. if (attr_mask & IB_QP_PATH_MTU) {
  948. mqpcb->path_mtu = attr->path_mtu;
  949. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_PATH_MTU, 1);
  950. }
  951. if (attr_mask & IB_QP_TIMEOUT) {
  952. mqpcb->timeout = attr->timeout;
  953. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_TIMEOUT, 1);
  954. }
  955. if (attr_mask & IB_QP_RETRY_CNT) {
  956. mqpcb->retry_count = attr->retry_cnt;
  957. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RETRY_COUNT, 1);
  958. }
  959. if (attr_mask & IB_QP_RNR_RETRY) {
  960. mqpcb->rnr_retry_count = attr->rnr_retry;
  961. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RNR_RETRY_COUNT, 1);
  962. }
  963. if (attr_mask & IB_QP_RQ_PSN) {
  964. mqpcb->receive_psn = attr->rq_psn;
  965. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_RECEIVE_PSN, 1);
  966. }
  967. if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
  968. mqpcb->rdma_nr_atomic_resp_res = attr->max_dest_rd_atomic < 3 ?
  969. attr->max_dest_rd_atomic : 2;
  970. update_mask |=
  971. EHCA_BMASK_SET(MQPCB_MASK_RDMA_NR_ATOMIC_RESP_RES, 1);
  972. }
  973. if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
  974. mqpcb->rdma_atomic_outst_dest_qp = attr->max_rd_atomic < 3 ?
  975. attr->max_rd_atomic : 2;
  976. update_mask |=
  977. EHCA_BMASK_SET
  978. (MQPCB_MASK_RDMA_ATOMIC_OUTST_DEST_QP, 1);
  979. }
  980. if (attr_mask & IB_QP_ALT_PATH) {
  981. int ah_mult = ib_rate_to_mult(attr->alt_ah_attr.static_rate);
  982. int ehca_mult = ib_rate_to_mult(
  983. shca->sport[my_qp->init_attr.port_num].rate);
  984. mqpcb->dlid_al = attr->alt_ah_attr.dlid;
  985. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DLID_AL, 1);
  986. mqpcb->source_path_bits_al = attr->alt_ah_attr.src_path_bits;
  987. update_mask |=
  988. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_PATH_BITS_AL, 1);
  989. mqpcb->service_level_al = attr->alt_ah_attr.sl;
  990. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SERVICE_LEVEL_AL, 1);
  991. if (ah_mult < ehca_mult)
  992. mqpcb->max_static_rate = (ah_mult > 0) ?
  993. ((ehca_mult - 1) / ah_mult) : 0;
  994. else
  995. mqpcb->max_static_rate_al = 0;
  996. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE_AL, 1);
  997. /*
  998. * only if GRH is TRUE we might consider SOURCE_GID_IDX
  999. * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
  1000. */
  1001. if (attr->alt_ah_attr.ah_flags == IB_AH_GRH) {
  1002. mqpcb->send_grh_flag_al = 1 << 31;
  1003. update_mask |=
  1004. EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG_AL, 1);
  1005. mqpcb->source_gid_idx_al =
  1006. attr->alt_ah_attr.grh.sgid_index;
  1007. update_mask |=
  1008. EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX_AL, 1);
  1009. for (cnt = 0; cnt < 16; cnt++)
  1010. mqpcb->dest_gid_al.byte[cnt] =
  1011. attr->alt_ah_attr.grh.dgid.raw[cnt];
  1012. update_mask |=
  1013. EHCA_BMASK_SET(MQPCB_MASK_DEST_GID_AL, 1);
  1014. mqpcb->flow_label_al = attr->alt_ah_attr.grh.flow_label;
  1015. update_mask |=
  1016. EHCA_BMASK_SET(MQPCB_MASK_FLOW_LABEL_AL, 1);
  1017. mqpcb->hop_limit_al = attr->alt_ah_attr.grh.hop_limit;
  1018. update_mask |=
  1019. EHCA_BMASK_SET(MQPCB_MASK_HOP_LIMIT_AL, 1);
  1020. mqpcb->traffic_class_al =
  1021. attr->alt_ah_attr.grh.traffic_class;
  1022. update_mask |=
  1023. EHCA_BMASK_SET(MQPCB_MASK_TRAFFIC_CLASS_AL, 1);
  1024. }
  1025. }
  1026. if (attr_mask & IB_QP_MIN_RNR_TIMER) {
  1027. mqpcb->min_rnr_nak_timer_field = attr->min_rnr_timer;
  1028. update_mask |=
  1029. EHCA_BMASK_SET(MQPCB_MASK_MIN_RNR_NAK_TIMER_FIELD, 1);
  1030. }
  1031. if (attr_mask & IB_QP_SQ_PSN) {
  1032. mqpcb->send_psn = attr->sq_psn;
  1033. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_PSN, 1);
  1034. }
  1035. if (attr_mask & IB_QP_DEST_QPN) {
  1036. mqpcb->dest_qp_nr = attr->dest_qp_num;
  1037. update_mask |= EHCA_BMASK_SET(MQPCB_MASK_DEST_QP_NR, 1);
  1038. }
  1039. if (attr_mask & IB_QP_PATH_MIG_STATE) {
  1040. mqpcb->path_migration_state = attr->path_mig_state;
  1041. update_mask |=
  1042. EHCA_BMASK_SET(MQPCB_MASK_PATH_MIGRATION_STATE, 1);
  1043. }
  1044. if (attr_mask & IB_QP_CAP) {
  1045. mqpcb->max_nr_outst_send_wr = attr->cap.max_send_wr+1;
  1046. update_mask |=
  1047. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_SEND_WR, 1);
  1048. mqpcb->max_nr_outst_recv_wr = attr->cap.max_recv_wr+1;
  1049. update_mask |=
  1050. EHCA_BMASK_SET(MQPCB_MASK_MAX_NR_OUTST_RECV_WR, 1);
  1051. /* no support for max_send/recv_sge yet */
  1052. }
  1053. if (ehca_debug_level)
  1054. ehca_dmp(mqpcb, 4*70, "qp_num=%x", ibqp->qp_num);
  1055. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1056. my_qp->ipz_qp_handle,
  1057. &my_qp->pf,
  1058. update_mask,
  1059. mqpcb, my_qp->galpas.kernel);
  1060. if (h_ret != H_SUCCESS) {
  1061. ret = ehca2ib_return_code(h_ret);
  1062. ehca_err(ibqp->device, "hipz_h_modify_qp() failed rc=%lx "
  1063. "ehca_qp=%p qp_num=%x",h_ret, my_qp, ibqp->qp_num);
  1064. goto modify_qp_exit2;
  1065. }
  1066. if ((my_qp->qp_type == IB_QPT_UD ||
  1067. my_qp->qp_type == IB_QPT_GSI ||
  1068. my_qp->qp_type == IB_QPT_SMI) &&
  1069. statetrans == IB_QPST_SQE2RTS) {
  1070. /* doorbell to reprocessing wqes */
  1071. iosync(); /* serialize GAL register access */
  1072. hipz_update_sqa(my_qp, bad_wqe_cnt-1);
  1073. ehca_gen_dbg("doorbell for %x wqes", bad_wqe_cnt);
  1074. }
  1075. if (statetrans == IB_QPST_RESET2INIT ||
  1076. statetrans == IB_QPST_INIT2INIT) {
  1077. mqpcb->qp_enable = 1;
  1078. mqpcb->qp_state = EHCA_QPS_INIT;
  1079. update_mask = 0;
  1080. update_mask = EHCA_BMASK_SET(MQPCB_MASK_QP_ENABLE, 1);
  1081. h_ret = hipz_h_modify_qp(shca->ipz_hca_handle,
  1082. my_qp->ipz_qp_handle,
  1083. &my_qp->pf,
  1084. update_mask,
  1085. mqpcb,
  1086. my_qp->galpas.kernel);
  1087. if (h_ret != H_SUCCESS) {
  1088. ret = ehca2ib_return_code(h_ret);
  1089. ehca_err(ibqp->device, "ENABLE in context of "
  1090. "RESET_2_INIT failed! Maybe you didn't get "
  1091. "a LID h_ret=%lx ehca_qp=%p qp_num=%x",
  1092. h_ret, my_qp, ibqp->qp_num);
  1093. goto modify_qp_exit2;
  1094. }
  1095. }
  1096. if (statetrans == IB_QPST_ANY2RESET) {
  1097. ipz_qeit_reset(&my_qp->ipz_rqueue);
  1098. ipz_qeit_reset(&my_qp->ipz_squeue);
  1099. }
  1100. if (attr_mask & IB_QP_QKEY)
  1101. my_qp->qkey = attr->qkey;
  1102. modify_qp_exit2:
  1103. if (squeue_locked) { /* this means: sqe -> rts */
  1104. spin_unlock_irqrestore(&my_qp->spinlock_s, spl_flags);
  1105. my_qp->sqerr_purgeflag = 1;
  1106. }
  1107. modify_qp_exit1:
  1108. ehca_free_fw_ctrlblock(mqpcb);
  1109. return ret;
  1110. }
  1111. int ehca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
  1112. struct ib_udata *udata)
  1113. {
  1114. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  1115. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1116. ib_pd);
  1117. u32 cur_pid = current->tgid;
  1118. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1119. my_pd->ownpid != cur_pid) {
  1120. ehca_err(ibqp->pd->device, "Invalid caller pid=%x ownpid=%x",
  1121. cur_pid, my_pd->ownpid);
  1122. return -EINVAL;
  1123. }
  1124. return internal_modify_qp(ibqp, attr, attr_mask, 0);
  1125. }
  1126. int ehca_query_qp(struct ib_qp *qp,
  1127. struct ib_qp_attr *qp_attr,
  1128. int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr)
  1129. {
  1130. struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
  1131. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1132. ib_pd);
  1133. struct ehca_shca *shca = container_of(qp->device, struct ehca_shca,
  1134. ib_device);
  1135. struct ipz_adapter_handle adapter_handle = shca->ipz_hca_handle;
  1136. struct hcp_modify_qp_control_block *qpcb;
  1137. u32 cur_pid = current->tgid;
  1138. int cnt, ret = 0;
  1139. u64 h_ret;
  1140. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1141. my_pd->ownpid != cur_pid) {
  1142. ehca_err(qp->device, "Invalid caller pid=%x ownpid=%x",
  1143. cur_pid, my_pd->ownpid);
  1144. return -EINVAL;
  1145. }
  1146. if (qp_attr_mask & QP_ATTR_QUERY_NOT_SUPPORTED) {
  1147. ehca_err(qp->device,"Invalid attribute mask "
  1148. "ehca_qp=%p qp_num=%x qp_attr_mask=%x ",
  1149. my_qp, qp->qp_num, qp_attr_mask);
  1150. return -EINVAL;
  1151. }
  1152. qpcb = ehca_alloc_fw_ctrlblock();
  1153. if (!qpcb) {
  1154. ehca_err(qp->device,"Out of memory for qpcb "
  1155. "ehca_qp=%p qp_num=%x", my_qp, qp->qp_num);
  1156. return -ENOMEM;
  1157. }
  1158. h_ret = hipz_h_query_qp(adapter_handle,
  1159. my_qp->ipz_qp_handle,
  1160. &my_qp->pf,
  1161. qpcb, my_qp->galpas.kernel);
  1162. if (h_ret != H_SUCCESS) {
  1163. ret = ehca2ib_return_code(h_ret);
  1164. ehca_err(qp->device,"hipz_h_query_qp() failed "
  1165. "ehca_qp=%p qp_num=%x h_ret=%lx",
  1166. my_qp, qp->qp_num, h_ret);
  1167. goto query_qp_exit1;
  1168. }
  1169. qp_attr->cur_qp_state = ehca2ib_qp_state(qpcb->qp_state);
  1170. qp_attr->qp_state = qp_attr->cur_qp_state;
  1171. if (qp_attr->cur_qp_state == -EINVAL) {
  1172. ret = -EINVAL;
  1173. ehca_err(qp->device,"Got invalid ehca_qp_state=%x "
  1174. "ehca_qp=%p qp_num=%x",
  1175. qpcb->qp_state, my_qp, qp->qp_num);
  1176. goto query_qp_exit1;
  1177. }
  1178. if (qp_attr->qp_state == IB_QPS_SQD)
  1179. qp_attr->sq_draining = 1;
  1180. qp_attr->qkey = qpcb->qkey;
  1181. qp_attr->path_mtu = qpcb->path_mtu;
  1182. qp_attr->path_mig_state = qpcb->path_migration_state;
  1183. qp_attr->rq_psn = qpcb->receive_psn;
  1184. qp_attr->sq_psn = qpcb->send_psn;
  1185. qp_attr->min_rnr_timer = qpcb->min_rnr_nak_timer_field;
  1186. qp_attr->cap.max_send_wr = qpcb->max_nr_outst_send_wr-1;
  1187. qp_attr->cap.max_recv_wr = qpcb->max_nr_outst_recv_wr-1;
  1188. /* UD_AV CIRCUMVENTION */
  1189. if (my_qp->qp_type == IB_QPT_UD) {
  1190. qp_attr->cap.max_send_sge =
  1191. qpcb->actual_nr_sges_in_sq_wqe - 2;
  1192. qp_attr->cap.max_recv_sge =
  1193. qpcb->actual_nr_sges_in_rq_wqe - 2;
  1194. } else {
  1195. qp_attr->cap.max_send_sge =
  1196. qpcb->actual_nr_sges_in_sq_wqe;
  1197. qp_attr->cap.max_recv_sge =
  1198. qpcb->actual_nr_sges_in_rq_wqe;
  1199. }
  1200. qp_attr->cap.max_inline_data = my_qp->sq_max_inline_data_size;
  1201. qp_attr->dest_qp_num = qpcb->dest_qp_nr;
  1202. qp_attr->pkey_index =
  1203. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->prim_p_key_idx);
  1204. qp_attr->port_num =
  1205. EHCA_BMASK_GET(MQPCB_PRIM_PHYS_PORT, qpcb->prim_phys_port);
  1206. qp_attr->timeout = qpcb->timeout;
  1207. qp_attr->retry_cnt = qpcb->retry_count;
  1208. qp_attr->rnr_retry = qpcb->rnr_retry_count;
  1209. qp_attr->alt_pkey_index =
  1210. EHCA_BMASK_GET(MQPCB_PRIM_P_KEY_IDX, qpcb->alt_p_key_idx);
  1211. qp_attr->alt_port_num = qpcb->alt_phys_port;
  1212. qp_attr->alt_timeout = qpcb->timeout_al;
  1213. /* primary av */
  1214. qp_attr->ah_attr.sl = qpcb->service_level;
  1215. if (qpcb->send_grh_flag) {
  1216. qp_attr->ah_attr.ah_flags = IB_AH_GRH;
  1217. }
  1218. qp_attr->ah_attr.static_rate = qpcb->max_static_rate;
  1219. qp_attr->ah_attr.dlid = qpcb->dlid;
  1220. qp_attr->ah_attr.src_path_bits = qpcb->source_path_bits;
  1221. qp_attr->ah_attr.port_num = qp_attr->port_num;
  1222. /* primary GRH */
  1223. qp_attr->ah_attr.grh.traffic_class = qpcb->traffic_class;
  1224. qp_attr->ah_attr.grh.hop_limit = qpcb->hop_limit;
  1225. qp_attr->ah_attr.grh.sgid_index = qpcb->source_gid_idx;
  1226. qp_attr->ah_attr.grh.flow_label = qpcb->flow_label;
  1227. for (cnt = 0; cnt < 16; cnt++)
  1228. qp_attr->ah_attr.grh.dgid.raw[cnt] =
  1229. qpcb->dest_gid.byte[cnt];
  1230. /* alternate AV */
  1231. qp_attr->alt_ah_attr.sl = qpcb->service_level_al;
  1232. if (qpcb->send_grh_flag_al) {
  1233. qp_attr->alt_ah_attr.ah_flags = IB_AH_GRH;
  1234. }
  1235. qp_attr->alt_ah_attr.static_rate = qpcb->max_static_rate_al;
  1236. qp_attr->alt_ah_attr.dlid = qpcb->dlid_al;
  1237. qp_attr->alt_ah_attr.src_path_bits = qpcb->source_path_bits_al;
  1238. /* alternate GRH */
  1239. qp_attr->alt_ah_attr.grh.traffic_class = qpcb->traffic_class_al;
  1240. qp_attr->alt_ah_attr.grh.hop_limit = qpcb->hop_limit_al;
  1241. qp_attr->alt_ah_attr.grh.sgid_index = qpcb->source_gid_idx_al;
  1242. qp_attr->alt_ah_attr.grh.flow_label = qpcb->flow_label_al;
  1243. for (cnt = 0; cnt < 16; cnt++)
  1244. qp_attr->alt_ah_attr.grh.dgid.raw[cnt] =
  1245. qpcb->dest_gid_al.byte[cnt];
  1246. /* return init attributes given in ehca_create_qp */
  1247. if (qp_init_attr)
  1248. *qp_init_attr = my_qp->init_attr;
  1249. if (ehca_debug_level)
  1250. ehca_dmp(qpcb, 4*70, "qp_num=%x", qp->qp_num);
  1251. query_qp_exit1:
  1252. ehca_free_fw_ctrlblock(qpcb);
  1253. return ret;
  1254. }
  1255. int ehca_destroy_qp(struct ib_qp *ibqp)
  1256. {
  1257. struct ehca_qp *my_qp = container_of(ibqp, struct ehca_qp, ib_qp);
  1258. struct ehca_shca *shca = container_of(ibqp->device, struct ehca_shca,
  1259. ib_device);
  1260. struct ehca_pd *my_pd = container_of(my_qp->ib_qp.pd, struct ehca_pd,
  1261. ib_pd);
  1262. u32 cur_pid = current->tgid;
  1263. u32 qp_num = ibqp->qp_num;
  1264. int ret;
  1265. u64 h_ret;
  1266. u8 port_num;
  1267. enum ib_qp_type qp_type;
  1268. unsigned long flags;
  1269. if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
  1270. my_pd->ownpid != cur_pid) {
  1271. ehca_err(ibqp->device, "Invalid caller pid=%x ownpid=%x",
  1272. cur_pid, my_pd->ownpid);
  1273. return -EINVAL;
  1274. }
  1275. if (my_qp->send_cq) {
  1276. ret = ehca_cq_unassign_qp(my_qp->send_cq,
  1277. my_qp->real_qp_num);
  1278. if (ret) {
  1279. ehca_err(ibqp->device, "Couldn't unassign qp from "
  1280. "send_cq ret=%x qp_num=%x cq_num=%x", ret,
  1281. my_qp->ib_qp.qp_num, my_qp->send_cq->cq_number);
  1282. return ret;
  1283. }
  1284. }
  1285. spin_lock_irqsave(&ehca_qp_idr_lock, flags);
  1286. idr_remove(&ehca_qp_idr, my_qp->token);
  1287. spin_unlock_irqrestore(&ehca_qp_idr_lock, flags);
  1288. /* un-mmap if vma alloc */
  1289. if (my_qp->uspace_rqueue) {
  1290. ret = ehca_munmap(my_qp->uspace_rqueue,
  1291. my_qp->ipz_rqueue.queue_length);
  1292. if (ret)
  1293. ehca_err(ibqp->device, "Could not munmap rqueue "
  1294. "qp_num=%x", qp_num);
  1295. ret = ehca_munmap(my_qp->uspace_squeue,
  1296. my_qp->ipz_squeue.queue_length);
  1297. if (ret)
  1298. ehca_err(ibqp->device, "Could not munmap squeue "
  1299. "qp_num=%x", qp_num);
  1300. ret = ehca_munmap(my_qp->uspace_fwh, EHCA_PAGESIZE);
  1301. if (ret)
  1302. ehca_err(ibqp->device, "Could not munmap fwh qp_num=%x",
  1303. qp_num);
  1304. }
  1305. h_ret = hipz_h_destroy_qp(shca->ipz_hca_handle, my_qp);
  1306. if (h_ret != H_SUCCESS) {
  1307. ehca_err(ibqp->device, "hipz_h_destroy_qp() failed rc=%lx "
  1308. "ehca_qp=%p qp_num=%x", h_ret, my_qp, qp_num);
  1309. return ehca2ib_return_code(h_ret);
  1310. }
  1311. port_num = my_qp->init_attr.port_num;
  1312. qp_type = my_qp->init_attr.qp_type;
  1313. /* no support for IB_QPT_SMI yet */
  1314. if (qp_type == IB_QPT_GSI) {
  1315. struct ib_event event;
  1316. ehca_info(ibqp->device, "device %s: port %x is inactive.",
  1317. shca->ib_device.name, port_num);
  1318. event.device = &shca->ib_device;
  1319. event.event = IB_EVENT_PORT_ERR;
  1320. event.element.port_num = port_num;
  1321. shca->sport[port_num - 1].port_state = IB_PORT_DOWN;
  1322. ib_dispatch_event(&event);
  1323. }
  1324. ipz_queue_dtor(&my_qp->ipz_rqueue);
  1325. ipz_queue_dtor(&my_qp->ipz_squeue);
  1326. kmem_cache_free(qp_cache, my_qp);
  1327. return 0;
  1328. }
  1329. int ehca_init_qp_cache(void)
  1330. {
  1331. qp_cache = kmem_cache_create("ehca_cache_qp",
  1332. sizeof(struct ehca_qp), 0,
  1333. SLAB_HWCACHE_ALIGN,
  1334. NULL, NULL);
  1335. if (!qp_cache)
  1336. return -ENOMEM;
  1337. return 0;
  1338. }
  1339. void ehca_cleanup_qp_cache(void)
  1340. {
  1341. if (qp_cache)
  1342. kmem_cache_destroy(qp_cache);
  1343. }