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_LICENSE("GPL v2");
26 MODULE_VERSION(ISAR_REV);
28 #define DEBUG_HW_FIRMWARE_FIFO 0x10000
30 static const u8 faxmodulation[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121,
34 static void isar_setup(struct isar_hw *);
37 waitforHIA(struct isar_hw *isar, int timeout)
40 u8 val = isar->read_reg(isar->hw, ISAR_HIA);
42 while ((val & 1) && t) {
45 val = isar->read_reg(isar->hw, ISAR_HIA);
47 pr_debug("%s: HIA after %dus\n", isar->name, timeout - t);
52 * send msg to ISAR mailbox
53 * if msg is NULL use isar->buf
56 send_mbox(struct isar_hw *isar, u8 his, u8 creg, u8 len, u8 *msg)
58 if (!waitforHIA(isar, 1000))
60 pr_debug("send_mbox(%02x,%02x,%d)\n", his, creg, len);
61 isar->write_reg(isar->hw, ISAR_CTRL_H, creg);
62 isar->write_reg(isar->hw, ISAR_CTRL_L, len);
63 isar->write_reg(isar->hw, ISAR_WADR, 0);
67 isar->write_fifo(isar->hw, ISAR_MBOX, msg, len);
68 if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {
71 while (l < (int)len) {
72 hex_dump_to_buffer(msg + l, len - l, 32, 1,
74 pr_debug("%s: %s %02x: %s\n", isar->name,
75 __func__, l, isar->log);
80 isar->write_reg(isar->hw, ISAR_HIS, his);
81 waitforHIA(isar, 1000);
86 * receive message from ISAR mailbox
87 * if msg is NULL use isar->buf
90 rcv_mbox(struct isar_hw *isar, u8 *msg)
94 isar->write_reg(isar->hw, ISAR_RADR, 0);
95 if (msg && isar->clsb) {
96 isar->read_fifo(isar->hw, ISAR_MBOX, msg, isar->clsb);
97 if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) {
100 while (l < (int)isar->clsb) {
101 hex_dump_to_buffer(msg + l, isar->clsb - l, 32,
102 1, isar->log, 256, 1);
103 pr_debug("%s: %s %02x: %s\n", isar->name,
104 __func__, l, isar->log);
109 isar->write_reg(isar->hw, ISAR_IIA, 0);
113 get_irq_infos(struct isar_hw *isar)
115 isar->iis = isar->read_reg(isar->hw, ISAR_IIS);
116 isar->cmsb = isar->read_reg(isar->hw, ISAR_CTRL_H);
117 isar->clsb = isar->read_reg(isar->hw, ISAR_CTRL_L);
118 pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar->name,
119 isar->iis, isar->cmsb, isar->clsb);
123 * poll answer message from ISAR mailbox
124 * should be used only with ISAR IRQs disabled before DSP was started
128 poll_mbox(struct isar_hw *isar, int maxdelay)
133 irq = isar->read_reg(isar->hw, ISAR_IRQBIT);
134 while (t && !(irq & ISAR_IRQSTA)) {
140 rcv_mbox(isar, NULL);
142 pr_debug("%s: pulled %d bytes after %d us\n",
143 isar->name, isar->clsb, maxdelay - t);
148 ISARVersion(struct isar_hw *isar)
152 /* disable ISAR IRQ */
153 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
154 isar->buf[0] = ISAR_MSG_HWVER;
157 if (!send_mbox(isar, ISAR_HIS_VNR, 0, 3, NULL))
159 if (!poll_mbox(isar, 1000))
161 if (isar->iis == ISAR_IIS_VNR) {
162 if (isar->clsb == 1) {
163 ver = isar->buf[0] & 0xf;
172 load_firmware(struct isar_hw *isar, const u8 *buf, int size)
174 u32 saved_debug = isar->ch[0].bch.debug;
177 u16 left, val, *sp = (u16 *)buf;
187 if (1 != isar->version) {
188 pr_err("%s: ISAR wrong version %d firmware download aborted\n",
189 isar->name, isar->version);
192 if (!(saved_debug & DEBUG_HW_FIRMWARE_FIFO))
193 isar->ch[0].bch.debug &= ~DEBUG_HW_BFIFO;
194 pr_debug("%s: load firmware %d words (%d bytes)\n",
195 isar->name, size / 2, size);
198 /* disable ISAR IRQ */
199 spin_lock_irqsave(isar->hwlock, flags);
200 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
201 spin_unlock_irqrestore(isar->hwlock, flags);
203 blk_head.sadr = le16_to_cpu(*sp++);
204 blk_head.len = le16_to_cpu(*sp++);
205 blk_head.d_key = le16_to_cpu(*sp++);
207 pr_debug("ISAR firmware block (%#x,%d,%#x)\n",
208 blk_head.sadr, blk_head.len, blk_head.d_key & 0xff);
210 if (cnt + left > size) {
211 pr_info("%s: firmware error have %d need %d words\n",
212 isar->name, size, cnt + left);
216 spin_lock_irqsave(isar->hwlock, flags);
217 if (!send_mbox(isar, ISAR_HIS_DKEY, blk_head.d_key & 0xff,
219 pr_info("ISAR send_mbox dkey failed\n");
223 if (!poll_mbox(isar, 1000)) {
224 pr_warn("ISAR poll_mbox dkey failed\n");
228 spin_unlock_irqrestore(isar->hwlock, flags);
229 if ((isar->iis != ISAR_IIS_DKEY) || isar->cmsb || isar->clsb) {
230 pr_info("ISAR wrong dkey response (%x,%x,%x)\n",
231 isar->iis, isar->cmsb, isar->clsb);
242 /* the ISAR is big endian */
243 *mp++ = blk_head.sadr >> 8;
244 *mp++ = blk_head.sadr & 0xFF;
248 pr_debug("%s: load %3d words at %04x\n", isar->name,
250 blk_head.sadr += noc;
252 val = le16_to_cpu(*sp++);
257 spin_lock_irqsave(isar->hwlock, flags);
258 if (!send_mbox(isar, ISAR_HIS_FIRM, 0, nom, NULL)) {
259 pr_info("ISAR send_mbox prog failed\n");
263 if (!poll_mbox(isar, 1000)) {
264 pr_info("ISAR poll_mbox prog failed\n");
268 spin_unlock_irqrestore(isar->hwlock, flags);
269 if ((isar->iis != ISAR_IIS_FIRM) ||
270 isar->cmsb || isar->clsb) {
271 pr_info("ISAR wrong prog response (%x,%x,%x)\n",
272 isar->iis, isar->cmsb, isar->clsb);
277 pr_debug("%s: ISAR firmware block %d words loaded\n",
278 isar->name, blk_head.len);
280 isar->ch[0].bch.debug = saved_debug;
288 spin_lock_irqsave(isar->hwlock, flags);
289 if (!send_mbox(isar, ISAR_HIS_STDSP, 0, 2, NULL)) {
290 pr_info("ISAR send_mbox start dsp failed\n");
294 if (!poll_mbox(isar, 1000)) {
295 pr_info("ISAR poll_mbox start dsp failed\n");
299 if ((isar->iis != ISAR_IIS_STDSP) || isar->cmsb || isar->clsb) {
300 pr_info("ISAR wrong start dsp response (%x,%x,%x)\n",
301 isar->iis, isar->cmsb, isar->clsb);
305 pr_debug("%s: ISAR start dsp success\n", isar->name);
307 /* NORMAL mode entered */
308 /* Enable IRQs of ISAR */
309 isar->write_reg(isar->hw, ISAR_IRQBIT, ISAR_IRQSTA);
310 spin_unlock_irqrestore(isar->hwlock, flags);
311 cnt = 1000; /* max 1s */
312 while ((!isar->bstat) && cnt) {
317 pr_info("ISAR no general status event received\n");
321 pr_debug("%s: ISAR general status event %x\n",
322 isar->name, isar->bstat);
328 spin_lock_irqsave(isar->hwlock, flags);
329 if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_STST, 0, NULL)) {
330 pr_info("ISAR send_mbox self tst failed\n");
334 spin_unlock_irqrestore(isar->hwlock, flags);
335 cnt = 10000; /* max 100 ms */
336 while ((isar->iis != ISAR_IIS_DIAG) && cnt) {
342 pr_info("ISAR no self tst response\n");
346 if ((isar->cmsb == ISAR_CTRL_STST) && (isar->clsb == 1)
347 && (isar->buf[0] == 0))
348 pr_debug("%s: ISAR selftest OK\n", isar->name);
350 pr_info("ISAR selftest not OK %x/%x/%x\n",
351 isar->cmsb, isar->clsb, isar->buf[0]);
355 spin_lock_irqsave(isar->hwlock, flags);
357 if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_SWVER, 0, NULL)) {
358 pr_info("ISAR RQST SVN failed\n");
362 spin_unlock_irqrestore(isar->hwlock, flags);
363 cnt = 30000; /* max 300 ms */
364 while ((isar->iis != ISAR_IIS_DIAG) && cnt) {
370 pr_info("ISAR no SVN response\n");
374 if ((isar->cmsb == ISAR_CTRL_SWVER) && (isar->clsb == 1)) {
375 pr_notice("%s: ISAR software version %#x\n",
376 isar->name, isar->buf[0]);
378 pr_info("%s: ISAR wrong swver response (%x,%x)"
379 " cnt(%d)\n", isar->name, isar->cmsb,
385 spin_lock_irqsave(isar->hwlock, flags);
387 spin_unlock_irqrestore(isar->hwlock, flags);
390 spin_lock_irqsave(isar->hwlock, flags);
392 isar->ch[0].bch.debug = saved_debug;
394 /* disable ISAR IRQ */
395 isar->write_reg(isar->hw, ISAR_IRQBIT, 0);
396 spin_unlock_irqrestore(isar->hwlock, flags);
401 deliver_status(struct isar_ch *ch, int status)
403 pr_debug("%s: HL->LL FAXIND %x\n", ch->is->name, status);
404 _queue_data(&ch->bch.ch, PH_CONTROL_IND, status, 0, NULL, GFP_ATOMIC);
408 isar_rcv_frame(struct isar_ch *ch)
414 pr_debug("%s; ISAR zero len frame\n", ch->is->name);
415 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
418 if (test_bit(FLG_RX_OFF, &ch->bch.Flags)) {
419 ch->bch.dropcnt += ch->is->clsb;
420 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
423 switch (ch->bch.state) {
425 pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
426 ch->is->name, ch->is->iis, ch->is->cmsb, ch->is->clsb);
427 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
430 case ISDN_P_B_L2DTMF:
431 case ISDN_P_B_MODEM_ASYNC:
432 maxlen = bchannel_get_rxbuf(&ch->bch, ch->is->clsb);
434 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
435 ch->is->name, ch->bch.nr, ch->is->clsb);
436 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
439 rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
440 recv_Bchannel(&ch->bch, 0, false);
443 maxlen = bchannel_get_rxbuf(&ch->bch, ch->is->clsb);
445 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
446 ch->is->name, ch->bch.nr, ch->is->clsb);
447 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
450 if (ch->is->cmsb & HDLC_ERROR) {
451 pr_debug("%s: ISAR frame error %x len %d\n",
452 ch->is->name, ch->is->cmsb, ch->is->clsb);
453 #ifdef ERROR_STATISTIC
454 if (ch->is->cmsb & HDLC_ERR_RER)
456 if (ch->is->cmsb & HDLC_ERR_CER)
459 skb_trim(ch->bch.rx_skb, 0);
460 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
463 if (ch->is->cmsb & HDLC_FSD)
464 skb_trim(ch->bch.rx_skb, 0);
465 ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
466 rcv_mbox(ch->is, ptr);
467 if (ch->is->cmsb & HDLC_FED) {
468 if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
469 pr_debug("%s: ISAR frame too short %d\n",
470 ch->is->name, ch->bch.rx_skb->len);
471 skb_trim(ch->bch.rx_skb, 0);
474 skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
475 recv_Bchannel(&ch->bch, 0, false);
478 case ISDN_P_B_T30_FAX:
479 if (ch->state != STFAX_ACTIV) {
480 pr_debug("%s: isar_rcv_frame: not ACTIV\n",
482 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
484 skb_trim(ch->bch.rx_skb, 0);
487 if (!ch->bch.rx_skb) {
488 ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
490 if (unlikely(!ch->bch.rx_skb)) {
491 pr_info("%s: B receive out of memory\n",
493 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
497 if (ch->cmd == PCTRL_CMD_FRM) {
498 rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
499 pr_debug("%s: isar_rcv_frame: %d\n",
500 ch->is->name, ch->bch.rx_skb->len);
501 if (ch->is->cmsb & SART_NMD) { /* ABORT */
502 pr_debug("%s: isar_rcv_frame: no more data\n",
504 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
505 send_mbox(ch->is, SET_DPS(ch->dpath) |
506 ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
508 ch->state = STFAX_ESCAPE;
509 /* set_skb_flag(skb, DF_NOMOREDATA); */
511 recv_Bchannel(&ch->bch, 0, false);
512 if (ch->is->cmsb & SART_NMD)
513 deliver_status(ch, HW_MOD_NOCARR);
516 if (ch->cmd != PCTRL_CMD_FRH) {
517 pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
518 ch->is->name, ch->cmd);
519 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
521 skb_trim(ch->bch.rx_skb, 0);
525 if ((ch->bch.rx_skb->len + ch->is->clsb) >
526 (ch->bch.maxlen + 2)) {
527 pr_info("%s: %s incoming packet too large\n",
528 ch->is->name, __func__);
529 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
530 skb_trim(ch->bch.rx_skb, 0);
532 } else if (ch->is->cmsb & HDLC_ERROR) {
533 pr_info("%s: ISAR frame error %x len %d\n",
534 ch->is->name, ch->is->cmsb, ch->is->clsb);
535 skb_trim(ch->bch.rx_skb, 0);
536 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
539 if (ch->is->cmsb & HDLC_FSD)
540 skb_trim(ch->bch.rx_skb, 0);
541 ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
542 rcv_mbox(ch->is, ptr);
543 if (ch->is->cmsb & HDLC_FED) {
544 if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
545 pr_info("%s: ISAR frame too short %d\n",
546 ch->is->name, ch->bch.rx_skb->len);
547 skb_trim(ch->bch.rx_skb, 0);
550 skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
551 recv_Bchannel(&ch->bch, 0, false);
553 if (ch->is->cmsb & SART_NMD) { /* ABORT */
554 pr_debug("%s: isar_rcv_frame: no more data\n",
556 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
558 skb_trim(ch->bch.rx_skb, 0);
559 send_mbox(ch->is, SET_DPS(ch->dpath) |
560 ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, 0, NULL);
561 ch->state = STFAX_ESCAPE;
562 deliver_status(ch, HW_MOD_NOCARR);
566 pr_info("isar_rcv_frame protocol (%x)error\n", ch->bch.state);
567 ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
573 isar_fill_fifo(struct isar_ch *ch)
579 pr_debug("%s: ch%d tx_skb %d tx_idx %d\n", ch->is->name, ch->bch.nr,
580 ch->bch.tx_skb ? ch->bch.tx_skb->len : -1, ch->bch.tx_idx);
581 if (!(ch->is->bstat &
582 (ch->dpath == 1 ? BSTAT_RDM1 : BSTAT_RDM2)))
584 if (!ch->bch.tx_skb) {
585 if (!test_bit(FLG_TX_EMPTY, &ch->bch.Flags) ||
586 (ch->bch.state != ISDN_P_B_RAW))
589 /* use the card buffer */
590 memset(ch->is->buf, ch->bch.fill[0], count);
591 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
592 0, count, ch->is->buf);
595 count = ch->bch.tx_skb->len - ch->bch.tx_idx;
598 if (count > ch->mml) {
604 ptr = ch->bch.tx_skb->data + ch->bch.tx_idx;
605 if (!ch->bch.tx_idx) {
606 pr_debug("%s: frame start\n", ch->is->name);
607 if ((ch->bch.state == ISDN_P_B_T30_FAX) &&
608 (ch->cmd == PCTRL_CMD_FTH)) {
610 if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) {
612 test_and_set_bit(FLG_LASTDATA,
614 pr_debug("%s: set LASTDATA\n",
617 test_and_set_bit(FLG_DLEETX,
624 ch->bch.tx_idx += count;
625 switch (ch->bch.state) {
627 pr_info("%s: wrong protocol 0\n", __func__);
630 case ISDN_P_B_L2DTMF:
631 case ISDN_P_B_MODEM_ASYNC:
632 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
636 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
639 case ISDN_P_B_T30_FAX:
640 if (ch->state != STFAX_ACTIV)
641 pr_debug("%s: not ACTIV\n", ch->is->name);
642 else if (ch->cmd == PCTRL_CMD_FTH)
643 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
645 else if (ch->cmd == PCTRL_CMD_FTM)
646 send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
649 pr_debug("%s: not FTH/FTM\n", ch->is->name);
652 pr_info("%s: protocol(%x) error\n",
653 __func__, ch->bch.state);
658 static inline struct isar_ch *
659 sel_bch_isar(struct isar_hw *isar, u8 dpath)
661 struct isar_ch *base = &isar->ch[0];
663 if ((!dpath) || (dpath > 2))
665 if (base->dpath == dpath)
668 if (base->dpath == dpath)
674 send_next(struct isar_ch *ch)
676 pr_debug("%s: %s ch%d tx_skb %d tx_idx %d\n", ch->is->name, __func__,
677 ch->bch.nr, ch->bch.tx_skb ? ch->bch.tx_skb->len : -1,
679 if (ch->bch.state == ISDN_P_B_T30_FAX) {
680 if (ch->cmd == PCTRL_CMD_FTH) {
681 if (test_bit(FLG_LASTDATA, &ch->bch.Flags)) {
682 pr_debug("set NMD_DATA\n");
683 test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
685 } else if (ch->cmd == PCTRL_CMD_FTM) {
686 if (test_bit(FLG_DLEETX, &ch->bch.Flags)) {
687 test_and_set_bit(FLG_LASTDATA, &ch->bch.Flags);
688 test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
692 dev_kfree_skb(ch->bch.tx_skb);
693 if (get_next_bframe(&ch->bch)) {
695 test_and_clear_bit(FLG_TX_EMPTY, &ch->bch.Flags);
696 } else if (test_bit(FLG_TX_EMPTY, &ch->bch.Flags)) {
699 if (test_and_clear_bit(FLG_DLEETX, &ch->bch.Flags)) {
700 if (test_and_clear_bit(FLG_LASTDATA,
702 if (test_and_clear_bit(FLG_NMD_DATA,
705 send_mbox(ch->is, SET_DPS(ch->dpath) |
706 ISAR_HIS_SDATA, 0x01, 1, &zd);
708 test_and_set_bit(FLG_LL_OK, &ch->bch.Flags);
710 deliver_status(ch, HW_MOD_CONNECT);
712 } else if (test_bit(FLG_FILLEMPTY, &ch->bch.Flags)) {
713 test_and_set_bit(FLG_TX_EMPTY, &ch->bch.Flags);
719 check_send(struct isar_hw *isar, u8 rdm)
723 pr_debug("%s: rdm %x\n", isar->name, rdm);
724 if (rdm & BSTAT_RDM1) {
725 ch = sel_bch_isar(isar, 1);
726 if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
727 if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
734 if (rdm & BSTAT_RDM2) {
735 ch = sel_bch_isar(isar, 2);
736 if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
737 if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
746 static const char *dmril[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
747 "300", "600", "1200", "2400", "4800", "7200",
748 "9600nt", "9600t", "12000", "14400", "WRONG"};
749 static const char *dmrim[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
750 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
753 isar_pump_status_rsp(struct isar_ch *ch) {
754 u8 ril = ch->is->buf[0];
757 if (!test_and_clear_bit(ISAR_RATE_REQ, &ch->is->Flags))
760 pr_info("%s: wrong pstrsp ril=%d\n", ch->is->name, ril);
763 switch (ch->is->buf[1]) {
798 sprintf(ch->conmsg, "%s %s", dmril[ril], dmrim[rim]);
799 pr_debug("%s: pump strsp %s\n", ch->is->name, ch->conmsg);
803 isar_pump_statev_modem(struct isar_ch *ch, u8 devt) {
804 u8 dps = SET_DPS(ch->dpath);
807 case PSEV_10MS_TIMER:
808 pr_debug("%s: pump stev TIMER\n", ch->is->name);
811 pr_debug("%s: pump stev CONNECT\n", ch->is->name);
812 deliver_status(ch, HW_MOD_CONNECT);
815 pr_debug("%s: pump stev NO CONNECT\n", ch->is->name);
816 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
817 deliver_status(ch, HW_MOD_NOCARR);
820 pr_debug("%s: pump stev V24 OFF\n", ch->is->name);
823 pr_debug("%s: pump stev CTS ON\n", ch->is->name);
826 pr_debug("%s pump stev CTS OFF\n", ch->is->name);
829 pr_debug("%s: pump stev CARRIER ON\n", ch->is->name);
830 test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
831 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
834 pr_debug("%s: pump stev CARRIER OFF\n", ch->is->name);
837 pr_debug("%s: pump stev DSR ON\n", ch->is->name);
840 pr_debug("%s: pump stev DSR_OFF\n", ch->is->name);
843 pr_debug("%s: pump stev REMOTE RETRAIN\n", ch->is->name);
846 pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch->is->name);
849 pr_debug("%s: pump stev GSTN CLEAR\n", ch->is->name);
852 pr_info("u%s: unknown pump stev %x\n", ch->is->name, devt);
858 isar_pump_statev_fax(struct isar_ch *ch, u8 devt) {
859 u8 dps = SET_DPS(ch->dpath);
863 case PSEV_10MS_TIMER:
864 pr_debug("%s: pump stev TIMER\n", ch->is->name);
867 pr_debug("%s: pump stev RSP_READY\n", ch->is->name);
868 ch->state = STFAX_READY;
869 deliver_status(ch, HW_MOD_READY);
871 if (test_bit(BC_FLG_ORIG, &ch->bch.Flags))
872 isar_pump_cmd(bch, HW_MOD_FRH, 3);
874 isar_pump_cmd(bch, HW_MOD_FTH, 3);
878 if (ch->state == STFAX_LINE) {
879 pr_debug("%s: pump stev LINE_TX_H\n", ch->is->name);
880 ch->state = STFAX_CONT;
881 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
882 PCTRL_CMD_CONT, 0, NULL);
884 pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
885 ch->is->name, ch->state);
889 if (ch->state == STFAX_LINE) {
890 pr_debug("%s: pump stev LINE_RX_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_RX_H wrong st %x\n",
896 ch->is->name, ch->state);
900 if (ch->state == STFAX_LINE) {
901 pr_debug("%s: pump stev LINE_TX_B\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_TX_B wrong st %x\n",
907 ch->is->name, ch->state);
911 if (ch->state == STFAX_LINE) {
912 pr_debug("%s: pump stev LINE_RX_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_RX_B wrong st %x\n",
918 ch->is->name, ch->state);
922 if (ch->state == STFAX_CONT) {
923 pr_debug("%s: pump stev RSP_CONN\n", ch->is->name);
924 ch->state = STFAX_ACTIV;
925 test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
926 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
927 if (ch->cmd == PCTRL_CMD_FTH) {
928 int delay = (ch->mod == 3) ? 1000 : 200;
929 /* 1s (200 ms) Flags before data */
930 if (test_and_set_bit(FLG_FTI_RUN,
932 del_timer(&ch->ftimer);
934 jiffies + ((delay * HZ) / 1000);
935 test_and_set_bit(FLG_LL_CONN,
937 add_timer(&ch->ftimer);
939 deliver_status(ch, HW_MOD_CONNECT);
942 pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
943 ch->is->name, ch->state);
947 pr_debug("%s: pump stev FLAGS_DET\n", ch->is->name);
950 pr_debug("%s: pump stev RSP_DISC state(%d)\n",
951 ch->is->name, ch->state);
952 if (ch->state == STFAX_ESCAPE) {
954 switch (ch->newcmd) {
956 ch->state = STFAX_READY;
962 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
963 PCTRL_CMD_SILON, 1, &p1);
964 ch->state = STFAX_SILDET;
968 ch->mod = ch->newmod;
971 ch->cmd = ch->newcmd;
973 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
975 ch->state = STFAX_LINE;
979 pr_debug("%s: RSP_DISC unknown newcmd %x\n",
980 ch->is->name, ch->newcmd);
983 } else if (ch->state == STFAX_ACTIV) {
984 if (test_and_clear_bit(FLG_LL_OK, &ch->bch.Flags))
985 deliver_status(ch, HW_MOD_OK);
986 else if (ch->cmd == PCTRL_CMD_FRM)
987 deliver_status(ch, HW_MOD_NOCARR);
989 deliver_status(ch, HW_MOD_FCERROR);
990 ch->state = STFAX_READY;
991 } else if (ch->state != STFAX_SILDET) {
992 /* ignore in STFAX_SILDET */
993 ch->state = STFAX_READY;
994 deliver_status(ch, HW_MOD_FCERROR);
997 case PSEV_RSP_SILDET:
998 pr_debug("%s: pump stev RSP_SILDET\n", ch->is->name);
999 if (ch->state == STFAX_SILDET) {
1000 ch->mod = ch->newmod;
1003 ch->cmd = ch->newcmd;
1005 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
1007 ch->state = STFAX_LINE;
1011 case PSEV_RSP_SILOFF:
1012 pr_debug("%s: pump stev RSP_SILOFF\n", ch->is->name);
1014 case PSEV_RSP_FCERR:
1015 if (ch->state == STFAX_LINE) {
1016 pr_debug("%s: pump stev RSP_FCERR try %d\n",
1017 ch->is->name, ch->try_mod);
1018 if (ch->try_mod--) {
1019 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
1020 ch->cmd, 1, &ch->mod);
1024 pr_debug("%s: pump stev RSP_FCERR\n", ch->is->name);
1025 ch->state = STFAX_ESCAPE;
1026 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
1028 deliver_status(ch, HW_MOD_FCERROR);
1036 mISDNisar_irq(struct isar_hw *isar)
1040 get_irq_infos(isar);
1041 switch (isar->iis & ISAR_IIS_MSCMSD) {
1042 case ISAR_IIS_RDATA:
1043 ch = sel_bch_isar(isar, isar->iis >> 6);
1047 pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
1048 isar->name, isar->iis, isar->cmsb,
1050 isar->write_reg(isar->hw, ISAR_IIA, 0);
1053 case ISAR_IIS_GSTEV:
1054 isar->write_reg(isar->hw, ISAR_IIA, 0);
1055 isar->bstat |= isar->cmsb;
1056 check_send(isar, isar->cmsb);
1058 case ISAR_IIS_BSTEV:
1059 #ifdef ERROR_STATISTIC
1060 ch = sel_bch_isar(isar, isar->iis >> 6);
1062 if (isar->cmsb == BSTEV_TBO)
1064 if (isar->cmsb == BSTEV_RBO)
1068 pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
1069 isar->name, isar->iis >> 6, isar->cmsb);
1070 isar->write_reg(isar->hw, ISAR_IIA, 0);
1072 case ISAR_IIS_PSTEV:
1073 ch = sel_bch_isar(isar, isar->iis >> 6);
1075 rcv_mbox(isar, NULL);
1076 if (ch->bch.state == ISDN_P_B_MODEM_ASYNC)
1077 isar_pump_statev_modem(ch, isar->cmsb);
1078 else if (ch->bch.state == ISDN_P_B_T30_FAX)
1079 isar_pump_statev_fax(ch, isar->cmsb);
1080 else if (ch->bch.state == ISDN_P_B_RAW) {
1082 tt = isar->cmsb | 0x30;
1085 else if (tt == 0x3f)
1089 tt |= DTMF_TONE_VAL;
1090 _queue_data(&ch->bch.ch, PH_CONTROL_IND,
1091 MISDN_ID_ANY, sizeof(tt), &tt,
1094 pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
1095 isar->name, ch->bch.state,
1098 pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
1099 isar->name, isar->iis, isar->cmsb,
1101 isar->write_reg(isar->hw, ISAR_IIA, 0);
1104 case ISAR_IIS_PSTRSP:
1105 ch = sel_bch_isar(isar, isar->iis >> 6);
1107 rcv_mbox(isar, NULL);
1108 isar_pump_status_rsp(ch);
1110 pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
1111 isar->name, isar->iis, isar->cmsb,
1113 isar->write_reg(isar->hw, ISAR_IIA, 0);
1117 case ISAR_IIS_BSTRSP:
1118 case ISAR_IIS_IOM2RSP:
1119 rcv_mbox(isar, NULL);
1121 case ISAR_IIS_INVMSG:
1122 rcv_mbox(isar, NULL);
1123 pr_debug("%s: invalid msg his:%x\n", isar->name, isar->cmsb);
1126 rcv_mbox(isar, NULL);
1127 pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
1128 isar->name, isar->iis, isar->cmsb, isar->clsb);
1132 EXPORT_SYMBOL(mISDNisar_irq);
1135 ftimer_handler(struct timer_list *t)
1137 struct isar_ch *ch = from_timer(ch, t, ftimer);
1139 pr_debug("%s: ftimer flags %lx\n", ch->is->name, ch->bch.Flags);
1140 test_and_clear_bit(FLG_FTI_RUN, &ch->bch.Flags);
1141 if (test_and_clear_bit(FLG_LL_CONN, &ch->bch.Flags))
1142 deliver_status(ch, HW_MOD_CONNECT);
1146 setup_pump(struct isar_ch *ch) {
1147 u8 dps = SET_DPS(ch->dpath);
1150 switch (ch->bch.state) {
1154 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, PMOD_BYPASS, 0, NULL);
1156 case ISDN_P_B_L2DTMF:
1157 if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) {
1158 param[0] = 5; /* TOA 5 db */
1159 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
1160 PMOD_DTMF_TRANS, 1, param);
1162 param[0] = 40; /* REL -46 dbm */
1163 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
1164 PMOD_DTMF, 1, param);
1167 case ISDN_P_B_MODEM_ASYNC:
1168 ctrl = PMOD_DATAMODEM;
1169 if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
1171 param[5] = PV32P6_CTN;
1173 param[5] = PV32P6_ATN;
1175 param[0] = 6; /* 6 db */
1176 param[1] = PV32P2_V23R | PV32P2_V22A | PV32P2_V22B |
1177 PV32P2_V22C | PV32P2_V21 | PV32P2_BEL;
1178 param[2] = PV32P3_AMOD | PV32P3_V32B | PV32P3_V23B;
1179 param[3] = PV32P4_UT144;
1180 param[4] = PV32P5_UT144;
1181 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 6, param);
1183 case ISDN_P_B_T30_FAX:
1185 if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
1187 param[1] = PFAXP2_CTN;
1189 param[1] = PFAXP2_ATN;
1191 param[0] = 6; /* 6 db */
1192 send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 2, param);
1193 ch->state = STFAX_NULL;
1196 test_and_set_bit(FLG_FTI_RUN, &ch->bch.Flags);
1200 send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
1205 setup_sart(struct isar_ch *ch) {
1206 u8 dps = SET_DPS(ch->dpath);
1207 u8 ctrl, param[2] = {0, 0};
1209 switch (ch->bch.state) {
1211 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_DISABLE,
1215 case ISDN_P_B_L2DTMF:
1216 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_BINARY,
1220 case ISDN_P_B_T30_FAX:
1221 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_HDLC,
1224 case ISDN_P_B_MODEM_ASYNC:
1225 ctrl = SMODE_V14 | SCTRL_HDMC_BOTH;
1226 param[0] = S_P1_CHS_8;
1227 param[1] = S_P2_BFT_DEF;
1228 send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, ctrl, 2, param);
1232 send_mbox(ch->is, dps | ISAR_HIS_BSTREQ, 0, 0, NULL);
1237 setup_iom2(struct isar_ch *ch) {
1238 u8 dps = SET_DPS(ch->dpath);
1239 u8 cmsb = IOM_CTRL_ENA, msg[5] = {IOM_P1_TXD, 0, 0, 0, 0};
1241 if (ch->bch.nr == 2) {
1245 switch (ch->bch.state) {
1249 msg[1] = ch->dpath + 2;
1250 msg[3] = ch->dpath + 2;
1255 case ISDN_P_B_MODEM_ASYNC:
1256 case ISDN_P_B_T30_FAX:
1257 cmsb |= IOM_CTRL_RCV;
1259 case ISDN_P_B_L2DTMF:
1260 if (test_bit(FLG_DTMFSEND, &ch->bch.Flags))
1261 cmsb |= IOM_CTRL_RCV;
1262 cmsb |= IOM_CTRL_ALAW;
1265 send_mbox(ch->is, dps | ISAR_HIS_IOM2CFG, cmsb, 5, msg);
1267 send_mbox(ch->is, dps | ISAR_HIS_IOM2REQ, 0, 0, NULL);
1272 modeisar(struct isar_ch *ch, u32 bprotocol)
1274 /* Here we are selecting the best datapath for requested protocol */
1275 if (ch->bch.state == ISDN_P_NONE) { /* New Setup */
1276 switch (bprotocol) {
1277 case ISDN_P_NONE: /* init */
1279 /* no init for dpath 0 */
1281 test_and_clear_bit(FLG_HDLC, &ch->bch.Flags);
1282 test_and_clear_bit(FLG_TRANSPARENT, &ch->bch.Flags);
1286 /* best is datapath 2 */
1287 if (!test_and_set_bit(ISAR_DP2_USE, &ch->is->Flags))
1289 else if (!test_and_set_bit(ISAR_DP1_USE,
1293 pr_info("modeisar both paths in use\n");
1296 if (bprotocol == ISDN_P_B_HDLC)
1297 test_and_set_bit(FLG_HDLC, &ch->bch.Flags);
1299 test_and_set_bit(FLG_TRANSPARENT,
1302 case ISDN_P_B_MODEM_ASYNC:
1303 case ISDN_P_B_T30_FAX:
1304 case ISDN_P_B_L2DTMF:
1305 /* only datapath 1 */
1306 if (!test_and_set_bit(ISAR_DP1_USE, &ch->is->Flags))
1309 pr_info("%s: ISAR modeisar analog functions"
1310 "only with DP1\n", ch->is->name);
1315 pr_info("%s: protocol not known %x\n", ch->is->name,
1317 return -ENOPROTOOPT;
1320 pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch->is->name,
1321 ch->bch.nr, ch->dpath, ch->bch.state, bprotocol);
1322 ch->bch.state = bprotocol;
1326 if (ch->bch.state == ISDN_P_NONE) {
1327 /* Clear resources */
1329 test_and_clear_bit(ISAR_DP1_USE, &ch->is->Flags);
1330 else if (ch->dpath == 2)
1331 test_and_clear_bit(ISAR_DP2_USE, &ch->is->Flags);
1333 ch->is->ctrl(ch->is->hw, HW_DEACT_IND, ch->bch.nr);
1335 ch->is->ctrl(ch->is->hw, HW_ACTIVATE_IND, ch->bch.nr);
1340 isar_pump_cmd(struct isar_ch *ch, u32 cmd, u8 para)
1342 u8 dps = SET_DPS(ch->dpath);
1343 u8 ctrl = 0, nom = 0, p1 = 0;
1345 pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
1346 ch->is->name, cmd, para, ch->bch.state);
1349 if (ch->state == STFAX_READY) {
1351 ctrl = PCTRL_CMD_FTM;
1353 ch->state = STFAX_LINE;
1359 } else if ((ch->state == STFAX_ACTIV) &&
1360 (ch->cmd == PCTRL_CMD_FTM) && (ch->mod == para))
1361 deliver_status(ch, HW_MOD_CONNECT);
1364 ch->newcmd = PCTRL_CMD_FTM;
1366 ctrl = PCTRL_CMD_ESC;
1367 ch->state = STFAX_ESCAPE;
1371 if (ch->state == STFAX_READY) {
1373 ctrl = PCTRL_CMD_FTH;
1375 ch->state = STFAX_LINE;
1381 } else if ((ch->state == STFAX_ACTIV) &&
1382 (ch->cmd == PCTRL_CMD_FTH) && (ch->mod == para))
1383 deliver_status(ch, HW_MOD_CONNECT);
1386 ch->newcmd = PCTRL_CMD_FTH;
1388 ctrl = PCTRL_CMD_ESC;
1389 ch->state = STFAX_ESCAPE;
1393 if (ch->state == STFAX_READY) {
1395 ctrl = PCTRL_CMD_FRM;
1397 ch->state = STFAX_LINE;
1403 } else if ((ch->state == STFAX_ACTIV) &&
1404 (ch->cmd == PCTRL_CMD_FRM) && (ch->mod == para))
1405 deliver_status(ch, HW_MOD_CONNECT);
1408 ch->newcmd = PCTRL_CMD_FRM;
1410 ctrl = PCTRL_CMD_ESC;
1411 ch->state = STFAX_ESCAPE;
1415 if (ch->state == STFAX_READY) {
1417 ctrl = PCTRL_CMD_FRH;
1419 ch->state = STFAX_LINE;
1425 } else if ((ch->state == STFAX_ACTIV) &&
1426 (ch->cmd == PCTRL_CMD_FRH) && (ch->mod == para))
1427 deliver_status(ch, HW_MOD_CONNECT);
1430 ch->newcmd = PCTRL_CMD_FRH;
1432 ctrl = PCTRL_CMD_ESC;
1433 ch->state = STFAX_ESCAPE;
1436 case PCTRL_CMD_TDTMF:
1439 ctrl = PCTRL_CMD_TDTMF;
1443 send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, ctrl, nom, &p1);
1447 isar_setup(struct isar_hw *isar)
1454 for (i = 0; i < 2; i++) {
1456 send_mbox(isar, (i ? ISAR_HIS_DPS2 : ISAR_HIS_DPS1) |
1457 ISAR_HIS_P12CFG, 4, 1, &msg);
1458 isar->ch[i].mml = msg;
1459 isar->ch[i].bch.state = 0;
1460 isar->ch[i].dpath = i + 1;
1461 modeisar(&isar->ch[i], ISDN_P_NONE);
1466 isar_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)
1468 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1469 struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
1471 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1477 spin_lock_irqsave(ich->is->hwlock, flags);
1478 ret = bchannel_senddata(bch, skb);
1479 if (ret > 0) { /* direct TX */
1481 isar_fill_fifo(ich);
1483 spin_unlock_irqrestore(ich->is->hwlock, flags);
1485 case PH_ACTIVATE_REQ:
1486 spin_lock_irqsave(ich->is->hwlock, flags);
1487 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
1488 ret = modeisar(ich, ch->protocol);
1491 spin_unlock_irqrestore(ich->is->hwlock, flags);
1493 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
1496 case PH_DEACTIVATE_REQ:
1497 spin_lock_irqsave(ich->is->hwlock, flags);
1498 mISDN_clear_bchannel(bch);
1499 modeisar(ich, ISDN_P_NONE);
1500 spin_unlock_irqrestore(ich->is->hwlock, flags);
1501 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
1505 case PH_CONTROL_REQ:
1506 val = (u32 *)skb->data;
1507 pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich->is->name,
1509 if ((hh->id == 0) && ((*val & ~DTMF_TONE_MASK) ==
1511 if (bch->state == ISDN_P_B_L2DTMF) {
1512 char tt = *val & DTMF_TONE_MASK;
1521 spin_lock_irqsave(ich->is->hwlock, flags);
1522 isar_pump_cmd(ich, PCTRL_CMD_TDTMF, tt);
1523 spin_unlock_irqrestore(ich->is->hwlock, flags);
1525 pr_info("%s: DTMF send wrong protocol %x\n",
1526 __func__, bch->state);
1529 } else if ((hh->id == HW_MOD_FRM) || (hh->id == HW_MOD_FRH) ||
1530 (hh->id == HW_MOD_FTM) || (hh->id == HW_MOD_FTH)) {
1531 for (id = 0; id < FAXMODCNT; id++)
1532 if (faxmodulation[id] == *val)
1534 if ((FAXMODCNT > id) &&
1535 test_bit(FLG_INITIALIZED, &bch->Flags)) {
1536 pr_debug("%s: isar: new mod\n", ich->is->name);
1537 isar_pump_cmd(ich, hh->id, *val);
1540 pr_info("%s: wrong modulation\n",
1544 } else if (hh->id == HW_MOD_LASTDATA)
1545 test_and_set_bit(FLG_DLEETX, &bch->Flags);
1547 pr_info("%s: unknown PH_CONTROL_REQ %x\n",
1548 ich->is->name, hh->id);
1553 pr_info("%s: %s unknown prim(%x,%x)\n",
1554 ich->is->name, __func__, hh->prim, hh->id);
1563 channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
1565 return mISDN_ctrl_bchannel(bch, cq);
1569 isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1571 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1572 struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
1576 pr_debug("%s: %s cmd:%x %p\n", ich->is->name, __func__, cmd, arg);
1579 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1580 cancel_work_sync(&bch->workq);
1581 spin_lock_irqsave(ich->is->hwlock, flags);
1582 mISDN_clear_bchannel(bch);
1583 modeisar(ich, ISDN_P_NONE);
1584 spin_unlock_irqrestore(ich->is->hwlock, flags);
1585 ch->protocol = ISDN_P_NONE;
1587 module_put(ich->is->owner);
1590 case CONTROL_CHANNEL:
1591 ret = channel_bctrl(bch, arg);
1594 pr_info("%s: %s unknown prim(%x)\n",
1595 ich->is->name, __func__, cmd);
1601 free_isar(struct isar_hw *isar)
1603 modeisar(&isar->ch[0], ISDN_P_NONE);
1604 modeisar(&isar->ch[1], ISDN_P_NONE);
1605 del_timer(&isar->ch[0].ftimer);
1606 del_timer(&isar->ch[1].ftimer);
1607 test_and_clear_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
1608 test_and_clear_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
1612 init_isar(struct isar_hw *isar)
1617 isar->version = ISARVersion(isar);
1618 if (isar->ch[0].bch.debug & DEBUG_HW)
1619 pr_notice("%s: Testing version %d (%d time)\n",
1620 isar->name, isar->version, 3 - cnt);
1621 if (isar->version == 1)
1623 isar->ctrl(isar->hw, HW_RESET_REQ, 0);
1625 if (isar->version != 1)
1627 timer_setup(&isar->ch[0].ftimer, ftimer_handler, 0);
1628 test_and_set_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
1629 timer_setup(&isar->ch[1].ftimer, ftimer_handler, 0);
1630 test_and_set_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
1635 isar_open(struct isar_hw *isar, struct channel_req *rq)
1637 struct bchannel *bch;
1639 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1641 if (rq->protocol == ISDN_P_NONE)
1643 bch = &isar->ch[rq->adr.channel - 1].bch;
1644 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
1645 return -EBUSY; /* b-channel can be only open once */
1646 bch->ch.protocol = rq->protocol;
1652 mISDNisar_init(struct isar_hw *isar, void *hw)
1657 for (i = 0; i < 2; i++) {
1658 isar->ch[i].bch.nr = i + 1;
1659 mISDN_initbchannel(&isar->ch[i].bch, MAX_DATA_MEM, 32);
1660 isar->ch[i].bch.ch.nr = i + 1;
1661 isar->ch[i].bch.ch.send = &isar_l2l1;
1662 isar->ch[i].bch.ch.ctrl = isar_bctrl;
1663 isar->ch[i].bch.hw = hw;
1664 isar->ch[i].is = isar;
1667 isar->init = &init_isar;
1668 isar->release = &free_isar;
1669 isar->firmware = &load_firmware;
1670 isar->open = &isar_open;
1672 ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
1673 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)) |
1674 (1 << (ISDN_P_B_L2DTMF & ISDN_P_B_MASK)) |
1675 (1 << (ISDN_P_B_MODEM_ASYNC & ISDN_P_B_MASK)) |
1676 (1 << (ISDN_P_B_T30_FAX & ISDN_P_B_MASK));
1680 EXPORT_SYMBOL(mISDNisar_init);
1682 static int __init isar_mod_init(void)
1684 pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV);
1688 static void __exit isar_mod_cleanup(void)
1690 pr_notice("mISDN: ISAR module unloaded\n");
1692 module_init(isar_mod_init);
1693 module_exit(isar_mod_cleanup);