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