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