rxe_srq.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/vmalloc.h>
  34. #include "rxe.h"
  35. #include "rxe_loc.h"
  36. #include "rxe_queue.h"
  37. int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
  38. struct ib_srq_attr *attr, enum ib_srq_attr_mask mask)
  39. {
  40. if (srq && srq->error) {
  41. pr_warn("srq in error state\n");
  42. goto err1;
  43. }
  44. if (mask & IB_SRQ_MAX_WR) {
  45. if (attr->max_wr > rxe->attr.max_srq_wr) {
  46. pr_warn("max_wr(%d) > max_srq_wr(%d)\n",
  47. attr->max_wr, rxe->attr.max_srq_wr);
  48. goto err1;
  49. }
  50. if (attr->max_wr <= 0) {
  51. pr_warn("max_wr(%d) <= 0\n", attr->max_wr);
  52. goto err1;
  53. }
  54. if (srq && srq->limit && (attr->max_wr < srq->limit)) {
  55. pr_warn("max_wr (%d) < srq->limit (%d)\n",
  56. attr->max_wr, srq->limit);
  57. goto err1;
  58. }
  59. if (attr->max_wr < RXE_MIN_SRQ_WR)
  60. attr->max_wr = RXE_MIN_SRQ_WR;
  61. }
  62. if (mask & IB_SRQ_LIMIT) {
  63. if (attr->srq_limit > rxe->attr.max_srq_wr) {
  64. pr_warn("srq_limit(%d) > max_srq_wr(%d)\n",
  65. attr->srq_limit, rxe->attr.max_srq_wr);
  66. goto err1;
  67. }
  68. if (srq && (attr->srq_limit > srq->rq.queue->buf->index_mask)) {
  69. pr_warn("srq_limit (%d) > cur limit(%d)\n",
  70. attr->srq_limit,
  71. srq->rq.queue->buf->index_mask);
  72. goto err1;
  73. }
  74. }
  75. if (mask == IB_SRQ_INIT_MASK) {
  76. if (attr->max_sge > rxe->attr.max_srq_sge) {
  77. pr_warn("max_sge(%d) > max_srq_sge(%d)\n",
  78. attr->max_sge, rxe->attr.max_srq_sge);
  79. goto err1;
  80. }
  81. if (attr->max_sge < RXE_MIN_SRQ_SGE)
  82. attr->max_sge = RXE_MIN_SRQ_SGE;
  83. }
  84. return 0;
  85. err1:
  86. return -EINVAL;
  87. }
  88. int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
  89. struct ib_srq_init_attr *init,
  90. struct ib_ucontext *context,
  91. struct rxe_create_srq_resp __user *uresp)
  92. {
  93. int err;
  94. int srq_wqe_size;
  95. struct rxe_queue *q;
  96. srq->ibsrq.event_handler = init->event_handler;
  97. srq->ibsrq.srq_context = init->srq_context;
  98. srq->limit = init->attr.srq_limit;
  99. srq->srq_num = srq->pelem.index;
  100. srq->rq.max_wr = init->attr.max_wr;
  101. srq->rq.max_sge = init->attr.max_sge;
  102. srq_wqe_size = rcv_wqe_size(srq->rq.max_sge);
  103. spin_lock_init(&srq->rq.producer_lock);
  104. spin_lock_init(&srq->rq.consumer_lock);
  105. q = rxe_queue_init(rxe, &srq->rq.max_wr,
  106. srq_wqe_size);
  107. if (!q) {
  108. pr_warn("unable to allocate queue for srq\n");
  109. return -ENOMEM;
  110. }
  111. srq->rq.queue = q;
  112. err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, context, q->buf,
  113. q->buf_size, &q->ip);
  114. if (err) {
  115. vfree(q->buf);
  116. kfree(q);
  117. return err;
  118. }
  119. if (uresp) {
  120. if (copy_to_user(&uresp->srq_num, &srq->srq_num,
  121. sizeof(uresp->srq_num))) {
  122. rxe_queue_cleanup(q);
  123. return -EFAULT;
  124. }
  125. }
  126. return 0;
  127. }
  128. int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
  129. struct ib_srq_attr *attr, enum ib_srq_attr_mask mask,
  130. struct rxe_modify_srq_cmd *ucmd)
  131. {
  132. int err;
  133. struct rxe_queue *q = srq->rq.queue;
  134. struct mminfo __user *mi = NULL;
  135. if (mask & IB_SRQ_MAX_WR) {
  136. /*
  137. * This is completely screwed up, the response is supposed to
  138. * be in the outbuf not like this.
  139. */
  140. mi = u64_to_user_ptr(ucmd->mmap_info_addr);
  141. err = rxe_queue_resize(q, &attr->max_wr,
  142. rcv_wqe_size(srq->rq.max_sge),
  143. srq->rq.queue->ip ?
  144. srq->rq.queue->ip->context :
  145. NULL,
  146. mi, &srq->rq.producer_lock,
  147. &srq->rq.consumer_lock);
  148. if (err)
  149. goto err2;
  150. }
  151. if (mask & IB_SRQ_LIMIT)
  152. srq->limit = attr->srq_limit;
  153. return 0;
  154. err2:
  155. rxe_queue_cleanup(q);
  156. srq->rq.queue = NULL;
  157. return err;
  158. }