wq.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. 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 <linux/mlx5/driver.h>
  33. #include "wq.h"
  34. #include "mlx5_core.h"
  35. u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq)
  36. {
  37. return (u32)wq->sz_m1 + 1;
  38. }
  39. u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq)
  40. {
  41. return wq->sz_m1 + 1;
  42. }
  43. u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq)
  44. {
  45. return (u32)wq->sz_m1 + 1;
  46. }
  47. static u32 mlx5_wq_cyc_get_byte_size(struct mlx5_wq_cyc *wq)
  48. {
  49. return mlx5_wq_cyc_get_size(wq) << wq->log_stride;
  50. }
  51. static u32 mlx5_cqwq_get_byte_size(struct mlx5_cqwq *wq)
  52. {
  53. return mlx5_cqwq_get_size(wq) << wq->log_stride;
  54. }
  55. static u32 mlx5_wq_ll_get_byte_size(struct mlx5_wq_ll *wq)
  56. {
  57. return mlx5_wq_ll_get_size(wq) << wq->log_stride;
  58. }
  59. int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
  60. void *wqc, struct mlx5_wq_cyc *wq,
  61. struct mlx5_wq_ctrl *wq_ctrl)
  62. {
  63. int err;
  64. wq->log_stride = MLX5_GET(wq, wqc, log_wq_stride);
  65. wq->sz_m1 = (1 << MLX5_GET(wq, wqc, log_wq_sz)) - 1;
  66. err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
  67. if (err) {
  68. mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
  69. return err;
  70. }
  71. err = mlx5_buf_alloc_node(mdev, mlx5_wq_cyc_get_byte_size(wq),
  72. &wq_ctrl->buf, param->buf_numa_node);
  73. if (err) {
  74. mlx5_core_warn(mdev, "mlx5_buf_alloc_node() failed, %d\n", err);
  75. goto err_db_free;
  76. }
  77. wq->buf = wq_ctrl->buf.direct.buf;
  78. wq->db = wq_ctrl->db.db;
  79. wq_ctrl->mdev = mdev;
  80. return 0;
  81. err_db_free:
  82. mlx5_db_free(mdev, &wq_ctrl->db);
  83. return err;
  84. }
  85. int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
  86. void *cqc, struct mlx5_cqwq *wq,
  87. struct mlx5_wq_ctrl *wq_ctrl)
  88. {
  89. int err;
  90. wq->log_stride = 6 + MLX5_GET(cqc, cqc, cqe_sz);
  91. wq->log_sz = MLX5_GET(cqc, cqc, log_cq_size);
  92. wq->sz_m1 = (1 << wq->log_sz) - 1;
  93. err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
  94. if (err) {
  95. mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
  96. return err;
  97. }
  98. err = mlx5_buf_alloc_node(mdev, mlx5_cqwq_get_byte_size(wq),
  99. &wq_ctrl->buf, param->buf_numa_node);
  100. if (err) {
  101. mlx5_core_warn(mdev, "mlx5_buf_alloc_node() failed, %d\n", err);
  102. goto err_db_free;
  103. }
  104. wq->buf = wq_ctrl->buf.direct.buf;
  105. wq->db = wq_ctrl->db.db;
  106. wq_ctrl->mdev = mdev;
  107. return 0;
  108. err_db_free:
  109. mlx5_db_free(mdev, &wq_ctrl->db);
  110. return err;
  111. }
  112. int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
  113. void *wqc, struct mlx5_wq_ll *wq,
  114. struct mlx5_wq_ctrl *wq_ctrl)
  115. {
  116. struct mlx5_wqe_srq_next_seg *next_seg;
  117. int err;
  118. int i;
  119. wq->log_stride = MLX5_GET(wq, wqc, log_wq_stride);
  120. wq->sz_m1 = (1 << MLX5_GET(wq, wqc, log_wq_sz)) - 1;
  121. err = mlx5_db_alloc_node(mdev, &wq_ctrl->db, param->db_numa_node);
  122. if (err) {
  123. mlx5_core_warn(mdev, "mlx5_db_alloc_node() failed, %d\n", err);
  124. return err;
  125. }
  126. err = mlx5_buf_alloc_node(mdev, mlx5_wq_ll_get_byte_size(wq),
  127. &wq_ctrl->buf, param->buf_numa_node);
  128. if (err) {
  129. mlx5_core_warn(mdev, "mlx5_buf_alloc_node() failed, %d\n", err);
  130. goto err_db_free;
  131. }
  132. wq->buf = wq_ctrl->buf.direct.buf;
  133. wq->db = wq_ctrl->db.db;
  134. for (i = 0; i < wq->sz_m1; i++) {
  135. next_seg = mlx5_wq_ll_get_wqe(wq, i);
  136. next_seg->next_wqe_index = cpu_to_be16(i + 1);
  137. }
  138. next_seg = mlx5_wq_ll_get_wqe(wq, i);
  139. wq->tail_next = &next_seg->next_wqe_index;
  140. wq_ctrl->mdev = mdev;
  141. return 0;
  142. err_db_free:
  143. mlx5_db_free(mdev, &wq_ctrl->db);
  144. return err;
  145. }
  146. void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl)
  147. {
  148. mlx5_buf_free(wq_ctrl->mdev, &wq_ctrl->buf);
  149. mlx5_db_free(wq_ctrl->mdev, &wq_ctrl->db);
  150. }