18 #include <linux/module.h>
19 #include <linux/slab.h>
22 static unsigned short act2000_isa_ports[] =
24 0x0200, 0x0240, 0x0280, 0x02c0, 0x0300, 0x0340, 0x0380,
25 0xcfe0, 0xcfa0, 0xcf60, 0xcf20, 0xcee0, 0xcea0, 0xce60,
28 static act2000_card *cards = (act2000_card *)
NULL;
31 static int act_bus = 0;
32 static int act_port = -1;
33 static int act_irq = -1;
34 static char *act_id =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
39 MODULE_PARM_DESC(act_bus,
"BusType of first card, 1=ISA, 2=MCA, 3=PCMCIA, currently only ISA");
48 static int act2000_addcard(
int,
int,
int,
char *);
53 if ((channel >= 0) && (channel < ACT2000_BCH))
63 act2000_clear_msn(act2000_card *card)
65 struct msn_entry *
p = card->msn_list;
70 card->msn_list =
NULL;
71 spin_unlock_irqrestore(&card->lock, flags);
85 act2000_find_msn(act2000_card *card,
char *
msn,
int ia5)
87 struct msn_entry *p = card->msn_list;
91 if (!
strcmp(p->msn, msn)) {
98 return (1 << (eaz -
'0'));
110 struct msn_entry *p = card->msn_list;
127 act2000_set_msn(act2000_card *card,
char *eazmsn)
129 struct msn_entry *p = card->msn_list;
130 struct msn_entry *q =
NULL;
138 for (i = 0; i <
strlen(eazmsn); i++)
141 if (
strlen(eazmsn) == 1) {
144 if (p->eaz == eazmsn[0]) {
149 card->msn_list = p->next;
150 spin_unlock_irqrestore(&card->lock, flags);
153 "Mapping for EAZ %c deleted\n",
165 if (p->eaz == eazmsn[0]) {
167 strcpy(p->msn, &eazmsn[1]);
168 spin_unlock_irqrestore(&card->lock, flags);
170 "Mapping for EAZ %c changed to %s\n",
182 strcpy(p->msn, &eazmsn[1]);
183 p->next = card->msn_list;
186 spin_unlock_irqrestore(&card->lock, flags);
188 "Mapping %c -> %s added\n",
197 struct act2000_card *card =
208 "act2000_transmit: Illegal bustype %d\n", card->bus);
215 struct act2000_card *card =
226 "act2000_receive: Illegal bustype %d\n", card->bus);
231 act2000_poll(
unsigned long data)
233 act2000_card *card = (act2000_card *)data;
236 act2000_receive(&card->poll_tq);
239 spin_unlock_irqrestore(&card->lock, flags);
243 act2000_command(act2000_card *card,
isdn_ctrl *
c)
265 card->flags |= ACT2000_FLAGS_LOADED;
266 if (!(card->flags & ACT2000_FLAGS_IVALID)) {
267 card->ptimer.expires =
jiffies + 3;
268 card->ptimer.function = act2000_poll;
269 card->ptimer.data = (
unsigned long)card;
277 "act2000: Illegal BUS type %d\n",
284 if (!(card->flags & ACT2000_FLAGS_RUNNING))
292 if ((ret = act2000_set_msn(card, tmp)))
294 if (card->flags & ACT2000_FLAGS_RUNNING)
301 if (act2000_addcard(cdef.
bus, cdef.
port, cdef.
irq, cdef.
id))
305 if (!(card->flags & ACT2000_FLAGS_RUNNING))
313 if (!(card->flags & ACT2000_FLAGS_RUNNING))
315 if (!(chan = find_channel(card, c->
arg & 0x0f)))
318 if (chan->fsm_state != ACT2000_STATE_NULL) {
319 spin_unlock_irqrestore(&card->lock, flags);
328 chan->fsm_state = ACT2000_STATE_OCALL;
329 chan->callref = 0xffff;
330 spin_unlock_irqrestore(&card->lock, flags);
338 card->interface.statcallb(&cmd);
342 if (!(card->flags & ACT2000_FLAGS_RUNNING))
344 if (!(chan = find_channel(card, c->
arg & 0x0f)))
346 if (chan->fsm_state == ACT2000_STATE_ICALL)
350 if (!(card->flags & ACT2000_FLAGS_RUNNING))
354 if (!(card->flags & ACT2000_FLAGS_RUNNING))
356 if (!(chan = find_channel(card, c->
arg & 0x0f)))
358 switch (chan->fsm_state) {
359 case ACT2000_STATE_ICALL:
360 case ACT2000_STATE_BSETUP:
363 case ACT2000_STATE_ACTIVE:
369 if (!(card->flags & ACT2000_FLAGS_RUNNING))
371 if (!(chan = find_channel(card, c->
arg & 0x0f)))
375 chan->eazmask = act2000_find_msn(card, c->
parm.
num, 0);
382 chan->eazmask |= (1 << (c->
parm.
num[i] -
'0'));
385 chan->eazmask = 0x3ff;
389 if (!(card->flags & ACT2000_FLAGS_RUNNING))
391 if (!(chan = find_channel(card, c->
arg & 0x0f)))
397 if (!(card->flags & ACT2000_FLAGS_RUNNING))
399 if (!(chan = find_channel(card, c->
arg & 0x0f)))
401 chan->l2prot = (c->
arg >> 8);
404 if (!(card->flags & ACT2000_FLAGS_RUNNING))
410 if (!(chan = find_channel(card, c->
arg & 0x0f)))
412 chan->l3prot = (c->
arg >> 8);
420 act2000_sendbuf(act2000_card *card,
int channel,
int ack,
struct sk_buff *
skb)
427 if (!(chan = find_channel(card, channel)))
429 if (chan->fsm_state != ACT2000_STATE_ACTIVE)
432 if ((chan->queued + len) >= ACT2000_MAX_QUEUED)
436 if (skb_headroom(skb) < 19) {
444 skb_reserve(xmit_skb, 19);
445 skb_copy_from_linear_data(skb,
skb_put(xmit_skb, len), len);
459 msg->
hdr.
msgnum = actcapi_nextsmsg(card);
467 act2000_schedule_tx(card);
474 act2000_readstatus(
u_char __user *
buf,
int len, act2000_card *card)
479 for (p = buf, count = 0; count <
len; p++, count++) {
480 if (card->status_buf_read == card->status_buf_write)
482 put_user(*card->status_buf_read++, p);
483 if (card->status_buf_read > card->status_buf_end)
484 card->status_buf_read = card->status_buf;
492 static inline act2000_card *
493 act2000_findcard(
int driverid)
495 act2000_card *p = cards;
498 if (p->myid == driverid)
502 return (act2000_card *) 0;
511 act2000_card *card = act2000_findcard(c->
driver);
514 return (act2000_command(card, c));
516 "act2000: if_command %d called with invalid driverId %d!\n",
522 if_writecmd(
const u_char __user *buf,
int len,
int id,
int channel)
524 act2000_card *card = act2000_findcard(
id);
527 if (!(card->flags & ACT2000_FLAGS_RUNNING))
532 "act2000: if_writecmd called with invalid driverId!\n");
537 if_readstatus(
u_char __user *buf,
int len,
int id,
int channel)
539 act2000_card *card = act2000_findcard(
id);
542 if (!(card->flags & ACT2000_FLAGS_RUNNING))
544 return (act2000_readstatus(buf, len, card));
547 "act2000: if_readstatus called with invalid driverId!\n");
552 if_sendbuf(
int id,
int channel,
int ack,
struct sk_buff *skb)
554 act2000_card *card = act2000_findcard(
id);
557 if (!(card->flags & ACT2000_FLAGS_RUNNING))
559 return (act2000_sendbuf(card, channel, ack, skb));
562 "act2000: if_sendbuf called with invalid driverId!\n");
572 act2000_alloccard(
int bus,
int port,
int irq,
char *
id)
576 if (!(card = kzalloc(
sizeof(act2000_card),
GFP_KERNEL))) {
578 "act2000: (%s) Could not allocate card-struct.\n",
id);
583 skb_queue_head_init(&card->sndq);
584 skb_queue_head_init(&card->rcvq);
585 skb_queue_head_init(&card->ackq);
586 INIT_WORK(&card->snd_tq, act2000_transmit);
588 INIT_WORK(&card->poll_tq, act2000_receive);
591 card->interface.channels = ACT2000_BCH;
592 card->interface.maxbufsize = 4000;
593 card->interface.command = if_command;
594 card->interface.writebuf_skb = if_sendbuf;
595 card->interface.writecmd = if_writecmd;
596 card->interface.readstat = if_readstatus;
597 card->interface.features =
602 card->interface.hl_hdrlen = 20;
604 strlcpy(card->interface.id,
id,
sizeof(card->interface.id));
605 for (i = 0; i < ACT2000_BCH; i++) {
606 card->bch[
i].plci = 0x8000;
607 card->bch[
i].ncci = 0x8000;
623 act2000_registercard(act2000_card *card)
632 "act2000: Illegal BUS type %d\n",
638 "act2000: Unable to register %s\n",
642 card->myid = card->interface.channels;
643 sprintf(card->regname,
"act2000-isdn (%s)", card->interface.id);
648 unregister_card(act2000_card *card)
654 card->interface.statcallb(&cmd);
663 "act2000: Invalid BUS type %d\n",
670 act2000_addcard(
int bus,
int port,
int irq,
char *
id)
673 act2000_card *q =
NULL;
683 act2000_alloccard(bus, port, irq,
id);
690 for (i = 0; i <
ARRAY_SIZE(act2000_isa_ports); i++)
693 "ISA card at port 0x%x\n",
694 act2000_isa_ports[i]);
695 act2000_alloccard(bus,
696 act2000_isa_ports[i], irq,
id);
703 "act2000: addcard: Invalid BUS type %d\n", bus);
711 if (!p->interface.statcallb) {
719 if (act2000_registercard(p))
723 "act2000: Could not request port 0x%04x\n",
726 p->interface.statcallb =
NULL;
731 "act2000: No IRQ available, fallback to polling\n");
737 "-type card at port "
741 printk(
"irq %d\n", p->irq);
751 "act2000: addcard: Invalid BUS type %d\n",
764 "act2000: Initialization of %s failed\n",
778 return (added - failed);
781 #define DRIVERNAME "IBM Active 2000 ISDN driver"
783 static int __init act2000_init(
void)
787 act2000_addcard(act_bus, act_port, act_irq, act_id);
793 static void __exit act2000_exit(
void)
795 act2000_card *card = cards;
798 unregister_card(card);
806 act2000_clear_msn(last);