2 * Author Andreas Eversberg (jolly@eversberg.eu)
3 * Based on source code structure by
4 * Karsten Keil (keil@isdn4linux.de)
6 * This file is (c) under GNU PUBLIC LICENSE
8 * Thanks to Karsten Keil (great drivers)
9 * Cologne Chip (great chips)
12 * Real-time tone generation
14 * Real-time cross-connection and conferrence
15 * Compensate jitter due to system load and hardware fault.
16 * All features are done in kernel space and will be realized
17 * using hardware, if available and supported by chip set.
18 * Blowfish encryption/decryption
23 * The dsp module provides layer 2 for b-channels (64kbit). It provides
24 * transparent audio forwarding with special digital signal processing:
26 * - (1) generation of tones
27 * - (2) detection of dtmf tones
28 * - (3) crossconnecting and conferences (clocking)
29 * - (4) echo generation for delay test
30 * - (5) volume control
31 * - (6) disable receive data
33 * - (8) encryption/decryption
37 * ------upper layer------
41 * +-----+-------------+-----+
48 * |+---------+| +----+----+
51 * || Tones || | DTMF |
54 * |+----+----+| +----+----+
58 * +----+----+ +----+----+
61 * |TX Volume| |RX Volume|
64 * +----+----+ +----+----+
68 * +----+-------------+----+
71 * | Pipeline Processing |
74 * +----+-------------+----+
78 * +----+----+ +----+----+
81 * | Encrypt | | Decrypt |
84 * +----+----+ +----+----+
88 * ------card layer------
91 * Above you can see the logical data flow. If software is used to do the
92 * process, it is actually the real data flow. If hardware is used, data
93 * may not flow, but hardware commands to the card, to provide the data flow
96 * NOTE: The channel must be activated in order to make dsp work, even if
97 * no data flow to the upper layer is intended. Activation can be done
98 * after and before controlling the setting using PH_CONTROL requests.
100 * DTMF: Will be detected by hardware if possible. It is done before CMX
103 * Tones: Will be generated via software if endless looped audio fifos are
104 * not supported by hardware. Tones will override all data from CMX.
105 * It is not required to join a conference to use tones at any time.
107 * CMX: Is transparent when not used. When it is used, it will do
108 * crossconnections and conferences via software if not possible through
109 * hardware. If hardware capability is available, hardware is used.
111 * Echo: Is generated by CMX and is used to check performance of hard and
114 * The CMX has special functions for conferences with one, two and more
115 * members. It will allow different types of data flow. Receive and transmit
116 * data to/form upper layer may be switched on/off individually without losing
117 * features of CMX, Tones and DTMF.
119 * Echo Cancellation: Sometimes we like to cancel echo from the interface.
120 * Note that a VoIP call may not have echo caused by the IP phone. The echo
121 * is generated by the telephone line connected to it. Because the delay
122 * is high, it becomes an echo. RESULT: Echo Cachelation is required if
123 * both echo AND delay is applied to an interface.
124 * Remember that software CMX always generates a more or less delay.
126 * If all used features can be realized in hardware, and if transmit and/or
127 * receive data ist disabled, the card may not send/receive any data at all.
128 * Not receiving is useful if only announcements are played. Not sending is
129 * useful if an answering machine records audio. Not sending and receiving is
130 * useful during most states of the call. If supported by hardware, tones
131 * will be played without cpu load. Small PBXs and NT-Mode applications will
132 * not need expensive hardware when processing calls.
137 * When data is received from upper or lower layer (card), the complete dsp
138 * module is locked by a global lock. This lock MUST lock irq, because it
139 * must lock timer events by DSP poll timer.
140 * When data is ready to be transmitted down, the data is queued and sent
141 * outside lock and timer event.
142 * PH_CONTROL must not change any settings, join or split conference members
143 * during process of data.
147 * It works quite the same as transparent, except that HDLC data is forwarded
148 * to all other conference members if no hardware bridging is possible.
149 * Send data will be writte to sendq. Sendq will be sent if confirm is received.
150 * Conference cannot join, if one member is not hdlc.
154 #include <linux/delay.h>
155 #include <linux/gfp.h>
156 #include <linux/mISDNif.h>
157 #include <linux/mISDNdsp.h>
158 #include <linux/module.h>
159 #include <linux/vmalloc.h>
163 static const char *mISDN_dsp_revision
= "2.0";
168 static int dtmfthreshold
= 100;
170 MODULE_AUTHOR("Andreas Eversberg");
171 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
172 module_param(options
, uint
, S_IRUGO
| S_IWUSR
);
173 module_param(poll
, uint
, S_IRUGO
| S_IWUSR
);
174 module_param(dtmfthreshold
, uint
, S_IRUGO
| S_IWUSR
);
175 MODULE_LICENSE("GPL");
177 /*int spinnest = 0;*/
179 spinlock_t dsp_lock
; /* global dsp lock */
180 struct list_head dsp_ilist
;
181 struct list_head conf_ilist
;
184 int dsp_poll
, dsp_tics
;
186 /* check if rx may be turned off or must be turned on */
188 dsp_rx_off_member(struct dsp
*dsp
)
190 struct mISDN_ctrl_req cq
;
193 memset(&cq
, 0, sizeof(cq
));
195 if (!dsp
->features_rx_off
)
199 if (!dsp
->rx_disabled
)
202 else if (dsp
->dtmf
.software
)
204 /* echo in software */
205 else if (dsp
->echo
.software
)
207 /* bridge in software */
208 else if (dsp
->conf
&& dsp
->conf
->software
)
210 /* data is not required by user space and not required
211 * for echo dtmf detection, soft-echo, soft-bridging */
213 if (rx_off
== dsp
->rx_is_off
)
217 if (dsp_debug
& DEBUG_DSP_CORE
)
218 printk(KERN_DEBUG
"%s: no peer, no rx_off\n",
222 cq
.op
= MISDN_CTRL_RX_OFF
;
224 if (dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
)) {
225 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
229 dsp
->rx_is_off
= rx_off
;
230 if (dsp_debug
& DEBUG_DSP_CORE
)
231 printk(KERN_DEBUG
"%s: %s set rx_off = %d\n",
232 __func__
, dsp
->name
, rx_off
);
235 dsp_rx_off(struct dsp
*dsp
)
237 struct dsp_conf_member
*member
;
239 if (dsp_options
& DSP_OPT_NOHARDWARE
)
244 dsp_rx_off_member(dsp
);
247 /* check all members in conf */
248 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
249 dsp_rx_off_member(member
->dsp
);
253 /* enable "fill empty" feature */
255 dsp_fill_empty(struct dsp
*dsp
)
257 struct mISDN_ctrl_req cq
;
259 memset(&cq
, 0, sizeof(cq
));
262 if (dsp_debug
& DEBUG_DSP_CORE
)
263 printk(KERN_DEBUG
"%s: no peer, no fill_empty\n",
267 cq
.op
= MISDN_CTRL_FILL_EMPTY
;
270 if (dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
)) {
271 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
275 if (dsp_debug
& DEBUG_DSP_CORE
)
276 printk(KERN_DEBUG
"%s: %s set fill_empty = 1\n",
277 __func__
, dsp
->name
);
281 dsp_control_req(struct dsp
*dsp
, struct mISDNhead
*hh
, struct sk_buff
*skb
)
283 struct sk_buff
*nskb
;
289 if (skb
->len
< sizeof(int)) {
290 printk(KERN_ERR
"%s: PH_CONTROL message too short\n", __func__
);
293 cont
= *((int *)skb
->data
);
294 len
= skb
->len
- sizeof(int);
295 data
= skb
->data
+ sizeof(int);
298 case DTMF_TONE_START
: /* turn on DTMF */
303 if (dsp_debug
& DEBUG_DSP_CORE
)
304 printk(KERN_DEBUG
"%s: start dtmf\n", __func__
);
305 if (len
== sizeof(int)) {
306 if (dsp_debug
& DEBUG_DSP_CORE
)
307 printk(KERN_NOTICE
"changing DTMF Threshold "
308 "to %d\n", *((int *)data
));
309 dsp
->dtmf
.treshold
= (*(int *)data
) * 10000;
311 dsp
->dtmf
.enable
= 1;
313 dsp_dtmf_goertzel_init(dsp
);
315 /* check dtmf hardware */
316 dsp_dtmf_hardware(dsp
);
319 case DTMF_TONE_STOP
: /* turn off DTMF */
320 if (dsp_debug
& DEBUG_DSP_CORE
)
321 printk(KERN_DEBUG
"%s: stop dtmf\n", __func__
);
322 dsp
->dtmf
.enable
= 0;
323 dsp
->dtmf
.hardware
= 0;
324 dsp
->dtmf
.software
= 0;
326 case DSP_CONF_JOIN
: /* join / update conference */
327 if (len
< sizeof(int)) {
331 if (*((u32
*)data
) == 0)
333 if (dsp_debug
& DEBUG_DSP_CORE
)
334 printk(KERN_DEBUG
"%s: join conference %d\n",
335 __func__
, *((u32
*)data
));
336 ret
= dsp_cmx_conf(dsp
, *((u32
*)data
));
337 /* dsp_cmx_hardware will also be called here */
339 if (dsp_debug
& DEBUG_DSP_CMX
)
342 case DSP_CONF_SPLIT
: /* remove from conference */
344 if (dsp_debug
& DEBUG_DSP_CORE
)
345 printk(KERN_DEBUG
"%s: release conference\n", __func__
);
346 ret
= dsp_cmx_conf(dsp
, 0);
347 /* dsp_cmx_hardware will also be called here */
348 if (dsp_debug
& DEBUG_DSP_CMX
)
352 case DSP_TONE_PATT_ON
: /* play tone */
357 if (len
< sizeof(int)) {
361 if (dsp_debug
& DEBUG_DSP_CORE
)
362 printk(KERN_DEBUG
"%s: turn tone 0x%x on\n",
363 __func__
, *((int *)skb
->data
));
364 ret
= dsp_tone(dsp
, *((int *)data
));
366 dsp_cmx_hardware(dsp
->conf
, dsp
);
372 case DSP_TONE_PATT_OFF
: /* stop tone */
377 if (dsp_debug
& DEBUG_DSP_CORE
)
378 printk(KERN_DEBUG
"%s: turn tone off\n", __func__
);
380 dsp_cmx_hardware(dsp
->conf
, dsp
);
382 /* reset tx buffers (user space data) */
387 case DSP_VOL_CHANGE_TX
: /* change volume */
392 if (len
< sizeof(int)) {
396 dsp
->tx_volume
= *((int *)data
);
397 if (dsp_debug
& DEBUG_DSP_CORE
)
398 printk(KERN_DEBUG
"%s: change tx vol to %d\n",
399 __func__
, dsp
->tx_volume
);
400 dsp_cmx_hardware(dsp
->conf
, dsp
);
401 dsp_dtmf_hardware(dsp
);
404 case DSP_VOL_CHANGE_RX
: /* change volume */
409 if (len
< sizeof(int)) {
413 dsp
->rx_volume
= *((int *)data
);
414 if (dsp_debug
& DEBUG_DSP_CORE
)
415 printk(KERN_DEBUG
"%s: change rx vol to %d\n",
416 __func__
, dsp
->tx_volume
);
417 dsp_cmx_hardware(dsp
->conf
, dsp
);
418 dsp_dtmf_hardware(dsp
);
421 case DSP_ECHO_ON
: /* enable echo */
422 dsp
->echo
.software
= 1; /* soft echo */
423 if (dsp_debug
& DEBUG_DSP_CORE
)
424 printk(KERN_DEBUG
"%s: enable cmx-echo\n", __func__
);
425 dsp_cmx_hardware(dsp
->conf
, dsp
);
427 if (dsp_debug
& DEBUG_DSP_CMX
)
430 case DSP_ECHO_OFF
: /* disable echo */
431 dsp
->echo
.software
= 0;
432 dsp
->echo
.hardware
= 0;
433 if (dsp_debug
& DEBUG_DSP_CORE
)
434 printk(KERN_DEBUG
"%s: disable cmx-echo\n", __func__
);
435 dsp_cmx_hardware(dsp
->conf
, dsp
);
437 if (dsp_debug
& DEBUG_DSP_CMX
)
440 case DSP_RECEIVE_ON
: /* enable receive to user space */
441 if (dsp_debug
& DEBUG_DSP_CORE
)
442 printk(KERN_DEBUG
"%s: enable receive to user "
443 "space\n", __func__
);
444 dsp
->rx_disabled
= 0;
447 case DSP_RECEIVE_OFF
: /* disable receive to user space */
448 if (dsp_debug
& DEBUG_DSP_CORE
)
449 printk(KERN_DEBUG
"%s: disable receive to "
450 "user space\n", __func__
);
451 dsp
->rx_disabled
= 1;
454 case DSP_MIX_ON
: /* enable mixing of tx data */
459 if (dsp_debug
& DEBUG_DSP_CORE
)
460 printk(KERN_DEBUG
"%s: enable mixing of "
461 "tx-data with conf members\n", __func__
);
463 dsp_cmx_hardware(dsp
->conf
, dsp
);
465 if (dsp_debug
& DEBUG_DSP_CMX
)
468 case DSP_MIX_OFF
: /* disable mixing of tx data */
473 if (dsp_debug
& DEBUG_DSP_CORE
)
474 printk(KERN_DEBUG
"%s: disable mixing of "
475 "tx-data with conf members\n", __func__
);
477 dsp_cmx_hardware(dsp
->conf
, dsp
);
479 if (dsp_debug
& DEBUG_DSP_CMX
)
482 case DSP_TXDATA_ON
: /* enable txdata */
484 if (dsp_debug
& DEBUG_DSP_CORE
)
485 printk(KERN_DEBUG
"%s: enable tx-data\n", __func__
);
486 dsp_cmx_hardware(dsp
->conf
, dsp
);
488 if (dsp_debug
& DEBUG_DSP_CMX
)
491 case DSP_TXDATA_OFF
: /* disable txdata */
493 if (dsp_debug
& DEBUG_DSP_CORE
)
494 printk(KERN_DEBUG
"%s: disable tx-data\n", __func__
);
495 dsp_cmx_hardware(dsp
->conf
, dsp
);
497 if (dsp_debug
& DEBUG_DSP_CMX
)
500 case DSP_DELAY
: /* use delay algorithm instead of dynamic
506 if (len
< sizeof(int)) {
510 dsp
->cmx_delay
= (*((int *)data
)) << 3;
511 /* milliseconds to samples */
512 if (dsp
->cmx_delay
>= (CMX_BUFF_HALF
>> 1))
513 /* clip to half of maximum usable buffer
514 (half of half buffer) */
515 dsp
->cmx_delay
= (CMX_BUFF_HALF
>> 1) - 1;
516 if (dsp_debug
& DEBUG_DSP_CORE
)
517 printk(KERN_DEBUG
"%s: use delay algorithm to "
518 "compensate jitter (%d samples)\n",
519 __func__
, dsp
->cmx_delay
);
521 case DSP_JITTER
: /* use dynamic jitter algorithm instead of
528 if (dsp_debug
& DEBUG_DSP_CORE
)
529 printk(KERN_DEBUG
"%s: use jitter algorithm to "
530 "compensate jitter\n", __func__
);
532 case DSP_TX_DEJITTER
: /* use dynamic jitter algorithm for tx-buffer */
537 dsp
->tx_dejitter
= 1;
538 if (dsp_debug
& DEBUG_DSP_CORE
)
539 printk(KERN_DEBUG
"%s: use dejitter on TX "
540 "buffer\n", __func__
);
542 case DSP_TX_DEJ_OFF
: /* use tx-buffer without dejittering*/
547 dsp
->tx_dejitter
= 0;
548 if (dsp_debug
& DEBUG_DSP_CORE
)
549 printk(KERN_DEBUG
"%s: use TX buffer without "
550 "dejittering\n", __func__
);
552 case DSP_PIPELINE_CFG
:
557 if (len
> 0 && ((char *)data
)[len
- 1]) {
558 printk(KERN_DEBUG
"%s: pipeline config string "
559 "is not NULL terminated!\n", __func__
);
562 dsp
->pipeline
.inuse
= 1;
563 dsp_cmx_hardware(dsp
->conf
, dsp
);
564 ret
= dsp_pipeline_build(&dsp
->pipeline
,
565 len
> 0 ? data
: NULL
);
566 dsp_cmx_hardware(dsp
->conf
, dsp
);
570 case DSP_BF_ENABLE_KEY
: /* turn blowfish on */
575 if (len
< 4 || len
> 56) {
579 if (dsp_debug
& DEBUG_DSP_CORE
)
580 printk(KERN_DEBUG
"%s: turn blowfish on (key "
581 "not shown)\n", __func__
);
582 ret
= dsp_bf_init(dsp
, (u8
*)data
, len
);
585 cont
= DSP_BF_ACCEPT
;
587 cont
= DSP_BF_REJECT
;
588 /* send indication if it worked to set it */
589 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
, MISDN_ID_ANY
,
590 sizeof(int), &cont
, GFP_ATOMIC
);
593 if (dsp
->up
->send(dsp
->up
, nskb
))
599 dsp_cmx_hardware(dsp
->conf
, dsp
);
600 dsp_dtmf_hardware(dsp
);
604 case DSP_BF_DISABLE
: /* turn blowfish off */
609 if (dsp_debug
& DEBUG_DSP_CORE
)
610 printk(KERN_DEBUG
"%s: turn blowfish off\n", __func__
);
612 dsp_cmx_hardware(dsp
->conf
, dsp
);
613 dsp_dtmf_hardware(dsp
);
617 if (dsp_debug
& DEBUG_DSP_CORE
)
618 printk(KERN_DEBUG
"%s: ctrl req %x unhandled\n",
626 get_features(struct mISDNchannel
*ch
)
628 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
629 struct mISDN_ctrl_req cq
;
632 if (dsp_debug
& DEBUG_DSP_CORE
)
633 printk(KERN_DEBUG
"%s: no peer, no features\n",
637 memset(&cq
, 0, sizeof(cq
));
638 cq
.op
= MISDN_CTRL_GETOP
;
639 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
) < 0) {
640 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
644 if (cq
.op
& MISDN_CTRL_RX_OFF
)
645 dsp
->features_rx_off
= 1;
646 if (cq
.op
& MISDN_CTRL_FILL_EMPTY
)
647 dsp
->features_fill_empty
= 1;
648 if (dsp_options
& DSP_OPT_NOHARDWARE
)
650 if ((cq
.op
& MISDN_CTRL_HW_FEATURES_OP
)) {
651 cq
.op
= MISDN_CTRL_HW_FEATURES
;
652 *((u_long
*)&cq
.p1
) = (u_long
)&dsp
->features
;
653 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
)) {
654 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
658 if (dsp_debug
& DEBUG_DSP_CORE
)
659 printk(KERN_DEBUG
"%s: features not supported for %s\n",
660 __func__
, dsp
->name
);
664 dsp_function(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
666 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
667 struct mISDNhead
*hh
;
672 hh
= mISDN_HEAD_P(skb
);
676 dsp
->data_pending
= 0;
677 /* trigger next hdlc frame, if any */
679 spin_lock_irqsave(&dsp_lock
, flags
);
681 schedule_work(&dsp
->workq
);
682 spin_unlock_irqrestore(&dsp_lock
, flags
);
691 if (dsp
->rx_is_off
) {
692 if (dsp_debug
& DEBUG_DSP_CORE
)
693 printk(KERN_DEBUG
"%s: rx-data during rx_off"
695 __func__
, dsp
->name
);
699 spin_lock_irqsave(&dsp_lock
, flags
);
700 dsp_cmx_hdlc(dsp
, skb
);
701 spin_unlock_irqrestore(&dsp_lock
, flags
);
702 if (dsp
->rx_disabled
) {
703 /* if receive is not allowed */
706 hh
->prim
= DL_DATA_IND
;
708 return dsp
->up
->send(dsp
->up
, skb
);
712 spin_lock_irqsave(&dsp_lock
, flags
);
714 /* decrypt if enabled */
716 dsp_bf_decrypt(dsp
, skb
->data
, skb
->len
);
718 if (dsp
->pipeline
.inuse
)
719 dsp_pipeline_process_rx(&dsp
->pipeline
, skb
->data
,
721 /* change volume if requested */
723 dsp_change_volume(skb
, dsp
->rx_volume
);
724 /* check if dtmf soft decoding is turned on */
725 if (dsp
->dtmf
.software
) {
726 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
727 skb
->len
, (dsp_options
& DSP_OPT_ULAW
) ? 1 : 0);
729 /* we need to process receive data if software */
730 if (dsp
->conf
&& dsp
->conf
->software
) {
731 /* process data from card at cmx */
732 dsp_cmx_receive(dsp
, skb
);
735 spin_unlock_irqrestore(&dsp_lock
, flags
);
737 /* send dtmf result, if any */
741 struct sk_buff
*nskb
;
742 if (dsp_debug
& DEBUG_DSP_DTMF
)
743 printk(KERN_DEBUG
"%s: digit"
744 "(%c) to layer %s\n",
745 __func__
, *digits
, dsp
->name
);
746 k
= *digits
| DTMF_TONE_VAL
;
747 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
748 MISDN_ID_ANY
, sizeof(int), &k
,
761 if (dsp
->rx_disabled
) {
762 /* if receive is not allowed */
765 hh
->prim
= DL_DATA_IND
;
767 return dsp
->up
->send(dsp
->up
, skb
);
769 case (PH_CONTROL_IND
):
770 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
771 printk(KERN_DEBUG
"%s: PH_CONTROL INDICATION "
772 "received: %x (len %d) %s\n", __func__
,
773 hh
->id
, skb
->len
, dsp
->name
);
775 case (DTMF_HFC_COEF
): /* getting coefficients */
776 if (!dsp
->dtmf
.hardware
) {
777 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
778 printk(KERN_DEBUG
"%s: ignoring DTMF "
779 "coefficients from HFC\n",
783 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
787 struct sk_buff
*nskb
;
788 if (dsp_debug
& DEBUG_DSP_DTMF
)
789 printk(KERN_DEBUG
"%s: digit"
790 "(%c) to layer %s\n",
791 __func__
, *digits
, dsp
->name
);
792 k
= *digits
| DTMF_TONE_VAL
;
793 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
794 MISDN_ID_ANY
, sizeof(int), &k
,
807 case (HFC_VOL_CHANGE_TX
): /* change volume */
808 if (skb
->len
!= sizeof(int)) {
812 spin_lock_irqsave(&dsp_lock
, flags
);
813 dsp
->tx_volume
= *((int *)skb
->data
);
814 if (dsp_debug
& DEBUG_DSP_CORE
)
815 printk(KERN_DEBUG
"%s: change tx volume to "
816 "%d\n", __func__
, dsp
->tx_volume
);
817 dsp_cmx_hardware(dsp
->conf
, dsp
);
818 dsp_dtmf_hardware(dsp
);
820 spin_unlock_irqrestore(&dsp_lock
, flags
);
823 if (dsp_debug
& DEBUG_DSP_CORE
)
824 printk(KERN_DEBUG
"%s: ctrl ind %x unhandled "
825 "%s\n", __func__
, hh
->id
, dsp
->name
);
829 case (PH_ACTIVATE_IND
):
830 case (PH_ACTIVATE_CNF
):
831 if (dsp_debug
& DEBUG_DSP_CORE
)
832 printk(KERN_DEBUG
"%s: b_channel is now active %s\n",
833 __func__
, dsp
->name
);
834 /* bchannel now active */
835 spin_lock_irqsave(&dsp_lock
, flags
);
837 dsp
->data_pending
= 0;
839 /* rx_W and rx_R will be adjusted on first frame */
842 memset(dsp
->rx_buff
, 0, sizeof(dsp
->rx_buff
));
843 dsp_cmx_hardware(dsp
->conf
, dsp
);
844 dsp_dtmf_hardware(dsp
);
846 spin_unlock_irqrestore(&dsp_lock
, flags
);
847 if (dsp_debug
& DEBUG_DSP_CORE
)
848 printk(KERN_DEBUG
"%s: done with activation, sending "
849 "confirm to user space. %s\n", __func__
,
851 /* send activation to upper layer */
852 hh
->prim
= DL_ESTABLISH_CNF
;
854 return dsp
->up
->send(dsp
->up
, skb
);
856 case (PH_DEACTIVATE_IND
):
857 case (PH_DEACTIVATE_CNF
):
858 if (dsp_debug
& DEBUG_DSP_CORE
)
859 printk(KERN_DEBUG
"%s: b_channel is now inactive %s\n",
860 __func__
, dsp
->name
);
861 /* bchannel now inactive */
862 spin_lock_irqsave(&dsp_lock
, flags
);
864 dsp
->data_pending
= 0;
865 dsp_cmx_hardware(dsp
->conf
, dsp
);
867 spin_unlock_irqrestore(&dsp_lock
, flags
);
868 hh
->prim
= DL_RELEASE_CNF
;
870 return dsp
->up
->send(dsp
->up
, skb
);
881 if (!dsp
->b_active
) {
885 hh
->prim
= PH_DATA_REQ
;
886 spin_lock_irqsave(&dsp_lock
, flags
);
887 skb_queue_tail(&dsp
->sendq
, skb
);
888 schedule_work(&dsp
->workq
);
889 spin_unlock_irqrestore(&dsp_lock
, flags
);
892 /* send data to tx-buffer (if no tone is played) */
893 if (!dsp
->tone
.tone
) {
894 spin_lock_irqsave(&dsp_lock
, flags
);
895 dsp_cmx_transmit(dsp
, skb
);
896 spin_unlock_irqrestore(&dsp_lock
, flags
);
899 case (PH_CONTROL_REQ
):
900 spin_lock_irqsave(&dsp_lock
, flags
);
901 ret
= dsp_control_req(dsp
, hh
, skb
);
902 spin_unlock_irqrestore(&dsp_lock
, flags
);
904 case (DL_ESTABLISH_REQ
):
905 case (PH_ACTIVATE_REQ
):
906 if (dsp_debug
& DEBUG_DSP_CORE
)
907 printk(KERN_DEBUG
"%s: activating b_channel %s\n",
908 __func__
, dsp
->name
);
909 if (dsp
->dtmf
.hardware
|| dsp
->dtmf
.software
)
910 dsp_dtmf_goertzel_init(dsp
);
912 /* enable fill_empty feature */
913 if (dsp
->features_fill_empty
)
915 /* send ph_activate */
916 hh
->prim
= PH_ACTIVATE_REQ
;
918 return ch
->recv(ch
->peer
, skb
);
920 case (DL_RELEASE_REQ
):
921 case (PH_DEACTIVATE_REQ
):
922 if (dsp_debug
& DEBUG_DSP_CORE
)
923 printk(KERN_DEBUG
"%s: releasing b_channel %s\n",
924 __func__
, dsp
->name
);
925 spin_lock_irqsave(&dsp_lock
, flags
);
927 dsp
->tone
.hardware
= 0;
928 dsp
->tone
.software
= 0;
929 if (timer_pending(&dsp
->tone
.tl
))
930 del_timer(&dsp
->tone
.tl
);
932 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be
934 skb_queue_purge(&dsp
->sendq
);
935 spin_unlock_irqrestore(&dsp_lock
, flags
);
936 hh
->prim
= PH_DEACTIVATE_REQ
;
938 return ch
->recv(ch
->peer
, skb
);
941 if (dsp_debug
& DEBUG_DSP_CORE
)
942 printk(KERN_DEBUG
"%s: msg %x unhandled %s\n",
943 __func__
, hh
->prim
, dsp
->name
);
952 dsp_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
954 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
958 if (debug
& DEBUG_DSP_CTRL
)
959 printk(KERN_DEBUG
"%s:(%x)\n", __func__
, cmd
);
966 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
968 /* wait until workqueue has finished,
969 * must lock here, or we may hit send-process currently
971 spin_lock_irqsave(&dsp_lock
, flags
);
973 spin_unlock_irqrestore(&dsp_lock
, flags
);
974 /* MUST not be locked, because it waits until queue is done. */
975 cancel_work_sync(&dsp
->workq
);
976 spin_lock_irqsave(&dsp_lock
, flags
);
977 if (timer_pending(&dsp
->tone
.tl
))
978 del_timer(&dsp
->tone
.tl
);
979 skb_queue_purge(&dsp
->sendq
);
980 if (dsp_debug
& DEBUG_DSP_CTRL
)
981 printk(KERN_DEBUG
"%s: releasing member %s\n",
982 __func__
, dsp
->name
);
984 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be called
986 dsp_pipeline_destroy(&dsp
->pipeline
);
988 if (dsp_debug
& DEBUG_DSP_CTRL
)
989 printk(KERN_DEBUG
"%s: remove & destroy object %s\n",
990 __func__
, dsp
->name
);
991 list_del(&dsp
->list
);
992 spin_unlock_irqrestore(&dsp_lock
, flags
);
994 if (dsp_debug
& DEBUG_DSP_CTRL
)
995 printk(KERN_DEBUG
"%s: dsp instance released\n",
998 module_put(THIS_MODULE
);
1005 dsp_send_bh(struct work_struct
*work
)
1007 struct dsp
*dsp
= container_of(work
, struct dsp
, workq
);
1008 struct sk_buff
*skb
;
1009 struct mISDNhead
*hh
;
1011 if (dsp
->hdlc
&& dsp
->data_pending
)
1012 return; /* wait until data has been acknowledged */
1014 /* send queued data */
1015 while ((skb
= skb_dequeue(&dsp
->sendq
))) {
1016 /* in locked date, we must have still data in queue */
1017 if (dsp
->data_pending
) {
1018 if (dsp_debug
& DEBUG_DSP_CORE
)
1019 printk(KERN_DEBUG
"%s: fifo full %s, this is "
1020 "no bug!\n", __func__
, dsp
->name
);
1021 /* flush transparent data, if not acked */
1025 hh
= mISDN_HEAD_P(skb
);
1026 if (hh
->prim
== DL_DATA_REQ
) {
1027 /* send packet up */
1029 if (dsp
->up
->send(dsp
->up
, skb
))
1034 /* send packet down */
1036 dsp
->data_pending
= 1;
1037 if (dsp
->ch
.recv(dsp
->ch
.peer
, skb
)) {
1039 dsp
->data_pending
= 0;
1048 dspcreate(struct channel_req
*crq
)
1053 if (crq
->protocol
!= ISDN_P_B_L2DSP
1054 && crq
->protocol
!= ISDN_P_B_L2DSPHDLC
)
1055 return -EPROTONOSUPPORT
;
1056 ndsp
= vzalloc(sizeof(struct dsp
));
1058 printk(KERN_ERR
"%s: vmalloc struct dsp failed\n", __func__
);
1061 if (dsp_debug
& DEBUG_DSP_CTRL
)
1062 printk(KERN_DEBUG
"%s: creating new dsp instance\n", __func__
);
1064 /* default enabled */
1065 INIT_WORK(&ndsp
->workq
, (void *)dsp_send_bh
);
1066 skb_queue_head_init(&ndsp
->sendq
);
1067 ndsp
->ch
.send
= dsp_function
;
1068 ndsp
->ch
.ctrl
= dsp_ctrl
;
1070 crq
->ch
= &ndsp
->ch
;
1071 if (crq
->protocol
== ISDN_P_B_L2DSP
) {
1072 crq
->protocol
= ISDN_P_B_RAW
;
1075 crq
->protocol
= ISDN_P_B_HDLC
;
1078 if (!try_module_get(THIS_MODULE
))
1079 printk(KERN_WARNING
"%s:cannot get module\n",
1082 sprintf(ndsp
->name
, "DSP_C%x(0x%p)",
1083 ndsp
->up
->st
->dev
->id
+ 1, ndsp
);
1084 /* set frame size to start */
1085 ndsp
->features
.hfc_id
= -1; /* current PCM id */
1086 ndsp
->features
.pcm_id
= -1; /* current PCM id */
1087 ndsp
->pcm_slot_rx
= -1; /* current CPM slot */
1088 ndsp
->pcm_slot_tx
= -1;
1089 ndsp
->pcm_bank_rx
= -1;
1090 ndsp
->pcm_bank_tx
= -1;
1091 ndsp
->hfc_conf
= -1; /* current conference number */
1092 /* set tone timer */
1093 timer_setup(&ndsp
->tone
.tl
, dsp_tone_timeout
, 0);
1095 if (dtmfthreshold
< 20 || dtmfthreshold
> 500)
1096 dtmfthreshold
= 200;
1097 ndsp
->dtmf
.treshold
= dtmfthreshold
* 10000;
1099 /* init pipeline append to list */
1100 spin_lock_irqsave(&dsp_lock
, flags
);
1101 dsp_pipeline_init(&ndsp
->pipeline
);
1102 list_add_tail(&ndsp
->list
, &dsp_ilist
);
1103 spin_unlock_irqrestore(&dsp_lock
, flags
);
1109 static struct Bprotocol DSP
= {
1110 .Bprotocols
= (1 << (ISDN_P_B_L2DSP
& ISDN_P_B_MASK
))
1111 | (1 << (ISDN_P_B_L2DSPHDLC
& ISDN_P_B_MASK
)),
1116 static int __init
dsp_init(void)
1121 printk(KERN_INFO
"DSP module %s\n", mISDN_dsp_revision
);
1123 dsp_options
= options
;
1126 /* set packet size */
1129 if (dsp_poll
> MAX_POLL
) {
1130 printk(KERN_ERR
"%s: Wrong poll value (%d), use %d "
1131 "maximum.\n", __func__
, poll
, MAX_POLL
);
1136 printk(KERN_ERR
"%s: Wrong poll value (%d), use 8 "
1137 "minimum.\n", __func__
, dsp_poll
);
1141 dsp_tics
= poll
* HZ
/ 8000;
1142 if (dsp_tics
* 8000 != poll
* HZ
) {
1143 printk(KERN_INFO
"mISDN_dsp: Cannot clock every %d "
1144 "samples (0,125 ms). It is not a multiple of "
1145 "%d HZ.\n", poll
, HZ
);
1151 while (poll
<= MAX_POLL
) {
1152 tics
= (poll
* HZ
) / 8000;
1153 if (tics
* 8000 == poll
* HZ
) {
1162 if (dsp_poll
== 0) {
1163 printk(KERN_INFO
"mISDN_dsp: There is no multiple of kernel "
1164 "clock that equals exactly the duration of 8-256 "
1165 "samples. (Choose kernel clock speed like 100, 250, "
1170 printk(KERN_INFO
"mISDN_dsp: DSP clocks every %d samples. This equals "
1171 "%d jiffies.\n", dsp_poll
, dsp_tics
);
1173 spin_lock_init(&dsp_lock
);
1174 INIT_LIST_HEAD(&dsp_ilist
);
1175 INIT_LIST_HEAD(&conf_ilist
);
1177 /* init conversion tables */
1178 dsp_audio_generate_law_tables();
1179 dsp_silence
= (dsp_options
& DSP_OPT_ULAW
) ? 0xff : 0x2a;
1180 dsp_audio_law_to_s32
= (dsp_options
& DSP_OPT_ULAW
) ?
1181 dsp_audio_ulaw_to_s32
: dsp_audio_alaw_to_s32
;
1182 dsp_audio_generate_s2law_table();
1183 dsp_audio_generate_seven();
1184 dsp_audio_generate_mix_table();
1185 if (dsp_options
& DSP_OPT_ULAW
)
1186 dsp_audio_generate_ulaw_samples();
1187 dsp_audio_generate_volume_changes();
1189 err
= dsp_pipeline_module_init();
1191 printk(KERN_ERR
"mISDN_dsp: Can't initialize pipeline, "
1192 "error(%d)\n", err
);
1196 err
= mISDN_register_Bprotocol(&DSP
);
1198 printk(KERN_ERR
"Can't register %s error(%d)\n", DSP
.name
, err
);
1202 /* set sample timer */
1203 timer_setup(&dsp_spl_tl
, (void *)dsp_cmx_send
, 0);
1204 dsp_spl_tl
.expires
= jiffies
+ dsp_tics
;
1205 dsp_spl_jiffies
= dsp_spl_tl
.expires
;
1206 add_timer(&dsp_spl_tl
);
1212 static void __exit
dsp_cleanup(void)
1214 mISDN_unregister_Bprotocol(&DSP
);
1216 del_timer_sync(&dsp_spl_tl
);
1218 if (!list_empty(&dsp_ilist
)) {
1219 printk(KERN_ERR
"mISDN_dsp: Audio DSP object inst list not "
1222 if (!list_empty(&conf_ilist
)) {
1223 printk(KERN_ERR
"mISDN_dsp: Conference list not empty. Not "
1224 "all memory freed.\n");
1227 dsp_pipeline_module_exit();
1230 module_init(dsp_init
);
1231 module_exit(dsp_cleanup
);