2 * Audio crossconnecting/conferrencing (hardware level).
4 * Copyright 2002 by Andreas Eversberg (jolly@eversberg.eu)
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
12 * The process of adding and removing parties to/from a conference:
14 * There is a chain of struct dsp_conf which has one or more members in a chain
15 * of struct dsp_conf_member.
17 * After a party is added, the conference is checked for hardware capability.
18 * Also if a party is removed, the conference is checked again.
20 * There are 3 different solutions: -1 = software, 0 = hardware-crossconnect
21 * 1-n = hardware-conference. The n will give the conference number.
23 * Depending on the change after removal or insertion of a party, hardware
26 * The current solution is stored within the struct dsp_conf entry.
32 * There are 3 types of interaction: One member is alone, in this case only
33 * data flow from upper to lower layer is done.
34 * Two members will also exchange their data so they are crossconnected.
35 * Three or more members will be added in a conference and will hear each
36 * other but will not receive their own speech (echo) if not enabled.
38 * Features of CMX are:
39 * - Crossconnecting or even conference, if more than two members are together.
40 * - Force mixing of transmit data with other crossconnect/conference members.
41 * - Echo generation to benchmark the delay of audio processing.
42 * - Use hardware to minimize cpu load, disable FIFO load and minimize delay.
43 * - Dejittering and clock generation.
45 * There are 2 buffers:
51 * ----------------+-------------+-------------------
53 * The rx-buffer is a ring buffer used to store the received data for each
54 * individual member. This is only the case if data needs to be dejittered
55 * or in case of a conference where different clocks require reclocking.
56 * The transmit-clock (R) will read the buffer.
57 * If the clock overruns the write-pointer, we will have a buffer underrun.
58 * If the write pointer always has a certain distance from the transmit-
59 * clock, we will have a delay. The delay will dynamically be increased and
66 * -----------------+--------+-----------------------
68 * The tx-buffer is a ring buffer to queue the transmit data from user space
69 * until it will be mixed or sent. There are two pointers, R and W. If the write
70 * pointer W would reach or overrun R, the buffer would overrun. In this case
71 * (some) data is dropped so that it will not overrun.
72 * Additionally a dynamic dejittering can be enabled. this allows data from
73 * user space that have jitter and different clock source.
78 * A Clock is not required, if the data source has exactly one clock. In this
79 * case the data source is forwarded to the destination.
81 * A Clock is required, because the data source
82 * - has multiple clocks.
83 * - has no usable clock due to jitter or packet loss (VoIP).
84 * In this case the system's clock is used. The clock resolution depends on
85 * the jiffie resolution.
87 * If a member joins a conference:
89 * - If a member joins, its rx_buff is set to silence and change read pointer
92 * The procedure of received data from card is explained in cmx_receive.
93 * The procedure of received data from user space is explained in cmx_transmit.
94 * The procedure of transmit data to card is cmx_send.
97 * Interaction with other features:
100 * DTMF decoding is done before the data is crossconnected.
103 * Changing rx-volume is done before the data is crossconnected. The tx-volume
104 * must be changed whenever data is transmitted to the card by the cmx.
107 * If a tone is enabled, it will be processed whenever data is transmitted to
108 * the card. It will replace the tx-data from the user space.
109 * If tones are generated by hardware, this conference member is removed for
113 * If cmx is realized in hardware, rx data will be disabled if requested by
114 * the upper layer. If dtmf decoding is done by software and enabled, rx data
115 * will not be disabled but blocked to the upper layer.
117 * HFC conference engine:
118 * If it is possible to realize all features using hardware, hardware will be
119 * used if not forbidden by control command. Disabling rx-data provides
120 * absolutely traffic free audio processing. (except for the quick 1-frame
121 * upload of a tone loop, only once for a new tone)
125 /* delay.h is required for hw_lock.h */
127 #include <linux/slab.h>
128 #include <linux/delay.h>
129 #include <linux/mISDNif.h>
130 #include <linux/mISDNdsp.h>
134 * debugging of multi party conference,
135 * by using conference even with two members
138 /* #define CMX_CONF_DEBUG */
140 /*#define CMX_DEBUG * massive read/write pointer output */
141 /*#define CMX_DELAY_DEBUG * gives rx-buffer delay overview */
142 /*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */
145 count_list_member(struct list_head
*head
)
150 list_for_each(m
, head
)
156 * debug cmx memory structure
159 dsp_cmx_debug(struct dsp
*dsp
)
161 struct dsp_conf
*conf
;
162 struct dsp_conf_member
*member
;
165 printk(KERN_DEBUG
"-----Current DSP\n");
166 list_for_each_entry(odsp
, &dsp_ilist
, list
) {
167 printk(KERN_DEBUG
"* %s hardecho=%d softecho=%d txmix=%d",
168 odsp
->name
, odsp
->echo
.hardware
, odsp
->echo
.software
,
171 printk(" (Conf %d)", odsp
->conf
->id
);
176 printk(KERN_DEBUG
"-----Current Conf:\n");
177 list_for_each_entry(conf
, &conf_ilist
, list
) {
178 printk(KERN_DEBUG
"* Conf %d (%p)\n", conf
->id
, conf
);
179 list_for_each_entry(member
, &conf
->mlist
, list
) {
181 " - member = %s (slot_tx %d, bank_tx %d, "
182 "slot_rx %d, bank_rx %d hfc_conf %d "
183 "tx_data %d rx_is_off %d)%s\n",
184 member
->dsp
->name
, member
->dsp
->pcm_slot_tx
,
185 member
->dsp
->pcm_bank_tx
, member
->dsp
->pcm_slot_rx
,
186 member
->dsp
->pcm_bank_rx
, member
->dsp
->hfc_conf
,
187 member
->dsp
->tx_data
, member
->dsp
->rx_is_off
,
188 (member
->dsp
== dsp
) ? " *this*" : "");
191 printk(KERN_DEBUG
"-----end\n");
197 static struct dsp_conf
*
198 dsp_cmx_search_conf(u32 id
)
200 struct dsp_conf
*conf
;
203 printk(KERN_WARNING
"%s: conference ID is 0.\n", __func__
);
207 /* search conference */
208 list_for_each_entry(conf
, &conf_ilist
, list
)
217 * add member to conference
220 dsp_cmx_add_conf_member(struct dsp
*dsp
, struct dsp_conf
*conf
)
222 struct dsp_conf_member
*member
;
225 printk(KERN_WARNING
"%s: conf or dsp is 0.\n", __func__
);
229 printk(KERN_WARNING
"%s: dsp is already member in a conf.\n",
235 printk(KERN_WARNING
"%s: dsp is already in a conf.\n",
240 member
= kzalloc(sizeof(struct dsp_conf_member
), GFP_ATOMIC
);
242 printk(KERN_ERR
"kzalloc struct dsp_conf_member failed\n");
246 /* clear rx buffer */
247 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
248 dsp
->rx_init
= 1; /* rx_W and rx_R will be adjusted on first frame */
252 list_add_tail(&member
->list
, &conf
->mlist
);
255 dsp
->member
= member
;
262 * del member from conference
265 dsp_cmx_del_conf_member(struct dsp
*dsp
)
267 struct dsp_conf_member
*member
;
270 printk(KERN_WARNING
"%s: dsp is 0.\n",
276 printk(KERN_WARNING
"%s: dsp is not in a conf.\n",
281 if (list_empty(&dsp
->conf
->mlist
)) {
282 printk(KERN_WARNING
"%s: dsp has linked an empty conf.\n",
287 /* find us in conf */
288 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
289 if (member
->dsp
== dsp
) {
290 list_del(&member
->list
);
298 "%s: dsp is not present in its own conf_member list.\n",
308 static struct dsp_conf
309 *dsp_cmx_new_conf(u32 id
)
311 struct dsp_conf
*conf
;
314 printk(KERN_WARNING
"%s: id is 0.\n",
319 conf
= kzalloc(sizeof(struct dsp_conf
), GFP_ATOMIC
);
321 printk(KERN_ERR
"kzalloc struct dsp_conf failed\n");
324 INIT_LIST_HEAD(&conf
->mlist
);
327 list_add_tail(&conf
->list
, &conf_ilist
);
337 dsp_cmx_del_conf(struct dsp_conf
*conf
)
340 printk(KERN_WARNING
"%s: conf is null.\n",
345 if (!list_empty(&conf
->mlist
)) {
346 printk(KERN_WARNING
"%s: conf not empty.\n",
350 list_del(&conf
->list
);
358 * send HW message to hfc card
361 dsp_cmx_hw_message(struct dsp
*dsp
, u32 message
, u32 param1
, u32 param2
,
362 u32 param3
, u32 param4
)
364 struct mISDN_ctrl_req cq
;
366 memset(&cq
, 0, sizeof(cq
));
368 cq
.p1
= param1
| (param2
<< 8);
369 cq
.p2
= param3
| (param4
<< 8);
371 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
);
376 * do hardware update and set the software/hardware flag
378 * either a conference or a dsp instance can be given
379 * if only dsp instance is given, the instance is not associated with a conf
380 * and therefore removed. if a conference is given, the dsp is expected to
381 * be member of that conference.
384 dsp_cmx_hardware(struct dsp_conf
*conf
, struct dsp
*dsp
)
386 struct dsp_conf_member
*member
, *nextm
;
388 int memb
= 0, i
, ii
, i1
, i2
;
390 u_char freeslots
[256];
391 int same_hfc
= -1, same_pcm
= -1, current_conf
= -1,
392 all_conf
= 1, tx_data
= 0;
394 /* dsp gets updated (no conf) */
398 if (dsp_debug
& DEBUG_DSP_CMX
)
399 printk(KERN_DEBUG
"%s checking dsp %s\n",
400 __func__
, dsp
->name
);
402 /* remove HFC conference if enabled */
403 if (dsp
->hfc_conf
>= 0) {
404 if (dsp_debug
& DEBUG_DSP_CMX
)
406 "%s removing %s from HFC conf %d "
407 "because dsp is split\n", __func__
,
408 dsp
->name
, dsp
->hfc_conf
);
409 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_CONF_SPLIT
,
413 /* process hw echo */
414 if (dsp
->features
.pcm_banks
< 1)
416 if (!dsp
->echo
.software
&& !dsp
->echo
.hardware
) {
417 /* NO ECHO: remove PCM slot if assigned */
418 if (dsp
->pcm_slot_tx
>= 0 || dsp
->pcm_slot_rx
>= 0) {
419 if (dsp_debug
& DEBUG_DSP_CMX
)
420 printk(KERN_DEBUG
"%s removing %s from"
421 " PCM slot %d (TX) %d (RX) because"
422 " dsp is split (no echo)\n",
424 dsp
->pcm_slot_tx
, dsp
->pcm_slot_rx
);
425 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_DISC
,
427 dsp
->pcm_slot_tx
= -1;
428 dsp
->pcm_bank_tx
= -1;
429 dsp
->pcm_slot_rx
= -1;
430 dsp
->pcm_bank_rx
= -1;
434 /* echo is enabled, find out if we use soft or hardware */
435 dsp
->echo
.software
= dsp
->tx_data
;
436 dsp
->echo
.hardware
= 0;
437 /* ECHO: already echo */
438 if (dsp
->pcm_slot_tx
>= 0 && dsp
->pcm_slot_rx
< 0 &&
439 dsp
->pcm_bank_tx
== 2 && dsp
->pcm_bank_rx
== 2) {
440 dsp
->echo
.hardware
= 1;
443 /* ECHO: if slot already assigned */
444 if (dsp
->pcm_slot_tx
>= 0) {
445 dsp
->pcm_slot_rx
= dsp
->pcm_slot_tx
;
446 dsp
->pcm_bank_tx
= 2; /* 2 means loop */
447 dsp
->pcm_bank_rx
= 2;
448 if (dsp_debug
& DEBUG_DSP_CMX
)
450 "%s refresh %s for echo using slot %d\n",
453 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
454 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
455 dsp
->echo
.hardware
= 1;
458 /* ECHO: find slot */
459 dsp
->pcm_slot_tx
= -1;
460 dsp
->pcm_slot_rx
= -1;
461 memset(freeslots
, 1, sizeof(freeslots
));
462 list_for_each_entry(finddsp
, &dsp_ilist
, list
) {
463 if (finddsp
->features
.pcm_id
== dsp
->features
.pcm_id
) {
464 if (finddsp
->pcm_slot_rx
>= 0 &&
465 finddsp
->pcm_slot_rx
< sizeof(freeslots
))
466 freeslots
[finddsp
->pcm_slot_rx
] = 0;
467 if (finddsp
->pcm_slot_tx
>= 0 &&
468 finddsp
->pcm_slot_tx
< sizeof(freeslots
))
469 freeslots
[finddsp
->pcm_slot_tx
] = 0;
473 ii
= dsp
->features
.pcm_slots
;
480 if (dsp_debug
& DEBUG_DSP_CMX
)
482 "%s no slot available for echo\n",
484 /* no more slots available */
485 dsp
->echo
.software
= 1;
488 /* assign free slot */
489 dsp
->pcm_slot_tx
= i
;
490 dsp
->pcm_slot_rx
= i
;
491 dsp
->pcm_bank_tx
= 2; /* loop */
492 dsp
->pcm_bank_rx
= 2;
493 if (dsp_debug
& DEBUG_DSP_CMX
)
495 "%s assign echo for %s using slot %d\n",
496 __func__
, dsp
->name
, dsp
->pcm_slot_tx
);
497 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
498 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
499 dsp
->echo
.hardware
= 1;
503 /* conf gets updated (all members) */
504 if (dsp_debug
& DEBUG_DSP_CMX
)
505 printk(KERN_DEBUG
"%s checking conference %d\n",
508 if (list_empty(&conf
->mlist
)) {
509 printk(KERN_ERR
"%s: conference without members\n",
513 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
, list
);
514 same_hfc
= member
->dsp
->features
.hfc_id
;
515 same_pcm
= member
->dsp
->features
.pcm_id
;
516 /* check all members in our conference */
517 list_for_each_entry(member
, &conf
->mlist
, list
) {
518 /* check if member uses mixing */
519 if (member
->dsp
->tx_mix
) {
520 if (dsp_debug
& DEBUG_DSP_CMX
)
522 "%s dsp %s cannot form a conf, because "
523 "tx_mix is turned on\n", __func__
,
526 list_for_each_entry(member
, &conf
->mlist
, list
) {
528 /* remove HFC conference if enabled */
529 if (dsp
->hfc_conf
>= 0) {
530 if (dsp_debug
& DEBUG_DSP_CMX
)
532 "%s removing %s from HFC "
533 "conf %d because not "
534 "possible with hardware\n",
538 dsp_cmx_hw_message(dsp
,
539 MISDN_CTRL_HFC_CONF_SPLIT
,
543 /* remove PCM slot if assigned */
544 if (dsp
->pcm_slot_tx
>= 0 ||
545 dsp
->pcm_slot_rx
>= 0) {
546 if (dsp_debug
& DEBUG_DSP_CMX
)
547 printk(KERN_DEBUG
"%s removing "
548 "%s from PCM slot %d (TX)"
549 " slot %d (RX) because not"
550 " possible with hardware\n",
555 dsp_cmx_hw_message(dsp
,
556 MISDN_CTRL_HFC_PCM_DISC
,
558 dsp
->pcm_slot_tx
= -1;
559 dsp
->pcm_bank_tx
= -1;
560 dsp
->pcm_slot_rx
= -1;
561 dsp
->pcm_bank_rx
= -1;
568 /* check if member has echo turned on */
569 if (member
->dsp
->echo
.hardware
|| member
->dsp
->echo
.software
) {
570 if (dsp_debug
& DEBUG_DSP_CMX
)
572 "%s dsp %s cannot form a conf, because "
573 "echo is turned on\n", __func__
,
577 /* check if member has tx_mix turned on */
578 if (member
->dsp
->tx_mix
) {
579 if (dsp_debug
& DEBUG_DSP_CMX
)
581 "%s dsp %s cannot form a conf, because "
582 "tx_mix is turned on\n",
583 __func__
, member
->dsp
->name
);
586 /* check if member changes volume at an not suppoted level */
587 if (member
->dsp
->tx_volume
) {
588 if (dsp_debug
& DEBUG_DSP_CMX
)
590 "%s dsp %s cannot form a conf, because "
591 "tx_volume is changed\n",
592 __func__
, member
->dsp
->name
);
595 if (member
->dsp
->rx_volume
) {
596 if (dsp_debug
& DEBUG_DSP_CMX
)
598 "%s dsp %s cannot form a conf, because "
599 "rx_volume is changed\n",
600 __func__
, member
->dsp
->name
);
603 /* check if tx-data turned on */
604 if (member
->dsp
->tx_data
) {
605 if (dsp_debug
& DEBUG_DSP_CMX
)
607 "%s dsp %s tx_data is turned on\n",
608 __func__
, member
->dsp
->name
);
611 /* check if pipeline exists */
612 if (member
->dsp
->pipeline
.inuse
) {
613 if (dsp_debug
& DEBUG_DSP_CMX
)
615 "%s dsp %s cannot form a conf, because "
616 "pipeline exists\n", __func__
,
620 /* check if encryption is enabled */
621 if (member
->dsp
->bf_enable
) {
622 if (dsp_debug
& DEBUG_DSP_CMX
)
623 printk(KERN_DEBUG
"%s dsp %s cannot form a "
624 "conf, because encryption is enabled\n",
625 __func__
, member
->dsp
->name
);
628 /* check if member is on a card with PCM support */
629 if (member
->dsp
->features
.pcm_id
< 0) {
630 if (dsp_debug
& DEBUG_DSP_CMX
)
632 "%s dsp %s cannot form a conf, because "
633 "dsp has no PCM bus\n",
634 __func__
, member
->dsp
->name
);
637 /* check if relations are on the same PCM bus */
638 if (member
->dsp
->features
.pcm_id
!= same_pcm
) {
639 if (dsp_debug
& DEBUG_DSP_CMX
)
641 "%s dsp %s cannot form a conf, because "
642 "dsp is on a different PCM bus than the "
644 __func__
, member
->dsp
->name
);
647 /* determine if members are on the same hfc chip */
648 if (same_hfc
!= member
->dsp
->features
.hfc_id
)
650 /* if there are members already in a conference */
651 if (current_conf
< 0 && member
->dsp
->hfc_conf
>= 0)
652 current_conf
= member
->dsp
->hfc_conf
;
653 /* if any member is not in a conference */
654 if (member
->dsp
->hfc_conf
< 0)
660 /* if no member, this is an error */
666 if (dsp_debug
& DEBUG_DSP_CMX
)
668 "%s conf %d cannot form a HW conference, "
669 "because dsp is alone\n", __func__
, conf
->id
);
672 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
679 * ok, now we are sure that all members are on the same pcm.
680 * now we will see if we have only two members, so we can do
681 * crossconnections, which don't have any limitations.
684 /* if we have only two members */
686 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
688 nextm
= list_entry(member
->list
.next
, struct dsp_conf_member
,
690 /* remove HFC conference if enabled */
691 if (member
->dsp
->hfc_conf
>= 0) {
692 if (dsp_debug
& DEBUG_DSP_CMX
)
694 "%s removing %s from HFC conf %d because "
695 "two parties require only a PCM slot\n",
696 __func__
, member
->dsp
->name
,
697 member
->dsp
->hfc_conf
);
698 dsp_cmx_hw_message(member
->dsp
,
699 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
700 member
->dsp
->hfc_conf
= -1;
702 if (nextm
->dsp
->hfc_conf
>= 0) {
703 if (dsp_debug
& DEBUG_DSP_CMX
)
705 "%s removing %s from HFC conf %d because "
706 "two parties require only a PCM slot\n",
707 __func__
, nextm
->dsp
->name
,
708 nextm
->dsp
->hfc_conf
);
709 dsp_cmx_hw_message(nextm
->dsp
,
710 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
711 nextm
->dsp
->hfc_conf
= -1;
713 /* if members have two banks (and not on the same chip) */
714 if (member
->dsp
->features
.pcm_banks
> 1 &&
715 nextm
->dsp
->features
.pcm_banks
> 1 &&
716 member
->dsp
->features
.hfc_id
!=
717 nextm
->dsp
->features
.hfc_id
) {
718 /* if both members have same slots with crossed banks */
719 if (member
->dsp
->pcm_slot_tx
>= 0 &&
720 member
->dsp
->pcm_slot_rx
>= 0 &&
721 nextm
->dsp
->pcm_slot_tx
>= 0 &&
722 nextm
->dsp
->pcm_slot_rx
>= 0 &&
723 nextm
->dsp
->pcm_slot_tx
==
724 member
->dsp
->pcm_slot_rx
&&
725 nextm
->dsp
->pcm_slot_rx
==
726 member
->dsp
->pcm_slot_tx
&&
727 nextm
->dsp
->pcm_slot_tx
==
728 member
->dsp
->pcm_slot_tx
&&
729 member
->dsp
->pcm_bank_tx
!=
730 member
->dsp
->pcm_bank_rx
&&
731 nextm
->dsp
->pcm_bank_tx
!=
732 nextm
->dsp
->pcm_bank_rx
) {
733 /* all members have same slot */
734 if (dsp_debug
& DEBUG_DSP_CMX
)
736 "%s dsp %s & %s stay joined on "
737 "PCM slot %d bank %d (TX) bank %d "
738 "(RX) (on different chips)\n",
742 member
->dsp
->pcm_slot_tx
,
743 member
->dsp
->pcm_bank_tx
,
744 member
->dsp
->pcm_bank_rx
);
746 conf
->software
= tx_data
;
749 /* find a new slot */
750 memset(freeslots
, 1, sizeof(freeslots
));
751 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
752 if (dsp
!= member
->dsp
&&
754 member
->dsp
->features
.pcm_id
==
755 dsp
->features
.pcm_id
) {
756 if (dsp
->pcm_slot_rx
>= 0 &&
759 freeslots
[dsp
->pcm_slot_rx
] = 0;
760 if (dsp
->pcm_slot_tx
>= 0 &&
763 freeslots
[dsp
->pcm_slot_tx
] = 0;
767 ii
= member
->dsp
->features
.pcm_slots
;
774 if (dsp_debug
& DEBUG_DSP_CMX
)
776 "%s no slot available for "
777 "%s & %s\n", __func__
,
780 /* no more slots available */
783 /* assign free slot */
784 member
->dsp
->pcm_slot_tx
= i
;
785 member
->dsp
->pcm_slot_rx
= i
;
786 nextm
->dsp
->pcm_slot_tx
= i
;
787 nextm
->dsp
->pcm_slot_rx
= i
;
788 member
->dsp
->pcm_bank_rx
= 0;
789 member
->dsp
->pcm_bank_tx
= 1;
790 nextm
->dsp
->pcm_bank_rx
= 1;
791 nextm
->dsp
->pcm_bank_tx
= 0;
792 if (dsp_debug
& DEBUG_DSP_CMX
)
794 "%s adding %s & %s to new PCM slot %d "
795 "(TX and RX on different chips) because "
796 "both members have not same slots\n",
800 member
->dsp
->pcm_slot_tx
);
801 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
802 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
803 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
804 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
805 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
806 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
808 conf
->software
= tx_data
;
810 /* if members have one bank (or on the same chip) */
812 /* if both members have different crossed slots */
813 if (member
->dsp
->pcm_slot_tx
>= 0 &&
814 member
->dsp
->pcm_slot_rx
>= 0 &&
815 nextm
->dsp
->pcm_slot_tx
>= 0 &&
816 nextm
->dsp
->pcm_slot_rx
>= 0 &&
817 nextm
->dsp
->pcm_slot_tx
==
818 member
->dsp
->pcm_slot_rx
&&
819 nextm
->dsp
->pcm_slot_rx
==
820 member
->dsp
->pcm_slot_tx
&&
821 member
->dsp
->pcm_slot_tx
!=
822 member
->dsp
->pcm_slot_rx
&&
823 member
->dsp
->pcm_bank_tx
== 0 &&
824 member
->dsp
->pcm_bank_rx
== 0 &&
825 nextm
->dsp
->pcm_bank_tx
== 0 &&
826 nextm
->dsp
->pcm_bank_rx
== 0) {
827 /* all members have same slot */
828 if (dsp_debug
& DEBUG_DSP_CMX
)
830 "%s dsp %s & %s stay joined on PCM "
831 "slot %d (TX) %d (RX) on same chip "
832 "or one bank PCM)\n", __func__
,
835 member
->dsp
->pcm_slot_tx
,
836 member
->dsp
->pcm_slot_rx
);
838 conf
->software
= tx_data
;
841 /* find two new slot */
842 memset(freeslots
, 1, sizeof(freeslots
));
843 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
844 if (dsp
!= member
->dsp
&&
846 member
->dsp
->features
.pcm_id
==
847 dsp
->features
.pcm_id
) {
848 if (dsp
->pcm_slot_rx
>= 0 &&
851 freeslots
[dsp
->pcm_slot_rx
] = 0;
852 if (dsp
->pcm_slot_tx
>= 0 &&
855 freeslots
[dsp
->pcm_slot_tx
] = 0;
859 ii
= member
->dsp
->features
.pcm_slots
;
866 if (dsp_debug
& DEBUG_DSP_CMX
)
868 "%s no slot available "
869 "for %s & %s\n", __func__
,
872 /* no more slots available */
882 if (dsp_debug
& DEBUG_DSP_CMX
)
884 "%s no slot available "
889 /* no more slots available */
892 /* assign free slots */
893 member
->dsp
->pcm_slot_tx
= i1
;
894 member
->dsp
->pcm_slot_rx
= i2
;
895 nextm
->dsp
->pcm_slot_tx
= i2
;
896 nextm
->dsp
->pcm_slot_rx
= i1
;
897 member
->dsp
->pcm_bank_rx
= 0;
898 member
->dsp
->pcm_bank_tx
= 0;
899 nextm
->dsp
->pcm_bank_rx
= 0;
900 nextm
->dsp
->pcm_bank_tx
= 0;
901 if (dsp_debug
& DEBUG_DSP_CMX
)
903 "%s adding %s & %s to new PCM slot %d "
904 "(TX) %d (RX) on same chip or one bank "
905 "PCM, because both members have not "
906 "crossed slots\n", __func__
,
909 member
->dsp
->pcm_slot_tx
,
910 member
->dsp
->pcm_slot_rx
);
911 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
912 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
913 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
914 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
915 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
916 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
918 conf
->software
= tx_data
;
924 * if we have more than two, we may check if we have a conference
925 * unit available on the chip. also all members must be on the same
928 /* if not the same HFC chip */
930 if (dsp_debug
& DEBUG_DSP_CMX
)
932 "%s conference %d cannot be formed, because "
933 "members are on different chips or not "
939 /* for more than two members.. */
941 /* if all members already have the same conference */
944 conf
->software
= tx_data
;
949 * if there is an existing conference, but not all members have joined
951 if (current_conf
>= 0) {
953 list_for_each_entry(member
, &conf
->mlist
, list
) {
954 /* if no conference engine on our chip, change to
956 if (!member
->dsp
->features
.hfc_conf
)
958 /* in case of hdlc, change to software */
959 if (member
->dsp
->hdlc
)
961 /* join to current conference */
962 if (member
->dsp
->hfc_conf
== current_conf
)
964 /* get a free timeslot first */
965 memset(freeslots
, 1, sizeof(freeslots
));
966 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
968 * not checking current member, because
969 * slot will be overwritten.
972 dsp
!= member
->dsp
&&
973 /* dsp must be on the same PCM */
974 member
->dsp
->features
.pcm_id
==
975 dsp
->features
.pcm_id
) {
976 /* dsp must be on a slot */
977 if (dsp
->pcm_slot_tx
>= 0 &&
980 freeslots
[dsp
->pcm_slot_tx
] = 0;
981 if (dsp
->pcm_slot_rx
>= 0 &&
984 freeslots
[dsp
->pcm_slot_rx
] = 0;
988 ii
= member
->dsp
->features
.pcm_slots
;
995 /* no more slots available */
996 if (dsp_debug
& DEBUG_DSP_CMX
)
998 "%s conference %d cannot be formed,"
999 " because no slot free\n",
1000 __func__
, conf
->id
);
1003 if (dsp_debug
& DEBUG_DSP_CMX
)
1005 "%s changing dsp %s to HW conference "
1006 "%d slot %d\n", __func__
,
1007 member
->dsp
->name
, current_conf
, i
);
1008 /* assign free slot & set PCM & join conf */
1009 member
->dsp
->pcm_slot_tx
= i
;
1010 member
->dsp
->pcm_slot_rx
= i
;
1011 member
->dsp
->pcm_bank_tx
= 2; /* loop */
1012 member
->dsp
->pcm_bank_rx
= 2;
1013 member
->dsp
->hfc_conf
= current_conf
;
1014 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
1016 dsp_cmx_hw_message(member
->dsp
,
1017 MISDN_CTRL_HFC_CONF_JOIN
, current_conf
, 0, 0, 0);
1020 conf
->software
= tx_data
;
1025 * no member is in a conference yet, so we find a free one
1027 memset(freeunits
, 1, sizeof(freeunits
));
1028 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1029 /* dsp must be on the same chip */
1030 if (dsp
->features
.hfc_id
== same_hfc
&&
1031 /* dsp must have joined a HW conference */
1032 dsp
->hfc_conf
>= 0 &&
1033 /* slot must be within range */
1035 freeunits
[dsp
->hfc_conf
] = 0;
1045 /* no more conferences available */
1046 if (dsp_debug
& DEBUG_DSP_CMX
)
1048 "%s conference %d cannot be formed, because "
1049 "no conference number free\n",
1050 __func__
, conf
->id
);
1053 /* join all members */
1060 * conf_id != 0: join or change conference
1061 * conf_id == 0: split from conference if not already
1064 dsp_cmx_conf(struct dsp
*dsp
, u32 conf_id
)
1067 struct dsp_conf
*conf
;
1068 struct dsp_conf_member
*member
;
1070 /* if conference doesn't change */
1071 if (dsp
->conf_id
== conf_id
)
1074 /* first remove us from current conf */
1076 if (dsp_debug
& DEBUG_DSP_CMX
)
1077 printk(KERN_DEBUG
"removing us from conference %d\n",
1079 /* remove us from conf */
1081 err
= dsp_cmx_del_conf_member(dsp
);
1086 /* update hardware */
1087 dsp_cmx_hardware(NULL
, dsp
);
1089 /* conf now empty? */
1090 if (list_empty(&conf
->mlist
)) {
1091 if (dsp_debug
& DEBUG_DSP_CMX
)
1093 "conference is empty, so we remove it.\n");
1094 err
= dsp_cmx_del_conf(conf
);
1098 /* update members left on conf */
1099 dsp_cmx_hardware(conf
, NULL
);
1107 /* now add us to conf */
1108 if (dsp_debug
& DEBUG_DSP_CMX
)
1109 printk(KERN_DEBUG
"searching conference %d\n",
1111 conf
= dsp_cmx_search_conf(conf_id
);
1113 if (dsp_debug
& DEBUG_DSP_CMX
)
1115 "conference doesn't exist yet, creating.\n");
1116 /* the conference doesn't exist, so we create */
1117 conf
= dsp_cmx_new_conf(conf_id
);
1120 } else if (!list_empty(&conf
->mlist
)) {
1121 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
1123 if (dsp
->hdlc
&& !member
->dsp
->hdlc
) {
1124 if (dsp_debug
& DEBUG_DSP_CMX
)
1126 "cannot join transparent conference.\n");
1129 if (!dsp
->hdlc
&& member
->dsp
->hdlc
) {
1130 if (dsp_debug
& DEBUG_DSP_CMX
)
1132 "cannot join hdlc conference.\n");
1136 /* add conference member */
1137 err
= dsp_cmx_add_conf_member(dsp
, conf
);
1140 dsp
->conf_id
= conf_id
;
1142 /* if we are alone, we do nothing! */
1143 if (list_empty(&conf
->mlist
)) {
1144 if (dsp_debug
& DEBUG_DSP_CMX
)
1146 "we are alone in this conference, so exit.\n");
1147 /* update hardware */
1148 dsp_cmx_hardware(NULL
, dsp
);
1152 /* update members on conf */
1153 dsp_cmx_hardware(conf
, NULL
);
1158 #ifdef CMX_DELAY_DEBUG
1161 showdelay(struct dsp
*dsp
, int samples
, int delay
)
1163 char bar
[] = "--------------------------------------------------|";
1166 delaycount
+= samples
;
1167 if (delaycount
< 8000)
1171 sdelay
= delay
* 50 / (dsp_poll
<< 2);
1173 printk(KERN_DEBUG
"DELAY (%s) %3d >%s\n", dsp
->name
, delay
,
1174 sdelay
> 50 ? "..." : bar
+ 50 - sdelay
);
1179 * audio data is received from card
1182 dsp_cmx_receive(struct dsp
*dsp
, struct sk_buff
*skb
)
1186 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1189 /* check if we have sompen */
1193 /* half of the buffer should be larger than maximum packet size */
1194 if (len
>= CMX_BUFF_HALF
) {
1196 "%s line %d: packet from card is too large (%d bytes). "
1197 "please make card send smaller packets OR increase "
1198 "CMX_BUFF_SIZE\n", __FILE__
, __LINE__
, len
);
1203 * initialize pointers if not already -
1204 * also add delay if requested by PH_SIGNAL
1208 if (dsp
->features
.unordered
) {
1209 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1211 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1214 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1219 dsp
->rx_W
= dsp
->cmx_delay
;
1221 dsp
->rx_W
= dsp_poll
>> 1;
1224 /* if frame contains time code, write directly */
1225 if (dsp
->features
.unordered
) {
1226 dsp
->rx_W
= (hh
->id
& CMX_BUFF_MASK
);
1227 /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1230 * if we underrun (or maybe overrun),
1231 * we set our new read pointer, and write silence to buffer
1233 if (((dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
) >= CMX_BUFF_HALF
) {
1234 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1236 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1237 "maximum delay), adjusting read pointer! "
1238 "(inst %s)\n", (u_long
)dsp
, dsp
->name
);
1239 /* flush rx buffer and set delay to dsp_poll / 2 */
1240 if (dsp
->features
.unordered
) {
1241 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1243 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1246 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1251 dsp
->rx_W
= dsp
->cmx_delay
;
1253 dsp
->rx_W
= dsp_poll
>> 1;
1255 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1257 /* if we have reached double delay, jump back to middle */
1259 if (((dsp
->rx_W
- dsp
->rx_R
) & CMX_BUFF_MASK
) >=
1260 (dsp
->cmx_delay
<< 1)) {
1261 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1263 "cmx_receive(dsp=%lx): OVERRUN (because "
1264 "twice the delay is reached), adjusting "
1265 "read pointer! (inst %s)\n",
1266 (u_long
)dsp
, dsp
->name
);
1268 if (dsp
->features
.unordered
) {
1269 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1270 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1274 dsp
->rx_W
= dsp
->cmx_delay
;
1276 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1279 /* show where to write */
1282 "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1283 (u_long
)dsp
, dsp
->rx_R
, dsp
->rx_W
, len
, dsp
->name
);
1286 /* write data into rx_buffer */
1293 d
[w
++ & CMX_BUFF_MASK
] = *p
++;
1297 /* increase write-pointer */
1298 dsp
->rx_W
= ((dsp
->rx_W
+ len
) & CMX_BUFF_MASK
);
1299 #ifdef CMX_DELAY_DEBUG
1300 showdelay(dsp
, len
, (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
);
1306 * send (mixed) audio data to card and control jitter
1309 dsp_cmx_send_member(struct dsp
*dsp
, int len
, s32
*c
, int members
)
1311 struct dsp_conf
*conf
= dsp
->conf
;
1312 struct dsp
*member
, *other
;
1313 register s32 sample
;
1314 u8
*d
, *p
, *q
, *o_q
;
1315 struct sk_buff
*nskb
, *txskb
;
1316 int r
, rr
, t
, tt
, o_r
, o_rr
;
1318 struct mISDNhead
*hh
, *thh
;
1319 int tx_data_only
= 0;
1321 /* don't process if: */
1322 if (!dsp
->b_active
) { /* if not active */
1326 if (((dsp
->conf
&& dsp
->conf
->hardware
) || /* hardware conf */
1327 dsp
->echo
.hardware
) && /* OR hardware echo */
1328 dsp
->tx_R
== dsp
->tx_W
&& /* AND no tx-data */
1329 !(dsp
->tone
.tone
&& dsp
->tone
.software
)) { /* AND not soft tones */
1330 if (!dsp
->tx_data
) { /* no tx_data for user space required */
1334 if (dsp
->conf
&& dsp
->conf
->software
&& dsp
->conf
->hardware
)
1336 if (dsp
->echo
.software
&& dsp
->echo
.hardware
)
1342 "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1343 members
, dsp
->name
, conf
, dsp
->rx_R
, dsp
->rx_W
);
1346 /* preload if we have delay set */
1347 if (dsp
->cmx_delay
&& !dsp
->last_tx
) {
1353 /* PREPARE RESULT */
1354 nskb
= mI_alloc_skb(len
+ preload
, GFP_ATOMIC
);
1357 "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1361 hh
= mISDN_HEAD_P(nskb
);
1362 hh
->prim
= PH_DATA_REQ
;
1366 /* set pointers, indexes and stuff */
1368 p
= dsp
->tx_buff
; /* transmit data */
1369 q
= dsp
->rx_buff
; /* received data */
1370 d
= skb_put(nskb
, preload
+ len
); /* result */
1371 t
= dsp
->tx_R
; /* tx-pointers */
1373 r
= dsp
->rx_R
; /* rx-pointers */
1374 rr
= (r
+ len
) & CMX_BUFF_MASK
;
1376 /* preload with silence, if required */
1378 memset(d
, dsp_silence
, preload
);
1382 /* PROCESS TONES/TX-DATA ONLY */
1383 if (dsp
->tone
.tone
&& dsp
->tone
.software
) {
1385 dsp_tone_copy(dsp
, d
, len
);
1386 dsp
->tx_R
= 0; /* clear tx buffer */
1390 /* if we have tx-data but do not use mixing */
1391 if (!dsp
->tx_mix
&& t
!= tt
) {
1392 /* -> send tx-data and continue when not enough */
1394 sprintf(debugbuf
, "TX sending (%04x-%04x)%p: ", t
, tt
, p
);
1396 while (r
!= rr
&& t
!= tt
) {
1398 if (strlen(debugbuf
) < 48)
1399 sprintf(debugbuf
+ strlen(debugbuf
), " %02x",
1402 *d
++ = p
[t
]; /* write tx_buff */
1403 t
= (t
+ 1) & CMX_BUFF_MASK
;
1404 r
= (r
+ 1) & CMX_BUFF_MASK
;
1409 printk(KERN_DEBUG
"%s\n", debugbuf
);
1415 printk(KERN_DEBUG
"%s\n", debugbuf
);
1418 /* PROCESS DATA (one member / no conf) */
1419 if (!conf
|| members
<= 1) {
1420 /* -> if echo is NOT enabled */
1421 if (!dsp
->echo
.software
) {
1422 /* -> send tx-data if available or use 0-volume */
1423 while (r
!= rr
&& t
!= tt
) {
1424 *d
++ = p
[t
]; /* write tx_buff */
1425 t
= (t
+ 1) & CMX_BUFF_MASK
;
1426 r
= (r
+ 1) & CMX_BUFF_MASK
;
1429 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1430 printk(KERN_DEBUG
"%s: RX empty\n",
1432 memset(d
, dsp_silence
, (rr
- r
) & CMX_BUFF_MASK
);
1434 /* -> if echo is enabled */
1437 * -> mix tx-data with echo if available,
1440 while (r
!= rr
&& t
!= tt
) {
1441 *d
++ = dsp_audio_mix_law
[(p
[t
] << 8) | q
[r
]];
1442 t
= (t
+ 1) & CMX_BUFF_MASK
;
1443 r
= (r
+ 1) & CMX_BUFF_MASK
;
1446 *d
++ = q
[r
]; /* echo */
1447 r
= (r
+ 1) & CMX_BUFF_MASK
;
1453 /* PROCESS DATA (two members) */
1454 #ifdef CMX_CONF_DEBUG
1459 /* "other" becomes other party */
1460 other
= (list_entry(conf
->mlist
.next
,
1461 struct dsp_conf_member
, list
))->dsp
;
1462 if (other
== member
)
1463 other
= (list_entry(conf
->mlist
.prev
,
1464 struct dsp_conf_member
, list
))->dsp
;
1465 o_q
= other
->rx_buff
; /* received data */
1466 o_rr
= (other
->rx_R
+ len
) & CMX_BUFF_MASK
;
1467 /* end of rx-pointer */
1468 o_r
= (o_rr
- rr
+ r
) & CMX_BUFF_MASK
;
1469 /* start rx-pointer at current read position*/
1470 /* -> if echo is NOT enabled */
1471 if (!dsp
->echo
.software
) {
1473 * -> copy other member's rx-data,
1474 * if tx-data is available, mix
1476 while (o_r
!= o_rr
&& t
!= tt
) {
1477 *d
++ = dsp_audio_mix_law
[(p
[t
] << 8) | o_q
[o_r
]];
1478 t
= (t
+ 1) & CMX_BUFF_MASK
;
1479 o_r
= (o_r
+ 1) & CMX_BUFF_MASK
;
1481 while (o_r
!= o_rr
) {
1483 o_r
= (o_r
+ 1) & CMX_BUFF_MASK
;
1485 /* -> if echo is enabled */
1488 * -> mix other member's rx-data with echo,
1489 * if tx-data is available, mix
1491 while (r
!= rr
&& t
!= tt
) {
1492 sample
= dsp_audio_law_to_s32
[p
[t
]] +
1493 dsp_audio_law_to_s32
[q
[r
]] +
1494 dsp_audio_law_to_s32
[o_q
[o_r
]];
1495 if (sample
< -32768)
1497 else if (sample
> 32767)
1499 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1500 /* tx-data + rx_data + echo */
1501 t
= (t
+ 1) & CMX_BUFF_MASK
;
1502 r
= (r
+ 1) & CMX_BUFF_MASK
;
1503 o_r
= (o_r
+ 1) & CMX_BUFF_MASK
;
1506 *d
++ = dsp_audio_mix_law
[(q
[r
] << 8) | o_q
[o_r
]];
1507 r
= (r
+ 1) & CMX_BUFF_MASK
;
1508 o_r
= (o_r
+ 1) & CMX_BUFF_MASK
;
1514 /* PROCESS DATA (three or more members) */
1515 /* -> if echo is NOT enabled */
1516 if (!dsp
->echo
.software
) {
1518 * -> subtract rx-data from conf-data,
1519 * if tx-data is available, mix
1521 while (r
!= rr
&& t
!= tt
) {
1522 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++ -
1523 dsp_audio_law_to_s32
[q
[r
]];
1524 if (sample
< -32768)
1526 else if (sample
> 32767)
1528 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1530 r
= (r
+ 1) & CMX_BUFF_MASK
;
1531 t
= (t
+ 1) & CMX_BUFF_MASK
;
1534 sample
= *c
++ - dsp_audio_law_to_s32
[q
[r
]];
1535 if (sample
< -32768)
1537 else if (sample
> 32767)
1539 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1541 r
= (r
+ 1) & CMX_BUFF_MASK
;
1543 /* -> if echo is enabled */
1546 * -> encode conf-data, if tx-data
1549 while (r
!= rr
&& t
!= tt
) {
1550 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++;
1551 if (sample
< -32768)
1553 else if (sample
> 32767)
1555 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1557 t
= (t
+ 1) & CMX_BUFF_MASK
;
1558 r
= (r
+ 1) & CMX_BUFF_MASK
;
1562 if (sample
< -32768)
1564 else if (sample
> 32767)
1566 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1568 r
= (r
+ 1) & CMX_BUFF_MASK
;
1576 * send tx-data if enabled - don't filter,
1577 * because we want what we send, not what we filtered
1581 hh
->prim
= DL_DATA_REQ
;
1583 /* queue and trigger */
1584 skb_queue_tail(&dsp
->sendq
, nskb
);
1585 schedule_work(&dsp
->workq
);
1586 /* exit because only tx_data is used */
1589 txskb
= mI_alloc_skb(len
, GFP_ATOMIC
);
1592 "FATAL ERROR in mISDN_dsp.o: "
1593 "cannot alloc %d bytes\n", len
);
1595 thh
= mISDN_HEAD_P(txskb
);
1596 thh
->prim
= DL_DATA_REQ
;
1598 skb_put_data(txskb
, nskb
->data
+ preload
, len
);
1599 /* queue (trigger later) */
1600 skb_queue_tail(&dsp
->sendq
, txskb
);
1605 /* send data only to card, if we don't just calculated tx_data */
1608 dsp_change_volume(nskb
, dsp
->tx_volume
);
1610 if (dsp
->pipeline
.inuse
)
1611 dsp_pipeline_process_tx(&dsp
->pipeline
, nskb
->data
,
1615 dsp_bf_encrypt(dsp
, nskb
->data
, nskb
->len
);
1616 /* queue and trigger */
1617 skb_queue_tail(&dsp
->sendq
, nskb
);
1618 schedule_work(&dsp
->workq
);
1621 static u32 jittercount
; /* counter for jitter check */
1622 struct timer_list dsp_spl_tl
;
1623 unsigned long dsp_spl_jiffies
; /* calculate the next time to fire */
1624 static u16 dsp_count
; /* last sample count */
1625 static int dsp_count_valid
; /* if we have last sample count */
1628 dsp_cmx_send(void *arg
)
1630 struct dsp_conf
*conf
;
1631 struct dsp_conf_member
*member
;
1633 int mustmix
, members
;
1634 static s32 mixbuffer
[MAX_POLL
+ 100];
1638 int jittercheck
= 0, delay
, i
;
1643 spin_lock_irqsave(&dsp_lock
, flags
);
1645 if (!dsp_count_valid
) {
1646 dsp_count
= mISDN_clock_get();
1648 dsp_count_valid
= 1;
1650 count
= mISDN_clock_get();
1651 length
= count
- dsp_count
;
1654 if (length
> MAX_POLL
+ 100)
1655 length
= MAX_POLL
+ 100;
1656 /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
1659 * check if jitter needs to be checked (this is every second)
1661 jittercount
+= length
;
1662 if (jittercount
>= 8000) {
1663 jittercount
-= 8000;
1667 /* loop all members that do not require conference mixing */
1668 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1675 members
= count_list_member(&conf
->mlist
);
1676 #ifdef CMX_CONF_DEBUG
1677 if (conf
->software
&& members
> 1)
1679 if (conf
->software
&& members
> 2)
1684 /* transmission required */
1686 dsp_cmx_send_member(dsp
, length
, mixbuffer
, members
);
1689 * unused mixbuffer is given to prevent a
1690 * potential null-pointer-bug
1695 /* loop all members that require conference mixing */
1696 list_for_each_entry(conf
, &conf_ilist
, list
) {
1697 /* count members and check hardware */
1698 members
= count_list_member(&conf
->mlist
);
1699 #ifdef CMX_CONF_DEBUG
1700 if (conf
->software
&& members
> 1) {
1702 if (conf
->software
&& members
> 2) {
1704 /* check for hdlc conf */
1705 member
= list_entry(conf
->mlist
.next
,
1706 struct dsp_conf_member
, list
);
1707 if (member
->dsp
->hdlc
)
1710 memset(mixbuffer
, 0, length
* sizeof(s32
));
1711 list_for_each_entry(member
, &conf
->mlist
, list
) {
1713 /* get range of data to mix */
1717 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1718 /* add member's data */
1720 *c
++ += dsp_audio_law_to_s32
[q
[r
]];
1721 r
= (r
+ 1) & CMX_BUFF_MASK
;
1725 /* process each member */
1726 list_for_each_entry(member
, &conf
->mlist
, list
) {
1728 dsp_cmx_send_member(member
->dsp
, length
,
1729 mixbuffer
, members
);
1734 /* delete rx-data, increment buffers, change pointers */
1735 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1741 /* move receive pointer when receiving */
1742 if (!dsp
->rx_is_off
) {
1743 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1744 /* delete rx-data */
1747 r
= (r
+ 1) & CMX_BUFF_MASK
;
1749 /* increment rx-buffer pointer */
1750 dsp
->rx_R
= r
; /* write incremented read pointer */
1753 /* check current rx_delay */
1754 delay
= (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
;
1755 if (delay
>= CMX_BUFF_HALF
)
1756 delay
= 0; /* will be the delay before next write */
1757 /* check for lower delay */
1758 if (delay
< dsp
->rx_delay
[0])
1759 dsp
->rx_delay
[0] = delay
;
1760 /* check current tx_delay */
1761 delay
= (dsp
->tx_W
-dsp
->tx_R
) & CMX_BUFF_MASK
;
1762 if (delay
>= CMX_BUFF_HALF
)
1763 delay
= 0; /* will be the delay before next write */
1764 /* check for lower delay */
1765 if (delay
< dsp
->tx_delay
[0])
1766 dsp
->tx_delay
[0] = delay
;
1768 /* find the lowest of all rx_delays */
1769 delay
= dsp
->rx_delay
[0];
1771 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1772 if (delay
> dsp
->rx_delay
[i
])
1773 delay
= dsp
->rx_delay
[i
];
1777 * remove rx_delay only if we have delay AND we
1778 * have not preset cmx_delay AND
1779 * the delay is greater dsp_poll
1781 if (delay
> dsp_poll
&& !dsp
->cmx_delay
) {
1782 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1784 "%s lowest rx_delay of %d bytes for"
1785 " dsp %s are now removed.\n",
1789 rr
= (r
+ delay
- (dsp_poll
>> 1))
1791 /* delete rx-data */
1794 r
= (r
+ 1) & CMX_BUFF_MASK
;
1796 /* increment rx-buffer pointer */
1798 /* write incremented read pointer */
1800 /* find the lowest of all tx_delays */
1801 delay
= dsp
->tx_delay
[0];
1803 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1804 if (delay
> dsp
->tx_delay
[i
])
1805 delay
= dsp
->tx_delay
[i
];
1809 * remove delay only if we have delay AND we
1810 * have enabled tx_dejitter
1812 if (delay
> dsp_poll
&& dsp
->tx_dejitter
) {
1813 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1815 "%s lowest tx_delay of %d bytes for"
1816 " dsp %s are now removed.\n",
1820 rr
= (r
+ delay
- (dsp_poll
>> 1))
1822 /* delete tx-data */
1825 r
= (r
+ 1) & CMX_BUFF_MASK
;
1827 /* increment rx-buffer pointer */
1829 /* write incremented read pointer */
1831 /* scroll up delays */
1832 i
= MAX_SECONDS_JITTER_CHECK
- 1;
1834 dsp
->rx_delay
[i
] = dsp
->rx_delay
[i
- 1];
1835 dsp
->tx_delay
[i
] = dsp
->tx_delay
[i
- 1];
1838 dsp
->tx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1839 dsp
->rx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1843 /* if next event would be in the past ... */
1844 if ((s32
)(dsp_spl_jiffies
+ dsp_tics
-jiffies
) <= 0)
1845 dsp_spl_jiffies
= jiffies
+ 1;
1847 dsp_spl_jiffies
+= dsp_tics
;
1849 dsp_spl_tl
.expires
= dsp_spl_jiffies
;
1850 add_timer(&dsp_spl_tl
);
1853 spin_unlock_irqrestore(&dsp_lock
, flags
);
1857 * audio data is transmitted from upper layer to the dsp
1860 dsp_cmx_transmit(struct dsp
*dsp
, struct sk_buff
*skb
)
1864 int space
; /* todo: , l = skb->len; */
1866 char debugbuf
[256] = "";
1869 /* check if there is enough space, and then copy */
1874 space
= (ww
- w
- 1) & CMX_BUFF_MASK
;
1875 /* write-pointer should not overrun nor reach read pointer */
1876 if (space
< skb
->len
) {
1877 /* write to the space we have left */
1878 ww
= (ww
- 1) & CMX_BUFF_MASK
; /* end one byte prior tx_R */
1879 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1880 printk(KERN_DEBUG
"%s: TX overflow space=%d skb->len="
1881 "%d, w=0x%04x, ww=0x%04x\n", __func__
, space
,
1884 /* write until all byte are copied */
1885 ww
= (w
+ skb
->len
) & CMX_BUFF_MASK
;
1887 /* show current buffer */
1890 "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1891 (u_long
)dsp
, (ww
- w
) & CMX_BUFF_MASK
, w
, ww
, dsp
->name
);
1894 /* copy transmit data to tx-buffer */
1896 sprintf(debugbuf
, "TX getting (%04x-%04x)%p: ", w
, ww
, p
);
1900 if (strlen(debugbuf
) < 48)
1901 sprintf(debugbuf
+ strlen(debugbuf
), " %02x", *d
);
1904 w
= (w
+ 1) & CMX_BUFF_MASK
;
1907 printk(KERN_DEBUG
"%s\n", debugbuf
);
1913 * hdlc data is received from card and sent to all members.
1916 dsp_cmx_hdlc(struct dsp
*dsp
, struct sk_buff
*skb
)
1918 struct sk_buff
*nskb
= NULL
;
1919 struct dsp_conf_member
*member
;
1920 struct mISDNhead
*hh
;
1922 /* not if not active */
1926 /* check if we have sompen */
1932 /* in case of software echo */
1933 if (dsp
->echo
.software
) {
1934 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1936 hh
= mISDN_HEAD_P(nskb
);
1937 hh
->prim
= PH_DATA_REQ
;
1939 skb_queue_tail(&dsp
->sendq
, nskb
);
1940 schedule_work(&dsp
->workq
);
1945 /* in case of hardware conference */
1946 if (dsp
->conf
->hardware
)
1948 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
1949 if (dsp
->echo
.software
|| member
->dsp
!= dsp
) {
1950 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1952 hh
= mISDN_HEAD_P(nskb
);
1953 hh
->prim
= PH_DATA_REQ
;
1955 skb_queue_tail(&member
->dsp
->sendq
, nskb
);
1956 schedule_work(&member
->dsp
->workq
);