1 /* $Id: module.c,v 1.14.6.4 2001/09/23 22:24:32 kai Exp $
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * Thanks to Friedemann Baitinger and IBM Germany
16 #include "act2000_isa.h"
18 #include <linux/module.h>
19 #include <linux/init.h>
21 static unsigned short act2000_isa_ports
[] =
23 0x0200, 0x0240, 0x0280, 0x02c0, 0x0300, 0x0340, 0x0380,
24 0xcfe0, 0xcfa0, 0xcf60, 0xcf20, 0xcee0, 0xcea0, 0xce60,
27 static act2000_card
*cards
= (act2000_card
*) NULL
;
29 /* Parameters to be set by insmod */
30 static int act_bus
= 0;
31 static int act_port
= -1; /* -1 = Autoprobe */
32 static int act_irq
= -1;
33 static char *act_id
= "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
35 MODULE_DESCRIPTION( "ISDN4Linux: Driver for IBM Active 2000 ISDN card");
36 MODULE_AUTHOR( "Fritz Elfert");
37 MODULE_LICENSE( "GPL");
38 MODULE_PARM_DESC(act_bus
, "BusType of first card, 1=ISA, 2=MCA, 3=PCMCIA, currently only ISA");
39 MODULE_PARM_DESC(membase
, "Base port address of first card");
40 MODULE_PARM_DESC(act_irq
, "IRQ of first card");
41 MODULE_PARM_DESC(act_id
, "ID-String of first card");
42 module_param(act_bus
, int, 0);
43 module_param(act_port
, int, 0);
44 module_param(act_irq
, int, 0);
45 module_param(act_id
, charp
, 0);
47 static int act2000_addcard(int, int, int, char *);
50 find_channel(act2000_card
*card
, int channel
)
52 if ((channel
>= 0) && (channel
< ACT2000_BCH
))
53 return &(card
->bch
[channel
]);
54 printk(KERN_WARNING
"act2000: Invalid channel %d\n", channel
);
62 act2000_clear_msn(act2000_card
*card
)
64 struct msn_entry
*p
= card
->msn_list
;
68 spin_lock_irqsave(&card
->lock
, flags
);
69 card
->msn_list
= NULL
;
70 spin_unlock_irqrestore(&card
->lock
, flags
);
79 * Find an MSN entry in the list.
80 * If ia5 != 0, return IA5-encoded EAZ, else
81 * return a bitmask with corresponding bit set.
84 act2000_find_msn(act2000_card
*card
, char *msn
, int ia5
)
86 struct msn_entry
*p
= card
->msn_list
;
90 if (!strcmp(p
->msn
, msn
)) {
97 return (1 << (eaz
- '0'));
103 * Find an EAZ entry in the list.
104 * return a string with corresponding msn.
107 act2000_find_eaz(act2000_card
*card
, char eaz
)
109 struct msn_entry
*p
= card
->msn_list
;
120 * Add or delete an MSN to the MSN list
122 * First character of msneaz is EAZ, rest is MSN.
123 * If length of eazmsn is 1, delete that entry.
126 act2000_set_msn(act2000_card
*card
, char *eazmsn
)
128 struct msn_entry
*p
= card
->msn_list
;
129 struct msn_entry
*q
= NULL
;
135 if (strlen(eazmsn
) > 16)
137 for (i
= 0; i
< strlen(eazmsn
); i
++)
138 if (!isdigit(eazmsn
[i
]))
140 if (strlen(eazmsn
) == 1) {
141 /* Delete a single MSN */
143 if (p
->eaz
== eazmsn
[0]) {
144 spin_lock_irqsave(&card
->lock
, flags
);
148 card
->msn_list
= p
->next
;
149 spin_unlock_irqrestore(&card
->lock
, flags
);
152 "Mapping for EAZ %c deleted\n",
161 /* Add a single MSN */
163 /* Found in list, replace MSN */
164 if (p
->eaz
== eazmsn
[0]) {
165 spin_lock_irqsave(&card
->lock
, flags
);
166 strcpy(p
->msn
, &eazmsn
[1]);
167 spin_unlock_irqrestore(&card
->lock
, flags
);
169 "Mapping for EAZ %c changed to %s\n",
176 /* Not found in list, add new entry */
177 p
= kmalloc(sizeof(msn_entry
), GFP_KERNEL
);
181 strcpy(p
->msn
, &eazmsn
[1]);
182 p
->next
= card
->msn_list
;
183 spin_lock_irqsave(&card
->lock
, flags
);
185 spin_unlock_irqrestore(&card
->lock
, flags
);
187 "Mapping %c -> %s added\n",
194 act2000_transmit(struct work_struct
*work
)
196 struct act2000_card
*card
=
197 container_of(work
, struct act2000_card
, snd_tq
);
200 case ACT2000_BUS_ISA
:
201 act2000_isa_send(card
);
203 case ACT2000_BUS_PCMCIA
:
204 case ACT2000_BUS_MCA
:
207 "act2000_transmit: Illegal bustype %d\n", card
->bus
);
212 act2000_receive(struct work_struct
*work
)
214 struct act2000_card
*card
=
215 container_of(work
, struct act2000_card
, poll_tq
);
218 case ACT2000_BUS_ISA
:
219 act2000_isa_receive(card
);
221 case ACT2000_BUS_PCMCIA
:
222 case ACT2000_BUS_MCA
:
225 "act2000_receive: Illegal bustype %d\n", card
->bus
);
230 act2000_poll(unsigned long data
)
232 act2000_card
* card
= (act2000_card
*)data
;
235 act2000_receive(&card
->poll_tq
);
236 spin_lock_irqsave(&card
->lock
, flags
);
237 mod_timer(&card
->ptimer
, jiffies
+3);
238 spin_unlock_irqrestore(&card
->lock
, flags
);
242 act2000_command(act2000_card
* card
, isdn_ctrl
* c
)
253 switch (c
->command
) {
255 memcpy(&a
, c
->parm
.num
, sizeof(ulong
));
256 arg
= (void __user
*)a
;
258 case ACT2000_IOCTL_LOADBOOT
:
260 case ACT2000_BUS_ISA
:
261 ret
= act2000_isa_download(card
,
264 card
->flags
|= ACT2000_FLAGS_LOADED
;
265 if (!(card
->flags
& ACT2000_FLAGS_IVALID
)) {
266 card
->ptimer
.expires
= jiffies
+ 3;
267 card
->ptimer
.function
= act2000_poll
;
268 card
->ptimer
.data
= (unsigned long)card
;
269 add_timer(&card
->ptimer
);
271 actcapi_manufacturer_req_errh(card
);
276 "act2000: Illegal BUS type %d\n",
281 case ACT2000_IOCTL_SETPROTO
:
282 card
->ptype
= a
?ISDN_PTYPE_EURO
:ISDN_PTYPE_1TR6
;
283 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
285 actcapi_manufacturer_req_net(card
);
287 case ACT2000_IOCTL_SETMSN
:
288 if (copy_from_user(tmp
, arg
,
291 if ((ret
= act2000_set_msn(card
, tmp
)))
293 if (card
->flags
& ACT2000_FLAGS_RUNNING
)
294 return(actcapi_manufacturer_req_msn(card
));
296 case ACT2000_IOCTL_ADDCARD
:
297 if (copy_from_user(&cdef
, arg
,
300 if (act2000_addcard(cdef
.bus
, cdef
.port
, cdef
.irq
, cdef
.id
))
303 case ACT2000_IOCTL_TEST
:
304 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
312 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
314 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
316 spin_lock_irqsave(&card
->lock
, flags
);
317 if (chan
->fsm_state
!= ACT2000_STATE_NULL
) {
318 spin_unlock_irqrestore(&card
->lock
, flags
);
319 printk(KERN_WARNING
"Dial on channel with state %d\n",
323 if (card
->ptype
== ISDN_PTYPE_EURO
)
324 tmp
[0] = act2000_find_msn(card
, c
->parm
.setup
.eazmsn
, 1);
326 tmp
[0] = c
->parm
.setup
.eazmsn
[0];
327 chan
->fsm_state
= ACT2000_STATE_OCALL
;
328 chan
->callref
= 0xffff;
329 spin_unlock_irqrestore(&card
->lock
, flags
);
330 ret
= actcapi_connect_req(card
, chan
, c
->parm
.setup
.phone
,
331 tmp
[0], c
->parm
.setup
.si1
,
334 cmd
.driver
= card
->myid
;
335 cmd
.command
= ISDN_STAT_DHUP
;
337 card
->interface
.statcallb(&cmd
);
340 case ISDN_CMD_ACCEPTD
:
341 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
343 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
345 if (chan
->fsm_state
== ACT2000_STATE_ICALL
)
346 actcapi_select_b2_protocol_req(card
, chan
);
348 case ISDN_CMD_ACCEPTB
:
349 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
352 case ISDN_CMD_HANGUP
:
353 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
355 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
357 switch (chan
->fsm_state
) {
358 case ACT2000_STATE_ICALL
:
359 case ACT2000_STATE_BSETUP
:
360 actcapi_connect_resp(card
, chan
, 0x15);
362 case ACT2000_STATE_ACTIVE
:
363 actcapi_disconnect_b3_req(card
, chan
);
367 case ISDN_CMD_SETEAZ
:
368 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
370 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
372 if (strlen(c
->parm
.num
)) {
373 if (card
->ptype
== ISDN_PTYPE_EURO
) {
374 chan
->eazmask
= act2000_find_msn(card
, c
->parm
.num
, 0);
376 if (card
->ptype
== ISDN_PTYPE_1TR6
) {
379 for (i
= 0; i
< strlen(c
->parm
.num
); i
++)
380 if (isdigit(c
->parm
.num
[i
]))
381 chan
->eazmask
|= (1 << (c
->parm
.num
[i
] - '0'));
384 chan
->eazmask
= 0x3ff;
385 actcapi_listen_req(card
);
387 case ISDN_CMD_CLREAZ
:
388 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
390 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
393 actcapi_listen_req(card
);
396 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
398 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
400 chan
->l2prot
= (c
->arg
>> 8);
403 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
405 if ((c
->arg
>> 8) != ISDN_PROTO_L3_TRANS
) {
406 printk(KERN_WARNING
"L3 protocol unknown\n");
409 if (!(chan
= find_channel(card
, c
->arg
& 0x0f)))
411 chan
->l3prot
= (c
->arg
>> 8);
419 act2000_sendbuf(act2000_card
*card
, int channel
, int ack
, struct sk_buff
*skb
)
421 struct sk_buff
*xmit_skb
;
426 if (!(chan
= find_channel(card
, channel
)))
428 if (chan
->fsm_state
!= ACT2000_STATE_ACTIVE
)
431 if ((chan
->queued
+ len
) >= ACT2000_MAX_QUEUED
)
435 if (skb_headroom(skb
) < 19) {
436 printk(KERN_WARNING
"act2000_sendbuf: Headroom only %d\n",
438 xmit_skb
= alloc_skb(len
+ 19, GFP_ATOMIC
);
440 printk(KERN_WARNING
"act2000_sendbuf: Out of memory\n");
443 skb_reserve(xmit_skb
, 19);
444 skb_copy_from_linear_data(skb
, skb_put(xmit_skb
, len
), len
);
446 xmit_skb
= skb_clone(skb
, GFP_ATOMIC
);
448 printk(KERN_WARNING
"act2000_sendbuf: Out of memory\n");
453 msg
= (actcapi_msg
*)skb_push(xmit_skb
, 19);
454 msg
->hdr
.len
= 19 + len
;
455 msg
->hdr
.applicationID
= 1;
456 msg
->hdr
.cmd
.cmd
= 0x86;
457 msg
->hdr
.cmd
.subcmd
= 0x00;
458 msg
->hdr
.msgnum
= actcapi_nextsmsg(card
);
459 msg
->msg
.data_b3_req
.datalen
= len
;
460 msg
->msg
.data_b3_req
.blocknr
= (msg
->hdr
.msgnum
& 0xff);
461 msg
->msg
.data_b3_req
.fakencci
= MAKE_NCCI(chan
->plci
, 0, chan
->ncci
);
462 msg
->msg
.data_b3_req
.flags
= ack
; /* Will be set to 0 on actual sending */
463 actcapi_debug_msg(xmit_skb
, 1);
465 skb_queue_tail(&card
->sndq
, xmit_skb
);
466 act2000_schedule_tx(card
);
471 /* Read the Status-replies from the Interface */
473 act2000_readstatus(u_char __user
* buf
, int len
, act2000_card
* card
)
478 for (p
= buf
, count
= 0; count
< len
; p
++, count
++) {
479 if (card
->status_buf_read
== card
->status_buf_write
)
481 put_user(*card
->status_buf_read
++, p
);
482 if (card
->status_buf_read
> card
->status_buf_end
)
483 card
->status_buf_read
= card
->status_buf
;
489 * Find card with given driverId
491 static inline act2000_card
*
492 act2000_findcard(int driverid
)
494 act2000_card
*p
= cards
;
497 if (p
->myid
== driverid
)
501 return (act2000_card
*) 0;
505 * Wrapper functions for interface to linklevel
508 if_command(isdn_ctrl
* c
)
510 act2000_card
*card
= act2000_findcard(c
->driver
);
513 return (act2000_command(card
, c
));
515 "act2000: if_command %d called with invalid driverId %d!\n",
516 c
->command
, c
->driver
);
521 if_writecmd(const u_char __user
*buf
, int len
, int id
, int channel
)
523 act2000_card
*card
= act2000_findcard(id
);
526 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
531 "act2000: if_writecmd called with invalid driverId!\n");
536 if_readstatus(u_char __user
* buf
, int len
, int id
, int channel
)
538 act2000_card
*card
= act2000_findcard(id
);
541 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
543 return (act2000_readstatus(buf
, len
, card
));
546 "act2000: if_readstatus called with invalid driverId!\n");
551 if_sendbuf(int id
, int channel
, int ack
, struct sk_buff
*skb
)
553 act2000_card
*card
= act2000_findcard(id
);
556 if (!(card
->flags
& ACT2000_FLAGS_RUNNING
))
558 return (act2000_sendbuf(card
, channel
, ack
, skb
));
561 "act2000: if_sendbuf called with invalid driverId!\n");
567 * Allocate a new card-struct, initialize it
568 * link it into cards-list.
571 act2000_alloccard(int bus
, int port
, int irq
, char *id
)
575 if (!(card
= kzalloc(sizeof(act2000_card
), GFP_KERNEL
))) {
577 "act2000: (%s) Could not allocate card-struct.\n", id
);
580 spin_lock_init(&card
->lock
);
581 spin_lock_init(&card
->mnlock
);
582 skb_queue_head_init(&card
->sndq
);
583 skb_queue_head_init(&card
->rcvq
);
584 skb_queue_head_init(&card
->ackq
);
585 INIT_WORK(&card
->snd_tq
, act2000_transmit
);
586 INIT_WORK(&card
->rcv_tq
, actcapi_dispatch
);
587 INIT_WORK(&card
->poll_tq
, act2000_receive
);
588 init_timer(&card
->ptimer
);
589 card
->interface
.owner
= THIS_MODULE
;
590 card
->interface
.channels
= ACT2000_BCH
;
591 card
->interface
.maxbufsize
= 4000;
592 card
->interface
.command
= if_command
;
593 card
->interface
.writebuf_skb
= if_sendbuf
;
594 card
->interface
.writecmd
= if_writecmd
;
595 card
->interface
.readstat
= if_readstatus
;
596 card
->interface
.features
=
597 ISDN_FEATURE_L2_X75I
|
598 ISDN_FEATURE_L2_HDLC
|
599 ISDN_FEATURE_L3_TRANS
|
600 ISDN_FEATURE_P_UNKNOWN
;
601 card
->interface
.hl_hdrlen
= 20;
602 card
->ptype
= ISDN_PTYPE_EURO
;
603 strlcpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
));
604 for (i
=0; i
<ACT2000_BCH
; i
++) {
605 card
->bch
[i
].plci
= 0x8000;
606 card
->bch
[i
].ncci
= 0x8000;
607 card
->bch
[i
].l2prot
= ISDN_PROTO_L2_X75I
;
608 card
->bch
[i
].l3prot
= ISDN_PROTO_L3_TRANS
;
619 * register card at linklevel
622 act2000_registercard(act2000_card
* card
)
625 case ACT2000_BUS_ISA
:
627 case ACT2000_BUS_MCA
:
628 case ACT2000_BUS_PCMCIA
:
631 "act2000: Illegal BUS type %d\n",
635 if (!register_isdn(&card
->interface
)) {
637 "act2000: Unable to register %s\n",
641 card
->myid
= card
->interface
.channels
;
642 sprintf(card
->regname
, "act2000-isdn (%s)", card
->interface
.id
);
647 unregister_card(act2000_card
* card
)
651 cmd
.command
= ISDN_STAT_UNLOAD
;
652 cmd
.driver
= card
->myid
;
653 card
->interface
.statcallb(&cmd
);
655 case ACT2000_BUS_ISA
:
656 act2000_isa_release(card
);
658 case ACT2000_BUS_MCA
:
659 case ACT2000_BUS_PCMCIA
:
662 "act2000: Invalid BUS type %d\n",
669 act2000_addcard(int bus
, int port
, int irq
, char *id
)
672 act2000_card
*q
= NULL
;
679 bus
= ACT2000_BUS_ISA
;
681 /* Port defined, do fixed setup */
682 act2000_alloccard(bus
, port
, irq
, id
);
684 /* No port defined, perform autoprobing.
685 * This may result in more than one card detected.
688 case ACT2000_BUS_ISA
:
689 for (i
= 0; i
< ARRAY_SIZE(act2000_isa_ports
); i
++)
690 if (act2000_isa_detect(act2000_isa_ports
[i
])) {
691 printk(KERN_INFO
"act2000: Detected "
692 "ISA card at port 0x%x\n",
693 act2000_isa_ports
[i
]);
694 act2000_alloccard(bus
,
695 act2000_isa_ports
[i
], irq
, id
);
698 case ACT2000_BUS_MCA
:
699 case ACT2000_BUS_PCMCIA
:
702 "act2000: addcard: Invalid BUS type %d\n", bus
);
710 if (!p
->interface
.statcallb
) {
711 /* Not yet registered.
712 * Try to register and activate it.
716 case ACT2000_BUS_ISA
:
717 if (act2000_isa_detect(p
->port
)) {
718 if (act2000_registercard(p
))
720 if (act2000_isa_config_port(p
, p
->port
)) {
722 "act2000: Could not request port 0x%04x\n",
725 p
->interface
.statcallb
= NULL
;
728 if (act2000_isa_config_irq(p
, p
->irq
)) {
730 "act2000: No IRQ available, fallback to polling\n");
731 /* Fall back to polled operation */
736 "-type card at port "
740 printk("irq %d\n", p
->irq
);
746 case ACT2000_BUS_MCA
:
747 case ACT2000_BUS_PCMCIA
:
750 "act2000: addcard: Invalid BUS type %d\n",
754 /* Card already initialized */
757 /* Init OK, next card ... */
761 /* Init failed, remove card from list, free memory */
763 "act2000: Initialization of %s failed\n",
777 return (added
- failed
);
780 #define DRIVERNAME "IBM Active 2000 ISDN driver"
782 static int __init
act2000_init(void)
784 printk(KERN_INFO
"%s\n", DRIVERNAME
);
786 act2000_addcard(act_bus
, act_port
, act_irq
, act_id
);
788 printk(KERN_INFO
"act2000: No cards defined yet\n");
792 static void __exit
act2000_exit(void)
794 act2000_card
*card
= cards
;
797 unregister_card(card
);
798 del_timer(&card
->ptimer
);
805 act2000_clear_msn(last
);
808 printk(KERN_INFO
"%s unloaded\n", DRIVERNAME
);
811 module_init(act2000_init
);
812 module_exit(act2000_exit
);