Merge branch 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[linux-2.6] / 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 int init_card(struct IsdnCardState *cs)
804 {
805         int     irq_cnt, cnt = 3, ret;
806
807         if (!cs->irq) {
808                 ret = cs->cardmsg(cs, CARD_INIT, NULL);
809                 return(ret);
810         }
811         irq_cnt = kstat_irqs(cs->irq);
812         printk(KERN_INFO "%s: IRQ %d count %d\n", CardType[cs->typ],
813                cs->irq, irq_cnt);
814         if (request_irq(cs->irq, cs->irq_func, cs->irq_flags, "HiSax", cs)) {
815                 printk(KERN_WARNING "HiSax: couldn't get interrupt %d\n",
816                        cs->irq);
817                 return 1;
818         }
819         while (cnt) {
820                 cs->cardmsg(cs, CARD_INIT, NULL);
821                 /* Timeout 10ms */
822                 msleep(10);
823                 printk(KERN_INFO "%s: IRQ %d count %d\n",
824                        CardType[cs->typ], cs->irq, kstat_irqs(cs->irq));
825                 if (kstat_irqs(cs->irq) == irq_cnt) {
826                         printk(KERN_WARNING
827                                "%s: IRQ(%d) getting no interrupts during init %d\n",
828                                CardType[cs->typ], cs->irq, 4 - cnt);
829                         if (cnt == 1) {
830                                 free_irq(cs->irq, cs);
831                                 return 2;
832                         } else {
833                                 cs->cardmsg(cs, CARD_RESET, NULL);
834                                 cnt--;
835                         }
836                 } else {
837                         cs->cardmsg(cs, CARD_TEST, NULL);
838                         return 0;
839                 }
840         }
841         return 3;
842 }
843
844 static int __devinit hisax_cs_setup_card(struct IsdnCard *card)
845 {
846         int ret;
847
848         switch (card->typ) {
849 #if CARD_TELES0
850         case ISDN_CTYPE_16_0:
851         case ISDN_CTYPE_8_0:
852                 ret = setup_teles0(card);
853                 break;
854 #endif
855 #if CARD_TELES3
856         case ISDN_CTYPE_16_3:
857         case ISDN_CTYPE_PNP:
858         case ISDN_CTYPE_TELESPCMCIA:
859         case ISDN_CTYPE_COMPAQ_ISA:
860                 ret = setup_teles3(card);
861                 break;
862 #endif
863 #if CARD_S0BOX
864         case ISDN_CTYPE_S0BOX:
865                 ret = setup_s0box(card);
866                 break;
867 #endif
868 #if CARD_TELESPCI
869         case ISDN_CTYPE_TELESPCI:
870                 ret = setup_telespci(card);
871                 break;
872 #endif
873 #if CARD_AVM_A1
874         case ISDN_CTYPE_A1:
875                 ret = setup_avm_a1(card);
876                 break;
877 #endif
878 #if CARD_AVM_A1_PCMCIA
879         case ISDN_CTYPE_A1_PCMCIA:
880                 ret = setup_avm_a1_pcmcia(card);
881                 break;
882 #endif
883 #if CARD_FRITZPCI
884         case ISDN_CTYPE_FRITZPCI:
885                 ret = setup_avm_pcipnp(card);
886                 break;
887 #endif
888 #if CARD_ELSA
889         case ISDN_CTYPE_ELSA:
890         case ISDN_CTYPE_ELSA_PNP:
891         case ISDN_CTYPE_ELSA_PCMCIA:
892         case ISDN_CTYPE_ELSA_PCI:
893                 ret = setup_elsa(card);
894                 break;
895 #endif
896 #if CARD_IX1MICROR2
897         case ISDN_CTYPE_IX1MICROR2:
898                 ret = setup_ix1micro(card);
899                 break;
900 #endif
901 #if CARD_DIEHLDIVA
902         case ISDN_CTYPE_DIEHLDIVA:
903                 ret = setup_diva(card);
904                 break;
905 #endif
906 #if CARD_ASUSCOM
907         case ISDN_CTYPE_ASUSCOM:
908                 ret = setup_asuscom(card);
909                 break;
910 #endif
911 #if CARD_TELEINT
912         case ISDN_CTYPE_TELEINT:
913                 ret = setup_TeleInt(card);
914                 break;
915 #endif
916 #if CARD_SEDLBAUER
917         case ISDN_CTYPE_SEDLBAUER:
918         case ISDN_CTYPE_SEDLBAUER_PCMCIA:
919         case ISDN_CTYPE_SEDLBAUER_FAX:
920                 ret = setup_sedlbauer(card);
921                 break;
922 #endif
923 #if CARD_SPORTSTER
924         case ISDN_CTYPE_SPORTSTER:
925                 ret = setup_sportster(card);
926                 break;
927 #endif
928 #if CARD_MIC
929         case ISDN_CTYPE_MIC:
930                 ret = setup_mic(card);
931                 break;
932 #endif
933 #if CARD_NETJET_S
934         case ISDN_CTYPE_NETJET_S:
935                 ret = setup_netjet_s(card);
936                 break;
937 #endif
938 #if CARD_HFCS
939         case ISDN_CTYPE_TELES3C:
940         case ISDN_CTYPE_ACERP10:
941                 ret = setup_hfcs(card);
942                 break;
943 #endif
944 #if CARD_HFC_PCI
945         case ISDN_CTYPE_HFC_PCI:
946                 ret = setup_hfcpci(card);
947                 break;
948 #endif
949 #if CARD_HFC_SX
950         case ISDN_CTYPE_HFC_SX:
951                 ret = setup_hfcsx(card);
952                 break;
953 #endif
954 #if CARD_NICCY
955         case ISDN_CTYPE_NICCY:
956                 ret = setup_niccy(card);
957                 break;
958 #endif
959 #if CARD_ISURF
960         case ISDN_CTYPE_ISURF:
961                 ret = setup_isurf(card);
962                 break;
963 #endif
964 #if CARD_HSTSAPHIR
965         case ISDN_CTYPE_HSTSAPHIR:
966                 ret = setup_saphir(card);
967                 break;
968 #endif
969 #if     CARD_BKM_A4T
970         case ISDN_CTYPE_BKM_A4T:
971                 ret = setup_bkm_a4t(card);
972                 break;
973 #endif
974 #if     CARD_SCT_QUADRO
975         case ISDN_CTYPE_SCT_QUADRO:
976                 ret = setup_sct_quadro(card);
977                 break;
978 #endif
979 #if CARD_GAZEL
980         case ISDN_CTYPE_GAZEL:
981                 ret = setup_gazel(card);
982                 break;
983 #endif
984 #if CARD_W6692
985         case ISDN_CTYPE_W6692:
986                 ret = setup_w6692(card);
987                 break;
988 #endif
989 #if CARD_NETJET_U
990         case ISDN_CTYPE_NETJET_U:
991                 ret = setup_netjet_u(card);
992                 break;
993 #endif
994 #if CARD_FN_ENTERNOW_PCI
995         case ISDN_CTYPE_ENTERNOW:
996                 ret = setup_enternow_pci(card);
997                 break;
998 #endif
999         case ISDN_CTYPE_DYNAMIC:
1000                 ret = 2;
1001                 break;
1002         default:
1003                 printk(KERN_WARNING
1004                        "HiSax: Support for %s Card not selected\n",
1005                        CardType[card->typ]);
1006                 ret = 0;
1007                 break;
1008         }
1009
1010         return ret;
1011 }
1012
1013 static int hisax_cs_new(int cardnr, char *id, struct IsdnCard *card,
1014                         struct IsdnCardState **cs_out, int *busy_flag,
1015                         struct module *lockowner)
1016 {
1017         struct IsdnCardState *cs;
1018
1019         *cs_out = NULL;
1020
1021         cs = kzalloc(sizeof(struct IsdnCardState), GFP_ATOMIC);
1022         if (!cs) {
1023                 printk(KERN_WARNING
1024                        "HiSax: No memory for IsdnCardState(card %d)\n",
1025                        cardnr + 1);
1026                 goto out;
1027         }
1028         card->cs = cs;
1029         spin_lock_init(&cs->statlock);
1030         spin_lock_init(&cs->lock);
1031         cs->chanlimit = 2;      /* maximum B-channel number */
1032         cs->logecho = 0;        /* No echo logging */
1033         cs->cardnr = cardnr;
1034         cs->debug = L1_DEB_WARN;
1035         cs->HW_Flags = 0;
1036         cs->busy_flag = busy_flag;
1037         cs->irq_flags = I4L_IRQ_FLAG;
1038 #if TEI_PER_CARD
1039         if (card->protocol == ISDN_PTYPE_NI1)
1040                 test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
1041 #else
1042         test_and_set_bit(FLG_TWO_DCHAN, &cs->HW_Flags);
1043 #endif
1044         cs->protocol = card->protocol;
1045
1046         if (card->typ <= 0 || card->typ > ISDN_CTYPE_COUNT) {
1047                 printk(KERN_WARNING
1048                        "HiSax: Card Type %d out of range\n", card->typ);
1049                 goto outf_cs;
1050         }
1051         if (!(cs->dlog = kmalloc(MAX_DLOG_SPACE, GFP_ATOMIC))) {
1052                 printk(KERN_WARNING
1053                        "HiSax: No memory for dlog(card %d)\n", cardnr + 1);
1054                 goto outf_cs;
1055         }
1056         if (!(cs->status_buf = kmalloc(HISAX_STATUS_BUFSIZE, GFP_ATOMIC))) {
1057                 printk(KERN_WARNING
1058                        "HiSax: No memory for status_buf(card %d)\n",
1059                        cardnr + 1);
1060                 goto outf_dlog;
1061         }
1062         cs->stlist = NULL;
1063         cs->status_read = cs->status_buf;
1064         cs->status_write = cs->status_buf;
1065         cs->status_end = cs->status_buf + HISAX_STATUS_BUFSIZE - 1;
1066         cs->typ = card->typ;
1067 #ifdef MODULE
1068         cs->iif.owner = lockowner;
1069 #endif
1070         strcpy(cs->iif.id, id);
1071         cs->iif.channels = 2;
1072         cs->iif.maxbufsize = MAX_DATA_SIZE;
1073         cs->iif.hl_hdrlen = MAX_HEADER_LEN;
1074         cs->iif.features =
1075                 ISDN_FEATURE_L2_X75I |
1076                 ISDN_FEATURE_L2_HDLC |
1077                 ISDN_FEATURE_L2_HDLC_56K |
1078                 ISDN_FEATURE_L2_TRANS |
1079                 ISDN_FEATURE_L3_TRANS |
1080 #ifdef  CONFIG_HISAX_1TR6
1081                 ISDN_FEATURE_P_1TR6 |
1082 #endif
1083 #ifdef  CONFIG_HISAX_EURO
1084                 ISDN_FEATURE_P_EURO |
1085 #endif
1086 #ifdef  CONFIG_HISAX_NI1
1087                 ISDN_FEATURE_P_NI1 |
1088 #endif
1089                 0;
1090
1091         cs->iif.command = HiSax_command;
1092         cs->iif.writecmd = NULL;
1093         cs->iif.writebuf_skb = HiSax_writebuf_skb;
1094         cs->iif.readstat = HiSax_readstatus;
1095         register_isdn(&cs->iif);
1096         cs->myid = cs->iif.channels;
1097
1098         *cs_out = cs;
1099         return 1;       /* success */
1100
1101 outf_dlog:
1102         kfree(cs->dlog);
1103 outf_cs:
1104         kfree(cs);
1105         card->cs = NULL;
1106 out:
1107         return 0;       /* error */
1108 }
1109
1110 static int hisax_cs_setup(int cardnr, struct IsdnCard *card,
1111                           struct IsdnCardState *cs)
1112 {
1113         int ret;
1114
1115         if (!(cs->rcvbuf = kmalloc(MAX_DFRAME_LEN_L1, GFP_ATOMIC))) {
1116                 printk(KERN_WARNING "HiSax: No memory for isac rcvbuf\n");
1117                 ll_unload(cs);
1118                 goto outf_cs;
1119         }
1120         cs->rcvidx = 0;
1121         cs->tx_skb = NULL;
1122         cs->tx_cnt = 0;
1123         cs->event = 0;
1124
1125         skb_queue_head_init(&cs->rq);
1126         skb_queue_head_init(&cs->sq);
1127
1128         init_bcstate(cs, 0);
1129         init_bcstate(cs, 1);
1130
1131         /* init_card only handles interrupts which are not */
1132         /* used here for the loadable driver */
1133         switch (card->typ) {
1134                 case ISDN_CTYPE_DYNAMIC:
1135                         ret = 0;
1136                         break;
1137                 default:
1138                         ret = init_card(cs);
1139                         break;
1140         }
1141         if (ret) {
1142                 closecard(cardnr);
1143                 goto outf_cs;
1144         }
1145         init_tei(cs, cs->protocol);
1146         ret = CallcNewChan(cs);
1147         if (ret) {
1148                 closecard(cardnr);
1149                 goto outf_cs;
1150         }
1151         /* ISAR needs firmware download first */
1152         if (!test_bit(HW_ISAR, &cs->HW_Flags))
1153                 ll_run(cs, 0);
1154
1155         return 1;
1156
1157 outf_cs:
1158         kfree(cs);
1159         card->cs = NULL;
1160         return 0;
1161 }
1162
1163 /* Used from an exported function but calls __devinit functions.
1164  * Tell modpost not to warn (__ref)
1165  */
1166 static int __ref checkcard(int cardnr, char *id, int *busy_flag,
1167                            struct module *lockowner,
1168                            hisax_setup_func_t card_setup)
1169 {
1170         int ret;
1171         struct IsdnCard *card = cards + cardnr;
1172         struct IsdnCardState *cs;
1173
1174         ret = hisax_cs_new(cardnr, id, card, &cs, busy_flag, lockowner);
1175         if (!ret)
1176                 return 0;
1177
1178         printk(KERN_INFO
1179                "HiSax: Card %d Protocol %s Id=%s (%d)\n", cardnr + 1,
1180                (card->protocol == ISDN_PTYPE_1TR6) ? "1TR6" :
1181                (card->protocol == ISDN_PTYPE_EURO) ? "EDSS1" :
1182                (card->protocol == ISDN_PTYPE_LEASED) ? "LEASED" :
1183                (card->protocol == ISDN_PTYPE_NI1) ? "NI1" :
1184                "NONE", cs->iif.id, cs->myid);
1185
1186         ret = card_setup(card);
1187         if (!ret) {
1188                 ll_unload(cs);
1189                 goto outf_cs;
1190         }
1191
1192         ret = hisax_cs_setup(cardnr, card, cs);
1193         goto out;
1194
1195  outf_cs:
1196         kfree(cs);
1197         card->cs = NULL;
1198  out:
1199         return ret;
1200 }
1201
1202 static void HiSax_shiftcards(int idx)
1203 {
1204         int i;
1205
1206         for (i = idx; i < (HISAX_MAX_CARDS - 1); i++)
1207                 memcpy(&cards[i], &cards[i + 1], sizeof(cards[i]));
1208 }
1209
1210 static int __init HiSax_inithardware(int *busy_flag)
1211 {
1212         int foundcards = 0;
1213         int i = 0;
1214         int t = ',';
1215         int flg = 0;
1216         char *id;
1217         char *next_id = HiSax_id;
1218         char ids[20];
1219
1220         if (strchr(HiSax_id, ','))
1221                 t = ',';
1222         else if (strchr(HiSax_id, '%'))
1223                 t = '%';
1224
1225         while (i < nrcards) {
1226                 if (cards[i].typ < 1)
1227                         break;
1228                 id = next_id;
1229                 if ((next_id = strchr(id, t))) {
1230                         *next_id++ = 0;
1231                         strcpy(ids, id);
1232                         flg = i + 1;
1233                 } else {
1234                         next_id = id;
1235                         if (flg >= i)
1236                                 strcpy(ids, id);
1237                         else
1238                                 sprintf(ids, "%s%d", id, i);
1239                 }
1240                 if (checkcard(i, ids, busy_flag, THIS_MODULE,
1241                               hisax_cs_setup_card)) {
1242                         foundcards++;
1243                         i++;
1244                 } else {
1245                         /* make sure we don't oops the module */
1246                         if (cards[i].typ > 0 && cards[i].typ <= ISDN_CTYPE_COUNT) {
1247                                 printk(KERN_WARNING
1248                                         "HiSax: Card %s not installed !\n",
1249                                         CardType[cards[i].typ]);
1250                         }
1251                         HiSax_shiftcards(i);
1252                         nrcards--;
1253                 }
1254         }
1255         return foundcards;
1256 }
1257
1258 void HiSax_closecard(int cardnr)
1259 {
1260         int i, last = nrcards - 1;
1261
1262         if (cardnr > last || cardnr < 0)
1263                 return;
1264         if (cards[cardnr].cs) {
1265                 ll_stop(cards[cardnr].cs);
1266                 release_tei(cards[cardnr].cs);
1267                 CallcFreeChan(cards[cardnr].cs);
1268
1269                 closecard(cardnr);
1270                 if (cards[cardnr].cs->irq)
1271                         free_irq(cards[cardnr].cs->irq, cards[cardnr].cs);
1272                 kfree((void *) cards[cardnr].cs);
1273                 cards[cardnr].cs = NULL;
1274         }
1275         i = cardnr;
1276         while (i <= last) {
1277                 cards[i] = cards[i + 1];
1278                 i++;
1279         }
1280         nrcards--;
1281 }
1282
1283 void HiSax_reportcard(int cardnr, int sel)
1284 {
1285         struct IsdnCardState *cs = cards[cardnr].cs;
1286
1287         printk(KERN_DEBUG "HiSax: reportcard No %d\n", cardnr + 1);
1288         printk(KERN_DEBUG "HiSax: Type %s\n", CardType[cs->typ]);
1289         printk(KERN_DEBUG "HiSax: debuglevel %x\n", cs->debug);
1290         printk(KERN_DEBUG "HiSax: HiSax_reportcard address 0x%lX\n",
1291                (ulong) & HiSax_reportcard);
1292         printk(KERN_DEBUG "HiSax: cs 0x%lX\n", (ulong) cs);
1293         printk(KERN_DEBUG "HiSax: HW_Flags %lx bc0 flg %lx bc1 flg %lx\n",
1294                cs->HW_Flags, cs->bcs[0].Flag, cs->bcs[1].Flag);
1295         printk(KERN_DEBUG "HiSax: bcs 0 mode %d ch%d\n",
1296                cs->bcs[0].mode, cs->bcs[0].channel);
1297         printk(KERN_DEBUG "HiSax: bcs 1 mode %d ch%d\n",
1298                cs->bcs[1].mode, cs->bcs[1].channel);
1299 #ifdef ERROR_STATISTIC
1300         printk(KERN_DEBUG "HiSax: dc errors(rx,crc,tx) %d,%d,%d\n",
1301                cs->err_rx, cs->err_crc, cs->err_tx);
1302         printk(KERN_DEBUG
1303                "HiSax: bc0 errors(inv,rdo,crc,tx) %d,%d,%d,%d\n",
1304                cs->bcs[0].err_inv, cs->bcs[0].err_rdo, cs->bcs[0].err_crc,
1305                cs->bcs[0].err_tx);
1306         printk(KERN_DEBUG
1307                "HiSax: bc1 errors(inv,rdo,crc,tx) %d,%d,%d,%d\n",
1308                cs->bcs[1].err_inv, cs->bcs[1].err_rdo, cs->bcs[1].err_crc,
1309                cs->bcs[1].err_tx);
1310         if (sel == 99) {
1311                 cs->err_rx  = 0;
1312                 cs->err_crc = 0;
1313                 cs->err_tx  = 0;
1314                 cs->bcs[0].err_inv = 0;
1315                 cs->bcs[0].err_rdo = 0;
1316                 cs->bcs[0].err_crc = 0;
1317                 cs->bcs[0].err_tx  = 0;
1318                 cs->bcs[1].err_inv = 0;
1319                 cs->bcs[1].err_rdo = 0;
1320                 cs->bcs[1].err_crc = 0;
1321                 cs->bcs[1].err_tx  = 0;
1322         }
1323 #endif
1324 }
1325
1326 static int __init HiSax_init(void)
1327 {
1328         int i, retval;
1329 #ifdef MODULE
1330         int j;
1331         int nzproto = 0;
1332 #endif
1333
1334         HiSaxVersion();
1335         retval = CallcNew();
1336         if (retval)
1337                 goto out;
1338         retval = Isdnl3New();
1339         if (retval)
1340                 goto out_callc;
1341         retval = Isdnl2New();
1342         if (retval)
1343                 goto out_isdnl3;
1344         retval = TeiNew();
1345         if (retval)
1346                 goto out_isdnl2;
1347         retval = Isdnl1New();
1348         if (retval)
1349                 goto out_tei;
1350
1351 #ifdef MODULE
1352         if (!type[0]) {
1353                 /* We 'll register drivers later, but init basic functions */
1354                 for (i = 0; i < HISAX_MAX_CARDS; i++)
1355                         cards[i].typ = 0;
1356                 return 0;
1357         }
1358 #ifdef CONFIG_HISAX_ELSA
1359         if (type[0] == ISDN_CTYPE_ELSA_PCMCIA) {
1360                 /* we have exported  and return in this case */
1361                 return 0;
1362         }
1363 #endif
1364 #ifdef CONFIG_HISAX_SEDLBAUER
1365         if (type[0] == ISDN_CTYPE_SEDLBAUER_PCMCIA) {
1366                 /* we have to export  and return in this case */
1367                 return 0;
1368         }
1369 #endif
1370 #ifdef CONFIG_HISAX_AVM_A1_PCMCIA
1371         if (type[0] == ISDN_CTYPE_A1_PCMCIA) {
1372                 /* we have to export  and return in this case */
1373                 return 0;
1374         }
1375 #endif
1376 #ifdef CONFIG_HISAX_HFC_SX
1377         if (type[0] == ISDN_CTYPE_HFC_SP_PCMCIA) {
1378                 /* we have to export  and return in this case */
1379                 return 0;
1380         }
1381 #endif
1382 #endif
1383         nrcards = 0;
1384 #ifdef MODULE
1385         if (id)                 /* If id= string used */
1386                 HiSax_id = id;
1387         for (i = j = 0; j < HISAX_MAX_CARDS; i++) {
1388                 cards[j].typ = type[i];
1389                 if (protocol[i]) {
1390                         cards[j].protocol = protocol[i];
1391                         nzproto++;
1392                 } else {
1393                         cards[j].protocol = DEFAULT_PROTO;
1394                 }
1395                 switch (type[i]) {
1396                 case ISDN_CTYPE_16_0:
1397                         cards[j].para[0] = irq[i];
1398                         cards[j].para[1] = mem[i];
1399                         cards[j].para[2] = io[i];
1400                         break;
1401
1402                 case ISDN_CTYPE_8_0:
1403                         cards[j].para[0] = irq[i];
1404                         cards[j].para[1] = mem[i];
1405                         break;
1406
1407 #ifdef IO0_IO1
1408                 case ISDN_CTYPE_PNP:
1409                 case ISDN_CTYPE_NICCY:
1410                         cards[j].para[0] = irq[i];
1411                         cards[j].para[1] = io0[i];
1412                         cards[j].para[2] = io1[i];
1413                         break;
1414                 case ISDN_CTYPE_COMPAQ_ISA:
1415                         cards[j].para[0] = irq[i];
1416                         cards[j].para[1] = io0[i];
1417                         cards[j].para[2] = io1[i];
1418                         cards[j].para[3] = io[i];
1419                         break;
1420 #endif
1421                 case ISDN_CTYPE_ELSA:
1422                 case ISDN_CTYPE_HFC_PCI:
1423                         cards[j].para[0] = io[i];
1424                         break;
1425                 case ISDN_CTYPE_16_3:
1426                 case ISDN_CTYPE_TELESPCMCIA:
1427                 case ISDN_CTYPE_A1:
1428                 case ISDN_CTYPE_A1_PCMCIA:
1429                 case ISDN_CTYPE_ELSA_PNP:
1430                 case ISDN_CTYPE_ELSA_PCMCIA:
1431                 case ISDN_CTYPE_IX1MICROR2:
1432                 case ISDN_CTYPE_DIEHLDIVA:
1433                 case ISDN_CTYPE_ASUSCOM:
1434                 case ISDN_CTYPE_TELEINT:
1435                 case ISDN_CTYPE_SEDLBAUER:
1436                 case ISDN_CTYPE_SEDLBAUER_PCMCIA:
1437                 case ISDN_CTYPE_SEDLBAUER_FAX:
1438                 case ISDN_CTYPE_SPORTSTER:
1439                 case ISDN_CTYPE_MIC:
1440                 case ISDN_CTYPE_TELES3C:
1441                 case ISDN_CTYPE_ACERP10:
1442                 case ISDN_CTYPE_S0BOX:
1443                 case ISDN_CTYPE_FRITZPCI:
1444                 case ISDN_CTYPE_HSTSAPHIR:
1445                 case ISDN_CTYPE_GAZEL:
1446                 case ISDN_CTYPE_HFC_SX:
1447                 case ISDN_CTYPE_HFC_SP_PCMCIA:
1448                         cards[j].para[0] = irq[i];
1449                         cards[j].para[1] = io[i];
1450                         break;
1451                 case ISDN_CTYPE_ISURF:
1452                         cards[j].para[0] = irq[i];
1453                         cards[j].para[1] = io[i];
1454                         cards[j].para[2] = mem[i];
1455                         break;
1456                 case ISDN_CTYPE_ELSA_PCI:
1457                 case ISDN_CTYPE_NETJET_S:
1458                 case ISDN_CTYPE_TELESPCI:
1459                 case ISDN_CTYPE_W6692:
1460                 case ISDN_CTYPE_NETJET_U:
1461                         break;
1462                 case ISDN_CTYPE_BKM_A4T:
1463                         break;
1464                 case ISDN_CTYPE_SCT_QUADRO:
1465                         if (irq[i]) {
1466                                 cards[j].para[0] = irq[i];
1467                         } else {
1468                                 /* QUADRO is a 4 BRI card */
1469                                 cards[j++].para[0] = 1;
1470                                 /* we need to check if further cards can be added */
1471                                 if (j < HISAX_MAX_CARDS) {
1472                                         cards[j].typ = ISDN_CTYPE_SCT_QUADRO;
1473                                         cards[j].protocol = protocol[i];
1474                                         cards[j++].para[0] = 2;
1475                                 }
1476                                 if (j < HISAX_MAX_CARDS) {
1477                                         cards[j].typ = ISDN_CTYPE_SCT_QUADRO;
1478                                         cards[j].protocol = protocol[i];
1479                                         cards[j++].para[0] = 3;
1480                                 }
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] = 4;
1485                                 }
1486                         }
1487                         break;
1488                 }
1489                 j++;
1490         }
1491         if (!nzproto) {
1492                 printk(KERN_WARNING
1493                        "HiSax: Warning - no protocol specified\n");
1494                 printk(KERN_WARNING "HiSax: using protocol %s\n",
1495                        DEFAULT_PROTO_NAME);
1496         }
1497 #endif
1498         if (!HiSax_id)
1499                 HiSax_id = HiSaxID;
1500         if (!HiSaxID[0])
1501                 strcpy(HiSaxID, "HiSax");
1502         for (i = 0; i < HISAX_MAX_CARDS; i++)
1503                 if (cards[i].typ > 0)
1504                         nrcards++;
1505         printk(KERN_DEBUG "HiSax: Total %d card%s defined\n",
1506                nrcards, (nrcards > 1) ? "s" : "");
1507
1508         /* Install only, if at least one card found */
1509         if (!HiSax_inithardware(NULL))
1510                 return -ENODEV;
1511         return 0;
1512
1513  out_tei:
1514         TeiFree();
1515  out_isdnl2:
1516         Isdnl2Free();
1517  out_isdnl3:
1518         Isdnl3Free();
1519  out_callc:
1520         CallcFree();
1521  out:
1522         return retval;
1523 }
1524
1525 static void __exit HiSax_exit(void)
1526 {
1527         int cardnr = nrcards - 1;
1528
1529         while (cardnr >= 0)
1530                 HiSax_closecard(cardnr--);
1531         Isdnl1Free();
1532         TeiFree();
1533         Isdnl2Free();
1534         Isdnl3Free();
1535         CallcFree();
1536         printk(KERN_INFO "HiSax module removed\n");
1537 }
1538
1539 #ifdef CONFIG_HOTPLUG
1540
1541 int __devinit hisax_init_pcmcia(void *pcm_iob, int *busy_flag, struct IsdnCard *card)
1542 {
1543         u_char ids[16];
1544         int ret = -1;
1545
1546         cards[nrcards] = *card;
1547         if (nrcards)
1548                 sprintf(ids, "HiSax%d", nrcards);
1549         else
1550                 sprintf(ids, "HiSax");
1551         if (!checkcard(nrcards, ids, busy_flag, THIS_MODULE,
1552                        hisax_cs_setup_card))
1553                 goto error;
1554
1555         ret = nrcards;
1556         nrcards++;
1557 error:
1558         return ret;
1559 }
1560
1561 EXPORT_SYMBOL(hisax_init_pcmcia);
1562 #endif
1563
1564 EXPORT_SYMBOL(HiSax_closecard);
1565
1566 #include "hisax_if.h"
1567
1568 EXPORT_SYMBOL(hisax_register);
1569 EXPORT_SYMBOL(hisax_unregister);
1570
1571 static void hisax_d_l1l2(struct hisax_if *ifc, int pr, void *arg);
1572 static void hisax_b_l1l2(struct hisax_if *ifc, int pr, void *arg);
1573 static void hisax_d_l2l1(struct PStack *st, int pr, void *arg);
1574 static void hisax_b_l2l1(struct PStack *st, int pr, void *arg);
1575 static int hisax_cardmsg(struct IsdnCardState *cs, int mt, void *arg);
1576 static int hisax_bc_setstack(struct PStack *st, struct BCState *bcs);
1577 static void hisax_bc_close(struct BCState *bcs);
1578 static void hisax_bh(struct work_struct *work);
1579 static void EChannel_proc_rcv(struct hisax_d_if *d_if);
1580
1581 static int hisax_setup_card_dynamic(struct IsdnCard *card)
1582 {
1583         return 2;
1584 }
1585
1586 int hisax_register(struct hisax_d_if *hisax_d_if, struct hisax_b_if *b_if[],
1587                    char *name, int protocol)
1588 {
1589         int i, retval;
1590         char id[20];
1591         struct IsdnCardState *cs;
1592
1593         for (i = 0; i < HISAX_MAX_CARDS; i++) {
1594                 if (!cards[i].typ)
1595                         break;
1596         }
1597
1598         if (i >= HISAX_MAX_CARDS)
1599                 return -EBUSY;
1600
1601         cards[i].typ = ISDN_CTYPE_DYNAMIC;
1602         cards[i].protocol = protocol;
1603         sprintf(id, "%s%d", name, i);
1604         nrcards++;
1605         retval = checkcard(i, id, NULL, hisax_d_if->owner,
1606                                 hisax_setup_card_dynamic);
1607         if (retval == 0) { // yuck
1608                 cards[i].typ = 0;
1609                 nrcards--;
1610                 return -EINVAL;
1611         }
1612         cs = cards[i].cs;
1613         hisax_d_if->cs = cs;
1614         cs->hw.hisax_d_if = hisax_d_if;
1615         cs->cardmsg = hisax_cardmsg;
1616         INIT_WORK(&cs->tqueue, hisax_bh);
1617         cs->channel[0].d_st->l2.l2l1 = hisax_d_l2l1;
1618         for (i = 0; i < 2; i++) {
1619                 cs->bcs[i].BC_SetStack = hisax_bc_setstack;
1620                 cs->bcs[i].BC_Close = hisax_bc_close;
1621
1622                 b_if[i]->ifc.l1l2 = hisax_b_l1l2;
1623
1624                 hisax_d_if->b_if[i] = b_if[i];
1625         }
1626         hisax_d_if->ifc.l1l2 = hisax_d_l1l2;
1627         skb_queue_head_init(&hisax_d_if->erq);
1628         clear_bit(0, &hisax_d_if->ph_state);
1629         
1630         return 0;
1631 }
1632
1633 void hisax_unregister(struct hisax_d_if *hisax_d_if)
1634 {
1635         cards[hisax_d_if->cs->cardnr].typ = 0;
1636         HiSax_closecard(hisax_d_if->cs->cardnr);
1637         skb_queue_purge(&hisax_d_if->erq);
1638 }
1639
1640 #include "isdnl1.h"
1641
1642 static void hisax_sched_event(struct IsdnCardState *cs, int event)
1643 {
1644         test_and_set_bit(event, &cs->event);
1645         schedule_work(&cs->tqueue);
1646 }
1647
1648 static void hisax_bh(struct work_struct *work)
1649 {
1650         struct IsdnCardState *cs =
1651                 container_of(work, struct IsdnCardState, tqueue);
1652         struct PStack *st;
1653         int pr;
1654
1655         if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
1656                 DChannel_proc_rcv(cs);
1657         if (test_and_clear_bit(E_RCVBUFREADY, &cs->event))
1658                 EChannel_proc_rcv(cs->hw.hisax_d_if);
1659         if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
1660                 if (test_bit(0, &cs->hw.hisax_d_if->ph_state))
1661                         pr = PH_ACTIVATE | INDICATION;
1662                 else
1663                         pr = PH_DEACTIVATE | INDICATION;
1664                 for (st = cs->stlist; st; st = st->next)
1665                         st->l1.l1l2(st, pr, NULL);
1666                 
1667         }
1668 }
1669
1670 static void hisax_b_sched_event(struct BCState *bcs, int event)
1671 {
1672         test_and_set_bit(event, &bcs->event);
1673         schedule_work(&bcs->tqueue);
1674 }
1675
1676 static inline void D_L2L1(struct hisax_d_if *d_if, int pr, void *arg)
1677 {
1678         struct hisax_if *ifc = (struct hisax_if *) d_if;
1679         ifc->l2l1(ifc, pr, arg);
1680 }
1681
1682 static inline void B_L2L1(struct hisax_b_if *b_if, int pr, void *arg)
1683 {
1684         struct hisax_if *ifc = (struct hisax_if *) b_if;
1685         ifc->l2l1(ifc, pr, arg);
1686 }
1687
1688 static void hisax_d_l1l2(struct hisax_if *ifc, int pr, void *arg)
1689 {
1690         struct hisax_d_if *d_if = (struct hisax_d_if *) ifc;
1691         struct IsdnCardState *cs = d_if->cs;
1692         struct PStack *st;
1693         struct sk_buff *skb;
1694
1695         switch (pr) {
1696         case PH_ACTIVATE | INDICATION:
1697                 set_bit(0, &d_if->ph_state);
1698                 hisax_sched_event(cs, D_L1STATECHANGE);
1699                 break;
1700         case PH_DEACTIVATE | INDICATION:
1701                 clear_bit(0, &d_if->ph_state);
1702                 hisax_sched_event(cs, D_L1STATECHANGE);
1703                 break;
1704         case PH_DATA | INDICATION:
1705                 skb_queue_tail(&cs->rq, arg);
1706                 hisax_sched_event(cs, D_RCVBUFREADY);
1707                 break;
1708         case PH_DATA | CONFIRM:
1709                 skb = skb_dequeue(&cs->sq);
1710                 if (skb) {
1711                         D_L2L1(d_if, PH_DATA | REQUEST, skb);
1712                         break;
1713                 }
1714                 clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
1715                 for (st = cs->stlist; st; st = st->next) {
1716                         if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags)) {
1717                                 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1718                                 break;
1719                         }
1720                 }
1721                 break;
1722         case PH_DATA_E | INDICATION:
1723                 skb_queue_tail(&d_if->erq, arg);
1724                 hisax_sched_event(cs, E_RCVBUFREADY);
1725                 break;
1726         default:
1727                 printk("pr %#x\n", pr);
1728                 break;
1729         }
1730 }
1731
1732 static void hisax_b_l1l2(struct hisax_if *ifc, int pr, void *arg)
1733 {
1734         struct hisax_b_if *b_if = (struct hisax_b_if *) ifc;
1735         struct BCState *bcs = b_if->bcs;
1736         struct PStack *st = bcs->st;
1737         struct sk_buff *skb;
1738
1739         // FIXME use isdnl1?
1740         switch (pr) {
1741         case PH_ACTIVATE | INDICATION:
1742                 st->l1.l1l2(st, pr, NULL);
1743                 break;
1744         case PH_DEACTIVATE | INDICATION:
1745                 st->l1.l1l2(st, pr, NULL);
1746                 clear_bit(BC_FLG_BUSY, &bcs->Flag);
1747                 skb_queue_purge(&bcs->squeue);
1748                 bcs->hw.b_if = NULL;
1749                 break;
1750         case PH_DATA | INDICATION:
1751                 skb_queue_tail(&bcs->rqueue, arg);
1752                 hisax_b_sched_event(bcs, B_RCVBUFREADY);
1753                 break;
1754         case PH_DATA | CONFIRM:
1755                 bcs->tx_cnt -= (long)arg;
1756                 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag)) {
1757                         u_long  flags;
1758                         spin_lock_irqsave(&bcs->aclock, flags);
1759                         bcs->ackcnt += (long)arg;
1760                         spin_unlock_irqrestore(&bcs->aclock, flags);
1761                         schedule_event(bcs, B_ACKPENDING);
1762                 }
1763                 skb = skb_dequeue(&bcs->squeue);
1764                 if (skb) {
1765                         B_L2L1(b_if, PH_DATA | REQUEST, skb);
1766                         break;
1767                 }
1768                 clear_bit(BC_FLG_BUSY, &bcs->Flag);
1769                 if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags)) {
1770                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1771                 }
1772                 break;
1773         default:
1774                 printk("hisax_b_l1l2 pr %#x\n", pr);
1775                 break;
1776         }
1777 }
1778
1779 static void hisax_d_l2l1(struct PStack *st, int pr, void *arg)
1780 {
1781         struct IsdnCardState *cs = st->l1.hardware;
1782         struct hisax_d_if *hisax_d_if = cs->hw.hisax_d_if;
1783         struct sk_buff *skb = arg;
1784
1785         switch (pr) {
1786         case PH_DATA | REQUEST:
1787         case PH_PULL | INDICATION:
1788                 if (cs->debug & DEB_DLOG_HEX)
1789                         LogFrame(cs, skb->data, skb->len);
1790                 if (cs->debug & DEB_DLOG_VERBOSE)
1791                         dlogframe(cs, skb, 0);
1792                 Logl2Frame(cs, skb, "PH_DATA_REQ", 0);
1793                 // FIXME lock?
1794                 if (!test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags))
1795                         D_L2L1(hisax_d_if, PH_DATA | REQUEST, skb);
1796                 else
1797                         skb_queue_tail(&cs->sq, skb);
1798                 break;
1799         case PH_PULL | REQUEST:
1800                 if (!test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
1801                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1802                 else
1803                         set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1804                 break;
1805         default:
1806                 D_L2L1(hisax_d_if, pr, arg);
1807                 break;
1808         }
1809 }
1810
1811 static int hisax_cardmsg(struct IsdnCardState *cs, int mt, void *arg)
1812 {
1813         return 0;
1814 }
1815
1816 static void hisax_b_l2l1(struct PStack *st, int pr, void *arg)
1817 {
1818         struct BCState *bcs = st->l1.bcs;
1819         struct hisax_b_if *b_if = bcs->hw.b_if;
1820
1821         switch (pr) {
1822         case PH_ACTIVATE | REQUEST:
1823                 B_L2L1(b_if, pr, (void *)(unsigned long)st->l1.mode);
1824                 break;
1825         case PH_DATA | REQUEST:
1826         case PH_PULL | INDICATION:
1827                 // FIXME lock?
1828                 if (!test_and_set_bit(BC_FLG_BUSY, &bcs->Flag)) {
1829                         B_L2L1(b_if, PH_DATA | REQUEST, arg);
1830                 } else {
1831                         skb_queue_tail(&bcs->squeue, arg);
1832                 }
1833                 break;
1834         case PH_PULL | REQUEST:
1835                 if (!test_bit(BC_FLG_BUSY, &bcs->Flag))
1836                         st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1837                 else
1838                         set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1839                 break;
1840         case PH_DEACTIVATE | REQUEST:
1841                 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
1842                 skb_queue_purge(&bcs->squeue);
1843         default:
1844                 B_L2L1(b_if, pr, arg);
1845                 break;
1846         }
1847 }
1848
1849 static int hisax_bc_setstack(struct PStack *st, struct BCState *bcs)
1850 {
1851         struct IsdnCardState *cs = st->l1.hardware;
1852         struct hisax_d_if *hisax_d_if = cs->hw.hisax_d_if;
1853
1854         bcs->channel = st->l1.bc;
1855
1856         bcs->hw.b_if = hisax_d_if->b_if[st->l1.bc];
1857         hisax_d_if->b_if[st->l1.bc]->bcs = bcs;
1858
1859         st->l1.bcs = bcs;
1860         st->l2.l2l1 = hisax_b_l2l1;
1861         setstack_manager(st);
1862         bcs->st = st;
1863         setstack_l1_B(st);
1864         skb_queue_head_init(&bcs->rqueue);
1865         skb_queue_head_init(&bcs->squeue);
1866         return 0;
1867 }
1868
1869 static void hisax_bc_close(struct BCState *bcs)
1870 {
1871         struct hisax_b_if *b_if = bcs->hw.b_if;
1872
1873         if (b_if)
1874                 B_L2L1(b_if, PH_DEACTIVATE | REQUEST, NULL);
1875 }
1876
1877 static void EChannel_proc_rcv(struct hisax_d_if *d_if)
1878 {
1879         struct IsdnCardState *cs = d_if->cs;
1880         u_char *ptr;
1881         struct sk_buff *skb;
1882
1883         while ((skb = skb_dequeue(&d_if->erq)) != NULL) {
1884                 if (cs->debug & DEB_DLOG_HEX) {
1885                         ptr = cs->dlog;
1886                         if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
1887                                 *ptr++ = 'E';
1888                                 *ptr++ = 'C';
1889                                 *ptr++ = 'H';
1890                                 *ptr++ = 'O';
1891                                 *ptr++ = ':';
1892                                 ptr += QuickHex(ptr, skb->data, skb->len);
1893                                 ptr--;
1894                                 *ptr++ = '\n';
1895                                 *ptr = 0;
1896                                 HiSax_putstatus(cs, NULL, cs->dlog);
1897                         } else
1898                                 HiSax_putstatus(cs, "LogEcho: ",
1899                                                 "warning Frame too big (%d)",
1900                                                 skb->len);
1901                 }
1902                 dev_kfree_skb_any(skb);
1903         }
1904 }
1905
1906 #ifdef CONFIG_PCI
1907 #include <linux/pci.h>
1908
1909 static struct pci_device_id hisax_pci_tbl[] __devinitdata = {
1910 #ifdef CONFIG_HISAX_FRITZPCI
1911         {PCI_VENDOR_ID_AVM,      PCI_DEVICE_ID_AVM_A1,           PCI_ANY_ID, PCI_ANY_ID},
1912 #endif
1913 #ifdef CONFIG_HISAX_DIEHLDIVA
1914         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA20,     PCI_ANY_ID, PCI_ANY_ID},
1915         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA20_U,   PCI_ANY_ID, PCI_ANY_ID},
1916         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA201,    PCI_ANY_ID, PCI_ANY_ID},
1917 //#########################################################################################     
1918         {PCI_VENDOR_ID_EICON,    PCI_DEVICE_ID_EICON_DIVA202,    PCI_ANY_ID, PCI_ANY_ID},
1919 //#########################################################################################     
1920 #endif
1921 #ifdef CONFIG_HISAX_ELSA
1922         {PCI_VENDOR_ID_ELSA,     PCI_DEVICE_ID_ELSA_MICROLINK,   PCI_ANY_ID, PCI_ANY_ID},
1923         {PCI_VENDOR_ID_ELSA,     PCI_DEVICE_ID_ELSA_QS3000,      PCI_ANY_ID, PCI_ANY_ID},
1924 #endif
1925 #ifdef CONFIG_HISAX_GAZEL
1926         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_R685,         PCI_ANY_ID, PCI_ANY_ID},
1927         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_R753,         PCI_ANY_ID, PCI_ANY_ID},
1928         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_DJINN_ITOO,   PCI_ANY_ID, PCI_ANY_ID},
1929         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_OLITEC,       PCI_ANY_ID, PCI_ANY_ID},
1930 #endif
1931 #ifdef CONFIG_HISAX_SCT_QUADRO
1932         {PCI_VENDOR_ID_PLX,      PCI_DEVICE_ID_PLX_9050,         PCI_ANY_ID, PCI_ANY_ID},
1933 #endif
1934 #ifdef CONFIG_HISAX_NICCY
1935         {PCI_VENDOR_ID_SATSAGEM, PCI_DEVICE_ID_SATSAGEM_NICCY,   PCI_ANY_ID,PCI_ANY_ID},
1936 #endif
1937 #ifdef CONFIG_HISAX_SEDLBAUER
1938         {PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_100,     PCI_ANY_ID,PCI_ANY_ID},
1939 #endif
1940 #if defined(CONFIG_HISAX_NETJET) || defined(CONFIG_HISAX_NETJET_U)
1941         {PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_300,     PCI_ANY_ID,PCI_ANY_ID},
1942 #endif
1943 #if defined(CONFIG_HISAX_TELESPCI) || defined(CONFIG_HISAX_SCT_QUADRO)
1944         {PCI_VENDOR_ID_ZORAN,    PCI_DEVICE_ID_ZORAN_36120,      PCI_ANY_ID,PCI_ANY_ID},
1945 #endif
1946 #ifdef CONFIG_HISAX_W6692
1947         {PCI_VENDOR_ID_DYNALINK, PCI_DEVICE_ID_DYNALINK_IS64PH,  PCI_ANY_ID,PCI_ANY_ID},
1948         {PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_6692,    PCI_ANY_ID,PCI_ANY_ID},
1949 #endif
1950 #ifdef CONFIG_HISAX_HFC_PCI
1951         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_2BD0,         PCI_ANY_ID, PCI_ANY_ID},
1952         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B000,         PCI_ANY_ID, PCI_ANY_ID},
1953         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B006,         PCI_ANY_ID, PCI_ANY_ID},
1954         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B007,         PCI_ANY_ID, PCI_ANY_ID},
1955         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B008,         PCI_ANY_ID, PCI_ANY_ID},
1956         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B009,         PCI_ANY_ID, PCI_ANY_ID},
1957         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00A,         PCI_ANY_ID, PCI_ANY_ID},
1958         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00B,         PCI_ANY_ID, PCI_ANY_ID},
1959         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B00C,         PCI_ANY_ID, PCI_ANY_ID},
1960         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B100,         PCI_ANY_ID, PCI_ANY_ID},
1961         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B700,         PCI_ANY_ID, PCI_ANY_ID},
1962         {PCI_VENDOR_ID_CCD,      PCI_DEVICE_ID_CCD_B701,         PCI_ANY_ID, PCI_ANY_ID},
1963         {PCI_VENDOR_ID_ABOCOM,   PCI_DEVICE_ID_ABOCOM_2BD1,      PCI_ANY_ID, PCI_ANY_ID},
1964         {PCI_VENDOR_ID_ASUSTEK,  PCI_DEVICE_ID_ASUSTEK_0675,     PCI_ANY_ID, PCI_ANY_ID},
1965         {PCI_VENDOR_ID_BERKOM,   PCI_DEVICE_ID_BERKOM_T_CONCEPT, PCI_ANY_ID, PCI_ANY_ID},
1966         {PCI_VENDOR_ID_BERKOM,   PCI_DEVICE_ID_BERKOM_A1T,       PCI_ANY_ID, PCI_ANY_ID},
1967         {PCI_VENDOR_ID_ANIGMA,   PCI_DEVICE_ID_ANIGMA_MC145575,  PCI_ANY_ID, PCI_ANY_ID},
1968         {PCI_VENDOR_ID_ZOLTRIX,  PCI_DEVICE_ID_ZOLTRIX_2BD0,     PCI_ANY_ID, PCI_ANY_ID},
1969         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_IOM2_E, PCI_ANY_ID, PCI_ANY_ID},
1970         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_E,      PCI_ANY_ID, PCI_ANY_ID},
1971         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_IOM2_A, PCI_ANY_ID, PCI_ANY_ID},
1972         {PCI_VENDOR_ID_DIGI,     PCI_DEVICE_ID_DIGI_DF_M_A,      PCI_ANY_ID, PCI_ANY_ID},
1973 #endif
1974         { }                             /* Terminating entry */
1975 };
1976
1977 MODULE_DEVICE_TABLE(pci, hisax_pci_tbl);
1978 #endif /* CONFIG_PCI */
1979
1980 module_init(HiSax_init);
1981 module_exit(HiSax_exit);
1982
1983 EXPORT_SYMBOL(FsmNew);
1984 EXPORT_SYMBOL(FsmFree);
1985 EXPORT_SYMBOL(FsmEvent);
1986 EXPORT_SYMBOL(FsmChangeState);
1987 EXPORT_SYMBOL(FsmInitTimer);
1988 EXPORT_SYMBOL(FsmDelTimer);
1989 EXPORT_SYMBOL(FsmRestartTimer);