2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
3 * Copyright (c) 2001 Gary Jennejohn. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * 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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 /*---------------------------------------------------------------------------
29 * i4b_ifpi2_l1.c - AVM Fritz PCI Version 2 layer 1 handler
30 * ---------------------------------------------
33 *---------------------------------------------------------------------------*/
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #include <sys/socket.h>
45 #include <i4b/include/i4b_debug.h>
46 #include <i4b/include/i4b_ioctl.h>
47 #include <i4b/include/i4b_trace.h>
49 #include <i4b/layer1/isic/i4b_isic.h>
50 #include <i4b/layer1/isic/i4b_isac.h>
52 #include <i4b/layer1/ifpi2/i4b_ifpi2_ext.h>
54 #include <i4b/layer1/i4b_l1.h>
56 #include <i4b/include/i4b_mbuf.h>
57 #include <i4b/include/i4b_global.h>
59 /*---------------------------------------------------------------------------*
61 * L2 -> L1: PH-DATA-REQUEST
62 * =========================
65 * unit physical interface unit number
66 * m mbuf containing L2 frame to be sent out
67 * freeflag MBUF_FREE: free mbuf here after having sent
69 * MBUF_DONTFREE: mbuf is freed by Layer 2
71 * ==0 fail, nothing sent out
72 * !=0 ok, frame sent out
74 *---------------------------------------------------------------------------*/
76 ifpi2_ph_data_req(int unit, struct mbuf *m, int freeflag)
80 struct l1_softc *sc = ifpi2_scp[unit];
83 NDBGL1(L1_PRIM, "PH-DATA-REQ, unit %d, freeflag=%d", unit, freeflag);
86 if(m == NULL) /* failsafe */
91 if(sc->sc_I430state == ST_F3) /* layer 1 not running ? */
93 NDBGL1(L1_I_ERR, "still in state F3!");
94 ifpi2_ph_activate_req(unit);
97 if(sc->sc_state & ISAC_TX_ACTIVE)
99 if(sc->sc_obuf2 == NULL)
101 sc->sc_obuf2 = m; /* save mbuf ptr */
104 sc->sc_freeflag2 = 1; /* IRQ must mfree */
106 sc->sc_freeflag2 = 0; /* IRQ must not mfree */
108 NDBGL1(L1_I_MSG, "using 2nd ISAC TX buffer, state = %s", ifpi2_printstate(sc));
110 if(sc->sc_trace & TRACE_D_TX)
113 hdr.unit = L0IFPI2UNIT(unit);
116 hdr.count = ++sc->sc_trace_dcount;
118 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
124 NDBGL1(L1_I_ERR, "No Space in TX FIFO, state = %s", ifpi2_printstate(sc));
126 if(freeflag == MBUF_FREE)
133 if(sc->sc_trace & TRACE_D_TX)
136 hdr.unit = L0IFPI2UNIT(unit);
139 hdr.count = ++sc->sc_trace_dcount;
141 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
144 sc->sc_state |= ISAC_TX_ACTIVE; /* set transmitter busy flag */
146 NDBGL1(L1_I_MSG, "ISAC_TX_ACTIVE set");
148 sc->sc_freeflag = 0; /* IRQ must NOT mfree */
150 ISAC_WRFIFO(m->m_data, min(m->m_len, ISAC_FIFO_LEN)); /* output to TX fifo */
152 if(m->m_len > ISAC_FIFO_LEN) /* message > 32 bytes ? */
154 sc->sc_obuf = m; /* save mbuf ptr */
155 sc->sc_op = m->m_data + ISAC_FIFO_LEN; /* ptr for irq hdl */
156 sc->sc_ol = m->m_len - ISAC_FIFO_LEN; /* length for irq hdl */
159 sc->sc_freeflag = 1; /* IRQ must mfree */
172 cmd = ISAC_CMDR_XTF | ISAC_CMDR_XME;
175 ISAC_WRITE(I_CMDR, cmd);
183 /*---------------------------------------------------------------------------*
185 * L2 -> L1: PH-ACTIVATE-REQUEST
186 * =============================
189 * unit physical interface unit number
195 *---------------------------------------------------------------------------*/
197 ifpi2_ph_activate_req(int unit)
199 struct l1_softc *sc = ifpi2_scp[unit];
200 NDBGL1(L1_PRIM, "PH-ACTIVATE-REQ, unit %d", unit);
201 ifpi2_next_state(sc, EV_PHAR);
205 /*---------------------------------------------------------------------------*
206 * command from the upper layers
207 *---------------------------------------------------------------------------*/
209 ifpi2_mph_command_req(int unit, int command, void *parm)
211 struct l1_softc *sc = ifpi2_scp[unit];
215 case CMR_DOPEN: /* daemon running */
216 NDBGL1(L1_PRIM, "unit %d, command = CMR_DOPEN", unit);
220 case CMR_DCLOSE: /* daemon not running */
221 NDBGL1(L1_PRIM, "unit %d, command = CMR_DCLOSE", unit);
226 NDBGL1(L1_PRIM, "unit %d, command = CMR_SETTRACE, parm = %d", unit, (unsigned int)parm);
227 sc->sc_trace = (unsigned int)parm;
231 NDBGL1(L1_ERROR, "ERROR, unknown command = %d, unit = %d, parm = %d", command, unit, (unsigned int)parm);