static int iavc_receive(iavc_softc_t *sc, u_int8_t *dmabuf, int b3data) { struct mbuf *m; u_int32_t ApplId, Length; /* * byte 0x21 = RECEIVE_MESSAGE * dword ApplId * dword length * ... CAPI msg * * --or-- * * byte 0x22 = RECEIVE_DATA_B3_IND * dword ApplId * dword length * ... CAPI msg * dword datalen * ... B3 data */ if (sc->sc_dma) { dmabuf = amcc_get_word(dmabuf, &ApplId); dmabuf = amcc_get_word(dmabuf, &Length); } else { ApplId = iavc_get_word(sc); Length = iavc_get_slice(sc, sc->sc_recvbuf); dmabuf = sc->sc_recvbuf; } m = i4b_Dgetmbuf(Length); if (!m) { aprint_error_dev(&sc->sc_dev, "can't get memory for receive\n"); return (ENOMEM); } memcpy(mtod(m, u_int8_t*), dmabuf, Length); #if 0 { u_int8_t *p = mtod(m, u_int8_t*); int len = 0; printf("%s: applid=%d, len=%d\n", device_xname(&sc->sc_dev), ApplId, Length); while (len < m->m_len) { printf(" %02x", p[len]); if (len && (len % 16) == 0) printf("\n"); len++; } if (len % 16) printf("\n"); } #endif if (b3data) { if (sc->sc_dma) { dmabuf = amcc_get_word(dmabuf + Length, &Length); } else { Length = iavc_get_slice(sc, sc->sc_recvbuf); dmabuf = sc->sc_recvbuf; } m->m_next = i4b_Bgetmbuf(Length); if (!m->m_next) { aprint_error_dev(&sc->sc_dev, "can't get memory for receive\n"); i4b_Dfreembuf(m); return (ENOMEM); } memcpy(mtod(m->m_next, u_int8_t*), dmabuf, Length); } capi_ll_receive(&sc->sc_capi, m); return 0; }
/*---------------------------------------------------------------------------* * write to rbch device *---------------------------------------------------------------------------*/ PDEVSTATIC int isdnbchanwrite(dev_t dev, struct uio * uio, int ioflag) { struct mbuf *m; int error = 0; int unit = minor(dev); struct rbch_softc *sc = &rbch_softc[unit]; int s; NDBGL4(L4_RBCHDBG, "unit %d, write", unit); s = splnet(); if(!(sc->sc_devstate & ST_ISOPEN)) { NDBGL4(L4_RBCHDBG, "unit %d, write while not open", unit); splx(s); return(EIO); } if((sc->sc_devstate & ST_NOBLOCK)) { if(!(sc->sc_devstate & ST_CONNECTED)) { splx(s); return(EWOULDBLOCK); } if(IF_QFULL(sc->sc_ilt->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) { splx(s); return(EWOULDBLOCK); } } else { while(!(sc->sc_devstate & ST_CONNECTED)) { NDBGL4(L4_RBCHDBG, "unit %d, write wait init", unit); error = tsleep((void *) &rbch_softc[unit], TTIPRI | PCATCH, "wrrbch", 0 ); if(error == ERESTART) { splx(s); return (ERESTART); } else if(error == EINTR) { splx(s); NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait init", unit); return(EINTR); } else if(error) { splx(s); NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep init", unit, error); return(error); } tsleep((void *) &rbch_softc[unit], TTIPRI | PCATCH, "xrbch", (hz*1)); } while(IF_QFULL(sc->sc_ilt->tx_queue) && (sc->sc_devstate & ST_ISOPEN)) { sc->sc_devstate |= ST_WRWAITEMPTY; NDBGL4(L4_RBCHDBG, "unit %d, write queue full", unit); if ((error = tsleep((void *) &sc->sc_ilt->tx_queue, TTIPRI | PCATCH, "wrbch", 0)) != 0) { sc->sc_devstate &= ~ST_WRWAITEMPTY; if(error == ERESTART) { splx(s); return(ERESTART); } else if(error == EINTR) { splx(s); NDBGL4(L4_RBCHDBG, "unit %d, EINTR during wait write", unit); return(error); } else if(error) { splx(s); NDBGL4(L4_RBCHDBG, "unit %d, error %d tsleep write", unit, error); return(error); } else if (!(sc->sc_devstate & ST_CONNECTED)) { splx(s); return 0; } } } } if(!(sc->sc_devstate & ST_ISOPEN)) { NDBGL4(L4_RBCHDBG, "unit %d, not open anymore", unit); splx(s); return(EIO); } if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL) { m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid); NDBGL4(L4_RBCHDBG, "unit %d, write %d bytes", unit, m->m_len); error = uiomove(m->m_data, m->m_len, uio); if(IF_QFULL(sc->sc_ilt->tx_queue)) { m_freem(m); } else { IF_ENQUEUE(sc->sc_ilt->tx_queue, m); } (*sc->sc_ilt->bchannel_driver->bch_tx_start)(sc->sc_ilt->l1token, sc->sc_ilt->channel); } splx(s); return(error); }
/*---------------------------------------------------------------------------* * get_trace_data_from_l1() * ------------------------ * is called from layer 1, adds timestamp to trace data and puts * it into a queue, from which it can be read from the i4btrc * device. The unit number in the trace header selects the minor * device's queue the data is put into. *---------------------------------------------------------------------------*/ int get_trace_data_from_l1(i4b_trace_hdr_t *hdr, int len, char *buf) { struct mbuf *m; int x; int unit; int trunc = 0; int totlen = len + sizeof(i4b_trace_hdr_t); /* * for telephony (or better non-HDLC HSCX mode) we get * (MCLBYTE + sizeof(i4b_trace_hdr_t)) length packets * to put into the queue to userland. because of this * we detect this situation, strip the length to MCLBYTES * max size, and infor the userland program of this fact * by putting the no of truncated bytes into hdr->trunc. */ if(totlen > MCLBYTES) { trunc = 1; hdr->trunc = totlen - MCLBYTES; totlen = MCLBYTES; } else { hdr->trunc = 0; } /* set length of trace record */ hdr->length = totlen; /* check valid unit no */ if((unit = hdr->unit) > NI4BTRC) { printf("i4b_trace: get_trace_data_from_l1 - unit > NI4BTRC!\n"); return(0); } /* get mbuf */ if(!(m = i4b_Bgetmbuf(totlen))) { printf("i4b_trace: get_trace_data_from_l1 - i4b_getmbuf() failed!\n"); return(0); } /* check if we are in analyzemode */ if(analyzemode && (unit == rxunit || unit == txunit)) { if(unit == rxunit) hdr->dir = FROM_NT; else hdr->dir = FROM_TE; unit = outunit; } IF_LOCK(&trace_queue[unit]); if(_IF_QFULL(&trace_queue[unit])) { struct mbuf *m1; x = SPLI4B(); _IF_DEQUEUE(&trace_queue[unit], m1); splx(x); i4b_Bfreembuf(m1); } /* copy trace header */ memcpy(m->m_data, hdr, sizeof(i4b_trace_hdr_t)); /* copy trace data */ if(trunc) memcpy(&m->m_data[sizeof(i4b_trace_hdr_t)], buf, totlen-sizeof(i4b_trace_hdr_t)); else memcpy(&m->m_data[sizeof(i4b_trace_hdr_t)], buf, len); x = SPLI4B(); _IF_ENQUEUE(&trace_queue[unit], m); IF_UNLOCK(&trace_queue[unit]); if(device_state[unit] & ST_WAITDATA) { device_state[unit] &= ~ST_WAITDATA; wakeup((caddr_t) &trace_queue[unit]); } splx(x); return(1); }
/*---------------------------------------------------------------------------* * B-channel interrupt handler *---------------------------------------------------------------------------*/ void iwic_bchan_xirq(struct iwic_softc *sc, int chan_no) { int irq_stat; struct iwic_bchan *chan; int cmd = 0; int activity = 0; chan = &sc->sc_bchan[chan_no]; irq_stat = IWIC_READ(sc, chan->offset + B_EXIR); NDBGL1(L1_H_IRQ, "irq_stat = 0x%x", irq_stat); if((irq_stat & (B_EXIR_RMR | B_EXIR_RME | B_EXIR_RDOV | B_EXIR_XFR | B_EXIR_XDUN)) == 0) { NDBGL1(L1_H_XFRERR, "spurious IRQ!"); return; } if (irq_stat & B_EXIR_RDOV) { NDBGL1(L1_H_XFRERR, "iwic%d: EXIR B-channel Receive Data Overflow", sc->sc_unit); } if (irq_stat & B_EXIR_XDUN) { NDBGL1(L1_H_XFRERR, "iwic%d: EXIR B-channel Transmit Data Underrun", sc->sc_unit); cmd |= (B_CMDR_XRST); /*XXX must retransmit frame ! */ } /* RX message end interrupt */ if(irq_stat & B_EXIR_RME) { int error; NDBGL1(L1_H_IRQ, "B_EXIR_RME"); error = (IWIC_READ(sc,chan->offset+B_STAR) & (B_STAR_RDOV | B_STAR_CRCE | B_STAR_RMB)); if(error) { if(error & B_STAR_RDOV) NDBGL1(L1_H_XFRERR, "iwic%d: B-channel Receive Data Overflow", sc->sc_unit); if(error & B_STAR_CRCE) NDBGL1(L1_H_XFRERR, "iwic%d: B-channel CRC Error", sc->sc_unit); if(error & B_STAR_RMB) NDBGL1(L1_H_XFRERR, "iwic%d: B-channel Receive Message Aborted", sc->sc_unit); } /* all error conditions checked, now decide and take action */ if(error == 0) { int fifo_data_len; fifo_data_len = ((IWIC_READ(sc,chan->offset+B_RBCL)) & ((IWIC_BCHAN_FIFO_LEN)-1)); if(fifo_data_len == 0) fifo_data_len = IWIC_BCHAN_FIFO_LEN; if(chan->in_mbuf == NULL) { if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 iwic_bchan_irq: RME, cannot allocate mbuf!\n"); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } if((chan->in_len + fifo_data_len) <= BCH_MAX_DATALEN) { /* read data from fifo */ NDBGL1(L1_H_IRQ, "B_EXIR_RME, rd fifo, len = %d", fifo_data_len); IWIC_RDBFIFO(sc, chan, chan->in_cbptr, fifo_data_len); cmd |= (B_CMDR_RACK | B_CMDR_RACT); IWIC_WRITE(sc, chan->offset + B_CMDR, cmd); cmd = 0; chan->in_len += fifo_data_len; chan->rxcount += fifo_data_len; /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr_t hdr; hdr.unit = L0IWICUNIT(sc->sc_unit); hdr.type = (chan_no == IWIC_BCH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_bchan[chan_no].sc_trace_bcount; MICROTIME(hdr.time); i4b_l1_trace_ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data); } (*chan->iwic_drvr_linktab->bch_rx_data_ready)(chan->iwic_drvr_linktab->unit); activity = ACT_RX; /* mark buffer ptr as unused */ chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } else { NDBGL1(L1_H_XFRERR, "RAWHDLC rx buffer overflow in RME, in_len=%d, fifolen=%d", chan->in_len, fifo_data_len); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; cmd |= (B_CMDR_RRST | B_CMDR_RACK); } } else { if (chan->in_mbuf != NULL) { i4b_Bfreembuf(chan->in_mbuf); chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } cmd |= (B_CMDR_RRST | B_CMDR_RACK); } } /* RX fifo full interrupt */ if(irq_stat & B_EXIR_RMR) { NDBGL1(L1_H_IRQ, "B_EXIR_RMR"); if(chan->in_mbuf == NULL) { if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 iwic_bchan_irq: RMR, cannot allocate mbuf!\n"); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } chan->rxcount += IWIC_BCHAN_FIFO_LEN; if((chan->in_len + IWIC_BCHAN_FIFO_LEN) <= BCH_MAX_DATALEN) { /* read data from fifo */ NDBGL1(L1_H_IRQ, "B_EXIR_RMR, rd fifo, len = max (64)"); IWIC_RDBFIFO(sc, chan, chan->in_cbptr, IWIC_BCHAN_FIFO_LEN); chan->in_cbptr += IWIC_BCHAN_FIFO_LEN; chan->in_len += IWIC_BCHAN_FIFO_LEN; } else { if(chan->bprot == BPROT_NONE) { /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr_t hdr; hdr.unit = L0IWICUNIT(sc->sc_unit); hdr.type = (chan_no == IWIC_BCH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_bchan[chan_no].sc_trace_bcount; MICROTIME(hdr.time); i4b_l1_trace_ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data); } /* silence detection */ if(!(i4b_l1_bchan_tel_silence(chan->in_mbuf->m_data, chan->in_mbuf->m_len))) activity = ACT_RX; if(!(IF_QFULL(&chan->rx_queue))) { IF_ENQUEUE(&chan->rx_queue, chan->in_mbuf); } else { i4b_Bfreembuf(chan->in_mbuf); } /* signal upper driver that data is available */ (*chan->iwic_drvr_linktab->bch_rx_data_ready)(chan->iwic_drvr_linktab->unit); /* alloc new buffer */ if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 iwic_bchan_irq: RMR, cannot allocate new mbuf!\n"); /* setup new data ptr */ chan->in_cbptr = chan->in_mbuf->m_data; /* read data from fifo */ NDBGL1(L1_H_IRQ, "B_EXIR_RMR, rd fifo1, len = max (64)"); IWIC_RDBFIFO(sc, chan, chan->in_cbptr, IWIC_BCHAN_FIFO_LEN); chan->in_cbptr += IWIC_BCHAN_FIFO_LEN; chan->in_len = IWIC_BCHAN_FIFO_LEN; chan->rxcount += IWIC_BCHAN_FIFO_LEN; } else { NDBGL1(L1_H_XFRERR, "RAWHDLC rx buffer overflow in RPF, in_len=%d", chan->in_len); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; cmd |= (B_CMDR_RRST | B_CMDR_RACK); } } /* command to release fifo space */ cmd |= B_CMDR_RACK; } /* TX interrupt */ if (irq_stat & B_EXIR_XFR) { /* transmit fifo empty, new data can be written to fifo */ int activity = -1; int len; int nextlen; NDBGL1(L1_H_IRQ, "B_EXIR_XFR"); if(chan->out_mbuf_cur == NULL) /* last frame is transmitted */ { IF_DEQUEUE(&chan->tx_queue, chan->out_mbuf_head); if(chan->out_mbuf_head == NULL) { chan->state &= ~ST_TX_ACTIVE; (*chan->iwic_drvr_linktab->bch_tx_queue_empty)(chan->iwic_drvr_linktab->unit); } else { chan->state |= ST_TX_ACTIVE; chan->out_mbuf_cur = chan->out_mbuf_head; chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data; chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len; if(sc->sc_trace & TRACE_B_TX) { i4b_trace_hdr_t hdr; hdr.unit = L0IWICUNIT(sc->sc_unit); hdr.type = (chan_no == IWIC_BCH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_TE; hdr.count = ++sc->sc_bchan[chan_no].sc_trace_bcount; MICROTIME(hdr.time); i4b_l1_trace_ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data); } if(chan->bprot == BPROT_NONE) { if(!(i4b_l1_bchan_tel_silence(chan->out_mbuf_cur->m_data, chan->out_mbuf_cur->m_len))) activity = ACT_TX; } else { activity = ACT_TX; } } } len = 0; while(chan->out_mbuf_cur && len != IWIC_BCHAN_FIFO_LEN) { nextlen = min(chan->out_mbuf_cur_len, IWIC_BCHAN_FIFO_LEN - len); NDBGL1(L1_H_IRQ, "B_EXIR_XFR, wr fifo, len = %d", nextlen); IWIC_WRBFIFO(sc, chan, chan->out_mbuf_cur_ptr, nextlen); cmd |= B_CMDR_XMS; len += nextlen; chan->txcount += nextlen; chan->out_mbuf_cur_ptr += nextlen; chan->out_mbuf_cur_len -= nextlen; if(chan->out_mbuf_cur_len == 0) { if((chan->out_mbuf_cur = chan->out_mbuf_cur->m_next) != NULL) { chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data; chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len; if(sc->sc_trace & TRACE_B_TX) { i4b_trace_hdr_t hdr; hdr.unit = L0IWICUNIT(sc->sc_unit); hdr.type = (chan_no == IWIC_BCH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_TE; hdr.count = ++sc->sc_bchan[chan_no].sc_trace_bcount; MICROTIME(hdr.time); i4b_l1_trace_ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data); } } else { if (chan->bprot != BPROT_NONE) cmd |= B_CMDR_XME; i4b_Bfreembuf(chan->out_mbuf_head); chan->out_mbuf_head = NULL; } } } } if(cmd) { cmd |= B_CMDR_RACT; IWIC_WRITE(sc, chan->offset + B_CMDR, cmd); } }
/*---------------------------------------------------------------------------* * HSCX IRQ Handler *---------------------------------------------------------------------------*/ void isic_hscx_irq(register struct isic_softc *sc, u_char ista, int h_chan, u_char ex_irq) { register l1_bchan_state_t *chan = &sc->sc_chan[h_chan]; u_char exir = 0; int activity = -1; u_char cmd = 0; NDBGL1(L1_H_IRQ, "%#x", ista); if(ex_irq) { /* get channel extended irq reg */ exir = HSCX_READ(h_chan, H_EXIR); if(exir & HSCX_EXIR_RFO) { chan->stat_RFO++; NDBGL1(L1_H_XFRERR, "ex_irq: receive data overflow"); } if((exir & HSCX_EXIR_XDU) && (chan->bprot != BPROT_NONE))/* xmit data underrun */ { chan->stat_XDU++; NDBGL1(L1_H_XFRERR, "ex_irq: xmit data underrun"); isic_hscx_cmd(sc, h_chan, HSCX_CMDR_XRES); if (chan->out_mbuf_head != NULL) /* don't continue to transmit this buffer */ { i4b_Bfreembuf(chan->out_mbuf_head); chan->out_mbuf_cur = chan->out_mbuf_head = NULL; } } } /* rx message end, end of frame */ if(ista & HSCX_ISTA_RME) { register int fifo_data_len; u_char rsta; int error = 0; rsta = HSCX_READ(h_chan, H_RSTA); if((rsta & 0xf0) != 0xa0) { if((rsta & HSCX_RSTA_VFR) == 0) { chan->stat_VFR++; cmd |= (HSCX_CMDR_RHR); NDBGL1(L1_H_XFRERR, "received invalid Frame"); error++; } if(rsta & HSCX_RSTA_RDO) { chan->stat_RDO++; NDBGL1(L1_H_XFRERR, "receive data overflow"); error++; } if((rsta & HSCX_RSTA_CRC) == 0) { chan->stat_CRC++; cmd |= (HSCX_CMDR_RHR); NDBGL1(L1_H_XFRERR, "CRC check failed"); error++; } if(rsta & HSCX_RSTA_RAB) { chan->stat_RAB++; NDBGL1(L1_H_XFRERR, "Receive message aborted"); error++; } } fifo_data_len = ((HSCX_READ(h_chan, H_RBCL)) & ((sc->sc_bfifolen)-1)); if(fifo_data_len == 0) fifo_data_len = sc->sc_bfifolen; /* all error conditions checked, now decide and take action */ if(error == 0) { if(chan->in_mbuf == NULL) { if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 isic_hscx_irq: RME, cannot allocate mbuf!"); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } fifo_data_len -= 1; /* last byte in fifo is RSTA ! */ if((chan->in_len + fifo_data_len) <= BCH_MAX_DATALEN) { /* read data from HSCX fifo */ HSCX_RDFIFO(h_chan, chan->in_cbptr, fifo_data_len); cmd |= (HSCX_CMDR_RMC); isic_hscx_cmd(sc, h_chan, cmd); cmd = 0; chan->in_len += fifo_data_len; chan->rxcount += fifo_data_len; /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr hdr; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_trace_bcount; isdn_layer2_trace_ind(&sc->sc_l2, sc->sc_l3token, &hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data); } (*chan->l4_driver->bch_rx_data_ready)(chan->l4_driver_softc); activity = ACT_RX; /* mark buffer ptr as unused */ chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } else { NDBGL1(L1_H_XFRERR, "RAWHDLC rx buffer overflow in RME, in_len=%d, fifolen=%d", chan->in_len, fifo_data_len); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; cmd |= (HSCX_CMDR_RHR | HSCX_CMDR_RMC); } } else { if (chan->in_mbuf != NULL) { i4b_Bfreembuf(chan->in_mbuf); chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } cmd |= (HSCX_CMDR_RMC); } } /* rx fifo full */ if(ista & HSCX_ISTA_RPF) { if(chan->in_mbuf == NULL) { if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 isic_hscx_irq: RPF, cannot allocate mbuf!"); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } chan->rxcount += sc->sc_bfifolen; if((chan->in_len + sc->sc_bfifolen) <= BCH_MAX_DATALEN) { /* read data from HSCX fifo */ HSCX_RDFIFO(h_chan, chan->in_cbptr, sc->sc_bfifolen); chan->in_cbptr += sc->sc_bfifolen; chan->in_len += sc->sc_bfifolen; } else { if(chan->bprot == BPROT_NONE) { /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr hdr; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_trace_bcount; isdn_layer2_trace_ind(&sc->sc_l2, sc->sc_l3token, &hdr,chan->in_mbuf->m_len, chan->in_mbuf->m_data); } /* silence detection */ if(!(isdn_bchan_silence(chan->in_mbuf->m_data, chan->in_mbuf->m_len))) activity = ACT_RX; if(!(IF_QFULL(&chan->rx_queue))) { IF_ENQUEUE(&chan->rx_queue, chan->in_mbuf); } else { i4b_Bfreembuf(chan->in_mbuf); } /* signal upper driver that data is available */ (*chan->l4_driver->bch_rx_data_ready)(chan->l4_driver_softc); /* alloc new buffer */ if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 isic_hscx_irq: RPF, cannot allocate new mbuf!"); /* setup new data ptr */ chan->in_cbptr = chan->in_mbuf->m_data; /* read data from HSCX fifo */ HSCX_RDFIFO(h_chan, chan->in_cbptr, sc->sc_bfifolen); chan->in_cbptr += sc->sc_bfifolen; chan->in_len = sc->sc_bfifolen; chan->rxcount += sc->sc_bfifolen; } else { NDBGL1(L1_H_XFRERR, "RAWHDLC rx buffer overflow in RPF, in_len=%d", chan->in_len); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; cmd |= (HSCX_CMDR_RHR); } } /* command to release fifo space */ cmd |= HSCX_CMDR_RMC; } /* transmit fifo empty, new data can be written to fifo */ if(ista & HSCX_ISTA_XPR) { /* * for a description what is going on here, please have * a look at isic_bchannel_start() in i4b_bchan.c ! */ int len; int nextlen; NDBGL1(L1_H_IRQ, "%s, chan %d - XPR, Tx Fifo Empty!", device_xname(sc->sc_dev), h_chan); if(chan->out_mbuf_cur == NULL) /* last frame is transmitted */ { IF_DEQUEUE(&chan->tx_queue, chan->out_mbuf_head); if(chan->out_mbuf_head == NULL) { chan->state &= ~HSCX_TX_ACTIVE; (*chan->l4_driver->bch_tx_queue_empty)(chan->l4_driver_softc); } else { chan->state |= HSCX_TX_ACTIVE; chan->out_mbuf_cur = chan->out_mbuf_head; chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data; chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len; if(sc->sc_trace & TRACE_B_TX) { i4b_trace_hdr hdr; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_TE; hdr.count = ++sc->sc_trace_bcount; isdn_layer2_trace_ind(&sc->sc_l2, sc->sc_l3token, &hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data); } if(chan->bprot == BPROT_NONE) { if(!(isdn_bchan_silence(chan->out_mbuf_cur->m_data, chan->out_mbuf_cur->m_len))) activity = ACT_TX; } else { activity = ACT_TX; } } } len = 0; while(chan->out_mbuf_cur && len != sc->sc_bfifolen) { nextlen = min(chan->out_mbuf_cur_len, sc->sc_bfifolen - len); #ifdef NOTDEF printf("i:mh=%x, mc=%x, mcp=%x, mcl=%d l=%d nl=%d # ", chan->out_mbuf_head, chan->out_mbuf_cur, chan->out_mbuf_cur_ptr, chan->out_mbuf_cur_len, len, next_len); #endif isic_hscx_waitxfw(sc, h_chan); /* necessary !!! */ HSCX_WRFIFO(h_chan, chan->out_mbuf_cur_ptr, nextlen); cmd |= HSCX_CMDR_XTF; len += nextlen; chan->txcount += nextlen; chan->out_mbuf_cur_ptr += nextlen; chan->out_mbuf_cur_len -= nextlen; if(chan->out_mbuf_cur_len == 0) { if((chan->out_mbuf_cur = chan->out_mbuf_cur->m_next) != NULL) { chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data; chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len; if(sc->sc_trace & TRACE_B_TX) { i4b_trace_hdr hdr; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_TE; hdr.count = ++sc->sc_trace_bcount; isdn_layer2_trace_ind(&sc->sc_l2, sc->sc_l3token, &hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data); } } else { if (chan->bprot != BPROT_NONE) cmd |= HSCX_CMDR_XME; i4b_Bfreembuf(chan->out_mbuf_head); chan->out_mbuf_head = NULL; } } } } if(cmd) /* is there a command for the HSCX ? */ { isic_hscx_cmd(sc, h_chan, cmd); /* yes, to HSCX */ } /* call timeout handling routine */ if(activity == ACT_RX || activity == ACT_TX) (*chan->l4_driver->bch_activity)(chan->l4_driver_softc, activity); }
/* * this is the real interrupt routine */ static void avm_pnp_hscx_intr(int h_chan, int stat, int cnt, struct isic_softc *sc) { register isic_Bchan_t *chan = &sc->sc_chan[h_chan]; int activity = -1; DBGL1(L1_H_IRQ, "avm_pnp_hscx_intr", ("%#x\n", stat)); if((stat & HSCX_INT_XDU) && (chan->bprot != BPROT_NONE))/* xmit data underrun */ { chan->stat_XDU++; DBGL1(L1_H_XFRERR, "avm_pnp_hscx_intr", ("xmit data underrun\n")); /* abort the transmission */ sc->avma1pp_txl = 0; sc->avma1pp_cmd |= HSCX_CMD_XRS; hscx_write_reg(h_chan, HSCX_STAT, sc, 1); sc->avma1pp_cmd &= ~HSCX_CMD_XRS; hscx_write_reg(h_chan, HSCX_STAT, sc, 1); if (chan->out_mbuf_head != NULL) /* don't continue to transmit this buffer */ { i4b_Bfreembuf(chan->out_mbuf_head); chan->out_mbuf_cur = chan->out_mbuf_head = NULL; } } /* * The following is based on examination of the Linux driver. * * The logic here is different than with a "real" HSCX; all kinds * of information (interrupt/status bits) are in stat. * HSCX_INT_RPR indicates a receive interrupt * HSCX_STAT_RDO indicates an overrun condition, abort - * otherwise read the bytes ((stat & HSCX_STZT_RML_MASK) >> 8) * HSCX_STAT_RME indicates end-of-frame and apparently any * CRC/framing errors are only reported in this state. * if ((stat & HSCX_STAT_CRCVFRRAB) != HSCX_STAT_CRCVFR) * CRC/framing error */ if(stat & HSCX_INT_RPR) { register int fifo_data_len; int error = 0; /* always have to read the FIFO, so use a scratch buffer */ u_char scrbuf[HSCX_FIFO_LEN]; if(stat & HSCX_STAT_RDO) { chan->stat_RDO++; DBGL1(L1_H_XFRERR, "avm_pnp_hscx_intr", ("receive data overflow\n")); error++; } fifo_data_len = cnt; if(fifo_data_len == 0) fifo_data_len = sc->sc_bfifolen; /* ALWAYS read data from HSCX fifo */ HSCX_RDFIFO(h_chan, scrbuf, fifo_data_len); chan->rxcount += fifo_data_len; /* all error conditions checked, now decide and take action */ if(error == 0) { if(chan->in_mbuf == NULL) { if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 avm_pnp_hscx_intr: RME, cannot allocate mbuf!\n"); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } if((chan->in_len + fifo_data_len) <= BCH_MAX_DATALEN) { /* OK to copy the data */ bcopy(scrbuf, chan->in_cbptr, fifo_data_len); chan->in_cbptr += fifo_data_len; chan->in_len += fifo_data_len; /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr_t hdr; hdr.unit = sc->sc_unit; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_trace_bcount; MICROTIME(hdr.time); MPH_Trace_Ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data); } if (stat & HSCX_STAT_RME) { if((stat & HSCX_STAT_CRCVFRRAB) == HSCX_STAT_CRCVFR) { (*chan->drvr_linktab->bch_rx_data_ready)(chan->drvr_linktab->unit); activity = ACT_RX; /* mark buffer ptr as unused */ chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } else { chan->stat_CRC++; DBGL1(L1_H_XFRERR, "avm_pnp_hscx_intr", ("CRC/RAB\n")); if (chan->in_mbuf != NULL) { i4b_Bfreembuf(chan->in_mbuf); chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } } } } /* END enough space in mbuf */ else { if(chan->bprot == BPROT_NONE) { /* setup mbuf data length */ chan->in_mbuf->m_len = chan->in_len; chan->in_mbuf->m_pkthdr.len = chan->in_len; if(sc->sc_trace & TRACE_B_RX) { i4b_trace_hdr_t hdr; hdr.unit = sc->sc_unit; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_NT; hdr.count = ++sc->sc_trace_bcount; MICROTIME(hdr.time); MPH_Trace_Ind(&hdr, chan->in_mbuf->m_len, chan->in_mbuf->m_data); } /* move rx'd data to rx queue */ IF_ENQUEUE(&chan->rx_queue, chan->in_mbuf); (*chan->drvr_linktab->bch_rx_data_ready)(chan->drvr_linktab->unit); if(!(isic_hscx_silence(chan->in_mbuf->m_data, chan->in_mbuf->m_len))) activity = ACT_RX; /* alloc new buffer */ if((chan->in_mbuf = i4b_Bgetmbuf(BCH_MAX_DATALEN)) == NULL) panic("L1 avm_pnp_hscx_intr: RPF, cannot allocate new mbuf!\n"); /* setup new data ptr */ chan->in_cbptr = chan->in_mbuf->m_data; /* OK to copy the data */ bcopy(scrbuf, chan->in_cbptr, fifo_data_len); chan->in_cbptr += fifo_data_len; chan->in_len = fifo_data_len; chan->rxcount += fifo_data_len; } else { DBGL1(L1_H_XFRERR, "avm_pnp_hscx_intr", ("RAWHDLC rx buffer overflow in RPF, in_len=%d\n", chan->in_len)); chan->in_cbptr = chan->in_mbuf->m_data; chan->in_len = 0; } } } /* if(error == 0) */ else { /* land here for RDO */ if (chan->in_mbuf != NULL) { i4b_Bfreembuf(chan->in_mbuf); chan->in_mbuf = NULL; chan->in_cbptr = NULL; chan->in_len = 0; } sc->avma1pp_txl = 0; sc->avma1pp_cmd |= HSCX_CMD_RRS; hscx_write_reg(h_chan, HSCX_STAT, sc, 1); sc->avma1pp_cmd &= ~HSCX_CMD_RRS; hscx_write_reg(h_chan, HSCX_STAT, sc, 1); } } /* transmit fifo empty, new data can be written to fifo */ if(stat & HSCX_INT_XPR) { /* * for a description what is going on here, please have * a look at isic_bchannel_start() in i4b_bchan.c ! */ DBGL1(L1_H_IRQ, "avm_pnp_hscx_intr", ("unit %d, chan %d - XPR, Tx Fifo Empty!\n", sc->sc_unit, h_chan)); if(chan->out_mbuf_cur == NULL || chan->out_mbuf_head == NULL) /* last frame is transmitted */ { IF_DEQUEUE(&chan->tx_queue, chan->out_mbuf_head); if(chan->out_mbuf_head == NULL) { chan->state &= ~HSCX_TX_ACTIVE; (*chan->drvr_linktab->bch_tx_queue_empty)(chan->drvr_linktab->unit); } else { chan->state |= HSCX_TX_ACTIVE; chan->out_mbuf_cur = chan->out_mbuf_head; chan->out_mbuf_cur_ptr = chan->out_mbuf_cur->m_data; chan->out_mbuf_cur_len = chan->out_mbuf_cur->m_len; if(sc->sc_trace & TRACE_B_TX) { i4b_trace_hdr_t hdr; hdr.unit = sc->sc_unit; hdr.type = (h_chan == HSCX_CH_A ? TRC_CH_B1 : TRC_CH_B2); hdr.dir = FROM_TE; hdr.count = ++sc->sc_trace_bcount; MICROTIME(hdr.time); MPH_Trace_Ind(&hdr, chan->out_mbuf_cur->m_len, chan->out_mbuf_cur->m_data); } if(chan->bprot == BPROT_NONE) { if(!(isic_hscx_silence(chan->out_mbuf_cur->m_data, chan->out_mbuf_cur->m_len))) activity = ACT_TX; } else { activity = ACT_TX; } } } isic_hscx_fifo(chan, sc); } /* call timeout handling routine */ if(activity == ACT_RX || activity == ACT_TX) (*chan->drvr_linktab->bch_activity)(chan->drvr_linktab->unit, activity); }
/*---------------------------------------------------------------------------* * isdn_layer2_trace_ind * --------------------- * is called from layer 1, adds timestamp to trace data and puts * it into a queue, from which it can be read from the i4btrc * device. The unit number in the trace header selects the minor * device's queue the data is put into. *---------------------------------------------------------------------------*/ int isdn_layer2_trace_ind(struct l2_softc *sc, struct isdn_l3_driver *drv, i4b_trace_hdr *hdr, size_t len, unsigned char *buf) { struct mbuf *m; int bri, x; int trunc = 0; int totlen = len + sizeof(i4b_trace_hdr); MICROTIME(hdr->time); hdr->bri = sc->drv->bri; /* * for telephony (or better non-HDLC HSCX mode) we get * (MCLBYTE + sizeof(i4b_trace_hdr_t)) length packets * to put into the queue to userland. because of this * we detect this situation, strip the length to MCLBYTES * max size, and infor the userland program of this fact * by putting the no of truncated bytes into hdr->trunc. */ if(totlen > MCLBYTES) { trunc = 1; hdr->trunc = totlen - MCLBYTES; totlen = MCLBYTES; } else { hdr->trunc = 0; } /* set length of trace record */ hdr->length = totlen; /* check valid interface */ if((bri = hdr->bri) > NISDNTRC) { printf("i4b_trace: get_trace_data_from_l1 - bri > NISDNTRC!\n"); return(0); } /* get mbuf */ if(!(m = i4b_Bgetmbuf(totlen))) { printf("i4b_trace: get_trace_data_from_l1 - i4b_getmbuf() failed!\n"); return(0); } /* check if we are in analyzemode */ if(analyzemode && (bri == rxunit || bri == txunit)) { if(bri == rxunit) hdr->dir = FROM_NT; else hdr->dir = FROM_TE; bri = outunit; } if(IF_QFULL(&trace_queue[bri])) { struct mbuf *m1; x = splnet(); IF_DEQUEUE(&trace_queue[bri], m1); splx(x); i4b_Bfreembuf(m1); } /* copy trace header */ memcpy(m->m_data, hdr, sizeof(i4b_trace_hdr)); /* copy trace data */ if(trunc) memcpy(&m->m_data[sizeof(i4b_trace_hdr)], buf, totlen-sizeof(i4b_trace_hdr)); else memcpy(&m->m_data[sizeof(i4b_trace_hdr)], buf, len); x = splnet(); IF_ENQUEUE(&trace_queue[bri], m); if(device_state[bri] & ST_WAITDATA) { device_state[bri] &= ~ST_WAITDATA; wakeup((caddr_t) &trace_queue[bri]); } splx(x); return(1); }
/*---------------------------------------------------------------------------* * write to tel device *---------------------------------------------------------------------------*/ PDEVSTATIC int i4btelwrite(dev_t dev, struct uio * uio, int ioflag) { struct mbuf *m; int s; int error = 0; tel_sc_t *sc = &tel_sc[minor(dev)]; if(!(sc->devstate & ST_CONNECTED)) return(EIO); if(!(sc->devstate & ST_ISOPEN)) { return(EIO); } #ifdef NOTDEF while(!(sc->devstate & ST_CONNECTED)) { if((error = tsleep((caddr_t) &sc->devstate, TTIPRI | PCATCH, "wrtel", 0 )) != 0) { return(error); } /* * XXX the originations B channel gets much earlier * switched thru than the destinations B channel, so * if the origination starts to send at once, some * 200 bytes (at my site) or so get lost, so i delay * a bit before sending. (-hm) */ tsleep((caddr_t) &sc->devstate, TTIPRI | PCATCH, "xtel", (hz*1)); } #endif while((IF_QFULL(sc->isdn_linktab->tx_queue)) && (sc->devstate & ST_ISOPEN)) { sc->devstate |= ST_WRWAITEMPTY; if((error = tsleep((caddr_t) &sc->isdn_linktab->tx_queue, TTIPRI | PCATCH, "wtel", 0)) != 0) { sc->devstate &= ~ST_WRWAITEMPTY; return(error); } } if(!(sc->devstate & ST_ISOPEN)) { return(EIO); } if(!(sc->devstate & ST_CONNECTED)) { return(EIO); } s = splimp(); if((m = i4b_Bgetmbuf(BCH_MAX_DATALEN)) != NULL) { m->m_len = min(BCH_MAX_DATALEN, uio->uio_resid); error = uiomove(m->m_data, m->m_len, uio); if(sc->audiofmt == CVT_ALAW2ULAW) { int i; for(i = 0; i < m->m_len; i++) m->m_data[i] = ulaw_alaw[(int)m->m_data[i]]; } IF_ENQUEUE(sc->isdn_linktab->tx_queue, m); (*sc->isdn_linktab->bch_tx_start)(sc->isdn_linktab->unit, sc->isdn_linktab->channel); } splx(s); return(error); }