blob: b0bacf377c18b4b39e0d3be22254a31270a563dc [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);
Alexey Dobriyan9a58a802010-01-14 03:10:54 -0800493 card->procent = proc_create_data(card->procfn, 0, NULL, card->proc_fops, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 ncards++;
Karsten Keil17f0cd22007-02-28 20:13:50 -0800496 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s attached\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 card->cnr, card->name);
498 return 0;
499}
500
501EXPORT_SYMBOL(attach_capi_ctr);
502
Tilman Schmidt554f2002009-04-23 02:24:21 +0000503/**
504 * detach_capi_ctr() - unregister CAPI controller
505 * @card: controller descriptor structure.
506 *
507 * Called by hardware driver to remove the registration of a controller
508 * with the CAPI subsystem.
509 * Return value: 0 on success, error code < 0 on error
510 */
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512int detach_capi_ctr(struct capi_ctr *card)
513{
514 if (card->cardstate != CARD_DETECTED)
Tilman Schmidt4e329972009-06-07 09:09:23 +0000515 capi_ctr_down(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 ncards--;
518
519 if (card->procent) {
520 remove_proc_entry(card->procfn, NULL);
521 card->procent = NULL;
522 }
523 capi_cards[card->cnr - 1] = NULL;
Karsten Keil17f0cd22007-02-28 20:13:50 -0800524 printk(KERN_NOTICE "kcapi: Controller [%03d]: %s unregistered\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 card->cnr, card->name);
526
527 return 0;
528}
529
530EXPORT_SYMBOL(detach_capi_ctr);
531
Tilman Schmidt554f2002009-04-23 02:24:21 +0000532/**
533 * register_capi_driver() - register CAPI driver
534 * @driver: driver descriptor structure.
535 *
536 * Called by hardware driver to register itself with the CAPI subsystem.
537 */
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539void register_capi_driver(struct capi_driver *driver)
540{
541 unsigned long flags;
542
543 write_lock_irqsave(&capi_drivers_list_lock, flags);
544 list_add_tail(&driver->list, &capi_drivers);
545 write_unlock_irqrestore(&capi_drivers_list_lock, flags);
546}
547
548EXPORT_SYMBOL(register_capi_driver);
549
Tilman Schmidt554f2002009-04-23 02:24:21 +0000550/**
551 * unregister_capi_driver() - unregister CAPI driver
552 * @driver: driver descriptor structure.
553 *
554 * Called by hardware driver to unregister itself from the CAPI subsystem.
555 */
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557void unregister_capi_driver(struct capi_driver *driver)
558{
559 unsigned long flags;
560
561 write_lock_irqsave(&capi_drivers_list_lock, flags);
562 list_del(&driver->list);
563 write_unlock_irqrestore(&capi_drivers_list_lock, flags);
564}
565
566EXPORT_SYMBOL(unregister_capi_driver);
567
568/* ------------------------------------------------------------- */
569/* -------- CAPI2.0 Interface ---------------------------------- */
570/* ------------------------------------------------------------- */
571
Tilman Schmidt554f2002009-04-23 02:24:21 +0000572/**
573 * capi20_isinstalled() - CAPI 2.0 operation CAPI_INSTALLED
574 *
575 * Return value: CAPI result code (CAPI_NOERROR if at least one ISDN controller
576 * is ready for use, CAPI_REGNOTINSTALLED otherwise)
577 */
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579u16 capi20_isinstalled(void)
580{
581 int i;
582 for (i = 0; i < CAPI_MAXCONTR; i++) {
583 if (capi_cards[i] && capi_cards[i]->cardstate == CARD_RUNNING)
584 return CAPI_NOERROR;
585 }
586 return CAPI_REGNOTINSTALLED;
587}
588
589EXPORT_SYMBOL(capi20_isinstalled);
590
Tilman Schmidt554f2002009-04-23 02:24:21 +0000591/**
592 * capi20_register() - CAPI 2.0 operation CAPI_REGISTER
593 * @ap: CAPI application descriptor structure.
594 *
595 * Register an application's presence with CAPI.
596 * A unique application ID is assigned and stored in @ap->applid.
597 * After this function returns successfully, the message receive
598 * callback function @ap->recv_message() may be called at any time
599 * until capi20_release() has been called for the same @ap.
600 * Return value: CAPI result code
601 */
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603u16 capi20_register(struct capi20_appl *ap)
604{
605 int i;
606 u16 applid;
607 unsigned long flags;
608
609 DBG("");
610
611 if (ap->rparam.datablklen < 128)
612 return CAPI_LOGBLKSIZETOSMALL;
613
614 write_lock_irqsave(&application_lock, flags);
615
616 for (applid = 1; applid <= CAPI_MAXAPPL; applid++) {
617 if (capi_applications[applid - 1] == NULL)
618 break;
619 }
620 if (applid > CAPI_MAXAPPL) {
621 write_unlock_irqrestore(&application_lock, flags);
622 return CAPI_TOOMANYAPPLS;
623 }
624
625 ap->applid = applid;
626 capi_applications[applid - 1] = ap;
627
628 ap->nrecvctlpkt = 0;
629 ap->nrecvdatapkt = 0;
630 ap->nsentctlpkt = 0;
631 ap->nsentdatapkt = 0;
632 ap->callback = NULL;
Matthias Kaehlcke67837f22007-07-17 04:04:16 -0700633 mutex_init(&ap->recv_mtx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 skb_queue_head_init(&ap->recv_queue);
David Howellsc4028952006-11-22 14:57:56 +0000635 INIT_WORK(&ap->recv_work, recv_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ap->release_in_progress = 0;
637
638 write_unlock_irqrestore(&application_lock, flags);
639
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800640 mutex_lock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 for (i = 0; i < CAPI_MAXCONTR; i++) {
642 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
643 continue;
644 register_appl(capi_cards[i], applid, &ap->rparam);
645 }
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800646 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 if (showcapimsgs & 1) {
649 printk(KERN_DEBUG "kcapi: appl %d up\n", applid);
650 }
651
652 return CAPI_NOERROR;
653}
654
655EXPORT_SYMBOL(capi20_register);
656
Tilman Schmidt554f2002009-04-23 02:24:21 +0000657/**
658 * capi20_release() - CAPI 2.0 operation CAPI_RELEASE
659 * @ap: CAPI application descriptor structure.
660 *
661 * Terminate an application's registration with CAPI.
662 * After this function returns successfully, the message receive
663 * callback function @ap->recv_message() will no longer be called.
664 * Return value: CAPI result code
665 */
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667u16 capi20_release(struct capi20_appl *ap)
668{
669 int i;
670 unsigned long flags;
671
672 DBG("applid %#x", ap->applid);
673
674 write_lock_irqsave(&application_lock, flags);
675 ap->release_in_progress = 1;
676 capi_applications[ap->applid - 1] = NULL;
677 write_unlock_irqrestore(&application_lock, flags);
678
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800679 mutex_lock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 for (i = 0; i < CAPI_MAXCONTR; i++) {
681 if (!capi_cards[i] || capi_cards[i]->cardstate != CARD_RUNNING)
682 continue;
683 release_appl(capi_cards[i], ap->applid);
684 }
Arjan van de Ven9cdf1822006-03-23 03:00:21 -0800685 mutex_unlock(&controller_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 flush_scheduled_work();
688 skb_queue_purge(&ap->recv_queue);
689
690 if (showcapimsgs & 1) {
691 printk(KERN_DEBUG "kcapi: appl %d down\n", ap->applid);
692 }
693
694 return CAPI_NOERROR;
695}
696
697EXPORT_SYMBOL(capi20_release);
698
Tilman Schmidt554f2002009-04-23 02:24:21 +0000699/**
700 * capi20_put_message() - CAPI 2.0 operation CAPI_PUT_MESSAGE
701 * @ap: CAPI application descriptor structure.
702 * @skb: CAPI message.
703 *
704 * Transfer a single message to CAPI.
705 * Return value: CAPI result code
706 */
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb)
709{
710 struct capi_ctr *card;
711 int showctl = 0;
712 u8 cmd, subcmd;
713
714 DBG("applid %#x", ap->applid);
715
716 if (ncards == 0)
717 return CAPI_REGNOTINSTALLED;
718 if ((ap->applid == 0) || ap->release_in_progress)
719 return CAPI_ILLAPPNR;
720 if (skb->len < 12
721 || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data))
722 || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data)))
723 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
724 card = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data));
725 if (!card || card->cardstate != CARD_RUNNING) {
726 card = get_capi_ctr_by_nr(1); // XXX why?
727 if (!card || card->cardstate != CARD_RUNNING)
728 return CAPI_REGNOTINSTALLED;
729 }
730 if (card->blocked)
731 return CAPI_SENDQUEUEFULL;
732
733 cmd = CAPIMSG_COMMAND(skb->data);
734 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
735
736 if (cmd == CAPI_DATA_B3 && subcmd== CAPI_REQ) {
737 card->nsentdatapkt++;
738 ap->nsentdatapkt++;
739 if (card->traceflag > 2) showctl |= 2;
740 } else {
741 card->nsentctlpkt++;
742 ap->nsentctlpkt++;
743 if (card->traceflag) showctl |= 2;
744 }
745 showctl |= (card->traceflag & 1);
746 if (showctl & 2) {
747 if (showctl & 1) {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800748 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 CAPIMSG_CONTROLLER(skb->data),
750 CAPIMSG_APPID(skb->data),
751 capi_cmd2str(cmd, subcmd),
752 CAPIMSG_LEN(skb->data));
753 } else {
Karsten Keil17f0cd22007-02-28 20:13:50 -0800754 _cdebbuf *cdb = capi_message2str(skb->data);
755 if (cdb) {
756 printk(KERN_DEBUG "kcapi: put [%03d] %s\n",
757 CAPIMSG_CONTROLLER(skb->data),
758 cdb->buf);
759 cdebbuf_free(cdb);
760 } else
761 printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u cannot trace\n",
762 CAPIMSG_CONTROLLER(skb->data),
763 CAPIMSG_APPID(skb->data),
764 capi_cmd2str(cmd, subcmd),
765 CAPIMSG_LEN(skb->data));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768 return card->send_message(card, skb);
769}
770
771EXPORT_SYMBOL(capi20_put_message);
772
Tilman Schmidt554f2002009-04-23 02:24:21 +0000773/**
774 * capi20_get_manufacturer() - CAPI 2.0 operation CAPI_GET_MANUFACTURER
775 * @contr: controller number.
776 * @buf: result buffer (64 bytes).
777 *
778 * Retrieve information about the manufacturer of the specified ISDN controller
779 * or (for @contr == 0) the driver itself.
780 * Return value: CAPI result code
781 */
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783u16 capi20_get_manufacturer(u32 contr, u8 *buf)
784{
785 struct capi_ctr *card;
786
787 if (contr == 0) {
788 strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN);
789 return CAPI_NOERROR;
790 }
791 card = get_capi_ctr_by_nr(contr);
792 if (!card || card->cardstate != CARD_RUNNING)
793 return CAPI_REGNOTINSTALLED;
794 strlcpy(buf, card->manu, CAPI_MANUFACTURER_LEN);
795 return CAPI_NOERROR;
796}
797
798EXPORT_SYMBOL(capi20_get_manufacturer);
799
Tilman Schmidt554f2002009-04-23 02:24:21 +0000800/**
801 * capi20_get_version() - CAPI 2.0 operation CAPI_GET_VERSION
802 * @contr: controller number.
803 * @verp: result structure.
804 *
805 * Retrieve version information for the specified ISDN controller
806 * or (for @contr == 0) the driver itself.
807 * Return value: CAPI result code
808 */
809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810u16 capi20_get_version(u32 contr, struct capi_version *verp)
811{
812 struct capi_ctr *card;
813
814 if (contr == 0) {
815 *verp = driver_version;
816 return CAPI_NOERROR;
817 }
818 card = get_capi_ctr_by_nr(contr);
819 if (!card || card->cardstate != CARD_RUNNING)
820 return CAPI_REGNOTINSTALLED;
821
822 memcpy((void *) verp, &card->version, sizeof(capi_version));
823 return CAPI_NOERROR;
824}
825
826EXPORT_SYMBOL(capi20_get_version);
827
Tilman Schmidt554f2002009-04-23 02:24:21 +0000828/**
829 * capi20_get_serial() - CAPI 2.0 operation CAPI_GET_SERIAL_NUMBER
830 * @contr: controller number.
831 * @serial: result buffer (8 bytes).
832 *
833 * Retrieve the serial number of the specified ISDN controller
834 * or (for @contr == 0) the driver itself.
835 * Return value: CAPI result code
836 */
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838u16 capi20_get_serial(u32 contr, u8 *serial)
839{
840 struct capi_ctr *card;
841
842 if (contr == 0) {
843 strlcpy(serial, driver_serial, CAPI_SERIAL_LEN);
844 return CAPI_NOERROR;
845 }
846 card = get_capi_ctr_by_nr(contr);
847 if (!card || card->cardstate != CARD_RUNNING)
848 return CAPI_REGNOTINSTALLED;
849
850 strlcpy((void *) serial, card->serial, CAPI_SERIAL_LEN);
851 return CAPI_NOERROR;
852}
853
854EXPORT_SYMBOL(capi20_get_serial);
855
Tilman Schmidt554f2002009-04-23 02:24:21 +0000856/**
857 * capi20_get_profile() - CAPI 2.0 operation CAPI_GET_PROFILE
858 * @contr: controller number.
859 * @profp: result structure.
860 *
861 * Retrieve capability information for the specified ISDN controller
862 * or (for @contr == 0) the number of installed controllers.
863 * Return value: CAPI result code
864 */
865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866u16 capi20_get_profile(u32 contr, struct capi_profile *profp)
867{
868 struct capi_ctr *card;
869
870 if (contr == 0) {
871 profp->ncontroller = ncards;
872 return CAPI_NOERROR;
873 }
874 card = get_capi_ctr_by_nr(contr);
875 if (!card || card->cardstate != CARD_RUNNING)
876 return CAPI_REGNOTINSTALLED;
877
878 memcpy((void *) profp, &card->profile,
879 sizeof(struct capi_profile));
880 return CAPI_NOERROR;
881}
882
883EXPORT_SYMBOL(capi20_get_profile);
884
Robert P. J. Day37772ac2008-04-28 02:14:42 -0700885#ifdef AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886static int old_capi_manufacturer(unsigned int cmd, void __user *data)
887{
888 avmb1_loadandconfigdef ldef;
889 avmb1_extcarddef cdef;
890 avmb1_resetdef rdef;
891 capicardparams cparams;
892 struct capi_ctr *card;
893 struct capi_driver *driver = NULL;
894 capiloaddata ldata;
895 struct list_head *l;
896 unsigned long flags;
897 int retval;
898
899 switch (cmd) {
900 case AVMB1_ADDCARD:
901 case AVMB1_ADDCARD_WITH_TYPE:
902 if (cmd == AVMB1_ADDCARD) {
903 if ((retval = copy_from_user(&cdef, data,
904 sizeof(avmb1_carddef))))
905 return retval;
906 cdef.cardtype = AVM_CARDTYPE_B1;
907 } else {
908 if ((retval = copy_from_user(&cdef, data,
909 sizeof(avmb1_extcarddef))))
910 return retval;
911 }
912 cparams.port = cdef.port;
913 cparams.irq = cdef.irq;
914 cparams.cardnr = cdef.cardnr;
915
916 read_lock_irqsave(&capi_drivers_list_lock, flags);
917 switch (cdef.cardtype) {
918 case AVM_CARDTYPE_B1:
919 list_for_each(l, &capi_drivers) {
920 driver = list_entry(l, struct capi_driver, list);
921 if (strcmp(driver->name, "b1isa") == 0)
922 break;
923 }
924 break;
925 case AVM_CARDTYPE_T1:
926 list_for_each(l, &capi_drivers) {
927 driver = list_entry(l, struct capi_driver, list);
928 if (strcmp(driver->name, "t1isa") == 0)
929 break;
930 }
931 break;
932 default:
933 driver = NULL;
934 break;
935 }
936 if (!driver) {
937 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
938 printk(KERN_ERR "kcapi: driver not loaded.\n");
939 return -EIO;
940 }
941 if (!driver->add_card) {
942 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
943 printk(KERN_ERR "kcapi: driver has no add card function.\n");
944 return -EIO;
945 }
946
947 retval = driver->add_card(driver, &cparams);
948 read_unlock_irqrestore(&capi_drivers_list_lock, flags);
949 return retval;
950
951 case AVMB1_LOAD:
952 case AVMB1_LOAD_AND_CONFIG:
953
954 if (cmd == AVMB1_LOAD) {
955 if (copy_from_user(&ldef, data,
956 sizeof(avmb1_loaddef)))
957 return -EFAULT;
958 ldef.t4config.len = 0;
959 ldef.t4config.data = NULL;
960 } else {
961 if (copy_from_user(&ldef, data,
962 sizeof(avmb1_loadandconfigdef)))
963 return -EFAULT;
964 }
965 card = get_capi_ctr_by_nr(ldef.contr);
Jesper Juhle8a285b2007-10-16 01:27:52 -0700966 if (!card)
967 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 card = capi_ctr_get(card);
969 if (!card)
970 return -ESRCH;
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700971 if (card->load_firmware == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 printk(KERN_DEBUG "kcapi: load: no load function\n");
Julia Lawall4d5392c2008-09-22 19:04:54 -0700973 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 return -ESRCH;
975 }
976
977 if (ldef.t4file.len <= 0) {
978 printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len);
Julia Lawall4d5392c2008-09-22 19:04:54 -0700979 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 return -EINVAL;
981 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -0700982 if (ldef.t4file.data == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n");
Julia Lawall4d5392c2008-09-22 19:04:54 -0700984 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 return -EINVAL;
986 }
987
988 ldata.firmware.user = 1;
989 ldata.firmware.data = ldef.t4file.data;
990 ldata.firmware.len = ldef.t4file.len;
991 ldata.configuration.user = 1;
992 ldata.configuration.data = ldef.t4config.data;
993 ldata.configuration.len = ldef.t4config.len;
994
995 if (card->cardstate != CARD_DETECTED) {
996 printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr);
Julia Lawall4d5392c2008-09-22 19:04:54 -0700997 capi_ctr_put(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return -EBUSY;
999 }
1000 card->cardstate = CARD_LOADING;
1001
1002 retval = card->load_firmware(card, &ldata);
1003
1004 if (retval) {
1005 card->cardstate = CARD_DETECTED;
1006 capi_ctr_put(card);
1007 return retval;
1008 }
1009
1010 while (card->cardstate != CARD_RUNNING) {
1011
1012 msleep_interruptible(100); /* 0.1 sec */
1013
1014 if (signal_pending(current)) {
1015 capi_ctr_put(card);
1016 return -EINTR;
1017 }
1018 }
1019 capi_ctr_put(card);
1020 return 0;
1021
1022 case AVMB1_RESETCARD:
1023 if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef)))
1024 return -EFAULT;
1025 card = get_capi_ctr_by_nr(rdef.contr);
1026 if (!card)
1027 return -ESRCH;
1028
1029 if (card->cardstate == CARD_DETECTED)
1030 return 0;
1031
1032 card->reset_ctr(card);
1033
1034 while (card->cardstate > CARD_DETECTED) {
1035
1036 msleep_interruptible(100); /* 0.1 sec */
1037
1038 if (signal_pending(current))
1039 return -EINTR;
1040 }
1041 return 0;
1042
1043 }
1044 return -EINVAL;
1045}
1046#endif
1047
Tilman Schmidt554f2002009-04-23 02:24:21 +00001048/**
1049 * capi20_manufacturer() - CAPI 2.0 operation CAPI_MANUFACTURER
1050 * @cmd: command.
1051 * @data: parameter.
1052 *
1053 * Perform manufacturer specific command.
1054 * Return value: CAPI result code
1055 */
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057int capi20_manufacturer(unsigned int cmd, void __user *data)
1058{
1059 struct capi_ctr *card;
1060
1061 switch (cmd) {
Robert P. J. Day37772ac2008-04-28 02:14:42 -07001062#ifdef AVMB1_COMPAT
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 case AVMB1_LOAD:
1064 case AVMB1_LOAD_AND_CONFIG:
1065 case AVMB1_RESETCARD:
1066 case AVMB1_GET_CARDINFO:
1067 case AVMB1_REMOVECARD:
1068 return old_capi_manufacturer(cmd, data);
1069#endif
1070 case KCAPI_CMD_TRACE:
1071 {
1072 kcapi_flagdef fdef;
1073
1074 if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef)))
1075 return -EFAULT;
1076
1077 card = get_capi_ctr_by_nr(fdef.contr);
1078 if (!card)
1079 return -ESRCH;
1080
1081 card->traceflag = fdef.flag;
Karsten Keil17f0cd22007-02-28 20:13:50 -08001082 printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 card->cnr, card->traceflag);
1084 return 0;
1085 }
1086 case KCAPI_CMD_ADDCARD:
1087 {
1088 struct list_head *l;
1089 struct capi_driver *driver = NULL;
1090 capicardparams cparams;
1091 kcapi_carddef cdef;
1092 int retval;
1093
1094 if ((retval = copy_from_user(&cdef, data, sizeof(cdef))))
1095 return retval;
1096
1097 cparams.port = cdef.port;
1098 cparams.irq = cdef.irq;
1099 cparams.membase = cdef.membase;
1100 cparams.cardnr = cdef.cardnr;
1101 cparams.cardtype = 0;
1102 cdef.driver[sizeof(cdef.driver)-1] = 0;
1103
1104 list_for_each(l, &capi_drivers) {
1105 driver = list_entry(l, struct capi_driver, list);
1106 if (strcmp(driver->name, cdef.driver) == 0)
1107 break;
1108 }
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001109 if (driver == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 printk(KERN_ERR "kcapi: driver \"%s\" not loaded.\n",
1111 cdef.driver);
1112 return -ESRCH;
1113 }
1114
1115 if (!driver->add_card) {
1116 printk(KERN_ERR "kcapi: driver \"%s\" has no add card function.\n", cdef.driver);
1117 return -EIO;
1118 }
1119
1120 return driver->add_card(driver, &cparams);
1121 }
1122
1123 default:
1124 printk(KERN_ERR "kcapi: manufacturer command %d unknown.\n",
1125 cmd);
1126 break;
1127
1128 }
1129 return -EINVAL;
1130}
1131
1132EXPORT_SYMBOL(capi20_manufacturer);
1133
1134/* temporary hack */
Tilman Schmidt554f2002009-04-23 02:24:21 +00001135
1136/**
1137 * capi20_set_callback() - set CAPI application notification callback function
1138 * @ap: CAPI application descriptor structure.
1139 * @callback: callback function (NULL to remove).
1140 *
1141 * If not NULL, the callback function will be called to notify the
1142 * application of the addition or removal of a controller.
1143 * The first argument (cmd) will tell whether the controller was added
1144 * (KCI_CONTRUP) or removed (KCI_CONTRDOWN).
1145 * The second argument (contr) will be the controller number.
1146 * For cmd==KCI_CONTRUP the third argument (data) will be a pointer to the
1147 * new controller's capability profile structure.
1148 */
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150void capi20_set_callback(struct capi20_appl *ap,
1151 void (*callback) (unsigned int cmd, __u32 contr, void *data))
1152{
1153 ap->callback = callback;
1154}
1155
1156EXPORT_SYMBOL(capi20_set_callback);
1157
1158/* ------------------------------------------------------------- */
1159/* -------- Init & Cleanup ------------------------------------- */
1160/* ------------------------------------------------------------- */
1161
1162/*
1163 * init / exit functions
1164 */
1165
1166static int __init kcapi_init(void)
1167{
1168 char *p;
1169 char rev[32];
Karsten Keil17f0cd22007-02-28 20:13:50 -08001170 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Karsten Keil17f0cd22007-02-28 20:13:50 -08001172 ret = cdebug_init();
1173 if (ret)
1174 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 kcapi_proc_init();
1176
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001177 if ((p = strchr(revision, ':')) != NULL && p[1]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 strlcpy(rev, p + 2, sizeof(rev));
Harvey Harrison2f9e9b62008-04-28 02:14:37 -07001179 if ((p = strchr(rev, '$')) != NULL && p > rev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 *(p-1) = 0;
1181 } else
1182 strcpy(rev, "1.0");
1183
1184 printk(KERN_NOTICE "CAPI Subsystem Rev %s\n", rev);
1185
1186 return 0;
1187}
1188
1189static void __exit kcapi_exit(void)
1190{
1191 kcapi_proc_exit();
1192
1193 /* make sure all notifiers are finished */
1194 flush_scheduled_work();
Karsten Keil17f0cd22007-02-28 20:13:50 -08001195 cdebug_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
1198module_init(kcapi_init);
1199module_exit(kcapi_exit);