ehca_reqs.c 19 KB

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