ehca_qp.c 48 KB

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