mISDN: Cleanup debug messages
[safe/jmp/linux-2.6] / drivers / isdn / mISDN / dsp_core.c
1 /*
2  * Author       Andreas Eversberg (jolly@eversberg.eu)
3  * Based on source code structure by
4  *              Karsten Keil (keil@isdn4linux.de)
5  *
6  *              This file is (c) under GNU PUBLIC LICENSE
7  *              For changes and modifications please read
8  *              ../../../Documentation/isdn/mISDN.cert
9  *
10  * Thanks to    Karsten Keil (great drivers)
11  *              Cologne Chip (great chips)
12  *
13  * This module does:
14  *              Real-time tone generation
15  *              DTMF detection
16  *              Real-time cross-connection and conferrence
17  *              Compensate jitter due to system load and hardware fault.
18  *              All features are done in kernel space and will be realized
19  *              using hardware, if available and supported by chip set.
20  *              Blowfish encryption/decryption
21  */
22
23 /* STRUCTURE:
24  *
25  * The dsp module provides layer 2 for b-channels (64kbit). It provides
26  * transparent audio forwarding with special digital signal processing:
27  *
28  * - (1) generation of tones
29  * - (2) detection of dtmf tones
30  * - (3) crossconnecting and conferences (clocking)
31  * - (4) echo generation for delay test
32  * - (5) volume control
33  * - (6) disable receive data
34  * - (7) pipeline
35  * - (8) encryption/decryption
36  *
37  * Look:
38  *             TX            RX
39  *         ------upper layer------
40  *             |             ^
41  *             |             |(6)
42  *             v             |
43  *       +-----+-------------+-----+
44  *       |(3)(4)                   |
45  *       |           CMX           |
46  *       |                         |
47  *       |           +-------------+
48  *       |           |       ^
49  *       |           |       |
50  *       |+---------+|  +----+----+
51  *       ||(1)      ||  |(2)      |
52  *       ||         ||  |         |
53  *       ||  Tones  ||  |  DTMF   |
54  *       ||         ||  |         |
55  *       ||         ||  |         |
56  *       |+----+----+|  +----+----+
57  *       +-----+-----+       ^
58  *             |             |
59  *             v             |
60  *        +----+----+   +----+----+
61  *        |(5)      |   |(5)      |
62  *        |         |   |         |
63  *        |TX Volume|   |RX Volume|
64  *        |         |   |         |
65  *        |         |   |         |
66  *        +----+----+   +----+----+
67  *             |             ^
68  *             |             |
69  *             v             |
70  *        +----+-------------+----+
71  *        |(7)                    |
72  *        |                       |
73  *        |  Pipeline Processing  |
74  *        |                       |
75  *        |                       |
76  *        +----+-------------+----+
77  *             |             ^
78  *             |             |
79  *             v             |
80  *        +----+----+   +----+----+
81  *        |(8)      |   |(8)      |
82  *        |         |   |         |
83  *        | Encrypt |   | Decrypt |
84  *        |         |   |         |
85  *        |         |   |         |
86  *        +----+----+   +----+----+
87  *             |             ^
88  *             |             |
89  *             v             |
90  *         ------card  layer------
91  *             TX            RX
92  *
93  * Above you can see the logical data flow. If software is used to do the
94  * process, it is actually the real data flow. If hardware is used, data
95  * may not flow, but hardware commands to the card, to provide the data flow
96  * as shown.
97  *
98  * NOTE: The channel must be activated in order to make dsp work, even if
99  * no data flow to the upper layer is intended. Activation can be done
100  * after and before controlling the setting using PH_CONTROL requests.
101  *
102  * DTMF: Will be detected by hardware if possible. It is done before CMX
103  * processing.
104  *
105  * Tones: Will be generated via software if endless looped audio fifos are
106  * not supported by hardware. Tones will override all data from CMX.
107  * It is not required to join a conference to use tones at any time.
108  *
109  * CMX: Is transparent when not used. When it is used, it will do
110  * crossconnections and conferences via software if not possible through
111  * hardware. If hardware capability is available, hardware is used.
112  *
113  * Echo: Is generated by CMX and is used to check performane of hard and
114  * software CMX.
115  *
116  * The CMX has special functions for conferences with one, two and more
117  * members. It will allow different types of data flow. Receive and transmit
118  * data to/form upper layer may be swithed on/off individually without loosing
119  * features of CMX, Tones and DTMF.
120  *
121  * Echo Cancellation: Sometimes we like to cancel echo from the interface.
122  * Note that a VoIP call may not have echo caused by the IP phone. The echo
123  * is generated by the telephone line connected to it. Because the delay
124  * is high, it becomes an echo. RESULT: Echo Cachelation is required if
125  * both echo AND delay is applied to an interface.
126  * Remember that software CMX always generates a more or less delay.
127  *
128  * If all used features can be realized in hardware, and if transmit and/or
129  * receive data ist disabled, the card may not send/receive any data at all.
130  * Not receiving is usefull if only announcements are played. Not sending is
131  * usefull if an answering machine records audio. Not sending and receiving is
132  * usefull during most states of the call. If supported by hardware, tones
133  * will be played without cpu load. Small PBXs and NT-Mode applications will
134  * not need expensive hardware when processing calls.
135  *
136  *
137  * LOCKING:
138  *
139  * When data is received from upper or lower layer (card), the complete dsp
140  * module is locked by a global lock.  This lock MUST lock irq, because it
141  * must lock timer events by DSP poll timer.
142  * When data is ready to be transmitted down, the data is queued and sent
143  * outside lock and timer event.
144  * PH_CONTROL must not change any settings, join or split conference members
145  * during process of data.
146  *
147  * HDLC:
148  *
149  * It works quite the same as transparent, except that HDLC data is forwarded
150  * to all other conference members if no hardware bridging is possible.
151  * Send data will be writte to sendq. Sendq will be sent if confirm is received.
152  * Conference cannot join, if one member is not hdlc.
153  *
154  */
155
156 #include <linux/delay.h>
157 #include <linux/mISDNif.h>
158 #include <linux/mISDNdsp.h>
159 #include <linux/module.h>
160 #include <linux/vmalloc.h>
161 #include "core.h"
162 #include "dsp.h"
163
164 static const char *mISDN_dsp_revision = "2.0";
165
166 static int debug;
167 static int options;
168 static int poll;
169 static int dtmfthreshold = 100;
170
171 MODULE_AUTHOR("Andreas Eversberg");
172 module_param(debug, uint, S_IRUGO | S_IWUSR);
173 module_param(options, uint, S_IRUGO | S_IWUSR);
174 module_param(poll, uint, S_IRUGO | S_IWUSR);
175 module_param(dtmfthreshold, uint, S_IRUGO | S_IWUSR);
176 MODULE_LICENSE("GPL");
177
178 /*int spinnest = 0;*/
179
180 spinlock_t dsp_lock; /* global dsp lock */
181 struct list_head dsp_ilist;
182 struct list_head conf_ilist;
183 int dsp_debug;
184 int dsp_options;
185 int dsp_poll, dsp_tics;
186
187 /* check if rx may be turned off or must be turned on */
188 static void
189 dsp_rx_off_member(struct dsp *dsp)
190 {
191         struct mISDN_ctrl_req   cq;
192         int rx_off = 1;
193
194         memset(&cq, 0, sizeof(cq));
195
196         if (!dsp->features_rx_off)
197                 return;
198
199         /* not disabled */
200         if (!dsp->rx_disabled)
201                 rx_off = 0;
202         /* software dtmf */
203         else if (dsp->dtmf.software)
204                 rx_off = 0;
205         /* echo in software */
206         else if (dsp->echo.software)
207                 rx_off = 0;
208         /* bridge in software */
209         else if (dsp->conf && dsp->conf->software)
210                 rx_off = 0;
211         /* data is not required by user space and not required
212          * for echo dtmf detection, soft-echo, soft-bridging */
213
214         if (rx_off == dsp->rx_is_off)
215                 return;
216
217         if (!dsp->ch.peer) {
218                 if (dsp_debug & DEBUG_DSP_CORE)
219                         printk(KERN_DEBUG "%s: no peer, no rx_off\n",
220                                 __func__);
221                 return;
222         }
223         cq.op = MISDN_CTRL_RX_OFF;
224         cq.p1 = rx_off;
225         if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
226                 printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
227                         __func__);
228                 return;
229         }
230         dsp->rx_is_off = rx_off;
231         if (dsp_debug & DEBUG_DSP_CORE)
232                 printk(KERN_DEBUG "%s: %s set rx_off = %d\n",
233                         __func__, dsp->name, rx_off);
234 }
235 static void
236 dsp_rx_off(struct dsp *dsp)
237 {
238         struct dsp_conf_member  *member;
239
240         if (dsp_options & DSP_OPT_NOHARDWARE)
241                 return;
242
243         /* no conf */
244         if (!dsp->conf) {
245                 dsp_rx_off_member(dsp);
246                 return;
247         }
248         /* check all members in conf */
249         list_for_each_entry(member, &dsp->conf->mlist, list) {
250                 dsp_rx_off_member(member->dsp);
251         }
252 }
253
254 /* enable "fill empty" feature */
255 static void
256 dsp_fill_empty(struct dsp *dsp)
257 {
258         struct mISDN_ctrl_req   cq;
259
260         memset(&cq, 0, sizeof(cq));
261
262         if (!dsp->ch.peer) {
263                 if (dsp_debug & DEBUG_DSP_CORE)
264                         printk(KERN_DEBUG "%s: no peer, no fill_empty\n",
265                                 __func__);
266                 return;
267         }
268         cq.op = MISDN_CTRL_FILL_EMPTY;
269         cq.p1 = 1;
270         if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
271                 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
272                         __func__);
273                 return;
274         }
275         if (dsp_debug & DEBUG_DSP_CORE)
276                 printk(KERN_DEBUG "%s: %s set fill_empty = 1\n",
277                         __func__, dsp->name);
278 }
279
280 static int
281 dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb)
282 {
283         struct sk_buff  *nskb;
284         int ret = 0;
285         int cont;
286         u8 *data;
287         int len;
288
289         if (skb->len < sizeof(int))
290                 printk(KERN_ERR "%s: PH_CONTROL message too short\n", __func__);
291         cont = *((int *)skb->data);
292         len = skb->len - sizeof(int);
293         data = skb->data + sizeof(int);
294
295         switch (cont) {
296         case DTMF_TONE_START: /* turn on DTMF */
297                 if (dsp->hdlc) {
298                         ret = -EINVAL;
299                         break;
300                 }
301                 if (dsp_debug & DEBUG_DSP_CORE)
302                         printk(KERN_DEBUG "%s: start dtmf\n", __func__);
303                 if (len == sizeof(int)) {
304                         if (dsp_debug & DEBUG_DSP_CORE)
305                                 printk(KERN_NOTICE "changing DTMF Threshold "
306                                         "to %d\n", *((int *)data));
307                         dsp->dtmf.treshold = (*(int *)data) * 10000;
308                 }
309                 /* init goertzel */
310                 dsp_dtmf_goertzel_init(dsp);
311
312                 /* check dtmf hardware */
313                 dsp_dtmf_hardware(dsp);
314                 dsp_rx_off(dsp);
315                 break;
316         case DTMF_TONE_STOP: /* turn off DTMF */
317                 if (dsp_debug & DEBUG_DSP_CORE)
318                         printk(KERN_DEBUG "%s: stop dtmf\n", __func__);
319                 dsp->dtmf.hardware = 0;
320                 dsp->dtmf.software = 0;
321                 break;
322         case DSP_CONF_JOIN: /* join / update conference */
323                 if (len < sizeof(int)) {
324                         ret = -EINVAL;
325                         break;
326                 }
327                 if (*((u32 *)data) == 0)
328                         goto conf_split;
329                 if (dsp_debug & DEBUG_DSP_CORE)
330                         printk(KERN_DEBUG "%s: join conference %d\n",
331                                 __func__, *((u32 *)data));
332                 ret = dsp_cmx_conf(dsp, *((u32 *)data));
333                         /* dsp_cmx_hardware will also be called here */
334                 dsp_rx_off(dsp);
335                 if (dsp_debug & DEBUG_DSP_CMX)
336                         dsp_cmx_debug(dsp);
337                 break;
338         case DSP_CONF_SPLIT: /* remove from conference */
339 conf_split:
340                 if (dsp_debug & DEBUG_DSP_CORE)
341                         printk(KERN_DEBUG "%s: release conference\n", __func__);
342                 ret = dsp_cmx_conf(dsp, 0);
343                         /* dsp_cmx_hardware will also be called here */
344                 if (dsp_debug & DEBUG_DSP_CMX)
345                         dsp_cmx_debug(dsp);
346                 dsp_rx_off(dsp);
347                 break;
348         case DSP_TONE_PATT_ON: /* play tone */
349                 if (dsp->hdlc) {
350                         ret = -EINVAL;
351                         break;
352                 }
353                 if (len < sizeof(int)) {
354                         ret = -EINVAL;
355                         break;
356                 }
357                 if (dsp_debug & DEBUG_DSP_CORE)
358                         printk(KERN_DEBUG "%s: turn tone 0x%x on\n",
359                                 __func__, *((int *)skb->data));
360                 ret = dsp_tone(dsp, *((int *)data));
361                 if (!ret) {
362                         dsp_cmx_hardware(dsp->conf, dsp);
363                         dsp_rx_off(dsp);
364                 }
365                 if (!dsp->tone.tone)
366                         goto tone_off;
367                 break;
368         case DSP_TONE_PATT_OFF: /* stop tone */
369                 if (dsp->hdlc) {
370                         ret = -EINVAL;
371                         break;
372                 }
373                 if (dsp_debug & DEBUG_DSP_CORE)
374                         printk(KERN_DEBUG "%s: turn tone off\n", __func__);
375                 dsp_tone(dsp, 0);
376                 dsp_cmx_hardware(dsp->conf, dsp);
377                 dsp_rx_off(dsp);
378                 /* reset tx buffers (user space data) */
379 tone_off:
380                 dsp->rx_W = 0;
381                 dsp->rx_R = 0;
382                 break;
383         case DSP_VOL_CHANGE_TX: /* change volume */
384                 if (dsp->hdlc) {
385                         ret = -EINVAL;
386                         break;
387                 }
388                 if (len < sizeof(int)) {
389                         ret = -EINVAL;
390                         break;
391                 }
392                 dsp->tx_volume = *((int *)data);
393                 if (dsp_debug & DEBUG_DSP_CORE)
394                         printk(KERN_DEBUG "%s: change tx vol to %d\n",
395                                 __func__, dsp->tx_volume);
396                 dsp_cmx_hardware(dsp->conf, dsp);
397                 dsp_dtmf_hardware(dsp);
398                 dsp_rx_off(dsp);
399                 break;
400         case DSP_VOL_CHANGE_RX: /* change volume */
401                 if (dsp->hdlc) {
402                         ret = -EINVAL;
403                         break;
404                 }
405                 if (len < sizeof(int)) {
406                         ret = -EINVAL;
407                         break;
408                 }
409                 dsp->rx_volume = *((int *)data);
410                 if (dsp_debug & DEBUG_DSP_CORE)
411                         printk(KERN_DEBUG "%s: change rx vol to %d\n",
412                                 __func__, dsp->tx_volume);
413                 dsp_cmx_hardware(dsp->conf, dsp);
414                 dsp_dtmf_hardware(dsp);
415                 dsp_rx_off(dsp);
416                 break;
417         case DSP_ECHO_ON: /* enable echo */
418                 dsp->echo.software = 1; /* soft echo */
419                 if (dsp_debug & DEBUG_DSP_CORE)
420                         printk(KERN_DEBUG "%s: enable cmx-echo\n", __func__);
421                 dsp_cmx_hardware(dsp->conf, dsp);
422                 dsp_rx_off(dsp);
423                 if (dsp_debug & DEBUG_DSP_CMX)
424                         dsp_cmx_debug(dsp);
425                 break;
426         case DSP_ECHO_OFF: /* disable echo */
427                 dsp->echo.software = 0;
428                 dsp->echo.hardware = 0;
429                 if (dsp_debug & DEBUG_DSP_CORE)
430                         printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
431                 dsp_cmx_hardware(dsp->conf, dsp);
432                 dsp_rx_off(dsp);
433                 if (dsp_debug & DEBUG_DSP_CMX)
434                         dsp_cmx_debug(dsp);
435                 break;
436         case DSP_RECEIVE_ON: /* enable receive to user space */
437                 if (dsp_debug & DEBUG_DSP_CORE)
438                         printk(KERN_DEBUG "%s: enable receive to user "
439                                 "space\n", __func__);
440                 dsp->rx_disabled = 0;
441                 dsp_rx_off(dsp);
442                 break;
443         case DSP_RECEIVE_OFF: /* disable receive to user space */
444                 if (dsp_debug & DEBUG_DSP_CORE)
445                         printk(KERN_DEBUG "%s: disable receive to "
446                                 "user space\n", __func__);
447                 dsp->rx_disabled = 1;
448                 dsp_rx_off(dsp);
449                 break;
450         case DSP_MIX_ON: /* enable mixing of tx data */
451                 if (dsp->hdlc) {
452                         ret = -EINVAL;
453                         break;
454                 }
455                 if (dsp_debug & DEBUG_DSP_CORE)
456                         printk(KERN_DEBUG "%s: enable mixing of "
457                                 "tx-data with conf mebers\n", __func__);
458                 dsp->tx_mix = 1;
459                 dsp_cmx_hardware(dsp->conf, dsp);
460                 dsp_rx_off(dsp);
461                 if (dsp_debug & DEBUG_DSP_CMX)
462                         dsp_cmx_debug(dsp);
463                 break;
464         case DSP_MIX_OFF: /* disable mixing of tx data */
465                 if (dsp->hdlc) {
466                         ret = -EINVAL;
467                         break;
468                 }
469                 if (dsp_debug & DEBUG_DSP_CORE)
470                         printk(KERN_DEBUG "%s: disable mixing of "
471                                 "tx-data with conf mebers\n", __func__);
472                 dsp->tx_mix = 0;
473                 dsp_cmx_hardware(dsp->conf, dsp);
474                 dsp_rx_off(dsp);
475                 if (dsp_debug & DEBUG_DSP_CMX)
476                         dsp_cmx_debug(dsp);
477                 break;
478         case DSP_TXDATA_ON: /* enable txdata */
479                 dsp->tx_data = 1;
480                 if (dsp_debug & DEBUG_DSP_CORE)
481                         printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
482                 dsp_cmx_hardware(dsp->conf, dsp);
483                 dsp_rx_off(dsp);
484                 if (dsp_debug & DEBUG_DSP_CMX)
485                         dsp_cmx_debug(dsp);
486                 break;
487         case DSP_TXDATA_OFF: /* disable txdata */
488                 dsp->tx_data = 0;
489                 if (dsp_debug & DEBUG_DSP_CORE)
490                         printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
491                 dsp_cmx_hardware(dsp->conf, dsp);
492                 dsp_rx_off(dsp);
493                 if (dsp_debug & DEBUG_DSP_CMX)
494                         dsp_cmx_debug(dsp);
495                 break;
496         case DSP_DELAY: /* use delay algorithm instead of dynamic
497                            jitter algorithm */
498                 if (dsp->hdlc) {
499                         ret = -EINVAL;
500                         break;
501                 }
502                 if (len < sizeof(int)) {
503                         ret = -EINVAL;
504                         break;
505                 }
506                 dsp->cmx_delay = (*((int *)data)) << 3;
507                         /* miliseconds to samples */
508                 if (dsp->cmx_delay >= (CMX_BUFF_HALF>>1))
509                         /* clip to half of maximum usable buffer
510                         (half of half buffer) */
511                         dsp->cmx_delay = (CMX_BUFF_HALF>>1) - 1;
512                 if (dsp_debug & DEBUG_DSP_CORE)
513                         printk(KERN_DEBUG "%s: use delay algorithm to "
514                                 "compensate jitter (%d samples)\n",
515                                 __func__, dsp->cmx_delay);
516                 break;
517         case DSP_JITTER: /* use dynamic jitter algorithm instead of
518                     delay algorithm */
519                 if (dsp->hdlc) {
520                         ret = -EINVAL;
521                         break;
522                 }
523                 dsp->cmx_delay = 0;
524                 if (dsp_debug & DEBUG_DSP_CORE)
525                         printk(KERN_DEBUG "%s: use jitter algorithm to "
526                                 "compensate jitter\n", __func__);
527                 break;
528         case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
529                 if (dsp->hdlc) {
530                         ret = -EINVAL;
531                         break;
532                 }
533                 dsp->tx_dejitter = 1;
534                 if (dsp_debug & DEBUG_DSP_CORE)
535                         printk(KERN_DEBUG "%s: use dejitter on TX "
536                                 "buffer\n", __func__);
537                 break;
538         case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
539                 if (dsp->hdlc) {
540                         ret = -EINVAL;
541                         break;
542                 }
543                 dsp->tx_dejitter = 0;
544                 if (dsp_debug & DEBUG_DSP_CORE)
545                         printk(KERN_DEBUG "%s: use TX buffer without "
546                                 "dejittering\n", __func__);
547                 break;
548         case DSP_PIPELINE_CFG:
549                 if (dsp->hdlc) {
550                         ret = -EINVAL;
551                         break;
552                 }
553                 if (len > 0 && ((char *)data)[len - 1]) {
554                         printk(KERN_DEBUG "%s: pipeline config string "
555                                 "is not NULL terminated!\n", __func__);
556                         ret = -EINVAL;
557                 } else {
558                         dsp->pipeline.inuse = 1;
559                         dsp_cmx_hardware(dsp->conf, dsp);
560                         ret = dsp_pipeline_build(&dsp->pipeline,
561                                 len > 0 ? data : NULL);
562                         dsp_cmx_hardware(dsp->conf, dsp);
563                         dsp_rx_off(dsp);
564                 }
565                 break;
566         case DSP_BF_ENABLE_KEY: /* turn blowfish on */
567                 if (dsp->hdlc) {
568                         ret = -EINVAL;
569                         break;
570                 }
571                 if (len < 4 || len > 56) {
572                         ret = -EINVAL;
573                         break;
574                 }
575                 if (dsp_debug & DEBUG_DSP_CORE)
576                         printk(KERN_DEBUG "%s: turn blowfish on (key "
577                                 "not shown)\n", __func__);
578                 ret = dsp_bf_init(dsp, (u8 *)data, len);
579                 /* set new cont */
580                 if (!ret)
581                         cont = DSP_BF_ACCEPT;
582                 else
583                         cont = DSP_BF_REJECT;
584                 /* send indication if it worked to set it */
585                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
586                         sizeof(int), &cont, GFP_ATOMIC);
587                 if (nskb) {
588                         if (dsp->up) {
589                                 if (dsp->up->send(dsp->up, nskb))
590                                         dev_kfree_skb(nskb);
591                         } else
592                                 dev_kfree_skb(nskb);
593                 }
594                 if (!ret) {
595                         dsp_cmx_hardware(dsp->conf, dsp);
596                         dsp_dtmf_hardware(dsp);
597                         dsp_rx_off(dsp);
598                 }
599                 break;
600         case DSP_BF_DISABLE: /* turn blowfish off */
601                 if (dsp->hdlc) {
602                         ret = -EINVAL;
603                         break;
604                 }
605                 if (dsp_debug & DEBUG_DSP_CORE)
606                         printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
607                 dsp_bf_cleanup(dsp);
608                 dsp_cmx_hardware(dsp->conf, dsp);
609                 dsp_dtmf_hardware(dsp);
610                 dsp_rx_off(dsp);
611                 break;
612         default:
613                 if (dsp_debug & DEBUG_DSP_CORE)
614                         printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
615                                 __func__, cont);
616                 ret = -EINVAL;
617         }
618         return ret;
619 }
620
621 static void
622 get_features(struct mISDNchannel *ch)
623 {
624         struct dsp              *dsp = container_of(ch, struct dsp, ch);
625         struct mISDN_ctrl_req   cq;
626
627         if (!ch->peer) {
628                 if (dsp_debug & DEBUG_DSP_CORE)
629                         printk(KERN_DEBUG "%s: no peer, no features\n",
630                                 __func__);
631                 return;
632         }
633         memset(&cq, 0, sizeof(cq));
634         cq.op = MISDN_CTRL_GETOP;
635         if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
636                 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
637                         __func__);
638                 return;
639         }
640         if (cq.op & MISDN_CTRL_RX_OFF)
641                 dsp->features_rx_off = 1;
642         if (cq.op & MISDN_CTRL_FILL_EMPTY)
643                 dsp->features_fill_empty = 1;
644         if (dsp_options & DSP_OPT_NOHARDWARE)
645                 return;
646         if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
647                 cq.op = MISDN_CTRL_HW_FEATURES;
648                 *((u_long *)&cq.p1) = (u_long)&dsp->features;
649                 if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
650                         printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
651                                 __func__);
652                 }
653         } else
654                 if (dsp_debug & DEBUG_DSP_CORE)
655                         printk(KERN_DEBUG "%s: features not supported for %s\n",
656                                 __func__, dsp->name);
657 }
658
659 static int
660 dsp_function(struct mISDNchannel *ch,  struct sk_buff *skb)
661 {
662         struct dsp              *dsp = container_of(ch, struct dsp, ch);
663         struct mISDNhead        *hh;
664         int                     ret = 0;
665         u8                      *digits = NULL;
666         u_long                  flags;
667
668         hh = mISDN_HEAD_P(skb);
669         switch (hh->prim) {
670         /* FROM DOWN */
671         case (PH_DATA_CNF):
672                 dsp->data_pending = 0;
673                 /* trigger next hdlc frame, if any */
674                 if (dsp->hdlc) {
675                         spin_lock_irqsave(&dsp_lock, flags);
676                         if (dsp->b_active)
677                                 schedule_work(&dsp->workq);
678                         spin_unlock_irqrestore(&dsp_lock, flags);
679                 }
680                 break;
681         case (PH_DATA_IND):
682         case (DL_DATA_IND):
683                 if (skb->len < 1) {
684                         ret = -EINVAL;
685                         break;
686                 }
687                 if (dsp->rx_is_off) {
688                         if (dsp_debug & DEBUG_DSP_CORE)
689                                 printk(KERN_DEBUG "%s: rx-data during rx_off"
690                                         " for %s\n",
691                                 __func__, dsp->name);
692                 }
693                 if (dsp->hdlc) {
694                         /* hdlc */
695                         spin_lock_irqsave(&dsp_lock, flags);
696                         dsp_cmx_hdlc(dsp, skb);
697                         spin_unlock_irqrestore(&dsp_lock, flags);
698                         if (dsp->rx_disabled) {
699                                 /* if receive is not allowed */
700                                 break;
701                         }
702                         hh->prim = DL_DATA_IND;
703                         if (dsp->up)
704                                 return dsp->up->send(dsp->up, skb);
705                         break;
706                 }
707
708                 spin_lock_irqsave(&dsp_lock, flags);
709
710                 /* decrypt if enabled */
711                 if (dsp->bf_enable)
712                         dsp_bf_decrypt(dsp, skb->data, skb->len);
713                 /* pipeline */
714                 if (dsp->pipeline.inuse)
715                         dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
716                                 skb->len, hh->id);
717                 /* change volume if requested */
718                 if (dsp->rx_volume)
719                         dsp_change_volume(skb, dsp->rx_volume);
720                 /* check if dtmf soft decoding is turned on */
721                 if (dsp->dtmf.software) {
722                         digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
723                                 skb->len, (dsp_options&DSP_OPT_ULAW) ? 1 : 0);
724                 }
725                 /* we need to process receive data if software */
726                 if (dsp->conf && dsp->conf->software) {
727                         /* process data from card at cmx */
728                         dsp_cmx_receive(dsp, skb);
729                 }
730
731                 spin_unlock_irqrestore(&dsp_lock, flags);
732
733                 /* send dtmf result, if any */
734                 if (digits) {
735                         while (*digits) {
736                                 int k;
737                                 struct sk_buff *nskb;
738                                 if (dsp_debug & DEBUG_DSP_DTMF)
739                                         printk(KERN_DEBUG "%s: digit"
740                                             "(%c) to layer %s\n",
741                                             __func__, *digits, dsp->name);
742                                 k = *digits | DTMF_TONE_VAL;
743                                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
744                                         MISDN_ID_ANY, sizeof(int), &k,
745                                         GFP_ATOMIC);
746                                 if (nskb) {
747                                         if (dsp->up) {
748                                                 if (dsp->up->send(
749                                                     dsp->up, nskb))
750                                                         dev_kfree_skb(nskb);
751                                         } else
752                                                 dev_kfree_skb(nskb);
753                                 }
754                                 digits++;
755                         }
756                 }
757                 if (dsp->rx_disabled) {
758                         /* if receive is not allowed */
759                         break;
760                 }
761                 hh->prim = DL_DATA_IND;
762                 if (dsp->up)
763                         return dsp->up->send(dsp->up, skb);
764                 break;
765         case (PH_CONTROL_IND):
766                 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
767                         printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
768                                 "received: %x (len %d) %s\n", __func__,
769                                 hh->id, skb->len, dsp->name);
770                 switch (hh->id) {
771                 case (DTMF_HFC_COEF): /* getting coefficients */
772                         if (!dsp->dtmf.hardware) {
773                                 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
774                                         printk(KERN_DEBUG "%s: ignoring DTMF "
775                                                 "coefficients from HFC\n",
776                                                 __func__);
777                                 break;
778                         }
779                         digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
780                                 skb->len, 2);
781                         while (*digits) {
782                                 int k;
783                                 struct sk_buff *nskb;
784                                 if (dsp_debug & DEBUG_DSP_DTMF)
785                                         printk(KERN_DEBUG "%s: digit"
786                                             "(%c) to layer %s\n",
787                                             __func__, *digits, dsp->name);
788                                 k = *digits | DTMF_TONE_VAL;
789                                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
790                                         MISDN_ID_ANY, sizeof(int), &k,
791                                         GFP_ATOMIC);
792                                 if (nskb) {
793                                         if (dsp->up) {
794                                                 if (dsp->up->send(
795                                                     dsp->up, nskb))
796                                                         dev_kfree_skb(nskb);
797                                         } else
798                                                 dev_kfree_skb(nskb);
799                                 }
800                                 digits++;
801                         }
802                         break;
803                 case (HFC_VOL_CHANGE_TX): /* change volume */
804                         if (skb->len != sizeof(int)) {
805                                 ret = -EINVAL;
806                                 break;
807                         }
808                         spin_lock_irqsave(&dsp_lock, flags);
809                         dsp->tx_volume = *((int *)skb->data);
810                         if (dsp_debug & DEBUG_DSP_CORE)
811                                 printk(KERN_DEBUG "%s: change tx volume to "
812                                         "%d\n", __func__, dsp->tx_volume);
813                         dsp_cmx_hardware(dsp->conf, dsp);
814                         dsp_dtmf_hardware(dsp);
815                         dsp_rx_off(dsp);
816                         spin_unlock_irqrestore(&dsp_lock, flags);
817                         break;
818                 default:
819                         if (dsp_debug & DEBUG_DSP_CORE)
820                                 printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
821                                         "%s\n", __func__, hh->id, dsp->name);
822                         ret = -EINVAL;
823                 }
824                 break;
825         case (PH_ACTIVATE_IND):
826         case (PH_ACTIVATE_CNF):
827                 if (dsp_debug & DEBUG_DSP_CORE)
828                         printk(KERN_DEBUG "%s: b_channel is now active %s\n",
829                                 __func__, dsp->name);
830                 /* bchannel now active */
831                 spin_lock_irqsave(&dsp_lock, flags);
832                 dsp->b_active = 1;
833                 dsp->data_pending = 0;
834                 dsp->rx_init = 1;
835                         /* rx_W and rx_R will be adjusted on first frame */
836                 dsp->rx_W = 0;
837                 dsp->rx_R = 0;
838                 memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
839                 dsp_cmx_hardware(dsp->conf, dsp);
840                 dsp_dtmf_hardware(dsp);
841                 dsp_rx_off(dsp);
842                 spin_unlock_irqrestore(&dsp_lock, flags);
843                 if (dsp_debug & DEBUG_DSP_CORE)
844                         printk(KERN_DEBUG "%s: done with activation, sending "
845                                 "confirm to user space. %s\n", __func__,
846                                 dsp->name);
847                 /* send activation to upper layer */
848                 hh->prim = DL_ESTABLISH_CNF;
849                 if (dsp->up)
850                         return dsp->up->send(dsp->up, skb);
851                 break;
852         case (PH_DEACTIVATE_IND):
853         case (PH_DEACTIVATE_CNF):
854                 if (dsp_debug & DEBUG_DSP_CORE)
855                         printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
856                                 __func__, dsp->name);
857                 /* bchannel now inactive */
858                 spin_lock_irqsave(&dsp_lock, flags);
859                 dsp->b_active = 0;
860                 dsp->data_pending = 0;
861                 dsp_cmx_hardware(dsp->conf, dsp);
862                 dsp_rx_off(dsp);
863                 spin_unlock_irqrestore(&dsp_lock, flags);
864                 hh->prim = DL_RELEASE_CNF;
865                 if (dsp->up)
866                         return dsp->up->send(dsp->up, skb);
867                 break;
868         /* FROM UP */
869         case (DL_DATA_REQ):
870         case (PH_DATA_REQ):
871                 if (skb->len < 1) {
872                         ret = -EINVAL;
873                         break;
874                 }
875                 if (dsp->hdlc) {
876                         /* hdlc */
877                         if (!dsp->b_active) {
878                                 ret = -EIO;
879                                 break;
880                         }
881                         hh->prim = PH_DATA_REQ;
882                         spin_lock_irqsave(&dsp_lock, flags);
883                         skb_queue_tail(&dsp->sendq, skb);
884                         schedule_work(&dsp->workq);
885                         spin_unlock_irqrestore(&dsp_lock, flags);
886                         return 0;
887                 }
888                 /* send data to tx-buffer (if no tone is played) */
889                 if (!dsp->tone.tone) {
890                         spin_lock_irqsave(&dsp_lock, flags);
891                         dsp_cmx_transmit(dsp, skb);
892                         spin_unlock_irqrestore(&dsp_lock, flags);
893                 }
894                 break;
895         case (PH_CONTROL_REQ):
896                 spin_lock_irqsave(&dsp_lock, flags);
897                 ret = dsp_control_req(dsp, hh, skb);
898                 spin_unlock_irqrestore(&dsp_lock, flags);
899                 break;
900         case (DL_ESTABLISH_REQ):
901         case (PH_ACTIVATE_REQ):
902                 if (dsp_debug & DEBUG_DSP_CORE)
903                         printk(KERN_DEBUG "%s: activating b_channel %s\n",
904                                 __func__, dsp->name);
905                 if (dsp->dtmf.hardware || dsp->dtmf.software)
906                         dsp_dtmf_goertzel_init(dsp);
907                 get_features(ch);
908                 /* enable fill_empty feature */
909                 if (dsp->features_fill_empty)
910                         dsp_fill_empty(dsp);
911                 /* send ph_activate */
912                 hh->prim = PH_ACTIVATE_REQ;
913                 if (ch->peer)
914                         return ch->recv(ch->peer, skb);
915                 break;
916         case (DL_RELEASE_REQ):
917         case (PH_DEACTIVATE_REQ):
918                 if (dsp_debug & DEBUG_DSP_CORE)
919                         printk(KERN_DEBUG "%s: releasing b_channel %s\n",
920                                 __func__, dsp->name);
921                 spin_lock_irqsave(&dsp_lock, flags);
922                 dsp->tone.tone = 0;
923                 dsp->tone.hardware = 0;
924                 dsp->tone.software = 0;
925                 if (timer_pending(&dsp->tone.tl))
926                         del_timer(&dsp->tone.tl);
927                 if (dsp->conf)
928                         dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
929                                                  called here */
930                 skb_queue_purge(&dsp->sendq);
931                 spin_unlock_irqrestore(&dsp_lock, flags);
932                 hh->prim = PH_DEACTIVATE_REQ;
933                 if (ch->peer)
934                         return ch->recv(ch->peer, skb);
935                 break;
936         default:
937                 if (dsp_debug & DEBUG_DSP_CORE)
938                         printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
939                                 __func__, hh->prim, dsp->name);
940                 ret = -EINVAL;
941         }
942         if (!ret)
943                 dev_kfree_skb(skb);
944         return ret;
945 }
946
947 static int
948 dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
949 {
950         struct dsp              *dsp = container_of(ch, struct dsp, ch);
951         u_long          flags;
952         int             err = 0;
953
954         if (debug & DEBUG_DSP_CTRL)
955                 printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
956
957         switch (cmd) {
958         case OPEN_CHANNEL:
959                 break;
960         case CLOSE_CHANNEL:
961                 if (dsp->ch.peer)
962                         dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
963
964                 /* wait until workqueue has finished,
965                  * must lock here, or we may hit send-process currently
966                  * queueing. */
967                 spin_lock_irqsave(&dsp_lock, flags);
968                 dsp->b_active = 0;
969                 spin_unlock_irqrestore(&dsp_lock, flags);
970                 /* MUST not be locked, because it waits until queue is done. */
971                 cancel_work_sync(&dsp->workq);
972                 spin_lock_irqsave(&dsp_lock, flags);
973                 if (timer_pending(&dsp->tone.tl))
974                         del_timer(&dsp->tone.tl);
975                 skb_queue_purge(&dsp->sendq);
976                 if (dsp_debug & DEBUG_DSP_CTRL)
977                         printk(KERN_DEBUG "%s: releasing member %s\n",
978                                 __func__, dsp->name);
979                 dsp->b_active = 0;
980                 dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
981                                          here */
982                 dsp_pipeline_destroy(&dsp->pipeline);
983
984                 if (dsp_debug & DEBUG_DSP_CTRL)
985                         printk(KERN_DEBUG "%s: remove & destroy object %s\n",
986                                 __func__, dsp->name);
987                 list_del(&dsp->list);
988                 spin_unlock_irqrestore(&dsp_lock, flags);
989
990                 if (dsp_debug & DEBUG_DSP_CTRL)
991                         printk(KERN_DEBUG "%s: dsp instance released\n",
992                                 __func__);
993                 vfree(dsp);
994                 module_put(THIS_MODULE);
995                 break;
996         }
997         return err;
998 }
999
1000 static void
1001 dsp_send_bh(struct work_struct *work)
1002 {
1003         struct dsp *dsp = container_of(work, struct dsp, workq);
1004         struct sk_buff *skb;
1005         struct mISDNhead        *hh;
1006
1007         if (dsp->hdlc && dsp->data_pending)
1008                 return; /* wait until data has been acknowledged */
1009
1010         /* send queued data */
1011         while ((skb = skb_dequeue(&dsp->sendq))) {
1012                 /* in locked date, we must have still data in queue */
1013                 if (dsp->data_pending) {
1014                         if (dsp_debug & DEBUG_DSP_CORE)
1015                                 printk(KERN_DEBUG "%s: fifo full %s, this is "
1016                                         "no bug!\n", __func__, dsp->name);
1017                         /* flush transparent data, if not acked */
1018                         dev_kfree_skb(skb);
1019                         continue;
1020                 }
1021                 hh = mISDN_HEAD_P(skb);
1022                 if (hh->prim == DL_DATA_REQ) {
1023                         /* send packet up */
1024                         if (dsp->up) {
1025                                 if (dsp->up->send(dsp->up, skb))
1026                                         dev_kfree_skb(skb);
1027                         } else
1028                                 dev_kfree_skb(skb);
1029                 } else {
1030                         /* send packet down */
1031                         if (dsp->ch.peer) {
1032                                 dsp->data_pending = 1;
1033                                 if (dsp->ch.recv(dsp->ch.peer, skb)) {
1034                                         dev_kfree_skb(skb);
1035                                         dsp->data_pending = 0;
1036                                 }
1037                         } else
1038                                 dev_kfree_skb(skb);
1039                 }
1040         }
1041 }
1042
1043 static int
1044 dspcreate(struct channel_req *crq)
1045 {
1046         struct dsp              *ndsp;
1047         u_long          flags;
1048
1049         if (crq->protocol != ISDN_P_B_L2DSP
1050          && crq->protocol != ISDN_P_B_L2DSPHDLC)
1051                 return -EPROTONOSUPPORT;
1052         ndsp = vmalloc(sizeof(struct dsp));
1053         if (!ndsp) {
1054                 printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
1055                 return -ENOMEM;
1056         }
1057         memset(ndsp, 0, sizeof(struct dsp));
1058         if (dsp_debug & DEBUG_DSP_CTRL)
1059                 printk(KERN_DEBUG "%s: creating new dsp instance\n", __func__);
1060
1061         /* default enabled */
1062         INIT_WORK(&ndsp->workq, (void *)dsp_send_bh);
1063         skb_queue_head_init(&ndsp->sendq);
1064         ndsp->ch.send = dsp_function;
1065         ndsp->ch.ctrl = dsp_ctrl;
1066         ndsp->up = crq->ch;
1067         crq->ch = &ndsp->ch;
1068         if (crq->protocol == ISDN_P_B_L2DSP) {
1069                 crq->protocol = ISDN_P_B_RAW;
1070                 ndsp->hdlc = 0;
1071         } else {
1072                 crq->protocol = ISDN_P_B_HDLC;
1073                 ndsp->hdlc = 1;
1074         }
1075         if (!try_module_get(THIS_MODULE))
1076                 printk(KERN_WARNING "%s:cannot get module\n",
1077                         __func__);
1078
1079         sprintf(ndsp->name, "DSP_C%x(0x%p)",
1080                 ndsp->up->st->dev->id + 1, ndsp);
1081         /* set frame size to start */
1082         ndsp->features.hfc_id = -1; /* current PCM id */
1083         ndsp->features.pcm_id = -1; /* current PCM id */
1084         ndsp->pcm_slot_rx = -1; /* current CPM slot */
1085         ndsp->pcm_slot_tx = -1;
1086         ndsp->pcm_bank_rx = -1;
1087         ndsp->pcm_bank_tx = -1;
1088         ndsp->hfc_conf = -1; /* current conference number */
1089         /* set tone timer */
1090         ndsp->tone.tl.function = (void *)dsp_tone_timeout;
1091         ndsp->tone.tl.data = (long) ndsp;
1092         init_timer(&ndsp->tone.tl);
1093
1094         if (dtmfthreshold < 20 || dtmfthreshold > 500)
1095                 dtmfthreshold = 200;
1096         ndsp->dtmf.treshold = dtmfthreshold*10000;
1097
1098         /* init pipeline append to list */
1099         spin_lock_irqsave(&dsp_lock, flags);
1100         dsp_pipeline_init(&ndsp->pipeline);
1101         list_add_tail(&ndsp->list, &dsp_ilist);
1102         spin_unlock_irqrestore(&dsp_lock, flags);
1103
1104         return 0;
1105 }
1106
1107
1108 static struct Bprotocol DSP = {
1109         .Bprotocols = (1 << (ISDN_P_B_L2DSP & ISDN_P_B_MASK))
1110                 | (1 << (ISDN_P_B_L2DSPHDLC & ISDN_P_B_MASK)),
1111         .name = "dsp",
1112         .create = dspcreate
1113 };
1114
1115 static int dsp_init(void)
1116 {
1117         int err;
1118         int tics;
1119
1120         printk(KERN_INFO "DSP modul %s\n", mISDN_dsp_revision);
1121
1122         dsp_options = options;
1123         dsp_debug = debug;
1124
1125         /* set packet size */
1126         dsp_poll = poll;
1127         if (dsp_poll) {
1128                 if (dsp_poll > MAX_POLL) {
1129                         printk(KERN_ERR "%s: Wrong poll value (%d), use %d "
1130                                 "maximum.\n", __func__, poll, MAX_POLL);
1131                         err = -EINVAL;
1132                         return err;
1133                 }
1134                 if (dsp_poll < 8) {
1135                         printk(KERN_ERR "%s: Wrong poll value (%d), use 8 "
1136                                 "minimum.\n", __func__, dsp_poll);
1137                         err = -EINVAL;
1138                         return err;
1139                 }
1140                 dsp_tics = poll * HZ / 8000;
1141                 if (dsp_tics * 8000 != poll * HZ) {
1142                         printk(KERN_INFO "mISDN_dsp: Cannot clock every %d "
1143                                 "samples (0,125 ms). It is not a multiple of "
1144                                 "%d HZ.\n", poll, HZ);
1145                         err = -EINVAL;
1146                         return err;
1147                 }
1148         } else {
1149                 poll = 8;
1150                 while (poll <= MAX_POLL) {
1151                         tics = (poll * HZ) / 8000;
1152                         if (tics * 8000 == poll * HZ) {
1153                                 dsp_tics = tics;
1154                                 dsp_poll = poll;
1155                                 if (poll >= 64)
1156                                         break;
1157                         }
1158                         poll++;
1159                 }
1160         }
1161         if (dsp_poll == 0) {
1162                 printk(KERN_INFO "mISDN_dsp: There is no multiple of kernel "
1163                         "clock that equals exactly the duration of 8-256 "
1164                         "samples. (Choose kernel clock speed like 100, 250, "
1165                         "300, 1000)\n");
1166                 err = -EINVAL;
1167                 return err;
1168         }
1169         printk(KERN_INFO "mISDN_dsp: DSP clocks every %d samples. This equals "
1170                 "%d jiffies.\n", dsp_poll, dsp_tics);
1171
1172         spin_lock_init(&dsp_lock);
1173         INIT_LIST_HEAD(&dsp_ilist);
1174         INIT_LIST_HEAD(&conf_ilist);
1175
1176         /* init conversion tables */
1177         dsp_audio_generate_law_tables();
1178         dsp_silence = (dsp_options&DSP_OPT_ULAW) ? 0xff : 0x2a;
1179         dsp_audio_law_to_s32 = (dsp_options&DSP_OPT_ULAW) ?
1180                 dsp_audio_ulaw_to_s32 : dsp_audio_alaw_to_s32;
1181         dsp_audio_generate_s2law_table();
1182         dsp_audio_generate_seven();
1183         dsp_audio_generate_mix_table();
1184         if (dsp_options & DSP_OPT_ULAW)
1185                 dsp_audio_generate_ulaw_samples();
1186         dsp_audio_generate_volume_changes();
1187
1188         err = dsp_pipeline_module_init();
1189         if (err) {
1190                 printk(KERN_ERR "mISDN_dsp: Can't initialize pipeline, "
1191                         "error(%d)\n", err);
1192                 return err;
1193         }
1194
1195         err = mISDN_register_Bprotocol(&DSP);
1196         if (err) {
1197                 printk(KERN_ERR "Can't register %s error(%d)\n", DSP.name, err);
1198                 return err;
1199         }
1200
1201         /* set sample timer */
1202         dsp_spl_tl.function = (void *)dsp_cmx_send;
1203         dsp_spl_tl.data = 0;
1204         init_timer(&dsp_spl_tl);
1205         dsp_spl_tl.expires = jiffies + dsp_tics;
1206         dsp_spl_jiffies = dsp_spl_tl.expires;
1207         add_timer(&dsp_spl_tl);
1208
1209         return 0;
1210 }
1211
1212
1213 static void dsp_cleanup(void)
1214 {
1215         mISDN_unregister_Bprotocol(&DSP);
1216
1217         if (timer_pending(&dsp_spl_tl))
1218                 del_timer(&dsp_spl_tl);
1219
1220         if (!list_empty(&dsp_ilist)) {
1221                 printk(KERN_ERR "mISDN_dsp: Audio DSP object inst list not "
1222                         "empty.\n");
1223         }
1224         if (!list_empty(&conf_ilist)) {
1225                 printk(KERN_ERR "mISDN_dsp: Conference list not empty. Not "
1226                         "all memory freed.\n");
1227         }
1228
1229         dsp_pipeline_module_exit();
1230 }
1231
1232 module_init(dsp_init);
1233 module_exit(dsp_cleanup);
1234