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.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
35 #include <linux/slab.h>
55 static const char *res_name
[] = {
57 [MLX4_RES_RDMARC
] = "RDMARC",
58 [MLX4_RES_ALTC
] = "ALTC",
59 [MLX4_RES_AUXC
] = "AUXC",
60 [MLX4_RES_SRQ
] = "SRQ",
63 [MLX4_RES_DMPT
] = "DMPT",
64 [MLX4_RES_CMPT
] = "CMPT",
65 [MLX4_RES_MTT
] = "MTT",
66 [MLX4_RES_MCG
] = "MCG",
69 u64
mlx4_make_profile(struct mlx4_dev
*dev
,
70 struct mlx4_profile
*request
,
71 struct mlx4_dev_cap
*dev_cap
,
72 struct mlx4_init_hca_param
*init_hca
)
74 struct mlx4_priv
*priv
= mlx4_priv(dev
);
75 struct mlx4_resource
{
84 struct mlx4_resource
*profile
;
85 struct mlx4_resource tmp
;
89 profile
= kcalloc(MLX4_RES_NUM
, sizeof(*profile
), GFP_KERNEL
);
94 * We want to scale the number of MTTs with the size of the
95 * system memory, since it makes sense to register a lot of
96 * memory on a system with a lot of memory. As a heuristic,
97 * make sure we have enough MTTs to cover twice the system
98 * memory (with PAGE_SIZE entries).
100 * This number has to be a power of two and fit into 32 bits
101 * due to device limitations, so cap this at 2^31 as well.
102 * That limits us to 8TB of memory registration per HCA with
103 * 4KB pages, which is probably OK for the next few months.
107 roundup_pow_of_two(max_t(unsigned, request
->num_mtt
,
109 si
.totalram
>> (log_mtts_per_seg
- 1))));
111 profile
[MLX4_RES_QP
].size
= dev_cap
->qpc_entry_sz
;
112 profile
[MLX4_RES_RDMARC
].size
= dev_cap
->rdmarc_entry_sz
;
113 profile
[MLX4_RES_ALTC
].size
= dev_cap
->altc_entry_sz
;
114 profile
[MLX4_RES_AUXC
].size
= dev_cap
->aux_entry_sz
;
115 profile
[MLX4_RES_SRQ
].size
= dev_cap
->srq_entry_sz
;
116 profile
[MLX4_RES_CQ
].size
= dev_cap
->cqc_entry_sz
;
117 profile
[MLX4_RES_EQ
].size
= dev_cap
->eqc_entry_sz
;
118 profile
[MLX4_RES_DMPT
].size
= dev_cap
->dmpt_entry_sz
;
119 profile
[MLX4_RES_CMPT
].size
= dev_cap
->cmpt_entry_sz
;
120 profile
[MLX4_RES_MTT
].size
= dev_cap
->mtt_entry_sz
;
121 profile
[MLX4_RES_MCG
].size
= mlx4_get_mgm_entry_size(dev
);
123 profile
[MLX4_RES_QP
].num
= request
->num_qp
;
124 profile
[MLX4_RES_RDMARC
].num
= request
->num_qp
* request
->rdmarc_per_qp
;
125 profile
[MLX4_RES_ALTC
].num
= request
->num_qp
;
126 profile
[MLX4_RES_AUXC
].num
= request
->num_qp
;
127 profile
[MLX4_RES_SRQ
].num
= request
->num_srq
;
128 profile
[MLX4_RES_CQ
].num
= request
->num_cq
;
129 profile
[MLX4_RES_EQ
].num
= min_t(unsigned, dev_cap
->max_eqs
, MAX_MSIX
);
130 profile
[MLX4_RES_DMPT
].num
= request
->num_mpt
;
131 profile
[MLX4_RES_CMPT
].num
= MLX4_NUM_CMPTS
;
132 profile
[MLX4_RES_MTT
].num
= request
->num_mtt
* (1 << log_mtts_per_seg
);
133 profile
[MLX4_RES_MCG
].num
= request
->num_mcg
;
135 for (i
= 0; i
< MLX4_RES_NUM
; ++i
) {
137 profile
[i
].num
= roundup_pow_of_two(profile
[i
].num
);
138 profile
[i
].log_num
= ilog2(profile
[i
].num
);
139 profile
[i
].size
*= profile
[i
].num
;
140 profile
[i
].size
= max(profile
[i
].size
, (u64
) PAGE_SIZE
);
144 * Sort the resources in decreasing order of size. Since they
145 * all have sizes that are powers of 2, we'll be able to keep
146 * resources aligned to their size and pack them without gaps
147 * using the sorted order.
149 for (i
= MLX4_RES_NUM
; i
> 0; --i
)
150 for (j
= 1; j
< i
; ++j
) {
151 if (profile
[j
].size
> profile
[j
- 1].size
) {
153 profile
[j
] = profile
[j
- 1];
154 profile
[j
- 1] = tmp
;
158 for (i
= 0; i
< MLX4_RES_NUM
; ++i
) {
159 if (profile
[i
].size
) {
160 profile
[i
].start
= total_size
;
161 total_size
+= profile
[i
].size
;
164 if (total_size
> dev_cap
->max_icm_sz
) {
165 mlx4_err(dev
, "Profile requires 0x%llx bytes; "
166 "won't fit in 0x%llx bytes of context memory.\n",
167 (unsigned long long) total_size
,
168 (unsigned long long) dev_cap
->max_icm_sz
);
174 mlx4_dbg(dev
, " profile[%2d] (%6s): 2^%02d entries @ 0x%10llx, "
176 i
, res_name
[profile
[i
].type
], profile
[i
].log_num
,
177 (unsigned long long) profile
[i
].start
,
178 (unsigned long long) profile
[i
].size
);
181 mlx4_dbg(dev
, "HCA context memory: reserving %d KB\n",
182 (int) (total_size
>> 10));
184 for (i
= 0; i
< MLX4_RES_NUM
; ++i
) {
185 switch (profile
[i
].type
) {
187 dev
->caps
.num_qps
= profile
[i
].num
;
188 init_hca
->qpc_base
= profile
[i
].start
;
189 init_hca
->log_num_qps
= profile
[i
].log_num
;
191 case MLX4_RES_RDMARC
:
192 for (priv
->qp_table
.rdmarc_shift
= 0;
193 request
->num_qp
<< priv
->qp_table
.rdmarc_shift
< profile
[i
].num
;
194 ++priv
->qp_table
.rdmarc_shift
)
196 dev
->caps
.max_qp_dest_rdma
= 1 << priv
->qp_table
.rdmarc_shift
;
197 priv
->qp_table
.rdmarc_base
= (u32
) profile
[i
].start
;
198 init_hca
->rdmarc_base
= profile
[i
].start
;
199 init_hca
->log_rd_per_qp
= priv
->qp_table
.rdmarc_shift
;
202 init_hca
->altc_base
= profile
[i
].start
;
205 init_hca
->auxc_base
= profile
[i
].start
;
208 dev
->caps
.num_srqs
= profile
[i
].num
;
209 init_hca
->srqc_base
= profile
[i
].start
;
210 init_hca
->log_num_srqs
= profile
[i
].log_num
;
213 dev
->caps
.num_cqs
= profile
[i
].num
;
214 init_hca
->cqc_base
= profile
[i
].start
;
215 init_hca
->log_num_cqs
= profile
[i
].log_num
;
218 dev
->caps
.num_eqs
= profile
[i
].num
;
219 init_hca
->eqc_base
= profile
[i
].start
;
220 init_hca
->log_num_eqs
= profile
[i
].log_num
;
223 dev
->caps
.num_mpts
= profile
[i
].num
;
224 priv
->mr_table
.mpt_base
= profile
[i
].start
;
225 init_hca
->dmpt_base
= profile
[i
].start
;
226 init_hca
->log_mpt_sz
= profile
[i
].log_num
;
229 init_hca
->cmpt_base
= profile
[i
].start
;
232 dev
->caps
.num_mtts
= profile
[i
].num
;
233 priv
->mr_table
.mtt_base
= profile
[i
].start
;
234 init_hca
->mtt_base
= profile
[i
].start
;
237 dev
->caps
.num_mgms
= profile
[i
].num
>> 1;
238 dev
->caps
.num_amgms
= profile
[i
].num
>> 1;
239 init_hca
->mc_base
= profile
[i
].start
;
240 init_hca
->log_mc_entry_sz
=
241 ilog2(mlx4_get_mgm_entry_size(dev
));
242 init_hca
->log_mc_table_sz
= profile
[i
].log_num
;
243 init_hca
->log_mc_hash_sz
= profile
[i
].log_num
- 1;
251 * PDs don't take any HCA memory, but we assign them as part
252 * of the HCA profile anyway.
254 dev
->caps
.num_pds
= MLX4_NUM_PDS
;