restrack.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /*
  2. * Copyright (c) 2018 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <rdma/rdma_cm.h>
  33. #include "iw_cxgb4.h"
  34. #include <rdma/restrack.h>
  35. #include <uapi/rdma/rdma_netlink.h>
  36. static int fill_sq(struct sk_buff *msg, struct t4_wq *wq)
  37. {
  38. /* WQ+SQ */
  39. if (rdma_nl_put_driver_u32(msg, "sqid", wq->sq.qid))
  40. goto err;
  41. if (rdma_nl_put_driver_u32(msg, "flushed", wq->flushed))
  42. goto err;
  43. if (rdma_nl_put_driver_u32(msg, "memsize", wq->sq.memsize))
  44. goto err;
  45. if (rdma_nl_put_driver_u32(msg, "cidx", wq->sq.cidx))
  46. goto err;
  47. if (rdma_nl_put_driver_u32(msg, "pidx", wq->sq.pidx))
  48. goto err;
  49. if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->sq.wq_pidx))
  50. goto err;
  51. if (rdma_nl_put_driver_u32(msg, "flush_cidx", wq->sq.flush_cidx))
  52. goto err;
  53. if (rdma_nl_put_driver_u32(msg, "in_use", wq->sq.in_use))
  54. goto err;
  55. if (rdma_nl_put_driver_u32(msg, "size", wq->sq.size))
  56. goto err;
  57. if (rdma_nl_put_driver_u32_hex(msg, "flags", wq->sq.flags))
  58. goto err;
  59. return 0;
  60. err:
  61. return -EMSGSIZE;
  62. }
  63. static int fill_rq(struct sk_buff *msg, struct t4_wq *wq)
  64. {
  65. /* RQ */
  66. if (rdma_nl_put_driver_u32(msg, "rqid", wq->rq.qid))
  67. goto err;
  68. if (rdma_nl_put_driver_u32(msg, "memsize", wq->rq.memsize))
  69. goto err;
  70. if (rdma_nl_put_driver_u32(msg, "cidx", wq->rq.cidx))
  71. goto err;
  72. if (rdma_nl_put_driver_u32(msg, "pidx", wq->rq.pidx))
  73. goto err;
  74. if (rdma_nl_put_driver_u32(msg, "wq_pidx", wq->rq.wq_pidx))
  75. goto err;
  76. if (rdma_nl_put_driver_u32(msg, "msn", wq->rq.msn))
  77. goto err;
  78. if (rdma_nl_put_driver_u32_hex(msg, "rqt_hwaddr", wq->rq.rqt_hwaddr))
  79. goto err;
  80. if (rdma_nl_put_driver_u32(msg, "rqt_size", wq->rq.rqt_size))
  81. goto err;
  82. if (rdma_nl_put_driver_u32(msg, "in_use", wq->rq.in_use))
  83. goto err;
  84. if (rdma_nl_put_driver_u32(msg, "size", wq->rq.size))
  85. goto err;
  86. return 0;
  87. err:
  88. return -EMSGSIZE;
  89. }
  90. static int fill_swsqe(struct sk_buff *msg, struct t4_sq *sq, u16 idx,
  91. struct t4_swsqe *sqe)
  92. {
  93. if (rdma_nl_put_driver_u32(msg, "idx", idx))
  94. goto err;
  95. if (rdma_nl_put_driver_u32(msg, "opcode", sqe->opcode))
  96. goto err;
  97. if (rdma_nl_put_driver_u32(msg, "complete", sqe->complete))
  98. goto err;
  99. if (sqe->complete &&
  100. rdma_nl_put_driver_u32(msg, "cqe_status", CQE_STATUS(&sqe->cqe)))
  101. goto err;
  102. if (rdma_nl_put_driver_u32(msg, "signaled", sqe->signaled))
  103. goto err;
  104. if (rdma_nl_put_driver_u32(msg, "flushed", sqe->flushed))
  105. goto err;
  106. return 0;
  107. err:
  108. return -EMSGSIZE;
  109. }
  110. /*
  111. * Dump the first and last pending sqes.
  112. */
  113. static int fill_swsqes(struct sk_buff *msg, struct t4_sq *sq,
  114. u16 first_idx, struct t4_swsqe *first_sqe,
  115. u16 last_idx, struct t4_swsqe *last_sqe)
  116. {
  117. if (!first_sqe)
  118. goto out;
  119. if (fill_swsqe(msg, sq, first_idx, first_sqe))
  120. goto err;
  121. if (!last_sqe)
  122. goto out;
  123. if (fill_swsqe(msg, sq, last_idx, last_sqe))
  124. goto err;
  125. out:
  126. return 0;
  127. err:
  128. return -EMSGSIZE;
  129. }
  130. int c4iw_fill_res_qp_entry(struct sk_buff *msg, struct ib_qp *ibqp)
  131. {
  132. struct t4_swsqe *fsp = NULL, *lsp = NULL;
  133. struct c4iw_qp *qhp = to_c4iw_qp(ibqp);
  134. u16 first_sq_idx = 0, last_sq_idx = 0;
  135. struct t4_swsqe first_sqe, last_sqe;
  136. struct nlattr *table_attr;
  137. struct t4_wq wq;
  138. /* User qp state is not available, so don't dump user qps */
  139. if (qhp->ucontext)
  140. return 0;
  141. table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
  142. if (!table_attr)
  143. goto err;
  144. /* Get a consistent snapshot */
  145. spin_lock_irq(&qhp->lock);
  146. wq = qhp->wq;
  147. /* If there are any pending sqes, copy the first and last */
  148. if (wq.sq.cidx != wq.sq.pidx) {
  149. first_sq_idx = wq.sq.cidx;
  150. first_sqe = qhp->wq.sq.sw_sq[first_sq_idx];
  151. fsp = &first_sqe;
  152. last_sq_idx = wq.sq.pidx;
  153. if (last_sq_idx-- == 0)
  154. last_sq_idx = wq.sq.size - 1;
  155. if (last_sq_idx != first_sq_idx) {
  156. last_sqe = qhp->wq.sq.sw_sq[last_sq_idx];
  157. lsp = &last_sqe;
  158. }
  159. }
  160. spin_unlock_irq(&qhp->lock);
  161. if (fill_sq(msg, &wq))
  162. goto err_cancel_table;
  163. if (fill_swsqes(msg, &wq.sq, first_sq_idx, fsp, last_sq_idx, lsp))
  164. goto err_cancel_table;
  165. if (fill_rq(msg, &wq))
  166. goto err_cancel_table;
  167. nla_nest_end(msg, table_attr);
  168. return 0;
  169. err_cancel_table:
  170. nla_nest_cancel(msg, table_attr);
  171. err:
  172. return -EMSGSIZE;
  173. }
  174. union union_ep {
  175. struct c4iw_listen_ep lep;
  176. struct c4iw_ep ep;
  177. };
  178. int c4iw_fill_res_cm_id_entry(struct sk_buff *msg,
  179. struct rdma_cm_id *cm_id)
  180. {
  181. struct nlattr *table_attr;
  182. struct c4iw_ep_common *epcp;
  183. struct c4iw_listen_ep *listen_ep = NULL;
  184. struct c4iw_ep *ep = NULL;
  185. struct iw_cm_id *iw_cm_id;
  186. union union_ep *uep;
  187. iw_cm_id = rdma_iw_cm_id(cm_id);
  188. if (!iw_cm_id)
  189. return 0;
  190. epcp = (struct c4iw_ep_common *)iw_cm_id->provider_data;
  191. if (!epcp)
  192. return 0;
  193. uep = kzalloc(sizeof(*uep), GFP_KERNEL);
  194. if (!uep)
  195. return 0;
  196. table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
  197. if (!table_attr)
  198. goto err_free_uep;
  199. /* Get a consistent snapshot */
  200. mutex_lock(&epcp->mutex);
  201. if (epcp->state == LISTEN) {
  202. uep->lep = *(struct c4iw_listen_ep *)epcp;
  203. mutex_unlock(&epcp->mutex);
  204. listen_ep = &uep->lep;
  205. epcp = &listen_ep->com;
  206. } else {
  207. uep->ep = *(struct c4iw_ep *)epcp;
  208. mutex_unlock(&epcp->mutex);
  209. ep = &uep->ep;
  210. epcp = &ep->com;
  211. }
  212. if (rdma_nl_put_driver_u32(msg, "state", epcp->state))
  213. goto err_cancel_table;
  214. if (rdma_nl_put_driver_u64_hex(msg, "flags", epcp->flags))
  215. goto err_cancel_table;
  216. if (rdma_nl_put_driver_u64_hex(msg, "history", epcp->history))
  217. goto err_cancel_table;
  218. if (listen_ep) {
  219. if (rdma_nl_put_driver_u32(msg, "stid", listen_ep->stid))
  220. goto err_cancel_table;
  221. if (rdma_nl_put_driver_u32(msg, "backlog", listen_ep->backlog))
  222. goto err_cancel_table;
  223. } else {
  224. if (rdma_nl_put_driver_u32(msg, "hwtid", ep->hwtid))
  225. goto err_cancel_table;
  226. if (rdma_nl_put_driver_u32(msg, "ord", ep->ord))
  227. goto err_cancel_table;
  228. if (rdma_nl_put_driver_u32(msg, "ird", ep->ird))
  229. goto err_cancel_table;
  230. if (rdma_nl_put_driver_u32(msg, "emss", ep->emss))
  231. goto err_cancel_table;
  232. if (!ep->parent_ep && rdma_nl_put_driver_u32(msg, "atid",
  233. ep->atid))
  234. goto err_cancel_table;
  235. }
  236. nla_nest_end(msg, table_attr);
  237. kfree(uep);
  238. return 0;
  239. err_cancel_table:
  240. nla_nest_cancel(msg, table_attr);
  241. err_free_uep:
  242. kfree(uep);
  243. return -EMSGSIZE;
  244. }
  245. static int fill_cq(struct sk_buff *msg, struct t4_cq *cq)
  246. {
  247. if (rdma_nl_put_driver_u32(msg, "cqid", cq->cqid))
  248. goto err;
  249. if (rdma_nl_put_driver_u32(msg, "memsize", cq->memsize))
  250. goto err;
  251. if (rdma_nl_put_driver_u32(msg, "size", cq->size))
  252. goto err;
  253. if (rdma_nl_put_driver_u32(msg, "cidx", cq->cidx))
  254. goto err;
  255. if (rdma_nl_put_driver_u32(msg, "cidx_inc", cq->cidx_inc))
  256. goto err;
  257. if (rdma_nl_put_driver_u32(msg, "sw_cidx", cq->sw_cidx))
  258. goto err;
  259. if (rdma_nl_put_driver_u32(msg, "sw_pidx", cq->sw_pidx))
  260. goto err;
  261. if (rdma_nl_put_driver_u32(msg, "sw_in_use", cq->sw_in_use))
  262. goto err;
  263. if (rdma_nl_put_driver_u32(msg, "vector", cq->vector))
  264. goto err;
  265. if (rdma_nl_put_driver_u32(msg, "gen", cq->gen))
  266. goto err;
  267. if (rdma_nl_put_driver_u32(msg, "error", cq->error))
  268. goto err;
  269. if (rdma_nl_put_driver_u64_hex(msg, "bits_type_ts",
  270. be64_to_cpu(cq->bits_type_ts)))
  271. goto err;
  272. if (rdma_nl_put_driver_u64_hex(msg, "flags", cq->flags))
  273. goto err;
  274. return 0;
  275. err:
  276. return -EMSGSIZE;
  277. }
  278. static int fill_cqe(struct sk_buff *msg, struct t4_cqe *cqe, u16 idx,
  279. const char *qstr)
  280. {
  281. if (rdma_nl_put_driver_u32(msg, qstr, idx))
  282. goto err;
  283. if (rdma_nl_put_driver_u32_hex(msg, "header",
  284. be32_to_cpu(cqe->header)))
  285. goto err;
  286. if (rdma_nl_put_driver_u32(msg, "len", be32_to_cpu(cqe->len)))
  287. goto err;
  288. if (rdma_nl_put_driver_u32_hex(msg, "wrid_hi",
  289. be32_to_cpu(cqe->u.gen.wrid_hi)))
  290. goto err;
  291. if (rdma_nl_put_driver_u32_hex(msg, "wrid_low",
  292. be32_to_cpu(cqe->u.gen.wrid_low)))
  293. goto err;
  294. if (rdma_nl_put_driver_u64_hex(msg, "bits_type_ts",
  295. be64_to_cpu(cqe->bits_type_ts)))
  296. goto err;
  297. return 0;
  298. err:
  299. return -EMSGSIZE;
  300. }
  301. static int fill_hwcqes(struct sk_buff *msg, struct t4_cq *cq,
  302. struct t4_cqe *cqes)
  303. {
  304. u16 idx;
  305. idx = (cq->cidx > 0) ? cq->cidx - 1 : cq->size - 1;
  306. if (fill_cqe(msg, cqes, idx, "hwcq_idx"))
  307. goto err;
  308. idx = cq->cidx;
  309. if (fill_cqe(msg, cqes + 1, idx, "hwcq_idx"))
  310. goto err;
  311. return 0;
  312. err:
  313. return -EMSGSIZE;
  314. }
  315. static int fill_swcqes(struct sk_buff *msg, struct t4_cq *cq,
  316. struct t4_cqe *cqes)
  317. {
  318. u16 idx;
  319. if (!cq->sw_in_use)
  320. return 0;
  321. idx = cq->sw_cidx;
  322. if (fill_cqe(msg, cqes, idx, "swcq_idx"))
  323. goto err;
  324. if (cq->sw_in_use == 1)
  325. goto out;
  326. idx = (cq->sw_pidx > 0) ? cq->sw_pidx - 1 : cq->size - 1;
  327. if (fill_cqe(msg, cqes + 1, idx, "swcq_idx"))
  328. goto err;
  329. out:
  330. return 0;
  331. err:
  332. return -EMSGSIZE;
  333. }
  334. int c4iw_fill_res_cq_entry(struct sk_buff *msg, struct ib_cq *ibcq)
  335. {
  336. struct c4iw_cq *chp = to_c4iw_cq(ibcq);
  337. struct nlattr *table_attr;
  338. struct t4_cqe hwcqes[2];
  339. struct t4_cqe swcqes[2];
  340. struct t4_cq cq;
  341. u16 idx;
  342. /* User cq state is not available, so don't dump user cqs */
  343. if (ibcq->uobject)
  344. return 0;
  345. table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
  346. if (!table_attr)
  347. goto err;
  348. /* Get a consistent snapshot */
  349. spin_lock_irq(&chp->lock);
  350. /* t4_cq struct */
  351. cq = chp->cq;
  352. /* get 2 hw cqes: cidx-1, and cidx */
  353. idx = (cq.cidx > 0) ? cq.cidx - 1 : cq.size - 1;
  354. hwcqes[0] = chp->cq.queue[idx];
  355. idx = cq.cidx;
  356. hwcqes[1] = chp->cq.queue[idx];
  357. /* get first and last sw cqes */
  358. if (cq.sw_in_use) {
  359. swcqes[0] = chp->cq.sw_queue[cq.sw_cidx];
  360. if (cq.sw_in_use > 1) {
  361. idx = (cq.sw_pidx > 0) ? cq.sw_pidx - 1 : cq.size - 1;
  362. swcqes[1] = chp->cq.sw_queue[idx];
  363. }
  364. }
  365. spin_unlock_irq(&chp->lock);
  366. if (fill_cq(msg, &cq))
  367. goto err_cancel_table;
  368. if (fill_swcqes(msg, &cq, swcqes))
  369. goto err_cancel_table;
  370. if (fill_hwcqes(msg, &cq, hwcqes))
  371. goto err_cancel_table;
  372. nla_nest_end(msg, table_attr);
  373. return 0;
  374. err_cancel_table:
  375. nla_nest_cancel(msg, table_attr);
  376. err:
  377. return -EMSGSIZE;
  378. }
  379. int c4iw_fill_res_mr_entry(struct sk_buff *msg, struct ib_mr *ibmr)
  380. {
  381. struct c4iw_mr *mhp = to_c4iw_mr(ibmr);
  382. struct c4iw_dev *dev = mhp->rhp;
  383. u32 stag = mhp->attr.stag;
  384. struct nlattr *table_attr;
  385. struct fw_ri_tpte tpte;
  386. int ret;
  387. if (!stag)
  388. return 0;
  389. table_attr = nla_nest_start_noflag(msg, RDMA_NLDEV_ATTR_DRIVER);
  390. if (!table_attr)
  391. goto err;
  392. ret = cxgb4_read_tpte(dev->rdev.lldi.ports[0], stag, (__be32 *)&tpte);
  393. if (ret) {
  394. dev_err(&dev->rdev.lldi.pdev->dev,
  395. "%s cxgb4_read_tpte err %d\n", __func__, ret);
  396. return 0;
  397. }
  398. if (rdma_nl_put_driver_u32_hex(msg, "idx", stag >> 8))
  399. goto err_cancel_table;
  400. if (rdma_nl_put_driver_u32(msg, "valid",
  401. FW_RI_TPTE_VALID_G(ntohl(tpte.valid_to_pdid))))
  402. goto err_cancel_table;
  403. if (rdma_nl_put_driver_u32_hex(msg, "key", stag & 0xff))
  404. goto err_cancel_table;
  405. if (rdma_nl_put_driver_u32(msg, "state",
  406. FW_RI_TPTE_STAGSTATE_G(ntohl(tpte.valid_to_pdid))))
  407. goto err_cancel_table;
  408. if (rdma_nl_put_driver_u32(msg, "pdid",
  409. FW_RI_TPTE_PDID_G(ntohl(tpte.valid_to_pdid))))
  410. goto err_cancel_table;
  411. if (rdma_nl_put_driver_u32_hex(msg, "perm",
  412. FW_RI_TPTE_PERM_G(ntohl(tpte.locread_to_qpid))))
  413. goto err_cancel_table;
  414. if (rdma_nl_put_driver_u32(msg, "ps",
  415. FW_RI_TPTE_PS_G(ntohl(tpte.locread_to_qpid))))
  416. goto err_cancel_table;
  417. if (rdma_nl_put_driver_u64(msg, "len",
  418. ((u64)ntohl(tpte.len_hi) << 32) | ntohl(tpte.len_lo)))
  419. goto err_cancel_table;
  420. if (rdma_nl_put_driver_u32_hex(msg, "pbl_addr",
  421. FW_RI_TPTE_PBLADDR_G(ntohl(tpte.nosnoop_pbladdr))))
  422. goto err_cancel_table;
  423. nla_nest_end(msg, table_attr);
  424. return 0;
  425. err_cancel_table:
  426. nla_nest_cancel(msg, table_attr);
  427. err:
  428. return -EMSGSIZE;
  429. }