2 * Copyright (c) 1997, 2000 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_ifpi_isac.c - i4b Fritz PCI ISAC handler
29 * --------------------------------------------
30 * $Id: i4b_ifpi_isac.c,v 1.3 2000/05/29 15:41:41 hm Exp $
31 * last edit-date: [Mon May 29 15:22:52 2000]
33 *---------------------------------------------------------------------------*/
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/socket.h>
47 #include <i4b/include/i4b_debug.h>
48 #include <i4b/include/i4b_ioctl.h>
49 #include <i4b/include/i4b_trace.h>
51 #include <i4b/layer1/i4b_l1.h>
53 #include <i4b/layer1/isic/i4b_isic.h>
54 #include <i4b/layer1/isic/i4b_isac.h>
55 #include <i4b/layer1/isic/i4b_hscx.h>
57 #include <i4b/layer1/ifpi/i4b_ifpi_ext.h>
59 #include <i4b/include/i4b_global.h>
60 #include <i4b/include/i4b_mbuf.h>
62 static u_char ifpi_isac_exir_hdlr(register struct l1_softc *sc, u_char exir);
63 static void ifpi_isac_ind_hdlr(register struct l1_softc *sc, int ind);
65 /*---------------------------------------------------------------------------*
66 * ISAC interrupt service routine
67 *---------------------------------------------------------------------------*/
69 ifpi_isac_irq(struct l1_softc *sc, int ista)
71 register u_char c = 0;
72 NDBGL1(L1_F_MSG, "unit %d: ista = 0x%02x", sc->sc_unit, ista);
74 if(ista & ISAC_ISTA_EXI) /* extended interrupt */
76 c |= ifpi_isac_exir_hdlr(sc, ISAC_READ(I_EXIR));
79 if(ista & ISAC_ISTA_RME) /* receive message end */
84 /* get rx status register */
86 rsta = ISAC_READ(I_RSTA);
88 if((rsta & ISAC_RSTA_MASK) != 0x20)
92 if(!(rsta & ISAC_RSTA_CRC)) /* CRC error */
95 NDBGL1(L1_I_ERR, "unit %d: CRC error", sc->sc_unit);
98 if(rsta & ISAC_RSTA_RDO) /* ReceiveDataOverflow */
101 NDBGL1(L1_I_ERR, "unit %d: Data Overrun error", sc->sc_unit);
104 if(rsta & ISAC_RSTA_RAB) /* ReceiveABorted */
107 NDBGL1(L1_I_ERR, "unit %d: Receive Aborted error", sc->sc_unit);
111 NDBGL1(L1_I_ERR, "unit %d: RME unknown error, RSTA = 0x%02x!", sc->sc_unit, rsta);
113 i4b_Dfreembuf(sc->sc_ibuf);
115 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
121 ISAC_WRITE(I_CMDR, ISAC_CMDR_RMC|ISAC_CMDR_RRES);
127 rest = (ISAC_READ(I_RBCL) & (ISAC_FIFO_LEN-1));
130 rest = ISAC_FIFO_LEN;
132 if(sc->sc_ibuf == NULL)
134 if((sc->sc_ibuf = i4b_Dgetmbuf(rest)) != NULL)
135 sc->sc_ib = sc->sc_ibuf->m_data;
137 panic("ifpi_isac_irq: RME, i4b_Dgetmbuf returns NULL!\n");
141 if(sc->sc_ilen <= (MAX_DFRAME_LEN - rest))
143 ISAC_RDFIFO(sc->sc_ib, rest);
146 sc->sc_ibuf->m_pkthdr.len =
147 sc->sc_ibuf->m_len = sc->sc_ilen;
149 if(sc->sc_trace & TRACE_D_RX)
152 hdr.unit = L0IFPIUNIT(sc->sc_unit);
155 hdr.count = ++sc->sc_trace_dcount;
157 i4b_l1_trace_ind(&hdr, sc->sc_ibuf->m_len, sc->sc_ibuf->m_data);
163 (ctrl_desc[sc->sc_unit].protocol != PROTOCOL_D64S))
165 i4b_l1_ph_data_ind(L0IFPIUNIT(sc->sc_unit), sc->sc_ibuf);
169 i4b_Dfreembuf(sc->sc_ibuf);
174 NDBGL1(L1_I_ERR, "RME, input buffer overflow!");
175 i4b_Dfreembuf(sc->sc_ibuf);
176 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
184 if(ista & ISAC_ISTA_RPF) /* receive fifo full */
186 if(sc->sc_ibuf == NULL)
188 if((sc->sc_ibuf = i4b_Dgetmbuf(MAX_DFRAME_LEN)) != NULL)
189 sc->sc_ib= sc->sc_ibuf->m_data;
191 panic("ifpi_isac_irq: RPF, i4b_Dgetmbuf returns NULL!\n");
195 if(sc->sc_ilen <= (MAX_DFRAME_LEN - ISAC_FIFO_LEN))
197 ISAC_RDFIFO(sc->sc_ib, ISAC_FIFO_LEN);
198 sc->sc_ilen += ISAC_FIFO_LEN;
199 sc->sc_ib += ISAC_FIFO_LEN;
204 NDBGL1(L1_I_ERR, "RPF, input buffer overflow!");
205 i4b_Dfreembuf(sc->sc_ibuf);
209 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
213 if(ista & ISAC_ISTA_XPR) /* transmit fifo empty (XPR bit set) */
215 if((sc->sc_obuf2 != NULL) && (sc->sc_obuf == NULL))
217 sc->sc_freeflag = sc->sc_freeflag2;
218 sc->sc_obuf = sc->sc_obuf2;
219 sc->sc_op = sc->sc_obuf->m_data;
220 sc->sc_ol = sc->sc_obuf->m_len;
223 printf("ob2=%x, op=%x, ol=%d, f=%d #",
233 printf("ob=%x, op=%x, ol=%d, f=%d #",
243 ISAC_WRFIFO(sc->sc_op, min(sc->sc_ol, ISAC_FIFO_LEN));
245 if(sc->sc_ol > ISAC_FIFO_LEN) /* length > 32 ? */
247 sc->sc_op += ISAC_FIFO_LEN; /* bufferptr+32 */
248 sc->sc_ol -= ISAC_FIFO_LEN; /* length - 32 */
249 c |= ISAC_CMDR_XTF; /* set XTF bit */
255 i4b_Dfreembuf(sc->sc_obuf);
262 c |= ISAC_CMDR_XTF | ISAC_CMDR_XME;
267 sc->sc_state &= ~ISAC_TX_ACTIVE;
271 if(ista & ISAC_ISTA_CISQ) /* channel status change CISQ */
275 /* get command/indication rx register*/
277 ci = ISAC_READ(I_CIRR);
279 /* if S/Q IRQ, read SQC reg to clr SQC IRQ */
281 if(ci & ISAC_CIRR_SQC)
282 (void) ISAC_READ(I_SQRR);
284 /* C/I code change IRQ (flag already cleared by CIRR read) */
286 if(ci & ISAC_CIRR_CIC0)
287 ifpi_isac_ind_hdlr(sc, (ci >> 2) & 0xf);
292 ISAC_WRITE(I_CMDR, c);
297 /*---------------------------------------------------------------------------*
298 * ISAC L1 Extended IRQ handler
299 *---------------------------------------------------------------------------*/
301 ifpi_isac_exir_hdlr(register struct l1_softc *sc, u_char exir)
305 if(exir & ISAC_EXIR_XMR)
307 NDBGL1(L1_I_ERR, "EXIRQ Tx Message Repeat");
312 if(exir & ISAC_EXIR_XDU)
314 NDBGL1(L1_I_ERR, "EXIRQ Tx Data Underrun");
319 if(exir & ISAC_EXIR_PCE)
321 NDBGL1(L1_I_ERR, "EXIRQ Protocol Error");
324 if(exir & ISAC_EXIR_RFO)
326 NDBGL1(L1_I_ERR, "EXIRQ Rx Frame Overflow");
328 c |= ISAC_CMDR_RMC|ISAC_CMDR_RRES;
331 if(exir & ISAC_EXIR_SOV)
333 NDBGL1(L1_I_ERR, "EXIRQ Sync Xfer Overflow");
336 if(exir & ISAC_EXIR_MOS)
338 NDBGL1(L1_I_ERR, "EXIRQ Monitor Status");
341 if(exir & ISAC_EXIR_SAW)
343 /* cannot happen, STCR:TSF is set to 0 */
345 NDBGL1(L1_I_ERR, "EXIRQ Subscriber Awake");
348 if(exir & ISAC_EXIR_WOV)
350 /* cannot happen, STCR:TSF is set to 0 */
352 NDBGL1(L1_I_ERR, "EXIRQ Watchdog Timer Overflow");
358 /*---------------------------------------------------------------------------*
359 * ISAC L1 Indication handler
360 *---------------------------------------------------------------------------*/
362 ifpi_isac_ind_hdlr(register struct l1_softc *sc, int ind)
369 NDBGL1(L1_I_CICO, "rx AI8 in state %s", ifpi_printstate(sc));
370 if(sc->sc_bustyp == BUS_TYPE_IOM2)
371 ifpi_isac_l1_cmd(sc, CMD_AR8);
373 i4b_l1_mph_status_ind(L0IFPIUNIT(sc->sc_unit), STI_L1STAT, LAYER_ACTIVE, NULL);
376 case ISAC_CIRR_IAI10:
377 NDBGL1(L1_I_CICO, "rx AI10 in state %s", ifpi_printstate(sc));
378 if(sc->sc_bustyp == BUS_TYPE_IOM2)
379 ifpi_isac_l1_cmd(sc, CMD_AR10);
381 i4b_l1_mph_status_ind(L0IFPIUNIT(sc->sc_unit), STI_L1STAT, LAYER_ACTIVE, NULL);
385 NDBGL1(L1_I_CICO, "rx RSY in state %s", ifpi_printstate(sc));
390 NDBGL1(L1_I_CICO, "rx PU in state %s", ifpi_printstate(sc));
395 NDBGL1(L1_I_CICO, "rx DR in state %s", ifpi_printstate(sc));
396 ifpi_isac_l1_cmd(sc, CMD_DIU);
401 NDBGL1(L1_I_CICO, "rx DID in state %s", ifpi_printstate(sc));
403 i4b_l1_mph_status_ind(L0IFPIUNIT(sc->sc_unit), STI_L1STAT, LAYER_IDLE, NULL);
407 NDBGL1(L1_I_CICO, "rx DIS in state %s", ifpi_printstate(sc));
412 NDBGL1(L1_I_CICO, "rx EI in state %s", ifpi_printstate(sc));
413 ifpi_isac_l1_cmd(sc, CMD_DIU);
418 NDBGL1(L1_I_CICO, "rx ARD in state %s", ifpi_printstate(sc));
423 NDBGL1(L1_I_CICO, "rx TI in state %s", ifpi_printstate(sc));
428 NDBGL1(L1_I_CICO, "rx ATI in state %s", ifpi_printstate(sc));
433 NDBGL1(L1_I_CICO, "rx SD in state %s", ifpi_printstate(sc));
438 NDBGL1(L1_I_ERR, "UNKNOWN Indication 0x%x in state %s", ind, ifpi_printstate(sc));
442 ifpi_next_state(sc, event);
445 /*---------------------------------------------------------------------------*
446 * execute a layer 1 command
447 *---------------------------------------------------------------------------*/
449 ifpi_isac_l1_cmd(struct l1_softc *sc, int command)
453 #ifdef I4B_SMP_WORKAROUND
455 /* XXXXXXXXXXXXXXXXXXX */
458 * patch from Wolfgang Helbig:
460 * Here is a patch that makes i4b work on an SMP:
461 * The card (TELES 16.3) didn't interrupt on an SMP machine.
462 * This is a gross workaround, but anyway it works *and* provides
463 * some information as how to finally fix this problem.
466 HSCX_WRITE(0, H_MASK, 0xff);
467 HSCX_WRITE(1, H_MASK, 0xff);
468 ISAC_WRITE(I_MASK, 0xff);
470 HSCX_WRITE(0, H_MASK, HSCX_A_IMASK);
471 HSCX_WRITE(1, H_MASK, HSCX_B_IMASK);
472 ISAC_WRITE(I_MASK, ISAC_IMASK);
474 /* XXXXXXXXXXXXXXXXXXX */
476 #endif /* I4B_SMP_WORKAROUND */
478 if(command < 0 || command > CMD_ILL)
480 NDBGL1(L1_I_ERR, "illegal cmd 0x%x in state %s", command, ifpi_printstate(sc));
484 if(sc->sc_bustyp == BUS_TYPE_IOM2)
492 NDBGL1(L1_I_CICO, "tx TIM in state %s", ifpi_printstate(sc));
493 cmd |= (ISAC_CIXR_CTIM << 2);
497 NDBGL1(L1_I_CICO, "tx RS in state %s", ifpi_printstate(sc));
498 cmd |= (ISAC_CIXR_CRS << 2);
502 NDBGL1(L1_I_CICO, "tx AR8 in state %s", ifpi_printstate(sc));
503 cmd |= (ISAC_CIXR_CAR8 << 2);
507 NDBGL1(L1_I_CICO, "tx AR10 in state %s", ifpi_printstate(sc));
508 cmd |= (ISAC_CIXR_CAR10 << 2);
512 NDBGL1(L1_I_CICO, "tx DIU in state %s", ifpi_printstate(sc));
513 cmd |= (ISAC_CIXR_CDIU << 2);
516 ISAC_WRITE(I_CIXR, cmd);
519 /*---------------------------------------------------------------------------*
520 * L1 ISAC initialization
521 *---------------------------------------------------------------------------*/
523 ifpi_isac_init(struct l1_softc *sc)
525 ISAC_IMASK = 0xff; /* disable all irqs */
527 ISAC_WRITE(I_MASK, ISAC_IMASK);
529 if(sc->sc_bustyp != BUS_TYPE_IOM2)
531 NDBGL1(L1_I_SETUP, "configuring for IOM-1 mode");
533 /* ADF2: Select mode IOM-1 */
534 ISAC_WRITE(I_ADF2, 0x00);
536 /* SPCR: serial port control register:
537 * SPU - software power up = 0
538 * SAC - SIP port high Z
539 * SPM - timing mode 0
540 * TLP - test loop = 0
541 * C1C, C2C - B1 and B2 switched to/from SPa
543 ISAC_WRITE(I_SPCR, ISAC_SPCR_C1C1|ISAC_SPCR_C2C1);
545 /* SQXR: S/Q channel xmit register:
546 * SQIE - S/Q IRQ enable = 0
547 * SQX1-4 - Fa bits = 1
549 ISAC_WRITE(I_SQXR, ISAC_SQXR_SQX1|ISAC_SQXR_SQX2|ISAC_SQXR_SQX3|ISAC_SQXR_SQX4);
551 /* ADF1: additional feature reg 1:
553 * TEM - test mode = 0
554 * PFS - pre-filter = 0
555 * CFS - IOM clock/frame always active
556 * FSC1/2 - polarity of 8kHz strobe
557 * ITF - interframe fill = idle
559 ISAC_WRITE(I_ADF1, ISAC_ADF1_FC2); /* ADF1 */
561 /* STCR: sync transfer control reg:
562 * TSF - terminal secific functions = 0
563 * TBA - TIC bus address = 7
566 ISAC_WRITE(I_STCR, ISAC_STCR_TBA2|ISAC_STCR_TBA1|ISAC_STCR_TBA0);
568 /* MODE: Mode Register:
569 * MDSx - transparent mode 2
570 * TMD - timer mode = external
571 * RAC - Receiver enabled
572 * DIMx - digital i/f mode
574 ISAC_WRITE(I_MODE, ISAC_MODE_MDS2|ISAC_MODE_MDS1|ISAC_MODE_RAC|ISAC_MODE_DIM0);
578 NDBGL1(L1_I_SETUP, "configuring for IOM-2 mode");
580 /* ADF2: Select mode IOM-2 */
581 ISAC_WRITE(I_ADF2, ISAC_ADF2_IMS);
583 /* SPCR: serial port control register:
584 * SPU - software power up = 0
585 * SPM - timing mode 0
586 * TLP - test loop = 0
587 * C1C, C2C - B1 + C1 and B2 + IC2 monitoring
589 ISAC_WRITE(I_SPCR, 0x00);
591 /* SQXR: S/Q channel xmit register:
592 * IDC - IOM direction = 0 (master)
593 * CFS - Config Select = 0 (clock always active)
594 * CI1E - C/I channel 1 IRQ enable = 0
595 * SQIE - S/Q IRQ enable = 0
596 * SQX1-4 - Fa bits = 1
598 ISAC_WRITE(I_SQXR, ISAC_SQXR_SQX1|ISAC_SQXR_SQX2|ISAC_SQXR_SQX3|ISAC_SQXR_SQX4);
600 /* ADF1: additional feature reg 1:
602 * TEM - test mode = 0
603 * PFS - pre-filter = 0
604 * IOF - IOM i/f off = 0
605 * ITF - interframe fill = idle
607 ISAC_WRITE(I_ADF1, 0x00);
609 /* STCR: sync transfer control reg:
610 * TSF - terminal secific functions = 0
611 * TBA - TIC bus address = 7
614 ISAC_WRITE(I_STCR, ISAC_STCR_TBA2|ISAC_STCR_TBA1|ISAC_STCR_TBA0);
616 /* MODE: Mode Register:
617 * MDSx - transparent mode 2
618 * TMD - timer mode = external
619 * RAC - Receiver enabled
620 * DIMx - digital i/f mode
622 ISAC_WRITE(I_MODE, ISAC_MODE_MDS2|ISAC_MODE_MDS1|ISAC_MODE_RAC|ISAC_MODE_DIM0);
627 * XXX a transmitter reset causes an ISAC tx IRQ which will not
628 * be serviced at attach time under some circumstances leaving
629 * the associated IRQ line on the ISA bus active. This prevents
630 * any further interrupts to be serviced because no low -> high
631 * transition can take place anymore. (-hm)
635 * RRES - HDLC receiver reset
636 * XRES - transmitter reset
638 ISAC_WRITE(I_CMDR, ISAC_CMDR_RRES|ISAC_CMDR_XRES);
642 /* enabled interrupts:
643 * ===================
644 * RME - receive message end
645 * RPF - receive pool full
646 * XPR - transmit pool ready
647 * CISQ - CI or S/Q channel change
648 * EXI - extended interrupt
651 ISAC_IMASK = ISAC_MASK_RSC | /* auto mode only */
652 ISAC_MASK_TIN | /* timer irq */
653 ISAC_MASK_SIN; /* sync xfer irq */
655 ISAC_WRITE(I_MASK, ISAC_IMASK);