2 * Copyright (c) 1999, 2000 Gary Jennejohn. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 /*---------------------------------------------------------------------------
34 * i4b_ifpi_pci.c: AVM Fritz!Card PCI hardware driver
35 * --------------------------------------------------
36 * $Id: i4b_ifpi_pci.c,v 1.4 2000/06/02 11:58:56 hm Exp $
37 * last edit-date: [Fri Jan 12 17:01:26 2001]
39 *---------------------------------------------------------------------------*/
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
46 #include <sys/param.h>
47 #include <sys/kernel.h>
48 #include <sys/systm.h>
51 #include <machine/bus.h>
55 #include <dev/pci/pcireg.h>
56 #include <dev/pci/pcivar.h>
58 #include <sys/socket.h>
61 #include <i4b/include/i4b_debug.h>
62 #include <i4b/include/i4b_ioctl.h>
63 #include <i4b/include/i4b_trace.h>
65 #include <i4b/include/i4b_global.h>
66 #include <i4b/include/i4b_mbuf.h>
68 #include <i4b/layer1/i4b_l1.h>
69 #include <i4b/layer1/isic/i4b_isic.h>
70 #include <i4b/layer1/isic/i4b_isac.h>
71 #include <i4b/layer1/isic/i4b_hscx.h>
73 #include <i4b/layer1/ifpi/i4b_ifpi_ext.h>
75 #define PCI_AVMA1_VID 0x1244
76 #define PCI_AVMA1_DID 0x0a00
80 static void avma1pp_disable(device_t);
81 static void avma1pp_intr(void *);
82 static void hscx_write_reg(int, u_int, u_int, struct l1_softc *);
83 static u_char hscx_read_reg(int, u_int, struct l1_softc *);
84 static u_int hscx_read_reg_int(int, u_int, struct l1_softc *);
85 static void hscx_read_fifo(int, void *, size_t, struct l1_softc *);
86 static void hscx_write_fifo(int, void *, size_t, struct l1_softc *);
87 static void avma1pp_hscx_int_handler(struct l1_softc *);
88 static void avma1pp_hscx_intr(int, u_int, struct l1_softc *);
89 static void avma1pp_init_linktab(struct l1_softc *);
90 static void avma1pp_bchannel_setup(int, int, int, int);
91 static void avma1pp_bchannel_start(int, int);
92 static void avma1pp_hscx_init(struct l1_softc *, int, int);
93 static void avma1pp_bchannel_stat(int, int, bchan_statistics_t *);
94 static void avma1pp_set_linktab(int, int, drvr_link_t *);
95 static isdn_link_t * avma1pp_ret_linktab(int, int);
96 static int avma1pp_pci_probe(device_t);
97 static int avma1pp_hscx_fifo(l1_bchan_state_t *, struct l1_softc *);
98 int avma1pp_attach_avma1pp(device_t);
99 static void ifpi_isac_intr(struct l1_softc *sc);
101 static device_method_t avma1pp_pci_methods[] = {
102 /* Device interface */
103 DEVMETHOD(device_probe, avma1pp_pci_probe),
104 DEVMETHOD(device_attach, avma1pp_attach_avma1pp),
105 DEVMETHOD(device_shutdown, avma1pp_disable),
108 DEVMETHOD(bus_print_child, bus_generic_print_child),
109 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
114 #if 0 /* use what's in l1_softc */
115 /* a minimal softc for the Fritz!Card PCI */
118 bus_space_handle_t avma1pp_bhandle;
119 bus_space_tag_t avma1pp_btag;
120 void *avma1pp_intrhand;
121 struct resource *avma1pp_irq;
122 struct resource *avma1pp_res;
123 /* pointer to ifpi_sc */
124 struct l1_softc *avma1pp_isc;
128 static driver_t avma1pp_pci_driver = {
131 sizeof(struct l1_softc)
134 static devclass_t avma1pp_pci_devclass;
136 DRIVER_MODULE(avma1pp, pci, avma1pp_pci_driver, avma1pp_pci_devclass, 0, 0);
138 /* jump table for multiplex routines */
140 struct i4b_l1mux_func avma1pp_l1mux_func = {
143 ifpi_mph_command_req,
145 ifpi_ph_activate_req,
148 struct l1_softc *ifpi_scp[IFPI_MAXUNIT];
150 /*---------------------------------------------------------------------------*
151 * AVM PCI Fritz!Card special registers
152 *---------------------------------------------------------------------------*/
155 * register offsets from i/o base
157 #define STAT0_OFFSET 0x02
158 #define STAT1_OFFSET 0x03
159 #define ADDR_REG_OFFSET 0x04
160 /*#define MODREG_OFFSET 0x06
161 #define VERREG_OFFSET 0x07*/
163 /* these 2 are used to select an ISAC register set */
164 #define ISAC_LO_REG_OFFSET 0x04
165 #define ISAC_HI_REG_OFFSET 0x06
167 /* offset higher than this goes to the HI register set */
168 #define MAX_LO_REG_OFFSET 0x2f
170 /* mask for the offset */
171 #define ISAC_REGSET_MASK 0x0f
173 /* the offset from the base to the ISAC registers */
174 #define ISAC_REG_OFFSET 0x10
176 /* the offset from the base to the ISAC FIFO */
177 #define ISAC_FIFO 0x02
179 /* not really the HSCX, but sort of */
180 #define HSCX_FIFO 0x00
181 #define HSCX_STAT 0x04
184 * AVM PCI Status Latch 0 read only bits
186 #define ASL_IRQ_ISAC 0x01 /* ISAC interrupt, active low */
187 #define ASL_IRQ_HSCX 0x02 /* HSX interrupt, active low */
188 #define ASL_IRQ_TIMER 0x04 /* Timer interrupt, active low */
189 #define ASL_IRQ_BCHAN ASL_IRQ_HSCX
190 /* actually active LOW */
191 #define ASL_IRQ_Pending (ASL_IRQ_ISAC | ASL_IRQ_HSCX | ASL_IRQ_TIMER)
194 * AVM Status Latch 0 write only bits
196 #define ASL_RESET_ALL 0x01 /* reset siemens IC's, active 1 */
197 #define ASL_TIMERDISABLE 0x02 /* active high */
198 #define ASL_TIMERRESET 0x04 /* active high */
199 #define ASL_ENABLE_INT 0x08 /* active high */
200 #define ASL_TESTBIT 0x10 /* active high */
203 * AVM Status Latch 1 write only bits
205 #define ASL1_INTSEL 0x0f /* active high */
206 #define ASL1_ENABLE_IOM 0x80 /* active high */
211 #define HSCX_MODE_ITF_FLG 0x01
212 #define HSCX_MODE_TRANS 0x02
213 #define HSCX_MODE_CCR_7 0x04
214 #define HSCX_MODE_CCR_16 0x08
215 #define HSCX_MODE_TESTLOOP 0x80
220 #define HSCX_STAT_RME 0x01
221 #define HSCX_STAT_RDO 0x10
222 #define HSCX_STAT_CRCVFRRAB 0x0E
223 #define HSCX_STAT_CRCVFR 0x06
224 #define HSCX_STAT_RML_MASK 0x3f00
227 * "HSCX" interrupt bits
229 #define HSCX_INT_XPR 0x80
230 #define HSCX_INT_XDU 0x40
231 #define HSCX_INT_RPR 0x20
232 #define HSCX_INT_MASK 0xE0
235 * "HSCX" command bits
237 #define HSCX_CMD_XRS 0x80
238 #define HSCX_CMD_XME 0x01
239 #define HSCX_CMD_RRS 0x20
240 #define HSCX_CMD_XML_MASK 0x3f00
243 * Commands and parameters are sent to the "HSCX" as a long, but the
244 * fields are handled as bytes.
247 * (prot << 16)|(txl << 8)|cmd
250 * prot = protocol to use
251 * txl = transmit length
252 * cmd = the command to be executed
254 * The fields are defined as u_char in struct l1_softc.
256 * Macro to coalesce the byte fields into a u_int
258 #define AVMA1PPSETCMDLONG(f) (f) = ((sc->avma1pp_cmd) | (sc->avma1pp_txl << 8) \
259 | (sc->avma1pp_prot << 16))
262 * to prevent deactivating the "HSCX" when both channels are active we
263 * define an HSCX_ACTIVE flag which is or'd into the channel's state
264 * flag in avma1pp_bchannel_setup upon active and cleared upon deactivation.
265 * It is set high to allow room for new flags.
267 #define HSCX_AVMA1PP_ACTIVE 0x1000
269 /*---------------------------------------------------------------------------*
270 * AVM read fifo routines
271 *---------------------------------------------------------------------------*/
274 avma1pp_read_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
276 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
277 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
281 bus_space_write_1(btag, bhandle, ADDR_REG_OFFSET, ISAC_FIFO);
282 bus_space_read_multi_1(btag, bhandle, ISAC_REG_OFFSET, buf, size);
284 case ISIC_WHAT_HSCXA:
285 hscx_read_fifo(0, buf, size, sc);
287 case ISIC_WHAT_HSCXB:
288 hscx_read_fifo(1, buf, size, sc);
294 hscx_read_fifo(int chan, void *buf, size_t len, struct l1_softc *sc)
298 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
299 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
301 bus_space_write_4(btag, bhandle, ADDR_REG_OFFSET, chan);
302 ip = (u_int32_t *)buf;
304 /* what if len isn't a multiple of sizeof(int) and buf is */
308 *ip++ = bus_space_read_4(btag, bhandle, ISAC_REG_OFFSET);
313 /*---------------------------------------------------------------------------*
314 * AVM write fifo routines
315 *---------------------------------------------------------------------------*/
317 avma1pp_write_fifo(struct l1_softc *sc, int what, void *buf, size_t size)
319 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
320 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
324 bus_space_write_1(btag, bhandle, ADDR_REG_OFFSET, ISAC_FIFO);
325 bus_space_write_multi_1(btag, bhandle, ISAC_REG_OFFSET, (u_int8_t*)buf, size);
327 case ISIC_WHAT_HSCXA:
328 hscx_write_fifo(0, buf, size, sc);
330 case ISIC_WHAT_HSCXB:
331 hscx_write_fifo(1, buf, size, sc);
337 hscx_write_fifo(int chan, void *buf, size_t len, struct l1_softc *sc)
341 l1_bchan_state_t *Bchan = &sc->sc_chan[chan];
342 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
343 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
346 sc->avma1pp_cmd &= ~HSCX_CMD_XME;
348 if (Bchan->out_mbuf_cur == NULL)
350 if (Bchan->bprot != BPROT_NONE)
351 sc->avma1pp_cmd |= HSCX_CMD_XME;
353 if (len != sc->sc_bfifolen)
354 sc->avma1pp_txl = len;
356 cnt = 0; /* borrow cnt */
357 AVMA1PPSETCMDLONG(cnt);
358 hscx_write_reg(chan, HSCX_STAT, cnt, sc);
360 ip = (u_int32_t *)buf;
364 bus_space_write_4(btag, bhandle, ISAC_REG_OFFSET, *ip);
370 /*---------------------------------------------------------------------------*
371 * AVM write register routines
372 *---------------------------------------------------------------------------*/
375 avma1pp_write_reg(struct l1_softc *sc, int what, bus_size_t offs, u_int8_t data)
378 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
379 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
383 reg_bank = (offs > MAX_LO_REG_OFFSET) ? ISAC_HI_REG_OFFSET:ISAC_LO_REG_OFFSET;
384 #ifdef AVMA1PCI_DEBUG
385 printf("write_reg bank %d off %ld.. ", (int)reg_bank, (long)offs);
387 /* set the register bank */
388 bus_space_write_1(btag, bhandle, ADDR_REG_OFFSET, reg_bank);
389 bus_space_write_1(btag, bhandle, ISAC_REG_OFFSET + (offs & ISAC_REGSET_MASK), data);
391 case ISIC_WHAT_HSCXA:
392 hscx_write_reg(0, offs, data, sc);
394 case ISIC_WHAT_HSCXB:
395 hscx_write_reg(1, offs, data, sc);
401 hscx_write_reg(int chan, u_int off, u_int val, struct l1_softc *sc)
403 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
404 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
406 /* point at the correct channel */
407 bus_space_write_4(btag, bhandle, ADDR_REG_OFFSET, chan);
408 bus_space_write_4(btag, bhandle, ISAC_REG_OFFSET + off, val);
411 /*---------------------------------------------------------------------------*
412 * AVM read register routines
413 *---------------------------------------------------------------------------*/
415 avma1pp_read_reg(struct l1_softc *sc, int what, bus_size_t offs)
418 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
419 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
423 reg_bank = (offs > MAX_LO_REG_OFFSET) ? ISAC_HI_REG_OFFSET:ISAC_LO_REG_OFFSET;
424 #ifdef AVMA1PCI_DEBUG
425 printf("read_reg bank %d off %ld.. ", (int)reg_bank, (long)offs);
427 /* set the register bank */
428 bus_space_write_1(btag, bhandle, ADDR_REG_OFFSET, reg_bank);
429 return(bus_space_read_1(btag, bhandle, ISAC_REG_OFFSET +
430 (offs & ISAC_REGSET_MASK)));
431 case ISIC_WHAT_HSCXA:
432 return hscx_read_reg(0, offs, sc);
433 case ISIC_WHAT_HSCXB:
434 return hscx_read_reg(1, offs, sc);
440 hscx_read_reg(int chan, u_int off, struct l1_softc *sc)
442 return(hscx_read_reg_int(chan, off, sc) & 0xff);
446 * need to be able to return an int because the RBCH is in the 2nd
450 hscx_read_reg_int(int chan, u_int off, struct l1_softc *sc)
452 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
453 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
455 /* point at the correct channel */
456 bus_space_write_4(btag, bhandle, ADDR_REG_OFFSET, chan);
457 return(bus_space_read_4(btag, bhandle, ISAC_REG_OFFSET + off));
460 /*---------------------------------------------------------------------------*
461 * avma1pp_probe - probe for a card
462 *---------------------------------------------------------------------------*/
464 avma1pp_pci_probe(dev)
469 vid = pci_get_vendor(dev);
470 did = pci_get_device(dev);
472 if ((vid == PCI_AVMA1_VID) && (did == PCI_AVMA1_DID)) {
473 device_set_desc(dev, "AVM Fritz!Card PCI");
480 /*---------------------------------------------------------------------------*
481 * avma1pp_attach_avma1pp - attach Fritz!Card PCI
482 *---------------------------------------------------------------------------*/
484 avma1pp_attach_avma1pp(device_t dev)
492 bus_space_handle_t bhandle;
493 bus_space_tag_t btag;
494 l1_bchan_state_t *chan;
498 vid = pci_get_vendor(dev);
499 did = pci_get_device(dev);
500 sc = device_get_softc(dev);
501 unit = device_get_unit(dev);
502 bzero(sc, sizeof(struct l1_softc));
504 /* probably not really required */
505 if(unit >= IFPI_MAXUNIT) {
506 printf("avma1pp%d: Error, unit >= IFPI_MAXUNIT!\n", unit);
511 if ((vid != PCI_AVMA1_VID) && (did != PCI_AVMA1_DID)) {
512 printf("avma1pp%d: unknown device!?\n", unit);
518 sc->sc_resources.io_rid[0] = PCIR_BAR(1);
519 sc->sc_resources.io_base[0] = bus_alloc_resource_any(dev,
520 SYS_RES_IOPORT, &sc->sc_resources.io_rid[0], RF_ACTIVE);
522 if (sc->sc_resources.io_base[0] == NULL) {
523 printf("avma1pp%d: couldn't map IO port\n", unit);
528 bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
529 btag = rman_get_bustag(sc->sc_resources.io_base[0]);
531 /* Allocate interrupt */
532 sc->sc_resources.irq_rid = 0;
533 sc->sc_resources.irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
534 &sc->sc_resources.irq_rid, RF_SHAREABLE | RF_ACTIVE);
536 if (sc->sc_resources.irq == NULL) {
537 bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(1), sc->sc_resources.io_base[0]);
538 printf("avma1pp%d: couldn't map interrupt\n", unit);
543 error = bus_setup_intr(dev, sc->sc_resources.irq, INTR_TYPE_NET, NULL, avma1pp_intr, sc, &ih);
546 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_resources.irq);
547 bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(1), sc->sc_resources.io_base[0]);
548 printf("avma1pp%d: couldn't set up irq\n", unit);
554 /* end of new-bus stuff */
556 ISAC_BASE = (caddr_t)ISIC_WHAT_ISAC;
558 HSCX_A_BASE = (caddr_t)ISIC_WHAT_HSCXA;
559 HSCX_B_BASE = (caddr_t)ISIC_WHAT_HSCXB;
561 /* setup access routines */
564 sc->readreg = avma1pp_read_reg;
565 sc->writereg = avma1pp_write_reg;
567 sc->readfifo = avma1pp_read_fifo;
568 sc->writefifo = avma1pp_write_fifo;
570 /* setup card type */
572 sc->sc_cardtyp = CARD_TYPEP_AVMA1PCI;
574 /* setup IOM bus type */
576 sc->sc_bustyp = BUS_TYPE_IOM2;
578 /* set up some other miscellaneous things */
580 sc->sc_bfifolen = HSCX_FIFO_LEN;
583 /* the Linux driver does this to clear any pending ISAC interrupts */
585 v = ISAC_READ(I_STAR);
586 #ifdef AVMA1PCI_DEBUG
587 printf("avma1pp_attach: I_STAR %x...", v);
589 v = ISAC_READ(I_MODE);
590 #ifdef AVMA1PCI_DEBUG
591 printf("avma1pp_attach: I_MODE %x...", v);
593 v = ISAC_READ(I_ADF2);
594 #ifdef AVMA1PCI_DEBUG
595 printf("avma1pp_attach: I_ADF2 %x...", v);
597 v = ISAC_READ(I_ISTA);
598 #ifdef AVMA1PCI_DEBUG
599 printf("avma1pp_attach: I_ISTA %x...", v);
601 if (v & ISAC_ISTA_EXI)
603 v = ISAC_READ(I_EXIR);
604 #ifdef AVMA1PCI_DEBUG
605 printf("avma1pp_attach: I_EXIR %x...", v);
608 v = ISAC_READ(I_CIRR);
609 #ifdef AVMA1PCI_DEBUG
610 printf("avma1pp_attach: I_CIRR %x...", v);
612 ISAC_WRITE(I_MASK, 0xff);
613 /* the Linux driver does this to clear any pending HSCX interrupts */
614 v = hscx_read_reg_int(0, HSCX_STAT, sc);
615 #ifdef AVMA1PCI_DEBUG
616 printf("avma1pp_attach: 0 HSCX_STAT %x...", v);
618 v = hscx_read_reg_int(1, HSCX_STAT, sc);
619 #ifdef AVMA1PCI_DEBUG
620 printf("avma1pp_attach: 1 HSCX_STAT %x\n", v);
623 bus_space_write_1(btag, bhandle, STAT0_OFFSET, ASL_RESET_ALL|ASL_TIMERDISABLE);
624 DELAY(SEC_DELAY/100); /* 10 ms */
625 bus_space_write_1(btag, bhandle, STAT0_OFFSET, ASL_TIMERRESET|ASL_ENABLE_INT|ASL_TIMERDISABLE);
626 DELAY(SEC_DELAY/100); /* 10 ms */
627 #ifdef AVMA1PCI_DEBUG
628 bus_space_write_1(btag, bhandle, STAT1_OFFSET, ASL1_ENABLE_IOM|sc->sc_irq);
629 DELAY(SEC_DELAY/100); /* 10 ms */
630 v = bus_space_read_1(btag, bhandle, STAT1_OFFSET);
631 printf("after reset: S1 %#x\n", v);
633 v = bus_space_read_4(btag, bhandle, 0);
634 printf("avma1pp_attach_avma1pp: v %#x\n", v);
637 /* from here to the end would normally be done in isic_pciattach */
639 printf("ifpi%d: ISAC %s (IOM-%c)\n", unit,
640 "2085 Version A1/A2 or 2086/2186 Version 1.1",
641 sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2');
646 #if defined (__FreeBSD__) && __FreeBSD__ > 4
647 /* Init the channel mutexes */
648 chan = &sc->sc_chan[HSCX_CH_A];
649 if(!mtx_initialized(&chan->rx_queue.ifq_mtx))
650 mtx_init(&chan->rx_queue.ifq_mtx, "i4b_avma1pp_rx", NULL, MTX_DEF);
651 if(!mtx_initialized(&chan->tx_queue.ifq_mtx))
652 mtx_init(&chan->tx_queue.ifq_mtx, "i4b_avma1pp_tx", NULL, MTX_DEF);
653 chan = &sc->sc_chan[HSCX_CH_B];
654 if(!mtx_initialized(&chan->rx_queue.ifq_mtx))
655 mtx_init(&chan->rx_queue.ifq_mtx, "i4b_avma1pp_rx", NULL, MTX_DEF);
656 if(!mtx_initialized(&chan->tx_queue.ifq_mtx))
657 mtx_init(&chan->tx_queue.ifq_mtx, "i4b_avma1pp_tx", NULL, MTX_DEF);
660 /* init the "HSCX" */
661 avma1pp_bchannel_setup(sc->sc_unit, HSCX_CH_A, BPROT_NONE, 0);
663 avma1pp_bchannel_setup(sc->sc_unit, HSCX_CH_B, BPROT_NONE, 0);
665 /* can't use the normal B-Channel stuff */
666 avma1pp_init_linktab(sc);
668 /* set trace level */
670 sc->sc_trace = TRACE_OFF;
672 sc->sc_state = ISAC_IDLE;
684 sc->sc_freeflag2 = 0;
686 #if defined(__FreeBSD__) && __FreeBSD__ >=3
687 callout_handle_init(&sc->sc_T3_callout);
688 callout_handle_init(&sc->sc_T4_callout);
691 /* init higher protocol layers */
693 i4b_l1_mph_status_ind(L0IFPIUNIT(sc->sc_unit), STI_ATTACH, sc->sc_cardtyp, &avma1pp_l1mux_func);
701 * this is the real interrupt routine
704 avma1pp_hscx_intr(int h_chan, u_int stat, struct l1_softc *sc)
706 register l1_bchan_state_t *chan = &sc->sc_chan[h_chan];
710 NDBGL1(L1_H_IRQ, "%#x", stat);
712 if((stat & HSCX_INT_XDU) && (chan->bprot != BPROT_NONE))/* xmit data underrun */
715 NDBGL1(L1_H_XFRERR, "xmit data underrun");
716 /* abort the transmission */
718 sc->avma1pp_cmd |= HSCX_CMD_XRS;
719 AVMA1PPSETCMDLONG(param);
720 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
721 sc->avma1pp_cmd &= ~HSCX_CMD_XRS;
722 AVMA1PPSETCMDLONG(param);
723 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
725 if (chan->out_mbuf_head != NULL) /* don't continue to transmit this buffer */
727 i4b_Bfreembuf(chan->out_mbuf_head);
728 chan->out_mbuf_cur = chan->out_mbuf_head = NULL;
733 * The following is based on examination of the Linux driver.
735 * The logic here is different than with a "real" HSCX; all kinds
736 * of information (interrupt/status bits) are in stat.
737 * HSCX_INT_RPR indicates a receive interrupt
738 * HSCX_STAT_RDO indicates an overrun condition, abort -
739 * otherwise read the bytes ((stat & HSCX_STZT_RML_MASK) >> 8)
740 * HSCX_STAT_RME indicates end-of-frame and apparently any
741 * CRC/framing errors are only reported in this state.
742 * if ((stat & HSCX_STAT_CRCVFRRAB) != HSCX_STAT_CRCVFR)
746 if(stat & HSCX_INT_RPR)
748 register int fifo_data_len;
750 /* always have to read the FIFO, so use a scratch buffer */
751 u_char scrbuf[HSCX_FIFO_LEN];
753 if(stat & HSCX_STAT_RDO)
756 NDBGL1(L1_H_XFRERR, "receive data overflow");
761 * check whether we're receiving data for an inactive B-channel
762 * and discard it. This appears to happen for telephony when
763 * both B-channels are active and one is deactivated. Since
764 * it is not really possible to deactivate the channel in that
765 * case (the ASIC seems to deactivate _both_ channels), the
766 * "deactivated" channel keeps receiving data which can lead
767 * to exhaustion of mbufs and a kernel panic.
769 * This is a hack, but it's the only solution I can think of
770 * without having the documentation for the ASIC.
773 if (chan->state == HSCX_IDLE)
775 NDBGL1(L1_H_XFRERR, "toss data from %d", h_chan);
779 fifo_data_len = ((stat & HSCX_STAT_RML_MASK) >> 8);
781 if(fifo_data_len == 0)
782 fifo_data_len = sc->sc_bfifolen;
784 /* ALWAYS read data from HSCX fifo */
786 HSCX_RDFIFO(h_chan, scrbuf, fifo_data_len);
787 chan->rxcount += fifo_data_len;
789 /* all error conditions checked, now decide and take action */
793 if(chan->in_mbuf == NULL)
795 if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL)
796 panic("L1 avma1pp_hscx_intr: RME, cannot allocate mbuf!\n");
797 chan->in_cbptr = chan->in_mbuf->m_data;
801 if((chan->in_len + fifo_data_len) <= BCH_MAX_DATALEN)
803 /* OK to copy the data */
804 bcopy(scrbuf, chan->in_cbptr, fifo_data_len);
805 chan->in_cbptr += fifo_data_len;
806 chan->in_len += fifo_data_len;
808 /* setup mbuf data length */
810 chan->in_mbuf->m_len = chan->in_len;
811 chan->in_mbuf->m_pkthdr.len = chan->in_len;
813 if(sc->sc_trace & TRACE_B_RX)
816 hdr.unit = L0IFPIUNIT(sc->sc_unit);
817 hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2);
819 hdr.count = ++sc->sc_trace_bcount;
821 i4b_l1_trace_ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data);
824 if (stat & HSCX_STAT_RME)
826 if((stat & HSCX_STAT_CRCVFRRAB) == HSCX_STAT_CRCVFR)
828 (*chan->isic_drvr_linktab->bch_rx_data_ready)(chan->isic_drvr_linktab->unit);
831 /* mark buffer ptr as unused */
833 chan->in_mbuf = NULL;
834 chan->in_cbptr = NULL;
840 NDBGL1(L1_H_XFRERR, "CRC/RAB");
841 if (chan->in_mbuf != NULL)
843 i4b_Bfreembuf(chan->in_mbuf);
844 chan->in_mbuf = NULL;
845 chan->in_cbptr = NULL;
850 } /* END enough space in mbuf */
853 if(chan->bprot == BPROT_NONE)
855 /* setup mbuf data length */
857 chan->in_mbuf->m_len = chan->in_len;
858 chan->in_mbuf->m_pkthdr.len = chan->in_len;
860 if(sc->sc_trace & TRACE_B_RX)
863 hdr.unit = L0IFPIUNIT(sc->sc_unit);
864 hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2);
866 hdr.count = ++sc->sc_trace_bcount;
868 i4b_l1_trace_ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data);
871 if(!(i4b_l1_bchan_tel_silence(chan->in_mbuf->m_data, chan->in_mbuf->m_len)))
874 /* move rx'd data to rx queue */
876 #if defined (__FreeBSD__) && __FreeBSD__ > 4
877 (void) IF_HANDOFF(&chan->rx_queue, chan->in_mbuf, NULL);
879 if(!(IF_QFULL(&chan->rx_queue)))
881 IF_ENQUEUE(&chan->rx_queue, chan->in_mbuf);
885 i4b_Bfreembuf(chan->in_mbuf);
888 /* signal upper layer that data are available */
889 (*chan->isic_drvr_linktab->bch_rx_data_ready)(chan->isic_drvr_linktab->unit);
891 /* alloc new buffer */
893 if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL)
894 panic("L1 avma1pp_hscx_intr: RPF, cannot allocate new mbuf!\n");
896 /* setup new data ptr */
898 chan->in_cbptr = chan->in_mbuf->m_data;
900 /* OK to copy the data */
901 bcopy(scrbuf, chan->in_cbptr, fifo_data_len);
903 chan->in_cbptr += fifo_data_len;
904 chan->in_len = fifo_data_len;
906 chan->rxcount += fifo_data_len;
910 NDBGL1(L1_H_XFRERR, "RAWHDLC rx buffer overflow in RPF, in_len=%d", chan->in_len);
911 chan->in_cbptr = chan->in_mbuf->m_data;
915 } /* if(error == 0) */
918 /* land here for RDO */
919 if (chan->in_mbuf != NULL)
921 i4b_Bfreembuf(chan->in_mbuf);
922 chan->in_mbuf = NULL;
923 chan->in_cbptr = NULL;
927 sc->avma1pp_cmd |= HSCX_CMD_RRS;
928 AVMA1PPSETCMDLONG(param);
929 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
930 sc->avma1pp_cmd &= ~HSCX_CMD_RRS;
931 AVMA1PPSETCMDLONG(param);
932 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
937 /* transmit fifo empty, new data can be written to fifo */
939 if(stat & HSCX_INT_XPR)
942 * for a description what is going on here, please have
943 * a look at isic_bchannel_start() in i4b_bchan.c !
946 NDBGL1(L1_H_IRQ, "unit %d, chan %d - XPR, Tx Fifo Empty!", sc->sc_unit, h_chan);
948 if(chan->out_mbuf_cur == NULL) /* last frame is transmitted */
950 IF_DEQUEUE(&chan->tx_queue, chan->out_mbuf_head);
952 if(chan->out_mbuf_head == NULL)
954 chan->state &= ~HSCX_TX_ACTIVE;
955 (*chan->isic_drvr_linktab->bch_tx_queue_empty)(chan->isic_drvr_linktab->unit);
959 chan->state |= HSCX_TX_ACTIVE;
960 chan->out_mbuf_cur = chan->out_mbuf_head;
961 chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data;
962 chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len;
964 if(sc->sc_trace & TRACE_B_TX)
967 hdr.unit = L0IFPIUNIT(sc->sc_unit);
968 hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2);
970 hdr.count = ++sc->sc_trace_bcount;
972 i4b_l1_trace_ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data);
975 if(chan->bprot == BPROT_NONE)
977 if(!(i4b_l1_bchan_tel_silence(chan->out_mbuf_cur->m_data, chan->out_mbuf_cur->m_len)))
987 avma1pp_hscx_fifo(chan, sc);
990 /* call timeout handling routine */
992 if(activity == ACT_RX || activity == ACT_TX)
993 (*chan->isic_drvr_linktab->bch_activity)(chan->isic_drvr_linktab->unit, activity);
997 * this is the main routine which checks each channel and then calls
998 * the real interrupt routine as appropriate
1001 avma1pp_hscx_int_handler(struct l1_softc *sc)
1005 /* has to be a u_int because the byte count is in the 2nd byte */
1006 stat = hscx_read_reg_int(0, HSCX_STAT, sc);
1007 if (stat & HSCX_INT_MASK)
1008 avma1pp_hscx_intr(0, stat, sc);
1009 stat = hscx_read_reg_int(1, HSCX_STAT, sc);
1010 if (stat & HSCX_INT_MASK)
1011 avma1pp_hscx_intr(1, stat, sc);
1015 avma1pp_disable(device_t dev)
1017 struct l1_softc *sc = device_get_softc(dev);
1018 bus_space_handle_t bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
1019 bus_space_tag_t btag = rman_get_bustag(sc->sc_resources.io_base[0]);
1021 bus_space_write_1(btag, bhandle, STAT0_OFFSET, ASL_RESET_ALL|ASL_TIMERDISABLE);
1025 avma1pp_intr(void *xsc)
1028 struct l1_softc *sc;
1029 bus_space_handle_t bhandle;
1030 bus_space_tag_t btag;
1033 bhandle = rman_get_bushandle(sc->sc_resources.io_base[0]);
1034 btag = rman_get_bustag(sc->sc_resources.io_base[0]);
1036 stat = bus_space_read_1(btag, bhandle, STAT0_OFFSET);
1037 NDBGL1(L1_H_IRQ, "stat %x", stat);
1038 /* was there an interrupt from this card ? */
1039 if ((stat & ASL_IRQ_Pending) == ASL_IRQ_Pending)
1041 /* interrupts are low active */
1042 if (!(stat & ASL_IRQ_TIMER))
1043 NDBGL1(L1_H_IRQ, "timer interrupt ???");
1044 if (!(stat & ASL_IRQ_HSCX))
1046 NDBGL1(L1_H_IRQ, "HSCX");
1047 avma1pp_hscx_int_handler(sc);
1049 if (!(stat & ASL_IRQ_ISAC))
1051 NDBGL1(L1_H_IRQ, "ISAC");
1057 avma1pp_hscx_init(struct l1_softc *sc, int h_chan, int activate)
1059 l1_bchan_state_t *chan = &sc->sc_chan[h_chan];
1062 NDBGL1(L1_BCHAN, "unit=%d, channel=%d, %s",
1063 sc->sc_unit, h_chan, activate ? "activate" : "deactivate");
1067 /* only deactivate if both channels are idle */
1068 if (sc->sc_chan[HSCX_CH_A].state != HSCX_IDLE ||
1069 sc->sc_chan[HSCX_CH_B].state != HSCX_IDLE)
1073 sc->avma1pp_cmd = HSCX_CMD_XRS|HSCX_CMD_RRS;
1074 sc->avma1pp_prot = HSCX_MODE_TRANS;
1075 AVMA1PPSETCMDLONG(param);
1076 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
1079 if(chan->bprot == BPROT_RHDLC)
1081 NDBGL1(L1_BCHAN, "BPROT_RHDLC");
1083 /* HDLC Frames, transparent mode 0 */
1084 sc->avma1pp_cmd = HSCX_CMD_XRS|HSCX_CMD_RRS;
1085 sc->avma1pp_prot = HSCX_MODE_ITF_FLG;
1086 AVMA1PPSETCMDLONG(param);
1087 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
1088 sc->avma1pp_cmd = HSCX_CMD_XRS;
1089 AVMA1PPSETCMDLONG(param);
1090 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
1091 sc->avma1pp_cmd = 0;
1095 NDBGL1(L1_BCHAN, "BPROT_NONE??");
1097 /* Raw Telephony, extended transparent mode 1 */
1098 sc->avma1pp_cmd = HSCX_CMD_XRS|HSCX_CMD_RRS;
1099 sc->avma1pp_prot = HSCX_MODE_TRANS;
1100 AVMA1PPSETCMDLONG(param);
1101 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
1102 sc->avma1pp_cmd = HSCX_CMD_XRS;
1103 AVMA1PPSETCMDLONG(param);
1104 hscx_write_reg(h_chan, HSCX_STAT, param, sc);
1105 sc->avma1pp_cmd = 0;
1110 avma1pp_bchannel_setup(int unit, int h_chan, int bprot, int activate)
1113 struct l1_softc *sc = ifpi_scp[unit];
1115 struct l1_softc *sc = isic_find_sc(unit);
1117 l1_bchan_state_t *chan = &sc->sc_chan[h_chan];
1124 chan->state = HSCX_IDLE;
1125 avma1pp_hscx_init(sc, h_chan, activate);
1128 NDBGL1(L1_BCHAN, "unit=%d, channel=%d, %s",
1129 sc->sc_unit, h_chan, activate ? "activate" : "deactivate");
1133 chan->unit = sc->sc_unit; /* unit number */
1134 chan->channel = h_chan; /* B channel */
1135 chan->bprot = bprot; /* B channel protocol */
1136 chan->state = HSCX_IDLE; /* B channel state */
1140 chan->rx_queue.ifq_maxlen = IFQ_MAXLEN;
1142 i4b_Bcleanifq(&chan->rx_queue); /* clean rx queue */
1144 chan->rxcount = 0; /* reset rx counter */
1146 i4b_Bfreembuf(chan->in_mbuf); /* clean rx mbuf */
1148 chan->in_mbuf = NULL; /* reset mbuf ptr */
1149 chan->in_cbptr = NULL; /* reset mbuf curr ptr */
1150 chan->in_len = 0; /* reset mbuf data len */
1152 /* transmitter part */
1154 chan->tx_queue.ifq_maxlen = IFQ_MAXLEN;
1156 i4b_Bcleanifq(&chan->tx_queue); /* clean tx queue */
1158 chan->txcount = 0; /* reset tx counter */
1160 i4b_Bfreembuf(chan->out_mbuf_head); /* clean tx mbuf */
1162 chan->out_mbuf_head = NULL; /* reset head mbuf ptr */
1163 chan->out_mbuf_cur = NULL; /* reset current mbuf ptr */
1164 chan->out_mbuf_cur_ptr = NULL; /* reset current mbuf data ptr */
1165 chan->out_mbuf_cur_len = 0; /* reset current mbuf data cnt */
1170 avma1pp_hscx_init(sc, h_chan, activate);
1171 chan->state |= HSCX_AVMA1PP_ACTIVE;
1178 avma1pp_bchannel_start(int unit, int h_chan)
1181 struct l1_softc *sc = ifpi_scp[unit];
1183 struct l1_softc *sc = isic_find_sc(unit);
1185 register l1_bchan_state_t *chan = &sc->sc_chan[h_chan];
1189 s = SPLI4B(); /* enter critical section */
1190 if(chan->state & HSCX_TX_ACTIVE) /* already running ? */
1193 return; /* yes, leave */
1196 /* get next mbuf from queue */
1198 IF_DEQUEUE(&chan->tx_queue, chan->out_mbuf_head);
1200 if(chan->out_mbuf_head == NULL) /* queue empty ? */
1202 splx(s); /* leave critical section */
1203 return; /* yes, exit */
1206 /* init current mbuf values */
1208 chan->out_mbuf_cur = chan->out_mbuf_head;
1209 chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len;
1210 chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data;
1212 /* activity indicator for timeout handling */
1214 if(chan->bprot == BPROT_NONE)
1216 if(!(i4b_l1_bchan_tel_silence(chan->out_mbuf_cur->m_data, chan->out_mbuf_cur->m_len)))
1224 chan->state |= HSCX_TX_ACTIVE; /* we start transmitting */
1226 if(sc->sc_trace & TRACE_B_TX) /* if trace, send mbuf to trace dev */
1228 i4b_trace_hdr_t hdr;
1229 hdr.unit = L0IFPIUNIT(sc->sc_unit);
1230 hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2);
1232 hdr.count = ++sc->sc_trace_bcount;
1233 MICROTIME(hdr.time);
1234 i4b_l1_trace_ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data);
1237 avma1pp_hscx_fifo(chan, sc);
1239 /* call timeout handling routine */
1241 if(activity == ACT_RX || activity == ACT_TX)
1242 (*chan->isic_drvr_linktab->bch_activity)(chan->isic_drvr_linktab->unit, activity);
1247 /*---------------------------------------------------------------------------*
1248 * return the address of isic drivers linktab
1249 *---------------------------------------------------------------------------*/
1250 static isdn_link_t *
1251 avma1pp_ret_linktab(int unit, int channel)
1254 struct l1_softc *sc = ifpi_scp[unit];
1256 struct l1_softc *sc = isic_find_sc(unit);
1258 l1_bchan_state_t *chan = &sc->sc_chan[channel];
1260 return(&chan->isic_isdn_linktab);
1263 /*---------------------------------------------------------------------------*
1264 * set the driver linktab in the b channel softc
1265 *---------------------------------------------------------------------------*/
1267 avma1pp_set_linktab(int unit, int channel, drvr_link_t *dlt)
1270 struct l1_softc *sc = ifpi_scp[unit];
1272 struct l1_softc *sc = isic_find_sc(unit);
1274 l1_bchan_state_t *chan = &sc->sc_chan[channel];
1276 chan->isic_drvr_linktab = dlt;
1280 /*---------------------------------------------------------------------------*
1281 * initialize our local linktab
1282 *---------------------------------------------------------------------------*/
1284 avma1pp_init_linktab(struct l1_softc *sc)
1286 l1_bchan_state_t *chan = &sc->sc_chan[HSCX_CH_A];
1287 isdn_link_t *lt = &chan->isic_isdn_linktab;
1289 /* make sure the hardware driver is known to layer 4 */
1290 /* avoid overwriting if already set */
1291 if (ctrl_types[CTRL_PASSIVE].set_linktab == NULL)
1293 ctrl_types[CTRL_PASSIVE].set_linktab = i4b_l1_set_linktab;
1294 ctrl_types[CTRL_PASSIVE].get_linktab = i4b_l1_ret_linktab;
1298 lt->unit = sc->sc_unit;
1299 lt->channel = HSCX_CH_A;
1300 lt->bch_config = avma1pp_bchannel_setup;
1301 lt->bch_tx_start = avma1pp_bchannel_start;
1302 lt->bch_stat = avma1pp_bchannel_stat;
1303 lt->tx_queue = &chan->tx_queue;
1305 /* used by non-HDLC data transfers, i.e. telephony drivers */
1306 lt->rx_queue = &chan->rx_queue;
1308 /* used by HDLC data transfers, i.e. ipr and isp drivers */
1309 lt->rx_mbuf = &chan->in_mbuf;
1311 chan = &sc->sc_chan[HSCX_CH_B];
1312 lt = &chan->isic_isdn_linktab;
1314 lt->unit = sc->sc_unit;
1315 lt->channel = HSCX_CH_B;
1316 lt->bch_config = avma1pp_bchannel_setup;
1317 lt->bch_tx_start = avma1pp_bchannel_start;
1318 lt->bch_stat = avma1pp_bchannel_stat;
1319 lt->tx_queue = &chan->tx_queue;
1321 /* used by non-HDLC data transfers, i.e. telephony drivers */
1322 lt->rx_queue = &chan->rx_queue;
1324 /* used by HDLC data transfers, i.e. ipr and isp drivers */
1325 lt->rx_mbuf = &chan->in_mbuf;
1329 * use this instead of isic_bchannel_stat in i4b_bchan.c because it's static
1332 avma1pp_bchannel_stat(int unit, int h_chan, bchan_statistics_t *bsp)
1335 struct l1_softc *sc = ifpi_scp[unit];
1337 struct l1_softc *sc = isic_find_sc(unit);
1339 l1_bchan_state_t *chan = &sc->sc_chan[h_chan];
1344 bsp->outbytes = chan->txcount;
1345 bsp->inbytes = chan->rxcount;
1353 /*---------------------------------------------------------------------------*
1354 * fill HSCX fifo with data from the current mbuf
1355 * Put this here until it can go into i4b_hscx.c
1356 *---------------------------------------------------------------------------*/
1358 avma1pp_hscx_fifo(l1_bchan_state_t *chan, struct l1_softc *sc)
1364 /* using a scratch buffer simplifies writing to the FIFO */
1365 u_char scrbuf[HSCX_FIFO_LEN];
1370 * fill the HSCX tx fifo with data from the current mbuf. if
1371 * current mbuf holds less data than HSCX fifo length, try to
1372 * get the next mbuf from (a possible) mbuf chain. if there is
1373 * not enough data in a single mbuf or in a chain, then this
1374 * is the last mbuf and we tell the HSCX that it has to send
1375 * CRC and closing flag
1378 while(chan->out_mbuf_cur && len != sc->sc_bfifolen)
1380 nextlen = min(chan->out_mbuf_cur_len, sc->sc_bfifolen - len);
1383 printf("i:mh=%p, mc=%p, mcp=%p, mcl=%d l=%d nl=%d # ",
1384 chan->out_mbuf_head,
1386 chan->out_mbuf_cur_ptr,
1387 chan->out_mbuf_cur_len,
1392 cmd |= HSCX_CMDR_XTF;
1393 /* collect the data in the scratch buffer */
1394 for (i = 0; i < nextlen; i++)
1395 scrbuf[i + len] = chan->out_mbuf_cur_ptr[i];
1398 chan->txcount += nextlen;
1400 chan->out_mbuf_cur_ptr += nextlen;
1401 chan->out_mbuf_cur_len -= nextlen;
1403 if(chan->out_mbuf_cur_len == 0)
1405 if((chan->out_mbuf_cur = chan->out_mbuf_cur->m_next) != NULL)
1407 chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data;
1408 chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len;
1410 if(sc->sc_trace & TRACE_B_TX)
1412 i4b_trace_hdr_t hdr;
1413 hdr.unit = L0IFPIUNIT(sc->sc_unit);
1414 hdr.type = (chan->channel == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2);
1416 hdr.count = ++sc->sc_trace_bcount;
1417 MICROTIME(hdr.time);
1418 i4b_l1_trace_ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data);
1423 if (chan->bprot != BPROT_NONE)
1424 cmd |= HSCX_CMDR_XME;
1425 i4b_Bfreembuf(chan->out_mbuf_head);
1426 chan->out_mbuf_head = NULL;
1430 /* write what we have from the scratch buf to the HSCX fifo */
1432 HSCX_WRFIFO(chan->channel, scrbuf, len);
1436 /*---------------------------------------------------------------------------*
1437 * ifpi - ISAC interrupt routine
1438 *---------------------------------------------------------------------------*/
1440 ifpi_isac_intr(struct l1_softc *sc)
1442 register u_char isac_irq_stat;
1446 /* get isac irq status */
1447 isac_irq_stat = ISAC_READ(I_ISTA);
1450 ifpi_isac_irq(sc, isac_irq_stat); /* isac handler */
1455 ISAC_WRITE(I_MASK, 0xff);
1459 ISAC_WRITE(I_MASK, ISAC_IMASK);
1462 /*---------------------------------------------------------------------------*
1463 * ifpi_recover - try to recover from irq lockup
1464 *---------------------------------------------------------------------------*/
1466 ifpi_recover(struct l1_softc *sc)
1470 /* get isac irq status */
1472 byte = ISAC_READ(I_ISTA);
1474 NDBGL1(L1_ERROR, " ISAC: ISTA = 0x%x", byte);
1476 if(byte & ISAC_ISTA_EXI)
1477 NDBGL1(L1_ERROR, " ISAC: EXIR = 0x%x", (u_char)ISAC_READ(I_EXIR));
1479 if(byte & ISAC_ISTA_CISQ)
1481 byte = ISAC_READ(I_CIRR);
1483 NDBGL1(L1_ERROR, " ISAC: CISQ = 0x%x", byte);
1485 if(byte & ISAC_CIRR_SQC)
1486 NDBGL1(L1_ERROR, " ISAC: SQRR = 0x%x", (u_char)ISAC_READ(I_SQRR));
1489 NDBGL1(L1_ERROR, " ISAC: IMASK = 0x%x", ISAC_IMASK);
1491 ISAC_WRITE(I_MASK, 0xff);
1493 ISAC_WRITE(I_MASK, ISAC_IMASK);