more debug output
[linux-2.4.git] / drivers / isdn / hisax / config.c
1 /* $Id: config.c,v 1.1.4.5 2001/12/09 19:19:26 kai Exp $
2  *
3  * Author       Karsten Keil
4  * Copyright    by Karsten Keil      <keil@isdn4linux.de>
5  *              by Kai Germaschewski <kai.germaschewski@gmx.de>
6  * 
7  * This software may be used and distributed according to the terms
8  * of the GNU General Public License, incorporated herein by reference.
9  *
10  * For changes and modifications please read
11  * ../../../Documentation/isdn/HiSax.cert
12  *
13  * based on the teles driver from Jan den Ouden
14  *
15  */
16
17 #include <linux/types.h>
18 #include <linux/stddef.h>
19 #include <linux/timer.h>
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include "hisax.h"
23 #include <linux/module.h>
24 #include <linux/kernel_stat.h>
25 #include <linux/tqueue.h>
26 #include <linux/interrupt.h>
27 #define HISAX_STATUS_BUFSIZE 4096
28 #define INCLUDE_INLINE_FUNCS
29
30 /*
31  * This structure array contains one entry per card. An entry looks
32  * like this:
33  *
34  * { type, protocol, p0, p1, p2, NULL }
35  *
36  * type
37  *    1 Teles 16.0       p0=irq p1=membase p2=iobase
38  *    2 Teles  8.0       p0=irq p1=membase
39  *    3 Teles 16.3       p0=irq p1=iobase
40  *    4 Creatix PNP      p0=irq p1=IO0 (ISAC)  p2=IO1 (HSCX)
41  *    5 AVM A1 (Fritz)   p0=irq p1=iobase
42  *    6 ELSA PC          [p0=iobase] or nothing (autodetect)
43  *    7 ELSA Quickstep   p0=irq p1=iobase
44  *    8 Teles PCMCIA     p0=irq p1=iobase
45  *    9 ITK ix1-micro    p0=irq p1=iobase
46  *   10 ELSA PCMCIA      p0=irq p1=iobase
47  *   11 Eicon.Diehl Diva p0=irq p1=iobase
48  *   12 Asuscom ISDNLink p0=irq p1=iobase
49  *   13 Teleint          p0=irq p1=iobase
50  *   14 Teles 16.3c      p0=irq p1=iobase
51  *   15 Sedlbauer speed  p0=irq p1=iobase
52  *   15 Sedlbauer PC/104        p0=irq p1=iobase
53  *   15 Sedlbauer speed pci     no parameter
54  *   16 USR Sportster internal  p0=irq  p1=iobase
55  *   17 MIC card                p0=irq  p1=iobase
56  *   18 ELSA Quickstep 1000PCI  no parameter
57  *   19 Compaq ISDN S0 ISA card p0=irq  p1=IO0 (HSCX)  p2=IO1 (ISAC) p3=IO2
58  *   20 Travers Technologies NETjet-S PCI card
59  *   21 TELES PCI               no parameter
60  *   22 Sedlbauer Speed Star    p0=irq p1=iobase
61  *   23 reserved
62  *   24 Dr Neuhaus Niccy PnP/PCI card p0=irq p1=IO0 p2=IO1 (PnP only)
63  *   25 Teles S0Box             p0=irq p1=iobase (from isapnp setup)
64  *   26 AVM A1 PCMCIA (Fritz)   p0=irq p1=iobase
65  *   27 AVM PnP/PCI             p0=irq p1=iobase (PCI no parameter)
66  *   28 Sedlbauer Speed Fax+    p0=irq p1=iobase (from isapnp setup)
67  *   29 Siemens I-Surf          p0=irq p1=iobase p2=memory (from isapnp setup)
68  *   30 ACER P10                p0=irq p1=iobase (from isapnp setup)
69  *   31 HST Saphir              p0=irq  p1=iobase
70  *   32 Telekom A4T             none
71  *   33 Scitel Quadro           p0=subcontroller (4*S0, subctrl 1...4)
72  *   34 Gazel ISDN cards
73  *   35 HFC 2BDS0 PCI           none
74  *   36 Winbond 6692 PCI        none
75  *   37 HFC 2BDS0 S+/SP         p0=irq p1=iobase
76  *   38 Travers Technologies NETspider-U PCI card
77  *   39 HFC 2BDS0-SP PCMCIA     p0=irq p1=iobase
78  *   40 hotplug interface
79  *   41 Formula-n enter:now ISDN PCI a/b   none
80  *
81  * protocol can be either ISDN_PTYPE_EURO or ISDN_PTYPE_1TR6 or ISDN_PTYPE_NI1
82  *
83  *
84  */
85
86 const char *CardType[] = {
87         "No Card", "Teles 16.0", "Teles 8.0", "Teles 16.3",
88         "Creatix/Teles PnP", "AVM A1", "Elsa ML", "Elsa Quickstep",
89         "Teles PCMCIA", "ITK ix1-micro Rev.2", "Elsa PCMCIA",
90         "Eicon.Diehl Diva", "ISDNLink", "TeleInt", "Teles 16.3c",
91         "Sedlbauer Speed Card", "USR Sportster", "ith mic Linux",
92         "Elsa PCI", "Compaq ISA", "NETjet-S", "Teles PCI", 
93         "Sedlbauer Speed Star (PCMCIA)", "AMD 7930", "NICCY", "S0Box",
94         "AVM A1 (PCMCIA)", "AVM Fritz PnP/PCI", "Sedlbauer Speed Fax +",
95         "Siemens I-Surf", "Acer P10", "HST Saphir", "Telekom A4T",
96         "Scitel Quadro", "Gazel", "HFC 2BDS0 PCI", "Winbond 6692",
97         "HFC 2BDS0 SX", "NETspider-U", "HFC-2BDS0-SP PCMCIA",
98         "Hotplug", "Formula-n enter:now PCI a/b", 
99 };
100
101 void HiSax_closecard(int cardnr);
102
103 #ifdef CONFIG_HISAX_ELSA
104 #define DEFAULT_CARD ISDN_CTYPE_ELSA
105 #define DEFAULT_CFG {0,0,0,0}
106 int elsa_init_pcmcia(void *, int, int *, int);
107 EXPORT_SYMBOL(elsa_init_pcmcia);
108 #endif
109
110 #ifdef CONFIG_HISAX_AVM_A1
111 #undef DEFAULT_CARD
112 #undef DEFAULT_CFG
113 #define DEFAULT_CARD ISDN_CTYPE_A1
114 #define DEFAULT_CFG {10,0x340,0,0}
115 #endif
116
117 #ifdef CONFIG_HISAX_AVM_A1_PCMCIA
118 #undef DEFAULT_CARD
119 #undef DEFAULT_CFG
120 #define DEFAULT_CARD ISDN_CTYPE_A1_PCMCIA
121 #define DEFAULT_CFG {11,0x170,0,0}
122 int avm_a1_init_pcmcia(void *, int, int *, int);
123 EXPORT_SYMBOL(avm_a1_init_pcmcia);
124 #endif
125
126 #ifdef CONFIG_HISAX_FRITZPCI
127 #undef DEFAULT_CARD
128 #undef DEFAULT_CFG
129 #define DEFAULT_CARD ISDN_CTYPE_FRITZPCI
130 #define DEFAULT_CFG {0,0,0,0}
131 #endif
132
133 #ifdef CONFIG_HISAX_16_3
134 #undef DEFAULT_CARD
135 #undef DEFAULT_CFG
136 #define DEFAULT_CARD ISDN_CTYPE_16_3
137 #define DEFAULT_CFG {15,0x180,0,0}
138 #endif
139
140 #ifdef CONFIG_HISAX_S0BOX
141 #undef DEFAULT_CARD
142 #undef DEFAULT_CFG
143 #define DEFAULT_CARD ISDN_CTYPE_S0BOX
144 #define DEFAULT_CFG {7,0x378,0,0}
145 #endif
146
147 #ifdef CONFIG_HISAX_16_0
148 #undef DEFAULT_CARD
149 #undef DEFAULT_CFG
150 #define DEFAULT_CARD ISDN_CTYPE_16_0
151 #define DEFAULT_CFG {15,0xd0000,0xd80,0}
152 #endif
153
154 #ifdef CONFIG_HISAX_TELESPCI
155 #undef DEFAULT_CARD
156 #undef DEFAULT_CFG
157 #define DEFAULT_CARD ISDN_CTYPE_TELESPCI
158 #define DEFAULT_CFG {0,0,0,0}
159 #endif
160
161 #ifdef CONFIG_HISAX_IX1MICROR2
162 #undef DEFAULT_CARD
163 #undef DEFAULT_CFG
164 #define DEFAULT_CARD ISDN_CTYPE_IX1MICROR2
165 #define DEFAULT_CFG {5,0x390,0,0}
166 #endif
167
168 #ifdef CONFIG_HISAX_DIEHLDIVA
169 #undef DEFAULT_CARD
170 #undef DEFAULT_CFG
171 #define DEFAULT_CARD ISDN_CTYPE_DIEHLDIVA
172 #define DEFAULT_CFG {0,0x0,0,0}
173 #endif
174
175 #ifdef CONFIG_HISAX_ASUSCOM
176 #undef DEFAULT_CARD
177 #undef DEFAULT_CFG
178 #define DEFAULT_CARD ISDN_CTYPE_ASUSCOM
179 #define DEFAULT_CFG {5,0x200,0,0}
180 #endif
181
182 #ifdef CONFIG_HISAX_TELEINT
183 #undef DEFAULT_CARD
184 #undef DEFAULT_CFG
185 #define DEFAULT_CARD ISDN_CTYPE_TELEINT
186 #define DEFAULT_CFG {5,0x300,0,0}
187 #endif
188
189 #ifdef CONFIG_HISAX_SEDLBAUER
190 #undef DEFAULT_CARD
191 #undef DEFAULT_CFG
192 #define DEFAULT_CARD ISDN_CTYPE_SEDLBAUER
193 #define DEFAULT_CFG {11,0x270,0,0}
194 int sedl_init_pcmcia(void *, int, int *, int);
195 EXPORT_SYMBOL(sedl_init_pcmcia);
196 #endif
197
198 #ifdef CONFIG_HISAX_SPORTSTER
199 #undef DEFAULT_CARD
200 #undef DEFAULT_CFG
201 #define DEFAULT_CARD ISDN_CTYPE_SPORTSTER
202 #define DEFAULT_CFG {7,0x268,0,0}
203 #endif
204
205 #ifdef CONFIG_HISAX_MIC
206 #undef DEFAULT_CARD
207 #undef DEFAULT_CFG
208 #define DEFAULT_CARD ISDN_CTYPE_MIC
209 #define DEFAULT_CFG {12,0x3e0,0,0}
210 #endif
211
212 #ifdef CONFIG_HISAX_NETJET
213 #undef DEFAULT_CARD
214 #undef DEFAULT_CFG
215 #define DEFAULT_CARD ISDN_CTYPE_NETJET_S
216 #define DEFAULT_CFG {0,0,0,0}
217 #endif
218
219 #ifdef CONFIG_HISAX_HFCS
220 #undef DEFAULT_CARD
221 #undef DEFAULT_CFG
222 #define DEFAULT_CARD ISDN_CTYPE_TELES3C
223 #define DEFAULT_CFG {5,0x500,0,0}
224 #endif
225
226 #ifdef CONFIG_HISAX_HFC_PCI
227 #undef DEFAULT_CARD
228 #undef DEFAULT_CFG
229 #define DEFAULT_CARD ISDN_CTYPE_HFC_PCI
230 #define DEFAULT_CFG {0,0,0,0}
231 #endif
232
233 #ifdef CONFIG_HISAX_HFC_SX
234 #undef DEFAULT_CARD
235 #undef DEFAULT_CFG
236 #define DEFAULT_CARD ISDN_CTYPE_HFC_SX
237 #define DEFAULT_CFG {5,0x2E0,0,0}
238 int hfc_init_pcmcia(void *, int, int *, int);
239 EXPORT_SYMBOL(hfc_init_pcmcia);
240 #endif
241
242
243 #ifdef CONFIG_HISAX_AMD7930
244 #undef DEFAULT_CARD
245 #undef DEFAULT_CFG
246 #define DEFAULT_CARD ISDN_CTYPE_AMD7930
247 #define DEFAULT_CFG {12,0x3e0,0,0}
248 #endif
249
250 #ifdef CONFIG_HISAX_NICCY
251 #undef DEFAULT_CARD
252 #undef DEFAULT_CFG
253 #define DEFAULT_CARD ISDN_CTYPE_NICCY
254 #define DEFAULT_CFG {0,0x0,0,0}
255 #endif
256
257 #ifdef CONFIG_HISAX_ISURF
258 #undef DEFAULT_CARD
259 #undef DEFAULT_CFG
260 #define DEFAULT_CARD ISDN_CTYPE_ISURF
261 #define DEFAULT_CFG {5,0x100,0xc8000,0}
262 #endif
263
264 #ifdef CONFIG_HISAX_HSTSAPHIR
265 #undef DEFAULT_CARD
266 #undef DEFAULT_CFG
267 #define DEFAULT_CARD ISDN_CTYPE_HSTSAPHIR
268 #define DEFAULT_CFG {5,0x250,0,0}
269 #endif
270
271 #ifdef CONFIG_HISAX_BKM_A4T
272 #undef DEFAULT_CARD
273 #undef DEFAULT_CFG
274 #define DEFAULT_CARD ISDN_CTYPE_BKM_A4T
275 #define DEFAULT_CFG {0,0x0,0,0}
276 #endif
277
278 #ifdef CONFIG_HISAX_SCT_QUADRO
279 #undef DEFAULT_CARD
280 #undef DEFAULT_CFG
281 #define DEFAULT_CARD ISDN_CTYPE_SCT_QUADRO
282 #define DEFAULT_CFG {1,0x0,0,0}
283 #endif
284
285 #ifdef CONFIG_HISAX_GAZEL
286 #undef DEFAULT_CARD
287 #undef DEFAULT_CFG
288 #define DEFAULT_CARD ISDN_CTYPE_GAZEL
289 #define DEFAULT_CFG {15,0x180,0,0}
290 #endif
291
292 #ifdef CONFIG_HISAX_W6692
293 #undef DEFAULT_CARD
294 #undef DEFAULT_CFG
295 #define DEFAULT_CARD ISDN_CTYPE_W6692
296 #define DEFAULT_CFG {0,0,0,0}
297 #endif
298
299 #ifdef CONFIG_HISAX_NETJET_U
300 #undef DEFAULT_CARD
301 #undef DEFAULT_CFG
302 #define DEFAULT_CARD ISDN_CTYPE_NETJET_U
303 #define DEFAULT_CFG {0,0,0,0}
304 #endif
305
306 #ifdef CONFIG_HISAX_1TR6
307 #define DEFAULT_PROTO ISDN_PTYPE_1TR6
308 #define DEFAULT_PROTO_NAME "1TR6"
309 #endif
310 #ifdef CONFIG_HISAX_NI1
311 #undef DEFAULT_PROTO
312 #define DEFAULT_PROTO ISDN_PTYPE_NI1
313 #undef DEFAULT_PROTO_NAME
314 #define DEFAULT_PROTO_NAME "NI1"
315 #endif
316 #ifdef CONFIG_HISAX_EURO
317 #undef DEFAULT_PROTO
318 #define DEFAULT_PROTO ISDN_PTYPE_EURO
319 #undef DEFAULT_PROTO_NAME
320 #define DEFAULT_PROTO_NAME "EURO"
321 #endif
322 #ifndef DEFAULT_PROTO
323 #define DEFAULT_PROTO ISDN_PTYPE_UNKNOWN
324 #define DEFAULT_PROTO_NAME "UNKNOWN"
325 #endif
326 #ifndef DEFAULT_CARD
327 #define DEFAULT_CARD 0
328 #define DEFAULT_CFG {0,0,0,0}
329 #endif
330
331 int hisax_init_pcmcia(void *, int *, struct IsdnCard *);
332 EXPORT_SYMBOL(hisax_init_pcmcia);
333 EXPORT_SYMBOL(HiSax_closecard);
334
335 #define FIRST_CARD { \
336         DEFAULT_CARD, \
337         DEFAULT_PROTO, \
338         DEFAULT_CFG, \
339         NULL, \
340 }
341
342 struct IsdnCard cards[HISAX_MAX_CARDS] = {
343         FIRST_CARD,
344 };
345
346 #define HISAX_IDSIZE (HISAX_MAX_CARDS*8)
347 static char HiSaxID[HISAX_IDSIZE] __devinitdata = { 0, };
348
349 char *HiSax_id __devinitdata = HiSaxID;
350 #ifdef MODULE
351 /* Variables for insmod */
352 static int type[HISAX_MAX_CARDS] __devinitdata = { 0, };
353 static int protocol[HISAX_MAX_CARDS] __devinitdata = { 0, };
354 static int io[HISAX_MAX_CARDS] __devinitdata = { 0, };
355 #undef IO0_IO1
356 #ifdef CONFIG_HISAX_16_3
357 #define IO0_IO1
358 #endif
359 #ifdef CONFIG_HISAX_NICCY
360 #undef IO0_IO1
361 #define IO0_IO1
362 #endif
363 #ifdef IO0_IO1
364 static int io0[HISAX_MAX_CARDS] __devinitdata = { 0, };
365 static int io1[HISAX_MAX_CARDS] __devinitdata = { 0, };
366 #endif
367 static int irq[HISAX_MAX_CARDS] __devinitdata = { 0, };
368 static int mem[HISAX_MAX_CARDS] __devinitdata = { 0, };
369 static char *id __devinitdata = HiSaxID;
370
371 #define PARM_PARA "1-" __MODULE_STRING(HISAX_MAX_CARDS) "i"
372
373 MODULE_DESCRIPTION("ISDN4Linux: Driver for passive ISDN cards");
374 MODULE_AUTHOR("Karsten Keil");
375 MODULE_LICENSE("GPL");
376 MODULE_PARM(type, PARM_PARA);
377 MODULE_PARM(protocol, PARM_PARA);
378 MODULE_PARM(io, PARM_PARA);
379 MODULE_PARM(irq, PARM_PARA);
380 MODULE_PARM(mem, PARM_PARA);
381 MODULE_PARM(id, "s");
382 #ifdef IO0_IO1
383 MODULE_PARM(io0, PARM_PARA);
384 MODULE_PARM(io1, PARM_PARA);
385 #endif
386 #endif /* MODULE */
387
388 int nrcards;
389
390 extern char *l1_revision;
391 extern char *l2_revision;
392 extern char *l3_revision;
393 extern char *lli_revision;
394 extern char *tei_revision;
395
396 char *HiSax_getrev(const char *revision)
397 {
398         char *rev;
399         char *p;
400
401         if ((p = strchr(revision, ':'))) {
402                 rev = p + 2;
403                 p = strchr(rev, '$');
404                 *--p = 0;
405         } else
406                 rev = "???";
407         return rev;
408 }
409
410 void __init HiSaxVersion(void)
411 {
412         char tmp[64];
413
414         printk(KERN_INFO "HiSax: Linux Driver for passive ISDN cards\n");
415 #ifdef MODULE
416         printk(KERN_INFO "HiSax: Version 3.5 (module)\n");
417 #else
418         printk(KERN_INFO "HiSax: Version 3.5 (kernel)\n");
419 #endif
420         strcpy(tmp, l1_revision);
421         printk(KERN_INFO "HiSax: Layer1 Revision %s\n", HiSax_getrev(tmp));
422         strcpy(tmp, l2_revision);
423         printk(KERN_INFO "HiSax: Layer2 Revision %s\n", HiSax_getrev(tmp));
424         strcpy(tmp, tei_revision);
425         printk(KERN_INFO "HiSax: TeiMgr Revision %s\n", HiSax_getrev(tmp));
426         strcpy(tmp, l3_revision);
427         printk(KERN_INFO "HiSax: Layer3 Revision %s\n", HiSax_getrev(tmp));
428         strcpy(tmp, lli_revision);
429         printk(KERN_INFO "HiSax: LinkLayer Revision %s\n",
430                HiSax_getrev(tmp));
431         certification_check(1);
432 }
433
434 #ifndef MODULE
435 #define MAX_ARG (HISAX_MAX_CARDS*5)
436 static int __init HiSax_setup(char *line)
437 {
438         int i, j, argc;
439         int ints[MAX_ARG + 1];
440         char *str;
441
442         str = get_options(line, MAX_ARG, ints);
443         argc = ints[0];
444         printk(KERN_DEBUG "HiSax_setup: argc(%d) str(%s)\n", argc, str);
445         i = 0;
446         j = 1;
447         while (argc && (i < HISAX_MAX_CARDS)) {
448                 cards[i].protocol = DEFAULT_PROTO;
449                 if (argc) {
450                         cards[i].typ = ints[j];
451                         j++;
452                         argc--;
453                 }
454                 if (argc) {
455                         cards[i].protocol = ints[j];
456                         j++;
457                         argc--;
458                 }
459                 if (argc) {
460                         cards[i].para[0] = ints[j];
461                         j++;
462                         argc--;
463                 }
464                 if (argc) {
465                         cards[i].para[1] = ints[j];
466                         j++;
467                         argc--;
468                 }
469                 if (argc) {
470                         cards[i].para[2] = ints[j];
471                         j++;
472                         argc--;
473                 }
474                 i++;
475         }
476         if (str && *str) {
477                 if (strlen(str) < HISAX_IDSIZE)
478                         strcpy(HiSaxID, str);
479                 else
480                         printk(KERN_WARNING "HiSax: ID too long!");
481         } else
482                 strcpy(HiSaxID, "HiSax");
483
484         HiSax_id = HiSaxID;
485         return 1;
486 }
487
488 __setup("hisax=", HiSax_setup);
489 #endif /* MODULES */
490
491 #if CARD_TELES0
492 extern int setup_teles0(struct IsdnCard *card);
493 #endif
494
495 #if CARD_TELES3
496 extern int setup_teles3(struct IsdnCard *card);
497 #endif
498
499 #if CARD_S0BOX
500 extern int setup_s0box(struct IsdnCard *card);
501 #endif
502
503 #if CARD_TELESPCI
504 extern int setup_telespci(struct IsdnCard *card);
505 #endif
506
507 #if CARD_AVM_A1
508 extern int setup_avm_a1(struct IsdnCard *card);
509 #endif
510
511 #if CARD_AVM_A1_PCMCIA
512 extern int setup_avm_a1_pcmcia(struct IsdnCard *card);
513 #endif
514
515 #if CARD_FRITZPCI
516 extern int setup_avm_pcipnp(struct IsdnCard *card);
517 #endif
518
519 #if CARD_ELSA
520 extern int setup_elsa(struct IsdnCard *card);
521 #endif
522
523 #if CARD_IX1MICROR2
524 extern int setup_ix1micro(struct IsdnCard *card);
525 #endif
526
527 #if CARD_DIEHLDIVA
528 extern int setup_diva(struct IsdnCard *card);
529 #endif
530
531 #if CARD_ASUSCOM
532 extern int setup_asuscom(struct IsdnCard *card);
533 #endif
534
535 #if CARD_TELEINT
536 extern int setup_TeleInt(struct IsdnCard *card);
537 #endif
538
539 #if CARD_SEDLBAUER
540 extern int setup_sedlbauer(struct IsdnCard *card);
541 #endif
542
543 #if CARD_SPORTSTER
544 extern int setup_sportster(struct IsdnCard *card);
545 #endif
546
547 #if CARD_MIC
548 extern int setup_mic(struct IsdnCard *card);
549 #endif
550
551 #if CARD_NETJET_S
552 extern int setup_netjet_s(struct IsdnCard *card);
553 #endif
554
555 #if CARD_HFCS
556 extern int setup_hfcs(struct IsdnCard *card);
557 #endif
558
559 #if CARD_HFC_PCI
560 extern int setup_hfcpci(struct IsdnCard *card);
561 #endif
562
563 #if CARD_HFC_SX
564 extern int setup_hfcsx(struct IsdnCard *card);
565 #endif
566
567 #if CARD_AMD7930
568 extern int setup_amd7930(struct IsdnCard *card);
569 #endif
570
571 #if CARD_NICCY
572 extern int setup_niccy(struct IsdnCard *card);
573 #endif
574
575 #if CARD_ISURF
576 extern int setup_isurf(struct IsdnCard *card);
577 #endif
578
579 #if CARD_HSTSAPHIR
580 extern int setup_saphir(struct IsdnCard *card);
581 #endif
582
583 #if CARD_TESTEMU
584 extern int setup_testemu(struct IsdnCard *card);
585 #endif
586
587 #if CARD_BKM_A4T
588 extern int setup_bkm_a4t(struct IsdnCard *card);
589 #endif
590
591 #if CARD_SCT_QUADRO
592 extern int setup_sct_quadro(struct IsdnCard *card);
593 #endif
594
595 #if CARD_GAZEL
596 extern int setup_gazel(struct IsdnCard *card);
597 #endif
598
599 #if CARD_W6692
600 extern int setup_w6692(struct IsdnCard *card);
601 #endif
602
603 #if CARD_NETJET_U
604 extern int setup_netjet_u(struct IsdnCard *card);
605 #endif
606
607 #if CARD_FN_ENTERNOW_PCI
608 extern int setup_enternow_pci(struct IsdnCard *card);
609 #endif
610
611 /*
612  * Find card with given driverId
613  */
614 static inline struct IsdnCardState *hisax_findcard(int driverid)
615 {
616         int i;
617
618         for (i = 0; i < nrcards; i++)
619                 if (cards[i].cs)
620                         if (cards[i].cs->myid == driverid)
621                                 return cards[i].cs;
622         return NULL;
623 }
624
625 /*
626  * Find card with given card number
627  */
628 struct IsdnCardState *hisax_get_card(int cardnr)
629 {
630         if ((cardnr <= nrcards) && (cardnr > 0))
631                 if (cards[cardnr - 1].cs)
632                         return cards[cardnr - 1].cs;
633         return NULL;
634 }
635
636 int HiSax_readstatus(u_char * buf, int len, int user, int id, int channel)
637 {
638         int count, cnt;
639         u_char *p = buf;
640         struct IsdnCardState *cs = hisax_findcard(id);
641
642         if (cs) {
643                 if (len > HISAX_STATUS_BUFSIZE) {
644                         printk(KERN_WARNING
645                                "HiSax: status overflow readstat %d/%d\n",
646                                len, HISAX_STATUS_BUFSIZE);
647                 }
648                 count = cs->status_end - cs->status_read + 1;
649                 if (count >= len)
650                         count = len;
651                 if (user)
652                         copy_to_user(p, cs->status_read, count);
653                 else
654                         memcpy(p, cs->status_read, count);
655                 cs->status_read += count;
656                 if (cs->status_read > cs->status_end)
657                         cs->status_read = cs->status_buf;
658                 p += count;
659                 count = len - count;
660                 while (count) {
661                         if (count > HISAX_STATUS_BUFSIZE)
662                                 cnt = HISAX_STATUS_BUFSIZE;
663                         else
664                                 cnt = count;
665                         if (user)
666                                 copy_to_user(p, cs->status_read, cnt);
667                         else
668                                 memcpy(p, cs->status_read, cnt);
669                         p += cnt;
670                         cs->status_read += cnt % HISAX_STATUS_BUFSIZE;
671                         count -= cnt;
672                 }
673                 return len;
674         } else {
675                 printk(KERN_ERR
676                        "HiSax: if_readstatus called with invalid driverId!\n");
677                 return -ENODEV;
678         }
679 }
680
681 int jiftime(char *s, long mark)
682 {
683         s += 8;
684
685         *s-- = '\0';
686         *s-- = mark % 10 + '0';
687         mark /= 10;
688         *s-- = mark % 10 + '0';
689         mark /= 10;
690         *s-- = '.';
691         *s-- = mark % 10 + '0';
692         mark /= 10;
693         *s-- = mark % 6 + '0';
694         mark /= 6;
695         *s-- = ':';
696         *s-- = mark % 10 + '0';
697         mark /= 10;
698         *s-- = mark % 10 + '0';
699         return 8;
700 }
701
702 static u_char tmpbuf[HISAX_STATUS_BUFSIZE];
703
704 void VHiSax_putstatus(struct IsdnCardState *cs, char *head, char *fmt,
705                       va_list args)
706 {
707         /* if head == NULL the fmt contains the full info */
708
709         long flags;
710         int count, i;
711         u_char *p;
712         isdn_ctrl ic;
713         int len;
714
715         save_flags(flags);
716         cli();
717         p = tmpbuf;
718         if (head) {
719                 p += jiftime(p, jiffies);
720                 p += sprintf(p, " %s", head);
721                 p += vsprintf(p, fmt, args);
722                 *p++ = '\n';
723                 *p = 0;
724                 len = p - tmpbuf;
725                 p = tmpbuf;
726         } else {
727                 p = fmt;
728                 len = strlen(fmt);
729         }
730         if (!cs) {
731                 printk(KERN_WARNING "HiSax: No CardStatus for message %s",
732                        p);
733                 restore_flags(flags);
734                 return;
735         }
736         if (len > HISAX_STATUS_BUFSIZE) {
737                 printk(KERN_WARNING "HiSax: status overflow %d/%d\n",
738                        len, HISAX_STATUS_BUFSIZE);
739                 restore_flags(flags);
740                 return;
741         }
742         count = len;
743         i = cs->status_end - cs->status_write + 1;
744         if (i >= len)
745                 i = len;
746         len -= i;
747         memcpy(cs->status_write, p, i);
748         cs->status_write += i;
749         if (cs->status_write > cs->status_end)
750                 cs->status_write = cs->status_buf;
751         p += i;
752         if (len) {
753                 memcpy(cs->status_write, p, len);
754                 cs->status_write += len;
755         }
756 #ifdef KERNELSTACK_DEBUG
757         i = (ulong) & len - current->kernel_stack_page;
758         sprintf(tmpbuf, "kstack %s %lx use %ld\n", current->comm,
759                 current->kernel_stack_page, i);
760         len = strlen(tmpbuf);
761         for (p = tmpbuf, i = len; i > 0; i--, p++) {
762                 *cs->status_write++ = *p;
763                 if (cs->status_write > cs->status_end)
764                         cs->status_write = cs->status_buf;
765                 count++;
766         }
767 #endif
768         restore_flags(flags);
769         if (count) {
770                 ic.command = ISDN_STAT_STAVAIL;
771                 ic.driver = cs->myid;
772                 ic.arg = count;
773                 cs->iif.statcallb(&ic);
774         }
775 }
776
777 void HiSax_putstatus(struct IsdnCardState *cs, char *head, char *fmt, ...)
778 {
779         va_list args;
780
781         va_start(args, fmt);
782         VHiSax_putstatus(cs, head, fmt, args);
783         va_end(args);
784 }
785
786 int ll_run(struct IsdnCardState *cs, int addfeatures)
787 {
788         long flags;
789         isdn_ctrl ic;
790
791         save_flags(flags);
792         cli();
793         ic.driver = cs->myid;
794         ic.command = ISDN_STAT_RUN;
795         cs->iif.features |= addfeatures;
796         cs->iif.statcallb(&ic);
797         restore_flags(flags);
798         return 0;
799 }
800
801 void ll_stop(struct IsdnCardState *cs)
802 {
803         isdn_ctrl ic;
804
805         ic.command = ISDN_STAT_STOP;
806         ic.driver = cs->myid;
807         cs->iif.statcallb(&ic);
808         //      CallcFreeChan(cs);
809 }
810
811 static void ll_unload(struct IsdnCardState *cs)
812 {
813         isdn_ctrl ic;
814
815         ic.command = ISDN_STAT_UNLOAD;
816         ic.driver = cs->myid;
817         cs->iif.statcallb(&ic);
818         if (cs->status_buf)
819                 kfree(cs->status_buf);
820         cs->status_read = NULL;
821         cs->status_write = NULL;
822         cs->status_end = NULL;
823         kfree(cs->dlog);
824 }
825
826 static void closecard(int cardnr)
827 {
828         struct IsdnCardState *csta = cards[cardnr].cs;
829
830         if (csta->bcs->BC_Close != NULL) {
831                 csta->bcs->BC_Close(csta->bcs + 1);
832                 csta->bcs->BC_Close(csta->bcs);
833         }
834
835         skb_queue_purge(&csta->rq);
836         skb_queue_purge(&csta->sq);
837         if (csta->rcvbuf) {
838                 kfree(csta->rcvbuf);
839                 csta->rcvbuf = NULL;
840         }
841         if (csta->tx_skb) {
842                 dev_kfree_skb(csta->tx_skb);
843                 csta->tx_skb = NULL;
844         }
845         if (csta->DC_Close != NULL) {
846                 csta->DC_Close(csta);
847         }
848         if (csta->cardmsg)
849                 csta->cardmsg(csta, CARD_RELEASE, NULL);
850         if (csta->dbusytimer.function != NULL) // FIXME?
851                 del_timer(&csta->dbusytimer);
852         ll_unload(csta);
853 }
854
855 static int __devinit init_card(struct IsdnCardState *cs)
856 {
857         int irq_cnt, cnt = 3;
858         long flags;
859
860         if (!cs->irq)
861                 return cs->cardmsg(cs, CARD_INIT, NULL);
862         save_flags(flags);
863         cli();
864         irq_cnt = kstat_irqs(cs->irq);
865         printk(KERN_INFO "%s: IRQ %d count %d\n", CardType[cs->typ],
866                cs->irq, irq_cnt);
867         if (request_irq(cs->irq, cs->irq_func, cs->irq_flags, "HiSax", cs)) {
868                 printk(KERN_WARNING "HiSax: couldn't get interrupt %d\n",
869                        cs->irq);
870                 restore_flags(flags);
871                 return 1;
872         }
873         while (cnt) {
874                 cs->cardmsg(cs, CARD_INIT, NULL);
875                 sti();
876                 set_current_state(TASK_UNINTERRUPTIBLE);
877                 /* Timeout 10ms */
878                 schedule_timeout((10 * HZ) / 1000);
879                 restore_flags(flags);
880                 printk(KERN_INFO "%s: IRQ %d count %d\n",
881                        CardType[cs->typ], cs->irq, kstat_irqs(cs->irq));
882                 if (kstat_irqs(cs->irq) == irq_cnt) {
883                         printk(KERN_WARNING
884                                "%s: IRQ(%d) getting no interrupts during init %d\n",
885                                CardType[cs->typ], cs->irq, 4 - cnt);
886                         if (cnt == 1) {
887                                 free_irq(cs->irq, cs);
888                                 return 2;
889                         } else {
890                                 cs->cardmsg(cs, CARD_RESET, NULL);
891                                 cnt--;
892                         }
893                 } else {
894                         cs->cardmsg(cs, CARD_TEST, NULL);
895                         return 0;
896                 }
897         }
898         restore_flags(flags);
899         return 3;
900 }
901
902 static int __devinit checkcard(int cardnr, char *id, int *busy_flag)
903 {
904         long flags;
905         int ret = 0;
906         struct IsdnCard *card = cards + cardnr;
907         struct IsdnCardState *cs;
908
909         save_flags(flags);
910         cli();
911         cs = kmalloc(sizeof(struct IsdnCardState), GFP_ATOMIC);
912         if (!cs) {
913                 printk(KERN_WARNING
914                        "HiSax: No memory for IsdnCardState(card %d)\n",
915                        cardnr + 1);
916                 goto out;
917         }
918         memset(cs, 0, sizeof(struct IsdnCardState));
919         card->cs = cs;
920         cs->chanlimit = 2;      /* maximum B-channel number */
921         cs->logecho = 0;        /* No echo logging */
922         cs->cardnr = cardnr;
923         cs->debug = L1_DEB_WARN;
924         cs->HW_Flags = 0;
925         cs->busy_flag = busy_flag;
926         cs->irq_flags = I4L_IRQ_FLAG;
927 #if TEI_PER_CARD
928         if (card->protocol == ISDN_PTYPE_NI1)
929                 test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
930 #else
931         test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
932 #endif
933         cs->protocol = card->protocol;
934
935         if (card->typ <= 0 || card->typ > ISDN_CTYPE_COUNT) {
936                 printk(KERN_WARNING
937                        "HiSax: Card Type %d out of range\n", card->typ);
938                 goto outf_cs;
939         }
940         if (!(cs->dlog = kmalloc(MAX_DLOG_SPACE, GFP_ATOMIC))) {
941                 printk(KERN_WARNING
942                        "HiSax: No memory for dlog(card %d)\n", cardnr + 1);
943                 goto outf_cs;
944         }
945         if (!(cs->status_buf = kmalloc(HISAX_STATUS_BUFSIZE, GFP_ATOMIC))) {
946                 printk(KERN_WARNING
947                        "HiSax: No memory for status_buf(card %d)\n",
948                        cardnr + 1);
949                 goto outf_dlog;
950         }
951         cs->stlist = NULL;
952         cs->status_read = cs->status_buf;
953         cs->status_write = cs->status_buf;
954         cs->status_end = cs->status_buf + HISAX_STATUS_BUFSIZE - 1;
955         cs->typ = card->typ;
956         strcpy(cs->iif.id, id);
957         cs->iif.channels = 2;
958         cs->iif.maxbufsize = MAX_DATA_SIZE;
959         cs->iif.hl_hdrlen = MAX_HEADER_LEN;
960         cs->iif.features =
961                 ISDN_FEATURE_L2_X75I |
962                 ISDN_FEATURE_L2_HDLC |
963                 ISDN_FEATURE_L2_HDLC_56K |
964                 ISDN_FEATURE_L2_TRANS |
965                 ISDN_FEATURE_L3_TRANS |
966 #ifdef  CONFIG_HISAX_1TR6
967                 ISDN_FEATURE_P_1TR6 |
968 #endif
969 #ifdef  CONFIG_HISAX_EURO
970                 ISDN_FEATURE_P_EURO |
971 #endif
972 #ifdef  CONFIG_HISAX_NI1
973                 ISDN_FEATURE_P_NI1 |
974 #endif
975                 0;
976
977         cs->iif.command = HiSax_command;
978         cs->iif.writecmd = NULL;
979         cs->iif.writebuf_skb = HiSax_writebuf_skb;
980         cs->iif.readstat = HiSax_readstatus;
981         register_isdn(&cs->iif);
982         cs->myid = cs->iif.channels;
983         printk(KERN_INFO
984                "HiSax: Card %d Protocol %s Id=%s (%d)\n", cardnr + 1,
985                (card->protocol == ISDN_PTYPE_1TR6) ? "1TR6" :
986                (card->protocol == ISDN_PTYPE_EURO) ? "EDSS1" :
987                (card->protocol == ISDN_PTYPE_LEASED) ? "LEASED" :
988                (card->protocol == ISDN_PTYPE_NI1) ? "NI1" :
989                "NONE", cs->iif.id, cs->myid);
990         switch (card->typ) {
991 #if CARD_TELES0
992         case ISDN_CTYPE_16_0:
993         case ISDN_CTYPE_8_0:
994                 ret = setup_teles0(card);
995                 break;
996 #endif
997 #if CARD_TELES3
998         case ISDN_CTYPE_16_3:
999         case ISDN_CTYPE_PNP:
1000         case ISDN_CTYPE_TELESPCMCIA:
1001         case ISDN_CTYPE_COMPAQ_ISA:
1002                 ret = setup_teles3(card);
1003                 break;
1004 #endif
1005 #if CARD_S0BOX
1006         case ISDN_CTYPE_S0BOX:
1007                 ret = setup_s0box(card);
1008                 break;
1009 #endif
1010 #if CARD_TELESPCI
1011         case ISDN_CTYPE_TELESPCI:
1012                 ret = setup_telespci(card);
1013                 break;
1014 #endif
1015 #if CARD_AVM_A1
1016         case ISDN_CTYPE_A1:
1017                 ret = setup_avm_a1(card);
1018                 break;
1019 #endif
1020 #if CARD_AVM_A1_PCMCIA
1021         case ISDN_CTYPE_A1_PCMCIA:
1022                 ret = setup_avm_a1_pcmcia(card);
1023                 break;
1024 #endif
1025 #if CARD_FRITZPCI
1026         case ISDN_CTYPE_FRITZPCI:
1027                 ret = setup_avm_pcipnp(card);
1028                 break;
1029 #endif
1030 #if CARD_ELSA
1031         case ISDN_CTYPE_ELSA:
1032         case ISDN_CTYPE_ELSA_PNP:
1033         case ISDN_CTYPE_ELSA_PCMCIA:
1034         case ISDN_CTYPE_ELSA_PCI:
1035                 ret = setup_elsa(card);
1036                 break;
1037 #endif
1038 #if CARD_IX1MICROR2
1039         case ISDN_CTYPE_IX1MICROR2:
1040                 ret = setup_ix1micro(card);
1041                 break;
1042 #endif
1043 #if CARD_DIEHLDIVA
1044         case ISDN_CTYPE_DIEHLDIVA:
1045                 ret = setup_diva(card);
1046                 break;
1047 #endif
1048 #if CARD_ASUSCOM
1049         case ISDN_CTYPE_ASUSCOM:
1050                 ret = setup_asuscom(card);
1051                 break;
1052 #endif
1053 #if CARD_TELEINT
1054         case ISDN_CTYPE_TELEINT:
1055                 ret = setup_TeleInt(card);
1056                 break;
1057 #endif
1058 #if CARD_SEDLBAUER
1059         case ISDN_CTYPE_SEDLBAUER:
1060         case ISDN_CTYPE_SEDLBAUER_PCMCIA:
1061         case ISDN_CTYPE_SEDLBAUER_FAX:
1062                 ret = setup_sedlbauer(card);
1063                 break;
1064 #endif
1065 #if CARD_SPORTSTER
1066         case ISDN_CTYPE_SPORTSTER:
1067                 ret = setup_sportster(card);
1068                 break;
1069 #endif
1070 #if CARD_MIC
1071         case ISDN_CTYPE_MIC:
1072                 ret = setup_mic(card);
1073                 break;
1074 #endif
1075 #if CARD_NETJET_S
1076         case ISDN_CTYPE_NETJET_S:
1077                 ret = setup_netjet_s(card);
1078                 break;
1079 #endif
1080 #if CARD_HFCS
1081         case ISDN_CTYPE_TELES3C:
1082         case ISDN_CTYPE_ACERP10:
1083                 ret = setup_hfcs(card);
1084                 break;
1085 #endif
1086 #if CARD_HFC_PCI
1087         case ISDN_CTYPE_HFC_PCI:
1088                 ret = setup_hfcpci(card);
1089                 break;
1090 #endif
1091 #if CARD_HFC_SX
1092         case ISDN_CTYPE_HFC_SX:
1093                 ret = setup_hfcsx(card);
1094                 break;
1095 #endif
1096 #if CARD_NICCY
1097         case ISDN_CTYPE_NICCY:
1098                 ret = setup_niccy(card);
1099                 break;
1100 #endif
1101 #if CARD_AMD7930
1102         case ISDN_CTYPE_AMD7930:
1103                 ret = setup_amd7930(card);
1104                 break;
1105 #endif
1106 #if CARD_ISURF
1107         case ISDN_CTYPE_ISURF:
1108                 ret = setup_isurf(card);
1109                 break;
1110 #endif
1111 #if CARD_HSTSAPHIR
1112         case ISDN_CTYPE_HSTSAPHIR:
1113                 ret = setup_saphir(card);
1114                 break;
1115 #endif
1116 #if CARD_TESTEMU
1117         case ISDN_CTYPE_TESTEMU:
1118                 ret = setup_testemu(card);
1119                 break;
1120 #endif
1121 #if     CARD_BKM_A4T
1122         case ISDN_CTYPE_BKM_A4T:
1123                 ret = setup_bkm_a4t(card);
1124                 break;
1125 #endif
1126 #if     CARD_SCT_QUADRO
1127         case ISDN_CTYPE_SCT_QUADRO:
1128                 ret = setup_sct_quadro(card);
1129                 break;
1130 #endif
1131 #if CARD_GAZEL
1132         case ISDN_CTYPE_GAZEL:
1133                 ret = setup_gazel(card);
1134                 break;
1135 #endif
1136 #if CARD_W6692
1137         case ISDN_CTYPE_W6692:
1138                 ret = setup_w6692(card);
1139                 break;
1140 #endif
1141 #if CARD_NETJET_U
1142         case ISDN_CTYPE_NETJET_U:
1143                 ret = setup_netjet_u(card);
1144                 break;
1145 #endif
1146 #if CARD_FN_ENTERNOW_PCI
1147         case ISDN_CTYPE_ENTERNOW:
1148                 ret = setup_enternow_pci(card);
1149                 break;
1150 #endif
1151         case ISDN_CTYPE_DYNAMIC:
1152                 ret = 2;
1153                 break;
1154         default:
1155                 printk(KERN_WARNING
1156                        "HiSax: Support for %s Card not selected\n",
1157                        CardType[card->typ]);
1158                 ll_unload(cs);
1159                 goto outf_cs;
1160         }
1161         if (!ret) {
1162                 ll_unload(cs);
1163                 goto outf_cs;
1164         }
1165         if (!(cs->rcvbuf = kmalloc(MAX_DFRAME_LEN_L1, GFP_ATOMIC))) {
1166                 printk(KERN_WARNING "HiSax: No memory for isac rcvbuf\n");
1167                 ll_unload(cs);
1168                 goto outf_cs;
1169         }
1170         cs->rcvidx = 0;
1171         cs->tx_skb = NULL;
1172         cs->tx_cnt = 0;
1173         cs->event = 0;
1174         cs->tqueue.sync = 0;
1175         cs->tqueue.data = cs;
1176
1177         skb_queue_head_init(&cs->rq);
1178         skb_queue_head_init(&cs->sq);
1179
1180         init_bcstate(cs, 0);
1181         init_bcstate(cs, 1);
1182
1183         /* init_card only handles interrupts which are not */
1184         /* used here for the loadable driver */
1185         switch (card->typ) {
1186         case ISDN_CTYPE_DYNAMIC:
1187                 ret = 0;
1188                 break;
1189         default:
1190                 ret = init_card(cs);
1191                 break;
1192         }
1193         if (ret) {
1194                 closecard(cardnr);
1195                 ret = 0;
1196                 goto outf_cs;
1197         }
1198         init_tei(cs, cs->protocol);
1199         ret = CallcNewChan(cs);
1200         if (ret) {
1201                 closecard(cardnr);
1202                 ret = 0;
1203                 goto outf_cs;
1204         }
1205         /* ISAR needs firmware download first */
1206         if (!test_bit(HW_ISAR, &cs->HW_Flags))
1207                 ll_run(cs, 0);
1208
1209         ret = 1;
1210         goto out;
1211
1212  outf_dlog:
1213         kfree(cs->dlog);
1214  outf_cs:
1215         kfree(cs);
1216         card->cs = NULL;
1217  out:
1218         restore_flags(flags);
1219         return ret;
1220 }
1221
1222 void __devinit HiSax_shiftcards(int idx)
1223 {
1224         int i;
1225
1226         for (i = idx; i < (HISAX_MAX_CARDS - 1); i++)
1227                 memcpy(&cards[i], &cards[i + 1], sizeof(cards[i]));
1228 }
1229
1230 int __devinit HiSax_inithardware(int *busy_flag)
1231 {
1232         int foundcards = 0;
1233         int i = 0;
1234         int t = ',';
1235         int flg = 0;
1236         char *id;
1237         char *next_id = HiSax_id;
1238         char ids[20];
1239
1240         if (strchr(HiSax_id, ','))
1241                 t = ',';
1242         else if (strchr(HiSax_id, '%'))
1243                 t = '%';
1244
1245         while (i < nrcards) {
1246                 if (cards[i].typ < 1)
1247                         break;
1248                 id = next_id;
1249                 if ((next_id = strchr(id, t))) {
1250                         *next_id++ = 0;
1251                         strcpy(ids, id);
1252                         flg = i + 1;
1253                 } else {
1254                         next_id = id;
1255                         if (flg >= i)
1256                                 strcpy(ids, id);
1257                         else
1258                                 sprintf(ids, "%s%d", id, i);
1259                 }
1260                 if (checkcard(i, ids, busy_flag)) {
1261                         foundcards++;
1262                         i++;
1263                 } else {
1264                         /* make sure we don't oops the module */
1265                         if (cards[i].typ > 0 && cards[i].typ <= ISDN_CTYPE_COUNT) {
1266                                 printk(KERN_WARNING
1267                                         "HiSax: Card %s not installed !\n",
1268                                         CardType[cards[i].typ]);
1269                         }
1270                         HiSax_shiftcards(i);
1271                         nrcards--;
1272                 }
1273         }
1274         return foundcards;
1275 }
1276
1277 void HiSax_closecard(int cardnr)
1278 {
1279         int i, last = nrcards - 1;
1280
1281         if (cardnr > last)
1282                 return;
1283         if (cards[cardnr].cs) {
1284                 ll_stop(cards[cardnr].cs);
1285                 release_tei(cards[cardnr].cs);
1286                 CallcFreeChan(cards[cardnr].cs);
1287
1288                 closecard(cardnr);
1289                 if (cards[cardnr].cs->irq)
1290                         free_irq(cards[cardnr].cs->irq, cards[cardnr].cs);
1291                 kfree((void *) cards[cardnr].cs);
1292                 cards[cardnr].cs = NULL;
1293         }
1294         i = cardnr;
1295         while (i <= last) {
1296                 cards[i] = cards[i + 1];
1297                 i++;
1298         }
1299         nrcards--;
1300 }
1301
1302 void HiSax_reportcard(int cardnr, int sel)
1303 {
1304         struct IsdnCardState *cs = cards[cardnr].cs;
1305
1306         printk(KERN_DEBUG "HiSax: reportcard No %d\n", cardnr + 1);
1307         printk(KERN_DEBUG "HiSax: Type %s\n", CardType[cs->typ]);
1308         printk(KERN_DEBUG "HiSax: debuglevel %x\n", cs->debug);
1309         printk(KERN_DEBUG "HiSax: HiSax_reportcard address 0x%lX\n",
1310                (ulong) & HiSax_reportcard);
1311         printk(KERN_DEBUG "HiSax: cs 0x%lX\n", (ulong) cs);
1312         printk(KERN_DEBUG "HiSax: HW_Flags %lx bc0 flg %lx bc1 flg %lx\n",
1313                cs->HW_Flags, cs->bcs[0].Flag, cs->bcs[1].Flag);
1314         printk(KERN_DEBUG "HiSax: bcs 0 mode %d ch%d\n",
1315                cs->bcs[0].mode, cs->bcs[0].channel);
1316         printk(KERN_DEBUG "HiSax: bcs 1 mode %d ch%d\n",
1317                cs->bcs[1].mode, cs->bcs[1].channel);
1318 #ifdef ERROR_STATISTIC
1319         printk(KERN_DEBUG "HiSax: dc errors(rx,crc,tx) %d,%d,%d\n",
1320                cs->err_rx, cs->err_crc, cs->err_tx);
1321         printk(KERN_DEBUG
1322                "HiSax: bc0 errors(inv,rdo,crc,tx) %d,%d,%d,%d\n",
1323                cs->bcs[0].err_inv, cs->bcs[0].err_rdo, cs->bcs[0].err_crc,
1324                cs->bcs[0].err_tx);
1325         printk(KERN_DEBUG
1326                "HiSax: bc1 errors(inv,rdo,crc,tx) %d,%d,%d,%d\n",
1327                cs->bcs[1].err_inv, cs->bcs[1].err_rdo, cs->bcs[1].err_crc,
1328                cs->bcs[1].err_tx);
1329         if (sel == 99) {
1330                 cs->err_rx  = 0;
1331                 cs->err_crc = 0;
1332                 cs->err_tx  = 0;
1333                 cs->bcs[0].err_inv = 0;
1334                 cs->bcs[0].err_rdo = 0;
1335                 cs->bcs[0].err_crc = 0;
1336                 cs->bcs[0].err_tx  = 0;
1337                 cs->bcs[1].err_inv = 0;
1338                 cs->bcs[1].err_rdo = 0;
1339                 cs->bcs[1].err_crc = 0;
1340                 cs->bcs[1].err_tx  = 0;
1341         }
1342 #endif
1343 }
1344
1345 static int __init HiSax_init(void)
1346 {
1347         int i, retval;
1348 #ifdef MODULE
1349         int j;
1350         int nzproto = 0;
1351 #endif
1352
1353         HiSaxVersion();
1354         retval = CallcNew();
1355         if (retval)
1356                 goto out;
1357         retval = Isdnl3New();
1358         if (retval)
1359                 goto out_callc;
1360         retval = Isdnl2New();
1361         if (retval)
1362                 goto out_isdnl3;
1363         retval = TeiNew();
1364         if (retval)
1365                 goto out_isdnl2;
1366         retval = Isdnl1New();
1367         if (retval)
1368                 goto out_tei;
1369
1370 #ifdef MODULE
1371         if (!type[0]) {
1372                 /* We 'll register drivers later, but init basic functions */
1373                 for (i = 0; i < HISAX_MAX_CARDS; i++)
1374                         cards[i].typ = 0;
1375                 return 0;
1376         }
1377 #ifdef CONFIG_HISAX_ELSA
1378         if (type[0] == ISDN_CTYPE_ELSA_PCMCIA) {
1379                 /* we have exported  and return in this case */
1380                 return 0;
1381         }
1382 #endif
1383 #ifdef CONFIG_HISAX_SEDLBAUER
1384         if (type[0] == ISDN_CTYPE_SEDLBAUER_PCMCIA) {
1385                 /* we have to export  and return in this case */
1386                 return 0;
1387         }
1388 #endif
1389 #ifdef CONFIG_HISAX_AVM_A1_PCMCIA
1390         if (type[0] == ISDN_CTYPE_A1_PCMCIA) {
1391                 /* we have to export  and return in this case */
1392                 return 0;
1393         }
1394 #endif
1395 #ifdef CONFIG_HISAX_HFC_SX
1396         if (type[0] == ISDN_CTYPE_HFC_SP_PCMCIA) {
1397                 /* we have to export  and return in this case */
1398                 return 0;
1399         }
1400 #endif
1401 #endif
1402         nrcards = 0;
1403 #ifdef MODULE
1404         if (id)                 /* If id= string used */
1405                 HiSax_id = id;
1406         for (i = j = 0; j < HISAX_MAX_CARDS; i++) {
1407                 cards[j].typ = type[i];
1408                 if (protocol[i]) {
1409                         cards[j].protocol = protocol[i];
1410                         nzproto++;
1411                 } else {
1412                         cards[j].protocol = DEFAULT_PROTO;
1413                 }
1414                 switch (type[i]) {
1415                 case ISDN_CTYPE_16_0:
1416                         cards[j].para[0] = irq[i];
1417                         cards[j].para[1] = mem[i];
1418                         cards[j].para[2] = io[i];
1419                         break;
1420
1421                 case ISDN_CTYPE_8_0:
1422                         cards[j].para[0] = irq[i];
1423                         cards[j].para[1] = mem[i];
1424                         break;
1425
1426 #ifdef IO0_IO1
1427                 case ISDN_CTYPE_PNP:
1428                 case ISDN_CTYPE_NICCY:
1429                         cards[j].para[0] = irq[i];
1430                         cards[j].para[1] = io0[i];
1431                         cards[j].para[2] = io1[i];
1432                         break;
1433                 case ISDN_CTYPE_COMPAQ_ISA:
1434                         cards[j].para[0] = irq[i];
1435                         cards[j].para[1] = io0[i];
1436                         cards[j].para[2] = io1[i];
1437                         cards[j].para[3] = io[i];
1438                         break;
1439 #endif
1440                 case ISDN_CTYPE_ELSA:
1441                 case ISDN_CTYPE_HFC_PCI:
1442                         cards[j].para[0] = io[i];
1443                         break;
1444                 case ISDN_CTYPE_16_3:
1445                 case ISDN_CTYPE_TELESPCMCIA:
1446                 case ISDN_CTYPE_A1:
1447                 case ISDN_CTYPE_A1_PCMCIA:
1448                 case ISDN_CTYPE_ELSA_PNP:
1449                 case ISDN_CTYPE_ELSA_PCMCIA:
1450                 case ISDN_CTYPE_IX1MICROR2:
1451                 case ISDN_CTYPE_DIEHLDIVA:
1452                 case ISDN_CTYPE_ASUSCOM:
1453                 case ISDN_CTYPE_TELEINT:
1454                 case ISDN_CTYPE_SEDLBAUER:
1455                 case ISDN_CTYPE_SEDLBAUER_PCMCIA:
1456                 case ISDN_CTYPE_SEDLBAUER_FAX:
1457                 case ISDN_CTYPE_SPORTSTER:
1458                 case ISDN_CTYPE_MIC:
1459                 case ISDN_CTYPE_TELES3C:
1460                 case ISDN_CTYPE_ACERP10:
1461                 case ISDN_CTYPE_S0BOX:
1462                 case ISDN_CTYPE_FRITZPCI:
1463                 case ISDN_CTYPE_HSTSAPHIR:
1464                 case ISDN_CTYPE_GAZEL:
1465                 case ISDN_CTYPE_HFC_SX:
1466                 case ISDN_CTYPE_HFC_SP_PCMCIA:
1467                         cards[j].para[0] = irq[i];
1468                         cards[j].para[1] = io[i];
1469                         break;
1470                 case ISDN_CTYPE_ISURF:
1471                         cards[j].para[0] = irq[i];
1472                         cards[j].para[1] = io[i];
1473                         cards[j].para[2] = mem[i];
1474                         break;
1475                 case ISDN_CTYPE_ELSA_PCI:
1476                 case ISDN_CTYPE_NETJET_S:
1477                 case ISDN_CTYPE_AMD7930:
1478                 case ISDN_CTYPE_TELESPCI:
1479                 case ISDN_CTYPE_W6692:
1480                 case ISDN_CTYPE_NETJET_U:
1481                         break;
1482                 case ISDN_CTYPE_BKM_A4T:
1483                         break;
1484                 case ISDN_CTYPE_SCT_QUADRO:
1485                         if (irq[i]) {
1486                                 cards[j].para[0] = irq[i];
1487                         } else {
1488                                 /* QUADRO is a 4 BRI card */
1489                                 cards[j++].para[0] = 1;
1490                                 /* we need to check if further cards can be added */
1491                                 if (j < HISAX_MAX_CARDS) {
1492                                         cards[j].typ = ISDN_CTYPE_SCT_QUADRO;
1493                                         cards[j].protocol = protocol[i];
1494                                         cards[j++].para[0] = 2;
1495                                 }
1496                                 if (j < HISAX_MAX_CARDS) {
1497                                         cards[j].typ = ISDN_CTYPE_SCT_QUADRO;
1498                                         cards[j].protocol = protocol[i];
1499                                         cards[j++].para[0] = 3;
1500                                 }
1501                                 if (j < HISAX_MAX_CARDS) {
1502                                         cards[j].typ = ISDN_CTYPE_SCT_QUADRO;
1503                                         cards[j].protocol = protocol[i];
1504                                         cards[j].para[0] = 4;
1505                                 }
1506                         }
1507                         break;
1508                 }
1509                 j++;
1510         }
1511         if (!nzproto) {
1512                 printk(KERN_WARNING
1513                        "HiSax: Warning - no protocol specified\n");
1514                 printk(KERN_WARNING "HiSax: using protocol %s\n",
1515                        DEFAULT_PROTO_NAME);
1516         }
1517 #endif
1518         if (!HiSax_id)
1519                 HiSax_id = HiSaxID;
1520         if (!HiSaxID[0])
1521                 strcpy(HiSaxID, "HiSax");
1522         for (i = 0; i < HISAX_MAX_CARDS; i++)
1523                 if (cards[i].typ > 0)
1524                         nrcards++;
1525         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1526                nrcards, (nrcards > 1) ? "s" : "");
1527
1528         /* Install only, if at least one card found */
1529         if (!HiSax_inithardware(NULL))
1530                 return -ENODEV;
1531         return 0;
1532
1533  out_tei:
1534         TeiFree();
1535  out_isdnl2:
1536         Isdnl2Free();
1537  out_isdnl3:
1538         Isdnl3Free();
1539  out_callc:
1540         CallcFree();
1541  out:
1542         return retval;
1543 }
1544
1545 static void __exit HiSax_exit(void)
1546 {
1547         int cardnr = nrcards - 1;
1548         long flags;
1549
1550         save_flags(flags);
1551         cli();
1552         while (cardnr >= 0)
1553                 HiSax_closecard(cardnr--);
1554         Isdnl1Free();
1555         TeiFree();
1556         Isdnl2Free();
1557         Isdnl3Free();
1558         CallcFree();
1559         restore_flags(flags);
1560         printk(KERN_INFO "HiSax module removed\n");
1561 }
1562
1563 #ifdef CONFIG_HISAX_ELSA
1564 int elsa_init_pcmcia(void *pcm_iob, int pcm_irq, int *busy_flag, int prot)
1565 {
1566 #ifdef MODULE
1567         int i;
1568
1569         nrcards = 0;
1570         /* Initialize all structs, even though we only accept
1571            two pcmcia cards
1572         */
1573         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1574                 cards[i].para[0] = irq[i];
1575                 cards[i].para[1] = io[i];
1576                 cards[i].typ = type[i];
1577                 if (protocol[i]) {
1578                         cards[i].protocol = protocol[i];
1579                 } else {
1580                         cards[i].protocol = DEFAULT_PROTO;
1581                 }
1582         }
1583         cards[0].para[0] = pcm_irq;
1584         cards[0].para[1] = (int) pcm_iob;
1585         cards[0].protocol = prot;
1586         cards[0].typ = ISDN_CTYPE_ELSA_PCMCIA;
1587
1588         if (!HiSax_id)
1589                 HiSax_id = HiSaxID;
1590         if (!HiSaxID[0])
1591                 strcpy(HiSaxID, "HiSax");
1592         for (i = 0; i < HISAX_MAX_CARDS; i++)
1593                 if (cards[i].typ > 0)
1594                         nrcards++;
1595         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1596                nrcards, (nrcards > 1) ? "s" : "");
1597
1598         if (!HiSax_inithardware(busy_flag))
1599                 return -ENODEV;
1600         printk(KERN_NOTICE "HiSax: module installed\n");
1601 #endif
1602         return 0;
1603 }
1604 #endif
1605
1606 #ifdef CONFIG_HISAX_HFC_SX
1607 int hfc_init_pcmcia(void *pcm_iob, int pcm_irq, int *busy_flag, int prot)
1608 {
1609 #ifdef MODULE
1610         int i;
1611
1612         nrcards = 0;
1613         /* Initialize all structs, even though we only accept
1614            two pcmcia cards
1615         */
1616         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1617                 cards[i].para[0] = irq[i];
1618                 cards[i].para[1] = io[i];
1619                 cards[i].typ = type[i];
1620                 if (protocol[i]) {
1621                         cards[i].protocol = protocol[i];
1622                 } else {
1623                         cards[i].protocol = DEFAULT_PROTO;
1624                 }
1625         }
1626         cards[0].para[0] = pcm_irq;
1627         cards[0].para[1] = (int) pcm_iob;
1628         cards[0].protocol = prot;
1629         cards[0].typ = ISDN_CTYPE_HFC_SP_PCMCIA;
1630
1631         if (!HiSax_id)
1632                 HiSax_id = HiSaxID;
1633         if (!HiSaxID[0])
1634                 strcpy(HiSaxID, "HiSax");
1635         for (i = 0; i < HISAX_MAX_CARDS; i++)
1636                 if (cards[i].typ > 0)
1637                         nrcards++;
1638         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1639                nrcards, (nrcards > 1) ? "s" : "");
1640
1641         if (!HiSax_inithardware(busy_flag))
1642                 return -ENODEV;
1643         printk(KERN_NOTICE "HiSax: module installed\n");
1644 #endif
1645         return 0;
1646 }
1647 #endif
1648
1649 #ifdef CONFIG_HISAX_SEDLBAUER
1650 int sedl_init_pcmcia(void *pcm_iob, int pcm_irq, int *busy_flag, int prot)
1651 {
1652 #ifdef MODULE
1653         int i;
1654
1655         nrcards = 0;
1656         /* Initialize all structs, even though we only accept
1657            two pcmcia cards
1658         */
1659         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1660                 cards[i].para[0] = irq[i];
1661                 cards[i].para[1] = io[i];
1662                 cards[i].typ = type[i];
1663                 if (protocol[i]) {
1664                         cards[i].protocol = protocol[i];
1665                 } else {
1666                         cards[i].protocol = DEFAULT_PROTO;
1667                 }
1668         }
1669         cards[0].para[0] = pcm_irq;
1670         cards[0].para[1] = (int) pcm_iob;
1671         cards[0].protocol = prot;
1672         cards[0].typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
1673
1674         if (!HiSax_id)
1675                 HiSax_id = HiSaxID;
1676         if (!HiSaxID[0])
1677                 strcpy(HiSaxID, "HiSax");
1678         for (i = 0; i < HISAX_MAX_CARDS; i++)
1679                 if (cards[i].typ > 0)
1680                         nrcards++;
1681         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1682                nrcards, (nrcards > 1) ? "s" : "");
1683
1684         if (!HiSax_inithardware(busy_flag))
1685                 return -ENODEV;
1686         printk(KERN_NOTICE "HiSax: module installed\n");
1687 #endif
1688         return 0;
1689 }
1690 #endif
1691
1692 #ifdef CONFIG_HISAX_AVM_A1_PCMCIA
1693 int avm_a1_init_pcmcia(void *pcm_iob, int pcm_irq, int *busy_flag, int prot)
1694 {
1695 #ifdef MODULE
1696         int i;
1697
1698         nrcards = 0;
1699         /* Initialize all structs, even though we only accept
1700            two pcmcia cards
1701         */
1702         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1703                 cards[i].para[0] = irq[i];
1704                 cards[i].para[1] = io[i];
1705                 cards[i].typ = type[i];
1706                 if (protocol[i]) {
1707                         cards[i].protocol = protocol[i];
1708                 } else {
1709                         cards[i].protocol = DEFAULT_PROTO;
1710                 }
1711         }
1712         cards[0].para[0] = pcm_irq;
1713         cards[0].para[1] = (int) pcm_iob;
1714         cards[0].protocol = prot;
1715         cards[0].typ = ISDN_CTYPE_A1_PCMCIA;
1716
1717         if (!HiSax_id)
1718                 HiSax_id = HiSaxID;
1719         if (!HiSaxID[0])
1720                 strcpy(HiSaxID, "HiSax");
1721         for (i = 0; i < HISAX_MAX_CARDS; i++)
1722                 if (cards[i].typ > 0)
1723                         nrcards++;
1724         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1725                nrcards, (nrcards > 1) ? "s" : "");
1726
1727         if (!HiSax_inithardware(busy_flag))
1728                 return -ENODEV;
1729         printk(KERN_NOTICE "HiSax: module installed\n");
1730 #endif
1731         return 0;
1732 }
1733 #endif
1734
1735 int __devinit hisax_init_pcmcia(void *pcm_iob, int *busy_flag,
1736                                 struct IsdnCard *card)
1737 {
1738         u_char ids[16];
1739         int ret = -1;
1740
1741         cards[nrcards] = *card;
1742         if (nrcards)
1743                 sprintf(ids, "HiSax%d", nrcards);
1744         else
1745                 sprintf(ids, "HiSax");
1746         if (!checkcard(nrcards, ids, busy_flag)) {
1747                 return -1;
1748         }
1749         ret = nrcards;
1750         nrcards++;
1751         return ret;
1752 }
1753
1754 #include "hisax_if.h"
1755
1756 EXPORT_SYMBOL(hisax_register);
1757 EXPORT_SYMBOL(hisax_unregister);
1758
1759 static void hisax_d_l1l2(struct hisax_if *ifc, int pr, void *arg);
1760 static void hisax_b_l1l2(struct hisax_if *ifc, int pr, void *arg);
1761 static void hisax_d_l2l1(struct PStack *st, int pr, void *arg);
1762 static void hisax_b_l2l1(struct PStack *st, int pr, void *arg);
1763 static int hisax_cardmsg(struct IsdnCardState *cs, int mt, void *arg);
1764 static int hisax_bc_setstack(struct PStack *st, struct BCState *bcs);
1765 static void hisax_bc_close(struct BCState *bcs);
1766 static void hisax_bh(struct IsdnCardState *cs);
1767 static void EChannel_proc_rcv(struct hisax_d_if *d_if);
1768
1769 int hisax_register(struct hisax_d_if *hisax_d_if, struct hisax_b_if *b_if[],
1770                    char *name, int protocol)
1771 {
1772         int i, retval;
1773         char id[20];
1774         struct IsdnCardState *cs;
1775
1776         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1777                 if (!cards[i].typ)
1778                         break;
1779         }
1780
1781         if (i >= HISAX_MAX_CARDS)
1782                 return -EBUSY;
1783
1784         cards[i].typ = ISDN_CTYPE_DYNAMIC;
1785         cards[i].protocol = protocol;
1786         sprintf(id, "%s%d", name, i);
1787         nrcards++;
1788         retval = checkcard(i, id, 0);
1789         if (retval == 0) { // yuck
1790                 cards[i].typ = 0;
1791                 nrcards--;
1792                 return retval;
1793         }
1794         cs = cards[i].cs;
1795         hisax_d_if->cs = cs;
1796         cs->hw.hisax_d_if = hisax_d_if;
1797         cs->cardmsg = hisax_cardmsg;
1798         cs->tqueue.routine = (void *) (void *) hisax_bh;
1799         cs->channel[0].d_st->l2.l2l1 = hisax_d_l2l1;
1800         for (i = 0; i < 2; i++) {
1801                 cs->bcs[i].BC_SetStack = hisax_bc_setstack;
1802                 cs->bcs[i].BC_Close = hisax_bc_close;
1803
1804                 b_if[i]->ifc.l1l2 = hisax_b_l1l2;
1805
1806                 hisax_d_if->b_if[i] = b_if[i];
1807         }
1808         hisax_d_if->ifc.l1l2 = hisax_d_l1l2;
1809         skb_queue_head_init(&hisax_d_if->erq);
1810         clear_bit(0, &hisax_d_if->ph_state);
1811         
1812         return 0;
1813 }
1814
1815 void hisax_unregister(struct hisax_d_if *hisax_d_if)
1816 {
1817         cards[hisax_d_if->cs->cardnr].typ = 0;
1818         HiSax_closecard(hisax_d_if->cs->cardnr);
1819         skb_queue_purge(&hisax_d_if->erq);
1820 }
1821
1822 #include "isdnl1.h"
1823
1824 static void hisax_sched_event(struct IsdnCardState *cs, int event)
1825 {
1826         cs->event |= 1 << event;
1827         queue_task(&cs->tqueue, &tq_immediate);
1828         mark_bh(IMMEDIATE_BH);
1829 }
1830
1831 static void hisax_bh(struct IsdnCardState *cs)
1832 {
1833         struct PStack *st;
1834         int pr;
1835
1836         if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
1837                 DChannel_proc_rcv(cs);
1838         if (test_and_clear_bit(E_RCVBUFREADY, &cs->event))
1839                 EChannel_proc_rcv(cs->hw.hisax_d_if);
1840         if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
1841                 if (test_bit(0, &cs->hw.hisax_d_if->ph_state))
1842                         pr = PH_ACTIVATE | INDICATION;
1843                 else
1844                         pr = PH_DEACTIVATE | INDICATION;
1845                 for (st = cs->stlist; st; st = st->next)
1846                         st->l1.l1l2(st, pr, NULL);
1847                 
1848         }
1849 }
1850
1851 static void hisax_b_sched_event(struct BCState *bcs, int event)
1852 {
1853         bcs->event |= 1 << event;
1854         queue_task(&bcs->tqueue, &tq_immediate);
1855         mark_bh(IMMEDIATE_BH);
1856 }
1857
1858 static inline void D_L2L1(struct hisax_d_if *d_if, int pr, void *arg)
1859 {
1860         struct hisax_if *ifc = (struct hisax_if *) d_if;
1861         ifc->l2l1(ifc, pr, arg);
1862 }
1863
1864 static inline void B_L2L1(struct hisax_b_if *b_if, int pr, void *arg)
1865 {
1866         struct hisax_if *ifc = (struct hisax_if *) b_if;
1867         ifc->l2l1(ifc, pr, arg);
1868 }
1869
1870 static void hisax_d_l1l2(struct hisax_if *ifc, int pr, void *arg)
1871 {
1872         struct hisax_d_if *d_if = (struct hisax_d_if *) ifc;
1873         struct IsdnCardState *cs = d_if->cs;
1874         struct PStack *st;
1875         struct sk_buff *skb;
1876
1877         switch (pr) {
1878         case PH_ACTIVATE | INDICATION:
1879                 set_bit(0, &d_if->ph_state);
1880                 hisax_sched_event(cs, D_L1STATECHANGE);
1881                 break;
1882         case PH_DEACTIVATE | INDICATION:
1883                 clear_bit(0, &d_if->ph_state);
1884                 hisax_sched_event(cs, D_L1STATECHANGE);
1885                 break;
1886         case PH_DATA | INDICATION:
1887                 skb_queue_tail(&cs->rq, arg);
1888                 hisax_sched_event(cs, D_RCVBUFREADY);
1889                 break;
1890         case PH_DATA | CONFIRM:
1891                 skb = skb_dequeue(&cs->sq);
1892                 if (skb) {
1893                         D_L2L1(d_if, PH_DATA | REQUEST, skb);
1894                         break;
1895                 }
1896                 clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
1897                 for (st = cs->stlist; st; st = st->next) {
1898                         if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags)) {
1899                                 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1900                                 break;
1901                         }
1902                 }
1903                 break;
1904         case PH_DATA_E | INDICATION:
1905                 skb_queue_tail(&d_if->erq, arg);
1906                 hisax_sched_event(cs, E_RCVBUFREADY);
1907                 break;
1908         default:
1909                 printk("pr %#x\n", pr);
1910                 break;
1911         }
1912 }
1913
1914 static void hisax_b_l1l2(struct hisax_if *ifc, int pr, void *arg)
1915 {
1916         struct hisax_b_if *b_if = (struct hisax_b_if *) ifc;
1917         struct BCState *bcs = b_if->bcs;
1918         struct PStack *st = bcs->st;
1919         struct sk_buff *skb;
1920
1921         // FIXME use isdnl1?
1922         switch (pr) {
1923         case PH_ACTIVATE | INDICATION:
1924                 st->l1.l1l2(st, pr, NULL);
1925                 break;
1926         case PH_DEACTIVATE | INDICATION:
1927                 st->l1.l1l2(st, pr, NULL);
1928                 clear_bit(BC_FLG_BUSY, &bcs->Flag);
1929                 skb_queue_purge(&bcs->squeue);
1930                 bcs->hw.b_if = NULL;
1931                 break;
1932         case PH_DATA | INDICATION:
1933                 skb_queue_tail(&bcs->rqueue, arg);
1934                 hisax_b_sched_event(bcs, B_RCVBUFREADY);
1935                 break;
1936         case PH_DATA | CONFIRM:
1937                 bcs->tx_cnt -= (int) arg;
1938                 if (bcs->st->lli.l1writewakeup)
1939                         bcs->st->lli.l1writewakeup(bcs->st, (int) arg);
1940                 skb = skb_dequeue(&bcs->squeue);
1941                 if (skb) {
1942                         B_L2L1(b_if, PH_DATA | REQUEST, skb);
1943                         break;
1944                 }
1945                 clear_bit(BC_FLG_BUSY, &bcs->Flag);
1946                 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags)) {
1947                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1948                 }
1949                 break;
1950         default:
1951                 printk("hisax_b_l1l2 pr %#x\n", pr);
1952                 break;
1953         }
1954 }
1955
1956 static void hisax_d_l2l1(struct PStack *st, int pr, void *arg)
1957 {
1958         struct IsdnCardState *cs = st->l1.hardware;
1959         struct hisax_d_if *hisax_d_if = cs->hw.hisax_d_if;
1960         struct sk_buff *skb = arg;
1961
1962         switch (pr) {
1963         case PH_DATA | REQUEST:
1964         case PH_PULL | INDICATION:
1965                 if (cs->debug & DEB_DLOG_HEX)
1966                         LogFrame(cs, skb->data, skb->len);
1967                 if (cs->debug & DEB_DLOG_VERBOSE)
1968                         dlogframe(cs, skb, 0);
1969                 Logl2Frame(cs, skb, "PH_DATA_REQ", 0);
1970                 // FIXME lock?
1971                 if (!test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags))
1972                         D_L2L1(hisax_d_if, PH_DATA | REQUEST, skb);
1973                 else
1974                         skb_queue_tail(&cs->sq, skb);
1975                 break;
1976         case PH_PULL | REQUEST:
1977                 if (!test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
1978                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1979                 else
1980                         set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1981                 break;
1982         default:
1983                 D_L2L1(hisax_d_if, pr, arg);
1984                 break;
1985         }
1986 }
1987
1988 static int hisax_cardmsg(struct IsdnCardState *cs, int mt, void *arg)
1989 {
1990         return 0;
1991 }
1992
1993 static void hisax_b_l2l1(struct PStack *st, int pr, void *arg)
1994 {
1995         struct BCState *bcs = st->l1.bcs;
1996         struct hisax_b_if *b_if = bcs->hw.b_if;
1997
1998         switch (pr) {
1999         case PH_ACTIVATE | REQUEST:
2000                 B_L2L1(b_if, pr, (void *) st->l1.mode);
2001                 break;
2002         case PH_DATA | REQUEST:
2003         case PH_PULL | INDICATION:
2004                 // FIXME lock?
2005                 if (!test_and_set_bit(BC_FLG_BUSY, &bcs->Flag)) {
2006                         B_L2L1(b_if, PH_DATA | REQUEST, arg);
2007                 } else {
2008                         skb_queue_tail(&bcs->squeue, arg);
2009                 }
2010                 break;
2011         case PH_PULL | REQUEST:
2012                 if (!test_bit(BC_FLG_BUSY, &bcs->Flag))
2013                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
2014                 else
2015                         set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
2016                 break;
2017         case PH_DEACTIVATE | REQUEST:
2018                 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
2019                 skb_queue_purge(&bcs->squeue);
2020         default:
2021                 B_L2L1(b_if, pr, arg);
2022                 break;
2023         }
2024 }
2025
2026 static int hisax_bc_setstack(struct PStack *st, struct BCState *bcs)
2027 {
2028         struct IsdnCardState *cs = st->l1.hardware;
2029         struct hisax_d_if *hisax_d_if = cs->hw.hisax_d_if;
2030
2031         bcs->channel = st->l1.bc;
2032
2033         bcs->hw.b_if = hisax_d_if->b_if[st->l1.bc];
2034         hisax_d_if->b_if[st->l1.bc]->bcs = bcs;
2035
2036         st->l1.bcs = bcs;
2037         st->l2.l2l1 = hisax_b_l2l1;
2038         setstack_manager(st);
2039         bcs->st = st;
2040         setstack_l1_B(st);
2041         skb_queue_head_init(&bcs->rqueue);
2042         skb_queue_head_init(&bcs->squeue);
2043         return 0;
2044 }
2045
2046 static void hisax_bc_close(struct BCState *bcs)
2047 {
2048         struct hisax_b_if *b_if = bcs->hw.b_if;
2049
2050         if (b_if)
2051                 B_L2L1(b_if, PH_DEACTIVATE | REQUEST, NULL);
2052 }
2053
2054 static void EChannel_proc_rcv(struct hisax_d_if *d_if)
2055 {
2056         struct IsdnCardState *cs = d_if->cs;
2057         u_char *ptr;
2058         struct sk_buff *skb;
2059
2060         while ((skb = skb_dequeue(&d_if->erq)) != NULL) {
2061                 if (cs->debug & DEB_DLOG_HEX) {
2062                         ptr = cs->dlog;
2063                         if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
2064                                 *ptr++ = 'E';
2065                                 *ptr++ = 'C';
2066                                 *ptr++ = 'H';
2067                                 *ptr++ = 'O';
2068                                 *ptr++ = ':';
2069                                 ptr += QuickHex(ptr, skb->data, skb->len);
2070                                 ptr--;
2071                                 *ptr++ = '\n';
2072                                 *ptr = 0;
2073                                 HiSax_putstatus(cs, NULL, cs->dlog);
2074                         } else
2075                                 HiSax_putstatus(cs, "LogEcho: ",
2076                                                 "warning Frame too big (%d)",
2077                                                 skb->len);
2078                 }
2079                 dev_kfree_skb_any(skb);
2080         }
2081 }
2082
2083 void HiSax_mod_dec_use_count(struct IsdnCardState *cs)
2084 {
2085         struct module *mod;
2086
2087         if (cs && cs->cardmsg == hisax_cardmsg) {
2088                 mod = cs->hw.hisax_d_if->owner;
2089                 if (mod)
2090                         __MOD_DEC_USE_COUNT(mod);
2091         } else {
2092                 MOD_DEC_USE_COUNT;
2093         }
2094 }
2095
2096 void HiSax_mod_inc_use_count(struct IsdnCardState *cs)
2097 {
2098         struct module *mod;
2099
2100         if (cs && cs->cardmsg == hisax_cardmsg) {
2101                 mod = cs->hw.hisax_d_if->owner;
2102                 if (mod)
2103                 // hope we do win the race...
2104                         try_inc_mod_count(mod);
2105         } else {
2106                 MOD_INC_USE_COUNT;
2107         }
2108 }
2109
2110 #include <linux/pci.h>
2111
2112 static struct pci_device_id hisax_pci_tbl[] __initdata = {
2113 #ifdef CONFIG_HISAX_FRITZPCI
2114         {PCI_VENDOR_ID_AVM,      PCI_DEVICE_ID_AVM_A1,           PCI_ANY_ID, PCI_ANY_ID},
2115 #endif
2116 #ifdef CONFIG_HISAX_DIEHLDIVA
2117         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA20,     PCI_ANY_ID, PCI_ANY_ID},
2118         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA20_U,   PCI_ANY_ID, PCI_ANY_ID},
2119         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA201,    PCI_ANY_ID, PCI_ANY_ID},
2120 //#########################################################################################     
2121         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA202,    PCI_ANY_ID, PCI_ANY_ID},
2122 //#########################################################################################     
2123 #endif
2124 #ifdef CONFIG_HISAX_ELSA
2125         {PCI_VENDOR_ID_ELSA,     PCI_DEVICE_ID_ELSA_MICROLINK,   PCI_ANY_ID, PCI_ANY_ID},
2126         {PCI_VENDOR_ID_ELSA,     PCI_DEVICE_ID_ELSA_QS3000,      PCI_ANY_ID, PCI_ANY_ID},
2127 #endif
2128 #ifdef CONFIG_HISAX_GAZEL
2129         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_R685,         PCI_ANY_ID, PCI_ANY_ID},
2130         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_R753,         PCI_ANY_ID, PCI_ANY_ID},
2131         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_DJINN_ITOO,   PCI_ANY_ID, PCI_ANY_ID},
2132 #endif
2133 #ifdef CONFIG_HISAX_QUADRO
2134         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_9050,         PCI_ANY_ID, PCI_ANY_ID},
2135 #endif
2136 #ifdef CONFIG_HISAX_NICCY
2137         {PCI_VENDOR_ID_SATSAGEM, PCI_DEVICE_ID_SATSAGEM_NICCY,   PCI_ANY_ID,PCI_ANY_ID},
2138 #endif
2139 #ifdef CONFIG_HISAX_SEDLBAUER
2140         {PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_100,     PCI_ANY_ID,PCI_ANY_ID},
2141 #endif
2142 #if defined(CONFIG_HISAX_NETJET) || defined(CONFIG_HISAX_NETJET_U)
2143         {PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300,     PCI_ANY_ID,PCI_ANY_ID},
2144 #endif
2145 #if defined(CONFIG_HISAX_TELESPCI) || defined(CONFIG_HISAX_SCT_QUADRO)
2146         {PCI_VENDOR_ID_ZORAN,    PCI_DEVICE_ID_ZORAN_36120,      PCI_ANY_ID,PCI_ANY_ID},
2147 #endif
2148 #ifdef CONFIG_HISAX_W6692
2149         {PCI_VENDOR_ID_DYNALINK, PCI_DEVICE_ID_DYNALINK_IS64PH,  PCI_ANY_ID,PCI_ANY_ID},
2150         {PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_6692,    PCI_ANY_ID,PCI_ANY_ID},
2151 #endif
2152 #ifdef CONFIG_HISAX_HFC_PCI
2153         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_2BD0,         PCI_ANY_ID, PCI_ANY_ID},
2154         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B000,         PCI_ANY_ID, PCI_ANY_ID},
2155         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B006,         PCI_ANY_ID, PCI_ANY_ID},
2156         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B007,         PCI_ANY_ID, PCI_ANY_ID},
2157         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B008,         PCI_ANY_ID, PCI_ANY_ID},
2158         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B009,         PCI_ANY_ID, PCI_ANY_ID},
2159         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00A,         PCI_ANY_ID, PCI_ANY_ID},
2160         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00B,         PCI_ANY_ID, PCI_ANY_ID},
2161         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00C,         PCI_ANY_ID, PCI_ANY_ID},
2162         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B100,         PCI_ANY_ID, PCI_ANY_ID},
2163         {PCI_VENDOR_ID_ABOCOM,   PCI_DEVICE_ID_ABOCOM_2BD1,      PCI_ANY_ID, PCI_ANY_ID},
2164         {PCI_VENDOR_ID_ASUSTEK,  PCI_DEVICE_ID_ASUSTEK_0675,     PCI_ANY_ID, PCI_ANY_ID},
2165         {PCI_VENDOR_ID_BERKOM,   PCI_DEVICE_ID_BERKOM_T_CONCEPT, PCI_ANY_ID, PCI_ANY_ID},
2166         {PCI_VENDOR_ID_BERKOM,   PCI_DEVICE_ID_BERKOM_A1T,       PCI_ANY_ID, PCI_ANY_ID},
2167         {PCI_VENDOR_ID_ANIGMA,   PCI_DEVICE_ID_ANIGMA_MC145575,  PCI_ANY_ID, PCI_ANY_ID},
2168         {PCI_VENDOR_ID_ZOLTRIX,  PCI_DEVICE_ID_ZOLTRIX_2BD0,     PCI_ANY_ID, PCI_ANY_ID},
2169         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_IOM2_E, PCI_ANY_ID, PCI_ANY_ID},
2170         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_E,      PCI_ANY_ID, PCI_ANY_ID},
2171         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_IOM2_A, PCI_ANY_ID, PCI_ANY_ID},
2172         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_A,      PCI_ANY_ID, PCI_ANY_ID},
2173 #endif
2174         { }                             /* Terminating entry */
2175 };
2176
2177 MODULE_DEVICE_TABLE(pci, hisax_pci_tbl);
2178
2179 module_init(HiSax_init);
2180 module_exit(HiSax_exit);
2181
2182 EXPORT_SYMBOL(FsmNew);
2183 EXPORT_SYMBOL(FsmFree);
2184 EXPORT_SYMBOL(FsmEvent);
2185 EXPORT_SYMBOL(FsmChangeState);
2186 EXPORT_SYMBOL(FsmInitTimer);
2187 EXPORT_SYMBOL(FsmDelTimer);
2188 EXPORT_SYMBOL(FsmRestartTimer);