ehca_reqs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * post_send/recv, poll_cq, req_notify
  5. *
  6. * Authors: Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  7. * Waleri Fomin <fomin@de.ibm.com>
  8. * Joachim Fenkes <fenkes@de.ibm.com>
  9. * Reinhard Ernst <rernst@de.ibm.com>
  10. *
  11. * Copyright (c) 2005 IBM Corporation
  12. *
  13. * All rights reserved.
  14. *
  15. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  16. * BSD.
  17. *
  18. * OpenIB BSD License
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. *
  23. * Redistributions of source code must retain the above copyright notice, this
  24. * list of conditions and the following disclaimer.
  25. *
  26. * Redistributions in binary form must reproduce the above copyright notice,
  27. * this list of conditions and the following disclaimer in the documentation
  28. * and/or other materials
  29. * provided with the distribution.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  32. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  35. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  36. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  38. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  39. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. #include <asm-powerpc/system.h>
  44. #include "ehca_classes.h"
  45. #include "ehca_tools.h"
  46. #include "ehca_qes.h"
  47. #include "ehca_iverbs.h"
  48. #include "hcp_if.h"
  49. #include "hipz_fns.h"
  50. static inline int ehca_write_rwqe(struct ipz_queue *ipz_rqueue,
  51. struct ehca_wqe *wqe_p,
  52. struct ib_recv_wr *recv_wr)
  53. {
  54. u8 cnt_ds;
  55. if (unlikely((recv_wr->num_sge < 0) ||
  56. (recv_wr->num_sge > ipz_rqueue->act_nr_of_sg))) {
  57. ehca_gen_err("Invalid number of WQE SGE. "
  58. "num_sqe=%x max_nr_of_sg=%x",
  59. recv_wr->num_sge, ipz_rqueue->act_nr_of_sg);
  60. return -EINVAL; /* invalid SG list length */
  61. }
  62. /* clear wqe header until sglist */
  63. memset(wqe_p, 0, offsetof(struct ehca_wqe, u.ud_av.sg_list));
  64. wqe_p->work_request_id = recv_wr->wr_id;
  65. wqe_p->nr_of_data_seg = recv_wr->num_sge;
  66. for (cnt_ds = 0; cnt_ds < recv_wr->num_sge; cnt_ds++) {
  67. wqe_p->u.all_rcv.sg_list[cnt_ds].vaddr =
  68. recv_wr->sg_list[cnt_ds].addr;
  69. wqe_p->u.all_rcv.sg_list[cnt_ds].lkey =
  70. recv_wr->sg_list[cnt_ds].lkey;
  71. wqe_p->u.all_rcv.sg_list[cnt_ds].length =
  72. recv_wr->sg_list[cnt_ds].length;
  73. }
  74. if (ehca_debug_level) {
  75. ehca_gen_dbg("RECEIVE WQE written into ipz_rqueue=%p",
  76. ipz_rqueue);
  77. ehca_dmp( wqe_p, 16*(6 + wqe_p->nr_of_data_seg), "recv wqe");
  78. }
  79. return 0;
  80. }
  81. #if defined(DEBUG_GSI_SEND_WR)
  82. /* need ib_mad struct */
  83. #include <rdma/ib_mad.h>
  84. static void trace_send_wr_ud(const struct ib_send_wr *send_wr)
  85. {
  86. int idx;
  87. int j;
  88. while (send_wr) {
  89. struct ib_mad_hdr *mad_hdr = send_wr->wr.ud.mad_hdr;
  90. struct ib_sge *sge = send_wr->sg_list;
  91. ehca_gen_dbg("send_wr#%x wr_id=%lx num_sge=%x "
  92. "send_flags=%x opcode=%x", idx, send_wr->wr_id,
  93. send_wr->num_sge, send_wr->send_flags,
  94. send_wr->opcode);
  95. if (mad_hdr) {
  96. ehca_gen_dbg("send_wr#%x mad_hdr base_version=%x "
  97. "mgmt_class=%x class_version=%x method=%x "
  98. "status=%x class_specific=%x tid=%lx "
  99. "attr_id=%x resv=%x attr_mod=%x",
  100. idx, mad_hdr->base_version,
  101. mad_hdr->mgmt_class,
  102. mad_hdr->class_version, mad_hdr->method,
  103. mad_hdr->status, mad_hdr->class_specific,
  104. mad_hdr->tid, mad_hdr->attr_id,
  105. mad_hdr->resv,
  106. mad_hdr->attr_mod);
  107. }
  108. for (j = 0; j < send_wr->num_sge; j++) {
  109. u8 *data = (u8 *)abs_to_virt(sge->addr);
  110. ehca_gen_dbg("send_wr#%x sge#%x addr=%p length=%x "
  111. "lkey=%x",
  112. idx, j, data, sge->length, sge->lkey);
  113. /* assume length is n*16 */
  114. ehca_dmp(data, sge->length, "send_wr#%x sge#%x",
  115. idx, j);
  116. sge++;
  117. } /* eof for j */
  118. idx++;
  119. send_wr = send_wr->next;
  120. } /* eof while send_wr */
  121. }
  122. #endif /* DEBUG_GSI_SEND_WR */
  123. static inline int ehca_write_swqe(struct ehca_qp *qp,
  124. struct ehca_wqe *wqe_p,
  125. const struct ib_send_wr *send_wr)
  126. {
  127. u32 idx;
  128. u64 dma_length;
  129. struct ehca_av *my_av;
  130. u32 remote_qkey = send_wr->wr.ud.remote_qkey;
  131. if (unlikely((send_wr->num_sge < 0) ||
  132. (send_wr->num_sge > qp->ipz_squeue.act_nr_of_sg))) {
  133. ehca_gen_err("Invalid number of WQE SGE. "
  134. "num_sqe=%x max_nr_of_sg=%x",
  135. send_wr->num_sge, qp->ipz_squeue.act_nr_of_sg);
  136. return -EINVAL; /* invalid SG list length */
  137. }
  138. /* clear wqe header until sglist */
  139. memset(wqe_p, 0, offsetof(struct ehca_wqe, u.ud_av.sg_list));
  140. wqe_p->work_request_id = send_wr->wr_id;
  141. switch (send_wr->opcode) {
  142. case IB_WR_SEND:
  143. case IB_WR_SEND_WITH_IMM:
  144. wqe_p->optype = WQE_OPTYPE_SEND;
  145. break;
  146. case IB_WR_RDMA_WRITE:
  147. case IB_WR_RDMA_WRITE_WITH_IMM:
  148. wqe_p->optype = WQE_OPTYPE_RDMAWRITE;
  149. break;
  150. case IB_WR_RDMA_READ:
  151. wqe_p->optype = WQE_OPTYPE_RDMAREAD;
  152. break;
  153. default:
  154. ehca_gen_err("Invalid opcode=%x", send_wr->opcode);
  155. return -EINVAL; /* invalid opcode */
  156. }
  157. wqe_p->wqef = (send_wr->opcode) & WQEF_HIGH_NIBBLE;
  158. wqe_p->wr_flag = 0;
  159. if (send_wr->send_flags & IB_SEND_SIGNALED)
  160. wqe_p->wr_flag |= WQE_WRFLAG_REQ_SIGNAL_COM;
  161. if (send_wr->opcode == IB_WR_SEND_WITH_IMM ||
  162. send_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
  163. /* this might not work as long as HW does not support it */
  164. wqe_p->immediate_data = be32_to_cpu(send_wr->imm_data);
  165. wqe_p->wr_flag |= WQE_WRFLAG_IMM_DATA_PRESENT;
  166. }
  167. wqe_p->nr_of_data_seg = send_wr->num_sge;
  168. switch (qp->qp_type) {
  169. case IB_QPT_SMI:
  170. case IB_QPT_GSI:
  171. /* no break is intential here */
  172. case IB_QPT_UD:
  173. /* IB 1.2 spec C10-15 compliance */
  174. if (send_wr->wr.ud.remote_qkey & 0x80000000)
  175. remote_qkey = qp->qkey;
  176. wqe_p->destination_qp_number = send_wr->wr.ud.remote_qpn << 8;
  177. wqe_p->local_ee_context_qkey = remote_qkey;
  178. if (!send_wr->wr.ud.ah) {
  179. ehca_gen_err("wr.ud.ah is NULL. qp=%p", qp);
  180. return -EINVAL;
  181. }
  182. my_av = container_of(send_wr->wr.ud.ah, struct ehca_av, ib_ah);
  183. wqe_p->u.ud_av.ud_av = my_av->av;
  184. /*
  185. * omitted check of IB_SEND_INLINE
  186. * since HW does not support it
  187. */
  188. for (idx = 0; idx < send_wr->num_sge; idx++) {
  189. wqe_p->u.ud_av.sg_list[idx].vaddr =
  190. send_wr->sg_list[idx].addr;
  191. wqe_p->u.ud_av.sg_list[idx].lkey =
  192. send_wr->sg_list[idx].lkey;
  193. wqe_p->u.ud_av.sg_list[idx].length =
  194. send_wr->sg_list[idx].length;
  195. } /* eof for idx */
  196. if (qp->qp_type == IB_QPT_SMI ||
  197. qp->qp_type == IB_QPT_GSI)
  198. wqe_p->u.ud_av.ud_av.pmtu = 1;
  199. if (qp->qp_type == IB_QPT_GSI) {
  200. wqe_p->pkeyi = send_wr->wr.ud.pkey_index;
  201. #ifdef DEBUG_GSI_SEND_WR
  202. trace_send_wr_ud(send_wr);
  203. #endif /* DEBUG_GSI_SEND_WR */
  204. }
  205. break;
  206. case IB_QPT_UC:
  207. if (send_wr->send_flags & IB_SEND_FENCE)
  208. wqe_p->wr_flag |= WQE_WRFLAG_FENCE;
  209. /* no break is intentional here */
  210. case IB_QPT_RC:
  211. /* TODO: atomic not implemented */
  212. wqe_p->u.nud.remote_virtual_adress =
  213. send_wr->wr.rdma.remote_addr;
  214. wqe_p->u.nud.rkey = send_wr->wr.rdma.rkey;
  215. /*
  216. * omitted checking of IB_SEND_INLINE
  217. * since HW does not support it
  218. */
  219. dma_length = 0;
  220. for (idx = 0; idx < send_wr->num_sge; idx++) {
  221. wqe_p->u.nud.sg_list[idx].vaddr =
  222. send_wr->sg_list[idx].addr;
  223. wqe_p->u.nud.sg_list[idx].lkey =
  224. send_wr->sg_list[idx].lkey;
  225. wqe_p->u.nud.sg_list[idx].length =
  226. send_wr->sg_list[idx].length;
  227. dma_length += send_wr->sg_list[idx].length;
  228. } /* eof idx */
  229. wqe_p->u.nud.atomic_1st_op_dma_len = dma_length;
  230. break;
  231. default:
  232. ehca_gen_err("Invalid qptype=%x", qp->qp_type);
  233. return -EINVAL;
  234. }
  235. if (ehca_debug_level) {
  236. ehca_gen_dbg("SEND WQE written into queue qp=%p ", qp);
  237. ehca_dmp( wqe_p, 16*(6 + wqe_p->nr_of_data_seg), "send wqe");
  238. }
  239. return 0;
  240. }
  241. /* map_ib_wc_status converts raw cqe_status to ib_wc_status */
  242. static inline void map_ib_wc_status(u32 cqe_status,
  243. enum ib_wc_status *wc_status)
  244. {
  245. if (unlikely(cqe_status & WC_STATUS_ERROR_BIT)) {
  246. switch (cqe_status & 0x3F) {
  247. case 0x01:
  248. case 0x21:
  249. *wc_status = IB_WC_LOC_LEN_ERR;
  250. break;
  251. case 0x02:
  252. case 0x22:
  253. *wc_status = IB_WC_LOC_QP_OP_ERR;
  254. break;
  255. case 0x03:
  256. case 0x23:
  257. *wc_status = IB_WC_LOC_EEC_OP_ERR;
  258. break;
  259. case 0x04:
  260. case 0x24:
  261. *wc_status = IB_WC_LOC_PROT_ERR;
  262. break;
  263. case 0x05:
  264. case 0x25:
  265. *wc_status = IB_WC_WR_FLUSH_ERR;
  266. break;
  267. case 0x06:
  268. *wc_status = IB_WC_MW_BIND_ERR;
  269. break;
  270. case 0x07: /* remote error - look into bits 20:24 */
  271. switch ((cqe_status
  272. & WC_STATUS_REMOTE_ERROR_FLAGS) >> 11) {
  273. case 0x0:
  274. /*
  275. * PSN Sequence Error!
  276. * couldn't find a matching status!
  277. */
  278. *wc_status = IB_WC_GENERAL_ERR;
  279. break;
  280. case 0x1:
  281. *wc_status = IB_WC_REM_INV_REQ_ERR;
  282. break;
  283. case 0x2:
  284. *wc_status = IB_WC_REM_ACCESS_ERR;
  285. break;
  286. case 0x3:
  287. *wc_status = IB_WC_REM_OP_ERR;
  288. break;
  289. case 0x4:
  290. *wc_status = IB_WC_REM_INV_RD_REQ_ERR;
  291. break;
  292. }
  293. break;
  294. case 0x08:
  295. *wc_status = IB_WC_RETRY_EXC_ERR;
  296. break;
  297. case 0x09:
  298. *wc_status = IB_WC_RNR_RETRY_EXC_ERR;
  299. break;
  300. case 0x0A:
  301. case 0x2D:
  302. *wc_status = IB_WC_REM_ABORT_ERR;
  303. break;
  304. case 0x0B:
  305. case 0x2E:
  306. *wc_status = IB_WC_INV_EECN_ERR;
  307. break;
  308. case 0x0C:
  309. case 0x2F:
  310. *wc_status = IB_WC_INV_EEC_STATE_ERR;
  311. break;
  312. case 0x0D:
  313. *wc_status = IB_WC_BAD_RESP_ERR;
  314. break;
  315. case 0x10:
  316. /* WQE purged */
  317. *wc_status = IB_WC_WR_FLUSH_ERR;
  318. break;
  319. default:
  320. *wc_status = IB_WC_FATAL_ERR;
  321. }
  322. } else
  323. *wc_status = IB_WC_SUCCESS;
  324. }
  325. int ehca_post_send(struct ib_qp *qp,
  326. struct ib_send_wr *send_wr,
  327. struct ib_send_wr **bad_send_wr)
  328. {
  329. struct ehca_qp *my_qp = container_of(qp, struct ehca_qp, ib_qp);
  330. struct ib_send_wr *cur_send_wr;
  331. struct ehca_wqe *wqe_p;
  332. int wqe_cnt = 0;
  333. int ret = 0;
  334. unsigned long flags;
  335. /* LOCK the QUEUE */
  336. spin_lock_irqsave(&my_qp->spinlock_s, flags);
  337. /* loop processes list of send reqs */
  338. for (cur_send_wr = send_wr; cur_send_wr != NULL;
  339. cur_send_wr = cur_send_wr->next) {
  340. u64 start_offset = my_qp->ipz_squeue.current_q_offset;
  341. /* get pointer next to free WQE */
  342. wqe_p = ipz_qeit_get_inc(&my_qp->ipz_squeue);
  343. if (unlikely(!wqe_p)) {
  344. /* too many posted work requests: queue overflow */
  345. if (bad_send_wr)
  346. *bad_send_wr = cur_send_wr;
  347. if (wqe_cnt == 0) {
  348. ret = -ENOMEM;
  349. ehca_err(qp->device, "Too many posted WQEs "
  350. "qp_num=%x", qp->qp_num);
  351. }
  352. goto post_send_exit0;
  353. }
  354. /* write a SEND WQE into the QUEUE */
  355. ret = ehca_write_swqe(my_qp, wqe_p, cur_send_wr);
  356. /*
  357. * if something failed,
  358. * reset the free entry pointer to the start value
  359. */
  360. if (unlikely(ret)) {
  361. my_qp->ipz_squeue.current_q_offset = start_offset;
  362. *bad_send_wr = cur_send_wr;
  363. if (wqe_cnt == 0) {
  364. ret = -EINVAL;
  365. ehca_err(qp->device, "Could not write WQE "
  366. "qp_num=%x", qp->qp_num);
  367. }
  368. goto post_send_exit0;
  369. }
  370. wqe_cnt++;
  371. ehca_dbg(qp->device, "ehca_qp=%p qp_num=%x wqe_cnt=%d",
  372. my_qp, qp->qp_num, wqe_cnt);
  373. } /* eof for cur_send_wr */
  374. post_send_exit0:
  375. iosync(); /* serialize GAL register access */
  376. hipz_update_sqa(my_qp, wqe_cnt);
  377. spin_unlock_irqrestore(&my_qp->spinlock_s, flags);
  378. return ret;
  379. }
  380. static int internal_post_recv(struct ehca_qp *my_qp,
  381. struct ib_device *dev,
  382. struct ib_recv_wr *recv_wr,
  383. struct ib_recv_wr **bad_recv_wr)
  384. {
  385. struct ib_recv_wr *cur_recv_wr;
  386. struct ehca_wqe *wqe_p;
  387. int wqe_cnt = 0;
  388. int ret = 0;
  389. unsigned long flags;
  390. if (unlikely(!HAS_RQ(my_qp))) {
  391. ehca_err(dev, "QP has no RQ ehca_qp=%p qp_num=%x ext_type=%d",
  392. my_qp, my_qp->real_qp_num, my_qp->ext_type);
  393. return -ENODEV;
  394. }
  395. /* LOCK the QUEUE */
  396. spin_lock_irqsave(&my_qp->spinlock_r, flags);
  397. /* loop processes list of send reqs */
  398. for (cur_recv_wr = recv_wr; cur_recv_wr != NULL;
  399. cur_recv_wr = cur_recv_wr->next) {
  400. u64 start_offset = my_qp->ipz_rqueue.current_q_offset;
  401. /* get pointer next to free WQE */
  402. wqe_p = ipz_qeit_get_inc(&my_qp->ipz_rqueue);
  403. if (unlikely(!wqe_p)) {
  404. /* too many posted work requests: queue overflow */
  405. if (bad_recv_wr)
  406. *bad_recv_wr = cur_recv_wr;
  407. if (wqe_cnt == 0) {
  408. ret = -ENOMEM;
  409. ehca_err(dev, "Too many posted WQEs "
  410. "qp_num=%x", my_qp->real_qp_num);
  411. }
  412. goto post_recv_exit0;
  413. }
  414. /* write a RECV WQE into the QUEUE */
  415. ret = ehca_write_rwqe(&my_qp->ipz_rqueue, wqe_p, cur_recv_wr);
  416. /*
  417. * if something failed,
  418. * reset the free entry pointer to the start value
  419. */
  420. if (unlikely(ret)) {
  421. my_qp->ipz_rqueue.current_q_offset = start_offset;
  422. *bad_recv_wr = cur_recv_wr;
  423. if (wqe_cnt == 0) {
  424. ret = -EINVAL;
  425. ehca_err(dev, "Could not write WQE "
  426. "qp_num=%x", my_qp->real_qp_num);
  427. }
  428. goto post_recv_exit0;
  429. }
  430. wqe_cnt++;
  431. ehca_dbg(dev, "ehca_qp=%p qp_num=%x wqe_cnt=%d",
  432. my_qp, my_qp->real_qp_num, wqe_cnt);
  433. } /* eof for cur_recv_wr */
  434. post_recv_exit0:
  435. iosync(); /* serialize GAL register access */
  436. hipz_update_rqa(my_qp, wqe_cnt);
  437. spin_unlock_irqrestore(&my_qp->spinlock_r, flags);
  438. return ret;
  439. }
  440. int ehca_post_recv(struct ib_qp *qp,
  441. struct ib_recv_wr *recv_wr,
  442. struct ib_recv_wr **bad_recv_wr)
  443. {
  444. return internal_post_recv(container_of(qp, struct ehca_qp, ib_qp),
  445. qp->device, recv_wr, bad_recv_wr);
  446. }
  447. int ehca_post_srq_recv(struct ib_srq *srq,
  448. struct ib_recv_wr *recv_wr,
  449. struct ib_recv_wr **bad_recv_wr)
  450. {
  451. return internal_post_recv(container_of(srq, struct ehca_qp, ib_srq),
  452. srq->device, recv_wr, bad_recv_wr);
  453. }
  454. /*
  455. * ib_wc_opcode table converts ehca wc opcode to ib
  456. * Since we use zero to indicate invalid opcode, the actual ib opcode must
  457. * be decremented!!!
  458. */
  459. static const u8 ib_wc_opcode[255] = {
  460. [0x01] = IB_WC_RECV+1,
  461. [0x02] = IB_WC_RECV_RDMA_WITH_IMM+1,
  462. [0x04] = IB_WC_BIND_MW+1,
  463. [0x08] = IB_WC_FETCH_ADD+1,
  464. [0x10] = IB_WC_COMP_SWAP+1,
  465. [0x20] = IB_WC_RDMA_WRITE+1,
  466. [0x40] = IB_WC_RDMA_READ+1,
  467. [0x80] = IB_WC_SEND+1
  468. };
  469. /* internal function to poll one entry of cq */
  470. static inline int ehca_poll_cq_one(struct ib_cq *cq, struct ib_wc *wc)
  471. {
  472. int ret = 0;
  473. struct ehca_cq *my_cq = container_of(cq, struct ehca_cq, ib_cq);
  474. struct ehca_cqe *cqe;
  475. struct ehca_qp *my_qp;
  476. int cqe_count = 0;
  477. poll_cq_one_read_cqe:
  478. cqe = (struct ehca_cqe *)
  479. ipz_qeit_get_inc_valid(&my_cq->ipz_queue);
  480. if (!cqe) {
  481. ret = -EAGAIN;
  482. ehca_dbg(cq->device, "Completion queue is empty ehca_cq=%p "
  483. "cq_num=%x ret=%i", my_cq, my_cq->cq_number, ret);
  484. goto poll_cq_one_exit0;
  485. }
  486. /* prevents loads being reordered across this point */
  487. rmb();
  488. cqe_count++;
  489. if (unlikely(cqe->status & WC_STATUS_PURGE_BIT)) {
  490. struct ehca_qp *qp;
  491. int purgeflag;
  492. unsigned long flags;
  493. qp = ehca_cq_get_qp(my_cq, cqe->local_qp_number);
  494. if (!qp) {
  495. ehca_err(cq->device, "cq_num=%x qp_num=%x "
  496. "could not find qp -> ignore cqe",
  497. my_cq->cq_number, cqe->local_qp_number);
  498. ehca_dmp(cqe, 64, "cq_num=%x qp_num=%x",
  499. my_cq->cq_number, cqe->local_qp_number);
  500. /* ignore this purged cqe */
  501. goto poll_cq_one_read_cqe;
  502. }
  503. spin_lock_irqsave(&qp->spinlock_s, flags);
  504. purgeflag = qp->sqerr_purgeflag;
  505. spin_unlock_irqrestore(&qp->spinlock_s, flags);
  506. if (purgeflag) {
  507. ehca_dbg(cq->device,
  508. "Got CQE with purged bit qp_num=%x src_qp=%x",
  509. cqe->local_qp_number, cqe->remote_qp_number);
  510. if (ehca_debug_level)
  511. ehca_dmp(cqe, 64, "qp_num=%x src_qp=%x",
  512. cqe->local_qp_number,
  513. cqe->remote_qp_number);
  514. /*
  515. * ignore this to avoid double cqes of bad wqe
  516. * that caused sqe and turn off purge flag
  517. */
  518. qp->sqerr_purgeflag = 0;
  519. goto poll_cq_one_read_cqe;
  520. }
  521. }
  522. /* tracing cqe */
  523. if (unlikely(ehca_debug_level)) {
  524. ehca_dbg(cq->device,
  525. "Received COMPLETION ehca_cq=%p cq_num=%x -----",
  526. my_cq, my_cq->cq_number);
  527. ehca_dmp(cqe, 64, "ehca_cq=%p cq_num=%x",
  528. my_cq, my_cq->cq_number);
  529. ehca_dbg(cq->device,
  530. "ehca_cq=%p cq_num=%x -------------------------",
  531. my_cq, my_cq->cq_number);
  532. }
  533. /* we got a completion! */
  534. wc->wr_id = cqe->work_request_id;
  535. /* eval ib_wc_opcode */
  536. wc->opcode = ib_wc_opcode[cqe->optype]-1;
  537. if (unlikely(wc->opcode == -1)) {
  538. ehca_err(cq->device, "Invalid cqe->OPType=%x cqe->status=%x "
  539. "ehca_cq=%p cq_num=%x",
  540. cqe->optype, cqe->status, my_cq, my_cq->cq_number);
  541. /* dump cqe for other infos */
  542. ehca_dmp(cqe, 64, "ehca_cq=%p cq_num=%x",
  543. my_cq, my_cq->cq_number);
  544. /* update also queue adder to throw away this entry!!! */
  545. goto poll_cq_one_exit0;
  546. }
  547. /* eval ib_wc_status */
  548. if (unlikely(cqe->status & WC_STATUS_ERROR_BIT)) {
  549. /* complete with errors */
  550. map_ib_wc_status(cqe->status, &wc->status);
  551. wc->vendor_err = wc->status;
  552. } else
  553. wc->status = IB_WC_SUCCESS;
  554. read_lock(&ehca_qp_idr_lock);
  555. my_qp = idr_find(&ehca_qp_idr, cqe->qp_token);
  556. wc->qp = &my_qp->ib_qp;
  557. read_unlock(&ehca_qp_idr_lock);
  558. wc->byte_len = cqe->nr_bytes_transferred;
  559. wc->pkey_index = cqe->pkey_index;
  560. wc->slid = cqe->rlid;
  561. wc->dlid_path_bits = cqe->dlid;
  562. wc->src_qp = cqe->remote_qp_number;
  563. wc->wc_flags = cqe->w_completion_flags;
  564. wc->imm_data = cpu_to_be32(cqe->immediate_data);
  565. wc->sl = cqe->service_level;
  566. if (unlikely(wc->status != IB_WC_SUCCESS))
  567. ehca_dbg(cq->device,
  568. "ehca_cq=%p cq_num=%x WARNING unsuccessful cqe "
  569. "OPType=%x status=%x qp_num=%x src_qp=%x wr_id=%lx "
  570. "cqe=%p", my_cq, my_cq->cq_number, cqe->optype,
  571. cqe->status, cqe->local_qp_number,
  572. cqe->remote_qp_number, cqe->work_request_id, cqe);
  573. poll_cq_one_exit0:
  574. if (cqe_count > 0)
  575. hipz_update_feca(my_cq, cqe_count);
  576. return ret;
  577. }
  578. int ehca_poll_cq(struct ib_cq *cq, int num_entries, struct ib_wc *wc)
  579. {
  580. struct ehca_cq *my_cq = container_of(cq, struct ehca_cq, ib_cq);
  581. int nr;
  582. struct ib_wc *current_wc = wc;
  583. int ret = 0;
  584. unsigned long flags;
  585. if (num_entries < 1) {
  586. ehca_err(cq->device, "Invalid num_entries=%d ehca_cq=%p "
  587. "cq_num=%x", num_entries, my_cq, my_cq->cq_number);
  588. ret = -EINVAL;
  589. goto poll_cq_exit0;
  590. }
  591. spin_lock_irqsave(&my_cq->spinlock, flags);
  592. for (nr = 0; nr < num_entries; nr++) {
  593. ret = ehca_poll_cq_one(cq, current_wc);
  594. if (ret)
  595. break;
  596. current_wc++;
  597. } /* eof for nr */
  598. spin_unlock_irqrestore(&my_cq->spinlock, flags);
  599. if (ret == -EAGAIN || !ret)
  600. ret = nr;
  601. poll_cq_exit0:
  602. return ret;
  603. }
  604. int ehca_req_notify_cq(struct ib_cq *cq, enum ib_cq_notify_flags notify_flags)
  605. {
  606. struct ehca_cq *my_cq = container_of(cq, struct ehca_cq, ib_cq);
  607. int ret = 0;
  608. switch (notify_flags & IB_CQ_SOLICITED_MASK) {
  609. case IB_CQ_SOLICITED:
  610. hipz_set_cqx_n0(my_cq, 1);
  611. break;
  612. case IB_CQ_NEXT_COMP:
  613. hipz_set_cqx_n1(my_cq, 1);
  614. break;
  615. default:
  616. return -EINVAL;
  617. }
  618. if (notify_flags & IB_CQ_REPORT_MISSED_EVENTS) {
  619. unsigned long spl_flags;
  620. spin_lock_irqsave(&my_cq->spinlock, spl_flags);
  621. ret = ipz_qeit_is_valid(&my_cq->ipz_queue);
  622. spin_unlock_irqrestore(&my_cq->spinlock, spl_flags);
  623. }
  624. return ret;
  625. }