2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Linux MegaRAID device driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2004 LSI Logic Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FILE : megaraid_mm.c
|
2006-07-25 14:45:06 +00:00
|
|
|
* Version : v2.20.2.7 (Jul 16 2006)
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* Common management module
|
|
|
|
*/
|
Detach sched.h from mm.h
First thing mm.h does is including sched.h solely for can_do_mlock() inline
function which has "current" dereference inside. By dealing with can_do_mlock()
mm.h can be detached from sched.h which is good. See below, why.
This patch
a) removes unconditional inclusion of sched.h from mm.h
b) makes can_do_mlock() normal function in mm/mlock.c
c) exports can_do_mlock() to not break compilation
d) adds sched.h inclusions back to files that were getting it indirectly.
e) adds less bloated headers to some files (asm/signal.h, jiffies.h) that were
getting them indirectly
Net result is:
a) mm.h users would get less code to open, read, preprocess, parse, ... if
they don't need sched.h
b) sched.h stops being dependency for significant number of files:
on x86_64 allmodconfig touching sched.h results in recompile of 4083 files,
after patch it's only 3744 (-8.3%).
Cross-compile tested on
all arm defconfigs, all mips defconfigs, all powerpc defconfigs,
alpha alpha-up
arm
i386 i386-up i386-defconfig i386-allnoconfig
ia64 ia64-up
m68k
mips
parisc parisc-up
powerpc powerpc-up
s390 s390-up
sparc sparc-up
sparc64 sparc64-up
um-x86_64
x86_64 x86_64-up x86_64-defconfig x86_64-allnoconfig
as well as my two usual configs.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-05-20 21:22:52 +00:00
|
|
|
#include <linux/sched.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-06-02 12:28:52 +00:00
|
|
|
#include <linux/mutex.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "megaraid_mm.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Entry points for char node driver
|
2010-06-02 12:28:52 +00:00
|
|
|
static DEFINE_MUTEX(mraid_mm_mutex);
|
2005-04-16 22:20:36 +00:00
|
|
|
static int mraid_mm_open(struct inode *, struct file *);
|
2010-04-26 22:24:01 +00:00
|
|
|
static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
// routines to convert to and from the old the format
|
|
|
|
static int mimd_to_kioc(mimd_t __user *, mraid_mmadp_t *, uioc_t *);
|
|
|
|
static int kioc_to_mimd(uioc_t *, mimd_t __user *);
|
|
|
|
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
static int handle_drvrcmd(void __user *, uint8_t, int *);
|
|
|
|
static int lld_ioctl(mraid_mmadp_t *, uioc_t *);
|
|
|
|
static void ioctl_done(uioc_t *);
|
2017-10-22 22:30:04 +00:00
|
|
|
static void lld_timedout(struct timer_list *);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *);
|
|
|
|
static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *);
|
|
|
|
static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *);
|
|
|
|
static void mraid_mm_dealloc_kioc(mraid_mmadp_t *, uioc_t *);
|
|
|
|
static int mraid_mm_attach_buf(mraid_mmadp_t *, uioc_t *, int);
|
|
|
|
static int mraid_mm_setup_dma_pools(mraid_mmadp_t *);
|
|
|
|
static void mraid_mm_free_adp_resources(mraid_mmadp_t *);
|
|
|
|
static void mraid_mm_teardown_dma_pools(mraid_mmadp_t *);
|
|
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
static long mraid_mm_compat_ioctl(struct file *, unsigned int, unsigned long);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MODULE_AUTHOR("LSI Logic Corporation");
|
|
|
|
MODULE_DESCRIPTION("LSI Logic Management Module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(LSI_COMMON_MOD_VERSION);
|
|
|
|
|
|
|
|
static int dbglevel = CL_ANN;
|
|
|
|
module_param_named(dlevel, dbglevel, int, 0);
|
|
|
|
MODULE_PARM_DESC(dlevel, "Debug level (default=0)");
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(mraid_mm_register_adp);
|
|
|
|
EXPORT_SYMBOL(mraid_mm_unregister_adp);
|
|
|
|
EXPORT_SYMBOL(mraid_mm_adapter_app_handle);
|
|
|
|
|
2007-04-19 17:10:24 +00:00
|
|
|
static uint32_t drvr_ver = 0x02200207;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static int adapters_count_g;
|
|
|
|
static struct list_head adapters_list_g;
|
|
|
|
|
|
|
|
static wait_queue_head_t wait_q;
|
|
|
|
|
2007-02-12 08:55:34 +00:00
|
|
|
static const struct file_operations lsi_fops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = mraid_mm_open,
|
2010-04-26 22:24:01 +00:00
|
|
|
.unlocked_ioctl = mraid_mm_unlocked_ioctl,
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = mraid_mm_compat_ioctl,
|
|
|
|
#endif
|
|
|
|
.owner = THIS_MODULE,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = noop_llseek,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2008-02-05 07:53:18 +00:00
|
|
|
static struct miscdevice megaraid_mm_dev = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = "megadev0",
|
|
|
|
.fops = &lsi_fops,
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
|
|
|
* mraid_mm_open - open routine for char node interface
|
2007-01-06 06:41:48 +00:00
|
|
|
* @inode : unused
|
2005-04-16 22:20:36 +00:00
|
|
|
* @filep : unused
|
|
|
|
*
|
2007-01-06 06:41:48 +00:00
|
|
|
* Allow ioctl operations by apps only if they have superuser privilege.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mraid_mm_open(struct inode *inode, struct file *filep)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Only allow superuser to access private ioctl interface
|
|
|
|
*/
|
|
|
|
if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_ioctl - module entry-point for ioctls
|
|
|
|
* @inode : inode (ignored)
|
|
|
|
* @filep : file operations pointer (ignored)
|
|
|
|
* @cmd : ioctl command
|
|
|
|
* @arg : user ioctl packet
|
|
|
|
*/
|
|
|
|
static int
|
2010-04-26 22:24:01 +00:00
|
|
|
mraid_mm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
uioc_t *kioc;
|
|
|
|
char signature[EXT_IOCTL_SIGN_SZ] = {0};
|
|
|
|
int rval;
|
|
|
|
mraid_mmadp_t *adp;
|
|
|
|
uint8_t old_ioctl;
|
|
|
|
int drvrcmd_rval;
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure only USCSICMD are issued through this interface.
|
|
|
|
* MIMD application would still fire different command.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD)) {
|
|
|
|
return (-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for signature to see if this is the new or old ioctl format.
|
|
|
|
*/
|
|
|
|
if (copy_from_user(signature, argp, EXT_IOCTL_SIGN_SZ)) {
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
|
|
|
"megaraid cmm: copy from usr addr failed\n"));
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(signature, EXT_IOCTL_SIGN, EXT_IOCTL_SIGN_SZ) == 0)
|
|
|
|
old_ioctl = 0;
|
|
|
|
else
|
|
|
|
old_ioctl = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At present, we don't support the new ioctl packet
|
|
|
|
*/
|
|
|
|
if (!old_ioctl )
|
|
|
|
return (-EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it is a driver ioctl (as opposed to fw ioctls), then we can
|
|
|
|
* handle the command locally. rval > 0 means it is not a drvr cmd
|
|
|
|
*/
|
|
|
|
rval = handle_drvrcmd(argp, old_ioctl, &drvrcmd_rval);
|
|
|
|
|
|
|
|
if (rval < 0)
|
|
|
|
return rval;
|
|
|
|
else if (rval == 0)
|
|
|
|
return drvrcmd_rval;
|
|
|
|
|
|
|
|
rval = 0;
|
|
|
|
if ((adp = mraid_mm_get_adapter(argp, &rval)) == NULL) {
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if adapter can accept ioctl. We may have marked it offline
|
|
|
|
* if any previous kioc had timedout on this controller.
|
|
|
|
*/
|
|
|
|
if (!adp->quiescent) {
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
|
|
|
"megaraid cmm: controller cannot accept cmds due to "
|
|
|
|
"earlier errors\n" ));
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following call will block till a kioc is available
|
2016-01-05 19:32:54 +00:00
|
|
|
* or return NULL if the list head is empty for the pointer
|
|
|
|
* of type mraid_mmapt passed to mraid_mm_alloc_kioc
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
kioc = mraid_mm_alloc_kioc(adp);
|
2016-01-05 19:32:54 +00:00
|
|
|
if (!kioc)
|
|
|
|
return -ENXIO;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* User sent the old mimd_t ioctl packet. Convert it to uioc_t.
|
|
|
|
*/
|
|
|
|
if ((rval = mimd_to_kioc(argp, adp, kioc))) {
|
|
|
|
mraid_mm_dealloc_kioc(adp, kioc);
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
kioc->done = ioctl_done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue the IOCTL to the low level driver. After the IOCTL completes
|
|
|
|
* release the kioc if and only if it was _not_ timedout. If it was
|
|
|
|
* timedout, that means that resources are still with low level driver.
|
|
|
|
*/
|
|
|
|
if ((rval = lld_ioctl(adp, kioc))) {
|
|
|
|
|
|
|
|
if (!kioc->timedout)
|
|
|
|
mraid_mm_dealloc_kioc(adp, kioc);
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the kioc back to user space
|
|
|
|
*/
|
|
|
|
rval = kioc_to_mimd(kioc, argp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the kioc to free pool
|
|
|
|
*/
|
|
|
|
mraid_mm_dealloc_kioc(adp, kioc);
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
2010-04-26 22:24:01 +00:00
|
|
|
static long
|
|
|
|
mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2010-12-10 13:55:42 +00:00
|
|
|
/* inconsistent: mraid_mm_compat_ioctl doesn't take the BKL */
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_lock(&mraid_mm_mutex);
|
2010-04-26 22:24:01 +00:00
|
|
|
err = mraid_mm_ioctl(filep, cmd, arg);
|
2010-06-02 12:28:52 +00:00
|
|
|
mutex_unlock(&mraid_mm_mutex);
|
2010-04-26 22:24:01 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
|
|
|
|
* @umimd : User space mimd_t ioctl packet
|
2007-01-06 06:41:48 +00:00
|
|
|
* @rval : returned success/error status
|
|
|
|
*
|
|
|
|
* The function return value is a pointer to the located @adapter.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static mraid_mmadp_t *
|
|
|
|
mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
|
|
|
|
{
|
|
|
|
mraid_mmadp_t *adapter;
|
|
|
|
mimd_t mimd;
|
|
|
|
uint32_t adapno;
|
|
|
|
int iterator;
|
|
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) {
|
|
|
|
*rval = -EFAULT;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
adapno = GETADAP(mimd.ui.fcs.adapno);
|
|
|
|
|
|
|
|
if (adapno >= adapters_count_g) {
|
|
|
|
*rval = -ENODEV;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
adapter = NULL;
|
|
|
|
iterator = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(adapter, &adapters_list_g, list) {
|
|
|
|
if (iterator++ == adapno) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!adapter) {
|
|
|
|
*rval = -ENODEV;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return adapter;
|
|
|
|
}
|
|
|
|
|
2007-01-06 06:41:48 +00:00
|
|
|
/**
|
|
|
|
* handle_drvrcmd - Checks if the opcode is a driver cmd and if it is, handles it.
|
2005-04-16 22:20:36 +00:00
|
|
|
* @arg : packet sent by the user app
|
|
|
|
* @old_ioctl : mimd if 1; uioc otherwise
|
2007-01-06 06:41:48 +00:00
|
|
|
* @rval : pointer for command's returned value (not function status)
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval)
|
|
|
|
{
|
|
|
|
mimd_t __user *umimd;
|
|
|
|
mimd_t kmimd;
|
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t subopcode;
|
|
|
|
|
|
|
|
if (old_ioctl)
|
|
|
|
goto old_packet;
|
|
|
|
else
|
|
|
|
goto new_packet;
|
|
|
|
|
|
|
|
new_packet:
|
|
|
|
return (-ENOTSUPP);
|
|
|
|
|
|
|
|
old_packet:
|
|
|
|
*rval = 0;
|
|
|
|
umimd = arg;
|
|
|
|
|
|
|
|
if (copy_from_user(&kmimd, umimd, sizeof(mimd_t)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
opcode = kmimd.ui.fcs.opcode;
|
|
|
|
subopcode = kmimd.ui.fcs.subopcode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
|
|
|
|
* GET_NUMADP, then we can handle. Otherwise we should return 1 to
|
|
|
|
* indicate that we cannot handle this.
|
|
|
|
*/
|
|
|
|
if (opcode != 0x82)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch (subopcode) {
|
|
|
|
|
|
|
|
case MEGAIOC_QDRVRVER:
|
|
|
|
|
|
|
|
if (copy_to_user(kmimd.data, &drvr_ver, sizeof(uint32_t)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case MEGAIOC_QNADAP:
|
|
|
|
|
|
|
|
*rval = adapters_count_g;
|
|
|
|
|
|
|
|
if (copy_to_user(kmimd.data, &adapters_count_g,
|
|
|
|
sizeof(uint32_t)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* cannot handle */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mimd_to_kioc - Converter from old to new ioctl format
|
|
|
|
* @umimd : user space old MIMD IOCTL
|
2007-01-06 06:41:48 +00:00
|
|
|
* @adp : adapter softstate
|
2005-04-16 22:20:36 +00:00
|
|
|
* @kioc : kernel space new format IOCTL
|
|
|
|
*
|
|
|
|
* Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
|
|
|
|
* new packet is in kernel space so that driver can perform operations on it
|
|
|
|
* freely.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc)
|
|
|
|
{
|
|
|
|
mbox64_t *mbox64;
|
|
|
|
mbox_t *mbox;
|
|
|
|
mraid_passthru_t *pthru32;
|
|
|
|
uint32_t adapno;
|
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t subopcode;
|
|
|
|
mimd_t mimd;
|
|
|
|
|
|
|
|
if (copy_from_user(&mimd, umimd, sizeof(mimd_t)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Applications are not allowed to send extd pthru
|
|
|
|
*/
|
|
|
|
if ((mimd.mbox[0] == MBOXCMD_PASSTHRU64) ||
|
|
|
|
(mimd.mbox[0] == MBOXCMD_EXTPTHRU))
|
|
|
|
return (-EINVAL);
|
|
|
|
|
|
|
|
opcode = mimd.ui.fcs.opcode;
|
|
|
|
subopcode = mimd.ui.fcs.subopcode;
|
|
|
|
adapno = GETADAP(mimd.ui.fcs.adapno);
|
|
|
|
|
|
|
|
if (adapno >= adapters_count_g)
|
|
|
|
return (-ENODEV);
|
|
|
|
|
|
|
|
kioc->adapno = adapno;
|
|
|
|
kioc->mb_type = MBOX_LEGACY;
|
|
|
|
kioc->app_type = APPTYPE_MIMD;
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
|
|
|
|
case 0x82:
|
|
|
|
|
|
|
|
if (subopcode == MEGAIOC_QADAPINFO) {
|
|
|
|
|
|
|
|
kioc->opcode = GET_ADAP_INFO;
|
|
|
|
kioc->data_dir = UIOC_RD;
|
|
|
|
kioc->xferlen = sizeof(mraid_hba_info_t);
|
|
|
|
|
|
|
|
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
|
|
|
|
return (-ENOMEM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
|
|
|
"megaraid cmm: Invalid subop\n"));
|
|
|
|
return (-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x81:
|
|
|
|
|
|
|
|
kioc->opcode = MBOX_CMD;
|
|
|
|
kioc->xferlen = mimd.ui.fcs.length;
|
|
|
|
kioc->user_data_len = kioc->xferlen;
|
|
|
|
kioc->user_data = mimd.ui.fcs.buffer;
|
|
|
|
|
|
|
|
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
|
|
|
|
return (-ENOMEM);
|
|
|
|
|
|
|
|
if (mimd.outlen) kioc->data_dir = UIOC_RD;
|
|
|
|
if (mimd.inlen) kioc->data_dir |= UIOC_WR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x80:
|
|
|
|
|
|
|
|
kioc->opcode = MBOX_CMD;
|
|
|
|
kioc->xferlen = (mimd.outlen > mimd.inlen) ?
|
|
|
|
mimd.outlen : mimd.inlen;
|
|
|
|
kioc->user_data_len = kioc->xferlen;
|
|
|
|
kioc->user_data = mimd.data;
|
|
|
|
|
|
|
|
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
|
|
|
|
return (-ENOMEM);
|
|
|
|
|
|
|
|
if (mimd.outlen) kioc->data_dir = UIOC_RD;
|
|
|
|
if (mimd.inlen) kioc->data_dir |= UIOC_WR;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If driver command, nothing else to do
|
|
|
|
*/
|
|
|
|
if (opcode == 0x82)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a mailbox cmd; copy the mailbox from mimd
|
|
|
|
*/
|
|
|
|
mbox64 = (mbox64_t *)((unsigned long)kioc->cmdbuf);
|
|
|
|
mbox = &mbox64->mbox32;
|
|
|
|
memcpy(mbox, mimd.mbox, 14);
|
|
|
|
|
|
|
|
if (mbox->cmd != MBOXCMD_PASSTHRU) { // regular DCMD
|
|
|
|
|
|
|
|
mbox->xferaddr = (uint32_t)kioc->buf_paddr;
|
|
|
|
|
|
|
|
if (kioc->data_dir & UIOC_WR) {
|
|
|
|
if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
|
|
|
|
kioc->xferlen)) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a regular 32-bit pthru cmd; mbox points to pthru struct.
|
|
|
|
* Just like in above case, the beginning for memblk is treated as
|
|
|
|
* a mailbox. The passthru will begin at next 1K boundary. And the
|
|
|
|
* data will start 1K after that.
|
|
|
|
*/
|
|
|
|
pthru32 = kioc->pthru32;
|
|
|
|
kioc->user_pthru = &umimd->pthru;
|
|
|
|
mbox->xferaddr = (uint32_t)kioc->pthru32_h;
|
|
|
|
|
|
|
|
if (copy_from_user(pthru32, kioc->user_pthru,
|
|
|
|
sizeof(mraid_passthru_t))) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthru32->dataxferaddr = kioc->buf_paddr;
|
|
|
|
if (kioc->data_dir & UIOC_WR) {
|
2013-10-30 17:13:51 +00:00
|
|
|
if (pthru32->dataxferlen > kioc->xferlen)
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
|
|
|
|
pthru32->dataxferlen)) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_attch_buf - Attach a free dma buffer for required size
|
|
|
|
* @adp : Adapter softstate
|
|
|
|
* @kioc : kioc that the buffer needs to be attached to
|
|
|
|
* @xferlen : required length for buffer
|
|
|
|
*
|
|
|
|
* First we search for a pool with smallest buffer that is >= @xferlen. If
|
|
|
|
* that pool has no free buffer, we will try for the next bigger size. If none
|
|
|
|
* is available, we will try to allocate the smallest buffer that is >=
|
|
|
|
* @xferlen and attach it the pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mraid_mm_attach_buf(mraid_mmadp_t *adp, uioc_t *kioc, int xferlen)
|
|
|
|
{
|
|
|
|
mm_dmapool_t *pool;
|
|
|
|
int right_pool = -1;
|
|
|
|
unsigned long flags;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
kioc->pool_index = -1;
|
|
|
|
kioc->buf_vaddr = NULL;
|
|
|
|
kioc->buf_paddr = 0;
|
|
|
|
kioc->free_buf = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need xferlen amount of memory. See if we can get it from our
|
|
|
|
* dma pools. If we don't get exact size, we will try bigger buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DMA_POOLS; i++) {
|
|
|
|
|
|
|
|
pool = &adp->dma_pool_list[i];
|
|
|
|
|
|
|
|
if (xferlen > pool->buf_size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (right_pool == -1)
|
|
|
|
right_pool = i;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pool->lock, flags);
|
|
|
|
|
|
|
|
if (!pool->in_use) {
|
|
|
|
|
|
|
|
pool->in_use = 1;
|
|
|
|
kioc->pool_index = i;
|
|
|
|
kioc->buf_vaddr = pool->vaddr;
|
|
|
|
kioc->buf_paddr = pool->paddr;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pool->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spin_unlock_irqrestore(&pool->lock, flags);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If xferlen doesn't match any of our pools, return error
|
|
|
|
*/
|
|
|
|
if (right_pool == -1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We did not get any buffer from the preallocated pool. Let us try
|
|
|
|
* to allocate one new buffer. NOTE: This is a blocking call.
|
|
|
|
*/
|
|
|
|
pool = &adp->dma_pool_list[right_pool];
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pool->lock, flags);
|
|
|
|
|
|
|
|
kioc->pool_index = right_pool;
|
|
|
|
kioc->free_buf = 1;
|
2017-07-06 08:13:06 +00:00
|
|
|
kioc->buf_vaddr = dma_pool_alloc(pool->handle, GFP_ATOMIC,
|
2005-04-16 22:20:36 +00:00
|
|
|
&kioc->buf_paddr);
|
|
|
|
spin_unlock_irqrestore(&pool->lock, flags);
|
|
|
|
|
|
|
|
if (!kioc->buf_vaddr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_alloc_kioc - Returns a uioc_t from free list
|
|
|
|
* @adp : Adapter softstate for this module
|
|
|
|
*
|
|
|
|
* The kioc_semaphore is initialized with number of kioc nodes in the
|
|
|
|
* free kioc pool. If the kioc pool is empty, this function blocks till
|
|
|
|
* a kioc becomes free.
|
|
|
|
*/
|
|
|
|
static uioc_t *
|
|
|
|
mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
|
|
|
|
{
|
|
|
|
uioc_t *kioc;
|
|
|
|
struct list_head* head;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
down(&adp->kioc_semaphore);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&adp->kioc_pool_lock, flags);
|
|
|
|
|
|
|
|
head = &adp->kioc_pool;
|
|
|
|
|
|
|
|
if (list_empty(head)) {
|
|
|
|
up(&adp->kioc_semaphore);
|
|
|
|
spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
|
|
|
|
|
|
|
|
con_log(CL_ANN, ("megaraid cmm: kioc list empty!\n"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
kioc = list_entry(head->next, uioc_t, list);
|
|
|
|
list_del_init(&kioc->list);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
|
|
|
|
|
|
|
|
memset((caddr_t)(unsigned long)kioc->cmdbuf, 0, sizeof(mbox64_t));
|
|
|
|
memset((caddr_t) kioc->pthru32, 0, sizeof(mraid_passthru_t));
|
|
|
|
|
|
|
|
kioc->buf_vaddr = NULL;
|
|
|
|
kioc->buf_paddr = 0;
|
|
|
|
kioc->pool_index =-1;
|
|
|
|
kioc->free_buf = 0;
|
|
|
|
kioc->user_data = NULL;
|
|
|
|
kioc->user_data_len = 0;
|
|
|
|
kioc->user_pthru = NULL;
|
|
|
|
kioc->timedout = 0;
|
|
|
|
|
|
|
|
return kioc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_dealloc_kioc - Return kioc to free pool
|
|
|
|
* @adp : Adapter softstate
|
|
|
|
* @kioc : uioc_t node to be returned to free pool
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc)
|
|
|
|
{
|
|
|
|
mm_dmapool_t *pool;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (kioc->pool_index != -1) {
|
|
|
|
pool = &adp->dma_pool_list[kioc->pool_index];
|
|
|
|
|
|
|
|
/* This routine may be called in non-isr context also */
|
|
|
|
spin_lock_irqsave(&pool->lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* While attaching the dma buffer, if we didn't get the
|
|
|
|
* required buffer from the pool, we would have allocated
|
|
|
|
* it at the run time and set the free_buf flag. We must
|
|
|
|
* free that buffer. Otherwise, just mark that the buffer is
|
|
|
|
* not in use
|
|
|
|
*/
|
|
|
|
if (kioc->free_buf == 1)
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_free(pool->handle, kioc->buf_vaddr,
|
2005-04-16 22:20:36 +00:00
|
|
|
kioc->buf_paddr);
|
|
|
|
else
|
|
|
|
pool->in_use = 0;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&pool->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the kioc to the free pool */
|
|
|
|
spin_lock_irqsave(&adp->kioc_pool_lock, flags);
|
|
|
|
list_add(&kioc->list, &adp->kioc_pool);
|
|
|
|
spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
|
|
|
|
|
|
|
|
/* increment the free kioc count */
|
|
|
|
up(&adp->kioc_semaphore);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lld_ioctl - Routine to issue ioctl to low level drvr
|
|
|
|
* @adp : The adapter handle
|
|
|
|
* @kioc : The ioctl packet with kernel addresses
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
|
|
|
|
{
|
|
|
|
int rval;
|
2017-10-22 22:30:04 +00:00
|
|
|
struct uioc_timeout timeout = { };
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kioc->status = -ENODATA;
|
|
|
|
rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE);
|
|
|
|
|
|
|
|
if (rval) return rval;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the timer
|
|
|
|
*/
|
|
|
|
if (adp->timeout > 0) {
|
2017-10-22 22:30:04 +00:00
|
|
|
timeout.uioc = kioc;
|
|
|
|
timer_setup_on_stack(&timeout.timer, lld_timedout, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-10-22 22:30:04 +00:00
|
|
|
timeout.timer.expires = jiffies + adp->timeout * HZ;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-10-22 22:30:04 +00:00
|
|
|
add_timer(&timeout.timer);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait till the low level driver completes the ioctl. After this
|
|
|
|
* call, the ioctl either completed successfully or timedout.
|
|
|
|
*/
|
|
|
|
wait_event(wait_q, (kioc->status != -ENODATA));
|
2017-10-22 22:30:04 +00:00
|
|
|
if (timeout.timer.function) {
|
|
|
|
del_timer_sync(&timeout.timer);
|
|
|
|
destroy_timer_on_stack(&timeout.timer);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the command had timedout, we mark the controller offline
|
|
|
|
* before returning
|
|
|
|
*/
|
|
|
|
if (kioc->timedout) {
|
|
|
|
adp->quiescent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return kioc->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ioctl_done - callback from the low level driver
|
|
|
|
* @kioc : completed ioctl packet
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ioctl_done(uioc_t *kioc)
|
|
|
|
{
|
|
|
|
uint32_t adapno;
|
|
|
|
int iterator;
|
|
|
|
mraid_mmadp_t* adapter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When the kioc returns from driver, make sure it still doesn't
|
|
|
|
* have ENODATA in status. Otherwise, driver will hang on wait_event
|
|
|
|
* forever
|
|
|
|
*/
|
|
|
|
if (kioc->status == -ENODATA) {
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
|
|
|
"megaraid cmm: lld didn't change status!\n"));
|
|
|
|
|
|
|
|
kioc->status = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if this kioc was timedout before. If so, nobody is waiting
|
|
|
|
* on this kioc. We don't have to wake up anybody. Instead, we just
|
|
|
|
* have to free the kioc
|
|
|
|
*/
|
|
|
|
if (kioc->timedout) {
|
|
|
|
iterator = 0;
|
|
|
|
adapter = NULL;
|
|
|
|
adapno = kioc->adapno;
|
|
|
|
|
|
|
|
con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed "
|
|
|
|
"ioctl that was timedout before\n"));
|
|
|
|
|
|
|
|
list_for_each_entry(adapter, &adapters_list_g, list) {
|
|
|
|
if (iterator++ == adapno) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
kioc->timedout = 0;
|
|
|
|
|
|
|
|
if (adapter) {
|
|
|
|
mraid_mm_dealloc_kioc( adapter, kioc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wake_up(&wait_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 06:41:48 +00:00
|
|
|
/**
|
|
|
|
* lld_timedout - callback from the expired timer
|
2017-10-22 22:30:04 +00:00
|
|
|
* @t : timer that timed out
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static void
|
2017-10-22 22:30:04 +00:00
|
|
|
lld_timedout(struct timer_list *t)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2017-10-22 22:30:04 +00:00
|
|
|
struct uioc_timeout *timeout = from_timer(timeout, t, timer);
|
|
|
|
uioc_t *kioc = timeout->uioc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kioc->status = -ETIME;
|
|
|
|
kioc->timedout = 1;
|
|
|
|
|
|
|
|
con_log(CL_ANN, (KERN_WARNING "megaraid cmm: ioctl timed out\n"));
|
|
|
|
|
|
|
|
wake_up(&wait_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-01-06 06:41:48 +00:00
|
|
|
* kioc_to_mimd - Converter from new back to old format
|
2005-04-16 22:20:36 +00:00
|
|
|
* @kioc : Kernel space IOCTL packet (successfully issued)
|
|
|
|
* @mimd : User space MIMD packet
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
|
|
|
|
{
|
|
|
|
mimd_t kmimd;
|
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t subopcode;
|
|
|
|
|
|
|
|
mbox64_t *mbox64;
|
|
|
|
mraid_passthru_t __user *upthru32;
|
|
|
|
mraid_passthru_t *kpthru32;
|
|
|
|
mcontroller_t cinfo;
|
|
|
|
mraid_hba_info_t *hinfo;
|
|
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(&kmimd, mimd, sizeof(mimd_t)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
opcode = kmimd.ui.fcs.opcode;
|
|
|
|
subopcode = kmimd.ui.fcs.subopcode;
|
|
|
|
|
|
|
|
if (opcode == 0x82) {
|
|
|
|
switch (subopcode) {
|
|
|
|
|
|
|
|
case MEGAIOC_QADAPINFO:
|
|
|
|
|
|
|
|
hinfo = (mraid_hba_info_t *)(unsigned long)
|
|
|
|
kioc->buf_vaddr;
|
|
|
|
|
|
|
|
hinfo_to_cinfo(hinfo, &cinfo);
|
|
|
|
|
|
|
|
if (copy_to_user(kmimd.data, &cinfo, sizeof(cinfo)))
|
|
|
|
return (-EFAULT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbox64 = (mbox64_t *)(unsigned long)kioc->cmdbuf;
|
|
|
|
|
|
|
|
if (kioc->user_pthru) {
|
|
|
|
|
|
|
|
upthru32 = kioc->user_pthru;
|
|
|
|
kpthru32 = kioc->pthru32;
|
|
|
|
|
|
|
|
if (copy_to_user(&upthru32->scsistatus,
|
|
|
|
&kpthru32->scsistatus,
|
|
|
|
sizeof(uint8_t))) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kioc->user_data) {
|
|
|
|
if (copy_to_user(kioc->user_data, kioc->buf_vaddr,
|
|
|
|
kioc->user_data_len)) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copy_to_user(&mimd->mbox[17],
|
|
|
|
&mbox64->mbox32.status, sizeof(uint8_t))) {
|
|
|
|
return (-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* hinfo_to_cinfo - Convert new format hba info into old format
|
|
|
|
* @hinfo : New format, more comprehensive adapter info
|
|
|
|
* @cinfo : Old format adapter info to support mimd_t apps
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo)
|
|
|
|
{
|
|
|
|
if (!hinfo || !cinfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cinfo->base = hinfo->baseport;
|
|
|
|
cinfo->irq = hinfo->irq;
|
|
|
|
cinfo->numldrv = hinfo->num_ldrv;
|
|
|
|
cinfo->pcibus = hinfo->pci_bus;
|
|
|
|
cinfo->pcidev = hinfo->pci_slot;
|
|
|
|
cinfo->pcifun = PCI_FUNC(hinfo->pci_dev_fn);
|
|
|
|
cinfo->pciid = hinfo->pci_device_id;
|
|
|
|
cinfo->pcivendor = hinfo->pci_vendor_id;
|
|
|
|
cinfo->pcislot = hinfo->pci_slot;
|
|
|
|
cinfo->uid = hinfo->unique_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 06:41:48 +00:00
|
|
|
/**
|
|
|
|
* mraid_mm_register_adp - Registration routine for low level drivers
|
2013-06-26 14:25:53 +00:00
|
|
|
* @lld_adp : Adapter object
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
|
|
|
|
{
|
|
|
|
mraid_mmadp_t *adapter;
|
|
|
|
mbox64_t *mbox_list;
|
|
|
|
uioc_t *kioc;
|
|
|
|
uint32_t rval;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
if (lld_adp->drvr_type != DRVRTYPE_MBOX)
|
|
|
|
return (-EINVAL);
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
adapter = kzalloc(sizeof(mraid_mmadp_t), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-03-10 22:24:55 +00:00
|
|
|
if (!adapter)
|
|
|
|
return -ENOMEM;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
adapter->unique_id = lld_adp->unique_id;
|
|
|
|
adapter->drvr_type = lld_adp->drvr_type;
|
|
|
|
adapter->drvr_data = lld_adp->drvr_data;
|
|
|
|
adapter->pdev = lld_adp->pdev;
|
|
|
|
adapter->issue_uioc = lld_adp->issue_uioc;
|
|
|
|
adapter->timeout = lld_adp->timeout;
|
|
|
|
adapter->max_kioc = lld_adp->max_kioc;
|
|
|
|
adapter->quiescent = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate single blocks of memory for all required kiocs,
|
|
|
|
* mailboxes and passthru structures.
|
|
|
|
*/
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
adapter->kioc_list = kmalloc_array(lld_adp->max_kioc,
|
|
|
|
sizeof(uioc_t),
|
|
|
|
GFP_KERNEL);
|
|
|
|
adapter->mbox_list = kmalloc_array(lld_adp->max_kioc,
|
|
|
|
sizeof(mbox64_t),
|
|
|
|
GFP_KERNEL);
|
2017-07-06 08:13:06 +00:00
|
|
|
adapter->pthru_dma_pool = dma_pool_create("megaraid mm pthru pool",
|
|
|
|
&adapter->pdev->dev,
|
2005-04-16 22:20:36 +00:00
|
|
|
sizeof(mraid_passthru_t),
|
|
|
|
16, 0);
|
|
|
|
|
|
|
|
if (!adapter->kioc_list || !adapter->mbox_list ||
|
|
|
|
!adapter->pthru_dma_pool) {
|
|
|
|
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
2008-07-04 06:47:27 +00:00
|
|
|
"megaraid cmm: out of memory, %s %d\n", __func__,
|
2005-04-16 22:20:36 +00:00
|
|
|
__LINE__));
|
|
|
|
|
|
|
|
rval = (-ENOMEM);
|
|
|
|
|
|
|
|
goto memalloc_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Slice kioc_list and make a kioc_pool with the individiual kiocs
|
|
|
|
*/
|
|
|
|
INIT_LIST_HEAD(&adapter->kioc_pool);
|
|
|
|
spin_lock_init(&adapter->kioc_pool_lock);
|
|
|
|
sema_init(&adapter->kioc_semaphore, lld_adp->max_kioc);
|
|
|
|
|
|
|
|
mbox_list = (mbox64_t *)adapter->mbox_list;
|
|
|
|
|
|
|
|
for (i = 0; i < lld_adp->max_kioc; i++) {
|
|
|
|
|
|
|
|
kioc = adapter->kioc_list + i;
|
|
|
|
kioc->cmdbuf = (uint64_t)(unsigned long)(mbox_list + i);
|
2017-07-06 08:13:06 +00:00
|
|
|
kioc->pthru32 = dma_pool_alloc(adapter->pthru_dma_pool,
|
2005-04-16 22:20:36 +00:00
|
|
|
GFP_KERNEL, &kioc->pthru32_h);
|
|
|
|
|
|
|
|
if (!kioc->pthru32) {
|
|
|
|
|
|
|
|
con_log(CL_ANN, (KERN_WARNING
|
|
|
|
"megaraid cmm: out of memory, %s %d\n",
|
2008-07-04 06:47:27 +00:00
|
|
|
__func__, __LINE__));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
rval = (-ENOMEM);
|
|
|
|
|
|
|
|
goto pthru_dma_pool_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&kioc->list, &adapter->kioc_pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the dma pools for data buffers
|
|
|
|
if ((rval = mraid_mm_setup_dma_pools(adapter)) != 0) {
|
|
|
|
goto dma_pool_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&adapter->list, &adapters_list_g);
|
|
|
|
|
|
|
|
adapters_count_g++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dma_pool_error:
|
|
|
|
/* Do nothing */
|
|
|
|
|
|
|
|
pthru_dma_pool_error:
|
|
|
|
|
|
|
|
for (i = 0; i < lld_adp->max_kioc; i++) {
|
|
|
|
kioc = adapter->kioc_list + i;
|
|
|
|
if (kioc->pthru32) {
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_free(adapter->pthru_dma_pool, kioc->pthru32,
|
2005-04-16 22:20:36 +00:00
|
|
|
kioc->pthru32_h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memalloc_error:
|
|
|
|
|
2005-11-07 09:01:26 +00:00
|
|
|
kfree(adapter->kioc_list);
|
|
|
|
kfree(adapter->mbox_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (adapter->pthru_dma_pool)
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_destroy(adapter->pthru_dma_pool);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-07 09:01:26 +00:00
|
|
|
kfree(adapter);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_adapter_app_handle - return the application handle for this adapter
|
2007-01-06 06:41:48 +00:00
|
|
|
* @unique_id : adapter unique identifier
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2007-01-06 06:41:48 +00:00
|
|
|
* For the given driver data, locate the adapter in our global list and
|
2005-04-16 22:20:36 +00:00
|
|
|
* return the corresponding handle, which is also used by applications to
|
|
|
|
* uniquely identify an adapter.
|
|
|
|
*
|
2007-01-06 06:41:48 +00:00
|
|
|
* Return adapter handle if found in the list.
|
|
|
|
* Return 0 if adapter could not be located, should never happen though.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
mraid_mm_adapter_app_handle(uint32_t unique_id)
|
|
|
|
{
|
|
|
|
mraid_mmadp_t *adapter;
|
|
|
|
mraid_mmadp_t *tmp;
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
|
|
|
|
|
|
|
|
if (adapter->unique_id == unique_id) {
|
|
|
|
|
|
|
|
return MKADAP(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
|
|
|
|
* @adp : Adapter softstate
|
|
|
|
*
|
|
|
|
* We maintain a pool of dma buffers per each adapter. Each pool has one
|
|
|
|
* buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
|
|
|
|
* We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
|
|
|
|
* dont' want to waste too much memory by allocating more buffers per each
|
|
|
|
* pool.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mraid_mm_setup_dma_pools(mraid_mmadp_t *adp)
|
|
|
|
{
|
|
|
|
mm_dmapool_t *pool;
|
|
|
|
int bufsize;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create MAX_DMA_POOLS number of pools
|
|
|
|
*/
|
|
|
|
bufsize = MRAID_MM_INIT_BUFF_SIZE;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DMA_POOLS; i++){
|
|
|
|
|
|
|
|
pool = &adp->dma_pool_list[i];
|
|
|
|
|
|
|
|
pool->buf_size = bufsize;
|
|
|
|
spin_lock_init(&pool->lock);
|
|
|
|
|
2017-07-06 08:13:06 +00:00
|
|
|
pool->handle = dma_pool_create("megaraid mm data buffer",
|
|
|
|
&adp->pdev->dev, bufsize,
|
|
|
|
16, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!pool->handle) {
|
|
|
|
goto dma_pool_setup_error;
|
|
|
|
}
|
|
|
|
|
2017-07-06 08:13:06 +00:00
|
|
|
pool->vaddr = dma_pool_alloc(pool->handle, GFP_KERNEL,
|
2005-04-16 22:20:36 +00:00
|
|
|
&pool->paddr);
|
|
|
|
|
|
|
|
if (!pool->vaddr)
|
|
|
|
goto dma_pool_setup_error;
|
|
|
|
|
|
|
|
bufsize = bufsize * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dma_pool_setup_error:
|
|
|
|
|
|
|
|
mraid_mm_teardown_dma_pools(adp);
|
|
|
|
return (-ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 06:41:48 +00:00
|
|
|
/**
|
2005-04-16 22:20:36 +00:00
|
|
|
* mraid_mm_unregister_adp - Unregister routine for low level drivers
|
|
|
|
* @unique_id : UID of the adpater
|
2007-01-06 06:41:48 +00:00
|
|
|
*
|
|
|
|
* Assumes no outstanding ioctls to llds.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
mraid_mm_unregister_adp(uint32_t unique_id)
|
|
|
|
{
|
|
|
|
mraid_mmadp_t *adapter;
|
|
|
|
mraid_mmadp_t *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
|
|
|
|
|
|
|
|
|
|
|
|
if (adapter->unique_id == unique_id) {
|
|
|
|
|
|
|
|
adapters_count_g--;
|
|
|
|
|
|
|
|
list_del_init(&adapter->list);
|
|
|
|
|
|
|
|
mraid_mm_free_adp_resources(adapter);
|
|
|
|
|
|
|
|
kfree(adapter);
|
|
|
|
|
|
|
|
con_log(CL_ANN, (
|
|
|
|
"megaraid cmm: Unregistered one adapter:%#x\n",
|
|
|
|
unique_id));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_free_adp_resources - Free adapter softstate
|
|
|
|
* @adp : Adapter softstate
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
|
|
|
|
{
|
|
|
|
uioc_t *kioc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mraid_mm_teardown_dma_pools(adp);
|
|
|
|
|
|
|
|
for (i = 0; i < adp->max_kioc; i++) {
|
|
|
|
|
|
|
|
kioc = adp->kioc_list + i;
|
|
|
|
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_free(adp->pthru_dma_pool, kioc->pthru32,
|
2005-04-16 22:20:36 +00:00
|
|
|
kioc->pthru32_h);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(adp->kioc_list);
|
|
|
|
kfree(adp->mbox_list);
|
|
|
|
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_destroy(adp->pthru_dma_pool);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
|
|
|
|
* @adp : Adapter softstate
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
mm_dmapool_t *pool;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DMA_POOLS; i++) {
|
|
|
|
|
|
|
|
pool = &adp->dma_pool_list[i];
|
|
|
|
|
|
|
|
if (pool->handle) {
|
|
|
|
|
|
|
|
if (pool->vaddr)
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_free(pool->handle, pool->vaddr,
|
2005-04-16 22:20:36 +00:00
|
|
|
pool->paddr);
|
|
|
|
|
2017-07-06 08:13:06 +00:00
|
|
|
dma_pool_destroy(pool->handle);
|
2005-04-16 22:20:36 +00:00
|
|
|
pool->handle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-01-06 06:41:48 +00:00
|
|
|
* mraid_mm_init - Module entry point
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static int __init
|
|
|
|
mraid_mm_init(void)
|
|
|
|
{
|
2008-02-05 07:53:18 +00:00
|
|
|
int err;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
// Announce the driver version
|
|
|
|
con_log(CL_ANN, (KERN_INFO "megaraid cmm: %s %s\n",
|
|
|
|
LSI_COMMON_MOD_VERSION, LSI_COMMON_MOD_EXT_VERSION));
|
|
|
|
|
2008-02-05 07:53:18 +00:00
|
|
|
err = misc_register(&megaraid_mm_dev);
|
|
|
|
if (err < 0) {
|
|
|
|
con_log(CL_ANN, ("megaraid cmm: cannot register misc device\n"));
|
|
|
|
return err;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init_waitqueue_head(&wait_q);
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&adapters_list_g);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-06 06:41:48 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
2005-04-16 22:20:36 +00:00
|
|
|
/**
|
2007-01-06 06:41:48 +00:00
|
|
|
* mraid_mm_compat_ioctl - 32bit to 64bit ioctl conversion routine
|
|
|
|
* @filep : file operations pointer (ignored)
|
|
|
|
* @cmd : ioctl command
|
|
|
|
* @arg : user ioctl packet
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static long
|
|
|
|
mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int err;
|
2005-05-16 22:32:17 +00:00
|
|
|
|
2010-04-26 22:24:01 +00:00
|
|
|
err = mraid_mm_ioctl(filep, cmd, arg);
|
2005-05-16 22:32:17 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2007-01-06 06:41:48 +00:00
|
|
|
* mraid_mm_exit - Module exit point
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
static void __exit
|
|
|
|
mraid_mm_exit(void)
|
|
|
|
{
|
|
|
|
con_log(CL_DLEVEL1 , ("exiting common mod\n"));
|
|
|
|
|
2008-02-05 07:53:18 +00:00
|
|
|
misc_deregister(&megaraid_mm_dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mraid_mm_init);
|
|
|
|
module_exit(mraid_mm_exit);
|
|
|
|
|
|
|
|
/* vi: set ts=8 sw=8 tw=78: */
|