Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Author       Andreas Eversberg (jolly@eversberg.eu)
0003  * Based on source code structure by
0004  *      Karsten Keil (keil@isdn4linux.de)
0005  *
0006  *      This file is (c) under GNU PUBLIC LICENSE
0007  *
0008  * Thanks to    Karsten Keil (great drivers)
0009  *              Cologne Chip (great chips)
0010  *
0011  * This module does:
0012  *      Real-time tone generation
0013  *      DTMF detection
0014  *      Real-time cross-connection and conferrence
0015  *      Compensate jitter due to system load and hardware fault.
0016  *      All features are done in kernel space and will be realized
0017  *      using hardware, if available and supported by chip set.
0018  *      Blowfish encryption/decryption
0019  */
0020 
0021 /* STRUCTURE:
0022  *
0023  * The dsp module provides layer 2 for b-channels (64kbit). It provides
0024  * transparent audio forwarding with special digital signal processing:
0025  *
0026  * - (1) generation of tones
0027  * - (2) detection of dtmf tones
0028  * - (3) crossconnecting and conferences (clocking)
0029  * - (4) echo generation for delay test
0030  * - (5) volume control
0031  * - (6) disable receive data
0032  * - (7) pipeline
0033  * - (8) encryption/decryption
0034  *
0035  * Look:
0036  *             TX            RX
0037  *         ------upper layer------
0038  *             |             ^
0039  *             |             |(6)
0040  *             v             |
0041  *       +-----+-------------+-----+
0042  *       |(3)(4)                   |
0043  *       |           CMX           |
0044  *       |                         |
0045  *       |           +-------------+
0046  *       |           |       ^
0047  *       |           |       |
0048  *       |+---------+|  +----+----+
0049  *       ||(1)      ||  |(2)      |
0050  *       ||         ||  |         |
0051  *       ||  Tones  ||  |  DTMF   |
0052  *       ||         ||  |         |
0053  *       ||         ||  |         |
0054  *       |+----+----+|  +----+----+
0055  *       +-----+-----+       ^
0056  *             |             |
0057  *             v             |
0058  *        +----+----+   +----+----+
0059  *        |(5)      |   |(5)      |
0060  *        |         |   |         |
0061  *        |TX Volume|   |RX Volume|
0062  *        |         |   |         |
0063  *        |         |   |         |
0064  *        +----+----+   +----+----+
0065  *             |             ^
0066  *             |             |
0067  *             v             |
0068  *        +----+-------------+----+
0069  *        |(7)                    |
0070  *        |                       |
0071  *        |  Pipeline Processing  |
0072  *        |                       |
0073  *        |                       |
0074  *        +----+-------------+----+
0075  *             |             ^
0076  *             |             |
0077  *             v             |
0078  *        +----+----+   +----+----+
0079  *        |(8)      |   |(8)      |
0080  *        |         |   |         |
0081  *        | Encrypt |   | Decrypt |
0082  *        |         |   |         |
0083  *        |         |   |         |
0084  *        +----+----+   +----+----+
0085  *             |             ^
0086  *             |             |
0087  *             v             |
0088  *         ------card  layer------
0089  *             TX            RX
0090  *
0091  * Above you can see the logical data flow. If software is used to do the
0092  * process, it is actually the real data flow. If hardware is used, data
0093  * may not flow, but hardware commands to the card, to provide the data flow
0094  * as shown.
0095  *
0096  * NOTE: The channel must be activated in order to make dsp work, even if
0097  * no data flow to the upper layer is intended. Activation can be done
0098  * after and before controlling the setting using PH_CONTROL requests.
0099  *
0100  * DTMF: Will be detected by hardware if possible. It is done before CMX
0101  * processing.
0102  *
0103  * Tones: Will be generated via software if endless looped audio fifos are
0104  * not supported by hardware. Tones will override all data from CMX.
0105  * It is not required to join a conference to use tones at any time.
0106  *
0107  * CMX: Is transparent when not used. When it is used, it will do
0108  * crossconnections and conferences via software if not possible through
0109  * hardware. If hardware capability is available, hardware is used.
0110  *
0111  * Echo: Is generated by CMX and is used to check performance of hard and
0112  * software CMX.
0113  *
0114  * The CMX has special functions for conferences with one, two and more
0115  * members. It will allow different types of data flow. Receive and transmit
0116  * data to/form upper layer may be switched on/off individually without losing
0117  * features of CMX, Tones and DTMF.
0118  *
0119  * Echo Cancellation: Sometimes we like to cancel echo from the interface.
0120  * Note that a VoIP call may not have echo caused by the IP phone. The echo
0121  * is generated by the telephone line connected to it. Because the delay
0122  * is high, it becomes an echo. RESULT: Echo Cachelation is required if
0123  * both echo AND delay is applied to an interface.
0124  * Remember that software CMX always generates a more or less delay.
0125  *
0126  * If all used features can be realized in hardware, and if transmit and/or
0127  * receive data ist disabled, the card may not send/receive any data at all.
0128  * Not receiving is useful if only announcements are played. Not sending is
0129  * useful if an answering machine records audio. Not sending and receiving is
0130  * useful during most states of the call. If supported by hardware, tones
0131  * will be played without cpu load. Small PBXs and NT-Mode applications will
0132  * not need expensive hardware when processing calls.
0133  *
0134  *
0135  * LOCKING:
0136  *
0137  * When data is received from upper or lower layer (card), the complete dsp
0138  * module is locked by a global lock.  This lock MUST lock irq, because it
0139  * must lock timer events by DSP poll timer.
0140  * When data is ready to be transmitted down, the data is queued and sent
0141  * outside lock and timer event.
0142  * PH_CONTROL must not change any settings, join or split conference members
0143  * during process of data.
0144  *
0145  * HDLC:
0146  *
0147  * It works quite the same as transparent, except that HDLC data is forwarded
0148  * to all other conference members if no hardware bridging is possible.
0149  * Send data will be writte to sendq. Sendq will be sent if confirm is received.
0150  * Conference cannot join, if one member is not hdlc.
0151  *
0152  */
0153 
0154 #include <linux/delay.h>
0155 #include <linux/gfp.h>
0156 #include <linux/mISDNif.h>
0157 #include <linux/mISDNdsp.h>
0158 #include <linux/module.h>
0159 #include <linux/vmalloc.h>
0160 #include "core.h"
0161 #include "dsp.h"
0162 
0163 static const char *mISDN_dsp_revision = "2.0";
0164 
0165 static int debug;
0166 static int options;
0167 static int poll;
0168 static int dtmfthreshold = 100;
0169 
0170 MODULE_AUTHOR("Andreas Eversberg");
0171 module_param(debug, uint, S_IRUGO | S_IWUSR);
0172 module_param(options, uint, S_IRUGO | S_IWUSR);
0173 module_param(poll, uint, S_IRUGO | S_IWUSR);
0174 module_param(dtmfthreshold, uint, S_IRUGO | S_IWUSR);
0175 MODULE_LICENSE("GPL");
0176 
0177 /*int spinnest = 0;*/
0178 
0179 DEFINE_SPINLOCK(dsp_lock); /* global dsp lock */
0180 LIST_HEAD(dsp_ilist);
0181 LIST_HEAD(conf_ilist);
0182 int dsp_debug;
0183 int dsp_options;
0184 int dsp_poll, dsp_tics;
0185 
0186 /* check if rx may be turned off or must be turned on */
0187 static void
0188 dsp_rx_off_member(struct dsp *dsp)
0189 {
0190     struct mISDN_ctrl_req   cq;
0191     int rx_off = 1;
0192 
0193     memset(&cq, 0, sizeof(cq));
0194 
0195     if (!dsp->features_rx_off)
0196         return;
0197 
0198     /* not disabled */
0199     if (!dsp->rx_disabled)
0200         rx_off = 0;
0201     /* software dtmf */
0202     else if (dsp->dtmf.software)
0203         rx_off = 0;
0204     /* echo in software */
0205     else if (dsp->echo.software)
0206         rx_off = 0;
0207     /* bridge in software */
0208     else if (dsp->conf && dsp->conf->software)
0209         rx_off = 0;
0210     /* data is not required by user space and not required
0211      * for echo dtmf detection, soft-echo, soft-bridging */
0212 
0213     if (rx_off == dsp->rx_is_off)
0214         return;
0215 
0216     if (!dsp->ch.peer) {
0217         if (dsp_debug & DEBUG_DSP_CORE)
0218             printk(KERN_DEBUG "%s: no peer, no rx_off\n",
0219                    __func__);
0220         return;
0221     }
0222     cq.op = MISDN_CTRL_RX_OFF;
0223     cq.p1 = rx_off;
0224     if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
0225         printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
0226                __func__);
0227         return;
0228     }
0229     dsp->rx_is_off = rx_off;
0230     if (dsp_debug & DEBUG_DSP_CORE)
0231         printk(KERN_DEBUG "%s: %s set rx_off = %d\n",
0232                __func__, dsp->name, rx_off);
0233 }
0234 static void
0235 dsp_rx_off(struct dsp *dsp)
0236 {
0237     struct dsp_conf_member  *member;
0238 
0239     if (dsp_options & DSP_OPT_NOHARDWARE)
0240         return;
0241 
0242     /* no conf */
0243     if (!dsp->conf) {
0244         dsp_rx_off_member(dsp);
0245         return;
0246     }
0247     /* check all members in conf */
0248     list_for_each_entry(member, &dsp->conf->mlist, list) {
0249         dsp_rx_off_member(member->dsp);
0250     }
0251 }
0252 
0253 /* enable "fill empty" feature */
0254 static void
0255 dsp_fill_empty(struct dsp *dsp)
0256 {
0257     struct mISDN_ctrl_req   cq;
0258 
0259     memset(&cq, 0, sizeof(cq));
0260 
0261     if (!dsp->ch.peer) {
0262         if (dsp_debug & DEBUG_DSP_CORE)
0263             printk(KERN_DEBUG "%s: no peer, no fill_empty\n",
0264                    __func__);
0265         return;
0266     }
0267     cq.op = MISDN_CTRL_FILL_EMPTY;
0268     cq.p1 = 1;
0269     cq.p2 = dsp_silence;
0270     if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
0271         printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
0272                __func__);
0273         return;
0274     }
0275     if (dsp_debug & DEBUG_DSP_CORE)
0276         printk(KERN_DEBUG "%s: %s set fill_empty = 1\n",
0277                __func__, dsp->name);
0278 }
0279 
0280 static int
0281 dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb)
0282 {
0283     struct sk_buff  *nskb;
0284     int ret = 0;
0285     int cont;
0286     u8 *data;
0287     int len;
0288 
0289     if (skb->len < sizeof(int)) {
0290         printk(KERN_ERR "%s: PH_CONTROL message too short\n", __func__);
0291         return -EINVAL;
0292     }
0293     cont = *((int *)skb->data);
0294     len = skb->len - sizeof(int);
0295     data = skb->data + sizeof(int);
0296 
0297     switch (cont) {
0298     case DTMF_TONE_START: /* turn on DTMF */
0299         if (dsp->hdlc) {
0300             ret = -EINVAL;
0301             break;
0302         }
0303         if (dsp_debug & DEBUG_DSP_CORE)
0304             printk(KERN_DEBUG "%s: start dtmf\n", __func__);
0305         if (len == sizeof(int)) {
0306             if (dsp_debug & DEBUG_DSP_CORE)
0307                 printk(KERN_NOTICE "changing DTMF Threshold "
0308                        "to %d\n", *((int *)data));
0309             dsp->dtmf.treshold = (*(int *)data) * 10000;
0310         }
0311         dsp->dtmf.enable = 1;
0312         /* init goertzel */
0313         dsp_dtmf_goertzel_init(dsp);
0314 
0315         /* check dtmf hardware */
0316         dsp_dtmf_hardware(dsp);
0317         dsp_rx_off(dsp);
0318         break;
0319     case DTMF_TONE_STOP: /* turn off DTMF */
0320         if (dsp_debug & DEBUG_DSP_CORE)
0321             printk(KERN_DEBUG "%s: stop dtmf\n", __func__);
0322         dsp->dtmf.enable = 0;
0323         dsp->dtmf.hardware = 0;
0324         dsp->dtmf.software = 0;
0325         break;
0326     case DSP_CONF_JOIN: /* join / update conference */
0327         if (len < sizeof(int)) {
0328             ret = -EINVAL;
0329             break;
0330         }
0331         if (*((u32 *)data) == 0)
0332             goto conf_split;
0333         if (dsp_debug & DEBUG_DSP_CORE)
0334             printk(KERN_DEBUG "%s: join conference %d\n",
0335                    __func__, *((u32 *)data));
0336         ret = dsp_cmx_conf(dsp, *((u32 *)data));
0337         /* dsp_cmx_hardware will also be called here */
0338         dsp_rx_off(dsp);
0339         if (dsp_debug & DEBUG_DSP_CMX)
0340             dsp_cmx_debug(dsp);
0341         break;
0342     case DSP_CONF_SPLIT: /* remove from conference */
0343     conf_split:
0344         if (dsp_debug & DEBUG_DSP_CORE)
0345             printk(KERN_DEBUG "%s: release conference\n", __func__);
0346         ret = dsp_cmx_conf(dsp, 0);
0347         /* dsp_cmx_hardware will also be called here */
0348         if (dsp_debug & DEBUG_DSP_CMX)
0349             dsp_cmx_debug(dsp);
0350         dsp_rx_off(dsp);
0351         break;
0352     case DSP_TONE_PATT_ON: /* play tone */
0353         if (dsp->hdlc) {
0354             ret = -EINVAL;
0355             break;
0356         }
0357         if (len < sizeof(int)) {
0358             ret = -EINVAL;
0359             break;
0360         }
0361         if (dsp_debug & DEBUG_DSP_CORE)
0362             printk(KERN_DEBUG "%s: turn tone 0x%x on\n",
0363                    __func__, *((int *)skb->data));
0364         ret = dsp_tone(dsp, *((int *)data));
0365         if (!ret) {
0366             dsp_cmx_hardware(dsp->conf, dsp);
0367             dsp_rx_off(dsp);
0368         }
0369         if (!dsp->tone.tone)
0370             goto tone_off;
0371         break;
0372     case DSP_TONE_PATT_OFF: /* stop tone */
0373         if (dsp->hdlc) {
0374             ret = -EINVAL;
0375             break;
0376         }
0377         if (dsp_debug & DEBUG_DSP_CORE)
0378             printk(KERN_DEBUG "%s: turn tone off\n", __func__);
0379         dsp_tone(dsp, 0);
0380         dsp_cmx_hardware(dsp->conf, dsp);
0381         dsp_rx_off(dsp);
0382         /* reset tx buffers (user space data) */
0383     tone_off:
0384         dsp->rx_W = 0;
0385         dsp->rx_R = 0;
0386         break;
0387     case DSP_VOL_CHANGE_TX: /* change volume */
0388         if (dsp->hdlc) {
0389             ret = -EINVAL;
0390             break;
0391         }
0392         if (len < sizeof(int)) {
0393             ret = -EINVAL;
0394             break;
0395         }
0396         dsp->tx_volume = *((int *)data);
0397         if (dsp_debug & DEBUG_DSP_CORE)
0398             printk(KERN_DEBUG "%s: change tx vol to %d\n",
0399                    __func__, dsp->tx_volume);
0400         dsp_cmx_hardware(dsp->conf, dsp);
0401         dsp_dtmf_hardware(dsp);
0402         dsp_rx_off(dsp);
0403         break;
0404     case DSP_VOL_CHANGE_RX: /* change volume */
0405         if (dsp->hdlc) {
0406             ret = -EINVAL;
0407             break;
0408         }
0409         if (len < sizeof(int)) {
0410             ret = -EINVAL;
0411             break;
0412         }
0413         dsp->rx_volume = *((int *)data);
0414         if (dsp_debug & DEBUG_DSP_CORE)
0415             printk(KERN_DEBUG "%s: change rx vol to %d\n",
0416                    __func__, dsp->tx_volume);
0417         dsp_cmx_hardware(dsp->conf, dsp);
0418         dsp_dtmf_hardware(dsp);
0419         dsp_rx_off(dsp);
0420         break;
0421     case DSP_ECHO_ON: /* enable echo */
0422         dsp->echo.software = 1; /* soft echo */
0423         if (dsp_debug & DEBUG_DSP_CORE)
0424             printk(KERN_DEBUG "%s: enable cmx-echo\n", __func__);
0425         dsp_cmx_hardware(dsp->conf, dsp);
0426         dsp_rx_off(dsp);
0427         if (dsp_debug & DEBUG_DSP_CMX)
0428             dsp_cmx_debug(dsp);
0429         break;
0430     case DSP_ECHO_OFF: /* disable echo */
0431         dsp->echo.software = 0;
0432         dsp->echo.hardware = 0;
0433         if (dsp_debug & DEBUG_DSP_CORE)
0434             printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
0435         dsp_cmx_hardware(dsp->conf, dsp);
0436         dsp_rx_off(dsp);
0437         if (dsp_debug & DEBUG_DSP_CMX)
0438             dsp_cmx_debug(dsp);
0439         break;
0440     case DSP_RECEIVE_ON: /* enable receive to user space */
0441         if (dsp_debug & DEBUG_DSP_CORE)
0442             printk(KERN_DEBUG "%s: enable receive to user "
0443                    "space\n", __func__);
0444         dsp->rx_disabled = 0;
0445         dsp_rx_off(dsp);
0446         break;
0447     case DSP_RECEIVE_OFF: /* disable receive to user space */
0448         if (dsp_debug & DEBUG_DSP_CORE)
0449             printk(KERN_DEBUG "%s: disable receive to "
0450                    "user space\n", __func__);
0451         dsp->rx_disabled = 1;
0452         dsp_rx_off(dsp);
0453         break;
0454     case DSP_MIX_ON: /* enable mixing of tx data */
0455         if (dsp->hdlc) {
0456             ret = -EINVAL;
0457             break;
0458         }
0459         if (dsp_debug & DEBUG_DSP_CORE)
0460             printk(KERN_DEBUG "%s: enable mixing of "
0461                    "tx-data with conf members\n", __func__);
0462         dsp->tx_mix = 1;
0463         dsp_cmx_hardware(dsp->conf, dsp);
0464         dsp_rx_off(dsp);
0465         if (dsp_debug & DEBUG_DSP_CMX)
0466             dsp_cmx_debug(dsp);
0467         break;
0468     case DSP_MIX_OFF: /* disable mixing of tx data */
0469         if (dsp->hdlc) {
0470             ret = -EINVAL;
0471             break;
0472         }
0473         if (dsp_debug & DEBUG_DSP_CORE)
0474             printk(KERN_DEBUG "%s: disable mixing of "
0475                    "tx-data with conf members\n", __func__);
0476         dsp->tx_mix = 0;
0477         dsp_cmx_hardware(dsp->conf, dsp);
0478         dsp_rx_off(dsp);
0479         if (dsp_debug & DEBUG_DSP_CMX)
0480             dsp_cmx_debug(dsp);
0481         break;
0482     case DSP_TXDATA_ON: /* enable txdata */
0483         dsp->tx_data = 1;
0484         if (dsp_debug & DEBUG_DSP_CORE)
0485             printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
0486         dsp_cmx_hardware(dsp->conf, dsp);
0487         dsp_rx_off(dsp);
0488         if (dsp_debug & DEBUG_DSP_CMX)
0489             dsp_cmx_debug(dsp);
0490         break;
0491     case DSP_TXDATA_OFF: /* disable txdata */
0492         dsp->tx_data = 0;
0493         if (dsp_debug & DEBUG_DSP_CORE)
0494             printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
0495         dsp_cmx_hardware(dsp->conf, dsp);
0496         dsp_rx_off(dsp);
0497         if (dsp_debug & DEBUG_DSP_CMX)
0498             dsp_cmx_debug(dsp);
0499         break;
0500     case DSP_DELAY: /* use delay algorithm instead of dynamic
0501                jitter algorithm */
0502         if (dsp->hdlc) {
0503             ret = -EINVAL;
0504             break;
0505         }
0506         if (len < sizeof(int)) {
0507             ret = -EINVAL;
0508             break;
0509         }
0510         dsp->cmx_delay = (*((int *)data)) << 3;
0511         /* milliseconds to samples */
0512         if (dsp->cmx_delay >= (CMX_BUFF_HALF >> 1))
0513             /* clip to half of maximum usable buffer
0514                (half of half buffer) */
0515             dsp->cmx_delay = (CMX_BUFF_HALF >> 1) - 1;
0516         if (dsp_debug & DEBUG_DSP_CORE)
0517             printk(KERN_DEBUG "%s: use delay algorithm to "
0518                    "compensate jitter (%d samples)\n",
0519                    __func__, dsp->cmx_delay);
0520         break;
0521     case DSP_JITTER: /* use dynamic jitter algorithm instead of
0522                 delay algorithm */
0523         if (dsp->hdlc) {
0524             ret = -EINVAL;
0525             break;
0526         }
0527         dsp->cmx_delay = 0;
0528         if (dsp_debug & DEBUG_DSP_CORE)
0529             printk(KERN_DEBUG "%s: use jitter algorithm to "
0530                    "compensate jitter\n", __func__);
0531         break;
0532     case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
0533         if (dsp->hdlc) {
0534             ret = -EINVAL;
0535             break;
0536         }
0537         dsp->tx_dejitter = 1;
0538         if (dsp_debug & DEBUG_DSP_CORE)
0539             printk(KERN_DEBUG "%s: use dejitter on TX "
0540                    "buffer\n", __func__);
0541         break;
0542     case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
0543         if (dsp->hdlc) {
0544             ret = -EINVAL;
0545             break;
0546         }
0547         dsp->tx_dejitter = 0;
0548         if (dsp_debug & DEBUG_DSP_CORE)
0549             printk(KERN_DEBUG "%s: use TX buffer without "
0550                    "dejittering\n", __func__);
0551         break;
0552     case DSP_PIPELINE_CFG:
0553         if (dsp->hdlc) {
0554             ret = -EINVAL;
0555             break;
0556         }
0557         if (len > 0 && ((char *)data)[len - 1]) {
0558             printk(KERN_DEBUG "%s: pipeline config string "
0559                    "is not NULL terminated!\n", __func__);
0560             ret = -EINVAL;
0561         } else {
0562             dsp->pipeline.inuse = 1;
0563             dsp_cmx_hardware(dsp->conf, dsp);
0564             ret = dsp_pipeline_build(&dsp->pipeline,
0565                          len > 0 ? data : NULL);
0566             dsp_cmx_hardware(dsp->conf, dsp);
0567             dsp_rx_off(dsp);
0568         }
0569         break;
0570     case DSP_BF_ENABLE_KEY: /* turn blowfish on */
0571         if (dsp->hdlc) {
0572             ret = -EINVAL;
0573             break;
0574         }
0575         if (len < 4 || len > 56) {
0576             ret = -EINVAL;
0577             break;
0578         }
0579         if (dsp_debug & DEBUG_DSP_CORE)
0580             printk(KERN_DEBUG "%s: turn blowfish on (key "
0581                    "not shown)\n", __func__);
0582         ret = dsp_bf_init(dsp, (u8 *)data, len);
0583         /* set new cont */
0584         if (!ret)
0585             cont = DSP_BF_ACCEPT;
0586         else
0587             cont = DSP_BF_REJECT;
0588         /* send indication if it worked to set it */
0589         nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
0590                     sizeof(int), &cont, GFP_ATOMIC);
0591         if (nskb) {
0592             if (dsp->up) {
0593                 if (dsp->up->send(dsp->up, nskb))
0594                     dev_kfree_skb(nskb);
0595             } else
0596                 dev_kfree_skb(nskb);
0597         }
0598         if (!ret) {
0599             dsp_cmx_hardware(dsp->conf, dsp);
0600             dsp_dtmf_hardware(dsp);
0601             dsp_rx_off(dsp);
0602         }
0603         break;
0604     case DSP_BF_DISABLE: /* turn blowfish off */
0605         if (dsp->hdlc) {
0606             ret = -EINVAL;
0607             break;
0608         }
0609         if (dsp_debug & DEBUG_DSP_CORE)
0610             printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
0611         dsp_bf_cleanup(dsp);
0612         dsp_cmx_hardware(dsp->conf, dsp);
0613         dsp_dtmf_hardware(dsp);
0614         dsp_rx_off(dsp);
0615         break;
0616     default:
0617         if (dsp_debug & DEBUG_DSP_CORE)
0618             printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
0619                    __func__, cont);
0620         ret = -EINVAL;
0621     }
0622     return ret;
0623 }
0624 
0625 static void
0626 get_features(struct mISDNchannel *ch)
0627 {
0628     struct dsp      *dsp = container_of(ch, struct dsp, ch);
0629     struct mISDN_ctrl_req   cq;
0630 
0631     if (!ch->peer) {
0632         if (dsp_debug & DEBUG_DSP_CORE)
0633             printk(KERN_DEBUG "%s: no peer, no features\n",
0634                    __func__);
0635         return;
0636     }
0637     memset(&cq, 0, sizeof(cq));
0638     cq.op = MISDN_CTRL_GETOP;
0639     if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
0640         printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
0641                __func__);
0642         return;
0643     }
0644     if (cq.op & MISDN_CTRL_RX_OFF)
0645         dsp->features_rx_off = 1;
0646     if (cq.op & MISDN_CTRL_FILL_EMPTY)
0647         dsp->features_fill_empty = 1;
0648     if (dsp_options & DSP_OPT_NOHARDWARE)
0649         return;
0650     if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
0651         cq.op = MISDN_CTRL_HW_FEATURES;
0652         *((u_long *)&cq.p1) = (u_long)&dsp->features;
0653         if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
0654             printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
0655                    __func__);
0656         }
0657     } else
0658         if (dsp_debug & DEBUG_DSP_CORE)
0659             printk(KERN_DEBUG "%s: features not supported for %s\n",
0660                    __func__, dsp->name);
0661 }
0662 
0663 static int
0664 dsp_function(struct mISDNchannel *ch,  struct sk_buff *skb)
0665 {
0666     struct dsp      *dsp = container_of(ch, struct dsp, ch);
0667     struct mISDNhead    *hh;
0668     int         ret = 0;
0669     u8          *digits = NULL;
0670     u_long          flags;
0671 
0672     hh = mISDN_HEAD_P(skb);
0673     switch (hh->prim) {
0674         /* FROM DOWN */
0675     case (PH_DATA_CNF):
0676         dsp->data_pending = 0;
0677         /* trigger next hdlc frame, if any */
0678         if (dsp->hdlc) {
0679             spin_lock_irqsave(&dsp_lock, flags);
0680             if (dsp->b_active)
0681                 schedule_work(&dsp->workq);
0682             spin_unlock_irqrestore(&dsp_lock, flags);
0683         }
0684         break;
0685     case (PH_DATA_IND):
0686     case (DL_DATA_IND):
0687         if (skb->len < 1) {
0688             ret = -EINVAL;
0689             break;
0690         }
0691         if (dsp->rx_is_off) {
0692             if (dsp_debug & DEBUG_DSP_CORE)
0693                 printk(KERN_DEBUG "%s: rx-data during rx_off"
0694                        " for %s\n",
0695                        __func__, dsp->name);
0696         }
0697         if (dsp->hdlc) {
0698             /* hdlc */
0699             spin_lock_irqsave(&dsp_lock, flags);
0700             dsp_cmx_hdlc(dsp, skb);
0701             spin_unlock_irqrestore(&dsp_lock, flags);
0702             if (dsp->rx_disabled) {
0703                 /* if receive is not allowed */
0704                 break;
0705             }
0706             hh->prim = DL_DATA_IND;
0707             if (dsp->up)
0708                 return dsp->up->send(dsp->up, skb);
0709             break;
0710         }
0711 
0712         spin_lock_irqsave(&dsp_lock, flags);
0713 
0714         /* decrypt if enabled */
0715         if (dsp->bf_enable)
0716             dsp_bf_decrypt(dsp, skb->data, skb->len);
0717         /* pipeline */
0718         if (dsp->pipeline.inuse)
0719             dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
0720                         skb->len, hh->id);
0721         /* change volume if requested */
0722         if (dsp->rx_volume)
0723             dsp_change_volume(skb, dsp->rx_volume);
0724         /* check if dtmf soft decoding is turned on */
0725         if (dsp->dtmf.software) {
0726             digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
0727                               skb->len, (dsp_options & DSP_OPT_ULAW) ? 1 : 0);
0728         }
0729         /* we need to process receive data if software */
0730         if (dsp->conf && dsp->conf->software) {
0731             /* process data from card at cmx */
0732             dsp_cmx_receive(dsp, skb);
0733         }
0734 
0735         spin_unlock_irqrestore(&dsp_lock, flags);
0736 
0737         /* send dtmf result, if any */
0738         if (digits) {
0739             while (*digits) {
0740                 int k;
0741                 struct sk_buff *nskb;
0742                 if (dsp_debug & DEBUG_DSP_DTMF)
0743                     printk(KERN_DEBUG "%s: digit"
0744                            "(%c) to layer %s\n",
0745                            __func__, *digits, dsp->name);
0746                 k = *digits | DTMF_TONE_VAL;
0747                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
0748                             MISDN_ID_ANY, sizeof(int), &k,
0749                             GFP_ATOMIC);
0750                 if (nskb) {
0751                     if (dsp->up) {
0752                         if (dsp->up->send(
0753                                 dsp->up, nskb))
0754                             dev_kfree_skb(nskb);
0755                     } else
0756                         dev_kfree_skb(nskb);
0757                 }
0758                 digits++;
0759             }
0760         }
0761         if (dsp->rx_disabled) {
0762             /* if receive is not allowed */
0763             break;
0764         }
0765         hh->prim = DL_DATA_IND;
0766         if (dsp->up)
0767             return dsp->up->send(dsp->up, skb);
0768         break;
0769     case (PH_CONTROL_IND):
0770         if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
0771             printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
0772                    "received: %x (len %d) %s\n", __func__,
0773                    hh->id, skb->len, dsp->name);
0774         switch (hh->id) {
0775         case (DTMF_HFC_COEF): /* getting coefficients */
0776             if (!dsp->dtmf.hardware) {
0777                 if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
0778                     printk(KERN_DEBUG "%s: ignoring DTMF "
0779                            "coefficients from HFC\n",
0780                            __func__);
0781                 break;
0782             }
0783             digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
0784                               skb->len, 2);
0785             while (*digits) {
0786                 int k;
0787                 struct sk_buff *nskb;
0788                 if (dsp_debug & DEBUG_DSP_DTMF)
0789                     printk(KERN_DEBUG "%s: digit"
0790                            "(%c) to layer %s\n",
0791                            __func__, *digits, dsp->name);
0792                 k = *digits | DTMF_TONE_VAL;
0793                 nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
0794                             MISDN_ID_ANY, sizeof(int), &k,
0795                             GFP_ATOMIC);
0796                 if (nskb) {
0797                     if (dsp->up) {
0798                         if (dsp->up->send(
0799                                 dsp->up, nskb))
0800                             dev_kfree_skb(nskb);
0801                     } else
0802                         dev_kfree_skb(nskb);
0803                 }
0804                 digits++;
0805             }
0806             break;
0807         case (HFC_VOL_CHANGE_TX): /* change volume */
0808             if (skb->len != sizeof(int)) {
0809                 ret = -EINVAL;
0810                 break;
0811             }
0812             spin_lock_irqsave(&dsp_lock, flags);
0813             dsp->tx_volume = *((int *)skb->data);
0814             if (dsp_debug & DEBUG_DSP_CORE)
0815                 printk(KERN_DEBUG "%s: change tx volume to "
0816                        "%d\n", __func__, dsp->tx_volume);
0817             dsp_cmx_hardware(dsp->conf, dsp);
0818             dsp_dtmf_hardware(dsp);
0819             dsp_rx_off(dsp);
0820             spin_unlock_irqrestore(&dsp_lock, flags);
0821             break;
0822         default:
0823             if (dsp_debug & DEBUG_DSP_CORE)
0824                 printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
0825                        "%s\n", __func__, hh->id, dsp->name);
0826             ret = -EINVAL;
0827         }
0828         break;
0829     case (PH_ACTIVATE_IND):
0830     case (PH_ACTIVATE_CNF):
0831         if (dsp_debug & DEBUG_DSP_CORE)
0832             printk(KERN_DEBUG "%s: b_channel is now active %s\n",
0833                    __func__, dsp->name);
0834         /* bchannel now active */
0835         spin_lock_irqsave(&dsp_lock, flags);
0836         dsp->b_active = 1;
0837         dsp->data_pending = 0;
0838         dsp->rx_init = 1;
0839         /* rx_W and rx_R will be adjusted on first frame */
0840         dsp->rx_W = 0;
0841         dsp->rx_R = 0;
0842         memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
0843         dsp_cmx_hardware(dsp->conf, dsp);
0844         dsp_dtmf_hardware(dsp);
0845         dsp_rx_off(dsp);
0846         spin_unlock_irqrestore(&dsp_lock, flags);
0847         if (dsp_debug & DEBUG_DSP_CORE)
0848             printk(KERN_DEBUG "%s: done with activation, sending "
0849                    "confirm to user space. %s\n", __func__,
0850                    dsp->name);
0851         /* send activation to upper layer */
0852         hh->prim = DL_ESTABLISH_CNF;
0853         if (dsp->up)
0854             return dsp->up->send(dsp->up, skb);
0855         break;
0856     case (PH_DEACTIVATE_IND):
0857     case (PH_DEACTIVATE_CNF):
0858         if (dsp_debug & DEBUG_DSP_CORE)
0859             printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
0860                    __func__, dsp->name);
0861         /* bchannel now inactive */
0862         spin_lock_irqsave(&dsp_lock, flags);
0863         dsp->b_active = 0;
0864         dsp->data_pending = 0;
0865         dsp_cmx_hardware(dsp->conf, dsp);
0866         dsp_rx_off(dsp);
0867         spin_unlock_irqrestore(&dsp_lock, flags);
0868         hh->prim = DL_RELEASE_CNF;
0869         if (dsp->up)
0870             return dsp->up->send(dsp->up, skb);
0871         break;
0872         /* FROM UP */
0873     case (DL_DATA_REQ):
0874     case (PH_DATA_REQ):
0875         if (skb->len < 1) {
0876             ret = -EINVAL;
0877             break;
0878         }
0879         if (dsp->hdlc) {
0880             /* hdlc */
0881             if (!dsp->b_active) {
0882                 ret = -EIO;
0883                 break;
0884             }
0885             hh->prim = PH_DATA_REQ;
0886             spin_lock_irqsave(&dsp_lock, flags);
0887             skb_queue_tail(&dsp->sendq, skb);
0888             schedule_work(&dsp->workq);
0889             spin_unlock_irqrestore(&dsp_lock, flags);
0890             return 0;
0891         }
0892         /* send data to tx-buffer (if no tone is played) */
0893         if (!dsp->tone.tone) {
0894             spin_lock_irqsave(&dsp_lock, flags);
0895             dsp_cmx_transmit(dsp, skb);
0896             spin_unlock_irqrestore(&dsp_lock, flags);
0897         }
0898         break;
0899     case (PH_CONTROL_REQ):
0900         spin_lock_irqsave(&dsp_lock, flags);
0901         ret = dsp_control_req(dsp, hh, skb);
0902         spin_unlock_irqrestore(&dsp_lock, flags);
0903         break;
0904     case (DL_ESTABLISH_REQ):
0905     case (PH_ACTIVATE_REQ):
0906         if (dsp_debug & DEBUG_DSP_CORE)
0907             printk(KERN_DEBUG "%s: activating b_channel %s\n",
0908                    __func__, dsp->name);
0909         if (dsp->dtmf.hardware || dsp->dtmf.software)
0910             dsp_dtmf_goertzel_init(dsp);
0911         get_features(ch);
0912         /* enable fill_empty feature */
0913         if (dsp->features_fill_empty)
0914             dsp_fill_empty(dsp);
0915         /* send ph_activate */
0916         hh->prim = PH_ACTIVATE_REQ;
0917         if (ch->peer)
0918             return ch->recv(ch->peer, skb);
0919         break;
0920     case (DL_RELEASE_REQ):
0921     case (PH_DEACTIVATE_REQ):
0922         if (dsp_debug & DEBUG_DSP_CORE)
0923             printk(KERN_DEBUG "%s: releasing b_channel %s\n",
0924                    __func__, dsp->name);
0925         spin_lock_irqsave(&dsp_lock, flags);
0926         dsp->tone.tone = 0;
0927         dsp->tone.hardware = 0;
0928         dsp->tone.software = 0;
0929         if (timer_pending(&dsp->tone.tl))
0930             del_timer(&dsp->tone.tl);
0931         if (dsp->conf)
0932             dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
0933                          called here */
0934         skb_queue_purge(&dsp->sendq);
0935         spin_unlock_irqrestore(&dsp_lock, flags);
0936         hh->prim = PH_DEACTIVATE_REQ;
0937         if (ch->peer)
0938             return ch->recv(ch->peer, skb);
0939         break;
0940     default:
0941         if (dsp_debug & DEBUG_DSP_CORE)
0942             printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
0943                    __func__, hh->prim, dsp->name);
0944         ret = -EINVAL;
0945     }
0946     if (!ret)
0947         dev_kfree_skb(skb);
0948     return ret;
0949 }
0950 
0951 static int
0952 dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
0953 {
0954     struct dsp      *dsp = container_of(ch, struct dsp, ch);
0955     u_long      flags;
0956 
0957     if (debug & DEBUG_DSP_CTRL)
0958         printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
0959 
0960     switch (cmd) {
0961     case OPEN_CHANNEL:
0962         break;
0963     case CLOSE_CHANNEL:
0964         if (dsp->ch.peer)
0965             dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
0966 
0967         /* wait until workqueue has finished,
0968          * must lock here, or we may hit send-process currently
0969          * queueing. */
0970         spin_lock_irqsave(&dsp_lock, flags);
0971         dsp->b_active = 0;
0972         spin_unlock_irqrestore(&dsp_lock, flags);
0973         /* MUST not be locked, because it waits until queue is done. */
0974         cancel_work_sync(&dsp->workq);
0975         spin_lock_irqsave(&dsp_lock, flags);
0976         if (timer_pending(&dsp->tone.tl))
0977             del_timer(&dsp->tone.tl);
0978         skb_queue_purge(&dsp->sendq);
0979         if (dsp_debug & DEBUG_DSP_CTRL)
0980             printk(KERN_DEBUG "%s: releasing member %s\n",
0981                    __func__, dsp->name);
0982         dsp->b_active = 0;
0983         dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
0984                      here */
0985         dsp_pipeline_destroy(&dsp->pipeline);
0986 
0987         if (dsp_debug & DEBUG_DSP_CTRL)
0988             printk(KERN_DEBUG "%s: remove & destroy object %s\n",
0989                    __func__, dsp->name);
0990         list_del(&dsp->list);
0991         spin_unlock_irqrestore(&dsp_lock, flags);
0992 
0993         if (dsp_debug & DEBUG_DSP_CTRL)
0994             printk(KERN_DEBUG "%s: dsp instance released\n",
0995                    __func__);
0996         vfree(dsp);
0997         module_put(THIS_MODULE);
0998         break;
0999     }
1000     return 0;
1001 }
1002 
1003 static void
1004 dsp_send_bh(struct work_struct *work)
1005 {
1006     struct dsp *dsp = container_of(work, struct dsp, workq);
1007     struct sk_buff *skb;
1008     struct mISDNhead    *hh;
1009 
1010     if (dsp->hdlc && dsp->data_pending)
1011         return; /* wait until data has been acknowledged */
1012 
1013     /* send queued data */
1014     while ((skb = skb_dequeue(&dsp->sendq))) {
1015         /* in locked date, we must have still data in queue */
1016         if (dsp->data_pending) {
1017             if (dsp_debug & DEBUG_DSP_CORE)
1018                 printk(KERN_DEBUG "%s: fifo full %s, this is "
1019                        "no bug!\n", __func__, dsp->name);
1020             /* flush transparent data, if not acked */
1021             dev_kfree_skb(skb);
1022             continue;
1023         }
1024         hh = mISDN_HEAD_P(skb);
1025         if (hh->prim == DL_DATA_REQ) {
1026             /* send packet up */
1027             if (dsp->up) {
1028                 if (dsp->up->send(dsp->up, skb))
1029                     dev_kfree_skb(skb);
1030             } else
1031                 dev_kfree_skb(skb);
1032         } else {
1033             /* send packet down */
1034             if (dsp->ch.peer) {
1035                 dsp->data_pending = 1;
1036                 if (dsp->ch.recv(dsp->ch.peer, skb)) {
1037                     dev_kfree_skb(skb);
1038                     dsp->data_pending = 0;
1039                 }
1040             } else
1041                 dev_kfree_skb(skb);
1042         }
1043     }
1044 }
1045 
1046 static int
1047 dspcreate(struct channel_req *crq)
1048 {
1049     struct dsp      *ndsp;
1050     u_long      flags;
1051 
1052     if (crq->protocol != ISDN_P_B_L2DSP
1053         && crq->protocol != ISDN_P_B_L2DSPHDLC)
1054         return -EPROTONOSUPPORT;
1055     ndsp = vzalloc(sizeof(struct dsp));
1056     if (!ndsp) {
1057         printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
1058         return -ENOMEM;
1059     }
1060     if (dsp_debug & DEBUG_DSP_CTRL)
1061         printk(KERN_DEBUG "%s: creating new dsp instance\n", __func__);
1062 
1063     /* default enabled */
1064     INIT_WORK(&ndsp->workq, (void *)dsp_send_bh);
1065     skb_queue_head_init(&ndsp->sendq);
1066     ndsp->ch.send = dsp_function;
1067     ndsp->ch.ctrl = dsp_ctrl;
1068     ndsp->up = crq->ch;
1069     crq->ch = &ndsp->ch;
1070     if (crq->protocol == ISDN_P_B_L2DSP) {
1071         crq->protocol = ISDN_P_B_RAW;
1072         ndsp->hdlc = 0;
1073     } else {
1074         crq->protocol = ISDN_P_B_HDLC;
1075         ndsp->hdlc = 1;
1076     }
1077     if (!try_module_get(THIS_MODULE))
1078         printk(KERN_WARNING "%s:cannot get module\n",
1079                __func__);
1080 
1081     sprintf(ndsp->name, "DSP_C%x(0x%p)",
1082         ndsp->up->st->dev->id + 1, ndsp);
1083     /* set frame size to start */
1084     ndsp->features.hfc_id = -1; /* current PCM id */
1085     ndsp->features.pcm_id = -1; /* current PCM id */
1086     ndsp->pcm_slot_rx = -1; /* current CPM slot */
1087     ndsp->pcm_slot_tx = -1;
1088     ndsp->pcm_bank_rx = -1;
1089     ndsp->pcm_bank_tx = -1;
1090     ndsp->hfc_conf = -1; /* current conference number */
1091     /* set tone timer */
1092     timer_setup(&ndsp->tone.tl, dsp_tone_timeout, 0);
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 __init dsp_init(void)
1116 {
1117     int err;
1118     int tics;
1119 
1120     printk(KERN_INFO "DSP module %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     /* init conversion tables */
1173     dsp_audio_generate_law_tables();
1174     dsp_silence = (dsp_options & DSP_OPT_ULAW) ? 0xff : 0x2a;
1175     dsp_audio_law_to_s32 = (dsp_options & DSP_OPT_ULAW) ?
1176         dsp_audio_ulaw_to_s32 : dsp_audio_alaw_to_s32;
1177     dsp_audio_generate_s2law_table();
1178     dsp_audio_generate_seven();
1179     dsp_audio_generate_mix_table();
1180     if (dsp_options & DSP_OPT_ULAW)
1181         dsp_audio_generate_ulaw_samples();
1182     dsp_audio_generate_volume_changes();
1183 
1184     err = dsp_pipeline_module_init();
1185     if (err) {
1186         printk(KERN_ERR "mISDN_dsp: Can't initialize pipeline, "
1187                "error(%d)\n", err);
1188         return err;
1189     }
1190 
1191     err = mISDN_register_Bprotocol(&DSP);
1192     if (err) {
1193         printk(KERN_ERR "Can't register %s error(%d)\n", DSP.name, err);
1194         return err;
1195     }
1196 
1197     /* set sample timer */
1198     timer_setup(&dsp_spl_tl, (void *)dsp_cmx_send, 0);
1199     dsp_spl_tl.expires = jiffies + dsp_tics;
1200     dsp_spl_jiffies = dsp_spl_tl.expires;
1201     add_timer(&dsp_spl_tl);
1202 
1203     return 0;
1204 }
1205 
1206 
1207 static void __exit dsp_cleanup(void)
1208 {
1209     mISDN_unregister_Bprotocol(&DSP);
1210 
1211     del_timer_sync(&dsp_spl_tl);
1212 
1213     if (!list_empty(&dsp_ilist)) {
1214         printk(KERN_ERR "mISDN_dsp: Audio DSP object inst list not "
1215                "empty.\n");
1216     }
1217     if (!list_empty(&conf_ilist)) {
1218         printk(KERN_ERR "mISDN_dsp: Conference list not empty. Not "
1219                "all memory freed.\n");
1220     }
1221 
1222     dsp_pipeline_module_exit();
1223 }
1224 
1225 module_init(dsp_init);
1226 module_exit(dsp_cleanup);