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_DESCRIPTION("mISDN driver for Digital Audio Processing of transparent data");
176 MODULE_LICENSE("GPL");
178 /*int spinnest = 0;*/
180 DEFINE_SPINLOCK(dsp_lock
); /* global dsp lock */
181 LIST_HEAD(dsp_ilist
);
182 LIST_HEAD(conf_ilist
);
185 int dsp_poll
, dsp_tics
;
187 /* check if rx may be turned off or must be turned on */
189 dsp_rx_off_member(struct dsp
*dsp
)
191 struct mISDN_ctrl_req cq
;
194 memset(&cq
, 0, sizeof(cq
));
196 if (!dsp
->features_rx_off
)
200 if (!dsp
->rx_disabled
)
203 else if (dsp
->dtmf
.software
)
205 /* echo in software */
206 else if (dsp
->echo
.software
)
208 /* bridge in software */
209 else if (dsp
->conf
&& dsp
->conf
->software
)
211 /* data is not required by user space and not required
212 * for echo dtmf detection, soft-echo, soft-bridging */
214 if (rx_off
== dsp
->rx_is_off
)
218 if (dsp_debug
& DEBUG_DSP_CORE
)
219 printk(KERN_DEBUG
"%s: no peer, no rx_off\n",
223 cq
.op
= MISDN_CTRL_RX_OFF
;
225 if (dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
)) {
226 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
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
);
236 dsp_rx_off(struct dsp
*dsp
)
238 struct dsp_conf_member
*member
;
240 if (dsp_options
& DSP_OPT_NOHARDWARE
)
245 dsp_rx_off_member(dsp
);
248 /* check all members in conf */
249 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
250 dsp_rx_off_member(member
->dsp
);
254 /* enable "fill empty" feature */
256 dsp_fill_empty(struct dsp
*dsp
)
258 struct mISDN_ctrl_req cq
;
260 memset(&cq
, 0, sizeof(cq
));
263 if (dsp_debug
& DEBUG_DSP_CORE
)
264 printk(KERN_DEBUG
"%s: no peer, no fill_empty\n",
268 cq
.op
= MISDN_CTRL_FILL_EMPTY
;
271 if (dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
)) {
272 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
276 if (dsp_debug
& DEBUG_DSP_CORE
)
277 printk(KERN_DEBUG
"%s: %s set fill_empty = 1\n",
278 __func__
, dsp
->name
);
282 dsp_control_req(struct dsp
*dsp
, struct mISDNhead
*hh
, struct sk_buff
*skb
)
284 struct sk_buff
*nskb
;
290 if (skb
->len
< sizeof(int)) {
291 printk(KERN_ERR
"%s: PH_CONTROL message too short\n", __func__
);
294 cont
= *((int *)skb
->data
);
295 len
= skb
->len
- sizeof(int);
296 data
= skb
->data
+ sizeof(int);
299 case DTMF_TONE_START
: /* turn on DTMF */
304 if (dsp_debug
& DEBUG_DSP_CORE
)
305 printk(KERN_DEBUG
"%s: start dtmf\n", __func__
);
306 if (len
== sizeof(int)) {
307 if (dsp_debug
& DEBUG_DSP_CORE
)
308 printk(KERN_NOTICE
"changing DTMF Threshold "
309 "to %d\n", *((int *)data
));
310 dsp
->dtmf
.treshold
= (*(int *)data
) * 10000;
312 dsp
->dtmf
.enable
= 1;
314 dsp_dtmf_goertzel_init(dsp
);
316 /* check dtmf hardware */
317 dsp_dtmf_hardware(dsp
);
320 case DTMF_TONE_STOP
: /* turn off DTMF */
321 if (dsp_debug
& DEBUG_DSP_CORE
)
322 printk(KERN_DEBUG
"%s: stop dtmf\n", __func__
);
323 dsp
->dtmf
.enable
= 0;
324 dsp
->dtmf
.hardware
= 0;
325 dsp
->dtmf
.software
= 0;
327 case DSP_CONF_JOIN
: /* join / update conference */
328 if (len
< sizeof(int)) {
332 if (*((u32
*)data
) == 0)
334 if (dsp_debug
& DEBUG_DSP_CORE
)
335 printk(KERN_DEBUG
"%s: join conference %d\n",
336 __func__
, *((u32
*)data
));
337 ret
= dsp_cmx_conf(dsp
, *((u32
*)data
));
338 /* dsp_cmx_hardware will also be called here */
340 if (dsp_debug
& DEBUG_DSP_CMX
)
343 case DSP_CONF_SPLIT
: /* remove from conference */
345 if (dsp_debug
& DEBUG_DSP_CORE
)
346 printk(KERN_DEBUG
"%s: release conference\n", __func__
);
347 ret
= dsp_cmx_conf(dsp
, 0);
348 /* dsp_cmx_hardware will also be called here */
349 if (dsp_debug
& DEBUG_DSP_CMX
)
353 case DSP_TONE_PATT_ON
: /* play tone */
358 if (len
< sizeof(int)) {
362 if (dsp_debug
& DEBUG_DSP_CORE
)
363 printk(KERN_DEBUG
"%s: turn tone 0x%x on\n",
364 __func__
, *((int *)skb
->data
));
365 ret
= dsp_tone(dsp
, *((int *)data
));
367 dsp_cmx_hardware(dsp
->conf
, dsp
);
373 case DSP_TONE_PATT_OFF
: /* stop tone */
378 if (dsp_debug
& DEBUG_DSP_CORE
)
379 printk(KERN_DEBUG
"%s: turn tone off\n", __func__
);
381 dsp_cmx_hardware(dsp
->conf
, dsp
);
383 /* reset tx buffers (user space data) */
388 case DSP_VOL_CHANGE_TX
: /* change volume */
393 if (len
< sizeof(int)) {
397 dsp
->tx_volume
= *((int *)data
);
398 if (dsp_debug
& DEBUG_DSP_CORE
)
399 printk(KERN_DEBUG
"%s: change tx vol to %d\n",
400 __func__
, dsp
->tx_volume
);
401 dsp_cmx_hardware(dsp
->conf
, dsp
);
402 dsp_dtmf_hardware(dsp
);
405 case DSP_VOL_CHANGE_RX
: /* change volume */
410 if (len
< sizeof(int)) {
414 dsp
->rx_volume
= *((int *)data
);
415 if (dsp_debug
& DEBUG_DSP_CORE
)
416 printk(KERN_DEBUG
"%s: change rx vol to %d\n",
417 __func__
, dsp
->tx_volume
);
418 dsp_cmx_hardware(dsp
->conf
, dsp
);
419 dsp_dtmf_hardware(dsp
);
422 case DSP_ECHO_ON
: /* enable echo */
423 dsp
->echo
.software
= 1; /* soft echo */
424 if (dsp_debug
& DEBUG_DSP_CORE
)
425 printk(KERN_DEBUG
"%s: enable cmx-echo\n", __func__
);
426 dsp_cmx_hardware(dsp
->conf
, dsp
);
428 if (dsp_debug
& DEBUG_DSP_CMX
)
431 case DSP_ECHO_OFF
: /* disable echo */
432 dsp
->echo
.software
= 0;
433 dsp
->echo
.hardware
= 0;
434 if (dsp_debug
& DEBUG_DSP_CORE
)
435 printk(KERN_DEBUG
"%s: disable cmx-echo\n", __func__
);
436 dsp_cmx_hardware(dsp
->conf
, dsp
);
438 if (dsp_debug
& DEBUG_DSP_CMX
)
441 case DSP_RECEIVE_ON
: /* enable receive to user space */
442 if (dsp_debug
& DEBUG_DSP_CORE
)
443 printk(KERN_DEBUG
"%s: enable receive to user "
444 "space\n", __func__
);
445 dsp
->rx_disabled
= 0;
448 case DSP_RECEIVE_OFF
: /* disable receive to user space */
449 if (dsp_debug
& DEBUG_DSP_CORE
)
450 printk(KERN_DEBUG
"%s: disable receive to "
451 "user space\n", __func__
);
452 dsp
->rx_disabled
= 1;
455 case DSP_MIX_ON
: /* enable mixing of tx data */
460 if (dsp_debug
& DEBUG_DSP_CORE
)
461 printk(KERN_DEBUG
"%s: enable mixing of "
462 "tx-data with conf members\n", __func__
);
464 dsp_cmx_hardware(dsp
->conf
, dsp
);
466 if (dsp_debug
& DEBUG_DSP_CMX
)
469 case DSP_MIX_OFF
: /* disable mixing of tx data */
474 if (dsp_debug
& DEBUG_DSP_CORE
)
475 printk(KERN_DEBUG
"%s: disable mixing of "
476 "tx-data with conf members\n", __func__
);
478 dsp_cmx_hardware(dsp
->conf
, dsp
);
480 if (dsp_debug
& DEBUG_DSP_CMX
)
483 case DSP_TXDATA_ON
: /* enable txdata */
485 if (dsp_debug
& DEBUG_DSP_CORE
)
486 printk(KERN_DEBUG
"%s: enable tx-data\n", __func__
);
487 dsp_cmx_hardware(dsp
->conf
, dsp
);
489 if (dsp_debug
& DEBUG_DSP_CMX
)
492 case DSP_TXDATA_OFF
: /* disable txdata */
494 if (dsp_debug
& DEBUG_DSP_CORE
)
495 printk(KERN_DEBUG
"%s: disable tx-data\n", __func__
);
496 dsp_cmx_hardware(dsp
->conf
, dsp
);
498 if (dsp_debug
& DEBUG_DSP_CMX
)
501 case DSP_DELAY
: /* use delay algorithm instead of dynamic
507 if (len
< sizeof(int)) {
511 dsp
->cmx_delay
= (*((int *)data
)) << 3;
512 /* milliseconds to samples */
513 if (dsp
->cmx_delay
>= (CMX_BUFF_HALF
>> 1))
514 /* clip to half of maximum usable buffer
515 (half of half buffer) */
516 dsp
->cmx_delay
= (CMX_BUFF_HALF
>> 1) - 1;
517 if (dsp_debug
& DEBUG_DSP_CORE
)
518 printk(KERN_DEBUG
"%s: use delay algorithm to "
519 "compensate jitter (%d samples)\n",
520 __func__
, dsp
->cmx_delay
);
522 case DSP_JITTER
: /* use dynamic jitter algorithm instead of
529 if (dsp_debug
& DEBUG_DSP_CORE
)
530 printk(KERN_DEBUG
"%s: use jitter algorithm to "
531 "compensate jitter\n", __func__
);
533 case DSP_TX_DEJITTER
: /* use dynamic jitter algorithm for tx-buffer */
538 dsp
->tx_dejitter
= 1;
539 if (dsp_debug
& DEBUG_DSP_CORE
)
540 printk(KERN_DEBUG
"%s: use dejitter on TX "
541 "buffer\n", __func__
);
543 case DSP_TX_DEJ_OFF
: /* use tx-buffer without dejittering*/
548 dsp
->tx_dejitter
= 0;
549 if (dsp_debug
& DEBUG_DSP_CORE
)
550 printk(KERN_DEBUG
"%s: use TX buffer without "
551 "dejittering\n", __func__
);
553 case DSP_PIPELINE_CFG
:
558 if (len
> 0 && ((char *)data
)[len
- 1]) {
559 printk(KERN_DEBUG
"%s: pipeline config string "
560 "is not NULL terminated!\n", __func__
);
563 dsp
->pipeline
.inuse
= 1;
564 dsp_cmx_hardware(dsp
->conf
, dsp
);
565 ret
= dsp_pipeline_build(&dsp
->pipeline
,
566 len
> 0 ? data
: NULL
);
567 dsp_cmx_hardware(dsp
->conf
, dsp
);
571 case DSP_BF_ENABLE_KEY
: /* turn blowfish on */
576 if (len
< 4 || len
> 56) {
580 if (dsp_debug
& DEBUG_DSP_CORE
)
581 printk(KERN_DEBUG
"%s: turn blowfish on (key "
582 "not shown)\n", __func__
);
583 ret
= dsp_bf_init(dsp
, (u8
*)data
, len
);
586 cont
= DSP_BF_ACCEPT
;
588 cont
= DSP_BF_REJECT
;
589 /* send indication if it worked to set it */
590 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
, MISDN_ID_ANY
,
591 sizeof(int), &cont
, GFP_ATOMIC
);
594 if (dsp
->up
->send(dsp
->up
, nskb
))
600 dsp_cmx_hardware(dsp
->conf
, dsp
);
601 dsp_dtmf_hardware(dsp
);
605 case DSP_BF_DISABLE
: /* turn blowfish off */
610 if (dsp_debug
& DEBUG_DSP_CORE
)
611 printk(KERN_DEBUG
"%s: turn blowfish off\n", __func__
);
613 dsp_cmx_hardware(dsp
->conf
, dsp
);
614 dsp_dtmf_hardware(dsp
);
618 if (dsp_debug
& DEBUG_DSP_CORE
)
619 printk(KERN_DEBUG
"%s: ctrl req %x unhandled\n",
627 get_features(struct mISDNchannel
*ch
)
629 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
630 struct mISDN_ctrl_req cq
;
633 if (dsp_debug
& DEBUG_DSP_CORE
)
634 printk(KERN_DEBUG
"%s: no peer, no features\n",
638 memset(&cq
, 0, sizeof(cq
));
639 cq
.op
= MISDN_CTRL_GETOP
;
640 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
) < 0) {
641 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
645 if (cq
.op
& MISDN_CTRL_RX_OFF
)
646 dsp
->features_rx_off
= 1;
647 if (cq
.op
& MISDN_CTRL_FILL_EMPTY
)
648 dsp
->features_fill_empty
= 1;
649 if (dsp_options
& DSP_OPT_NOHARDWARE
)
651 if ((cq
.op
& MISDN_CTRL_HW_FEATURES_OP
)) {
652 cq
.op
= MISDN_CTRL_HW_FEATURES
;
653 *((u_long
*)&cq
.p1
) = (u_long
)&dsp
->features
;
654 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
)) {
655 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
659 if (dsp_debug
& DEBUG_DSP_CORE
)
660 printk(KERN_DEBUG
"%s: features not supported for %s\n",
661 __func__
, dsp
->name
);
665 dsp_function(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
667 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
668 struct mISDNhead
*hh
;
673 hh
= mISDN_HEAD_P(skb
);
677 dsp
->data_pending
= 0;
678 /* trigger next hdlc frame, if any */
680 spin_lock_irqsave(&dsp_lock
, flags
);
682 schedule_work(&dsp
->workq
);
683 spin_unlock_irqrestore(&dsp_lock
, flags
);
692 if (dsp
->rx_is_off
) {
693 if (dsp_debug
& DEBUG_DSP_CORE
)
694 printk(KERN_DEBUG
"%s: rx-data during rx_off"
696 __func__
, dsp
->name
);
700 spin_lock_irqsave(&dsp_lock
, flags
);
701 dsp_cmx_hdlc(dsp
, skb
);
702 spin_unlock_irqrestore(&dsp_lock
, flags
);
703 if (dsp
->rx_disabled
) {
704 /* if receive is not allowed */
707 hh
->prim
= DL_DATA_IND
;
709 return dsp
->up
->send(dsp
->up
, skb
);
713 spin_lock_irqsave(&dsp_lock
, flags
);
715 /* decrypt if enabled */
717 dsp_bf_decrypt(dsp
, skb
->data
, skb
->len
);
719 if (dsp
->pipeline
.inuse
)
720 dsp_pipeline_process_rx(&dsp
->pipeline
, skb
->data
,
722 /* change volume if requested */
724 dsp_change_volume(skb
, dsp
->rx_volume
);
725 /* check if dtmf soft decoding is turned on */
726 if (dsp
->dtmf
.software
) {
727 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
728 skb
->len
, (dsp_options
& DSP_OPT_ULAW
) ? 1 : 0);
730 /* we need to process receive data if software */
731 if (dsp
->conf
&& dsp
->conf
->software
) {
732 /* process data from card at cmx */
733 dsp_cmx_receive(dsp
, skb
);
736 spin_unlock_irqrestore(&dsp_lock
, flags
);
738 /* send dtmf result, if any */
742 struct sk_buff
*nskb
;
743 if (dsp_debug
& DEBUG_DSP_DTMF
)
744 printk(KERN_DEBUG
"%s: digit"
745 "(%c) to layer %s\n",
746 __func__
, *digits
, dsp
->name
);
747 k
= *digits
| DTMF_TONE_VAL
;
748 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
749 MISDN_ID_ANY
, sizeof(int), &k
,
762 if (dsp
->rx_disabled
) {
763 /* if receive is not allowed */
766 hh
->prim
= DL_DATA_IND
;
768 return dsp
->up
->send(dsp
->up
, skb
);
770 case (PH_CONTROL_IND
):
771 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
772 printk(KERN_DEBUG
"%s: PH_CONTROL INDICATION "
773 "received: %x (len %d) %s\n", __func__
,
774 hh
->id
, skb
->len
, dsp
->name
);
776 case (DTMF_HFC_COEF
): /* getting coefficients */
777 if (!dsp
->dtmf
.hardware
) {
778 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
779 printk(KERN_DEBUG
"%s: ignoring DTMF "
780 "coefficients from HFC\n",
784 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
788 struct sk_buff
*nskb
;
789 if (dsp_debug
& DEBUG_DSP_DTMF
)
790 printk(KERN_DEBUG
"%s: digit"
791 "(%c) to layer %s\n",
792 __func__
, *digits
, dsp
->name
);
793 k
= *digits
| DTMF_TONE_VAL
;
794 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
795 MISDN_ID_ANY
, sizeof(int), &k
,
808 case (HFC_VOL_CHANGE_TX
): /* change volume */
809 if (skb
->len
!= sizeof(int)) {
813 spin_lock_irqsave(&dsp_lock
, flags
);
814 dsp
->tx_volume
= *((int *)skb
->data
);
815 if (dsp_debug
& DEBUG_DSP_CORE
)
816 printk(KERN_DEBUG
"%s: change tx volume to "
817 "%d\n", __func__
, dsp
->tx_volume
);
818 dsp_cmx_hardware(dsp
->conf
, dsp
);
819 dsp_dtmf_hardware(dsp
);
821 spin_unlock_irqrestore(&dsp_lock
, flags
);
824 if (dsp_debug
& DEBUG_DSP_CORE
)
825 printk(KERN_DEBUG
"%s: ctrl ind %x unhandled "
826 "%s\n", __func__
, hh
->id
, dsp
->name
);
830 case (PH_ACTIVATE_IND
):
831 case (PH_ACTIVATE_CNF
):
832 if (dsp_debug
& DEBUG_DSP_CORE
)
833 printk(KERN_DEBUG
"%s: b_channel is now active %s\n",
834 __func__
, dsp
->name
);
835 /* bchannel now active */
836 spin_lock_irqsave(&dsp_lock
, flags
);
838 dsp
->data_pending
= 0;
840 /* rx_W and rx_R will be adjusted on first frame */
843 memset(dsp
->rx_buff
, 0, sizeof(dsp
->rx_buff
));
844 dsp_cmx_hardware(dsp
->conf
, dsp
);
845 dsp_dtmf_hardware(dsp
);
847 spin_unlock_irqrestore(&dsp_lock
, flags
);
848 if (dsp_debug
& DEBUG_DSP_CORE
)
849 printk(KERN_DEBUG
"%s: done with activation, sending "
850 "confirm to user space. %s\n", __func__
,
852 /* send activation to upper layer */
853 hh
->prim
= DL_ESTABLISH_CNF
;
855 return dsp
->up
->send(dsp
->up
, skb
);
857 case (PH_DEACTIVATE_IND
):
858 case (PH_DEACTIVATE_CNF
):
859 if (dsp_debug
& DEBUG_DSP_CORE
)
860 printk(KERN_DEBUG
"%s: b_channel is now inactive %s\n",
861 __func__
, dsp
->name
);
862 /* bchannel now inactive */
863 spin_lock_irqsave(&dsp_lock
, flags
);
865 dsp
->data_pending
= 0;
866 dsp_cmx_hardware(dsp
->conf
, dsp
);
868 spin_unlock_irqrestore(&dsp_lock
, flags
);
869 hh
->prim
= DL_RELEASE_CNF
;
871 return dsp
->up
->send(dsp
->up
, skb
);
882 if (!dsp
->b_active
) {
886 hh
->prim
= PH_DATA_REQ
;
887 spin_lock_irqsave(&dsp_lock
, flags
);
888 skb_queue_tail(&dsp
->sendq
, skb
);
889 schedule_work(&dsp
->workq
);
890 spin_unlock_irqrestore(&dsp_lock
, flags
);
893 /* send data to tx-buffer (if no tone is played) */
894 if (!dsp
->tone
.tone
) {
895 spin_lock_irqsave(&dsp_lock
, flags
);
896 dsp_cmx_transmit(dsp
, skb
);
897 spin_unlock_irqrestore(&dsp_lock
, flags
);
900 case (PH_CONTROL_REQ
):
901 spin_lock_irqsave(&dsp_lock
, flags
);
902 ret
= dsp_control_req(dsp
, hh
, skb
);
903 spin_unlock_irqrestore(&dsp_lock
, flags
);
905 case (DL_ESTABLISH_REQ
):
906 case (PH_ACTIVATE_REQ
):
907 if (dsp_debug
& DEBUG_DSP_CORE
)
908 printk(KERN_DEBUG
"%s: activating b_channel %s\n",
909 __func__
, dsp
->name
);
910 if (dsp
->dtmf
.hardware
|| dsp
->dtmf
.software
)
911 dsp_dtmf_goertzel_init(dsp
);
913 /* enable fill_empty feature */
914 if (dsp
->features_fill_empty
)
916 /* send ph_activate */
917 hh
->prim
= PH_ACTIVATE_REQ
;
919 return ch
->recv(ch
->peer
, skb
);
921 case (DL_RELEASE_REQ
):
922 case (PH_DEACTIVATE_REQ
):
923 if (dsp_debug
& DEBUG_DSP_CORE
)
924 printk(KERN_DEBUG
"%s: releasing b_channel %s\n",
925 __func__
, dsp
->name
);
926 spin_lock_irqsave(&dsp_lock
, flags
);
928 dsp
->tone
.hardware
= 0;
929 dsp
->tone
.software
= 0;
930 if (timer_pending(&dsp
->tone
.tl
))
931 del_timer(&dsp
->tone
.tl
);
933 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be
935 skb_queue_purge(&dsp
->sendq
);
936 spin_unlock_irqrestore(&dsp_lock
, flags
);
937 hh
->prim
= PH_DEACTIVATE_REQ
;
939 return ch
->recv(ch
->peer
, skb
);
942 if (dsp_debug
& DEBUG_DSP_CORE
)
943 printk(KERN_DEBUG
"%s: msg %x unhandled %s\n",
944 __func__
, hh
->prim
, dsp
->name
);
953 dsp_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
955 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 /* init conversion tables */
1174 dsp_audio_generate_law_tables();
1175 dsp_silence
= (dsp_options
& DSP_OPT_ULAW
) ? 0xff : 0x2a;
1176 dsp_audio_law_to_s32
= (dsp_options
& DSP_OPT_ULAW
) ?
1177 dsp_audio_ulaw_to_s32
: dsp_audio_alaw_to_s32
;
1178 dsp_audio_generate_s2law_table();
1179 dsp_audio_generate_seven();
1180 dsp_audio_generate_mix_table();
1181 if (dsp_options
& DSP_OPT_ULAW
)
1182 dsp_audio_generate_ulaw_samples();
1183 dsp_audio_generate_volume_changes();
1185 err
= dsp_pipeline_module_init();
1187 printk(KERN_ERR
"mISDN_dsp: Can't initialize pipeline, "
1188 "error(%d)\n", err
);
1192 err
= mISDN_register_Bprotocol(&DSP
);
1194 printk(KERN_ERR
"Can't register %s error(%d)\n", DSP
.name
, err
);
1198 /* set sample timer */
1199 timer_setup(&dsp_spl_tl
, dsp_cmx_send
, 0);
1200 dsp_spl_tl
.expires
= jiffies
+ dsp_tics
;
1201 dsp_spl_jiffies
= dsp_spl_tl
.expires
;
1202 add_timer(&dsp_spl_tl
);
1208 static void __exit
dsp_cleanup(void)
1210 mISDN_unregister_Bprotocol(&DSP
);
1212 del_timer_sync(&dsp_spl_tl
);
1214 if (!list_empty(&dsp_ilist
)) {
1215 printk(KERN_ERR
"mISDN_dsp: Audio DSP object inst list not "
1218 if (!list_empty(&conf_ilist
)) {
1219 printk(KERN_ERR
"mISDN_dsp: Conference list not empty. Not "
1220 "all memory freed.\n");
1223 dsp_pipeline_module_exit();
1226 module_init(dsp_init
);
1227 module_exit(dsp_cleanup
);