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/delay.h>
29 #include <linux/vmalloc.h>
30 #include <linux/mISDNhw.h>
33 #define ISAR_REV "2.1"
35 MODULE_AUTHOR("Karsten Keil");
36 MODULE_LICENSE("GPL v2");
37 MODULE_VERSION(ISAR_REV
);
39 #define DEBUG_HW_FIRMWARE_FIFO 0x10000
41 static const u8 faxmodulation_s
[] = "3,24,48,72,73,74,96,97,98,121,122,145,146";
42 static const u8 faxmodulation
[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
46 static void isar_setup(struct isar_hw
*);
49 waitforHIA(struct isar_hw
*isar
, int timeout
)
52 u8 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
54 while ((val
& 1) && t
) {
57 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
59 pr_debug("%s: HIA after %dus\n", isar
->name
, timeout
- t
);
64 * send msg to ISAR mailbox
65 * if msg is NULL use isar->buf
68 send_mbox(struct isar_hw
*isar
, u8 his
, u8 creg
, u8 len
, u8
*msg
)
70 if (!waitforHIA(isar
, 1000))
72 pr_debug("send_mbox(%02x,%02x,%d)\n", his
, creg
, len
);
73 isar
->write_reg(isar
->hw
, ISAR_CTRL_H
, creg
);
74 isar
->write_reg(isar
->hw
, ISAR_CTRL_L
, len
);
75 isar
->write_reg(isar
->hw
, ISAR_WADR
, 0);
79 isar
->write_fifo(isar
->hw
, ISAR_MBOX
, msg
, len
);
80 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
83 while (l
< (int)len
) {
84 hex_dump_to_buffer(msg
+ l
, len
- l
, 32, 1,
86 pr_debug("%s: %s %02x: %s\n", isar
->name
,
87 __func__
, l
, isar
->log
);
92 isar
->write_reg(isar
->hw
, ISAR_HIS
, his
);
93 waitforHIA(isar
, 1000);
98 * receive message from ISAR mailbox
99 * if msg is NULL use isar->buf
102 rcv_mbox(struct isar_hw
*isar
, u8
*msg
)
106 isar
->write_reg(isar
->hw
, ISAR_RADR
, 0);
107 if (msg
&& isar
->clsb
) {
108 isar
->read_fifo(isar
->hw
, ISAR_MBOX
, msg
, isar
->clsb
);
109 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
112 while (l
< (int)isar
->clsb
) {
113 hex_dump_to_buffer(msg
+ l
, isar
->clsb
- l
, 32,
114 1, isar
->log
, 256, 1);
115 pr_debug("%s: %s %02x: %s\n", isar
->name
,
116 __func__
, l
, isar
->log
);
121 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
125 get_irq_infos(struct isar_hw
*isar
)
127 isar
->iis
= isar
->read_reg(isar
->hw
, ISAR_IIS
);
128 isar
->cmsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_H
);
129 isar
->clsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_L
);
130 pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar
->name
,
131 isar
->iis
, isar
->cmsb
, isar
->clsb
);
135 * poll answer message from ISAR mailbox
136 * should be used only with ISAR IRQs disabled before DSP was started
140 poll_mbox(struct isar_hw
*isar
, int maxdelay
)
145 irq
= isar
->read_reg(isar
->hw
, ISAR_IRQBIT
);
146 while (t
&& !(irq
& ISAR_IRQSTA
)) {
152 rcv_mbox(isar
, NULL
);
154 pr_debug("%s: pulled %d bytes after %d us\n",
155 isar
->name
, isar
->clsb
, maxdelay
- t
);
160 ISARVersion(struct isar_hw
*isar
)
164 /* disable ISAR IRQ */
165 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
166 isar
->buf
[0] = ISAR_MSG_HWVER
;
169 if (!send_mbox(isar
, ISAR_HIS_VNR
, 0, 3, NULL
))
171 if (!poll_mbox(isar
, 1000))
173 if (isar
->iis
== ISAR_IIS_VNR
) {
174 if (isar
->clsb
== 1) {
175 ver
= isar
->buf
[0] & 0xf;
184 load_firmware(struct isar_hw
*isar
, const u8
*buf
, int size
)
186 u32 saved_debug
= isar
->ch
[0].bch
.debug
;
189 u16 left
, val
, *sp
= (u16
*)buf
;
199 if (1 != isar
->version
) {
200 pr_err("%s: ISAR wrong version %d firmware download aborted\n",
201 isar
->name
, isar
->version
);
204 if (!(saved_debug
& DEBUG_HW_FIRMWARE_FIFO
))
205 isar
->ch
[0].bch
.debug
&= ~DEBUG_HW_BFIFO
;
206 pr_debug("%s: load firmware %d words (%d bytes)\n",
207 isar
->name
, size
/2, size
);
210 /* disable ISAR IRQ */
211 spin_lock_irqsave(isar
->hwlock
, flags
);
212 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
213 spin_unlock_irqrestore(isar
->hwlock
, flags
);
215 blk_head
.sadr
= le16_to_cpu(*sp
++);
216 blk_head
.len
= le16_to_cpu(*sp
++);
217 blk_head
.d_key
= le16_to_cpu(*sp
++);
219 pr_debug("ISAR firmware block (%#x,%d,%#x)\n",
220 blk_head
.sadr
, blk_head
.len
, blk_head
.d_key
& 0xff);
222 if (cnt
+ left
> size
) {
223 pr_info("%s: firmware error have %d need %d words\n",
224 isar
->name
, size
, cnt
+ left
);
228 spin_lock_irqsave(isar
->hwlock
, flags
);
229 if (!send_mbox(isar
, ISAR_HIS_DKEY
, blk_head
.d_key
& 0xff,
231 pr_info("ISAR send_mbox dkey failed\n");
235 if (!poll_mbox(isar
, 1000)) {
236 pr_warning("ISAR poll_mbox dkey failed\n");
240 spin_unlock_irqrestore(isar
->hwlock
, flags
);
241 if ((isar
->iis
!= ISAR_IIS_DKEY
) || isar
->cmsb
|| isar
->clsb
) {
242 pr_info("ISAR wrong dkey response (%x,%x,%x)\n",
243 isar
->iis
, isar
->cmsb
, isar
->clsb
);
254 /* the ISAR is big endian */
255 *mp
++ = blk_head
.sadr
>> 8;
256 *mp
++ = blk_head
.sadr
& 0xFF;
260 pr_debug("%s: load %3d words at %04x\n", isar
->name
,
262 blk_head
.sadr
+= noc
;
264 val
= le16_to_cpu(*sp
++);
269 spin_lock_irqsave(isar
->hwlock
, flags
);
270 if (!send_mbox(isar
, ISAR_HIS_FIRM
, 0, nom
, NULL
)) {
271 pr_info("ISAR send_mbox prog failed\n");
275 if (!poll_mbox(isar
, 1000)) {
276 pr_info("ISAR poll_mbox prog failed\n");
280 spin_unlock_irqrestore(isar
->hwlock
, flags
);
281 if ((isar
->iis
!= ISAR_IIS_FIRM
) ||
282 isar
->cmsb
|| isar
->clsb
) {
283 pr_info("ISAR wrong prog response (%x,%x,%x)\n",
284 isar
->iis
, isar
->cmsb
, isar
->clsb
);
289 pr_debug("%s: ISAR firmware block %d words loaded\n",
290 isar
->name
, blk_head
.len
);
292 isar
->ch
[0].bch
.debug
= saved_debug
;
300 spin_lock_irqsave(isar
->hwlock
, flags
);
301 if (!send_mbox(isar
, ISAR_HIS_STDSP
, 0, 2, NULL
)) {
302 pr_info("ISAR send_mbox start dsp failed\n");
306 if (!poll_mbox(isar
, 1000)) {
307 pr_info("ISAR poll_mbox start dsp failed\n");
311 if ((isar
->iis
!= ISAR_IIS_STDSP
) || isar
->cmsb
|| isar
->clsb
) {
312 pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",
313 isar
->iis
, isar
->cmsb
, isar
->clsb
);
317 pr_debug("%s: ISAR start dsp success\n", isar
->name
);
319 /* NORMAL mode entered */
320 /* Enable IRQs of ISAR */
321 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, ISAR_IRQSTA
);
322 spin_unlock_irqrestore(isar
->hwlock
, flags
);
323 cnt
= 1000; /* max 1s */
324 while ((!isar
->bstat
) && cnt
) {
329 pr_info("ISAR no general status event received\n");
333 pr_debug("%s: ISAR general status event %x\n",
334 isar
->name
, isar
->bstat
);
340 spin_lock_irqsave(isar
->hwlock
, flags
);
341 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_STST
, 0, NULL
)) {
342 pr_info("ISAR send_mbox self tst failed\n");
346 spin_unlock_irqrestore(isar
->hwlock
, flags
);
347 cnt
= 10000; /* max 100 ms */
348 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
354 pr_info("ISAR no self tst response\n");
358 if ((isar
->cmsb
== ISAR_CTRL_STST
) && (isar
->clsb
== 1)
359 && (isar
->buf
[0] == 0))
360 pr_debug("%s: ISAR selftest OK\n", isar
->name
);
362 pr_info("ISAR selftest not OK %x/%x/%x\n",
363 isar
->cmsb
, isar
->clsb
, isar
->buf
[0]);
367 spin_lock_irqsave(isar
->hwlock
, flags
);
369 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_SWVER
, 0, NULL
)) {
370 pr_info("ISAR RQST SVN failed\n");
374 spin_unlock_irqrestore(isar
->hwlock
, flags
);
375 cnt
= 30000; /* max 300 ms */
376 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
382 pr_info("ISAR no SVN response\n");
386 if ((isar
->cmsb
== ISAR_CTRL_SWVER
) && (isar
->clsb
== 1)) {
387 pr_notice("%s: ISAR software version %#x\n",
388 isar
->name
, isar
->buf
[0]);
390 pr_info("%s: ISAR wrong swver response (%x,%x)"
391 " cnt(%d)\n", isar
->name
, isar
->cmsb
,
397 spin_lock_irqsave(isar
->hwlock
, flags
);
399 spin_unlock_irqrestore(isar
->hwlock
, flags
);
402 spin_lock_irqsave(isar
->hwlock
, flags
);
404 isar
->ch
[0].bch
.debug
= saved_debug
;
406 /* disable ISAR IRQ */
407 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
408 spin_unlock_irqrestore(isar
->hwlock
, flags
);
413 deliver_status(struct isar_ch
*ch
, int status
)
415 pr_debug("%s: HL->LL FAXIND %x\n", ch
->is
->name
, status
);
416 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
, status
, 0, NULL
, GFP_ATOMIC
);
420 isar_rcv_frame(struct isar_ch
*ch
)
425 pr_debug("%s; ISAR zero len frame\n", ch
->is
->name
);
426 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
429 switch (ch
->bch
.state
) {
431 pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
432 ch
->is
->name
, ch
->is
->iis
, ch
->is
->cmsb
, ch
->is
->clsb
);
433 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
436 case ISDN_P_B_L2DTMF
:
437 case ISDN_P_B_MODEM_ASYNC
:
438 if (!ch
->bch
.rx_skb
) {
439 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
441 if (unlikely(!ch
->bch
.rx_skb
)) {
442 pr_info("%s: B receive out of memory\n",
444 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
448 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
449 recv_Bchannel(&ch
->bch
, 0);
452 if (!ch
->bch
.rx_skb
) {
453 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
455 if (unlikely(!ch
->bch
.rx_skb
)) {
456 pr_info("%s: B receive out of memory\n",
458 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
462 if ((ch
->bch
.rx_skb
->len
+ ch
->is
->clsb
) >
463 (ch
->bch
.maxlen
+ 2)) {
464 pr_debug("%s: incoming packet too large\n",
466 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
467 skb_trim(ch
->bch
.rx_skb
, 0);
470 if (ch
->is
->cmsb
& HDLC_ERROR
) {
471 pr_debug("%s: ISAR frame error %x len %d\n",
472 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
473 #ifdef ERROR_STATISTIC
474 if (ch
->is
->cmsb
& HDLC_ERR_RER
)
476 if (ch
->is
->cmsb
& HDLC_ERR_CER
)
479 skb_trim(ch
->bch
.rx_skb
, 0);
480 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
483 if (ch
->is
->cmsb
& HDLC_FSD
)
484 skb_trim(ch
->bch
.rx_skb
, 0);
485 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
486 rcv_mbox(ch
->is
, ptr
);
487 if (ch
->is
->cmsb
& HDLC_FED
) {
488 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
489 pr_debug("%s: ISAR frame to short %d\n",
490 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
491 skb_trim(ch
->bch
.rx_skb
, 0);
494 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
495 recv_Bchannel(&ch
->bch
, 0);
498 case ISDN_P_B_T30_FAX
:
499 if (ch
->state
!= STFAX_ACTIV
) {
500 pr_debug("%s: isar_rcv_frame: not ACTIV\n",
502 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
504 skb_trim(ch
->bch
.rx_skb
, 0);
507 if (!ch
->bch
.rx_skb
) {
508 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
510 if (unlikely(!ch
->bch
.rx_skb
)) {
511 pr_info("%s: B receive out of memory\n",
513 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
517 if (ch
->cmd
== PCTRL_CMD_FRM
) {
518 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
519 pr_debug("%s: isar_rcv_frame: %d\n",
520 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
521 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
522 pr_debug("%s: isar_rcv_frame: no more data\n",
524 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
525 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
526 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
528 ch
->state
= STFAX_ESCAPE
;
529 /* set_skb_flag(skb, DF_NOMOREDATA); */
531 recv_Bchannel(&ch
->bch
, 0);
532 if (ch
->is
->cmsb
& SART_NMD
)
533 deliver_status(ch
, HW_MOD_NOCARR
);
536 if (ch
->cmd
!= PCTRL_CMD_FRH
) {
537 pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
538 ch
->is
->name
, ch
->cmd
);
539 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
541 skb_trim(ch
->bch
.rx_skb
, 0);
545 if ((ch
->bch
.rx_skb
->len
+ ch
->is
->clsb
) >
546 (ch
->bch
.maxlen
+ 2)) {
547 pr_info("%s: %s incoming packet too large\n",
548 ch
->is
->name
, __func__
);
549 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
550 skb_trim(ch
->bch
.rx_skb
, 0);
552 } else if (ch
->is
->cmsb
& HDLC_ERROR
) {
553 pr_info("%s: ISAR frame error %x len %d\n",
554 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
555 skb_trim(ch
->bch
.rx_skb
, 0);
556 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
559 if (ch
->is
->cmsb
& HDLC_FSD
)
560 skb_trim(ch
->bch
.rx_skb
, 0);
561 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
562 rcv_mbox(ch
->is
, ptr
);
563 if (ch
->is
->cmsb
& HDLC_FED
) {
564 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
565 pr_info("%s: ISAR frame to short %d\n",
566 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
567 skb_trim(ch
->bch
.rx_skb
, 0);
570 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
571 recv_Bchannel(&ch
->bch
, 0);
573 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
574 pr_debug("%s: isar_rcv_frame: no more data\n",
576 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
578 skb_trim(ch
->bch
.rx_skb
, 0);
579 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
580 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
, 0, NULL
);
581 ch
->state
= STFAX_ESCAPE
;
582 deliver_status(ch
, HW_MOD_NOCARR
);
586 pr_info("isar_rcv_frame protocol (%x)error\n", ch
->bch
.state
);
587 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
593 isar_fill_fifo(struct isar_ch
*ch
)
599 pr_debug("%s: ch%d tx_skb %p tx_idx %d\n",
600 ch
->is
->name
, ch
->bch
.nr
, ch
->bch
.tx_skb
, ch
->bch
.tx_idx
);
603 count
= ch
->bch
.tx_skb
->len
- ch
->bch
.tx_idx
;
606 if (!(ch
->is
->bstat
&
607 (ch
->dpath
== 1 ? BSTAT_RDM1
: BSTAT_RDM2
)))
609 if (count
> ch
->mml
) {
615 ptr
= ch
->bch
.tx_skb
->data
+ ch
->bch
.tx_idx
;
616 if (!ch
->bch
.tx_idx
) {
617 pr_debug("%s: frame start\n", ch
->is
->name
);
618 if ((ch
->bch
.state
== ISDN_P_B_T30_FAX
) &&
619 (ch
->cmd
== PCTRL_CMD_FTH
)) {
621 if ((ptr
[0] == 0xff) && (ptr
[1] == 0x13)) {
623 test_and_set_bit(FLG_LASTDATA
,
625 pr_debug("%s: set LASTDATA\n",
628 test_and_set_bit(FLG_DLEETX
,
635 ch
->bch
.tx_idx
+= count
;
636 switch (ch
->bch
.state
) {
638 pr_info("%s: wrong protocol 0\n", __func__
);
641 case ISDN_P_B_L2DTMF
:
642 case ISDN_P_B_MODEM_ASYNC
:
643 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
647 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
650 case ISDN_P_B_T30_FAX
:
651 if (ch
->state
!= STFAX_ACTIV
)
652 pr_debug("%s: not ACTIV\n", ch
->is
->name
);
653 else if (ch
->cmd
== PCTRL_CMD_FTH
)
654 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
656 else if (ch
->cmd
== PCTRL_CMD_FTM
)
657 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
660 pr_debug("%s: not FTH/FTM\n", ch
->is
->name
);
663 pr_info("%s: protocol(%x) error\n",
664 __func__
, ch
->bch
.state
);
669 static inline struct isar_ch
*
670 sel_bch_isar(struct isar_hw
*isar
, u8 dpath
)
672 struct isar_ch
*base
= &isar
->ch
[0];
674 if ((!dpath
) || (dpath
> 2))
676 if (base
->dpath
== dpath
)
679 if (base
->dpath
== dpath
)
685 send_next(struct isar_ch
*ch
)
687 pr_debug("%s: %s ch%d tx_skb %p tx_idx %d\n",
688 ch
->is
->name
, __func__
, ch
->bch
.nr
,
689 ch
->bch
.tx_skb
, ch
->bch
.tx_idx
);
690 if (ch
->bch
.state
== ISDN_P_B_T30_FAX
) {
691 if (ch
->cmd
== PCTRL_CMD_FTH
) {
692 if (test_bit(FLG_LASTDATA
, &ch
->bch
.Flags
)) {
693 pr_debug("set NMD_DATA\n");
694 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
696 } else if (ch
->cmd
== PCTRL_CMD_FTM
) {
697 if (test_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
698 test_and_set_bit(FLG_LASTDATA
, &ch
->bch
.Flags
);
699 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
703 if (ch
->bch
.tx_skb
) {
704 /* send confirm, on trans, free on hdlc. */
705 if (test_bit(FLG_TRANSPARENT
, &ch
->bch
.Flags
))
706 confirm_Bsend(&ch
->bch
);
707 dev_kfree_skb(ch
->bch
.tx_skb
);
709 if (get_next_bframe(&ch
->bch
))
712 if (test_and_clear_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
713 if (test_and_clear_bit(FLG_LASTDATA
,
715 if (test_and_clear_bit(FLG_NMD_DATA
,
718 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
719 ISAR_HIS_SDATA
, 0x01, 1, &zd
);
721 test_and_set_bit(FLG_LL_OK
, &ch
->bch
.Flags
);
723 deliver_status(ch
, HW_MOD_CONNECT
);
730 check_send(struct isar_hw
*isar
, u8 rdm
)
734 pr_debug("%s: rdm %x\n", isar
->name
, rdm
);
735 if (rdm
& BSTAT_RDM1
) {
736 ch
= sel_bch_isar(isar
, 1);
737 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
738 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
745 if (rdm
& BSTAT_RDM2
) {
746 ch
= sel_bch_isar(isar
, 2);
747 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
748 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
757 const char *dmril
[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
758 "300", "600", "1200", "2400", "4800", "7200",
759 "9600nt", "9600t", "12000", "14400", "WRONG"};
760 const char *dmrim
[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
761 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
764 isar_pump_status_rsp(struct isar_ch
*ch
) {
765 u8 ril
= ch
->is
->buf
[0];
768 if (!test_and_clear_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
))
771 pr_info("%s: wrong pstrsp ril=%d\n", ch
->is
->name
, ril
);
774 switch (ch
->is
->buf
[1]) {
809 sprintf(ch
->conmsg
, "%s %s", dmril
[ril
], dmrim
[rim
]);
810 pr_debug("%s: pump strsp %s\n", ch
->is
->name
, ch
->conmsg
);
814 isar_pump_statev_modem(struct isar_ch
*ch
, u8 devt
) {
815 u8 dps
= SET_DPS(ch
->dpath
);
818 case PSEV_10MS_TIMER
:
819 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
822 pr_debug("%s: pump stev CONNECT\n", ch
->is
->name
);
823 deliver_status(ch
, HW_MOD_CONNECT
);
826 pr_debug("%s: pump stev NO CONNECT\n", ch
->is
->name
);
827 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
828 deliver_status(ch
, HW_MOD_NOCARR
);
831 pr_debug("%s: pump stev V24 OFF\n", ch
->is
->name
);
834 pr_debug("%s: pump stev CTS ON\n", ch
->is
->name
);
837 pr_debug("%s pump stev CTS OFF\n", ch
->is
->name
);
840 pr_debug("%s: pump stev CARRIER ON\n", ch
->is
->name
);
841 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
842 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
845 pr_debug("%s: pump stev CARRIER OFF\n", ch
->is
->name
);
848 pr_debug("%s: pump stev DSR ON\n", ch
->is
->name
);
851 pr_debug("%s: pump stev DSR_OFF\n", ch
->is
->name
);
854 pr_debug("%s: pump stev REMOTE RETRAIN\n", ch
->is
->name
);
857 pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch
->is
->name
);
860 pr_debug("%s: pump stev GSTN CLEAR\n", ch
->is
->name
);
863 pr_info("u%s: nknown pump stev %x\n", ch
->is
->name
, devt
);
869 isar_pump_statev_fax(struct isar_ch
*ch
, u8 devt
) {
870 u8 dps
= SET_DPS(ch
->dpath
);
874 case PSEV_10MS_TIMER
:
875 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
878 pr_debug("%s: pump stev RSP_READY\n", ch
->is
->name
);
879 ch
->state
= STFAX_READY
;
880 deliver_status(ch
, HW_MOD_READY
);
882 if (test_bit(BC_FLG_ORIG
, &ch
->bch
.Flags
))
883 isar_pump_cmd(bch
, HW_MOD_FRH
, 3);
885 isar_pump_cmd(bch
, HW_MOD_FTH
, 3);
889 if (ch
->state
== STFAX_LINE
) {
890 pr_debug("%s: pump stev LINE_TX_H\n", ch
->is
->name
);
891 ch
->state
= STFAX_CONT
;
892 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
893 PCTRL_CMD_CONT
, 0, NULL
);
895 pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
896 ch
->is
->name
, ch
->state
);
900 if (ch
->state
== STFAX_LINE
) {
901 pr_debug("%s: pump stev LINE_RX_H\n", ch
->is
->name
);
902 ch
->state
= STFAX_CONT
;
903 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
904 PCTRL_CMD_CONT
, 0, NULL
);
906 pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",
907 ch
->is
->name
, ch
->state
);
911 if (ch
->state
== STFAX_LINE
) {
912 pr_debug("%s: pump stev LINE_TX_B\n", ch
->is
->name
);
913 ch
->state
= STFAX_CONT
;
914 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
915 PCTRL_CMD_CONT
, 0, NULL
);
917 pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",
918 ch
->is
->name
, ch
->state
);
922 if (ch
->state
== STFAX_LINE
) {
923 pr_debug("%s: pump stev LINE_RX_B\n", ch
->is
->name
);
924 ch
->state
= STFAX_CONT
;
925 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
926 PCTRL_CMD_CONT
, 0, NULL
);
928 pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",
929 ch
->is
->name
, ch
->state
);
933 if (ch
->state
== STFAX_CONT
) {
934 pr_debug("%s: pump stev RSP_CONN\n", ch
->is
->name
);
935 ch
->state
= STFAX_ACTIV
;
936 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
937 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
938 if (ch
->cmd
== PCTRL_CMD_FTH
) {
939 int delay
= (ch
->mod
== 3) ? 1000 : 200;
940 /* 1s (200 ms) Flags before data */
941 if (test_and_set_bit(FLG_FTI_RUN
,
943 del_timer(&ch
->ftimer
);
945 jiffies
+ ((delay
* HZ
)/1000);
946 test_and_set_bit(FLG_LL_CONN
,
948 add_timer(&ch
->ftimer
);
950 deliver_status(ch
, HW_MOD_CONNECT
);
953 pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
954 ch
->is
->name
, ch
->state
);
958 pr_debug("%s: pump stev FLAGS_DET\n", ch
->is
->name
);
961 pr_debug("%s: pump stev RSP_DISC state(%d)\n",
962 ch
->is
->name
, ch
->state
);
963 if (ch
->state
== STFAX_ESCAPE
) {
965 switch (ch
->newcmd
) {
967 ch
->state
= STFAX_READY
;
972 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
973 PCTRL_CMD_SILON
, 1, &p1
);
974 ch
->state
= STFAX_SILDET
;
978 ch
->mod
= ch
->newmod
;
981 ch
->cmd
= ch
->newcmd
;
983 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
985 ch
->state
= STFAX_LINE
;
989 pr_debug("%s: RSP_DISC unknown newcmd %x\n",
990 ch
->is
->name
, ch
->newcmd
);
993 } else if (ch
->state
== STFAX_ACTIV
) {
994 if (test_and_clear_bit(FLG_LL_OK
, &ch
->bch
.Flags
))
995 deliver_status(ch
, HW_MOD_OK
);
996 else if (ch
->cmd
== PCTRL_CMD_FRM
)
997 deliver_status(ch
, HW_MOD_NOCARR
);
999 deliver_status(ch
, HW_MOD_FCERROR
);
1000 ch
->state
= STFAX_READY
;
1001 } else if (ch
->state
!= STFAX_SILDET
) {
1002 /* ignore in STFAX_SILDET */
1003 ch
->state
= STFAX_READY
;
1004 deliver_status(ch
, HW_MOD_FCERROR
);
1007 case PSEV_RSP_SILDET
:
1008 pr_debug("%s: pump stev RSP_SILDET\n", ch
->is
->name
);
1009 if (ch
->state
== STFAX_SILDET
) {
1010 ch
->mod
= ch
->newmod
;
1013 ch
->cmd
= ch
->newcmd
;
1015 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1017 ch
->state
= STFAX_LINE
;
1021 case PSEV_RSP_SILOFF
:
1022 pr_debug("%s: pump stev RSP_SILOFF\n", ch
->is
->name
);
1024 case PSEV_RSP_FCERR
:
1025 if (ch
->state
== STFAX_LINE
) {
1026 pr_debug("%s: pump stev RSP_FCERR try %d\n",
1027 ch
->is
->name
, ch
->try_mod
);
1028 if (ch
->try_mod
--) {
1029 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1030 ch
->cmd
, 1, &ch
->mod
);
1034 pr_debug("%s: pump stev RSP_FCERR\n", ch
->is
->name
);
1035 ch
->state
= STFAX_ESCAPE
;
1036 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
1038 deliver_status(ch
, HW_MOD_FCERROR
);
1046 mISDNisar_irq(struct isar_hw
*isar
)
1050 get_irq_infos(isar
);
1051 switch (isar
->iis
& ISAR_IIS_MSCMSD
) {
1052 case ISAR_IIS_RDATA
:
1053 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1057 pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
1058 isar
->name
, isar
->iis
, isar
->cmsb
,
1060 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1063 case ISAR_IIS_GSTEV
:
1064 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1065 isar
->bstat
|= isar
->cmsb
;
1066 check_send(isar
, isar
->cmsb
);
1068 case ISAR_IIS_BSTEV
:
1069 #ifdef ERROR_STATISTIC
1070 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1072 if (isar
->cmsb
== BSTEV_TBO
)
1074 if (isar
->cmsb
== BSTEV_RBO
)
1078 pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
1079 isar
->name
, isar
->iis
>>6, isar
->cmsb
);
1080 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1082 case ISAR_IIS_PSTEV
:
1083 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1085 rcv_mbox(isar
, NULL
);
1086 if (ch
->bch
.state
== ISDN_P_B_MODEM_ASYNC
)
1087 isar_pump_statev_modem(ch
, isar
->cmsb
);
1088 else if (ch
->bch
.state
== ISDN_P_B_T30_FAX
)
1089 isar_pump_statev_fax(ch
, isar
->cmsb
);
1090 else if (ch
->bch
.state
== ISDN_P_B_RAW
) {
1092 tt
= isar
->cmsb
| 0x30;
1095 else if (tt
== 0x3f)
1099 tt
|= DTMF_TONE_VAL
;
1100 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
,
1101 MISDN_ID_ANY
, sizeof(tt
), &tt
,
1104 pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
1105 isar
->name
, ch
->bch
.state
,
1108 pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
1109 isar
->name
, isar
->iis
, isar
->cmsb
,
1111 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1114 case ISAR_IIS_PSTRSP
:
1115 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1117 rcv_mbox(isar
, NULL
);
1118 isar_pump_status_rsp(ch
);
1120 pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
1121 isar
->name
, isar
->iis
, isar
->cmsb
,
1123 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1127 case ISAR_IIS_BSTRSP
:
1128 case ISAR_IIS_IOM2RSP
:
1129 rcv_mbox(isar
, NULL
);
1131 case ISAR_IIS_INVMSG
:
1132 rcv_mbox(isar
, NULL
);
1133 pr_debug("%s: invalid msg his:%x\n", isar
->name
, isar
->cmsb
);
1136 rcv_mbox(isar
, NULL
);
1137 pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
1138 isar
->name
, isar
->iis
, isar
->cmsb
, isar
->clsb
);
1142 EXPORT_SYMBOL(mISDNisar_irq
);
1145 ftimer_handler(unsigned long data
)
1147 struct isar_ch
*ch
= (struct isar_ch
*)data
;
1149 pr_debug("%s: ftimer flags %lx\n", ch
->is
->name
, ch
->bch
.Flags
);
1150 test_and_clear_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1151 if (test_and_clear_bit(FLG_LL_CONN
, &ch
->bch
.Flags
))
1152 deliver_status(ch
, HW_MOD_CONNECT
);
1156 setup_pump(struct isar_ch
*ch
) {
1157 u8 dps
= SET_DPS(ch
->dpath
);
1160 switch (ch
->bch
.state
) {
1164 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, PMOD_BYPASS
, 0, NULL
);
1166 case ISDN_P_B_L2DTMF
:
1167 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
)) {
1168 param
[0] = 5; /* TOA 5 db */
1169 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1170 PMOD_DTMF_TRANS
, 1, param
);
1172 param
[0] = 40; /* REL -46 dbm */
1173 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1174 PMOD_DTMF
, 1, param
);
1176 case ISDN_P_B_MODEM_ASYNC
:
1177 ctrl
= PMOD_DATAMODEM
;
1178 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1180 param
[5] = PV32P6_CTN
;
1182 param
[5] = PV32P6_ATN
;
1184 param
[0] = 6; /* 6 db */
1185 param
[1] = PV32P2_V23R
| PV32P2_V22A
| PV32P2_V22B
|
1186 PV32P2_V22C
| PV32P2_V21
| PV32P2_BEL
;
1187 param
[2] = PV32P3_AMOD
| PV32P3_V32B
| PV32P3_V23B
;
1188 param
[3] = PV32P4_UT144
;
1189 param
[4] = PV32P5_UT144
;
1190 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 6, param
);
1192 case ISDN_P_B_T30_FAX
:
1194 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1196 param
[1] = PFAXP2_CTN
;
1198 param
[1] = PFAXP2_ATN
;
1200 param
[0] = 6; /* 6 db */
1201 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 2, param
);
1202 ch
->state
= STFAX_NULL
;
1205 test_and_set_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1209 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
1214 setup_sart(struct isar_ch
*ch
) {
1215 u8 dps
= SET_DPS(ch
->dpath
);
1216 u8 ctrl
, param
[2] = {0, 0};
1218 switch (ch
->bch
.state
) {
1220 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_DISABLE
,
1224 case ISDN_P_B_L2DTMF
:
1225 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_BINARY
,
1229 case ISDN_P_B_T30_FAX
:
1230 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_HDLC
,
1233 case ISDN_P_B_MODEM_ASYNC
:
1234 ctrl
= SMODE_V14
| SCTRL_HDMC_BOTH
;
1235 param
[0] = S_P1_CHS_8
;
1236 param
[1] = S_P2_BFT_DEF
;
1237 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, ctrl
, 2, param
);
1241 send_mbox(ch
->is
, dps
| ISAR_HIS_BSTREQ
, 0, 0, NULL
);
1246 setup_iom2(struct isar_ch
*ch
) {
1247 u8 dps
= SET_DPS(ch
->dpath
);
1248 u8 cmsb
= IOM_CTRL_ENA
, msg
[5] = {IOM_P1_TXD
, 0, 0, 0, 0};
1250 if (ch
->bch
.nr
== 2) {
1254 switch (ch
->bch
.state
) {
1258 msg
[1] = ch
->dpath
+ 2;
1259 msg
[3] = ch
->dpath
+ 2;
1264 case ISDN_P_B_MODEM_ASYNC
:
1265 case ISDN_P_B_T30_FAX
:
1266 cmsb
|= IOM_CTRL_RCV
;
1267 case ISDN_P_B_L2DTMF
:
1268 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
))
1269 cmsb
|= IOM_CTRL_RCV
;
1270 cmsb
|= IOM_CTRL_ALAW
;
1273 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2CFG
, cmsb
, 5, msg
);
1275 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2REQ
, 0, 0, NULL
);
1280 modeisar(struct isar_ch
*ch
, u32 bprotocol
)
1282 /* Here we are selecting the best datapath for requested protocol */
1283 if (ch
->bch
.state
== ISDN_P_NONE
) { /* New Setup */
1284 switch (bprotocol
) {
1285 case ISDN_P_NONE
: /* init */
1287 /* no init for dpath 0 */
1289 test_and_clear_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1290 test_and_clear_bit(FLG_TRANSPARENT
, &ch
->bch
.Flags
);
1294 /* best is datapath 2 */
1295 if (!test_and_set_bit(ISAR_DP2_USE
, &ch
->is
->Flags
))
1297 else if (!test_and_set_bit(ISAR_DP1_USE
,
1301 pr_info("modeisar both pathes in use\n");
1304 if (bprotocol
== ISDN_P_B_HDLC
)
1305 test_and_set_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1307 test_and_set_bit(FLG_TRANSPARENT
,
1310 case ISDN_P_B_MODEM_ASYNC
:
1311 case ISDN_P_B_T30_FAX
:
1312 case ISDN_P_B_L2DTMF
:
1313 /* only datapath 1 */
1314 if (!test_and_set_bit(ISAR_DP1_USE
, &ch
->is
->Flags
))
1317 pr_info("%s: ISAR modeisar analog functions"
1318 "only with DP1\n", ch
->is
->name
);
1323 pr_info("%s: protocol not known %x\n", ch
->is
->name
,
1325 return -ENOPROTOOPT
;
1328 pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch
->is
->name
,
1329 ch
->bch
.nr
, ch
->dpath
, ch
->bch
.state
, bprotocol
);
1330 ch
->bch
.state
= bprotocol
;
1334 if (ch
->bch
.state
== ISDN_P_NONE
) {
1335 /* Clear resources */
1337 test_and_clear_bit(ISAR_DP1_USE
, &ch
->is
->Flags
);
1338 else if (ch
->dpath
== 2)
1339 test_and_clear_bit(ISAR_DP2_USE
, &ch
->is
->Flags
);
1341 ch
->is
->ctrl(ch
->is
->hw
, HW_DEACT_IND
, ch
->bch
.nr
);
1343 ch
->is
->ctrl(ch
->is
->hw
, HW_ACTIVATE_IND
, ch
->bch
.nr
);
1348 isar_pump_cmd(struct isar_ch
*ch
, u32 cmd
, u8 para
)
1350 u8 dps
= SET_DPS(ch
->dpath
);
1351 u8 ctrl
= 0, nom
= 0, p1
= 0;
1353 pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
1354 ch
->is
->name
, cmd
, para
, ch
->bch
.state
);
1357 if (ch
->state
== STFAX_READY
) {
1359 ctrl
= PCTRL_CMD_FTM
;
1361 ch
->state
= STFAX_LINE
;
1367 } else if ((ch
->state
== STFAX_ACTIV
) &&
1368 (ch
->cmd
== PCTRL_CMD_FTM
) && (ch
->mod
== para
))
1369 deliver_status(ch
, HW_MOD_CONNECT
);
1372 ch
->newcmd
= PCTRL_CMD_FTM
;
1374 ctrl
= PCTRL_CMD_ESC
;
1375 ch
->state
= STFAX_ESCAPE
;
1379 if (ch
->state
== STFAX_READY
) {
1381 ctrl
= PCTRL_CMD_FTH
;
1383 ch
->state
= STFAX_LINE
;
1389 } else if ((ch
->state
== STFAX_ACTIV
) &&
1390 (ch
->cmd
== PCTRL_CMD_FTH
) && (ch
->mod
== para
))
1391 deliver_status(ch
, HW_MOD_CONNECT
);
1394 ch
->newcmd
= PCTRL_CMD_FTH
;
1396 ctrl
= PCTRL_CMD_ESC
;
1397 ch
->state
= STFAX_ESCAPE
;
1401 if (ch
->state
== STFAX_READY
) {
1403 ctrl
= PCTRL_CMD_FRM
;
1405 ch
->state
= STFAX_LINE
;
1411 } else if ((ch
->state
== STFAX_ACTIV
) &&
1412 (ch
->cmd
== PCTRL_CMD_FRM
) && (ch
->mod
== para
))
1413 deliver_status(ch
, HW_MOD_CONNECT
);
1416 ch
->newcmd
= PCTRL_CMD_FRM
;
1418 ctrl
= PCTRL_CMD_ESC
;
1419 ch
->state
= STFAX_ESCAPE
;
1423 if (ch
->state
== STFAX_READY
) {
1425 ctrl
= PCTRL_CMD_FRH
;
1427 ch
->state
= STFAX_LINE
;
1433 } else if ((ch
->state
== STFAX_ACTIV
) &&
1434 (ch
->cmd
== PCTRL_CMD_FRH
) && (ch
->mod
== para
))
1435 deliver_status(ch
, HW_MOD_CONNECT
);
1438 ch
->newcmd
= PCTRL_CMD_FRH
;
1440 ctrl
= PCTRL_CMD_ESC
;
1441 ch
->state
= STFAX_ESCAPE
;
1444 case PCTRL_CMD_TDTMF
:
1447 ctrl
= PCTRL_CMD_TDTMF
;
1451 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, ctrl
, nom
, &p1
);
1455 isar_setup(struct isar_hw
*isar
)
1462 for (i
= 0; i
< 2; i
++) {
1464 send_mbox(isar
, (i
? ISAR_HIS_DPS2
: ISAR_HIS_DPS1
) |
1465 ISAR_HIS_P12CFG
, 4, 1, &msg
);
1466 isar
->ch
[i
].mml
= msg
;
1467 isar
->ch
[i
].bch
.state
= 0;
1468 isar
->ch
[i
].dpath
= i
+ 1;
1469 modeisar(&isar
->ch
[i
], ISDN_P_NONE
);
1474 isar_l2l1(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1476 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1477 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1479 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1485 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1486 ret
= bchannel_senddata(bch
, skb
);
1487 if (ret
> 0) { /* direct TX */
1488 id
= hh
->id
; /* skb can be freed */
1490 isar_fill_fifo(ich
);
1491 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1492 if (!test_bit(FLG_TRANSPARENT
, &bch
->Flags
))
1493 queue_ch_frame(ch
, PH_DATA_CNF
, id
, NULL
);
1495 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1497 case PH_ACTIVATE_REQ
:
1498 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1499 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
))
1500 ret
= modeisar(ich
, ch
->protocol
);
1503 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1505 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
1508 case PH_DEACTIVATE_REQ
:
1509 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1510 mISDN_clear_bchannel(bch
);
1511 modeisar(ich
, ISDN_P_NONE
);
1512 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1513 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
, 0,
1517 case PH_CONTROL_REQ
:
1518 val
= (u32
*)skb
->data
;
1519 pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich
->is
->name
,
1521 if ((hh
->id
== 0) && ((*val
& ~DTMF_TONE_MASK
) ==
1523 if (bch
->state
== ISDN_P_B_L2DTMF
) {
1524 char tt
= *val
& DTMF_TONE_MASK
;
1533 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1534 isar_pump_cmd(ich
, PCTRL_CMD_TDTMF
, tt
);
1535 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1537 pr_info("%s: DTMF send wrong protocol %x\n",
1538 __func__
, bch
->state
);
1541 } else if ((hh
->id
== HW_MOD_FRM
) || (hh
->id
== HW_MOD_FRH
) ||
1542 (hh
->id
== HW_MOD_FTM
) || (hh
->id
== HW_MOD_FTH
)) {
1543 for (id
= 0; id
< FAXMODCNT
; id
++)
1544 if (faxmodulation
[id
] == *val
)
1546 if ((FAXMODCNT
> id
) &&
1547 test_bit(FLG_INITIALIZED
, &bch
->Flags
)) {
1548 pr_debug("%s: isar: new mod\n", ich
->is
->name
);
1549 isar_pump_cmd(ich
, hh
->id
, *val
);
1552 pr_info("%s: wrong modulation\n",
1556 } else if (hh
->id
== HW_MOD_LASTDATA
)
1557 test_and_set_bit(FLG_DLEETX
, &bch
->Flags
);
1559 pr_info("%s: unknown PH_CONTROL_REQ %x\n",
1560 ich
->is
->name
, hh
->id
);
1564 pr_info("%s: %s unknown prim(%x,%x)\n",
1565 ich
->is
->name
, __func__
, hh
->prim
, hh
->id
);
1574 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
1579 case MISDN_CTRL_GETOP
:
1582 /* Nothing implemented yet */
1583 case MISDN_CTRL_FILL_EMPTY
:
1585 pr_info("%s: unknown Op %x\n", __func__
, cq
->op
);
1593 isar_bctrl(struct mISDNchannel
*ch
, u32 cmd
, void *arg
)
1595 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1596 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1600 pr_debug("%s: %s cmd:%x %p\n", ich
->is
->name
, __func__
, cmd
, arg
);
1603 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1604 if (test_bit(FLG_ACTIVE
, &bch
->Flags
)) {
1605 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1606 mISDN_freebchannel(bch
);
1607 modeisar(ich
, ISDN_P_NONE
);
1608 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1610 skb_queue_purge(&bch
->rqueue
);
1613 ch
->protocol
= ISDN_P_NONE
;
1615 module_put(ich
->is
->owner
);
1618 case CONTROL_CHANNEL
:
1619 ret
= channel_bctrl(bch
, arg
);
1622 pr_info("%s: %s unknown prim(%x)\n",
1623 ich
->is
->name
, __func__
, cmd
);
1629 free_isar(struct isar_hw
*isar
)
1631 modeisar(&isar
->ch
[0], ISDN_P_NONE
);
1632 modeisar(&isar
->ch
[1], ISDN_P_NONE
);
1633 del_timer(&isar
->ch
[0].ftimer
);
1634 del_timer(&isar
->ch
[1].ftimer
);
1635 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1636 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1640 init_isar(struct isar_hw
*isar
)
1645 isar
->version
= ISARVersion(isar
);
1646 if (isar
->ch
[0].bch
.debug
& DEBUG_HW
)
1647 pr_notice("%s: Testing version %d (%d time)\n",
1648 isar
->name
, isar
->version
, 3 - cnt
);
1649 if (isar
->version
== 1)
1651 isar
->ctrl(isar
->hw
, HW_RESET_REQ
, 0);
1653 if (isar
->version
!= 1)
1655 isar
->ch
[0].ftimer
.function
= &ftimer_handler
;
1656 isar
->ch
[0].ftimer
.data
= (long)&isar
->ch
[0];
1657 init_timer(&isar
->ch
[0].ftimer
);
1658 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1659 isar
->ch
[1].ftimer
.function
= &ftimer_handler
;
1660 isar
->ch
[1].ftimer
.data
= (long)&isar
->ch
[1];
1661 init_timer(&isar
->ch
[1].ftimer
);
1662 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1667 isar_open(struct isar_hw
*isar
, struct channel_req
*rq
)
1669 struct bchannel
*bch
;
1671 if (rq
->adr
.channel
> 2)
1673 if (rq
->protocol
== ISDN_P_NONE
)
1675 bch
= &isar
->ch
[rq
->adr
.channel
- 1].bch
;
1676 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
1677 return -EBUSY
; /* b-channel can be only open once */
1678 test_and_clear_bit(FLG_FILLEMPTY
, &bch
->Flags
);
1679 bch
->ch
.protocol
= rq
->protocol
;
1685 mISDNisar_init(struct isar_hw
*isar
, void *hw
)
1690 for (i
= 0; i
< 2; i
++) {
1691 isar
->ch
[i
].bch
.nr
= i
+ 1;
1692 mISDN_initbchannel(&isar
->ch
[i
].bch
, MAX_DATA_MEM
);
1693 isar
->ch
[i
].bch
.ch
.nr
= i
+ 1;
1694 isar
->ch
[i
].bch
.ch
.send
= &isar_l2l1
;
1695 isar
->ch
[i
].bch
.ch
.ctrl
= isar_bctrl
;
1696 isar
->ch
[i
].bch
.hw
= hw
;
1697 isar
->ch
[i
].is
= isar
;
1700 isar
->init
= &init_isar
;
1701 isar
->release
= &free_isar
;
1702 isar
->firmware
= &load_firmware
;
1703 isar
->open
= &isar_open
;
1705 ret
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1706 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
)) |
1707 (1 << (ISDN_P_B_L2DTMF
& ISDN_P_B_MASK
)) |
1708 (1 << (ISDN_P_B_MODEM_ASYNC
& ISDN_P_B_MASK
)) |
1709 (1 << (ISDN_P_B_T30_FAX
& ISDN_P_B_MASK
));
1713 EXPORT_SYMBOL(mISDNisar_init
);
1715 static int isar_mod_init(void)
1717 pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV
);
1721 static void isar_mod_cleanup(void)
1723 pr_notice("mISDN: ISAR module unloaded\n");
1725 module_init(isar_mod_init
);
1726 module_exit(isar_mod_cleanup
);