2005-04-17 06:20:36 +08:00
|
|
|
/* $Id: kcapi.c,v 1.1.2.8 2004/03/26 19:57:20 armin Exp $
|
2012-02-20 11:52:38 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Kernel CAPI 2.0 Module
|
2012-02-20 11:52:38 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright 1999 by Carsten Paeth <calle@calle.de>
|
|
|
|
* Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
|
2012-02-20 11:52:38 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This software may be used and distributed according to the terms
|
|
|
|
* of the GNU General Public License, incorporated herein by reference.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-04-28 17:14:42 +08:00
|
|
|
#define AVMB1_COMPAT
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "kcapi.h"
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/capi.h>
|
|
|
|
#include <linux/kernelcapi.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/delay.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <linux/isdn/capicmd.h>
|
|
|
|
#include <linux/isdn/capiutil.h>
|
2008-04-28 17:14:42 +08:00
|
|
|
#ifdef AVMB1_COMPAT
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/b1lli.h>
|
|
|
|
#endif
|
2006-03-23 19:00:21 +08:00
|
|
|
#include <linux/mutex.h>
|
2010-02-08 18:12:15 +08:00
|
|
|
#include <linux/rcupdate.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int showcapimsgs = 0;
|
2010-12-24 22:59:06 +08:00
|
|
|
static struct workqueue_struct *kcapi_wq;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer");
|
|
|
|
MODULE_AUTHOR("Carsten Paeth");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
module_param(showcapimsgs, uint, 0);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
struct capictr_event {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct work_struct work;
|
2010-02-08 18:12:13 +08:00
|
|
|
unsigned int type;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 controller;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
static struct capi_version driver_version = {2, 0, 1, 1 << 4};
|
2005-04-17 06:20:36 +08:00
|
|
|
static char driver_serial[CAPI_SERIAL_LEN] = "0004711";
|
|
|
|
static char capi_manufakturer[64] = "AVM Berlin";
|
|
|
|
|
|
|
|
#define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f)
|
|
|
|
|
|
|
|
LIST_HEAD(capi_drivers);
|
2010-02-08 18:12:11 +08:00
|
|
|
DEFINE_MUTEX(capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
struct capi_ctr *capi_controller[CAPI_MAXCONTR];
|
|
|
|
DEFINE_MUTEX(capi_controller_lock);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct capi20_appl *capi_applications[CAPI_MAXAPPL];
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
static int ncontrollers;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
static BLOCKING_NOTIFIER_HEAD(ctr_notifier_list);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* -------- controller ref counting -------------------------------------- */
|
|
|
|
|
|
|
|
static inline struct capi_ctr *
|
2010-02-08 18:12:10 +08:00
|
|
|
capi_ctr_get(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
if (!try_module_get(ctr->owner))
|
2005-04-17 06:20:36 +08:00
|
|
|
return NULL;
|
2010-02-08 18:12:10 +08:00
|
|
|
return ctr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2010-02-08 18:12:10 +08:00
|
|
|
capi_ctr_put(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
module_put(ctr->owner);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
|
|
|
|
{
|
|
|
|
if (contr - 1 >= CAPI_MAXCONTR)
|
|
|
|
return NULL;
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
return capi_controller[contr - 1];
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-10-17 13:18:15 +08:00
|
|
|
static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
|
|
|
|
{
|
|
|
|
lockdep_assert_held(&capi_controller_lock);
|
|
|
|
|
|
|
|
if (applid - 1 >= CAPI_MAXAPPL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return capi_applications[applid - 1];
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
|
|
|
|
{
|
|
|
|
if (applid - 1 >= CAPI_MAXAPPL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-02-08 18:12:15 +08:00
|
|
|
return rcu_dereference(capi_applications[applid - 1]);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------- util functions ------------------------------------ */
|
|
|
|
|
|
|
|
static inline int capi_cmd_valid(u8 cmd)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CAPI_ALERT:
|
|
|
|
case CAPI_CONNECT:
|
|
|
|
case CAPI_CONNECT_ACTIVE:
|
|
|
|
case CAPI_CONNECT_B3_ACTIVE:
|
|
|
|
case CAPI_CONNECT_B3:
|
|
|
|
case CAPI_CONNECT_B3_T90_ACTIVE:
|
|
|
|
case CAPI_DATA_B3:
|
|
|
|
case CAPI_DISCONNECT_B3:
|
|
|
|
case CAPI_DISCONNECT:
|
|
|
|
case CAPI_FACILITY:
|
|
|
|
case CAPI_INFO:
|
|
|
|
case CAPI_LISTEN:
|
|
|
|
case CAPI_MANUFACTURER:
|
|
|
|
case CAPI_RESET_B3:
|
|
|
|
case CAPI_SELECT_B_PROTOCOL:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int capi_subcmd_valid(u8 subcmd)
|
|
|
|
{
|
|
|
|
switch (subcmd) {
|
|
|
|
case CAPI_REQ:
|
|
|
|
case CAPI_CONF:
|
|
|
|
case CAPI_IND:
|
|
|
|
case CAPI_RESP:
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------ */
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
static void
|
|
|
|
register_appl(struct capi_ctr *ctr, u16 applid, capi_register_params *rparam)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = capi_ctr_get(ctr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr)
|
|
|
|
ctr->register_appl(ctr, applid, rparam);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-02-08 18:12:10 +08:00
|
|
|
printk(KERN_WARNING "%s: cannot get controller resources\n",
|
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
static void release_appl(struct capi_ctr *ctr, u16 applid)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
DBG("applid %#x", applid);
|
2012-02-20 11:52:38 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->release_appl(ctr, applid);
|
|
|
|
capi_ctr_put(ctr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void notify_up(u32 contr)
|
|
|
|
{
|
|
|
|
struct capi20_appl *ap;
|
2010-02-08 18:12:12 +08:00
|
|
|
struct capi_ctr *ctr;
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 applid;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:12 +08:00
|
|
|
if (showcapimsgs & 1)
|
2012-02-20 11:52:38 +08:00
|
|
|
printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr);
|
2010-02-08 18:12:12 +08:00
|
|
|
|
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
|
|
|
if (ctr) {
|
|
|
|
if (ctr->state == CAPI_CTR_RUNNING)
|
2010-02-08 18:12:14 +08:00
|
|
|
goto unlock_out;
|
2010-02-08 18:12:12 +08:00
|
|
|
|
|
|
|
ctr->state = CAPI_CTR_RUNNING;
|
|
|
|
|
|
|
|
for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
|
2010-10-17 13:18:15 +08:00
|
|
|
ap = __get_capi_appl_by_nr(applid);
|
|
|
|
if (ap)
|
|
|
|
register_appl(ctr, applid, &ap->rparam);
|
2010-02-08 18:12:12 +08:00
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
wake_up_interruptible_all(&ctr->state_wait_queue);
|
2010-02-08 18:12:12 +08:00
|
|
|
} else
|
2008-04-28 17:14:40 +08:00
|
|
|
printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
unlock_out:
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
static void ctr_down(struct capi_ctr *ctr, int new_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct capi20_appl *ap;
|
|
|
|
u16 applid;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr->state == CAPI_CTR_DETECTED || ctr->state == CAPI_CTR_DETACHED)
|
2010-02-08 18:12:12 +08:00
|
|
|
return;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
ctr->state = new_state;
|
2010-02-08 18:12:12 +08:00
|
|
|
|
|
|
|
memset(ctr->manu, 0, sizeof(ctr->manu));
|
|
|
|
memset(&ctr->version, 0, sizeof(ctr->version));
|
|
|
|
memset(&ctr->profile, 0, sizeof(ctr->profile));
|
|
|
|
memset(ctr->serial, 0, sizeof(ctr->serial));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
|
2010-10-17 13:18:15 +08:00
|
|
|
ap = __get_capi_appl_by_nr(applid);
|
2010-02-08 18:12:15 +08:00
|
|
|
if (ap)
|
2010-02-08 18:12:12 +08:00
|
|
|
capi_ctr_put(ctr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
wake_up_interruptible_all(&ctr->state_wait_queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:12 +08:00
|
|
|
static void notify_down(u32 contr)
|
|
|
|
{
|
|
|
|
struct capi_ctr *ctr;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:12 +08:00
|
|
|
if (showcapimsgs & 1)
|
|
|
|
printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr);
|
|
|
|
|
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
|
|
|
if (ctr)
|
2010-02-08 18:12:14 +08:00
|
|
|
ctr_down(ctr, CAPI_CTR_DETECTED);
|
2010-02-08 18:12:12 +08:00
|
|
|
else
|
|
|
|
printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
2010-02-08 18:12:12 +08:00
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
static int
|
|
|
|
notify_handler(struct notifier_block *nb, unsigned long val, void *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:13 +08:00
|
|
|
u32 contr = (long)v;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
switch (val) {
|
|
|
|
case CAPICTR_UP:
|
|
|
|
notify_up(contr);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-02-08 18:12:13 +08:00
|
|
|
case CAPICTR_DOWN:
|
|
|
|
notify_down(contr);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-02-08 18:12:13 +08:00
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_notify_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct capictr_event *event =
|
|
|
|
container_of(work, struct capictr_event, work);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
blocking_notifier_call_chain(&ctr_notifier_list, event->type,
|
|
|
|
(void *)(long)event->controller);
|
|
|
|
kfree(event);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The notifier will result in adding/deleteing of devices. Devices can
|
|
|
|
* only removed in user process, not in bh.
|
|
|
|
*/
|
2010-02-08 18:12:13 +08:00
|
|
|
static int notify_push(unsigned int event_type, u32 controller)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:13 +08:00
|
|
|
struct capictr_event *event = kmalloc(sizeof(*event), GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
if (!event)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
INIT_WORK(&event->work, do_notify_work);
|
|
|
|
event->type = event_type;
|
|
|
|
event->controller = controller;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-24 22:59:06 +08:00
|
|
|
queue_work(kcapi_wq, &event->work);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
int register_capictr_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return blocking_notifier_chain_register(&ctr_notifier_list, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(register_capictr_notifier);
|
|
|
|
|
|
|
|
int unregister_capictr_notifier(struct notifier_block *nb)
|
|
|
|
{
|
|
|
|
return blocking_notifier_chain_unregister(&ctr_notifier_list, nb);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(unregister_capictr_notifier);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* -------- Receiver ------------------------------------------ */
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void recv_handler(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
2006-11-22 22:57:56 +08:00
|
|
|
struct capi20_appl *ap =
|
|
|
|
container_of(work, struct capi20_appl, recv_work);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if ((!ap) || (ap->release_in_progress))
|
|
|
|
return;
|
|
|
|
|
2007-07-17 19:04:16 +08:00
|
|
|
mutex_lock(&ap->recv_mtx);
|
2005-04-17 06:20:36 +08:00
|
|
|
while ((skb = skb_dequeue(&ap->recv_queue))) {
|
|
|
|
if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_IND)
|
|
|
|
ap->nrecvdatapkt++;
|
|
|
|
else
|
|
|
|
ap->nrecvctlpkt++;
|
|
|
|
|
|
|
|
ap->recv_message(ap, skb);
|
|
|
|
}
|
2007-07-17 19:04:16 +08:00
|
|
|
mutex_unlock(&ap->recv_mtx);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi_ctr_handle_message() - handle incoming CAPI message
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
* @appl: application ID.
|
|
|
|
* @skb: message.
|
|
|
|
*
|
|
|
|
* Called by hardware driver to pass a CAPI message to the application.
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl,
|
|
|
|
struct sk_buff *skb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct capi20_appl *ap;
|
|
|
|
int showctl = 0;
|
|
|
|
u8 cmd, subcmd;
|
2007-03-01 12:13:50 +08:00
|
|
|
_cdebbuf *cdb;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->state != CAPI_CTR_RUNNING) {
|
2007-03-01 12:13:50 +08:00
|
|
|
cdb = capi_message2str(skb->data);
|
|
|
|
if (cdb) {
|
|
|
|
printk(KERN_INFO "kcapi: controller [%03d] not active, got: %s",
|
2012-02-20 11:52:38 +08:00
|
|
|
ctr->cnr, cdb->buf);
|
2007-03-01 12:13:50 +08:00
|
|
|
cdebbuf_free(cdb);
|
|
|
|
} else
|
|
|
|
printk(KERN_INFO "kcapi: controller [%03d] not active, cannot trace\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
ctr->cnr);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = CAPIMSG_COMMAND(skb->data);
|
2012-02-20 11:52:38 +08:00
|
|
|
subcmd = CAPIMSG_SUBCOMMAND(skb->data);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cmd == CAPI_DATA_B3 && subcmd == CAPI_IND) {
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->nrecvdatapkt++;
|
|
|
|
if (ctr->traceflag > 2)
|
|
|
|
showctl |= 2;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->nrecvctlpkt++;
|
|
|
|
if (ctr->traceflag)
|
|
|
|
showctl |= 2;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
showctl |= (ctr->traceflag & 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (showctl & 2) {
|
|
|
|
if (showctl & 1) {
|
2007-03-01 12:13:50 +08:00
|
|
|
printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u\n",
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->cnr, CAPIMSG_APPID(skb->data),
|
2005-04-17 06:20:36 +08:00
|
|
|
capi_cmd2str(cmd, subcmd),
|
|
|
|
CAPIMSG_LEN(skb->data));
|
|
|
|
} else {
|
2007-03-01 12:13:50 +08:00
|
|
|
cdb = capi_message2str(skb->data);
|
|
|
|
if (cdb) {
|
|
|
|
printk(KERN_DEBUG "kcapi: got [%03d] %s\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
ctr->cnr, cdb->buf);
|
2007-03-01 12:13:50 +08:00
|
|
|
cdebbuf_free(cdb);
|
|
|
|
} else
|
|
|
|
printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u, cannot trace\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
ctr->cnr, CAPIMSG_APPID(skb->data),
|
|
|
|
capi_cmd2str(cmd, subcmd),
|
|
|
|
CAPIMSG_LEN(skb->data));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:15 +08:00
|
|
|
rcu_read_lock();
|
2005-04-17 06:20:36 +08:00
|
|
|
ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data));
|
2010-02-08 18:12:15 +08:00
|
|
|
if (!ap) {
|
|
|
|
rcu_read_unlock();
|
2007-03-01 12:13:50 +08:00
|
|
|
cdb = capi_message2str(skb->data);
|
|
|
|
if (cdb) {
|
|
|
|
printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
CAPIMSG_APPID(skb->data), cdb->buf);
|
2007-03-01 12:13:50 +08:00
|
|
|
cdebbuf_free(cdb);
|
|
|
|
} else
|
|
|
|
printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s) cannot trace\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
CAPIMSG_APPID(skb->data),
|
|
|
|
capi_cmd2str(cmd, subcmd));
|
2005-04-17 06:20:36 +08:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
skb_queue_tail(&ap->recv_queue, skb);
|
2010-12-24 22:59:06 +08:00
|
|
|
queue_work(kcapi_wq, &ap->recv_work);
|
2010-02-08 18:12:15 +08:00
|
|
|
rcu_read_unlock();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi_ctr_handle_message);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi_ctr_ready() - signal CAPI controller ready
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to signal that the controller is up and running.
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
void capi_ctr_ready(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
printk(KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n",
|
|
|
|
ctr->cnr, ctr->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
notify_push(CAPICTR_UP, ctr->cnr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi_ctr_ready);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
2009-06-07 17:09:23 +08:00
|
|
|
* capi_ctr_down() - signal CAPI controller not ready
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to signal that the controller is down and
|
|
|
|
* unavailable for use.
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
void capi_ctr_down(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
printk(KERN_NOTICE "kcapi: controller [%03d] down.\n", ctr->cnr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
notify_push(CAPICTR_DOWN, ctr->cnr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-06-07 17:09:23 +08:00
|
|
|
EXPORT_SYMBOL(capi_ctr_down);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi_ctr_suspend_output() - suspend controller
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to stop data flow.
|
2010-02-08 18:12:14 +08:00
|
|
|
*
|
|
|
|
* Note: The caller is responsible for synchronizing concurrent state changes
|
|
|
|
* as well as invocations of capi_ctr_handle_message.
|
2009-04-23 10:24:21 +08:00
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
void capi_ctr_suspend_output(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
if (!ctr->blocked) {
|
|
|
|
printk(KERN_DEBUG "kcapi: controller [%03d] suspend\n",
|
|
|
|
ctr->cnr);
|
|
|
|
ctr->blocked = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi_ctr_suspend_output);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi_ctr_resume_output() - resume controller
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to resume data flow.
|
2010-02-08 18:12:14 +08:00
|
|
|
*
|
|
|
|
* Note: The caller is responsible for synchronizing concurrent state changes
|
|
|
|
* as well as invocations of capi_ctr_handle_message.
|
2009-04-23 10:24:21 +08:00
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
void capi_ctr_resume_output(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->blocked) {
|
|
|
|
printk(KERN_DEBUG "kcapi: controller [%03d] resumed\n",
|
|
|
|
ctr->cnr);
|
|
|
|
ctr->blocked = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi_ctr_resume_output);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* attach_capi_ctr() - register CAPI controller
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to register a controller with the CAPI subsystem.
|
|
|
|
* Return value: 0 on success, error code < 0 on error
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
int attach_capi_ctr(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < CAPI_MAXCONTR; i++) {
|
2010-02-08 18:12:10 +08:00
|
|
|
if (!capi_controller[i])
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == CAPI_MAXCONTR) {
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "kcapi: out of controller slots\n");
|
2012-02-20 11:52:38 +08:00
|
|
|
return -EBUSY;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
capi_controller[i] = ctr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->nrecvctlpkt = 0;
|
|
|
|
ctr->nrecvdatapkt = 0;
|
|
|
|
ctr->nsentctlpkt = 0;
|
|
|
|
ctr->nsentdatapkt = 0;
|
|
|
|
ctr->cnr = i + 1;
|
|
|
|
ctr->state = CAPI_CTR_DETECTED;
|
|
|
|
ctr->blocked = 0;
|
|
|
|
ctr->traceflag = showcapimsgs;
|
2010-02-08 18:12:14 +08:00
|
|
|
init_waitqueue_head(&ctr->state_wait_queue);
|
2010-02-08 18:12:10 +08:00
|
|
|
|
|
|
|
sprintf(ctr->procfn, "capi/controllers/%d", ctr->cnr);
|
|
|
|
ctr->procent = proc_create_data(ctr->procfn, 0, NULL, ctr->proc_fops, ctr);
|
|
|
|
|
|
|
|
ncontrollers++;
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
printk(KERN_NOTICE "kcapi: controller [%03d]: %s attached\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
ctr->cnr, ctr->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(attach_capi_ctr);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* detach_capi_ctr() - unregister CAPI controller
|
2010-02-08 18:12:10 +08:00
|
|
|
* @ctr: controller descriptor structure.
|
2009-04-23 10:24:21 +08:00
|
|
|
*
|
|
|
|
* Called by hardware driver to remove the registration of a controller
|
|
|
|
* with the CAPI subsystem.
|
|
|
|
* Return value: 0 on success, error code < 0 on error
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
int detach_capi_ctr(struct capi_ctr *ctr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-02-08 18:12:14 +08:00
|
|
|
int err = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
ctr_down(ctr, CAPI_CTR_DETACHED);
|
|
|
|
|
|
|
|
if (capi_controller[ctr->cnr - 1] != ctr) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
capi_controller[ctr->cnr - 1] = NULL;
|
2010-02-08 18:12:14 +08:00
|
|
|
ncontrollers--;
|
|
|
|
|
|
|
|
if (ctr->procent)
|
|
|
|
remove_proc_entry(ctr->procfn, NULL);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
printk(KERN_NOTICE "kcapi: controller [%03d]: %s unregistered\n",
|
|
|
|
ctr->cnr, ctr->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
unlock_out:
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(detach_capi_ctr);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* register_capi_driver() - register CAPI driver
|
|
|
|
* @driver: driver descriptor structure.
|
|
|
|
*
|
|
|
|
* Called by hardware driver to register itself with the CAPI subsystem.
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void register_capi_driver(struct capi_driver *driver)
|
|
|
|
{
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_lock(&capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_add_tail(&driver->list, &capi_drivers);
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_unlock(&capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(register_capi_driver);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* unregister_capi_driver() - unregister CAPI driver
|
|
|
|
* @driver: driver descriptor structure.
|
|
|
|
*
|
|
|
|
* Called by hardware driver to unregister itself from the CAPI subsystem.
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void unregister_capi_driver(struct capi_driver *driver)
|
|
|
|
{
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_lock(&capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_del(&driver->list);
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_unlock(&capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(unregister_capi_driver);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* -------- CAPI2.0 Interface ---------------------------------- */
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_isinstalled() - CAPI 2.0 operation CAPI_INSTALLED
|
|
|
|
*
|
|
|
|
* Return value: CAPI result code (CAPI_NOERROR if at least one ISDN controller
|
|
|
|
* is ready for use, CAPI_REGNOTINSTALLED otherwise)
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_isinstalled(void)
|
|
|
|
{
|
2010-02-08 18:12:14 +08:00
|
|
|
u16 ret = CAPI_REGNOTINSTALLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
|
|
|
for (i = 0; i < CAPI_MAXCONTR; i++)
|
2010-02-08 18:12:10 +08:00
|
|
|
if (capi_controller[i] &&
|
2010-02-08 18:12:14 +08:00
|
|
|
capi_controller[i]->state == CAPI_CTR_RUNNING) {
|
|
|
|
ret = CAPI_NOERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_isinstalled);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_register() - CAPI 2.0 operation CAPI_REGISTER
|
|
|
|
* @ap: CAPI application descriptor structure.
|
|
|
|
*
|
|
|
|
* Register an application's presence with CAPI.
|
|
|
|
* A unique application ID is assigned and stored in @ap->applid.
|
|
|
|
* After this function returns successfully, the message receive
|
|
|
|
* callback function @ap->recv_message() may be called at any time
|
|
|
|
* until capi20_release() has been called for the same @ap.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_register(struct capi20_appl *ap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u16 applid;
|
|
|
|
|
|
|
|
DBG("");
|
|
|
|
|
|
|
|
if (ap->rparam.datablklen < 128)
|
|
|
|
return CAPI_LOGBLKSIZETOSMALL;
|
|
|
|
|
2010-02-08 18:12:15 +08:00
|
|
|
ap->nrecvctlpkt = 0;
|
|
|
|
ap->nrecvdatapkt = 0;
|
|
|
|
ap->nsentctlpkt = 0;
|
|
|
|
ap->nsentdatapkt = 0;
|
|
|
|
mutex_init(&ap->recv_mtx);
|
|
|
|
skb_queue_head_init(&ap->recv_queue);
|
|
|
|
INIT_WORK(&ap->recv_work, recv_handler);
|
|
|
|
ap->release_in_progress = 0;
|
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
|
|
|
|
if (capi_applications[applid - 1] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (applid > CAPI_MAXAPPL) {
|
2010-02-08 18:12:15 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return CAPI_TOOMANYAPPLS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ap->applid = applid;
|
|
|
|
capi_applications[applid - 1] = ap;
|
|
|
|
|
|
|
|
for (i = 0; i < CAPI_MAXCONTR; i++) {
|
2010-02-08 18:12:10 +08:00
|
|
|
if (!capi_controller[i] ||
|
|
|
|
capi_controller[i]->state != CAPI_CTR_RUNNING)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2010-02-08 18:12:10 +08:00
|
|
|
register_appl(capi_controller[i], applid, &ap->rparam);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (showcapimsgs & 1) {
|
|
|
|
printk(KERN_DEBUG "kcapi: appl %d up\n", applid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_register);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_release() - CAPI 2.0 operation CAPI_RELEASE
|
|
|
|
* @ap: CAPI application descriptor structure.
|
|
|
|
*
|
|
|
|
* Terminate an application's registration with CAPI.
|
|
|
|
* After this function returns successfully, the message receive
|
|
|
|
* callback function @ap->recv_message() will no longer be called.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_release(struct capi20_appl *ap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG("applid %#x", ap->applid);
|
|
|
|
|
2010-02-08 18:12:15 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ap->release_in_progress = 1;
|
|
|
|
capi_applications[ap->applid - 1] = NULL;
|
|
|
|
|
2010-02-08 18:12:15 +08:00
|
|
|
synchronize_rcu();
|
2010-02-08 18:12:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < CAPI_MAXCONTR; i++) {
|
2010-02-08 18:12:10 +08:00
|
|
|
if (!capi_controller[i] ||
|
|
|
|
capi_controller[i]->state != CAPI_CTR_RUNNING)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2010-02-08 18:12:10 +08:00
|
|
|
release_appl(capi_controller[i], ap->applid);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-24 22:59:06 +08:00
|
|
|
flush_workqueue(kcapi_wq);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb_queue_purge(&ap->recv_queue);
|
|
|
|
|
|
|
|
if (showcapimsgs & 1) {
|
|
|
|
printk(KERN_DEBUG "kcapi: appl %d down\n", ap->applid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_release);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_put_message() - CAPI 2.0 operation CAPI_PUT_MESSAGE
|
|
|
|
* @ap: CAPI application descriptor structure.
|
|
|
|
* @skb: CAPI message.
|
|
|
|
*
|
|
|
|
* Transfer a single message to CAPI.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2005-04-17 06:20:36 +08:00
|
|
|
int showctl = 0;
|
|
|
|
u8 cmd, subcmd;
|
|
|
|
|
|
|
|
DBG("applid %#x", ap->applid);
|
2012-02-20 11:52:38 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ncontrollers == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return CAPI_REGNOTINSTALLED;
|
|
|
|
if ((ap->applid == 0) || ap->release_in_progress)
|
|
|
|
return CAPI_ILLAPPNR;
|
|
|
|
if (skb->len < 12
|
|
|
|
|| !capi_cmd_valid(CAPIMSG_COMMAND(skb->data))
|
|
|
|
|| !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data)))
|
|
|
|
return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The controller reference is protected by the existence of the
|
|
|
|
* application passed to us. We assume that the caller properly
|
|
|
|
* synchronizes this service with capi20_release.
|
|
|
|
*/
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data));
|
2010-02-08 18:12:43 +08:00
|
|
|
if (!ctr || ctr->state != CAPI_CTR_RUNNING)
|
|
|
|
return CAPI_REGNOTINSTALLED;
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->blocked)
|
2005-04-17 06:20:36 +08:00
|
|
|
return CAPI_SENDQUEUEFULL;
|
|
|
|
|
|
|
|
cmd = CAPIMSG_COMMAND(skb->data);
|
2012-02-20 11:52:38 +08:00
|
|
|
subcmd = CAPIMSG_SUBCOMMAND(skb->data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
if (cmd == CAPI_DATA_B3 && subcmd == CAPI_REQ) {
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->nsentdatapkt++;
|
2005-04-17 06:20:36 +08:00
|
|
|
ap->nsentdatapkt++;
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->traceflag > 2)
|
|
|
|
showctl |= 2;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->nsentctlpkt++;
|
2005-04-17 06:20:36 +08:00
|
|
|
ap->nsentctlpkt++;
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->traceflag)
|
|
|
|
showctl |= 2;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
showctl |= (ctr->traceflag & 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (showctl & 2) {
|
|
|
|
if (showctl & 1) {
|
2007-03-01 12:13:50 +08:00
|
|
|
printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
CAPIMSG_CONTROLLER(skb->data),
|
|
|
|
CAPIMSG_APPID(skb->data),
|
|
|
|
capi_cmd2str(cmd, subcmd),
|
|
|
|
CAPIMSG_LEN(skb->data));
|
|
|
|
} else {
|
2007-03-01 12:13:50 +08:00
|
|
|
_cdebbuf *cdb = capi_message2str(skb->data);
|
|
|
|
if (cdb) {
|
|
|
|
printk(KERN_DEBUG "kcapi: put [%03d] %s\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
CAPIMSG_CONTROLLER(skb->data),
|
|
|
|
cdb->buf);
|
2007-03-01 12:13:50 +08:00
|
|
|
cdebbuf_free(cdb);
|
|
|
|
} else
|
|
|
|
printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u cannot trace\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
CAPIMSG_CONTROLLER(skb->data),
|
|
|
|
CAPIMSG_APPID(skb->data),
|
|
|
|
capi_cmd2str(cmd, subcmd),
|
|
|
|
CAPIMSG_LEN(skb->data));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
return ctr->send_message(ctr, skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_put_message);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_get_manufacturer() - CAPI 2.0 operation CAPI_GET_MANUFACTURER
|
|
|
|
* @contr: controller number.
|
|
|
|
* @buf: result buffer (64 bytes).
|
|
|
|
*
|
|
|
|
* Retrieve information about the manufacturer of the specified ISDN controller
|
|
|
|
* or (for @contr == 0) the driver itself.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_get_manufacturer(u32 contr, u8 *buf)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2010-02-08 18:12:14 +08:00
|
|
|
u16 ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (contr == 0) {
|
|
|
|
strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN);
|
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr && ctr->state == CAPI_CTR_RUNNING) {
|
|
|
|
strlcpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN);
|
|
|
|
ret = CAPI_NOERROR;
|
|
|
|
} else
|
|
|
|
ret = CAPI_REGNOTINSTALLED;
|
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_get_manufacturer);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_get_version() - CAPI 2.0 operation CAPI_GET_VERSION
|
|
|
|
* @contr: controller number.
|
|
|
|
* @verp: result structure.
|
|
|
|
*
|
|
|
|
* Retrieve version information for the specified ISDN controller
|
|
|
|
* or (for @contr == 0) the driver itself.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_get_version(u32 contr, struct capi_version *verp)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2010-02-08 18:12:14 +08:00
|
|
|
u16 ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (contr == 0) {
|
|
|
|
*verp = driver_version;
|
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr && ctr->state == CAPI_CTR_RUNNING) {
|
|
|
|
memcpy(verp, &ctr->version, sizeof(capi_version));
|
|
|
|
ret = CAPI_NOERROR;
|
|
|
|
} else
|
|
|
|
ret = CAPI_REGNOTINSTALLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_get_version);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_get_serial() - CAPI 2.0 operation CAPI_GET_SERIAL_NUMBER
|
|
|
|
* @contr: controller number.
|
|
|
|
* @serial: result buffer (8 bytes).
|
|
|
|
*
|
|
|
|
* Retrieve the serial number of the specified ISDN controller
|
|
|
|
* or (for @contr == 0) the driver itself.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_get_serial(u32 contr, u8 *serial)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2010-02-08 18:12:14 +08:00
|
|
|
u16 ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (contr == 0) {
|
|
|
|
strlcpy(serial, driver_serial, CAPI_SERIAL_LEN);
|
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr && ctr->state == CAPI_CTR_RUNNING) {
|
|
|
|
strlcpy(serial, ctr->serial, CAPI_SERIAL_LEN);
|
|
|
|
ret = CAPI_NOERROR;
|
|
|
|
} else
|
|
|
|
ret = CAPI_REGNOTINSTALLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_get_serial);
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_get_profile() - CAPI 2.0 operation CAPI_GET_PROFILE
|
|
|
|
* @contr: controller number.
|
|
|
|
* @profp: result structure.
|
|
|
|
*
|
|
|
|
* Retrieve capability information for the specified ISDN controller
|
|
|
|
* or (for @contr == 0) the number of installed controllers.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
u16 capi20_get_profile(u32 contr, struct capi_profile *profp)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2010-02-08 18:12:14 +08:00
|
|
|
u16 ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (contr == 0) {
|
2010-02-08 18:12:10 +08:00
|
|
|
profp->ncontroller = ncontrollers;
|
2005-04-17 06:20:36 +08:00
|
|
|
return CAPI_NOERROR;
|
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr && ctr->state == CAPI_CTR_RUNNING) {
|
|
|
|
memcpy(profp, &ctr->profile, sizeof(struct capi_profile));
|
|
|
|
ret = CAPI_NOERROR;
|
|
|
|
} else
|
|
|
|
ret = CAPI_REGNOTINSTALLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_get_profile);
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
/* Must be called with capi_controller_lock held. */
|
|
|
|
static int wait_on_ctr_state(struct capi_ctr *ctr, unsigned int state)
|
|
|
|
{
|
|
|
|
DEFINE_WAIT(wait);
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
ctr = capi_ctr_get(ctr);
|
|
|
|
if (!ctr)
|
|
|
|
return -ESRCH;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
prepare_to_wait(&ctr->state_wait_queue, &wait,
|
|
|
|
TASK_INTERRUPTIBLE);
|
|
|
|
|
|
|
|
if (ctr->state == state)
|
|
|
|
break;
|
|
|
|
if (ctr->state == CAPI_CTR_DETACHED) {
|
|
|
|
retval = -ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
retval = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
schedule();
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
}
|
|
|
|
finish_wait(&ctr->state_wait_queue, &wait);
|
|
|
|
|
|
|
|
capi_ctr_put(ctr);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-04-28 17:14:42 +08:00
|
|
|
#ifdef AVMB1_COMPAT
|
2005-04-17 06:20:36 +08:00
|
|
|
static int old_capi_manufacturer(unsigned int cmd, void __user *data)
|
|
|
|
{
|
|
|
|
avmb1_loadandconfigdef ldef;
|
|
|
|
avmb1_extcarddef cdef;
|
|
|
|
avmb1_resetdef rdef;
|
|
|
|
capicardparams cparams;
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct capi_driver *driver = NULL;
|
|
|
|
capiloaddata ldata;
|
|
|
|
struct list_head *l;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case AVMB1_ADDCARD:
|
|
|
|
case AVMB1_ADDCARD_WITH_TYPE:
|
|
|
|
if (cmd == AVMB1_ADDCARD) {
|
2012-02-20 11:52:38 +08:00
|
|
|
if ((retval = copy_from_user(&cdef, data,
|
|
|
|
sizeof(avmb1_carddef))))
|
|
|
|
return -EFAULT;
|
|
|
|
cdef.cardtype = AVM_CARDTYPE_B1;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2012-02-20 11:52:38 +08:00
|
|
|
if ((retval = copy_from_user(&cdef, data,
|
|
|
|
sizeof(avmb1_extcarddef))))
|
|
|
|
return -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
cparams.port = cdef.port;
|
|
|
|
cparams.irq = cdef.irq;
|
|
|
|
cparams.cardnr = cdef.cardnr;
|
|
|
|
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_lock(&capi_drivers_lock);
|
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
switch (cdef.cardtype) {
|
|
|
|
case AVM_CARDTYPE_B1:
|
|
|
|
list_for_each(l, &capi_drivers) {
|
|
|
|
driver = list_entry(l, struct capi_driver, list);
|
|
|
|
if (strcmp(driver->name, "b1isa") == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AVM_CARDTYPE_T1:
|
|
|
|
list_for_each(l, &capi_drivers) {
|
|
|
|
driver = list_entry(l, struct capi_driver, list);
|
|
|
|
if (strcmp(driver->name, "t1isa") == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
driver = NULL;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (!driver) {
|
|
|
|
printk(KERN_ERR "kcapi: driver not loaded.\n");
|
2010-02-08 18:12:11 +08:00
|
|
|
retval = -EIO;
|
|
|
|
} else if (!driver->add_card) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "kcapi: driver has no add card function.\n");
|
2010-02-08 18:12:11 +08:00
|
|
|
retval = -EIO;
|
|
|
|
} else
|
|
|
|
retval = driver->add_card(driver, &cparams);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_unlock(&capi_drivers_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
|
|
|
|
case AVMB1_LOAD:
|
|
|
|
case AVMB1_LOAD_AND_CONFIG:
|
|
|
|
|
|
|
|
if (cmd == AVMB1_LOAD) {
|
|
|
|
if (copy_from_user(&ldef, data,
|
|
|
|
sizeof(avmb1_loaddef)))
|
|
|
|
return -EFAULT;
|
|
|
|
ldef.t4config.len = 0;
|
|
|
|
ldef.t4config.data = NULL;
|
|
|
|
} else {
|
|
|
|
if (copy_from_user(&ldef, data,
|
|
|
|
sizeof(avmb1_loadandconfigdef)))
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(ldef.contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (!ctr) {
|
|
|
|
retval = -EINVAL;
|
|
|
|
goto load_unlock_out;
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->load_firmware == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_DEBUG "kcapi: load: no load function\n");
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = -ESRCH;
|
|
|
|
goto load_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ldef.t4file.len <= 0) {
|
|
|
|
printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len);
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto load_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-28 17:14:37 +08:00
|
|
|
if (ldef.t4file.data == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n");
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = -EINVAL;
|
|
|
|
goto load_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ldata.firmware.user = 1;
|
|
|
|
ldata.firmware.data = ldef.t4file.data;
|
|
|
|
ldata.firmware.len = ldef.t4file.len;
|
|
|
|
ldata.configuration.user = 1;
|
|
|
|
ldata.configuration.data = ldef.t4config.data;
|
|
|
|
ldata.configuration.len = ldef.t4config.len;
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->state != CAPI_CTR_DETECTED) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = -EBUSY;
|
|
|
|
goto load_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->state = CAPI_CTR_LOADING;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
retval = ctr->load_firmware(ctr, &ldata);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval) {
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->state = CAPI_CTR_DETECTED;
|
2010-02-08 18:12:14 +08:00
|
|
|
goto load_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = wait_on_ctr_state(ctr, CAPI_CTR_RUNNING);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
load_unlock_out:
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
case AVMB1_RESETCARD:
|
|
|
|
if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef)))
|
|
|
|
return -EFAULT;
|
2010-02-08 18:12:14 +08:00
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(rdef.contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (!ctr) {
|
|
|
|
retval = -ESRCH;
|
|
|
|
goto reset_unlock_out;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
if (ctr->state == CAPI_CTR_DETECTED)
|
2010-02-08 18:12:14 +08:00
|
|
|
goto reset_unlock_out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-05-23 09:02:08 +08:00
|
|
|
if (ctr->reset_ctr == NULL) {
|
|
|
|
printk(KERN_DEBUG "kcapi: reset: no reset function\n");
|
|
|
|
retval = -ESRCH;
|
|
|
|
goto reset_unlock_out;
|
|
|
|
}
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr->reset_ctr(ctr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
retval = wait_on_ctr_state(ctr, CAPI_CTR_DETECTED);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 11:52:38 +08:00
|
|
|
reset_unlock_out:
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_unlock(&capi_controller_lock);
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-23 10:24:21 +08:00
|
|
|
/**
|
|
|
|
* capi20_manufacturer() - CAPI 2.0 operation CAPI_MANUFACTURER
|
|
|
|
* @cmd: command.
|
|
|
|
* @data: parameter.
|
|
|
|
*
|
|
|
|
* Perform manufacturer specific command.
|
|
|
|
* Return value: CAPI result code
|
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int capi20_manufacturer(unsigned int cmd, void __user *data)
|
|
|
|
{
|
2010-02-08 18:12:10 +08:00
|
|
|
struct capi_ctr *ctr;
|
2010-02-08 18:12:14 +08:00
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (cmd) {
|
2008-04-28 17:14:42 +08:00
|
|
|
#ifdef AVMB1_COMPAT
|
2005-04-17 06:20:36 +08:00
|
|
|
case AVMB1_LOAD:
|
|
|
|
case AVMB1_LOAD_AND_CONFIG:
|
|
|
|
case AVMB1_RESETCARD:
|
|
|
|
case AVMB1_GET_CARDINFO:
|
|
|
|
case AVMB1_REMOVECARD:
|
|
|
|
return old_capi_manufacturer(cmd, data);
|
|
|
|
#endif
|
|
|
|
case KCAPI_CMD_TRACE:
|
|
|
|
{
|
|
|
|
kcapi_flagdef fdef;
|
|
|
|
|
|
|
|
if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
mutex_lock(&capi_controller_lock);
|
|
|
|
|
2010-02-08 18:12:10 +08:00
|
|
|
ctr = get_capi_ctr_by_nr(fdef.contr);
|
2010-02-08 18:12:14 +08:00
|
|
|
if (ctr) {
|
|
|
|
ctr->traceflag = fdef.flag;
|
|
|
|
printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n",
|
|
|
|
ctr->cnr, ctr->traceflag);
|
|
|
|
retval = 0;
|
|
|
|
} else
|
|
|
|
retval = -ESRCH;
|
|
|
|
|
|
|
|
mutex_unlock(&capi_controller_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:14 +08:00
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
case KCAPI_CMD_ADDCARD:
|
|
|
|
{
|
|
|
|
struct list_head *l;
|
|
|
|
struct capi_driver *driver = NULL;
|
|
|
|
capicardparams cparams;
|
|
|
|
kcapi_carddef cdef;
|
|
|
|
|
|
|
|
if ((retval = copy_from_user(&cdef, data, sizeof(cdef))))
|
2010-06-03 07:56:13 +08:00
|
|
|
return -EFAULT;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cparams.port = cdef.port;
|
|
|
|
cparams.irq = cdef.irq;
|
|
|
|
cparams.membase = cdef.membase;
|
|
|
|
cparams.cardnr = cdef.cardnr;
|
|
|
|
cparams.cardtype = 0;
|
2012-02-20 11:52:38 +08:00
|
|
|
cdef.driver[sizeof(cdef.driver) - 1] = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_lock(&capi_drivers_lock);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
list_for_each(l, &capi_drivers) {
|
|
|
|
driver = list_entry(l, struct capi_driver, list);
|
|
|
|
if (strcmp(driver->name, cdef.driver) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2008-04-28 17:14:37 +08:00
|
|
|
if (driver == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "kcapi: driver \"%s\" not loaded.\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
cdef.driver);
|
2010-02-08 18:12:11 +08:00
|
|
|
retval = -ESRCH;
|
|
|
|
} else if (!driver->add_card) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "kcapi: driver \"%s\" has no add card function.\n", cdef.driver);
|
2010-02-08 18:12:11 +08:00
|
|
|
retval = -EIO;
|
|
|
|
} else
|
|
|
|
retval = driver->add_card(driver, &cparams);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-08 18:12:11 +08:00
|
|
|
mutex_unlock(&capi_drivers_lock);
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "kcapi: manufacturer command %d unknown.\n",
|
2012-02-20 11:52:38 +08:00
|
|
|
cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(capi20_manufacturer);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
/* -------- Init & Cleanup ------------------------------------- */
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init / exit functions
|
|
|
|
*/
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
static struct notifier_block capictr_nb = {
|
|
|
|
.notifier_call = notify_handler,
|
|
|
|
.priority = INT_MAX,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init kcapi_init(void)
|
|
|
|
{
|
2010-02-08 18:12:09 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-24 22:59:06 +08:00
|
|
|
kcapi_wq = alloc_workqueue("kcapi", 0, 0);
|
|
|
|
if (!kcapi_wq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-02-08 18:12:13 +08:00
|
|
|
register_capictr_notifier(&capictr_nb);
|
|
|
|
|
2010-02-08 18:12:09 +08:00
|
|
|
err = cdebug_init();
|
2010-12-24 22:59:06 +08:00
|
|
|
if (err) {
|
|
|
|
unregister_capictr_notifier(&capictr_nb);
|
|
|
|
destroy_workqueue(kcapi_wq);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
kcapi_proc_init();
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit kcapi_exit(void)
|
|
|
|
{
|
2012-02-20 11:52:38 +08:00
|
|
|
kcapi_proc_exit();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-12-24 22:59:06 +08:00
|
|
|
unregister_capictr_notifier(&capictr_nb);
|
2007-03-01 12:13:50 +08:00
|
|
|
cdebug_exit();
|
2010-12-24 22:59:06 +08:00
|
|
|
destroy_workqueue(kcapi_wq);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(kcapi_init);
|
|
|
|
module_exit(kcapi_exit);
|