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
|
/* $Id: mntfunc.c,v 1.19.6.4 2005/01/31 12:22:20 armin Exp $
*
* Driver for Eicon DIVA Server ISDN cards.
* Maint module
*
* Copyright 2000-2003 by Armin Schindler (mac@melware.de)
* Copyright 2000-2003 Cytronics & Melware (info@melware.de)
*
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*/
#include "platform.h"
#include "di_defs.h"
#include "divasync.h"
#include "debug_if.h"
extern char *DRIVERRELEASE_MNT;
#define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
#define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
extern void DIVA_DIDD_Read(void *, int);
static dword notify_handle;
static DESCRIPTOR DAdapter;
static DESCRIPTOR MAdapter;
static DESCRIPTOR MaintDescriptor =
{ IDI_DIMAINT, 0, 0, (IDI_CALL) diva_maint_prtComp };
extern int diva_os_copy_to_user(void *os_handle, void __user *dst,
const void *src, int length);
extern int diva_os_copy_from_user(void *os_handle, void *dst,
const void __user *src, int length);
static void no_printf(unsigned char *x, ...)
{
/* dummy debug function */
}
#include "debuglib.c"
/*
* DIDD callback function
*/
static void *didd_callback(void *context, DESCRIPTOR * adapter,
int removal)
{
if (adapter->type == IDI_DADAPTER) {
DBG_ERR(("cb: Change in DAdapter ? Oops ?."));
} else if (adapter->type == IDI_DIMAINT) {
if (removal) {
DbgDeregister();
memset(&MAdapter, 0, sizeof(MAdapter));
dprintf = no_printf;
} else {
memcpy(&MAdapter, adapter, sizeof(MAdapter));
dprintf = (DIVA_DI_PRINTF) MAdapter.request;
DbgRegister("MAINT", DRIVERRELEASE_MNT, DBG_DEFAULT);
}
} else if ((adapter->type > 0) && (adapter->type < 16)) {
if (removal) {
diva_mnt_remove_xdi_adapter(adapter);
} else {
diva_mnt_add_xdi_adapter(adapter);
}
}
return (NULL);
}
/*
* connect to didd
*/
static int DIVA_INIT_FUNCTION connect_didd(void)
{
int x = 0;
int dadapter = 0;
IDI_SYNC_REQ req;
DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
for (x = 0; x < MAX_DESCRIPTORS; x++) {
if (DIDD_Table[x].type == IDI_DADAPTER) { /* DADAPTER found */
dadapter = 1;
memcpy(&DAdapter, &DIDD_Table[x], sizeof(DAdapter));
req.didd_notify.e.Req = 0;
req.didd_notify.e.Rc =
IDI_SYNC_REQ_DIDD_REGISTER_ADAPTER_NOTIFY;
req.didd_notify.info.callback = (void *)didd_callback;
req.didd_notify.info.context = NULL;
DAdapter.request((ENTITY *) & req);
if (req.didd_notify.e.Rc != 0xff)
return (0);
notify_handle = req.didd_notify.info.handle;
/* Register MAINT (me) */
req.didd_add_adapter.e.Req = 0;
req.didd_add_adapter.e.Rc =
IDI_SYNC_REQ_DIDD_ADD_ADAPTER;
req.didd_add_adapter.info.descriptor =
(void *) &MaintDescriptor;
DAdapter.request((ENTITY *) & req);
if (req.didd_add_adapter.e.Rc != 0xff)
return (0);
} else if ((DIDD_Table[x].type > 0)
&& (DIDD_Table[x].type < 16)) {
diva_mnt_add_xdi_adapter(&DIDD_Table[x]);
}
}
return (dadapter);
}
/*
* disconnect from didd
*/
static void DIVA_EXIT_FUNCTION disconnect_didd(void)
{
IDI_SYNC_REQ req;
req.didd_notify.e.Req = 0;
req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY;
req.didd_notify.info.handle = notify_handle;
DAdapter.request((ENTITY *) & req);
req.didd_remove_adapter.e.Req = 0;
req.didd_remove_adapter.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER;
req.didd_remove_adapter.info.p_request =
(IDI_CALL) MaintDescriptor.request;
DAdapter.request((ENTITY *) & req);
}
/*
* read/write maint
*/
int maint_read_write(void __user *buf, int count)
{
byte data[128];
dword cmd, id, mask;
int ret = 0;
if (count < (3 * sizeof(dword)))
return (-EFAULT);
if (diva_os_copy_from_user(NULL, (void *) &data[0],
buf, 3 * sizeof(dword))) {
return (-EFAULT);
}
cmd = *(dword *) & data[0]; /* command */
id = *(dword *) & data[4]; /* driver id */
mask = *(dword *) & data[8]; /* mask or size */
switch (cmd) {
case DITRACE_CMD_GET_DRIVER_INFO:
if ((ret = diva_get_driver_info(id, data, sizeof(data))) > 0) {
if ((count < ret) || diva_os_copy_to_user
(NULL, buf, (void *) &data[0], ret))
ret = -EFAULT;
} else {
ret = -EINVAL;
}
break;
case DITRACE_READ_DRIVER_DBG_MASK:
if ((ret = diva_get_driver_dbg_mask(id, (byte *) data)) > 0) {
if ((count < ret) || diva_os_copy_to_user
(NULL, buf, (void *) &data[0], ret))
ret = -EFAULT;
} else {
ret = -ENODEV;
}
break;
case DITRACE_WRITE_DRIVER_DBG_MASK:
if ((ret = diva_set_driver_dbg_mask(id, mask)) <= 0) {
ret = -ENODEV;
}
break;
/*
Filter commands will ignore the ID due to fact that filtering affects
the B- channel and Audio Tap trace levels only. Also MAINT driver will
select the right trace ID by itself
*/
case DITRACE_WRITE_SELECTIVE_TRACE_FILTER:
if (!mask) {
ret = diva_set_trace_filter (1, "*");
} else if (mask < sizeof(data)) {
if (diva_os_copy_from_user(NULL, data, (char __user *)buf+12, mask)) {
ret = -EFAULT;
} else {
ret = diva_set_trace_filter ((int)mask, data);
}
} else {
ret = -EINVAL;
}
break;
case DITRACE_READ_SELECTIVE_TRACE_FILTER:
if ((ret = diva_get_trace_filter (sizeof(data), data)) > 0) {
if (diva_os_copy_to_user (NULL, buf, data, ret))
ret = -EFAULT;
} else {
ret = -ENODEV;
}
break;
case DITRACE_READ_TRACE_ENTRY:{
diva_os_spin_lock_magic_t old_irql;
word size;
diva_dbg_entry_head_t *pmsg;
byte *pbuf;
if (!(pbuf = diva_os_malloc(0, mask))) {
return (-ENOMEM);
}
for(;;) {
if (!(pmsg =
diva_maint_get_message(&size, &old_irql))) {
break;
}
if (size > mask) {
diva_maint_ack_message(0, &old_irql);
ret = -EINVAL;
break;
}
ret = size;
memcpy(pbuf, pmsg, size);
diva_maint_ack_message(1, &old_irql);
if ((count < size) ||
diva_os_copy_to_user (NULL, buf, (void *) pbuf, size))
ret = -EFAULT;
break;
}
diva_os_free(0, pbuf);
}
break;
case DITRACE_READ_TRACE_ENTRYS:{
diva_os_spin_lock_magic_t old_irql;
word size;
diva_dbg_entry_head_t *pmsg;
byte *pbuf = NULL;
int written = 0;
if (mask < 4096) {
ret = -EINVAL;
break;
}
if (!(pbuf = diva_os_malloc(0, mask))) {
return (-ENOMEM);
}
for (;;) {
if (!(pmsg =
diva_maint_get_message(&size, &old_irql))) {
break;
}
if ((size + 8) > mask) {
diva_maint_ack_message(0, &old_irql);
break;
}
/*
Write entry length
*/
pbuf[written++] = (byte) size;
pbuf[written++] = (byte) (size >> 8);
pbuf[written++] = 0;
pbuf[written++] = 0;
/*
Write message
*/
memcpy(&pbuf[written], pmsg, size);
diva_maint_ack_message(1, &old_irql);
written += size;
mask -= (size + 4);
}
pbuf[written++] = 0;
pbuf[written++] = 0;
pbuf[written++] = 0;
pbuf[written++] = 0;
if ((count < written) || diva_os_copy_to_user(NULL, buf, (void *) pbuf, written)) {
ret = -EFAULT;
} else {
ret = written;
}
diva_os_free(0, pbuf);
}
break;
default:
ret = -EINVAL;
}
return (ret);
}
/*
* init
*/
int DIVA_INIT_FUNCTION mntfunc_init(int *buffer_length, void **buffer,
unsigned long diva_dbg_mem)
{
if (*buffer_length < 64) {
*buffer_length = 64;
}
if (*buffer_length > 512) {
*buffer_length = 512;
}
*buffer_length *= 1024;
if (diva_dbg_mem) {
*buffer = (void *) diva_dbg_mem;
} else {
while ((*buffer_length >= (64 * 1024))
&&
(!(*buffer = diva_os_malloc (0, *buffer_length)))) {
*buffer_length -= 1024;
}
if (!*buffer) {
DBG_ERR(("init: Can not alloc trace buffer"));
return (0);
}
}
if (diva_maint_init(*buffer, *buffer_length, (diva_dbg_mem == 0))) {
if (!diva_dbg_mem) {
diva_os_free (0, *buffer);
}
DBG_ERR(("init: maint init failed"));
return (0);
}
if (!connect_didd()) {
DBG_ERR(("init: failed to connect to DIDD."));
diva_maint_finit();
if (!diva_dbg_mem) {
diva_os_free (0, *buffer);
}
return (0);
}
return (1);
}
/*
* exit
*/
void DIVA_EXIT_FUNCTION mntfunc_finit(void)
{
void *buffer;
int i = 100;
DbgDeregister();
while (diva_mnt_shutdown_xdi_adapters() && i--) {
diva_os_sleep(10);
}
disconnect_didd();
if ((buffer = diva_maint_finit())) {
diva_os_free (0, buffer);
}
memset(&MAdapter, 0, sizeof(MAdapter));
dprintf = no_printf;
}
|