1 /* $NetBSD: isic_l1.c,v 1.17 2007/10/19 11:59:54 ad Exp $ */
4 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: isic_l1.c,v 1.17 2007/10/19 11:59:54 ad Exp $");
32 #include <sys/param.h>
33 #include <sys/ioctl.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
39 #include <sys/device.h>
41 #include <sys/socket.h>
44 #include <sys/callout.h>
46 #include <netisdn/i4b_debug.h>
47 #include <netisdn/i4b_ioctl.h>
48 #include <netisdn/i4b_trace.h>
50 #include <netisdn/i4b_l2.h>
51 #include <netisdn/i4b_l1l2.h>
52 #include <netisdn/i4b_mbuf.h>
53 #include <netisdn/i4b_global.h>
55 #include <dev/ic/isic_l1.h>
56 #include <dev/ic/isac.h>
57 #include <dev/ic/ipac.h>
58 #include <dev/ic/hscx.h>
63 unsigned int i4b_l1_debug
= L1_DEBUG_DEFAULT
;
65 static int isic_std_ph_data_req(isdn_layer1token
, struct mbuf
*, int);
66 static int isic_std_ph_activate_req(isdn_layer1token
);
67 static int isic_std_mph_command_req(isdn_layer1token
, int, void*);
68 static void isic_enable_intr(struct isic_softc
*sc
, int enable
);
70 const struct isdn_layer1_isdnif_driver isic_std_driver
= {
72 isic_std_ph_activate_req
,
73 isic_std_mph_command_req
76 /* from i4btrc driver i4b_trace.c */
77 extern int get_trace_data_from_l1(int unit
, int what
, int len
, char *buf
);
79 /*---------------------------------------------------------------------------*
81 * L2 -> L1: PH-DATA-REQUEST
82 * =========================
85 * token softc of physical driver
86 * m mbuf containing L2 frame to be sent out
87 * freeflag MBUF_FREE: free mbuf here after having sent
89 * MBUF_DONTFREE: mbuf is freed by Layer 2
91 * ==0 fail, nothing sent out
92 * !=0 ok, frame sent out
94 *---------------------------------------------------------------------------*/
96 isic_std_ph_data_req(isdn_layer1token token
, struct mbuf
*m
, int freeflag
)
98 struct isic_softc
*sc
= (struct isic_softc
*)token
;
102 if (m
== NULL
) /* failsafe */
107 if(sc
->sc_I430state
== ST_F3
) /* layer 1 not running ? */
109 NDBGL1(L1_I_ERR
, "still in state F3!");
110 isic_std_ph_activate_req(token
);
113 if(sc
->sc_state
& ISAC_TX_ACTIVE
)
115 if(sc
->sc_obuf2
== NULL
)
117 sc
->sc_obuf2
= m
; /* save mbuf ptr */
120 sc
->sc_freeflag2
= 1; /* IRQ must mfree */
122 sc
->sc_freeflag2
= 0; /* IRQ must not mfree */
124 NDBGL1(L1_I_MSG
, "using 2nd ISAC TX buffer, state = %s", isic_printstate(sc
));
126 if(sc
->sc_trace
& TRACE_D_TX
)
131 hdr
.count
= ++sc
->sc_trace_dcount
;
132 isdn_layer2_trace_ind(&sc
->sc_l2
, sc
->sc_l3token
, &hdr
, m
->m_len
, m
->m_data
);
138 NDBGL1(L1_I_ERR
, "No Space in TX FIFO, state = %s", isic_printstate(sc
));
140 if(freeflag
== MBUF_FREE
)
147 if(sc
->sc_trace
& TRACE_D_TX
)
152 hdr
.count
= ++sc
->sc_trace_dcount
;
153 isdn_layer2_trace_ind(&sc
->sc_l2
, sc
->sc_l3token
, &hdr
, m
->m_len
, m
->m_data
);
156 sc
->sc_state
|= ISAC_TX_ACTIVE
; /* set transmitter busy flag */
158 NDBGL1(L1_I_MSG
, "ISAC_TX_ACTIVE set");
160 sc
->sc_freeflag
= 0; /* IRQ must NOT mfree */
162 ISAC_WRFIFO(m
->m_data
, min(m
->m_len
, ISAC_FIFO_LEN
)); /* output to TX fifo */
164 if(m
->m_len
> ISAC_FIFO_LEN
) /* message > 32 bytes ? */
166 sc
->sc_obuf
= m
; /* save mbuf ptr */
167 sc
->sc_op
= m
->m_data
+ ISAC_FIFO_LEN
; /* ptr for irq hdl */
168 sc
->sc_ol
= m
->m_len
- ISAC_FIFO_LEN
; /* length for irq hdl */
171 sc
->sc_freeflag
= 1; /* IRQ must mfree */
184 cmd
= ISAC_CMDR_XTF
| ISAC_CMDR_XME
;
187 ISAC_WRITE(I_CMDR
, cmd
);
195 /*---------------------------------------------------------------------------*
197 * L2 -> L1: PH-ACTIVATE-REQUEST
198 * =============================
201 * token softc of physical interface
207 *---------------------------------------------------------------------------*/
209 isic_std_ph_activate_req(isdn_layer1token token
)
211 struct isic_softc
*sc
= (struct isic_softc
*)token
;
213 NDBGL1(L1_PRIM
, " %s ", device_xname(&sc
->sc_dev
));
214 isic_next_state(sc
, EV_PHAR
);
218 /*---------------------------------------------------------------------------*
219 * command from the upper layers
220 *---------------------------------------------------------------------------*/
222 isic_std_mph_command_req(isdn_layer1token token
, int command
, void *parm
)
224 struct isic_softc
*sc
= (struct isic_softc
*)token
;
225 int s
, pass_down
= 0;
230 case CMR_DOPEN
: /* daemon running */
231 NDBGL1(L1_PRIM
, "%s, command = CMR_DOPEN", device_xname(&sc
->sc_dev
));
232 sc
->sc_intr_valid
= ISIC_INTR_VALID
;
236 case CMR_DCLOSE
: /* daemon not running */
237 NDBGL1(L1_PRIM
, "%s, command = CMR_DCLOSE", device_xname(&sc
->sc_dev
));
238 sc
->sc_intr_valid
= ISIC_INTR_DISABLED
;
239 isic_enable_intr(sc
, 0);
248 NDBGL1(L1_PRIM
, "%s, command = CMR_SETTRACE, parm = %p", device_xname(&sc
->sc_dev
), parm
);
249 sc
->sc_trace
= (int)(unsigned long)parm
;
253 NDBGL1(L1_ERROR
, "ERROR, unknown command = %d, %s, parm = %p", command
, device_xname(&sc
->sc_dev
), parm
);
257 if (pass_down
&& sc
->drv_command
!= NULL
)
258 sc
->drv_command(sc
, command
, parm
);
260 if (command
== CMR_DOPEN
)
261 isic_enable_intr(sc
, 1);
269 isic_enable_intr(struct isic_softc
*sc
, int enable
)
272 if (sc
->sc_cardtyp
== CARD_TYPEP_AVMA1PCIV2
) {
274 isic_isacsx_init(sc
);
275 else isic_isacsx_disable_intr(sc
);
278 #endif /* NNISACSX > 0 */
284 /* disable receiver */
285 ISAC_WRITE(I_MODE
, ISAC_MODE_MDS2
|ISAC_MODE_MDS1
|ISAC_MODE_DIM0
);
286 /* mask interrupts */
288 IPAC_WRITE(IPAC_MASK
, 0xff);
290 ISAC_WRITE(I_MASK
, 0xff);
293 #endif /* NNISAC > 0 */