2007-05-09 08:00:38 +07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 Topspin Communications. All rights reserved.
|
2008-07-26 00:32:52 +07:00
|
|
|
* Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
|
2007-05-09 08:00:38 +07:00
|
|
|
* Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
2011-05-28 03:14:23 +07:00
|
|
|
#include <linux/export.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2011-12-13 11:13:48 +07:00
|
|
|
#include <linux/kernel.h>
|
2012-08-13 15:15:06 +07:00
|
|
|
#include <linux/vmalloc.h>
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
#include <linux/mlx4/cmd.h>
|
|
|
|
|
|
|
|
#include "mlx4.h"
|
|
|
|
#include "icm.h"
|
|
|
|
|
|
|
|
static u32 mlx4_buddy_alloc(struct mlx4_buddy *buddy, int order)
|
|
|
|
{
|
|
|
|
int o;
|
|
|
|
int m;
|
|
|
|
u32 seg;
|
|
|
|
|
|
|
|
spin_lock(&buddy->lock);
|
|
|
|
|
2008-07-23 04:19:40 +07:00
|
|
|
for (o = order; o <= buddy->max_order; ++o)
|
|
|
|
if (buddy->num_free[o]) {
|
|
|
|
m = 1 << (buddy->max_order - o);
|
|
|
|
seg = find_first_bit(buddy->bits[o], m);
|
|
|
|
if (seg < m)
|
|
|
|
goto found;
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
spin_unlock(&buddy->lock);
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
found:
|
|
|
|
clear_bit(seg, buddy->bits[o]);
|
2008-07-23 04:19:40 +07:00
|
|
|
--buddy->num_free[o];
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
while (o > order) {
|
|
|
|
--o;
|
|
|
|
seg <<= 1;
|
|
|
|
set_bit(seg ^ 1, buddy->bits[o]);
|
2008-07-23 04:19:40 +07:00
|
|
|
++buddy->num_free[o];
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&buddy->lock);
|
|
|
|
|
|
|
|
seg <<= order;
|
|
|
|
|
|
|
|
return seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
|
|
|
|
{
|
|
|
|
seg >>= order;
|
|
|
|
|
|
|
|
spin_lock(&buddy->lock);
|
|
|
|
|
|
|
|
while (test_bit(seg ^ 1, buddy->bits[order])) {
|
|
|
|
clear_bit(seg ^ 1, buddy->bits[order]);
|
2008-07-23 04:19:40 +07:00
|
|
|
--buddy->num_free[order];
|
2007-05-09 08:00:38 +07:00
|
|
|
seg >>= 1;
|
|
|
|
++order;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(seg, buddy->bits[order]);
|
2008-07-23 04:19:40 +07:00
|
|
|
++buddy->num_free[order];
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
spin_unlock(&buddy->lock);
|
|
|
|
}
|
|
|
|
|
2008-02-05 11:20:41 +07:00
|
|
|
static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
|
|
|
|
buddy->max_order = max_order;
|
|
|
|
spin_lock_init(&buddy->lock);
|
|
|
|
|
2012-08-15 05:17:10 +07:00
|
|
|
buddy->bits = kcalloc(buddy->max_order + 1, sizeof (long *),
|
2007-05-09 08:00:38 +07:00
|
|
|
GFP_KERNEL);
|
2011-10-06 23:33:12 +07:00
|
|
|
buddy->num_free = kcalloc((buddy->max_order + 1), sizeof *buddy->num_free,
|
2008-07-23 04:19:40 +07:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!buddy->bits || !buddy->num_free)
|
2007-05-09 08:00:38 +07:00
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
for (i = 0; i <= buddy->max_order; ++i) {
|
|
|
|
s = BITS_TO_LONGS(1 << (buddy->max_order - i));
|
2012-08-15 05:17:10 +07:00
|
|
|
buddy->bits[i] = kcalloc(s, sizeof (long), GFP_KERNEL | __GFP_NOWARN);
|
2012-08-13 15:15:06 +07:00
|
|
|
if (!buddy->bits[i]) {
|
2012-08-15 05:17:10 +07:00
|
|
|
buddy->bits[i] = vzalloc(s * sizeof(long));
|
2012-08-13 15:15:06 +07:00
|
|
|
if (!buddy->bits[i])
|
|
|
|
goto err_out_free;
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(0, buddy->bits[buddy->max_order]);
|
2008-07-23 04:19:40 +07:00
|
|
|
buddy->num_free[buddy->max_order] = 1;
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out_free:
|
|
|
|
for (i = 0; i <= buddy->max_order; ++i)
|
2012-08-13 15:15:06 +07:00
|
|
|
if (buddy->bits[i] && is_vmalloc_addr(buddy->bits[i]))
|
|
|
|
vfree(buddy->bits[i]);
|
|
|
|
else
|
|
|
|
kfree(buddy->bits[i]);
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2008-07-23 04:19:40 +07:00
|
|
|
err_out:
|
2007-05-09 08:00:38 +07:00
|
|
|
kfree(buddy->bits);
|
2008-07-23 04:19:40 +07:00
|
|
|
kfree(buddy->num_free);
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlx4_buddy_cleanup(struct mlx4_buddy *buddy)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i <= buddy->max_order; ++i)
|
2012-08-13 15:15:06 +07:00
|
|
|
if (is_vmalloc_addr(buddy->bits[i]))
|
|
|
|
vfree(buddy->bits[i]);
|
|
|
|
else
|
|
|
|
kfree(buddy->bits[i]);
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
kfree(buddy->bits);
|
2008-07-23 04:19:40 +07:00
|
|
|
kfree(buddy->num_free);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
mlx4_core: resource tracking for HCA resources used by guests
The resource tracker is used to track usage of HCA resources by the different
guests.
Virtual functions (VFs) are attached to guest operating systems but
resources are allocated from the same pool and are assigned to VFs. It is
essential that hostile/buggy guests not be able to affect the operation of
other VFs, possibly attached to other guest OSs since ConnectX firmware is not
tolerant to misuse of resources.
The resource tracker module associates each resource with a VF and maintains
state information for the allocated object. It also defines allowed state
transitions and enforces them.
Relationships between resources are also referred to. For example, CQs are
pointed to by QPs, so it is forbidden to destroy a CQ if a QP refers to it.
ICM memory is always accessible through the primary function and hence it is
allocated by the owner of the primary function.
When a guest dies, an FLR is generated for all the VFs it owns and all the
resources it used are freed.
The tracked resource types are: QPs, CQs, SRQs, MPTs, MTTs, MACs, RES_EQs,
and XRCDNs.
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-12-13 11:15:24 +07:00
|
|
|
u32 __mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
|
|
|
struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
|
|
|
|
u32 seg;
|
2011-12-13 11:16:56 +07:00
|
|
|
int seg_order;
|
|
|
|
u32 offset;
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
seg_order = max_t(int, order - log_mtts_per_seg, 0);
|
|
|
|
|
|
|
|
seg = mlx4_buddy_alloc(&mr_table->mtt_buddy, seg_order);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (seg == -1)
|
|
|
|
return -1;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
offset = seg * (1 << log_mtts_per_seg);
|
|
|
|
|
|
|
|
if (mlx4_table_get_range(dev, &mr_table->mtt_table, offset,
|
|
|
|
offset + (1 << order) - 1)) {
|
|
|
|
mlx4_buddy_free(&mr_table->mtt_buddy, seg, seg_order);
|
2007-05-09 08:00:38 +07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
return offset;
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:13:48 +07:00
|
|
|
static u32 mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
|
|
|
|
{
|
2013-03-07 10:46:54 +07:00
|
|
|
u64 in_param = 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
u64 out_param;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
set_param_l(&in_param, order);
|
|
|
|
err = mlx4_cmd_imm(dev, in_param, &out_param, RES_MTT,
|
|
|
|
RES_OP_RESERVE_AND_MAP,
|
|
|
|
MLX4_CMD_ALLOC_RES,
|
|
|
|
MLX4_CMD_TIME_CLASS_A,
|
|
|
|
MLX4_CMD_WRAPPED);
|
|
|
|
if (err)
|
|
|
|
return -1;
|
|
|
|
return get_param_l(&out_param);
|
|
|
|
}
|
|
|
|
return __mlx4_alloc_mtt_range(dev, order);
|
|
|
|
}
|
|
|
|
|
2007-05-09 08:00:38 +07:00
|
|
|
int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
|
|
|
|
struct mlx4_mtt *mtt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!npages) {
|
|
|
|
mtt->order = -1;
|
|
|
|
mtt->page_shift = MLX4_ICM_PAGE_SHIFT;
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
mtt->page_shift = page_shift;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
for (mtt->order = 0, i = 1; i < npages; i <<= 1)
|
2007-05-09 08:00:38 +07:00
|
|
|
++mtt->order;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
mtt->offset = mlx4_alloc_mtt_range(dev, mtt->order);
|
|
|
|
if (mtt->offset == -1)
|
2007-05-09 08:00:38 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mtt_init);
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
void __mlx4_free_mtt_range(struct mlx4_dev *dev, u32 offset, int order)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
2011-12-13 11:16:56 +07:00
|
|
|
u32 first_seg;
|
|
|
|
int seg_order;
|
2007-05-09 08:00:38 +07:00
|
|
|
struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
seg_order = max_t(int, order - log_mtts_per_seg, 0);
|
|
|
|
first_seg = offset / (1 << log_mtts_per_seg);
|
|
|
|
|
|
|
|
mlx4_buddy_free(&mr_table->mtt_buddy, first_seg, seg_order);
|
2012-01-02 11:07:39 +07:00
|
|
|
mlx4_table_put_range(dev, &mr_table->mtt_table, offset,
|
|
|
|
offset + (1 << order) - 1);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
static void mlx4_free_mtt_range(struct mlx4_dev *dev, u32 offset, int order)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
2013-03-07 10:46:54 +07:00
|
|
|
u64 in_param = 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
2011-12-13 11:16:56 +07:00
|
|
|
set_param_l(&in_param, offset);
|
2011-12-13 11:13:48 +07:00
|
|
|
set_param_h(&in_param, order);
|
|
|
|
err = mlx4_cmd(dev, in_param, RES_MTT, RES_OP_RESERVE_AND_MAP,
|
|
|
|
MLX4_CMD_FREE_RES,
|
|
|
|
MLX4_CMD_TIME_CLASS_A,
|
|
|
|
MLX4_CMD_WRAPPED);
|
|
|
|
if (err)
|
2014-05-08 02:52:57 +07:00
|
|
|
mlx4_warn(dev, "Failed to free mtt range at:%d order:%d\n",
|
|
|
|
offset, order);
|
2011-12-13 11:13:48 +07:00
|
|
|
return;
|
|
|
|
}
|
2011-12-13 11:16:56 +07:00
|
|
|
__mlx4_free_mtt_range(dev, offset, order);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
|
|
|
|
{
|
2007-05-09 08:00:38 +07:00
|
|
|
if (mtt->order < 0)
|
|
|
|
return;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
mlx4_free_mtt_range(dev, mtt->offset, mtt->order);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mtt_cleanup);
|
|
|
|
|
|
|
|
u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
|
|
|
|
{
|
2011-12-13 11:16:56 +07:00
|
|
|
return (u64) mtt->offset * dev->caps.mtt_entry_sz;
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mtt_addr);
|
|
|
|
|
|
|
|
static u32 hw_index_to_key(u32 ind)
|
|
|
|
{
|
|
|
|
return (ind >> 24) | (ind << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 key_to_hw_index(u32 key)
|
|
|
|
{
|
|
|
|
return (key << 24) | (key >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mlx4_SW2HW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
|
|
|
|
int mpt_index)
|
|
|
|
{
|
2012-01-19 16:45:19 +07:00
|
|
|
return mlx4_cmd(dev, mailbox->dma, mpt_index,
|
2011-12-13 11:13:48 +07:00
|
|
|
0, MLX4_CMD_SW2HW_MPT, MLX4_CMD_TIME_CLASS_B,
|
|
|
|
MLX4_CMD_WRAPPED);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mlx4_HW2SW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
|
|
|
|
int mpt_index)
|
|
|
|
{
|
|
|
|
return mlx4_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
|
2011-12-13 11:10:51 +07:00
|
|
|
!mailbox, MLX4_CMD_HW2SW_MPT,
|
|
|
|
MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:18:37 +07:00
|
|
|
/* Must protect against concurrent access */
|
2014-07-31 15:01:29 +07:00
|
|
|
int mlx4_mr_hw_get_mpt(struct mlx4_dev *dev, struct mlx4_mr *mmr,
|
|
|
|
struct mlx4_mpt_entry ***mpt_entry)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
int key = key_to_hw_index(mmr->key) & (dev->caps.num_mpts - 1);
|
|
|
|
struct mlx4_cmd_mailbox *mailbox = NULL;
|
|
|
|
|
|
|
|
if (mmr->enabled != MLX4_MPT_EN_HW)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = mlx4_HW2SW_MPT(dev, NULL, key);
|
|
|
|
if (err) {
|
|
|
|
mlx4_warn(dev, "HW2SW_MPT failed (%d).", err);
|
|
|
|
mlx4_warn(dev, "Most likely the MR has MWs bound to it.\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mmr->enabled = MLX4_MPT_EN_SW;
|
|
|
|
|
|
|
|
if (!mlx4_is_mfunc(dev)) {
|
|
|
|
**mpt_entry = mlx4_table_find(
|
|
|
|
&mlx4_priv(dev)->mr_table.dmpt_table,
|
|
|
|
key, NULL);
|
|
|
|
} else {
|
|
|
|
mailbox = mlx4_alloc_cmd_mailbox(dev);
|
|
|
|
if (IS_ERR_OR_NULL(mailbox))
|
|
|
|
return PTR_ERR(mailbox);
|
|
|
|
|
|
|
|
err = mlx4_cmd_box(dev, 0, mailbox->dma, key,
|
|
|
|
0, MLX4_CMD_QUERY_MPT,
|
|
|
|
MLX4_CMD_TIME_CLASS_B,
|
|
|
|
MLX4_CMD_WRAPPED);
|
|
|
|
if (err)
|
|
|
|
goto free_mailbox;
|
|
|
|
|
|
|
|
*mpt_entry = (struct mlx4_mpt_entry **)&mailbox->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*mpt_entry) || !(**mpt_entry)) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto free_mailbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_mailbox:
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_hw_get_mpt);
|
|
|
|
|
|
|
|
int mlx4_mr_hw_write_mpt(struct mlx4_dev *dev, struct mlx4_mr *mmr,
|
|
|
|
struct mlx4_mpt_entry **mpt_entry)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (!mlx4_is_mfunc(dev)) {
|
|
|
|
/* Make sure any changes to this entry are flushed */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
*(u8 *)(*mpt_entry) = MLX4_MPT_STATUS_HW;
|
|
|
|
|
|
|
|
/* Make sure the new status is written */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
err = mlx4_SYNC_TPT(dev);
|
|
|
|
} else {
|
|
|
|
int key = key_to_hw_index(mmr->key) & (dev->caps.num_mpts - 1);
|
|
|
|
|
|
|
|
struct mlx4_cmd_mailbox *mailbox =
|
|
|
|
container_of((void *)mpt_entry, struct mlx4_cmd_mailbox,
|
|
|
|
buf);
|
|
|
|
|
|
|
|
err = mlx4_SW2HW_MPT(dev, mailbox, key);
|
|
|
|
}
|
|
|
|
|
2014-09-11 17:18:37 +07:00
|
|
|
if (!err) {
|
|
|
|
mmr->pd = be32_to_cpu((*mpt_entry)->pd_flags) & MLX4_MPT_PD_MASK;
|
2014-07-31 15:01:29 +07:00
|
|
|
mmr->enabled = MLX4_MPT_EN_HW;
|
2014-09-11 17:18:37 +07:00
|
|
|
}
|
2014-07-31 15:01:29 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_hw_write_mpt);
|
|
|
|
|
|
|
|
void mlx4_mr_hw_put_mpt(struct mlx4_dev *dev,
|
|
|
|
struct mlx4_mpt_entry **mpt_entry)
|
|
|
|
{
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
struct mlx4_cmd_mailbox *mailbox =
|
|
|
|
container_of((void *)mpt_entry, struct mlx4_cmd_mailbox,
|
|
|
|
buf);
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_hw_put_mpt);
|
|
|
|
|
|
|
|
int mlx4_mr_hw_change_pd(struct mlx4_dev *dev, struct mlx4_mpt_entry *mpt_entry,
|
|
|
|
u32 pdn)
|
|
|
|
{
|
2014-09-11 17:18:37 +07:00
|
|
|
u32 pd_flags = be32_to_cpu(mpt_entry->pd_flags) & ~MLX4_MPT_PD_MASK;
|
2014-07-31 15:01:29 +07:00
|
|
|
/* The wrapper function will put the slave's id here */
|
|
|
|
if (mlx4_is_mfunc(dev))
|
|
|
|
pd_flags &= ~MLX4_MPT_PD_VF_MASK;
|
2014-09-11 17:18:37 +07:00
|
|
|
|
|
|
|
mpt_entry->pd_flags = cpu_to_be32(pd_flags |
|
2014-07-31 15:01:29 +07:00
|
|
|
(pdn & MLX4_MPT_PD_MASK)
|
|
|
|
| MLX4_MPT_PD_FLAG_EN_INV);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_hw_change_pd);
|
|
|
|
|
|
|
|
int mlx4_mr_hw_change_access(struct mlx4_dev *dev,
|
|
|
|
struct mlx4_mpt_entry *mpt_entry,
|
|
|
|
u32 access)
|
|
|
|
{
|
|
|
|
u32 flags = (be32_to_cpu(mpt_entry->flags) & ~MLX4_PERM_MASK) |
|
|
|
|
(access & MLX4_PERM_MASK);
|
|
|
|
|
|
|
|
mpt_entry->flags = cpu_to_be32(flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_hw_change_access);
|
|
|
|
|
2012-03-06 11:05:02 +07:00
|
|
|
static int mlx4_mr_alloc_reserved(struct mlx4_dev *dev, u32 mridx, u32 pd,
|
2011-12-13 11:13:48 +07:00
|
|
|
u64 iova, u64 size, u32 access, int npages,
|
|
|
|
int page_shift, struct mlx4_mr *mr)
|
|
|
|
{
|
2007-05-09 08:00:38 +07:00
|
|
|
mr->iova = iova;
|
|
|
|
mr->size = size;
|
|
|
|
mr->pd = pd;
|
|
|
|
mr->access = access;
|
2013-02-06 23:19:08 +07:00
|
|
|
mr->enabled = MLX4_MPT_DISABLED;
|
2011-12-13 11:13:48 +07:00
|
|
|
mr->key = hw_index_to_key(mridx);
|
|
|
|
|
|
|
|
return mlx4_mtt_init(dev, npages, page_shift, &mr->mtt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mlx4_WRITE_MTT(struct mlx4_dev *dev,
|
|
|
|
struct mlx4_cmd_mailbox *mailbox,
|
|
|
|
int num_entries)
|
|
|
|
{
|
|
|
|
return mlx4_cmd(dev, mailbox->dma, num_entries, 0, MLX4_CMD_WRITE_MTT,
|
|
|
|
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
|
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
int __mlx4_mpt_reserve(struct mlx4_dev *dev)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
|
|
|
|
return mlx4_bitmap_alloc(&priv->mr_table.mpt_bitmap);
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
static int mlx4_mpt_reserve(struct mlx4_dev *dev)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
|
|
|
u64 out_param;
|
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
if (mlx4_cmd_imm(dev, 0, &out_param, RES_MPT, RES_OP_RESERVE,
|
|
|
|
MLX4_CMD_ALLOC_RES,
|
|
|
|
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED))
|
|
|
|
return -1;
|
|
|
|
return get_param_l(&out_param);
|
|
|
|
}
|
2013-02-06 23:19:08 +07:00
|
|
|
return __mlx4_mpt_reserve(dev);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
void __mlx4_mpt_release(struct mlx4_dev *dev, u32 index)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
|
mlx4_core: Roll back round robin bitmap allocation commit for CQs, SRQs, and MPTs
Commit f4ec9e9 "mlx4_core: Change bitmap allocator to work in round-robin fashion"
introduced round-robin allocation (via bitmap) for all resources which allocate
via a bitmap.
Round robin allocation is desirable for mcgs, counters, pd's, UARs, and xrcds.
These are simply numbers, with no involvement of ICM memory mapping.
Round robin is required for QPs, since we had a problem with immediate
reuse of a 24-bit QP number (commit f4ec9e9).
However, for other resources which use the bitmap allocator and involve
mapping ICM memory -- MPTs, CQs, SRQs -- round-robin is not desirable.
What happens in these cases is the following:
ICM memory is allocated and mapped in chunks of 256K.
Since the resource allocation index goes up monotonically, the allocator
will eventually require mapping a new chunk. Now, chunks are also unmapped
when their reference count goes back to zero. Thus, if a single app is
running and starts/exits frequently we will have the following situation:
When the app starts, a new chunk must be allocated and mapped.
When the app exits, the chunk reference count goes back to zero, and the
chunk is unmapped and freed. Therefore, the app must pay the cost of allocation
and mapping of ICM memory each time it runs (although the price is paid only when
allocating the initial entry in the new chunk).
For apps which allocate MPTs/SRQs/CQs and which operate as described above,
this presented a performance problem.
We therefore roll back the round-robin allocator modification for MPTs, CQs, SRQs.
Reported-by: Matthew Finlay <matt@mellanox.com>
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-08 21:50:17 +07:00
|
|
|
mlx4_bitmap_free(&priv->mr_table.mpt_bitmap, index, MLX4_NO_RR);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
static void mlx4_mpt_release(struct mlx4_dev *dev, u32 index)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
2013-03-07 10:46:54 +07:00
|
|
|
u64 in_param = 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
set_param_l(&in_param, index);
|
|
|
|
if (mlx4_cmd(dev, in_param, RES_MPT, RES_OP_RESERVE,
|
|
|
|
MLX4_CMD_FREE_RES,
|
|
|
|
MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED))
|
|
|
|
mlx4_warn(dev, "Failed to release mr index:%d\n",
|
|
|
|
index);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-06 23:19:08 +07:00
|
|
|
__mlx4_mpt_release(dev, index);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
int __mlx4_mpt_alloc_icm(struct mlx4_dev *dev, u32 index, gfp_t gfp)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
|
|
|
struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
return mlx4_table_get(dev, &mr_table->dmpt_table, index, gfp);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
static int mlx4_mpt_alloc_icm(struct mlx4_dev *dev, u32 index, gfp_t gfp)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
2013-03-07 10:46:54 +07:00
|
|
|
u64 param = 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
set_param_l(¶m, index);
|
|
|
|
return mlx4_cmd_imm(dev, param, ¶m, RES_MPT, RES_OP_MAP_ICM,
|
|
|
|
MLX4_CMD_ALLOC_RES,
|
|
|
|
MLX4_CMD_TIME_CLASS_A,
|
|
|
|
MLX4_CMD_WRAPPED);
|
|
|
|
}
|
2014-05-11 19:15:12 +07:00
|
|
|
return __mlx4_mpt_alloc_icm(dev, index, gfp);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
void __mlx4_mpt_free_icm(struct mlx4_dev *dev, u32 index)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
|
|
|
struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
|
|
|
|
|
|
|
|
mlx4_table_put(dev, &mr_table->dmpt_table, index);
|
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
static void mlx4_mpt_free_icm(struct mlx4_dev *dev, u32 index)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
2013-03-07 10:46:54 +07:00
|
|
|
u64 in_param = 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
set_param_l(&in_param, index);
|
|
|
|
if (mlx4_cmd(dev, in_param, RES_MPT, RES_OP_MAP_ICM,
|
|
|
|
MLX4_CMD_FREE_RES, MLX4_CMD_TIME_CLASS_A,
|
|
|
|
MLX4_CMD_WRAPPED))
|
|
|
|
mlx4_warn(dev, "Failed to free icm of mr index:%d\n",
|
|
|
|
index);
|
|
|
|
return;
|
|
|
|
}
|
2013-02-06 23:19:08 +07:00
|
|
|
return __mlx4_mpt_free_icm(dev, index);
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
|
|
|
|
int npages, int page_shift, struct mlx4_mr *mr)
|
|
|
|
{
|
|
|
|
u32 index;
|
|
|
|
int err;
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
index = mlx4_mpt_reserve(dev);
|
2011-12-13 11:13:48 +07:00
|
|
|
if (index == -1)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = mlx4_mr_alloc_reserved(dev, index, pd, iova, size,
|
|
|
|
access, npages, page_shift, mr);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (err)
|
2013-02-06 23:19:08 +07:00
|
|
|
mlx4_mpt_release(dev, index);
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_alloc);
|
|
|
|
|
2013-02-06 23:19:09 +07:00
|
|
|
static int mlx4_mr_free_reserved(struct mlx4_dev *dev, struct mlx4_mr *mr)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
if (mr->enabled == MLX4_MPT_EN_HW) {
|
2007-05-09 08:00:38 +07:00
|
|
|
err = mlx4_HW2SW_MPT(dev, NULL,
|
|
|
|
key_to_hw_index(mr->key) &
|
|
|
|
(dev->caps.num_mpts - 1));
|
2013-02-06 23:19:09 +07:00
|
|
|
if (err) {
|
2014-05-08 02:52:57 +07:00
|
|
|
mlx4_warn(dev, "HW2SW_MPT failed (%d), MR has MWs bound to it\n",
|
|
|
|
err);
|
2013-02-06 23:19:09 +07:00
|
|
|
return err;
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2013-02-06 23:19:08 +07:00
|
|
|
mr->enabled = MLX4_MPT_EN_SW;
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
mlx4_mtt_cleanup(dev, &mr->mtt);
|
2013-02-06 23:19:09 +07:00
|
|
|
|
|
|
|
return 0;
|
2011-12-13 11:13:48 +07:00
|
|
|
}
|
|
|
|
|
2013-02-06 23:19:09 +07:00
|
|
|
int mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr)
|
2011-12-13 11:13:48 +07:00
|
|
|
{
|
2013-02-06 23:19:09 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mlx4_mr_free_reserved(dev, mr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-12-13 11:13:48 +07:00
|
|
|
if (mr->enabled)
|
2013-02-06 23:19:08 +07:00
|
|
|
mlx4_mpt_free_icm(dev, key_to_hw_index(mr->key));
|
|
|
|
mlx4_mpt_release(dev, key_to_hw_index(mr->key));
|
2013-02-06 23:19:09 +07:00
|
|
|
|
|
|
|
return 0;
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_free);
|
|
|
|
|
2014-07-31 15:01:29 +07:00
|
|
|
void mlx4_mr_rereg_mem_cleanup(struct mlx4_dev *dev, struct mlx4_mr *mr)
|
|
|
|
{
|
|
|
|
mlx4_mtt_cleanup(dev, &mr->mtt);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_rereg_mem_cleanup);
|
|
|
|
|
|
|
|
int mlx4_mr_rereg_mem_write(struct mlx4_dev *dev, struct mlx4_mr *mr,
|
|
|
|
u64 iova, u64 size, int npages,
|
|
|
|
int page_shift, struct mlx4_mpt_entry *mpt_entry)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2014-09-11 17:18:37 +07:00
|
|
|
mpt_entry->start = cpu_to_be64(iova);
|
|
|
|
mpt_entry->length = cpu_to_be64(size);
|
|
|
|
mpt_entry->entity_size = cpu_to_be32(page_shift);
|
2014-07-31 15:01:29 +07:00
|
|
|
|
|
|
|
err = mlx4_mtt_init(dev, npages, page_shift, &mr->mtt);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2014-09-11 17:18:37 +07:00
|
|
|
mpt_entry->pd_flags &= cpu_to_be32(MLX4_MPT_PD_MASK |
|
|
|
|
MLX4_MPT_PD_FLAG_EN_INV);
|
|
|
|
mpt_entry->flags &= cpu_to_be32(MLX4_MPT_FLAG_FREE |
|
|
|
|
MLX4_MPT_FLAG_SW_OWNS);
|
2014-07-31 15:01:29 +07:00
|
|
|
if (mr->mtt.order < 0) {
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL);
|
|
|
|
mpt_entry->mtt_addr = 0;
|
|
|
|
} else {
|
|
|
|
mpt_entry->mtt_addr = cpu_to_be64(mlx4_mtt_addr(dev,
|
|
|
|
&mr->mtt));
|
|
|
|
if (mr->mtt.page_shift == 0)
|
|
|
|
mpt_entry->mtt_sz = cpu_to_be32(1 << mr->mtt.order);
|
|
|
|
}
|
2014-09-11 17:18:37 +07:00
|
|
|
if (mr->mtt.order >= 0 && mr->mtt.page_shift == 0) {
|
|
|
|
/* fast register MR in free state */
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_FREE);
|
|
|
|
mpt_entry->pd_flags |= cpu_to_be32(MLX4_MPT_PD_FLAG_FAST_REG |
|
|
|
|
MLX4_MPT_PD_FLAG_RAE);
|
|
|
|
} else {
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS);
|
|
|
|
}
|
2014-07-31 15:01:29 +07:00
|
|
|
mr->enabled = MLX4_MPT_EN_SW;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_rereg_mem_write);
|
|
|
|
|
2007-05-09 08:00:38 +07:00
|
|
|
int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr)
|
|
|
|
{
|
|
|
|
struct mlx4_cmd_mailbox *mailbox;
|
|
|
|
struct mlx4_mpt_entry *mpt_entry;
|
|
|
|
int err;
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
err = mlx4_mpt_alloc_icm(dev, key_to_hw_index(mr->key), GFP_KERNEL);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
mailbox = mlx4_alloc_cmd_mailbox(dev);
|
|
|
|
if (IS_ERR(mailbox)) {
|
|
|
|
err = PTR_ERR(mailbox);
|
|
|
|
goto err_table;
|
|
|
|
}
|
|
|
|
mpt_entry = mailbox->buf;
|
2008-07-23 22:12:26 +07:00
|
|
|
mpt_entry->flags = cpu_to_be32(MLX4_MPT_FLAG_MIO |
|
2007-05-09 08:00:38 +07:00
|
|
|
MLX4_MPT_FLAG_REGION |
|
|
|
|
mr->access);
|
|
|
|
|
|
|
|
mpt_entry->key = cpu_to_be32(key_to_hw_index(mr->key));
|
2008-07-23 22:12:26 +07:00
|
|
|
mpt_entry->pd_flags = cpu_to_be32(mr->pd | MLX4_MPT_PD_FLAG_EN_INV);
|
2007-05-09 08:00:38 +07:00
|
|
|
mpt_entry->start = cpu_to_be64(mr->iova);
|
|
|
|
mpt_entry->length = cpu_to_be64(mr->size);
|
|
|
|
mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift);
|
2008-07-23 22:12:26 +07:00
|
|
|
|
2007-06-08 13:24:38 +07:00
|
|
|
if (mr->mtt.order < 0) {
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL);
|
2011-12-13 11:16:56 +07:00
|
|
|
mpt_entry->mtt_addr = 0;
|
2008-07-23 22:12:26 +07:00
|
|
|
} else {
|
2011-12-13 11:16:56 +07:00
|
|
|
mpt_entry->mtt_addr = cpu_to_be64(mlx4_mtt_addr(dev,
|
|
|
|
&mr->mtt));
|
2008-07-23 22:12:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mr->mtt.order >= 0 && mr->mtt.page_shift == 0) {
|
|
|
|
/* fast register MR in free state */
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_FREE);
|
2008-09-03 03:38:29 +07:00
|
|
|
mpt_entry->pd_flags |= cpu_to_be32(MLX4_MPT_PD_FLAG_FAST_REG |
|
|
|
|
MLX4_MPT_PD_FLAG_RAE);
|
2011-12-13 11:16:56 +07:00
|
|
|
mpt_entry->mtt_sz = cpu_to_be32(1 << mr->mtt.order);
|
2008-07-23 22:12:26 +07:00
|
|
|
} else {
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS);
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
err = mlx4_SW2HW_MPT(dev, mailbox,
|
|
|
|
key_to_hw_index(mr->key) & (dev->caps.num_mpts - 1));
|
|
|
|
if (err) {
|
|
|
|
mlx4_warn(dev, "SW2HW_MPT failed (%d)\n", err);
|
|
|
|
goto err_cmd;
|
|
|
|
}
|
2013-02-06 23:19:08 +07:00
|
|
|
mr->enabled = MLX4_MPT_EN_HW;
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_cmd:
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
|
|
|
|
err_table:
|
2013-02-06 23:19:08 +07:00
|
|
|
mlx4_mpt_free_icm(dev, key_to_hw_index(mr->key));
|
2007-05-09 08:00:38 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mr_enable);
|
|
|
|
|
2007-08-01 16:28:53 +07:00
|
|
|
static int mlx4_write_mtt_chunk(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
|
|
|
|
int start_index, int npages, u64 *page_list)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
2007-08-01 16:28:53 +07:00
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
__be64 *mtts;
|
|
|
|
dma_addr_t dma_handle;
|
|
|
|
int i;
|
|
|
|
|
2011-12-13 11:16:56 +07:00
|
|
|
mtts = mlx4_table_find(&priv->mr_table.mtt_table, mtt->offset +
|
|
|
|
start_index, &dma_handle);
|
2007-08-01 16:28:53 +07:00
|
|
|
|
|
|
|
if (!mtts)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-06-23 13:07:56 +07:00
|
|
|
dma_sync_single_for_cpu(&dev->pdev->dev, dma_handle,
|
|
|
|
npages * sizeof (u64), DMA_TO_DEVICE);
|
|
|
|
|
2007-08-01 16:28:53 +07:00
|
|
|
for (i = 0; i < npages; ++i)
|
|
|
|
mtts[i] = cpu_to_be64(page_list[i] | MLX4_MTT_FLAG_PRESENT);
|
|
|
|
|
2009-06-23 13:07:56 +07:00
|
|
|
dma_sync_single_for_device(&dev->pdev->dev, dma_handle,
|
|
|
|
npages * sizeof (u64), DMA_TO_DEVICE);
|
2007-08-01 16:28:53 +07:00
|
|
|
|
|
|
|
return 0;
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
|
mlx4_core: resource tracking for HCA resources used by guests
The resource tracker is used to track usage of HCA resources by the different
guests.
Virtual functions (VFs) are attached to guest operating systems but
resources are allocated from the same pool and are assigned to VFs. It is
essential that hostile/buggy guests not be able to affect the operation of
other VFs, possibly attached to other guest OSs since ConnectX firmware is not
tolerant to misuse of resources.
The resource tracker module associates each resource with a VF and maintains
state information for the allocated object. It also defines allowed state
transitions and enforces them.
Relationships between resources are also referred to. For example, CQs are
pointed to by QPs, so it is forbidden to destroy a CQ if a QP refers to it.
ICM memory is always accessible through the primary function and hence it is
allocated by the owner of the primary function.
When a guest dies, an FLR is generated for all the VFs it owns and all the
resources it used are freed.
The tracked resource types are: QPs, CQs, SRQs, MPTs, MTTs, MACs, RES_EQs,
and XRCDNs.
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: David S. Miller <davem@davemloft.net>
2011-12-13 11:15:24 +07:00
|
|
|
int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
|
2011-12-13 11:13:48 +07:00
|
|
|
int start_index, int npages, u64 *page_list)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
2011-12-13 11:13:48 +07:00
|
|
|
int err = 0;
|
2007-08-01 16:28:53 +07:00
|
|
|
int chunk;
|
2011-12-13 11:16:56 +07:00
|
|
|
int mtts_per_page;
|
|
|
|
int max_mtts_first_page;
|
|
|
|
|
|
|
|
/* compute how may mtts fit in the first page */
|
|
|
|
mtts_per_page = PAGE_SIZE / sizeof(u64);
|
|
|
|
max_mtts_first_page = mtts_per_page - (mtt->offset + start_index)
|
|
|
|
% mtts_per_page;
|
|
|
|
|
|
|
|
chunk = min_t(int, max_mtts_first_page, npages);
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
while (npages > 0) {
|
2007-08-01 16:28:53 +07:00
|
|
|
err = mlx4_write_mtt_chunk(dev, mtt, start_index, chunk, page_list);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (err)
|
2007-08-01 16:28:53 +07:00
|
|
|
return err;
|
|
|
|
npages -= chunk;
|
|
|
|
start_index += chunk;
|
|
|
|
page_list += chunk;
|
2011-12-13 11:16:56 +07:00
|
|
|
|
|
|
|
chunk = min_t(int, mtts_per_page, npages);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
2011-12-13 11:13:48 +07:00
|
|
|
return err;
|
|
|
|
}
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2011-12-13 11:13:48 +07:00
|
|
|
int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
|
|
|
|
int start_index, int npages, u64 *page_list)
|
|
|
|
{
|
|
|
|
struct mlx4_cmd_mailbox *mailbox = NULL;
|
|
|
|
__be64 *inbox = NULL;
|
|
|
|
int chunk;
|
|
|
|
int err = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (mtt->order < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (mlx4_is_mfunc(dev)) {
|
|
|
|
mailbox = mlx4_alloc_cmd_mailbox(dev);
|
|
|
|
if (IS_ERR(mailbox))
|
|
|
|
return PTR_ERR(mailbox);
|
|
|
|
inbox = mailbox->buf;
|
|
|
|
|
|
|
|
while (npages > 0) {
|
2011-12-13 11:16:56 +07:00
|
|
|
chunk = min_t(int, MLX4_MAILBOX_SIZE / sizeof(u64) - 2,
|
|
|
|
npages);
|
|
|
|
inbox[0] = cpu_to_be64(mtt->offset + start_index);
|
2011-12-13 11:13:48 +07:00
|
|
|
inbox[1] = 0;
|
|
|
|
for (i = 0; i < chunk; ++i)
|
|
|
|
inbox[i + 2] = cpu_to_be64(page_list[i] |
|
|
|
|
MLX4_MTT_FLAG_PRESENT);
|
|
|
|
err = mlx4_WRITE_MTT(dev, mailbox, chunk);
|
|
|
|
if (err) {
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
npages -= chunk;
|
|
|
|
start_index += chunk;
|
|
|
|
page_list += chunk;
|
|
|
|
}
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return __mlx4_write_mtt(dev, mtt, start_index, npages, page_list);
|
2007-05-09 08:00:38 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_write_mtt);
|
|
|
|
|
|
|
|
int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
|
2014-05-11 19:15:12 +07:00
|
|
|
struct mlx4_buf *buf, gfp_t gfp)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
|
|
|
u64 *page_list;
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
page_list = kmalloc(buf->npages * sizeof *page_list,
|
|
|
|
gfp);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (!page_list)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < buf->npages; ++i)
|
|
|
|
if (buf->nbufs == 1)
|
2008-02-07 12:17:59 +07:00
|
|
|
page_list[i] = buf->direct.map + (i << buf->page_shift);
|
2007-05-09 08:00:38 +07:00
|
|
|
else
|
2008-02-07 12:17:59 +07:00
|
|
|
page_list[i] = buf->page_list[i].map;
|
2007-05-09 08:00:38 +07:00
|
|
|
|
|
|
|
err = mlx4_write_mtt(dev, mtt, 0, buf->npages, page_list);
|
|
|
|
|
|
|
|
kfree(page_list);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_buf_write_mtt);
|
|
|
|
|
2013-02-06 23:19:14 +07:00
|
|
|
int mlx4_mw_alloc(struct mlx4_dev *dev, u32 pd, enum mlx4_mw_type type,
|
|
|
|
struct mlx4_mw *mw)
|
|
|
|
{
|
|
|
|
u32 index;
|
|
|
|
|
|
|
|
if ((type == MLX4_MW_TYPE_1 &&
|
|
|
|
!(dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW)) ||
|
|
|
|
(type == MLX4_MW_TYPE_2 &&
|
|
|
|
!(dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN)))
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
|
|
|
index = mlx4_mpt_reserve(dev);
|
|
|
|
if (index == -1)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mw->key = hw_index_to_key(index);
|
|
|
|
mw->pd = pd;
|
|
|
|
mw->type = type;
|
|
|
|
mw->enabled = MLX4_MPT_DISABLED;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mw_alloc);
|
|
|
|
|
|
|
|
int mlx4_mw_enable(struct mlx4_dev *dev, struct mlx4_mw *mw)
|
|
|
|
{
|
|
|
|
struct mlx4_cmd_mailbox *mailbox;
|
|
|
|
struct mlx4_mpt_entry *mpt_entry;
|
|
|
|
int err;
|
|
|
|
|
2014-05-11 19:15:12 +07:00
|
|
|
err = mlx4_mpt_alloc_icm(dev, key_to_hw_index(mw->key), GFP_KERNEL);
|
2013-02-06 23:19:14 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
mailbox = mlx4_alloc_cmd_mailbox(dev);
|
|
|
|
if (IS_ERR(mailbox)) {
|
|
|
|
err = PTR_ERR(mailbox);
|
|
|
|
goto err_table;
|
|
|
|
}
|
|
|
|
mpt_entry = mailbox->buf;
|
|
|
|
|
|
|
|
/* Note that the MLX4_MPT_FLAG_REGION bit in mpt_entry->flags is turned
|
|
|
|
* off, thus creating a memory window and not a memory region.
|
|
|
|
*/
|
|
|
|
mpt_entry->key = cpu_to_be32(key_to_hw_index(mw->key));
|
|
|
|
mpt_entry->pd_flags = cpu_to_be32(mw->pd);
|
|
|
|
if (mw->type == MLX4_MW_TYPE_2) {
|
|
|
|
mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_FREE);
|
|
|
|
mpt_entry->qpn = cpu_to_be32(MLX4_MPT_QP_FLAG_BOUND_QP);
|
|
|
|
mpt_entry->pd_flags |= cpu_to_be32(MLX4_MPT_PD_FLAG_EN_INV);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mlx4_SW2HW_MPT(dev, mailbox,
|
|
|
|
key_to_hw_index(mw->key) &
|
|
|
|
(dev->caps.num_mpts - 1));
|
|
|
|
if (err) {
|
|
|
|
mlx4_warn(dev, "SW2HW_MPT failed (%d)\n", err);
|
|
|
|
goto err_cmd;
|
|
|
|
}
|
|
|
|
mw->enabled = MLX4_MPT_EN_HW;
|
|
|
|
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_cmd:
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
|
|
|
|
err_table:
|
|
|
|
mlx4_mpt_free_icm(dev, key_to_hw_index(mw->key));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mw_enable);
|
|
|
|
|
|
|
|
void mlx4_mw_free(struct mlx4_dev *dev, struct mlx4_mw *mw)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (mw->enabled == MLX4_MPT_EN_HW) {
|
|
|
|
err = mlx4_HW2SW_MPT(dev, NULL,
|
|
|
|
key_to_hw_index(mw->key) &
|
|
|
|
(dev->caps.num_mpts - 1));
|
|
|
|
if (err)
|
|
|
|
mlx4_warn(dev, "xxx HW2SW_MPT failed (%d)\n", err);
|
|
|
|
|
|
|
|
mw->enabled = MLX4_MPT_EN_SW;
|
|
|
|
}
|
|
|
|
if (mw->enabled)
|
|
|
|
mlx4_mpt_free_icm(dev, key_to_hw_index(mw->key));
|
|
|
|
mlx4_mpt_release(dev, key_to_hw_index(mw->key));
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_mw_free);
|
|
|
|
|
2007-10-11 05:43:54 +07:00
|
|
|
int mlx4_init_mr_table(struct mlx4_dev *dev)
|
2007-05-09 08:00:38 +07:00
|
|
|
{
|
2011-12-13 11:13:48 +07:00
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
struct mlx4_mr_table *mr_table = &priv->mr_table;
|
2007-05-09 08:00:38 +07:00
|
|
|
int err;
|
|
|
|
|
2011-12-13 11:13:48 +07:00
|
|
|
/* Nothing to do for slaves - all MR handling is forwarded
|
|
|
|
* to the master */
|
|
|
|
if (mlx4_is_slave(dev))
|
|
|
|
return 0;
|
|
|
|
|
2013-11-03 15:03:22 +07:00
|
|
|
if (!is_power_of_2(dev->caps.num_mpts))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-05-09 08:00:38 +07:00
|
|
|
err = mlx4_bitmap_init(&mr_table->mpt_bitmap, dev->caps.num_mpts,
|
2008-10-23 00:25:29 +07:00
|
|
|
~0, dev->caps.reserved_mrws, 0);
|
2007-05-09 08:00:38 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mlx4_buddy_init(&mr_table->mtt_buddy,
|
2012-08-13 15:15:07 +07:00
|
|
|
ilog2((u32)dev->caps.num_mtts /
|
2011-12-13 11:16:56 +07:00
|
|
|
(1 << log_mtts_per_seg)));
|
2007-05-09 08:00:38 +07:00
|
|
|
if (err)
|
|
|
|
goto err_buddy;
|
|
|
|
|
|
|
|
if (dev->caps.reserved_mtts) {
|
2011-12-13 11:13:48 +07:00
|
|
|
priv->reserved_mtts =
|
|
|
|
mlx4_alloc_mtt_range(dev,
|
|
|
|
fls(dev->caps.reserved_mtts - 1));
|
|
|
|
if (priv->reserved_mtts < 0) {
|
2014-05-08 02:52:57 +07:00
|
|
|
mlx4_warn(dev, "MTT table of order %u is too small\n",
|
2007-05-09 08:00:38 +07:00
|
|
|
mr_table->mtt_buddy.max_order);
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_reserve_mtts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_reserve_mtts:
|
|
|
|
mlx4_buddy_cleanup(&mr_table->mtt_buddy);
|
|
|
|
|
|
|
|
err_buddy:
|
|
|
|
mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mlx4_cleanup_mr_table(struct mlx4_dev *dev)
|
|
|
|
{
|
2011-12-13 11:13:48 +07:00
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
struct mlx4_mr_table *mr_table = &priv->mr_table;
|
2007-05-09 08:00:38 +07:00
|
|
|
|
2011-12-13 11:13:48 +07:00
|
|
|
if (mlx4_is_slave(dev))
|
|
|
|
return;
|
|
|
|
if (priv->reserved_mtts >= 0)
|
|
|
|
mlx4_free_mtt_range(dev, priv->reserved_mtts,
|
|
|
|
fls(dev->caps.reserved_mtts - 1));
|
2007-05-09 08:00:38 +07:00
|
|
|
mlx4_buddy_cleanup(&mr_table->mtt_buddy);
|
|
|
|
mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
|
|
|
|
}
|
2007-08-01 16:29:05 +07:00
|
|
|
|
|
|
|
static inline int mlx4_check_fmr(struct mlx4_fmr *fmr, u64 *page_list,
|
|
|
|
int npages, u64 iova)
|
|
|
|
{
|
|
|
|
int i, page_mask;
|
|
|
|
|
|
|
|
if (npages > fmr->max_pages)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
page_mask = (1 << fmr->page_shift) - 1;
|
|
|
|
|
|
|
|
/* We are getting page lists, so va must be page aligned. */
|
|
|
|
if (iova & page_mask)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Trust the user not to pass misaligned data in page_list */
|
|
|
|
if (0)
|
|
|
|
for (i = 0; i < npages; ++i) {
|
|
|
|
if (page_list[i] & ~page_mask)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmr->maps >= fmr->max_maps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mlx4_map_phys_fmr(struct mlx4_dev *dev, struct mlx4_fmr *fmr, u64 *page_list,
|
|
|
|
int npages, u64 iova, u32 *lkey, u32 *rkey)
|
|
|
|
{
|
|
|
|
u32 key;
|
|
|
|
int i, err;
|
|
|
|
|
|
|
|
err = mlx4_check_fmr(fmr, page_list, npages, iova);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
++fmr->maps;
|
|
|
|
|
|
|
|
key = key_to_hw_index(fmr->mr.key);
|
|
|
|
key += dev->caps.num_mpts;
|
|
|
|
*lkey = *rkey = fmr->mr.key = hw_index_to_key(key);
|
|
|
|
|
|
|
|
*(u8 *) fmr->mpt = MLX4_MPT_STATUS_SW;
|
|
|
|
|
|
|
|
/* Make sure MPT status is visible before writing MTT entries */
|
|
|
|
wmb();
|
|
|
|
|
2009-06-23 13:07:56 +07:00
|
|
|
dma_sync_single_for_cpu(&dev->pdev->dev, fmr->dma_handle,
|
|
|
|
npages * sizeof(u64), DMA_TO_DEVICE);
|
|
|
|
|
2007-08-01 16:29:05 +07:00
|
|
|
for (i = 0; i < npages; ++i)
|
|
|
|
fmr->mtts[i] = cpu_to_be64(page_list[i] | MLX4_MTT_FLAG_PRESENT);
|
|
|
|
|
2009-06-23 13:07:56 +07:00
|
|
|
dma_sync_single_for_device(&dev->pdev->dev, fmr->dma_handle,
|
|
|
|
npages * sizeof(u64), DMA_TO_DEVICE);
|
2007-08-01 16:29:05 +07:00
|
|
|
|
|
|
|
fmr->mpt->key = cpu_to_be32(key);
|
|
|
|
fmr->mpt->lkey = cpu_to_be32(key);
|
|
|
|
fmr->mpt->length = cpu_to_be64(npages * (1ull << fmr->page_shift));
|
|
|
|
fmr->mpt->start = cpu_to_be64(iova);
|
|
|
|
|
|
|
|
/* Make MTT entries are visible before setting MPT status */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
*(u8 *) fmr->mpt = MLX4_MPT_STATUS_HW;
|
|
|
|
|
|
|
|
/* Make sure MPT status is visible before consumer can use FMR */
|
|
|
|
wmb();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_map_phys_fmr);
|
|
|
|
|
|
|
|
int mlx4_fmr_alloc(struct mlx4_dev *dev, u32 pd, u32 access, int max_pages,
|
|
|
|
int max_maps, u8 page_shift, struct mlx4_fmr *fmr)
|
|
|
|
{
|
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
int err = -ENOMEM;
|
|
|
|
|
2012-02-09 23:10:06 +07:00
|
|
|
if (max_maps > dev->caps.max_fmr_maps)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-05-06 05:56:52 +07:00
|
|
|
if (page_shift < (ffs(dev->caps.page_size_cap) - 1) || page_shift >= 32)
|
2007-08-01 16:29:05 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* All MTTs must fit in the same page */
|
|
|
|
if (max_pages * sizeof *fmr->mtts > PAGE_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
fmr->page_shift = page_shift;
|
|
|
|
fmr->max_pages = max_pages;
|
|
|
|
fmr->max_maps = max_maps;
|
|
|
|
fmr->maps = 0;
|
|
|
|
|
|
|
|
err = mlx4_mr_alloc(dev, pd, 0, 0, access, max_pages,
|
|
|
|
page_shift, &fmr->mr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
fmr->mtts = mlx4_table_find(&priv->mr_table.mtt_table,
|
2011-12-13 11:16:56 +07:00
|
|
|
fmr->mr.mtt.offset,
|
2007-08-01 16:29:05 +07:00
|
|
|
&fmr->dma_handle);
|
2011-12-13 11:16:56 +07:00
|
|
|
|
2007-08-01 16:29:05 +07:00
|
|
|
if (!fmr->mtts) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free:
|
2013-02-06 23:19:09 +07:00
|
|
|
(void) mlx4_mr_free(dev, &fmr->mr);
|
2007-08-01 16:29:05 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_fmr_alloc);
|
|
|
|
|
|
|
|
int mlx4_fmr_enable(struct mlx4_dev *dev, struct mlx4_fmr *fmr)
|
|
|
|
{
|
2008-02-14 18:41:29 +07:00
|
|
|
struct mlx4_priv *priv = mlx4_priv(dev);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = mlx4_mr_enable(dev, &fmr->mr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
fmr->mpt = mlx4_table_find(&priv->mr_table.dmpt_table,
|
|
|
|
key_to_hw_index(fmr->mr.key), NULL);
|
|
|
|
if (!fmr->mpt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
2007-08-01 16:29:05 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_fmr_enable);
|
|
|
|
|
|
|
|
void mlx4_fmr_unmap(struct mlx4_dev *dev, struct mlx4_fmr *fmr,
|
|
|
|
u32 *lkey, u32 *rkey)
|
|
|
|
{
|
2011-12-13 11:13:48 +07:00
|
|
|
struct mlx4_cmd_mailbox *mailbox;
|
|
|
|
int err;
|
|
|
|
|
2007-08-01 16:29:05 +07:00
|
|
|
if (!fmr->maps)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fmr->maps = 0;
|
|
|
|
|
2011-12-13 11:13:48 +07:00
|
|
|
mailbox = mlx4_alloc_cmd_mailbox(dev);
|
|
|
|
if (IS_ERR(mailbox)) {
|
|
|
|
err = PTR_ERR(mailbox);
|
2014-05-22 19:55:40 +07:00
|
|
|
pr_warn("mlx4_ib: mlx4_alloc_cmd_mailbox failed (%d)\n", err);
|
2011-12-13 11:13:48 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mlx4_HW2SW_MPT(dev, NULL,
|
|
|
|
key_to_hw_index(fmr->mr.key) &
|
|
|
|
(dev->caps.num_mpts - 1));
|
|
|
|
mlx4_free_cmd_mailbox(dev, mailbox);
|
|
|
|
if (err) {
|
2014-05-22 19:55:40 +07:00
|
|
|
pr_warn("mlx4_ib: mlx4_HW2SW_MPT failed (%d)\n", err);
|
2011-12-13 11:13:48 +07:00
|
|
|
return;
|
|
|
|
}
|
2013-02-06 23:19:08 +07:00
|
|
|
fmr->mr.enabled = MLX4_MPT_EN_SW;
|
2007-08-01 16:29:05 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_fmr_unmap);
|
|
|
|
|
|
|
|
int mlx4_fmr_free(struct mlx4_dev *dev, struct mlx4_fmr *fmr)
|
|
|
|
{
|
2013-02-06 23:19:09 +07:00
|
|
|
int ret;
|
|
|
|
|
2007-08-01 16:29:05 +07:00
|
|
|
if (fmr->maps)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2013-02-06 23:19:09 +07:00
|
|
|
ret = mlx4_mr_free(dev, &fmr->mr);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-02-06 23:19:08 +07:00
|
|
|
fmr->mr.enabled = MLX4_MPT_DISABLED;
|
2007-08-01 16:29:05 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_fmr_free);
|
|
|
|
|
|
|
|
int mlx4_SYNC_TPT(struct mlx4_dev *dev)
|
|
|
|
{
|
2011-12-13 11:10:51 +07:00
|
|
|
return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_SYNC_TPT, 1000,
|
2012-05-15 17:34:59 +07:00
|
|
|
MLX4_CMD_NATIVE);
|
2007-08-01 16:29:05 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mlx4_SYNC_TPT);
|