ehca_qp.c 57 KB

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