summaryrefslogtreecommitdiffstats
path: root/sys/i4b/layer1/i4b_l1dmux.c
blob: 15f3783f1fbba870b8dcfb3f78f167373078d965 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*-
 * Copyright (c) 2000, 2001 Hellmuth Michaelis. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*---------------------------------------------------------------------------
 *
 *	i4b_l1dmux.c - isdn4bsd layer 1 driver multiplexer
 *	--------------------------------------------------
 *      last edit-date: [Wed Jan 10 16:43:24 2001]
 *
 *---------------------------------------------------------------------------*/

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/systm.h>

#include <i4b/include/i4b_debug.h>
#include <i4b/include/i4b_ioctl.h>
#include <i4b/include/i4b_trace.h>

#include <i4b/layer1/i4b_l1.h>

#include <i4b/include/i4b_l1l2.h>
#include <i4b/include/i4b_global.h>

/*
 * this code is nothing but a big dynamic switch to multiplex and demultiplex
 * layer 1 hardware isdn drivers to a common layer 2.
 *
 * when a card is successfully attached at system boot time, the driver for
 * this card calls the routine i4b_l1_mph_status_ind() with status = STI_ATTACH.
 *
 * This command is used to setup the tables for converting a "driver unit" and
 * "driver type" pair (encoded in the calls from the hardware driver to the
 * routines in this source file) to a "unit number" used in layer 2 and the
 * layers above (up to and including the isdnd daemon) and for converting
 * layer 2 units back to calling the appropriate driver and driver unit
 * number.
 *
 * Example: in my setup, a Winbond (iwic) card is probed first and gets
 * driver unit number 0, driver type 1 in layer 1. This becomes unit
 * number 0 in layer 2 and up. The second card probed is a Teles card
 * (isic) and gets driver unit number 0, driver type 0 in layer 1. This
 * becomes unit number 1 in layer 1 and up.
 *
 * To add support for a new driver, add a new driver number to i4b_l1.h:
 * currently we have L1DRVR_ISIC and L1DRVR_IWIC, so you would add
 * L1DRVR_FOO. More you would want to add a L0FOOUNIT to encode unit
 * numbers in your driver. You then have to add a l1foounittab[] and
 * add an entry to the getl1tab() routine for your driver. The only
 * thing left now is to write your driver with the support functions
 * for this multiplexer ;-)
 */
 
unsigned int i4b_l1_debug = L1_DEBUG_DEFAULT;

static int l1isicunittab[MAXL1UNITS];

static int l1iwicunittab[MAXL1UNITS];

static int l1ifpiunittab[MAXL1UNITS];

static int l1ifpi2unittab[MAXL1UNITS];

static int l1ihfcunittab[MAXL1UNITS];

static int l1ifpnpunittab[MAXL1UNITS];

static int l1itjcunittab[MAXL1UNITS];

static int numl1units = 0;

static int l1drvunittab[MAXL1UNITS];
static struct i4b_l1mux_func *l1mux_func[MAXL1DRVR];

static int i4b_l1_ph_data_req(int, struct mbuf *, int);
static int i4b_l1_ph_activate_req(int);

/* from i4btrc driver i4b_trace.c */
int get_trace_data_from_l1(int unit, int what, int len, char *buf);

/* from layer 2 */
int i4b_ph_data_ind(int unit, struct mbuf *m);
int i4b_ph_activate_ind(int unit);
int i4b_ph_deactivate_ind(int unit);
int i4b_mph_status_ind(int, int, int);

/* layer 1 lme */
int i4b_l1_mph_command_req(int, int, void *);

/*---------------------------------------------------------------------------*
 *	jump table: interface function pointers L1/L2 interface 
 *---------------------------------------------------------------------------*/
struct i4b_l1l2_func i4b_l1l2_func = {

	/* Layer 1 --> Layer 2 */
	
	(int (*)(int, struct mbuf *))		i4b_ph_data_ind,
	(int (*)(int)) 				i4b_ph_activate_ind,
	(int (*)(int))				i4b_ph_deactivate_ind,

	/* Layer 2 --> Layer 1 */

	(int (*)(int, struct mbuf *, int))	i4b_l1_ph_data_req,

	(int (*)(int))				i4b_l1_ph_activate_req,

	/* Layer 1 --> trace interface driver, ISDN trace data */

	(int (*)(i4b_trace_hdr_t *, int, u_char *)) get_trace_data_from_l1,

	/* Driver control and status information */

	(int (*)(int, int, int))		i4b_mph_status_ind,
	(int (*)(int, int, void *))		i4b_l1_mph_command_req,
};

/*---------------------------------------------------------------------------*
 *	return a pointer to a layer 0 drivers unit tab
 *---------------------------------------------------------------------------*/
static __inline int *
getl1tab(int drv)
{
	switch(drv)
	{
		case L1DRVR_ISIC:
			return(l1isicunittab);
			break;
		case L1DRVR_IWIC:
			return(l1iwicunittab);
			break;
		case L1DRVR_IFPI:
			return(l1ifpiunittab);
			break;
		case L1DRVR_IFPI2:
			return(l1ifpi2unittab);
			break;
		case L1DRVR_IHFC:
			return(l1ihfcunittab);
			break;
		case L1DRVR_IFPNP:
			return(l1ifpnpunittab);
			break;
		case L1DRVR_ITJC:
			return(l1itjcunittab);
			break;
		default:
			return(NULL);
			break;
	}
}

/*===========================================================================*
 *	B - Channel (data transfer)
 *===========================================================================*/

/*---------------------------------------------------------------------------*
 *	return the address of ISDN drivers linktab	
 *---------------------------------------------------------------------------*/
isdn_link_t *
i4b_l1_ret_linktab(int unit, int channel)
{
	int drv_unit, ch_unit;
 
	drv_unit = L0DRVR(l1drvunittab[unit]);
	ch_unit = L0UNIT(l1drvunittab[unit]);
 
	NDBGL1(L1_PRIM, "unit %d -> drv %d / drvunit %d", unit, drv_unit, ch_unit);

	if (drv_unit >= MAXL1DRVR || l1mux_func[drv_unit] == NULL
	    || l1mux_func[drv_unit]->ret_linktab == NULL)
		panic("i4b_l1_ret_linktab: unknown driver type %d\n", drv_unit);

	return(l1mux_func[drv_unit]->ret_linktab(ch_unit, channel));
}
 
/*---------------------------------------------------------------------------*
 *	set the ISDN driver linktab
 *---------------------------------------------------------------------------*/
void
i4b_l1_set_linktab(int unit, int channel, drvr_link_t *dlt)
{
	int drv_unit, ch_unit;
 
	drv_unit = L0DRVR(l1drvunittab[unit]);
	ch_unit = L0UNIT(l1drvunittab[unit]);
 
	NDBGL1(L1_PRIM, "unit %d -> drv %d / drvunit %d", unit, drv_unit, ch_unit);

	if (drv_unit >= MAXL1DRVR || l1mux_func[drv_unit] == NULL
	    || l1mux_func[drv_unit]->set_linktab == NULL)
		panic("i4b_l1_set_linktab: unknown driver type %d\n", drv_unit);

	l1mux_func[drv_unit]->set_linktab(ch_unit, channel, dlt);
}

/*===========================================================================*
 *	trace D- and B-Channel support
 *===========================================================================*/

/*---------------------------------------------------------------------------*
 *	L0 -> L1 trace information to trace driver
 *---------------------------------------------------------------------------*/
int
i4b_l1_trace_ind(i4b_trace_hdr_t *hdr, int len, u_char *data)
{
	register int *tab;
	
	if((tab = getl1tab(L0DRVR(hdr->unit))) == NULL)
		panic("i4b_l1_trace_ind: unknown driver type %d\n", L0DRVR(hdr->unit));

	NDBGL1(L1_PRIM, "(drv %d / drvunit %d) -> unit %d", L0DRVR(hdr->unit), L0UNIT(hdr->unit), tab[L0UNIT(hdr->unit)]);
	
	hdr->unit = tab[L0UNIT(hdr->unit)];

	return(MPH_Trace_Ind(hdr, len, data));
}

/*===========================================================================*
 *	D - Channel (signalling)
 *===========================================================================*/

/*---------------------------------------------------------------------------*
 *	L0 -> L1 status indication from hardware
 *---------------------------------------------------------------------------*/
int
i4b_l1_mph_status_ind(int drv_unit, int status, int parm, struct i4b_l1mux_func *l1mux_func_p)
{
	register int *tab;
	
	/*
	 * in case the status STI_ATTACH is sent from the hardware, the
	 * driver has just attached itself and we need to initialize
	 * the tables and assorted variables.
	 */

	if(status == STI_ATTACH)
	{
		if (l1mux_func_p == (struct i4b_l1mux_func *)0)
			panic("i4b_l1_mph_status_ind: i4b_l1mux_func pointer is NULL\n");

		if(numl1units < MAXL1UNITS)
		{
			if((tab = getl1tab(L0DRVR(drv_unit))) == NULL)
				panic("i4b_l1_mph_status_ind: unknown driver type %d\n", L0DRVR(drv_unit));
			
			tab[L0UNIT(drv_unit)] = numl1units;

			l1drvunittab[numl1units] = drv_unit;

			l1mux_func[L0DRVR(drv_unit)] = l1mux_func_p;

			switch(L0DRVR(drv_unit))
			{
				case L1DRVR_ISIC:
					printf("isic%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_IWIC:
					printf("iwic%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_IFPI:
					printf("ifpi%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_IFPI2:
					printf("ifpi2-%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_IFPNP:
					printf("ifpnp%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_IHFC:
					printf("ihfc%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
				case L1DRVR_ITJC:
					printf("itjc%d: passive stack unit %d\n", L0UNIT(drv_unit), numl1units);
					break;
			}
			
			NDBGL1(L1_PRIM, "ATTACH drv %d, drvunit %d -> unit %d", L0DRVR(drv_unit), L0UNIT(drv_unit), numl1units);

			numl1units++;			
		}
	}

	if((tab = getl1tab(L0DRVR(drv_unit))) == NULL)	
		panic("i4b_l1_mph_status_ind: unknown driver type %d\n", L0DRVR(drv_unit));

	NDBGL1(L1_PRIM, "(drv %d / drvunit %d) -> unit %d\n", L0DRVR(drv_unit), L0UNIT(drv_unit), tab[L0UNIT(drv_unit)]);
	
	return(MPH_Status_Ind(tab[L0UNIT(drv_unit)], status, parm));
}

/*---------------------------------------------------------------------------*
 *	L0 -> L1 data from hardware
 *---------------------------------------------------------------------------*/
int
i4b_l1_ph_data_ind(int drv_unit, struct mbuf *data)
{
	register int *tab;

	if((tab = getl1tab(L0DRVR(drv_unit))) == NULL)	
		panic("i4b_l1_ph_data_ind: unknown driver type %d\n", L0DRVR(drv_unit));

#if 0
	NDBGL1(L1_PRIM, "(drv %d / drvunit %d) -> unit %d", L0DRVR(drv_unit), L0UNIT(drv_unit), tab[L0UNIT(drv_unit)]);
#endif

	return(PH_Data_Ind(tab[L0UNIT(drv_unit)], data));
}

/*---------------------------------------------------------------------------*
 *	L0 -> L1 activate indication from hardware
 *---------------------------------------------------------------------------*/
int
i4b_l1_ph_activate_ind(int drv_unit)
{
	register int *tab;

	if((tab = getl1tab(L0DRVR(drv_unit))) == NULL)	
		panic("i4b_l1_ph_activate_ind: unknown driver type %d\n", L0DRVR(drv_unit));

	NDBGL1(L1_PRIM, "(drv %d / drvunit %d) -> unit %d", L0DRVR(drv_unit), L0UNIT(drv_unit), tab[L0UNIT(drv_unit)]);

	return(PH_Act_Ind(tab[L0UNIT(drv_unit)]));
}

/*---------------------------------------------------------------------------*
 *	L0 -> L1 deactivate indication from hardware
 *---------------------------------------------------------------------------*/
int
i4b_l1_ph_deactivate_ind(int drv_unit)
{
	register int *tab;
	
	if((tab = getl1tab(L0DRVR(drv_unit))) == NULL)
		panic("i4b_l1_ph_deactivate_ind: unknown driver type %d\n", L0DRVR(drv_unit));

	NDBGL1(L1_PRIM, "(drv %d / drvunit %d) -> unit %d", L0DRVR(drv_unit), L0UNIT(drv_unit), tab[L0UNIT(drv_unit)]);		

	return(PH_Deact_Ind(tab[L0UNIT(drv_unit)]));
}
	
/*---------------------------------------------------------------------------*
 *	L2 -> L1 command to hardware
 *---------------------------------------------------------------------------*/
int
i4b_l1_mph_command_req(int unit, int command, void * parm)
{
	register int drv_unit = L0DRVR(l1drvunittab[unit]);
	register int ch_unit = L0UNIT(l1drvunittab[unit]);
 
	NDBGL1(L1_PRIM, "unit %d -> drv %d / drvunit %d", unit, drv_unit, ch_unit);

	if (drv_unit >= MAXL1DRVR || l1mux_func[drv_unit] == NULL
	    || l1mux_func[drv_unit]->mph_command_req == NULL)
		panic("i4b_l1_mph_command_req: unknown driver type %d\n", drv_unit);
 
	return(l1mux_func[drv_unit]->mph_command_req(ch_unit, command, parm));
}

/*---------------------------------------------------------------------------*
 *	L2 -> L1 data to be transmitted to hardware
 *---------------------------------------------------------------------------*/
static int
i4b_l1_ph_data_req(int unit, struct mbuf *data, int flag)
{
	register int drv_unit = L0DRVR(l1drvunittab[unit]);
	register int ch_unit = L0UNIT(l1drvunittab[unit]);

#if 0
	NDBGL1(L1_PRIM, "unit %d -> drv %d / drvunit %d", unit, drv_unit, ch_unit);
#endif
	
	if (drv_unit >= MAXL1DRVR || l1mux_func[drv_unit] == NULL
	    || l1mux_func[drv_unit]->ph_data_req == NULL)
		panic("i4b_l1_ph_data_req: unknown driver type %d\n", drv_unit);

	return(l1mux_func[drv_unit]->ph_data_req(ch_unit, data, flag));
}

/*---------------------------------------------------------------------------*
 *	L2 -> L1 activate request to hardware
 *---------------------------------------------------------------------------*/
static int
i4b_l1_ph_activate_req(int unit)
{
	register int drv_unit = L0DRVR(l1drvunittab[unit]);
	register int ch_unit = L0UNIT(l1drvunittab[unit]);
 
	NDBGL1(L1_PRIM, "unit %d -> drv %d / drvunit %d", unit, drv_unit, ch_unit);

	if (drv_unit >= MAXL1DRVR || l1mux_func[drv_unit] == NULL
	    || l1mux_func[drv_unit]->ph_activate_req == NULL)
		panic("i4b_l1_ph_activate_req: unknown driver type %d\n", drv_unit);

	return(l1mux_func[drv_unit]->ph_activate_req(ch_unit));
}

/* EOF */
OpenPOWER on IntegriCloud