0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/slab.h>
0010 #include <linux/mISDNif.h>
0011 #include <linux/kthread.h>
0012 #include <linux/sched.h>
0013 #include <linux/sched/cputime.h>
0014 #include <linux/signal.h>
0015
0016 #include "core.h"
0017
0018 static u_int *debug;
0019
0020 static inline void
0021 _queue_message(struct mISDNstack *st, struct sk_buff *skb)
0022 {
0023 struct mISDNhead *hh = mISDN_HEAD_P(skb);
0024
0025 if (*debug & DEBUG_QUEUE_FUNC)
0026 printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
0027 __func__, hh->prim, hh->id, skb);
0028 skb_queue_tail(&st->msgq, skb);
0029 if (likely(!test_bit(mISDN_STACK_STOPPED, &st->status))) {
0030 test_and_set_bit(mISDN_STACK_WORK, &st->status);
0031 wake_up_interruptible(&st->workq);
0032 }
0033 }
0034
0035 static int
0036 mISDN_queue_message(struct mISDNchannel *ch, struct sk_buff *skb)
0037 {
0038 _queue_message(ch->st, skb);
0039 return 0;
0040 }
0041
0042 static struct mISDNchannel *
0043 get_channel4id(struct mISDNstack *st, u_int id)
0044 {
0045 struct mISDNchannel *ch;
0046
0047 mutex_lock(&st->lmutex);
0048 list_for_each_entry(ch, &st->layer2, list) {
0049 if (id == ch->nr)
0050 goto unlock;
0051 }
0052 ch = NULL;
0053 unlock:
0054 mutex_unlock(&st->lmutex);
0055 return ch;
0056 }
0057
0058 static void
0059 send_socklist(struct mISDN_sock_list *sl, struct sk_buff *skb)
0060 {
0061 struct sock *sk;
0062 struct sk_buff *cskb = NULL;
0063
0064 read_lock(&sl->lock);
0065 sk_for_each(sk, &sl->head) {
0066 if (sk->sk_state != MISDN_BOUND)
0067 continue;
0068 if (!cskb)
0069 cskb = skb_copy(skb, GFP_ATOMIC);
0070 if (!cskb) {
0071 printk(KERN_WARNING "%s no skb\n", __func__);
0072 break;
0073 }
0074 if (!sock_queue_rcv_skb(sk, cskb))
0075 cskb = NULL;
0076 }
0077 read_unlock(&sl->lock);
0078 dev_kfree_skb(cskb);
0079 }
0080
0081 static void
0082 send_layer2(struct mISDNstack *st, struct sk_buff *skb)
0083 {
0084 struct sk_buff *cskb;
0085 struct mISDNhead *hh = mISDN_HEAD_P(skb);
0086 struct mISDNchannel *ch;
0087 int ret;
0088
0089 if (!st)
0090 return;
0091 mutex_lock(&st->lmutex);
0092 if ((hh->id & MISDN_ID_ADDR_MASK) == MISDN_ID_ANY) {
0093 list_for_each_entry(ch, &st->layer2, list) {
0094 if (list_is_last(&ch->list, &st->layer2)) {
0095 cskb = skb;
0096 skb = NULL;
0097 } else {
0098 cskb = skb_copy(skb, GFP_KERNEL);
0099 }
0100 if (cskb) {
0101 ret = ch->send(ch, cskb);
0102 if (ret) {
0103 if (*debug & DEBUG_SEND_ERR)
0104 printk(KERN_DEBUG
0105 "%s ch%d prim(%x) addr(%x)"
0106 " err %d\n",
0107 __func__, ch->nr,
0108 hh->prim, ch->addr, ret);
0109 dev_kfree_skb(cskb);
0110 }
0111 } else {
0112 printk(KERN_WARNING "%s ch%d addr %x no mem\n",
0113 __func__, ch->nr, ch->addr);
0114 goto out;
0115 }
0116 }
0117 } else {
0118 list_for_each_entry(ch, &st->layer2, list) {
0119 if ((hh->id & MISDN_ID_ADDR_MASK) == ch->addr) {
0120 ret = ch->send(ch, skb);
0121 if (!ret)
0122 skb = NULL;
0123 goto out;
0124 }
0125 }
0126 ret = st->dev->teimgr->ctrl(st->dev->teimgr, CHECK_DATA, skb);
0127 if (!ret)
0128 skb = NULL;
0129 else if (*debug & DEBUG_SEND_ERR)
0130 printk(KERN_DEBUG
0131 "%s mgr prim(%x) err %d\n",
0132 __func__, hh->prim, ret);
0133 }
0134 out:
0135 mutex_unlock(&st->lmutex);
0136 dev_kfree_skb(skb);
0137 }
0138
0139 static inline int
0140 send_msg_to_layer(struct mISDNstack *st, struct sk_buff *skb)
0141 {
0142 struct mISDNhead *hh = mISDN_HEAD_P(skb);
0143 struct mISDNchannel *ch;
0144 int lm;
0145
0146 lm = hh->prim & MISDN_LAYERMASK;
0147 if (*debug & DEBUG_QUEUE_FUNC)
0148 printk(KERN_DEBUG "%s prim(%x) id(%x) %p\n",
0149 __func__, hh->prim, hh->id, skb);
0150 if (lm == 0x1) {
0151 if (!hlist_empty(&st->l1sock.head)) {
0152 __net_timestamp(skb);
0153 send_socklist(&st->l1sock, skb);
0154 }
0155 return st->layer1->send(st->layer1, skb);
0156 } else if (lm == 0x2) {
0157 if (!hlist_empty(&st->l1sock.head))
0158 send_socklist(&st->l1sock, skb);
0159 send_layer2(st, skb);
0160 return 0;
0161 } else if (lm == 0x4) {
0162 ch = get_channel4id(st, hh->id);
0163 if (ch)
0164 return ch->send(ch, skb);
0165 else
0166 printk(KERN_WARNING
0167 "%s: dev(%s) prim(%x) id(%x) no channel\n",
0168 __func__, dev_name(&st->dev->dev), hh->prim,
0169 hh->id);
0170 } else if (lm == 0x8) {
0171 WARN_ON(lm == 0x8);
0172 ch = get_channel4id(st, hh->id);
0173 if (ch)
0174 return ch->send(ch, skb);
0175 else
0176 printk(KERN_WARNING
0177 "%s: dev(%s) prim(%x) id(%x) no channel\n",
0178 __func__, dev_name(&st->dev->dev), hh->prim,
0179 hh->id);
0180 } else {
0181
0182 printk(KERN_WARNING "%s: dev(%s) prim %x not delivered\n",
0183 __func__, dev_name(&st->dev->dev), hh->prim);
0184 }
0185 return -ESRCH;
0186 }
0187
0188 static void
0189 do_clear_stack(struct mISDNstack *st)
0190 {
0191 }
0192
0193 static int
0194 mISDNStackd(void *data)
0195 {
0196 struct mISDNstack *st = data;
0197 #ifdef MISDN_MSG_STATS
0198 u64 utime, stime;
0199 #endif
0200 int err = 0;
0201
0202 sigfillset(¤t->blocked);
0203 if (*debug & DEBUG_MSG_THREAD)
0204 printk(KERN_DEBUG "mISDNStackd %s started\n",
0205 dev_name(&st->dev->dev));
0206
0207 if (st->notify != NULL) {
0208 complete(st->notify);
0209 st->notify = NULL;
0210 }
0211
0212 for (;;) {
0213 struct sk_buff *skb;
0214
0215 if (unlikely(test_bit(mISDN_STACK_STOPPED, &st->status))) {
0216 test_and_clear_bit(mISDN_STACK_WORK, &st->status);
0217 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
0218 } else
0219 test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
0220 while (test_bit(mISDN_STACK_WORK, &st->status)) {
0221 skb = skb_dequeue(&st->msgq);
0222 if (!skb) {
0223 test_and_clear_bit(mISDN_STACK_WORK,
0224 &st->status);
0225
0226 skb = skb_dequeue(&st->msgq);
0227 if (!skb)
0228 continue;
0229 test_and_set_bit(mISDN_STACK_WORK,
0230 &st->status);
0231 }
0232 #ifdef MISDN_MSG_STATS
0233 st->msg_cnt++;
0234 #endif
0235 err = send_msg_to_layer(st, skb);
0236 if (unlikely(err)) {
0237 if (*debug & DEBUG_SEND_ERR)
0238 printk(KERN_DEBUG
0239 "%s: %s prim(%x) id(%x) "
0240 "send call(%d)\n",
0241 __func__, dev_name(&st->dev->dev),
0242 mISDN_HEAD_PRIM(skb),
0243 mISDN_HEAD_ID(skb), err);
0244 dev_kfree_skb(skb);
0245 continue;
0246 }
0247 if (unlikely(test_bit(mISDN_STACK_STOPPED,
0248 &st->status))) {
0249 test_and_clear_bit(mISDN_STACK_WORK,
0250 &st->status);
0251 test_and_clear_bit(mISDN_STACK_RUNNING,
0252 &st->status);
0253 break;
0254 }
0255 }
0256 if (test_bit(mISDN_STACK_CLEARING, &st->status)) {
0257 test_and_set_bit(mISDN_STACK_STOPPED, &st->status);
0258 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
0259 do_clear_stack(st);
0260 test_and_clear_bit(mISDN_STACK_CLEARING, &st->status);
0261 test_and_set_bit(mISDN_STACK_RESTART, &st->status);
0262 }
0263 if (test_and_clear_bit(mISDN_STACK_RESTART, &st->status)) {
0264 test_and_clear_bit(mISDN_STACK_STOPPED, &st->status);
0265 test_and_set_bit(mISDN_STACK_RUNNING, &st->status);
0266 if (!skb_queue_empty(&st->msgq))
0267 test_and_set_bit(mISDN_STACK_WORK,
0268 &st->status);
0269 }
0270 if (test_bit(mISDN_STACK_ABORT, &st->status))
0271 break;
0272 if (st->notify != NULL) {
0273 complete(st->notify);
0274 st->notify = NULL;
0275 }
0276 #ifdef MISDN_MSG_STATS
0277 st->sleep_cnt++;
0278 #endif
0279 test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
0280 wait_event_interruptible(st->workq, (st->status &
0281 mISDN_STACK_ACTION_MASK));
0282 if (*debug & DEBUG_MSG_THREAD)
0283 printk(KERN_DEBUG "%s: %s wake status %08lx\n",
0284 __func__, dev_name(&st->dev->dev), st->status);
0285 test_and_set_bit(mISDN_STACK_ACTIVE, &st->status);
0286
0287 test_and_clear_bit(mISDN_STACK_WAKEUP, &st->status);
0288
0289 if (test_bit(mISDN_STACK_STOPPED, &st->status)) {
0290 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
0291 #ifdef MISDN_MSG_STATS
0292 st->stopped_cnt++;
0293 #endif
0294 }
0295 }
0296 #ifdef MISDN_MSG_STATS
0297 printk(KERN_DEBUG "mISDNStackd daemon for %s proceed %d "
0298 "msg %d sleep %d stopped\n",
0299 dev_name(&st->dev->dev), st->msg_cnt, st->sleep_cnt,
0300 st->stopped_cnt);
0301 task_cputime(st->thread, &utime, &stime);
0302 printk(KERN_DEBUG
0303 "mISDNStackd daemon for %s utime(%llu) stime(%llu)\n",
0304 dev_name(&st->dev->dev), utime, stime);
0305 printk(KERN_DEBUG
0306 "mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n",
0307 dev_name(&st->dev->dev), st->thread->nvcsw, st->thread->nivcsw);
0308 printk(KERN_DEBUG "mISDNStackd daemon for %s killed now\n",
0309 dev_name(&st->dev->dev));
0310 #endif
0311 test_and_set_bit(mISDN_STACK_KILLED, &st->status);
0312 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status);
0313 test_and_clear_bit(mISDN_STACK_ACTIVE, &st->status);
0314 test_and_clear_bit(mISDN_STACK_ABORT, &st->status);
0315 skb_queue_purge(&st->msgq);
0316 st->thread = NULL;
0317 if (st->notify != NULL) {
0318 complete(st->notify);
0319 st->notify = NULL;
0320 }
0321 return 0;
0322 }
0323
0324 static int
0325 l1_receive(struct mISDNchannel *ch, struct sk_buff *skb)
0326 {
0327 if (!ch->st)
0328 return -ENODEV;
0329 __net_timestamp(skb);
0330 _queue_message(ch->st, skb);
0331 return 0;
0332 }
0333
0334 void
0335 set_channel_address(struct mISDNchannel *ch, u_int sapi, u_int tei)
0336 {
0337 ch->addr = sapi | (tei << 8);
0338 }
0339
0340 void
0341 __add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
0342 {
0343 list_add_tail(&ch->list, &st->layer2);
0344 }
0345
0346 void
0347 add_layer2(struct mISDNchannel *ch, struct mISDNstack *st)
0348 {
0349 mutex_lock(&st->lmutex);
0350 __add_layer2(ch, st);
0351 mutex_unlock(&st->lmutex);
0352 }
0353
0354 static int
0355 st_own_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
0356 {
0357 if (!ch->st || !ch->st->layer1)
0358 return -EINVAL;
0359 return ch->st->layer1->ctrl(ch->st->layer1, cmd, arg);
0360 }
0361
0362 int
0363 create_stack(struct mISDNdevice *dev)
0364 {
0365 struct mISDNstack *newst;
0366 int err;
0367 DECLARE_COMPLETION_ONSTACK(done);
0368
0369 newst = kzalloc(sizeof(struct mISDNstack), GFP_KERNEL);
0370 if (!newst) {
0371 printk(KERN_ERR "kmalloc mISDN_stack failed\n");
0372 return -ENOMEM;
0373 }
0374 newst->dev = dev;
0375 INIT_LIST_HEAD(&newst->layer2);
0376 INIT_HLIST_HEAD(&newst->l1sock.head);
0377 rwlock_init(&newst->l1sock.lock);
0378 init_waitqueue_head(&newst->workq);
0379 skb_queue_head_init(&newst->msgq);
0380 mutex_init(&newst->lmutex);
0381 dev->D.st = newst;
0382 err = create_teimanager(dev);
0383 if (err) {
0384 printk(KERN_ERR "kmalloc teimanager failed\n");
0385 kfree(newst);
0386 return err;
0387 }
0388 dev->teimgr->peer = &newst->own;
0389 dev->teimgr->recv = mISDN_queue_message;
0390 dev->teimgr->st = newst;
0391 newst->layer1 = &dev->D;
0392 dev->D.recv = l1_receive;
0393 dev->D.peer = &newst->own;
0394 newst->own.st = newst;
0395 newst->own.ctrl = st_own_ctrl;
0396 newst->own.send = mISDN_queue_message;
0397 newst->own.recv = mISDN_queue_message;
0398 if (*debug & DEBUG_CORE_FUNC)
0399 printk(KERN_DEBUG "%s: st(%s)\n", __func__,
0400 dev_name(&newst->dev->dev));
0401 newst->notify = &done;
0402 newst->thread = kthread_run(mISDNStackd, (void *)newst, "mISDN_%s",
0403 dev_name(&newst->dev->dev));
0404 if (IS_ERR(newst->thread)) {
0405 err = PTR_ERR(newst->thread);
0406 printk(KERN_ERR
0407 "mISDN:cannot create kernel thread for %s (%d)\n",
0408 dev_name(&newst->dev->dev), err);
0409 delete_teimanager(dev->teimgr);
0410 kfree(newst);
0411 } else
0412 wait_for_completion(&done);
0413 return err;
0414 }
0415
0416 int
0417 connect_layer1(struct mISDNdevice *dev, struct mISDNchannel *ch,
0418 u_int protocol, struct sockaddr_mISDN *adr)
0419 {
0420 struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
0421 struct channel_req rq;
0422 int err;
0423
0424
0425 if (*debug & DEBUG_CORE_FUNC)
0426 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
0427 __func__, dev_name(&dev->dev), protocol, adr->dev,
0428 adr->channel, adr->sapi, adr->tei);
0429 switch (protocol) {
0430 case ISDN_P_NT_S0:
0431 case ISDN_P_NT_E1:
0432 case ISDN_P_TE_S0:
0433 case ISDN_P_TE_E1:
0434 ch->recv = mISDN_queue_message;
0435 ch->peer = &dev->D.st->own;
0436 ch->st = dev->D.st;
0437 rq.protocol = protocol;
0438 rq.adr.channel = adr->channel;
0439 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
0440 printk(KERN_DEBUG "%s: ret %d (dev %d)\n", __func__, err,
0441 dev->id);
0442 if (err)
0443 return err;
0444 write_lock_bh(&dev->D.st->l1sock.lock);
0445 sk_add_node(&msk->sk, &dev->D.st->l1sock.head);
0446 write_unlock_bh(&dev->D.st->l1sock.lock);
0447 break;
0448 default:
0449 return -ENOPROTOOPT;
0450 }
0451 return 0;
0452 }
0453
0454 int
0455 connect_Bstack(struct mISDNdevice *dev, struct mISDNchannel *ch,
0456 u_int protocol, struct sockaddr_mISDN *adr)
0457 {
0458 struct channel_req rq, rq2;
0459 int pmask, err;
0460 struct Bprotocol *bp;
0461
0462 if (*debug & DEBUG_CORE_FUNC)
0463 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
0464 __func__, dev_name(&dev->dev), protocol,
0465 adr->dev, adr->channel, adr->sapi,
0466 adr->tei);
0467 ch->st = dev->D.st;
0468 pmask = 1 << (protocol & ISDN_P_B_MASK);
0469 if (pmask & dev->Bprotocols) {
0470 rq.protocol = protocol;
0471 rq.adr = *adr;
0472 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
0473 if (err)
0474 return err;
0475 ch->recv = rq.ch->send;
0476 ch->peer = rq.ch;
0477 rq.ch->recv = ch->send;
0478 rq.ch->peer = ch;
0479 rq.ch->st = dev->D.st;
0480 } else {
0481 bp = get_Bprotocol4mask(pmask);
0482 if (!bp)
0483 return -ENOPROTOOPT;
0484 rq2.protocol = protocol;
0485 rq2.adr = *adr;
0486 rq2.ch = ch;
0487 err = bp->create(&rq2);
0488 if (err)
0489 return err;
0490 ch->recv = rq2.ch->send;
0491 ch->peer = rq2.ch;
0492 rq2.ch->st = dev->D.st;
0493 rq.protocol = rq2.protocol;
0494 rq.adr = *adr;
0495 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
0496 if (err) {
0497 rq2.ch->ctrl(rq2.ch, CLOSE_CHANNEL, NULL);
0498 return err;
0499 }
0500 rq2.ch->recv = rq.ch->send;
0501 rq2.ch->peer = rq.ch;
0502 rq.ch->recv = rq2.ch->send;
0503 rq.ch->peer = rq2.ch;
0504 rq.ch->st = dev->D.st;
0505 }
0506 ch->protocol = protocol;
0507 ch->nr = rq.ch->nr;
0508 return 0;
0509 }
0510
0511 int
0512 create_l2entity(struct mISDNdevice *dev, struct mISDNchannel *ch,
0513 u_int protocol, struct sockaddr_mISDN *adr)
0514 {
0515 struct channel_req rq;
0516 int err;
0517
0518 if (*debug & DEBUG_CORE_FUNC)
0519 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n",
0520 __func__, dev_name(&dev->dev), protocol,
0521 adr->dev, adr->channel, adr->sapi,
0522 adr->tei);
0523 rq.protocol = ISDN_P_TE_S0;
0524 if (dev->Dprotocols & (1 << ISDN_P_TE_E1))
0525 rq.protocol = ISDN_P_TE_E1;
0526 switch (protocol) {
0527 case ISDN_P_LAPD_NT:
0528 rq.protocol = ISDN_P_NT_S0;
0529 if (dev->Dprotocols & (1 << ISDN_P_NT_E1))
0530 rq.protocol = ISDN_P_NT_E1;
0531 fallthrough;
0532 case ISDN_P_LAPD_TE:
0533 ch->recv = mISDN_queue_message;
0534 ch->peer = &dev->D.st->own;
0535 ch->st = dev->D.st;
0536 rq.adr.channel = 0;
0537 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq);
0538 printk(KERN_DEBUG "%s: ret 1 %d\n", __func__, err);
0539 if (err)
0540 break;
0541 rq.protocol = protocol;
0542 rq.adr = *adr;
0543 rq.ch = ch;
0544 err = dev->teimgr->ctrl(dev->teimgr, OPEN_CHANNEL, &rq);
0545 printk(KERN_DEBUG "%s: ret 2 %d\n", __func__, err);
0546 if (!err) {
0547 if ((protocol == ISDN_P_LAPD_NT) && !rq.ch)
0548 break;
0549 add_layer2(rq.ch, dev->D.st);
0550 rq.ch->recv = mISDN_queue_message;
0551 rq.ch->peer = &dev->D.st->own;
0552 rq.ch->ctrl(rq.ch, OPEN_CHANNEL, NULL);
0553 }
0554 break;
0555 default:
0556 err = -EPROTONOSUPPORT;
0557 }
0558 return err;
0559 }
0560
0561 void
0562 delete_channel(struct mISDNchannel *ch)
0563 {
0564 struct mISDN_sock *msk = container_of(ch, struct mISDN_sock, ch);
0565 struct mISDNchannel *pch;
0566
0567 if (!ch->st) {
0568 printk(KERN_WARNING "%s: no stack\n", __func__);
0569 return;
0570 }
0571 if (*debug & DEBUG_CORE_FUNC)
0572 printk(KERN_DEBUG "%s: st(%s) protocol(%x)\n", __func__,
0573 dev_name(&ch->st->dev->dev), ch->protocol);
0574 if (ch->protocol >= ISDN_P_B_START) {
0575 if (ch->peer) {
0576 ch->peer->ctrl(ch->peer, CLOSE_CHANNEL, NULL);
0577 ch->peer = NULL;
0578 }
0579 return;
0580 }
0581 switch (ch->protocol) {
0582 case ISDN_P_NT_S0:
0583 case ISDN_P_TE_S0:
0584 case ISDN_P_NT_E1:
0585 case ISDN_P_TE_E1:
0586 write_lock_bh(&ch->st->l1sock.lock);
0587 sk_del_node_init(&msk->sk);
0588 write_unlock_bh(&ch->st->l1sock.lock);
0589 ch->st->dev->D.ctrl(&ch->st->dev->D, CLOSE_CHANNEL, NULL);
0590 break;
0591 case ISDN_P_LAPD_TE:
0592 pch = get_channel4id(ch->st, ch->nr);
0593 if (pch) {
0594 mutex_lock(&ch->st->lmutex);
0595 list_del(&pch->list);
0596 mutex_unlock(&ch->st->lmutex);
0597 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
0598 pch = ch->st->dev->teimgr;
0599 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
0600 } else
0601 printk(KERN_WARNING "%s: no l2 channel\n",
0602 __func__);
0603 break;
0604 case ISDN_P_LAPD_NT:
0605 pch = ch->st->dev->teimgr;
0606 if (pch) {
0607 pch->ctrl(pch, CLOSE_CHANNEL, NULL);
0608 } else
0609 printk(KERN_WARNING "%s: no l2 channel\n",
0610 __func__);
0611 break;
0612 default:
0613 break;
0614 }
0615 return;
0616 }
0617
0618 void
0619 delete_stack(struct mISDNdevice *dev)
0620 {
0621 struct mISDNstack *st = dev->D.st;
0622 DECLARE_COMPLETION_ONSTACK(done);
0623
0624 if (*debug & DEBUG_CORE_FUNC)
0625 printk(KERN_DEBUG "%s: st(%s)\n", __func__,
0626 dev_name(&st->dev->dev));
0627 if (dev->teimgr)
0628 delete_teimanager(dev->teimgr);
0629 if (st->thread) {
0630 if (st->notify) {
0631 printk(KERN_WARNING "%s: notifier in use\n",
0632 __func__);
0633 complete(st->notify);
0634 }
0635 st->notify = &done;
0636 test_and_set_bit(mISDN_STACK_ABORT, &st->status);
0637 test_and_set_bit(mISDN_STACK_WAKEUP, &st->status);
0638 wake_up_interruptible(&st->workq);
0639 wait_for_completion(&done);
0640 }
0641 if (!list_empty(&st->layer2))
0642 printk(KERN_WARNING "%s: layer2 list not empty\n",
0643 __func__);
0644 if (!hlist_empty(&st->l1sock.head))
0645 printk(KERN_WARNING "%s: layer1 list not empty\n",
0646 __func__);
0647 kfree(st);
0648 }
0649
0650 void
0651 mISDN_initstack(u_int *dp)
0652 {
0653 debug = dp;
0654 }