blob: dc506ab99cac03c1d9ca42a8053a5a0d5ff1cf2b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: kcapi.c,v 1.1.2.8 2004/03/26 19:57:20 armin Exp $
2 *
3 * Kernel CAPI 2.0 Module
4 *
5 * Copyright 1999 by Carsten Paeth <calle@calle.de>
6 * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 */
12
Robert P. J. Day37772ac2008-04-28 02:14:42 -070013#define AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include "kcapi.h"
16#include <linux/module.h>
17#include <linux/mm.h>
18#include <linux/interrupt.h>
19#include <linux/ioport.h>
20#include <linux/proc_fs.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040021#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/seq_file.h>
23#include <linux/skbuff.h>
24#include <linux/workqueue.h>
25#include <linux/capi.h>
26#include <linux/kernelcapi.h>
27#include <linux/init.h>
28#include <linux/moduleparam.h>
29#include <linux/delay.h>
30#include <asm/uaccess.h>
31#include <linux/isdn/capicmd.h>
32#include <linux/isdn/capiutil.h>
Robert P. J. Day37772ac2008-04-28 02:14:42 -070033#ifdef AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/b1lli.h>
35#endif
Arjan van de Ven9cdf1822006-03-23 03:00:21 -080036#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38static char *revision = "$Revision: 1.1.2.8 $";
39
40/* ------------------------------------------------------------- */
41
42static int showcapimsgs = 0;
43
44MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer");
45MODULE_AUTHOR("Carsten Paeth");
46MODULE_LICENSE("GPL");
47module_param(showcapimsgs, uint, 0);
48
49/* ------------------------------------------------------------- */
50
51struct capi_notifier {
52 struct work_struct work;
53 unsigned int cmd;
54 u32 controller;
55 u16 applid;
56 u32 ncci;
57};
58
59/* ------------------------------------------------------------- */
60
61static struct capi_version driver_version = {2, 0, 1, 1<<4};
62static char driver_serial[CAPI_SERIAL_LEN] = "0004711";
63static char capi_manufakturer[64] = "AVM Berlin";
64
65#define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f)
66
67LIST_HEAD(capi_drivers);
68DEFINE_RWLOCK(capi_drivers_list_lock);
69
70static DEFINE_RWLOCK(application_lock);
Arjan van de Ven9cdf1822006-03-23 03:00:21 -080071static DEFINE_MUTEX(controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73struct capi20_appl *capi_applications[CAPI_MAXAPPL];
74struct capi_ctr *capi_cards[CAPI_MAXCONTR];
75
76static int ncards;
77
78/* -------- controller ref counting -------------------------------------- */
79
80static inline struct capi_ctr *
81capi_ctr_get(struct capi_ctr *card)
82{
83 if (!try_module_get(card->owner))
84 return NULL;
85 return card;
86}
87
88static inline void
89capi_ctr_put(struct capi_ctr *card)
90{
91 module_put(card->owner);
92}
93
94/* ------------------------------------------------------------- */
95
96static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
97{
98 if (contr - 1 >= CAPI_MAXCONTR)
99 return NULL;
100
101 return capi_cards[contr - 1];
102}
103
104static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
105{
106 if (applid - 1 >= CAPI_MAXAPPL)
107 return NULL;
108
109 return capi_applications[applid - 1];
110}
111
112/* -------- util functions ------------------------------------ */
113
114static inline int capi_cmd_valid(u8 cmd)
115{
116 switch (cmd) {
117 case CAPI_ALERT:
118 case CAPI_CONNECT:
119 case CAPI_CONNECT_ACTIVE:
120 case CAPI_CONNECT_B3_ACTIVE:
121 case CAPI_CONNECT_B3:
122 case CAPI_CONNECT_B3_T90_ACTIVE:
123 case CAPI_DATA_B3:
124 case CAPI_DISCONNECT_B3:
125 case CAPI_DISCONNECT:
126 case CAPI_FACILITY:
127 case CAPI_INFO:
128 case CAPI_LISTEN:
129 case CAPI_MANUFACTURER:
130 case CAPI_RESET_B3:
131 case CAPI_SELECT_B_PROTOCOL:
132 return 1;
133 }
134 return 0;
135}
136
137static inline int capi_subcmd_valid(u8 subcmd)
138{
139 switch (subcmd) {
140 case CAPI_REQ:
141 case CAPI_CONF:
142 case CAPI_IND:
143 case CAPI_RESP:
144 return 1;
145 }
146 return 0;
147}
148
149/* ------------------------------------------------------------ */
150
151static void register_appl(struct capi_ctr *card, u16 applid, capi_register_params *rparam)
152{
153 card = capi_ctr_get(card);
154
155 if (card)
156 card->register_appl(card, applid, rparam);
157 else
Harvey Harrison156f1ed2008-04-28 02:14:40 -0700158 printk(KERN_WARNING "%s: cannot get card resources\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161
162static void release_appl(struct capi_ctr *card, u16 applid)
163{
164 DBG("applid %#x", applid);
165
166 card->release_appl(card, applid);
167 capi_ctr_put(card);
168}
169
170/* -------- KCI_CONTRUP --------------------------------------- */
171
172static void notify_up(u32 contr)
173{
174 struct capi_ctr *card = get_capi_ctr_by_nr(contr);
175 struct capi20_appl *ap;
176 u16 applid;
177
178 if (showcapimsgs & 1) {
179 printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr);
180 }
181 if (!card) {
Harvey Harrison156f1ed2008-04-28 02:14:40 -0700182 printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return;
184 }
185 for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
186 ap = get_capi_appl_by_nr(applid);
187 if (!ap || ap->release_in_progress) continue;
188 register_appl(card, applid, &ap->rparam);
189 if (ap->callback && !ap->release_in_progress)
190 ap->callback(KCI_CONTRUP, contr, &card->profile);
191 }
192}
193
194/* -------- KCI_CONTRDOWN ------------------------------------- */
195
196static void notify_down(u32 contr)
197{
198 struct capi20_appl *ap;
199 u16 applid;
200
201 if (showcapimsgs & 1) {
202 printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr);
203 }
204
205 for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
206 ap = get_capi_appl_by_nr(applid);
207 if (ap && ap->callback && !ap->release_in_progress)
208 ap->callback(KCI_CONTRDOWN, contr, NULL);
209 }
210}
211
David Howellsc4028952006-11-22 14:57:56 +0000212static void notify_handler(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
David Howellsc4028952006-11-22 14:57:56 +0000214 struct capi_notifier *np =
215 container_of(work, struct capi_notifier, work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 switch (np->cmd) {
218 case KCI_CONTRUP:
219 notify_up(np->controller);
220 break;
221 case KCI_CONTRDOWN:
222 notify_down(np->controller);
223 break;
224 }
225
226 kfree(np);
227}
228
229/*
230 * The notifier will result in adding/deleteing of devices. Devices can
231 * only removed in user process, not in bh.
232 */
233static int notify_push(unsigned int cmd, u32 controller, u16 applid, u32 ncci)
234{
235 struct capi_notifier *np = kmalloc(sizeof(*np), GFP_ATOMIC);
236
237 if (!np)
238 return -ENOMEM;
239
David Howellsc4028952006-11-22 14:57:56 +0000240 INIT_WORK(&np->work, notify_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 np->cmd = cmd;
242 np->controller = controller;
243 np->applid = applid;
244 np->ncci = ncci;
245
246 schedule_work(&np->work);
247 return 0;
248}
249
250
251/* -------- Receiver ------------------------------------------ */
252
David Howellsc4028952006-11-22 14:57:56 +0000253static void recv_handler(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 struct sk_buff *skb;
David Howellsc4028952006-11-22 14:57:56 +0000256 struct capi20_appl *ap =
257 container_of(work, struct capi20_appl, recv_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 if ((!ap) || (ap->release_in_progress))
260 return;
261
Matthias Kaehlcke67837f22007-07-17 04:04:16 -0700262 mutex_lock(&ap->recv_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 while ((skb = skb_dequeue(&ap->recv_queue))) {
264 if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_IND)
265 ap->nrecvdatapkt++;
266 else
267 ap->nrecvctlpkt++;
268
269 ap->recv_message(ap, skb);
270 }
Matthias Kaehlcke67837f22007-07-17 04:04:16 -0700271 mutex_unlock(&ap->recv_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Tilman Schmidt554f2002009-04-23 02:24:21 +0000274/**
275 * capi_ctr_handle_message() - handle incoming CAPI message
276 * @card: controller descriptor structure.
277 * @appl: application ID.
278 * @skb: message.
279 *
280 * Called by hardware driver to pass a CAPI message to the application.
281 */
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283void capi_ctr_handle_message(struct capi_ctr * card, u16 appl, struct sk_buff *skb)
284{
285 struct capi20_appl *ap;
286 int showctl = 0;
287 u8 cmd, subcmd;
288 unsigned long flags;
Karsten Keil17f0cd22007-02-28 20:13:50 -0800289 _cdebbuf *cdb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 if (card->cardstate != CARD_RUNNING) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800292 cdb = capi_message2str(skb->data);
293 if (cdb) {
294 printk(KERN_INFO "kcapi: controller [%03d] not active, got: %s",
295 card->cnr, cdb->buf);
296 cdebbuf_free(cdb);
297 } else
298 printk(KERN_INFO "kcapi: controller [%03d] not active, cannot trace\n",
299 card->cnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 goto error;
301 }
302
303 cmd = CAPIMSG_COMMAND(skb->data);
304 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
305 if (cmd == CAPI_DATA_B3 && subcmd == CAPI_IND) {
306 card->nrecvdatapkt++;
307 if (card->traceflag > 2) showctl |= 2;
308 } else {
309 card->nrecvctlpkt++;
310 if (card->traceflag) showctl |= 2;
311 }
312 showctl |= (card->traceflag & 1);
313 if (showctl & 2) {
314 if (showctl & 1) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800315 printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u\n",
316 card->cnr, CAPIMSG_APPID(skb->data),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 capi_cmd2str(cmd, subcmd),
318 CAPIMSG_LEN(skb->data));
319 } else {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800320 cdb = capi_message2str(skb->data);
321 if (cdb) {
322 printk(KERN_DEBUG "kcapi: got [%03d] %s\n",
323 card->cnr, cdb->buf);
324 cdebbuf_free(cdb);
325 } else
326 printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u, cannot trace\n",
327 card->cnr, CAPIMSG_APPID(skb->data),
328 capi_cmd2str(cmd, subcmd),
329 CAPIMSG_LEN(skb->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 }
331
332 }
333
334 read_lock_irqsave(&application_lock, flags);
335 ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data));
336 if ((!ap) || (ap->release_in_progress)) {
337 read_unlock_irqrestore(&application_lock, flags);
Karsten Keil17f0cd22007-02-28 20:13:50 -0800338 cdb = capi_message2str(skb->data);
339 if (cdb) {
340 printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n",
341 CAPIMSG_APPID(skb->data), cdb->buf);
342 cdebbuf_free(cdb);
343 } else
344 printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s) cannot trace\n",
345 CAPIMSG_APPID(skb->data),
346 capi_cmd2str(cmd, subcmd));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 goto error;
348 }
349 skb_queue_tail(&ap->recv_queue, skb);
350 schedule_work(&ap->recv_work);
351 read_unlock_irqrestore(&application_lock, flags);
352
353 return;
354
355error:
356 kfree_skb(skb);
357}
358
359EXPORT_SYMBOL(capi_ctr_handle_message);
360
Tilman Schmidt554f2002009-04-23 02:24:21 +0000361/**
362 * capi_ctr_ready() - signal CAPI controller ready
363 * @card: controller descriptor structure.
364 *
365 * Called by hardware driver to signal that the controller is up and running.
366 */
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368void capi_ctr_ready(struct capi_ctr * card)
369{
370 card->cardstate = CARD_RUNNING;
371
Karsten Keil17f0cd22007-02-28 20:13:50 -0800372 printk(KERN_NOTICE "kcapi: card [%03d] \"%s\" ready.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 card->cnr, card->name);
374
375 notify_push(KCI_CONTRUP, card->cnr, 0, 0);
376}
377
378EXPORT_SYMBOL(capi_ctr_ready);
379
Tilman Schmidt554f2002009-04-23 02:24:21 +0000380/**
Tilman Schmidt4e329972009-06-07 09:09:23 +0000381 * capi_ctr_down() - signal CAPI controller not ready
Tilman Schmidt554f2002009-04-23 02:24:21 +0000382 * @card: controller descriptor structure.
383 *
384 * Called by hardware driver to signal that the controller is down and
385 * unavailable for use.
386 */
387
Tilman Schmidt4e329972009-06-07 09:09:23 +0000388void capi_ctr_down(struct capi_ctr * card)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 u16 appl;
391
392 DBG("");
393
394 if (card->cardstate == CARD_DETECTED)
395 return;
396
397 card->cardstate = CARD_DETECTED;
398
399 memset(card->manu, 0, sizeof(card->manu));
400 memset(&card->version, 0, sizeof(card->version));
401 memset(&card->profile, 0, sizeof(card->profile));
402 memset(card->serial, 0, sizeof(card->serial));
403
404 for (appl = 1; appl <= CAPI_MAXAPPL; appl++) {
405 struct capi20_appl *ap = get_capi_appl_by_nr(appl);
406 if (!ap || ap->release_in_progress)
407 continue;
408
409 capi_ctr_put(card);
410 }
411
Karsten Keil17f0cd22007-02-28 20:13:50 -0800412 printk(KERN_NOTICE "kcapi: card [%03d] down.\n", card->cnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 notify_push(KCI_CONTRDOWN, card->cnr, 0, 0);
415}
416
Tilman Schmidt4e329972009-06-07 09:09:23 +0000417EXPORT_SYMBOL(capi_ctr_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Tilman Schmidt554f2002009-04-23 02:24:21 +0000419/**
420 * capi_ctr_suspend_output() - suspend controller
421 * @card: controller descriptor structure.
422 *
423 * Called by hardware driver to stop data flow.
424 */
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426void capi_ctr_suspend_output(struct capi_ctr *card)
427{
428 if (!card->blocked) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800429 printk(KERN_DEBUG "kcapi: card [%03d] suspend\n", card->cnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 card->blocked = 1;
431 }
432}
433
434EXPORT_SYMBOL(capi_ctr_suspend_output);
435
Tilman Schmidt554f2002009-04-23 02:24:21 +0000436/**
437 * capi_ctr_resume_output() - resume controller
438 * @card: controller descriptor structure.
439 *
440 * Called by hardware driver to resume data flow.
441 */
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443void capi_ctr_resume_output(struct capi_ctr *card)
444{
445 if (card->blocked) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800446 printk(KERN_DEBUG "kcapi: card [%03d] resume\n", card->cnr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 card->blocked = 0;
448 }
449}
450
451EXPORT_SYMBOL(capi_ctr_resume_output);
452
453/* ------------------------------------------------------------- */
454
Tilman Schmidt554f2002009-04-23 02:24:21 +0000455/**
456 * attach_capi_ctr() - register CAPI controller
457 * @card: controller descriptor structure.
458 *
459 * Called by hardware driver to register a controller with the CAPI subsystem.
460 * Return value: 0 on success, error code < 0 on error
461 */
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463int
464attach_capi_ctr(struct capi_ctr *card)
465{
466 int i;
467
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800468 mutex_lock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 for (i = 0; i < CAPI_MAXCONTR; i++) {
471 if (capi_cards[i] == NULL)
472 break;
473 }
474 if (i == CAPI_MAXCONTR) {
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800475 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 printk(KERN_ERR "kcapi: out of controller slots\n");
477 return -EBUSY;
478 }
479 capi_cards[i] = card;
480
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800481 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 card->nrecvctlpkt = 0;
484 card->nrecvdatapkt = 0;
485 card->nsentctlpkt = 0;
486 card->nsentdatapkt = 0;
487 card->cnr = i + 1;
488 card->cardstate = CARD_DETECTED;
489 card->blocked = 0;
490 card->traceflag = showcapimsgs;
491
492 sprintf(card->procfn, "capi/controllers/%d", card->cnr);
493 card->procent = create_proc_entry(card->procfn, 0, NULL);
494 if (card->procent) {
495 card->procent->read_proc =
496 (int (*)(char *,char **,off_t,int,int *,void *))
497 card->ctr_read_proc;
498 card->procent->data = card;
499 }
500
501 ncards++;
Karsten Keil17f0cd22007-02-28 20:13:50 -0800502 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s attached\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 card->cnr, card->name);
504 return 0;
505}
506
507EXPORT_SYMBOL(attach_capi_ctr);
508
Tilman Schmidt554f2002009-04-23 02:24:21 +0000509/**
510 * detach_capi_ctr() - unregister CAPI controller
511 * @card: controller descriptor structure.
512 *
513 * Called by hardware driver to remove the registration of a controller
514 * with the CAPI subsystem.
515 * Return value: 0 on success, error code < 0 on error
516 */
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518int detach_capi_ctr(struct capi_ctr *card)
519{
520 if (card->cardstate != CARD_DETECTED)
Tilman Schmidt4e329972009-06-07 09:09:23 +0000521 capi_ctr_down(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 ncards--;
524
525 if (card->procent) {
526 remove_proc_entry(card->procfn, NULL);
527 card->procent = NULL;
528 }
529 capi_cards[card->cnr - 1] = NULL;
Karsten Keil17f0cd22007-02-28 20:13:50 -0800530 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s unregistered\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 card->cnr, card->name);
532
533 return 0;
534}
535
536EXPORT_SYMBOL(detach_capi_ctr);
537
Tilman Schmidt554f2002009-04-23 02:24:21 +0000538/**
539 * register_capi_driver() - register CAPI driver
540 * @driver: driver descriptor structure.
541 *
542 * Called by hardware driver to register itself with the CAPI subsystem.
543 */
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545void register_capi_driver(struct capi_driver *driver)
546{
547 unsigned long flags;
548
549 write_lock_irqsave(&capi_drivers_list_lock, flags);
550 list_add_tail(&driver->list, &capi_drivers);
551 write_unlock_irqrestore(&capi_drivers_list_lock, flags);
552}
553
554EXPORT_SYMBOL(register_capi_driver);
555
Tilman Schmidt554f2002009-04-23 02:24:21 +0000556/**
557 * unregister_capi_driver() - unregister CAPI driver
558 * @driver: driver descriptor structure.
559 *
560 * Called by hardware driver to unregister itself from the CAPI subsystem.
561 */
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563void unregister_capi_driver(struct capi_driver *driver)
564{
565 unsigned long flags;
566
567 write_lock_irqsave(&capi_drivers_list_lock, flags);
568 list_del(&driver->list);
569 write_unlock_irqrestore(&capi_drivers_list_lock, flags);
570}
571
572EXPORT_SYMBOL(unregister_capi_driver);
573
574/* ------------------------------------------------------------- */
575/* -------- CAPI2.0 Interface ---------------------------------- */
576/* ------------------------------------------------------------- */
577
Tilman Schmidt554f2002009-04-23 02:24:21 +0000578/**
579 * capi20_isinstalled() - CAPI 2.0 operation CAPI_INSTALLED
580 *
581 * Return value: CAPI result code (CAPI_NOERROR if at least one ISDN controller
582 * is ready for use, CAPI_REGNOTINSTALLED otherwise)
583 */
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585u16 capi20_isinstalled(void)
586{
587 int i;
588 for (i = 0; i < CAPI_MAXCONTR; i++) {
589 if (capi_cards[i] && capi_cards[i]->cardstate == CARD_RUNNING)
590 return CAPI_NOERROR;
591 }
592 return CAPI_REGNOTINSTALLED;
593}
594
595EXPORT_SYMBOL(capi20_isinstalled);
596
Tilman Schmidt554f2002009-04-23 02:24:21 +0000597/**
598 * capi20_register() - CAPI 2.0 operation CAPI_REGISTER
599 * @ap: CAPI application descriptor structure.
600 *
601 * Register an application's presence with CAPI.
602 * A unique application ID is assigned and stored in @ap->applid.
603 * After this function returns successfully, the message receive
604 * callback function @ap->recv_message() may be called at any time
605 * until capi20_release() has been called for the same @ap.
606 * Return value: CAPI result code
607 */
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609u16 capi20_register(struct capi20_appl *ap)
610{
611 int i;
612 u16 applid;
613 unsigned long flags;
614
615 DBG("");
616
617 if (ap->rparam.datablklen < 128)
618 return CAPI_LOGBLKSIZETOSMALL;
619
620 write_lock_irqsave(&application_lock, flags);
621
622 for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
623 if (capi_applications[applid - 1] == NULL)
624 break;
625 }
626 if (applid > CAPI_MAXAPPL) {
627 write_unlock_irqrestore(&application_lock, flags);
628 return CAPI_TOOMANYAPPLS;
629 }
630
631 ap->applid = applid;
632 capi_applications[applid - 1] = ap;
633
634 ap->nrecvctlpkt = 0;
635 ap->nrecvdatapkt = 0;
636 ap->nsentctlpkt = 0;
637 ap->nsentdatapkt = 0;
638 ap->callback = NULL;
Matthias Kaehlcke67837f22007-07-17 04:04:16 -0700639 mutex_init(&ap->recv_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 skb_queue_head_init(&ap->recv_queue);
David Howellsc4028952006-11-22 14:57:56 +0000641 INIT_WORK(&ap->recv_work, recv_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ap->release_in_progress = 0;
643
644 write_unlock_irqrestore(&application_lock, flags);
645
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800646 mutex_lock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 for (i = 0; i < CAPI_MAXCONTR; i++) {
648 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
649 continue;
650 register_appl(capi_cards[i], applid, &ap->rparam);
651 }
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800652 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 if (showcapimsgs & 1) {
655 printk(KERN_DEBUG "kcapi: appl %d up\n", applid);
656 }
657
658 return CAPI_NOERROR;
659}
660
661EXPORT_SYMBOL(capi20_register);
662
Tilman Schmidt554f2002009-04-23 02:24:21 +0000663/**
664 * capi20_release() - CAPI 2.0 operation CAPI_RELEASE
665 * @ap: CAPI application descriptor structure.
666 *
667 * Terminate an application's registration with CAPI.
668 * After this function returns successfully, the message receive
669 * callback function @ap->recv_message() will no longer be called.
670 * Return value: CAPI result code
671 */
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673u16 capi20_release(struct capi20_appl *ap)
674{
675 int i;
676 unsigned long flags;
677
678 DBG("applid %#x", ap->applid);
679
680 write_lock_irqsave(&application_lock, flags);
681 ap->release_in_progress = 1;
682 capi_applications[ap->applid - 1] = NULL;
683 write_unlock_irqrestore(&application_lock, flags);
684
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800685 mutex_lock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 for (i = 0; i < CAPI_MAXCONTR; i++) {
687 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
688 continue;
689 release_appl(capi_cards[i], ap->applid);
690 }
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800691 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 flush_scheduled_work();
694 skb_queue_purge(&ap->recv_queue);
695
696 if (showcapimsgs & 1) {
697 printk(KERN_DEBUG "kcapi: appl %d down\n", ap->applid);
698 }
699
700 return CAPI_NOERROR;
701}
702
703EXPORT_SYMBOL(capi20_release);
704
Tilman Schmidt554f2002009-04-23 02:24:21 +0000705/**
706 * capi20_put_message() - CAPI 2.0 operation CAPI_PUT_MESSAGE
707 * @ap: CAPI application descriptor structure.
708 * @skb: CAPI message.
709 *
710 * Transfer a single message to CAPI.
711 * Return value: CAPI result code
712 */
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb)
715{
716 struct capi_ctr *card;
717 int showctl = 0;
718 u8 cmd, subcmd;
719
720 DBG("applid %#x", ap->applid);
721
722 if (ncards == 0)
723 return CAPI_REGNOTINSTALLED;
724 if ((ap->applid == 0) || ap->release_in_progress)
725 return CAPI_ILLAPPNR;
726 if (skb->len < 12
727 || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data))
728 || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data)))
729 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
730 card = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data));
731 if (!card || card->cardstate != CARD_RUNNING) {
732 card = get_capi_ctr_by_nr(1); // XXX why?
733 if (!card || card->cardstate != CARD_RUNNING)
734 return CAPI_REGNOTINSTALLED;
735 }
736 if (card->blocked)
737 return CAPI_SENDQUEUEFULL;
738
739 cmd = CAPIMSG_COMMAND(skb->data);
740 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
741
742 if (cmd == CAPI_DATA_B3 && subcmd== CAPI_REQ) {
743 card->nsentdatapkt++;
744 ap->nsentdatapkt++;
745 if (card->traceflag > 2) showctl |= 2;
746 } else {
747 card->nsentctlpkt++;
748 ap->nsentctlpkt++;
749 if (card->traceflag) showctl |= 2;
750 }
751 showctl |= (card->traceflag & 1);
752 if (showctl & 2) {
753 if (showctl & 1) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800754 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 CAPIMSG_CONTROLLER(skb->data),
756 CAPIMSG_APPID(skb->data),
757 capi_cmd2str(cmd, subcmd),
758 CAPIMSG_LEN(skb->data));
759 } else {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800760 _cdebbuf *cdb = capi_message2str(skb->data);
761 if (cdb) {
762 printk(KERN_DEBUG "kcapi: put [%03d] %s\n",
763 CAPIMSG_CONTROLLER(skb->data),
764 cdb->buf);
765 cdebbuf_free(cdb);
766 } else
767 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u cannot trace\n",
768 CAPIMSG_CONTROLLER(skb->data),
769 CAPIMSG_APPID(skb->data),
770 capi_cmd2str(cmd, subcmd),
771 CAPIMSG_LEN(skb->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 }
774 return card->send_message(card, skb);
775}
776
777EXPORT_SYMBOL(capi20_put_message);
778
Tilman Schmidt554f2002009-04-23 02:24:21 +0000779/**
780 * capi20_get_manufacturer() - CAPI 2.0 operation CAPI_GET_MANUFACTURER
781 * @contr: controller number.
782 * @buf: result buffer (64 bytes).
783 *
784 * Retrieve information about the manufacturer of the specified ISDN controller
785 * or (for @contr == 0) the driver itself.
786 * Return value: CAPI result code
787 */
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789u16 capi20_get_manufacturer(u32 contr, u8 *buf)
790{
791 struct capi_ctr *card;
792
793 if (contr == 0) {
794 strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN);
795 return CAPI_NOERROR;
796 }
797 card = get_capi_ctr_by_nr(contr);
798 if (!card || card->cardstate != CARD_RUNNING)
799 return CAPI_REGNOTINSTALLED;
800 strlcpy(buf, card->manu, CAPI_MANUFACTURER_LEN);
801 return CAPI_NOERROR;
802}
803
804EXPORT_SYMBOL(capi20_get_manufacturer);
805
Tilman Schmidt554f2002009-04-23 02:24:21 +0000806/**
807 * capi20_get_version() - CAPI 2.0 operation CAPI_GET_VERSION
808 * @contr: controller number.
809 * @verp: result structure.
810 *
811 * Retrieve version information for the specified ISDN controller
812 * or (for @contr == 0) the driver itself.
813 * Return value: CAPI result code
814 */
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816u16 capi20_get_version(u32 contr, struct capi_version *verp)
817{
818 struct capi_ctr *card;
819
820 if (contr == 0) {
821 *verp = driver_version;
822 return CAPI_NOERROR;
823 }
824 card = get_capi_ctr_by_nr(contr);
825 if (!card || card->cardstate != CARD_RUNNING)
826 return CAPI_REGNOTINSTALLED;
827
828 memcpy((void *) verp, &card->version, sizeof(capi_version));
829 return CAPI_NOERROR;
830}
831
832EXPORT_SYMBOL(capi20_get_version);
833
Tilman Schmidt554f2002009-04-23 02:24:21 +0000834/**
835 * capi20_get_serial() - CAPI 2.0 operation CAPI_GET_SERIAL_NUMBER
836 * @contr: controller number.
837 * @serial: result buffer (8 bytes).
838 *
839 * Retrieve the serial number of the specified ISDN controller
840 * or (for @contr == 0) the driver itself.
841 * Return value: CAPI result code
842 */
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844u16 capi20_get_serial(u32 contr, u8 *serial)
845{
846 struct capi_ctr *card;
847
848 if (contr == 0) {
849 strlcpy(serial, driver_serial, CAPI_SERIAL_LEN);
850 return CAPI_NOERROR;
851 }
852 card = get_capi_ctr_by_nr(contr);
853 if (!card || card->cardstate != CARD_RUNNING)
854 return CAPI_REGNOTINSTALLED;
855
856 strlcpy((void *) serial, card->serial, CAPI_SERIAL_LEN);
857 return CAPI_NOERROR;
858}
859
860EXPORT_SYMBOL(capi20_get_serial);
861
Tilman Schmidt554f2002009-04-23 02:24:21 +0000862/**
863 * capi20_get_profile() - CAPI 2.0 operation CAPI_GET_PROFILE
864 * @contr: controller number.
865 * @profp: result structure.
866 *
867 * Retrieve capability information for the specified ISDN controller
868 * or (for @contr == 0) the number of installed controllers.
869 * Return value: CAPI result code
870 */
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872u16 capi20_get_profile(u32 contr, struct capi_profile *profp)
873{
874 struct capi_ctr *card;
875
876 if (contr == 0) {
877 profp->ncontroller = ncards;
878 return CAPI_NOERROR;
879 }
880 card = get_capi_ctr_by_nr(contr);
881 if (!card || card->cardstate != CARD_RUNNING)
882 return CAPI_REGNOTINSTALLED;
883
884 memcpy((void *) profp, &card->profile,
885 sizeof(struct capi_profile));
886 return CAPI_NOERROR;
887}
888
889EXPORT_SYMBOL(capi20_get_profile);
890
Robert P. J. Day37772ac2008-04-28 02:14:42 -0700891#ifdef AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892static int old_capi_manufacturer(unsigned int cmd, void __user *data)
893{
894 avmb1_loadandconfigdef ldef;
895 avmb1_extcarddef cdef;
896 avmb1_resetdef rdef;
897 capicardparams cparams;
898 struct capi_ctr *card;
899 struct capi_driver *driver = NULL;
900 capiloaddata ldata;
901 struct list_head *l;
902 unsigned long flags;
903 int retval;
904
905 switch (cmd) {
906 case AVMB1_ADDCARD:
907 case AVMB1_ADDCARD_WITH_TYPE:
908 if (cmd == AVMB1_ADDCARD) {
909 if ((retval = copy_from_user(&cdef, data,
910 sizeof(avmb1_carddef))))
911 return retval;
912 cdef.cardtype = AVM_CARDTYPE_B1;
913 } else {
914 if ((retval = copy_from_user(&cdef, data,
915 sizeof(avmb1_extcarddef))))
916 return retval;
917 }
918 cparams.port = cdef.port;
919 cparams.irq = cdef.irq;
920 cparams.cardnr = cdef.cardnr;
921
922 read_lock_irqsave(&capi_drivers_list_lock, flags);
923 switch (cdef.cardtype) {
924 case AVM_CARDTYPE_B1:
925 list_for_each(l, &capi_drivers) {
926 driver = list_entry(l, struct capi_driver, list);
927 if (strcmp(driver->name, "b1isa") == 0)
928 break;
929 }
930 break;
931 case AVM_CARDTYPE_T1:
932 list_for_each(l, &capi_drivers) {
933 driver = list_entry(l, struct capi_driver, list);
934 if (strcmp(driver->name, "t1isa") == 0)
935 break;
936 }
937 break;
938 default:
939 driver = NULL;
940 break;
941 }
942 if (!driver) {
943 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
944 printk(KERN_ERR "kcapi: driver not loaded.\n");
945 return -EIO;
946 }
947 if (!driver->add_card) {
948 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
949 printk(KERN_ERR "kcapi: driver has no add card function.\n");
950 return -EIO;
951 }
952
953 retval = driver->add_card(driver, &cparams);
954 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
955 return retval;
956
957 case AVMB1_LOAD:
958 case AVMB1_LOAD_AND_CONFIG:
959
960 if (cmd == AVMB1_LOAD) {
961 if (copy_from_user(&ldef, data,
962 sizeof(avmb1_loaddef)))
963 return -EFAULT;
964 ldef.t4config.len = 0;
965 ldef.t4config.data = NULL;
966 } else {
967 if (copy_from_user(&ldef, data,
968 sizeof(avmb1_loadandconfigdef)))
969 return -EFAULT;
970 }
971 card = get_capi_ctr_by_nr(ldef.contr);
Jesper Juhle8a285b2007-10-16 01:27:52 -0700972 if (!card)
973 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 card = capi_ctr_get(card);
975 if (!card)
976 return -ESRCH;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700977 if (card->load_firmware == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 printk(KERN_DEBUG "kcapi: load: no load function\n");
Julia Lawall4d5392c2008-09-22 19:04:54 -0700979 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 return -ESRCH;
981 }
982
983 if (ldef.t4file.len <= 0) {
984 printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len);
Julia Lawall4d5392c2008-09-22 19:04:54 -0700985 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 return -EINVAL;
987 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700988 if (ldef.t4file.data == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n");
Julia Lawall4d5392c2008-09-22 19:04:54 -0700990 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 return -EINVAL;
992 }
993
994 ldata.firmware.user = 1;
995 ldata.firmware.data = ldef.t4file.data;
996 ldata.firmware.len = ldef.t4file.len;
997 ldata.configuration.user = 1;
998 ldata.configuration.data = ldef.t4config.data;
999 ldata.configuration.len = ldef.t4config.len;
1000
1001 if (card->cardstate != CARD_DETECTED) {
1002 printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr);
Julia Lawall4d5392c2008-09-22 19:04:54 -07001003 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 return -EBUSY;
1005 }
1006 card->cardstate = CARD_LOADING;
1007
1008 retval = card->load_firmware(card, &ldata);
1009
1010 if (retval) {
1011 card->cardstate = CARD_DETECTED;
1012 capi_ctr_put(card);
1013 return retval;
1014 }
1015
1016 while (card->cardstate != CARD_RUNNING) {
1017
1018 msleep_interruptible(100); /* 0.1 sec */
1019
1020 if (signal_pending(current)) {
1021 capi_ctr_put(card);
1022 return -EINTR;
1023 }
1024 }
1025 capi_ctr_put(card);
1026 return 0;
1027
1028 case AVMB1_RESETCARD:
1029 if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef)))
1030 return -EFAULT;
1031 card = get_capi_ctr_by_nr(rdef.contr);
1032 if (!card)
1033 return -ESRCH;
1034
1035 if (card->cardstate == CARD_DETECTED)
1036 return 0;
1037
1038 card->reset_ctr(card);
1039
1040 while (card->cardstate > CARD_DETECTED) {
1041
1042 msleep_interruptible(100); /* 0.1 sec */
1043
1044 if (signal_pending(current))
1045 return -EINTR;
1046 }
1047 return 0;
1048
1049 }
1050 return -EINVAL;
1051}
1052#endif
1053
Tilman Schmidt554f2002009-04-23 02:24:21 +00001054/**
1055 * capi20_manufacturer() - CAPI 2.0 operation CAPI_MANUFACTURER
1056 * @cmd: command.
1057 * @data: parameter.
1058 *
1059 * Perform manufacturer specific command.
1060 * Return value: CAPI result code
1061 */
1062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063int capi20_manufacturer(unsigned int cmd, void __user *data)
1064{
1065 struct capi_ctr *card;
1066
1067 switch (cmd) {
Robert P. J. Day37772ac2008-04-28 02:14:42 -07001068#ifdef AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 case AVMB1_LOAD:
1070 case AVMB1_LOAD_AND_CONFIG:
1071 case AVMB1_RESETCARD:
1072 case AVMB1_GET_CARDINFO:
1073 case AVMB1_REMOVECARD:
1074 return old_capi_manufacturer(cmd, data);
1075#endif
1076 case KCAPI_CMD_TRACE:
1077 {
1078 kcapi_flagdef fdef;
1079
1080 if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef)))
1081 return -EFAULT;
1082
1083 card = get_capi_ctr_by_nr(fdef.contr);
1084 if (!card)
1085 return -ESRCH;
1086
1087 card->traceflag = fdef.flag;
Karsten Keil17f0cd22007-02-28 20:13:50 -08001088 printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 card->cnr, card->traceflag);
1090 return 0;
1091 }
1092 case KCAPI_CMD_ADDCARD:
1093 {
1094 struct list_head *l;
1095 struct capi_driver *driver = NULL;
1096 capicardparams cparams;
1097 kcapi_carddef cdef;
1098 int retval;
1099
1100 if ((retval = copy_from_user(&cdef, data, sizeof(cdef))))
1101 return retval;
1102
1103 cparams.port = cdef.port;
1104 cparams.irq = cdef.irq;
1105 cparams.membase = cdef.membase;
1106 cparams.cardnr = cdef.cardnr;
1107 cparams.cardtype = 0;
1108 cdef.driver[sizeof(cdef.driver)-1] = 0;
1109
1110 list_for_each(l, &capi_drivers) {
1111 driver = list_entry(l, struct capi_driver, list);
1112 if (strcmp(driver->name, cdef.driver) == 0)
1113 break;
1114 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001115 if (driver == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 printk(KERN_ERR "kcapi: driver \"%s\" not loaded.\n",
1117 cdef.driver);
1118 return -ESRCH;
1119 }
1120
1121 if (!driver->add_card) {
1122 printk(KERN_ERR "kcapi: driver \"%s\" has no add card function.\n", cdef.driver);
1123 return -EIO;
1124 }
1125
1126 return driver->add_card(driver, &cparams);
1127 }
1128
1129 default:
1130 printk(KERN_ERR "kcapi: manufacturer command %d unknown.\n",
1131 cmd);
1132 break;
1133
1134 }
1135 return -EINVAL;
1136}
1137
1138EXPORT_SYMBOL(capi20_manufacturer);
1139
1140/* temporary hack */
Tilman Schmidt554f2002009-04-23 02:24:21 +00001141
1142/**
1143 * capi20_set_callback() - set CAPI application notification callback function
1144 * @ap: CAPI application descriptor structure.
1145 * @callback: callback function (NULL to remove).
1146 *
1147 * If not NULL, the callback function will be called to notify the
1148 * application of the addition or removal of a controller.
1149 * The first argument (cmd) will tell whether the controller was added
1150 * (KCI_CONTRUP) or removed (KCI_CONTRDOWN).
1151 * The second argument (contr) will be the controller number.
1152 * For cmd==KCI_CONTRUP the third argument (data) will be a pointer to the
1153 * new controller's capability profile structure.
1154 */
1155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156void capi20_set_callback(struct capi20_appl *ap,
1157 void (*callback) (unsigned int cmd, __u32 contr, void *data))
1158{
1159 ap->callback = callback;
1160}
1161
1162EXPORT_SYMBOL(capi20_set_callback);
1163
1164/* ------------------------------------------------------------- */
1165/* -------- Init & Cleanup ------------------------------------- */
1166/* ------------------------------------------------------------- */
1167
1168/*
1169 * init / exit functions
1170 */
1171
1172static int __init kcapi_init(void)
1173{
1174 char *p;
1175 char rev[32];
Karsten Keil17f0cd22007-02-28 20:13:50 -08001176 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Karsten Keil17f0cd22007-02-28 20:13:50 -08001178 ret = cdebug_init();
1179 if (ret)
1180 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 kcapi_proc_init();
1182
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001183 if ((p = strchr(revision, ':')) != NULL && p[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 strlcpy(rev, p + 2, sizeof(rev));
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001185 if ((p = strchr(rev, '$')) != NULL && p > rev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 *(p-1) = 0;
1187 } else
1188 strcpy(rev, "1.0");
1189
1190 printk(KERN_NOTICE "CAPI Subsystem Rev %s\n", rev);
1191
1192 return 0;
1193}
1194
1195static void __exit kcapi_exit(void)
1196{
1197 kcapi_proc_exit();
1198
1199 /* make sure all notifiers are finished */
1200 flush_scheduled_work();
Karsten Keil17f0cd22007-02-28 20:13:50 -08001201 cdebug_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
1204module_init(kcapi_init);
1205module_exit(kcapi_exit);