verbs_txreq.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
  2. /*
  3. * Copyright(c) 2016 - 2018 Intel Corporation.
  4. */
  5. #include "hfi.h"
  6. #include "verbs_txreq.h"
  7. #include "qp.h"
  8. #include "trace.h"
  9. #define TXREQ_LEN 24
  10. void hfi1_put_txreq(struct verbs_txreq *tx)
  11. {
  12. struct hfi1_ibdev *dev;
  13. struct rvt_qp *qp;
  14. unsigned long flags;
  15. unsigned int seq;
  16. struct hfi1_qp_priv *priv;
  17. qp = tx->qp;
  18. dev = to_idev(qp->ibqp.device);
  19. if (tx->mr)
  20. rvt_put_mr(tx->mr);
  21. sdma_txclean(dd_from_dev(dev), &tx->txreq);
  22. /* Free verbs_txreq and return to slab cache */
  23. kmem_cache_free(dev->verbs_txreq_cache, tx);
  24. do {
  25. seq = read_seqbegin(&dev->txwait_lock);
  26. if (!list_empty(&dev->txwait)) {
  27. struct iowait *wait;
  28. write_seqlock_irqsave(&dev->txwait_lock, flags);
  29. wait = list_first_entry(&dev->txwait, struct iowait,
  30. list);
  31. qp = iowait_to_qp(wait);
  32. priv = qp->priv;
  33. list_del_init(&priv->s_iowait.list);
  34. /* refcount held until actual wake up */
  35. write_sequnlock_irqrestore(&dev->txwait_lock, flags);
  36. hfi1_qp_wakeup(qp, RVT_S_WAIT_TX);
  37. break;
  38. }
  39. } while (read_seqretry(&dev->txwait_lock, seq));
  40. }
  41. struct verbs_txreq *__get_txreq(struct hfi1_ibdev *dev,
  42. struct rvt_qp *qp)
  43. __must_hold(&qp->s_lock)
  44. {
  45. struct verbs_txreq *tx = NULL;
  46. write_seqlock(&dev->txwait_lock);
  47. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  48. struct hfi1_qp_priv *priv;
  49. tx = kmem_cache_alloc(dev->verbs_txreq_cache, VERBS_TXREQ_GFP);
  50. if (tx)
  51. goto out;
  52. priv = qp->priv;
  53. if (list_empty(&priv->s_iowait.list)) {
  54. dev->n_txwait++;
  55. qp->s_flags |= RVT_S_WAIT_TX;
  56. list_add_tail(&priv->s_iowait.list, &dev->txwait);
  57. priv->s_iowait.lock = &dev->txwait_lock;
  58. trace_hfi1_qpsleep(qp, RVT_S_WAIT_TX);
  59. rvt_get_qp(qp);
  60. }
  61. qp->s_flags &= ~RVT_S_BUSY;
  62. }
  63. out:
  64. write_sequnlock(&dev->txwait_lock);
  65. return tx;
  66. }
  67. int verbs_txreq_init(struct hfi1_ibdev *dev)
  68. {
  69. char buf[TXREQ_LEN];
  70. struct hfi1_devdata *dd = dd_from_dev(dev);
  71. snprintf(buf, sizeof(buf), "hfi1_%u_vtxreq_cache", dd->unit);
  72. dev->verbs_txreq_cache = kmem_cache_create(buf,
  73. sizeof(struct verbs_txreq),
  74. 0, SLAB_HWCACHE_ALIGN,
  75. NULL);
  76. if (!dev->verbs_txreq_cache)
  77. return -ENOMEM;
  78. return 0;
  79. }
  80. void verbs_txreq_exit(struct hfi1_ibdev *dev)
  81. {
  82. kmem_cache_destroy(dev->verbs_txreq_cache);
  83. dev->verbs_txreq_cache = NULL;
  84. }