2 * mISDNisar.c ISAR (Siemens PSB 7110) specific functions
4 * Author Karsten Keil (keil@isdn4linux.de)
6 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* define this to enable static debug messages, if you kernel supports
24 * dynamic debugging, you should use debugfs for this
28 #include <linux/gfp.h>
29 #include <linux/delay.h>
30 #include <linux/vmalloc.h>
31 #include <linux/mISDNhw.h>
32 #include <linux/module.h>
35 #define ISAR_REV "2.1"
37 MODULE_AUTHOR("Karsten Keil");
38 MODULE_LICENSE("GPL v2");
39 MODULE_VERSION(ISAR_REV
);
41 #define DEBUG_HW_FIRMWARE_FIFO 0x10000
43 static const u8 faxmodulation_s
[] = "3,24,48,72,73,74,96,97,98,121,122,145,146";
44 static const u8 faxmodulation
[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
48 static void isar_setup(struct isar_hw
*);
51 waitforHIA(struct isar_hw
*isar
, int timeout
)
54 u8 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
56 while ((val
& 1) && t
) {
59 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
61 pr_debug("%s: HIA after %dus\n", isar
->name
, timeout
- t
);
66 * send msg to ISAR mailbox
67 * if msg is NULL use isar->buf
70 send_mbox(struct isar_hw
*isar
, u8 his
, u8 creg
, u8 len
, u8
*msg
)
72 if (!waitforHIA(isar
, 1000))
74 pr_debug("send_mbox(%02x,%02x,%d)\n", his
, creg
, len
);
75 isar
->write_reg(isar
->hw
, ISAR_CTRL_H
, creg
);
76 isar
->write_reg(isar
->hw
, ISAR_CTRL_L
, len
);
77 isar
->write_reg(isar
->hw
, ISAR_WADR
, 0);
81 isar
->write_fifo(isar
->hw
, ISAR_MBOX
, msg
, len
);
82 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
85 while (l
< (int)len
) {
86 hex_dump_to_buffer(msg
+ l
, len
- l
, 32, 1,
88 pr_debug("%s: %s %02x: %s\n", isar
->name
,
89 __func__
, l
, isar
->log
);
94 isar
->write_reg(isar
->hw
, ISAR_HIS
, his
);
95 waitforHIA(isar
, 1000);
100 * receive message from ISAR mailbox
101 * if msg is NULL use isar->buf
104 rcv_mbox(struct isar_hw
*isar
, u8
*msg
)
108 isar
->write_reg(isar
->hw
, ISAR_RADR
, 0);
109 if (msg
&& isar
->clsb
) {
110 isar
->read_fifo(isar
->hw
, ISAR_MBOX
, msg
, isar
->clsb
);
111 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
114 while (l
< (int)isar
->clsb
) {
115 hex_dump_to_buffer(msg
+ l
, isar
->clsb
- l
, 32,
116 1, isar
->log
, 256, 1);
117 pr_debug("%s: %s %02x: %s\n", isar
->name
,
118 __func__
, l
, isar
->log
);
123 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
127 get_irq_infos(struct isar_hw
*isar
)
129 isar
->iis
= isar
->read_reg(isar
->hw
, ISAR_IIS
);
130 isar
->cmsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_H
);
131 isar
->clsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_L
);
132 pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar
->name
,
133 isar
->iis
, isar
->cmsb
, isar
->clsb
);
137 * poll answer message from ISAR mailbox
138 * should be used only with ISAR IRQs disabled before DSP was started
142 poll_mbox(struct isar_hw
*isar
, int maxdelay
)
147 irq
= isar
->read_reg(isar
->hw
, ISAR_IRQBIT
);
148 while (t
&& !(irq
& ISAR_IRQSTA
)) {
154 rcv_mbox(isar
, NULL
);
156 pr_debug("%s: pulled %d bytes after %d us\n",
157 isar
->name
, isar
->clsb
, maxdelay
- t
);
162 ISARVersion(struct isar_hw
*isar
)
166 /* disable ISAR IRQ */
167 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
168 isar
->buf
[0] = ISAR_MSG_HWVER
;
171 if (!send_mbox(isar
, ISAR_HIS_VNR
, 0, 3, NULL
))
173 if (!poll_mbox(isar
, 1000))
175 if (isar
->iis
== ISAR_IIS_VNR
) {
176 if (isar
->clsb
== 1) {
177 ver
= isar
->buf
[0] & 0xf;
186 load_firmware(struct isar_hw
*isar
, const u8
*buf
, int size
)
188 u32 saved_debug
= isar
->ch
[0].bch
.debug
;
191 u16 left
, val
, *sp
= (u16
*)buf
;
201 if (1 != isar
->version
) {
202 pr_err("%s: ISAR wrong version %d firmware download aborted\n",
203 isar
->name
, isar
->version
);
206 if (!(saved_debug
& DEBUG_HW_FIRMWARE_FIFO
))
207 isar
->ch
[0].bch
.debug
&= ~DEBUG_HW_BFIFO
;
208 pr_debug("%s: load firmware %d words (%d bytes)\n",
209 isar
->name
, size
/2, size
);
212 /* disable ISAR IRQ */
213 spin_lock_irqsave(isar
->hwlock
, flags
);
214 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
215 spin_unlock_irqrestore(isar
->hwlock
, flags
);
217 blk_head
.sadr
= le16_to_cpu(*sp
++);
218 blk_head
.len
= le16_to_cpu(*sp
++);
219 blk_head
.d_key
= le16_to_cpu(*sp
++);
221 pr_debug("ISAR firmware block (%#x,%d,%#x)\n",
222 blk_head
.sadr
, blk_head
.len
, blk_head
.d_key
& 0xff);
224 if (cnt
+ left
> size
) {
225 pr_info("%s: firmware error have %d need %d words\n",
226 isar
->name
, size
, cnt
+ left
);
230 spin_lock_irqsave(isar
->hwlock
, flags
);
231 if (!send_mbox(isar
, ISAR_HIS_DKEY
, blk_head
.d_key
& 0xff,
233 pr_info("ISAR send_mbox dkey failed\n");
237 if (!poll_mbox(isar
, 1000)) {
238 pr_warning("ISAR poll_mbox dkey failed\n");
242 spin_unlock_irqrestore(isar
->hwlock
, flags
);
243 if ((isar
->iis
!= ISAR_IIS_DKEY
) || isar
->cmsb
|| isar
->clsb
) {
244 pr_info("ISAR wrong dkey response (%x,%x,%x)\n",
245 isar
->iis
, isar
->cmsb
, isar
->clsb
);
256 /* the ISAR is big endian */
257 *mp
++ = blk_head
.sadr
>> 8;
258 *mp
++ = blk_head
.sadr
& 0xFF;
262 pr_debug("%s: load %3d words at %04x\n", isar
->name
,
264 blk_head
.sadr
+= noc
;
266 val
= le16_to_cpu(*sp
++);
271 spin_lock_irqsave(isar
->hwlock
, flags
);
272 if (!send_mbox(isar
, ISAR_HIS_FIRM
, 0, nom
, NULL
)) {
273 pr_info("ISAR send_mbox prog failed\n");
277 if (!poll_mbox(isar
, 1000)) {
278 pr_info("ISAR poll_mbox prog failed\n");
282 spin_unlock_irqrestore(isar
->hwlock
, flags
);
283 if ((isar
->iis
!= ISAR_IIS_FIRM
) ||
284 isar
->cmsb
|| isar
->clsb
) {
285 pr_info("ISAR wrong prog response (%x,%x,%x)\n",
286 isar
->iis
, isar
->cmsb
, isar
->clsb
);
291 pr_debug("%s: ISAR firmware block %d words loaded\n",
292 isar
->name
, blk_head
.len
);
294 isar
->ch
[0].bch
.debug
= saved_debug
;
302 spin_lock_irqsave(isar
->hwlock
, flags
);
303 if (!send_mbox(isar
, ISAR_HIS_STDSP
, 0, 2, NULL
)) {
304 pr_info("ISAR send_mbox start dsp failed\n");
308 if (!poll_mbox(isar
, 1000)) {
309 pr_info("ISAR poll_mbox start dsp failed\n");
313 if ((isar
->iis
!= ISAR_IIS_STDSP
) || isar
->cmsb
|| isar
->clsb
) {
314 pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",
315 isar
->iis
, isar
->cmsb
, isar
->clsb
);
319 pr_debug("%s: ISAR start dsp success\n", isar
->name
);
321 /* NORMAL mode entered */
322 /* Enable IRQs of ISAR */
323 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, ISAR_IRQSTA
);
324 spin_unlock_irqrestore(isar
->hwlock
, flags
);
325 cnt
= 1000; /* max 1s */
326 while ((!isar
->bstat
) && cnt
) {
331 pr_info("ISAR no general status event received\n");
335 pr_debug("%s: ISAR general status event %x\n",
336 isar
->name
, isar
->bstat
);
342 spin_lock_irqsave(isar
->hwlock
, flags
);
343 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_STST
, 0, NULL
)) {
344 pr_info("ISAR send_mbox self tst failed\n");
348 spin_unlock_irqrestore(isar
->hwlock
, flags
);
349 cnt
= 10000; /* max 100 ms */
350 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
356 pr_info("ISAR no self tst response\n");
360 if ((isar
->cmsb
== ISAR_CTRL_STST
) && (isar
->clsb
== 1)
361 && (isar
->buf
[0] == 0))
362 pr_debug("%s: ISAR selftest OK\n", isar
->name
);
364 pr_info("ISAR selftest not OK %x/%x/%x\n",
365 isar
->cmsb
, isar
->clsb
, isar
->buf
[0]);
369 spin_lock_irqsave(isar
->hwlock
, flags
);
371 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_SWVER
, 0, NULL
)) {
372 pr_info("ISAR RQST SVN failed\n");
376 spin_unlock_irqrestore(isar
->hwlock
, flags
);
377 cnt
= 30000; /* max 300 ms */
378 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
384 pr_info("ISAR no SVN response\n");
388 if ((isar
->cmsb
== ISAR_CTRL_SWVER
) && (isar
->clsb
== 1)) {
389 pr_notice("%s: ISAR software version %#x\n",
390 isar
->name
, isar
->buf
[0]);
392 pr_info("%s: ISAR wrong swver response (%x,%x)"
393 " cnt(%d)\n", isar
->name
, isar
->cmsb
,
399 spin_lock_irqsave(isar
->hwlock
, flags
);
401 spin_unlock_irqrestore(isar
->hwlock
, flags
);
404 spin_lock_irqsave(isar
->hwlock
, flags
);
406 isar
->ch
[0].bch
.debug
= saved_debug
;
408 /* disable ISAR IRQ */
409 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
410 spin_unlock_irqrestore(isar
->hwlock
, flags
);
415 deliver_status(struct isar_ch
*ch
, int status
)
417 pr_debug("%s: HL->LL FAXIND %x\n", ch
->is
->name
, status
);
418 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
, status
, 0, NULL
, GFP_ATOMIC
);
422 isar_rcv_frame(struct isar_ch
*ch
)
427 pr_debug("%s; ISAR zero len frame\n", ch
->is
->name
);
428 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
431 switch (ch
->bch
.state
) {
433 pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
434 ch
->is
->name
, ch
->is
->iis
, ch
->is
->cmsb
, ch
->is
->clsb
);
435 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
438 case ISDN_P_B_L2DTMF
:
439 case ISDN_P_B_MODEM_ASYNC
:
440 if (!ch
->bch
.rx_skb
) {
441 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
443 if (unlikely(!ch
->bch
.rx_skb
)) {
444 pr_info("%s: B receive out of memory\n",
446 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
450 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
451 recv_Bchannel(&ch
->bch
, 0);
454 if (!ch
->bch
.rx_skb
) {
455 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
457 if (unlikely(!ch
->bch
.rx_skb
)) {
458 pr_info("%s: B receive out of memory\n",
460 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
464 if ((ch
->bch
.rx_skb
->len
+ ch
->is
->clsb
) >
465 (ch
->bch
.maxlen
+ 2)) {
466 pr_debug("%s: incoming packet too large\n",
468 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
469 skb_trim(ch
->bch
.rx_skb
, 0);
472 if (ch
->is
->cmsb
& HDLC_ERROR
) {
473 pr_debug("%s: ISAR frame error %x len %d\n",
474 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
475 #ifdef ERROR_STATISTIC
476 if (ch
->is
->cmsb
& HDLC_ERR_RER
)
478 if (ch
->is
->cmsb
& HDLC_ERR_CER
)
481 skb_trim(ch
->bch
.rx_skb
, 0);
482 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
485 if (ch
->is
->cmsb
& HDLC_FSD
)
486 skb_trim(ch
->bch
.rx_skb
, 0);
487 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
488 rcv_mbox(ch
->is
, ptr
);
489 if (ch
->is
->cmsb
& HDLC_FED
) {
490 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
491 pr_debug("%s: ISAR frame to short %d\n",
492 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
493 skb_trim(ch
->bch
.rx_skb
, 0);
496 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
497 recv_Bchannel(&ch
->bch
, 0);
500 case ISDN_P_B_T30_FAX
:
501 if (ch
->state
!= STFAX_ACTIV
) {
502 pr_debug("%s: isar_rcv_frame: not ACTIV\n",
504 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
506 skb_trim(ch
->bch
.rx_skb
, 0);
509 if (!ch
->bch
.rx_skb
) {
510 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
512 if (unlikely(!ch
->bch
.rx_skb
)) {
513 pr_info("%s: B receive out of memory\n",
515 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
519 if (ch
->cmd
== PCTRL_CMD_FRM
) {
520 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
521 pr_debug("%s: isar_rcv_frame: %d\n",
522 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
523 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
524 pr_debug("%s: isar_rcv_frame: no more data\n",
526 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
527 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
528 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
530 ch
->state
= STFAX_ESCAPE
;
531 /* set_skb_flag(skb, DF_NOMOREDATA); */
533 recv_Bchannel(&ch
->bch
, 0);
534 if (ch
->is
->cmsb
& SART_NMD
)
535 deliver_status(ch
, HW_MOD_NOCARR
);
538 if (ch
->cmd
!= PCTRL_CMD_FRH
) {
539 pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
540 ch
->is
->name
, ch
->cmd
);
541 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
543 skb_trim(ch
->bch
.rx_skb
, 0);
547 if ((ch
->bch
.rx_skb
->len
+ ch
->is
->clsb
) >
548 (ch
->bch
.maxlen
+ 2)) {
549 pr_info("%s: %s incoming packet too large\n",
550 ch
->is
->name
, __func__
);
551 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
552 skb_trim(ch
->bch
.rx_skb
, 0);
554 } else if (ch
->is
->cmsb
& HDLC_ERROR
) {
555 pr_info("%s: ISAR frame error %x len %d\n",
556 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
557 skb_trim(ch
->bch
.rx_skb
, 0);
558 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
561 if (ch
->is
->cmsb
& HDLC_FSD
)
562 skb_trim(ch
->bch
.rx_skb
, 0);
563 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
564 rcv_mbox(ch
->is
, ptr
);
565 if (ch
->is
->cmsb
& HDLC_FED
) {
566 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
567 pr_info("%s: ISAR frame to short %d\n",
568 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
569 skb_trim(ch
->bch
.rx_skb
, 0);
572 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
573 recv_Bchannel(&ch
->bch
, 0);
575 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
576 pr_debug("%s: isar_rcv_frame: no more data\n",
578 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
580 skb_trim(ch
->bch
.rx_skb
, 0);
581 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
582 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
, 0, NULL
);
583 ch
->state
= STFAX_ESCAPE
;
584 deliver_status(ch
, HW_MOD_NOCARR
);
588 pr_info("isar_rcv_frame protocol (%x)error\n", ch
->bch
.state
);
589 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
595 isar_fill_fifo(struct isar_ch
*ch
)
601 pr_debug("%s: ch%d tx_skb %p tx_idx %d\n",
602 ch
->is
->name
, ch
->bch
.nr
, ch
->bch
.tx_skb
, ch
->bch
.tx_idx
);
605 count
= ch
->bch
.tx_skb
->len
- ch
->bch
.tx_idx
;
608 if (!(ch
->is
->bstat
&
609 (ch
->dpath
== 1 ? BSTAT_RDM1
: BSTAT_RDM2
)))
611 if (count
> ch
->mml
) {
617 ptr
= ch
->bch
.tx_skb
->data
+ ch
->bch
.tx_idx
;
618 if (!ch
->bch
.tx_idx
) {
619 pr_debug("%s: frame start\n", ch
->is
->name
);
620 if ((ch
->bch
.state
== ISDN_P_B_T30_FAX
) &&
621 (ch
->cmd
== PCTRL_CMD_FTH
)) {
623 if ((ptr
[0] == 0xff) && (ptr
[1] == 0x13)) {
625 test_and_set_bit(FLG_LASTDATA
,
627 pr_debug("%s: set LASTDATA\n",
630 test_and_set_bit(FLG_DLEETX
,
637 ch
->bch
.tx_idx
+= count
;
638 switch (ch
->bch
.state
) {
640 pr_info("%s: wrong protocol 0\n", __func__
);
643 case ISDN_P_B_L2DTMF
:
644 case ISDN_P_B_MODEM_ASYNC
:
645 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
649 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
652 case ISDN_P_B_T30_FAX
:
653 if (ch
->state
!= STFAX_ACTIV
)
654 pr_debug("%s: not ACTIV\n", ch
->is
->name
);
655 else if (ch
->cmd
== PCTRL_CMD_FTH
)
656 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
658 else if (ch
->cmd
== PCTRL_CMD_FTM
)
659 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
662 pr_debug("%s: not FTH/FTM\n", ch
->is
->name
);
665 pr_info("%s: protocol(%x) error\n",
666 __func__
, ch
->bch
.state
);
671 static inline struct isar_ch
*
672 sel_bch_isar(struct isar_hw
*isar
, u8 dpath
)
674 struct isar_ch
*base
= &isar
->ch
[0];
676 if ((!dpath
) || (dpath
> 2))
678 if (base
->dpath
== dpath
)
681 if (base
->dpath
== dpath
)
687 send_next(struct isar_ch
*ch
)
689 pr_debug("%s: %s ch%d tx_skb %p tx_idx %d\n",
690 ch
->is
->name
, __func__
, ch
->bch
.nr
,
691 ch
->bch
.tx_skb
, ch
->bch
.tx_idx
);
692 if (ch
->bch
.state
== ISDN_P_B_T30_FAX
) {
693 if (ch
->cmd
== PCTRL_CMD_FTH
) {
694 if (test_bit(FLG_LASTDATA
, &ch
->bch
.Flags
)) {
695 pr_debug("set NMD_DATA\n");
696 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
698 } else if (ch
->cmd
== PCTRL_CMD_FTM
) {
699 if (test_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
700 test_and_set_bit(FLG_LASTDATA
, &ch
->bch
.Flags
);
701 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
705 if (ch
->bch
.tx_skb
) {
706 /* send confirm, on trans, free on hdlc. */
707 if (test_bit(FLG_TRANSPARENT
, &ch
->bch
.Flags
))
708 confirm_Bsend(&ch
->bch
);
709 dev_kfree_skb(ch
->bch
.tx_skb
);
711 if (get_next_bframe(&ch
->bch
))
714 if (test_and_clear_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
715 if (test_and_clear_bit(FLG_LASTDATA
,
717 if (test_and_clear_bit(FLG_NMD_DATA
,
720 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
721 ISAR_HIS_SDATA
, 0x01, 1, &zd
);
723 test_and_set_bit(FLG_LL_OK
, &ch
->bch
.Flags
);
725 deliver_status(ch
, HW_MOD_CONNECT
);
732 check_send(struct isar_hw
*isar
, u8 rdm
)
736 pr_debug("%s: rdm %x\n", isar
->name
, rdm
);
737 if (rdm
& BSTAT_RDM1
) {
738 ch
= sel_bch_isar(isar
, 1);
739 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
740 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
747 if (rdm
& BSTAT_RDM2
) {
748 ch
= sel_bch_isar(isar
, 2);
749 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
750 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
759 const char *dmril
[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
760 "300", "600", "1200", "2400", "4800", "7200",
761 "9600nt", "9600t", "12000", "14400", "WRONG"};
762 const char *dmrim
[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
763 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
766 isar_pump_status_rsp(struct isar_ch
*ch
) {
767 u8 ril
= ch
->is
->buf
[0];
770 if (!test_and_clear_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
))
773 pr_info("%s: wrong pstrsp ril=%d\n", ch
->is
->name
, ril
);
776 switch (ch
->is
->buf
[1]) {
811 sprintf(ch
->conmsg
, "%s %s", dmril
[ril
], dmrim
[rim
]);
812 pr_debug("%s: pump strsp %s\n", ch
->is
->name
, ch
->conmsg
);
816 isar_pump_statev_modem(struct isar_ch
*ch
, u8 devt
) {
817 u8 dps
= SET_DPS(ch
->dpath
);
820 case PSEV_10MS_TIMER
:
821 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
824 pr_debug("%s: pump stev CONNECT\n", ch
->is
->name
);
825 deliver_status(ch
, HW_MOD_CONNECT
);
828 pr_debug("%s: pump stev NO CONNECT\n", ch
->is
->name
);
829 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
830 deliver_status(ch
, HW_MOD_NOCARR
);
833 pr_debug("%s: pump stev V24 OFF\n", ch
->is
->name
);
836 pr_debug("%s: pump stev CTS ON\n", ch
->is
->name
);
839 pr_debug("%s pump stev CTS OFF\n", ch
->is
->name
);
842 pr_debug("%s: pump stev CARRIER ON\n", ch
->is
->name
);
843 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
844 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
847 pr_debug("%s: pump stev CARRIER OFF\n", ch
->is
->name
);
850 pr_debug("%s: pump stev DSR ON\n", ch
->is
->name
);
853 pr_debug("%s: pump stev DSR_OFF\n", ch
->is
->name
);
856 pr_debug("%s: pump stev REMOTE RETRAIN\n", ch
->is
->name
);
859 pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch
->is
->name
);
862 pr_debug("%s: pump stev GSTN CLEAR\n", ch
->is
->name
);
865 pr_info("u%s: unknown pump stev %x\n", ch
->is
->name
, devt
);
871 isar_pump_statev_fax(struct isar_ch
*ch
, u8 devt
) {
872 u8 dps
= SET_DPS(ch
->dpath
);
876 case PSEV_10MS_TIMER
:
877 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
880 pr_debug("%s: pump stev RSP_READY\n", ch
->is
->name
);
881 ch
->state
= STFAX_READY
;
882 deliver_status(ch
, HW_MOD_READY
);
884 if (test_bit(BC_FLG_ORIG
, &ch
->bch
.Flags
))
885 isar_pump_cmd(bch
, HW_MOD_FRH
, 3);
887 isar_pump_cmd(bch
, HW_MOD_FTH
, 3);
891 if (ch
->state
== STFAX_LINE
) {
892 pr_debug("%s: pump stev LINE_TX_H\n", ch
->is
->name
);
893 ch
->state
= STFAX_CONT
;
894 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
895 PCTRL_CMD_CONT
, 0, NULL
);
897 pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
898 ch
->is
->name
, ch
->state
);
902 if (ch
->state
== STFAX_LINE
) {
903 pr_debug("%s: pump stev LINE_RX_H\n", ch
->is
->name
);
904 ch
->state
= STFAX_CONT
;
905 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
906 PCTRL_CMD_CONT
, 0, NULL
);
908 pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",
909 ch
->is
->name
, ch
->state
);
913 if (ch
->state
== STFAX_LINE
) {
914 pr_debug("%s: pump stev LINE_TX_B\n", ch
->is
->name
);
915 ch
->state
= STFAX_CONT
;
916 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
917 PCTRL_CMD_CONT
, 0, NULL
);
919 pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",
920 ch
->is
->name
, ch
->state
);
924 if (ch
->state
== STFAX_LINE
) {
925 pr_debug("%s: pump stev LINE_RX_B\n", ch
->is
->name
);
926 ch
->state
= STFAX_CONT
;
927 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
928 PCTRL_CMD_CONT
, 0, NULL
);
930 pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",
931 ch
->is
->name
, ch
->state
);
935 if (ch
->state
== STFAX_CONT
) {
936 pr_debug("%s: pump stev RSP_CONN\n", ch
->is
->name
);
937 ch
->state
= STFAX_ACTIV
;
938 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
939 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
940 if (ch
->cmd
== PCTRL_CMD_FTH
) {
941 int delay
= (ch
->mod
== 3) ? 1000 : 200;
942 /* 1s (200 ms) Flags before data */
943 if (test_and_set_bit(FLG_FTI_RUN
,
945 del_timer(&ch
->ftimer
);
947 jiffies
+ ((delay
* HZ
)/1000);
948 test_and_set_bit(FLG_LL_CONN
,
950 add_timer(&ch
->ftimer
);
952 deliver_status(ch
, HW_MOD_CONNECT
);
955 pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
956 ch
->is
->name
, ch
->state
);
960 pr_debug("%s: pump stev FLAGS_DET\n", ch
->is
->name
);
963 pr_debug("%s: pump stev RSP_DISC state(%d)\n",
964 ch
->is
->name
, ch
->state
);
965 if (ch
->state
== STFAX_ESCAPE
) {
967 switch (ch
->newcmd
) {
969 ch
->state
= STFAX_READY
;
974 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
975 PCTRL_CMD_SILON
, 1, &p1
);
976 ch
->state
= STFAX_SILDET
;
980 ch
->mod
= ch
->newmod
;
983 ch
->cmd
= ch
->newcmd
;
985 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
987 ch
->state
= STFAX_LINE
;
991 pr_debug("%s: RSP_DISC unknown newcmd %x\n",
992 ch
->is
->name
, ch
->newcmd
);
995 } else if (ch
->state
== STFAX_ACTIV
) {
996 if (test_and_clear_bit(FLG_LL_OK
, &ch
->bch
.Flags
))
997 deliver_status(ch
, HW_MOD_OK
);
998 else if (ch
->cmd
== PCTRL_CMD_FRM
)
999 deliver_status(ch
, HW_MOD_NOCARR
);
1001 deliver_status(ch
, HW_MOD_FCERROR
);
1002 ch
->state
= STFAX_READY
;
1003 } else if (ch
->state
!= STFAX_SILDET
) {
1004 /* ignore in STFAX_SILDET */
1005 ch
->state
= STFAX_READY
;
1006 deliver_status(ch
, HW_MOD_FCERROR
);
1009 case PSEV_RSP_SILDET
:
1010 pr_debug("%s: pump stev RSP_SILDET\n", ch
->is
->name
);
1011 if (ch
->state
== STFAX_SILDET
) {
1012 ch
->mod
= ch
->newmod
;
1015 ch
->cmd
= ch
->newcmd
;
1017 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1019 ch
->state
= STFAX_LINE
;
1023 case PSEV_RSP_SILOFF
:
1024 pr_debug("%s: pump stev RSP_SILOFF\n", ch
->is
->name
);
1026 case PSEV_RSP_FCERR
:
1027 if (ch
->state
== STFAX_LINE
) {
1028 pr_debug("%s: pump stev RSP_FCERR try %d\n",
1029 ch
->is
->name
, ch
->try_mod
);
1030 if (ch
->try_mod
--) {
1031 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1032 ch
->cmd
, 1, &ch
->mod
);
1036 pr_debug("%s: pump stev RSP_FCERR\n", ch
->is
->name
);
1037 ch
->state
= STFAX_ESCAPE
;
1038 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
1040 deliver_status(ch
, HW_MOD_FCERROR
);
1048 mISDNisar_irq(struct isar_hw
*isar
)
1052 get_irq_infos(isar
);
1053 switch (isar
->iis
& ISAR_IIS_MSCMSD
) {
1054 case ISAR_IIS_RDATA
:
1055 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1059 pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
1060 isar
->name
, isar
->iis
, isar
->cmsb
,
1062 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1065 case ISAR_IIS_GSTEV
:
1066 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1067 isar
->bstat
|= isar
->cmsb
;
1068 check_send(isar
, isar
->cmsb
);
1070 case ISAR_IIS_BSTEV
:
1071 #ifdef ERROR_STATISTIC
1072 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1074 if (isar
->cmsb
== BSTEV_TBO
)
1076 if (isar
->cmsb
== BSTEV_RBO
)
1080 pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
1081 isar
->name
, isar
->iis
>>6, isar
->cmsb
);
1082 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1084 case ISAR_IIS_PSTEV
:
1085 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1087 rcv_mbox(isar
, NULL
);
1088 if (ch
->bch
.state
== ISDN_P_B_MODEM_ASYNC
)
1089 isar_pump_statev_modem(ch
, isar
->cmsb
);
1090 else if (ch
->bch
.state
== ISDN_P_B_T30_FAX
)
1091 isar_pump_statev_fax(ch
, isar
->cmsb
);
1092 else if (ch
->bch
.state
== ISDN_P_B_RAW
) {
1094 tt
= isar
->cmsb
| 0x30;
1097 else if (tt
== 0x3f)
1101 tt
|= DTMF_TONE_VAL
;
1102 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
,
1103 MISDN_ID_ANY
, sizeof(tt
), &tt
,
1106 pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
1107 isar
->name
, ch
->bch
.state
,
1110 pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
1111 isar
->name
, isar
->iis
, isar
->cmsb
,
1113 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1116 case ISAR_IIS_PSTRSP
:
1117 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1119 rcv_mbox(isar
, NULL
);
1120 isar_pump_status_rsp(ch
);
1122 pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
1123 isar
->name
, isar
->iis
, isar
->cmsb
,
1125 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1129 case ISAR_IIS_BSTRSP
:
1130 case ISAR_IIS_IOM2RSP
:
1131 rcv_mbox(isar
, NULL
);
1133 case ISAR_IIS_INVMSG
:
1134 rcv_mbox(isar
, NULL
);
1135 pr_debug("%s: invalid msg his:%x\n", isar
->name
, isar
->cmsb
);
1138 rcv_mbox(isar
, NULL
);
1139 pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
1140 isar
->name
, isar
->iis
, isar
->cmsb
, isar
->clsb
);
1144 EXPORT_SYMBOL(mISDNisar_irq
);
1147 ftimer_handler(unsigned long data
)
1149 struct isar_ch
*ch
= (struct isar_ch
*)data
;
1151 pr_debug("%s: ftimer flags %lx\n", ch
->is
->name
, ch
->bch
.Flags
);
1152 test_and_clear_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1153 if (test_and_clear_bit(FLG_LL_CONN
, &ch
->bch
.Flags
))
1154 deliver_status(ch
, HW_MOD_CONNECT
);
1158 setup_pump(struct isar_ch
*ch
) {
1159 u8 dps
= SET_DPS(ch
->dpath
);
1162 switch (ch
->bch
.state
) {
1166 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, PMOD_BYPASS
, 0, NULL
);
1168 case ISDN_P_B_L2DTMF
:
1169 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
)) {
1170 param
[0] = 5; /* TOA 5 db */
1171 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1172 PMOD_DTMF_TRANS
, 1, param
);
1174 param
[0] = 40; /* REL -46 dbm */
1175 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1176 PMOD_DTMF
, 1, param
);
1178 case ISDN_P_B_MODEM_ASYNC
:
1179 ctrl
= PMOD_DATAMODEM
;
1180 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1182 param
[5] = PV32P6_CTN
;
1184 param
[5] = PV32P6_ATN
;
1186 param
[0] = 6; /* 6 db */
1187 param
[1] = PV32P2_V23R
| PV32P2_V22A
| PV32P2_V22B
|
1188 PV32P2_V22C
| PV32P2_V21
| PV32P2_BEL
;
1189 param
[2] = PV32P3_AMOD
| PV32P3_V32B
| PV32P3_V23B
;
1190 param
[3] = PV32P4_UT144
;
1191 param
[4] = PV32P5_UT144
;
1192 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 6, param
);
1194 case ISDN_P_B_T30_FAX
:
1196 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1198 param
[1] = PFAXP2_CTN
;
1200 param
[1] = PFAXP2_ATN
;
1202 param
[0] = 6; /* 6 db */
1203 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 2, param
);
1204 ch
->state
= STFAX_NULL
;
1207 test_and_set_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1211 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
1216 setup_sart(struct isar_ch
*ch
) {
1217 u8 dps
= SET_DPS(ch
->dpath
);
1218 u8 ctrl
, param
[2] = {0, 0};
1220 switch (ch
->bch
.state
) {
1222 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_DISABLE
,
1226 case ISDN_P_B_L2DTMF
:
1227 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_BINARY
,
1231 case ISDN_P_B_T30_FAX
:
1232 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_HDLC
,
1235 case ISDN_P_B_MODEM_ASYNC
:
1236 ctrl
= SMODE_V14
| SCTRL_HDMC_BOTH
;
1237 param
[0] = S_P1_CHS_8
;
1238 param
[1] = S_P2_BFT_DEF
;
1239 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, ctrl
, 2, param
);
1243 send_mbox(ch
->is
, dps
| ISAR_HIS_BSTREQ
, 0, 0, NULL
);
1248 setup_iom2(struct isar_ch
*ch
) {
1249 u8 dps
= SET_DPS(ch
->dpath
);
1250 u8 cmsb
= IOM_CTRL_ENA
, msg
[5] = {IOM_P1_TXD
, 0, 0, 0, 0};
1252 if (ch
->bch
.nr
== 2) {
1256 switch (ch
->bch
.state
) {
1260 msg
[1] = ch
->dpath
+ 2;
1261 msg
[3] = ch
->dpath
+ 2;
1266 case ISDN_P_B_MODEM_ASYNC
:
1267 case ISDN_P_B_T30_FAX
:
1268 cmsb
|= IOM_CTRL_RCV
;
1269 case ISDN_P_B_L2DTMF
:
1270 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
))
1271 cmsb
|= IOM_CTRL_RCV
;
1272 cmsb
|= IOM_CTRL_ALAW
;
1275 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2CFG
, cmsb
, 5, msg
);
1277 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2REQ
, 0, 0, NULL
);
1282 modeisar(struct isar_ch
*ch
, u32 bprotocol
)
1284 /* Here we are selecting the best datapath for requested protocol */
1285 if (ch
->bch
.state
== ISDN_P_NONE
) { /* New Setup */
1286 switch (bprotocol
) {
1287 case ISDN_P_NONE
: /* init */
1289 /* no init for dpath 0 */
1291 test_and_clear_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1292 test_and_clear_bit(FLG_TRANSPARENT
, &ch
->bch
.Flags
);
1296 /* best is datapath 2 */
1297 if (!test_and_set_bit(ISAR_DP2_USE
, &ch
->is
->Flags
))
1299 else if (!test_and_set_bit(ISAR_DP1_USE
,
1303 pr_info("modeisar both pathes in use\n");
1306 if (bprotocol
== ISDN_P_B_HDLC
)
1307 test_and_set_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1309 test_and_set_bit(FLG_TRANSPARENT
,
1312 case ISDN_P_B_MODEM_ASYNC
:
1313 case ISDN_P_B_T30_FAX
:
1314 case ISDN_P_B_L2DTMF
:
1315 /* only datapath 1 */
1316 if (!test_and_set_bit(ISAR_DP1_USE
, &ch
->is
->Flags
))
1319 pr_info("%s: ISAR modeisar analog functions"
1320 "only with DP1\n", ch
->is
->name
);
1325 pr_info("%s: protocol not known %x\n", ch
->is
->name
,
1327 return -ENOPROTOOPT
;
1330 pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch
->is
->name
,
1331 ch
->bch
.nr
, ch
->dpath
, ch
->bch
.state
, bprotocol
);
1332 ch
->bch
.state
= bprotocol
;
1336 if (ch
->bch
.state
== ISDN_P_NONE
) {
1337 /* Clear resources */
1339 test_and_clear_bit(ISAR_DP1_USE
, &ch
->is
->Flags
);
1340 else if (ch
->dpath
== 2)
1341 test_and_clear_bit(ISAR_DP2_USE
, &ch
->is
->Flags
);
1343 ch
->is
->ctrl(ch
->is
->hw
, HW_DEACT_IND
, ch
->bch
.nr
);
1345 ch
->is
->ctrl(ch
->is
->hw
, HW_ACTIVATE_IND
, ch
->bch
.nr
);
1350 isar_pump_cmd(struct isar_ch
*ch
, u32 cmd
, u8 para
)
1352 u8 dps
= SET_DPS(ch
->dpath
);
1353 u8 ctrl
= 0, nom
= 0, p1
= 0;
1355 pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
1356 ch
->is
->name
, cmd
, para
, ch
->bch
.state
);
1359 if (ch
->state
== STFAX_READY
) {
1361 ctrl
= PCTRL_CMD_FTM
;
1363 ch
->state
= STFAX_LINE
;
1369 } else if ((ch
->state
== STFAX_ACTIV
) &&
1370 (ch
->cmd
== PCTRL_CMD_FTM
) && (ch
->mod
== para
))
1371 deliver_status(ch
, HW_MOD_CONNECT
);
1374 ch
->newcmd
= PCTRL_CMD_FTM
;
1376 ctrl
= PCTRL_CMD_ESC
;
1377 ch
->state
= STFAX_ESCAPE
;
1381 if (ch
->state
== STFAX_READY
) {
1383 ctrl
= PCTRL_CMD_FTH
;
1385 ch
->state
= STFAX_LINE
;
1391 } else if ((ch
->state
== STFAX_ACTIV
) &&
1392 (ch
->cmd
== PCTRL_CMD_FTH
) && (ch
->mod
== para
))
1393 deliver_status(ch
, HW_MOD_CONNECT
);
1396 ch
->newcmd
= PCTRL_CMD_FTH
;
1398 ctrl
= PCTRL_CMD_ESC
;
1399 ch
->state
= STFAX_ESCAPE
;
1403 if (ch
->state
== STFAX_READY
) {
1405 ctrl
= PCTRL_CMD_FRM
;
1407 ch
->state
= STFAX_LINE
;
1413 } else if ((ch
->state
== STFAX_ACTIV
) &&
1414 (ch
->cmd
== PCTRL_CMD_FRM
) && (ch
->mod
== para
))
1415 deliver_status(ch
, HW_MOD_CONNECT
);
1418 ch
->newcmd
= PCTRL_CMD_FRM
;
1420 ctrl
= PCTRL_CMD_ESC
;
1421 ch
->state
= STFAX_ESCAPE
;
1425 if (ch
->state
== STFAX_READY
) {
1427 ctrl
= PCTRL_CMD_FRH
;
1429 ch
->state
= STFAX_LINE
;
1435 } else if ((ch
->state
== STFAX_ACTIV
) &&
1436 (ch
->cmd
== PCTRL_CMD_FRH
) && (ch
->mod
== para
))
1437 deliver_status(ch
, HW_MOD_CONNECT
);
1440 ch
->newcmd
= PCTRL_CMD_FRH
;
1442 ctrl
= PCTRL_CMD_ESC
;
1443 ch
->state
= STFAX_ESCAPE
;
1446 case PCTRL_CMD_TDTMF
:
1449 ctrl
= PCTRL_CMD_TDTMF
;
1453 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, ctrl
, nom
, &p1
);
1457 isar_setup(struct isar_hw
*isar
)
1464 for (i
= 0; i
< 2; i
++) {
1466 send_mbox(isar
, (i
? ISAR_HIS_DPS2
: ISAR_HIS_DPS1
) |
1467 ISAR_HIS_P12CFG
, 4, 1, &msg
);
1468 isar
->ch
[i
].mml
= msg
;
1469 isar
->ch
[i
].bch
.state
= 0;
1470 isar
->ch
[i
].dpath
= i
+ 1;
1471 modeisar(&isar
->ch
[i
], ISDN_P_NONE
);
1476 isar_l2l1(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1478 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1479 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1481 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1487 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1488 ret
= bchannel_senddata(bch
, skb
);
1489 if (ret
> 0) { /* direct TX */
1490 id
= hh
->id
; /* skb can be freed */
1492 isar_fill_fifo(ich
);
1493 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1494 if (!test_bit(FLG_TRANSPARENT
, &bch
->Flags
))
1495 queue_ch_frame(ch
, PH_DATA_CNF
, id
, NULL
);
1497 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1499 case PH_ACTIVATE_REQ
:
1500 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1501 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
))
1502 ret
= modeisar(ich
, ch
->protocol
);
1505 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1507 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
1510 case PH_DEACTIVATE_REQ
:
1511 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1512 mISDN_clear_bchannel(bch
);
1513 modeisar(ich
, ISDN_P_NONE
);
1514 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1515 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
, 0,
1519 case PH_CONTROL_REQ
:
1520 val
= (u32
*)skb
->data
;
1521 pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich
->is
->name
,
1523 if ((hh
->id
== 0) && ((*val
& ~DTMF_TONE_MASK
) ==
1525 if (bch
->state
== ISDN_P_B_L2DTMF
) {
1526 char tt
= *val
& DTMF_TONE_MASK
;
1535 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1536 isar_pump_cmd(ich
, PCTRL_CMD_TDTMF
, tt
);
1537 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1539 pr_info("%s: DTMF send wrong protocol %x\n",
1540 __func__
, bch
->state
);
1543 } else if ((hh
->id
== HW_MOD_FRM
) || (hh
->id
== HW_MOD_FRH
) ||
1544 (hh
->id
== HW_MOD_FTM
) || (hh
->id
== HW_MOD_FTH
)) {
1545 for (id
= 0; id
< FAXMODCNT
; id
++)
1546 if (faxmodulation
[id
] == *val
)
1548 if ((FAXMODCNT
> id
) &&
1549 test_bit(FLG_INITIALIZED
, &bch
->Flags
)) {
1550 pr_debug("%s: isar: new mod\n", ich
->is
->name
);
1551 isar_pump_cmd(ich
, hh
->id
, *val
);
1554 pr_info("%s: wrong modulation\n",
1558 } else if (hh
->id
== HW_MOD_LASTDATA
)
1559 test_and_set_bit(FLG_DLEETX
, &bch
->Flags
);
1561 pr_info("%s: unknown PH_CONTROL_REQ %x\n",
1562 ich
->is
->name
, hh
->id
);
1566 pr_info("%s: %s unknown prim(%x,%x)\n",
1567 ich
->is
->name
, __func__
, hh
->prim
, hh
->id
);
1576 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
1581 case MISDN_CTRL_GETOP
:
1584 /* Nothing implemented yet */
1585 case MISDN_CTRL_FILL_EMPTY
:
1587 pr_info("%s: unknown Op %x\n", __func__
, cq
->op
);
1595 isar_bctrl(struct mISDNchannel
*ch
, u32 cmd
, void *arg
)
1597 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1598 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1602 pr_debug("%s: %s cmd:%x %p\n", ich
->is
->name
, __func__
, cmd
, arg
);
1605 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1606 if (test_bit(FLG_ACTIVE
, &bch
->Flags
)) {
1607 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1608 mISDN_freebchannel(bch
);
1609 modeisar(ich
, ISDN_P_NONE
);
1610 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1612 skb_queue_purge(&bch
->rqueue
);
1615 ch
->protocol
= ISDN_P_NONE
;
1617 module_put(ich
->is
->owner
);
1620 case CONTROL_CHANNEL
:
1621 ret
= channel_bctrl(bch
, arg
);
1624 pr_info("%s: %s unknown prim(%x)\n",
1625 ich
->is
->name
, __func__
, cmd
);
1631 free_isar(struct isar_hw
*isar
)
1633 modeisar(&isar
->ch
[0], ISDN_P_NONE
);
1634 modeisar(&isar
->ch
[1], ISDN_P_NONE
);
1635 del_timer(&isar
->ch
[0].ftimer
);
1636 del_timer(&isar
->ch
[1].ftimer
);
1637 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1638 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1642 init_isar(struct isar_hw
*isar
)
1647 isar
->version
= ISARVersion(isar
);
1648 if (isar
->ch
[0].bch
.debug
& DEBUG_HW
)
1649 pr_notice("%s: Testing version %d (%d time)\n",
1650 isar
->name
, isar
->version
, 3 - cnt
);
1651 if (isar
->version
== 1)
1653 isar
->ctrl(isar
->hw
, HW_RESET_REQ
, 0);
1655 if (isar
->version
!= 1)
1657 isar
->ch
[0].ftimer
.function
= &ftimer_handler
;
1658 isar
->ch
[0].ftimer
.data
= (long)&isar
->ch
[0];
1659 init_timer(&isar
->ch
[0].ftimer
);
1660 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1661 isar
->ch
[1].ftimer
.function
= &ftimer_handler
;
1662 isar
->ch
[1].ftimer
.data
= (long)&isar
->ch
[1];
1663 init_timer(&isar
->ch
[1].ftimer
);
1664 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1669 isar_open(struct isar_hw
*isar
, struct channel_req
*rq
)
1671 struct bchannel
*bch
;
1673 if (rq
->adr
.channel
> 2)
1675 if (rq
->protocol
== ISDN_P_NONE
)
1677 bch
= &isar
->ch
[rq
->adr
.channel
- 1].bch
;
1678 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
1679 return -EBUSY
; /* b-channel can be only open once */
1680 test_and_clear_bit(FLG_FILLEMPTY
, &bch
->Flags
);
1681 bch
->ch
.protocol
= rq
->protocol
;
1687 mISDNisar_init(struct isar_hw
*isar
, void *hw
)
1692 for (i
= 0; i
< 2; i
++) {
1693 isar
->ch
[i
].bch
.nr
= i
+ 1;
1694 mISDN_initbchannel(&isar
->ch
[i
].bch
, MAX_DATA_MEM
);
1695 isar
->ch
[i
].bch
.ch
.nr
= i
+ 1;
1696 isar
->ch
[i
].bch
.ch
.send
= &isar_l2l1
;
1697 isar
->ch
[i
].bch
.ch
.ctrl
= isar_bctrl
;
1698 isar
->ch
[i
].bch
.hw
= hw
;
1699 isar
->ch
[i
].is
= isar
;
1702 isar
->init
= &init_isar
;
1703 isar
->release
= &free_isar
;
1704 isar
->firmware
= &load_firmware
;
1705 isar
->open
= &isar_open
;
1707 ret
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1708 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
)) |
1709 (1 << (ISDN_P_B_L2DTMF
& ISDN_P_B_MASK
)) |
1710 (1 << (ISDN_P_B_MODEM_ASYNC
& ISDN_P_B_MASK
)) |
1711 (1 << (ISDN_P_B_T30_FAX
& ISDN_P_B_MASK
));
1715 EXPORT_SYMBOL(mISDNisar_init
);
1717 static int __init
isar_mod_init(void)
1719 pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV
);
1723 static void __exit
isar_mod_cleanup(void)
1725 pr_notice("mISDN: ISAR module unloaded\n");
1727 module_init(isar_mod_init
);
1728 module_exit(isar_mod_cleanup
);