qp.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*
  2. * Copyright(c) 2015 - 2018 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/err.h>
  48. #include <linux/vmalloc.h>
  49. #include <linux/hash.h>
  50. #include <linux/module.h>
  51. #include <linux/seq_file.h>
  52. #include <rdma/rdma_vt.h>
  53. #include <rdma/rdmavt_qp.h>
  54. #include <rdma/ib_verbs.h>
  55. #include "hfi.h"
  56. #include "qp.h"
  57. #include "trace.h"
  58. #include "verbs_txreq.h"
  59. unsigned int hfi1_qp_table_size = 256;
  60. module_param_named(qp_table_size, hfi1_qp_table_size, uint, S_IRUGO);
  61. MODULE_PARM_DESC(qp_table_size, "QP table size");
  62. static void flush_tx_list(struct rvt_qp *qp);
  63. static int iowait_sleep(
  64. struct sdma_engine *sde,
  65. struct iowait *wait,
  66. struct sdma_txreq *stx,
  67. unsigned int seq,
  68. bool pkts_sent);
  69. static void iowait_wakeup(struct iowait *wait, int reason);
  70. static void iowait_sdma_drained(struct iowait *wait);
  71. static void qp_pio_drain(struct rvt_qp *qp);
  72. const struct rvt_operation_params hfi1_post_parms[RVT_OPERATION_MAX] = {
  73. [IB_WR_RDMA_WRITE] = {
  74. .length = sizeof(struct ib_rdma_wr),
  75. .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  76. },
  77. [IB_WR_RDMA_READ] = {
  78. .length = sizeof(struct ib_rdma_wr),
  79. .qpt_support = BIT(IB_QPT_RC),
  80. .flags = RVT_OPERATION_ATOMIC,
  81. },
  82. [IB_WR_ATOMIC_CMP_AND_SWP] = {
  83. .length = sizeof(struct ib_atomic_wr),
  84. .qpt_support = BIT(IB_QPT_RC),
  85. .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
  86. },
  87. [IB_WR_ATOMIC_FETCH_AND_ADD] = {
  88. .length = sizeof(struct ib_atomic_wr),
  89. .qpt_support = BIT(IB_QPT_RC),
  90. .flags = RVT_OPERATION_ATOMIC | RVT_OPERATION_ATOMIC_SGE,
  91. },
  92. [IB_WR_RDMA_WRITE_WITH_IMM] = {
  93. .length = sizeof(struct ib_rdma_wr),
  94. .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  95. },
  96. [IB_WR_SEND] = {
  97. .length = sizeof(struct ib_send_wr),
  98. .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
  99. BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  100. },
  101. [IB_WR_SEND_WITH_IMM] = {
  102. .length = sizeof(struct ib_send_wr),
  103. .qpt_support = BIT(IB_QPT_UD) | BIT(IB_QPT_SMI) | BIT(IB_QPT_GSI) |
  104. BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  105. },
  106. [IB_WR_REG_MR] = {
  107. .length = sizeof(struct ib_reg_wr),
  108. .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  109. .flags = RVT_OPERATION_LOCAL,
  110. },
  111. [IB_WR_LOCAL_INV] = {
  112. .length = sizeof(struct ib_send_wr),
  113. .qpt_support = BIT(IB_QPT_UC) | BIT(IB_QPT_RC),
  114. .flags = RVT_OPERATION_LOCAL,
  115. },
  116. [IB_WR_SEND_WITH_INV] = {
  117. .length = sizeof(struct ib_send_wr),
  118. .qpt_support = BIT(IB_QPT_RC),
  119. },
  120. };
  121. static void flush_tx_list(struct rvt_qp *qp)
  122. {
  123. struct hfi1_qp_priv *priv = qp->priv;
  124. while (!list_empty(&priv->s_iowait.tx_head)) {
  125. struct sdma_txreq *tx;
  126. tx = list_first_entry(
  127. &priv->s_iowait.tx_head,
  128. struct sdma_txreq,
  129. list);
  130. list_del_init(&tx->list);
  131. hfi1_put_txreq(
  132. container_of(tx, struct verbs_txreq, txreq));
  133. }
  134. }
  135. static void flush_iowait(struct rvt_qp *qp)
  136. {
  137. struct hfi1_qp_priv *priv = qp->priv;
  138. unsigned long flags;
  139. seqlock_t *lock = priv->s_iowait.lock;
  140. if (!lock)
  141. return;
  142. write_seqlock_irqsave(lock, flags);
  143. if (!list_empty(&priv->s_iowait.list)) {
  144. list_del_init(&priv->s_iowait.list);
  145. priv->s_iowait.lock = NULL;
  146. rvt_put_qp(qp);
  147. }
  148. write_sequnlock_irqrestore(lock, flags);
  149. }
  150. static inline int opa_mtu_enum_to_int(int mtu)
  151. {
  152. switch (mtu) {
  153. case OPA_MTU_8192: return 8192;
  154. case OPA_MTU_10240: return 10240;
  155. default: return -1;
  156. }
  157. }
  158. /**
  159. * This function is what we would push to the core layer if we wanted to be a
  160. * "first class citizen". Instead we hide this here and rely on Verbs ULPs
  161. * to blindly pass the MTU enum value from the PathRecord to us.
  162. */
  163. static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu)
  164. {
  165. int val;
  166. /* Constraining 10KB packets to 8KB packets */
  167. if (mtu == (enum ib_mtu)OPA_MTU_10240)
  168. mtu = OPA_MTU_8192;
  169. val = opa_mtu_enum_to_int((int)mtu);
  170. if (val > 0)
  171. return val;
  172. return ib_mtu_enum_to_int(mtu);
  173. }
  174. int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  175. int attr_mask, struct ib_udata *udata)
  176. {
  177. struct ib_qp *ibqp = &qp->ibqp;
  178. struct hfi1_ibdev *dev = to_idev(ibqp->device);
  179. struct hfi1_devdata *dd = dd_from_dev(dev);
  180. u8 sc;
  181. if (attr_mask & IB_QP_AV) {
  182. sc = ah_to_sc(ibqp->device, &attr->ah_attr);
  183. if (sc == 0xf)
  184. return -EINVAL;
  185. if (!qp_to_sdma_engine(qp, sc) &&
  186. dd->flags & HFI1_HAS_SEND_DMA)
  187. return -EINVAL;
  188. if (!qp_to_send_context(qp, sc))
  189. return -EINVAL;
  190. }
  191. if (attr_mask & IB_QP_ALT_PATH) {
  192. sc = ah_to_sc(ibqp->device, &attr->alt_ah_attr);
  193. if (sc == 0xf)
  194. return -EINVAL;
  195. if (!qp_to_sdma_engine(qp, sc) &&
  196. dd->flags & HFI1_HAS_SEND_DMA)
  197. return -EINVAL;
  198. if (!qp_to_send_context(qp, sc))
  199. return -EINVAL;
  200. }
  201. return 0;
  202. }
  203. /*
  204. * qp_set_16b - Set the hdr_type based on whether the slid or the
  205. * dlid in the connection is extended. Only applicable for RC and UC
  206. * QPs. UD QPs determine this on the fly from the ah in the wqe
  207. */
  208. static inline void qp_set_16b(struct rvt_qp *qp)
  209. {
  210. struct hfi1_pportdata *ppd;
  211. struct hfi1_ibport *ibp;
  212. struct hfi1_qp_priv *priv = qp->priv;
  213. /* Update ah_attr to account for extended LIDs */
  214. hfi1_update_ah_attr(qp->ibqp.device, &qp->remote_ah_attr);
  215. /* Create 32 bit LIDs */
  216. hfi1_make_opa_lid(&qp->remote_ah_attr);
  217. if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH))
  218. return;
  219. ibp = to_iport(qp->ibqp.device, qp->port_num);
  220. ppd = ppd_from_ibp(ibp);
  221. priv->hdr_type = hfi1_get_hdr_type(ppd->lid, &qp->remote_ah_attr);
  222. }
  223. void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  224. int attr_mask, struct ib_udata *udata)
  225. {
  226. struct ib_qp *ibqp = &qp->ibqp;
  227. struct hfi1_qp_priv *priv = qp->priv;
  228. if (attr_mask & IB_QP_AV) {
  229. priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
  230. priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
  231. priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
  232. qp_set_16b(qp);
  233. }
  234. if (attr_mask & IB_QP_PATH_MIG_STATE &&
  235. attr->path_mig_state == IB_MIG_MIGRATED &&
  236. qp->s_mig_state == IB_MIG_ARMED) {
  237. qp->s_flags |= HFI1_S_AHG_CLEAR;
  238. priv->s_sc = ah_to_sc(ibqp->device, &qp->remote_ah_attr);
  239. priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
  240. priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
  241. qp_set_16b(qp);
  242. }
  243. }
  244. /**
  245. * hfi1_check_send_wqe - validate wqe
  246. * @qp - The qp
  247. * @wqe - The built wqe
  248. *
  249. * validate wqe. This is called
  250. * prior to inserting the wqe into
  251. * the ring but after the wqe has been
  252. * setup.
  253. *
  254. * Returns 0 on success, -EINVAL on failure
  255. *
  256. */
  257. int hfi1_check_send_wqe(struct rvt_qp *qp,
  258. struct rvt_swqe *wqe)
  259. {
  260. struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  261. struct rvt_ah *ah;
  262. switch (qp->ibqp.qp_type) {
  263. case IB_QPT_RC:
  264. case IB_QPT_UC:
  265. if (wqe->length > 0x80000000U)
  266. return -EINVAL;
  267. break;
  268. case IB_QPT_SMI:
  269. ah = ibah_to_rvtah(wqe->ud_wr.ah);
  270. if (wqe->length > (1 << ah->log_pmtu))
  271. return -EINVAL;
  272. break;
  273. case IB_QPT_GSI:
  274. case IB_QPT_UD:
  275. ah = ibah_to_rvtah(wqe->ud_wr.ah);
  276. if (wqe->length > (1 << ah->log_pmtu))
  277. return -EINVAL;
  278. if (ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)] == 0xf)
  279. return -EINVAL;
  280. default:
  281. break;
  282. }
  283. return wqe->length <= piothreshold;
  284. }
  285. /**
  286. * _hfi1_schedule_send - schedule progress
  287. * @qp: the QP
  288. *
  289. * This schedules qp progress w/o regard to the s_flags.
  290. *
  291. * It is only used in the post send, which doesn't hold
  292. * the s_lock.
  293. */
  294. void _hfi1_schedule_send(struct rvt_qp *qp)
  295. {
  296. struct hfi1_qp_priv *priv = qp->priv;
  297. struct hfi1_ibport *ibp =
  298. to_iport(qp->ibqp.device, qp->port_num);
  299. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  300. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  301. iowait_schedule(&priv->s_iowait, ppd->hfi1_wq,
  302. priv->s_sde ?
  303. priv->s_sde->cpu :
  304. cpumask_first(cpumask_of_node(dd->node)));
  305. }
  306. static void qp_pio_drain(struct rvt_qp *qp)
  307. {
  308. struct hfi1_ibdev *dev;
  309. struct hfi1_qp_priv *priv = qp->priv;
  310. if (!priv->s_sendcontext)
  311. return;
  312. dev = to_idev(qp->ibqp.device);
  313. while (iowait_pio_pending(&priv->s_iowait)) {
  314. write_seqlock_irq(&dev->iowait_lock);
  315. hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 1);
  316. write_sequnlock_irq(&dev->iowait_lock);
  317. iowait_pio_drain(&priv->s_iowait);
  318. write_seqlock_irq(&dev->iowait_lock);
  319. hfi1_sc_wantpiobuf_intr(priv->s_sendcontext, 0);
  320. write_sequnlock_irq(&dev->iowait_lock);
  321. }
  322. }
  323. /**
  324. * hfi1_schedule_send - schedule progress
  325. * @qp: the QP
  326. *
  327. * This schedules qp progress and caller should hold
  328. * the s_lock.
  329. */
  330. void hfi1_schedule_send(struct rvt_qp *qp)
  331. {
  332. lockdep_assert_held(&qp->s_lock);
  333. if (hfi1_send_ok(qp))
  334. _hfi1_schedule_send(qp);
  335. }
  336. void hfi1_qp_wakeup(struct rvt_qp *qp, u32 flag)
  337. {
  338. unsigned long flags;
  339. spin_lock_irqsave(&qp->s_lock, flags);
  340. if (qp->s_flags & flag) {
  341. qp->s_flags &= ~flag;
  342. trace_hfi1_qpwakeup(qp, flag);
  343. hfi1_schedule_send(qp);
  344. }
  345. spin_unlock_irqrestore(&qp->s_lock, flags);
  346. /* Notify hfi1_destroy_qp() if it is waiting. */
  347. rvt_put_qp(qp);
  348. }
  349. static int iowait_sleep(
  350. struct sdma_engine *sde,
  351. struct iowait *wait,
  352. struct sdma_txreq *stx,
  353. uint seq,
  354. bool pkts_sent)
  355. {
  356. struct verbs_txreq *tx = container_of(stx, struct verbs_txreq, txreq);
  357. struct rvt_qp *qp;
  358. struct hfi1_qp_priv *priv;
  359. unsigned long flags;
  360. int ret = 0;
  361. struct hfi1_ibdev *dev;
  362. qp = tx->qp;
  363. priv = qp->priv;
  364. spin_lock_irqsave(&qp->s_lock, flags);
  365. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  366. /*
  367. * If we couldn't queue the DMA request, save the info
  368. * and try again later rather than destroying the
  369. * buffer and undoing the side effects of the copy.
  370. */
  371. /* Make a common routine? */
  372. dev = &sde->dd->verbs_dev;
  373. list_add_tail(&stx->list, &wait->tx_head);
  374. write_seqlock(&dev->iowait_lock);
  375. if (sdma_progress(sde, seq, stx))
  376. goto eagain;
  377. if (list_empty(&priv->s_iowait.list)) {
  378. struct hfi1_ibport *ibp =
  379. to_iport(qp->ibqp.device, qp->port_num);
  380. ibp->rvp.n_dmawait++;
  381. qp->s_flags |= RVT_S_WAIT_DMA_DESC;
  382. iowait_queue(pkts_sent, &priv->s_iowait,
  383. &sde->dmawait);
  384. priv->s_iowait.lock = &dev->iowait_lock;
  385. trace_hfi1_qpsleep(qp, RVT_S_WAIT_DMA_DESC);
  386. rvt_get_qp(qp);
  387. }
  388. write_sequnlock(&dev->iowait_lock);
  389. qp->s_flags &= ~RVT_S_BUSY;
  390. spin_unlock_irqrestore(&qp->s_lock, flags);
  391. ret = -EBUSY;
  392. } else {
  393. spin_unlock_irqrestore(&qp->s_lock, flags);
  394. hfi1_put_txreq(tx);
  395. }
  396. return ret;
  397. eagain:
  398. write_sequnlock(&dev->iowait_lock);
  399. spin_unlock_irqrestore(&qp->s_lock, flags);
  400. list_del_init(&stx->list);
  401. return -EAGAIN;
  402. }
  403. static void iowait_wakeup(struct iowait *wait, int reason)
  404. {
  405. struct rvt_qp *qp = iowait_to_qp(wait);
  406. WARN_ON(reason != SDMA_AVAIL_REASON);
  407. hfi1_qp_wakeup(qp, RVT_S_WAIT_DMA_DESC);
  408. }
  409. static void iowait_sdma_drained(struct iowait *wait)
  410. {
  411. struct rvt_qp *qp = iowait_to_qp(wait);
  412. unsigned long flags;
  413. /*
  414. * This happens when the send engine notes
  415. * a QP in the error state and cannot
  416. * do the flush work until that QP's
  417. * sdma work has finished.
  418. */
  419. spin_lock_irqsave(&qp->s_lock, flags);
  420. if (qp->s_flags & RVT_S_WAIT_DMA) {
  421. qp->s_flags &= ~RVT_S_WAIT_DMA;
  422. hfi1_schedule_send(qp);
  423. }
  424. spin_unlock_irqrestore(&qp->s_lock, flags);
  425. }
  426. /**
  427. * qp_to_sdma_engine - map a qp to a send engine
  428. * @qp: the QP
  429. * @sc5: the 5 bit sc
  430. *
  431. * Return:
  432. * A send engine for the qp or NULL for SMI type qp.
  433. */
  434. struct sdma_engine *qp_to_sdma_engine(struct rvt_qp *qp, u8 sc5)
  435. {
  436. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  437. struct sdma_engine *sde;
  438. if (!(dd->flags & HFI1_HAS_SEND_DMA))
  439. return NULL;
  440. switch (qp->ibqp.qp_type) {
  441. case IB_QPT_SMI:
  442. return NULL;
  443. default:
  444. break;
  445. }
  446. sde = sdma_select_engine_sc(dd, qp->ibqp.qp_num >> dd->qos_shift, sc5);
  447. return sde;
  448. }
  449. /*
  450. * qp_to_send_context - map a qp to a send context
  451. * @qp: the QP
  452. * @sc5: the 5 bit sc
  453. *
  454. * Return:
  455. * A send context for the qp
  456. */
  457. struct send_context *qp_to_send_context(struct rvt_qp *qp, u8 sc5)
  458. {
  459. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  460. switch (qp->ibqp.qp_type) {
  461. case IB_QPT_SMI:
  462. /* SMA packets to VL15 */
  463. return dd->vld[15].sc;
  464. default:
  465. break;
  466. }
  467. return pio_select_send_context_sc(dd, qp->ibqp.qp_num >> dd->qos_shift,
  468. sc5);
  469. }
  470. static const char * const qp_type_str[] = {
  471. "SMI", "GSI", "RC", "UC", "UD",
  472. };
  473. static int qp_idle(struct rvt_qp *qp)
  474. {
  475. return
  476. qp->s_last == qp->s_acked &&
  477. qp->s_acked == qp->s_cur &&
  478. qp->s_cur == qp->s_tail &&
  479. qp->s_tail == qp->s_head;
  480. }
  481. /**
  482. * qp_iter_print - print the qp information to seq_file
  483. * @s: the seq_file to emit the qp information on
  484. * @iter: the iterator for the qp hash list
  485. */
  486. void qp_iter_print(struct seq_file *s, struct rvt_qp_iter *iter)
  487. {
  488. struct rvt_swqe *wqe;
  489. struct rvt_qp *qp = iter->qp;
  490. struct hfi1_qp_priv *priv = qp->priv;
  491. struct sdma_engine *sde;
  492. struct send_context *send_context;
  493. struct rvt_ack_entry *e = NULL;
  494. struct rvt_srq *srq = qp->ibqp.srq ?
  495. ibsrq_to_rvtsrq(qp->ibqp.srq) : NULL;
  496. sde = qp_to_sdma_engine(qp, priv->s_sc);
  497. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  498. send_context = qp_to_send_context(qp, priv->s_sc);
  499. if (qp->s_ack_queue)
  500. e = &qp->s_ack_queue[qp->s_tail_ack_queue];
  501. seq_printf(s,
  502. "N %d %s QP %x R %u %s %u %u f=%x %u %u %u %u %u %u SPSN %x %x %x %x %x RPSN %x S(%u %u %u %u %u %u %u) R(%u %u %u) RQP %x LID %x SL %u MTU %u %u %u %u %u SDE %p,%u SC %p,%u SCQ %u %u PID %d OS %x %x E %x %x %x RNR %d %s %d\n",
  503. iter->n,
  504. qp_idle(qp) ? "I" : "B",
  505. qp->ibqp.qp_num,
  506. atomic_read(&qp->refcount),
  507. qp_type_str[qp->ibqp.qp_type],
  508. qp->state,
  509. wqe ? wqe->wr.opcode : 0,
  510. qp->s_flags,
  511. iowait_sdma_pending(&priv->s_iowait),
  512. iowait_pio_pending(&priv->s_iowait),
  513. !list_empty(&priv->s_iowait.list),
  514. qp->timeout,
  515. wqe ? wqe->ssn : 0,
  516. qp->s_lsn,
  517. qp->s_last_psn,
  518. qp->s_psn, qp->s_next_psn,
  519. qp->s_sending_psn, qp->s_sending_hpsn,
  520. qp->r_psn,
  521. qp->s_last, qp->s_acked, qp->s_cur,
  522. qp->s_tail, qp->s_head, qp->s_size,
  523. qp->s_avail,
  524. /* ack_queue ring pointers, size */
  525. qp->s_tail_ack_queue, qp->r_head_ack_queue,
  526. rvt_max_atomic(&to_idev(qp->ibqp.device)->rdi),
  527. /* remote QP info */
  528. qp->remote_qpn,
  529. rdma_ah_get_dlid(&qp->remote_ah_attr),
  530. rdma_ah_get_sl(&qp->remote_ah_attr),
  531. qp->pmtu,
  532. qp->s_retry,
  533. qp->s_retry_cnt,
  534. qp->s_rnr_retry_cnt,
  535. qp->s_rnr_retry,
  536. sde,
  537. sde ? sde->this_idx : 0,
  538. send_context,
  539. send_context ? send_context->sw_index : 0,
  540. ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->head,
  541. ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->tail,
  542. qp->pid,
  543. qp->s_state,
  544. qp->s_ack_state,
  545. /* ack queue information */
  546. e ? e->opcode : 0,
  547. e ? e->psn : 0,
  548. e ? e->lpsn : 0,
  549. qp->r_min_rnr_timer,
  550. srq ? "SRQ" : "RQ",
  551. srq ? srq->rq.size : qp->r_rq.size
  552. );
  553. }
  554. void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp)
  555. {
  556. struct hfi1_qp_priv *priv;
  557. priv = kzalloc_node(sizeof(*priv), GFP_KERNEL, rdi->dparms.node);
  558. if (!priv)
  559. return ERR_PTR(-ENOMEM);
  560. priv->owner = qp;
  561. priv->s_ahg = kzalloc_node(sizeof(*priv->s_ahg), GFP_KERNEL,
  562. rdi->dparms.node);
  563. if (!priv->s_ahg) {
  564. kfree(priv);
  565. return ERR_PTR(-ENOMEM);
  566. }
  567. iowait_init(
  568. &priv->s_iowait,
  569. 1,
  570. _hfi1_do_send,
  571. iowait_sleep,
  572. iowait_wakeup,
  573. iowait_sdma_drained);
  574. return priv;
  575. }
  576. void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp)
  577. {
  578. struct hfi1_qp_priv *priv = qp->priv;
  579. kfree(priv->s_ahg);
  580. kfree(priv);
  581. }
  582. unsigned free_all_qps(struct rvt_dev_info *rdi)
  583. {
  584. struct hfi1_ibdev *verbs_dev = container_of(rdi,
  585. struct hfi1_ibdev,
  586. rdi);
  587. struct hfi1_devdata *dd = container_of(verbs_dev,
  588. struct hfi1_devdata,
  589. verbs_dev);
  590. int n;
  591. unsigned qp_inuse = 0;
  592. for (n = 0; n < dd->num_pports; n++) {
  593. struct hfi1_ibport *ibp = &dd->pport[n].ibport_data;
  594. rcu_read_lock();
  595. if (rcu_dereference(ibp->rvp.qp[0]))
  596. qp_inuse++;
  597. if (rcu_dereference(ibp->rvp.qp[1]))
  598. qp_inuse++;
  599. rcu_read_unlock();
  600. }
  601. return qp_inuse;
  602. }
  603. void flush_qp_waiters(struct rvt_qp *qp)
  604. {
  605. lockdep_assert_held(&qp->s_lock);
  606. flush_iowait(qp);
  607. }
  608. void stop_send_queue(struct rvt_qp *qp)
  609. {
  610. struct hfi1_qp_priv *priv = qp->priv;
  611. cancel_work_sync(&priv->s_iowait.iowork);
  612. }
  613. void quiesce_qp(struct rvt_qp *qp)
  614. {
  615. struct hfi1_qp_priv *priv = qp->priv;
  616. iowait_sdma_drain(&priv->s_iowait);
  617. qp_pio_drain(qp);
  618. flush_tx_list(qp);
  619. }
  620. void notify_qp_reset(struct rvt_qp *qp)
  621. {
  622. qp->r_adefered = 0;
  623. clear_ahg(qp);
  624. }
  625. /*
  626. * Switch to alternate path.
  627. * The QP s_lock should be held and interrupts disabled.
  628. */
  629. void hfi1_migrate_qp(struct rvt_qp *qp)
  630. {
  631. struct hfi1_qp_priv *priv = qp->priv;
  632. struct ib_event ev;
  633. qp->s_mig_state = IB_MIG_MIGRATED;
  634. qp->remote_ah_attr = qp->alt_ah_attr;
  635. qp->port_num = rdma_ah_get_port_num(&qp->alt_ah_attr);
  636. qp->s_pkey_index = qp->s_alt_pkey_index;
  637. qp->s_flags |= HFI1_S_AHG_CLEAR;
  638. priv->s_sc = ah_to_sc(qp->ibqp.device, &qp->remote_ah_attr);
  639. priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
  640. qp_set_16b(qp);
  641. ev.device = qp->ibqp.device;
  642. ev.element.qp = &qp->ibqp;
  643. ev.event = IB_EVENT_PATH_MIG;
  644. qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
  645. }
  646. int mtu_to_path_mtu(u32 mtu)
  647. {
  648. return mtu_to_enum(mtu, OPA_MTU_8192);
  649. }
  650. u32 mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu)
  651. {
  652. u32 mtu;
  653. struct hfi1_ibdev *verbs_dev = container_of(rdi,
  654. struct hfi1_ibdev,
  655. rdi);
  656. struct hfi1_devdata *dd = container_of(verbs_dev,
  657. struct hfi1_devdata,
  658. verbs_dev);
  659. struct hfi1_ibport *ibp;
  660. u8 sc, vl;
  661. ibp = &dd->pport[qp->port_num - 1].ibport_data;
  662. sc = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
  663. vl = sc_to_vlt(dd, sc);
  664. mtu = verbs_mtu_enum_to_int(qp->ibqp.device, pmtu);
  665. if (vl < PER_VL_SEND_CONTEXTS)
  666. mtu = min_t(u32, mtu, dd->vld[vl].mtu);
  667. return mtu;
  668. }
  669. int get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
  670. struct ib_qp_attr *attr)
  671. {
  672. int mtu, pidx = qp->port_num - 1;
  673. struct hfi1_ibdev *verbs_dev = container_of(rdi,
  674. struct hfi1_ibdev,
  675. rdi);
  676. struct hfi1_devdata *dd = container_of(verbs_dev,
  677. struct hfi1_devdata,
  678. verbs_dev);
  679. mtu = verbs_mtu_enum_to_int(qp->ibqp.device, attr->path_mtu);
  680. if (mtu == -1)
  681. return -1; /* values less than 0 are error */
  682. if (mtu > dd->pport[pidx].ibmtu)
  683. return mtu_to_enum(dd->pport[pidx].ibmtu, IB_MTU_2048);
  684. else
  685. return attr->path_mtu;
  686. }
  687. void notify_error_qp(struct rvt_qp *qp)
  688. {
  689. struct hfi1_qp_priv *priv = qp->priv;
  690. seqlock_t *lock = priv->s_iowait.lock;
  691. if (lock) {
  692. write_seqlock(lock);
  693. if (!list_empty(&priv->s_iowait.list) &&
  694. !(qp->s_flags & RVT_S_BUSY)) {
  695. qp->s_flags &= ~HFI1_S_ANY_WAIT_IO;
  696. list_del_init(&priv->s_iowait.list);
  697. priv->s_iowait.lock = NULL;
  698. rvt_put_qp(qp);
  699. }
  700. write_sequnlock(lock);
  701. }
  702. if (!(qp->s_flags & RVT_S_BUSY)) {
  703. if (qp->s_rdma_mr) {
  704. rvt_put_mr(qp->s_rdma_mr);
  705. qp->s_rdma_mr = NULL;
  706. }
  707. flush_tx_list(qp);
  708. }
  709. }
  710. /**
  711. * hfi1_qp_iter_cb - callback for iterator
  712. * @qp - the qp
  713. * @v - the sl in low bits of v
  714. *
  715. * This is called from the iterator callback to work
  716. * on an individual qp.
  717. */
  718. static void hfi1_qp_iter_cb(struct rvt_qp *qp, u64 v)
  719. {
  720. int lastwqe;
  721. struct ib_event ev;
  722. struct hfi1_ibport *ibp =
  723. to_iport(qp->ibqp.device, qp->port_num);
  724. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  725. u8 sl = (u8)v;
  726. if (qp->port_num != ppd->port ||
  727. (qp->ibqp.qp_type != IB_QPT_UC &&
  728. qp->ibqp.qp_type != IB_QPT_RC) ||
  729. rdma_ah_get_sl(&qp->remote_ah_attr) != sl ||
  730. !(ib_rvt_state_ops[qp->state] & RVT_POST_SEND_OK))
  731. return;
  732. spin_lock_irq(&qp->r_lock);
  733. spin_lock(&qp->s_hlock);
  734. spin_lock(&qp->s_lock);
  735. lastwqe = rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  736. spin_unlock(&qp->s_lock);
  737. spin_unlock(&qp->s_hlock);
  738. spin_unlock_irq(&qp->r_lock);
  739. if (lastwqe) {
  740. ev.device = qp->ibqp.device;
  741. ev.element.qp = &qp->ibqp;
  742. ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
  743. qp->ibqp.event_handler(&ev, qp->ibqp.qp_context);
  744. }
  745. }
  746. /**
  747. * hfi1_error_port_qps - put a port's RC/UC qps into error state
  748. * @ibp: the ibport.
  749. * @sl: the service level.
  750. *
  751. * This function places all RC/UC qps with a given service level into error
  752. * state. It is generally called to force upper lay apps to abandon stale qps
  753. * after an sl->sc mapping change.
  754. */
  755. void hfi1_error_port_qps(struct hfi1_ibport *ibp, u8 sl)
  756. {
  757. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  758. struct hfi1_ibdev *dev = &ppd->dd->verbs_dev;
  759. rvt_qp_iter(&dev->rdi, sl, hfi1_qp_iter_cb);
  760. }