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 performane 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/mISDNif.h>
158 #include <linux/mISDNdsp.h>
159 #include <linux/module.h>
160 #include <linux/vmalloc.h>
164 static const char *mISDN_dsp_revision
= "2.0";
169 static int dtmfthreshold
= 100;
171 MODULE_AUTHOR("Andreas Eversberg");
172 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
173 module_param(options
, uint
, S_IRUGO
| S_IWUSR
);
174 module_param(poll
, uint
, S_IRUGO
| S_IWUSR
);
175 module_param(dtmfthreshold
, uint
, S_IRUGO
| S_IWUSR
);
176 MODULE_LICENSE("GPL");
178 /*int spinnest = 0;*/
180 spinlock_t dsp_lock
; /* global dsp lock */
181 struct list_head dsp_ilist
;
182 struct 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
;
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__
);
291 cont
= *((int *)skb
->data
);
292 len
= skb
->len
- sizeof(int);
293 data
= skb
->data
+ sizeof(int);
296 case DTMF_TONE_START
: /* turn on DTMF */
301 if (dsp_debug
& DEBUG_DSP_CORE
)
302 printk(KERN_DEBUG
"%s: start dtmf\n", __func__
);
303 if (len
== sizeof(int)) {
304 if (dsp_debug
& DEBUG_DSP_CORE
)
305 printk(KERN_NOTICE
"changing DTMF Threshold "
306 "to %d\n", *((int *)data
));
307 dsp
->dtmf
.treshold
= (*(int *)data
) * 10000;
309 dsp
->dtmf
.enable
= 1;
311 dsp_dtmf_goertzel_init(dsp
);
313 /* check dtmf hardware */
314 dsp_dtmf_hardware(dsp
);
317 case DTMF_TONE_STOP
: /* turn off DTMF */
318 if (dsp_debug
& DEBUG_DSP_CORE
)
319 printk(KERN_DEBUG
"%s: stop dtmf\n", __func__
);
320 dsp
->dtmf
.enable
= 0;
321 dsp
->dtmf
.hardware
= 0;
322 dsp
->dtmf
.software
= 0;
324 case DSP_CONF_JOIN
: /* join / update conference */
325 if (len
< sizeof(int)) {
329 if (*((u32
*)data
) == 0)
331 if (dsp_debug
& DEBUG_DSP_CORE
)
332 printk(KERN_DEBUG
"%s: join conference %d\n",
333 __func__
, *((u32
*)data
));
334 ret
= dsp_cmx_conf(dsp
, *((u32
*)data
));
335 /* dsp_cmx_hardware will also be called here */
337 if (dsp_debug
& DEBUG_DSP_CMX
)
340 case DSP_CONF_SPLIT
: /* remove from conference */
342 if (dsp_debug
& DEBUG_DSP_CORE
)
343 printk(KERN_DEBUG
"%s: release conference\n", __func__
);
344 ret
= dsp_cmx_conf(dsp
, 0);
345 /* dsp_cmx_hardware will also be called here */
346 if (dsp_debug
& DEBUG_DSP_CMX
)
350 case DSP_TONE_PATT_ON
: /* play tone */
355 if (len
< sizeof(int)) {
359 if (dsp_debug
& DEBUG_DSP_CORE
)
360 printk(KERN_DEBUG
"%s: turn tone 0x%x on\n",
361 __func__
, *((int *)skb
->data
));
362 ret
= dsp_tone(dsp
, *((int *)data
));
364 dsp_cmx_hardware(dsp
->conf
, dsp
);
370 case DSP_TONE_PATT_OFF
: /* stop tone */
375 if (dsp_debug
& DEBUG_DSP_CORE
)
376 printk(KERN_DEBUG
"%s: turn tone off\n", __func__
);
378 dsp_cmx_hardware(dsp
->conf
, dsp
);
380 /* reset tx buffers (user space data) */
385 case DSP_VOL_CHANGE_TX
: /* change volume */
390 if (len
< sizeof(int)) {
394 dsp
->tx_volume
= *((int *)data
);
395 if (dsp_debug
& DEBUG_DSP_CORE
)
396 printk(KERN_DEBUG
"%s: change tx vol to %d\n",
397 __func__
, dsp
->tx_volume
);
398 dsp_cmx_hardware(dsp
->conf
, dsp
);
399 dsp_dtmf_hardware(dsp
);
402 case DSP_VOL_CHANGE_RX
: /* change volume */
407 if (len
< sizeof(int)) {
411 dsp
->rx_volume
= *((int *)data
);
412 if (dsp_debug
& DEBUG_DSP_CORE
)
413 printk(KERN_DEBUG
"%s: change rx vol to %d\n",
414 __func__
, dsp
->tx_volume
);
415 dsp_cmx_hardware(dsp
->conf
, dsp
);
416 dsp_dtmf_hardware(dsp
);
419 case DSP_ECHO_ON
: /* enable echo */
420 dsp
->echo
.software
= 1; /* soft echo */
421 if (dsp_debug
& DEBUG_DSP_CORE
)
422 printk(KERN_DEBUG
"%s: enable cmx-echo\n", __func__
);
423 dsp_cmx_hardware(dsp
->conf
, dsp
);
425 if (dsp_debug
& DEBUG_DSP_CMX
)
428 case DSP_ECHO_OFF
: /* disable echo */
429 dsp
->echo
.software
= 0;
430 dsp
->echo
.hardware
= 0;
431 if (dsp_debug
& DEBUG_DSP_CORE
)
432 printk(KERN_DEBUG
"%s: disable cmx-echo\n", __func__
);
433 dsp_cmx_hardware(dsp
->conf
, dsp
);
435 if (dsp_debug
& DEBUG_DSP_CMX
)
438 case DSP_RECEIVE_ON
: /* enable receive to user space */
439 if (dsp_debug
& DEBUG_DSP_CORE
)
440 printk(KERN_DEBUG
"%s: enable receive to user "
441 "space\n", __func__
);
442 dsp
->rx_disabled
= 0;
445 case DSP_RECEIVE_OFF
: /* disable receive to user space */
446 if (dsp_debug
& DEBUG_DSP_CORE
)
447 printk(KERN_DEBUG
"%s: disable receive to "
448 "user space\n", __func__
);
449 dsp
->rx_disabled
= 1;
452 case DSP_MIX_ON
: /* enable mixing of tx data */
457 if (dsp_debug
& DEBUG_DSP_CORE
)
458 printk(KERN_DEBUG
"%s: enable mixing of "
459 "tx-data with conf mebers\n", __func__
);
461 dsp_cmx_hardware(dsp
->conf
, dsp
);
463 if (dsp_debug
& DEBUG_DSP_CMX
)
466 case DSP_MIX_OFF
: /* disable mixing of tx data */
471 if (dsp_debug
& DEBUG_DSP_CORE
)
472 printk(KERN_DEBUG
"%s: disable mixing of "
473 "tx-data with conf mebers\n", __func__
);
475 dsp_cmx_hardware(dsp
->conf
, dsp
);
477 if (dsp_debug
& DEBUG_DSP_CMX
)
480 case DSP_TXDATA_ON
: /* enable txdata */
482 if (dsp_debug
& DEBUG_DSP_CORE
)
483 printk(KERN_DEBUG
"%s: enable tx-data\n", __func__
);
484 dsp_cmx_hardware(dsp
->conf
, dsp
);
486 if (dsp_debug
& DEBUG_DSP_CMX
)
489 case DSP_TXDATA_OFF
: /* disable txdata */
491 if (dsp_debug
& DEBUG_DSP_CORE
)
492 printk(KERN_DEBUG
"%s: disable tx-data\n", __func__
);
493 dsp_cmx_hardware(dsp
->conf
, dsp
);
495 if (dsp_debug
& DEBUG_DSP_CMX
)
498 case DSP_DELAY
: /* use delay algorithm instead of dynamic
504 if (len
< sizeof(int)) {
508 dsp
->cmx_delay
= (*((int *)data
)) << 3;
509 /* milliseconds to samples */
510 if (dsp
->cmx_delay
>= (CMX_BUFF_HALF
>>1))
511 /* clip to half of maximum usable buffer
512 (half of half buffer) */
513 dsp
->cmx_delay
= (CMX_BUFF_HALF
>>1) - 1;
514 if (dsp_debug
& DEBUG_DSP_CORE
)
515 printk(KERN_DEBUG
"%s: use delay algorithm to "
516 "compensate jitter (%d samples)\n",
517 __func__
, dsp
->cmx_delay
);
519 case DSP_JITTER
: /* use dynamic jitter algorithm instead of
526 if (dsp_debug
& DEBUG_DSP_CORE
)
527 printk(KERN_DEBUG
"%s: use jitter algorithm to "
528 "compensate jitter\n", __func__
);
530 case DSP_TX_DEJITTER
: /* use dynamic jitter algorithm for tx-buffer */
535 dsp
->tx_dejitter
= 1;
536 if (dsp_debug
& DEBUG_DSP_CORE
)
537 printk(KERN_DEBUG
"%s: use dejitter on TX "
538 "buffer\n", __func__
);
540 case DSP_TX_DEJ_OFF
: /* use tx-buffer without dejittering*/
545 dsp
->tx_dejitter
= 0;
546 if (dsp_debug
& DEBUG_DSP_CORE
)
547 printk(KERN_DEBUG
"%s: use TX buffer without "
548 "dejittering\n", __func__
);
550 case DSP_PIPELINE_CFG
:
555 if (len
> 0 && ((char *)data
)[len
- 1]) {
556 printk(KERN_DEBUG
"%s: pipeline config string "
557 "is not NULL terminated!\n", __func__
);
560 dsp
->pipeline
.inuse
= 1;
561 dsp_cmx_hardware(dsp
->conf
, dsp
);
562 ret
= dsp_pipeline_build(&dsp
->pipeline
,
563 len
> 0 ? data
: NULL
);
564 dsp_cmx_hardware(dsp
->conf
, dsp
);
568 case DSP_BF_ENABLE_KEY
: /* turn blowfish on */
573 if (len
< 4 || len
> 56) {
577 if (dsp_debug
& DEBUG_DSP_CORE
)
578 printk(KERN_DEBUG
"%s: turn blowfish on (key "
579 "not shown)\n", __func__
);
580 ret
= dsp_bf_init(dsp
, (u8
*)data
, len
);
583 cont
= DSP_BF_ACCEPT
;
585 cont
= DSP_BF_REJECT
;
586 /* send indication if it worked to set it */
587 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
, MISDN_ID_ANY
,
588 sizeof(int), &cont
, GFP_ATOMIC
);
591 if (dsp
->up
->send(dsp
->up
, nskb
))
597 dsp_cmx_hardware(dsp
->conf
, dsp
);
598 dsp_dtmf_hardware(dsp
);
602 case DSP_BF_DISABLE
: /* turn blowfish off */
607 if (dsp_debug
& DEBUG_DSP_CORE
)
608 printk(KERN_DEBUG
"%s: turn blowfish off\n", __func__
);
610 dsp_cmx_hardware(dsp
->conf
, dsp
);
611 dsp_dtmf_hardware(dsp
);
615 if (dsp_debug
& DEBUG_DSP_CORE
)
616 printk(KERN_DEBUG
"%s: ctrl req %x unhandled\n",
624 get_features(struct mISDNchannel
*ch
)
626 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
627 struct mISDN_ctrl_req cq
;
630 if (dsp_debug
& DEBUG_DSP_CORE
)
631 printk(KERN_DEBUG
"%s: no peer, no features\n",
635 memset(&cq
, 0, sizeof(cq
));
636 cq
.op
= MISDN_CTRL_GETOP
;
637 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
) < 0) {
638 printk(KERN_DEBUG
"%s: CONTROL_CHANNEL failed\n",
642 if (cq
.op
& MISDN_CTRL_RX_OFF
)
643 dsp
->features_rx_off
= 1;
644 if (cq
.op
& MISDN_CTRL_FILL_EMPTY
)
645 dsp
->features_fill_empty
= 1;
646 if (dsp_options
& DSP_OPT_NOHARDWARE
)
648 if ((cq
.op
& MISDN_CTRL_HW_FEATURES_OP
)) {
649 cq
.op
= MISDN_CTRL_HW_FEATURES
;
650 *((u_long
*)&cq
.p1
) = (u_long
)&dsp
->features
;
651 if (ch
->peer
->ctrl(ch
->peer
, CONTROL_CHANNEL
, &cq
)) {
652 printk(KERN_DEBUG
"%s: 2nd CONTROL_CHANNEL failed\n",
656 if (dsp_debug
& DEBUG_DSP_CORE
)
657 printk(KERN_DEBUG
"%s: features not supported for %s\n",
658 __func__
, dsp
->name
);
662 dsp_function(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
664 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
665 struct mISDNhead
*hh
;
670 hh
= mISDN_HEAD_P(skb
);
674 dsp
->data_pending
= 0;
675 /* trigger next hdlc frame, if any */
677 spin_lock_irqsave(&dsp_lock
, flags
);
679 schedule_work(&dsp
->workq
);
680 spin_unlock_irqrestore(&dsp_lock
, flags
);
689 if (dsp
->rx_is_off
) {
690 if (dsp_debug
& DEBUG_DSP_CORE
)
691 printk(KERN_DEBUG
"%s: rx-data during rx_off"
693 __func__
, dsp
->name
);
697 spin_lock_irqsave(&dsp_lock
, flags
);
698 dsp_cmx_hdlc(dsp
, skb
);
699 spin_unlock_irqrestore(&dsp_lock
, flags
);
700 if (dsp
->rx_disabled
) {
701 /* if receive is not allowed */
704 hh
->prim
= DL_DATA_IND
;
706 return dsp
->up
->send(dsp
->up
, skb
);
710 spin_lock_irqsave(&dsp_lock
, flags
);
712 /* decrypt if enabled */
714 dsp_bf_decrypt(dsp
, skb
->data
, skb
->len
);
716 if (dsp
->pipeline
.inuse
)
717 dsp_pipeline_process_rx(&dsp
->pipeline
, skb
->data
,
719 /* change volume if requested */
721 dsp_change_volume(skb
, dsp
->rx_volume
);
722 /* check if dtmf soft decoding is turned on */
723 if (dsp
->dtmf
.software
) {
724 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
725 skb
->len
, (dsp_options
&DSP_OPT_ULAW
) ? 1 : 0);
727 /* we need to process receive data if software */
728 if (dsp
->conf
&& dsp
->conf
->software
) {
729 /* process data from card at cmx */
730 dsp_cmx_receive(dsp
, skb
);
733 spin_unlock_irqrestore(&dsp_lock
, flags
);
735 /* send dtmf result, if any */
739 struct sk_buff
*nskb
;
740 if (dsp_debug
& DEBUG_DSP_DTMF
)
741 printk(KERN_DEBUG
"%s: digit"
742 "(%c) to layer %s\n",
743 __func__
, *digits
, dsp
->name
);
744 k
= *digits
| DTMF_TONE_VAL
;
745 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
746 MISDN_ID_ANY
, sizeof(int), &k
,
759 if (dsp
->rx_disabled
) {
760 /* if receive is not allowed */
763 hh
->prim
= DL_DATA_IND
;
765 return dsp
->up
->send(dsp
->up
, skb
);
767 case (PH_CONTROL_IND
):
768 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
769 printk(KERN_DEBUG
"%s: PH_CONTROL INDICATION "
770 "received: %x (len %d) %s\n", __func__
,
771 hh
->id
, skb
->len
, dsp
->name
);
773 case (DTMF_HFC_COEF
): /* getting coefficients */
774 if (!dsp
->dtmf
.hardware
) {
775 if (dsp_debug
& DEBUG_DSP_DTMFCOEFF
)
776 printk(KERN_DEBUG
"%s: ignoring DTMF "
777 "coefficients from HFC\n",
781 digits
= dsp_dtmf_goertzel_decode(dsp
, skb
->data
,
785 struct sk_buff
*nskb
;
786 if (dsp_debug
& DEBUG_DSP_DTMF
)
787 printk(KERN_DEBUG
"%s: digit"
788 "(%c) to layer %s\n",
789 __func__
, *digits
, dsp
->name
);
790 k
= *digits
| DTMF_TONE_VAL
;
791 nskb
= _alloc_mISDN_skb(PH_CONTROL_IND
,
792 MISDN_ID_ANY
, sizeof(int), &k
,
805 case (HFC_VOL_CHANGE_TX
): /* change volume */
806 if (skb
->len
!= sizeof(int)) {
810 spin_lock_irqsave(&dsp_lock
, flags
);
811 dsp
->tx_volume
= *((int *)skb
->data
);
812 if (dsp_debug
& DEBUG_DSP_CORE
)
813 printk(KERN_DEBUG
"%s: change tx volume to "
814 "%d\n", __func__
, dsp
->tx_volume
);
815 dsp_cmx_hardware(dsp
->conf
, dsp
);
816 dsp_dtmf_hardware(dsp
);
818 spin_unlock_irqrestore(&dsp_lock
, flags
);
821 if (dsp_debug
& DEBUG_DSP_CORE
)
822 printk(KERN_DEBUG
"%s: ctrl ind %x unhandled "
823 "%s\n", __func__
, hh
->id
, dsp
->name
);
827 case (PH_ACTIVATE_IND
):
828 case (PH_ACTIVATE_CNF
):
829 if (dsp_debug
& DEBUG_DSP_CORE
)
830 printk(KERN_DEBUG
"%s: b_channel is now active %s\n",
831 __func__
, dsp
->name
);
832 /* bchannel now active */
833 spin_lock_irqsave(&dsp_lock
, flags
);
835 dsp
->data_pending
= 0;
837 /* rx_W and rx_R will be adjusted on first frame */
840 memset(dsp
->rx_buff
, 0, sizeof(dsp
->rx_buff
));
841 dsp_cmx_hardware(dsp
->conf
, dsp
);
842 dsp_dtmf_hardware(dsp
);
844 spin_unlock_irqrestore(&dsp_lock
, flags
);
845 if (dsp_debug
& DEBUG_DSP_CORE
)
846 printk(KERN_DEBUG
"%s: done with activation, sending "
847 "confirm to user space. %s\n", __func__
,
849 /* send activation to upper layer */
850 hh
->prim
= DL_ESTABLISH_CNF
;
852 return dsp
->up
->send(dsp
->up
, skb
);
854 case (PH_DEACTIVATE_IND
):
855 case (PH_DEACTIVATE_CNF
):
856 if (dsp_debug
& DEBUG_DSP_CORE
)
857 printk(KERN_DEBUG
"%s: b_channel is now inactive %s\n",
858 __func__
, dsp
->name
);
859 /* bchannel now inactive */
860 spin_lock_irqsave(&dsp_lock
, flags
);
862 dsp
->data_pending
= 0;
863 dsp_cmx_hardware(dsp
->conf
, dsp
);
865 spin_unlock_irqrestore(&dsp_lock
, flags
);
866 hh
->prim
= DL_RELEASE_CNF
;
868 return dsp
->up
->send(dsp
->up
, skb
);
879 if (!dsp
->b_active
) {
883 hh
->prim
= PH_DATA_REQ
;
884 spin_lock_irqsave(&dsp_lock
, flags
);
885 skb_queue_tail(&dsp
->sendq
, skb
);
886 schedule_work(&dsp
->workq
);
887 spin_unlock_irqrestore(&dsp_lock
, flags
);
890 /* send data to tx-buffer (if no tone is played) */
891 if (!dsp
->tone
.tone
) {
892 spin_lock_irqsave(&dsp_lock
, flags
);
893 dsp_cmx_transmit(dsp
, skb
);
894 spin_unlock_irqrestore(&dsp_lock
, flags
);
897 case (PH_CONTROL_REQ
):
898 spin_lock_irqsave(&dsp_lock
, flags
);
899 ret
= dsp_control_req(dsp
, hh
, skb
);
900 spin_unlock_irqrestore(&dsp_lock
, flags
);
902 case (DL_ESTABLISH_REQ
):
903 case (PH_ACTIVATE_REQ
):
904 if (dsp_debug
& DEBUG_DSP_CORE
)
905 printk(KERN_DEBUG
"%s: activating b_channel %s\n",
906 __func__
, dsp
->name
);
907 if (dsp
->dtmf
.hardware
|| dsp
->dtmf
.software
)
908 dsp_dtmf_goertzel_init(dsp
);
910 /* enable fill_empty feature */
911 if (dsp
->features_fill_empty
)
913 /* send ph_activate */
914 hh
->prim
= PH_ACTIVATE_REQ
;
916 return ch
->recv(ch
->peer
, skb
);
918 case (DL_RELEASE_REQ
):
919 case (PH_DEACTIVATE_REQ
):
920 if (dsp_debug
& DEBUG_DSP_CORE
)
921 printk(KERN_DEBUG
"%s: releasing b_channel %s\n",
922 __func__
, dsp
->name
);
923 spin_lock_irqsave(&dsp_lock
, flags
);
925 dsp
->tone
.hardware
= 0;
926 dsp
->tone
.software
= 0;
927 if (timer_pending(&dsp
->tone
.tl
))
928 del_timer(&dsp
->tone
.tl
);
930 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be
932 skb_queue_purge(&dsp
->sendq
);
933 spin_unlock_irqrestore(&dsp_lock
, flags
);
934 hh
->prim
= PH_DEACTIVATE_REQ
;
936 return ch
->recv(ch
->peer
, skb
);
939 if (dsp_debug
& DEBUG_DSP_CORE
)
940 printk(KERN_DEBUG
"%s: msg %x unhandled %s\n",
941 __func__
, hh
->prim
, dsp
->name
);
950 dsp_ctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
952 struct dsp
*dsp
= container_of(ch
, struct dsp
, ch
);
956 if (debug
& DEBUG_DSP_CTRL
)
957 printk(KERN_DEBUG
"%s:(%x)\n", __func__
, cmd
);
964 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CLOSE_CHANNEL
, NULL
);
966 /* wait until workqueue has finished,
967 * must lock here, or we may hit send-process currently
969 spin_lock_irqsave(&dsp_lock
, flags
);
971 spin_unlock_irqrestore(&dsp_lock
, flags
);
972 /* MUST not be locked, because it waits until queue is done. */
973 cancel_work_sync(&dsp
->workq
);
974 spin_lock_irqsave(&dsp_lock
, flags
);
975 if (timer_pending(&dsp
->tone
.tl
))
976 del_timer(&dsp
->tone
.tl
);
977 skb_queue_purge(&dsp
->sendq
);
978 if (dsp_debug
& DEBUG_DSP_CTRL
)
979 printk(KERN_DEBUG
"%s: releasing member %s\n",
980 __func__
, dsp
->name
);
982 dsp_cmx_conf(dsp
, 0); /* dsp_cmx_hardware will also be called
984 dsp_pipeline_destroy(&dsp
->pipeline
);
986 if (dsp_debug
& DEBUG_DSP_CTRL
)
987 printk(KERN_DEBUG
"%s: remove & destroy object %s\n",
988 __func__
, dsp
->name
);
989 list_del(&dsp
->list
);
990 spin_unlock_irqrestore(&dsp_lock
, flags
);
992 if (dsp_debug
& DEBUG_DSP_CTRL
)
993 printk(KERN_DEBUG
"%s: dsp instance released\n",
996 module_put(THIS_MODULE
);
1003 dsp_send_bh(struct work_struct
*work
)
1005 struct dsp
*dsp
= container_of(work
, struct dsp
, workq
);
1006 struct sk_buff
*skb
;
1007 struct mISDNhead
*hh
;
1009 if (dsp
->hdlc
&& dsp
->data_pending
)
1010 return; /* wait until data has been acknowledged */
1012 /* send queued data */
1013 while ((skb
= skb_dequeue(&dsp
->sendq
))) {
1014 /* in locked date, we must have still data in queue */
1015 if (dsp
->data_pending
) {
1016 if (dsp_debug
& DEBUG_DSP_CORE
)
1017 printk(KERN_DEBUG
"%s: fifo full %s, this is "
1018 "no bug!\n", __func__
, dsp
->name
);
1019 /* flush transparent data, if not acked */
1023 hh
= mISDN_HEAD_P(skb
);
1024 if (hh
->prim
== DL_DATA_REQ
) {
1025 /* send packet up */
1027 if (dsp
->up
->send(dsp
->up
, skb
))
1032 /* send packet down */
1034 dsp
->data_pending
= 1;
1035 if (dsp
->ch
.recv(dsp
->ch
.peer
, skb
)) {
1037 dsp
->data_pending
= 0;
1046 dspcreate(struct channel_req
*crq
)
1051 if (crq
->protocol
!= ISDN_P_B_L2DSP
1052 && crq
->protocol
!= ISDN_P_B_L2DSPHDLC
)
1053 return -EPROTONOSUPPORT
;
1054 ndsp
= vmalloc(sizeof(struct dsp
));
1056 printk(KERN_ERR
"%s: vmalloc struct dsp failed\n", __func__
);
1059 memset(ndsp
, 0, sizeof(struct dsp
));
1060 if (dsp_debug
& DEBUG_DSP_CTRL
)
1061 printk(KERN_DEBUG
"%s: creating new dsp instance\n", __func__
);
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
;
1069 crq
->ch
= &ndsp
->ch
;
1070 if (crq
->protocol
== ISDN_P_B_L2DSP
) {
1071 crq
->protocol
= ISDN_P_B_RAW
;
1074 crq
->protocol
= ISDN_P_B_HDLC
;
1077 if (!try_module_get(THIS_MODULE
))
1078 printk(KERN_WARNING
"%s:cannot get module\n",
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 ndsp
->tone
.tl
.function
= (void *)dsp_tone_timeout
;
1093 ndsp
->tone
.tl
.data
= (long) ndsp
;
1094 init_timer(&ndsp
->tone
.tl
);
1096 if (dtmfthreshold
< 20 || dtmfthreshold
> 500)
1097 dtmfthreshold
= 200;
1098 ndsp
->dtmf
.treshold
= dtmfthreshold
*10000;
1100 /* init pipeline append to list */
1101 spin_lock_irqsave(&dsp_lock
, flags
);
1102 dsp_pipeline_init(&ndsp
->pipeline
);
1103 list_add_tail(&ndsp
->list
, &dsp_ilist
);
1104 spin_unlock_irqrestore(&dsp_lock
, flags
);
1110 static struct Bprotocol DSP
= {
1111 .Bprotocols
= (1 << (ISDN_P_B_L2DSP
& ISDN_P_B_MASK
))
1112 | (1 << (ISDN_P_B_L2DSPHDLC
& ISDN_P_B_MASK
)),
1117 static int dsp_init(void)
1122 printk(KERN_INFO
"DSP modul %s\n", mISDN_dsp_revision
);
1124 dsp_options
= options
;
1127 /* set packet size */
1130 if (dsp_poll
> MAX_POLL
) {
1131 printk(KERN_ERR
"%s: Wrong poll value (%d), use %d "
1132 "maximum.\n", __func__
, poll
, MAX_POLL
);
1137 printk(KERN_ERR
"%s: Wrong poll value (%d), use 8 "
1138 "minimum.\n", __func__
, dsp_poll
);
1142 dsp_tics
= poll
* HZ
/ 8000;
1143 if (dsp_tics
* 8000 != poll
* HZ
) {
1144 printk(KERN_INFO
"mISDN_dsp: Cannot clock every %d "
1145 "samples (0,125 ms). It is not a multiple of "
1146 "%d HZ.\n", poll
, HZ
);
1152 while (poll
<= MAX_POLL
) {
1153 tics
= (poll
* HZ
) / 8000;
1154 if (tics
* 8000 == poll
* HZ
) {
1163 if (dsp_poll
== 0) {
1164 printk(KERN_INFO
"mISDN_dsp: There is no multiple of kernel "
1165 "clock that equals exactly the duration of 8-256 "
1166 "samples. (Choose kernel clock speed like 100, 250, "
1171 printk(KERN_INFO
"mISDN_dsp: DSP clocks every %d samples. This equals "
1172 "%d jiffies.\n", dsp_poll
, dsp_tics
);
1174 spin_lock_init(&dsp_lock
);
1175 INIT_LIST_HEAD(&dsp_ilist
);
1176 INIT_LIST_HEAD(&conf_ilist
);
1178 /* init conversion tables */
1179 dsp_audio_generate_law_tables();
1180 dsp_silence
= (dsp_options
&DSP_OPT_ULAW
) ? 0xff : 0x2a;
1181 dsp_audio_law_to_s32
= (dsp_options
&DSP_OPT_ULAW
) ?
1182 dsp_audio_ulaw_to_s32
: dsp_audio_alaw_to_s32
;
1183 dsp_audio_generate_s2law_table();
1184 dsp_audio_generate_seven();
1185 dsp_audio_generate_mix_table();
1186 if (dsp_options
& DSP_OPT_ULAW
)
1187 dsp_audio_generate_ulaw_samples();
1188 dsp_audio_generate_volume_changes();
1190 err
= dsp_pipeline_module_init();
1192 printk(KERN_ERR
"mISDN_dsp: Can't initialize pipeline, "
1193 "error(%d)\n", err
);
1197 err
= mISDN_register_Bprotocol(&DSP
);
1199 printk(KERN_ERR
"Can't register %s error(%d)\n", DSP
.name
, err
);
1203 /* set sample timer */
1204 dsp_spl_tl
.function
= (void *)dsp_cmx_send
;
1205 dsp_spl_tl
.data
= 0;
1206 init_timer(&dsp_spl_tl
);
1207 dsp_spl_tl
.expires
= jiffies
+ dsp_tics
;
1208 dsp_spl_jiffies
= dsp_spl_tl
.expires
;
1209 add_timer(&dsp_spl_tl
);
1215 static void dsp_cleanup(void)
1217 mISDN_unregister_Bprotocol(&DSP
);
1219 if (timer_pending(&dsp_spl_tl
))
1220 del_timer(&dsp_spl_tl
);
1222 if (!list_empty(&dsp_ilist
)) {
1223 printk(KERN_ERR
"mISDN_dsp: Audio DSP object inst list not "
1226 if (!list_empty(&conf_ilist
)) {
1227 printk(KERN_ERR
"mISDN_dsp: Conference list not empty. Not "
1228 "all memory freed.\n");
1231 dsp_pipeline_module_exit();
1234 module_init(dsp_init
);
1235 module_exit(dsp_cleanup
);