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
7 * For changes and modifications please read
8 * ../../../Documentation/isdn/mISDN.cert
10 * Thanks to Karsten Keil (great drivers)
11 * Cologne Chip (great chips)
14 * Real-time tone generation
16 * Real-time cross-connection and conferrence
17 * Compensate jitter due to system load and hardware fault.
18 * All features are done in kernel space and will be realized
19 * using hardware, if available and supported by chip set.
20 * Blowfish encryption/decryption
25 * The dsp module provides layer 2 for b-channels (64kbit). It provides
26 * transparent audio forwarding with special digital signal processing:
28 * - (1) generation of tones
29 * - (2) detection of dtmf tones
30 * - (3) crossconnecting and conferences (clocking)
31 * - (4) echo generation for delay test
32 * - (5) volume control
33 * - (6) disable receive data
35 * - (8) encryption/decryption
39 * ------upper layer------
43 * +-----+-------------+-----+
50 * |+---------+| +----+----+
53 * || Tones || | DTMF |
56 * |+----+----+| +----+----+
60 * +----+----+ +----+----+
63 * |TX Volume| |RX Volume|
66 * +----+----+ +----+----+
70 * +----+-------------+----+
73 * | Pipeline Processing |
76 * +----+-------------+----+
80 * +----+----+ +----+----+
83 * | Encrypt | | Decrypt |
86 * +----+----+ +----+----+
90 * ------card layer------
93 * Above you can see the logical data flow. If software is used to do the
94 * process, it is actually the real data flow. If hardware is used, data
95 * may not flow, but hardware commands to the card, to provide the data flow
98 * NOTE: The channel must be activated in order to make dsp work, even if
99 * no data flow to the upper layer is intended. Activation can be done
100 * after and before controlling the setting using PH_CONTROL requests.
102 * DTMF: Will be detected by hardware if possible. It is done before CMX
105 * Tones: Will be generated via software if endless looped audio fifos are
106 * not supported by hardware. Tones will override all data from CMX.
107 * It is not required to join a conference to use tones at any time.
109 * CMX: Is transparent when not used. When it is used, it will do
110 * crossconnections and conferences via software if not possible through
111 * hardware. If hardware capability is available, hardware is used.
113 * Echo: Is generated by CMX and is used to check performance of hard and
116 * The CMX has special functions for conferences with one, two and more
117 * members. It will allow different types of data flow. Receive and transmit
118 * data to/form upper layer may be swithed on/off individually without loosing
119 * features of CMX, Tones and DTMF.
121 * Echo Cancellation: Sometimes we like to cancel echo from the interface.
122 * Note that a VoIP call may not have echo caused by the IP phone. The echo
123 * is generated by the telephone line connected to it. Because the delay
124 * is high, it becomes an echo. RESULT: Echo Cachelation is required if
125 * both echo AND delay is applied to an interface.
126 * Remember that software CMX always generates a more or less delay.
128 * If all used features can be realized in hardware, and if transmit and/or
129 * receive data ist disabled, the card may not send/receive any data at all.
130 * Not receiving is usefull if only announcements are played. Not sending is
131 * usefull if an answering machine records audio. Not sending and receiving is
132 * usefull during most states of the call. If supported by hardware, tones
133 * will be played without cpu load. Small PBXs and NT-Mode applications will
134 * not need expensive hardware when processing calls.
139 * When data is received from upper or lower layer (card), the complete dsp
140 * module is locked by a global lock. This lock MUST lock irq, because it
141 * must lock timer events by DSP poll timer.
142 * When data is ready to be transmitted down, the data is queued and sent
143 * outside lock and timer event.
144 * PH_CONTROL must not change any settings, join or split conference members
145 * during process of data.
149 * It works quite the same as transparent, except that HDLC data is forwarded
150 * to all other conference members if no hardware bridging is possible.
151 * Send data will be writte to sendq. Sendq will be sent if confirm is received.
152 * Conference cannot join, if one member is not hdlc.
156 #include <linux/delay.h>
157 #include <linux/gfp.h>
158 #include <linux/mISDNif.h>
159 #include <linux/mISDNdsp.h>
160 #include <linux/module.h>
161 #include <linux/vmalloc.h>
165 static const char *mISDN_dsp_revision
= "2.0";
170 static int dtmfthreshold
= 100;
172 MODULE_AUTHOR("Andreas Eversberg");
173 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
174 module_param(options
, uint
, S_IRUGO
| S_IWUSR
);
175 module_param(poll
, uint
, S_IRUGO
| S_IWUSR
);
176 module_param(dtmfthreshold
, uint
, S_IRUGO
| S_IWUSR
);
177 MODULE_LICENSE("GPL");
179 /*int spinnest = 0;*/
181 spinlock_t dsp_lock
; /* global dsp lock */
182 struct list_head dsp_ilist
;
183 struct list_head conf_ilist
;
186 int dsp_poll
, dsp_tics
;
188 /* check if rx may be turned off or must be turned on */
190 dsp_rx_off_member(struct dsp
*dsp
)
192 struct mISDN_ctrl_req cq
;
195 memset(&cq
, 0, sizeof(cq
));
197 if (!dsp
->features_rx_off
)
201 if (!dsp
->rx_disabled
)
204 else if (dsp
->dtmf
.software
)
206 /* echo in software */
207 else if (dsp
->echo
.software
)
209 /* bridge in software */
210 else if (dsp
->conf
&& dsp
->conf
->software
)
212 /* data is not required by user space and not required
213 * for echo dtmf detection, soft-echo, soft-bridging */
215 if (rx_off
== dsp
->rx_is_off
)
219 if (dsp_debug
& DEBUG_DSP_CORE
)
220 printk(KERN_DEBUG
"%s: no peer, no rx_off\n",
224 cq
.op
= MISDN_CTRL_RX_OFF
;
226 if (dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
)) {
227 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
231 dsp
->rx_is_off
= rx_off
;
232 if (dsp_debug
& DEBUG_DSP_CORE
)
233 printk(KERN_DEBUG
"%s: %s set rx_off = %d\n",
234 __func__
, dsp
->name
, rx_off
);
237 dsp_rx_off(struct dsp
*dsp
)
239 struct dsp_conf_member
*member
;
241 if (dsp_options
& DSP_OPT_NOHARDWARE
)
246 dsp_rx_off_member(dsp
);
249 /* check all members in conf */
250 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
251 dsp_rx_off_member(member
->dsp
);
255 /* enable "fill empty" feature */
257 dsp_fill_empty(struct dsp
*dsp
)
259 struct mISDN_ctrl_req cq
;
261 memset(&cq
, 0, sizeof(cq
));
264 if (dsp_debug
& DEBUG_DSP_CORE
)
265 printk(KERN_DEBUG
"%s: no peer, no fill_empty\n",
269 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__
);
292 cont
= *((int *)skb
->data
);
293 len
= skb
->len
- sizeof(int);
294 data
= skb
->data
+ sizeof(int);
297 case DTMF_TONE_START
: /* turn on DTMF */
302 if (dsp_debug
& DEBUG_DSP_CORE
)
303 printk(KERN_DEBUG
"%s: start dtmf\n", __func__
);
304 if (len
== sizeof(int)) {
305 if (dsp_debug
& DEBUG_DSP_CORE
)
306 printk(KERN_NOTICE
"changing DTMF Threshold "
307 "to %d\n", *((int *)data
));
308 dsp
->dtmf
.treshold
= (*(int *)data
) * 10000;
310 dsp
->dtmf
.enable
= 1;
312 dsp_dtmf_goertzel_init(dsp
);
314 /* check dtmf hardware */
315 dsp_dtmf_hardware(dsp
);
318 case DTMF_TONE_STOP
: /* turn off DTMF */
319 if (dsp_debug
& DEBUG_DSP_CORE
)
320 printk(KERN_DEBUG
"%s: stop dtmf\n", __func__
);
321 dsp
->dtmf
.enable
= 0;
322 dsp
->dtmf
.hardware
= 0;
323 dsp
->dtmf
.software
= 0;
325 case DSP_CONF_JOIN
: /* join / update conference */
326 if (len
< sizeof(int)) {
330 if (*((u32
*)data
) == 0)
332 if (dsp_debug
& DEBUG_DSP_CORE
)
333 printk(KERN_DEBUG
"%s: join conference %d\n",
334 __func__
, *((u32
*)data
));
335 ret
= dsp_cmx_conf(dsp
, *((u32
*)data
));
336 /* dsp_cmx_hardware will also be called here */
338 if (dsp_debug
& DEBUG_DSP_CMX
)
341 case DSP_CONF_SPLIT
: /* remove from conference */
343 if (dsp_debug
& DEBUG_DSP_CORE
)
344 printk(KERN_DEBUG
"%s: release conference\n", __func__
);
345 ret
= dsp_cmx_conf(dsp
, 0);
346 /* dsp_cmx_hardware will also be called here */
347 if (dsp_debug
& DEBUG_DSP_CMX
)
351 case DSP_TONE_PATT_ON
: /* play tone */
356 if (len
< sizeof(int)) {
360 if (dsp_debug
& DEBUG_DSP_CORE
)
361 printk(KERN_DEBUG
"%s: turn tone 0x%x on\n",
362 __func__
, *((int *)skb
->data
));
363 ret
= dsp_tone(dsp
, *((int *)data
));
365 dsp_cmx_hardware(dsp
->conf
, dsp
);
371 case DSP_TONE_PATT_OFF
: /* stop tone */
376 if (dsp_debug
& DEBUG_DSP_CORE
)
377 printk(KERN_DEBUG
"%s: turn tone off\n", __func__
);
379 dsp_cmx_hardware(dsp
->conf
, dsp
);
381 /* reset tx buffers (user space data) */
386 case DSP_VOL_CHANGE_TX
: /* change volume */
391 if (len
< sizeof(int)) {
395 dsp
->tx_volume
= *((int *)data
);
396 if (dsp_debug
& DEBUG_DSP_CORE
)
397 printk(KERN_DEBUG
"%s: change tx vol to %d\n",
398 __func__
, dsp
->tx_volume
);
399 dsp_cmx_hardware(dsp
->conf
, dsp
);
400 dsp_dtmf_hardware(dsp
);
403 case DSP_VOL_CHANGE_RX
: /* change volume */
408 if (len
< sizeof(int)) {
412 dsp
->rx_volume
= *((int *)data
);
413 if (dsp_debug
& DEBUG_DSP_CORE
)
414 printk(KERN_DEBUG
"%s: change rx vol to %d\n",
415 __func__
, dsp
->tx_volume
);
416 dsp_cmx_hardware(dsp
->conf
, dsp
);
417 dsp_dtmf_hardware(dsp
);
420 case DSP_ECHO_ON
: /* enable echo */
421 dsp
->echo
.software
= 1; /* soft echo */
422 if (dsp_debug
& DEBUG_DSP_CORE
)
423 printk(KERN_DEBUG
"%s: enable cmx-echo\n", __func__
);
424 dsp_cmx_hardware(dsp
->conf
, dsp
);
426 if (dsp_debug
& DEBUG_DSP_CMX
)
429 case DSP_ECHO_OFF
: /* disable echo */
430 dsp
->echo
.software
= 0;
431 dsp
->echo
.hardware
= 0;
432 if (dsp_debug
& DEBUG_DSP_CORE
)
433 printk(KERN_DEBUG
"%s: disable cmx-echo\n", __func__
);
434 dsp_cmx_hardware(dsp
->conf
, dsp
);
436 if (dsp_debug
& DEBUG_DSP_CMX
)
439 case DSP_RECEIVE_ON
: /* enable receive to user space */
440 if (dsp_debug
& DEBUG_DSP_CORE
)
441 printk(KERN_DEBUG
"%s: enable receive to user "
442 "space\n", __func__
);
443 dsp
->rx_disabled
= 0;
446 case DSP_RECEIVE_OFF
: /* disable receive to user space */
447 if (dsp_debug
& DEBUG_DSP_CORE
)
448 printk(KERN_DEBUG
"%s: disable receive to "
449 "user space\n", __func__
);
450 dsp
->rx_disabled
= 1;
453 case DSP_MIX_ON
: /* enable mixing of tx data */
458 if (dsp_debug
& DEBUG_DSP_CORE
)
459 printk(KERN_DEBUG
"%s: enable mixing of "
460 "tx-data with conf mebers\n", __func__
);
462 dsp_cmx_hardware(dsp
->conf
, dsp
);
464 if (dsp_debug
& DEBUG_DSP_CMX
)
467 case DSP_MIX_OFF
: /* disable mixing of tx data */
472 if (dsp_debug
& DEBUG_DSP_CORE
)
473 printk(KERN_DEBUG
"%s: disable mixing of "
474 "tx-data with conf mebers\n", __func__
);
476 dsp_cmx_hardware(dsp
->conf
, dsp
);
478 if (dsp_debug
& DEBUG_DSP_CMX
)
481 case DSP_TXDATA_ON
: /* enable txdata */
483 if (dsp_debug
& DEBUG_DSP_CORE
)
484 printk(KERN_DEBUG
"%s: enable tx-data\n", __func__
);
485 dsp_cmx_hardware(dsp
->conf
, dsp
);
487 if (dsp_debug
& DEBUG_DSP_CMX
)
490 case DSP_TXDATA_OFF
: /* disable txdata */
492 if (dsp_debug
& DEBUG_DSP_CORE
)
493 printk(KERN_DEBUG
"%s: disable tx-data\n", __func__
);
494 dsp_cmx_hardware(dsp
->conf
, dsp
);
496 if (dsp_debug
& DEBUG_DSP_CMX
)
499 case DSP_DELAY
: /* use delay algorithm instead of dynamic
505 if (len
< sizeof(int)) {
509 dsp
->cmx_delay
= (*((int *)data
)) << 3;
510 /* milliseconds to samples */
511 if (dsp
->cmx_delay
>= (CMX_BUFF_HALF
>>1))
512 /* clip to half of maximum usable buffer
513 (half of half buffer) */
514 dsp
->cmx_delay
= (CMX_BUFF_HALF
>>1) - 1;
515 if (dsp_debug
& DEBUG_DSP_CORE
)
516 printk(KERN_DEBUG
"%s: use delay algorithm to "
517 "compensate jitter (%d samples)\n",
518 __func__
, dsp
->cmx_delay
);
520 case DSP_JITTER
: /* use dynamic jitter algorithm instead of
527 if (dsp_debug
& DEBUG_DSP_CORE
)
528 printk(KERN_DEBUG
"%s: use jitter algorithm to "
529 "compensate jitter\n", __func__
);
531 case DSP_TX_DEJITTER
: /* use dynamic jitter algorithm for tx-buffer */
536 dsp
->tx_dejitter
= 1;
537 if (dsp_debug
& DEBUG_DSP_CORE
)
538 printk(KERN_DEBUG
"%s: use dejitter on TX "
539 "buffer\n", __func__
);
541 case DSP_TX_DEJ_OFF
: /* use tx-buffer without dejittering*/
546 dsp
->tx_dejitter
= 0;
547 if (dsp_debug
& DEBUG_DSP_CORE
)
548 printk(KERN_DEBUG
"%s: use TX buffer without "
549 "dejittering\n", __func__
);
551 case DSP_PIPELINE_CFG
:
556 if (len
> 0 && ((char *)data
)[len
- 1]) {
557 printk(KERN_DEBUG
"%s: pipeline config string "
558 "is not NULL terminated!\n", __func__
);
561 dsp
->pipeline
.inuse
= 1;
562 dsp_cmx_hardware(dsp
->conf
, dsp
);
563 ret
= dsp_pipeline_build(&dsp
->pipeline
,
564 len
> 0 ? data
: NULL
);
565 dsp_cmx_hardware(dsp
->conf
, dsp
);
569 case DSP_BF_ENABLE_KEY
: /* turn blowfish on */
574 if (len
< 4 || len
> 56) {
578 if (dsp_debug
& DEBUG_DSP_CORE
)
579 printk(KERN_DEBUG
"%s: turn blowfish on (key "
580 "not shown)\n", __func__
);
581 ret
= dsp_bf_init(dsp
, (u8
*)data
, len
);
584 cont
= DSP_BF_ACCEPT
;
586 cont
= DSP_BF_REJECT
;
587 /* send indication if it worked to set it */
588 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
, MISDN_ID_ANY
,
589 sizeof(int), &cont
, GFP_ATOMIC
);
592 if (dsp
->up
->send(dsp
->up
, nskb
))
598 dsp_cmx_hardware(dsp
->conf
, dsp
);
599 dsp_dtmf_hardware(dsp
);
603 case DSP_BF_DISABLE
: /* turn blowfish off */
608 if (dsp_debug
& DEBUG_DSP_CORE
)
609 printk(KERN_DEBUG
"%s: turn blowfish off\n", __func__
);
611 dsp_cmx_hardware(dsp
->conf
, dsp
);
612 dsp_dtmf_hardware(dsp
);
616 if (dsp_debug
& DEBUG_DSP_CORE
)
617 printk(KERN_DEBUG
"%s: ctrl req %x unhandled\n",
625 get_features(struct mISDNchannel
*ch
)
627 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
628 struct mISDN_ctrl_req cq
;
631 if (dsp_debug
& DEBUG_DSP_CORE
)
632 printk(KERN_DEBUG
"%s: no peer, no features\n",
636 memset(&cq
, 0, sizeof(cq
));
637 cq
.op
= MISDN_CTRL_GETOP
;
638 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
) < 0) {
639 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
643 if (cq
.op
& MISDN_CTRL_RX_OFF
)
644 dsp
->features_rx_off
= 1;
645 if (cq
.op
& MISDN_CTRL_FILL_EMPTY
)
646 dsp
->features_fill_empty
= 1;
647 if (dsp_options
& DSP_OPT_NOHARDWARE
)
649 if ((cq
.op
& MISDN_CTRL_HW_FEATURES_OP
)) {
650 cq
.op
= MISDN_CTRL_HW_FEATURES
;
651 *((u_long
*)&cq
.p1
) = (u_long
)&dsp
->features
;
652 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
)) {
653 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
657 if (dsp_debug
& DEBUG_DSP_CORE
)
658 printk(KERN_DEBUG
"%s: features not supported for %s\n",
659 __func__
, dsp
->name
);
663 dsp_function(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
665 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
666 struct mISDNhead
*hh
;
671 hh
= mISDN_HEAD_P(skb
);
675 dsp
->data_pending
= 0;
676 /* trigger next hdlc frame, if any */
678 spin_lock_irqsave(&dsp_lock
, flags
);
680 schedule_work(&dsp
->workq
);
681 spin_unlock_irqrestore(&dsp_lock
, flags
);
690 if (dsp
->rx_is_off
) {
691 if (dsp_debug
& DEBUG_DSP_CORE
)
692 printk(KERN_DEBUG
"%s: rx-data during rx_off"
694 __func__
, dsp
->name
);
698 spin_lock_irqsave(&dsp_lock
, flags
);
699 dsp_cmx_hdlc(dsp
, skb
);
700 spin_unlock_irqrestore(&dsp_lock
, flags
);
701 if (dsp
->rx_disabled
) {
702 /* if receive is not allowed */
705 hh
->prim
= DL_DATA_IND
;
707 return dsp
->up
->send(dsp
->up
, skb
);
711 spin_lock_irqsave(&dsp_lock
, flags
);
713 /* decrypt if enabled */
715 dsp_bf_decrypt(dsp
, skb
->data
, skb
->len
);
717 if (dsp
->pipeline
.inuse
)
718 dsp_pipeline_process_rx(&dsp
->pipeline
, skb
->data
,
720 /* change volume if requested */
722 dsp_change_volume(skb
, dsp
->rx_volume
);
723 /* check if dtmf soft decoding is turned on */
724 if (dsp
->dtmf
.software
) {
725 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
726 skb
->len
, (dsp_options
&DSP_OPT_ULAW
) ? 1 : 0);
728 /* we need to process receive data if software */
729 if (dsp
->conf
&& dsp
->conf
->software
) {
730 /* process data from card at cmx */
731 dsp_cmx_receive(dsp
, skb
);
734 spin_unlock_irqrestore(&dsp_lock
, flags
);
736 /* send dtmf result, if any */
740 struct sk_buff
*nskb
;
741 if (dsp_debug
& DEBUG_DSP_DTMF
)
742 printk(KERN_DEBUG
"%s: digit"
743 "(%c) to layer %s\n",
744 __func__
, *digits
, dsp
->name
);
745 k
= *digits
| DTMF_TONE_VAL
;
746 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
747 MISDN_ID_ANY
, sizeof(int), &k
,
760 if (dsp
->rx_disabled
) {
761 /* if receive is not allowed */
764 hh
->prim
= DL_DATA_IND
;
766 return dsp
->up
->send(dsp
->up
, skb
);
768 case (PH_CONTROL_IND
):
769 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
770 printk(KERN_DEBUG
"%s: PH_CONTROL INDICATION "
771 "received: %x (len %d) %s\n", __func__
,
772 hh
->id
, skb
->len
, dsp
->name
);
774 case (DTMF_HFC_COEF
): /* getting coefficients */
775 if (!dsp
->dtmf
.hardware
) {
776 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
777 printk(KERN_DEBUG
"%s: ignoring DTMF "
778 "coefficients from HFC\n",
782 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
786 struct sk_buff
*nskb
;
787 if (dsp_debug
& DEBUG_DSP_DTMF
)
788 printk(KERN_DEBUG
"%s: digit"
789 "(%c) to layer %s\n",
790 __func__
, *digits
, dsp
->name
);
791 k
= *digits
| DTMF_TONE_VAL
;
792 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
793 MISDN_ID_ANY
, sizeof(int), &k
,
806 case (HFC_VOL_CHANGE_TX
): /* change volume */
807 if (skb
->len
!= sizeof(int)) {
811 spin_lock_irqsave(&dsp_lock
, flags
);
812 dsp
->tx_volume
= *((int *)skb
->data
);
813 if (dsp_debug
& DEBUG_DSP_CORE
)
814 printk(KERN_DEBUG
"%s: change tx volume to "
815 "%d\n", __func__
, dsp
->tx_volume
);
816 dsp_cmx_hardware(dsp
->conf
, dsp
);
817 dsp_dtmf_hardware(dsp
);
819 spin_unlock_irqrestore(&dsp_lock
, flags
);
822 if (dsp_debug
& DEBUG_DSP_CORE
)
823 printk(KERN_DEBUG
"%s: ctrl ind %x unhandled "
824 "%s\n", __func__
, hh
->id
, dsp
->name
);
828 case (PH_ACTIVATE_IND
):
829 case (PH_ACTIVATE_CNF
):
830 if (dsp_debug
& DEBUG_DSP_CORE
)
831 printk(KERN_DEBUG
"%s: b_channel is now active %s\n",
832 __func__
, dsp
->name
);
833 /* bchannel now active */
834 spin_lock_irqsave(&dsp_lock
, flags
);
836 dsp
->data_pending
= 0;
838 /* rx_W and rx_R will be adjusted on first frame */
841 memset(dsp
->rx_buff
, 0, sizeof(dsp
->rx_buff
));
842 dsp_cmx_hardware(dsp
->conf
, dsp
);
843 dsp_dtmf_hardware(dsp
);
845 spin_unlock_irqrestore(&dsp_lock
, flags
);
846 if (dsp_debug
& DEBUG_DSP_CORE
)
847 printk(KERN_DEBUG
"%s: done with activation, sending "
848 "confirm to user space. %s\n", __func__
,
850 /* send activation to upper layer */
851 hh
->prim
= DL_ESTABLISH_CNF
;
853 return dsp
->up
->send(dsp
->up
, skb
);
855 case (PH_DEACTIVATE_IND
):
856 case (PH_DEACTIVATE_CNF
):
857 if (dsp_debug
& DEBUG_DSP_CORE
)
858 printk(KERN_DEBUG
"%s: b_channel is now inactive %s\n",
859 __func__
, dsp
->name
);
860 /* bchannel now inactive */
861 spin_lock_irqsave(&dsp_lock
, flags
);
863 dsp
->data_pending
= 0;
864 dsp_cmx_hardware(dsp
->conf
, dsp
);
866 spin_unlock_irqrestore(&dsp_lock
, flags
);
867 hh
->prim
= DL_RELEASE_CNF
;
869 return dsp
->up
->send(dsp
->up
, skb
);
880 if (!dsp
->b_active
) {
884 hh
->prim
= PH_DATA_REQ
;
885 spin_lock_irqsave(&dsp_lock
, flags
);
886 skb_queue_tail(&dsp
->sendq
, skb
);
887 schedule_work(&dsp
->workq
);
888 spin_unlock_irqrestore(&dsp_lock
, flags
);
891 /* send data to tx-buffer (if no tone is played) */
892 if (!dsp
->tone
.tone
) {
893 spin_lock_irqsave(&dsp_lock
, flags
);
894 dsp_cmx_transmit(dsp
, skb
);
895 spin_unlock_irqrestore(&dsp_lock
, flags
);
898 case (PH_CONTROL_REQ
):
899 spin_lock_irqsave(&dsp_lock
, flags
);
900 ret
= dsp_control_req(dsp
, hh
, skb
);
901 spin_unlock_irqrestore(&dsp_lock
, flags
);
903 case (DL_ESTABLISH_REQ
):
904 case (PH_ACTIVATE_REQ
):
905 if (dsp_debug
& DEBUG_DSP_CORE
)
906 printk(KERN_DEBUG
"%s: activating b_channel %s\n",
907 __func__
, dsp
->name
);
908 if (dsp
->dtmf
.hardware
|| dsp
->dtmf
.software
)
909 dsp_dtmf_goertzel_init(dsp
);
911 /* enable fill_empty feature */
912 if (dsp
->features_fill_empty
)
914 /* send ph_activate */
915 hh
->prim
= PH_ACTIVATE_REQ
;
917 return ch
->recv(ch
->peer
, skb
);
919 case (DL_RELEASE_REQ
):
920 case (PH_DEACTIVATE_REQ
):
921 if (dsp_debug
& DEBUG_DSP_CORE
)
922 printk(KERN_DEBUG
"%s: releasing b_channel %s\n",
923 __func__
, dsp
->name
);
924 spin_lock_irqsave(&dsp_lock
, flags
);
926 dsp
->tone
.hardware
= 0;
927 dsp
->tone
.software
= 0;
928 if (timer_pending(&dsp
->tone
.tl
))
929 del_timer(&dsp
->tone
.tl
);
931 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be
933 skb_queue_purge(&dsp
->sendq
);
934 spin_unlock_irqrestore(&dsp_lock
, flags
);
935 hh
->prim
= PH_DEACTIVATE_REQ
;
937 return ch
->recv(ch
->peer
, skb
);
940 if (dsp_debug
& DEBUG_DSP_CORE
)
941 printk(KERN_DEBUG
"%s: msg %x unhandled %s\n",
942 __func__
, hh
->prim
, dsp
->name
);
951 dsp_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
953 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
957 if (debug
& DEBUG_DSP_CTRL
)
958 printk(KERN_DEBUG
"%s:(%x)\n", __func__
, cmd
);
965 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
967 /* wait until workqueue has finished,
968 * must lock here, or we may hit send-process currently
970 spin_lock_irqsave(&dsp_lock
, flags
);
972 spin_unlock_irqrestore(&dsp_lock
, flags
);
973 /* MUST not be locked, because it waits until queue is done. */
974 cancel_work_sync(&dsp
->workq
);
975 spin_lock_irqsave(&dsp_lock
, flags
);
976 if (timer_pending(&dsp
->tone
.tl
))
977 del_timer(&dsp
->tone
.tl
);
978 skb_queue_purge(&dsp
->sendq
);
979 if (dsp_debug
& DEBUG_DSP_CTRL
)
980 printk(KERN_DEBUG
"%s: releasing member %s\n",
981 __func__
, dsp
->name
);
983 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be called
985 dsp_pipeline_destroy(&dsp
->pipeline
);
987 if (dsp_debug
& DEBUG_DSP_CTRL
)
988 printk(KERN_DEBUG
"%s: remove & destroy object %s\n",
989 __func__
, dsp
->name
);
990 list_del(&dsp
->list
);
991 spin_unlock_irqrestore(&dsp_lock
, flags
);
993 if (dsp_debug
& DEBUG_DSP_CTRL
)
994 printk(KERN_DEBUG
"%s: dsp instance released\n",
997 module_put(THIS_MODULE
);
1004 dsp_send_bh(struct work_struct
*work
)
1006 struct dsp
*dsp
= container_of(work
, struct dsp
, workq
);
1007 struct sk_buff
*skb
;
1008 struct mISDNhead
*hh
;
1010 if (dsp
->hdlc
&& dsp
->data_pending
)
1011 return; /* wait until data has been acknowledged */
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 */
1024 hh
= mISDN_HEAD_P(skb
);
1025 if (hh
->prim
== DL_DATA_REQ
) {
1026 /* send packet up */
1028 if (dsp
->up
->send(dsp
->up
, skb
))
1033 /* send packet down */
1035 dsp
->data_pending
= 1;
1036 if (dsp
->ch
.recv(dsp
->ch
.peer
, skb
)) {
1038 dsp
->data_pending
= 0;
1047 dspcreate(struct channel_req
*crq
)
1052 if (crq
->protocol
!= ISDN_P_B_L2DSP
1053 && crq
->protocol
!= ISDN_P_B_L2DSPHDLC
)
1054 return -EPROTONOSUPPORT
;
1055 ndsp
= vmalloc(sizeof(struct dsp
));
1057 printk(KERN_ERR
"%s: vmalloc struct dsp failed\n", __func__
);
1060 memset(ndsp
, 0, sizeof(struct dsp
));
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 ndsp
->tone
.tl
.function
= (void *)dsp_tone_timeout
;
1094 ndsp
->tone
.tl
.data
= (long) ndsp
;
1095 init_timer(&ndsp
->tone
.tl
);
1097 if (dtmfthreshold
< 20 || dtmfthreshold
> 500)
1098 dtmfthreshold
= 200;
1099 ndsp
->dtmf
.treshold
= dtmfthreshold
*10000;
1101 /* init pipeline append to list */
1102 spin_lock_irqsave(&dsp_lock
, flags
);
1103 dsp_pipeline_init(&ndsp
->pipeline
);
1104 list_add_tail(&ndsp
->list
, &dsp_ilist
);
1105 spin_unlock_irqrestore(&dsp_lock
, flags
);
1111 static struct Bprotocol DSP
= {
1112 .Bprotocols
= (1 << (ISDN_P_B_L2DSP
& ISDN_P_B_MASK
))
1113 | (1 << (ISDN_P_B_L2DSPHDLC
& ISDN_P_B_MASK
)),
1118 static int __init
dsp_init(void)
1123 printk(KERN_INFO
"DSP modul %s\n", mISDN_dsp_revision
);
1125 dsp_options
= options
;
1128 /* set packet size */
1131 if (dsp_poll
> MAX_POLL
) {
1132 printk(KERN_ERR
"%s: Wrong poll value (%d), use %d "
1133 "maximum.\n", __func__
, poll
, MAX_POLL
);
1138 printk(KERN_ERR
"%s: Wrong poll value (%d), use 8 "
1139 "minimum.\n", __func__
, dsp_poll
);
1143 dsp_tics
= poll
* HZ
/ 8000;
1144 if (dsp_tics
* 8000 != poll
* HZ
) {
1145 printk(KERN_INFO
"mISDN_dsp: Cannot clock every %d "
1146 "samples (0,125 ms). It is not a multiple of "
1147 "%d HZ.\n", poll
, HZ
);
1153 while (poll
<= MAX_POLL
) {
1154 tics
= (poll
* HZ
) / 8000;
1155 if (tics
* 8000 == poll
* HZ
) {
1164 if (dsp_poll
== 0) {
1165 printk(KERN_INFO
"mISDN_dsp: There is no multiple of kernel "
1166 "clock that equals exactly the duration of 8-256 "
1167 "samples. (Choose kernel clock speed like 100, 250, "
1172 printk(KERN_INFO
"mISDN_dsp: DSP clocks every %d samples. This equals "
1173 "%d jiffies.\n", dsp_poll
, dsp_tics
);
1175 spin_lock_init(&dsp_lock
);
1176 INIT_LIST_HEAD(&dsp_ilist
);
1177 INIT_LIST_HEAD(&conf_ilist
);
1179 /* init conversion tables */
1180 dsp_audio_generate_law_tables();
1181 dsp_silence
= (dsp_options
&DSP_OPT_ULAW
) ? 0xff : 0x2a;
1182 dsp_audio_law_to_s32
= (dsp_options
&DSP_OPT_ULAW
) ?
1183 dsp_audio_ulaw_to_s32
: dsp_audio_alaw_to_s32
;
1184 dsp_audio_generate_s2law_table();
1185 dsp_audio_generate_seven();
1186 dsp_audio_generate_mix_table();
1187 if (dsp_options
& DSP_OPT_ULAW
)
1188 dsp_audio_generate_ulaw_samples();
1189 dsp_audio_generate_volume_changes();
1191 err
= dsp_pipeline_module_init();
1193 printk(KERN_ERR
"mISDN_dsp: Can't initialize pipeline, "
1194 "error(%d)\n", err
);
1198 err
= mISDN_register_Bprotocol(&DSP
);
1200 printk(KERN_ERR
"Can't register %s error(%d)\n", DSP
.name
, err
);
1204 /* set sample timer */
1205 dsp_spl_tl
.function
= (void *)dsp_cmx_send
;
1206 dsp_spl_tl
.data
= 0;
1207 init_timer(&dsp_spl_tl
);
1208 dsp_spl_tl
.expires
= jiffies
+ dsp_tics
;
1209 dsp_spl_jiffies
= dsp_spl_tl
.expires
;
1210 add_timer(&dsp_spl_tl
);
1216 static void __exit
dsp_cleanup(void)
1218 mISDN_unregister_Bprotocol(&DSP
);
1220 if (timer_pending(&dsp_spl_tl
))
1221 del_timer(&dsp_spl_tl
);
1223 if (!list_empty(&dsp_ilist
)) {
1224 printk(KERN_ERR
"mISDN_dsp: Audio DSP object inst list not "
1227 if (!list_empty(&conf_ilist
)) {
1228 printk(KERN_ERR
"mISDN_dsp: Conference list not empty. Not "
1229 "all memory freed.\n");
1232 dsp_pipeline_module_exit();
1235 module_init(dsp_init
);
1236 module_exit(dsp_cleanup
);