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