20 #include <linux/module.h>
23 #include <linux/kernel.h>
25 #include <linux/types.h>
26 #include <linux/sched.h>
27 #include <linux/slab.h>
30 #include <linux/string.h>
33 #include <linux/isdnif.h>
34 #include <asm/string.h>
60 static int pcbit_stat(
u_char __user *
buf,
int len,
int,
int);
62 static int pcbit_writecmd(
const u_char __user *,
int,
int,
int);
64 static int set_protocol_running(
struct pcbit_dev *
dev);
66 static void pcbit_clear_msn(
struct pcbit_dev *
dev);
67 static void pcbit_set_msn(
struct pcbit_dev *
dev,
char *
list);
68 static int pcbit_check_msn(
struct pcbit_dev *
dev,
char *
msn);
73 struct pcbit_dev *
dev;
78 printk(
"pcbit_init: couldn't malloc pcbit_dev struct\n");
86 if (mem_base >= 0xA0000 && mem_base <= 0xFFFFF) {
90 "PCBIT: memory region %lx-%lx already in use\n",
91 dev->ph_mem, dev->ph_mem + 4096);
96 dev->sh_mem =
ioremap(dev->ph_mem, 4096);
100 printk(
"memory address invalid");
106 dev->b1 = kzalloc(
sizeof(
struct pcbit_chan),
GFP_KERNEL);
108 printk(
"pcbit_init: couldn't malloc pcbit_chan struct\n");
115 dev->b2 = kzalloc(
sizeof(
struct pcbit_chan),
GFP_KERNEL);
117 printk(
"pcbit_init: couldn't malloc pcbit_chan struct\n");
166 dev->dev_if = dev_if;
179 dev_if->
command = pcbit_command;
185 strcpy(dev_if->
id, pcbit_devname[board]);
214 struct pcbit_dev *
dev;
221 pcbit_clear_msn(dev);
223 if (dev->b1->fsm_timer.function)
225 if (dev->b2->fsm_timer.function)
238 struct pcbit_dev *
dev;
239 struct pcbit_chan *
chan;
242 dev = finddev(ctl->
driver);
246 printk(
"pcbit_command: unknown device\n");
250 chan = (ctl->
arg & 0x0F) ? dev->b2 : dev->b1;
266 printk(
"ISDN_CMD_ACCEPTB - not really needed\n");
272 chan->proto = (ctl->
arg >> 8);
275 pcbit_clear_msn(dev);
278 pcbit_set_msn(dev, ctl->
parm.
num);
299 static void pcbit_block_timer(
unsigned long data)
301 struct pcbit_chan *chan;
302 struct pcbit_dev *
dev;
305 chan = (
struct pcbit_chan *)data;
307 dev = chan2dev(chan);
315 chan->block_timer.function =
NULL;
324 dev->dev_if->statcallb(&ictl);
332 struct pcbit_chan *chan;
333 struct pcbit_dev *
dev;
335 dev = finddev(driver);
338 printk(
"finddev returned NULL");
342 chan = chnum ? dev->b2 : dev->b1;
352 "pcbit: %d packets already in queue - write fails\n",
361 if (chan->block_timer.function ==
NULL) {
363 chan->block_timer.function = &pcbit_block_timer;
364 chan->block_timer.data = (
long) chan;
365 chan->block_timer.expires =
jiffies + 1 *
HZ;
380 chan->s_refnum = refnum;
387 static int pcbit_writecmd(
const u_char __user *
buf,
int len,
int driver,
int channel)
389 struct pcbit_dev *
dev;
397 dev = finddev(driver);
401 printk(
"pcbit_writecmd: couldn't find device");
405 switch (dev->l2_state) {
408 if (len < 0 || len >
BANK4 + 1 || len > 1024)
410 printk(
"pcbit_writecmd: invalid length %d\n", len);
416 return PTR_ERR(cbuf);
435 for (i = 0; i < len; i++)
438 if (!(
readb(dev->sh_mem + dev->loadptr)))
444 printk(
"TIMEOUT i=%d\n", i);
447 writeb(loadbuf[i], dev->sh_mem + dev->loadptr + 1);
448 writeb(0x01, dev->sh_mem + dev->loadptr);
456 return errstat ? errstat : len;
471 struct pcbit_chan *chan;
481 if (!(chan = capi_channel(dev, skb))) {
483 "CAPI header: unknown channel id\n");
486 chan->r_refnum = skb->
data[7];
489 dev->dev_if->rcvcallb_skb(dev->id, chan->id, skb);
497 if (!(chan = capi_channel(dev, skb))) {
499 "CAPI header: unknown channel id\n");
511 chan->block_timer.function =
NULL;
520 dev->dev_if->statcallb(&ictl);
529 if (!dev->b1->fsm_state)
531 else if (!dev->b2->fsm_state)
535 "Incoming connection: no channels available");
550 if (pcbit_check_msn(dev, cbdata.
data.
setup.CallingPN))
595 if (!(chan = capi_channel(dev, skb))) {
597 "CAPI header: unknown channel id\n");
602 printk(
"error in capi_decode_conn_actv_ind\n");
606 chan->r_refnum = refnum;
611 if (!(chan = capi_channel(dev, skb))) {
613 "CAPI header: unknown channel id\n");
626 if (!(chan = capi_channel(dev, skb))) {
628 "CAPI header: unknown channel id\n");
636 printk(
"error %d - capi_decode_sel_proto_conf\n", err);
640 if (!(chan = capi_channel(dev, skb))) {
642 "CAPI header: unknown channel id\n");
652 if (!(chan = capi_channel(dev, skb))) {
654 "CAPI header: unknown channel id\n");
664 if (!(chan = capi_channel(dev, skb))) {
666 "CAPI header: unknown channel id\n");
682 capi_decode_debug_188(skb->
data, skb->
len);
701 static char statbuf[STATBUF_LEN];
702 static int stat_st = 0;
703 static int stat_end = 0;
705 static int pcbit_stat(
u_char __user *buf,
int len,
int driver,
int channel)
708 stat_count = stat_end - stat_st;
711 stat_count = STATBUF_LEN - stat_st + stat_end;
714 if (len > stat_count)
717 if (stat_st < stat_end)
725 if (len > STATBUF_LEN - stat_st)
728 STATBUF_LEN - stat_st))
731 len - (STATBUF_LEN - stat_st)))
734 stat_st = len - (STATBUF_LEN - stat_st);
743 if (stat_st == STATBUF_LEN)
748 if (stat_st == stat_end)
749 stat_st = stat_end = 0;
754 static void pcbit_logstat(
struct pcbit_dev *dev,
char *
str)
759 for (i = stat_end; i <
strlen(str); i++)
762 stat_end = (stat_end + 1) % STATBUF_LEN;
763 if (stat_end == stat_st)
764 stat_st = (stat_st + 1) % STATBUF_LEN;
770 dev->dev_if->statcallb(&ictl);
774 unsigned short i,
unsigned short ev,
unsigned short f)
778 sprintf(buf,
"change on device: %d channel:%d\n%s -> %s -> %s\n",
787 pcbit_logstat(dev, buf);
790 static void set_running_timeout(
unsigned long ptr)
792 struct pcbit_dev *
dev;
797 dev = (
struct pcbit_dev *) ptr;
802 static int set_protocol_running(
struct pcbit_dev *dev)
808 dev->set_running_timer.function = &set_running_timeout;
809 dev->set_running_timer.data = (
ulong) dev;
816 writeb((0x80U | ((dev->rcv_seq & 0x07) << 3) | (dev->send_seq & 0x07)),
817 dev->sh_mem +
BANK4);
829 dev->unack_seq = dev->send_seq;
831 dev->writeptr = dev->sh_mem;
832 dev->readptr = dev->sh_mem +
BANK2;
838 dev->dev_if->statcallb(&ctl);
857 dev->dev_if->statcallb(&ctl);
867 struct pcbit_dev *
dev;
870 dev = finddev(ctl->
driver);
889 dev->unack_seq = dev->send_seq = dev->rcv_seq = 0;
891 dev->writeptr = dev->sh_mem;
892 dev->readptr = dev->sh_mem +
BANK2;
944 return set_protocol_running(dev);
969 printk(
"error: unknown ioctl\n");
982 static void pcbit_clear_msn(
struct pcbit_dev *dev)
984 struct msn_entry *
ptr, *back;
986 for (ptr = dev->msn_list; ptr;)
993 dev->msn_list =
NULL;
996 static void pcbit_set_msn(
struct pcbit_dev *dev,
char *
list)
998 struct msn_entry *
ptr;
999 struct msn_entry *back =
NULL;
1012 ptr->next = dev->msn_list;
1013 dev->msn_list =
ptr;
1019 for (back = dev->msn_list; back->next; back = back->next);
1045 memcpy(ptr->msn, sp, len - 1);
1051 if (dev->msn_list ==
NULL)
1052 dev->msn_list =
ptr;
1063 static int pcbit_check_msn(
struct pcbit_dev *dev,
char *
msn)
1065 struct msn_entry *
ptr;
1067 for (ptr = dev->msn_list; ptr; ptr = ptr->next) {
1069 if (ptr->msn ==
NULL)
1072 if (
strcmp(ptr->msn, msn) == 0)