2 * Copyright (c) 1997, 2000 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
25 *---------------------------------------------------------------------------
27 * i4b_l4if.c - Layer 3 interface to Layer 4
28 * -------------------------------------------
30 * $Id: i4b_l4if.c,v 1.27 2000/08/24 11:48:58 hm Exp $
32 * $FreeBSD: src/sys/i4b/layer3/i4b_l4if.c,v 1.6.2.1 2001/08/10 14:08:42 obrien Exp $
34 * last edit-date: [Fri Jun 2 14:32:19 2000]
36 *---------------------------------------------------------------------------*/
45 #include <sys/param.h>
46 #include <sys/systm.h>
49 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000
50 #include <sys/callout.h>
54 #include <machine/i4b_debug.h>
55 #include <machine/i4b_ioctl.h>
56 #include <machine/i4b_cause.h>
58 #include <i4b/i4b_debug.h>
59 #include <i4b/i4b_ioctl.h>
60 #include <i4b/i4b_cause.h>
63 #include <i4b/include/i4b_l2l3.h>
64 #include <i4b/include/i4b_l3l4.h>
65 #include <i4b/include/i4b_global.h>
67 #include <i4b/layer3/i4b_l3.h>
68 #include <i4b/layer3/i4b_l3fsm.h>
70 #include <i4b/layer4/i4b_l4.h>
72 extern void isic_settrace(int unit, int val); /*XXX*/
73 extern int isic_gettrace(int unit); /*XXX*/
75 static void n_connect_request(u_int cdid);
76 static void n_connect_response(u_int cdid, int response, int cause);
77 static void n_disconnect_request(u_int cdid, int cause);
78 static void n_alert_request(u_int cdid);
79 static void n_mgmt_command(int unit, int cmd, void *parm);
81 /*---------------------------------------------------------------------------*
82 * i4b_mdl_status_ind - status indication from lower layers
83 *---------------------------------------------------------------------------*/
85 i4b_mdl_status_ind(int unit, int status, int parm)
90 NDBGL3(L3_MSG, "unit = %d, status = %d, parm = %d", unit, status, parm);
95 NDBGL3(L3_MSG, "STI_ATTACH: attaching unit %d to controller %d", unit, nctrl);
97 /* init function pointers */
99 ctrl_desc[nctrl].N_CONNECT_REQUEST = n_connect_request;
100 ctrl_desc[nctrl].N_CONNECT_RESPONSE = n_connect_response;
101 ctrl_desc[nctrl].N_DISCONNECT_REQUEST = n_disconnect_request;
102 ctrl_desc[nctrl].N_ALERT_REQUEST = n_alert_request;
103 ctrl_desc[nctrl].N_DOWNLOAD = NULL; /* only used by active cards */
104 ctrl_desc[nctrl].N_DIAGNOSTICS = NULL; /* only used by active cards */
105 ctrl_desc[nctrl].N_MGMT_COMMAND = n_mgmt_command;
107 /* init type and unit */
109 ctrl_desc[nctrl].unit = unit;
110 ctrl_desc[nctrl].ctrl_type = CTRL_PASSIVE;
111 ctrl_desc[nctrl].card_type = parm;
115 ctrl_desc[nctrl].dl_est = DL_DOWN;
116 ctrl_desc[nctrl].nbch = 2; /* XXX extra param? */
117 for (i = 0; i < ctrl_desc[nctrl].nbch; i++)
118 ctrl_desc[nctrl].bch_state[i] = BCH_ST_FREE;
120 ctrl_desc[nctrl].tei = -1;
122 /* init unit to controller table */
124 utoc_tab[unit] = nctrl;
126 /* increment no. of controllers */
133 i4b_l4_l12stat(unit, 1, parm);
134 NDBGL3(L3_MSG, "STI_L1STAT: unit %d layer 1 = %s", unit, status ? "up" : "down");
138 i4b_l4_l12stat(unit, 2, parm);
139 NDBGL3(L3_MSG, "STI_L2STAT: unit %d layer 2 = %s", unit, status ? "up" : "down");
143 ctrl_desc[unit].tei = parm;
144 i4b_l4_teiasg(unit, parm);
145 NDBGL3(L3_MSG, "STI_TEIASG: unit %d TEI = %d = 0x%02x", unit, parm, parm);
148 case STI_PDEACT: /* L1 T4 timeout */
149 NDBGL3(L3_ERR, "STI_PDEACT: unit %d TEI = %d = 0x%02x", unit, parm, parm);
153 for(i=0; i < N_CALL_DESC; i++)
155 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
156 (ctrl_desc[call_desc[i].controller].unit == unit))
158 i4b_l3_stop_all_timers(&(call_desc[i]));
159 if(call_desc[i].cdid != CDID_UNUSED)
164 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
165 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
166 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
167 ctrl_desc[utoc_tab[unit]].tei = -1;
171 i4b_l4_pdeact(unit, sendup);
172 call_desc[i].cdid = CDID_UNUSED;
176 case STI_NOL1ACC: /* no outgoing access to S0 */
177 NDBGL3(L3_ERR, "STI_NOL1ACC: unit %d no outgoing access to S0", unit);
179 for(i=0; i < N_CALL_DESC; i++)
181 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
182 (ctrl_desc[call_desc[i].controller].unit == unit))
184 if(call_desc[i].cdid != CDID_UNUSED)
186 SET_CAUSE_TYPE(call_desc[i].cause_in, CAUSET_I4B);
187 SET_CAUSE_VAL(call_desc[i].cause_in, CAUSE_I4B_L1ERROR);
188 i4b_l4_disconnect_ind(&(call_desc[i]));
193 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
194 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
195 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
196 ctrl_desc[utoc_tab[unit]].tei = -1;
200 NDBGL3(L3_ERR, "ERROR, unit %d, unknown status value %d!", unit, status);
206 /*---------------------------------------------------------------------------*
207 * send command to the lower layers
208 *---------------------------------------------------------------------------*/
210 n_mgmt_command(int unit, int cmd, void *parm)
217 NDBGL3(L3_MSG, "CMR_DOPEN for unit %d", unit);
219 for(i=0; i < N_CALL_DESC; i++)
221 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
222 (ctrl_desc[call_desc[i].controller].unit == unit))
224 call_desc[i].cdid = CDID_UNUSED;
228 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
229 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
230 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
231 ctrl_desc[utoc_tab[unit]].tei = -1;
235 NDBGL3(L3_MSG, "CMR_DCLOSE for unit %d", unit);
239 NDBGL3(L3_MSG, "CMR_SETTRACE for unit %d", unit);
243 NDBGL3(L3_MSG, "unknown cmd %d for unit %d", cmd, unit);
247 MDL_Command_Req(unit, cmd, parm);
251 /*---------------------------------------------------------------------------*
252 * handle connect request message from userland
253 *---------------------------------------------------------------------------*/
255 n_connect_request(u_int cdid)
259 cd = cd_by_cdid(cdid);
261 next_l3state(cd, EV_SETUPRQ);
264 /*---------------------------------------------------------------------------*
265 * handle setup response message from userland
266 *---------------------------------------------------------------------------*/
268 n_connect_response(u_int cdid, int response, int cause)
273 cd = cd_by_cdid(cdid);
277 cd->response = response;
278 cd->cause_out = cause;
282 case SETUP_RESP_ACCEPT:
283 next_l3state(cd, EV_SETACRS);
284 chstate = BCH_ST_USED;
287 case SETUP_RESP_REJECT:
288 next_l3state(cd, EV_SETRJRS);
289 chstate = BCH_ST_FREE;
292 case SETUP_RESP_DNTCRE:
293 next_l3state(cd, EV_SETDCRS);
294 chstate = BCH_ST_FREE;
297 default: /* failsafe */
298 next_l3state(cd, EV_SETDCRS);
299 chstate = BCH_ST_FREE;
300 NDBGL3(L3_ERR, "unknown response, doing SETUP_RESP_DNTCRE");
304 if((cd->channelid >= 0) && (cd->channelid < ctrl_desc[cd->controller].nbch))
306 ctrl_desc[cd->controller].bch_state[cd->channelid] = chstate;
310 NDBGL3(L3_MSG, "Warning, invalid channelid %d, response = %d\n", cd->channelid, response);
314 /*---------------------------------------------------------------------------*
315 * handle disconnect request message from userland
316 *---------------------------------------------------------------------------*/
318 n_disconnect_request(u_int cdid, int cause)
322 cd = cd_by_cdid(cdid);
324 cd->cause_out = cause;
326 next_l3state(cd, EV_DISCRQ);
329 /*---------------------------------------------------------------------------*
330 * handle alert request message from userland
331 *---------------------------------------------------------------------------*/
333 n_alert_request(u_int cdid)
337 cd = cd_by_cdid(cdid);
339 next_l3state(cd, EV_ALERTRQ);
342 #endif /* NI4BQ931 > 0 */