mISDN: Fix DTMF locking bug issue
[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 && dsp->pcm_slot_tx < 0)
207                 rx_off = 0;
208         /* bridge in software */
209         else if (dsp->conf) {
210                 if (dsp->conf->software)
211                         rx_off = 0;
212         }
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 = 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 = 0;
428                 if (dsp_debug & DEBUG_DSP_CORE)
429                         printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
430                 dsp_cmx_hardware(dsp->conf, dsp);
431                 dsp_rx_off(dsp);
432                 if (dsp_debug & DEBUG_DSP_CMX)
433                         dsp_cmx_debug(dsp);
434                 break;
435         case DSP_RECEIVE_ON: /* enable receive to user space */
436                 if (dsp_debug & DEBUG_DSP_CORE)
437                         printk(KERN_DEBUG "%s: enable receive to user "
438                                 "space\n", __func__);
439                 dsp->rx_disabled = 0;
440                 dsp_rx_off(dsp);
441                 break;
442         case DSP_RECEIVE_OFF: /* disable receive to user space */
443                 if (dsp_debug & DEBUG_DSP_CORE)
444                         printk(KERN_DEBUG "%s: disable receive to "
445                                 "user space\n", __func__);
446                 dsp->rx_disabled = 1;
447                 dsp_rx_off(dsp);
448                 break;
449         case DSP_MIX_ON: /* enable mixing of tx data */
450                 if (dsp->hdlc) {
451                         ret = -EINVAL;
452                         break;
453                 }
454                 if (dsp_debug & DEBUG_DSP_CORE)
455                         printk(KERN_DEBUG "%s: enable mixing of "
456                                 "tx-data with conf mebers\n", __func__);
457                 dsp->tx_mix = 1;
458                 dsp_cmx_hardware(dsp->conf, dsp);
459                 dsp_rx_off(dsp);
460                 if (dsp_debug & DEBUG_DSP_CMX)
461                         dsp_cmx_debug(dsp);
462                 break;
463         case DSP_MIX_OFF: /* disable mixing of tx data */
464                 if (dsp->hdlc) {
465                         ret = -EINVAL;
466                         break;
467                 }
468                 if (dsp_debug & DEBUG_DSP_CORE)
469                         printk(KERN_DEBUG "%s: disable mixing of "
470                                 "tx-data with conf mebers\n", __func__);
471                 dsp->tx_mix = 0;
472                 dsp_cmx_hardware(dsp->conf, dsp);
473                 dsp_rx_off(dsp);
474                 if (dsp_debug & DEBUG_DSP_CMX)
475                         dsp_cmx_debug(dsp);
476                 break;
477         case DSP_TXDATA_ON: /* enable txdata */
478                 dsp->tx_data = 1;
479                 if (dsp_debug & DEBUG_DSP_CORE)
480                         printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
481                 dsp_cmx_hardware(dsp->conf, dsp);
482                 dsp_rx_off(dsp);
483                 if (dsp_debug & DEBUG_DSP_CMX)
484                         dsp_cmx_debug(dsp);
485                 break;
486         case DSP_TXDATA_OFF: /* disable txdata */
487                 dsp->tx_data = 0;
488                 if (dsp_debug & DEBUG_DSP_CORE)
489                         printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
490                 dsp_cmx_hardware(dsp->conf, dsp);
491                 dsp_rx_off(dsp);
492                 if (dsp_debug & DEBUG_DSP_CMX)
493                         dsp_cmx_debug(dsp);
494                 break;
495         case DSP_DELAY: /* use delay algorithm instead of dynamic
496                            jitter algorithm */
497                 if (dsp->hdlc) {
498                         ret = -EINVAL;
499                         break;
500                 }
501                 if (len < sizeof(int)) {
502                         ret = -EINVAL;
503                         break;
504                 }
505                 dsp->cmx_delay = (*((int *)data)) << 3;
506                         /* miliseconds to samples */
507                 if (dsp->cmx_delay >= (CMX_BUFF_HALF>>1))
508                         /* clip to half of maximum usable buffer
509                         (half of half buffer) */
510                         dsp->cmx_delay = (CMX_BUFF_HALF>>1) - 1;
511                 if (dsp_debug & DEBUG_DSP_CORE)
512                         printk(KERN_DEBUG "%s: use delay algorithm to "
513                                 "compensate jitter (%d samples)\n",
514                                 __func__, dsp->cmx_delay);
515                 break;
516         case DSP_JITTER: /* use dynamic jitter algorithm instead of
517                     delay algorithm */
518                 if (dsp->hdlc) {
519                         ret = -EINVAL;
520                         break;
521                 }
522                 dsp->cmx_delay = 0;
523                 if (dsp_debug & DEBUG_DSP_CORE)
524                         printk(KERN_DEBUG "%s: use jitter algorithm to "
525                                 "compensate jitter\n", __func__);
526                 break;
527         case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
528                 if (dsp->hdlc) {
529                         ret = -EINVAL;
530                         break;
531                 }
532                 dsp->tx_dejitter = 1;
533                 if (dsp_debug & DEBUG_DSP_CORE)
534                         printk(KERN_DEBUG "%s: use dejitter on TX "
535                                 "buffer\n", __func__);
536                 break;
537         case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
538                 if (dsp->hdlc) {
539                         ret = -EINVAL;
540                         break;
541                 }
542                 dsp->tx_dejitter = 0;
543                 if (dsp_debug & DEBUG_DSP_CORE)
544                         printk(KERN_DEBUG "%s: use TX buffer without "
545                                 "dejittering\n", __func__);
546                 break;
547         case DSP_PIPELINE_CFG:
548                 if (dsp->hdlc) {
549                         ret = -EINVAL;
550                         break;
551                 }
552                 if (len > 0 && ((char *)data)[len - 1]) {
553                         printk(KERN_DEBUG "%s: pipeline config string "
554                                 "is not NULL terminated!\n", __func__);
555                         ret = -EINVAL;
556                 } else {
557                         dsp->pipeline.inuse = 1;
558                         dsp_cmx_hardware(dsp->conf, dsp);
559                         ret = dsp_pipeline_build(&dsp->pipeline,
560                                 len > 0 ? (char *)data : NULL);
561                         dsp_cmx_hardware(dsp->conf, dsp);
562                         dsp_rx_off(dsp);
563                 }
564                 break;
565         case DSP_BF_ENABLE_KEY: /* turn blowfish on */
566                 if (dsp->hdlc) {
567                         ret = -EINVAL;
568                         break;
569                 }
570                 if (len < 4 || len > 56) {
571                         ret = -EINVAL;
572                         break;
573                 }
574                 if (dsp_debug & DEBUG_DSP_CORE)
575                         printk(KERN_DEBUG "%s: turn blowfish on (key "
576                                 "not shown)\n", __func__);
577                 ret = dsp_bf_init(dsp, (u8 *)data, len);
578                 /* set new cont */
579                 if (!ret)
580                         cont = DSP_BF_ACCEPT;
581                 else
582                         cont = DSP_BF_REJECT;
583                 /* send indication if it worked to set it */
584                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
585                         sizeof(int), &cont, GFP_ATOMIC);
586                 if (nskb) {
587                         if (dsp->up) {
588                                 if (dsp->up->send(dsp->up, nskb))
589                                         dev_kfree_skb(nskb);
590                         } else
591                                 dev_kfree_skb(nskb);
592                 }
593                 if (!ret) {
594                         dsp_cmx_hardware(dsp->conf, dsp);
595                         dsp_dtmf_hardware(dsp);
596                         dsp_rx_off(dsp);
597                 }
598                 break;
599         case DSP_BF_DISABLE: /* turn blowfish off */
600                 if (dsp->hdlc) {
601                         ret = -EINVAL;
602                         break;
603                 }
604                 if (dsp_debug & DEBUG_DSP_CORE)
605                         printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
606                 dsp_bf_cleanup(dsp);
607                 dsp_cmx_hardware(dsp->conf, dsp);
608                 dsp_dtmf_hardware(dsp);
609                 dsp_rx_off(dsp);
610                 break;
611         default:
612                 if (dsp_debug & DEBUG_DSP_CORE)
613                         printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
614                                 __func__, cont);
615                 ret = -EINVAL;
616         }
617         return ret;
618 }
619
620 static void
621 get_features(struct mISDNchannel *ch)
622 {
623         struct dsp              *dsp = container_of(ch, struct dsp, ch);
624         struct mISDN_ctrl_req   cq;
625
626         if (!ch->peer) {
627                 if (dsp_debug & DEBUG_DSP_CORE)
628                         printk(KERN_DEBUG "%s: no peer, no features\n",
629                                 __func__);
630                 return;
631         }
632         memset(&cq, 0, sizeof(cq));
633         cq.op = MISDN_CTRL_GETOP;
634         if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
635                 printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
636                         __func__);
637                 return;
638         }
639         if (cq.op & MISDN_CTRL_RX_OFF)
640                 dsp->features_rx_off = 1;
641         if (cq.op & MISDN_CTRL_FILL_EMPTY)
642                 dsp->features_fill_empty = 1;
643         if (dsp_options & DSP_OPT_NOHARDWARE)
644                 return;
645         if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
646                 cq.op = MISDN_CTRL_HW_FEATURES;
647                 *((u_long *)&cq.p1) = (u_long)&dsp->features;
648                 if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
649                         printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
650                                 __func__);
651                 }
652         } else
653                 if (dsp_debug & DEBUG_DSP_CORE)
654                         printk(KERN_DEBUG "%s: features not supported for %s\n",
655                                 __func__, dsp->name);
656 }
657
658 static int
659 dsp_function(struct mISDNchannel *ch,  struct sk_buff *skb)
660 {
661         struct dsp              *dsp = container_of(ch, struct dsp, ch);
662         struct mISDNhead        *hh;
663         int                     ret = 0;
664         u8                      *digits = NULL;
665         u_long                  flags;
666
667         hh = mISDN_HEAD_P(skb);
668         switch (hh->prim) {
669         /* FROM DOWN */
670         case (PH_DATA_CNF):
671                 dsp->data_pending = 0;
672                 /* trigger next hdlc frame, if any */
673                 if (dsp->hdlc) {
674                         spin_lock_irqsave(&dsp_lock, flags);
675                         if (dsp->b_active)
676                                 schedule_work(&dsp->workq);
677                         spin_unlock_irqrestore(&dsp_lock, flags);
678                 }
679                 break;
680         case (PH_DATA_IND):
681         case (DL_DATA_IND):
682                 if (skb->len < 1) {
683                         ret = -EINVAL;
684                         break;
685                 }
686                 if (dsp->rx_is_off) {
687                         if (dsp_debug & DEBUG_DSP_CORE)
688                                 printk(KERN_DEBUG "%s: rx-data during rx_off"
689                                         " for %s\n",
690                                 __func__, dsp->name);
691                 }
692                 if (dsp->hdlc) {
693                         /* hdlc */
694                         spin_lock_irqsave(&dsp_lock, flags);
695                         dsp_cmx_hdlc(dsp, skb);
696                         spin_unlock_irqrestore(&dsp_lock, flags);
697                         if (dsp->rx_disabled) {
698                                 /* if receive is not allowed */
699                                 break;
700                         }
701                         hh->prim = DL_DATA_IND;
702                         if (dsp->up)
703                                 return dsp->up->send(dsp->up, skb);
704                         break;
705                 }
706
707                 spin_lock_irqsave(&dsp_lock, flags);
708
709                 /* decrypt if enabled */
710                 if (dsp->bf_enable)
711                         dsp_bf_decrypt(dsp, skb->data, skb->len);
712                 /* pipeline */
713                 if (dsp->pipeline.inuse)
714                         dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
715                                 skb->len, hh->id);
716                 /* change volume if requested */
717                 if (dsp->rx_volume)
718                         dsp_change_volume(skb, dsp->rx_volume);
719                 /* check if dtmf soft decoding is turned on */
720                 if (dsp->dtmf.software) {
721                         digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
722                                 skb->len, (dsp_options&DSP_OPT_ULAW)?1:0);
723                 }
724                 /* we need to process receive data if software */
725                 if (dsp->pcm_slot_tx < 0 && dsp->pcm_slot_rx < 0) {
726                         /* process data from card at cmx */
727                         dsp_cmx_receive(dsp, skb);
728                 }
729
730                 spin_unlock_irqrestore(&dsp_lock, flags);
731
732                 /* send dtmf result, if any */
733                 if (digits) {
734                         while (*digits) {
735                                 int k;
736                                 struct sk_buff *nskb;
737                                 if (dsp_debug & DEBUG_DSP_DTMF)
738                                         printk(KERN_DEBUG "%s: digit"
739                                             "(%c) to layer %s\n",
740                                             __func__, *digits, dsp->name);
741                                 k = *digits | DTMF_TONE_VAL;
742                                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
743                                         MISDN_ID_ANY, sizeof(int), &k,
744                                         GFP_ATOMIC);
745                                 if (nskb) {
746                                         if (dsp->up) {
747                                                 if (dsp->up->send(
748                                                     dsp->up, nskb))
749                                                         dev_kfree_skb(nskb);
750                                         } else
751                                                 dev_kfree_skb(nskb);
752                                 }
753                                 digits++;
754                         }
755                 }
756                 if (dsp->rx_disabled) {
757                         /* if receive is not allowed */
758                         break;
759                 }
760                 hh->prim = DL_DATA_IND;
761                 if (dsp->up)
762                         return dsp->up->send(dsp->up, skb);
763                 break;
764         case (PH_CONTROL_IND):
765                 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
766                         printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
767                                 "received: %x (len %d) %s\n", __func__,
768                                 hh->id, skb->len, dsp->name);
769                 switch (hh->id) {
770                 case (DTMF_HFC_COEF): /* getting coefficients */
771                         if (!dsp->dtmf.hardware) {
772                                 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
773                                         printk(KERN_DEBUG "%s: ignoring DTMF "
774                                                 "coefficients from HFC\n",
775                                                 __func__);
776                                 break;
777                         }
778                         digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
779                                 skb->len, 2);
780                         while (*digits) {
781                                 int k;
782                                 struct sk_buff *nskb;
783                                 if (dsp_debug & DEBUG_DSP_DTMF)
784                                         printk(KERN_DEBUG "%s: digit"
785                                             "(%c) to layer %s\n",
786                                             __func__, *digits, dsp->name);
787                                 k = *digits | DTMF_TONE_VAL;
788                                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
789                                         MISDN_ID_ANY, sizeof(int), &k,
790                                         GFP_ATOMIC);
791                                 if (nskb) {
792                                         if (dsp->up) {
793                                                 if (dsp->up->send(
794                                                     dsp->up, nskb))
795                                                         dev_kfree_skb(nskb);
796                                         } else
797                                                 dev_kfree_skb(nskb);
798                                 }
799                                 digits++;
800                         }
801                         break;
802                 case (HFC_VOL_CHANGE_TX): /* change volume */
803                         if (skb->len != sizeof(int)) {
804                                 ret = -EINVAL;
805                                 break;
806                         }
807                         spin_lock_irqsave(&dsp_lock, flags);
808                         dsp->tx_volume = *((int *)skb->data);
809                         if (dsp_debug & DEBUG_DSP_CORE)
810                                 printk(KERN_DEBUG "%s: change tx volume to "
811                                         "%d\n", __func__, dsp->tx_volume);
812                         dsp_cmx_hardware(dsp->conf, dsp);
813                         dsp_dtmf_hardware(dsp);
814                         dsp_rx_off(dsp);
815                         spin_unlock_irqrestore(&dsp_lock, flags);
816                         break;
817                 default:
818                         if (dsp_debug & DEBUG_DSP_CORE)
819                                 printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
820                                         "%s\n", __func__, hh->id, dsp->name);
821                         ret = -EINVAL;
822                 }
823                 break;
824         case (PH_ACTIVATE_IND):
825         case (PH_ACTIVATE_CNF):
826                 if (dsp_debug & DEBUG_DSP_CORE)
827                         printk(KERN_DEBUG "%s: b_channel is now active %s\n",
828                                 __func__, dsp->name);
829                 /* bchannel now active */
830                 spin_lock_irqsave(&dsp_lock, flags);
831                 dsp->b_active = 1;
832                 dsp->data_pending = 0;
833                 dsp->rx_init = 1;
834                         /* rx_W and rx_R will be adjusted on first frame */
835                 dsp->rx_W = 0;
836                 dsp->rx_R = 0;
837                 memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
838                 dsp_cmx_hardware(dsp->conf, dsp);
839                 dsp_dtmf_hardware(dsp);
840                 dsp_rx_off(dsp);
841                 spin_unlock_irqrestore(&dsp_lock, flags);
842                 if (dsp_debug & DEBUG_DSP_CORE)
843                         printk(KERN_DEBUG "%s: done with activation, sending "
844                                 "confirm to user space. %s\n", __func__,
845                                 dsp->name);
846                 /* send activation to upper layer */
847                 hh->prim = DL_ESTABLISH_CNF;
848                 if (dsp->up)
849                         return dsp->up->send(dsp->up, skb);
850                 break;
851         case (PH_DEACTIVATE_IND):
852         case (PH_DEACTIVATE_CNF):
853                 if (dsp_debug & DEBUG_DSP_CORE)
854                         printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
855                                 __func__, dsp->name);
856                 /* bchannel now inactive */
857                 spin_lock_irqsave(&dsp_lock, flags);
858                 dsp->b_active = 0;
859                 dsp->data_pending = 0;
860                 dsp_cmx_hardware(dsp->conf, dsp);
861                 dsp_rx_off(dsp);
862                 spin_unlock_irqrestore(&dsp_lock, flags);
863                 hh->prim = DL_RELEASE_CNF;
864                 if (dsp->up)
865                         return dsp->up->send(dsp->up, skb);
866                 break;
867         /* FROM UP */
868         case (DL_DATA_REQ):
869         case (PH_DATA_REQ):
870                 if (skb->len < 1) {
871                         ret = -EINVAL;
872                         break;
873                 }
874                 if (dsp->hdlc) {
875                         /* hdlc */
876                         if (!dsp->b_active) {
877                                 ret = -EIO;
878                                 break;
879                         }
880                         hh->prim = PH_DATA_REQ;
881                         spin_lock_irqsave(&dsp_lock, flags);
882                         skb_queue_tail(&dsp->sendq, skb);
883                         schedule_work(&dsp->workq);
884                         spin_unlock_irqrestore(&dsp_lock, flags);
885                         return 0;
886                 }
887                 /* send data to tx-buffer (if no tone is played) */
888                 if (!dsp->tone.tone) {
889                         spin_lock_irqsave(&dsp_lock, flags);
890                         dsp_cmx_transmit(dsp, skb);
891                         spin_unlock_irqrestore(&dsp_lock, flags);
892                 }
893                 break;
894         case (PH_CONTROL_REQ):
895                 spin_lock_irqsave(&dsp_lock, flags);
896                 ret = dsp_control_req(dsp, hh, skb);
897                 spin_unlock_irqrestore(&dsp_lock, flags);
898                 break;
899         case (DL_ESTABLISH_REQ):
900         case (PH_ACTIVATE_REQ):
901                 if (dsp_debug & DEBUG_DSP_CORE)
902                         printk(KERN_DEBUG "%s: activating b_channel %s\n",
903                                 __func__, dsp->name);
904                 if (dsp->dtmf.hardware || dsp->dtmf.software)
905                         dsp_dtmf_goertzel_init(dsp);
906                 get_features(ch);
907                 /* enable fill_empty feature */
908                 if (dsp->features_fill_empty)
909                         dsp_fill_empty(dsp);
910                 /* send ph_activate */
911                 hh->prim = PH_ACTIVATE_REQ;
912                 if (ch->peer)
913                         return ch->recv(ch->peer, skb);
914                 break;
915         case (DL_RELEASE_REQ):
916         case (PH_DEACTIVATE_REQ):
917                 if (dsp_debug & DEBUG_DSP_CORE)
918                         printk(KERN_DEBUG "%s: releasing b_channel %s\n",
919                                 __func__, dsp->name);
920                 spin_lock_irqsave(&dsp_lock, flags);
921                 dsp->tone.tone = 0;
922                 dsp->tone.hardware = 0;
923                 dsp->tone.software = 0;
924                 if (timer_pending(&dsp->tone.tl))
925                         del_timer(&dsp->tone.tl);
926                 if (dsp->conf)
927                         dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
928                                                  called here */
929                 skb_queue_purge(&dsp->sendq);
930                 spin_unlock_irqrestore(&dsp_lock, flags);
931                 hh->prim = PH_DEACTIVATE_REQ;
932                 if (ch->peer)
933                         return ch->recv(ch->peer, skb);
934                 break;
935         default:
936                 if (dsp_debug & DEBUG_DSP_CORE)
937                         printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
938                                 __func__, hh->prim, dsp->name);
939                 ret = -EINVAL;
940         }
941         if (!ret)
942                 dev_kfree_skb(skb);
943         return ret;
944 }
945
946 static int
947 dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
948 {
949         struct dsp              *dsp = container_of(ch, struct dsp, ch);
950         u_long          flags;
951         int             err = 0;
952
953         if (debug & DEBUG_DSP_CTRL)
954         printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
955
956         switch (cmd) {
957         case OPEN_CHANNEL:
958                 break;
959         case CLOSE_CHANNEL:
960                 if (dsp->ch.peer)
961                         dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
962
963                 /* wait until workqueue has finished,
964                  * must lock here, or we may hit send-process currently
965                  * queueing. */
966                 spin_lock_irqsave(&dsp_lock, flags);
967                 dsp->b_active = 0;
968                 spin_unlock_irqrestore(&dsp_lock, flags);
969                 /* MUST not be locked, because it waits until queue is done. */
970                 cancel_work_sync(&dsp->workq);
971                 spin_lock_irqsave(&dsp_lock, flags);
972                 if (timer_pending(&dsp->tone.tl))
973                         del_timer(&dsp->tone.tl);
974                 skb_queue_purge(&dsp->sendq);
975                 if (dsp_debug & DEBUG_DSP_CTRL)
976                         printk(KERN_DEBUG "%s: releasing member %s\n",
977                                 __func__, dsp->name);
978                 dsp->b_active = 0;
979                 dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
980                                          here */
981                 dsp_pipeline_destroy(&dsp->pipeline);
982
983                 if (dsp_debug & DEBUG_DSP_CTRL)
984                         printk(KERN_DEBUG "%s: remove & destroy object %s\n",
985                                 __func__, dsp->name);
986                 list_del(&dsp->list);
987                 spin_unlock_irqrestore(&dsp_lock, flags);
988
989                 if (dsp_debug & DEBUG_DSP_CTRL)
990                         printk(KERN_DEBUG "%s: dsp instance released\n",
991                                 __func__);
992                 vfree(dsp);
993                 module_put(THIS_MODULE);
994                 break;
995         }
996         return err;
997 }
998
999 static void
1000 dsp_send_bh(struct work_struct *work)
1001 {
1002         struct dsp *dsp = container_of(work, struct dsp, workq);
1003         struct sk_buff *skb;
1004         struct mISDNhead        *hh;
1005
1006         if (dsp->hdlc && dsp->data_pending)
1007                 return; /* wait until data has been acknowledged */
1008
1009         /* send queued data */
1010         while ((skb = skb_dequeue(&dsp->sendq))) {
1011                 /* in locked date, we must have still data in queue */
1012                 if (dsp->data_pending) {
1013                         if (dsp_debug & DEBUG_DSP_CORE)
1014                                 printk(KERN_DEBUG "%s: fifo full %s, this is "
1015                                         "no bug!\n", __func__, dsp->name);
1016                         /* flush transparent data, if not acked */
1017                         dev_kfree_skb(skb);
1018                         continue;
1019                 }
1020                 hh = mISDN_HEAD_P(skb);
1021                 if (hh->prim == DL_DATA_REQ) {
1022                         /* send packet up */
1023                         if (dsp->up) {
1024                                 if (dsp->up->send(dsp->up, skb))
1025                                         dev_kfree_skb(skb);
1026                         } else
1027                                 dev_kfree_skb(skb);
1028                 } else {
1029                         /* send packet down */
1030                         if (dsp->ch.peer) {
1031                                 dsp->data_pending = 1;
1032                                 if (dsp->ch.recv(dsp->ch.peer, skb)) {
1033                                         dev_kfree_skb(skb);
1034                                         dsp->data_pending = 0;
1035                                 }
1036                         } else
1037                                 dev_kfree_skb(skb);
1038                 }
1039         }
1040 }
1041
1042 static int
1043 dspcreate(struct channel_req *crq)
1044 {
1045         struct dsp              *ndsp;
1046         u_long          flags;
1047
1048         if (crq->protocol != ISDN_P_B_L2DSP
1049          && crq->protocol != ISDN_P_B_L2DSPHDLC)
1050                 return -EPROTONOSUPPORT;
1051         ndsp = vmalloc(sizeof(struct dsp));
1052         if (!ndsp) {
1053                 printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
1054                 return -ENOMEM;
1055         }
1056         memset(ndsp, 0, sizeof(struct dsp));
1057         if (dsp_debug & DEBUG_DSP_CTRL)
1058                 printk(KERN_DEBUG "%s: creating new dsp instance\n", __func__);
1059
1060         /* default enabled */
1061         INIT_WORK(&ndsp->workq, (void *)dsp_send_bh);
1062         skb_queue_head_init(&ndsp->sendq);
1063         ndsp->ch.send = dsp_function;
1064         ndsp->ch.ctrl = dsp_ctrl;
1065         ndsp->up = crq->ch;
1066         crq->ch = &ndsp->ch;
1067         if (crq->protocol == ISDN_P_B_L2DSP) {
1068                 crq->protocol = ISDN_P_B_RAW;
1069                 ndsp->hdlc = 0;
1070         } else {
1071                 crq->protocol = ISDN_P_B_HDLC;
1072                 ndsp->hdlc = 1;
1073         }
1074         if (!try_module_get(THIS_MODULE))
1075                 printk(KERN_WARNING "%s:cannot get module\n",
1076                         __func__);
1077
1078         sprintf(ndsp->name, "DSP_C%x(0x%p)",
1079                 ndsp->up->st->dev->id + 1, ndsp);
1080         /* set frame size to start */
1081         ndsp->features.hfc_id = -1; /* current PCM id */
1082         ndsp->features.pcm_id = -1; /* current PCM id */
1083         ndsp->pcm_slot_rx = -1; /* current CPM slot */
1084         ndsp->pcm_slot_tx = -1;
1085         ndsp->pcm_bank_rx = -1;
1086         ndsp->pcm_bank_tx = -1;
1087         ndsp->hfc_conf = -1; /* current conference number */
1088         /* set tone timer */
1089         ndsp->tone.tl.function = (void *)dsp_tone_timeout;
1090         ndsp->tone.tl.data = (long) ndsp;
1091         init_timer(&ndsp->tone.tl);
1092
1093         if (dtmfthreshold < 20 || dtmfthreshold > 500)
1094                 dtmfthreshold = 200;
1095         ndsp->dtmf.treshold = dtmfthreshold*10000;
1096
1097         /* init pipeline append to list */
1098         spin_lock_irqsave(&dsp_lock, flags);
1099         dsp_pipeline_init(&ndsp->pipeline);
1100         list_add_tail(&ndsp->list, &dsp_ilist);
1101         spin_unlock_irqrestore(&dsp_lock, flags);
1102
1103         return 0;
1104 }
1105
1106
1107 static struct Bprotocol DSP = {
1108         .Bprotocols = (1 << (ISDN_P_B_L2DSP & ISDN_P_B_MASK))
1109                 | (1 << (ISDN_P_B_L2DSPHDLC & ISDN_P_B_MASK)),
1110         .name = "dsp",
1111         .create = dspcreate
1112 };
1113
1114 static int dsp_init(void)
1115 {
1116         int err;
1117         int tics;
1118
1119         printk(KERN_INFO "DSP modul %s\n", mISDN_dsp_revision);
1120
1121         dsp_options = options;
1122         dsp_debug = debug;
1123
1124         /* set packet size */
1125         dsp_poll = poll;
1126         if (dsp_poll) {
1127                 if (dsp_poll > MAX_POLL) {
1128                         printk(KERN_ERR "%s: Wrong poll value (%d), use %d "
1129                                 "maximum.\n", __func__, poll, MAX_POLL);
1130                         err = -EINVAL;
1131                         return err;
1132                 }
1133                 if (dsp_poll < 8) {
1134                         printk(KERN_ERR "%s: Wrong poll value (%d), use 8 "
1135                                 "minimum.\n", __func__, dsp_poll);
1136                         err = -EINVAL;
1137                         return err;
1138                 }
1139                 dsp_tics = poll * HZ / 8000;
1140                 if (dsp_tics * 8000 != poll * HZ) {
1141                         printk(KERN_INFO "mISDN_dsp: Cannot clock every %d "
1142                                 "samples (0,125 ms). It is not a multiple of "
1143                                 "%d HZ.\n", poll, HZ);
1144                         err = -EINVAL;
1145                         return err;
1146                 }
1147         } else {
1148                 poll = 8;
1149                 while (poll <= MAX_POLL) {
1150                         tics = (poll * HZ) / 8000;
1151                         if (tics * 8000 == poll * HZ) {
1152                                 dsp_tics = tics;
1153                                 dsp_poll = poll;
1154                                 if (poll >= 64)
1155                                         break;
1156                         }
1157                         poll++;
1158                 }
1159         }
1160         if (dsp_poll == 0) {
1161                 printk(KERN_INFO "mISDN_dsp: There is no multiple of kernel "
1162                         "clock that equals exactly the duration of 8-256 "
1163                         "samples. (Choose kernel clock speed like 100, 250, "
1164                         "300, 1000)\n");
1165                 err = -EINVAL;
1166                 return err;
1167         }
1168         printk(KERN_INFO "mISDN_dsp: DSP clocks every %d samples. This equals "
1169                 "%d jiffies.\n", dsp_poll, dsp_tics);
1170
1171         spin_lock_init(&dsp_lock);
1172         INIT_LIST_HEAD(&dsp_ilist);
1173         INIT_LIST_HEAD(&conf_ilist);
1174
1175         /* init conversion tables */
1176         dsp_audio_generate_law_tables();
1177         dsp_silence = (dsp_options&DSP_OPT_ULAW)?0xff:0x2a;
1178         dsp_audio_law_to_s32 = (dsp_options&DSP_OPT_ULAW)?dsp_audio_ulaw_to_s32:
1179                 dsp_audio_alaw_to_s32;
1180         dsp_audio_generate_s2law_table();
1181         dsp_audio_generate_seven();
1182         dsp_audio_generate_mix_table();
1183         if (dsp_options & DSP_OPT_ULAW)
1184                 dsp_audio_generate_ulaw_samples();
1185         dsp_audio_generate_volume_changes();
1186
1187         err = dsp_pipeline_module_init();
1188         if (err) {
1189                 printk(KERN_ERR "mISDN_dsp: Can't initialize pipeline, "
1190                         "error(%d)\n", err);
1191                 return err;
1192         }
1193
1194         err = mISDN_register_Bprotocol(&DSP);
1195         if (err) {
1196                 printk(KERN_ERR "Can't register %s error(%d)\n", DSP.name, err);
1197                 return err;
1198         }
1199
1200         /* set sample timer */
1201         dsp_spl_tl.function = (void *)dsp_cmx_send;
1202         dsp_spl_tl.data = 0;
1203         init_timer(&dsp_spl_tl);
1204         dsp_spl_tl.expires = jiffies + dsp_tics;
1205         dsp_spl_jiffies = dsp_spl_tl.expires;
1206         add_timer(&dsp_spl_tl);
1207
1208         return 0;
1209 }
1210
1211
1212 static void dsp_cleanup(void)
1213 {
1214         mISDN_unregister_Bprotocol(&DSP);
1215
1216         if (timer_pending(&dsp_spl_tl))
1217                 del_timer(&dsp_spl_tl);
1218
1219         if (!list_empty(&dsp_ilist)) {
1220                 printk(KERN_ERR "mISDN_dsp: Audio DSP object inst list not "
1221                         "empty.\n");
1222         }
1223         if (!list_empty(&conf_ilist)) {
1224                 printk(KERN_ERR "mISDN_dsp: Conference list not empty. Not "
1225                         "all memory freed.\n");
1226         }
1227
1228         dsp_pipeline_module_exit();
1229 }
1230
1231 module_init(dsp_init);
1232 module_exit(dsp_cleanup);
1233