2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 /*---------------------------------------------------------------------------
28 * i4b_isac.c - i4b siemens isdn chipset driver ISAC handler
29 * ---------------------------------------------------------
30 * last edit-date: [Wed Jan 24 09:10:36 2001]
32 *---------------------------------------------------------------------------*/
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/socket.h>
46 #include <i4b/include/i4b_debug.h>
47 #include <i4b/include/i4b_ioctl.h>
48 #include <i4b/include/i4b_trace.h>
50 #include <i4b/layer1/i4b_l1.h>
52 #include <i4b/layer1/isic/i4b_isic.h>
53 #include <i4b/layer1/isic/i4b_isac.h>
54 #include <i4b/layer1/isic/i4b_hscx.h>
56 #include <i4b/include/i4b_global.h>
57 #include <i4b/include/i4b_mbuf.h>
59 static u_char isic_isac_exir_hdlr(register struct l1_softc *sc, u_char exir);
60 static void isic_isac_ind_hdlr(register struct l1_softc *sc, int ind);
62 /*---------------------------------------------------------------------------*
63 * ISAC interrupt service routine
64 *---------------------------------------------------------------------------*/
66 isic_isac_irq(struct l1_softc *sc, int ista)
68 register u_char c = 0;
69 NDBGL1(L1_F_MSG, "unit %d: ista = 0x%02x", sc->sc_unit, ista);
71 if(ista & ISAC_ISTA_EXI) /* extended interrupt */
73 c |= isic_isac_exir_hdlr(sc, ISAC_READ(I_EXIR));
76 if(ista & ISAC_ISTA_RME) /* receive message end */
81 /* get rx status register */
83 rsta = ISAC_READ(I_RSTA);
85 if((rsta & ISAC_RSTA_MASK) != 0x20)
89 if(!(rsta & ISAC_RSTA_CRC)) /* CRC error */
92 NDBGL1(L1_I_ERR, "unit %d: CRC error", sc->sc_unit);
95 if(rsta & ISAC_RSTA_RDO) /* ReceiveDataOverflow */
98 NDBGL1(L1_I_ERR, "unit %d: Data Overrun error", sc->sc_unit);
101 if(rsta & ISAC_RSTA_RAB) /* ReceiveABorted */
104 NDBGL1(L1_I_ERR, "unit %d: Receive Aborted error", sc->sc_unit);
108 NDBGL1(L1_I_ERR, "unit %d: RME unknown error, RSTA = 0x%02x!", sc->sc_unit, rsta);
110 i4b_Dfreembuf(sc->sc_ibuf);
112 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
118 ISAC_WRITE(I_CMDR, ISAC_CMDR_RMC|ISAC_CMDR_RRES);
124 rest = (ISAC_READ(I_RBCL) & (ISAC_FIFO_LEN-1));
127 rest = ISAC_FIFO_LEN;
129 if(sc->sc_ibuf == NULL)
131 if((sc->sc_ibuf = i4b_Dgetmbuf(rest)) != NULL)
132 sc->sc_ib = sc->sc_ibuf->m_data;
134 panic("isic_isac_irq: RME, i4b_Dgetmbuf returns NULL!\n");
138 if(sc->sc_ilen <= (MAX_DFRAME_LEN - rest))
140 ISAC_RDFIFO(sc->sc_ib, rest);
143 sc->sc_ibuf->m_pkthdr.len =
144 sc->sc_ibuf->m_len = sc->sc_ilen;
146 if(sc->sc_trace & TRACE_D_RX)
149 hdr.unit = L0ISICUNIT(sc->sc_unit);
152 hdr.count = ++sc->sc_trace_dcount;
154 i4b_l1_trace_ind(&hdr, sc->sc_ibuf->m_len, sc->sc_ibuf->m_data);
160 (ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S))
162 i4b_l1_ph_data_ind(L0ISICUNIT(sc->sc_unit), sc->sc_ibuf);
166 i4b_Dfreembuf(sc->sc_ibuf);
171 NDBGL1(L1_I_ERR, "RME, input buffer overflow!");
172 i4b_Dfreembuf(sc->sc_ibuf);
173 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
181 if(ista & ISAC_ISTA_RPF) /* receive fifo full */
183 if(sc->sc_ibuf == NULL)
185 if((sc->sc_ibuf = i4b_Dgetmbuf(MAX_DFRAME_LEN)) != NULL)
186 sc->sc_ib= sc->sc_ibuf->m_data;
188 panic("isic_isac_irq: RPF, i4b_Dgetmbuf returns NULL!\n");
192 if(sc->sc_ilen <= (MAX_DFRAME_LEN - ISAC_FIFO_LEN))
194 ISAC_RDFIFO(sc->sc_ib, ISAC_FIFO_LEN);
195 sc->sc_ilen += ISAC_FIFO_LEN;
196 sc->sc_ib += ISAC_FIFO_LEN;
201 NDBGL1(L1_I_ERR, "RPF, input buffer overflow!");
202 i4b_Dfreembuf(sc->sc_ibuf);
206 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
210 if(ista & ISAC_ISTA_XPR) /* transmit fifo empty (XPR bit set) */
212 if((sc->sc_obuf2 != NULL) && (sc->sc_obuf == NULL))
214 sc->sc_freeflag = sc->sc_freeflag2;
215 sc->sc_obuf = sc->sc_obuf2;
216 sc->sc_op = sc->sc_obuf->m_data;
217 sc->sc_ol = sc->sc_obuf->m_len;
220 printf("ob2=%x, op=%x, ol=%d, f=%d #",
230 printf("ob=%x, op=%x, ol=%d, f=%d #",
240 ISAC_WRFIFO(sc->sc_op, min(sc->sc_ol, ISAC_FIFO_LEN));
242 if(sc->sc_ol > ISAC_FIFO_LEN) /* length > 32 ? */
244 sc->sc_op += ISAC_FIFO_LEN; /* bufferptr+32 */
245 sc->sc_ol -= ISAC_FIFO_LEN; /* length - 32 */
246 c |= ISAC_CMDR_XTF; /* set XTF bit */
252 i4b_Dfreembuf(sc->sc_obuf);
259 c |= ISAC_CMDR_XTF | ISAC_CMDR_XME;
264 sc->sc_state &= ~ISAC_TX_ACTIVE;
268 if(ista & ISAC_ISTA_CISQ) /* channel status change CISQ */
272 /* get command/indication rx register*/
274 ci = ISAC_READ(I_CIRR);
276 /* if S/Q IRQ, read SQC reg to clr SQC IRQ */
278 if(ci & ISAC_CIRR_SQC)
279 (void) ISAC_READ(I_SQRR);
281 /* C/I code change IRQ (flag already cleared by CIRR read) */
283 if(ci & ISAC_CIRR_CIC0)
284 isic_isac_ind_hdlr(sc, (ci >> 2) & 0xf);
289 ISAC_WRITE(I_CMDR, c);
294 /*---------------------------------------------------------------------------*
295 * ISAC L1 Extended IRQ handler
296 *---------------------------------------------------------------------------*/
298 isic_isac_exir_hdlr(register struct l1_softc *sc, u_char exir)
302 if(exir & ISAC_EXIR_XMR)
304 NDBGL1(L1_I_ERR, "EXIRQ Tx Message Repeat");
309 if(exir & ISAC_EXIR_XDU)
311 NDBGL1(L1_I_ERR, "EXIRQ Tx Data Underrun");
316 if(exir & ISAC_EXIR_PCE)
318 NDBGL1(L1_I_ERR, "EXIRQ Protocol Error");
321 if(exir & ISAC_EXIR_RFO)
323 NDBGL1(L1_I_ERR, "EXIRQ Rx Frame Overflow");
325 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
328 if(exir & ISAC_EXIR_SOV)
330 NDBGL1(L1_I_ERR, "EXIRQ Sync Xfer Overflow");
333 if(exir & ISAC_EXIR_MOS)
335 NDBGL1(L1_I_ERR, "EXIRQ Monitor Status");
338 if(exir & ISAC_EXIR_SAW)
340 /* cannot happen, STCR:TSF is set to 0 */
342 NDBGL1(L1_I_ERR, "EXIRQ Subscriber Awake");
345 if(exir & ISAC_EXIR_WOV)
347 /* cannot happen, STCR:TSF is set to 0 */
349 NDBGL1(L1_I_ERR, "EXIRQ Watchdog Timer Overflow");
355 /*---------------------------------------------------------------------------*
356 * ISAC L1 Indication handler
357 *---------------------------------------------------------------------------*/
359 isic_isac_ind_hdlr(register struct l1_softc *sc, int ind)
366 NDBGL1(L1_I_CICO, "rx AI8 in state %s", isic_printstate(sc));
367 if(sc->sc_bustyp == BUS_TYPE_IOM2)
368 isic_isac_l1_cmd(sc, CMD_AR8);
370 i4b_l1_mph_status_ind(L0ISICUNIT(sc->sc_unit), STI_L1STAT, LAYER_ACTIVE, NULL);
373 case ISAC_CIRR_IAI10:
374 NDBGL1(L1_I_CICO, "rx AI10 in state %s", isic_printstate(sc));
375 if(sc->sc_bustyp == BUS_TYPE_IOM2)
376 isic_isac_l1_cmd(sc, CMD_AR10);
378 i4b_l1_mph_status_ind(L0ISICUNIT(sc->sc_unit), STI_L1STAT, LAYER_ACTIVE, NULL);
382 NDBGL1(L1_I_CICO, "rx RSY in state %s", isic_printstate(sc));
387 NDBGL1(L1_I_CICO, "rx PU in state %s", isic_printstate(sc));
392 NDBGL1(L1_I_CICO, "rx DR in state %s", isic_printstate(sc));
393 isic_isac_l1_cmd(sc, CMD_DIU);
398 NDBGL1(L1_I_CICO, "rx DID in state %s", isic_printstate(sc));
400 i4b_l1_mph_status_ind(L0ISICUNIT(sc->sc_unit), STI_L1STAT, LAYER_IDLE, NULL);
404 NDBGL1(L1_I_CICO, "rx DIS in state %s", isic_printstate(sc));
409 NDBGL1(L1_I_CICO, "rx EI in state %s", isic_printstate(sc));
410 isic_isac_l1_cmd(sc, CMD_DIU);
415 NDBGL1(L1_I_CICO, "rx ARD in state %s", isic_printstate(sc));
420 NDBGL1(L1_I_CICO, "rx TI in state %s", isic_printstate(sc));
425 NDBGL1(L1_I_CICO, "rx ATI in state %s", isic_printstate(sc));
430 NDBGL1(L1_I_CICO, "rx SD in state %s", isic_printstate(sc));
435 NDBGL1(L1_I_ERR, "UNKNOWN Indication 0x%x in state %s", ind, isic_printstate(sc));
439 isic_next_state(sc, event);
442 /*---------------------------------------------------------------------------*
443 * execute a layer 1 command
444 *---------------------------------------------------------------------------*/
446 isic_isac_l1_cmd(struct l1_softc *sc, int command)
450 #ifdef I4B_SMP_WORKAROUND
452 /* XXXXXXXXXXXXXXXXXXX */
455 * patch from Wolfgang Helbig:
457 * Here is a patch that makes i4b work on an SMP:
458 * The card (TELES 16.3) didn't interrupt on an SMP machine.
459 * This is a gross workaround, but anyway it works *and* provides
460 * some information as how to finally fix this problem.
463 HSCX_WRITE(0, H_MASK, 0xff);
464 HSCX_WRITE(1, H_MASK, 0xff);
465 ISAC_WRITE(I_MASK, 0xff);
467 HSCX_WRITE(0, H_MASK, HSCX_A_IMASK);
468 HSCX_WRITE(1, H_MASK, HSCX_B_IMASK);
469 ISAC_WRITE(I_MASK, ISAC_IMASK);
471 /* XXXXXXXXXXXXXXXXXXX */
473 #endif /* I4B_SMP_WORKAROUND */
475 if(command < 0 || command > CMD_ILL)
477 NDBGL1(L1_I_ERR, "illegal cmd 0x%x in state %s", command, isic_printstate(sc));
481 if(sc->sc_bustyp == BUS_TYPE_IOM2)
489 NDBGL1(L1_I_CICO, "tx TIM in state %s", isic_printstate(sc));
490 cmd |= (ISAC_CIXR_CTIM << 2);
494 NDBGL1(L1_I_CICO, "tx RS in state %s", isic_printstate(sc));
495 cmd |= (ISAC_CIXR_CRS << 2);
499 NDBGL1(L1_I_CICO, "tx AR8 in state %s", isic_printstate(sc));
500 cmd |= (ISAC_CIXR_CAR8 << 2);
504 NDBGL1(L1_I_CICO, "tx AR10 in state %s", isic_printstate(sc));
505 cmd |= (ISAC_CIXR_CAR10 << 2);
509 NDBGL1(L1_I_CICO, "tx DIU in state %s", isic_printstate(sc));
510 cmd |= (ISAC_CIXR_CDIU << 2);
513 ISAC_WRITE(I_CIXR, cmd);
516 /*---------------------------------------------------------------------------*
517 * L1 ISAC initialization
518 *---------------------------------------------------------------------------*/
520 isic_isac_init(struct l1_softc *sc)
522 ISAC_IMASK = 0xff; /* disable all irqs */
524 ISAC_WRITE(I_MASK, ISAC_IMASK);
526 if(sc->sc_bustyp != BUS_TYPE_IOM2)
528 NDBGL1(L1_I_SETUP, "configuring for IOM-1 mode");
530 /* ADF2: Select mode IOM-1 */
531 ISAC_WRITE(I_ADF2, 0x00);
533 /* SPCR: serial port control register:
534 * SPU - software power up = 0
535 * SAC - SIP port high Z
536 * SPM - timing mode 0
537 * TLP - test loop = 0
538 * C1C, C2C - B1 and B2 switched to/from SPa
540 ISAC_WRITE(I_SPCR, ISAC_SPCR_C1C1|ISAC_SPCR_C2C1);
542 /* SQXR: S/Q channel xmit register:
543 * SQIE - S/Q IRQ enable = 0
544 * SQX1-4 - Fa bits = 1
546 ISAC_WRITE(I_SQXR, ISAC_SQXR_SQX1|ISAC_SQXR_SQX2|ISAC_SQXR_SQX3|ISAC_SQXR_SQX4);
548 /* ADF1: additional feature reg 1:
550 * TEM - test mode = 0
551 * PFS - pre-filter = 0
552 * CFS - IOM clock/frame always active
553 * FSC1/2 - polarity of 8kHz strobe
554 * ITF - interframe fill = idle
556 ISAC_WRITE(I_ADF1, ISAC_ADF1_FC2); /* ADF1 */
558 /* STCR: sync transfer control reg:
559 * TSF - terminal secific functions = 0
560 * TBA - TIC bus address = 7
563 ISAC_WRITE(I_STCR, ISAC_STCR_TBA2|ISAC_STCR_TBA1|ISAC_STCR_TBA0);
565 /* MODE: Mode Register:
566 * MDSx - transparent mode 2
567 * TMD - timer mode = external
568 * RAC - Receiver enabled
569 * DIMx - digital i/f mode
571 ISAC_WRITE(I_MODE, ISAC_MODE_MDS2|ISAC_MODE_MDS1|ISAC_MODE_RAC|ISAC_MODE_DIM0);
575 NDBGL1(L1_I_SETUP, "configuring for IOM-2 mode");
577 /* ADF2: Select mode IOM-2 */
578 ISAC_WRITE(I_ADF2, ISAC_ADF2_IMS);
580 /* SPCR: serial port control register:
581 * SPU - software power up = 0
582 * SPM - timing mode 0
583 * TLP - test loop = 0
584 * C1C, C2C - B1 + C1 and B2 + IC2 monitoring
586 ISAC_WRITE(I_SPCR, 0x00);
588 /* SQXR: S/Q channel xmit register:
589 * IDC - IOM direction = 0 (master)
590 * CFS - Config Select = 0 (clock always active)
591 * CI1E - C/I channel 1 IRQ enable = 0
592 * SQIE - S/Q IRQ enable = 0
593 * SQX1-4 - Fa bits = 1
595 ISAC_WRITE(I_SQXR, ISAC_SQXR_SQX1|ISAC_SQXR_SQX2|ISAC_SQXR_SQX3|ISAC_SQXR_SQX4);
597 /* ADF1: additional feature reg 1:
599 * TEM - test mode = 0
600 * PFS - pre-filter = 0
601 * IOF - IOM i/f off = 0
602 * ITF - interframe fill = idle
604 ISAC_WRITE(I_ADF1, 0x00);
606 /* STCR: sync transfer control reg:
607 * TSF - terminal secific functions = 0
608 * TBA - TIC bus address = 7
611 ISAC_WRITE(I_STCR, ISAC_STCR_TBA2|ISAC_STCR_TBA1|ISAC_STCR_TBA0);
613 /* MODE: Mode Register:
614 * MDSx - transparent mode 2
615 * TMD - timer mode = external
616 * RAC - Receiver enabled
617 * DIMx - digital i/f mode
619 ISAC_WRITE(I_MODE, ISAC_MODE_MDS2|ISAC_MODE_MDS1|ISAC_MODE_RAC|ISAC_MODE_DIM0);
624 * XXX a transmitter reset causes an ISAC tx IRQ which will not
625 * be serviced at attach time under some circumstances leaving
626 * the associated IRQ line on the ISA bus active. This prevents
627 * any further interrupts to be serviced because no low -> high
628 * transition can take place anymore. (-hm)
632 * RRES - HDLC receiver reset
633 * XRES - transmitter reset
635 ISAC_WRITE(I_CMDR, ISAC_CMDR_RRES|ISAC_CMDR_XRES);
639 /* enabled interrupts:
640 * ===================
641 * RME - receive message end
642 * RPF - receive pool full
643 * XPR - transmit pool ready
644 * CISQ - CI or S/Q channel change
645 * EXI - extended interrupt
648 ISAC_IMASK = ISAC_MASK_RSC | /* auto mode only */
649 ISAC_MASK_TIN | /* timer irq */
650 ISAC_MASK_SIN; /* sync xfer irq */
652 ISAC_WRITE(I_MASK, ISAC_IMASK);