]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer1/isic/i4b_l1.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / layer1 / isic / i4b_l1.c
1 /*-
2  * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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
23  * SUCH DAMAGE.
24  */
25
26 /*---------------------------------------------------------------------------
27  *
28  *      i4b_l1.c - isdn4bsd layer 1 handler
29  *      -----------------------------------
30  *      last edit-date: [Wed Jan 24 09:12:03 2001]
31  *
32  *---------------------------------------------------------------------------*/
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40 #include <sys/socket.h>
41
42 #include <net/if.h>
43
44 #include <i4b/include/i4b_debug.h>
45 #include <i4b/include/i4b_ioctl.h>
46 #include <i4b/include/i4b_trace.h>
47
48 #include <i4b/layer1/isic/i4b_isic.h>
49 #include <i4b/layer1/isic/i4b_isac.h>
50
51 #include <i4b/layer1/i4b_l1.h>
52
53 #include <i4b/include/i4b_mbuf.h>
54 #include <i4b/include/i4b_global.h>
55
56 /*---------------------------------------------------------------------------*
57  *
58  *      L2 -> L1: PH-DATA-REQUEST
59  *      =========================
60  *
61  *      parms:
62  *              unit            physical interface unit number
63  *              m               mbuf containing L2 frame to be sent out
64  *              freeflag        MBUF_FREE: free mbuf here after having sent
65  *                                              it out
66  *                              MBUF_DONTFREE: mbuf is freed by Layer 2
67  *      returns:
68  *              ==0     fail, nothing sent out
69  *              !=0     ok, frame sent out
70  *
71  *---------------------------------------------------------------------------*/
72 int
73 isic_ph_data_req(int unit, struct mbuf *m, int freeflag)
74 {
75         u_char cmd;
76         int s;
77         struct l1_softc *sc = &l1_sc[unit];
78
79 #ifdef NOTDEF
80         NDBGL1(L1_PRIM, "unit %d, freeflag=%d", unit, freeflag);
81 #endif
82
83         if(m == NULL)                   /* failsafe */
84                 return (0);
85
86         s = SPLI4B();
87
88         if(sc->sc_I430state == ST_F3)   /* layer 1 not running ? */
89         {
90                 NDBGL1(L1_I_ERR, "still in state F3!");
91                 isic_ph_activate_req(unit);
92         }
93
94         if(sc->sc_state & ISAC_TX_ACTIVE)
95         {
96                 if(sc->sc_obuf2 == NULL)
97                 {
98                         sc->sc_obuf2 = m;               /* save mbuf ptr */
99
100                         if(freeflag)
101                                 sc->sc_freeflag2 = 1;   /* IRQ must mfree */
102                         else
103                                 sc->sc_freeflag2 = 0;   /* IRQ must not mfree */
104
105                         NDBGL1(L1_I_MSG, "using 2nd ISAC TX buffer, state = %s", isic_printstate(sc));
106
107                         if(sc->sc_trace & TRACE_D_TX)
108                         {
109                                 i4b_trace_hdr_t hdr;
110                                 hdr.unit = L0ISICUNIT(unit);
111                                 hdr.type = TRC_CH_D;
112                                 hdr.dir = FROM_TE;
113                                 hdr.count = ++sc->sc_trace_dcount;
114                                 MICROTIME(hdr.time);
115                                 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
116                         }
117                         splx(s);
118                         return(1);
119                 }
120
121                 NDBGL1(L1_I_ERR, "No Space in TX FIFO, state = %s", isic_printstate(sc));
122         
123                 if(freeflag == MBUF_FREE)
124                         i4b_Dfreembuf(m);                       
125         
126                 splx(s);
127                 return (0);
128         }
129
130         if(sc->sc_trace & TRACE_D_TX)
131         {
132                 i4b_trace_hdr_t hdr;
133                 hdr.unit = L0ISICUNIT(unit);
134                 hdr.type = TRC_CH_D;
135                 hdr.dir = FROM_TE;
136                 hdr.count = ++sc->sc_trace_dcount;
137                 MICROTIME(hdr.time);
138                 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
139         }
140         
141         sc->sc_state |= ISAC_TX_ACTIVE; /* set transmitter busy flag */
142
143         NDBGL1(L1_I_MSG, "ISAC_TX_ACTIVE set");
144
145         sc->sc_freeflag = 0;            /* IRQ must NOT mfree */
146         
147         ISAC_WRFIFO(m->m_data, min(m->m_len, ISAC_FIFO_LEN)); /* output to TX fifo */
148
149         if(m->m_len > ISAC_FIFO_LEN)    /* message > 32 bytes ? */
150         {
151                 sc->sc_obuf = m;        /* save mbuf ptr */
152                 sc->sc_op = m->m_data + ISAC_FIFO_LEN;  /* ptr for irq hdl */
153                 sc->sc_ol = m->m_len - ISAC_FIFO_LEN;   /* length for irq hdl */
154
155                 if(freeflag)
156                         sc->sc_freeflag = 1;    /* IRQ must mfree */
157                 
158                 cmd = ISAC_CMDR_XTF;
159         }
160         else
161         {
162                 sc->sc_obuf = NULL;
163                 sc->sc_op = NULL;
164                 sc->sc_ol = 0;
165
166                 if(freeflag)
167                         i4b_Dfreembuf(m);
168
169                 cmd = ISAC_CMDR_XTF | ISAC_CMDR_XME;
170         }
171
172         ISAC_WRITE(I_CMDR, cmd);
173         ISACCMDRWRDELAY();
174
175         splx(s);
176         
177         return(1);
178 }
179
180 /*---------------------------------------------------------------------------*
181  *
182  *      L2 -> L1: PH-ACTIVATE-REQUEST
183  *      =============================
184  *
185  *      parms:
186  *              unit    physical interface unit number
187  *
188  *      returns:
189  *              ==0     
190  *              !=0     
191  *
192  *---------------------------------------------------------------------------*/
193 int
194 isic_ph_activate_req(int unit)
195 {
196         struct l1_softc *sc = &l1_sc[unit];
197         NDBGL1(L1_PRIM, "unit %d", unit);
198         isic_next_state(sc, EV_PHAR);
199         return(0);
200 }
201
202 /*---------------------------------------------------------------------------*
203  *      command from the upper layers
204  *---------------------------------------------------------------------------*/
205 int
206 isic_mph_command_req(int unit, int command, void *parm)
207 {
208         struct l1_softc *sc = &l1_sc[unit];
209
210         switch(command)
211         {
212                 case CMR_DOPEN:         /* daemon running */
213                         NDBGL1(L1_PRIM, "unit %d, command = CMR_DOPEN", unit);
214                         sc->sc_enabled = 1;                     
215                         break;
216                         
217                 case CMR_DCLOSE:        /* daemon not running */
218                         NDBGL1(L1_PRIM, "unit %d, command = CMR_DCLOSE", unit);
219                         sc->sc_enabled = 0;
220                         break;
221
222                 case CMR_SETTRACE:
223                         NDBGL1(L1_PRIM, "unit %d, command = CMR_SETTRACE, parm = %d", unit, (unsigned int)parm);
224                         sc->sc_trace = (unsigned int)parm;
225                         break;
226                 
227                 case CMR_GCST:
228                         {
229                         struct chipstat *cst;
230                         NDBGL1(L1_PRIM, "unit %d, command = CMR_GCST, parm = %d", unit, (unsigned int)parm);
231                         cst = (struct chipstat *)parm;
232                         cst->driver_type = L1DRVR_ISIC;
233                         cst->stats.hscxstat.unit = sc->sc_unit;
234                         cst->stats.hscxstat.chan = cst->driver_bchannel;
235                         cst->stats.hscxstat.vfr = sc->sc_chan[cst->driver_bchannel].stat_VFR;
236                         cst->stats.hscxstat.rdo = sc->sc_chan[cst->driver_bchannel].stat_RDO;
237                         cst->stats.hscxstat.crc = sc->sc_chan[cst->driver_bchannel].stat_CRC;
238                         cst->stats.hscxstat.rab = sc->sc_chan[cst->driver_bchannel].stat_RAB;
239                         cst->stats.hscxstat.xdu = sc->sc_chan[cst->driver_bchannel].stat_XDU;
240                         cst->stats.hscxstat.rfo = sc->sc_chan[cst->driver_bchannel].stat_RFO;
241                         break;
242                         }
243                 default:
244                         NDBGL1(L1_ERROR, "ERROR, unknown command = %d, unit = %d, parm = %d", command, unit, (unsigned int)parm);
245                         break;
246         }
247
248         return(0);
249 }