profile.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/init.h>
  35. #include "mlx4.h"
  36. #include "fw.h"
  37. enum {
  38. MLX4_RES_QP,
  39. MLX4_RES_RDMARC,
  40. MLX4_RES_ALTC,
  41. MLX4_RES_AUXC,
  42. MLX4_RES_SRQ,
  43. MLX4_RES_CQ,
  44. MLX4_RES_EQ,
  45. MLX4_RES_DMPT,
  46. MLX4_RES_CMPT,
  47. MLX4_RES_MTT,
  48. MLX4_RES_MCG,
  49. MLX4_RES_NUM
  50. };
  51. static const char *res_name[] = {
  52. [MLX4_RES_QP] = "QP",
  53. [MLX4_RES_RDMARC] = "RDMARC",
  54. [MLX4_RES_ALTC] = "ALTC",
  55. [MLX4_RES_AUXC] = "AUXC",
  56. [MLX4_RES_SRQ] = "SRQ",
  57. [MLX4_RES_CQ] = "CQ",
  58. [MLX4_RES_EQ] = "EQ",
  59. [MLX4_RES_DMPT] = "DMPT",
  60. [MLX4_RES_CMPT] = "CMPT",
  61. [MLX4_RES_MTT] = "MTT",
  62. [MLX4_RES_MCG] = "MCG",
  63. };
  64. u64 mlx4_make_profile(struct mlx4_dev *dev,
  65. struct mlx4_profile *request,
  66. struct mlx4_dev_cap *dev_cap,
  67. struct mlx4_init_hca_param *init_hca)
  68. {
  69. struct mlx4_priv *priv = mlx4_priv(dev);
  70. struct mlx4_resource {
  71. u64 size;
  72. u64 start;
  73. int type;
  74. int num;
  75. int log_num;
  76. };
  77. u64 total_size = 0;
  78. struct mlx4_resource *profile;
  79. struct mlx4_resource tmp;
  80. int i, j;
  81. profile = kzalloc(MLX4_RES_NUM * sizeof *profile, GFP_KERNEL);
  82. if (!profile)
  83. return -ENOMEM;
  84. profile[MLX4_RES_QP].size = dev_cap->qpc_entry_sz;
  85. profile[MLX4_RES_RDMARC].size = dev_cap->rdmarc_entry_sz;
  86. profile[MLX4_RES_ALTC].size = dev_cap->altc_entry_sz;
  87. profile[MLX4_RES_AUXC].size = dev_cap->aux_entry_sz;
  88. profile[MLX4_RES_SRQ].size = dev_cap->srq_entry_sz;
  89. profile[MLX4_RES_CQ].size = dev_cap->cqc_entry_sz;
  90. profile[MLX4_RES_EQ].size = dev_cap->eqc_entry_sz;
  91. profile[MLX4_RES_DMPT].size = dev_cap->dmpt_entry_sz;
  92. profile[MLX4_RES_CMPT].size = dev_cap->cmpt_entry_sz;
  93. profile[MLX4_RES_MTT].size = MLX4_MTT_ENTRY_PER_SEG * dev_cap->mtt_entry_sz;
  94. profile[MLX4_RES_MCG].size = MLX4_MGM_ENTRY_SIZE;
  95. profile[MLX4_RES_QP].num = request->num_qp;
  96. profile[MLX4_RES_RDMARC].num = request->num_qp * request->rdmarc_per_qp;
  97. profile[MLX4_RES_ALTC].num = request->num_qp;
  98. profile[MLX4_RES_AUXC].num = request->num_qp;
  99. profile[MLX4_RES_SRQ].num = request->num_srq;
  100. profile[MLX4_RES_CQ].num = request->num_cq;
  101. profile[MLX4_RES_EQ].num = min_t(unsigned, dev_cap->max_eqs,
  102. dev_cap->reserved_eqs +
  103. num_possible_cpus() + 1);
  104. profile[MLX4_RES_DMPT].num = request->num_mpt;
  105. profile[MLX4_RES_CMPT].num = MLX4_NUM_CMPTS;
  106. profile[MLX4_RES_MTT].num = request->num_mtt;
  107. profile[MLX4_RES_MCG].num = request->num_mcg;
  108. for (i = 0; i < MLX4_RES_NUM; ++i) {
  109. profile[i].type = i;
  110. profile[i].num = roundup_pow_of_two(profile[i].num);
  111. profile[i].log_num = ilog2(profile[i].num);
  112. profile[i].size *= profile[i].num;
  113. profile[i].size = max(profile[i].size, (u64) PAGE_SIZE);
  114. }
  115. /*
  116. * Sort the resources in decreasing order of size. Since they
  117. * all have sizes that are powers of 2, we'll be able to keep
  118. * resources aligned to their size and pack them without gaps
  119. * using the sorted order.
  120. */
  121. for (i = MLX4_RES_NUM; i > 0; --i)
  122. for (j = 1; j < i; ++j) {
  123. if (profile[j].size > profile[j - 1].size) {
  124. tmp = profile[j];
  125. profile[j] = profile[j - 1];
  126. profile[j - 1] = tmp;
  127. }
  128. }
  129. for (i = 0; i < MLX4_RES_NUM; ++i) {
  130. if (profile[i].size) {
  131. profile[i].start = total_size;
  132. total_size += profile[i].size;
  133. }
  134. if (total_size > dev_cap->max_icm_sz) {
  135. mlx4_err(dev, "Profile requires 0x%llx bytes; "
  136. "won't fit in 0x%llx bytes of context memory.\n",
  137. (unsigned long long) total_size,
  138. (unsigned long long) dev_cap->max_icm_sz);
  139. kfree(profile);
  140. return -ENOMEM;
  141. }
  142. if (profile[i].size)
  143. mlx4_dbg(dev, " profile[%2d] (%6s): 2^%02d entries @ 0x%10llx, "
  144. "size 0x%10llx\n",
  145. i, res_name[profile[i].type], profile[i].log_num,
  146. (unsigned long long) profile[i].start,
  147. (unsigned long long) profile[i].size);
  148. }
  149. mlx4_dbg(dev, "HCA context memory: reserving %d KB\n",
  150. (int) (total_size >> 10));
  151. for (i = 0; i < MLX4_RES_NUM; ++i) {
  152. switch (profile[i].type) {
  153. case MLX4_RES_QP:
  154. dev->caps.num_qps = profile[i].num;
  155. init_hca->qpc_base = profile[i].start;
  156. init_hca->log_num_qps = profile[i].log_num;
  157. break;
  158. case MLX4_RES_RDMARC:
  159. for (priv->qp_table.rdmarc_shift = 0;
  160. request->num_qp << priv->qp_table.rdmarc_shift < profile[i].num;
  161. ++priv->qp_table.rdmarc_shift)
  162. ; /* nothing */
  163. dev->caps.max_qp_dest_rdma = 1 << priv->qp_table.rdmarc_shift;
  164. priv->qp_table.rdmarc_base = (u32) profile[i].start;
  165. init_hca->rdmarc_base = profile[i].start;
  166. init_hca->log_rd_per_qp = priv->qp_table.rdmarc_shift;
  167. break;
  168. case MLX4_RES_ALTC:
  169. init_hca->altc_base = profile[i].start;
  170. break;
  171. case MLX4_RES_AUXC:
  172. init_hca->auxc_base = profile[i].start;
  173. break;
  174. case MLX4_RES_SRQ:
  175. dev->caps.num_srqs = profile[i].num;
  176. init_hca->srqc_base = profile[i].start;
  177. init_hca->log_num_srqs = profile[i].log_num;
  178. break;
  179. case MLX4_RES_CQ:
  180. dev->caps.num_cqs = profile[i].num;
  181. init_hca->cqc_base = profile[i].start;
  182. init_hca->log_num_cqs = profile[i].log_num;
  183. break;
  184. case MLX4_RES_EQ:
  185. dev->caps.num_eqs = profile[i].num;
  186. init_hca->eqc_base = profile[i].start;
  187. init_hca->log_num_eqs = profile[i].log_num;
  188. break;
  189. case MLX4_RES_DMPT:
  190. dev->caps.num_mpts = profile[i].num;
  191. priv->mr_table.mpt_base = profile[i].start;
  192. init_hca->dmpt_base = profile[i].start;
  193. init_hca->log_mpt_sz = profile[i].log_num;
  194. break;
  195. case MLX4_RES_CMPT:
  196. init_hca->cmpt_base = profile[i].start;
  197. break;
  198. case MLX4_RES_MTT:
  199. dev->caps.num_mtt_segs = profile[i].num;
  200. priv->mr_table.mtt_base = profile[i].start;
  201. init_hca->mtt_base = profile[i].start;
  202. break;
  203. case MLX4_RES_MCG:
  204. dev->caps.num_mgms = profile[i].num >> 1;
  205. dev->caps.num_amgms = profile[i].num >> 1;
  206. init_hca->mc_base = profile[i].start;
  207. init_hca->log_mc_entry_sz = ilog2(MLX4_MGM_ENTRY_SIZE);
  208. init_hca->log_mc_table_sz = profile[i].log_num;
  209. init_hca->log_mc_hash_sz = profile[i].log_num - 1;
  210. break;
  211. default:
  212. break;
  213. }
  214. }
  215. /*
  216. * PDs don't take any HCA memory, but we assign them as part
  217. * of the HCA profile anyway.
  218. */
  219. dev->caps.num_pds = MLX4_NUM_PDS;
  220. kfree(profile);
  221. return total_size;
  222. }