34 #include <linux/module.h>
36 #include <linux/string.h>
37 #include <linux/slab.h>
69 struct mthca_resource {
80 struct mthca_resource tmp;
117 profile[
i].log_num =
max(
ffs(profile[i].
num) - 1, 0);
118 profile[
i].size *= profile[
i].num;
119 if (mthca_is_memfree(dev))
123 if (mthca_is_memfree(dev)) {
125 mem_avail = dev_lim->
hca.
arbel.max_icm_sz;
137 for (i = MTHCA_RES_NUM; i > 0; --
i)
138 for (j = 1; j <
i; ++
j) {
139 if (profile[j].
size > profile[j - 1].
size) {
141 profile[
j] = profile[j - 1];
142 profile[j - 1] =
tmp;
147 if (profile[i].
size) {
149 total_size += profile[
i].size;
151 if (total_size > mem_avail) {
152 mthca_err(dev,
"Profile requires 0x%llx bytes; "
153 "won't fit in 0x%llx bytes of context memory.\n",
154 (
unsigned long long) total_size,
155 (
unsigned long long) mem_avail);
161 mthca_dbg(dev,
"profile[%2d]--%2d/%2d @ 0x%16llx "
163 i, profile[i].
type, profile[i].log_num,
164 (
unsigned long long) profile[i].
start,
165 (
unsigned long long) profile[i].size);
168 if (mthca_is_memfree(dev))
169 mthca_dbg(dev,
"HCA context memory: reserving %d KB\n",
170 (
int) (total_size >> 10));
172 mthca_dbg(dev,
"HCA memory: allocated %d KB/%d KB (%d KB free)\n",
173 (
int) (total_size >> 10), (
int) (mem_avail >> 10),
174 (
int) ((mem_avail - total_size) >> 10));
177 switch (profile[i].
type) {
179 dev->
limits.num_qps = profile[
i].num;
184 dev->
limits.num_eecs = profile[
i].num;
189 dev->
limits.num_srqs = profile[
i].num;
194 dev->
limits.num_cqs = profile[
i].num;
205 dev->
limits.num_eqs = profile[
i].num;
218 dev->
limits.num_mgms = profile[
i].num >> 1;
219 dev->
limits.num_amgms = profile[
i].num >> 1;
220 init_hca->
mc_base = profile[
i].start;
223 init_hca->
mc_hash_sz = 1 << (profile[
i].log_num - 1);
226 dev->
limits.num_mpts = profile[
i].num;
227 dev->
mr_table.mpt_base = profile[
i].start;
232 dev->
limits.num_mtt_segs = profile[
i].num;
233 dev->
mr_table.mtt_base = profile[
i].start;
238 dev->
limits.num_uars = profile[
i].num;
242 dev->
av_table.ddr_av_base = profile[
i].start;
243 dev->
av_table.num_ddr_avs = profile[
i].num;
265 mthca_warn(dev,
"MPT table too large (requested size 2^%d >= 2^24)\n",
267 mthca_warn(dev,
"Disabling memory key throughput optimization.\n");
279 dev->
limits.fmr_reserved_mtts = 0;