2006-09-22 22:22:22 +00:00
|
|
|
/*
|
|
|
|
* IBM eServer eHCA Infiniband device driver for Linux on POWER
|
|
|
|
*
|
|
|
|
* userspace support verbs
|
|
|
|
*
|
|
|
|
* Authors: Christoph Raisch <raisch@de.ibm.com>
|
|
|
|
* Hoang-Nam Nguyen <hnguyen@de.ibm.com>
|
|
|
|
* Heiko J Schick <schickhj@de.ibm.com>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 IBM Corporation
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is distributed under a dual license of GPL v2.0 and OpenIB
|
|
|
|
* BSD.
|
|
|
|
*
|
|
|
|
* OpenIB BSD License
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
2006-09-22 22:22:22 +00:00
|
|
|
#include "ehca_classes.h"
|
|
|
|
#include "ehca_iverbs.h"
|
|
|
|
#include "ehca_mrmw.h"
|
|
|
|
#include "ehca_tools.h"
|
|
|
|
#include "hcp_if.h"
|
|
|
|
|
|
|
|
struct ib_ucontext *ehca_alloc_ucontext(struct ib_device *device,
|
|
|
|
struct ib_udata *udata)
|
|
|
|
{
|
|
|
|
struct ehca_ucontext *my_context;
|
|
|
|
|
|
|
|
my_context = kzalloc(sizeof *my_context, GFP_KERNEL);
|
|
|
|
if (!my_context) {
|
|
|
|
ehca_err(device, "Out of memory device=%p", device);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
return &my_context->ib_ucontext;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ehca_dealloc_ucontext(struct ib_ucontext *context)
|
|
|
|
{
|
|
|
|
kfree(container_of(context, struct ehca_ucontext, ib_ucontext));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
static void ehca_mm_open(struct vm_area_struct *vma)
|
2006-09-22 22:22:22 +00:00
|
|
|
{
|
2007-07-12 15:53:47 +00:00
|
|
|
u32 *count = (u32 *)vma->vm_private_data;
|
2007-01-23 23:13:35 +00:00
|
|
|
if (!count) {
|
|
|
|
ehca_gen_err("Invalid vma struct vm_start=%lx vm_end=%lx",
|
|
|
|
vma->vm_start, vma->vm_end);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
(*count)++;
|
|
|
|
if (!(*count))
|
|
|
|
ehca_gen_err("Use count overflow vm_start=%lx vm_end=%lx",
|
|
|
|
vma->vm_start, vma->vm_end);
|
|
|
|
ehca_gen_dbg("vm_start=%lx vm_end=%lx count=%x",
|
|
|
|
vma->vm_start, vma->vm_end, *count);
|
|
|
|
}
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
static void ehca_mm_close(struct vm_area_struct *vma)
|
|
|
|
{
|
2007-07-12 15:53:47 +00:00
|
|
|
u32 *count = (u32 *)vma->vm_private_data;
|
2007-01-23 23:13:35 +00:00
|
|
|
if (!count) {
|
|
|
|
ehca_gen_err("Invalid vma struct vm_start=%lx vm_end=%lx",
|
|
|
|
vma->vm_start, vma->vm_end);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
(*count)--;
|
|
|
|
ehca_gen_dbg("vm_start=%lx vm_end=%lx count=%x",
|
|
|
|
vma->vm_start, vma->vm_end, *count);
|
|
|
|
}
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2009-09-27 18:29:37 +00:00
|
|
|
static const struct vm_operations_struct vm_ops = {
|
2007-01-23 23:13:35 +00:00
|
|
|
.open = ehca_mm_open,
|
|
|
|
.close = ehca_mm_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ehca_mmap_fw(struct vm_area_struct *vma, struct h_galpas *galpas,
|
|
|
|
u32 *mm_count)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u64 vsize, physical;
|
|
|
|
|
|
|
|
vsize = vma->vm_end - vma->vm_start;
|
2007-09-11 13:31:06 +00:00
|
|
|
if (vsize < EHCA_PAGESIZE) {
|
2007-01-23 23:13:35 +00:00
|
|
|
ehca_gen_err("invalid vsize=%lx", vma->vm_end - vma->vm_start);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
physical = galpas->user.fw_handle;
|
|
|
|
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
|
2009-01-16 22:55:28 +00:00
|
|
|
ehca_gen_dbg("vsize=%llx physical=%llx", vsize, physical);
|
2007-01-23 23:13:35 +00:00
|
|
|
/* VM_IO | VM_RESERVED are set by remap_pfn_range() */
|
2007-09-11 13:31:06 +00:00
|
|
|
ret = remap_4k_pfn(vma, vma->vm_start, physical >> EHCA_PAGESHIFT,
|
|
|
|
vma->vm_page_prot);
|
2007-01-23 23:13:35 +00:00
|
|
|
if (unlikely(ret)) {
|
2007-09-11 13:32:22 +00:00
|
|
|
ehca_gen_err("remap_pfn_range() failed ret=%i", ret);
|
2007-01-23 23:13:35 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
vma->vm_private_data = mm_count;
|
|
|
|
(*mm_count)++;
|
|
|
|
vma->vm_ops = &vm_ops;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ehca_mmap_queue(struct vm_area_struct *vma, struct ipz_queue *queue,
|
|
|
|
u32 *mm_count)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u64 start, ofs;
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
vma->vm_flags |= VM_RESERVED;
|
|
|
|
start = vma->vm_start;
|
|
|
|
for (ofs = 0; ofs < queue->queue_length; ofs += PAGE_SIZE) {
|
|
|
|
u64 virt_addr = (u64)ipz_qeit_calc(queue, ofs);
|
|
|
|
page = virt_to_page(virt_addr);
|
|
|
|
ret = vm_insert_page(vma, start, page);
|
|
|
|
if (unlikely(ret)) {
|
2007-09-11 13:32:22 +00:00
|
|
|
ehca_gen_err("vm_insert_page() failed rc=%i", ret);
|
2007-01-23 23:13:35 +00:00
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
2007-07-20 14:04:17 +00:00
|
|
|
start += PAGE_SIZE;
|
2007-01-23 23:13:35 +00:00
|
|
|
}
|
|
|
|
vma->vm_private_data = mm_count;
|
|
|
|
(*mm_count)++;
|
|
|
|
vma->vm_ops = &vm_ops;
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ehca_mmap_cq(struct vm_area_struct *vma, struct ehca_cq *cq,
|
|
|
|
u32 rsrc_type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (rsrc_type) {
|
2007-09-11 13:29:39 +00:00
|
|
|
case 0: /* galpa fw handle */
|
2007-01-23 23:13:35 +00:00
|
|
|
ehca_dbg(cq->ib_cq.device, "cq_num=%x fw", cq->cq_number);
|
|
|
|
ret = ehca_mmap_fw(vma, &cq->galpas, &cq->mm_count_galpa);
|
|
|
|
if (unlikely(ret)) {
|
2006-09-22 22:22:22 +00:00
|
|
|
ehca_err(cq->ib_cq.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_fw() failed rc=%i cq_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, cq->cq_number);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
2007-01-23 23:13:35 +00:00
|
|
|
break;
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-09-11 13:29:39 +00:00
|
|
|
case 1: /* cq queue_addr */
|
2007-01-23 23:13:35 +00:00
|
|
|
ehca_dbg(cq->ib_cq.device, "cq_num=%x queue", cq->cq_number);
|
|
|
|
ret = ehca_mmap_queue(vma, &cq->ipz_queue, &cq->mm_count_queue);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
ehca_err(cq->ib_cq.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_queue() failed rc=%i cq_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, cq->cq_number);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
default:
|
|
|
|
ehca_err(cq->ib_cq.device, "bad resource type=%x cq_num=%x",
|
|
|
|
rsrc_type, cq->cq_number);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ehca_mmap_qp(struct vm_area_struct *vma, struct ehca_qp *qp,
|
|
|
|
u32 rsrc_type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (rsrc_type) {
|
2007-09-11 13:29:39 +00:00
|
|
|
case 0: /* galpa fw handle */
|
2007-01-23 23:13:35 +00:00
|
|
|
ehca_dbg(qp->ib_qp.device, "qp_num=%x fw", qp->ib_qp.qp_num);
|
|
|
|
ret = ehca_mmap_fw(vma, &qp->galpas, &qp->mm_count_galpa);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
ehca_err(qp->ib_qp.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"remap_pfn_range() failed ret=%i qp_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, qp->ib_qp.qp_num);
|
|
|
|
return -ENOMEM;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
2007-01-23 23:13:35 +00:00
|
|
|
break;
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-09-11 13:29:39 +00:00
|
|
|
case 1: /* qp rqueue_addr */
|
2008-04-23 18:55:45 +00:00
|
|
|
ehca_dbg(qp->ib_qp.device, "qp_num=%x rq", qp->ib_qp.qp_num);
|
2007-07-12 15:53:47 +00:00
|
|
|
ret = ehca_mmap_queue(vma, &qp->ipz_rqueue,
|
|
|
|
&qp->mm_count_rqueue);
|
2007-01-23 23:13:35 +00:00
|
|
|
if (unlikely(ret)) {
|
2006-09-22 22:22:22 +00:00
|
|
|
ehca_err(qp->ib_qp.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_queue(rq) failed rc=%i qp_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, qp->ib_qp.qp_num);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
2007-01-23 23:13:35 +00:00
|
|
|
break;
|
2006-09-22 22:22:22 +00:00
|
|
|
|
2007-09-11 13:29:39 +00:00
|
|
|
case 2: /* qp squeue_addr */
|
2008-04-23 18:55:45 +00:00
|
|
|
ehca_dbg(qp->ib_qp.device, "qp_num=%x sq", qp->ib_qp.qp_num);
|
2007-07-12 15:53:47 +00:00
|
|
|
ret = ehca_mmap_queue(vma, &qp->ipz_squeue,
|
|
|
|
&qp->mm_count_squeue);
|
2007-01-23 23:13:35 +00:00
|
|
|
if (unlikely(ret)) {
|
|
|
|
ehca_err(qp->ib_qp.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_queue(sq) failed rc=%i qp_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, qp->ib_qp.qp_num);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-01-23 23:13:35 +00:00
|
|
|
ehca_err(qp->ib_qp.device, "bad resource type=%x qp=num=%x",
|
|
|
|
rsrc_type, qp->ib_qp.qp_num);
|
|
|
|
return -EINVAL;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
return 0;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ehca_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
|
|
|
|
{
|
2007-09-11 13:29:39 +00:00
|
|
|
u64 fileoffset = vma->vm_pgoff;
|
|
|
|
u32 idr_handle = fileoffset & 0x1FFFFFF;
|
|
|
|
u32 q_type = (fileoffset >> 27) & 0x1; /* CQ, QP,... */
|
|
|
|
u32 rsrc_type = (fileoffset >> 25) & 0x3; /* sq,rq,cmnd_window */
|
2006-09-22 22:22:22 +00:00
|
|
|
u32 ret;
|
|
|
|
struct ehca_cq *cq;
|
|
|
|
struct ehca_qp *qp;
|
2007-07-09 13:25:10 +00:00
|
|
|
struct ib_uobject *uobject;
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
switch (q_type) {
|
2007-09-11 13:29:39 +00:00
|
|
|
case 0: /* CQ */
|
2007-07-09 13:31:10 +00:00
|
|
|
read_lock(&ehca_cq_idr_lock);
|
2006-09-22 22:22:22 +00:00
|
|
|
cq = idr_find(&ehca_cq_idr, idr_handle);
|
2007-07-09 13:31:10 +00:00
|
|
|
read_unlock(&ehca_cq_idr_lock);
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* make sure this mmap really belongs to the authorized user */
|
|
|
|
if (!cq)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!cq->ib_cq.uobject || cq->ib_cq.uobject->context != context)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
ret = ehca_mmap_cq(vma, cq, rsrc_type);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
ehca_err(cq->ib_cq.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_cq() failed rc=%i cq_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, cq->cq_number);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-09-11 13:29:39 +00:00
|
|
|
case 1: /* QP */
|
2007-07-09 13:31:10 +00:00
|
|
|
read_lock(&ehca_qp_idr_lock);
|
2006-09-22 22:22:22 +00:00
|
|
|
qp = idr_find(&ehca_qp_idr, idr_handle);
|
2007-07-09 13:31:10 +00:00
|
|
|
read_unlock(&ehca_qp_idr_lock);
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* make sure this mmap really belongs to the authorized user */
|
|
|
|
if (!qp)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-07-09 13:25:10 +00:00
|
|
|
uobject = IS_SRQ(qp) ? qp->ib_srq.uobject : qp->ib_qp.uobject;
|
|
|
|
if (!uobject || uobject->context != context)
|
2006-09-22 22:22:22 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2007-01-23 23:13:35 +00:00
|
|
|
ret = ehca_mmap_qp(vma, qp, rsrc_type);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
ehca_err(qp->ib_qp.device,
|
2007-09-11 13:32:22 +00:00
|
|
|
"ehca_mmap_qp() failed rc=%i qp_num=%x",
|
2007-01-23 23:13:35 +00:00
|
|
|
ret, qp->ib_qp.qp_num);
|
|
|
|
return ret;
|
2006-09-22 22:22:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ehca_gen_err("bad queue type %x", q_type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|