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>
16 static int portbase
= ICN_BASEADDR
;
17 static unsigned long membase
= ICN_MEMADDR
;
18 static char *icn_id
= "\0";
19 static char *icn_id2
= "\0";
21 MODULE_DESCRIPTION("ISDN4Linux: Driver for ICN active ISDN card");
22 MODULE_AUTHOR("Fritz Elfert");
23 MODULE_LICENSE("GPL");
24 module_param(portbase
, int, 0);
25 MODULE_PARM_DESC(portbase
, "Port address of first card");
26 module_param(membase
, ulong
, 0);
27 MODULE_PARM_DESC(membase
, "Shared memory address of all cards");
28 module_param(icn_id
, charp
, 0);
29 MODULE_PARM_DESC(icn_id
, "ID-String of first card");
30 module_param(icn_id2
, charp
, 0);
31 MODULE_PARM_DESC(icn_id2
, "ID-String of first card, second S0 (4B only)");
34 * Verbose bootcode- and protocol-downloading.
39 * Verbose Shmem-Mapping.
44 *revision
= "$Revision: 1.65.6.8 $";
46 static int icn_addcard(int, char *, char *);
49 * Free send-queue completely.
51 * card = pointer to card struct
52 * channel = channel number
55 icn_free_queue(icn_card
* card
, int channel
)
57 struct sk_buff_head
*queue
= &card
->spqueue
[channel
];
60 skb_queue_purge(queue
);
61 card
->xlen
[channel
] = 0;
62 card
->sndcount
[channel
] = 0;
63 if ((skb
= card
->xskb
[channel
])) {
64 card
->xskb
[channel
] = NULL
;
69 /* Put a value into a shift-register, highest bit first.
71 * port = port for output (bit 0 is significant)
72 * val = value to be output
73 * firstbit = Bit-Number of highest bit
74 * bitcount = Number of bits to output
77 icn_shiftout(unsigned short port
,
86 for (s
= firstbit
, c
= bitcount
; c
> 0; s
--, c
--)
87 OUTB_P((u_char
) ((val
>> s
) & 1) ? 0xff : 0, port
);
91 * disable a cards shared memory
94 icn_disable_ram(icn_card
* card
)
96 OUTB_P(0, ICN_MAPRAM
);
100 * enable a cards shared memory
103 icn_enable_ram(icn_card
* card
)
105 OUTB_P(0xff, ICN_MAPRAM
);
109 * Map a cards channel0 (Bank0/Bank8) or channel1 (Bank4/Bank12)
111 * must called with holding the devlock
114 icn_map_channel(icn_card
* card
, int channel
)
117 printk(KERN_DEBUG
"icn_map_channel %d %d\n", dev
.channel
, channel
);
119 if ((channel
== dev
.channel
) && (card
== dev
.mcard
))
122 icn_disable_ram(dev
.mcard
);
123 icn_shiftout(ICN_BANK
, chan2bank
[channel
], 3, 4); /* Select Bank */
124 icn_enable_ram(card
);
126 dev
.channel
= channel
;
128 printk(KERN_DEBUG
"icn_map_channel done\n");
133 * Lock a cards channel.
134 * Return 0 if requested card/channel is unmapped (failure).
135 * Return 1 on success.
137 * must called with holding the devlock
140 icn_lock_channel(icn_card
* card
, int channel
)
145 printk(KERN_DEBUG
"icn_lock_channel %d\n", channel
);
147 if ((dev
.channel
== channel
) && (card
== dev
.mcard
)) {
151 printk(KERN_DEBUG
"icn_lock_channel %d OK\n", channel
);
156 printk(KERN_DEBUG
"icn_lock_channel %d FAILED, dc=%d\n", channel
, dev
.channel
);
163 * Release current card/channel lock
165 * must called with holding the devlock
168 __icn_release_channel(void)
171 printk(KERN_DEBUG
"icn_release_channel l=%d\n", dev
.chanlock
);
173 if (dev
.chanlock
> 0)
178 * Release current card/channel lock
181 icn_release_channel(void)
185 spin_lock_irqsave(&dev
.devlock
, flags
);
186 __icn_release_channel();
187 spin_unlock_irqrestore(&dev
.devlock
, flags
);
191 * Try to map and lock a cards channel.
192 * Return 1 on success, 0 on failure.
195 icn_trymaplock_channel(icn_card
* card
, int channel
)
200 printk(KERN_DEBUG
"trymaplock c=%d dc=%d l=%d\n", channel
, dev
.channel
,
203 spin_lock_irqsave(&dev
.devlock
, flags
);
204 if ((!dev
.chanlock
) ||
205 ((dev
.channel
== channel
) && (dev
.mcard
== card
))) {
207 icn_map_channel(card
, channel
);
208 spin_unlock_irqrestore(&dev
.devlock
, flags
);
210 printk(KERN_DEBUG
"trymaplock %d OK\n", channel
);
214 spin_unlock_irqrestore(&dev
.devlock
, flags
);
216 printk(KERN_DEBUG
"trymaplock %d FAILED\n", channel
);
222 * Release current card/channel lock,
223 * then map same or other channel without locking.
226 icn_maprelease_channel(icn_card
* card
, int channel
)
231 printk(KERN_DEBUG
"map_release c=%d l=%d\n", channel
, dev
.chanlock
);
233 spin_lock_irqsave(&dev
.devlock
, flags
);
234 if (dev
.chanlock
> 0)
237 icn_map_channel(card
, channel
);
238 spin_unlock_irqrestore(&dev
.devlock
, flags
);
241 /* Get Data from the B-Channel, assemble fragmented packets and put them
242 * into receive-queue. Wake up any B-Channel-reading processes.
243 * This routine is called via timer-callback from icn_pollbchan().
247 icn_pollbchan_receive(int channel
, icn_card
* card
)
249 int mch
= channel
+ ((card
->secondhalf
) ? 2 : 0);
254 if (icn_trymaplock_channel(card
, mch
)) {
256 cnt
= readb(&rbuf_l
);
257 if ((card
->rcvidx
[channel
] + cnt
) > 4000) {
259 "icn: (%s) bogus packet on ch%d, dropping.\n",
262 card
->rcvidx
[channel
] = 0;
265 memcpy_fromio(&card
->rcvbuf
[channel
][card
->rcvidx
[channel
]],
267 card
->rcvidx
[channel
] += cnt
;
268 eflag
= readb(&rbuf_f
);
271 icn_maprelease_channel(card
, mch
& 2);
273 if ((cnt
= card
->rcvidx
[channel
])) {
274 if (!(skb
= dev_alloc_skb(cnt
))) {
275 printk(KERN_WARNING
"icn: receive out of memory\n");
278 memcpy(skb_put(skb
, cnt
), card
->rcvbuf
[channel
], cnt
);
279 card
->rcvidx
[channel
] = 0;
280 card
->interface
.rcvcallb_skb(card
->myid
, channel
, skb
);
283 if (!icn_trymaplock_channel(card
, mch
))
286 icn_maprelease_channel(card
, mch
& 2);
290 /* Send data-packet to B-Channel, split it up into fragments of
291 * ICN_FRAGSIZE length. If last fragment is sent out, signal
292 * success to upper layers via statcallb with ISDN_STAT_BSENT argument.
293 * This routine is called via timer-callback from icn_pollbchan() or
294 * directly from icn_sendbuf().
298 icn_pollbchan_send(int channel
, icn_card
* card
)
300 int mch
= channel
+ ((card
->secondhalf
) ? 2 : 0);
306 if (!(card
->sndcount
[channel
] || card
->xskb
[channel
] ||
307 skb_queue_len(&card
->spqueue
[channel
])))
309 if (icn_trymaplock_channel(card
, mch
)) {
311 (card
->sndcount
[channel
] ||
312 skb_queue_len(&card
->spqueue
[channel
]) ||
313 card
->xskb
[channel
])) {
314 spin_lock_irqsave(&card
->lock
, flags
);
315 if (card
->xmit_lock
[channel
]) {
316 spin_unlock_irqrestore(&card
->lock
, flags
);
319 card
->xmit_lock
[channel
]++;
320 spin_unlock_irqrestore(&card
->lock
, flags
);
321 skb
= card
->xskb
[channel
];
323 skb
= skb_dequeue(&card
->spqueue
[channel
]);
325 /* Pop ACK-flag off skb.
326 * Store length to xlen.
328 if (*(skb_pull(skb
,1)))
329 card
->xlen
[channel
] = skb
->len
;
331 card
->xlen
[channel
] = 0;
336 if (skb
->len
> ICN_FRAGSIZE
) {
337 writeb(0xff, &sbuf_f
);
340 writeb(0x0, &sbuf_f
);
343 writeb(cnt
, &sbuf_l
);
344 memcpy_toio(&sbuf_d
, skb
->data
, cnt
);
346 sbnext
; /* switch to next buffer */
347 icn_maprelease_channel(card
, mch
& 2);
348 spin_lock_irqsave(&card
->lock
, flags
);
349 card
->sndcount
[channel
] -= cnt
;
351 if (card
->xskb
[channel
])
352 card
->xskb
[channel
] = NULL
;
353 card
->xmit_lock
[channel
] = 0;
354 spin_unlock_irqrestore(&card
->lock
, flags
);
356 if (card
->xlen
[channel
]) {
357 cmd
.command
= ISDN_STAT_BSENT
;
358 cmd
.driver
= card
->myid
;
360 cmd
.parm
.length
= card
->xlen
[channel
];
361 card
->interface
.statcallb(&cmd
);
364 card
->xskb
[channel
] = skb
;
365 card
->xmit_lock
[channel
] = 0;
366 spin_unlock_irqrestore(&card
->lock
, flags
);
368 if (!icn_trymaplock_channel(card
, mch
))
371 icn_maprelease_channel(card
, mch
& 2);
375 /* Send/Receive Data to/from the B-Channel.
376 * This routine is called via timer-callback.
377 * It schedules itself while any B-Channel is open.
381 icn_pollbchan(unsigned long data
)
383 icn_card
*card
= (icn_card
*) data
;
386 if (card
->flags
& ICN_FLAGS_B1ACTIVE
) {
387 icn_pollbchan_receive(0, card
);
388 icn_pollbchan_send(0, card
);
390 if (card
->flags
& ICN_FLAGS_B2ACTIVE
) {
391 icn_pollbchan_receive(1, card
);
392 icn_pollbchan_send(1, card
);
394 if (card
->flags
& (ICN_FLAGS_B1ACTIVE
| ICN_FLAGS_B2ACTIVE
)) {
395 /* schedule b-channel polling again */
396 spin_lock_irqsave(&card
->lock
, flags
);
397 mod_timer(&card
->rb_timer
, jiffies
+ICN_TIMER_BCREAD
);
398 card
->flags
|= ICN_FLAGS_RBTIMER
;
399 spin_unlock_irqrestore(&card
->lock
, flags
);
401 card
->flags
&= ~ICN_FLAGS_RBTIMER
;
404 typedef struct icn_stat
{
410 static icn_stat icn_stat_table
[] =
412 {"BCON_", ISDN_STAT_BCONN
, 1}, /* B-Channel connected */
413 {"BDIS_", ISDN_STAT_BHUP
, 2}, /* B-Channel disconnected */
415 ** add d-channel connect and disconnect support to link-level
417 {"DCON_", ISDN_STAT_DCONN
, 10}, /* D-Channel connected */
418 {"DDIS_", ISDN_STAT_DHUP
, 11}, /* D-Channel disconnected */
419 {"DCAL_I", ISDN_STAT_ICALL
, 3}, /* Incoming call dialup-line */
420 {"DSCA_I", ISDN_STAT_ICALL
, 3}, /* Incoming call 1TR6-SPV */
421 {"FCALL", ISDN_STAT_ICALL
, 4}, /* Leased line connection up */
422 {"CIF", ISDN_STAT_CINF
, 5}, /* Charge-info, 1TR6-type */
423 {"AOC", ISDN_STAT_CINF
, 6}, /* Charge-info, DSS1-type */
424 {"CAU", ISDN_STAT_CAUSE
, 7}, /* Cause code */
425 {"TEI OK", ISDN_STAT_RUN
, 0}, /* Card connected to wallplug */
426 {"E_L1: ACT FAIL", ISDN_STAT_BHUP
, 8}, /* Layer-1 activation failed */
427 {"E_L2: DATA LIN", ISDN_STAT_BHUP
, 8}, /* Layer-2 data link lost */
428 {"E_L1: ACTIVATION FAILED",
429 ISDN_STAT_BHUP
, 8}, /* Layer-1 activation failed */
436 * Check Statusqueue-Pointer from isdn-cards.
437 * If there are new status-replies from the interface, check
438 * them against B-Channel-connects/disconnects and set flags accordingly.
439 * Wake-Up any processes, who are reading the status-device.
440 * If there are B-Channels open, initiate a timer-callback to
442 * This routine is called periodically via timer.
446 icn_parse_status(u_char
* status
, int channel
, icn_card
* card
)
448 icn_stat
*s
= icn_stat_table
;
454 if (!strncmp(status
, s
->statstr
, strlen(s
->statstr
))) {
455 cmd
.command
= s
->command
;
463 cmd
.driver
= card
->myid
;
467 spin_lock_irqsave(&card
->lock
, flags
);
468 icn_free_queue(card
,channel
);
469 card
->rcvidx
[channel
] = 0;
472 ((channel
)?ICN_FLAGS_B2ACTIVE
:ICN_FLAGS_B1ACTIVE
)) {
476 card
->flags
&= ~((channel
)?
477 ICN_FLAGS_B2ACTIVE
:ICN_FLAGS_B1ACTIVE
);
479 memset(&ncmd
, 0, sizeof(ncmd
));
481 ncmd
.driver
= card
->myid
;
483 ncmd
.command
= ISDN_STAT_BHUP
;
484 spin_unlock_irqrestore(&card
->lock
, flags
);
485 card
->interface
.statcallb(&cmd
);
487 spin_unlock_irqrestore(&card
->lock
, flags
);
490 spin_lock_irqsave(&card
->lock
, flags
);
491 icn_free_queue(card
,channel
);
492 card
->flags
|= (channel
) ?
493 ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
;
494 spin_unlock_irqrestore(&card
->lock
, flags
);
497 spin_lock_irqsave(&card
->lock
, flags
);
498 card
->flags
&= ~((channel
) ?
499 ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
);
500 icn_free_queue(card
, channel
);
501 card
->rcvidx
[channel
] = 0;
502 spin_unlock_irqrestore(&card
->lock
, flags
);
506 char *t
= status
+ 6;
507 char *s
= strchr(t
, ',');
510 strlcpy(cmd
.parm
.setup
.phone
, t
,
511 sizeof(cmd
.parm
.setup
.phone
));
512 s
= strchr(t
= s
, ',');
515 cmd
.parm
.setup
.si1
= 0;
518 simple_strtoul(t
, NULL
, 10);
519 s
= strchr(t
= s
, ',');
522 cmd
.parm
.setup
.si2
= 0;
525 simple_strtoul(t
, NULL
, 10);
526 strlcpy(cmd
.parm
.setup
.eazmsn
, s
,
527 sizeof(cmd
.parm
.setup
.eazmsn
));
529 cmd
.parm
.setup
.plan
= 0;
530 cmd
.parm
.setup
.screen
= 0;
533 sprintf(cmd
.parm
.setup
.phone
, "LEASED%d", card
->myid
);
534 sprintf(cmd
.parm
.setup
.eazmsn
, "%d", channel
+ 1);
535 cmd
.parm
.setup
.si1
= 7;
536 cmd
.parm
.setup
.si2
= 0;
537 cmd
.parm
.setup
.plan
= 0;
538 cmd
.parm
.setup
.screen
= 0;
541 strlcpy(cmd
.parm
.num
, status
+ 3, sizeof(cmd
.parm
.num
));
544 snprintf(cmd
.parm
.num
, sizeof(cmd
.parm
.num
), "%d",
545 (int) simple_strtoul(status
+ 7, NULL
, 16));
549 if (strlen(status
) == 4)
550 snprintf(cmd
.parm
.num
, sizeof(cmd
.parm
.num
), "%s%c%c",
551 status
+ 2, *status
, *(status
+ 1));
553 strlcpy(cmd
.parm
.num
, status
+ 1, sizeof(cmd
.parm
.num
));
556 spin_lock_irqsave(&card
->lock
, flags
);
557 card
->flags
&= ~ICN_FLAGS_B1ACTIVE
;
558 icn_free_queue(card
, 0);
560 spin_unlock_irqrestore(&card
->lock
, flags
);
562 cmd
.driver
= card
->myid
;
563 card
->interface
.statcallb(&cmd
);
564 cmd
.command
= ISDN_STAT_DHUP
;
566 cmd
.driver
= card
->myid
;
567 card
->interface
.statcallb(&cmd
);
568 cmd
.command
= ISDN_STAT_BHUP
;
569 spin_lock_irqsave(&card
->lock
, flags
);
570 card
->flags
&= ~ICN_FLAGS_B2ACTIVE
;
571 icn_free_queue(card
, 1);
573 spin_unlock_irqrestore(&card
->lock
, flags
);
575 cmd
.driver
= card
->myid
;
576 card
->interface
.statcallb(&cmd
);
577 cmd
.command
= ISDN_STAT_DHUP
;
579 cmd
.driver
= card
->myid
;
582 card
->interface
.statcallb(&cmd
);
587 icn_putmsg(icn_card
* card
, unsigned char c
)
591 spin_lock_irqsave(&card
->lock
, flags
);
592 *card
->msg_buf_write
++ = (c
== 0xff) ? '\n' : c
;
593 if (card
->msg_buf_write
== card
->msg_buf_read
) {
594 if (++card
->msg_buf_read
> card
->msg_buf_end
)
595 card
->msg_buf_read
= card
->msg_buf
;
597 if (card
->msg_buf_write
> card
->msg_buf_end
)
598 card
->msg_buf_write
= card
->msg_buf
;
599 spin_unlock_irqrestore(&card
->lock
, flags
);
603 icn_polldchan(unsigned long data
)
605 icn_card
*card
= (icn_card
*) data
;
606 int mch
= card
->secondhalf
? 2 : 0;
616 if (icn_trymaplock_channel(card
, mch
)) {
618 for (left
= avail
, i
= readb(&msg_o
); left
> 0; i
++, left
--) {
619 c
= readb(&dev
.shmem
->comm_buffers
.iopc_buf
[i
& 0xff]);
622 card
->imsg
[card
->iptr
] = 0;
624 if (card
->imsg
[0] == '0' && card
->imsg
[1] >= '0' &&
625 card
->imsg
[1] <= '2' && card
->imsg
[2] == ';') {
626 ch
= (card
->imsg
[1] - '0') - 1;
628 icn_parse_status(p
, ch
, card
);
631 if (!strncmp(p
, "DRV1.", 5)) {
635 printk(KERN_INFO
"icn: (%s) %s\n", CID
, p
);
636 if (!strncmp(p
+ 7, "TC", 2)) {
637 card
->ptype
= ISDN_PTYPE_1TR6
;
638 card
->interface
.features
|= ISDN_FEATURE_P_1TR6
;
640 "icn: (%s) 1TR6-Protocol loaded and running\n", CID
);
642 if (!strncmp(p
+ 7, "EC", 2)) {
643 card
->ptype
= ISDN_PTYPE_EURO
;
644 card
->interface
.features
|= ISDN_FEATURE_P_EURO
;
646 "icn: (%s) Euro-Protocol loaded and running\n", CID
);
648 p
= strstr(card
->imsg
, "BRV") + 3;
650 if (*p
>= '0' && *p
<= '9')
657 card
->fw_rev
= (int) simple_strtoul(vstr
, NULL
, 10);
663 card
->imsg
[card
->iptr
] = c
;
668 writeb((readb(&msg_o
) + avail
) & 0xff, &msg_o
);
669 icn_release_channel();
672 cmd
.command
= ISDN_STAT_STAVAIL
;
673 cmd
.driver
= card
->myid
;
675 card
->interface
.statcallb(&cmd
);
677 spin_lock_irqsave(&card
->lock
, flags
);
678 if (card
->flags
& (ICN_FLAGS_B1ACTIVE
| ICN_FLAGS_B2ACTIVE
))
679 if (!(card
->flags
& ICN_FLAGS_RBTIMER
)) {
680 /* schedule b-channel polling */
681 card
->flags
|= ICN_FLAGS_RBTIMER
;
682 del_timer(&card
->rb_timer
);
683 card
->rb_timer
.function
= icn_pollbchan
;
684 card
->rb_timer
.data
= (unsigned long) card
;
685 card
->rb_timer
.expires
= jiffies
+ ICN_TIMER_BCREAD
;
686 add_timer(&card
->rb_timer
);
689 mod_timer(&card
->st_timer
, jiffies
+ICN_TIMER_DCREAD
);
690 spin_unlock_irqrestore(&card
->lock
, flags
);
693 /* Append a packet to the transmit buffer-queue.
695 * channel = Number of B-channel
696 * skb = pointer to sk_buff
697 * card = pointer to card-struct
699 * Number of bytes transferred, -E??? on error
703 icn_sendbuf(int channel
, int ack
, struct sk_buff
*skb
, icn_card
* card
)
707 struct sk_buff
*nskb
;
711 "icn: Send packet too large\n");
715 if (!(card
->flags
& (channel
) ? ICN_FLAGS_B2ACTIVE
: ICN_FLAGS_B1ACTIVE
))
717 if (card
->sndcount
[channel
] > ICN_MAX_SQUEUE
)
719 #warning TODO test headroom or use skb->nb to flag ACK
720 nskb
= skb_clone(skb
, GFP_ATOMIC
);
722 /* Push ACK flag as one
723 * byte in front of data.
725 *(skb_push(nskb
, 1)) = ack
?1:0;
726 skb_queue_tail(&card
->spqueue
[channel
], nskb
);
730 spin_lock_irqsave(&card
->lock
, flags
);
731 card
->sndcount
[channel
] += len
;
732 spin_unlock_irqrestore(&card
->lock
, flags
);
738 * Check card's status after starting the bootstrap loader.
739 * On entry, the card's shared memory has already to be mapped.
741 * 0 on success (Boot loader ready)
742 * -EIO on failure (timeout)
745 icn_check_loader(int cardnumber
)
751 printk(KERN_DEBUG
"Loader %d ?\n", cardnumber
);
753 if (readb(&dev
.shmem
->data_control
.scns
) ||
754 readb(&dev
.shmem
->data_control
.scnr
)) {
757 "icn: Boot-Loader %d timed out.\n",
759 icn_release_channel();
763 printk(KERN_DEBUG
"Loader %d TO?\n", cardnumber
);
765 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
768 printk(KERN_DEBUG
"Loader %d OK\n", cardnumber
);
770 icn_release_channel();
776 /* Load the boot-code into the interface-card's memory and start it.
777 * Always called from user-process.
780 * buffer = pointer to packet
782 * 0 if successfully loaded
786 #define SLEEP(sec) { \
788 printk(KERN_DEBUG "SLEEP(%d)\n",slsec); \
790 msleep_interruptible(1000); \
799 icn_loadboot(u_char __user
* buffer
, icn_card
* card
)
806 printk(KERN_DEBUG
"icn_loadboot called, buffaddr=%08lx\n", (ulong
) buffer
);
808 if (!(codebuf
= kmalloc(ICN_CODE_STAGE1
, GFP_KERNEL
))) {
809 printk(KERN_WARNING
"icn: Could not allocate code buffer\n");
813 if (copy_from_user(codebuf
, buffer
, ICN_CODE_STAGE1
)) {
818 if (!request_region(card
->port
, ICN_PORTLEN
, card
->regname
)) {
820 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
823 card
->port
+ ICN_PORTLEN
);
829 card
->other
->rvalid
= 1;
832 if (!request_mem_region(dev
.memaddr
, 0x4000, "icn-isdn (all cards)")) {
834 "icn: memory at 0x%08lx in use.\n", dev
.memaddr
);
838 dev
.shmem
= ioremap(dev
.memaddr
, 0x4000);
841 OUTB_P(0, ICN_RUN
); /* Reset Controller */
842 OUTB_P(0, ICN_MAPRAM
); /* Disable RAM */
843 icn_shiftout(ICN_CFG
, 0x0f, 3, 4); /* Windowsize= 16k */
844 icn_shiftout(ICN_CFG
, dev
.memaddr
, 23, 10); /* Set RAM-Addr. */
846 printk(KERN_DEBUG
"shmem=%08lx\n", dev
.memaddr
);
850 printk(KERN_DEBUG
"Map Bank 0\n");
852 spin_lock_irqsave(&dev
.devlock
, flags
);
853 icn_map_channel(card
, 0); /* Select Bank 0 */
854 icn_lock_channel(card
, 0); /* Lock Bank 0 */
855 spin_unlock_irqrestore(&dev
.devlock
, flags
);
857 memcpy_toio(dev
.shmem
, codebuf
, ICN_CODE_STAGE1
); /* Copy code */
859 printk(KERN_DEBUG
"Bootloader transferred\n");
861 if (card
->doubleS0
) {
864 printk(KERN_DEBUG
"Map Bank 8\n");
866 spin_lock_irqsave(&dev
.devlock
, flags
);
867 __icn_release_channel();
868 icn_map_channel(card
, 2); /* Select Bank 8 */
869 icn_lock_channel(card
, 2); /* Lock Bank 8 */
870 spin_unlock_irqrestore(&dev
.devlock
, flags
);
872 memcpy_toio(dev
.shmem
, codebuf
, ICN_CODE_STAGE1
); /* Copy code */
874 printk(KERN_DEBUG
"Bootloader transferred\n");
878 OUTB_P(0xff, ICN_RUN
); /* Start Boot-Code */
879 if ((ret
= icn_check_loader(card
->doubleS0
? 2 : 1))) {
882 if (!card
->doubleS0
) {
886 /* reached only, if we have a Double-S0-Card */
888 printk(KERN_DEBUG
"Map Bank 0\n");
890 spin_lock_irqsave(&dev
.devlock
, flags
);
891 icn_map_channel(card
, 0); /* Select Bank 0 */
892 icn_lock_channel(card
, 0); /* Lock Bank 0 */
893 spin_unlock_irqrestore(&dev
.devlock
, flags
);
895 ret
= (icn_check_loader(1));
904 icn_loadproto(u_char __user
* buffer
, icn_card
* card
)
906 register u_char __user
*p
= buffer
;
908 uint left
= ICN_CODE_STAGE2
;
914 printk(KERN_DEBUG
"icn_loadproto called\n");
916 if (!access_ok(VERIFY_READ
, buffer
, ICN_CODE_STAGE2
))
919 spin_lock_irqsave(&dev
.devlock
, flags
);
920 if (card
->secondhalf
) {
921 icn_map_channel(card
, 2);
922 icn_lock_channel(card
, 2);
924 icn_map_channel(card
, 0);
925 icn_lock_channel(card
, 0);
927 spin_unlock_irqrestore(&dev
.devlock
, flags
);
929 if (sbfree
) { /* If there is a free buffer... */
933 if (copy_from_user(codebuf
, p
, cnt
)) {
934 icn_maprelease_channel(card
, 0);
937 memcpy_toio(&sbuf_l
, codebuf
, cnt
); /* copy data */
938 sbnext
; /* switch to next buffer */
944 printk(KERN_DEBUG
"boot 2 !sbfree\n");
947 icn_maprelease_channel(card
, 0);
950 set_current_state(TASK_INTERRUPTIBLE
);
951 schedule_timeout(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 put_user(*card
->msg_buf_read
++, p
);
1015 if (card
->msg_buf_read
> card
->msg_buf_end
)
1016 card
->msg_buf_read
= card
->msg_buf
;
1021 /* Put command-strings into the command-queue of the Interface */
1023 icn_writecmd(const u_char
* buf
, int len
, int user
, icn_card
* card
)
1025 int mch
= card
->secondhalf
? 2 : 0;
1032 unsigned long flags
;
1033 int lastmap_channel
;
1034 struct icn_card
*lastmap_card
;
1046 if (copy_from_user(msg
, buf
, count
))
1049 memcpy(msg
, buf
, count
);
1051 spin_lock_irqsave(&dev
.devlock
, flags
);
1052 lastmap_card
= dev
.mcard
;
1053 lastmap_channel
= dev
.channel
;
1054 icn_map_channel(card
, mch
);
1056 icn_putmsg(card
, '>');
1057 for (p
= msg
, pp
= readb(&cmd_i
), i
= count
; i
> 0; i
--, p
++, pp
1059 writeb((*p
== '\n') ? 0xff : *p
,
1060 &dev
.shmem
->comm_buffers
.pcio_buf
[pp
& 0xff]);
1063 icn_putmsg(card
, *p
);
1064 if ((*p
== '\n') && (i
> 1)) {
1065 icn_putmsg(card
, '>');
1070 writeb((readb(&cmd_i
) + count
) & 0xff, &cmd_i
);
1072 icn_map_channel(lastmap_card
, lastmap_channel
);
1073 spin_unlock_irqrestore(&dev
.devlock
, flags
);
1082 printk(KERN_WARNING
"icn: writemsg incomplete!\n");
1083 cmd
.command
= ISDN_STAT_STAVAIL
;
1084 cmd
.driver
= card
->myid
;
1086 card
->interface
.statcallb(&cmd
);
1091 * Delete card's pending timers, send STOP to linklevel
1094 icn_stopcard(icn_card
* card
)
1096 unsigned long flags
;
1099 spin_lock_irqsave(&card
->lock
, flags
);
1100 if (card
->flags
& ICN_FLAGS_RUNNING
) {
1101 card
->flags
&= ~ICN_FLAGS_RUNNING
;
1102 del_timer(&card
->st_timer
);
1103 del_timer(&card
->rb_timer
);
1104 spin_unlock_irqrestore(&card
->lock
, flags
);
1105 cmd
.command
= ISDN_STAT_STOP
;
1106 cmd
.driver
= card
->myid
;
1107 card
->interface
.statcallb(&cmd
);
1109 icn_stopcard(card
->other
);
1111 spin_unlock_irqrestore(&card
->lock
, flags
);
1115 icn_stopallcards(void)
1117 icn_card
*p
= cards
;
1126 * Unmap all cards, because some of them may be mapped accidetly during
1127 * autoprobing of some network drivers (SMC-driver?)
1130 icn_disable_cards(void)
1132 icn_card
*card
= cards
;
1135 if (!request_region(card
->port
, ICN_PORTLEN
, "icn-isdn")) {
1137 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1140 card
->port
+ ICN_PORTLEN
);
1142 OUTB_P(0, ICN_RUN
); /* Reset Controller */
1143 OUTB_P(0, ICN_MAPRAM
); /* Disable RAM */
1144 release_region(card
->port
, ICN_PORTLEN
);
1151 icn_command(isdn_ctrl
* c
, icn_card
* card
)
1161 switch (c
->command
) {
1162 case ISDN_CMD_IOCTL
:
1163 memcpy(&a
, c
->parm
.num
, sizeof(ulong
));
1164 arg
= (char __user
*)a
;
1166 case ICN_IOCTL_SETMMIO
:
1167 if (dev
.memaddr
!= (a
& 0x0ffc000)) {
1168 if (!request_mem_region(a
& 0x0ffc000, 0x4000, "icn-isdn (all cards)")) {
1170 "icn: memory at 0x%08lx in use.\n",
1174 release_mem_region(a
& 0x0ffc000, 0x4000);
1176 spin_lock_irqsave(&card
->lock
, flags
);
1179 release_mem_region(dev
.memaddr
, 0x4000);
1182 dev
.memaddr
= a
& 0x0ffc000;
1183 spin_unlock_irqrestore(&card
->lock
, flags
);
1185 "icn: (%s) mmio set to 0x%08lx\n",
1190 case ICN_IOCTL_GETMMIO
:
1191 return (long) dev
.memaddr
;
1192 case ICN_IOCTL_SETPORT
:
1193 if (a
== 0x300 || a
== 0x310 || a
== 0x320 || a
== 0x330
1194 || a
== 0x340 || a
== 0x350 || a
== 0x360 ||
1195 a
== 0x308 || a
== 0x318 || a
== 0x328 || a
== 0x338
1196 || a
== 0x348 || a
== 0x358 || a
== 0x368) {
1197 if (card
->port
!= (unsigned short) a
) {
1198 if (!request_region((unsigned short) a
, ICN_PORTLEN
, "icn-isdn")) {
1200 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1201 CID
, (int) a
, (int) a
+ ICN_PORTLEN
);
1204 release_region((unsigned short) a
, ICN_PORTLEN
);
1206 spin_lock_irqsave(&card
->lock
, flags
);
1208 release_region(card
->port
, ICN_PORTLEN
);
1209 card
->port
= (unsigned short) a
;
1211 if (card
->doubleS0
) {
1212 card
->other
->port
= (unsigned short) a
;
1213 card
->other
->rvalid
= 0;
1215 spin_unlock_irqrestore(&card
->lock
, flags
);
1217 "icn: (%s) port set to 0x%03x\n",
1223 case ICN_IOCTL_GETPORT
:
1224 return (int) card
->port
;
1225 case ICN_IOCTL_GETDOUBLE
:
1226 return (int) card
->doubleS0
;
1227 case ICN_IOCTL_DEBUGVAR
:
1228 if (copy_to_user(arg
,
1234 ulong l
= (ulong
) & dev
;
1235 if (copy_to_user(arg
,
1241 case ICN_IOCTL_LOADBOOT
:
1242 if (dev
.firstload
) {
1243 icn_disable_cards();
1247 return (icn_loadboot(arg
, card
));
1248 case ICN_IOCTL_LOADPROTO
:
1250 if ((i
= (icn_loadproto(arg
, card
))))
1253 i
= icn_loadproto(arg
+ ICN_CODE_STAGE2
, card
->other
);
1256 case ICN_IOCTL_ADDCARD
:
1259 if (copy_from_user(&cdef
,
1263 return (icn_addcard(cdef
.port
, cdef
.id1
, cdef
.id2
));
1265 case ICN_IOCTL_LEASEDCFG
:
1267 if (!card
->leased
) {
1269 while (card
->ptype
== ISDN_PTYPE_UNKNOWN
) {
1270 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
1272 msleep_interruptible(ICN_BOOT_TIMEOUT1
);
1273 sprintf(cbuf
, "00;FV2ON\n01;EAZ%c\n02;EAZ%c\n",
1274 (a
& 1)?'1':'C', (a
& 2)?'2':'C');
1275 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1277 "icn: (%s) Leased-line mode enabled\n",
1279 cmd
.command
= ISDN_STAT_RUN
;
1280 cmd
.driver
= card
->myid
;
1282 card
->interface
.statcallb(&cmd
);
1287 sprintf(cbuf
, "00;FV2OFF\n");
1288 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1290 "icn: (%s) Leased-line mode disabled\n",
1292 cmd
.command
= ISDN_STAT_RUN
;
1293 cmd
.driver
= card
->myid
;
1295 card
->interface
.statcallb(&cmd
);
1304 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1308 if ((c
->arg
& 255) < ICN_BCH
) {
1314 p
= c
->parm
.setup
.phone
;
1315 if (*p
== 's' || *p
== 'S') {
1318 strcpy(dcode
, "SCA");
1321 strcpy(dcode
, "CAL");
1323 sprintf(cbuf
, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a
+ 1),
1324 dcode
, dial
, c
->parm
.setup
.si1
,
1325 c
->parm
.setup
.si2
, c
->parm
.setup
.eazmsn
);
1326 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1329 case ISDN_CMD_ACCEPTD
:
1330 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1332 if (c
->arg
< ICN_BCH
) {
1334 if (card
->fw_rev
>= 300) {
1335 switch (card
->l2_proto
[a
- 1]) {
1336 case ISDN_PROTO_L2_X75I
:
1337 sprintf(cbuf
, "%02d;BX75\n", (int) a
);
1339 case ISDN_PROTO_L2_HDLC
:
1340 sprintf(cbuf
, "%02d;BTRA\n", (int) a
);
1343 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1345 sprintf(cbuf
, "%02d;DCON_R\n", (int) a
);
1346 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1349 case ISDN_CMD_ACCEPTB
:
1350 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1352 if (c
->arg
< ICN_BCH
) {
1354 if (card
->fw_rev
>= 300)
1355 switch (card
->l2_proto
[a
- 1]) {
1356 case ISDN_PROTO_L2_X75I
:
1357 sprintf(cbuf
, "%02d;BCON_R,BX75\n", (int) a
);
1359 case ISDN_PROTO_L2_HDLC
:
1360 sprintf(cbuf
, "%02d;BCON_R,BTRA\n", (int) a
);
1363 sprintf(cbuf
, "%02d;BCON_R\n", (int) a
);
1364 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1367 case ISDN_CMD_HANGUP
:
1368 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1370 if (c
->arg
< ICN_BCH
) {
1372 sprintf(cbuf
, "%02d;BDIS_R\n%02d;DDIS_R\n", (int) a
, (int) a
);
1373 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1376 case ISDN_CMD_SETEAZ
:
1377 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1381 if (c
->arg
< ICN_BCH
) {
1383 if (card
->ptype
== ISDN_PTYPE_EURO
) {
1384 sprintf(cbuf
, "%02d;MS%s%s\n", (int) a
,
1385 c
->parm
.num
[0] ? "N" : "ALL", c
->parm
.num
);
1387 sprintf(cbuf
, "%02d;EAZ%s\n", (int) a
,
1388 c
->parm
.num
[0] ? (char *)(c
->parm
.num
) : "0123456789");
1389 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1392 case ISDN_CMD_CLREAZ
:
1393 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1397 if (c
->arg
< ICN_BCH
) {
1399 if (card
->ptype
== ISDN_PTYPE_EURO
)
1400 sprintf(cbuf
, "%02d;MSNC\n", (int) a
);
1402 sprintf(cbuf
, "%02d;EAZC\n", (int) a
);
1403 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1406 case ISDN_CMD_SETL2
:
1407 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1409 if ((c
->arg
& 255) < ICN_BCH
) {
1412 case ISDN_PROTO_L2_X75I
:
1413 sprintf(cbuf
, "%02d;BX75\n", (int) (a
& 255) + 1);
1415 case ISDN_PROTO_L2_HDLC
:
1416 sprintf(cbuf
, "%02d;BTRA\n", (int) (a
& 255) + 1);
1421 i
= icn_writecmd(cbuf
, strlen(cbuf
), 0, card
);
1422 card
->l2_proto
[a
& 255] = (a
>> 8);
1425 case ISDN_CMD_SETL3
:
1426 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1436 * Find card with given driverId
1438 static inline icn_card
*
1439 icn_findcard(int driverid
)
1441 icn_card
*p
= cards
;
1444 if (p
->myid
== driverid
)
1448 return (icn_card
*) 0;
1452 * Wrapper functions for interface to linklevel
1455 if_command(isdn_ctrl
* c
)
1457 icn_card
*card
= icn_findcard(c
->driver
);
1460 return (icn_command(c
, card
));
1462 "icn: if_command %d called with invalid driverId %d!\n",
1463 c
->command
, c
->driver
);
1468 if_writecmd(const u_char __user
*buf
, int len
, int id
, int channel
)
1470 icn_card
*card
= icn_findcard(id
);
1473 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1475 return (icn_writecmd(buf
, len
, 1, card
));
1478 "icn: if_writecmd called with invalid driverId!\n");
1483 if_readstatus(u_char __user
*buf
, int len
, int id
, int channel
)
1485 icn_card
*card
= icn_findcard(id
);
1488 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1490 return (icn_readstatus(buf
, len
, card
));
1493 "icn: if_readstatus called with invalid driverId!\n");
1498 if_sendbuf(int id
, int channel
, int ack
, struct sk_buff
*skb
)
1500 icn_card
*card
= icn_findcard(id
);
1503 if (!card
->flags
& ICN_FLAGS_RUNNING
)
1505 return (icn_sendbuf(channel
, ack
, skb
, card
));
1508 "icn: if_sendbuf called with invalid driverId!\n");
1513 * Allocate a new card-struct, initialize it
1514 * link it into cards-list and register it at linklevel.
1517 icn_initcard(int port
, char *id
)
1522 if (!(card
= (icn_card
*) kmalloc(sizeof(icn_card
), GFP_KERNEL
))) {
1524 "icn: (%s) Could not allocate card-struct.\n", id
);
1525 return (icn_card
*) 0;
1527 memset((char *) card
, 0, sizeof(icn_card
));
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
;
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
);
1674 spin_unlock_irqrestore(&card
->lock
, flags
);
1685 release_mem_region(dev
.memaddr
, 0x4000);
1687 printk(KERN_NOTICE
"ICN-ISDN-driver unloaded\n");
1690 module_init(icn_init
);
1691 module_exit(icn_exit
);