2 * $Id: b1capi.c,v 1.14 1999/04/15 19:49:29 calle Exp $
4 * CAPI 2.0 Module for AVM B1-card.
6 * (c) Copyright 1997 by Carsten Paeth (calle@calle.in-berlin.de)
9 * Revision 1.14 1999/04/15 19:49:29 calle
10 * fix fuer die B1-PCI. Jetzt geht z.B. auch IRQ 17 ...
12 * Revision 1.13 1999/01/05 18:29:31 he
13 * merged remaining schedule_timeout() changes from 2.1.127
15 * Revision 1.12 1998/10/25 14:38:58 fritz
16 * Backported from MIPS (Cobalt).
18 * Revision 1.11 1998/03/29 16:05:58 calle
19 * changes from 2.0 tree merged.
21 * Revision 1.4.2.18 1998/03/20 20:34:37 calle
22 * port valid check now only for T1, because of the PCI and PCMCIA cards.
24 * Revision 1.4.2.17 1998/03/20 14:38:17 calle
25 * capidrv: prepared state machines for suspend/resume/hold
26 * capidrv: fix bug in state machine if B1/T1 is out of nccis
27 * b1capi: changed some errno returns.
28 * b1capi: detect if you try to add same T1 to different io address.
29 * b1capi: change number of nccis depending on number of channels.
32 * Revision 1.4.2.16 1998/03/20 09:01:08 calle
33 * Changes capi_register handling to get full support for 30 bchannels.
35 * Revision 1.4.2.15 1998/03/18 17:43:26 calle
36 * T1 with fastlink, bugfix for multicontroller support in capidrv.c
38 * Revision 1.4.2.14 1998/03/04 17:33:47 calle
41 * Revision 1.4.2.13 1998/02/27 15:40:41 calle
42 * T1 running with slow link. bugfix in capi_release.
44 * Revision 1.4.2.12 1998/02/24 17:58:25 calle
47 * Revision 1.10 1998/02/13 07:09:10 calle
48 * change for 2.1.86 (removing FREE_READ/FREE_WRITE from [dev]_kfree_skb()
50 * Revision 1.9 1998/01/31 11:14:39 calle
51 * merged changes to 2.0 tree, prepare 2.1.82 to work.
53 * Revision 1.8 1997/12/10 20:00:46 calle
54 * get changes from 2.0 version
56 * Revision 1.4.2.5 1997/12/07 19:59:54 calle
57 * more changes for M1/T1/B1 + config
59 * Revision 1.4.2.4 1997/11/26 16:57:20 calle
60 * more changes for B1/M1/T1.
62 * Revision 1.7 1997/10/19 14:45:40 calle
63 * fixed capi_get_version.
65 * Revision 1.6 1997/10/01 09:21:09 fritz
66 * Removed old compatibility stuff for 2.0.X kernels.
67 * From now on, this code is for 2.1.X ONLY!
68 * Old stuff is still in the separate branch.
70 * Revision 1.5 1997/07/12 08:22:26 calle
71 * Correct bug in CARD_NR macro, so now more than one card will work.
72 * Allow card reset, even if card is in running state.
75 * Revision 1.4 1997/05/27 15:17:45 fritz
76 * Added changes for recent 2.1.x kernels:
77 * changed return type of isdn_close
78 * queue_task_* -> queue_task
79 * clear/set_bit -> test_and_... where apropriate.
80 * changed type of hard_header_cache parameter.
82 * Revision 1.3 1997/05/18 09:24:09 calle
83 * added verbose disconnect reason reporting to avmb1.
84 * some fixes in capi20 interface.
85 * changed info messages for B1-PCI
87 * Revision 1.2 1997/03/05 21:20:41 fritz
88 * Removed include of config.h (mkdep stated this is unneded).
90 * Revision 1.1 1997/03/04 21:50:27 calle
91 * Frirst version in isdn4linux
93 * Revision 2.2 1997/02/12 09:31:39 calle
96 * Revision 1.1 1997/01/31 10:32:20 calle
102 #include <linux/module.h>
103 #include <linux/kernel.h>
104 #include <linux/mm.h>
105 #include <linux/interrupt.h>
106 #include <linux/ioport.h>
107 #include <asm/segment.h>
108 #include <linux/skbuff.h>
109 #include <linux/tqueue.h>
110 #include <linux/capi.h>
111 #include <linux/b1lli.h>
112 #include <linux/kernelcapi.h>
115 #include "capiutil.h"
117 static char *revision
= "$Revision: 1.14 $";
119 /* ------------------------------------------------------------- */
121 int showcapimsgs
= 0; /* used in lli.c */
124 MODULE_AUTHOR("Carsten Paeth <calle@calle.in-berlin.de>");
125 MODULE_PARM(showcapimsgs
, "0-5i");
126 MODULE_PARM(loaddebug
, "0-1i");
128 /* ------------------------------------------------------------- */
131 struct msgidqueue
*next
;
135 typedef struct avmb1_ncci
{
136 struct avmb1_ncci
*next
;
140 struct msgidqueue
*msgidqueue
;
141 struct msgidqueue
*msgidlast
;
142 struct msgidqueue
*msgidfree
;
143 struct msgidqueue msgidpool
[CAPI_MAXDATAWINDOW
];
146 typedef struct avmb1_appl
{
148 capi_register_params rparam
;
151 void (*signal
) (__u16 applid
, __u32 param
);
152 struct sk_buff_head recv_queue
;
153 struct avmb1_ncci
*nccilist
;
156 /* ------------------------------------------------------------- */
158 static struct capi_version driver_version
= {2, 0, 1, 1<<4};
159 static char driver_serial
[CAPI_SERIAL_LEN
] = "4711";
160 static char capi_manufakturer
[64] = "AVM Berlin";
162 #define APPL(a) (&applications[(a)-1])
163 #define VALID_APPLID(a) ((a) && (a) <= CAPI_MAXAPPL && APPL(a)->applid == a)
164 #define APPL_IS_FREE(a) (APPL(a)->applid == 0)
165 #define APPL_MARK_FREE(a) do{ APPL(a)->applid=0; MOD_DEC_USE_COUNT; }while(0);
166 #define APPL_MARK_USED(a) do{ APPL(a)->applid=(a); MOD_INC_USE_COUNT; }while(0);
168 #define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f)
170 #define VALID_CARD(c) ((c) > 0 && (c) <= CAPI_MAXCONTR)
171 #define CARD(c) (&cards[(c)-1])
172 #define CARDNR(cp) (((cp)-cards)+1)
174 static avmb1_appl applications
[CAPI_MAXAPPL
];
175 static avmb1_card cards
[CAPI_MAXCONTR
];
176 static int ncards
= 0;
177 static struct sk_buff_head recv_queue
;
178 static struct capi_interface_user
*capi_users
= 0;
179 static long notify_up_set
= 0;
180 static long notify_down_set
= 0;
182 static struct tq_struct tq_state_notify
;
183 static struct tq_struct tq_recv_notify
;
185 /* -------- util functions ------------------------------------ */
187 static char *cardtype2str(int cardtype
)
191 case AVM_CARDTYPE_B1
: return "B1-ISA";
192 case AVM_CARDTYPE_B1PCI
: return "B1-PCI";
193 case AVM_CARDTYPE_M1
: return "M1";
194 case AVM_CARDTYPE_M2
: return "M2";
195 case AVM_CARDTYPE_T1
: return "T1";
199 static inline int capi_cmd_valid(__u8 cmd
)
204 case CAPI_CONNECT_ACTIVE
:
205 case CAPI_CONNECT_B3_ACTIVE
:
206 case CAPI_CONNECT_B3
:
207 case CAPI_CONNECT_B3_T90_ACTIVE
:
209 case CAPI_DISCONNECT_B3
:
210 case CAPI_DISCONNECT
:
214 case CAPI_MANUFACTURER
:
216 case CAPI_SELECT_B_PROTOCOL
:
222 static inline int capi_subcmd_valid(__u8 subcmd
)
234 /* -------- NCCI Handling ------------------------------------- */
236 static inline void mq_init(avmb1_ncci
* np
)
241 memset(np
->msgidpool
, 0, sizeof(np
->msgidpool
));
242 np
->msgidfree
= &np
->msgidpool
[0];
243 for (i
= 1; i
< np
->winsize
; i
++) {
244 np
->msgidpool
[i
].next
= np
->msgidfree
;
245 np
->msgidfree
= &np
->msgidpool
[i
];
249 static inline int mq_enqueue(avmb1_ncci
* np
, __u16 msgid
)
251 struct msgidqueue
*mq
;
252 if ((mq
= np
->msgidfree
) == 0)
254 np
->msgidfree
= mq
->next
;
258 np
->msgidlast
->next
= mq
;
265 static inline int mq_dequeue(avmb1_ncci
* np
, __u16 msgid
)
267 struct msgidqueue
**pp
;
268 for (pp
= &np
->msgidqueue
; *pp
; pp
= &(*pp
)->next
) {
269 if ((*pp
)->msgid
== msgid
) {
270 struct msgidqueue
*mq
= *pp
;
272 if (mq
== np
->msgidlast
)
274 mq
->next
= np
->msgidfree
;
282 void avmb1_handle_new_ncci(avmb1_card
* card
,
283 __u16 appl
, __u32 ncci
, __u32 winsize
)
286 if (!VALID_APPLID(appl
)) {
287 printk(KERN_ERR
"avmb1_handle_new_ncci: illegal appl %d\n", appl
);
290 if ((np
= (avmb1_ncci
*) kmalloc(sizeof(avmb1_ncci
), GFP_ATOMIC
)) == 0) {
291 printk(KERN_ERR
"avmb1_handle_new_ncci: alloc failed ncci 0x%x\n", ncci
);
294 if (winsize
> CAPI_MAXDATAWINDOW
) {
295 printk(KERN_ERR
"avmb1_handle_new_ncci: winsize %d too big, set to %d\n",
296 winsize
, CAPI_MAXDATAWINDOW
);
297 winsize
= CAPI_MAXDATAWINDOW
;
301 np
->winsize
= winsize
;
303 np
->next
= APPL(appl
)->nccilist
;
304 APPL(appl
)->nccilist
= np
;
305 printk(KERN_INFO
"b1capi: appl %d ncci 0x%x up\n", appl
, ncci
);
309 void avmb1_handle_free_ncci(avmb1_card
* card
,
310 __u16 appl
, __u32 ncci
)
312 if (!VALID_APPLID(appl
)) {
313 printk(KERN_ERR
"avmb1_handle_free_ncci: illegal appl %d\n", appl
);
316 if (ncci
!= 0xffffffff) {
318 for (pp
= &APPL(appl
)->nccilist
; *pp
; pp
= &(*pp
)->next
) {
319 if ((*pp
)->ncci
== ncci
) {
320 avmb1_ncci
*np
= *pp
;
323 printk(KERN_INFO
"b1capi: appl %d ncci 0x%x down\n", appl
, ncci
);
327 printk(KERN_ERR
"avmb1_handle_free_ncci: ncci 0x%x not found\n", ncci
);
329 avmb1_ncci
**pp
, **nextpp
;
330 for (pp
= &APPL(appl
)->nccilist
; *pp
; pp
= nextpp
) {
331 if (NCCI2CTRL((*pp
)->ncci
) == card
->cnr
) {
332 avmb1_ncci
*np
= *pp
;
334 printk(KERN_INFO
"b1capi: appl %d ncci 0x%x down!\n", appl
, np
->ncci
);
338 nextpp
= &(*pp
)->next
;
341 APPL(appl
)->releasing
--;
342 if (APPL(appl
)->releasing
<= 0) {
343 APPL(appl
)->signal
= 0;
344 APPL_MARK_FREE(appl
);
345 printk(KERN_INFO
"b1capi: appl %d down\n", appl
);
350 static avmb1_ncci
*find_ncci(avmb1_appl
* app
, __u32 ncci
)
353 for (np
= app
->nccilist
; np
; np
= np
->next
) {
354 if (np
->ncci
== ncci
)
362 /* -------- Receiver ------------------------------------------ */
365 static void recv_handler(void *dummy
)
369 while ((skb
= skb_dequeue(&recv_queue
)) != 0) {
370 __u16 appl
= CAPIMSG_APPID(skb
->data
);
371 struct avmb1_ncci
*np
;
372 if (!VALID_APPLID(appl
)) {
373 printk(KERN_ERR
"b1capi: recv_handler: applid %d ? (%s)\n",
374 appl
, capi_message2str(skb
->data
));
378 if (APPL(appl
)->signal
== 0) {
379 printk(KERN_ERR
"b1capi: recv_handler: applid %d has no signal function\n",
384 if ( CAPIMSG_COMMAND(skb
->data
) == CAPI_DATA_B3
385 && CAPIMSG_SUBCOMMAND(skb
->data
) == CAPI_CONF
386 && (np
= find_ncci(APPL(appl
), CAPIMSG_NCCI(skb
->data
))) != 0
387 && mq_dequeue(np
, CAPIMSG_MSGID(skb
->data
)) == 0) {
388 printk(KERN_ERR
"b1capi: msgid %hu ncci 0x%x not on queue\n",
389 CAPIMSG_MSGID(skb
->data
), np
->ncci
);
391 skb_queue_tail(&APPL(appl
)->recv_queue
, skb
);
392 (APPL(appl
)->signal
) (APPL(appl
)->applid
, APPL(appl
)->param
);
397 void avmb1_handle_capimsg(avmb1_card
* card
, __u16 appl
, struct sk_buff
*skb
)
399 if (card
->cardstate
!= CARD_RUNNING
) {
400 printk(KERN_INFO
"b1capi: controller %d not active, got: %s",
401 card
->cnr
, capi_message2str(skb
->data
));
405 skb_queue_tail(&recv_queue
, skb
);
406 queue_task(&tq_recv_notify
, &tq_immediate
);
407 mark_bh(IMMEDIATE_BH
);
414 void avmb1_interrupt(int interrupt
, void *devptr
, struct pt_regs
*regs
)
418 card
= (avmb1_card
*) devptr
;
421 printk(KERN_WARNING
"avmb1_interrupt: wrong device\n");
424 if (card
->interrupt
) {
425 printk(KERN_ERR
"avmb1_interrupt: reentering interrupt hander\n");
431 B1_handle_interrupt(card
);
436 /* -------- Notifier ------------------------------------------ */
438 static void notify_up(__u16 contr
)
440 struct capi_interface_user
*p
;
442 printk(KERN_NOTICE
"b1capi: notify up contr %d\n", contr
);
443 for (p
= capi_users
; p
; p
= p
->next
) {
445 (*p
->callback
) (KCI_CONTRUP
, contr
,
447 CARD(contr
)->version
[VER_PROFILE
]);
451 static void notify_down(__u16 contr
)
453 struct capi_interface_user
*p
;
454 printk(KERN_NOTICE
"b1capi: notify down contr %d\n", contr
);
455 for (p
= capi_users
; p
; p
= p
->next
) {
457 (*p
->callback
) (KCI_CONTRDOWN
, contr
, 0);
461 static void notify_handler(void *dummy
)
465 for (contr
=1; VALID_CARD(contr
); contr
++)
466 if (test_and_clear_bit(contr
, ¬ify_up_set
))
468 for (contr
=1; VALID_CARD(contr
); contr
++)
469 if (test_and_clear_bit(contr
, ¬ify_down_set
))
473 /* -------- card ready callback ------------------------------- */
476 void avmb1_card_ready(avmb1_card
* card
)
478 struct capi_profile
*profp
=
479 (struct capi_profile
*)card
->version
[VER_PROFILE
];
480 char *dversion
= card
->version
[VER_DRIVER
];
482 char *cardname
, cname
[20];
484 int nbchan
= profp
->nbchannel
;
486 card
->cversion
.majorversion
= 2;
487 card
->cversion
.minorversion
= 0;
488 card
->cversion
.majormanuversion
= (((dversion
[0] - '0') & 0xf) << 4);
489 card
->cversion
.majormanuversion
|= ((dversion
[2] - '0') & 0xf);
490 card
->cversion
.minormanuversion
= (dversion
[3] - '0') << 4;
491 card
->cversion
.minormanuversion
|=
492 (dversion
[5] - '0') * 10 + ((dversion
[6] - '0') & 0xf);
493 card
->cardstate
= CARD_RUNNING
;
495 for (appl
= 1; appl
<= CAPI_MAXAPPL
; appl
++) {
496 if (VALID_APPLID(appl
) && !APPL(appl
)->releasing
) {
497 int nconn
, want
= APPL(appl
)->rparam
.level3cnt
;
499 if (want
> 0) nconn
= want
;
500 else nconn
= nbchan
* -want
;
501 if (nconn
== 0) nconn
= nbchan
;
503 B1_send_register(card
->port
, appl
,
504 1024 * (nconn
+1), nconn
,
505 APPL(appl
)->rparam
.datablkcnt
,
506 APPL(appl
)->rparam
.datablklen
);
510 set_bit(CARDNR(card
), ¬ify_up_set
);
511 queue_task(&tq_state_notify
, &tq_scheduler
);
513 flag
= ((__u8
*)(profp
->manu
))[1];
515 case 0: cardname
= cardtype2str(card
->cardtype
); break;
516 case 3: cardname
= "PCMCIA B"; break;
517 case 4: cardname
= "PCMCIA M1"; break;
518 case 5: cardname
= "PCMCIA M2"; break;
519 case 6: cardname
= "B1 V3.0"; break;
520 case 7: cardname
= "B1 PCI"; break;
521 default: cardname
= cname
; break;
522 sprintf(cname
, "AVM?%u", (unsigned int)flag
);
525 printk(KERN_NOTICE
"b1capi: card %d \"%s\" ready.\n",
526 CARDNR(card
), cardname
);
527 flag
= ((__u8
*)(profp
->manu
))[3];
529 printk(KERN_NOTICE
"b1capi: card %d Protocol:%s%s%s%s%s%s%s\n",
531 (flag
& 0x01) ? " DSS1" : "",
532 (flag
& 0x02) ? " CT1" : "",
533 (flag
& 0x04) ? " VN3" : "",
534 (flag
& 0x08) ? " NI1" : "",
535 (flag
& 0x10) ? " AUSTEL" : "",
536 (flag
& 0x20) ? " ESS" : "",
537 (flag
& 0x40) ? " 1TR6" : ""
539 flag
= ((__u8
*)(profp
->manu
))[5];
541 printk(KERN_NOTICE
"b1capi: card %d Linetype:%s%s%s%s\n",
543 (flag
& 0x01) ? " point to point" : "",
544 (flag
& 0x02) ? " point to multipoint" : "",
545 (flag
& 0x08) ? " leased line without D-channel" : "",
546 (flag
& 0x04) ? " leased line with D-channel" : ""
550 static void avmb1_card_down(avmb1_card
* card
, int notify
)
554 card
->cardstate
= CARD_DETECTED
;
556 for (appl
= 1; appl
<= CAPI_MAXAPPL
; appl
++) {
557 avmb1_ncci
**pp
, **nextpp
;
558 for (pp
= &APPL(appl
)->nccilist
; *pp
; pp
= nextpp
) {
559 if (NCCI2CTRL((*pp
)->ncci
) == card
->cnr
) {
560 avmb1_ncci
*np
= *pp
;
562 printk(KERN_INFO
"b1capi: appl %d ncci 0x%x forced down!\n", appl
, np
->ncci
);
566 nextpp
= &(*pp
)->next
;
570 set_bit(CARDNR(card
), ¬ify_down_set
);
571 queue_task(&tq_state_notify
, &tq_scheduler
);
572 printk(KERN_NOTICE
"b1capi: card %d down.\n", CARDNR(card
));
575 /* ------------------------------------------------------------- */
578 int avmb1_registercard(int port
, int irq
, int cardtype
, int allocio
)
580 struct avmb1_card
*card
;
584 for (i
=0; i
< CAPI_MAXCONTR
&& cards
[i
].cardstate
!= CARD_FREE
; i
++) ;
586 if (i
== CAPI_MAXCONTR
) {
587 printk(KERN_ERR
"b1capi: out of controller slots\n");
592 memset(card
, 0, sizeof(avmb1_card
));
593 sprintf(card
->name
, "avmb1-%d", CARDNR(card
));
596 request_region(port
, AVMB1_PORTLEN
, card
->name
);
598 if ((irqval
= request_irq(irq
, avmb1_interrupt
,
599 SA_SHIRQ
, card
->name
, card
)) != 0) {
600 printk(KERN_ERR
"b1capi: unable to get IRQ %d (irqval=%d).\n",
602 release_region(port
, AVMB1_PORTLEN
);
606 card
->cardstate
= CARD_DETECTED
;
608 card
->cnr
= CARDNR(card
);
611 card
->cardtype
= cardtype
;
615 int avmb1_addcard(int port
, int irq
, int cardtype
)
617 return avmb1_registercard(port
, irq
, cardtype
, 1);
620 int avmb1_detectcard(int port
, int irq
, int cardtype
)
624 if (!B1_valid_irq(irq
, cardtype
)) {
625 printk(KERN_WARNING
"b1capi: irq %d not valid for %s-card.\n",
626 irq
, cardtype2str(cardtype
));
629 if (!B1_valid_port(port
, cardtype
)) {
630 printk(KERN_WARNING
"b1capi: port 0x%x not valid for %s-card.\n",
631 port
, cardtype2str(cardtype
));
635 if ((rc
= B1_detect(port
, cardtype
)) != 0) {
636 printk(KERN_NOTICE
"b1capi: NO %s-card at 0x%x (%d)\n",
637 cardtype2str(cardtype
), port
, rc
);
643 case AVM_CARDTYPE_M1
:
644 case AVM_CARDTYPE_M2
:
645 case AVM_CARDTYPE_B1
:
646 case AVM_CARDTYPE_B1PCI
:
647 printk(KERN_NOTICE
"b1capi: AVM-%s-Controller detected at 0x%x\n", cardtype2str(cardtype
), port
);
649 case AVM_CARDTYPE_T1
:
656 int avmb1_probecard(int port
, int irq
, int cardtype
)
658 if (check_region(port
, AVMB1_PORTLEN
)) {
660 "b1capi: ports 0x%03x-0x%03x in use.\n",
661 port
, port
+ AVMB1_PORTLEN
);
664 return avmb1_detectcard(port
, irq
, cardtype
);
667 int avmb1_unregistercard(int cnr
, int freeio
)
670 if (!VALID_CARD(cnr
))
674 if (card
->cardstate
== CARD_FREE
)
676 if (card
->cardstate
== CARD_RUNNING
)
677 avmb1_card_down(card
, freeio
);
679 if (card
->cardstate
!= CARD_FREE
)
680 if (card
->cardtype
== AVM_CARDTYPE_T1
)
681 T1_reset(card
->port
);
683 free_irq(card
->irq
, card
);
685 release_region(card
->port
, AVMB1_PORTLEN
);
686 card
->cardstate
= CARD_FREE
;
690 int avmb1_resetcard(int cnr
)
694 if (!VALID_CARD(cnr
))
697 if (card
->cardstate
== CARD_FREE
)
700 if (card
->cardstate
== CARD_RUNNING
)
701 avmb1_card_down(card
, 0);
703 B1_reset(card
->port
);
704 B1_reset(card
->port
);
706 card
->cardstate
= CARD_DETECTED
;
711 /* ------------------------------------------------------------- */
712 /* -------- CAPI2.0 Interface ---------------------------------- */
713 /* ------------------------------------------------------------- */
715 static int capi_installed(void)
718 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
719 if (cards
[i
].cardstate
== CARD_RUNNING
)
725 static __u16
capi_register(capi_register_params
* rparam
, __u16
* applidp
)
727 int nconn
, want
= rparam
->level3cnt
;
731 if (rparam
->datablklen
< 128)
732 return CAPI_LOGBLKSIZETOSMALL
;
734 for (appl
= 1; appl
<= CAPI_MAXAPPL
; appl
++) {
735 if (APPL_IS_FREE(appl
))
738 if (appl
> CAPI_MAXAPPL
)
739 return CAPI_TOOMANYAPPLS
;
741 APPL_MARK_USED(appl
);
742 skb_queue_head_init(&APPL(appl
)->recv_queue
);
744 memcpy(&APPL(appl
)->rparam
, rparam
, sizeof(capi_register_params
));
746 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
747 struct capi_profile
*profp
=
748 (struct capi_profile
*)cards
[i
].version
[VER_PROFILE
];
750 if (cards
[i
].cardstate
!= CARD_RUNNING
)
753 if (want
> 0) nconn
= want
;
754 else nconn
= profp
->nbchannel
* -want
;
755 if (nconn
== 0) nconn
= profp
->nbchannel
;
757 B1_send_register(cards
[i
].port
, appl
,
758 1024 * (nconn
+1), nconn
,
759 APPL(appl
)->rparam
.datablkcnt
,
760 APPL(appl
)->rparam
.datablklen
);
763 printk(KERN_INFO
"b1capi: appl %d up\n", appl
);
768 static __u16
capi_release(__u16 applid
)
773 if (!VALID_APPLID(applid
) || APPL(applid
)->releasing
)
774 return CAPI_ILLAPPNR
;
775 while ((skb
= skb_dequeue(&APPL(applid
)->recv_queue
)) != 0)
777 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
778 if (cards
[i
].cardstate
!= CARD_RUNNING
) {
781 APPL(applid
)->releasing
++;
782 B1_send_release(cards
[i
].port
, applid
);
784 if (APPL(applid
)->releasing
<= 0) {
785 APPL(applid
)->signal
= 0;
786 APPL_MARK_FREE(applid
);
787 printk(KERN_INFO
"b1capi: appl %d down\n", applid
);
792 static __u16
capi_put_message(__u16 applid
, struct sk_buff
*skb
)
797 return CAPI_REGNOTINSTALLED
;
798 if (!VALID_APPLID(applid
))
799 return CAPI_ILLAPPNR
;
801 || !capi_cmd_valid(CAPIMSG_COMMAND(skb
->data
))
802 || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb
->data
)))
803 return CAPI_ILLCMDORSUBCMDORMSGTOSMALL
;
804 contr
= CAPIMSG_CONTROLLER(skb
->data
);
805 if (!VALID_CARD(contr
) || CARD(contr
)->cardstate
!= CARD_RUNNING
) {
807 if (CARD(contr
)->cardstate
!= CARD_RUNNING
)
808 return CAPI_REGNOTINSTALLED
;
810 if (CARD(contr
)->blocked
)
811 return CAPI_SENDQUEUEFULL
;
813 if ( CAPIMSG_COMMAND(skb
->data
) == CAPI_DATA_B3
814 && CAPIMSG_SUBCOMMAND(skb
->data
) == CAPI_REQ
815 && (np
= find_ncci(APPL(applid
), CAPIMSG_NCCI(skb
->data
))) != 0
816 && mq_enqueue(np
, CAPIMSG_MSGID(skb
->data
)) == 0)
817 return CAPI_SENDQUEUEFULL
;
819 B1_send_message(CARD(contr
)->port
, skb
);
823 static __u16
capi_get_message(__u16 applid
, struct sk_buff
**msgp
)
827 if (!VALID_APPLID(applid
))
828 return CAPI_ILLAPPNR
;
829 if ((skb
= skb_dequeue(&APPL(applid
)->recv_queue
)) == 0)
830 return CAPI_RECEIVEQUEUEEMPTY
;
835 static __u16
capi_set_signal(__u16 applid
,
836 void (*signal
) (__u16 applid
, __u32 param
),
839 if (!VALID_APPLID(applid
))
840 return CAPI_ILLAPPNR
;
841 APPL(applid
)->signal
= signal
;
842 APPL(applid
)->param
= param
;
846 static __u16
capi_get_manufacturer(__u16 contr
, __u8 buf
[CAPI_MANUFACTURER_LEN
])
849 strncpy(buf
, capi_manufakturer
, CAPI_MANUFACTURER_LEN
);
852 if (!VALID_CARD(contr
) || CARD(contr
)->cardstate
!= CARD_RUNNING
)
855 strncpy(buf
, capi_manufakturer
, CAPI_MANUFACTURER_LEN
);
859 static __u16
capi_get_version(__u16 contr
, struct capi_version
*verp
)
862 *verp
= driver_version
;
865 if (!VALID_CARD(contr
) || CARD(contr
)->cardstate
!= CARD_RUNNING
)
868 memcpy((void *) verp
, &CARD(contr
)->cversion
,
869 sizeof(capi_version
));
873 static __u16
capi_get_serial(__u16 contr
, __u8 serial
[CAPI_SERIAL_LEN
])
876 strncpy(serial
, driver_serial
, 8);
879 if (!VALID_CARD(contr
) || CARD(contr
)->cardstate
!= CARD_RUNNING
)
882 memcpy((void *) serial
, CARD(contr
)->version
[VER_SERIAL
],
884 serial
[CAPI_SERIAL_LEN
- 1] = 0;
888 static __u16
capi_get_profile(__u16 contr
, struct capi_profile
*profp
)
891 profp
->ncontroller
= ncards
;
894 if (!VALID_CARD(contr
) || CARD(contr
)->cardstate
!= CARD_RUNNING
)
897 memcpy((void *) profp
, CARD(contr
)->version
[VER_PROFILE
],
898 sizeof(struct capi_profile
));
902 static int capi_manufacturer(unsigned int cmd
, void *data
)
905 avmb1_loadandconfigdef ldef
;
906 avmb1_extcarddef cdef
;
914 case AVMB1_ADDCARD_WITH_TYPE
:
915 if (cmd
== AVMB1_ADDCARD
) {
916 if ((rc
= copy_from_user((void *) &cdef
, data
,
917 sizeof(avmb1_carddef
))))
919 cdef
.cardtype
= AVM_CARDTYPE_B1
;
921 if ((rc
= copy_from_user((void *) &cdef
, data
,
922 sizeof(avmb1_extcarddef
))))
926 if ((rc
= avmb1_probecard(cdef
.port
, cdef
.irq
, cdef
.cardtype
)) != 0)
929 if (cdef
.cardtype
== AVM_CARDTYPE_T1
) {
931 for (i
=0; i
< CAPI_MAXCONTR
; i
++) {
932 if ( cards
[i
].cardstate
!= CARD_FREE
933 && cards
[i
].cardtype
== AVM_CARDTYPE_T1
934 && cards
[i
].cardnr
== cdef
.cardnr
) {
936 "b1capi: T1-HEMA-card-%d already at 0x%x\n",
937 cdef
.cardnr
, cards
[i
].port
);
941 rc
= T1_detectandinit(cdef
.port
,cdef
.irq
,cdef
.cardnr
);
943 printk(KERN_NOTICE
"b1capi: NO T1-HEMA-card-%d at 0x%x (%d)\n",
944 cdef
.cardnr
, cdef
.port
, rc
);
947 printk(KERN_NOTICE
"b1capi: T1-HEMA-card-%d at 0x%x\n",
948 cdef
.cardnr
, cdef
.port
);
951 rc
= avmb1_addcard(cdef
.port
, cdef
.irq
, cdef
.cardtype
);
954 /* don't want to change interface t
955 addcard/probecard/registercard */
956 if (cdef
.cardtype
== AVM_CARDTYPE_T1
) {
958 for (i
=0; i
< CAPI_MAXCONTR
; i
++) {
959 if (cards
[i
].cnr
== rc
) {
960 cards
[i
].cardnr
= cdef
.cardnr
;
968 case AVMB1_LOAD_AND_CONFIG
:
970 if (cmd
== AVMB1_LOAD
) {
971 if ((rc
= copy_from_user((void *) &ldef
, data
,
972 sizeof(avmb1_loaddef
))))
974 ldef
.t4config
.len
= 0;
975 ldef
.t4config
.data
= 0;
977 if ((rc
= copy_from_user((void *) &ldef
, data
,
978 sizeof(avmb1_loadandconfigdef
))))
981 if (!VALID_CARD(ldef
.contr
))
984 if (ldef
.t4file
.len
<= 0) {
985 printk(KERN_DEBUG
"b1capi: load: invalid parameter: length of t4file is %d ?\n", ldef
.t4file
.len
);
989 card
= CARD(ldef
.contr
);
992 if (card
->cardstate
!= CARD_DETECTED
) {
993 restore_flags(flags
);
995 printk(KERN_DEBUG
"b1capi: load: contr=%d not in detect state\n", ldef
.contr
);
998 card
->cardstate
= CARD_LOADING
;
999 restore_flags(flags
);
1002 printk(KERN_DEBUG
"b1capi: load: reseting contr %d\n",
1006 B1_reset(card
->port
);
1009 printk(KERN_DEBUG
"b1capi: loading contr %d\n",
1013 if ((rc
= B1_load_t4file(card
->port
, &ldef
.t4file
))) {
1014 B1_reset(card
->port
);
1015 printk(KERN_ERR
"b1capi: failed to load t4file!!\n");
1016 card
->cardstate
= CARD_DETECTED
;
1020 B1_disable_irq(card
->port
);
1022 if (ldef
.t4config
.len
> 0) { /* load config */
1024 printk(KERN_DEBUG
"b1capi: loading config to contr %d\n",
1027 if ((rc
= B1_load_config(card
->port
, &ldef
.t4config
))) {
1028 B1_reset(card
->port
);
1029 printk(KERN_ERR
"b1capi: failed to load config!!\n");
1030 card
->cardstate
= CARD_DETECTED
;
1036 printk(KERN_DEBUG
"b1capi: load: ready contr %d: checking\n",
1040 if (!B1_loaded(card
->port
)) {
1041 card
->cardstate
= CARD_DETECTED
;
1042 printk(KERN_ERR
"b1capi: failed to load t4file.\n");
1049 card
->cardstate
= CARD_INITSTATE
;
1052 B1_setinterrupt(card
->port
, card
->irq
, card
->cardtype
);
1053 restore_flags(flags
);
1056 printk(KERN_DEBUG
"b1capi: load: irq enabled contr %d\n",
1063 if (card
->cardtype
== AVM_CARDTYPE_T1
)
1064 B1_send_init(card
->port
, AVM_NAPPS
,
1065 AVM_NNCCI_PER_CHANNEL
*30,
1068 B1_send_init(card
->port
, AVM_NAPPS
,
1069 AVM_NNCCI_PER_CHANNEL
*2,
1073 printk(KERN_DEBUG
"b1capi: load: waiting for init reply contr %d\n",
1077 while (card
->cardstate
!= CARD_RUNNING
) {
1079 current
->state
= TASK_INTERRUPTIBLE
;
1080 schedule_timeout(HZ
/10); /* 0.1 sec */
1082 if (signal_pending(current
))
1087 case AVMB1_RESETCARD
:
1088 if ((rc
= copy_from_user((void *) &rdef
, data
,
1089 sizeof(avmb1_resetdef
))))
1092 return avmb1_resetcard(rdef
.contr
);
1094 case AVMB1_GET_CARDINFO
:
1095 if ((rc
= copy_from_user((void *) &gdef
, data
,
1096 sizeof(avmb1_getdef
))))
1099 if (!VALID_CARD(gdef
.contr
))
1102 card
= CARD(gdef
.contr
);
1104 gdef
.cardstate
= card
->cardstate
;
1105 gdef
.cardtype
= card
->cardtype
;
1107 if ((rc
= copy_to_user(data
, (void *) &gdef
,
1108 sizeof(avmb1_getdef
))))
1112 case AVMB1_REMOVECARD
:
1113 if ((rc
= copy_from_user((void *) &rdef
, data
,
1114 sizeof(avmb1_resetdef
))))
1116 if (!VALID_CARD(rdef
.contr
))
1119 card
= CARD(rdef
.contr
);
1121 if (card
->cardstate
!= CARD_DETECTED
)
1124 return avmb1_unregistercard(rdef
.contr
, 1);
1129 struct capi_interface avmb1_interface
=
1137 capi_get_manufacturer
,
1144 /* ------------------------------------------------------------- */
1145 /* -------- Exported Functions --------------------------------- */
1146 /* ------------------------------------------------------------- */
1148 struct capi_interface
*attach_capi_interface(struct capi_interface_user
*userp
)
1150 struct capi_interface_user
*p
;
1152 for (p
= capi_users
; p
; p
= p
->next
) {
1154 printk(KERN_ERR
"b1capi: double attach from %s\n",
1159 userp
->next
= capi_users
;
1162 printk(KERN_NOTICE
"b1capi: %s attached\n", userp
->name
);
1164 return &avmb1_interface
;
1167 int detach_capi_interface(struct capi_interface_user
*userp
)
1169 struct capi_interface_user
**pp
;
1171 for (pp
= &capi_users
; *pp
; pp
= &(*pp
)->next
) {
1176 printk(KERN_NOTICE
"b1capi: %s detached\n", userp
->name
);
1180 printk(KERN_ERR
"b1capi: double detach from %s\n", userp
->name
);
1184 /* ------------------------------------------------------------- */
1185 /* -------- Init & Cleanup ------------------------------------- */
1186 /* ------------------------------------------------------------- */
1188 EXPORT_SYMBOL(attach_capi_interface
);
1189 EXPORT_SYMBOL(detach_capi_interface
);
1190 EXPORT_SYMBOL(avmb1_addcard
);
1191 EXPORT_SYMBOL(avmb1_probecard
);
1192 EXPORT_SYMBOL(avmb1_registercard
);
1193 EXPORT_SYMBOL(avmb1_unregistercard
);
1194 EXPORT_SYMBOL(avmb1_resetcard
);
1195 EXPORT_SYMBOL(avmb1_detectcard
);
1199 * init / exit functions
1203 #define avmb1_init init_module
1206 int avmb1_init(void)
1211 skb_queue_head_init(&recv_queue
);
1212 /* init_bh(CAPI_BH, do_capi_bh); */
1214 tq_state_notify
.routine
= notify_handler
;
1215 tq_state_notify
.data
= 0;
1217 tq_recv_notify
.routine
= recv_handler
;
1218 tq_recv_notify
.data
= 0;
1221 if ((p
= strchr(revision
, ':'))) {
1223 p
= strchr(rev
, '$');
1226 strcpy(rev
, " ??? ");
1229 printk(KERN_NOTICE
"AVM-B1-CAPI-driver Rev%s: loaded\n", rev
);
1231 printk(KERN_NOTICE
"AVM-B1-CAPI-driver Rev%s: started\n", rev
);
1237 void cleanup_module(void)
1243 if ((p
= strchr(revision
, ':'))) {
1245 p
= strchr(rev
, '$');
1248 strcpy(rev
, " ??? ");
1251 for (i
= 0; i
< CAPI_MAXCONTR
; i
++) {
1252 if (cards
[i
].cardstate
!= CARD_FREE
) {
1256 B1_disable_irq(cards
[i
].port
);
1257 avmb1_resetcard(i
+1);
1259 * free kernel resources
1261 avmb1_unregistercard(i
+1, 1);
1264 schedule(); /* execute queued tasks .... */
1265 printk(KERN_NOTICE
"AVM-B1-CAPI-driver Rev%s: unloaded\n", rev
);