]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer1/ifpnp/i4b_ifpnp_l1.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / layer1 / ifpnp / i4b_ifpnp_l1.c
1 /*-
2  * Copyright (c) 1997, 2000 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_ifpnp_l1.c - AVM Fritz PnP layer 1 handler
29  *      ----------------------------------------------
30  *      $Id: i4b_ifpnp_l1.c,v 1.4 2000/06/02 16:14:36 hm Exp $ 
31  *      $Ust: src/i4b/layer1-nb/ifpnp/i4b_ifpnp_l1.c,v 1.4 2000/04/18 08:03:05 ust Exp $ 
32  *      last edit-date: [Fri Jun  2 14:55:49 2000]
33  *
34  *---------------------------------------------------------------------------*/
35
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/mbuf.h>
42 #include <sys/socket.h>
43
44 #include <net/if.h>
45
46 #include <i4b/include/i4b_debug.h>
47 #include <i4b/include/i4b_ioctl.h>
48 #include <i4b/include/i4b_trace.h>
49
50 #include <i4b/layer1/isic/i4b_isic.h>
51 #include <i4b/layer1/isic/i4b_isac.h>
52
53 #include <i4b/layer1/ifpnp/i4b_ifpnp_ext.h>
54
55 #include <i4b/layer1/i4b_l1.h>
56
57 #include <i4b/include/i4b_mbuf.h>
58 #include <i4b/include/i4b_global.h>
59
60 /*---------------------------------------------------------------------------*
61  *
62  *      L2 -> L1: PH-DATA-REQUEST
63  *      =========================
64  *
65  *      parms:
66  *              unit            physical interface unit number
67  *              m               mbuf containing L2 frame to be sent out
68  *              freeflag        MBUF_FREE: free mbuf here after having sent
69  *                                              it out
70  *                              MBUF_DONTFREE: mbuf is freed by Layer 2
71  *      returns:
72  *              ==0     fail, nothing sent out
73  *              !=0     ok, frame sent out
74  *
75  *---------------------------------------------------------------------------*/
76 int
77 ifpnp_ph_data_req(int unit, struct mbuf *m, int freeflag)
78 {
79         u_char cmd;
80         int s;
81         struct l1_softc *sc = ifpnp_scp[unit];
82
83 #ifdef NOTDEF
84         NDBGL1(L1_PRIM, "PH-DATA-REQ, unit %d, freeflag=%d", unit, freeflag);
85 #endif
86
87         if(m == NULL)                   /* failsafe */
88                 return (0);
89
90         s = SPLI4B();
91
92         if(sc->sc_I430state == ST_F3)   /* layer 1 not running ? */
93         {
94                 NDBGL1(L1_I_ERR, "still in state F3!");
95                 ifpnp_ph_activate_req(unit);
96         }
97
98         if(sc->sc_state & ISAC_TX_ACTIVE)
99         {
100                 if(sc->sc_obuf2 == NULL)
101                 {
102                         sc->sc_obuf2 = m;               /* save mbuf ptr */
103
104                         if(freeflag)
105                                 sc->sc_freeflag2 = 1;   /* IRQ must mfree */
106                         else
107                                 sc->sc_freeflag2 = 0;   /* IRQ must not mfree */
108
109                         NDBGL1(L1_I_MSG, "using 2nd ISAC TX buffer, state = %s", ifpnp_printstate(sc));
110
111                         if(sc->sc_trace & TRACE_D_TX)
112                         {
113                                 i4b_trace_hdr_t hdr;
114                                 hdr.unit = L0IFPNPUNIT(unit);
115                                 hdr.type = TRC_CH_D;
116                                 hdr.dir = FROM_TE;
117                                 hdr.count = ++sc->sc_trace_dcount;
118                                 MICROTIME(hdr.time);
119                                 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
120                         }
121                         splx(s);
122                         return(1);
123                 }
124
125                 NDBGL1(L1_I_ERR, "No Space in TX FIFO, state = %s", ifpnp_printstate(sc));
126         
127                 if(freeflag == MBUF_FREE)
128                         i4b_Dfreembuf(m);                       
129         
130                 splx(s);
131                 return (0);
132         }
133
134         if(sc->sc_trace & TRACE_D_TX)
135         {
136                 i4b_trace_hdr_t hdr;
137                 hdr.unit = L0IFPNPUNIT(unit);
138                 hdr.type = TRC_CH_D;
139                 hdr.dir = FROM_TE;
140                 hdr.count = ++sc->sc_trace_dcount;
141                 MICROTIME(hdr.time);
142                 i4b_l1_trace_ind(&hdr, m->m_len, m->m_data);
143         }
144         
145         sc->sc_state |= ISAC_TX_ACTIVE; /* set transmitter busy flag */
146
147         NDBGL1(L1_I_MSG, "ISAC_TX_ACTIVE set");
148
149         sc->sc_freeflag = 0;            /* IRQ must NOT mfree */
150         
151         ISAC_WRFIFO(m->m_data, min(m->m_len, ISAC_FIFO_LEN)); /* output to TX fifo */
152
153         if(m->m_len > ISAC_FIFO_LEN)    /* message > 32 bytes ? */
154         {
155                 sc->sc_obuf = m;        /* save mbuf ptr */
156                 sc->sc_op = m->m_data + ISAC_FIFO_LEN;  /* ptr for irq hdl */
157                 sc->sc_ol = m->m_len - ISAC_FIFO_LEN;   /* length for irq hdl */
158
159                 if(freeflag)
160                         sc->sc_freeflag = 1;    /* IRQ must mfree */
161                 
162                 cmd = ISAC_CMDR_XTF;
163         }
164         else
165         {
166                 sc->sc_obuf = NULL;
167                 sc->sc_op = NULL;
168                 sc->sc_ol = 0;
169
170                 if(freeflag)
171                         i4b_Dfreembuf(m);
172
173                 cmd = ISAC_CMDR_XTF | ISAC_CMDR_XME;
174         }
175
176         ISAC_WRITE(I_CMDR, cmd);
177         ISACCMDRWRDELAY();
178
179         splx(s);
180         
181         return(1);
182 }
183
184 /*---------------------------------------------------------------------------*
185  *
186  *      L2 -> L1: PH-ACTIVATE-REQUEST
187  *      =============================
188  *
189  *      parms:
190  *              unit    physical interface unit number
191  *
192  *      returns:
193  *              ==0     
194  *              !=0     
195  *
196  *---------------------------------------------------------------------------*/
197 int
198 ifpnp_ph_activate_req(int unit)
199 {
200         struct l1_softc *sc = ifpnp_scp[unit];
201         NDBGL1(L1_PRIM, "PH-ACTIVATE-REQ, unit %d\n", unit);
202         ifpnp_next_state(sc, EV_PHAR);
203         return(0);
204 }
205
206 /*---------------------------------------------------------------------------*
207  *      command from the upper layers
208  *---------------------------------------------------------------------------*/
209 int
210 ifpnp_mph_command_req(int unit, int command, void *parm)
211 {
212         struct l1_softc *sc = ifpnp_scp[unit];
213
214         switch(command)
215         {
216                 case CMR_DOPEN:         /* daemon running */
217                         NDBGL1(L1_PRIM, "unit %d, command = CMR_DOPEN", unit);
218                         sc->sc_enabled = 1;                     
219                         break;
220                         
221                 case CMR_DCLOSE:        /* daemon not running */
222                         NDBGL1(L1_PRIM, "unit %d, command = CMR_DCLOSE", unit);
223                         sc->sc_enabled = 0;
224                         break;
225
226                 case CMR_SETTRACE:
227                         NDBGL1(L1_PRIM, "unit %d, command = CMR_SETTRACE, parm = %d", unit, (unsigned int)parm);
228                         sc->sc_trace = (unsigned int)parm;
229                         break;
230                 
231                 default:
232                         NDBGL1(L1_ERROR, "ERROR, unknown command = %d, unit = %d, parm = %d", command, unit, (unsigned int)parm);
233                         break;
234         }
235
236         return(0);
237 }