1 // SPDX-License-Identifier: GPL-2.0-only
3 * mISDNisar.c ISAR (Siemens PSB 7110) specific functions
5 * Author Karsten Keil (keil@isdn4linux.de)
7 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
10 /* define this to enable static debug messages, if you kernel supports
11 * dynamic debugging, you should use debugfs for this
15 #include <linux/gfp.h>
16 #include <linux/delay.h>
17 #include <linux/vmalloc.h>
18 #include <linux/mISDNhw.h>
19 #include <linux/module.h>
22 #define ISAR_REV "2.1"
24 MODULE_AUTHOR("Karsten Keil");
25 MODULE_DESCRIPTION("mISDN driver for ISAR (Siemens PSB 7110) specific functions");
26 MODULE_LICENSE("GPL v2");
27 MODULE_VERSION(ISAR_REV
);
29 #define DEBUG_HW_FIRMWARE_FIFO 0x10000
31 static const u8 faxmodulation
[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
35 static void isar_setup(struct isar_hw
*);
38 waitforHIA(struct isar_hw
*isar
, int timeout
)
41 u8 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
43 while ((val
& 1) && t
) {
46 val
= isar
->read_reg(isar
->hw
, ISAR_HIA
);
48 pr_debug("%s: HIA after %dus\n", isar
->name
, timeout
- t
);
53 * send msg to ISAR mailbox
54 * if msg is NULL use isar->buf
57 send_mbox(struct isar_hw
*isar
, u8 his
, u8 creg
, u8 len
, u8
*msg
)
59 if (!waitforHIA(isar
, 1000))
61 pr_debug("send_mbox(%02x,%02x,%d)\n", his
, creg
, len
);
62 isar
->write_reg(isar
->hw
, ISAR_CTRL_H
, creg
);
63 isar
->write_reg(isar
->hw
, ISAR_CTRL_L
, len
);
64 isar
->write_reg(isar
->hw
, ISAR_WADR
, 0);
68 isar
->write_fifo(isar
->hw
, ISAR_MBOX
, msg
, len
);
69 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
72 while (l
< (int)len
) {
73 hex_dump_to_buffer(msg
+ l
, len
- l
, 32, 1,
75 pr_debug("%s: %s %02x: %s\n", isar
->name
,
76 __func__
, l
, isar
->log
);
81 isar
->write_reg(isar
->hw
, ISAR_HIS
, his
);
82 waitforHIA(isar
, 1000);
87 * receive message from ISAR mailbox
88 * if msg is NULL use isar->buf
91 rcv_mbox(struct isar_hw
*isar
, u8
*msg
)
95 isar
->write_reg(isar
->hw
, ISAR_RADR
, 0);
96 if (msg
&& isar
->clsb
) {
97 isar
->read_fifo(isar
->hw
, ISAR_MBOX
, msg
, isar
->clsb
);
98 if (isar
->ch
[0].bch
.debug
& DEBUG_HW_BFIFO
) {
101 while (l
< (int)isar
->clsb
) {
102 hex_dump_to_buffer(msg
+ l
, isar
->clsb
- l
, 32,
103 1, isar
->log
, 256, 1);
104 pr_debug("%s: %s %02x: %s\n", isar
->name
,
105 __func__
, l
, isar
->log
);
110 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
114 get_irq_infos(struct isar_hw
*isar
)
116 isar
->iis
= isar
->read_reg(isar
->hw
, ISAR_IIS
);
117 isar
->cmsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_H
);
118 isar
->clsb
= isar
->read_reg(isar
->hw
, ISAR_CTRL_L
);
119 pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar
->name
,
120 isar
->iis
, isar
->cmsb
, isar
->clsb
);
124 * poll answer message from ISAR mailbox
125 * should be used only with ISAR IRQs disabled before DSP was started
129 poll_mbox(struct isar_hw
*isar
, int maxdelay
)
134 irq
= isar
->read_reg(isar
->hw
, ISAR_IRQBIT
);
135 while (t
&& !(irq
& ISAR_IRQSTA
)) {
141 rcv_mbox(isar
, NULL
);
143 pr_debug("%s: pulled %d bytes after %d us\n",
144 isar
->name
, isar
->clsb
, maxdelay
- t
);
149 ISARVersion(struct isar_hw
*isar
)
153 /* disable ISAR IRQ */
154 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
155 isar
->buf
[0] = ISAR_MSG_HWVER
;
158 if (!send_mbox(isar
, ISAR_HIS_VNR
, 0, 3, NULL
))
160 if (!poll_mbox(isar
, 1000))
162 if (isar
->iis
== ISAR_IIS_VNR
) {
163 if (isar
->clsb
== 1) {
164 ver
= isar
->buf
[0] & 0xf;
173 load_firmware(struct isar_hw
*isar
, const u8
*buf
, int size
)
175 u32 saved_debug
= isar
->ch
[0].bch
.debug
;
178 u16 left
, val
, *sp
= (u16
*)buf
;
188 if (1 != isar
->version
) {
189 pr_err("%s: ISAR wrong version %d firmware download aborted\n",
190 isar
->name
, isar
->version
);
193 if (!(saved_debug
& DEBUG_HW_FIRMWARE_FIFO
))
194 isar
->ch
[0].bch
.debug
&= ~DEBUG_HW_BFIFO
;
195 pr_debug("%s: load firmware %d words (%d bytes)\n",
196 isar
->name
, size
/ 2, size
);
199 /* disable ISAR IRQ */
200 spin_lock_irqsave(isar
->hwlock
, flags
);
201 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
202 spin_unlock_irqrestore(isar
->hwlock
, flags
);
204 blk_head
.sadr
= le16_to_cpu(*sp
++);
205 blk_head
.len
= le16_to_cpu(*sp
++);
206 blk_head
.d_key
= le16_to_cpu(*sp
++);
208 pr_debug("ISAR firmware block (%#x,%d,%#x)\n",
209 blk_head
.sadr
, blk_head
.len
, blk_head
.d_key
& 0xff);
211 if (cnt
+ left
> size
) {
212 pr_info("%s: firmware error have %d need %d words\n",
213 isar
->name
, size
, cnt
+ left
);
217 spin_lock_irqsave(isar
->hwlock
, flags
);
218 if (!send_mbox(isar
, ISAR_HIS_DKEY
, blk_head
.d_key
& 0xff,
220 pr_info("ISAR send_mbox dkey failed\n");
224 if (!poll_mbox(isar
, 1000)) {
225 pr_warn("ISAR poll_mbox dkey failed\n");
229 spin_unlock_irqrestore(isar
->hwlock
, flags
);
230 if ((isar
->iis
!= ISAR_IIS_DKEY
) || isar
->cmsb
|| isar
->clsb
) {
231 pr_info("ISAR wrong dkey response (%x,%x,%x)\n",
232 isar
->iis
, isar
->cmsb
, isar
->clsb
);
243 /* the ISAR is big endian */
244 *mp
++ = blk_head
.sadr
>> 8;
245 *mp
++ = blk_head
.sadr
& 0xFF;
249 pr_debug("%s: load %3d words at %04x\n", isar
->name
,
251 blk_head
.sadr
+= noc
;
253 val
= le16_to_cpu(*sp
++);
258 spin_lock_irqsave(isar
->hwlock
, flags
);
259 if (!send_mbox(isar
, ISAR_HIS_FIRM
, 0, nom
, NULL
)) {
260 pr_info("ISAR send_mbox prog failed\n");
264 if (!poll_mbox(isar
, 1000)) {
265 pr_info("ISAR poll_mbox prog failed\n");
269 spin_unlock_irqrestore(isar
->hwlock
, flags
);
270 if ((isar
->iis
!= ISAR_IIS_FIRM
) ||
271 isar
->cmsb
|| isar
->clsb
) {
272 pr_info("ISAR wrong prog response (%x,%x,%x)\n",
273 isar
->iis
, isar
->cmsb
, isar
->clsb
);
278 pr_debug("%s: ISAR firmware block %d words loaded\n",
279 isar
->name
, blk_head
.len
);
281 isar
->ch
[0].bch
.debug
= saved_debug
;
289 spin_lock_irqsave(isar
->hwlock
, flags
);
290 if (!send_mbox(isar
, ISAR_HIS_STDSP
, 0, 2, NULL
)) {
291 pr_info("ISAR send_mbox start dsp failed\n");
295 if (!poll_mbox(isar
, 1000)) {
296 pr_info("ISAR poll_mbox start dsp failed\n");
300 if ((isar
->iis
!= ISAR_IIS_STDSP
) || isar
->cmsb
|| isar
->clsb
) {
301 pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",
302 isar
->iis
, isar
->cmsb
, isar
->clsb
);
306 pr_debug("%s: ISAR start dsp success\n", isar
->name
);
308 /* NORMAL mode entered */
309 /* Enable IRQs of ISAR */
310 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, ISAR_IRQSTA
);
311 spin_unlock_irqrestore(isar
->hwlock
, flags
);
312 cnt
= 1000; /* max 1s */
313 while ((!isar
->bstat
) && cnt
) {
318 pr_info("ISAR no general status event received\n");
322 pr_debug("%s: ISAR general status event %x\n",
323 isar
->name
, isar
->bstat
);
329 spin_lock_irqsave(isar
->hwlock
, flags
);
330 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_STST
, 0, NULL
)) {
331 pr_info("ISAR send_mbox self tst failed\n");
335 spin_unlock_irqrestore(isar
->hwlock
, flags
);
336 cnt
= 10000; /* max 100 ms */
337 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
343 pr_info("ISAR no self tst response\n");
347 if ((isar
->cmsb
== ISAR_CTRL_STST
) && (isar
->clsb
== 1)
348 && (isar
->buf
[0] == 0))
349 pr_debug("%s: ISAR selftest OK\n", isar
->name
);
351 pr_info("ISAR selftest not OK %x/%x/%x\n",
352 isar
->cmsb
, isar
->clsb
, isar
->buf
[0]);
356 spin_lock_irqsave(isar
->hwlock
, flags
);
358 if (!send_mbox(isar
, ISAR_HIS_DIAG
, ISAR_CTRL_SWVER
, 0, NULL
)) {
359 pr_info("ISAR RQST SVN failed\n");
363 spin_unlock_irqrestore(isar
->hwlock
, flags
);
364 cnt
= 30000; /* max 300 ms */
365 while ((isar
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
371 pr_info("ISAR no SVN response\n");
375 if ((isar
->cmsb
== ISAR_CTRL_SWVER
) && (isar
->clsb
== 1)) {
376 pr_notice("%s: ISAR software version %#x\n",
377 isar
->name
, isar
->buf
[0]);
379 pr_info("%s: ISAR wrong swver response (%x,%x)"
380 " cnt(%d)\n", isar
->name
, isar
->cmsb
,
386 spin_lock_irqsave(isar
->hwlock
, flags
);
388 spin_unlock_irqrestore(isar
->hwlock
, flags
);
391 spin_lock_irqsave(isar
->hwlock
, flags
);
393 isar
->ch
[0].bch
.debug
= saved_debug
;
395 /* disable ISAR IRQ */
396 isar
->write_reg(isar
->hw
, ISAR_IRQBIT
, 0);
397 spin_unlock_irqrestore(isar
->hwlock
, flags
);
402 deliver_status(struct isar_ch
*ch
, int status
)
404 pr_debug("%s: HL->LL FAXIND %x\n", ch
->is
->name
, status
);
405 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
, status
, 0, NULL
, GFP_ATOMIC
);
409 isar_rcv_frame(struct isar_ch
*ch
)
415 pr_debug("%s; ISAR zero len frame\n", ch
->is
->name
);
416 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
419 if (test_bit(FLG_RX_OFF
, &ch
->bch
.Flags
)) {
420 ch
->bch
.dropcnt
+= ch
->is
->clsb
;
421 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
424 switch (ch
->bch
.state
) {
426 pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
427 ch
->is
->name
, ch
->is
->iis
, ch
->is
->cmsb
, ch
->is
->clsb
);
428 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
431 case ISDN_P_B_L2DTMF
:
432 case ISDN_P_B_MODEM_ASYNC
:
433 maxlen
= bchannel_get_rxbuf(&ch
->bch
, ch
->is
->clsb
);
435 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
436 ch
->is
->name
, ch
->bch
.nr
, ch
->is
->clsb
);
437 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
440 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
441 recv_Bchannel(&ch
->bch
, 0, false);
444 maxlen
= bchannel_get_rxbuf(&ch
->bch
, ch
->is
->clsb
);
446 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
447 ch
->is
->name
, ch
->bch
.nr
, ch
->is
->clsb
);
448 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
451 if (ch
->is
->cmsb
& HDLC_ERROR
) {
452 pr_debug("%s: ISAR frame error %x len %d\n",
453 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
454 #ifdef ERROR_STATISTIC
455 if (ch
->is
->cmsb
& HDLC_ERR_RER
)
457 if (ch
->is
->cmsb
& HDLC_ERR_CER
)
460 skb_trim(ch
->bch
.rx_skb
, 0);
461 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
464 if (ch
->is
->cmsb
& HDLC_FSD
)
465 skb_trim(ch
->bch
.rx_skb
, 0);
466 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
467 rcv_mbox(ch
->is
, ptr
);
468 if (ch
->is
->cmsb
& HDLC_FED
) {
469 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
470 pr_debug("%s: ISAR frame too short %d\n",
471 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
472 skb_trim(ch
->bch
.rx_skb
, 0);
475 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
476 recv_Bchannel(&ch
->bch
, 0, false);
479 case ISDN_P_B_T30_FAX
:
480 if (ch
->state
!= STFAX_ACTIV
) {
481 pr_debug("%s: isar_rcv_frame: not ACTIV\n",
483 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
485 skb_trim(ch
->bch
.rx_skb
, 0);
488 if (!ch
->bch
.rx_skb
) {
489 ch
->bch
.rx_skb
= mI_alloc_skb(ch
->bch
.maxlen
,
491 if (unlikely(!ch
->bch
.rx_skb
)) {
492 pr_info("%s: B receive out of memory\n",
494 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
498 if (ch
->cmd
== PCTRL_CMD_FRM
) {
499 rcv_mbox(ch
->is
, skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
));
500 pr_debug("%s: isar_rcv_frame: %d\n",
501 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
502 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
503 pr_debug("%s: isar_rcv_frame: no more data\n",
505 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
506 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
507 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
509 ch
->state
= STFAX_ESCAPE
;
510 /* set_skb_flag(skb, DF_NOMOREDATA); */
512 recv_Bchannel(&ch
->bch
, 0, false);
513 if (ch
->is
->cmsb
& SART_NMD
)
514 deliver_status(ch
, HW_MOD_NOCARR
);
517 if (ch
->cmd
!= PCTRL_CMD_FRH
) {
518 pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
519 ch
->is
->name
, ch
->cmd
);
520 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
522 skb_trim(ch
->bch
.rx_skb
, 0);
526 if ((ch
->bch
.rx_skb
->len
+ ch
->is
->clsb
) >
527 (ch
->bch
.maxlen
+ 2)) {
528 pr_info("%s: %s incoming packet too large\n",
529 ch
->is
->name
, __func__
);
530 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
531 skb_trim(ch
->bch
.rx_skb
, 0);
533 } else if (ch
->is
->cmsb
& HDLC_ERROR
) {
534 pr_info("%s: ISAR frame error %x len %d\n",
535 ch
->is
->name
, ch
->is
->cmsb
, ch
->is
->clsb
);
536 skb_trim(ch
->bch
.rx_skb
, 0);
537 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
540 if (ch
->is
->cmsb
& HDLC_FSD
)
541 skb_trim(ch
->bch
.rx_skb
, 0);
542 ptr
= skb_put(ch
->bch
.rx_skb
, ch
->is
->clsb
);
543 rcv_mbox(ch
->is
, ptr
);
544 if (ch
->is
->cmsb
& HDLC_FED
) {
545 if (ch
->bch
.rx_skb
->len
< 3) { /* last 2 are the FCS */
546 pr_info("%s: ISAR frame too short %d\n",
547 ch
->is
->name
, ch
->bch
.rx_skb
->len
);
548 skb_trim(ch
->bch
.rx_skb
, 0);
551 skb_trim(ch
->bch
.rx_skb
, ch
->bch
.rx_skb
->len
- 2);
552 recv_Bchannel(&ch
->bch
, 0, false);
554 if (ch
->is
->cmsb
& SART_NMD
) { /* ABORT */
555 pr_debug("%s: isar_rcv_frame: no more data\n",
557 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
559 skb_trim(ch
->bch
.rx_skb
, 0);
560 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
561 ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
, 0, NULL
);
562 ch
->state
= STFAX_ESCAPE
;
563 deliver_status(ch
, HW_MOD_NOCARR
);
567 pr_info("isar_rcv_frame protocol (%x)error\n", ch
->bch
.state
);
568 ch
->is
->write_reg(ch
->is
->hw
, ISAR_IIA
, 0);
574 isar_fill_fifo(struct isar_ch
*ch
)
580 pr_debug("%s: ch%d tx_skb %d tx_idx %d\n", ch
->is
->name
, ch
->bch
.nr
,
581 ch
->bch
.tx_skb
? ch
->bch
.tx_skb
->len
: -1, ch
->bch
.tx_idx
);
582 if (!(ch
->is
->bstat
&
583 (ch
->dpath
== 1 ? BSTAT_RDM1
: BSTAT_RDM2
)))
585 if (!ch
->bch
.tx_skb
) {
586 if (!test_bit(FLG_TX_EMPTY
, &ch
->bch
.Flags
) ||
587 (ch
->bch
.state
!= ISDN_P_B_RAW
))
590 /* use the card buffer */
591 memset(ch
->is
->buf
, ch
->bch
.fill
[0], count
);
592 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
593 0, count
, ch
->is
->buf
);
596 count
= ch
->bch
.tx_skb
->len
- ch
->bch
.tx_idx
;
599 if (count
> ch
->mml
) {
605 ptr
= ch
->bch
.tx_skb
->data
+ ch
->bch
.tx_idx
;
606 if (!ch
->bch
.tx_idx
) {
607 pr_debug("%s: frame start\n", ch
->is
->name
);
608 if ((ch
->bch
.state
== ISDN_P_B_T30_FAX
) &&
609 (ch
->cmd
== PCTRL_CMD_FTH
)) {
611 if ((ptr
[0] == 0xff) && (ptr
[1] == 0x13)) {
613 test_and_set_bit(FLG_LASTDATA
,
615 pr_debug("%s: set LASTDATA\n",
618 test_and_set_bit(FLG_DLEETX
,
625 ch
->bch
.tx_idx
+= count
;
626 switch (ch
->bch
.state
) {
628 pr_info("%s: wrong protocol 0\n", __func__
);
631 case ISDN_P_B_L2DTMF
:
632 case ISDN_P_B_MODEM_ASYNC
:
633 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
637 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
640 case ISDN_P_B_T30_FAX
:
641 if (ch
->state
!= STFAX_ACTIV
)
642 pr_debug("%s: not ACTIV\n", ch
->is
->name
);
643 else if (ch
->cmd
== PCTRL_CMD_FTH
)
644 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
646 else if (ch
->cmd
== PCTRL_CMD_FTM
)
647 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) | ISAR_HIS_SDATA
,
650 pr_debug("%s: not FTH/FTM\n", ch
->is
->name
);
653 pr_info("%s: protocol(%x) error\n",
654 __func__
, ch
->bch
.state
);
659 static inline struct isar_ch
*
660 sel_bch_isar(struct isar_hw
*isar
, u8 dpath
)
662 struct isar_ch
*base
= &isar
->ch
[0];
664 if ((!dpath
) || (dpath
> 2))
666 if (base
->dpath
== dpath
)
669 if (base
->dpath
== dpath
)
675 send_next(struct isar_ch
*ch
)
677 pr_debug("%s: %s ch%d tx_skb %d tx_idx %d\n", ch
->is
->name
, __func__
,
678 ch
->bch
.nr
, ch
->bch
.tx_skb
? ch
->bch
.tx_skb
->len
: -1,
680 if (ch
->bch
.state
== ISDN_P_B_T30_FAX
) {
681 if (ch
->cmd
== PCTRL_CMD_FTH
) {
682 if (test_bit(FLG_LASTDATA
, &ch
->bch
.Flags
)) {
683 pr_debug("set NMD_DATA\n");
684 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
686 } else if (ch
->cmd
== PCTRL_CMD_FTM
) {
687 if (test_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
688 test_and_set_bit(FLG_LASTDATA
, &ch
->bch
.Flags
);
689 test_and_set_bit(FLG_NMD_DATA
, &ch
->bch
.Flags
);
693 dev_kfree_skb(ch
->bch
.tx_skb
);
694 if (get_next_bframe(&ch
->bch
)) {
696 test_and_clear_bit(FLG_TX_EMPTY
, &ch
->bch
.Flags
);
697 } else if (test_bit(FLG_TX_EMPTY
, &ch
->bch
.Flags
)) {
700 if (test_and_clear_bit(FLG_DLEETX
, &ch
->bch
.Flags
)) {
701 if (test_and_clear_bit(FLG_LASTDATA
,
703 if (test_and_clear_bit(FLG_NMD_DATA
,
706 send_mbox(ch
->is
, SET_DPS(ch
->dpath
) |
707 ISAR_HIS_SDATA
, 0x01, 1, &zd
);
709 test_and_set_bit(FLG_LL_OK
, &ch
->bch
.Flags
);
711 deliver_status(ch
, HW_MOD_CONNECT
);
713 } else if (test_bit(FLG_FILLEMPTY
, &ch
->bch
.Flags
)) {
714 test_and_set_bit(FLG_TX_EMPTY
, &ch
->bch
.Flags
);
720 check_send(struct isar_hw
*isar
, u8 rdm
)
724 pr_debug("%s: rdm %x\n", isar
->name
, rdm
);
725 if (rdm
& BSTAT_RDM1
) {
726 ch
= sel_bch_isar(isar
, 1);
727 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
728 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
735 if (rdm
& BSTAT_RDM2
) {
736 ch
= sel_bch_isar(isar
, 2);
737 if (ch
&& test_bit(FLG_ACTIVE
, &ch
->bch
.Flags
)) {
738 if (ch
->bch
.tx_skb
&& (ch
->bch
.tx_skb
->len
>
747 static const char *dmril
[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
748 "300", "600", "1200", "2400", "4800", "7200",
749 "9600nt", "9600t", "12000", "14400", "WRONG"};
750 static const char *dmrim
[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
751 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
754 isar_pump_status_rsp(struct isar_ch
*ch
) {
755 u8 ril
= ch
->is
->buf
[0];
758 if (!test_and_clear_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
))
761 pr_info("%s: wrong pstrsp ril=%d\n", ch
->is
->name
, ril
);
764 switch (ch
->is
->buf
[1]) {
799 sprintf(ch
->conmsg
, "%s %s", dmril
[ril
], dmrim
[rim
]);
800 pr_debug("%s: pump strsp %s\n", ch
->is
->name
, ch
->conmsg
);
804 isar_pump_statev_modem(struct isar_ch
*ch
, u8 devt
) {
805 u8 dps
= SET_DPS(ch
->dpath
);
808 case PSEV_10MS_TIMER
:
809 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
812 pr_debug("%s: pump stev CONNECT\n", ch
->is
->name
);
813 deliver_status(ch
, HW_MOD_CONNECT
);
816 pr_debug("%s: pump stev NO CONNECT\n", ch
->is
->name
);
817 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
818 deliver_status(ch
, HW_MOD_NOCARR
);
821 pr_debug("%s: pump stev V24 OFF\n", ch
->is
->name
);
824 pr_debug("%s: pump stev CTS ON\n", ch
->is
->name
);
827 pr_debug("%s pump stev CTS OFF\n", ch
->is
->name
);
830 pr_debug("%s: pump stev CARRIER ON\n", ch
->is
->name
);
831 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
832 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
835 pr_debug("%s: pump stev CARRIER OFF\n", ch
->is
->name
);
838 pr_debug("%s: pump stev DSR ON\n", ch
->is
->name
);
841 pr_debug("%s: pump stev DSR_OFF\n", ch
->is
->name
);
844 pr_debug("%s: pump stev REMOTE RETRAIN\n", ch
->is
->name
);
847 pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch
->is
->name
);
850 pr_debug("%s: pump stev GSTN CLEAR\n", ch
->is
->name
);
853 pr_info("u%s: unknown pump stev %x\n", ch
->is
->name
, devt
);
859 isar_pump_statev_fax(struct isar_ch
*ch
, u8 devt
) {
860 u8 dps
= SET_DPS(ch
->dpath
);
864 case PSEV_10MS_TIMER
:
865 pr_debug("%s: pump stev TIMER\n", ch
->is
->name
);
868 pr_debug("%s: pump stev RSP_READY\n", ch
->is
->name
);
869 ch
->state
= STFAX_READY
;
870 deliver_status(ch
, HW_MOD_READY
);
872 if (test_bit(BC_FLG_ORIG
, &ch
->bch
.Flags
))
873 isar_pump_cmd(bch
, HW_MOD_FRH
, 3);
875 isar_pump_cmd(bch
, HW_MOD_FTH
, 3);
879 if (ch
->state
== STFAX_LINE
) {
880 pr_debug("%s: pump stev LINE_TX_H\n", ch
->is
->name
);
881 ch
->state
= STFAX_CONT
;
882 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
883 PCTRL_CMD_CONT
, 0, NULL
);
885 pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
886 ch
->is
->name
, ch
->state
);
890 if (ch
->state
== STFAX_LINE
) {
891 pr_debug("%s: pump stev LINE_RX_H\n", ch
->is
->name
);
892 ch
->state
= STFAX_CONT
;
893 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
894 PCTRL_CMD_CONT
, 0, NULL
);
896 pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",
897 ch
->is
->name
, ch
->state
);
901 if (ch
->state
== STFAX_LINE
) {
902 pr_debug("%s: pump stev LINE_TX_B\n", ch
->is
->name
);
903 ch
->state
= STFAX_CONT
;
904 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
905 PCTRL_CMD_CONT
, 0, NULL
);
907 pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",
908 ch
->is
->name
, ch
->state
);
912 if (ch
->state
== STFAX_LINE
) {
913 pr_debug("%s: pump stev LINE_RX_B\n", ch
->is
->name
);
914 ch
->state
= STFAX_CONT
;
915 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
916 PCTRL_CMD_CONT
, 0, NULL
);
918 pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",
919 ch
->is
->name
, ch
->state
);
923 if (ch
->state
== STFAX_CONT
) {
924 pr_debug("%s: pump stev RSP_CONN\n", ch
->is
->name
);
925 ch
->state
= STFAX_ACTIV
;
926 test_and_set_bit(ISAR_RATE_REQ
, &ch
->is
->Flags
);
927 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
928 if (ch
->cmd
== PCTRL_CMD_FTH
) {
929 int delay
= (ch
->mod
== 3) ? 1000 : 200;
930 /* 1s (200 ms) Flags before data */
931 if (test_and_set_bit(FLG_FTI_RUN
,
933 del_timer(&ch
->ftimer
);
935 jiffies
+ ((delay
* HZ
) / 1000);
936 test_and_set_bit(FLG_LL_CONN
,
938 add_timer(&ch
->ftimer
);
940 deliver_status(ch
, HW_MOD_CONNECT
);
943 pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
944 ch
->is
->name
, ch
->state
);
948 pr_debug("%s: pump stev FLAGS_DET\n", ch
->is
->name
);
951 pr_debug("%s: pump stev RSP_DISC state(%d)\n",
952 ch
->is
->name
, ch
->state
);
953 if (ch
->state
== STFAX_ESCAPE
) {
955 switch (ch
->newcmd
) {
957 ch
->state
= STFAX_READY
;
963 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
964 PCTRL_CMD_SILON
, 1, &p1
);
965 ch
->state
= STFAX_SILDET
;
969 ch
->mod
= ch
->newmod
;
972 ch
->cmd
= ch
->newcmd
;
974 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
976 ch
->state
= STFAX_LINE
;
980 pr_debug("%s: RSP_DISC unknown newcmd %x\n",
981 ch
->is
->name
, ch
->newcmd
);
984 } else if (ch
->state
== STFAX_ACTIV
) {
985 if (test_and_clear_bit(FLG_LL_OK
, &ch
->bch
.Flags
))
986 deliver_status(ch
, HW_MOD_OK
);
987 else if (ch
->cmd
== PCTRL_CMD_FRM
)
988 deliver_status(ch
, HW_MOD_NOCARR
);
990 deliver_status(ch
, HW_MOD_FCERROR
);
991 ch
->state
= STFAX_READY
;
992 } else if (ch
->state
!= STFAX_SILDET
) {
993 /* ignore in STFAX_SILDET */
994 ch
->state
= STFAX_READY
;
995 deliver_status(ch
, HW_MOD_FCERROR
);
998 case PSEV_RSP_SILDET
:
999 pr_debug("%s: pump stev RSP_SILDET\n", ch
->is
->name
);
1000 if (ch
->state
== STFAX_SILDET
) {
1001 ch
->mod
= ch
->newmod
;
1004 ch
->cmd
= ch
->newcmd
;
1006 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1008 ch
->state
= STFAX_LINE
;
1012 case PSEV_RSP_SILOFF
:
1013 pr_debug("%s: pump stev RSP_SILOFF\n", ch
->is
->name
);
1015 case PSEV_RSP_FCERR
:
1016 if (ch
->state
== STFAX_LINE
) {
1017 pr_debug("%s: pump stev RSP_FCERR try %d\n",
1018 ch
->is
->name
, ch
->try_mod
);
1019 if (ch
->try_mod
--) {
1020 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
,
1021 ch
->cmd
, 1, &ch
->mod
);
1025 pr_debug("%s: pump stev RSP_FCERR\n", ch
->is
->name
);
1026 ch
->state
= STFAX_ESCAPE
;
1027 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, PCTRL_CMD_ESC
,
1029 deliver_status(ch
, HW_MOD_FCERROR
);
1037 mISDNisar_irq(struct isar_hw
*isar
)
1041 get_irq_infos(isar
);
1042 switch (isar
->iis
& ISAR_IIS_MSCMSD
) {
1043 case ISAR_IIS_RDATA
:
1044 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1048 pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
1049 isar
->name
, isar
->iis
, isar
->cmsb
,
1051 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1054 case ISAR_IIS_GSTEV
:
1055 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1056 isar
->bstat
|= isar
->cmsb
;
1057 check_send(isar
, isar
->cmsb
);
1059 case ISAR_IIS_BSTEV
:
1060 #ifdef ERROR_STATISTIC
1061 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1063 if (isar
->cmsb
== BSTEV_TBO
)
1065 if (isar
->cmsb
== BSTEV_RBO
)
1069 pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
1070 isar
->name
, isar
->iis
>> 6, isar
->cmsb
);
1071 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1073 case ISAR_IIS_PSTEV
:
1074 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1076 rcv_mbox(isar
, NULL
);
1077 if (ch
->bch
.state
== ISDN_P_B_MODEM_ASYNC
)
1078 isar_pump_statev_modem(ch
, isar
->cmsb
);
1079 else if (ch
->bch
.state
== ISDN_P_B_T30_FAX
)
1080 isar_pump_statev_fax(ch
, isar
->cmsb
);
1081 else if (ch
->bch
.state
== ISDN_P_B_RAW
) {
1083 tt
= isar
->cmsb
| 0x30;
1086 else if (tt
== 0x3f)
1090 tt
|= DTMF_TONE_VAL
;
1091 _queue_data(&ch
->bch
.ch
, PH_CONTROL_IND
,
1092 MISDN_ID_ANY
, sizeof(tt
), &tt
,
1095 pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
1096 isar
->name
, ch
->bch
.state
,
1099 pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
1100 isar
->name
, isar
->iis
, isar
->cmsb
,
1102 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1105 case ISAR_IIS_PSTRSP
:
1106 ch
= sel_bch_isar(isar
, isar
->iis
>> 6);
1108 rcv_mbox(isar
, NULL
);
1109 isar_pump_status_rsp(ch
);
1111 pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
1112 isar
->name
, isar
->iis
, isar
->cmsb
,
1114 isar
->write_reg(isar
->hw
, ISAR_IIA
, 0);
1118 case ISAR_IIS_BSTRSP
:
1119 case ISAR_IIS_IOM2RSP
:
1120 rcv_mbox(isar
, NULL
);
1122 case ISAR_IIS_INVMSG
:
1123 rcv_mbox(isar
, NULL
);
1124 pr_debug("%s: invalid msg his:%x\n", isar
->name
, isar
->cmsb
);
1127 rcv_mbox(isar
, NULL
);
1128 pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
1129 isar
->name
, isar
->iis
, isar
->cmsb
, isar
->clsb
);
1133 EXPORT_SYMBOL(mISDNisar_irq
);
1136 ftimer_handler(struct timer_list
*t
)
1138 struct isar_ch
*ch
= from_timer(ch
, t
, ftimer
);
1140 pr_debug("%s: ftimer flags %lx\n", ch
->is
->name
, ch
->bch
.Flags
);
1141 test_and_clear_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1142 if (test_and_clear_bit(FLG_LL_CONN
, &ch
->bch
.Flags
))
1143 deliver_status(ch
, HW_MOD_CONNECT
);
1147 setup_pump(struct isar_ch
*ch
) {
1148 u8 dps
= SET_DPS(ch
->dpath
);
1151 switch (ch
->bch
.state
) {
1155 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, PMOD_BYPASS
, 0, NULL
);
1157 case ISDN_P_B_L2DTMF
:
1158 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
)) {
1159 param
[0] = 5; /* TOA 5 db */
1160 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1161 PMOD_DTMF_TRANS
, 1, param
);
1163 param
[0] = 40; /* REL -46 dbm */
1164 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
,
1165 PMOD_DTMF
, 1, param
);
1168 case ISDN_P_B_MODEM_ASYNC
:
1169 ctrl
= PMOD_DATAMODEM
;
1170 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1172 param
[5] = PV32P6_CTN
;
1174 param
[5] = PV32P6_ATN
;
1176 param
[0] = 6; /* 6 db */
1177 param
[1] = PV32P2_V23R
| PV32P2_V22A
| PV32P2_V22B
|
1178 PV32P2_V22C
| PV32P2_V21
| PV32P2_BEL
;
1179 param
[2] = PV32P3_AMOD
| PV32P3_V32B
| PV32P3_V23B
;
1180 param
[3] = PV32P4_UT144
;
1181 param
[4] = PV32P5_UT144
;
1182 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 6, param
);
1184 case ISDN_P_B_T30_FAX
:
1186 if (test_bit(FLG_ORIGIN
, &ch
->bch
.Flags
)) {
1188 param
[1] = PFAXP2_CTN
;
1190 param
[1] = PFAXP2_ATN
;
1192 param
[0] = 6; /* 6 db */
1193 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 2, param
);
1194 ch
->state
= STFAX_NULL
;
1197 test_and_set_bit(FLG_FTI_RUN
, &ch
->bch
.Flags
);
1201 send_mbox(ch
->is
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
1206 setup_sart(struct isar_ch
*ch
) {
1207 u8 dps
= SET_DPS(ch
->dpath
);
1208 u8 ctrl
, param
[2] = {0, 0};
1210 switch (ch
->bch
.state
) {
1212 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_DISABLE
,
1216 case ISDN_P_B_L2DTMF
:
1217 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_BINARY
,
1221 case ISDN_P_B_T30_FAX
:
1222 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, SMODE_HDLC
,
1225 case ISDN_P_B_MODEM_ASYNC
:
1226 ctrl
= SMODE_V14
| SCTRL_HDMC_BOTH
;
1227 param
[0] = S_P1_CHS_8
;
1228 param
[1] = S_P2_BFT_DEF
;
1229 send_mbox(ch
->is
, dps
| ISAR_HIS_SARTCFG
, ctrl
, 2, param
);
1233 send_mbox(ch
->is
, dps
| ISAR_HIS_BSTREQ
, 0, 0, NULL
);
1238 setup_iom2(struct isar_ch
*ch
) {
1239 u8 dps
= SET_DPS(ch
->dpath
);
1240 u8 cmsb
= IOM_CTRL_ENA
, msg
[5] = {IOM_P1_TXD
, 0, 0, 0, 0};
1242 if (ch
->bch
.nr
== 2) {
1246 switch (ch
->bch
.state
) {
1250 msg
[1] = ch
->dpath
+ 2;
1251 msg
[3] = ch
->dpath
+ 2;
1256 case ISDN_P_B_MODEM_ASYNC
:
1257 case ISDN_P_B_T30_FAX
:
1258 cmsb
|= IOM_CTRL_RCV
;
1260 case ISDN_P_B_L2DTMF
:
1261 if (test_bit(FLG_DTMFSEND
, &ch
->bch
.Flags
))
1262 cmsb
|= IOM_CTRL_RCV
;
1263 cmsb
|= IOM_CTRL_ALAW
;
1266 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2CFG
, cmsb
, 5, msg
);
1268 send_mbox(ch
->is
, dps
| ISAR_HIS_IOM2REQ
, 0, 0, NULL
);
1273 modeisar(struct isar_ch
*ch
, u32 bprotocol
)
1275 /* Here we are selecting the best datapath for requested protocol */
1276 if (ch
->bch
.state
== ISDN_P_NONE
) { /* New Setup */
1277 switch (bprotocol
) {
1278 case ISDN_P_NONE
: /* init */
1280 /* no init for dpath 0 */
1282 test_and_clear_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1283 test_and_clear_bit(FLG_TRANSPARENT
, &ch
->bch
.Flags
);
1287 /* best is datapath 2 */
1288 if (!test_and_set_bit(ISAR_DP2_USE
, &ch
->is
->Flags
))
1290 else if (!test_and_set_bit(ISAR_DP1_USE
,
1294 pr_info("modeisar both paths in use\n");
1297 if (bprotocol
== ISDN_P_B_HDLC
)
1298 test_and_set_bit(FLG_HDLC
, &ch
->bch
.Flags
);
1300 test_and_set_bit(FLG_TRANSPARENT
,
1303 case ISDN_P_B_MODEM_ASYNC
:
1304 case ISDN_P_B_T30_FAX
:
1305 case ISDN_P_B_L2DTMF
:
1306 /* only datapath 1 */
1307 if (!test_and_set_bit(ISAR_DP1_USE
, &ch
->is
->Flags
))
1310 pr_info("%s: ISAR modeisar analog functions"
1311 "only with DP1\n", ch
->is
->name
);
1316 pr_info("%s: protocol not known %x\n", ch
->is
->name
,
1318 return -ENOPROTOOPT
;
1321 pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch
->is
->name
,
1322 ch
->bch
.nr
, ch
->dpath
, ch
->bch
.state
, bprotocol
);
1323 ch
->bch
.state
= bprotocol
;
1327 if (ch
->bch
.state
== ISDN_P_NONE
) {
1328 /* Clear resources */
1330 test_and_clear_bit(ISAR_DP1_USE
, &ch
->is
->Flags
);
1331 else if (ch
->dpath
== 2)
1332 test_and_clear_bit(ISAR_DP2_USE
, &ch
->is
->Flags
);
1334 ch
->is
->ctrl(ch
->is
->hw
, HW_DEACT_IND
, ch
->bch
.nr
);
1336 ch
->is
->ctrl(ch
->is
->hw
, HW_ACTIVATE_IND
, ch
->bch
.nr
);
1341 isar_pump_cmd(struct isar_ch
*ch
, u32 cmd
, u8 para
)
1343 u8 dps
= SET_DPS(ch
->dpath
);
1344 u8 ctrl
= 0, nom
= 0, p1
= 0;
1346 pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
1347 ch
->is
->name
, cmd
, para
, ch
->bch
.state
);
1350 if (ch
->state
== STFAX_READY
) {
1352 ctrl
= PCTRL_CMD_FTM
;
1354 ch
->state
= STFAX_LINE
;
1360 } else if ((ch
->state
== STFAX_ACTIV
) &&
1361 (ch
->cmd
== PCTRL_CMD_FTM
) && (ch
->mod
== para
))
1362 deliver_status(ch
, HW_MOD_CONNECT
);
1365 ch
->newcmd
= PCTRL_CMD_FTM
;
1367 ctrl
= PCTRL_CMD_ESC
;
1368 ch
->state
= STFAX_ESCAPE
;
1372 if (ch
->state
== STFAX_READY
) {
1374 ctrl
= PCTRL_CMD_FTH
;
1376 ch
->state
= STFAX_LINE
;
1382 } else if ((ch
->state
== STFAX_ACTIV
) &&
1383 (ch
->cmd
== PCTRL_CMD_FTH
) && (ch
->mod
== para
))
1384 deliver_status(ch
, HW_MOD_CONNECT
);
1387 ch
->newcmd
= PCTRL_CMD_FTH
;
1389 ctrl
= PCTRL_CMD_ESC
;
1390 ch
->state
= STFAX_ESCAPE
;
1394 if (ch
->state
== STFAX_READY
) {
1396 ctrl
= PCTRL_CMD_FRM
;
1398 ch
->state
= STFAX_LINE
;
1404 } else if ((ch
->state
== STFAX_ACTIV
) &&
1405 (ch
->cmd
== PCTRL_CMD_FRM
) && (ch
->mod
== para
))
1406 deliver_status(ch
, HW_MOD_CONNECT
);
1409 ch
->newcmd
= PCTRL_CMD_FRM
;
1411 ctrl
= PCTRL_CMD_ESC
;
1412 ch
->state
= STFAX_ESCAPE
;
1416 if (ch
->state
== STFAX_READY
) {
1418 ctrl
= PCTRL_CMD_FRH
;
1420 ch
->state
= STFAX_LINE
;
1426 } else if ((ch
->state
== STFAX_ACTIV
) &&
1427 (ch
->cmd
== PCTRL_CMD_FRH
) && (ch
->mod
== para
))
1428 deliver_status(ch
, HW_MOD_CONNECT
);
1431 ch
->newcmd
= PCTRL_CMD_FRH
;
1433 ctrl
= PCTRL_CMD_ESC
;
1434 ch
->state
= STFAX_ESCAPE
;
1437 case PCTRL_CMD_TDTMF
:
1440 ctrl
= PCTRL_CMD_TDTMF
;
1444 send_mbox(ch
->is
, dps
| ISAR_HIS_PUMPCTRL
, ctrl
, nom
, &p1
);
1448 isar_setup(struct isar_hw
*isar
)
1455 for (i
= 0; i
< 2; i
++) {
1457 send_mbox(isar
, (i
? ISAR_HIS_DPS2
: ISAR_HIS_DPS1
) |
1458 ISAR_HIS_P12CFG
, 4, 1, &msg
);
1459 isar
->ch
[i
].mml
= msg
;
1460 isar
->ch
[i
].bch
.state
= 0;
1461 isar
->ch
[i
].dpath
= i
+ 1;
1462 modeisar(&isar
->ch
[i
], ISDN_P_NONE
);
1467 isar_l2l1(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1469 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1470 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1472 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1478 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1479 ret
= bchannel_senddata(bch
, skb
);
1480 if (ret
> 0) { /* direct TX */
1482 isar_fill_fifo(ich
);
1484 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1486 case PH_ACTIVATE_REQ
:
1487 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1488 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
))
1489 ret
= modeisar(ich
, ch
->protocol
);
1492 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1494 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
1497 case PH_DEACTIVATE_REQ
:
1498 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1499 mISDN_clear_bchannel(bch
);
1500 modeisar(ich
, ISDN_P_NONE
);
1501 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1502 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
, 0,
1506 case PH_CONTROL_REQ
:
1507 val
= (u32
*)skb
->data
;
1508 pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich
->is
->name
,
1510 if ((hh
->id
== 0) && ((*val
& ~DTMF_TONE_MASK
) ==
1512 if (bch
->state
== ISDN_P_B_L2DTMF
) {
1513 char tt
= *val
& DTMF_TONE_MASK
;
1522 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1523 isar_pump_cmd(ich
, PCTRL_CMD_TDTMF
, tt
);
1524 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1526 pr_info("%s: DTMF send wrong protocol %x\n",
1527 __func__
, bch
->state
);
1530 } else if ((hh
->id
== HW_MOD_FRM
) || (hh
->id
== HW_MOD_FRH
) ||
1531 (hh
->id
== HW_MOD_FTM
) || (hh
->id
== HW_MOD_FTH
)) {
1532 for (id
= 0; id
< FAXMODCNT
; id
++)
1533 if (faxmodulation
[id
] == *val
)
1535 if ((FAXMODCNT
> id
) &&
1536 test_bit(FLG_INITIALIZED
, &bch
->Flags
)) {
1537 pr_debug("%s: isar: new mod\n", ich
->is
->name
);
1538 isar_pump_cmd(ich
, hh
->id
, *val
);
1541 pr_info("%s: wrong modulation\n",
1545 } else if (hh
->id
== HW_MOD_LASTDATA
)
1546 test_and_set_bit(FLG_DLEETX
, &bch
->Flags
);
1548 pr_info("%s: unknown PH_CONTROL_REQ %x\n",
1549 ich
->is
->name
, hh
->id
);
1554 pr_info("%s: %s unknown prim(%x,%x)\n",
1555 ich
->is
->name
, __func__
, hh
->prim
, hh
->id
);
1564 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
1566 return mISDN_ctrl_bchannel(bch
, cq
);
1570 isar_bctrl(struct mISDNchannel
*ch
, u32 cmd
, void *arg
)
1572 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1573 struct isar_ch
*ich
= container_of(bch
, struct isar_ch
, bch
);
1577 pr_debug("%s: %s cmd:%x %p\n", ich
->is
->name
, __func__
, cmd
, arg
);
1580 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1581 cancel_work_sync(&bch
->workq
);
1582 spin_lock_irqsave(ich
->is
->hwlock
, flags
);
1583 mISDN_clear_bchannel(bch
);
1584 modeisar(ich
, ISDN_P_NONE
);
1585 spin_unlock_irqrestore(ich
->is
->hwlock
, flags
);
1586 ch
->protocol
= ISDN_P_NONE
;
1588 module_put(ich
->is
->owner
);
1591 case CONTROL_CHANNEL
:
1592 ret
= channel_bctrl(bch
, arg
);
1595 pr_info("%s: %s unknown prim(%x)\n",
1596 ich
->is
->name
, __func__
, cmd
);
1602 free_isar(struct isar_hw
*isar
)
1604 modeisar(&isar
->ch
[0], ISDN_P_NONE
);
1605 modeisar(&isar
->ch
[1], ISDN_P_NONE
);
1606 del_timer(&isar
->ch
[0].ftimer
);
1607 del_timer(&isar
->ch
[1].ftimer
);
1608 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1609 test_and_clear_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1613 init_isar(struct isar_hw
*isar
)
1618 isar
->version
= ISARVersion(isar
);
1619 if (isar
->ch
[0].bch
.debug
& DEBUG_HW
)
1620 pr_notice("%s: Testing version %d (%d time)\n",
1621 isar
->name
, isar
->version
, 3 - cnt
);
1622 if (isar
->version
== 1)
1624 isar
->ctrl(isar
->hw
, HW_RESET_REQ
, 0);
1626 if (isar
->version
!= 1)
1628 timer_setup(&isar
->ch
[0].ftimer
, ftimer_handler
, 0);
1629 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[0].bch
.Flags
);
1630 timer_setup(&isar
->ch
[1].ftimer
, ftimer_handler
, 0);
1631 test_and_set_bit(FLG_INITIALIZED
, &isar
->ch
[1].bch
.Flags
);
1636 isar_open(struct isar_hw
*isar
, struct channel_req
*rq
)
1638 struct bchannel
*bch
;
1640 if (rq
->adr
.channel
== 0 || rq
->adr
.channel
> 2)
1642 if (rq
->protocol
== ISDN_P_NONE
)
1644 bch
= &isar
->ch
[rq
->adr
.channel
- 1].bch
;
1645 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
1646 return -EBUSY
; /* b-channel can be only open once */
1647 bch
->ch
.protocol
= rq
->protocol
;
1653 mISDNisar_init(struct isar_hw
*isar
, void *hw
)
1658 for (i
= 0; i
< 2; i
++) {
1659 isar
->ch
[i
].bch
.nr
= i
+ 1;
1660 mISDN_initbchannel(&isar
->ch
[i
].bch
, MAX_DATA_MEM
, 32);
1661 isar
->ch
[i
].bch
.ch
.nr
= i
+ 1;
1662 isar
->ch
[i
].bch
.ch
.send
= &isar_l2l1
;
1663 isar
->ch
[i
].bch
.ch
.ctrl
= isar_bctrl
;
1664 isar
->ch
[i
].bch
.hw
= hw
;
1665 isar
->ch
[i
].is
= isar
;
1668 isar
->init
= &init_isar
;
1669 isar
->release
= &free_isar
;
1670 isar
->firmware
= &load_firmware
;
1671 isar
->open
= &isar_open
;
1673 ret
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
1674 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
)) |
1675 (1 << (ISDN_P_B_L2DTMF
& ISDN_P_B_MASK
)) |
1676 (1 << (ISDN_P_B_MODEM_ASYNC
& ISDN_P_B_MASK
)) |
1677 (1 << (ISDN_P_B_T30_FAX
& ISDN_P_B_MASK
));
1681 EXPORT_SYMBOL(mISDNisar_init
);
1683 static int __init
isar_mod_init(void)
1685 pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV
);
1689 static void __exit
isar_mod_cleanup(void)
1691 pr_notice("mISDN: ISAR module unloaded\n");
1693 module_init(isar_mod_init
);
1694 module_exit(isar_mod_cleanup
);