2 * Copyright (c) 1997, 1999 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
25 *---------------------------------------------------------------------------
27 * i4b_l1.c - isdn4bsd layer 1 handler
28 * -----------------------------------
30 * $Id: i4b_l1.c,v 1.2 1999/12/13 21:25:26 hm Exp $
34 * last edit-date: [Mon Dec 13 22:01:55 1999]
36 *---------------------------------------------------------------------------*/
42 #include <sys/param.h>
43 #include <sys/ioccom.h>
44 #include <sys/kernel.h>
45 #include <sys/systm.h>
47 #include <sys/socket.h>
49 #include <machine/stdarg.h>
50 #include <machine/clock.h>
54 #include <machine/i4b_debug.h>
55 #include <machine/i4b_ioctl.h>
56 #include <machine/i4b_trace.h>
58 #include <i4b/layer1/i4b_l1.h>
59 #include <i4b/layer1/i4b_isac.h>
60 #include <i4b/layer1/i4b_hscx.h>
62 #include <i4b/include/i4b_l1l2.h>
63 #include <i4b/include/i4b_mbuf.h>
64 #include <i4b/include/i4b_global.h>
66 unsigned int i4b_l1_debug = L1_DEBUG_DEFAULT;
68 static int ph_data_req(int, struct mbuf *, int);
69 static int ph_activate_req(int);
71 /* from i4btrc driver i4b_trace.c */
72 extern int get_trace_data_from_l1(int unit, int what, int len, char *buf);
75 extern int i4b_ph_data_ind(int unit, struct mbuf *m);
76 extern int i4b_ph_activate_ind(int unit);
77 extern int i4b_ph_deactivate_ind(int unit);
78 extern int i4b_mph_attach_ind(int unit);
79 extern int i4b_mph_status_ind(int, int, int);
82 static int i4b_mph_command_req(int, int, int);
85 struct i4b_l1l2_func i4b_l1l2_func = {
87 /* Layer 1 --> Layer 2 */
89 (int (*)(int, struct mbuf *)) i4b_ph_data_ind,
90 (int (*)(int)) i4b_ph_activate_ind,
91 (int (*)(int)) i4b_ph_deactivate_ind,
93 /* Layer 2 --> Layer 1 */
95 (int (*)(int, struct mbuf *, int)) ph_data_req,
96 (int (*)(int)) ph_activate_req,
98 /* Layer 1 --> upstream, ISDN trace data */
100 (int (*)(i4b_trace_hdr_t *, int, u_char *)) get_trace_data_from_l1,
102 /* Driver control and status information */
104 (int (*)(int, int, int)) i4b_mph_status_ind,
105 (int (*)(int, int, int)) i4b_mph_command_req,
108 /*---------------------------------------------------------------------------*
110 * L2 -> L1: PH-DATA-REQUEST
111 * =========================
114 * unit physical interface unit number
115 * m mbuf containing L2 frame to be sent out
116 * freeflag MBUF_FREE: free mbuf here after having sent
118 * MBUF_DONTFREE: mbuf is freed by Layer 2
120 * ==0 fail, nothing sent out
121 * !=0 ok, frame sent out
123 *---------------------------------------------------------------------------*/
125 ph_data_req(int unit, struct mbuf *m, int freeflag)
129 struct l1_softc *sc = &l1_sc[unit];
132 DBGL1(L1_PRIM, "PH-DATA-REQ", ("unit %d, freeflag=%d\n", unit, freeflag));
135 if(m == NULL) /* failsafe */
140 if(sc->sc_I430state == ST_F3) /* layer 1 not running ? */
142 DBGL1(L1_I_ERR, "ph_data_req", ("still in state F3!\n"));
143 ph_activate_req(unit);
146 if(sc->sc_state & ISAC_TX_ACTIVE)
148 if(sc->sc_obuf2 == NULL)
150 sc->sc_obuf2 = m; /* save mbuf ptr */
153 sc->sc_freeflag2 = 1; /* IRQ must mfree */
155 sc->sc_freeflag2 = 0; /* IRQ must not mfree */
157 DBGL1(L1_I_MSG, "ph_data_req", ("using 2nd ISAC TX buffer, state = %s\n", isic_printstate(sc)));
159 if(sc->sc_trace & TRACE_D_TX)
165 hdr.count = ++sc->sc_trace_dcount;
167 MPH_Trace_Ind(&hdr, m->m_len, m->m_data);
173 DBGL1(L1_I_ERR, "ph_data_req", ("No Space in TX FIFO, state = %s\n", isic_printstate(sc)));
175 if(freeflag == MBUF_FREE)
182 if(sc->sc_trace & TRACE_D_TX)
188 hdr.count = ++sc->sc_trace_dcount;
190 MPH_Trace_Ind(&hdr, m->m_len, m->m_data);
193 sc->sc_state |= ISAC_TX_ACTIVE; /* set transmitter busy flag */
195 DBGL1(L1_I_MSG, "ph_data_req", ("ISAC_TX_ACTIVE set\n"));
197 sc->sc_freeflag = 0; /* IRQ must NOT mfree */
199 ISAC_WRFIFO(m->m_data, min(m->m_len, ISAC_FIFO_LEN)); /* output to TX fifo */
201 if(m->m_len > ISAC_FIFO_LEN) /* message > 32 bytes ? */
203 sc->sc_obuf = m; /* save mbuf ptr */
204 sc->sc_op = m->m_data + ISAC_FIFO_LEN; /* ptr for irq hdl */
205 sc->sc_ol = m->m_len - ISAC_FIFO_LEN; /* length for irq hdl */
208 sc->sc_freeflag = 1; /* IRQ must mfree */
221 cmd = ISAC_CMDR_XTF | ISAC_CMDR_XME;
224 ISAC_WRITE(I_CMDR, cmd);
232 /*---------------------------------------------------------------------------*
234 * L2 -> L1: PH-ACTIVATE-REQUEST
235 * =============================
238 * unit physical interface unit number
244 *---------------------------------------------------------------------------*/
246 ph_activate_req(int unit)
248 struct l1_softc *sc = &l1_sc[unit];
249 DBGL1(L1_PRIM, "PH-ACTIVATE-REQ", ("unit %d\n", unit));
250 isic_next_state(sc, EV_PHAR);
254 /*---------------------------------------------------------------------------*
255 * command from the upper layers
256 *---------------------------------------------------------------------------*/
258 i4b_mph_command_req(int unit, int command, int parm)
260 struct l1_softc *sc = &l1_sc[unit];
264 case CMR_DOPEN: /* daemon running */
265 DBGL1(L1_PRIM, "MPH-COMMAND-REQ", ("unit %d, command = CMR_DOPEN\n", unit));
269 case CMR_DCLOSE: /* daemon not running */
270 DBGL1(L1_PRIM, "MPH-COMMAND-REQ", ("unit %d, command = CMR_DCLOSE\n", unit));
275 DBGL1(L1_ERROR, "i4b_mph_command_req", ("ERROR, unknown command = %d, unit = %d, parm = %d\n", command, unit, parm));
282 #endif /* NISIC > 0 */