2 * Copyright (c) 2000 Hans Petter Selasky. 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
25 *---------------------------------------------------------------------------
27 * i4b_ihfc_l1.c - hfc layer 1 handler
28 * -----------------------------------
30 * The idea of this file is to separate hfcs/sp/pci data/signal
31 * handling and the I4B data/signal handling.
33 * Everything which has got anything to do with I4B has been put here!
35 * last edit-date: [Wed Jul 19 09:41:03 2000]
37 * $Id: i4b_ihfc_l1if.c,v 1.10 2000/09/19 13:50:36 hm Exp $
39 * $FreeBSD: src/sys/i4b/layer1/ihfc/i4b_ihfc_l1if.c,v 1.7.2.1 2001/08/10 14:08:37 obrien Exp $
41 *---------------------------------------------------------------------------*/
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
51 #include <sys/socket.h>
56 #include <machine/i4b_debug.h>
57 #include <machine/i4b_ioctl.h>
58 #include <machine/i4b_trace.h>
60 #include <i4b/include/i4b_mbuf.h>
61 #include <i4b/include/i4b_global.h>
63 #include <i4b/layer1/i4b_l1.h>
64 #include <i4b/layer1/ihfc/i4b_ihfc.h>
65 #include <i4b/layer1/ihfc/i4b_ihfc_ext.h>
67 /*---------------------------------------------------------------------------*
70 * NOTE: The prototypes for get/putmbuf and B_linkinit
71 * have been put in i4b_hfc_ext.h for global hfc use.
73 * NOTE: channel != chan
74 *---------------------------------------------------------------------------*/
76 isdn_link_t * ihfc_B_ret_linktab (int unit, int channel);
77 static void ihfc_B_set_linktab (int unit, int channel, drvr_link_t *B_linktab);
79 static void ihfc_B_start (int unit, int chan);
80 static void ihfc_B_stat (int unit, int chan, bchan_statistics_t *bsp);
81 void ihfc_B_setup (int unit, int chan, int bprot, int activate);
83 static int ihfc_mph_command_req (int unit, int command, void *parm);
85 static int ihfc_ph_activate_req (int unit);
86 static int ihfc_ph_data_req (int unit, struct mbuf *m, int freeflag);
88 static void ihfc_T3_expired (ihfc_sc_t *sc);
90 /*---------------------------------------------------------------------------*
91 * Our I4B L1 mulitplexer link
92 *---------------------------------------------------------------------------*/
93 struct i4b_l1mux_func ihfc_l1mux_func = {
101 /*---------------------------------------------------------------------------*
102 * L2 -> L1: PH-DATA-REQUEST (D-Channel)
104 * NOTE: We may get called here from ihfc_hdlc_Dread or isac_hdlc_Dread
105 * via the upper layers.
106 *---------------------------------------------------------------------------*/
108 ihfc_ph_data_req(int unit, struct mbuf *m, int freeflag)
110 ihfc_sc_t *sc = &ihfc_softc[unit];
120 NDBGL1(L1_PRIM, "L1 was not running: "
121 "ihfc_ph_activate_req(unit = %d)!", unit);
123 ihfc_ph_activate_req(unit);
126 /* "Allow" I-frames (-hp) */
128 if (freeflag == MBUF_DONTFREE) m = m_copypacket(m, M_DONTWAIT);
130 if (!_IF_QFULL(&S_IFQUEUE) && m)
132 IF_ENQUEUE(&S_IFQUEUE, m);
134 ihfc_B_start(unit, chan); /* (recycling) */
138 NDBGL1(L1_ERROR, "No frame out (unit = %d)", unit);
139 if (m) i4b_Dfreembuf(m);
145 if (S_INTR_ACTIVE) S_INT_S1 |= 0x04;
152 /*---------------------------------------------------------------------------*
153 * L2 -> L1: PH-ACTIVATE-REQUEST (B-channel and D-channel)
154 *---------------------------------------------------------------------------*/
156 ihfc_ph_activate_req(int unit)
158 ihfc_sc_t *sc = &ihfc_softc[unit];
163 if ((!S_STM_T3) && (S_PHSTATE != 3))
168 S_STM_T3CALLOUT = timeout((TIMEOUT_FUNC_T)
169 ihfc_T3_expired, (ihfc_sc_t *)sc,
170 IHFC_ACTIVATION_TIMEOUT);
176 /*---------------------------------------------------------------------------*
177 * T3 timeout - persistant deactivation
178 *---------------------------------------------------------------------------*/
180 ihfc_T3_expired(ihfc_sc_t *sc)
189 if (S_PHSTATE != 3) /* line was not activated */
191 i4b_Dcleanifq(&S_IFQUEUE);
192 i4b_l1_ph_deactivate_ind(S_I4BUNIT);
194 i4b_l1_mph_status_ind(S_I4BUNIT, STI_PDEACT, 0, 0);
196 HFC_FSM(sc, 2); /* L1 deactivate */
202 /*---------------------------------------------------------------------------*
203 * Command from the upper layers (B-channel and D-channel)
204 *---------------------------------------------------------------------------*/
206 ihfc_mph_command_req(int unit, int command, void *parm)
208 ihfc_sc_t *sc = &ihfc_softc[unit];
212 case CMR_DOPEN: /* daemon running */
214 "unit %d, command = CMR_DOPEN", unit);
218 case CMR_DCLOSE: /* daemon not running */
220 "unit %d, command = CMR_DCLOSE", unit);
224 case CMR_SETTRACE: /* set new trace mask */
226 "unit %d, command = CMR_SETTRACE, parm = %d",
227 unit, (unsigned int)parm);
228 S_TRACE = (unsigned int)parm;
231 case CMR_GCST: /* get chip statistic */
233 "unit %d, command = CMR_GCST, parm = %d",
234 unit, (unsigned int)parm);
236 #define CST ((struct chipstat *)parm)
238 CST->driver_type = L1DRVR_IHFC;
240 /* XXX CST->xxxx_stat = xxx; */
247 "ERROR, unknown command = %d, unit = %d, parm = %d",
248 command, unit, (unsigned int)parm);
255 /*---------------------------------------------------------------------------*
256 * Data source switch for Read channels - 1, 3 and 5 (B and D-Channel)
257 *---------------------------------------------------------------------------*/
259 ihfc_putmbuf (ihfc_sc_t *sc, u_char chan, struct mbuf *m)
265 if(S_TRACE & TRACE_D_RX)
267 hdr.count = ++S_DTRACECOUNT;
270 hdr.unit = S_I4BUNIT;
274 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
277 if (!S_ENABLED) { i4b_Dfreembuf(m); return; }
279 m->m_pkthdr.len = m->m_len;
281 i4b_l1_ph_data_ind(S_I4BUNIT, m);
285 if(S_TRACE & TRACE_B_RX)
287 hdr.count = ++S_BTRACECOUNT;
289 hdr.type = (chan < 4) ? TRC_CH_B1 : TRC_CH_B2;
290 hdr.unit = S_I4BUNIT;
294 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
297 if (!S_ENABLED) { i4b_Bfreembuf(m); return; }
299 if (S_PROT == BPROT_NONE)
301 if(!i4b_l1_bchan_tel_silence(m->m_data, m->m_len))
303 S_BDRVLINK->bch_activity(S_BDRVLINK->unit, ACT_RX);
306 if (!_IF_QFULL(&S_IFQUEUE))
309 IF_ENQUEUE(&S_IFQUEUE, m);
310 S_BDRVLINK->bch_rx_data_ready(S_BDRVLINK->unit);
316 if (S_PROT == BPROT_RHDLC)
319 S_BYTES += m->m_pkthdr.len = m->m_len;
320 S_BDRVLINK->bch_rx_data_ready(S_BDRVLINK->unit);
326 NDBGL1(L1_ERROR, "Unknown protocol: %d", S_PROT);
330 /*---------------------------------------------------------------------------*
331 * Data destinator switch for write channels - 0, 2 and 4
332 *---------------------------------------------------------------------------*/
334 ihfc_getmbuf (ihfc_sc_t *sc, u_char chan)
336 register struct mbuf *m;
341 IF_DEQUEUE(&S_IFQUEUE, m);
343 if((S_TRACE & TRACE_D_TX) && m)
345 hdr.count = ++S_DTRACECOUNT;
348 hdr.unit = S_I4BUNIT;
352 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
357 IF_DEQUEUE(&S_IFQUEUE, m);
361 S_BDRVLINK->bch_tx_queue_empty(S_BDRVLINK->unit);
363 IF_DEQUEUE(&S_IFQUEUE, m);
367 if(!i4b_l1_bchan_tel_silence(m->m_data, m->m_len))
369 S_BDRVLINK->bch_activity(S_BDRVLINK->unit, ACT_TX);
374 if(S_TRACE & TRACE_B_TX)
376 hdr.count = ++S_BTRACECOUNT;
378 hdr.type = (chan < 4) ? TRC_CH_B1 : TRC_CH_B2;
379 hdr.unit = S_I4BUNIT;
383 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
391 /*---------------------------------------------------------------------------*
392 * Initialize rx/tx data structures (B-channel)
393 *---------------------------------------------------------------------------*/
395 ihfc_B_setup(int unit, int chan, int bprot, int activate)
397 ihfc_sc_t *sc = &ihfc_softc[unit];
400 if (((u_int)chan > 5) || ((u_int)chan < 2)) return;
404 HFC_INIT(sc, chan, bprot, activate);
409 /*---------------------------------------------------------------------------*
410 * Start transmission (B-channel or D-channel tx)
411 * NOTE: if "chan" variable is corrupted, it will not cause any harm,
412 * but data may be lost and there may be software sync. errors.
413 *---------------------------------------------------------------------------*/
415 ihfc_B_start(int unit, int chan)
417 ihfc_sc_t *sc = &ihfc_softc[unit];
420 if ((u_int)chan > 5) return;
424 if (S_FILTER && !S_MBUF && !S_INTR_ACTIVE)
426 S_INTR_ACTIVE |= 2; /* never know what *
430 S_FILTER(sc, chan); /* quick tx */
438 /*---------------------------------------------------------------------------*
439 * Fill statistics struct (B-channel)
440 *---------------------------------------------------------------------------*/
442 ihfc_B_stat(int unit, int chan, bchan_statistics_t *bsp)
444 ihfc_sc_t *sc = &ihfc_softc[unit];
447 if ((u_int)chan > 5) return;
453 bsp->inbytes = S_BYTES; S_BYTES = 0;
457 bsp->outbytes = S_BYTES; S_BYTES = 0;
462 /*---------------------------------------------------------------------------*
463 * Return the address of IHFC linktab to I4B (B-channel)
464 *---------------------------------------------------------------------------*/
466 ihfc_B_ret_linktab(int unit, int channel)
468 ihfc_sc_t *sc = &ihfc_softc[unit];
471 return(&sc->sc_blinktab[channel]);
476 /*---------------------------------------------------------------------------*
477 * Set the I4B driver linktab for IHFC use (B-channel)
478 *---------------------------------------------------------------------------*/
480 ihfc_B_set_linktab(int unit, int channel, drvr_link_t *B_linktab)
482 ihfc_sc_t *sc = &ihfc_softc[unit];
485 sc->sc_bdrvlinktab[channel] = B_linktab;
488 /*---------------------------------------------------------------------------*
489 * Initialize linktab for I4B use (B-channel)
490 *---------------------------------------------------------------------------*/
492 ihfc_B_linkinit(ihfc_sc_t *sc)
496 /* make sure the hardware driver is known to layer 4 */
497 ctrl_types[CTRL_PASSIVE].set_linktab = i4b_l1_set_linktab;
498 ctrl_types[CTRL_PASSIVE].get_linktab = i4b_l1_ret_linktab;
500 for (chan = 2; chan < 6; chan++)
502 S_BLINK.unit = S_UNIT;
503 S_BLINK.channel = chan; /* point to tx-chan */
504 S_BLINK.bch_config = ihfc_B_setup;
505 S_BLINK.bch_tx_start = ihfc_B_start;
506 S_BLINK.bch_stat = ihfc_B_stat;
508 /* This is a transmit channel (even) */
509 S_BLINK.tx_queue = &S_IFQUEUE;
511 /* This is a receive channel (odd) */
512 S_BLINK.rx_queue = &S_IFQUEUE;
513 S_BLINK.rx_mbuf = &S_MBUFDUMMY;
517 #endif /* NIHFC > 0 */