Linux Audio

Check our new training course

Loading...
v6.8
  1/*
  2 * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
  3 * Copyright (c) 2005 Mellanox Technologies. 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
 
 
 34#include <linux/string.h>
 35#include <linux/slab.h>
 36
 37#include "mthca_profile.h"
 38
 39enum {
 40	MTHCA_RES_QP,
 41	MTHCA_RES_EEC,
 42	MTHCA_RES_SRQ,
 43	MTHCA_RES_CQ,
 44	MTHCA_RES_EQP,
 45	MTHCA_RES_EEEC,
 46	MTHCA_RES_EQ,
 47	MTHCA_RES_RDB,
 48	MTHCA_RES_MCG,
 49	MTHCA_RES_MPT,
 50	MTHCA_RES_MTT,
 51	MTHCA_RES_UAR,
 52	MTHCA_RES_UDAV,
 53	MTHCA_RES_UARC,
 54	MTHCA_RES_NUM
 55};
 56
 57enum {
 58	MTHCA_NUM_EQS = 32,
 59	MTHCA_NUM_PDS = 1 << 15
 60};
 61
 62s64 mthca_make_profile(struct mthca_dev *dev,
 63		       struct mthca_profile *request,
 64		       struct mthca_dev_lim *dev_lim,
 65		       struct mthca_init_hca_param *init_hca)
 66{
 67	struct mthca_resource {
 68		u64 size;
 69		u64 start;
 70		int type;
 71		int num;
 72		int log_num;
 73	};
 74
 75	u64 mem_base, mem_avail;
 76	s64 total_size = 0;
 77	struct mthca_resource *profile;
 78	int i, j;
 79
 80	profile = kcalloc(MTHCA_RES_NUM, sizeof(*profile), GFP_KERNEL);
 81	if (!profile)
 82		return -ENOMEM;
 83
 84	profile[MTHCA_RES_QP].size   = dev_lim->qpc_entry_sz;
 85	profile[MTHCA_RES_EEC].size  = dev_lim->eec_entry_sz;
 86	profile[MTHCA_RES_SRQ].size  = dev_lim->srq_entry_sz;
 87	profile[MTHCA_RES_CQ].size   = dev_lim->cqc_entry_sz;
 88	profile[MTHCA_RES_EQP].size  = dev_lim->eqpc_entry_sz;
 89	profile[MTHCA_RES_EEEC].size = dev_lim->eeec_entry_sz;
 90	profile[MTHCA_RES_EQ].size   = dev_lim->eqc_entry_sz;
 91	profile[MTHCA_RES_RDB].size  = MTHCA_RDB_ENTRY_SIZE;
 92	profile[MTHCA_RES_MCG].size  = MTHCA_MGM_ENTRY_SIZE;
 93	profile[MTHCA_RES_MPT].size  = dev_lim->mpt_entry_sz;
 94	profile[MTHCA_RES_MTT].size  = dev->limits.mtt_seg_size;
 95	profile[MTHCA_RES_UAR].size  = dev_lim->uar_scratch_entry_sz;
 96	profile[MTHCA_RES_UDAV].size = MTHCA_AV_SIZE;
 97	profile[MTHCA_RES_UARC].size = request->uarc_size;
 98
 99	profile[MTHCA_RES_QP].num    = request->num_qp;
100	profile[MTHCA_RES_SRQ].num   = request->num_srq;
101	profile[MTHCA_RES_EQP].num   = request->num_qp;
102	profile[MTHCA_RES_RDB].num   = request->num_qp * request->rdb_per_qp;
103	profile[MTHCA_RES_CQ].num    = request->num_cq;
104	profile[MTHCA_RES_EQ].num    = MTHCA_NUM_EQS;
105	profile[MTHCA_RES_MCG].num   = request->num_mcg;
106	profile[MTHCA_RES_MPT].num   = request->num_mpt;
107	profile[MTHCA_RES_MTT].num   = request->num_mtt;
108	profile[MTHCA_RES_UAR].num   = request->num_uar;
109	profile[MTHCA_RES_UARC].num  = request->num_uar;
110	profile[MTHCA_RES_UDAV].num  = request->num_udav;
111
112	for (i = 0; i < MTHCA_RES_NUM; ++i) {
113		profile[i].type     = i;
114		profile[i].log_num  = max(ffs(profile[i].num) - 1, 0);
115		profile[i].size    *= profile[i].num;
116		if (mthca_is_memfree(dev))
117			profile[i].size = max(profile[i].size, (u64) PAGE_SIZE);
118	}
119
120	if (mthca_is_memfree(dev)) {
121		mem_base  = 0;
122		mem_avail = dev_lim->hca.arbel.max_icm_sz;
123	} else {
124		mem_base  = dev->ddr_start;
125		mem_avail = dev->fw.tavor.fw_start - dev->ddr_start;
126	}
127
128	/*
129	 * Sort the resources in decreasing order of size.  Since they
130	 * all have sizes that are powers of 2, we'll be able to keep
131	 * resources aligned to their size and pack them without gaps
132	 * using the sorted order.
133	 */
134	for (i = MTHCA_RES_NUM; i > 0; --i)
135		for (j = 1; j < i; ++j) {
136			if (profile[j].size > profile[j - 1].size)
137				swap(profile[j], profile[j - 1]);
138		}
139
140	for (i = 0; i < MTHCA_RES_NUM; ++i) {
141		if (profile[i].size) {
142			profile[i].start = mem_base + total_size;
143			total_size      += profile[i].size;
144		}
145		if (total_size > mem_avail) {
146			mthca_err(dev, "Profile requires 0x%llx bytes; "
147				  "won't fit in 0x%llx bytes of context memory.\n",
148				  (unsigned long long) total_size,
149				  (unsigned long long) mem_avail);
150			kfree(profile);
151			return -ENOMEM;
152		}
153
154		if (profile[i].size)
155			mthca_dbg(dev, "profile[%2d]--%2d/%2d @ 0x%16llx "
156				  "(size 0x%8llx)\n",
157				  i, profile[i].type, profile[i].log_num,
158				  (unsigned long long) profile[i].start,
159				  (unsigned long long) profile[i].size);
160	}
161
162	if (mthca_is_memfree(dev))
163		mthca_dbg(dev, "HCA context memory: reserving %d KB\n",
164			  (int) (total_size >> 10));
165	else
166		mthca_dbg(dev, "HCA memory: allocated %d KB/%d KB (%d KB free)\n",
167			  (int) (total_size >> 10), (int) (mem_avail >> 10),
168			  (int) ((mem_avail - total_size) >> 10));
169
170	for (i = 0; i < MTHCA_RES_NUM; ++i) {
171		switch (profile[i].type) {
172		case MTHCA_RES_QP:
173			dev->limits.num_qps   = profile[i].num;
174			init_hca->qpc_base    = profile[i].start;
175			init_hca->log_num_qps = profile[i].log_num;
176			break;
177		case MTHCA_RES_EEC:
178			dev->limits.num_eecs   = profile[i].num;
179			init_hca->eec_base     = profile[i].start;
180			init_hca->log_num_eecs = profile[i].log_num;
181			break;
182		case MTHCA_RES_SRQ:
183			dev->limits.num_srqs   = profile[i].num;
184			init_hca->srqc_base    = profile[i].start;
185			init_hca->log_num_srqs = profile[i].log_num;
186			break;
187		case MTHCA_RES_CQ:
188			dev->limits.num_cqs   = profile[i].num;
189			init_hca->cqc_base    = profile[i].start;
190			init_hca->log_num_cqs = profile[i].log_num;
191			break;
192		case MTHCA_RES_EQP:
193			init_hca->eqpc_base = profile[i].start;
194			break;
195		case MTHCA_RES_EEEC:
196			init_hca->eeec_base = profile[i].start;
197			break;
198		case MTHCA_RES_EQ:
199			dev->limits.num_eqs   = profile[i].num;
200			init_hca->eqc_base    = profile[i].start;
201			init_hca->log_num_eqs = profile[i].log_num;
202			break;
203		case MTHCA_RES_RDB:
204			for (dev->qp_table.rdb_shift = 0;
205			     request->num_qp << dev->qp_table.rdb_shift < profile[i].num;
206			     ++dev->qp_table.rdb_shift)
207				; /* nothing */
208			dev->qp_table.rdb_base    = (u32) profile[i].start;
209			init_hca->rdb_base        = profile[i].start;
210			break;
211		case MTHCA_RES_MCG:
212			dev->limits.num_mgms      = profile[i].num >> 1;
213			dev->limits.num_amgms     = profile[i].num >> 1;
214			init_hca->mc_base         = profile[i].start;
215			init_hca->log_mc_entry_sz = ffs(MTHCA_MGM_ENTRY_SIZE) - 1;
216			init_hca->log_mc_table_sz = profile[i].log_num;
217			init_hca->mc_hash_sz      = 1 << (profile[i].log_num - 1);
218			break;
219		case MTHCA_RES_MPT:
220			dev->limits.num_mpts   = profile[i].num;
221			dev->mr_table.mpt_base = profile[i].start;
222			init_hca->mpt_base     = profile[i].start;
223			init_hca->log_mpt_sz   = profile[i].log_num;
224			break;
225		case MTHCA_RES_MTT:
226			dev->limits.num_mtt_segs = profile[i].num;
227			dev->mr_table.mtt_base   = profile[i].start;
228			init_hca->mtt_base       = profile[i].start;
229			init_hca->mtt_seg_sz     = ffs(dev->limits.mtt_seg_size) - 7;
230			break;
231		case MTHCA_RES_UAR:
232			dev->limits.num_uars       = profile[i].num;
233			init_hca->uar_scratch_base = profile[i].start;
234			break;
235		case MTHCA_RES_UDAV:
236			dev->av_table.ddr_av_base = profile[i].start;
237			dev->av_table.num_ddr_avs = profile[i].num;
238			break;
239		case MTHCA_RES_UARC:
240			dev->uar_table.uarc_size = request->uarc_size;
241			dev->uar_table.uarc_base = profile[i].start;
242			init_hca->uarc_base   	 = profile[i].start;
243			init_hca->log_uarc_sz 	 = ffs(request->uarc_size) - 13;
244			init_hca->log_uar_sz  	 = ffs(request->num_uar) - 1;
245			break;
246		default:
247			break;
248		}
249	}
250
251	/*
252	 * PDs don't take any HCA memory, but we assign them as part
253	 * of the HCA profile anyway.
254	 */
255	dev->limits.num_pds = MTHCA_NUM_PDS;
256
257	if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT &&
258	    init_hca->log_mpt_sz > 23) {
259		mthca_warn(dev, "MPT table too large (requested size 2^%d >= 2^24)\n",
260			   init_hca->log_mpt_sz);
261		mthca_warn(dev, "Disabling memory key throughput optimization.\n");
262		dev->mthca_flags &= ~MTHCA_FLAG_SINAI_OPT;
263	}
264
265	/*
266	 * For Tavor, FMRs use ioremapped PCI memory. For 32 bit
267	 * systems it may use too much vmalloc space to map all MTT
268	 * memory, so we reserve some MTTs for FMR access, taking them
269	 * out of the MR pool. They don't use additional memory, but
270	 * we assign them as part of the HCA profile anyway.
271	 */
272	if (mthca_is_memfree(dev) || BITS_PER_LONG == 64)
273		dev->limits.fmr_reserved_mtts = 0;
274	else
275		dev->limits.fmr_reserved_mtts = request->fmr_reserved_mtts;
276
277	kfree(profile);
278	return total_size;
279}
v5.4
  1/*
  2 * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
  3 * Copyright (c) 2005 Mellanox Technologies. 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
 34#include <linux/module.h>
 35#include <linux/moduleparam.h>
 36#include <linux/string.h>
 37#include <linux/slab.h>
 38
 39#include "mthca_profile.h"
 40
 41enum {
 42	MTHCA_RES_QP,
 43	MTHCA_RES_EEC,
 44	MTHCA_RES_SRQ,
 45	MTHCA_RES_CQ,
 46	MTHCA_RES_EQP,
 47	MTHCA_RES_EEEC,
 48	MTHCA_RES_EQ,
 49	MTHCA_RES_RDB,
 50	MTHCA_RES_MCG,
 51	MTHCA_RES_MPT,
 52	MTHCA_RES_MTT,
 53	MTHCA_RES_UAR,
 54	MTHCA_RES_UDAV,
 55	MTHCA_RES_UARC,
 56	MTHCA_RES_NUM
 57};
 58
 59enum {
 60	MTHCA_NUM_EQS = 32,
 61	MTHCA_NUM_PDS = 1 << 15
 62};
 63
 64s64 mthca_make_profile(struct mthca_dev *dev,
 65		       struct mthca_profile *request,
 66		       struct mthca_dev_lim *dev_lim,
 67		       struct mthca_init_hca_param *init_hca)
 68{
 69	struct mthca_resource {
 70		u64 size;
 71		u64 start;
 72		int type;
 73		int num;
 74		int log_num;
 75	};
 76
 77	u64 mem_base, mem_avail;
 78	s64 total_size = 0;
 79	struct mthca_resource *profile;
 80	int i, j;
 81
 82	profile = kcalloc(MTHCA_RES_NUM, sizeof(*profile), GFP_KERNEL);
 83	if (!profile)
 84		return -ENOMEM;
 85
 86	profile[MTHCA_RES_QP].size   = dev_lim->qpc_entry_sz;
 87	profile[MTHCA_RES_EEC].size  = dev_lim->eec_entry_sz;
 88	profile[MTHCA_RES_SRQ].size  = dev_lim->srq_entry_sz;
 89	profile[MTHCA_RES_CQ].size   = dev_lim->cqc_entry_sz;
 90	profile[MTHCA_RES_EQP].size  = dev_lim->eqpc_entry_sz;
 91	profile[MTHCA_RES_EEEC].size = dev_lim->eeec_entry_sz;
 92	profile[MTHCA_RES_EQ].size   = dev_lim->eqc_entry_sz;
 93	profile[MTHCA_RES_RDB].size  = MTHCA_RDB_ENTRY_SIZE;
 94	profile[MTHCA_RES_MCG].size  = MTHCA_MGM_ENTRY_SIZE;
 95	profile[MTHCA_RES_MPT].size  = dev_lim->mpt_entry_sz;
 96	profile[MTHCA_RES_MTT].size  = dev->limits.mtt_seg_size;
 97	profile[MTHCA_RES_UAR].size  = dev_lim->uar_scratch_entry_sz;
 98	profile[MTHCA_RES_UDAV].size = MTHCA_AV_SIZE;
 99	profile[MTHCA_RES_UARC].size = request->uarc_size;
100
101	profile[MTHCA_RES_QP].num    = request->num_qp;
102	profile[MTHCA_RES_SRQ].num   = request->num_srq;
103	profile[MTHCA_RES_EQP].num   = request->num_qp;
104	profile[MTHCA_RES_RDB].num   = request->num_qp * request->rdb_per_qp;
105	profile[MTHCA_RES_CQ].num    = request->num_cq;
106	profile[MTHCA_RES_EQ].num    = MTHCA_NUM_EQS;
107	profile[MTHCA_RES_MCG].num   = request->num_mcg;
108	profile[MTHCA_RES_MPT].num   = request->num_mpt;
109	profile[MTHCA_RES_MTT].num   = request->num_mtt;
110	profile[MTHCA_RES_UAR].num   = request->num_uar;
111	profile[MTHCA_RES_UARC].num  = request->num_uar;
112	profile[MTHCA_RES_UDAV].num  = request->num_udav;
113
114	for (i = 0; i < MTHCA_RES_NUM; ++i) {
115		profile[i].type     = i;
116		profile[i].log_num  = max(ffs(profile[i].num) - 1, 0);
117		profile[i].size    *= profile[i].num;
118		if (mthca_is_memfree(dev))
119			profile[i].size = max(profile[i].size, (u64) PAGE_SIZE);
120	}
121
122	if (mthca_is_memfree(dev)) {
123		mem_base  = 0;
124		mem_avail = dev_lim->hca.arbel.max_icm_sz;
125	} else {
126		mem_base  = dev->ddr_start;
127		mem_avail = dev->fw.tavor.fw_start - dev->ddr_start;
128	}
129
130	/*
131	 * Sort the resources in decreasing order of size.  Since they
132	 * all have sizes that are powers of 2, we'll be able to keep
133	 * resources aligned to their size and pack them without gaps
134	 * using the sorted order.
135	 */
136	for (i = MTHCA_RES_NUM; i > 0; --i)
137		for (j = 1; j < i; ++j) {
138			if (profile[j].size > profile[j - 1].size)
139				swap(profile[j], profile[j - 1]);
140		}
141
142	for (i = 0; i < MTHCA_RES_NUM; ++i) {
143		if (profile[i].size) {
144			profile[i].start = mem_base + total_size;
145			total_size      += profile[i].size;
146		}
147		if (total_size > mem_avail) {
148			mthca_err(dev, "Profile requires 0x%llx bytes; "
149				  "won't fit in 0x%llx bytes of context memory.\n",
150				  (unsigned long long) total_size,
151				  (unsigned long long) mem_avail);
152			kfree(profile);
153			return -ENOMEM;
154		}
155
156		if (profile[i].size)
157			mthca_dbg(dev, "profile[%2d]--%2d/%2d @ 0x%16llx "
158				  "(size 0x%8llx)\n",
159				  i, profile[i].type, profile[i].log_num,
160				  (unsigned long long) profile[i].start,
161				  (unsigned long long) profile[i].size);
162	}
163
164	if (mthca_is_memfree(dev))
165		mthca_dbg(dev, "HCA context memory: reserving %d KB\n",
166			  (int) (total_size >> 10));
167	else
168		mthca_dbg(dev, "HCA memory: allocated %d KB/%d KB (%d KB free)\n",
169			  (int) (total_size >> 10), (int) (mem_avail >> 10),
170			  (int) ((mem_avail - total_size) >> 10));
171
172	for (i = 0; i < MTHCA_RES_NUM; ++i) {
173		switch (profile[i].type) {
174		case MTHCA_RES_QP:
175			dev->limits.num_qps   = profile[i].num;
176			init_hca->qpc_base    = profile[i].start;
177			init_hca->log_num_qps = profile[i].log_num;
178			break;
179		case MTHCA_RES_EEC:
180			dev->limits.num_eecs   = profile[i].num;
181			init_hca->eec_base     = profile[i].start;
182			init_hca->log_num_eecs = profile[i].log_num;
183			break;
184		case MTHCA_RES_SRQ:
185			dev->limits.num_srqs   = profile[i].num;
186			init_hca->srqc_base    = profile[i].start;
187			init_hca->log_num_srqs = profile[i].log_num;
188			break;
189		case MTHCA_RES_CQ:
190			dev->limits.num_cqs   = profile[i].num;
191			init_hca->cqc_base    = profile[i].start;
192			init_hca->log_num_cqs = profile[i].log_num;
193			break;
194		case MTHCA_RES_EQP:
195			init_hca->eqpc_base = profile[i].start;
196			break;
197		case MTHCA_RES_EEEC:
198			init_hca->eeec_base = profile[i].start;
199			break;
200		case MTHCA_RES_EQ:
201			dev->limits.num_eqs   = profile[i].num;
202			init_hca->eqc_base    = profile[i].start;
203			init_hca->log_num_eqs = profile[i].log_num;
204			break;
205		case MTHCA_RES_RDB:
206			for (dev->qp_table.rdb_shift = 0;
207			     request->num_qp << dev->qp_table.rdb_shift < profile[i].num;
208			     ++dev->qp_table.rdb_shift)
209				; /* nothing */
210			dev->qp_table.rdb_base    = (u32) profile[i].start;
211			init_hca->rdb_base        = profile[i].start;
212			break;
213		case MTHCA_RES_MCG:
214			dev->limits.num_mgms      = profile[i].num >> 1;
215			dev->limits.num_amgms     = profile[i].num >> 1;
216			init_hca->mc_base         = profile[i].start;
217			init_hca->log_mc_entry_sz = ffs(MTHCA_MGM_ENTRY_SIZE) - 1;
218			init_hca->log_mc_table_sz = profile[i].log_num;
219			init_hca->mc_hash_sz      = 1 << (profile[i].log_num - 1);
220			break;
221		case MTHCA_RES_MPT:
222			dev->limits.num_mpts   = profile[i].num;
223			dev->mr_table.mpt_base = profile[i].start;
224			init_hca->mpt_base     = profile[i].start;
225			init_hca->log_mpt_sz   = profile[i].log_num;
226			break;
227		case MTHCA_RES_MTT:
228			dev->limits.num_mtt_segs = profile[i].num;
229			dev->mr_table.mtt_base   = profile[i].start;
230			init_hca->mtt_base       = profile[i].start;
231			init_hca->mtt_seg_sz     = ffs(dev->limits.mtt_seg_size) - 7;
232			break;
233		case MTHCA_RES_UAR:
234			dev->limits.num_uars       = profile[i].num;
235			init_hca->uar_scratch_base = profile[i].start;
236			break;
237		case MTHCA_RES_UDAV:
238			dev->av_table.ddr_av_base = profile[i].start;
239			dev->av_table.num_ddr_avs = profile[i].num;
240			break;
241		case MTHCA_RES_UARC:
242			dev->uar_table.uarc_size = request->uarc_size;
243			dev->uar_table.uarc_base = profile[i].start;
244			init_hca->uarc_base   	 = profile[i].start;
245			init_hca->log_uarc_sz 	 = ffs(request->uarc_size) - 13;
246			init_hca->log_uar_sz  	 = ffs(request->num_uar) - 1;
247			break;
248		default:
249			break;
250		}
251	}
252
253	/*
254	 * PDs don't take any HCA memory, but we assign them as part
255	 * of the HCA profile anyway.
256	 */
257	dev->limits.num_pds = MTHCA_NUM_PDS;
258
259	if (dev->mthca_flags & MTHCA_FLAG_SINAI_OPT &&
260	    init_hca->log_mpt_sz > 23) {
261		mthca_warn(dev, "MPT table too large (requested size 2^%d >= 2^24)\n",
262			   init_hca->log_mpt_sz);
263		mthca_warn(dev, "Disabling memory key throughput optimization.\n");
264		dev->mthca_flags &= ~MTHCA_FLAG_SINAI_OPT;
265	}
266
267	/*
268	 * For Tavor, FMRs use ioremapped PCI memory. For 32 bit
269	 * systems it may use too much vmalloc space to map all MTT
270	 * memory, so we reserve some MTTs for FMR access, taking them
271	 * out of the MR pool. They don't use additional memory, but
272	 * we assign them as part of the HCA profile anyway.
273	 */
274	if (mthca_is_memfree(dev) || BITS_PER_LONG == 64)
275		dev->limits.fmr_reserved_mtts = 0;
276	else
277		dev->limits.fmr_reserved_mtts = request->fmr_reserved_mtts;
278
279	kfree(profile);
280	return total_size;
281}