1 // SPDX-License-Identifier: GPL-2.0-only
3 * isac.c ISAC specific routines
5 * Author Karsten Keil <keil@isdn4linux.de>
7 * Copyright 2009 by Karsten Keil <keil@isdn4linux.de>
10 #include <linux/irqreturn.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <linux/mISDNhw.h>
17 #define DBUSY_TIMER_VALUE 80
20 #define ISAC_REV "2.0"
22 MODULE_AUTHOR("Karsten Keil");
23 MODULE_VERSION(ISAC_REV);
24 MODULE_LICENSE("GPL v2");
26 #define ReadISAC(is, o) (is->read_reg(is->dch.hw, o + is->off))
27 #define WriteISAC(is, o, v) (is->write_reg(is->dch.hw, o + is->off, v))
28 #define ReadHSCX(h, o) (h->ip->read_reg(h->ip->hw, h->off + o))
29 #define WriteHSCX(h, o, v) (h->ip->write_reg(h->ip->hw, h->off + o, v))
30 #define ReadIPAC(ip, o) (ip->read_reg(ip->hw, o))
31 #define WriteIPAC(ip, o, v) (ip->write_reg(ip->hw, o, v))
34 ph_command(struct isac_hw *isac, u8 command)
36 pr_debug("%s: ph_command %x\n", isac->name, command);
37 if (isac->type & IPAC_TYPE_ISACX)
38 WriteISAC(isac, ISACX_CIX0, (command << 4) | 0xE);
40 WriteISAC(isac, ISAC_CIX0, (command << 2) | 3);
44 isac_ph_state_change(struct isac_hw *isac)
46 switch (isac->state) {
49 ph_command(isac, ISAC_CMD_DUI);
51 schedule_event(&isac->dch, FLG_PHCHANGE);
55 isac_ph_state_bh(struct dchannel *dch)
57 struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
59 switch (isac->state) {
63 l1_event(dch->l1, HW_RESET_IND);
67 l1_event(dch->l1, HW_DEACT_CNF);
72 l1_event(dch->l1, HW_DEACT_IND);
76 l1_event(dch->l1, HW_POWERUP_IND);
79 if (dch->state <= 5) {
81 l1_event(dch->l1, ANYSIGNAL);
84 l1_event(dch->l1, LOSTFRAMING);
89 l1_event(dch->l1, INFO2);
93 l1_event(dch->l1, INFO4_P8);
97 l1_event(dch->l1, INFO4_P10);
100 pr_debug("%s: TE newstate %x\n", isac->name, dch->state);
104 isac_empty_fifo(struct isac_hw *isac, int count)
108 pr_debug("%s: %s %d\n", isac->name, __func__, count);
110 if (!isac->dch.rx_skb) {
111 isac->dch.rx_skb = mI_alloc_skb(isac->dch.maxlen, GFP_ATOMIC);
112 if (!isac->dch.rx_skb) {
113 pr_info("%s: D receive out of memory\n", isac->name);
114 WriteISAC(isac, ISAC_CMDR, 0x80);
118 if ((isac->dch.rx_skb->len + count) >= isac->dch.maxlen) {
119 pr_debug("%s: %s overrun %d\n", isac->name, __func__,
120 isac->dch.rx_skb->len + count);
121 WriteISAC(isac, ISAC_CMDR, 0x80);
124 ptr = skb_put(isac->dch.rx_skb, count);
125 isac->read_fifo(isac->dch.hw, isac->off, ptr, count);
126 WriteISAC(isac, ISAC_CMDR, 0x80);
127 if (isac->dch.debug & DEBUG_HW_DFIFO) {
128 char pfx[MISDN_MAX_IDLEN + 16];
130 snprintf(pfx, MISDN_MAX_IDLEN + 15, "D-recv %s %d ",
132 print_hex_dump_bytes(pfx, DUMP_PREFIX_OFFSET, ptr, count);
137 isac_fill_fifo(struct isac_hw *isac)
142 if (!isac->dch.tx_skb)
144 count = isac->dch.tx_skb->len - isac->dch.tx_idx;
153 pr_debug("%s: %s %d\n", isac->name, __func__, count);
154 ptr = isac->dch.tx_skb->data + isac->dch.tx_idx;
155 isac->dch.tx_idx += count;
156 isac->write_fifo(isac->dch.hw, isac->off, ptr, count);
157 WriteISAC(isac, ISAC_CMDR, more ? 0x8 : 0xa);
158 if (test_and_set_bit(FLG_BUSY_TIMER, &isac->dch.Flags)) {
159 pr_debug("%s: %s dbusytimer running\n", isac->name, __func__);
160 del_timer(&isac->dch.timer);
162 isac->dch.timer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ)/1000);
163 add_timer(&isac->dch.timer);
164 if (isac->dch.debug & DEBUG_HW_DFIFO) {
165 char pfx[MISDN_MAX_IDLEN + 16];
167 snprintf(pfx, MISDN_MAX_IDLEN + 15, "D-send %s %d ",
169 print_hex_dump_bytes(pfx, DUMP_PREFIX_OFFSET, ptr, count);
174 isac_rme_irq(struct isac_hw *isac)
178 val = ReadISAC(isac, ISAC_RSTA);
179 if ((val & 0x70) != 0x20) {
181 pr_debug("%s: ISAC RDO\n", isac->name);
182 #ifdef ERROR_STATISTIC
187 pr_debug("%s: ISAC CRC error\n", isac->name);
188 #ifdef ERROR_STATISTIC
192 WriteISAC(isac, ISAC_CMDR, 0x80);
193 dev_kfree_skb(isac->dch.rx_skb);
194 isac->dch.rx_skb = NULL;
196 count = ReadISAC(isac, ISAC_RBCL) & 0x1f;
199 isac_empty_fifo(isac, count);
200 recv_Dchannel(&isac->dch);
205 isac_xpr_irq(struct isac_hw *isac)
207 if (test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags))
208 del_timer(&isac->dch.timer);
209 if (isac->dch.tx_skb && isac->dch.tx_idx < isac->dch.tx_skb->len) {
210 isac_fill_fifo(isac);
212 dev_kfree_skb(isac->dch.tx_skb);
213 if (get_next_dframe(&isac->dch))
214 isac_fill_fifo(isac);
219 isac_retransmit(struct isac_hw *isac)
221 if (test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags))
222 del_timer(&isac->dch.timer);
223 if (test_bit(FLG_TX_BUSY, &isac->dch.Flags)) {
225 isac->dch.tx_idx = 0;
226 isac_fill_fifo(isac);
227 } else if (isac->dch.tx_skb) { /* should not happen */
228 pr_info("%s: tx_skb exist but not busy\n", isac->name);
229 test_and_set_bit(FLG_TX_BUSY, &isac->dch.Flags);
230 isac->dch.tx_idx = 0;
231 isac_fill_fifo(isac);
233 pr_info("%s: ISAC XDU no TX_BUSY\n", isac->name);
234 if (get_next_dframe(&isac->dch))
235 isac_fill_fifo(isac);
240 isac_mos_irq(struct isac_hw *isac)
245 val = ReadISAC(isac, ISAC_MOSR);
246 pr_debug("%s: ISAC MOSR %02x\n", isac->name, val);
250 isac->mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
252 pr_info("%s: ISAC MON RX out of memory!\n",
256 WriteISAC(isac, ISAC_MOCR, isac->mocr);
261 if (isac->mon_rxp >= MAX_MON_FRAME) {
264 WriteISAC(isac, ISAC_MOCR, isac->mocr);
266 pr_debug("%s: ISAC MON RX overflow!\n", isac->name);
269 isac->mon_rx[isac->mon_rxp++] = ReadISAC(isac, ISAC_MOR0);
270 pr_debug("%s: ISAC MOR0 %02x\n", isac->name,
271 isac->mon_rx[isac->mon_rxp - 1]);
272 if (isac->mon_rxp == 1) {
274 WriteISAC(isac, ISAC_MOCR, isac->mocr);
280 isac->mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
282 pr_info("%s: ISAC MON RX out of memory!\n",
286 WriteISAC(isac, ISAC_MOCR, isac->mocr);
291 if (isac->mon_rxp >= MAX_MON_FRAME) {
294 WriteISAC(isac, ISAC_MOCR, isac->mocr);
296 pr_debug("%s: ISAC MON RX overflow!\n", isac->name);
299 isac->mon_rx[isac->mon_rxp++] = ReadISAC(isac, ISAC_MOR1);
300 pr_debug("%s: ISAC MOR1 %02x\n", isac->name,
301 isac->mon_rx[isac->mon_rxp - 1]);
303 WriteISAC(isac, ISAC_MOCR, isac->mocr);
308 WriteISAC(isac, ISAC_MOCR, isac->mocr);
310 WriteISAC(isac, ISAC_MOCR, isac->mocr);
312 ret = isac->monitor(isac->dch.hw, MONITOR_RX_0,
313 isac->mon_rx, isac->mon_rxp);
317 pr_info("%s: MONITOR 0 received %d but no user\n",
318 isac->name, isac->mon_rxp);
326 WriteISAC(isac, ISAC_MOCR, isac->mocr);
328 WriteISAC(isac, ISAC_MOCR, isac->mocr);
330 ret = isac->monitor(isac->dch.hw, MONITOR_RX_1,
331 isac->mon_rx, isac->mon_rxp);
335 pr_info("%s: MONITOR 1 received %d but no user\n",
336 isac->name, isac->mon_rxp);
343 if ((!isac->mon_tx) || (isac->mon_txc &&
344 (isac->mon_txp >= isac->mon_txc) && !(val & 0x08))) {
346 WriteISAC(isac, ISAC_MOCR, isac->mocr);
348 WriteISAC(isac, ISAC_MOCR, isac->mocr);
349 if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
351 isac->monitor(isac->dch.hw,
352 MONITOR_TX_0, NULL, 0);
360 if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
362 isac->monitor(isac->dch.hw,
363 MONITOR_TX_0, NULL, 0);
370 WriteISAC(isac, ISAC_MOX0, isac->mon_tx[isac->mon_txp++]);
371 pr_debug("%s: ISAC %02x -> MOX0\n", isac->name,
372 isac->mon_tx[isac->mon_txp - 1]);
376 if ((!isac->mon_tx) || (isac->mon_txc &&
377 (isac->mon_txp >= isac->mon_txc) && !(val & 0x80))) {
379 WriteISAC(isac, ISAC_MOCR, isac->mocr);
381 WriteISAC(isac, ISAC_MOCR, isac->mocr);
382 if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
384 isac->monitor(isac->dch.hw,
385 MONITOR_TX_1, NULL, 0);
393 if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
395 isac->monitor(isac->dch.hw,
396 MONITOR_TX_1, NULL, 0);
403 WriteISAC(isac, ISAC_MOX1, isac->mon_tx[isac->mon_txp++]);
404 pr_debug("%s: ISAC %02x -> MOX1\n", isac->name,
405 isac->mon_tx[isac->mon_txp - 1]);
408 val = 0; /* dummy to avoid warning */
413 isac_cisq_irq(struct isac_hw *isac) {
416 val = ReadISAC(isac, ISAC_CIR0);
417 pr_debug("%s: ISAC CIR0 %02X\n", isac->name, val);
419 pr_debug("%s: ph_state change %x->%x\n", isac->name,
420 isac->state, (val >> 2) & 0xf);
421 isac->state = (val >> 2) & 0xf;
422 isac_ph_state_change(isac);
425 val = ReadISAC(isac, ISAC_CIR1);
426 pr_debug("%s: ISAC CIR1 %02X\n", isac->name, val);
431 isacsx_cic_irq(struct isac_hw *isac)
435 val = ReadISAC(isac, ISACX_CIR0);
436 pr_debug("%s: ISACX CIR0 %02X\n", isac->name, val);
437 if (val & ISACX_CIR0_CIC0) {
438 pr_debug("%s: ph_state change %x->%x\n", isac->name,
439 isac->state, val >> 4);
440 isac->state = val >> 4;
441 isac_ph_state_change(isac);
446 isacsx_rme_irq(struct isac_hw *isac)
451 val = ReadISAC(isac, ISACX_RSTAD);
452 if ((val & (ISACX_RSTAD_VFR |
456 != (ISACX_RSTAD_VFR | ISACX_RSTAD_CRC)) {
457 pr_debug("%s: RSTAD %#x, dropped\n", isac->name, val);
458 #ifdef ERROR_STATISTIC
459 if (val & ISACX_RSTAD_CRC)
464 WriteISAC(isac, ISACX_CMDRD, ISACX_CMDRD_RMC);
465 dev_kfree_skb(isac->dch.rx_skb);
466 isac->dch.rx_skb = NULL;
468 count = ReadISAC(isac, ISACX_RBCLD) & 0x1f;
471 isac_empty_fifo(isac, count);
472 if (isac->dch.rx_skb) {
473 skb_trim(isac->dch.rx_skb, isac->dch.rx_skb->len - 1);
474 pr_debug("%s: dchannel received %d\n", isac->name,
475 isac->dch.rx_skb->len);
476 recv_Dchannel(&isac->dch);
482 mISDNisac_irq(struct isac_hw *isac, u8 val)
486 pr_debug("%s: ISAC interrupt %02x\n", isac->name, val);
487 if (isac->type & IPAC_TYPE_ISACX) {
488 if (val & ISACX__CIC)
489 isacsx_cic_irq(isac);
490 if (val & ISACX__ICD) {
491 val = ReadISAC(isac, ISACX_ISTAD);
492 pr_debug("%s: ISTAD %02x\n", isac->name, val);
493 if (val & ISACX_D_XDU) {
494 pr_debug("%s: ISAC XDU\n", isac->name);
495 #ifdef ERROR_STATISTIC
498 isac_retransmit(isac);
500 if (val & ISACX_D_XMR) {
501 pr_debug("%s: ISAC XMR\n", isac->name);
502 #ifdef ERROR_STATISTIC
505 isac_retransmit(isac);
507 if (val & ISACX_D_XPR)
509 if (val & ISACX_D_RFO) {
510 pr_debug("%s: ISAC RFO\n", isac->name);
511 WriteISAC(isac, ISACX_CMDRD, ISACX_CMDRD_RMC);
513 if (val & ISACX_D_RME)
514 isacsx_rme_irq(isac);
515 if (val & ISACX_D_RPF)
516 isac_empty_fifo(isac, 0x20);
519 if (val & 0x80) /* RME */
521 if (val & 0x40) /* RPF */
522 isac_empty_fifo(isac, 32);
523 if (val & 0x10) /* XPR */
525 if (val & 0x04) /* CISQ */
527 if (val & 0x20) /* RSC - never */
528 pr_debug("%s: ISAC RSC interrupt\n", isac->name);
529 if (val & 0x02) /* SIN - never */
530 pr_debug("%s: ISAC SIN interrupt\n", isac->name);
531 if (val & 0x01) { /* EXI */
532 val = ReadISAC(isac, ISAC_EXIR);
533 pr_debug("%s: ISAC EXIR %02x\n", isac->name, val);
534 if (val & 0x80) /* XMR */
535 pr_debug("%s: ISAC XMR\n", isac->name);
536 if (val & 0x40) { /* XDU */
537 pr_debug("%s: ISAC XDU\n", isac->name);
538 #ifdef ERROR_STATISTIC
541 isac_retransmit(isac);
543 if (val & 0x04) /* MOS */
549 EXPORT_SYMBOL(mISDNisac_irq);
552 isac_l1hw(struct mISDNchannel *ch, struct sk_buff *skb)
554 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
555 struct dchannel *dch = container_of(dev, struct dchannel, dev);
556 struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
558 struct mISDNhead *hh = mISDN_HEAD_P(skb);
564 spin_lock_irqsave(isac->hwlock, flags);
565 ret = dchannel_senddata(dch, skb);
566 if (ret > 0) { /* direct TX */
567 id = hh->id; /* skb can be freed */
568 isac_fill_fifo(isac);
570 spin_unlock_irqrestore(isac->hwlock, flags);
571 queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
573 spin_unlock_irqrestore(isac->hwlock, flags);
575 case PH_ACTIVATE_REQ:
576 ret = l1_event(dch->l1, hh->prim);
578 case PH_DEACTIVATE_REQ:
579 test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
580 ret = l1_event(dch->l1, hh->prim);
590 isac_ctrl(struct isac_hw *isac, u32 cmd, unsigned long para)
598 spin_lock_irqsave(isac->hwlock, flags);
599 if (!(isac->type & IPAC_TYPE_ISACX)) {
600 /* TODO: implement for IPAC_TYPE_ISACX */
601 if (para & 1) /* B1 */
603 else if (para & 2) /* B2 */
605 /* we only support IOM2 mode */
606 WriteISAC(isac, ISAC_SPCR, tl);
608 WriteISAC(isac, ISAC_ADF1, 0x8);
610 WriteISAC(isac, ISAC_ADF1, 0x0);
612 spin_unlock_irqrestore(isac->hwlock, flags);
614 case HW_TIMER3_VALUE:
615 ret = l1_event(isac->dch.l1, HW_TIMER3_VALUE | (para & 0xff));
618 pr_debug("%s: %s unknown command %x %lx\n", isac->name,
619 __func__, cmd, para);
626 isac_l1cmd(struct dchannel *dch, u32 cmd)
628 struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
631 pr_debug("%s: cmd(%x) state(%02x)\n", isac->name, cmd, isac->state);
634 spin_lock_irqsave(isac->hwlock, flags);
635 ph_command(isac, ISAC_CMD_AR8);
636 spin_unlock_irqrestore(isac->hwlock, flags);
639 spin_lock_irqsave(isac->hwlock, flags);
640 ph_command(isac, ISAC_CMD_AR10);
641 spin_unlock_irqrestore(isac->hwlock, flags);
644 spin_lock_irqsave(isac->hwlock, flags);
645 if ((isac->state == ISAC_IND_EI) ||
646 (isac->state == ISAC_IND_DR) ||
647 (isac->state == ISAC_IND_DR6) ||
648 (isac->state == ISAC_IND_RS))
649 ph_command(isac, ISAC_CMD_TIM);
651 ph_command(isac, ISAC_CMD_RS);
652 spin_unlock_irqrestore(isac->hwlock, flags);
655 skb_queue_purge(&dch->squeue);
657 dev_kfree_skb(dch->tx_skb);
662 dev_kfree_skb(dch->rx_skb);
665 test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
666 if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
667 del_timer(&dch->timer);
670 spin_lock_irqsave(isac->hwlock, flags);
671 ph_command(isac, ISAC_CMD_TIM);
672 spin_unlock_irqrestore(isac->hwlock, flags);
674 case PH_ACTIVATE_IND:
675 test_and_set_bit(FLG_ACTIVE, &dch->Flags);
676 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
679 case PH_DEACTIVATE_IND:
680 test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
681 _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
685 pr_debug("%s: %s unknown command %x\n", isac->name,
693 isac_release(struct isac_hw *isac)
695 if (isac->type & IPAC_TYPE_ISACX)
696 WriteISAC(isac, ISACX_MASK, 0xff);
697 else if (isac->type != 0)
698 WriteISAC(isac, ISAC_MASK, 0xff);
699 if (isac->dch.timer.function != NULL) {
700 del_timer(&isac->dch.timer);
701 isac->dch.timer.function = NULL;
708 l1_event(isac->dch.l1, CLOSE_CHANNEL);
709 mISDN_freedchannel(&isac->dch);
713 dbusy_timer_handler(struct timer_list *t)
715 struct isac_hw *isac = from_timer(isac, t, dch.timer);
719 if (test_bit(FLG_BUSY_TIMER, &isac->dch.Flags)) {
720 spin_lock_irqsave(isac->hwlock, flags);
721 rbch = ReadISAC(isac, ISAC_RBCH);
722 star = ReadISAC(isac, ISAC_STAR);
723 pr_debug("%s: D-Channel Busy RBCH %02x STAR %02x\n",
724 isac->name, rbch, star);
725 if (rbch & ISAC_RBCH_XAC) /* D-Channel Busy */
726 test_and_set_bit(FLG_L1_BUSY, &isac->dch.Flags);
728 /* discard frame; reset transceiver */
729 test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags);
730 if (isac->dch.tx_idx)
731 isac->dch.tx_idx = 0;
733 pr_info("%s: ISAC D-Channel Busy no tx_idx\n",
735 /* Transmitter reset */
736 WriteISAC(isac, ISAC_CMDR, 0x01);
738 spin_unlock_irqrestore(isac->hwlock, flags);
743 open_dchannel_caller(struct isac_hw *isac, struct channel_req *rq, void *caller)
745 pr_debug("%s: %s dev(%d) open from %p\n", isac->name, __func__,
746 isac->dch.dev.id, caller);
747 if (rq->protocol != ISDN_P_TE_S0)
749 if (rq->adr.channel == 1)
750 /* E-Channel not supported */
752 rq->ch = &isac->dch.dev.D;
753 rq->ch->protocol = rq->protocol;
754 if (isac->dch.state == 7)
755 _queue_data(rq->ch, PH_ACTIVATE_IND, MISDN_ID_ANY,
756 0, NULL, GFP_KERNEL);
761 open_dchannel(struct isac_hw *isac, struct channel_req *rq)
763 return open_dchannel_caller(isac, rq, __builtin_return_address(0));
766 static const char *ISACVer[] =
767 {"2086/2186 V1.1", "2085 B1", "2085 B2",
771 isac_init(struct isac_hw *isac)
777 err = create_l1(&isac->dch, isac_l1cmd);
783 timer_setup(&isac->dch.timer, dbusy_timer_handler, 0);
785 if (isac->type & IPAC_TYPE_ISACX) {
786 /* Disable all IRQ */
787 WriteISAC(isac, ISACX_MASK, 0xff);
788 val = ReadISAC(isac, ISACX_STARD);
789 pr_debug("%s: ISACX STARD %x\n", isac->name, val);
790 val = ReadISAC(isac, ISACX_ISTAD);
791 pr_debug("%s: ISACX ISTAD %x\n", isac->name, val);
792 val = ReadISAC(isac, ISACX_ISTA);
793 pr_debug("%s: ISACX ISTA %x\n", isac->name, val);
795 WriteISAC(isac, ISACX_TR_CONF0, 0x00);
796 /* enable transmitter */
797 WriteISAC(isac, ISACX_TR_CONF2, 0x00);
798 /* transparent mode 0, RAC, stop/go */
799 WriteISAC(isac, ISACX_MODED, 0xc9);
800 /* all HDLC IRQ unmasked */
801 val = ReadISAC(isac, ISACX_ID);
802 if (isac->dch.debug & DEBUG_HW)
803 pr_notice("%s: ISACX Design ID %x\n",
804 isac->name, val & 0x3f);
805 val = ReadISAC(isac, ISACX_CIR0);
806 pr_debug("%s: ISACX CIR0 %02X\n", isac->name, val);
807 isac->state = val >> 4;
808 isac_ph_state_change(isac);
809 ph_command(isac, ISAC_CMD_RS);
810 WriteISAC(isac, ISACX_MASK, IPACX__ON);
811 WriteISAC(isac, ISACX_MASKD, 0x00);
812 } else { /* old isac */
813 WriteISAC(isac, ISAC_MASK, 0xff);
814 val = ReadISAC(isac, ISAC_STAR);
815 pr_debug("%s: ISAC STAR %x\n", isac->name, val);
816 val = ReadISAC(isac, ISAC_MODE);
817 pr_debug("%s: ISAC MODE %x\n", isac->name, val);
818 val = ReadISAC(isac, ISAC_ADF2);
819 pr_debug("%s: ISAC ADF2 %x\n", isac->name, val);
820 val = ReadISAC(isac, ISAC_ISTA);
821 pr_debug("%s: ISAC ISTA %x\n", isac->name, val);
823 val = ReadISAC(isac, ISAC_EXIR);
824 pr_debug("%s: ISAC EXIR %x\n", isac->name, val);
826 val = ReadISAC(isac, ISAC_RBCH);
827 if (isac->dch.debug & DEBUG_HW)
828 pr_notice("%s: ISAC version (%x): %s\n", isac->name,
829 val, ISACVer[(val >> 5) & 3]);
830 isac->type |= ((val >> 5) & 3);
833 if (!(isac->adf2 & 0x80)) { /* only IOM 2 Mode */
834 pr_info("%s: only support IOM2 mode but adf2=%02x\n",
835 isac->name, isac->adf2);
839 WriteISAC(isac, ISAC_ADF2, isac->adf2);
840 WriteISAC(isac, ISAC_SQXR, 0x2f);
841 WriteISAC(isac, ISAC_SPCR, 0x00);
842 WriteISAC(isac, ISAC_STCR, 0x70);
843 WriteISAC(isac, ISAC_MODE, 0xc9);
844 WriteISAC(isac, ISAC_TIMR, 0x00);
845 WriteISAC(isac, ISAC_ADF1, 0x00);
846 val = ReadISAC(isac, ISAC_CIR0);
847 pr_debug("%s: ISAC CIR0 %x\n", isac->name, val);
848 isac->state = (val >> 2) & 0xf;
849 isac_ph_state_change(isac);
850 ph_command(isac, ISAC_CMD_RS);
851 WriteISAC(isac, ISAC_MASK, 0);
857 mISDNisac_init(struct isac_hw *isac, void *hw)
859 mISDN_initdchannel(&isac->dch, MAX_DFRAME_LEN_L1, isac_ph_state_bh);
861 isac->dch.dev.D.send = isac_l1hw;
862 isac->init = isac_init;
863 isac->release = isac_release;
864 isac->ctrl = isac_ctrl;
865 isac->open = open_dchannel;
866 isac->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0);
867 isac->dch.dev.nrbchan = 2;
870 EXPORT_SYMBOL(mISDNisac_init);
873 waitforCEC(struct hscx_hw *hx)
878 starb = ReadHSCX(hx, IPAC_STARB);
885 pr_debug("%s: B%1d CEC %d us\n", hx->ip->name, hx->bch.nr,
888 pr_info("%s: B%1d CEC timeout\n", hx->ip->name, hx->bch.nr);
893 waitforXFW(struct hscx_hw *hx)
898 starb = ReadHSCX(hx, IPAC_STARB);
899 if ((starb & 0x44) == 0x40)
905 pr_debug("%s: B%1d XFW %d us\n", hx->ip->name, hx->bch.nr,
908 pr_info("%s: B%1d XFW timeout\n", hx->ip->name, hx->bch.nr);
912 hscx_cmdr(struct hscx_hw *hx, u8 cmd)
914 if (hx->ip->type & IPAC_TYPE_IPACX)
915 WriteHSCX(hx, IPACX_CMDRB, cmd);
918 WriteHSCX(hx, IPAC_CMDRB, cmd);
923 hscx_empty_fifo(struct hscx_hw *hscx, u8 count)
928 pr_debug("%s: B%1d %d\n", hscx->ip->name, hscx->bch.nr, count);
929 if (test_bit(FLG_RX_OFF, &hscx->bch.Flags)) {
930 hscx->bch.dropcnt += count;
931 hscx_cmdr(hscx, 0x80); /* RMC */
934 maxlen = bchannel_get_rxbuf(&hscx->bch, count);
936 hscx_cmdr(hscx, 0x80); /* RMC */
937 if (hscx->bch.rx_skb)
938 skb_trim(hscx->bch.rx_skb, 0);
939 pr_warn("%s.B%d: No bufferspace for %d bytes\n",
940 hscx->ip->name, hscx->bch.nr, count);
943 p = skb_put(hscx->bch.rx_skb, count);
945 if (hscx->ip->type & IPAC_TYPE_IPACX)
946 hscx->ip->read_fifo(hscx->ip->hw,
947 hscx->off + IPACX_RFIFOB, p, count);
949 hscx->ip->read_fifo(hscx->ip->hw,
950 hscx->off, p, count);
952 hscx_cmdr(hscx, 0x80); /* RMC */
954 if (hscx->bch.debug & DEBUG_HW_BFIFO) {
955 snprintf(hscx->log, 64, "B%1d-recv %s %d ",
956 hscx->bch.nr, hscx->ip->name, count);
957 print_hex_dump_bytes(hscx->log, DUMP_PREFIX_OFFSET, p, count);
962 hscx_fill_fifo(struct hscx_hw *hscx)
967 if (!hscx->bch.tx_skb) {
968 if (!test_bit(FLG_TX_EMPTY, &hscx->bch.Flags))
970 count = hscx->fifo_size;
973 memset(p, hscx->bch.fill[0], count);
975 count = hscx->bch.tx_skb->len - hscx->bch.tx_idx;
978 p = hscx->bch.tx_skb->data + hscx->bch.tx_idx;
980 more = test_bit(FLG_TRANSPARENT, &hscx->bch.Flags) ? 1 : 0;
981 if (count > hscx->fifo_size) {
982 count = hscx->fifo_size;
985 pr_debug("%s: B%1d %d/%d/%d\n", hscx->ip->name, hscx->bch.nr,
986 count, hscx->bch.tx_idx, hscx->bch.tx_skb->len);
987 hscx->bch.tx_idx += count;
989 if (hscx->ip->type & IPAC_TYPE_IPACX)
990 hscx->ip->write_fifo(hscx->ip->hw,
991 hscx->off + IPACX_XFIFOB, p, count);
994 hscx->ip->write_fifo(hscx->ip->hw,
995 hscx->off, p, count);
997 hscx_cmdr(hscx, more ? 0x08 : 0x0a);
999 if (hscx->bch.tx_skb && (hscx->bch.debug & DEBUG_HW_BFIFO)) {
1000 snprintf(hscx->log, 64, "B%1d-send %s %d ",
1001 hscx->bch.nr, hscx->ip->name, count);
1002 print_hex_dump_bytes(hscx->log, DUMP_PREFIX_OFFSET, p, count);
1007 hscx_xpr(struct hscx_hw *hx)
1009 if (hx->bch.tx_skb && hx->bch.tx_idx < hx->bch.tx_skb->len) {
1012 dev_kfree_skb(hx->bch.tx_skb);
1013 if (get_next_bframe(&hx->bch)) {
1015 test_and_clear_bit(FLG_TX_EMPTY, &hx->bch.Flags);
1016 } else if (test_bit(FLG_TX_EMPTY, &hx->bch.Flags)) {
1023 ipac_rme(struct hscx_hw *hx)
1028 if (hx->ip->type & IPAC_TYPE_IPACX)
1029 rstab = ReadHSCX(hx, IPACX_RSTAB);
1031 rstab = ReadHSCX(hx, IPAC_RSTAB);
1032 pr_debug("%s: B%1d RSTAB %02x\n", hx->ip->name, hx->bch.nr, rstab);
1033 if ((rstab & 0xf0) != 0xa0) {
1034 /* !(VFR && !RDO && CRC && !RAB) */
1035 if (!(rstab & 0x80)) {
1036 if (hx->bch.debug & DEBUG_HW_BCHANNEL)
1037 pr_notice("%s: B%1d invalid frame\n",
1038 hx->ip->name, hx->bch.nr);
1041 if (hx->bch.debug & DEBUG_HW_BCHANNEL)
1042 pr_notice("%s: B%1d RDO proto=%x\n",
1043 hx->ip->name, hx->bch.nr,
1046 if (!(rstab & 0x20)) {
1047 if (hx->bch.debug & DEBUG_HW_BCHANNEL)
1048 pr_notice("%s: B%1d CRC error\n",
1049 hx->ip->name, hx->bch.nr);
1051 hscx_cmdr(hx, 0x80); /* Do RMC */
1054 if (hx->ip->type & IPAC_TYPE_IPACX)
1055 count = ReadHSCX(hx, IPACX_RBCLB);
1057 count = ReadHSCX(hx, IPAC_RBCLB);
1058 count &= (hx->fifo_size - 1);
1060 count = hx->fifo_size;
1061 hscx_empty_fifo(hx, count);
1062 if (!hx->bch.rx_skb)
1064 if (hx->bch.rx_skb->len < 2) {
1065 pr_debug("%s: B%1d frame too short %d\n",
1066 hx->ip->name, hx->bch.nr, hx->bch.rx_skb->len);
1067 skb_trim(hx->bch.rx_skb, 0);
1069 skb_trim(hx->bch.rx_skb, hx->bch.rx_skb->len - 1);
1070 recv_Bchannel(&hx->bch, 0, false);
1075 ipac_irq(struct hscx_hw *hx, u8 ista)
1077 u8 istab, m, exirb = 0;
1079 if (hx->ip->type & IPAC_TYPE_IPACX)
1080 istab = ReadHSCX(hx, IPACX_ISTAB);
1081 else if (hx->ip->type & IPAC_TYPE_IPAC) {
1082 istab = ReadHSCX(hx, IPAC_ISTAB);
1083 m = (hx->bch.nr & 1) ? IPAC__EXA : IPAC__EXB;
1085 exirb = ReadHSCX(hx, IPAC_EXIRB);
1086 pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
1089 } else if (hx->bch.nr & 2) { /* HSCX B */
1090 if (ista & (HSCX__EXA | HSCX__ICA))
1091 ipac_irq(&hx->ip->hscx[0], ista);
1092 if (ista & HSCX__EXB) {
1093 exirb = ReadHSCX(hx, IPAC_EXIRB);
1094 pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
1097 istab = ista & 0xF8;
1098 } else { /* HSCX A */
1099 istab = ReadHSCX(hx, IPAC_ISTAB);
1100 if (ista & HSCX__EXA) {
1101 exirb = ReadHSCX(hx, IPAC_EXIRB);
1102 pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
1105 istab = istab & 0xF8;
1107 if (exirb & IPAC_B_XDU)
1108 istab |= IPACX_B_XDU;
1109 if (exirb & IPAC_B_RFO)
1110 istab |= IPACX_B_RFO;
1111 pr_debug("%s: B%1d ISTAB %02x\n", hx->ip->name, hx->bch.nr, istab);
1113 if (!test_bit(FLG_ACTIVE, &hx->bch.Flags))
1116 if (istab & IPACX_B_RME)
1119 if (istab & IPACX_B_RPF) {
1120 hscx_empty_fifo(hx, hx->fifo_size);
1121 if (test_bit(FLG_TRANSPARENT, &hx->bch.Flags))
1122 recv_Bchannel(&hx->bch, 0, false);
1125 if (istab & IPACX_B_RFO) {
1126 pr_debug("%s: B%1d RFO error\n", hx->ip->name, hx->bch.nr);
1127 hscx_cmdr(hx, 0x40); /* RRES */
1130 if (istab & IPACX_B_XPR)
1133 if (istab & IPACX_B_XDU) {
1134 if (test_bit(FLG_TRANSPARENT, &hx->bch.Flags)) {
1135 if (test_bit(FLG_FILLEMPTY, &hx->bch.Flags))
1136 test_and_set_bit(FLG_TX_EMPTY, &hx->bch.Flags);
1140 pr_debug("%s: B%1d XDU error at len %d\n", hx->ip->name,
1141 hx->bch.nr, hx->bch.tx_idx);
1143 hscx_cmdr(hx, 0x01); /* XRES */
1148 mISDNipac_irq(struct ipac_hw *ipac, int maxloop)
1150 int cnt = maxloop + 1;
1152 struct isac_hw *isac = &ipac->isac;
1154 if (ipac->type & IPAC_TYPE_IPACX) {
1155 ista = ReadIPAC(ipac, ISACX_ISTA);
1156 while (ista && --cnt) {
1157 pr_debug("%s: ISTA %02x\n", ipac->name, ista);
1158 if (ista & IPACX__ICA)
1159 ipac_irq(&ipac->hscx[0], ista);
1160 if (ista & IPACX__ICB)
1161 ipac_irq(&ipac->hscx[1], ista);
1162 if (ista & (ISACX__ICD | ISACX__CIC))
1163 mISDNisac_irq(&ipac->isac, ista);
1164 ista = ReadIPAC(ipac, ISACX_ISTA);
1166 } else if (ipac->type & IPAC_TYPE_IPAC) {
1167 ista = ReadIPAC(ipac, IPAC_ISTA);
1168 while (ista && --cnt) {
1169 pr_debug("%s: ISTA %02x\n", ipac->name, ista);
1170 if (ista & (IPAC__ICD | IPAC__EXD)) {
1171 istad = ReadISAC(isac, ISAC_ISTA);
1172 pr_debug("%s: ISTAD %02x\n", ipac->name, istad);
1173 if (istad & IPAC_D_TIN2)
1174 pr_debug("%s TIN2 irq\n", ipac->name);
1175 if (ista & IPAC__EXD)
1176 istad |= 1; /* ISAC EXI */
1177 mISDNisac_irq(isac, istad);
1179 if (ista & (IPAC__ICA | IPAC__EXA))
1180 ipac_irq(&ipac->hscx[0], ista);
1181 if (ista & (IPAC__ICB | IPAC__EXB))
1182 ipac_irq(&ipac->hscx[1], ista);
1183 ista = ReadIPAC(ipac, IPAC_ISTA);
1185 } else if (ipac->type & IPAC_TYPE_HSCX) {
1187 ista = ReadIPAC(ipac, IPAC_ISTAB + ipac->hscx[1].off);
1188 pr_debug("%s: B2 ISTA %02x\n", ipac->name, ista);
1190 ipac_irq(&ipac->hscx[1], ista);
1191 istad = ReadISAC(isac, ISAC_ISTA);
1192 pr_debug("%s: ISTAD %02x\n", ipac->name, istad);
1194 mISDNisac_irq(isac, istad);
1195 if (0 == (ista | istad))
1199 if (cnt > maxloop) /* only for ISAC/HSCX without PCI IRQ test */
1202 pr_debug("%s: %d irqloops cpu%d\n", ipac->name,
1203 maxloop - cnt, smp_processor_id());
1204 if (maxloop && !cnt)
1205 pr_notice("%s: %d IRQ LOOP cpu%d\n", ipac->name,
1206 maxloop, smp_processor_id());
1209 EXPORT_SYMBOL(mISDNipac_irq);
1212 hscx_mode(struct hscx_hw *hscx, u32 bprotocol)
1214 pr_debug("%s: HSCX %c protocol %x-->%x ch %d\n", hscx->ip->name,
1215 '@' + hscx->bch.nr, hscx->bch.state, bprotocol, hscx->bch.nr);
1216 if (hscx->ip->type & IPAC_TYPE_IPACX) {
1217 if (hscx->bch.nr & 1) { /* B1 and ICA */
1218 WriteIPAC(hscx->ip, ISACX_BCHA_TSDP_BC1, 0x80);
1219 WriteIPAC(hscx->ip, ISACX_BCHA_CR, 0x88);
1220 } else { /* B2 and ICB */
1221 WriteIPAC(hscx->ip, ISACX_BCHB_TSDP_BC1, 0x81);
1222 WriteIPAC(hscx->ip, ISACX_BCHB_CR, 0x88);
1224 switch (bprotocol) {
1225 case ISDN_P_NONE: /* init */
1226 WriteHSCX(hscx, IPACX_MODEB, 0xC0); /* rec off */
1227 WriteHSCX(hscx, IPACX_EXMB, 0x30); /* std adj. */
1228 WriteHSCX(hscx, IPACX_MASKB, 0xFF); /* ints off */
1229 hscx_cmdr(hscx, 0x41);
1230 test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
1231 test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1234 WriteHSCX(hscx, IPACX_MODEB, 0x88); /* ex trans */
1235 WriteHSCX(hscx, IPACX_EXMB, 0x00); /* trans */
1236 hscx_cmdr(hscx, 0x41);
1237 WriteHSCX(hscx, IPACX_MASKB, IPACX_B_ON);
1238 test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1241 WriteHSCX(hscx, IPACX_MODEB, 0xC0); /* trans */
1242 WriteHSCX(hscx, IPACX_EXMB, 0x00); /* hdlc,crc */
1243 hscx_cmdr(hscx, 0x41);
1244 WriteHSCX(hscx, IPACX_MASKB, IPACX_B_ON);
1245 test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
1248 pr_info("%s: protocol not known %x\n", hscx->ip->name,
1250 return -ENOPROTOOPT;
1252 } else if (hscx->ip->type & IPAC_TYPE_IPAC) { /* IPAC */
1253 WriteHSCX(hscx, IPAC_CCR1, 0x82);
1254 WriteHSCX(hscx, IPAC_CCR2, 0x30);
1255 WriteHSCX(hscx, IPAC_XCCR, 0x07);
1256 WriteHSCX(hscx, IPAC_RCCR, 0x07);
1257 WriteHSCX(hscx, IPAC_TSAX, hscx->slot);
1258 WriteHSCX(hscx, IPAC_TSAR, hscx->slot);
1259 switch (bprotocol) {
1261 WriteHSCX(hscx, IPAC_TSAX, 0x1F);
1262 WriteHSCX(hscx, IPAC_TSAR, 0x1F);
1263 WriteHSCX(hscx, IPAC_MODEB, 0x84);
1264 WriteHSCX(hscx, IPAC_CCR1, 0x82);
1265 WriteHSCX(hscx, IPAC_MASKB, 0xFF); /* ints off */
1266 test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
1267 test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1270 WriteHSCX(hscx, IPAC_MODEB, 0xe4); /* ex trans */
1271 WriteHSCX(hscx, IPAC_CCR1, 0x82);
1272 hscx_cmdr(hscx, 0x41);
1273 WriteHSCX(hscx, IPAC_MASKB, 0);
1274 test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1277 WriteHSCX(hscx, IPAC_MODEB, 0x8c);
1278 WriteHSCX(hscx, IPAC_CCR1, 0x8a);
1279 hscx_cmdr(hscx, 0x41);
1280 WriteHSCX(hscx, IPAC_MASKB, 0);
1281 test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
1284 pr_info("%s: protocol not known %x\n", hscx->ip->name,
1286 return -ENOPROTOOPT;
1288 } else if (hscx->ip->type & IPAC_TYPE_HSCX) { /* HSCX */
1289 WriteHSCX(hscx, IPAC_CCR1, 0x85);
1290 WriteHSCX(hscx, IPAC_CCR2, 0x30);
1291 WriteHSCX(hscx, IPAC_XCCR, 0x07);
1292 WriteHSCX(hscx, IPAC_RCCR, 0x07);
1293 WriteHSCX(hscx, IPAC_TSAX, hscx->slot);
1294 WriteHSCX(hscx, IPAC_TSAR, hscx->slot);
1295 switch (bprotocol) {
1297 WriteHSCX(hscx, IPAC_TSAX, 0x1F);
1298 WriteHSCX(hscx, IPAC_TSAR, 0x1F);
1299 WriteHSCX(hscx, IPAC_MODEB, 0x84);
1300 WriteHSCX(hscx, IPAC_CCR1, 0x85);
1301 WriteHSCX(hscx, IPAC_MASKB, 0xFF); /* ints off */
1302 test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
1303 test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1306 WriteHSCX(hscx, IPAC_MODEB, 0xe4); /* ex trans */
1307 WriteHSCX(hscx, IPAC_CCR1, 0x85);
1308 hscx_cmdr(hscx, 0x41);
1309 WriteHSCX(hscx, IPAC_MASKB, 0);
1310 test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
1313 WriteHSCX(hscx, IPAC_MODEB, 0x8c);
1314 WriteHSCX(hscx, IPAC_CCR1, 0x8d);
1315 hscx_cmdr(hscx, 0x41);
1316 WriteHSCX(hscx, IPAC_MASKB, 0);
1317 test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
1320 pr_info("%s: protocol not known %x\n", hscx->ip->name,
1322 return -ENOPROTOOPT;
1326 hscx->bch.state = bprotocol;
1331 hscx_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)
1333 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1334 struct hscx_hw *hx = container_of(bch, struct hscx_hw, bch);
1336 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1337 unsigned long flags;
1341 spin_lock_irqsave(hx->ip->hwlock, flags);
1342 ret = bchannel_senddata(bch, skb);
1343 if (ret > 0) { /* direct TX */
1347 spin_unlock_irqrestore(hx->ip->hwlock, flags);
1349 case PH_ACTIVATE_REQ:
1350 spin_lock_irqsave(hx->ip->hwlock, flags);
1351 if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
1352 ret = hscx_mode(hx, ch->protocol);
1355 spin_unlock_irqrestore(hx->ip->hwlock, flags);
1357 _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
1360 case PH_DEACTIVATE_REQ:
1361 spin_lock_irqsave(hx->ip->hwlock, flags);
1362 mISDN_clear_bchannel(bch);
1363 hscx_mode(hx, ISDN_P_NONE);
1364 spin_unlock_irqrestore(hx->ip->hwlock, flags);
1365 _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
1370 pr_info("%s: %s unknown prim(%x,%x)\n",
1371 hx->ip->name, __func__, hh->prim, hh->id);
1380 channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
1382 return mISDN_ctrl_bchannel(bch, cq);
1386 hscx_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1388 struct bchannel *bch = container_of(ch, struct bchannel, ch);
1389 struct hscx_hw *hx = container_of(bch, struct hscx_hw, bch);
1393 pr_debug("%s: %s cmd:%x %p\n", hx->ip->name, __func__, cmd, arg);
1396 test_and_clear_bit(FLG_OPEN, &bch->Flags);
1397 cancel_work_sync(&bch->workq);
1398 spin_lock_irqsave(hx->ip->hwlock, flags);
1399 mISDN_clear_bchannel(bch);
1400 hscx_mode(hx, ISDN_P_NONE);
1401 spin_unlock_irqrestore(hx->ip->hwlock, flags);
1402 ch->protocol = ISDN_P_NONE;
1404 module_put(hx->ip->owner);
1407 case CONTROL_CHANNEL:
1408 ret = channel_bctrl(bch, arg);
1411 pr_info("%s: %s unknown prim(%x)\n",
1412 hx->ip->name, __func__, cmd);
1418 free_ipac(struct ipac_hw *ipac)
1420 isac_release(&ipac->isac);
1423 static const char *HSCXVer[] =
1424 {"A1", "?1", "A2", "?3", "A3", "V2.1", "?6", "?7",
1425 "?8", "?9", "?10", "?11", "?12", "?13", "?14", "???"};
1430 hscx_init(struct hscx_hw *hx)
1434 WriteHSCX(hx, IPAC_RAH2, 0xFF);
1435 WriteHSCX(hx, IPAC_XBCH, 0x00);
1436 WriteHSCX(hx, IPAC_RLCR, 0x00);
1438 if (hx->ip->type & IPAC_TYPE_HSCX) {
1439 WriteHSCX(hx, IPAC_CCR1, 0x85);
1440 val = ReadHSCX(hx, HSCX_VSTR);
1441 pr_debug("%s: HSCX VSTR %02x\n", hx->ip->name, val);
1442 if (hx->bch.debug & DEBUG_HW)
1443 pr_notice("%s: HSCX version %s\n", hx->ip->name,
1444 HSCXVer[val & 0x0f]);
1446 WriteHSCX(hx, IPAC_CCR1, 0x82);
1447 WriteHSCX(hx, IPAC_CCR2, 0x30);
1448 WriteHSCX(hx, IPAC_XCCR, 0x07);
1449 WriteHSCX(hx, IPAC_RCCR, 0x07);
1453 ipac_init(struct ipac_hw *ipac)
1457 if (ipac->type & IPAC_TYPE_HSCX) {
1458 hscx_init(&ipac->hscx[0]);
1459 hscx_init(&ipac->hscx[1]);
1460 val = ReadIPAC(ipac, IPAC_ID);
1461 } else if (ipac->type & IPAC_TYPE_IPAC) {
1462 hscx_init(&ipac->hscx[0]);
1463 hscx_init(&ipac->hscx[1]);
1464 WriteIPAC(ipac, IPAC_MASK, IPAC__ON);
1465 val = ReadIPAC(ipac, IPAC_CONF);
1466 /* conf is default 0, but can be overwritten by card setup */
1467 pr_debug("%s: IPAC CONF %02x/%02x\n", ipac->name,
1469 WriteIPAC(ipac, IPAC_CONF, ipac->conf);
1470 val = ReadIPAC(ipac, IPAC_ID);
1471 if (ipac->hscx[0].bch.debug & DEBUG_HW)
1472 pr_notice("%s: IPAC Design ID %02x\n", ipac->name, val);
1474 /* nothing special for IPACX to do here */
1475 return isac_init(&ipac->isac);
1479 open_bchannel(struct ipac_hw *ipac, struct channel_req *rq)
1481 struct bchannel *bch;
1483 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1485 if (rq->protocol == ISDN_P_NONE)
1487 bch = &ipac->hscx[rq->adr.channel - 1].bch;
1488 if (test_and_set_bit(FLG_OPEN, &bch->Flags))
1489 return -EBUSY; /* b-channel can be only open once */
1490 test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
1491 bch->ch.protocol = rq->protocol;
1497 channel_ctrl(struct ipac_hw *ipac, struct mISDN_ctrl_req *cq)
1502 case MISDN_CTRL_GETOP:
1503 cq->op = MISDN_CTRL_LOOP | MISDN_CTRL_L1_TIMER3;
1505 case MISDN_CTRL_LOOP:
1506 /* cq->channel: 0 disable, 1 B1 loop 2 B2 loop, 3 both */
1507 if (cq->channel < 0 || cq->channel > 3) {
1511 ret = ipac->ctrl(ipac, HW_TESTLOOP, cq->channel);
1513 case MISDN_CTRL_L1_TIMER3:
1514 ret = ipac->isac.ctrl(&ipac->isac, HW_TIMER3_VALUE, cq->p1);
1517 pr_info("%s: unknown CTRL OP %x\n", ipac->name, cq->op);
1525 ipac_dctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
1527 struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
1528 struct dchannel *dch = container_of(dev, struct dchannel, dev);
1529 struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
1530 struct ipac_hw *ipac = container_of(isac, struct ipac_hw, isac);
1531 struct channel_req *rq;
1534 pr_debug("%s: DCTRL: %x %p\n", ipac->name, cmd, arg);
1538 if (rq->protocol == ISDN_P_TE_S0)
1539 err = open_dchannel_caller(isac, rq, __builtin_return_address(0));
1541 err = open_bchannel(ipac, rq);
1544 if (!try_module_get(ipac->owner))
1545 pr_info("%s: cannot get module\n", ipac->name);
1548 pr_debug("%s: dev(%d) close from %p\n", ipac->name,
1549 dch->dev.id, __builtin_return_address(0));
1550 module_put(ipac->owner);
1552 case CONTROL_CHANNEL:
1553 err = channel_ctrl(ipac, arg);
1556 pr_debug("%s: unknown DCTRL command %x\n", ipac->name, cmd);
1563 mISDNipac_init(struct ipac_hw *ipac, void *hw)
1569 if (ipac->isac.dch.debug & DEBUG_HW)
1570 pr_notice("%s: ipac type %x\n", ipac->name, ipac->type);
1571 if (ipac->type & IPAC_TYPE_HSCX) {
1572 ipac->isac.type = IPAC_TYPE_ISAC;
1573 ipac->hscx[0].off = 0;
1574 ipac->hscx[1].off = 0x40;
1575 ipac->hscx[0].fifo_size = 32;
1576 ipac->hscx[1].fifo_size = 32;
1577 } else if (ipac->type & IPAC_TYPE_IPAC) {
1578 ipac->isac.type = IPAC_TYPE_IPAC | IPAC_TYPE_ISAC;
1579 ipac->hscx[0].off = 0;
1580 ipac->hscx[1].off = 0x40;
1581 ipac->hscx[0].fifo_size = 64;
1582 ipac->hscx[1].fifo_size = 64;
1583 } else if (ipac->type & IPAC_TYPE_IPACX) {
1584 ipac->isac.type = IPAC_TYPE_IPACX | IPAC_TYPE_ISACX;
1585 ipac->hscx[0].off = IPACX_OFF_ICA;
1586 ipac->hscx[1].off = IPACX_OFF_ICB;
1587 ipac->hscx[0].fifo_size = 64;
1588 ipac->hscx[1].fifo_size = 64;
1592 mISDNisac_init(&ipac->isac, hw);
1594 ipac->isac.dch.dev.D.ctrl = ipac_dctrl;
1596 for (i = 0; i < 2; i++) {
1597 ipac->hscx[i].bch.nr = i + 1;
1598 set_channelmap(i + 1, ipac->isac.dch.dev.channelmap);
1599 list_add(&ipac->hscx[i].bch.ch.list,
1600 &ipac->isac.dch.dev.bchannels);
1601 mISDN_initbchannel(&ipac->hscx[i].bch, MAX_DATA_MEM,
1602 ipac->hscx[i].fifo_size);
1603 ipac->hscx[i].bch.ch.nr = i + 1;
1604 ipac->hscx[i].bch.ch.send = &hscx_l2l1;
1605 ipac->hscx[i].bch.ch.ctrl = hscx_bctrl;
1606 ipac->hscx[i].bch.hw = hw;
1607 ipac->hscx[i].ip = ipac;
1608 /* default values for IOM time slots
1609 * can be overwritten by card */
1610 ipac->hscx[i].slot = (i == 0) ? 0x2f : 0x03;
1613 ipac->init = ipac_init;
1614 ipac->release = free_ipac;
1616 ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
1617 (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
1620 EXPORT_SYMBOL(mISDNipac_init);
1625 pr_notice("mISDNipac module version %s\n", ISAC_REV);
1630 isac_mod_cleanup(void)
1632 pr_notice("mISDNipac module unloaded\n");
1634 module_init(isac_mod_init);
1635 module_exit(isac_mod_cleanup);