5a0e3ad6af
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>
360 lines
8.4 KiB
C
360 lines
8.4 KiB
C
/*
|
|
* Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
|
|
* Copyright (c) 2007, 2008 Mellanox Technologies. 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/slab.h>
|
|
|
|
#include "mlx4_ib.h"
|
|
|
|
static u32 convert_access(int acc)
|
|
{
|
|
return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX4_PERM_ATOMIC : 0) |
|
|
(acc & IB_ACCESS_REMOTE_WRITE ? MLX4_PERM_REMOTE_WRITE : 0) |
|
|
(acc & IB_ACCESS_REMOTE_READ ? MLX4_PERM_REMOTE_READ : 0) |
|
|
(acc & IB_ACCESS_LOCAL_WRITE ? MLX4_PERM_LOCAL_WRITE : 0) |
|
|
MLX4_PERM_LOCAL_READ;
|
|
}
|
|
|
|
struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc)
|
|
{
|
|
struct mlx4_ib_mr *mr;
|
|
int err;
|
|
|
|
mr = kmalloc(sizeof *mr, GFP_KERNEL);
|
|
if (!mr)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
err = mlx4_mr_alloc(to_mdev(pd->device)->dev, to_mpd(pd)->pdn, 0,
|
|
~0ull, convert_access(acc), 0, 0, &mr->mmr);
|
|
if (err)
|
|
goto err_free;
|
|
|
|
err = mlx4_mr_enable(to_mdev(pd->device)->dev, &mr->mmr);
|
|
if (err)
|
|
goto err_mr;
|
|
|
|
mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key;
|
|
mr->umem = NULL;
|
|
|
|
return &mr->ibmr;
|
|
|
|
err_mr:
|
|
mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr);
|
|
|
|
err_free:
|
|
kfree(mr);
|
|
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,
|
|
struct ib_umem *umem)
|
|
{
|
|
u64 *pages;
|
|
struct ib_umem_chunk *chunk;
|
|
int i, j, k;
|
|
int n;
|
|
int len;
|
|
int err = 0;
|
|
|
|
pages = (u64 *) __get_free_page(GFP_KERNEL);
|
|
if (!pages)
|
|
return -ENOMEM;
|
|
|
|
i = n = 0;
|
|
|
|
list_for_each_entry(chunk, &umem->chunk_list, list)
|
|
for (j = 0; j < chunk->nmap; ++j) {
|
|
len = sg_dma_len(&chunk->page_list[j]) >> mtt->page_shift;
|
|
for (k = 0; k < len; ++k) {
|
|
pages[i++] = sg_dma_address(&chunk->page_list[j]) +
|
|
umem->page_size * k;
|
|
/*
|
|
* Be friendly to mlx4_write_mtt() and
|
|
* pass it chunks of appropriate size.
|
|
*/
|
|
if (i == PAGE_SIZE / sizeof (u64)) {
|
|
err = mlx4_write_mtt(dev->dev, mtt, n,
|
|
i, pages);
|
|
if (err)
|
|
goto out;
|
|
n += i;
|
|
i = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (i)
|
|
err = mlx4_write_mtt(dev->dev, mtt, n, i, pages);
|
|
|
|
out:
|
|
free_page((unsigned long) pages);
|
|
return err;
|
|
}
|
|
|
|
struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
|
|
u64 virt_addr, int access_flags,
|
|
struct ib_udata *udata)
|
|
{
|
|
struct mlx4_ib_dev *dev = to_mdev(pd->device);
|
|
struct mlx4_ib_mr *mr;
|
|
int shift;
|
|
int err;
|
|
int n;
|
|
|
|
mr = kmalloc(sizeof *mr, GFP_KERNEL);
|
|
if (!mr)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mr->umem = ib_umem_get(pd->uobject->context, start, length,
|
|
access_flags, 0);
|
|
if (IS_ERR(mr->umem)) {
|
|
err = PTR_ERR(mr->umem);
|
|
goto err_free;
|
|
}
|
|
|
|
n = ib_umem_page_count(mr->umem);
|
|
shift = ilog2(mr->umem->page_size);
|
|
|
|
err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, virt_addr, length,
|
|
convert_access(access_flags), n, shift, &mr->mmr);
|
|
if (err)
|
|
goto err_umem;
|
|
|
|
err = mlx4_ib_umem_write_mtt(dev, &mr->mmr.mtt, mr->umem);
|
|
if (err)
|
|
goto err_mr;
|
|
|
|
err = mlx4_mr_enable(dev->dev, &mr->mmr);
|
|
if (err)
|
|
goto err_mr;
|
|
|
|
mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key;
|
|
|
|
return &mr->ibmr;
|
|
|
|
err_mr:
|
|
mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr);
|
|
|
|
err_umem:
|
|
ib_umem_release(mr->umem);
|
|
|
|
err_free:
|
|
kfree(mr);
|
|
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
int mlx4_ib_dereg_mr(struct ib_mr *ibmr)
|
|
{
|
|
struct mlx4_ib_mr *mr = to_mmr(ibmr);
|
|
|
|
mlx4_mr_free(to_mdev(ibmr->device)->dev, &mr->mmr);
|
|
if (mr->umem)
|
|
ib_umem_release(mr->umem);
|
|
kfree(mr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct ib_mr *mlx4_ib_alloc_fast_reg_mr(struct ib_pd *pd,
|
|
int max_page_list_len)
|
|
{
|
|
struct mlx4_ib_dev *dev = to_mdev(pd->device);
|
|
struct mlx4_ib_mr *mr;
|
|
int err;
|
|
|
|
mr = kmalloc(sizeof *mr, GFP_KERNEL);
|
|
if (!mr)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, 0, 0, 0,
|
|
max_page_list_len, 0, &mr->mmr);
|
|
if (err)
|
|
goto err_free;
|
|
|
|
err = mlx4_mr_enable(dev->dev, &mr->mmr);
|
|
if (err)
|
|
goto err_mr;
|
|
|
|
mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key;
|
|
mr->umem = NULL;
|
|
|
|
return &mr->ibmr;
|
|
|
|
err_mr:
|
|
mlx4_mr_free(dev->dev, &mr->mmr);
|
|
|
|
err_free:
|
|
kfree(mr);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device *ibdev,
|
|
int page_list_len)
|
|
{
|
|
struct mlx4_ib_dev *dev = to_mdev(ibdev);
|
|
struct mlx4_ib_fast_reg_page_list *mfrpl;
|
|
int size = page_list_len * sizeof (u64);
|
|
|
|
if (size > PAGE_SIZE)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
mfrpl = kmalloc(sizeof *mfrpl, GFP_KERNEL);
|
|
if (!mfrpl)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mfrpl->ibfrpl.page_list = kmalloc(size, GFP_KERNEL);
|
|
if (!mfrpl->ibfrpl.page_list)
|
|
goto err_free;
|
|
|
|
mfrpl->mapped_page_list = dma_alloc_coherent(&dev->dev->pdev->dev,
|
|
size, &mfrpl->map,
|
|
GFP_KERNEL);
|
|
if (!mfrpl->ibfrpl.page_list)
|
|
goto err_free;
|
|
|
|
WARN_ON(mfrpl->map & 0x3f);
|
|
|
|
return &mfrpl->ibfrpl;
|
|
|
|
err_free:
|
|
kfree(mfrpl->ibfrpl.page_list);
|
|
kfree(mfrpl);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
|
|
void mlx4_ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list)
|
|
{
|
|
struct mlx4_ib_dev *dev = to_mdev(page_list->device);
|
|
struct mlx4_ib_fast_reg_page_list *mfrpl = to_mfrpl(page_list);
|
|
int size = page_list->max_page_list_len * sizeof (u64);
|
|
|
|
dma_free_coherent(&dev->dev->pdev->dev, size, mfrpl->mapped_page_list,
|
|
mfrpl->map);
|
|
kfree(mfrpl->ibfrpl.page_list);
|
|
kfree(mfrpl);
|
|
}
|
|
|
|
struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int acc,
|
|
struct ib_fmr_attr *fmr_attr)
|
|
{
|
|
struct mlx4_ib_dev *dev = to_mdev(pd->device);
|
|
struct mlx4_ib_fmr *fmr;
|
|
int err = -ENOMEM;
|
|
|
|
fmr = kmalloc(sizeof *fmr, GFP_KERNEL);
|
|
if (!fmr)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
err = mlx4_fmr_alloc(dev->dev, to_mpd(pd)->pdn, convert_access(acc),
|
|
fmr_attr->max_pages, fmr_attr->max_maps,
|
|
fmr_attr->page_shift, &fmr->mfmr);
|
|
if (err)
|
|
goto err_free;
|
|
|
|
err = mlx4_fmr_enable(to_mdev(pd->device)->dev, &fmr->mfmr);
|
|
if (err)
|
|
goto err_mr;
|
|
|
|
fmr->ibfmr.rkey = fmr->ibfmr.lkey = fmr->mfmr.mr.key;
|
|
|
|
return &fmr->ibfmr;
|
|
|
|
err_mr:
|
|
mlx4_mr_free(to_mdev(pd->device)->dev, &fmr->mfmr.mr);
|
|
|
|
err_free:
|
|
kfree(fmr);
|
|
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
|
|
int npages, u64 iova)
|
|
{
|
|
struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr);
|
|
struct mlx4_ib_dev *dev = to_mdev(ifmr->ibfmr.device);
|
|
|
|
return mlx4_map_phys_fmr(dev->dev, &ifmr->mfmr, page_list, npages, iova,
|
|
&ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey);
|
|
}
|
|
|
|
int mlx4_ib_unmap_fmr(struct list_head *fmr_list)
|
|
{
|
|
struct ib_fmr *ibfmr;
|
|
int err;
|
|
struct mlx4_dev *mdev = NULL;
|
|
|
|
list_for_each_entry(ibfmr, fmr_list, list) {
|
|
if (mdev && to_mdev(ibfmr->device)->dev != mdev)
|
|
return -EINVAL;
|
|
mdev = to_mdev(ibfmr->device)->dev;
|
|
}
|
|
|
|
if (!mdev)
|
|
return 0;
|
|
|
|
list_for_each_entry(ibfmr, fmr_list, list) {
|
|
struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr);
|
|
|
|
mlx4_fmr_unmap(mdev, &ifmr->mfmr, &ifmr->ibfmr.lkey, &ifmr->ibfmr.rkey);
|
|
}
|
|
|
|
/*
|
|
* Make sure all MPT status updates are visible before issuing
|
|
* SYNC_TPT firmware command.
|
|
*/
|
|
wmb();
|
|
|
|
err = mlx4_SYNC_TPT(mdev);
|
|
if (err)
|
|
printk(KERN_WARNING "mlx4_ib: SYNC_TPT error %d when "
|
|
"unmapping FMRs\n", err);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int mlx4_ib_fmr_dealloc(struct ib_fmr *ibfmr)
|
|
{
|
|
struct mlx4_ib_fmr *ifmr = to_mfmr(ibfmr);
|
|
struct mlx4_ib_dev *dev = to_mdev(ibfmr->device);
|
|
int err;
|
|
|
|
err = mlx4_fmr_free(dev->dev, &ifmr->mfmr);
|
|
|
|
if (!err)
|
|
kfree(ifmr);
|
|
|
|
return err;
|
|
}
|