ehca_qp.c 49 KB

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