2 * Copyright (c) 1997, 2001 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_itjc_l1.c - NetJet-S layer 1 handler
28 * ---------------------------------------------
30 * $FreeBSD: src/sys/i4b/layer1/itjc/i4b_itjc_l1.c,v 1.1.2.1 2001/08/10 14:08:39 obrien Exp $
31 * $DragonFly: src/sys/net/i4b/layer1/itjc/i4b_itjc_l1.c,v 1.4 2005/06/03 16:50:07 dillon Exp $
33 * last edit-date: [Wed Jan 10 17:16:19 2001]
35 *---------------------------------------------------------------------------*/
40 #if (NITJC > 0) && (NPCI > 0)
42 #include <sys/param.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/thread2.h>
49 #include <machine/stdarg.h>
50 #include <machine/clock.h>
54 #include <net/i4b/include/machine/i4b_debug.h>
55 #include <net/i4b/include/machine/i4b_ioctl.h>
56 #include <net/i4b/include/machine/i4b_trace.h>
58 #include "../isic/i4b_isic.h"
59 #include "../isic/i4b_isac.h"
61 #include "i4b_itjc_ext.h"
63 #include "../i4b_l1.h"
65 #include "../../include/i4b_mbuf.h"
66 #include "../../include/i4b_global.h"
68 /*---------------------------------------------------------------------------*
70 * L2 -> L1: PH-DATA-REQUEST
71 * =========================
74 * unit physical interface unit number
75 * m mbuf containing L2 frame to be sent out
76 * freeflag MBUF_FREE: free mbuf here after having sent
78 * MBUF_DONTFREE: mbuf is freed by Layer 2
80 * ==0 fail, nothing sent out
81 * !=0 ok, frame sent out
83 *---------------------------------------------------------------------------*/
85 itjc_ph_data_req(int unit, struct mbuf *m, int freeflag)
88 struct l1_softc *sc = itjc_scp[unit];
90 NDBGL1(L1_PRIM, "PH-DATA-REQ, unit %d, freeflag=%d", unit, freeflag);
92 if(m == NULL) /* failsafe */
97 if(sc->sc_I430state == ST_F3) /* layer 1 not running ? */
99 NDBGL1(L1_I_ERR, "still in state F3!");
100 itjc_ph_activate_req(unit);
103 if(sc->sc_state & ISAC_TX_ACTIVE)
105 if(sc->sc_obuf2 == NULL)
107 sc->sc_obuf2 = m; /* save mbuf ptr */
110 sc->sc_freeflag2 = 1; /* IRQ must mfree */
112 sc->sc_freeflag2 = 0; /* IRQ must not mfree */
114 NDBGL1(L1_I_MSG, "using 2nd ISAC TX buffer, state = %s", itjc_printstate(sc));
116 if(sc->sc_trace & TRACE_D_TX)
119 hdr.unit = L0ITJCUNIT(unit);
122 hdr.count = ++sc->sc_trace_dcount;
124 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
130 NDBGL1(L1_I_ERR, "No Space in TX FIFO, state = %s", itjc_printstate(sc));
132 if(freeflag == MBUF_FREE)
139 if(sc->sc_trace & TRACE_D_TX)
142 hdr.unit = L0ITJCUNIT(unit);
145 hdr.count = ++sc->sc_trace_dcount;
147 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
150 sc->sc_state |= ISAC_TX_ACTIVE; /* set transmitter busy flag */
152 NDBGL1(L1_I_MSG, "ISAC_TX_ACTIVE set");
154 sc->sc_freeflag = 0; /* IRQ must NOT mfree */
156 ISAC_WRFIFO(m->m_data, min(m->m_len, ISAC_FIFO_LEN)); /* output to TX fifo */
158 if(m->m_len > ISAC_FIFO_LEN) /* message > 32 bytes ? */
160 sc->sc_obuf = m; /* save mbuf ptr */
161 sc->sc_op = m->m_data + ISAC_FIFO_LEN; /* ptr for irq hdl */
162 sc->sc_ol = m->m_len - ISAC_FIFO_LEN; /* length for irq hdl */
165 sc->sc_freeflag = 1; /* IRQ must mfree */
178 cmd = ISAC_CMDR_XTF | ISAC_CMDR_XME;
181 ISAC_WRITE(I_CMDR, cmd);
189 /*---------------------------------------------------------------------------*
191 * L2 -> L1: PH-ACTIVATE-REQUEST
192 * =============================
195 * unit physical interface unit number
201 *---------------------------------------------------------------------------*/
203 itjc_ph_activate_req(int unit)
205 struct l1_softc *sc = itjc_scp[unit];
206 NDBGL1(L1_PRIM, "PH-ACTIVATE-REQ, unit %d", unit);
207 itjc_next_state(sc, EV_PHAR);
211 /*---------------------------------------------------------------------------*
212 * command from the upper layers
213 *---------------------------------------------------------------------------*/
215 itjc_mph_command_req(int unit, int command, void *parm)
217 struct l1_softc *sc = itjc_scp[unit];
221 case CMR_DOPEN: /* daemon running */
222 NDBGL1(L1_PRIM, "unit %d, command = CMR_DOPEN", unit);
226 case CMR_DCLOSE: /* daemon not running */
227 NDBGL1(L1_PRIM, "unit %d, command = CMR_DCLOSE", unit);
232 NDBGL1(L1_PRIM, "unit %d, command = CMR_SETTRACE, parm = %d", unit, (unsigned int)parm);
233 sc->sc_trace = (unsigned int)parm;
237 NDBGL1(L1_ERROR, "ERROR, unknown command = %d, unit = %d, parm = %d", command, unit, (unsigned int)parm);
244 #endif /* NITJC > 0 */