2 * Audio crossconnecting/conferrencing (hardware level).
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 jiffy 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 * debug cmx memory structure
148 dsp_cmx_debug(struct dsp *dsp)
150 struct dsp_conf *conf;
151 struct dsp_conf_member *member;
154 printk(KERN_DEBUG "-----Current DSP\n");
155 list_for_each_entry(odsp, &dsp_ilist, list) {
156 printk(KERN_DEBUG "* %s hardecho=%d softecho=%d txmix=%d",
157 odsp->name, odsp->echo.hardware, odsp->echo.software,
160 printk(" (Conf %d)", odsp->conf->id);
165 printk(KERN_DEBUG "-----Current Conf:\n");
166 list_for_each_entry(conf, &conf_ilist, list) {
167 printk(KERN_DEBUG "* Conf %d (%p)\n", conf->id, conf);
168 list_for_each_entry(member, &conf->mlist, list) {
170 " - member = %s (slot_tx %d, bank_tx %d, "
171 "slot_rx %d, bank_rx %d hfc_conf %d "
172 "tx_data %d rx_is_off %d)%s\n",
173 member->dsp->name, member->dsp->pcm_slot_tx,
174 member->dsp->pcm_bank_tx, member->dsp->pcm_slot_rx,
175 member->dsp->pcm_bank_rx, member->dsp->hfc_conf,
176 member->dsp->tx_data, member->dsp->rx_is_off,
177 (member->dsp == dsp) ? " *this*" : "");
180 printk(KERN_DEBUG "-----end\n");
186 static struct dsp_conf *
187 dsp_cmx_search_conf(u32 id)
189 struct dsp_conf *conf;
192 printk(KERN_WARNING "%s: conference ID is 0.\n", __func__);
196 /* search conference */
197 list_for_each_entry(conf, &conf_ilist, list)
206 * add member to conference
209 dsp_cmx_add_conf_member(struct dsp *dsp, struct dsp_conf *conf)
211 struct dsp_conf_member *member;
214 printk(KERN_WARNING "%s: conf or dsp is 0.\n", __func__);
218 printk(KERN_WARNING "%s: dsp is already member in a conf.\n",
224 printk(KERN_WARNING "%s: dsp is already in a conf.\n",
229 member = kzalloc(sizeof(struct dsp_conf_member), GFP_ATOMIC);
231 printk(KERN_ERR "kzalloc struct dsp_conf_member failed\n");
235 /* clear rx buffer */
236 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
237 dsp->rx_init = 1; /* rx_W and rx_R will be adjusted on first frame */
241 list_add_tail(&member->list, &conf->mlist);
244 dsp->member = member;
251 * del member from conference
254 dsp_cmx_del_conf_member(struct dsp *dsp)
256 struct dsp_conf_member *member;
259 printk(KERN_WARNING "%s: dsp is 0.\n",
265 printk(KERN_WARNING "%s: dsp is not in a conf.\n",
270 if (list_empty(&dsp->conf->mlist)) {
271 printk(KERN_WARNING "%s: dsp has linked an empty conf.\n",
276 /* find us in conf */
277 list_for_each_entry(member, &dsp->conf->mlist, list) {
278 if (member->dsp == dsp) {
279 list_del(&member->list);
287 "%s: dsp is not present in its own conf_member list.\n",
297 static struct dsp_conf
298 *dsp_cmx_new_conf(u32 id)
300 struct dsp_conf *conf;
303 printk(KERN_WARNING "%s: id is 0.\n",
308 conf = kzalloc(sizeof(struct dsp_conf), GFP_ATOMIC);
310 printk(KERN_ERR "kzalloc struct dsp_conf failed\n");
313 INIT_LIST_HEAD(&conf->mlist);
316 list_add_tail(&conf->list, &conf_ilist);
326 dsp_cmx_del_conf(struct dsp_conf *conf)
329 printk(KERN_WARNING "%s: conf is null.\n",
334 if (!list_empty(&conf->mlist)) {
335 printk(KERN_WARNING "%s: conf not empty.\n",
339 list_del(&conf->list);
347 * send HW message to hfc card
350 dsp_cmx_hw_message(struct dsp *dsp, u32 message, u32 param1, u32 param2,
351 u32 param3, u32 param4)
353 struct mISDN_ctrl_req cq;
355 memset(&cq, 0, sizeof(cq));
357 cq.p1 = param1 | (param2 << 8);
358 cq.p2 = param3 | (param4 << 8);
360 dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq);
365 * do hardware update and set the software/hardware flag
367 * either a conference or a dsp instance can be given
368 * if only dsp instance is given, the instance is not associated with a conf
369 * and therefore removed. if a conference is given, the dsp is expected to
370 * be member of that conference.
373 dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp)
375 struct dsp_conf_member *member, *nextm;
377 int memb = 0, i, ii, i1, i2;
379 u_char freeslots[256];
380 int same_hfc = -1, same_pcm = -1, current_conf = -1,
381 all_conf = 1, tx_data = 0;
383 /* dsp gets updated (no conf) */
387 if (dsp_debug & DEBUG_DSP_CMX)
388 printk(KERN_DEBUG "%s checking dsp %s\n",
389 __func__, dsp->name);
391 /* remove HFC conference if enabled */
392 if (dsp->hfc_conf >= 0) {
393 if (dsp_debug & DEBUG_DSP_CMX)
395 "%s removing %s from HFC conf %d "
396 "because dsp is split\n", __func__,
397 dsp->name, dsp->hfc_conf);
398 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_CONF_SPLIT,
402 /* process hw echo */
403 if (dsp->features.pcm_banks < 1)
405 if (!dsp->echo.software && !dsp->echo.hardware) {
406 /* NO ECHO: remove PCM slot if assigned */
407 if (dsp->pcm_slot_tx >= 0 || dsp->pcm_slot_rx >= 0) {
408 if (dsp_debug & DEBUG_DSP_CMX)
409 printk(KERN_DEBUG "%s removing %s from"
410 " PCM slot %d (TX) %d (RX) because"
411 " dsp is split (no echo)\n",
413 dsp->pcm_slot_tx, dsp->pcm_slot_rx);
414 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_DISC,
416 dsp->pcm_slot_tx = -1;
417 dsp->pcm_bank_tx = -1;
418 dsp->pcm_slot_rx = -1;
419 dsp->pcm_bank_rx = -1;
423 /* echo is enabled, find out if we use soft or hardware */
424 dsp->echo.software = dsp->tx_data;
425 dsp->echo.hardware = 0;
426 /* ECHO: already echo */
427 if (dsp->pcm_slot_tx >= 0 && dsp->pcm_slot_rx < 0 &&
428 dsp->pcm_bank_tx == 2 && dsp->pcm_bank_rx == 2) {
429 dsp->echo.hardware = 1;
432 /* ECHO: if slot already assigned */
433 if (dsp->pcm_slot_tx >= 0) {
434 dsp->pcm_slot_rx = dsp->pcm_slot_tx;
435 dsp->pcm_bank_tx = 2; /* 2 means loop */
436 dsp->pcm_bank_rx = 2;
437 if (dsp_debug & DEBUG_DSP_CMX)
439 "%s refresh %s for echo using slot %d\n",
442 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
443 dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
444 dsp->echo.hardware = 1;
447 /* ECHO: find slot */
448 dsp->pcm_slot_tx = -1;
449 dsp->pcm_slot_rx = -1;
450 memset(freeslots, 1, sizeof(freeslots));
451 list_for_each_entry(finddsp, &dsp_ilist, list) {
452 if (finddsp->features.pcm_id == dsp->features.pcm_id) {
453 if (finddsp->pcm_slot_rx >= 0 &&
454 finddsp->pcm_slot_rx < sizeof(freeslots))
455 freeslots[finddsp->pcm_slot_rx] = 0;
456 if (finddsp->pcm_slot_tx >= 0 &&
457 finddsp->pcm_slot_tx < sizeof(freeslots))
458 freeslots[finddsp->pcm_slot_tx] = 0;
462 ii = dsp->features.pcm_slots;
469 if (dsp_debug & DEBUG_DSP_CMX)
471 "%s no slot available for echo\n",
473 /* no more slots available */
474 dsp->echo.software = 1;
477 /* assign free slot */
478 dsp->pcm_slot_tx = i;
479 dsp->pcm_slot_rx = i;
480 dsp->pcm_bank_tx = 2; /* loop */
481 dsp->pcm_bank_rx = 2;
482 if (dsp_debug & DEBUG_DSP_CMX)
484 "%s assign echo for %s using slot %d\n",
485 __func__, dsp->name, dsp->pcm_slot_tx);
486 dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
487 dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
488 dsp->echo.hardware = 1;
492 /* conf gets updated (all members) */
493 if (dsp_debug & DEBUG_DSP_CMX)
494 printk(KERN_DEBUG "%s checking conference %d\n",
497 if (list_empty(&conf->mlist)) {
498 printk(KERN_ERR "%s: conference without members\n",
502 member = list_entry(conf->mlist.next, struct dsp_conf_member, list);
503 same_hfc = member->dsp->features.hfc_id;
504 same_pcm = member->dsp->features.pcm_id;
505 /* check all members in our conference */
506 list_for_each_entry(member, &conf->mlist, list) {
507 /* check if member uses mixing */
508 if (member->dsp->tx_mix) {
509 if (dsp_debug & DEBUG_DSP_CMX)
511 "%s dsp %s cannot form a conf, because "
512 "tx_mix is turned on\n", __func__,
515 list_for_each_entry(member, &conf->mlist, list) {
517 /* remove HFC conference if enabled */
518 if (dsp->hfc_conf >= 0) {
519 if (dsp_debug & DEBUG_DSP_CMX)
521 "%s removing %s from HFC "
522 "conf %d because not "
523 "possible with hardware\n",
527 dsp_cmx_hw_message(dsp,
528 MISDN_CTRL_HFC_CONF_SPLIT,
532 /* remove PCM slot if assigned */
533 if (dsp->pcm_slot_tx >= 0 ||
534 dsp->pcm_slot_rx >= 0) {
535 if (dsp_debug & DEBUG_DSP_CMX)
536 printk(KERN_DEBUG "%s removing "
537 "%s from PCM slot %d (TX)"
538 " slot %d (RX) because not"
539 " possible with hardware\n",
544 dsp_cmx_hw_message(dsp,
545 MISDN_CTRL_HFC_PCM_DISC,
547 dsp->pcm_slot_tx = -1;
548 dsp->pcm_bank_tx = -1;
549 dsp->pcm_slot_rx = -1;
550 dsp->pcm_bank_rx = -1;
557 /* check if member has echo turned on */
558 if (member->dsp->echo.hardware || member->dsp->echo.software) {
559 if (dsp_debug & DEBUG_DSP_CMX)
561 "%s dsp %s cannot form a conf, because "
562 "echo is turned on\n", __func__,
566 /* check if member has tx_mix turned on */
567 if (member->dsp->tx_mix) {
568 if (dsp_debug & DEBUG_DSP_CMX)
570 "%s dsp %s cannot form a conf, because "
571 "tx_mix is turned on\n",
572 __func__, member->dsp->name);
575 /* check if member changes volume at an not suppoted level */
576 if (member->dsp->tx_volume) {
577 if (dsp_debug & DEBUG_DSP_CMX)
579 "%s dsp %s cannot form a conf, because "
580 "tx_volume is changed\n",
581 __func__, member->dsp->name);
584 if (member->dsp->rx_volume) {
585 if (dsp_debug & DEBUG_DSP_CMX)
587 "%s dsp %s cannot form a conf, because "
588 "rx_volume is changed\n",
589 __func__, member->dsp->name);
592 /* check if tx-data turned on */
593 if (member->dsp->tx_data) {
594 if (dsp_debug & DEBUG_DSP_CMX)
596 "%s dsp %s tx_data is turned on\n",
597 __func__, member->dsp->name);
600 /* check if pipeline exists */
601 if (member->dsp->pipeline.inuse) {
602 if (dsp_debug & DEBUG_DSP_CMX)
604 "%s dsp %s cannot form a conf, because "
605 "pipeline exists\n", __func__,
609 /* check if encryption is enabled */
610 if (member->dsp->bf_enable) {
611 if (dsp_debug & DEBUG_DSP_CMX)
612 printk(KERN_DEBUG "%s dsp %s cannot form a "
613 "conf, because encryption is enabled\n",
614 __func__, member->dsp->name);
617 /* check if member is on a card with PCM support */
618 if (member->dsp->features.pcm_id < 0) {
619 if (dsp_debug & DEBUG_DSP_CMX)
621 "%s dsp %s cannot form a conf, because "
622 "dsp has no PCM bus\n",
623 __func__, member->dsp->name);
626 /* check if relations are on the same PCM bus */
627 if (member->dsp->features.pcm_id != same_pcm) {
628 if (dsp_debug & DEBUG_DSP_CMX)
630 "%s dsp %s cannot form a conf, because "
631 "dsp is on a different PCM bus than the "
633 __func__, member->dsp->name);
636 /* determine if members are on the same hfc chip */
637 if (same_hfc != member->dsp->features.hfc_id)
639 /* if there are members already in a conference */
640 if (current_conf < 0 && member->dsp->hfc_conf >= 0)
641 current_conf = member->dsp->hfc_conf;
642 /* if any member is not in a conference */
643 if (member->dsp->hfc_conf < 0)
649 /* if no member, this is an error */
655 if (dsp_debug & DEBUG_DSP_CMX)
657 "%s conf %d cannot form a HW conference, "
658 "because dsp is alone\n", __func__, conf->id);
661 member = list_entry(conf->mlist.next, struct dsp_conf_member,
668 * ok, now we are sure that all members are on the same pcm.
669 * now we will see if we have only two members, so we can do
670 * crossconnections, which don't have any limitations.
673 /* if we have only two members */
675 member = list_entry(conf->mlist.next, struct dsp_conf_member,
677 nextm = list_entry(member->list.next, struct dsp_conf_member,
679 /* remove HFC conference if enabled */
680 if (member->dsp->hfc_conf >= 0) {
681 if (dsp_debug & DEBUG_DSP_CMX)
683 "%s removing %s from HFC conf %d because "
684 "two parties require only a PCM slot\n",
685 __func__, member->dsp->name,
686 member->dsp->hfc_conf);
687 dsp_cmx_hw_message(member->dsp,
688 MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
689 member->dsp->hfc_conf = -1;
691 if (nextm->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__, nextm->dsp->name,
697 nextm->dsp->hfc_conf);
698 dsp_cmx_hw_message(nextm->dsp,
699 MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
700 nextm->dsp->hfc_conf = -1;
702 /* if members have two banks (and not on the same chip) */
703 if (member->dsp->features.pcm_banks > 1 &&
704 nextm->dsp->features.pcm_banks > 1 &&
705 member->dsp->features.hfc_id !=
706 nextm->dsp->features.hfc_id) {
707 /* if both members have same slots with crossed banks */
708 if (member->dsp->pcm_slot_tx >= 0 &&
709 member->dsp->pcm_slot_rx >= 0 &&
710 nextm->dsp->pcm_slot_tx >= 0 &&
711 nextm->dsp->pcm_slot_rx >= 0 &&
712 nextm->dsp->pcm_slot_tx ==
713 member->dsp->pcm_slot_rx &&
714 nextm->dsp->pcm_slot_rx ==
715 member->dsp->pcm_slot_tx &&
716 nextm->dsp->pcm_slot_tx ==
717 member->dsp->pcm_slot_tx &&
718 member->dsp->pcm_bank_tx !=
719 member->dsp->pcm_bank_rx &&
720 nextm->dsp->pcm_bank_tx !=
721 nextm->dsp->pcm_bank_rx) {
722 /* all members have same slot */
723 if (dsp_debug & DEBUG_DSP_CMX)
725 "%s dsp %s & %s stay joined on "
726 "PCM slot %d bank %d (TX) bank %d "
727 "(RX) (on different chips)\n",
731 member->dsp->pcm_slot_tx,
732 member->dsp->pcm_bank_tx,
733 member->dsp->pcm_bank_rx);
735 conf->software = tx_data;
738 /* find a new slot */
739 memset(freeslots, 1, sizeof(freeslots));
740 list_for_each_entry(dsp, &dsp_ilist, list) {
741 if (dsp != member->dsp &&
743 member->dsp->features.pcm_id ==
744 dsp->features.pcm_id) {
745 if (dsp->pcm_slot_rx >= 0 &&
748 freeslots[dsp->pcm_slot_rx] = 0;
749 if (dsp->pcm_slot_tx >= 0 &&
752 freeslots[dsp->pcm_slot_tx] = 0;
756 ii = member->dsp->features.pcm_slots;
763 if (dsp_debug & DEBUG_DSP_CMX)
765 "%s no slot available for "
766 "%s & %s\n", __func__,
769 /* no more slots available */
772 /* assign free slot */
773 member->dsp->pcm_slot_tx = i;
774 member->dsp->pcm_slot_rx = i;
775 nextm->dsp->pcm_slot_tx = i;
776 nextm->dsp->pcm_slot_rx = i;
777 member->dsp->pcm_bank_rx = 0;
778 member->dsp->pcm_bank_tx = 1;
779 nextm->dsp->pcm_bank_rx = 1;
780 nextm->dsp->pcm_bank_tx = 0;
781 if (dsp_debug & DEBUG_DSP_CMX)
783 "%s adding %s & %s to new PCM slot %d "
784 "(TX and RX on different chips) because "
785 "both members have not same slots\n",
789 member->dsp->pcm_slot_tx);
790 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
791 member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
792 member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
793 dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
794 nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
795 nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
797 conf->software = tx_data;
799 /* if members have one bank (or on the same chip) */
801 /* if both members have different crossed slots */
802 if (member->dsp->pcm_slot_tx >= 0 &&
803 member->dsp->pcm_slot_rx >= 0 &&
804 nextm->dsp->pcm_slot_tx >= 0 &&
805 nextm->dsp->pcm_slot_rx >= 0 &&
806 nextm->dsp->pcm_slot_tx ==
807 member->dsp->pcm_slot_rx &&
808 nextm->dsp->pcm_slot_rx ==
809 member->dsp->pcm_slot_tx &&
810 member->dsp->pcm_slot_tx !=
811 member->dsp->pcm_slot_rx &&
812 member->dsp->pcm_bank_tx == 0 &&
813 member->dsp->pcm_bank_rx == 0 &&
814 nextm->dsp->pcm_bank_tx == 0 &&
815 nextm->dsp->pcm_bank_rx == 0) {
816 /* all members have same slot */
817 if (dsp_debug & DEBUG_DSP_CMX)
819 "%s dsp %s & %s stay joined on PCM "
820 "slot %d (TX) %d (RX) on same chip "
821 "or one bank PCM)\n", __func__,
824 member->dsp->pcm_slot_tx,
825 member->dsp->pcm_slot_rx);
827 conf->software = tx_data;
830 /* find two new slot */
831 memset(freeslots, 1, sizeof(freeslots));
832 list_for_each_entry(dsp, &dsp_ilist, list) {
833 if (dsp != member->dsp &&
835 member->dsp->features.pcm_id ==
836 dsp->features.pcm_id) {
837 if (dsp->pcm_slot_rx >= 0 &&
840 freeslots[dsp->pcm_slot_rx] = 0;
841 if (dsp->pcm_slot_tx >= 0 &&
844 freeslots[dsp->pcm_slot_tx] = 0;
848 ii = member->dsp->features.pcm_slots;
855 if (dsp_debug & DEBUG_DSP_CMX)
857 "%s no slot available "
858 "for %s & %s\n", __func__,
861 /* no more slots available */
871 if (dsp_debug & DEBUG_DSP_CMX)
873 "%s no slot available "
878 /* no more slots available */
881 /* assign free slots */
882 member->dsp->pcm_slot_tx = i1;
883 member->dsp->pcm_slot_rx = i2;
884 nextm->dsp->pcm_slot_tx = i2;
885 nextm->dsp->pcm_slot_rx = i1;
886 member->dsp->pcm_bank_rx = 0;
887 member->dsp->pcm_bank_tx = 0;
888 nextm->dsp->pcm_bank_rx = 0;
889 nextm->dsp->pcm_bank_tx = 0;
890 if (dsp_debug & DEBUG_DSP_CMX)
892 "%s adding %s & %s to new PCM slot %d "
893 "(TX) %d (RX) on same chip or one bank "
894 "PCM, because both members have not "
895 "crossed slots\n", __func__,
898 member->dsp->pcm_slot_tx,
899 member->dsp->pcm_slot_rx);
900 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
901 member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
902 member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
903 dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
904 nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
905 nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
907 conf->software = tx_data;
913 * if we have more than two, we may check if we have a conference
914 * unit available on the chip. also all members must be on the same
917 /* if not the same HFC chip */
919 if (dsp_debug & DEBUG_DSP_CMX)
921 "%s conference %d cannot be formed, because "
922 "members are on different chips or not "
928 /* for more than two members.. */
930 /* if all members already have the same conference */
933 conf->software = tx_data;
938 * if there is an existing conference, but not all members have joined
940 if (current_conf >= 0) {
942 list_for_each_entry(member, &conf->mlist, list) {
943 /* if no conference engine on our chip, change to
945 if (!member->dsp->features.hfc_conf)
947 /* in case of hdlc, change to software */
948 if (member->dsp->hdlc)
950 /* join to current conference */
951 if (member->dsp->hfc_conf == current_conf)
953 /* get a free timeslot first */
954 memset(freeslots, 1, sizeof(freeslots));
955 list_for_each_entry(dsp, &dsp_ilist, list) {
957 * not checking current member, because
958 * slot will be overwritten.
961 dsp != member->dsp &&
962 /* dsp must be on the same PCM */
963 member->dsp->features.pcm_id ==
964 dsp->features.pcm_id) {
965 /* dsp must be on a slot */
966 if (dsp->pcm_slot_tx >= 0 &&
969 freeslots[dsp->pcm_slot_tx] = 0;
970 if (dsp->pcm_slot_rx >= 0 &&
973 freeslots[dsp->pcm_slot_rx] = 0;
977 ii = member->dsp->features.pcm_slots;
984 /* no more slots available */
985 if (dsp_debug & DEBUG_DSP_CMX)
987 "%s conference %d cannot be formed,"
988 " because no slot free\n",
992 if (dsp_debug & DEBUG_DSP_CMX)
994 "%s changing dsp %s to HW conference "
995 "%d slot %d\n", __func__,
996 member->dsp->name, current_conf, i);
997 /* assign free slot & set PCM & join conf */
998 member->dsp->pcm_slot_tx = i;
999 member->dsp->pcm_slot_rx = i;
1000 member->dsp->pcm_bank_tx = 2; /* loop */
1001 member->dsp->pcm_bank_rx = 2;
1002 member->dsp->hfc_conf = current_conf;
1003 dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
1005 dsp_cmx_hw_message(member->dsp,
1006 MISDN_CTRL_HFC_CONF_JOIN, current_conf, 0, 0, 0);
1009 conf->software = tx_data;
1014 * no member is in a conference yet, so we find a free one
1016 memset(freeunits, 1, sizeof(freeunits));
1017 list_for_each_entry(dsp, &dsp_ilist, list) {
1018 /* dsp must be on the same chip */
1019 if (dsp->features.hfc_id == same_hfc &&
1020 /* dsp must have joined a HW conference */
1021 dsp->hfc_conf >= 0 &&
1022 /* slot must be within range */
1024 freeunits[dsp->hfc_conf] = 0;
1034 /* no more conferences available */
1035 if (dsp_debug & DEBUG_DSP_CMX)
1037 "%s conference %d cannot be formed, because "
1038 "no conference number free\n",
1039 __func__, conf->id);
1042 /* join all members */
1049 * conf_id != 0: join or change conference
1050 * conf_id == 0: split from conference if not already
1053 dsp_cmx_conf(struct dsp *dsp, u32 conf_id)
1056 struct dsp_conf *conf;
1057 struct dsp_conf_member *member;
1059 /* if conference doesn't change */
1060 if (dsp->conf_id == conf_id)
1063 /* first remove us from current conf */
1065 if (dsp_debug & DEBUG_DSP_CMX)
1066 printk(KERN_DEBUG "removing us from conference %d\n",
1068 /* remove us from conf */
1070 err = dsp_cmx_del_conf_member(dsp);
1075 /* update hardware */
1076 dsp_cmx_hardware(NULL, dsp);
1078 /* conf now empty? */
1079 if (list_empty(&conf->mlist)) {
1080 if (dsp_debug & DEBUG_DSP_CMX)
1082 "conference is empty, so we remove it.\n");
1083 err = dsp_cmx_del_conf(conf);
1087 /* update members left on conf */
1088 dsp_cmx_hardware(conf, NULL);
1096 /* now add us to conf */
1097 if (dsp_debug & DEBUG_DSP_CMX)
1098 printk(KERN_DEBUG "searching conference %d\n",
1100 conf = dsp_cmx_search_conf(conf_id);
1102 if (dsp_debug & DEBUG_DSP_CMX)
1104 "conference doesn't exist yet, creating.\n");
1105 /* the conference doesn't exist, so we create */
1106 conf = dsp_cmx_new_conf(conf_id);
1109 } else if (!list_empty(&conf->mlist)) {
1110 member = list_entry(conf->mlist.next, struct dsp_conf_member,
1112 if (dsp->hdlc && !member->dsp->hdlc) {
1113 if (dsp_debug & DEBUG_DSP_CMX)
1115 "cannot join transparent conference.\n");
1118 if (!dsp->hdlc && member->dsp->hdlc) {
1119 if (dsp_debug & DEBUG_DSP_CMX)
1121 "cannot join hdlc conference.\n");
1125 /* add conference member */
1126 err = dsp_cmx_add_conf_member(dsp, conf);
1129 dsp->conf_id = conf_id;
1131 /* if we are alone, we do nothing! */
1132 if (list_empty(&conf->mlist)) {
1133 if (dsp_debug & DEBUG_DSP_CMX)
1135 "we are alone in this conference, so exit.\n");
1136 /* update hardware */
1137 dsp_cmx_hardware(NULL, dsp);
1141 /* update members on conf */
1142 dsp_cmx_hardware(conf, NULL);
1147 #ifdef CMX_DELAY_DEBUG
1150 showdelay(struct dsp *dsp, int samples, int delay)
1152 char bar[] = "--------------------------------------------------|";
1155 delaycount += samples;
1156 if (delaycount < 8000)
1160 sdelay = delay * 50 / (dsp_poll << 2);
1162 printk(KERN_DEBUG "DELAY (%s) %3d >%s\n", dsp->name, delay,
1163 sdelay > 50 ? "..." : bar + 50 - sdelay);
1168 * audio data is received from card
1171 dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb)
1175 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1178 /* check if we have sompen */
1182 /* half of the buffer should be larger than maximum packet size */
1183 if (len >= CMX_BUFF_HALF) {
1185 "%s line %d: packet from card is too large (%d bytes). "
1186 "please make card send smaller packets OR increase "
1187 "CMX_BUFF_SIZE\n", __FILE__, __LINE__, len);
1192 * initialize pointers if not already -
1193 * also add delay if requested by PH_SIGNAL
1197 if (dsp->features.unordered) {
1198 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1200 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1203 dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
1208 dsp->rx_W = dsp->cmx_delay;
1210 dsp->rx_W = dsp_poll >> 1;
1213 /* if frame contains time code, write directly */
1214 if (dsp->features.unordered) {
1215 dsp->rx_W = (hh->id & CMX_BUFF_MASK);
1216 /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1219 * if we underrun (or maybe overrun),
1220 * we set our new read pointer, and write silence to buffer
1222 if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) {
1223 if (dsp_debug & DEBUG_DSP_CLOCK)
1225 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1226 "maximum delay), adjusting read pointer! "
1227 "(inst %s)\n", (u_long)dsp, dsp->name);
1228 /* flush rx buffer and set delay to dsp_poll / 2 */
1229 if (dsp->features.unordered) {
1230 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1232 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1235 dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
1240 dsp->rx_W = dsp->cmx_delay;
1242 dsp->rx_W = dsp_poll >> 1;
1244 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1246 /* if we have reached double delay, jump back to middle */
1248 if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
1249 (dsp->cmx_delay << 1)) {
1250 if (dsp_debug & DEBUG_DSP_CLOCK)
1252 "cmx_receive(dsp=%lx): OVERRUN (because "
1253 "twice the delay is reached), adjusting "
1254 "read pointer! (inst %s)\n",
1255 (u_long)dsp, dsp->name);
1257 if (dsp->features.unordered) {
1258 dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1259 dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1263 dsp->rx_W = dsp->cmx_delay;
1265 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1268 /* show where to write */
1271 "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1272 (u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name);
1275 /* write data into rx_buffer */
1282 d[w++ & CMX_BUFF_MASK] = *p++;
1286 /* increase write-pointer */
1287 dsp->rx_W = ((dsp->rx_W + len) & CMX_BUFF_MASK);
1288 #ifdef CMX_DELAY_DEBUG
1289 showdelay(dsp, len, (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK);
1295 * send (mixed) audio data to card and control jitter
1298 dsp_cmx_send_member(struct dsp *dsp, int len, s32 *c, int members)
1300 struct dsp_conf *conf = dsp->conf;
1301 struct dsp *member, *other;
1302 register s32 sample;
1303 u8 *d, *p, *q, *o_q;
1304 struct sk_buff *nskb, *txskb;
1305 int r, rr, t, tt, o_r, o_rr;
1307 struct mISDNhead *hh, *thh;
1308 int tx_data_only = 0;
1310 /* don't process if: */
1311 if (!dsp->b_active) { /* if not active */
1315 if (((dsp->conf && dsp->conf->hardware) || /* hardware conf */
1316 dsp->echo.hardware) && /* OR hardware echo */
1317 dsp->tx_R == dsp->tx_W && /* AND no tx-data */
1318 !(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */
1319 if (!dsp->tx_data) { /* no tx_data for user space required */
1323 if (dsp->conf && dsp->conf->software && dsp->conf->hardware)
1325 if (dsp->echo.software && dsp->echo.hardware)
1331 "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1332 members, dsp->name, conf, dsp->rx_R, dsp->rx_W);
1335 /* preload if we have delay set */
1336 if (dsp->cmx_delay && !dsp->last_tx) {
1342 /* PREPARE RESULT */
1343 nskb = mI_alloc_skb(len + preload, GFP_ATOMIC);
1346 "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1350 hh = mISDN_HEAD_P(nskb);
1351 hh->prim = PH_DATA_REQ;
1355 /* set pointers, indexes and stuff */
1357 p = dsp->tx_buff; /* transmit data */
1358 q = dsp->rx_buff; /* received data */
1359 d = skb_put(nskb, preload + len); /* result */
1360 t = dsp->tx_R; /* tx-pointers */
1362 r = dsp->rx_R; /* rx-pointers */
1363 rr = (r + len) & CMX_BUFF_MASK;
1365 /* preload with silence, if required */
1367 memset(d, dsp_silence, preload);
1371 /* PROCESS TONES/TX-DATA ONLY */
1372 if (dsp->tone.tone && dsp->tone.software) {
1374 dsp_tone_copy(dsp, d, len);
1375 dsp->tx_R = 0; /* clear tx buffer */
1379 /* if we have tx-data but do not use mixing */
1380 if (!dsp->tx_mix && t != tt) {
1381 /* -> send tx-data and continue when not enough */
1383 sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p);
1385 while (r != rr && t != tt) {
1387 if (strlen(debugbuf) < 48)
1388 sprintf(debugbuf + strlen(debugbuf), " %02x",
1391 *d++ = p[t]; /* write tx_buff */
1392 t = (t + 1) & CMX_BUFF_MASK;
1393 r = (r + 1) & CMX_BUFF_MASK;
1398 printk(KERN_DEBUG "%s\n", debugbuf);
1404 printk(KERN_DEBUG "%s\n", debugbuf);
1407 /* PROCESS DATA (one member / no conf) */
1408 if (!conf || members <= 1) {
1409 /* -> if echo is NOT enabled */
1410 if (!dsp->echo.software) {
1411 /* -> send tx-data if available or use 0-volume */
1412 while (r != rr && t != tt) {
1413 *d++ = p[t]; /* write tx_buff */
1414 t = (t + 1) & CMX_BUFF_MASK;
1415 r = (r + 1) & CMX_BUFF_MASK;
1418 if (dsp_debug & DEBUG_DSP_CLOCK)
1419 printk(KERN_DEBUG "%s: RX empty\n",
1421 memset(d, dsp_silence, (rr - r) & CMX_BUFF_MASK);
1423 /* -> if echo is enabled */
1426 * -> mix tx-data with echo if available,
1429 while (r != rr && t != tt) {
1430 *d++ = dsp_audio_mix_law[(p[t] << 8) | q[r]];
1431 t = (t + 1) & CMX_BUFF_MASK;
1432 r = (r + 1) & CMX_BUFF_MASK;
1435 *d++ = q[r]; /* echo */
1436 r = (r + 1) & CMX_BUFF_MASK;
1442 /* PROCESS DATA (two members) */
1443 #ifdef CMX_CONF_DEBUG
1448 /* "other" becomes other party */
1449 other = (list_entry(conf->mlist.next,
1450 struct dsp_conf_member, list))->dsp;
1451 if (other == member)
1452 other = (list_entry(conf->mlist.prev,
1453 struct dsp_conf_member, list))->dsp;
1454 o_q = other->rx_buff; /* received data */
1455 o_rr = (other->rx_R + len) & CMX_BUFF_MASK;
1456 /* end of rx-pointer */
1457 o_r = (o_rr - rr + r) & CMX_BUFF_MASK;
1458 /* start rx-pointer at current read position*/
1459 /* -> if echo is NOT enabled */
1460 if (!dsp->echo.software) {
1462 * -> copy other member's rx-data,
1463 * if tx-data is available, mix
1465 while (o_r != o_rr && t != tt) {
1466 *d++ = dsp_audio_mix_law[(p[t] << 8) | o_q[o_r]];
1467 t = (t + 1) & CMX_BUFF_MASK;
1468 o_r = (o_r + 1) & CMX_BUFF_MASK;
1470 while (o_r != o_rr) {
1472 o_r = (o_r + 1) & CMX_BUFF_MASK;
1474 /* -> if echo is enabled */
1477 * -> mix other member's rx-data with echo,
1478 * if tx-data is available, mix
1480 while (r != rr && t != tt) {
1481 sample = dsp_audio_law_to_s32[p[t]] +
1482 dsp_audio_law_to_s32[q[r]] +
1483 dsp_audio_law_to_s32[o_q[o_r]];
1484 if (sample < -32768)
1486 else if (sample > 32767)
1488 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1489 /* tx-data + rx_data + echo */
1490 t = (t + 1) & CMX_BUFF_MASK;
1491 r = (r + 1) & CMX_BUFF_MASK;
1492 o_r = (o_r + 1) & CMX_BUFF_MASK;
1495 *d++ = dsp_audio_mix_law[(q[r] << 8) | o_q[o_r]];
1496 r = (r + 1) & CMX_BUFF_MASK;
1497 o_r = (o_r + 1) & CMX_BUFF_MASK;
1503 /* PROCESS DATA (three or more members) */
1504 /* -> if echo is NOT enabled */
1505 if (!dsp->echo.software) {
1507 * -> subtract rx-data from conf-data,
1508 * if tx-data is available, mix
1510 while (r != rr && t != tt) {
1511 sample = dsp_audio_law_to_s32[p[t]] + *c++ -
1512 dsp_audio_law_to_s32[q[r]];
1513 if (sample < -32768)
1515 else if (sample > 32767)
1517 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1519 r = (r + 1) & CMX_BUFF_MASK;
1520 t = (t + 1) & CMX_BUFF_MASK;
1523 sample = *c++ - 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;
1532 /* -> if echo is enabled */
1535 * -> encode conf-data, if tx-data
1538 while (r != rr && t != tt) {
1539 sample = dsp_audio_law_to_s32[p[t]] + *c++;
1540 if (sample < -32768)
1542 else if (sample > 32767)
1544 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1546 t = (t + 1) & CMX_BUFF_MASK;
1547 r = (r + 1) & CMX_BUFF_MASK;
1551 if (sample < -32768)
1553 else if (sample > 32767)
1555 *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1557 r = (r + 1) & CMX_BUFF_MASK;
1565 * send tx-data if enabled - don't filter,
1566 * because we want what we send, not what we filtered
1570 hh->prim = DL_DATA_REQ;
1572 /* queue and trigger */
1573 skb_queue_tail(&dsp->sendq, nskb);
1574 schedule_work(&dsp->workq);
1575 /* exit because only tx_data is used */
1578 txskb = mI_alloc_skb(len, GFP_ATOMIC);
1581 "FATAL ERROR in mISDN_dsp.o: "
1582 "cannot alloc %d bytes\n", len);
1584 thh = mISDN_HEAD_P(txskb);
1585 thh->prim = DL_DATA_REQ;
1587 skb_put_data(txskb, nskb->data + preload, len);
1588 /* queue (trigger later) */
1589 skb_queue_tail(&dsp->sendq, txskb);
1594 /* send data only to card, if we don't just calculated tx_data */
1597 dsp_change_volume(nskb, dsp->tx_volume);
1599 if (dsp->pipeline.inuse)
1600 dsp_pipeline_process_tx(&dsp->pipeline, nskb->data,
1604 dsp_bf_encrypt(dsp, nskb->data, nskb->len);
1605 /* queue and trigger */
1606 skb_queue_tail(&dsp->sendq, nskb);
1607 schedule_work(&dsp->workq);
1610 static u32 jittercount; /* counter for jitter check */
1611 struct timer_list dsp_spl_tl;
1612 unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
1613 static u16 dsp_count; /* last sample count */
1614 static int dsp_count_valid; /* if we have last sample count */
1617 dsp_cmx_send(struct timer_list *arg)
1619 struct dsp_conf *conf;
1620 struct dsp_conf_member *member;
1622 int mustmix, members;
1623 static s32 mixbuffer[MAX_POLL + 100];
1627 int jittercheck = 0, delay, i;
1632 spin_lock_irqsave(&dsp_lock, flags);
1634 if (!dsp_count_valid) {
1635 dsp_count = mISDN_clock_get();
1637 dsp_count_valid = 1;
1639 count = mISDN_clock_get();
1640 length = count - dsp_count;
1643 if (length > MAX_POLL + 100)
1644 length = MAX_POLL + 100;
1645 /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
1648 * check if jitter needs to be checked (this is every second)
1650 jittercount += length;
1651 if (jittercount >= 8000) {
1652 jittercount -= 8000;
1656 /* loop all members that do not require conference mixing */
1657 list_for_each_entry(dsp, &dsp_ilist, list) {
1664 members = list_count_nodes(&conf->mlist);
1665 #ifdef CMX_CONF_DEBUG
1666 if (conf->software && members > 1)
1668 if (conf->software && members > 2)
1673 /* transmission required */
1675 dsp_cmx_send_member(dsp, length, mixbuffer, members);
1678 * unused mixbuffer is given to prevent a
1679 * potential null-pointer-bug
1684 /* loop all members that require conference mixing */
1685 list_for_each_entry(conf, &conf_ilist, list) {
1686 /* count members and check hardware */
1687 members = list_count_nodes(&conf->mlist);
1688 #ifdef CMX_CONF_DEBUG
1689 if (conf->software && members > 1) {
1691 if (conf->software && members > 2) {
1693 /* check for hdlc conf */
1694 member = list_entry(conf->mlist.next,
1695 struct dsp_conf_member, list);
1696 if (member->dsp->hdlc)
1699 memset(mixbuffer, 0, length * sizeof(s32));
1700 list_for_each_entry(member, &conf->mlist, list) {
1702 /* get range of data to mix */
1706 rr = (r + length) & CMX_BUFF_MASK;
1707 /* add member's data */
1709 *c++ += dsp_audio_law_to_s32[q[r]];
1710 r = (r + 1) & CMX_BUFF_MASK;
1714 /* process each member */
1715 list_for_each_entry(member, &conf->mlist, list) {
1717 dsp_cmx_send_member(member->dsp, length,
1718 mixbuffer, members);
1723 /* delete rx-data, increment buffers, change pointers */
1724 list_for_each_entry(dsp, &dsp_ilist, list) {
1730 /* move receive pointer when receiving */
1731 if (!dsp->rx_is_off) {
1732 rr = (r + length) & CMX_BUFF_MASK;
1733 /* delete rx-data */
1736 r = (r + 1) & CMX_BUFF_MASK;
1738 /* increment rx-buffer pointer */
1739 dsp->rx_R = r; /* write incremented read pointer */
1742 /* check current rx_delay */
1743 delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK;
1744 if (delay >= CMX_BUFF_HALF)
1745 delay = 0; /* will be the delay before next write */
1746 /* check for lower delay */
1747 if (delay < dsp->rx_delay[0])
1748 dsp->rx_delay[0] = delay;
1749 /* check current tx_delay */
1750 delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK;
1751 if (delay >= CMX_BUFF_HALF)
1752 delay = 0; /* will be the delay before next write */
1753 /* check for lower delay */
1754 if (delay < dsp->tx_delay[0])
1755 dsp->tx_delay[0] = delay;
1757 /* find the lowest of all rx_delays */
1758 delay = dsp->rx_delay[0];
1760 while (i < MAX_SECONDS_JITTER_CHECK) {
1761 if (delay > dsp->rx_delay[i])
1762 delay = dsp->rx_delay[i];
1766 * remove rx_delay only if we have delay AND we
1767 * have not preset cmx_delay AND
1768 * the delay is greater dsp_poll
1770 if (delay > dsp_poll && !dsp->cmx_delay) {
1771 if (dsp_debug & DEBUG_DSP_CLOCK)
1773 "%s lowest rx_delay of %d bytes for"
1774 " dsp %s are now removed.\n",
1778 rr = (r + delay - (dsp_poll >> 1))
1780 /* delete rx-data */
1783 r = (r + 1) & CMX_BUFF_MASK;
1785 /* increment rx-buffer pointer */
1787 /* write incremented read pointer */
1789 /* find the lowest of all tx_delays */
1790 delay = dsp->tx_delay[0];
1792 while (i < MAX_SECONDS_JITTER_CHECK) {
1793 if (delay > dsp->tx_delay[i])
1794 delay = dsp->tx_delay[i];
1798 * remove delay only if we have delay AND we
1799 * have enabled tx_dejitter
1801 if (delay > dsp_poll && dsp->tx_dejitter) {
1802 if (dsp_debug & DEBUG_DSP_CLOCK)
1804 "%s lowest tx_delay of %d bytes for"
1805 " dsp %s are now removed.\n",
1809 rr = (r + delay - (dsp_poll >> 1))
1811 /* delete tx-data */
1814 r = (r + 1) & CMX_BUFF_MASK;
1816 /* increment rx-buffer pointer */
1818 /* write incremented read pointer */
1820 /* scroll up delays */
1821 i = MAX_SECONDS_JITTER_CHECK - 1;
1823 dsp->rx_delay[i] = dsp->rx_delay[i - 1];
1824 dsp->tx_delay[i] = dsp->tx_delay[i - 1];
1827 dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1828 dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1832 /* if next event would be in the past ... */
1833 if ((s32)(dsp_spl_jiffies + dsp_tics-jiffies) <= 0)
1834 dsp_spl_jiffies = jiffies + 1;
1836 dsp_spl_jiffies += dsp_tics;
1838 dsp_spl_tl.expires = dsp_spl_jiffies;
1839 add_timer(&dsp_spl_tl);
1842 spin_unlock_irqrestore(&dsp_lock, flags);
1846 * audio data is transmitted from upper layer to the dsp
1849 dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb)
1853 int space; /* todo: , l = skb->len; */
1855 char debugbuf[256] = "";
1858 /* check if there is enough space, and then copy */
1863 space = (ww - w - 1) & CMX_BUFF_MASK;
1864 /* write-pointer should not overrun nor reach read pointer */
1865 if (space < skb->len) {
1866 /* write to the space we have left */
1867 ww = (ww - 1) & CMX_BUFF_MASK; /* end one byte prior tx_R */
1868 if (dsp_debug & DEBUG_DSP_CLOCK)
1869 printk(KERN_DEBUG "%s: TX overflow space=%d skb->len="
1870 "%d, w=0x%04x, ww=0x%04x\n", __func__, space,
1873 /* write until all byte are copied */
1874 ww = (w + skb->len) & CMX_BUFF_MASK;
1876 /* show current buffer */
1879 "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1880 (u_long)dsp, (ww - w) & CMX_BUFF_MASK, w, ww, dsp->name);
1883 /* copy transmit data to tx-buffer */
1885 sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p);
1889 if (strlen(debugbuf) < 48)
1890 sprintf(debugbuf + strlen(debugbuf), " %02x", *d);
1893 w = (w + 1) & CMX_BUFF_MASK;
1896 printk(KERN_DEBUG "%s\n", debugbuf);
1902 * hdlc data is received from card and sent to all members.
1905 dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb)
1907 struct sk_buff *nskb = NULL;
1908 struct dsp_conf_member *member;
1909 struct mISDNhead *hh;
1911 /* not if not active */
1915 /* check if we have sompen */
1921 /* in case of software echo */
1922 if (dsp->echo.software) {
1923 nskb = skb_clone(skb, GFP_ATOMIC);
1925 hh = mISDN_HEAD_P(nskb);
1926 hh->prim = PH_DATA_REQ;
1928 skb_queue_tail(&dsp->sendq, nskb);
1929 schedule_work(&dsp->workq);
1934 /* in case of hardware conference */
1935 if (dsp->conf->hardware)
1937 list_for_each_entry(member, &dsp->conf->mlist, list) {
1938 if (dsp->echo.software || member->dsp != dsp) {
1939 nskb = skb_clone(skb, GFP_ATOMIC);
1941 hh = mISDN_HEAD_P(nskb);
1942 hh->prim = PH_DATA_REQ;
1944 skb_queue_tail(&member->dsp->sendq, nskb);
1945 schedule_work(&member->dsp->workq);