1 /* $Id: icn.c,v 1.65.6.8 2001/09/23 22:24:55 kai Exp $
3 * ISDN low-level module for the ICN active ISDN-Card.
5 * Copyright 1994,95,96 by Fritz Elfert (fritz@isdn4linux.de)
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
17 static int portbase
= ICN_BASEADDR
;
18 static unsigned long membase
= ICN_MEMADDR
;
19 static char *icn_id
= "\0";
20 static char *icn_id2
= "\0";
22 MODULE_DESCRIPTION("ISDN4Linux: Driver for ICN active ISDN card");
23 MODULE_AUTHOR("Fritz Elfert");
24 MODULE_LICENSE("GPL");
25 module_param(portbase
, int, 0);
26 MODULE_PARM_DESC(portbase
, "Port address of first card");
27 module_param(membase
, ulong
, 0);
28 MODULE_PARM_DESC(membase
, "Shared memory address of all cards");
29 module_param(icn_id
, charp
, 0);
30 MODULE_PARM_DESC(icn_id
, "ID-String of first card");
31 module_param(icn_id2
, charp
, 0);
32 MODULE_PARM_DESC(icn_id2
, "ID-String of first card, second S0 (4B only)");
35 * Verbose bootcode- and protocol-downloading.
40 * Verbose Shmem-Mapping.
45 *revision
= "$Revision: 1.65.6.8 $";
47 static int icn_addcard(int, char *, char *);
50 * Free send-queue completely.
52 * card = pointer to card struct
53 * channel = channel number
56 icn_free_queue(icn_card
* card
, int channel
)
58 struct sk_buff_head
*queue
= &card
->spqueue
[channel
];
61 skb_queue_purge(queue
);
62 card
->xlen
[channel
] = 0;
63 card
->sndcount
[channel
] = 0;
64 if ((skb
= card
->xskb
[channel
])) {
65 card
->xskb
[channel
] = NULL
;
70 /* Put a value into a shift-register, highest bit first.
72 * port = port for output (bit 0 is significant)
73 * val = value to be output
74 * firstbit = Bit-Number of highest bit
75 * bitcount = Number of bits to output
78 icn_shiftout(unsigned short port
,
87 for (s
= firstbit
, c
= bitcount
; c
> 0; s
--, c
--)
88 OUTB_P((u_char
) ((val
>> s
) & 1) ? 0xff : 0, port
);
92 * disable a cards shared memory
95 icn_disable_ram(icn_card
* card
)
97 OUTB_P(0, ICN_MAPRAM
);
101 * enable a cards shared memory
104 icn_enable_ram(icn_card
* card
)
106 OUTB_P(0xff, ICN_MAPRAM
);
110 * Map a cards channel0 (Bank0/Bank8) or channel1 (Bank4/Bank12)
112 * must called with holding the devlock
115 icn_map_channel(icn_card
* card
, int channel
)
118 printk(KERN_DEBUG
"icn_map_channel %d %d\n", dev
.channel
, channel
);
120 if ((channel
== dev
.channel
) && (card
== dev
.mcard
))
123 icn_disable_ram(dev
.mcard
);
124 icn_shiftout(ICN_BANK
, chan2bank
[channel
], 3, 4); /* Select Bank */
125 icn_enable_ram(card
);
127 dev
.channel
= channel
;
129 printk(KERN_DEBUG
"icn_map_channel done\n");
134 * Lock a cards channel.
135 * Return 0 if requested card/channel is unmapped (failure).
136 * Return 1 on success.
138 * must called with holding the devlock
141 icn_lock_channel(icn_card
* card
, int channel
)
146 printk(KERN_DEBUG
"icn_lock_channel %d\n", channel
);
148 if ((dev
.channel
== channel
) && (card
== dev
.mcard
)) {
152 printk(KERN_DEBUG
"icn_lock_channel %d OK\n", channel
);
157 printk(KERN_DEBUG
"icn_lock_channel %d FAILED, dc=%d\n", channel
, dev
.channel
);
164 * Release current card/channel lock
166 * must called with holding the devlock
169 __icn_release_channel(void)
172 printk(KERN_DEBUG
"icn_release_channel l=%d\n", dev
.chanlock
);
174 if (dev
.chanlock
> 0)
179 * Release current card/channel lock
182 icn_release_channel(void)
186 spin_lock_irqsave(&dev
.devlock
, flags
);
187 __icn_release_channel();
188 spin_unlock_irqrestore(&dev
.devlock
, flags
);
192 * Try to map and lock a cards channel.
193 * Return 1 on success, 0 on failure.
196 icn_trymaplock_channel(icn_card
* card
, int channel
)
201 printk(KERN_DEBUG
"trymaplock c=%d dc=%d l=%d\n", channel
, dev
.channel
,
204 spin_lock_irqsave(&dev
.devlock
, flags
);
205 if ((!dev
.chanlock
) ||
206 ((dev
.channel
== channel
) && (dev
.mcard
== card
))) {
208 icn_map_channel(card
, channel
);
209 spin_unlock_irqrestore(&dev
.devlock
, flags
);
211 printk(KERN_DEBUG
"trymaplock %d OK\n", channel
);
215 spin_unlock_irqrestore(&dev
.devlock
, flags
);
217 printk(KERN_DEBUG
"trymaplock %d FAILED\n", channel
);
223 * Release current card/channel lock,
224 * then map same or other channel without locking.
227 icn_maprelease_channel(icn_card
* card
, int channel
)
232 printk(KERN_DEBUG
"map_release c=%d l=%d\n", channel
, dev
.chanlock
);
234 spin_lock_irqsave(&dev
.devlock
, flags
);
235 if (dev
.chanlock
> 0)
238 icn_map_channel(card
, channel
);
239 spin_unlock_irqrestore(&dev
.devlock
, flags
);
242 /* Get Data from the B-Channel, assemble fragmented packets and put them
243 * into receive-queue. Wake up any B-Channel-reading processes.
244 * This routine is called via timer-callback from icn_pollbchan().
248 icn_pollbchan_receive(int channel
, icn_card
* card
)
250 int mch
= channel
+ ((card
->secondhalf
) ? 2 : 0);
255 if (icn_trymaplock_channel(card
, mch
)) {
257 cnt
= readb(&rbuf_l
);
258 if ((card
->rcvidx
[channel
] + cnt
) > 4000) {
260 "icn: (%s) bogus packet on ch%d, dropping.\n",
263 card
->rcvidx
[channel
] = 0;
266 memcpy_fromio(&card
->rcvbuf
[channel
][card
->rcvidx
[channel
]],
268 card
->rcvidx
[channel
] += cnt
;
269 eflag
= readb(&rbuf_f
);
272 icn_maprelease_channel(card
, mch
& 2);
274 if ((cnt
= card
->rcvidx
[channel
])) {
275 if (!(skb
= dev_alloc_skb(cnt
))) {
276 printk(KERN_WARNING
"icn: receive out of memory\n");
279 memcpy(skb_put(skb
, cnt
), card
->rcvbuf
[channel
], cnt
);
280 card
->rcvidx
[channel
] = 0;
281 card
->interface
.rcvcallb_skb(card
->myid
, channel
, skb
);
284 if (!icn_trymaplock_channel(card
, mch
))
287 icn_maprelease_channel(card
, mch
& 2);
291 /* Send data-packet to B-Channel, split it up into fragments of
292 * ICN_FRAGSIZE length. If last fragment is sent out, signal
293 * success to upper layers via statcallb with ISDN_STAT_BSENT argument.
294 * This routine is called via timer-callback from icn_pollbchan() or
295 * directly from icn_sendbuf().
299 icn_pollbchan_send(int channel
, icn_card
* card
)
301 int mch
= channel
+ ((card
->secondhalf
) ? 2 : 0);
307 if (!(card
->sndcount
[channel
] || card
->xskb
[channel
] ||
308 !skb_queue_empty(&card
->spqueue
[channel
])))
310 if (icn_trymaplock_channel(card
, mch
)) {
312 (card
->sndcount
[channel
] ||
313 !skb_queue_empty(&card
->spqueue
[channel
]) ||
314 card
->xskb
[channel
])) {
315 spin_lock_irqsave(&card
->lock
, flags
);
316 if (card
->xmit_lock
[channel
]) {
317 spin_unlock_irqrestore(&card
->lock
, flags
);
320 card
->xmit_lock
[channel
]++;
321 spin_unlock_irqrestore(&card
->lock
, flags
);
322 skb
= card
->xskb
[channel
];
324 skb
= skb_dequeue(&card
->spqueue
[channel
]);
326 /* Pop ACK-flag off skb.
327 * Store length to xlen.
329 if (*(skb_pull(skb
,1)))
330 card
->xlen
[channel
] = skb
->len
;
332 card
->xlen
[channel
] = 0;
337 if (skb
->len
> ICN_FRAGSIZE
) {
338 writeb(0xff, &sbuf_f
);
341 writeb(0x0, &sbuf_f
);
344 writeb(cnt
, &sbuf_l
);
345 memcpy_toio(&sbuf_d
, skb
->data
, cnt
);
347 sbnext
; /* switch to next buffer */
348 icn_maprelease_channel(card
, mch
& 2);
349 spin_lock_irqsave(&card
->lock
, flags
);
350 card
->sndcount
[channel
] -= cnt
;
352 if (card
->xskb
[channel
])
353 card
->xskb
[channel
] = NULL
;
354 card
->xmit_lock
[channel
] = 0;
355 spin_unlock_irqrestore(&card
->lock
, flags
);
357 if (card
->xlen
[channel
]) {
358 cmd
.command
= ISDN_STAT_BSENT
;
359 cmd
.driver
= card
->myid
;
361 cmd
.parm
.length
= card
->xlen
[channel
];
362 card
->interface
.statcallb(&cmd
);
365 card
->xskb
[channel
] = skb
;
366 card
->xmit_lock
[channel
] = 0;
367 spin_unlock_irqrestore(&card
->lock
, flags
);
369 if (!icn_trymaplock_channel(card
, mch
))
372 icn_maprelease_channel(card
, mch
& 2);
376 /* Send/Receive Data to/from the B-Channel.
377 * This routine is called via timer-callback.
378 * It schedules itself while any B-Channel is open.
382 icn_pollbchan(unsigned long data
)
384 icn_card
*card
= (icn_card
*) data
;
387 if (card
->flags
& ICN_FLAGS_B1ACTIVE
) {
388 icn_pollbchan_receive(0, card
);
389 icn_pollbchan_send(0, card
);
391 if (card
->flags
& ICN_FLAGS_B2ACTIVE
) {
392 icn_pollbchan_receive(1, card
);
393 icn_pollbchan_send(1, card
);
395 if (card
->flags
& (ICN_FLAGS_B1ACTIVE
| ICN_FLAGS_B2ACTIVE
)) {
396 /* schedule b-channel polling again */
397 spin_lock_irqsave(&card
->lock
, flags
);
398 mod_timer(&card
->rb_timer
, jiffies
+ICN_TIMER_BCREAD
);
399 card
->flags
|= ICN_FLAGS_RBTIMER
;
400 spin_unlock_irqrestore(&card
->lock
, flags
);
402 card
->flags
&= ~ICN_FLAGS_RBTIMER
;
405 typedef struct icn_stat
{
411 static icn_stat icn_stat_table
[] =
413 {"BCON_", ISDN_STAT_BCONN
, 1}, /* B-Channel connected */
414 {"BDIS_", ISDN_STAT_BHUP
, 2}, /* B-Channel disconnected */
416 ** add d-channel connect and disconnect support to link-level
418 {"DCON_", ISDN_STAT_DCONN
, 10}, /* D-Channel connected */
419 {"DDIS_", ISDN_STAT_DHUP
, 11}, /* D-Channel disconnected */
420 {"DCAL_I", ISDN_STAT_ICALL
, 3}, /* Incoming call dialup-line */
421 {"DSCA_I", ISDN_STAT_ICALL
, 3}, /* Incoming call 1TR6-SPV */
422 {"FCALL", ISDN_STAT_ICALL
, 4}, /* Leased line connection up */
423 {"CIF", ISDN_STAT_CINF
, 5}, /* Charge-info, 1TR6-type */
424 {"AOC", ISDN_STAT_CINF
, 6}, /* Charge-info, DSS1-type */
425 {"CAU", ISDN_STAT_CAUSE
, 7}, /* Cause code */
426 {"TEI OK", ISDN_STAT_RUN
, 0}, /* Card connected to wallplug */
427 {"E_L1: ACT FAIL", ISDN_STAT_BHUP
, 8}, /* Layer-1 activation failed */
428 {"E_L2: DATA LIN", ISDN_STAT_BHUP
, 8}, /* Layer-2 data link lost */
429 {"E_L1: ACTIVATION FAILED",
430 ISDN_STAT_BHUP
, 8}, /* Layer-1 activation failed */
437 * Check Statusqueue-Pointer from isdn-cards.
438 * If there are new status-replies from the interface, check
439 * them against B-Channel-connects/disconnects and set flags accordingly.
440 * Wake-Up any processes, who are reading the status-device.
441 * If there are B-Channels open, initiate a timer-callback to
443 * This routine is called periodically via timer.
447 icn_parse_status(u_char
* status
, int channel
, icn_card
* card
)
449 icn_stat
*s
= icn_stat_table
;
455 if (!strncmp(status
, s
->statstr
, strlen(s
->statstr
))) {
456 cmd
.command
= s
->command
;
464 cmd
.driver
= card
->myid
;
468 spin_lock_irqsave(&card
->lock
, flags
);
469 icn_free_queue(card
,channel
);
470 card
->rcvidx
[channel
] = 0;
473 ((channel
)?ICN_FLAGS_B2ACTIVE
:ICN_FLAGS_B1ACTIVE
)) {
477 card
->flags
&= ~((channel
)?
478 ICN_FLAGS_B2ACTIVE
:ICN_FLAGS_B1ACTIVE
);
480 memset(&ncmd
, 0, sizeof(ncmd
));
482 ncmd
.driver
= card
->myid
;
484 ncmd
.command
= ISDN_STAT_BHUP
;
485 spin_unlock_irqrestore(&card
->lock
, flags
);
486 card
->interface
.statcallb(&cmd
);
488 spin_unlock_irqrestore(&card
->lock
, flags
);
491 spin_lock_irqsave(&card
->lock
, flags
);
492 icn_free_queue(card
,channel
);
493 card
->flags
|= (channel
) ?
494 ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
;
495 spin_unlock_irqrestore(&card
->lock
, flags
);
498 spin_lock_irqsave(&card
->lock
, flags
);
499 card
->flags
&= ~((channel
) ?
500 ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
);
501 icn_free_queue(card
, channel
);
502 card
->rcvidx
[channel
] = 0;
503 spin_unlock_irqrestore(&card
->lock
, flags
);
507 char *t
= status
+ 6;
508 char *s
= strchr(t
, ',');
511 strlcpy(cmd
.parm
.setup
.phone
, t
,
512 sizeof(cmd
.parm
.setup
.phone
));
513 s
= strchr(t
= s
, ',');
516 cmd
.parm
.setup
.si1
= 0;
519 simple_strtoul(t
, NULL
, 10);
520 s
= strchr(t
= s
, ',');
523 cmd
.parm
.setup
.si2
= 0;
526 simple_strtoul(t
, NULL
, 10);
527 strlcpy(cmd
.parm
.setup
.eazmsn
, s
,
528 sizeof(cmd
.parm
.setup
.eazmsn
));
530 cmd
.parm
.setup
.plan
= 0;
531 cmd
.parm
.setup
.screen
= 0;
534 sprintf(cmd
.parm
.setup
.phone
, "LEASED%d", card
->myid
);
535 sprintf(cmd
.parm
.setup
.eazmsn
, "%d", channel
+ 1);
536 cmd
.parm
.setup
.si1
= 7;
537 cmd
.parm
.setup
.si2
= 0;
538 cmd
.parm
.setup
.plan
= 0;
539 cmd
.parm
.setup
.screen
= 0;
542 strlcpy(cmd
.parm
.num
, status
+ 3, sizeof(cmd
.parm
.num
));
545 snprintf(cmd
.parm
.num
, sizeof(cmd
.parm
.num
), "%d",
546 (int) simple_strtoul(status
+ 7, NULL
, 16));
550 if (strlen(status
) == 4)
551 snprintf(cmd
.parm
.num
, sizeof(cmd
.parm
.num
), "%s%c%c",
552 status
+ 2, *status
, *(status
+ 1));
554 strlcpy(cmd
.parm
.num
, status
+ 1, sizeof(cmd
.parm
.num
));
557 spin_lock_irqsave(&card
->lock
, flags
);
558 card
->flags
&= ~ICN_FLAGS_B1ACTIVE
;
559 icn_free_queue(card
, 0);
561 spin_unlock_irqrestore(&card
->lock
, flags
);
563 cmd
.driver
= card
->myid
;
564 card
->interface
.statcallb(&cmd
);
565 cmd
.command
= ISDN_STAT_DHUP
;
567 cmd
.driver
= card
->myid
;
568 card
->interface
.statcallb(&cmd
);
569 cmd
.command
= ISDN_STAT_BHUP
;
570 spin_lock_irqsave(&card
->lock
, flags
);
571 card
->flags
&= ~ICN_FLAGS_B2ACTIVE
;
572 icn_free_queue(card
, 1);
574 spin_unlock_irqrestore(&card
->lock
, flags
);
576 cmd
.driver
= card
->myid
;
577 card
->interface
.statcallb(&cmd
);
578 cmd
.command
= ISDN_STAT_DHUP
;
580 cmd
.driver
= card
->myid
;
583 card
->interface
.statcallb(&cmd
);
588 icn_putmsg(icn_card
* card
, unsigned char c
)
592 spin_lock_irqsave(&card
->lock
, flags
);
593 *card
->msg_buf_write
++ = (c
== 0xff) ? '\n' : c
;
594 if (card
->msg_buf_write
== card
->msg_buf_read
) {
595 if (++card
->msg_buf_read
> card
->msg_buf_end
)
596 card
->msg_buf_read
= card
->msg_buf
;
598 if (card
->msg_buf_write
> card
->msg_buf_end
)
599 card
->msg_buf_write
= card
->msg_buf
;
600 spin_unlock_irqrestore(&card
->lock
, flags
);
604 icn_polldchan(unsigned long data
)
606 icn_card
*card
= (icn_card
*) data
;
607 int mch
= card
->secondhalf
? 2 : 0;
617 if (icn_trymaplock_channel(card
, mch
)) {
619 for (left
= avail
, i
= readb(&msg_o
); left
> 0; i
++, left
--) {
620 c
= readb(&dev
.shmem
->comm_buffers
.iopc_buf
[i
& 0xff]);
623 card
->imsg
[card
->iptr
] = 0;
625 if (card
->imsg
[0] == '0' && card
->imsg
[1] >= '0' &&
626 card
->imsg
[1] <= '2' && card
->imsg
[2] == ';') {
627 ch
= (card
->imsg
[1] - '0') - 1;
629 icn_parse_status(p
, ch
, card
);
632 if (!strncmp(p
, "DRV1.", 5)) {
636 printk(KERN_INFO
"icn: (%s) %s\n", CID
, p
);
637 if (!strncmp(p
+ 7, "TC", 2)) {
638 card
->ptype
= ISDN_PTYPE_1TR6
;
639 card
->interface
.features
|= ISDN_FEATURE_P_1TR6
;
641 "icn: (%s) 1TR6-Protocol loaded and running\n", CID
);
643 if (!strncmp(p
+ 7, "EC", 2)) {
644 card
->ptype
= ISDN_PTYPE_EURO
;
645 card
->interface
.features
|= ISDN_FEATURE_P_EURO
;
647 "icn: (%s) Euro-Protocol loaded and running\n", CID
);
649 p
= strstr(card
->imsg
, "BRV") + 3;
651 if (*p
>= '0' && *p
<= '9')
658 card
->fw_rev
= (int) simple_strtoul(vstr
, NULL
, 10);
664 card
->imsg
[card
->iptr
] = c
;
669 writeb((readb(&msg_o
) + avail
) & 0xff, &msg_o
);
670 icn_release_channel();
673 cmd
.command
= ISDN_STAT_STAVAIL
;
674 cmd
.driver
= card
->myid
;
676 card
->interface
.statcallb(&cmd
);
678 spin_lock_irqsave(&card
->lock
, flags
);
679 if (card
->flags
& (ICN_FLAGS_B1ACTIVE
| ICN_FLAGS_B2ACTIVE
))
680 if (!(card
->flags
& ICN_FLAGS_RBTIMER
)) {
681 /* schedule b-channel polling */
682 card
->flags
|= ICN_FLAGS_RBTIMER
;
683 del_timer(&card
->rb_timer
);
684 card
->rb_timer
.function
= icn_pollbchan
;
685 card
->rb_timer
.data
= (unsigned long) card
;
686 card
->rb_timer
.expires
= jiffies
+ ICN_TIMER_BCREAD
;
687 add_timer(&card
->rb_timer
);
690 mod_timer(&card
->st_timer
, jiffies
+ICN_TIMER_DCREAD
);
691 spin_unlock_irqrestore(&card
->lock
, flags
);
694 /* Append a packet to the transmit buffer-queue.
696 * channel = Number of B-channel
697 * skb = pointer to sk_buff
698 * card = pointer to card-struct
700 * Number of bytes transferred, -E??? on error
704 icn_sendbuf(int channel
, int ack
, struct sk_buff
*skb
, icn_card
* card
)
708 struct sk_buff
*nskb
;
712 "icn: Send packet too large\n");
716 if (!(card
->flags
& (channel
) ? ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
))
718 if (card
->sndcount
[channel
] > ICN_MAX_SQUEUE
)
720 #warning TODO test headroom or use skb->nb to flag ACK
721 nskb
= skb_clone(skb
, GFP_ATOMIC
);
723 /* Push ACK flag as one
724 * byte in front of data.
726 *(skb_push(nskb
, 1)) = ack
?1:0;
727 skb_queue_tail(&card
->spqueue
[channel
], nskb
);
731 spin_lock_irqsave(&card
->lock
, flags
);
732 card
->sndcount
[channel
] += len
;
733 spin_unlock_irqrestore(&card
->lock
, flags
);
739 * Check card's status after starting the bootstrap loader.
740 * On entry, the card's shared memory has already to be mapped.
742 * 0 on success (Boot loader ready)
743 * -EIO on failure (timeout)
746 icn_check_loader(int cardnumber
)
752 printk(KERN_DEBUG
"Loader %d ?\n", cardnumber
);
754 if (readb(&dev
.shmem
->data_control
.scns
) ||
755 readb(&dev
.shmem
->data_control
.scnr
)) {
758 "icn: Boot-Loader %d timed out.\n",
760 icn_release_channel();
764 printk(KERN_DEBUG
"Loader %d TO?\n", cardnumber
);
766 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
769 printk(KERN_DEBUG
"Loader %d OK\n", cardnumber
);
771 icn_release_channel();
777 /* Load the boot-code into the interface-card's memory and start it.
778 * Always called from user-process.
781 * buffer = pointer to packet
783 * 0 if successfully loaded
787 #define SLEEP(sec) { \
789 printk(KERN_DEBUG "SLEEP(%d)\n",slsec); \
791 msleep_interruptible(1000); \
800 icn_loadboot(u_char __user
* buffer
, icn_card
* card
)
807 printk(KERN_DEBUG
"icn_loadboot called, buffaddr=%08lx\n", (ulong
) buffer
);
809 if (!(codebuf
= kmalloc(ICN_CODE_STAGE1
, GFP_KERNEL
))) {
810 printk(KERN_WARNING
"icn: Could not allocate code buffer\n");
814 if (copy_from_user(codebuf
, buffer
, ICN_CODE_STAGE1
)) {
819 if (!request_region(card
->port
, ICN_PORTLEN
, card
->regname
)) {
821 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
824 card
->port
+ ICN_PORTLEN
);
830 card
->other
->rvalid
= 1;
833 if (!request_mem_region(dev
.memaddr
, 0x4000, "icn-isdn (all cards)")) {
835 "icn: memory at 0x%08lx in use.\n", dev
.memaddr
);
839 dev
.shmem
= ioremap(dev
.memaddr
, 0x4000);
842 OUTB_P(0, ICN_RUN
); /* Reset Controller */
843 OUTB_P(0, ICN_MAPRAM
); /* Disable RAM */
844 icn_shiftout(ICN_CFG
, 0x0f, 3, 4); /* Windowsize= 16k */
845 icn_shiftout(ICN_CFG
, dev
.memaddr
, 23, 10); /* Set RAM-Addr. */
847 printk(KERN_DEBUG
"shmem=%08lx\n", dev
.memaddr
);
851 printk(KERN_DEBUG
"Map Bank 0\n");
853 spin_lock_irqsave(&dev
.devlock
, flags
);
854 icn_map_channel(card
, 0); /* Select Bank 0 */
855 icn_lock_channel(card
, 0); /* Lock Bank 0 */
856 spin_unlock_irqrestore(&dev
.devlock
, flags
);
858 memcpy_toio(dev
.shmem
, codebuf
, ICN_CODE_STAGE1
); /* Copy code */
860 printk(KERN_DEBUG
"Bootloader transferred\n");
862 if (card
->doubleS0
) {
865 printk(KERN_DEBUG
"Map Bank 8\n");
867 spin_lock_irqsave(&dev
.devlock
, flags
);
868 __icn_release_channel();
869 icn_map_channel(card
, 2); /* Select Bank 8 */
870 icn_lock_channel(card
, 2); /* Lock Bank 8 */
871 spin_unlock_irqrestore(&dev
.devlock
, flags
);
873 memcpy_toio(dev
.shmem
, codebuf
, ICN_CODE_STAGE1
); /* Copy code */
875 printk(KERN_DEBUG
"Bootloader transferred\n");
879 OUTB_P(0xff, ICN_RUN
); /* Start Boot-Code */
880 if ((ret
= icn_check_loader(card
->doubleS0
? 2 : 1))) {
883 if (!card
->doubleS0
) {
887 /* reached only, if we have a Double-S0-Card */
889 printk(KERN_DEBUG
"Map Bank 0\n");
891 spin_lock_irqsave(&dev
.devlock
, flags
);
892 icn_map_channel(card
, 0); /* Select Bank 0 */
893 icn_lock_channel(card
, 0); /* Lock Bank 0 */
894 spin_unlock_irqrestore(&dev
.devlock
, flags
);
896 ret
= (icn_check_loader(1));
905 icn_loadproto(u_char __user
* buffer
, icn_card
* card
)
907 register u_char __user
*p
= buffer
;
909 uint left
= ICN_CODE_STAGE2
;
915 printk(KERN_DEBUG
"icn_loadproto called\n");
917 if (!access_ok(VERIFY_READ
, buffer
, ICN_CODE_STAGE2
))
920 spin_lock_irqsave(&dev
.devlock
, flags
);
921 if (card
->secondhalf
) {
922 icn_map_channel(card
, 2);
923 icn_lock_channel(card
, 2);
925 icn_map_channel(card
, 0);
926 icn_lock_channel(card
, 0);
928 spin_unlock_irqrestore(&dev
.devlock
, flags
);
930 if (sbfree
) { /* If there is a free buffer... */
934 if (copy_from_user(codebuf
, p
, cnt
)) {
935 icn_maprelease_channel(card
, 0);
938 memcpy_toio(&sbuf_l
, codebuf
, cnt
); /* copy data */
939 sbnext
; /* switch to next buffer */
945 printk(KERN_DEBUG
"boot 2 !sbfree\n");
948 icn_maprelease_channel(card
, 0);
951 schedule_timeout_interruptible(10);
954 writeb(0x20, &sbuf_n
);
957 if (readb(&cmd_o
) || readb(&cmd_i
)) {
959 printk(KERN_DEBUG
"Proto?\n");
963 "icn: (%s) Protocol timed out.\n",
966 printk(KERN_DEBUG
"Proto TO!\n");
968 icn_maprelease_channel(card
, 0);
972 printk(KERN_DEBUG
"Proto TO?\n");
974 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
976 if ((card
->secondhalf
) || (!card
->doubleS0
)) {
978 printk(KERN_DEBUG
"Proto loaded, install poll-timer %d\n",
981 spin_lock_irqsave(&card
->lock
, flags
);
982 init_timer(&card
->st_timer
);
983 card
->st_timer
.expires
= jiffies
+ ICN_TIMER_DCREAD
;
984 card
->st_timer
.function
= icn_polldchan
;
985 card
->st_timer
.data
= (unsigned long) card
;
986 add_timer(&card
->st_timer
);
987 card
->flags
|= ICN_FLAGS_RUNNING
;
988 if (card
->doubleS0
) {
989 init_timer(&card
->other
->st_timer
);
990 card
->other
->st_timer
.expires
= jiffies
+ ICN_TIMER_DCREAD
;
991 card
->other
->st_timer
.function
= icn_polldchan
;
992 card
->other
->st_timer
.data
= (unsigned long) card
->other
;
993 add_timer(&card
->other
->st_timer
);
994 card
->other
->flags
|= ICN_FLAGS_RUNNING
;
996 spin_unlock_irqrestore(&card
->lock
, flags
);
998 icn_maprelease_channel(card
, 0);
1004 /* Read the Status-replies from the Interface */
1006 icn_readstatus(u_char __user
*buf
, int len
, icn_card
* card
)
1011 for (p
= buf
, count
= 0; count
< len
; p
++, count
++) {
1012 if (card
->msg_buf_read
== card
->msg_buf_write
)
1014 if (put_user(*card
->msg_buf_read
++, p
))
1016 if (card
->msg_buf_read
> card
->msg_buf_end
)
1017 card
->msg_buf_read
= card
->msg_buf
;
1022 /* Put command-strings into the command-queue of the Interface */
1024 icn_writecmd(const u_char
* buf
, int len
, int user
, icn_card
* card
)
1026 int mch
= card
->secondhalf
? 2 : 0;
1033 unsigned long flags
;
1034 int lastmap_channel
;
1035 struct icn_card
*lastmap_card
;
1047 if (copy_from_user(msg
, buf
, count
))
1050 memcpy(msg
, buf
, count
);
1052 spin_lock_irqsave(&dev
.devlock
, flags
);
1053 lastmap_card
= dev
.mcard
;
1054 lastmap_channel
= dev
.channel
;
1055 icn_map_channel(card
, mch
);
1057 icn_putmsg(card
, '>');
1058 for (p
= msg
, pp
= readb(&cmd_i
), i
= count
; i
> 0; i
--, p
++, pp
1060 writeb((*p
== '\n') ? 0xff : *p
,
1061 &dev
.shmem
->comm_buffers
.pcio_buf
[pp
& 0xff]);
1064 icn_putmsg(card
, *p
);
1065 if ((*p
== '\n') && (i
> 1)) {
1066 icn_putmsg(card
, '>');
1071 writeb((readb(&cmd_i
) + count
) & 0xff, &cmd_i
);
1073 icn_map_channel(lastmap_card
, lastmap_channel
);
1074 spin_unlock_irqrestore(&dev
.devlock
, flags
);
1083 printk(KERN_WARNING
"icn: writemsg incomplete!\n");
1084 cmd
.command
= ISDN_STAT_STAVAIL
;
1085 cmd
.driver
= card
->myid
;
1087 card
->interface
.statcallb(&cmd
);
1092 * Delete card's pending timers, send STOP to linklevel
1095 icn_stopcard(icn_card
* card
)
1097 unsigned long flags
;
1100 spin_lock_irqsave(&card
->lock
, flags
);
1101 if (card
->flags
& ICN_FLAGS_RUNNING
) {
1102 card
->flags
&= ~ICN_FLAGS_RUNNING
;
1103 del_timer(&card
->st_timer
);
1104 del_timer(&card
->rb_timer
);
1105 spin_unlock_irqrestore(&card
->lock
, flags
);
1106 cmd
.command
= ISDN_STAT_STOP
;
1107 cmd
.driver
= card
->myid
;
1108 card
->interface
.statcallb(&cmd
);
1110 icn_stopcard(card
->other
);
1112 spin_unlock_irqrestore(&card
->lock
, flags
);
1116 icn_stopallcards(void)
1118 icn_card
*p
= cards
;
1127 * Unmap all cards, because some of them may be mapped accidetly during
1128 * autoprobing of some network drivers (SMC-driver?)
1131 icn_disable_cards(void)
1133 icn_card
*card
= cards
;
1136 if (!request_region(card
->port
, ICN_PORTLEN
, "icn-isdn")) {
1138 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1141 card
->port
+ ICN_PORTLEN
);
1143 OUTB_P(0, ICN_RUN
); /* Reset Controller */
1144 OUTB_P(0, ICN_MAPRAM
); /* Disable RAM */
1145 release_region(card
->port
, ICN_PORTLEN
);
1152 icn_command(isdn_ctrl
* c
, icn_card
* card
)
1162 switch (c
->command
) {
1163 case ISDN_CMD_IOCTL
:
1164 memcpy(&a
, c
->parm
.num
, sizeof(ulong
));
1165 arg
= (char __user
*)a
;
1167 case ICN_IOCTL_SETMMIO
:
1168 if (dev
.memaddr
!= (a
& 0x0ffc000)) {
1169 if (!request_mem_region(a
& 0x0ffc000, 0x4000, "icn-isdn (all cards)")) {
1171 "icn: memory at 0x%08lx in use.\n",
1175 release_mem_region(a
& 0x0ffc000, 0x4000);
1177 spin_lock_irqsave(&card
->lock
, flags
);
1180 release_mem_region(dev
.memaddr
, 0x4000);
1183 dev
.memaddr
= a
& 0x0ffc000;
1184 spin_unlock_irqrestore(&card
->lock
, flags
);
1186 "icn: (%s) mmio set to 0x%08lx\n",
1191 case ICN_IOCTL_GETMMIO
:
1192 return (long) dev
.memaddr
;
1193 case ICN_IOCTL_SETPORT
:
1194 if (a
== 0x300 || a
== 0x310 || a
== 0x320 || a
== 0x330
1195 || a
== 0x340 || a
== 0x350 || a
== 0x360 ||
1196 a
== 0x308 || a
== 0x318 || a
== 0x328 || a
== 0x338
1197 || a
== 0x348 || a
== 0x358 || a
== 0x368) {
1198 if (card
->port
!= (unsigned short) a
) {
1199 if (!request_region((unsigned short) a
, ICN_PORTLEN
, "icn-isdn")) {
1201 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1202 CID
, (int) a
, (int) a
+ ICN_PORTLEN
);
1205 release_region((unsigned short) a
, ICN_PORTLEN
);
1207 spin_lock_irqsave(&card
->lock
, flags
);
1209 release_region(card
->port
, ICN_PORTLEN
);
1210 card
->port
= (unsigned short) a
;
1212 if (card
->doubleS0
) {
1213 card
->other
->port
= (unsigned short) a
;
1214 card
->other
->rvalid
= 0;
1216 spin_unlock_irqrestore(&card
->lock
, flags
);
1218 "icn: (%s) port set to 0x%03x\n",
1224 case ICN_IOCTL_GETPORT
:
1225 return (int) card
->port
;
1226 case ICN_IOCTL_GETDOUBLE
:
1227 return (int) card
->doubleS0
;
1228 case ICN_IOCTL_DEBUGVAR
:
1229 if (copy_to_user(arg
,
1235 ulong l
= (ulong
) & dev
;
1236 if (copy_to_user(arg
,
1242 case ICN_IOCTL_LOADBOOT
:
1243 if (dev
.firstload
) {
1244 icn_disable_cards();
1248 return (icn_loadboot(arg
, card
));
1249 case ICN_IOCTL_LOADPROTO
:
1251 if ((i
= (icn_loadproto(arg
, card
))))
1254 i
= icn_loadproto(arg
+ ICN_CODE_STAGE2
, card
->other
);
1257 case ICN_IOCTL_ADDCARD
:
1260 if (copy_from_user(&cdef
,
1264 return (icn_addcard(cdef
.port
, cdef
.id1
, cdef
.id2
));
1266 case ICN_IOCTL_LEASEDCFG
:
1268 if (!card
->leased
) {
1270 while (card
->ptype
== ISDN_PTYPE_UNKNOWN
) {
1271 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
1273 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
1274 sprintf(cbuf
, "00;FV2ON\n01;EAZ%c\n02;EAZ%c\n",
1275 (a
& 1)?'1':'C', (a
& 2)?'2':'C');
1276 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1278 "icn: (%s) Leased-line mode enabled\n",
1280 cmd
.command
= ISDN_STAT_RUN
;
1281 cmd
.driver
= card
->myid
;
1283 card
->interface
.statcallb(&cmd
);
1288 sprintf(cbuf
, "00;FV2OFF\n");
1289 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1291 "icn: (%s) Leased-line mode disabled\n",
1293 cmd
.command
= ISDN_STAT_RUN
;
1294 cmd
.driver
= card
->myid
;
1296 card
->interface
.statcallb(&cmd
);
1305 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1309 if ((c
->arg
& 255) < ICN_BCH
) {
1315 p
= c
->parm
.setup
.phone
;
1316 if (*p
== 's' || *p
== 'S') {
1319 strcpy(dcode
, "SCA");
1322 strcpy(dcode
, "CAL");
1324 sprintf(cbuf
, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a
+ 1),
1325 dcode
, dial
, c
->parm
.setup
.si1
,
1326 c
->parm
.setup
.si2
, c
->parm
.setup
.eazmsn
);
1327 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1330 case ISDN_CMD_ACCEPTD
:
1331 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1333 if (c
->arg
< ICN_BCH
) {
1335 if (card
->fw_rev
>= 300) {
1336 switch (card
->l2_proto
[a
- 1]) {
1337 case ISDN_PROTO_L2_X75I
:
1338 sprintf(cbuf
, "%02d;BX75\n", (int) a
);
1340 case ISDN_PROTO_L2_HDLC
:
1341 sprintf(cbuf
, "%02d;BTRA\n", (int) a
);
1344 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1346 sprintf(cbuf
, "%02d;DCON_R\n", (int) a
);
1347 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1350 case ISDN_CMD_ACCEPTB
:
1351 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1353 if (c
->arg
< ICN_BCH
) {
1355 if (card
->fw_rev
>= 300)
1356 switch (card
->l2_proto
[a
- 1]) {
1357 case ISDN_PROTO_L2_X75I
:
1358 sprintf(cbuf
, "%02d;BCON_R,BX75\n", (int) a
);
1360 case ISDN_PROTO_L2_HDLC
:
1361 sprintf(cbuf
, "%02d;BCON_R,BTRA\n", (int) a
);
1364 sprintf(cbuf
, "%02d;BCON_R\n", (int) a
);
1365 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1368 case ISDN_CMD_HANGUP
:
1369 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1371 if (c
->arg
< ICN_BCH
) {
1373 sprintf(cbuf
, "%02d;BDIS_R\n%02d;DDIS_R\n", (int) a
, (int) a
);
1374 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1377 case ISDN_CMD_SETEAZ
:
1378 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1382 if (c
->arg
< ICN_BCH
) {
1384 if (card
->ptype
== ISDN_PTYPE_EURO
) {
1385 sprintf(cbuf
, "%02d;MS%s%s\n", (int) a
,
1386 c
->parm
.num
[0] ? "N" : "ALL", c
->parm
.num
);
1388 sprintf(cbuf
, "%02d;EAZ%s\n", (int) a
,
1389 c
->parm
.num
[0] ? (char *)(c
->parm
.num
) : "0123456789");
1390 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1393 case ISDN_CMD_CLREAZ
:
1394 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1398 if (c
->arg
< ICN_BCH
) {
1400 if (card
->ptype
== ISDN_PTYPE_EURO
)
1401 sprintf(cbuf
, "%02d;MSNC\n", (int) a
);
1403 sprintf(cbuf
, "%02d;EAZC\n", (int) a
);
1404 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1407 case ISDN_CMD_SETL2
:
1408 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1410 if ((c
->arg
& 255) < ICN_BCH
) {
1413 case ISDN_PROTO_L2_X75I
:
1414 sprintf(cbuf
, "%02d;BX75\n", (int) (a
& 255) + 1);
1416 case ISDN_PROTO_L2_HDLC
:
1417 sprintf(cbuf
, "%02d;BTRA\n", (int) (a
& 255) + 1);
1422 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1423 card
->l2_proto
[a
& 255] = (a
>> 8);
1426 case ISDN_CMD_SETL3
:
1427 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1437 * Find card with given driverId
1439 static inline icn_card
*
1440 icn_findcard(int driverid
)
1442 icn_card
*p
= cards
;
1445 if (p
->myid
== driverid
)
1449 return (icn_card
*) 0;
1453 * Wrapper functions for interface to linklevel
1456 if_command(isdn_ctrl
* c
)
1458 icn_card
*card
= icn_findcard(c
->driver
);
1461 return (icn_command(c
, card
));
1463 "icn: if_command %d called with invalid driverId %d!\n",
1464 c
->command
, c
->driver
);
1469 if_writecmd(const u_char __user
*buf
, int len
, int id
, int channel
)
1471 icn_card
*card
= icn_findcard(id
);
1474 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1476 return (icn_writecmd(buf
, len
, 1, card
));
1479 "icn: if_writecmd called with invalid driverId!\n");
1484 if_readstatus(u_char __user
*buf
, int len
, int id
, int channel
)
1486 icn_card
*card
= icn_findcard(id
);
1489 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1491 return (icn_readstatus(buf
, len
, card
));
1494 "icn: if_readstatus called with invalid driverId!\n");
1499 if_sendbuf(int id
, int channel
, int ack
, struct sk_buff
*skb
)
1501 icn_card
*card
= icn_findcard(id
);
1504 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1506 return (icn_sendbuf(channel
, ack
, skb
, card
));
1509 "icn: if_sendbuf called with invalid driverId!\n");
1514 * Allocate a new card-struct, initialize it
1515 * link it into cards-list and register it at linklevel.
1518 icn_initcard(int port
, char *id
)
1523 if (!(card
= kzalloc(sizeof(icn_card
), GFP_KERNEL
))) {
1525 "icn: (%s) Could not allocate card-struct.\n", id
);
1526 return (icn_card
*) 0;
1528 spin_lock_init(&card
->lock
);
1530 card
->interface
.owner
= THIS_MODULE
;
1531 card
->interface
.hl_hdrlen
= 1;
1532 card
->interface
.channels
= ICN_BCH
;
1533 card
->interface
.maxbufsize
= 4000;
1534 card
->interface
.command
= if_command
;
1535 card
->interface
.writebuf_skb
= if_sendbuf
;
1536 card
->interface
.writecmd
= if_writecmd
;
1537 card
->interface
.readstat
= if_readstatus
;
1538 card
->interface
.features
= ISDN_FEATURE_L2_X75I
|
1539 ISDN_FEATURE_L2_HDLC
|
1540 ISDN_FEATURE_L3_TRANS
|
1541 ISDN_FEATURE_P_UNKNOWN
;
1542 card
->ptype
= ISDN_PTYPE_UNKNOWN
;
1543 strlcpy(card
->interface
.id
, id
, sizeof(card
->interface
.id
));
1544 card
->msg_buf_write
= card
->msg_buf
;
1545 card
->msg_buf_read
= card
->msg_buf
;
1546 card
->msg_buf_end
= &card
->msg_buf
[sizeof(card
->msg_buf
) - 1];
1547 for (i
= 0; i
< ICN_BCH
; i
++) {
1548 card
->l2_proto
[i
] = ISDN_PROTO_L2_X75I
;
1549 skb_queue_head_init(&card
->spqueue
[i
]);
1553 if (!register_isdn(&card
->interface
)) {
1554 cards
= cards
->next
;
1556 "icn: Unable to register %s\n", id
);
1558 return (icn_card
*) 0;
1560 card
->myid
= card
->interface
.channels
;
1561 sprintf(card
->regname
, "icn-isdn (%s)", card
->interface
.id
);
1566 icn_addcard(int port
, char *id1
, char *id2
)
1571 if (!(card
= icn_initcard(port
, id1
))) {
1576 "icn: (%s) ICN-2B, port 0x%x added\n",
1577 card
->interface
.id
, port
);
1580 if (!(card2
= icn_initcard(port
, id2
))) {
1582 "icn: (%s) half ICN-4B, port 0x%x added\n",
1583 card2
->interface
.id
, port
);
1587 card
->secondhalf
= 0;
1588 card
->other
= card2
;
1589 card2
->doubleS0
= 1;
1590 card2
->secondhalf
= 1;
1591 card2
->other
= card
;
1593 "icn: (%s and %s) ICN-4B, port 0x%x added\n",
1594 card
->interface
.id
, card2
->interface
.id
, port
);
1600 icn_setup(char *line
)
1604 static char sid
[20];
1605 static char sid2
[20];
1607 str
= get_options(line
, 2, ints
);
1611 membase
= (unsigned long)ints
[2];
1615 if ((p
= strchr(sid
, ','))) {
1623 __setup("icn=", icn_setup
);
1626 static int __init
icn_init(void)
1631 memset(&dev
, 0, sizeof(icn_dev
));
1632 dev
.memaddr
= (membase
& 0x0ffc000);
1636 spin_lock_init(&dev
.devlock
);
1638 if ((p
= strchr(revision
, ':'))) {
1640 p
= strchr(rev
, '$');
1643 strcpy(rev
, " ??? ");
1644 printk(KERN_NOTICE
"ICN-ISDN-driver Rev%smem=0x%08lx\n", rev
,
1646 return (icn_addcard(portbase
, icn_id
, icn_id2
));
1649 static void __exit
icn_exit(void)
1652 icn_card
*card
= cards
;
1653 icn_card
*last
, *tmpcard
;
1655 unsigned long flags
;
1659 cmd
.command
= ISDN_STAT_UNLOAD
;
1660 cmd
.driver
= card
->myid
;
1661 card
->interface
.statcallb(&cmd
);
1662 spin_lock_irqsave(&card
->lock
, flags
);
1664 OUTB_P(0, ICN_RUN
); /* Reset Controller */
1665 OUTB_P(0, ICN_MAPRAM
); /* Disable RAM */
1666 if (card
->secondhalf
|| (!card
->doubleS0
)) {
1667 release_region(card
->port
, ICN_PORTLEN
);
1670 for (i
= 0; i
< ICN_BCH
; i
++)
1671 icn_free_queue(card
, i
);
1673 tmpcard
= card
->next
;
1674 spin_unlock_irqrestore(&card
->lock
, flags
);
1686 release_mem_region(dev
.memaddr
, 0x4000);
1688 printk(KERN_NOTICE
"ICN-ISDN-driver unloaded\n");
1691 module_init(icn_init
);
1692 module_exit(icn_exit
);