2019-05-27 13:55:21 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-27 06:54:58 +07:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Author Karsten Keil <kkeil@novell.com>
|
|
|
|
*
|
|
|
|
* Copyright 2008 by Karsten Keil <kkeil@novell.com>
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-07-27 06:54:58 +07:00
|
|
|
#include <linux/mISDNif.h>
|
|
|
|
#include <linux/kthread.h>
|
2012-11-13 20:20:55 +07:00
|
|
|
#include <linux/sched.h>
|
2017-02-05 17:48:36 +07:00
|
|
|
#include <linux/sched/cputime.h>
|
2017-02-04 05:47:37 +07:00
|
|
|
#include <linux/signal.h>
|
|
|
|
|
2008-07-27 06:54:58 +07:00
|
|
|
#include "core.h"
|
|
|
|
|
|
|
|
static u_int *debug;
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
_queue_message(struct mISDNstack *st, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct mISDNhead *hh = mISDN_HEAD_P(skb);
|
|
|
|
|
|
|
|
if (*debug & DEBUG_QUEUE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, hh->prim, hh->id, skb);
|
2008-07-27 06:54:58 +07:00
|
|
|
skb_queue_tail(&st->msgq, skb);
|
|
|
|
if (likely(!test_bit(mISDN_STACK_STOPPED, &st->status))) {
|
|
|
|
test_and_set_bit(mISDN_STACK_WORK, &st->status);
|
|
|
|
wake_up_interruptible(&st->workq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 12:15:17 +07:00
|
|
|
static int
|
2008-07-27 06:54:58 +07:00
|
|
|
mISDN_queue_message(struct mISDNchannel *ch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
_queue_message(ch->st, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mISDNchannel *
|
|
|
|
get_channel4id(struct mISDNstack *st, u_int id)
|
|
|
|
{
|
|
|
|
struct mISDNchannel *ch;
|
|
|
|
|
|
|
|
mutex_lock(&st->lmutex);
|
|
|
|
list_for_each_entry(ch, &st->layer2, list) {
|
|
|
|
if (id == ch->nr)
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
ch = NULL;
|
|
|
|
unlock:
|
|
|
|
mutex_unlock(&st->lmutex);
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_socklist(struct mISDN_sock_list *sl, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
struct sk_buff *cskb = NULL;
|
|
|
|
|
|
|
|
read_lock(&sl->lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 08:06:00 +07:00
|
|
|
sk_for_each(sk, &sl->head) {
|
2008-07-27 06:54:58 +07:00
|
|
|
if (sk->sk_state != MISDN_BOUND)
|
|
|
|
continue;
|
|
|
|
if (!cskb)
|
2017-05-31 14:08:25 +07:00
|
|
|
cskb = skb_copy(skb, GFP_ATOMIC);
|
2008-07-27 06:54:58 +07:00
|
|
|
if (!cskb) {
|
|
|
|
printk(KERN_WARNING "%s no skb\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!sock_queue_rcv_skb(sk, cskb))
|
|
|
|
cskb = NULL;
|
|
|
|
}
|
|
|
|
read_unlock(&sl->lock);
|
2019-08-22 01:10:56 +07:00
|
|
|
dev_kfree_skb(cskb);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_layer2(struct mISDNstack *st, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct sk_buff *cskb;
|
|
|
|
struct mISDNhead *hh = mISDN_HEAD_P(skb);
|
|
|
|
struct mISDNchannel *ch;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!st)
|
|
|
|
return;
|
|
|
|
mutex_lock(&st->lmutex);
|
|
|
|
if ((hh->id & MISDN_ID_ADDR_MASK) == MISDN_ID_ANY) { /* L2 for all */
|
|
|
|
list_for_each_entry(ch, &st->layer2, list) {
|
|
|
|
if (list_is_last(&ch->list, &st->layer2)) {
|
|
|
|
cskb = skb;
|
|
|
|
skb = NULL;
|
|
|
|
} else {
|
|
|
|
cskb = skb_copy(skb, GFP_KERNEL);
|
|
|
|
}
|
|
|
|
if (cskb) {
|
|
|
|
ret = ch->send(ch, cskb);
|
|
|
|
if (ret) {
|
|
|
|
if (*debug & DEBUG_SEND_ERR)
|
|
|
|
printk(KERN_DEBUG
|
2012-02-20 10:52:38 +07:00
|
|
|
"%s ch%d prim(%x) addr(%x)"
|
|
|
|
" err %d\n",
|
|
|
|
__func__, ch->nr,
|
|
|
|
hh->prim, ch->addr, ret);
|
2008-07-27 06:54:58 +07:00
|
|
|
dev_kfree_skb(cskb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printk(KERN_WARNING "%s ch%d addr %x no mem\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, ch->nr, ch->addr);
|
2008-07-27 06:54:58 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
list_for_each_entry(ch, &st->layer2, list) {
|
|
|
|
if ((hh->id & MISDN_ID_ADDR_MASK) == ch->addr) {
|
|
|
|
ret = ch->send(ch, skb);
|
|
|
|
if (!ret)
|
|
|
|
skb = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = st->dev->teimgr->ctrl(st->dev->teimgr, CHECK_DATA, skb);
|
|
|
|
if (!ret)
|
|
|
|
skb = NULL;
|
|
|
|
else if (*debug & DEBUG_SEND_ERR)
|
|
|
|
printk(KERN_DEBUG
|
2012-07-08 08:37:38 +07:00
|
|
|
"%s mgr prim(%x) err %d\n",
|
|
|
|
__func__, hh->prim, ret);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&st->lmutex);
|
2019-08-22 01:10:56 +07:00
|
|
|
dev_kfree_skb(skb);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
send_msg_to_layer(struct mISDNstack *st, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct mISDNhead *hh = mISDN_HEAD_P(skb);
|
|
|
|
struct mISDNchannel *ch;
|
|
|
|
int lm;
|
|
|
|
|
|
|
|
lm = hh->prim & MISDN_LAYERMASK;
|
|
|
|
if (*debug & DEBUG_QUEUE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, hh->prim, hh->id, skb);
|
2008-07-27 06:54:58 +07:00
|
|
|
if (lm == 0x1) {
|
|
|
|
if (!hlist_empty(&st->l1sock.head)) {
|
|
|
|
__net_timestamp(skb);
|
|
|
|
send_socklist(&st->l1sock, skb);
|
|
|
|
}
|
|
|
|
return st->layer1->send(st->layer1, skb);
|
|
|
|
} else if (lm == 0x2) {
|
|
|
|
if (!hlist_empty(&st->l1sock.head))
|
|
|
|
send_socklist(&st->l1sock, skb);
|
|
|
|
send_layer2(st, skb);
|
|
|
|
return 0;
|
|
|
|
} else if (lm == 0x4) {
|
|
|
|
ch = get_channel4id(st, hh->id);
|
|
|
|
if (ch)
|
|
|
|
return ch->send(ch, skb);
|
|
|
|
else
|
|
|
|
printk(KERN_WARNING
|
2012-02-20 10:52:38 +07:00
|
|
|
"%s: dev(%s) prim(%x) id(%x) no channel\n",
|
|
|
|
__func__, dev_name(&st->dev->dev), hh->prim,
|
|
|
|
hh->id);
|
2008-07-27 06:54:58 +07:00
|
|
|
} else if (lm == 0x8) {
|
|
|
|
WARN_ON(lm == 0x8);
|
|
|
|
ch = get_channel4id(st, hh->id);
|
|
|
|
if (ch)
|
|
|
|
return ch->send(ch, skb);
|
|
|
|
else
|
|
|
|
printk(KERN_WARNING
|
2012-02-20 10:52:38 +07:00
|
|
|
"%s: dev(%s) prim(%x) id(%x) no channel\n",
|
|
|
|
__func__, dev_name(&st->dev->dev), hh->prim,
|
|
|
|
hh->id);
|
2008-07-27 06:54:58 +07:00
|
|
|
} else {
|
|
|
|
/* broadcast not handled yet */
|
|
|
|
printk(KERN_WARNING "%s: dev(%s) prim %x not delivered\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, dev_name(&st->dev->dev), hh->prim);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
return -ESRCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_clear_stack(struct mISDNstack *st)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mISDNStackd(void *data)
|
|
|
|
{
|
|
|
|
struct mISDNstack *st = data;
|
2012-11-13 20:20:55 +07:00
|
|
|
#ifdef MISDN_MSG_STATS
|
2017-01-31 10:09:26 +07:00
|
|
|
u64 utime, stime;
|
2012-11-13 20:20:55 +07:00
|
|
|
#endif
|
2008-07-27 06:54:58 +07:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
sigfillset(¤t->blocked);
|
|
|
|
if (*debug & DEBUG_MSG_THREAD)
|
2008-08-16 05:04:33 +07:00
|
|
|
printk(KERN_DEBUG "mISDNStackd %s started\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&st->dev->dev));
|
2008-07-27 06:54:58 +07:00
|
|
|
|
|
|
|
if (st->notify != NULL) {
|
|
|
|
complete(st->notify);
|
|
|
|
st->notify = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
if (unlikely(test_bit(mISDN_STACK_STOPPED, &st->status))) {
|
|
|
|
test_and_clear_bit(mISDN_STACK_WORK, &st->status);
|
|
|
|
test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
} else
|
|
|
|
test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
while (test_bit(mISDN_STACK_WORK, &st->status)) {
|
|
|
|
skb = skb_dequeue(&st->msgq);
|
|
|
|
if (!skb) {
|
|
|
|
test_and_clear_bit(mISDN_STACK_WORK,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
/* test if a race happens */
|
|
|
|
skb = skb_dequeue(&st->msgq);
|
|
|
|
if (!skb)
|
|
|
|
continue;
|
|
|
|
test_and_set_bit(mISDN_STACK_WORK,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
#ifdef MISDN_MSG_STATS
|
|
|
|
st->msg_cnt++;
|
|
|
|
#endif
|
|
|
|
err = send_msg_to_layer(st, skb);
|
|
|
|
if (unlikely(err)) {
|
|
|
|
if (*debug & DEBUG_SEND_ERR)
|
|
|
|
printk(KERN_DEBUG
|
2012-02-20 10:52:38 +07:00
|
|
|
"%s: %s prim(%x) id(%x) "
|
|
|
|
"send call(%d)\n",
|
|
|
|
__func__, dev_name(&st->dev->dev),
|
|
|
|
mISDN_HEAD_PRIM(skb),
|
|
|
|
mISDN_HEAD_ID(skb), err);
|
2008-07-27 06:54:58 +07:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (unlikely(test_bit(mISDN_STACK_STOPPED,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status))) {
|
2008-07-27 06:54:58 +07:00
|
|
|
test_and_clear_bit(mISDN_STACK_WORK,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
test_and_clear_bit(mISDN_STACK_RUNNING,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (test_bit(mISDN_STACK_CLEARING, &st->status)) {
|
|
|
|
test_and_set_bit(mISDN_STACK_STOPPED, &st->status);
|
|
|
|
test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
do_clear_stack(st);
|
|
|
|
test_and_clear_bit(mISDN_STACK_CLEARING, &st->status);
|
|
|
|
test_and_set_bit(mISDN_STACK_RESTART, &st->status);
|
|
|
|
}
|
|
|
|
if (test_and_clear_bit(mISDN_STACK_RESTART, &st->status)) {
|
|
|
|
test_and_clear_bit(mISDN_STACK_STOPPED, &st->status);
|
|
|
|
test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
if (!skb_queue_empty(&st->msgq))
|
|
|
|
test_and_set_bit(mISDN_STACK_WORK,
|
2012-02-20 10:52:38 +07:00
|
|
|
&st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
if (test_bit(mISDN_STACK_ABORT, &st->status))
|
|
|
|
break;
|
|
|
|
if (st->notify != NULL) {
|
|
|
|
complete(st->notify);
|
|
|
|
st->notify = NULL;
|
|
|
|
}
|
|
|
|
#ifdef MISDN_MSG_STATS
|
|
|
|
st->sleep_cnt++;
|
|
|
|
#endif
|
|
|
|
test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
|
|
|
|
wait_event_interruptible(st->workq, (st->status &
|
2012-02-20 10:52:38 +07:00
|
|
|
mISDN_STACK_ACTION_MASK));
|
2008-07-27 06:54:58 +07:00
|
|
|
if (*debug & DEBUG_MSG_THREAD)
|
|
|
|
printk(KERN_DEBUG "%s: %s wake status %08lx\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, dev_name(&st->dev->dev), st->status);
|
2008-07-27 06:54:58 +07:00
|
|
|
test_and_set_bit(mISDN_STACK_ACTIVE, &st->status);
|
|
|
|
|
|
|
|
test_and_clear_bit(mISDN_STACK_WAKEUP, &st->status);
|
|
|
|
|
|
|
|
if (test_bit(mISDN_STACK_STOPPED, &st->status)) {
|
|
|
|
test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
#ifdef MISDN_MSG_STATS
|
|
|
|
st->stopped_cnt++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef MISDN_MSG_STATS
|
|
|
|
printk(KERN_DEBUG "mISDNStackd daemon for %s proceed %d "
|
2012-02-20 10:52:38 +07:00
|
|
|
"msg %d sleep %d stopped\n",
|
|
|
|
dev_name(&st->dev->dev), st->msg_cnt, st->sleep_cnt,
|
|
|
|
st->stopped_cnt);
|
2017-01-31 10:09:26 +07:00
|
|
|
task_cputime(st->thread, &utime, &stime);
|
2008-07-27 06:54:58 +07:00
|
|
|
printk(KERN_DEBUG
|
2017-01-31 10:09:26 +07:00
|
|
|
"mISDNStackd daemon for %s utime(%llu) stime(%llu)\n",
|
2012-11-13 20:20:55 +07:00
|
|
|
dev_name(&st->dev->dev), utime, stime);
|
2008-07-27 06:54:58 +07:00
|
|
|
printk(KERN_DEBUG
|
2012-02-20 10:52:38 +07:00
|
|
|
"mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n",
|
|
|
|
dev_name(&st->dev->dev), st->thread->nvcsw, st->thread->nivcsw);
|
2008-07-27 06:54:58 +07:00
|
|
|
printk(KERN_DEBUG "mISDNStackd daemon for %s killed now\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&st->dev->dev));
|
2008-07-27 06:54:58 +07:00
|
|
|
#endif
|
|
|
|
test_and_set_bit(mISDN_STACK_KILLED, &st->status);
|
|
|
|
test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
|
|
|
|
test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
|
|
|
|
test_and_clear_bit(mISDN_STACK_ABORT, &st->status);
|
|
|
|
skb_queue_purge(&st->msgq);
|
|
|
|
st->thread = NULL;
|
|
|
|
if (st->notify != NULL) {
|
|
|
|
complete(st->notify);
|
|
|
|
st->notify = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
l1_receive(struct mISDNchannel *ch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
if (!ch->st)
|
|
|
|
return -ENODEV;
|
|
|
|
__net_timestamp(skb);
|
|
|
|
_queue_message(ch->st, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
set_channel_address(struct mISDNchannel *ch, u_int sapi, u_int tei)
|
|
|
|
{
|
|
|
|
ch->addr = sapi | (tei << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
__add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
|
|
|
|
{
|
|
|
|
list_add_tail(&ch->list, &st->layer2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
|
|
|
|
{
|
|
|
|
mutex_lock(&st->lmutex);
|
|
|
|
__add_layer2(ch, st);
|
|
|
|
mutex_unlock(&st->lmutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
st_own_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
|
|
|
|
{
|
2009-11-04 23:27:09 +07:00
|
|
|
if (!ch->st || !ch->st->layer1)
|
2008-07-27 06:54:58 +07:00
|
|
|
return -EINVAL;
|
|
|
|
return ch->st->layer1->ctrl(ch->st->layer1, cmd, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
create_stack(struct mISDNdevice *dev)
|
|
|
|
{
|
|
|
|
struct mISDNstack *newst;
|
|
|
|
int err;
|
|
|
|
DECLARE_COMPLETION_ONSTACK(done);
|
|
|
|
|
|
|
|
newst = kzalloc(sizeof(struct mISDNstack), GFP_KERNEL);
|
|
|
|
if (!newst) {
|
|
|
|
printk(KERN_ERR "kmalloc mISDN_stack failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
newst->dev = dev;
|
|
|
|
INIT_LIST_HEAD(&newst->layer2);
|
|
|
|
INIT_HLIST_HEAD(&newst->l1sock.head);
|
|
|
|
rwlock_init(&newst->l1sock.lock);
|
|
|
|
init_waitqueue_head(&newst->workq);
|
|
|
|
skb_queue_head_init(&newst->msgq);
|
|
|
|
mutex_init(&newst->lmutex);
|
|
|
|
dev->D.st = newst;
|
|
|
|
err = create_teimanager(dev);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "kmalloc teimanager failed\n");
|
|
|
|
kfree(newst);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
dev->teimgr->peer = &newst->own;
|
|
|
|
dev->teimgr->recv = mISDN_queue_message;
|
|
|
|
dev->teimgr->st = newst;
|
|
|
|
newst->layer1 = &dev->D;
|
|
|
|
dev->D.recv = l1_receive;
|
|
|
|
dev->D.peer = &newst->own;
|
|
|
|
newst->own.st = newst;
|
|
|
|
newst->own.ctrl = st_own_ctrl;
|
|
|
|
newst->own.send = mISDN_queue_message;
|
|
|
|
newst->own.recv = mISDN_queue_message;
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
2008-08-16 05:04:33 +07:00
|
|
|
printk(KERN_DEBUG "%s: st(%s)\n", __func__,
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&newst->dev->dev));
|
2008-07-27 06:54:58 +07:00
|
|
|
newst->notify = &done;
|
|
|
|
newst->thread = kthread_run(mISDNStackd, (void *)newst, "mISDN_%s",
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&newst->dev->dev));
|
2008-07-27 06:54:58 +07:00
|
|
|
if (IS_ERR(newst->thread)) {
|
|
|
|
err = PTR_ERR(newst->thread);
|
|
|
|
printk(KERN_ERR
|
2012-02-20 10:52:38 +07:00
|
|
|
"mISDN:cannot create kernel thread for %s (%d)\n",
|
|
|
|
dev_name(&newst->dev->dev), err);
|
2008-07-27 06:54:58 +07:00
|
|
|
delete_teimanager(dev->teimgr);
|
|
|
|
kfree(newst);
|
|
|
|
} else
|
|
|
|
wait_for_completion(&done);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
connect_layer1(struct mISDNdevice *dev, struct mISDNchannel *ch,
|
2012-02-20 10:52:38 +07:00
|
|
|
u_int protocol, struct sockaddr_mISDN *adr)
|
2008-07-27 06:54:58 +07:00
|
|
|
{
|
|
|
|
struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
|
|
|
|
struct channel_req rq;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, dev_name(&dev->dev), protocol, adr->dev,
|
|
|
|
adr->channel, adr->sapi, adr->tei);
|
2008-07-27 06:54:58 +07:00
|
|
|
switch (protocol) {
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
ch->recv = mISDN_queue_message;
|
|
|
|
ch->peer = &dev->D.st->own;
|
|
|
|
ch->st = dev->D.st;
|
|
|
|
rq.protocol = protocol;
|
2008-09-03 20:17:45 +07:00
|
|
|
rq.adr.channel = adr->channel;
|
2008-07-27 06:54:58 +07:00
|
|
|
err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
|
2008-09-14 19:42:18 +07:00
|
|
|
printk(KERN_DEBUG "%s: ret %d (dev %d)\n", __func__, err,
|
2012-02-20 10:52:38 +07:00
|
|
|
dev->id);
|
2008-07-27 06:54:58 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
write_lock_bh(&dev->D.st->l1sock.lock);
|
|
|
|
sk_add_node(&msk->sk, &dev->D.st->l1sock.head);
|
|
|
|
write_unlock_bh(&dev->D.st->l1sock.lock);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
connect_Bstack(struct mISDNdevice *dev, struct mISDNchannel *ch,
|
2012-02-20 10:52:38 +07:00
|
|
|
u_int protocol, struct sockaddr_mISDN *adr)
|
2008-07-27 06:54:58 +07:00
|
|
|
{
|
|
|
|
struct channel_req rq, rq2;
|
|
|
|
int pmask, err;
|
|
|
|
struct Bprotocol *bp;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, dev_name(&dev->dev), protocol,
|
|
|
|
adr->dev, adr->channel, adr->sapi,
|
|
|
|
adr->tei);
|
2008-07-27 06:54:58 +07:00
|
|
|
ch->st = dev->D.st;
|
|
|
|
pmask = 1 << (protocol & ISDN_P_B_MASK);
|
|
|
|
if (pmask & dev->Bprotocols) {
|
|
|
|
rq.protocol = protocol;
|
|
|
|
rq.adr = *adr;
|
|
|
|
err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
ch->recv = rq.ch->send;
|
|
|
|
ch->peer = rq.ch;
|
|
|
|
rq.ch->recv = ch->send;
|
|
|
|
rq.ch->peer = ch;
|
|
|
|
rq.ch->st = dev->D.st;
|
|
|
|
} else {
|
|
|
|
bp = get_Bprotocol4mask(pmask);
|
|
|
|
if (!bp)
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
rq2.protocol = protocol;
|
|
|
|
rq2.adr = *adr;
|
|
|
|
rq2.ch = ch;
|
|
|
|
err = bp->create(&rq2);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
ch->recv = rq2.ch->send;
|
|
|
|
ch->peer = rq2.ch;
|
|
|
|
rq2.ch->st = dev->D.st;
|
|
|
|
rq.protocol = rq2.protocol;
|
|
|
|
rq.adr = *adr;
|
|
|
|
err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
|
|
|
|
if (err) {
|
|
|
|
rq2.ch->ctrl(rq2.ch, CLOSE_CHANNEL, NULL);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
rq2.ch->recv = rq.ch->send;
|
|
|
|
rq2.ch->peer = rq.ch;
|
|
|
|
rq.ch->recv = rq2.ch->send;
|
|
|
|
rq.ch->peer = rq2.ch;
|
|
|
|
rq.ch->st = dev->D.st;
|
|
|
|
}
|
|
|
|
ch->protocol = protocol;
|
|
|
|
ch->nr = rq.ch->nr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
create_l2entity(struct mISDNdevice *dev, struct mISDNchannel *ch,
|
2012-02-20 10:52:38 +07:00
|
|
|
u_int protocol, struct sockaddr_mISDN *adr)
|
2008-07-27 06:54:58 +07:00
|
|
|
{
|
|
|
|
struct channel_req rq;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__, dev_name(&dev->dev), protocol,
|
|
|
|
adr->dev, adr->channel, adr->sapi,
|
|
|
|
adr->tei);
|
2008-07-27 06:54:58 +07:00
|
|
|
rq.protocol = ISDN_P_TE_S0;
|
|
|
|
if (dev->Dprotocols & (1 << ISDN_P_TE_E1))
|
|
|
|
rq.protocol = ISDN_P_TE_E1;
|
|
|
|
switch (protocol) {
|
|
|
|
case ISDN_P_LAPD_NT:
|
|
|
|
rq.protocol = ISDN_P_NT_S0;
|
|
|
|
if (dev->Dprotocols & (1 << ISDN_P_NT_E1))
|
|
|
|
rq.protocol = ISDN_P_NT_E1;
|
2018-07-04 04:17:31 +07:00
|
|
|
/* fall through */
|
2008-07-27 06:54:58 +07:00
|
|
|
case ISDN_P_LAPD_TE:
|
|
|
|
ch->recv = mISDN_queue_message;
|
|
|
|
ch->peer = &dev->D.st->own;
|
|
|
|
ch->st = dev->D.st;
|
|
|
|
rq.adr.channel = 0;
|
|
|
|
err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
|
|
|
|
printk(KERN_DEBUG "%s: ret 1 %d\n", __func__, err);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
rq.protocol = protocol;
|
|
|
|
rq.adr = *adr;
|
|
|
|
rq.ch = ch;
|
|
|
|
err = dev->teimgr->ctrl(dev->teimgr, OPEN_CHANNEL, &rq);
|
|
|
|
printk(KERN_DEBUG "%s: ret 2 %d\n", __func__, err);
|
|
|
|
if (!err) {
|
|
|
|
if ((protocol == ISDN_P_LAPD_NT) && !rq.ch)
|
|
|
|
break;
|
|
|
|
add_layer2(rq.ch, dev->D.st);
|
|
|
|
rq.ch->recv = mISDN_queue_message;
|
|
|
|
rq.ch->peer = &dev->D.st->own;
|
|
|
|
rq.ch->ctrl(rq.ch, OPEN_CHANNEL, NULL); /* can't fail */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EPROTONOSUPPORT;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delete_channel(struct mISDNchannel *ch)
|
|
|
|
{
|
|
|
|
struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
|
|
|
|
struct mISDNchannel *pch;
|
|
|
|
|
|
|
|
if (!ch->st) {
|
|
|
|
printk(KERN_WARNING "%s: no stack\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s: st(%s) protocol(%x)\n", __func__,
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&ch->st->dev->dev), ch->protocol);
|
2008-07-27 06:54:58 +07:00
|
|
|
if (ch->protocol >= ISDN_P_B_START) {
|
|
|
|
if (ch->peer) {
|
|
|
|
ch->peer->ctrl(ch->peer, CLOSE_CHANNEL, NULL);
|
|
|
|
ch->peer = NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (ch->protocol) {
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
write_lock_bh(&ch->st->l1sock.lock);
|
|
|
|
sk_del_node_init(&msk->sk);
|
|
|
|
write_unlock_bh(&ch->st->l1sock.lock);
|
|
|
|
ch->st->dev->D.ctrl(&ch->st->dev->D, CLOSE_CHANNEL, NULL);
|
|
|
|
break;
|
|
|
|
case ISDN_P_LAPD_TE:
|
|
|
|
pch = get_channel4id(ch->st, ch->nr);
|
|
|
|
if (pch) {
|
|
|
|
mutex_lock(&ch->st->lmutex);
|
|
|
|
list_del(&pch->list);
|
|
|
|
mutex_unlock(&ch->st->lmutex);
|
|
|
|
pch->ctrl(pch, CLOSE_CHANNEL, NULL);
|
|
|
|
pch = ch->st->dev->teimgr;
|
|
|
|
pch->ctrl(pch, CLOSE_CHANNEL, NULL);
|
|
|
|
} else
|
|
|
|
printk(KERN_WARNING "%s: no l2 channel\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__);
|
2008-07-27 06:54:58 +07:00
|
|
|
break;
|
|
|
|
case ISDN_P_LAPD_NT:
|
|
|
|
pch = ch->st->dev->teimgr;
|
|
|
|
if (pch) {
|
|
|
|
pch->ctrl(pch, CLOSE_CHANNEL, NULL);
|
|
|
|
} else
|
|
|
|
printk(KERN_WARNING "%s: no l2 channel\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__);
|
2008-07-27 06:54:58 +07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delete_stack(struct mISDNdevice *dev)
|
|
|
|
{
|
|
|
|
struct mISDNstack *st = dev->D.st;
|
|
|
|
DECLARE_COMPLETION_ONSTACK(done);
|
|
|
|
|
|
|
|
if (*debug & DEBUG_CORE_FUNC)
|
|
|
|
printk(KERN_DEBUG "%s: st(%s)\n", __func__,
|
2012-02-20 10:52:38 +07:00
|
|
|
dev_name(&st->dev->dev));
|
2008-07-27 06:54:58 +07:00
|
|
|
if (dev->teimgr)
|
|
|
|
delete_teimanager(dev->teimgr);
|
|
|
|
if (st->thread) {
|
|
|
|
if (st->notify) {
|
|
|
|
printk(KERN_WARNING "%s: notifier in use\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__);
|
|
|
|
complete(st->notify);
|
2008-07-27 06:54:58 +07:00
|
|
|
}
|
|
|
|
st->notify = &done;
|
|
|
|
test_and_set_bit(mISDN_STACK_ABORT, &st->status);
|
|
|
|
test_and_set_bit(mISDN_STACK_WAKEUP, &st->status);
|
|
|
|
wake_up_interruptible(&st->workq);
|
|
|
|
wait_for_completion(&done);
|
|
|
|
}
|
|
|
|
if (!list_empty(&st->layer2))
|
|
|
|
printk(KERN_WARNING "%s: layer2 list not empty\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__);
|
2008-07-27 06:54:58 +07:00
|
|
|
if (!hlist_empty(&st->l1sock.head))
|
|
|
|
printk(KERN_WARNING "%s: layer1 list not empty\n",
|
2012-02-20 10:52:38 +07:00
|
|
|
__func__);
|
2008-07-27 06:54:58 +07:00
|
|
|
kfree(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mISDN_initstack(u_int *dp)
|
|
|
|
{
|
|
|
|
debug = dp;
|
|
|
|
}
|